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