Merge "Use new picture/video attachment assets." into jb-ub-mail
diff --git a/assets/script.js b/assets/script.js
index ee15d03..45b72a0 100644
--- a/assets/script.js
+++ b/assets/script.js
@@ -67,8 +67,8 @@
     var i;
     var elements = document.getElementsByClassName("mail-message-content");
     var messageElement;
-    var documentWidth = document.documentElement.offsetWidth;
-    var scale;
+    var documentWidth = document.body.offsetWidth;
+
     for (i = 0; i < elements.length; i++) {
         messageElement = elements[i];
         messageElement.style.zoom = documentWidth / messageElement.scrollWidth;
diff --git a/res/layout/conversation_view.xml b/res/layout/conversation_view.xml
index 438e2b8..295833d 100644
--- a/res/layout/conversation_view.xml
+++ b/res/layout/conversation_view.xml
@@ -34,7 +34,9 @@
     <FrameLayout
         android:id="@+id/conversation_topmost_overlay"
         android:layout_width="match_parent"
-        android:layout_height="match_parent">
+        android:layout_height="match_parent"
+        android:layout_marginLeft="@dimen/conversation_view_margin_side"
+        android:layout_marginRight="@dimen/conversation_view_margin_side">
 
         <include layout="@layout/conversation_message_header"
             android:id="@+id/snap_header"
diff --git a/res/layout/new_message_notification_bar.xml b/res/layout/new_message_notification_bar.xml
index b14f607..82dc342 100644
--- a/res/layout/new_message_notification_bar.xml
+++ b/res/layout/new_message_notification_bar.xml
@@ -18,8 +18,6 @@
 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_marginBottom="12dp"
-    android:layout_marginLeft="@dimen/new_message_notification_margin_side"
-    android:layout_marginRight="@dimen/new_message_notification_margin_side"
     android:animateLayoutChanges="true"
     android:background="@android:color/white">
 
diff --git a/res/layout/swipe_leavebehind.xml b/res/layout/swipe_leavebehind.xml
index 3aa7c40..9344249 100644
--- a/res/layout/swipe_leavebehind.xml
+++ b/res/layout/swipe_leavebehind.xml
@@ -42,7 +42,7 @@
             android:paddingLeft="16dip"
             android:clickable="true"
             android:layout_gravity="center_vertical"
-            android:gravity="center_vertical" />
+            android:gravity="center_vertical"/>
 
         <View
             android:id="@+id/undo_separator"
diff --git a/res/raw/template_conversation_upper.html b/res/raw/template_conversation_upper.html
index 32b884d..ed45f30 100644
--- a/res/raw/template_conversation_upper.html
+++ b/res/raw/template_conversation_upper.html
@@ -22,5 +22,5 @@
     }
   </style>
 </head>
-<body style="margin: 0;">
+<body style="margin: 0 %spx;">
 <div id="conversation-header" style="height: %spx;"></div>
diff --git a/res/raw/template_message.html b/res/raw/template_message.html
index 97784ee..f000215 100644
--- a/res/raw/template_message.html
+++ b/res/raw/template_message.html
@@ -1,5 +1,5 @@
 <div id="%s" class="mail-message %s">
     <div class="mail-message-header spacer" style="height: %spx;"></div>
-    <div class="mail-message-content collapsible %s" style="display: %s; zoom: %s; padding: 16px;">%s</div>
+    <div class="mail-message-content collapsible zoom-normal %s" style="display: %s; padding: 16px 0;">%s</div>
     <div class="mail-message-footer collapsible" style="display: %s; height: %spx;"></div>
 </div>
diff --git a/res/values-sw600dp/dimen.xml b/res/values-sw600dp/dimen.xml
index d980bd3..e4edad5 100644
--- a/res/values-sw600dp/dimen.xml
+++ b/res/values-sw600dp/dimen.xml
@@ -25,6 +25,7 @@
     <dimen name="wide_subject_margin_right">28dip</dimen>
     <dimen name="subject_width">238dip</dimen>
     <dimen name="spinner_frame_width">180dp</dimen>
+    <dimen name="conversation_view_margin_side">32dp</dimen>
     <dimen name="conversation_header_side_padding">0dip</dimen>
     <dimen name="conversation_header_vertical_padding">12dip</dimen>
     <dimen name="conversation_page_side_margin">16dip</dimen>
@@ -41,7 +42,6 @@
     <dimen name="message_header_action_button_width">56dip</dimen>
     <dimen name="message_header_title_container_margin_right">0dip</dimen>
     <dimen name="super_collapsed_height">32sp</dimen>
-    <dimen name="new_message_notification_margin_side">32dp</dimen>
     <dimen name="compose_scrollview_width">800dip</dimen>
     <dimen name="compose_area_left_padding">100dip</dimen>
     <dimen name="compose_area_right_padding">100dip</dimen>
diff --git a/res/values/dimen.xml b/res/values/dimen.xml
index cb64129..ec2d352 100644
--- a/res/values/dimen.xml
+++ b/res/values/dimen.xml
@@ -44,6 +44,8 @@
     <dimen name="standard_scaled_dimen">100sp</dimen>
     <dimen name="folder_cell_width">8dip</dimen>
     <dimen name="triangle_width">15dip</dimen>
+    <dimen name="conversation_message_content_margin_side">16dp</dimen>
+    <dimen name="conversation_view_margin_side">0dp</dimen>
     <dimen name="conversation_header_vertical_item_padding">8dip</dimen>
     <dimen name="conversation_header_vertical_padding">0dip</dimen>
     <dimen name="conversation_header_side_padding">8dip</dimen>
@@ -67,7 +69,6 @@
     <dimen name="contact_photo_width">48sp</dimen>
     <dimen name="contact_photo_height">48sp</dimen>
     <dimen name="message_header_inner_side_padding">8dip</dimen>
-    <dimen name="new_message_notification_margin_side">0dp</dimen>
     <dimen name="attachment_toast_yoffset">-100dip</dimen>
     <dimen name="spinner_frame_width">168dip</dimen>
     <dimen name="folder_list_heading_padding_side">8dp</dimen>
diff --git a/src/com/android/mail/browse/ConversationContainer.java b/src/com/android/mail/browse/ConversationContainer.java
index bbee924..47ae675 100644
--- a/src/com/android/mail/browse/ConversationContainer.java
+++ b/src/com/android/mail/browse/ConversationContainer.java
@@ -26,6 +26,7 @@
 import android.view.View;
 import android.view.ViewConfiguration;
 import android.view.ViewGroup;
+import android.view.ViewGroup.MarginLayoutParams;
 import android.webkit.WebView;
 import android.widget.Adapter;
 import android.widget.ListView;
@@ -168,6 +169,8 @@
 
     private final InputSmoother mVelocityTracker;
 
+    final private int mSideMargin;
+
     private final DataSetObserver mAdapterObserver = new AdapterObserver();
 
     /**
@@ -219,6 +222,8 @@
         // Intercepting ACTION_POINTER_DOWN events allows pinch-zoom to work when the first pointer
         // goes down on an overlay view.
         setMotionEventSplittingEnabled(false);
+
+        mSideMargin = getResources().getDimensionPixelOffset(R.dimen.conversation_view_margin_side);
     }
 
     @Override
@@ -671,9 +676,16 @@
         final int itemType = mOverlayAdapter.getItemViewType(adapterIndex);
         final View convertView = mScrapViews.poll(itemType);
 
-        View view = mOverlayAdapter.getView(adapterIndex, convertView, this);
+        final View view = mOverlayAdapter.getView(adapterIndex, convertView, this);
         mOverlayViews.put(adapterIndex, new OverlayView(view, itemType));
 
+
+        // apply a default margin to all overlay items
+        MarginLayoutParams lp = (MarginLayoutParams) view.getLayoutParams();
+        if (lp.leftMargin != mSideMargin || lp.rightMargin != mSideMargin) {
+            lp.leftMargin = lp.rightMargin = mSideMargin;
+        }
+
         final int index = BOTTOM_LAYER_VIEW_IDS.length;
 
         // Only re-attach if the view had previously been added to a view hierarchy.
diff --git a/src/com/android/mail/browse/SendersView.java b/src/com/android/mail/browse/SendersView.java
index f2d7d59..5e53504 100644
--- a/src/com/android/mail/browse/SendersView.java
+++ b/src/com/android/mail/browse/SendersView.java
@@ -104,25 +104,36 @@
         }
     }
 
-    public static SpannableStringBuilder createMessageInfo(Context context,
-            Conversation conv) {
+    public static SpannableStringBuilder createMessageInfo(Context context, Conversation conv) {
         ConversationInfo conversationInfo = conv.conversationInfo;
         int sendingStatus = conv.sendingState;
         SpannableStringBuilder messageInfo = new SpannableStringBuilder();
+        boolean hasSenders = false;
+        // This covers the case where the sender is "me" and this is a draft
+        // message, which means this will only run once most of the time.
+        for (MessageInfo m : conversationInfo.messageInfos) {
+            if (!TextUtils.isEmpty(m.sender)) {
+                hasSenders = true;
+                break;
+            }
+        }
         getSenderResources(context);
         if (conversationInfo != null) {
             int count = conversationInfo.messageCount;
             int draftCount = conversationInfo.draftCount;
-            if (count > 0 || draftCount <= 0) {
-                messageInfo.append(sMessageCountSpacerString);
-            }
+            boolean showSending = sendingStatus == UIProvider.ConversationSendingState.SENDING;
             if (count > 1) {
                 messageInfo.append(count + "");
             }
             messageInfo.setSpan(CharacterStyle.wrap(sMessageInfoStyleSpan), 0,
                     messageInfo.length(), 0);
             if (draftCount > 0) {
-                messageInfo.append(sSendersSplitToken);
+                // If we are showing a message count or any draft text and there
+                // is at least 1 sender, prepend the sending state text with a
+                // comma.
+                if (hasSenders || count > 1) {
+                    messageInfo.append(sSendersSplitToken);
+                }
                 SpannableStringBuilder draftString = new SpannableStringBuilder();
                 if (draftCount == 1) {
                     draftString.append(sDraftSingularString);
@@ -134,10 +145,10 @@
                         Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                 messageInfo.append(draftString);
             }
-            if (sendingStatus == UIProvider.ConversationSendingState.SENDING) {
+            if (showSending) {
                 // If we are showing a message count or any draft text, prepend
                 // the sending state text with a comma.
-                if (count > 1 ||draftCount > 0) {
+                if (count > 1 || draftCount > 0) {
                     messageInfo.append(sSendersSplitToken);
                 }
                 SpannableStringBuilder sending = new SpannableStringBuilder();
@@ -145,6 +156,11 @@
                 sending.setSpan(sSendingStyleSpan, 0, sending.length(), 0);
                 messageInfo.append(sending);
             }
+            // Prepend a space if we are showing other message info text.
+            if (count > 1 || (draftCount > 0 && hasSenders) || showSending) {
+                messageInfo = new SpannableStringBuilder(sMessageCountSpacerString)
+                        .append(messageInfo);
+            }
         }
         return messageInfo;
     }
diff --git a/src/com/android/mail/ui/AbstractActivityController.java b/src/com/android/mail/ui/AbstractActivityController.java
index daf701a..69c0e15 100644
--- a/src/com/android/mail/ui/AbstractActivityController.java
+++ b/src/com/android/mail/ui/AbstractActivityController.java
@@ -494,11 +494,6 @@
         } else {
             mConvListContext = ConversationListContext.forFolder(mAccount, mFolder);
         }
-        // Add the folder that we were viewing to the recent folders list.
-        // TODO: this may need to be fine tuned.  If this is the signal that is indicating that
-        // the list is shown to the user, this could fire in one pane if the user goes directly
-        // to a conversation
-        updateRecentFolderList();
         cancelRefreshTask();
     }
 
@@ -1351,6 +1346,11 @@
     public void showConversation(Conversation conversation) {
         // Set the current conversation just in case it wasn't already set.
         setCurrentConversation(conversation);
+        // Add the folder that we were viewing to the recent folders list.
+        // TODO: this may need to be fine tuned.  If this is the signal that is indicating that
+        // the list is shown to the user, this could fire in one pane if the user goes directly
+        // to a conversation
+        updateRecentFolderList();
     }
 
     /**
@@ -1403,6 +1403,9 @@
 
     @Override
     public void onConversationSelected(Conversation conversation) {
+        // Only animate destructive actions if we are going to be showing the
+        // conversation list when we show the next conversation.
+        commitDestructiveActions(Utils.useTabletUI(mContext));
         showConversation(conversation);
         if (Intent.ACTION_SEARCH.equals(mActivity.getIntent().getAction())) {
             mViewMode.enterSearchResultsConversationMode();
@@ -2586,7 +2589,7 @@
     }
 
     private void promptUserForAuthentication(Account account) {
-        if (account != null && account.reauthenticationIntentUri != null) {
+        if (account != null && !Utils.isEmpty(account.reauthenticationIntentUri)) {
             final Intent authenticationIntent =
                     new Intent(Intent.ACTION_VIEW, account.reauthenticationIntentUri);
             mActivity.startActivityForResult(authenticationIntent, REAUTHENTICATE_REQUEST_CODE);
diff --git a/src/com/android/mail/ui/AnimatedAdapter.java b/src/com/android/mail/ui/AnimatedAdapter.java
index ed2feb8..c7b19a0 100644
--- a/src/com/android/mail/ui/AnimatedAdapter.java
+++ b/src/com/android/mail/ui/AnimatedAdapter.java
@@ -292,7 +292,12 @@
         if (hasLeaveBehinds()) {
             if(isPositionLeaveBehind(conv)) {
                 LeaveBehindItem fadeIn = getLeaveBehindItem(conv);
-                fadeIn.startFadeInAnimation();
+                if (hasFadeLeaveBehinds()) {
+                    // Avoid the fade in and just show the text.
+                    fadeIn.showTextImmediately();
+                } else {
+                    fadeIn.startFadeInAnimation();
+                }
                 return fadeIn;
             }
         }
@@ -361,6 +366,14 @@
             }
             changed = true;
         }
+        if (hasFadeLeaveBehinds() && !animate) {
+            // Find any fading leave behind items and commit them all, too.
+            for (LeaveBehindItem item : mFadeLeaveBehindItems.values()) {
+                item.commit();
+            }
+            mFadeLeaveBehindItems.clear();
+            changed = true;
+        }
         if (!mLastDeletingItems.isEmpty()) {
             mLastDeletingItems.clear();
             changed = true;
diff --git a/src/com/android/mail/ui/ConversationListFragment.java b/src/com/android/mail/ui/ConversationListFragment.java
index 530eec7..7aaf528 100644
--- a/src/com/android/mail/ui/ConversationListFragment.java
+++ b/src/com/android/mail/ui/ConversationListFragment.java
@@ -359,6 +359,9 @@
 
     @Override
     public void onDestroyView() {
+        // If we are destroying this view, make sure anything that needs to be
+        // committed gets committed.
+        commitDestructiveActions(false);
         Utils.dumpLayoutRequests("CLF.onDestroyView()", getView());
 
         // If this fragment is being retained, onSaveInstance will not be called, so we need to
@@ -367,7 +370,11 @@
         // If the activity is being being torn down the loader may have been reset, so this state
         // may not useful for a future list instance, but in that case, the valid list state would
         // have been saved in onSaveInstanceState
-        mListSavedState = mListView.onSaveInstanceState();
+        // We only want to do this, if the conversation cursor is not disabled
+        final ConversationCursor cursor = getConversationListCursor();
+        if (cursor != null && !cursor.isClosed()) {
+            mListSavedState = mListView.onSaveInstanceState();
+        }
 
         // Clear the list's adapter
         mListAdapter.destroy();
diff --git a/src/com/android/mail/ui/ConversationViewFragment.java b/src/com/android/mail/ui/ConversationViewFragment.java
index 3b79ea8..b45d5e5 100644
--- a/src/com/android/mail/ui/ConversationViewFragment.java
+++ b/src/com/android/mail/ui/ConversationViewFragment.java
@@ -601,7 +601,12 @@
         final int convHeaderPos = mAdapter.addConversationHeader(mConversation);
         final int convHeaderPx = measureOverlayHeight(convHeaderPos);
 
-        mTemplates.startConversation(mWebView.screenPxToWebPx(convHeaderPx));
+        final int sideMarginPx = getResources().getDimensionPixelOffset(
+                R.dimen.conversation_view_margin_side) + getResources().getDimensionPixelOffset(
+                R.dimen.conversation_message_content_margin_side);
+
+        mTemplates.startConversation(mWebView.screenPxToWebPx(sideMarginPx),
+                mWebView.screenPxToWebPx(convHeaderPx));
 
         int collapsedStart = -1;
         ConversationMessage prevCollapsedMsg = null;
@@ -691,7 +696,7 @@
         final int headerPx = measureOverlayHeight(headerPos);
         final int footerPx = measureOverlayHeight(footerPos);
 
-        mTemplates.appendMessageHtml(msg, expanded, safeForImages, 1.0f,
+        mTemplates.appendMessageHtml(msg, expanded, safeForImages,
                 mWebView.screenPxToWebPx(headerPx), mWebView.screenPxToWebPx(footerPx));
     }
 
@@ -711,7 +716,7 @@
             final int headerPx = measureOverlayHeight(header);
             final int footerPx = measureOverlayHeight(footer);
 
-            mTemplates.appendMessageHtml(msg, false /* expanded */, msg.alwaysShowImages, 1.0f,
+            mTemplates.appendMessageHtml(msg, false /* expanded */, msg.alwaysShowImages,
                     mWebView.screenPxToWebPx(headerPx), mWebView.screenPxToWebPx(footerPx));
             replacements.add(header);
             replacements.add(footer);
diff --git a/src/com/android/mail/ui/FolderListLayout.java b/src/com/android/mail/ui/FolderListLayout.java
index 0095df9..b281f86 100644
--- a/src/com/android/mail/ui/FolderListLayout.java
+++ b/src/com/android/mail/ui/FolderListLayout.java
@@ -22,13 +22,13 @@
 
     @Override
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
-        LogUtils.w(Utils.VIEW_DEBUGGING_TAG, "FolderListLayout(%s).onMeasure() called", this);
+        LogUtils.d(Utils.VIEW_DEBUGGING_TAG, "FolderListLayout(%s).onMeasure() called", this);
         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
     }
 
     @Override
     protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
-        LogUtils.w(Utils.VIEW_DEBUGGING_TAG, "FolderListLayout(%s).onLayout() called", this);
+        LogUtils.d(Utils.VIEW_DEBUGGING_TAG, "FolderListLayout(%s).onLayout() called", this);
         super.onLayout(changed, left, top, right, bottom);
     }
 
diff --git a/src/com/android/mail/ui/HtmlConversationTemplates.java b/src/com/android/mail/ui/HtmlConversationTemplates.java
index 1119ebb..db18980 100644
--- a/src/com/android/mail/ui/HtmlConversationTemplates.java
+++ b/src/com/android/mail/ui/HtmlConversationTemplates.java
@@ -128,7 +128,7 @@
     }
 
     public void appendMessageHtml(Message message, boolean isExpanded,
-            boolean safeForImages, float zoomValue, int headerHeight, int footerHeight) {
+            boolean safeForImages, int headerHeight, int footerHeight) {
 
         final String bodyDisplay = isExpanded ? "block" : "none";
         final String expandedClass = isExpanded ? "expanded" : "";
@@ -165,7 +165,6 @@
                 headerHeight,
                 showImagesClass,
                 bodyDisplay,
-                zoomValue,
                 body,
                 bodyDisplay,
                 footerHeight
@@ -176,13 +175,13 @@
         return MESSAGE_PREFIX + msg.id;
     }
 
-    public void startConversation(int conversationHeaderHeight) {
+    public void startConversation(int sideMargin, int conversationHeaderHeight) {
         if (mInProgress) {
             throw new IllegalStateException("must call startConversation first");
         }
 
         reset();
-        append(sConversationUpper, conversationHeaderHeight);
+        append(sConversationUpper, sideMargin, conversationHeaderHeight);
         mInProgress = true;
     }
 
diff --git a/src/com/android/mail/ui/LeaveBehindItem.java b/src/com/android/mail/ui/LeaveBehindItem.java
index dcfcd66..deeb495 100644
--- a/src/com/android/mail/ui/LeaveBehindItem.java
+++ b/src/com/android/mail/ui/LeaveBehindItem.java
@@ -202,6 +202,7 @@
             ObjectAnimator height = ObjectAnimator.ofInt(this, "animatedHeight", start, end);
             mAnimatedHeight = start;
             mWidth = getMeasuredWidth();
+            mSwipeableContent.setVisibility(View.GONE);
             height.setInterpolator(new DecelerateInterpolator(2.0f));
             height.addListener(listener);
             height.setDuration(sShrinkAnimationDuration);
@@ -245,4 +246,12 @@
         mAnimatedHeight = height;
         requestLayout();
     }
+
+    /**
+     * We are in a state where we can't afford the alpha fade in, so just show the text.
+     */
+    public void showTextImmediately() {
+        // Fake that we are already fading it in so animations get ignored.
+        mFadingInText = true;
+    }
 }
