diff --git a/app/src/main/java/net/helcel/beans/activity/MainActivity.kt b/app/src/main/java/net/helcel/beans/activity/MainActivity.kt index bb3a48e..76dbb65 100644 --- a/app/src/main/java/net/helcel/beans/activity/MainActivity.kt +++ b/app/src/main/java/net/helcel/beans/activity/MainActivity.kt @@ -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) + } + } \ No newline at end of file diff --git a/app/src/main/java/net/helcel/beans/activity/fragment/SettingsFragment.kt b/app/src/main/java/net/helcel/beans/activity/fragment/SettingsFragment.kt index b9f21e6..e435da1 100644 --- a/app/src/main/java/net/helcel/beans/activity/fragment/SettingsFragment.kt +++ b/app/src/main/java/net/helcel/beans/activity/fragment/SettingsFragment.kt @@ -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(getString(R.string.key_projection))?.setOnPreferenceChangeListener { _, key -> + Settings.refreshProjection() + } + // Toggle groups findPreference(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(getString(R.string.key_regional))?.setOnPreferenceChangeListener { _, key -> when (key as String) { diff --git a/app/src/main/java/net/helcel/beans/helper/Settings.kt b/app/src/main/java/net/helcel/beans/helper/Settings.kt index 3263a8f..0745576 100644 --- a/app/src/main/java/net/helcel/beans/helper/Settings.kt +++ b/app/src/main/java/net/helcel/beans/helper/Settings.kt @@ -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 diff --git a/app/src/main/java/net/helcel/beans/svg/SVGWrapper.kt b/app/src/main/java/net/helcel/beans/svg/SVGWrapper.kt index fbf4c3e..9fc1cee 100644 --- a/app/src/main/java/net/helcel/beans/svg/SVGWrapper.kt +++ b/app/src/main/java/net/helcel/beans/svg/SVGWrapper.kt @@ -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 diff --git a/app/src/main/res/drawable/map.xml b/app/src/main/res/drawable/map.xml new file mode 100644 index 0000000..521c6ac --- /dev/null +++ b/app/src/main/res/drawable/map.xml @@ -0,0 +1,16 @@ + + + + + + + diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 7012cc2..17d70a2 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -15,4 +15,14 @@ @string/on @string/off + + + @string/azimuthalequidistant + @string/equirectangular + @string/equidistant + @string/mercator + @string/loximuthal + @string/webmercator + + diff --git a/app/src/main/res/values/en.xml b/app/src/main/res/values/en.xml index 1d446ad..22b57ab 100644 --- a/app/src/main/res/values/en.xml +++ b/app/src/main/res/values/en.xml @@ -37,4 +37,11 @@ Ok Total Uncategorized + Azimuthal Equidistant + Equirectangular + Equidistant + Mercator + Loximuthal + Web Mercator + Map Projection \ No newline at end of file diff --git a/app/src/main/res/xml/fragment_settings.xml b/app/src/main/res/xml/fragment_settings.xml index a9faaf6..4dc5e63 100644 --- a/app/src/main/res/xml/fragment_settings.xml +++ b/app/src/main/res/xml/fragment_settings.xml @@ -13,6 +13,16 @@ app:title="@string/key_theme" app:useSimpleSummaryProvider="true" /> + +