Java Code Examples for android.view.KeyEvent#KEYCODE_BUTTON_X

The following examples show how to use android.view.KeyEvent#KEYCODE_BUTTON_X . 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: VideoPlayerActivity.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
private boolean navigateDvdMenu(int keyCode) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_UP:
            mService.navigate(MediaPlayer.Navigate.Up);
            return true;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            mService.navigate(MediaPlayer.Navigate.Down);
            return true;
        case KeyEvent.KEYCODE_DPAD_LEFT:
            mService.navigate(MediaPlayer.Navigate.Left);
            return true;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            mService.navigate(MediaPlayer.Navigate.Right);
            return true;
        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_ENTER:
        case KeyEvent.KEYCODE_BUTTON_X:
        case KeyEvent.KEYCODE_BUTTON_A:
            mService.navigate(MediaPlayer.Navigate.Activate);
            return true;
        default:
            return false;
    }
}
 
Example 2
Source File: AliteScreen.java    From Alite with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void processButtonUp(int button) {
	if (button == KeyEvent.KEYCODE_BUTTON_A) {
		if (selectedButton == null) {
			if (ok != null) {
				hitOk();
			} else if (no != null) {
				hitNo();
			}
		} else {
			if (selectedButton == ok) {
				hitOk();
			} else if (selectedButton == yes) {
				hitYes();
			} else if (selectedButton == no) {
				hitNo();
			}
		}
		selectedButton = null;
	}
	if (button == KeyEvent.KEYCODE_BUTTON_X) {
		if (message != null && !messageIsModal) {
			cancelMessage();
		}
	}
}
 
Example 3
Source File: AliteIntro.java    From Alite with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
	if (isController(event.getSource())) {
		switch (event.getKeyCode()) {
			case KeyEvent.KEYCODE_BUTTON_A:
			case KeyEvent.KEYCODE_BUTTON_B:
			case KeyEvent.KEYCODE_BUTTON_X:
			case KeyEvent.KEYCODE_BUTTON_Y:
			case KeyEvent.KEYCODE_BUTTON_L1:
			case KeyEvent.KEYCODE_BUTTON_L2:
				if (getCurrentFocus() instanceof VideoView) {
					VideoView videoView = (VideoView) getCurrentFocus();
					if (videoView != null) {
						try {
							videoView.stopPlayback();
						} catch (IllegalStateException e) {
							// Ignore...
						}
					}
					startAlite(videoView);
				}		
				break;
		}
	}
	return super.dispatchKeyEvent(event);
}
 
Example 4
Source File: GamepadMappings.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Method for mapping PS3 gamepad axis and button values
 * to standard gamepad button and axes values.
 */
@Override
public void mapToStandardGamepad(float[] mappedAxes, float[] mappedButtons,
        float[] rawAxes, float[] rawButtons) {
    // On PS3 X/Y has higher priority.
    float a = rawButtons[KeyEvent.KEYCODE_BUTTON_A];
    float b = rawButtons[KeyEvent.KEYCODE_BUTTON_B];
    float x = rawButtons[KeyEvent.KEYCODE_BUTTON_X];
    float y = rawButtons[KeyEvent.KEYCODE_BUTTON_Y];
    mappedButtons[CanonicalButtonIndex.PRIMARY] = x;
    mappedButtons[CanonicalButtonIndex.SECONDARY] = y;
    mappedButtons[CanonicalButtonIndex.TERTIARY] = a;
    mappedButtons[CanonicalButtonIndex.QUATERNARY] = b;

    mapTriggerButtonsToTopShoulder(mappedButtons, rawButtons);
    mapCommonThumbstickButtons(mappedButtons, rawButtons);
    mapCommonDpadButtons(mappedButtons, rawButtons);
    mapCommonStartSelectMetaButtons(mappedButtons, rawButtons);
    mapTriggerAxesToBottomShoulder(mappedButtons, rawAxes);

    mapXYAxes(mappedAxes, rawAxes);
    mapZAndRZAxesToRightStick(mappedAxes, rawAxes);
}
 
Example 5
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 6
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 7
Source File: GamepadMappings.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private static void mapCommonXYABButtons(float[] mappedButtons, float[] rawButtons) {
    float a = rawButtons[KeyEvent.KEYCODE_BUTTON_A];
    float b = rawButtons[KeyEvent.KEYCODE_BUTTON_B];
    float x = rawButtons[KeyEvent.KEYCODE_BUTTON_X];
    float y = rawButtons[KeyEvent.KEYCODE_BUTTON_Y];
    mappedButtons[CanonicalButtonIndex.PRIMARY] = a;
    mappedButtons[CanonicalButtonIndex.SECONDARY] = b;
    mappedButtons[CanonicalButtonIndex.TERTIARY] = x;
    mappedButtons[CanonicalButtonIndex.QUATERNARY] = y;
}
 
Example 8
Source File: GamepadMappings.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Method for mapping PS4 gamepad axis and button values
 * to standard gamepad button and axes values.
 */