diff --git a/src/com/android/mail/ui/OnePaneRoot.java b/src/com/android/mail/ui/OnePaneRoot.java
index 8ffaede..56f467c 100644
--- a/src/com/android/mail/ui/OnePaneRoot.java
+++ b/src/com/android/mail/ui/OnePaneRoot.java
@@ -25,15 +25,15 @@
 
     @Override
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
-        LogUtils.w(Utils.VIEW_DEBUGGING_TAG, "OnePaneLayout(%s).onMeasure() called", this);
+        LogUtils.d(Utils.VIEW_DEBUGGING_TAG, "OnePaneLayout(%s).onMeasure() called", this);
         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
     }
 
     @Override
     protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
-        LogUtils.w(Utils.VIEW_DEBUGGING_TAG, "OnePaneLayout(%s).onLayout() START", this);
+        LogUtils.d(Utils.VIEW_DEBUGGING_TAG, "OnePaneLayout(%s).onLayout() START", this);
         super.onLayout(changed, left, top, right, bottom);
-        LogUtils.w(Utils.VIEW_DEBUGGING_TAG, "OnePaneLayout(%s).onLayout() FINISH", this);
+        LogUtils.d(Utils.VIEW_DEBUGGING_TAG, "OnePaneLayout(%s).onLayout() FINISH", this);
     }
 
     @Override
