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

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

Added transparency to the notification backgrounds on the lockscreen

To achieve a decent lockscreen animation we also need to account for alpha.

Change-Id: Iba75f9c304962da309e0e2d32a58d757b6607b5b
parent 614576e3
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -78,13 +78,13 @@
    <color name="notification_material_background_color">#ffffffff</color>

    <!-- The color of the material notification background when dimmed -->
    <color name="notification_material_background_dimmed_color">#f2ffffff</color>
    <color name="notification_material_background_dimmed_color">#ccffffff</color>

    <!-- The color of the material notification background when low priority -->
    <color name="notification_material_background_low_priority_color">#fff5f5f5</color>

    <!-- The background color of the notification shade -->
    <color name="notification_shade_background_color">#fff9f9f9</color>
    <color name="notification_shade_background_color">#ffeeeeee</color>

    <!-- The color of the ripples on the untinted notifications -->
    <color name="notification_ripple_untinted_color">#28000000</color>
+70 −3
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.statusbar;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.animation.TimeAnimator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Canvas;
@@ -33,6 +34,7 @@ import android.view.animation.PathInterpolator;

import com.android.systemui.R;
import com.android.systemui.classifier.FalsingManager;
import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;

/**
 * Base class for both {@link ExpandableNotificationRow} and {@link NotificationOverflowContainer}
@@ -127,6 +129,31 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
    private FalsingManager mFalsingManager;
    private boolean mTrackTouch;

    private float mNormalBackgroundVisibilityAmount;
    private ValueAnimator mFadeInFromDarkAnimator;
    private ValueAnimator.AnimatorUpdateListener mBackgroundVisibilityUpdater
            = new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            setNormalBackgroundVisibilityAmount(mBackgroundNormal.getAlpha());
        }
    };
    private AnimatorListenerAdapter mFadeInEndListener = new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            mFadeInFromDarkAnimator = null;
            updateOutlineAlpha();
        }
    };
    private ValueAnimator.AnimatorUpdateListener mUpdateOutlineListener
            = new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            updateOutlineAlpha();
        }
    };

    public ActivatableNotificationView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
@@ -156,6 +183,7 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
        mBackgroundDimmed.setCustomBackground(R.drawable.notification_material_bg_dim);
        updateBackground();
        updateBackgroundTint();
        updateOutlineAlpha();
    }

    private final Runnable mTapTimeoutRunnable = new Runnable() {
@@ -262,7 +290,7 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
        }
    }

    private void startActivateAnimation(boolean reverse) {
    private void startActivateAnimation(final boolean reverse) {
        if (!isAttachedToWindow()) {
            return;
        }
@@ -307,6 +335,16 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
        mBackgroundNormal.animate()
                .alpha(reverse ? 0f : 1f)
                .setInterpolator(alphaInterpolator)
                .setUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        float animatedFraction = animation.getAnimatedFraction();
                        if (reverse) {
                            animatedFraction = 1.0f - animatedFraction;
                        }
                        setNormalBackgroundVisibilityAmount(animatedFraction);
                    }
                })
                .setDuration(ACTIVATE_ANIMATION_LENGTH);
    }

@@ -367,7 +405,25 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
        } else {
            updateBackground();
        }
        setOutlineAlpha(dark ? 0f : 1f);
        updateOutlineAlpha();
    }

    private void updateOutlineAlpha() {
        if (mDark) {
            setOutlineAlpha(0f);
            return;
        }
        float alpha = NotificationStackScrollLayout.BACKGROUND_ALPHA_DIMMED;
        alpha = (alpha + (1.0f - alpha) * mNormalBackgroundVisibilityAmount);
        if (mFadeInFromDarkAnimator != null) {
            alpha *= mFadeInFromDarkAnimator.getAnimatedFraction();
        }
        setOutlineAlpha(alpha);
    }

    public void setNormalBackgroundVisibilityAmount(float normalBackgroundVisibilityAmount) {
        mNormalBackgroundVisibilityAmount = normalBackgroundVisibilityAmount;
        updateOutlineAlpha();
    }

    public void setShowingLegacyBackground(boolean showing) {
@@ -431,7 +487,15 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
                        background.setAlpha(1f);
                    }
                })
                .setUpdateListener(mBackgroundVisibilityUpdater)
                .start();
        mFadeInFromDarkAnimator = TimeAnimator.ofFloat(0.0f, 1.0f);
        mFadeInFromDarkAnimator.setDuration(DARK_ANIMATION_LENGTH);
        mFadeInFromDarkAnimator.setStartDelay(delay);
        mFadeInFromDarkAnimator.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN);
        mFadeInFromDarkAnimator.addListener(mFadeInEndListener);
        mFadeInFromDarkAnimator.addUpdateListener(mUpdateOutlineListener);
        mFadeInFromDarkAnimator.start();
    }

    /**
@@ -477,6 +541,7 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
                mBackgroundAnimator = null;
            }
        });
        mBackgroundAnimator.addUpdateListener(mBackgroundVisibilityUpdater);
        mBackgroundAnimator.start();
    }

@@ -494,6 +559,8 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
            mBackgroundNormal.setAlpha(1f);
            removeCallbacks(mTapTimeoutRunnable);
        }
        setNormalBackgroundVisibilityAmount(
                mBackgroundNormal.getVisibility() == View.VISIBLE ? 1.0f : 0.0f);
    }

    protected boolean shouldHideBackground() {
+5 −5
Original line number Diff line number Diff line
@@ -24,8 +24,6 @@ import android.util.AttributeSet;
import android.view.View;
import android.view.ViewOutlineProvider;

import com.android.systemui.R;

/**
 * Like {@link ExpandableView}, but setting an outline for the height and clipping.
 */
