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

Commit 599be34e authored by Adrian Roos's avatar Adrian Roos
Browse files

Improve action bar transition

Improves the transition of the action bar between
the collapsed and expanded states.

Bug: 28935363
Change-Id: I89efe95aa045d04bab4208a001f82cb69b38fce5
parent e82ac10f
Loading
Loading
Loading
Loading
+7 −0
Original line number Original line Diff line number Diff line
@@ -193,6 +193,13 @@ public class ExpandableNotificationRow extends ActivatableNotificationView {
        mGroupExpansionChanging = changing;
        mGroupExpansionChanging = changing;
    }
    }


    @Override
    public void setActualHeightAnimating(boolean animating) {
        if (mPrivateLayout != null) {
            mPrivateLayout.setContentHeightAnimating(animating);
        }
    }

    public NotificationContentView getPrivateLayout() {
    public NotificationContentView getPrivateLayout() {
        return mPrivateLayout;
        return mPrivateLayout;
    }
    }
+2 −0
Original line number Original line Diff line number Diff line
@@ -432,6 +432,8 @@ public abstract class ExpandableView extends FrameLayout {
        return false;
        return false;
    }
    }


    public void setActualHeightAnimating(boolean animating) {}

    /**
    /**
     * A listener notifying when {@link #getActualHeight} changes.
     * A listener notifying when {@link #getActualHeight} changes.
     */
     */