diff --git a/src/com/android/mail/ui/RecentFolderList.java b/src/com/android/mail/ui/RecentFolderList.java
index 1114387..5c9b440 100644
--- a/src/com/android/mail/ui/RecentFolderList.java
+++ b/src/com/android/mail/ui/RecentFolderList.java
@@ -123,7 +123,7 @@
      * @param context
      */
     public RecentFolderList(Context context) {
-        mFolderCache = new LruCache<String, Folder>(MAX_RECENT_FOLDERS);
+        mFolderCache = new LruCache<String, Folder>(MAX_RECENT_FOLDERS + MAX_EXCLUDED_FOLDERS);
         mContext = context;
     }
 
@@ -156,13 +156,15 @@
         }
         LogUtils.d(TAG, "Number of recents = %d", c.getCount());
         int i = 0;
-        while (c.moveToNext()) {
+        c.moveToLast();
+        // Add them backwards, since the most recent values are at the beginning in the cursor.
+        // This enables older values to fall off the LRU cache. Also, read all values, just in case
+        // there are duplicates in the cursor.
+        do {
             final Folder folder = new Folder(c);
             mFolderCache.putElement(folder.uri.toString(), folder);
             LogUtils.v(TAG, "Account %s, Recent: %s", mAccount.name, folder.name);
-            if (++i == (MAX_RECENT_FOLDERS + MAX_EXCLUDED_FOLDERS))
-                break;
-        }
+        } while (c.moveToPrevious());
     }
 
     /**
@@ -188,8 +190,9 @@
 
     /**
      * Generate a sorted list of recent folders, excluding the passed in folder (if any) and
-     * the current account's default inbox. This must be called <em>after</em>
+     * default inbox for the current account. This must be called <em>after</em>
      * {@link #setCurrentAccount(Account)} has been called.
+     * Returns a list of size {@value #MAX_RECENT_FOLDERS} or smaller.
      * @param excludedFolder the folder to be excluded (typically the current folder)
      */
     public ArrayList<Folder> getRecentFolderList(Folder excludedFolder) {
@@ -198,20 +201,22 @@
             excludedUris.add(excludedFolder.uri);
         }
         final Uri defaultInbox = (mAccount == null) ?
-            Uri.EMPTY : Settings.getDefaultInboxUri(mAccount.settings);
+                Uri.EMPTY : Settings.getDefaultInboxUri(mAccount.settings);
         if (!defaultInbox.equals(Uri.EMPTY)) {
-            // This could already be in the list, but that's ok
             excludedUris.add(defaultInbox);
         }
         final List<Folder> recent = new ArrayList<Folder>(mFolderCache.values());
-        Collections.sort(recent, ALPHABET_IGNORECASE);
         final ArrayList<Folder> recentFolders = new ArrayList<Folder>();
-        for (Folder f : recent) {
+        for (final Folder f : recent) {
             if (!excludedUris.contains(f.uri)) {
                 recentFolders.add(f);
             }
-            if (recentFolders.size() == MAX_RECENT_FOLDERS) break;
+            if (recentFolders.size() == MAX_RECENT_FOLDERS) {
+                break;
+            }
         }
+        // Sort the values as the very last step.
+        Collections.sort(recentFolders, ALPHABET_IGNORECASE);
         return recentFolders;
     }
 
diff --git a/src/com/android/mail/ui/SwipeableListView.java b/src/com/android/mail/ui/SwipeableListView.java
index b9921e1..babf34b 100644
--- a/src/com/android/mail/ui/SwipeableListView.java
+++ b/src/com/android/mail/ui/SwipeableListView.java
@@ -82,11 +82,11 @@
 
     @Override
     protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
