Show distance between finger and markers
This commit is contained in:
parent
e2d3062438
commit
ec612db57d
1 changed files with 99 additions and 2 deletions
|
@ -10,9 +10,13 @@ import android.graphics.PointF;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.graphics.PorterDuffColorFilter;
|
import android.graphics.PorterDuffColorFilter;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Message;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
|
import android.view.GestureDetector;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
|
||||||
import net.osmand.Location;
|
import net.osmand.Location;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
|
@ -22,6 +26,7 @@ import net.osmand.data.RotatedTileBox;
|
||||||
import net.osmand.plus.GPXUtilities.TrkSegment;
|
import net.osmand.plus.GPXUtilities.TrkSegment;
|
||||||
import net.osmand.plus.MapMarkersHelper;
|
import net.osmand.plus.MapMarkersHelper;
|
||||||
import net.osmand.plus.MapMarkersHelper.MapMarker;
|
import net.osmand.plus.MapMarkersHelper.MapMarker;
|
||||||
|
import net.osmand.plus.OsmAndConstants;
|
||||||
import net.osmand.plus.OsmAndFormatter;
|
import net.osmand.plus.OsmAndFormatter;
|
||||||
import net.osmand.plus.OsmandSettings;
|
import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
|
@ -42,6 +47,8 @@ import gnu.trove.list.array.TIntArrayList;
|
||||||
public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvider,
|
public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvider,
|
||||||
IContextMenuProviderSelection, ContextMenuLayer.IMoveObjectProvider {
|
IContextMenuProviderSelection, ContextMenuLayer.IMoveObjectProvider {
|
||||||
|
|
||||||
|
private static final long USE_FINGER_LOCATION_DELAY = 1000;
|
||||||
|
private static final int MAP_REFRESH_MESSAGE = OsmAndConstants.UI_HANDLER_MAP_VIEW + 6;
|
||||||
protected static final int DIST_TO_SHOW = 80;
|
protected static final int DIST_TO_SHOW = 80;
|
||||||
private static final int TEXT_SIZE = 12;
|
private static final int TEXT_SIZE = 12;
|
||||||
private static final int VERTICAL_OFFSET = 10;
|
private static final int VERTICAL_OFFSET = 10;
|
||||||
|
@ -81,6 +88,13 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
|
||||||
private TIntArrayList ty = new TIntArrayList();
|
private TIntArrayList ty = new TIntArrayList();
|
||||||
private Path linePath = new Path();
|
private Path linePath = new Path();
|
||||||
|
|
||||||
|
private LatLon fingerLocation;
|
||||||
|
private boolean hasMoved;
|
||||||
|
private boolean moving;
|
||||||
|
private boolean useFingerLocation;
|
||||||
|
private GestureDetector longTapDetector;
|
||||||
|
private Handler handler;
|
||||||
|
|
||||||
private ContextMenuLayer contextMenuLayer;
|
private ContextMenuLayer contextMenuLayer;
|
||||||
|
|
||||||
private boolean inPlanRouteMode;
|
private boolean inPlanRouteMode;
|
||||||
|
@ -193,7 +207,39 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
|
||||||
@Override
|
@Override
|
||||||
public void initLayer(OsmandMapTileView view) {
|
public void initLayer(OsmandMapTileView view) {
|
||||||
this.view = view;
|
this.view = view;
|
||||||
|
handler = new Handler();
|
||||||
initUI();
|
initUI();
|
||||||
|
longTapDetector = new GestureDetector(view.getContext(), new GestureDetector.OnGestureListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onDown(MotionEvent e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onShowPress(MotionEvent e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onSingleTapUp(MotionEvent e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLongPress(MotionEvent e) {
|
||||||
|
cancelFingerAction();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -276,8 +322,8 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
|
||||||
@Override
|
@Override
|
||||||
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) {
|
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) {
|
||||||
Location myLoc = map.getMyApplication().getLocationProvider().getLastStaleKnownLocation();
|
Location myLoc = map.getMyApplication().getLocationProvider().getLastStaleKnownLocation();
|
||||||
widgetsFactory.updateInfo(myLoc == null
|
widgetsFactory.updateInfo(useFingerLocation ? fingerLocation : (myLoc == null
|
||||||
? tileBox.getCenterLatLon() : new LatLon(myLoc.getLatitude(), myLoc.getLongitude()), tileBox.getZoom());
|
? tileBox.getCenterLatLon() : new LatLon(myLoc.getLatitude(), myLoc.getLongitude())), tileBox.getZoom());
|
||||||
OsmandSettings settings = map.getMyApplication().getSettings();
|
OsmandSettings settings = map.getMyApplication().getSettings();
|
||||||
|
|
||||||
if (tileBox.getZoom() < 3 || !settings.USE_MAP_MARKERS.get()) {
|
if (tileBox.getZoom() < 3 || !settings.USE_MAP_MARKERS.get()) {
|
||||||
|
@ -374,6 +420,57 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
|
||||||
public void destroyLayer() {
|
public void destroyLayer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) {
|
||||||
|
if (!longTapDetector.onTouchEvent(event)) {
|
||||||
|
switch (event.getAction()) {
|
||||||
|
case MotionEvent.ACTION_DOWN:
|
||||||
|
float x = event.getX();
|
||||||
|
float y = event.getY();
|
||||||
|
fingerLocation = tileBox.getLatLonFromPixel(x, y);
|
||||||
|
hasMoved = false;
|
||||||
|
moving = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MotionEvent.ACTION_MOVE:
|
||||||
|
if (!hasMoved) {
|
||||||
|
if (!handler.hasMessages(MAP_REFRESH_MESSAGE)) {
|
||||||
|
Message msg = Message.obtain(handler, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
handler.removeMessages(MAP_REFRESH_MESSAGE);
|
||||||
|
if (moving) {
|
||||||
|
if (!useFingerLocation) {
|
||||||
|
useFingerLocation = true;
|
||||||
|
map.refreshMap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
msg.what = MAP_REFRESH_MESSAGE;
|
||||||
|
handler.sendMessageDelayed(msg, USE_FINGER_LOCATION_DELAY);
|
||||||
|
}
|
||||||
|
hasMoved = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MotionEvent.ACTION_UP:
|
||||||
|
case MotionEvent.ACTION_CANCEL:
|
||||||
|
cancelFingerAction();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.onTouchEvent(event, tileBox);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cancelFingerAction() {
|
||||||
|
handler.removeMessages(MAP_REFRESH_MESSAGE);
|
||||||
|
useFingerLocation = false;
|
||||||
|
moving = false;
|
||||||
|
fingerLocation = null;
|
||||||
|
map.refreshMap();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean drawInScreenPixels() {
|
public boolean drawInScreenPixels() {
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in a new issue