List of usage examples for android.content SharedPreferences getBoolean
boolean getBoolean(String key, boolean defValue);
From source file:Main.java
@SuppressWarnings("unchecked") public static <T> T getPref(Context _context, String prefKey, T defValue, Class<T> clazz) { final SharedPreferences pref = getDefaultSharedPreferences(_context); if (Long.class == clazz) { return (T) (Long.valueOf(pref.getLong(prefKey, (Long) defValue))); } else if (Integer.class == clazz) { return (T) (Integer.valueOf(pref.getInt(prefKey, (Integer) defValue))); } else if (defValue instanceof String) { return (T) (pref.getString(prefKey, String.valueOf(defValue))); } else if (defValue instanceof Boolean) { return (T) (Boolean.valueOf(pref.getBoolean(prefKey, (Boolean) defValue))); }/*from w w w .jav a2 s .c o m*/ throw new UnsupportedOperationException("Class " + clazz + " not supported"); }
From source file:it.scoppelletti.mobilepower.app.HelpDialogFragment.java
/** * Verifica se un’attività ha già visualizzato una * Guida./* ww w .j a v a2 s. co m*/ * * @param activity Attività. * @param prefKey Chiave della preferenza che indica se la Guida è * già stata visualizzata. * @return Esito della verifica. */ public static boolean isShown(Activity activity, String prefKey) { SharedPreferences prefs; if (activity == null) { throw new NullPointerException("Argument activity is null."); } if (StringUtils.isBlank(prefKey)) { throw new NullPointerException("Argument prefKey is null."); } prefs = activity.getPreferences(Context.MODE_PRIVATE); return prefs.getBoolean(prefKey, false); }
From source file:com.atinternet.tracker.LifeCycle.java
/** * Init lifecycle//from w w w . j a v a 2s .c o m * * @param context Context */ static void initLifeCycle(Context context) { SharedPreferences preferences = Tracker.getPreferences(); try { versionCode = String.valueOf(context.getPackageManager() .getPackageInfo(context.getApplicationContext().getPackageName(), 0).versionCode); // Not first session if (!preferences.getBoolean(FIRST_SESSION, true) || preferences.getBoolean("ATFirstInitLifecycleDone", false)) { newSessionInit(preferences); } else { SharedPreferences backwardPreferences = context.getSharedPreferences("ATPrefs", Context.MODE_PRIVATE); firstSessionInit(preferences, backwardPreferences); } } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } preferences.edit().putBoolean("ATFirstInitLifecycleDone", true).apply(); isInitialized = true; }
From source file:com.lewen.listener.vlc.Util.java
public static void updateLibVlcSettings(SharedPreferences pref) { LibVLC instance = LibVLC.getExistingInstance(); if (instance == null) return;/*from w w w . jav a 2 s . c om*/ instance.setIomx(pref.getBoolean("enable_iomx", false)); instance.setSubtitlesEncoding(pref.getString("subtitles_text_encoding", "")); instance.setTimeStretching(pref.getBoolean("enable_time_stretching_audio", false)); instance.setFrameSkip(pref.getBoolean("enable_frame_skip", false)); instance.setChroma(pref.getString("chroma_format", "")); instance.setVerboseMode(pref.getBoolean("enable_verbose_mode", true)); if (pref.getBoolean("equalizer_enabled", false)) instance.setEqualizer(getFloatArray(pref, "equalizer_values")); int aout; try { aout = Integer.parseInt(pref.getString("aout", "-1")); } catch (NumberFormatException nfe) { aout = -1; } int vout; try { vout = Integer.parseInt(pref.getString("vout", "-1")); } catch (NumberFormatException nfe) { vout = -1; } int deblocking; try { deblocking = Integer.parseInt(pref.getString("deblocking", "-1")); } catch (NumberFormatException nfe) { deblocking = -1; } int networkCaching = pref.getInt("network_caching_value", 0); if (networkCaching > 60000) networkCaching = 60000; else if (networkCaching < 0) networkCaching = 0; instance.setAout(aout); instance.setVout(vout); instance.setDeblocking(deblocking); instance.setNetworkCaching(networkCaching); }
From source file:net.peterkuterna.android.apps.devoxxsched.service.SyncService.java
/** * Should we perform a remote sync?//from ww w . j a v a 2 s . co m */ private static boolean performRemoteSync(ContentResolver resolver, HttpClient httpClient, Intent intent, Context context) { final SharedPreferences settingsPrefs = context.getSharedPreferences(SettingsActivity.SETTINGS_NAME, MODE_PRIVATE); final SharedPreferences syncServicePrefs = context.getSharedPreferences(SyncPrefs.DEVOXXSCHED_SYNC, Context.MODE_PRIVATE); final boolean onlySyncWifi = settingsPrefs.getBoolean(context.getString(R.string.sync_only_wifi_key), false); final int localVersion = syncServicePrefs.getInt(SyncPrefs.LOCAL_VERSION, VERSION_NONE); if (!onlySyncWifi || isWifiConnected(context)) { final boolean remoteParse = localVersion < VERSION_REMOTE; final boolean forceRemoteRefresh = intent.getBooleanExtra(EXTRA_FORCE_REFRESH, false); final boolean hasContentChanged = hasContentChanged(resolver, httpClient); return remoteParse || forceRemoteRefresh || hasContentChanged; } return false; }
From source file:de.itomig.itoplib.ItopConfig.java
public static String getItopUrl() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(itopAppContext); String url = (prefs.getString(KEY_URL, DEMO_URL)).trim(); if ((url.length() > 3) && (url.charAt(url.length() - 1) == '/')) { // remove trailing slash in url, if there is one url = url.substring(0, url.length() - 1); }/* ww w.j a va2s . co m*/ boolean ssl_enabled = prefs.getBoolean(KEY_SSL, DEMO_SSL); if (ssl_enabled) { return "https://" + url; } else { return "http://" + url; } }
From source file:com.keylesspalace.tusky.util.NotificationManager.java
private static void setupPreferences(SharedPreferences preferences, NotificationCompat.Builder builder) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { return; //do nothing on Android O or newer, the system uses the channel settings anyway }// w w w . ja va 2 s. c om if (preferences.getBoolean("notificationAlertSound", true)) { builder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI); } if (preferences.getBoolean("notificationAlertVibrate", false)) { builder.setVibrate(new long[] { 500, 500 }); } if (preferences.getBoolean("notificationAlertLight", false)) { builder.setLights(0xFF00FF8F, 300, 1000); } }
From source file:com.atinternet.tracker.LifeCycle.java
/** * Get the object which contains lifecycle metrics * * @return Closure//from w w w .j ava 2 s . c om */ static Closure getMetrics(final SharedPreferences preferences) { return new Closure() { @Override public String execute() { try { LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>(); // fs map.put("fs", preferences.getBoolean(FIRST_SESSION, false) ? 1 : 0); // fsau map.put("fsau", preferences.getBoolean(FIRST_SESSION_AFTER_UPDATE, false) ? 1 : 0); if (!TextUtils.isEmpty(preferences.getString(FIRST_SESSION_DATE_AFTER_UPDATE, ""))) { map.put("scsu", preferences.getInt(SESSION_COUNT_SINCE_UPDATE, 0)); map.put("fsdau", Integer.parseInt(preferences.getString(FIRST_SESSION_DATE_AFTER_UPDATE, ""))); map.put("dsu", preferences.getInt(DAYS_SINCE_UPDATE, 0)); } map.put("sc", preferences.getInt(SESSION_COUNT, 0)); map.put("fsd", Integer.parseInt(preferences.getString(FIRST_SESSION_DATE, ""))); map.put("dsls", preferences.getInt(DAYS_SINCE_LAST_SESSION, 0)); map.put("dsfs", preferences.getInt(DAYS_SINCE_FIRST_SESSION, 0)); map.put("sessionId", sessionId); return new JSONObject().put("lifecycle", new JSONObject(map)).toString(); } catch (JSONException e) { e.printStackTrace(); } return ""; } }; }
From source file:com.fairmichael.fintan.websms.connector.fishtext.ConnectorFishtext.java
private static String getLogin(final Context context, final ConnectorCommand command) { final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context); final String login = p.getBoolean(PREFS_LOGIN_WTIH_DEFAULT, false) ? command.getDefSender() : Utils.getSender(context, command.getDefSender()); return login; }
From source file:Main.java
public static Object getData(Context context, String fileName, String key, Class clazz) { SharedPreferences sharedPreferences = context.getSharedPreferences(fileName, Context.MODE_PRIVATE); if (clazz.getName().equals(String.class.getName())) { return sharedPreferences.getString(key, ""); } else if (clazz.getName().equals(Integer.class.getName())) { return sharedPreferences.getInt(key, 0); } else if (clazz.getName().equals(Float.class.getName())) { return sharedPreferences.getFloat(key, 0); } else if (clazz.getName().equals(Long.class.getName())) { return sharedPreferences.getLong(key, 0); } else {//from w w w . j a va2 s.c o m return sharedPreferences.getBoolean(key, false); } }