altosdroid: Add map source preference
authorKeith Packard <keithp@keithp.com>
Sun, 21 Jun 2015 17:34:00 +0000 (10:34 -0700)
committerKeith Packard <keithp@keithp.com>
Tue, 23 Jun 2015 04:04:43 +0000 (21:04 -0700)
Not hooked up yet.

Signed-off-by: Keith Packard <keithp@keithp.com>
altosdroid/res/menu/option_menu.xml
altosdroid/res/values/strings.xml
altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java
altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java
altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java

index 9cb57dfc952dfa1d29c818d7ed15cb1a0176c685..7e08c80333c30a3c8958f52533e4cb8d9a68fe00 100644 (file)
@@ -37,6 +37,9 @@
     <item android:id="@+id/map_type"
          android:icon="@android:drawable/ic_menu_mapmode"
          android:title="@string/map_type" />
+    <item android:id="@+id/map_source"
+         android:icon="@android:drawable/ic_menu_mapmode"
+         android:title="@string/map_source" />
     <item android:id="@+id/select_tracker"
          android:icon="@android:drawable/ic_menu_view"
          android:title="@string/select_tracker"/>
index 0c0128197c632bfb4689b5d4e886fe3c80a5d513..5a9d96299d74a6df2f095d34716748b35d4d02d5 100644 (file)
@@ -36,6 +36,7 @@
        <string name="select_tracker">Select Tracker</string>
        <string name="delete_track">Delete Track</string>
        <string name="map_type">Map Type</string>
+       <string name="map_source">Toggle Online/Offline maps</string>
 
        <!-- MapTypeActivity -->
        <string name="map_type">Map Type</string>
index 8fe97187506c174dcecdea6c9cae810224aebed5..fb669c5dcbfd3d72b408ebca9a0c17ec6e7e92a2 100644 (file)
@@ -503,12 +503,18 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener {
                return tab_view;
        }
 
+       public void set_map_source() {
+       }
+
        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                AltosDebug.init(this);
                AltosDebug.debug("+++ ON CREATE +++");
 
+               // Initialise preferences
+               AltosDroidPreferences.init(this);
+
                fm = getSupportFragmentManager();
 
                // Set up the window layout
@@ -918,6 +924,12 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener {
                        serverIntent = new Intent(this, MapTypeActivity.class);
                        startActivityForResult(serverIntent, REQUEST_MAP_TYPE);
                        return true;
+               case R.id.map_source:
+                       int source = AltosDroidPreferences.map_source();
+                       int new_source = source == AltosDroidPreferences.MAP_SOURCE_ONLINE ? AltosDroidPreferences.MAP_SOURCE_OFFLINE : AltosDroidPreferences.MAP_SOURCE_ONLINE;
+                       AltosDroidPreferences.set_map_source(new_source);
+                       set_map_source();
+                       return true;
                case R.id.select_tracker:
                        if (serials != null) {
                                String[] trackers = new String[serials.length];
index cda35f1ddd0e6ae6f17238c61669ddbab8c36602..6f74014a244a420282a6dc7228b134a864c0eb26 100644 (file)
@@ -27,6 +27,14 @@ public class AltosDroidPreferences extends AltosPreferences {
 
        static DeviceAddress    active_device_address;
 
+       /* Map source preference name */
+       final static String mapSourcePreference = "MAP-SOURCE";
+
+       static final int        MAP_SOURCE_OFFLINE = 0;
+       static final int        MAP_SOURCE_ONLINE = 1;
+
+       static int      map_source;
+
        public static void init(Context context) {
                if (backend != null)
                        return;
@@ -38,6 +46,8 @@ public class AltosDroidPreferences extends AltosPreferences {
 
                if (address != null && name != null)
                        active_device_address = new DeviceAddress (address, name);
+
+               map_source = backend.getInt(mapSourcePreference, MAP_SOURCE_ONLINE);
        }
 
        public static void set_active_device(DeviceAddress address) {
@@ -54,4 +64,18 @@ public class AltosDroidPreferences extends AltosPreferences {
                        return active_device_address;
                }
        }
+
+       public static void set_map_source(int map_source) {
+               synchronized(backend) {
+                       AltosDroidPreferences.map_source = map_source;
+                       backend.putInt(mapSourcePreference, map_source);
+                       flush_preferences();
+               }
+       }
+
+       public static int map_source() {
+               synchronized(backend) {
+                       return map_source;
+               }
+       }
 }
index 5236343012bac77f8eafce2c42a9484811e7697f..2d0ae65de8ab5fcecdc857e50feabf988ac00de9 100644 (file)
@@ -449,9 +449,6 @@ public class TelemetryService extends Service implements LocationListener {
                        Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
                }
 
-               // Initialise preferences
-               AltosDroidPreferences.init(this);
-
                telemetry_state = new TelemetryState();
 
                // Create a reference to the NotificationManager so that we can update our notifcation text later