public class Mygesturelintener extends Simpleongesturelistener {
private context;
Public Mygesturelintener {
Super ();
This.context = context;
}
Click to trigger immediately when the touch screen is pressed
/* @Override
public boolean Ondown (Motionevent e) {
TODO auto-generated Method Stub
Toast.maketext (Context, "down" + e.getaction (), Toast.length_short)
. Show ();
return true;
}*/
Double-click, finger on the touch screen quickly hit the second trigger
@Override
public boolean Ondoubletap (Motionevent e) {
TODO auto-generated Method Stub
Return Super.ondoubletap (e);
}
Double-click Press and lift each trigger once
@Override
public boolean ondoubletapevent (Motionevent e) {
TODO auto-generated Method Stub
Return Super.ondoubletapevent (e);
}
Slide, the touch screen is pressed and quickly moved and lifted, it triggers a scrolling gesture and then triggers a sliding gesture
@Override
public boolean onfling (Motionevent E1, motionevent E2, float Velocityx,
Float velocityy) {
TODO auto-generated Method Stub
Return Super.onfling (E1, E2, Velocityx, Velocityy);
}
Long press, touch screen after press neither lift nor move, after a period of time triggered
@Override
public void Onlongpress (Motionevent e) {
TODO auto-generated Method Stub
Toast.maketext (Context, "LONG" + e.getaction (), Toast.length_short)
. Show ();
}
Scrolling, the touch screen is pressed and then moved
@Override
public boolean onscroll (Motionevent E1, motionevent E2, float Distancex,
Float Distancey) {
Toast.maketext (Context, "onscroll" + e2.getaction (), Toast.length_short)
. Show ();
return true;
}
Short press, the touch screen pressed after a moment to lift, will trigger this gesture, if the rapid lift will not
@Override
public void Onshowpress (Motionevent e) {
TODO auto-generated Method Stub
Toast.maketext (Context, "show" + e.getaction (), Toast.length_short)
. Show ();
}
Click Confirm, ie quickly press and lift, but not continuously click Second
/* @Override
public boolean onsingletapconfirmed (Motionevent e) {
TODO auto-generated Method Stub
Toast.maketext (Context, "onsingletapconfirmed" + e.getaction (), Toast.length_short)
. Show ();
return true;
}*/
Lift, when the finger left the touch screen triggered (long press, scrolling, sliding, does not trigger this gesture)
/* @Override
public boolean onsingletapup (Motionevent e) {
TODO auto-generated Method Stub
Toast.maketext (Context, "Onsingletapup" + e.getaction (), Toast.length_short)
. Show ();
return true;
}*/
public class Mainactivity extends activity {
Private Gesturedetector mgesturedetector;//Gesture Object
Private Mygesturelintener mygesturelintener;//Gesture Listener Interface Object
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Mygesturelintener = new Mygesturelintener (this);
The method of constructing gesture object
Mgesturedetector = new Gesturedetector (This,
Mygesturelintener);
}
The Ontouchevent method of the/**gesturedetector class is used to identify different gestures.
@Override
public boolean ontouchevent (Motionevent event) {
Boolean B = false;
int i = event.getaction ();
int j = Motionevent.action_move;
System.out.println (i+ "<----------------->" +j);
b = Mgesturedetector.ontouchevent (event);
if (b) {
Intent in = new Intent ();
In.setclass (this, testactivity.class);
StartActivity (in);
}
return b;
}
@Override
public boolean Oncreateoptionsmenu (Menu menu) {
Inflate the menu; This adds items to the action bar if it is present.
Getmenuinflater (). Inflate (R.menu.main, menu);
return true;
}
}