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

Commit 4748afe3 authored by Jeff DeCew's avatar Jeff DeCew
Browse files

Collapse the CallStyle buttons to just an icon instead of truncating text.

Fixes: 195019654
Test: post CallStyle notification without custom action; observe text
Test: post CallStyle notification with custom action; observe buttons shrink to icon only.
Test: repeat tests using various font and screen sizes.
Change-Id: Icbd6189a1e03494e481e8672263570ae2657f946
parent f19b1dfd
Loading
Loading
Loading
Loading
+39 −14
Original line number Diff line number Diff line
@@ -53,6 +53,8 @@ public class NotificationActionListLayout extends LinearLayout {
    private int mEmphasizedHeight;
    private int mRegularHeight;
    @DimenRes private int mCollapsibleIndentDimen = R.dimen.notification_actions_padding_start;
    int mNumNotGoneChildren;
    int mNumPriorityChildren;

    public NotificationActionListLayout(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
@@ -76,15 +78,14 @@ public class NotificationActionListLayout extends LinearLayout {
                && ((EmphasizedNotificationButton) actionView).isPriority();
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        final int N = getChildCount();
    private void countAndRebuildMeasureOrder() {
        final int numChildren = getChildCount();
        int textViews = 0;
        int otherViews = 0;
        int notGoneChildren = 0;
        int priorityChildren = 0;
        mNumNotGoneChildren = 0;
        mNumPriorityChildren = 0;

        for (int i = 0; i < N; i++) {
        for (int i = 0; i < numChildren; i++) {
            View c = getChildAt(i);
            if (c instanceof TextView) {
                textViews++;
@@ -92,9 +93,9 @@ public class NotificationActionListLayout extends LinearLayout {
                otherViews++;
            }
            if (c.getVisibility() != GONE) {
                notGoneChildren++;
                mNumNotGoneChildren++;
                if (isPriority(c)) {
                    priorityChildren++;
                    mNumPriorityChildren++;
                }
            }
        }
@@ -119,17 +120,20 @@ public class NotificationActionListLayout extends LinearLayout {
        if (needRebuild) {
            rebuildMeasureOrder(textViews, otherViews);
        }
    }

    private int measureAndGetUsedWidth(int widthMeasureSpec, int heightMeasureSpec, int innerWidth,
            boolean collapsePriorityActions) {
        final int numChildren = getChildCount();
        final boolean constrained =
                MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.UNSPECIFIED;

        final int innerWidth = MeasureSpec.getSize(widthMeasureSpec) - mPaddingLeft - mPaddingRight;
        final int otherSize = mMeasureOrderOther.size();
        int usedWidth = 0;

        int maxPriorityWidth = 0;
        int measuredChildren = 0;
        int measuredPriorityChildren = 0;
        for (int i = 0; i < N; i++) {
        for (int i = 0; i < numChildren; i++) {
            // Measure shortest children first. To avoid measuring twice, we approximate by looking
            // at the text length.
            final boolean isPriority;
@@ -154,12 +158,20 @@ public class NotificationActionListLayout extends LinearLayout {
                // measure in the order of (approx.) size, a large view can still take more than its
                // share if the others are small.
                int availableWidth = innerWidth - usedWidth;
                int unmeasuredChildren = notGoneChildren - measuredChildren;
                int unmeasuredChildren = mNumNotGoneChildren - measuredChildren;
                int maxWidthForChild = availableWidth / unmeasuredChildren;
                if (isPriority) {
                if (isPriority && collapsePriorityActions) {
                    // Collapsing the actions to just the width required to show the icon.
                    if (maxPriorityWidth == 0) {
                        maxPriorityWidth = getResources().getDimensionPixelSize(
                                R.dimen.notification_actions_collapsed_priority_width);
                    }
                    maxWidthForChild = maxPriorityWidth + lp.leftMargin + lp.rightMargin;
                } else if (isPriority) {
                    // Priority children get a larger maximum share of the total space:
                    //  maximum priority share = (nPriority + 1) / (MAX + 1)
                    int unmeasuredPriorityChildren = priorityChildren - measuredPriorityChildren;
                    int unmeasuredPriorityChildren = mNumPriorityChildren
                            - measuredPriorityChildren;
                    int unmeasuredOtherChildren = unmeasuredChildren - unmeasuredPriorityChildren;
                    int widthReservedForOtherChildren = innerWidth * unmeasuredOtherChildren
                            / (Notification.MAX_ACTION_BUTTONS + 1);
@@ -187,6 +199,19 @@ public class NotificationActionListLayout extends LinearLayout {
        } else {
            mExtraStartPadding = 0;
        }
        return usedWidth;
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        countAndRebuildMeasureOrder();
        final int innerWidth = MeasureSpec.getSize(widthMeasureSpec) - mPaddingLeft - mPaddingRight;
        int usedWidth = measureAndGetUsedWidth(widthMeasureSpec, heightMeasureSpec, innerWidth,
                false /* collapsePriorityButtons */);
        if (mNumPriorityChildren != 0 && usedWidth >= innerWidth) {
            usedWidth = measureAndGetUsedWidth(widthMeasureSpec, heightMeasureSpec, innerWidth,
                    true /* collapsePriorityButtons */);
        }

        mTotalWidth = usedWidth + mPaddingRight + mPaddingLeft + mExtraStartPadding;
        setMeasuredDimension(resolveSize(getSuggestedMinimumWidth(), widthMeasureSpec),
+2 −2
Original line number Diff line number Diff line
@@ -24,9 +24,9 @@
            android:insetBottom="@dimen/button_inset_vertical_material">
            <shape android:shape="rectangle">
                <corners android:radius="@dimen/notification_action_button_radius" />
                <padding android:left="12dp"
                <padding android:left="16dp"
                         android:top="@dimen/button_padding_vertical_material"
                         android:right="12dp"
                         android:right="16dp"
                         android:bottom="@dimen/button_padding_vertical_material" />
                <solid android:color="@color/white" />
            </shape>
+3 −0
Original line number Diff line number Diff line
@@ -237,6 +237,9 @@
         value is calculated in ConversationLayout#updateActionListPadding() -->
    <dimen name="notification_actions_padding_start">36dp</dimen>

    <!-- The max width of a priority action button when it is collapsed to just the icon. -->
    <dimen name="notification_actions_collapsed_priority_width">60dp</dimen>

    <!-- The start padding to optionally use (e.g. if there's extra space) for CallStyle
         notification actions.
         this = conversation_content_start (80dp) - button inset (4dp) - action padding (12dp) -->
+1 −0
Original line number Diff line number Diff line
@@ -3185,6 +3185,7 @@

  <java-symbol type="id" name="notification_action_list_margin_target" />
  <java-symbol type="dimen" name="notification_actions_padding_start"/>
  <java-symbol type="dimen" name="notification_actions_collapsed_priority_width"/>
  <java-symbol type="dimen" name="notification_action_disabled_alpha" />
  <java-symbol type="id" name="tag_margin_end_when_icon_visible" />
  <java-symbol type="id" name="tag_margin_end_when_icon_gone" />