Example usage for android.view KeyEvent KEYCODE_MENU

List of usage examples for android.view KeyEvent KEYCODE_MENU

Introduction

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

Prototype

int KEYCODE_MENU

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

Click Source Link

Document

Key code constant: Menu key.

Usage

From source file:com.supremainc.biostar2.main.HomeActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    switch (event.getKeyCode()) {
    case KeyEvent.KEYCODE_MENU:
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            mLayout.onDrawMenu();//from  ww w. j  av  a  2 s  .  c om
        }
        return true;
    }
    return super.dispatchKeyEvent(event);
}

From source file:com.aimfire.demo.CameraActivity.java

public boolean onKeyDown(int keyCode, KeyEvent event) {
    //if((keyCode == KeyEvent.KEYCODE_VOLUME_UP) || 
    //(keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) ||
    //(keyCode == KeyEvent.KEYCODE_CAMERA))
    if (keyCode == KeyEvent.KEYCODE_CAMERA) {
        clickCapture(null);/*from   w ww .  ja  v  a2s.c o  m*/
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_MENU) {
        /*
         * TODO: handle hardware menu button
         */
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:org.videolan.vlc.gui.MyFragment.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override/*from  w w w .ja  v  a  2  s .  c  om*/
public boolean onKeyUp(int keyCode, KeyEvent event) {
    //Filter for LG devices, see https://code.google.com/p/android/issues/detail?id=78154
    if ((keyCode == KeyEvent.KEYCODE_MENU) && (Build.VERSION.SDK_INT <= 16)
            && (Build.MANUFACTURER.compareTo("LGE") == 0)) {
        openOptionsMenu();
        return true;
    }
    View v = getCurrentFocus();
    if (v == null)
        return super.onKeyUp(keyCode, event);
    if ((mActionBarIconId == -1) && (v.getId() == -1) && (v.getNextFocusDownId() == -1)
            && (v.getNextFocusUpId() == -1) && (v.getNextFocusLeftId() == -1)
            && (v.getNextFocusRightId() == -1)) {
        mActionBarIconId = Util.generateViewId();
        v.setId(mActionBarIconId);
        v.setNextFocusUpId(mActionBarIconId);
        v.setNextFocusDownId(mActionBarIconId);
        v.setNextFocusLeftId(mActionBarIconId);
        v.setNextFocusRightId(R.id.ml_menu_search);
        if (AndroidUtil.isHoneycombOrLater())
            v.setNextFocusForwardId(mActionBarIconId);
        if (findViewById(R.id.ml_menu_search) != null)
            findViewById(R.id.ml_menu_search).setNextFocusLeftId(mActionBarIconId);
    }
    return super.onKeyUp(keyCode, event);
}

From source file:com.vuze.android.remote.activity.TorrentViewActivity.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {

    if (AndroidUtilsUI.sendOnKeyToFragments(this, keyCode, event)) {
        return true;
    }//w w  w  .  j av a2  s.  com

    switch (keyCode) {
    case KeyEvent.KEYCODE_PROG_RED: {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            finishAffinity();
        }
        break;
    }
    case KeyEvent.KEYCODE_MENU: {
        if (super.onKeyUp(keyCode, event)) {
            return true;
        }
        if (toolbar != null) {
            return toolbar.showOverflowMenu();
        }

        break;
    }
    }
    return super.onKeyUp(keyCode, event);
}

From source file:com.lybeat.lilyplayer.widget.media.IjkVideoView.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    boolean isKeyCodeSupported = keyCode != KeyEvent.KEYCODE_BACK && keyCode != KeyEvent.KEYCODE_VOLUME_UP
            && keyCode != KeyEvent.KEYCODE_VOLUME_DOWN && keyCode != KeyEvent.KEYCODE_VOLUME_MUTE
            && keyCode != KeyEvent.KEYCODE_MENU && keyCode != KeyEvent.KEYCODE_CALL
            && keyCode != KeyEvent.KEYCODE_ENDCALL;
    if (isInPlaybackState() && isKeyCodeSupported && mMediaController != null) {
        if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) {
            if (mMediaPlayer.isPlaying()) {
                pause();/* w  w w  . j  a v  a 2  s. co  m*/
                mMediaController.show();
            } else {
                start();
                mMediaController.hide();
            }
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY) {
            if (!mMediaPlayer.isPlaying()) {
                start();
                mMediaController.hide();
            }
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE) {
            if (mMediaPlayer.isPlaying()) {
                pause();
                mMediaController.show();
            }
            return true;
        } else {
            toggleMediaControlsVisibility();
        }
    }

    return super.onKeyDown(keyCode, event);
}

