List of usage examples for android.preference CheckBoxPreference setChecked
public void setChecked(boolean checked)
From source file:fi.iki.murgo.irssinotifier.SettingsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { Log.d(TAG, "Opened settings"); super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preference_screen); final Context ctx = this; final CheckBoxPreference enabled = (CheckBoxPreference) findPreference("NotificationsEnabled"); enabled.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { final boolean checked = (Boolean) newValue; String s = "Disabling notifications..."; if (checked) { s = "Enabling notifications..."; }/*from w w w . j a v a2 s . c om*/ SettingsSendingTask task = new SettingsSendingTask(SettingsActivity.this, "Sending settings", s); task.setCallback(new Callback<ServerResponse>() { @Override public void doStuff(ServerResponse result) { if (result.getException() != null) { if (result.getException() instanceof IOException) { MessageBox.Show(ctx, "Network error", "Ensure your internet connection works and try again.", null); } else if (result.getException() instanceof AuthenticationException) { MessageBox.Show(ctx, "Authentication error", "Unable to authenticate to server.", null); } else if (result.getException() instanceof ServerException) { MessageBox.Show(ctx, "Server error", "Mystical server error, check if updates are available", null); } else { MessageBox.Show(ctx, null, "Unable to send settings to the server! Please try again later!", null); } enabled.setChecked(!checked); } } }); task.execute(); return true; } }); Preference aboutPref = findPreference("about"); aboutPref.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { Intent i = new Intent(ctx, AboutActivity.class); startActivity(i); finish(); return true; } }); Preference channelsPref = findPreference("channels"); channelsPref.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { Intent i = new Intent(ctx, ChannelSettingsActivity.class); startActivity(i); return true; } }); ListPreference mode = (ListPreference) findPreference("notificationModeString"); mode.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { NotificationMode m = NotificationMode.PerChannel; String v = (String) newValue; if (v.equals(ctx.getResources().getStringArray(R.array.notification_modes)[0])) m = NotificationMode.Single; if (v.equals(ctx.getResources().getStringArray(R.array.notification_modes)[1])) m = NotificationMode.PerChannel; if (v.equals(ctx.getResources().getStringArray(R.array.notification_modes)[2])) m = NotificationMode.PerMessage; Preferences p = new Preferences(ctx); p.setNotificationMode(m); return true; } }); Preference initialSettingsPref = findPreference("redoInitialSettings"); initialSettingsPref.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { Preferences prefs = new Preferences(ctx); prefs.setAuthToken(null); prefs.setAccountName(null); prefs.setGcmRegistrationId(null); prefs.setLicenseCount(0); IrssiNotifierActivity.refreshIsNeeded(); finish(); return true; } }); Preference disableThemePref = findPreference("ThemeDisabled"); disableThemePref.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { IrssiNotifierActivity.refreshIsNeeded(); return true; } }); handleColorPicker(); handleIcb(); if (!LicenseHelper.isPlusVersion(this)) { CheckBoxPreference usePullMechanismPref = (CheckBoxPreference) findPreference("UsePullMechanism"); usePullMechanismPref.setSummary(usePullMechanismPref.getSummary() + ". Only in Plus version."); usePullMechanismPref.setEnabled(false); usePullMechanismPref.setChecked(false); } }
From source file:net.basilwang.StaticAttachmentActivity.java
@Override public void onPreferenceAttached(PreferenceScreen root, int xmlId) { if (root == null) return; // for whatever reason in very rare cases this is null if (xmlId == R.xml.preferencesfragment) { PreferenceCategory logonPreference; PreferenceScreen logonAddPreference; PreferenceScreen aboutusPreference; PreferenceScreen shareonweiboPreference; // PreferenceScreen ruguozhaiPreference; // The filelds we have deleted // CheckBoxPreference weekViewCheckboxPreference; // CheckBoxPreference scoreCheckboxPreference; CheckBoxPreference adCheckboxPreference; logonAddPreference = (PreferenceScreen) root .findPreference(LOGON_ADD_PREFERENCES); if (logonAddPreference != null) { logonAddPreference.setOnPreferenceClickListener(this); }// ww w . j a v a 2 s .co m logonPreference = (PreferenceCategory) root .findPreference(LOGON_PREFERENCES); aboutusPreference = (PreferenceScreen) root .findPreference(ABOUT_US); shareonweiboPreference = (PreferenceScreen) root .findPreference(SHAREONWEIBO); // ruguozhaiPreference = (PreferenceScreen) root // .findPreference(RU_GUO_ZHAI); adCheckboxPreference = (CheckBoxPreference) root .findPreference(CLOSE_AD); // weekViewCheckboxPreference = (CheckBoxPreference) root // .findPreference(WEEKVIEW_ENABLED); // 2012-09-26 basilwang if weekview already enabled, we set // WeekViewCheckboxPreference enable status is false // if (Preferences.isWeekViewUnlocked(this)) { // weekViewCheckboxPreference.setChecked(true); // weekViewCheckboxPreference.setEnabled(false); // } else { // weekViewCheckboxPreference.setChecked(false); // weekViewCheckboxPreference.setEnabled(true); // } if (Preferences.isAdClosed(this)) { adCheckboxPreference.setChecked(true); adCheckboxPreference.setEnabled(false); } else { adCheckboxPreference.setChecked(false); adCheckboxPreference.setEnabled(true); } aboutusPreference.setOnPreferenceClickListener(this); shareonweiboPreference.setOnPreferenceClickListener(this); // ruguozhaiPreference.setOnPreferenceClickListener(this); // weekViewCheckboxPreference.setOnPreferenceClickListener(this); adCheckboxPreference.setOnPreferenceClickListener(this); YoumiOffersManager.init(this, "2fc95b356bb979ae", "8b94f727980f7158"); YoumiOffersManager.checkStatus(StaticAttachmentActivity.this, StaticAttachmentActivity.this); reloadData(logonPreference, logonAddPreference, root.getPreferenceManager()); } }
From source file:com.aware.Aware_Preferences.java
/** * ESM module settings UI//ww w . j av a 2 s .c o m */ private void esm() { final CheckBoxPreference esm = (CheckBoxPreference) findPreference(Aware_Preferences.STATUS_ESM); esm.setChecked(Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_ESM).equals("true")); esm.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_ESM, esm.isChecked()); if (esm.isChecked()) { framework.startESM(); } else { framework.stopESM(); } return true; } }); }
From source file:com.aware.Aware_Preferences.java
/** * Screen module settings UI//from ww w. java 2 s .com */ private void screen() { final CheckBoxPreference screen = (CheckBoxPreference) findPreference(Aware_Preferences.STATUS_SCREEN); screen.setChecked( Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_SCREEN).equals("true")); screen.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_SCREEN, screen.isChecked()); if (screen.isChecked()) { framework.startScreen(); } else { framework.stopScreen(); } return true; } }); }
From source file:com.aware.Aware_Preferences.java
/** * Battery module settings UI//www . j a v a 2s . c o m */ private void battery() { final CheckBoxPreference battery = (CheckBoxPreference) findPreference(Aware_Preferences.STATUS_BATTERY); battery.setChecked( Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_BATTERY).equals("true")); battery.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_BATTERY, battery.isChecked()); if (battery.isChecked()) { framework.startBattery(); } else { framework.stopBattery(); } return true; } }); }
From source file:com.aware.Aware_Preferences.java
/** * WiFi module settings UI//from ww w. j a v a2 s .c o m */ private void wifi() { final CheckBoxPreference wifi = (CheckBoxPreference) findPreference(Aware_Preferences.STATUS_WIFI); wifi.setChecked(Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_WIFI).equals("true")); wifi.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_WIFI, wifi.isChecked()); if (wifi.isChecked()) { framework.startWiFi(); } else { framework.stopWiFi(); } return true; } }); final EditTextPreference wifiInterval = (EditTextPreference) findPreference( Aware_Preferences.FREQUENCY_WIFI); if (Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_WIFI).length() > 0) { wifiInterval.setSummary( Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_WIFI) + " seconds"); } wifiInterval.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_WIFI)); wifiInterval.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Aware.setSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_WIFI, (String) newValue); wifiInterval.setSummary((String) newValue + " seconds"); framework.startWiFi(); return true; } }); }
From source file:com.aware.Aware_Preferences.java
/** * TimeZone module settings UI/*w w w. ja v a 2s. c o m*/ */ private void timeZone() { final CheckBoxPreference timeZone = (CheckBoxPreference) findPreference(Aware_Preferences.STATUS_TIMEZONE); timeZone.setChecked( Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_TIMEZONE).equals("true")); timeZone.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_TIMEZONE, timeZone.isChecked()); if (timeZone.isChecked()) { framework.startTimeZone(); } else { framework.stopTimeZone(); } return true; } }); final EditTextPreference frequencyTimeZone = (EditTextPreference) findPreference( Aware_Preferences.FREQUENCY_TIMEZONE); if (Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_TIMEZONE).length() > 0) { frequencyTimeZone.setSummary( Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_TIMEZONE) + " seconds"); } frequencyTimeZone.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_TIMEZONE)); frequencyTimeZone.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Aware.setSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_TIMEZONE, (String) newValue); frequencyTimeZone.setSummary((String) newValue + " seconds"); framework.startTimeZone(); return true; } }); }
From source file:com.aware.Aware_Preferences.java
/** * Telephony module settings UI/*from ww w . ja v a 2 s .c om*/ */ private void telephony() { final CheckBoxPreference telephony = (CheckBoxPreference) findPreference( Aware_Preferences.STATUS_TELEPHONY); telephony.setChecked( Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_TELEPHONY).equals("true")); telephony.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_TELEPHONY, telephony.isChecked()); if (telephony.isChecked()) { framework.startTelephony(); } else { framework.stopTelephony(); } return true; } }); }
From source file:com.aware.Aware_Preferences.java
/** * Communication module settings UI/*from w ww . ja v a2s. c om*/ */ private void communication() { final CheckBoxPreference calls = (CheckBoxPreference) findPreference(Aware_Preferences.STATUS_CALLS); calls.setChecked(Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_CALLS).equals("true")); calls.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_CALLS, calls.isChecked()); if (calls.isChecked()) { framework.startCommunication(); } else { framework.stopCommunication(); } return true; } }); final CheckBoxPreference messages = (CheckBoxPreference) findPreference(Aware_Preferences.STATUS_MESSAGES); messages.setChecked( Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_MESSAGES).equals("true")); messages.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_MESSAGES, messages.isChecked()); if (messages.isChecked()) { framework.startCommunication(); } else { framework.stopCommunication(); } return true; } }); final CheckBoxPreference communication = (CheckBoxPreference) findPreference( Aware_Preferences.STATUS_COMMUNICATION_EVENTS); communication.setChecked(Aware .getSetting(getApplicationContext(), Aware_Preferences.STATUS_COMMUNICATION_EVENTS).equals("true")); communication.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_COMMUNICATION_EVENTS, communication.isChecked()); if (communication.isChecked()) { framework.startCommunication(); } else { framework.stopCommunication(); } return true; } }); }
From source file:com.aware.Aware_Preferences.java
/** * Light module settings UI/*from w w w . j a va 2 s .co m*/ */ private void light() { final PreferenceScreen light_pref = (PreferenceScreen) findPreference("light"); Sensor temp = mSensorMgr.getDefaultSensor(Sensor.TYPE_LIGHT); if (temp != null) { light_pref.setSummary( light_pref.getSummary().toString().replace("*", " - Power: " + temp.getPower() + " mA")); } else { light_pref.setSummary(light_pref.getSummary().toString().replace("*", "")); } final CheckBoxPreference light = (CheckBoxPreference) findPreference(Aware_Preferences.STATUS_LIGHT); light.setChecked(Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_LIGHT).equals("true")); light.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { if (mSensorMgr.getDefaultSensor(Sensor.TYPE_LIGHT) == null) { showDialog(DIALOG_ERROR_MISSING_SENSOR); light.setChecked(false); Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_LIGHT, false); return false; } Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_LIGHT, light.isChecked()); if (light.isChecked()) { framework.startLight(); } else { framework.stopLight(); } return true; } }); final EditTextPreference frequency_light = (EditTextPreference) findPreference( Aware_Preferences.FREQUENCY_LIGHT); if (Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LIGHT).length() > 0) { frequency_light.setSummary( Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LIGHT) + " microseconds"); } frequency_light.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LIGHT)); frequency_light.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Aware.setSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LIGHT, (String) newValue); frequency_light.setSummary((String) newValue + " microseconds"); framework.startLight(); return true; } }); }