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

Commit 03fbdbe6 authored by Selim Cinek's avatar Selim Cinek Committed by Android (Google) Code Review
Browse files

Merge changes from topic 'background_inflation' into oc-dev

* changes:
  Fixed the contrast for low-priority notifications
  Moving Row inflation to the background too
  Moving the inflation to the background
parents f0de5cdd ac5f0274
Loading
Loading
Loading
Loading
+39 −3
Original line number Diff line number Diff line
@@ -2675,6 +2675,7 @@ public class Notification implements Parcelable
        private int mActionBarColor = COLOR_INVALID;
        private int mBackgroundColor = COLOR_INVALID;
        private int mForegroundColor = COLOR_INVALID;
        private int mBackgroundColorHint = COLOR_INVALID;

        /**
         * Constructs a new Builder with the defaults:
@@ -3839,6 +3840,13 @@ public class Notification implements Parcelable
                            backgroundColor);
                    mSecondaryTextColor = NotificationColorUtil.resolveSecondaryColor(mContext,
                            backgroundColor);
                    if (backgroundColor != COLOR_DEFAULT
                            && (mBackgroundColorHint != COLOR_INVALID || isColorized())) {
                        mPrimaryTextColor = NotificationColorUtil.findAlphaToMeetContrast(
                                mPrimaryTextColor, backgroundColor, 4.5);
                        mSecondaryTextColor = NotificationColorUtil.findAlphaToMeetContrast(
                                mSecondaryTextColor, backgroundColor, 4.5);
                    }
                } else {
                    double backLum = NotificationColorUtil.calculateLuminance(backgroundColor);
                    double textLum = NotificationColorUtil.calculateLuminance(mForegroundColor);
@@ -4662,10 +4670,26 @@ public class Notification implements Parcelable
            if (mCachedContrastColorIsFor == mN.color && mCachedContrastColor != COLOR_INVALID) {
                return mCachedContrastColor;
            }
            final int contrasted = NotificationColorUtil.resolveContrastColor(mContext, mN.color);

            int color;
            int background = mBackgroundColorHint;
            if (mBackgroundColorHint == COLOR_INVALID) {
                background = mContext.getColor(
                        com.android.internal.R.color.notification_material_background_color);
            }
            if (mN.color == COLOR_DEFAULT) {
                ensureColors();
                color = mSecondaryTextColor;
            } else {
                color = NotificationColorUtil.resolveContrastColor(mContext, mN.color,
                        background);
            }
            if (Color.alpha(color) < 255) {
                // alpha doesn't go well for color filters, so let's blend it manually
                color = NotificationColorUtil.compositeColors(color, background);
            }
            mCachedContrastColorIsFor = mN.color;
            return mCachedContrastColor = contrasted;
            return mCachedContrastColor = color;
        }

        int resolveAmbientColor() {
@@ -4882,7 +4906,8 @@ public class Notification implements Parcelable
            if (isColorized()) {
                return mBackgroundColor != COLOR_INVALID ? mBackgroundColor : mN.color;
            } else {
                return COLOR_DEFAULT;
                return mBackgroundColorHint != COLOR_INVALID ? mBackgroundColorHint
                        : COLOR_DEFAULT;
            }
        }

@@ -4913,6 +4938,17 @@ public class Notification implements Parcelable
            mTextColorsAreForBackground = COLOR_INVALID;
            ensureColors();
        }

        /**
         * Sets the background color for this notification to be a different one then the default.
         * This is mainly used to calculate contrast and won't necessarily be applied to the
         * background.
         *
         * @hide
         */
        public void setBackgroundColorHint(int backgroundColor) {
            mBackgroundColorHint = backgroundColor;
        }
    }

    /**
+44 −5
Original line number Diff line number Diff line
@@ -285,6 +285,38 @@ public class NotificationColorUtil {
        return ColorUtilsFromCompat.LABToColor(low, a, b);
    }

    /**
     * Finds a suitable alpha such that there's enough contrast.
     *
     * @param color the color to start searching from.
     * @param backgroundColor the color to ensure contrast against.
     * @param minRatio the minimum contrast ratio required.
     * @return the same color as {@param color} with potentially modified alpha to meet contrast
     */
    public static int findAlphaToMeetContrast(int color, int backgroundColor, double minRatio) {
        int fg = color;
        int bg = backgroundColor;
        if (ColorUtilsFromCompat.calculateContrast(fg, bg) >= minRatio) {
            return color;
        }
        int startAlpha = Color.alpha(color);
        int r = Color.red(color);
        int g = Color.green(color);
        int b = Color.blue(color);

        int low = startAlpha, high = 255;
        for (int i = 0; i < 15 && high - low > 0; i++) {
            final int alpha = (low + high) / 2;
            fg = Color.argb(alpha, r, g, b);
            if (ColorUtilsFromCompat.calculateContrast(fg, bg) > minRatio) {
                high = alpha;
            } else {
                low = alpha;
            }
        }
        return Color.argb(high, r, g, b);
    }

    /**
     * Finds a suitable color such that there's enough contrast.
     *
@@ -373,19 +405,19 @@ public class NotificationColorUtil {
     * color for the Notification's action and header text.
     *
     * @param notificationColor the color of the notification or {@link Notification#COLOR_DEFAULT}
     * @param backgroundColor the background color to ensure the contrast against.
     * @return a color of the same hue with enough contrast against the backgrounds.
     */
    public static int resolveContrastColor(Context context, int notificationColor) {
    public static int resolveContrastColor(Context context, int notificationColor,
            int backgroundColor) {
        final int resolvedColor = resolveColor(context, notificationColor);

        final int actionBg = context.getColor(
                com.android.internal.R.color.notification_action_list);
        final int notiBg = context.getColor(
                com.android.internal.R.color.notification_material_background_color);

        int color = resolvedColor;
        color = NotificationColorUtil.ensureLargeTextContrast(color, actionBg);
        color = NotificationColorUtil.ensureTextContrast(color, notiBg);
        color = NotificationColorUtil.ensureTextContrast(color, backgroundColor);

        if (color != resolvedColor) {
            if (DEBUG){
@@ -394,7 +426,7 @@ public class NotificationColorUtil {
                                + " and %s (over background) by changing #%s to %s",
                        context.getPackageName(),
                        NotificationColorUtil.contrastChange(resolvedColor, color, actionBg),
                        NotificationColorUtil.contrastChange(resolvedColor, color, notiBg),
                        NotificationColorUtil.contrastChange(resolvedColor, color, backgroundColor),
                        Integer.toHexString(resolvedColor), Integer.toHexString(color)));
            }
        }
@@ -501,6 +533,13 @@ public class NotificationColorUtil {
        return ColorUtilsFromCompat.calculateContrast(foregroundColor, backgroundColor);
    }

    /**
     * Composite two potentially translucent colors over each other and returns the result.
     */
    public static int compositeColors(int foreground, int background) {
        return ColorUtilsFromCompat.compositeColors(foreground, background);
    }

    /**
     * Framework copy of functions needed from android.support.v4.graphics.ColorUtils.
     */
+1 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-Iaidl-files-unde

LOCAL_STATIC_ANDROID_LIBRARIES := \
    SystemUIPluginLib \
    android-support-v4 \
    android-support-v7-recyclerview \
    android-support-v7-preference \
    android-support-v7-appcompat \
+24 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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
 */

package com.android.systemui.statusbar;

/**
 * An interface that allows aborting existing operations.
 */
public interface Abortable {
    void abort();
}
+1 −1
Original line number Diff line number Diff line
@@ -891,7 +891,7 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
     * @return the calculated background color
     */
    private int calculateBgColor(boolean withTint, boolean withOverRide) {
        if (mDark) {
        if (withTint && mDark) {
            return getContext().getColor(R.color.notification_material_background_dark_color);
        }
        if (withOverRide && mOverrideTint != NO_COLOR) {
Loading