Java Code Examples for android.app.Activity#getSharedPreferences()

The following examples show how to use android.app.Activity#getSharedPreferences() . These examples are extracted from open source projects. 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 Project: SteamGifts   File: IntroActivity.java    License: MIT License 5 votes vote down vote up
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 2
Source Project: FireFiles   File: AppRate.java    License: Apache License 2.0 5 votes vote down vote up
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 3
Source Project: discreet-app-rate   File: AppRate.java    License: Apache License 2.0 5 votes vote down vote up
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 4
Source Project: react-native-update   File: RCTUpdateMgr.java    License: MIT License 5 votes vote down vote up
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 5
Source Project: AvI   File: UserInfoStore.java    License: MIT License 5 votes vote down vote up
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 6
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 7
Source Project: NightOwl   File: MainApplication.java    License: Apache License 2.0 5 votes vote down vote up
@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 8
Source Project: FlappyCow   File: AccomplishmentBox.java    License: MIT License 5 votes vote down vote up
/**
 * 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 9
Source Project: AvI   File: AccessTokenStore.java    License: MIT License 5 votes vote down vote up
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 10
/**
 * @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 11
Source Project: SystemUITuner2   File: SetThings.java    License: MIT License 5 votes vote down vote up
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 12
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 13
Source Project: FlappyCow   File: AccomplishmentBox.java    License: MIT License 5 votes vote down vote up
/**
 * 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 14
Source Project: FireFiles   File: AppRate.java    License: Apache License 2.0 5 votes vote down vote up
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 15
Source Project: FireFiles   File: AppRate.java    License: Apache License 2.0 5 votes vote down vote up
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 16
Source Project: AvI   File: UserInfoStore.java    License: MIT License 4 votes vote down vote up
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 17
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
public static String getSharedValue(Activity activity) {
    SharedPreferences sharedPre = activity.getSharedPreferences(sharedName, Context.MODE_PRIVATE);
    return sharedPre.getString(sharedKeyName, "");
}
 
Example 19
Source Project: BetterWay   File: MainModel.java    License: Apache License 2.0 4 votes vote down vote up
public void setActivity(Activity activity) {
    sharedPreferences = activity.getSharedPreferences(PREFERENCE, Context.MODE_PRIVATE);
}
 
Example 20
static String getSDCardUri(Activity activity) {

        SharedPreferences preferenceSD = activity.getSharedPreferences("sdUri", Context.MODE_PRIVATE);

        return preferenceSD.getString("selectedSD", "");
    }