Android Button Reuse

Source: Internet
Author: User

Recently made Android TV system customization, the above arrangement I do a key board button multiplexing function: When the TV OSD menu is displayed when the ch+/ch-on the key board is the key on/off, the vol+/vol-is reused as the direction key right/left. The OSD menu is implemented using a fragment, so choose the OSD menu display (onresume) Trigger button multiplexing function, the OSD menu disappears (onStop) When the button reuse function. The idea of implementation is reasonable, and we know that the application handling key event Keyevnet is usually determined by the event's KeyCode value to determine what the program is going to do, so just handle the key function Onkey,onkeyup,onkeydown such as processing the key event before the KeyCode value of the event can be used to achieve the re-use of keys, specifically, this is to change the Keycode_channel_up/keycode_channel_down to Keycode_dpad_up/keycode_dpad _down the same keycode_volume_up/keycode_volume_down changed to Keycode_dpad_right/keycode_dpad_left. The Dispatchkeyevent (KeyEvent event) is required to modify the key value before the function mentioned above, and the official interpretation of the method is to intercept the keystroke event before it is distributed to the window. All right, gossip less. The code is as follows:  

1  Public Booleandispatchkeyevent (KeyEvent event) {2         LongDowntime=event.getdowntime ();3         LongEventtime =event.geteventtime ();4         intAction =event.getaction ();5         intCode =Event.getkeycode ();6         intrepeat =Event.getrepeatcount ();7         intMetaState =event.getmetastate ();8         Switch(code) {9          Casekeyevent.keycode_channel_up:Tenevent =Newkeyevent (Downtime, eventtime, action, KEYEVENT.KEYCODE_DPAD_UP, Repeat, metaState); One              Break; A          CaseKeyevent.keycode_channel_down: -event =Newkeyevent (Downtime, eventtime, action, Keyevent.keycode_dpad_down, Repeat, metaState); -              Break; the          Casekeyevent.keycode_volume_up: -event =Newkeyevent (Downtime, eventtime, action, Keyevent.keycode_dpad_right, Repeat, metaState); -              Break; -          CaseKeyevent.keycode_volume_down: +event =Newkeyevent (Downtime, eventtime, action, Keyevent.keycode_dpad_left, Repeat, metaState); -              Break; +         } A  at         return Super. Dispatchkeyevent (event); -}

Android Button Reuse

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.