1/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.support.v4.view;
18
19/**
20 * Helper class for accessing values in {@link android.view.InputDevice}.
21 */
22public final class InputDeviceCompat {
23
24    /**
25     * A mask for input source classes.
26     *
27     * Each distinct input source constant has one or more input source class bits set to
28     * specify the desired interpretation for its input events.
29     */
30    public static final int SOURCE_CLASS_MASK = 0x000000ff;
31
32    /**
33     * The input source has no class.
34     *
35     * It is up to the application to determine how to handle the device based on the device type.
36     */
37    public static final int SOURCE_CLASS_NONE = 0x00000000;
38
39    /**
40     * The input source has buttons or keys.
41     * Examples: {@link #SOURCE_KEYBOARD}, {@link #SOURCE_DPAD}.
42     *
43     * A {@link android.view.KeyEvent} should be interpreted as a button or key press.
44     */
45    public static final int SOURCE_CLASS_BUTTON = 0x00000001;
46
47    /**
48     * The input source is a pointing device associated with a display.
49     * Examples: {@link #SOURCE_TOUCHSCREEN}, {@link #SOURCE_MOUSE}.
50     *
51     * A {@link android.view.MotionEvent} should be interpreted as absolute coordinates in
52     * display units according to the {@link android.view.View} hierarchy.  Pointer down/up
53     * indicated when
54     * the finger touches the display or when the selection button is pressed/released.
55     *
56     * Use {@link android.view.InputDevice#getMotionRange} to query the range of the pointing
57     * device.  Some devices permit
58     * touches outside the display area so the effective range may be somewhat smaller or larger
59     * than the actual display size.
60     */
61    public static final int SOURCE_CLASS_POINTER = 0x00000002;
62
63    /**
64     * The input source is a trackball navigation device.
65     * Examples: {@link #SOURCE_TRACKBALL}.
66     *
67     * A {@link android.view.MotionEvent} should be interpreted as relative movements in
68     * device-specific
69     * units used for navigation purposes.  Pointer down/up indicates when the selection button
70     * is pressed/released.
71     *
72     * Use {@link android.view.InputDevice#getMotionRange} to query the range of motion.
73     */
74    public static final int SOURCE_CLASS_TRACKBALL = 0x00000004;
75
76    /**
77     * The input source is an absolute positioning device not associated with a display
78     * (unlike {@link #SOURCE_CLASS_POINTER}).
79     *
80     * A {@link android.view.MotionEvent} should be interpreted as absolute coordinates in
81     * device-specific surface units.
82     *
83     * Use {@link android.view.InputDevice#getMotionRange} to query the range of positions.
84     */
85    public static final int SOURCE_CLASS_POSITION = 0x00000008;
86
87    /**
88     * The input source is a joystick.
89     *
90     * A {@link android.view.MotionEvent} should be interpreted as absolute joystick movements.
91     *
92     * Use {@link android.view.InputDevice#getMotionRange} to query the range of positions.
93     */
94    public static final int SOURCE_CLASS_JOYSTICK = 0x00000010;
95
96    /**
97     * The input source is unknown.
98     */
99    public static final int SOURCE_UNKNOWN = 0x00000000;
100
101    /**
102     * The input source is a keyboard.
103     *
104     * This source indicates pretty much anything that has buttons.  Use
105     * {@link android.view.InputDevice#getKeyboardType()} to determine whether the keyboard has
106     * alphabetic keys
107     * and can be used to enter text.
108     *
109     * @see #SOURCE_CLASS_BUTTON
110     */
111    public static final int SOURCE_KEYBOARD = 0x00000100 | SOURCE_CLASS_BUTTON;
112
113    /**
114     * The input source is a DPad.
115     *
116     * @see #SOURCE_CLASS_BUTTON
117     */
118    public static final int SOURCE_DPAD = 0x00000200 | SOURCE_CLASS_BUTTON;
119
120    /**
121     * The input source is a game pad.
122     * (It may also be a {@link #SOURCE_JOYSTICK}).
123     *
124     * @see #SOURCE_CLASS_BUTTON
125     */
126    public static final int SOURCE_GAMEPAD = 0x00000400 | SOURCE_CLASS_BUTTON;
127
128    /**
129     * The input source is a touch screen pointing device.
130     *
131     * @see #SOURCE_CLASS_POINTER
132     */
133    public static final int SOURCE_TOUCHSCREEN = 0x00001000 | SOURCE_CLASS_POINTER;
134
135    /**
136     * The input source is a mouse pointing device.
137     * This code is also used for other mouse-like pointing devices such as trackpads
138     * and trackpoints.
139     *
140     * @see #SOURCE_CLASS_POINTER
141     */
142    public static final int SOURCE_MOUSE = 0x00002000 | SOURCE_CLASS_POINTER;
143
144    /**
145     * The input source is a stylus pointing device.
146     * <p>
147     * Note that this bit merely indicates that an input device is capable of obtaining
148     * input from a stylus.  To determine whether a given touch event was produced
149     * by a stylus, examine the tool type returned by {@link android.view.MotionEvent#getToolType(int)}
150     * for each individual pointer.
151     * </p><p>
152     * A single touch event may multiple pointers with different tool types,
153     * such as an event that has one pointer with tool type
154     * {@link android.view.MotionEvent#TOOL_TYPE_FINGER} and another pointer with tool type
155     * {@link android.view.MotionEvent#TOOL_TYPE_STYLUS}.  So it is important to examine
156     * the tool type of each pointer, regardless of the source reported
157     * by {@link android.view.MotionEvent#getSource()}.
158     * </p>
159     *
160     * @see #SOURCE_CLASS_POINTER
161     */
162    public static final int SOURCE_STYLUS = 0x00004000 | SOURCE_CLASS_POINTER;
163
164    /**
165     * The input source is a trackball.
166     *
167     * @see #SOURCE_CLASS_TRACKBALL
168     */
169    public static final int SOURCE_TRACKBALL = 0x00010000 | SOURCE_CLASS_TRACKBALL;
170
171    /**
172     * The input source is a touch pad or digitizer tablet that is not
173     * associated with a display (unlike {@link #SOURCE_TOUCHSCREEN}).
174     *
175     * @see #SOURCE_CLASS_POSITION
176     */
177    public static final int SOURCE_TOUCHPAD = 0x00100000 | SOURCE_CLASS_POSITION;
178
179    /**
180     * The input source is a touch device whose motions should be interpreted as navigation events.
181     *
182     * For example, an upward swipe should be as an upward focus traversal in the same manner as
183     * pressing up on a D-Pad would be. Swipes to the left, right and down should be treated in a
184     * similar manner.
185     *
186     * @see #SOURCE_CLASS_NONE
187     */
188    public static final int SOURCE_TOUCH_NAVIGATION = 0x00200000 | SOURCE_CLASS_NONE;
189
190    /**
191     * The input source is a joystick.
192     * (It may also be a {@link #SOURCE_GAMEPAD}).
193     *
194     * @see #SOURCE_CLASS_JOYSTICK
195     */
196    public static final int SOURCE_JOYSTICK = 0x01000000 | SOURCE_CLASS_JOYSTICK;
197
198    /**
199     * The input source is a device connected through HDMI-based bus.
200     *
201     * The key comes in through HDMI-CEC or MHL signal line, and is treated as if it were
202     * generated by a locally connected DPAD or keyboard.
203     */
204    public static final int SOURCE_HDMI = 0x02000000 | SOURCE_CLASS_BUTTON;
205
206    /**
207     * A special input source constant that is used when filtering input devices
208     * to match devices that provide any type of input source.
209     */
210    public static final int SOURCE_ANY = 0xffffff00;
211
212    private InputDeviceCompat() {}
213}
214