Search in sources :

Example 11 with SwitchPreference

use of android.support.v14.preference.SwitchPreference 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)

Example 12 with SwitchPreference

use of android.support.v14.preference.SwitchPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class WifiApEnabler method handleWifiApStateChanged.

private void handleWifiApStateChanged(int state, int reason) {
    boolean enableWifiApSettingsExt = mContext.getResources().getBoolean(R.bool.show_wifi_hotspot_settings);
    if (enableWifiApSettingsExt) {
        HotspotPreference hSwitch = (HotspotPreference) mSwitch;
        switch(state) {
            case WifiManager.WIFI_AP_STATE_ENABLING:
                hSwitch.setSummary(R.string.wifi_tether_starting);
                hSwitch.setEnabled(false);
                break;
            case WifiManager.WIFI_AP_STATE_ENABLED:
                /**
                     * Summary on enable is handled by tether
                     * broadcast notice
                     */
                postTurnOn(mContext, TETHERING_WIFI);
                hSwitch.setChecked(true);
                /* Doesnt need the airplane check */
                hSwitch.setEnabled(!mDataSaverBackend.isDataSaverEnabled());
                break;
            case WifiManager.WIFI_AP_STATE_DISABLING:
                hSwitch.setSummary(R.string.wifi_tether_stopping);
                hSwitch.setChecked(false);
                hSwitch.setEnabled(false);
                break;
            case WifiManager.WIFI_AP_STATE_DISABLED:
                hSwitch.setChecked(false);
                hSwitch.setSummary(mOriginalSummary);
                enableWifiSwitch();
                break;
            default:
                hSwitch.setChecked(false);
                if (reason == WifiManager.SAP_START_FAILURE_NO_CHANNEL) {
                    hSwitch.setSummary(R.string.wifi_sap_no_channel_error);
                } else {
                    hSwitch.setSummary(R.string.wifi_error);
                }
                enableWifiSwitch();
        }
    } else {
        SwitchPreference sSwitch = (SwitchPreference) mSwitch;
        switch(state) {
            case WifiManager.WIFI_AP_STATE_ENABLING:
                sSwitch.setSummary(R.string.wifi_tether_starting);
                sSwitch.setEnabled(false);
                break;
            case WifiManager.WIFI_AP_STATE_ENABLED:
                /**
                     * Summary on enable is handled by tether
                     * broadcast notice
                     */
                sSwitch.setChecked(true);
                /* Doesnt need the airplane check */
                sSwitch.setEnabled(!mDataSaverBackend.isDataSaverEnabled());
                mWifiSavedState = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.WIFI_SAVED_STATE, 0);
                break;
            case WifiManager.WIFI_AP_STATE_DISABLING:
                sSwitch.setSummary(R.string.wifi_tether_stopping);
                sSwitch.setChecked(false);
                sSwitch.setEnabled(false);
                break;
            case WifiManager.WIFI_AP_STATE_DISABLED:
                sSwitch.setChecked(false);
                sSwitch.setSummary(mOriginalSummary);
                /* If saved WiFi state is enabled, WiFi will restore to enabled state
                    on softAP disable. in this case call enableWifiSwitch on WIFI_STATE_ENABLED
                    event */
                if (mWifiSavedState == 0)
                    enableWifiSwitch();
                break;
            default:
                sSwitch.setChecked(false);
                if (reason == WifiManager.SAP_START_FAILURE_NO_CHANNEL) {
                    sSwitch.setSummary(R.string.wifi_sap_no_channel_error);
                } else {
                    sSwitch.setSummary(R.string.wifi_error);
                }
                enableWifiSwitch();
        }
    }
}
Also used : SwitchPreference(android.support.v14.preference.SwitchPreference) HotspotPreference(com.android.settings.HotspotPreference)

Example 13 with SwitchPreference

use of android.support.v14.preference.SwitchPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DevelopmentSettings method findAndInitSwitchPref.

private SwitchPreference findAndInitSwitchPref(String key) {
    SwitchPreference pref = (SwitchPreference) findPreference(key);
    if (pref == null) {
        throw new IllegalArgumentException("Cannot find preference with key = " + key);
    }
    mAllPrefs.add(pref);
    mResetSwitchPrefs.add(pref);
    return pref;
}
Also used : RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) SwitchPreference(android.support.v14.preference.SwitchPreference)

Example 14 with SwitchPreference

use of android.support.v14.preference.SwitchPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ZenModeScheduleRuleSettings method onCreateInternal.

