| 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; | |
| 8 import android.content.pm.PackageManager; | 7 import android.content.pm.PackageManager; |
| 9 import android.view.InputDevice; | 8 import android.view.InputDevice; |
| 10 | 9 |
| 10 import org.chromium.base.ContextUtils; |
| 11 import org.chromium.base.annotations.CalledByNative; | 11 import org.chromium.base.annotations.CalledByNative; |
| 12 import org.chromium.base.annotations.JNINamespace; | 12 import org.chromium.base.annotations.JNINamespace; |
| 13 | 13 |
| 14 /** | 14 /** |
| 15 * Simple proxy for querying input device properties from C++. | 15 * Simple proxy for querying input device properties from C++. |
| 16 */ | 16 */ |
| 17 @JNINamespace("ui") | 17 @JNINamespace("ui") |
| 18 public class TouchDevice { | 18 public class TouchDevice { |
| 19 | 19 |
| 20 /** | 20 /** |
| 21 * Static methods only so make constructor private. | 21 * Static methods only so make constructor private. |
| 22 */ | 22 */ |
| 23 private TouchDevice() { } | 23 private TouchDevice() { } |
| 24 | 24 |
| 25 /** | 25 /** |
| 26 * @return Maximum supported touch points. | 26 * @return Maximum supported touch points. |
| 27 */ | 27 */ |
| 28 @CalledByNative | 28 @CalledByNative |
| 29 private static int maxTouchPoints(Context context) { | 29 private static int maxTouchPoints() { |
| 30 // Android only tells us if the device belongs to a "Touchscreen Class"
which only | 30 // Android only tells us if the device belongs to a "Touchscreen Class"
which only |
| 31 // guarantees a minimum number of touch points. Be conservative and retu
rn the minimum, | 31 // guarantees a minimum number of touch points. Be conservative and retu
rn the minimum, |
| 32 // checking membership from the highest class down. | 32 // checking membership from the highest class down. |
| 33 | 33 |
| 34 if (context.getPackageManager().hasSystemFeature( | 34 if (ContextUtils.getApplicationContext().getPackageManager().hasSystemFe
ature( |
| 35 PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_JAZZHAND)) { | 35 PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_JAZZHAND)) { |
| 36 return 5; | 36 return 5; |
| 37 } else if (context.getPackageManager().hasSystemFeature( | 37 } else if (ContextUtils.getApplicationContext().getPackageManager().hasS
ystemFeature( |
| 38 PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT)) { | 38 PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINC
T)) { |
| 39 return 2; | 39 return 2; |
| 40 } else if (context.getPackageManager().hasSystemFeature( | 40 } else if (ContextUtils.getApplicationContext().getPackageManager().hasS
ystemFeature( |
| 41 PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH)) { | 41 PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH)) { |
| 42 return 2; | 42 return 2; |
| 43 } else if (context.getPackageManager().hasSystemFeature( | 43 } else if (ContextUtils.getApplicationContext().getPackageManager().hasS
ystemFeature( |
| 44 PackageManager.FEATURE_TOUCHSCREEN)) { | 44 PackageManager.FEATURE_TOUCHSCREEN)) { |
| 45 return 1; | 45 return 1; |
| 46 } else { | 46 } else { |
| 47 return 0; | 47 return 0; |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 | 50 |
| 51 /** | 51 /** |
| 52 * @return an array of two ints: result[0] represents the pointer-types and
result[1] represents | 52 * @return an array of two ints: result[0] represents the pointer-types and
result[1] represents |
| 53 * the hover-types supported by the device, where each int is the un
ion (bitwise OR) of | 53 * the hover-types supported by the device, where each int is the un
ion (bitwise OR) of |
| 54 * corresponding type (PointerType/HoverType) bits. | 54 * corresponding type (PointerType/HoverType) bits. |
| 55 */ | 55 */ |
| 56 @CalledByNative | 56 @CalledByNative |
| 57 private static int[] availablePointerAndHoverTypes(Context context) { | 57 private static int[] availablePointerAndHoverTypes() { |
| 58 int[] result = new int[2]; | 58 int[] result = new int[2]; |
| 59 result[0] = result[1] = 0; | 59 result[0] = result[1] = 0; |
| 60 | 60 |
| 61 for (int deviceId : InputDevice.getDeviceIds()) { | 61 for (int deviceId : InputDevice.getDeviceIds()) { |
| 62 InputDevice inputDevice = InputDevice.getDevice(deviceId); | 62 InputDevice inputDevice = InputDevice.getDevice(deviceId); |
| 63 if (inputDevice == null) continue; | 63 if (inputDevice == null) continue; |
| 64 | 64 |
| 65 int sources = inputDevice.getSources(); | 65 int sources = inputDevice.getSources(); |
| 66 | 66 |
| 67 if (hasSource(sources, InputDevice.SOURCE_MOUSE) | 67 if (hasSource(sources, InputDevice.SOURCE_MOUSE) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 89 if (result[0] == 0) result[0] = PointerType.NONE; | 89 if (result[0] == 0) result[0] = PointerType.NONE; |
| 90 if (result[1] == 0) result[1] = HoverType.NONE; | 90 if (result[1] == 0) result[1] = HoverType.NONE; |
| 91 | 91 |
| 92 return result; | 92 return result; |
| 93 } | 93 } |
| 94 | 94 |
| 95 private static boolean hasSource(int sources, int inputDeviceSource) { | 95 private static boolean hasSource(int sources, int inputDeviceSource) { |
| 96 return (sources & inputDeviceSource) == inputDeviceSource; | 96 return (sources & inputDeviceSource) == inputDeviceSource; |
| 97 } | 97 } |
| 98 } | 98 } |
| OLD | NEW |