Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] - Add touch velocity effects on scale gesture. Fine tune.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramin Mirsharifi authored and tobrun committed Oct 18, 2017
1 parent 4c24500 commit 3d78709
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float d
return false;
}

if (tiltGestureOccurred) {
if (tiltGestureOccurred || scaleGestureOccurred) {
return false;
}

Expand Down Expand Up @@ -476,9 +476,14 @@ public boolean onScaleBegin(ScaleGestureDetector detector) {
@Override
public void onScaleEnd(ScaleGestureDetector detector) {
double velocityXY = Math.abs(velocityTracker.getYVelocity()) + Math.abs(velocityTracker.getXVelocity());
if (velocityXY > MapboxConstants.VELOCITY_THRESHOLD_IGNORE_FLING) {
if (velocityXY > MapboxConstants.VELOCITY_THRESHOLD_IGNORE_FLING / 2) {
long animationTime = (long)(Math.log(velocityXY) * 66);
transform.zoom(wasZoomingIn, new PointF(detector.getFocusX(), detector.getFocusY()), animationTime);
double zoomAddition = (float) (Math.log(velocityXY) / 7.7);
if (!wasZoomingIn) {
zoomAddition = -zoomAddition;
}
scaleGestureOccurred = true;
transform.zoom(zoomAddition, new PointF(detector.getFocusX(), detector.getFocusY()), animationTime);
handler.postDelayed(new Runnable() {
@Override
public void run() {
Expand Down Expand Up @@ -509,7 +514,7 @@ public boolean onScale(ScaleGestureDetector detector) {
// Also ignore small scales
long time = detector.getEventTime();
long interval = time - scaleBeginTime;
if (!scaleGestureOccurred && (interval <= ViewConfiguration.getTapTimeout())) {
if (!scaleGestureOccurred && (interval <= ViewConfiguration.getTapTimeout() / 3)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,10 @@ void zoom(boolean zoomIn, @NonNull PointF focalPoint) {
}
}

void zoom(boolean zoomIn, @NonNull PointF focalPoint,long duration) {
void zoom(double zoomAddition, @NonNull PointF focalPoint,long duration) {
CameraPosition cameraPosition = invalidateCameraPosition();
if (cameraPosition != null) {
int newZoom = (int) Math.round(cameraPosition.zoom + (zoomIn ? 1 : -1));
int newZoom = (int) Math.round(cameraPosition.zoom + zoomAddition);
setZoom(newZoom, focalPoint, duration);
} else {
// we are not transforming, notify about being idle
Expand Down

0 comments on commit 3d78709

Please sign in to comment.