am 0eecd87b: am d26498cd: Merge "[Quantum search] new two-pane land search result list" into ub-gmail-ur14-dev

* commit '0eecd87b5b7ff4f5e9f122d9fe3593bdf8b6d10d':
  [Quantum search] new two-pane land search result list
diff --git a/res/drawable-hdpi/ic_mic_white_24dp.png b/res/drawable-hdpi/ic_mic_white_24dp.png
new file mode 100644
index 0000000..eefd59e
--- /dev/null
+++ b/res/drawable-hdpi/ic_mic_white_24dp.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_mic_white_24dp.png b/res/drawable-mdpi/ic_mic_white_24dp.png
new file mode 100644
index 0000000..fca776f
--- /dev/null
+++ b/res/drawable-mdpi/ic_mic_white_24dp.png
Binary files differ
diff --git a/res/drawable-xhdpi/ic_mic_white_24dp.png b/res/drawable-xhdpi/ic_mic_white_24dp.png
new file mode 100644
index 0000000..b7d8dc7
--- /dev/null
+++ b/res/drawable-xhdpi/ic_mic_white_24dp.png
Binary files differ
diff --git a/res/drawable-xxhdpi/ic_mic_white_24dp.png b/res/drawable-xxhdpi/ic_mic_white_24dp.png
new file mode 100644
index 0000000..658c5a5
--- /dev/null
+++ b/res/drawable-xxhdpi/ic_mic_white_24dp.png
Binary files differ
diff --git a/res/drawable-xxxhdpi/ic_mic_white_24dp.png b/res/drawable-xxxhdpi/ic_mic_white_24dp.png
new file mode 100644
index 0000000..fe00ae5
--- /dev/null
+++ b/res/drawable-xxxhdpi/ic_mic_white_24dp.png
Binary files differ
diff --git a/src/com/android/mail/ui/AbstractActivityController.java b/src/com/android/mail/ui/AbstractActivityController.java
index 431b06c..c5425e4 100644
--- a/src/com/android/mail/ui/AbstractActivityController.java
+++ b/src/com/android/mail/ui/AbstractActivityController.java
@@ -1322,6 +1322,7 @@
 
         mSearchViewController = new MaterialSearchViewController(mActivity, this, intent,
                 savedState);
+        addConversationListLayoutListener(mSearchViewController);
 
         // Immediately handle a clean launch with intent, and any state restoration
         // that does not rely on restored fragments or loader data
diff --git a/src/com/android/mail/ui/ActivityController.java b/src/com/android/mail/ui/ActivityController.java
index 91f4baf..3ccdad3 100644
--- a/src/com/android/mail/ui/ActivityController.java
+++ b/src/com/android/mail/ui/ActivityController.java
@@ -285,5 +285,5 @@
     /**
      * Attach layout listener so our custom toolbar can listen to thread list layout events.
      */
-    void setConversationListLayoutListener(TwoPaneLayout.ConversationListLayoutListener listener);
+    void addConversationListLayoutListener(TwoPaneLayout.ConversationListLayoutListener listener);
 }
diff --git a/src/com/android/mail/ui/CustomViewToolbar.java b/src/com/android/mail/ui/CustomViewToolbar.java
index 7df8a38..676321a 100644
--- a/src/com/android/mail/ui/CustomViewToolbar.java
+++ b/src/com/android/mail/ui/CustomViewToolbar.java
@@ -41,8 +41,6 @@
     protected TextView mActionBarTitle;
     protected View mSearchButton;
 
-    private boolean mIsTabletLandscape;
-
     public CustomViewToolbar(Context context) {
         super(context);
     }
@@ -75,8 +73,6 @@
                 mController.startSearch();
             }
         });
-
-        mIsTabletLandscape = getResources().getBoolean(R.bool.is_tablet_landscape);
     }
 
     @Override
