Make only the "Add Network" WifiDialog fullscreen.

Fixes an issue where other instances of WifiDialog were being launched
fullscreen. Creates static methods for creating fullscreen and modal
WifiDialogs to make the style more explicit.

Bug: 63889135
Test: make -j40 RunSettingsRoboTests
Change-Id: I2200b5d7f817b9f69a6abb73bf2c04ea24556d19
This commit is contained in:
Eric Schwarzenbach
2017-07-21 15:48:58 -07:00
parent bd429f42cb
commit bc1cf7e260
5 changed files with 101 additions and 24 deletions

View File

@@ -174,10 +174,9 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
} }
mSelectedAccessPoint = mDlgAccessPoint; mSelectedAccessPoint = mDlgAccessPoint;
mDialog = new WifiDialog(getActivity(), this, mDlgAccessPoint, mDialog = WifiDialog.createModal(getActivity(), this, mDlgAccessPoint,
WifiConfigUiBase.MODE_VIEW, true /* hide the submit button */); WifiConfigUiBase.MODE_VIEW);
return mDialog; return mDialog;
} }
return super.onCreateDialog(dialogId); return super.onCreateDialog(dialogId);
} }

View File

@@ -27,6 +27,7 @@ import com.android.settings.R;
import com.android.settingslib.RestrictedLockUtils; import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.wifi.AccessPoint; import com.android.settingslib.wifi.AccessPoint;
// TODO(b/64069122) Have this extend a dialogfragment to handle the fullscreen launch case.
class WifiDialog extends AlertDialog implements WifiConfigUiBase, DialogInterface.OnClickListener { class WifiDialog extends AlertDialog implements WifiConfigUiBase, DialogInterface.OnClickListener {
public interface WifiDialogListener { public interface WifiDialogListener {
@@ -45,21 +46,31 @@ class WifiDialog extends AlertDialog implements WifiConfigUiBase, DialogInterfac
private WifiConfigController mController; private WifiConfigController mController;
private boolean mHideSubmitButton; private boolean mHideSubmitButton;
public WifiDialog(Context context, WifiDialogListener listener, AccessPoint accessPoint,
int mode, boolean hideSubmitButton) { /** Creates a WifiDialog with fullscreen style. It displays in fullscreen mode. */
this(context, listener, accessPoint, mode); public static WifiDialog createFullscreen(Context context, WifiDialogListener listener,
mHideSubmitButton = hideSubmitButton; AccessPoint accessPoint, int mode) {
return new WifiDialog(context, listener, accessPoint, mode,
R.style.Theme_Settings_NoActionBar, false /* hideSubmitButton */);
} }
public WifiDialog(Context context, WifiDialogListener listener, AccessPoint accessPoint, /**
int mode) { * Creates a WifiDialog with no additional style. It displays as a dialog above the current
// conditionally sets the theme to fullscreen dialog for "Add Network" * view.
super(context, */
mode == WifiConfigUiBase.MODE_CONNECT ? R.style.Theme_Settings_NoActionBar : 0); public static WifiDialog createModal(Context context, WifiDialogListener listener,
AccessPoint accessPoint, int mode) {
return new WifiDialog(context, listener, accessPoint, mode, 0 /* style */,
mode == WifiConfigUiBase.MODE_VIEW /* hideSubmitButton*/);
}
/* package */ WifiDialog(Context context, WifiDialogListener listener, AccessPoint accessPoint,
int mode, int style, boolean hideSubmitButton) {
super(context, style);
mMode = mode; mMode = mode;
mListener = listener; mListener = listener;
mAccessPoint = accessPoint; mAccessPoint = accessPoint;
mHideSubmitButton = false; mHideSubmitButton = hideSubmitButton;
} }
@Override @Override

View File

@@ -55,7 +55,7 @@ public class WifiDialogActivity extends Activity implements WifiDialog.WifiDialo
accessPoint = new AccessPoint(this, accessPointState); accessPoint = new AccessPoint(this, accessPointState);
} }
WifiDialog dialog = new WifiDialog(this, this, accessPoint, WifiConfigUiBase.MODE_CONNECT); WifiDialog dialog = WifiDialog.createModal(this, this, accessPoint, WifiConfigUiBase.MODE_CONNECT);
dialog.show(); dialog.show();
dialog.setOnDismissListener(this); dialog.setOnDismissListener(this);
} }

View File

@@ -626,20 +626,23 @@ public class WifiSettings extends RestrictedSettingsFragment
public Dialog onCreateDialog(int dialogId) { public Dialog onCreateDialog(int dialogId) {
switch (dialogId) { switch (dialogId) {
case WIFI_DIALOG_ID: case WIFI_DIALOG_ID:
AccessPoint ap = mDlgAccessPoint; // For manual launch if (mDlgAccessPoint == null && mAccessPointSavedState == null) {
if (ap == null) { // For re-launch from saved state // add new network
if (mAccessPointSavedState != null) { mDialog = WifiDialog
ap = new AccessPoint(getActivity(), mAccessPointSavedState); .createFullscreen(getActivity(), this, mDlgAccessPoint, mDialogMode);
// For repeated orientation changes } else {
mDlgAccessPoint = ap; // modify network
if (mDlgAccessPoint == null) {
// restore AP from save state
mDlgAccessPoint = new AccessPoint(getActivity(), mAccessPointSavedState);
// Reset the saved access point data // Reset the saved access point data
mAccessPointSavedState = null; mAccessPointSavedState = null;
} }
mDialog = WifiDialog
.createModal(getActivity(), this, mDlgAccessPoint, mDialogMode);
} }
// If it's null, fine, it's for Add Network
mSelectedAccessPoint = ap; mSelectedAccessPoint = mDlgAccessPoint;
mDialog = new WifiDialog(getActivity(), this, ap, mDialogMode,
/* no hide submit/connect */ false);
return mDialog; return mDialog;
case WPS_PBC_DIALOG_ID: case WPS_PBC_DIALOG_ID:
return new WpsDialog(getActivity(), WpsInfo.PBC); return new WpsDialog(getActivity(), WpsInfo.PBC);

View File

@@ -0,0 +1,64 @@
package com.android.settings.wifi;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import com.android.settings.R;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
import com.android.settings.wifi.WifiDialog.WifiDialogListener;
import com.android.settingslib.wifi.AccessPoint;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
shadows = ShadowEntityHeaderController.class)
public class WifiDialogTest {
@Mock private AccessPoint mockAccessPoint;
private Context mContext = RuntimeEnvironment.application;
private WifiDialogListener mListener = new WifiDialogListener() {
@Override
public void onForget(WifiDialog dialog) {
}
@Override
public void onSubmit(WifiDialog dialog) {
}
};
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
}
@Test
public void createFullscreen_setsFullscreenTheme() {
WifiDialog fullscreen = WifiDialog.createFullscreen(mContext, mListener, mockAccessPoint,
WifiConfigUiBase.MODE_CONNECT);
assertThat(fullscreen.getContext().getThemeResId())
.isEqualTo(R.style.Theme_Settings_NoActionBar);
}
@Test
public void createModal_usesDefaultTheme() {
WifiDialog modal = WifiDialog
.createModal(mContext, mListener, mockAccessPoint, WifiConfigUiBase.MODE_CONNECT);
WifiDialog wifiDialog = new WifiDialog(mContext, mListener, mockAccessPoint,
WifiConfigUiBase.MODE_CONNECT, 0 /* style */, false /* hideSubmitButton */);
assertThat(modal.getContext().getThemeResId())
.isEqualTo(wifiDialog.getContext().getThemeResId());
}
}