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

Commit abb8f6cc authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

Pointer Icon Refactor: Simplify tracking resolved pointer icon

There isn't a big benefit of tracking the pointer icon type and custom
icon individually in ViewRootImpl. It only adds complexity that is
already encapsulated in the PointerIcon class.

So we simplify the tracking logic by using a single mResolvedPointerIcon
member to track the resolved icon.

Bug: 293587049
Test: manual
Change-Id: I86e4929c01ed1322e8254c98bbf47949e8bc02ab
parent b4e04acd
Loading
Loading
Loading
Loading
+32 −22
Original line number Diff line number Diff line
@@ -826,10 +826,18 @@ public final class ViewRootImpl implements ViewParent,
     * The resolved pointer icon type requested by this window.
     * A null value indicates the resolved pointer icon has not yet been calculated.
     */
    // TODO(b/293587049): Remove pointer icon tracking by type when refactor is complete.
    @Nullable
    private Integer mPointerIconType = null;
    private PointerIcon mCustomPointerIcon = null;

    /**
     * The resolved pointer icon requested by this window.
     * A null value indicates the resolved pointer icon has not yet been calculated.
     */
    @Nullable
    private PointerIcon mResolvedPointerIcon = null;

    /**
     * see {@link #playSoundEffect(int)}
     */
@@ -7399,12 +7407,14 @@ public final class ViewRootImpl implements ViewParent,
                // Other apps or the window manager may change the icon type outside of
                // this app, therefore the icon type has to be reset on enter/exit event.
                mPointerIconType = null;
                mResolvedPointerIcon = null;
            }

            if (action != MotionEvent.ACTION_HOVER_EXIT) {
                // Resolve the pointer icon
                if (!updatePointerIcon(event) && action == MotionEvent.ACTION_HOVER_MOVE) {
                    mPointerIconType = null;
                    mResolvedPointerIcon = null;
                }
            }

@@ -7459,6 +7469,7 @@ public final class ViewRootImpl implements ViewParent,

    private void resetPointerIcon(MotionEvent event) {
        mPointerIconType = null;
        mResolvedPointerIcon = null;
        updatePointerIcon(event);
    }

@@ -7496,6 +7507,21 @@ public final class ViewRootImpl implements ViewParent,
            pointerIcon = mView.onResolvePointerIcon(event, pointerIndex);
        }

        if (enablePointerChoreographer()) {
            if (pointerIcon == null) {
                pointerIcon = PointerIcon.getSystemIcon(mContext, PointerIcon.TYPE_NOT_SPECIFIED);
            }
            if (Objects.equals(mResolvedPointerIcon, pointerIcon)) {
                return true;
            }
            mResolvedPointerIcon = pointerIcon;

            InputManagerGlobal.getInstance()
                    .setPointerIcon(pointerIcon, event.getDisplayId(),
                            event.getDeviceId(), event.getPointerId(0), getInputToken());
            return true;
        }

        final int pointerType = (pointerIcon != null) ?
                pointerIcon.getType() : PointerIcon.TYPE_NOT_SPECIFIED;

@@ -7503,35 +7529,19 @@ public final class ViewRootImpl implements ViewParent,
            mPointerIconType = pointerType;
            mCustomPointerIcon = null;
            if (mPointerIconType != PointerIcon.TYPE_CUSTOM) {
                if (enablePointerChoreographer()) {
                    InputManagerGlobal
                            .getInstance()
                            .setPointerIcon(PointerIcon.getSystemIcon(mContext, pointerType),
                                    event.getDisplayId(), event.getDeviceId(),
                                    event.getPointerId(pointerIndex), getInputToken());
                } else {
                InputManagerGlobal
                        .getInstance()
                        .setPointerIconType(pointerType);
                }
                return true;
            }
        }
        if (mPointerIconType == PointerIcon.TYPE_CUSTOM &&
                !pointerIcon.equals(mCustomPointerIcon)) {
            mCustomPointerIcon = pointerIcon;
            if (enablePointerChoreographer()) {
                InputManagerGlobal
                        .getInstance()
                        .setPointerIcon(mCustomPointerIcon,
                                event.getDisplayId(), event.getDeviceId(),
                                event.getPointerId(pointerIndex), getInputToken());
            } else {
            InputManagerGlobal
                    .getInstance()
                    .setCustomPointerIcon(mCustomPointerIcon);
        }
        }
        return true;
    }