@@ -93,29 +89,26 @@
 
     @Override
     public void onConversationListLayout(int xEnd, boolean drawerOpen) {
-        // Only reposition in tablet landscape mode.
-        if (mIsTabletLandscape) {
-            if (drawerOpen) {
-                mSearchButton.setVisibility(INVISIBLE);
+        if (drawerOpen) {
+            mSearchButton.setVisibility(INVISIBLE);
+        } else {
+            mSearchButton.setVisibility(VISIBLE);
+            // Since we no longer shift the search button when the drawer opens/closes, only set
+            // the width of the title on the first pass (when width is 0) so we avoid changing
+            // width during layout passes.
+            final int[] coords = new int[2];
+            mActionBarTitle.getLocationInWindow(coords);
+            final int newWidth;
+            if (ViewUtils.isViewRtl(this)) {
+                newWidth = coords[0] + mActionBarTitle.getWidth() - xEnd -
+                        mSearchButton.getWidth();
             } else {
-                mSearchButton.setVisibility(VISIBLE);
-                // Since we no longer shift the search button when the drawer opens/closes, only set
-                // the width of the title on the first pass (when width is 0) so we avoid changing
-                // width during layout passes.
-                final int[] coords = new int[2];
-                mActionBarTitle.getLocationInWindow(coords);
-                final int newWidth;
-                if (ViewUtils.isViewRtl(this)) {
-                    newWidth = coords[0] + mActionBarTitle.getWidth() - xEnd -
-                            mSearchButton.getWidth();
-                } else {
-                    newWidth = xEnd - coords[0] - mSearchButton.getWidth();
-                }
+                newWidth = xEnd - coords[0] - mSearchButton.getWidth();
+            }
 
-                // Only set the width if it's different than before so we avoid draw on layout pass.
-                if (mActionBarTitle.getWidth() != newWidth) {
-                    mActionBarTitle.setWidth(newWidth);
-                }
+            // Only set the width if it's different than before so we avoid draw on layout pass.
+            if (mActionBarTitle.getWidth() != newWidth) {
+                mActionBarTitle.setWidth(newWidth);
             }
         }
     }
diff --git a/src/com/android/mail/ui/MailActivity.java b/src/com/android/mail/ui/MailActivity.java
index bcba078..1251e8b 100644
--- a/src/com/android/mail/ui/MailActivity.java
+++ b/src/com/android/mail/ui/MailActivity.java
@@ -179,7 +179,7 @@
             // Tablets use CustomViewToolbar to override the default search menu item positioning.
             final CustomViewToolbar customViewToolbar = (CustomViewToolbar) toolbar;
             customViewToolbar.setController(this, mController, mViewMode);
-            mController.setConversationListLayoutListener(customViewToolbar);
+            mController.addConversationListLayoutListener(customViewToolbar);
         }
         setSupportActionBar(toolbar);
         toolbar.setNavigationOnClickListener(mController.getNavigationViewClickListener());
diff --git a/src/com/android/mail/ui/MaterialSearchActionView.java b/src/com/android/mail/ui/MaterialSearchActionView.java
index 1b131e0..d7ad5a3 100644
--- a/src/com/android/mail/ui/MaterialSearchActionView.java
+++ b/src/com/android/mail/ui/MaterialSearchActionView.java
@@ -19,6 +19,9 @@
 
 import android.content.Context;
 import android.content.res.Resources;
+import android.graphics.drawable.ColorDrawable;
+import android.graphics.drawable.Drawable;
+import android.support.annotation.DrawableRes;
 import android.text.Editable;
 import android.text.TextWatcher;
 import android.util.AttributeSet;
@@ -27,6 +30,7 @@
 import android.view.Menu;
 import android.view.MenuItem;
 import android.view.View;
+import android.view.ViewGroup;
 import android.view.inputmethod.EditorInfo;
 import android.view.inputmethod.InputMethodManager;
 import android.widget.EditText;
@@ -35,27 +39,52 @@
 import android.widget.TextView;
 
 import com.android.mail.R;
+import com.android.mail.utils.ViewUtils;
 
 /**
  * Custom view for the action bar when search is displayed.
  */
 public class MaterialSearchActionView extends LinearLayout implements TextWatcher,
         View.OnClickListener, TextView.OnEditorActionListener, View.OnKeyListener {
+    private Drawable mNormalBackgroundDrawable;
+    private Drawable mTwoPaneLandConvModeBackgroundDrawable;
+    private @DrawableRes int mNormalBackButtonDrawable;
+    private @DrawableRes int mTwoPaneLandConvModeBackButtonDrawable;
+    private @DrawableRes int mNormalClearTextButtonDrawable;
+    private @DrawableRes int mTwoPaneLandConvModeClearTextButtonDrawable;
+    private @DrawableRes int mNormalVoiceButtonDrawable;
+    private @DrawableRes int mTwoPaneLandConvModeVoiceButtonDrawable;
+    private int mNormalTextColor;
+    private int mTwoPaneLandConvModeTextColor;
+
     private MaterialSearchViewController mController;
     private InputMethodManager mImm;
     private boolean mShowingClose;
     private boolean mSupportVoice;
 
-    private View mBackButton;
+    private ImageView mBackButton;
     private EditText mQueryText;
     private ImageView mEndingButton;
 
     public MaterialSearchActionView(Context context) {
-        super(context);
+        this(context, null);
     }
 
     public MaterialSearchActionView(Context context, AttributeSet attrs) {
         super(context, attrs);
+
+        final Resources res = getResources();
+        mNormalBackgroundDrawable = new ColorDrawable(res.getColor(android.R.color.white));
+        mTwoPaneLandConvModeBackgroundDrawable =
+                new ColorDrawable(res.getColor(R.color.actionbar_color));
+        mNormalBackButtonDrawable = R.drawable.ic_arrow_back_24dp_with_rtl;
+        mTwoPaneLandConvModeBackButtonDrawable = R.drawable.ic_arrow_back_wht_24dp;
+        mNormalClearTextButtonDrawable = R.drawable.ic_close_24dp;
+        mTwoPaneLandConvModeClearTextButtonDrawable = R.drawable.ic_close_wht_24dp;
+        mNormalVoiceButtonDrawable = R.drawable.ic_mic_24dp;
+        mTwoPaneLandConvModeVoiceButtonDrawable = R.drawable.ic_mic_white_24dp;
+        mNormalTextColor = res.getColor(R.color.search_query_text);
+        mTwoPaneLandConvModeTextColor = res.getColor(android.R.color.white);
     }
 
     // PUBLIC API
@@ -79,12 +108,45 @@
         }
     }
 
