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

Commit f85dddfd authored by Vishnu Nair's avatar Vishnu Nair Committed by Android (Google) Code Review
Browse files

Merge "Pip: Use raw input coordiates when calculating pip movement offsets"

parents 9c558594 1899955c
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -48962,7 +48962,9 @@ package android.view {
    method public float getPressure();
    method public float getPressure(int);
    method public float getRawX();
    method public float getRawX(int);
    method public float getRawY();
    method public float getRawY(int);
    method public float getSize();
    method public float getSize(int);
    method public int getSource();
+32 −0
Original line number Diff line number Diff line
@@ -2587,6 +2587,38 @@ public final class MotionEvent extends InputEvent implements Parcelable {
        return nativeGetRawAxisValue(mNativePtr, AXIS_Y, 0, HISTORY_CURRENT);
    }

    /**
     * Returns the original raw X coordinate of this event.  For touch
     * events on the screen, this is the original location of the event
     * on the screen, before it had been adjusted for the containing window
     * and views.
     *
     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
     * (the first pointer that is down) to {@link #getPointerCount()}-1.
     *
     * @see #getX(int)
     * @see #AXIS_X
     */
    public float getRawX(int pointerIndex) {
        return nativeGetRawAxisValue(mNativePtr, AXIS_X, pointerIndex, HISTORY_CURRENT);
    }

    /**
     * Returns the original raw Y coordinate of this event.  For touch
     * events on the screen, this is the original location of the event
     * on the screen, before it had been adjusted for the containing window
     * and views.
     *
     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
     * (the first pointer that is down) to {@link #getPointerCount()}-1.
     *
     * @see #getY(int)
     * @see #AXIS_Y
     */
    public float getRawY(int pointerIndex) {
        return nativeGetRawAxisValue(mNativePtr, AXIS_Y, pointerIndex, HISTORY_CURRENT);
    }

    /**
     * Return the precision of the X coordinates being reported.  You can
     * multiply this number with {@link #getX} to find the actual hardware
+20 −9
Original line number Diff line number Diff line
@@ -84,7 +84,7 @@ public class PipTouchState {
     * Processes a given touch event and updates the state.
     */
    public void onTouchEvent(MotionEvent ev) {
        switch (ev.getAction()) {
        switch (ev.getActionMasked()) {
            case MotionEvent.ACTION_DOWN: {
                if (!mAllowTouches) {
                    return;
@@ -92,12 +92,13 @@ public class PipTouchState {

                // Initialize the velocity tracker
                initOrResetVelocityTracker();
                addMovement(ev);

                mActivePointerId = ev.getPointerId(0);
                if (DEBUG) {
                    Log.e(TAG, "Setting active pointer id on DOWN: " + mActivePointerId);
                }
                mLastTouch.set(ev.getX(), ev.getY());
                mLastTouch.set(ev.getRawX(), ev.getRawY());
                mDownTouch.set(mLastTouch);
                mAllowDraggingOffscreen = true;
                mIsUserInteracting = true;
@@ -118,15 +119,15 @@ public class PipTouchState {
                }

                // Update the velocity tracker
                mVelocityTracker.addMovement(ev);
                addMovement(ev);
                int pointerIndex = ev.findPointerIndex(mActivePointerId);
                if (pointerIndex == -1) {
                    Log.e(TAG, "Invalid active pointer id on MOVE: " + mActivePointerId);
                    break;
                }

                float x = ev.getX(pointerIndex);
                float y = ev.getY(pointerIndex);
                float x = ev.getRawX(pointerIndex);
                float y = ev.getRawY(pointerIndex);
                mLastDelta.set(x - mLastTouch.x, y - mLastTouch.y);
                mDownDelta.set(x - mDownTouch.x, y - mDownTouch.y);

@@ -149,7 +150,7 @@ public class PipTouchState {
                }

                // Update the velocity tracker
                mVelocityTracker.addMovement(ev);
                addMovement(ev);

                int pointerIndex = ev.getActionIndex();
                int pointerId = ev.getPointerId(pointerIndex);
@@ -161,7 +162,7 @@ public class PipTouchState {
                        Log.e(TAG, "Relinquish active pointer id on POINTER_UP: " +
                                mActivePointerId);
                    }
                    mLastTouch.set(ev.getX(newPointerIndex), ev.getY(newPointerIndex));
                    mLastTouch.set(ev.getRawX(newPointerIndex), ev.getRawY(newPointerIndex));
                }
                break;
            }
@@ -172,7 +173,7 @@ public class PipTouchState {
                }

                // Update the velocity tracker
                mVelocityTracker.addMovement(ev);
                addMovement(ev);
                mVelocityTracker.computeCurrentVelocity(1000,
                        mViewConfig.getScaledMaximumFlingVelocity());
                mVelocity.set(mVelocityTracker.getXVelocity(), mVelocityTracker.getYVelocity());
@@ -184,7 +185,7 @@ public class PipTouchState {
                }

                mUpTouchTime = ev.getEventTime();
                mLastTouch.set(ev.getX(pointerIndex), ev.getY(pointerIndex));
                mLastTouch.set(ev.getRawX(pointerIndex), ev.getRawY(pointerIndex));
                mPreviouslyDragging = mIsDragging;
                mIsWaitingForDoubleTap = !mIsDoubleTap && !mIsDragging &&
                        (mUpTouchTime - mDownTouchTime) < DOUBLE_TAP_TIMEOUT;
@@ -331,6 +332,16 @@ public class PipTouchState {
        }
    }

    private void addMovement(MotionEvent event) {
        // Add movement to velocity tracker using raw screen X and Y coordinates instead
        // of window coordinates because the window frame may be moving at the same time.
        float deltaX = event.getRawX() - event.getX();
        float deltaY = event.getRawY() - event.getY();
        event.offsetLocation(deltaX, deltaY);
        mVelocityTracker.addMovement(event);
        event.offsetLocation(-deltaX, -deltaY);
    }

    public void dump(PrintWriter pw, String prefix) {
        final String innerPrefix = prefix + "  ";
        pw.println(prefix + TAG);