Add support for arbitrary axes in MotionEvents.

This change makes it possible to extend the set of axes that
are reported in MotionEvents by defining new axis constants.

The MotionEvent object is now backed by its C++ counterpart
to avoid having to maintain multiple representations of the
same data.

Change-Id: Ibe93c90d4b390d43c176cce48d558d20869ee608
This commit is contained in:
Jeff Brown
2011-02-14 17:03:18 -08:00
parent c3451d4a44
commit 91c69ab015
17 changed files with 2528 additions and 1162 deletions

View File

@@ -207497,22 +207497,22 @@
</method>
<method name="getDeviceId"
return="int"
abstract="false"
abstract="true"
native="false"
synchronized="false"
static="false"
final="true"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="getSource"
return="int"
abstract="false"
abstract="true"
native="false"
synchronized="false"
static="false"
final="true"
final="false"
deprecated="not deprecated"
visibility="public"
>

View File

@@ -210399,7 +210399,7 @@
deprecated="not deprecated"
visibility="public"
>
<parameter name="rangeType" type="int">
<parameter name="axis" type="int">
</parameter>
</method>
<method name="getName"
@@ -210489,7 +210489,7 @@
value="8"
static="true"
final="true"
deprecated="not deprecated"
deprecated="deprecated"
visibility="public"
>
</field>
@@ -210500,7 +210500,7 @@
value="2"
static="true"
final="true"
deprecated="not deprecated"
deprecated="deprecated"
visibility="public"
>
</field>
@@ -210511,7 +210511,7 @@
value="3"
static="true"
final="true"
deprecated="not deprecated"
deprecated="deprecated"
visibility="public"
>
</field>
@@ -210522,7 +210522,7 @@
value="6"
static="true"
final="true"
deprecated="not deprecated"
deprecated="deprecated"
visibility="public"
>
</field>
@@ -210533,7 +210533,7 @@
value="7"
static="true"
final="true"
deprecated="not deprecated"
deprecated="deprecated"
visibility="public"
>
</field>
@@ -210544,7 +210544,7 @@
value="4"
static="true"
final="true"
deprecated="not deprecated"
deprecated="deprecated"
visibility="public"
>
</field>
@@ -210555,7 +210555,7 @@
value="5"
static="true"
final="true"
deprecated="not deprecated"
deprecated="deprecated"
visibility="public"
>
</field>
@@ -210566,7 +210566,7 @@
value="0"
static="true"
final="true"
deprecated="not deprecated"
deprecated="deprecated"
visibility="public"
>
</field>
@@ -210577,7 +210577,7 @@
value="1"
static="true"
final="true"
deprecated="not deprecated"
deprecated="deprecated"
visibility="public"
>
</field>
@@ -210856,22 +210856,22 @@
</method>
<method name="getDeviceId"
return="int"
abstract="false"
abstract="true"
native="false"
synchronized="false"
static="false"
final="true"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="getSource"
return="int"
abstract="false"
abstract="true"
native="false"
synchronized="false"
static="false"
final="true"
final="false"
deprecated="not deprecated"
visibility="public"
>
@@ -211661,6 +211661,17 @@
<parameter name="c" type="int">
</parameter>
</method>
<method name="getDeviceId"
return="int"
abstract="false"
native="false"
synchronized="false"
static="false"
final="true"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="getDisplayLabel"
return="char"
abstract="false"
@@ -211834,6 +211845,17 @@
visibility="public"
>
</method>
<method name="getSource"
return="int"
abstract="false"
native="false"
synchronized="false"
static="false"
final="true"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="getUnicodeChar"
return="int"
abstract="false"
@@ -212090,6 +212112,19 @@
<parameter name="metaState" type="int">
</parameter>
</method>
<method name="setSource"
return="void"
abstract="false"
native="false"
synchronized="false"
static="false"
final="true"
deprecated="not deprecated"
visibility="public"
>
<parameter name="source" type="int">
</parameter>
</method>
<method name="startTracking"
return="void"
abstract="false"
@@ -216346,6 +216381,45 @@
visibility="public"
>
</method>
<method name="getAxisValue"
return="float"
abstract="false"
native="false"
synchronized="false"
static="false"
final="true"
deprecated="not deprecated"
visibility="public"
>
<parameter name="axis" type="int">
</parameter>
</method>
<method name="getAxisValue"
return="float"
abstract="false"
native="false"
synchronized="false"
static="false"
final="true"
deprecated="not deprecated"
visibility="public"
>
<parameter name="axis" type="int">
</parameter>
<parameter name="pointerIndex" type="int">
</parameter>
</method>
<method name="getDeviceId"
return="int"
abstract="false"
native="false"
synchronized="false"
static="false"
final="true"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="getDownTime"
return="long"
abstract="false"
@@ -216390,6 +216464,38 @@
visibility="public"
>
</method>
<method name="getHistoricalAxisValue"
return="float"
abstract="false"
native="false"
synchronized="false"
static="false"
final="true"
deprecated="not deprecated"
visibility="public"
>
<parameter name="axis" type="int">
</parameter>
<parameter name="pos" type="int">
</parameter>
</method>
<method name="getHistoricalAxisValue"
return="float"
abstract="false"
native="false"
synchronized="false"
static="false"
final="true"
deprecated="not deprecated"
visibility="public"
>
<parameter name="axis" type="int">
</parameter>
<parameter name="pointerIndex" type="int">
</parameter>
<parameter name="pos" type="int">
</parameter>
</method>
<method name="getHistoricalEventTime"
return="long"
abstract="false"
@@ -216827,6 +216933,17 @@
<parameter name="pointerIndex" type="int">
</parameter>
</method>
<method name="getSource"
return="int"
abstract="false"
native="false"
synchronized="false"
static="false"
final="true"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="getToolMajor"
return="float"
abstract="false"
@@ -217135,7 +217252,7 @@
deprecated="not deprecated"
visibility="public"
>
<parameter name="o" type="android.view.MotionEvent">
<parameter name="other" type="android.view.MotionEvent">
</parameter>
</method>
<method name="obtainNoHistory"
@@ -217148,7 +217265,7 @@
deprecated="not deprecated"
visibility="public"
>
<parameter name="o" type="android.view.MotionEvent">
<parameter name="other" type="android.view.MotionEvent">
</parameter>
</method>
<method name="offsetLocation"
@@ -217218,6 +217335,19 @@
<parameter name="y" type="float">
</parameter>
</method>
<method name="setSource"
return="void"
abstract="false"
native="false"
synchronized="false"
static="false"
final="true"
deprecated="not deprecated"
visibility="public"
>
<parameter name="source" type="int">
</parameter>
</method>
<method name="transform"
return="void"
abstract="false"
@@ -217444,6 +217574,105 @@
visibility="public"
>
</field>
<field name="AXIS_ORIENTATION"
type="int"
transient="false"
volatile="false"
value="8"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="AXIS_PRESSURE"
type="int"
transient="false"
volatile="false"
value="2"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="AXIS_SIZE"
type="int"
transient="false"
volatile="false"
value="3"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="AXIS_TOOL_MAJOR"
type="int"
transient="false"
volatile="false"
value="6"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="AXIS_TOOL_MINOR"
type="int"
transient="false"
volatile="false"
value="7"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="AXIS_TOUCH_MAJOR"
type="int"
transient="false"
volatile="false"
value="4"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="AXIS_TOUCH_MINOR"
type="int"
transient="false"
volatile="false"
value="5"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="AXIS_X"
type="int"
transient="false"
volatile="false"
value="0"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="AXIS_Y"
type="int"
transient="false"
volatile="false"
value="1"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="CREATOR"
type="android.os.Parcelable.Creator"
transient="false"
@@ -217526,6 +217755,68 @@
visibility="public"
>
</constructor>
<constructor name="MotionEvent.PointerCoords"
type="android.view.MotionEvent.PointerCoords"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="other" type="android.view.MotionEvent.PointerCoords">
</parameter>
</constructor>
<method name="clear"
return="void"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="copyFrom"
return="void"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="other" type="android.view.MotionEvent.PointerCoords">
</parameter>
</method>
<method name="getAxisValue"
return="float"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="axis" type="int">
</parameter>
</method>
<method name="setAxisValue"
return="void"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="axis" type="int">
</parameter>
<parameter name="value" type="float">
</parameter>
</method>
<field name="orientation"
type="float"
transient="false"
@@ -265620,7 +265911,7 @@
deprecated="not deprecated"
visibility="public"
>
<parameter name="t" type="T">
<parameter name="arg0" type="T">
</parameter>
</method>
</interface>

View File

