double tap scale is back
This commit is contained in:
parent
8d350238cf
commit
424f44ba12
@ -33,6 +33,7 @@ import android.content.Context;
|
|||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.view.GestureDetector;
|
import android.view.GestureDetector;
|
||||||
|
import android.view.GestureDetector.OnDoubleTapListener;
|
||||||
import android.view.GestureDetector.OnGestureListener;
|
import android.view.GestureDetector.OnGestureListener;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
@ -140,6 +141,23 @@ public class MapView extends RelativeLayout {
|
|||||||
return mMap.handleGesture(Gesture.PRESS, mMotionEvent.wrap(e));
|
return mMap.handleGesture(Gesture.PRESS, mMotionEvent.wrap(e));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
mGestureDetector.setOnDoubleTapListener(new OnDoubleTapListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onSingleTapConfirmed(MotionEvent e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onDoubleTapEvent(MotionEvent e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onDoubleTap(MotionEvent e) {
|
||||||
|
return mMap.handleGesture(Gesture.DOUBLE_TAP, mMotionEvent.wrap(e));
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map getMap() {
|
public Map getMap() {
|
||||||
|
@ -28,21 +28,24 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Changes Viewport for move, fling, scale, rotation and tilt gestures.
|
* Changes Viewport by handling move, fling, scale, rotation and tilt gestures.
|
||||||
*/
|
*/
|
||||||
public class MapEventLayer extends Layer implements Map.InputListener, GestureListener {
|
public class MapEventLayer extends Layer implements Map.InputListener, GestureListener {
|
||||||
|
|
||||||
static final Logger log = LoggerFactory.getLogger(MapEventLayer.class);
|
static final Logger log = LoggerFactory.getLogger(MapEventLayer.class);
|
||||||
|
|
||||||
|
/* TODO replace with bitmasks */
|
||||||
private boolean mEnableRotate = true;
|
private boolean mEnableRotate = true;
|
||||||
private boolean mEnableTilt = true;
|
private boolean mEnableTilt = true;
|
||||||
private boolean mEnableMove = true;
|
private boolean mEnableMove = true;
|
||||||
private boolean mEnableScale = true;
|
private boolean mEnableScale = true;
|
||||||
|
|
||||||
|
/* possible state transitions */
|
||||||
private boolean mCanScale;
|
private boolean mCanScale;
|
||||||
private boolean mCanRotate;
|
private boolean mCanRotate;
|
||||||
private boolean mCanTilt;
|
private boolean mCanTilt;
|
||||||
|
|
||||||
|
/* current gesture state */
|
||||||
private boolean mDoRotate;
|
private boolean mDoRotate;
|
||||||
private boolean mDoScale;
|
private boolean mDoScale;
|
||||||
private boolean mDoTilt;
|
private boolean mDoTilt;
|
||||||
@ -185,8 +188,8 @@ public class MapEventLayer extends Layer implements Map.InputListener, GestureLi
|
|||||||
|
|
||||||
/* double-tap + hold */
|
/* double-tap + hold */
|
||||||
if (mDoubleTap) {
|
if (mDoubleTap) {
|
||||||
|
// FIXME limit scale properly
|
||||||
mViewport.scaleMap(1 - my / (height / 8), 0, 0);
|
mViewport.scaleMap(1 - my / (height / 6), 0, 0);
|
||||||
mMap.updateMap(true);
|
mMap.updateMap(true);
|
||||||
mStartMove = -1;
|
mStartMove = -1;
|
||||||
return true;
|
return true;
|
||||||
@ -275,7 +278,7 @@ public class MapEventLayer extends Layer implements Map.InputListener, GestureLi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (mDoScale && mEnableRotate) {
|
} else if (mDoScale && mEnableRotate) {
|
||||||
/* reenable rotation when higher threshold is reached */
|
/* re-enable rotation when higher threshold is reached */
|
||||||
double rad = Math.atan2(dy, dx);
|
double rad = Math.atan2(dy, dx);
|
||||||
double r = rad - mAngle;
|
double r = rad - mAngle;
|
||||||
|
|
||||||
@ -290,7 +293,7 @@ public class MapEventLayer extends Layer implements Map.InputListener, GestureLi
|
|||||||
if (mCanScale || mDoRotate) {
|
if (mCanScale || mDoRotate) {
|
||||||
|
|
||||||
if (!(mDoScale || mDoRotate)) {
|
if (!(mDoScale || mDoRotate)) {
|
||||||
/* enter exclusice scale mode */
|
/* enter exclusive scale mode */
|
||||||
if (Math.abs(deltaPinch) > (CanvasAdapter.dpi
|
if (Math.abs(deltaPinch) > (CanvasAdapter.dpi
|
||||||
/ MIN_SLOP * PINCH_ZOOM_THRESHOLD)) {
|
/ MIN_SLOP * PINCH_ZOOM_THRESHOLD)) {
|
||||||
|
|
||||||
@ -373,25 +376,26 @@ public class MapEventLayer extends Layer implements Map.InputListener, GestureLi
|
|||||||
int h = Tile.SIZE * 3;
|
int h = Tile.SIZE * 3;
|
||||||
|
|
||||||
mMap.animator().animateFling(Math.round(velocityX),
|
mMap.animator().animateFling(Math.round(velocityX),
|
||||||
Math.round(velocityY),
|
Math.round(velocityY),
|
||||||
-w, w, -h, h);
|
-w, w, -h, h);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onGesture(Gesture g, MotionEvent e) {
|
public boolean onGesture(Gesture g, MotionEvent e) {
|
||||||
if (g instanceof Gesture.DoubleTap) {
|
if (g == Gesture.DOUBLE_TAP) {
|
||||||
//mMapPosition.animateZoom(2);
|
|
||||||
// avoid onLongPress
|
|
||||||
// mMap.getLayers().cancelGesture();
|
|
||||||
mDoubleTap = true;
|
mDoubleTap = true;
|
||||||
|
mDown = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2011 See libgdx AUTHORS file.
|
* from libgdx:
|
||||||
|
* Copyright 2011 Mario Zechner <badlogicgames@gmail.com>
|
||||||
|
* Copyright 2011 Nathan Sweet <nathan.sweet@gmail.com>
|
||||||
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
|
Loading…
x
Reference in New Issue
Block a user