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
This commit is contained in:
Jake Hamby
2012-03-13 19:15:20 -07:00
parent 4f85e85666
commit a9534367b5
2 changed files with 26 additions and 5 deletions

View File

@@ -25,6 +25,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:maxLength="50" android:maxLength="50"
android:singleLine="true"
/> />
</LinearLayout> </LinearLayout>

View File

@@ -30,10 +30,14 @@ import android.text.Editable;
import android.text.InputFilter; import android.text.InputFilter;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView;
import com.android.settings.R; import com.android.settings.R;
@@ -94,19 +98,23 @@ public final class BluetoothNameDialogFragment extends DialogFragment implements
.setPositiveButton(R.string.bluetooth_rename_button, .setPositiveButton(R.string.bluetooth_rename_button,
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if (mLocalAdapter != null) { String deviceName = mDeviceNameView.getText().toString();
String deviceName = mDeviceNameView.getText().toString(); setDeviceName(deviceName);
Log.d(TAG, "Setting device name to " + deviceName);
mLocalAdapter.setName(deviceName);
}
} }
}) })
.setNegativeButton(android.R.string.cancel, null) .setNegativeButton(android.R.string.cancel, null)
.create(); .create();
mAlertDialog.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
return mAlertDialog; return mAlertDialog;
} }
private void setDeviceName(String deviceName) {
Log.d(TAG, "Setting device name to " + deviceName);
mLocalAdapter.setName(deviceName);
}
@Override @Override
public void onSaveInstanceState(Bundle outState) { public void onSaveInstanceState(Bundle outState) {
outState.putString(KEY_NAME, mDeviceNameView.getText().toString()); 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.setText(deviceName); // set initial value before adding listener
mDeviceNameView.addTextChangedListener(this); 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; return view;
} }