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

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

Improved the logic for notification clipping

Views are now still clipped during animations
but just on the right size.

Change-Id: I25e7d6dd67c9fcdb3a2c743048f9e83c840d837e
parent 25fd4e2b
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -41,6 +41,8 @@ public abstract class ExpandableView extends FrameLayout {
    private boolean mActualHeightInitialized;
    private boolean mDark;
    private ArrayList<View> mMatchParentViews = new ArrayList<View>();
    private int mClipTopOptimization;
    private static Rect mClipRect = new Rect();

    public ExpandableView(Context context, AttributeSet attrs) {
        super(context, attrs);
@@ -141,6 +143,7 @@ public abstract class ExpandableView extends FrameLayout {
    public void setActualHeight(int actualHeight, boolean notifyListeners) {
        mActualHeightInitialized = true;
        mActualHeight = actualHeight;
        updateClipping();
        if (notifyListeners) {
            notifyHeightChanged();
        }
@@ -299,6 +302,26 @@ public abstract class ExpandableView extends FrameLayout {
        outRect.top += getTranslationY() + getClipTopAmount();
    }

    private void updateClipping() {
        mClipRect.set(0, mClipTopOptimization, getWidth(), getActualHeight());
        setClipBounds(mClipRect);
    }

    public int getClipTopOptimization() {
        return mClipTopOptimization;
    }

    /**
     * Set that the view will be clipped by a given amount from the top. Contrary to
     * {@link #setClipTopAmount} this amount doesn't effect shadows and the background.
     *
     * @param clipTopOptimization the amount to clip from the top
     */
    public void setClipTopOptimization(int clipTopOptimization) {
        mClipTopOptimization = clipTopOptimization;
        updateClipping();
    }

    /**
     * A listener notifying when {@link #getActualHeight} changes.
     */
+15 −2
Original line number Diff line number Diff line
@@ -723,7 +723,6 @@ public class NotificationStackScrollLayout extends ViewGroup
    }

    public void dismissViewAnimated(View child, Runnable endRunnable, int delay, long duration) {
        child.setClipBounds(null);
        mSwipeHelper.dismissChild(child, 0, endRunnable, delay, true, duration);
    }

@@ -1566,7 +1565,7 @@ public class NotificationStackScrollLayout extends ViewGroup
        updateAnimationState(false, child);

        // Make sure the clipRect we might have set is removed
        child.setClipBounds(null);
        ((ExpandableView) child).setClipTopOptimization(0);
    }

    /**
@@ -2343,6 +2342,20 @@ public class NotificationStackScrollLayout extends ViewGroup
    public void setDismissAllInProgress(boolean dismissAllInProgress) {
        mDismissAllInProgress = dismissAllInProgress;
        mDismissView.setDismissAllInProgress(dismissAllInProgress);
        if (dismissAllInProgress) {
            disableClipOptimization();
        }
    }

    private void disableClipOptimization() {
        final int count = getChildCount();
        for (int i = 0; i < count; i++) {
            ExpandableView child = (ExpandableView) getChildAt(i);
            if (child.getVisibility() == GONE) {
                continue;
            }
            child.setClipTopOptimization(0);
        }
    }

    public boolean isDismissViewNotGone() {
+4 −18
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.systemui.statusbar.stack;

import android.graphics.Rect;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
@@ -40,7 +39,6 @@ public class StackScrollState {

    private final ViewGroup mHostView;
    private Map<ExpandableView, StackViewState> mStateMap;
    private final Rect mClipRect = new Rect();
    private final int mClearAllTopPadding;

    public StackScrollState(ViewGroup hostView) {
@@ -152,7 +150,10 @@ public class StackScrollState {
        if (oldClipTopAmount != state.clipTopAmount) {
            view.setClipTopAmount(state.clipTopAmount);
        }
        updateChildClip(view, newHeight, state.topOverLap);
        float oldClipTopOptimization = view.getClipTopOptimization();
        if (oldClipTopOptimization != state.topOverLap) {
            view.setClipTopOptimization(state.topOverLap);
        }
        return true;
    }

@@ -211,21 +212,6 @@ public class StackScrollState {
        }
    }

    /**
     * Updates the clipping of a view
     *
     * @param child the view to update
     * @param height the currently applied height of the view
     * @param clipInset how much should this view be clipped from the top
     */
    private void updateChildClip(View child, int height, int clipInset) {
        mClipRect.set(0,
                clipInset,
                child.getWidth(),
                height);
        child.setClipBounds(mClipRect);
    }

    public void performSpeedBumpAnimation(int i, SpeedBumpView speedBump, StackViewState state,
            long delay) {
        View nextChild = getNextChildNotGone(i);
+1 −1
Original line number Diff line number Diff line
@@ -118,7 +118,7 @@ public class StackStateAnimator {
                continue;
            }

            child.setClipBounds(null);
            child.setClipTopOptimization(0);
            startStackAnimations(child, viewState, finalState, i, -1 /* fixedDelay */);
        }
        if (!isRunning()) {