Start showing label list on tablets

Change-Id: Ib5529ce2eca88c71979ed0bc6340cb2a752ffd25
diff --git a/res/drawable-hdpi/label_bg_holo_light.9.png b/res/drawable-hdpi/folder_bg_holo_light.9.png
similarity index 100%
rename from res/drawable-hdpi/label_bg_holo_light.9.png
rename to res/drawable-hdpi/folder_bg_holo_light.9.png
Binary files differ
diff --git a/res/drawable-mdpi/label_bg_holo_light.9.png b/res/drawable-mdpi/folder_bg_holo_light.9.png
similarity index 100%
rename from res/drawable-mdpi/label_bg_holo_light.9.png
rename to res/drawable-mdpi/folder_bg_holo_light.9.png
Binary files differ
diff --git a/res/drawable-sw600dp-hdpi/label_bg_holo_light.9.png b/res/drawable-sw600dp-hdpi/folder_bg_holo_light.9.png
similarity index 100%
rename from res/drawable-sw600dp-hdpi/label_bg_holo_light.9.png
rename to res/drawable-sw600dp-hdpi/folder_bg_holo_light.9.png
Binary files differ
diff --git a/res/drawable-sw600dp-mdpi/label_bg_holo_light.9.png b/res/drawable-sw600dp-mdpi/folder_bg_holo_light.9.png
similarity index 100%
rename from res/drawable-sw600dp-mdpi/label_bg_holo_light.9.png
rename to res/drawable-sw600dp-mdpi/folder_bg_holo_light.9.png
Binary files differ
diff --git a/res/drawable-sw600dp-xhdpi/label_bg_holo_light.9.png b/res/drawable-sw600dp-xhdpi/folder_bg_holo_light.9.png
similarity index 100%
rename from res/drawable-sw600dp-xhdpi/label_bg_holo_light.9.png
rename to res/drawable-sw600dp-xhdpi/folder_bg_holo_light.9.png
Binary files differ
diff --git a/res/drawable-xhdpi/label_bg_holo_light.9.png b/res/drawable-xhdpi/folder_bg_holo_light.9.png
similarity index 100%
rename from res/drawable-xhdpi/label_bg_holo_light.9.png
rename to res/drawable-xhdpi/folder_bg_holo_light.9.png
Binary files differ
diff --git a/res/layout/label_switch_spinner_dropdown_item.xml b/res/layout/folder_switch_spinner_dropdown_item.xml
similarity index 100%
rename from res/layout/label_switch_spinner_dropdown_item.xml
rename to res/layout/folder_switch_spinner_dropdown_item.xml
diff --git a/res/layout/two_pane_activity.xml b/res/layout/two_pane_activity.xml
index fa6e943..7b08f4a 100644
--- a/res/layout/two_pane_activity.xml
+++ b/res/layout/two_pane_activity.xml
@@ -25,9 +25,10 @@
   android:layout_height="match_parent" >
 
   <FrameLayout
-    android:id="@+id/labels_pane"
-    android:layout_width="@dimen/label_list_pane_width"
-    android:layout_height="match_parent"/>
+    android:id="@+id/folders_pane"
+    android:layout_width="@dimen/folder_list_pane_width"
+    android:layout_height="match_parent"
+    android:background="@drawable/folder_bg_holo_light"/>
 
   <RelativeLayout
         android:layout_width="wrap_content"
diff --git a/res/values/constants.xml b/res/values/constants.xml
index fddacc1..4229c70 100644
--- a/res/values/constants.xml
+++ b/res/values/constants.xml
@@ -36,7 +36,7 @@
          different views. For the default layout (phone), these values
          are equal. These are only used in TwoPaneLayout, so they need
          to be specified for sw600dp and sw720dp layouts. -->
-    <integer name="label_list_weight">1</integer>
+    <integer name="folder_list_weight">1</integer>
     <integer name="conversation_list_weight">1</integer>
     <integer name="conversation_view_weight">1</integer>
     <!-- Max unread count to show for a folder -->