+    public void adjustViewForTwoPaneLandscape(boolean alignWithTL, int xEnd) {
+        final ViewGroup.LayoutParams params = getLayoutParams();
+        if (alignWithTL) {
+            setBackgroundDrawable(mTwoPaneLandConvModeBackgroundDrawable);
+            mBackButton.setImageResource(mTwoPaneLandConvModeBackButtonDrawable);
+            if (mShowingClose) {
+                mEndingButton.setImageResource(mTwoPaneLandConvModeClearTextButtonDrawable);
+            } else {
+                mEndingButton.setImageResource(mTwoPaneLandConvModeVoiceButtonDrawable);
+            }
+            mQueryText.setTextColor(mTwoPaneLandConvModeTextColor);
+
+            if (ViewUtils.isViewRtl(this)) {
+                int[] coords = new int[2];
+                getLocationInWindow(coords);
+                params.width = coords[0] + getWidth() - xEnd;
+            } else {
+                params.width = xEnd;
+            }
+        } else {
+            setBackgroundDrawable(mNormalBackgroundDrawable);
+            mBackButton.setImageResource(mNormalBackButtonDrawable);
+            if (mShowingClose) {
+                mEndingButton.setImageResource(mNormalClearTextButtonDrawable);
+            } else {
+                mEndingButton.setImageResource(mNormalVoiceButtonDrawable);
+            }
+            mQueryText.setTextColor(mNormalTextColor);
+            params.width = ViewGroup.LayoutParams.MATCH_PARENT;
+        }
+        setLayoutParams(params);
+    }
+
     @Override
     protected void onFinishInflate() {
         super.onFinishInflate();
 
         mImm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
-        mBackButton = findViewById(R.id.search_actionbar_back_button);
+        mBackButton = (ImageView) findViewById(R.id.search_actionbar_back_button);
         mBackButton.setOnClickListener(this);
         mQueryText = (EditText) findViewById(R.id.search_actionbar_query_text);
         mQueryText.addTextChangedListener(this);
diff --git a/src/com/android/mail/ui/MaterialSearchViewController.java b/src/com/android/mail/ui/MaterialSearchViewController.java
index 5014e19..b5e01af 100644
--- a/src/com/android/mail/ui/MaterialSearchViewController.java
+++ b/src/com/android/mail/ui/MaterialSearchViewController.java
@@ -36,7 +36,8 @@
 /**
  * Controller for interactions between ActivityController and our custom search views.
  */
-public class MaterialSearchViewController implements ViewMode.ModeChangeListener {
+public class MaterialSearchViewController implements ViewMode.ModeChangeListener,
+        TwoPaneLayout.ConversationListLayoutListener {
     // The controller is not in search mode. Both search action bar and the suggestion list
     // are not visible to the user.
     public static final int SEARCH_VIEW_STATE_GONE = 0;
@@ -59,6 +60,7 @@
 
     private int mViewMode;
     private int mViewState;
+    private int mEndXCoordForTabletLandscape;
 
     private boolean mWaitToDestroyProvider;
 
@@ -110,6 +112,21 @@
         mViewMode = newMode;
     }
 
+    @Override
+    public void onConversationListLayout(int xEnd, boolean drawerOpen) {
+        // Only care about the first layout
+        if (mEndXCoordForTabletLandscape != xEnd) {
+            // This is called when we get into tablet landscape mode
+            mEndXCoordForTabletLandscape = xEnd;
+            if (ViewMode.isSearchMode(mViewMode)) {
+                final int defaultVisibility = mController.shouldShowSearchBarByDefault() ?
+                        View.VISIBLE : View.GONE;
+                mSearchActionView.setVisibility(drawerOpen ? View.INVISIBLE : defaultVisibility);
+            }
+            adjustViewForTwoPaneLandscape();
+        }
+    }
+
     public boolean handleBackPress() {
         final boolean shouldShowSearchBar = mController.shouldShowSearchBarByDefault();
         if (shouldShowSearchBar && mSearchSuggestionList.isShown()) {
@@ -132,6 +149,7 @@
                     mSearchActionView.setVisibility(View.VISIBLE);
                     mSearchSuggestionList.setVisibility(View.GONE);
                     mSearchActionView.focusSearchBar(false);
+                    adjustViewForTwoPaneLandscape();
                     break;
                 }
                 // Fallthrough to setting everything invisible
@@ -146,12 +164,21 @@
                 break;
             case MaterialSearchViewController.SEARCH_VIEW_STATE_VISIBLE:
                 mSearchActionView.setVisibility(View.VISIBLE);
+                // Set to default layout/assets
+                mSearchActionView.adjustViewForTwoPaneLandscape(false /* do not align */, 0);
                 mSearchSuggestionList.setVisibility(View.VISIBLE);
                 mSearchActionView.focusSearchBar(true);
                 break;
         }
     }
 
+    private void adjustViewForTwoPaneLandscape() {
+        final boolean alignWithTL = mController.isTwoPaneLandscape() &&
+                mViewState == MaterialSearchViewController.SEARCH_VIEW_STATE_ONLY_ACTIONBAR &&
+                ViewMode.isSearchMode(mViewMode);
+        mSearchActionView.adjustViewForTwoPaneLandscape(alignWithTL, mEndXCoordForTabletLandscape);
+    }
+
     public void onQueryTextChanged(String query) {
         mSearchSuggestionList.setQuery(query);
     }
diff --git a/src/com/android/mail/ui/OnePaneController.java b/src/com/android/mail/ui/OnePaneController.java
index 196c5ff..875bb5a 100644
--- a/src/com/android/mail/ui/OnePaneController.java
+++ b/src/com/android/mail/ui/OnePaneController.java
@@ -526,7 +526,7 @@
     }
 
     @Override
