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:me.xiaopan.sketchsample.activity.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_MENU) {
        if (drawerLayout.isDrawerOpen(Gravity.LEFT)) {
            drawerLayout.closeDrawer(Gravity.LEFT);
        } else {//from w  w  w  .j av  a2 s.c o m
            drawerLayout.openDrawer(Gravity.LEFT);
        }
        return true;
    } else {
        return super.onKeyDown(keyCode, event);
    }
}

From source file:com.mschlauch.comfortreader.FullscreenActivity.java

public boolean onKeyDown(int keyCode, KeyEvent event) {

    int duration = Toast.LENGTH_SHORT;

    //VOLUME KEY DOWN
    if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        Context context = getApplicationContext();
        CharSequence text = "??";

        if (started == false) {
            previousButtonClicked(contentView);

            text = "<<";

        }/*www  . j  a  v  a2 s. c  o  m*/
        toast = Toast.makeText(context, text, duration);
        toast.show();

        stop();
        keyCode = -900000;
        return true;
    }
    //VOLUME KEY UP
    else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {

        Context context = getApplicationContext();
        CharSequence text = "";

        if (started == true) {

            text = "??";
            toast = Toast.makeText(context, text, duration);
            toast.show();

        }

        playButtonClicked(contentView);
        keyCode = -900000;
        return true;

    }

    else if (keyCode == KeyEvent.KEYCODE_MENU) {
        menuButtonClicked(contentView);
        return true;
    }
    super.onKeyDown(keyCode, event);

    return true;
}

From source file:robert.com.basiclibrary.base.BaseActivity.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (isOnKeyLongPress) {
        isOnKeyLongPress = false;//from ww w .  ja v a 2  s. c  o m
        return true;
    }

    switch (keyCode) {
    case KeyEvent.KEYCODE_BACK:
        if (onBottomDragListener != null) {
            onBottomDragListener.onDragBottom(false);
            return true;
        }
        break;
    case KeyEvent.KEYCODE_MENU:
        if (onBottomDragListener != null) {
            onBottomDragListener.onDragBottom(true);
            return true;
        }
        break;
    default:
        break;
    }

    return super.onKeyUp(keyCode, event);
}

From source file:android.widget.TiVideoView4.java

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

    return super.onKeyDown(keyCode, event);
}

From source file:com.aegamesi.steamtrade.MainActivity.java

@Override
public boolean onKeyUp(int keyCode, @NonNull KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_MENU) {
        toggleDrawer();//from   www.  j a va2  s.c o m
        return true;
    }
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        Fragment activeFragment = getSupportFragmentManager().findFragmentById(R.id.content_frame);
        if (activeFragment instanceof FragmentWeb) {
            // go *back* if possible
            if (((FragmentWeb) activeFragment).onBackPressed())
                return true;
        }
    }

    return super.onKeyUp(keyCode, event);
}

From source file:CookieVideoView.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 av  a 2s  .c  om*/
                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:net.olejon.spotcommander.WebViewActivity.java

@Override
public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_BACK: {
        event.startTracking();/*from   ww  w  .  j  a v a2s .co  m*/
        return true;
    }
    case KeyEvent.KEYCODE_MENU: {
        return true;
    }
    case KeyEvent.KEYCODE_SEARCH: {
        return true;
    }
    case KeyEvent.KEYCODE_VOLUME_DOWN: {
        return true;
    }
    case KeyEvent.KEYCODE_VOLUME_UP: {
        return true;
    }
    default: {
        return super.onKeyDown(keyCode, event);
    }
    }
}

From source file:com.mobilevue.vod.VideoControllerView.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (mPlayer == null) {
        return true;
    }/*from w  ww. j a  va2 s . c om*/

    int keyCode = event.getKeyCode();
    final boolean uniqueDown = event.getRepeatCount() == 0 && event.getAction() == KeyEvent.ACTION_DOWN;
    if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE
            || keyCode == KeyEvent.KEYCODE_SPACE) {
        if (uniqueDown) {
            doPauseResume();
            show(sDefaultTimeout);
            if (mPauseButton != null) {
                mPauseButton.requestFocus();
            }
        }
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY) {
        if (uniqueDown && !mPlayer.isPlaying()) {
            mPlayer.start();
            updatePausePlay();
            show(sDefaultTimeout);
        }
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE) {
        if (uniqueDown && mPlayer.isPlaying()) {
            mPlayer.pause();
            updatePausePlay();
            show(sDefaultTimeout);
        }
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP
            || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) {
        // don't show the controls for volume adjustment
        return super.dispatchKeyEvent(event);
    } else if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_MENU) {
        if (uniqueDown) {
            hide();
        }
        return true;
    }

    show(sDefaultTimeout);
    return super.dispatchKeyEvent(event);
}

From source file:net.olejon.spotcommander.WebViewActivity.java

@Override
public boolean onKeyUp(int keyCode, @NonNull KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_MENU: {
        mWebView.loadUrl("javascript:nativeAppAction('menu')");
        return true;
    }/*from  w  w w  . j  a  v  a  2s . c o  m*/
    case KeyEvent.KEYCODE_SEARCH: {
        mWebView.loadUrl("javascript:nativeAppAction('search')");
        return true;
    }
    case KeyEvent.KEYCODE_BACK: {
        if (mHasLongPressedBack)
            return true;

        if (mWebView.canGoBack() && mWebView.getUrl().contains("accounts.spotify.com/")
                || mWebView.canGoBack() && mWebView.getUrl().contains("facebook.com/")) {
            mWebView.goBack();

            return true;
        } else if (mWebView.canGoBack() || mTools.getSharedPreferencesBoolean("CAN_CLOSE_COVER")) {
            mWebView.loadUrl("javascript:nativeAppAction('back')");

            return true;
        }

        mTools.showToast(getString(R.string.webview_back), 1);

        return true;
    }
    case KeyEvent.KEYCODE_VOLUME_DOWN: {
        mWebView.loadUrl("javascript:nativeAppAction('volume_down')");
        return true;
    }
    case KeyEvent.KEYCODE_VOLUME_UP: {
        mWebView.loadUrl("javascript:nativeAppAction('volume_up')");
        return true;
    }
    default: {
        return super.onKeyUp(keyCode, event);
    }
    }
}

From source file:com.ll.myapplication.vitamio.widget.VideoView.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_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
                  || keyCode == KeyEvent.KEYCODE_SPACE) {
              if (mMediaPlayer.isPlaying()) {
                  pause();//from  w w  w  .j  ava 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 {
              toggleMediaControlsVisiblity();
          }
      }

      return super.onKeyDown(keyCode, event);
  }