Update url bar look & feel

       updated assets, layout, search behavior

Change-Id: I05543e57cb9a69e3a7cb5fe9a27648fd7196e51e
diff --git a/res/drawable-mdpi/ic_clear_search_light.png b/res/drawable-mdpi/ic_clear_search_light.png
new file mode 100644
index 0000000..8c66fa1
--- /dev/null
+++ b/res/drawable-mdpi/ic_clear_search_light.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_favorite_on_normal.png b/res/drawable-mdpi/ic_favorite_on_normal.png
new file mode 100644
index 0000000..b086569
--- /dev/null
+++ b/res/drawable-mdpi/ic_favorite_on_normal.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_search_light.png b/res/drawable-mdpi/ic_search_light.png
new file mode 100644
index 0000000..63c10ab
--- /dev/null
+++ b/res/drawable-mdpi/ic_search_light.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_voice_search.png b/res/drawable-mdpi/ic_voice_search.png
new file mode 100644
index 0000000..a2fe874
--- /dev/null
+++ b/res/drawable-mdpi/ic_voice_search.png
Binary files differ
diff --git a/res/drawable-mdpi/textfield_active_holo_dark.9.png b/res/drawable-mdpi/textfield_active_holo_dark.9.png
new file mode 100644
index 0000000..d37c8b2
--- /dev/null
+++ b/res/drawable-mdpi/textfield_active_holo_dark.9.png
Binary files differ
diff --git a/res/drawable-mdpi/textfield_default_holo_dark.9.png b/res/drawable-mdpi/textfield_default_holo_dark.9.png
new file mode 100644
index 0000000..ab6abdc
--- /dev/null
+++ b/res/drawable-mdpi/textfield_default_holo_dark.9.png
Binary files differ
diff --git a/res/drawable/btn_star.xml b/res/drawable/btn_star.xml
new file mode 100644
index 0000000..4c3d145
--- /dev/null
+++ b/res/drawable/btn_star.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2008 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.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item android:state_activated="true"
+          android:drawable="@drawable/ic_favorite_on_normal" />
+    <item android:state_activated="false"
+          android:drawable="@drawable/ic_favorite_off_normal" />
+</selector>
diff --git a/res/layout/url_bar.xml b/res/layout/url_bar.xml
index 3636ca8..61b03ed 100644
--- a/res/layout/url_bar.xml
+++ b/res/layout/url_bar.xml
@@ -27,89 +27,46 @@
             android:src="@drawable/ic_back_normal"
             android:layout_width="wrap_content"
             android:layout_height="match_parent"
-            style="@style/HoloButton"
-            android:background="@drawable/browserbarbutton" />
+            style="@style/HoloButton" />
         <ImageButton
             android:id="@+id/forward"
             android:src="@drawable/ic_forward_normal"
             android:layout_width="wrap_content"
             android:layout_height="match_parent"
-            style="@style/HoloButton"
-            android:background="@drawable/browserbarbutton" />
+            style="@style/HoloButton" />
         <ImageView
             android:id="@+id/stop"
-            android:background="@drawable/browserbarbutton"
             android:layout_width="wrap_content"
             android:layout_height="match_parent"
             style="@style/HoloButton"
             android:gravity="center_vertical"
             android:src="@drawable/ic_stop_normal" />
         <LinearLayout
-            android:id="@+id/urlbar_unfocused"
+            android:id="@+id/urlbar_focused"
             android:layout_width="0dip"
             android:layout_height="match_parent"
             android:layout_weight="1.0"
-            android:background="@null"
-            android:orientation="horizontal">
-            <ImageView
-                android:id="@+id/browsericon"
-                android:src="@drawable/ic_web_white"
-                android:layout_width="wrap_content"
-                android:layout_height="match_parent"
-                style="@style/HoloButton" />
+            android:layout_marginLeft="16dip"
+            android:orientation="horizontal"
+            android:background="@drawable/textfield_active_holo_dark">
             <ImageView
                 android:id="@+id/lock"
                 android:layout_width="wrap_content"
                 android:layout_height="match_parent"
                 style="@style/HoloIcon"
                 android:visibility="gone" />
