Example usage for android.view KeyEvent KEYCODE_BUTTON_R1

List of usage examples for android.view KeyEvent KEYCODE_BUTTON_R1

Introduction

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

Prototype

int KEYCODE_BUTTON_R1

To view the source code for android.view KeyEvent KEYCODE_BUTTON_R1.

Click Source Link

Document

Key code constant: R1 Button key.

Usage

From source file:com.aengbee.android.leanback.ui.PlaybackOverlayActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BUTTON_R1) {
        getMediaController().getTransportControls().skipToNext();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_BUTTON_L1) {
        getMediaController().getTransportControls().skipToPrevious();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_BUTTON_L2) {
        getMediaController().getTransportControls().rewind();
    } else if (keyCode == KeyEvent.KEYCODE_BUTTON_R2) {
        getMediaController().getTransportControls().fastForward();
    }/*from   w  w  w  .  j av  a2s  .c  o  m*/

    return super.onKeyDown(keyCode, event);
}

From source file:us.nineworlds.serenity.ui.browser.tv.TVShowBrowserActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    SerenityGallery gallery = (SerenityGallery) findViewById(R.id.tvShowBannerGallery);

    boolean menuKeySlidingMenu = preferences.getBoolean("remote_control_menu", true);
    if (menuKeySlidingMenu) {
        if (keyCode == KeyEvent.KEYCODE_MENU) {
            if (drawerLayout.isDrawerOpen(linearDrawerLayout)) {
                drawerLayout.closeDrawers();
            } else {
                drawerLayout.openDrawer(linearDrawerLayout);
            }//www .j  av  a  2 s.  co m
            return true;
        }
    }

    if (keyCode == KeyEvent.KEYCODE_BACK && drawerLayout.isDrawerOpen(linearDrawerLayout)) {
        drawerLayout.closeDrawers();
        if (gallery != null) {
            gallery.requestFocusFromTouch();
        }
        return true;
    }

    if (gallery == null) {
        return super.onKeyDown(keyCode, event);
    }

    AbstractPosterImageGalleryAdapter adapter = (AbstractPosterImageGalleryAdapter) gallery.getAdapter();
    if (adapter != null) {
        int itemsCount = adapter.getCount();

        if (contextMenuRequested(keyCode)) {
            View view = gallery.getSelectedView();
            view.performLongClick();
            return true;
        }
        if (isKeyCodeSkipBack(keyCode)) {
            int selectedItem = gallery.getSelectedItemPosition();
            int newPosition = selectedItem - 10;
            if (newPosition < 0) {
                newPosition = 0;
            }
            gallery.setSelection(newPosition);
            gallery.requestFocusFromTouch();
            return true;
        }
        if (isKeyCodeSkipForward(keyCode)) {
            int selectedItem = gallery.getSelectedItemPosition();
            int newPosition = selectedItem + 10;
            if (newPosition > itemsCount) {
                newPosition = itemsCount - 1;
            }
            gallery.setSelection(newPosition);
            gallery.requestFocusFromTouch();
            return true;
        }
        if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY || keyCode == KeyEvent.KEYCODE_BUTTON_R1) {
            SeriesContentInfo info = (SeriesContentInfo) gallery.getSelectedItem();
            new FindUnwatchedAsyncTask(this).execute(info);
            return true;
        }
    }

    return super.onKeyDown(keyCode, event);
}

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 w  w .j a v  a2s . 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;
}