Added Android 2.2 support for two finger touch. Zoom out without changing central point added.
This commit is contained in:
parent
e1191af1cf
commit
2cbf36cf25
2 changed files with 13 additions and 14 deletions
|
@ -1,5 +1,7 @@
|
||||||
package net.osmand.plus.helpers;
|
package net.osmand.plus.helpers;
|
||||||
|
|
||||||
|
import android.annotation.TargetApi;
|
||||||
|
import android.os.Build;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.ViewConfiguration;
|
import android.view.ViewConfiguration;
|
||||||
|
|
||||||
|
@ -10,15 +12,20 @@ public abstract class SimpleTwoFingerTapDetector {
|
||||||
private static final int TIMEOUT = ViewConfiguration.getTapTimeout() + 100;
|
private static final int TIMEOUT = ViewConfiguration.getTapTimeout() + 100;
|
||||||
private long mFirstDownTime = 0;
|
private long mFirstDownTime = 0;
|
||||||
private byte mTwoFingerTapCount = 0;
|
private byte mTwoFingerTapCount = 0;
|
||||||
private MotionEvent firstEvent = null;
|
|
||||||
|
|
||||||
private void reset(long time) {
|
private void reset(long time) {
|
||||||
mFirstDownTime = time;
|
mFirstDownTime = time;
|
||||||
mTwoFingerTapCount = 0;
|
mTwoFingerTapCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean onTouchEvent(MotionEvent event) {
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
switch (event.getActionMasked()) {
|
//this is workaround
|
||||||
|
// because we support android 2.2
|
||||||
|
int action = event.getAction();
|
||||||
|
//action code will have value same as event.getActionMasked()
|
||||||
|
int actionCode = action & MotionEvent.ACTION_MASK;
|
||||||
|
switch (actionCode) {
|
||||||
case MotionEvent.ACTION_DOWN:
|
case MotionEvent.ACTION_DOWN:
|
||||||
if (mFirstDownTime == 0 || event.getEventTime() - mFirstDownTime > TIMEOUT){
|
if (mFirstDownTime == 0 || event.getEventTime() - mFirstDownTime > TIMEOUT){
|
||||||
reset(event.getDownTime());
|
reset(event.getDownTime());
|
||||||
|
@ -27,18 +34,15 @@ public abstract class SimpleTwoFingerTapDetector {
|
||||||
case MotionEvent.ACTION_POINTER_UP:
|
case MotionEvent.ACTION_POINTER_UP:
|
||||||
if (event.getPointerCount() == 2) {
|
if (event.getPointerCount() == 2) {
|
||||||
mTwoFingerTapCount++;
|
mTwoFingerTapCount++;
|
||||||
firstEvent = MotionEvent.obtain(event);
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
mFirstDownTime = 0;
|
mFirstDownTime = 0;
|
||||||
firstEvent = null;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MotionEvent.ACTION_UP:
|
case MotionEvent.ACTION_UP:
|
||||||
if (mTwoFingerTapCount == 1 && event.getEventTime() - mFirstDownTime < TIMEOUT) {
|
if (mTwoFingerTapCount == 1 && event.getEventTime() - mFirstDownTime < TIMEOUT) {
|
||||||
onTwoFingerTap(firstEvent, event);
|
onTwoFingerTap();
|
||||||
mFirstDownTime = 0;
|
mFirstDownTime = 0;
|
||||||
firstEvent = null;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,5 +50,5 @@ public abstract class SimpleTwoFingerTapDetector {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void onTwoFingerTap(MotionEvent firstevent, MotionEvent secondevent);
|
public abstract void onTwoFingerTap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,14 +151,9 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
||||||
private boolean afterTwoFingerTap = false;
|
private boolean afterTwoFingerTap = false;
|
||||||
SimpleTwoFingerTapDetector twoFingerTapDetector = new SimpleTwoFingerTapDetector() {
|
SimpleTwoFingerTapDetector twoFingerTapDetector = new SimpleTwoFingerTapDetector() {
|
||||||
@Override
|
@Override
|
||||||
public void onTwoFingerTap(MotionEvent firstevent, MotionEvent secondevent) {
|
public void onTwoFingerTap() {
|
||||||
afterTwoFingerTap = true;
|
afterTwoFingerTap = true;
|
||||||
final RotatedTileBox tb = getCurrentRotatedTileBox();
|
getAnimatedDraggingThread().startZooming(getZoom()-1,true);
|
||||||
float midx = (firstevent.getX() + secondevent.getX()) / 2;
|
|
||||||
float midy = (firstevent.getY() + secondevent.getY()) / 2;
|
|
||||||
final double lat = tb.getLatFromPixel(midx, midy);
|
|
||||||
final double lon = tb.getLonFromPixel(midx, midy);
|
|
||||||
getAnimatedDraggingThread().startMoving(lat, lon, getZoom() - 1, true);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue