[WifiSettings] Submit Wi-Fi dialog with enter key

Add a OnKeyListener for hardware keyboards and an
OnEditorActionListener for on-screen IMEs to submit the Wi-Fi dialog
with the currently entered information.

Before committing the action, check for whether the dialog is
submittable -- that is checking whether all necessary information has
been entered. If not the enter key behaves the same as it is before
the change.

Bug: 22211604
Change-Id: Idede4233a7385d3bcd8fd6614948270280536bf1
This commit is contained in:
Maurice Lam
2015-08-27 16:06:55 -07:00
parent e3be8eb3e5
commit 2662df8433
5 changed files with 95 additions and 40 deletions

View File

@@ -42,8 +42,10 @@ import android.text.InputType;
import android.text.TextWatcher;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
@@ -68,7 +70,8 @@ import java.util.Iterator;
* share the logic for controlling buttons, text fields, etc.
*/
public class WifiConfigController implements TextWatcher,
AdapterView.OnItemSelectedListener, OnCheckedChangeListener {
AdapterView.OnItemSelectedListener, OnCheckedChangeListener,
TextView.OnEditorActionListener, View.OnKeyListener{
private static final String TAG = "WifiConfigController";
private final WifiConfigUiBase mConfigUi;
@@ -344,32 +347,32 @@ public class WifiConfigController implements TextWatcher,
Button submit = mConfigUi.getSubmitButton();
if (submit == null) return;
submit.setEnabled(isSubmittable());
}
boolean isSubmittable() {
boolean enabled = false;
boolean passwordInvalid = false;
if (mPasswordView != null &&
((mAccessPointSecurity == AccessPoint.SECURITY_WEP && mPasswordView.length() == 0) ||
(mAccessPointSecurity == AccessPoint.SECURITY_PSK && mPasswordView.length() < 8))) {
((mAccessPointSecurity == AccessPoint.SECURITY_WEP && mPasswordView.length() == 0) ||
(mAccessPointSecurity == AccessPoint.SECURITY_PSK && mPasswordView.length() < 8))) {
passwordInvalid = true;
}
if ((mSsidView != null && mSsidView.length() == 0) ||
((mAccessPoint == null || !mAccessPoint.isSaved()) &&
passwordInvalid)) {
((mAccessPoint == null || !mAccessPoint.isSaved()) &&
passwordInvalid)) {
enabled = false;
} else {
if (ipAndProxyFieldsAreValid()) {
enabled = true;
} else {
enabled = false;
}
enabled = ipAndProxyFieldsAreValid();
}
if (mEapCaCertSpinner != null &&
mView.findViewById(R.id.l_ca_cert).getVisibility() != View.GONE &&
((String)mEapCaCertSpinner.getSelectedItem()).equals(unspecifiedCert)) {
enabled = false;
}
submit.setEnabled(enabled);
return enabled;
}
/* package */ WifiConfiguration getConfig() {
@@ -632,6 +635,8 @@ public class WifiConfigController implements TextWatcher,
if (mPasswordView == null) {
mPasswordView = (TextView) mView.findViewById(R.id.password);
mPasswordView.addTextChangedListener(this);
mPasswordView.setOnEditorActionListener(this);
mPasswordView.setOnKeyListener(this);
((CheckBox) mView.findViewById(R.id.show_password))
.setOnCheckedChangeListener(this);
@@ -988,6 +993,28 @@ public class WifiConfigController implements TextWatcher,
// work done in afterTextChanged
}
@Override
public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
if (textView == mPasswordView) {
if (id == EditorInfo.IME_ACTION_DONE && isSubmittable()) {
mConfigUi.dispatchSubmit();
return true;
}
}
return false;
}
@Override
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
if (view == mPasswordView) {
if (keyCode == KeyEvent.KEYCODE_ENTER && isSubmittable()) {
mConfigUi.dispatchSubmit();
return true;
}
}
return false;
}
@Override
public void onCheckedChanged(CompoundButton view, boolean isChecked) {
if (view.getId() == R.id.show_password) {