Add "one tap make active" ability to markers from favorites and gpx

This commit is contained in:
alex 2017-12-08 16:31:20 +02:00
parent e760665a43
commit b31d511e0c
3 changed files with 59 additions and 2 deletions

View file

@ -136,7 +136,7 @@ public class MapActivityLayers {
mapView.addLayer(downloadedRegionsLayer, 0.5f);
// 0.9 gpx layer
gpxLayer = new GPXLayer();
gpxLayer = new GPXLayer(activity);
mapView.addLayer(gpxLayer, 0.9f);
// 1. route layer
@ -148,7 +148,7 @@ public class MapActivityLayers {
poiMapLayer = new POIMapLayer(activity);
mapView.addLayer(poiMapLayer, 3);
// 4. favorites layer
mFavouritesLayer = new FavouritesLayer();
mFavouritesLayer = new FavouritesLayer(activity);
mapView.addLayer(mFavouritesLayer, 4);
// 4.6 measurement tool layer
measurementToolLayer = new MeasurementToolLayer();

View file

@ -11,7 +11,9 @@ import android.graphics.PorterDuffColorFilter;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.v4.content.ContextCompat;
import android.view.View;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
@ -21,8 +23,10 @@ import net.osmand.data.QuadTree;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.views.ContextMenuLayer.ApplyMovedObjectCallback;
import net.osmand.plus.views.MapTextLayer.MapTextProvider;
@ -33,6 +37,8 @@ import java.util.List;
public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider,
ContextMenuLayer.IMoveObjectProvider, MapTextProvider<FavouritePoint> {
private MapActivity mapActivity;
protected int startZoom = 6;
protected OsmandMapTileView view;
@ -57,6 +63,10 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
return favorites.getFavouritePoints();
}
public FavouritesLayer(MapActivity mapActivity) {
this.mapActivity = mapActivity;
}
@Override
public void initLayer(OsmandMapTileView view) {
this.view = view;
@ -224,6 +234,25 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
@Override
public boolean runExclusiveAction(Object o, boolean unknownLocation) {
if (unknownLocation || o == null || !(o instanceof FavouritePoint)
|| !view.getApplication().getSettings().SELECT_MARKER_ON_SINGLE_TAP.get()) {
return false;
}
MapMarker marker = mapMarkersHelper.getMapMarker((FavouritePoint) o);
if (marker != null) {
final MapMarker old = mapMarkersHelper.getMapMarkers().get(0);
mapMarkersHelper.moveMarkerToTop(marker);
String title = mapActivity.getString(R.string.marker_activated, mapMarkersHelper.getMapMarkers().get(0).getName(mapActivity));
Snackbar.make(mapActivity.findViewById(R.id.bottomFragmentContainer), title, Snackbar.LENGTH_LONG)
.setAction(R.string.shared_string_cancel, new View.OnClickListener() {
@Override
public void onClick(View v) {
mapMarkersHelper.moveMarkerToTop(old);
}
})
.show();
return true;
}
return false;
}

View file

@ -18,7 +18,9 @@ import android.os.AsyncTask;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.v4.content.ContextCompat;
import android.view.View;
import net.osmand.AndroidUtils;
import net.osmand.data.LatLon;
@ -36,10 +38,12 @@ import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu.TrackChartPoints;
import net.osmand.plus.render.OsmandRenderer;
@ -59,6 +63,7 @@ import java.util.Map;
public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider,
ContextMenuLayer.IMoveObjectProvider, MapTextProvider<WptPt> {
private MapActivity mapActivity;
private OsmandMapTileView view;
private Paint paint;
@ -106,6 +111,10 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
@ColorInt
private int defPointColor;
public GPXLayer(MapActivity mapActivity) {
this.mapActivity = mapActivity;
}
@Override
public void initLayer(OsmandMapTileView view) {
this.view = view;
@ -579,6 +588,25 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
@Override
public boolean runExclusiveAction(Object o, boolean unknownLocation) {
if (unknownLocation || o == null || !(o instanceof WptPt)
|| !view.getApplication().getSettings().SELECT_MARKER_ON_SINGLE_TAP.get()) {
return false;
}
MapMarker marker = mapMarkersHelper.getMapMarker((WptPt) o);
if (marker != null) {
final MapMarker old = mapMarkersHelper.getMapMarkers().get(0);
mapMarkersHelper.moveMarkerToTop(marker);
String title = mapActivity.getString(R.string.marker_activated, mapMarkersHelper.getMapMarkers().get(0).getName(mapActivity));
Snackbar.make(mapActivity.findViewById(R.id.bottomFragmentContainer), title, Snackbar.LENGTH_LONG)
.setAction(R.string.shared_string_cancel, new View.OnClickListener() {
@Override
public void onClick(View v) {
mapMarkersHelper.moveMarkerToTop(old);
}
})
.show();
return true;
}
return false;
}