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

Commit 1b2a05eb authored by Selim Cinek's avatar Selim Cinek
Browse files

Fixed the animation when flinging over the bottom stack

The new approach is still not perfect but has way less artifacts.

Change-Id: I096d3823c5ede720bdf05558d68529e903dce5b5
Fixes: 27744811
parent d1395647
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ public class ExpandHelper implements Gefingerpoken {
        void setUserExpandedChild(View v, boolean userExpanded);
        void setUserLockedChild(View v, boolean userLocked);
        void expansionStateChanged(boolean isExpanding);
        int getMaxExpandHeight(ExpandableView view);
    }

    private static final String TAG = "ExpandHelper";
@@ -144,7 +145,7 @@ public class ExpandHelper implements Gefingerpoken {
            return mView.getActualHeight();
        }
        public int getNaturalHeight() {
            return mView.getMaxContentHeight();
            return mCallback.getMaxExpandHeight(mView);
        }
    }

+12 −1
Original line number Diff line number Diff line
@@ -156,6 +156,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {
            }
        }
    };
    private boolean mForceUnlocked;
    private boolean mDismissed;
    private boolean mKeepInParent;
    private boolean mRemoved;
@@ -645,6 +646,16 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {
        onChildrenCountChanged();
    }

    public void setForceUnlocked(boolean forceUnlocked) {
        mForceUnlocked = forceUnlocked;
        if (mIsSummaryWithChildren) {
            List<ExpandableNotificationRow> notificationChildren = getNotificationChildren();
            for (ExpandableNotificationRow child : notificationChildren) {
                child.setForceUnlocked(forceUnlocked);
            }
        }
    }

    public void setDismissed(boolean dismissed) {
        mDismissed = dismissed;
    }
@@ -1017,7 +1028,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {
    }

    public boolean isUserLocked() {
        return mUserLocked;
        return mUserLocked && !mForceUnlocked;
    }

    public void setUserLocked(boolean userLocked) {
+54 −12
Original line number Diff line number Diff line
@@ -330,6 +330,7 @@ public class NotificationStackScrollLayout extends ViewGroup
    private boolean mPulsing;
    private boolean mDrawBackgroundAsSrc;
    private boolean mFadedOut;
    private boolean mGroupExpandedForMeasure;

    public NotificationStackScrollLayout(Context context) {
        this(context, null);
@@ -929,6 +930,30 @@ public class NotificationStackScrollLayout extends ViewGroup
        }
    }

    @Override
    public int getMaxExpandHeight(ExpandableView view) {
        int maxContentHeight = view.getMaxContentHeight();
        if (view.isSummaryWithChildren()) {
            // Faking a measure with the group expanded to simulate how the group would look if
            // it was. Doing a calculation here would be highly non-trivial because of the
            // algorithm
            mGroupExpandedForMeasure = true;
            ExpandableNotificationRow row = (ExpandableNotificationRow) view;
            mGroupManager.toggleGroupExpansion(row.getStatusBarNotification());
            row.setForceUnlocked(true);
            mAmbientState.setLayoutHeight(mMaxLayoutHeight);
            mStackScrollAlgorithm.getStackScrollState(mAmbientState, mCurrentStackScrollState);
            mAmbientState.setLayoutHeight(getLayoutHeight());
            mGroupManager.toggleGroupExpansion(
                    row.getStatusBarNotification());
            mGroupExpandedForMeasure = false;
            row.setForceUnlocked(false);
            int height = mCurrentStackScrollState.getViewStateForView(view).height;
            return Math.min(height, maxContentHeight);
        }
        return maxContentHeight;
    }

    public void setScrollingEnabled(boolean enable) {
        mScrollingEnabled = enable;
    }
@@ -1547,6 +1572,24 @@ public class NotificationStackScrollLayout extends ViewGroup
        return null;
    }

    /**
     * @return the child before the given view which has visibility unequal to GONE
     */
    public ExpandableView getViewBeforeView(ExpandableView view) {
        ExpandableView previousView = null;
        int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            View child = getChildAt(i);
            if (child == view) {
                return previousView;
            }
            if (child.getVisibility() != View.GONE) {
                previousView = (ExpandableView) child;
            }
        }
        return null;
    }

    /**
     * @return The first child which has visibility unequal to GONE which is currently below the
     *         given translationY or equal to it.
@@ -1591,14 +1634,6 @@ public class NotificationStackScrollLayout extends ViewGroup
        return count;
    }

    private int getMaxExpandHeight(View view) {
        if (view instanceof ExpandableNotificationRow) {
            ExpandableNotificationRow row = (ExpandableNotificationRow) view;
            return row.getIntrinsicHeight();
        }
        return view.getHeight();
    }

    public int getContentHeight() {
        return mContentHeight;
    }
@@ -2867,8 +2902,7 @@ public class NotificationStackScrollLayout extends ViewGroup
                if (row.isChildInGroup()) {
                    endPosition += row.getNotificationParent().getTranslationY();
                }
                int stackEnd = mMaxLayoutHeight - mBottomStackPeekSize -
                        mBottomStackSlowDownHeight + (int) mStackTranslation;
                int stackEnd = getStackEndPosition();
                if (endPosition > stackEnd) {
                    mOwnScrollY += endPosition - stackEnd;
                    mDisallowScrollingInThisMotion = true;
@@ -2877,6 +2911,11 @@ public class NotificationStackScrollLayout extends ViewGroup
        }
    }

    private int getStackEndPosition() {
        return mMaxLayoutHeight - mBottomStackPeekSize - mBottomStackSlowDownHeight
                + mPaddingBetweenElements + (int) mStackTranslation;
    }

    public void setOnHeightChangedListener(
            ExpandableView.OnHeightChangedListener mOnHeightChangedListener) {
        this.mOnHeightChangedListener = mOnHeightChangedListener;
@@ -3357,14 +3396,17 @@ public class NotificationStackScrollLayout extends ViewGroup

    @Override
    public void onGroupExpansionChanged(ExpandableNotificationRow changedRow, boolean expanded) {
        boolean animated = mAnimationsEnabled && (mIsExpanded || changedRow.isPinned());
        boolean animated = !mGroupExpandedForMeasure && mAnimationsEnabled
                && (mIsExpanded || changedRow.isPinned());
        if (animated) {
            mExpandedGroupView = changedRow;
            mNeedsAnimation = true;
        }
        changedRow.setChildrenExpanded(expanded, animated);
        if (!mGroupExpandedForMeasure) {
            onHeightChanged(changedRow, false /* needsAnimation */);
        }
    }

    @Override
    public void onGroupCreatedFromChildren(NotificationGroupManager.NotificationGroup group) {