Merge "Revert "Correct RTL support of Smart Actions"" into sc-qpr1-dev

This commit is contained in:
Jeff DeCew
2021-09-08 14:47:58 +00:00
committed by Android (Google) Code Review
5 changed files with 28 additions and 18 deletions

View File

@@ -29,8 +29,8 @@
android:textSize="@dimen/smart_reply_button_font_size" android:textSize="@dimen/smart_reply_button_font_size"
android:lineSpacingExtra="@dimen/smart_reply_button_line_spacing_extra" android:lineSpacingExtra="@dimen/smart_reply_button_line_spacing_extra"
android:textColor="@color/smart_reply_button_text" android:textColor="@color/smart_reply_button_text"
android:paddingStart="@dimen/smart_reply_button_action_padding_left" android:paddingLeft="@dimen/smart_reply_button_action_padding_left"
android:paddingEnd="@dimen/smart_reply_button_padding_horizontal" android:paddingRight="@dimen/smart_reply_button_padding_horizontal"
android:drawablePadding="@dimen/smart_action_button_icon_padding" android:drawablePadding="@dimen/smart_action_button_icon_padding"
android:textStyle="normal" android:textStyle="normal"
android:ellipsize="none"/> android:ellipsize="none"/>

View File

@@ -31,7 +31,7 @@
android:textSize="@dimen/smart_reply_button_font_size" android:textSize="@dimen/smart_reply_button_font_size"
android:lineSpacingExtra="@dimen/smart_reply_button_line_spacing_extra" android:lineSpacingExtra="@dimen/smart_reply_button_line_spacing_extra"
android:textColor="@color/smart_reply_button_text" android:textColor="@color/smart_reply_button_text"
android:paddingStart="@dimen/smart_reply_button_padding_horizontal" android:paddingLeft="@dimen/smart_reply_button_padding_horizontal"
android:paddingEnd="@dimen/smart_reply_button_padding_horizontal" android:paddingRight="@dimen/smart_reply_button_padding_horizontal"
android:textStyle="normal" android:textStyle="normal"
android:ellipsize="none"/> android:ellipsize="none"/>

View File

@@ -311,7 +311,7 @@ interface SmartActionInflater {
setBounds(0, 0, newIconSize, newIconSize) setBounds(0, 0, newIconSize, newIconSize)
} }
// Add the action icon to the Smart Action button. // Add the action icon to the Smart Action button.
setCompoundDrawablesRelative(iconDrawable, null, null, null) setCompoundDrawables(iconDrawable, null, null, null)
val onClickListener = View.OnClickListener { val onClickListener = View.OnClickListener {
onSmartActionClick(entry, smartActions, actionIndex, action) onSmartActionClick(entry, smartActions, actionIndex, action)

View File

@@ -503,15 +503,15 @@ public class SmartReplyView extends ViewGroup {
} }
/** /**
* Returns the combined width of the start drawable (the action icon) and the padding between * Returns the combined width of the left drawable (the action icon) and the padding between the
* the drawable and the button text. * drawable and the button text.
*/ */
private int getStartCompoundDrawableWidthWithPadding(Button button) { private int getLeftCompoundDrawableWidthWithPadding(Button button) {
Drawable[] drawables = button.getCompoundDrawablesRelative(); Drawable[] drawables = button.getCompoundDrawables();
Drawable startDrawable = drawables[0]; Drawable leftDrawable = drawables[0];
if (startDrawable == null) return 0; if (leftDrawable == null) return 0;
return startDrawable.getBounds().width() + button.getCompoundDrawablePadding(); return leftDrawable.getBounds().width() + button.getCompoundDrawablePadding();
} }
private int squeezeButtonToTextWidth(Button button, int heightMeasureSpec, int textWidth) { private int squeezeButtonToTextWidth(Button button, int heightMeasureSpec, int textWidth) {
@@ -520,8 +520,8 @@ public class SmartReplyView extends ViewGroup {
// Re-measure the squeezed smart reply button. // Re-measure the squeezed smart reply button.
clearLayoutLineCount(button); clearLayoutLineCount(button);
final int widthMeasureSpec = MeasureSpec.makeMeasureSpec( final int widthMeasureSpec = MeasureSpec.makeMeasureSpec(
button.getPaddingStart() + button.getPaddingEnd() + textWidth button.getPaddingLeft() + button.getPaddingRight() + textWidth
+ getStartCompoundDrawableWidthWithPadding(button), MeasureSpec.AT_MOST); + getLeftCompoundDrawableWidthWithPadding(button), MeasureSpec.AT_MOST);
button.measure(widthMeasureSpec, heightMeasureSpec); button.measure(widthMeasureSpec, heightMeasureSpec);
final int newWidth = button.getMeasuredWidth(); final int newWidth = button.getMeasuredWidth();

View File

@@ -581,6 +581,8 @@ public class SmartReplyViewTest extends SysuiTestCase {
// devices. // devices.
layout.setBaselineAligned(false); layout.setBaselineAligned(false);
final boolean isRtl = mView.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
// Add smart replies // Add smart replies
Button previous = null; Button previous = null;
SmartReplyView.SmartReplies smartReplies = SmartReplyView.SmartReplies smartReplies =
@@ -600,7 +602,11 @@ public class SmartReplyViewTest extends SysuiTestCase {
if (previous != null) { if (previous != null) {
ViewGroup.MarginLayoutParams lp = ViewGroup.MarginLayoutParams lp =
(ViewGroup.MarginLayoutParams) previous.getLayoutParams(); (ViewGroup.MarginLayoutParams) previous.getLayoutParams();
lp.setMarginEnd(mSpacing); if (isRtl) {
lp.leftMargin = mSpacing;
} else {
lp.rightMargin = mSpacing;
}
} }
layout.addView(current); layout.addView(current);
previous = current; previous = current;
@@ -624,7 +630,11 @@ public class SmartReplyViewTest extends SysuiTestCase {
if (previous != null) { if (previous != null) {
ViewGroup.MarginLayoutParams lp = ViewGroup.MarginLayoutParams lp =
(ViewGroup.MarginLayoutParams) previous.getLayoutParams(); (ViewGroup.MarginLayoutParams) previous.getLayoutParams();
lp.setMarginEnd(mSpacing); if (isRtl) {
lp.leftMargin = mSpacing;
} else {
lp.rightMargin = mSpacing;
}
} }
layout.addView(current); layout.addView(current);
previous = current; previous = current;
@@ -923,8 +933,8 @@ public class SmartReplyViewTest extends SysuiTestCase {
.collect(Collectors.toList()); .collect(Collectors.toList());
Button singleLineButton = buttons.get(0); Button singleLineButton = buttons.get(0);
Button doubleLineButton = buttons.get(1); Button doubleLineButton = buttons.get(1);
Drawable singleLineDrawable = singleLineButton.getCompoundDrawablesRelative()[0]; // start Drawable singleLineDrawable = singleLineButton.getCompoundDrawables()[0]; // left drawable
Drawable doubleLineDrawable = doubleLineButton.getCompoundDrawablesRelative()[0]; // start Drawable doubleLineDrawable = doubleLineButton.getCompoundDrawables()[0]; // left drawable
assertEquals(singleLineDrawable.getBounds().width(), assertEquals(singleLineDrawable.getBounds().width(),
doubleLineDrawable.getBounds().width()); doubleLineDrawable.getBounds().width());
assertEquals(singleLineDrawable.getBounds().height(), assertEquals(singleLineDrawable.getBounds().height(),