[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

@@ -26,13 +26,19 @@ import android.os.Bundle;
import android.view.View;
import android.widget.Button;
class WifiDialog extends AlertDialog implements WifiConfigUiBase {
static final int BUTTON_SUBMIT = DialogInterface.BUTTON_POSITIVE;
static final int BUTTON_FORGET = DialogInterface.BUTTON_NEUTRAL;
class WifiDialog extends AlertDialog implements WifiConfigUiBase, DialogInterface.OnClickListener {
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 mModify;
private final DialogInterface.OnClickListener mListener;
private final WifiDialogListener mListener;
private final AccessPoint mAccessPoint;
private View mView;
@@ -40,7 +46,7 @@ class WifiDialog extends AlertDialog implements WifiConfigUiBase {
private boolean mHideSubmitButton;
private boolean mHideForgetButton;
public WifiDialog(Context context, DialogInterface.OnClickListener listener,
public WifiDialog(Context context, WifiDialogListener listener,
AccessPoint accessPoint, boolean edit, boolean modify,
boolean hideSubmitButton, boolean hideForgetButton) {
this(context, listener, accessPoint, edit, modify);
@@ -48,7 +54,7 @@ class WifiDialog extends AlertDialog implements WifiConfigUiBase {
mHideForgetButton = hideForgetButton;
}
public WifiDialog(Context context, DialogInterface.OnClickListener listener,
public WifiDialog(Context context, WifiDialogListener listener,
AccessPoint accessPoint, boolean edit, boolean modify) {
super(context);
mEdit = edit;
@@ -90,6 +96,28 @@ class WifiDialog extends AlertDialog implements WifiConfigUiBase {
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
public boolean isEdit() {
return mEdit;
@@ -112,16 +140,16 @@ class WifiDialog extends AlertDialog implements WifiConfigUiBase {
@Override
public void setSubmitButton(CharSequence text) {
setButton(BUTTON_SUBMIT, text, mListener);
setButton(BUTTON_SUBMIT, text, this);
}
@Override
public void setForgetButton(CharSequence text) {
setButton(BUTTON_FORGET, text, mListener);
setButton(BUTTON_FORGET, text, this);
}
@Override
public void setCancelButton(CharSequence text) {
setButton(BUTTON_NEGATIVE, text, mListener);
setButton(BUTTON_NEGATIVE, text, this);
}
}