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
This commit is contained in:
@@ -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"/>
|
||||
|
||||
@@ -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"/>
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -503,15 +503,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) {
|
||||
@@ -520,8 +520,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);
|
||||
|
||||
final int newWidth = button.getMeasuredWidth();
|
||||
|
||||
@@ -581,8 +581,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 =
|
||||
@@ -602,11 +600,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;
|
||||
@@ -630,11 +624,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;
|
||||
@@ -933,8 +923,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(),
|
||||
|
||||
Reference in New Issue
Block a user