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

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

Avoid overlap if expanding in the bottom stack

We are now scrolling slightly upwards if an expanding / collapsing
motion goes into the bottom stack to avoid overlapping with the
card above.

Bug: 15167388
Change-Id: I7a3ca3d80de0178de28e16b3cabe4b7ef35d933a
parent d2e2f0fb
Loading
Loading
Loading
Loading
+25 −6
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.animation.AnimationUtils;
import android.widget.OverScroller;
import android.widget.ScrollView;

import com.android.systemui.ExpandHelper;
import com.android.systemui.R;
@@ -172,6 +171,7 @@ public class NotificationStackScrollLayout extends ViewGroup
    private ViewGroup mScrollView;
    private boolean mInterceptDelegateEnabled;
    private boolean mDelegateToScrollView;
    private boolean mDisallowScrollingInThisMotion;

    private ViewTreeObserver.OnPreDrawListener mChildrenUpdater
            = new ViewTreeObserver.OnPreDrawListener() {
@@ -308,7 +308,7 @@ public class NotificationStackScrollLayout extends ViewGroup
        }
        setMaxLayoutHeight(getHeight());
        updateContentHeight();
        updateScrollPositionIfNecessary();
        clampScrollPosition();
        requestChildrenUpdate();
    }

@@ -390,7 +390,7 @@ public class NotificationStackScrollLayout extends ViewGroup
        return mStateAnimator.isRunning();
    }

    private void updateScrollPositionIfNecessary() {
    private void clampScrollPosition() {
        int scrollRange = getScrollRange();
        if (scrollRange < mOwnScrollY) {
            mOwnScrollY = scrollRange;
@@ -649,12 +649,13 @@ public class NotificationStackScrollLayout extends ViewGroup
            }
            boolean wasExpandingBefore = mExpandingNotification;
            expandWantsIt = mExpandHelper.onTouchEvent(ev);
            if (mExpandedInThisMotion && !mExpandingNotification && wasExpandingBefore) {
            if (mExpandedInThisMotion && !mExpandingNotification && wasExpandingBefore
                    && !mDisallowScrollingInThisMotion) {
                dispatchDownEventToScroller(ev);
            }
        }
        boolean scrollerWantsIt = false;
        if (!mSwipingInProgress && !mExpandingNotification) {
        if (!mSwipingInProgress && !mExpandingNotification && !mDisallowScrollingInThisMotion) {
            scrollerWantsIt = onScrollTouch(ev);
        }
        boolean horizontalSwipeWantsIt = false;
@@ -1399,6 +1400,7 @@ public class NotificationStackScrollLayout extends ViewGroup
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            mExpandedInThisMotion = false;
            mOnlyScrollingInThisMotion = !mScroller.isFinished();
            mDisallowScrollingInThisMotion = false;
        }
    }

@@ -1823,11 +1825,28 @@ public class NotificationStackScrollLayout extends ViewGroup
    @Override
    public void onHeightChanged(ExpandableView view) {
        updateContentHeight();
        updateScrollPositionIfNecessary();
        updateScrollPositionOnExpandInBottom(view);
        clampScrollPosition();
        notifyHeightChangeListener(view);
        requestChildrenUpdate();
    }

    private void updateScrollPositionOnExpandInBottom(ExpandableView view) {
        if (view instanceof ExpandableNotificationRow) {
            ExpandableNotificationRow row = (ExpandableNotificationRow) view;
            if (row.isUserLocked()) {
                // We are actually expanding this view
                float endPosition = row.getTranslationY() + row.getActualHeight();
                int stackEnd = mMaxLayoutHeight - mBottomStackPeekSize -
                        mBottomStackSlowDownHeight;
                if (endPosition > stackEnd) {
                    mOwnScrollY += endPosition - stackEnd;
                    mDisallowScrollingInThisMotion = true;
                }
            }
        }
    }

    public void setOnHeightChangedListener(
            ExpandableView.OnHeightChangedListener mOnHeightChangedListener) {
        this.mOnHeightChangedListener = mOnHeightChangedListener;