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

Commit b1a85a7b authored by Jorge Gil's avatar Jorge Gil
Browse files

Add MaximizeMenuView with m3's dynamic color theming

To more easily support theming, this change also:
1) Replaces the maximize button's drawable with a custom
   StateListDrawable with selector state support, for out-of-the-box
   theming based on hover, selected, pressed and inactive states without
   manual motion event tracking.
   Also disables hardware acceleration on this button except for during
   animations, to prevent aliasing.
2) Moves toolkit specific logic into MaximizeMenuView, to encapsulate
   view inflation, binding, animations, etc and to keep it separate
   from the menu's window management logic

Bug: 328668781
Test: maximize menu theming follows app theme, regardless of system
theme

Change-Id: I8f5866102226d161cbb4d94611df46155747ce75
parent 7ee6daf9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -20,5 +20,6 @@
    android:shape="rectangle">
    <corners
        android:radius="@dimen/desktop_mode_maximize_menu_buttons_outline_radius"/>
    <solid android:color="?androidprv:attr/materialColorSurfaceContainerLow"/>
    <stroke android:width="1dp" android:color="?androidprv:attr/materialColorOutlineVariant"/>
</shape>
 No newline at end of file
+7 −15
Original line number Diff line number Diff line
@@ -31,23 +31,15 @@
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <FrameLayout
            android:id="@+id/maximize_menu_maximize_button_layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/desktop_mode_maximize_menu_layout_background"
            android:padding="4dp"
            android:layout_marginRight="8dp"
            android:layout_marginBottom="4dp"
            android:alpha="0">
        <Button
            android:layout_width="94dp"
            android:layout_height="60dp"
            android:id="@+id/maximize_menu_maximize_button"
            style="?android:attr/buttonBarButtonStyle"
                android:layout_width="86dp"
                android:layout_height="@dimen/desktop_mode_maximize_menu_button_height"
                android:background="@drawable/desktop_mode_maximize_menu_button_background"
                android:stateListAnimator="@null"/>
        </FrameLayout>
            android:stateListAnimator="@null"
            android:layout_marginRight="8dp"
            android:layout_marginBottom="4dp"
            android:alpha="0"/>

        <TextView
            android:id="@+id/maximize_menu_maximize_window_text"
+6 −0
Original line number Diff line number Diff line
@@ -476,6 +476,12 @@

    <!-- The radius of the layout outline around the maximize menu buttons. -->
    <dimen name="desktop_mode_maximize_menu_buttons_outline_radius">6dp</dimen>
    <!-- The stroke width of the outline around the maximize menu buttons. -->
    <dimen name="desktop_mode_maximize_menu_buttons_outline_stroke">1dp</dimen>
    <!-- The radius of the inner fill of the maximize menu buttons. -->
    <dimen name="desktop_mode_maximize_menu_buttons_fill_radius">4dp</dimen>
    <!-- The padding between the outline and fill of the maximize menu buttons. -->
    <dimen name="desktop_mode_maximize_menu_buttons_fill_padding">4dp</dimen>

    <!-- The corner radius of the maximize menu. -->
    <dimen name="desktop_mode_maximize_menu_corner_radius">8dp</dimen>
+445 −157

File changed.

Preview size limit exceeded, changes collapsed.

+35 −0
Original line number Diff line number Diff line
@@ -15,11 +15,16 @@
 */
package com.android.wm.shell.windowdecor.common

import android.annotation.ColorInt
import android.annotation.IntRange
import android.app.ActivityManager.RunningTaskInfo
import android.content.Context
import android.content.res.Configuration
import android.content.res.Configuration.UI_MODE_NIGHT_MASK
import android.graphics.Color
import androidx.compose.material3.ColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme

/** The theme of a window decoration. */
internal enum class Theme { LIGHT, DARK }
@@ -30,10 +35,31 @@ internal fun Theme.isLight(): Boolean = this == Theme.LIGHT
/** Whether a [Theme] is dark. */
internal fun Theme.isDark(): Boolean = this == Theme.DARK

/** Returns a copy of the color with its [alpha] component replaced with the given value. */
@ColorInt
internal fun @receiver:ColorInt Int.withAlpha(@IntRange(from = 0, to = 255) alpha: Int): Int =
    Color.argb(
        alpha,
        Color.red(this),
        Color.green(this),
        Color.blue(this)
    )

/** Common opacity values used in window decoration views. */
const val OPACITY_100 = 255
const val OPACITY_11 = 28
const val OPACITY_12 = 31
const val OPACITY_15 = 38
const val OPACITY_40 = 102
const val OPACITY_55 = 140
const val OPACITY_65 = 166

/**
 * Utility class for determining themes based on system settings and app's [RunningTaskInfo].
 */
internal class DecorThemeUtil(private val context: Context) {
    private val lightColors = dynamicLightColorScheme(context)
    private val darkColors = dynamicDarkColorScheme(context)

    private val systemTheme: Theme
        get() = if ((context.resources.configuration.uiMode and UI_MODE_NIGHT_MASK) ==
@@ -56,4 +82,13 @@ internal class DecorThemeUtil(private val context: Context) {
            Theme.LIGHT
        }
    }

    /**
     * Returns the [ColorScheme] to use to style window decorations based on the given
     * [RunningTaskInfo].
     */
    fun getColorScheme(task: RunningTaskInfo): ColorScheme = when (getAppTheme(task)) {
        Theme.LIGHT -> lightColors
        Theme.DARK -> darkColors
    }
}
Loading