List of usage examples for android.preference CheckBoxPreference CheckBoxPreference
public CheckBoxPreference(Context context)
From source file:com.guipenedo.pokeradar.activities.settings.PokemonFilterSettingsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { getDelegate().installViewFactory();//from w w w. j a v a2 s . com 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:com.mattprecious.notisync.preferences.DevicePreferenceFragment.java
@Override public void onResume() { super.onResume(); BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter(); if (btAdapter == null) { return;/*from w ww . j a v a2s . c o m*/ } 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:org.teleportr.activity.Autocompletion.java
/** Called when the activity is first created. */ @Override/*www . jav a2 s . c o 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: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 . j ava 2 s . c om preference.setDefaultValue(defaultValue); preference.setSummary(summary); preference.setKey(key); return preference; }
From source file:net.freifunk.android.discover.SettingsActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.pref_data_sync); // get data via the key ArrayList<NodeMap> nodeMapArrayList = new ArrayList<NodeMap>(MapMaster.getInstance().getMaps().values()); PreferenceCategory communities = (PreferenceCategory) findPreference("communities"); // sort by Name Collections.sort(nodeMapArrayList, new NodeMapComparator()); if (nodeMapArrayList != null && communities != null) { for (final NodeMap nm : nodeMapArrayList) { PreferenceScreen communityPreferenceScreen = getPreferenceManager() .createPreferenceScreen(SettingsActivity.this); communityPreferenceScreen.setTitle(nm.getMapName()); communityPreferenceScreen.setKey(nm.getMapName()); final CheckBoxPreference deactivateCommunityPreference = new CheckBoxPreference( SettingsActivity.this); // TODO: move Strings to resources deactivateCommunityPreference.setTitle("Community aktiv"); deactivateCommunityPreference .setSummary("deaktivieren, falls Community nicht auf der Karte angezeigt werden soll"); deactivateCommunityPreference.setKey("community_deactivate_" + nm.getMapName()); deactivateCommunityPreference.setChecked(nm.isActive()); deactivateCommunityPreference .setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Database db = Database.getInstance(null); boolean newActive = newValue.toString().equals("true") ? true : false; nm.setActive(newActive); db.addNodeMap(nm); // reload if set to active if (newActive) { nm.loadNodes(); } else { nm.updateNodes(); }/*from w ww . ja v a2 s . c o m*/ return true; } }); EditTextPreference editCommunityPreference = new EditTextPreference(SettingsActivity.this); // TODO: move Strings to resources editCommunityPreference.setTitle("URL bearbeiten"); editCommunityPreference.setSummary("aendern, falls eine andere Quelle genutzt werden soll."); editCommunityPreference.setKey("community_edit_" + nm.getMapName()); editCommunityPreference.setText(nm.getMapUrl()); editCommunityPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Database db = Database.getInstance(null); // remove old nodes from map nm.setActive(false); EventBus.getInstance().post(new NodeResult(NodeResult.NodeResultType.UPDATE_NODES, nm)); // we should probably do this async as well db.deleteAllNodesForMap(nm); // load new nodes NodeMap newMap = new NodeMap(nm.getMapName(), (String) newValue, true); db.addNodeMap(newMap); //HashMap<String, NodeMap> nodeResult = new HashMap<String, NodeMap>(1); //nodeResult.put(nm.getMapName(), nm); newMap.updateNodes(); //EventBus.getInstance().post(new NodeResult(NodeResult.NodeResultType.LOAD_NODES, nm)); //EventBus.getInstance().post(new NodeResult(NodeResult.NodeResultType.UPDATE_MAP, nodeResult)); return true; } }); communityPreferenceScreen.addPreference(deactivateCommunityPreference); communityPreferenceScreen.addPreference(editCommunityPreference); communities.addPreference(communityPreferenceScreen); } } setupActionBar(); }
From source file:de.badaix.snapcast.GroupSettingsFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Load the preferences from an XML resource addPreferencesFromResource(R.xml.group_preferences); PreferenceScreen screen = this.getPreferenceScreen(); prefStreams = (ListPreference) findPreference("pref_stream"); Bundle bundle = getArguments();/* ww w.ja v a2 s . c o m*/ try { group = new Group(new JSONObject(bundle.getString("group"))); serverStatus = new ServerStatus(new JSONObject(bundle.getString("serverStatus"))); } catch (JSONException e) { e.printStackTrace(); } final ArrayList<Stream> streams = serverStatus.getStreams(); final CharSequence[] streamNames = new CharSequence[streams.size()]; final CharSequence[] streamIds = new CharSequence[streams.size()]; for (int i = 0; i < streams.size(); ++i) { streamNames[i] = streams.get(i).getName(); streamIds[i] = streams.get(i).getId(); } prefStreams.setEntries(streamNames); prefStreams.setEntryValues(streamIds); for (int i = 0; i < streams.size(); ++i) { if (streamIds[i].equals(group.getStreamId())) { prefStreams.setTitle(streamNames[i]); prefStreams.setValueIndex(i); oldStream = prefStreams.getValue(); break; } } prefStreams.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { for (int i = 0; i < streams.size(); ++i) { if (streamIds[i].equals(newValue)) { prefStreams.setTitle(streamNames[i]); // client.getConfig().setStream(streamIds[i].toString()); prefStreams.setValueIndex(i); break; } } return false; } }); prefCatClients = (PreferenceCategory) findPreference("pref_cat_clients"); ArrayList<CheckBoxPreference> allClients = new ArrayList<>(); for (Group g : serverStatus.getGroups()) { for (Client client : g.getClients()) { CheckBoxPreference checkBoxPref = new CheckBoxPreference(screen.getContext()); checkBoxPref.setKey(client.getId()); checkBoxPref.setTitle(client.getVisibleName()); checkBoxPref.setChecked(g.getId().equals(group.getId())); checkBoxPref.setPersistent(false); allClients.add(checkBoxPref); } } Collections.sort(allClients, new Comparator<CheckBoxPreference>() { @Override public int compare(CheckBoxPreference lhs, CheckBoxPreference rhs) { return lhs.getTitle().toString().compareToIgnoreCase(rhs.getTitle().toString()); } }); for (CheckBoxPreference pref : allClients) prefCatClients.addPreference(pref); oldClients = getClients().toString(); }
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 . ja v a 2s .c o 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:com.rareventure.gps2.reviewer.SettingsActivity.java
private void createPreferenceHierarchy() { PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this); this.setPreferenceScreen(root); isCollectData = new CheckBoxPreference(this); isCollectData.setTitle(R.string.collect_gps_data); isCollectData.setSummary(R.string.collect_gps_data_desc); root.addPreference(isCollectData);/*from w w w . j av a 2s .c om*/ isCollectData.setOnPreferenceClickListener(this); percTimeGpsOn = new SeekBarDialogPreference(this, getText(R.string.title_perc_time_gps_on), getText(R.string.desc_perc_time_gps_on), getResources().getInteger(R.dimen.perc_time_gps_on_min_value), getResources().getInteger(R.dimen.perc_time_gps_on_max_value), getResources().getInteger(R.dimen.perc_time_gps_on_steps), getResources().getInteger(R.dimen.perc_time_gps_on_log_scale), getText(R.string.seekbar_perc_printf_format).toString(), null); percTimeGpsOn.setOnPreferenceChangeListener(this); root.addPreference(percTimeGpsOn); minBatteryLife = new SeekBarDialogPreference(this, getText(R.string.title_min_battery_life_perc), getText(R.string.desc_min_battery_life_perc), getResources().getInteger(R.dimen.min_battery_level_min_value), getResources().getInteger(R.dimen.min_battery_level_max_value), getResources().getInteger(R.dimen.min_battery_level_steps), getResources().getInteger(R.dimen.min_battery_level_log_scale), getText(R.string.seekbar_perc_printf_format).toString(), null); minBatteryLife.setOnPreferenceChangeListener(this); root.addPreference(minBatteryLife); enableToolTips = new CheckBoxPreference(this); enableToolTips.setTitle(R.string.enable_tooltips); enableToolTips.setKey("enable_tooltips"); root.addPreference(enableToolTips); enableToolTips.setOnPreferenceClickListener(this); useMetricUnits = new CheckBoxPreference(this); useMetricUnits.setTitle(R.string.use_metric_units); useMetricUnits.setChecked(GTG.prefs.useMetric); root.addPreference(useMetricUnits); //note that we can't use setIntent() for these preferences, since that would // be interpreted as an outside action causing us to lose the password is set flag colorblindSettings = getPreferenceManager().createPreferenceScreen(this); // screenPref.setKey("screen_preference"); // colorblindSettings.setIntent(new Intent(this, ChooseColorsScreen.class)); colorblindSettings.setTitle(R.string.colorblind_title); colorblindSettings.setSummary(R.string.colorblind_summary); colorblindSettings.setOnPreferenceClickListener(this); root.addPreference(colorblindSettings); mapFontSize = new SeekBarDialogPreference(this, getText(R.string.title_map_font_size), getText(R.string.desc_map_font_size), getResources().getInteger(R.dimen.map_font_size_min_value), getResources().getInteger(R.dimen.map_font_size_max_value), getResources().getInteger(R.dimen.map_font_size_steps), getResources().getInteger(R.dimen.map_font_size_log_scale), "%1.0f", null); mapFontSize.setOnPreferenceChangeListener(this); root.addPreference(mapFontSize); enablePassword = new CheckBoxPreference(this); enablePassword.setTitle(R.string.enable_password); enablePassword.setKey("enable_password"); root.addPreference(enablePassword); enablePassword.setOnPreferenceClickListener(this); changePassword = new Preference(this); changePassword.setTitle(R.string.change_password); root.addPreference(changePassword); changePassword.setDependency("enable_password"); changePassword.setOnPreferenceClickListener(this); passwordTimeout = new SeekBarDialogPreference(this, getText(R.string.title_password_timeout), getText(R.string.desc_password_timeout), 0, passwordTimeoutStrs.length - 1, passwordTimeoutStrs.length, 0, null, new SeekBarWithText.CustomUpdateTextView() { @Override public String updateText(float value) { return passwordTimeoutStrs[(int) value]; } }); passwordTimeout.setOnPreferenceChangeListener(this); root.addPreference(passwordTimeout); createBackupFilePref = getPreferenceManager().createPreferenceScreen(this); createBackupFilePref.setTitle(R.string.create_backup_pref); root.addPreference(createBackupFilePref); createBackupFilePref.setOnPreferenceClickListener(this); restoreBackupFilePref = getPreferenceManager().createPreferenceScreen(this); restoreBackupFilePref.setTitle(R.string.restore_backup_pref); root.addPreference(restoreBackupFilePref); restoreBackupFilePref.setOnPreferenceClickListener(this); allowErrorReporting = new CheckBoxPreference(this); allowErrorReporting.setTitle(R.string.allow_error_reporting); allowErrorReporting.setSummary(R.string.allow_error_reporting_summary); allowErrorReporting.setChecked(GTG.isAcraEnabled(this)); root.addPreference(allowErrorReporting); aboutPref = getPreferenceManager().createPreferenceScreen(this); aboutPref.setOnPreferenceClickListener(this); aboutPref.setTitle(R.string.about); root.addPreference(aboutPref); PreferenceCategory advancedCategory = new PreferenceCategory(this); advancedCategory.setTitle("Advanced"); root.addPreference(advancedCategory); writeGpsWakeLockDebugFile = new CheckBoxPreference(this); writeGpsWakeLockDebugFile.setTitle(R.string.write_to_gps_wake_lock_log); writeGpsWakeLockDebugFile.setSummary(String.format(getString(R.string.write_to_gps_wake_lock_log_summary), getString(R.string.gps_wake_lock_filename))); writeGpsWakeLockDebugFile.setChecked(GTG.prefs.writeGpsWakeLockDebug); writeGpsWakeLockDebugFile.setOnPreferenceClickListener(this); advancedCategory.addPreference(writeGpsWakeLockDebugFile); }
From source file:nya.miku.wishmaster.chans.incah.InachModule.java
@Override public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) { Context context = preferenceGroup.getContext(); CheckBoxPreference ajaxPref = new CheckBoxPreference(context); ajaxPref.setTitle(R.string.inach_prefs_ajax_update); ajaxPref.setSummary(R.string.inach_prefs_ajax_update_summary); ajaxPref.setKey(getSharedKey(PREF_AJAX_UPDATE)); ajaxPref.setDefaultValue(true);/*from w w w . j a va 2 s .co m*/ preferenceGroup.addPreference(ajaxPref); super.addPreferencesOnScreen(preferenceGroup); }