1. Overview
The previous section describes the differences between the Android TV app and some of the Android mobile app's representations. There is a lot of focus processing in actual programming, and focus processing is often handled within the event transfer function. So this section does a summary of the Android event delivery and focus processing. Also since the description of the Android event delivery inevitably involves Android gesture interception. This is also a supplement to the original knowledge, because previously involved in the Android event delivery is to do gesture interception, so that when the code in the gesture distribution function to deal with the focus of the TV, and the interface to move the fill. For a moment a little confused, why is written in the dispathkeyevent is not written in onintercepttouchevent. The reason for this is because it handles the focus in the event delivery process, rather than intercepting events in the event delivery process.
2, Android simple event delivery process
Referring to the Android event delivery process will certainly involve several of the following functions
ontouchevent
function |
Description |
remarks |
Dispathtouchevent (Mot Ionevent ev) |
Event distribution (gesture distribution) |
Touch screen-Mobile |
Dispatchkeyevent (KeyEvent event) |
Event distribution |
Remote control-TV |
onintercepttouchevent |
Event intercept (gesture intercept) Returns true: Event is intercepted, Event passed to its own Ontouchevent Returns false: The event continues to pass |
ViewGroup only |
Event handling Returns true: Event consumed terminated pass Return false: Continue delivery |
|
Table 1
Android Event delivery has two kinds of events, one is touch screen touch events, one is the key event, keyboard mode and remote control with this, not boil. The flow of dispathtouchevent and Dispatchkeyevent is the same.
Event delivery process details and source code analysis, the online has a lot of detailed description, and some say is foggy, the actual use of the project and reference:
Pre_andevcon_mastering-the-android-touch-system
Event delivery starts Dispath from the event distribution function of the activity ... If no event consumption ends up being consumed in the child view of the ontouchevent back to activty, then this function will not be uploaded.
Simple down event delivery as seen in Table 1: (Event not consumed)
Figure 1
Figure 2
About interception: For the Move/up event after the interception of the down event is more complex, in practice, as long as you know which view is not a down event, there is no move/up and in the actual project itself to intercept the move event. Onintercepttouchevent
Public booleanonintercepttouchevent (motionevent ev)
The event intercept function onintercepttouchevent is a function that is only viewgroup. Event interception (gesture blocking) is also done when customizing ViewGroup. The actual situation encountered is that the move event at some boundaries when the use of conditions to decide whether to let ViewGroup himself or Childview to deal with. Where the return value determines whether to intercept, false continues to pass, and true intercepts to itself, the process is shown in Figure 1, figure 2.
3, Dispathkeyevent and Dispathtouchevent
The event distribution function is also the dispatch function of the event flow. Dispath of the base class ... The function determines how the event is passed, which involves calling Onintercepttouchevent, and the Ontouchevent function.
Do custom ViewGroup event interception is not required to rewrite Dispath ... As long as you rewrite the Onintercepttouchevent function. So before also relatively rare rewrite dispath ...
But there are many places in the TV app that rewrite the function. At first it was a bit of a wonder why it was written here, and then I saw that every dispathkeyevent function had a call to Super.dispathkeyevent, and rewriting dispathkeyevent did not affect the distribution of events. Just the equivalent of a hook hanging in the event delivery process to handle: Click the button gesture when the focus effect and the interface effect,
4. Focus Processing
Mobile app development focus on less processing, there is edittext sometimes need to get the next focus, or remove, in fact, less processing. TV is more to deal with, here are the next several focus processing functions
Activity |
|
View CurrentView = Getcurrentfocus (); |
|
ViewGroup |
|
View CurrentView = Findfocus (); |
|
View |
|
Currentview.focussearch (direction); |
Finds the closest focusable view of the specified direction if no null is returned |
Setclickedable |
|
Setfocusable |
|
Android event delivery and focus processing (TV)