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

Commit 54fe9ad2 authored by Selim Cinek's avatar Selim Cinek
Browse files

Made the expand button positioning conditional on expanded state

The expand button now allows content to flow below the header
when expanded and is dynamically placed in the layout
to push over the content.
Also made sure that match parent views don't artificially
increase the size of RemeasurableLinearLayouts as otherwise
the content would be stuck too big at times.

Bug: 150905003
Test: Visual, observe expand buttons when expanded / collapsed
Change-Id: I933b8a74ab6cacd48c98b1a9667b0e30c82bda11
parent 857f279d
Loading
Loading
Loading
Loading
+23 −0
Original line number Original line Diff line number Diff line
@@ -107,6 +107,7 @@ public class ConversationLayout extends FrameLayout
    private View mConversationIconBadge;
    private View mConversationIconBadge;
    private Icon mLargeIcon;
    private Icon mLargeIcon;
    private View mExpandButtonContainer;
    private View mExpandButtonContainer;
    private ViewGroup mExpandButtonAndContentContainer;
    private NotificationExpandButton mExpandButton;
    private NotificationExpandButton mExpandButton;
    private int mExpandButtonExpandedTopMargin;
    private int mExpandButtonExpandedTopMargin;
    private int mBadgedSideMargins;
    private int mBadgedSideMargins;