-            <TextView
-                android:id="@+id/url_unfocused"
-                android:layout_width="0dip"
-                android:layout_weight="1.0"
-                android:layout_height="match_parent"
-                android:background="@null"
-                android:textAppearance="?android:attr/textAppearanceMedium"
-                android:textColor="#ffc0c0c0"
-                android:hint="@string/search_hint"
-                android:gravity="center_vertical"
-                android:singleLine="true"
-                android:ellipsize="end"
-                android:lines="1"
-                android:scrollHorizontally="true" />
-            <view class="com.android.browser.TitleBarXLarge$CustomCheck"
-                android:id="@+id/star"
-                android:layout_width="wrap_content"
-                android:layout_height="match_parent"
-                style="@style/HoloButton"
-                android:focusable="false"
-                android:button="@android:drawable/btn_star"
-                android:background="@drawable/browserbarbutton" />
-        </LinearLayout>
-        <LinearLayout
-            android:id="@+id/urlbar_focused"
-            android:layout_width="0dip"
-            android:layout_height="match_parent"
-            android:layout_weight="1.0"
-            android:orientation="horizontal"
-            android:background="@drawable/text_field_results"
-            android:visibility="gone">
-            <ImageView
-                android:id="@+id/searchicon"
-                android:src="@drawable/ic_search_category_suggest"
-                android:layout_width="wrap_content"
-                android:layout_height="match_parent"
-                style="@style/HoloButton" />
             <com.android.browser.UrlInputView
                 android:id="@+id/url_focused"
                 android:layout_width="0dip"
                 android:layout_weight="1.0"
                 android:layout_height="match_parent"
+                android:layout_marginTop="12dip"
+                android:layout_marginLeft="16dip"
+                android:paddingLeft="0dip"
+                android:paddingRight="0dip"
                 android:background="@null"
                 android:textAppearance="?android:attr/textAppearanceMedium"
-                android:textColor="@color/black"
                 android:hint="@string/search_hint"
-                android:gravity="center_vertical"
                 android:singleLine="true"
                 android:ellipsize="end"
                 android:lines="1"
@@ -118,8 +75,14 @@
                 android:imeOptions="actionGo"
                 style="@style/Suggestions" />
             <ImageView
+                android:id="@+id/star"
+                android:src="@drawable/btn_star"
+                android:layout_width="wrap_content"
+                android:layout_height="match_parent"
+                style="@style/HoloButton" />
+            <ImageView
                 android:id="@+id/clear"
-                android:src="@drawable/ic_clear_search"
+                android:src="@drawable/ic_clear_search_light"
                 android:layout_width="wrap_content"
                 android:layout_height="match_parent"
                 style="@style/HoloButton" />
@@ -131,23 +94,27 @@
             android:layout_height="match_parent"
             android:visibility="gone"
             android:gravity="center_vertical"
-            style="@style/HoloButton"
-            android:background="@drawable/browserbarbutton" />
+            style="@style/HoloButton" />
+        <ImageView
+            android:id="@+id/voicesearch"
+            android:src="@drawable/ic_voice_search"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            style="@style/HoloButton" />
         <ImageButton
             android:id="@+id/search"
             android:src="@drawable/ic_search_normal"
             android:layout_width="wrap_content"
             android:layout_height="match_parent"
             android:gravity="center_vertical"
-            style="@style/HoloButton"
-            android:background="@drawable/browserbarbutton" />
+            style="@style/HoloButton" />
         <ImageButton
             android:id="@+id/all_btn"
             android:layout_width="wrap_content"
             android:layout_height="match_parent"
+            android:layout_marginRight="4dip"
             android:scaleType="center"
             style="@style/HoloButton"
-            android:background="@drawable/browserbarbutton"
             android:src="@drawable/ic_bookmarks_history_normal" />
     </LinearLayout>
     <com.android.browser.PageProgressView
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 115676c..9df1c3a 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -41,8 +41,7 @@
         <item name="android:windowExitAnimation">@anim/title_bar_exit</item>
     </style>
         <style name="HoloIcon">
-        <item name="android:paddingLeft">16dip</item>
-        <item name="android:paddingRight">16dip</item>
+        <item name="android:layout_marginLeft">16dip</item>
     </style>
     <style name="HoloButton" parent="@style/HoloIcon">
         <item name="android:background">@drawable/browserbarbutton</item>
diff --git a/src/com/android/browser/TitleBarXLarge.java b/src/com/android/browser/TitleBarXLarge.java
index 42effe1..5326280 100644
--- a/src/com/android/browser/TitleBarXLarge.java
+++ b/src/com/android/browser/TitleBarXLarge.java
@@ -26,20 +26,21 @@
 import android.graphics.Bitmap;
 import android.graphics.drawable.Drawable;
 import android.os.Bundle;
+import android.text.Editable;
 import android.text.TextUtils;
-import android.util.AttributeSet;
+import android.text.TextWatcher;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.View.OnClickListener;
-import android.widget.CheckBox;
+import android.view.View.OnFocusChangeListener;
 import android.widget.ImageView;
-import android.widget.TextView;
 
 /**
  * tabbed title bar for xlarge screen browser
  */
 public class TitleBarXLarge extends TitleBarBase
