public final class InputDevice extends Object implements Parcelable
Each input device may support multiple classes of input. For example, a multi-function keyboard may compose the capabilities of a standard keyboard together with a track pad mouse or other pointing device.
Some input devices present multiple distinguishable sources of input. Applications can query the framework about the characteristics of each distinct source.
As a further wrinkle, different kinds of input sources uses different coordinate systems to describe motion events. Refer to the comments on the input source constants for the appropriate interpretation.
Modifier and Type | Class and Description |
---|---|
static class |
InputDevice.MotionRange
Provides information about the range of values for a particular
MotionEvent axis. |
Parcelable.ClassLoaderCreator<T>, Parcelable.Creator<T>
Modifier and Type | Field and Description |
---|---|
static Parcelable.Creator<InputDevice> |
CREATOR |
static int |
KEYBOARD_TYPE_ALPHABETIC
The keyboard supports a complement of alphabetic keys.
|
static int |
KEYBOARD_TYPE_NON_ALPHABETIC
The keyboard is not fully alphabetic.
|
static int |
KEYBOARD_TYPE_NONE
There is no keyboard.
|
static int |
MOTION_RANGE_ORIENTATION
Deprecated.
Use
MotionEvent.AXIS_ORIENTATION instead. |
static int |
MOTION_RANGE_PRESSURE
Deprecated.
Use
MotionEvent.AXIS_PRESSURE instead. |
static int |
MOTION_RANGE_SIZE
Deprecated.
Use
MotionEvent.AXIS_SIZE instead. |
static int |
MOTION_RANGE_TOOL_MAJOR
Deprecated.
Use
MotionEvent.AXIS_TOOL_MAJOR instead. |
static int |
MOTION_RANGE_TOOL_MINOR
Deprecated.
Use
MotionEvent.AXIS_TOOL_MINOR instead. |
static int |
MOTION_RANGE_TOUCH_MAJOR
Deprecated.
Use
MotionEvent.AXIS_TOUCH_MAJOR instead. |
static int |
MOTION_RANGE_TOUCH_MINOR
Deprecated.
Use
MotionEvent.AXIS_TOUCH_MINOR instead. |
static int |
MOTION_RANGE_X
Deprecated.
Use
MotionEvent.AXIS_X instead. |
static int |
MOTION_RANGE_Y
Deprecated.
Use
MotionEvent.AXIS_Y instead. |
static int |
SOURCE_ANY
A special input source constant that is used when filtering input devices
to match devices that provide any type of input source.
|
static int |
SOURCE_CLASS_BUTTON
The input source has buttons or keys.
|
static int |
SOURCE_CLASS_JOYSTICK
The input source is a joystick.
|
static int |
SOURCE_CLASS_MASK
A mask for input source classes.
|
static int |
SOURCE_CLASS_POINTER
The input source is a pointing device associated with a display.
|
static int |
SOURCE_CLASS_POSITION
The input source is an absolute positioning device not associated with a display
(unlike
SOURCE_CLASS_POINTER ). |
static int |
SOURCE_CLASS_TRACKBALL
The input source is a trackball navigation device.
|
static int |
SOURCE_DPAD
The input source is a DPad.
|
static int |
SOURCE_GAMEPAD
The input source is a game pad.
|
static int |
SOURCE_JOYSTICK
The input source is a joystick.
|
static int |
SOURCE_KEYBOARD
The input source is a keyboard.
|
static int |
SOURCE_MOUSE
The input source is a mouse pointing device.
|
static int |
SOURCE_STYLUS
The input source is a stylus pointing device.
|
static int |
SOURCE_TOUCHPAD
The input source is a touch pad or digitizer tablet that is not
associated with a display (unlike
SOURCE_TOUCHSCREEN ). |
static int |
SOURCE_TOUCHSCREEN
The input source is a touch screen pointing device.
|
static int |
SOURCE_TRACKBALL
The input source is a trackball.
|
static int |
SOURCE_UNKNOWN
The input source is unknown.
|
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_WRITE_RETURN_VALUE
Modifier and Type | Method and Description |
---|---|
int |
describeContents()
Describe the kinds of special objects contained in this Parcelable's
marshalled representation.
|
String |
getDescriptor()
Gets the input device descriptor, which is a stable identifier for an input device.
|
static InputDevice |
getDevice(int id)
Gets information about the input device with the specified id.
|
static int[] |
getDeviceIds()
Gets the ids of all input devices in the system.
|
int |
getGeneration()
Gets a generation number for this input device.
|
int |
getId()
Gets the input device id.
|
int |
getKeyboardType()
Gets the keyboard type.
|
KeyCharacterMap |
getKeyCharacterMap()
Gets the key character map associated with this input device.
|
InputDevice.MotionRange |
getMotionRange(int axis)
Gets information about the range of values for a particular
MotionEvent axis. |
InputDevice.MotionRange |
getMotionRange(int axis,
int source)
Gets information about the range of values for a particular
MotionEvent axis
used by a particular source on the device. |
List<InputDevice.MotionRange> |
getMotionRanges()
Gets the ranges for all axes supported by the device.
|
String |
getName()
Gets the name of this input device.
|
int |
getSources()
Gets the input sources supported by this input device as a combined bitfield.
|
Vibrator |
getVibrator()
Gets the vibrator service associated with the device, if there is one.
|
boolean |
isExternal()
Returns true if the device is external (connected to USB or Bluetooth or some other
peripheral bus), otherwise it is built-in.
|
boolean |
isFullKeyboard()
Returns true if the device is a full keyboard.
|
boolean |
isVirtual()
Returns true if the device is a virtual input device rather than a real one,
such as the virtual keyboard (see
KeyCharacterMap.VIRTUAL_KEYBOARD ). |
String |
toString()
Returns a string containing a concise, human-readable description of this
object.
|
void |
writeToParcel(Parcel out,
int flags)
Flatten this object in to a Parcel.
|
public static final int SOURCE_CLASS_MASK
public static final int SOURCE_CLASS_BUTTON
SOURCE_KEYBOARD
, SOURCE_DPAD
.
A KeyEvent
should be interpreted as a button or key press.
Use getKeyCharacterMap()
to query the device's button and key mappings.public static final int SOURCE_CLASS_POINTER
SOURCE_TOUCHSCREEN
, SOURCE_MOUSE
.
A MotionEvent
should be interpreted as absolute coordinates in
display units according to the View
hierarchy. Pointer down/up indicated when
the finger touches the display or when the selection button is pressed/released.
Use getMotionRange(int)
to query the range of the pointing device. Some devices permit
touches outside the display area so the effective range may be somewhat smaller or larger
than the actual display size.public static final int SOURCE_CLASS_TRACKBALL
SOURCE_TRACKBALL
.
A MotionEvent
should be interpreted as relative movements in device-specific
units used for navigation purposes. Pointer down/up indicates when the selection button
is pressed/released.
Use getMotionRange(int)
to query the range of motion.public static final int SOURCE_CLASS_POSITION
SOURCE_CLASS_POINTER
).
A MotionEvent
should be interpreted as absolute coordinates in
device-specific surface units.
Use getMotionRange(int)
to query the range of positions.public static final int SOURCE_CLASS_JOYSTICK
MotionEvent
should be interpreted as absolute joystick movements.
Use getMotionRange(int)
to query the range of positions.public static final int SOURCE_UNKNOWN
public static final int SOURCE_KEYBOARD
getKeyboardType()
to determine whether the keyboard has alphabetic keys
and can be used to enter text.SOURCE_CLASS_BUTTON
,
Constant Field Valuespublic static final int SOURCE_DPAD
SOURCE_CLASS_BUTTON
,
Constant Field Valuespublic static final int SOURCE_GAMEPAD
SOURCE_JOYSTICK
).SOURCE_CLASS_BUTTON
,
Constant Field Valuespublic static final int SOURCE_TOUCHSCREEN
SOURCE_CLASS_POINTER
,
Constant Field Valuespublic static final int SOURCE_MOUSE
SOURCE_CLASS_POINTER
,
Constant Field Valuespublic static final int SOURCE_STYLUS
Note that this bit merely indicates that an input device is capable of obtaining
input from a stylus. To determine whether a given touch event was produced
by a stylus, examine the tool type returned by MotionEvent.getToolType(int)
for each individual pointer.
A single touch event may multiple pointers with different tool types,
such as an event that has one pointer with tool type
MotionEvent.TOOL_TYPE_FINGER
and another pointer with tool type
MotionEvent.TOOL_TYPE_STYLUS
. So it is important to examine
the tool type of each pointer, regardless of the source reported
by MotionEvent.getSource()
.
SOURCE_CLASS_POINTER
,
Constant Field Valuespublic static final int SOURCE_TRACKBALL
SOURCE_CLASS_TRACKBALL
,
Constant Field Valuespublic static final int SOURCE_TOUCHPAD
SOURCE_TOUCHSCREEN
).SOURCE_CLASS_POSITION
,
Constant Field Valuespublic static final int SOURCE_JOYSTICK
SOURCE_GAMEPAD
).SOURCE_CLASS_JOYSTICK
,
Constant Field Valuespublic static final int SOURCE_ANY
@Deprecated public static final int MOTION_RANGE_X
MotionEvent.AXIS_X
instead.MotionEvent.AXIS_X
.getMotionRange(int)
,
Constant Field Values@Deprecated public static final int MOTION_RANGE_Y
MotionEvent.AXIS_Y
instead.MotionEvent.AXIS_Y
.getMotionRange(int)
,
Constant Field Values@Deprecated public static final int MOTION_RANGE_PRESSURE
MotionEvent.AXIS_PRESSURE
instead.MotionEvent.AXIS_PRESSURE
.getMotionRange(int)
,
Constant Field Values@Deprecated public static final int MOTION_RANGE_SIZE
MotionEvent.AXIS_SIZE
instead.MotionEvent.AXIS_SIZE
.getMotionRange(int)
,
Constant Field Values@Deprecated public static final int MOTION_RANGE_TOUCH_MAJOR
MotionEvent.AXIS_TOUCH_MAJOR
instead.MotionEvent.AXIS_TOUCH_MAJOR
.getMotionRange(int)
,
Constant Field Values@Deprecated public static final int MOTION_RANGE_TOUCH_MINOR
MotionEvent.AXIS_TOUCH_MINOR
instead.MotionEvent.AXIS_TOUCH_MINOR
.getMotionRange(int)
,
Constant Field Values@Deprecated public static final int MOTION_RANGE_TOOL_MAJOR
MotionEvent.AXIS_TOOL_MAJOR
instead.MotionEvent.AXIS_TOOL_MAJOR
.getMotionRange(int)
,
Constant Field Values@Deprecated public static final int MOTION_RANGE_TOOL_MINOR
MotionEvent.AXIS_TOOL_MINOR
instead.MotionEvent.AXIS_TOOL_MINOR
.getMotionRange(int)
,
Constant Field Values@Deprecated public static final int MOTION_RANGE_ORIENTATION
MotionEvent.AXIS_ORIENTATION
instead.MotionEvent.AXIS_ORIENTATION
.getMotionRange(int)
,
Constant Field Valuespublic static final int KEYBOARD_TYPE_NONE
public static final int KEYBOARD_TYPE_NON_ALPHABETIC
public static final int KEYBOARD_TYPE_ALPHABETIC
public static final Parcelable.Creator<InputDevice> CREATOR
public static InputDevice getDevice(int id)
id
- The device id.public static int[] getDeviceIds()
public int getId()
Each input device receives a unique id when it is first configured
by the system. The input device id may change when the system is restarted or if the
input device is disconnected, reconnected or reconfigured at any time.
If you require a stable identifier for a device that persists across
boots and reconfigurations, use getDescriptor()
.
public int getGeneration()
public String getDescriptor()
An input device descriptor uniquely identifies an input device. Its value is intended to be persistent across system restarts, and should not change even if the input device is disconnected, reconnected or reconfigured at any time.
It is possible for there to be multiple InputDevice
instances that have the
same input device descriptor. This might happen in situations where a single
human input device registers multiple InputDevice
instances (HID collections)
that describe separate features of the device, such as a keyboard that also
has a trackpad. Alternately, it may be that the input devices are simply
indistinguishable, such as two keyboards made by the same manufacturer.
The input device descriptor returned by getDescriptor()
should only be
used when an application needs to remember settings associated with a particular
input device. For all other purposes when referring to a logical
InputDevice
instance at runtime use the id returned by getId()
.
public boolean isVirtual()
KeyCharacterMap.VIRTUAL_KEYBOARD
).
Virtual input devices are provided to implement system-level functionality and should not be seen or configured by users.
KeyCharacterMap.VIRTUAL_KEYBOARD
public boolean isExternal()
public boolean isFullKeyboard()
public String getName()
public int getSources()
public int getKeyboardType()
public KeyCharacterMap getKeyCharacterMap()
public InputDevice.MotionRange getMotionRange(int axis)
MotionEvent
axis.
If the device supports multiple sources, the same axis may have different meanings
for each source. Returns information about the first axis found for any source.
To obtain information about the axis for a specific source, use
getMotionRange(int, int)
.axis
- The axis constant.MotionEvent.AXIS_X
,
MotionEvent.AXIS_Y
,
#getSupportedAxes()
public InputDevice.MotionRange getMotionRange(int axis, int source)
MotionEvent
axis
used by a particular source on the device.
If the device supports multiple sources, the same axis may have different meanings
for each source.axis
- The axis constant.source
- The source for which to return information.MotionEvent.AXIS_X
,
MotionEvent.AXIS_Y
,
#getSupportedAxes()
public List<InputDevice.MotionRange> getMotionRanges()
getMotionRange(int, int)
public Vibrator getVibrator()
Vibrator.hasVibrator()
to determine whether a vibrator is
present.
Note that the vibrator associated with the device may be different from
the system vibrator. To obtain an instance of the system vibrator instead, call
Context.getSystemService(java.lang.String)
with Context.VIBRATOR_SERVICE
as argument.public void writeToParcel(Parcel out, int flags)
Parcelable
writeToParcel
in interface Parcelable
out
- The Parcel in which the object should be written.flags
- Additional flags about how the object should be written.
May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE
.public int describeContents()
Parcelable
describeContents
in interface Parcelable
public String toString()
Object
getClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful
toString
method
if you intend implementing your own toString
method.