Choose map projection in settings
This commit is contained in:
parent
e87f2fac28
commit
494d58034d
@ -24,6 +24,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
private lateinit var css: CSSWrapper
|
private lateinit var css: CSSWrapper
|
||||||
|
|
||||||
override fun onRestart() {
|
override fun onRestart() {
|
||||||
|
refreshProjection()
|
||||||
refreshMap()
|
refreshMap()
|
||||||
super.onRestart()
|
super.onRestart()
|
||||||
}
|
}
|
||||||
@ -50,7 +51,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
Settings.start(this)
|
Settings.start(this)
|
||||||
supportActionBar?.setBackgroundDrawable(colorWrapper(this, android.R.attr.colorPrimary))
|
supportActionBar?.setBackgroundDrawable(colorWrapper(this, android.R.attr.colorPrimary))
|
||||||
|
|
||||||
|
|
||||||
setContentView(_binding.root)
|
setContentView(_binding.root)
|
||||||
|
|
||||||
_binding.photoView.minimumScale = 1f
|
_binding.photoView.minimumScale = 1f
|
||||||
@ -58,9 +58,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
GeoLocImporter.importStates(this)
|
GeoLocImporter.importStates(this)
|
||||||
Data.loadData(this, Int.MIN_VALUE)
|
Data.loadData(this, Int.MIN_VALUE)
|
||||||
psvg = SVGWrapper(this)
|
|
||||||
css = CSSWrapper(this)
|
|
||||||
|
|
||||||
|
refreshProjection()
|
||||||
refreshMap()
|
refreshMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,4 +69,9 @@ class MainActivity : AppCompatActivity() {
|
|||||||
_binding.photoView.setImageDrawable(PictureDrawable(psvg.get()?.renderToPicture(opt)))
|
_binding.photoView.setImageDrawable(PictureDrawable(psvg.get()?.renderToPicture(opt)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun refreshProjection() {
|
||||||
|
psvg = SVGWrapper(this)
|
||||||
|
css = CSSWrapper(this)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -7,9 +7,11 @@ import androidx.preference.Preference
|
|||||||
import androidx.preference.PreferenceFragmentCompat
|
import androidx.preference.PreferenceFragmentCompat
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import net.helcel.beans.R
|
import net.helcel.beans.R
|
||||||
|
import net.helcel.beans.activity.MainActivity
|
||||||
import net.helcel.beans.countries.GeoLocImporter
|
import net.helcel.beans.countries.GeoLocImporter
|
||||||
import net.helcel.beans.helper.Data
|
import net.helcel.beans.helper.Data
|
||||||
import net.helcel.beans.helper.DialogCloser
|
import net.helcel.beans.helper.DialogCloser
|
||||||
|
import net.helcel.beans.helper.Settings
|
||||||
|
|
||||||
|
|
||||||
class SettingsFragment : PreferenceFragmentCompat(), DialogCloser {
|
class SettingsFragment : PreferenceFragmentCompat(), DialogCloser {
|
||||||
@ -28,6 +30,11 @@ class SettingsFragment : PreferenceFragmentCompat(), DialogCloser {
|
|||||||
setTheme(ctx, key as String)
|
setTheme(ctx, key as String)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Select map projection
|
||||||
|
findPreference<Preference>(getString(R.string.key_projection))?.setOnPreferenceChangeListener { _, key ->
|
||||||
|
Settings.refreshProjection()
|
||||||
|
}
|
||||||
|
|
||||||
// Toggle groups
|
// Toggle groups
|
||||||
findPreference<Preference>(getString(R.string.key_group))?.setOnPreferenceChangeListener { _, key ->
|
findPreference<Preference>(getString(R.string.key_group))?.setOnPreferenceChangeListener { _, key ->
|
||||||
if (key as String == ctx.getString(R.string.off)) {
|
if (key as String == ctx.getString(R.string.off)) {
|
||||||
@ -42,7 +49,6 @@ class SettingsFragment : PreferenceFragmentCompat(), DialogCloser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Toggle regional geolocs
|
// Toggle regional geolocs
|
||||||
findPreference<Preference>(getString(R.string.key_regional))?.setOnPreferenceChangeListener { _, key ->
|
findPreference<Preference>(getString(R.string.key_regional))?.setOnPreferenceChangeListener { _, key ->
|
||||||
when (key as String) {
|
when (key as String) {
|
||||||
|
@ -4,12 +4,15 @@ import android.content.Context
|
|||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import net.helcel.beans.R
|
import net.helcel.beans.R
|
||||||
|
import net.helcel.beans.activity.MainActivity
|
||||||
import net.helcel.beans.activity.fragment.SettingsFragment
|
import net.helcel.beans.activity.fragment.SettingsFragment
|
||||||
|
|
||||||
object Settings {
|
object Settings {
|
||||||
|
|
||||||
private lateinit var sp: SharedPreferences
|
private lateinit var sp: SharedPreferences
|
||||||
fun start(ctx: Context) {
|
private lateinit var mainActivity: MainActivity
|
||||||
|
fun start(ctx: MainActivity) {
|
||||||
|
mainActivity = ctx
|
||||||
sp = PreferenceManager.getDefaultSharedPreferences(ctx)
|
sp = PreferenceManager.getDefaultSharedPreferences(ctx)
|
||||||
SettingsFragment.setTheme(
|
SettingsFragment.setTheme(
|
||||||
ctx, sp.getString(ctx.getString(R.string.key_theme), ctx.getString(R.string.system))
|
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 {
|
private fun getBooleanValue(ctx: Context, key: String?): Boolean {
|
||||||
return when (key) {
|
return when (key) {
|
||||||
ctx.getString(R.string.on) -> true
|
ctx.getString(R.string.on) -> true
|
||||||
|
@ -1,11 +1,24 @@
|
|||||||
package net.helcel.beans.svg
|
package net.helcel.beans.svg
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import androidx.preference.PreferenceManager
|
||||||
import com.caverock.androidsvg.SVG
|
import com.caverock.androidsvg.SVG
|
||||||
|
import net.helcel.beans.R
|
||||||
|
|
||||||
class SVGWrapper(ctx: Context) {
|
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? {
|
fun get(): SVG? {
|
||||||
return svg
|
return svg
|
||||||
|
16
app/src/main/res/drawable/map.xml
Normal file
16
app/src/main/res/drawable/map.xml
Normal 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>
|
@ -15,4 +15,14 @@
|
|||||||
<item>@string/on</item>
|
<item>@string/on</item>
|
||||||
<item>@string/off</item>
|
<item>@string/off</item>
|
||||||
</string-array>
|
</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>
|
</resources>
|
||||||
|
@ -37,4 +37,11 @@
|
|||||||
<string name="ok">Ok</string>
|
<string name="ok">Ok</string>
|
||||||
<string name="total">Total</string>
|
<string name="total">Total</string>
|
||||||
<string name="uncategorized">Uncategorized</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>
|
</resources>
|
@ -13,6 +13,16 @@
|
|||||||
app:title="@string/key_theme"
|
app:title="@string/key_theme"
|
||||||
app:useSimpleSummaryProvider="true" />
|
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
|
<ListPreference
|
||||||
app:defaultValue="@string/counters"
|
app:defaultValue="@string/counters"
|
||||||
app:enabled="true"
|
app:enabled="true"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user