From 30194eb7d4dfd083ae7e456342203cc6d9d9cf81 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sun, 3 Aug 2014 16:39:46 +0200 Subject: Move functions to count visible points in viewport class --- main/src/cgeo/geocaching/maps/CGeoMap.java | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 2ca0cfd..e96c246 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -373,21 +373,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { } protected void countVisibleCaches() { - final List protectedCaches = caches.getAsList(); - - int count = 0; - if (!protectedCaches.isEmpty()) { - final Viewport viewport = mapView.getViewport(); - - for (final Geocache cache : protectedCaches) { - if (cache != null && cache.getCoords() != null) { - if (viewport.contains(cache)) { - count++; - } - } - } - } - cachesCnt = count; + cachesCnt = mapView.getViewport().count(caches.getAsList()); } @Override -- cgit v1.1 From 836fc36b272f5865e5c46e1f08e67eeeb49b3eae Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sun, 3 Aug 2014 16:44:16 +0200 Subject: Inline method used only once --- main/src/cgeo/geocaching/maps/CGeoMap.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index e96c246..cccc15c 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -1014,7 +1014,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { displayPoint(coordsIntent); loadTimer = Subscriptions.empty(); } else { - loadTimer = startLoadTimer(); + loadTimer = Schedulers.newThread().createWorker().schedulePeriodically(new LoadTimerAction(this), 0, 250, TimeUnit.MILLISECONDS); } return loadTimer; } @@ -1071,13 +1071,6 @@ public class CGeoMap extends AbstractMap implements ViewFactory { } /** - * loading timer Triggers every 250ms and checks for viewport change and starts a {@link LoadRunnable}. - */ - private Subscription startLoadTimer() { - return Schedulers.newThread().createWorker().schedulePeriodically(new LoadTimerAction(this), 0, 250, TimeUnit.MILLISECONDS); - } - - /** * get if map is loading something * * @return -- cgit v1.1 From c687d8b70878935ed2fef931b1818c3a3c08d018 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sun, 3 Aug 2014 16:47:53 +0200 Subject: Do not catch ThreadDeath exception There is no reason to catch ThreadDeath exception here. --- main/src/cgeo/geocaching/maps/CGeoMap.java | 7 ------- 1 file changed, 7 deletions(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index cccc15c..db71c84 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -204,7 +204,6 @@ public class CGeoMap extends AbstractMap implements ViewFactory { private static BlockingQueue downloadQueue = new ArrayBlockingQueue<>(1); private static ThreadPoolExecutor downloadExecutor = new ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS, downloadQueue, new ThreadPoolExecutor.DiscardOldestPolicy()); private static BlockingQueue loadQueue = new ArrayBlockingQueue<>(1); - private static ThreadPoolExecutor loadExecutor = new ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS, loadQueue, new ThreadPoolExecutor.DiscardOldestPolicy()); // handlers /** Updates the titles */ @@ -1218,9 +1217,6 @@ public class CGeoMap extends AbstractMap implements ViewFactory { //render displayExecutor.execute(new DisplayRunnable(this)); - } catch (final ThreadDeath e) { - Log.d("DownloadThread stopped"); - displayHandler.sendEmptyMessage(UPDATE_TITLE); } finally { showProgressHandler.sendEmptyMessage(HIDE_PROGRESS); // hide progress } @@ -1280,9 +1276,6 @@ public class CGeoMap extends AbstractMap implements ViewFactory { } displayHandler.sendEmptyMessage(UPDATE_TITLE); - } catch (final ThreadDeath e) { - Log.d("DisplayThread stopped"); - displayHandler.sendEmptyMessage(UPDATE_TITLE); } finally { showProgressHandler.sendEmptyMessage(HIDE_PROGRESS); } -- cgit v1.1 From 4c08563f0ba5d84cfbe37707b35f2e22d2c6bd23 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sun, 3 Aug 2014 17:02:23 +0200 Subject: Remove special handling of pseudo location --- main/src/cgeo/geocaching/maps/CGeoMap.java | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index db71c84..59ac4d7 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -891,7 +891,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { // Set center of map to my location if appropriate. private void myLocationInMiddle(final IGeoData geo) { - if (followMyLocation && !geo.isPseudoLocation()) { + if (followMyLocation) { centerMap(geo.getCoords()); } } @@ -908,7 +908,6 @@ public class CGeoMap extends AbstractMap implements ViewFactory { private static final float MIN_LOCATION_DELTA = 0.01f; Location currentLocation = new Location(""); - boolean locationValid = false; float currentHeading; private long timeLastPositionOverlayCalculation = 0; @@ -923,15 +922,9 @@ public class CGeoMap extends AbstractMap implements ViewFactory { @Override public void updateGeoDir(final IGeoData geo, final float dir) { - if (geo.isPseudoLocation()) { - locationValid = false; - } else { - locationValid = true; - - currentLocation = geo.getLocation(); - currentHeading = DirectionProvider.getDirectionNow(dir); - repaintPositionOverlay(); - } + currentLocation = geo.getLocation(); + currentHeading = DirectionProvider.getDirectionNow(dir); + repaintPositionOverlay(); } /** @@ -975,10 +968,6 @@ public class CGeoMap extends AbstractMap implements ViewFactory { } boolean needsRepaintForDistance() { - if (!locationValid) { - return false; - } - final CGeoMap map = mapRef.get(); if (map == null) { return false; -- cgit v1.1 From 6630ac7b85b2726df247c9fefa120e35e79dcd24 Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Mon, 4 Aug 2014 17:54:57 +0200 Subject: refactoring: avoid optimization of TEMPORARY_LIST --- main/src/cgeo/geocaching/maps/CGeoMap.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 59ac4d7..5b1461b 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -693,7 +693,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { public void call(final Integer selectedListId) { storeCaches(geocodes, selectedListId); } - }, true, StoredList.TEMPORARY_LIST_ID); + }, true, StoredList.TEMPORARY_LIST.id); } else { storeCaches(geocodes, StoredList.STANDARD_LIST_ID); } -- cgit v1.1 From 69993a499674c90ebb2cf16e2ce7411c533721f9 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Mon, 4 Aug 2014 19:14:20 +0200 Subject: Remove now unused HideLiveMapHint setting This is part of fix for #3470. --- main/src/cgeo/geocaching/maps/CGeoMap.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 5b1461b..c373d3f 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -491,7 +491,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { } prepareFilterBar(); - if (!app.isLiveMapHintShownInThisSession() && !Settings.getHideLiveMapHint() && Settings.getLiveMapHintShowCount() <= 3) { + if (!app.isLiveMapHintShownInThisSession() && Settings.getLiveMapHintShowCount() <= 3) { LiveMapInfoDialogBuilder.create(activity).show(); } } -- cgit v1.1 From 8fcc2adc388892729d326a465a06e0ba348e9c0b Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Tue, 5 Aug 2014 12:11:28 +0200 Subject: Redraw circle around user location at every accuracy change --- main/src/cgeo/geocaching/maps/CGeoMap.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index c373d3f..4b3132f 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -938,16 +938,16 @@ public class CGeoMap extends AbstractMap implements ViewFactory { try { final CGeoMap map = mapRef.get(); if (map != null) { - final boolean needsRepaintForDistance = needsRepaintForDistance(); + final boolean needsRepaintForDistanceOrAccuracy = needsRepaintForDistanceOrAccuracy(); final boolean needsRepaintForHeading = needsRepaintForHeading(); - if (needsRepaintForDistance) { + if (needsRepaintForDistanceOrAccuracy) { if (map.followMyLocation) { map.centerMap(new Geopoint(currentLocation)); } } - if (needsRepaintForDistance || needsRepaintForHeading) { + if (needsRepaintForDistanceOrAccuracy || needsRepaintForHeading) { map.overlayPositionAndScale.setCoordinates(currentLocation); map.overlayPositionAndScale.setHeading(currentHeading); map.mapView.repaintRequired(map.overlayPositionAndScale); @@ -967,7 +967,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { return Math.abs(AngleUtils.difference(currentHeading, map.overlayPositionAndScale.getHeading())) > MIN_HEADING_DELTA; } - boolean needsRepaintForDistance() { + boolean needsRepaintForDistanceOrAccuracy() { final CGeoMap map = mapRef.get(); if (map == null) { return false; @@ -976,6 +976,9 @@ public class CGeoMap extends AbstractMap implements ViewFactory { float dist = Float.MAX_VALUE; if (lastLocation != null) { + if (lastLocation.getAccuracy() != currentLocation.getAccuracy()) { + return true; + } dist = currentLocation.distanceTo(lastLocation); } -- cgit v1.1 From 1e24584929b62c304c7d36a7e1fa652e7e94a23a Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Sun, 10 Aug 2014 13:32:53 +0200 Subject: more strict checking of Maps API key --- main/src/cgeo/geocaching/maps/MapProviderFactory.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/MapProviderFactory.java b/main/src/cgeo/geocaching/maps/MapProviderFactory.java index dd4ff0f..212188d 100644 --- a/main/src/cgeo/geocaching/maps/MapProviderFactory.java +++ b/main/src/cgeo/geocaching/maps/MapProviderFactory.java @@ -33,7 +33,8 @@ public class MapProviderFactory { public static boolean isGoogleMapsInstalled() { // Check if API key is available - if (StringUtils.isBlank(CgeoApplication.getInstance().getString(R.string.maps_api_key))) { + final String mapsKey = CgeoApplication.getInstance().getString(R.string.maps_api_key); + if (StringUtils.length(mapsKey) < 30 || StringUtils.contains(mapsKey, "key")) { Log.w("No Google API key available."); return false; } @@ -41,7 +42,7 @@ public class MapProviderFactory { // Check if API is available try { Class.forName("com.google.android.maps.MapActivity"); - } catch (ClassNotFoundException e) { + } catch (final ClassNotFoundException e) { return false; } @@ -59,7 +60,7 @@ public class MapProviderFactory { return provider1 == provider2 && provider1.isSameActivity(source1, source2); } - public static void addMapviewMenuItems(Menu menu) { + public static void addMapviewMenuItems(final Menu menu) { final SubMenu parentMenu = menu.findItem(R.id.menu_select_mapview).getSubMenu(); final int currentSource = Settings.getMapSource().getNumericalId(); @@ -78,8 +79,8 @@ public class MapProviderFactory { * @return the map source, or null if id does not correspond to a registered map source */ @Nullable - public static MapSource getMapSource(int id) { - for (MapSource mapSource : mapSources) { + public static MapSource getMapSource(final int id) { + for (final MapSource mapSource : mapSources) { if (mapSource.getNumericalId() == id) { return mapSource; } @@ -109,7 +110,7 @@ public class MapProviderFactory { */ public static void deleteOfflineMapSources() { final ArrayList deletion = new ArrayList<>(); - for (MapSource mapSource : mapSources) { + for (final MapSource mapSource : mapSources) { if (mapSource instanceof MapsforgeMapProvider.OfflineMapSource) { deletion.add(mapSource); } -- cgit v1.1 From 6a564806ba3d7d5786c8d59ca5b4a87c4a76753d Mon Sep 17 00:00:00 2001 From: Christian Krause Date: Tue, 19 Aug 2014 03:51:05 +0200 Subject: Minor refactoring Move the identical function calls outside of the if-else block. --- main/src/cgeo/geocaching/maps/CGeoMap.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 4b3132f..c2317d0 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -1258,15 +1258,11 @@ public class CGeoMap extends AbstractMap implements ViewFactory { } itemsToDisplay.add(getCacheItem(cache)); } - - overlayCaches.updateItems(itemsToDisplay); - displayHandler.sendEmptyMessage(INVALIDATE_MAP); - - } else { - overlayCaches.updateItems(itemsToDisplay); - displayHandler.sendEmptyMessage(INVALIDATE_MAP); } + overlayCaches.updateItems(itemsToDisplay); + displayHandler.sendEmptyMessage(INVALIDATE_MAP); + displayHandler.sendEmptyMessage(UPDATE_TITLE); } finally { showProgressHandler.sendEmptyMessage(HIDE_PROGRESS); -- cgit v1.1 From ce9fa62c58102031f5b11e97a1cb1c4ffd6a32c9 Mon Sep 17 00:00:00 2001 From: Christian Krause Date: Tue, 19 Aug 2014 03:51:15 +0200 Subject: Don't update overlayCaches if just one point is displayed This fixes a race conditions between doDisplayRun() and displayPoint() which caused the wrong waypoint to be displayed. --- main/src/cgeo/geocaching/maps/CGeoMap.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index c2317d0..b0e6464 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -1259,8 +1259,10 @@ public class CGeoMap extends AbstractMap implements ViewFactory { itemsToDisplay.add(getCacheItem(cache)); } } - - overlayCaches.updateItems(itemsToDisplay); + // don't add other waypoints to overlayCaches if just one point should be displayed + if (coordsIntent == null) { + overlayCaches.updateItems(itemsToDisplay); + } displayHandler.sendEmptyMessage(INVALIDATE_MAP); displayHandler.sendEmptyMessage(UPDATE_TITLE); -- cgit v1.1 From f8adb612eb11883885a932097212e1639e3fcd4e Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Sat, 23 Aug 2014 14:04:32 +0200 Subject: allow more types of shortcuts from the home screen --- main/src/cgeo/geocaching/maps/CGeoMap.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 1c2cab9..9e387fc 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -1570,11 +1570,10 @@ public class CGeoMap extends AbstractMap implements ViewFactory { fromActivity.startActivity(mapIntent); } - public static void startActivityLiveMap(final Activity fromActivity) { - final Intent mapIntent = newIntent(fromActivity); - mapIntent.putExtra(EXTRAS_MAP_MODE, MapMode.LIVE); - mapIntent.putExtra(EXTRAS_LIVE_ENABLED, Settings.isLiveMap()); - fromActivity.startActivity(mapIntent); + public static Intent getLiveMapIntent(final Activity fromActivity) { + return newIntent(fromActivity) + .putExtra(EXTRAS_MAP_MODE, MapMode.LIVE) + .putExtra(EXTRAS_LIVE_ENABLED, true); } public static void startActivityCoords(final Activity fromActivity, final Geopoint coords, final WaypointType type, final String title) { -- cgit v1.1 From b02a5883e2dd116455759d7fa9a649ac8739869a Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Sat, 23 Aug 2014 14:37:31 +0200 Subject: provide homescreen shortcut for live map --- main/src/cgeo/geocaching/maps/MapActivity.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 main/src/cgeo/geocaching/maps/MapActivity.java (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/MapActivity.java b/main/src/cgeo/geocaching/maps/MapActivity.java new file mode 100644 index 0000000..28668ca --- /dev/null +++ b/main/src/cgeo/geocaching/maps/MapActivity.java @@ -0,0 +1,17 @@ +package cgeo.geocaching.maps; + +import android.app.Activity; +import android.os.Bundle; + +/** + * This activity provides an entry point for external intent calls, and then forwards to the currently used map activity + * implementation. + */ +public class MapActivity extends Activity { + @Override + protected void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + startActivity(CGeoMap.getLiveMapIntent(this)); + finish(); + } +} -- cgit v1.1 From 14b64ba566fa61afc5950dbd889d0aac4f591a8f Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Sun, 24 Aug 2014 13:05:39 +0200 Subject: fix #1303: use qualified intent keys --- main/src/cgeo/geocaching/maps/CGeoMap.java | 73 +++++++++++++----------------- 1 file changed, 32 insertions(+), 41 deletions(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 9e387fc..ea7d308 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -6,6 +6,7 @@ import cgeo.geocaching.CacheListActivity; import cgeo.geocaching.CgeoApplication; import cgeo.geocaching.DataStore; import cgeo.geocaching.Geocache; +import cgeo.geocaching.Intents; import cgeo.geocaching.R; import cgeo.geocaching.SearchResult; import cgeo.geocaching.Waypoint; @@ -125,16 +126,6 @@ public class CGeoMap extends AbstractMap implements ViewFactory { private static final int UPDATE_PROGRESS = 0; private static final int FINISHED_LOADING_DETAILS = 1; - //Menu - private static final String EXTRAS_GEOCODE = "geocode"; - private static final String EXTRAS_COORDS = "coords"; - private static final String EXTRAS_WPTTYPE = "wpttype"; - private static final String EXTRAS_MAPSTATE = "mapstate"; - private static final String EXTRAS_SEARCH = "search"; - private static final String EXTRAS_MAP_TITLE = "mapTitle"; - private static final String EXTRAS_MAP_MODE = "mapMode"; - private static final String EXTRAS_LIVE_ENABLED = "liveEnabled"; - private static final String BUNDLE_MAP_SOURCE = "mapSource"; private static final String BUNDLE_MAP_STATE = "mapState"; private static final String BUNDLE_LIVE_ENABLED = "liveEnabled"; @@ -402,14 +393,14 @@ public class CGeoMap extends AbstractMap implements ViewFactory { // Get parameters from the intent final Bundle extras = activity.getIntent().getExtras(); if (extras != null) { - mapMode = (MapMode) extras.get(EXTRAS_MAP_MODE); - isLiveEnabled = extras.getBoolean(EXTRAS_LIVE_ENABLED, false); - searchIntent = extras.getParcelable(EXTRAS_SEARCH); - geocodeIntent = extras.getString(EXTRAS_GEOCODE); - coordsIntent = extras.getParcelable(EXTRAS_COORDS); - waypointTypeIntent = WaypointType.findById(extras.getString(EXTRAS_WPTTYPE)); - mapStateIntent = extras.getIntArray(EXTRAS_MAPSTATE); - mapTitle = extras.getString(EXTRAS_MAP_TITLE); + mapMode = (MapMode) extras.get(Intents.EXTRA_MAP_MODE); + isLiveEnabled = extras.getBoolean(Intents.EXTRA_LIVE_ENABLED, false); + searchIntent = extras.getParcelable(Intents.EXTRA_SEARCH); + geocodeIntent = extras.getString(Intents.EXTRA_GEOCODE); + coordsIntent = extras.getParcelable(Intents.EXTRA_COORDS); + waypointTypeIntent = WaypointType.findById(extras.getString(Intents.EXTRA_WPTTYPE)); + mapStateIntent = extras.getIntArray(Intents.EXTRA_MAPSTATE); + mapTitle = extras.getString(Intents.EXTRA_MAP_TITLE); } else { mapMode = MapMode.LIVE; @@ -850,19 +841,19 @@ public class CGeoMap extends AbstractMap implements ViewFactory { // prepare information to restart a similar view final Intent mapIntent = new Intent(activity, Settings.getMapProvider().getMapClass()); - mapIntent.putExtra(EXTRAS_SEARCH, searchIntent); - mapIntent.putExtra(EXTRAS_GEOCODE, geocodeIntent); + mapIntent.putExtra(Intents.EXTRA_SEARCH, searchIntent); + mapIntent.putExtra(Intents.EXTRA_GEOCODE, geocodeIntent); if (coordsIntent != null) { - mapIntent.putExtra(EXTRAS_COORDS, coordsIntent); + mapIntent.putExtra(Intents.EXTRA_COORDS, coordsIntent); } - mapIntent.putExtra(EXTRAS_WPTTYPE, waypointTypeIntent != null ? waypointTypeIntent.id : null); - mapIntent.putExtra(EXTRAS_MAP_TITLE, mapTitle); - mapIntent.putExtra(EXTRAS_MAP_MODE, mapMode); - mapIntent.putExtra(EXTRAS_LIVE_ENABLED, isLiveEnabled); + mapIntent.putExtra(Intents.EXTRA_WPTTYPE, waypointTypeIntent != null ? waypointTypeIntent.id : null); + mapIntent.putExtra(Intents.EXTRA_MAP_TITLE, mapTitle); + mapIntent.putExtra(Intents.EXTRA_MAP_MODE, mapMode); + mapIntent.putExtra(Intents.EXTRA_LIVE_ENABLED, isLiveEnabled); final int[] mapState = currentMapState(); if (mapState != null) { - mapIntent.putExtra(EXTRAS_MAPSTATE, mapState); + mapIntent.putExtra(Intents.EXTRA_MAPSTATE, mapState); } // start the new map @@ -1561,41 +1552,41 @@ public class CGeoMap extends AbstractMap implements ViewFactory { public static void startActivitySearch(final Activity fromActivity, final SearchResult search, final String title) { final Intent mapIntent = newIntent(fromActivity); - mapIntent.putExtra(EXTRAS_SEARCH, search); - mapIntent.putExtra(EXTRAS_MAP_MODE, MapMode.LIST); - mapIntent.putExtra(EXTRAS_LIVE_ENABLED, false); + mapIntent.putExtra(Intents.EXTRA_SEARCH, search); + mapIntent.putExtra(Intents.EXTRA_MAP_MODE, MapMode.LIST); + mapIntent.putExtra(Intents.EXTRA_LIVE_ENABLED, false); if (StringUtils.isNotBlank(title)) { - mapIntent.putExtra(CGeoMap.EXTRAS_MAP_TITLE, title); + mapIntent.putExtra(Intents.EXTRA_MAP_TITLE, title); } fromActivity.startActivity(mapIntent); } public static Intent getLiveMapIntent(final Activity fromActivity) { return newIntent(fromActivity) - .putExtra(EXTRAS_MAP_MODE, MapMode.LIVE) - .putExtra(EXTRAS_LIVE_ENABLED, true); + .putExtra(Intents.EXTRA_MAP_MODE, MapMode.LIVE) + .putExtra(Intents.EXTRA_LIVE_ENABLED, true); } public static void startActivityCoords(final Activity fromActivity, final Geopoint coords, final WaypointType type, final String title) { final Intent mapIntent = newIntent(fromActivity); - mapIntent.putExtra(EXTRAS_MAP_MODE, MapMode.COORDS); - mapIntent.putExtra(EXTRAS_LIVE_ENABLED, false); - mapIntent.putExtra(EXTRAS_COORDS, coords); + mapIntent.putExtra(Intents.EXTRA_MAP_MODE, MapMode.COORDS); + mapIntent.putExtra(Intents.EXTRA_LIVE_ENABLED, false); + mapIntent.putExtra(Intents.EXTRA_COORDS, coords); if (type != null) { - mapIntent.putExtra(EXTRAS_WPTTYPE, type.id); + mapIntent.putExtra(Intents.EXTRA_WPTTYPE, type.id); } if (StringUtils.isNotBlank(title)) { - mapIntent.putExtra(EXTRAS_MAP_TITLE, title); + mapIntent.putExtra(Intents.EXTRA_MAP_TITLE, title); } fromActivity.startActivity(mapIntent); } public static void startActivityGeoCode(final Activity fromActivity, final String geocode) { final Intent mapIntent = newIntent(fromActivity); - mapIntent.putExtra(EXTRAS_MAP_MODE, MapMode.SINGLE); - mapIntent.putExtra(EXTRAS_LIVE_ENABLED, false); - mapIntent.putExtra(EXTRAS_GEOCODE, geocode); - mapIntent.putExtra(EXTRAS_MAP_TITLE, geocode); + mapIntent.putExtra(Intents.EXTRA_MAP_MODE, MapMode.SINGLE); + mapIntent.putExtra(Intents.EXTRA_LIVE_ENABLED, false); + mapIntent.putExtra(Intents.EXTRA_GEOCODE, geocode); + mapIntent.putExtra(Intents.EXTRA_MAP_TITLE, geocode); fromActivity.startActivity(mapIntent); } -- cgit v1.1 From 66ab1f4bb25c2f3961ed92810e0b339afdf0c6d7 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sun, 24 Aug 2014 13:01:28 +0200 Subject: refactoring: remove utility methods from DirectionProvider --- main/src/cgeo/geocaching/maps/CGeoMap.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index ea7d308..16ca0bf 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -32,7 +32,6 @@ import cgeo.geocaching.maps.interfaces.MapProvider; import cgeo.geocaching.maps.interfaces.MapSource; import cgeo.geocaching.maps.interfaces.MapViewImpl; import cgeo.geocaching.maps.interfaces.OnMapDragListener; -import cgeo.geocaching.sensors.DirectionProvider; import cgeo.geocaching.sensors.GeoDirHandler; import cgeo.geocaching.sensors.IGeoData; import cgeo.geocaching.settings.Settings; @@ -915,7 +914,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { @Override public void updateGeoDir(final IGeoData geo, final float dir) { currentLocation = geo.getLocation(); - currentHeading = DirectionProvider.getDirectionNow(dir); + currentHeading = AngleUtils.getDirectionNow(dir); repaintPositionOverlay(); } -- cgit v1.1 From 29ce5d0b3d316a8deececa1cfcc9d3553ff8fa70 Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Tue, 26 Aug 2014 20:53:02 +0200 Subject: fix #4221: respect "live" toggle when starting live map --- main/src/cgeo/geocaching/maps/CGeoMap.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 16ca0bf..c9894e2 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -1563,7 +1563,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { public static Intent getLiveMapIntent(final Activity fromActivity) { return newIntent(fromActivity) .putExtra(Intents.EXTRA_MAP_MODE, MapMode.LIVE) - .putExtra(Intents.EXTRA_LIVE_ENABLED, true); + .putExtra(Intents.EXTRA_LIVE_ENABLED, Settings.isLiveMap()); } public static void startActivityCoords(final Activity fromActivity, final Geopoint coords, final WaypointType type, final String title) { -- cgit v1.1 From 9fab22819d5348f8e59d098b79cf8f23259af06e Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Tue, 26 Aug 2014 20:40:48 +0200 Subject: Get the initial location from Android at startup time --- main/src/cgeo/geocaching/maps/CGeoMap.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index c9894e2..4b91fff 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -898,7 +898,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { // minimum change of location in fraction of map width/height (whatever is smaller) for position overlay update private static final float MIN_LOCATION_DELTA = 0.01f; - Location currentLocation = new Location(""); + Location currentLocation = CgeoApplication.getInstance().currentGeo().getLocation(); float currentHeading; private long timeLastPositionOverlayCalculation = 0; -- cgit v1.1 From e9c93380f8eda43671236e2cdb6a96468bbfcd24 Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Sat, 6 Sep 2014 06:34:49 +0200 Subject: fix #4244: different zoom for normal map and map of single cache --- main/src/cgeo/geocaching/maps/CGeoMap.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index d257cc6..b27693b 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -459,7 +459,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { mapView.repaintRequired(null); - setZoom(Settings.getMapZoom()); + setZoom(Settings.getMapZoom(mapMode)); mapView.getMapController().setCenter(Settings.getMapCenter()); if (null == mapStateIntent) { @@ -886,7 +886,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { } private void savePrefs() { - Settings.setMapZoom(mapView.getMapZoomLevel()); + Settings.setMapZoom(mapMode, mapView.getMapZoomLevel()); Settings.setMapCenter(mapView.getMapViewCenter()); } -- cgit v1.1 From f68437aa50c15bc8d2958589fdc4f38c1a79a38c Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Tue, 9 Sep 2014 13:49:17 +0200 Subject: Include exception stack trace in error message --- main/src/cgeo/geocaching/maps/CGeoMap.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index b27693b..7750c71 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -955,7 +955,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { } } } catch (final RuntimeException e) { - Log.w("Failed to update location."); + Log.w("Failed to update location", e); } } } -- cgit v1.1 From 789130734996ee989e534d7b841fc71a23063002 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Tue, 9 Sep 2014 13:52:19 +0200 Subject: Name ignored catch parameter as such --- main/src/cgeo/geocaching/maps/MapProviderFactory.java | 2 +- main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java | 2 +- main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/MapProviderFactory.java b/main/src/cgeo/geocaching/maps/MapProviderFactory.java index 212188d..a640847 100644 --- a/main/src/cgeo/geocaching/maps/MapProviderFactory.java +++ b/main/src/cgeo/geocaching/maps/MapProviderFactory.java @@ -42,7 +42,7 @@ public class MapProviderFactory { // Check if API is available try { Class.forName("com.google.android.maps.MapActivity"); - } catch (final ClassNotFoundException e) { + } catch (final ClassNotFoundException ignored) { return false; } diff --git a/main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java b/main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java index c611790..b07f561 100644 --- a/main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java +++ b/main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java @@ -83,7 +83,7 @@ public class GoogleMapView extends MapView implements MapViewImpl { controller.getZoomControls().setLayoutParams(zoomParams); super.displayZoomControls(takeFocus); - } catch (NoSuchMethodException e) { + } catch (NoSuchMethodException ignored) { Log.w("GoogleMapView.displayZoomControls: unable to explicitly place the zoom buttons"); } catch (Exception e) { Log.e("GoogleMapView.displayZoomControls", e); diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java index d95cc80..81dafb4 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java @@ -234,7 +234,7 @@ public class MapsforgeMapView extends MapView implements MapViewImpl { if (StringUtils.isNotEmpty(customRenderTheme)) { try { setRenderTheme(new File(customRenderTheme)); - } catch (FileNotFoundException e) { + } catch (FileNotFoundException ignored) { Toast.makeText( getContext(), getContext().getResources().getString(R.string.warn_rendertheme_missing), -- cgit v1.1 From e5786079235ce14f0373c1b631c091a0b281f051 Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Sun, 12 Oct 2014 09:00:43 +0200 Subject: fix #4414: Enable total number of caches in live map only with debug setting --- main/src/cgeo/geocaching/maps/CGeoMap.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 91abc9a..bc9ba2f 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -225,7 +225,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { map.countVisibleCaches(); if (!map.caches.isEmpty() && !map.mapTitle.contains("[")) { title.append(" [").append(map.cachesCnt); - if (map.cachesCnt != map.caches.size()) { + if (map.cachesCnt != map.caches.size() && Settings.isDebug()) { title.append('/').append(map.caches.size()); } title.append(']'); -- cgit v1.1 From 49e8d591b4628b916ff3dc1a55da1bcf75c35407 Mon Sep 17 00:00:00 2001 From: Yu Lin Date: Mon, 20 Oct 2014 19:51:14 -0500 Subject: put db access at 1 place into async task --- main/src/cgeo/geocaching/maps/CGeoMap.java | 33 ++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index bc9ba2f..25d4785 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -61,6 +61,7 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.res.Resources; import android.location.Location; +import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; import android.os.Handler; @@ -521,18 +522,28 @@ public class CGeoMap extends AbstractMap implements ViewFactory { resumeSubscription = Subscriptions.from(geoDirUpdate.start(GeoDirHandler.UPDATE_GEODIR), startTimer()); if (!CollectionUtils.isEmpty(dirtyCaches)) { - for (final String geocode : dirtyCaches) { - final Geocache cache = DataStore.loadCache(geocode, LoadFlags.LOAD_WAYPOINTS); - if (cache != null) { - // new collection type needs to remove first - caches.remove(cache); - // re-add to update the freshness - caches.add(cache); + new AsyncTask() { + @Override + public Void doInBackground(final Void... params) { + for (final String geocode : dirtyCaches) { + final Geocache cache = DataStore.loadCache(geocode, LoadFlags.LOAD_WAYPOINTS); + if (cache != null) { + // new collection type needs to remove first + caches.remove(cache); + // re-add to update the freshness + caches.add(cache); + } + } + return null; } - } - dirtyCaches.clear(); - // Update display - displayExecutor.execute(new DisplayRunnable(this)); + + @Override + public void onPostExecute(final Void result) { + dirtyCaches.clear(); + // Update display + displayExecutor.execute(new DisplayRunnable(CGeoMap.this)); + } + }.execute(); } } -- cgit v1.1 From 7c95d28947a9ed8f003bfaef147f2fb72dc4b6ab Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Sun, 2 Nov 2014 11:07:28 +0100 Subject: rename package The package not only contains the GeoPoint definition, but other location related classes, too. --- main/src/cgeo/geocaching/maps/CGeoMap.java | 4 ++-- main/src/cgeo/geocaching/maps/CachesOverlay.java | 2 +- main/src/cgeo/geocaching/maps/PositionDrawer.java | 2 +- main/src/cgeo/geocaching/maps/ScaleDrawer.java | 4 ++-- main/src/cgeo/geocaching/maps/google/v1/GoogleGeoPoint.java | 2 +- main/src/cgeo/geocaching/maps/google/v1/GoogleMapItemFactory.java | 2 +- main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java | 2 +- main/src/cgeo/geocaching/maps/interfaces/MapItemFactory.java | 2 +- main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java | 2 +- main/src/cgeo/geocaching/maps/mapsforge/MapsforgeGeoPoint.java | 2 +- main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapItemFactory.java | 2 +- main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java | 2 +- main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeGeoPoint.java | 2 +- .../geocaching/maps/mapsforge/v024/MapsforgeMapItemFactory024.java | 2 +- main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java | 2 +- 15 files changed, 17 insertions(+), 17 deletions(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 25d4785..0f3337c 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -20,9 +20,9 @@ import cgeo.geocaching.enumerations.LiveMapStrategy.Strategy; import cgeo.geocaching.enumerations.LoadFlags; import cgeo.geocaching.enumerations.LoadFlags.RemoveFlag; import cgeo.geocaching.enumerations.WaypointType; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.Viewport; import cgeo.geocaching.list.StoredList; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.Viewport; import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import cgeo.geocaching.maps.interfaces.MapActivityImpl; diff --git a/main/src/cgeo/geocaching/maps/CachesOverlay.java b/main/src/cgeo/geocaching/maps/CachesOverlay.java index 3c6109e..96912ab 100644 --- a/main/src/cgeo/geocaching/maps/CachesOverlay.java +++ b/main/src/cgeo/geocaching/maps/CachesOverlay.java @@ -10,7 +10,7 @@ import cgeo.geocaching.activity.Progress; import cgeo.geocaching.connector.gc.GCMap; import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.enumerations.LoadFlags; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import cgeo.geocaching.maps.interfaces.ItemizedOverlayImpl; diff --git a/main/src/cgeo/geocaching/maps/PositionDrawer.java b/main/src/cgeo/geocaching/maps/PositionDrawer.java index 08244ef..6a45e62 100644 --- a/main/src/cgeo/geocaching/maps/PositionDrawer.java +++ b/main/src/cgeo/geocaching/maps/PositionDrawer.java @@ -2,7 +2,7 @@ package cgeo.geocaching.maps; import cgeo.geocaching.CgeoApplication; import cgeo.geocaching.R; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import cgeo.geocaching.maps.interfaces.MapItemFactory; import cgeo.geocaching.maps.interfaces.MapProjectionImpl; diff --git a/main/src/cgeo/geocaching/maps/ScaleDrawer.java b/main/src/cgeo/geocaching/maps/ScaleDrawer.java index 95c987d..04398b4 100644 --- a/main/src/cgeo/geocaching/maps/ScaleDrawer.java +++ b/main/src/cgeo/geocaching/maps/ScaleDrawer.java @@ -1,8 +1,8 @@ package cgeo.geocaching.maps; import cgeo.geocaching.CgeoApplication; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.Units; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.Units; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import cgeo.geocaching.maps.interfaces.MapViewImpl; diff --git a/main/src/cgeo/geocaching/maps/google/v1/GoogleGeoPoint.java b/main/src/cgeo/geocaching/maps/google/v1/GoogleGeoPoint.java index 2f540ad..7fbfac2 100644 --- a/main/src/cgeo/geocaching/maps/google/v1/GoogleGeoPoint.java +++ b/main/src/cgeo/geocaching/maps/google/v1/GoogleGeoPoint.java @@ -1,6 +1,6 @@ package cgeo.geocaching.maps.google.v1; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import com.google.android.maps.GeoPoint; diff --git a/main/src/cgeo/geocaching/maps/google/v1/GoogleMapItemFactory.java b/main/src/cgeo/geocaching/maps/google/v1/GoogleMapItemFactory.java index d7e9380..5fedf69 100644 --- a/main/src/cgeo/geocaching/maps/google/v1/GoogleMapItemFactory.java +++ b/main/src/cgeo/geocaching/maps/google/v1/GoogleMapItemFactory.java @@ -1,7 +1,7 @@ package cgeo.geocaching.maps.google.v1; import cgeo.geocaching.IWaypoint; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import cgeo.geocaching.maps.interfaces.MapItemFactory; diff --git a/main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java b/main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java index b07f561..d474e1d 100644 --- a/main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java +++ b/main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java @@ -2,7 +2,7 @@ package cgeo.geocaching.maps.google.v1; import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; -import cgeo.geocaching.geopoint.Viewport; +import cgeo.geocaching.location.Viewport; import cgeo.geocaching.maps.CachesOverlay; import cgeo.geocaching.maps.PositionAndScaleOverlay; import cgeo.geocaching.maps.interfaces.GeneralOverlay; diff --git a/main/src/cgeo/geocaching/maps/interfaces/MapItemFactory.java b/main/src/cgeo/geocaching/maps/interfaces/MapItemFactory.java index 22c6698..f69de03 100644 --- a/main/src/cgeo/geocaching/maps/interfaces/MapItemFactory.java +++ b/main/src/cgeo/geocaching/maps/interfaces/MapItemFactory.java @@ -1,7 +1,7 @@ package cgeo.geocaching.maps.interfaces; import cgeo.geocaching.IWaypoint; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; public interface MapItemFactory { diff --git a/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java b/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java index 4a6d733..0560ad4 100644 --- a/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java +++ b/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java @@ -1,6 +1,6 @@ package cgeo.geocaching.maps.interfaces; -import cgeo.geocaching.geopoint.Viewport; +import cgeo.geocaching.location.Viewport; import cgeo.geocaching.maps.CachesOverlay; import cgeo.geocaching.maps.PositionAndScaleOverlay; diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeGeoPoint.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeGeoPoint.java index 197bd76..298cb90 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeGeoPoint.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeGeoPoint.java @@ -1,6 +1,6 @@ package cgeo.geocaching.maps.mapsforge; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import org.mapsforge.core.GeoPoint; diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapItemFactory.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapItemFactory.java index 4ade09c..ccfd023 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapItemFactory.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapItemFactory.java @@ -1,7 +1,7 @@ package cgeo.geocaching.maps.mapsforge; import cgeo.geocaching.IWaypoint; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import cgeo.geocaching.maps.interfaces.MapItemFactory; diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java index 81dafb4..73d87b0 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java @@ -1,7 +1,7 @@ package cgeo.geocaching.maps.mapsforge; import cgeo.geocaching.R; -import cgeo.geocaching.geopoint.Viewport; +import cgeo.geocaching.location.Viewport; import cgeo.geocaching.maps.CachesOverlay; import cgeo.geocaching.maps.PositionAndScaleOverlay; import cgeo.geocaching.maps.interfaces.GeneralOverlay; diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeGeoPoint.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeGeoPoint.java index c801e3f..72aceb0 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeGeoPoint.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeGeoPoint.java @@ -1,6 +1,6 @@ package cgeo.geocaching.maps.mapsforge.v024; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import org.mapsforge.android.mapsold.GeoPoint; diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapItemFactory024.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapItemFactory024.java index 4f1d34c..23d94d9 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapItemFactory024.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapItemFactory024.java @@ -1,7 +1,7 @@ package cgeo.geocaching.maps.mapsforge.v024; import cgeo.geocaching.IWaypoint; -import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import cgeo.geocaching.maps.interfaces.MapItemFactory; diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java index 8dd15fc..42c55fe 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java @@ -1,7 +1,7 @@ package cgeo.geocaching.maps.mapsforge.v024; import cgeo.geocaching.R; -import cgeo.geocaching.geopoint.Viewport; +import cgeo.geocaching.location.Viewport; import cgeo.geocaching.maps.CachesOverlay; import cgeo.geocaching.maps.PositionAndScaleOverlay; import cgeo.geocaching.maps.interfaces.GeneralOverlay; -- cgit v1.1 From 0aaa9ab5d6aaa30e714c674e4111a7f86d7da039 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Thu, 6 Nov 2014 19:06:15 +0100 Subject: Initialize fields early --- main/src/cgeo/geocaching/maps/CGeoMap.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 0f3337c..7f02d24 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -135,12 +135,12 @@ public class CGeoMap extends AbstractMap implements ViewFactory { private CgeoApplication app; private MapItemFactory mapItemFactory; private String mapTitle; - private LeastRecentlyUsedSet caches; + final private LeastRecentlyUsedSet caches = new LeastRecentlyUsedSet<>(MAX_CACHES + DataStore.getAllCachesCount()); private MapViewImpl mapView; private CachesOverlay overlayCaches; private PositionAndScaleOverlay overlayPositionAndScale; - final private GeoDirHandler geoDirUpdate; + final private GeoDirHandler geoDirUpdate = new UpdateLoc(this); private SearchResult searchIntent = null; private String geocodeIntent = null; private Geopoint coordsIntent = null; @@ -357,7 +357,6 @@ public class CGeoMap extends AbstractMap implements ViewFactory { public CGeoMap(final MapActivityImpl activity) { super(activity); - geoDirUpdate = new UpdateLoc(this); } protected void countVisibleCaches() { @@ -382,9 +381,6 @@ public class CGeoMap extends AbstractMap implements ViewFactory { activity = this.getActivity(); app = (CgeoApplication) activity.getApplication(); - final int countBubbleCnt = DataStore.getAllCachesCount(); - caches = new LeastRecentlyUsedSet<>(MAX_CACHES + countBubbleCnt); - final MapProvider mapProvider = Settings.getMapProvider(); mapItemFactory = mapProvider.getMapItemFactory(); -- cgit v1.1 From 7b1bbc16efe63e887b2211c48e3c727579ea0d6f Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Mon, 10 Nov 2014 20:26:21 +0100 Subject: refactoring: move LiveMapStrategy enums to map --- main/src/cgeo/geocaching/maps/CGeoMap.java | 2 +- main/src/cgeo/geocaching/maps/LiveMapStrategy.java | 48 ++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 main/src/cgeo/geocaching/maps/LiveMapStrategy.java (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 7f02d24..ea3ceec 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -16,13 +16,13 @@ import cgeo.geocaching.connector.gc.GCLogin; import cgeo.geocaching.connector.gc.MapTokens; import cgeo.geocaching.connector.gc.Tile; import cgeo.geocaching.enumerations.CacheType; -import cgeo.geocaching.enumerations.LiveMapStrategy.Strategy; import cgeo.geocaching.enumerations.LoadFlags; import cgeo.geocaching.enumerations.LoadFlags.RemoveFlag; import cgeo.geocaching.enumerations.WaypointType; import cgeo.geocaching.list.StoredList; import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.location.Viewport; +import cgeo.geocaching.maps.LiveMapStrategy.Strategy; import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import cgeo.geocaching.maps.interfaces.MapActivityImpl; diff --git a/main/src/cgeo/geocaching/maps/LiveMapStrategy.java b/main/src/cgeo/geocaching/maps/LiveMapStrategy.java new file mode 100644 index 0000000..16d5e8b --- /dev/null +++ b/main/src/cgeo/geocaching/maps/LiveMapStrategy.java @@ -0,0 +1,48 @@ +package cgeo.geocaching.maps; + +import cgeo.geocaching.CgeoApplication; +import cgeo.geocaching.R; + +import java.util.EnumSet; + +/** + * Defines the strategy for the Live Map + */ +public interface LiveMapStrategy { + + public enum StrategyFlag { + LOAD_TILES, // 2x2 tiles filling the complete viewport + PARSE_TILES, // parse PNG images + SEARCH_NEARBY // searchByCoords() + } + + public enum Strategy { + FASTEST(1, EnumSet.of(StrategyFlag.LOAD_TILES), R.string.map_strategy_fastest), + FAST(2, EnumSet.of(StrategyFlag.LOAD_TILES, StrategyFlag.PARSE_TILES), R.string.map_strategy_fast), + AUTO(3, EnumSet.noneOf(StrategyFlag.class), R.string.map_strategy_auto), + DETAILED(4, EnumSet.allOf(StrategyFlag.class), R.string.map_strategy_detailed); + + public final int id; + public final EnumSet flags; + private final int stringId; + + Strategy(int id, EnumSet flags, int stringId) { + this.id = id; + this.flags = flags; + this.stringId = stringId; + } + + public static Strategy getById(final int id) { + for (Strategy strategy : Strategy.values()) { + if (strategy.id == id) { + return strategy; + } + } + return AUTO; + } + + public final String getL10n() { + return CgeoApplication.getInstance().getBaseContext().getResources().getString(stringId); + } + } +} -- cgit v1.1 From e32c7498d5932a87f6289136201c6e3308565d49 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sun, 23 Nov 2014 13:22:22 +0100 Subject: progress cannot be null --- main/src/cgeo/geocaching/maps/CachesOverlay.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CachesOverlay.java b/main/src/cgeo/geocaching/maps/CachesOverlay.java index 96912ab..c4c4465 100644 --- a/main/src/cgeo/geocaching/maps/CachesOverlay.java +++ b/main/src/cgeo/geocaching/maps/CachesOverlay.java @@ -255,9 +255,7 @@ public class CachesOverlay extends AbstractItemizedOverlay { progress.dismiss(); } catch (NotFoundException e) { Log.e("CachesOverlay.onTap", e); - if (progress != null) { - progress.dismiss(); - } + progress.dismiss(); } return true; -- cgit v1.1 From 4c5f4a1991c129ec03aa8978bf107c34ebbbee73 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sun, 23 Nov 2014 14:27:57 +0100 Subject: Remove used-once interface IGeoData IGeoData was only implemented by the GeoData class. We can as well use it directly. --- main/src/cgeo/geocaching/maps/CGeoMap.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index ea3ceec..233f0e6 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -32,8 +32,8 @@ import cgeo.geocaching.maps.interfaces.MapProvider; import cgeo.geocaching.maps.interfaces.MapSource; import cgeo.geocaching.maps.interfaces.MapViewImpl; import cgeo.geocaching.maps.interfaces.OnMapDragListener; +import cgeo.geocaching.sensors.GeoData; import cgeo.geocaching.sensors.GeoDirHandler; -import cgeo.geocaching.sensors.IGeoData; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.ui.dialog.LiveMapInfoDialogBuilder; import cgeo.geocaching.utils.AngleUtils; @@ -896,7 +896,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { } // Set center of map to my location if appropriate. - private void myLocationInMiddle(final IGeoData geo) { + private void myLocationInMiddle(final GeoData geo) { if (followMyLocation) { centerMap(geo.getCoords()); } @@ -927,7 +927,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { } @Override - public void updateGeoDir(final IGeoData geo, final float dir) { + public void updateGeoDir(final GeoData geo, final float dir) { currentLocation = geo.getLocation(); currentHeading = AngleUtils.getDirectionNow(dir); repaintPositionOverlay(); -- cgit v1.1 From 847a9777dc1a81b10f456009cee326d47fd3710d Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sun, 23 Nov 2014 14:31:08 +0100 Subject: Remove identity method GeoData#getLocation() --- main/src/cgeo/geocaching/maps/CGeoMap.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 233f0e6..7cb3183 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -913,7 +913,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { // minimum change of location in fraction of map width/height (whatever is smaller) for position overlay update private static final float MIN_LOCATION_DELTA = 0.01f; - Location currentLocation = CgeoApplication.getInstance().currentGeo().getLocation(); + Location currentLocation = CgeoApplication.getInstance().currentGeo(); float currentHeading; private long timeLastPositionOverlayCalculation = 0; @@ -928,7 +928,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { @Override public void updateGeoDir(final GeoData geo, final float dir) { - currentLocation = geo.getLocation(); + currentLocation = geo; currentHeading = AngleUtils.getDirectionNow(dir); repaintPositionOverlay(); } -- cgit v1.1 From 6c478f349a88a7c46f8ff4941692cf2c5f0ecea3 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sun, 23 Nov 2014 17:53:46 +0100 Subject: Fix Javadoc bogus references --- main/src/cgeo/geocaching/maps/CGeoMap.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 7cb3183..292808d 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -1002,7 +1002,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { } /** - * Starts the {@link LoadTimer}. + * Starts the load timer. */ private Subscription startTimer() { @@ -1081,7 +1081,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { /** * Worker thread that loads caches and waypoints from the database and then spawns the {@link DownloadRunnable}. - * started by {@link LoadTimer} + * started by the load timer. */ private static class LoadRunnable extends DoRunnable { -- cgit v1.1 From b568a4393e9797861dbffaf9b016049c101078ff Mon Sep 17 00:00:00 2001 From: rsudev Date: Thu, 27 Nov 2014 21:20:41 +0100 Subject: Fix #4247, No action bar on map activities on Android 3.x Enable 2.x implementation for 3.x. as well. Additionally fix options menu for 3.x --- main/src/cgeo/geocaching/maps/AbstractMap.java | 12 +++---- main/src/cgeo/geocaching/maps/CGeoMap.java | 46 ++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 8 deletions(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/AbstractMap.java b/main/src/cgeo/geocaching/maps/AbstractMap.java index 2eceadb..f62fb3a 100644 --- a/main/src/cgeo/geocaching/maps/AbstractMap.java +++ b/main/src/cgeo/geocaching/maps/AbstractMap.java @@ -19,7 +19,7 @@ public abstract class AbstractMap { MapActivityImpl mapActivity; - protected AbstractMap(MapActivityImpl activity) { + protected AbstractMap(final MapActivityImpl activity) { mapActivity = activity; } @@ -31,10 +31,10 @@ public abstract class AbstractMap { return mapActivity.getActivity(); } - public void onCreate(Bundle savedInstanceState) { + public void onCreate(final Bundle savedInstanceState) { mapActivity.superOnCreate(savedInstanceState); - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) { + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH) { mapActivity.getActivity().requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); } } @@ -55,17 +55,17 @@ public abstract class AbstractMap { mapActivity.superOnDestroy(); } - public boolean onCreateOptionsMenu(Menu menu) { + public boolean onCreateOptionsMenu(final Menu menu) { final boolean result = mapActivity.superOnCreateOptionsMenu(menu); mapActivity.getActivity().getMenuInflater().inflate(R.menu.map_activity, menu); return result; } - public boolean onPrepareOptionsMenu(Menu menu) { + public boolean onPrepareOptionsMenu(final Menu menu) { return mapActivity.superOnPrepareOptionsMenu(menu); } - public boolean onOptionsItemSelected(MenuItem item) { + public boolean onOptionsItemSelected(final MenuItem item) { return mapActivity.superOnOptionsItemSelected(item); } diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 292808d..2868679 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -67,6 +67,7 @@ import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.view.Menu; +import android.view.MenuInflater; import android.view.MenuItem; import android.view.SubMenu; import android.view.View; @@ -182,6 +183,8 @@ public class CGeoMap extends AbstractMap implements ViewFactory { private boolean centered = false; // if map is already centered private boolean alreadyCentered = false; // -""- for setting my location private static final Set dirtyCaches = new HashSet<>(); + // flag for honeycomb special popup menu handling + private boolean honeycombMenu = false; /** * if live map is enabled, this is the minimum zoom level, independent of the stored setting @@ -476,6 +479,18 @@ public class CGeoMap extends AbstractMap implements ViewFactory { } prepareFilterBar(); + // Check for Honeycomb fake overflow button and attach popup + final View overflowActionBar = ButterKnife.findById(activity, R.id.overflowActionBar); + if (overflowActionBar != null) { + honeycombMenu = true; + overflowActionBar.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(final View v) { + showPopupHoneycomb(v); + } + }); + } + if (!app.isLiveMapHintShownInThisSession() && Settings.getLiveMapHintShowCount() <= 3) { LiveMapInfoDialogBuilder.create(activity).show(); } @@ -563,10 +578,37 @@ public class CGeoMap extends AbstractMap implements ViewFactory { } @TargetApi(Build.VERSION_CODES.HONEYCOMB) + private void showPopupHoneycomb(final View view) { + // Inflate the core menu ourselves + final android.widget.PopupMenu popupMenu = new android.widget.PopupMenu(getActivity(), view); + final MenuInflater inflater = new MenuInflater(getActivity()); + inflater.inflate(R.menu.map_activity, popupMenu.getMenu()); + + // continue processing menu items as usual + onCreateOptionsMenu(popupMenu.getMenu()); + + onPrepareOptionsMenu(popupMenu.getMenu()); + + popupMenu.setOnMenuItemClickListener( + new android.widget.PopupMenu.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(final MenuItem item) { + return onOptionsItemSelected(item); + } + } + ); + // display menu + popupMenu.show(); + } + + @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override public boolean onCreateOptionsMenu(final Menu menu) { // menu inflation happens in Google/Mapsforge specific classes - super.onCreateOptionsMenu(menu); + // skip it for honeycomb - handled specially in @see showPopupHoneycomb + if (!honeycombMenu) { + super.onCreateOptionsMenu(menu); + } MapProviderFactory.addMapviewMenuItems(menu); @@ -574,7 +616,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { subMenuStrategy.setHeaderTitle(res.getString(R.string.map_strategy_title)); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { /* if we have an Actionbar find the my position toggle */ final MenuItem item = menu.findItem(R.id.menu_toggle_mypos); myLocSwitch = new CheckBox(activity); -- cgit v1.1 From bf3d875b0f2998a1bb50483cad6ec7d7f3c05e42 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sun, 21 Dec 2014 23:49:25 +0100 Subject: Use GPS when compass is disabled or absent Work on #4548. --- main/src/cgeo/geocaching/maps/CGeoMap.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 2868679..f2a5146 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -34,6 +34,7 @@ import cgeo.geocaching.maps.interfaces.MapViewImpl; import cgeo.geocaching.maps.interfaces.OnMapDragListener; import cgeo.geocaching.sensors.GeoData; import cgeo.geocaching.sensors.GeoDirHandler; +import cgeo.geocaching.sensors.Sensors; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.ui.dialog.LiveMapInfoDialogBuilder; import cgeo.geocaching.utils.AngleUtils; @@ -133,7 +134,6 @@ public class CGeoMap extends AbstractMap implements ViewFactory { // Those are initialized in onCreate() and will never be null afterwards private Resources res; private Activity activity; - private CgeoApplication app; private MapItemFactory mapItemFactory; private String mapTitle; final private LeastRecentlyUsedSet caches = new LeastRecentlyUsedSet<>(MAX_CACHES + DataStore.getAllCachesCount()); @@ -382,7 +382,6 @@ public class CGeoMap extends AbstractMap implements ViewFactory { // class init res = this.getResources(); activity = this.getActivity(); - app = (CgeoApplication) activity.getApplication(); final MapProvider mapProvider = Settings.getMapProvider(); mapItemFactory = mapProvider.getMapItemFactory(); @@ -491,7 +490,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { }); } - if (!app.isLiveMapHintShownInThisSession() && Settings.getLiveMapHintShowCount() <= 3) { + if (!CgeoApplication.getInstance().isLiveMapHintShownInThisSession() && Settings.getLiveMapHintShowCount() <= 3) { LiveMapInfoDialogBuilder.create(activity).show(); } } @@ -955,7 +954,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { // minimum change of location in fraction of map width/height (whatever is smaller) for position overlay update private static final float MIN_LOCATION_DELTA = 0.01f; - Location currentLocation = CgeoApplication.getInstance().currentGeo(); + Location currentLocation = Sensors.getInstance().currentGeo(); float currentHeading; private long timeLastPositionOverlayCalculation = 0; @@ -1539,7 +1538,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { if (myLocSwitch != null) { myLocSwitch.setChecked(followMyLocation); if (followMyLocation) { - myLocationInMiddle(app.currentGeo()); + myLocationInMiddle(Sensors.getInstance().currentGeo()); } } } -- cgit v1.1 From 2549e4bf0e2dc21b9e3ac15469ca34d16b53e9b3 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sat, 10 Jan 2015 18:45:26 +0100 Subject: fix #3078: live map should start at last position except in follow mode --- main/src/cgeo/geocaching/maps/CGeoMap.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index f2a5146..2c5fbf9 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -153,7 +153,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { private MapTokens tokens = null; private boolean noMapTokenShowed = false; // map status data - private boolean followMyLocation = false; + private static boolean followMyLocation = true; // threads private Subscription loadTimer; private LoadDetails loadDetailsThread = null; @@ -460,7 +460,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { mapView.getMapController().setCenter(Settings.getMapCenter()); if (null == mapStateIntent) { - followMyLocation = mapMode == MapMode.LIVE; + followMyLocation &= mapMode != MapMode.LIVE; } else { followMyLocation = 1 == mapStateIntent[3]; if ((overlayCaches.getCircles() ? 1 : 0) != mapStateIntent[4]) { -- cgit v1.1 From dd4ac8b7418540b56ab3112c5eb6e1f7f8be5820 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sat, 10 Jan 2015 19:01:46 +0100 Subject: Make the test the right way --- main/src/cgeo/geocaching/maps/CGeoMap.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 2c5fbf9..18826a4 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -460,7 +460,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { mapView.getMapController().setCenter(Settings.getMapCenter()); if (null == mapStateIntent) { - followMyLocation &= mapMode != MapMode.LIVE; + followMyLocation &= mapMode == MapMode.LIVE; } else { followMyLocation = 1 == mapStateIntent[3]; if ((overlayCaches.getCircles() ? 1 : 0) != mapStateIntent[4]) { -- cgit v1.1 From cdbbc5d747e648801fbac19e54982017f11081cd Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Sun, 11 Jan 2015 12:46:13 +0100 Subject: use static accces --- main/src/cgeo/geocaching/maps/CGeoMap.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 18826a4..0fdd038 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -989,7 +989,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { final boolean needsRepaintForHeading = needsRepaintForHeading(); if (needsRepaintForDistanceOrAccuracy) { - if (map.followMyLocation) { + if (CGeoMap.followMyLocation) { map.centerMap(new Geopoint(currentLocation)); } } -- cgit v1.1 From 4dab903b443f4985c4af207faf97de563304fdd6 Mon Sep 17 00:00:00 2001 From: rsudev Date: Fri, 16 Jan 2015 16:31:39 +0100 Subject: Fixes #2687, OSM:Offline: After selecting new map it is opend at map center but not at the previous location - re-apply current position and zoom after changing the source without re-starting the map activity --- main/src/cgeo/geocaching/maps/CGeoMap.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 18826a4..457b06c 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -876,7 +876,12 @@ public class CGeoMap extends AbstractMap implements ViewFactory { if (restartRequired) { mapRestart(); } else if (mapView != null) { // changeMapSource can be called by onCreate() + mapStateIntent = currentMapState(); mapView.setMapSource(); + // re-center the map + centered = false; + centerMap(geocodeIntent, searchIntent, coordsIntent, mapStateIntent); + // re-build menues ActivityMixin.invalidateOptionsMenu(activity); } @@ -887,9 +892,6 @@ public class CGeoMap extends AbstractMap implements ViewFactory { * Restart the current activity with the default map source. */ private void mapRestart() { - // close old mapview - activity.finish(); - // prepare information to restart a similar view final Intent mapIntent = new Intent(activity, Settings.getMapProvider().getMapClass()); @@ -908,6 +910,9 @@ public class CGeoMap extends AbstractMap implements ViewFactory { mapIntent.putExtra(Intents.EXTRA_MAPSTATE, mapState); } + // close old map + activity.finish(); + // start the new map activity.startActivity(mapIntent); } -- cgit v1.1 From 8fbaa36d29ea1934a48f51039bb60eaa1df3f010 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konrad=20Gr=C3=A4fe?= Date: Mon, 26 Jan 2015 21:24:13 +0100 Subject: Add distance overlay to the map view --- main/src/cgeo/geocaching/maps/CGeoMap.java | 10 ++ main/src/cgeo/geocaching/maps/DistanceOverlay.java | 178 +++++++++++++++++++++ .../maps/google/v1/GoogleDistanceOverlay.java | 53 ++++++ .../geocaching/maps/google/v1/GoogleMapView.java | 49 +++--- .../geocaching/maps/interfaces/MapViewImpl.java | 4 + .../maps/mapsforge/MapsforgeDistanceOverlay.java | 56 +++++++ .../maps/mapsforge/MapsforgeMapView.java | 61 ++++--- .../mapsforge/v024/MapsforgeDistanceOverlay.java | 57 +++++++ .../maps/mapsforge/v024/MapsforgeMapView024.java | 55 ++++--- 9 files changed, 454 insertions(+), 69 deletions(-) create mode 100755 main/src/cgeo/geocaching/maps/DistanceOverlay.java create mode 100755 main/src/cgeo/geocaching/maps/google/v1/GoogleDistanceOverlay.java create mode 100755 main/src/cgeo/geocaching/maps/mapsforge/MapsforgeDistanceOverlay.java create mode 100755 main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeDistanceOverlay.java (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 933fdbd..4724566 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -140,6 +140,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { private MapViewImpl mapView; private CachesOverlay overlayCaches; private PositionAndScaleOverlay overlayPositionAndScale; + private DistanceOverlay overlayDistance; final private GeoDirHandler geoDirUpdate = new UpdateLoc(this); private SearchResult searchIntent = null; @@ -454,6 +455,10 @@ public class CGeoMap extends AbstractMap implements ViewFactory { overlayPositionAndScale.setHistory(trailHistory); } + if (coordsIntent != null || geocodeIntent != null) { + overlayDistance = mapView.createAddDistanceOverlay(coordsIntent, geocodeIntent); + } + mapView.repaintRequired(null); setZoom(Settings.getMapZoom(mapMode)); @@ -1003,6 +1008,11 @@ public class CGeoMap extends AbstractMap implements ViewFactory { map.overlayPositionAndScale.setCoordinates(currentLocation); map.overlayPositionAndScale.setHeading(currentHeading); map.mapView.repaintRequired(map.overlayPositionAndScale); + + if (map.overlayDistance != null) { + map.overlayDistance.setCoordinates(currentLocation); + map.mapView.repaintRequired(map.overlayDistance); + } } } } catch (final RuntimeException e) { diff --git a/main/src/cgeo/geocaching/maps/DistanceOverlay.java b/main/src/cgeo/geocaching/maps/DistanceOverlay.java new file mode 100755 index 0000000..211db98 --- /dev/null +++ b/main/src/cgeo/geocaching/maps/DistanceOverlay.java @@ -0,0 +1,178 @@ +package cgeo.geocaching.maps; + +import cgeo.geocaching.CgeoApplication; +import cgeo.geocaching.DataStore; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.Units; +import cgeo.geocaching.location.Viewport; +import cgeo.geocaching.maps.interfaces.GeneralOverlay; +import cgeo.geocaching.maps.interfaces.MapProjectionImpl; +import cgeo.geocaching.maps.interfaces.MapViewImpl; +import cgeo.geocaching.maps.interfaces.OverlayImpl; + +import android.content.Context; +import android.graphics.BlurMaskFilter; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.Point; +import android.graphics.Rect; +import android.graphics.RectF; +import android.graphics.Typeface; +import android.location.Location; +import android.util.DisplayMetrics; +import android.view.WindowManager; + +public class DistanceOverlay implements GeneralOverlay { + private Geopoint currentCoords; + private final Geopoint destinationCoords; + + private Paint paintBox = null; + private Paint paintBoxShadow = null; + private Paint paintText = null; + private Paint paintCompass = null; + private BlurMaskFilter blurBoxShadow = null; + + private final boolean needsInvertedColors; + private float pixelDensity = 0; + private final float boxWidth, boxHeight, boxCornerRadius, boxShadowSize, boxPadding; + private final float textHeight, maxTextWidth; + private final float boxX, boxY; + + private String distanceText = null; + + private OverlayImpl ovlImpl = null; + + public DistanceOverlay(final OverlayImpl ovlImpl, final MapViewImpl mapView, final Geopoint coords, final String geocode) { + this.ovlImpl = ovlImpl; + + if (coords == null) { + final Viewport bounds = DataStore.getBounds(geocode); + if (bounds == null) { + this.destinationCoords = new Geopoint(0, 0); + } else { + this.destinationCoords = bounds.center; + } + } else { + this.destinationCoords = coords; + } + + final DisplayMetrics metrics = new DisplayMetrics(); + final WindowManager windowManager = (WindowManager) CgeoApplication.getInstance().getSystemService(Context.WINDOW_SERVICE); + windowManager.getDefaultDisplay().getMetrics(metrics); + + pixelDensity = metrics.density; + + boxPadding = 2; + boxWidth = 100 * pixelDensity + 3 * boxPadding; + boxHeight = 30 * pixelDensity + 2 * boxPadding; + boxCornerRadius = 5 * pixelDensity; + boxShadowSize = 1 * pixelDensity; + textHeight = 20 * pixelDensity; + + needsInvertedColors = mapView.needsInvertedColors(); + boxX = metrics.widthPixels - boxWidth; + boxY = 0; + + maxTextWidth = boxWidth - 3 * boxPadding; + } + + public void setCoordinates(final Location coordinatesIn) { + currentCoords = new Geopoint(coordinatesIn); + + final float distance = currentCoords.distanceTo(destinationCoords); + distanceText = Units.getDistanceFromKilometers(distance); + } + + @Override + public void draw(final Canvas canvas, final MapViewImpl mapView, final boolean shadow) { + drawInternal(canvas); + } + + @Override + public void drawOverlayBitmap(final Canvas canvas, final Point drawPosition, final MapProjectionImpl projection, final byte drawZoomLevel) { + drawInternal(canvas); + } + + private void drawInternal(final Canvas canvas) { + if (currentCoords == null) { + return; + } + + if (blurBoxShadow == null) { + blurBoxShadow = new BlurMaskFilter(3, BlurMaskFilter.Blur.NORMAL); + } + + if (paintBoxShadow == null) { + paintBoxShadow = new Paint(); + paintBoxShadow.setAntiAlias(true); + paintBoxShadow.setMaskFilter(blurBoxShadow); + } + + if (paintBox == null) { + paintBox = new Paint(); + paintBox.setAntiAlias(true); + } + + if (paintText == null) { + paintText = new Paint(); + paintText.setAntiAlias(true); + paintText.setTextAlign(Paint.Align.LEFT); + paintText.setTypeface(Typeface.DEFAULT_BOLD); + } + + if (paintCompass == null) { + paintCompass = new Paint(Paint.ANTI_ALIAS_FLAG); + paintCompass.setDither(true); + paintCompass.setFilterBitmap(true); + } + + if (needsInvertedColors) { + paintBoxShadow.setColor(0xFF000000); + paintBox.setColor(0xFFFFFFFF); + paintText.setColor(0xFF000000); + } else { + paintBoxShadow.setColor(0xFFFFFFFF); + paintBox.setColor(0xFF000000); + paintText.setColor(0xFFFFFFFF); + } + + /* Calculate text size */ + final Rect textBounds = new Rect(); + paintText.setTextSize(textHeight); + paintText.getTextBounds(distanceText, 0, distanceText.length(), textBounds); + while (textBounds.height() > maxTextWidth) { + paintText.setTextSize(paintText.getTextSize() - 1); + paintText.getTextBounds(distanceText, 0, distanceText.length(), textBounds); + } + + final float textX = (boxWidth - 3 * boxPadding - textBounds.width()) / 2 + boxX + 2 * boxPadding; + final float textY = (boxHeight + textBounds.height()) / 2 + boxY; + + /* Paint background box */ + canvas.drawRoundRect( + new RectF( + boxX - boxShadowSize, boxY - boxShadowSize - boxCornerRadius, + boxX + boxWidth + boxShadowSize + boxCornerRadius, boxY + boxHeight + boxShadowSize + ), + boxCornerRadius, boxCornerRadius, + paintBoxShadow + ); + canvas.drawRoundRect( + new RectF( + boxX, boxY - boxCornerRadius, + boxX + boxWidth + boxCornerRadius, boxY + boxHeight + ), + boxCornerRadius, boxCornerRadius, + paintBox + ); + + /* Paint distance */ + canvas.drawText(distanceText, textX, textY, paintText); + } + + @Override + public OverlayImpl getOverlayImpl() { + return this.ovlImpl; + } + +} diff --git a/main/src/cgeo/geocaching/maps/google/v1/GoogleDistanceOverlay.java b/main/src/cgeo/geocaching/maps/google/v1/GoogleDistanceOverlay.java new file mode 100755 index 0000000..281a6e9 --- /dev/null +++ b/main/src/cgeo/geocaching/maps/google/v1/GoogleDistanceOverlay.java @@ -0,0 +1,53 @@ +package cgeo.geocaching.maps.google.v1; + +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.maps.DistanceOverlay; +import cgeo.geocaching.maps.interfaces.GeneralOverlay; +import cgeo.geocaching.maps.interfaces.MapViewImpl; +import cgeo.geocaching.maps.interfaces.OverlayImpl; + +import com.google.android.maps.MapView; +import com.google.android.maps.Overlay; + +import android.graphics.Canvas; + +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +public class GoogleDistanceOverlay extends Overlay implements OverlayImpl { + + private final DistanceOverlay overlayBase; + private final Lock lock = new ReentrantLock(); + + public GoogleDistanceOverlay(final MapViewImpl mapView, final Geopoint coords, final String geocode) { + overlayBase = new DistanceOverlay(this, mapView, coords, geocode); + } + + @Override + public void draw(final Canvas canvas, final MapView mapView, final boolean shadow) { + super.draw(canvas, mapView, shadow); + + assert mapView instanceof MapViewImpl; + overlayBase.draw(canvas, (MapViewImpl) mapView, shadow); + } + + public GeneralOverlay getBase() { + return overlayBase; + } + + @Override + public void lock() { + lock.lock(); + } + + @Override + public void unlock() { + lock.unlock(); + } + + @Override + public MapViewImpl getMapViewImpl() { + throw new UnsupportedOperationException(); + } + +} diff --git a/main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java b/main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java index d474e1d..08c9ae7 100644 --- a/main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java +++ b/main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java @@ -2,8 +2,10 @@ package cgeo.geocaching.maps.google.v1; import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.location.Viewport; import cgeo.geocaching.maps.CachesOverlay; +import cgeo.geocaching.maps.DistanceOverlay; import cgeo.geocaching.maps.PositionAndScaleOverlay; import cgeo.geocaching.maps.interfaces.GeneralOverlay; import cgeo.geocaching.maps.interfaces.GeoPointImpl; @@ -36,22 +38,22 @@ public class GoogleMapView extends MapView implements MapViewImpl { private OnMapDragListener onDragListener; private final GoogleMapController mapController = new GoogleMapController(getController()); - public GoogleMapView(Context context, AttributeSet attrs) { + public GoogleMapView(final Context context, final AttributeSet attrs) { super(context, attrs); initialize(context); } - public GoogleMapView(Context context, AttributeSet attrs, int defStyle) { + public GoogleMapView(final Context context, final AttributeSet attrs, final int defStyle) { super(context, attrs, defStyle); initialize(context); } - public GoogleMapView(Context context, String apiKey) { + public GoogleMapView(final Context context, final String apiKey) { super(context, apiKey); initialize(context); } - private void initialize(Context context) { + private void initialize(final Context context) { if (isInEditMode()) { return; } @@ -66,16 +68,16 @@ public class GoogleMapView extends MapView implements MapViewImpl { } super.draw(canvas); - } catch (Exception e) { + } catch (final Exception e) { Log.e("GoogleMapView.draw", e); } } @Override - public void displayZoomControls(boolean takeFocus) { + public void displayZoomControls(final boolean takeFocus) { try { // Push zoom controls to the right - FrameLayout.LayoutParams zoomParams = new FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT); + final FrameLayout.LayoutParams zoomParams = new FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT); zoomParams.gravity = Gravity.RIGHT; // The call to retrieve the zoom buttons controller is undocumented and works so far on all devices // supported by Google Play, but fails at least on one Jolla. @@ -83,9 +85,9 @@ public class GoogleMapView extends MapView implements MapViewImpl { controller.getZoomControls().setLayoutParams(zoomParams); super.displayZoomControls(takeFocus); - } catch (NoSuchMethodException ignored) { + } catch (final NoSuchMethodException ignored) { Log.w("GoogleMapView.displayZoomControls: unable to explicitly place the zoom buttons"); - } catch (Exception e) { + } catch (final Exception e) { Log.e("GoogleMapView.displayZoomControls", e); } } @@ -98,7 +100,7 @@ public class GoogleMapView extends MapView implements MapViewImpl { @Override @NonNull public GeoPointImpl getMapViewCenter() { - GeoPoint point = getMapCenter(); + final GeoPoint point = getMapCenter(); return new GoogleGeoPoint(point.getLatitudeE6(), point.getLongitudeE6()); } @@ -118,9 +120,9 @@ public class GoogleMapView extends MapView implements MapViewImpl { } @Override - public CachesOverlay createAddMapOverlay(Context context, Drawable drawable) { + public CachesOverlay createAddMapOverlay(final Context context, final Drawable drawable) { - GoogleCacheOverlay ovl = new GoogleCacheOverlay(context, drawable); + final GoogleCacheOverlay ovl = new GoogleCacheOverlay(context, drawable); getOverlays().add(ovl); return ovl.getBase(); } @@ -128,12 +130,19 @@ public class GoogleMapView extends MapView implements MapViewImpl { @Override public PositionAndScaleOverlay createAddPositionAndScaleOverlay() { - GoogleOverlay ovl = new GoogleOverlay(); + final GoogleOverlay ovl = new GoogleOverlay(); getOverlays().add(ovl); return (PositionAndScaleOverlay) ovl.getBase(); } @Override + public DistanceOverlay createAddDistanceOverlay(final Geopoint coords, final String geocode) { + final GoogleDistanceOverlay ovl = new GoogleDistanceOverlay(this, coords, geocode); + getOverlays().add(ovl); + return (DistanceOverlay) ovl.getBase(); + } + + @Override public int getMapZoomLevel() { return getZoomLevel(); } @@ -144,21 +153,21 @@ public class GoogleMapView extends MapView implements MapViewImpl { } @Override - public void repaintRequired(GeneralOverlay overlay) { + public void repaintRequired(final GeneralOverlay overlay) { invalidate(); } @Override - public void setOnDragListener(OnMapDragListener onDragListener) { + public void setOnDragListener(final OnMapDragListener onDragListener) { this.onDragListener = onDragListener; } @Override - public boolean onTouchEvent(MotionEvent ev) { + public boolean onTouchEvent(final MotionEvent ev) { try { gestureDetector.onTouchEvent(ev); return super.onTouchEvent(ev); - } catch (Exception e) { + } catch (final Exception e) { Log.e("GoogleMapView.onTouchEvent", e); } return false; @@ -166,7 +175,7 @@ public class GoogleMapView extends MapView implements MapViewImpl { private class GestureListener extends SimpleOnGestureListener { @Override - public boolean onDoubleTap(MotionEvent e) { + public boolean onDoubleTap(final MotionEvent e) { getController().zoomInFixing((int) e.getX(), (int) e.getY()); if (onDragListener != null) { onDragListener.onDrag(); @@ -175,8 +184,8 @@ public class GoogleMapView extends MapView implements MapViewImpl { } @Override - public boolean onScroll(MotionEvent e1, MotionEvent e2, - float distanceX, float distanceY) { + public boolean onScroll(final MotionEvent e1, final MotionEvent e2, + final float distanceX, final float distanceY) { if (onDragListener != null) { onDragListener.onDrag(); } diff --git a/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java b/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java index 0560ad4..00a8790 100644 --- a/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java +++ b/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java @@ -1,7 +1,9 @@ package cgeo.geocaching.maps.interfaces; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.location.Viewport; import cgeo.geocaching.maps.CachesOverlay; +import cgeo.geocaching.maps.DistanceOverlay; import cgeo.geocaching.maps.PositionAndScaleOverlay; import org.eclipse.jdt.annotation.NonNull; @@ -48,6 +50,8 @@ public interface MapViewImpl { PositionAndScaleOverlay createAddPositionAndScaleOverlay(); + DistanceOverlay createAddDistanceOverlay(Geopoint coords, String geocode); + void setMapSource(); /** diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeDistanceOverlay.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeDistanceOverlay.java new file mode 100755 index 0000000..ed6b6fb --- /dev/null +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeDistanceOverlay.java @@ -0,0 +1,56 @@ +package cgeo.geocaching.maps.mapsforge; + +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.maps.DistanceOverlay; +import cgeo.geocaching.maps.interfaces.GeneralOverlay; +import cgeo.geocaching.maps.interfaces.MapViewImpl; +import cgeo.geocaching.maps.interfaces.OverlayImpl; + +import org.mapsforge.android.maps.Projection; +import org.mapsforge.android.maps.overlay.Overlay; + +import android.graphics.Canvas; +import android.graphics.Point; + +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +public class MapsforgeDistanceOverlay extends Overlay implements OverlayImpl { + + private DistanceOverlay overlayBase = null; + private final Lock lock = new ReentrantLock(); + + public MapsforgeDistanceOverlay(final MapViewImpl mapView, final Geopoint coords, final String geocode) { + overlayBase = new DistanceOverlay(this, mapView, coords, geocode); + } + + @Override + protected void drawOverlayBitmap(final Canvas canvas, final Point drawPosition, + final Projection projection, final byte drawZoomLevel) { + + if (overlayBase != null) { + overlayBase.drawOverlayBitmap(canvas, drawPosition, new MapsforgeMapProjection(projection), drawZoomLevel); + } + } + + public GeneralOverlay getBase() { + return overlayBase; + } + + @Override + public void lock() { + lock.lock(); + } + + @Override + public void unlock() { + lock.unlock(); + + } + + @Override + public MapViewImpl getMapViewImpl() { + return (MapViewImpl) internalMapView; + } + +} diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java index 73d87b0..dd67a8f 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java @@ -1,8 +1,10 @@ package cgeo.geocaching.maps.mapsforge; import cgeo.geocaching.R; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.location.Viewport; import cgeo.geocaching.maps.CachesOverlay; +import cgeo.geocaching.maps.DistanceOverlay; import cgeo.geocaching.maps.PositionAndScaleOverlay; import cgeo.geocaching.maps.interfaces.GeneralOverlay; import cgeo.geocaching.maps.interfaces.GeoPointImpl; @@ -40,12 +42,12 @@ public class MapsforgeMapView extends MapView implements MapViewImpl { private OnMapDragListener onDragListener; private final MapsforgeMapController mapController = new MapsforgeMapController(getController(), getMapGenerator().getZoomLevelMax()); - public MapsforgeMapView(Context context, AttributeSet attrs) { + public MapsforgeMapView(final Context context, final AttributeSet attrs) { super(context, attrs); initialize(context); } - private void initialize(Context context) { + private void initialize(final Context context) { if (isInEditMode()) { return; } @@ -56,7 +58,7 @@ public class MapsforgeMapView extends MapView implements MapViewImpl { } @Override - public void draw(@NonNull Canvas canvas) { + public void draw(@NonNull final Canvas canvas) { try { // Google Maps and OSM Maps use different zoom levels for the same view. // Here we don't want the Google Maps compatible zoom level, but the actual one. @@ -65,13 +67,13 @@ public class MapsforgeMapView extends MapView implements MapViewImpl { } super.draw(canvas); - } catch (Exception e) { + } catch (final Exception e) { Log.e("MapsforgeMapView.draw", e); } } @Override - public void displayZoomControls(boolean takeFocus) { + public void displayZoomControls(final boolean takeFocus) { // nothing to do here } @@ -83,7 +85,7 @@ public class MapsforgeMapView extends MapView implements MapViewImpl { @Override @NonNull public GeoPointImpl getMapViewCenter() { - GeoPoint point = getMapPosition().getMapCenter(); + final GeoPoint point = getMapPosition().getMapCenter(); return new MapsforgeGeoPoint(point.latitudeE6, point.longitudeE6); } @@ -103,31 +105,38 @@ public class MapsforgeMapView extends MapView implements MapViewImpl { } @Override - public CachesOverlay createAddMapOverlay(Context context, Drawable drawable) { + public CachesOverlay createAddMapOverlay(final Context context, final Drawable drawable) { - MapsforgeCacheOverlay ovl = new MapsforgeCacheOverlay(context, drawable); + final MapsforgeCacheOverlay ovl = new MapsforgeCacheOverlay(context, drawable); getOverlays().add(ovl); return ovl.getBase(); } @Override public PositionAndScaleOverlay createAddPositionAndScaleOverlay() { - MapsforgeOverlay ovl = new MapsforgeOverlay(); + final MapsforgeOverlay ovl = new MapsforgeOverlay(); getOverlays().add(ovl); return (PositionAndScaleOverlay) ovl.getBase(); } @Override + public DistanceOverlay createAddDistanceOverlay(final Geopoint coords, final String geocode) { + final MapsforgeDistanceOverlay ovl = new MapsforgeDistanceOverlay(this, coords, geocode); + getOverlays().add(ovl); + return (DistanceOverlay) ovl.getBase(); + } + + @Override public int getLatitudeSpan() { int span = 0; - Projection projection = getProjection(); + final Projection projection = getProjection(); if (projection != null && getHeight() > 0) { - GeoPoint low = projection.fromPixels(0, 0); - GeoPoint high = projection.fromPixels(0, getHeight()); + final GeoPoint low = projection.fromPixels(0, 0); + final GeoPoint high = projection.fromPixels(0, getHeight()); if (low != null && high != null) { span = Math.abs(high.latitudeE6 - low.latitudeE6); @@ -142,11 +151,11 @@ public class MapsforgeMapView extends MapView implements MapViewImpl { int span = 0; - Projection projection = getProjection(); + final Projection projection = getProjection(); if (projection != null && getWidth() > 0) { - GeoPoint low = projection.fromPixels(0, 0); - GeoPoint high = projection.fromPixels(getWidth(), 0); + final GeoPoint low = projection.fromPixels(0, 0); + final GeoPoint high = projection.fromPixels(getWidth(), 0); if (low != null && high != null) { span = Math.abs(high.longitudeE6 - low.longitudeE6); @@ -191,7 +200,7 @@ public class MapsforgeMapView extends MapView implements MapViewImpl { newMapType = ((MapsforgeMapSource) mapSource).getGenerator(); } - MapGenerator mapGenerator = MapGeneratorFactory.createMapGenerator(newMapType); + final MapGenerator mapGenerator = MapGeneratorFactory.createMapGenerator(newMapType); // When swapping map sources, make sure we aren't exceeding max zoom. See bug #1535 final int maxZoom = mapGenerator.getZoomLevelMax(); @@ -230,11 +239,11 @@ public class MapsforgeMapView extends MapView implements MapViewImpl { @Override public void setMapTheme() { - String customRenderTheme = Settings.getCustomRenderThemeFilePath(); + final String customRenderTheme = Settings.getCustomRenderThemeFilePath(); if (StringUtils.isNotEmpty(customRenderTheme)) { try { setRenderTheme(new File(customRenderTheme)); - } catch (FileNotFoundException ignored) { + } catch (final FileNotFoundException ignored) { Toast.makeText( getContext(), getContext().getResources().getString(R.string.warn_rendertheme_missing), @@ -247,38 +256,38 @@ public class MapsforgeMapView extends MapView implements MapViewImpl { } @Override - public void repaintRequired(GeneralOverlay overlay) { + public void repaintRequired(final GeneralOverlay overlay) { if (null == overlay) { invalidate(); } else { try { - Overlay ovl = (Overlay) overlay.getOverlayImpl(); + final Overlay ovl = (Overlay) overlay.getOverlayImpl(); if (ovl != null) { ovl.requestRedraw(); } - } catch (Exception e) { + } catch (final Exception e) { Log.e("MapsforgeMapView.repaintRequired", e); } } } @Override - public void setOnDragListener(OnMapDragListener onDragListener) { + public void setOnDragListener(final OnMapDragListener onDragListener) { this.onDragListener = onDragListener; } @Override - public boolean onTouchEvent(MotionEvent ev) { + public boolean onTouchEvent(final MotionEvent ev) { gestureDetector.onTouchEvent(ev); return super.onTouchEvent(ev); } private class GestureListener extends SimpleOnGestureListener { @Override - public boolean onDoubleTap(MotionEvent e) { + public boolean onDoubleTap(final MotionEvent e) { if (onDragListener != null) { onDragListener.onDrag(); } @@ -286,8 +295,8 @@ public class MapsforgeMapView extends MapView implements MapViewImpl { } @Override - public boolean onScroll(MotionEvent e1, MotionEvent e2, - float distanceX, float distanceY) { + public boolean onScroll(final MotionEvent e1, final MotionEvent e2, + final float distanceX, final float distanceY) { if (onDragListener != null) { onDragListener.onDrag(); } diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeDistanceOverlay.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeDistanceOverlay.java new file mode 100755 index 0000000..25b97f0 --- /dev/null +++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeDistanceOverlay.java @@ -0,0 +1,57 @@ +package cgeo.geocaching.maps.mapsforge.v024; + +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.maps.DistanceOverlay; +import cgeo.geocaching.maps.interfaces.GeneralOverlay; +import cgeo.geocaching.maps.interfaces.MapViewImpl; +import cgeo.geocaching.maps.interfaces.OverlayImpl; + +import org.mapsforge.android.mapsold.Overlay; +import org.mapsforge.android.mapsold.Projection; + +import android.graphics.Canvas; +import android.graphics.Point; + +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +public class MapsforgeDistanceOverlay extends Overlay implements OverlayImpl { + + private DistanceOverlay overlayBase = null; + private final Lock lock = new ReentrantLock(); + + public MapsforgeDistanceOverlay(final MapViewImpl mapView, final Geopoint coords, final String geocode) { + overlayBase = new DistanceOverlay(this, mapView, coords, geocode); + } + + @Override + protected void drawOverlayBitmap(final Canvas canvas, final Point drawPosition, + final Projection projection, final byte drawZoomLevel) { + + if (overlayBase != null) { + overlayBase.drawOverlayBitmap(canvas, drawPosition, new MapsforgeMapProjection(projection), drawZoomLevel); + } + } + + public GeneralOverlay getBase() { + return overlayBase; + } + + @Override + public void lock() { + lock.lock(); + + } + + @Override + public void unlock() { + lock.unlock(); + + } + + @Override + public MapViewImpl getMapViewImpl() { + return (MapViewImpl) internalMapView; + } + +} diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java index 42c55fe..6b97707 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java @@ -1,8 +1,10 @@ package cgeo.geocaching.maps.mapsforge.v024; import cgeo.geocaching.R; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.location.Viewport; import cgeo.geocaching.maps.CachesOverlay; +import cgeo.geocaching.maps.DistanceOverlay; import cgeo.geocaching.maps.PositionAndScaleOverlay; import cgeo.geocaching.maps.interfaces.GeneralOverlay; import cgeo.geocaching.maps.interfaces.GeoPointImpl; @@ -34,12 +36,12 @@ public class MapsforgeMapView024 extends MapView implements MapViewImpl { private OnMapDragListener onDragListener; private final MapsforgeMapController mapController = new MapsforgeMapController(getController(), getMaxZoomLevel()); - public MapsforgeMapView024(Context context, AttributeSet attrs) { + public MapsforgeMapView024(final Context context, final AttributeSet attrs) { super(context, attrs); initialize(context); } - private void initialize(Context context) { + private void initialize(final Context context) { if (isInEditMode()) { return; } @@ -47,7 +49,7 @@ public class MapsforgeMapView024 extends MapView implements MapViewImpl { } @Override - public void draw(@NonNull Canvas canvas) { + public void draw(@NonNull final Canvas canvas) { try { // Google Maps and OSM Maps use different zoom levels for the same view. // Here we don't want the Google Maps compatible zoom level, but the actual one. @@ -56,13 +58,13 @@ public class MapsforgeMapView024 extends MapView implements MapViewImpl { } super.draw(canvas); - } catch (Exception e) { + } catch (final Exception e) { Log.e("MapsforgeMapView024.draw", e); } } @Override - public void displayZoomControls(boolean takeFocus) { + public void displayZoomControls(final boolean takeFocus) { // nothing to do here } @@ -74,7 +76,7 @@ public class MapsforgeMapView024 extends MapView implements MapViewImpl { @Override @NonNull public GeoPointImpl getMapViewCenter() { - GeoPoint point = getMapCenter(); + final GeoPoint point = getMapCenter(); return new MapsforgeGeoPoint(point.getLatitudeE6(), point.getLongitudeE6()); } @@ -94,31 +96,38 @@ public class MapsforgeMapView024 extends MapView implements MapViewImpl { } @Override - public CachesOverlay createAddMapOverlay(Context context, Drawable drawable) { + public CachesOverlay createAddMapOverlay(final Context context, final Drawable drawable) { - MapsforgeCacheOverlay ovl = new MapsforgeCacheOverlay(context, drawable); + final MapsforgeCacheOverlay ovl = new MapsforgeCacheOverlay(context, drawable); getOverlays().add(ovl); return ovl.getBase(); } @Override public PositionAndScaleOverlay createAddPositionAndScaleOverlay() { - MapsforgeOverlay ovl = new MapsforgeOverlay(); + final MapsforgeOverlay ovl = new MapsforgeOverlay(); getOverlays().add(ovl); return (PositionAndScaleOverlay) ovl.getBase(); } @Override + public DistanceOverlay createAddDistanceOverlay(final Geopoint coords, final String geocode) { + final MapsforgeDistanceOverlay ovl = new MapsforgeDistanceOverlay(this, coords, geocode); + getOverlays().add(ovl); + return (DistanceOverlay) ovl.getBase(); + } + + @Override public int getLatitudeSpan() { int span = 0; - Projection projection = getProjection(); + final Projection projection = getProjection(); if (projection != null && getHeight() > 0) { - GeoPoint low = projection.fromPixels(0, 0); - GeoPoint high = projection.fromPixels(0, getHeight()); + final GeoPoint low = projection.fromPixels(0, 0); + final GeoPoint high = projection.fromPixels(0, getHeight()); if (low != null && high != null) { span = Math.abs(high.getLatitudeE6() - low.getLatitudeE6()); @@ -133,11 +142,11 @@ public class MapsforgeMapView024 extends MapView implements MapViewImpl { int span = 0; - Projection projection = getProjection(); + final Projection projection = getProjection(); if (projection != null && getWidth() > 0) { - GeoPoint low = projection.fromPixels(0, 0); - GeoPoint high = projection.fromPixels(getWidth(), 0); + final GeoPoint low = projection.fromPixels(0, 0); + final GeoPoint high = projection.fromPixels(getWidth(), 0); if (low != null && high != null) { span = Math.abs(high.getLongitudeE6() - low.getLongitudeE6()); @@ -188,38 +197,38 @@ public class MapsforgeMapView024 extends MapView implements MapViewImpl { } @Override - public void repaintRequired(GeneralOverlay overlay) { + public void repaintRequired(final GeneralOverlay overlay) { if (null == overlay) { invalidate(); } else { try { - Overlay ovl = (Overlay) overlay.getOverlayImpl(); + final Overlay ovl = (Overlay) overlay.getOverlayImpl(); if (ovl != null) { ovl.requestRedraw(); } - } catch (Exception e) { + } catch (final Exception e) { Log.e("MapsforgeMapView024.repaintRequired", e); } } } @Override - public void setOnDragListener(OnMapDragListener onDragListener) { + public void setOnDragListener(final OnMapDragListener onDragListener) { this.onDragListener = onDragListener; } @Override - public boolean onTouchEvent(MotionEvent ev) { + public boolean onTouchEvent(final MotionEvent ev) { gestureDetector.onTouchEvent(ev); return super.onTouchEvent(ev); } private class GestureListener extends SimpleOnGestureListener { @Override - public boolean onDoubleTap(MotionEvent e) { + public boolean onDoubleTap(final MotionEvent e) { if (onDragListener != null) { onDragListener.onDrag(); } @@ -227,8 +236,8 @@ public class MapsforgeMapView024 extends MapView implements MapViewImpl { } @Override - public boolean onScroll(MotionEvent e1, MotionEvent e2, - float distanceX, float distanceY) { + public boolean onScroll(final MotionEvent e1, final MotionEvent e2, + final float distanceX, final float distanceY) { if (onDragListener != null) { onDragListener.onDrag(); } -- cgit v1.1 From 5d3018c77573e4cacc795284139c260ea70aa8a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konrad=20Gr=C3=A4fe?= Date: Mon, 26 Jan 2015 22:53:38 +0100 Subject: Add line between curren location and destination to the map view --- main/src/cgeo/geocaching/maps/CGeoMap.java | 11 +++ .../src/cgeo/geocaching/maps/DirectionOverlay.java | 83 ++++++++++++++++++++++ .../maps/google/v1/GoogleDirectionOverlay.java | 53 ++++++++++++++ .../geocaching/maps/google/v1/GoogleMapView.java | 8 +++ .../geocaching/maps/interfaces/MapViewImpl.java | 3 + .../maps/mapsforge/MapsforgeDirectionOverlay.java | 56 +++++++++++++++ .../maps/mapsforge/MapsforgeMapView.java | 8 +++ .../mapsforge/v024/MapsforgeDirectionOverlay.java | 57 +++++++++++++++ .../maps/mapsforge/v024/MapsforgeMapView024.java | 8 +++ 9 files changed, 287 insertions(+) create mode 100755 main/src/cgeo/geocaching/maps/DirectionOverlay.java create mode 100755 main/src/cgeo/geocaching/maps/google/v1/GoogleDirectionOverlay.java create mode 100755 main/src/cgeo/geocaching/maps/mapsforge/MapsforgeDirectionOverlay.java create mode 100755 main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeDirectionOverlay.java (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 4724566..afbc1ed 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -141,6 +141,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { private CachesOverlay overlayCaches; private PositionAndScaleOverlay overlayPositionAndScale; private DistanceOverlay overlayDistance; + private DirectionOverlay overlayDirection; final private GeoDirHandler geoDirUpdate = new UpdateLoc(this); private SearchResult searchIntent = null; @@ -450,6 +451,11 @@ public class CGeoMap extends AbstractMap implements ViewFactory { mapView.clearOverlays(); overlayCaches = mapView.createAddMapOverlay(mapView.getContext(), getResources().getDrawable(R.drawable.marker)); + + if (coordsIntent != null || geocodeIntent != null) { + overlayDirection = mapView.createAddDirectionOverlay(coordsIntent, geocodeIntent); + } + overlayPositionAndScale = mapView.createAddPositionAndScaleOverlay(); if (trailHistory != null) { overlayPositionAndScale.setHistory(trailHistory); @@ -1005,6 +1011,11 @@ public class CGeoMap extends AbstractMap implements ViewFactory { } if (needsRepaintForDistanceOrAccuracy || needsRepaintForHeading) { + if (map.overlayDirection != null) { + map.overlayDirection.setCoordinates(currentLocation); + map.mapView.repaintRequired(map.overlayDirection); + } + map.overlayPositionAndScale.setCoordinates(currentLocation); map.overlayPositionAndScale.setHeading(currentHeading); map.mapView.repaintRequired(map.overlayPositionAndScale); diff --git a/main/src/cgeo/geocaching/maps/DirectionOverlay.java b/main/src/cgeo/geocaching/maps/DirectionOverlay.java new file mode 100755 index 0000000..0807afa --- /dev/null +++ b/main/src/cgeo/geocaching/maps/DirectionOverlay.java @@ -0,0 +1,83 @@ +package cgeo.geocaching.maps; + +import cgeo.geocaching.DataStore; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.Viewport; +import cgeo.geocaching.maps.interfaces.GeneralOverlay; +import cgeo.geocaching.maps.interfaces.MapItemFactory; +import cgeo.geocaching.maps.interfaces.MapProjectionImpl; +import cgeo.geocaching.maps.interfaces.MapViewImpl; +import cgeo.geocaching.maps.interfaces.OverlayImpl; +import cgeo.geocaching.settings.Settings; + +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.Point; +import android.location.Location; + +public class DirectionOverlay implements GeneralOverlay { + private Geopoint currentCoords; + private final Geopoint destinationCoords; + private final MapItemFactory mapItemFactory; + + private OverlayImpl ovlImpl = null; + + private Paint line = null; + + public DirectionOverlay(final OverlayImpl ovlImpl, final MapViewImpl mapView, final Geopoint coords, final String geocode) { + this.ovlImpl = ovlImpl; + + if (coords == null) { + final Viewport bounds = DataStore.getBounds(geocode); + if (bounds == null) { + this.destinationCoords = new Geopoint(0, 0); + } else { + this.destinationCoords = bounds.center; + } + } else { + this.destinationCoords = coords; + } + + this.mapItemFactory = Settings.getMapProvider().getMapItemFactory(); + } + + public void setCoordinates(final Location coordinatesIn) { + currentCoords = new Geopoint(coordinatesIn); + } + + @Override + public void draw(final Canvas canvas, final MapViewImpl mapView, final boolean shadow) { + drawInternal(canvas, mapView.getMapProjection()); + } + + @Override + public void drawOverlayBitmap(final Canvas canvas, final Point drawPosition, final MapProjectionImpl projection, final byte drawZoomLevel) { + drawInternal(canvas, projection); + } + + private void drawInternal(final Canvas canvas, final MapProjectionImpl projection) { + if (currentCoords == null) { + return; + } + + if (line == null) { + line = new Paint(); + line.setAntiAlias(true); + line.setStrokeWidth(2f); + line.setColor(0xFFEB391E); + } + + final Point pos = new Point(); + final Point dest = new Point(); + projection.toPixels(mapItemFactory.getGeoPointBase(currentCoords), pos); + projection.toPixels(mapItemFactory.getGeoPointBase(destinationCoords), dest); + + canvas.drawLine(pos.x, pos.y, dest.x, dest.y, line); + } + + @Override + public OverlayImpl getOverlayImpl() { + return this.ovlImpl; + } + +} diff --git a/main/src/cgeo/geocaching/maps/google/v1/GoogleDirectionOverlay.java b/main/src/cgeo/geocaching/maps/google/v1/GoogleDirectionOverlay.java new file mode 100755 index 0000000..cc896c6 --- /dev/null +++ b/main/src/cgeo/geocaching/maps/google/v1/GoogleDirectionOverlay.java @@ -0,0 +1,53 @@ +package cgeo.geocaching.maps.google.v1; + +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.maps.DirectionOverlay; +import cgeo.geocaching.maps.interfaces.GeneralOverlay; +import cgeo.geocaching.maps.interfaces.MapViewImpl; +import cgeo.geocaching.maps.interfaces.OverlayImpl; + +import com.google.android.maps.MapView; +import com.google.android.maps.Overlay; + +import android.graphics.Canvas; + +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +public class GoogleDirectionOverlay extends Overlay implements OverlayImpl { + + private final DirectionOverlay overlayBase; + private final Lock lock = new ReentrantLock(); + + public GoogleDirectionOverlay(final MapViewImpl mapView, final Geopoint coords, final String geocode) { + overlayBase = new DirectionOverlay(this, mapView, coords, geocode); + } + + @Override + public void draw(final Canvas canvas, final MapView mapView, final boolean shadow) { + super.draw(canvas, mapView, shadow); + + assert mapView instanceof MapViewImpl; + overlayBase.draw(canvas, (MapViewImpl) mapView, shadow); + } + + public GeneralOverlay getBase() { + return overlayBase; + } + + @Override + public void lock() { + lock.lock(); + } + + @Override + public void unlock() { + lock.unlock(); + } + + @Override + public MapViewImpl getMapViewImpl() { + throw new UnsupportedOperationException(); + } + +} diff --git a/main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java b/main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java index 08c9ae7..9664c3e 100644 --- a/main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java +++ b/main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java @@ -5,6 +5,7 @@ import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.location.Viewport; import cgeo.geocaching.maps.CachesOverlay; +import cgeo.geocaching.maps.DirectionOverlay; import cgeo.geocaching.maps.DistanceOverlay; import cgeo.geocaching.maps.PositionAndScaleOverlay; import cgeo.geocaching.maps.interfaces.GeneralOverlay; @@ -136,6 +137,13 @@ public class GoogleMapView extends MapView implements MapViewImpl { } @Override + public DirectionOverlay createAddDirectionOverlay(final Geopoint coords, final String geocode) { + final GoogleDirectionOverlay ovl = new GoogleDirectionOverlay(this, coords, geocode); + getOverlays().add(ovl); + return (DirectionOverlay) ovl.getBase(); + } + + @Override public DistanceOverlay createAddDistanceOverlay(final Geopoint coords, final String geocode) { final GoogleDistanceOverlay ovl = new GoogleDistanceOverlay(this, coords, geocode); getOverlays().add(ovl); diff --git a/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java b/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java index 00a8790..f15f12a 100644 --- a/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java +++ b/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java @@ -3,6 +3,7 @@ package cgeo.geocaching.maps.interfaces; import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.location.Viewport; import cgeo.geocaching.maps.CachesOverlay; +import cgeo.geocaching.maps.DirectionOverlay; import cgeo.geocaching.maps.DistanceOverlay; import cgeo.geocaching.maps.PositionAndScaleOverlay; @@ -52,6 +53,8 @@ public interface MapViewImpl { DistanceOverlay createAddDistanceOverlay(Geopoint coords, String geocode); + DirectionOverlay createAddDirectionOverlay(Geopoint coords, String geocode); + void setMapSource(); /** diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeDirectionOverlay.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeDirectionOverlay.java new file mode 100755 index 0000000..98c19db --- /dev/null +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeDirectionOverlay.java @@ -0,0 +1,56 @@ +package cgeo.geocaching.maps.mapsforge; + +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.maps.DirectionOverlay; +import cgeo.geocaching.maps.interfaces.GeneralOverlay; +import cgeo.geocaching.maps.interfaces.MapViewImpl; +import cgeo.geocaching.maps.interfaces.OverlayImpl; + +import org.mapsforge.android.maps.Projection; +import org.mapsforge.android.maps.overlay.Overlay; + +import android.graphics.Canvas; +import android.graphics.Point; + +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +public class MapsforgeDirectionOverlay extends Overlay implements OverlayImpl { + + private DirectionOverlay overlayBase = null; + private final Lock lock = new ReentrantLock(); + + public MapsforgeDirectionOverlay(final MapViewImpl mapView, final Geopoint coords, final String geocode) { + overlayBase = new DirectionOverlay(this, mapView, coords, geocode); + } + + @Override + protected void drawOverlayBitmap(final Canvas canvas, final Point drawPosition, + final Projection projection, final byte drawZoomLevel) { + + if (overlayBase != null) { + overlayBase.drawOverlayBitmap(canvas, drawPosition, new MapsforgeMapProjection(projection), drawZoomLevel); + } + } + + public GeneralOverlay getBase() { + return overlayBase; + } + + @Override + public void lock() { + lock.lock(); + } + + @Override + public void unlock() { + lock.unlock(); + + } + + @Override + public MapViewImpl getMapViewImpl() { + return (MapViewImpl) internalMapView; + } + +} diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java index dd67a8f..a81c108 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java @@ -4,6 +4,7 @@ import cgeo.geocaching.R; import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.location.Viewport; import cgeo.geocaching.maps.CachesOverlay; +import cgeo.geocaching.maps.DirectionOverlay; import cgeo.geocaching.maps.DistanceOverlay; import cgeo.geocaching.maps.PositionAndScaleOverlay; import cgeo.geocaching.maps.interfaces.GeneralOverlay; @@ -120,6 +121,13 @@ public class MapsforgeMapView extends MapView implements MapViewImpl { } @Override + public DirectionOverlay createAddDirectionOverlay(final Geopoint coords, final String geocode) { + final MapsforgeDirectionOverlay ovl = new MapsforgeDirectionOverlay(this, coords, geocode); + getOverlays().add(ovl); + return (DirectionOverlay) ovl.getBase(); + } + + @Override public DistanceOverlay createAddDistanceOverlay(final Geopoint coords, final String geocode) { final MapsforgeDistanceOverlay ovl = new MapsforgeDistanceOverlay(this, coords, geocode); getOverlays().add(ovl); diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeDirectionOverlay.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeDirectionOverlay.java new file mode 100755 index 0000000..281b27f --- /dev/null +++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeDirectionOverlay.java @@ -0,0 +1,57 @@ +package cgeo.geocaching.maps.mapsforge.v024; + +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.maps.DirectionOverlay; +import cgeo.geocaching.maps.interfaces.GeneralOverlay; +import cgeo.geocaching.maps.interfaces.MapViewImpl; +import cgeo.geocaching.maps.interfaces.OverlayImpl; + +import org.mapsforge.android.mapsold.Overlay; +import org.mapsforge.android.mapsold.Projection; + +import android.graphics.Canvas; +import android.graphics.Point; + +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +public class MapsforgeDirectionOverlay extends Overlay implements OverlayImpl { + + private DirectionOverlay overlayBase = null; + private final Lock lock = new ReentrantLock(); + + public MapsforgeDirectionOverlay(final MapViewImpl mapView, final Geopoint coords, final String geocode) { + overlayBase = new DirectionOverlay(this, mapView, coords, geocode); + } + + @Override + protected void drawOverlayBitmap(final Canvas canvas, final Point drawPosition, + final Projection projection, final byte drawZoomLevel) { + + if (overlayBase != null) { + overlayBase.drawOverlayBitmap(canvas, drawPosition, new MapsforgeMapProjection(projection), drawZoomLevel); + } + } + + public GeneralOverlay getBase() { + return overlayBase; + } + + @Override + public void lock() { + lock.lock(); + + } + + @Override + public void unlock() { + lock.unlock(); + + } + + @Override + public MapViewImpl getMapViewImpl() { + return (MapViewImpl) internalMapView; + } + +} diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java index 6b97707..937c13b 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java @@ -4,6 +4,7 @@ import cgeo.geocaching.R; import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.location.Viewport; import cgeo.geocaching.maps.CachesOverlay; +import cgeo.geocaching.maps.DirectionOverlay; import cgeo.geocaching.maps.DistanceOverlay; import cgeo.geocaching.maps.PositionAndScaleOverlay; import cgeo.geocaching.maps.interfaces.GeneralOverlay; @@ -111,6 +112,13 @@ public class MapsforgeMapView024 extends MapView implements MapViewImpl { } @Override + public DirectionOverlay createAddDirectionOverlay(final Geopoint coords, final String geocode) { + final MapsforgeDirectionOverlay ovl = new MapsforgeDirectionOverlay(this, coords, geocode); + getOverlays().add(ovl); + return (DirectionOverlay) ovl.getBase(); + } + + @Override public DistanceOverlay createAddDistanceOverlay(final Geopoint coords, final String geocode) { final MapsforgeDistanceOverlay ovl = new MapsforgeDistanceOverlay(this, coords, geocode); getOverlays().add(ovl); -- cgit v1.1 From 8c773d5c41fb118c4013e3f7ccf9f10186d4d6b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konrad=20Gr=C3=A4fe?= Date: Wed, 28 Jan 2015 21:05:33 +0100 Subject: Save memory by reducing the number of map overlays Move DistanceOverlay and DirectionOverlay into PositionAndScaleOverlay to save memory. --- main/src/cgeo/geocaching/maps/CGeoMap.java | 19 +-- main/src/cgeo/geocaching/maps/DirectionDrawer.java | 48 ++++++ .../src/cgeo/geocaching/maps/DirectionOverlay.java | 83 ---------- main/src/cgeo/geocaching/maps/DistanceDrawer.java | 136 ++++++++++++++++ main/src/cgeo/geocaching/maps/DistanceOverlay.java | 178 --------------------- .../geocaching/maps/PositionAndScaleOverlay.java | 39 ++++- .../maps/google/v1/GoogleDirectionOverlay.java | 53 ------ .../maps/google/v1/GoogleDistanceOverlay.java | 53 ------ .../geocaching/maps/google/v1/GoogleMapView.java | 20 +-- .../geocaching/maps/google/v1/GoogleOverlay.java | 9 +- .../geocaching/maps/interfaces/MapViewImpl.java | 8 +- .../maps/mapsforge/MapsforgeDirectionOverlay.java | 56 ------- .../maps/mapsforge/MapsforgeDistanceOverlay.java | 56 ------- .../maps/mapsforge/MapsforgeMapView.java | 20 +-- .../maps/mapsforge/MapsforgeOverlay.java | 11 +- .../mapsforge/v024/MapsforgeDirectionOverlay.java | 57 ------- .../mapsforge/v024/MapsforgeDistanceOverlay.java | 57 ------- .../maps/mapsforge/v024/MapsforgeMapView024.java | 20 +-- .../maps/mapsforge/v024/MapsforgeOverlay.java | 11 +- 19 files changed, 240 insertions(+), 694 deletions(-) create mode 100755 main/src/cgeo/geocaching/maps/DirectionDrawer.java delete mode 100755 main/src/cgeo/geocaching/maps/DirectionOverlay.java create mode 100755 main/src/cgeo/geocaching/maps/DistanceDrawer.java delete mode 100755 main/src/cgeo/geocaching/maps/DistanceOverlay.java delete mode 100755 main/src/cgeo/geocaching/maps/google/v1/GoogleDirectionOverlay.java delete mode 100755 main/src/cgeo/geocaching/maps/google/v1/GoogleDistanceOverlay.java delete mode 100755 main/src/cgeo/geocaching/maps/mapsforge/MapsforgeDirectionOverlay.java delete mode 100755 main/src/cgeo/geocaching/maps/mapsforge/MapsforgeDistanceOverlay.java delete mode 100755 main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeDirectionOverlay.java delete mode 100755 main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeDistanceOverlay.java (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index afbc1ed..a7983bb 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -140,8 +140,6 @@ public class CGeoMap extends AbstractMap implements ViewFactory { private MapViewImpl mapView; private CachesOverlay overlayCaches; private PositionAndScaleOverlay overlayPositionAndScale; - private DistanceOverlay overlayDistance; - private DirectionOverlay overlayDirection; final private GeoDirHandler geoDirUpdate = new UpdateLoc(this); private SearchResult searchIntent = null; @@ -452,18 +450,12 @@ public class CGeoMap extends AbstractMap implements ViewFactory { overlayCaches = mapView.createAddMapOverlay(mapView.getContext(), getResources().getDrawable(R.drawable.marker)); - if (coordsIntent != null || geocodeIntent != null) { - overlayDirection = mapView.createAddDirectionOverlay(coordsIntent, geocodeIntent); - } - overlayPositionAndScale = mapView.createAddPositionAndScaleOverlay(); + overlayPositionAndScale = mapView.createAddPositionAndScaleOverlay(coordsIntent, geocodeIntent); if (trailHistory != null) { overlayPositionAndScale.setHistory(trailHistory); } - if (coordsIntent != null || geocodeIntent != null) { - overlayDistance = mapView.createAddDistanceOverlay(coordsIntent, geocodeIntent); - } mapView.repaintRequired(null); @@ -1011,19 +1003,10 @@ public class CGeoMap extends AbstractMap implements ViewFactory { } if (needsRepaintForDistanceOrAccuracy || needsRepaintForHeading) { - if (map.overlayDirection != null) { - map.overlayDirection.setCoordinates(currentLocation); - map.mapView.repaintRequired(map.overlayDirection); - } map.overlayPositionAndScale.setCoordinates(currentLocation); map.overlayPositionAndScale.setHeading(currentHeading); map.mapView.repaintRequired(map.overlayPositionAndScale); - - if (map.overlayDistance != null) { - map.overlayDistance.setCoordinates(currentLocation); - map.mapView.repaintRequired(map.overlayDistance); - } } } } catch (final RuntimeException e) { diff --git a/main/src/cgeo/geocaching/maps/DirectionDrawer.java b/main/src/cgeo/geocaching/maps/DirectionDrawer.java new file mode 100755 index 0000000..ccef59c --- /dev/null +++ b/main/src/cgeo/geocaching/maps/DirectionDrawer.java @@ -0,0 +1,48 @@ +package cgeo.geocaching.maps; + +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.maps.interfaces.MapItemFactory; +import cgeo.geocaching.maps.interfaces.MapProjectionImpl; +import cgeo.geocaching.settings.Settings; + +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.Point; +import android.location.Location; + +public class DirectionDrawer { + private Geopoint currentCoords; + private final Geopoint destinationCoords; + private final MapItemFactory mapItemFactory; + + private Paint line = null; + + public DirectionDrawer(final Geopoint coords) { + this.destinationCoords = coords; + this.mapItemFactory = Settings.getMapProvider().getMapItemFactory(); + } + + public void setCoordinates(final Location coordinatesIn) { + currentCoords = new Geopoint(coordinatesIn); + } + + void drawDirection(final Canvas canvas, final MapProjectionImpl projection) { + if (currentCoords == null) { + return; + } + + if (line == null) { + line = new Paint(); + line.setAntiAlias(true); + line.setStrokeWidth(2f); + line.setColor(0xFFEB391E); + } + + final Point pos = new Point(); + final Point dest = new Point(); + projection.toPixels(mapItemFactory.getGeoPointBase(currentCoords), pos); + projection.toPixels(mapItemFactory.getGeoPointBase(destinationCoords), dest); + + canvas.drawLine(pos.x, pos.y, dest.x, dest.y, line); + } +} diff --git a/main/src/cgeo/geocaching/maps/DirectionOverlay.java b/main/src/cgeo/geocaching/maps/DirectionOverlay.java deleted file mode 100755 index 0807afa..0000000 --- a/main/src/cgeo/geocaching/maps/DirectionOverlay.java +++ /dev/null @@ -1,83 +0,0 @@ -package cgeo.geocaching.maps; - -import cgeo.geocaching.DataStore; -import cgeo.geocaching.location.Geopoint; -import cgeo.geocaching.location.Viewport; -import cgeo.geocaching.maps.interfaces.GeneralOverlay; -import cgeo.geocaching.maps.interfaces.MapItemFactory; -import cgeo.geocaching.maps.interfaces.MapProjectionImpl; -import cgeo.geocaching.maps.interfaces.MapViewImpl; -import cgeo.geocaching.maps.interfaces.OverlayImpl; -import cgeo.geocaching.settings.Settings; - -import android.graphics.Canvas; -import android.graphics.Paint; -import android.graphics.Point; -import android.location.Location; - -public class DirectionOverlay implements GeneralOverlay { - private Geopoint currentCoords; - private final Geopoint destinationCoords; - private final MapItemFactory mapItemFactory; - - private OverlayImpl ovlImpl = null; - - private Paint line = null; - - public DirectionOverlay(final OverlayImpl ovlImpl, final MapViewImpl mapView, final Geopoint coords, final String geocode) { - this.ovlImpl = ovlImpl; - - if (coords == null) { - final Viewport bounds = DataStore.getBounds(geocode); - if (bounds == null) { - this.destinationCoords = new Geopoint(0, 0); - } else { - this.destinationCoords = bounds.center; - } - } else { - this.destinationCoords = coords; - } - - this.mapItemFactory = Settings.getMapProvider().getMapItemFactory(); - } - - public void setCoordinates(final Location coordinatesIn) { - currentCoords = new Geopoint(coordinatesIn); - } - - @Override - public void draw(final Canvas canvas, final MapViewImpl mapView, final boolean shadow) { - drawInternal(canvas, mapView.getMapProjection()); - } - - @Override - public void drawOverlayBitmap(final Canvas canvas, final Point drawPosition, final MapProjectionImpl projection, final byte drawZoomLevel) { - drawInternal(canvas, projection); - } - - private void drawInternal(final Canvas canvas, final MapProjectionImpl projection) { - if (currentCoords == null) { - return; - } - - if (line == null) { - line = new Paint(); - line.setAntiAlias(true); - line.setStrokeWidth(2f); - line.setColor(0xFFEB391E); - } - - final Point pos = new Point(); - final Point dest = new Point(); - projection.toPixels(mapItemFactory.getGeoPointBase(currentCoords), pos); - projection.toPixels(mapItemFactory.getGeoPointBase(destinationCoords), dest); - - canvas.drawLine(pos.x, pos.y, dest.x, dest.y, line); - } - - @Override - public OverlayImpl getOverlayImpl() { - return this.ovlImpl; - } - -} diff --git a/main/src/cgeo/geocaching/maps/DistanceDrawer.java b/main/src/cgeo/geocaching/maps/DistanceDrawer.java new file mode 100755 index 0000000..6450f70 --- /dev/null +++ b/main/src/cgeo/geocaching/maps/DistanceDrawer.java @@ -0,0 +1,136 @@ +package cgeo.geocaching.maps; + +import cgeo.geocaching.CgeoApplication; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.Units; +import cgeo.geocaching.maps.interfaces.MapViewImpl; + +import android.content.Context; +import android.graphics.BlurMaskFilter; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.Rect; +import android.graphics.RectF; +import android.graphics.Typeface; +import android.location.Location; +import android.util.DisplayMetrics; +import android.view.WindowManager; + +public class DistanceDrawer { + private Geopoint currentCoords; + private final Geopoint destinationCoords; + + private Paint paintBox = null; + private Paint paintBoxShadow = null; + private Paint paintText = null; + private BlurMaskFilter blurBoxShadow = null; + + private final boolean needsInvertedColors; + private float pixelDensity = 0; + private final float boxWidth, boxHeight, boxCornerRadius, boxShadowSize, boxPadding; + private final float textHeight, maxTextWidth; + private final float boxX, boxY; + + private String distanceText = null; + + public DistanceDrawer(final MapViewImpl mapView, final Geopoint destinationCoords) { + this.destinationCoords = destinationCoords; + + final DisplayMetrics metrics = new DisplayMetrics(); + final WindowManager windowManager = (WindowManager) CgeoApplication.getInstance().getSystemService(Context.WINDOW_SERVICE); + windowManager.getDefaultDisplay().getMetrics(metrics); + + pixelDensity = metrics.density; + + boxPadding = 2; + boxWidth = 100 * pixelDensity + 3 * boxPadding; + boxHeight = 30 * pixelDensity + 2 * boxPadding; + boxCornerRadius = 5 * pixelDensity; + boxShadowSize = 1 * pixelDensity; + textHeight = 20 * pixelDensity; + + needsInvertedColors = mapView.needsInvertedColors(); + boxX = metrics.widthPixels - boxWidth; + boxY = 0; + + maxTextWidth = boxWidth - 3 * boxPadding; + } + + public void setCoordinates(final Location coordinatesIn) { + currentCoords = new Geopoint(coordinatesIn); + + final float distance = currentCoords.distanceTo(destinationCoords); + distanceText = Units.getDistanceFromKilometers(distance); + } + + void drawDistance(final Canvas canvas) { + if (currentCoords == null) { + return; + } + + if (blurBoxShadow == null) { + blurBoxShadow = new BlurMaskFilter(3, BlurMaskFilter.Blur.NORMAL); + } + + if (paintBoxShadow == null) { + paintBoxShadow = new Paint(); + paintBoxShadow.setAntiAlias(true); + paintBoxShadow.setMaskFilter(blurBoxShadow); + } + + if (paintBox == null) { + paintBox = new Paint(); + paintBox.setAntiAlias(true); + } + + if (paintText == null) { + paintText = new Paint(); + paintText.setAntiAlias(true); + paintText.setTextAlign(Paint.Align.LEFT); + paintText.setTypeface(Typeface.DEFAULT_BOLD); + } + + if (needsInvertedColors) { + paintBoxShadow.setColor(0xFF000000); + paintBox.setColor(0xFFFFFFFF); + paintText.setColor(0xFF000000); + } else { + paintBoxShadow.setColor(0xFFFFFFFF); + paintBox.setColor(0xFF000000); + paintText.setColor(0xFFFFFFFF); + } + + /* Calculate text size */ + final Rect textBounds = new Rect(); + paintText.setTextSize(textHeight); + paintText.getTextBounds(distanceText, 0, distanceText.length(), textBounds); + while (textBounds.height() > maxTextWidth) { + paintText.setTextSize(paintText.getTextSize() - 1); + paintText.getTextBounds(distanceText, 0, distanceText.length(), textBounds); + } + + final float textX = (boxWidth - 3 * boxPadding - textBounds.width()) / 2 + boxX + 2 * boxPadding; + final float textY = (boxHeight + textBounds.height()) / 2 + boxY; + + /* Paint background box */ + canvas.drawRoundRect( + new RectF( + boxX - boxShadowSize, boxY - boxShadowSize - boxCornerRadius, + boxX + boxWidth + boxShadowSize + boxCornerRadius, boxY + boxHeight + boxShadowSize + ), + boxCornerRadius, boxCornerRadius, + paintBoxShadow + ); + canvas.drawRoundRect( + new RectF( + boxX, boxY - boxCornerRadius, + boxX + boxWidth + boxCornerRadius, boxY + boxHeight + ), + boxCornerRadius, boxCornerRadius, + paintBox + ); + + /* Paint distance */ + canvas.drawText(distanceText, textX, textY, paintText); + } +} diff --git a/main/src/cgeo/geocaching/maps/DistanceOverlay.java b/main/src/cgeo/geocaching/maps/DistanceOverlay.java deleted file mode 100755 index 211db98..0000000 --- a/main/src/cgeo/geocaching/maps/DistanceOverlay.java +++ /dev/null @@ -1,178 +0,0 @@ -package cgeo.geocaching.maps; - -import cgeo.geocaching.CgeoApplication; -import cgeo.geocaching.DataStore; -import cgeo.geocaching.location.Geopoint; -import cgeo.geocaching.location.Units; -import cgeo.geocaching.location.Viewport; -import cgeo.geocaching.maps.interfaces.GeneralOverlay; -import cgeo.geocaching.maps.interfaces.MapProjectionImpl; -import cgeo.geocaching.maps.interfaces.MapViewImpl; -import cgeo.geocaching.maps.interfaces.OverlayImpl; - -import android.content.Context; -import android.graphics.BlurMaskFilter; -import android.graphics.Canvas; -import android.graphics.Paint; -import android.graphics.Point; -import android.graphics.Rect; -import android.graphics.RectF; -import android.graphics.Typeface; -import android.location.Location; -import android.util.DisplayMetrics; -import android.view.WindowManager; - -public class DistanceOverlay implements GeneralOverlay { - private Geopoint currentCoords; - private final Geopoint destinationCoords; - - private Paint paintBox = null; - private Paint paintBoxShadow = null; - private Paint paintText = null; - private Paint paintCompass = null; - private BlurMaskFilter blurBoxShadow = null; - - private final boolean needsInvertedColors; - private float pixelDensity = 0; - private final float boxWidth, boxHeight, boxCornerRadius, boxShadowSize, boxPadding; - private final float textHeight, maxTextWidth; - private final float boxX, boxY; - - private String distanceText = null; - - private OverlayImpl ovlImpl = null; - - public DistanceOverlay(final OverlayImpl ovlImpl, final MapViewImpl mapView, final Geopoint coords, final String geocode) { - this.ovlImpl = ovlImpl; - - if (coords == null) { - final Viewport bounds = DataStore.getBounds(geocode); - if (bounds == null) { - this.destinationCoords = new Geopoint(0, 0); - } else { - this.destinationCoords = bounds.center; - } - } else { - this.destinationCoords = coords; - } - - final DisplayMetrics metrics = new DisplayMetrics(); - final WindowManager windowManager = (WindowManager) CgeoApplication.getInstance().getSystemService(Context.WINDOW_SERVICE); - windowManager.getDefaultDisplay().getMetrics(metrics); - - pixelDensity = metrics.density; - - boxPadding = 2; - boxWidth = 100 * pixelDensity + 3 * boxPadding; - boxHeight = 30 * pixelDensity + 2 * boxPadding; - boxCornerRadius = 5 * pixelDensity; - boxShadowSize = 1 * pixelDensity; - textHeight = 20 * pixelDensity; - - needsInvertedColors = mapView.needsInvertedColors(); - boxX = metrics.widthPixels - boxWidth; - boxY = 0; - - maxTextWidth = boxWidth - 3 * boxPadding; - } - - public void setCoordinates(final Location coordinatesIn) { - currentCoords = new Geopoint(coordinatesIn); - - final float distance = currentCoords.distanceTo(destinationCoords); - distanceText = Units.getDistanceFromKilometers(distance); - } - - @Override - public void draw(final Canvas canvas, final MapViewImpl mapView, final boolean shadow) { - drawInternal(canvas); - } - - @Override - public void drawOverlayBitmap(final Canvas canvas, final Point drawPosition, final MapProjectionImpl projection, final byte drawZoomLevel) { - drawInternal(canvas); - } - - private void drawInternal(final Canvas canvas) { - if (currentCoords == null) { - return; - } - - if (blurBoxShadow == null) { - blurBoxShadow = new BlurMaskFilter(3, BlurMaskFilter.Blur.NORMAL); - } - - if (paintBoxShadow == null) { - paintBoxShadow = new Paint(); - paintBoxShadow.setAntiAlias(true); - paintBoxShadow.setMaskFilter(blurBoxShadow); - } - - if (paintBox == null) { - paintBox = new Paint(); - paintBox.setAntiAlias(true); - } - - if (paintText == null) { - paintText = new Paint(); - paintText.setAntiAlias(true); - paintText.setTextAlign(Paint.Align.LEFT); - paintText.setTypeface(Typeface.DEFAULT_BOLD); - } - - if (paintCompass == null) { - paintCompass = new Paint(Paint.ANTI_ALIAS_FLAG); - paintCompass.setDither(true); - paintCompass.setFilterBitmap(true); - } - - if (needsInvertedColors) { - paintBoxShadow.setColor(0xFF000000); - paintBox.setColor(0xFFFFFFFF); - paintText.setColor(0xFF000000); - } else { - paintBoxShadow.setColor(0xFFFFFFFF); - paintBox.setColor(0xFF000000); - paintText.setColor(0xFFFFFFFF); - } - - /* Calculate text size */ - final Rect textBounds = new Rect(); - paintText.setTextSize(textHeight); - paintText.getTextBounds(distanceText, 0, distanceText.length(), textBounds); - while (textBounds.height() > maxTextWidth) { - paintText.setTextSize(paintText.getTextSize() - 1); - paintText.getTextBounds(distanceText, 0, distanceText.length(), textBounds); - } - - final float textX = (boxWidth - 3 * boxPadding - textBounds.width()) / 2 + boxX + 2 * boxPadding; - final float textY = (boxHeight + textBounds.height()) / 2 + boxY; - - /* Paint background box */ - canvas.drawRoundRect( - new RectF( - boxX - boxShadowSize, boxY - boxShadowSize - boxCornerRadius, - boxX + boxWidth + boxShadowSize + boxCornerRadius, boxY + boxHeight + boxShadowSize - ), - boxCornerRadius, boxCornerRadius, - paintBoxShadow - ); - canvas.drawRoundRect( - new RectF( - boxX, boxY - boxCornerRadius, - boxX + boxWidth + boxCornerRadius, boxY + boxHeight - ), - boxCornerRadius, boxCornerRadius, - paintBox - ); - - /* Paint distance */ - canvas.drawText(distanceText, textX, textY, paintText); - } - - @Override - public OverlayImpl getOverlayImpl() { - return this.ovlImpl; - } - -} diff --git a/main/src/cgeo/geocaching/maps/PositionAndScaleOverlay.java b/main/src/cgeo/geocaching/maps/PositionAndScaleOverlay.java index 63fcd73..51d83aa 100644 --- a/main/src/cgeo/geocaching/maps/PositionAndScaleOverlay.java +++ b/main/src/cgeo/geocaching/maps/PositionAndScaleOverlay.java @@ -1,5 +1,8 @@ package cgeo.geocaching.maps; +import cgeo.geocaching.DataStore; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.Viewport; import cgeo.geocaching.maps.interfaces.GeneralOverlay; import cgeo.geocaching.maps.interfaces.MapProjectionImpl; import cgeo.geocaching.maps.interfaces.MapViewImpl; @@ -16,22 +19,40 @@ public class PositionAndScaleOverlay implements GeneralOverlay { PositionDrawer positionDrawer = null; ScaleDrawer scaleDrawer = null; + DirectionDrawer directionDrawer = null; + DistanceDrawer distanceDrawer = null; - public PositionAndScaleOverlay(OverlayImpl ovlImpl) { + public PositionAndScaleOverlay(final OverlayImpl ovlImpl, final MapViewImpl mapView, Geopoint coords, final String geocode) { this.ovlImpl = ovlImpl; positionDrawer = new PositionDrawer(); scaleDrawer = new ScaleDrawer(); + + if (coords == null && geocode != null) { + final Viewport bounds = DataStore.getBounds(geocode); + if (bounds != null) { + coords = bounds.center; + } + } + if (coords != null) { + directionDrawer = new DirectionDrawer(coords); + distanceDrawer = new DistanceDrawer(mapView, coords); + } } - public void setCoordinates(Location coordinatesIn) { + public void setCoordinates(final Location coordinatesIn) { positionDrawer.setCoordinates(coordinatesIn); + if (directionDrawer != null) { + directionDrawer.setCoordinates(coordinatesIn); + distanceDrawer.setCoordinates(coordinatesIn); + } + } public Location getCoordinates() { return positionDrawer.getCoordinates(); } - public void setHeading(float bearingNow) { + public void setHeading(final float bearingNow) { positionDrawer.setHeading(bearingNow); } @@ -40,21 +61,23 @@ public class PositionAndScaleOverlay implements GeneralOverlay { } @Override - public void drawOverlayBitmap(Canvas canvas, Point drawPosition, - MapProjectionImpl projection, byte drawZoomLevel) { + public void drawOverlayBitmap(final Canvas canvas, final Point drawPosition, + final MapProjectionImpl projection, final byte drawZoomLevel) { drawInternal(canvas, projection, getOverlayImpl().getMapViewImpl()); } @Override - public void draw(Canvas canvas, MapViewImpl mapView, boolean shadow) { + public void draw(final Canvas canvas, final MapViewImpl mapView, final boolean shadow) { drawInternal(canvas, mapView.getMapProjection(), mapView); } - private void drawInternal(Canvas canvas, MapProjectionImpl projection, MapViewImpl mapView) { + private void drawInternal(final Canvas canvas, final MapProjectionImpl projection, final MapViewImpl mapView) { + directionDrawer.drawDirection(canvas, projection); positionDrawer.drawPosition(canvas, projection); scaleDrawer.drawScale(canvas, mapView); + distanceDrawer.drawDistance(canvas); } @Override @@ -66,7 +89,7 @@ public class PositionAndScaleOverlay implements GeneralOverlay { return positionDrawer.getHistory(); } - public void setHistory(ArrayList history) { + public void setHistory(final ArrayList history) { positionDrawer.setHistory(history); } } diff --git a/main/src/cgeo/geocaching/maps/google/v1/GoogleDirectionOverlay.java b/main/src/cgeo/geocaching/maps/google/v1/GoogleDirectionOverlay.java deleted file mode 100755 index cc896c6..0000000 --- a/main/src/cgeo/geocaching/maps/google/v1/GoogleDirectionOverlay.java +++ /dev/null @@ -1,53 +0,0 @@ -package cgeo.geocaching.maps.google.v1; - -import cgeo.geocaching.location.Geopoint; -import cgeo.geocaching.maps.DirectionOverlay; -import cgeo.geocaching.maps.interfaces.GeneralOverlay; -import cgeo.geocaching.maps.interfaces.MapViewImpl; -import cgeo.geocaching.maps.interfaces.OverlayImpl; - -import com.google.android.maps.MapView; -import com.google.android.maps.Overlay; - -import android.graphics.Canvas; - -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; - -public class GoogleDirectionOverlay extends Overlay implements OverlayImpl { - - private final DirectionOverlay overlayBase; - private final Lock lock = new ReentrantLock(); - - public GoogleDirectionOverlay(final MapViewImpl mapView, final Geopoint coords, final String geocode) { - overlayBase = new DirectionOverlay(this, mapView, coords, geocode); - } - - @Override - public void draw(final Canvas canvas, final MapView mapView, final boolean shadow) { - super.draw(canvas, mapView, shadow); - - assert mapView instanceof MapViewImpl; - overlayBase.draw(canvas, (MapViewImpl) mapView, shadow); - } - - public GeneralOverlay getBase() { - return overlayBase; - } - - @Override - public void lock() { - lock.lock(); - } - - @Override - public void unlock() { - lock.unlock(); - } - - @Override - public MapViewImpl getMapViewImpl() { - throw new UnsupportedOperationException(); - } - -} diff --git a/main/src/cgeo/geocaching/maps/google/v1/GoogleDistanceOverlay.java b/main/src/cgeo/geocaching/maps/google/v1/GoogleDistanceOverlay.java deleted file mode 100755 index 281a6e9..0000000 --- a/main/src/cgeo/geocaching/maps/google/v1/GoogleDistanceOverlay.java +++ /dev/null @@ -1,53 +0,0 @@ -package cgeo.geocaching.maps.google.v1; - -import cgeo.geocaching.location.Geopoint; -import cgeo.geocaching.maps.DistanceOverlay; -import cgeo.geocaching.maps.interfaces.GeneralOverlay; -import cgeo.geocaching.maps.interfaces.MapViewImpl; -import cgeo.geocaching.maps.interfaces.OverlayImpl; - -import com.google.android.maps.MapView; -import com.google.android.maps.Overlay; - -import android.graphics.Canvas; - -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; - -public class GoogleDistanceOverlay extends Overlay implements OverlayImpl { - - private final DistanceOverlay overlayBase; - private final Lock lock = new ReentrantLock(); - - public GoogleDistanceOverlay(final MapViewImpl mapView, final Geopoint coords, final String geocode) { - overlayBase = new DistanceOverlay(this, mapView, coords, geocode); - } - - @Override - public void draw(final Canvas canvas, final MapView mapView, final boolean shadow) { - super.draw(canvas, mapView, shadow); - - assert mapView instanceof MapViewImpl; - overlayBase.draw(canvas, (MapViewImpl) mapView, shadow); - } - - public GeneralOverlay getBase() { - return overlayBase; - } - - @Override - public void lock() { - lock.lock(); - } - - @Override - public void unlock() { - lock.unlock(); - } - - @Override - public MapViewImpl getMapViewImpl() { - throw new UnsupportedOperationException(); - } - -} diff --git a/main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java b/main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java index 9664c3e..f3b7e9e 100644 --- a/main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java +++ b/main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java @@ -5,8 +5,6 @@ import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.location.Viewport; import cgeo.geocaching.maps.CachesOverlay; -import cgeo.geocaching.maps.DirectionOverlay; -import cgeo.geocaching.maps.DistanceOverlay; import cgeo.geocaching.maps.PositionAndScaleOverlay; import cgeo.geocaching.maps.interfaces.GeneralOverlay; import cgeo.geocaching.maps.interfaces.GeoPointImpl; @@ -129,28 +127,14 @@ public class GoogleMapView extends MapView implements MapViewImpl { } @Override - public PositionAndScaleOverlay createAddPositionAndScaleOverlay() { + public PositionAndScaleOverlay createAddPositionAndScaleOverlay(final Geopoint coords, final String geocode) { - final GoogleOverlay ovl = new GoogleOverlay(); + final GoogleOverlay ovl = new GoogleOverlay(this, coords, geocode); getOverlays().add(ovl); return (PositionAndScaleOverlay) ovl.getBase(); } @Override - public DirectionOverlay createAddDirectionOverlay(final Geopoint coords, final String geocode) { - final GoogleDirectionOverlay ovl = new GoogleDirectionOverlay(this, coords, geocode); - getOverlays().add(ovl); - return (DirectionOverlay) ovl.getBase(); - } - - @Override - public DistanceOverlay createAddDistanceOverlay(final Geopoint coords, final String geocode) { - final GoogleDistanceOverlay ovl = new GoogleDistanceOverlay(this, coords, geocode); - getOverlays().add(ovl); - return (DistanceOverlay) ovl.getBase(); - } - - @Override public int getMapZoomLevel() { return getZoomLevel(); } diff --git a/main/src/cgeo/geocaching/maps/google/v1/GoogleOverlay.java b/main/src/cgeo/geocaching/maps/google/v1/GoogleOverlay.java index 40a5539..415de1f 100644 --- a/main/src/cgeo/geocaching/maps/google/v1/GoogleOverlay.java +++ b/main/src/cgeo/geocaching/maps/google/v1/GoogleOverlay.java @@ -1,5 +1,6 @@ package cgeo.geocaching.maps.google.v1; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.maps.PositionAndScaleOverlay; import cgeo.geocaching.maps.interfaces.GeneralOverlay; import cgeo.geocaching.maps.interfaces.MapViewImpl; @@ -16,14 +17,14 @@ import java.util.concurrent.locks.ReentrantLock; public class GoogleOverlay extends Overlay implements OverlayImpl { private PositionAndScaleOverlay overlayBase = null; - private Lock lock = new ReentrantLock(); + private final Lock lock = new ReentrantLock(); - public GoogleOverlay() { - overlayBase = new PositionAndScaleOverlay(this); + public GoogleOverlay(final MapViewImpl mapView, final Geopoint coords, final String geocode) { + overlayBase = new PositionAndScaleOverlay(this, mapView, coords, geocode); } @Override - public void draw(Canvas canvas, MapView mapView, boolean shadow) { + public void draw(final Canvas canvas, final MapView mapView, final boolean shadow) { super.draw(canvas, mapView, shadow); if (overlayBase != null) { diff --git a/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java b/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java index f15f12a..1876dfc 100644 --- a/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java +++ b/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java @@ -3,8 +3,6 @@ package cgeo.geocaching.maps.interfaces; import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.location.Viewport; import cgeo.geocaching.maps.CachesOverlay; -import cgeo.geocaching.maps.DirectionOverlay; -import cgeo.geocaching.maps.DistanceOverlay; import cgeo.geocaching.maps.PositionAndScaleOverlay; import org.eclipse.jdt.annotation.NonNull; @@ -49,11 +47,7 @@ public interface MapViewImpl { CachesOverlay createAddMapOverlay(Context context, Drawable drawable); - PositionAndScaleOverlay createAddPositionAndScaleOverlay(); - - DistanceOverlay createAddDistanceOverlay(Geopoint coords, String geocode); - - DirectionOverlay createAddDirectionOverlay(Geopoint coords, String geocode); + PositionAndScaleOverlay createAddPositionAndScaleOverlay(final Geopoint coords, final String geocode); void setMapSource(); diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeDirectionOverlay.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeDirectionOverlay.java deleted file mode 100755 index 98c19db..0000000 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeDirectionOverlay.java +++ /dev/null @@ -1,56 +0,0 @@ -package cgeo.geocaching.maps.mapsforge; - -import cgeo.geocaching.location.Geopoint; -import cgeo.geocaching.maps.DirectionOverlay; -import cgeo.geocaching.maps.interfaces.GeneralOverlay; -import cgeo.geocaching.maps.interfaces.MapViewImpl; -import cgeo.geocaching.maps.interfaces.OverlayImpl; - -import org.mapsforge.android.maps.Projection; -import org.mapsforge.android.maps.overlay.Overlay; - -import android.graphics.Canvas; -import android.graphics.Point; - -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; - -public class MapsforgeDirectionOverlay extends Overlay implements OverlayImpl { - - private DirectionOverlay overlayBase = null; - private final Lock lock = new ReentrantLock(); - - public MapsforgeDirectionOverlay(final MapViewImpl mapView, final Geopoint coords, final String geocode) { - overlayBase = new DirectionOverlay(this, mapView, coords, geocode); - } - - @Override - protected void drawOverlayBitmap(final Canvas canvas, final Point drawPosition, - final Projection projection, final byte drawZoomLevel) { - - if (overlayBase != null) { - overlayBase.drawOverlayBitmap(canvas, drawPosition, new MapsforgeMapProjection(projection), drawZoomLevel); - } - } - - public GeneralOverlay getBase() { - return overlayBase; - } - - @Override - public void lock() { - lock.lock(); - } - - @Override - public void unlock() { - lock.unlock(); - - } - - @Override - public MapViewImpl getMapViewImpl() { - return (MapViewImpl) internalMapView; - } - -} diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeDistanceOverlay.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeDistanceOverlay.java deleted file mode 100755 index ed6b6fb..0000000 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeDistanceOverlay.java +++ /dev/null @@ -1,56 +0,0 @@ -package cgeo.geocaching.maps.mapsforge; - -import cgeo.geocaching.location.Geopoint; -import cgeo.geocaching.maps.DistanceOverlay; -import cgeo.geocaching.maps.interfaces.GeneralOverlay; -import cgeo.geocaching.maps.interfaces.MapViewImpl; -import cgeo.geocaching.maps.interfaces.OverlayImpl; - -import org.mapsforge.android.maps.Projection; -import org.mapsforge.android.maps.overlay.Overlay; - -import android.graphics.Canvas; -import android.graphics.Point; - -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; - -public class MapsforgeDistanceOverlay extends Overlay implements OverlayImpl { - - private DistanceOverlay overlayBase = null; - private final Lock lock = new ReentrantLock(); - - public MapsforgeDistanceOverlay(final MapViewImpl mapView, final Geopoint coords, final String geocode) { - overlayBase = new DistanceOverlay(this, mapView, coords, geocode); - } - - @Override - protected void drawOverlayBitmap(final Canvas canvas, final Point drawPosition, - final Projection projection, final byte drawZoomLevel) { - - if (overlayBase != null) { - overlayBase.drawOverlayBitmap(canvas, drawPosition, new MapsforgeMapProjection(projection), drawZoomLevel); - } - } - - public GeneralOverlay getBase() { - return overlayBase; - } - - @Override - public void lock() { - lock.lock(); - } - - @Override - public void unlock() { - lock.unlock(); - - } - - @Override - public MapViewImpl getMapViewImpl() { - return (MapViewImpl) internalMapView; - } - -} diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java index a81c108..71bf583 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java @@ -4,8 +4,6 @@ import cgeo.geocaching.R; import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.location.Viewport; import cgeo.geocaching.maps.CachesOverlay; -import cgeo.geocaching.maps.DirectionOverlay; -import cgeo.geocaching.maps.DistanceOverlay; import cgeo.geocaching.maps.PositionAndScaleOverlay; import cgeo.geocaching.maps.interfaces.GeneralOverlay; import cgeo.geocaching.maps.interfaces.GeoPointImpl; @@ -114,27 +112,13 @@ public class MapsforgeMapView extends MapView implements MapViewImpl { } @Override - public PositionAndScaleOverlay createAddPositionAndScaleOverlay() { - final MapsforgeOverlay ovl = new MapsforgeOverlay(); + public PositionAndScaleOverlay createAddPositionAndScaleOverlay(final Geopoint coords, final String geocode) { + final MapsforgeOverlay ovl = new MapsforgeOverlay(this, coords, geocode); getOverlays().add(ovl); return (PositionAndScaleOverlay) ovl.getBase(); } @Override - public DirectionOverlay createAddDirectionOverlay(final Geopoint coords, final String geocode) { - final MapsforgeDirectionOverlay ovl = new MapsforgeDirectionOverlay(this, coords, geocode); - getOverlays().add(ovl); - return (DirectionOverlay) ovl.getBase(); - } - - @Override - public DistanceOverlay createAddDistanceOverlay(final Geopoint coords, final String geocode) { - final MapsforgeDistanceOverlay ovl = new MapsforgeDistanceOverlay(this, coords, geocode); - getOverlays().add(ovl); - return (DistanceOverlay) ovl.getBase(); - } - - @Override public int getLatitudeSpan() { int span = 0; diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOverlay.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOverlay.java index 3df4ab0..3926eb6 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOverlay.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOverlay.java @@ -1,5 +1,6 @@ package cgeo.geocaching.maps.mapsforge; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.maps.PositionAndScaleOverlay; import cgeo.geocaching.maps.interfaces.GeneralOverlay; import cgeo.geocaching.maps.interfaces.MapViewImpl; @@ -17,15 +18,15 @@ import java.util.concurrent.locks.ReentrantLock; public class MapsforgeOverlay extends Overlay implements OverlayImpl { private PositionAndScaleOverlay overlayBase = null; - private Lock lock = new ReentrantLock(); + private final Lock lock = new ReentrantLock(); - public MapsforgeOverlay() { - overlayBase = new PositionAndScaleOverlay(this); + public MapsforgeOverlay(final MapViewImpl mapView, final Geopoint coords, final String geocode) { + overlayBase = new PositionAndScaleOverlay(this, mapView, coords, geocode); } @Override - protected void drawOverlayBitmap(Canvas canvas, Point drawPosition, - Projection projection, byte drawZoomLevel) { + protected void drawOverlayBitmap(final Canvas canvas, final Point drawPosition, + final Projection projection, final byte drawZoomLevel) { if (overlayBase != null) { overlayBase.drawOverlayBitmap(canvas, drawPosition, new MapsforgeMapProjection(projection), drawZoomLevel); diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeDirectionOverlay.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeDirectionOverlay.java deleted file mode 100755 index 281b27f..0000000 --- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeDirectionOverlay.java +++ /dev/null @@ -1,57 +0,0 @@ -package cgeo.geocaching.maps.mapsforge.v024; - -import cgeo.geocaching.location.Geopoint; -import cgeo.geocaching.maps.DirectionOverlay; -import cgeo.geocaching.maps.interfaces.GeneralOverlay; -import cgeo.geocaching.maps.interfaces.MapViewImpl; -import cgeo.geocaching.maps.interfaces.OverlayImpl; - -import org.mapsforge.android.mapsold.Overlay; -import org.mapsforge.android.mapsold.Projection; - -import android.graphics.Canvas; -import android.graphics.Point; - -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; - -public class MapsforgeDirectionOverlay extends Overlay implements OverlayImpl { - - private DirectionOverlay overlayBase = null; - private final Lock lock = new ReentrantLock(); - - public MapsforgeDirectionOverlay(final MapViewImpl mapView, final Geopoint coords, final String geocode) { - overlayBase = new DirectionOverlay(this, mapView, coords, geocode); - } - - @Override - protected void drawOverlayBitmap(final Canvas canvas, final Point drawPosition, - final Projection projection, final byte drawZoomLevel) { - - if (overlayBase != null) { - overlayBase.drawOverlayBitmap(canvas, drawPosition, new MapsforgeMapProjection(projection), drawZoomLevel); - } - } - - public GeneralOverlay getBase() { - return overlayBase; - } - - @Override - public void lock() { - lock.lock(); - - } - - @Override - public void unlock() { - lock.unlock(); - - } - - @Override - public MapViewImpl getMapViewImpl() { - return (MapViewImpl) internalMapView; - } - -} diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeDistanceOverlay.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeDistanceOverlay.java deleted file mode 100755 index 25b97f0..0000000 --- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeDistanceOverlay.java +++ /dev/null @@ -1,57 +0,0 @@ -package cgeo.geocaching.maps.mapsforge.v024; - -import cgeo.geocaching.location.Geopoint; -import cgeo.geocaching.maps.DistanceOverlay; -import cgeo.geocaching.maps.interfaces.GeneralOverlay; -import cgeo.geocaching.maps.interfaces.MapViewImpl; -import cgeo.geocaching.maps.interfaces.OverlayImpl; - -import org.mapsforge.android.mapsold.Overlay; -import org.mapsforge.android.mapsold.Projection; - -import android.graphics.Canvas; -import android.graphics.Point; - -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; - -public class MapsforgeDistanceOverlay extends Overlay implements OverlayImpl { - - private DistanceOverlay overlayBase = null; - private final Lock lock = new ReentrantLock(); - - public MapsforgeDistanceOverlay(final MapViewImpl mapView, final Geopoint coords, final String geocode) { - overlayBase = new DistanceOverlay(this, mapView, coords, geocode); - } - - @Override - protected void drawOverlayBitmap(final Canvas canvas, final Point drawPosition, - final Projection projection, final byte drawZoomLevel) { - - if (overlayBase != null) { - overlayBase.drawOverlayBitmap(canvas, drawPosition, new MapsforgeMapProjection(projection), drawZoomLevel); - } - } - - public GeneralOverlay getBase() { - return overlayBase; - } - - @Override - public void lock() { - lock.lock(); - - } - - @Override - public void unlock() { - lock.unlock(); - - } - - @Override - public MapViewImpl getMapViewImpl() { - return (MapViewImpl) internalMapView; - } - -} diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java index 937c13b..af9b756 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java @@ -4,8 +4,6 @@ import cgeo.geocaching.R; import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.location.Viewport; import cgeo.geocaching.maps.CachesOverlay; -import cgeo.geocaching.maps.DirectionOverlay; -import cgeo.geocaching.maps.DistanceOverlay; import cgeo.geocaching.maps.PositionAndScaleOverlay; import cgeo.geocaching.maps.interfaces.GeneralOverlay; import cgeo.geocaching.maps.interfaces.GeoPointImpl; @@ -105,27 +103,13 @@ public class MapsforgeMapView024 extends MapView implements MapViewImpl { } @Override - public PositionAndScaleOverlay createAddPositionAndScaleOverlay() { - final MapsforgeOverlay ovl = new MapsforgeOverlay(); + public PositionAndScaleOverlay createAddPositionAndScaleOverlay(final Geopoint coords, final String geocode) { + final MapsforgeOverlay ovl = new MapsforgeOverlay(this, coords, geocode); getOverlays().add(ovl); return (PositionAndScaleOverlay) ovl.getBase(); } @Override - public DirectionOverlay createAddDirectionOverlay(final Geopoint coords, final String geocode) { - final MapsforgeDirectionOverlay ovl = new MapsforgeDirectionOverlay(this, coords, geocode); - getOverlays().add(ovl); - return (DirectionOverlay) ovl.getBase(); - } - - @Override - public DistanceOverlay createAddDistanceOverlay(final Geopoint coords, final String geocode) { - final MapsforgeDistanceOverlay ovl = new MapsforgeDistanceOverlay(this, coords, geocode); - getOverlays().add(ovl); - return (DistanceOverlay) ovl.getBase(); - } - - @Override public int getLatitudeSpan() { int span = 0; diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOverlay.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOverlay.java index bfb3548..fda6dc1 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOverlay.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOverlay.java @@ -1,5 +1,6 @@ package cgeo.geocaching.maps.mapsforge.v024; +import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.maps.PositionAndScaleOverlay; import cgeo.geocaching.maps.interfaces.GeneralOverlay; import cgeo.geocaching.maps.interfaces.MapViewImpl; @@ -17,15 +18,15 @@ import java.util.concurrent.locks.ReentrantLock; public class MapsforgeOverlay extends Overlay implements OverlayImpl { private PositionAndScaleOverlay overlayBase = null; - private Lock lock = new ReentrantLock(); + private final Lock lock = new ReentrantLock(); - public MapsforgeOverlay() { - overlayBase = new PositionAndScaleOverlay(this); + public MapsforgeOverlay(final MapViewImpl mapView, final Geopoint coords, final String geocode) { + overlayBase = new PositionAndScaleOverlay(this, mapView, coords, geocode); } @Override - protected void drawOverlayBitmap(Canvas canvas, Point drawPosition, - Projection projection, byte drawZoomLevel) { + protected void drawOverlayBitmap(final Canvas canvas, final Point drawPosition, + final Projection projection, final byte drawZoomLevel) { if (overlayBase != null) { overlayBase.drawOverlayBitmap(canvas, drawPosition, new MapsforgeMapProjection(projection), drawZoomLevel); -- cgit v1.1 From 839d0b68f7d54d4c9f3e324c188b3cc11c8c9111 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konrad=20Gr=C3=A4fe?= Date: Wed, 28 Jan 2015 21:22:05 +0100 Subject: Add some transparency to the distance and direction drawers --- main/src/cgeo/geocaching/maps/DirectionDrawer.java | 4 ++-- main/src/cgeo/geocaching/maps/DistanceDrawer.java | 25 +++++++++------------- 2 files changed, 12 insertions(+), 17 deletions(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/DirectionDrawer.java b/main/src/cgeo/geocaching/maps/DirectionDrawer.java index ccef59c..095ab23 100755 --- a/main/src/cgeo/geocaching/maps/DirectionDrawer.java +++ b/main/src/cgeo/geocaching/maps/DirectionDrawer.java @@ -34,8 +34,8 @@ public class DirectionDrawer { if (line == null) { line = new Paint(); line.setAntiAlias(true); - line.setStrokeWidth(2f); - line.setColor(0xFFEB391E); + line.setStrokeWidth(4f); + line.setColor(0x80EB391E); } final Point pos = new Point(); diff --git a/main/src/cgeo/geocaching/maps/DistanceDrawer.java b/main/src/cgeo/geocaching/maps/DistanceDrawer.java index 6450f70..f2d11bb 100755 --- a/main/src/cgeo/geocaching/maps/DistanceDrawer.java +++ b/main/src/cgeo/geocaching/maps/DistanceDrawer.java @@ -70,34 +70,29 @@ public class DistanceDrawer { if (blurBoxShadow == null) { blurBoxShadow = new BlurMaskFilter(3, BlurMaskFilter.Blur.NORMAL); - } - if (paintBoxShadow == null) { paintBoxShadow = new Paint(); paintBoxShadow.setAntiAlias(true); paintBoxShadow.setMaskFilter(blurBoxShadow); - } - if (paintBox == null) { paintBox = new Paint(); paintBox.setAntiAlias(true); - } - if (paintText == null) { paintText = new Paint(); paintText.setAntiAlias(true); paintText.setTextAlign(Paint.Align.LEFT); paintText.setTypeface(Typeface.DEFAULT_BOLD); - } - if (needsInvertedColors) { - paintBoxShadow.setColor(0xFF000000); - paintBox.setColor(0xFFFFFFFF); - paintText.setColor(0xFF000000); - } else { - paintBoxShadow.setColor(0xFFFFFFFF); - paintBox.setColor(0xFF000000); - paintText.setColor(0xFFFFFFFF); + final int TRANSPARENCY = 0x80000000; + if (needsInvertedColors) { + paintBoxShadow.setColor(0x000000 | TRANSPARENCY); + paintBox.setColor(0xFFFFFF | TRANSPARENCY); + paintText.setColor(0xFF000000); + } else { + paintBoxShadow.setColor(0xFFFFFF | TRANSPARENCY); + paintBox.setColor(0x000000 | TRANSPARENCY); + paintText.setColor(0xFFFFFFFF); + } } /* Calculate text size */ -- cgit v1.1 From d69339c013d71ee2387f366163ccfd93af86800e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konrad=20Gr=C3=A4fe?= Date: Wed, 28 Jan 2015 22:44:07 +0100 Subject: Fix NullPointerException when a map with no destination is opened --- .../geocaching/maps/PositionAndScaleOverlay.java | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/PositionAndScaleOverlay.java b/main/src/cgeo/geocaching/maps/PositionAndScaleOverlay.java index 51d83aa..9a6e4b9 100644 --- a/main/src/cgeo/geocaching/maps/PositionAndScaleOverlay.java +++ b/main/src/cgeo/geocaching/maps/PositionAndScaleOverlay.java @@ -22,20 +22,20 @@ public class PositionAndScaleOverlay implements GeneralOverlay { DirectionDrawer directionDrawer = null; DistanceDrawer distanceDrawer = null; - public PositionAndScaleOverlay(final OverlayImpl ovlImpl, final MapViewImpl mapView, Geopoint coords, final String geocode) { + public PositionAndScaleOverlay(final OverlayImpl ovlImpl, final MapViewImpl mapView, final Geopoint coords, final String geocode) { this.ovlImpl = ovlImpl; positionDrawer = new PositionDrawer(); scaleDrawer = new ScaleDrawer(); - if (coords == null && geocode != null) { - final Viewport bounds = DataStore.getBounds(geocode); - if (bounds != null) { - coords = bounds.center; - } - } if (coords != null) { directionDrawer = new DirectionDrawer(coords); distanceDrawer = new DistanceDrawer(mapView, coords); + } else if (geocode != null) { + final Viewport bounds = DataStore.getBounds(geocode); + if (bounds != null) { + directionDrawer = new DirectionDrawer(bounds.center); + distanceDrawer = new DistanceDrawer(mapView, bounds.center); + } } } @@ -74,10 +74,14 @@ public class PositionAndScaleOverlay implements GeneralOverlay { } private void drawInternal(final Canvas canvas, final MapProjectionImpl projection, final MapViewImpl mapView) { - directionDrawer.drawDirection(canvas, projection); + if (directionDrawer != null) { + directionDrawer.drawDirection(canvas, projection); + } positionDrawer.drawPosition(canvas, projection); scaleDrawer.drawScale(canvas, mapView); - distanceDrawer.drawDistance(canvas); + if (distanceDrawer != null) { + distanceDrawer.drawDistance(canvas); + } } @Override -- cgit v1.1 From 109102414e61d9f5c6773e979a05784c9cc0d9be Mon Sep 17 00:00:00 2001 From: rsudev Date: Mon, 9 Feb 2015 23:36:17 +0100 Subject: Make direction width depend on pixel density --- main/src/cgeo/geocaching/maps/DirectionDrawer.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/DirectionDrawer.java b/main/src/cgeo/geocaching/maps/DirectionDrawer.java index 095ab23..c746221 100755 --- a/main/src/cgeo/geocaching/maps/DirectionDrawer.java +++ b/main/src/cgeo/geocaching/maps/DirectionDrawer.java @@ -1,25 +1,37 @@ package cgeo.geocaching.maps; +import cgeo.geocaching.CgeoApplication; import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.maps.interfaces.MapItemFactory; import cgeo.geocaching.maps.interfaces.MapProjectionImpl; import cgeo.geocaching.settings.Settings; +import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Point; import android.location.Location; +import android.util.DisplayMetrics; +import android.view.WindowManager; public class DirectionDrawer { private Geopoint currentCoords; private final Geopoint destinationCoords; private final MapItemFactory mapItemFactory; + private final float width; private Paint line = null; public DirectionDrawer(final Geopoint coords) { this.destinationCoords = coords; this.mapItemFactory = Settings.getMapProvider().getMapItemFactory(); + + final DisplayMetrics metrics = new DisplayMetrics(); + final WindowManager windowManager = (WindowManager) CgeoApplication.getInstance().getSystemService(Context.WINDOW_SERVICE); + windowManager.getDefaultDisplay().getMetrics(metrics); + + width = 4f * metrics.density; + } public void setCoordinates(final Location coordinatesIn) { @@ -34,7 +46,7 @@ public class DirectionDrawer { if (line == null) { line = new Paint(); line.setAntiAlias(true); - line.setStrokeWidth(4f); + line.setStrokeWidth(width); line.setColor(0x80EB391E); } -- cgit v1.1 From fa6741ea0b36317d0c141e765d53ee37de72fa1d Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Tue, 10 Feb 2015 11:47:25 +0100 Subject: Remove empty JavaDoc @param and @return --- main/src/cgeo/geocaching/maps/CGeoMap.java | 2 -- main/src/cgeo/geocaching/maps/CachesOverlay.java | 2 -- main/src/cgeo/geocaching/maps/DirectionDrawer.java | 0 main/src/cgeo/geocaching/maps/DistanceDrawer.java | 0 4 files changed, 4 deletions(-) mode change 100755 => 100644 main/src/cgeo/geocaching/maps/DirectionDrawer.java mode change 100755 => 100644 main/src/cgeo/geocaching/maps/DistanceDrawer.java (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index a7983bb..70d8bb8 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -511,7 +511,6 @@ public class CGeoMap extends AbstractMap implements ViewFactory { /** * Set the zoom of the map. The zoom is restricted to a certain minimum in case of live map. * - * @param zoom */ private void setZoom(final int zoom) { mapView.getMapController().setZoom(isLiveEnabled ? Math.max(zoom, MIN_LIVEMAP_ZOOM) : zoom); @@ -1120,7 +1119,6 @@ public class CGeoMap extends AbstractMap implements ViewFactory { /** * get if map is loading something * - * @return */ public boolean isLoading() { return !loadTimer.isUnsubscribed() && diff --git a/main/src/cgeo/geocaching/maps/CachesOverlay.java b/main/src/cgeo/geocaching/maps/CachesOverlay.java index c4c4465..048217e 100644 --- a/main/src/cgeo/geocaching/maps/CachesOverlay.java +++ b/main/src/cgeo/geocaching/maps/CachesOverlay.java @@ -158,8 +158,6 @@ public class CachesOverlay extends AbstractItemizedOverlay { * reality and therefore the minor changes due to the projection will not make any visible difference at the zoom * levels which are used to see the circles. * - * @param projection - * @return */ private int calculateDrawingRadius(MapProjectionImpl projection) { float[] distanceArray = new float[1]; diff --git a/main/src/cgeo/geocaching/maps/DirectionDrawer.java b/main/src/cgeo/geocaching/maps/DirectionDrawer.java old mode 100755 new mode 100644 diff --git a/main/src/cgeo/geocaching/maps/DistanceDrawer.java b/main/src/cgeo/geocaching/maps/DistanceDrawer.java old mode 100755 new mode 100644 -- cgit v1.1 From 80bf4445722190f96c1a017efc2e841ce33d4d45 Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Wed, 11 Feb 2015 23:16:55 +0100 Subject: new: show hint in compass and map --- main/src/cgeo/geocaching/maps/CGeoMap.java | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 70d8bb8..467a02f 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -682,6 +682,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { default: // DETAILED menu.findItem(R.id.menu_strategy_detailed).setChecked(true); } + menu.findItem(R.id.menu_hint).setVisible(mapMode == MapMode.SINGLE); } catch (final RuntimeException e) { Log.e("CGeoMap.onPrepareOptionsMenu", e); } @@ -785,6 +786,12 @@ public class CGeoMap extends AbstractMap implements ViewFactory { Settings.setLiveMapStrategy(Strategy.DETAILED); return true; } + case R.id.menu_hint: + if (caches.size() == 1) { + final String hint = caches.iterator().next().getHint(); + ActivityMixin.showToast(getActivity(), StringUtils.defaultString(hint, getActivity().getString(R.string.cache_hint_not_available))); + } + return true; default: final MapSource mapSource = MapProviderFactory.getMapSource(id); if (mapSource != null) { -- cgit v1.1 From 577abc10d5503c54d40f1da0ffa4765b935925b1 Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Fri, 13 Feb 2015 08:03:45 +0100 Subject: fix #4669: fix toast if no hint available --- main/src/cgeo/geocaching/maps/CGeoMap.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 467a02f..4e08311 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -788,8 +788,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { } case R.id.menu_hint: if (caches.size() == 1) { - final String hint = caches.iterator().next().getHint(); - ActivityMixin.showToast(getActivity(), StringUtils.defaultString(hint, getActivity().getString(R.string.cache_hint_not_available))); + caches.iterator().next().showHintToast(getActivity()); } return true; default: -- cgit v1.1 From 2f6dd14ce355f42f0fdcc23445ec6d2c119b095e Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Sun, 15 Feb 2015 16:44:14 +0100 Subject: fix #4676: hide show as list menu in map for single cache --- main/src/cgeo/geocaching/maps/CGeoMap.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 4e08311..bc5a5e1 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -665,7 +665,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { item = menu.findItem(R.id.menu_theme_mode); // show theme selection item.setVisible(mapView.hasMapThemes()); - menu.findItem(R.id.menu_as_list).setVisible(!isLoading()); + menu.findItem(R.id.menu_as_list).setVisible(!isLoading() && caches.size() > 1); menu.findItem(R.id.submenu_strategy).setVisible(isLiveEnabled); -- cgit v1.1 From f071c439321817ee09581dcbdf10c553214ff283 Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Sun, 15 Feb 2015 19:03:35 +0100 Subject: fix #4677 have compass menu in map of single cache --- main/src/cgeo/geocaching/maps/CGeoMap.java | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index bc5a5e1..009e49d 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -4,6 +4,7 @@ import butterknife.ButterKnife; import cgeo.geocaching.CacheListActivity; import cgeo.geocaching.CgeoApplication; +import cgeo.geocaching.CompassActivity; import cgeo.geocaching.DataStore; import cgeo.geocaching.Geocache; import cgeo.geocaching.Intents; @@ -683,6 +684,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { menu.findItem(R.id.menu_strategy_detailed).setChecked(true); } menu.findItem(R.id.menu_hint).setVisible(mapMode == MapMode.SINGLE); + menu.findItem(R.id.menu_compass).setVisible(mapMode == MapMode.SINGLE); } catch (final RuntimeException e) { Log.e("CGeoMap.onPrepareOptionsMenu", e); } @@ -791,6 +793,11 @@ public class CGeoMap extends AbstractMap implements ViewFactory { caches.iterator().next().showHintToast(getActivity()); } return true; + case R.id.menu_compass: + if (caches.size() == 1) { + CompassActivity.startActivityCache(this.getActivity(), caches.iterator().next()); + } + return true; default: final MapSource mapSource = MapProviderFactory.getMapSource(id); if (mapSource != null) { -- cgit v1.1 From b108f2aded11884b809618f876ee2f2b474df86c Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Sun, 15 Feb 2015 19:25:05 +0100 Subject: refactoring: remove unused code --- main/src/cgeo/geocaching/maps/CGeoMap.java | 9 ++-- main/src/cgeo/geocaching/maps/LiveMapStrategy.java | 48 ---------------------- main/src/cgeo/geocaching/maps/LivemapStrategy.java | 45 ++++++++++++++++++++ .../maps/interfaces/MapActivityImpl.java | 3 ++ 4 files changed, 52 insertions(+), 53 deletions(-) delete mode 100644 main/src/cgeo/geocaching/maps/LiveMapStrategy.java create mode 100644 main/src/cgeo/geocaching/maps/LivemapStrategy.java (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 009e49d..b2bb8a6 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -23,7 +23,6 @@ import cgeo.geocaching.enumerations.WaypointType; import cgeo.geocaching.list.StoredList; import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.location.Viewport; -import cgeo.geocaching.maps.LiveMapStrategy.Strategy; import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import cgeo.geocaching.maps.interfaces.MapActivityImpl; @@ -770,22 +769,22 @@ public class CGeoMap extends AbstractMap implements ViewFactory { } case R.id.menu_strategy_fastest: { item.setChecked(true); - Settings.setLiveMapStrategy(Strategy.FASTEST); + Settings.setLiveMapStrategy(LivemapStrategy.FASTEST); return true; } case R.id.menu_strategy_fast: { item.setChecked(true); - Settings.setLiveMapStrategy(Strategy.FAST); + Settings.setLiveMapStrategy(LivemapStrategy.FAST); return true; } case R.id.menu_strategy_auto: { item.setChecked(true); - Settings.setLiveMapStrategy(Strategy.AUTO); + Settings.setLiveMapStrategy(LivemapStrategy.AUTO); return true; } case R.id.menu_strategy_detailed: { item.setChecked(true); - Settings.setLiveMapStrategy(Strategy.DETAILED); + Settings.setLiveMapStrategy(LivemapStrategy.DETAILED); return true; } case R.id.menu_hint: diff --git a/main/src/cgeo/geocaching/maps/LiveMapStrategy.java b/main/src/cgeo/geocaching/maps/LiveMapStrategy.java deleted file mode 100644 index 16d5e8b..0000000 --- a/main/src/cgeo/geocaching/maps/LiveMapStrategy.java +++ /dev/null @@ -1,48 +0,0 @@ -package cgeo.geocaching.maps; - -import cgeo.geocaching.CgeoApplication; -import cgeo.geocaching.R; - -import java.util.EnumSet; - -/** - * Defines the strategy for the Live Map - */ -public interface LiveMapStrategy { - - public enum StrategyFlag { - LOAD_TILES, // 2x2 tiles filling the complete viewport - PARSE_TILES, // parse PNG images - SEARCH_NEARBY // searchByCoords() - } - - public enum Strategy { - FASTEST(1, EnumSet.of(StrategyFlag.LOAD_TILES), R.string.map_strategy_fastest), - FAST(2, EnumSet.of(StrategyFlag.LOAD_TILES, StrategyFlag.PARSE_TILES), R.string.map_strategy_fast), - AUTO(3, EnumSet.noneOf(StrategyFlag.class), R.string.map_strategy_auto), - DETAILED(4, EnumSet.allOf(StrategyFlag.class), R.string.map_strategy_detailed); - - public final int id; - public final EnumSet flags; - private final int stringId; - - Strategy(int id, EnumSet flags, int stringId) { - this.id = id; - this.flags = flags; - this.stringId = stringId; - } - - public static Strategy getById(final int id) { - for (Strategy strategy : Strategy.values()) { - if (strategy.id == id) { - return strategy; - } - } - return AUTO; - } - - public final String getL10n() { - return CgeoApplication.getInstance().getBaseContext().getResources().getString(stringId); - } - } -} diff --git a/main/src/cgeo/geocaching/maps/LivemapStrategy.java b/main/src/cgeo/geocaching/maps/LivemapStrategy.java new file mode 100644 index 0000000..c135fc8 --- /dev/null +++ b/main/src/cgeo/geocaching/maps/LivemapStrategy.java @@ -0,0 +1,45 @@ +package cgeo.geocaching.maps; + +import cgeo.geocaching.CgeoApplication; +import cgeo.geocaching.R; + +import java.util.EnumSet; + +/** + * Defines the strategy for the Live Map + */ +public enum LivemapStrategy { + FASTEST(1, EnumSet.of(Flag.LOAD_TILES), R.string.map_strategy_fastest), + FAST(2, EnumSet.of(Flag.LOAD_TILES, Flag.PARSE_TILES), R.string.map_strategy_fast), + AUTO(3, EnumSet.noneOf(Flag.class), R.string.map_strategy_auto), + DETAILED(4, EnumSet.allOf(Flag.class), R.string.map_strategy_detailed); + + public final int id; + public final EnumSet flags; + private final int stringId; + + public enum Flag { + LOAD_TILES, // 2x2 tiles filling the complete viewport + PARSE_TILES, // parse PNG images + SEARCH_NEARBY // searchByCoords() + } + + LivemapStrategy(final int id, final EnumSet flags, final int stringId) { + this.id = id; + this.flags = flags; + this.stringId = stringId; + } + + public static LivemapStrategy getById(final int id) { + for (final LivemapStrategy strategy : LivemapStrategy.values()) { + if (strategy.id == id) { + return strategy; + } + } + return AUTO; + } + + public final String getL10n() { + return CgeoApplication.getInstance().getBaseContext().getResources().getString(stringId); + } +} diff --git a/main/src/cgeo/geocaching/maps/interfaces/MapActivityImpl.java b/main/src/cgeo/geocaching/maps/interfaces/MapActivityImpl.java index 3596d5f..1e69b44 100644 --- a/main/src/cgeo/geocaching/maps/interfaces/MapActivityImpl.java +++ b/main/src/cgeo/geocaching/maps/interfaces/MapActivityImpl.java @@ -33,5 +33,8 @@ public interface MapActivityImpl { boolean superOnOptionsItemSelected(MenuItem item); + /** + * called from the pseudo actionbar layout + */ public abstract void navigateUp(View view); } -- cgit v1.1 From 083593725b909bb011f291c30e46e605e6908d2a Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Sat, 21 Feb 2015 12:54:36 +0100 Subject: disable Android Beam when there is nothing to beam --- main/src/cgeo/geocaching/maps/CGeoMap.java | 2 ++ 1 file changed, 2 insertions(+) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index b2bb8a6..fd08adb 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -32,6 +32,7 @@ import cgeo.geocaching.maps.interfaces.MapProvider; import cgeo.geocaching.maps.interfaces.MapSource; import cgeo.geocaching.maps.interfaces.MapViewImpl; import cgeo.geocaching.maps.interfaces.OnMapDragListener; +import cgeo.geocaching.network.AndroidBeam; import cgeo.geocaching.sensors.GeoData; import cgeo.geocaching.sensors.GeoDirHandler; import cgeo.geocaching.sensors.Sensors; @@ -496,6 +497,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { if (!CgeoApplication.getInstance().isLiveMapHintShownInThisSession() && Settings.getLiveMapHintShowCount() <= 3) { LiveMapInfoDialogBuilder.create(activity).show(); } + AndroidBeam.disable(activity); } private void initMyLocationSwitchButton(final CheckBox locSwitch) { -- cgit v1.1 From 7a6d90d0ce29acd65754947c9a94afb35637831f Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Thu, 26 Feb 2015 21:33:41 +0100 Subject: fix some findbugs issues --- main/src/cgeo/geocaching/maps/CGeoMap.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index fd08adb..ed938bd 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -464,7 +464,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { mapView.getMapController().setCenter(Settings.getMapCenter()); if (null == mapStateIntent) { - followMyLocation &= mapMode == MapMode.LIVE; + followMyLocation = followMyLocation && (mapMode == MapMode.LIVE); } else { followMyLocation = 1 == mapStateIntent[3]; if ((overlayCaches.getCircles() ? 1 : 0) != mapStateIntent[4]) { -- cgit v1.1 From 9c0b48c8282c5dee1be9fb42fe0bb8b01b3a7a20 Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Sat, 28 Feb 2015 18:27:28 +0100 Subject: fix #4694: use second line in map title --- main/src/cgeo/geocaching/maps/CGeoMap.java | 45 ++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 11 deletions(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index ed938bd..38fe6bd 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -219,28 +219,34 @@ public class CGeoMap extends AbstractMap implements ViewFactory { switch (what) { case UPDATE_TITLE: // set title - final StringBuilder title = new StringBuilder(); - if (map.mapMode == MapMode.LIVE && map.isLiveEnabled) { - title.append(map.res.getString(R.string.map_live)); + map.setTitle(map.res.getString(R.string.map_live)); } else { - title.append(map.mapTitle); + map.setTitle(map.mapTitle); } + // count caches in the sub title map.countVisibleCaches(); - if (!map.caches.isEmpty() && !map.mapTitle.contains("[")) { - title.append(" [").append(map.cachesCnt); - if (map.cachesCnt != map.caches.size() && Settings.isDebug()) { - title.append('/').append(map.caches.size()); + final StringBuilder subtitle = new StringBuilder(); + if (!map.caches.isEmpty()) { + final int totalCount = map.caches.size(); + + if (map.cachesCnt != totalCount && Settings.isDebug()) { + subtitle.append(map.cachesCnt).append('/').append(totalCount).append(map.res.getQuantityString(R.plurals.cache_counts, totalCount, totalCount)); + } + else { + subtitle.append(map.res.getQuantityString(R.plurals.cache_counts, map.cachesCnt, map.cachesCnt)); } - title.append(']'); } if (Settings.isDebug() && map.lastSearchResult != null && StringUtils.isNotBlank(map.lastSearchResult.getUrl())) { - title.append('[').append(map.lastSearchResult.getUrl()).append(']'); + subtitle.append(" [").append(map.lastSearchResult.getUrl()).append(']'); + } + + if (subtitle.length() > 0) { + map.setSubtitle(subtitle.toString()); } - map.setTitle(title.toString()); break; case INVALIDATE_MAP: map.mapView.repaintRequired(null); @@ -267,10 +273,27 @@ public class CGeoMap extends AbstractMap implements ViewFactory { } } + private void setSubtitle(final String subtitle) { + /* Compatibility for the old Action Bar, only used by the maps activity at the moment */ + final TextView titleView = ButterKnife.findById(activity, R.id.actionbar_title); + if (titleView != null) { + titleView.setText(titleView.getText().toString() + ' ' + subtitle); + } + if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)) { + setSubtitleIceCreamSandwich(subtitle); + } + } + @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) private void setTitleIceCreamSandwich(final String title) { activity.getActionBar().setTitle(title); } + + @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) + private void setSubtitleIceCreamSandwich(final String subtitle) { + activity.getActionBar().setSubtitle(subtitle); + } + /** Updates the progress. */ private static final class ShowProgressHandler extends Handler { private int counter = 0; -- cgit v1.1 From c8caa139c26f3f01c33060edec4cd2e209cf21a8 Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Sun, 1 Mar 2015 08:24:14 +0100 Subject: new: show cache name in title when searching around it --- main/src/cgeo/geocaching/maps/CGeoMap.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 38fe6bd..e0e0c48 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -420,7 +420,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { coordsIntent = extras.getParcelable(Intents.EXTRA_COORDS); waypointTypeIntent = WaypointType.findById(extras.getString(Intents.EXTRA_WPTTYPE)); mapStateIntent = extras.getIntArray(Intents.EXTRA_MAPSTATE); - mapTitle = extras.getString(Intents.EXTRA_MAP_TITLE); + mapTitle = extras.getString(Intents.EXTRA_TITLE); } else { mapMode = MapMode.LIVE; @@ -940,7 +940,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { mapIntent.putExtra(Intents.EXTRA_COORDS, coordsIntent); } mapIntent.putExtra(Intents.EXTRA_WPTTYPE, waypointTypeIntent != null ? waypointTypeIntent.id : null); - mapIntent.putExtra(Intents.EXTRA_MAP_TITLE, mapTitle); + mapIntent.putExtra(Intents.EXTRA_TITLE, mapTitle); mapIntent.putExtra(Intents.EXTRA_MAP_MODE, mapMode); mapIntent.putExtra(Intents.EXTRA_LIVE_ENABLED, isLiveEnabled); @@ -1658,7 +1658,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { mapIntent.putExtra(Intents.EXTRA_MAP_MODE, MapMode.LIST); mapIntent.putExtra(Intents.EXTRA_LIVE_ENABLED, false); if (StringUtils.isNotBlank(title)) { - mapIntent.putExtra(Intents.EXTRA_MAP_TITLE, title); + mapIntent.putExtra(Intents.EXTRA_TITLE, title); } fromActivity.startActivity(mapIntent); } @@ -1678,7 +1678,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { mapIntent.putExtra(Intents.EXTRA_WPTTYPE, type.id); } if (StringUtils.isNotBlank(title)) { - mapIntent.putExtra(Intents.EXTRA_MAP_TITLE, title); + mapIntent.putExtra(Intents.EXTRA_TITLE, title); } fromActivity.startActivity(mapIntent); } @@ -1688,7 +1688,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { mapIntent.putExtra(Intents.EXTRA_MAP_MODE, MapMode.SINGLE); mapIntent.putExtra(Intents.EXTRA_LIVE_ENABLED, false); mapIntent.putExtra(Intents.EXTRA_GEOCODE, geocode); - mapIntent.putExtra(Intents.EXTRA_MAP_TITLE, geocode); + mapIntent.putExtra(Intents.EXTRA_TITLE, geocode); fromActivity.startActivity(mapIntent); } -- cgit v1.1 From b6ed572616383b57bc2956f6b41e2853724c23f3 Mon Sep 17 00:00:00 2001 From: rsudev Date: Sun, 1 Mar 2015 10:28:07 +0100 Subject: Remove doubled totalcount in map title Small coorection to: fix #4694: use second line in map title (commit 9c0b48c8282c5dee1be9fb42fe0bb8b01b3a7a20) --- main/src/cgeo/geocaching/maps/CGeoMap.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index e0e0c48..7cd13a7 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -232,7 +232,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { final int totalCount = map.caches.size(); if (map.cachesCnt != totalCount && Settings.isDebug()) { - subtitle.append(map.cachesCnt).append('/').append(totalCount).append(map.res.getQuantityString(R.plurals.cache_counts, totalCount, totalCount)); + subtitle.append(map.cachesCnt).append('/').append(map.res.getQuantityString(R.plurals.cache_counts, totalCount, totalCount)); } else { subtitle.append(map.res.getQuantityString(R.plurals.cache_counts, map.cachesCnt, map.cachesCnt)); -- cgit v1.1 From 76156d12f1c1f2eb49eea5f63b7a34e0bb4fef0b Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Wed, 4 Mar 2015 16:49:58 +0100 Subject: remove mapsforge 0.24 support --- .../maps/mapsforge/MapsforgeMapProvider.java | 50 +--- .../maps/mapsforge/v024/MapsforgeCacheOverlay.java | 113 --------- .../mapsforge/v024/MapsforgeCacheOverlayItem.java | 37 --- .../maps/mapsforge/v024/MapsforgeGeoPoint.java | 18 -- .../mapsforge/v024/MapsforgeMapActivity024.java | 124 ---------- .../mapsforge/v024/MapsforgeMapController.java | 55 ----- .../mapsforge/v024/MapsforgeMapItemFactory024.java | 20 -- .../mapsforge/v024/MapsforgeMapProjection.java | 29 --- .../maps/mapsforge/v024/MapsforgeMapView024.java | 255 --------------------- .../maps/mapsforge/v024/MapsforgeOverlay.java | 55 ----- 10 files changed, 11 insertions(+), 745 deletions(-) delete mode 100644 main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeCacheOverlay.java delete mode 100644 main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeCacheOverlayItem.java delete mode 100644 main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeGeoPoint.java delete mode 100644 main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapActivity024.java delete mode 100644 main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapController.java delete mode 100644 main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapItemFactory024.java delete mode 100644 main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapProjection.java delete mode 100644 main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java delete mode 100644 main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOverlay.java (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProvider.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProvider.java index 01b10ec..8027808 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProvider.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProvider.java @@ -7,8 +7,6 @@ import cgeo.geocaching.maps.MapProviderFactory; import cgeo.geocaching.maps.interfaces.MapItemFactory; import cgeo.geocaching.maps.interfaces.MapProvider; import cgeo.geocaching.maps.interfaces.MapSource; -import cgeo.geocaching.maps.mapsforge.v024.MapsforgeMapActivity024; -import cgeo.geocaching.maps.mapsforge.v024.MapsforgeMapItemFactory024; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.utils.Log; @@ -30,7 +28,6 @@ public final class MapsforgeMapProvider extends AbstractMapProvider { public static final String MAPSFORGE_CYCLEMAP_ID = "MAPSFORGE_CYCLEMAP"; public static final String MAPSFORGE_MAPNIK_ID = "MAPSFORGE_MAPNIK"; - private boolean oldMap = false; private MapItemFactory mapItemFactory = new MapsforgeMapItemFactory(); private MapsforgeMapProvider() { @@ -56,13 +53,13 @@ public final class MapsforgeMapProvider extends AbstractMapProvider { return Collections.emptyList(); } - File directory = new File(directoryPath); + final File directory = new File(directoryPath); if (directory.isDirectory()) { try { - ArrayList mapFileList = new ArrayList<>(); + final ArrayList mapFileList = new ArrayList<>(); final File[] files = directory.listFiles(); if (ArrayUtils.isNotEmpty(files)) { - for (File file : files) { + for (final File file : files) { if (file.getName().endsWith(".map")) { if (MapsforgeMapProvider.isValidMapFile(file.getAbsolutePath())) { mapFileList.add(file.getAbsolutePath()); @@ -72,69 +69,44 @@ public final class MapsforgeMapProvider extends AbstractMapProvider { Collections.sort(mapFileList, String.CASE_INSENSITIVE_ORDER); } return mapFileList; - } catch (Exception e) { + } catch (final Exception e) { Log.e("MapsforgeMapProvider.getOfflineMaps: ", e); } } return Collections.emptyList(); } - public static boolean isValidMapFile(String mapFileIn) { + public static boolean isValidMapFile(final String mapFileIn) { if (StringUtils.isEmpty(mapFileIn)) { return false; } - MapDatabase mapDB = new MapDatabase(); - FileOpenResult result = mapDB.openFile(new File(mapFileIn)); + final MapDatabase mapDB = new MapDatabase(); + final FileOpenResult result = mapDB.openFile(new File(mapFileIn)); mapDB.closeFile(); - boolean isValid = result.isSuccess(); - - if (!isValid) { - isValid = isMapfile024(mapFileIn); - } - - return isValid; - } - - private static boolean isMapfile024(String mapFileIn) { - return mapFileIn != null && org.mapsforge.android.mapsold.MapDatabase.isValidMapFile(mapFileIn); + return result.isSuccess(); } @Override public boolean isSameActivity(final MapSource source1, final MapSource source2) { - return source1 == source2 || - !isMapfile024(Settings.getMapFile()) || - (!(source1 instanceof OfflineMapSource) && !(source2 instanceof OfflineMapSource)); + return source1 == source2 || (!(source1 instanceof OfflineMapSource) && !(source2 instanceof OfflineMapSource)); } @Override public Class getMapClass() { - final MapSource source = Settings.getMapSource(); - if (source instanceof OfflineMapSource && isMapfile024(Settings.getMapFile())) { - oldMap = true; - mapItemFactory = new MapsforgeMapItemFactory024(); - return MapsforgeMapActivity024.class; - } - oldMap = false; mapItemFactory = new MapsforgeMapItemFactory(); return MapsforgeMapActivity.class; } @Override public int getMapViewId() { - if (oldMap) { - return R.id.mfmap_old; - } return R.id.mfmap; } @Override public int getMapLayoutId() { - if (oldMap) { - return R.layout.map_mapsforge_old; - } return R.layout.map_mapsforge; } @@ -152,7 +124,7 @@ public final class MapsforgeMapProvider extends AbstractMapProvider { private final String fileName; - public OfflineMapSource(final String fileName, MapProvider mapProvider, final String name, final MapGeneratorInternal generator) { + public OfflineMapSource(final String fileName, final MapProvider mapProvider, final String name, final MapGeneratorInternal generator) { super(fileName, mapProvider, name, generator); this.fileName = fileName; } @@ -171,7 +143,7 @@ public final class MapsforgeMapProvider extends AbstractMapProvider { MapProviderFactory.deleteOfflineMapSources(); final Resources resources = CgeoApplication.getInstance().getResources(); final List offlineMaps = getOfflineMaps(); - for (String mapFile : offlineMaps) { + for (final String mapFile : offlineMaps) { final String mapName = StringUtils.capitalize(StringUtils.substringBeforeLast(new File(mapFile).getName(), ".")); registerMapSource(new OfflineMapSource(mapFile, this, mapName + " (" + resources.getString(R.string.map_source_osm_offline) + ")", MapGeneratorInternal.DATABASE_RENDERER)); } diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeCacheOverlay.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeCacheOverlay.java deleted file mode 100644 index a8111ed..0000000 --- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeCacheOverlay.java +++ /dev/null @@ -1,113 +0,0 @@ -package cgeo.geocaching.maps.mapsforge.v024; - -import cgeo.geocaching.maps.CachesOverlay; -import cgeo.geocaching.maps.interfaces.ItemizedOverlayImpl; -import cgeo.geocaching.maps.interfaces.MapProjectionImpl; -import cgeo.geocaching.maps.interfaces.MapViewImpl; - -import org.mapsforge.android.mapsold.ItemizedOverlay; -import org.mapsforge.android.mapsold.Projection; - -import android.content.Context; -import android.graphics.Canvas; -import android.graphics.Point; -import android.graphics.drawable.Drawable; - -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; - -public class MapsforgeCacheOverlay extends ItemizedOverlay implements ItemizedOverlayImpl { - - private CachesOverlay base; - private Lock lock = new ReentrantLock(); - - public MapsforgeCacheOverlay(Context contextIn, Drawable markerIn) { - super(boundCenterBottom(markerIn)); - base = new CachesOverlay(this, contextIn); - } - - @Override - public CachesOverlay getBase() { - return base; - } - - @Override - protected MapsforgeCacheOverlayItem createItem(int i) { - if (base == null) { - return null; - } - - return (MapsforgeCacheOverlayItem) base.createItem(i); - } - - @Override - public int size() { - if (base == null) { - return 0; - } - - return base.size(); - } - - @Override - protected boolean onTap(int arg0) { - if (base == null) { - return false; - } - - return base.onTap(arg0); - } - - @Override - protected void drawOverlayBitmap(Canvas canvas, Point drawPosition, - Projection projection, byte drawZoomLevel) { - base.drawOverlayBitmap(canvas, drawPosition, new MapsforgeMapProjection(projection), drawZoomLevel); - } - - @Override - public void superPopulate() { - populate(); - } - - @Override - public Drawable superBoundCenterBottom(Drawable marker) { - return ItemizedOverlay.boundCenterBottom(marker); - } - - @Override - public void superSetLastFocusedItemIndex(int i) { - // nothing to do - } - - @Override - public boolean superOnTap(int index) { - return super.onTap(index); - } - - @Override - public void superDraw(Canvas canvas, MapViewImpl mapView, boolean shadow) { - // nothing to do here... - } - - @Override - public void superDrawOverlayBitmap(Canvas canvas, Point drawPosition, - MapProjectionImpl projection, byte drawZoomLevel) { - super.drawOverlayBitmap(canvas, drawPosition, (Projection) projection.getImpl(), drawZoomLevel); - } - - @Override - public void lock() { - lock.lock(); - } - - @Override - public void unlock() { - lock.unlock(); - } - - @Override - public MapViewImpl getMapViewImpl() { - return (MapViewImpl) internalMapView; - } - -} diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeCacheOverlayItem.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeCacheOverlayItem.java deleted file mode 100644 index 4e4a358..0000000 --- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeCacheOverlayItem.java +++ /dev/null @@ -1,37 +0,0 @@ -package cgeo.geocaching.maps.mapsforge.v024; - -import cgeo.geocaching.IWaypoint; -import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl; - -import org.mapsforge.android.mapsold.GeoPoint; -import org.mapsforge.android.mapsold.OverlayItem; - -import android.graphics.drawable.Drawable; - -public class MapsforgeCacheOverlayItem extends OverlayItem implements CachesOverlayItemImpl { - final private IWaypoint coord; - final private boolean applyDistanceRule; - - public MapsforgeCacheOverlayItem(IWaypoint coordinate, boolean applyDistanceRule) { - super(new GeoPoint(coordinate.getCoords().getLatitudeE6(), coordinate.getCoords().getLongitudeE6()), coordinate.getName(), ""); - - this.coord = coordinate; - this.applyDistanceRule = applyDistanceRule; - } - - @Override - public IWaypoint getCoord() { - return coord; - } - - @Override - public Drawable getMarker(int index) { - return getMarker(); - } - - @Override - public boolean applyDistanceRule() { - return applyDistanceRule; - } - -} diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeGeoPoint.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeGeoPoint.java deleted file mode 100644 index 72aceb0..0000000 --- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeGeoPoint.java +++ /dev/null @@ -1,18 +0,0 @@ -package cgeo.geocaching.maps.mapsforge.v024; - -import cgeo.geocaching.location.Geopoint; -import cgeo.geocaching.maps.interfaces.GeoPointImpl; - -import org.mapsforge.android.mapsold.GeoPoint; - -public class MapsforgeGeoPoint extends GeoPoint implements GeoPointImpl { - - public MapsforgeGeoPoint(int latitudeE6, int longitudeE6) { - super(latitudeE6, longitudeE6); - } - - @Override - public Geopoint getCoords() { - return new Geopoint(getLatitudeE6() / 1e6, getLongitudeE6() / 1e6); - } -} diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapActivity024.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapActivity024.java deleted file mode 100644 index daeb2b8..0000000 --- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapActivity024.java +++ /dev/null @@ -1,124 +0,0 @@ -package cgeo.geocaching.maps.mapsforge.v024; - -import cgeo.geocaching.activity.ActivityMixin; -import cgeo.geocaching.activity.FilteredActivity; -import cgeo.geocaching.maps.AbstractMap; -import cgeo.geocaching.maps.CGeoMap; -import cgeo.geocaching.maps.interfaces.MapActivityImpl; - -import org.mapsforge.android.mapsold.MapActivity; - -import android.app.Activity; -import android.os.Bundle; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; - -public class MapsforgeMapActivity024 extends MapActivity implements MapActivityImpl, FilteredActivity { - - private AbstractMap mapBase; - - public MapsforgeMapActivity024() { - mapBase = new CGeoMap(this); - } - - @Override - public Activity getActivity() { - return this; - } - - @Override - protected void onCreate(Bundle icicle) { - mapBase.onCreate(icicle); - } - - @Override - protected void onSaveInstanceState(final Bundle outState) { - mapBase.onSaveInstanceState(outState); - } - - @Override - protected void onDestroy() { - mapBase.onDestroy(); - } - - @Override - protected void onPause() { - mapBase.onPause(); - } - - @Override - protected void onResume() { - mapBase.onResume(); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - return mapBase.onCreateOptionsMenu(menu); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - return mapBase.onOptionsItemSelected(item); - } - - @Override - public boolean onPrepareOptionsMenu(Menu menu) { - return mapBase.onPrepareOptionsMenu(menu); - } - - @Override - protected void onStop() { - mapBase.onStop(); - } - - @Override - public void superOnCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - } - - @Override - public boolean superOnCreateOptionsMenu(Menu menu) { - return super.onCreateOptionsMenu(menu); - } - - @Override - public void superOnDestroy() { - super.onDestroy(); - } - - @Override - public boolean superOnOptionsItemSelected(MenuItem item) { - return super.onOptionsItemSelected(item); - } - - @Override - public void superOnResume() { - super.onResume(); - } - - @Override - public void superOnStop() { - super.onStop(); - } - - @Override - public void superOnPause() { - super.onPause(); - } - - @Override - public boolean superOnPrepareOptionsMenu(Menu menu) { - return super.onPrepareOptionsMenu(menu); - } - - @Override - public void navigateUp(View view) { - ActivityMixin.navigateUp(this); - } - - @Override - public void showFilterMenu(View view) { - // do nothing, the filter bar only shows the global filter - } -} diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapController.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapController.java deleted file mode 100644 index db33d56..0000000 --- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapController.java +++ /dev/null @@ -1,55 +0,0 @@ -package cgeo.geocaching.maps.mapsforge.v024; - -import cgeo.geocaching.maps.interfaces.GeoPointImpl; -import cgeo.geocaching.maps.interfaces.MapControllerImpl; - -import org.mapsforge.android.mapsold.GeoPoint; -import org.mapsforge.android.mapsold.MapController; - -public class MapsforgeMapController implements MapControllerImpl { - - private MapController mapController; - private int maxZoomLevel; - - public MapsforgeMapController(MapController mapControllerIn, int maxZoomLevelIn) { - mapController = mapControllerIn; - maxZoomLevel = maxZoomLevelIn; - } - - @Override - public void animateTo(GeoPointImpl geoPoint) { - mapController.setCenter(castToGeoPointImpl(geoPoint)); - } - - private static GeoPoint castToGeoPointImpl(GeoPointImpl geoPoint) { - assert geoPoint instanceof GeoPoint; - return (GeoPoint) geoPoint; - } - - @Override - public void setCenter(GeoPointImpl geoPoint) { - mapController.setCenter(castToGeoPointImpl(geoPoint)); - } - - /** - * Set the map zoom level to mapzoom-1 or maxZoomLevel, whichever is least - * mapzoom-1 is used to be compatible with Google Maps zoom levels - */ - @Override - public void setZoom(int mapzoom) { - // Google Maps and OSM Maps use different zoom levels for the same view. - // All OSM Maps zoom levels are offset by 1 so they match Google Maps. - mapController.setZoom(Math.min(mapzoom - 1, maxZoomLevel)); - } - - @Override - public void zoomToSpan(int latSpanE6, int lonSpanE6) { - - if (latSpanE6 != 0 && lonSpanE6 != 0) { - // calculate zoomlevel - int distDegree = Math.max(latSpanE6, lonSpanE6); - int zoomLevel = (int) Math.floor(Math.log(360.0 * 1e6 / distDegree) / Math.log(2)); - mapController.setZoom(zoomLevel + 1); - } - } -} diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapItemFactory024.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapItemFactory024.java deleted file mode 100644 index 23d94d9..0000000 --- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapItemFactory024.java +++ /dev/null @@ -1,20 +0,0 @@ -package cgeo.geocaching.maps.mapsforge.v024; - -import cgeo.geocaching.IWaypoint; -import cgeo.geocaching.location.Geopoint; -import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl; -import cgeo.geocaching.maps.interfaces.GeoPointImpl; -import cgeo.geocaching.maps.interfaces.MapItemFactory; - -public class MapsforgeMapItemFactory024 implements MapItemFactory { - - @Override - public GeoPointImpl getGeoPointBase(final Geopoint coords) { - return new MapsforgeGeoPoint(coords.getLatitudeE6(), coords.getLongitudeE6()); - } - - @Override - public CachesOverlayItemImpl getCachesOverlayItem(final IWaypoint coordinate, boolean applyDistanceRule) { - return new MapsforgeCacheOverlayItem(coordinate, applyDistanceRule); - } -} diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapProjection.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapProjection.java deleted file mode 100644 index 9d36b7d..0000000 --- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapProjection.java +++ /dev/null @@ -1,29 +0,0 @@ -package cgeo.geocaching.maps.mapsforge.v024; - -import cgeo.geocaching.maps.interfaces.GeoPointImpl; -import cgeo.geocaching.maps.interfaces.MapProjectionImpl; - -import org.mapsforge.android.mapsold.GeoPoint; -import org.mapsforge.android.mapsold.Projection; - -import android.graphics.Point; - -public class MapsforgeMapProjection implements MapProjectionImpl { - - private Projection projection; - - public MapsforgeMapProjection(Projection projectionIn) { - projection = projectionIn; - } - - @Override - public void toPixels(GeoPointImpl leftGeo, Point left) { - projection.toPixels((GeoPoint) leftGeo, left); - } - - @Override - public Object getImpl() { - return projection; - } - -} diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java deleted file mode 100644 index af9b756..0000000 --- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java +++ /dev/null @@ -1,255 +0,0 @@ -package cgeo.geocaching.maps.mapsforge.v024; - -import cgeo.geocaching.R; -import cgeo.geocaching.location.Geopoint; -import cgeo.geocaching.location.Viewport; -import cgeo.geocaching.maps.CachesOverlay; -import cgeo.geocaching.maps.PositionAndScaleOverlay; -import cgeo.geocaching.maps.interfaces.GeneralOverlay; -import cgeo.geocaching.maps.interfaces.GeoPointImpl; -import cgeo.geocaching.maps.interfaces.MapControllerImpl; -import cgeo.geocaching.maps.interfaces.MapProjectionImpl; -import cgeo.geocaching.maps.interfaces.MapViewImpl; -import cgeo.geocaching.maps.interfaces.OnMapDragListener; -import cgeo.geocaching.settings.Settings; -import cgeo.geocaching.utils.Log; - -import org.eclipse.jdt.annotation.NonNull; -import org.mapsforge.android.mapsold.GeoPoint; -import org.mapsforge.android.mapsold.MapDatabase; -import org.mapsforge.android.mapsold.MapView; -import org.mapsforge.android.mapsold.MapViewMode; -import org.mapsforge.android.mapsold.Overlay; -import org.mapsforge.android.mapsold.Projection; - -import android.content.Context; -import android.graphics.Canvas; -import android.graphics.drawable.Drawable; -import android.util.AttributeSet; -import android.view.GestureDetector; -import android.view.GestureDetector.SimpleOnGestureListener; -import android.view.MotionEvent; -import android.widget.Toast; -public class MapsforgeMapView024 extends MapView implements MapViewImpl { - private GestureDetector gestureDetector; - private OnMapDragListener onDragListener; - private final MapsforgeMapController mapController = new MapsforgeMapController(getController(), getMaxZoomLevel()); - - public MapsforgeMapView024(final Context context, final AttributeSet attrs) { - super(context, attrs); - initialize(context); - } - - private void initialize(final Context context) { - if (isInEditMode()) { - return; - } - gestureDetector = new GestureDetector(context, new GestureListener()); - } - - @Override - public void draw(@NonNull final Canvas canvas) { - try { - // Google Maps and OSM Maps use different zoom levels for the same view. - // Here we don't want the Google Maps compatible zoom level, but the actual one. - if (getActualMapZoomLevel() > 22) { // to avoid too close zoom level (mostly on Samsung Galaxy S series) - getController().setZoom(22); - } - - super.draw(canvas); - } catch (final Exception e) { - Log.e("MapsforgeMapView024.draw", e); - } - } - - @Override - public void displayZoomControls(final boolean takeFocus) { - // nothing to do here - } - - @Override - public MapControllerImpl getMapController() { - return mapController; - } - - @Override - @NonNull - public GeoPointImpl getMapViewCenter() { - final GeoPoint point = getMapCenter(); - return new MapsforgeGeoPoint(point.getLatitudeE6(), point.getLongitudeE6()); - } - - @Override - public Viewport getViewport() { - return new Viewport(getMapViewCenter(), getLatitudeSpan() / 1e6, getLongitudeSpan() / 1e6); - } - - @Override - public void clearOverlays() { - getOverlays().clear(); - } - - @Override - public MapProjectionImpl getMapProjection() { - return new MapsforgeMapProjection(getProjection()); - } - - @Override - public CachesOverlay createAddMapOverlay(final Context context, final Drawable drawable) { - - final MapsforgeCacheOverlay ovl = new MapsforgeCacheOverlay(context, drawable); - getOverlays().add(ovl); - return ovl.getBase(); - } - - @Override - public PositionAndScaleOverlay createAddPositionAndScaleOverlay(final Geopoint coords, final String geocode) { - final MapsforgeOverlay ovl = new MapsforgeOverlay(this, coords, geocode); - getOverlays().add(ovl); - return (PositionAndScaleOverlay) ovl.getBase(); - } - - @Override - public int getLatitudeSpan() { - - int span = 0; - - final Projection projection = getProjection(); - - if (projection != null && getHeight() > 0) { - - final GeoPoint low = projection.fromPixels(0, 0); - final GeoPoint high = projection.fromPixels(0, getHeight()); - - if (low != null && high != null) { - span = Math.abs(high.getLatitudeE6() - low.getLatitudeE6()); - } - } - - return span; - } - - @Override - public int getLongitudeSpan() { - - int span = 0; - - final Projection projection = getProjection(); - - if (projection != null && getWidth() > 0) { - final GeoPoint low = projection.fromPixels(0, 0); - final GeoPoint high = projection.fromPixels(getWidth(), 0); - - if (low != null && high != null) { - span = Math.abs(high.getLongitudeE6() - low.getLongitudeE6()); - } - } - - return span; - } - - @Override - public void preLoad() { - // Nothing to do here - } - - /** - * Get the map zoom level which is compatible with Google Maps. - * - * @return the current map zoom level +1 - */ - @Override - public int getMapZoomLevel() { - // Google Maps and OSM Maps use different zoom levels for the same view. - // All OSM Maps zoom levels are offset by 1 so they match Google Maps. - return getZoomLevel() + 1; - } - - /** - * Get the actual map zoom level - * - * @return the current map zoom level with no adjustments - */ - private int getActualMapZoomLevel() { - return getZoomLevel(); - } - - @Override - public void setMapSource() { - setMapViewMode(MapViewMode.CANVAS_RENDERER); - setMapFile(Settings.getMapFile()); - if (!MapDatabase.isValidMapFile(Settings.getMapFile())) { - Log.e("MapsforgeMapView024: Invalid map file"); - } - Toast.makeText( - getContext(), - getContext().getResources().getString(R.string.warn_deprecated_mapfile), - Toast.LENGTH_LONG) - .show(); - } - - @Override - public void repaintRequired(final GeneralOverlay overlay) { - - if (null == overlay) { - invalidate(); - } else { - try { - final Overlay ovl = (Overlay) overlay.getOverlayImpl(); - - if (ovl != null) { - ovl.requestRedraw(); - } - - } catch (final Exception e) { - Log.e("MapsforgeMapView024.repaintRequired", e); - } - } - } - - @Override - public void setOnDragListener(final OnMapDragListener onDragListener) { - this.onDragListener = onDragListener; - } - - @Override - public boolean onTouchEvent(final MotionEvent ev) { - gestureDetector.onTouchEvent(ev); - return super.onTouchEvent(ev); - } - - private class GestureListener extends SimpleOnGestureListener { - @Override - public boolean onDoubleTap(final MotionEvent e) { - if (onDragListener != null) { - onDragListener.onDrag(); - } - return true; - } - - @Override - public boolean onScroll(final MotionEvent e1, final MotionEvent e2, - final float distanceX, final float distanceY) { - if (onDragListener != null) { - onDragListener.onDrag(); - } - return super.onScroll(e1, e2, distanceX, distanceY); - } - } - - @Override - public boolean needsInvertedColors() { - return false; - } - - @Override - public boolean hasMapThemes() { - // not supported - return false; - } - - @Override - public void setMapTheme() { - // not supported - } -} diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOverlay.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOverlay.java deleted file mode 100644 index fda6dc1..0000000 --- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOverlay.java +++ /dev/null @@ -1,55 +0,0 @@ -package cgeo.geocaching.maps.mapsforge.v024; - -import cgeo.geocaching.location.Geopoint; -import cgeo.geocaching.maps.PositionAndScaleOverlay; -import cgeo.geocaching.maps.interfaces.GeneralOverlay; -import cgeo.geocaching.maps.interfaces.MapViewImpl; -import cgeo.geocaching.maps.interfaces.OverlayImpl; - -import org.mapsforge.android.mapsold.Overlay; -import org.mapsforge.android.mapsold.Projection; - -import android.graphics.Canvas; -import android.graphics.Point; - -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; - -public class MapsforgeOverlay extends Overlay implements OverlayImpl { - - private PositionAndScaleOverlay overlayBase = null; - private final Lock lock = new ReentrantLock(); - - public MapsforgeOverlay(final MapViewImpl mapView, final Geopoint coords, final String geocode) { - overlayBase = new PositionAndScaleOverlay(this, mapView, coords, geocode); - } - - @Override - protected void drawOverlayBitmap(final Canvas canvas, final Point drawPosition, - final Projection projection, final byte drawZoomLevel) { - - if (overlayBase != null) { - overlayBase.drawOverlayBitmap(canvas, drawPosition, new MapsforgeMapProjection(projection), drawZoomLevel); - } - } - - public GeneralOverlay getBase() { - return overlayBase; - } - - @Override - public void lock() { - lock.lock(); - } - - @Override - public void unlock() { - lock.unlock(); - } - - @Override - public MapViewImpl getMapViewImpl() { - return (MapViewImpl) internalMapView; - } - -} -- cgit v1.1 From 1b42d3c5ebf38a7710cfe4040a90d98b54575cca Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Sun, 8 Mar 2015 10:37:16 +0100 Subject: fix #4717, fix #4723: more descriptive map title --- main/src/cgeo/geocaching/maps/CGeoMap.java | 132 ++++++++++++++++++++--------- 1 file changed, 91 insertions(+), 41 deletions(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 7cd13a7..6b1c23c 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -40,6 +40,7 @@ import cgeo.geocaching.settings.Settings; import cgeo.geocaching.ui.dialog.LiveMapInfoDialogBuilder; import cgeo.geocaching.utils.AngleUtils; import cgeo.geocaching.utils.CancellableHandler; +import cgeo.geocaching.utils.Formatter; import cgeo.geocaching.utils.LeastRecentlyUsedSet; import cgeo.geocaching.utils.Log; import cgeo.geocaching.utils.MapUtils; @@ -47,6 +48,7 @@ import cgeo.geocaching.utils.MapUtils; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; import rx.Subscription; import rx.functions.Action0; @@ -218,34 +220,8 @@ public class CGeoMap extends AbstractMap implements ViewFactory { switch (what) { case UPDATE_TITLE: - // set title - if (map.mapMode == MapMode.LIVE && map.isLiveEnabled) { - map.setTitle(map.res.getString(R.string.map_live)); - } else { - map.setTitle(map.mapTitle); - } - - // count caches in the sub title - map.countVisibleCaches(); - final StringBuilder subtitle = new StringBuilder(); - if (!map.caches.isEmpty()) { - final int totalCount = map.caches.size(); - - if (map.cachesCnt != totalCount && Settings.isDebug()) { - subtitle.append(map.cachesCnt).append('/').append(map.res.getQuantityString(R.plurals.cache_counts, totalCount, totalCount)); - } - else { - subtitle.append(map.res.getQuantityString(R.plurals.cache_counts, map.cachesCnt, map.cachesCnt)); - } - } - - if (Settings.isDebug() && map.lastSearchResult != null && StringUtils.isNotBlank(map.lastSearchResult.getUrl())) { - subtitle.append(" [").append(map.lastSearchResult.getUrl()).append(']'); - } - - if (subtitle.length() > 0) { - map.setSubtitle(subtitle.toString()); - } + map.setTitle(); + map.setSubtitle(); break; case INVALIDATE_MAP: @@ -261,7 +237,8 @@ public class CGeoMap extends AbstractMap implements ViewFactory { final private Handler displayHandler = new DisplayHandler(this); - private void setTitle(final String title) { + private void setTitle() { + final String title = calculateTitle(); /* Compatibility for the old Action Bar, only used by the maps activity at the moment */ final TextView titleview = ButterKnife.findById(activity, R.id.actionbar_title); if (titleview != null) { @@ -273,7 +250,35 @@ public class CGeoMap extends AbstractMap implements ViewFactory { } } - private void setSubtitle(final String subtitle) { + private String calculateTitle() { + if (isLiveEnabled) { + return res.getString(R.string.map_live); + } + if (mapMode == MapMode.SINGLE) { + final Geocache cache = getSingleModeCache(); + if (cache != null) { + return cache.getName(); + } + } + return StringUtils.defaultIfEmpty(mapTitle, res.getString(R.string.map_map)); + } + + @Nullable + private Geocache getSingleModeCache() { + for (final Geocache geocache : caches) { + if (geocache.getGeocode().equals(geocodeIntent)) { + return geocache; + } + } + return null; + } + + private void setSubtitle() { + final String subtitle = calculateSubtitle(); + if (StringUtils.isEmpty(subtitle)) { + return; + } + /* Compatibility for the old Action Bar, only used by the maps activity at the moment */ final TextView titleView = ButterKnife.findById(activity, R.id.actionbar_title); if (titleView != null) { @@ -284,6 +289,34 @@ public class CGeoMap extends AbstractMap implements ViewFactory { } } + private String calculateSubtitle() { + // count caches in the sub title + countVisibleCaches(); + final StringBuilder subtitle = new StringBuilder(); + if (!isLiveEnabled && mapMode == MapMode.SINGLE) { + final Geocache cache = getSingleModeCache(); + if (cache != null) { + return Formatter.formatMapSubtitle(cache); + } + } + if (!caches.isEmpty()) { + final int totalCount = caches.size(); + + if (cachesCnt != totalCount && Settings.isDebug()) { + subtitle.append(cachesCnt).append('/').append(res.getQuantityString(R.plurals.cache_counts, totalCount, totalCount)); + } + else { + subtitle.append(res.getQuantityString(R.plurals.cache_counts, cachesCnt, cachesCnt)); + } + } + + if (Settings.isDebug() && lastSearchResult != null && StringUtils.isNotBlank(lastSearchResult.getUrl())) { + subtitle.append(" [").append(lastSearchResult.getUrl()).append(']'); + } + + return subtitle.toString(); + } + @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) private void setTitleIceCreamSandwich(final String title) { activity.getActionBar().setTitle(title); @@ -459,7 +492,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { activity.getActionBar().setDisplayHomeAsUpEnabled(true); } activity.setContentView(mapProvider.getMapLayoutId()); - setTitle(res.getString(R.string.map_map)); + setTitle(); // initialize map mapView = (MapViewImpl) activity.findViewById(mapProvider.getMapViewId()); @@ -737,6 +770,10 @@ public class CGeoMap extends AbstractMap implements ViewFactory { lastSearchResult = null; searchIntent = null; ActivityMixin.invalidateOptionsMenu(activity); + if (mapMode != MapMode.SINGLE) { + mapTitle = StringUtils.EMPTY; + } + updateMapTitle(); return true; case R.id.menu_store_caches: if (!isLoading()) { @@ -813,14 +850,10 @@ public class CGeoMap extends AbstractMap implements ViewFactory { return true; } case R.id.menu_hint: - if (caches.size() == 1) { - caches.iterator().next().showHintToast(getActivity()); - } + menuShowHint(); return true; case R.id.menu_compass: - if (caches.size() == 1) { - CompassActivity.startActivityCache(this.getActivity(), caches.iterator().next()); - } + menuCompass(); return true; default: final MapSource mapSource = MapProviderFactory.getMapSource(id); @@ -833,6 +866,20 @@ public class CGeoMap extends AbstractMap implements ViewFactory { return false; } + private void menuCompass() { + final Geocache cache = getSingleModeCache(); + if (cache != null) { + CompassActivity.startActivityCache(this.getActivity(), cache); + } + } + + private void menuShowHint() { + final Geocache cache = getSingleModeCache(); + if (cache != null) { + cache.showHintToast(getActivity()); + } + } + private void selectMapTheme() { final File[] themeFiles = Settings.getMapThemeFiles(); @@ -1132,7 +1179,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { // update title on any change if (moved || !viewportNow.equals(previousViewport)) { - map.displayHandler.sendEmptyMessage(UPDATE_TITLE); + map.updateMapTitle(); } previousZoom = zoomNow; @@ -1358,7 +1405,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { } displayHandler.sendEmptyMessage(INVALIDATE_MAP); - displayHandler.sendEmptyMessage(UPDATE_TITLE); + updateMapTitle(); } finally { showProgressHandler.sendEmptyMessage(HIDE_PROGRESS); } @@ -1371,11 +1418,15 @@ public class CGeoMap extends AbstractMap implements ViewFactory { final CachesOverlayItemImpl item = getWaypointItem(waypoint); overlayCaches.updateItems(item); displayHandler.sendEmptyMessage(INVALIDATE_MAP); - displayHandler.sendEmptyMessage(UPDATE_TITLE); + updateMapTitle(); cachesCnt = 1; } + private void updateMapTitle() { + displayHandler.sendEmptyMessage(UPDATE_TITLE); + } + private static abstract class DoRunnable implements Runnable { private final WeakReference mapRef; @@ -1688,7 +1739,6 @@ public class CGeoMap extends AbstractMap implements ViewFactory { mapIntent.putExtra(Intents.EXTRA_MAP_MODE, MapMode.SINGLE); mapIntent.putExtra(Intents.EXTRA_LIVE_ENABLED, false); mapIntent.putExtra(Intents.EXTRA_GEOCODE, geocode); - mapIntent.putExtra(Intents.EXTRA_TITLE, geocode); fromActivity.startActivity(mapIntent); } -- cgit v1.1 From b6140ee20f1a74c580208c3f513954a13b7aa572 Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Sun, 8 Mar 2015 15:30:29 +0100 Subject: fix CME in accessing single cache on map --- main/src/cgeo/geocaching/maps/CGeoMap.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 6b1c23c..c808ffd 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -265,7 +265,8 @@ public class CGeoMap extends AbstractMap implements ViewFactory { @Nullable private Geocache getSingleModeCache() { - for (final Geocache geocache : caches) { + // use a copy of the caches list to avoid concurrent modification + for (final Geocache geocache : new ArrayList<>(caches)) { if (geocache.getGeocode().equals(geocodeIntent)) { return geocache; } -- cgit v1.1 From e685f1a95cee461b38b4fe3a9d2ed261b552dbce Mon Sep 17 00:00:00 2001 From: rsudev Date: Mon, 9 Mar 2015 12:07:49 +0100 Subject: Fixes #4722, Reproducible ANR with OSM:Offline map - the recent removal of mf 0.24 revealed a long-standing bug in detecting maps-source equality --- main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProvider.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProvider.java index 8027808..76d645c 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProvider.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProvider.java @@ -91,7 +91,7 @@ public final class MapsforgeMapProvider extends AbstractMapProvider { @Override public boolean isSameActivity(final MapSource source1, final MapSource source2) { - return source1 == source2 || (!(source1 instanceof OfflineMapSource) && !(source2 instanceof OfflineMapSource)); + return source1.getNumericalId() == source2.getNumericalId() || (!(source1 instanceof OfflineMapSource) && !(source2 instanceof OfflineMapSource)); } @Override -- cgit v1.1 From b2ffc2581c6630e313c4e623d0a40c8846e1e975 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Tue, 17 Mar 2015 08:37:59 +0100 Subject: Add missing final qualifiers in main module --- .../geocaching/maps/AbstractItemizedOverlay.java | 16 ++++---- .../cgeo/geocaching/maps/AbstractMapProvider.java | 2 +- main/src/cgeo/geocaching/maps/CGeoMap.java | 16 ++++---- main/src/cgeo/geocaching/maps/CachesOverlay.java | 38 ++++++++--------- main/src/cgeo/geocaching/maps/PositionDrawer.java | 48 +++++++++++----------- main/src/cgeo/geocaching/maps/PositionHistory.java | 6 +-- main/src/cgeo/geocaching/maps/ScaleDrawer.java | 6 +-- .../maps/google/v1/GoogleCacheOverlay.java | 26 ++++++------ .../maps/google/v1/GoogleCacheOverlayItem.java | 2 +- .../geocaching/maps/google/v1/GoogleGeoPoint.java | 2 +- .../maps/google/v1/GoogleMapActivity.java | 22 +++++----- .../maps/google/v1/GoogleMapController.java | 14 +++---- .../maps/google/v1/GoogleMapItemFactory.java | 2 +- .../maps/google/v1/GoogleMapProjection.java | 6 +-- .../maps/google/v1/GoogleMapProvider.java | 2 +- .../maps/mapsforge/MapsforgeCacheOverlay.java | 26 ++++++------ .../maps/mapsforge/MapsforgeCacheOverlayItem.java | 4 +- .../maps/mapsforge/MapsforgeGeoPoint.java | 2 +- .../maps/mapsforge/MapsforgeMapActivity.java | 22 +++++----- .../maps/mapsforge/MapsforgeMapController.java | 20 ++++----- .../maps/mapsforge/MapsforgeMapItemFactory.java | 2 +- .../maps/mapsforge/MapsforgeMapProjection.java | 6 +-- .../maps/mapsforge/MapsforgeMapSource.java | 2 +- 23 files changed, 146 insertions(+), 146 deletions(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/AbstractItemizedOverlay.java b/main/src/cgeo/geocaching/maps/AbstractItemizedOverlay.java index 747618b..9436b2a 100644 --- a/main/src/cgeo/geocaching/maps/AbstractItemizedOverlay.java +++ b/main/src/cgeo/geocaching/maps/AbstractItemizedOverlay.java @@ -17,9 +17,9 @@ import android.graphics.drawable.Drawable; */ public abstract class AbstractItemizedOverlay implements GeneralOverlay { - private ItemizedOverlayImpl ovlImpl; + private final ItemizedOverlayImpl ovlImpl; - protected AbstractItemizedOverlay(ItemizedOverlayImpl ovlImplIn) { + protected AbstractItemizedOverlay(final ItemizedOverlayImpl ovlImplIn) { ovlImpl = ovlImplIn; } @@ -27,26 +27,26 @@ public abstract class AbstractItemizedOverlay implements GeneralOverlay { ovlImpl.superPopulate(); } - public boolean onTap(int index) { + public boolean onTap(final int index) { return ovlImpl.superOnTap(index); } - Drawable boundCenterBottom(Drawable markerIn) { + Drawable boundCenterBottom(final Drawable markerIn) { return ovlImpl.superBoundCenterBottom(markerIn); } - void setLastFocusedItemIndex(int index) { + void setLastFocusedItemIndex(final int index) { ovlImpl.superSetLastFocusedItemIndex(index); } @Override - public void draw(Canvas canvas, MapViewImpl mapView, boolean shadow) { + public void draw(final Canvas canvas, final MapViewImpl mapView, final boolean shadow) { ovlImpl.superDraw(canvas, mapView, shadow); } @Override - public void drawOverlayBitmap(Canvas canvas, Point drawPosition, - MapProjectionImpl projection, byte drawZoomLevel) { + public void drawOverlayBitmap(final Canvas canvas, final Point drawPosition, + final MapProjectionImpl projection, final byte drawZoomLevel) { ovlImpl.superDrawOverlayBitmap(canvas, drawPosition, projection, drawZoomLevel); } diff --git a/main/src/cgeo/geocaching/maps/AbstractMapProvider.java b/main/src/cgeo/geocaching/maps/AbstractMapProvider.java index 620b953..bd42223 100644 --- a/main/src/cgeo/geocaching/maps/AbstractMapProvider.java +++ b/main/src/cgeo/geocaching/maps/AbstractMapProvider.java @@ -6,7 +6,7 @@ import cgeo.geocaching.maps.interfaces.MapSource; public abstract class AbstractMapProvider implements MapProvider { @Override - public void registerMapSource(MapSource mapSource) { + public void registerMapSource(final MapSource mapSource) { MapProviderFactory.registerMapSource(mapSource); } } diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index c808ffd..42e41b1 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -194,12 +194,12 @@ public class CGeoMap extends AbstractMap implements ViewFactory { */ private static final int MIN_LIVEMAP_ZOOM = 12; // Thread pooling - private static BlockingQueue displayQueue = new ArrayBlockingQueue<>(1); - private static ThreadPoolExecutor displayExecutor = new ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS, displayQueue, new ThreadPoolExecutor.DiscardOldestPolicy()); - private static BlockingQueue downloadQueue = new ArrayBlockingQueue<>(1); - private static ThreadPoolExecutor downloadExecutor = new ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS, downloadQueue, new ThreadPoolExecutor.DiscardOldestPolicy()); - private static BlockingQueue loadQueue = new ArrayBlockingQueue<>(1); - private static ThreadPoolExecutor loadExecutor = new ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS, loadQueue, new ThreadPoolExecutor.DiscardOldestPolicy()); + private static final BlockingQueue displayQueue = new ArrayBlockingQueue<>(1); + private static final ThreadPoolExecutor displayExecutor = new ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS, displayQueue, new ThreadPoolExecutor.DiscardOldestPolicy()); + private static final BlockingQueue downloadQueue = new ArrayBlockingQueue<>(1); + private static final ThreadPoolExecutor downloadExecutor = new ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS, downloadQueue, new ThreadPoolExecutor.DiscardOldestPolicy()); + private static final BlockingQueue loadQueue = new ArrayBlockingQueue<>(1); + private static final ThreadPoolExecutor loadExecutor = new ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS, loadQueue, new ThreadPoolExecutor.DiscardOldestPolicy()); // handlers /** Updates the titles */ @@ -382,7 +382,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { if (msg.what == UPDATE_PROGRESS) { if (waitDialog != null) { final int secondsElapsed = (int) ((System.currentTimeMillis() - detailProgressTime) / 1000); - int secondsRemaining; + final int secondsRemaining; if (detailProgress > 0) { secondsRemaining = (detailTotal - detailProgress) * secondsElapsed / detailProgress; } else { @@ -1234,7 +1234,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { showProgressHandler.sendEmptyMessage(SHOW_PROGRESS); loadThreadRun = System.currentTimeMillis(); - SearchResult searchResult; + final SearchResult searchResult; if (mapMode == MapMode.LIVE) { searchResult = isLiveEnabled ? new SearchResult() : new SearchResult(DataStore.loadStoredInViewport(mapView.getViewport(), Settings.getCacheType())); } else { diff --git a/main/src/cgeo/geocaching/maps/CachesOverlay.java b/main/src/cgeo/geocaching/maps/CachesOverlay.java index 048217e..9649c0d 100644 --- a/main/src/cgeo/geocaching/maps/CachesOverlay.java +++ b/main/src/cgeo/geocaching/maps/CachesOverlay.java @@ -43,13 +43,13 @@ public class CachesOverlay extends AbstractItemizedOverlay { private List items = new ArrayList<>(); private Context context = null; private boolean displayCircles = false; - private Progress progress = new Progress(); + private final Progress progress = new Progress(); private Paint blockedCircle = null; private PaintFlagsDrawFilter setFilter = null; private PaintFlagsDrawFilter removeFilter = null; private MapItemFactory mapItemFactory = null; - public CachesOverlay(ItemizedOverlayImpl ovlImpl, Context contextIn) { + public CachesOverlay(final ItemizedOverlayImpl ovlImpl, final Context contextIn) { super(ovlImpl); populate(); @@ -60,19 +60,19 @@ public class CachesOverlay extends AbstractItemizedOverlay { mapItemFactory = mapProvider.getMapItemFactory(); } - void updateItems(CachesOverlayItemImpl item) { - List itemsPre = new ArrayList<>(); + void updateItems(final CachesOverlayItemImpl item) { + final List itemsPre = new ArrayList<>(); itemsPre.add(item); updateItems(itemsPre); } - void updateItems(List itemsPre) { + void updateItems(final List itemsPre) { if (itemsPre == null) { return; } - for (CachesOverlayItemImpl item : itemsPre) { + for (final CachesOverlayItemImpl item : itemsPre) { item.setMarker(boundCenterBottom(item.getMarker(0))); } @@ -97,7 +97,7 @@ public class CachesOverlay extends AbstractItemizedOverlay { } @Override - public void draw(Canvas canvas, MapViewImpl mapView, boolean shadow) { + public void draw(final Canvas canvas, final MapViewImpl mapView, final boolean shadow) { drawInternal(canvas, mapView.getMapProjection()); @@ -105,15 +105,15 @@ public class CachesOverlay extends AbstractItemizedOverlay { } @Override - public void drawOverlayBitmap(Canvas canvas, Point drawPosition, - MapProjectionImpl projection, byte drawZoomLevel) { + public void drawOverlayBitmap(final Canvas canvas, final Point drawPosition, + final MapProjectionImpl projection, final byte drawZoomLevel) { drawInternal(canvas, projection); super.drawOverlayBitmap(canvas, drawPosition, projection, drawZoomLevel); } - private void drawInternal(Canvas canvas, MapProjectionImpl projection) { + private void drawInternal(final Canvas canvas, final MapProjectionImpl projection) { if (!displayCircles || items.isEmpty()) { return; } @@ -129,7 +129,7 @@ public class CachesOverlay extends AbstractItemizedOverlay { final int radius = calculateDrawingRadius(projection); final Point center = new Point(); - for (CachesOverlayItemImpl item : items) { + for (final CachesOverlayItemImpl item : items) { if (item.applyDistanceRule()) { final Geopoint itemCoord = item.getCoord().getCoords(); final GeoPointImpl itemGeo = mapItemFactory.getGeoPointBase(itemCoord); @@ -159,8 +159,8 @@ public class CachesOverlay extends AbstractItemizedOverlay { * levels which are used to see the circles. * */ - private int calculateDrawingRadius(MapProjectionImpl projection) { - float[] distanceArray = new float[1]; + private int calculateDrawingRadius(final MapProjectionImpl projection) { + final float[] distanceArray = new float[1]; final Geopoint itemCoord = items.get(0).getCoord().getCoords(); Location.distanceBetween(itemCoord.getLatitude(), itemCoord.getLongitude(), @@ -200,7 +200,7 @@ public class CachesOverlay extends AbstractItemizedOverlay { } @Override - public boolean onTap(int index) { + public boolean onTap(final int index) { try { if (items.size() <= index) { @@ -230,7 +230,7 @@ public class CachesOverlay extends AbstractItemizedOverlay { if (StringUtils.equalsIgnoreCase(coordType, "cache") && StringUtils.isNotBlank(coordinate.getGeocode())) { final Geocache cache = DataStore.loadCache(coordinate.getGeocode(), LoadFlags.LOAD_CACHE_OR_DB); if (cache != null) { - RequestDetailsThread requestDetailsThread = new RequestDetailsThread(cache); + final RequestDetailsThread requestDetailsThread = new RequestDetailsThread(cache); if (!requestDetailsThread.requestRequired()) { // don't show popup if we have enough details progress.dismiss(); @@ -251,7 +251,7 @@ public class CachesOverlay extends AbstractItemizedOverlay { } progress.dismiss(); - } catch (NotFoundException e) { + } catch (final NotFoundException e) { Log.e("CachesOverlay.onTap", e); progress.dismiss(); } @@ -260,10 +260,10 @@ public class CachesOverlay extends AbstractItemizedOverlay { } @Override - public CachesOverlayItemImpl createItem(int index) { + public CachesOverlayItemImpl createItem(final int index) { try { return items.get(index); - } catch (Exception e) { + } catch (final Exception e) { Log.e("CachesOverlay.createItem", e); } @@ -274,7 +274,7 @@ public class CachesOverlay extends AbstractItemizedOverlay { public int size() { try { return items.size(); - } catch (Exception e) { + } catch (final Exception e) { Log.e("CachesOverlay.size", e); } diff --git a/main/src/cgeo/geocaching/maps/PositionDrawer.java b/main/src/cgeo/geocaching/maps/PositionDrawer.java index 6a45e62..c7d1734 100644 --- a/main/src/cgeo/geocaching/maps/PositionDrawer.java +++ b/main/src/cgeo/geocaching/maps/PositionDrawer.java @@ -28,21 +28,21 @@ public class PositionDrawer { private Paint accuracyCircle = null; private Paint historyLine = null; private Paint historyLineShadow = null; - private Point center = new Point(); - private Point left = new Point(); + private final Point center = new Point(); + private final Point left = new Point(); private Bitmap arrow = null; private int widthArrowHalf = 0; private int heightArrowHalf = 0; private PaintFlagsDrawFilter setfil = null; private PaintFlagsDrawFilter remfil = null; - private PositionHistory positionHistory = new PositionHistory(); - private MapItemFactory mapItemFactory; + private final PositionHistory positionHistory = new PositionHistory(); + private final MapItemFactory mapItemFactory; public PositionDrawer() { this.mapItemFactory = Settings.getMapProvider().getMapItemFactory(); } - void drawPosition(Canvas canvas, MapProjectionImpl projection) { + void drawPosition(final Canvas canvas, final MapProjectionImpl projection) { if (coordinates == null || location == null) { return; } @@ -76,20 +76,20 @@ public class PositionDrawer { canvas.setDrawFilter(setfil); - double latitude = coordinates.getLatitude(); - double longitude = coordinates.getLongitude(); - float accuracy = coordinates.getAccuracy(); + final double latitude = coordinates.getLatitude(); + final double longitude = coordinates.getLongitude(); + final float accuracy = coordinates.getAccuracy(); - float[] result = new float[1]; + final float[] result = new float[1]; Location.distanceBetween(latitude, longitude, latitude, longitude + 1, result); - float longitudeLineDistance = result[0]; + final float longitudeLineDistance = result[0]; final Geopoint leftCoords = new Geopoint(latitude, longitude - accuracy / longitudeLineDistance); - GeoPointImpl leftGeo = mapItemFactory.getGeoPointBase(leftCoords); + final GeoPointImpl leftGeo = mapItemFactory.getGeoPointBase(leftCoords); projection.toPixels(leftGeo, left); projection.toPixels(location, center); - int radius = center.x - left.x; + final int radius = center.x - left.x; accuracyCircle.setColor(0x66000000); accuracyCircle.setStyle(Style.STROKE); @@ -106,23 +106,23 @@ public class PositionDrawer { final ArrayList paintHistory = new ArrayList<>(positionHistory.getHistory()); paintHistory.add(coordinates); - int size = paintHistory.size(); + final int size = paintHistory.size(); if (size > 1) { int alphaCnt = size - 201; if (alphaCnt < 1) { alphaCnt = 1; } - Point pointNow = new Point(); - Point pointPrevious = new Point(); - Location prev = paintHistory.get(0); + final Point pointNow = new Point(); + final Point pointPrevious = new Point(); + final Location prev = paintHistory.get(0); projection.toPixels(mapItemFactory.getGeoPointBase(new Geopoint(prev)), pointPrevious); for (int cnt = 1; cnt < size; cnt++) { - Location now = paintHistory.get(cnt); + final Location now = paintHistory.get(cnt); projection.toPixels(mapItemFactory.getGeoPointBase(new Geopoint(now)), pointNow); - int alpha; + final int alpha; if ((alphaCnt - cnt) > 0) { alpha = 255 / (alphaCnt - cnt); } @@ -147,10 +147,10 @@ public class PositionDrawer { heightArrowHalf = arrow.getHeight() / 2; } - int marginLeft = center.x - widthArrowHalf; - int marginTop = center.y - heightArrowHalf; + final int marginLeft = center.x - widthArrowHalf; + final int marginTop = center.y - heightArrowHalf; - Matrix matrix = new Matrix(); + final Matrix matrix = new Matrix(); matrix.setRotate(heading, widthArrowHalf, heightArrowHalf); matrix.postTranslate(marginLeft, marginTop); @@ -163,11 +163,11 @@ public class PositionDrawer { return positionHistory.getHistory(); } - public void setHistory(ArrayList history) { + public void setHistory(final ArrayList history) { positionHistory.setHistory(history); } - public void setHeading(float bearingNow) { + public void setHeading(final float bearingNow) { heading = bearingNow; } @@ -175,7 +175,7 @@ public class PositionDrawer { return heading; } - public void setCoordinates(Location coordinatesIn) { + public void setCoordinates(final Location coordinatesIn) { coordinates = coordinatesIn; location = mapItemFactory.getGeoPointBase(new Geopoint(coordinates)); } diff --git a/main/src/cgeo/geocaching/maps/PositionHistory.java b/main/src/cgeo/geocaching/maps/PositionHistory.java index af13740..4394eba 100644 --- a/main/src/cgeo/geocaching/maps/PositionHistory.java +++ b/main/src/cgeo/geocaching/maps/PositionHistory.java @@ -24,7 +24,7 @@ public class PositionHistory { /** * Adds the current position to the trail history to be able to show the trail on the map. */ - void rememberTrailPosition(Location coordinates) { + void rememberTrailPosition(final Location coordinates) { if (coordinates.getAccuracy() >= 50f) { return; } @@ -36,7 +36,7 @@ public class PositionHistory { return; } - Location historyRecent = history.get(history.size() - 1); + final Location historyRecent = history.get(history.size() - 1); if (historyRecent.distanceTo(coordinates) <= MINIMUM_DISTANCE_METERS) { return; } @@ -56,7 +56,7 @@ public class PositionHistory { return history; } - public void setHistory(ArrayList history) { + public void setHistory(final ArrayList history) { this.history = history; } diff --git a/main/src/cgeo/geocaching/maps/ScaleDrawer.java b/main/src/cgeo/geocaching/maps/ScaleDrawer.java index 04398b4..e905873 100644 --- a/main/src/cgeo/geocaching/maps/ScaleDrawer.java +++ b/main/src/cgeo/geocaching/maps/ScaleDrawer.java @@ -25,8 +25,8 @@ public class ScaleDrawer { private float pixelDensity = 0; public ScaleDrawer() { - DisplayMetrics metrics = new DisplayMetrics(); - WindowManager windowManager = (WindowManager) CgeoApplication.getInstance().getSystemService(Context.WINDOW_SERVICE); + final DisplayMetrics metrics = new DisplayMetrics(); + final WindowManager windowManager = (WindowManager) CgeoApplication.getInstance().getSystemService(Context.WINDOW_SERVICE); windowManager.getDefaultDisplay().getMetrics(metrics); pixelDensity = metrics.density; } @@ -36,7 +36,7 @@ public class ScaleDrawer { return scale * Math.floor(distance / scale); } - void drawScale(Canvas canvas, MapViewImpl mapView) { + void drawScale(final Canvas canvas, final MapViewImpl mapView) { final double span = mapView.getLongitudeSpan() / 1e6; final GeoPointImpl center = mapView.getMapViewCenter(); diff --git a/main/src/cgeo/geocaching/maps/google/v1/GoogleCacheOverlay.java b/main/src/cgeo/geocaching/maps/google/v1/GoogleCacheOverlay.java index 9b18c2d..3d2b83c 100644 --- a/main/src/cgeo/geocaching/maps/google/v1/GoogleCacheOverlay.java +++ b/main/src/cgeo/geocaching/maps/google/v1/GoogleCacheOverlay.java @@ -21,10 +21,10 @@ import java.util.concurrent.locks.ReentrantLock; */ public class GoogleCacheOverlay extends ItemizedOverlay implements ItemizedOverlayImpl { - private CachesOverlay base; - private Lock lock = new ReentrantLock(); + private final CachesOverlay base; + private final Lock lock = new ReentrantLock(); - public GoogleCacheOverlay(Context contextIn, Drawable markerIn) { + public GoogleCacheOverlay(final Context contextIn, final Drawable markerIn) { super(boundCenterBottom(markerIn)); base = new CachesOverlay(this, contextIn); } @@ -35,7 +35,7 @@ public class GoogleCacheOverlay extends ItemizedOverlay } @Override - protected GoogleCacheOverlayItem createItem(int i) { + protected GoogleCacheOverlayItem createItem(final int i) { if (base == null) { return null; } @@ -53,7 +53,7 @@ public class GoogleCacheOverlay extends ItemizedOverlay } @Override - protected boolean onTap(int arg0) { + protected boolean onTap(final int arg0) { if (base == null) { return false; } @@ -62,11 +62,11 @@ public class GoogleCacheOverlay extends ItemizedOverlay } @Override - public void draw(Canvas canvas, MapView mapView, boolean shadow) { + public void draw(final Canvas canvas, final MapView mapView, final boolean shadow) { base.draw(canvas, castMapViewImpl(mapView), shadow); } - private static MapViewImpl castMapViewImpl(MapView mapView) { + private static MapViewImpl castMapViewImpl(final MapView mapView) { assert mapView instanceof MapViewImpl; return (MapViewImpl) mapView; } @@ -77,28 +77,28 @@ public class GoogleCacheOverlay extends ItemizedOverlay } @Override - public Drawable superBoundCenterBottom(Drawable marker) { + public Drawable superBoundCenterBottom(final Drawable marker) { return ItemizedOverlay.boundCenterBottom(marker); } @Override - public void superSetLastFocusedItemIndex(int i) { + public void superSetLastFocusedItemIndex(final int i) { super.setLastFocusedIndex(i); } @Override - public boolean superOnTap(int index) { + public boolean superOnTap(final int index) { return super.onTap(index); } @Override - public void superDraw(Canvas canvas, MapViewImpl mapView, boolean shadow) { + public void superDraw(final Canvas canvas, final MapViewImpl mapView, final boolean shadow) { super.draw(canvas, (MapView) mapView, shadow); } @Override - public void superDrawOverlayBitmap(Canvas canvas, Point drawPosition, - MapProjectionImpl projection, byte drawZoomLevel) { + public void superDrawOverlayBitmap(final Canvas canvas, final Point drawPosition, + final MapProjectionImpl projection, final byte drawZoomLevel) { // Nothing to do here... } diff --git a/main/src/cgeo/geocaching/maps/google/v1/GoogleCacheOverlayItem.java b/main/src/cgeo/geocaching/maps/google/v1/GoogleCacheOverlayItem.java index 463aae9..977d67c 100644 --- a/main/src/cgeo/geocaching/maps/google/v1/GoogleCacheOverlayItem.java +++ b/main/src/cgeo/geocaching/maps/google/v1/GoogleCacheOverlayItem.java @@ -10,7 +10,7 @@ public class GoogleCacheOverlayItem extends OverlayItem implements CachesOverlay final private IWaypoint coord; final private boolean applyDistanceRule; - public GoogleCacheOverlayItem(final IWaypoint coordinate, boolean applyDistanceRule) { + public GoogleCacheOverlayItem(final IWaypoint coordinate, final boolean applyDistanceRule) { super(new GeoPoint(coordinate.getCoords().getLatitudeE6(), coordinate.getCoords().getLongitudeE6()), coordinate.getName(), ""); this.coord = coordinate; diff --git a/main/src/cgeo/geocaching/maps/google/v1/GoogleGeoPoint.java b/main/src/cgeo/geocaching/maps/google/v1/GoogleGeoPoint.java index 7fbfac2..3f89807 100644 --- a/main/src/cgeo/geocaching/maps/google/v1/GoogleGeoPoint.java +++ b/main/src/cgeo/geocaching/maps/google/v1/GoogleGeoPoint.java @@ -7,7 +7,7 @@ import com.google.android.maps.GeoPoint; public class GoogleGeoPoint extends GeoPoint implements GeoPointImpl { - public GoogleGeoPoint(int latitudeE6, int longitudeE6) { + public GoogleGeoPoint(final int latitudeE6, final int longitudeE6) { super(latitudeE6, longitudeE6); } diff --git a/main/src/cgeo/geocaching/maps/google/v1/GoogleMapActivity.java b/main/src/cgeo/geocaching/maps/google/v1/GoogleMapActivity.java index 374e7b0..04078cb 100644 --- a/main/src/cgeo/geocaching/maps/google/v1/GoogleMapActivity.java +++ b/main/src/cgeo/geocaching/maps/google/v1/GoogleMapActivity.java @@ -16,7 +16,7 @@ import android.view.View; public class GoogleMapActivity extends MapActivity implements MapActivityImpl, FilteredActivity { - private AbstractMap mapBase; + private final AbstractMap mapBase; public GoogleMapActivity() { mapBase = new CGeoMap(this); @@ -33,7 +33,7 @@ public class GoogleMapActivity extends MapActivity implements MapActivityImpl, F } @Override - protected void onCreate(Bundle icicle) { + protected void onCreate(final Bundle icicle) { mapBase.onCreate(icicle); } @@ -58,17 +58,17 @@ public class GoogleMapActivity extends MapActivity implements MapActivityImpl, F } @Override - public boolean onCreateOptionsMenu(Menu menu) { + public boolean onCreateOptionsMenu(final Menu menu) { return mapBase.onCreateOptionsMenu(menu); } @Override - public boolean onOptionsItemSelected(MenuItem item) { + public boolean onOptionsItemSelected(final MenuItem item) { return mapBase.onOptionsItemSelected(item); } @Override - public boolean onPrepareOptionsMenu(Menu menu) { + public boolean onPrepareOptionsMenu(final Menu menu) { return mapBase.onPrepareOptionsMenu(menu); } @@ -78,12 +78,12 @@ public class GoogleMapActivity extends MapActivity implements MapActivityImpl, F } @Override - public void superOnCreate(Bundle savedInstanceState) { + public void superOnCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override - public boolean superOnCreateOptionsMenu(Menu menu) { + public boolean superOnCreateOptionsMenu(final Menu menu) { return super.onCreateOptionsMenu(menu); } @@ -93,12 +93,12 @@ public class GoogleMapActivity extends MapActivity implements MapActivityImpl, F } @Override - public boolean superOnOptionsItemSelected(MenuItem item) { + public boolean superOnOptionsItemSelected(final MenuItem item) { return super.onOptionsItemSelected(item); } @Override - public void navigateUp(View view) { + public void navigateUp(final View view) { ActivityMixin.navigateUp(this); } @@ -118,12 +118,12 @@ public class GoogleMapActivity extends MapActivity implements MapActivityImpl, F } @Override - public boolean superOnPrepareOptionsMenu(Menu menu) { + public boolean superOnPrepareOptionsMenu(final Menu menu) { return super.onPrepareOptionsMenu(menu); } @Override - public void showFilterMenu(View view) { + public void showFilterMenu(final View view) { // do nothing, the filter bar only shows the global filter } } diff --git a/main/src/cgeo/geocaching/maps/google/v1/GoogleMapController.java b/main/src/cgeo/geocaching/maps/google/v1/GoogleMapController.java index ea95676..a533a76 100644 --- a/main/src/cgeo/geocaching/maps/google/v1/GoogleMapController.java +++ b/main/src/cgeo/geocaching/maps/google/v1/GoogleMapController.java @@ -8,34 +8,34 @@ import com.google.android.maps.MapController; public class GoogleMapController implements MapControllerImpl { - private MapController mapController; + private final MapController mapController; - public GoogleMapController(MapController mapControllerIn) { + public GoogleMapController(final MapController mapControllerIn) { mapController = mapControllerIn; } @Override - public void animateTo(GeoPointImpl geoPoint) { + public void animateTo(final GeoPointImpl geoPoint) { mapController.animateTo(castToGeoPointImpl(geoPoint)); } - private static GeoPoint castToGeoPointImpl(GeoPointImpl geoPoint) { + private static GeoPoint castToGeoPointImpl(final GeoPointImpl geoPoint) { assert geoPoint instanceof GeoPoint; return (GeoPoint) geoPoint; } @Override - public void setCenter(GeoPointImpl geoPoint) { + public void setCenter(final GeoPointImpl geoPoint) { mapController.setCenter(castToGeoPointImpl(geoPoint)); } @Override - public void setZoom(int mapzoom) { + public void setZoom(final int mapzoom) { mapController.setZoom(mapzoom); } @Override - public void zoomToSpan(int latSpanE6, int lonSpanE6) { + public void zoomToSpan(final int latSpanE6, final int lonSpanE6) { mapController.zoomToSpan(latSpanE6, lonSpanE6); } diff --git a/main/src/cgeo/geocaching/maps/google/v1/GoogleMapItemFactory.java b/main/src/cgeo/geocaching/maps/google/v1/GoogleMapItemFactory.java index 5fedf69..a35eda8 100644 --- a/main/src/cgeo/geocaching/maps/google/v1/GoogleMapItemFactory.java +++ b/main/src/cgeo/geocaching/maps/google/v1/GoogleMapItemFactory.java @@ -14,7 +14,7 @@ public class GoogleMapItemFactory implements MapItemFactory { } @Override - public CachesOverlayItemImpl getCachesOverlayItem(final IWaypoint coordinate, boolean applyDistanceRule) { + public CachesOverlayItemImpl getCachesOverlayItem(final IWaypoint coordinate, final boolean applyDistanceRule) { return new GoogleCacheOverlayItem(coordinate, applyDistanceRule); } } diff --git a/main/src/cgeo/geocaching/maps/google/v1/GoogleMapProjection.java b/main/src/cgeo/geocaching/maps/google/v1/GoogleMapProjection.java index 901a369..8a03bbb 100644 --- a/main/src/cgeo/geocaching/maps/google/v1/GoogleMapProjection.java +++ b/main/src/cgeo/geocaching/maps/google/v1/GoogleMapProjection.java @@ -10,14 +10,14 @@ import android.graphics.Point; public class GoogleMapProjection implements MapProjectionImpl { - private Projection projection; + private final Projection projection; - public GoogleMapProjection(Projection projectionIn) { + public GoogleMapProjection(final Projection projectionIn) { projection = projectionIn; } @Override - public void toPixels(GeoPointImpl leftGeo, Point left) { + public void toPixels(final GeoPointImpl leftGeo, final Point left) { projection.toPixels((GeoPoint) leftGeo, left); } diff --git a/main/src/cgeo/geocaching/maps/google/v1/GoogleMapProvider.java b/main/src/cgeo/geocaching/maps/google/v1/GoogleMapProvider.java index 884e076..8c9dd4d 100644 --- a/main/src/cgeo/geocaching/maps/google/v1/GoogleMapProvider.java +++ b/main/src/cgeo/geocaching/maps/google/v1/GoogleMapProvider.java @@ -83,7 +83,7 @@ public final class GoogleMapProvider extends AbstractMapProvider { private static final class GoogleSatelliteSource extends AbstractGoogleMapSource { - public GoogleSatelliteSource(MapProvider mapProvider, String name) { + public GoogleSatelliteSource(final MapProvider mapProvider, final String name) { super(GOOGLE_SATELLITE_ID, mapProvider, name); } diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeCacheOverlay.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeCacheOverlay.java index b9e40d7..02e4243 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeCacheOverlay.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeCacheOverlay.java @@ -18,10 +18,10 @@ import java.util.concurrent.locks.ReentrantLock; public class MapsforgeCacheOverlay extends ItemizedOverlay implements ItemizedOverlayImpl { - private CachesOverlay base; - private Lock lock = new ReentrantLock(); + private final CachesOverlay base; + private final Lock lock = new ReentrantLock(); - public MapsforgeCacheOverlay(Context contextIn, Drawable markerIn) { + public MapsforgeCacheOverlay(final Context contextIn, final Drawable markerIn) { super(boundCenterBottom(markerIn)); base = new CachesOverlay(this, contextIn); } @@ -32,7 +32,7 @@ public class MapsforgeCacheOverlay extends ItemizedOverlay Date: Sun, 19 Apr 2015 09:42:04 +0200 Subject: fix #4895: NPE in DistanceDrawer --- main/src/cgeo/geocaching/maps/DistanceDrawer.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'main/src/cgeo/geocaching/maps') diff --git a/main/src/cgeo/geocaching/maps/DistanceDrawer.java b/main/src/cgeo/geocaching/maps/DistanceDrawer.java index f2d11bb..9dde8e6 100644 --- a/main/src/cgeo/geocaching/maps/DistanceDrawer.java +++ b/main/src/cgeo/geocaching/maps/DistanceDrawer.java @@ -17,7 +17,6 @@ import android.util.DisplayMetrics; import android.view.WindowManager; public class DistanceDrawer { - private Geopoint currentCoords; private final Geopoint destinationCoords; private Paint paintBox = null; @@ -56,15 +55,15 @@ public class DistanceDrawer { maxTextWidth = boxWidth - 3 * boxPadding; } - public void setCoordinates(final Location coordinatesIn) { - currentCoords = new Geopoint(coordinatesIn); + public void setCoordinates(final Location location) { + final Geopoint currentCoords = new Geopoint(location); final float distance = currentCoords.distanceTo(destinationCoords); distanceText = Units.getDistanceFromKilometers(distance); } void drawDistance(final Canvas canvas) { - if (currentCoords == null) { + if (distanceText == null) { return; } -- cgit v1.1