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

Commit 18051edb authored by Jorge Gil's avatar Jorge Gil
Browse files

Add APPEARANCE_TRANSPARENT_CAPTION_BAR_BACKGROUND

To control whether the caption bar background is opaque (default) or
fully transparent. Also adds APPEARANCE_LIGHT_CAPTION_BARS to control
the foreground color of the caption bars when the background is set
to transparent and the app will draw a background themselves.

Bug: 316387515
Flag: ACONFIG android.view.flags.customizable_window_headers
DEVELOPMENT
Test: m

Change-Id: I5413ef48b1e89b624ecbbcb10bcd735c55575193
parent 953d3b1e
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -53746,8 +53746,10 @@ package android.view {
    method public void setSystemBarsAppearance(int, int);
    method public void setSystemBarsBehavior(int);
    method public void show(int);
    field @FlaggedApi("android.view.flags.customizable_window_headers") public static final int APPEARANCE_LIGHT_CAPTION_BARS = 256; // 0x100
    field public static final int APPEARANCE_LIGHT_NAVIGATION_BARS = 16; // 0x10
    field public static final int APPEARANCE_LIGHT_STATUS_BARS = 8; // 0x8
    field @FlaggedApi("android.view.flags.customizable_window_headers") public static final int APPEARANCE_TRANSPARENT_CAPTION_BAR_BACKGROUND = 128; // 0x80
    field public static final int BEHAVIOR_DEFAULT = 1; // 0x1
    field @Deprecated public static final int BEHAVIOR_SHOW_BARS_BY_SWIPE = 1; // 0x1
    field @Deprecated public static final int BEHAVIOR_SHOW_BARS_BY_TOUCH = 0; // 0x0
+18 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.view;

import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -26,6 +27,7 @@ import android.os.CancellationSignal;
import android.view.WindowInsets.Type;
import android.view.WindowInsets.Type.InsetsType;
import android.view.animation.Interpolator;
import android.view.flags.Flags;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -77,6 +79,20 @@ public interface WindowInsetsController {
     */
    int APPEARANCE_SEMI_TRANSPARENT_NAVIGATION_BARS = 1 << 6;

    /**
     * Makes the caption bar transparent.
     */
    @FlaggedApi(Flags.FLAG_CUSTOMIZABLE_WINDOW_HEADERS)
    int APPEARANCE_TRANSPARENT_CAPTION_BAR_BACKGROUND = 1 << 7;

    /**
     * When {@link WindowInsetsController#APPEARANCE_TRANSPARENT_CAPTION_BAR_BACKGROUND} is set,
     * changes the foreground color of the caption bars so that the items on the bar can be read
     * clearly on light backgrounds.
     */
    @FlaggedApi(Flags.FLAG_CUSTOMIZABLE_WINDOW_HEADERS)
    int APPEARANCE_LIGHT_CAPTION_BARS = 1 << 8;

    /**
     * Determines the appearance of system bars.
     * @hide
@@ -85,7 +101,8 @@ public interface WindowInsetsController {
    @IntDef(flag = true, value = {APPEARANCE_OPAQUE_STATUS_BARS, APPEARANCE_OPAQUE_NAVIGATION_BARS,
            APPEARANCE_LOW_PROFILE_BARS, APPEARANCE_LIGHT_STATUS_BARS,
            APPEARANCE_LIGHT_NAVIGATION_BARS, APPEARANCE_SEMI_TRANSPARENT_STATUS_BARS,
            APPEARANCE_SEMI_TRANSPARENT_NAVIGATION_BARS})
            APPEARANCE_SEMI_TRANSPARENT_NAVIGATION_BARS,
            APPEARANCE_TRANSPARENT_CAPTION_BAR_BACKGROUND, APPEARANCE_LIGHT_CAPTION_BARS})
    @interface Appearance {
    }

+19 −0
Original line number Diff line number Diff line
@@ -8,6 +8,8 @@ import android.graphics.Bitmap
import android.graphics.Color
import android.view.View
import android.view.View.OnLongClickListener
import android.view.WindowInsetsController.APPEARANCE_LIGHT_CAPTION_BARS
import android.view.WindowInsetsController.APPEARANCE_TRANSPARENT_CAPTION_BAR_BACKGROUND
import android.widget.ImageButton
import android.widget.ImageView
import android.widget.TextView
@@ -79,6 +81,9 @@ internal class DesktopModeAppControlsWindowDecorationViewHolder(

    @ColorInt
    private fun getCaptionBackgroundColor(taskInfo: RunningTaskInfo): Int {
        if (isTransparentBackgroundRequested(taskInfo)) {
            return Color.TRANSPARENT
        }
        val materialColorAttr: Int =
            if (isDarkMode()) {
                if (!taskInfo.isFocused) {
@@ -102,6 +107,10 @@ internal class DesktopModeAppControlsWindowDecorationViewHolder(
    @ColorInt
    private fun getAppNameAndButtonColor(taskInfo: RunningTaskInfo): Int {
        val materialColorAttr = when {
            isTransparentBackgroundRequested(taskInfo) &&
                    isLightCaptionBar(taskInfo) -> materialColorOnSecondaryContainer
            isTransparentBackgroundRequested(taskInfo) &&
                    !isLightCaptionBar(taskInfo) -> materialColorOnSurface
            isDarkMode() -> materialColorOnSurface
            else -> materialColorOnSecondaryContainer
        }
@@ -132,6 +141,16 @@ internal class DesktopModeAppControlsWindowDecorationViewHolder(
                Configuration.UI_MODE_NIGHT_YES
    }

    private fun isTransparentBackgroundRequested(taskInfo: RunningTaskInfo): Boolean {
        val appearance = taskInfo.taskDescription?.statusBarAppearance ?: 0
        return (appearance and APPEARANCE_TRANSPARENT_CAPTION_BAR_BACKGROUND) != 0
    }

    private fun isLightCaptionBar(taskInfo: RunningTaskInfo): Boolean {
        val appearance = taskInfo.taskDescription?.statusBarAppearance ?: 0
        return (appearance and APPEARANCE_LIGHT_CAPTION_BARS) != 0
    }

    companion object {
        private const val TAG = "DesktopModeAppControlsWindowDecorationViewHolder"
        private const val DARK_THEME_UNFOCUSED_OPACITY = 140 // 55%