From 2b8b9029fd4e44447e59d7349c656cc32b2de9c7 Mon Sep 17 00:00:00 2001 From: Andrew Sapperstein Date: Fri, 24 Jan 2014 19:03:35 -0800 Subject: Support RTL in chips library. Fixes b/12569794. Change-Id: I927a5d3e0d4af42a3ca3fbbb87ba201fe7bb830e --- chips/Android.mk | 2 +- chips/AndroidManifest.xml | 2 +- chips/res/layout/chips_recipient_dropdown_item.xml | 12 ++++----- chips/res/values-v17/styles-v17.xml | 28 ++++++++++++++++++++ chips/res/values/attrs.xml | 4 +-- chips/res/values/dimen.xml | 6 ++++- chips/res/values/styles.xml | 12 +++++++++ .../android/ex/chips/RecipientEditTextView.java | 30 ++++++++++++++++------ 8 files changed, 77 insertions(+), 19 deletions(-) create mode 100644 chips/res/values-v17/styles-v17.xml (limited to 'chips') diff --git a/chips/Android.mk b/chips/Android.mk index ef4b8ab..2bca597 100644 --- a/chips/Android.mk +++ b/chips/Android.mk @@ -17,7 +17,7 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := android-common-chips LOCAL_STATIC_JAVA_LIBRARIES += android-support-v4 -LOCAL_SDK_VERSION := 14 +LOCAL_SDK_VERSION := 19 LOCAL_SRC_FILES := \ $(call all-java-files-under, src) \ $(call all-logtags-files-under, src) diff --git a/chips/AndroidManifest.xml b/chips/AndroidManifest.xml index 7487c18..02ea564 100644 --- a/chips/AndroidManifest.xml +++ b/chips/AndroidManifest.xml @@ -19,6 +19,6 @@ + android:targetSdkVersion="19" /> \ No newline at end of file diff --git a/chips/res/layout/chips_recipient_dropdown_item.xml b/chips/res/layout/chips_recipient_dropdown_item.xml index cd11d67..b02b197 100644 --- a/chips/res/layout/chips_recipient_dropdown_item.xml +++ b/chips/res/layout/chips_recipient_dropdown_item.xml @@ -33,25 +33,25 @@ android:textSize="18sp" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:paddingLeft="8dip" android:singleLine="true" - android:ellipsize="end" /> + android:ellipsize="end" + style="@style/ChipTitleStyle" /> + android:layout_marginTop="-4dip" + style="@style/ChipSubtitleStyle" /> + android:scaleType="centerCrop" + style="@style/ChipIconStyle" /> diff --git a/chips/res/values-v17/styles-v17.xml b/chips/res/values-v17/styles-v17.xml new file mode 100644 index 0000000..d151a75 --- /dev/null +++ b/chips/res/values-v17/styles-v17.xml @@ -0,0 +1,28 @@ + + + + + + + + + diff --git a/chips/res/values/attrs.xml b/chips/res/values/attrs.xml index 6b26bcb..96d995a 100644 --- a/chips/res/values/attrs.xml +++ b/chips/res/values/attrs.xml @@ -16,8 +16,8 @@ - - + + diff --git a/chips/res/values/dimen.xml b/chips/res/values/dimen.xml index 98354d2..f989c86 100644 --- a/chips/res/values/dimen.xml +++ b/chips/res/values/dimen.xml @@ -20,4 +20,8 @@ 14sp 4dip -1 - \ No newline at end of file + + 8dip + 16dip + 12dip + diff --git a/chips/res/values/styles.xml b/chips/res/values/styles.xml index 8e2abf9..83f96b4 100644 --- a/chips/res/values/styles.xml +++ b/chips/res/values/styles.xml @@ -26,4 +26,16 @@ 48dip @dimen/line_spacing_extra + + + + + + diff --git a/chips/src/com/android/ex/chips/RecipientEditTextView.java b/chips/src/com/android/ex/chips/RecipientEditTextView.java index b355c1b..e48a3b1 100644 --- a/chips/src/com/android/ex/chips/RecipientEditTextView.java +++ b/chips/src/com/android/ex/chips/RecipientEditTextView.java @@ -152,13 +152,13 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements /** * Enumerator for avatar position. See attr.xml for more details. - * 0 for right, 1 for left. + * 0 for end, 1 for start. */ private int mAvatarPosition; - private static final int AVATAR_POSITION_RIGHT = 0; + private static final int AVATAR_POSITION_END = 0; - private static final int AVATAR_POSITION_LEFT = 1; + private static final int AVATAR_POSITION_START = 1; private boolean mDisableDelete; @@ -600,7 +600,8 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements Drawable background) { if (background == null) { Log.w(TAG, "Unable to draw a background for the chips as it was never set"); - Bitmap.createBitmap((int) mChipHeight * 2, (int) mChipHeight, Bitmap.Config.ARGB_8888); + return Bitmap.createBitmap( + (int) mChipHeight * 2, (int) mChipHeight, Bitmap.Config.ARGB_8888); } Rect backgroundPadding = new Rect(); @@ -632,14 +633,14 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements background.setBounds(0, 0, width, height); background.draw(canvas); // Draw the text vertically aligned - int textX = mAvatarPosition == AVATAR_POSITION_RIGHT ? + int textX = shouldPositionAvatarOnRight() ? mChipPadding + backgroundPadding.left : width - backgroundPadding.right - mChipPadding - textWidth; canvas.drawText(ellipsizedText, 0, ellipsizedText.length(), textX, getTextYOffset(ellipsizedText.toString(), paint, height), paint); if (icon != null) { // Draw the icon - int iconX = mAvatarPosition == AVATAR_POSITION_RIGHT ? + int iconX = shouldPositionAvatarOnRight() ? width - backgroundPadding.right - iconWidth : backgroundPadding.left; RectF src = new RectF(0, 0, icon.getWidth(), icon.getHeight()); @@ -652,6 +653,19 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements return tmpBitmap; } + /** + * Returns true if the avatar should be positioned at the right edge of the chip. + * Takes into account both the set avatar position (start or end) as well as whether + * the layout direction is LTR or RTL. + */ + private boolean shouldPositionAvatarOnRight() { + final boolean isRtl = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 ? + getLayoutDirection() == LAYOUT_DIRECTION_RTL : false; + final boolean assignedPosition = mAvatarPosition == AVATAR_POSITION_END; + // If in Rtl mode, the position should be flipped. + return isRtl ? !assignedPosition : assignedPosition; + } + /** * Returns the avatar icon to use for this recipient entry. Returns null if we don't want to * draw an icon for this recipient. @@ -2167,8 +2181,8 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements } return chip.isSelected() && - ((mAvatarPosition == 0 && offset == getChipEnd(chip)) || - (mAvatarPosition != 0 && offset == getChipStart(chip))); + ((mAvatarPosition == AVATAR_POSITION_END && offset == getChipEnd(chip)) || + (mAvatarPosition != AVATAR_POSITION_END && offset == getChipStart(chip))); } /** -- cgit v1.2.3