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

Commit 154f212c authored by Selim Cinek's avatar Selim Cinek
Browse files

Improved transitions for expanding messaging notifications

Views weren't transforming properly yet, we now are transforming
more.

Bug: 150905003
Test: visual, observe animations when expanding
Change-Id: Iee48926770f4fb9158aeaa14745049e7c24b4449
parent c2c276aa
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
    private boolean mImagesAtEnd;
    private ViewGroup mImageContainer;
    private MessagingImageMessage mIsolatedMessage;
    private boolean mTransformingImages;
    private boolean mClippingDisabled;
    private Point mDisplaySize = new Point();
    private ProgressBar mSendingSpinner;
    private View mSendingSpinnerContainer;
@@ -125,7 +125,7 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
        // We want to clip to the senderName if it's available, otherwise our images will come
        // from a weird position
        Rect clipRect;
        if (mSenderView.getVisibility() != View.GONE && !mTransformingImages) {
        if (mSenderView.getVisibility() != View.GONE && !mClippingDisabled) {
            int top;
            if (mSingleLine) {
                top = 0;
@@ -607,8 +607,8 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
        return mSender;
    }

    public void setTransformingImages(boolean transformingImages) {
        mTransformingImages = transformingImages;
    public void setClippingDisabled(boolean disabled) {
        mClippingDisabled = disabled;
    }

    public void setDisplayImagesAtEnd(boolean atEnd) {
@@ -640,4 +640,8 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
            updateSenderVisibility();
        }
    }

    public boolean isSingleLine() {
        return mSingleLine;
    }
}
+20 −1
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ public class ViewTransformationHelper implements TransformableView,
    private static final int TAG_CONTAINS_TRANSFORMED_VIEW = R.id.contains_transformed_view;

    private ArrayMap<Integer, View> mTransformedViews = new ArrayMap<>();
    private ArraySet<Integer> mKeysTransformingToSimilar = new ArraySet<>();
    private ArrayMap<Integer, CustomTransformation> mCustomTransformations = new ArrayMap<>();
    private ValueAnimator mViewTransformationAnimation;

@@ -48,8 +49,22 @@ public class ViewTransformationHelper implements TransformableView,
        mTransformedViews.put(key, transformedView);
    }

    /**
     * Add a view that transforms to a similar sibling, meaning that we should consider any mapping
     * found treated as the same viewType. This is useful for imageViews, where it's hard to compare
     * if the source images are the same when they are bitmap based.
     *
     * @param key The key how this is added
     * @param transformedView the view that is added
     */
    public void addViewTransformingToSimilar(int key, View transformedView) {
        addTransformedView(key, transformedView);
        mKeysTransformingToSimilar.add(key);
    }

    public void reset() {
        mTransformedViews.clear();
        mKeysTransformingToSimilar.clear();
    }

    public void setCustomTransformation(CustomTransformation transformation, int viewType) {
@@ -60,7 +75,11 @@ public class ViewTransformationHelper implements TransformableView,
    public TransformState getCurrentState(int fadingView) {
        View view = mTransformedViews.get(fadingView);
        if (view != null && view.getVisibility() != View.GONE) {
            return TransformState.createFrom(view, this);
            TransformState transformState = TransformState.createFrom(view, this);
            if (mKeysTransformingToSimilar.contains(fadingView)) {
                transformState.setIsSameAsAnyView(true);
            }
            return transformState;
        }
        return null;
    }
+28 −6
Original line number Diff line number Diff line
@@ -266,8 +266,9 @@ public class MessagingLayoutTransformState extends TransformState {
            transformView(transformationAmount, to, child, otherChild, false, /* sameAsAny */
                    useLinearTransformation);
            boolean otherIsIsolated = otherGroup.getIsolatedMessage() == otherChild;
            if (transformationAmount == 0.0f && otherIsIsolated) {
                ownGroup.setTransformingImages(true);
            if (transformationAmount == 0.0f
                    && (otherIsIsolated || otherGroup.isSingleLine())) {
                ownGroup.setClippingDisabled(true);
            }
            if (otherChild == null) {
                child.setTranslationY(previousTranslation);
@@ -291,11 +292,20 @@ public class MessagingLayoutTransformState extends TransformState {
        if (useLinearTransformation) {
            ownState.setDefaultInterpolator(Interpolators.LINEAR);
        }
        ownState.setIsSameAsAnyView(sameAsAny);
        ownState.setIsSameAsAnyView(sameAsAny && !isGone(otherView));
        if (to) {
            if (otherView != null) {
                TransformState otherState = TransformState.createFrom(otherView, mTransformInfo);
                if (!isGone(otherView)) {
                    ownState.transformViewTo(otherState, transformationAmount);
                } else {
                    if (!isGone(ownView)) {
                        ownState.disappear(transformationAmount, null);
                    }
                    // We still want to transform vertically if the view is gone,
                    // since avatars serve as anchors for the rest of the layout transition
                    ownState.transformViewVerticalTo(otherState, transformationAmount);
                }
                otherState.recycle();
            } else {
                ownState.disappear(transformationAmount, null);
@@ -303,7 +313,16 @@ public class MessagingLayoutTransformState extends TransformState {
        } else {
            if (otherView != null) {
                TransformState otherState = TransformState.createFrom(otherView, mTransformInfo);
                if (!isGone(otherView)) {
                    ownState.transformViewFrom(otherState, transformationAmount);
                } else {
                    if (!isGone(ownView)) {
                        ownState.appear(transformationAmount, null);
                    }
                    // We still want to transform vertically if the view is gone,
                    // since avatars serve as anchors for the rest of the layout transition
                    ownState.transformViewVerticalFrom(otherState, transformationAmount);
                }
                otherState.recycle();
            } else {
                ownState.appear(transformationAmount, null);
@@ -337,6 +356,9 @@ public class MessagingLayoutTransformState extends TransformState {
    }

    private boolean isGone(View view) {
        if (view == null) {
            return true;
        }
        if (view.getVisibility() == View.GONE) {
            return true;
        }
@@ -408,7 +430,7 @@ public class MessagingLayoutTransformState extends TransformState {
                ownGroup.getMessageContainer().setTranslationY(0);
                ownGroup.getSenderView().setTranslationY(0);
            }
            ownGroup.setTransformingImages(false);
            ownGroup.setClippingDisabled(false);
            ownGroup.updateClipRect();
        }
    }
+20 −3
Original line number Diff line number Diff line
@@ -37,6 +37,9 @@ class NotificationConversationTemplateViewWrapper constructor(

    private val minHeightWithActions: Int
    private val conversationLayout: ConversationLayout
    private var conversationIcon: View? = null
    private var conversationBadge: View? = null
    private var expandButton: View? = null
    private var messagingLinearLayout: MessagingLinearLayout? = null

    init {
@@ -47,6 +50,12 @@ class NotificationConversationTemplateViewWrapper constructor(

    private fun resolveViews() {
        messagingLinearLayout = conversationLayout.messagingLinearLayout
        conversationIcon = conversationLayout.requireViewById(
                com.android.internal.R.id.conversation_icon)
        conversationBadge = conversationLayout.requireViewById(
                com.android.internal.R.id.conversation_icon_badge)
        expandButton = conversationLayout.requireViewById(
                com.android.internal.R.id.expand_button)
    }

    override fun onContentUpdated(row: ExpandableNotificationRow) {
@@ -59,9 +68,17 @@ class NotificationConversationTemplateViewWrapper constructor(
    override fun updateTransformedTypes() {
        // This also clears the existing types
        super.updateTransformedTypes()
        if (messagingLinearLayout != null) {
            mTransformationHelper.addTransformedView(messagingLinearLayout!!.id,
                    messagingLinearLayout)
        messagingLinearLayout?.let {
            mTransformationHelper.addTransformedView(it.id, it)
        }
        conversationIcon?.let {
            mTransformationHelper.addViewTransformingToSimilar(it.id, it)
        }
        conversationBadge?.let {
            mTransformationHelper.addViewTransformingToSimilar(it.id, it)
        }
        expandButton?.let {
            mTransformationHelper.addViewTransformingToSimilar(it.id, it)
        }
    }