Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fc5dd2cb authored by Russell Brenner's avatar Russell Brenner
Browse files

Restore look of Wi-Fi panel for Setup Wizard

As part of the Wi-Fi refresh, this CL hides the action bar, menu, and
Settings icon in the context of the Setup Wizard. Dead code related
to WifiSettingsForSetupWizardXL has also been removed.

Bug: 5364589
Change-Id: Ib6716500153879b939a18a7007f1f6521b73890b
parent bd4bac32
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -144,8 +144,9 @@
        </activity-alias>

        <activity android:name=".wifi.WifiPickerActivity"
                  android:label="@string/wifi_setup_wizard_title"
                  android:clearTaskOnLaunch="true"
                  android:parentActivityName="Settings">
                  android:icon="@drawable/empty_icon">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <action android:name="android.net.wifi.PICK_WIFI_NETWORK" />
+2 −0
Original line number Diff line number Diff line
@@ -1179,6 +1179,8 @@
    <string name="wifi_settings_title">Wi-Fi</string>
    <!-- Summary text of the Wi-fi settings screen -->
    <string name="wifi_settings_summary">Set up &amp; manage wireless access points</string>
    <!-- Used in the 1st-level settings screen to turn on Wi-Fi  [CHAR LIMIT=NONE] -->
    <string name="wifi_setup_wizard_title">Select Wi-Fi network</string>
    <!-- Summary text when turning Wi-Fi or bluetooth on -->
    <string name="wifi_starting">Turning Wi-Fi on\u2026</string>
    <!-- Summary text when turning Wi-Fi or bluetooth off -->
