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

Commit 8199e8c9 authored by Haoyu Zhang's avatar Haoyu Zhang
Browse files

Globally enable stylus hover icon

Requested by Scribe UX, a hover icon should be displayed for editors
that support scribe handwriting. But no hover icon should be displayed
for other views.
To achieve the goal, this CL enables the stylus hover icon globally so
that WebView and other toolkits can support hover icon via overriding
View#onResolvePointerIcon for stylus. And it also hide the stylus hover
icon for views that support PointerIcon for mouse.
We want to preserve the existing behavior for devices that
move the mouse cursor. And for devices that don't, like a
hovering stylus, we defer to the default behavior in View.java.

Bug: 277951386
Test: atest PointerIconTest
Change-Id: Ic8b2bfc7c3fb5ac2954381a373ba0f73790bbe15
parent 422eb0f5
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -2043,7 +2043,10 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
        final float x = event.getXDispatchLocation(pointerIndex);
        final float y = event.getYDispatchLocation(pointerIndex);
        if (isOnScrollbarThumb(x, y) || isDraggingScrollBar()) {
            return PointerIcon.getSystemIcon(mContext, PointerIcon.TYPE_ARROW);
            // Return null here so that it fallbacks to the default PointerIcon for the source
            // device. For mouse, the default PointerIcon is PointerIcon.TYPE_ARROW.
            // For stylus, the default PointerIcon is PointerIcon.TYPE_NULL.
            return null;
        }
        // Check what the child under the pointer says about the pointer.
        final int childrenCount = mChildrenCount;
+1 −1
Original line number Diff line number Diff line
@@ -4703,7 +4703,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te

    @Override
    public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
        if (mFastScroll != null) {
        if (mFastScroll != null && event.isFromSource(InputDevice.SOURCE_MOUSE)) {
            PointerIcon pointerIcon = mFastScroll.onResolvePointerIcon(event, pointerIndex);
            if (pointerIcon != null) {
                return pointerIcon;
+3 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.InputDevice;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.PointerIcon;
@@ -173,7 +174,8 @@ public class Button extends TextView {

    @Override
    public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
        if (getPointerIcon() == null && isClickable() && isEnabled()) {
        if (getPointerIcon() == null && isClickable() && isEnabled()
                && event.isFromSource(InputDevice.SOURCE_MOUSE)) {
            return PointerIcon.getSystemIcon(getContext(), PointerIcon.TYPE_HAND);
        }
        return super.onResolvePointerIcon(event, pointerIndex);
+3 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.InputDevice;
import android.view.MotionEvent;
import android.view.PointerIcon;
import android.widget.RemoteViews.RemoteView;
@@ -99,7 +100,8 @@ public class ImageButton extends ImageView {

    @Override
    public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
        if (getPointerIcon() == null && isClickable() && isEnabled()) {
        if (getPointerIcon() == null && isClickable() && isEnabled()
                && event.isFromSource(InputDevice.SOURCE_MOUSE)) {
            return PointerIcon.getSystemIcon(getContext(), PointerIcon.TYPE_HAND);
        }
        return super.onResolvePointerIcon(event, pointerIndex);
+6 −3
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.util.MathUtils;
import android.util.StateSet;
import android.util.TypedValue;
import android.view.HapticFeedbackConstants;
import android.view.InputDevice;
import android.view.MotionEvent;
import android.view.PointerIcon;
import android.view.View;
@@ -1060,10 +1061,12 @@ public class RadialTimePickerView extends View {
        if (!isEnabled()) {
            return null;
        }
        if (event.isFromSource(InputDevice.SOURCE_MOUSE)) {
            final int degrees = getDegreesFromXY(event.getX(), event.getY(), false);
            if (degrees != -1) {
                return PointerIcon.getSystemIcon(getContext(), PointerIcon.TYPE_HAND);
            }
        }
        return super.onResolvePointerIcon(event, pointerIndex);
    }

Loading