[Chinese is converted]
1. onintercepttouchevent () is used to process events (similar to preprocessing, but it can also not be processed) and change the event transmission direction, that is, to determine whether to allow the touch event to continue downward (sub-Control) if yes, but true is returned (the event will be processed in the current viewgroup), the path to the next pass is truncated (all child controls will not be involved in the touch event ), at the same time, the event is passed to the ontouchevent () processing of the current control; if false is returned, the event is handed over to the onintercepttouchevent () of the Child control ()
2. ontouchevent () is used to process events. The returned value determines whether the current control consumes the event (consume). That is to say, after the current control finishes processing the touch event, whether to allow the touch event to be passed up (parent control). If the value of true is returned, the parent control does not have to handle the touch event on its own. If the return value is true, it is passed up to the parent control (Note: Do you think it is related to consumption? Anyway, I have compiled the processing code for the event? The answer is yes! For example, the premise that action_move or action_up occurs is that action_down has occurred. If you have not consumed action_down, the system will think that action_down has not happened, so action_move or action_up cannot be captured .)
Final int viewid = view. GETID (); Final int action = event. getactionmasked () & motionevent. action_mask; Final int actionindex = event. getactionindex (); Switch (Action) {Case motionevent. action_up: // the view here has an error: if the direction is not loose, then press the bullet. // then release the direction and finally release the bullet, the bullet button will not get the release view. setpressed (false); m_offsetx = m_offsety = 0; int x = (INT) event. getrawx (), Y = (INT) event. getrawy (); If (m_firerect.contains (x, y) {I F (R. Id. Fire! = Viewid) findviewbyid (R. Id. Fire). setpressed (false);} else if (m_padrect.contains (x, y) {If (R. Id. pad! = Viewid) findviewbyid (R. id. PAD ). setpressed (false); // run the int gridx = PME command on the snow. getgrid (). x; int gridy = PME. getgrid (). y; If (gameworld. snow = gameworld. instance (). getterrain (gridx, gridy, gameworld. terrain_type_all) | gameworld. snow = gameworld. instance (). getterrain (gridx + 1, gridy + 1, gameworld. terrain_type_all) {PME. slide ();} else {PME. setdir (dir. none) ;}} break; Case motionevent. action_move: // first adjust the coordinates of the event relative to the origin event. offsetlocation (m_offsetx, m_offsety); // log. D (TAG, "Down X" + event. getx (actionindex) + "Y" + event. gety (actionindex); buttontype type = getbutton (event. getx (actionindex), event. gety (actionindex); Switch (type) {Case up: Case down: Case left: case right: domove (type); break; Case fire: If (PME. fire () {audiopool. play (m_soundid [audioid. audio_fire.ordinal ()], getcurvolume (), 0);} break; default: PME. setdir (dir. none); break;} break; Case motionevent. action_down: // log. D (TAG, "First (" + m_offsetx + "," + m_offsety + ")"); view. setpressed (true); Switch (viewid) {case R. id. fire: m_offsetx = m_firerect.left; m_offsety = m_firerect.top; If (PME. fire () {audiopool. play (m_soundid [audioid. audio_fire.ordinal ()], getcurvolume (), 0);} break; case R. id. pad: m_offsetx = m_padrect.left; m_offsety = m_padrect.top; type = getbutton (event. getrawx (), event. getrawy (); Switch (type) {Case up: Case down: Case left: case right: PME. stopslide (); domove (type); break; default: PME. setdir (dir. none); break;} default: break;} break; Case motionevent. action_pointer_down: // first adjust the coordinates of the event relative to the origin event. offsetlocation (m_offsetx, m_offsety); log. D (TAG, "action_pointer_down X" + event. getx (actionindex) + "Y" + event. gety (actionindex); type = getbutton (event. getx (actionindex), event. gety (actionindex); Switch (type) {Case up: Case down: Case left: case right: findviewbyid (R. id. PAD ). setpressed (true); domove (type); break; Case fire: findviewbyid (R. id. fire ). setpressed (true); If (PME. fire () {audiopool. play (m_soundid [audioid. audio_fire.ordinal ()], getcurvolume (), 0);} break; default: break;} break; Case motionevent. action_pointer_up: // first adjust the coordinates of the event relative to the origin event. offsetlocation (m_offsetx, m_offsety); log. D (TAG, "action_pointer_up X" + event. getx (actionindex) + "Y" + event. gety (actionindex); type = getbutton (event. getx (actionindex), event. gety (actionindex); Switch (type) {Case up: Case down: Case left: case right: findviewbyid (R. id. PAD ). setpressed (false); PME. setdir (dir. none); break; Case fire: findviewbyid (R. id. fire ). setpressed (false); break; default: findviewbyid (R. id. PAD ). setpressed (false); findviewbyid (R. id. fire ). setpressed (false); PME. setdir (dir. none); break;} break; default: // for other events break ;}