Android gesture Operation Gesturedetector

Source: Internet
Author: User

 Packagecom.sphere.gesturetest;ImportAndroid.os.Bundle;Importandroid.app.Activity;ImportAndroid.view.GestureDetector;ImportAndroid.view.GestureDetector.OnGestureListener;ImportAndroid.view.Menu;Importandroid.view.MotionEvent;ImportAndroid.widget.Toast; Public classMainactivityextendsActivityImplementsongesturelistener{Gesturedetector Gesturedetector; Private intMin_destance = 50; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); Gesturedetector=NewGesturedetector ( This, This); } @Override Public BooleanOncreateoptionsmenu (Menu menu) {//inflate the menu; This adds items to the action bar if it is present.getmenuinflater (). Inflate (R.menu.main, menu); return true; } @Override Public Booleanontouchevent (Motionevent event) {//Hand gesture Detection class handles touch events        returngesturedetector.ontouchevent (event); }    //triggered when the user presses@Override Public BooleanOndown (motionevent arg0) {//TODO auto-generated Method StubToast ("Press"); return false; }    //triggered when the user drags on the screen@Override Public BooleanOnfling (motionevent arg0, Motionevent arg1,floatArg2,floatArg3) {        //TODO auto-generated Method Stub        if(Arg0.getx ()-Arg1.getx () >min_destance) {Toast ("Slide Left"); }        if(Arg0.getx ()-Arg1.getx () <min_destance) {Toast ("Slide Right"); }        return false; } @Override Public voidonlongpress (motionevent arg0) {//TODO auto-generated Method StubToast ("Long Press"); } @Override Public BooleanOnscroll (motionevent arg0, Motionevent arg1,floatArg2,floatArg3) {        //TODO auto-generated Method Stub//Toast ("scrolling ....") ");        return false; }    //triggered when the user presses on the screen and has not moved and released@Override Public voidonshowpress (motionevent arg0) {//TODO auto-generated Method StubToast ("Onshowpress ....") "); }    //The user taps the event on the touchscreen to trigger@Override Public BooleanOnsingletapup (motionevent arg0) {//TODO auto-generated Method StubToast ("Onsingletapup ....") "); return false; }         Public voidToast (String text) {Toast.maketext ( This, text, Toast.length_short). Show (); }}

Android gesture Operation Gesturedetector

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.