Merge "Set the url input to current page when cleared" into honeycomb-mr1
diff --git a/res/layout/url_bar.xml b/res/layout/url_bar.xml
index bf184a8..8743906 100644
--- a/res/layout/url_bar.xml
+++ b/res/layout/url_bar.xml
@@ -32,17 +32,15 @@
             android:paddingLeft="15dip"
             android:paddingRight="15dip"
             android:textAppearance="?android:attr/textAppearanceMedium"/>
-        <Button
+        <Spinner
             android:id="@+id/autologin_account"
-            android:background="@android:drawable/btn_dropdown"
-            android:textColor="@android:color/primary_text_light"
             android:layout_height="wrap_content"
-            android:layout_width="wrap_content"/>
+            android:layout_width="wrap_content"
+            style="@android:style/Widget.Holo.Light.Spinner" />
         <Button
             android:id="@+id/autologin_login"
             android:text="@string/autologin_bar_login_text"
-            android:background="@android:drawable/btn_default"
-            android:textColor="@android:color/primary_text_light"
+            style="@android:style/Widget.Holo.Light.Button"
             android:layout_marginRight="15dip"
             android:layout_height="wrap_content"
             android:layout_width="wrap_content" />
diff --git a/src/com/android/browser/BrowserBookmarksPage.java b/src/com/android/browser/BrowserBookmarksPage.java
index 98b25a8..de28d0d 100644
--- a/src/com/android/browser/BrowserBookmarksPage.java
+++ b/src/com/android/browser/BrowserBookmarksPage.java
@@ -453,7 +453,7 @@
     }
 
     private void loadUrl(int position) {
-        if (mCallbacks != null) {
+        if (mCallbacks != null && mAdapter != null) {
             mCallbacks.onBookmarkSelected(mAdapter.getItem(position), false);
         }
     }
diff --git a/src/com/android/browser/DeviceAccountLogin.java b/src/com/android/browser/DeviceAccountLogin.java
index 50b8c97..818e076 100644
--- a/src/com/android/browser/DeviceAccountLogin.java
+++ b/src/com/android/browser/DeviceAccountLogin.java
@@ -21,22 +21,18 @@
 import android.accounts.AccountManagerCallback;
 import android.accounts.AccountManagerFuture;
 import android.app.Activity;
-import android.app.AlertDialog;
-import android.content.DialogInterface;
 import android.os.Bundle;
 import android.webkit.WebView;
-import android.webkit.WebViewClient;
 
 public class DeviceAccountLogin implements
-        AccountManagerCallback<Bundle>, DialogInterface.OnClickListener {
+        AccountManagerCallback<Bundle> {
 
     private final Activity mActivity;
     private final WebView mWebView;
     private final Tab mTab;
     private final WebViewController mWebViewController;
     private final AccountManager mAccountManager;
-    private Account[] mAccounts;
-    private int mCurrentAccount;
+    Account[] mAccounts;
     private AutoLoginCallback mCallback;
     private String mAuthToken;
 
@@ -48,7 +44,6 @@
     public static final int PROCESSING = 2;
 
     public interface AutoLoginCallback {
-        public void setAccount(String account);
         public void loginFailed();
     }
 
@@ -129,37 +124,19 @@
         mTab.setDeviceAccountLogin(null);
     }
 
-    public void login(AutoLoginCallback cb) {
+    public void login(int accountIndex, AutoLoginCallback cb) {
         mState = PROCESSING;
         mCallback = cb;
         mAccountManager.getAuthToken(
-                mAccounts[mCurrentAccount], mAuthToken, null,
+                mAccounts[accountIndex], mAuthToken, null,
                 mActivity, this, null);
     }
 
-    public void chooseAccount(AutoLoginCallback cb) {
-        mCallback = cb;
-        CharSequence[] names = new CharSequence[mAccounts.length];
-        int i = 0;
-        for (Account a : mAccounts) {
-            names[i++] = a.name;
+    public String[] getAccountNames() {
+        String[] names = new String[mAccounts.length];
+        for (int i = 0; i < mAccounts.length; i++) {
+            names[i] = mAccounts[i].name;
         }
-        new AlertDialog.Builder(mActivity)
-                .setTitle(R.string.pref_autologin_title)
-                .setSingleChoiceItems(names, mCurrentAccount, this)
-                .setCancelable(true)
-                .show();
-    }
-
-    public String getCurrentAccount() {
-        return mAccounts[mCurrentAccount].name;
-    }
-
-    @Override
-    public void onClick(DialogInterface d, int which) {
-        assert mCallback != null;
-        mCallback.setAccount(mAccounts[which].name);
-        mCurrentAccount = which;
-        d.dismiss();
+        return names;
     }
 }
diff --git a/src/com/android/browser/IntentHandler.java b/src/com/android/browser/IntentHandler.java
index 77db538..fa8bfbc 100644
--- a/src/com/android/browser/IntentHandler.java
+++ b/src/com/android/browser/IntentHandler.java
@@ -145,14 +145,18 @@
                     || (activateVoiceSearch && appId != null))
                     && !mActivity.getPackageName().equals(appId)
                     && (flags & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
-                Tab appTab = mTabControl.getTabFromId(appId);
-                if (appTab != null) {
-                    mController.reuseTab(appTab, appId, urlData);
-                    return;
+                if (activateVoiceSearch) {
+                    Tab appTab = mTabControl.getTabFromId(appId);
+                    if (appTab != null) {
+                        mController.reuseTab(appTab, appId, urlData);
+                        return;
+                    } else {
+                        mController.openTabAndShow(null, urlData, false, appId);
+                    }
                 } else {
                     // No matching application tab, try to find a regular tab
                     // with a matching url.
-                    appTab = mTabControl.findUnusedTabWithUrl(urlData.mUrl);
+                    Tab appTab = mTabControl.findUnusedTabWithUrl(urlData.mUrl);
                     if (appTab != null) {
                         if (current != appTab) {
                             mController.switchToTab(mTabControl.getTabIndex(appTab));
@@ -164,7 +168,7 @@
                         // MAX_TABS. Then the url will be opened in the current
                         // tab. If a new tab is created, it will have "true" for
                         // exit on close.
-                        mController.openTabAndShow(null, urlData, true, appId);
+                        mController.openTabAndShow(null, urlData, false, appId);
                     }
                 }
             } else {
diff --git a/src/com/android/browser/TitleBarXLarge.java b/src/com/android/browser/TitleBarXLarge.java
index 9fce511..be5e90f 100644
--- a/src/com/android/browser/TitleBarXLarge.java
+++ b/src/com/android/browser/TitleBarXLarge.java
@@ -20,28 +20,32 @@
 import com.android.browser.autocomplete.SuggestedTextController.TextChangeWatcher;
 import com.android.browser.search.SearchEngine;
 
+import android.accounts.Account;
 import android.app.Activity;
 import android.content.Context;
 import android.content.res.Resources;
 import android.graphics.Bitmap;
 import android.graphics.drawable.Drawable;
 import android.text.TextUtils;
-import android.view.animation.Animation;
-import android.view.animation.Animation.AnimationListener;
-import android.view.animation.AnimationUtils;
+import android.view.ContextThemeWrapper;
 import android.view.KeyEvent;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.view.View.OnFocusChangeListener;
 import android.view.ViewGroup;
+import android.view.animation.Animation;
+import android.view.animation.Animation.AnimationListener;
+import android.view.animation.AnimationUtils;
 import android.webkit.WebView;
 import android.widget.AbsoluteLayout;
+import android.widget.ArrayAdapter;
 import android.widget.Button;
 import android.widget.FrameLayout;
 import android.widget.ImageButton;
 import android.widget.ImageView;
 import android.widget.ProgressBar;
+import android.widget.Spinner;
 import android.widget.TextView;
 
 import java.util.List;
@@ -75,12 +79,13 @@
     private Drawable mUnfocusDrawable;
     // Auto-login UI
     private View mAutoLogin;
-    private Button mAutoLoginAccount;
+    private Spinner mAutoLoginAccount;
     private Button mAutoLoginLogin;
     private ProgressBar mAutoLoginProgress;
     private TextView mAutoLoginError;
     private ImageButton mAutoLoginCancel;
     private DeviceAccountLogin mAutoLoginHandler;
+    private ArrayAdapter<String> mAccountsAdapter;
 
     private boolean mInLoad;
     private boolean mUseQuickControls;
@@ -149,8 +154,7 @@
         mUrlInput.setSelectAllOnFocus(true);
         mUrlInput.addQueryTextWatcher(this);
         mAutoLogin = findViewById(R.id.autologin);
-        mAutoLoginAccount = (Button) findViewById(R.id.autologin_account);
-        mAutoLoginAccount.setOnClickListener(this);
+        mAutoLoginAccount = (Spinner) findViewById(R.id.autologin_account);
         mAutoLoginLogin = (Button) findViewById(R.id.autologin_login);
         mAutoLoginLogin.setOnClickListener(this);
         mAutoLoginProgress =
@@ -180,7 +184,14 @@
         if (login != null) {
             mAutoLoginHandler = login;
             mAutoLogin.setVisibility(View.VISIBLE);
-            mAutoLoginAccount.setText(login.getCurrentAccount());
+            ContextThemeWrapper wrapper = new ContextThemeWrapper(mContext,
+                    android.R.style.Theme_Holo_Light);
+            mAccountsAdapter = new ArrayAdapter<String>(wrapper,
+                    android.R.layout.simple_spinner_item, login.getAccountNames());
+            mAccountsAdapter.setDropDownViewResource(
+                    android.R.layout.simple_spinner_dropdown_item);
+            mAutoLoginAccount.setAdapter(mAccountsAdapter);
+            mAutoLoginAccount.setSelection(0);
             mAutoLoginAccount.setEnabled(true);
             mAutoLoginLogin.setEnabled(true);
             mAutoLoginProgress.setVisibility(View.GONE);
@@ -360,21 +371,13 @@
                 mAutoLoginLogin.setEnabled(false);
                 mAutoLoginProgress.setVisibility(View.VISIBLE);
                 mAutoLoginError.setVisibility(View.GONE);
-                mAutoLoginHandler.login(this);
-            }
-        } else if (mAutoLoginAccount == v) {
-            if (mAutoLoginHandler != null) {
-                mAutoLoginHandler.chooseAccount(this);
+                mAutoLoginHandler.login(
+                        mAutoLoginAccount.getSelectedItemPosition(), this);
             }
         }
     }
 
     @Override
-    public void setAccount(String account) {
-        mAutoLoginAccount.setText(account);
-    }
-
-    @Override
     public void loginFailed() {
         mAutoLoginAccount.setEnabled(true);
         mAutoLoginLogin.setEnabled(true);