Merge "Apply new Android keycodes to CEC keycode mapping." into lmp-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
49764d45f6
@@ -160,19 +160,22 @@ final class HdmiCecKeycode {
|
||||
|
||||
/**
|
||||
* A mapping between Android and CEC keycode.
|
||||
* <p>
|
||||
* Normal implementation of this looks like
|
||||
*
|
||||
* <p>Normal implementation of this looks like
|
||||
* <pre>
|
||||
* new KeycodeEntry(KeyEvent.KEYCODE_DPAD_CENTER, CEC_KEYCODE_SELECT);
|
||||
* new KeycodeEntry(KeyEvent.KEYCODE_DPAD_CENTER, CEC_KEYCODE_SELECT);
|
||||
* </pre>
|
||||
* <p>However, some keys in CEC requires additional parameter.
|
||||
* In order to use parameterized cec key, add unique android keycode (existing or custom)
|
||||
* corresponding to a pair of cec keycode and and its param.
|
||||
* <p>
|
||||
* However, some keys in CEC requires additional parameter. In order to use parameterized cec
|
||||
* key, add unique android keycode (existing or custom) corresponding to a pair of cec keycode
|
||||
* and and its param.
|
||||
*
|
||||
* <pre>
|
||||
* new KeycodeEntry(CUSTOME_ANDORID_KEY_1, CEC_KEYCODE_SELECT_BROADCAST_TYPE,
|
||||
* UI_BROADCAST_TOGGLE_ALL);
|
||||
* new KeycodeEntry(CUSTOME_ANDORID_KEY_2, CEC_KEYCODE_SELECT_BROADCAST_TYPE,
|
||||
* UI_BROADCAST_ANALOGUE);
|
||||
* new KeycodeEntry(CUSTOME_ANDORID_KEY_1, CEC_KEYCODE_SELECT_BROADCAST_TYPE,
|
||||
* UI_BROADCAST_TOGGLE_ALL);
|
||||
* new KeycodeEntry(CUSTOME_ANDORID_KEY_2, CEC_KEYCODE_SELECT_BROADCAST_TYPE,
|
||||
* UI_BROADCAST_ANALOGUE);
|
||||
* </pre>
|
||||
*/
|
||||
private static class KeycodeEntry {
|
||||
@@ -226,6 +229,11 @@ final class HdmiCecKeycode {
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] intToSingleByteArray(int value) {
|
||||
return new byte[] {
|
||||
(byte) (value & 0xFF) };
|
||||
}
|
||||
|
||||
// Keycode entry container for all mappings.
|
||||
// Note that order of entry is the same as above cec keycode definition.
|
||||
private static final KeycodeEntry[] KEYCODE_ENTRIES = new KeycodeEntry[] {
|
||||
@@ -242,19 +250,25 @@ final class HdmiCecKeycode {
|
||||
new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_LEFT_UP),
|
||||
// No Android keycode defined for CEC_KEYCODE_LEFT_DOWN
|
||||
new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_LEFT_DOWN),
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_HOME, CEC_KEYCODE_ROOT_MENU, false),
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_SETTINGS, CEC_KEYCODE_SETUP_MENU, false),
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_MENU, CEC_KEYCODE_CONTENTS_MENU, false),
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_HOME, CEC_KEYCODE_ROOT_MENU),
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_SETTINGS, CEC_KEYCODE_SETUP_MENU),
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_TV_CONTENTS_MENU, CEC_KEYCODE_CONTENTS_MENU),
|
||||
// No Android keycode defined for CEC_KEYCODE_FAVORITE_MENU
|
||||
new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_FAVORITE_MENU),
|
||||
// Note that both BACK and ESCAPE are mapped to EXIT of CEC keycode.
|
||||
// This would be problematic when translates CEC keycode to Android keycode.
|
||||
// In current implementation, we pick BACK as mapping of EXIT key.
|
||||
// If you'd like to map CEC EXIT to Android EXIT key, change order of
|
||||
// the following two definition.
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_BACK, CEC_KEYCODE_EXIT),
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_ESCAPE, CEC_KEYCODE_EXIT),
|
||||
// RESERVED
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_TOP_MENU, CEC_KEYCODE_MEDIA_TOP_MENU),
|
||||
// No Android keycode defined for CEC_KEYCODE_MEDIA_CONTEXT_SENSITIVE_MENU
|
||||
new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_MEDIA_CONTEXT_SENSITIVE_MENU),
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_TV_MEDIA_CONTEXT_MENU,
|
||||
CEC_KEYCODE_MEDIA_CONTEXT_SENSITIVE_MENU),
|
||||
// RESERVED
|
||||
// No Android keycode defined for CEC_KEYCODE_NUMBER_ENTRY_MODE
|
||||
new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_NUMBER_ENTRY_MODE),
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_TV_NUMBER_ENTRY, CEC_KEYCODE_NUMBER_ENTRY_MODE),
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_11, CEC_KEYCODE_NUMBER_11),
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_12, CEC_KEYCODE_NUMBER_12),
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_0, CEC_KEYCODE_NUMBER_0_OR_NUMBER_10),
|
||||
@@ -273,8 +287,8 @@ final class HdmiCecKeycode {
|
||||
// RESERVED
|
||||
// No Android keycode defined for CEC_KEYCODE_NEXT_FAVORITE
|
||||
new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_NEXT_FAVORITE),
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_CHANNEL_UP, CEC_KEYCODE_CHANNEL_UP),
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_CHANNEL_DOWN, CEC_KEYCODE_CHANNEL_DOWN),
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_CHANNEL_UP, CEC_KEYCODE_CHANNEL_UP, false),
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_CHANNEL_DOWN, CEC_KEYCODE_CHANNEL_DOWN, false),
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_LAST_CHANNEL, CEC_KEYCODE_PREVIOUS_CHANNEL),
|
||||
// No Android keycode defined for CEC_KEYCODE_SOUND_SELECT
|
||||
new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_SOUND_SELECT),
|
||||
@@ -291,7 +305,12 @@ final class HdmiCecKeycode {
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_VOLUME_MUTE, CEC_KEYCODE_MUTE, false),
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_PLAY, CEC_KEYCODE_PLAY),
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_STOP, CEC_KEYCODE_STOP),
|
||||
// Note that we map both MEDIA_PAUSE and MEDIA_PLAY_PAUSE to CEC PAUSE key.
|
||||
// When it translates CEC PAUSE key, it picks Android MEDIA_PAUSE key as a mapping of
|
||||
// it. If you'd like to choose MEDIA_PLAY_PAUSE, please change order of the following
|
||||
// two lines.
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_PAUSE, CEC_KEYCODE_PAUSE),
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, CEC_KEYCODE_PAUSE),
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_RECORD, CEC_KEYCODE_RECORD),
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_REWIND, CEC_KEYCODE_REWIND),
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_MEDIA_FAST_FORWARD, CEC_KEYCODE_FAST_FORWARD),
|
||||
@@ -306,17 +325,30 @@ final class HdmiCecKeycode {
|
||||
new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_RESERVED),
|
||||
// No Android keycode defined for CEC_KEYCODE_ANGLE
|
||||
new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_ANGLE),
|
||||
// No Android keycode defined for CEC_KEYCODE_SUB_PICTURE
|
||||
new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_SUB_PICTURE),
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_CAPTIONS, CEC_KEYCODE_SUB_PICTURE),
|
||||
// No Android keycode defined for CEC_KEYCODE_VIDEO_ON_DEMAND
|
||||
new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_VIDEO_ON_DEMAND),
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_GUIDE, CEC_KEYCODE_ELECTRONIC_PROGRAM_GUIDE),
|
||||
// No Android keycode defined for CEC_KEYCODE_TIMER_PROGRAMMING
|
||||
new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_TIMER_PROGRAMMING),
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_TV_TIMER_PROGRAMMING, CEC_KEYCODE_TIMER_PROGRAMMING),
|
||||
// No Android keycode defined for CEC_KEYCODE_INITIAL_CONFIGURATION
|
||||
new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_INITIAL_CONFIGURATION),
|
||||
// No Android keycode defined for CEC_KEYCODE_SELECT_BROADCAST_TYPE
|
||||
new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_SELECT_BROADCAST_TYPE),
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_TV_TERRESTRIAL_ANALOG,
|
||||
CEC_KEYCODE_SELECT_BROADCAST_TYPE, true,
|
||||
intToSingleByteArray(UI_BROADCAST_ANALOGUE)),
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_TV_TERRESTRIAL_DIGITAL,
|
||||
CEC_KEYCODE_SELECT_BROADCAST_TYPE, true,
|
||||
intToSingleByteArray(UI_BROADCAST_DIGITAL_TERRESTRIAL)),
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_TV_SATELLITE_BS,
|
||||
CEC_KEYCODE_SELECT_BROADCAST_TYPE, true,
|
||||
intToSingleByteArray(UI_BROADCAST_DIGITAL_SATELLITE)),
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_TV_SATELLITE_CS,
|
||||
CEC_KEYCODE_SELECT_BROADCAST_TYPE, true,
|
||||
intToSingleByteArray(UI_BROADCAST_DIGITAL_COMMNICATIONS_SATELLITE)),
|
||||
new KeycodeEntry(KeyEvent.KEYCODE_TV_NETWORK,
|
||||
CEC_KEYCODE_SELECT_BROADCAST_TYPE, true,
|
||||
intToSingleByteArray(UI_BROADCAST_TOGGLE_ANALOGUE_DIGITAL)),
|
||||
// No Android keycode defined for CEC_KEYCODE_SELECT_SOUND_PRESENTATION
|
||||
new KeycodeEntry(UNSUPPORTED_KEYCODE, CEC_KEYCODE_SELECT_SOUND_PRESENTATION),
|
||||
// RESERVED
|
||||
@@ -381,8 +413,8 @@ final class HdmiCecKeycode {
|
||||
* Translate Hdmi CEC keycode with params to Android keycode.
|
||||
*
|
||||
* @param cecKeycodeAndParams CEC keycode and params
|
||||
* @return cec keycode corresponding to the given android keycode.
|
||||
* If finds no matched keycode, return {@link #UNSUPPORTED_KEYCODE}
|
||||
* @return cec keycode corresponding to the given android keycode. If finds no matched keycode,
|
||||
* return {@link #UNSUPPORTED_KEYCODE}
|
||||
*/
|
||||
static int cecKeycodeAndParamsToAndroidKey(byte[] cecKeycodeAndParams) {
|
||||
for (int i = 0; i < KEYCODE_ENTRIES.length; ++i) {
|
||||
@@ -415,5 +447,5 @@ final class HdmiCecKeycode {
|
||||
*/
|
||||
static boolean isSupportedKeycode(int androidKeycode) {
|
||||
return HdmiCecKeycode.androidKeyToCecKey(androidKeycode) != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user