@@ -33,7 +31,7 @@ public abstract class ExpandableOutlineView extends ExpandableView {

    private final Rect mOutlineRect = new Rect();
    private boolean mCustomOutline;
    private float mOutlineAlpha = 1f;
    private float mOutlineAlpha = -1f;

    public ExpandableOutlineView(Context context, AttributeSet attrs) {
        super(context, attrs);
@@ -66,9 +64,11 @@ public abstract class ExpandableOutlineView extends ExpandableView {
    }

    protected void setOutlineAlpha(float alpha) {
        if (alpha != mOutlineAlpha) {
            mOutlineAlpha = alpha;
            invalidateOutline();
        }
    }

    protected void setOutlineRect(RectF rect) {
        if (rect != null) {
+23 −5
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ public class ScrimView extends View
            mAlphaAnimator = null;
        }
    };
    private Runnable mChangeRunnable;

    public ScrimView(Context context) {
        this(context, null);
@@ -78,9 +79,7 @@ public class ScrimView extends View
    protected void onDraw(Canvas canvas) {
        if (mDrawAsSrc || (!mIsEmpty && mViewAlpha > 0f)) {
            PorterDuff.Mode mode = mDrawAsSrc ? PorterDuff.Mode.SRC : PorterDuff.Mode.SRC_OVER;
            int color = mScrimColor;
            color = Color.argb((int) (Color.alpha(color) * mViewAlpha), Color.red(color),
                    Color.green(color), Color.blue(color));
            int color = getScrimColorWithAlpha();
            if (!mHasExcludedArea) {
                canvas.drawColor(color, mode);
            } else {
@@ -106,6 +105,13 @@ public class ScrimView extends View
        }
    }

    public int getScrimColorWithAlpha() {
        int color = mScrimColor;
        color = Color.argb((int) (Color.alpha(color) * mViewAlpha), Color.red(color),
                Color.green(color), Color.blue(color));
        return color;
    }

    public void setDrawAsSrc(boolean asSrc) {
        mDrawAsSrc = asSrc;
        mPaint.setXfermode(new PorterDuffXfermode(mDrawAsSrc ? PorterDuff.Mode.SRC
@@ -118,6 +124,9 @@ public class ScrimView extends View
            mIsEmpty = Color.alpha(color) == 0;
            mScrimColor = color;
            invalidate();
            if (mChangeRunnable != null) {
                mChangeRunnable.run();
            }
        }
    }

@@ -134,8 +143,13 @@ public class ScrimView extends View
        if (mAlphaAnimator != null) {
            mAlphaAnimator.cancel();
        }
        if (alpha != mViewAlpha) {
            mViewAlpha = alpha;
            invalidate();
            if (mChangeRunnable != null) {
                mChangeRunnable.run();
            }
        }
    }

    public void animateViewAlpha(float alpha, long durationOut, Interpolator interpolator) {
@@ -164,4 +178,8 @@ public class ScrimView extends View
        mHasExcludedArea = area.left < area.right && area.top < area.bottom;
        invalidate();
    }

    public void setChangeRunnable(Runnable changeRunnable) {
        mChangeRunnable = changeRunnable;
    }
}
+3 −3
Original line number Diff line number Diff line
@@ -3742,7 +3742,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
        mNotificationPanel.setBarState(mState, mKeyguardFadingAway, goingToFullShade);
        updateDozingState();
        updatePublicMode();
        updateStackScrollerState(goingToFullShade);
        updateStackScrollerState(goingToFullShade, fromShadeLocked);
        updateNotifications();
        checkBarModes();
        updateMediaMetaData(false);
@@ -3763,11 +3763,11 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
                        != FingerprintUnlockController.MODE_WAKE_AND_UNLOCK_PULSING, animate);
    }

    public void updateStackScrollerState(boolean goingToFullShade) {
    public void updateStackScrollerState(boolean goingToFullShade, boolean fromShadeLocked) {
        if (mStackScroller == null) return;
        boolean onKeyguard = mState == StatusBarState.KEYGUARD;
        mStackScroller.setHideSensitive(isLockscreenPublicMode(), goingToFullShade);
        mStackScroller.setDimmed(onKeyguard, false /* animate */);
        mStackScroller.setDimmed(onKeyguard, fromShadeLocked /* animate */);
        mStackScroller.setExpandingEnabled(!onKeyguard);
        ActivatableNotificationView activatedChild = mStackScroller.getActivatedChild();
        mStackScroller.setActivatedChild(null);
Loading