Improved gestures: parallel system and samples #253

This commit is contained in:
Emux
2016-11-25 09:28:33 +02:00
parent 71f7c45b21
commit ba93445259
15 changed files with 934 additions and 173 deletions

View File

@@ -1,5 +1,6 @@
/*
* Copyright 2012 Hannes Janetzek
* Copyright 2016 devemux86
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
@@ -21,11 +22,13 @@ import android.content.Context;
import android.opengl.GLSurfaceView;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.GestureDetector;
import org.oscim.android.canvas.AndroidGraphics;
import org.oscim.android.gl.AndroidGL;
import org.oscim.android.gl.GlConfigChooser;
import org.oscim.android.input.AndroidMotionEvent;
import org.oscim.android.input.GestureHandler;
import org.oscim.backend.CanvasAdapter;
import org.oscim.backend.GLAdapter;
import org.oscim.map.Map;
@@ -51,6 +54,7 @@ public class MapView extends GLSurfaceView {
}
protected final AndroidMap mMap;
protected GestureDetector mGestureDetector;
protected final AndroidMotionEvent mMotionEvent;
public MapView(Context context) {
@@ -91,6 +95,12 @@ public class MapView extends GLSurfaceView {
mMap.clearMap();
mMap.updateMap(false);
if (!Map.NEW_GESTURES) {
GestureHandler gestureHandler = new GestureHandler(mMap);
mGestureDetector = new GestureDetector(context, gestureHandler);
mGestureDetector.setOnDoubleTapListener(gestureHandler);
}
mMotionEvent = new AndroidMotionEvent();
}
@@ -112,6 +122,11 @@ public class MapView extends GLSurfaceView {
if (!isClickable())
return false;
if (mGestureDetector != null) {
if (mGestureDetector.onTouchEvent(motionEvent))
return true;
}
mMap.input.fire(null, mMotionEvent.wrap(motionEvent));
mMotionEvent.recycle();
return true;

View File

@@ -0,0 +1,97 @@
/*
* Copyright 2013 Hannes Janetzek
* Copyright 2016 devemux86
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.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.oscim.android.input;
import android.view.GestureDetector.OnDoubleTapListener;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import org.oscim.event.Gesture;
import org.oscim.map.Map;
public class GestureHandler implements OnGestureListener, OnDoubleTapListener {
private final AndroidMotionEvent mMotionEvent;
private final Map mMap;
// Quick scale (double tap + swipe)
protected boolean quickScale;
public GestureHandler(Map map) {
mMotionEvent = new AndroidMotionEvent();
mMap = map;
}
/* OnGestureListener */
@Override
public boolean onSingleTapUp(MotionEvent e) {
return false;
}
@Override
public void onShowPress(MotionEvent e) {
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
return false;
}
@Override
public void onLongPress(MotionEvent e) {
// Quick scale (no long press)
if (quickScale)
return;
mMap.handleGesture(Gesture.LONG_PRESS, mMotionEvent.wrap(e));
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
return false;
}
@Override
public boolean onDown(MotionEvent e) {
quickScale = false;
return mMap.handleGesture(Gesture.PRESS, mMotionEvent.wrap(e));
}
/* OnDoubleTapListener */
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
return mMap.handleGesture(Gesture.TAP, mMotionEvent.wrap(e));
}
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
int action = e.getActionMasked();
// Quick scale
quickScale = (action == MotionEvent.ACTION_MOVE);
return false;
}
@Override
public boolean onDoubleTap(MotionEvent e) {
return mMap.handleGesture(Gesture.DOUBLE_TAP, mMotionEvent.wrap(e));
}
}