aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/maps
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/maps')
-rw-r--r--main/src/cgeo/geocaching/maps/CGeoMap.java176
-rw-r--r--main/src/cgeo/geocaching/maps/CachesOverlay.java2
-rw-r--r--main/src/cgeo/geocaching/maps/DirectionDrawer.java60
-rw-r--r--main/src/cgeo/geocaching/maps/DistanceDrawer.java131
-rw-r--r--main/src/cgeo/geocaching/maps/LiveMapStrategy.java48
-rw-r--r--main/src/cgeo/geocaching/maps/LivemapStrategy.java45
-rw-r--r--main/src/cgeo/geocaching/maps/PositionAndScaleOverlay.java43
-rw-r--r--main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java43
-rw-r--r--main/src/cgeo/geocaching/maps/google/v1/GoogleOverlay.java9
-rw-r--r--main/src/cgeo/geocaching/maps/interfaces/MapActivityImpl.java3
-rw-r--r--main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java3
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProvider.java50
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java55
-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
23 files changed, 481 insertions, 902 deletions
diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java
index 457b06c..c808ffd 100644
--- a/main/src/cgeo/geocaching/maps/CGeoMap.java
+++ b/main/src/cgeo/geocaching/maps/CGeoMap.java
@@ -4,6 +4,7 @@ import butterknife.ButterKnife;
import cgeo.geocaching.CacheListActivity;
import cgeo.geocaching.CgeoApplication;
+import cgeo.geocaching.CompassActivity;
import cgeo.geocaching.DataStore;
import cgeo.geocaching.Geocache;
import cgeo.geocaching.Intents;
@@ -22,7 +23,6 @@ import cgeo.geocaching.enumerations.WaypointType;
import cgeo.geocaching.list.StoredList;
import cgeo.geocaching.location.Geopoint;
import cgeo.geocaching.location.Viewport;
-import cgeo.geocaching.maps.LiveMapStrategy.Strategy;
import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl;
import cgeo.geocaching.maps.interfaces.GeoPointImpl;
import cgeo.geocaching.maps.interfaces.MapActivityImpl;
@@ -32,6 +32,7 @@ import cgeo.geocaching.maps.interfaces.MapProvider;
import cgeo.geocaching.maps.interfaces.MapSource;
import cgeo.geocaching.maps.interfaces.MapViewImpl;
import cgeo.geocaching.maps.interfaces.OnMapDragListener;
+import cgeo.geocaching.network.AndroidBeam;
import cgeo.geocaching.sensors.GeoData;
import cgeo.geocaching.sensors.GeoDirHandler;
import cgeo.geocaching.sensors.Sensors;
@@ -39,6 +40,7 @@ import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.ui.dialog.LiveMapInfoDialogBuilder;
import cgeo.geocaching.utils.AngleUtils;
import cgeo.geocaching.utils.CancellableHandler;
+import cgeo.geocaching.utils.Formatter;
import cgeo.geocaching.utils.LeastRecentlyUsedSet;
import cgeo.geocaching.utils.Log;
import cgeo.geocaching.utils.MapUtils;
@@ -46,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;
@@ -217,29 +220,9 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
switch (what) {
case UPDATE_TITLE:
- // set title
- final StringBuilder title = new StringBuilder();
+ map.setTitle();
+ map.setSubtitle();
- 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() && Settings.isDebug()) {
- title.append('/').append(map.caches.size());
- }
- title.append(']');
- }
-
- 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);
@@ -254,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) {
@@ -266,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;
@@ -396,7 +454,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
coordsIntent = extras.getParcelable(Intents.EXTRA_COORDS);
waypointTypeIntent = WaypointType.findById(extras.getString(Intents.EXTRA_WPTTYPE));
mapStateIntent = extras.getIntArray(Intents.EXTRA_MAPSTATE);
- mapTitle = extras.getString(Intents.EXTRA_MAP_TITLE);
+ mapTitle = extras.getString(Intents.EXTRA_TITLE);
}
else {
mapMode = MapMode.LIVE;
@@ -435,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());
@@ -449,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(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]) {
@@ -493,6 +554,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
if (!CgeoApplication.getInstance().isLiveMapHintShownInThisSession() && Settings.getLiveMapHintShowCount() <= 3) {
LiveMapInfoDialogBuilder.create(activity).show();
}
+ AndroidBeam.disable(activity);
}
private void initMyLocationSwitchButton(final CheckBox locSwitch) {
@@ -508,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);
@@ -663,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);
@@ -680,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);
}
@@ -708,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()) {
@@ -765,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) {
@@ -794,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();
@@ -901,7 +988,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
mapIntent.putExtra(Intents.EXTRA_COORDS, coordsIntent);
}
mapIntent.putExtra(Intents.EXTRA_WPTTYPE, waypointTypeIntent != null ? waypointTypeIntent.id : null);
- mapIntent.putExtra(Intents.EXTRA_MAP_TITLE, mapTitle);
+ mapIntent.putExtra(Intents.EXTRA_TITLE, mapTitle);
mapIntent.putExtra(Intents.EXTRA_MAP_MODE, mapMode);
mapIntent.putExtra(Intents.EXTRA_LIVE_ENABLED, isLiveEnabled);
@@ -994,12 +1081,13 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
final boolean needsRepaintForHeading = needsRepaintForHeading();
if (needsRepaintForDistanceOrAccuracy) {
- if (map.followMyLocation) {
+ if (CGeoMap.followMyLocation) {
map.centerMap(new Geopoint(currentLocation));
}
}
if (needsRepaintForDistanceOrAccuracy || needsRepaintForHeading) {
+
map.overlayPositionAndScale.setCoordinates(currentLocation);
map.overlayPositionAndScale.setHeading(currentHeading);
map.mapView.repaintRequired(map.overlayPositionAndScale);
@@ -1092,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;
@@ -1116,7 +1204,6 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
/**
* get if map is loading something
*
- * @return
*/
public boolean isLoading() {
return !loadTimer.isUnsubscribed() &&
@@ -1319,7 +1406,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
}
displayHandler.sendEmptyMessage(INVALIDATE_MAP);
- displayHandler.sendEmptyMessage(UPDATE_TITLE);
+ updateMapTitle();
} finally {
showProgressHandler.sendEmptyMessage(HIDE_PROGRESS);
}
@@ -1332,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;
@@ -1619,7 +1710,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
mapIntent.putExtra(Intents.EXTRA_MAP_MODE, MapMode.LIST);
mapIntent.putExtra(Intents.EXTRA_LIVE_ENABLED, false);
if (StringUtils.isNotBlank(title)) {
- mapIntent.putExtra(Intents.EXTRA_MAP_TITLE, title);
+ mapIntent.putExtra(Intents.EXTRA_TITLE, title);
}
fromActivity.startActivity(mapIntent);
}
@@ -1639,7 +1730,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
mapIntent.putExtra(Intents.EXTRA_WPTTYPE, type.id);
}
if (StringUtils.isNotBlank(title)) {
- mapIntent.putExtra(Intents.EXTRA_MAP_TITLE, title);
+ mapIntent.putExtra(Intents.EXTRA_TITLE, title);
}
fromActivity.startActivity(mapIntent);
}
@@ -1649,7 +1740,6 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
mapIntent.putExtra(Intents.EXTRA_MAP_MODE, MapMode.SINGLE);
mapIntent.putExtra(Intents.EXTRA_LIVE_ENABLED, false);
mapIntent.putExtra(Intents.EXTRA_GEOCODE, geocode);
- mapIntent.putExtra(Intents.EXTRA_MAP_TITLE, geocode);
fromActivity.startActivity(mapIntent);
}
diff --git a/main/src/cgeo/geocaching/maps/CachesOverlay.java b/main/src/cgeo/geocaching/maps/CachesOverlay.java
index c4c4465..048217e 100644
--- a/main/src/cgeo/geocaching/maps/CachesOverlay.java
+++ b/main/src/cgeo/geocaching/maps/CachesOverlay.java
@@ -158,8 +158,6 @@ public class CachesOverlay extends AbstractItemizedOverlay {
* reality and therefore the minor changes due to the projection will not make any visible difference at the zoom
* levels which are used to see the circles.
*
- * @param projection
- * @return
*/
private int calculateDrawingRadius(MapProjectionImpl projection) {
float[] distanceArray = new float[1];
diff --git a/main/src/cgeo/geocaching/maps/DirectionDrawer.java b/main/src/cgeo/geocaching/maps/DirectionDrawer.java
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..f2d11bb
--- /dev/null
+++ b/main/src/cgeo/geocaching/maps/DistanceDrawer.java
@@ -0,0 +1,131 @@
+package cgeo.geocaching.maps;
+
+import cgeo.geocaching.CgeoApplication;
+import cgeo.geocaching.location.Geopoint;
+import cgeo.geocaching.location.Units;
+import cgeo.geocaching.maps.interfaces.MapViewImpl;
+
+import android.content.Context;
+import android.graphics.BlurMaskFilter;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.Rect;
+import android.graphics.RectF;
+import android.graphics.Typeface;
+import android.location.Location;
+import android.util.DisplayMetrics;
+import android.view.WindowManager;
+
+public class DistanceDrawer {
+ private Geopoint currentCoords;
+ private final Geopoint destinationCoords;
+
+ private Paint paintBox = null;
+ private Paint paintBoxShadow = null;
+ private Paint paintText = null;
+ private BlurMaskFilter blurBoxShadow = null;
+
+ private final boolean needsInvertedColors;
+ private float pixelDensity = 0;
+ private final float boxWidth, boxHeight, boxCornerRadius, boxShadowSize, boxPadding;
+ private final float textHeight, maxTextWidth;
+ private final float boxX, boxY;
+
+ private String distanceText = null;
+
+ public DistanceDrawer(final MapViewImpl mapView, final Geopoint destinationCoords) {
+ this.destinationCoords = destinationCoords;
+
+ final DisplayMetrics metrics = new DisplayMetrics();
+ final WindowManager windowManager = (WindowManager) CgeoApplication.getInstance().getSystemService(Context.WINDOW_SERVICE);
+ windowManager.getDefaultDisplay().getMetrics(metrics);
+
+ pixelDensity = metrics.density;
+
+ boxPadding = 2;
+ boxWidth = 100 * pixelDensity + 3 * boxPadding;
+ boxHeight = 30 * pixelDensity + 2 * boxPadding;
+ boxCornerRadius = 5 * pixelDensity;
+ boxShadowSize = 1 * pixelDensity;
+ textHeight = 20 * pixelDensity;
+
+ needsInvertedColors = mapView.needsInvertedColors();
+ boxX = metrics.widthPixels - boxWidth;
+ boxY = 0;
+
+ maxTextWidth = boxWidth - 3 * boxPadding;
+ }
+
+ public void setCoordinates(final Location coordinatesIn) {
+ currentCoords = new Geopoint(coordinatesIn);
+
+ final float distance = currentCoords.distanceTo(destinationCoords);
+ distanceText = Units.getDistanceFromKilometers(distance);
+ }
+
+ void drawDistance(final Canvas canvas) {
+ if (currentCoords == null) {
+ return;
+ }
+
+ if (blurBoxShadow == null) {
+ blurBoxShadow = new BlurMaskFilter(3, BlurMaskFilter.Blur.NORMAL);
+
+ 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
deleted file mode 100644
index 16d5e8b..0000000
--- a/main/src/cgeo/geocaching/maps/LiveMapStrategy.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package cgeo.geocaching.maps;
-
-import cgeo.geocaching.CgeoApplication;
-import cgeo.geocaching.R;
-
-import java.util.EnumSet;
-
-/**
- * Defines the strategy for the Live Map
- */
-public interface LiveMapStrategy {
-
- public enum StrategyFlag {
- LOAD_TILES, // 2x2 tiles filling the complete viewport
- PARSE_TILES, // parse PNG images
- SEARCH_NEARBY // searchByCoords()
- }
-
- public enum Strategy {
- FASTEST(1, EnumSet.of(StrategyFlag.LOAD_TILES), R.string.map_strategy_fastest),
- FAST(2, EnumSet.of(StrategyFlag.LOAD_TILES, StrategyFlag.PARSE_TILES), R.string.map_strategy_fast),
- AUTO(3, EnumSet.noneOf(StrategyFlag.class), R.string.map_strategy_auto),
- DETAILED(4, EnumSet.allOf(StrategyFlag.class), R.string.map_strategy_detailed);
-
- public final int id;
- public final EnumSet<StrategyFlag> flags;
- private final int stringId;
-
- Strategy(int id, EnumSet<StrategyFlag> flags, int stringId) {
- this.id = id;
- this.flags = flags;
- this.stringId = stringId;
- }
-
- public static Strategy getById(final int id) {
- for (Strategy strategy : Strategy.values()) {
- if (strategy.id == id) {
- return strategy;
- }
- }
- return AUTO;
- }
-
- public final String getL10n() {
- return CgeoApplication.getInstance().getBaseContext().getResources().getString(stringId);
- }
- }
-}
diff --git a/main/src/cgeo/geocaching/maps/LivemapStrategy.java b/main/src/cgeo/geocaching/maps/LivemapStrategy.java
new file mode 100644
index 0000000..c135fc8
--- /dev/null
+++ b/main/src/cgeo/geocaching/maps/LivemapStrategy.java
@@ -0,0 +1,45 @@
+package cgeo.geocaching.maps;
+
+import cgeo.geocaching.CgeoApplication;
+import cgeo.geocaching.R;
+
+import java.util.EnumSet;
+
+/**
+ * Defines the strategy for the Live Map
+ */
+public enum LivemapStrategy {
+ FASTEST(1, EnumSet.of(Flag.LOAD_TILES), R.string.map_strategy_fastest),
+ FAST(2, EnumSet.of(Flag.LOAD_TILES, Flag.PARSE_TILES), R.string.map_strategy_fast),
+ AUTO(3, EnumSet.noneOf(Flag.class), R.string.map_strategy_auto),
+ DETAILED(4, EnumSet.allOf(Flag.class), R.string.map_strategy_detailed);
+
+ public final int id;
+ public final EnumSet<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/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/google/v1/GoogleMapView.java b/main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java
index d474e1d..f3b7e9e 100644
--- a/main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java
+++ b/main/src/cgeo/geocaching/maps/google/v1/GoogleMapView.java
@@ -2,6 +2,7 @@ package cgeo.geocaching.maps.google.v1;
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
+import cgeo.geocaching.location.Geopoint;
import cgeo.geocaching.location.Viewport;
import cgeo.geocaching.maps.CachesOverlay;
import cgeo.geocaching.maps.PositionAndScaleOverlay;
@@ -36,22 +37,22 @@ public class GoogleMapView extends MapView implements MapViewImpl {
private OnMapDragListener onDragListener;
private final GoogleMapController mapController = new GoogleMapController(getController());
- public GoogleMapView(Context context, AttributeSet attrs) {
+ public GoogleMapView(final Context context, final AttributeSet attrs) {
super(context, attrs);
initialize(context);
}
- public GoogleMapView(Context context, AttributeSet attrs, int defStyle) {
+ public GoogleMapView(final Context context, final AttributeSet attrs, final int defStyle) {
super(context, attrs, defStyle);
initialize(context);
}
- public GoogleMapView(Context context, String apiKey) {
+ public GoogleMapView(final Context context, final String apiKey) {
super(context, apiKey);
initialize(context);
}
- private void initialize(Context context) {
+ private void initialize(final Context context) {
if (isInEditMode()) {
return;
}
@@ -66,16 +67,16 @@ public class GoogleMapView extends MapView implements MapViewImpl {
}
super.draw(canvas);
- } catch (Exception e) {
+ } catch (final Exception e) {
Log.e("GoogleMapView.draw", e);
}
}
@Override
- public void displayZoomControls(boolean takeFocus) {
+ public void displayZoomControls(final boolean takeFocus) {
try {
// Push zoom controls to the right
- FrameLayout.LayoutParams zoomParams = new FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
+ final FrameLayout.LayoutParams zoomParams = new FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
zoomParams.gravity = Gravity.RIGHT;
// The call to retrieve the zoom buttons controller is undocumented and works so far on all devices
// supported by Google Play, but fails at least on one Jolla.
@@ -83,9 +84,9 @@ public class GoogleMapView extends MapView implements MapViewImpl {
controller.getZoomControls().setLayoutParams(zoomParams);
super.displayZoomControls(takeFocus);
- } catch (NoSuchMethodException ignored) {
+ } catch (final NoSuchMethodException ignored) {
Log.w("GoogleMapView.displayZoomControls: unable to explicitly place the zoom buttons");
- } catch (Exception e) {
+ } catch (final Exception e) {
Log.e("GoogleMapView.displayZoomControls", e);
}
}
@@ -98,7 +99,7 @@ public class GoogleMapView extends MapView implements MapViewImpl {
@Override
@NonNull
public GeoPointImpl getMapViewCenter() {
- GeoPoint point = getMapCenter();
+ final GeoPoint point = getMapCenter();
return new GoogleGeoPoint(point.getLatitudeE6(), point.getLongitudeE6());
}
@@ -118,17 +119,17 @@ public class GoogleMapView extends MapView implements MapViewImpl {
}
@Override
- public CachesOverlay createAddMapOverlay(Context context, Drawable drawable) {
+ public CachesOverlay createAddMapOverlay(final Context context, final Drawable drawable) {
- GoogleCacheOverlay ovl = new GoogleCacheOverlay(context, drawable);
+ final GoogleCacheOverlay ovl = new GoogleCacheOverlay(context, drawable);
getOverlays().add(ovl);
return ovl.getBase();
}
@Override
- public PositionAndScaleOverlay createAddPositionAndScaleOverlay() {
+ public PositionAndScaleOverlay createAddPositionAndScaleOverlay(final Geopoint coords, final String geocode) {
- GoogleOverlay ovl = new GoogleOverlay();
+ final GoogleOverlay ovl = new GoogleOverlay(this, coords, geocode);
getOverlays().add(ovl);
return (PositionAndScaleOverlay) ovl.getBase();
}
@@ -144,21 +145,21 @@ public class GoogleMapView extends MapView implements MapViewImpl {
}
@Override
- public void repaintRequired(GeneralOverlay overlay) {
+ public void repaintRequired(final GeneralOverlay overlay) {
invalidate();
}
@Override
- public void setOnDragListener(OnMapDragListener onDragListener) {
+ public void setOnDragListener(final OnMapDragListener onDragListener) {
this.onDragListener = onDragListener;
}
@Override
- public boolean onTouchEvent(MotionEvent ev) {
+ public boolean onTouchEvent(final MotionEvent ev) {
try {
gestureDetector.onTouchEvent(ev);
return super.onTouchEvent(ev);
- } catch (Exception e) {
+ } catch (final Exception e) {
Log.e("GoogleMapView.onTouchEvent", e);
}
return false;
@@ -166,7 +167,7 @@ public class GoogleMapView extends MapView implements MapViewImpl {
private class GestureListener extends SimpleOnGestureListener {
@Override
- public boolean onDoubleTap(MotionEvent e) {
+ public boolean onDoubleTap(final MotionEvent e) {
getController().zoomInFixing((int) e.getX(), (int) e.getY());
if (onDragListener != null) {
onDragListener.onDrag();
@@ -175,8 +176,8 @@ public class GoogleMapView extends MapView implements MapViewImpl {
}
@Override
- public boolean onScroll(MotionEvent e1, MotionEvent e2,
- float distanceX, float distanceY) {
+ public boolean onScroll(final MotionEvent e1, final MotionEvent e2,
+ final float distanceX, final float distanceY) {
if (onDragListener != null) {
onDragListener.onDrag();
}
diff --git a/main/src/cgeo/geocaching/maps/google/v1/GoogleOverlay.java b/main/src/cgeo/geocaching/maps/google/v1/GoogleOverlay.java
index 40a5539..415de1f 100644
--- a/main/src/cgeo/geocaching/maps/google/v1/GoogleOverlay.java
+++ b/main/src/cgeo/geocaching/maps/google/v1/GoogleOverlay.java
@@ -1,5 +1,6 @@
package cgeo.geocaching.maps.google.v1;
+import cgeo.geocaching.location.Geopoint;
import cgeo.geocaching.maps.PositionAndScaleOverlay;
import cgeo.geocaching.maps.interfaces.GeneralOverlay;
import cgeo.geocaching.maps.interfaces.MapViewImpl;
@@ -16,14 +17,14 @@ import java.util.concurrent.locks.ReentrantLock;
public class GoogleOverlay extends Overlay implements OverlayImpl {
private PositionAndScaleOverlay overlayBase = null;
- private Lock lock = new ReentrantLock();
+ private final Lock lock = new ReentrantLock();
- public GoogleOverlay() {
- overlayBase = new PositionAndScaleOverlay(this);
+ public GoogleOverlay(final MapViewImpl mapView, final Geopoint coords, final String geocode) {
+ overlayBase = new PositionAndScaleOverlay(this, mapView, coords, geocode);
}
@Override
- public void draw(Canvas canvas, MapView mapView, boolean shadow) {
+ public void draw(final Canvas canvas, final MapView mapView, final boolean shadow) {
super.draw(canvas, mapView, shadow);
if (overlayBase != null) {
diff --git a/main/src/cgeo/geocaching/maps/interfaces/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/MapViewImpl.java b/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java
index 0560ad4..1876dfc 100644
--- a/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java
+++ b/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java
@@ -1,5 +1,6 @@
package cgeo.geocaching.maps.interfaces;
+import cgeo.geocaching.location.Geopoint;
import cgeo.geocaching.location.Viewport;
import cgeo.geocaching.maps.CachesOverlay;
import cgeo.geocaching.maps.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/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/MapsforgeMapView.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java
index 73d87b0..71bf583 100644
--- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java
+++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java
@@ -1,6 +1,7 @@
package cgeo.geocaching.maps.mapsforge;
import cgeo.geocaching.R;
+import cgeo.geocaching.location.Geopoint;
import cgeo.geocaching.location.Viewport;
import cgeo.geocaching.maps.CachesOverlay;
import cgeo.geocaching.maps.PositionAndScaleOverlay;
@@ -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 ignored) {
+ } 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 72aceb0..0000000
--- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeGeoPoint.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package cgeo.geocaching.maps.mapsforge.v024;
-
-import cgeo.geocaching.location.Geopoint;
-import cgeo.geocaching.maps.interfaces.GeoPointImpl;
-
-import org.mapsforge.android.mapsold.GeoPoint;
-
-public class MapsforgeGeoPoint extends GeoPoint implements GeoPointImpl {
-
- public MapsforgeGeoPoint(int latitudeE6, int longitudeE6) {
- super(latitudeE6, longitudeE6);
- }
-
- @Override
- public Geopoint getCoords() {
- return new Geopoint(getLatitudeE6() / 1e6, getLongitudeE6() / 1e6);
- }
-}
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapActivity024.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapActivity024.java
deleted file mode 100644
index daeb2b8..0000000
--- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapActivity024.java
+++ /dev/null
@@ -1,124 +0,0 @@
-package cgeo.geocaching.maps.mapsforge.v024;
-
-import cgeo.geocaching.activity.ActivityMixin;
-import cgeo.geocaching.activity.FilteredActivity;
-import cgeo.geocaching.maps.AbstractMap;
-import cgeo.geocaching.maps.CGeoMap;
-import cgeo.geocaching.maps.interfaces.MapActivityImpl;
-
-import org.mapsforge.android.mapsold.MapActivity;
-
-import android.app.Activity;
-import android.os.Bundle;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-
-public class MapsforgeMapActivity024 extends MapActivity implements MapActivityImpl, FilteredActivity {
-
- private AbstractMap mapBase;
-
- public MapsforgeMapActivity024() {
- mapBase = new CGeoMap(this);
- }
-
- @Override
- public Activity getActivity() {
- return this;
- }
-
- @Override
- protected void onCreate(Bundle icicle) {
- mapBase.onCreate(icicle);
- }
-
- @Override
- protected void onSaveInstanceState(final Bundle outState) {
- mapBase.onSaveInstanceState(outState);
- }
-
- @Override
- protected void onDestroy() {
- mapBase.onDestroy();
- }
-
- @Override
- protected void onPause() {
- mapBase.onPause();
- }
-
- @Override
- protected void onResume() {
- mapBase.onResume();
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- return mapBase.onCreateOptionsMenu(menu);
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- return mapBase.onOptionsItemSelected(item);
- }
-
- @Override
- public boolean onPrepareOptionsMenu(Menu menu) {
- return mapBase.onPrepareOptionsMenu(menu);
- }
-
- @Override
- protected void onStop() {
- mapBase.onStop();
- }
-
- @Override
- public void superOnCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- }
-
- @Override
- public boolean superOnCreateOptionsMenu(Menu menu) {
- return super.onCreateOptionsMenu(menu);
- }
-
- @Override
- public void superOnDestroy() {
- super.onDestroy();
- }
-
- @Override
- public boolean superOnOptionsItemSelected(MenuItem item) {
- return super.onOptionsItemSelected(item);
- }
-
- @Override
- public void superOnResume() {
- super.onResume();
- }
-
- @Override
- public void superOnStop() {
- super.onStop();
- }
-
- @Override
- public void superOnPause() {
- super.onPause();
- }
-
- @Override
- public boolean superOnPrepareOptionsMenu(Menu menu) {
- return super.onPrepareOptionsMenu(menu);
- }
-
- @Override
- public void navigateUp(View view) {
- ActivityMixin.navigateUp(this);
- }
-
- @Override
- public void showFilterMenu(View view) {
- // do nothing, the filter bar only shows the global filter
- }
-}
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapController.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapController.java
deleted file mode 100644
index db33d56..0000000
--- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapController.java
+++ /dev/null
@@ -1,55 +0,0 @@
-package cgeo.geocaching.maps.mapsforge.v024;
-
-import cgeo.geocaching.maps.interfaces.GeoPointImpl;
-import cgeo.geocaching.maps.interfaces.MapControllerImpl;
-
-import org.mapsforge.android.mapsold.GeoPoint;
-import org.mapsforge.android.mapsold.MapController;
-
-public class MapsforgeMapController implements MapControllerImpl {
-
- private MapController mapController;
- private int maxZoomLevel;
-
- public MapsforgeMapController(MapController mapControllerIn, int maxZoomLevelIn) {
- mapController = mapControllerIn;
- maxZoomLevel = maxZoomLevelIn;
- }
-
- @Override
- public void animateTo(GeoPointImpl geoPoint) {
- mapController.setCenter(castToGeoPointImpl(geoPoint));
- }
-
- private static GeoPoint castToGeoPointImpl(GeoPointImpl geoPoint) {
- assert geoPoint instanceof GeoPoint;
- return (GeoPoint) geoPoint;
- }
-
- @Override
- public void setCenter(GeoPointImpl geoPoint) {
- mapController.setCenter(castToGeoPointImpl(geoPoint));
- }
-
- /**
- * Set the map zoom level to mapzoom-1 or maxZoomLevel, whichever is least
- * mapzoom-1 is used to be compatible with Google Maps zoom levels
- */
- @Override
- public void setZoom(int mapzoom) {
- // Google Maps and OSM Maps use different zoom levels for the same view.
- // All OSM Maps zoom levels are offset by 1 so they match Google Maps.
- mapController.setZoom(Math.min(mapzoom - 1, maxZoomLevel));
- }
-
- @Override
- public void zoomToSpan(int latSpanE6, int lonSpanE6) {
-
- if (latSpanE6 != 0 && lonSpanE6 != 0) {
- // calculate zoomlevel
- int distDegree = Math.max(latSpanE6, lonSpanE6);
- int zoomLevel = (int) Math.floor(Math.log(360.0 * 1e6 / distDegree) / Math.log(2));
- mapController.setZoom(zoomLevel + 1);
- }
- }
-}
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapItemFactory024.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapItemFactory024.java
deleted file mode 100644
index 23d94d9..0000000
--- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapItemFactory024.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package cgeo.geocaching.maps.mapsforge.v024;
-
-import cgeo.geocaching.IWaypoint;
-import cgeo.geocaching.location.Geopoint;
-import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl;
-import cgeo.geocaching.maps.interfaces.GeoPointImpl;
-import cgeo.geocaching.maps.interfaces.MapItemFactory;
-
-public class MapsforgeMapItemFactory024 implements MapItemFactory {
-
- @Override
- public GeoPointImpl getGeoPointBase(final Geopoint coords) {
- return new MapsforgeGeoPoint(coords.getLatitudeE6(), coords.getLongitudeE6());
- }
-
- @Override
- public CachesOverlayItemImpl getCachesOverlayItem(final IWaypoint coordinate, boolean applyDistanceRule) {
- return new MapsforgeCacheOverlayItem(coordinate, applyDistanceRule);
- }
-}
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapProjection.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapProjection.java
deleted file mode 100644
index 9d36b7d..0000000
--- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapProjection.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package cgeo.geocaching.maps.mapsforge.v024;
-
-import cgeo.geocaching.maps.interfaces.GeoPointImpl;
-import cgeo.geocaching.maps.interfaces.MapProjectionImpl;
-
-import org.mapsforge.android.mapsold.GeoPoint;
-import org.mapsforge.android.mapsold.Projection;
-
-import android.graphics.Point;
-
-public class MapsforgeMapProjection implements MapProjectionImpl {
-
- private Projection projection;
-
- public MapsforgeMapProjection(Projection projectionIn) {
- projection = projectionIn;
- }
-
- @Override
- public void toPixels(GeoPointImpl leftGeo, Point left) {
- projection.toPixels((GeoPoint) leftGeo, left);
- }
-
- @Override
- public Object getImpl() {
- return projection;
- }
-
-}
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java
deleted file mode 100644
index 42c55fe..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.location.Viewport;
-import cgeo.geocaching.maps.CachesOverlay;
-import cgeo.geocaching.maps.PositionAndScaleOverlay;
-import cgeo.geocaching.maps.interfaces.GeneralOverlay;
-import cgeo.geocaching.maps.interfaces.GeoPointImpl;
-import cgeo.geocaching.maps.interfaces.MapControllerImpl;
-import cgeo.geocaching.maps.interfaces.MapProjectionImpl;
-import cgeo.geocaching.maps.interfaces.MapViewImpl;
-import cgeo.geocaching.maps.interfaces.OnMapDragListener;
-import cgeo.geocaching.settings.Settings;
-import cgeo.geocaching.utils.Log;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.mapsforge.android.mapsold.GeoPoint;
-import org.mapsforge.android.mapsold.MapDatabase;
-import org.mapsforge.android.mapsold.MapView;
-import org.mapsforge.android.mapsold.MapViewMode;
-import org.mapsforge.android.mapsold.Overlay;
-import org.mapsforge.android.mapsold.Projection;
-
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.drawable.Drawable;
-import android.util.AttributeSet;
-import android.view.GestureDetector;
-import android.view.GestureDetector.SimpleOnGestureListener;
-import android.view.MotionEvent;
-import android.widget.Toast;
-public class MapsforgeMapView024 extends MapView implements MapViewImpl {
- private GestureDetector gestureDetector;
- private OnMapDragListener onDragListener;
- private final MapsforgeMapController mapController = new MapsforgeMapController(getController(), getMaxZoomLevel());
-
- public MapsforgeMapView024(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;
- }
-
-}