OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.content.browser.input; | 5 package org.chromium.device.gamepad; |
6 | 6 |
7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.hardware.input.InputManager; | 9 import android.hardware.input.InputManager; |
10 import android.hardware.input.InputManager.InputDeviceListener; | 10 import android.hardware.input.InputManager.InputDeviceListener; |
11 import android.view.InputDevice; | 11 import android.view.InputDevice; |
12 import android.view.InputEvent; | 12 import android.view.InputEvent; |
13 import android.view.KeyEvent; | 13 import android.view.KeyEvent; |
14 import android.view.MotionEvent; | 14 import android.view.MotionEvent; |
15 | 15 |
16 import org.chromium.base.ThreadUtils; | 16 import org.chromium.base.ThreadUtils; |
17 import org.chromium.base.annotations.CalledByNative; | 17 import org.chromium.base.annotations.CalledByNative; |
18 import org.chromium.base.annotations.JNINamespace; | 18 import org.chromium.base.annotations.JNINamespace; |
19 import org.chromium.content.browser.ContentView; | 19 // import org.chromium.content.browser.ContentView; |
scottmg
2016/06/23 17:27:19
Remove.
| |
20 | 20 |
21 /** | 21 /** |
22 * Class to manage connected gamepad devices list. | 22 * Class to manage connected gamepad devices list. |
23 * | 23 * |
24 * It is a Java counterpart of GamepadPlatformDataFetcherAndroid and feeds Gamep ad API with input | 24 * It is a Java counterpart of GamepadPlatformDataFetcherAndroid and feeds Gamep ad API with input |
25 * data. | 25 * data. |
26 */ | 26 */ |
27 @JNINamespace("content") | 27 @JNINamespace("device") |
28 public class GamepadList { | 28 public class GamepadList { |
29 private static final int MAX_GAMEPADS = 4; | 29 private static final int MAX_GAMEPADS = 4; |
30 | 30 |
31 private final Object mLock = new Object(); | 31 private final Object mLock = new Object(); |
32 | 32 |
33 private final GamepadDevice[] mGamepadDevices = new GamepadDevice[MAX_GAMEPA DS]; | 33 private final GamepadDevice[] mGamepadDevices = new GamepadDevice[MAX_GAMEPA DS]; |
34 private InputManager mInputManager; | 34 private InputManager mInputManager; |
35 private int mAttachedToWindowCounter; | 35 private int mAttachedToWindowCounter; |
36 private boolean mIsGamepadAPIActive; | 36 private boolean mIsGamepadAPIActive; |
37 private InputDeviceListener mInputDeviceListener; | 37 private InputDeviceListener mInputDeviceListener; |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 | 231 |
232 private void unregisterGamepad(int deviceId) { | 232 private void unregisterGamepad(int deviceId) { |
233 GamepadDevice gamepadDevice = getDeviceById(deviceId); | 233 GamepadDevice gamepadDevice = getDeviceById(deviceId); |
234 if (gamepadDevice == null) return; // Not a registered device. | 234 if (gamepadDevice == null) return; // Not a registered device. |
235 int index = gamepadDevice.getIndex(); | 235 int index = gamepadDevice.getIndex(); |
236 mGamepadDevices[index] = null; | 236 mGamepadDevices[index] = null; |
237 } | 237 } |
238 | 238 |
239 private static boolean isGamepadDevice(InputDevice inputDevice) { | 239 private static boolean isGamepadDevice(InputDevice inputDevice) { |
240 if (inputDevice == null) return false; | 240 if (inputDevice == null) return false; |
241 return ((inputDevice.getSources() | 241 return ((inputDevice.getSources() & InputDevice.SOURCE_JOYSTICK) |
242 & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK); | 242 == InputDevice.SOURCE_JOYSTICK); |
243 } | 243 } |
244 | 244 |
245 private GamepadDevice getGamepadForEvent(InputEvent event) { | 245 private GamepadDevice getGamepadForEvent(InputEvent event) { |
246 return getDeviceById(event.getDeviceId()); | 246 return getDeviceById(event.getDeviceId()); |
247 } | 247 } |
248 | 248 |
249 /** | 249 /** |
250 * @return True if HTML5 gamepad API is active. | 250 * @return True if HTML5 gamepad API is active. |
251 */ | 251 */ |
252 public static boolean isGamepadAPIActive() { | 252 public static boolean isGamepadAPIActive() { |
253 return getInstance().mIsGamepadAPIActive; | 253 return getInstance().mIsGamepadAPIActive; |
254 } | 254 } |
255 | 255 |
256 /** | 256 /** |
257 * @return True if the motion event corresponds to a gamepad event. | 257 * @return True if the motion event corresponds to a gamepad event. |
258 */ | 258 */ |
259 public static boolean isGamepadEvent(MotionEvent event) { | 259 public static boolean isGamepadEvent(MotionEvent event) { |
260 return ((event.getSource() & InputDevice.SOURCE_JOYSTICK) == InputDevice .SOURCE_JOYSTICK); | 260 return ((event.getSource() & InputDevice.SOURCE_JOYSTICK) == InputDevice .SOURCE_JOYSTICK); |
261 } | 261 } |
262 | 262 |
263 /** | 263 /** |
264 * @return True if event's keycode corresponds to a gamepad key. | 264 * @return True if event's keycode corresponds to a gamepad key. |
265 */ | 265 */ |
266 public static boolean isGamepadEvent(KeyEvent event) { | 266 public static boolean isGamepadEvent(KeyEvent event) { |
267 int keyCode = event.getKeyCode(); | 267 int keyCode = event.getKeyCode(); |
268 switch (keyCode) { | 268 switch (keyCode) { |
269 // Specific handling for dpad keys is required because | 269 // Specific handling for dpad keys is required because |
270 // KeyEvent.isGamepadButton doesn't consider dpad keys. | 270 // KeyEvent.isGamepadButton doesn't consider dpad keys. |
271 case KeyEvent.KEYCODE_DPAD_UP: | 271 case KeyEvent.KEYCODE_DPAD_UP: |
272 case KeyEvent.KEYCODE_DPAD_DOWN: | 272 case KeyEvent.KEYCODE_DPAD_DOWN: |
273 case KeyEvent.KEYCODE_DPAD_LEFT: | 273 case KeyEvent.KEYCODE_DPAD_LEFT: |
274 case KeyEvent.KEYCODE_DPAD_RIGHT: | 274 case KeyEvent.KEYCODE_DPAD_RIGHT: |
275 return true; | 275 return true; |
276 default: | 276 default: |
277 return KeyEvent.isGamepadButton(keyCode); | 277 return KeyEvent.isGamepadButton(keyCode); |
278 } | 278 } |
279 } | 279 } |
280 | 280 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
316 } | 316 } |
317 } | 317 } |
318 } | 318 } |
319 | 319 |
320 private native void nativeSetGamepadData(long webGamepadsPtr, int index, boo lean mapping, | 320 private native void nativeSetGamepadData(long webGamepadsPtr, int index, boo lean mapping, |
321 boolean connected, String devicename, long timestamp, float[] axes, float[] buttons); | 321 boolean connected, String devicename, long timestamp, float[] axes, float[] buttons); |
322 | 322 |
323 private static class LazyHolder { | 323 private static class LazyHolder { |
324 private static final GamepadList INSTANCE = new GamepadList(); | 324 private static final GamepadList INSTANCE = new GamepadList(); |
325 } | 325 } |
326 | |
327 } | 326 } |
OLD | NEW |