Made collapse/expand a manual action.

It now opens and closes based upon user interaction
alone rather than on focus. Also, the header is always
visible, even when all of the attachments are visible.
Clicking it causes the attachments to collapse.

Change-Id: Icec76f8260241c7bceb39209c60625c4d96a9d0d
diff --git a/res/layout/compose_attachments.xml b/res/layout/compose_attachments.xml
index 382db81..26f75d0 100644
--- a/res/layout/compose_attachments.xml
+++ b/res/layout/compose_attachments.xml
@@ -19,26 +19,18 @@
     <GridLayout
         android:id="@+id/attachment_collapse_view"
         android:layout_width="match_parent"
-        android:layout_height="wrap_content"
+        android:layout_height="48dip"
         android:orientation="horizontal"
-        android:background="@drawable/attachment_bg_holo"
-        android:rowCount="1"
-        android:columnCount="3"
-        android:visibility="gone">
-        <ImageView
-            android:id="@+id/attachment_collapse_preview_icon"
-            android:layout_width="48dip"
-            android:layout_height="48dip"
-            android:layout_row="0"
-            android:layout_column="0"
-            android:scaleType="center"
-            android:src="@drawable/ic_menu_attachment_holo_light"/>
+        android:background="?android:attr/selectableItemBackground"
+        android:rowCount="2"
+        android:columnCount="2"
+        android:visibility="visible">
         <TextView
             android:id="@+id/attachment_collapse_text"
             android:layout_width="0dip"
             android:layout_height="wrap_content"
             android:layout_row="0"
-            android:layout_column="1"
+            android:layout_column="0"
             android:layout_gravity="fill_horizontal|center_vertical"
             android:textAppearance="?android:attr/textAppearanceSmall"
             android:textAllCaps="true"
@@ -46,21 +38,21 @@
             android:singleLine="true"
             android:ellipsize="end" />
         <ImageView
+            android:id="@+id/attachment_collapse_caret"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_row="0"
-            android:layout_column="2"
+            android:layout_column="1"
             android:layout_gravity="center_vertical"
             android:layout_marginRight="8dip"
             android:src="@drawable/ic_menu_expander_minimized_holo_light"/>
         <View
-            android:layout_width="0dip"
-            android:layout_height="0dip"
-            android:layout_row="0"
+            android:layout_width="match_parent"
+            android:layout_height="@dimen/message_details_header_bottom_border_height"
+            android:layout_row="1"
             android:layout_column="0"
-            android:layout_columnSpan="3"
-            android:layout_gravity="fill"
-            android:background="?android:attr/selectableItemBackground"
+            android:layout_columnSpan="2"
+            android:background="@color/conv_subject_border"
             />
     </GridLayout>
     <com.android.mail.ui.AttachmentTileGrid
diff --git a/src/com/android/mail/compose/AttachmentsView.java b/src/com/android/mail/compose/AttachmentsView.java
index 2ea0581..725b72d 100644
--- a/src/com/android/mail/compose/AttachmentsView.java
+++ b/src/com/android/mail/compose/AttachmentsView.java
@@ -20,7 +20,6 @@
 import android.content.res.Resources;
 import android.database.Cursor;
 import android.database.sqlite.SQLiteException;
-import android.graphics.Bitmap;
 import android.net.Uri;
 import android.os.ParcelFileDescriptor;
 import android.provider.OpenableColumns;
@@ -41,10 +40,8 @@
 import com.android.mail.providers.Attachment;
 import com.android.mail.providers.Message;
 import com.android.mail.providers.UIProvider;
-import com.android.mail.ui.AttachmentBitmapHolder;
 import com.android.mail.ui.AttachmentTile;
 import com.android.mail.ui.AttachmentTileGrid;
-import com.android.mail.ui.ThumbnailLoadTask;
 import com.android.mail.utils.LogUtils;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.Lists;
@@ -56,7 +53,7 @@
 /*
  * View for displaying attachments in the compose screen.
  */
