Fix focus highlight bug

    Bug: 5240233
    post the layout change on state change
    add clear button when editing

Change-Id: I9db16619cd39611153503b28757d4b16e52ab9e3
diff --git a/res/layout/title_bar_nav.xml b/res/layout/title_bar_nav.xml
index eeba9d7..8ed6331 100644
--- a/res/layout/title_bar_nav.xml
+++ b/res/layout/title_bar_nav.xml
@@ -26,6 +26,14 @@
         android:gravity="center_vertical"
         android:orientation="horizontal">
         <ImageView
+            android:id="@+id/magnify"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:paddingLeft="8dip"
+            android:paddingRight="8dip"
+            android:visibility="gone"
+            android:src="@drawable/ic_search_category_suggest" />
+        <ImageView
             android:id="@+id/incognito_icon"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
@@ -83,6 +91,14 @@
             android:src="@drawable/ic_voice_search_holo_dark"
             style="@style/HoloButton"
             android:visibility="gone" />
+        <ImageView
+            android:id="@+id/clear"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:contentDescription="@string/accessibility_button_clear"
+            android:src="@drawable/ic_close_window_holo_dark"
+            style="@style/HoloButton"
+            android:visibility="gone" />
     </LinearLayout>
     <ImageButton
         android:id="@+id/tab_switcher"
diff --git a/src/com/android/browser/NavigationBarPhone.java b/src/com/android/browser/NavigationBarPhone.java
index fee9604..7e8695b 100644
--- a/src/com/android/browser/NavigationBarPhone.java
+++ b/src/com/android/browser/NavigationBarPhone.java
@@ -36,6 +36,8 @@
 
     private ImageView mStopButton;
     private ImageView mVoiceButton;
+    private ImageView mMagnify;
+    private ImageView mClearButton;
     private Drawable mStopDrawable;
     private Drawable mRefreshDrawable;
     private String mStopDescription;
@@ -69,6 +71,9 @@
         mStopButton.setOnClickListener(this);
         mVoiceButton = (ImageView) findViewById(R.id.voice);
         mVoiceButton.setOnClickListener(this);
+        mClearButton = (ImageView) findViewById(R.id.clear);
+        mClearButton.setOnClickListener(this);
+        mMagnify = (ImageView) findViewById(R.id.magnify);
         mTabSwitcher = findViewById(R.id.tab_switcher);
         mTabSwitcher.setOnClickListener(this);
         mMore = findViewById(R.id.more);
@@ -156,6 +161,8 @@
             ((PhoneUi) mBaseUi).toggleNavScreen();
         } else if (mMore == v) {
             showMenu(mMore);
+        } else if (mClearButton == v) {
+            mUrlInput.setText("");
         } else {
             super.onClick(v);
         }
@@ -209,6 +216,8 @@
         case StateListener.STATE_NORMAL:
             mComboIcon.setVisibility(View.VISIBLE);
             mStopButton.setVisibility(View.GONE);
+            mClearButton.setVisibility(View.GONE);
+            mMagnify.setVisibility(View.GONE);
             setSearchMode(mInVoiceMode);
             mTabSwitcher.setVisibility(View.VISIBLE);
             mTitleContainer.setBackgroundDrawable(null);
@@ -217,6 +226,8 @@
         case StateListener.STATE_HIGHLIGHTED:
             mComboIcon.setVisibility(View.GONE);
             mStopButton.setVisibility(View.VISIBLE);
+            mClearButton.setVisibility(View.GONE);
+            mMagnify.setVisibility(View.GONE);
             setSearchMode(true);
             mTabSwitcher.setVisibility(View.GONE);
             mMore.setVisibility(View.GONE);
@@ -225,6 +236,8 @@
         case StateListener.STATE_EDITED:
             mComboIcon.setVisibility(View.GONE);
             mStopButton.setVisibility(View.GONE);
+            mClearButton.setVisibility(View.VISIBLE);
+            mMagnify.setVisibility(View.VISIBLE);
             setSearchMode(false);
             mTabSwitcher.setVisibility(View.GONE);
             mMore.setVisibility(View.GONE);
diff --git a/src/com/android/browser/UrlInputView.java b/src/com/android/browser/UrlInputView.java
index 2acc69b..fbdf400 100644
--- a/src/com/android/browser/UrlInputView.java
+++ b/src/com/android/browser/UrlInputView.java
@@ -56,6 +56,8 @@
     static final String SUGGESTED = "browser-suggest";
     static final String VOICE = "voice-search";
 
+    static final int POST_DELAY = 100;
+
     static interface StateListener {
         static final int STATE_NORMAL = 0;
         static final int STATE_HIGHLIGHTED = 1;
@@ -123,16 +125,23 @@
 
     protected void onFocusChanged(boolean focused, int direction, Rect prevRect) {
         super.onFocusChanged(focused, direction, prevRect);
+        int state = -1;
         if (focused) {
             if (hasSelection()) {
-                changeState(StateListener.STATE_HIGHLIGHTED);
+                state = StateListener.STATE_HIGHLIGHTED;
             } else {
-                changeState(StateListener.STATE_EDITED);
+                state = StateListener.STATE_EDITED;
             }
         } else {
             // reset the selection state
-            changeState(StateListener.STATE_NORMAL);
+            state = StateListener.STATE_NORMAL;
         }
+        final int s = state;
+        post(new Runnable() {
+            public void run() {
+                changeState(s);
+            }
+        });
     }
 
     @Override
@@ -141,7 +150,10 @@
         boolean res = super.onTouchEvent(evt);
         if ((MotionEvent.ACTION_DOWN == evt.getActionMasked())
               && hasSelection) {
-            changeState(StateListener.STATE_EDITED);
+            postDelayed(new Runnable() {
+                public void run() {
+                    changeState(StateListener.STATE_EDITED);
+                }}, POST_DELAY);
         }
         return res;
     }