Choose map projection in settings

This commit is contained in:
fgerber 2024-04-09 22:29:26 +02:00
parent e87f2fac28
commit 494d58034d
8 changed files with 80 additions and 6 deletions

View File

@ -24,6 +24,7 @@ class MainActivity : AppCompatActivity() {
private lateinit var css: CSSWrapper
override fun onRestart() {
refreshProjection()
refreshMap()
super.onRestart()
}
@ -50,7 +51,6 @@ class MainActivity : AppCompatActivity() {
Settings.start(this)
supportActionBar?.setBackgroundDrawable(colorWrapper(this, android.R.attr.colorPrimary))
setContentView(_binding.root)
_binding.photoView.minimumScale = 1f
@ -58,9 +58,8 @@ class MainActivity : AppCompatActivity() {
GeoLocImporter.importStates(this)
Data.loadData(this, Int.MIN_VALUE)
psvg = SVGWrapper(this)
css = CSSWrapper(this)
refreshProjection()
refreshMap()
}
@ -70,4 +69,9 @@ class MainActivity : AppCompatActivity() {
_binding.photoView.setImageDrawable(PictureDrawable(psvg.get()?.renderToPicture(opt)))
}
fun refreshProjection() {
psvg = SVGWrapper(this)
css = CSSWrapper(this)
}
}

View File

@ -7,9 +7,11 @@ import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceManager
import net.helcel.beans.R
import net.helcel.beans.activity.MainActivity
import net.helcel.beans.countries.GeoLocImporter
import net.helcel.beans.helper.Data
import net.helcel.beans.helper.DialogCloser
import net.helcel.beans.helper.Settings
class SettingsFragment : PreferenceFragmentCompat(), DialogCloser {
@ -28,6 +30,11 @@ class SettingsFragment : PreferenceFragmentCompat(), DialogCloser {
setTheme(ctx, key as String)
}
// Select map projection
findPreference<Preference>(getString(R.string.key_projection))?.setOnPreferenceChangeListener { _, key ->
Settings.refreshProjection()
}
// Toggle groups
findPreference<Preference>(getString(R.string.key_group))?.setOnPreferenceChangeListener { _, key ->
if (key as String == ctx.getString(R.string.off)) {
@ -42,7 +49,6 @@ class SettingsFragment : PreferenceFragmentCompat(), DialogCloser {
}
}
// Toggle regional geolocs
findPreference<Preference>(getString(R.string.key_regional))?.setOnPreferenceChangeListener { _, key ->
when (key as String) {

View File

@ -4,12 +4,15 @@ import android.content.Context
import android.content.SharedPreferences
import androidx.preference.PreferenceManager
import net.helcel.beans.R
import net.helcel.beans.activity.MainActivity
import net.helcel.beans.activity.fragment.SettingsFragment
object Settings {
private lateinit var sp: SharedPreferences
fun start(ctx: Context) {
private lateinit var mainActivity: MainActivity
fun start(ctx: MainActivity) {
mainActivity = ctx
sp = PreferenceManager.getDefaultSharedPreferences(ctx)
SettingsFragment.setTheme(
ctx, sp.getString(ctx.getString(R.string.key_theme), ctx.getString(R.string.system))
@ -37,6 +40,11 @@ object Settings {
)
}
fun refreshProjection(): Boolean {
mainActivity.refreshProjection()
return true
}
private fun getBooleanValue(ctx: Context, key: String?): Boolean {
return when (key) {
ctx.getString(R.string.on) -> true

View File

@ -1,11 +1,24 @@
package net.helcel.beans.svg
import android.content.Context
import androidx.preference.PreferenceManager
import com.caverock.androidsvg.SVG
import net.helcel.beans.R
class SVGWrapper(ctx: Context) {
private var svg: SVG? = SVG.getFromAsset(ctx.assets, "webmercator01.svg")
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(ctx)
val svgFile = when (sharedPreferences.getString(ctx.getString(R.string.key_projection), ctx.getString(R.string.mercator))) {
ctx.getString(R.string.azimuthalequidistant) -> "aeqd01.svg"
ctx.getString(R.string.equirectangular) -> "eqdc01.svg"
ctx.getString(R.string.equidistant) -> "eqearth01.svg"
ctx.getString(R.string.mercator) -> "mercator01.svg"
ctx.getString(R.string.loximuthal) -> "loxim01.svg"
ctx.getString(R.string.webmercator) -> "webmercator01.svg"
else -> "webmercator01.svg"
}
private var svg: SVG? = SVG.getFromAsset(ctx.assets, svgFile)
fun get(): SVG? {
return svg

View File

@ -0,0 +1,16 @@
<vector
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24"
android:width="24dp"
xmlns:android="http://schemas.android.com/apk/res/android" >
<path
android:fillColor="?attr/colorOnBackground"
android:pathData="M15,5.1L9,3 3,5.02v16.2l6,-2.33 6,2.1 6,-2.02L21,2.77L15,5.1z" />
<path
android:fillColor="?attr/colorPrimary"
android:pathData="M15,18.89l-6,-2.11L9,5.11l6,2.11v11.67z"/>
</vector>

View File

@ -15,4 +15,14 @@
<item>@string/on</item>
<item>@string/off</item>
</string-array>
<string-array name="map_projection">
<item>@string/azimuthalequidistant</item>
<item>@string/equirectangular</item>
<item>@string/equidistant</item>
<item>@string/mercator</item>
<item>@string/loximuthal</item>
<item>@string/webmercator</item>
</string-array>
</resources>

View File

@ -37,4 +37,11 @@
<string name="ok">Ok</string>
<string name="total">Total</string>
<string name="uncategorized">Uncategorized</string>
<string name="azimuthalequidistant">Azimuthal Equidistant</string>
<string name="equirectangular">Equirectangular</string>
<string name="equidistant">Equidistant</string>
<string name="mercator">Mercator</string>
<string name="loximuthal">Loximuthal</string>
<string name="webmercator">Web Mercator</string>
<string name="key_projection">Map Projection</string>
</resources>

View File

@ -13,6 +13,16 @@
app:title="@string/key_theme"
app:useSimpleSummaryProvider="true" />
<ListPreference
app:defaultValue="@string/webmercator"
app:enabled="true"
app:entries="@array/map_projection"
app:entryValues="@array/map_projection"
app:icon="@drawable/map"
app:key="@string/key_projection"
app:title="@string/key_projection"
app:useSimpleSummaryProvider="true" />
<ListPreference
app:defaultValue="@string/counters"
app:enabled="true"