Java Code Examples for android.view.KeyEvent#KEYCODE_MENU

The following examples show how to use android.view.KeyEvent#KEYCODE_MENU . 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: BrowserActivity.java    From JumpGo with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_ENTER) {
        if (mSearch.hasFocus()) {
            searchTheWeb(mSearch.getText().toString());
        }
    } else if ((keyCode == KeyEvent.KEYCODE_MENU)
        && (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN)
        && (Build.MANUFACTURER.compareTo("LGE") == 0)) {
        // Workaround for stupid LG devices that crash
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_BACK) {
        mKeyDownStartTime = System.currentTimeMillis();
        Handlers.MAIN.postDelayed(mLongPressBackRunnable, ViewConfiguration.getLongPressTimeout());
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 2
Source File: CordovaWebViewImpl.java    From xmall with MIT License 6 votes vote down vote up
@Override
public void setButtonPlumbedToJs(int keyCode, boolean override) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_VOLUME_DOWN:
        case KeyEvent.KEYCODE_VOLUME_UP:
        case KeyEvent.KEYCODE_BACK:
        case KeyEvent.KEYCODE_MENU:
            // TODO: Why are search and menu buttons handled separately?
            if (override) {
                boundKeyCodes.add(keyCode);
            } else {
                boundKeyCodes.remove(keyCode);
            }
            return;
        default:
            throw new IllegalArgumentException("Unsupported keycode: " + keyCode);
    }
}
 
Example 3
Source File: MainActivity.java    From BookReader with Apache License 2.0 6 votes vote down vote up
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN
            && event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
        if (System.currentTimeMillis() - currentBackPressedTime > BACK_PRESSED_INTERVAL) {
            currentBackPressedTime = System.currentTimeMillis();
            ToastUtils.showToast(getString(R.string.exit_tips));
            return true;
        } else {
            finish(); // 退出
        }
    } else if (event.getKeyCode() == KeyEvent.KEYCODE_MENU) {
        return true;
    }
    return super.dispatchKeyEvent(event);
}
 
Example 4
Source File: CordovaActivity.java    From CordovaYoutubeVideoPlayer with MIT License 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
    //Determine if the focus is on the current view or not
    if (appView != null && appView.getFocusedChild() != null && (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_MENU)) {
                return appView.onKeyDown(keyCode, event);
    }
    else
        return super.onKeyDown(keyCode, event);
}
 
Example 5
Source File: ActionBarLayout.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public boolean onKeyUp(int keyCode, KeyEvent event)
{
    if (keyCode == KeyEvent.KEYCODE_MENU && !checkTransitionAnimation() && !startedTracking && currentActionBar != null)
    {
        currentActionBar.onMenuButtonPressed();
    }
    return super.onKeyUp(keyCode, event);
}
 
Example 6
Source File: AppCompatPreferenceActivity.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
@SuppressLint("RestrictedApi")
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    // Let support action bars open menus in response to the menu key prioritized over
    // the window handling it
    final int keyCode = event.getKeyCode();
    final ActionBar actionBar = getSupportActionBar();
    if (keyCode == KeyEvent.KEYCODE_MENU
        && actionBar != null && actionBar.onMenuKeyEvent(event)) {
        return true;
    }
    return super.dispatchKeyEvent(event);
}
 
Example 7
Source File: MemoActivity.java    From EverMemo with MIT License 5 votes vote down vote up
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
	if (keyCode == KeyEvent.KEYCODE_MENU) {
		findViewById(R.id.more).performClick();
		return true;
	}
	return super.onKeyUp(keyCode, event);
}
 
Example 8
Source File: VideoView.java    From HPlayer with Apache License 2.0 5 votes vote down vote up
@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();
        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);
}
 
Example 9
Source File: ActionBarActivity.java    From Yahala-Messenger with MIT License 5 votes vote down vote up
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_MENU && !checkTransitionAnimation() && !startedTracking) {
        actionBar.onMenuButtonPressed();
        return true;
    }
    return super.onKeyUp(keyCode, event);
}
 
