Example usage for android.view KeyEvent getSource

List of usage examples for android.view KeyEvent getSource

Introduction

In this page you can find the example usage for android.view KeyEvent getSource.

Prototype

@Override
public final int getSource() 

Source Link

Usage

From source file:org.mozilla.gecko.BrowserApp.java

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (AndroidGamepadManager.handleKeyEvent(event)) {
        return true;
    }/*from w ww. j  a v  a2  s  .c o m*/

    // Global onKey handler. This is called if the focused UI doesn't
    // handle the key event, and before Gecko swallows the events.
    if (event.getAction() != KeyEvent.ACTION_DOWN) {
        return false;
    }

    if ((event.getSource() & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_BUTTON_Y:
            // Toggle/focus the address bar on gamepad-y button.
            if (mBrowserChrome.getVisibility() == View.VISIBLE) {
                if (mDynamicToolbar.isEnabled() && !isHomePagerVisible()) {
                    mDynamicToolbar.setVisible(false, VisibilityTransition.ANIMATE);
                    if (mLayerView != null) {
                        mLayerView.requestFocus();
                    }
                } else {
                    // Just focus the address bar when about:home is visible
                    // or when the dynamic toolbar isn't enabled.
                    mBrowserToolbar.requestFocusFromTouch();
                }
            } else {
                mDynamicToolbar.setVisible(true, VisibilityTransition.ANIMATE);
                mBrowserToolbar.requestFocusFromTouch();
            }
            return true;
        case KeyEvent.KEYCODE_BUTTON_L1:
            // Go back on L1
            Tabs.getInstance().getSelectedTab().doBack();
            return true;
        case KeyEvent.KEYCODE_BUTTON_R1:
            // Go forward on R1
            Tabs.getInstance().getSelectedTab().doForward();
            return true;
        }
    }

    // Check if this was a shortcut. Meta keys exists only on 11+.
    final Tab tab = Tabs.getInstance().getSelectedTab();
    if (Versions.feature11Plus && tab != null && event.isCtrlPressed()) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_LEFT_BRACKET:
            tab.doBack();
            return true;

        case KeyEvent.KEYCODE_RIGHT_BRACKET:
            tab.doForward();
            return true;

        case KeyEvent.KEYCODE_R:
            tab.doReload();
            return true;

        case KeyEvent.KEYCODE_PERIOD:
            tab.doStop();
            return true;

        case KeyEvent.KEYCODE_T:
            addTab();
            return true;

        case KeyEvent.KEYCODE_W:
            Tabs.getInstance().closeTab(tab);
            return true;

        case KeyEvent.KEYCODE_F:
            mFindInPageBar.show();
            return true;
        }
    }

    return false;
}