Chromium Code Reviews| 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.ui.base; | 5 package org.chromium.ui.base; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.content.pm.PackageManager; | 8 import android.content.pm.PackageManager; |
| 9 import android.view.InputDevice; | |
| 9 | 10 |
| 10 import org.chromium.base.CalledByNative; | 11 import org.chromium.base.CalledByNative; |
| 11 import org.chromium.base.JNINamespace; | 12 import org.chromium.base.JNINamespace; |
| 12 | 13 |
| 13 /** | 14 /** |
| 14 * Simple proxy to let us query the touch device from C++ | 15 * Simple proxy to let us query the touch device from C++ |
| 15 */ | 16 */ |
| 16 @JNINamespace("ui") | 17 @JNINamespace("ui") |
| 17 public class TouchDevice { | 18 public class TouchDevice { |
|
bokan
2014/11/03 14:28:11
Can we change the name of this class? Perhaps Inpu
mustaq
2014/11/03 17:11:38
I agree InputDevice is a better name here, will ad
| |
| 18 | 19 |
| 19 /** | 20 /** |
| 20 * Static methods only so make constructor private. | 21 * Static methods only so make constructor private. |
| 21 */ | 22 */ |
| 22 private TouchDevice() { } | 23 private TouchDevice() { } |
| 23 | 24 |
| 24 /** | 25 /** |
| 25 * Returns the number of supported touch points. | |
| 26 * | |
| 27 * @return Maximum supported touch points. | 26 * @return Maximum supported touch points. |
| 28 */ | 27 */ |
| 29 @CalledByNative | 28 @CalledByNative |
| 30 private static int maxTouchPoints(Context context) { | 29 private static int maxTouchPoints(Context context) { |
| 31 // Android only tells us if the device belongs to a "Touchscreen Class" | 30 // Android only tells us if the device belongs to a "Touchscreen Class" |
| 32 // which only guarantees a minimum number of touch points. Be | 31 // which only guarantees a minimum number of touch points. Be |
| 33 // conservative and return the minimum, checking membership from the | 32 // conservative and return the minimum, checking membership from the |
| 34 // highest class down. | 33 // highest class down. |
| 34 | |
| 35 if (context.getPackageManager().hasSystemFeature( | 35 if (context.getPackageManager().hasSystemFeature( |
| 36 PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_JAZZHAND)) { | 36 PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_JAZZHAND)) { |
| 37 return 5; | 37 return 5; |
| 38 } else if (context.getPackageManager().hasSystemFeature( | 38 } else if (context.getPackageManager().hasSystemFeature( |
| 39 PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT)) { | 39 PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT)) { |
| 40 return 2; | 40 return 2; |
| 41 } else if (context.getPackageManager().hasSystemFeature( | 41 } else if (context.getPackageManager().hasSystemFeature( |
| 42 PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH)) { | 42 PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH)) { |
| 43 return 2; | 43 return 2; |
| 44 } else if (context.getPackageManager().hasSystemFeature( | 44 } else if (context.getPackageManager().hasSystemFeature( |
| 45 PackageManager.FEATURE_TOUCHSCREEN)) { | 45 PackageManager.FEATURE_TOUCHSCREEN)) { |
| 46 return 1; | 46 return 1; |
| 47 } else { | 47 } else { |
| 48 return 0; | 48 return 0; |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 | |
| 52 /** | |
| 53 * TODO | |
| 54 */ | |
| 55 public enum PointerType { | |
| 56 None(1), Coarse(2), Fine(4); | |
| 57 | |
| 58 private int mValue; | |
| 59 | |
| 60 private PointerType(int value) { | |
| 61 mValue = value; | |
| 62 } | |
| 63 | |
| 64 public int getValue() { | |
| 65 return mValue; | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 /** | |
| 70 * @return TODO | |
| 71 */ | |
| 72 @CalledByNative | |
| 73 private static int availablePointerTypes(Context context) { | |
| 74 int pointerTypesVal = 0; | |
| 75 | |
| 76 for (int deviceId : InputDevice.getDeviceIds()) { | |
| 77 int sources = InputDevice.getDevice(deviceId).getSources(); | |
| 78 | |
| 79 if (hasSource(sources, InputDevice.SOURCE_JOYSTICK) | |
|
bokan
2014/11/03 14:28:10
Is there a cursor associated with a joystick? I've
mustaq
2014/11/03 17:11:38
I was considering an old PC-based game I played lo
| |
| 80 || hasSource(sources, InputDevice.SOURCE_MOUSE) | |
| 81 || hasSource(sources, InputDevice.SOURCE_STYLUS) | |
| 82 || hasSource(sources, InputDevice.SOURCE_TRACKBALL)) { | |
| 83 pointerTypesVal |= PointerType.Fine.getValue(); | |
| 84 | |
| 85 } else if (hasSource(sources, InputDevice.SOURCE_CLASS_POINTER)) { | |
| 86 pointerTypesVal |= PointerType.Coarse.getValue(); | |
| 87 | |
| 88 } | |
| 89 } | |
| 90 | |
| 91 return pointerTypesVal; | |
| 92 } | |
| 93 | |
| 94 private static boolean hasSource(int sources, int inputDeviceSource) { | |
| 95 return (sources & inputDeviceSource) == inputDeviceSource; | |
| 96 } | |
| 51 } | 97 } |
| OLD | NEW |