Java Code Examples for android.view.KeyEvent#KEYCODE_BUTTON_R1

The following examples show how to use android.view.KeyEvent#KEYCODE_BUTTON_R1 . 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: PlaybackActivity.java    From tv-samples with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BUTTON_R1) {
        mPlaybackFragment.skipToNext();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_BUTTON_L1) {
        mPlaybackFragment.skipToPrevious();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_BUTTON_L2) {
        mPlaybackFragment.rewind();
    } else if (keyCode == KeyEvent.KEYCODE_BUTTON_R2) {
        mPlaybackFragment.fastForward();
    }

    return super.onKeyDown(keyCode, event);
}
 
Example 2
Source File: PlaybackActivity.java    From androidtv-Leanback with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BUTTON_R1) {
        mPlaybackFragment.skipToNext();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_BUTTON_L1) {
        mPlaybackFragment.skipToPrevious();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_BUTTON_L2) {
        mPlaybackFragment.rewind();
    } else if (keyCode == KeyEvent.KEYCODE_BUTTON_R2) {
        mPlaybackFragment.fastForward();
    }

    return super.onKeyDown(keyCode, event);
}
 
Example 3
Source File: GamepadController.java    From AndroidDemoProjects with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the tracked state values of this controller in response to a key input event.
 */
public void handleKeyEvent(KeyEvent keyEvent) {
    boolean keyIsDown = keyEvent.getAction() == KeyEvent.ACTION_DOWN;

    if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BUTTON_A) {
        mButtonState[BUTTON_A][FRAME_INDEX_CURRENT] = keyIsDown;
    } else if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BUTTON_B) {
        mButtonState[BUTTON_B][FRAME_INDEX_CURRENT] = keyIsDown;
    } else if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BUTTON_X) {
        mButtonState[BUTTON_X][FRAME_INDEX_CURRENT] = keyIsDown;
    } else if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BUTTON_Y) {
        mButtonState[BUTTON_Y][FRAME_INDEX_CURRENT] = keyIsDown;
    } else if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BUTTON_R1 ) {
        mButtonState[BUTTON_R1][FRAME_INDEX_CURRENT] = keyIsDown;
    } else if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BUTTON_R2 ) {
        mButtonState[BUTTON_R2][FRAME_INDEX_CURRENT] = keyIsDown;
    } else if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BUTTON_L1 ) {
        mButtonState[BUTTON_L1][FRAME_INDEX_CURRENT] = keyIsDown;
    } else if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BUTTON_L2 ) {
        mButtonState[BUTTON_L2][FRAME_INDEX_CURRENT] = keyIsDown;
    }
}
 
Example 4
Source File: ControllerMappingHelper.java    From citra_android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Some controllers report extra button presses that can be ignored.
 */
public boolean shouldKeyBeIgnored(InputDevice inputDevice, int keyCode)
{
  if (isDualShock4(inputDevice))
  {
    // The two analog triggers generate analog motion events as well as a keycode.
    // We always prefer to use the analog values, so throw away the button press
    // Even though the triggers are L/R2, without mappings they generate L/R1 events.
    return keyCode == KeyEvent.KEYCODE_BUTTON_L1 || keyCode == KeyEvent.KEYCODE_BUTTON_R1;
  }
  return false;
}
 
Example 5
Source File: AndroidControllerMapping.java    From gdx-controllerutils with Apache License 2.0 5 votes vote down vote up
AndroidControllerMapping() {
    super(0, 1, 2, 3,
            KeyEvent.KEYCODE_BUTTON_A, KeyEvent.KEYCODE_BUTTON_B,
            KeyEvent.KEYCODE_BUTTON_X, KeyEvent.KEYCODE_BUTTON_Y,
            KeyEvent.KEYCODE_BACK, KeyEvent.KEYCODE_BUTTON_START,
            KeyEvent.KEYCODE_BUTTON_L1, KeyEvent.KEYCODE_BUTTON_L2,
            KeyEvent.KEYCODE_BUTTON_R1, KeyEvent.KEYCODE_BUTTON_R2,
            KeyEvent.KEYCODE_BUTTON_THUMBL, KeyEvent.KEYCODE_BUTTON_THUMBR);
}
 
Example 6
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 7
Source File: GamepadMappings.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Method for mapping the L1/R1 buttons to lower shoulder buttons, rather than
 * upper shoulder as the user would normally expect. Please think twice before
 * using this, as it can easily confuse the user. It is only really useful if
 * the controller completely lacks a second set of shoulder buttons.
 */
