Java Code Examples for android.view.KeyEvent#KEYCODE_VOLUME_DOWN

The following examples show how to use android.view.KeyEvent#KEYCODE_VOLUME_DOWN . 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: Home.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_VOLUME_DOWN:
        case KeyEvent.KEYCODE_VOLUME_UP:
        case KeyEvent.KEYCODE_VOLUME_MUTE:
            if (JoH.quietratelimit("button-press", 5)) {
                if (Pref.getBooleanDefaultFalse("buttons_silence_alert")) {
                    final ActiveBgAlert activeBgAlert = ActiveBgAlert.getOnly();
                    if (activeBgAlert != null) {
                        AlertPlayer.getPlayer().Snooze(xdrip.getAppContext(), -1);
                        final String msg = "Snoozing alert due to volume button press";
                        JoH.static_toast_long(msg);
                        UserError.Log.ueh(TAG, msg);
                    } else {
                        if (d) UserError.Log.d(TAG, "no active alert to snooze");
                    }
                } else {
                    if (d) UserError.Log.d(TAG, "No action as preference is disabled");
                }
            }
            break;
    }
    if (d) Log.d(TAG, "Keydown event: " + keyCode + " event: " + event.toString());
    return super.onKeyDown(keyCode, event);
}
 
Example 2
Source File: MovieActivity.java    From android with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (mCastManager != null && mCastManager.isConnected()) {
        if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
            changeVolume(CastApplication.VOLUME_INCREMENT);
        } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
            changeVolume(-CastApplication.VOLUME_INCREMENT);
        } else {
            // we don't want to consume non-volume key events
            return super.onKeyDown(keyCode, event);
        }
        if (mCastManager.getPlaybackStatus() == MediaStatus.PLAYER_STATE_PLAYING) {
            return super.onKeyDown(keyCode, event);
        } else {
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 3
Source File: CordovaWebView.java    From crosswalk-cordova-android with Apache License 2.0 6 votes vote down vote up
public void setButtonPlumbedToJs(int keyCode, boolean override) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_VOLUME_DOWN:
        case KeyEvent.KEYCODE_VOLUME_UP:
        case KeyEvent.KEYCODE_BACK:
            // 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 4
Source File: ArticleCollectionActivity.java    From aard2-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
    if (!useVolumeForNav()) {
        return false;
    }
    ArticleFragment af = articleCollectionPagerAdapter.getPrimaryItem();
    if (af != null) {
        ArticleWebView webView = af.getWebView();

        if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
            webView.pageUp(true);
            return true;
        }
        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
            webView.pageDown(true);
            return true;
        }
    }
    return super.onKeyLongPress(keyCode, event);
}
 
Example 5
Source File: PlayerActivity.java    From monkeyboard-radio-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent keyEvent) {
    if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        if (playerBound) {
            if (!playerService.isPlaying()) {
                updateVolume(playerService.getPlayerVolume());
            }
        }
    } else if (!sharedPreferences.getBoolean(
            getString(R.string.PREF_HEADUNIT_CONTROLLER_INPUT),
            false
        )) {
        if (handleKeyDown(keyCode)) {
            return true;
        }
    } else {
        // Custom input has already been handled
        switch(keyCode) {
            case KeyEvent.KEYCODE_DPAD_DOWN:
            case KeyEvent.KEYCODE_DPAD_LEFT:
            case KeyEvent.KEYCODE_DPAD_RIGHT:
            case KeyEvent.KEYCODE_DPAD_CENTER:
            case KeyEvent.KEYCODE_TAB:
            case KeyEvent.KEYCODE_DPAD_UP:
            case KeyEvent.KEYCODE_ENTER:
                return true;
         }
    }
    return super.onKeyDown(keyCode, keyEvent);
}
 
Example 6
Source File: AssetVideoView.java    From ResearchStack 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 7
Source File: CaptureIntentModule.java    From Camera2 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyUp(int keyCode, KeyEvent event)
{
    switch (keyCode)
    {
        case KeyEvent.KEYCODE_VOLUME_UP:
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            mStateMachine.processEvent(new EventClickOnCameraKey());
            return true;
    }
    return false;
}
 
Example 8
Source File: VideoView.java    From BambooPlayer 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: CameraActivity.java    From tensorflow-classifier-android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyDown(final int keyCode, final KeyEvent event) {
  if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
    debug = !debug;
    requestRender();
    onSetDebug(debug);
    return true;
  }
  return super.onKeyDown(keyCode, event);
}
 
Example 10
Source File: GamePadActivity.java    From bombsquad-remote-android with Apache License 2.0 5 votes vote down vote up
boolean _isRunKey(int keyCode) {
  switch (keyCode) {
    case KeyEvent.KEYCODE_BUTTON_R1:
    case KeyEvent.KEYCODE_BUTTON_R2:
    case KeyEvent.KEYCODE_BUTTON_L1:
    case KeyEvent.KEYCODE_BUTTON_L2:
    case KeyEvent.KEYCODE_VOLUME_UP:
    case KeyEvent.KEYCODE_VOLUME_DOWN:
      return true;
    default:
      return false;
  }
}
 
