Search in sources :

Example 1 with AppListSwitchPreference

use of com.android.settings.AppListSwitchPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ConfigureWifiSettings method initPreferences.

private void initPreferences() {
    List<WifiConfiguration> configs = mWifiManager.getConfiguredNetworks();
    if (configs == null || configs.size() == 0) {
        removePreference(KEY_SAVED_NETWORKS);
    }
    if (!mWifiManager.hasCarrierConfiguredNetworks()) {
        removePreference(KEY_CONNECT_CARRIER_NETWORKS);
    } else {
        SwitchPreference connectToCarrierNetworks = (SwitchPreference) findPreference(KEY_CONNECT_CARRIER_NETWORKS);
        if (connectToCarrierNetworks != null) {
            connectToCarrierNetworks.setChecked(Settings.Global.getInt(getContentResolver(), Settings.Global.WIFI_CONNECT_CARRIER_NETWORKS, 0) == 1);
        }
    }
    SwitchPreference notifyOpenNetworks = (SwitchPreference) findPreference(KEY_NOTIFY_OPEN_NETWORKS);
    notifyOpenNetworks.setChecked(Settings.Global.getInt(getContentResolver(), Settings.Global.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, 0) == 1);
    notifyOpenNetworks.setEnabled(mWifiManager.isWifiEnabled());
    final Context context = getActivity();
    if (avoidBadWifiConfig()) {
        // Hide preference toggle, always avoid bad wifi networks.
        removePreference(KEY_CELLULAR_FALLBACK);
    } else {
        // Show preference toggle, initialized based on current settings value.
        boolean currentSetting = avoidBadWifiCurrentSettings();
        SwitchPreference pref = (SwitchPreference) findPreference(KEY_CELLULAR_FALLBACK);
        // change if the resources change, but if that happens the activity will be recreated...
        if (pref != null) {
            pref.setChecked(currentSetting);
        }
    }
    mWifiAssistantPreference = (AppListSwitchPreference) findPreference(KEY_WIFI_ASSISTANT);
    Collection<NetworkScorerAppManager.NetworkScorerAppData> scorers = NetworkScorerAppManager.getAllValidScorers(context);
    if (UserManager.get(context).isAdminUser() && !scorers.isEmpty()) {
        mWifiAssistantPreference.setOnPreferenceChangeListener(this);
        initWifiAssistantPreference(scorers);
    } else if (mWifiAssistantPreference != null) {
        getPreferenceScreen().removePreference(mWifiAssistantPreference);
    }
    ListPreference sleepPolicyPref = (ListPreference) findPreference(KEY_SLEEP_POLICY);
    if (sleepPolicyPref != null) {
        if (Utils.isWifiOnly(context)) {
            sleepPolicyPref.setEntries(R.array.wifi_sleep_policy_entries_wifi_only);
        }
        sleepPolicyPref.setOnPreferenceChangeListener(this);
        int value = Settings.Global.getInt(getContentResolver(), Settings.Global.WIFI_SLEEP_POLICY, Settings.Global.WIFI_SLEEP_POLICY_NEVER);
        String stringValue = String.valueOf(value);
        sleepPolicyPref.setValue(stringValue);
        updateSleepPolicySummary(sleepPolicyPref, stringValue);
    }
}
Also used : Context(android.content.Context) WifiConfiguration(android.net.wifi.WifiConfiguration) AppListSwitchPreference(com.android.settings.AppListSwitchPreference) SwitchPreference(android.support.v14.preference.SwitchPreference) ListPreference(android.support.v7.preference.ListPreference)

Aggregations

Context (android.content.Context)1 WifiConfiguration (android.net.wifi.WifiConfiguration)1 SwitchPreference (android.support.v14.preference.SwitchPreference)1 ListPreference (android.support.v7.preference.ListPreference)1 AppListSwitchPreference (com.android.settings.AppListSwitchPreference)1