Merge "Make only the "Add Network" WifiDialog fullscreen." into oc-mr1-dev
am: 5e888ad7b6
Change-Id: I8e6852561bba50ed44d17f52099ebf82becd5433
This commit is contained in:
@@ -174,10 +174,9 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
|
||||
}
|
||||
mSelectedAccessPoint = mDlgAccessPoint;
|
||||
|
||||
mDialog = new WifiDialog(getActivity(), this, mDlgAccessPoint,
|
||||
WifiConfigUiBase.MODE_VIEW, true /* hide the submit button */);
|
||||
mDialog = WifiDialog.createModal(getActivity(), this, mDlgAccessPoint,
|
||||
WifiConfigUiBase.MODE_VIEW);
|
||||
return mDialog;
|
||||
|
||||
}
|
||||
return super.onCreateDialog(dialogId);
|
||||
}
|
||||
|
@@ -27,6 +27,7 @@ import com.android.settings.R;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
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 {
|
||||
|
||||
public interface WifiDialogListener {
|
||||
@@ -45,21 +46,31 @@ class WifiDialog extends AlertDialog implements WifiConfigUiBase, DialogInterfac
|
||||
private WifiConfigController mController;
|
||||
private boolean mHideSubmitButton;
|
||||
|
||||
public WifiDialog(Context context, WifiDialogListener listener, AccessPoint accessPoint,
|
||||
int mode, boolean hideSubmitButton) {
|
||||
this(context, listener, accessPoint, mode);
|
||||
mHideSubmitButton = hideSubmitButton;
|
||||
|
||||
/** Creates a WifiDialog with fullscreen style. It displays in fullscreen mode. */
|
||||
public static WifiDialog createFullscreen(Context context, WifiDialogListener listener,
|
||||
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) {
|
||||
// conditionally sets the theme to fullscreen dialog for "Add Network"
|
||||
super(context,
|
||||
mode == WifiConfigUiBase.MODE_CONNECT ? R.style.Theme_Settings_NoActionBar : 0);
|
||||
/**
|
||||
* Creates a WifiDialog with no additional style. It displays as a dialog above the current
|
||||
* view.
|
||||
*/
|
||||
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;
|
||||
mListener = listener;
|
||||
mAccessPoint = accessPoint;
|
||||
mHideSubmitButton = false;
|
||||
mHideSubmitButton = hideSubmitButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -55,7 +55,7 @@ public class WifiDialogActivity extends Activity implements WifiDialog.WifiDialo
|
||||
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.setOnDismissListener(this);
|
||||
}
|
||||
|
@@ -626,20 +626,23 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
public Dialog onCreateDialog(int dialogId) {
|
||||
switch (dialogId) {
|
||||
case WIFI_DIALOG_ID:
|
||||
AccessPoint ap = mDlgAccessPoint; // For manual launch
|
||||
if (ap == null) { // For re-launch from saved state
|
||||
if (mAccessPointSavedState != null) {
|
||||
ap = new AccessPoint(getActivity(), mAccessPointSavedState);
|
||||
// For repeated orientation changes
|
||||
mDlgAccessPoint = ap;
|
||||
if (mDlgAccessPoint == null && mAccessPointSavedState == null) {
|
||||
// add new network
|
||||
mDialog = WifiDialog
|
||||
.createFullscreen(getActivity(), this, mDlgAccessPoint, mDialogMode);
|
||||
} else {
|
||||
// modify network
|
||||
if (mDlgAccessPoint == null) {
|
||||
// restore AP from save state
|
||||
mDlgAccessPoint = new AccessPoint(getActivity(), mAccessPointSavedState);
|
||||
// Reset the saved access point data
|
||||
mAccessPointSavedState = null;
|
||||
}
|
||||
mDialog = WifiDialog
|
||||
.createModal(getActivity(), this, mDlgAccessPoint, mDialogMode);
|
||||
}
|
||||
// If it's null, fine, it's for Add Network
|
||||
mSelectedAccessPoint = ap;
|
||||
mDialog = new WifiDialog(getActivity(), this, ap, mDialogMode,
|
||||
/* no hide submit/connect */ false);
|
||||
|
||||
mSelectedAccessPoint = mDlgAccessPoint;
|
||||
return mDialog;
|
||||
case WPS_PBC_DIALOG_ID:
|
||||
return new WpsDialog(getActivity(), WpsInfo.PBC);
|
||||
|
@@ -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());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user