@Test public void shouldGiveSharedPreferences() throws Exception { Activity activity = Robolectric.setupActivity(Activity.class); SharedPreferences preferences = activity.getPreferences(Context.MODE_PRIVATE); assertNotNull(preferences); preferences.edit().putString("foo", "bar").commit(); assertThat(activity.getPreferences(Context.MODE_PRIVATE).getString("foo", null)).isEqualTo("bar"); }
@Override public android.content.SharedPreferences getPreferences(int int0) { return mOriginActivity.getPreferences(int0); }
/** * @param mode * @return * @see android.app.Activity#getPreferences(int) */ public SharedPreferences getPreferences(int mode) { return mActivity.getPreferences(mode); }
public Preferences(Activity activity) { prefs = activity.getPreferences(Activity.MODE_PRIVATE); }
public void broadcastIntent(View v){ Activity activity = (Activity) view.getContext() SharedPreferences sharedPref = activity.getPreferences(Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPref.edit(); editor.putString("xx",x); editor.commit(); Intent i=new Intent("android.intent.action.AIRPLANE_MODE"); sendBroadcast(i); }
public void onClick(DialogInterface dialog, int index) { // Store the answer in SharedPreferences SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPref.edit(); editor.putBoolean( OpenFitActivity.OpenFitFragment.PREFERENCE_SKIP_CHANGELOG_KEY, dontShowAgain.isChecked()); editor.apply(); } });
void storePersistent() { SharedPreferences sharedPreferences = context.getPreferences(Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString("dropboxPersistent", dropbox.get().saveAsString()); editor.putString("boxPersistent", box.get().saveAsString()); editor.putString("googledrivePersistent", googledrive.get().saveAsString()); editor.putString("onedrivePersistent", onedrive.get().saveAsString()); editor.putString("onedrivebusinessPersistent", googledrive.get().saveAsString()); editor.putString("egnytePersistent", onedrive.get().saveAsString()); editor.apply(); } }
public static String checkVersionAndShowWhatsNewIfNeeded(Activity activity) { try { PackageInfo info = Utils.getPackageInfo(activity); SharedPreferences preferences = activity.getPreferences(0); int newVersionCode = info.versionCode; int oldVersionCode = preferences.getInt("versionCode", -1); if (newVersionCode > oldVersionCode) { preferences.edit().putInt("versionCode", newVersionCode).commit(); showWhatsNew(activity); } return "v. "+info.versionName; } catch(Exception ex) { return "Free"; } }
private Observable<AppInfo> getApps() { return Observable.create(subscriber -> { List<AppInfo> apps = new ArrayList<>(); SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE); Type appInfoType = new TypeToken<List<AppInfo>>() { }.getType(); String serializedApps = sharedPref.getString("APPS", ""); if (!"".equals(serializedApps)) { apps = new Gson().fromJson(serializedApps, appInfoType); } for (AppInfo app : apps) { subscriber.onNext(app); } subscriber.onCompleted(); }); } }
public static void addToMap(Activity activity, MapView mapView) throws IOException, JSONException { /** * Deal with SharedPreferences. Use it if we haven't explicitly loaded. Set it if we have. */ SharedPreferences preferences = activity.getPreferences(Context.MODE_PRIVATE); if (fpGeoJson == null) { String previousFpGeoJsonPath = preferences.getString(PREVIOUS_FP_FILE_PATH, null); if (previousFpGeoJsonPath == null) return; load(new File(previousFpGeoJsonPath)); } else { SharedPreferences.Editor editor = preferences.edit(); editor.putString(PREVIOUS_FP_FILE_PATH, fpGeoJson.getAbsolutePath()); editor.apply(); } if (atlas == null) return; atlas.setActivity(activity); atlas.setupMapView(mapView); }
private void storeList(List<AppInfo> appInfos) { ApplicationsList.getInstance().setList(appInfos); Schedulers.io().createWorker().schedule(() -> { SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE); Type appInfoType = new TypeToken<List<AppInfo>>() { }.getType(); sharedPref.edit().putString("APPS", new Gson().toJson(appInfos, appInfoType)).apply(); }); }
prefs = ((Activity) context).getPreferences( preferencesMode.value()); break;
private void showChangelog(){ SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE); // Check if the changelog has to be skipped (ie "Don't show again" has been checked) boolean skipChangelog = sharedPref.getBoolean(PREFERENCE_SKIP_CHANGELOG_KEY, false); // Get versionCode numbers of the app (current and last) int lastVersion = sharedPref.getInt(PREFERENCE_LAST_VERSION_KEY, 0); int thisVersion = BuildConfig.VERSION_CODE; // Reinit skipChangelog if the app has been updated since last start (or first start) if(thisVersion != lastVersion){ SharedPreferences.Editor sharedPrefEditor = sharedPref.edit(); // Reinitialize the skipChangelog preference skipChangelog = false; sharedPrefEditor.putBoolean(PREFERENCE_SKIP_CHANGELOG_KEY, false); // Set last version sharedPrefEditor.putInt(PREFERENCE_LAST_VERSION_KEY, thisVersion); sharedPrefEditor.apply(); } if(!skipChangelog) { // load news DialogNews d = new DialogNews(); d.show(getFragmentManager(), getString(R.string.dialog_title_news)); } }
void prepare(Activity context) { this.context = context; CloudRail.setAppKey(CLOUDRAIL_LICENSE_KEY); this.initDropbox(); this.initBox(); this.initGoogleDrive(); this.initOneDrive(); this.initOneDriveBusiness(); this.initEgnyte(); SharedPreferences sharedPreferences = context.getPreferences(Context.MODE_PRIVATE); try { String persistent = sharedPreferences.getString("dropboxPersistent", null); if (persistent != null) dropbox.get().loadAsString(persistent); persistent = sharedPreferences.getString("boxPersistent", null); if (persistent != null) box.get().loadAsString(persistent); persistent = sharedPreferences.getString("googledrivePersistent", null); if (persistent != null) googledrive.get().loadAsString(persistent); persistent = sharedPreferences.getString("onedrivePersistent", null); if (persistent != null) onedrive.get().loadAsString(persistent); persistent = sharedPreferences.getString("onedrivebusinessPersistent", null); if (persistent != null) onedrivebusiness.get().loadAsString(persistent); persistent = sharedPreferences.getString("egnytePersistent", null); if (persistent != null) egnyte.get().loadAsString(persistent); } catch (ParseException e) {} }
final SharedPreferences sharedPref = mActivity.getPreferences(Context.MODE_PRIVATE); final String currentServer = sharedPref.getString(getString(R.string.saved_server_ip), "https://github.com/jboss-outreach"); final EditTextPreference mPreference = (EditTextPreference) findPreference("server_location");