Switch the phone to use the omnibox instead of qsb

 Initial changes, needs more work

Change-Id: Ic9bbe4eb8e95212baa7c40813217f01d9efdf286
diff --git a/res/layout/title_bar.xml b/res/layout/title_bar.xml
index 9bfba35..a73fdca 100644
--- a/res/layout/title_bar.xml
+++ b/res/layout/title_bar.xml
@@ -23,7 +23,7 @@
     android:paddingRight="12dip"
     android:paddingTop="2dip"
     android:paddingBottom="1dip"
-    android:background="@drawable/search_plate_browser" >
+    android:background="@drawable/bg_urlbar" >
 
     <ProgressBar android:id="@+id/progress_horizontal"
         style="?android:attr/progressBarStyleHorizontal"
@@ -40,13 +40,13 @@
         >
 
         <LinearLayout android:id="@+id/title_bg"
-            android:background="@drawable/title_text"
             android:layout_width="0dip"
             android:layout_weight="1.0"
-            android:layout_height="wrap_content"
+            android:layout_height="48dip"
             android:layout_marginBottom="4dip"
             android:gravity="center_vertical"
             android:orientation="horizontal"
+            android:background="@drawable/url_background"
             >
                 <ImageView android:id="@+id/favicon"
                     android:layout_width="20dip"
@@ -59,16 +59,25 @@
                     android:layout_marginLeft="6dip"
                     android:visibility="gone"
                     />
-                <TextView
-                    android:id="@+id/title"
-                    android:layout_height="wrap_content"
+                <com.android.browser.UrlInputView
+                    android:id="@+id/url_input"
+                    android:focusable="true"
                     android:layout_width="0dip"
                     android:layout_weight="1.0"
-                    android:layout_marginLeft="3dip"
-                    android:gravity="center_vertical"
+                    android:layout_height="match_parent"
+                    android:layout_marginLeft="16dip"
+                    android:paddingLeft="0dip"
+                    android:paddingRight="0dip"
+                    android:background="@null"
+                    android:textAppearance="?android:attr/textAppearanceMedium"
+                    android:hint="@string/search_hint"
                     android:singleLine="true"
                     android:ellipsize="end"
-                />
+                    android:lines="1"
+                    android:scrollHorizontally="true"
+                    android:inputType="textUri"
+                    android:imeOptions="actionGo"
+                    style="@style/Suggestions" />
         </LinearLayout>
         <ImageView android:id="@+id/stop"
             android:background="@drawable/stop_background"
@@ -78,7 +87,7 @@
             android:src="@drawable/ic_btn_stop_v2"
             android:visibility="gone"
         />
-        <ImageView
+        <ImageButton
             android:id="@+id/rt_btn"
             android:layout_width="wrap_content"
             android:layout_height="match_parent"
diff --git a/res/values-xlarge/integers.xml b/res/values-xlarge/integers.xml
new file mode 100644
index 0000000..abdafbf
--- /dev/null
+++ b/res/values-xlarge/integers.xml
@@ -0,0 +1,19 @@
+<?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.
+-->
+<resources
+    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+    <!-- The number of lines in the suggestions dropdown in landscape -->
+    <integer name="max_suggest_lines_landscape">5</integer>
+    <!-- The number of lines in the suggestions dropdown in portrait -->
+    <integer name="max_suggest_lines_portrait">12</integer>
+</resources>
diff --git a/res/values/integers.xml b/res/values/integers.xml
index a0b7ae3..3356f77 100644
--- a/res/values/integers.xml
+++ b/res/values/integers.xml
@@ -15,7 +15,7 @@
     <!-- The number of lines in the suggestions dropdown in landscape -->
     <integer name="max_suggest_lines_landscape">5</integer>
     <!-- The number of lines in the suggestions dropdown in portrait -->
-    <integer name="max_suggest_lines_portrait">12</integer>
+    <integer name="max_suggest_lines_portrait">4</integer>
     <!--  The maximum number of open tabs -->
     <integer name="max_tabs">16</integer>
     <!--  The duration of the tab animations in millisecs  -->