private static void mapUpperTriggerButtonsToBottomShoulder(float[] mappedButtons,
        float[] rawButtons) {
    float l1 = rawButtons[KeyEvent.KEYCODE_BUTTON_L1];
    float r1 = rawButtons[KeyEvent.KEYCODE_BUTTON_R1];
    mappedButtons[CanonicalButtonIndex.LEFT_TRIGGER] = l1;
    mappedButtons[CanonicalButtonIndex.RIGHT_TRIGGER] = r1;
}
 
Example 8
Source File: AudioPlayerActivity.java    From VCL-Android with Apache License 2.0 4 votes vote down vote up
public boolean onKeyDown(int keyCode, KeyEvent event){
    switch (keyCode){
        /*
         * Playback control
         */
        case KeyEvent.KEYCODE_MEDIA_PLAY:
        case KeyEvent.KEYCODE_MEDIA_PAUSE:
        case KeyEvent.KEYCODE_SPACE:
            togglePlayPause();
            return true;
        case KeyEvent.KEYCODE_MEDIA_STOP:
            mService.stop();
            finish();
            return true;
        case KeyEvent.KEYCODE_F:
        case KeyEvent.KEYCODE_BUTTON_R1:
            goNext();
            return true;
        case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
            seek(10000);
            return true;
        case KeyEvent.KEYCODE_MEDIA_REWIND:
            seek(-10000);
            return true;
        case KeyEvent.KEYCODE_R:
        case KeyEvent.KEYCODE_BUTTON_L1:
            goPrevious();
            return true;
        /*
         * Playlist navigation
         */
        case KeyEvent.KEYCODE_DPAD_UP:
            selectPrevious();
            mRecyclerView.requestFocus();
            return true;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            selectNext();
            mRecyclerView.requestFocus();
            return true;
        case KeyEvent.KEYCODE_DPAD_CENTER:
            if (mRecyclerView.hasFocus()) {
                playSelection();
                return true;
            } else
            return false;
        default:
            return super.onKeyDown(keyCode, event);
    }
}
 
Example 9
Source File: VideoPlayerActivity.java    From VCL-Android with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_BUTTON_B)
        return super.onKeyDown(keyCode, event);
    if (mIsLoading) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_S:
            case KeyEvent.KEYCODE_MEDIA_STOP:
                exitOK();
                return true;
        }
        return false;
    }
    showOverlayTimeout(OVERLAY_TIMEOUT);
    switch (keyCode) {
    case KeyEvent.KEYCODE_F:
    case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
    case KeyEvent.KEYCODE_MEDIA_NEXT:
        seekDelta(10000);
        return true;
    case KeyEvent.KEYCODE_R:
    case KeyEvent.KEYCODE_MEDIA_REWIND:
    case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
        seekDelta(-10000);
        return true;
    case KeyEvent.KEYCODE_BUTTON_R1:
        seekDelta(60000);
        return true;
    case KeyEvent.KEYCODE_BUTTON_L1:
        seekDelta(-60000);
        return true;
    case KeyEvent.KEYCODE_BUTTON_A:
        if (mOverlayProgress.getVisibility() == View.VISIBLE)
            return false;
    case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
    case KeyEvent.KEYCODE_MEDIA_PLAY:
    case KeyEvent.KEYCODE_MEDIA_PAUSE:
    case KeyEvent.KEYCODE_SPACE:
        if (mIsNavMenu)
            return navigateDvdMenu(keyCode);
        else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) //prevent conflict with remote control
            return super.onKeyDown(keyCode, event);
        else
            doPlayPause();
        return true;
    case KeyEvent.KEYCODE_O:
    case KeyEvent.KEYCODE_BUTTON_Y:
    case KeyEvent.KEYCODE_MENU:
        showAdvancedOptions(mAdvOptions);
        return true;
    case KeyEvent.KEYCODE_V:
    case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
    case KeyEvent.KEYCODE_BUTTON_X:
        onAudioSubClick(mTracks);
        return true;
    case KeyEvent.KEYCODE_N:
        showNavMenu();
        return true;
    case KeyEvent.KEYCODE_A:
        resizeVideo();
        return true;
    case KeyEvent.KEYCODE_M:
    case KeyEvent.KEYCODE_VOLUME_MUTE:
        updateMute();
        return true;
    case KeyEvent.KEYCODE_S:
    case KeyEvent.KEYCODE_MEDIA_STOP:
        exitOK();
        return true;
    case KeyEvent.KEYCODE_DPAD_UP:
    case KeyEvent.KEYCODE_DPAD_DOWN:
    case KeyEvent.KEYCODE_DPAD_LEFT:
    case KeyEvent.KEYCODE_DPAD_RIGHT:
    case KeyEvent.KEYCODE_DPAD_CENTER:
    case KeyEvent.KEYCODE_ENTER:
        if (mIsNavMenu)
            return navigateDvdMenu(keyCode);
        else
            return super.onKeyDown(keyCode, event);
    case KeyEvent.KEYCODE_J:
        delayAudio(-50000l);
        return true;
    case KeyEvent.KEYCODE_K:
        delayAudio(50000l);
        return true;
    case KeyEvent.KEYCODE_G:
        delaySubs(-50000l);
        return true;
    case KeyEvent.KEYCODE_H:
        delaySubs(50000l);
        return true;
    case KeyEvent.KEYCODE_VOLUME_DOWN:
    case KeyEvent.KEYCODE_VOLUME_UP:
        if (mMute) {
            updateMute();
            return true;
        } else
            return false;
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 10
Source File: GamepadMappings.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private static void mapTriggerButtonsToTopShoulder(float[] mappedButtons, float[] rawButtons) {
    float l1 = rawButtons[KeyEvent.KEYCODE_BUTTON_L1];
    float r1 = rawButtons[KeyEvent.KEYCODE_BUTTON_R1];
    mappedButtons[CanonicalButtonIndex.LEFT_SHOULDER] = l1;
    mappedButtons[CanonicalButtonIndex.RIGHT_SHOULDER] = r1;
}
 
