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

Commit b5258351 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "System Bars: Ensure contrast when app requested transparent bar" into qt-dev

parents 3432b6df 4c864595
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -132,6 +132,7 @@ import android.widget.AdapterView;
import android.widget.Toast;
import android.widget.Toolbar;

import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.app.IVoiceInteractor;
@@ -4904,6 +4905,17 @@ public class Activity extends ContextThemeWrapper
            mTaskDescription.setNavigationBarColor(navigationBarColor);
        }

        final int targetSdk = getApplicationInfo().targetSdkVersion;
        final boolean targetPreQ = targetSdk < Build.VERSION_CODES.Q;
        if (!targetPreQ) {
            mTaskDescription.setEnsureStatusBarContrastWhenTransparent(a.getBoolean(
                    R.styleable.ActivityTaskDescription_ensureStatusBarContrastWhenTransparent,
                    false));
            mTaskDescription.setEnsureNavigationBarContrastWhenTransparent(a.getBoolean(
                    R.styleable.ActivityTaskDescription_ensureNavigationBarContrastWhenTransparent,
                    true));
        }

        a.recycle();
        setTaskDescription(mTaskDescription);
    }
+60 −9
Original line number Diff line number Diff line
@@ -986,6 +986,8 @@ public class ActivityManager {
        private int mColorBackground;
        private int mStatusBarColor;
        private int mNavigationBarColor;
        private boolean mEnsureStatusBarContrastWhenTransparent;
        private boolean mEnsureNavigationBarContrastWhenTransparent;

        /**
         * Creates the TaskDescription to the specified values.
@@ -998,7 +1000,7 @@ public class ActivityManager {
         */
        @Deprecated
        public TaskDescription(String label, Bitmap icon, int colorPrimary) {
            this(label, icon, 0, null, colorPrimary, 0, 0, 0);
            this(label, icon, 0, null, colorPrimary, 0, 0, 0, false, false);
            if ((colorPrimary != 0) && (Color.alpha(colorPrimary) != 255)) {
                throw new RuntimeException("A TaskDescription's primary color should be opaque");
            }
@@ -1014,7 +1016,7 @@ public class ActivityManager {
         *                     opaque.
         */
        public TaskDescription(String label, @DrawableRes int iconRes, int colorPrimary) {
            this(label, null, iconRes, null, colorPrimary, 0, 0, 0);
            this(label, null, iconRes, null, colorPrimary, 0, 0, 0, false, false);
            if ((colorPrimary != 0) && (Color.alpha(colorPrimary) != 255)) {
                throw new RuntimeException("A TaskDescription's primary color should be opaque");
            }
@@ -1029,7 +1031,7 @@ public class ActivityManager {
         */
        @Deprecated
        public TaskDescription(String label, Bitmap icon) {
            this(label, icon, 0, null, 0, 0, 0, 0);
            this(label, icon, 0, null, 0, 0, 0, 0, false, false);
        }

        /**
@@ -1040,7 +1042,7 @@ public class ActivityManager {
         *                activity.
         */
        public TaskDescription(String label, @DrawableRes int iconRes) {
            this(label, null, iconRes, null, 0, 0, 0, 0);
            this(label, null, iconRes, null, 0, 0, 0, 0, false, false);
        }

        /**
@@ -1049,19 +1051,21 @@ public class ActivityManager {
         * @param label A label and description of the current state of this activity.
         */
        public TaskDescription(String label) {
            this(label, null, 0, null, 0, 0, 0, 0);
            this(label, null, 0, null, 0, 0, 0, 0, false, false);
        }

        /**
         * Creates an empty TaskDescription.
         */
        public TaskDescription() {
            this(null, null, 0, null, 0, 0, 0, 0);
            this(null, null, 0, null, 0, 0, 0, 0, false, false);
        }

        /** @hide */
        public TaskDescription(String label, Bitmap bitmap, int iconRes, String iconFilename,
                int colorPrimary, int colorBackground, int statusBarColor, int navigationBarColor) {
                int colorPrimary, int colorBackground, int statusBarColor, int navigationBarColor,
                boolean ensureStatusBarContrastWhenTransparent,
                boolean ensureNavigationBarContrastWhenTransparent) {
            mLabel = label;
            mIcon = bitmap;
            mIconRes = iconRes;
@@ -1070,6 +1074,9 @@ public class ActivityManager {
            mColorBackground = colorBackground;
            mStatusBarColor = statusBarColor;
            mNavigationBarColor = navigationBarColor;
            mEnsureStatusBarContrastWhenTransparent = ensureStatusBarContrastWhenTransparent;
            mEnsureNavigationBarContrastWhenTransparent =
                    ensureNavigationBarContrastWhenTransparent;
        }

        /**
@@ -1092,6 +1099,9 @@ public class ActivityManager {
            mColorBackground = other.mColorBackground;
            mStatusBarColor = other.mStatusBarColor;
            mNavigationBarColor = other.mNavigationBarColor;
            mEnsureStatusBarContrastWhenTransparent = other.mEnsureStatusBarContrastWhenTransparent;
            mEnsureNavigationBarContrastWhenTransparent =
                    other.mEnsureNavigationBarContrastWhenTransparent;
        }

        /**
@@ -1114,6 +1124,9 @@ public class ActivityManager {
            if (other.mNavigationBarColor != 0) {
                mNavigationBarColor = other.mNavigationBarColor;
            }
            mEnsureStatusBarContrastWhenTransparent = other.mEnsureStatusBarContrastWhenTransparent;
            mEnsureNavigationBarContrastWhenTransparent =
                    other.mEnsureNavigationBarContrastWhenTransparent;
        }

        private TaskDescription(Parcel source) {
@@ -1272,6 +1285,37 @@ public class ActivityManager {
            return mNavigationBarColor;
        }

        /**
         * @hide
         */
        public boolean getEnsureStatusBarContrastWhenTransparent() {
            return mEnsureStatusBarContrastWhenTransparent;
        }

        /**
         * @hide
         */
        public void setEnsureStatusBarContrastWhenTransparent(
                boolean ensureStatusBarContrastWhenTransparent) {
            mEnsureStatusBarContrastWhenTransparent = ensureStatusBarContrastWhenTransparent;
        }

        /**
         * @hide
         */
        public boolean getEnsureNavigationBarContrastWhenTransparent() {
            return mEnsureNavigationBarContrastWhenTransparent;
        }

        /**
         * @hide
         */
        public void setEnsureNavigationBarContrastWhenTransparent(
                boolean ensureNavigationBarContrastWhenTransparent) {
            mEnsureNavigationBarContrastWhenTransparent =
                    ensureNavigationBarContrastWhenTransparent;
        }

        /** @hide */
        public void saveToXml(XmlSerializer out) throws IOException {
            if (mLabel != null) {
@@ -1332,6 +1376,8 @@ public class ActivityManager {
            dest.writeInt(mColorBackground);
            dest.writeInt(mStatusBarColor);
            dest.writeInt(mNavigationBarColor);
            dest.writeBoolean(mEnsureStatusBarContrastWhenTransparent);
            dest.writeBoolean(mEnsureNavigationBarContrastWhenTransparent);
            if (mIconFilename == null) {
                dest.writeInt(0);
            } else {
@@ -1348,6 +1394,8 @@ public class ActivityManager {
            mColorBackground = source.readInt();
            mStatusBarColor = source.readInt();
            mNavigationBarColor = source.readInt();
            mEnsureStatusBarContrastWhenTransparent = source.readBoolean();
            mEnsureNavigationBarContrastWhenTransparent = source.readBoolean();
            mIconFilename = source.readInt() > 0 ? source.readString() : null;
        }

@@ -1366,8 +1414,11 @@ public class ActivityManager {
            return "TaskDescription Label: " + mLabel + " Icon: " + mIcon +
                    " IconRes: " + mIconRes + " IconFilename: " + mIconFilename +
                    " colorPrimary: " + mColorPrimary + " colorBackground: " + mColorBackground +
                    " statusBarColor: " + mColorBackground +
                    " navigationBarColor: " + mNavigationBarColor;
                    " statusBarColor: " + mStatusBarColor + (
                    mEnsureStatusBarContrastWhenTransparent ? " (contrast when transparent)"
                            : "") + " navigationBarColor: " + mNavigationBarColor + (
                    mEnsureNavigationBarContrastWhenTransparent
                            ? " (contrast when transparent)" : "");
        }
    }

+64 −0
Original line number Diff line number Diff line
@@ -2329,6 +2329,70 @@ public abstract class Window {
        return 0;
    }

    /**
     * Sets whether the system should ensure that the status bar has enough
     * contrast when a fully transparent background is requested.
     *
     * <p>If set to this value, the system will determine whether a scrim is necessary
     * to ensure that the status bar has enough contrast with the contents of
     * this app, and set an appropriate effective bar background color accordingly.
     *
     * <p>When the status bar color has a non-zero alpha value, the value of this
     * property has no effect.
     *
     * @see android.R.attr#ensureStatusBarContrastWhenTransparent
     * @hide pending API
     */
    public void setEnsureStatusBarContrastWhenTransparent(boolean ensureContrast) {
    }

    /**
     * Returns whether the system is ensuring that the status bar has enough contrast when a
     * fully transparent background is requested.
     *
     * <p>When the status bar color has a non-zero alpha value, the value of this
     * property has no effect.
     *
     * @see android.R.attr#ensureStatusBarContrastWhenTransparent
     * @return true, if the system is ensuring contrast, false otherwise.
     * @hide pending API
     */
    public boolean isEnsureStatusBarContrastWhenTransparent() {
        return false;
    }

    /**
     * Sets whether the system should ensure that the navigation bar has enough
     * contrast when a fully transparent background is requested.
     *
     * <p>If set to this value, the system will determine whether a scrim is necessary
     * to ensure that the navigation bar has enough contrast with the contents of
     * this app, and set an appropriate effective bar background color accordingly.
     *
     * <p>When the navigation bar color has a non-zero alpha value, the value of this
     * property has no effect.
     *
     * @see android.R.attr#ensureNavigationBarContrastWhenTransparent
     * @hide pending API
     */
    public void setEnsureNavigationBarContrastWhenTransparent(boolean ensureContrast) {
    }

    /**
     * Returns whether the system is ensuring that the navigation bar has enough contrast when a
     * fully transparent background is requested.
     *
     * <p>When the navigation bar color has a non-zero alpha value, the value of this
     * property has no effect.
     *
     * @return true, if the system is ensuring contrast, false otherwise.
     * @see android.R.attr#ensureNavigationBarContrastWhenTransparent
     * @hide pending API
     */
    public boolean isEnsureNavigationBarContrastWhenTransparent() {
        return false;
    }

    /** @hide */
    public void setTheme(int resId) {
    }
+21 −6
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import static android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;

import static com.android.internal.policy.PhoneWindow.FEATURE_OPTIONS_PANEL;

import android.animation.Animator;
@@ -125,6 +126,8 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
    // The height of a window which has not in DIP.
    private final static int DECOR_SHADOW_UNFOCUSED_HEIGHT_IN_DIP = 5;

    private static final int SCRIM_LIGHT = 0x99ffffff; // 60% white

    public static final ColorViewAttributes STATUS_BAR_COLOR_VIEW_ATTRIBUTES =
            new ColorViewAttributes(SYSTEM_UI_FLAG_FULLSCREEN, FLAG_TRANSLUCENT_STATUS,
                    Gravity.TOP, Gravity.LEFT, Gravity.RIGHT,
@@ -1237,19 +1240,31 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind

    private int calculateStatusBarColor() {
        return calculateBarColor(mWindow.getAttributes().flags, FLAG_TRANSLUCENT_STATUS,
                mSemiTransparentBarColor, mWindow.mStatusBarColor);
                mSemiTransparentBarColor, mWindow.mStatusBarColor,
                getWindowSystemUiVisibility(), SYSTEM_UI_FLAG_LIGHT_STATUS_BAR,
                mWindow.mEnsureStatusBarContrastWhenTransparent);
    }

    private int calculateNavigationBarColor() {
        return calculateBarColor(mWindow.getAttributes().flags, FLAG_TRANSLUCENT_NAVIGATION,
                mSemiTransparentBarColor, mWindow.mNavigationBarColor);
                mSemiTransparentBarColor, mWindow.mNavigationBarColor,
                getWindowSystemUiVisibility(), SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR,
                mWindow.mEnsureNavigationBarContrastWhenTransparent
                        && getContext().getResources().getBoolean(R.bool.config_navBarNeedsScrim));
    }

    public static int calculateBarColor(int flags, int translucentFlag, int semiTransparentBarColor,
            int barColor) {
        return (flags & translucentFlag) != 0 ? semiTransparentBarColor
                : (flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0 ? barColor
                : Color.BLACK;
            int barColor, int sysuiVis, int lightSysuiFlag, boolean scrimTransparent) {
        if ((flags & translucentFlag) != 0) {
            return semiTransparentBarColor;
        } else if ((flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
            return Color.BLACK;
        } else if (scrimTransparent && barColor == Color.TRANSPARENT) {
            boolean light = (sysuiVis & lightSysuiFlag) != 0;
            return light ? SCRIM_LIGHT : semiTransparentBarColor;
        } else {
            return barColor;
        }
    }

    private int getCurrentColor(ColorViewState state) {
+37 −0
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ import android.media.AudioManager;
import android.media.session.MediaController;
import android.media.session.MediaSessionManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Parcel;
@@ -247,6 +248,9 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
    private boolean mForcedStatusBarColor = false;
    private boolean mForcedNavigationBarColor = false;

    boolean mEnsureStatusBarContrastWhenTransparent;
    boolean mEnsureNavigationBarContrastWhenTransparent;

    @UnsupportedAppUsage
    private CharSequence mTitle = null;

@@ -2439,6 +2443,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
        final boolean targetPreHoneycomb = targetSdk < android.os.Build.VERSION_CODES.HONEYCOMB;
        final boolean targetPreIcs = targetSdk < android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH;
        final boolean targetPreL = targetSdk < android.os.Build.VERSION_CODES.LOLLIPOP;
        final boolean targetPreQ = targetSdk < Build.VERSION_CODES.Q;
        final boolean targetHcNeedsOptions = context.getResources().getBoolean(
                R.bool.target_honeycomb_needs_options_menu);
        final boolean noActionBar = !hasFeature(FEATURE_ACTION_BAR) || hasFeature(FEATURE_NO_TITLE);
@@ -2457,6 +2462,12 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
            mNavigationBarDividerColor = a.getColor(R.styleable.Window_navigationBarDividerColor,
                    0x00000000);
        }
        if (!targetPreQ) {
            mEnsureStatusBarContrastWhenTransparent = a.getBoolean(
                    R.styleable.Window_ensureStatusBarContrastWhenTransparent, false);
            mEnsureNavigationBarContrastWhenTransparent = a.getBoolean(
                    R.styleable.Window_ensureNavigationBarContrastWhenTransparent, true);
        }

        WindowManager.LayoutParams params = getAttributes();

@@ -3845,6 +3856,32 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
        return mNavigationBarDividerColor;
    }

    @Override
    public void setEnsureStatusBarContrastWhenTransparent(boolean ensureContrast) {
        mEnsureStatusBarContrastWhenTransparent = ensureContrast;
        if (mDecor != null) {
            mDecor.updateColorViews(null, false /* animate */);
        }
    }

    @Override
    public boolean isEnsureStatusBarContrastWhenTransparent() {
        return mEnsureStatusBarContrastWhenTransparent;
    }

    @Override
    public void setEnsureNavigationBarContrastWhenTransparent(boolean ensureContrast) {
        mEnsureNavigationBarContrastWhenTransparent = ensureContrast;
        if (mDecor != null) {
            mDecor.updateColorViews(null, false /* animate */);
        }
    }

    @Override
    public boolean isEnsureNavigationBarContrastWhenTransparent() {
        return mEnsureNavigationBarContrastWhenTransparent;
    }

    public void setIsStartingWindow(boolean isStartingWindow) {
        mIsStartingWindow = isStartingWindow;
    }
Loading