InputDevicepublic final class InputDevice extends Object implements android.os.ParcelableDescribes the capabilities of a particular input device.
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.
|
Fields Summary |
---|
private final int | mId | private final int | mGeneration | private final int | mControllerNumber | private final String | mName | private final int | mVendorId | private final int | mProductId | private final String | mDescriptor | private final android.hardware.input.InputDeviceIdentifier | mIdentifier | private final boolean | mIsExternal | private final int | mSources | private final int | mKeyboardType | private final KeyCharacterMap | mKeyCharacterMap | private final boolean | mHasVibrator | private final boolean | mHasButtonUnderPad | private final ArrayList | mMotionRanges | private android.os.Vibrator | mVibrator | public static final int | SOURCE_CLASS_MASKA mask for input source classes.
Each distinct input source constant has one or more input source class bits set to
specify the desired interpretation for its input events. | public static final int | SOURCE_CLASS_NONEThe input source has no class.
It is up to the application to determine how to handle the device based on the device type. | public static final int | SOURCE_CLASS_BUTTONThe input source has buttons or keys.
Examples: {@link #SOURCE_KEYBOARD}, {@link #SOURCE_DPAD}.
A {@link KeyEvent} should be interpreted as a button or key press.
Use {@link #getKeyCharacterMap} to query the device's button and key mappings. | public static final int | SOURCE_CLASS_POINTERThe input source is a pointing device associated with a display.
Examples: {@link #SOURCE_TOUCHSCREEN}, {@link #SOURCE_MOUSE}.
A {@link MotionEvent} should be interpreted as absolute coordinates in
display units according to the {@link View} hierarchy. Pointer down/up indicated when
the finger touches the display or when the selection button is pressed/released.
Use {@link #getMotionRange} 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_TRACKBALLThe input source is a trackball navigation device.
Examples: {@link #SOURCE_TRACKBALL}.
A {@link 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 {@link #getMotionRange} to query the range of motion. | public static final int | SOURCE_CLASS_POSITIONThe input source is an absolute positioning device not associated with a display
(unlike {@link #SOURCE_CLASS_POINTER}).
A {@link MotionEvent} should be interpreted as absolute coordinates in
device-specific surface units.
Use {@link #getMotionRange} to query the range of positions. | public static final int | SOURCE_CLASS_JOYSTICKThe input source is a joystick.
A {@link MotionEvent} should be interpreted as absolute joystick movements.
Use {@link #getMotionRange} to query the range of positions. | public static final int | SOURCE_UNKNOWNThe input source is unknown. | public static final int | SOURCE_KEYBOARDThe input source is a keyboard.
This source indicates pretty much anything that has buttons. Use
{@link #getKeyboardType()} to determine whether the keyboard has alphabetic keys
and can be used to enter text. | public static final int | SOURCE_DPADThe input source is a DPad. | public static final int | SOURCE_GAMEPADThe input source is a game pad.
(It may also be a {@link #SOURCE_JOYSTICK}). | public static final int | SOURCE_TOUCHSCREENThe input source is a touch screen pointing device. | public static final int | SOURCE_MOUSEThe input source is a mouse pointing device.
This code is also used for other mouse-like pointing devices such as trackpads
and trackpoints. | public static final int | SOURCE_STYLUSThe input source is a stylus pointing device.
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 {@link 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
{@link MotionEvent#TOOL_TYPE_FINGER} and another pointer with tool type
{@link MotionEvent#TOOL_TYPE_STYLUS}. So it is important to examine
the tool type of each pointer, regardless of the source reported
by {@link MotionEvent#getSource()}.
| public static final int | SOURCE_TRACKBALLThe input source is a trackball. | public static final int | SOURCE_TOUCHPADThe input source is a touch pad or digitizer tablet that is not
associated with a display (unlike {@link #SOURCE_TOUCHSCREEN}). | public static final int | SOURCE_TOUCH_NAVIGATIONThe input source is a touch device whose motions should be interpreted as navigation events.
For example, an upward swipe should be as an upward focus traversal in the same manner as
pressing up on a D-Pad would be. Swipes to the left, right and down should be treated in a
similar manner. | public static final int | SOURCE_JOYSTICKThe input source is a joystick.
(It may also be a {@link #SOURCE_GAMEPAD}). | public static final int | SOURCE_HDMIThe input source is a device connected through HDMI-based bus.
The key comes in through HDMI-CEC or MHL signal line, and is treated as if it were
generated by a locally connected DPAD or keyboard. | public static final int | SOURCE_ANYA special input source constant that is used when filtering input devices
to match devices that provide any type of input source. | public static final int | MOTION_RANGE_XConstant for retrieving the range of values for {@link MotionEvent#AXIS_X}. | public static final int | MOTION_RANGE_YConstant for retrieving the range of values for {@link MotionEvent#AXIS_Y}. | public static final int | MOTION_RANGE_PRESSUREConstant for retrieving the range of values for {@link MotionEvent#AXIS_PRESSURE}. | public static final int | MOTION_RANGE_SIZEConstant for retrieving the range of values for {@link MotionEvent#AXIS_SIZE}. | public static final int | MOTION_RANGE_TOUCH_MAJORConstant for retrieving the range of values for {@link MotionEvent#AXIS_TOUCH_MAJOR}. | public static final int | MOTION_RANGE_TOUCH_MINORConstant for retrieving the range of values for {@link MotionEvent#AXIS_TOUCH_MINOR}. | public static final int | MOTION_RANGE_TOOL_MAJORConstant for retrieving the range of values for {@link MotionEvent#AXIS_TOOL_MAJOR}. | public static final int | MOTION_RANGE_TOOL_MINORConstant for retrieving the range of values for {@link MotionEvent#AXIS_TOOL_MINOR}. | public static final int | MOTION_RANGE_ORIENTATIONConstant for retrieving the range of values for {@link MotionEvent#AXIS_ORIENTATION}. | public static final int | KEYBOARD_TYPE_NONEThere is no keyboard. | public static final int | KEYBOARD_TYPE_NON_ALPHABETICThe keyboard is not fully alphabetic. It may be a numeric keypad or an assortment
of buttons that are not mapped as alphabetic keys suitable for text input. | public static final int | KEYBOARD_TYPE_ALPHABETICThe keyboard supports a complement of alphabetic keys. | public static final Parcelable.Creator | CREATOR |
Constructors Summary |
---|
private InputDevice(int id, int generation, int controllerNumber, String name, int vendorId, int productId, String descriptor, boolean isExternal, int sources, int keyboardType, KeyCharacterMap keyCharacterMap, boolean hasVibrator, boolean hasButtonUnderPad)
// Called by native code.
mId = id;
mGeneration = generation;
mControllerNumber = controllerNumber;
mName = name;
mVendorId = vendorId;
mProductId = productId;
mDescriptor = descriptor;
mIsExternal = isExternal;
mSources = sources;
mKeyboardType = keyboardType;
mKeyCharacterMap = keyCharacterMap;
mHasVibrator = hasVibrator;
mHasButtonUnderPad = hasButtonUnderPad;
mIdentifier = new InputDeviceIdentifier(descriptor, vendorId, productId);
| private InputDevice(android.os.Parcel in)
mId = in.readInt();
mGeneration = in.readInt();
mControllerNumber = in.readInt();
mName = in.readString();
mVendorId = in.readInt();
mProductId = in.readInt();
mDescriptor = in.readString();
mIsExternal = in.readInt() != 0;
mSources = in.readInt();
mKeyboardType = in.readInt();
mKeyCharacterMap = KeyCharacterMap.CREATOR.createFromParcel(in);
mHasVibrator = in.readInt() != 0;
mHasButtonUnderPad = in.readInt() != 0;
mIdentifier = new InputDeviceIdentifier(mDescriptor, mVendorId, mProductId);
for (;;) {
int axis = in.readInt();
if (axis < 0) {
break;
}
addMotionRange(axis, in.readInt(), in.readFloat(), in.readFloat(), in.readFloat(),
in.readFloat(), in.readFloat());
}
|
Methods Summary |
---|
private void | addMotionRange(int axis, int source, float min, float max, float flat, float fuzz, float resolution)
mMotionRanges.add(new MotionRange(axis, source, min, max, flat, fuzz, resolution));
| private void | appendSourceDescriptionIfApplicable(java.lang.StringBuilder description, int source, java.lang.String sourceName)
if ((mSources & source) == source) {
description.append(" ");
description.append(sourceName);
}
| public int | describeContents()
return 0;
| public int | getControllerNumber()The controller number for a given input device.
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 {@link InputManager.InputDeviceListener}.
All input devices which are not gamepads or joysticks will be assigned a controller number
of 0.
return mControllerNumber;
| public java.lang.String | getDescriptor()Gets the input device descriptor, which is a stable identifier for an input device.
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 {@link InputDevice} instances that have the
same input device descriptor. This might happen in situations where a single
human input device registers multiple {@link 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 {@link #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
{@link InputDevice} instance at runtime use the id returned by {@link #getId()}.
return mDescriptor;
| public static android.view.InputDevice | getDevice(int id)Gets information about the input device with the specified id.
return InputManager.getInstance().getInputDevice(id);
| public static int[] | getDeviceIds()Gets the ids of all input devices in the system.
return InputManager.getInstance().getInputDeviceIds();
| public int | getGeneration()Gets a generation number for this input device.
The generation number is incremented whenever the device is reconfigured and its
properties may have changed.
return mGeneration;
| public int | getId()Gets the input device id.
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 {@link #getDescriptor()}.
return mId;
| public android.hardware.input.InputDeviceIdentifier | getIdentifier()The set of identifying information for type of input device. This
information can be used by the system to configure appropriate settings
for the device.
return mIdentifier;
| public KeyCharacterMap | getKeyCharacterMap()Gets the key character map associated with this input device.
return mKeyCharacterMap;
| public int | getKeyboardType()Gets the keyboard type.
return mKeyboardType;
| public android.view.InputDevice$MotionRange | getMotionRange(int axis)Gets information about the range of values for a particular {@link 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
{@link #getMotionRange(int, int)}.
final int numRanges = mMotionRanges.size();
for (int i = 0; i < numRanges; i++) {
final MotionRange range = mMotionRanges.get(i);
if (range.mAxis == axis) {
return range;
}
}
return null;
| public android.view.InputDevice$MotionRange | getMotionRange(int axis, int source)Gets information about the range of values for a particular {@link 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.
final int numRanges = mMotionRanges.size();
for (int i = 0; i < numRanges; i++) {
final MotionRange range = mMotionRanges.get(i);
if (range.mAxis == axis && range.mSource == source) {
return range;
}
}
return null;
| public java.util.List | getMotionRanges()Gets the ranges for all axes supported by the device.
return mMotionRanges;
| public java.lang.String | getName()Gets the name of this input device.
return mName;
| public int | getProductId()Gets the product id for the given device, if available.
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.
return mProductId;
| public int | getSources()Gets the input sources supported by this input device as a combined bitfield.
return mSources;
| public int | getVendorId()Gets the vendor id for the given device, if available.
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.
return mVendorId;
| public android.os.Vibrator | getVibrator()Gets the vibrator service associated with the device, if there is one.
Even if the device does not have a vibrator, the result is never null.
Use {@link 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
{@link Context#getSystemService} with {@link Context#VIBRATOR_SERVICE} as argument.
synchronized (mMotionRanges) {
if (mVibrator == null) {
if (mHasVibrator) {
mVibrator = InputManager.getInstance().getInputDeviceVibrator(mId);
} else {
mVibrator = NullVibrator.getInstance();
}
}
return mVibrator;
}
| public boolean | hasButtonUnderPad()Reports whether the device has a button under its touchpad
return mHasButtonUnderPad;
| public boolean[] | hasKeys(int keys)Gets whether the device is capable of producing the list of keycodes.
return InputManager.getInstance().deviceHasKeys(mId, keys);
| public boolean | isExternal()Returns true if the device is external (connected to USB or Bluetooth or some other
peripheral bus), otherwise it is built-in.
return mIsExternal;
| public boolean | isFullKeyboard()Returns true if the device is a full keyboard.
return (mSources & SOURCE_KEYBOARD) == SOURCE_KEYBOARD
&& mKeyboardType == KEYBOARD_TYPE_ALPHABETIC;
| public boolean | isVirtual()Returns true if the device is a virtual input device rather than a real one,
such as the virtual keyboard (see {@link KeyCharacterMap#VIRTUAL_KEYBOARD}).
Virtual input devices are provided to implement system-level functionality
and should not be seen or configured by users.
return mId < 0;
| public boolean | supportsSource(int source)Determines whether the input device supports the given source or sources.
return (mSources & source) == source;
| public java.lang.String | toString()
StringBuilder description = new StringBuilder();
description.append("Input Device ").append(mId).append(": ").append(mName).append("\n");
description.append(" Descriptor: ").append(mDescriptor).append("\n");
description.append(" Generation: ").append(mGeneration).append("\n");
description.append(" Location: ").append(mIsExternal ? "external" : "built-in").append("\n");
description.append(" Keyboard Type: ");
switch (mKeyboardType) {
case KEYBOARD_TYPE_NONE:
description.append("none");
break;
case KEYBOARD_TYPE_NON_ALPHABETIC:
description.append("non-alphabetic");
break;
case KEYBOARD_TYPE_ALPHABETIC:
description.append("alphabetic");
break;
}
description.append("\n");
description.append(" Has Vibrator: ").append(mHasVibrator).append("\n");
description.append(" Sources: 0x").append(Integer.toHexString(mSources)).append(" (");
appendSourceDescriptionIfApplicable(description, SOURCE_KEYBOARD, "keyboard");
appendSourceDescriptionIfApplicable(description, SOURCE_DPAD, "dpad");
appendSourceDescriptionIfApplicable(description, SOURCE_TOUCHSCREEN, "touchscreen");
appendSourceDescriptionIfApplicable(description, SOURCE_MOUSE, "mouse");
appendSourceDescriptionIfApplicable(description, SOURCE_STYLUS, "stylus");
appendSourceDescriptionIfApplicable(description, SOURCE_TRACKBALL, "trackball");
appendSourceDescriptionIfApplicable(description, SOURCE_TOUCHPAD, "touchpad");
appendSourceDescriptionIfApplicable(description, SOURCE_JOYSTICK, "joystick");
appendSourceDescriptionIfApplicable(description, SOURCE_GAMEPAD, "gamepad");
description.append(" )\n");
final int numAxes = mMotionRanges.size();
for (int i = 0; i < numAxes; i++) {
MotionRange range = mMotionRanges.get(i);
description.append(" ").append(MotionEvent.axisToString(range.mAxis));
description.append(": source=0x").append(Integer.toHexString(range.mSource));
description.append(" min=").append(range.mMin);
description.append(" max=").append(range.mMax);
description.append(" flat=").append(range.mFlat);
description.append(" fuzz=").append(range.mFuzz);
description.append(" resolution=").append(range.mResolution);
description.append("\n");
}
return description.toString();
| public void | writeToParcel(android.os.Parcel out, int flags)
out.writeInt(mId);
out.writeInt(mGeneration);
out.writeInt(mControllerNumber);
out.writeString(mName);
out.writeInt(mVendorId);
out.writeInt(mProductId);
out.writeString(mDescriptor);
out.writeInt(mIsExternal ? 1 : 0);
out.writeInt(mSources);
out.writeInt(mKeyboardType);
mKeyCharacterMap.writeToParcel(out, flags);
out.writeInt(mHasVibrator ? 1 : 0);
out.writeInt(mHasButtonUnderPad ? 1 : 0);
final int numRanges = mMotionRanges.size();
for (int i = 0; i < numRanges; i++) {
MotionRange range = mMotionRanges.get(i);
out.writeInt(range.mAxis);
out.writeInt(range.mSource);
out.writeFloat(range.mMin);
out.writeFloat(range.mMax);
out.writeFloat(range.mFlat);
out.writeFloat(range.mFuzz);
out.writeFloat(range.mResolution);
}
out.writeInt(-1);
|
|