Created
February 21, 2017 09:04
-
-
Save CoXier/066da346bdf19c519457300f7c7988f6 to your computer and use it in GitHub Desktop.
Android gesture detector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.util.Log; | |
import android.view.GestureDetector; | |
import android.view.MotionEvent; | |
/** | |
* Created by CoXier on 17-2-21. | |
*/ | |
public class SimpleGestureListener extends GestureDetector.SimpleOnGestureListener { | |
private static final String TAG = "SimpleGestureListener"; | |
private Listener mListener; | |
@Override | |
public boolean onDown(MotionEvent e) { | |
return true; | |
} | |
@Override | |
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { | |
Log.i(TAG,e1.toString()+"\n"+e2.toString()); | |
Log.d(TAG,"distanceX = "+distanceX+",distanceY = "+distanceY); | |
if (mListener == null) | |
return true; | |
if (distanceX == 0 && Math.abs(distanceY) > 1){ | |
mListener.onScrollVertical(distanceY); | |
} | |
if (distanceY == 0 && Math.abs(distanceX) > 1){ | |
mListener.onScrollHorizontal(distanceX); | |
} | |
return true; | |
} | |
public void setListener(Listener mListener) { | |
this.mListener = mListener; | |
} | |
interface Listener{ | |
/** | |
* left scroll dx >0 | |
* right scroll dx <0 | |
* @param dx | |
*/ | |
void onScrollHorizontal(float dx); | |
/** | |
* upward scroll dy > 0 | |
* downward scroll dy < 0 | |
* @param dy | |
*/ | |
void onScrollVertical(float dy); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment