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

Commit 3a60bb30 authored by Matt Sziklay's avatar Matt Sziklay Committed by Android (Google) Code Review
Browse files

Merge "Change header background/text/icons color to be system based." into main

parents 9f1195be 71add7cb
Loading
Loading
Loading
Loading
+0 −22
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2022 The Android Open Source Project
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->
<shape android:shape="rectangle"
       android:tintMode="multiply"
       android:tint="@color/decor_title_color"
       xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@android:color/white" />
</shape>
+3 −8
Original line number Diff line number Diff line
@@ -21,8 +21,7 @@
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:orientation="horizontal"
    android:background="@drawable/desktop_mode_decor_title">
    android:orientation="horizontal">

    <LinearLayout
        android:id="@+id/open_menu_button"
@@ -45,7 +44,6 @@
            android:layout_width="0dp"
            android:layout_height="20dp"
            android:minWidth="80dp"
            android:textColor="@color/desktop_mode_caption_app_name_dark"
            android:textAppearance="@android:style/TextAppearance.Material.Title"
            android:textSize="14sp"
            android:textFontWeight="500"
@@ -62,7 +60,6 @@
            android:layout_height="16dp"
            android:contentDescription="@string/expand_menu_text"
            android:src="@drawable/ic_baseline_expand_more_24"
            android:tint="@color/desktop_mode_caption_expand_button_dark"
            android:background="@null"
            android:scaleType="fitCenter"
            android:clickable="false"
@@ -87,8 +84,7 @@
        android:src="@drawable/decor_desktop_mode_maximize_button_dark"
        android:scaleType="fitCenter"
        android:gravity="end"
        android:background="@null"
        android:tint="@color/desktop_mode_caption_maximize_button_dark"/>
        android:background="@null"/>

    <ImageButton
        android:id="@+id/close_window"
@@ -100,6 +96,5 @@
        android:src="@drawable/decor_close_button_dark"
        android:scaleType="fitCenter"
        android:gravity="end"
        android:background="@null"
        android:tint="@color/desktop_mode_caption_close_button_dark"/>
        android:background="@null"/>
</com.android.wm.shell.windowdecor.WindowDecorLinearLayout>
 No newline at end of file
+1 −3
Original line number Diff line number Diff line
@@ -20,8 +20,7 @@
    android:id="@+id/desktop_mode_caption"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:background="@drawable/desktop_mode_decor_title">
    android:gravity="center_horizontal">

    <ImageButton
        android:id="@+id/caption_handle"
@@ -33,5 +32,4 @@
        tools:tint="@color/desktop_mode_caption_handle_bar_dark"
        android:scaleType="fitXY"
        android:background="?android:selectableItemBackground"/>

</com.android.wm.shell.windowdecor.WindowDecorLinearLayout>
 No newline at end of file
+0 −8
Original line number Diff line number Diff line
@@ -60,14 +60,6 @@
    <!-- Desktop Mode -->
    <color name="desktop_mode_caption_handle_bar_light">#EFF1F2</color>
    <color name="desktop_mode_caption_handle_bar_dark">#1C1C17</color>
    <color name="desktop_mode_caption_expand_button_light">#EFF1F2</color>
    <color name="desktop_mode_caption_expand_button_dark">#48473A</color>
    <color name="desktop_mode_caption_close_button_light">#EFF1F2</color>
    <color name="desktop_mode_caption_close_button_dark">#1C1C17</color>
    <color name="desktop_mode_caption_maximize_button_light">#EFF1F2</color>
    <color name="desktop_mode_caption_maximize_button_dark">#1C1C17</color>
    <color name="desktop_mode_caption_app_name_light">#EFF1F2</color>
    <color name="desktop_mode_caption_app_name_dark">#1C1C17</color>
    <color name="desktop_mode_resize_veil_light">#EFF1F2</color>
    <color name="desktop_mode_resize_veil_dark">#1C1C17</color>
    <color name="desktop_mode_maximize_menu_button">#DDDACD</color>
+70 −36
Original line number Diff line number Diff line
package com.android.wm.shell.windowdecor.viewholder

import android.annotation.ColorInt
import android.app.ActivityManager.RunningTaskInfo
import android.content.res.ColorStateList
import android.content.res.Configuration
import android.graphics.Bitmap
import android.graphics.drawable.GradientDrawable
import android.graphics.Color
import android.view.View
import android.view.View.OnLongClickListener
import android.widget.ImageButton
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.withStyledAttributes
import com.android.internal.R.attr.materialColorOnSecondaryContainer
import com.android.internal.R.attr.materialColorOnSurface
import com.android.internal.R.attr.materialColorSecondaryContainer
import com.android.internal.R.attr.materialColorSurfaceContainerHigh
import com.android.internal.R.attr.materialColorSurfaceContainerLow
import com.android.internal.R.attr.materialColorSurfaceDim
import com.android.wm.shell.R

