List of usage examples for android.preference CheckBoxPreference getSummary
public CharSequence getSummary()
From source file:Main.java
static void addSwitchPreferenceBasedOnCheckBoxPreference(final CheckBoxPreference checkBox, final PreferenceGroup group) { final SwitchPreference switchPref = new SwitchPreference(checkBox.getContext()); switchPref.setTitle(checkBox.getTitle()); switchPref.setKey(checkBox.getKey()); switchPref.setOrder(checkBox.getOrder()); switchPref.setPersistent(checkBox.isPersistent()); switchPref.setEnabled(checkBox.isEnabled()); switchPref.setChecked(checkBox.isChecked()); switchPref.setSummary(checkBox.getSummary()); switchPref.setSummaryOn(checkBox.getSummaryOn()); switchPref.setSummaryOff(checkBox.getSummaryOff()); switchPref.setSwitchTextOn(EMPTY_TEXT); switchPref.setSwitchTextOff(EMPTY_TEXT); group.addPreference(switchPref);//from ww w . j av a2s . c om switchPref.setDependency(checkBox.getDependency()); }
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 ava 2s. c o m*/ 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); } }