Merge pull request #416 from wkawecki/master

#413 Add Satellite Map Layers
This commit is contained in:
Andre Kirchhoff
2022-04-22 16:47:30 -03:00
committed by GitHub
7 changed files with 84 additions and 8 deletions

View File

@@ -1083,6 +1083,10 @@ class MainActivity : BaseActivity(), Logging,
chooseLangDialog()
return true
}
R.id.preferences_map_style -> {
chooseMapStyle()
return true
}
else -> super.onOptionsItemSelected(item)
}
}
@@ -1187,9 +1191,31 @@ class MainActivity : BaseActivity(), Logging,
debug("Lang from prefs: $lang")
builder.setSingleChoiceItems(languageLabels, languageValues.indexOf(lang)) { dialog, which ->
var lang = languageValues[which];
debug("Set lang pref to $lang")
editor.putString("lang", lang)
val selectedLang = languageValues[which]
debug("Set lang pref to $selectedLang")
editor.putString("lang", selectedLang)
editor.apply()
dialog.dismiss()
}
val dialog = builder.create()
dialog.show()
}
private fun chooseMapStyle() {
/// Prepare dialog and its items
val builder = MaterialAlertDialogBuilder(this)
builder.setTitle(getString(R.string.preferences_map_style))
val mapStyles by lazy { resources.getStringArray(R.array.map_styles) }
/// Load preferences and its value
val prefs = UIViewModel.getPreferences(this)
val editor: SharedPreferences.Editor = prefs.edit()
val mapStyleId = prefs.getInt("map_style_id", 1)
debug("mapStyleId from prefs: $mapStyleId")
builder.setSingleChoiceItems(mapStyles, mapStyleId) { dialog, which ->
debug("Set mapStyleId pref to $which")
editor.putInt("map_style_id", which)
editor.apply()
dialog.dismiss()
}

View File

@@ -1,6 +1,8 @@
package com.geeksville.mesh.ui
import android.app.AlertDialog
import android.content.Context
import android.content.SharedPreferences
import android.graphics.Color
import android.os.Bundle
import android.view.LayoutInflater
@@ -227,10 +229,10 @@ class MapFragment : ScreenFragment("Map"), Logging {
if (userStyleURI != null) {
offlineManager.removeStylePack(userStyleURI!!)
mapView?.getMapboxMap()?.loadStyleUri(Style.OUTDOORS)
mapView?.getMapboxMap()?.loadStyleUri(loadMapStyleFromPref())
} else {
offlineManager.removeStylePack(mapView?.getMapboxMap()?.getStyle()?.styleURI.toString())
mapView?.getMapboxMap()?.loadStyleUri(Style.OUTDOORS)
mapView?.getMapboxMap()?.loadStyleUri(loadMapStyleFromPref())
}
MapboxMap.clearData(resourceOptions) {
it.error?.let { error ->
@@ -275,7 +277,7 @@ class MapFragment : ScreenFragment("Map"), Logging {
R.drawable.ic_twotone_person_pin_24
)!!.toBitmap()
map.loadStyleUri(Style.OUTDOORS) {
map.loadStyleUri(loadMapStyleFromPref()) {
if (it.isStyleLoaded) {
it.addSource(nodePositions)
it.addImage(markerImageId, markerIcon)
@@ -654,6 +656,25 @@ class MapFragment : ScreenFragment("Map"), Logging {
}
}
}
private fun loadMapStyleFromPref():String {
val prefs = context?.getSharedPreferences("ui-prefs", Context.MODE_PRIVATE)
val mapStyleId = prefs?.getInt("map_style_id", 1)
debug("mapStyleId from prefs: $mapStyleId")
val mapStyle = when (mapStyleId) {
0 -> Style.MAPBOX_STREETS
1 -> Style.OUTDOORS
2 -> Style.LIGHT
3 -> Style.DARK
4 -> Style.SATELLITE
5 -> Style.SATELLITE_STREETS
6 -> Style.TRAFFIC_DAY
7 -> Style.TRAFFIC_NIGHT
else -> Style.OUTDOORS
}
return mapStyle
}
}

View File

@@ -32,6 +32,10 @@
android:id="@+id/preferences_language"
android:title="@string/preferences_language"
app:showAsAction="withText" />
<item
android:id="@+id/preferences_map_style"
android:title="@string/preferences_map_style"
app:showAsAction="withText" />
<item
android:id="@+id/about"
android:title="@string/about"

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="map_styles">
<item>Ulice</item>
<item>Teren</item>
<item>Jasny</item>
<item>Ciemny</item>
<item>Satelita</item>
<item>Satelita (wraz z ulicami)</item>
<item>Natężenie ruchu (jasny)</item>
<item>Natężenie ruchu (ciemy)</item>
</string-array>
</resources>

View File

@@ -137,5 +137,6 @@ Jeśli jesteś zainteresowany opłaceniem przez nas mapboxa (lub przejściem do
<string name="allow_will_show">Zezwól (pokaże okno dialogowe)</string>
<string name="preferences_language">Język (wymagany restart)</string>
<string name="preferences_system_default">Domyślny systemu</string>
<string name="preferences_map_style">Typ map</string>
<string name="resend">Ponów</string>
</resources>

View File

@@ -3,7 +3,7 @@
<array name="MapMenuCheckbox">
<item>Use Custom URI?</item>
</array>
<string-array name="language_entries">
<string-array name="language_entries" translatable="false">
<!-- zz --><item>@string/preferences_system_default</item>
<!-- en --><item>English</item>
<!-- cs --><item>Čeština</item>
@@ -33,7 +33,7 @@
<!-- tr --><item>Türkçe</item>
</string-array>
<string-array name="language_values">
<string-array name="language_values" translatable="false">
<item>zz</item>
<item>en</item>
<item>cs</item>
@@ -62,4 +62,14 @@
<item>sv</item>
<item>tr</item>
</string-array>
<string-array name="map_styles">
<item>Streets</item>
<item>Outdoors</item>
<item>Light</item>
<item>Dark</item>
<item>Satellite</item>
<item>Satellite Streets</item>
<item>Navigation Day</item>
<item>Navigation Night</item>
</string-array>
</resources>

View File

@@ -140,5 +140,6 @@
<string name="download_failed">Unable to download style pack</string>
<string name="preferences_language">Language (restart needed)</string>
<string name="preferences_system_default">System default</string>
<string name="preferences_map_style">Map style</string>
<string name="resend">Resend</string>
</resources>