am 51401366: am b74a98d1: am 263ca4e5: am 2b8b9029: Support RTL in chips library.

* commit '51401366c84d0285d69b7a967d14465a4702671d':
  Support RTL in chips library.
diff --git a/Android.mk b/Android.mk
index ef4b8ab..2bca597 100644
--- a/Android.mk
+++ b/Android.mk
@@ -17,7 +17,7 @@
 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/AndroidManifest.xml b/AndroidManifest.xml
index 7487c18..02ea564 100644
--- a/AndroidManifest.xml
+++ b/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/res/layout/chips_recipient_dropdown_item.xml b/res/layout/chips_recipient_dropdown_item.xml
index cd11d67..b02b197 100644
--- a/res/layout/chips_recipient_dropdown_item.xml
+++ b/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/res/values-v17/styles-v17.xml b/res/values-v17/styles-v17.xml
new file mode 100644
index 0000000..d151a75
--- /dev/null
+++ b/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/res/values/attrs.xml b/res/values/attrs.xml
index 6b26bcb..96d995a 100644
--- a/res/values/attrs.xml
+++ b/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/res/values/dimen.xml b/res/values/dimen.xml
index 98354d2..f989c86 100644
--- a/res/values/dimen.xml
+++ b/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/res/values/styles.xml b/res/values/styles.xml
index 8e2abf9..83f96b4 100644
--- a/res/values/styles.xml
+++ b/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/src/com/android/ex/chips/RecipientEditTextView.java b/src/com/android/ex/chips/RecipientEditTextView.java
index b355c1b..e48a3b1 100644
--- a/src/com/android/ex/chips/RecipientEditTextView.java
+++ b/src/com/android/ex/chips/RecipientEditTextView.java
@@ -152,13 +152,13 @@
 
     /**
      * 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 @@
         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 @@
         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 @@
     }
 
     /**
+     * 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 @@
         }
 
         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)));
     }
 
     /**