diff options
-rw-r--r-- | api/current.xml | 58 | ||||
-rw-r--r-- | common/java/com/android/common/ui/PointerLocationView.java | 22 | ||||
-rw-r--r-- | core/java/android/view/GestureDetector.java | 8 | ||||
-rw-r--r-- | core/java/android/view/MotionEvent.java | 100 | ||||
-rw-r--r-- | services/java/com/android/server/InputDevice.java | 4 |
5 files changed, 143 insertions, 49 deletions
diff --git a/api/current.xml b/api/current.xml index be14731..9cdd2f0 100644 --- a/api/current.xml +++ b/api/current.xml @@ -168648,6 +168648,28 @@ visibility="public" > </method> +<method name="getActionIndex" + return="int" + abstract="false" + native="false" + synchronized="false" + static="false" + final="true" + deprecated="not deprecated" + visibility="public" +> +</method> +<method name="getActionMasked" + return="int" + abstract="false" + native="false" + synchronized="false" + static="false" + final="true" + deprecated="not deprecated" + visibility="public" +> +</method> <method name="getDeviceId" return="int" abstract="false" @@ -169268,7 +169290,7 @@ value="5" static="true" final="true" - deprecated="not deprecated" + deprecated="deprecated" visibility="public" > </field> @@ -169279,7 +169301,7 @@ value="6" static="true" final="true" - deprecated="not deprecated" + deprecated="deprecated" visibility="public" > </field> @@ -169290,7 +169312,7 @@ value="261" static="true" final="true" - deprecated="not deprecated" + deprecated="deprecated" visibility="public" > </field> @@ -169301,7 +169323,7 @@ value="262" static="true" final="true" - deprecated="not deprecated" + deprecated="deprecated" visibility="public" > </field> @@ -169312,7 +169334,7 @@ value="517" static="true" final="true" - deprecated="not deprecated" + deprecated="deprecated" visibility="public" > </field> @@ -169323,7 +169345,7 @@ value="518" static="true" final="true" - deprecated="not deprecated" + deprecated="deprecated" visibility="public" > </field> @@ -169345,7 +169367,7 @@ value="65280" static="true" final="true" - deprecated="not deprecated" + deprecated="deprecated" visibility="public" > </field> @@ -169356,6 +169378,28 @@ value="8" static="true" final="true" + deprecated="deprecated" + visibility="public" +> +</field> +<field name="ACTION_POINTER_INDEX_MASK" + type="int" + transient="false" + volatile="false" + value="65280" + static="true" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> +<field name="ACTION_POINTER_INDEX_SHIFT" + type="int" + transient="false" + volatile="false" + value="8" + static="true" + final="true" deprecated="not deprecated" visibility="public" > diff --git a/common/java/com/android/common/ui/PointerLocationView.java b/common/java/com/android/common/ui/PointerLocationView.java index e83c5ae..7bdb0bc 100644 --- a/common/java/com/android/common/ui/PointerLocationView.java +++ b/common/java/com/android/common/ui/PointerLocationView.java @@ -234,8 +234,9 @@ public class PointerLocationView extends View { } if ((action&MotionEvent.ACTION_MASK) == MotionEvent.ACTION_POINTER_DOWN) { - final int id = (action&MotionEvent.ACTION_POINTER_ID_MASK) - >> MotionEvent.ACTION_POINTER_ID_SHIFT; + final int index = (action&MotionEvent.ACTION_POINTER_INDEX_MASK) + >> MotionEvent.ACTION_POINTER_INDEX_SHIFT; + final int id = event.getPointerId(index); while (NP <= id) { PointerState ps = new PointerState(); ps.mVelocity = VelocityTracker.obtain(); @@ -260,13 +261,14 @@ public class PointerLocationView extends View { } for (int i=0; i<NI; i++) { - final PointerState ps = mPointers.get(event.getPointerId(i)); + final int id = event.getPointerId(i); + final PointerState ps = mPointers.get(id); ps.mVelocity.addMovement(event); ps.mVelocity.computeCurrentVelocity(1); final int N = event.getHistorySize(); for (int j=0; j<N; j++) { if (mPrintCoords) { - Log.i("Pointer", "Pointer " + (i+1) + ": (" + Log.i("Pointer", "Pointer " + (id+1) + ": (" + event.getHistoricalX(i, j) + ", " + event.getHistoricalY(i, j) + ")" + " Prs=" + event.getHistoricalPressure(i, j) @@ -276,7 +278,7 @@ public class PointerLocationView extends View { ps.mYs.add(event.getHistoricalY(i, j)); } if (mPrintCoords) { - Log.i("Pointer", "Pointer " + (i+1) + ": (" + Log.i("Pointer", "Pointer " + (id+1) + ": (" + event.getX(i) + ", " + event.getY(i) + ")" + " Prs=" + event.getPressure(i) + " Size=" + event.getSize(i)); @@ -293,8 +295,9 @@ public class PointerLocationView extends View { } if ((action&MotionEvent.ACTION_MASK) == MotionEvent.ACTION_POINTER_UP) { - final int id = (action&MotionEvent.ACTION_POINTER_ID_MASK) - >> MotionEvent.ACTION_POINTER_ID_SHIFT; + final int index = (action&MotionEvent.ACTION_POINTER_INDEX_MASK) + >> MotionEvent.ACTION_POINTER_INDEX_SHIFT; + final int id = event.getPointerId(index); final PointerState ps = mPointers.get(id); ps.mXs.add(Float.NaN); ps.mYs.add(Float.NaN); @@ -306,11 +309,12 @@ public class PointerLocationView extends View { if (action == MotionEvent.ACTION_UP) { for (int i=0; i<NI; i++) { - final PointerState ps = mPointers.get(event.getPointerId(i)); + final int id = event.getPointerId(i); + final PointerState ps = mPointers.get(id); if (ps.mCurDown) { ps.mCurDown = false; if (mPrintCoords) { - Log.i("Pointer", "Pointer " + (i+1) + ": UP"); + Log.i("Pointer", "Pointer " + (id+1) + ": UP"); } } } diff --git a/core/java/android/view/GestureDetector.java b/core/java/android/view/GestureDetector.java index 3c79200..58f998e 100644 --- a/core/java/android/view/GestureDetector.java +++ b/core/java/android/view/GestureDetector.java @@ -465,10 +465,10 @@ public class GestureDetector { case MotionEvent.ACTION_POINTER_UP: // Ending a multitouch gesture and going back to 1 finger if (mIgnoreMultitouch && ev.getPointerCount() == 2) { - int id = (((action & MotionEvent.ACTION_POINTER_ID_MASK) - >> MotionEvent.ACTION_POINTER_ID_SHIFT) == 0) ? 1 : 0; - mLastMotionX = ev.getX(id); - mLastMotionY = ev.getY(id); + int index = (((action & MotionEvent.ACTION_POINTER_INDEX_MASK) + >> MotionEvent.ACTION_POINTER_INDEX_SHIFT) == 0) ? 1 : 0; + mLastMotionX = ev.getX(index); + mLastMotionY = ev.getY(index); mVelocityTracker.recycle(); mVelocityTracker = VelocityTracker.obtain(); } diff --git a/core/java/android/view/MotionEvent.java b/core/java/android/view/MotionEvent.java index ca907af..d648e96 100644 --- a/core/java/android/view/MotionEvent.java +++ b/core/java/android/view/MotionEvent.java @@ -76,61 +76,81 @@ public final class MotionEvent implements Parcelable { public static final int ACTION_POINTER_DOWN = 5; /** - * Synonym for {@link #ACTION_POINTER_DOWN} with - * {@link #ACTION_POINTER_ID_MASK} of 0: the primary pointer has gone done. + * A non-primary pointer has gone up. The bits in + * {@link #ACTION_POINTER_ID_MASK} indicate which pointer changed. */ - public static final int ACTION_POINTER_1_DOWN = ACTION_POINTER_DOWN | 0x0000; + public static final int ACTION_POINTER_UP = 6; /** - * Synonym for {@link #ACTION_POINTER_DOWN} with - * {@link #ACTION_POINTER_ID_MASK} of 1: the secondary pointer has gone done. + * Bits in the action code that represent a pointer index, used with + * {@link #ACTION_POINTER_DOWN} and {@link #ACTION_POINTER_UP}. Shifting + * down by {@link #ACTION_POINTER_INDEX_SHIFT} provides the actual pointer + * index where the data for the pointer going up or down can be found; you can + * get its identifier with {@link #getPointerId(int)} and the actual + * data with {@link #getX(int)} etc. */ - public static final int ACTION_POINTER_2_DOWN = ACTION_POINTER_DOWN | 0x0100; + public static final int ACTION_POINTER_INDEX_MASK = 0xff00; /** - * Synonym for {@link #ACTION_POINTER_DOWN} with - * {@link #ACTION_POINTER_ID_MASK} of 2: the tertiary pointer has gone done. + * Bit shift for the action bits holding the pointer index as + * defined by {@link #ACTION_POINTER_INDEX_MASK}. */ - public static final int ACTION_POINTER_3_DOWN = ACTION_POINTER_DOWN | 0x0200; + public static final int ACTION_POINTER_INDEX_SHIFT = 8; /** - * A non-primary pointer has gone up. The bits in - * {@link #ACTION_POINTER_ID_MASK} indicate which pointer changed. + * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the + * data index associated with {@link #ACTION_POINTER_DOWN}. */ - public static final int ACTION_POINTER_UP = 6; + @Deprecated + public static final int ACTION_POINTER_1_DOWN = ACTION_POINTER_DOWN | 0x0000; + + /** + * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the + * data index associated with {@link #ACTION_POINTER_DOWN}. + */ + @Deprecated + public static final int ACTION_POINTER_2_DOWN = ACTION_POINTER_DOWN | 0x0100; /** - * Synonym for {@link #ACTION_POINTER_UP} with - * {@link #ACTION_POINTER_ID_MASK} of 0: the primary pointer has gone up. + * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the + * data index associated with {@link #ACTION_POINTER_DOWN}. */ + @Deprecated + public static final int ACTION_POINTER_3_DOWN = ACTION_POINTER_DOWN | 0x0200; + + /** + * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the + * data index associated with {@link #ACTION_POINTER_UP}. + */ + @Deprecated public static final int ACTION_POINTER_1_UP = ACTION_POINTER_UP | 0x0000; /** - * Synonym for {@link #ACTION_POINTER_UP} with - * {@link #ACTION_POINTER_ID_MASK} of 1: the secondary pointer has gone up. + * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the + * data index associated with {@link #ACTION_POINTER_UP}. */ + @Deprecated public static final int ACTION_POINTER_2_UP = ACTION_POINTER_UP | 0x0100; /** - * Synonym for {@link #ACTION_POINTER_UP} with - * {@link #ACTION_POINTER_ID_MASK} of 2: the tertiary pointer has gone up. + * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the + * data index associated with {@link #ACTION_POINTER_UP}. */ + @Deprecated public static final int ACTION_POINTER_3_UP = ACTION_POINTER_UP | 0x0200; /** - * Bits in the action code that represent a pointer ID, used with - * {@link #ACTION_POINTER_DOWN} and {@link #ACTION_POINTER_UP}. Pointer IDs - * start at 0, with 0 being the primary (first) pointer in the motion. Note - * that this not <em>not</em> an index into the array of pointer values, - * which is compacted to only contain pointers that are down; the pointer - * ID for a particular index can be found with {@link #findPointerIndex}. + * @deprecated Renamed to {@link #ACTION_POINTER_INDEX_MASK} to match + * the actual data contained in these bits. */ + @Deprecated public static final int ACTION_POINTER_ID_MASK = 0xff00; /** - * Bit shift for the action bits holding the pointer identifier as - * defined by {@link #ACTION_POINTER_ID_MASK}. + * @deprecated Renamed to {@link #ACTION_POINTER_INDEX_SHIFT} to match + * the actual data contained in these bits. */ + @Deprecated public static final int ACTION_POINTER_ID_SHIFT = 8; private static final boolean TRACK_RECYCLED_LOCATION = false; @@ -618,13 +638,39 @@ public final class MotionEvent implements Parcelable { /** * Return the kind of action being performed -- one of either * {@link #ACTION_DOWN}, {@link #ACTION_MOVE}, {@link #ACTION_UP}, or - * {@link #ACTION_CANCEL}. + * {@link #ACTION_CANCEL}. Consider using {@link #getActionMasked} + * and {@link #getActionIndex} to retrieve the separate masked action + * and pointer index. */ public final int getAction() { return mAction; } /** + * Return the masked action being performed, without pointer index + * information. May be any of the actions: {@link #ACTION_DOWN}, + * {@link #ACTION_MOVE}, {@link #ACTION_UP}, {@link #ACTION_CANCEL}, + * {@link #ACTION_POINTER_DOWN}, or {@link #ACTION_POINTER_UP}. + * Use {@link #getActionIndex} to return the index associated with + * pointer actions. + */ + public final int getActionMasked() { + return mAction & ACTION_MASK; + } + + /** + * For {@link #ACTION_POINTER_DOWN} or {@link #ACTION_POINTER_UP} + * as returned by {@link #getActionMasked}, this returns the associated + * pointer index. The index may be used with {@link #getPointerId(int)}, + * {@link #getX(int)}, {@link #getY(int)}, {@link #getPressure(int)}, + * and {@link #getSize(int)} to get information about the pointer that has + * gone down or up. + */ + public final int getActionIndex() { + return (mAction & ACTION_POINTER_INDEX_MASK) >> ACTION_POINTER_INDEX_SHIFT; + } + + /** * Returns the time (in ms) when the user originally pressed down to start * a stream of position events. */ diff --git a/services/java/com/android/server/InputDevice.java b/services/java/com/android/server/InputDevice.java index 6f207e0..d3bb6dc 100644 --- a/services/java/com/android/server/InputDevice.java +++ b/services/java/com/android/server/InputDevice.java @@ -570,14 +570,14 @@ public class InputDevice { mDownTime = curTime; } else { action = MotionEvent.ACTION_POINTER_DOWN - | (upOrDownPointer << MotionEvent.ACTION_POINTER_ID_SHIFT); + | (upOrDownPointer << MotionEvent.ACTION_POINTER_INDEX_SHIFT); } } else { if (numPointers == 1) { action = MotionEvent.ACTION_UP; } else { action = MotionEvent.ACTION_POINTER_UP - | (upOrDownPointer << MotionEvent.ACTION_POINTER_ID_SHIFT); + | (upOrDownPointer << MotionEvent.ACTION_POINTER_INDEX_SHIFT); } } currentMove = null; |