List of usage examples for android.preference CheckBoxPreference setPersistent
public void setPersistent(boolean persistent)
From source file:com.adam.aslfms.MusicAppsActivity.java
private void update() { mSupportedMusicAppsList.removeAll(); mPrefsToMapisMap.clear();/*from w ww . j a v a2s .co m*/ mMapisToPrefsMap.clear(); MusicAPI[] mapis = MusicAPI.all(this); for (MusicAPI mapi : mapis) { CheckBoxPreference appPref = new CheckBoxPreference(this, null); appPref.setTitle(mapi.getName()); appPref.setPersistent(false); appPref.setChecked(mapi.isEnabled()); mSupportedMusicAppsList.addPreference(appPref); mPrefsToMapisMap.put(appPref, mapi); mMapisToPrefsMap.put(mapi, appPref); setSMASummary(appPref, mapi); } // explanation text, for what this screen does Preference detect = new Preference(this); if (mapis.length == 0) detect.setTitle(R.string.no_supported_mapis_title); else if (mapis.length == 1) detect.setTitle(R.string.find_supported_mapis_one_title); else detect.setTitle(getString(R.string.find_supported_mapis_many_title).replace("%1", Integer.toString(mapis.length))); detect.setSummary(R.string.find_supported_mapis_summary); mSupportedMusicAppsList.addPreference(detect); }
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();// w w w. j av a 2 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(); }