Fixed double tap scaling bug.

This commit is contained in:
GaidamakUA 2016-01-26 17:28:22 +02:00
parent 519f56b7e2
commit 93f6c7f00e
3 changed files with 38 additions and 15 deletions

View file

@ -52,7 +52,7 @@ public class DoubleTapScaleDetector {
secondDown = null; secondDown = null;
if (isDoubleTapping) { if (isDoubleTapping) {
isDoubleTapping = false; isDoubleTapping = false;
listener.onZoomEnded(scale, 0); listener.onZoomEnded(scale);
return true; return true;
} else { } else {
firstUp = MotionEvent.obtain(event); firstUp = MotionEvent.obtain(event);
@ -77,7 +77,7 @@ public class DoubleTapScaleDetector {
float delta = convertPxToDp((int) (firstDown.getY() - event.getY())); float delta = convertPxToDp((int) (firstDown.getY() - event.getY()));
float scaleDelta = delta / (displayHeightPx / SCALE_PER_SCREEN); float scaleDelta = delta / (displayHeightPx / SCALE_PER_SCREEN);
scale = 1 - scaleDelta; scale = 1 - scaleDelta;
listener.onZoomingOrRotating(scale, 0); listener.onZooming(scale);
return true; return true;
} }
} }
@ -130,9 +130,9 @@ public class DoubleTapScaleDetector {
public interface DoubleTapZoomListener { public interface DoubleTapZoomListener {
public void onZoomStarted(PointF centerPoint); public void onZoomStarted(PointF centerPoint);
public void onZoomingOrRotating(double relativeToStart, float angle); public void onZooming(double relativeToStart);
public void onZoomEnded(double relativeToStart, float angleRelative); public void onZoomEnded(double relativeToStart);
public void onGestureInit(float x1, float y1, float x2, float y2); public void onGestureInit(float x1, float y1, float x2, float y2);
} }

View file

@ -1,16 +1,16 @@
package net.osmand.plus.views; package net.osmand.plus.views;
import java.lang.reflect.Method;
import net.osmand.PlatformUtil;
import net.osmand.util.MapUtils;
import org.apache.commons.logging.Log;
import android.content.Context; import android.content.Context;
import android.graphics.PointF; import android.graphics.PointF;
import android.view.MotionEvent; import android.view.MotionEvent;
import net.osmand.PlatformUtil;
import net.osmand.util.MapUtils;
import org.apache.commons.logging.Log;
import java.lang.reflect.Method;
public class MultiTouchSupport { public class MultiTouchSupport {
@ -29,7 +29,7 @@ public class MultiTouchSupport {
public void onZoomingOrRotating(double relativeToStart, float angle); public void onZoomingOrRotating(double relativeToStart, float angle);
public void onZoomEnded(double relativeToStart, float angleRelative); public void onZoomOrRotationEnded(double relativeToStart, float angleRelative);
public void onGestureInit(float x1, float y1, float x2, float y2); public void onGestureInit(float x1, float y1, float x2, float y2);
@ -87,7 +87,7 @@ public class MultiTouchSupport {
Integer pointCount = (Integer) getPointerCount.invoke(event); Integer pointCount = (Integer) getPointerCount.invoke(event);
if(pointCount < 2){ if(pointCount < 2){
if(inZoomMode){ if(inZoomMode){
listener.onZoomEnded(zoomRelative, angleRelative); listener.onZoomOrRotationEnded(zoomRelative, angleRelative);
} }
return false; return false;
} }
@ -112,7 +112,7 @@ public class MultiTouchSupport {
return true; return true;
} else if(actionCode == ACTION_POINTER_UP){ } else if(actionCode == ACTION_POINTER_UP){
if(inZoomMode){ if(inZoomMode){
listener.onZoomEnded(zoomRelative, angleRelative); listener.onZoomOrRotationEnded(zoomRelative, angleRelative);
inZoomMode = false; inZoomMode = false;
} }
return true; return true;

View file

@ -859,7 +859,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
private static final float ANGLE_THRESHOLD = 15; private static final float ANGLE_THRESHOLD = 15;
@Override @Override
public void onZoomEnded(double relativeToStart, float angleRelative) { public void onZoomOrRotationEnded(double relativeToStart, float angleRelative) {
// 1.5 works better even on dm.density=1 devices // 1.5 works better even on dm.density=1 devices
float dz = (float) (Math.log(relativeToStart) / Math.log(2)) * 1.5f; float dz = (float) (Math.log(relativeToStart) / Math.log(2)) * 1.5f;
setIntZoom(Math.round(dz) + initialViewport.getZoom()); setIntZoom(Math.round(dz) + initialViewport.getZoom());
@ -880,6 +880,24 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
} }
} }
@Override
public void onZoomEnded(double relativeToStart) {
// 1.5 works better even on dm.density=1 devices
float dz = (float) ((relativeToStart - 1) * DoubleTapScaleDetector.SCALE_PER_SCREEN);
setIntZoom(Math.round(dz) + initialViewport.getZoom());
final int newZoom = getZoom();
if (application.accessibilityEnabled()) {
if (newZoom != initialViewport.getZoom()) {
showMessage(application.getString(R.string.zoomIs) + " " + newZoom); //$NON-NLS-1$
} else {
final LatLon p1 = initialViewport.getLatLonFromPixel(x1, y1);
final LatLon p2 = initialViewport.getLatLonFromPixel(x2, y2);
showMessage(OsmAndFormatter.getFormattedDistance((float) MapUtils.getDistance(p1.getLatitude(), p1.getLongitude(), p2.getLatitude(), p2.getLongitude()), application));
}
}
}
@Override @Override
public void onGestureInit(float x1, float y1, float x2, float y2) { public void onGestureInit(float x1, float y1, float x2, float y2) {
this.x1 = x1; this.x1 = x1;
@ -912,7 +930,12 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
if (dz != 0 || relAngle != 0) { if (dz != 0 || relAngle != 0) {
changeZoomPosition((float) dz, relAngle); changeZoomPosition((float) dz, relAngle);
} }
}
@Override
public void onZooming(double relativeToStart) {
double dz = (relativeToStart - 1) * DoubleTapScaleDetector.SCALE_PER_SCREEN;
changeZoomPosition((float) dz, 0);
} }
private void changeZoomPosition(float dz, float angle) { private void changeZoomPosition(float dz, float angle) {