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

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

Improved the messaging transformation

The messaging layout now transforms smoothly between
the different views.

Test: manual, send messages really fast, expand, collapse
Bug: 63708826
Change-Id: I79da4092eb03fb41a1963b566602386b25141192
parent d3809996
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Pools;
import android.view.Gravity;
@@ -61,6 +62,7 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
    private Icon mAvatarIcon;
    private ColorFilter mMessageBackgroundFilter;
    private int mTextColor;
    private List<MessagingMessage> mMessages;
    private ArrayList<MessagingMessage> mAddedMessages = new ArrayList<>();
    private boolean mFirstLayout;
    private boolean mIsHidingAnimated;
@@ -323,6 +325,7 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
            }
            message.setTextColor(mTextColor);
        }
        mMessages = group;
    }

    @Override
@@ -351,6 +354,31 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
        mFirstLayout = false;
    }

    /**
     * Calculates the group compatibility between this and another group.
     *
     * @param otherGroup the other group to compare it with
     *
     * @return 0 if the groups are totally incompatible or 1 + the number of matching messages if
     *         they match.
     */
    public int calculateGroupCompatibility(MessagingGroup otherGroup) {
        if (TextUtils.equals(getSenderName(),otherGroup.getSenderName())) {
            int result = 1;
            for (int i = 0; i < mMessages.size() && i < otherGroup.mMessages.size(); i++) {
                MessagingMessage ownMessage = mMessages.get(mMessages.size() - 1 - i);
                MessagingMessage otherMessage = otherGroup.mMessages.get(
                        otherGroup.mMessages.size() - 1 - i);
                if (!ownMessage.sameAs(otherMessage)) {
                    return result;
                }
                result++;
            }
            return result;
        }
        return 0;
    }

    public View getSender() {
        return mSenderName;
    }
@@ -358,4 +386,8 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
    public View getAvatar() {
        return mAvatarView;
    }

    public MessagingLinearLayout getMessageContainer() {
        return mMessageContainer;
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -104,6 +104,7 @@ public class MessagingLayout extends FrameLayout {
    protected void onFinishInflate() {
        super.onFinishInflate();
        mMessagingLinearLayout = findViewById(R.id.notification_messaging);
        mMessagingLinearLayout.setMessagingLayout(this);
        // We still want to clip, but only on the top, since views can temporarily out of bounds
        // during transitions.
        DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
@@ -436,4 +437,8 @@ public class MessagingLayout extends FrameLayout {
    public MessagingLinearLayout getMessagingLinearLayout() {
        return mMessagingLinearLayout;
    }

    public ArrayList<MessagingGroup> getMessagingGroups() {
        return mGroups;
    }
}
+9 −0
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ public class MessagingLinearLayout extends ViewGroup {
     * {@link #NOT_MEASURED_BEFORE} if this is the first layout pass.
     */
    private int mLastMeasuredWidth = NOT_MEASURED_BEFORE;
    private MessagingLayout mMessagingLayout;

    public MessagingLinearLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
@@ -258,6 +259,14 @@ public class MessagingLinearLayout extends ViewGroup {
        mMaxDisplayedLines = numberLines;
    }

    public void setMessagingLayout(MessagingLayout layout) {
        mMessagingLayout = layout;
    }

    public MessagingLayout getMessagingLayout() {
        return mMessagingLayout;
    }

    public interface MessagingChild {
        int MEASURED_NORMAL = 0;
        int MEASURED_SHORTENED = 1;
+4 −0
Original line number Diff line number Diff line
@@ -88,6 +88,10 @@ public class MessagingMessage extends ImageFloatingTextView implements
        return true;
    }

    boolean sameAs(MessagingMessage message) {
        return sameAs(message.getMessage());
    }

    static MessagingMessage createMessage(MessagingLayout layout,
            Notification.MessagingStyle.Message m) {
        MessagingLinearLayout messagingLinearLayout = layout.getMessagingLinearLayout();
+10 −3
Original line number Diff line number Diff line
@@ -35,7 +35,8 @@ import java.util.Stack;
/**
 * A view that can be transformed to and from.
 */
public class ViewTransformationHelper implements TransformableView {
public class ViewTransformationHelper implements TransformableView,
        TransformState.TransformInfo {

    private static final int TAG_CONTAINS_TRANSFORMED_VIEW = R.id.contains_transformed_view;

@@ -59,7 +60,7 @@ 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);
            return TransformState.createFrom(view, this);
        }
        return null;
    }
@@ -88,6 +89,7 @@ public class ViewTransformationHelper implements TransformableView {
                        endRunnable.run();
                    }
                    setVisible(false);
                    mViewTransformationAnimation = null;
                } else {
                    abortTransformations();
                }
@@ -245,7 +247,7 @@ public class ViewTransformationHelper implements TransformableView {
    }

    public void resetTransformedView(View view) {
        TransformState state = TransformState.createFrom(view);
        TransformState state = TransformState.createFrom(view, this);
        state.setVisible(true /* visible */, true /* force */);
        state.recycle();
    }
@@ -257,6 +259,11 @@ public class ViewTransformationHelper implements TransformableView {
        return new ArraySet<>(mTransformedViews.values());
    }

    @Override
    public boolean isAnimating() {
        return mViewTransformationAnimation != null && mViewTransformationAnimation.isRunning();
    }

    public static abstract class CustomTransformation {
        /**
         * Transform a state to the given view
Loading