Java Code Examples for android.view.KeyEvent#KEYCODE_TV_INPUT

The following examples show how to use android.view.KeyEvent#KEYCODE_TV_INPUT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KeyboardShortcuts.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * This should be called from the Activity's dispatchKeyEvent() to handle keyboard shortcuts.
 *
 * Note: dispatchKeyEvent() is called before the active view or web page gets a chance to handle
 * the key event. So the keys handled here cannot be overridden by any view or web page.
 *
 * @param event The KeyEvent to handle.
 * @param activity The ChromeActivity in which the key was pressed.
 * @param uiInitialized Whether the UI has been initialized. If this is false, most keys will
 *                      not be handled.
 * @return True if the event was handled. False if the event was ignored. Null if the event
 *         should be handled by the activity's parent class.
 */
@SuppressFBWarnings("NP_BOOLEAN_RETURN_NULL")
public static Boolean dispatchKeyEvent(KeyEvent event, ChromeActivity activity,
        boolean uiInitialized) {
    int keyCode = event.getKeyCode();
    if (!uiInitialized) {
        if (keyCode == KeyEvent.KEYCODE_SEARCH || keyCode == KeyEvent.KEYCODE_MENU) return true;
        return null;
    }

    switch (keyCode) {
        case KeyEvent.KEYCODE_SEARCH:
            if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
                activity.onMenuOrKeyboardAction(R.id.focus_url_bar, false);
            }
            // Always consume the SEARCH key events to prevent android from showing
            // the default app search UI, which locks up Chrome.
            return true;
        case KeyEvent.KEYCODE_MENU:
            if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
                activity.onMenuOrKeyboardAction(R.id.show_menu, false);
            }
            return true;
        case KeyEvent.KEYCODE_TV:
        case KeyEvent.KEYCODE_GUIDE:
        case KeyEvent.KEYCODE_DVR:
        case KeyEvent.KEYCODE_AVR_INPUT:
        case KeyEvent.KEYCODE_AVR_POWER:
        case KeyEvent.KEYCODE_STB_INPUT:
        case KeyEvent.KEYCODE_STB_POWER:
        case KeyEvent.KEYCODE_TV_INPUT:
        case KeyEvent.KEYCODE_TV_POWER:
        case KeyEvent.KEYCODE_WINDOW:
            // Do not consume the AV device-related keys so that the system will take
            // an appropriate action, such as switching to TV mode.
            return false;
    }

    return null;
}
 
Example 2
Source File: KeyboardShortcuts.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * This should be called from the Activity's dispatchKeyEvent() to handle keyboard shortcuts.
 *
 * Note: dispatchKeyEvent() is called before the active view or web page gets a chance to handle
 * the key event. So the keys handled here cannot be overridden by any view or web page.
 *
 * @param event The KeyEvent to handle.
 * @param activity The ChromeActivity in which the key was pressed.
 * @param uiInitialized Whether the UI has been initialized. If this is false, most keys will
 *                      not be handled.
 * @return True if the event was handled. False if the event was ignored. Null if the event
 *         should be handled by the activity's parent class.
 */
@SuppressFBWarnings("NP_BOOLEAN_RETURN_NULL")
public static Boolean dispatchKeyEvent(KeyEvent event, ChromeActivity activity,
        boolean uiInitialized) {
    int keyCode = event.getKeyCode();
    if (!uiInitialized) {
        if (keyCode == KeyEvent.KEYCODE_SEARCH || keyCode == KeyEvent.KEYCODE_MENU) return true;
        return null;
    }

    switch (keyCode) {
        case KeyEvent.KEYCODE_SEARCH:
            if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
                activity.onMenuOrKeyboardAction(R.id.focus_url_bar, false);
            }
            // Always consume the SEARCH key events to prevent android from showing
            // the default app search UI, which locks up Chrome.
            return true;
        case KeyEvent.KEYCODE_MENU:
            if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
                activity.onMenuOrKeyboardAction(R.id.show_menu, false);
            }
            return true;
        case KeyEvent.KEYCODE_ESCAPE:
            if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
                if (activity.exitFullscreenIfShowing()) return true;
            }
            break;
        case KeyEvent.KEYCODE_TV:
        case KeyEvent.KEYCODE_GUIDE:
        case KeyEvent.KEYCODE_DVR:
        case KeyEvent.KEYCODE_AVR_INPUT:
        case KeyEvent.KEYCODE_AVR_POWER:
        case KeyEvent.KEYCODE_STB_INPUT:
        case KeyEvent.KEYCODE_STB_POWER:
        case KeyEvent.KEYCODE_TV_INPUT:
        case KeyEvent.KEYCODE_TV_POWER:
        case KeyEvent.KEYCODE_WINDOW:
            // Do not consume the AV device-related keys so that the system will take
            // an appropriate action, such as switching to TV mode.
            return false;
    }

    return null;
}
 
Example 3
Source File: KeyboardShortcuts.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * This should be called from the Activity's dispatchKeyEvent() to handle keyboard shortcuts.
 *
 * Note: dispatchKeyEvent() is called before the active view or web page gets a chance to handle
 * the key event. So the keys handled here cannot be overridden by any view or web page.
 *
 * @param event The KeyEvent to handle.
 * @param activity The ChromeActivity in which the key was pressed.
 * @param uiInitialized Whether the UI has been initialized. If this is false, most keys will
 *                      not be handled.
 * @return True if the event was handled. False if the event was ignored. Null if the event
 *         should be handled by the activity's parent class.
 */
@SuppressFBWarnings("NP_BOOLEAN_RETURN_NULL")
public static Boolean dispatchKeyEvent(KeyEvent event, ChromeActivity activity,
        boolean uiInitialized) {
    int keyCode = event.getKeyCode();
    if (!uiInitialized) {
        if (keyCode == KeyEvent.KEYCODE_SEARCH || keyCode == KeyEvent.KEYCODE_MENU) return true;
        return null;
    }

    switch (keyCode) {
        case KeyEvent.KEYCODE_SEARCH:
            if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
                activity.onMenuOrKeyboardAction(R.id.focus_url_bar, false);
            }
            // Always consume the SEARCH key events to prevent android from showing
            // the default app search UI, which locks up Chrome.
            return true;
        case KeyEvent.KEYCODE_MENU:
            if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
                activity.onMenuOrKeyboardAction(R.id.show_menu, false);
            }
            return true;
        case KeyEvent.KEYCODE_ESCAPE:
            if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
                if (activity.exitFullscreenIfShowing()) return true;
            }
            break;
        case KeyEvent.KEYCODE_TV:
        case KeyEvent.KEYCODE_GUIDE:
        case KeyEvent.KEYCODE_DVR:
        case KeyEvent.KEYCODE_AVR_INPUT:
        case KeyEvent.KEYCODE_AVR_POWER:
        case KeyEvent.KEYCODE_STB_INPUT:
        case KeyEvent.KEYCODE_STB_POWER:
        case KeyEvent.KEYCODE_TV_INPUT:
        case KeyEvent.KEYCODE_TV_POWER:
        case KeyEvent.KEYCODE_WINDOW:
            // Do not consume the AV device-related keys so that the system will take
            // an appropriate action, such as switching to TV mode.
            return false;
    }

    return null;
}