-    implements UrlInputListener, OnClickListener {
+    implements UrlInputListener, OnClickListener, OnFocusChangeListener,
+    TextWatcher {
 
     private static final int PROGRESS_MAX = 100;
 
@@ -51,17 +52,16 @@
     private View mContainer;
     private View mBackButton;
     private View mForwardButton;
-    private CheckBox mStar;
+    private ImageView mStar;
     private View mSearchButton;
-    private View mFocusContainer;
-    private View mUnfocusContainer;
+    private View mUrlContainer;
     private View mGoButton;
     private ImageView mStopButton;
     private View mAllButton;
     private View mClearButton;
+    private View mVoiceSearch;
     private PageProgressView mProgressView;
-    private UrlInputView mUrlFocused;
-    private TextView mUrlUnfocused;
+    private UrlInputView mUrlInput;
     private boolean mInLoad;
 
     public TitleBarXLarge(Activity activity, UiController controller) {
@@ -78,23 +78,21 @@
         factory.inflate(R.layout.url_bar, this);
 
         mContainer = findViewById(R.id.taburlbar);
-        mUrlFocused = (UrlInputView) findViewById(R.id.url_focused);
-        mUrlUnfocused = (TextView) findViewById(R.id.url_unfocused);
+        mUrlInput = (UrlInputView) findViewById(R.id.url_focused);
         mAllButton = findViewById(R.id.all_btn);
         // TODO: Change enabled states based on whether you can go
         // back/forward.  Probably should be done inside onPageStarted.
         mBackButton = findViewById(R.id.back);
         mForwardButton = findViewById(R.id.forward);
-        mStar = (CheckBox) findViewById(R.id.star);
+        mStar = (ImageView) findViewById(R.id.star);
         mStopButton = (ImageView) findViewById(R.id.stop);
         mSearchButton = findViewById(R.id.search);
         mLockIcon = (ImageView) findViewById(R.id.lock);
         mGoButton = findViewById(R.id.go);
         mClearButton = findViewById(R.id.clear);
+        mVoiceSearch = findViewById(R.id.voicesearch);
         mProgressView = (PageProgressView) findViewById(R.id.progress);
-        mFocusContainer = findViewById(R.id.urlbar_focused);
-        mUnfocusContainer = findViewById(R.id.urlbar_unfocused);
-
+        mUrlContainer = findViewById(R.id.urlbar_focused);
         mBackButton.setOnClickListener(this);
         mForwardButton.setOnClickListener(this);
         mStar.setOnClickListener(this);
@@ -103,21 +101,28 @@
         mSearchButton.setOnClickListener(this);
         mGoButton.setOnClickListener(this);
         mClearButton.setOnClickListener(this);
-        mUrlFocused.setUrlInputListener(this);
-        mUrlFocused.setContainer(mFocusContainer);
-        mUrlFocused.setController(mUiController);
-        mUnfocusContainer.setOnClickListener(this);
+        mUrlContainer.setOnClickListener(this);
+        mUrlInput.setUrlInputListener(this);
+        mUrlInput.setContainer(mUrlContainer);
+        mUrlInput.setController(mUiController);
+        mUrlInput.setOnFocusChangeListener(this);
+        mUrlInput.setSelectAllOnFocus(true);
+        mUrlInput.addTextChangedListener(this);
+        setUrlMode(false);
+    }
+
+    @Override
+    public void onFocusChange(View view, boolean hasFocus) {
+        setUrlMode(hasFocus);
     }
 
     public void setCurrentUrlIsBookmark(boolean isBookmark) {
-        mStar.setChecked(isBookmark);
+        mStar.setActivated(isBookmark);
     }
 
     @Override
     public void onClick(View v) {
-        if (mUnfocusContainer == v) {
-            setUrlMode(true);
-        } else if (mBackButton == v) {
+        if (mBackButton == v) {
             mUiController.getCurrentTopWebView().goBack();
         } else if (mForwardButton == v) {
             mUiController.getCurrentTopWebView().goForward();
@@ -131,12 +136,12 @@
         } else if (mStopButton == v) {
             stopOrRefresh();
         } else if (mGoButton == v) {
-            if (!TextUtils.isEmpty(mUrlFocused.getText())) {
-                onAction(mUrlFocused.getText().toString(), null,
+            if (!TextUtils.isEmpty(mUrlInput.getText())) {
+                onAction(mUrlInput.getText().toString(), null,
                         UrlInputView.TYPED);
             }
         } else if (mClearButton == v) {
-            mUrlFocused.setText("");
+            clearOrClose();
         }
     }
 
@@ -147,6 +152,16 @@
     @Override
     void setFavicon(Bitmap icon) { }
 
+    private void clearOrClose() {
+        if (TextUtils.isEmpty(mUrlInput.getText())) {
+            // close
+            setUrlMode(false);
+        } else {
+            // clear
+            mUrlInput.setText("");
+        }
+    }
+
     // UrlInputListener implementation
 
     @Override
@@ -181,31 +196,30 @@
     public void onEdit(String text) {
         setDisplayTitle(text, true);
         if (text != null) {
-            mUrlFocused.setSelection(text.length());
+            mUrlInput.setSelection(text.length());
         }
     }
 
     private void setUrlMode(boolean focused) {
-        swapUrlContainer(focused);
         if (focused) {
-            mUrlFocused.selectAll();
-            mUrlFocused.requestFocus();
-            mUrlFocused.setDropDownWidth(mUnfocusContainer.getWidth());
-            mUrlFocused.setDropDownHorizontalOffset(-mUrlFocused.getLeft());
+            mUrlInput.setDropDownWidth(mUrlContainer.getWidth());
+            mUrlInput.setDropDownHorizontalOffset(-mUrlInput.getLeft());
             mSearchButton.setVisibility(View.GONE);
-            mGoButton.setVisibility(View.VISIBLE);
+            mStar.setVisibility(View.GONE);
+            mClearButton.setVisibility(View.VISIBLE);
+            updateSearchMode();
         } else {
+            mUrlInput.clearFocus();
             mSearchButton.setVisibility(View.VISIBLE);
             mGoButton.setVisibility(View.GONE);
+            mVoiceSearch.setVisibility(View.GONE);
+            mStar.setVisibility(View.VISIBLE);
+            mClearButton.setVisibility(View.GONE);
         }
     }
 
-    private void swapUrlContainer(boolean focus) {
-        mUnfocusContainer.setVisibility(focus ? View.GONE : View.VISIBLE);
-        mFocusContainer.setVisibility(focus ? View.VISIBLE : View.GONE);
-    }
-
     private void search() {
+        mUrlInput.requestFocus();
         setDisplayTitle("");
         setUrlMode(true);
     }
@@ -239,36 +253,42 @@
         }
     }
 
+    private void updateSearchMode() {
+        setSearchMode(TextUtils.isEmpty(mUrlInput.getText()));
+    }
+
+    private void setSearchMode(boolean voiceSearchEnabled) {
+        mVoiceSearch.setVisibility(voiceSearchEnabled ? View.VISIBLE :
+                View.GONE);
+        mGoButton.setVisibility(voiceSearchEnabled ? View.GONE :
+                View.VISIBLE);
+    }
+
     @Override
     /* package */ void setDisplayTitle(String title) {
-        mUrlFocused.setText(title, false);
-        mUrlUnfocused.setText(title);
+        mUrlInput.setText(title, false);
     }
 
     void setDisplayTitle(String title, boolean filter) {
-        mUrlFocused.setText(title, filter);
-        mUrlUnfocused.setText(title);
+        mUrlInput.setText(title, filter);
     }
 
-    /**
-     * Custom CheckBox which does not toggle when pressed.  Used by mStar.
-     */
-    public static class CustomCheck extends CheckBox {
-        public CustomCheck(Context context) {
-            super(context);
-        }
+    // UrlInput text watcher
 
-        public CustomCheck(Context context, AttributeSet attrs) {
-            super(context, attrs);
-        }
-
-        public CustomCheck(Context context, AttributeSet attrs, int defStyle) {
-            super(context, attrs, defStyle);
-        }
-
-        @Override
-        public void toggle() {
-            // Do nothing
+    @Override
+    public void afterTextChanged(Editable s) {
+        if (mUrlInput.hasFocus()) {
+            // check if url input is empty and adjust voice search state
+            updateSearchMode();
         }
     }
+
+    @Override
+    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+    }
+
+    @Override
+    public void onTextChanged(CharSequence s, int start, int before, int count) {
+    }
+
 }
diff --git a/src/com/android/browser/UrlInputView.java b/src/com/android/browser/UrlInputView.java
index 0abea12..bd47f6a 100644
--- a/src/com/android/browser/UrlInputView.java
+++ b/src/com/android/browser/UrlInputView.java
@@ -89,7 +89,7 @@
     protected void onConfigurationChanged(Configuration config) {
         super.onConfigurationChanged(config);
         mLandscape = (config.orientation &
-                Configuration.ORIENTATION_LANDSCAPE) > 0;
+                Configuration.ORIENTATION_LANDSCAPE) != 0;
         mAdapter.setLandscapeMode(mLandscape);
         if (isPopupShowing() && (getVisibility() == View.VISIBLE)) {
             setupDropDown();
@@ -116,6 +116,7 @@
         if (getLeft() != -getDropDownHorizontalOffset()) {
             setDropDownHorizontalOffset(-getLeft());
         }
+        setDropDownVerticalOffset(8);
     }
 
     @Override
@@ -151,7 +152,6 @@
 
     private void finishInput(String url, String extra, String source) {
         this.dismissDropDown();
-        this.setSelection(0,0);
         mInputManager.hideSoftInputFromWindow(getWindowToken(), 0);
         if (TextUtils.isEmpty(url)) {
             mListener.onDismiss();