Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to set custom touch detectors to OsmandMapTileView #21455

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 28 additions & 15 deletions OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Loading