+10 −0
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@ public class WifiPickerActivity extends PreferenceActivity implements ButtonBarH
    private static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
    private static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
    private static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
    private static final String EXTRA_WIFI_SHOW_ACTION_BAR = "wifi_show_action_bar";
    private static final String EXTRA_WIFI_SHOW_MENUS = "wifi_show_menus";

    @Override
    public Intent getIntent() {
@@ -67,6 +69,14 @@ public class WifiPickerActivity extends PreferenceActivity implements ButtonBarH
            intent.putExtra(EXTRA_PREFS_SET_BACK_TEXT,
                    orgIntent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT));
        }
        if (orgIntent.hasExtra(EXTRA_WIFI_SHOW_ACTION_BAR)) {
            intent.putExtra(EXTRA_WIFI_SHOW_ACTION_BAR,
                    orgIntent.getBooleanExtra(EXTRA_WIFI_SHOW_ACTION_BAR, true));
        }
        if (orgIntent.hasExtra(EXTRA_WIFI_SHOW_MENUS)) {
            intent.putExtra(EXTRA_WIFI_SHOW_MENUS,
                    orgIntent.getBooleanExtra(EXTRA_WIFI_SHOW_MENUS, true));
        }

        if (resultTo == null) {
            startActivity(intent);
+44 −88
Original line number Diff line number Diff line
@@ -70,15 +70,12 @@ import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * This currently provides three types of UI.
 * Two types of UI are provided here.
 *
 * Two are for phones with relatively small screens: "for SetupWizard" and "for usual Settings".
 * Users just need to launch WifiSettings Activity as usual. The request will be appropriately
 * handled by ActivityManager, and they will have appropriate look-and-feel with this fragment.
 * The first is for "usual Settings", appearing as any other Setup fragment.
 *
 * Third type is for Setup Wizard with X-Large, landscape UI. Users need to launch
 * {@link WifiSettingsForSetupWizardXL} Activity, which contains this fragment but also has
 * other decorations specific to that screen.
 * The second is for Setup Wizard, with a simplified interface that hides the action bar
 * and menus.
 */
public class WifiSettings extends SettingsPreferenceFragment
        implements DialogInterface.OnClickListener  {
@@ -135,15 +132,20 @@ public class WifiSettings extends SettingsPreferenceFragment
    // this boolean extra specifies whether to disable the Next button when not connected
    private static final String EXTRA_ENABLE_NEXT_ON_CONNECT = "wifi_enable_next_on_connect";

    private static final String EXTRA_WIFI_SHOW_ACTION_BAR = "wifi_show_action_bar";
    private static final String EXTRA_WIFI_SHOW_MENUS = "wifi_show_menus";

    // should Next button only be enabled when we have a connection?
    private boolean mEnableNextOnConnection;
    private boolean mInXlSetupWizard;

    // Save the dialog details
    private boolean mDlgEdit;
    private AccessPoint mDlgAccessPoint;
    private Bundle mAccessPointSavedState;

    // Menus are not shown by Setup Wizard
    private boolean mShowMenu;

    /* End of "used in Wifi Setup context" */

    public WifiSettings() {
@@ -167,13 +169,6 @@ public class WifiSettings extends SettingsPreferenceFragment
        mScanner = new Scanner();
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);

        mInXlSetupWizard = (activity instanceof WifiSettingsForSetupWizardXL);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        // We don't call super.onActivityCreated() here, since it assumes we already set up
@@ -238,11 +233,11 @@ public class WifiSettings extends SettingsPreferenceFragment
            }
        }

        if (mInXlSetupWizard) {
            addPreferencesFromResource(R.xml.wifi_access_points_for_wifi_setup_xl);
        } else {
        addPreferencesFromResource(R.xml.wifi_settings);

        // Action bar is hidden for Setup Wizard
        final boolean showActionBar = intent.getBooleanExtra(EXTRA_WIFI_SHOW_ACTION_BAR, true);
        if (showActionBar) {
            Switch actionBarSwitch = new Switch(activity);

            if (activity instanceof PreferenceActivity) {
@@ -266,8 +261,12 @@ public class WifiSettings extends SettingsPreferenceFragment
        mEmptyView = (TextView) getView().findViewById(android.R.id.empty);
        getListView().setEmptyView(mEmptyView);

        // Menu is hidden for Setup Wizard
        mShowMenu = intent.getBooleanExtra(EXTRA_WIFI_SHOW_MENUS, true);
        if (mShowMenu) {
            registerForContextMenu(getListView());
        setHasOptionsMenu(true);
        }
        setHasOptionsMenu(mShowMenu);

        // After confirming PreferenceScreen is available, we call super.
        super.onActivityCreated(savedInstanceState);
@@ -302,8 +301,7 @@ public class WifiSettings extends SettingsPreferenceFragment

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        // We don't want menus in Setup Wizard XL.
        if (!mInXlSetupWizard) {
        if (mShowMenu) {
            final boolean wifiIsEnabled = mWifiManager.isWifiEnabled();
            menu.add(Menu.NONE, MENU_ID_WPS_PBC, 0, R.string.wifi_menu_wps_pbc)
                    .setEnabled(wifiIsEnabled)
@@ -390,9 +388,7 @@ public class WifiSettings extends SettingsPreferenceFragment

    @Override
    public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo info) {
        if (mInXlSetupWizard) {
            ((WifiSettingsForSetupWizardXL)getActivity()).onCreateContextMenu(menu, view, info);
        } else if (info instanceof AdapterContextMenuInfo) {
        if (info instanceof AdapterContextMenuInfo) {
            Preference preference = (Preference) getListView().getItemAtPosition(
                    ((AdapterContextMenuInfo) info).position);

@@ -429,7 +425,7 @@ public class WifiSettings extends SettingsPreferenceFragment
                    mWifiManager.connect(mChannel, mSelectedAccessPoint.getConfig(),
                            mConnectListener);
                } else {
                    showConfigUi(mSelectedAccessPoint, true);
                    showDialog(mSelectedAccessPoint, true);
                }
                return true;
            }
@@ -438,7 +434,7 @@ public class WifiSettings extends SettingsPreferenceFragment
                return true;
            }
            case MENU_ID_MODIFY: {
                showConfigUi(mSelectedAccessPoint, true);
                showDialog(mSelectedAccessPoint, true);
                return true;
            }
        }
@@ -455,7 +451,7 @@ public class WifiSettings extends SettingsPreferenceFragment
                mSelectedAccessPoint.generateOpenNetworkConfig();
                mWifiManager.connect(mChannel, mSelectedAccessPoint.getConfig(), mConnectListener);
            } else {
                showConfigUi(mSelectedAccessPoint, false);
                showDialog(mSelectedAccessPoint, false);
            }
        } else {
            return super.onPreferenceTreeClick(screen, preference);
@@ -463,18 +459,6 @@ public class WifiSettings extends SettingsPreferenceFragment
        return true;
    }

    /**
     * Shows an appropriate Wifi configuration component.
     * Called when a user clicks "Add network" preference or one of available networks is selected.
     */
    private void showConfigUi(AccessPoint accessPoint, boolean edit) {
        if (mInXlSetupWizard) {
            ((WifiSettingsForSetupWizardXL)getActivity()).showConfigUi(accessPoint, edit);
        } else {
            showDialog(accessPoint, edit);
        }
    }

    private void showDialog(AccessPoint accessPoint, boolean edit) {
        if (mDialog != null) {
            removeDialog(WIFI_DIALOG_ID);
@@ -537,17 +521,12 @@ public class WifiSettings extends SettingsPreferenceFragment
                // AccessPoints are automatically sorted with TreeSet.
                final Collection<AccessPoint> accessPoints = constructAccessPoints();
                getPreferenceScreen().removeAll();
                if (mInXlSetupWizard) {
                    ((WifiSettingsForSetupWizardXL)getActivity()).onAccessPointsUpdated(
                            getPreferenceScreen(), accessPoints);
                } else {
                if(accessPoints.size() == 0) {
                    addMessagePreference(R.string.wifi_empty_list_wifi_on);
                }
                for (AccessPoint accessPoint : accessPoints) {
                    getPreferenceScreen().addPreference(accessPoint);
                }
                }
                break;

            case WifiManager.WIFI_STATE_ENABLING:
@@ -653,10 +632,6 @@ public class WifiSettings extends SettingsPreferenceFragment
            if (!mConnected.get() && SupplicantState.isHandshakeState(state)) {
                updateConnectionState(WifiInfo.getDetailedStateOf(state));
            }

            if (mInXlSetupWizard) {
                ((WifiSettingsForSetupWizardXL)getActivity()).onSupplicantStateChanged(intent);
            }
        } else if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) {
            NetworkInfo info = (NetworkInfo) intent.getParcelableExtra(
                    WifiManager.EXTRA_NETWORK_INFO);
@@ -695,10 +670,6 @@ public class WifiSettings extends SettingsPreferenceFragment
                accessPoint.update(mLastInfo, mLastState);
            }
        }

        if (mInXlSetupWizard) {
            ((WifiSettingsForSetupWizardXL)getActivity()).updateConnectionState(mLastState);
        }
    }

    private void updateWifiState(int state) {
@@ -763,21 +734,12 @@ public class WifiSettings extends SettingsPreferenceFragment
     * @param connected true when the device is connected to a wifi network.
     */
    private void changeNextButtonState(boolean connected) {
        if (mInXlSetupWizard) {
            ((WifiSettingsForSetupWizardXL)getActivity()).changeNextButtonState(connected);
        } else if (mEnableNextOnConnection && hasNextButton()) {
        if (mEnableNextOnConnection && hasNextButton()) {
            getNextButton().setEnabled(connected);
        }
    }

    public void onClick(DialogInterface dialogInterface, int button) {
        if (mInXlSetupWizard) {
            if (button == WifiDialog.BUTTON_FORGET && mSelectedAccessPoint != null) {
                forget();
            } else if (button == WifiDialog.BUTTON_SUBMIT) {
                ((WifiSettingsForSetupWizardXL)getActivity()).onConnectButtonPressed();
            }
        } else {
        if (button == WifiDialog.BUTTON_FORGET && mSelectedAccessPoint != null) {
            forget();
        } else if (button == WifiDialog.BUTTON_SUBMIT) {
@@ -785,8 +747,6 @@ public class WifiSettings extends SettingsPreferenceFragment
        }
    }

    }

    /* package */ void submit(WifiConfigController configController) {

        final WifiConfiguration config = configController.getConfig();
@@ -800,11 +760,11 @@ public class WifiSettings extends SettingsPreferenceFragment
            }
        } else if (config.networkId != INVALID_NETWORK_ID) {
            if (mSelectedAccessPoint != null) {
                saveNetwork(config);
                mWifiManager.save(mChannel, config, mSaveListener);
            }
        } else {
            if (configController.isEdit() || requireKeyStore(config)) {
                saveNetwork(config);
                mWifiManager.save(mChannel, config, mSaveListener);
            } else {
                mWifiManager.connect(mChannel, config, mConnectListener);
            }
@@ -816,14 +776,6 @@ public class WifiSettings extends SettingsPreferenceFragment
        updateAccessPoints();
    }

    private void saveNetwork(WifiConfiguration config) {
        if (mInXlSetupWizard) {
            ((WifiSettingsForSetupWizardXL)getActivity()).onSaveNetwork(config);
        } else {
            mWifiManager.save(mChannel, config, mSaveListener);
        }
    }

    /* package */ void forget() {
        mWifiManager.forget(mChannel, mSelectedAccessPoint.networkId, mForgetListener);

@@ -853,7 +805,7 @@ public class WifiSettings extends SettingsPreferenceFragment
    /* package */ void onAddNetworkPressed() {
        // No exact access point is selected.
        mSelectedAccessPoint = null;
        showConfigUi(null, true);
        showDialog(null, true);
    }

    /* package */ int getAccessPointsCount() {
@@ -885,6 +837,10 @@ public class WifiSettings extends SettingsPreferenceFragment

    @Override
    protected int getHelpResource() {
        // Setup Wizard has different help content
        if (mShowMenu) {
            return R.string.help_url_wifi;
        }
        return 0;
    }
}