Skip to content

Commit

Permalink
Improved gestures (#249) #253
Browse files Browse the repository at this point in the history
  • Loading branch information
andreynovikov authored and devemux86 committed Nov 28, 2016
1 parent ca5e34e commit 71f7c45
Show file tree
Hide file tree
Showing 10 changed files with 239 additions and 204 deletions.
12 changes: 1 addition & 11 deletions vtm-android/src/org/oscim/android/MapView.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@
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;
Expand All @@ -53,7 +51,6 @@ public class MapView extends GLSurfaceView {
}

protected final AndroidMap mMap;
protected final GestureDetector mGestureDetector;
protected final AndroidMotionEvent mMotionEvent;

public MapView(Context context) {
Expand Down Expand Up @@ -94,10 +91,6 @@ public MapView(Context context, AttributeSet attributeSet) {
mMap.clearMap();
mMap.updateMap(false);

GestureHandler gestureHandler = new GestureHandler(mMap);
mGestureDetector = new GestureDetector(context, gestureHandler);
mGestureDetector.setOnDoubleTapListener(gestureHandler);

mMotionEvent = new AndroidMotionEvent();
}

Expand All @@ -116,14 +109,11 @@ public void onResume() {
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(android.view.MotionEvent motionEvent) {

if (!isClickable())
return false;

if (mGestureDetector.onTouchEvent(motionEvent))
return true;

mMap.input.fire(null, mMotionEvent.wrap(motionEvent));
mMotionEvent.recycle();
return true;
}

Expand Down
15 changes: 13 additions & 2 deletions vtm-android/src/org/oscim/android/input/AndroidMotionEvent.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2013 Hannes Janetzek
* Copyright 2016 Andrey Novikov
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
Expand All @@ -20,10 +21,10 @@

public class AndroidMotionEvent extends MotionEvent {

android.view.MotionEvent mEvent;
private android.view.MotionEvent mEvent;

public MotionEvent wrap(android.view.MotionEvent e) {
mEvent = e;
mEvent = android.view.MotionEvent.obtain(e);
return this;
}

Expand Down Expand Up @@ -57,6 +58,16 @@ public int getPointerCount() {
return mEvent.getPointerCount();
}

@Override
public MotionEvent copy() {
return new AndroidMotionEvent().wrap(mEvent);
}

@Override
public void recycle() {
mEvent.recycle();
}

@Override
public long getTime() {
return mEvent.getEventTime();
Expand Down
97 changes: 0 additions & 97 deletions vtm-android/src/org/oscim/android/input/GestureHandler.java

This file was deleted.

9 changes: 9 additions & 0 deletions vtm-gdx/src/org/oscim/gdx/GdxMotionEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ public int getPointerCount() {
return 0;
}

@Override
public MotionEvent copy() {
return new GdxMotionEvent(action, x, y, button);
}

@Override
public void recycle() {
}

@Override
public long getTime() {
return 0;
Expand Down
22 changes: 22 additions & 0 deletions vtm-gdx/src/org/oscim/gdx/MotionHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

import org.oscim.event.MotionEvent;
import org.oscim.map.Map;
import org.oscim.utils.ArrayUtils;

import java.util.Arrays;

public class MotionHandler extends MotionEvent implements InputProcessor {
private final Map mMap;
Expand Down Expand Up @@ -77,6 +80,25 @@ public int getPointerCount() {
return mPointerDown;
}

@Override
public MotionEvent copy() {
MotionHandler handler = new MotionHandler(mMap);
handler.mPointerDown = mPointerDown;
handler.mDownTime = mDownTime;
handler.mType = mType;
handler.mPointer = mPointer;
handler.mCurX = mCurX;
handler.mCurY = mCurY;
handler.mPointerX = Arrays.copyOf(mPointerX, 10);
handler.mPointerY = Arrays.copyOf(mPointerY, 10);
handler.mTime = mTime;
return handler;
}

@Override
public void recycle() {
}

@Override
public long getTime() {
return (long) (mTime / 1000000d);
Expand Down
9 changes: 9 additions & 0 deletions vtm-tests/test/org/oscim/layers/MapEventLayerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,14 @@ public float getY(int idx) {
public int getPointerCount() {
return 0;
}

@Override
public MotionEvent copy() {
return new TestMotionEvent(action, x, y);
}

@Override
public void recycle() {
}
}
}
25 changes: 17 additions & 8 deletions vtm/src/org/oscim/event/Gesture.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2013 Hannes Janetzek
* Copyright 2016 Andrey Novikov
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
Expand All @@ -18,20 +19,28 @@

public interface Gesture {

static final class Press implements Gesture {
final class Press implements Gesture {
}

static final class LongPress implements Gesture {
final class LongPress implements Gesture {
}

static final class Tap implements Gesture {
final class Tap implements Gesture {
}

static final class DoubleTap implements Gesture {
final class DoubleTap implements Gesture {
}

public static Gesture PRESS = new Press();
public static Gesture LONG_PRESS = new LongPress();
public static Gesture TAP = new Tap();
public static Gesture DOUBLE_TAP = new DoubleTap();
final class TripleTap implements Gesture {
}

class TwoFingerTap implements Gesture {
}

Gesture PRESS = new Press();
Gesture LONG_PRESS = new LongPress();
Gesture TAP = new Tap();
Gesture DOUBLE_TAP = new DoubleTap();
Gesture TRIPLE_TAP = new TripleTap();
Gesture TWO_FINGER_TAP = new TwoFingerTap();
}
36 changes: 0 additions & 36 deletions vtm/src/org/oscim/event/GestureDetector.java

This file was deleted.

3 changes: 3 additions & 0 deletions vtm/src/org/oscim/event/MotionEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@ public abstract class MotionEvent {

public abstract int getPointerCount();

public abstract MotionEvent copy();

public abstract void recycle();
}
Loading

0 comments on commit 71f7c45

Please sign in to comment.