/**
@@ -49,57 +58,82 @@ internal class DesktopModeAppControlsWindowDecorationViewHolder(
    }

    override fun bindData(taskInfo: RunningTaskInfo) {
        val captionDrawable = captionView.background as GradientDrawable
        taskInfo.taskDescription?.statusBarColor?.let {
            captionDrawable.setColor(it)
        }

        closeWindowButton.imageTintList = ColorStateList.valueOf(
                getCaptionCloseButtonColor(taskInfo))
        maximizeWindowButton.imageTintList = ColorStateList.valueOf(
                getCaptionMaximizeButtonColor(taskInfo))
        expandMenuButton.imageTintList = ColorStateList.valueOf(
                getCaptionExpandButtonColor(taskInfo))
        appNameTextView.setTextColor(getCaptionAppNameTextColor(taskInfo))
        captionView.setBackgroundColor(getCaptionBackgroundColor(taskInfo))
        val color = getAppNameAndButtonColor(taskInfo)
        val alpha = Color.alpha(color)
        closeWindowButton.imageTintList = ColorStateList.valueOf(color)
        maximizeWindowButton.imageTintList = ColorStateList.valueOf(color)
        expandMenuButton.imageTintList = ColorStateList.valueOf(color)
        appNameTextView.setTextColor(color)
        appIconImageView.imageAlpha = alpha
        maximizeWindowButton.imageAlpha = alpha
        closeWindowButton.imageAlpha = alpha
        expandMenuButton.imageAlpha = alpha
    }

    override fun onHandleMenuOpened() {}

    override fun onHandleMenuClosed() {}

    private fun getCaptionAppNameTextColor(taskInfo: RunningTaskInfo): Int {
        return if (shouldUseLightCaptionColors(taskInfo)) {
            context.getColor(R.color.desktop_mode_caption_app_name_light)
    @ColorInt
    private fun getCaptionBackgroundColor(taskInfo: RunningTaskInfo): Int {
        val materialColorAttr: Int =
            if (isDarkMode()) {
                if (!taskInfo.isFocused) {
                    materialColorSurfaceContainerHigh
                } else {
            context.getColor(R.color.desktop_mode_caption_app_name_dark)
        }
                    materialColorSurfaceDim
                }

    private fun getCaptionCloseButtonColor(taskInfo: RunningTaskInfo): Int {
        return if (shouldUseLightCaptionColors(taskInfo)) {
            context.getColor(R.color.desktop_mode_caption_close_button_light)
            } else {
            context.getColor(R.color.desktop_mode_caption_close_button_dark)
                if (!taskInfo.isFocused) {
                    materialColorSurfaceContainerLow
                } else {
                    materialColorSecondaryContainer
                }
        }

    private fun getCaptionMaximizeButtonColor(taskInfo: RunningTaskInfo): Int {
        return if (shouldUseLightCaptionColors(taskInfo)) {
            context.getColor(R.color.desktop_mode_caption_maximize_button_light)
        } else {
            context.getColor(R.color.desktop_mode_caption_maximize_button_dark)
        context.withStyledAttributes(null, intArrayOf(materialColorAttr), 0, 0) {
            return getColor(0, 0)
        }
        return 0
    }

    private fun getCaptionExpandButtonColor(taskInfo: RunningTaskInfo): Int {
        return if (shouldUseLightCaptionColors(taskInfo)) {
            context.getColor(R.color.desktop_mode_caption_expand_button_light)
    @ColorInt
    private fun getAppNameAndButtonColor(taskInfo: RunningTaskInfo): Int {
        val materialColorAttr = when {
            isDarkMode() -> materialColorOnSurface
            else -> materialColorOnSecondaryContainer
        }
        val appDetailsOpacity = when {
            isDarkMode() && !taskInfo.isFocused -> DARK_THEME_UNFOCUSED_OPACITY
            !isDarkMode() && !taskInfo.isFocused -> LIGHT_THEME_UNFOCUSED_OPACITY
            else -> FOCUSED_OPACITY
        }
        context.withStyledAttributes(null, intArrayOf(materialColorAttr), 0, 0) {
            val color = getColor(0, 0)
            return if (appDetailsOpacity == FOCUSED_OPACITY) {
                color
            } else {
            context.getColor(R.color.desktop_mode_caption_expand_button_dark)
                Color.argb(
                    appDetailsOpacity,
                    Color.red(color),
                    Color.green(color),
                    Color.blue(color)
                )
            }
        }
        return 0
    }

    private fun isDarkMode(): Boolean {
        return context.resources.configuration.uiMode and
                Configuration.UI_MODE_NIGHT_MASK ==
                Configuration.UI_MODE_NIGHT_YES
    }

    companion object {
        private const val TAG = "DesktopModeAppControlsWindowDecorationViewHolder"
        private const val DARK_THEME_UNFOCUSED_OPACITY = 140 // 55%
        private const val LIGHT_THEME_UNFOCUSED_OPACITY = 166 // 65%
        private const val FOCUSED_OPACITY = 255
    }
}
Loading