Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a9534367 authored by Jake Hamby's avatar Jake Hamby
Browse files

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
parent 4f85e856
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:maxLength="50"
        android:singleLine="true"
    />
        
</LinearLayout>
+25 −5
Original line number Diff line number Diff line
@@ -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);
                                }
                                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;
    }