Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9822d2b2 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

First stab at poly-finger support.

The MotionEvent API should be fairly solid, but there is still a lot of
work to do in the input device code.  In particular, right now we are
really stupid about watching how fingers change -- we just take whatever
the driver reports as down and dump that directly into the motion event.

The big remaning work is to assign pointer IDs so that applications have
help in determine which fingers go up and down, and adding support for
the official multi-touch driver protocol.
parent c0980488
Loading
Loading
Loading
Loading
+281 −0
Original line number Diff line number Diff line
@@ -144536,6 +144536,21 @@
<parameter name="pos" type="int">
</parameter>
</method>
<method name="getHistoricalPressure"
 return="float"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="pointer" type="int">
</parameter>
<parameter name="pos" type="int">
</parameter>
</method>
<method name="getHistoricalSize"
 return="float"
 abstract="false"
@@ -144549,6 +144564,21 @@
<parameter name="pos" type="int">
</parameter>
</method>
<method name="getHistoricalSize"
 return="float"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="pointer" type="int">
</parameter>
<parameter name="pos" type="int">
</parameter>
</method>
<method name="getHistoricalX"
 return="float"
 abstract="false"
@@ -144562,6 +144592,34 @@
<parameter name="pos" type="int">
</parameter>
</method>
<method name="getHistoricalX"
 return="float"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="pointer" type="int">
</parameter>
<parameter name="pos" type="int">
</parameter>
</method>
<method name="getHistoricalY"
 return="float"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="pos" type="int">
</parameter>
</method>
<method name="getHistoricalY"
 return="float"
 abstract="false"
@@ -144572,6 +144630,8 @@
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="pointer" type="int">
</parameter>
<parameter name="pos" type="int">
</parameter>
</method>
@@ -144597,6 +144657,28 @@
 visibility="public"
>
</method>
<method name="getPointerCount"
 return="int"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="getPressure"
 return="float"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="getPressure"
 return="float"
 abstract="false"
@@ -144607,6 +144689,8 @@
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="pointer" type="int">
</parameter>
</method>
<method name="getRawX"
 return="float"
@@ -144641,6 +144725,30 @@
 visibility="public"
>
</method>
<method name="getSize"
 return="float"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="pointer" type="int">
</parameter>
</method>
<method name="getX"
 return="float"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="getX"
 return="float"
 abstract="false"
@@ -144651,6 +144759,8 @@
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="pointer" type="int">
</parameter>
</method>
<method name="getXPrecision"
 return="float"
@@ -144674,6 +144784,19 @@
 visibility="public"
>
</method>
<method name="getY"
 return="float"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="pointer" type="int">
</parameter>
</method>
<method name="getYPrecision"
 return="float"
 abstract="false"
@@ -144736,6 +144859,43 @@
</parameter>
<parameter name="action" type="int">
</parameter>
<parameter name="pointers" type="int">
</parameter>
<parameter name="x" type="float">
</parameter>
<parameter name="y" type="float">
</parameter>
<parameter name="pressure" type="float">
</parameter>
<parameter name="size" type="float">
</parameter>
<parameter name="metaState" type="int">
</parameter>
<parameter name="xPrecision" type="float">
</parameter>
<parameter name="yPrecision" type="float">
</parameter>
<parameter name="deviceId" type="int">
</parameter>
<parameter name="edgeFlags" type="int">
</parameter>
</method>
<method name="obtain"
 return="android.view.MotionEvent"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="downTime" type="long">
</parameter>
<parameter name="eventTime" type="long">
</parameter>
<parameter name="action" type="int">
</parameter>
<parameter name="x" type="float">
</parameter>
<parameter name="y" type="float">
@@ -144860,6 +145020,17 @@
 visibility="public"
>
</field>
<field name="ACTION_MASK"
 type="int"
 transient="false"
 volatile="false"
 value="255"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="ACTION_MOVE"
 type="int"
 transient="false"
@@ -144882,6 +145053,116 @@
 visibility="public"
