Index: content/public/android/java/src/org/chromium/content/browser/input/GamepadMappings.java |
diff --git a/content/public/android/java/src/org/chromium/content/browser/input/GamepadMappings.java b/content/public/android/java/src/org/chromium/content/browser/input/GamepadMappings.java |
index f0c14d1ae88a60f248475173fe0d2d4876ca11e1..fee108bfecd4f9776e04ab24468bab1b9bfa99f6 100644 |
--- a/content/public/android/java/src/org/chromium/content/browser/input/GamepadMappings.java |
+++ b/content/public/android/java/src/org/chromium/content/browser/input/GamepadMappings.java |
@@ -1,4 +1,4 @@ |
-// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
@@ -8,17 +8,23 @@ import android.view.KeyEvent; |
import android.view.MotionEvent; |
import org.chromium.base.JNINamespace; |
+import org.chromium.base.VisibleForTesting; |
/** |
* Class to manage mapping information related to each supported gamepad controller device. |
*/ |
@JNINamespace("content") |
class GamepadMappings { |
- private static final String NVIDIA_SHIELD_DEVICE_NAME_PREFIX = |
- "NVIDIA Corporation NVIDIA Controller"; |
- private static final String MICROSOFT_XBOX_PAD_DEVICE_NAME = "Microsoft X-Box 360 pad"; |
- private static final String PS3_SIXAXIS_DEVICE_NAME = "Sony PLAYSTATION(R)3 Controller"; |
- private static final String SAMSUNG_EI_GP20_DEVICE_NAME = "Samsung Game Pad EI-GP20"; |
+ @VisibleForTesting |
+ static final String NVIDIA_SHIELD_DEVICE_NAME_PREFIX = "NVIDIA Corporation NVIDIA Controller"; |
+ @VisibleForTesting |
+ static final String MICROSOFT_XBOX_PAD_DEVICE_NAME = "Microsoft X-Box 360 pad"; |
+ @VisibleForTesting |
+ static final String PS3_SIXAXIS_DEVICE_NAME = "Sony PLAYSTATION(R)3 Controller"; |
+ @VisibleForTesting |
+ static final String SAMSUNG_EI_GP20_DEVICE_NAME = "Samsung Game Pad EI-GP20"; |
+ @VisibleForTesting |
+ static final String AMAZON_FIRE_DEVICE_NAME = "Amazon Fire Game Controller"; |
public static boolean mapToStandardGamepad(float[] mappedAxes, float[] mappedButtons, |
float[] rawAxes, float[] rawButtons, String deviceName) { |
@@ -34,6 +40,9 @@ class GamepadMappings { |
} else if (deviceName.equals(SAMSUNG_EI_GP20_DEVICE_NAME)) { |
mapSamsungEIGP20Gamepad(mappedButtons, rawButtons, mappedAxes, rawAxes); |
return true; |
+ } else if (deviceName.equals(AMAZON_FIRE_DEVICE_NAME)) { |
+ mapAmazonFireGamepad(mappedButtons, rawButtons, mappedAxes, rawAxes); |
+ return true; |
} |
mapUnknownGamepad(mappedButtons, rawButtons, mappedAxes, rawAxes); |
@@ -115,6 +124,13 @@ class GamepadMappings { |
mappedButtons[CanonicalButtonIndex.RIGHT_SHOULDER] = rTrigger; |
} |
+ private static void mapPedalAxesToBottomShoulder(float[] mappedButtons, float[] rawAxes) { |
+ float lTrigger = rawAxes[MotionEvent.AXIS_BRAKE]; |
+ float rTrigger = rawAxes[MotionEvent.AXIS_GAS]; |
+ mappedButtons[CanonicalButtonIndex.LEFT_TRIGGER] = lTrigger; |
+ mappedButtons[CanonicalButtonIndex.RIGHT_TRIGGER] = rTrigger; |
+ } |
+ |
private static void mapTriggerAxesToBottomShoulder(float[] mappedButtons, float[] rawAxes) { |
float lTrigger = rawAxes[MotionEvent.AXIS_LTRIGGER]; |
float rTrigger = rawAxes[MotionEvent.AXIS_RTRIGGER]; |
@@ -122,11 +138,13 @@ class GamepadMappings { |
mappedButtons[CanonicalButtonIndex.RIGHT_TRIGGER] = rTrigger; |
} |
- private static float negativeAxisValueAsButton(float input) { |
+ @VisibleForTesting |
+ static float negativeAxisValueAsButton(float input) { |
return (input < -0.5f) ? 1.f : 0.f; |
} |
- private static float positiveAxisValueAsButton(float input) { |
+ @VisibleForTesting |
+ static float positiveAxisValueAsButton(float input) { |
return (input > 0.5f) ? 1.f : 0.f; |
} |
@@ -140,6 +158,23 @@ class GamepadMappings { |
} |
/** |
+ * Method for mapping Amazon Fire gamepad axis and button values |
+ * to standard gamepad button and axes values. |
+ */ |
+ private static void mapAmazonFireGamepad( |
+ float[] mappedButtons, float[] rawButtons, float[] mappedAxes, float[] rawAxes) { |
+ mapCommonXYABButtons(mappedButtons, rawButtons); |
+ mapTriggerButtonsToTopShoulder(mappedButtons, rawButtons); |
+ mapCommonThumbstickButtons(mappedButtons, rawButtons); |
+ mapCommonStartSelectMetaButtons(mappedButtons, rawButtons); |
+ mapPedalAxesToBottomShoulder(mappedButtons, rawAxes); |
+ mapHatAxisToDpadButtons(mappedButtons, rawAxes); |
+ |
+ mapXYAxes(mappedAxes, rawAxes); |
+ mapZAndRZAxesToRightStick(mappedAxes, rawAxes); |
+ } |
+ |
+ /** |
* Method for mapping Nvidia gamepad axis and button values |
* to standard gamepad button and axes values. |
*/ |