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

Commit 6811d728 authored by Selim Cinek's avatar Selim Cinek
Browse files

Drawing the background of the notifications as a grey color now

Some cases are still not working perfectly as the background is
never animating

Change-Id: I4b357161d53d62f4cf5c0fbf76e70e5f3465bd68
parent c18010f6
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -83,9 +83,8 @@
    <!-- The color of the material notification background when low priority -->
    <color name="notification_material_background_low_priority_color">#fff5f5f5</color>

    <!-- The color of the material notification background for media notifications when no custom
         color is specified -->
    <color name="notification_material_background_media_default_color">#ff424242</color>
    <!-- The background color of the notification shade -->
    <color name="notification_shade_background_color">#fff9f9f9</color>

    <!-- The color of the ripples on the untinted notifications -->
    <color name="notification_ripple_untinted_color">#28000000</color>
+1 −1
Original line number Diff line number Diff line
@@ -302,7 +302,7 @@
    <dimen name="z_distance_between_notifications">1dp</dimen>

    <!-- The padding between the individual notification cards. -->
    <dimen name="notification_padding">2dp</dimen>
    <dimen name="notification_padding">0.5dp</dimen>

    <!-- The minimum amount of top overscroll to go to the quick settings. -->
    <dimen name="min_top_overscroll_to_qs">36dp</dimen>
+45 −1
Original line number Diff line number Diff line
@@ -22,7 +22,10 @@ import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.Interpolator;
@@ -32,11 +35,14 @@ import android.view.animation.Interpolator;
 */
public class ScrimView extends View
{
    private final Paint mPaint = new Paint();
    private int mScrimColor;
    private boolean mIsEmpty = true;
    private boolean mDrawAsSrc;
    private float mViewAlpha = 1.0f;
    private ValueAnimator mAlphaAnimator;
    private Rect mExcludedRect = new Rect();
    private boolean mHasExcludedArea;
    private ValueAnimator.AnimatorUpdateListener mAlphaUpdateListener
            = new ValueAnimator.AnimatorUpdateListener() {
        @Override
@@ -75,12 +81,35 @@ public class ScrimView extends View
            int color = mScrimColor;
            color = Color.argb((int) (Color.alpha(color) * mViewAlpha), Color.red(color),
                    Color.green(color), Color.blue(color));
            if (!mHasExcludedArea) {
                canvas.drawColor(color, mode);
            } else {
                mPaint.setColor(color);
                if (mExcludedRect.top > 0) {
                    canvas.drawRect(0, 0, getWidth(), mExcludedRect.top, mPaint);
                }
                if (mExcludedRect.left > 0) {
                    canvas.drawRect(0,  mExcludedRect.top, mExcludedRect.left, mExcludedRect.bottom,
                            mPaint);
                }
                if (mExcludedRect.right < getWidth()) {
                    canvas.drawRect(mExcludedRect.right,
                            mExcludedRect.top,
                            getWidth(),
                            mExcludedRect.bottom,
                            mPaint);
                }
                if (mExcludedRect.bottom < getHeight()) {
                    canvas.drawRect(0,  mExcludedRect.bottom, getWidth(), getHeight(), mPaint);
                }
            }
        }
    }

    public void setDrawAsSrc(boolean asSrc) {
        mDrawAsSrc = asSrc;
        mPaint.setXfermode(new PorterDuffXfermode(mDrawAsSrc ? PorterDuff.Mode.SRC
                : PorterDuff.Mode.SRC_OVER));
        invalidate();
    }

