Skip to content

Commit 349e576

Browse files
committed
docs: Fixed bugs in Game Controller training doc.
bug: 16375247, 14671463 Change-Id: I51f595065435c3990a979a66b402acc2b6867a1a
1 parent 25303a9 commit 349e576

File tree

1 file changed

+14
-34
lines changed

1 file changed

+14
-34
lines changed

docs/html/training/game-controllers/controller-input.jd

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,15 @@ these input events by implementing the following callback methods in your active
3939
{@link android.app.Activity} or focused {@link android.view.View} (you should
4040
implement the callbacks for either the {@link android.app.Activity} or
4141
{@link android.view.View}, but not both): </p>
42-
4342
<ul>
4443
<li>From {@link android.app.Activity}:
4544
<ul>
46-
<li>{@link android.app.Activity#dispatchGenericMotionEvent(android.view.MotionEvent) dispatchGenericMotionEvent(android.view.MotionEvent)}
45+
<li>{@link android.app.Activity#dispatchGenericMotionEvent(android.view.MotionEvent)
46+
dispatchGenericMotionEvent(android.view. MotionEvent)}
4747
<p>Called to process generic motion events such as joystick movements.</p>
4848
</li>
49-
<li>{@link android.app.Activity#dispatchKeyEvent(android.view.KeyEvent) dispatchKeyEvent(android.view.KeyEvent)}
49+
<li>{@link android.app.Activity#dispatchKeyEvent(android.view.KeyEvent)
50+
dispatchKeyEvent(android.view.KeyEvent)}
5051
<p>Called to process key events such as a press or release of a
5152
gamepad or D-pad button.</p>
5253
</li>
@@ -244,27 +245,25 @@ buttons.</p>
244245
and {@link android.view.KeyEvent#KEYCODE_MENU}<sup>*</sup></td>
245246
</tr>
246247
<tr>
247-
<td>Same as Android <em>Back</em></td>
248+
<td>Same as Android <em>Back</em> navigation behavior described in the
249+
<a href="{@docRoot}design/patterns/navigation.html">Navigation</a> design
250+
guide.</td>
248251
<td>{@link android.view.KeyEvent#KEYCODE_BACK KEYCODE_BACK}</td>
249252
</tr>
250253
<tr>
251254
<td>Navigate back to a previous item in a menu</td>
252-
<td>{@link android.view.KeyEvent#KEYCODE_BUTTON_B BUTTON_B}<sup>**</sup></td>
255+
<td>{@link android.view.KeyEvent#KEYCODE_BUTTON_B BUTTON_B}</td>
253256
</tr>
254257
<tr>
255258
<td>Confirm selection, or perform primary game action</td>
256-
<td>{@link android.view.KeyEvent#KEYCODE_BUTTON_A BUTTON_A}<sup>**</sup> and
259+
<td>{@link android.view.KeyEvent#KEYCODE_BUTTON_A BUTTON_A} and
257260
{@link android.view.KeyEvent#KEYCODE_DPAD_CENTER DPAD_CENTER}</td>
258261
</tr>
259262
</table>
260263
<p>
261264
<em>* Your game should not rely on the presence of the Start, Select, or Menu
262265
buttons.</em>
263266
</p>
264-
<p>
265-
<em>** This could be the opposite button (A/B), depending on the locale that
266-
you are supporting.</em>
267-
</p>
268267

269268
<p class="note"><strong>Tip: </strong>Consider providing a configuration screen
270269
in your game to allow users to personalize their own game controller mappings for
@@ -309,41 +308,22 @@ public class GameView extends View {
309308

310309
private static boolean isFireKey(int keyCode) {
311310
// Here we treat Button_A and DPAD_CENTER as the primary action
312-
// keys for the game. You may need to switch this to Button_B and
313-
// DPAD_CENTER depending on the user expectations for the locale
314-
// in which your game runs.
311+
// keys for the game.
315312
return keyCode == KeyEvent.KEYCODE_DPAD_CENTER
316313
|| keyCode == KeyEvent.KEYCODE_BUTTON_A;
317314
}
318315
}
319316
</pre>
320317

321-
<p>Follow these best practices when handling button presses:</p>
322-
<ul>
323-
<li><strong>Provide localized button mappings.</strong> Generally, if your game
324-
has a primary gameplay action (for example, it fires lasers, lets your avatar
325-
do a high jump, or confirms an item selection), you should map
326-
both {@link android.view.KeyEvent#KEYCODE_DPAD_CENTER DPAD_CENTER} and
327-
{@link android.view.KeyEvent#KEYCODE_BUTTON_A BUTTON_A} to this action. However,
328-
in some locales, users may expect
329-
{@link android.view.KeyEvent#KEYCODE_BUTTON_B BUTTON_B} to be the confirm
330-
button and {@link android.view.KeyEvent#KEYCODE_BUTTON_A BUTTON_A} to be the
331-
back button instead. If you are supporting these locales, make sure to treat
332-
the A and B buttons accordingly in your game. To determine the user's locale,
333-
call the {@link java.util.Locale#getDefault()} method.
334-
<li><strong>Map {@link android.view.KeyEvent#KEYCODE_BUTTON_A BUTTON_A}
335-
consistently across different Android versions.</strong> On Android 4.2 (API
318+
<p class="note"><strong>Note: </strong>On Android 4.2 (API
336319
level 17) and lower, the system treats
337320
{@link android.view.KeyEvent#KEYCODE_BUTTON_A BUTTON_A} as the Android
338321
<em>Back</em> key by default. If your app supports these Android
339322
versions, make sure to treat
340323
{@link android.view.KeyEvent#KEYCODE_BUTTON_A BUTTON_A} as the primary game
341-
action (except in the localization case mentioned
342-
above). To determine the current Android SDK
324+
action. To determine the current Android SDK
343325
version on the device, refer to the
344-
{@link android.os.Build.VERSION#SDK_INT Build.VERSION.SDK_INT} value.
345-
</li>
346-
</ul>
326+
{@link android.os.Build.VERSION#SDK_INT Build.VERSION.SDK_INT} value.</p>
347327

348328
<h2 id="dpad">Process Directional Pad Input</h2>
349329
<p>The 4-way directional pad (D-pad) is a common physical control in many game
@@ -424,7 +404,7 @@ public class Dpad {
424404
// UP and DOWN direction accordingly.
425405
else if (Float.compare(yaxis, -1.0f) == 0) {
426406
directionPressed = Dpad.UP;
427-
} else if (Float.compare(yaxis, -1.0f) == 0) {
407+
} else if (Float.compare(yaxis, 1.0f) == 0) {
428408
directionPressed = Dpad.DOWN;
429409
}
430410
}

0 commit comments

Comments
 (0)