[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:
@@ -18,7 +18,6 @@ package com.android.settings.wifi;
|
|||||||
|
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -45,7 +44,7 @@ import java.util.List;
|
|||||||
* UI to manage saved networks/access points.
|
* UI to manage saved networks/access points.
|
||||||
*/
|
*/
|
||||||
public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
|
public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
|
||||||
implements DialogInterface.OnClickListener, Indexable {
|
implements Indexable, WifiDialog.WifiDialogListener {
|
||||||
private static final String TAG = "SavedAccessPointsWifiSettings";
|
private static final String TAG = "SavedAccessPointsWifiSettings";
|
||||||
|
|
||||||
private WifiDialog mDialog;
|
private WifiDialog mDialog;
|
||||||
@@ -170,14 +169,19 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialogInterface, int button) {
|
public void onForget(WifiDialog dialog) {
|
||||||
if (button == WifiDialog.BUTTON_FORGET && mSelectedAccessPoint != null) {
|
if (mSelectedAccessPoint != null) {
|
||||||
mWifiManager.forget(mSelectedAccessPoint.getConfig().networkId, null);
|
mWifiManager.forget(mSelectedAccessPoint.getConfig().networkId, null);
|
||||||
getPreferenceScreen().removePreference((Preference) mSelectedAccessPoint.getTag());
|
getPreferenceScreen().removePreference((Preference) mSelectedAccessPoint.getTag());
|
||||||
mSelectedAccessPoint = null;
|
mSelectedAccessPoint = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSubmit(WifiDialog dialog) {
|
||||||
|
// Ignored
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
|
public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
|
||||||
if (preference instanceof AccessPointPreference) {
|
if (preference instanceof AccessPointPreference) {
|
||||||
|
@@ -42,8 +42,10 @@ import android.text.InputType;
|
|||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.inputmethod.EditorInfo;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
@@ -68,7 +70,8 @@ import java.util.Iterator;
|
|||||||
* share the logic for controlling buttons, text fields, etc.
|
* share the logic for controlling buttons, text fields, etc.
|
||||||
*/
|
*/
|
||||||
public class WifiConfigController implements TextWatcher,
|
public class WifiConfigController implements TextWatcher,
|
||||||
AdapterView.OnItemSelectedListener, OnCheckedChangeListener {
|
AdapterView.OnItemSelectedListener, OnCheckedChangeListener,
|
||||||
|
TextView.OnEditorActionListener, View.OnKeyListener{
|
||||||
private static final String TAG = "WifiConfigController";
|
private static final String TAG = "WifiConfigController";
|
||||||
|
|
||||||
private final WifiConfigUiBase mConfigUi;
|
private final WifiConfigUiBase mConfigUi;
|
||||||
@@ -344,32 +347,32 @@ public class WifiConfigController implements TextWatcher,
|
|||||||
Button submit = mConfigUi.getSubmitButton();
|
Button submit = mConfigUi.getSubmitButton();
|
||||||
if (submit == null) return;
|
if (submit == null) return;
|
||||||
|
|
||||||
|
submit.setEnabled(isSubmittable());
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isSubmittable() {
|
||||||
boolean enabled = false;
|
boolean enabled = false;
|
||||||
boolean passwordInvalid = false;
|
boolean passwordInvalid = false;
|
||||||
|
|
||||||
if (mPasswordView != null &&
|
if (mPasswordView != null &&
|
||||||
((mAccessPointSecurity == AccessPoint.SECURITY_WEP && mPasswordView.length() == 0) ||
|
((mAccessPointSecurity == AccessPoint.SECURITY_WEP && mPasswordView.length() == 0) ||
|
||||||
(mAccessPointSecurity == AccessPoint.SECURITY_PSK && mPasswordView.length() < 8))) {
|
(mAccessPointSecurity == AccessPoint.SECURITY_PSK && mPasswordView.length() < 8))) {
|
||||||
passwordInvalid = true;
|
passwordInvalid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((mSsidView != null && mSsidView.length() == 0) ||
|
if ((mSsidView != null && mSsidView.length() == 0) ||
|
||||||
((mAccessPoint == null || !mAccessPoint.isSaved()) &&
|
((mAccessPoint == null || !mAccessPoint.isSaved()) &&
|
||||||
passwordInvalid)) {
|
passwordInvalid)) {
|
||||||
enabled = false;
|
enabled = false;
|
||||||
} else {
|
} else {
|
||||||
if (ipAndProxyFieldsAreValid()) {
|
enabled = ipAndProxyFieldsAreValid();
|
||||||
enabled = true;
|
|
||||||
} else {
|
|
||||||
enabled = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (mEapCaCertSpinner != null &&
|
if (mEapCaCertSpinner != null &&
|
||||||
mView.findViewById(R.id.l_ca_cert).getVisibility() != View.GONE &&
|
mView.findViewById(R.id.l_ca_cert).getVisibility() != View.GONE &&
|
||||||
((String)mEapCaCertSpinner.getSelectedItem()).equals(unspecifiedCert)) {
|
((String)mEapCaCertSpinner.getSelectedItem()).equals(unspecifiedCert)) {
|
||||||
enabled = false;
|
enabled = false;
|
||||||
}
|
}
|
||||||
submit.setEnabled(enabled);
|
return enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* package */ WifiConfiguration getConfig() {
|
/* package */ WifiConfiguration getConfig() {
|
||||||
@@ -632,6 +635,8 @@ public class WifiConfigController implements TextWatcher,
|
|||||||
if (mPasswordView == null) {
|
if (mPasswordView == null) {
|
||||||
mPasswordView = (TextView) mView.findViewById(R.id.password);
|
mPasswordView = (TextView) mView.findViewById(R.id.password);
|
||||||
mPasswordView.addTextChangedListener(this);
|
mPasswordView.addTextChangedListener(this);
|
||||||
|
mPasswordView.setOnEditorActionListener(this);
|
||||||
|
mPasswordView.setOnKeyListener(this);
|
||||||
((CheckBox) mView.findViewById(R.id.show_password))
|
((CheckBox) mView.findViewById(R.id.show_password))
|
||||||
.setOnCheckedChangeListener(this);
|
.setOnCheckedChangeListener(this);
|
||||||
|
|
||||||
@@ -988,6 +993,28 @@ public class WifiConfigController implements TextWatcher,
|
|||||||
// work done in afterTextChanged
|
// 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
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton view, boolean isChecked) {
|
public void onCheckedChanged(CompoundButton view, boolean isChecked) {
|
||||||
if (view.getId() == R.id.show_password) {
|
if (view.getId() == R.id.show_password) {
|
||||||
|
@@ -29,6 +29,8 @@ public interface WifiConfigUiBase {
|
|||||||
public LayoutInflater getLayoutInflater();
|
public LayoutInflater getLayoutInflater();
|
||||||
public boolean isEdit();
|
public boolean isEdit();
|
||||||
|
|
||||||
|
public void dispatchSubmit();
|
||||||
|
|
||||||
public void setTitle(int id);
|
public void setTitle(int id);
|
||||||
public void setTitle(CharSequence title);
|
public void setTitle(CharSequence title);
|
||||||
|
|
||||||
|
@@ -26,13 +26,19 @@ import android.os.Bundle;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
|
||||||
class WifiDialog extends AlertDialog implements WifiConfigUiBase {
|
class WifiDialog extends AlertDialog implements WifiConfigUiBase, DialogInterface.OnClickListener {
|
||||||
static final int BUTTON_SUBMIT = DialogInterface.BUTTON_POSITIVE;
|
|
||||||
static final int BUTTON_FORGET = DialogInterface.BUTTON_NEUTRAL;
|
public interface WifiDialogListener {
|
||||||
|
void onForget(WifiDialog dialog);
|
||||||
|
void onSubmit(WifiDialog dialog);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final int BUTTON_SUBMIT = DialogInterface.BUTTON_POSITIVE;
|
||||||
|
private static final int BUTTON_FORGET = DialogInterface.BUTTON_NEUTRAL;
|
||||||
|
|
||||||
private final boolean mEdit;
|
private final boolean mEdit;
|
||||||
private final boolean mModify;
|
private final boolean mModify;
|
||||||
private final DialogInterface.OnClickListener mListener;
|
private final WifiDialogListener mListener;
|
||||||
private final AccessPoint mAccessPoint;
|
private final AccessPoint mAccessPoint;
|
||||||
|
|
||||||
private View mView;
|
private View mView;
|
||||||
@@ -40,7 +46,7 @@ class WifiDialog extends AlertDialog implements WifiConfigUiBase {
|
|||||||
private boolean mHideSubmitButton;
|
private boolean mHideSubmitButton;
|
||||||
private boolean mHideForgetButton;
|
private boolean mHideForgetButton;
|
||||||
|
|
||||||
public WifiDialog(Context context, DialogInterface.OnClickListener listener,
|
public WifiDialog(Context context, WifiDialogListener listener,
|
||||||
AccessPoint accessPoint, boolean edit, boolean modify,
|
AccessPoint accessPoint, boolean edit, boolean modify,
|
||||||
boolean hideSubmitButton, boolean hideForgetButton) {
|
boolean hideSubmitButton, boolean hideForgetButton) {
|
||||||
this(context, listener, accessPoint, edit, modify);
|
this(context, listener, accessPoint, edit, modify);
|
||||||
@@ -48,7 +54,7 @@ class WifiDialog extends AlertDialog implements WifiConfigUiBase {
|
|||||||
mHideForgetButton = hideForgetButton;
|
mHideForgetButton = hideForgetButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WifiDialog(Context context, DialogInterface.OnClickListener listener,
|
public WifiDialog(Context context, WifiDialogListener listener,
|
||||||
AccessPoint accessPoint, boolean edit, boolean modify) {
|
AccessPoint accessPoint, boolean edit, boolean modify) {
|
||||||
super(context);
|
super(context);
|
||||||
mEdit = edit;
|
mEdit = edit;
|
||||||
@@ -90,6 +96,28 @@ class WifiDialog extends AlertDialog implements WifiConfigUiBase {
|
|||||||
mController.updatePassword();
|
mController.updatePassword();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispatchSubmit() {
|
||||||
|
if (mListener != null) {
|
||||||
|
mListener.onSubmit(this);
|
||||||
|
}
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialogInterface, int id) {
|
||||||
|
if (mListener != null) {
|
||||||
|
switch (id) {
|
||||||
|
case BUTTON_SUBMIT:
|
||||||
|
mListener.onSubmit(this);
|
||||||
|
break;
|
||||||
|
case BUTTON_FORGET:
|
||||||
|
mListener.onForget(this);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEdit() {
|
public boolean isEdit() {
|
||||||
return mEdit;
|
return mEdit;
|
||||||
@@ -112,16 +140,16 @@ class WifiDialog extends AlertDialog implements WifiConfigUiBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSubmitButton(CharSequence text) {
|
public void setSubmitButton(CharSequence text) {
|
||||||
setButton(BUTTON_SUBMIT, text, mListener);
|
setButton(BUTTON_SUBMIT, text, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setForgetButton(CharSequence text) {
|
public void setForgetButton(CharSequence text) {
|
||||||
setButton(BUTTON_FORGET, text, mListener);
|
setButton(BUTTON_FORGET, text, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCancelButton(CharSequence text) {
|
public void setCancelButton(CharSequence text) {
|
||||||
setButton(BUTTON_NEGATIVE, text, mListener);
|
setButton(BUTTON_NEGATIVE, text, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,19 +16,15 @@
|
|||||||
|
|
||||||
package com.android.settings.wifi;
|
package com.android.settings.wifi;
|
||||||
|
|
||||||
import static android.net.wifi.WifiConfiguration.INVALID_NETWORK_ID;
|
|
||||||
import static android.os.UserManager.DISALLOW_CONFIG_WIFI;
|
import static android.os.UserManager.DISALLOW_CONFIG_WIFI;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.AppGlobals;
|
import android.app.AppGlobals;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.app.admin.DeviceAdminInfo;
|
|
||||||
import android.app.admin.DevicePolicyManager;
|
import android.app.admin.DevicePolicyManager;
|
||||||
import android.app.admin.DevicePolicyManagerInternal;
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.IPackageManager;
|
import android.content.pm.IPackageManager;
|
||||||
@@ -48,7 +44,6 @@ import android.os.HandlerThread;
|
|||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceScreen;
|
import android.preference.PreferenceScreen;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
@@ -69,7 +64,6 @@ import android.widget.TextView.BufferType;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.android.internal.logging.MetricsLogger;
|
import com.android.internal.logging.MetricsLogger;
|
||||||
import com.android.server.LocalServices;
|
|
||||||
import com.android.settings.LinkifyUtils;
|
import com.android.settings.LinkifyUtils;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.RestrictedSettingsFragment;
|
import com.android.settings.RestrictedSettingsFragment;
|
||||||
@@ -96,8 +90,8 @@ import java.util.List;
|
|||||||
* and menus.
|
* and menus.
|
||||||
*/
|
*/
|
||||||
public class WifiSettings extends RestrictedSettingsFragment
|
public class WifiSettings extends RestrictedSettingsFragment
|
||||||
implements DialogInterface.OnClickListener, Indexable, WifiTracker.WifiListener,
|
implements Indexable, WifiTracker.WifiListener, AccessPointListener,
|
||||||
AccessPointListener {
|
WifiDialog.WifiDialogListener {
|
||||||
|
|
||||||
private static final String TAG = "WifiSettings";
|
private static final String TAG = "WifiSettings";
|
||||||
|
|
||||||
@@ -816,13 +810,14 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialogInterface, int button) {
|
public void onForget(WifiDialog dialog) {
|
||||||
if (button == WifiDialog.BUTTON_FORGET && mSelectedAccessPoint != null) {
|
forget();
|
||||||
forget();
|
}
|
||||||
} else if (button == WifiDialog.BUTTON_SUBMIT) {
|
|
||||||
if (mDialog != null) {
|
@Override
|
||||||
submit(mDialog.getController());
|
public void onSubmit(WifiDialog dialog) {
|
||||||
}
|
if (mDialog != null) {
|
||||||
|
submit(mDialog.getController());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1020,5 +1015,4 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
Settings.Global.WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN, 0) != 0;
|
Settings.Global.WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN, 0) != 0;
|
||||||
return !isLockdownFeatureEnabled;
|
return !isLockdownFeatureEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user