From a9534367b5be907885fe0e2f10375889aeaf635b Mon Sep 17 00:00:00 2001 From: Jake Hamby Date: Tue, 13 Mar 2012 19:15:20 -0700 Subject: [PATCH] Fix IME soft keyboard for Bluetooth rename device dialog. The soft keyboard should automatically pop up when the user selects the Bluetooth rename device menu item. Fixed by calling setSoftInputMode(SOFT_INPUT_STATE_ALWAYS_VISIBLE) on the Window containing the AlertDialog before showing. The device name field should also be a single line field, with the Done button causing the device to be renamed. Set the "singleLine" attribute in the layout XML to true, and added a TextView.OnEditorActionListener to set the device name and dismiss the dialog for EditorInfo.IME_ACTION_DONE. Bug: 5342542 Bug: 5343354 Change-Id: I550d8e9a59395ad66f8a9c11d29c0f2ef278c196 --- res/layout/dialog_edittext.xml | 1 + .../BluetoothNameDialogFragment.java | 30 +++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/res/layout/dialog_edittext.xml b/res/layout/dialog_edittext.xml index 6b849ac5784..80911da7bbc 100644 --- a/res/layout/dialog_edittext.xml +++ b/res/layout/dialog_edittext.xml @@ -25,6 +25,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:maxLength="50" + android:singleLine="true" /> diff --git a/src/com/android/settings/bluetooth/BluetoothNameDialogFragment.java b/src/com/android/settings/bluetooth/BluetoothNameDialogFragment.java index 4996858fe26..b80e42ac03a 100644 --- a/src/com/android/settings/bluetooth/BluetoothNameDialogFragment.java +++ b/src/com/android/settings/bluetooth/BluetoothNameDialogFragment.java @@ -30,10 +30,14 @@ import android.text.Editable; import android.text.InputFilter; import android.text.TextWatcher; import android.util.Log; +import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; +import android.view.WindowManager; +import android.view.inputmethod.EditorInfo; import android.widget.Button; import android.widget.EditText; +import android.widget.TextView; import com.android.settings.R; @@ -94,19 +98,23 @@ public final class BluetoothNameDialogFragment extends DialogFragment implements .setPositiveButton(R.string.bluetooth_rename_button, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { - if (mLocalAdapter != null) { - String deviceName = mDeviceNameView.getText().toString(); - Log.d(TAG, "Setting device name to " + deviceName); - mLocalAdapter.setName(deviceName); - } + String deviceName = mDeviceNameView.getText().toString(); + setDeviceName(deviceName); } }) .setNegativeButton(android.R.string.cancel, null) .create(); + mAlertDialog.getWindow().setSoftInputMode( + WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); return mAlertDialog; } + private void setDeviceName(String deviceName) { + Log.d(TAG, "Setting device name to " + deviceName); + mLocalAdapter.setName(deviceName); + } + @Override public void onSaveInstanceState(Bundle outState) { outState.putString(KEY_NAME, mDeviceNameView.getText().toString()); @@ -123,6 +131,18 @@ public final class BluetoothNameDialogFragment extends DialogFragment implements }); mDeviceNameView.setText(deviceName); // set initial value before adding listener mDeviceNameView.addTextChangedListener(this); + mDeviceNameView.setOnEditorActionListener(new TextView.OnEditorActionListener() { + @Override + public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { + if (actionId == EditorInfo.IME_ACTION_DONE) { + setDeviceName(v.getText().toString()); + mAlertDialog.dismiss(); + return true; // action handled + } else { + return false; // not handled + } + } + }); return view; }