-        LogUtils.w(Utils.VIEW_DEBUGGING_TAG,
+        LogUtils.d(Utils.VIEW_DEBUGGING_TAG,
                 "START CLF-ListView.onFocusChanged layoutRequested=%s root.layoutRequested=%s",
                 isLayoutRequested(), getRootView().isLayoutRequested());
         super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
-        LogUtils.w(Utils.VIEW_DEBUGGING_TAG, new Error(),
+        LogUtils.d(Utils.VIEW_DEBUGGING_TAG, new Error(),
                 "FINISH CLF-ListView.onFocusChanged layoutRequested=%s root.layoutRequested=%s",
                 isLayoutRequested(), getRootView().isLayoutRequested());
     }
diff --git a/src/com/android/mail/ui/TwoPaneLayout.java b/src/com/android/mail/ui/TwoPaneLayout.java
index b703ef1..eccde26 100644
--- a/src/com/android/mail/ui/TwoPaneLayout.java
+++ b/src/com/android/mail/ui/TwoPaneLayout.java
@@ -751,13 +751,13 @@
 
     @Override
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
-        LogUtils.w(Utils.VIEW_DEBUGGING_TAG, "TPL(%s).onMeasure()", this);
+        LogUtils.d(Utils.VIEW_DEBUGGING_TAG, "TPL(%s).onMeasure()", this);
         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
     }
 
     @Override
     protected void onLayout(boolean changed, int l, int t, int r, int b) {
-        LogUtils.w(Utils.VIEW_DEBUGGING_TAG, "TPL(%s).onLayout()", this);
+        LogUtils.d(Utils.VIEW_DEBUGGING_TAG, "TPL(%s).onLayout()", this);
         super.onLayout(changed, l, t, r, b);
     }
 
diff --git a/src/com/android/mail/utils/Utils.java b/src/com/android/mail/utils/Utils.java
index 366432e..9c316c5 100644
--- a/src/com/android/mail/utils/Utils.java
+++ b/src/com/android/mail/utils/Utils.java
@@ -1055,7 +1055,7 @@
     public static void markDirtyTillRoot(String message, View v) {
         // During development, we want to log extra debugging information, and disable the
         // hacky workaround to help diagnose the underlying problem.
-        if (LogUtils.isDebugLoggingEnabled(VIEW_DEBUGGING_TAG)) return;
+        if (LogUtils.isLoggable(VIEW_DEBUGGING_TAG, LogUtils.DEBUG)) return;
 
         LogUtils.d(VIEW_DEBUGGING_TAG, "%s: markingDirtyTillRoot", message);
         v.invalidate();
@@ -1083,7 +1083,7 @@
             }
         }
         if (inLayout && !v.isLayoutRequested()) {
-            LogUtils.e(VIEW_DEBUGGING_TAG,
+            LogUtils.i(VIEW_DEBUGGING_TAG,
                     e, "WARNING: in requestLayout during layout pass, view=%s", v);
         }
     }
@@ -1096,10 +1096,10 @@
      * @param v
      */
     public static void dumpLayoutRequests(String message, View v) {
-        LogUtils.w(VIEW_DEBUGGING_TAG, "dumpLayoutRequests: %s", message);
+        LogUtils.d(VIEW_DEBUGGING_TAG, "dumpLayoutRequests: %s", message);
 
         while (v != null) {
-            LogUtils.w(VIEW_DEBUGGING_TAG,
+            LogUtils.d(VIEW_DEBUGGING_TAG,
                     "view item: %s mw/mh=%d/%d w/h=%d/%d layoutRequested=%s vis=%s id=0x%x",
                     v, v.getMeasuredWidth(), v.getMeasuredHeight(), v.getWidth(), v.getHeight(),
                     v.isLayoutRequested(), v.getVisibility(), v.getId());
@@ -1110,7 +1110,7 @@
             } else {
                 if (vp != null) {
                     // this is the root. can't really get access to this guy
-                    LogUtils.w(VIEW_DEBUGGING_TAG,
+                    LogUtils.d(VIEW_DEBUGGING_TAG,
                             "view item: (ViewRootImpl) isLayoutRequested=%s\n",
                             vp.isLayoutRequested());
                 }