From e0081f7ba6fc9f1e4484d3e291fd30065ad5b620 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 5 May 2016 02:25:52 -0700 Subject: altoslib: Fix map preloading callbacks, run in separate thread The map storage and tile callbacks were muddled together. Create clearly separate states for map data and have status updates be delivered when registering for new status events so that registration is sufficient to track the state without an explicit call to get the current state. Run the map tile creation in a separate thread so that even checking status of files on disk runs out of the UI thread. These fixes serve to make the pacifier update more smoothly, and also not over/under count tile loading so that the loading actually completes when all of the tiles are loaded. Signed-off-by: Keith Packard --- .../src/org/altusmetrum/AltosDroid/AltosMapOffline.java | 14 +++++++------- .../src/org/altusmetrum/AltosDroid/PreloadMapActivity.java | 13 +++++-------- 2 files changed, 12 insertions(+), 15 deletions(-) (limited to 'altosdroid/src') diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosMapOffline.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosMapOffline.java index bde80cfc..ab142b17 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosMapOffline.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosMapOffline.java @@ -133,7 +133,7 @@ public class AltosMapOffline extends View implements ScaleGestureDetector.OnScal if (canvas.quickReject(pt.x, pt.y, pt.x + px_size, pt.y + px_size, Canvas.EdgeType.AA)) return; - AltosImage altos_image = cache.get(this, store, px_size, px_size); + AltosImage altos_image = this.get_image(); MapImage map_image = (MapImage) altos_image; @@ -150,8 +150,8 @@ public class AltosMapOffline extends View implements ScaleGestureDetector.OnScal if (t.has_location()) { String message = null; switch (status) { - case AltosMapTile.loading: - message = "Loading..."; + case AltosMapTile.fetching: + message = "Fetching..."; break; case AltosMapTile.bad_request: message = "Internal error"; @@ -181,14 +181,14 @@ public class AltosMapOffline extends View implements ScaleGestureDetector.OnScal } } - public MapTile(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 MapTile(AltosMapCache cache, AltosLatLon upper_left, AltosLatLon center, int zoom, int maptype, int px_size) { + super(cache, 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 MapTile(listener, upper_left, center, zoom, maptype, px_size); + public AltosMapTile new_tile(AltosMapCache cache, AltosLatLon upper_left, AltosLatLon center, int zoom, int maptype, int px_size) { + return new MapTile(cache, upper_left, center, zoom, maptype, px_size); } public AltosMapPath new_path() { diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/PreloadMapActivity.java b/altosdroid/src/org/altusmetrum/AltosDroid/PreloadMapActivity.java index 87f03a92..13a44e1f 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/PreloadMapActivity.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/PreloadMapActivity.java @@ -107,7 +107,6 @@ public class PreloadMapActivity extends Activity implements AltosLaunchSiteListe } AltosMap map; - AltosMapLoader loader; class PreloadMapImage implements AltosImage { public void flush() { @@ -137,14 +136,14 @@ public class PreloadMapActivity extends Activity implements AltosLaunchSiteListe 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 PreloadMapTile(AltosMapCache cache, AltosLatLon upper_left, AltosLatLon center, int zoom, int maptype, int px_size) { + super(cache, 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 AltosMapTile new_tile(AltosMapCache cache, AltosLatLon upper_left, AltosLatLon center, int zoom, int maptype, int px_size) { + return new PreloadMapTile(cache, upper_left, center, zoom, maptype, px_size); } public int width() { @@ -265,7 +264,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); + new AltosMapLoader(map, this, lat, lon, min, max, r, t); } catch (ParseException e) { AltosDebug.debug("PreloadMap load raised exception %s", e.toString()); } @@ -398,8 +397,6 @@ public class PreloadMapActivity extends Activity implements AltosLaunchSiteListe map = new AltosMap(this); - loader = new AltosMapLoader(map, this); - // Listen for GPS and Network position updates LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); -- cgit v1.2.3