Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Use gesture detector compatibility libs
Browse files Browse the repository at this point in the history
  • Loading branch information
Leith Bade committed Nov 21, 2014
1 parent 9c7b6dc commit 201ab76
Showing 1 changed file with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
import android.net.NetworkInfo;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.view.GestureDetectorCompat;
import android.support.v4.view.ScaleGestureDetectorCompat;
import android.view.GestureDetector;
import android.view.ScaleGestureDetector;
import android.util.AttributeSet;
import android.util.Log;
import android.view.GestureDetector;
import android.view.InputDevice;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
Expand Down Expand Up @@ -70,7 +72,7 @@ public class MapView extends SurfaceView {
private float mScreenDensity = 1.0f;

// Touch gesture detectors
private GestureDetector mGestureDetector;
private GestureDetectorCompat mGestureDetector;
private ScaleGestureDetector mScaleGestureDetector;
private RotateGestureDetector mRotateGestureDetector;
private boolean mTwoTap = false;
Expand Down Expand Up @@ -185,10 +187,11 @@ private void initialize(Context context, AttributeSet attrs) {
getHolder().addCallback(new Callbacks());

// Touch gesture detectors
mGestureDetector = new GestureDetector(context, new GestureListener());
mGestureDetector = new GestureDetectorCompat(context, new GestureListener());
mGestureDetector.setIsLongpressEnabled(true);
mScaleGestureDetector = new ScaleGestureDetector(context,
new ScaleGestureListener());
ScaleGestureDetectorCompat.setQuickScaleEnabled(mScaleGestureDetector, true);
mRotateGestureDetector = new RotateGestureDetector(context,
new RotateGestureListener());

Expand Down Expand Up @@ -829,7 +832,6 @@ public boolean onRotateBegin(RotateGestureDetector detector) {
}

mBeginTime = detector.getEventTime();
Log.d("rotate", "rotate begin");
return true;
}

Expand All @@ -839,7 +841,6 @@ public void onRotateEnd(RotateGestureDetector detector) {
mBeginTime = 0;
mTotalAngle = 0.0f;
mStarted = false;
Log.d("rotate", "rotate end");
}

// Called each time one of the two fingers moves
Expand All @@ -850,24 +851,19 @@ public boolean onRotate(RotateGestureDetector detector) {
return false;
}

Log.d("rotate", "rotate evt");

// If rotate is large enough ignore a tap
// TODO: Google Maps seem to use a velocity rather than absolute
// value, up to a point then they always rotate
mTotalAngle += detector.getRotationDegreesDelta();
Log.d("rotate", "ttl angle " + mTotalAngle);
if ((mTotalAngle > 5.0f) || (mTotalAngle < -5.0f)) {
mStarted = true;
Log.d("rotate", "rotate started");
}

// Ignore short touches in case it is a tap
// Also ignore small rotate
long time = detector.getEventTime();
long interval = time - mBeginTime;
if (!mStarted && (interval <= ViewConfiguration.getTapTimeout())) {
Log.d("rotate", "rotate ignored");
return false;
}

Expand All @@ -882,7 +878,6 @@ public boolean onRotate(RotateGestureDetector detector) {
// Rotate the map
double bearing = mNativeMapView.getBearing();
bearing += detector.getRotationDegreesDelta();
Log.d("rotate", "rotate to " + bearing);
mNativeMapView.setBearing(bearing, detector.getFocusX() / mScreenDensity,
detector.getFocusY() / mScreenDensity);

Expand Down Expand Up @@ -1108,7 +1103,7 @@ public TrackballLongPressTimeOut() {
cancelled = false;
}

// Cancel the timeoht
// Cancel the timeout
public void cancel() {
cancelled = true;
}
Expand Down Expand Up @@ -1202,7 +1197,7 @@ public class ConnectivityReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.v(TAG, "ConnectivityReceiver.onReceive: action = " + intent.getAction());
if (intent.getAction() == ConnectivityManager.CONNECTIVITY_ACTION) {
if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
boolean noConnectivity = intent.getBooleanExtra(
ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
onConnectivityChanged(!noConnectivity);
Expand Down

0 comments on commit 201ab76

Please sign in to comment.