List of usage examples for android.content SharedPreferences getString
@Nullable String getString(String key, @Nullable String defValue);
From source file:key.secretkey.utils.PasswordStorage.java
public static File getRepositoryDirectory(Context context) { File dir = null;/*from w w w . j a v a 2s . co m*/ SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()); if (settings.getBoolean("git_external", false)) { String external_repo = settings.getString("git_external_repo", null); if (external_repo != null) { dir = new File(external_repo); } } else { dir = new File(context.getFilesDir() + "/store"); } return dir; }
From source file:io.v.android.apps.syncslides.SignInActivity.java
/** * Returns the best-effort email of the signed-in user. *//*from w w w . ja va 2s .c om*/ public static String getUserEmail(Context ctx) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx); return prefs.getString(PREF_USER_ACCOUNT_NAME, ""); }
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))); }/* w ww.ja va 2 s . com*/ throw new UnsupportedOperationException("Class " + clazz + " not supported"); }
From source file:ch.fixme.status.Widget.java
protected static void setAlarm(Context ctxt, Intent i, int widgetId, int delay) { // Get interval SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctxt); long update_interval = Long .parseLong(prefs.getString(Prefs.KEY_CHECK_INTERVAL, Prefs.DEFAULT_CHECK_INTERVAL)) * 60L * 1000L; // Set alarm/*from w w w. j a v a 2 s .co m*/ AlarmManager am = (AlarmManager) ctxt.getSystemService(Context.ALARM_SERVICE); PendingIntent pi = PendingIntent.getService(ctxt, widgetId, i, 0); am.cancel(pi); am.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + delay, update_interval, pi); // Log.i(Main.TAG, "start notification every " + update_interval / 1000 // + "s"); }
From source file:no.ntnu.wifimanager.ServerUtilities.java
/** * Register this account/device pair within the server. * * @return whether the registration succeeded or not. */// w w w. j ava 2 s .co m public static boolean register(final Context context, final String regId) { Log.i(LOG_TAG, "registering device (regId = " + regId + ")"); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); String userId = preferences.getString("email", "NA"); Map<String, String> params = new HashMap<String, String>(); params.put("regId", regId); params.put("userId", userId); long backoff = BACKOFF_MILLI_SECONDS + random.nextInt(1000); // Once GCM returns a registration id, we need to register it in the // demo server. As the server might be down, we will retry it a couple // times. for (int i = 1; i <= MAX_ATTEMPTS; i++) { Log.d(LOG_TAG, "Attempt #" + i + " to register"); try { displayMessage(context, context.getString(R.string.server_registering, i, MAX_ATTEMPTS)); HTTPpost(URL_REGISTER_APP_FOR_GCM, params, HTTP_CONTENT_TYPE_URL_ENCODED); GCMRegistrar.setRegisteredOnServer(context, true); String message = context.getString(R.string.server_registered); CommonUtilities.displayMessage(context, message); return true; } catch (IOException e) { // Here we are simplifying and retrying on any error; in a real // application, it should retry only on unrecoverable errors // (like HTTP error code 503). Log.e(LOG_TAG, "Failed to register on attempt " + i, e); if (i == MAX_ATTEMPTS) { break; } try { Log.d(LOG_TAG, "Sleeping for " + backoff + " ms before retry"); Thread.sleep(backoff); } catch (InterruptedException e1) { // Activity finished before we complete - exit. Log.d(LOG_TAG, "Thread interrupted: abort remaining retries!"); Thread.currentThread().interrupt(); return false; } // increase backoff exponentially backoff *= 2; } } String message = context.getString(R.string.server_register_error, MAX_ATTEMPTS); CommonUtilities.displayMessage(context, message); return false; }
From source file:dk.moerks.ratebeermobile.io.NetBroker.java
private static void signin(Context context, DefaultHttpClient httpclient) throws NetworkException, LoginException { HttpPost httppost = new HttpPost("http://www.ratebeer.com/signin/"); Log.d(LOGTAG, "Before Try"); try {//ww w . ja v a 2 s .c o m SharedPreferences settings = context.getSharedPreferences(Settings.PREFERENCETAG, 0); String username = settings.getString("rb_username", ""); String password = settings.getString("rb_password", ""); if (username != null && password != null && username.length() > 0 && password.length() > 0) { Log.d(LOGTAG, "Building Login Request"); // Add your data List<NameValuePair> parameters = new ArrayList<NameValuePair>(); parameters.add(new BasicNameValuePair("SaveInfo", "on")); parameters.add(new BasicNameValuePair("username", username)); parameters.add(new BasicNameValuePair("pwd", password)); httppost.setEntity(new UrlEncodedFormEntity(parameters)); //Check to see if we are already logged in List<Cookie> beforeCookies = httpclient.getCookieStore().getCookies(); for (Iterator<Cookie> iterator = beforeCookies.iterator(); iterator.hasNext();) { Cookie cookie = iterator.next(); if (cookie.getName().equalsIgnoreCase("SessionCode")) { return; } } Log.d(LOGTAG, "Executing Login Request"); // Execute HTTP Post Request HttpResponse result = httpclient.execute(httppost); int statusCode = result.getStatusLine().getStatusCode(); Log.d(LOGTAG, "Validating we got the right status from server: " + statusCode); if (statusCode == 200) { List<Cookie> cookies = httpclient.getCookieStore().getCookies(); Log.d(LOGTAG, "Start Validating Cookies. List length: " + cookies.size()); for (Iterator<Cookie> iterator = cookies.iterator(); iterator.hasNext();) { Cookie cookie = iterator.next(); Log.d(LOGTAG, "Matching Cookie: " + cookie.getName()); if (cookie.getName().equalsIgnoreCase("SessionCode")) { result.getEntity().consumeContent(); return; } } throw new LoginException(LOGTAG, "Login to ratebeer.com failed. Check your credentials"); } else { throw new LoginException(LOGTAG, "Login to ratebeer.com failed. Check your credentials"); } } else { throw new LoginException(LOGTAG, "Login to ratebeer.com failed. Check your credentials"); } } catch (ClientProtocolException e) { } catch (IOException e) { throw new NetworkException(context, LOGTAG, "Network Error - Do you have a network connection?", e); } }
From source file:ee.ioc.phon.android.speak.Utils.java
public static String getUniqueId(SharedPreferences settings) { String id = settings.getString("id", null); if (id == null) { id = UUID.randomUUID().toString(); SharedPreferences.Editor editor = settings.edit(); editor.putString("id", id); editor.commit();/*w w w . ja v a2s.c o m*/ } return id; }
From source file:Main.java
public static String getWhitelist(SharedPreferences prefs, String languageCode) { if (languageCode.equals("ara")) { return prefs.getString(KEY_CHARACTER_WHITELIST_ARABIC, getDefaultWhitelist(languageCode)); } // Arabic/* w ww .j a v a 2 s . c o m*/ else if (languageCode.equals("bul")) { return prefs.getString(KEY_CHARACTER_WHITELIST_BULGARIAN, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("cat")) { return prefs.getString(KEY_CHARACTER_WHITELIST_CATALAN, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("chi_sim")) { return prefs.getString(KEY_CHARACTER_WHITELIST_CHINESE_SIMPLIFIED, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("chi_tra")) { return prefs.getString(KEY_CHARACTER_WHITELIST_CHINESE_TRADITIONAL, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("ces")) { return prefs.getString(KEY_CHARACTER_WHITELIST_CZECH, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("dan")) { return prefs.getString(KEY_CHARACTER_WHITELIST_DANISH, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("nld")) { return prefs.getString(KEY_CHARACTER_WHITELIST_DUTCH, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("eng")) { return prefs.getString(KEY_CHARACTER_WHITELIST_ENGLISH, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("fin")) { return prefs.getString(KEY_CHARACTER_WHITELIST_FINNISH, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("fra")) { return prefs.getString(KEY_CHARACTER_WHITELIST_FRENCH, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("deu")) { return prefs.getString(KEY_CHARACTER_WHITELIST_GERMAN, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("ell")) { return prefs.getString(KEY_CHARACTER_WHITELIST_GREEK, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("heb")) { return prefs.getString(KEY_CHARACTER_WHITELIST_HEBREW, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("hin")) { return prefs.getString(KEY_CHARACTER_WHITELIST_HINDI, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("hun")) { return prefs.getString(KEY_CHARACTER_WHITELIST_HUNGARIAN, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("ind")) { return prefs.getString(KEY_CHARACTER_WHITELIST_INDONESIAN, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("ita")) { return prefs.getString(KEY_CHARACTER_WHITELIST_ITALIAN, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("jpn")) { return prefs.getString(KEY_CHARACTER_WHITELIST_JAPANESE, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("kor")) { return prefs.getString(KEY_CHARACTER_WHITELIST_KOREAN, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("lav")) { return prefs.getString(KEY_CHARACTER_WHITELIST_LATVIAN, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("lit")) { return prefs.getString(KEY_CHARACTER_WHITELIST_LITHUANIAN, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("nor")) { return prefs.getString(KEY_CHARACTER_WHITELIST_NORWEGIAN, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("pol")) { return prefs.getString(KEY_CHARACTER_WHITELIST_POLISH, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("por")) { return prefs.getString(KEY_CHARACTER_WHITELIST_PORTUGUESE, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("ron")) { return prefs.getString(KEY_CHARACTER_WHITELIST_ROMANIAN, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("rus")) { return prefs.getString(KEY_CHARACTER_WHITELIST_RUSSIAN, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("srp")) { return prefs.getString(KEY_CHARACTER_WHITELIST_SERBIAN, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("slk")) { return prefs.getString(KEY_CHARACTER_WHITELIST_SLOVAK, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("slv")) { return prefs.getString(KEY_CHARACTER_WHITELIST_SLOVENIAN, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("spa")) { return prefs.getString(KEY_CHARACTER_WHITELIST_SPANISH, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("swe")) { return prefs.getString(KEY_CHARACTER_WHITELIST_SWEDISH, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("tgl")) { return prefs.getString(KEY_CHARACTER_WHITELIST_TAGALOG, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("tha")) { return prefs.getString(KEY_CHARACTER_WHITELIST_THAI, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("tur")) { return prefs.getString(KEY_CHARACTER_WHITELIST_TURKISH, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("ukr")) { return prefs.getString(KEY_CHARACTER_WHITELIST_UKRAINIAN, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("vie")) { return prefs.getString(KEY_CHARACTER_WHITELIST_VIETNAMESE, getDefaultWhitelist(languageCode)); } else { throw new IllegalArgumentException(); } }
From source file:Main.java
public static String getBlacklist(SharedPreferences prefs, String languageCode) { if (languageCode.equals("ara")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_ARABIC, getDefaultBlacklist(languageCode)); } // Arabic//from ww w.jav a 2s .c o m else if (languageCode.equals("bul")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_BULGARIAN, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("cat")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_CATALAN, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("chi_sim")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_CHINESE_SIMPLIFIED, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("chi_tra")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_CHINESE_TRADITIONAL, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("ces")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_CZECH, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("dan")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_DANISH, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("nld")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_DUTCH, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("eng")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_ENGLISH, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("fin")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_FINNISH, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("fra")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_FRENCH, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("deu")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_GERMAN, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("ell")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_GREEK, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("heb")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_HEBREW, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("hin")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_HINDI, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("hun")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_HUNGARIAN, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("ind")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_INDONESIAN, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("ita")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_ITALIAN, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("jpn")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_JAPANESE, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("kor")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_KOREAN, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("lav")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_LATVIAN, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("lit")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_LITHUANIAN, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("nor")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_NORWEGIAN, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("pol")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_POLISH, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("por")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_PORTUGUESE, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("ron")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_ROMANIAN, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("rus")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_RUSSIAN, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("srp")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_SERBIAN, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("slk")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_SLOVAK, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("slv")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_SLOVENIAN, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("spa")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_SPANISH, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("swe")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_SWEDISH, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("tgl")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_TAGALOG, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("tha")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_THAI, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("tur")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_TURKISH, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("ukr")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_UKRAINIAN, getDefaultBlacklist(languageCode)); } else if (languageCode.equals("vie")) { return prefs.getString(KEY_CHARACTER_BLACKLIST_VIETNAMESE, getDefaultBlacklist(languageCode)); } else { throw new IllegalArgumentException(); } }
From source file:com.apptentive.android.sdk.module.messagecenter.ApptentiveMessageCenter.java
public static void clearPendingMessageCenterPushNotification(Activity activity) { SharedPreferences prefs = activity.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE); String pushData = prefs.getString(Constants.PREF_KEY_PENDING_PUSH_NOTIFICATION, null); if (pushData != null) { try {/*w w w. j ava2 s. c om*/ JSONObject pushJson = new JSONObject(pushData); ApptentiveInternal.PushAction action = ApptentiveInternal.PushAction.unknown; if (pushJson.has(ApptentiveInternal.PUSH_ACTION)) { action = ApptentiveInternal.PushAction .parse(pushJson.getString(ApptentiveInternal.PUSH_ACTION)); } switch (action) { case pmc: Log.i("Clearing pending Message Center push notification."); prefs.edit().remove(Constants.PREF_KEY_PENDING_PUSH_NOTIFICATION).commit(); break; } } catch (JSONException e) { Log.w("Error parsing JSON from push notification.", e); MetricModule.sendError(activity.getApplicationContext(), e, "Parsing Push notification", pushData); } } }