Merge "Added action bar shadow for pre-L devices" into ub-gmail-ur14-dev
diff --git a/res/layout-sw600dp/mail_toolbar_view.xml b/res/layout-sw600dp/mail_toolbar_view.xml
new file mode 100644
index 0000000..bef17f9
--- /dev/null
+++ b/res/layout-sw600dp/mail_toolbar_view.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Copyright (C) 2014 Google Inc.
+    Licensed to The Android Open Source Project.
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+
+<com.android.mail.ui.CustomViewToolbar
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:id="@+id/mail_toolbar"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
+    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" >
+
+    <!-- Custom view for search icon -->
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="match_parent">
+
+        <TextView
+            android:id="@+id/actionbar_title"
+            android:ellipsize="end"
+            android:gravity="center_vertical|start"
+            android:paddingLeft="12dp"
+            android:paddingRight="12dp"
+            android:singleLine="true"
+            android:textAlignment="viewStart"
+            style="@style/ActionBarTitleStyle" />
+
+        <ImageView
+            android:id="@+id/actionbar_search_button"
+            android:layout_width="56dp"
+            android:layout_height="match_parent"
+            android:background="?android:attr/selectableItemBackground"
+            android:scaleType="center"
+            android:src="@drawable/ic_menu_search" />
+
+    </LinearLayout>
+
+</com.android.mail.ui.CustomViewToolbar>
\ No newline at end of file
diff --git a/res/layout/mail_toolbar_view.xml b/res/layout/mail_toolbar_view.xml
new file mode 100644
index 0000000..961e89c
--- /dev/null
+++ b/res/layout/mail_toolbar_view.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Copyright (C) 2014 Google Inc.
+    Licensed to The Android Open Source Project.
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+
+<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:id="@+id/mail_toolbar"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
+    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
\ No newline at end of file
diff --git a/res/layout/toolbar_with_search.xml b/res/layout/toolbar_with_search.xml
index 1ce3a09..9cc0ca7 100644
--- a/res/layout/toolbar_with_search.xml
+++ b/res/layout/toolbar_with_search.xml
@@ -17,42 +17,12 @@
 -->
 
 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="?attr/actionBarSize"
     android:background="?attr/colorPrimary"
     android:elevation="8dp" >
 
-    <com.android.mail.ui.CustomViewToolbar
-        android:id="@+id/mail_toolbar"
-        android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
-        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" >
-
-        <!-- Custom view for search icon -->
-        <LinearLayout
-            android:layout_width="match_parent"
-            android:layout_height="match_parent">
-
-            <TextView
-                android:id="@+id/actionbar_title"
-                android:gravity="center_vertical"
-                android:paddingLeft="12dp"
-                android:paddingRight="12dp"
-                style="@style/ActionBarTitleStyle" />
-
-            <ImageView
-                android:id="@+id/actionbar_search_button"
-                android:layout_width="56dp"
-                android:layout_height="match_parent"
-                android:background="?android:attr/selectableItemBackground"
-                android:scaleType="center"
-                android:src="@drawable/ic_menu_search" />
-
-        </LinearLayout>
-
-    </com.android.mail.ui.CustomViewToolbar>
+    <include layout="@layout/mail_toolbar_view" />
 
     <include layout="@layout/mail_actionbar_searchview" />
 
diff --git a/res/menu/conversation_list_menu.xml b/res/menu/conversation_list_menu.xml
index 7e5d53f..85d5632 100644
--- a/res/menu/conversation_list_menu.xml
+++ b/res/menu/conversation_list_menu.xml
@@ -31,6 +31,13 @@
         android:title="@string/empty_spam"
         app:showAsAction="always|withText" />
 
+    <!-- Available only for accounts with SERVER_SEARCH and in a folder
+      that supports FOLDER_SERVER_SEARCH -->
+    <item android:id="@+id/search"
+        android:title="@string/menu_search"
+        app:showAsAction="ifRoom|collapseActionView"
+        android:icon="@drawable/ic_menu_search" />
+
     <!-- These invisible menu item are used to enable keyboard shortcuts -->
     <item
         android:id="@+id/compose"
diff --git a/src/com/android/mail/analytics/AnalyticsUtils.java b/src/com/android/mail/analytics/AnalyticsUtils.java
index 01adade..b968ad7 100644
--- a/src/com/android/mail/analytics/AnalyticsUtils.java
+++ b/src/com/android/mail/analytics/AnalyticsUtils.java
@@ -90,6 +90,8 @@
             s = "send_message";
         } else if (id == R.id.discard) {
             s = "compose_discard_draft";
+        } else if (id == R.id.search) {
+            s = "search";
         } else if (id == R.id.print_all) {
             s = "print_all";
         } else if (id == R.id.print_message) {
diff --git a/src/com/android/mail/compose/ComposeActivity.java b/src/com/android/mail/compose/ComposeActivity.java
index 069a837..e2ff335 100644
--- a/src/com/android/mail/compose/ComposeActivity.java
+++ b/src/com/android/mail/compose/ComposeActivity.java
@@ -1546,7 +1546,7 @@
                     quotedText = body.substring(quotedTextIndex);
                 }
             }
