From 0ed4b641b6189c8e2521c70ff8cb9bad34cd0d35 Mon Sep 17 00:00:00 2001 From: chumv Date: Tue, 26 Nov 2024 19:02:15 +0200 Subject: [PATCH] Add ability to set custom touch detectors to OsmandMapTileView --- .../osmand/plus/views/OsmandMapTileView.java | 43 ++++++++++++------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java index d8cdcda0853..0c2d9742c13 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java @@ -28,7 +28,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.core.util.Pair; import net.osmand.PlatformUtil; import net.osmand.StateChangedListener; @@ -86,7 +85,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.Locale; import java.util.Map; public class OsmandMapTileView implements IMapDownloaderCallback { @@ -332,17 +330,16 @@ public void setMapActivity(@Nullable MapActivity mapActivity) { } public void setupTouchDetectors(@NonNull Context ctx) { - gestureDetector = new GestureDetector(ctx, new MapTileViewOnGestureListener()); - multiTouchSupport = new MultiTouchSupport(application, new MapTileViewMultiTouchZoomListener()); - doubleTapScaleDetector = new DoubleTapScaleDetector(this, ctx, new MapTileViewMultiTouchZoomListener()); - twoFingersTapDetector = new TwoFingerTapDetector() { + setGestureDetector(new GestureDetector(ctx, new MapTileViewOnGestureListener())); + setMultiTouchSupport(new MultiTouchSupport(application, new MapTileViewMultiTouchZoomListener())); + setDoubleTapScaleDetector(new DoubleTapScaleDetector(this, ctx, new MapTileViewMultiTouchZoomListener())); + setTwoFingersTapDetector(new TwoFingerTapDetector() { @Override public boolean onTouchEvent(MotionEvent event) { int action = event.getAction(); int actionCode = action & MotionEvent.ACTION_MASK; - switch (actionCode) { - case MotionEvent.ACTION_DOWN: - blockTwoFingersTap = false; + if (actionCode == MotionEvent.ACTION_DOWN) { + blockTwoFingersTap = false; } return super.onTouchEvent(event); } @@ -363,14 +360,30 @@ public void onTwoFingerTap() { } } } - }; + }); + } + + public void setDoubleTapScaleDetector(@Nullable DoubleTapScaleDetector detector) { + doubleTapScaleDetector = detector; + } + + public void setTwoFingersTapDetector(@Nullable TwoFingerTapDetector detector) { + twoFingersTapDetector = detector; + } + + public void setMultiTouchSupport(@Nullable MultiTouchSupport support) { + multiTouchSupport = support; + } + + public void setGestureDetector(@Nullable GestureDetector detector) { + gestureDetector = detector; } public void clearTouchDetectors() { - gestureDetector = null; - multiTouchSupport = null; - doubleTapScaleDetector = null; - twoFingersTapDetector = null; + setGestureDetector(null); + setMultiTouchSupport(null); + setDoubleTapScaleDetector(null); + setTwoFingersTapDetector(null); } @NonNull @@ -1694,7 +1707,7 @@ public void fitRectToMap(double left, double right, double top, double bottom, if (isLayoutRtl()) { dx = -dx; } else { - dx -= (tbw - tb.getPixWidth()) ; + dx -= (tbw - tb.getPixWidth()); } // dy -= (tbh - tb.getPixHeight()) / 2; // this to make margin from top dx += (int) (tbw * (1 - border) / 2);