List of usage examples for android.preference CheckBoxPreference setSummary
public void setSummary(CharSequence summary)
From source file:com.esminis.server.library.activity.DrawerFragment.java
protected CheckBoxPreference createPreferenceCheckbox(Context context, String key, boolean defaultValue, @StringRes int title, @StringRes int summary) { final CheckBoxPreference preference = new CheckBoxPreference(context); preference.setTitle(title);/* w ww . jav a2 s .c om*/ preference.setDefaultValue(defaultValue); preference.setSummary(summary); preference.setKey(key); return preference; }
From source file:com.mattprecious.notisync.preferences.DevicePreferenceFragment.java
@Override public void onResume() { super.onResume(); BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter(); if (btAdapter == null) { return;//from ww w .ja v a 2 s . c om } PreferenceScreen screen = getPreferenceScreen(); screen.removeAll(); Set<String> selectedDevices = Preferences.getDevices(getActivity()); // Get a set of currently paired devices Set<BluetoothDevice> pairedDevices = btAdapter.getBondedDevices(); for (BluetoothDevice device : pairedDevices) { CheckBoxPreference preference = new CheckBoxPreference(getActivity()); preference.setOnPreferenceChangeListener(preferenceListener); preference.setTitle(device.getName()); preference.setSummary(device.getAddress()); int iconResId = Helpers.getBtClassDrawable(device); if (iconResId != 0) { preference.setIcon(iconResId); } if (selectedDevices.contains(device.getAddress())) { preference.setDefaultValue(true); localDeviceSet.add(device.getAddress()); } getPreferenceScreen().addPreference(preference); } }
From source file:nya.miku.wishmaster.api.AbstractWakabaModule.java
@Override public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) { Context context = preferenceGroup.getContext(); addPasswordPreference(preferenceGroup); if (canHttps()) { CheckBoxPreference httpsPref = new CheckBoxPreference(context); httpsPref.setTitle(R.string.pref_use_https); httpsPref.setSummary(R.string.pref_use_https_summary); httpsPref.setKey(getSharedKey(PREF_KEY_USE_HTTPS)); httpsPref.setDefaultValue(useHttpsDefaultValue()); preferenceGroup.addPreference(httpsPref); addUnsafeSslPreference(preferenceGroup, getSharedKey(PREF_KEY_USE_HTTPS)); }//from w w w . j a v a2 s . c o m addProxyPreferences(preferenceGroup); }
From source file:com.harshad.linconnectclient.ApplicationSettingsActivity.java
private void setupSimplePreferencesScreen() { addPreferencesFromResource(R.xml.pref_application); applicationCategory = (PreferenceCategory) findPreference("header_application"); // Listen for check/uncheck all tap findPreference("pref_all").setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override//from w w w . j a v a 2 s . co m public boolean onPreferenceChange(Preference arg0, Object arg1) { for (int i = 0; i < applicationCategory.getPreferenceCount(); i++) { // Uncheck or check all items ((CheckBoxPreference) (applicationCategory.getPreference(i))).setChecked((Boolean) arg1); } return true; } }); class ApplicationTask extends AsyncTask<String, Void, List<ApplicationInfo>> { private PackageManager packageManager; @Override protected void onPreExecute() { progressDialog = ProgressDialog.show(ApplicationSettingsActivity.this, null, "Loading...", true); } @Override protected List<ApplicationInfo> doInBackground(String... notif) { packageManager = getApplicationContext().getPackageManager(); // Comparator used to sort applications by name class CustomComparator implements Comparator<ApplicationInfo> { @Override public int compare(ApplicationInfo arg0, ApplicationInfo arg1) { return arg0.loadLabel(packageManager).toString() .compareTo(arg1.loadLabel(packageManager).toString()); } } // Get installed applications Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); List<ApplicationInfo> appList = getApplicationContext().getPackageManager() .getInstalledApplications(PackageManager.GET_META_DATA); // Sort by application name Collections.sort(appList, new CustomComparator()); return appList; } @Override protected void onPostExecute(List<ApplicationInfo> result) { // Add each application to screen for (ApplicationInfo appInfo : result) { CheckBoxPreference c = new CheckBoxPreference(ApplicationSettingsActivity.this); c.setTitle(appInfo.loadLabel(packageManager).toString()); c.setSummary(appInfo.packageName); c.setIcon(appInfo.loadIcon(packageManager)); c.setKey(appInfo.packageName); c.setChecked(true); c.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference arg0, Object arg1) { // On tap, show an enabled/disabled notification on the desktop Object[] notif = new Object[3]; if (arg1.toString().equals("true")) { notif[0] = arg0.getTitle().toString() + " notifications enabled"; notif[1] = "via LinConnect"; notif[2] = arg0.getIcon(); } else { notif[0] = arg0.getTitle().toString() + " notifications disabled"; notif[1] = "via LinConnect"; notif[2] = arg0.getIcon(); } new TestTask().execute(notif); return true; } }); applicationCategory.addPreference(c); } progressDialog.dismiss(); } } new ApplicationTask().execute(); }
From source file:org.teleportr.activity.Autocompletion.java
/** Called when the activity is first created. */ @Override/* ww w . ja v a 2 s . co m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setTitle(getString(R.string.downloads_activity_titel)); getPreferenceManager().setSharedPreferencesName("autocompletion"); setPreferenceScreen(getPreferenceManager().createPreferenceScreen(this)); File dir = new File(Environment.getExternalStorageDirectory().getPath() + "/teleporter"); if (!dir.exists()) dir.mkdir(); final Map<String, ?> vals = getPreferenceManager().getSharedPreferences().getAll(); if (vals.isEmpty() && dir.list().length > 0) Toast.makeText(this, getString(R.string.inform_sdcard), Toast.LENGTH_LONG).show(); // clean up (autocompletion downloads deleted on sdcard) getPreferenceManager().getSharedPreferences().edit().clear().commit(); for (String file : dir.list()) { CheckBoxPreference c = new CheckBoxPreference(this); getPreferenceScreen().addItemFromInflater(c); c.setKey(file); c.setTitle(file.split("_")[0]); c.setSummary(file.substring(file.indexOf("_") + 1, file.lastIndexOf("."))); if (vals.containsKey(file)) { c.setChecked((Boolean) vals.get(file)); } } if (getPreferenceScreen().getPreferenceCount() == 0) new FetchNearbyDownloads().execute(""); }
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..."; }//w w w .java 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); } }
From source file:nya.miku.wishmaster.api.AbstractChanModule.java
/** * ( ?/ ) -? " SSL"/* w w w .jav a 2s. c om*/ * @param group , ??? * @param dependencyKey -?? ? , null */ protected void addUnsafeSslPreference(PreferenceGroup group, String dependencyKey) { final Context context = group.getContext(); CheckBoxPreference unsafeSslPref = new CheckBoxPreference(context); //? " SSL" unsafeSslPref.setTitle(R.string.pref_ignore_ssl_errors); unsafeSslPref.setSummary(R.string.pref_ignore_ssl_errors_summary); unsafeSslPref.setKey(getSharedKey(PREF_KEY_UNSAFE_SSL)); unsafeSslPref.setDefaultValue(false); unsafeSslPref.setOnPreferenceChangeListener(updateHttpListener); group.addPreference(unsafeSslPref); if (dependencyKey != null) unsafeSslPref.setDependency(dependencyKey); }
From source file:com.guipenedo.pokeradar.activities.settings.PokemonFilterSettingsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { getDelegate().installViewFactory();//w w w . ja va 2 s . c om getDelegate().onCreate(savedInstanceState); super.onCreate(savedInstanceState); PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(this); PreferenceCategory category = new PreferenceCategory(this); category.setTitle(R.string.filter_pokemons); screen.addPreference(category); try { JSONArray pokemonList = new JSONArray(Utils.loadJSONFromFile(this, "pokemon.json")); for (int i = 0; i < pokemonList.length(); i++) { JSONObject pokemon = pokemonList.getJSONObject(i); CheckBoxPreference checkBox = new CheckBoxPreference(this); checkBox.setTitle(pokemon.getString("Name")); checkBox.setIcon(new BitmapDrawable(getResources(), Utils.bitmapForPokemon(this, Integer.parseInt(pokemon.getString("Number"))))); checkBox.setDefaultValue(true); checkBox.setSummary(String.format(getString(R.string.setting_filter_pokemon_summary), pokemon.getString("Name"))); checkBox.setKey("pref_key_show_pokemon_" + Integer.parseInt(pokemon.getString("Number"))); category.addPreference(checkBox); } } catch (JSONException e) { e.printStackTrace(); } setPreferenceScreen(screen); }
From source file:nya.miku.wishmaster.chans.nullchancc.NullchanccModule.java
private void addOnlyNewPostsPreference(PreferenceGroup group) { Context context = group.getContext(); CheckBoxPreference onlyNewPostsPreference = new CheckBoxPreference(context); onlyNewPostsPreference.setTitle(R.string.nullchancc_prefs_only_new_posts); onlyNewPostsPreference.setSummary(R.string.nullchancc_prefs_only_new_posts_summary); onlyNewPostsPreference.setKey(getSharedKey(PREF_KEY_ONLY_NEW_POSTS)); onlyNewPostsPreference.setDefaultValue(true); group.addItemFromInflater(onlyNewPostsPreference); }