@@ -20,6 +20,7 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.SparseArray;
/**
* Describes the capabilities of a particular input device.
@@ -41,9 +42,9 @@ public final class InputDevice implements Parcelable {
private String mName;
private int mSources;
private int mKeyboardType;
private MotionRange[] mMotionRanges;
private final SparseArray<MotionRange> mMotionRanges = new SparseArray<MotionRange>();
/**
* A mask for input source classes.
*
@@ -181,70 +182,85 @@ public final class InputDevice implements Parcelable {
public static final int SOURCE_ANY = 0xffffff00;
/**
* Constant for retrieving the range of values for {@link MotionEvent.PointerCoords#x}.
* Constant for retrieving the range of values for {@link MotionEvent#AXIS_X}.
*
* @see #getMotionRange
* @deprecated Use {@link MotionEvent#AXIS_X} instead.
*/
public static final int MOTION_RANGE_X = 0;
@Deprecated
public static final int MOTION_RANGE_X = MotionEvent.AXIS_X;
/**
* Constant for retrieving the range of values for {@link MotionEvent.PointerCoords#y}.
* Constant for retrieving the range of values for {@link MotionEvent#AXIS_Y}.
*
* @see #getMotionRange
* @deprecated Use {@link MotionEvent#AXIS_Y} instead.
*/
public static final int MOTION_RANGE_Y = 1;
@Deprecated
public static final int MOTION_RANGE_Y = MotionEvent.AXIS_Y;
/**
* Constant for retrieving the range of values for {@link MotionEvent.PointerCoords#pressure}.
* Constant for retrieving the range of values for {@link MotionEvent#AXIS_PRESSURE}.
*
* @see #getMotionRange
* @deprecated Use {@link MotionEvent#AXIS_PRESSURE} instead.
*/
public static final int MOTION_RANGE_PRESSURE = 2;
@Deprecated
public static final int MOTION_RANGE_PRESSURE = MotionEvent.AXIS_PRESSURE;
/**
* Constant for retrieving the range of values for {@link MotionEvent.PointerCoords#size}.
* Constant for retrieving the range of values for {@link MotionEvent#AXIS_SIZE}.
*
* @see #getMotionRange
* @deprecated Use {@link MotionEvent#AXIS_SIZE} instead.
*/
public static final int MOTION_RANGE_SIZE = 3;
@Deprecated
public static final int MOTION_RANGE_SIZE = MotionEvent.AXIS_SIZE;
/**
* Constant for retrieving the range of values for {@link MotionEvent.PointerCoords#touchMajor}.
* Constant for retrieving the range of values for {@link MotionEvent#AXIS_TOUCH_MAJOR}.
*
* @see #getMotionRange
* @deprecated Use {@link MotionEvent#AXIS_TOUCH_MAJOR} instead.
*/
public static final int MOTION_RANGE_TOUCH_MAJOR = 4;
@Deprecated
public static final int MOTION_RANGE_TOUCH_MAJOR = MotionEvent.AXIS_TOUCH_MAJOR;
/**
* Constant for retrieving the range of values for {@link MotionEvent.PointerCoords#touchMinor}.
* Constant for retrieving the range of values for {@link MotionEvent#AXIS_TOUCH_MINOR}.
*
* @see #getMotionRange
* @deprecated Use {@link MotionEvent#AXIS_TOUCH_MINOR} instead.
*/
public static final int MOTION_RANGE_TOUCH_MINOR = 5;
@Deprecated
public static final int MOTION_RANGE_TOUCH_MINOR = MotionEvent.AXIS_TOUCH_MINOR;
/**
* Constant for retrieving the range of values for {@link MotionEvent.PointerCoords#toolMajor}.
* Constant for retrieving the range of values for {@link MotionEvent#AXIS_TOOL_MAJOR}.
*
* @see #getMotionRange
* @deprecated Use {@link MotionEvent#AXIS_TOOL_MAJOR} instead.
*/
public static final int MOTION_RANGE_TOOL_MAJOR = 6;
@Deprecated
public static final int MOTION_RANGE_TOOL_MAJOR = MotionEvent.AXIS_TOOL_MAJOR;
/**
* Constant for retrieving the range of values for {@link MotionEvent.PointerCoords#toolMinor}.
* Constant for retrieving the range of values for {@link MotionEvent#AXIS_TOOL_MINOR}.
*
* @see #getMotionRange
* @deprecated Use {@link MotionEvent#AXIS_TOOL_MINOR} instead.
*/
public static final int MOTION_RANGE_TOOL_MINOR = 7;
@Deprecated
public static final int MOTION_RANGE_TOOL_MINOR = MotionEvent.AXIS_TOOL_MINOR;
/**
* Constant for retrieving the range of values for
* {@link MotionEvent.PointerCoords#orientation}.
* Constant for retrieving the range of values for {@link MotionEvent#AXIS_ORIENTATION}.
*
* @see #getMotionRange
* @deprecated Use {@link MotionEvent#AXIS_ORIENTATION} instead.
*/
public static final int MOTION_RANGE_ORIENTATION = 8;
private static final int MOTION_RANGE_LAST = MOTION_RANGE_ORIENTATION;
@Deprecated
public static final int MOTION_RANGE_ORIENTATION = MotionEvent.AXIS_ORIENTATION;
/**
* There is no keyboard.
@@ -261,10 +277,9 @@ public final class InputDevice implements Parcelable {
* The keyboard supports a complement of alphabetic keys.
*/
public static final int KEYBOARD_TYPE_ALPHABETIC = 2;
// Called by native code.
private InputDevice() {
mMotionRanges = new MotionRange[MOTION_RANGE_LAST + 1];
}
/**
@@ -335,72 +350,69 @@ public final class InputDevice implements Parcelable {
public KeyCharacterMap getKeyCharacterMap() {
return KeyCharacterMap.load(mId);
}
/**
* Gets information about the range of values for a particular {@link MotionEvent}
* coordinate.
* @param rangeType The motion range constant.
* @return The range of values, or null if the requested coordinate is not
* Gets information about the range of values for a particular {@link MotionEvent} axis.
* @param axis The axis constant.
* @return The range of values, or null if the requested axis is not
* supported by the device.
*
* @see MotionEvent#AXIS_X
* @see MotionEvent#AXIS_Y
*/
public MotionRange getMotionRange(int rangeType) {
if (rangeType < 0 || rangeType > MOTION_RANGE_LAST) {
throw new IllegalArgumentException("Requested range is out of bounds.");
}
return mMotionRanges[rangeType];
public MotionRange getMotionRange(int axis) {
return mMotionRanges.get(axis);
}
private void addMotionRange(int rangeType, float min, float max, float flat, float fuzz) {
if (rangeType >= 0 && rangeType <= MOTION_RANGE_LAST) {
MotionRange range = new MotionRange(min, max, flat, fuzz);
mMotionRanges[rangeType] = range;
}
// Called by native code.
private void addMotionRange(int axis, float min, float max, float flat, float fuzz) {
mMotionRanges.append(axis, new MotionRange(min, max, flat, fuzz));
}
/**
* Provides information about the range of values for a particular {@link MotionEvent}
* coordinate.
* Provides information about the range of values for a particular {@link MotionEvent} axis.
*
* @see InputDevice#getMotionRange(int)
*/
public static final class MotionRange {
private float mMin;
private float mMax;
private float mFlat;
private float mFuzz;
private MotionRange(float min, float max, float flat, float fuzz) {
mMin = min;
mMax = max;
mFlat = flat;
mFuzz = fuzz;
}
/**
* Gets the minimum value for the coordinate.
* @return The minimum value.
* Gets the minimum value for the axis.
* @return The (inclusive) minimum value.
*/
public float getMin() {
return mMin;
}
/**
* Gets the maximum value for the coordinate.
* @return The minimum value.
* Gets the maximum value for the axis.
* @return The (inclusive) maximum value.
*/
public float getMax() {
return mMax;
}
/**
* Gets the range of the coordinate (difference between maximum and minimum).
* Gets the range of the axis (difference between maximum and minimum plus one).
* @return The range of values.
*/
public float getRange() {
return mMax - mMin;
return mMax - mMin + 1;
}
/**
* Gets the extent of the center flat position with respect to this coordinate.
* Gets the extent of the center flat position with respect to this axis.
* For example, a flat value of 8 means that the center position is between -8 and +8.
* This value is mainly useful for calibrating self-centering devices.
* @return The extent of the center flat position.
@@ -408,9 +420,9 @@ public final class InputDevice implements Parcelable {
public float getFlat() {
return mFlat;
}
/**
* Gets the error tolerance for input device measurements with respect to this coordinate.
* Gets the error tolerance for input device measurements with respect to this axis.
* For example, a value of 2 indicates that the measured value may be up to +/- 2 units
* away from the actual value due to noise and device sensitivity limitations.
* @return The error tolerance.
@@ -419,7 +431,7 @@ public final class InputDevice implements Parcelable {
return mFuzz;
}
}
public static final Parcelable.Creator<InputDevice> CREATOR
= new Parcelable.Creator<InputDevice>() {
public InputDevice createFromParcel(Parcel in) {
@@ -438,15 +450,13 @@ public final class InputDevice implements Parcelable {
mName = in.readString();
mSources = in.readInt();
mKeyboardType = in.readInt();
for (;;) {
int rangeType = in.readInt();
if (rangeType < 0) {
int axis = in.readInt();
if (axis < 0) {
break;
}
addMotionRange(rangeType,
in.readFloat(), in.readFloat(), in.readFloat(), in.readFloat());
addMotionRange(axis, in.readFloat(), in.readFloat(), in.readFloat(), in.readFloat());
}
}
@@ -456,25 +466,25 @@ public final class InputDevice implements Parcelable {
out.writeString(mName);
out.writeInt(mSources);
out.writeInt(mKeyboardType);
for (int i = 0; i <= MOTION_RANGE_LAST; i++) {
MotionRange range = mMotionRanges[i];
if (range != null) {
out.writeInt(i);
out.writeFloat(range.mMin);
out.writeFloat(range.mMax);
out.writeFloat(range.mFlat);
out.writeFloat(range.mFuzz);
}
final int numAxes = mMotionRanges.size();
for (int i = 0; i < numAxes; i++) {
int axis = mMotionRanges.keyAt(i);
MotionRange range = mMotionRanges.valueAt(i);
out.writeInt(axis);
out.writeFloat(range.mMin);
out.writeFloat(range.mMax);
out.writeFloat(range.mFlat);
out.writeFloat(range.mFuzz);
}
out.writeInt(-1);
}
@Override
public int describeContents() {
return 0;
}
@Override
public String toString() {
StringBuilder description = new StringBuilder();
@@ -493,29 +503,32 @@ public final class InputDevice implements Parcelable {
break;
}
description.append("\n");
description.append(" Sources:");
description.append(" Sources: ").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_TRACKBALL, "trackball");
appendSourceDescriptionIfApplicable(description, SOURCE_TOUCHPAD, "touchpad");
description.append("\n");
appendRangeDescriptionIfApplicable(description, MOTION_RANGE_X, "x");
appendRangeDescriptionIfApplicable(description, MOTION_RANGE_Y, "y");
appendRangeDescriptionIfApplicable(description, MOTION_RANGE_PRESSURE, "pressure");
appendRangeDescriptionIfApplicable(description, MOTION_RANGE_SIZE, "size");
appendRangeDescriptionIfApplicable(description, MOTION_RANGE_TOUCH_MAJOR, "touchMajor");
appendRangeDescriptionIfApplicable(description, MOTION_RANGE_TOUCH_MINOR, "touchMinor");
appendRangeDescriptionIfApplicable(description, MOTION_RANGE_TOOL_MAJOR, "toolMajor");
appendRangeDescriptionIfApplicable(description, MOTION_RANGE_TOOL_MINOR, "toolMinor");
appendRangeDescriptionIfApplicable(description, MOTION_RANGE_ORIENTATION, "orientation");
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++) {
int axis = mMotionRanges.keyAt(i);
MotionRange range = mMotionRanges.valueAt(i);
description.append(" ").append(MotionEvent.axisToString(axis));
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("\n");
}
return description.toString();
}
private void appendSourceDescriptionIfApplicable(StringBuilder description, int source,
String sourceName) {
if ((mSources & source) == source) {
@@ -523,17 +536,4 @@ public final class InputDevice implements Parcelable {
description.append(sourceName);
}
}
private void appendRangeDescriptionIfApplicable(StringBuilder description,
int rangeType, String rangeName) {
MotionRange range = mMotionRanges[rangeType];
if (range != null) {
description.append(" Range[").append(rangeName);
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("\n");
}
}
}

View File

@@ -23,11 +23,6 @@ import android.os.Parcelable;
* Common base class for input events.
*/
public abstract class InputEvent implements Parcelable {
/** @hide */
protected int mDeviceId;
/** @hide */
protected int mSource;
/** @hide */
protected static final int PARCEL_TOKEN_MOTION_EVENT = 1;
/** @hide */
@@ -45,55 +40,37 @@ public abstract class InputEvent implements Parcelable {
* @return The device id.
* @see InputDevice#getDevice
*/
public final int getDeviceId() {
return mDeviceId;
}
public abstract int getDeviceId();
/**
* Gets the device that this event came from.
*
* @return The device, or null if unknown.
*/
public final InputDevice getDevice() {
return InputDevice.getDevice(mDeviceId);
return InputDevice.getDevice(getDeviceId());
}
/**
* Gets the source of the event.
*
* @return The event source or {@link InputDevice#SOURCE_UNKNOWN} if unknown.
* @see InputDevice#getSourceInfo
*/
public final int getSource() {
return mSource;
}
public abstract int getSource();
/**
* Modifies the source of the event.
* @param source The source.
*
*
* @param source The new source.
* @hide
*/
public final void setSource(int source) {
mSource = source;
}
public abstract void setSource(int source);
public int describeContents() {
return 0;
}
/** @hide */
protected final void readBaseFromParcel(Parcel in) {
mDeviceId = in.readInt();
mSource = in.readInt();
}
/** @hide */
protected final void writeBaseToParcel(Parcel out) {
out.writeInt(mDeviceId);
out.writeInt(mSource);
}
public static final Parcelable.Creator<InputEvent> CREATOR
= new Parcelable.Creator<InputEvent>() {
public InputEvent createFromParcel(Parcel in) {

View File

@@ -1180,6 +1180,8 @@ public class KeyEvent extends InputEvent implements Parcelable {
private KeyEvent mNext;
private boolean mRecycled;
private int mDeviceId;
private int mSource;
private int mMetaState;
private int mAction;
private int mKeyCode;
@@ -1651,6 +1653,23 @@ public class KeyEvent extends InputEvent implements Parcelable {
return native_hasDefaultAction(mKeyCode);
}
/** {@inheritDoc} */
@Override
public final int getDeviceId() {
return mDeviceId;
}
/** {@inheritDoc} */
@Override
public final int getSource() {
return mSource;
}
/** {@inheritDoc} */
@Override
public final void setSource(int source) {
mSource = source;
}
/**
* <p>Returns the state of the meta keys.</p>
@@ -2651,8 +2670,8 @@ public class KeyEvent extends InputEvent implements Parcelable {
}
private KeyEvent(Parcel in) {
readBaseFromParcel(in);
mDeviceId = in.readInt();
mSource = in.readInt();
mAction = in.readInt();
mKeyCode = in.readInt();
mRepeatCount = in.readInt();
@@ -2665,9 +2684,9 @@ public class KeyEvent extends InputEvent implements Parcelable {
public void writeToParcel(Parcel out, int flags) {
out.writeInt(PARCEL_TOKEN_KEY_EVENT);
writeBaseToParcel(out);
out.writeInt(mDeviceId);
out.writeInt(mSource);
out.writeInt(mAction);
out.writeInt(mKeyCode);
out.writeInt(mRepeatCount);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -28,6 +28,10 @@
#include <utils/RefBase.h>
#include <utils/String8.h>
#ifdef HAVE_ANDROID_OS
class SkMatrix;
#endif
/*
* Additional private constants not defined in ndk/ui/input.h.
*/
@@ -79,6 +83,10 @@ struct AInputDevice {
namespace android {
#ifdef HAVE_ANDROID_OS
class Parcel;
#endif
/*
* Flags that flow alongside events in the input dispatch system to help with certain
* policy decisions such as waking from device sleep.
@@ -162,15 +170,61 @@ struct InputConfiguration {
* Pointer coordinate data.
*/
struct PointerCoords {
float x;
float y;
float pressure;
float size;
float touchMajor;
float touchMinor;
float toolMajor;
float toolMinor;
float orientation;
static const size_t MAX_AXES = 15; // 15 so that sizeof(PointerCoords) == 16 * 4 == 64
// Bitfield of axes that are present in this structure.
uint32_t bits; // 32bits are enough for now, can raise to 64bit when needed
// Values of axes that are stored in this structure packed in order by axis id
// for each axis that is present in the structure according to 'bits'.
float values[MAX_AXES];
inline void clear() {
bits = 0;
}
inline float getAxisValue(int32_t axis) const {
uint32_t axisBit = 1 << axis;
if (!(bits & axisBit)) {
return 0;
}
uint32_t index = __builtin_popcount(bits & (axisBit - 1));
return values[index];
}
inline void setAxisValue(int32_t axis, float value) {
uint32_t axisBit = 1 << axis;
uint32_t index = __builtin_popcount(bits & (axisBit - 1));
if (!(bits & axisBit)) {
uint32_t count = __builtin_popcount(bits);
if (count >= MAX_AXES) {
tooManyAxes(axis);
return;
}
bits |= axisBit;
for (uint32_t i = count; i > index; i--) {
values[i] = values[i - 1];
}
}
values[index] = value;
}
inline float* editAxisValue(int32_t axis) {
uint32_t axisBit = 1 << axis;
if (!(bits & axisBit)) {
return NULL;
}
uint32_t index = __builtin_popcount(bits & (axisBit - 1));
return &values[index];
}
#ifdef HAVE_ANDROID_OS
status_t readFromParcel(Parcel* parcel);
status_t writeToParcel(Parcel* parcel) const;
#endif
private:
void tooManyAxes(int axis);
};
/*
@@ -185,12 +239,13 @@ public:
inline int32_t getDeviceId() const { return mDeviceId; }
inline int32_t getSource() const { return mSource; }
inline void setSource(int32_t source) { mSource = source; }
protected:
void initialize(int32_t deviceId, int32_t source);
void initialize(const InputEvent& from);
private:
int32_t mDeviceId;
int32_t mSource;
};
@@ -241,7 +296,7 @@ public:
nsecs_t eventTime);
void initialize(const KeyEvent& from);
private:
protected:
int32_t mAction;
int32_t mFlags;
int32_t mKeyCode;
@@ -263,12 +318,18 @@ public:
inline int32_t getAction() const { return mAction; }
inline void setAction(int32_t action) { mAction = action; }
inline int32_t getFlags() const { return mFlags; }
inline int32_t getEdgeFlags() const { return mEdgeFlags; }
inline void setEdgeFlags(int32_t edgeFlags) { mEdgeFlags = edgeFlags; }
inline int32_t getMetaState() const { return mMetaState; }
inline void setMetaState(int32_t metaState) { mMetaState = metaState; }
inline float getXOffset() const { return mXOffset; }
inline float getYOffset() const { return mYOffset; }
@@ -285,48 +346,54 @@ public:
inline nsecs_t getEventTime() const { return mSampleEventTimes[getHistorySize()]; }
const PointerCoords* getRawPointerCoords(size_t pointerIndex) const;
float getRawAxisValue(int32_t axis, size_t pointerIndex) const;
inline float getRawX(size_t pointerIndex) const {
return getCurrentPointerCoords(pointerIndex).x;
return getRawAxisValue(AINPUT_MOTION_AXIS_X, pointerIndex);
}
inline float getRawY(size_t pointerIndex) const {
return getCurrentPointerCoords(pointerIndex).y;
return getRawAxisValue(AINPUT_MOTION_AXIS_Y, pointerIndex);
}
float getAxisValue(int32_t axis, size_t pointerIndex) const;
inline float getX(size_t pointerIndex) const {
return getRawX(pointerIndex) + mXOffset;
return getAxisValue(AINPUT_MOTION_AXIS_X, pointerIndex);
}
inline float getY(size_t pointerIndex) const {
return getRawY(pointerIndex) + mYOffset;
return getAxisValue(AINPUT_MOTION_AXIS_Y, pointerIndex);
}
inline float getPressure(size_t pointerIndex) const {
return getCurrentPointerCoords(pointerIndex).pressure;
return getAxisValue(AINPUT_MOTION_AXIS_PRESSURE, pointerIndex);
}
inline float getSize(size_t pointerIndex) const {
return getCurrentPointerCoords(pointerIndex).size;
return getAxisValue(AINPUT_MOTION_AXIS_SIZE, pointerIndex);
}
inline float getTouchMajor(size_t pointerIndex) const {
return getCurrentPointerCoords(pointerIndex).touchMajor;
return getAxisValue(AINPUT_MOTION_AXIS_TOUCH_MAJOR, pointerIndex);
}
inline float getTouchMinor(size_t pointerIndex) const {
return getCurrentPointerCoords(pointerIndex).touchMinor;
return getAxisValue(AINPUT_MOTION_AXIS_TOUCH_MINOR, pointerIndex);
}
inline float getToolMajor(size_t pointerIndex) const {
return getCurrentPointerCoords(pointerIndex).toolMajor;
return getAxisValue(AINPUT_MOTION_AXIS_TOOL_MAJOR, pointerIndex);
}
inline float getToolMinor(size_t pointerIndex) const {
return getCurrentPointerCoords(pointerIndex).toolMinor;
return getAxisValue(AINPUT_MOTION_AXIS_TOOL_MINOR, pointerIndex);
}
inline float getOrientation(size_t pointerIndex) const {
return getCurrentPointerCoords(pointerIndex).orientation;
return getAxisValue(AINPUT_MOTION_AXIS_ORIENTATION, pointerIndex);
}
inline size_t getHistorySize() const { return mSampleEventTimes.size() - 1; }
@@ -335,48 +402,67 @@ public:
return mSampleEventTimes[historicalIndex];
}
const PointerCoords* getHistoricalRawPointerCoords(
size_t pointerIndex, size_t historicalIndex) const;
float getHistoricalRawAxisValue(int32_t axis, size_t pointerIndex,
size_t historicalIndex) const;
inline float getHistoricalRawX(size_t pointerIndex, size_t historicalIndex) const {
return getHistoricalPointerCoords(pointerIndex, historicalIndex).x;
return getHistoricalRawAxisValue(
AINPUT_MOTION_AXIS_X, pointerIndex, historicalIndex);
}
inline float getHistoricalRawY(size_t pointerIndex, size_t historicalIndex) const {
return getHistoricalPointerCoords(pointerIndex, historicalIndex).y;
return getHistoricalRawAxisValue(
AINPUT_MOTION_AXIS_Y, pointerIndex, historicalIndex);
}
float getHistoricalAxisValue(int32_t axis, size_t pointerIndex, size_t historicalIndex) const;
inline float getHistoricalX(size_t pointerIndex, size_t historicalIndex) const {
return getHistoricalRawX(pointerIndex, historicalIndex) + mXOffset;
return getHistoricalAxisValue(
AINPUT_MOTION_AXIS_X, pointerIndex, historicalIndex);
}
inline float getHistoricalY(size_t pointerIndex, size_t historicalIndex) const {
return getHistoricalRawY(pointerIndex, historicalIndex) + mYOffset;
return getHistoricalAxisValue(
AINPUT_MOTION_AXIS_Y, pointerIndex, historicalIndex);
}
inline float getHistoricalPressure(size_t pointerIndex, size_t historicalIndex) const {
return getHistoricalPointerCoords(pointerIndex, historicalIndex).pressure;
return getHistoricalAxisValue(
AINPUT_MOTION_AXIS_PRESSURE, pointerIndex, historicalIndex);
}
inline float getHistoricalSize(size_t pointerIndex, size_t historicalIndex) const {
return getHistoricalPointerCoords(pointerIndex, historicalIndex).size;
return getHistoricalAxisValue(
AINPUT_MOTION_AXIS_SIZE, pointerIndex, historicalIndex);
}
inline float getHistoricalTouchMajor(size_t pointerIndex, size_t historicalIndex) const {
return getHistoricalPointerCoords(pointerIndex, historicalIndex).touchMajor;
return getHistoricalAxisValue(
AINPUT_MOTION_AXIS_TOUCH_MAJOR, pointerIndex, historicalIndex);
}
inline float getHistoricalTouchMinor(size_t pointerIndex, size_t historicalIndex) const {
return getHistoricalPointerCoords(pointerIndex, historicalIndex).touchMinor;
return getHistoricalAxisValue(
AINPUT_MOTION_AXIS_TOUCH_MINOR, pointerIndex, historicalIndex);
}
inline float getHistoricalToolMajor(size_t pointerIndex, size_t historicalIndex) const {
return getHistoricalPointerCoords(pointerIndex, historicalIndex).toolMajor;
return getHistoricalAxisValue(
AINPUT_MOTION_AXIS_TOOL_MAJOR, pointerIndex, historicalIndex);
}
inline float getHistoricalToolMinor(size_t pointerIndex, size_t historicalIndex) const {
return getHistoricalPointerCoords(pointerIndex, historicalIndex).toolMinor;
return getHistoricalAxisValue(
AINPUT_MOTION_AXIS_TOOL_MINOR, pointerIndex, historicalIndex);
}
inline float getHistoricalOrientation(size_t pointerIndex, size_t historicalIndex) const {
return getHistoricalPointerCoords(pointerIndex, historicalIndex).orientation;
return getHistoricalAxisValue(
AINPUT_MOTION_AXIS_ORIENTATION, pointerIndex, historicalIndex);
}
void initialize(
@@ -396,12 +482,23 @@ public:
const int32_t* pointerIds,
const PointerCoords* pointerCoords);
void copyFrom(const MotionEvent* other, bool keepHistory);
void addSample(
nsecs_t eventTime,
const PointerCoords* pointerCoords);
void offsetLocation(float xOffset, float yOffset);
void scale(float scaleFactor);
#ifdef HAVE_ANDROID_OS
void transform(const SkMatrix* matrix);
status_t readFromParcel(Parcel* parcel);
status_t writeToParcel(Parcel* parcel) const;
#endif
// Low-level accessors.
inline const int32_t* getPointerIds() const { return mPointerIds.array(); }
inline const nsecs_t* getSampleEventTimes() const { return mSampleEventTimes.array(); }
@@ -409,7 +506,7 @@ public:
return mSamplePointerCoords.array();
}
private:
protected:
int32_t mAction;
int32_t mFlags;
int32_t mEdgeFlags;
@@ -422,15 +519,6 @@ private:
Vector<int32_t> mPointerIds;
Vector<nsecs_t> mSampleEventTimes;
Vector<PointerCoords> mSamplePointerCoords;
inline const PointerCoords& getCurrentPointerCoords(size_t pointerIndex) const {
return mSamplePointerCoords[getHistorySize() * getPointerCount() + pointerIndex];
}
inline const PointerCoords& getHistoricalPointerCoords(
size_t pointerIndex, size_t historicalIndex) const {
return mSamplePointerCoords[historicalIndex * getPointerCount() + pointerIndex];
}
};
/*
@@ -486,11 +574,11 @@ public:
inline const String8 getName() const { return mName; }
inline uint32_t getSources() const { return mSources; }
const MotionRange* getMotionRange(int32_t rangeType) const;
const MotionRange* getMotionRange(int32_t axis) const;
void addSource(uint32_t source);
void addMotionRange(int32_t rangeType, float min, float max, float flat, float fuzz);
void addMotionRange(int32_t rangeType, const MotionRange& range);
void addMotionRange(int32_t axis, float min, float max, float flat, float fuzz);
void addMotionRange(int32_t axis, const MotionRange& range);
inline void setKeyboardType(int32_t keyboardType) { mKeyboardType = keyboardType; }
inline int32_t getKeyboardType() const { return mKeyboardType; }

View File

@@ -60,7 +60,12 @@ LOCAL_SHARED_LIBRARIES := \
libEGL \
libpixelflinger \
libhardware \
libhardware_legacy
libhardware_legacy \
libskia \
libbinder
LOCAL_C_INCLUDES := \
external/skia/include/core
LOCAL_MODULE:= libui

View File

@@ -15,6 +15,16 @@
#include <ui/Input.h>
#include <math.h>
#ifdef HAVE_ANDROID_OS
#include <binder/Parcel.h>
#include "SkPoint.h"
#include "SkMatrix.h"
#include "SkScalar.h"
#endif
namespace android {
static const char* CONFIGURATION_FILE_DIR[] = {
@@ -237,6 +247,41 @@ void KeyEvent::initialize(const KeyEvent& from) {
mEventTime = from.mEventTime;
}
// --- PointerCoords ---
#ifdef HAVE_ANDROID_OS
status_t PointerCoords::readFromParcel(Parcel* parcel) {
bits = parcel->readInt32();
uint32_t count = __builtin_popcount(bits);
if (count > MAX_AXES) {
return BAD_VALUE;
}
for (uint32_t i = 0; i < count; i++) {
values[i] = parcel->readInt32();
}
return OK;
}
status_t PointerCoords::writeToParcel(Parcel* parcel) const {
parcel->writeInt32(bits);
uint32_t count = __builtin_popcount(bits);
for (uint32_t i = 0; i < count; i++) {
parcel->writeInt32(values[i]);
}
return OK;
}
#endif
void PointerCoords::tooManyAxes(int axis) {
LOGW("Could not set value for axis %d because the PointerCoords structure is full and "
"cannot contain more than %d axis values.", axis, int(MAX_AXES));
}
// --- MotionEvent ---
void MotionEvent::initialize(
@@ -272,6 +317,33 @@ void MotionEvent::initialize(
addSample(eventTime, pointerCoords);
}
void MotionEvent::copyFrom(const MotionEvent* other, bool keepHistory) {
InputEvent::initialize(other->mDeviceId, other->mSource);
mAction = other->mAction;
mFlags = other->mFlags;
mEdgeFlags = other->mEdgeFlags;
mMetaState = other->mMetaState;
mXOffset = other->mXOffset;
mYOffset = other->mYOffset;
mXPrecision = other->mXPrecision;
mYPrecision = other->mYPrecision;
mDownTime = other->mDownTime;
mPointerIds = other->mPointerIds;
if (keepHistory) {
mSampleEventTimes = other->mSampleEventTimes;
mSamplePointerCoords = other->mSamplePointerCoords;
} else {
mSampleEventTimes.clear();
mSampleEventTimes.push(other->getEventTime());
mSamplePointerCoords.clear();
size_t pointerCount = other->getPointerCount();
size_t historySize = other->getHistorySize();
mSamplePointerCoords.appendArray(other->mSamplePointerCoords.array()
+ (historySize * pointerCount), pointerCount);
}
}
void MotionEvent::addSample(
int64_t eventTime,
const PointerCoords* pointerCoords) {
@@ -279,11 +351,224 @@ void MotionEvent::addSample(
mSamplePointerCoords.appendArray(pointerCoords, getPointerCount());
}
const PointerCoords* MotionEvent::getRawPointerCoords(size_t pointerIndex) const {
return &mSamplePointerCoords[getHistorySize() * getPointerCount() + pointerIndex];
}
float MotionEvent::getRawAxisValue(int32_t axis, size_t pointerIndex) const {
return getRawPointerCoords(pointerIndex)->getAxisValue(axis);
}
float MotionEvent::getAxisValue(int32_t axis, size_t pointerIndex) const {
float value = getRawPointerCoords(pointerIndex)->getAxisValue(axis);
switch (axis) {
case AINPUT_MOTION_AXIS_X:
value += mXOffset;
break;
case AINPUT_MOTION_AXIS_Y:
value += mYOffset;
break;
}
return value;
}
const PointerCoords* MotionEvent::getHistoricalRawPointerCoords(
size_t pointerIndex, size_t historicalIndex) const {
return &mSamplePointerCoords[historicalIndex * getPointerCount() + pointerIndex];
}
float MotionEvent::getHistoricalRawAxisValue(int32_t axis, size_t pointerIndex,
size_t historicalIndex) const {
return getHistoricalRawPointerCoords(pointerIndex, historicalIndex)->getAxisValue(axis);
}
float MotionEvent::getHistoricalAxisValue(int32_t axis, size_t pointerIndex,
size_t historicalIndex) const {
float value = getHistoricalRawPointerCoords(pointerIndex, historicalIndex)->getAxisValue(axis);
switch (axis) {
case AINPUT_MOTION_AXIS_X:
value += mXOffset;
break;
case AINPUT_MOTION_AXIS_Y:
value += mYOffset;
break;
}
return value;
}
void MotionEvent::offsetLocation(float xOffset, float yOffset) {
mXOffset += xOffset;
mYOffset += yOffset;
}
static inline void scaleAxisValue(PointerCoords& c, int axis, float scaleFactor) {
float* value = c.editAxisValue(axis);
if (value) {
*value *= scaleFactor;
}
}
void MotionEvent::scale(float scaleFactor) {
mXOffset *= scaleFactor;
mYOffset *= scaleFactor;
mXPrecision *= scaleFactor;
mYPrecision *= scaleFactor;
size_t numSamples = mSamplePointerCoords.size();
for (size_t i = 0; i < numSamples; i++) {
PointerCoords& c = mSamplePointerCoords.editItemAt(i);
// No need to scale pressure or size since they are normalized.
// No need to scale orientation since it is meaningless to do so.
scaleAxisValue(c, AINPUT_MOTION_AXIS_X, scaleFactor);
scaleAxisValue(c, AINPUT_MOTION_AXIS_Y, scaleFactor);
scaleAxisValue(c, AINPUT_MOTION_AXIS_TOUCH_MAJOR, scaleFactor);
scaleAxisValue(c, AINPUT_MOTION_AXIS_TOUCH_MINOR, scaleFactor);
scaleAxisValue(c, AINPUT_MOTION_AXIS_TOOL_MAJOR, scaleFactor);
scaleAxisValue(c, AINPUT_MOTION_AXIS_TOOL_MINOR, scaleFactor);
}
}
#ifdef HAVE_ANDROID_OS
static inline float transformAngle(const SkMatrix* matrix, float angleRadians) {
// Construct and transform a vector oriented at the specified clockwise angle from vertical.
// Coordinate system: down is increasing Y, right is increasing X.
SkPoint vector;
vector.fX = SkFloatToScalar(sinf(angleRadians));
vector.fY = SkFloatToScalar(-cosf(angleRadians));
matrix->mapVectors(& vector, 1);
// Derive the transformed vector's clockwise angle from vertical.
float result = atan2f(SkScalarToFloat(vector.fX), SkScalarToFloat(-vector.fY));
if (result < - M_PI_2) {
result += M_PI;
} else if (result > M_PI_2) {
result -= M_PI;
}
return result;
}
void MotionEvent::transform(const SkMatrix* matrix) {
float oldXOffset = mXOffset;
float oldYOffset = mYOffset;
// The tricky part of this implementation is to preserve the value of
// rawX and rawY. So we apply the transformation to the first point
// then derive an appropriate new X/Y offset that will preserve rawX and rawY.
SkPoint point;
float rawX = getRawX(0);
float rawY = getRawY(0);
matrix->mapXY(SkFloatToScalar(rawX + oldXOffset), SkFloatToScalar(rawY + oldYOffset),
& point);
float newX = SkScalarToFloat(point.fX);
float newY = SkScalarToFloat(point.fY);
float newXOffset = newX - rawX;
float newYOffset = newY - rawY;
mXOffset = newXOffset;
mYOffset = newYOffset;
// Apply the transformation to all samples.
size_t numSamples = mSamplePointerCoords.size();
for (size_t i = 0; i < numSamples; i++) {
PointerCoords& c = mSamplePointerCoords.editItemAt(i);
float* xPtr = c.editAxisValue(AINPUT_MOTION_AXIS_X);
float* yPtr = c.editAxisValue(AINPUT_MOTION_AXIS_Y);
if (xPtr && yPtr) {
float x = *xPtr + oldXOffset;
float y = *yPtr + oldYOffset;
matrix->mapXY(SkFloatToScalar(x), SkFloatToScalar(y), & point);
*xPtr = SkScalarToFloat(point.fX) - newXOffset;
*yPtr = SkScalarToFloat(point.fY) - newYOffset;
}
float* orientationPtr = c.editAxisValue(AINPUT_MOTION_AXIS_ORIENTATION);
if (orientationPtr) {
*orientationPtr = transformAngle(matrix, *orientationPtr);
}
}
}
status_t MotionEvent::readFromParcel(Parcel* parcel) {
size_t pointerCount = parcel->readInt32();
size_t sampleCount = parcel->readInt32();
if (pointerCount == 0 || pointerCount > MAX_POINTERS || sampleCount == 0) {
return BAD_VALUE;
}
mDeviceId = parcel->readInt32();
mSource = parcel->readInt32();
mAction = parcel->readInt32();
mFlags = parcel->readInt32();
mEdgeFlags = parcel->readInt32();
mMetaState = parcel->readInt32();
mXOffset = parcel->readFloat();
mYOffset = parcel->readFloat();
mXPrecision = parcel->readFloat();
mYPrecision = parcel->readFloat();
mDownTime = parcel->readInt64();
mPointerIds.clear();
mPointerIds.setCapacity(pointerCount);
mSampleEventTimes.clear();
mSampleEventTimes.setCapacity(sampleCount);
mSamplePointerCoords.clear();
mSamplePointerCoords.setCapacity(sampleCount * pointerCount);
for (size_t i = 0; i < pointerCount; i++) {
mPointerIds.push(parcel->readInt32());
}
while (sampleCount-- > 0) {
mSampleEventTimes.push(parcel->readInt64());
for (size_t i = 0; i < pointerCount; i++) {
mSamplePointerCoords.push();
status_t status = mSamplePointerCoords.editTop().readFromParcel(parcel);
if (!status) {
return status;
}
}
}
return OK;
}
status_t MotionEvent::writeToParcel(Parcel* parcel) const {
size_t pointerCount = mPointerIds.size();
size_t sampleCount = mSampleEventTimes.size();
parcel->writeInt32(pointerCount);
parcel->writeInt32(sampleCount);
parcel->writeInt32(mDeviceId);
parcel->writeInt32(mSource);
parcel->writeInt32(mAction);
parcel->writeInt32(mFlags);
parcel->writeInt32(mEdgeFlags);
parcel->writeInt32(mMetaState);
parcel->writeFloat(mXOffset);
parcel->writeFloat(mYOffset);
parcel->writeFloat(mXPrecision);
parcel->writeFloat(mYPrecision);
parcel->writeInt64(mDownTime);
for (size_t i = 0; i < pointerCount; i++) {
parcel->writeInt32(mPointerIds.itemAt(i));
}
const PointerCoords* pc = mSamplePointerCoords.array();
for (size_t h = 0; h < sampleCount; h++) {
parcel->writeInt64(mSampleEventTimes.itemAt(h));
for (size_t i = 0; i < pointerCount; i++) {
status_t status = (pc++)->writeToParcel(parcel);
if (!status) {
return status;
}
}
}
return OK;
}
#endif
// --- InputDeviceInfo ---
InputDeviceInfo::InputDeviceInfo() {
@@ -307,8 +592,8 @@ void InputDeviceInfo::initialize(int32_t id, const String8& name) {
mMotionRanges.clear();
}
const InputDeviceInfo::MotionRange* InputDeviceInfo::getMotionRange(int32_t rangeType) const {
ssize_t index = mMotionRanges.indexOfKey(rangeType);
const InputDeviceInfo::MotionRange* InputDeviceInfo::getMotionRange(int32_t axis) const {
ssize_t index = mMotionRanges.indexOfKey(axis);
return index >= 0 ? & mMotionRanges.valueAt(index) : NULL;
}
@@ -316,14 +601,14 @@ void InputDeviceInfo::addSource(uint32_t source) {
mSources |= source;
}
void InputDeviceInfo::addMotionRange(int32_t rangeType, float min, float max,
void InputDeviceInfo::addMotionRange(int32_t axis, float min, float max,
float flat, float fuzz) {
MotionRange range = { min, max, flat, fuzz };
addMotionRange(rangeType, range);
addMotionRange(axis, range);
}
void InputDeviceInfo::addMotionRange(int32_t rangeType, const MotionRange& range) {
mMotionRanges.add(rangeType, range);
void InputDeviceInfo::addMotionRange(int32_t axis, const MotionRange& range) {
mMotionRanges.add(axis, range);
}
} // namespace android

View File

@@ -159,15 +159,17 @@ void InputPublisherAndConsumerTest::PublishAndConsumeMotionEvent(
sampleEventTimes.push(i + 10);
for (size_t j = 0; j < pointerCount; j++) {
samplePointerCoords.push();
samplePointerCoords.editTop().x = 100 * i + j;
samplePointerCoords.editTop().y = 200 * i + j;
samplePointerCoords.editTop().pressure = 0.5 * i + j;
samplePointerCoords.editTop().size = 0.7 * i + j;
samplePointerCoords.editTop().touchMajor = 1.5 * i + j;
samplePointerCoords.editTop().touchMinor = 1.7 * i + j;
samplePointerCoords.editTop().toolMajor = 2.5 * i + j;
samplePointerCoords.editTop().toolMinor = 2.7 * i + j;
samplePointerCoords.editTop().orientation = 3.5 * i + j;
PointerCoords& pc = samplePointerCoords.editTop();
pc.clear();
pc.setAxisValue(AINPUT_MOTION_AXIS_X, 100 * i + j);
pc.setAxisValue(AINPUT_MOTION_AXIS_Y, 200 * i + j);
pc.setAxisValue(AINPUT_MOTION_AXIS_PRESSURE, 0.5 * i + j);
pc.setAxisValue(AINPUT_MOTION_AXIS_SIZE, 0.7 * i + j);
pc.setAxisValue(AINPUT_MOTION_AXIS_TOUCH_MAJOR, 1.5 * i + j);
pc.setAxisValue(AINPUT_MOTION_AXIS_TOUCH_MINOR, 1.7 * i + j);
pc.setAxisValue(AINPUT_MOTION_AXIS_TOOL_MAJOR, 2.5 * i + j);
pc.setAxisValue(AINPUT_MOTION_AXIS_TOOL_MAJOR, 2.7 * i + j);
pc.setAxisValue(AINPUT_MOTION_AXIS_ORIENTATION, 3.5 * i + j);
}
}
@@ -239,27 +241,27 @@ void InputPublisherAndConsumerTest::PublishAndConsumeMotionEvent(
for (size_t i = 0; i < pointerCount; i++) {
SCOPED_TRACE(i);
size_t offset = sampleIndex * pointerCount + i;
EXPECT_EQ(samplePointerCoords[offset].x,
EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AINPUT_MOTION_AXIS_X),
motionEvent->getHistoricalRawX(i, sampleIndex));
EXPECT_EQ(samplePointerCoords[offset].y,
EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AINPUT_MOTION_AXIS_Y),
motionEvent->getHistoricalRawY(i, sampleIndex));
EXPECT_EQ(samplePointerCoords[offset].x + xOffset,
EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AINPUT_MOTION_AXIS_X) + xOffset,
motionEvent->getHistoricalX(i, sampleIndex));
EXPECT_EQ(samplePointerCoords[offset].y + yOffset,
EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AINPUT_MOTION_AXIS_Y) + yOffset,
motionEvent->getHistoricalY(i, sampleIndex));
EXPECT_EQ(samplePointerCoords[offset].pressure,
EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AINPUT_MOTION_AXIS_PRESSURE),
motionEvent->getHistoricalPressure(i, sampleIndex));
EXPECT_EQ(samplePointerCoords[offset].size,
EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AINPUT_MOTION_AXIS_SIZE),
motionEvent->getHistoricalSize(i, sampleIndex));
EXPECT_EQ(samplePointerCoords[offset].touchMajor,
EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AINPUT_MOTION_AXIS_TOUCH_MAJOR),
motionEvent->getHistoricalTouchMajor(i, sampleIndex));
EXPECT_EQ(samplePointerCoords[offset].touchMinor,
EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AINPUT_MOTION_AXIS_TOUCH_MINOR),
motionEvent->getHistoricalTouchMinor(i, sampleIndex));
EXPECT_EQ(samplePointerCoords[offset].toolMajor,
EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AINPUT_MOTION_AXIS_TOOL_MAJOR),
motionEvent->getHistoricalToolMajor(i, sampleIndex));
EXPECT_EQ(samplePointerCoords[offset].toolMinor,
EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AINPUT_MOTION_AXIS_TOOL_MINOR),
motionEvent->getHistoricalToolMinor(i, sampleIndex));
EXPECT_EQ(samplePointerCoords[offset].orientation,
EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AINPUT_MOTION_AXIS_ORIENTATION),
motionEvent->getHistoricalOrientation(i, sampleIndex));
}
}
@@ -269,17 +271,28 @@ void InputPublisherAndConsumerTest::PublishAndConsumeMotionEvent(
for (size_t i = 0; i < pointerCount; i++) {
SCOPED_TRACE(i);
size_t offset = lastSampleIndex * pointerCount + i;
EXPECT_EQ(samplePointerCoords[offset].x, motionEvent->getRawX(i));
EXPECT_EQ(samplePointerCoords[offset].y, motionEvent->getRawY(i));
EXPECT_EQ(samplePointerCoords[offset].x + xOffset, motionEvent->getX(i));
EXPECT_EQ(samplePointerCoords[offset].y + yOffset, motionEvent->getY(i));
EXPECT_EQ(samplePointerCoords[offset].pressure, motionEvent->getPressure(i));
EXPECT_EQ(samplePointerCoords[offset].size, motionEvent->getSize(i));
EXPECT_EQ(samplePointerCoords[offset].touchMajor, motionEvent->getTouchMajor(i));
EXPECT_EQ(samplePointerCoords[offset].touchMinor, motionEvent->getTouchMinor(i));
EXPECT_EQ(samplePointerCoords[offset].toolMajor, motionEvent->getToolMajor(i));
EXPECT_EQ(samplePointerCoords[offset].toolMinor, motionEvent->getToolMinor(i));
EXPECT_EQ(samplePointerCoords[offset].orientation, motionEvent->getOrientation(i));
EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AINPUT_MOTION_AXIS_X),
motionEvent->getRawX(i));
EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AINPUT_MOTION_AXIS_Y),
motionEvent->getRawY(i));
EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AINPUT_MOTION_AXIS_X) + xOffset,
motionEvent->getX(i));
EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AINPUT_MOTION_AXIS_Y) + yOffset,
motionEvent->getY(i));
EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AINPUT_MOTION_AXIS_PRESSURE),
motionEvent->getPressure(i));
EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AINPUT_MOTION_AXIS_SIZE),
motionEvent->getSize(i));
EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AINPUT_MOTION_AXIS_TOUCH_MAJOR),
motionEvent->getTouchMajor(i));
EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AINPUT_MOTION_AXIS_TOUCH_MINOR),
motionEvent->getTouchMinor(i));
EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AINPUT_MOTION_AXIS_TOOL_MAJOR),
motionEvent->getToolMajor(i));
EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AINPUT_MOTION_AXIS_TOOL_MINOR),
motionEvent->getToolMinor(i));
EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AINPUT_MOTION_AXIS_ORIENTATION),
motionEvent->getOrientation(i));
}
status = mConsumer->sendFinishedSignal(false);
@@ -328,7 +341,8 @@ TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenNotReset_ReturnsErr
const size_t pointerCount = 1;
int32_t pointerIds[pointerCount] = { 0 };
PointerCoords pointerCoords[pointerCount] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
PointerCoords pointerCoords[pointerCount];
pointerCoords[0].clear();
status = mPublisher->publishMotionEvent(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
pointerCount, pointerIds, pointerCoords);

View File

@@ -172,6 +172,11 @@ float AMotionEvent_getOrientation(const AInputEvent* motion_event, size_t pointe
return static_cast<const MotionEvent*>(motion_event)->getOrientation(pointer_index);
}
float AMotionEvent_getAxisValue(const AInputEvent* motion_event,
int32_t axis, size_t pointer_index) {
return static_cast<const MotionEvent*>(motion_event)->getAxisValue(axis, pointer_index);
}
size_t AMotionEvent_getHistorySize(const AInputEvent* motion_event) {
return static_cast<const MotionEvent*>(motion_event)->getHistorySize();
}
@@ -248,6 +253,12 @@ float AMotionEvent_getHistoricalOrientation(AInputEvent* motion_event, size_t po
pointer_index, history_index);
}
float AMotionEvent_getHistoricalAxisValue(const AInputEvent* motion_event,
int32_t axis, size_t pointer_index, size_t history_index) {
return static_cast<const MotionEvent*>(motion_event)->getHistoricalAxisValue(
axis, pointer_index, history_index);
}
void AInputQueue_attachLooper(AInputQueue* queue, ALooper* looper,
int ident, ALooper_callbackFunc callback, void* data) {

View File

@@ -362,24 +362,41 @@ enum {
AINPUT_KEYBOARD_TYPE_ALPHABETIC = 2,
};
/*
* Constants that identify each individual axis of a motion event.
*/
enum {
AINPUT_MOTION_AXIS_X = 0,
AINPUT_MOTION_AXIS_Y = 1,
AINPUT_MOTION_AXIS_PRESSURE = 2,
AINPUT_MOTION_AXIS_SIZE = 3,
AINPUT_MOTION_AXIS_TOUCH_MAJOR = 4,
AINPUT_MOTION_AXIS_TOUCH_MINOR = 5,
AINPUT_MOTION_AXIS_TOOL_MAJOR = 6,
AINPUT_MOTION_AXIS_TOOL_MINOR = 7,
AINPUT_MOTION_AXIS_ORIENTATION = 8,
};
/*
* Constants used to retrieve information about the range of motion for a particular
* coordinate of a motion event.
*
* Refer to the documentation on android.view.InputDevice for more details about input sources
* and their correct interpretation.
*
* DEPRECATION NOTICE: These constants are deprecated. Use AINPUT_MOTION_AXIS_* constants instead.
*/
enum {
AINPUT_MOTION_RANGE_X = 0,
AINPUT_MOTION_RANGE_Y = 1,
AINPUT_MOTION_RANGE_PRESSURE = 2,
AINPUT_MOTION_RANGE_SIZE = 3,
AINPUT_MOTION_RANGE_TOUCH_MAJOR = 4,
AINPUT_MOTION_RANGE_TOUCH_MINOR = 5,
AINPUT_MOTION_RANGE_TOOL_MAJOR = 6,
AINPUT_MOTION_RANGE_TOOL_MINOR = 7,
AINPUT_MOTION_RANGE_ORIENTATION = 8,
};
AINPUT_MOTION_RANGE_X = AINPUT_MOTION_AXIS_X,
AINPUT_MOTION_RANGE_Y = AINPUT_MOTION_AXIS_Y,
AINPUT_MOTION_RANGE_PRESSURE = AINPUT_MOTION_AXIS_PRESSURE,
AINPUT_MOTION_RANGE_SIZE = AINPUT_MOTION_AXIS_SIZE,
AINPUT_MOTION_RANGE_TOUCH_MAJOR = AINPUT_MOTION_AXIS_TOUCH_MAJOR,
AINPUT_MOTION_RANGE_TOUCH_MINOR = AINPUT_MOTION_AXIS_TOUCH_MINOR,
AINPUT_MOTION_RANGE_TOOL_MAJOR = AINPUT_MOTION_AXIS_TOOL_MAJOR,
AINPUT_MOTION_RANGE_TOOL_MINOR = AINPUT_MOTION_AXIS_TOOL_MINOR,
AINPUT_MOTION_RANGE_ORIENTATION = AINPUT_MOTION_AXIS_ORIENTATION,
} __attribute__ ((deprecated));
/*
@@ -526,7 +543,7 @@ float AMotionEvent_getY(const AInputEvent* motion_event, size_t pointer_index);
/* Get the current pressure of this event for the given pointer index.
* The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
* however values higher than 1 may be generated depending on the calibration of
* although values higher than 1 may be generated depending on the calibration of
* the input device. */
float AMotionEvent_getPressure(const AInputEvent* motion_event, size_t pointer_index);
@@ -568,6 +585,10 @@ float AMotionEvent_getToolMinor(const AInputEvent* motion_event, size_t pointer_
* (finger pointing fully right). */
float AMotionEvent_getOrientation(const AInputEvent* motion_event, size_t pointer_index);
/* Get the value of the request axis for the given pointer index. */
float AMotionEvent_getAxisValue(const AInputEvent* motion_event,
int32_t axis, size_t pointer_index);
/* Get the number of historical points in this event. These are movements that
* have occurred between this event and the previous event. This only applies
* to AMOTION_EVENT_ACTION_MOVE events -- all other actions will have a size of 0.
@@ -614,7 +635,7 @@ float AMotionEvent_getHistoricalY(AInputEvent* motion_event, size_t pointer_inde
/* Get the historical pressure of this event for the given pointer index that
* occurred between this event and the previous motion event.
* The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
* however values higher than 1 may be generated depending on the calibration of
* although values higher than 1 may be generated depending on the calibration of
* the input device. */
float AMotionEvent_getHistoricalPressure(AInputEvent* motion_event, size_t pointer_index,
size_t history_index);
@@ -669,6 +690,11 @@ float AMotionEvent_getHistoricalToolMinor(const AInputEvent* motion_event, size_
float AMotionEvent_getHistoricalOrientation(const AInputEvent* motion_event, size_t pointer_index,
size_t history_index);
/* Get the historical value of the request axis for the given pointer index
* that occurred between this event and the previous motion event. */
float AMotionEvent_getHistoricalAxisValue(const AInputEvent* motion_event,
int32_t axis, size_t pointer_index, size_t history_index);
/*
* Input queue

View File

@@ -482,8 +482,10 @@ bool InputDispatcher::enqueueInboundEventLocked(EventEntry* entry) {
&& (motionEntry->source & AINPUT_SOURCE_CLASS_POINTER)
&& mInputTargetWaitCause == INPUT_TARGET_WAIT_CAUSE_APPLICATION_NOT_READY
&& mInputTargetWaitApplication != NULL) {
int32_t x = int32_t(motionEntry->firstSample.pointerCoords[0].x);
int32_t y = int32_t(motionEntry->firstSample.pointerCoords[0].y);
int32_t x = int32_t(motionEntry->firstSample.pointerCoords[0].
getAxisValue(AINPUT_MOTION_AXIS_X));
int32_t y = int32_t(motionEntry->firstSample.pointerCoords[0].
getAxisValue(AINPUT_MOTION_AXIS_Y));
const InputWindow* touchedWindow = findTouchedWindowAtLocked(x, y);
if (touchedWindow
&& touchedWindow->inputWindowHandle != NULL
@@ -888,11 +890,15 @@ void InputDispatcher::logOutboundMotionDetailsLocked(const char* prefix, const M
"touchMajor=%f, touchMinor=%f, toolMajor=%f, toolMinor=%f, "
"orientation=%f",
i, entry->pointerIds[i],
sample->pointerCoords[i].x, sample->pointerCoords[i].y,
sample->pointerCoords[i].pressure, sample->pointerCoords[i].size,
sample->pointerCoords[i].touchMajor, sample->pointerCoords[i].touchMinor,
sample->pointerCoords[i].toolMajor, sample->pointerCoords[i].toolMinor,
sample->pointerCoords[i].orientation);
sample->pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_X),
sample->pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_Y),
sample->pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_PRESSURE),
sample->pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_SIZE),
sample->pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_TOUCH_MAJOR),
sample->pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_TOUCH_MINOR),
sample->pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_TOOL_MAJOR),
sample->pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_TOOL_MINOR),
sample->pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_ORIENTATION));
}
// Keep in mind that due to batching, it is possible for the number of samples actually
@@ -1188,8 +1194,10 @@ int32_t InputDispatcher::findTouchedWindowTargetsLocked(nsecs_t currentTime,
/* Case 1: New splittable pointer going down. */
int32_t pointerIndex = getMotionEventActionPointerIndex(action);
int32_t x = int32_t(entry->firstSample.pointerCoords[pointerIndex].x);
int32_t y = int32_t(entry->firstSample.pointerCoords[pointerIndex].y);
int32_t x = int32_t(entry->firstSample.pointerCoords[pointerIndex].
getAxisValue(AINPUT_MOTION_AXIS_X));
int32_t y = int32_t(entry->firstSample.pointerCoords[pointerIndex].
getAxisValue(AINPUT_MOTION_AXIS_Y));
const InputWindow* newTouchedWindow = NULL;
const InputWindow* topErrorWindow = NULL;
@@ -2275,11 +2283,16 @@ void InputDispatcher::notifyMotion(nsecs_t eventTime, int32_t deviceId, uint32_t
LOGD(" Pointer %d: id=%d, x=%f, y=%f, pressure=%f, size=%f, "
"touchMajor=%f, touchMinor=%f, toolMajor=%f, toolMinor=%f, "
"orientation=%f",
i, pointerIds[i], pointerCoords[i].x, pointerCoords[i].y,
pointerCoords[i].pressure, pointerCoords[i].size,
pointerCoords[i].touchMajor, pointerCoords[i].touchMinor,
pointerCoords[i].toolMajor, pointerCoords[i].toolMinor,
pointerCoords[i].orientation);
i, pointerIds[i],
pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_X),
pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_Y),
pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_PRESSURE),
pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_SIZE),
pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_TOUCH_MAJOR),
pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_TOUCH_MINOR),
pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_TOOL_MAJOR),
pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_TOOL_MINOR),
pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_ORIENTATION));
}
#endif
if (! validateMotionEvent(action, pointerCount, pointerIds)) {

View File

@@ -1285,24 +1285,23 @@ void CursorInputMapper::sync(nsecs_t when) {
}
}
pointerCoords.clear();
if (mPointerController != NULL) {
mPointerController->move(deltaX, deltaY);
if (downChanged) {
mPointerController->setButtonState(mLocked.down ? POINTER_BUTTON_1 : 0);
}
mPointerController->getPosition(&pointerCoords.x, &pointerCoords.y);
float x, y;
mPointerController->getPosition(&x, &y);
pointerCoords.setAxisValue(AINPUT_MOTION_AXIS_X, x);
pointerCoords.setAxisValue(AINPUT_MOTION_AXIS_Y, y);
} else {
pointerCoords.x = deltaX;
pointerCoords.y = deltaY;
pointerCoords.setAxisValue(AINPUT_MOTION_AXIS_X, deltaX);
pointerCoords.setAxisValue(AINPUT_MOTION_AXIS_Y, deltaY);
}
pointerCoords.pressure = mLocked.down ? 1.0f : 0.0f;
pointerCoords.size = 0;
pointerCoords.touchMajor = 0;
pointerCoords.touchMinor = 0;
pointerCoords.toolMajor = 0;
pointerCoords.toolMinor = 0;
pointerCoords.orientation = 0;
pointerCoords.setAxisValue(AINPUT_MOTION_AXIS_PRESSURE, mLocked.down ? 1.0f : 0.0f);
} // release lock
int32_t metaState = mContext->getGlobalMetaState();
@@ -2686,15 +2685,16 @@ void TouchInputMapper::dispatchTouch(nsecs_t when, uint32_t policyFlags,
// Write output coords.
PointerCoords& out = pointerCoords[outIndex];
out.x = x;
out.y = y;
out.pressure = pressure;
out.size = size;
out.touchMajor = touchMajor;
out.touchMinor = touchMinor;
out.toolMajor = toolMajor;
out.toolMinor = toolMinor;
out.orientation = orientation;
out.clear();
out.setAxisValue(AINPUT_MOTION_AXIS_X, x);
out.setAxisValue(AINPUT_MOTION_AXIS_Y, y);
out.setAxisValue(AINPUT_MOTION_AXIS_PRESSURE, pressure);
out.setAxisValue(AINPUT_MOTION_AXIS_SIZE, size);
out.setAxisValue(AINPUT_MOTION_AXIS_TOUCH_MAJOR, touchMajor);
out.setAxisValue(AINPUT_MOTION_AXIS_TOUCH_MINOR, touchMinor);
out.setAxisValue(AINPUT_MOTION_AXIS_TOOL_MAJOR, toolMajor);
out.setAxisValue(AINPUT_MOTION_AXIS_TOOL_MINOR, toolMinor);
out.setAxisValue(AINPUT_MOTION_AXIS_ORIENTATION, orientation);
pointerIds[outIndex] = int32_t(id);
@@ -2706,14 +2706,17 @@ void TouchInputMapper::dispatchTouch(nsecs_t when, uint32_t policyFlags,
// Check edge flags by looking only at the first pointer since the flags are
// global to the event.
if (motionEventAction == AMOTION_EVENT_ACTION_DOWN) {
if (pointerCoords[0].x <= 0) {
float x = pointerCoords[0].getAxisValue(AINPUT_MOTION_AXIS_X);
float y = pointerCoords[0].getAxisValue(AINPUT_MOTION_AXIS_Y);
if (x <= 0) {
motionEventEdgeFlags |= AMOTION_EVENT_EDGE_FLAG_LEFT;
} else if (pointerCoords[0].x >= mLocked.orientedSurfaceWidth) {
} else if (x >= mLocked.orientedSurfaceWidth) {
motionEventEdgeFlags |= AMOTION_EVENT_EDGE_FLAG_RIGHT;
}
if (pointerCoords[0].y <= 0) {
if (y <= 0) {
motionEventEdgeFlags |= AMOTION_EVENT_EDGE_FLAG_TOP;
} else if (pointerCoords[0].y >= mLocked.orientedSurfaceHeight) {
} else if (y >= mLocked.orientedSurfaceHeight) {
motionEventEdgeFlags |= AMOTION_EVENT_EDGE_FLAG_BOTTOM;
}
}
@@ -3853,15 +3856,9 @@ void JoystickInputMapper::sync(nsecs_t when) {
if (motionAxisChanged) {
PointerCoords pointerCoords;
pointerCoords.x = mAxes.x.value;
pointerCoords.y = mAxes.y.value;
pointerCoords.touchMajor = 0;
pointerCoords.touchMinor = 0;
pointerCoords.toolMajor = 0;
pointerCoords.toolMinor = 0;
pointerCoords.pressure = 0;
pointerCoords.size = 0;
pointerCoords.orientation = 0;
pointerCoords.clear();
pointerCoords.setAxisValue(AINPUT_MOTION_AXIS_X, mAxes.x.value);
pointerCoords.setAxisValue(AINPUT_MOTION_AXIS_Y, mAxes.y.value);
int32_t pointerId = 0;
getDispatcher()->notifyMotion(when, getDeviceId(), AINPUT_SOURCE_JOYSTICK, 0,

View File

@@ -1473,15 +1473,15 @@ protected:
float x, float y, float pressure, float size,
float touchMajor, float touchMinor, float toolMajor, float toolMinor,
float orientation) {
ASSERT_NEAR(x, coords.x, 1);
ASSERT_NEAR(y, coords.y, 1);
ASSERT_NEAR(pressure, coords.pressure, EPSILON);
ASSERT_NEAR(size, coords.size, EPSILON);
ASSERT_NEAR(touchMajor, coords.touchMajor, 1);
ASSERT_NEAR(touchMinor, coords.touchMinor, 1);
ASSERT_NEAR(toolMajor, coords.toolMajor, 1);
ASSERT_NEAR(toolMinor, coords.toolMinor, 1);
ASSERT_NEAR(orientation, coords.orientation, EPSILON);
ASSERT_NEAR(x, coords.getAxisValue(AINPUT_MOTION_AXIS_X), 1);
ASSERT_NEAR(y, coords.getAxisValue(AINPUT_MOTION_AXIS_Y), 1);
ASSERT_NEAR(pressure, coords.getAxisValue(AINPUT_MOTION_AXIS_PRESSURE), EPSILON);
ASSERT_NEAR(size, coords.getAxisValue(AINPUT_MOTION_AXIS_SIZE), EPSILON);
ASSERT_NEAR(touchMajor, coords.getAxisValue(AINPUT_MOTION_AXIS_TOUCH_MAJOR), 1);
ASSERT_NEAR(touchMinor, coords.getAxisValue(AINPUT_MOTION_AXIS_TOUCH_MINOR), 1);
ASSERT_NEAR(toolMajor, coords.getAxisValue(AINPUT_MOTION_AXIS_TOOL_MAJOR), 1);
ASSERT_NEAR(toolMinor, coords.getAxisValue(AINPUT_MOTION_AXIS_TOOL_MINOR), 1);
ASSERT_NEAR(orientation, coords.getAxisValue(AINPUT_MOTION_AXIS_ORIENTATION), EPSILON);
}
};
@@ -2078,7 +2078,6 @@ TEST_F(CursorInputMapperTest, Process_ShouldHandleIndependentXYUpdates) {
process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0, 0, 0);
ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args));
ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action);
ASSERT_NEAR(0.0f, args.pointerCoords[0].x, EPSILON);
ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
0.0f, -2.0f / TRACKBALL_MOVEMENT_THRESHOLD, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
}
@@ -2893,8 +2892,8 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenNotOrientationAware_DoesNotRotate
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args));
ASSERT_NEAR(50, args.pointerCoords[0].x, 1);
ASSERT_NEAR(75, args.pointerCoords[0].y, 1);
ASSERT_NEAR(50, args.pointerCoords[0].getAxisValue(AINPUT_MOTION_AXIS_X), 1);
ASSERT_NEAR(75, args.pointerCoords[0].getAxisValue(AINPUT_MOTION_AXIS_Y), 1);
processUp(mapper);
processSync(mapper);
@@ -2915,8 +2914,8 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenOrientationAware_RotatesMotions)
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args));
ASSERT_NEAR(50, args.pointerCoords[0].x, 1);
ASSERT_NEAR(75, args.pointerCoords[0].y, 1);
ASSERT_NEAR(50, args.pointerCoords[0].getAxisValue(AINPUT_MOTION_AXIS_X), 1);
ASSERT_NEAR(75, args.pointerCoords[0].getAxisValue(AINPUT_MOTION_AXIS_Y), 1);
processUp(mapper);
processSync(mapper);
@@ -2928,8 +2927,8 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenOrientationAware_RotatesMotions)
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args));
ASSERT_NEAR(75, args.pointerCoords[0].x, 1);
ASSERT_NEAR(DISPLAY_WIDTH - 50, args.pointerCoords[0].y, 1);
ASSERT_NEAR(75, args.pointerCoords[0].getAxisValue(AINPUT_MOTION_AXIS_X), 1);
ASSERT_NEAR(DISPLAY_WIDTH - 50, args.pointerCoords[0].getAxisValue(AINPUT_MOTION_AXIS_Y), 1);
processUp(mapper);
processSync(mapper);
@@ -2941,8 +2940,8 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenOrientationAware_RotatesMotions)
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args));
ASSERT_NEAR(DISPLAY_WIDTH - 50, args.pointerCoords[0].x, 1);
ASSERT_NEAR(DISPLAY_HEIGHT - 75, args.pointerCoords[0].y, 1);
ASSERT_NEAR(DISPLAY_WIDTH - 50, args.pointerCoords[0].getAxisValue(AINPUT_MOTION_AXIS_X), 1);
ASSERT_NEAR(DISPLAY_HEIGHT - 75, args.pointerCoords[0].getAxisValue(AINPUT_MOTION_AXIS_Y), 1);
processUp(mapper);
processSync(mapper);
@@ -2954,8 +2953,8 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenOrientationAware_RotatesMotions)
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args));
ASSERT_NEAR(DISPLAY_HEIGHT - 75, args.pointerCoords[0].x, 1);
ASSERT_NEAR(50, args.pointerCoords[0].y, 1);
ASSERT_NEAR(DISPLAY_HEIGHT - 75, args.pointerCoords[0].getAxisValue(AINPUT_MOTION_AXIS_X), 1);
ASSERT_NEAR(50, args.pointerCoords[0].getAxisValue(AINPUT_MOTION_AXIS_Y), 1);
processUp(mapper);
processSync(mapper);

View File

@@ -87,7 +87,6 @@ static struct {
jfieldID mName;
jfieldID mSources;
jfieldID mKeyboardType;
jfieldID mMotionRanges;
} gInputDeviceClassInfo;
static struct {
@@ -1221,9 +1220,6 @@ int register_android_server_InputManager(JNIEnv* env) {
GET_FIELD_ID(gInputDeviceClassInfo.mKeyboardType, gInputDeviceClassInfo.clazz,
"mKeyboardType", "I");
GET_FIELD_ID(gInputDeviceClassInfo.mMotionRanges, gInputDeviceClassInfo.clazz,
"mMotionRanges", "[Landroid/view/InputDevice$MotionRange;");
// Configuration
FIND_CLASS(gConfigurationClassInfo.clazz, "android/content/res/Configuration");