@@ -114,6 +115,7 @@ public class ConversationLayout extends FrameLayout
    private int mIconSizeCentered;
    private int mIconSizeCentered;
    private View mIcon;
    private View mIcon;
    private int mExpandedGroupTopMargin;
    private int mExpandedGroupTopMargin;
    private int mExpandButtonExpandedSize;


    public ConversationLayout(@NonNull Context context) {
    public ConversationLayout(@NonNull Context context) {
        super(context);
        super(context);
@@ -153,9 +155,12 @@ public class ConversationLayout extends FrameLayout
        mConversationIconBadge = findViewById(R.id.conversation_icon_badge);
        mConversationIconBadge = findViewById(R.id.conversation_icon_badge);
        mHeaderText = findViewById(R.id.header_text);
        mHeaderText = findViewById(R.id.header_text);
        mExpandButtonContainer = findViewById(R.id.expand_button_container);
        mExpandButtonContainer = findViewById(R.id.expand_button_container);
        mExpandButtonAndContentContainer = findViewById(R.id.expand_button_and_content_container);
        mExpandButton = findViewById(R.id.expand_button);
        mExpandButton = findViewById(R.id.expand_button);
        mExpandButtonExpandedTopMargin = getResources().getDimensionPixelSize(
        mExpandButtonExpandedTopMargin = getResources().getDimensionPixelSize(
                R.dimen.conversation_expand_button_top_margin_expanded);
                R.dimen.conversation_expand_button_top_margin_expanded);
        mExpandButtonExpandedSize = getResources().getDimensionPixelSize(
                R.dimen.conversation_expand_button_expanded_size);
        mBadgedSideMargins = getResources().getDimensionPixelSize(
        mBadgedSideMargins = getResources().getDimensionPixelSize(
                R.dimen.conversation_badge_side_margin);
                R.dimen.conversation_badge_side_margin);
        mIconSizeBadged = getResources().getDimensionPixelSize(
        mIconSizeBadged = getResources().getDimensionPixelSize(
@@ -713,19 +718,36 @@ public class ConversationLayout extends FrameLayout
        int contentDescriptionId;
        int contentDescriptionId;
        int gravity;
        int gravity;
        int topMargin = 0;
        int topMargin = 0;
        ViewGroup newContainer;
        int newContainerHeight;
        if (mIsCollapsed) {
        if (mIsCollapsed) {
            drawableId = R.drawable.ic_expand_notification;
            drawableId = R.drawable.ic_expand_notification;
            contentDescriptionId = R.string.expand_button_content_description_collapsed;
            contentDescriptionId = R.string.expand_button_content_description_collapsed;
            gravity = Gravity.CENTER;
            gravity = Gravity.CENTER;
            newContainer = mExpandButtonAndContentContainer;
            newContainerHeight = LayoutParams.MATCH_PARENT;
        } else {
        } else {
            drawableId = R.drawable.ic_collapse_notification;
            drawableId = R.drawable.ic_collapse_notification;
            contentDescriptionId = R.string.expand_button_content_description_expanded;
            contentDescriptionId = R.string.expand_button_content_description_expanded;
            gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
            gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
            topMargin = mExpandButtonExpandedTopMargin;
            topMargin = mExpandButtonExpandedTopMargin;
            newContainer = this;
            newContainerHeight = mExpandButtonExpandedSize;
        }
        }
        mExpandButton.setImageDrawable(getContext().getDrawable(drawableId));
        mExpandButton.setImageDrawable(getContext().getDrawable(drawableId));
        mExpandButton.setColorFilter(mExpandButton.getOriginalNotificationColor());
        mExpandButton.setColorFilter(mExpandButton.getOriginalNotificationColor());


        // We need to make sure that the expand button is in the linearlayout pushing over the
        // content when collapsed, but allows the content to flow under it when expanded.
        if (newContainer != mExpandButtonContainer.getParent()) {
            ((ViewGroup) mExpandButtonContainer.getParent()).removeView(mExpandButtonContainer);
            newContainer.addView(mExpandButtonContainer);
            MarginLayoutParams layoutParams =
                    (MarginLayoutParams) mExpandButtonContainer.getLayoutParams();
            layoutParams.height = newContainerHeight;
            mExpandButtonContainer.setLayoutParams(layoutParams);
        }

        // update if the expand button is centered
        // update if the expand button is centered
        FrameLayout.LayoutParams layoutParams = (LayoutParams) mExpandButton.getLayoutParams();
        FrameLayout.LayoutParams layoutParams = (LayoutParams) mExpandButton.getLayoutParams();
        layoutParams.gravity = gravity;
        layoutParams.gravity = gravity;
@@ -733,6 +755,7 @@ public class ConversationLayout extends FrameLayout
        mExpandButton.setLayoutParams(layoutParams);
        mExpandButton.setLayoutParams(layoutParams);


        mExpandButtonContainer.setContentDescription(mContext.getText(contentDescriptionId));
        mExpandButtonContainer.setContentDescription(mContext.getText(contentDescriptionId));

    }
    }


    public void updateExpandability(boolean expandable, @Nullable OnClickListener onClickListener) {
    public void updateExpandability(boolean expandable, @Nullable OnClickListener onClickListener) {
+23 −2
Original line number Original line Diff line number Diff line
@@ -23,6 +23,8 @@ import android.view.View;
import android.widget.LinearLayout;
import android.widget.LinearLayout;
import android.widget.RemoteViews;
import android.widget.RemoteViews;


import java.util.ArrayList;

/**
/**
 * A LinearLayout that sets it's height again after the last measure pass. This is needed for
 * A LinearLayout that sets it's height again after the last measure pass. This is needed for
 * MessagingLayouts where groups need to be able to snap it's height to.
 * MessagingLayouts where groups need to be able to snap it's height to.
@@ -30,6 +32,8 @@ import android.widget.RemoteViews;
@RemoteViews.RemoteView
@RemoteViews.RemoteView
public class RemeasuringLinearLayout extends LinearLayout {
public class RemeasuringLinearLayout extends LinearLayout {


    private ArrayList<View> mMatchParentViews = new ArrayList<>();

    public RemeasuringLinearLayout(Context context) {
    public RemeasuringLinearLayout(Context context) {
        super(context);
        super(context);
    }
    }
@@ -54,6 +58,7 @@ public class RemeasuringLinearLayout extends LinearLayout {
        int count = getChildCount();
        int count = getChildCount();
        int height = 0;
        int height = 0;
        boolean isVertical = getOrientation() == LinearLayout.VERTICAL;
        boolean isVertical = getOrientation() == LinearLayout.VERTICAL;
        boolean isWrapContent = getLayoutParams().height == LayoutParams.WRAP_CONTENT;
        for (int i = 0; i < count; ++i) {
        for (int i = 0; i < count; ++i) {
            final View child = getChildAt(i);
            final View child = getChildAt(i);
            if (child == null || child.getVisibility() == View.GONE) {
            if (child == null || child.getVisibility() == View.GONE) {
@@ -61,9 +66,25 @@ public class RemeasuringLinearLayout extends LinearLayout {
            }
            }


            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (!isWrapContent || lp.height != LayoutParams.MATCH_PARENT || isVertical) {
                int childHeight = child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin;
                int childHeight = child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin;
                height = Math.max(height, isVertical ? height + childHeight : childHeight);
                height = Math.max(height, isVertical ? height + childHeight : childHeight);
            } else {
                // We have match parent children in a wrap content view, let's measure the
                // view properly
                mMatchParentViews.add(child);
            }
        }
        if (mMatchParentViews.size() > 0) {
            int exactHeightSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
            for (View child : mMatchParentViews) {
                child.measure(getChildMeasureSpec(
                        widthMeasureSpec, getPaddingStart() + getPaddingEnd(),
                        child.getLayoutParams().width),
                        exactHeightSpec);
            }
        }
        }
        mMatchParentViews.clear();
        setMeasuredDimension(getMeasuredWidth(), height);
        setMeasuredDimension(getMeasuredWidth(), height);
    }
    }
}
}
+23 −20
Original line number Original line Diff line number Diff line
@@ -76,7 +76,8 @@
        android:orientation="vertical"
        android:orientation="vertical"
        >
        >
        <!-- LinearLayout for Expand Button-->
        <!-- LinearLayout for Expand Button-->
        <LinearLayout
        <com.android.internal.widget.RemeasuringLinearLayout
            android:id="@+id/expand_button_and_content_container"
            android:layout_width="match_parent"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_weight="1"
@@ -184,13 +185,26 @@
            <!-- Unread Count -->
            <!-- Unread Count -->
            <!-- <TextView /> -->
            <!-- <TextView /> -->


            <!-- This is where the expand button will be placed when collapsed-->
        </com.android.internal.widget.RemeasuringLinearLayout>

        <include layout="@layout/notification_template_smart_reply_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/notification_content_margin"
            android:layout_marginStart="@dimen/conversation_content_start"
            android:layout_marginEnd="@dimen/notification_content_margin_end" />
        <include layout="@layout/notification_material_action_list" />
    </com.android.internal.widget.RemeasuringLinearLayout>

    <!--This is dynamically placed between here and at the end of the layout-->
    <FrameLayout
    <FrameLayout
        android:id="@+id/expand_button_container"
        android:id="@+id/expand_button_container"
        android:layout_width="wrap_content"
        android:layout_width="wrap_content"
                android:layout_height="match_parent"
        android:layout_height="@dimen/conversation_expand_button_expanded_size"
        android:layout_gravity="end|top"
        android:paddingStart="16dp"
        android:paddingStart="16dp"
        android:paddingEnd="@dimen/notification_content_margin_end">
        android:paddingEnd="@dimen/notification_content_margin_end">
            <!--TODO: figure out tinting for exander-->
        <com.android.internal.widget.NotificationExpandButton
        <com.android.internal.widget.NotificationExpandButton
            android:id="@+id/expand_button"
            android:id="@+id/expand_button"
            android:layout_width="@dimen/notification_header_expand_icon_size"
            android:layout_width="@dimen/notification_header_expand_icon_size"
@@ -201,15 +215,4 @@
            android:importantForAccessibility="no"
            android:importantForAccessibility="no"
            />
            />
    </FrameLayout>
    </FrameLayout>
                    />
        </LinearLayout>

        <include layout="@layout/notification_template_smart_reply_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/notification_content_margin"
            android:layout_marginStart="@dimen/conversation_content_start"
            android:layout_marginEnd="@dimen/notification_content_margin_end" />
        <include layout="@layout/notification_material_action_list" />
    </com.android.internal.widget.RemeasuringLinearLayout>
</com.android.internal.widget.ConversationLayout>
</com.android.internal.widget.ConversationLayout>
+2 −0
Original line number Original line Diff line number Diff line
@@ -686,6 +686,8 @@
    <dimen name="conversation_avatar_size">52dp</dimen>
    <dimen name="conversation_avatar_size">52dp</dimen>
    <!-- Start of the content in the conversation template -->
    <!-- Start of the content in the conversation template -->
    <dimen name="conversation_content_start">80dp</dimen>
    <dimen name="conversation_content_start">80dp</dimen>
    <!-- Size of the expand button when expanded -->
    <dimen name="conversation_expand_button_expanded_size">80dp</dimen>
    <!-- Top margin of the expand button for conversations when expanded -->
    <!-- Top margin of the expand button for conversations when expanded -->
    <dimen name="conversation_expand_button_top_margin_expanded">18dp</dimen>
    <dimen name="conversation_expand_button_top_margin_expanded">18dp</dimen>
    <!-- Side margins of the conversation badge in relation to the conversation icon -->
    <!-- Side margins of the conversation badge in relation to the conversation icon -->
+2 −0
Original line number Original line Diff line number Diff line
@@ -3880,7 +3880,9 @@
  <java-symbol type="id" name="conversation_icon_badge" />
  <java-symbol type="id" name="conversation_icon_badge" />
  <java-symbol type="id" name="expand_button_container" />
  <java-symbol type="id" name="expand_button_container" />
  <java-symbol type="id" name="messaging_group_content_container" />
  <java-symbol type="id" name="messaging_group_content_container" />
  <java-symbol type="id" name="expand_button_and_content_container" />
  <java-symbol type="dimen" name="conversation_expand_button_top_margin_expanded" />
  <java-symbol type="dimen" name="conversation_expand_button_top_margin_expanded" />
  <java-symbol type="dimen" name="conversation_expand_button_expanded_size" />
  <java-symbol type="dimen" name="messaging_group_singleline_sender_padding_end" />
  <java-symbol type="dimen" name="messaging_group_singleline_sender_padding_end" />
  <java-symbol type="dimen" name="conversation_badge_side_margin" />
  <java-symbol type="dimen" name="conversation_badge_side_margin" />
  <java-symbol type="dimen" name="conversation_icon_size_badged" />
  <java-symbol type="dimen" name="conversation_icon_size_badged" />