- extracted MapEventLayer from TouchHandler
- rename OverlayManager to LayerManager - move event-dispatching from TouchHandler to LayerManager
This commit is contained in:
parent
3c26515d4d
commit
5862ae4e7d
@ -14,11 +14,8 @@
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// Created by plusminus on 20:32:01 - 27.09.2008
|
||||
package org.oscim.overlay;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.core.PointF;
|
||||
import org.oscim.renderer.overlays.RenderOverlay;
|
||||
@ -30,11 +27,10 @@ import android.view.MotionEvent;
|
||||
/**
|
||||
* Base class representing an overlay which may be displayed on top of a
|
||||
* {@link MapView}. To add an overlay, subclass this class, create an instance,
|
||||
* and add it to the list obtained from getOverlays() of {@link MapView}. This
|
||||
* class implements a form of Gesture Handling similar to
|
||||
* and add via addOverlay() of {@link MapView}.
|
||||
* This class implements a form of Gesture Handling similar to
|
||||
* {@link android.view.GestureDetector.SimpleOnGestureListener} and
|
||||
* GestureDetector.OnGestureListener. The difference is there is an additional
|
||||
* argument for the item.
|
||||
* GestureDetector.OnGestureListener.
|
||||
*
|
||||
* @author Nicolas Gramlich
|
||||
*/
|
||||
@ -44,24 +40,22 @@ public abstract class Overlay {
|
||||
// Constants
|
||||
// ===========================================================
|
||||
|
||||
private static AtomicInteger sOrdinal = new AtomicInteger();
|
||||
//private static AtomicInteger sOrdinal = new AtomicInteger();
|
||||
|
||||
// From Google Maps API
|
||||
protected static final float SHADOW_X_SKEW = -0.8999999761581421f;
|
||||
protected static final float SHADOW_Y_SCALE = 0.5f;
|
||||
//protected static final float SHADOW_X_SKEW = -0.8999999761581421f;
|
||||
//protected static final float SHADOW_Y_SCALE = 0.5f;
|
||||
|
||||
// ===========================================================
|
||||
// Fields
|
||||
// ===========================================================
|
||||
|
||||
//protected final ResourceProxy mResourceProxy;
|
||||
//protected final float mScale;
|
||||
|
||||
// private static final Rect mRect = new Rect();
|
||||
private boolean mEnabled = true;
|
||||
private boolean mReceiveEvents = true;
|
||||
|
||||
protected final MapView mMapView;
|
||||
|
||||
/** RenderOverlay used to draw this layer. To be implemented by sub-classes */
|
||||
protected RenderOverlay mLayer;
|
||||
|
||||
public RenderOverlay getLayer() {
|
||||
@ -87,8 +81,8 @@ public abstract class Overlay {
|
||||
* @param pEnabled
|
||||
* ...
|
||||
*/
|
||||
public void setEnabled(final boolean pEnabled) {
|
||||
this.mEnabled = pEnabled;
|
||||
public void setEnabled(boolean pEnabled) {
|
||||
mEnabled = pEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -98,62 +92,76 @@ public abstract class Overlay {
|
||||
* @return true if the Overlay is marked enabled, false otherwise
|
||||
*/
|
||||
public boolean isEnabled() {
|
||||
return this.mEnabled;
|
||||
return mEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Since the menu-chain will pass through several independent Overlays, menu
|
||||
* IDs cannot be fixed at compile time. Overlays should use this method to
|
||||
* obtain and store a menu id for each menu item at construction time. This
|
||||
* will ensure that two overlays don't use the same id.
|
||||
* Sets whether the Overlay is marked to be receive touch exents.
|
||||
*
|
||||
* @return an integer suitable to be used as a menu identifier
|
||||
* @param pEnabled
|
||||
* ...
|
||||
*/
|
||||
protected final static int getSafeMenuId() {
|
||||
return sOrdinal.getAndIncrement();
|
||||
public void setEnableEvents(boolean pEnabled) {
|
||||
mReceiveEvents = pEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to <see cref="getSafeMenuId" />, except this reserves a sequence
|
||||
* of IDs of length <param name="count" />. The returned number is the
|
||||
* starting index of that sequential list.
|
||||
* Specifies if the Overlay is marked to be enabled. This should be checked
|
||||
* before calling draw().
|
||||
*
|
||||
* @param count
|
||||
* ....
|
||||
* @return an integer suitable to be used as a menu identifier
|
||||
* @return true if the Overlay is marked enabled, false otherwise
|
||||
*/
|
||||
protected final static int getSafeMenuIdSequence(final int count) {
|
||||
return sOrdinal.getAndAdd(count);
|
||||
public boolean eventsEnabled() {
|
||||
return mReceiveEvents;
|
||||
}
|
||||
|
||||
// ===========================================================
|
||||
// Methods for SuperClass/Interfaces
|
||||
// ===========================================================
|
||||
|
||||
// /**
|
||||
// * Draw the overlay over the map. This will be called on all active overlays
|
||||
// * with shadow=true, to lay down the shadow layer, and then again on all
|
||||
// * overlays with shadow=false. Callers should check isEnabled() before
|
||||
// * calling draw(). By default, draws nothing.
|
||||
// *
|
||||
// * @param c
|
||||
// * ...
|
||||
// * @param osmv
|
||||
// * ...
|
||||
// * @param shadow
|
||||
// * ...
|
||||
// */
|
||||
// protected abstract void draw(final Canvas c, final MapView osmv, final boolean shadow);
|
||||
///**
|
||||
// * Since the menu-chain will pass through several independent Overlays, menu
|
||||
// * IDs cannot be fixed at compile time. Overlays should use this method to
|
||||
// * obtain and store a menu id for each menu item at construction time. This
|
||||
// * will ensure that two overlays don't use the same id.
|
||||
// *
|
||||
// * @return an integer suitable to be used as a menu identifier
|
||||
// */
|
||||
//protected final static int getSafeMenuId() {
|
||||
// return sOrdinal.getAndIncrement();
|
||||
//}
|
||||
//
|
||||
///**
|
||||
// * Similar to <see cref="getSafeMenuId" />, except this reserves a sequence
|
||||
// * of IDs of length <param name="count" />. The returned number is the
|
||||
// * starting index of that sequential list.
|
||||
// *
|
||||
// * @param count
|
||||
// * ....
|
||||
// * @return an integer suitable to be used as a menu identifier
|
||||
// */
|
||||
//protected final static int getSafeMenuIdSequence(int count) {
|
||||
// return sOrdinal.getAndAdd(count);
|
||||
//}
|
||||
|
||||
// ===========================================================
|
||||
// Methods
|
||||
// ===========================================================
|
||||
|
||||
/**
|
||||
* Called before each frame render request.
|
||||
*
|
||||
* @param mapPosition
|
||||
* current MapPosition
|
||||
* @param changed
|
||||
* true when MapPosition has changed since last call
|
||||
*/
|
||||
public void onUpdate(MapPosition mapPosition, boolean changed) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to perform clean up of resources before shutdown. By default
|
||||
* does nothing.
|
||||
*/
|
||||
public void onDetach() {
|
||||
// FIXME call to this function is not implemented
|
||||
}
|
||||
|
||||
/**
|
||||
@ -168,7 +176,7 @@ public abstract class Overlay {
|
||||
* ...
|
||||
* @return ...
|
||||
*/
|
||||
public boolean onKeyDown(final int keyCode, final KeyEvent event) {
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -184,7 +192,7 @@ public abstract class Overlay {
|
||||
* ...
|
||||
* @return ...
|
||||
*/
|
||||
public boolean onKeyUp(final int keyCode, final KeyEvent event) {
|
||||
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -199,7 +207,7 @@ public abstract class Overlay {
|
||||
* ...
|
||||
* @return ...
|
||||
*/
|
||||
public boolean onTouchEvent(final MotionEvent e) {
|
||||
public boolean onTouchEvent(MotionEvent e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -213,7 +221,7 @@ public abstract class Overlay {
|
||||
* ...
|
||||
* @return ...
|
||||
*/
|
||||
public boolean onTrackballEvent(final MotionEvent e) {
|
||||
public boolean onTrackballEvent(MotionEvent e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -229,7 +237,7 @@ public abstract class Overlay {
|
||||
* ...
|
||||
* @return ...
|
||||
*/
|
||||
public boolean onDoubleTap(final MotionEvent e) {
|
||||
public boolean onDoubleTap(MotionEvent e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -243,7 +251,7 @@ public abstract class Overlay {
|
||||
* ...
|
||||
* @return ...
|
||||
*/
|
||||
public boolean onDoubleTapEvent(final MotionEvent e) {
|
||||
public boolean onDoubleTapEvent(MotionEvent e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -257,7 +265,7 @@ public abstract class Overlay {
|
||||
* ...
|
||||
* @return ...
|
||||
*/
|
||||
public boolean onSingleTapConfirmed(final MotionEvent e) {
|
||||
public boolean onSingleTapConfirmed(MotionEvent e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -273,7 +281,7 @@ public abstract class Overlay {
|
||||
* ...
|
||||
* @return ...
|
||||
*/
|
||||
public boolean onDown(final MotionEvent e) {
|
||||
public boolean onDown(MotionEvent e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -293,8 +301,8 @@ public abstract class Overlay {
|
||||
* ...
|
||||
* @return ...
|
||||
*/
|
||||
public boolean onFling(final MotionEvent pEvent1, final MotionEvent pEvent2,
|
||||
final float pVelocityX, final float pVelocityY) {
|
||||
public boolean onFling(MotionEvent pEvent1, MotionEvent pEvent2,
|
||||
float pVelocityX, float pVelocityY) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -308,7 +316,7 @@ public abstract class Overlay {
|
||||
* ...
|
||||
* @return ...
|
||||
*/
|
||||
public boolean onLongPress(final MotionEvent e) {
|
||||
public boolean onLongPress(MotionEvent e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -328,8 +336,8 @@ public abstract class Overlay {
|
||||
* ...
|
||||
* @return ...
|
||||
*/
|
||||
public boolean onScroll(final MotionEvent pEvent1, final MotionEvent pEvent2,
|
||||
final float pDistanceX, final float pDistanceY) {
|
||||
public boolean onScroll(MotionEvent pEvent1, MotionEvent pEvent2,
|
||||
float pDistanceX, float pDistanceY) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -337,7 +345,7 @@ public abstract class Overlay {
|
||||
* @param pEvent
|
||||
* ...
|
||||
*/
|
||||
public void onShowPress(final MotionEvent pEvent) {
|
||||
public void onShowPress(MotionEvent pEvent) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -351,19 +359,10 @@ public abstract class Overlay {
|
||||
* ...
|
||||
* @return ...
|
||||
*/
|
||||
public boolean onSingleTapUp(final MotionEvent e) {
|
||||
public boolean onSingleTapUp(MotionEvent e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mapPosition
|
||||
* current MapPosition
|
||||
* @param changed ...
|
||||
*/
|
||||
public void onUpdate(MapPosition mapPosition, boolean changed) {
|
||||
|
||||
}
|
||||
|
||||
// ===========================================================
|
||||
// Inner and Anonymous Classes
|
||||
// ===========================================================
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012 osmdroid
|
||||
* Copyright 2012 osmdroid authors
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
@ -14,25 +14,35 @@
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.oscim.overlay;
|
||||
package org.oscim.view;
|
||||
|
||||
import java.util.AbstractList;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.core.PointF;
|
||||
import org.oscim.overlay.Overlay;
|
||||
import org.oscim.overlay.Overlay.Snappable;
|
||||
import org.oscim.renderer.overlays.RenderOverlay;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.GestureDetector.OnDoubleTapListener;
|
||||
import android.view.GestureDetector.OnGestureListener;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
public class OverlayManager extends AbstractList<Overlay> {
|
||||
public class LayerManager extends AbstractList<Overlay> implements OnGestureListener,
|
||||
OnDoubleTapListener {
|
||||
|
||||
private final GestureDetector mGestureDetector;
|
||||
|
||||
private final CopyOnWriteArrayList<Overlay> mOverlayList;
|
||||
|
||||
public OverlayManager() {
|
||||
LayerManager(Context context) {
|
||||
mOverlayList = new CopyOnWriteArrayList<Overlay>();
|
||||
mGestureDetector = new GestureDetector(context, this);
|
||||
mGestureDetector.setOnDoubleTapListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -63,6 +73,17 @@ public class OverlayManager extends AbstractList<Overlay> {
|
||||
return mOverlayList.set(pIndex, pElement);
|
||||
}
|
||||
|
||||
public boolean handleMotionEvent(MotionEvent e) {
|
||||
|
||||
if (mGestureDetector.onTouchEvent(e))
|
||||
return true;
|
||||
|
||||
if (onTouchEvent(e))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean mDirtyOverlays;
|
||||
private RenderOverlay[] mDrawLayers;
|
||||
|
||||
@ -111,6 +132,17 @@ public class OverlayManager extends AbstractList<Overlay> {
|
||||
mDirtyOverlays = false;
|
||||
}
|
||||
|
||||
public boolean onTouchEvent(final MotionEvent event) {
|
||||
if (mDirtyOverlays)
|
||||
updateOverlays();
|
||||
|
||||
for (Overlay o : mOverlays)
|
||||
if (o.onTouchEvent(event))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean onKeyDown(final int keyCode, final KeyEvent event) {
|
||||
if (mDirtyOverlays)
|
||||
updateOverlays();
|
||||
@ -133,17 +165,6 @@ public class OverlayManager extends AbstractList<Overlay> {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean onTouchEvent(final MotionEvent event) {
|
||||
if (mDirtyOverlays)
|
||||
updateOverlays();
|
||||
|
||||
for (Overlay o : mOverlays)
|
||||
if (o.onTouchEvent(event))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean onTrackballEvent(final MotionEvent event) {
|
||||
if (mDirtyOverlays)
|
||||
updateOverlays();
|
||||
@ -169,6 +190,7 @@ public class OverlayManager extends AbstractList<Overlay> {
|
||||
|
||||
/* GestureDetector.OnDoubleTapListener */
|
||||
|
||||
@Override
|
||||
public boolean onDoubleTap(final MotionEvent e) {
|
||||
if (mDirtyOverlays)
|
||||
updateOverlays();
|
||||
@ -180,6 +202,7 @@ public class OverlayManager extends AbstractList<Overlay> {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDoubleTapEvent(final MotionEvent e) {
|
||||
if (mDirtyOverlays)
|
||||
updateOverlays();
|
||||
@ -191,6 +214,7 @@ public class OverlayManager extends AbstractList<Overlay> {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSingleTapConfirmed(final MotionEvent e) {
|
||||
if (mDirtyOverlays)
|
||||
updateOverlays();
|
||||
@ -204,6 +228,7 @@ public class OverlayManager extends AbstractList<Overlay> {
|
||||
|
||||
/* OnGestureListener */
|
||||
|
||||
@Override
|
||||
public boolean onDown(final MotionEvent pEvent) {
|
||||
if (mDirtyOverlays)
|
||||
updateOverlays();
|
||||
@ -215,6 +240,7 @@ public class OverlayManager extends AbstractList<Overlay> {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onFling(final MotionEvent pEvent1, final MotionEvent pEvent2,
|
||||
final float pVelocityX, final float pVelocityY) {
|
||||
if (mDirtyOverlays)
|
||||
@ -227,17 +253,17 @@ public class OverlayManager extends AbstractList<Overlay> {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean onLongPress(final MotionEvent pEvent) {
|
||||
@Override
|
||||
public void onLongPress(final MotionEvent pEvent) {
|
||||
if (mDirtyOverlays)
|
||||
updateOverlays();
|
||||
|
||||
for (Overlay o : mOverlays)
|
||||
if (o.onLongPress(pEvent))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onScroll(final MotionEvent pEvent1, final MotionEvent pEvent2,
|
||||
final float pDistanceX, final float pDistanceY) {
|
||||
if (mDirtyOverlays)
|
||||
@ -250,6 +276,7 @@ public class OverlayManager extends AbstractList<Overlay> {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShowPress(final MotionEvent pEvent) {
|
||||
if (mDirtyOverlays)
|
||||
updateOverlays();
|
||||
@ -259,6 +286,7 @@ public class OverlayManager extends AbstractList<Overlay> {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSingleTapUp(final MotionEvent pEvent) {
|
||||
if (mDirtyOverlays)
|
||||
updateOverlays();
|
@ -1,6 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
* Copyright 2012, 2013 Hannes Janetzek
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
*
|
||||
* 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
|
||||
@ -13,35 +12,24 @@
|
||||
* 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.oscim.view;
|
||||
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.overlay.OverlayManager;
|
||||
import org.oscim.overlay.Overlay;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.GestureDetector.OnDoubleTapListener;
|
||||
import android.view.GestureDetector.OnGestureListener;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
/**
|
||||
* @author Hannes Janetzek
|
||||
* Changes MapViewPosition for scroll, fling, scale, rotation and tilt gestures
|
||||
*
|
||||
* @TODO:
|
||||
* - use one AnimationTimer instead of CountDownTimers
|
||||
* - fix recognition of tilt/rotate/scale state...
|
||||
* - better recognition of tilt/rotate/scale state
|
||||
*/
|
||||
|
||||
final class TouchHandler implements OnGestureListener, OnDoubleTapListener {
|
||||
|
||||
private static final String TAG = TouchHandler.class.getName();
|
||||
|
||||
public class MapEventLayer extends Overlay {
|
||||
private static final boolean debug = false;
|
||||
|
||||
private final MapView mMapView;
|
||||
private final MapViewPosition mMapPosition;
|
||||
private final OverlayManager mOverlayManager;
|
||||
private static final String TAG = MapEventLayer.class.getName();
|
||||
|
||||
private float mSumScale;
|
||||
private float mSumRotate;
|
||||
@ -63,58 +51,55 @@ final class TouchHandler implements OnGestureListener, OnDoubleTapListener {
|
||||
private float mFocusX;
|
||||
private float mFocusY;
|
||||
|
||||
private final GestureDetector mGestureDetector;
|
||||
|
||||
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 float PINCH_TILT_THRESHOLD = 1f;
|
||||
|
||||
/**
|
||||
* @param context
|
||||
* the Context
|
||||
* @param mapView
|
||||
* the MapView
|
||||
*/
|
||||
public TouchHandler(Context context, MapView mapView) {
|
||||
mMapView = mapView;
|
||||
private final MapViewPosition mMapPosition;
|
||||
|
||||
public MapEventLayer(MapView mapView) {
|
||||
super(mapView);
|
||||
mMapPosition = mapView.getMapViewPosition();
|
||||
mOverlayManager = mapView.getOverlayManager();
|
||||
mGestureDetector = new GestureDetector(context, this);
|
||||
mGestureDetector.setOnDoubleTapListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param e
|
||||
* ...
|
||||
* @return ...
|
||||
*/
|
||||
public boolean handleMotionEvent(MotionEvent e) {
|
||||
|
||||
if (mOverlayManager.onTouchEvent(e))
|
||||
return true;
|
||||
|
||||
mGestureDetector.onTouchEvent(e);
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent e) {
|
||||
|
||||
int action = getAction(e);
|
||||
|
||||
if (action == MotionEvent.ACTION_DOWN) {
|
||||
mMulti = 0;
|
||||
mWasMulti = false;
|
||||
if (mOverlayManager.onDown(e))
|
||||
return true;
|
||||
|
||||
return onActionDown(e);
|
||||
mPrevX = e.getX(0);
|
||||
mPrevY = e.getY(0);
|
||||
return true; //onActionDown(e);
|
||||
} else if (action == MotionEvent.ACTION_MOVE) {
|
||||
return onActionMove(e);
|
||||
} else if (action == MotionEvent.ACTION_UP) {
|
||||
return onActionUp(e);
|
||||
mBeginRotate = false;
|
||||
mBeginTilt = false;
|
||||
mBeginScale = false;
|
||||
mDoubleTap = false;
|
||||
return true;
|
||||
//return onActionUp(e);
|
||||
|
||||
} else if (action == MotionEvent.ACTION_CANCEL) {
|
||||
return onActionCancel();
|
||||
mDoubleTap = false;
|
||||
return true;
|
||||
//return onActionCancel();
|
||||
} else if (action == MotionEvent.ACTION_POINTER_DOWN) {
|
||||
return onActionPointerDown(e);
|
||||
mMulti++;
|
||||
mWasMulti = true;
|
||||
|
||||
updateMulti(e);
|
||||
return true;
|
||||
//return onActionPointerDown(e);
|
||||
} else if (action == MotionEvent.ACTION_POINTER_UP) {
|
||||
return onActionPointerUp(e);
|
||||
updateMulti(e);
|
||||
mMulti--;
|
||||
return true;
|
||||
//return onActionPointerUp(e);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -124,11 +109,6 @@ final class TouchHandler implements OnGestureListener, OnDoubleTapListener {
|
||||
return e.getAction() & MotionEvent.ACTION_MASK;
|
||||
}
|
||||
|
||||
private boolean onActionCancel() {
|
||||
mDoubleTap = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean onActionMove(MotionEvent e) {
|
||||
float x1 = e.getX(0);
|
||||
float y1 = e.getY(0);
|
||||
@ -279,80 +259,14 @@ final class TouchHandler implements OnGestureListener, OnDoubleTapListener {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean onActionPointerDown(MotionEvent e) {
|
||||
@Override
|
||||
public boolean onDoubleTap(MotionEvent e) {
|
||||
|
||||
mMulti++;
|
||||
mWasMulti = true;
|
||||
|
||||
updateMulti(e);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean onActionPointerUp(MotionEvent e) {
|
||||
|
||||
updateMulti(e);
|
||||
mMulti--;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void printState(String action) {
|
||||
Log.d(TAG, action
|
||||
+ " " + mDoubleTap
|
||||
+ " " + mBeginScale
|
||||
+ " " + mBeginRotate
|
||||
+ " " + mBeginTilt);
|
||||
}
|
||||
|
||||
private boolean onActionDown(MotionEvent e) {
|
||||
mPrevX = e.getX(0);
|
||||
mPrevY = e.getY(0);
|
||||
mDoubleTap = true;
|
||||
//mMapPosition.animateZoom(2);
|
||||
|
||||
if (debug)
|
||||
printState("onActionDown");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param event
|
||||
* unused
|
||||
* @return ...
|
||||
*/
|
||||
private boolean onActionUp(MotionEvent event) {
|
||||
|
||||
if (debug)
|
||||
printState("onActionUp");
|
||||
|
||||
mBeginRotate = false;
|
||||
mBeginTilt = false;
|
||||
mBeginScale = false;
|
||||
mDoubleTap = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/******************* GestureListener *******************/
|
||||
|
||||
//private final Scroller mScroller;
|
||||
//private float mScrollX, mScrollY;
|
||||
// private boolean fling = false;
|
||||
|
||||
@Override
|
||||
public void onShowPress(MotionEvent e) {
|
||||
mOverlayManager.onShowPress(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSingleTapUp(MotionEvent e) {
|
||||
return mOverlayManager.onSingleTapUp(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDown(MotionEvent e) {
|
||||
if (debug)
|
||||
printState("onDown");
|
||||
printState("onDoubleTap");
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -361,18 +275,15 @@ final class TouchHandler implements OnGestureListener, OnDoubleTapListener {
|
||||
public boolean onScroll(final MotionEvent e1, final MotionEvent e2, final float distanceX,
|
||||
final float distanceY) {
|
||||
|
||||
if (mOverlayManager.onScroll(e1, e2, distanceX, distanceY)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mMulti == 0) {
|
||||
if (debug)
|
||||
printState("onScroll " + distanceX + " " + distanceY);
|
||||
mMapPosition.moveMap(-distanceX, -distanceY);
|
||||
mMapView.redrawMap(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -402,47 +313,16 @@ final class TouchHandler implements OnGestureListener, OnDoubleTapListener {
|
||||
mMapPosition.animateFling(
|
||||
Math.round(velocityX * s),
|
||||
Math.round(velocityY * s),
|
||||
-w, w, -h, h);
|
||||
-w, w, -h, h);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLongPress(MotionEvent e) {
|
||||
if (mDoubleTap)
|
||||
return;
|
||||
|
||||
if (mOverlayManager.onLongPress(e)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if (MapView.testRegionZoom) {
|
||||
// Log.d("mapsforge", "long press");
|
||||
// mMapView.mRegionLookup.updateRegion(-1, null);
|
||||
// }
|
||||
private void printState(String action) {
|
||||
Log.d(TAG, action
|
||||
+ " " + mDoubleTap
|
||||
+ " " + mBeginScale
|
||||
+ " " + mBeginRotate
|
||||
+ " " + mBeginTilt);
|
||||
}
|
||||
|
||||
/******************* DoubleTapListener ****************/
|
||||
@Override
|
||||
public boolean onSingleTapConfirmed(MotionEvent e) {
|
||||
return mOverlayManager.onSingleTapConfirmed(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDoubleTap(MotionEvent e) {
|
||||
if (mOverlayManager.onDoubleTap(e))
|
||||
return true;
|
||||
|
||||
mDoubleTap = true;
|
||||
//mMapPosition.animateZoom(2);
|
||||
|
||||
if (debug)
|
||||
printState("onDoubleTap");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDoubleTapEvent(MotionEvent e) {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -40,7 +40,6 @@ import org.oscim.generator.TileGenerator;
|
||||
import org.oscim.overlay.BuildingOverlay;
|
||||
import org.oscim.overlay.LabelingOverlay;
|
||||
import org.oscim.overlay.Overlay;
|
||||
import org.oscim.overlay.OverlayManager;
|
||||
import org.oscim.renderer.GLRenderer;
|
||||
import org.oscim.renderer.GLView;
|
||||
import org.oscim.renderer.TileManager;
|
||||
@ -80,11 +79,10 @@ public class MapView extends RelativeLayout {
|
||||
|
||||
//private final MapZoomControls mMapZoomControls;
|
||||
|
||||
private final TouchHandler mTouchEventHandler;
|
||||
private final Compass mCompass;
|
||||
|
||||
private final TileManager mTileManager;
|
||||
private final OverlayManager mOverlayManager;
|
||||
private final LayerManager mLayerManager;
|
||||
|
||||
final GLView mGLView;
|
||||
private final JobQueue mJobQueue;
|
||||
@ -150,9 +148,7 @@ public class MapView extends RelativeLayout {
|
||||
mMapViewPosition = new MapViewPosition(this);
|
||||
mMapPosition = new MapPosition();
|
||||
|
||||
mOverlayManager = new OverlayManager();
|
||||
|
||||
mTouchEventHandler = new TouchHandler(mapActivity, this);
|
||||
mLayerManager = new LayerManager(context);
|
||||
|
||||
mCompass = new Compass(mapActivity, this);
|
||||
|
||||
@ -180,25 +176,29 @@ public class MapView extends RelativeLayout {
|
||||
|
||||
addView(mGLView, params);
|
||||
|
||||
mLayerManager.add(new MapEventLayer(this));
|
||||
|
||||
//mMapZoomControls = new MapZoomControls(mapActivity, this);
|
||||
//mMapZoomControls.setShowMapZoomControls(true);
|
||||
mRotationEnabled = true;
|
||||
|
||||
//mOverlayManager.add(new GenericOverlay(this, new GridOverlay(this)));
|
||||
//mLayerManager.add(new GenericOverlay(this, new GridOverlay(this)));
|
||||
|
||||
mOverlayManager.add(new BuildingOverlay(this));
|
||||
mOverlayManager.add(new LabelingOverlay(this));
|
||||
mLayerManager.add(new BuildingOverlay(this));
|
||||
mLayerManager.add(new LabelingOverlay(this));
|
||||
|
||||
//mOverlayManager.add(new GenericOverlay(this, new TileOverlay(this)));
|
||||
//mOverlayManager.add(new GenericOverlay(this, new CustomOverlay(this)));
|
||||
//mOverlayManager.add(new MapLensOverlay(this));
|
||||
//mLayerManager.add(new GenericOverlay(this, new TileOverlay(this)));
|
||||
//mLayerManager.add(new GenericOverlay(this, new CustomOverlay(this)));
|
||||
//mLayerManager.add(new MapLensOverlay(this));
|
||||
|
||||
//PathOverlay path = new PathOverlay(this, Color.RED);
|
||||
//path.addGreatCircle(new GeoPoint(53.1, 8.8), new GeoPoint(53.1, -110.0));
|
||||
//mOverlayManager.add(path);
|
||||
//mLayerManager.add(path);
|
||||
//path = new PathOverlay(this, Color.GREEN);
|
||||
//path.addGreatCircle(new GeoPoint(53.1, 140), new GeoPoint(53.1, -110.0));
|
||||
//mOverlayManager.add(path);
|
||||
//mLayerManager.add(path);
|
||||
|
||||
//mLayerManager.add(new GenericOverlay(this, new AtlasTest(this)));
|
||||
|
||||
clearMap();
|
||||
}
|
||||
@ -218,7 +218,6 @@ public class MapView extends RelativeLayout {
|
||||
// restore the interrupted status
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -253,13 +252,11 @@ public class MapView extends RelativeLayout {
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent motionEvent) {
|
||||
// mMapZoomControlsjonMapViewTouchEvent(motionEvent.getAction()
|
||||
// & MotionEvent.ACTION_MASK);
|
||||
|
||||
if (this.isClickable())
|
||||
return mTouchEventHandler.handleMotionEvent(motionEvent);
|
||||
if (!isClickable())
|
||||
return false;
|
||||
|
||||
return false;
|
||||
return mLayerManager.handleMotionEvent(motionEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -344,7 +341,7 @@ public class MapView extends RelativeLayout {
|
||||
|
||||
// required when not changed?
|
||||
if (AndroidUtils.currentThreadIsUiThread())
|
||||
mOverlayManager.onUpdate(mMapPosition, changed);
|
||||
mLayerManager.onUpdate(mMapPosition, changed);
|
||||
|
||||
if (changed) {
|
||||
mTileManager.update(mMapPosition);
|
||||
@ -620,8 +617,8 @@ public class MapView extends RelativeLayout {
|
||||
return this.getOverlayManager();
|
||||
}
|
||||
|
||||
public OverlayManager getOverlayManager() {
|
||||
return mOverlayManager;
|
||||
public LayerManager getOverlayManager() {
|
||||
return mLayerManager;
|
||||
}
|
||||
|
||||
public TileManager getTileManager() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user