InputDevice.java revision c5ed5910c9ef066cec6a13bbb404ec57b1e92637
1/* 2 * Copyright (C) 2010 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.view; 18 19/** 20 * Describes the capabilities of a particular input device. 21 * <p> 22 * Each input device may support multiple classes of input. For example, a multifunction 23 * keyboard may compose the capabilities of a standard keyboard together with a track pad mouse 24 * or other pointing device. 25 * </p><p> 26 * Some input devices present multiple distinguishable sources of input. For example, a 27 * game pad may have two analog joysticks, a directional pad and a full complement of buttons. 28 * Applications can query the framework about the characteristics of each distinct source. 29 * </p><p> 30 * As a further wrinkle, different kinds of input sources uses different coordinate systems 31 * to describe motion events. Refer to the comments on the input source constants for 32 * the appropriate interpretation. 33 */ 34public final class InputDevice { 35 private int mId; 36 private String mName; 37 private int mSources; 38 39 /** 40 * A mask for input source classes. 41 * 42 * Each distinct input source constant has one or more input source class bits set to 43 * specify the desired interpretation for its input events. 44 */ 45 public static final int SOURCE_CLASS_MASK = 0x000000ff; 46 47 /** 48 * The input source has buttons or keys. 49 * Examples: {@link #SOURCE_KEYBOARD}, {@link #SOURCE_GAMEPAD}, {@link #SOURCE_DPAD}. 50 * 51 * A {@link KeyEvent} should be interpreted as a button or key press. 52 * 53 * Use {@link #hasKeyCode} to query whether the device supports a particular button or key. 54 */ 55 public static final int SOURCE_CLASS_BUTTON = 0x00000001; 56 57 /** 58 * The input source is a pointing device associated with a display. 59 * Examples: {@link #SOURCE_TOUCHSCREEN}, {@link #SOURCE_MOUSE}. 60 * 61 * A {@link MotionEvent} should be interpreted as absolute coordinates in 62 * display units according to the {@link View} hierarchy. Pointer down/up indicated when 63 * the finger touches the display or when the selection button is pressed/released. 64 * 65 * Use {@link #getMotionRange} to query the range of the pointing device. Some devices permit 66 * touches outside the display area so the effective range may be somewhat smaller or larger 67 * than the actual display size. 68 */ 69 public static final int SOURCE_CLASS_POINTER = 0x00000002; 70 71 /** 72 * The input source is a trackball navigation device. 73 * Examples: {@link #SOURCE_TRACKBALL}. 74 * 75 * A {@link MotionEvent} should be interpreted as relative movements in device-specific 76 * units used for navigation purposes. Pointer down/up indicates when the selection button 77 * is pressed/released. 78 * 79 * Use {@link #getMotionRange} to query the range of motion. 80 */ 81 public static final int SOURCE_CLASS_TRACKBALL = 0x00000004; 82 83 /** 84 * The input source is an absolute positioning device not associated with a display 85 * (unlike {@link #SOURCE_CLASS_POINTER}). 86 * 87 * A {@link MotionEvent} should be interpreted as absolute coordinates in 88 * device-specific surface units. 89 * 90 * Use {@link #getMotionRange} to query the range of positions. 91 */ 92 public static final int SOURCE_CLASS_POSITION = 0x00000008; 93 94 /** 95 * The input source is a joystick. 96 * 97 * A {@link KeyEvent} should be interpreted as a joystick button press. 98 * 99 * A {@link MotionEvent} should be interpreted in absolute coordinates as a joystick 100 * position in normalized device-specific units nominally between -1.0 and 1.0. 101 * 102 * Use {@link #getMotionRange} to query the range and precision of motion. 103 */ 104 public static final int SOURCE_CLASS_JOYSTICK = 0x00000010; 105 106 /** 107 * The input source is unknown. 108 */ 109 public static final int SOURCE_UNKNOWN = 0x00000000; 110 111 /** 112 * The input source is a keyboard. 113 * 114 * @see #SOURCE_CLASS_BUTTON 115 */ 116 public static final int SOURCE_KEYBOARD = 0x00000100 | SOURCE_CLASS_BUTTON; 117 118 /** 119 * The input source is a DPad. 120 * 121 * @see #SOURCE_CLASS_BUTTON 122 */ 123 public static final int SOURCE_DPAD = 0x00000200 | SOURCE_CLASS_BUTTON; 124 125 /** 126 * The input source is a gamepad. 127 * 128 * @see #SOURCE_CLASS_BUTTON 129 */ 130 public static final int SOURCE_GAMEPAD = 0x00000400 | SOURCE_CLASS_BUTTON; 131 132 /** 133 * The input source is a touch screen pointing device. 134 * 135 * @see #SOURCE_CLASS_POINTER 136 */ 137 public static final int SOURCE_TOUCHSCREEN = 0x00001000 | SOURCE_CLASS_POINTER; 138 139 /** 140 * The input source is a mouse pointing device. 141 * This code is also used for other mouse-like pointing devices such as trackpads 142 * and trackpoints. 143 * 144 * @see #SOURCE_CLASS_POINTER 145 */ 146 public static final int SOURCE_MOUSE = 0x00002000 | SOURCE_CLASS_POINTER; 147 148 /** 149 * The input source is a trackball. 150 * 151 * @see #SOURCE_CLASS_TRACKBALL 152 */ 153 public static final int SOURCE_TRACKBALL = 0x00010000 | SOURCE_CLASS_TRACKBALL; 154 155 /** 156 * The input source is a touch pad or digitizer tablet that is not 157 * associated with a display (unlike {@link SOURCE_TOUCHSCREEN}). 158 * 159 * @see #SOURCE_CLASS_POSITION 160 */ 161 public static final int SOURCE_TOUCHPAD = 0x00100000 | SOURCE_CLASS_POSITION; 162 163 /** 164 * The input source is a joystick mounted on the left or is a standalone joystick. 165 * 166 * @see #SOURCE_CLASS_JOYSTICK 167 */ 168 public static final int SOURCE_JOYSTICK_LEFT = 0x01000000 | SOURCE_CLASS_JOYSTICK; 169 170 /** 171 * The input source is a joystick mounted on the right. 172 * 173 * @see #SOURCE_CLASS_JOYSTICK 174 */ 175 public static final int SOURCE_JOYSTICK_RIGHT = 0x02000000 | SOURCE_CLASS_JOYSTICK; 176 177 /* 178 public static final int MOTION_RANGE_X = 0; 179 public static final int MOTION_RANGE_Y = 1; 180 public static final int MOTION_RANGE_PRESSURE = 2; 181 public static final int MOTION_RANGE_SIZE = 3; 182 public static final int MOTION_RANGE_TOUCH_MAJOR = 4; 183 public static final int MOTION_RANGE_TOUCH_MINOR = 5; 184 public static final int MOTION_RANGE_TOOL_MAJOR = 6; 185 public static final int MOTION_RANGE_TOOL_MINOR = 7; 186 public static final int MOTION_RANGE_ORIENTATION = 8; 187 188 public static InputDevice getDevice(int id) { 189 } 190 */ 191 192 /** 193 * Gets the name of this input device. 194 * @return The input device name. 195 */ 196 public String getName() { 197 return mName; 198 } 199 200 /** 201 * Gets the input sources supported by this input device as a combined bitfield. 202 * @return The supported input sources. 203 */ 204 public int getSources() { 205 return mSources; 206 } 207 208 /** 209 * Gets the key character map associated with this input device. 210 * @return The key character map. 211 */ 212 public KeyCharacterMap getKeyCharacterMap() { 213 return KeyCharacterMap.load(mId); 214 } 215 216 /* 217 218 public MotionRange getMotionRange(int range) { 219 } 220 221 public boolean hasKeyCode(int keyCode) { 222 } 223 224 public static final class MotionRange { 225 public float min; 226 public float max; 227 public float range; 228 public float flat; 229 public float fuzz; 230 }*/ 231} 232