Java Code Examples for android.app.Activity#getSharedPreferences()
The following examples show how to use
android.app.Activity#getSharedPreferences() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AccomplishmentBox.java From FlappyCow with MIT License | 5 votes |
/** * marks the data as online * @param activity activity that is needed for shared preferences */ public static void savesAreOnline(Activity activity){ SharedPreferences saves = activity.getSharedPreferences(SAVE_NAME, 0); SharedPreferences.Editor editor = saves.edit(); editor.putBoolean(ONLINE_STATUS_KEY, true); editor.commit(); }
Example 2
Source File: AppRate.java From FireFiles with Apache License 2.0 | 5 votes |
public static AppRate with(Activity activity, ViewGroup viewGroup) { AppRate instance = new AppRate(activity, viewGroup); instance.text = "Enjoying the app? Spread the word!";//activity.getString(R.string.dra_rate_app); instance.settings = activity.getSharedPreferences(PREFS_NAME, 0); instance.editor = instance.settings.edit(); return instance; }
Example 3
Source File: AppRate.java From FireFiles with Apache License 2.0 | 5 votes |
public static AppRate with(Activity activity) { AppRate instance = new AppRate(activity); instance.text = "Enjoying the app? Spread the word!";//activity.getString(R.string.dra_rate_app); instance.settings = activity.getSharedPreferences(PREFS_NAME, 0); instance.editor = instance.settings.edit(); return instance; }
Example 4
Source File: AccomplishmentBox.java From FlappyCow with MIT License | 5 votes |
/** * marks the data as offline * @param activity activity that is needed for shared preferences */ public static void savesAreOffline(Activity activity){ SharedPreferences saves = activity.getSharedPreferences(SAVE_NAME, 0); SharedPreferences.Editor editor = saves.edit(); editor.putBoolean(ONLINE_STATUS_KEY, false); editor.commit(); }
Example 5
Source File: MainSettingsActivity.java From PretendSharing_Xposed with MIT License | 5 votes |
private static void writeXposedSP(Activity thisActivity){ SharedPreferences a = thisActivity.getSharedPreferences(thisActivity.getPackageName() + "_preferences", MODE_WORLD_READABLE); SharedPreferences b = thisActivity.getSharedPreferences("xposed", MODE_WORLD_READABLE); SharedPreferences.Editor be = b.edit(); be.putString("package_settings",a.getString("package_settings","")); be.putString("xposed_mode",a.getString("xposed_mode","0")); be.putBoolean("enable_debug",a.getBoolean("enable_debug",false)); be.commit(); //防止系统销毁来不及保存怎么样 }
Example 6
Source File: SetThings.java From SystemUITuner2 with MIT License | 5 votes |
public SetThings(Activity activity) { //set all variables sharedPreferences = activity.getSharedPreferences(activity.getResources().getText(R.string.sharedprefs_id).toString(), Context.MODE_PRIVATE); editor = sharedPreferences.edit(); editor.apply(); Dark = sharedPreferences.getBoolean("isDark", false); setup = sharedPreferences.getBoolean("isSetup", false); exceptions = new Exceptions(); SDK_INT = Build.VERSION.SDK_INT; //noinspection deprecation titleText = activity.getResources().getColor(Dark ? android.R.color.primary_text_dark : android.R.color.primary_text_light); //noinspection deprecation,deprecation drawerItem = Dark ? activity.getResources().getColorStateList(R.color.drawer_item_dark) : activity.getResources().getColorStateList(R.color.drawer_item_light); // activity.setTheme(SetupActivity.class == activity.getClass() || NoRootSystemSettingsActivity.class == activity.getClass() ? Dark ? R.style.DARK : R.style.AppTheme : Dark ? R.style.DARK_NoAppBar : R.style.AppTheme_NoActionBar); activity.setTheme(Dark ? R.style.DARK : R.style.AppTheme); style = Dark ? R.style.DARK_NoAppBar : R.style.AppTheme_NoActionBar; //is dark mode on? pages = new ArrayList<Integer>() {{ //all (currently used) fragments add(R.id.nav_home); add(R.id.nav_statusbar); add(R.id.nav_demo_mode); add(R.id.nav_about); add(R.id.nav_settings); add(R.id.nav_misc); add(R.id.nav_quick_settings); add(R.id.nav_touchwiz); }}; currentActivity = activity; context = currentActivity; //kinda pointless... }
Example 7
Source File: OBPRestClient.java From Hello-OBP-OAuth1.0a-Android with Apache License 2.0 | 5 votes |
/** * @return true if the access token was loaded and set from shared * preferences */ public static boolean setAccessTokenFromSharedPrefs(Activity activity) { SharedPreferences settings = activity .getSharedPreferences(PREF_FILE, 0); String token = settings.getString(CONSUMER_TOKEN, PREF_NOT_SET); String secret = settings.getString(CONSUMER_SECRET, PREF_NOT_SET); boolean exists = !token.equals(PREF_NOT_SET) && !secret.equals(PREF_NOT_SET); // set it if it exists if (exists) consumer.setTokenWithSecret(token, secret); return exists; }
Example 8
Source File: AccessTokenStore.java From AvI with MIT License | 5 votes |
public static void storeAccessToken(Activity activity, com.auth0.core.Token accessToken){ SharedPreferences prefs = activity.getSharedPreferences(Constants.PREF_FILE_NAME, 0); SharedPreferences.Editor editor = prefs.edit(); editor.putString(PREF_AUTH_ACCESS_TOKEN, accessToken.getAccessToken()); editor.putString(PREF_AUTH_REFRESH_TOKEN, accessToken.getRefreshToken()); editor.putString(PREF_AUTH_ID_TOKEN, accessToken.getIdToken()); editor.commit(); }
Example 9
Source File: IntroActivity.java From SteamGifts with MIT License | 5 votes |
public static void showIntroIfNeccessary(Activity parentActivity, final String type, final int version) { SharedPreferences sp = parentActivity.getSharedPreferences("intro", MODE_PRIVATE); int lastSeenVersion = sp.getInt(type, 0); if (lastSeenVersion < version) { // Show the activity Intent intent = new Intent(parentActivity, IntroActivity.class); intent.putExtra("type", type); parentActivity.startActivity(intent); SharedPreferences.Editor spe = sp.edit(); spe.putInt(type, version); spe.apply(); } }
Example 10
Source File: MainApplication.java From NightOwl with Apache License 2.0 | 5 votes |
@Override public void onSkinChange(int mode, Activity activity) { SharedPreferences preferences = activity.getSharedPreferences("NightOwlDemo", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putInt("mode", mode); SharedPreferencesCompat.EditorCompat.getInstance().apply(editor); }
Example 11
Source File: Console.java From smartcard-reader with GNU General Public License v3.0 | 5 votes |
public Console(Activity activity, Bundle inState, int testMode, ListView listView, ViewSwitcher switcher) { mActivity = activity; mTestMode = testMode; mListView = listView; // persistent data in shared prefs SharedPreferences ss = activity.getSharedPreferences("prefs", Context.MODE_PRIVATE); mEditor = ss.edit(); mHandler = new Handler(); mMsgAdapter = new MessageAdapter(activity.getLayoutInflater(), inState, this); listView.setAdapter(mMsgAdapter); mSwitcher = switcher; if (switcher != null) { if (activity.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { // in landscape, switch to console messages and disable switching switcher.setDisplayedChild(VIEW_MESSAGES); mSwitcher = null; } else { if (mMsgAdapter.getCount() > 0) { switcher.setDisplayedChild(VIEW_MESSAGES); } } } }
Example 12
Source File: UserInfoStore.java From AvI with MIT License | 5 votes |
public static Location getLocation(Activity activity){ SharedPreferences prefs = activity.getSharedPreferences(Constants.PREF_FILE_NAME, 0); double latitude = Double.longBitsToDouble( prefs.getLong(PREF_USER_LOCATION_LAT, Double.doubleToRawLongBits(44.8149028))); double longitude = Double.longBitsToDouble( prefs.getLong(PREF_USER_LOCATION_LON, Double.doubleToRawLongBits(20.1424149))); Location retVal = new Location("User_Location"); retVal.setLatitude(latitude); retVal.setLongitude(longitude); return retVal; }
Example 13
Source File: RCTUpdateMgr.java From react-native-update with MIT License | 5 votes |
public RCTUpdateMgr(Activity activity) { this.activity = activity; this.context = activity.getApplicationContext(); documentFilePath = activity.getFilesDir().getAbsolutePath()+"/"; mainBundleFilePath = documentFilePath+MAIN_BUNDLE_FILE; PackageInfo pInfo = null; try { pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); appVersion = pInfo.versionName; buildVersion = pInfo.versionCode; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } settings = activity.getSharedPreferences(PREF_LOCAL_STORAGE, Activity.MODE_PRIVATE); String lastversionCode = settings.getString("APK_VERSION_CODE", "0"); if (!lastversionCode.equals("" + buildVersion)) { isRunFirstOnNewVersion = true; SharedPreferences.Editor edit = settings.edit(); edit.putString("APK_VERSION_CODE", "" + buildVersion); edit.putString("JS_VERSION_CLEAR", "yes"); edit.commit(); new Thread(new Runnable() { @Override public void run() { deleteDirectoryAtPath(documentFilePath + MAIN_BUNDLE_FOLDER); } }).start(); } }
Example 14
Source File: AppRate.java From discreet-app-rate with Apache License 2.0 | 5 votes |
public static AppRate with(Activity activity) { if (activity == null) { throw new IllegalStateException("Activity cannot be null"); } AppRate instance = new AppRate(activity); instance.text = activity.getString(R.string.dra_rate_app); instance.settings = activity.getSharedPreferences(PREFS_NAME, 0); instance.editor = instance.settings.edit(); instance.packageName = activity.getPackageName(); return instance; }
Example 15
Source File: AppRate.java From FireFiles with Apache License 2.0 | 5 votes |
public static AppRate with(Activity activity) { AppRate instance = new AppRate(activity); instance.text = "Enjoying the app? Spread the word!";//activity.getString(R.string.dra_rate_app); instance.settings = activity.getSharedPreferences(PREFS_NAME, 0); instance.editor = instance.settings.edit(); return instance; }
Example 16
Source File: DynamicSplashDownLoad.java From react-native-dynamic-splash with MIT License | 4 votes |
public static String getSharedValue(Activity activity) { SharedPreferences sharedPre = activity.getSharedPreferences(sharedName, Context.MODE_PRIVATE); return sharedPre.getString(sharedKeyName, ""); }
Example 17
Source File: SmartRate.java From SmartRateUsDialog-Android with Apache License 2.0 | 4 votes |
private static long getInitTime(Activity activity) { SharedPreferences sharedPreferences = activity.getSharedPreferences(SP_LIBRARY_NAME, Context.MODE_PRIVATE); long val = sharedPreferences.getLong(SP_KEY_INIT_TIME, 0); return val; }
Example 18
Source File: MainModel.java From BetterWay with Apache License 2.0 | 4 votes |
public void setActivity(Activity activity) { sharedPreferences = activity.getSharedPreferences(PREFERENCE, Context.MODE_PRIVATE); }
Example 19
Source File: UserInfoStore.java From AvI with MIT License | 4 votes |
public static String getUserId(Activity activity){ SharedPreferences prefs = activity.getSharedPreferences(Constants.PREF_FILE_NAME, 0); return prefs.getString(PREF_USER_AUTH_ID, "N/A"); }
Example 20
Source File: SDCardUtils.java From Gallery-example with GNU General Public License v3.0 | 2 votes |
static String getSDCardUri(Activity activity) { SharedPreferences preferenceSD = activity.getSharedPreferences("sdUri", Context.MODE_PRIVATE); return preferenceSD.getString("selectedSD", ""); }