- - {@link android.app.Activity#dispatchGenericMotionEvent(android.view.MotionEvent) dispatchGenericMotionEvent(android.view.MotionEvent)}
+
- {@link android.app.Activity#dispatchGenericMotionEvent(android.view.MotionEvent)
+ dispatchGenericMotionEvent(android.view. MotionEvent)}
Called to process generic motion events such as joystick movements.
- - {@link android.app.Activity#dispatchKeyEvent(android.view.KeyEvent) dispatchKeyEvent(android.view.KeyEvent)}
+
- {@link android.app.Activity#dispatchKeyEvent(android.view.KeyEvent)
+ dispatchKeyEvent(android.view.KeyEvent)}
Called to process key events such as a press or release of a
gamepad or D-pad button.
@@ -244,16 +245,18 @@ buttons.
and {@link android.view.KeyEvent#KEYCODE_MENU}*
- Same as Android Back |
+ Same as Android Back navigation behavior described in the
+ Navigation design
+ guide. |
{@link android.view.KeyEvent#KEYCODE_BACK KEYCODE_BACK} |
Navigate back to a previous item in a menu |
- {@link android.view.KeyEvent#KEYCODE_BUTTON_B BUTTON_B}** |
+ {@link android.view.KeyEvent#KEYCODE_BUTTON_B BUTTON_B} |
Confirm selection, or perform primary game action |
- {@link android.view.KeyEvent#KEYCODE_BUTTON_A BUTTON_A}** and
+ | {@link android.view.KeyEvent#KEYCODE_BUTTON_A BUTTON_A} and
{@link android.view.KeyEvent#KEYCODE_DPAD_CENTER DPAD_CENTER} |
@@ -261,10 +264,6 @@ buttons.
* Your game should not rely on the presence of the Start, Select, or Menu
buttons.
-
-** This could be the opposite button (A/B), depending on the locale that
-you are supporting.
-
Tip: Consider providing a configuration screen
in your game to allow users to personalize their own game controller mappings for
@@ -309,41 +308,22 @@ public class GameView extends View {
private static boolean isFireKey(int keyCode) {
// Here we treat Button_A and DPAD_CENTER as the primary action
- // keys for the game. You may need to switch this to Button_B and
- // DPAD_CENTER depending on the user expectations for the locale
- // in which your game runs.
+ // keys for the game.
return keyCode == KeyEvent.KEYCODE_DPAD_CENTER
|| keyCode == KeyEvent.KEYCODE_BUTTON_A;
}
}
-
Follow these best practices when handling button presses:
-
-- Provide localized button mappings. Generally, if your game
-has a primary gameplay action (for example, it fires lasers, lets your avatar
-do a high jump, or confirms an item selection), you should map
-both {@link android.view.KeyEvent#KEYCODE_DPAD_CENTER DPAD_CENTER} and
-{@link android.view.KeyEvent#KEYCODE_BUTTON_A BUTTON_A} to this action. However,
-in some locales, users may expect
-{@link android.view.KeyEvent#KEYCODE_BUTTON_B BUTTON_B} to be the confirm
-button and {@link android.view.KeyEvent#KEYCODE_BUTTON_A BUTTON_A} to be the
-back button instead. If you are supporting these locales, make sure to treat
-the A and B buttons accordingly in your game. To determine the user's locale,
-call the {@link java.util.Locale#getDefault()} method.
-
- Map {@link android.view.KeyEvent#KEYCODE_BUTTON_A BUTTON_A}
-consistently across different Android versions. On Android 4.2 (API
+
Note: On Android 4.2 (API
level 17) and lower, the system treats
{@link android.view.KeyEvent#KEYCODE_BUTTON_A BUTTON_A} as the Android
Back key by default. If your app supports these Android
versions, make sure to treat
{@link android.view.KeyEvent#KEYCODE_BUTTON_A BUTTON_A} as the primary game
-action (except in the localization case mentioned
-above). To determine the current Android SDK
+action. To determine the current Android SDK
version on the device, refer to the
-{@link android.os.Build.VERSION#SDK_INT Build.VERSION.SDK_INT} value.
-
-
+{@link android.os.Build.VERSION#SDK_INT Build.VERSION.SDK_INT} value.
Process Directional Pad Input
The 4-way directional pad (D-pad) is a common physical control in many game
@@ -424,7 +404,7 @@ public class Dpad {
// UP and DOWN direction accordingly.
else if (Float.compare(yaxis, -1.0f) == 0) {
directionPressed = Dpad.UP;
- } else if (Float.compare(yaxis, -1.0f) == 0) {
+ } else if (Float.compare(yaxis, 1.0f) == 0) {
directionPressed = Dpad.DOWN;
}
}
--
2.11.0