测试项目名称:TestSign
package test.sign;
import android.app.Activity;
import android.gesture.GestureOverlayView;
import android.gesture.GestureOverlayView.OnGestureListener;
import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
public class TestSignActivity extends Activity implements OnGestureListener, android.view.GestureDetector.OnGestureListener {
private GestureDetector mGestureDetector;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mGestureDetector = new GestureDetector(this);
}
public void onGesture(GestureOverlayView overlay, MotionEvent event) { }
public void onGestureCancelled(GestureOverlayView overlay, MotionEvent event) { }
public void onGestureEnded(GestureOverlayView overlay, MotionEvent event) { }
public void onGestureStarted(GestureOverlayView overlay, MotionEvent event) { }
public void onShowPress(MotionEvent e) { }
public void onLongPress(MotionEvent e) { }
public boolean onDown(MotionEvent e) { return false; }
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { return false; }
public boolean onSingleTapUp(MotionEvent e) { return false; }
@Override
public boolean onTouchEvent(MotionEvent event) { return mGestureDetector.onTouchEvent(event); }
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
float gapX = e1.getX()-e2.getX();
float gapY = e1.getY()-e2.getY();
if(gapY > 100) {
Log.i("fling", "it's going up now.");
return true;
}
if(gapY < - 100) {
Log.i("fling", "it's going down now.");
return true;
}
if(gapX > 100) {
Log.i("fling", "it's going left now.");
return true;
}
if(gapX < -100) {
Log.i("fling", "it's going right now.");
return true;
}
return false;
}
}