List of usage examples for android.preference PreferenceManager createPreferenceScreen
public PreferenceScreen createPreferenceScreen(Context context)
From source file:com.colossaldb.dnd.ui.DebugFragment.java
/** * Get the past actions performed./* ww w. j a v a2s .c o m*/ */ Preference getPast(PreferenceManager preferenceManager) { PreferenceScreen past = preferenceManager.createPreferenceScreen(getActivity()); if (past == null) return failedPreference("Failed to create past"); past.setTitle(R.string.past); JSONArray events = AppPreferences.getInstance().getDebugEvents(); addEventsToPreferenceScreen(past, events); return past; }
From source file:com.colossaldb.dnd.ui.DebugFragment.java
/** * Get the errors.//from w w w .j a va 2s. c o m */ Preference getErrors(PreferenceManager preferenceManager) { PreferenceScreen errors = preferenceManager.createPreferenceScreen(getActivity()); if (errors == null) return failedPreference("Failed to create errors"); errors.setTitle(R.string.errors); JSONArray events = AppPreferences.getInstance().getErrorEvents(); addEventsToPreferenceScreen(errors, events); return errors; }
From source file:com.colossaldb.dnd.ui.DebugFragment.java
/** * Future scheduled events (and related information - if available) *//* www . j a v a 2 s . c o m*/ Preference getFuture(PreferenceManager preferenceManager) { PreferenceScreen future = preferenceManager.createPreferenceScreen(getActivity()); if (future == null) return failedPreference("Failed to create future"); future.setTitle(R.string.future); Preference nextEvent = new Preference(getActivity()); nextEvent.setTitle("Next Schedule Run"); nextEvent.setSummary(AppPreferences.getInstance().getNextScheduleRun()); future.addPreference(nextEvent); return future; }
From source file:com.colossaldb.dnd.ui.DebugFragment.java
/** * Current debug information for display *///from ww w . j ava 2s . co m Preference getPresent(PreferenceManager preferenceManager) { PreferenceScreen present = preferenceManager.createPreferenceScreen(getActivity()); if (present == null) return failedPreference("Failed to create present"); present.setTitle(R.string.present); AppPreferences pref = AppPreferences.getInstance(); Preference enabled = new Preference(getActivity()); enabled.setTitle(R.string.enabled); enabled.setSummary("" + pref.isEnabled()); present.addPreference(enabled); Preference startTime = new Preference(getActivity()); startTime.setTitle(R.string.start); startTime.setSummary(pref.getFormattedStartTime()); present.addPreference(startTime); Preference endTime = new Preference(getActivity()); endTime.setTitle(R.string.end); endTime.setSummary(pref.getFormattedEndTime()); present.addPreference(endTime); Preference ringForContacts = new Preference(getActivity()); ringForContacts.setTitle(R.string.contacts); ringForContacts.setSummary("" + pref.ringForContacts()); present.addPreference(ringForContacts); Preference ringOnRepeat = new Preference(getActivity()); ringOnRepeat.setTitle(R.string.repeat_on_ring); ringOnRepeat.setSummary("" + pref.ringOnRepeatCall()); present.addPreference(ringOnRepeat); // Add the current state // Did the user change volume? // Did we sent the ringer volume? return present; }
From source file:info.balthaus.geologrenewed.app.ui.SettingsFragment.java
@Override protected PreferenceScreen createPreferenceHierarchy(PreferenceManager prefMan) { PreferenceScreen root = prefMan.createPreferenceScreen(getActivity()); resources = getActivity().getResources(); prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); String app = APP_TITLE;//w ww. j a va 2 s . com PackageManager pm = getActivity().getPackageManager(); if (pm != null) { try { PackageInfo pi = pm.getPackageInfo(getActivity().getPackageName(), 0); if (pi != null) { app = app + " v" + pi.versionName; } } catch (Exception e) { } } Preference copyright = new Preference(getActivity()); copyright.setTitle(app); copyright.setSummary(APP_COPYRIGHT + (char) 10 + "Twitter: @ChainfireXDA" + (char) 10 + "G+: http://google.com/+Chainfire" + (char) 10 + S(R.string.settings_tap_xda)); copyright.setKey("copyright"); copyright.setEnabled(true); copyright.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { try { Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(APP_WEBSITE_URL)); startActivity(i); } catch (Exception e) { // no http handler installed (wtf, it happens) } return false; } }); root.addPreference(copyright); /* maybe one day if (!proPresent) { Preference upgrade = new Preference(getActivity()); upgrade.setTitle(R.string.settings_upgrade); upgrade.setSummary(R.string.settings_upgrade_description); upgrade.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { try { Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse("market://details?id=eu.chainfire.geolog.pro")); startActivity(i); } catch (Exception e) { // no market installed } return false; } }); root.addPreference(upgrade); } */ PreferenceCategory catUnits = Pref.Category(getActivity(), root, R.string.settings_category_units); prefUnits = Pref.List(getActivity(), catUnits, getString(R.string.settings_units_caption), "", getString(R.string.settings_units_popup), PREF_UNITS, PREF_UNITS_DEFAULT, new String[] { getString(R.string.settings_units_metric), getString(R.string.settings_units_imperial) }, new String[] { VALUE_UNITS_METRIC, VALUE_UNITS_IMPERIAL }); PreferenceCategory catMarket = Pref.Category(getActivity(), root, R.string.settings_category_market); Pref.Preference(getActivity(), catMarket, R.string.settings_market, R.string.settings_market_description, true, new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { try { Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse("market://search?q=pub:Chainfire")); startActivity(i); } catch (Exception e) { // market not installed } return false; } }); Pref.Preference(getActivity(), catMarket, R.string.follow_pref_title, R.string.follow_pref_desc, true, new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { showFollow(false); return false; } }); int shown_follow = prefs.getInt(PREF_FOLLOW_SHOWN, 0); if (shown_follow == 0) { prefs.edit().putInt(PREF_FOLLOW_SHOWN, 1).commit(); showFollow(true); } updatePrefs(null); return root; }
From source file:eu.chainfire.geolog.ui.SettingsFragment.java
@Override protected PreferenceScreen createPreferenceHierarchy(PreferenceManager prefMan) { PreferenceScreen root = prefMan.createPreferenceScreen(getActivity()); resources = getActivity().getResources(); prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); String app = APP_TITLE;/*from w w w. ja v a 2 s. com*/ PackageManager pm = getActivity().getPackageManager(); if (pm != null) { try { PackageInfo pi = pm.getPackageInfo(getActivity().getPackageName(), 0); if (pi != null) { app = app + " v" + pi.versionName; } } catch (Exception e) { } } Preference copyright = new Preference(getActivity()); copyright.setTitle(app); copyright.setSummary(APP_COPYRIGHT + (char) 10 + "Twitter: @ChainfireXDA" + (char) 10 + "G+: http://google.com/+Chainfire" + (char) 10 + S(R.string.settings_tap_xda)); copyright.setKey("copyright"); copyright.setEnabled(true); copyright.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { try { Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(APP_WEBSITE_URL)); startActivity(i); } catch (Exception e) { // no http handler installed (wtf, it happens) } return false; } }); root.addPreference(copyright); /* maybe one day if (!proPresent) { Preference upgrade = new Preference(getActivity()); upgrade.setTitle(R.string.settings_upgrade); upgrade.setSummary(R.string.settings_upgrade_description); upgrade.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { try { Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse("market://details?id=eu.chainfire.geolog.pro")); startActivity(i); } catch (Exception e) { // no market installed } return false; } }); root.addPreference(upgrade); } */ PreferenceCategory catUnits = Pref.Category(getActivity(), root, R.string.settings_category_units); prefUnits = Pref.List(getActivity(), catUnits, getString(R.string.settings_units_caption), "", getString(R.string.settings_units_popup), PREF_UNITS, PREF_UNITS_DEFAULT, new String[] { getString(R.string.settings_units_metric), getString(R.string.settings_units_imperial) }, new String[] { VALUE_UNITS_METRIC, VALUE_UNITS_IMPERIAL }); PreferenceCategory catMarket = Pref.Category(getActivity(), root, R.string.settings_category_market); Pref.Preference(getActivity(), catMarket, R.string.settings_market, R.string.settings_market_description, true, new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { try { Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse("market://search?q=pub:Chainfire")); startActivity(i); } catch (Exception e) { // market not installed } return false; } }); Pref.Preference(getActivity(), catMarket, R.string.follow_pref_title, R.string.follow_pref_desc, true, new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { showFollow(false); return false; } }); int shown_follow = prefs.getInt(PREF_FOLLOW_SHOWN, 0); if (shown_follow == 0) { prefs.edit().putInt(PREF_FOLLOW_SHOWN, 1).commit(); showFollow(true); } updatePrefs(null); return root; }
From source file:net.basilwang.StaticAttachmentActivity.java
private void reloadData(PreferenceCategory logonPreference, PreferenceScreen logonAddPreference, PreferenceManager preferenceManager) { // 2012-11-23 basilwang refresh tabbar title refreshActionBarTitle();//from ww w . j a v a 2 s. c om logonPreference.removeAll(); logonPreference.addPreference(logonAddPreference); int accountId = PreferenceManager.getDefaultSharedPreferences(this) .getInt(LOGON_ACCOUNT_ID, 0); AccountService service = new AccountService(this); List<Account> list = service.getAccounts(); if (list.size() == 0) { logonAddPreference.setEnabled(true); } else { logonAddPreference.setEnabled(false); for (Account account : list) { PreferenceScreen preferenceItem = preferenceManager .createPreferenceScreen(this); // CheckBoxPreference checkBoxPreference = new // CheckBoxPreference(this); // make sure each key is unique preferenceItem.setKey(LOGON_ACCOUNT_PREFERENCES); preferenceItem.setTitle(PreferenceUtils.getPreferUserName(this)); if (accountId == account.getId()) preferenceItem.setSummary(R.string.already_checked); // preferenceItem.setChecked(false); // checkBoxPreference.setDisableDependentsState(disableDependentsState) // checkBoxPreference.setSelectable(false); preferenceItem.setOrder(0); preferenceItem.setOnPreferenceClickListener(this); logonPreference.addPreference(preferenceItem); } } }
From source file:de.ub0r.android.callmeter.ui.prefs.PreferencesPlain.java
private void loadRules() { new AsyncTask<Void, Void, JSONObject>() { @Override/*from w w w.ja v a2 s.com*/ protected JSONObject doInBackground(final Void... params) { try { String l; StringBuilder sb = new StringBuilder(); File f = new File(PreferencesPlain.this.getCacheDir(), "ub0rrules.json"); if (f.exists() && f.lastModified() + CACHE_TIMEOUT > System.currentTimeMillis()) { Log.i(TAG, "found cached data: " + f.getAbsolutePath()); BufferedReader r = new BufferedReader(new FileReader(f)); while ((l = r.readLine()) != null) { sb.append(l); } r.close(); } if (sb.length() == 0) { if (f.exists()) { f.delete(); } HttpURLConnection c = (HttpURLConnection) new URL( "http://ub0r.de/android/callmeter/rulesets/rulesets.json").openConnection(); Log.i(TAG, "load new data: " + c.getURL()); BufferedReader r = new BufferedReader(new InputStreamReader(c.getInputStream())); FileWriter w = new FileWriter(f); while ((l = r.readLine()) != null) { sb.append(l); w.write(l); } r.close(); w.close(); } try { return new JSONObject(sb.toString()); } catch (JSONException e) { Log.e(TAG, "JSON Error", e); Log.e(TAG, "JSON: " + sb.toString()); return null; } } catch (IOException e) { Log.e(TAG, "IOError", e); } return null; } @SuppressWarnings({ "deprecation", "rawtypes" }) @Override protected void onPostExecute(final JSONObject result) { if (result == null) { Toast.makeText(PreferencesPlain.this, R.string.err_export_read, Toast.LENGTH_LONG).show(); return; } PreferenceGroup base = (PreferenceGroup) PreferencesPlain.this.findPreference("import_rules_users"); PreferenceManager pm = base.getPreferenceManager(); // delete old base.removeAll(); base = (PreferenceGroup) PreferencesPlain.this.findPreference("import_rules_base"); // build list ArrayList<String> keys = new ArrayList<String>(result.length()); Iterator it = result.keys(); while (it.hasNext()) { keys.add(it.next().toString()); } Collections.sort(keys); keys.remove("common"); keys.add(0, "common"); OnPreferenceClickListener opcl = new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(final Preference preference) { Intent intent = new Intent(PreferencesPlain.this, PreferencesRules.class); intent.putExtra(PreferencesRules.EXTRA_JSON, result.toString()); intent.putExtra(PreferencesRules.EXTRA_COUNTRY, preference.getKey()); PreferencesPlain.this.startActivity(intent); return true; } }; for (String k : keys) { PreferenceScreen p = pm.createPreferenceScreen(PreferencesPlain.this); p.setPersistent(false); p.setKey(k); p.setTitle(k); p.setOnPreferenceClickListener(opcl); base.addPreference(p); } } ; }.execute((Void) null); }