From source file:com.xnxs.mediaplayer.widget.media.VRVideoView.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    boolean isKeyCodeSupported = keyCode != KeyEvent.KEYCODE_BACK && keyCode != KeyEvent.KEYCODE_VOLUME_UP
            && keyCode != KeyEvent.KEYCODE_VOLUME_DOWN && keyCode != KeyEvent.KEYCODE_VOLUME_MUTE
            && keyCode != KeyEvent.KEYCODE_MENU && keyCode != KeyEvent.KEYCODE_CALL
            && keyCode != KeyEvent.KEYCODE_ENDCALL;
    if (isInPlaybackState() && isKeyCodeSupported && mMediaController != null) {
        if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) {
            if (mMediaPlayer.isPlaying()) {
                pause();/*from w  w w . jav a  2  s. c o  m*/
                mMediaController.show();
            } else {
                start();
                mMediaController.hide();
            }
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY) {
            if (!mMediaPlayer.isPlaying()) {
                start();
                mMediaController.hide();
            }
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE) {
            if (mMediaPlayer.isPlaying()) {
                pause();
                mMediaController.show();
            }
            return true;
        } else {
            toggleMediaControlsVisiblity();
        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.android.launcher2.Launcher.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    final int uniChar = event.getUnicodeChar();
    final boolean handled = super.onKeyDown(keyCode, event);
    final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
    if (!handled && acceptFilter() && isKeyNotWhitespace) {
        boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb, keyCode, event);
        if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
            // something usable has been typed - start a search
            // the typed text will be retrieved and cleared by
            // showSearchDialog()
            // If there are multiple keystrokes before the search dialog takes focus,
            // onSearchRequested() will be called for every keystroke,
            // but it is idempotent, so it's fine.
            return onSearchRequested();
        }//from w w w  .j a  va  2  s  . co  m
    }

    // Eat the long press event so the keyboard doesn't come up.
    if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
        return true;
    }

    return handled;
}

From source file:android.support.v7ox.app.AppCompatDelegateImplV7.java

@Override
boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getKeyCode() == KeyEvent.KEYCODE_MENU) {
        // If this is a MENU event, let the Activity have a go.
        if (mOriginalWindowCallback.dispatchKeyEvent(event)) {
            return true;
        }/*from w  w  w.  ja v a  2 s .  c  o m*/
    }

    final int keyCode = event.getKeyCode();
    final int action = event.getAction();
    final boolean isDown = action == KeyEvent.ACTION_DOWN;

    return isDown ? onKeyDown(keyCode, event) : onKeyUp(keyCode, event);
}

From source file:android.support.v7ox.app.AppCompatDelegateImplV7.java

boolean onKeyUp(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_MENU:
        onKeyUpPanel(Window.FEATURE_OPTIONS_PANEL, event);
        return true;
    case KeyEvent.KEYCODE_BACK:
        final boolean wasLongPressBackDown = mLongPressBackDown;
        mLongPressBackDown = false;//from w w  w  .  j a v a  2 s  .  c om

        PanelFeatureState st = getPanelState(Window.FEATURE_OPTIONS_PANEL, false);
        if (st != null && st.isOpen) {
            if (!wasLongPressBackDown) {
                // Certain devices allow opening the options menu via a long press of the
                // back button. We should only close the open options menu if it wasn't
                // opened via a long press gesture.
                closePanel(st, true);
            }
            return true;
        }
        if (onBackPressed()) {
            return true;
        }
        break;
    }
    return false;
}

From source file:com.phonegap.DroidGap.java

/**
 * Called when a key is pressed./*ww  w.ja  va2  s . c  o m*/
 * 
 * @param keyCode
 * @param event
 */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

    // If back key
    if (keyCode == KeyEvent.KEYCODE_BACK) {

        // If back key is bound, then send event to JavaScript
        if (mKey.isBound()) {
            this.appView.loadUrl("javascript:document.keyEvent.backTrigger()");
        }

        // If not bound
        else {

            // Go to previous page in webview if it is possible to go back
            if (this.appView.canGoBack()) {
                this.appView.goBack();
            }

            // If not, then invoke behavior of super class
            else {
                return super.onKeyDown(keyCode, event);
            }
        }
    }

    // If menu key
    else if (keyCode == KeyEvent.KEYCODE_MENU) {
        appView.loadUrl("javascript:keyEvent.menuTrigger()");
    }

    // If search key
    else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
        appView.loadUrl("javascript:keyEvent.searchTrigger()");
    }

    return false;
}