diff options
author | Andrew Sapperstein <asapperstein@google.com> | 2014-01-24 19:03:35 -0800 |
---|---|---|
committer | Andrew Sapperstein <asapperstein@google.com> | 2014-01-27 14:03:26 -0800 |
commit | 2b8b9029fd4e44447e59d7349c656cc32b2de9c7 (patch) | |
tree | 0c1fe25b134f0a2e9aca73a3d19559533780d112 | |
parent | 2b080e1e1e24a2096fea375d825aa19089fa3e32 (diff) | |
download | android_frameworks_ex-2b8b9029fd4e44447e59d7349c656cc32b2de9c7.tar.gz android_frameworks_ex-2b8b9029fd4e44447e59d7349c656cc32b2de9c7.tar.bz2 android_frameworks_ex-2b8b9029fd4e44447e59d7349c656cc32b2de9c7.zip |
Support RTL in chips library.
Fixes b/12569794.
Change-Id: I927a5d3e0d4af42a3ca3fbbb87ba201fe7bb830e
-rw-r--r-- | chips/Android.mk | 2 | ||||
-rw-r--r-- | chips/AndroidManifest.xml | 2 | ||||
-rw-r--r-- | chips/res/layout/chips_recipient_dropdown_item.xml | 12 | ||||
-rw-r--r-- | chips/res/values-v17/styles-v17.xml | 28 | ||||
-rw-r--r-- | chips/res/values/attrs.xml | 4 | ||||
-rw-r--r-- | chips/res/values/dimen.xml | 6 | ||||
-rw-r--r-- | chips/res/values/styles.xml | 12 | ||||
-rw-r--r-- | chips/src/com/android/ex/chips/RecipientEditTextView.java | 30 |
8 files changed, 77 insertions, 19 deletions
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 @@ <uses-sdk android:minSdkVersion="11" - android:targetSdkVersion="18" /> + android:targetSdkVersion="19" /> </manifest>
\ 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" /> <TextView android:id="@android:id/text1" android:textColor="@drawable/list_item_font_secondary" android:textSize="14sp" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:paddingLeft="16dip" android:singleLine="true" android:ellipsize="end" - android:layout_marginTop="-4dip" /> + android:layout_marginTop="-4dip" + style="@style/ChipSubtitleStyle" /> </LinearLayout> <ImageView android:id="@android:id/icon" android:layout_width="48dip" android:layout_height="48dip" - android:layout_marginLeft="12dip" android:src="@drawable/ic_contact_picture" android:cropToPadding="true" - android:scaleType="centerCrop" /> + android:scaleType="centerCrop" + style="@style/ChipIconStyle" /> </LinearLayout> 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 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<resources> + <style name="ChipTitleStyle"> + <item name="android:paddingStart">@dimen/chip_title_padding_start</item> + </style> + + <style name="ChipSubtitleStyle"> + <item name="android:paddingStart">@dimen/chip_subtitle_padding_start</item> + </style> + + <style name="ChipIconStyle"> + <item name="android:layout_marginStart">@dimen/chip_icon_margin_start</item> + </style> +</resources> 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 @@ <resources> <declare-styleable name="RecipientEditTextView"> <attr name="avatarPosition"> - <enum name="right" value="0" /> - <enum name="left" value="1" /> + <enum name="end" value="0" /> + <enum name="start" value="1" /> </attr> <attr name="chipBackground" format="reference" /> <attr name="chipBackgroundPressed" format="reference" /> 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 @@ <dimen name="chip_text_size">14sp</dimen> <dimen name="line_spacing_extra">4dip</dimen> <integer name="chips_max_lines">-1</integer> -</resources>
\ No newline at end of file + + <dimen name="chip_title_padding_start">8dip</dimen> + <dimen name="chip_subtitle_padding_start">16dip</dimen> + <dimen name="chip_icon_margin_start">12dip</dimen> +</resources> 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 @@ <item name="android:minHeight">48dip</item> <item name="android:lineSpacingExtra">@dimen/line_spacing_extra</item> </style> + + <style name="ChipTitleStyle"> + <item name="android:paddingLeft">@dimen/chip_title_padding_start</item> + </style> + + <style name="ChipSubtitleStyle"> + <item name="android:paddingLeft">@dimen/chip_subtitle_padding_start</item> + </style> + + <style name="ChipIconStyle"> + <item name="android:layout_marginLeft">@dimen/chip_icon_margin_start</item> + </style> </resources> 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()); @@ -653,6 +654,19 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements } /** + * 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))); } /** |