diff options
| author | 2021-08-23 13:15:28 -0400 | |
|---|---|---|
| committer | 2023-05-02 09:32:20 -0400 | |
| commit | fbdeba2b860d93ed69b0b1378de0299f7228aa10 (patch) | |
| tree | aea672b7c56c3a0a2dd587b4c1730ed47146ec1e | |
| parent | 8c4326541ac25f042df916041557259fe4627a12 (diff) | |
Correct RTL support of Smart Actions
Fixes: 193213399
Test: atest SmartReplyViewTest (in RTL and LTR)
Test: Visually inspect smart actions from notifications posted in both LTR/RTL and after changing direction.
Change-Id: Ib280f943eca65ccf877c0062ac73133ffcda1f8d
(cherry picked from commit 8dab480298d26cb1a2dec5999f7416763e3bb900)
5 files changed, 18 insertions, 28 deletions
diff --git a/packages/SystemUI/res/layout/smart_action_button.xml b/packages/SystemUI/res/layout/smart_action_button.xml index 488be3a4479e..4e5785d284ee 100644 --- a/packages/SystemUI/res/layout/smart_action_button.xml +++ b/packages/SystemUI/res/layout/smart_action_button.xml @@ -29,8 +29,8 @@ android:textSize="@dimen/smart_reply_button_font_size" android:lineSpacingExtra="@dimen/smart_reply_button_line_spacing_extra" android:textColor="@color/smart_reply_button_text" - android:paddingLeft="@dimen/smart_reply_button_action_padding_left" - android:paddingRight="@dimen/smart_reply_button_padding_horizontal" + android:paddingStart="@dimen/smart_reply_button_action_padding_left" + android:paddingEnd="@dimen/smart_reply_button_padding_horizontal" android:drawablePadding="@dimen/smart_action_button_icon_padding" android:textStyle="normal" android:ellipsize="none"/> diff --git a/packages/SystemUI/res/layout/smart_reply_button.xml b/packages/SystemUI/res/layout/smart_reply_button.xml index ddf16e0afed7..b24362febbdd 100644 --- a/packages/SystemUI/res/layout/smart_reply_button.xml +++ b/packages/SystemUI/res/layout/smart_reply_button.xml @@ -31,7 +31,7 @@ android:textSize="@dimen/smart_reply_button_font_size" android:lineSpacingExtra="@dimen/smart_reply_button_line_spacing_extra" android:textColor="@color/smart_reply_button_text" - android:paddingLeft="@dimen/smart_reply_button_padding_horizontal" - android:paddingRight="@dimen/smart_reply_button_padding_horizontal" + android:paddingStart="@dimen/smart_reply_button_padding_horizontal" + android:paddingEnd="@dimen/smart_reply_button_padding_horizontal" android:textStyle="normal" android:ellipsize="none"/> diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyStateInflater.kt b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyStateInflater.kt index b563d86f65b1..21d03386b9e2 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyStateInflater.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyStateInflater.kt @@ -311,7 +311,7 @@ interface SmartActionInflater { setBounds(0, 0, newIconSize, newIconSize) } // Add the action icon to the Smart Action button. - setCompoundDrawables(iconDrawable, null, null, null) + setCompoundDrawablesRelative(iconDrawable, null, null, null) val onClickListener = View.OnClickListener { onSmartActionClick(entry, smartActions, actionIndex, action) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyView.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyView.java index 9e88ceb3a0d1..fb6ba8542a3f 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyView.java @@ -588,15 +588,15 @@ public class SmartReplyView extends ViewGroup { } /** - * Returns the combined width of the left drawable (the action icon) and the padding between the - * drawable and the button text. + * Returns the combined width of the start drawable (the action icon) and the padding between + * the drawable and the button text. */ - private int getLeftCompoundDrawableWidthWithPadding(Button button) { - Drawable[] drawables = button.getCompoundDrawables(); - Drawable leftDrawable = drawables[0]; - if (leftDrawable == null) return 0; + private int getStartCompoundDrawableWidthWithPadding(Button button) { + Drawable[] drawables = button.getCompoundDrawablesRelative(); + Drawable startDrawable = drawables[0]; + if (startDrawable == null) return 0; - return leftDrawable.getBounds().width() + button.getCompoundDrawablePadding(); + return startDrawable.getBounds().width() + button.getCompoundDrawablePadding(); } private int squeezeButtonToTextWidth(Button button, int heightMeasureSpec, int textWidth) { @@ -605,8 +605,8 @@ public class SmartReplyView extends ViewGroup { // Re-measure the squeezed smart reply button. clearLayoutLineCount(button); final int widthMeasureSpec = MeasureSpec.makeMeasureSpec( - button.getPaddingLeft() + button.getPaddingRight() + textWidth - + getLeftCompoundDrawableWidthWithPadding(button), MeasureSpec.AT_MOST); + button.getPaddingStart() + button.getPaddingEnd() + textWidth + + getStartCompoundDrawableWidthWithPadding(button), MeasureSpec.AT_MOST); button.measure(widthMeasureSpec, heightMeasureSpec); if (button.getLayout() == null) { Log.wtf(TAG, "Button layout is null after measure."); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SmartReplyViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SmartReplyViewTest.java index d9d8b6345fcb..3b0d5120cca3 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SmartReplyViewTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SmartReplyViewTest.java @@ -585,8 +585,6 @@ public class SmartReplyViewTest extends SysuiTestCase { // devices. layout.setBaselineAligned(false); - final boolean isRtl = mView.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; - // Add smart replies Button previous = null; SmartReplyView.SmartReplies smartReplies = @@ -606,11 +604,7 @@ public class SmartReplyViewTest extends SysuiTestCase { if (previous != null) { ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) previous.getLayoutParams(); - if (isRtl) { - lp.leftMargin = mSpacing; - } else { - lp.rightMargin = mSpacing; - } + lp.setMarginEnd(mSpacing); } layout.addView(current); previous = current; @@ -634,11 +628,7 @@ public class SmartReplyViewTest extends SysuiTestCase { if (previous != null) { ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) previous.getLayoutParams(); - if (isRtl) { - lp.leftMargin = mSpacing; - } else { - lp.rightMargin = mSpacing; - } + lp.setMarginEnd(mSpacing); } layout.addView(current); previous = current; @@ -937,8 +927,8 @@ public class SmartReplyViewTest extends SysuiTestCase { .collect(Collectors.toList()); Button singleLineButton = buttons.get(0); Button doubleLineButton = buttons.get(1); - Drawable singleLineDrawable = singleLineButton.getCompoundDrawables()[0]; // left drawable - Drawable doubleLineDrawable = doubleLineButton.getCompoundDrawables()[0]; // left drawable + Drawable singleLineDrawable = singleLineButton.getCompoundDrawablesRelative()[0]; // start + Drawable doubleLineDrawable = doubleLineButton.getCompoundDrawablesRelative()[0]; // start assertEquals(singleLineDrawable.getBounds().width(), doubleLineDrawable.getBounds().width()); assertEquals(singleLineDrawable.getBounds().height(), |