-class AttachmentsView extends LinearLayout implements AttachmentBitmapHolder, OnClickListener {
+class AttachmentsView extends LinearLayout implements OnClickListener {
     private static final String LOG_TAG = new LogUtils().getLogTag();
 
     private final Resources mResources;
@@ -67,10 +64,9 @@
     private LinearLayout mAttachmentLayout;
     private GridLayout mCollapseLayout;
     private TextView mCollapseText;
-    private ImageView mCollapseImage;
+    private ImageView mCollapseCaret;
 
-    private ThumbnailLoadTask mThumbnailTask;
-    private Attachment mPreviewAttachment;
+    private boolean mIsExpanded;
 
     public AttachmentsView(Context context) {
         this(context, null);
@@ -90,7 +86,7 @@
         mAttachmentLayout = (LinearLayout) findViewById(R.id.attachment_bar_list);
         mCollapseLayout = (GridLayout) findViewById(R.id.attachment_collapse_view);
         mCollapseText = (TextView) findViewById(R.id.attachment_collapse_text);
-        mCollapseImage = (ImageView) findViewById(R.id.attachment_collapse_preview_icon);
+        mCollapseCaret = (ImageView) findViewById(R.id.attachment_collapse_caret);
 
         mCollapseLayout.setOnClickListener(this);
     }
@@ -99,47 +95,47 @@
     public void onClick(View view) {
         switch (view.getId()) {
             case R.id.attachment_collapse_view:
-                expandView();
+                if (mIsExpanded) {
+                    collapseView();
+                } else {
+                    expandView();
+                }
                 break;
         }
     }
 
+    public void expandView() {
+        mTileGrid.setVisibility(VISIBLE);
+        mAttachmentLayout.setVisibility(VISIBLE);
+        setupCollapsibleView(false);
+        mIsExpanded = true;
+    }
+
     public void collapseView() {
         mTileGrid.setVisibility(GONE);
         mAttachmentLayout.setVisibility(GONE);
 
         // If there are some attachments, show the preview
         if (!mAttachments.isEmpty()) {
-            // setup text
-            final int numAttachments = mAttachments.size();
-            final String attachmentText = mResources.getQuantityString(
-                    R.plurals.number_of_attachments, numAttachments, numAttachments);
-            mCollapseText.setText(attachmentText);
-
-            // setup icon
-            final Attachment previousAttachment = mPreviewAttachment;
-            mPreviewAttachment = getFirstTiledAttachment();
-            ThumbnailLoadTask.setupThumbnailPreview(
-                    mThumbnailTask, this, mPreviewAttachment, previousAttachment);
-
+            setupCollapsibleView(true);
             mCollapseLayout.setVisibility(VISIBLE);
         }
+
+        mIsExpanded = false;
     }
 
-    private Attachment getFirstTiledAttachment() {
-        for (final Attachment attachment : mAttachments) {
-            if (AttachmentTile.isTiledAttachment(attachment)) {
-                return attachment;
-            }
+    private void setupCollapsibleView(boolean isCollapsed) {
+        // setup text
+        final int numAttachments = mAttachments.size();
+        final String attachmentText = mResources.getQuantityString(
+                R.plurals.number_of_attachments, numAttachments, numAttachments);
+        mCollapseText.setText(attachmentText);
+
+        if (isCollapsed) {
+            mCollapseCaret.setImageResource(R.drawable.ic_menu_expander_minimized_holo_light);
+        } else {
+            mCollapseCaret.setImageResource(R.drawable.ic_menu_expander_maximized_holo_light);
         }
-
-        return null;
-    }
-
-    public void expandView() {
-        mTileGrid.setVisibility(VISIBLE);
-        mAttachmentLayout.setVisibility(VISIBLE);
-        mCollapseLayout.setVisibility(GONE);
     }
 
     /**
@@ -157,9 +153,10 @@
     public void addAttachment(final Attachment attachment) {
         if (!isShown()) {
             setVisibility(View.VISIBLE);
-            expandView();
         }
+
         mAttachments.add(attachment);
+        expandView();
 
         // If we have an attachment that should be shown in a tiled look,
         // set up the tile and add it to the tile grid.
@@ -203,6 +200,8 @@
         if (mAttachments.size() == 0) {
             setVisibility(View.GONE);
             collapseView();
+        } else {
+            setupCollapsibleView(true);
         }
     }
 
@@ -458,29 +457,4 @@
             super(detailMessage, throwable);
         }
     }
-
-    @Override
-    public int getThumbnailWidth() {
-        return mCollapseImage.getWidth();
-    }
-
-    @Override
-    public int getThumbnailHeight() {
-        return mCollapseImage.getHeight();
-    }
-
-    @Override
-    public void setThumbnail(Bitmap result) {
-        mCollapseImage.setImageBitmap(result);
-    }
-
-    @Override
-    public void setThumbnailToDefault() {
-        mCollapseImage.setImageResource(R.drawable.ic_menu_attachment_holo_light);
-    }
-
-    @Override
-    public ContentResolver getResolver() {
-        return getContext().getContentResolver();
-    }
 }
diff --git a/src/com/android/mail/compose/ComposeActivity.java b/src/com/android/mail/compose/ComposeActivity.java
index 687914d..9a7d15b 100644
--- a/src/com/android/mail/compose/ComposeActivity.java
+++ b/src/com/android/mail/compose/ComposeActivity.java
@@ -98,7 +98,7 @@
 
 public class ComposeActivity extends Activity implements OnClickListener, OnNavigationListener,
         RespondInlineListener, DialogInterface.OnClickListener, TextWatcher,
-        AttachmentDeletedListener, OnAccountChangedListener, OnFocusChangeListener {
+        AttachmentDeletedListener, OnAccountChangedListener {
     // Identifiers for which type of composition this is
     static final int COMPOSE = -1;
     static final int REPLY = 0;
@@ -278,7 +278,6 @@
         super.onCreate(savedInstanceState);
         setContentView(R.layout.compose);
         findViews();
-        setFocusListeners();
         Intent intent = getIntent();
         Account account = null;
         Message message;
@@ -786,22 +785,6 @@
         mFromSpinner = (FromAddressSpinner) findViewById(R.id.from_picker);
     }
 
-    private void setFocusListeners() {
-        mTo.setOnFocusChangeListener(this);
-        mCc.setOnFocusChangeListener(this);
-        mBcc.setOnFocusChangeListener(this);
-        mSubject.setOnFocusChangeListener(this);
-        mQuotedTextView.setOnFocusChangeListener(this);
-        mBodyView.setOnFocusChangeListener(this);
-    }
-
-    @Override
-    public void onFocusChange(View v, boolean hasFocus) {
-        if (hasFocus) {
-            mAttachmentsView.collapseView();
-        }
-    }
-
     protected TextView getBody() {
         return mBodyView;
     }