aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/maps
diff options
context:
space:
mode:
authorWolfgang Wiedmeyer <wolfgit@wiedmeyer.de>2015-05-08 17:10:06 +0200
committerWolfgang Wiedmeyer <wolfgit@wiedmeyer.de>2015-10-11 23:55:58 +0200
commit8ff62c5f34db48aa15c7252c40fea3381bba0952 (patch)
tree2a0ffd9bcf9a2648c45f170426cf86fb319509f2 /main/src/cgeo/geocaching/maps
parent1d2b34e71a01d6af118ed89258ad0ecb983e1a9c (diff)
parent59b8b2e26a7fff6072c4d5d96f51035dc900e0bc (diff)
downloadcgeo-8ff62c5f34db48aa15c7252c40fea3381bba0952.zip
cgeo-8ff62c5f34db48aa15c7252c40fea3381bba0952.tar.gz
cgeo-8ff62c5f34db48aa15c7252c40fea3381bba0952.tar.bz2
merge upstream
Diffstat (limited to 'main/src/cgeo/geocaching/maps')
-rw-r--r--main/src/cgeo/geocaching/maps/AbstractItemizedOverlay.java16
-rw-r--r--main/src/cgeo/geocaching/maps/AbstractMap.java12
-rw-r--r--main/src/cgeo/geocaching/maps/AbstractMapProvider.java2
-rw-r--r--main/src/cgeo/geocaching/maps/CGeoMap.java464
-rw-r--r--main/src/cgeo/geocaching/maps/CachesOverlay.java46
-rw-r--r--main/src/cgeo/geocaching/maps/DirectionDrawer.java60
-rw-r--r--main/src/cgeo/geocaching/maps/DistanceDrawer.java130
-rw-r--r--main/src/cgeo/geocaching/maps/LivemapStrategy.java45
-rw-r--r--main/src/cgeo/geocaching/maps/MapActivity.java17
-rw-r--r--main/src/cgeo/geocaching/maps/MapProviderFactory.java13
-rw-r--r--main/src/cgeo/geocaching/maps/PositionAndScaleOverlay.java43
-rw-r--r--main/src/cgeo/geocaching/maps/PositionDrawer.java50
-rw-r--r--main/src/cgeo/geocaching/maps/PositionHistory.java6
-rw-r--r--main/src/cgeo/geocaching/maps/ScaleDrawer.java10
-rw-r--r--main/src/cgeo/geocaching/maps/interfaces/MapActivityImpl.java3
-rw-r--r--main/src/cgeo/geocaching/maps/interfaces/MapItemFactory.java2
-rw-r--r--main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java5
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/MapsforgeCacheOverlay.java26
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/MapsforgeCacheOverlayItem.java4
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/MapsforgeGeoPoint.java4
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapActivity.java22
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapController.java20
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapItemFactory.java4
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProjection.java6
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProvider.java50
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapSource.java2
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java57
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOverlay.java11
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeCacheOverlay.java113
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeCacheOverlayItem.java37
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeGeoPoint.java18
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapActivity024.java124
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapController.java55
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapItemFactory024.java20
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapProjection.java29
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java254
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOverlay.java54
37 files changed, 739 insertions, 1095 deletions
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/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/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 9bbf7af..42e41b1 100644
--- a/main/src/cgeo/geocaching/maps/CGeoMap.java
+++ b/main/src/cgeo/geocaching/maps/CGeoMap.java
@@ -4,8 +4,10 @@ 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;
import cgeo.geocaching.R;
import cgeo.geocaching.SearchResult;
import cgeo.geocaching.Waypoint;
@@ -15,13 +17,12 @@ 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.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;
@@ -31,13 +32,15 @@ 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.network.AndroidBeam;
+import cgeo.geocaching.sensors.GeoData;
import cgeo.geocaching.sensors.GeoDirHandler;
-import cgeo.geocaching.sensors.IGeoData;
+import cgeo.geocaching.sensors.Sensors;
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;
@@ -45,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;
@@ -61,11 +65,13 @@ 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;
import android.os.Message;
import android.view.Menu;
+import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;
@@ -123,16 +129,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";
@@ -141,15 +137,14 @@ 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;
- private LeastRecentlyUsedSet<Geocache> caches;
+ final private LeastRecentlyUsedSet<Geocache> 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;
@@ -161,7 +156,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;
@@ -191,19 +186,20 @@ 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<String> 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
*/
private static final int MIN_LIVEMAP_ZOOM = 12;
// Thread pooling
- private static BlockingQueue<Runnable> displayQueue = new ArrayBlockingQueue<>(1);
- private static ThreadPoolExecutor displayExecutor = new ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS, displayQueue, new ThreadPoolExecutor.DiscardOldestPolicy());
- private static BlockingQueue<Runnable> downloadQueue = new ArrayBlockingQueue<>(1);
- private static ThreadPoolExecutor downloadExecutor = new ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS, downloadQueue, new ThreadPoolExecutor.DiscardOldestPolicy());
- private static BlockingQueue<Runnable> loadQueue = new ArrayBlockingQueue<>(1);
-
- private static ThreadPoolExecutor loadExecutor = new ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS, loadQueue, new ThreadPoolExecutor.DiscardOldestPolicy());
+ private static final BlockingQueue<Runnable> displayQueue = new ArrayBlockingQueue<>(1);
+ private static final ThreadPoolExecutor displayExecutor = new ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS, displayQueue, new ThreadPoolExecutor.DiscardOldestPolicy());
+ private static final BlockingQueue<Runnable> downloadQueue = new ArrayBlockingQueue<>(1);
+ private static final ThreadPoolExecutor downloadExecutor = new ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS, downloadQueue, new ThreadPoolExecutor.DiscardOldestPolicy());
+ private static final BlockingQueue<Runnable> loadQueue = new ArrayBlockingQueue<>(1);
+ private static final ThreadPoolExecutor loadExecutor = new ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS, loadQueue, new ThreadPoolExecutor.DiscardOldestPolicy());
// handlers
/** Updates the titles */
@@ -224,29 +220,9 @@ 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));
- } else {
- title.append(map.mapTitle);
- }
-
- map.countVisibleCaches();
- if (!map.caches.isEmpty() && !map.mapTitle.contains("[")) {
- title.append(" [").append(map.cachesCnt);
- if (map.cachesCnt != map.caches.size()) {
- title.append('/').append(map.caches.size());
- }
- title.append(']');
- }
+ map.setTitle();
+ map.setSubtitle();
- if (Settings.isDebug() && map.lastSearchResult != null && StringUtils.isNotBlank(map.lastSearchResult.getUrl())) {
- title.append('[').append(map.lastSearchResult.getUrl()).append(']');
- }
-
- map.setTitle(title.toString());
break;
case INVALIDATE_MAP:
map.mapView.repaintRequired(null);
@@ -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,10 +250,84 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
}
}
+ 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() {
+ // 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;
+ }
+ }
+ 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) {
+ titleView.setText(titleView.getText().toString() + ' ' + subtitle);
+ }
+ if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)) {
+ setSubtitleIceCreamSandwich(subtitle);
+ }
+ }
+
+ 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);
}
+
+ @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;
@@ -331,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 {
@@ -367,25 +418,10 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
public CGeoMap(final MapActivityImpl activity) {
super(activity);
- geoDirUpdate = new UpdateLoc(this);
}
protected void countVisibleCaches() {
- final List<Geocache> 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
@@ -404,10 +440,6 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
// class init
res = this.getResources();
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();
@@ -415,14 +447,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_TITLE);
}
else {
mapMode = MapMode.LIVE;
@@ -461,7 +493,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());
@@ -475,18 +507,21 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
mapView.clearOverlays();
overlayCaches = mapView.createAddMapOverlay(mapView.getContext(), getResources().getDrawable(R.drawable.marker));
- overlayPositionAndScale = mapView.createAddPositionAndScaleOverlay();
+
+
+ overlayPositionAndScale = mapView.createAddPositionAndScaleOverlay(coordsIntent, geocodeIntent);
if (trailHistory != null) {
overlayPositionAndScale.setHistory(trailHistory);
}
+
mapView.repaintRequired(null);
- setZoom(Settings.getMapZoom());
+ setZoom(Settings.getMapZoom(mapMode));
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]) {
@@ -504,9 +539,22 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
}
prepareFilterBar();
- if (!app.isLiveMapHintShownInThisSession() && !Settings.getHideLiveMapHint() && Settings.getLiveMapHintShowCount() <= 3) {
+ // 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 (!CgeoApplication.getInstance().isLiveMapHintShownInThisSession() && Settings.getLiveMapHintShowCount() <= 3) {
LiveMapInfoDialogBuilder.create(activity).show();
}
+ AndroidBeam.disable(activity);
}
private void initMyLocationSwitchButton(final CheckBox locSwitch) {
@@ -522,7 +570,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);
@@ -546,18 +593,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<Void, Void, Void>() {
+ @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();
}
}
@@ -581,10 +638,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);
@@ -592,7 +676,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);
@@ -640,7 +724,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);
@@ -657,6 +741,8 @@ 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);
+ menu.findItem(R.id.menu_compass).setVisible(mapMode == MapMode.SINGLE);
} catch (final RuntimeException e) {
Log.e("CGeoMap.onPrepareOptionsMenu", e);
}
@@ -685,6 +771,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()) {
@@ -714,7 +804,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);
}
@@ -742,24 +832,30 @@ 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:
+ menuShowHint();
+ return true;
+ case R.id.menu_compass:
+ menuCompass();
+ return true;
default:
final MapSource mapSource = MapProviderFactory.getMapSource(id);
if (mapSource != null) {
@@ -771,6 +867,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();
@@ -853,7 +963,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);
}
@@ -864,27 +979,27 @@ 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());
- 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_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);
}
+ // close old map
+ activity.finish();
+
// start the new map
activity.startActivity(mapIntent);
}
@@ -909,13 +1024,13 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
}
private void savePrefs() {
- Settings.setMapZoom(mapView.getMapZoomLevel());
+ Settings.setMapZoom(mapMode, mapView.getMapZoomLevel());
Settings.setMapCenter(mapView.getMapViewCenter());
}
// Set center of map to my location if appropriate.
- private void myLocationInMiddle(final IGeoData geo) {
- if (followMyLocation && !geo.isPseudoLocation()) {
+ private void myLocationInMiddle(final GeoData geo) {
+ if (followMyLocation) {
centerMap(geo.getCoords());
}
}
@@ -931,8 +1046,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("");
- boolean locationValid = false;
+ Location currentLocation = Sensors.getInstance().currentGeo();
float currentHeading;
private long timeLastPositionOverlayCalculation = 0;
@@ -946,16 +1060,10 @@ 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();
- }
+ public void updateGeoDir(final GeoData geo, final float dir) {
+ currentLocation = geo;
+ currentHeading = AngleUtils.getDirectionNow(dir);
+ repaintPositionOverlay();
}
/**
@@ -969,23 +1077,24 @@ 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 (map.followMyLocation) {
+ if (needsRepaintForDistanceOrAccuracy) {
+ if (CGeoMap.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);
}
}
} catch (final RuntimeException e) {
- Log.w("Failed to update location.");
+ Log.w("Failed to update location", e);
}
}
}
@@ -998,11 +1107,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
return Math.abs(AngleUtils.difference(currentHeading, map.overlayPositionAndScale.getHeading())) > MIN_HEADING_DELTA;
}
- boolean needsRepaintForDistance() {
- if (!locationValid) {
- return false;
- }
-
+ boolean needsRepaintForDistanceOrAccuracy() {
final CGeoMap map = mapRef.get();
if (map == null) {
return false;
@@ -1011,6 +1116,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);
}
@@ -1028,7 +1136,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
}
/**
- * Starts the {@link LoadTimer}.
+ * Starts the load timer.
*/
private Subscription startTimer() {
@@ -1037,7 +1145,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;
}
@@ -1072,7 +1180,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;
@@ -1094,16 +1202,8 @@ 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
*/
public boolean isLoading() {
return !loadTimer.isUnsubscribed() &&
@@ -1114,7 +1214,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 {
@@ -1134,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 {
@@ -1250,9 +1350,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
}
@@ -1302,19 +1399,14 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
}
itemsToDisplay.add(getCacheItem(cache));
}
-
- overlayCaches.updateItems(itemsToDisplay);
- displayHandler.sendEmptyMessage(INVALIDATE_MAP);
-
- } else {
+ }
+ // 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(INVALIDATE_MAP);
- displayHandler.sendEmptyMessage(UPDATE_TITLE);
- } catch (final ThreadDeath e) {
- Log.d("DisplayThread stopped");
- displayHandler.sendEmptyMessage(UPDATE_TITLE);
+ updateMapTitle();
} finally {
showProgressHandler.sendEmptyMessage(HIDE_PROGRESS);
}
@@ -1327,11 +1419,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<CGeoMap> mapRef;
@@ -1538,7 +1634,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
if (myLocSwitch != null) {
myLocSwitch.setChecked(followMyLocation);
if (followMyLocation) {
- myLocationInMiddle(app.currentGeo());
+ myLocationInMiddle(Sensors.getInstance().currentGeo());
}
}
}
@@ -1610,42 +1706,40 @@ 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_TITLE, title);
}
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(Intents.EXTRA_MAP_MODE, MapMode.LIVE)
+ .putExtra(Intents.EXTRA_LIVE_ENABLED, Settings.isLiveMap());
}
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_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);
fromActivity.startActivity(mapIntent);
}
diff --git a/main/src/cgeo/geocaching/maps/CachesOverlay.java b/main/src/cgeo/geocaching/maps/CachesOverlay.java
index 3c6109e..9649c0d 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;
@@ -43,13 +43,13 @@ public class CachesOverlay extends AbstractItemizedOverlay {
private List<CachesOverlayItemImpl> 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<CachesOverlayItemImpl> itemsPre = new ArrayList<>();
+ void updateItems(final CachesOverlayItemImpl item) {
+ final List<CachesOverlayItemImpl> itemsPre = new ArrayList<>();
itemsPre.add(item);
updateItems(itemsPre);
}
- void updateItems(List<CachesOverlayItemImpl> itemsPre) {
+ void updateItems(final List<CachesOverlayItemImpl> 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);
@@ -158,11 +158,9 @@ 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];
+ 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(),
@@ -202,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) {
@@ -232,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();
@@ -253,21 +251,19 @@ public class CachesOverlay extends AbstractItemizedOverlay {
}
progress.dismiss();
- } catch (NotFoundException e) {
+ } catch (final NotFoundException e) {
Log.e("CachesOverlay.onTap", e);
- if (progress != null) {
- progress.dismiss();
- }
+ progress.dismiss();
}
return true;
}
@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);
}
@@ -278,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/DirectionDrawer.java b/main/src/cgeo/geocaching/maps/DirectionDrawer.java
new file mode 100644
index 0000000..c746221
--- /dev/null
+++ b/main/src/cgeo/geocaching/maps/DirectionDrawer.java
@@ -0,0 +1,60 @@
+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) {
+ 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(width);
+ line.setColor(0x80EB391E);
+ }
+
+ 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/DistanceDrawer.java b/main/src/cgeo/geocaching/maps/DistanceDrawer.java
new file mode 100644
index 0000000..9dde8e6
--- /dev/null
+++ b/main/src/cgeo/geocaching/maps/DistanceDrawer.java
@@ -0,0 +1,130 @@
+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 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 location) {
+ final Geopoint currentCoords = new Geopoint(location);
+
+ final float distance = currentCoords.distanceTo(destinationCoords);
+ distanceText = Units.getDistanceFromKilometers(distance);
+ }
+
+ void drawDistance(final Canvas canvas) {
+ if (distanceText == null) {
+ return;
+ }
+
+ if (blurBoxShadow == null) {
+ blurBoxShadow = new BlurMaskFilter(3, BlurMaskFilter.Blur.NORMAL);
+
+ paintBoxShadow = new Paint();
+ paintBoxShadow.setAntiAlias(true);
+ paintBoxShadow.setMaskFilter(blurBoxShadow);
+
+ paintBox = new Paint();
+ paintBox.setAntiAlias(true);
+
+ paintText = new Paint();
+ paintText.setAntiAlias(true);
+ paintText.setTextAlign(Paint.Align.LEFT);
+ paintText.setTypeface(Typeface.DEFAULT_BOLD);
+
+ 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 */
+ 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/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<Flag> 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<Flag> 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/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();
+ }
+}
diff --git a/main/src/cgeo/geocaching/maps/MapProviderFactory.java b/main/src/cgeo/geocaching/maps/MapProviderFactory.java
index 8685d94..b504020 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 ignored) {
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 <tt>null</tt> if <tt>id</tt> 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<MapSource> deletion = new ArrayList<>();
- for (MapSource mapSource : mapSources) {
+ for (final MapSource mapSource : mapSources) {
if (mapSource instanceof MapsforgeMapProvider.OfflineMapSource) {
deletion.add(mapSource);
}
diff --git a/main/src/cgeo/geocaching/maps/PositionAndScaleOverlay.java b/main/src/cgeo/geocaching/maps/PositionAndScaleOverlay.java
index 63fcd73..9a6e4b9 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, final Geopoint coords, final String geocode) {
this.ovlImpl = ovlImpl;
positionDrawer = new PositionDrawer();
scaleDrawer = new ScaleDrawer();
+
+ 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);
+ }
+ }
}
- 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,27 @@ 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) {
+ if (directionDrawer != null) {
+ directionDrawer.drawDirection(canvas, projection);
+ }
positionDrawer.drawPosition(canvas, projection);
scaleDrawer.drawScale(canvas, mapView);
+ if (distanceDrawer != null) {
+ distanceDrawer.drawDistance(canvas);
+ }
}
@Override
@@ -66,7 +93,7 @@ public class PositionAndScaleOverlay implements GeneralOverlay {
return positionDrawer.getHistory();
}
- public void setHistory(ArrayList<Location> history) {
+ public void setHistory(final ArrayList<Location> history) {
positionDrawer.setHistory(history);
}
}
diff --git a/main/src/cgeo/geocaching/maps/PositionDrawer.java b/main/src/cgeo/geocaching/maps/PositionDrawer.java
index 08244ef..c7d1734 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;
@@ -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<Location> 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<Location> history) {
+ public void setHistory(final ArrayList<Location> 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<Location> history) {
+ public void setHistory(final ArrayList<Location> history) {
this.history = history;
}
diff --git a/main/src/cgeo/geocaching/maps/ScaleDrawer.java b/main/src/cgeo/geocaching/maps/ScaleDrawer.java
index 95c987d..e905873 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;
@@ -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/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);
}
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..1876dfc 100644
--- a/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java
+++ b/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java
@@ -1,6 +1,7 @@
package cgeo.geocaching.maps.interfaces;
-import cgeo.geocaching.geopoint.Viewport;
+import cgeo.geocaching.location.Geopoint;
+import cgeo.geocaching.location.Viewport;
import cgeo.geocaching.maps.CachesOverlay;
import cgeo.geocaching.maps.PositionAndScaleOverlay;
@@ -46,7 +47,7 @@ public interface MapViewImpl {
CachesOverlay createAddMapOverlay(Context context, Drawable drawable);
- PositionAndScaleOverlay createAddPositionAndScaleOverlay();
+ PositionAndScaleOverlay createAddPositionAndScaleOverlay(final Geopoint coords, final String geocode);
void setMapSource();
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<MapsforgeCacheOverlayItem> 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<MapsforgeCacheOverlay
}
@Override
- protected MapsforgeCacheOverlayItem createItem(int i) {
+ protected MapsforgeCacheOverlayItem createItem(final int i) {
if (base == null) {
return null;
}
@@ -50,7 +50,7 @@ public class MapsforgeCacheOverlay extends ItemizedOverlay<MapsforgeCacheOverlay
}
@Override
- protected boolean onTap(int arg0) {
+ protected boolean onTap(final int arg0) {
if (base == null) {
return false;
}
@@ -59,8 +59,8 @@ public class MapsforgeCacheOverlay extends ItemizedOverlay<MapsforgeCacheOverlay
}
@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) {
base.drawOverlayBitmap(canvas, drawPosition, new MapsforgeMapProjection(projection), drawZoomLevel);
}
@@ -70,28 +70,28 @@ public class MapsforgeCacheOverlay extends ItemizedOverlay<MapsforgeCacheOverlay
}
@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) {
// nothing to do
}
@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) {
// nothing to do here...
}
@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) {
super.drawOverlayBitmap(canvas, drawPosition, (Projection) projection.getImpl(), drawZoomLevel);
}
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeCacheOverlayItem.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeCacheOverlayItem.java
index 27ca664..4a1b080 100644
--- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeCacheOverlayItem.java
+++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeCacheOverlayItem.java
@@ -12,7 +12,7 @@ public class MapsforgeCacheOverlayItem extends OverlayItem implements CachesOver
final private IWaypoint coord;
final private boolean applyDistanceRule;
- public MapsforgeCacheOverlayItem(IWaypoint coordinate, boolean applyDistanceRule) {
+ public MapsforgeCacheOverlayItem(final IWaypoint coordinate, final boolean applyDistanceRule) {
super(new GeoPoint(coordinate.getCoords().getLatitudeE6(), coordinate.getCoords().getLongitudeE6()), coordinate.getName(), "");
this.coord = coordinate;
@@ -25,7 +25,7 @@ public class MapsforgeCacheOverlayItem extends OverlayItem implements CachesOver
}
@Override
- public Drawable getMarker(int index) {
+ public Drawable getMarker(final int index) {
return getMarker();
}
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeGeoPoint.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeGeoPoint.java
index 197bd76..25269e6 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;
@@ -9,7 +9,7 @@ public class MapsforgeGeoPoint extends GeoPoint implements GeoPointImpl {
private static final long serialVersionUID = 1L;
- public MapsforgeGeoPoint(int latitudeE6, int longitudeE6) {
+ public MapsforgeGeoPoint(final int latitudeE6, final int longitudeE6) {
super(latitudeE6, longitudeE6);
}
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapActivity.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapActivity.java
index 94213ba..5220e05 100644
--- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapActivity.java
+++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapActivity.java
@@ -16,7 +16,7 @@ import android.view.View;
public class MapsforgeMapActivity extends MapActivity implements MapActivityImpl, FilteredActivity {
- private AbstractMap mapBase;
+ private final AbstractMap mapBase;
public MapsforgeMapActivity() {
mapBase = new CGeoMap(this);
@@ -28,7 +28,7 @@ public class MapsforgeMapActivity extends MapActivity implements MapActivityImpl
}
@Override
- protected void onCreate(Bundle icicle) {
+ protected void onCreate(final Bundle icicle) {
mapBase.onCreate(icicle);
}
@@ -53,17 +53,17 @@ public class MapsforgeMapActivity extends MapActivity implements MapActivityImpl
}
@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);
}
@@ -73,12 +73,12 @@ public class MapsforgeMapActivity extends MapActivity implements MapActivityImpl
}
@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);
}
@@ -88,7 +88,7 @@ public class MapsforgeMapActivity extends MapActivity implements MapActivityImpl
}
@Override
- public boolean superOnOptionsItemSelected(MenuItem item) {
+ public boolean superOnOptionsItemSelected(final MenuItem item) {
return super.onOptionsItemSelected(item);
}
@@ -108,17 +108,17 @@ public class MapsforgeMapActivity extends MapActivity implements MapActivityImpl
}
@Override
- public boolean superOnPrepareOptionsMenu(Menu menu) {
+ public boolean superOnPrepareOptionsMenu(final Menu menu) {
return super.onPrepareOptionsMenu(menu);
}
@Override
- public void navigateUp(View view) {
+ public void navigateUp(final View view) {
ActivityMixin.navigateUp(this);
}
@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/mapsforge/MapsforgeMapController.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapController.java
index 8b2e1e9..cfce07d 100644
--- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapController.java
+++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapController.java
@@ -8,26 +8,26 @@ import org.mapsforge.core.GeoPoint;
public class MapsforgeMapController implements MapControllerImpl {
- private MapController mapController;
- private int maxZoomLevel;
+ private final MapController mapController;
+ private final int maxZoomLevel;
- public MapsforgeMapController(MapController mapControllerIn, int maxZoomLevelIn) {
+ public MapsforgeMapController(final MapController mapControllerIn, final int maxZoomLevelIn) {
mapController = mapControllerIn;
maxZoomLevel = maxZoomLevelIn;
}
@Override
- public void animateTo(GeoPointImpl geoPoint) {
+ public void animateTo(final GeoPointImpl geoPoint) {
mapController.setCenter(castToGeoPoint(geoPoint));
}
- private static GeoPoint castToGeoPoint(GeoPointImpl geoPoint) {
+ private static GeoPoint castToGeoPoint(final GeoPointImpl geoPoint) {
assert geoPoint instanceof GeoPoint;
return (GeoPoint) geoPoint;
}
@Override
- public void setCenter(GeoPointImpl geoPoint) {
+ public void setCenter(final GeoPointImpl geoPoint) {
mapController.setCenter(castToGeoPoint(geoPoint));
}
@@ -36,19 +36,19 @@ public class MapsforgeMapController implements MapControllerImpl {
* mapzoom-1 is used to be compatible with Google Maps zoom levels
*/
@Override
- public void setZoom(int mapzoom) {
+ public void setZoom(final 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) {
+ public void zoomToSpan(final int latSpanE6, final 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));
+ final int distDegree = Math.max(latSpanE6, lonSpanE6);
+ final 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/MapsforgeMapItemFactory.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapItemFactory.java
index 4ade09c..8adf4ad 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;
@@ -14,7 +14,7 @@ public class MapsforgeMapItemFactory implements MapItemFactory {
}
@Override
- public CachesOverlayItemImpl getCachesOverlayItem(final IWaypoint coordinate, boolean applyDistanceRule) {
+ public CachesOverlayItemImpl getCachesOverlayItem(final IWaypoint coordinate, final boolean applyDistanceRule) {
return new MapsforgeCacheOverlayItem(coordinate, applyDistanceRule);
}
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProjection.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProjection.java
index 68d7123..a042eca 100644
--- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProjection.java
+++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProjection.java
@@ -10,14 +10,14 @@ import android.graphics.Point;
public class MapsforgeMapProjection implements MapProjectionImpl {
- private Projection projection;
+ private final Projection projection;
- public MapsforgeMapProjection(Projection projectionIn) {
+ public MapsforgeMapProjection(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/mapsforge/MapsforgeMapProvider.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProvider.java
index 01b10ec..76d645c 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<String> mapFileList = new ArrayList<>();
+ final ArrayList<String> 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.getNumericalId() == source2.getNumericalId() || (!(source1 instanceof OfflineMapSource) && !(source2 instanceof OfflineMapSource));
}
@Override
public Class<? extends Activity> 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<String> 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/MapsforgeMapSource.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapSource.java
index 861e567..23e9a23 100644
--- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapSource.java
+++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapSource.java
@@ -9,7 +9,7 @@ class MapsforgeMapSource extends AbstractMapSource {
private final MapGeneratorInternal generator;
- public MapsforgeMapSource(final String id, MapProvider mapProvider, String name, MapGeneratorInternal generator) {
+ public MapsforgeMapSource(final String id, final MapProvider mapProvider, final String name, final MapGeneratorInternal generator) {
super(id, mapProvider, name);
this.generator = generator;
}
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java
index d95cc80..71bf583 100644
--- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java
+++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java
@@ -1,7 +1,8 @@
package cgeo.geocaching.maps.mapsforge;
import cgeo.geocaching.R;
-import cgeo.geocaching.geopoint.Viewport;
+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;
@@ -40,12 +41,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 +57,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 +66,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 +84,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,16 +104,16 @@ 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();
+ public PositionAndScaleOverlay createAddPositionAndScaleOverlay(final Geopoint coords, final String geocode) {
+ final MapsforgeOverlay ovl = new MapsforgeOverlay(this, coords, geocode);
getOverlays().add(ovl);
return (PositionAndScaleOverlay) ovl.getBase();
}
@@ -122,12 +123,12 @@ public class MapsforgeMapView extends MapView implements MapViewImpl {
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 +143,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 +192,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 +231,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 e) {
+ } catch (final FileNotFoundException ignored) {
Toast.makeText(
getContext(),
getContext().getResources().getString(R.string.warn_rendertheme_missing),
@@ -247,38 +248,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 +287,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/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/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<MapsforgeCacheOverlayItem> 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 c801e3f..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.geopoint.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 4f1d34c..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.geopoint.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 8dd15fc..0000000
--- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java
+++ /dev/null
@@ -1,254 +0,0 @@
-package cgeo.geocaching.maps.mapsforge.v024;
-
-import cgeo.geocaching.R;
-import cgeo.geocaching.geopoint.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(Context context, AttributeSet attrs) {
- super(context, attrs);
- initialize(context);
- }
-
- private void initialize(Context context) {
- if (isInEditMode()) {
- return;
- }
- gestureDetector = new GestureDetector(context, new GestureListener());
- }
-
- @Override
- public void draw(@NonNull 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 (Exception e) {
- Log.e("MapsforgeMapView024.draw", e);
- }
- }
-
- @Override
- public void displayZoomControls(boolean takeFocus) {
- // nothing to do here
- }
-
- @Override
- public MapControllerImpl getMapController() {
- return mapController;
- }
-
- @Override
- @NonNull
- public GeoPointImpl getMapViewCenter() {
- 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(Context context, Drawable drawable) {
-
- MapsforgeCacheOverlay ovl = new MapsforgeCacheOverlay(context, drawable);
- getOverlays().add(ovl);
- return ovl.getBase();
- }
-
- @Override
- public PositionAndScaleOverlay createAddPositionAndScaleOverlay() {
- MapsforgeOverlay ovl = new MapsforgeOverlay();
- getOverlays().add(ovl);
- return (PositionAndScaleOverlay) ovl.getBase();
- }
-
- @Override
- public int getLatitudeSpan() {
-
- int span = 0;
-
- Projection projection = getProjection();
-
- if (projection != null && getHeight() > 0) {
-
- GeoPoint low = projection.fromPixels(0, 0);
- 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;
-
- Projection projection = getProjection();
-
- if (projection != null && getWidth() > 0) {
- GeoPoint low = projection.fromPixels(0, 0);
- 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(GeneralOverlay overlay) {
-
- if (null == overlay) {
- invalidate();
- } else {
- try {
- Overlay ovl = (Overlay) overlay.getOverlayImpl();
-
- if (ovl != null) {
- ovl.requestRedraw();
- }
-
- } catch (Exception e) {
- Log.e("MapsforgeMapView024.repaintRequired", e);
- }
- }
- }
-
- @Override
- public void setOnDragListener(OnMapDragListener onDragListener) {
- this.onDragListener = onDragListener;
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent ev) {
- gestureDetector.onTouchEvent(ev);
- return super.onTouchEvent(ev);
- }
-
- private class GestureListener extends SimpleOnGestureListener {
- @Override
- public boolean onDoubleTap(MotionEvent e) {
- if (onDragListener != null) {
- onDragListener.onDrag();
- }
- return true;
- }
-
- @Override
- public boolean onScroll(MotionEvent e1, MotionEvent e2,
- float distanceX, 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 bfb3548..0000000
--- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOverlay.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package cgeo.geocaching.maps.mapsforge.v024;
-
-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 Lock lock = new ReentrantLock();
-
- public MapsforgeOverlay() {
- overlayBase = new PositionAndScaleOverlay(this);
- }
-
- @Override
- protected void drawOverlayBitmap(Canvas canvas, Point drawPosition,
- Projection projection, 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;
- }
-
-}