首页蓝耳朵|小小蓝耳朵广州图书馆外文室英语儿童读物资源介绍网佛教青年之友旧版收集永硕E盘Phonics Short Vowels Game 
捕捉手指在屏幕上滑动的测试
所属栏目:Android  时间:2011-12-30 15:44  作者:狼子
测试项目名称: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;
}
}
小楼宝宝的涂鸦花花(Imitater)的博客起名称骨测字皖ICP备06000023号-17