Ontouchevent is also a method defined in view. Handles gesture events that are passed to view. Gesture event types include events such as Action_down,action_move,action_up,action_cancel.
Paste the Android 5.0 source code
1 Public Booleanontouchevent (Motionevent event) {2 Final floatx =event.getx ();3 Final floaty =event.gety ();4 Final intViewFlags =mviewflags;5 6 if((ViewFlags & enabled_mask) = =DISABLED) {7 if(event.getaction () = = Motionevent.action_up && (mprivateflags & pflag_pressed)! = 0) {8Setpressed (false);9 }Ten //A disabled view that's clickable still consumes the touch One //events, it just doesn ' t respond to them. A return((viewflags & clickable) = = Clickable | | -(ViewFlags & long_clickable) = =long_clickable)); - } the - if(Mtouchdelegate! =NULL) { - if(Mtouchdelegate.ontouchevent (event)) { - return true; + } - } + A if((viewflags & clickable) = = Clickable | | at(ViewFlags & long_clickable) = =long_clickable)) { - Switch(Event.getaction ()) { - Casemotionevent.action_up: - Booleanprepressed = (Mprivateflags & pflag_prepressed)! = 0; - if((Mprivateflags & pflag_pressed)! = 0 | |prepressed) { - //Take Focus if we don't have an it already and we should in in //Touch mode. - BooleanFocustaken =false; to if(Isfocusable () && isfocusableintouchmode () &&!isFocused ()) { +Focustaken =Requestfocus (); - } the * if(prepressed) { $ //The button is being released before we actuallyPanax Notoginseng //showed it as pressed. Make it show the pressed - //State now (before scheduling the click) to ensure the //The user sees it. +Setpressed (true, x, y); A } the + if(!mhasperformedlongpress) { - //This was a tap, so remove the Longpress check $ Removelongpresscallback (); $ - //Only perform take click Actions if we were in the pressed state - if(!Focustaken) { the //Use a Runnable and post this rather than calling - //PerformClick directly. This lets other visual stateWuyi //Of the view update before click Actions Start. the if(Mperformclick = =NULL) { -Mperformclick =NewPerformClick (); Wu } - if(!post (Mperformclick)) { About PerformClick (); $ } - } - } - A if(Munsetpressedstate = =NULL) { +Munsetpressedstate =Newunsetpressedstate (); the } - $ if(prepressed) { the postdelayed (Munsetpressedstate, the viewconfiguration.getpressedstateduration ()); the}Else if(!post (munsetpressedstate)) { the //If The post failed, unpress right now - Munsetpressedstate.run (); in } the the Removetapcallback (); About } the Break; the the CaseMotionevent.action_down: +Mhasperformedlongpress =false; - the if(Performbuttonactionontouchdown (event)) {Bayi Break; the } the - //Walk up the hierarchy to determine if we ' re inside a scrolling container. - BooleanIsinscrollingcontainer =Isinscrollingcontainer (); the the //for views inside a scrolling container, delay the pressed feedback for the //A short period in case the is a scroll. the if(isinscrollingcontainer) { -Mprivateflags |=pflag_prepressed; the if(Mpendingcheckfortap = =NULL) { theMpendingcheckfortap =NewCheckfortap (); the }94mpendingcheckfortap.x =event.getx (); theMPENDINGCHECKFORTAP.Y =event.gety (); the postdelayed (Mpendingcheckfortap, Viewconfiguration.gettaptimeout ()); the}Else {98 //Not inside a scrolling container, so show the feedback right away AboutSetpressed (true, x, y); -Checkforlongclick (0);101 }102 Break;103 104 CaseMotionevent.action_cancel: theSetpressed (false);106 Removetapcallback ();107 Removelongpresscallback ();108 Break;109 the CaseMotionevent.action_move:111 drawablehotspotchanged (x, y); the 113 //Being lenient about moving outside of buttons the if(!Pointinview (x, Y, Mtouchslop)) { the //Outside Button the Removetapcallback ();117 if((Mprivateflags & pflag_pressed)! = 0) {118 //Remove Any future long Press/tap checks119 Removelongpresscallback (); - 121Setpressed (false);122 }123 }124 Break; the }126 127 return true; - }129 the return false;131}
Android L (5.0) Source code gesture Recognition Ontouchevent