Example 10
Source File: AboutActivity.java    From LaunchTime with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if(keyCode==KeyEvent.KEYCODE_HOME) {
        Intent home = new Intent(this, MainActivity.class);
        startActivity(home);
        finish();
    } else if (keyCode==KeyEvent.KEYCODE_MENU) {
        Intent sett = new Intent(this, SettingsActivity.class);
        startActivity(sett);
        finish();
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 11
Source File: BaseActivity.java    From OpenMemories-AppStore with MIT License 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_MENU) {
        onBackPressed();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 12
Source File: CordovaWebView.java    From cordova-amazon-fireos with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
    if(boundKeyCodes.contains(keyCode))
    {
        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
                this.loadUrl("javascript:cordova.fireDocumentEvent('volumedownbutton');");
                return true;
        }
        // If volumeup key
        else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
                this.loadUrl("javascript:cordova.fireDocumentEvent('volumeupbutton');");
                return true;
        }
        else
        {
            return super.onKeyDown(keyCode, event);
        }
    }
    else if(keyCode == KeyEvent.KEYCODE_BACK)
    {
        return !(this.startOfHistory()) || isButtonPlumbedToJs(KeyEvent.KEYCODE_BACK);
    }
    else if(keyCode == KeyEvent.KEYCODE_MENU)
    {
        //How did we get here?  Is there a childView?
        View childView = this.getFocusedChild();
        if(childView != null)
        {
            //Make sure we close the keyboard if it's present
            InputMethodManager imm = (InputMethodManager) cordova.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(childView.getWindowToken(), 0);
            cordova.getActivity().openOptionsMenu();
            return true;
        } else {
            return super.onKeyDown(keyCode, event);
        }
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 13
Source File: Base.java    From COCOFramework with Apache License 2.0 5 votes vote down vote up
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (mCompatMenuKeyEnabled) {
        if (event.getKeyCode() == KeyEvent.KEYCODE_MENU && event.getAction() == KeyEvent.ACTION_UP) {
            onCompatMenuKeyPressed();
            return false;
        }
    }
    return super.dispatchKeyEvent(event);
}
 
Example 14
Source File: MainActivity.java    From WheelLogAndroid with GNU General Public License v3.0 5 votes vote down vote up
public boolean onKeyUp(int keyCode, KeyEvent event) {
    View settings_layout = findViewById(R.id.settings_layout);
    switch (keyCode) {
        case KeyEvent.KEYCODE_MENU:
            if (mDrawer.isDrawerOpen(settings_layout)) {
                mDrawer.closeDrawers();
            } else {
                mDrawer.openDrawer(GravityCompat.START, true);
            }
            return true;
        case KeyEvent.KEYCODE_BACK:
            if (mDrawer.isDrawerOpen(settings_layout)) {
                if (((PreferencesFragment) getPreferencesFragment()).is_main_menu())
                    mDrawer.closeDrawer(GravityCompat.START, true);
	else ((PreferencesFragment) getPreferencesFragment()).show_main_menu();
            } else {
                if (doubleBackToExitPressedOnce) {
                    finish();
                    return true;
                }

                doubleBackToExitPressedOnce = true;
                showSnackBar(R.string.back_to_exit);

                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        doubleBackToExitPressedOnce = false;
                    }
                }, 2000);
            }
            return true;
        default:
            return super.onKeyDown(keyCode, event);
    }
}
 
Example 15
Source File: CordovaWebView.java    From L.TileLayer.Cordova with MIT License 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
    if(boundKeyCodes.contains(keyCode))
    {
        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
            sendJavascriptEvent("volumedownbutton");
            return true;
        }
        // If volumeup key
        else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
            sendJavascriptEvent("volumeupbutton");
            return true;
        }
        else
        {
            return super.onKeyDown(keyCode, event);
        }
    }
    else if(keyCode == KeyEvent.KEYCODE_BACK)
    {
        return !(this.startOfHistory()) || isButtonPlumbedToJs(KeyEvent.KEYCODE_BACK);
    }
    else if(keyCode == KeyEvent.KEYCODE_MENU)
    {
        //How did we get here?  Is there a childView?
        View childView = this.getFocusedChild();
        if(childView != null)
        {
            //Make sure we close the keyboard if it's present
            InputMethodManager imm = (InputMethodManager) cordova.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(childView.getWindowToken(), 0);
            cordova.getActivity().openOptionsMenu();
            return true;
        } else {
            return super.onKeyDown(keyCode, event);
        }
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 16
Source File: SettingsActivity.java    From LaunchTime with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if(keyCode==KeyEvent.KEYCODE_HOME || keyCode==KeyEvent.KEYCODE_MENU) {
        Intent main = new Intent(this, MainActivity.class);
        startActivity(main);
        setResult(RESULT_OK);
        finish();
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 17
Source File: MediaPlayerView.java    From HeroVideo-master with Apache License 2.0 5 votes vote down vote up
@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();
                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);
}
 
Example 18
Source File: VRMediaController.java    From VRPlayer with Apache License 2.0 4 votes vote down vote up
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    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
            || keyCode == KeyEvent.KEYCODE_CAMERA) {
        // 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);
}
 
Example 19
Source File: ActionBarLayout.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_MENU && !checkTransitionAnimation() && !startedTracking && currentActionBar != null) {
        currentActionBar.onMenuButtonPressed();
    }
    return super.onKeyUp(keyCode, event);
}
 
Example 20
Source File: CustomMediaController.java    From AndroidTvDemo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean dispatchKeyEvent(KeyEvent event)
{
    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 || keyCode == KeyEvent.KEYCODE_CAMERA)
    {
        // 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);
}