-    public void setConversationListLayoutListener(
+    public void addConversationListLayoutListener(
             TwoPaneLayout.ConversationListLayoutListener listener) {
         // Do nothing
     }
diff --git a/src/com/android/mail/ui/TwoPaneController.java b/src/com/android/mail/ui/TwoPaneController.java
index 71d73d6..55b9e58 100644
--- a/src/com/android/mail/ui/TwoPaneController.java
+++ b/src/com/android/mail/ui/TwoPaneController.java
@@ -37,6 +37,9 @@
 import com.android.mail.providers.UIProvider.ConversationListIcon;
 import com.android.mail.utils.LogUtils;
 import com.android.mail.utils.Utils;
+import com.google.common.collect.Lists;
+
+import java.util.List;
 
 /**
  * Controller for two-pane Mail activity. Two Pane is used for tablets, where screen real estate
@@ -50,6 +53,8 @@
             "saved-miscellaneous-view-transaction-id";
 
     private TwoPaneLayout mLayout;
+    private List<TwoPaneLayout.ConversationListLayoutListener> mConversationListLayoutListeners =
+            Lists.newArrayList();
     @Deprecated
     private Conversation mConversationToShow;
 
@@ -84,8 +89,6 @@
 
     private boolean mIsTabletLandscape;
 
-    private TwoPaneLayout.ConversationListLayoutListener mConversationListLayoutListener;
-
     public TwoPaneController(MailActivity activity, ViewMode viewMode) {
         super(activity, viewMode);
     }
@@ -169,7 +172,6 @@
             LogUtils.wtf(LOG_TAG, "mLayout is null!");
             return false;
         }
-        mLayout.setConversationListLayoutListener(mConversationListLayoutListener);
         mLayout.setController(this);
         mActivity.getWindow().setBackgroundDrawable(null);
         mIsTabletLandscape = mActivity.getResources().getBoolean(R.bool.is_tablet_landscape);
@@ -685,11 +687,12 @@
     }
 
     @Override
-    public void setConversationListLayoutListener(
+    public void addConversationListLayoutListener(
             TwoPaneLayout.ConversationListLayoutListener listener) {
-        mConversationListLayoutListener = listener;
-        if (mLayout != null) {
-            mLayout.setConversationListLayoutListener(listener);
-        }
+        mConversationListLayoutListeners.add(listener);
+    }
+
+    public List<TwoPaneLayout.ConversationListLayoutListener> getConversationListLayoutListeners() {
+        return mConversationListLayoutListeners;
     }
 }
diff --git a/src/com/android/mail/ui/TwoPaneLayout.java b/src/com/android/mail/ui/TwoPaneLayout.java
index c4f612e..d687114 100644
--- a/src/com/android/mail/ui/TwoPaneLayout.java
+++ b/src/com/android/mail/ui/TwoPaneLayout.java
@@ -97,7 +97,6 @@
 
     private TwoPaneController mController;
     private LayoutListener mListener;
-    private ConversationListLayoutListener mConversationListLayoutListener;
 
     private View mMiscellaneousView;
     private View mConversationView;
@@ -115,6 +114,12 @@
     public static final int MISCELLANEOUS_VIEW_ID = R.id.miscellaneous_pane;
 
     public interface ConversationListLayoutListener {
+        /**
+         * Used for two-pane landscape layout positioning when other views need to align themselves
+         * to the list view. Should be called only in tablet landscape mode!
+         * @param xEnd the ending x coordinate of the list view
+         * @param drawerOpen
+         */
         void onConversationListLayout(int xEnd, boolean drawerOpen);
     }
 
@@ -279,9 +284,10 @@
         final boolean listVisible = isRtl ? listX + mListView.getWidth() >= 0 : listX >= 0;
         adjustPaneVisibility(folderVisible, listVisible, cvOnScreen);
 
-        if (mConversationListLayoutListener != null) {
-            mConversationListLayoutListener.onConversationListLayout(
-                    isRtl ? listX : convX, isDrawerOpen);
+        final List<ConversationListLayoutListener> layoutListeners =
+                mController.getConversationListLayoutListeners();
+        for (ConversationListLayoutListener listener : layoutListeners) {
+            listener.onConversationListLayout(isRtl ? listX : convX, isDrawerOpen);
         }
 
         mPositionedMode = mCurrentMode;
@@ -526,10 +532,6 @@
         return !mListCollapsible;
     }
 
-    public void setConversationListLayoutListener(ConversationListLayoutListener listener) {
-        mConversationListLayoutListener = listener;
-    }
-
     private class PaneAnimationListener extends AnimatorListenerAdapter implements Runnable {
 
         @Override