Attach the stop button to the textbox in the title bar.

This also required using different assets for the title bar background.

Fix for http://b/issue?id=2485473
diff --git a/res/drawable/title_loading.xml b/res/drawable/title_loading.xml
new file mode 100644
index 0000000..7f145d3
--- /dev/null
+++ b/res/drawable/title_loading.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 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.
+-->
+
+<!-- Custom layout file which mimics the textfield_search look, but draws the
+        pressed state even without window focus -->
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <item android:state_pressed="true"
+        android:drawable="@*android:drawable/textfield_search_pressed" />
+
+    <item android:state_enabled="true" android:state_focused="true"
+        android:drawable="@*android:drawable/textfield_search_selected" />
+
+    <item android:drawable="@*android:drawable/textfield_search_default" />
+
+</selector>
+
diff --git a/res/layout/title_bar.xml b/res/layout/title_bar.xml
index f5c6d6d..22ab6e4 100644
--- a/res/layout/title_bar.xml
+++ b/res/layout/title_bar.xml
@@ -15,9 +15,12 @@
    limitations under the License.
 -->
 
+<!-- Manually set the height, to ensure that it matches the SearchDialog's
+        height.  It also ensures that when the stop button is showing it does
+        not change its height. -->
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
-    android:layout_height="wrap_content"
+    android:layout_height="57dip"
     android:orientation="vertical"
     android:paddingLeft="8dip"
     android:paddingRight="12dip"
@@ -72,6 +75,13 @@
                     android:ellipsize="end"
                 />
         </LinearLayout>
+        <ImageView android:id="@+id/stop"
+            android:background="@*android:drawable/btn_search_dialog"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:src="@drawable/ic_btn_stop_v2"
+            android:visibility="gone"
+        />
         <ImageView
             android:id="@+id/rt_btn"
             android:layout_width="wrap_content"
diff --git a/src/com/android/browser/TitleBar.java b/src/com/android/browser/TitleBar.java
index 98667c3..03d44a6 100644
--- a/src/com/android/browser/TitleBar.java
+++ b/src/com/android/browser/TitleBar.java
@@ -62,7 +62,7 @@
     private ProgressBar     mHorizontalProgress;
     private ImageView       mFavicon;
     private ImageView       mLockIcon;
-    private Drawable        mStopDrawable;
+    private ImageView       mStopButton;
     private Drawable        mBookmarkDrawable;
     private Drawable        mVoiceDrawable;
     private boolean         mInLoad;
@@ -75,6 +75,7 @@
     private boolean         mInVoiceMode;
     private Drawable        mVoiceModeBackground;
     private Drawable        mNormalBackground;
+    private Drawable        mLoadingBackground;
     private ImageSpan       mArcsSpan;
 
     private static int LONG_PRESS = 1;
@@ -92,6 +93,7 @@
         mTitleBg = findViewById(R.id.title_bg);
         mLockIcon = (ImageView) findViewById(R.id.lock);
         mFavicon = (ImageView) findViewById(R.id.favicon);
+        mStopButton = (ImageView) findViewById(R.id.stop);
 
         mRtButton = (ImageView) findViewById(R.id.rt_btn);
         Resources resources = context.getResources();
@@ -117,11 +119,11 @@
             mVoiceDrawable = resources.getDrawable(
                     android.R.drawable.ic_btn_speak_now);
         }
-        mStopDrawable = resources.getDrawable(R.drawable.ic_btn_stop_v2);
         mBookmarkDrawable = mRtButton.getDrawable();
         mVoiceModeBackground = resources.getDrawable(
                 R.drawable.title_voice);
         mNormalBackground = mTitleBg.getBackground();
+        mLoadingBackground = resources.getDrawable(R.drawable.title_loading);
         mArcsSpan = new ImageSpan(context, R.drawable.arcs,
                 ImageSpan.ALIGN_BASELINE);
     }
@@ -258,23 +260,28 @@
     /* package */ void setInVoiceMode(boolean inVoiceMode) {
         if (mInVoiceMode == inVoiceMode) return;
         mInVoiceMode = inVoiceMode && mVoiceSearchIntent != null;
-        Drawable rightButtonDrawable, titleDrawable;
+        Drawable titleDrawable;
         if (mInVoiceMode) {
-            rightButtonDrawable = mVoiceDrawable;
+            mRtButton.setImageDrawable(mVoiceDrawable);
             titleDrawable = mVoiceModeBackground;
             mTitle.setEllipsize(null);
+            mRtButton.setVisibility(View.VISIBLE);
+            mStopButton.setVisibility(View.GONE);
         } else {
-            titleDrawable = mNormalBackground;
             if (mInLoad) {
-                rightButtonDrawable = mStopDrawable;
+                titleDrawable = mLoadingBackground;
+                mRtButton.setVisibility(View.GONE);
+                mStopButton.setVisibility(View.VISIBLE);
             } else {
-                rightButtonDrawable = mBookmarkDrawable;
+                titleDrawable = mNormalBackground;
+                mRtButton.setVisibility(View.VISIBLE);
+                mStopButton.setVisibility(View.GONE);
+                mRtButton.setImageDrawable(mBookmarkDrawable);
             }
             mTitle.setEllipsize(TextUtils.TruncateAt.END);
         }
         mTitle.setSingleLine(!mInVoiceMode);
         mTitleBg.setBackgroundDrawable(titleDrawable);
-        mRtButton.setImageDrawable(rightButtonDrawable);
     }
 
     /**
@@ -299,6 +306,9 @@
             mHorizontalProgress.setVisibility(View.INVISIBLE);
             if (!mInVoiceMode) {
                 mRtButton.setImageDrawable(mBookmarkDrawable);
+                mRtButton.setVisibility(View.VISIBLE);
+                mStopButton.setVisibility(View.GONE);
+                mTitleBg.setBackgroundDrawable(mNormalBackground);
             }
             mInLoad = false;
         } else {
@@ -313,7 +323,9 @@
                 ((Animatable) mCircularProgress).start();
                 mHorizontalProgress.setVisibility(View.VISIBLE);
                 if (!mInVoiceMode) {
-                    mRtButton.setImageDrawable(mStopDrawable);
+                    mTitleBg.setBackgroundDrawable(mLoadingBackground);
+                    mRtButton.setVisibility(View.GONE);
+                    mStopButton.setVisibility(View.VISIBLE);
                 }
                 mInLoad = true;
             }