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);
}
}
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();
}
}
}
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;
}
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;
}
});
}
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;
}
});
}
Aggregations