@Override
protected void onCreateInternal() {
    addPreferencesFromResource(R.xml.zen_mode_schedule_rule_settings);
    final PreferenceScreen root = getPreferenceScreen();
    mDays = root.findPreference(KEY_DAYS);
    mDays.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            showDaysDialog();
            return true;
        }
    });
    final FragmentManager mgr = getFragmentManager();
    mStart = new TimePickerPreference(getPrefContext(), mgr);
    mStart.setKey(KEY_START_TIME);
    mStart.setTitle(R.string.zen_mode_start_time);
    mStart.setCallback(new TimePickerPreference.Callback() {

        @Override
        public boolean onSetTime(final int hour, final int minute) {
            if (mDisableListeners)
                return true;
            if (!ZenModeConfig.isValidHour(hour))
                return false;
            if (!ZenModeConfig.isValidMinute(minute))
                return false;
            if (hour == mSchedule.startHour && minute == mSchedule.startMinute) {
                return true;
            }
            if (DEBUG)
                Log.d(TAG, "onPrefChange start h=" + hour + " m=" + minute);
            mSchedule.startHour = hour;
            mSchedule.startMinute = minute;
            updateRule(ZenModeConfig.toScheduleConditionId(mSchedule));
            return true;
        }
    });
    root.addPreference(mStart);
    mStart.setDependency(mDays.getKey());
    mEnd = new TimePickerPreference(getPrefContext(), mgr);
    mEnd.setKey(KEY_END_TIME);
    mEnd.setTitle(R.string.zen_mode_end_time);
    mEnd.setCallback(new TimePickerPreference.Callback() {

        @Override
        public boolean onSetTime(final int hour, final int minute) {
            if (mDisableListeners)
                return true;
            if (!ZenModeConfig.isValidHour(hour))
                return false;
            if (!ZenModeConfig.isValidMinute(minute))
                return false;
            if (hour == mSchedule.endHour && minute == mSchedule.endMinute) {
                return true;
            }
            if (DEBUG)
                Log.d(TAG, "onPrefChange end h=" + hour + " m=" + minute);
            mSchedule.endHour = hour;
            mSchedule.endMinute = minute;
            updateRule(ZenModeConfig.toScheduleConditionId(mSchedule));
            return true;
        }
    });
    root.addPreference(mEnd);
    mEnd.setDependency(mDays.getKey());
    mExitAtAlarm = (SwitchPreference) root.findPreference(KEY_EXIT_AT_ALARM);
    mExitAtAlarm.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object o) {
            mSchedule.exitAtAlarm = (Boolean) o;
            updateRule(ZenModeConfig.toScheduleConditionId(mSchedule));
            return true;
        }
    });
}
Also used : OnPreferenceClickListener(android.support.v7.preference.Preference.OnPreferenceClickListener) FragmentManager(android.app.FragmentManager) PreferenceScreen(android.support.v7.preference.PreferenceScreen) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference)

Example 15 with SwitchPreference

use of android.support.v14.preference.SwitchPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ZenModeVisualInterruptionSettings method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.zen_mode_visual_interruptions_settings);
    final PreferenceScreen root = getPreferenceScreen();
    mPolicy = NotificationManager.from(mContext).getNotificationPolicy();
    mScreenOff = (SwitchPreference) root.findPreference(KEY_SCREEN_OFF);
    if (!getResources().getBoolean(com.android.internal.R.bool.config_intrusiveNotificationLed)) {
        mScreenOff.setSummary(R.string.zen_mode_screen_off_summary_no_led);
    }
    mScreenOff.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (mDisableListeners)
                return true;
            final boolean val = (Boolean) newValue;
            MetricsLogger.action(mContext, MetricsEvent.ACTION_ZEN_ALLOW_WHEN_SCREEN_OFF, val);
            if (DEBUG)
                Log.d(TAG, "onPrefChange suppressWhenScreenOff=" + val);
            savePolicy(getNewSuppressedEffects(val, Policy.SUPPRESSED_EFFECT_SCREEN_OFF));
            return true;
        }
    });
    mScreenOn = (SwitchPreference) root.findPreference(KEY_SCREEN_ON);
    mScreenOn.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (mDisableListeners)
                return true;
            final boolean val = (Boolean) newValue;
            MetricsLogger.action(mContext, MetricsEvent.ACTION_ZEN_ALLOW_WHEN_SCREEN_ON, val);
            if (DEBUG)
                Log.d(TAG, "onPrefChange suppressWhenScreenOn=" + val);
            savePolicy(getNewSuppressedEffects(val, Policy.SUPPRESSED_EFFECT_SCREEN_ON));
            return true;
        }
    });
}
Also used : PreferenceScreen(android.support.v7.preference.PreferenceScreen) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference)

Aggregations

SwitchPreference (android.support.v14.preference.SwitchPreference)30 Preference (android.support.v7.preference.Preference)16 PreferenceScreen (android.support.v7.preference.PreferenceScreen)16 Context (android.content.Context)8 ContentResolver (android.content.ContentResolver)7 ListPreference (android.support.v7.preference.ListPreference)7 OnPreferenceChangeListener (android.support.v7.preference.Preference.OnPreferenceChangeListener)6 PreferenceCategory (android.support.v7.preference.PreferenceCategory)5 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)5 RestrictedPreference (com.android.settingslib.RestrictedPreference)4 Activity (android.app.Activity)3 Intent (android.content.Intent)3 PreferenceGroup (android.support.v7.preference.PreferenceGroup)3 PackageItemInfo (android.content.pm.PackageItemInfo)2 Settings (android.provider.Settings)2 DropDownPreference (android.support.v7.preference.DropDownPreference)2 OnPreferenceClickListener (android.support.v7.preference.Preference.OnPreferenceClickListener)2 ArrayList (java.util.ArrayList)2 FragmentManager (android.app.FragmentManager)1 UiModeManager (android.app.UiModeManager)1