-            mBodyView.setText(bodyText);
+            setBody(bodyText, false);
         }
         if (quotedTextIndex > -1 && quotedText != null) {
             mQuotedTextView.setQuotedTextFromDraft(quotedText, mForward);
@@ -3510,11 +3510,13 @@
 
     /**
      * Set the body of the message.
+     * Please try to exclusively use this method instead of calling mBodyView.setText(..) directly.
      *
      * @param text text to set
      * @param withSignature True to append a signature.
      */
     public void setBody(CharSequence text, boolean withSignature) {
+        LogUtils.i(LOG_TAG, "Body populated, len: %d, sig: %b", text.length(), withSignature);
         mBodyView.setText(text);
         if (withSignature) {
             appendSignature();
@@ -3555,7 +3557,7 @@
             if (!TextUtils.isEmpty(oldSignature)) {
                 int pos = getSignatureStartPosition(oldSignature, bodyText);
                 if (pos > -1) {
-                    mBodyView.setText(bodyText.substring(0, pos));
+                    setBody(bodyText.substring(0, pos), false);
                 }
             }
             setAccount(mReplyFromAccount.account);
@@ -3895,7 +3897,7 @@
         @Override
         protected void onPostExecute(Spanned spanned) {
             mBodyView.removeTextChangedListener(ComposeActivity.this);
-            mBodyView.setText(spanned);
+            setBody(spanned, false);
             mTextChanged = false;
             mBodyView.addTextChangedListener(ComposeActivity.this);
         }
diff --git a/src/com/android/mail/ui/AbstractActivityController.java b/src/com/android/mail/ui/AbstractActivityController.java
index cbec502..5c7fb8b 100644
--- a/src/com/android/mail/ui/AbstractActivityController.java
+++ b/src/com/android/mail/ui/AbstractActivityController.java
@@ -1607,6 +1607,9 @@
             showEmptyDialog();
         } else if (id == R.id.empty_spam) {
             showEmptyDialog();
+        } else if (id == R.id.search) {
+            mSearchViewController.showSearchActionBar(
+                    MaterialSearchViewController.SEARCH_VIEW_STATE_VISIBLE);
         } else {
             handled = false;
         }
diff --git a/src/com/android/mail/ui/ActionBarController.java b/src/com/android/mail/ui/ActionBarController.java
index cfa006e..34a1083 100644
--- a/src/com/android/mail/ui/ActionBarController.java
+++ b/src/com/android/mail/ui/ActionBarController.java
@@ -272,6 +272,10 @@
                 // is added.
                 setConversationModeOptions(menu);
                 break;
+            case ViewMode.CONVERSATION_LIST:
+                // The search menu item should only be visible for non-tablet devices
+                Utils.setMenuItemVisibility(menu, R.id.search,
+                        mAccount.supportsSearch() && !mIsOnTablet);
             case ViewMode.SEARCH_RESULTS_LIST:
                 // Hide compose and search
                 Utils.setMenuItemVisibility(menu, R.id.compose, false);
diff --git a/src/com/android/mail/ui/MailActivity.java b/src/com/android/mail/ui/MailActivity.java
index f46ed61..a21f595 100644
--- a/src/com/android/mail/ui/MailActivity.java
+++ b/src/com/android/mail/ui/MailActivity.java
@@ -29,6 +29,7 @@
 import android.nfc.NfcEvent;
 import android.os.Bundle;
 import android.support.v7.app.ActionBar;
+import android.support.v7.widget.Toolbar;
 import android.view.KeyEvent;
 import android.view.Menu;
 import android.view.MenuItem;
@@ -170,9 +171,13 @@
 
         setContentView(mController.getContentViewResource());
 
-        final CustomViewToolbar toolbar = (CustomViewToolbar) findViewById(R.id.mail_toolbar);
-        toolbar.setController(this, mController, mViewMode);
-        mController.setConversationListLayoutListener(toolbar);
+        final Toolbar toolbar = (Toolbar) findViewById(R.id.mail_toolbar);
+        if (toolbar instanceof CustomViewToolbar) {
+            // Tablets use CustomViewToolbar to override the default search menu item positioning.
+            final CustomViewToolbar customViewToolbar = (CustomViewToolbar) toolbar;
+            customViewToolbar.setController(this, mController, mViewMode);
+            mController.setConversationListLayoutListener(customViewToolbar);
+        }
         setSupportActionBar(toolbar);
         toolbar.setNavigationOnClickListener(mController.getNavigationViewClickListener());