Example 11
Source File: ArrowKeyMovementMethod.java    From PowerFileExplorer with GNU General Public License v3.0 5 votes vote down vote up
public boolean onKeyUp(TextView widget, Spannable buffer, int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_VOLUME_UP:
        if ( sUseVolumeKey ){
            return true;
        }
        break;
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        if ( sUseVolumeKey ){
            return true;
        }
        break;
    }
    return false;
}
 
Example 12
Source File: GenericUiControls.java    From BluetoothHidEmu with Apache License 2.0 5 votes vote down vote up
/**
 * onKeyDown()
 */
@Override
public boolean processKeyDown(int keyCode, KeyEvent event) {
    
    if (mEchoEditText != null && (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
        KeyListener keyListener = mEchoEditText.getKeyListener();
        keyListener.onKeyDown(mEchoEditText, mEchoEditText.getEditableText(), keyCode, event);
        return true;
    }
    return false;
}
 
Example 13
Source File: VoIPActivity.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (isIncomingWaiting && (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP)) {
        if (VoIPService.getSharedInstance() != null)
            VoIPService.getSharedInstance().stopRinging();
        else
            finish();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 14
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 15
Source File: MainActivity.java    From XMouse with MIT License 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
	switch(keyCode){
 	/*case KeyEvent.KEYCODE_MENU:
   case KeyEvent.KEYCODE_SEARCH:
   case KeyEvent.KEYCODE_BACK:*/
		case KeyEvent.KEYCODE_VOLUME_UP:
			event.startTracking();
			return true;
		case KeyEvent.KEYCODE_VOLUME_DOWN:
			event.startTracking();
			return true;
	}
	return super.onKeyDown(keyCode, event);
}
 
Example 16
Source File: PlaybackControls.java    From iview-android-tv with MIT License 4 votes vote down vote up
public boolean dispatchKeyEvent(KeyEvent event, int timeout) {
    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(timeout);
            if (mPauseButton != null) {
                mPauseButton.requestFocus();
            }
        }
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY) {
        if (uniqueDown && !mPlayer.isPlaying()) {
            mPlayer.start();
            updatePausePlay();
            show(timeout);
        }
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP
            || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE) {
        if (uniqueDown && mPlayer.isPlaying()) {
            mPlayer.pause();
            updatePausePlay();
            show(timeout);
        }
        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(timeout);
    return false;
}
 
Example 17
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 18
Source File: AppRunnerActivity.java    From PHONK with GNU General Public License v3.0 4 votes vote down vote up
public boolean checkVolumeKeys(int keyCode) {
    return ignoreVolumeEnabled && (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN);
}
 
Example 19
Source File: ContentVideoView.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public boolean onKey(View v, 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_CALL &&
                                 keyCode != KeyEvent.KEYCODE_MENU &&
                                 keyCode != KeyEvent.KEYCODE_SEARCH &&
                                 keyCode != KeyEvent.KEYCODE_ENDCALL;
    if (isInPlaybackState() && isKeyCodeSupported && mControls != null) {
        if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK ||
                keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) {
            if (isPlaying()) {
                pause();
                mControls.show();
            } else {
                start();
                mControls.hide();
            }
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY) {
            if (!isPlaying()) {
                start();
                mControls.hide();
            }
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP
                || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE) {
            if (isPlaying()) {
                pause();
                mControls.show();
            }
            return true;
        } else {
            toggleMediaControlsVisiblity();
        }
    } else if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
        exitFullscreen(false);
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_MENU || keyCode == KeyEvent.KEYCODE_SEARCH) {
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 20
Source File: CordovaWebViewImpl.java    From cordova-plugin-app-update-demo with MIT License 4 votes vote down vote up
@Override
public Boolean onDispatchKeyEvent(KeyEvent event) {
    int keyCode = event.getKeyCode();
    boolean isBackButton = keyCode == KeyEvent.KEYCODE_BACK;
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        if (isBackButton && mCustomView != null) {
            return true;
        } else if (boundKeyCodes.contains(keyCode)) {
            return true;
        } else if (isBackButton) {
            return engine.canGoBack();
        }
    } else if (event.getAction() == KeyEvent.ACTION_UP) {
        if (isBackButton && mCustomView != null) {
            hideCustomView();
            return true;
        } else if (boundKeyCodes.contains(keyCode)) {
            String eventName = null;
            switch (keyCode) {
                case KeyEvent.KEYCODE_VOLUME_DOWN:
                    eventName = "volumedownbutton";
                    break;
                case KeyEvent.KEYCODE_VOLUME_UP:
                    eventName = "volumeupbutton";
                    break;
                case KeyEvent.KEYCODE_SEARCH:
                    eventName = "searchbutton";
                    break;
                case KeyEvent.KEYCODE_MENU:
                    eventName = "menubutton";
                    break;
                case KeyEvent.KEYCODE_BACK:
                    eventName = "backbutton";
                    break;
            }
            if (eventName != null) {
                sendJavascriptEvent(eventName);
                return true;
            }
        } else if (isBackButton) {
            return engine.goBack();
        }
    }
    return null;
}