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

Commit 21dea1b3 authored by “Longbo's avatar “Longbo Committed by Longbo Wei
Browse files

a11y: ScrollPanel - Update hovered button style

Bug: b/400964604
Test: AutoclickControllerTest
Flag: com.android.server.accessibility.enable_autoclick_indicator

Change-Id: Ic5a9ce3a6e9430ca7e3f1b37e787daa3b8a8f522
parent ad3850c3
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -20,6 +20,9 @@ import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_M

import android.annotation.IntDef;
import android.content.Context;
import android.graphics.BlendMode;
import android.graphics.BlendModeColorFilter;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.util.DisplayMetrics;
import android.view.Gravity;
@@ -233,12 +236,38 @@ public class AutoclickScrollPanel {
                    return true;
            }

            // Update the button background color based on hover state.
            toggleSelectedButtonStyle(button, hovered);
            // Notify the controller about the hover change.
            mScrollPanelController.onHoverButtonChange(direction, hovered);
            return true;
        });
    }

    /**
     * Updates the button's style based on hover state.
     *
     * @param button  The button to update the style for.
     * @param hovered Whether the button is being hovered or not.
     */
    private void toggleSelectedButtonStyle(ImageButton button, boolean hovered) {
        if (hovered) {
            int tintColor = mContext.getColor(
                    com.android.internal.R.color.materialColorOnPrimary);

            // Apply semi-transparent (22%) tint.
            // SRC_ATOP preserves the button's texture and shadows while applying the tint.
            button.getBackground().setColorFilter(new BlendModeColorFilter(
                    Color.argb(56, Color.red(tintColor), Color.green(tintColor),
                            Color.blue(tintColor)),

                    BlendMode.SRC_ATOP));
        } else {
            // Clear the color filter to remove the effect.
            button.getBackground().clearColorFilter();
        }
    }

    /**
     * Retrieves the layout params for AutoclickScrollPanel, used when it's added to the Window
     * Manager.