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

Commit f9bba0b0 authored by Selim Cinek's avatar Selim Cinek
Browse files

Adapted the shelf color when transitioning

The shelf now changes colors correctly when
transitioning between low and high-priority
notifications.

Test: manual, add low-prio notification
Bug: 32437839
Change-Id: Iab51f3f1b1b2f446b1c00c80ecabcc4b00b0064a
parent db167370
Loading
Loading
Loading
Loading
+38 −4
Original line number Diff line number Diff line
@@ -86,6 +86,12 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
     */
    private static final float DARK_EXIT_SCALE_START = 0.93f;

    /**
     * A sentinel value when no color should be used. Can be used with {@link #setTintColor(int)}
     * or {@link #setOverrideTintColor(int, float)}.
     */
    protected static final int NO_COLOR = 0;

    private static final Interpolator ACTIVATE_INVERSE_INTERPOLATOR
            = new PathInterpolator(0.6f, 0, 0.5f, 1);
    private static final Interpolator ACTIVATE_INVERSE_ALPHA_INTERPOLATOR
@@ -167,6 +173,8 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
    private int mCurrentBackgroundTint;
    private int mTargetTint;
    private int mStartTint;
    private int mOverrideTint;
    private float mOverrideAmount;

    public ActivatableNotificationView(Context context, AttributeSet attrs) {
        super(context, attrs);
@@ -477,6 +485,23 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
        updateBackgroundTint(animated);
    }

    /**
     * Set an override tint color that is used for the background.
     *
     * @param color the color that should be used to tint the background.
     *              This can be {@link #NO_COLOR} if the tint should be normally computed.
     * @param overrideAmount a value from 0 to 1 how much the override tint should be used. The
     *                       background color will then be the interpolation between this and the
     *                       regular background color, where 1 means the overrideTintColor is fully
     *                       used and the background color not at all.
     */
    public void setOverrideTintColor(int color, float overrideAmount) {
        mOverrideTint = color;
        mOverrideAmount = overrideAmount;
        int newColor = calculateBgColor();
        setBackgroundTintColor(newColor);
    }

    protected void updateBackgroundTint() {
        updateBackgroundTint(false /* animated */);
    }
@@ -859,11 +884,20 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
    protected abstract View getContentView();

    public int calculateBgColor() {
        return calculateBgColor(true /* withTint */);
        return calculateBgColor(true /* withTint */, true /* withOverRide */);
    }

    private int calculateBgColor(boolean withTint) {
        if (withTint && mBgTint != 0) {
    /**
     * @param withTint should a possible tint be factored in?
     * @param withOverRide should the value be interpolated with {@link #mOverrideTint}
     * @return the calculated background color
     */
    private int calculateBgColor(boolean withTint, boolean withOverRide) {
        if (withOverRide && mOverrideTint != NO_COLOR) {
            int defaultTint = calculateBgColor(withTint, false);
            return NotificationUtils.interpolateColors(defaultTint, mOverrideTint, mOverrideAmount);
        }
        if (withTint && mBgTint != NO_COLOR) {
            return mBgTint;
        } else if (mShowingLegacyBackground) {
            return mLegacyColor;
@@ -954,7 +988,7 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
    }

    public int getBackgroundColorWithoutTint() {
        return calculateBgColor(false /* withTint */);
        return calculateBgColor(false /* withTint */, false /* withOverride */);
    }

    public interface OnActivatedListener {
+27 −4
Original line number Diff line number Diff line
@@ -148,7 +148,7 @@ public class NotificationShelf extends ActivatableNotificationView {
            mShelfState.openedAmount = openedAmount;
            mShelfState.clipTopAmount = 0;
            mShelfState.alpha = 1.0f;
            mShelfState.belowSpeedBump = false;
            mShelfState.belowSpeedBump = mAmbientState.getSpeedBumpIndex() == 0;
            mShelfState.shadowAlpha = 1.0f;
            mShelfState.isBottomClipped = false;
            mShelfState.hideSensitive = false;
@@ -183,10 +183,14 @@ public class NotificationShelf extends ActivatableNotificationView {
        //  find the first view that doesn't overlap with the shelf
        int notificationIndex = 0;
        int notGoneIndex = 0;
        int colorOfViewBeforeLast = 0;
        boolean backgroundForceHidden = false;
        if (mHideBackground && !mShelfState.hasItemsInStableShelf) {
            backgroundForceHidden = true;
        }
        int colorTwoBefore = NO_COLOR;
        int previousColor = NO_COLOR;
        float transitionAmount = 0.0f;
        while (notificationIndex < mHostLayout.getChildCount()) {
            ExpandableView child = (ExpandableView) mHostLayout.getChildAt(notificationIndex);
            notificationIndex++;
@@ -200,12 +204,13 @@ public class NotificationShelf extends ActivatableNotificationView {
            float notificationClipEnd;
            float shelfStart = getTranslationY();
            boolean aboveShelf = row.getTranslationZ() > mAmbientState.getBaseZHeight();
            if (child == lastChild || aboveShelf || backgroundForceHidden) {
            boolean isLastChild = child == lastChild;
            if (isLastChild || aboveShelf || backgroundForceHidden) {
                notificationClipEnd = shelfStart + getIntrinsicHeight();
            } else {
                notificationClipEnd = shelfStart - mPaddingBetweenElements;
                float height = notificationClipEnd - row.getTranslationY();
                if (height <= getNotificationMergeSize()) {
                if (!row.isBelowSpeedBump() && height <= getNotificationMergeSize()) {
                    // We want the gap to close when we reached the minimum size and only shrink
                    // before
                    notificationClipEnd = Math.min(shelfStart,
@@ -213,14 +218,29 @@ public class NotificationShelf extends ActivatableNotificationView {
                }
            }
            updateNotificationClipHeight(row, notificationClipEnd);
            numViewsInShelf += updateIconAppearance(row, iconState, icon, expandAmount);
            float inShelfAmount = updateIconAppearance(row, iconState, icon, expandAmount);
            numViewsInShelf += inShelfAmount;
            int ownColorUntinted = row.getBackgroundColorWithoutTint();
            if (row.getTranslationY() >= getTranslationY() && mNotGoneIndex == -1) {
                mNotGoneIndex = notGoneIndex;
                setTintColor(previousColor);
                setOverrideTintColor(colorTwoBefore, transitionAmount);

            } else if (mNotGoneIndex == -1) {
                colorTwoBefore = previousColor;
                transitionAmount = inShelfAmount;
            }
            if (isLastChild && colorOfViewBeforeLast != NO_COLOR) {
                row.setOverrideTintColor(colorOfViewBeforeLast, inShelfAmount);
            } else {
                colorOfViewBeforeLast = ownColorUntinted;
                row.setOverrideTintColor(NO_COLOR, 0 /* overrideAmount */);
            }
            if (notGoneIndex != 0 || !aboveShelf) {
                row.setAboveShelf(false);
            }
            notGoneIndex++;
            previousColor = ownColorUntinted;
        }
        mShelfIcons.calculateIconTranslations();
        mShelfIcons.applyIconStates();
@@ -246,6 +266,9 @@ public class NotificationShelf extends ActivatableNotificationView {
        }
    }

    /**
     * @return the icon amount how much this notification is in the shelf;
     */
    private float updateIconAppearance(ExpandableNotificationRow row,
            NotificationIconContainer.IconState iconState, StatusBarIconView icon,
            float expandAmount) {