Merge "Make search behavior match jb search behavior." into jb-ub-mail
diff --git a/res/values-sw600dp-port/constants.xml b/res/values-sw600dp-port/constants.xml
index ea3f99f..3168d69 100644
--- a/res/values-sw600dp-port/constants.xml
+++ b/res/values-sw600dp-port/constants.xml
@@ -26,4 +26,7 @@
 
     <!-- Whether the list is collapsed in conversation view mode -->
     <bool name="list_collapsed">true</bool>
+
+    <!-- Whether to show single or 2 pane search results -->
+    <bool name="show_two_pane_search_results">false</bool>
 </resources>
\ No newline at end of file
diff --git a/res/values-sw600dp/constants.xml b/res/values-sw600dp/constants.xml
index e8f5c67..4efbc24 100644
--- a/res/values-sw600dp/constants.xml
+++ b/res/values-sw600dp/constants.xml
@@ -26,4 +26,7 @@
 
     <!-- Whether the list is collapsed in conversation view mode -->
     <bool name="list_collapsed">false</bool>
+
+    <!-- Whether to show single or 2 pane search results -->
+    <bool name="show_two_pane_search_results">true</bool>
 </resources>
diff --git a/res/values-sw720dp-port/constants.xml b/res/values-sw720dp-port/constants.xml
index 75b2f59..1822f5d 100644
--- a/res/values-sw720dp-port/constants.xml
+++ b/res/values-sw720dp-port/constants.xml
@@ -18,4 +18,7 @@
 <resources>
     <!-- Whether the list is collapsed in conversation view mode -->
     <bool name="list_collapsed">true</bool>
+
+    <!-- Whether to show single or 2 pane search results -->
+    <bool name="show_two_pane_search_results">false</bool>
 </resources>
\ No newline at end of file
diff --git a/res/values-sw720dp/constants.xml b/res/values-sw720dp/constants.xml
index 1181de1..8e905fb 100644
--- a/res/values-sw720dp/constants.xml
+++ b/res/values-sw720dp/constants.xml
@@ -22,4 +22,7 @@
 
     <!-- Whether the list is collapsed in conversation view mode -->
     <bool name="list_collapsed">false</bool>
+
+    <!-- Whether to show single or 2 pane search results -->
+    <bool name="show_two_pane_search_results">true</bool>
 </resources>
\ No newline at end of file
diff --git a/res/values/constants.xml b/res/values/constants.xml
index 13067d5..5fe6e58 100644
--- a/res/values/constants.xml
+++ b/res/values/constants.xml
@@ -54,4 +54,7 @@
 
     <!-- Whether the list is collapsed in conversation view mode -->
     <bool name="list_collapsed">true</bool>
+
+    <!-- Whether to show single or 2 pane search results -->
+    <bool name="show_two_pane_search_results">false</bool>
 </resources>
diff --git a/src/com/android/mail/ui/TwoPaneController.java b/src/com/android/mail/ui/TwoPaneController.java
index 66453a7..cb4a57e 100644
--- a/src/com/android/mail/ui/TwoPaneController.java
+++ b/src/com/android/mail/ui/TwoPaneController.java
@@ -20,6 +20,7 @@
 import android.app.Fragment;
 import android.app.FragmentManager;
 import android.app.FragmentTransaction;
+import android.content.Intent;
 import android.net.Uri;
 import android.os.Bundle;
 import android.view.Gravity;
