altosui/altosdroid: Disable offline map type selections
[fw/altos] / altosdroid / src / org / altusmetrum / AltosDroid / PreloadMapActivity.java
index 498b208ef8e9f92e180fda89b3208d444d6d7cda..e393b566ba9362c3017603dfbe5eada5180c4810 100644 (file)
@@ -3,7 +3,8 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -41,7 +42,7 @@ import android.location.LocationManager;
 import android.location.LocationListener;
 import android.location.Criteria;
 
-import org.altusmetrum.altoslib_7.*;
+import org.altusmetrum.altoslib_13.*;
 
 /**
  * This Activity appears as a dialog. It lists any paired devices and
@@ -49,14 +50,16 @@ import org.altusmetrum.altoslib_7.*;
  * by the user, the MAC address of the device is sent back to the parent
  * Activity in the result Intent.
  */
-public class PreloadMapActivity extends Activity implements AltosLaunchSiteListener, AltosMapInterface, AltosMapLoaderListener, LocationListener {
+public class PreloadMapActivity extends Activity implements AltosLaunchSiteListener, AltosMapLoaderListener, LocationListener {
 
        private ArrayAdapter<AltosLaunchSite> known_sites_adapter;
 
+/*
        private CheckBox        hybrid;
        private CheckBox        satellite;
        private CheckBox        roadmap;
        private CheckBox        terrain;
+*/
 
        private Spinner         known_sites_spinner;
        private Spinner         min_zoom;
@@ -69,8 +72,14 @@ public class PreloadMapActivity extends Activity implements AltosLaunchSiteListe
 
        private ProgressBar     progress;
 
+       private AltosMapLoader  loader;
+
+       long    loader_notify_time;
+
        /* AltosMapLoaderListener interfaces */
        public void loader_start(final int max) {
+               loader_notify_time = System.currentTimeMillis();
+
                this.runOnUiThread(new Runnable() {
                                public void run() {
                                        progress.setMax(max);
@@ -80,6 +89,13 @@ public class PreloadMapActivity extends Activity implements AltosLaunchSiteListe
        }
 
        public void loader_notify(final int cur, final int max, final String name) {
+               long    now = System.currentTimeMillis();
+
+               if (now - loader_notify_time < 100)
+                       return;
+
+               loader_notify_time = now;
+
                this.runOnUiThread(new Runnable() {
                                public void run() {
                                        progress.setProgress(cur);
@@ -88,6 +104,7 @@ public class PreloadMapActivity extends Activity implements AltosLaunchSiteListe
        }
 
        public void loader_done(int max) {
+               loader = null;
                this.runOnUiThread(new Runnable() {
                                public void run() {
                                        progress.setProgress(0);
@@ -96,7 +113,12 @@ public class PreloadMapActivity extends Activity implements AltosLaunchSiteListe
                        });
        }
 
+       public void debug(String format, Object ... arguments) {
+               AltosDebug.debug(format, arguments);
+       }
+
        /* AltosLaunchSiteListener interface */
+
        public void notify_launch_sites(final List<AltosLaunchSite> sites) {
                this.runOnUiThread(new Runnable() {
                                public void run() {
@@ -106,71 +128,6 @@ public class PreloadMapActivity extends Activity implements AltosLaunchSiteListe
                        });
        }
 
-       AltosMap        map;
-       AltosMapLoader  loader;
-
-       class PreloadMapImage implements AltosImage {
-               public void flush() {
-               }
-
-               public PreloadMapImage(File file) {
-               }
-       }
-
-       public AltosMapPath new_path() {
-               return null;
-       }
-
-       public AltosMapLine new_line() {
-               return null;
-       }
-
-       public AltosImage load_image(File file) throws Exception {
-               return new PreloadMapImage(file);
-       }
-
-       public AltosMapMark new_mark(double lat, double lon, int state) {
-               return null;
-       }
-
-       class PreloadMapTile extends AltosMapTile {
-               public void paint(AltosMapTransform t) {
-               }
-
-               public PreloadMapTile(AltosMapTileListener listener, AltosLatLon upper_left, AltosLatLon center, int zoom, int maptype, int px_size) {
-                       super(listener, upper_left, center, zoom, maptype, px_size, 2);
-               }
-
-       }
-
-       public AltosMapTile new_tile(AltosMapTileListener listener, AltosLatLon upper_left, AltosLatLon center, int zoom, int maptype, int px_size) {
-               return new PreloadMapTile(listener, upper_left, center, zoom, maptype, px_size);
-       }
-
-       public int width() {
-               return AltosMap.px_size;
-       }
-
-       public int height() {
-               return AltosMap.px_size;
-       }
-
-       public void repaint() {
-       }
-
-       public void repaint(AltosRectangle damage) {
-       }
-
-       public void set_zoom_label(String label) {
-       }
-
-       public void select_object(AltosLatLon latlon) {
-       }
-
-       public void debug(String format, Object ... arguments) {
-               AltosDebug.debug(format, arguments);
-       }
-
        /* LocationProvider interface */
 
        AltosLaunchSite current_location_site;
@@ -235,26 +192,34 @@ public class PreloadMapActivity extends Activity implements AltosLaunchSiteListe
        private double radius() {
                double r = value_distance(radius);
                if (AltosPreferences.imperial_units())
-                       r = AltosConvert.distance.inverse(r);
+                       r = AltosConvert.miles_to_meters(r);
                else
                        r = r * 1000;
                return r;
        }
 
+/*
        private int bit(CheckBox box, int value) {
                if (box.isChecked())
                        return 1 << value;
                return 0;
        }
+*/
 
        private int types() {
+/*
                return (bit(hybrid, AltosMap.maptype_hybrid) |
                        bit(satellite, AltosMap.maptype_satellite) |
                        bit(roadmap, AltosMap.maptype_roadmap) |
                        bit(terrain, AltosMap.maptype_terrain));
+*/
+               return 1 << AltosMap.maptype_hybrid;
        }
 
        private void load() {
+               if (loader != null)
+                       return;
+
                try {
                        double  lat = latitude();
                        double  lon = longitude();
@@ -265,7 +230,7 @@ public class PreloadMapActivity extends Activity implements AltosLaunchSiteListe
 
                        AltosDebug.debug("PreloadMap load %f %f %d %d %f %d\n",
                                         lat, lon, min, max, r, t);
-                       loader.load(lat, lon, min, max, r, t);
+                       loader = new AltosMapLoader(this, lat, lon, min, max, r, t, AltosMapOffline.scale);
                } catch (ParseException e) {
                        AltosDebug.debug("PreloadMap load raised exception %s", e.toString());
                }
@@ -360,12 +325,14 @@ public class PreloadMapActivity extends Activity implements AltosLaunchSiteListe
                latitude = (EditText) findViewById(R.id.preload_latitude);
                longitude = (EditText) findViewById(R.id.preload_longitude);
 
+/*
                hybrid = (CheckBox) findViewById(R.id.preload_hybrid);
                satellite = (CheckBox) findViewById(R.id.preload_satellite);
                roadmap = (CheckBox) findViewById(R.id.preload_roadmap);
                terrain = (CheckBox) findViewById(R.id.preload_terrain);
 
                hybrid.setChecked(true);
+*/
 
                min_zoom = (Spinner) findViewById(R.id.preload_min_zoom);
                add_numbers(min_zoom,
@@ -396,10 +363,6 @@ public class PreloadMapActivity extends Activity implements AltosLaunchSiteListe
                known_sites_spinner.setAdapter(known_sites_adapter);
                known_sites_spinner.setOnItemSelectedListener(new SiteListListener());
 
-               map = new AltosMap(this);
-
-               loader = new AltosMapLoader(map, this);
-
                // Listen for GPS and Network position updates
                LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
 
@@ -412,6 +375,9 @@ public class PreloadMapActivity extends Activity implements AltosLaunchSiteListe
        protected void onDestroy() {
                super.onDestroy();
 
+               if (loader != null)
+                       loader.abort();
+
                // Stop listening for location updates
                ((LocationManager) getSystemService(Context.LOCATION_SERVICE)).removeUpdates(this);
        }