diff options
author | Amith Yamasani <yamasani@google.com> | 2009-09-15 10:25:51 -0700 |
---|---|---|
committer | Amith Yamasani <yamasani@google.com> | 2009-09-16 10:51:56 -0700 |
commit | 1d458570757e607f0dc11fb0e963017916ac0701 (patch) | |
tree | d2d6aa318713b415554ba3ae7652d5640ee461a2 /core/java/android/preference | |
parent | db6d939d2bbf457b1caa5479a60dae5e90d023e1 (diff) | |
download | frameworks_base-1d458570757e607f0dc11fb0e963017916ac0701.zip frameworks_base-1d458570757e607f0dc11fb0e963017916ac0701.tar.gz frameworks_base-1d458570757e607f0dc11fb0e963017916ac0701.tar.bz2 |
Show keyboard automatically in EditTextPreference dialogs
Diffstat (limited to 'core/java/android/preference')
-rw-r--r-- | core/java/android/preference/DialogPreference.java | 27 | ||||
-rw-r--r-- | core/java/android/preference/EditTextPreference.java | 7 |
2 files changed, 33 insertions, 1 deletions
diff --git a/core/java/android/preference/DialogPreference.java b/core/java/android/preference/DialogPreference.java index 666efae..cc48aeb 100644 --- a/core/java/android/preference/DialogPreference.java +++ b/core/java/android/preference/DialogPreference.java @@ -31,6 +31,9 @@ import android.text.TextUtils; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; +import android.view.Window; +import android.view.WindowManager; +import android.view.inputmethod.InputMethodManager; import android.widget.TextView; /** @@ -297,10 +300,32 @@ public abstract class DialogPreference extends Preference implements if (state != null) { dialog.onRestoreInstanceState(state); } + if (needInputMethod()) { + requestInputMethod(dialog); + } dialog.setOnDismissListener(this); dialog.show(); } - + + /** + * Returns whether the preference needs to display a soft input method when the dialog + * is displayed. Default is false. Subclasses should override this method if they need + * the soft input method brought up automatically. + * @hide + */ + protected boolean needInputMethod() { + return false; + } + + /** + * Sets the required flags on the dialog window to enable input method window to show up. + */ + private void requestInputMethod(Dialog dialog) { + Window window = dialog.getWindow(); + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE | + WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); + } + /** * Creates the content view for the dialog (if a custom content view is * required). By default, it inflates the dialog layout resource if it is diff --git a/core/java/android/preference/EditTextPreference.java b/core/java/android/preference/EditTextPreference.java index a12704f..84ee950 100644 --- a/core/java/android/preference/EditTextPreference.java +++ b/core/java/android/preference/EditTextPreference.java @@ -169,6 +169,13 @@ public class EditTextPreference extends DialogPreference { return mEditText; } + /** @hide */ + @Override + protected boolean needInputMethod() { + // We want the input method to show, if possible, when dialog is displayed + return true; + } + @Override protected Parcelable onSaveInstanceState() { final Parcelable superState = super.onSaveInstanceState(); |