diff --git a/res/values/two_pane_dimen.xml b/res/values/two_pane_dimen.xml
index 712c227..c55ac0c 100644
--- a/res/values/two_pane_dimen.xml
+++ b/res/values/two_pane_dimen.xml
@@ -17,9 +17,8 @@
 -->
 
 <resources>
-    <dimen name="label_list_pane_width">320dip</dimen>
-    <dimen name="label_list_minimum_height">48dip</dimen>
-    <dimen name="label_list_label_color_width">36dip</dimen>
+    <dimen name="folder_list_pane_width">320dip</dimen>
+    <dimen name="folder_list_label_color_width">36dip</dimen>
     <dimen name="new_message_notification_width">896dip</dimen>
     <dimen name="empty_view_top_padding">38dip</dimen>
 </resources>
diff --git a/src/com/android/mail/browse/ConversationItemView.java b/src/com/android/mail/browse/ConversationItemView.java
index 7ccc5a0..f982669 100644
--- a/src/com/android/mail/browse/ConversationItemView.java
+++ b/src/com/android/mail/browse/ConversationItemView.java
@@ -176,7 +176,7 @@
             IMPORTANT_TO_OTHERS = BitmapFactory.decodeResource(res,
                     R.drawable.ic_email_caret_none_important_unread);
             ATTACHMENT = BitmapFactory.decodeResource(res, R.drawable.ic_attachment_holo_light);
-            DATE_BACKGROUND = BitmapFactory.decodeResource(res, R.drawable.label_bg_holo_light);
+            DATE_BACKGROUND = BitmapFactory.decodeResource(res, R.drawable.folder_bg_holo_light);
 
             // Initialize colors.
             DEFAULT_TEXT_COLOR = res.getColor(R.color.default_text_color);
diff --git a/src/com/android/mail/ui/AbstractActivityController.java b/src/com/android/mail/ui/AbstractActivityController.java
index 6613dbe..6714d15 100644
--- a/src/com/android/mail/ui/AbstractActivityController.java
+++ b/src/com/android/mail/ui/AbstractActivityController.java
@@ -149,15 +149,13 @@
     }
 
     @Override