@@ -120,4 +149,19 @@ public class ScrimView extends View
        mAlphaAnimator.setDuration(durationOut);
        mAlphaAnimator.start();
    }

    public void setExcludedArea(Rect area) {
        if (area == null) {
            mHasExcludedArea = false;
            invalidate();
            return;
        }
        area.left = Math.max(area.left, 0);
        area.top = Math.max(area.top, 0);
        area.right = Math.min(area.right, getWidth());
        area.bottom = Math.min(area.bottom, getHeight());
        mExcludedRect.set(area);
        mHasExcludedArea = area.left < area.right && area.top < area.bottom;
        invalidate();
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.animation.PropertyValuesHolder;
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Rect;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.animation.DecelerateInterpolator;
@@ -497,4 +498,8 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener,
    public void dontAnimateBouncerChangesUntilNextFrame() {
        mDontAnimateBouncerChanges = true;
    }

    public void setExcludedBackgroundArea(Rect area) {
        mScrimBehind.setExcludedArea(area);
    }
}
+120 −1
Original line number Diff line number Diff line
@@ -22,6 +22,10 @@ import android.content.res.Configuration;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PointF;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Pair;
@@ -228,6 +232,18 @@ public class NotificationStackScrollLayout extends ViewGroup
    private NotificationOverflowContainer mOverflowContainer;
    private final ArrayList<Pair<ExpandableNotificationRow, Boolean>> mTmpList = new ArrayList<>();
    private FalsingManager mFalsingManager;
    private ColorDrawable mBackground;
    private boolean mAnimationRunning;
    private ViewTreeObserver.OnPreDrawListener mBackgroundUpdater
            = new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            updateBackground();
            return true;
        }
    };
    private Rect mBackgroundBounds = new Rect();
    private Rect mCurrentBounds = null;

    public NotificationStackScrollLayout(Context context) {
        this(context, null);
@@ -244,6 +260,9 @@ public class NotificationStackScrollLayout extends ViewGroup
    public NotificationStackScrollLayout(Context context, AttributeSet attrs, int defStyleAttr,
            int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        mBackground = new ColorDrawable(context.getColor(
                R.color.notification_shade_background_color));
        mBackground.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
        int minHeight = getResources().getDimensionPixelSize(R.dimen.notification_min_height);
        int maxHeight = getResources().getDimensionPixelSize(R.dimen.notification_max_height);
        mExpandHelper = new ExpandHelper(getContext(), this,
@@ -255,8 +274,8 @@ public class NotificationStackScrollLayout extends ViewGroup
        mSwipeHelper.setLongPressListener(mLongPressListener);
        mStackScrollAlgorithm = new StackScrollAlgorithm(context);
        initView(context);
        if (DEBUG) {
        setWillNotDraw(false);
        if (DEBUG) {
            mDebugPaint = new Paint();
            mDebugPaint.setColor(0xffff0000);
            mDebugPaint.setStrokeWidth(2);
@@ -267,6 +286,7 @@ public class NotificationStackScrollLayout extends ViewGroup

    @Override
    protected void onDraw(Canvas canvas) {
        mBackground.draw(canvas);
        if (DEBUG) {
            int y = mTopPadding;
            canvas.drawLine(0, y, getWidth(), y, mDebugPaint);
@@ -1390,6 +1410,82 @@ public class NotificationStackScrollLayout extends ViewGroup
        mContentHeight = height + mTopPadding;
    }

    private void updateBackground() {
        if (mAmbientState.isDark()) {
            return;
        }
        updateBackgroundBounds();
        if (!mCurrentBounds.equals(mBackgroundBounds)) {
            mCurrentBounds.set(mBackgroundBounds);
            mScrimController.setExcludedBackgroundArea(mCurrentBounds);
            mBackground.setBounds(0, mCurrentBounds.top, getWidth(), mCurrentBounds.bottom);
            invalidate();
        }
    }

    /**
     * Update the background bounds to the new desired bounds
     */
    private void updateBackgroundBounds() {
        ActivatableNotificationView firstView = getFirstViewWithBackground();
        int top = 0;
        if (firstView != null) {
            int finalTranslationY = (int) StackStateAnimator.getFinalTranslationY(firstView);
            if (mBackgroundBounds.top == finalTranslationY) {
                // we're ending up at the same location as we are now, lets just skip the animation
                top = finalTranslationY;
            } else {
                top = (int) firstView.getTranslationY();
            }
        }
        ActivatableNotificationView lastView = getLastViewWithBackground();
        int bottom = 0;
        if (lastView != null) {
            int finalTranslationY = (int) StackStateAnimator.getFinalTranslationY(lastView);
            int finalHeight = StackStateAnimator.getFinalActualHeight(lastView);
            int finalBottom = finalTranslationY + finalHeight;
            finalBottom = Math.min(finalBottom, getHeight());
            if (mBackgroundBounds.bottom == finalBottom) {
                // we're ending up at the same location as we are now, lets just skip the animation
                bottom = finalBottom;
            } else {
                bottom = (int) (lastView.getTranslationY() + lastView.getActualHeight());
                bottom = Math.min(bottom, getHeight());
            }
        }
        mBackgroundBounds.top = top;
        mBackgroundBounds.bottom = bottom;
        mBackgroundBounds.left = (int) getX();
        mBackgroundBounds.right = (int) (getX() + getWidth());
        if (mCurrentBounds == null) {
            mCurrentBounds = new Rect(mBackgroundBounds);
        }
    }

    private ActivatableNotificationView getLastViewWithBackground() {
        int childCount = getChildCount();
        for (int i = childCount - 1; i >= 0; i--) {
            View child = getChildAt(i);
            if (child.getVisibility() != View.GONE
                    && child instanceof ActivatableNotificationView) {
                return (ActivatableNotificationView) child;
            }
        }
        return null;
    }

    private ActivatableNotificationView getFirstViewWithBackground() {
        int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            View child = getChildAt(i);
            if (child.getVisibility() != View.GONE
                    && child instanceof ActivatableNotificationView) {
                return (ActivatableNotificationView) child;
            }
        }
        return null;
    }

    /**
     * Fling the scroll view
     *
@@ -1866,9 +1962,11 @@ public class NotificationStackScrollLayout extends ViewGroup
            mNeedsAnimation = false;
        }
        if (!mAnimationEvents.isEmpty() || isCurrentlyAnimating()) {
            setAnimationRunning(true);
            mStateAnimator.startAnimationForEvents(mAnimationEvents, mCurrentStackScrollState,
                    mGoToFullShadeDelay);
            mAnimationEvents.clear();
            updateBackground();
        } else {
            applyCurrentState();
        }
@@ -2354,6 +2452,7 @@ public class NotificationStackScrollLayout extends ViewGroup
    }

    public void onChildAnimationFinished() {
        setAnimationRunning(false);
        requestChildrenUpdate();
        runAnimationFinishedRunnables();
        clearViewOverlays();
@@ -2422,6 +2521,7 @@ public class NotificationStackScrollLayout extends ViewGroup
            mListener.onChildLocationsChanged(this);
        }
        runAnimationFinishedRunnables();
        updateBackground();
    }

    public void goToFullShade(long delay) {
@@ -2468,6 +2568,14 @@ public class NotificationStackScrollLayout extends ViewGroup
            mNeedsAnimation =  true;
        }
        requestChildrenUpdate();
        if (dark) {
            setWillNotDraw(!DEBUG);
            mScrimController.setExcludedBackgroundArea(null);
        } else {
            updateBackground();
            setWillNotDraw(false);
            // TODO: fade in background
        }
    }

    private int findDarkAnimationOriginIndex(@Nullable PointF screenLocation) {
@@ -2827,6 +2935,17 @@ public class NotificationStackScrollLayout extends ViewGroup
        return !mForceNoOverlappingRendering && super.hasOverlappingRendering();
    }

    public void setAnimationRunning(boolean animationRunning) {
        if (animationRunning != mAnimationRunning) {
            if (animationRunning) {
                getViewTreeObserver().addOnPreDrawListener(mBackgroundUpdater);
            } else {
                getViewTreeObserver().removeOnPreDrawListener(mBackgroundUpdater);
            }
            mAnimationRunning = animationRunning;
        }
    }

    /**
     * A listener that is notified when some child locations might have changed.
     */
Loading