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

Commit 4f135163 authored by Tiger's avatar Tiger
Browse files

Use the nav bar color as the scrim color with 80% alpha

To make the color of the 3-button nav bar scrim match the app's theme or
match the UI element (ex: panel, tool bar, ..., etc) docked on the nav
bar when the edge-to-edge policy is enforced, the logic of the scrim is
refined as follows:

If the nav bar color is specified, and
- alpha != 0, the scrim color will be the nav bar color with 80% alpha;
- alpha == 0, the scrim color logic will fallback to the existing one.

If the nav bar color is not specified, the scrim color will be the
window background color with 80% alpha. The icon color of nav bar will
be adjusted accordingly to ensure the contrast.

Bug: 309578419
Test: 1. Specify nav bar color via Java and see if the nav bar color is
         as expected in 3-button mode but transparent in gesture mode.
      2. Specify nav bar color via XML and see if the nav bar color is
         as expected in 3-button mode but transparent in gesture mode.
      3. Specify window background color and see if the nav bar color is
         as expected in 3-button mode but transparent in gesture mode.
Change-Id: Id3aea6cedc29732dcfe1a537c24312f184c956fe
parent 260d9c9e
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -1876,11 +1876,15 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation

    @Override
    public @Appearance int getSystemBarsAppearance() {
        if (!mHost.isSystemBarsAppearanceControlled()) {
        @Appearance int appearance = mHost.getSystemBarsAppearance();

        // We only return the requested appearance, not the implied one.
            return 0;
        appearance &= ~APPEARANCE_FORCE_LIGHT_NAVIGATION_BARS;
        if (!mHost.isSystemBarsAppearanceControlled()) {
            appearance &= ~COMPATIBLE_APPEARANCE_FLAGS;
        }
        return mHost.getSystemBarsAppearance();

        return appearance;
    }

    @Override
+6 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.view;

import static android.view.WindowInsetsController.APPEARANCE_FORCE_LIGHT_NAVIGATION_BARS;
import static android.view.WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS;
import static android.view.WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS;
import static android.view.WindowInsetsController.APPEARANCE_LOW_PROFILE_BARS;
@@ -64,7 +65,11 @@ public class InsetsFlags {
            @ViewDebug.FlagToString(
                    mask = APPEARANCE_SEMI_TRANSPARENT_NAVIGATION_BARS,
                    equals = APPEARANCE_SEMI_TRANSPARENT_NAVIGATION_BARS,
                    name = "SEMI_TRANSPARENT_NAVIGATION_BARS")
                    name = "SEMI_TRANSPARENT_NAVIGATION_BARS"),
            @ViewDebug.FlagToString(
                    mask = APPEARANCE_FORCE_LIGHT_NAVIGATION_BARS,
                    equals = APPEARANCE_FORCE_LIGHT_NAVIGATION_BARS,
                    name = "FORCE_LIGHT_NAVIGATION_BARS")
    })
    public @Appearance int appearance;

+2 −1
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ import static android.view.ViewRootImplProto.WIDTH;
import static android.view.ViewRootImplProto.WINDOW_ATTRIBUTES;
import static android.view.ViewRootImplProto.WIN_FRAME;
import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
import static android.view.WindowInsetsController.COMPATIBLE_APPEARANCE_FLAGS;
import static android.view.flags.Flags.sensitiveContentAppProtection;
import static android.view.WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS;
import static android.view.WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS;
@@ -2861,7 +2862,7 @@ public final class ViewRootImpl implements ViewParent,
        final int adjust = inOutParams.softInputMode & SOFT_INPUT_MASK_ADJUST;
        if ((inOutParams.privateFlags & PRIVATE_FLAG_APPEARANCE_CONTROLLED) == 0) {
            inOutParams.insetsFlags.appearance = 0;
            inOutParams.insetsFlags.appearance &= ~COMPATIBLE_APPEARANCE_FLAGS;
            if ((sysUiVis & SYSTEM_UI_FLAG_LOW_PROFILE) != 0) {
                inOutParams.insetsFlags.appearance |= APPEARANCE_LOW_PROFILE_BARS;
            }
+4 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.view;

import static android.view.InsetsController.DEBUG;
import static android.view.WindowInsetsController.COMPATIBLE_APPEARANCE_FLAGS;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_APPEARANCE_CONTROLLED;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_BEHAVIOR_CONTROLLED;

@@ -173,7 +174,9 @@ public class ViewRootInsetsControllerHost implements InsetsController.Host {

    @Override
    public void setSystemBarsAppearance(int appearance, int mask) {
        if ((mask & COMPATIBLE_APPEARANCE_FLAGS) != 0) {
            mViewRoot.mWindowAttributes.privateFlags |= PRIVATE_FLAG_APPEARANCE_CONTROLLED;
        }
        final InsetsFlags insetsFlags = mViewRoot.mWindowAttributes.insetsFlags;
        final int newAppearance = (insetsFlags.appearance & ~mask) | (appearance & mask);
        if (insetsFlags.appearance != newAppearance) {
+25 −4
Original line number Diff line number Diff line
@@ -93,16 +93,37 @@ public interface WindowInsetsController {
    @FlaggedApi(Flags.FLAG_CUSTOMIZABLE_WINDOW_HEADERS)
    int APPEARANCE_LIGHT_CAPTION_BARS = 1 << 8;

    /**
     * Same as {@link #APPEARANCE_LIGHT_NAVIGATION_BARS} but set by the system. The system will
     * respect {@link #APPEARANCE_LIGHT_NAVIGATION_BARS} when this is cleared.
     * @hide
     */
    int APPEARANCE_FORCE_LIGHT_NAVIGATION_BARS = 1 << 9;

    /**
     * Appearance flags that can be implied from system UI flags.
     * @hide
     */
    int COMPATIBLE_APPEARANCE_FLAGS = APPEARANCE_LOW_PROFILE_BARS
            | APPEARANCE_LIGHT_STATUS_BARS
            | APPEARANCE_LIGHT_NAVIGATION_BARS;

    /**
     * Determines the appearance of system bars.
     * @hide
     */
    @Retention(RetentionPolicy.SOURCE)
    @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,
    @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_TRANSPARENT_CAPTION_BAR_BACKGROUND, APPEARANCE_LIGHT_CAPTION_BARS})
            APPEARANCE_TRANSPARENT_CAPTION_BAR_BACKGROUND,
            APPEARANCE_LIGHT_CAPTION_BARS,
            APPEARANCE_FORCE_LIGHT_NAVIGATION_BARS})
    @interface Appearance {
    }

Loading