Back to project page project2.
The source code is released under:
MIT License
If you think the Android project project2 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package team2.scdm; //from w ww .ja va 2s . c o m import android.app.Activity; import android.content.Intent; import android.view.GestureDetector; import android.view.GestureDetector.OnGestureListener; import android.view.MotionEvent; public class GestureListener extends Activity implements OnGestureListener{ private GestureDetector gesture = null; private Class<?> leftActivity = null; private Class<?> rightActivity = null; @Override public boolean onTouchEvent(MotionEvent me) { if(gesture != null) return gesture.onTouchEvent(me); else return false; } @Override public boolean onDown(MotionEvent arg0) { // TODO Auto-generated method stub return false; } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { float xDiff = e2.getX() - e1.getX(); float yDiff = e2.getY() - e1.getY(); if(Math.abs(xDiff) > Math.abs(yDiff)) { if(xDiff < 0) { Intent intent = new Intent(this, rightActivity); startActivity(intent); } else { Intent intent = new Intent(this, leftActivity); startActivity(intent); } } return false; } @Override public void onLongPress(MotionEvent e) { // TODO Auto-generated method stub } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { // TODO Auto-generated method stub return false; } @Override public void onShowPress(MotionEvent e) { // TODO Auto-generated method stub } @Override public boolean onSingleTapUp(MotionEvent e) { // TODO Auto-generated method stub return false; } public void setGestureDetector(GestureDetector gesture) { this.gesture = gesture; } public void setLeftRight(Class<?> leftActivity, Class<?> rightActivity) { this.leftActivity = leftActivity; this.rightActivity = rightActivity; } }