-    public String getCurrentAccount() {
-        // TODO(viki): Auto-generated method stub
-        return null;
+    public Account getCurrentAccount() {
+        return mAccount;
     }
 
     @Override
     public ConversationListContext getCurrentListContext() {
-        // TODO(viki): Auto-generated method stub
-        return null;
+        return mConvListContext;
     }
 
     @Override
@@ -381,8 +379,6 @@
 
     @Override
     public void onResume() {
-        // TODO(viki): Auto-generated method stub
-        //        mBatchConversations.addObserver(this);
         if (mActionBarView != null) {
             mActionBarView.onResume();
         }
@@ -405,31 +401,26 @@
     @Override
     public void onSearchRequested() {
         // TODO(viki): Auto-generated method stub
-
     }
 
     @Override
     public void onStartBulkOperation() {
         // TODO(viki): Auto-generated method stub
-
     }
 
     @Override
     public void onStartDragMode() {
         // TODO(viki): Auto-generated method stub
-
     }
 
     @Override
     public void onStop() {
         // TODO(viki): Auto-generated method stub
-
     }
 
     @Override
     public void onStopDragMode() {
         // TODO(viki): Auto-generated method stub
-
     }
 
     /**
@@ -445,7 +436,7 @@
         // reset the action bar icon based on the mode. Why don't the individual controllers do
         // this themselves?
 
-        // On conversation list mode, clean up the conversation.
+        // In conversation list mode, clean up the conversation.
         if (newMode == ViewMode.CONVERSATION_LIST) {
             // Clean up the conversation here.
         }
@@ -460,13 +451,11 @@
     @Override
     public void onWindowFocusChanged(boolean hasFocus) {
         // TODO(viki): Auto-generated method stub
-
     }
 
     @Override
     public void reloadSearch(String string) {
         // TODO(viki): Auto-generated method stub
-
     }
 
     /**
@@ -488,9 +477,6 @@
     protected void restoreState(Bundle savedState) {
         if (savedState != null) {
             restoreListContext(savedState);
-            // Restore the list context
-            restoreListContext(savedState);
-
             // Attach the menu handler here.
 
             // Restore the view mode
@@ -507,19 +493,16 @@
     @Override
     public void startActionBarStatusCursorLoader(String account) {
         // TODO(viki): Auto-generated method stub
-
     }
 
     @Override
     public void stopActionBarStatusCursorLoader(String account) {
         // TODO(viki): Auto-generated method stub
-
     }
 
     @Override
     public void toggleStar(boolean toggleOn, long conversationId, long maxMessageId) {
         // TODO(viki): Auto-generated method stub
-
     }
 
     @Override
@@ -588,7 +571,6 @@
         // onLoadFinished will be called and we will be fine.
     }
 
-
     @Override
     public void onTouchEvent(MotionEvent event) {
         if (event.getAction() == MotionEvent.ACTION_DOWN) {
diff --git a/src/com/android/mail/ui/MailActionBar.java b/src/com/android/mail/ui/MailActionBar.java
index 728cd13..af17028 100644
--- a/src/com/android/mail/ui/MailActionBar.java
+++ b/src/com/android/mail/ui/MailActionBar.java
@@ -68,7 +68,7 @@
         /**
          * Returns the current account.
          */
-        String getCurrentAccount();
+        Account getCurrentAccount();
 
         /**
          * Called when the TwoPaneActionBar wants to get the current conversation list context.
diff --git a/src/com/android/mail/ui/TwoPaneController.java b/src/com/android/mail/ui/TwoPaneController.java
index 3204e7a..c7b7c9a 100644
--- a/src/com/android/mail/ui/TwoPaneController.java
+++ b/src/com/android/mail/ui/TwoPaneController.java
@@ -52,6 +52,13 @@
         if (show) {
             mViewMode.enterConversationListMode();
         }
+        renderConversationList();
+    }
+
+    /**
+     * Render the conversation list in the correct pane.
+     */
+    private void renderConversationList() {
         FragmentTransaction fragmentTransaction = mActivity.getFragmentManager().beginTransaction();
         // Use cross fading animation.
         fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
@@ -61,6 +68,19 @@
         fragmentTransaction.commitAllowingStateLoss();
     }
 
+    /**
+     * Render the folder list in the correct pane.
+     */
+    private void renderFolderList() {
+        Fragment folderListFragment = FolderListFragment.newInstance(this, mAccount.folderListUri);
+        FragmentTransaction fragmentTransaction = mActivity.getFragmentManager().beginTransaction();
+        fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
+        fragmentTransaction.replace(R.id.folders_pane, folderListFragment);
+        fragmentTransaction.commitAllowingStateLoss();
+        // Since we are showing the folder list, we are at the start of the view stack.
+        resetActionBarIcon();
+    }
+
     @Override
     protected boolean isConversationListVisible() {
         // TODO(viki): Auto-generated method stub
@@ -70,17 +90,19 @@
     @Override
     public void showConversationList(ConversationListContext context) {
         initializeConversationListFragment(true);
+        renderFolderList();
     }
 
     @Override
     public void showFolderList() {
-        // TODO: auto-generated method stub.
+        // On two-pane layouts, showing the folder list takes you to the top level of the
+        // application, which is the same as pressing the Up button
+        onUpPressed();
     }
 
     @Override
     public boolean onCreate(Bundle savedState) {
         mActivity.setContentView(R.layout.two_pane_activity);
-
         mLayout = (TwoPaneLayout) mActivity.findViewById(R.id.two_pane_activity);
         mLayout.initializeLayout(mActivity.getApplicationContext());
 
@@ -90,11 +112,6 @@
         mLayout.setListener(this);
 
         final boolean isParentInitialized = super.onCreate(savedState);
-        if (isParentInitialized && savedState == null) {
-            // Show a Label list, in the real application
-            // renderLabelList();
-            // In our case, we show a conversation list for everything.
-        }
         return isParentInitialized;
     }
 
@@ -122,13 +139,32 @@
         mViewMode.enterConversationMode();
     }
 
-    @Override
-    public boolean onUpPressed() {
+    /**
+     * Show the conversation list if it can be shown in the current orientation.
+     * @return true if the conversation list was shown
+     */
+    private boolean unhideConversationList(){
+        // Find if the conversation list can be shown
+        final boolean isConversationListShowable =
+                (mViewMode.getMode() == ViewMode.CONVERSATION &&
+                mLayout.isConversationListCollapsible());
+        if (isConversationListShowable) {
+            return mLayout.uncollapseList();
+        }
         return false;
     }
 
     @Override
+    public boolean onUpPressed() {
+        return unhideConversationList();
+    }
+
+    @Override
     public boolean onBackPressed() {
-        return false;
+        if (!(mViewMode.getMode() == ViewMode.CONVERSATION)){
+            return mViewMode.enterConversationListMode();
+        }
+        mActivity.finish();
+        return true;
     }
 }
diff --git a/src/com/android/mail/ui/TwoPaneLayout.java b/src/com/android/mail/ui/TwoPaneLayout.java
index 0d132af..c96c9b0 100644
--- a/src/com/android/mail/ui/TwoPaneLayout.java
+++ b/src/com/android/mail/ui/TwoPaneLayout.java
@@ -58,14 +58,14 @@
  * according to the specific <i>modes</i> the {@link Activity} can be in.
  *
  * Currently, the layout differs in three dimensions: orientation, two aspects of view modes.
- * This results in essentially three states: One where the labels are on the left and conversation
+ * This results in essentially three states: One where the folders are on the left and conversation
  * list is on the right, and two states where the conversation list is on the left: one in which
  * it's collapsed and another where it is not.
  *
- * In Label or conversation list view, conversations are hidden and labels and conversation lists
+ * In folder or conversation list view, conversations are hidden and folders and conversation lists
  * are visible. This is the case in both portrait and landscape
  *
- * In Conversation List or Conversation View, labels are hidden, and conversation lists and
+ * In Conversation List or Conversation View, folders are hidden, and conversation lists and
  * conversation view is visible. This is the case in both portrait and landscape.
  *
  * In the Gmail source code, this was called TriStateSplitLayout
@@ -86,7 +86,7 @@
     private static int sAnimationSlideLeftDuration;
     private static int sAnimationSlideRightDuration;
     private static double sScaledConversationListWeight;
-    private static double sScaledLabelListWeight;
+    private static double sScaledFolderListWeight;
     /**
      * The current mode that the tablet layout is in. This is a constant integer that holds values
      * that are {@link ViewMode} constants like {@link ViewMode#CONVERSATION}.
@@ -106,8 +106,8 @@
     private View mConversationView;
     private View mConversationViewOverlay;
     /** Left position of each fragment. */
-    private int mLabelsLeft;
-    private View mLabelsView;
+    private int mFoldersLeft;
+    private View mFoldersView;
     private int mListAlpha;
 
     /** Captured bitmap of each fragment. */
@@ -197,7 +197,7 @@
         public void onAnimationStart(Animator animation) {
             switch (listener_type) {
                 case CONVERSATION_LIST:
-                    mLabelsView.setVisibility(View.VISIBLE);
+                    mFoldersView.setVisibility(View.VISIBLE);
             }
         }
     }
@@ -290,7 +290,7 @@
     private int computeConversationListWidth(int totalWidth) {
         switch (currentMode) {
             case ViewMode.CONVERSATION_LIST:
-                return totalWidth - computeLabelListWidth();
+                return totalWidth - computeFolderListWidth();
             case ViewMode.CONVERSATION:
                 return (int) (totalWidth * sScaledConversationListWeight);
         }
@@ -322,17 +322,10 @@
     }
 
     /**
-     * Computes the width of the label list in stable state of the current mode.
+     * Computes the width of the folder list in stable state of the current mode.
      */
-    private int computeLabelListWidth() {
-        return computeLabelListWidth(getMeasuredWidth());
-    }
-
-    /**
-     * Computes the width of the label list in stable state of the current mode.
-     */
-    private int computeLabelListWidth(int totalWidth) {
-        return (int) (totalWidth * sScaledLabelListWeight);
+    private int computeFolderListWidth() {
+        return (int) (getMeasuredWidth() * sScaledFolderListWeight);
     }
 
     /**
@@ -374,8 +367,8 @@
         }
 
         canvas.save();
-        canvas.translate(mLabelsLeft, 0);
-        mLabelsView.draw(canvas);
+        canvas.translate(mFoldersLeft, 0);
+        mFoldersView.draw(canvas);
         canvas.restore();
 
         // The bitmap can be null if the view hasn't been drawn by the time we capture the bitmap.
@@ -402,21 +395,21 @@
         // On the initial call, measurements may not have been done (i.e. this
         // Layout has never been rendered), so no animation will be done.
         if (getMeasuredWidth() == 0) {
-            mLabelsView.setVisibility(View.VISIBLE);
+            mFoldersView.setVisibility(View.VISIBLE);
             onFinishEnteringConversationListMode();
             return;
         }
 
-        // Slide labels in from the left.
-        setLabelListWidth(computeLabelListWidth());
+        // Slide folder list in from the left.
+        final int folderListWidth = computeFolderListWidth();
+        setFolderListWidth(folderListWidth);
 
         // Prepare animation.
         mAnimatingFade = true;
         captureListBitmaps();
         ArrayList<PropertyValuesHolder> values = Lists.newArrayList();
 
-        int labelsWidth = computeLabelListWidth();
-        values.add(PropertyValuesHolder.ofInt("labelsLeft", -labelsWidth, 0));
+        values.add(PropertyValuesHolder.ofInt("foldersLeft", -folderListWidth, 0));
 
         // Reset the relative left of the list view.
         setConversationListLeft(0);
@@ -430,8 +423,8 @@
         animator.setDuration((long) (sAnimationSlideRightDuration * SLIDE_DURATION_SCALE));
         animator.setInterpolator(sRightInterpolator);
 
-        values.add(PropertyValuesHolder.ofInt("listBitmapLeft", 0, labelsWidth));
-        values.add(PropertyValuesHolder.ofInt("listLeft", 0, labelsWidth));
+        values.add(PropertyValuesHolder.ofInt("listBitmapLeft", 0, folderListWidth));
+        values.add(PropertyValuesHolder.ofInt("listLeft", 0, folderListWidth));
         values.add(PropertyValuesHolder.ofInt("listAlpha", 0, 255));
 
         // Slide conversation out to the right.
@@ -465,9 +458,9 @@
         captureListBitmaps();
         ArrayList<PropertyValuesHolder> values = Lists.newArrayList();
 
-        // Slide labels out towards the left off screen.
-        int labelsWidth = mLabelsView.getMeasuredWidth();
-        values.add(PropertyValuesHolder.ofInt("labelsLeft", 0, -labelsWidth));
+        // Slide folders out towards the left off screen.
+        int foldersWidth = mFoldersView.getMeasuredWidth();
+        values.add(PropertyValuesHolder.ofInt("foldersLeft", 0, -foldersWidth));
 
         // Shrink the conversation list to make room for the conversation, and default
         // it to collapsed in case it is collapsible.
@@ -475,7 +468,7 @@
         int targetWidth = computeConversationListWidth();
         setConversationListWidth(targetWidth);
 
-        int currentListLeft = labelsWidth + getConversationListLeft();
+        int currentListLeft = foldersWidth + getConversationListLeft();
         int targetListLeft = computeConversationListLeft(targetWidth);
         setConversationListLeft(targetListLeft);
         if (currentListLeft != targetListLeft) {
@@ -516,7 +509,7 @@
         mContext = context;
 
         Resources res = getResources();
-        mLabelsView = findViewById(R.id.labels_pane);
+        mFoldersView = findViewById(R.id.folders_pane);
         mConversationListContainer = findViewById(R.id.conversation_column_container);
         mListView = findViewById(R.id.conversation_list);
         mConversationView = findViewById(R.id.conversation_pane_container);
@@ -527,14 +520,13 @@
         sAnimationSlideLeftDuration = res.getInteger(R.integer.activity_slide_left_duration);
         sAnimationSlideRightDuration = res.getInteger(R.integer.activity_slide_right_duration);
         sAnimationCollapseDuration = res.getInteger(R.integer.activity_collapse_duration);
-        final int sLabelListWeight = res.getInteger(R.integer.label_list_weight);
+        final int sFolderListWeight = res.getInteger(R.integer.folder_list_weight);
         final int sConversationListWeight = res.getInteger(R.integer.conversation_list_weight);
         final int sConversationViewWeight = res.getInteger(R.integer.conversation_view_weight);
-        sScaledLabelListWeight = (double) sLabelListWeight
-                / (sLabelListWeight + sConversationListWeight);
+        sScaledFolderListWeight = (double) sFolderListWeight
+                / (sFolderListWeight + sConversationListWeight);
         sScaledConversationListWeight = (double) sConversationListWeight
                 / (sConversationListWeight + sConversationViewWeight);
-
         mPaint = new Paint();
         mPaint.setAntiAlias(true);
         mPaint.setColor(android.R.color.white);
@@ -547,7 +539,7 @@
     }
 
     /**
-     * @return whether the conversation list can be collapsed or not.
+     * @return whether the conversation list can be collapsed or not. This depends on orientation.
      */
     public boolean isConversationListCollapsible() {
         return mContext.getResources().getInteger(R.integer.conversation_list_collapsible) != 0;
@@ -575,6 +567,7 @@
         mListCollapsed = false;
         mConversationView.setVisibility(View.GONE);
         mConversationViewOverlay.setVisibility(View.GONE);
+        mFoldersView.setVisibility(View.VISIBLE);
 
         // Once animations settle, the conversation list always takes up the
         // remaining space that is on the right, so avoid hard pixel values,
@@ -591,14 +584,11 @@
      * Finalizes state after animations settle when entering conversation mode.
      */
     private void onFinishEnteringConversationMode() {
-        mLabelsView.setVisibility(View.GONE);
-
+        mFoldersView.setVisibility(View.GONE);
         setConversationListWidth(computeConversationListWidth());
-
         if (isConversationListCollapsible()) {
             onCollapseList();
         }
-
         dispatchConversationVisibilityChanged(true);
     }
 
@@ -620,7 +610,7 @@
 
         switch (currentMode) {
             case ViewMode.CONVERSATION_LIST:
-                setLabelListWidth(computeLabelListWidth());
+                setFolderListWidth(computeFolderListWidth());
                 break;
 
             case ViewMode.CONVERSATION:
@@ -674,7 +664,6 @@
                 enterConversationListMode();
                 break;
             case ViewMode.FOLDER_LIST:
-                // Show Folder lists here
                 break;
             case ViewMode.SEARCH_RESULTS:
                 // Show search results here
@@ -718,12 +707,12 @@
     }
 
     /**
-     * Sets the width of the label list pane.
+     * Sets the width of the folder list pane.
      * Used internally and by animators. Not to be used externally.
      */
-    private void setLabelListWidth(int width) {
-        mLabelsView.getLayoutParams().width = width;
-        // Mindy points out that this is strange. Instead of requesting a layout for the labels
+    private void setFolderListWidth(int width) {
+        mFoldersView.getLayoutParams().width = width;
+        // Mindy points out that this is strange. Instead of requesting a layout for the folders
         // view, we should be requesting a layout for the entire view.
         // TODO(viki): Change to this.requestLayout() and see if there is any improvement or loss
         requestLayout();
@@ -732,12 +721,12 @@
     // TODO(viki): I think most of the next methods aren't being used. Rather than removing them,
     // I'm marking them private to remove once the application is complete.
     /**
-     * Sets the left position of the labels fragment. Used by animators. Not to
+     * Sets the left position of the folders fragment. Used by animators. Not to
      * be used externally.
      * @hide
      */
-    private void setLabelsLeft(int left) {
-        mLabelsLeft = left;
+    private void setFoldersLeft(int left) {
+        mFoldersLeft = left;
         invalidate();
     }