• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 package org.chromium.ui.base;
6 
7 import android.content.Context;
8 import android.content.pm.PackageManager;
9 
10 import org.chromium.base.CalledByNative;
11 import org.chromium.base.JNINamespace;
12 
13 /**
14  * Simple proxy to let us query the touch device from C++
15  */
16 @JNINamespace("ui")
17 public class TouchDevice {
18 
19     /**
20      * Static methods only so make constructor private.
21      */
TouchDevice()22     private TouchDevice() { }
23 
24     /**
25      * Returns the number of supported touch points.
26      *
27      * @return Maximum supported touch points.
28      */
29     @CalledByNative
maxTouchPoints(Context context)30     private static int maxTouchPoints(Context context) {
31         // Android only tells us if the device belongs to a "Touchscreen Class"
32         // which only guarantees a minimum number of touch points. Be
33         // conservative and return the minimum, checking membership from the
34         // highest class down.
35         if (context.getPackageManager().hasSystemFeature(
36                 PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_JAZZHAND)) {
37             return 5;
38         } else if (context.getPackageManager().hasSystemFeature(
39                 PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT)) {
40             return 2;
41         } else if (context.getPackageManager().hasSystemFeature(
42                 PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH)) {
43             return 2;
44         } else if (context.getPackageManager().hasSystemFeature(
45                 PackageManager.FEATURE_TOUCHSCREEN)) {
46             return 1;
47         } else {
48             return 0;
49         }
50     }
51 }
52