prefs: made location prefs work like new backend prefs

markdownfixes
Georg Lukas 2016-09-21 16:52:09 +02:00
rodzic 3bd654c23d
commit c8a57cd516
4 zmienionych plików z 40 dodań i 17 usunięć

Wyświetl plik

@ -70,13 +70,13 @@
<activity android:name=".PrefsAct" android:label="@string/app_prefs"
android:parentActivityName=".HubActivity"
/>
<activity android:name=".BackendPrefs" android:label="@string/app_prefs"
<activity android:name=".BackendPrefs" android:label="@string/p__connection"
android:parentActivityName=".PrefsAct"
/>
<activity android:name=".PrefSymbolAct" android:label="@string/p_symbol"
android:parentActivityName=".PrefsAct"
/>
<activity android:name=".LocationPrefs" android:label="@string/app_prefs"
<activity android:name=".LocationPrefs" android:label="@string/p__location"
android:parentActivityName=".PrefsAct"
android:launchMode="singleTop"
/>

Wyświetl plik

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<de.duenndns.ListPreferenceWithValue
android:key="loc_source"
android:title="@string/p_locsource"
android:summary="@string/p_locsource_summary"
android:entries="@array/p_locsource_e"
android:entryValues="@array/p_locsource_ev"
android:defaultValue="smartbeaconing"
android:dialogTitle="@string/p_locsource" />
</PreferenceScreen>

Wyświetl plik

@ -67,14 +67,6 @@
android:dialogTitle="@string/p_status_entry" />
<!-- sub-screen "Position Reports" -->
<de.duenndns.ListPreferenceWithValue
android:key="loc_source"
android:title="@string/p_locsource"
android:summary="@string/p_locsource_summary"
android:entries="@array/p_locsource_e"
android:entryValues="@array/p_locsource_ev"
android:defaultValue="smartbeaconing"
android:dialogTitle="@string/p_locsource" />
<PreferenceScreen
android:title="@string/p__location"

Wyświetl plik

@ -3,28 +3,46 @@ package org.aprsdroid.app
import _root_.android.content.Context
import _root_.android.location.{Location, LocationManager}
import _root_.android.os.Bundle
import _root_.android.content.SharedPreferences
import _root_.android.content.SharedPreferences.OnSharedPreferenceChangeListener
import _root_.android.preference.{PreferenceActivity, PreferenceManager}
import _root_.android.widget.Toast
class LocationPrefs extends PreferenceActivity {
class LocationPrefs extends PreferenceActivity with OnSharedPreferenceChangeListener {
def loadXml() {
val prefs = new PrefsWrapper(this)
addPreferencesFromResource(R.xml.location)
addPreferencesFromResource(LocationSource.instanciatePrefsAct(prefs))
}
override def onCreate(savedInstanceState: Bundle) {
super.onCreate(savedInstanceState)
val prefs = new PrefsWrapper(this)
addPreferencesFromResource(LocationSource.instanciatePrefsAct(prefs))
loadXml()
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this)
}
override def onDestroy() {
super.onDestroy()
getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this)
}
override def onSharedPreferenceChanged(sp: SharedPreferences, key : String) {
if (key == "loc_source" || key == "manual_lat" || key == "manual_lon") {
setPreferenceScreen(null)
loadXml()
}
}
override def onNewIntent(i : android.content.Intent) {
if (i != null && i.getDataString() != null && i.getDataString().equals("gps2manual")) {
val l = getSystemService(Context.LOCATION_SERVICE).asInstanceOf[LocationManager]
.getLastKnownLocation(LocationManager.GPS_PROVIDER)
val prefs = new PrefsWrapper(this)
if (l != null) {
val pe = new PrefsWrapper(this).prefs.edit()
val pe = prefs.prefs.edit()
pe.putString("manual_lat", l.getLatitude().toString())
pe.putString("manual_lon", l.getLongitude().toString())
pe.commit()
}
finish()
startActivity(i)
} else Toast.makeText(this, getString(R.string.map_track_unknown, prefs.getCallsign()), Toast.LENGTH_SHORT).show()
}
}
}