diff --git a/mobile/android/base/PromptService.java b/mobile/android/base/PromptService.java index 885848ffa345..3d03aa0960a0 100644 --- a/mobile/android/base/PromptService.java +++ b/mobile/android/base/PromptService.java @@ -23,6 +23,7 @@ import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.text.InputType; import android.util.Log; +import android.view.inputmethod.InputMethodManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -94,6 +95,7 @@ public class PromptService implements OnClickListener, OnCancelListener, OnItemC private String label = ""; private String type = ""; private String hint = ""; + private Boolean autofocus = false; private String value = ""; private JSONObject mJSONInput = null; private View view = null; @@ -112,6 +114,9 @@ public class PromptService implements OnClickListener, OnCancelListener, OnItemC try { value = aJSONInput.getString("value"); } catch(Exception ex) { } + try { + autofocus = aJSONInput.getBoolean("autofocus"); + } catch(Exception ex) { } } public View getView() throws UnsupportedOperationException { @@ -187,6 +192,18 @@ public class PromptService implements OnClickListener, OnCancelListener, OnItemC if (!hint.equals("")) { input.setHint(hint); } + + if (autofocus) { + input.setOnFocusChangeListener(new View.OnFocusChangeListener() { + public void onFocusChange(View v, boolean hasFocus) { + if (hasFocus) { + ((InputMethodManager) GeckoApp.mAppContext.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(v, 0); + } + } + }); + input.requestFocus(); + } + view = (View)input; } else if (type.equals("menulist")) { Spinner spinner = new Spinner(GeckoApp.mAppContext); diff --git a/mobile/android/components/PromptService.js b/mobile/android/components/PromptService.js index 8b4ef6f8a485..401a4f8c5cce 100644 --- a/mobile/android/components/PromptService.js +++ b/mobile/android/components/PromptService.js @@ -248,7 +248,7 @@ Prompt.prototype = { }, nsIPrompt_prompt: function nsIPrompt_prompt(aTitle, aText, aValue, aCheckMsg, aCheckState) { - let inputs = [{ type: "textbox", value: aValue.value }]; + let inputs = [{ type: "textbox", value: aValue.value, autofocus: true }]; let data = this.commonPrompt(aTitle, aText, null, aCheckMsg, aCheckState, inputs); let ok = data.button == 0; @@ -261,7 +261,7 @@ Prompt.prototype = { nsIPrompt_promptPassword: function nsIPrompt_promptPassword( aTitle, aText, aPassword, aCheckMsg, aCheckState) { - let inputs = [{ type: "password", hint: PromptUtils.getLocaleString("password", "passwdmgr"), value: aPassword.value || "" }]; + let inputs = [{ type: "password", hint: PromptUtils.getLocaleString("password", "passwdmgr"), value: aPassword.value || "", autofocus: true }]; let data = this.commonPrompt(aTitle, aText, null, aCheckMsg, aCheckState, inputs); let ok = data.button == 0; @@ -274,7 +274,7 @@ Prompt.prototype = { nsIPrompt_promptUsernameAndPassword: function nsIPrompt_promptUsernameAndPassword( aTitle, aText, aUsername, aPassword, aCheckMsg, aCheckState) { - let inputs = [{ type: "textbox", hint: PromptUtils.getLocaleString("username", "passwdmgr"), value: aUsername.value }, + let inputs = [{ type: "textbox", hint: PromptUtils.getLocaleString("username", "passwdmgr"), value: aUsername.value, autofocus: true }, { type: "password", hint: PromptUtils.getLocaleString("password", "passwdmgr"), value: aPassword.value }]; let data = this.commonPrompt(aTitle, aText, null, aCheckMsg, aCheckState, inputs);