1 package jie.java.android.touchmovetest;
2
3 import android.app.Activity;
4 import android.os.Bundle;
5 import android.util.Log;
6 import android.view.GestureDetector;
7 import android.view.GestureDetector.SimpleOnGestureListener;
8 import android.view.MotionEvent;
9 import android.view.View;
10 import android.view.View.OnTouchListener;
11
12 public class TouchMoveTestActivity extends Activity implements OnTouchListener {
13 /** Called when the activity is first created. */
14
15
16 private class MyGestureListener extends SimpleOnGestureListener {
17
18 @Override
19 public boolean onDoubleTap(MotionEvent e) {
20 // TODO Auto-generated method stub
21 Log.d("g", "doubletap");
22 return super.onDoubleTap(e);
23 }
24
25 @Override
26 public boolean onDoubleTapEvent(MotionEvent e) {
27 // TODO Auto-generated method stub
28 Log.d("g", "doubletapevent");
29 return super.onDoubleTapEvent(e);
30 }
31
32 @Override
33 public boolean onDown(MotionEvent e) {
34 // TODO Auto-generated method stub
35 Log.d("g", "down");
36 return super.onDown(e);
37 }
38
39 @Override
40 public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
41 float velocityY) {
42 // TODO Auto-generated method stub
43 Log.d("g", "filing - e1.x:" + e1.getX() + " e2.x:" + e2.getX() + " vx:" + velocityX);
44 return super.onFling(e1, e2, velocityX, velocityY);
45 }
46
47 @Override
48 public void onLongPress(MotionEvent e) {
49 // TODO Auto-generated method stub
50 Log.d("g", "longpress");
51 super.onLongPress(e);
52 }
53
54 @Override
55 public boolean onScroll(MotionEvent e1, MotionEvent e2,
56 float distanceX, float distanceY) {
57 // TODO Auto-generated method stub
58 Log.d("g", "scroll - e1.x:" + e1.getX() + " e2.x:" + e2.getX() + " distx:" + distanceX);
59 return super.onScroll(e1, e2, distanceX, distanceY);
60 }
61
62 @Override
63 public void onShowPress(MotionEvent e) {
64 // TODO Auto-generated method stub
65 Log.d("g", "showpress");
66 super.onShowPress(e);
67 }
68
69 @Override
70 public boolean onSingleTapConfirmed(MotionEvent e) {
71 // TODO Auto-generated method stub
72 Log.d("g", "singletapconfirmed");
73 return super.onSingleTapConfirmed(e);
74 }
75
76 @Override
77 public boolean onSingleTapUp(MotionEvent e) {
78 // TODO Auto-generated method stub
79 Log.d("g", "singletapup");
80 return super.onSingleTapUp(e);
81 }
82 }
83
84 private GestureDetector detector = null;
85 @Override
86 public void onCreate(Bundle savedInstanceState) {
87 super.onCreate(savedInstanceState);
88 setContentView(R.layout.main);
89
90 this.findViewById(R.id.linearLayout1).setOnTouchListener(this);
91 this.findViewById(R.id.linearLayout1).setLongClickable(true);
92
93 detector = new GestureDetector(this, new MyGestureListener());
94 }
95
96 public boolean onTouch(View view, MotionEvent event) {
97 // TODO Auto-generated method stub
98 detector.onTouchEvent(event);
99 return false;
100 }
101 }