RTL - attachment tiles. Fixes b/12037028.

Also fixes a bug in compose tiles where the
attachment title and subtitle weren't being shown.

Change-Id: Ia568672abbd2503f95882473f71237710fca02da
diff --git a/res/layout/compose_attachment_tile.xml b/res/layout/compose_attachment_tile.xml
index 376d23c..14a68ce 100644
--- a/res/layout/compose_attachment_tile.xml
+++ b/res/layout/compose_attachment_tile.xml
@@ -26,23 +26,22 @@
 
     <include layout="@layout/attachment_preview"/>
 
-    <RelativeLayout
+    <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:background="@color/attachment_tile_shadow_box_color"
         android:layout_alignParentBottom="true"
         android:gravity="center_vertical"
-        android:paddingLeft="8dip">
+        style="@style/AttachmentTextContainer" >
 
         <LinearLayout
-            android:layout_width="match_parent"
+            android:layout_width="0dip"
             android:layout_height="wrap_content"
-            android:layout_alignParentLeft="true"
-            android:layout_toLeftOf="@+id/attachment_tile_close_button"
+            android:layout_weight="1"
             android:orientation="vertical"
             android:gravity="center_vertical"
-            android:layout_centerVertical="true"
-            android:paddingRight="4dip">
+            android:layout_gravity="center_vertical"
+            style="@style/ComposeAttachmentTileTextEndStyle">
 
             <TextView
                 android:id="@+id/attachment_tile_title"
@@ -72,15 +71,15 @@
         </LinearLayout>
 
         <ImageButton
-            android:id="@id/attachment_tile_close_button"
+            android:id="@+id/attachment_tile_close_button"
             android:src="@drawable/ic_attach_cancel"
             android:layout_width="44dip"
             android:layout_height="44dip"
+            android:layout_gravity="center_vertical|end|right"
             android:gravity="center"
             android:focusable="true"
-            android:background="?android:attr/selectableItemBackground"
-            android:layout_alignParentRight="true" />
+            android:background="?android:attr/selectableItemBackground" />
 
-    </RelativeLayout>
+    </LinearLayout>
 
 </com.android.mail.compose.ComposeAttachmentTile>
diff --git a/src/com/android/mail/compose/ComposeAttachmentTile.java b/src/com/android/mail/compose/ComposeAttachmentTile.java
index 7038455..022fbe1 100644
--- a/src/com/android/mail/compose/ComposeAttachmentTile.java
+++ b/src/com/android/mail/compose/ComposeAttachmentTile.java
@@ -18,6 +18,8 @@
 
     public ComposeAttachmentTile(Context context, AttributeSet attrs) {
         super(context, attrs);
+
+        setAlwaysShowInfoText(true);
     }
 
     public static ComposeAttachmentTile inflate(LayoutInflater inflater, ViewGroup parent) {
diff --git a/src/com/android/mail/ui/AttachmentTile.java b/src/com/android/mail/ui/AttachmentTile.java
index 1ca5f76..63542fa 100644
--- a/src/com/android/mail/ui/AttachmentTile.java
+++ b/src/com/android/mail/ui/AttachmentTile.java
@@ -59,6 +59,8 @@
     // considered skinny
     private static final float skinnyThresholdRatio = 0.5f;
 
+    private boolean mAlwaysShowInfoText;
+
 
     /**
      * Returns true if the attachment should be rendered as a tile. with a large image preview.
@@ -76,6 +78,7 @@
     public AttachmentTile(Context context, AttributeSet attrs) {
         super(context, attrs);
         mDefaultThumbnailSet = true;
+        mAlwaysShowInfoText = false;
     }
 
     @Override
@@ -167,8 +170,10 @@
 
         // We got a real thumbnail; hide the default thumbnail.
         mDefaultIcon.setVisibility(View.GONE);
-        mTitle.setVisibility(View.GONE);
-        mSubtitle.setVisibility(View.GONE);
+        if (!mAlwaysShowInfoText) {
+            mTitle.setVisibility(View.GONE);
+            mSubtitle.setVisibility(View.GONE);
+        }
 
         final int maxSize = getResources().getInteger(R.integer.attachment_preview_max_size);
         final int width = result.getWidth();
@@ -281,4 +286,8 @@
     public void thumbnailLoadFailed() {
         setThumbnailToDefault();
     }
+
+    protected void setAlwaysShowInfoText(boolean alwaysShowInfoText) {
+        mAlwaysShowInfoText = alwaysShowInfoText;
+    }
 }
diff --git a/src/com/android/mail/ui/AttachmentTileGrid.java b/src/com/android/mail/ui/AttachmentTileGrid.java
index 018cea2..2bb2acd 100644
--- a/src/com/android/mail/ui/AttachmentTileGrid.java
+++ b/src/com/android/mail/ui/AttachmentTileGrid.java
@@ -32,6 +32,7 @@
 import com.android.mail.ui.AttachmentTile.AttachmentPreview;
 import com.android.mail.ui.AttachmentTile.AttachmentPreviewCache;
 
+import com.android.mail.utils.ViewUtils;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 
@@ -162,9 +163,15 @@
 
     private void onLayoutForTiles() {
         final int count = getChildCount();
-        int childLeft = 0;
-        int childTop = 0;
+        if (count == 0) {
+            return;
+        }
+
         boolean skipBeginningOfRowFirstTime = true;
+        final boolean isRtl = ViewUtils.isViewRtl(this);
+        final int width = getMeasuredWidth();
+        int childLeft = (isRtl) ? width - getChildAt(0).getMeasuredWidth() : 0;;
+        int childTop = 0;
 
         // Layout the grid.
         for (int i = 0; i < count; i++) {
@@ -178,7 +185,7 @@
             // in the grid, reset childLeft to 0 and update childTop
             // to reflect the top of the new row.
             if (!skipBeginningOfRowFirstTime && i % mColumnCount == 0) {
-                childLeft = 0;
+                childLeft = (isRtl) ? width - childWidth : 0;
                 childTop += childHeight;
             } else {
                 skipBeginningOfRowFirstTime = false;
@@ -186,7 +193,12 @@
 
             child.layout(childLeft, childTop,
                     childLeft + childWidth, childTop + childHeight);
-            childLeft += childWidth;
+
+            if (isRtl) {
+                childLeft -= childWidth;
+            } else {
+                childLeft += childWidth;
+            }
         }
     }