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

Commit 6fb3b9eb authored by Alan Viverette's avatar Alan Viverette
Browse files

Add motion event forwarding hidden APIs to View

Change-Id: Ia7ab5496f8064c96b34912b5f5e9af6fd0978b34
parent bd6a6e60
Loading
Loading
Loading
Loading
+84 −0
Original line number Diff line number Diff line
@@ -15425,6 +15425,90 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        return parent;
    }
    /**
     * Transforms a motion event from view-local coordinates to on-screen
     * coordinates.
     *
     * @param ev the view-local motion event
     * @return false if the transformation could not be applied
     * @hide
     */
    public boolean toGlobalMotionEvent(MotionEvent ev) {
        final AttachInfo info = mAttachInfo;
        if (info == null) {
            return false;
        }
        transformMotionEventToGlobal(ev);
        ev.offsetLocation(info.mWindowLeft, info.mWindowTop);
        return true;
    }
    /**
     * Transforms a motion event from on-screen coordinates to view-local
     * coordinates.
     *
     * @param ev the on-screen motion event
     * @return false if the transformation could not be applied
     * @hide
     */
    public boolean toLocalMotionEvent(MotionEvent ev) {
        final AttachInfo info = mAttachInfo;
        if (info == null) {
            return false;
        }
        ev.offsetLocation(-info.mWindowLeft, -info.mWindowTop);
        transformMotionEventToLocal(ev);
        return true;
    }
    /**
     * Recursive helper method that applies transformations in post-order.
     *
     * @param ev the on-screen motion event
     */
    private void transformMotionEventToLocal(MotionEvent ev) {
        final ViewParent parent = mParent;
        if (parent instanceof View) {
            final View vp = (View) parent;
            vp.transformMotionEventToLocal(ev);
            ev.offsetLocation(vp.mScrollX, vp.mScrollY);
        } else if (parent instanceof ViewRootImpl) {
            final ViewRootImpl vr = (ViewRootImpl) parent;
            ev.offsetLocation(0, vr.mCurScrollY);
        }
        ev.offsetLocation(-mLeft, -mTop);
        if (!hasIdentityMatrix()) {
            ev.transform(getInverseMatrix());
        }
    }
    /**
     * Recursive helper method that applies transformations in pre-order.
     *
     * @param ev the on-screen motion event
     */
    private void transformMotionEventToGlobal(MotionEvent ev) {
        if (!hasIdentityMatrix()) {
            ev.transform(getMatrix());
        }
        ev.offsetLocation(mLeft, mTop);
        final ViewParent parent = mParent;
        if (parent instanceof View) {
            final View vp = (View) parent;
            ev.offsetLocation(-vp.mScrollX, -vp.mScrollY);
            vp.transformMotionEventToGlobal(ev);
        } else if (parent instanceof ViewRootImpl) {
            final ViewRootImpl vr = (ViewRootImpl) parent;
            ev.offsetLocation(0, -vr.mCurScrollY);
        }
    }
    /**
     * <p>Computes the coordinates of this view on the screen. The argument
     * must be an array of two integers. After the method returns, the array