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

Commit e7cf4983 authored by Milo Sredkov's avatar Milo Sredkov
Browse files

Allow extra height for the smartreply buttons

Currently ExpandableNotificationRow assumes that notifications can be
up to @dimen/notification_max_height big and propagates that value to
NotificationContentView. However, when smart reply buttons are present
the content could get bigger than that and cause content to be
truncated in an undesirable way.

Add a smart_reply_button_max_height dimension and add it in addition
to notification_max_height when smart reply buttons are present.

Screenshots:
- before: https://screenshot.googleplex.com/MssT483YPd5.png
- after: https://screenshot.googleplex.com/k5StCMhb74t.png

Bug: 72360319
Bug: 73949609
Test: In Notify post a Messaging notification with Large chices
Change-Id: Ib3e43cff927bb5ca6dd941705cd280dc85f14a08
parent de2e5ce1
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -930,6 +930,11 @@
    <dimen name="smart_reply_button_font_size">14sp</dimen>
    <dimen name="smart_reply_button_line_spacing_extra">6sp</dimen> <!-- Total line height 20sp. -->

    <!-- A reasonable upper bound for the height of the smart reply button. The measuring code
            needs to start with a guess for the maximum size. Currently two-line smart reply buttons
            add about 88dp of height to the notifications. -->
    <dimen name="smart_reply_button_max_height">100dp</dimen>

    <!-- Fingerprint Dialog values -->
    <dimen name="fingerprint_dialog_fp_icon_size">64dp</dimen>
    <dimen name="fingerprint_dialog_animation_translation_offset">350dp</dimen>
+9 −4
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ public class NotificationContentView extends FrameLayout {
    private RemoteInputView mHeadsUpRemoteInput;

    private SmartReplyConstants mSmartReplyConstants;
    private SmartReplyView mExpandedSmartReplyView;
    private SmartReplyLogger mSmartReplyLogger;

    private NotificationViewWrapper mContractedWrapper;
@@ -184,7 +185,11 @@ public class NotificationContentView extends FrameLayout {
        }
        int maxChildHeight = 0;
        if (mExpandedChild != null) {
            int size = Math.min(maxSize, mNotificationMaxHeight);
            int notificationMaxHeight = mNotificationMaxHeight;
            if (mExpandedSmartReplyView != null) {
                notificationMaxHeight += mExpandedSmartReplyView.getHeightUpperLimit();
            }
            int size = Math.min(maxSize, notificationMaxHeight);
            ViewGroup.LayoutParams layoutParams = mExpandedChild.getLayoutParams();
            boolean useExactly = false;
            if (layoutParams.height >= 0) {
@@ -1348,10 +1353,10 @@ public class NotificationContentView extends FrameLayout {
    private void applySmartReplyView(RemoteInput remoteInput, PendingIntent pendingIntent,
            NotificationData.Entry entry) {
        if (mExpandedChild != null) {
            SmartReplyView view =
            mExpandedSmartReplyView =
                    applySmartReplyView(mExpandedChild, remoteInput, pendingIntent, entry);
            if (view != null && remoteInput != null && remoteInput.getChoices() != null
                    && remoteInput.getChoices().length > 0) {
            if (mExpandedSmartReplyView != null && remoteInput != null
                    && remoteInput.getChoices() != null && remoteInput.getChoices().length > 0) {
                mSmartReplyLogger.smartRepliesAdded(entry, remoteInput.getChoices().length);
            }
        }
+19 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.statusbar.NotificationData;
import com.android.systemui.statusbar.SmartReplyLogger;
import com.android.systemui.statusbar.notification.NotificationUtils;
import com.android.systemui.statusbar.phone.KeyguardDismissUtil;

import java.text.BreakIterator;
@@ -48,6 +49,12 @@ public class SmartReplyView extends ViewGroup {
    private final SmartReplyConstants mConstants;
    private final KeyguardDismissUtil mKeyguardDismissUtil;

    /**
     * The upper bound for the height of this view in pixels. Notifications are automatically
     * recreated on density or font size changes so caching this should be fine.
     */
    private final int mHeightUpperLimit;

    /** Spacing to be applied between views. */
    private final int mSpacing;

@@ -69,6 +76,9 @@ public class SmartReplyView extends ViewGroup {
        mConstants = Dependency.get(SmartReplyConstants.class);
        mKeyguardDismissUtil = Dependency.get(KeyguardDismissUtil.class);

        mHeightUpperLimit = NotificationUtils.getFontScaledHeight(mContext,
            R.dimen.smart_reply_button_max_height);

        int spacing = 0;
        int singleLineButtonPaddingHorizontal = 0;
        int doubleLineButtonPaddingHorizontal = 0;
@@ -98,10 +108,19 @@ public class SmartReplyView extends ViewGroup {
        mSingleToDoubleLineButtonWidthIncrease =
                2 * (doubleLineButtonPaddingHorizontal - singleLineButtonPaddingHorizontal);


        mBreakIterator = BreakIterator.getLineInstance();
        reallocateCandidateButtonQueueForSqueezing();
    }

    /**
     * Returns an upper bound for the height of this view in pixels. This method is intended to be
     * invoked before onMeasure, so it doesn't do any analysis on the contents of the buttons.
     */
    public int getHeightUpperLimit() {
       return mHeightUpperLimit;
    }

    private void reallocateCandidateButtonQueueForSqueezing() {
        // Instead of clearing the priority queue, we re-allocate so that it would fit all buttons
        // exactly. This avoids (1) wasting memory because PriorityQueue never shrinks and