List of usage examples for android.preference ListPreference setDefaultValue
public void setDefaultValue(Object defaultValue)
From source file:com.aware.Aware_Preferences.java
/** * Webservices module settings UI// w w w . ja va 2 s .com */ private void webservices() { final CheckBoxPreference webservice = (CheckBoxPreference) findPreference( Aware_Preferences.STATUS_WEBSERVICE); webservice.setChecked( Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_WEBSERVICE).equals("true")); webservice.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { if (Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_SERVER).length() == 0) { showDialog(DIALOG_ERROR_MISSING_PARAMETERS); Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_WEBSERVICE, false); webservice.setChecked(false); return false; } else { Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_WEBSERVICE, webservice.isChecked()); if (webservice.isChecked() && Aware.getSetting(getApplicationContext(), WEBSERVICE_SERVER).length() > 0) { //setup and send data Intent study_config = new Intent(getApplicationContext(), StudyConfig.class); study_config.putExtra("study_url", Aware.getSetting(getApplicationContext(), WEBSERVICE_SERVER)); startService(study_config); } return true; } } }); final EditTextPreference webservice_server = (EditTextPreference) findPreference( Aware_Preferences.WEBSERVICE_SERVER); webservice_server.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_SERVER)); if (Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_SERVER).length() > 0) { webservice_server.setSummary( "Server: " + Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_SERVER)); } webservice_server.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Aware.setSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_SERVER, (String) newValue); webservice_server.setSummary("Server: " + (String) newValue); return true; } }); final CheckBoxPreference webservice_wifi_only = (CheckBoxPreference) findPreference( Aware_Preferences.WEBSERVICE_WIFI_ONLY); webservice_wifi_only.setChecked( Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_WIFI_ONLY).equals("true")); webservice_wifi_only.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Aware.setSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_WIFI_ONLY, webservice_wifi_only.isChecked()); return true; } }); final EditTextPreference frequency_webservice = (EditTextPreference) findPreference( Aware_Preferences.FREQUENCY_WEBSERVICE); if (Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_WEBSERVICE).length() > 0) { frequency_webservice.setSummary( Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_WEBSERVICE) + " minutes"); } frequency_webservice .setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_WEBSERVICE)); frequency_webservice.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Aware.setSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_WEBSERVICE, (String) newValue); frequency_webservice.setSummary((String) newValue + " minutes"); return true; } }); final ListPreference clean_old_data = (ListPreference) findPreference(FREQUENCY_CLEAN_OLD_DATA); if (Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_CLEAN_OLD_DATA).length() > 0) { String freq = Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_CLEAN_OLD_DATA); if (freq.equals("0")) { clean_old_data.setSummary("Never"); } else if (freq.equals("1")) { clean_old_data.setSummary("Weekly"); } else if (freq.equals("2")) { clean_old_data.setSummary("Monthly"); } } clean_old_data.setDefaultValue(Aware.getSetting(getApplicationContext(), FREQUENCY_CLEAN_OLD_DATA)); clean_old_data.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Aware.setSetting(getApplicationContext(), FREQUENCY_CLEAN_OLD_DATA, (String) newValue); if (((String) newValue).equals("0")) { clean_old_data.setSummary("Never"); } else if (((String) newValue).equals("1")) { clean_old_data.setSummary("Weekly"); } else if (((String) newValue).equals("2")) { clean_old_data.setSummary("Monthly"); } return true; } }); }