@Override
public void mapToStandardGamepad(
        float[] mappedAxes, float[] mappedButtons, float[] rawAxes, float[] rawButtons) {
    float a = rawButtons[KeyEvent.KEYCODE_BUTTON_A];
    float b = rawButtons[KeyEvent.KEYCODE_BUTTON_B];
    float c = rawButtons[KeyEvent.KEYCODE_BUTTON_C];
    float x = rawButtons[KeyEvent.KEYCODE_BUTTON_X];
    mappedButtons[CanonicalButtonIndex.PRIMARY] = b;
    mappedButtons[CanonicalButtonIndex.SECONDARY] = c;
    mappedButtons[CanonicalButtonIndex.TERTIARY] = a;
    mappedButtons[CanonicalButtonIndex.QUATERNARY] = x;

    float y = rawButtons[KeyEvent.KEYCODE_BUTTON_Y];
    float z = rawButtons[KeyEvent.KEYCODE_BUTTON_Z];
    mappedButtons[CanonicalButtonIndex.LEFT_SHOULDER] = y;
    mappedButtons[CanonicalButtonIndex.RIGHT_SHOULDER] = z;

    float rx = rawAxes[MotionEvent.AXIS_RX];
    float ry = rawAxes[MotionEvent.AXIS_RY];
    mappedButtons[CanonicalButtonIndex.LEFT_TRIGGER] = scaleRxRy(rx);
    mappedButtons[CanonicalButtonIndex.RIGHT_TRIGGER] = scaleRxRy(ry);

    mapHatAxisToDpadButtons(mappedButtons, rawAxes);
    mapCommonStartSelectMetaButtons(mappedButtons, rawButtons);

    mapXYAxes(mappedAxes, rawAxes);
    mapZAndRZAxesToRightStick(mappedAxes, rawAxes);
}
 
Example 9
Source File: GUIListeners.java    From Beats with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
static public int keyCode2Direction(int keyCode) {
	/* interprets a keyCode as a direction
	 * input:   keyCode  - a key code passed to handler           
	 * output: [0 1 2 3] -> [left down up right]; -1 -> unknown
	 */
	switch (keyCode) {
	// WASD, ZX-NM spread, AS-KL spread
	// 12-90 spread, D-Pad
	// Headphone music controller
	case KeyEvent.KEYCODE_A: case KeyEvent.KEYCODE_Z:
	case KeyEvent.KEYCODE_1: case KeyEvent.KEYCODE_DPAD_LEFT:
	case KeyEvent.KEYCODE_MEDIA_PREVIOUS: case KeyEvent.KEYCODE_MEDIA_REWIND:
	case KeyEvent.KEYCODE_BUTTON_X:
		return 0;
	case KeyEvent.KEYCODE_S: case KeyEvent.KEYCODE_X:
	case KeyEvent.KEYCODE_2: case KeyEvent.KEYCODE_DPAD_DOWN:
	case KeyEvent.KEYCODE_MEDIA_STOP:
	case KeyEvent.KEYCODE_BUTTON_A:
		return 1;
	case KeyEvent.KEYCODE_W: case KeyEvent.KEYCODE_N: case KeyEvent.KEYCODE_K:
	case KeyEvent.KEYCODE_9: case KeyEvent.KEYCODE_DPAD_UP:
	case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
	case KeyEvent.KEYCODE_BUTTON_Y:
		return 2;
	case KeyEvent.KEYCODE_D: case KeyEvent.KEYCODE_M: case KeyEvent.KEYCODE_L:
	case KeyEvent.KEYCODE_0: case KeyEvent.KEYCODE_DPAD_RIGHT:
	case KeyEvent.KEYCODE_MEDIA_NEXT: case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
	case KeyEvent.KEYCODE_BUTTON_B:
		return 3;
	default:
		return -1;
	}
}
 
Example 10
Source File: MainActivity.java    From bluetooth with Apache License 2.0 5 votes vote down vote up
@Override
public boolean dispatchKeyEvent(android.view.KeyEvent event) {
    boolean handled = false;
    if ((event.getSource() & InputDevice.SOURCE_GAMEPAD)
        == InputDevice.SOURCE_GAMEPAD) {

        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            switch (event.getKeyCode()) {
                case KeyEvent.KEYCODE_BUTTON_X:
                    last.setText("X Button");
                    handled = true;
                    break;
                case KeyEvent.KEYCODE_BUTTON_A:
                    last.setText("A Button");
                    handled = true;
                    break;
                case KeyEvent.KEYCODE_BUTTON_Y:
                    last.setText("Y Button");
                    handled = true;
                    break;
                case KeyEvent.KEYCODE_BUTTON_B:
                    last.setText("B Button");
                    handled = true;
                    break;
            }
            if (!handled)
                logger.append("code is " + event.getKeyCode() + "\n");
        } else if (event.getAction() == KeyEvent.ACTION_UP) {
            //don't care, but need to handle it.
            handled = true;
        } else {
            logger.append("unknown action " + event.getAction());
        }
        return handled;
    }

    return handled;
}
 
Example 11
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 12
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 13
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;
}