Android uses the gesturedetector gesture recognition sample to share _android

Source: Internet
Author: User
Tags stub touch

Copy Code code as follows:

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;
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.