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_BLUETOOTH_STYLUS
The input device is a Bluetooth stylus.
|
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_NONE
The input source has no class.
|
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_HDMI
The input source is a device connected through HDMI-based bus.
|
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_ROTARY_ENCODER
The input source is a rotating encoder device whose motions should be interpreted as akin to
those of a scroll wheel.
|
static int |
SOURCE_STYLUS
The input source is a stylus pointing device.
|
static int |
SOURCE_TOUCH_NAVIGATION
The input source is a touch device whose motions should be interpreted as navigation events.
|
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_ELIDE_DUPLICATES, PARCELABLE_WRITE_RETURN_VALUE
Modifier and Type | Method and Description |
---|---|
int |
describeContents()
Describe the kinds of special objects contained in this Parcelable
instance's marshaled representation.
|
int |
getControllerNumber()
The controller number for a given input device.
|
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.
|
InputDeviceIdentifier |
getIdentifier()
The set of identifying information for type of input device.
|
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 |
getProductId()
Gets the product id for the given device, if available.
|
int |
getSources()
Gets the input sources supported by this input device as a combined bitfield.
|
int |
getVendorId()
Gets the vendor id for the given device, if available.
|
Vibrator |
getVibrator()
Gets the vibrator service associated with the device, if there is one.
|
boolean |
hasButtonUnderPad()
Reports whether the device has a button under its touchpad
|
boolean[] |
hasKeys(int... keys)
Gets whether the device is capable of producing the list of keycodes.
|
boolean |
hasMicrophone()
Reports whether the device has a built-in microphone.
|
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 ). |
void |
setCustomPointerIcon(PointerIcon icon)
Specifies the current custom pointer.
|
void |
setPointerType(int pointerType)
Sets the current pointer type.
|
boolean |
supportsSource(int source)
Determines whether the input device supports the given source or sources.
|
String |
toString()
Returns a string representation of the 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_NONE
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_BLUETOOTH_STYLUS
Note that this bit merely indicates that an input device is capable of
obtaining input from a Bluetooth 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()
.
A bluetooth stylus generally receives its pressure and button state information from the stylus itself, and derives the rest from another source. For example, a Bluetooth stylus used in conjunction with a touchscreen would derive its contact position and pointer size from the touchscreen and may not be any more accurate than other tools such as fingers.
SOURCE_STYLUS
,
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_TOUCH_NAVIGATION
SOURCE_CLASS_NONE
,
Constant Field Valuespublic static final int SOURCE_ROTARY_ENCODER
{@hide}
,
Constant Field Valuespublic static final int SOURCE_JOYSTICK
SOURCE_GAMEPAD
).SOURCE_CLASS_JOYSTICK
,
Constant Field Valuespublic static final int SOURCE_HDMI
public 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 getControllerNumber()
Each gamepad or joystick is given a unique, positive controller number when initially
configured by the system. This number may change due to events such as device disconnects /
reconnects or user initiated reassignment. Any change in number will trigger an event that
can be observed by registering an InputManager.InputDeviceListener
.
All input devices which are not gamepads or joysticks will be assigned a controller number of 0.
public InputDeviceIdentifier getIdentifier()
public int getGeneration()
public int getVendorId()
A vendor id uniquely identifies the company who manufactured the device. A value of 0 will be assigned where a vendor id is not available.
public int getProductId()
A product id uniquely identifies which product within the address space of a given vendor, identified by the device's vendor id. A value of 0 will be assigned where a product id is not available.
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 boolean supportsSource(int source)
source
- The input source or sources to check against. This can be a generic device
type such as SOURCE_MOUSE
, a more generic device class, such as
SOURCE_CLASS_POINTER
, or a combination of sources bitwise ORed together.public int getKeyboardType()
public KeyCharacterMap getKeyCharacterMap()
public boolean[] hasKeys(int... keys)
keys
- The list of android keycodes to check for.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
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
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 boolean hasMicrophone()
public boolean hasButtonUnderPad()
public void setPointerType(int pointerType)
pointerType
- the type of the pointer icon.public void setCustomPointerIcon(PointerIcon icon)
icon
- the icon data.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
Parcelable.writeToParcel(Parcel, int)
,
the return value of this method must include the
Parcelable.CONTENTS_FILE_DESCRIPTOR
bit.describeContents
in interface Parcelable
Parcelable.CONTENTS_FILE_DESCRIPTOR
public String toString()
Object
toString
method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString
method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@
', and
the unsigned hexadecimal representation of the hash code of the
object. In other words, this method returns a string equal to the
value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())