merge ScaleListener into TouchHandler
This commit is contained in:
parent
026a0674cd
commit
17ae9fe098
@ -22,7 +22,6 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
|
||||||
import org.mapsforge.android.input.TouchHandler;
|
|
||||||
import org.mapsforge.android.mapgenerator.IMapGenerator;
|
import org.mapsforge.android.mapgenerator.IMapGenerator;
|
||||||
import org.mapsforge.android.mapgenerator.JobQueue;
|
import org.mapsforge.android.mapgenerator.JobQueue;
|
||||||
import org.mapsforge.android.mapgenerator.MapDatabaseFactory;
|
import org.mapsforge.android.mapgenerator.MapDatabaseFactory;
|
||||||
@ -75,7 +74,7 @@ public class MapView extends GLSurfaceView {
|
|||||||
*/
|
*/
|
||||||
public static final InternalRenderTheme DEFAULT_RENDER_THEME = InternalRenderTheme.OSMARENDER;
|
public static final InternalRenderTheme DEFAULT_RENDER_THEME = InternalRenderTheme.OSMARENDER;
|
||||||
|
|
||||||
private static final float DEFAULT_TEXT_SCALE = 1;
|
// private static final float DEFAULT_TEXT_SCALE = 1;
|
||||||
private static final Byte DEFAULT_START_ZOOM_LEVEL = Byte.valueOf((byte) 16);
|
private static final Byte DEFAULT_START_ZOOM_LEVEL = Byte.valueOf((byte) 16);
|
||||||
|
|
||||||
public final static boolean debugFrameTime = false;
|
public final static boolean debugFrameTime = false;
|
||||||
|
|||||||
@ -12,14 +12,13 @@
|
|||||||
* You should have received a copy of the GNU Lesser General Public License along with
|
* You should have received a copy of the GNU Lesser General Public License along with
|
||||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.mapsforge.android.input;
|
package org.mapsforge.android;
|
||||||
|
|
||||||
import org.mapsforge.android.MapView;
|
|
||||||
import org.mapsforge.android.MapViewPosition;
|
|
||||||
import org.mapsforge.core.Tile;
|
import org.mapsforge.core.Tile;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.CountDownTimer;
|
import android.os.CountDownTimer;
|
||||||
|
import android.os.SystemClock;
|
||||||
import android.view.GestureDetector;
|
import android.view.GestureDetector;
|
||||||
import android.view.GestureDetector.SimpleOnGestureListener;
|
import android.view.GestureDetector.SimpleOnGestureListener;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
@ -34,8 +33,8 @@ import android.widget.Scroller;
|
|||||||
public class TouchHandler {
|
public class TouchHandler {
|
||||||
private static final int INVALID_POINTER_ID = -1;
|
private static final int INVALID_POINTER_ID = -1;
|
||||||
|
|
||||||
protected final MapView mMapView;
|
/* package */final MapView mMapView;
|
||||||
protected final MapViewPosition mMapPosition;
|
/* package */final MapViewPosition mMapPosition;
|
||||||
|
|
||||||
private final float mMapMoveDelta;
|
private final float mMapMoveDelta;
|
||||||
private boolean mMoveThresholdReached;
|
private boolean mMoveThresholdReached;
|
||||||
@ -60,9 +59,8 @@ public class TouchHandler {
|
|||||||
mMapPosition = mapView.getMapPosition();
|
mMapPosition = mapView.getMapPosition();
|
||||||
mMapMoveDelta = viewConfiguration.getScaledTouchSlop();
|
mMapMoveDelta = viewConfiguration.getScaledTouchSlop();
|
||||||
mActivePointerId = INVALID_POINTER_ID;
|
mActivePointerId = INVALID_POINTER_ID;
|
||||||
mScaleGestureDetector = new ScaleGestureDetector(context, new ScaleListener(
|
mScaleGestureDetector = new ScaleGestureDetector(context, new ScaleListener());
|
||||||
mMapView));
|
mGestureDetector = new GestureDetector(context, new MapGestureDetector());
|
||||||
mGestureDetector = new GestureDetector(context, new MapGestureDetector(mMapView));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,8 +228,8 @@ public class TouchHandler {
|
|||||||
private CountDownTimer mTimer = null;
|
private CountDownTimer mTimer = null;
|
||||||
private boolean fling = false;
|
private boolean fling = false;
|
||||||
|
|
||||||
public MapGestureDetector(MapView mapView) {
|
public MapGestureDetector() {
|
||||||
mScroller = new Scroller(mapView.getContext(),
|
mScroller = new Scroller(mMapView.getContext(),
|
||||||
new android.view.animation.LinearInterpolator());
|
new android.view.animation.LinearInterpolator());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,4 +353,114 @@ public class TouchHandler {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ScaleListener implements ScaleGestureDetector.OnScaleGestureListener {
|
||||||
|
private float mCenterX;
|
||||||
|
private float mCenterY;
|
||||||
|
private float mFocusX;
|
||||||
|
private float mFocusY;
|
||||||
|
private float mScale;
|
||||||
|
private boolean mBeginScale;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onScale(ScaleGestureDetector gd) {
|
||||||
|
|
||||||
|
mScale = gd.getScaleFactor();
|
||||||
|
mFocusX = gd.getFocusX() - mCenterX;
|
||||||
|
mFocusY = gd.getFocusY() - mCenterY;
|
||||||
|
|
||||||
|
mSumScale *= mScale;
|
||||||
|
|
||||||
|
mTimeEnd = SystemClock.elapsedRealtime();
|
||||||
|
|
||||||
|
if (!mBeginScale) {
|
||||||
|
if (mTimeEnd - mTimeStart > 100) {
|
||||||
|
mBeginScale = true;
|
||||||
|
mScale = mSumScale;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
mMapPosition.scaleMap(mScale, mFocusX, mFocusY);
|
||||||
|
mMapView.redrawTiles();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private long mTimeStart;
|
||||||
|
private long mTimeEnd;
|
||||||
|
private float mSumScale;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onScaleBegin(ScaleGestureDetector gd) {
|
||||||
|
mTimeEnd = mTimeStart = SystemClock.elapsedRealtime();
|
||||||
|
mSumScale = 1;
|
||||||
|
mBeginScale = false;
|
||||||
|
mCenterX = mMapView.getWidth() >> 1;
|
||||||
|
mCenterY = mMapView.getHeight() >> 1;
|
||||||
|
mScale = 1;
|
||||||
|
// mMapPosition = mMapView.getMapPosition();
|
||||||
|
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) mScaleDuration, 30) {
|
||||||
|
@Override
|
||||||
|
public void onTick(long tick) {
|
||||||
|
scale(tick);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFinish() {
|
||||||
|
scale(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
}.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private DecelerateInterpolator mBounce = new DecelerateInterpolator();
|
||||||
|
private float mPrevScale;
|
||||||
|
private CountDownTimer mTimer;
|
||||||
|
boolean mZooutOut;
|
||||||
|
private final float mScaleDuration = 350;
|
||||||
|
|
||||||
|
boolean scale(long tick) {
|
||||||
|
|
||||||
|
if (mPrevScale >= 1) {
|
||||||
|
mTimer = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
float adv = (mScaleDuration - tick) / mScaleDuration;
|
||||||
|
adv = mBounce.getInterpolation(adv);
|
||||||
|
|
||||||
|
float scale = adv - mPrevScale;
|
||||||
|
mPrevScale += scale;
|
||||||
|
|
||||||
|
if (mZooutOut) {
|
||||||
|
mMapPosition.scaleMap(1 - scale, 0, 0);
|
||||||
|
} else {
|
||||||
|
mMapPosition.scaleMap(1 + scale, mFocusX, mFocusY);
|
||||||
|
}
|
||||||
|
|
||||||
|
mMapView.redrawTiles();
|
||||||
|
|
||||||
|
if (tick == 0)
|
||||||
|
mTimer = null;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -1,146 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify it under the
|
|
||||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
|
||||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
||||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
||||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License along with
|
|
||||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package org.mapsforge.android.input;
|
|
||||||
|
|
||||||
import org.mapsforge.android.MapView;
|
|
||||||
import org.mapsforge.android.MapViewPosition;
|
|
||||||
|
|
||||||
import android.os.CountDownTimer;
|
|
||||||
import android.os.SystemClock;
|
|
||||||
import android.view.ScaleGestureDetector;
|
|
||||||
import android.view.animation.DecelerateInterpolator;
|
|
||||||
|
|
||||||
class ScaleListener implements ScaleGestureDetector.OnScaleGestureListener {
|
|
||||||
private final MapView mMapView;
|
|
||||||
private MapViewPosition mMapPosition;
|
|
||||||
private float mCenterX;
|
|
||||||
private float mCenterY;
|
|
||||||
private float mFocusX;
|
|
||||||
private float mFocusY;
|
|
||||||
private float mScale;
|
|
||||||
private boolean mBeginScale;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new ScaleListener for the given MapView.
|
|
||||||
*
|
|
||||||
* @param mapView
|
|
||||||
* the MapView which should be scaled.
|
|
||||||
*/
|
|
||||||
ScaleListener(MapView mapView) {
|
|
||||||
mMapView = mapView;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onScale(ScaleGestureDetector gd) {
|
|
||||||
|
|
||||||
mScale = gd.getScaleFactor();
|
|
||||||
mFocusX = gd.getFocusX() - mCenterX;
|
|
||||||
mFocusY = gd.getFocusY() - mCenterY;
|
|
||||||
|
|
||||||
mSumScale *= mScale;
|
|
||||||
|
|
||||||
mTimeEnd = SystemClock.elapsedRealtime();
|
|
||||||
|
|
||||||
if (!mBeginScale) {
|
|
||||||
if (mTimeEnd - mTimeStart > 100) {
|
|
||||||
mBeginScale = true;
|
|
||||||
mScale = mSumScale;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
mMapPosition.scaleMap(mScale, mFocusX, mFocusY);
|
|
||||||
mMapView.redrawTiles();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private long mTimeStart;
|
|
||||||
private long mTimeEnd;
|
|
||||||
private float mSumScale;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onScaleBegin(ScaleGestureDetector gd) {
|
|
||||||
mTimeEnd = mTimeStart = SystemClock.elapsedRealtime();
|
|
||||||
mSumScale = 1;
|
|
||||||
mBeginScale = false;
|
|
||||||
mCenterX = mMapView.getWidth() >> 1;
|
|
||||||
mCenterY = mMapView.getHeight() >> 1;
|
|
||||||
mScale = 1;
|
|
||||||
mMapPosition = mMapView.getMapPosition();
|
|
||||||
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) mScaleDuration, 30) {
|
|
||||||
@Override
|
|
||||||
public void onTick(long tick) {
|
|
||||||
scale(tick);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFinish() {
|
|
||||||
scale(0);
|
|
||||||
|
|
||||||
}
|
|
||||||
}.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private DecelerateInterpolator mBounce = new DecelerateInterpolator();
|
|
||||||
private float mPrevScale;
|
|
||||||
private CountDownTimer mTimer;
|
|
||||||
boolean mZooutOut;
|
|
||||||
private final float mScaleDuration = 350;
|
|
||||||
|
|
||||||
boolean scale(long tick) {
|
|
||||||
|
|
||||||
if (mPrevScale >= 1) {
|
|
||||||
mTimer = null;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
float adv = (mScaleDuration - tick) / mScaleDuration;
|
|
||||||
adv = mBounce.getInterpolation(adv);
|
|
||||||
|
|
||||||
float scale = adv - mPrevScale;
|
|
||||||
mPrevScale += scale;
|
|
||||||
|
|
||||||
if (mZooutOut) {
|
|
||||||
mMapPosition.scaleMap(1 - scale, 0, 0);
|
|
||||||
} else {
|
|
||||||
mMapPosition.scaleMap(1 + scale, mFocusX, mFocusY);
|
|
||||||
}
|
|
||||||
|
|
||||||
mMapView.redrawTiles();
|
|
||||||
|
|
||||||
if (tick == 0)
|
|
||||||
mTimer = null;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user