@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SettingsActivityComponent cmp = DaggerService.getDaggerComponent(getActivity()); cmp.inject(this); mSettings.setCached(true); addPreferencesFromResource(R.xml.prefs_service); runWhen = (ListPreference) findPreference(ServiceSettings.RUN_WHEN); runWhen.setPersistent(false); runWhen.setValue(mSettings.runWhen()); runWhen.setOnPreferenceChangeListener(this); onlyOnWifi = (CheckBoxPreference) findPreference(ServiceSettings.ONLY_WIFI); onlyOnWifi.setPersistent(false); onlyOnWifi.setChecked(mSettings.onlyOnWifi()); onlyOnWifi.setOnPreferenceChangeListener(this); wifiNetwork = (MultiSelectListPreference) findPreference(ServiceSettings.WIFI_NETWORKS); wifiNetwork.setPersistent(false); String[] ssids = getWifiNetworks(); wifiNetwork.setEntries(ssids); wifiNetwork.setEntryValues(ssids); wifiNetwork.setValues(mSettings.allowedWifiNetworks()); wifiNetwork.setOnPreferenceChangeListener(this); onlyCharging = (CheckBoxPreference) findPreference(ServiceSettings.ONLY_CHARGING); onlyCharging.setPersistent(false); onlyCharging.setChecked(mSettings.onlyWhenCharging()); onlyCharging.setOnPreferenceChangeListener(this); catBetween = (PreferenceCategory) findPreference("cat_between"); hideShowRunWhenCategories(mSettings.runWhen()); scheduleStart = (TimePreference) findPreference(ServiceSettings.RANGE_START); scheduleStart.setPersistent(false); scheduleStart.setValue(mSettings.getScheduledStartTime()); scheduleStart.setOnPreferenceChangeListener(this); scheduleEnd = (TimePreference) findPreference(ServiceSettings.RANGE_END); scheduleEnd.setPersistent(false); scheduleEnd.setValue(mSettings.getScheduledEndTime()); scheduleEnd.setOnPreferenceChangeListener(this); exportConfig = findPreference("export"); exportConfig.setOnPreferenceClickListener(this); importConfig = findPreference("import"); importConfig.setOnPreferenceClickListener(this); }
private static void addPreferences(PreferenceScreen ps) { Context cx = ps.getContext(); Resources r = cx.getResources(); ps.setOrderingAsAdded(true); for (Codec c : codecs) { ListPreference l = new ListPreference(cx); l.setEntries(r.getStringArray(R.array.compression_display_values)); l.setEntryValues(r.getStringArray(R.array.compression_values)); l.setKey(c.key()); l.setPersistent(true); l.setEnabled(!c.isFailed()); c.setListPreference(l); l.setSummary(l.getEntry()); l.setTitle(c.getTitle()); ps.addPreference(l); } }