improve multitouch gesture detection
This commit is contained in:
parent
7c6ec614a2
commit
343a3bd1b3
@ -21,15 +21,12 @@ import org.oscim.overlay.OverlayManager;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.CountDownTimer;
|
import android.os.CountDownTimer;
|
||||||
import android.os.SystemClock;
|
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.GestureDetector;
|
import android.view.GestureDetector;
|
||||||
import android.view.GestureDetector.OnDoubleTapListener;
|
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.view.ScaleGestureDetector;
|
|
||||||
import android.view.ScaleGestureDetector.OnScaleGestureListener;
|
|
||||||
import android.view.animation.DecelerateInterpolator;
|
import android.view.animation.DecelerateInterpolator;
|
||||||
import android.widget.Scroller;
|
import android.widget.Scroller;
|
||||||
|
|
||||||
@ -40,12 +37,13 @@ import android.widget.Scroller;
|
|||||||
* - fix recognition of tilt/rotate/scale state...
|
* - fix recognition of tilt/rotate/scale state...
|
||||||
*/
|
*/
|
||||||
|
|
||||||
final class TouchHandler implements OnGestureListener, OnScaleGestureListener, OnDoubleTapListener {
|
final class TouchHandler implements OnGestureListener, OnDoubleTapListener {
|
||||||
|
//OnScaleGestureListener,
|
||||||
|
|
||||||
private static final String TAG = TouchHandler.class.getName();
|
private static final String TAG = TouchHandler.class.getName();
|
||||||
|
|
||||||
private static final float SCALE_DURATION = 500;
|
private static final float SCALE_DURATION = 500;
|
||||||
private static final float ROTATION_DELAY = 200; // ms
|
//private static final float ROTATION_DELAY = 200; // ms
|
||||||
|
|
||||||
private static final int INVALID_POINTER_ID = -1;
|
private static final int INVALID_POINTER_ID = -1;
|
||||||
|
|
||||||
@ -54,7 +52,7 @@ final class TouchHandler implements OnGestureListener, OnScaleGestureListener, O
|
|||||||
private final OverlayManager mOverlayManager;
|
private final OverlayManager mOverlayManager;
|
||||||
|
|
||||||
private final DecelerateInterpolator mInterpolator;
|
private final DecelerateInterpolator mInterpolator;
|
||||||
private final DecelerateInterpolator mLinearInterpolator;
|
//private final DecelerateInterpolator mLinearInterpolator;
|
||||||
private boolean mBeginScale;
|
private boolean mBeginScale;
|
||||||
private float mSumScale;
|
private float mSumScale;
|
||||||
|
|
||||||
@ -62,17 +60,28 @@ final class TouchHandler implements OnGestureListener, OnScaleGestureListener, O
|
|||||||
private boolean mBeginTilt;
|
private boolean mBeginTilt;
|
||||||
private boolean mLongPress;
|
private boolean mLongPress;
|
||||||
|
|
||||||
// private float mPosX;
|
private float mPrevX;
|
||||||
private float mPosY;
|
private float mPrevY;
|
||||||
|
|
||||||
|
private float mPrevX2;
|
||||||
|
private float mPrevY2;
|
||||||
|
|
||||||
private double mAngle;
|
private double mAngle;
|
||||||
|
|
||||||
private int mActivePointerId;
|
private int mActivePointerId;
|
||||||
|
|
||||||
private final ScaleGestureDetector mScaleGestureDetector;
|
//private final ScaleGestureDetector mScaleGestureDetector;
|
||||||
private final GestureDetector mGestureDetector;
|
private final GestureDetector mGestureDetector;
|
||||||
|
|
||||||
private final float dpi;
|
private final float dpi;
|
||||||
|
|
||||||
|
protected static final int JUMP_THRESHOLD = 100;
|
||||||
|
protected static final double PINCH_ZOOM_THRESHOLD = 5;
|
||||||
|
protected static final double PINCH_ROTATE_THRESHOLD = 0.02;
|
||||||
|
protected static final double PINCH_TILT_THRESHOLD = 0.002;
|
||||||
|
protected int mPrevPointerCount = 0;
|
||||||
|
protected double mPrevPinchWidth = -1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param context
|
* @param context
|
||||||
* the Context
|
* the Context
|
||||||
@ -86,14 +95,14 @@ final class TouchHandler implements OnGestureListener, OnScaleGestureListener, O
|
|||||||
// ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
|
// ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
|
||||||
// mMapMoveDelta = viewConfiguration.getScaledTouchSlop();
|
// mMapMoveDelta = viewConfiguration.getScaledTouchSlop();
|
||||||
mActivePointerId = INVALID_POINTER_ID;
|
mActivePointerId = INVALID_POINTER_ID;
|
||||||
mScaleGestureDetector = new ScaleGestureDetector(context, this);
|
//mScaleGestureDetector = new ScaleGestureDetector(context, this);
|
||||||
mGestureDetector = new GestureDetector(context, this);
|
mGestureDetector = new GestureDetector(context, this);
|
||||||
mGestureDetector.setOnDoubleTapListener(this);
|
mGestureDetector.setOnDoubleTapListener(this);
|
||||||
|
|
||||||
mInterpolator = new DecelerateInterpolator(2f);
|
mInterpolator = new DecelerateInterpolator(2f);
|
||||||
|
|
||||||
mScroller = new Scroller(mMapView.getContext(), mInterpolator);
|
mScroller = new Scroller(mMapView.getContext(), mInterpolator);
|
||||||
mLinearInterpolator = new DecelerateInterpolator(0.8f);//new android.view.animation.LinearInterpolator();
|
//mLinearInterpolator = new DecelerateInterpolator(0.8f);//new android.view.animation.LinearInterpolator();
|
||||||
|
|
||||||
DisplayMetrics metrics = mapView.getResources().getDisplayMetrics();
|
DisplayMetrics metrics = mapView.getResources().getDisplayMetrics();
|
||||||
dpi = metrics.xdpi;
|
dpi = metrics.xdpi;
|
||||||
@ -112,7 +121,7 @@ final class TouchHandler implements OnGestureListener, OnScaleGestureListener, O
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
mGestureDetector.onTouchEvent(event);
|
mGestureDetector.onTouchEvent(event);
|
||||||
mScaleGestureDetector.onTouchEvent(event);
|
//boolean scaling = false; //mScaleGestureDetector.onTouchEvent(event);
|
||||||
|
|
||||||
int action = getAction(event);
|
int action = getAction(event);
|
||||||
|
|
||||||
@ -149,106 +158,163 @@ final class TouchHandler implements OnGestureListener, OnScaleGestureListener, O
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean onActionDown(MotionEvent event) {
|
private boolean onActionDown(MotionEvent event) {
|
||||||
// mPosX = event.getX();
|
mPrevX = event.getX();
|
||||||
mPosY = event.getY();
|
mPrevY = event.getY();
|
||||||
|
|
||||||
// mMoveStart = false;
|
|
||||||
mBeginRotate = false;
|
mBeginRotate = false;
|
||||||
mBeginTilt = false;
|
mBeginTilt = false;
|
||||||
|
mBeginScale = false;
|
||||||
|
|
||||||
// save the ID of the pointer
|
// save the ID of the pointer
|
||||||
mActivePointerId = event.getPointerId(0);
|
mActivePointerId = event.getPointerId(0);
|
||||||
// Log.d("...", "set active pointer" + mActivePointerId);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean mScaling = false;
|
//private boolean mScaling = false;
|
||||||
|
|
||||||
private boolean onActionMove(MotionEvent event) {
|
private boolean onActionMove(MotionEvent event) {
|
||||||
int id = event.findPointerIndex(mActivePointerId);
|
int id = event.findPointerIndex(mActivePointerId);
|
||||||
|
|
||||||
float py = event.getY(id);
|
float x1 = event.getX(id);
|
||||||
float moveY = py - mPosY;
|
float y1 = event.getY(id);
|
||||||
mPosY = py;
|
|
||||||
|
float mx = x1 - mPrevX;
|
||||||
|
float my = y1 - mPrevY;
|
||||||
|
|
||||||
|
float width = mMapView.getWidth();
|
||||||
|
float height = mMapView.getHeight();
|
||||||
|
|
||||||
// double-tap + hold
|
// double-tap + hold
|
||||||
if (mLongPress) {
|
if (mLongPress) {
|
||||||
mMapPosition.scaleMap(1 - moveY / 100, 0, 0);
|
mMapPosition.scaleMap(1 - my / (height / 5), 0, 0);
|
||||||
mMapView.redrawMap(true);
|
mMapView.redrawMap(true);
|
||||||
|
|
||||||
|
mPrevX = x1;
|
||||||
|
mPrevY = y1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mMulti == 0)
|
// return if detect a new gesture, as indicated by a large jump
|
||||||
|
if (Math.abs(mx) > JUMP_THRESHOLD || Math.abs(my) > JUMP_THRESHOLD)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (event.getEventTime() - mMultiTouchDownTime < ROTATION_DELAY)
|
if (mMulti == 0) {
|
||||||
|
// reset pinch variables
|
||||||
|
mPrevPinchWidth = -1;
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
double x1 = event.getX(0);
|
float x2 = event.getX(1);
|
||||||
double x2 = event.getX(1);
|
float y2 = event.getY(1);
|
||||||
double y1 = event.getY(0);
|
|
||||||
double y2 = event.getY(1);
|
|
||||||
|
|
||||||
double dx = x1 - x2;
|
float dx = (x1 - x2);
|
||||||
double dy = y1 - y2;
|
float dy = (y1 - y2);
|
||||||
|
float slope = 0;
|
||||||
|
|
||||||
|
if (dx != 0)
|
||||||
|
slope = dy / dx;
|
||||||
|
|
||||||
|
double pinchWidth = Math.sqrt(dx * dx + dy * dy);
|
||||||
|
|
||||||
|
final double deltaPinchWidth = pinchWidth - mPrevPinchWidth;
|
||||||
|
|
||||||
double rad = Math.atan2(dy, dx);
|
double rad = Math.atan2(dy, dx);
|
||||||
double r = rad - mAngle;
|
double r = rad - mAngle;
|
||||||
|
|
||||||
if (!mBeginRotate && !mBeginScale) {
|
boolean startScale = (mPrevPinchWidth > 0 && Math.abs(deltaPinchWidth) > PINCH_ZOOM_THRESHOLD);
|
||||||
/* our naive gesture detector for rotation and tilt.. */
|
|
||||||
|
|
||||||
if (Math.abs(rad) < 0.30 || Math.abs(rad) > Math.PI - 0.30) {
|
boolean changed = false;
|
||||||
|
|
||||||
|
if (!mBeginTilt && (mBeginScale || startScale)) {
|
||||||
|
mBeginScale = true;
|
||||||
|
|
||||||
|
float scale = (float) (pinchWidth / mPrevPinchWidth);
|
||||||
|
|
||||||
|
mSumScale *= scale;
|
||||||
|
|
||||||
|
if (mSumScale < 0.95 || mSumScale > 1.05) {
|
||||||
|
mBeginRotate = false;
|
||||||
|
}
|
||||||
|
float fx = (x2 + x1) / 2 - width / 2;
|
||||||
|
float fy = (y2 + y1) / 2 - height / 2;
|
||||||
|
|
||||||
|
//Log.d(TAG, "zoom " + deltaPinchWidth + " " + scale + " " + mSumScale);
|
||||||
|
changed = mMapPosition.scaleMap(scale, fx, fy);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mBeginScale && !mBeginRotate && Math.abs(slope) < 2) {
|
||||||
|
// normalize dx, dy with screen width and height, so they are in [0, 1]
|
||||||
|
// final double xVelocity = dx / width;
|
||||||
|
float my2 = y2 - mPrevY2;
|
||||||
|
final double yVelocity = my / height;
|
||||||
|
final double yVelocity2 = my2 / height;
|
||||||
|
|
||||||
|
if ((yVelocity > PINCH_TILT_THRESHOLD && yVelocity2 > PINCH_TILT_THRESHOLD)
|
||||||
|
|| (yVelocity < -PINCH_TILT_THRESHOLD && yVelocity2 < -PINCH_TILT_THRESHOLD))
|
||||||
|
{
|
||||||
mBeginTilt = true;
|
mBeginTilt = true;
|
||||||
if (mMapPosition.tilt(moveY / 4)) {
|
changed = mMapPosition.tilt(my / 5);
|
||||||
mMapView.redrawMap(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!mBeginTilt) {
|
if (!mBeginTilt && (mBeginRotate || Math.abs(r) > PINCH_ROTATE_THRESHOLD)) {
|
||||||
if (Math.abs(r) > 0.05) {
|
//Log.d(TAG, "rotate: " + mBeginRotate + " " + Math.toDegrees(rad));
|
||||||
// Log.d(TAG, "begin rotate");
|
if (!mBeginRotate) {
|
||||||
mAngle = rad;
|
mAngle = rad;
|
||||||
mBeginRotate = true;
|
mSumScale = 1;
|
||||||
|
mBeginRotate = true;
|
||||||
|
|
||||||
|
mFocusX = (width / 2) - (x1 + x2) / 2;
|
||||||
|
mFocusY = (height / 2) - (y1 + y2) / 2;
|
||||||
|
} else {
|
||||||
|
double da = rad - mAngle;
|
||||||
|
|
||||||
|
if (Math.abs(da) > 0.01) {
|
||||||
|
double rsin = Math.sin(r);
|
||||||
|
double rcos = Math.cos(r);
|
||||||
|
float x = (float) (mFocusX * rcos + mFocusY * -rsin - mFocusX);
|
||||||
|
float y = (float) (mFocusX * rsin + mFocusY * rcos - mFocusY);
|
||||||
|
|
||||||
|
mMapPosition.rotateMap((float) Math.toDegrees(da), x, y);
|
||||||
|
|
||||||
|
changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mBeginRotate) {
|
if (changed)
|
||||||
double rsin = Math.sin(r);
|
|
||||||
double rcos = Math.cos(r);
|
|
||||||
|
|
||||||
// focus point relative to center
|
|
||||||
double cx = (mMapView.getWidth() >> 1) - (x1 + x2) / 2;
|
|
||||||
double cy = (mMapView.getHeight() >> 1) - (y1 + y2) / 2;
|
|
||||||
|
|
||||||
float x = (float) (cx * rcos + cy * -rsin - cx);
|
|
||||||
float y = (float) (cx * rsin + cy * rcos - cy);
|
|
||||||
|
|
||||||
mMapPosition.rotateMap((float) Math.toDegrees(rad - mAngle), x, y);
|
|
||||||
mAngle = rad;
|
|
||||||
mMapView.redrawMap(true);
|
mMapView.redrawMap(true);
|
||||||
}
|
|
||||||
|
mPrevX = x1;
|
||||||
|
mPrevY = y1;
|
||||||
|
mPrevX2 = x2;
|
||||||
|
mPrevY2 = y2;
|
||||||
|
|
||||||
|
mPrevPinchWidth = pinchWidth;
|
||||||
|
mAngle = rad;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int mMulti = 0;
|
private int mMulti = 0;
|
||||||
private boolean mWasMulti;
|
private boolean mWasMulti;
|
||||||
private long mMultiTouchDownTime;
|
|
||||||
|
// private long mMultiTouchDownTime;
|
||||||
|
|
||||||
private boolean onActionPointerDown(MotionEvent event) {
|
private boolean onActionPointerDown(MotionEvent event) {
|
||||||
|
// mMultiTouchDownTime = event.getEventTime();
|
||||||
mMultiTouchDownTime = event.getEventTime();
|
|
||||||
|
|
||||||
mMulti++;
|
mMulti++;
|
||||||
mWasMulti = true;
|
mWasMulti = true;
|
||||||
|
mSumScale = 1;
|
||||||
|
|
||||||
if (mMulti == 1) {
|
if (mMulti == 1) {
|
||||||
double dx = event.getX(0) - event.getX(1);
|
mPrevX2 = event.getX(1);
|
||||||
double dy = event.getY(0) - event.getY(1);
|
mPrevY2 = event.getY(1);
|
||||||
|
|
||||||
|
double dx = event.getX(0) - mPrevX2;
|
||||||
|
double dy = event.getY(0) - mPrevY2;
|
||||||
mAngle = Math.atan2(dy, dx);
|
mAngle = Math.atan2(dy, dx);
|
||||||
}
|
}
|
||||||
// Log.d("...", "mMulti down " + mMulti);
|
// Log.d("...", "mMulti down " + mMulti);
|
||||||
@ -269,13 +335,14 @@ final class TouchHandler implements OnGestureListener, OnScaleGestureListener, O
|
|||||||
pointerIndex = 0;
|
pointerIndex = 0;
|
||||||
}
|
}
|
||||||
// save the position of the event
|
// save the position of the event
|
||||||
// mPosX = motionEvent.getX(pointerIndex);
|
// mPrevX = motionEvent.getX(pointerIndex);
|
||||||
mPosY = motionEvent.getY(pointerIndex);
|
mPrevY = motionEvent.getY(pointerIndex);
|
||||||
mActivePointerId = motionEvent.getPointerId(pointerIndex);
|
mActivePointerId = motionEvent.getPointerId(pointerIndex);
|
||||||
}
|
}
|
||||||
mMulti--;
|
mMulti--;
|
||||||
|
|
||||||
mLongPress = false;
|
mLongPress = false;
|
||||||
|
|
||||||
// Log.d("...", "mMulti up " + mMulti);
|
// Log.d("...", "mMulti up " + mMulti);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -288,11 +355,14 @@ final class TouchHandler implements OnGestureListener, OnScaleGestureListener, O
|
|||||||
*/
|
*/
|
||||||
private boolean onActionUp(MotionEvent motionEvent) {
|
private boolean onActionUp(MotionEvent motionEvent) {
|
||||||
mActivePointerId = INVALID_POINTER_ID;
|
mActivePointerId = INVALID_POINTER_ID;
|
||||||
mScaling = false;
|
//mScaling = false;
|
||||||
mLongPress = false;
|
mLongPress = false;
|
||||||
|
|
||||||
mMulti = 0;
|
mMulti = 0;
|
||||||
|
|
||||||
|
mPrevPinchWidth = -1;
|
||||||
|
mPrevPointerCount = 0;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -353,8 +423,8 @@ final class TouchHandler implements OnGestureListener, OnScaleGestureListener, O
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mScaling)
|
// if (mScaling)
|
||||||
return true;
|
// return true;
|
||||||
|
|
||||||
if (mMulti == 0) {
|
if (mMulti == 0) {
|
||||||
mMapPosition.moveMap(-distanceX, -distanceY);
|
mMapPosition.moveMap(-distanceX, -distanceY);
|
||||||
@ -368,9 +438,12 @@ final class TouchHandler implements OnGestureListener, OnScaleGestureListener, O
|
|||||||
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
|
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
|
||||||
float velocityY) {
|
float velocityY) {
|
||||||
|
|
||||||
if (mScaling || mWasMulti)
|
if (mWasMulti)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
// if (mScaling || mWasMulti)
|
||||||
|
// return true;
|
||||||
|
|
||||||
int w = Tile.TILE_SIZE * 6;
|
int w = Tile.TILE_SIZE * 6;
|
||||||
int h = Tile.TILE_SIZE * 6;
|
int h = Tile.TILE_SIZE * 6;
|
||||||
mScrollX = 0;
|
mScrollX = 0;
|
||||||
@ -474,118 +547,119 @@ final class TouchHandler implements OnGestureListener, OnScaleGestureListener, O
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************* ScaleListener *******************/
|
// /******************* ScaleListener *******************/
|
||||||
private float mCenterX;
|
|
||||||
private float mCenterY;
|
|
||||||
private float mFocusX;
|
|
||||||
private float mFocusY;
|
|
||||||
private long mTimeStart;
|
|
||||||
private long mTimeEnd;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onScale(ScaleGestureDetector gd) {
|
|
||||||
|
|
||||||
if (mBeginTilt)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
float scale = gd.getScaleFactor();
|
|
||||||
mFocusX = gd.getFocusX() - mCenterX;
|
|
||||||
mFocusY = gd.getFocusY() - mCenterY;
|
|
||||||
|
|
||||||
mSumScale *= scale;
|
|
||||||
|
|
||||||
mTimeEnd = SystemClock.elapsedRealtime();
|
|
||||||
|
|
||||||
if (!mBeginScale) {
|
|
||||||
if (mSumScale > 1.1 || mSumScale < 0.9) {
|
|
||||||
// Log.d("...", "begin scale " + mSumScale);
|
|
||||||
mBeginScale = true;
|
|
||||||
// scale = mSumScale;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mBeginScale && mMapPosition.scaleMap(scale, mFocusX, mFocusY))
|
|
||||||
mMapView.redrawMap(true);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onScaleBegin(ScaleGestureDetector gd) {
|
|
||||||
mScaling = true;
|
|
||||||
mBeginScale = false;
|
|
||||||
|
|
||||||
mTimeEnd = mTimeStart = SystemClock.elapsedRealtime();
|
|
||||||
mSumScale = 1;
|
|
||||||
mCenterX = mMapView.getWidth() >> 1;
|
|
||||||
mCenterY = mMapView.getHeight() >> 1;
|
|
||||||
|
|
||||||
if (mTimer != null) {
|
|
||||||
mTimer.cancel();
|
|
||||||
mTimer = null;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onScaleEnd(ScaleGestureDetector gd) {
|
|
||||||
// Log.d("ScaleListener", "Sum " + mSumScale + " " + (mTimeEnd -
|
|
||||||
// mTimeStart));
|
|
||||||
|
|
||||||
if (mTimer == null && mTimeEnd - mTimeStart < 150
|
|
||||||
&& (mSumScale < 0.99 || mSumScale > 1.01)) {
|
|
||||||
|
|
||||||
mPrevScale = 0;
|
|
||||||
|
|
||||||
mZooutOut = mSumScale < 0.99;
|
|
||||||
|
|
||||||
mTimer = new CountDownTimer((int) SCALE_DURATION, 32) {
|
|
||||||
@Override
|
|
||||||
public void onTick(long tick) {
|
|
||||||
scaleAnim(tick);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFinish() {
|
|
||||||
scaleAnim(0);
|
|
||||||
}
|
|
||||||
}.start();
|
|
||||||
} else {
|
|
||||||
mScaling = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
mBeginScale = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private float mPrevScale;
|
private float mPrevScale;
|
||||||
private CountDownTimer mTimer;
|
private CountDownTimer mTimer;
|
||||||
boolean mZooutOut;
|
boolean mZooutOut;
|
||||||
|
// private float mCenterX;
|
||||||
|
// private float mCenterY;
|
||||||
|
private float mFocusX;
|
||||||
|
private float mFocusY;
|
||||||
|
// private long mTimeStart;
|
||||||
|
// private long mTimeEnd;
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public boolean onScale(ScaleGestureDetector gd) {
|
||||||
|
//
|
||||||
|
// if (mBeginTilt)
|
||||||
|
// return true;
|
||||||
|
//
|
||||||
|
// float scale = gd.getScaleFactor();
|
||||||
|
// mFocusX = gd.getFocusX() - mCenterX;
|
||||||
|
// mFocusY = gd.getFocusY() - mCenterY;
|
||||||
|
//
|
||||||
|
// mSumScale *= scale;
|
||||||
|
//
|
||||||
|
// mTimeEnd = SystemClock.elapsedRealtime();
|
||||||
|
//
|
||||||
|
// if (!mBeginScale) {
|
||||||
|
// if (mSumScale > 1.1 || mSumScale < 0.9) {
|
||||||
|
// // Log.d("...", "begin scale " + mSumScale);
|
||||||
|
// mBeginScale = true;
|
||||||
|
// // scale = mSumScale;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (mBeginScale && mMapPosition.scaleMap(scale, mFocusX, mFocusY))
|
||||||
|
// mMapView.redrawMap(true);
|
||||||
|
//
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public boolean onScaleBegin(ScaleGestureDetector gd) {
|
||||||
|
// mScaling = true;
|
||||||
|
// mBeginScale = false;
|
||||||
|
//
|
||||||
|
// mTimeEnd = mTimeStart = SystemClock.elapsedRealtime();
|
||||||
|
// mSumScale = 1;
|
||||||
|
// mCenterX = mMapView.getWidth() >> 1;
|
||||||
|
// mCenterY = mMapView.getHeight() >> 1;
|
||||||
|
//
|
||||||
|
// if (mTimer != null) {
|
||||||
|
// mTimer.cancel();
|
||||||
|
// mTimer = null;
|
||||||
|
// }
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public void onScaleEnd(ScaleGestureDetector gd) {
|
||||||
|
// // Log.d("ScaleListener", "Sum " + mSumScale + " " + (mTimeEnd -
|
||||||
|
// // mTimeStart));
|
||||||
|
//
|
||||||
|
// if (mTimer == null && mTimeEnd - mTimeStart < 150
|
||||||
|
// && (mSumScale < 0.99 || mSumScale > 1.01)) {
|
||||||
|
//
|
||||||
|
// mPrevScale = 0;
|
||||||
|
//
|
||||||
|
// mZooutOut = mSumScale < 0.99;
|
||||||
|
//
|
||||||
|
// mTimer = new CountDownTimer((int) SCALE_DURATION, 32) {
|
||||||
|
// @Override
|
||||||
|
// public void onTick(long tick) {
|
||||||
|
// scaleAnim(tick);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public void onFinish() {
|
||||||
|
// scaleAnim(0);
|
||||||
|
// }
|
||||||
|
// }.start();
|
||||||
|
// } else {
|
||||||
|
// mScaling = false;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// mBeginScale = false;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
|
||||||
boolean scaleAnim(long tick) {
|
//
|
||||||
|
// boolean scaleAnim(long tick) {
|
||||||
if (mPrevScale >= 1) {
|
//
|
||||||
mTimer = null;
|
// if (mPrevScale >= 1) {
|
||||||
return false;
|
// mTimer = null;
|
||||||
}
|
// return false;
|
||||||
|
// }
|
||||||
float adv = (SCALE_DURATION - tick) / SCALE_DURATION;
|
//
|
||||||
// adv = mInterpolator.getInterpolation(adv);
|
// float adv = (SCALE_DURATION - tick) / SCALE_DURATION;
|
||||||
adv = mLinearInterpolator.getInterpolation(adv);
|
// // adv = mInterpolator.getInterpolation(adv);
|
||||||
|
// adv = mLinearInterpolator.getInterpolation(adv);
|
||||||
float scale = adv - mPrevScale;
|
//
|
||||||
mPrevScale += scale;
|
// float scale = adv - mPrevScale;
|
||||||
|
// mPrevScale += scale;
|
||||||
if (mZooutOut) {
|
//
|
||||||
mMapPosition.scaleMap(1 - scale, 0, 0);
|
// if (mZooutOut) {
|
||||||
} else {
|
// mMapPosition.scaleMap(1 - scale, 0, 0);
|
||||||
mMapPosition.scaleMap(1 + scale, mFocusX, mFocusY);
|
// } else {
|
||||||
}
|
// mMapPosition.scaleMap(1 + scale, mFocusX, mFocusY);
|
||||||
|
// }
|
||||||
mMapView.redrawMap(true);
|
//
|
||||||
|
// mMapView.redrawMap(true);
|
||||||
if (tick == 0)
|
//
|
||||||
mTimer = null;
|
// if (tick == 0)
|
||||||
|
// mTimer = null;
|
||||||
return true;
|
//
|
||||||
}
|
// return true;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user