Example 11
Source File: AndroidJoystickJoyInput14.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
protected JoystickButton addButton( int keyCode ) {

//            logger.log(Level.FINE, "Adding button: {0}", keyCode);

            String name = KeyEvent.keyCodeToString(keyCode);
            String original = KeyEvent.keyCodeToString(keyCode);
            // A/B/X/Y buttons
            if (keyCode == KeyEvent.KEYCODE_BUTTON_Y) {
                original = JoystickButton.BUTTON_0;
            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_B) {
                original = JoystickButton.BUTTON_1;
            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_A) {
                original = JoystickButton.BUTTON_2;
            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_X) {
                original = JoystickButton.BUTTON_3;
            // Front buttons  Some of these have the top ones and the bottoms ones flipped.
            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_L1) {
                original = JoystickButton.BUTTON_4;
            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_R1) {
                original = JoystickButton.BUTTON_5;
            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_L2) {
                original = JoystickButton.BUTTON_6;
            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_R2) {
                original = JoystickButton.BUTTON_7;
//            // Dpad buttons
//            } else if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
//                original = JoystickButton.BUTTON_8;
//            } else if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
//                original = JoystickButton.BUTTON_9;
//            } else if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
//                original = JoystickButton.BUTTON_8;
//            } else if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
//                original = JoystickButton.BUTTON_9;
            // Select and start buttons
            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_SELECT) {
                original = JoystickButton.BUTTON_8;
            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_START) {
                original = JoystickButton.BUTTON_9;
            // Joystick push buttons
            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_THUMBL) {
                original = JoystickButton.BUTTON_10;
            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_THUMBR) {
                original = JoystickButton.BUTTON_11;
            }

            String logicalId = JoystickCompatibilityMappings.remapComponent( getName(), original );
            if( logicalId == null ? original != null : !logicalId.equals(original) ) {
                logger.log(Level.FINE, "Remapped: {0} to: {1}",
                        new Object[]{original, logicalId});
            }

            JoystickButton button = new DefaultJoystickButton( getInputManager(), this, getButtonCount(),
                                                               name, logicalId );
            addButton(button);
            buttonIndex.put( keyCode, button );
            return button;
        }
 
Example 12
Source File: Gamepad.java    From BobEngine with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Convert the KeyEvent key code into a Gamepad key code. Returns -1
 * if the key code does not have a matching Gamepad key code.
 * @param keyCode a KeyEvent key code
 * @return Gamepad key code
 */
public int getButton(int keyCode) {
	int button = -1;

	switch (keyCode) {
		case KeyEvent.KEYCODE_DPAD_RIGHT:
			button = D_RIGHT;
			break;
		case KeyEvent.KEYCODE_DPAD_LEFT:
			button = D_LEFT;
			break;
		case KeyEvent.KEYCODE_DPAD_UP:
			button = D_UP;
			break;
		case KeyEvent.KEYCODE_DPAD_DOWN:
			button = D_DOWN;
			break;
		case KeyEvent.KEYCODE_BUTTON_A:
			button = A;
			break;
		case KeyEvent.KEYCODE_BUTTON_B:
			button = B;
			break;
		case KeyEvent.KEYCODE_BUTTON_X:
			button = X;
			break;
		case KeyEvent.KEYCODE_BUTTON_Y:
			button = Y;
			break;
		case KeyEvent.KEYCODE_BUTTON_R1:
			button = R1;
			break;
		case KeyEvent.KEYCODE_BUTTON_L1:
			button = L1;
			break;
		case KeyEvent.KEYCODE_BUTTON_START:
			button = START;
			break;
		case KeyEvent.KEYCODE_BUTTON_SELECT:
			button = SELECT;
			break;
	}

	return button;
}