>
</field>
<field name="ACTION_POINTER_1_DOWN"
 type="int"
 transient="false"
 volatile="false"
 value="5"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="ACTION_POINTER_1_UP"
 type="int"
 transient="false"
 volatile="false"
 value="6"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="ACTION_POINTER_2_DOWN"
 type="int"
 transient="false"
 volatile="false"
 value="261"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="ACTION_POINTER_2_UP"
 type="int"
 transient="false"
 volatile="false"
 value="262"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="ACTION_POINTER_3_DOWN"
 type="int"
 transient="false"
 volatile="false"
 value="517"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="ACTION_POINTER_3_UP"
 type="int"
 transient="false"
 volatile="false"
 value="518"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="ACTION_POINTER_DOWN"
 type="int"
 transient="false"
 volatile="false"
 value="5"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="ACTION_POINTER_MASK"
 type="int"
 transient="false"
 volatile="false"
 value="65280"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="ACTION_POINTER_SHIFT"
 type="int"
 transient="false"
 volatile="false"
 value="8"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="ACTION_POINTER_UP"
 type="int"
 transient="false"
 volatile="false"
 value="6"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="ACTION_UP"
 type="int"
 transient="false"
+512 −175

File changed.

Preview size limit exceeded, changes collapsed.

+224 −118
Original line number Diff line number Diff line
@@ -26,6 +26,9 @@ public class InputDevice {
    /** Amount that trackball needs to move in order to generate a key event. */
    static final int TRACKBALL_MOVEMENT_THRESHOLD = 6;

    /** Maximum number of pointers we will track and report. */
    static final int MAX_POINTERS = 2;
    
    final int id;
    final int classes;
    final String name;
@@ -34,7 +37,7 @@ public class InputDevice {
    final AbsoluteInfo absPressure;
    final AbsoluteInfo absSize;
    
    long mDownTime = 0;
    long mKeyDownTime = 0;
    int mMetaKeysState = 0;
    
    final MotionState mAbs = new MotionState(0, 0);
@@ -48,13 +51,13 @@ public class InputDevice {
        float yMoveScale;
        MotionEvent currentMove = null;
        boolean changed = false;
        boolean down = false;
        boolean lastDown = false;
        long downTime = 0;
        int x = 0;
        int y = 0;
        int pressure = 1;
        int size = 0;
        boolean mLastAnyDown = false;
        long mDownTime = 0;
        final boolean[] mLastDown = new boolean[MAX_POINTERS];
        final boolean[] mDown = new boolean[MAX_POINTERS];
        final int[] mLastData = new int[MotionEvent.NUM_SAMPLE_DATA * MAX_POINTERS];
        final int[] mCurData = new int[MotionEvent.NUM_SAMPLE_DATA * MAX_POINTERS];
        final float[] mReportData = new float[MotionEvent.NUM_SAMPLE_DATA * MAX_POINTERS];
        
        MotionState(int mx, int my) {
            xPrecision = mx;
@@ -63,22 +66,46 @@ public class InputDevice {
            yMoveScale = my != 0 ? (1.0f/my) : 1.0f;
        }
        
        MotionEvent generateMotion(InputDevice device, long curTime, long curTimeNano,
                boolean isAbs, Display display, int orientation,
        MotionEvent generateAbsMotion(InputDevice device, long curTime,
                long curTimeNano, Display display, int orientation,
                int metaState) {
            float scaledX = x;
            float scaledY = y;
            float temp;
            float scaledPressure = 1.0f;
            float scaledSize = 0;
            int edgeFlags = 0;
            
            final float[] scaled = mReportData;
            final int[] cur = mCurData;
            
            boolean anyDown = false;
            int firstDownChanged = -1;
            int numPointers = 0;
            for (int i=0; i<MAX_POINTERS; i++) {
                boolean d = mDown[i];
                anyDown |= d;
                if (d != mLastDown[i] && firstDownChanged < 0) {
                    firstDownChanged = i;
                    mLastDown[i] = mDown[i];
                    d = true;
                }
                
                if (d) {
                    final int src = i * MotionEvent.NUM_SAMPLE_DATA;
                    final int dest = numPointers * MotionEvent.NUM_SAMPLE_DATA;
                    numPointers++;
                    scaled[dest + MotionEvent.SAMPLE_X] = cur[src + MotionEvent.SAMPLE_X];
                    scaled[dest + MotionEvent.SAMPLE_Y] = cur[src + MotionEvent.SAMPLE_Y];
                    scaled[dest + MotionEvent.SAMPLE_PRESSURE] = cur[src + MotionEvent.SAMPLE_PRESSURE];
                    scaled[dest + MotionEvent.SAMPLE_SIZE] = cur[src + MotionEvent.SAMPLE_SIZE];
                }
            }
            
            if (numPointers <= 0) {
                return null;
            }
            
            int action;
            if (down != lastDown) {
                if (isAbs) {
            int edgeFlags = 0;
            if (anyDown != mLastAnyDown) {
                final AbsoluteInfo absX = device.absX;
                final AbsoluteInfo absY = device.absY;
                    if (down && absX != null && absY != null) {
                if (anyDown && absX != null && absY != null) {
                    // We don't let downs start unless we are
                    // inside of the screen.  There are two reasons for
                    // this: to avoid spurious touches when holding
@@ -86,32 +113,44 @@ public class InputDevice {
                    // and to avoid reporting events if there are virtual
                    // keys on the touchscreen outside of the display
                    // area.
                        if (scaledX < absX.minValue || scaledX > absX.maxValue
                                || scaledY < absY.minValue || scaledY > absY.maxValue) {
                            if (false) Log.v("InputDevice", "Rejecting (" + scaledX + ","
                                    + scaledY + "): outside of ("
                    // Note that we are only looking at the first pointer,
                    // since what we are handling here is the first pointer
                    // going down, and this is the coordinate that will be
                    // used to dispatch the event.
                    if (cur[MotionEvent.SAMPLE_X] < absX.minValue
                            || cur[MotionEvent.SAMPLE_X] > absX.maxValue
                            || cur[MotionEvent.SAMPLE_Y] < absY.minValue
                            || cur[MotionEvent.SAMPLE_Y] > absY.maxValue) {
                        if (false) Log.v("InputDevice", "Rejecting ("
                                + cur[MotionEvent.SAMPLE_X] + ","
                                + cur[MotionEvent.SAMPLE_Y] + "): outside of ("
                                + absX.minValue + "," + absY.minValue
                                + ")-(" + absX.maxValue + ","
                                + absY.maxValue + ")");
                        return null;
                    }
                }
                } else {
                    x = y = 0;
                }
                lastDown = down;
                if (down) {
                mLastAnyDown = anyDown;
                if (anyDown) {
                    action = MotionEvent.ACTION_DOWN;
                    downTime = curTime;
                    mDownTime = curTime;
                } else {
                    action = MotionEvent.ACTION_UP;
                }
                currentMove = null;
            } else if (firstDownChanged >= 0) {
                if (mDown[firstDownChanged]) {
                    action = MotionEvent.ACTION_POINTER_DOWN
                            | (firstDownChanged << MotionEvent.ACTION_POINTER_SHIFT);
                } else {
                    action = MotionEvent.ACTION_POINTER_UP
                            | (firstDownChanged << MotionEvent.ACTION_POINTER_SHIFT);
                }
                currentMove = null;
            } else {
                action = MotionEvent.ACTION_MOVE;
            }
            
            if (isAbs) {
            final int dispW = display.getWidth()-1;
            final int dispH = display.getHeight()-1;
            int w = dispW;
@@ -122,89 +161,156 @@ public class InputDevice {
                w = h;
                h = tmp;
            }
                if (device.absX != null) {
                    scaledX = ((scaledX-device.absX.minValue)
                                / device.absX.range) * w;
            
            final AbsoluteInfo absX = device.absX;
            final AbsoluteInfo absY = device.absY;
            final AbsoluteInfo absPressure = device.absPressure;
            final AbsoluteInfo absSize = device.absSize;
            for (int i=0; i<numPointers; i++) {
                final int j = i * MotionEvent.NUM_SAMPLE_DATA;
            
                if (absX != null) {
                    scaled[j + MotionEvent.SAMPLE_X] =
                            ((scaled[j + MotionEvent.SAMPLE_X]-absX.minValue)
                                / absX.range) * w;
                }
                if (device.absY != null) {
                    scaledY = ((scaledY-device.absY.minValue)
                                / device.absY.range) * h;
                if (absY != null) {
                    scaled[j + MotionEvent.SAMPLE_Y] =
                            ((scaled[j + MotionEvent.SAMPLE_Y]-absY.minValue)
                                / absY.range) * h;
                }
                if (device.absPressure != null) {
                    scaledPressure = 
                        ((pressure-device.absPressure.minValue)
                                / (float)device.absPressure.range);
                if (absPressure != null) {
                    scaled[j + MotionEvent.SAMPLE_PRESSURE] = 
                            ((scaled[j + MotionEvent.SAMPLE_PRESSURE]-absPressure.minValue)
                                / (float)absPressure.range);
                }
                if (device.absSize != null) {
                    scaledSize = 
                        ((size-device.absSize.minValue)
                                / (float)device.absSize.range);
                if (absSize != null) {
                    scaled[j + MotionEvent.SAMPLE_SIZE] = 
                            ((scaled[j + MotionEvent.SAMPLE_SIZE]-absSize.minValue)
                                / (float)absSize.range);
                }
                
                switch (orientation) {
                    case Surface.ROTATION_90:
                        temp = scaledX;
                        scaledX = scaledY;
                        scaledY = w-temp;
                    case Surface.ROTATION_90: {
                        final float temp = scaled[MotionEvent.SAMPLE_X];
                        scaled[j + MotionEvent.SAMPLE_X] = scaled[j + MotionEvent.SAMPLE_Y];
                        scaled[j + MotionEvent.SAMPLE_Y] = w-temp;
                        break;
                    case Surface.ROTATION_180:
                        scaledX = w-scaledX;
                        scaledY = h-scaledY;
                    }
                    case Surface.ROTATION_180: {
                        scaled[j + MotionEvent.SAMPLE_X] = w-scaled[j + MotionEvent.SAMPLE_X];
                        scaled[j + MotionEvent.SAMPLE_Y] = h-scaled[j + MotionEvent.SAMPLE_Y];
                        break;
                    case Surface.ROTATION_270:
                        temp = scaledX;
                        scaledX = h-scaledY;
                        scaledY = temp;
                    }
                    case Surface.ROTATION_270: {
                        final float temp = scaled[i + MotionEvent.SAMPLE_X];
                        scaled[j + MotionEvent.SAMPLE_X] = h-scaled[j + MotionEvent.SAMPLE_Y];
                        scaled[j + MotionEvent.SAMPLE_Y] = temp;
                        break;
                    }
                }
            }
            
            // We only consider the first pointer when computing the edge
            // flags, since they are global to the event.
            if (action != MotionEvent.ACTION_DOWN) {
                    if (scaledX <= 0) {
                        edgeFlags += MotionEvent.EDGE_LEFT;
                    } else if (scaledX >= dispW) {
                        edgeFlags += MotionEvent.EDGE_RIGHT;
                if (scaled[MotionEvent.SAMPLE_X] <= 0) {
                    edgeFlags |= MotionEvent.EDGE_LEFT;
                } else if (scaled[MotionEvent.SAMPLE_X] >= dispW) {
                    edgeFlags |= MotionEvent.EDGE_RIGHT;
                }
                    if (scaledY <= 0) {
                        edgeFlags += MotionEvent.EDGE_TOP;
                    } else if (scaledY >= dispH) {
                        edgeFlags += MotionEvent.EDGE_BOTTOM;
                if (scaled[MotionEvent.SAMPLE_Y] <= 0) {
                    edgeFlags |= MotionEvent.EDGE_TOP;
                } else if (scaled[MotionEvent.SAMPLE_Y] >= dispH) {
                    edgeFlags |= MotionEvent.EDGE_BOTTOM;
                }
            }
            
            if (currentMove != null) {
                if (false) Log.i("InputDevice", "Adding batch x="
                        + scaled[MotionEvent.SAMPLE_X]
                        + " y=" + scaled[MotionEvent.SAMPLE_Y]
                        + " to " + currentMove);
                currentMove.addBatch(curTime, scaled, metaState);
                if (WindowManagerPolicy.WATCH_POINTER) {
                    Log.i("KeyInputQueue", "Updating: " + currentMove);
                }
                return null;
            }
            
            MotionEvent me = MotionEvent.obtainNano(mDownTime, curTime,
                    curTimeNano, action, numPointers, scaled, metaState,
                    xPrecision, yPrecision, device.id, edgeFlags);
            if (action == MotionEvent.ACTION_MOVE) {
                currentMove = me;
            }
            return me;
        }
        
        MotionEvent generateRelMotion(InputDevice device, long curTime,
                long curTimeNano, int orientation, int metaState) {
            
            final float[] scaled = mReportData;
            
            // For now we only support 1 pointer with relative motions.
            scaled[MotionEvent.SAMPLE_X] = mCurData[MotionEvent.SAMPLE_X];
            scaled[MotionEvent.SAMPLE_Y] = mCurData[MotionEvent.SAMPLE_Y];
            scaled[MotionEvent.SAMPLE_PRESSURE] = 1.0f;
            scaled[MotionEvent.SAMPLE_SIZE] = 0;
            int edgeFlags = 0;
            
            int action;
            if (mDown[0] != mLastDown[0]) {
                mCurData[MotionEvent.SAMPLE_X] =
                        mCurData[MotionEvent.SAMPLE_Y] = 0;
                mLastDown[0] = mDown[0];
                if (mDown[0]) {
                    action = MotionEvent.ACTION_DOWN;
                    mDownTime = curTime;
                } else {
                    action = MotionEvent.ACTION_UP;
                }
                currentMove = null;
            } else {
                scaledX *= xMoveScale;
                scaledY *= yMoveScale;
                action = MotionEvent.ACTION_MOVE;
            }
            
            scaled[MotionEvent.SAMPLE_X] *= xMoveScale;
            scaled[MotionEvent.SAMPLE_Y] *= yMoveScale;
            switch (orientation) {
                    case Surface.ROTATION_90:
                        temp = scaledX;
                        scaledX = scaledY;
                        scaledY = -temp;
                case Surface.ROTATION_90: {
                    final float temp = scaled[MotionEvent.SAMPLE_X];
                    scaled[MotionEvent.SAMPLE_X] = scaled[MotionEvent.SAMPLE_Y];
                    scaled[MotionEvent.SAMPLE_Y] = -temp;
                    break;
                    case Surface.ROTATION_180:
                        scaledX = -scaledX;
                        scaledY = -scaledY;
                }
                case Surface.ROTATION_180: {
                    scaled[MotionEvent.SAMPLE_X] = -scaled[MotionEvent.SAMPLE_X];
                    scaled[MotionEvent.SAMPLE_Y] = -scaled[MotionEvent.SAMPLE_Y];
                    break;
                    case Surface.ROTATION_270:
                        temp = scaledX;
                        scaledX = -scaledY;
                        scaledY = temp;
                }
                case Surface.ROTATION_270: {
                    final float temp = scaled[MotionEvent.SAMPLE_X];
                    scaled[MotionEvent.SAMPLE_X] = -scaled[MotionEvent.SAMPLE_Y];
                    scaled[MotionEvent.SAMPLE_Y] = temp;
                    break;
                }
            }
            
            if (currentMove != null) {
                if (false) Log.i("InputDevice", "Adding batch x=" + scaledX
                        + " y=" + scaledY + " to " + currentMove);
                currentMove.addBatch(curTime, scaledX, scaledY,
                        scaledPressure, scaledSize, metaState);
                if (false) Log.i("InputDevice", "Adding batch x="
                        + scaled[MotionEvent.SAMPLE_X]
                        + " y=" + scaled[MotionEvent.SAMPLE_Y]
                        + " to " + currentMove);
                currentMove.addBatch(curTime, scaled, metaState);
                if (WindowManagerPolicy.WATCH_POINTER) {
                    Log.i("KeyInputQueue", "Updating: " + currentMove);
                }
                return null;
            }
            
            MotionEvent me = MotionEvent.obtainNano(downTime, curTime,
                    curTimeNano, action, scaledX, scaledY,
                    scaledPressure, scaledSize, metaState,
            MotionEvent me = MotionEvent.obtainNano(mDownTime, curTime,
                    curTimeNano, action, 1, scaled, metaState,
                    xPrecision, yPrecision, device.id, edgeFlags);
            if (action == MotionEvent.ACTION_MOVE) {
                currentMove = me;
+71 −36

File changed.

Preview size limit exceeded, changes collapsed.