@@ -47,6 +48,7 @@
 // Called TwoPaneActivityController in Gmail.
 public final class TwoPaneController extends AbstractActivityController {
     private TwoPaneLayout mLayout;
+    private Boolean mShowTwoPaneSearchResults;
 
     /**
      * @param activity
@@ -136,7 +138,8 @@
         if (mLayout == null) {
             LogUtils.d(LOG_TAG, "mLayout is null!");
         }
-        mLayout.initializeLayout(mActivity.getApplicationContext());
+        mLayout.initializeLayout(mActivity.getApplicationContext(),
+                Intent.ACTION_SEARCH.equals(mActivity.getIntent().getAction()));
 
         // The tablet layout needs to refer to mode changes.
         mViewMode.addListener(mLayout);
@@ -264,7 +267,8 @@
             }
             mActivity.onBackPressed();
         } else if (mode == ViewMode.SEARCH_RESULTS_CONVERSATION) {
-            if (mLayout.isConversationListCollapsed()) {
+            if (mLayout.isConversationListCollapsed()
+                    || (mConvListContext.isSearchResult() && !showTwoPaneSearchResults())) {
                 commitLeaveBehindItems();
                 onBackPressed();
             } else {
@@ -312,9 +316,27 @@
         }
     }
 
+    private boolean showTwoPaneSearchResults() {
+        if (mShowTwoPaneSearchResults == null) {
+            mShowTwoPaneSearchResults = new Boolean(mContext.getResources().getBoolean(
+                    R.bool.show_two_pane_search_results));
+        }
+        return mShowTwoPaneSearchResults;
+    }
+
+    @Override
+    public void exitSearchMode() {
+        int mode = mViewMode.getMode();
+        if (mode == ViewMode.SEARCH_RESULTS_LIST
+                || (mode == ViewMode.SEARCH_RESULTS_CONVERSATION && showTwoPaneSearchResults())) {
+            mActivity.finish();
+        }
+    }
+
     @Override
     public boolean shouldShowFirstConversation() {
-        return mConvListContext != null && mConvListContext.isSearchResult();
+        return mConvListContext != null && mConvListContext.isSearchResult()
+                && showTwoPaneSearchResults();
     }
 
     @Override
diff --git a/src/com/android/mail/ui/TwoPaneLayout.java b/src/com/android/mail/ui/TwoPaneLayout.java
index 52fb401..ef7a7d2 100644
--- a/src/com/android/mail/ui/TwoPaneLayout.java
+++ b/src/com/android/mail/ui/TwoPaneLayout.java
@@ -127,6 +127,7 @@
             new AnimatorListener(AnimatorListener.CONVERSATION_LIST);
     private final AnimatorListener mConversationListener =
             new AnimatorListener(AnimatorListener.CONVERSATION);
+    private boolean mIsSearchResult = false;
 
     private class AnimatorListener implements Animator.AnimatorListener {
         public static final int CONVERSATION_LIST = 1;
@@ -285,7 +286,8 @@
      * Computes the width of the folder list in stable state of the current mode.
      */
     private int computeFolderListWidth() {
-        return (int) (getMeasuredWidth() * sScaledFolderListWeight);
+        return isFolderListCollapsed() ?
+                0 : (int) (getMeasuredWidth() * sScaledFolderListWeight);
     }
 
     /**
@@ -459,15 +461,23 @@
                 .leftMargin;
     }
 
+    public void initializeLayout(Context context) {
+        initializeLayout(context, false);
+    }
+
     /**
      * Initializes the layout with a specific context.
      */
     @VisibleForTesting
-    public void initializeLayout(Context context) {
+    public void initializeLayout(Context context, boolean isSearchResult) {
         mContext = context;
+        mIsSearchResult = isSearchResult;
 
         Resources res = getResources();
         mFoldersView = findViewById(R.id.content_pane);
+        if (mIsSearchResult) {
+            mFoldersView.setVisibility(View.GONE);
+        }
         mConversationListContainer = findViewById(R.id.conversation_column_container);
         mListView = findViewById(R.id.conversation_list);
         mConversationView = findViewById(R.id.conversation_pane_container);
@@ -497,6 +507,10 @@
         return mAnimatingFade;
     }
 
+    private boolean isFolderListCollapsed() {
+        return mIsSearchResult;
+    }
+
     /**
      * @return Whether or not the conversation list is visible on screen.
      */