diff --git a/src/com/android/browser/PhoneUi.java b/src/com/android/browser/PhoneUi.java
index cfe7351..a7b7834 100644
--- a/src/com/android/browser/PhoneUi.java
+++ b/src/com/android/browser/PhoneUi.java
@@ -49,7 +49,7 @@
      */
     public PhoneUi(Activity browser, UiController controller) {
         super(browser, controller);
-        mTitleBar = new TitleBar(mActivity, mUiController);
+        mTitleBar = new TitleBar(mActivity, mUiController, this);
         // mTitleBar will be always be shown in the fully loaded mode on
         // phone
         mTitleBar.setProgress(100);
diff --git a/src/com/android/browser/TitleBar.java b/src/com/android/browser/TitleBar.java
index b8ad2ef..7b5482a 100644
--- a/src/com/android/browser/TitleBar.java
+++ b/src/com/android/browser/TitleBar.java
@@ -16,8 +16,6 @@
 
 package com.android.browser;
 
-import com.android.common.speech.LoggingEvents;
-
 import android.app.Activity;
 import android.content.Intent;
 import android.content.pm.PackageManager;
@@ -25,8 +23,6 @@
 import android.content.res.Resources;
 import android.graphics.drawable.Animatable;
 import android.graphics.drawable.Drawable;
-import android.os.Handler;
-import android.os.Message;
 import android.speech.RecognizerIntent;
 import android.text.SpannableString;
 import android.text.Spanned;
@@ -37,23 +33,20 @@
 import android.view.ContextMenu;
 import android.view.LayoutInflater;
 import android.view.MenuInflater;
-import android.view.MotionEvent;
 import android.view.View;
-import android.view.ViewConfiguration;
+import android.view.View.OnFocusChangeListener;
+import android.widget.ImageButton;
 import android.widget.ImageView;
 import android.widget.ProgressBar;
-import android.widget.TextView;
 
 /**
  * This class represents a title bar for a particular "tab" or "window" in the
  * browser.
  */
-public class TitleBar extends TitleBarBase {
+public class TitleBar extends TitleBarBase implements OnFocusChangeListener {
 
     private Activity mActivity;
-    private UiController mController;
-    private TextView mTitle;
-    private ImageView mRtButton;
+    private ImageButton mRtButton;
     private Drawable mCircularProgress;
     private ProgressBar mHorizontalProgress;
     private ImageView mStopButton;
@@ -61,35 +54,33 @@
     private Drawable mVoiceDrawable;
     private boolean mInLoad;
     private View mTitleBg;
-    private MyHandler mHandler;
     private Intent mVoiceSearchIntent;
-    private boolean mInVoiceMode;
     private Drawable mVoiceModeBackground;
     private Drawable mNormalBackground;
-    private Drawable mLoadingBackground;
     private ImageSpan mArcsSpan;
     private int mLeftMargin;
     private int mRightMargin;
 
-    private static int LONG_PRESS = 1;
-
-    public TitleBar(Activity activity, UiController controller) {
-        super(activity);
-        mHandler = new MyHandler();
+    public TitleBar(Activity activity, UiController controller, PhoneUi ui) {
+        super(activity, controller, ui);
         LayoutInflater factory = LayoutInflater.from(activity);
         factory.inflate(R.layout.title_bar, this);
         mActivity = activity;
-        mController = controller;
 
-        mTitle = (TextView) findViewById(R.id.title);
-        mTitle.setCompoundDrawablePadding(5);
+        mUrlInput = (UrlInputView) findViewById(R.id.url_input);
+        mUrlInput.setCompoundDrawablePadding(5);
+        mUrlInput.setContainer(this);
+        mUrlInput.setSelectAllOnFocus(true);
+        mUrlInput.setController(mUiController);
+        mUrlInput.setUrlInputListener(this);
+        mUrlInput.setOnFocusChangeListener(this);
 
         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);
+        mRtButton = (ImageButton) findViewById(R.id.rt_btn);
         Resources resources = activity.getResources();
         mCircularProgress = resources.getDrawable(
                 com.android.internal.R.drawable.search_spinner);
@@ -125,30 +116,10 @@
         mVoiceModeBackground = resources.getDrawable(
                 R.drawable.title_voice);
         mNormalBackground = mTitleBg.getBackground();
-        mLoadingBackground = resources.getDrawable(R.drawable.title_loading);
         mArcsSpan = new ImageSpan(activity, R.drawable.arcs,
                 ImageSpan.ALIGN_BASELINE);
     }
 
-    private class MyHandler extends Handler {
-        @Override
-        public void handleMessage(Message msg) {
-            if (msg.what == LONG_PRESS) {
-                // Prevent the normal action from happening by setting the title
-                // bar's state to false.
-                mTitleBg.setPressed(false);
-                // Need to call a special method on BrowserActivity for when the
-                // fake title bar is up, because its ViewGroup does not show a
-                // context menu.
-                // TODO:
-                // this test is not valid for all UIs; fix later
-                if (getParent() != null) {
-                    mActivity.openContextMenu(TitleBar.this);
-                }
-            }
-        }
-    };
-
     @Override
     public void createContextMenu(ContextMenu menu) {
         MenuInflater inflater = mActivity.getMenuInflater();
@@ -156,93 +127,6 @@
         mActivity.onCreateContextMenu(menu, this, null);
     }
 
-    @Override
-    public boolean onTouchEvent(MotionEvent event) {
-        ImageView button = mInLoad ? mStopButton : mRtButton;
-        switch (event.getAction()) {
-            case MotionEvent.ACTION_DOWN:
-                // Make all touches hit either the textfield or the button,
-                // depending on which side of the right edge of the textfield
-                // they hit.
-                if ((int) event.getX() > mTitleBg.getRight()) {
-                    button.setPressed(true);
-                } else {
-                    mTitleBg.setPressed(true);
-                    mHandler.sendMessageDelayed(mHandler.obtainMessage(
-                            LONG_PRESS),
-                            ViewConfiguration.getLongPressTimeout());
-                }
-                break;
-            case MotionEvent.ACTION_MOVE:
-                int slop = ViewConfiguration.get(mActivity)
-                        .getScaledTouchSlop();
-                if ((int) event.getY() > getHeight() + slop) {
-                    // We only trigger the actions in ACTION_UP if one or the
-                    // other is pressed.  Since the user moved off the title
-                    // bar, mark both as not pressed.
-                    mTitleBg.setPressed(false);
-                    button.setPressed(false);
-                    mHandler.removeMessages(LONG_PRESS);
-                    break;
-                }
-                int x = (int) event.getX();
-                int titleRight = mTitleBg.getRight();
-                if (mTitleBg.isPressed() && x > titleRight + slop) {
-                    mTitleBg.setPressed(false);
-                    mHandler.removeMessages(LONG_PRESS);
-                } else if (button.isPressed() && x < titleRight - slop) {
-                    button.setPressed(false);
-                }
-                break;
-            case MotionEvent.ACTION_CANCEL:
-                button.setPressed(false);
-                mTitleBg.setPressed(false);
-                mHandler.removeMessages(LONG_PRESS);
-                break;
-            case MotionEvent.ACTION_UP:
-                if (button.isPressed()) {
-                    if (mInVoiceMode) {
-                        if (mController.getTabControl().getCurrentTab()
-                                .voiceSearchSourceIsGoogle()) {
-                            Intent i = new Intent(
-                                    LoggingEvents.ACTION_LOG_EVENT);
-                            i.putExtra(LoggingEvents.EXTRA_EVENT,
-                                    LoggingEvents.VoiceSearch.RETRY);
-                            mActivity.sendBroadcast(i);
-                        }
-                        mActivity.startActivity(mVoiceSearchIntent);
-                    } else if (mInLoad) {
-                        mController.stopLoading();
-                    } else {
-                        mController.bookmarkCurrentPage(
-                                AddBookmarkPage.DEFAULT_FOLDER_ID, true);
-                    }
-                    button.setPressed(false);
-                } else if (mTitleBg.isPressed()) {
-                    mHandler.removeMessages(LONG_PRESS);
-                    if (mInVoiceMode) {
-                        if (mController.getTabControl().getCurrentTab()
-                                .voiceSearchSourceIsGoogle()) {
-                            Intent i = new Intent(
-                                    LoggingEvents.ACTION_LOG_EVENT);
-                            i.putExtra(LoggingEvents.EXTRA_EVENT,
-                                    LoggingEvents.VoiceSearch.N_BEST_REVEAL);
-                            mActivity.sendBroadcast(i);
-                        }
-                        mController.showVoiceSearchResults(
-                                mTitle.getText().toString().trim());
-                    } else {
-                        mController.editUrl();
-                    }
-                    mTitleBg.setPressed(false);
-                }
-                break;
-            default:
-                break;
-        }
-        return true;
-    }
-
     /**
      * Change the TitleBar to or from voice mode.  If there is no package to
      * handle voice search, the TitleBar cannot be set to voice mode.
@@ -255,7 +139,7 @@
         if (mInVoiceMode) {
             mRtButton.setImageDrawable(mVoiceDrawable);
             titleDrawable = mVoiceModeBackground;
-            mTitle.setEllipsize(null);
+            mUrlInput.setEllipsize(null);
             mRtButton.setVisibility(View.VISIBLE);
             mStopButton.setVisibility(View.GONE);
             mTitleBg.setBackgroundDrawable(titleDrawable);
@@ -263,20 +147,17 @@
                     mRightMargin, mTitleBg.getPaddingBottom());
         } else {
             if (mInLoad) {
-                titleDrawable = mLoadingBackground;
                 mRtButton.setVisibility(View.GONE);
                 mStopButton.setVisibility(View.VISIBLE);
             } else {
-                titleDrawable = mNormalBackground;
                 mRtButton.setVisibility(View.VISIBLE);
                 mStopButton.setVisibility(View.GONE);
                 mRtButton.setImageDrawable(mBookmarkDrawable);
             }
-            mTitle.setEllipsize(TextUtils.TruncateAt.END);
-            mTitleBg.setBackgroundDrawable(titleDrawable);
+            mUrlInput.setEllipsize(TextUtils.TruncateAt.END);
             mTitleBg.setPadding(mLeftMargin, 0, mRightMargin, 0);
         }
-        mTitle.setSingleLine(!mInVoiceMode);
+        mUrlInput.setSingleLine(!mInVoiceMode);
     }
 
     /**
@@ -285,7 +166,7 @@
     @Override
     void setProgress(int newProgress) {
         if (newProgress >= mHorizontalProgress.getMax()) {
-            mTitle.setCompoundDrawables(null, null, null, null);
+            mUrlInput.setCompoundDrawables(null, null, null, null);
             ((Animatable) mCircularProgress).stop();
             mHorizontalProgress.setVisibility(View.INVISIBLE);
             if (!mInVoiceMode) {
@@ -303,12 +184,11 @@
                 // are attached to a window before starting the animation,
                 // preventing a potential race condition
                 // (fix for bug http://b/2115736)
-                mTitle.setCompoundDrawables(null, null, mCircularProgress,
+                mUrlInput.setCompoundDrawables(null, null, mCircularProgress,
                         null);
                 ((Animatable) mCircularProgress).start();
                 mHorizontalProgress.setVisibility(View.VISIBLE);
                 if (!mInVoiceMode) {
-                    mTitleBg.setBackgroundDrawable(mLoadingBackground);
                     mTitleBg.setPadding(mLeftMargin, 0, mRightMargin, 0);
                     mRtButton.setVisibility(View.GONE);
                     mStopButton.setVisibility(View.VISIBLE);
@@ -326,7 +206,7 @@
     @Override
     void setDisplayTitle(String title) {
         if (title == null) {
-            mTitle.setText(R.string.new_tab);
+            mUrlInput.setText(R.string.new_tab);
         } else {
             if (mInVoiceMode) {
                 // Add two spaces.  The second one will be replaced with an
@@ -336,10 +216,17 @@
                 int end = spannable.length();
                 spannable.setSpan(mArcsSpan, end - 1, end,
                         Spanned.SPAN_MARK_POINT);
-                mTitle.setText(spannable);
+                mUrlInput.setText(spannable);
             } else {
-                mTitle.setText(title);
+                mUrlInput.setText(title);
             }
         }
     }
+
+    @Override
+    public void onFocusChange(View v, boolean hasFocus) {
+        if (v == mUrlInput && hasFocus) {
+            mActivity.closeOptionsMenu();
+        }
+    }
 }
diff --git a/src/com/android/browser/TitleBarBase.java b/src/com/android/browser/TitleBarBase.java
index 1e944f1..f62e0e4 100644
--- a/src/com/android/browser/TitleBarBase.java
+++ b/src/com/android/browser/TitleBarBase.java
@@ -16,13 +16,19 @@
 
 package com.android.browser;
 
+import com.android.browser.UrlInputView.UrlInputListener;
+
+import android.app.SearchManager;
 import android.content.Context;
+import android.content.Intent;
 import android.graphics.Bitmap;
 import android.graphics.Color;
 import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.Drawable;
 import android.graphics.drawable.LayerDrawable;
 import android.graphics.drawable.PaintDrawable;
+import android.os.Bundle;
+import android.speech.RecognizerResultsIntent;
 import android.view.Gravity;
 import android.view.View;
 import android.widget.AbsoluteLayout;
@@ -32,15 +38,21 @@
 /**
  * Base class for a title bar used by the browser.
  */
-public class TitleBarBase extends LinearLayout {
+public class TitleBarBase extends LinearLayout implements UrlInputListener {
     // These need to be set by the subclass.
     protected ImageView mFavicon;
     protected ImageView mLockIcon;
 
     protected Drawable mGenericFavicon;
+    protected UiController mUiController;
+    protected BaseUi mBaseUi;
+    protected UrlInputView mUrlInput;
+    protected boolean mInVoiceMode;
 
-    public TitleBarBase(Context context) {
+    public TitleBarBase(Context context, UiController controller, BaseUi ui) {
         super(context, null);
+        mUiController = controller;
+        mBaseUi = ui;
         mGenericFavicon = context.getResources().getDrawable(
                 R.drawable.app_web_browser_sm);
     }
@@ -98,4 +110,62 @@
         }
     }
 
+    // UrlInputListener implementation
+
+    /**
+     * callback from suggestion dropdown
+     * user selected a suggestion
+     */
+    @Override
+    public void onAction(String text, String extra, String source) {
+        mUiController.getCurrentTopWebView().requestFocus();
+        mBaseUi.hideTitleBar();
+        Intent i = new Intent();
+        String action = null;
+        if (UrlInputView.VOICE.equals(source)) {
+            action = RecognizerResultsIntent.ACTION_VOICE_SEARCH_RESULTS;
+            source = null;
+        } else {
+            action = Intent.ACTION_SEARCH;
+        }
+        i.setAction(action);
+        i.putExtra(SearchManager.QUERY, text);
+        if (extra != null) {
+            i.putExtra(SearchManager.EXTRA_DATA_KEY, extra);
+        }
+        if (source != null) {
+            Bundle appData = new Bundle();
+            appData.putString(com.android.common.Search.SOURCE, source);
+            i.putExtra(SearchManager.APP_DATA, appData);
+        }
+        mUiController.handleNewIntent(i);
+        setDisplayTitle(text);
+    }
+
+    @Override
+    public void onDismiss() {
+        final Tab currentTab = mBaseUi.getActiveTab();
+        mBaseUi.hideTitleBar();
+        post(new Runnable() {
+            public void run() {
+                clearFocus();
+                if ((currentTab != null) && !mInVoiceMode) {
+                    setDisplayTitle(currentTab.getUrl());
+                }
+            }
+        });
+    }
+
+    /**
+     * callback from the suggestion dropdown
+     * copy text to input field and stay in edit mode
+     */
+    @Override
+    public void onCopySuggestion(String text) {
+        mUrlInput.setText(text, true);
+        if (text != null) {
+            mUrlInput.setSelection(text.length());
+        }
+    }
+
 }
diff --git a/src/com/android/browser/TitleBarXLarge.java b/src/com/android/browser/TitleBarXLarge.java
index 453e1b8..e53d7f3 100644
--- a/src/com/android/browser/TitleBarXLarge.java
+++ b/src/com/android/browser/TitleBarXLarge.java
@@ -16,18 +16,13 @@
 
 package com.android.browser;
 
-import com.android.browser.UrlInputView.UrlInputListener;
 import com.android.browser.search.SearchEngine;
 
 import android.app.Activity;
-import android.app.SearchManager;
 import android.content.Context;
-import android.content.Intent;
 import android.content.res.Resources;
 import android.graphics.Bitmap;
 import android.graphics.drawable.Drawable;
-import android.os.Bundle;
-import android.speech.RecognizerResultsIntent;
 import android.text.Editable;
 import android.text.TextUtils;
 import android.text.TextWatcher;
@@ -48,12 +43,11 @@
  * tabbed title bar for xlarge screen browser
  */
 public class TitleBarXLarge extends TitleBarBase
-    implements UrlInputListener, OnClickListener, OnFocusChangeListener,
+        implements OnClickListener, OnFocusChangeListener,
     TextWatcher {
 
     private static final int PROGRESS_MAX = 100;
 
-    private UiController mUiController;
     private XLargeUi mUi;
 
     private Drawable mStopDrawable;
@@ -73,18 +67,15 @@
     private View mVoiceSearch;
     private View mVoiceSearchIndicator;
     private PageProgressView mProgressView;
-    private UrlInputView mUrlInput;
     private Drawable mFocusDrawable;
     private Drawable mUnfocusDrawable;
-    private boolean mInVoiceMode;
 
     private boolean mInLoad;
     private boolean mUseQuickControls;
 
     public TitleBarXLarge(Activity activity, UiController controller,
             XLargeUi ui) {
-        super(activity);
-        mUiController = controller;
+        super(activity, controller, ui);
         mUi = ui;
         Resources resources = activity.getResources();
         mStopDrawable = resources.getDrawable(R.drawable.ic_stop_holo_dark);
@@ -276,64 +267,6 @@
         }
     }
 
-    // UrlInputListener implementation
-
-    /**
-     * callback from suggestion dropdown
-     * user selected a suggestion
-     */
-    @Override
-    public void onAction(String text, String extra, String source) {
-        mUiController.getCurrentTopWebView().requestFocus();
-        mUi.hideTitleBar();
-        Intent i = new Intent();
-        String action = null;
-        if (UrlInputView.VOICE.equals(source)) {
-            action = RecognizerResultsIntent.ACTION_VOICE_SEARCH_RESULTS;
-            source = null;
-        } else {
-            action = Intent.ACTION_SEARCH;
-        }
-        i.setAction(action);
-        i.putExtra(SearchManager.QUERY, text);
-        if (extra != null) {
-            i.putExtra(SearchManager.EXTRA_DATA_KEY, extra);
-        }
-        if (source != null) {
-            Bundle appData = new Bundle();
-            appData.putString(com.android.common.Search.SOURCE, source);
-            i.putExtra(SearchManager.APP_DATA, appData);
-        }
-        mUiController.handleNewIntent(i);
-        setDisplayTitle(text);
-    }
-
-    @Override
-    public void onDismiss() {
-        final Tab currentTab = mUi.getActiveTab();
-        mUi.hideTitleBar();
-        post(new Runnable() {
-            public void run() {
-                TitleBarXLarge.this.clearFocus();
-                if ((currentTab != null) && !mInVoiceMode) {
-                    setDisplayTitle(currentTab.getUrl());
-                }
-            }
-        });
-    }
-
-    /**
-     * callback from the suggestion dropdown
-     * copy text to input field and stay in edit mode
-     */
-    @Override
-    public void onCopySuggestion(String text) {
-        mUrlInput.setText(text, true);
-        if (text != null) {
-            mUrlInput.setSelection(text.length());
-        }
-    }
-
     private void setEditMode(boolean edit) {
         if (edit) {
             mUrlInput.setDropDownWidth(mUrlContainer.getWidth());
diff --git a/src/com/android/browser/UrlInputView.java b/src/com/android/browser/UrlInputView.java
index 6817b36..1f15b32 100644
--- a/src/com/android/browser/UrlInputView.java
+++ b/src/com/android/browser/UrlInputView.java
@@ -137,7 +137,7 @@
     }
 
     private void setupDropDown() {
-        int width = mContainer.getWidth();
+        int width = mContainer != null ? mContainer.getWidth() : getWidth();
         if (width != getDropDownWidth()) {
             setDropDownWidth(width);
         }
@@ -160,6 +160,9 @@
 
     @Override
     public void onFocusChange(View v, boolean hasFocus) {
+        if (mWrappedFocusListener != null) {
+            mWrappedFocusListener.onFocusChange(v, hasFocus);
+        }
         if (hasFocus) {
             forceIme();
             if (mInVoiceMode) {
@@ -169,9 +172,6 @@
         } else {
             finishInput(null, null, null);
         }
-        if (mWrappedFocusListener != null) {
-            mWrappedFocusListener.onFocusChange(v, hasFocus);
-        }
     }
 
     public void setUrlInputListener(UrlInputListener listener) {
@@ -179,6 +179,7 @@
     }
 
     public void forceIme() {
+        mInputManager.focusIn(this);
         mInputManager.showSoftInput(this, 0);
     }