public class Gesturetest extends Activity implements Onclicklistener, Ongesturelistener {//define gesture Detector instance Gesturedetector detector; @Overridepublic void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity10_layout);//create gesture Detector detector = new Gesturedetector (this);} Handing the touch event on the activity to Gesturedetector processing @overridepublic boolean ontouchevent (motionevent me) {return Detector.ontouchevent (Me);} @Overridepublic boolean Ondown (Motionevent arg0) {Toast.maketext (this, "pressing", Toast.length_long). Show (); return false ;} @Overridepublic boolean onfling (motionevent E1, motionevent E2, float Velocityx, float velocityy) {Toast.maketext (this, " Throwing ", Toast.length_long). Show (); return false;} @Overridepublic void Onlongpress (Motionevent e) {Toast.maketext (this, "long press", Toast.length_long). Show (); @Overridepublic boolean onscroll (motionevent E1, motionevent E2, float Distancex, float distancey) {Toast.maketext (this, "Sliding", Toast.length_long). Show (); return False;} @Overridepublic void Onshowpress (Motionevent e) {Toast.maketext (this, "holding", Toast.length_long). Show (); @Overridepublic Boolean onsingletapup (Motionevent e) {Toast.maketext (this, "lifting", Toast.length_long). Show (); return false;} @Overridepublic void OnClick (View arg0) {}}
where the onfling () parameter has the following meanings:
E1: Move event at start of gesture
e2: Move event of the current gesture point
velocityx: pixels moving X-axis per second
velocityy: Pixels moved in Y-axis per second
where the onscroll () parameter has the following meanings:
Distancex: equals the x value of E1 minus the X value of E2, and the result is signed.
Distancey: equals the Y value of E1 minus the Y value of E2 and evaluates to a sign.
Android Gesture Monitor (Gesturedetector Class)