Make sure PIN edit control is focused

When doing Bluetooth pairing and the dialog reqesting a PIN comes up, we
want the PIN field to be focused and the keyboard to be shown. This fixes
a regression from N.

Bug: 62857671
Test: make RunSettingsRoboTests
Change-Id: I00dabfda737b6ac61b50518e11f21e5f9a5a1be1
This commit is contained in:
Antony Sargent
2017-07-12 17:29:10 -07:00
parent c7b3f1f905
commit 4d7df06eb4
3 changed files with 51 additions and 15 deletions

View File

@@ -17,6 +17,7 @@ package com.android.settings.bluetooth;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
@@ -27,10 +28,12 @@ import android.text.InputType;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
@@ -192,7 +195,16 @@ public class BluetoothPairingDialogFragment extends InstrumentedDialogFragment i
mBuilder.setPositiveButton(getString(android.R.string.ok), this);
mBuilder.setNegativeButton(getString(android.R.string.cancel), this);
AlertDialog dialog = mBuilder.create();
dialog.setOnShowListener(d -> mDialog.getButton(Dialog.BUTTON_POSITIVE).setEnabled(false));
dialog.setOnShowListener(d -> {
mDialog.getButton(Dialog.BUTTON_POSITIVE).setEnabled(false);
if (mPairingView != null && mPairingView.requestFocus()) {
InputMethodManager imm = (InputMethodManager)
getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.showSoftInput(mPairingView, InputMethodManager.SHOW_IMPLICIT);
}
}
});
return dialog;
}