List of usage examples for android.content SharedPreferences getString
@Nullable String getString(String key, @Nullable String defValue);
From source file:de.itomig.itoplib.ItopConfig.java
public static BasicNameValuePair getItopUserNameValuePair() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(itopAppContext); String login = prefs.getString(KEY_LOGIN, DEMO_LOGIN).trim(); return new BasicNameValuePair("auth_user", login); }
From source file:dk.moerks.ratebeermobile.io.TwitterPoster.java
/** * Build a TwitterPoster based on the user preferences * @param context The application context to get the user preferences from * @return A reusable TwitterPoster object *//*from w w w . ja va 2s .c om*/ public static TwitterPoster buildFromPreferences(Context context) { // Retrieve the Twitter user credentials from the application preferences SharedPreferences settings = context.getSharedPreferences(Settings.PREFERENCETAG, 0); // And return the Twitter poster object instance return new TwitterPoster(settings.getString("rb_twitter_username", ""), settings.getString("rb_twitter_password", "")); }
From source file:com.radadev.xkcd.Comics.java
public static final Date getLastUpdate(Context context) { SharedPreferences info = context.getSharedPreferences("info", Context.MODE_WORLD_WRITEABLE); String dateString = info.getString(KEY_LAST_UPDATE, null); return (dateString != null) ? new Date(dateString) : null; }
From source file:de.itomig.itoplib.ItopConfig.java
public static BasicNameValuePair getItopPwdNameValuePair() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(itopAppContext); String password = prefs.getString(KEY_PASSWORD, DEMO_PASSWORD).trim(); return new BasicNameValuePair("auth_pwd", password); }
From source file:de.itomig.itoplib.ItopConfig.java
public static String getItopCredentials() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(itopAppContext); String login = prefs.getString(KEY_LOGIN, DEMO_LOGIN).trim(); String password = prefs.getString(KEY_PASSWORD, DEMO_PASSWORD).trim(); return "auth_user=" + login + "&auth_pwd=" + password; }
From source file:com.apptentive.android.sdk.storage.DeviceManager.java
public static CustomData loadIntegrationConfig(Context context) { SharedPreferences prefs = context.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE); String integrationConfigString = prefs.getString(Constants.PREF_KEY_DEVICE_INTEGRATION_CONFIG, null); try {/* w ww. j a v a 2s . c o m*/ return new CustomData(integrationConfigString); } catch (Exception e) { // Ignore } try { return new CustomData(); } catch (JSONException e) { // Ignore } return null; // This should never happen. }
From source file:es.wolfi.passman.API.Core.java
/** * Check if the user has logged in, also sets up the API * @param c The context where this should be run * @param toast Whether we want or not a toast! Yum! * @param cb The callback//from ww w . j av a2 s . c o m */ public static void checkLogin(final Context c, final boolean toast, final FutureCallback<Boolean> cb) { SingleTon ton = SingleTon.getTon(); if (ton.getString(SettingValues.HOST.toString()) == null) { SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(c); String url = settings.getString(SettingValues.HOST.toString(), null); // If the url is null app has not yet been configured! if (url == null) { cb.onCompleted(null, false); return; } // Load the server settings ton.addString(SettingValues.HOST.toString(), url); ton.addString(SettingValues.USER.toString(), settings.getString(SettingValues.USER.toString(), "")); ton.addString(SettingValues.PASSWORD.toString(), settings.getString(SettingValues.PASSWORD.toString(), "")); } String host = ton.getString(SettingValues.HOST.toString()); String user = ton.getString(SettingValues.USER.toString()); String pass = ton.getString(SettingValues.PASSWORD.toString()); Toast.makeText(c, host, Toast.LENGTH_LONG).show(); Log.d(LOG_TAG, "Host: " + host); Log.d(LOG_TAG, "User: " + user); Log.d(LOG_TAG, "Pass: " + pass); Vault.setUpAPI(host, user, pass); Vault.getVaults(c, new FutureCallback<HashMap<String, Vault>>() { @Override public void onCompleted(Exception e, HashMap<String, Vault> result) { boolean ret = true; if (e != null) { if (e.getMessage().equals("401")) { if (toast) Toast.makeText(c, c.getString(R.string.wrongNCSettings), Toast.LENGTH_LONG).show(); ret = false; } else if (e.getMessage().contains("Unable to resolve host") || e.getMessage().contains("Invalid URI")) { if (toast) Toast.makeText(c, c.getString(R.string.wrongNCUrl), Toast.LENGTH_LONG).show(); ret = false; } else { Log.e(LOG_TAG, "Error: " + e.getMessage(), e); if (toast) Toast.makeText(c, c.getString(R.string.net_error) + ": " + e.getMessage(), Toast.LENGTH_LONG).show(); ret = false; } } cb.onCompleted(e, ret); } }); }
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); }//from www .ja v a2s .c o m boolean ssl_enabled = prefs.getBoolean(KEY_SSL, DEMO_SSL); if (ssl_enabled) { return "https://" + url; } else { return "http://" + url; } }
From source file:com.ilearnrw.reader.utils.HttpHelper.java
public static boolean refreshTokens(Context context) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); String refreshToken = preferences.getString(context.getString(R.string.sp_refreshToken), ""); if (refreshToken.isEmpty()) return false; HttpResponse refreshResponse = HttpHelper .get("https://ssl.ilearnrw.eu/ilearnrw/user/newtokens?refresh=" + refreshToken); ArrayList<String> refreshData = HttpHelper.handleResponse(refreshResponse); if (refreshData == null) return false; if (refreshData.size() > 1) { try {//w w w .ja v a2 s. co m TokenResult lr = new Gson().fromJson(refreshData.get(1), TokenResult.class); SharedPreferences.Editor editor = preferences.edit(); editor.putString(context.getString(R.string.sp_authToken), lr.authToken); editor.putString(context.getString(R.string.sp_refreshToken), lr.refreshToken); editor.apply(); return true; } catch (Exception e) { e.printStackTrace(); return false; } } else { Log.e("Error", refreshData.get(0)); } return false; }
From source file:com.apptentive.android.sdk.model.CodePointStore.java
private static CodePointStore load(SharedPreferences prefs) { String json = prefs.getString(Constants.PREF_KEY_CODE_POINT_STORE, null); try {// w w w.j a v a 2 s. c om if (json != null) { return new CodePointStore(json); } } catch (JSONException e) { Log.e("Error loading CodePointStore from SharedPreferences.", e); } return new CodePointStore(); }