+55 −4
Original line number Original line Diff line number Diff line
@@ -106,13 +106,19 @@ public class NotificationContentView extends FrameLayout {
    private boolean mExpandable;
    private boolean mExpandable;
    private boolean mClipToActualHeight = true;
    private boolean mClipToActualHeight = true;
    private ExpandableNotificationRow mContainingNotification;
    private ExpandableNotificationRow mContainingNotification;
    /** The visible type at the start of a touch driven transformation */
    private int mTransformationStartVisibleType;
    private int mTransformationStartVisibleType;
    /** The visible type at the start of an animation driven transformation */
    private int mAnimationStartVisibleType = UNDEFINED;
    private boolean mUserExpanding;
    private boolean mUserExpanding;
    private int mSingleLineWidthIndention;
    private int mSingleLineWidthIndention;
    private boolean mForceSelectNextLayout = true;
    private boolean mForceSelectNextLayout = true;
    private PendingIntent mPreviousExpandedRemoteInputIntent;
    private PendingIntent mPreviousExpandedRemoteInputIntent;
    private PendingIntent mPreviousHeadsUpRemoteInputIntent;
    private PendingIntent mPreviousHeadsUpRemoteInputIntent;


    private int mContentHeightAtAnimationStart = UNDEFINED;


    public NotificationContentView(Context context, AttributeSet attrs) {
    public NotificationContentView(Context context, AttributeSet attrs) {
        super(context, attrs);
        super(context, attrs);
        mHybridGroupManager = new HybridGroupManager(getContext(), this);
        mHybridGroupManager = new HybridGroupManager(getContext(), this);
@@ -258,7 +264,14 @@ public class NotificationContentView extends FrameLayout {


    @Override
    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        int previousHeight = 0;
        if (mExpandedChild != null) {
            previousHeight = mExpandedChild.getHeight();
        }
        super.onLayout(changed, left, top, right, bottom);
        super.onLayout(changed, left, top, right, bottom);
        if (previousHeight != 0 && mExpandedChild.getHeight() != previousHeight) {
            mContentHeightAtAnimationStart = previousHeight;
        }
        updateClipping();
        updateClipping();
        invalidateOutline();
        invalidateOutline();
        selectLayout(false /* animate */, mForceSelectNextLayout /* force */);
        selectLayout(false /* animate */, mForceSelectNextLayout /* force */);
@@ -408,24 +421,54 @@ public class NotificationContentView extends FrameLayout {
     *         height, the notification is clipped instead of being further shrunk.
     *         height, the notification is clipped instead of being further shrunk.
     */
     */
    private int getMinContentHeightHint() {
    private int getMinContentHeightHint() {
        if (mIsChildInGroup && (mVisibleType == VISIBLE_TYPE_SINGLELINE
        if (mIsChildInGroup && isVisibleOrTransitioning(VISIBLE_TYPE_SINGLELINE)) {
                || mTransformationStartVisibleType == VISIBLE_TYPE_SINGLELINE)) {
            return mContext.getResources().getDimensionPixelSize(
            return mContext.getResources().getDimensionPixelSize(
                        com.android.internal.R.dimen.notification_action_list_height);
                        com.android.internal.R.dimen.notification_action_list_height);
        }
        }

        // Transition between heads-up & expanded, or pinned.
        if (mHeadsUpChild != null && mExpandedChild != null) {
            boolean transitioningBetweenHunAndExpanded =
                    isTransitioningFromTo(VISIBLE_TYPE_HEADSUP, VISIBLE_TYPE_EXPANDED) ||
                    isTransitioningFromTo(VISIBLE_TYPE_EXPANDED, VISIBLE_TYPE_HEADSUP);
            boolean pinned = !isVisibleOrTransitioning(VISIBLE_TYPE_CONTRACTED) && mIsHeadsUp;
            if (transitioningBetweenHunAndExpanded || pinned) {
                return Math.min(mHeadsUpChild.getHeight(), mExpandedChild.getHeight());
            }
        }

        // Size change of the expanded version
        if ((mVisibleType == VISIBLE_TYPE_EXPANDED) && mContentHeightAtAnimationStart >= 0
                && mExpandedChild != null) {
            return Math.min(mContentHeightAtAnimationStart, mExpandedChild.getHeight());
        }

        int hint;
        int hint;
        if (mHeadsUpChild != null) {
        if (mHeadsUpChild != null && isVisibleOrTransitioning(VISIBLE_TYPE_HEADSUP)) {
            hint = mHeadsUpChild.getHeight();
            hint = mHeadsUpChild.getHeight();
        } else if (mExpandedChild != null) {
            hint = mExpandedChild.getHeight();
        } else {
        } else {
            hint = mContractedChild.getHeight() + mContext.getResources().getDimensionPixelSize(
            hint = mContractedChild.getHeight() + mContext.getResources().getDimensionPixelSize(
                    com.android.internal.R.dimen.notification_action_list_height);
                    com.android.internal.R.dimen.notification_action_list_height);
        }
        }
        if (mExpandedChild != null) {

        if (mExpandedChild != null && isVisibleOrTransitioning(VISIBLE_TYPE_EXPANDED)) {
            hint = Math.min(hint, mExpandedChild.getHeight());
            hint = Math.min(hint, mExpandedChild.getHeight());
        }
        }
        return hint;
        return hint;
    }
    }


    private boolean isTransitioningFromTo(int from, int to) {
        return (mTransformationStartVisibleType == from || mAnimationStartVisibleType == from)
                && mVisibleType == to;
    }

    private boolean isVisibleOrTransitioning(int type) {
        return mVisibleType == type || mTransformationStartVisibleType == type
                || mAnimationStartVisibleType == type;
    }

    private void updateContentTransformation() {
    private void updateContentTransformation() {
        int visibleType = calculateVisibleType();
        int visibleType = calculateVisibleType();
        if (visibleType != mVisibleType) {
        if (visibleType != mVisibleType) {
@@ -656,6 +699,7 @@ public class NotificationContentView extends FrameLayout {
            shownView.setVisible(true);
            shownView.setVisible(true);
            return;
            return;
        }
        }
        mAnimationStartVisibleType = mVisibleType;
        shownView.transformFrom(hiddenView);
        shownView.transformFrom(hiddenView);
        getViewForVisibleType(visibleType).setVisibility(View.VISIBLE);
        getViewForVisibleType(visibleType).setVisibility(View.VISIBLE);
        hiddenView.transformTo(shownView, new Runnable() {
        hiddenView.transformTo(shownView, new Runnable() {
@@ -664,6 +708,7 @@ public class NotificationContentView extends FrameLayout {
                if (hiddenView != getTransformableViewForVisibleType(mVisibleType)) {
                if (hiddenView != getTransformableViewForVisibleType(mVisibleType)) {
                    hiddenView.setVisible(false);
                    hiddenView.setVisible(false);
                }
                }
                mAnimationStartVisibleType = UNDEFINED;
            }
            }
        });
        });
    }
    }
@@ -1082,4 +1127,10 @@ public class NotificationContentView extends FrameLayout {
            mHeadsUpRemoteInput.setRemoved();
            mHeadsUpRemoteInput.setRemoved();
        }
        }
    }
    }

    public void setContentHeightAnimating(boolean animating) {
        if (!animating) {
            mContentHeightAtAnimationStart = UNDEFINED;
        }
    }
}
}
+10 −0
Original line number Original line Diff line number Diff line
@@ -43,6 +43,16 @@ public class ActionListTransformState extends TransformState {
        return new ActionListTransformState();
        return new ActionListTransformState();
    }
    }


    @Override
    public void transformViewFullyFrom(TransformState otherState, float transformationAmount) {
        // Don't do Y transform - let the wrapper handle this based on the content height
    }

    @Override
    public void transformViewFullyTo(TransformState otherState, float transformationAmount) {
        // Don't do Y transform - let the wrapper handle this based on the content height
    }

    @Override
    @Override
    protected void resetTransformedView() {
    protected void resetTransformedView() {
        // We need to keep the Y transformation, because this is used to keep the action list
        // We need to keep the Y transformation, because this is used to keep the action list
+2 −0
Original line number Original line Diff line number Diff line
@@ -485,6 +485,7 @@ public class StackStateAnimator {
                child.setTag(TAG_ANIMATOR_HEIGHT, null);
                child.setTag(TAG_ANIMATOR_HEIGHT, null);
                child.setTag(TAG_START_HEIGHT, null);
                child.setTag(TAG_START_HEIGHT, null);
                child.setTag(TAG_END_HEIGHT, null);
                child.setTag(TAG_END_HEIGHT, null);
                child.setActualHeightAnimating(false);
                if (!mWasCancelled && child instanceof ExpandableNotificationRow) {
                if (!mWasCancelled && child instanceof ExpandableNotificationRow) {
                    ((ExpandableNotificationRow) child).setGroupExpansionChanging(
                    ((ExpandableNotificationRow) child).setGroupExpansionChanging(
                            false /* isExpansionChanging */);
                            false /* isExpansionChanging */);
@@ -505,6 +506,7 @@ public class StackStateAnimator {
        child.setTag(TAG_ANIMATOR_HEIGHT, animator);
        child.setTag(TAG_ANIMATOR_HEIGHT, animator);
        child.setTag(TAG_START_HEIGHT, child.getActualHeight());
        child.setTag(TAG_START_HEIGHT, child.getActualHeight());
        child.setTag(TAG_END_HEIGHT, newEndValue);
        child.setTag(TAG_END_HEIGHT, newEndValue);
        child.setActualHeightAnimating(true);
    }
    }


    private void startInsetAnimation(final ExpandableView child,
    private void startInsetAnimation(final ExpandableView child,