List of usage examples for android.preference CheckBoxPreference setKey
public void setKey(String key)
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(); }
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);//from w w w. ja va 2s . co m preference.setDefaultValue(defaultValue); preference.setSummary(summary); preference.setKey(key); return preference; }
From source file:org.teleportr.activity.Autocompletion.java
/** Called when the activity is first created. */ @Override/*from w w w . j a va 2 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:de.tum.in.tumcampus.fragments.SettingsFragment.java
private void populateNewsSources() { PreferenceCategory news_sources = (PreferenceCategory) findPreference("card_news_sources"); NewsManager cm = new NewsManager(mContext); Cursor cur = cm.getNewsSources(); if (cur.moveToFirst()) { do {// ww w . j a v a2s .co m final CheckBoxPreference pref = new CheckBoxPreference(mContext); pref.setKey("card_news_source_" + cur.getString(0)); pref.setDefaultValue(true); if (Build.VERSION.SDK_INT >= 11) { // Load news source icon in background and set it final String url = cur.getString(1); new Thread(new Runnable() { @Override public void run() { NetUtils net = new NetUtils(mContext); final Bitmap bmp = net.downloadImageToBitmap(url); mContext.runOnUiThread(new Runnable() { @TargetApi(11) @Override public void run() { pref.setIcon(new BitmapDrawable(getResources(), bmp)); } }); } }).start(); } pref.setTitle(cur.getString(2)); news_sources.addPreference(pref); } while (cur.moveToNext()); } cur.close(); }
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 ww w. j a v a 2 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 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:nya.miku.wishmaster.api.AbstractChanModule.java
/** * ( ?/ ) -? " SSL"//from ww w. java 2s . com * @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:nya.miku.wishmaster.api.AbstractChanModule.java
/** * ( ?/ ) ? ?-?// w ww . j a va 2 s . c om * @param group , ??? */ protected void addProxyPreferences(PreferenceGroup group) { final Context context = group.getContext(); PreferenceCategory proxyCat = new PreferenceCategory(context); //? ? ? proxyCat.setTitle(R.string.pref_cat_proxy); group.addPreference(proxyCat); CheckBoxPreference useProxyPref = new CheckBoxPreference(context); //? "? ? " useProxyPref.setTitle(R.string.pref_use_proxy); useProxyPref.setSummary(R.string.pref_use_proxy_summary); useProxyPref.setKey(getSharedKey(PREF_KEY_USE_PROXY)); useProxyPref.setDefaultValue(false); useProxyPref.setOnPreferenceChangeListener(updateHttpListener); proxyCat.addPreference(useProxyPref); EditTextPreference proxyHostPref = new EditTextPreference(context); // ? ?-? proxyHostPref.setTitle(R.string.pref_proxy_host); proxyHostPref.setDialogTitle(R.string.pref_proxy_host); proxyHostPref.setSummary(R.string.pref_proxy_host_summary); proxyHostPref.setKey(getSharedKey(PREF_KEY_PROXY_HOST)); proxyHostPref.setDefaultValue(DEFAULT_PROXY_HOST); proxyHostPref.getEditText().setSingleLine(); proxyHostPref.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI); proxyHostPref.setOnPreferenceChangeListener(updateHttpListener); proxyCat.addPreference(proxyHostPref); proxyHostPref.setDependency(getSharedKey(PREF_KEY_USE_PROXY)); EditTextPreference proxyHostPort = new EditTextPreference(context); // ?-? proxyHostPort.setTitle(R.string.pref_proxy_port); proxyHostPort.setDialogTitle(R.string.pref_proxy_port); proxyHostPort.setSummary(R.string.pref_proxy_port_summary); proxyHostPort.setKey(getSharedKey(PREF_KEY_PROXY_PORT)); proxyHostPort.setDefaultValue(DEFAULT_PROXY_PORT); proxyHostPort.getEditText().setSingleLine(); proxyHostPort.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER); proxyHostPort.setOnPreferenceChangeListener(updateHttpListener); proxyCat.addPreference(proxyHostPort); proxyHostPort.setDependency(getSharedKey(PREF_KEY_USE_PROXY)); }
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); }