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

Commit f2debc90 authored by Daichi Hirono's avatar Daichi Hirono
Browse files

Fixes the hover color of app handle menu buttons

Previously, app handle menu buttons used RippleDrawable for their
background. This prevented setting a specific hover background color, as
RippleDrawable automatically uses a 20% alpha version of the ripple
color for hover effects.

This change replaces RippleDrawable with ShapeDrawable, which allows the
desired hover background color to be set.

Video: http://recall/-/dvR0xNyCWFr2PAfPfPhsQ6/ey9AVamOsC6vezHYo5Y560
Bug: 400529749
Test: None
Flag: com.android.window.flags.enable_desktop_windowing_mode
Change-Id: I092fa5a76a5998f8224ffeb264396152770a4e4e
parent 314dedc1
Loading
Loading
Loading
Loading
+7 −8
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@ import android.widget.ImageButton
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.Space
import android.widget.TextView
import android.window.DesktopModeFlags
import android.window.SurfaceSyncGroup
import androidx.annotation.StringRes
@@ -59,10 +58,10 @@ import com.android.wm.shell.splitscreen.SplitScreenController
import com.android.wm.shell.windowdecor.additionalviewcontainer.AdditionalSystemViewContainer
import com.android.wm.shell.windowdecor.additionalviewcontainer.AdditionalViewContainer
import com.android.wm.shell.windowdecor.common.DecorThemeUtil
import com.android.wm.shell.windowdecor.common.DrawableInsets
import com.android.wm.shell.windowdecor.common.WindowDecorTaskResourceLoader
import com.android.wm.shell.windowdecor.common.calculateMenuPosition
import com.android.wm.shell.windowdecor.common.DrawableInsets
import com.android.wm.shell.windowdecor.common.createRippleDrawable
import com.android.wm.shell.windowdecor.common.createBackgroundDrawable
import com.android.wm.shell.windowdecor.extension.isFullscreen
import com.android.wm.shell.windowdecor.extension.isMultiWindow
import com.android.wm.shell.windowdecor.extension.isPinned
@@ -702,7 +701,7 @@ class HandleMenu(
                imageTintList = ColorStateList.valueOf(style.textColor)
                this.taskInfo = this@HandleMenuView.taskInfo

                background = createRippleDrawable(
                background = createBackgroundDrawable(
                    color = style.textColor,
                    cornerRadius = iconButtonRippleRadius,
                    drawableInsets = iconButtonDrawableInsetsBase
@@ -740,7 +739,7 @@ class HandleMenu(
                else iconButtonDrawableInsetsRight

            fullscreenBtn.apply {
                background = createRippleDrawable(
                background = createBackgroundDrawable(
                    color = style.textColor,
                    cornerRadius = iconButtonRippleRadius,
                    drawableInsets = startInsets
@@ -748,7 +747,7 @@ class HandleMenu(
            }

            splitscreenBtn.apply {
                background = createRippleDrawable(
                background = createBackgroundDrawable(
                    color = style.textColor,
                    cornerRadius = iconButtonRippleRadius,
                    drawableInsets = iconButtonDrawableInsetsBase
@@ -756,7 +755,7 @@ class HandleMenu(
            }

            floatingBtn.apply {
                background = createRippleDrawable(
                background = createBackgroundDrawable(
                    color = style.textColor,
                    cornerRadius = iconButtonRippleRadius,
                    drawableInsets = iconButtonDrawableInsetsBase
@@ -764,7 +763,7 @@ class HandleMenu(
            }

            desktopBtn.apply {
                background = createRippleDrawable(
                background = createBackgroundDrawable(
                    color = style.textColor,
                    cornerRadius = iconButtonRippleRadius,
                    drawableInsets = endInsets
+0 −40
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import android.content.res.ColorStateList
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.graphics.drawable.LayerDrawable
import android.graphics.drawable.RippleDrawable
import android.graphics.drawable.ShapeDrawable
import android.graphics.drawable.shapes.RoundRectShape

@@ -47,45 +46,6 @@ fun replaceColorAlpha(@ColorInt color: Int, alpha: Int): Int {
    )
}

/**
 * Creates a RippleDrawable with specified color, corner radius, and insets.
 */
fun createRippleDrawable(
    @ColorInt color: Int,
    cornerRadius: Int,
    drawableInsets: DrawableInsets,
): RippleDrawable {
    return RippleDrawable(
        ColorStateList(
            arrayOf(
                intArrayOf(android.R.attr.state_hovered),
                intArrayOf(android.R.attr.state_pressed),
                intArrayOf(),
            ),
            intArrayOf(
                replaceColorAlpha(color, OPACITY_11),
                replaceColorAlpha(color, OPACITY_15),
                Color.TRANSPARENT,
            )
        ),
        null /* content */,
        LayerDrawable(arrayOf(
            ShapeDrawable().apply {
                shape = RoundRectShape(
                    FloatArray(8) { cornerRadius.toFloat() },
                    null /* inset */,
                    null /* innerRadii */
                )
                paint.color = Color.WHITE
            }
        )).apply {
            require(numberOfLayers == 1) { "Must only contain one layer" }
            setLayerInset(0 /* index */,
                drawableInsets.l, drawableInsets.t, drawableInsets.r, drawableInsets.b)
        }
    )
}

/**
 * Creates a background drawable with specified color, corner radius, and insets.
 */