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

Commit 0cccf78c authored by Jeremy Walker's avatar Jeremy Walker
Browse files

Changes PointerIcon hover on Button and other widgets to arrow.

Bug: 299269803
Test: Tests revised and added to cts in ag/26052147
Change-Id: I3612352c2c281b1b4bacba413a7199b880c1d639
parent 0d297ab7
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -42,3 +42,10 @@ flag {
  # Referenced in WM where WM starts before DeviceConfig
  is_fixed_read_only: true
}

flag {
    name: "enable_arrow_icon_on_hover_when_clickable"
    namespace: "toolkit"
    description: "Enable default arrow icon when hovering on buttons or clickable widgets."
    bug: "299269803"
}
+12 −3
Original line number Diff line number Diff line
@@ -16,6 +16,10 @@

package android.widget;

import static android.view.flags.Flags.enableArrowIconOnHoverWhenClickable;
import static android.view.flags.Flags.FLAG_ENABLE_ARROW_ICON_ON_HOVER_WHEN_CLICKABLE;

import android.annotation.FlaggedApi;
import android.content.Context;
import android.util.AttributeSet;
import android.view.InputDevice;
@@ -24,7 +28,6 @@ import android.view.MotionEvent;
import android.view.PointerIcon;
import android.widget.RemoteViews.RemoteView;


/**
 * A user interface element the user can tap or click to perform an action.
 *
@@ -172,10 +175,16 @@ public class Button extends TextView {
        return Button.class.getName();
    }

    @FlaggedApi(FLAG_ENABLE_ARROW_ICON_ON_HOVER_WHEN_CLICKABLE)
    @Override
    public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
        if (getPointerIcon() == null && isClickable() && isEnabled()
                && event.isFromSource(InputDevice.SOURCE_MOUSE)) {
        // By default the pointer icon is an arrow. More specifically, when the pointer icon is set
        // to null, it will be an arrow. Therefore, we don't need to change the icon when
        // enableArrowIconOnHoverWhenClickable() and the pointer icon is a null. We only need to do
        // that when we want the hand icon for hover.
        if (!enableArrowIconOnHoverWhenClickable() && getPointerIcon() == null && isClickable()
                && isEnabled() && event.isFromSource(InputDevice.SOURCE_MOUSE)
        ) {
            return PointerIcon.getSystemIcon(getContext(), PointerIcon.TYPE_HAND);
        }
        return super.onResolvePointerIcon(event, pointerIndex);
+10 −1
Original line number Diff line number Diff line
@@ -16,6 +16,10 @@

package android.widget;

import static android.view.flags.Flags.enableArrowIconOnHoverWhenClickable;
import static android.view.flags.Flags.FLAG_ENABLE_ARROW_ICON_ON_HOVER_WHEN_CLICKABLE;

import android.annotation.FlaggedApi;
import android.content.Context;
import android.util.AttributeSet;
import android.view.InputDevice;
@@ -98,11 +102,16 @@ public class ImageButton extends ImageView {
        return ImageButton.class.getName();
    }

    @FlaggedApi(FLAG_ENABLE_ARROW_ICON_ON_HOVER_WHEN_CLICKABLE)
    @Override
    public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
        if (getPointerIcon() == null && isClickable() && isEnabled()
                && event.isFromSource(InputDevice.SOURCE_MOUSE)) {
            return PointerIcon.getSystemIcon(getContext(), PointerIcon.TYPE_HAND);

            int pointerIcon = enableArrowIconOnHoverWhenClickable()
                    ? PointerIcon.TYPE_ARROW
                    : PointerIcon.TYPE_HAND;
            return PointerIcon.getSystemIcon(getContext(), pointerIcon);
        }
        return super.onResolvePointerIcon(event, pointerIndex);
    }
+9 −1
Original line number Diff line number Diff line
@@ -16,7 +16,11 @@

package android.widget;

import static android.view.flags.Flags.enableArrowIconOnHoverWhenClickable;
import static android.view.flags.Flags.FLAG_ENABLE_ARROW_ICON_ON_HOVER_WHEN_CLICKABLE;

import android.animation.ObjectAnimator;
import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.content.Context;
import android.content.res.ColorStateList;
@@ -1056,6 +1060,7 @@ public class RadialTimePickerView extends View {
        invalidate();
    }

    @FlaggedApi(FLAG_ENABLE_ARROW_ICON_ON_HOVER_WHEN_CLICKABLE)
    @Override
    public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
        if (!isEnabled()) {
@@ -1064,7 +1069,10 @@ public class RadialTimePickerView extends View {
        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);
                int pointerIcon = enableArrowIconOnHoverWhenClickable()
                        ? PointerIcon.TYPE_ARROW
                        : PointerIcon.TYPE_HAND;
                return PointerIcon.getSystemIcon(getContext(), pointerIcon);
            }
        }
        return super.onResolvePointerIcon(event, pointerIndex);
+9 −1
Original line number Diff line number Diff line
@@ -16,6 +16,10 @@

package android.widget;

import static android.view.flags.Flags.enableArrowIconOnHoverWhenClickable;
import static android.view.flags.Flags.FLAG_ENABLE_ARROW_ICON_ON_HOVER_WHEN_CLICKABLE;

import android.annotation.FlaggedApi;
import android.annotation.Nullable;
import android.content.Context;
import android.content.res.ColorStateList;
@@ -1037,6 +1041,7 @@ class SimpleMonthView extends View {
        return true;
    }

    @FlaggedApi(FLAG_ENABLE_ARROW_ICON_ON_HOVER_WHEN_CLICKABLE)
    @Override
    public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
        if (!isEnabled()) {
@@ -1049,7 +1054,10 @@ class SimpleMonthView extends View {
            final int y = (int) (event.getY() + 0.5f);
            final int dayUnderPointer = getDayAtLocation(x, y);
            if (dayUnderPointer >= 0) {
                return PointerIcon.getSystemIcon(getContext(), PointerIcon.TYPE_HAND);
                int pointerIcon = enableArrowIconOnHoverWhenClickable()
                        ? PointerIcon.TYPE_ARROW
                        : PointerIcon.TYPE_HAND;
                return PointerIcon.getSystemIcon(getContext(), pointerIcon);
            }
        }
        return super.onResolvePointerIcon(event, pointerIndex);
Loading