Java 类android.content.SharedPreferences 实例源码

项目:Kids-Portal-Android    文件:helper_browser.java   
public static String tab_5 (Activity activity) {
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(activity);
    String s;

    final String tab_string = sharedPref.getString("tab_4", "");

    try {
        if (tab_string.isEmpty()) {
            s = activity.getString(R.string.context_tab);
        } else {
            s = tab_string;
        }
    } catch (Exception e) {
        Log.e("KidsPortal", "Unable to get String", e);
        s = activity.getString(R.string.context_tab);
    }
    return s;
}
项目:android-dev-challenge    文件:SettingsFragment.java   
@Override
public void onCreatePreferences(Bundle bundle, String s) {
    // Add 'general' preferences, defined in the XML file
    addPreferencesFromResource(R.xml.pref_general);

    SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
    PreferenceScreen prefScreen = getPreferenceScreen();
    int count = prefScreen.getPreferenceCount();
    for (int i = 0; i < count; i++) {
        Preference p = prefScreen.getPreference(i);
        if (!(p instanceof CheckBoxPreference)) {
            String value = sharedPreferences.getString(p.getKey(), "");
            setPreferenceSummary(p, value);
        }
    }
}
项目:chapp-messenger    文件:LoginActivity.java   
private void getInformationFromFB(String UID) {
    dbr_users.child(UID).addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            email = (String) dataSnapshot.child("mail").getValue();
            name = (String) dataSnapshot.child("name").getValue();
            username = (String) dataSnapshot.child("username").getValue();
            password = (String) dataSnapshot.child("password").getValue();
            telefonnummer = (String) dataSnapshot.child("telefonnummer").getValue();

            SharedPreferences.Editor editor = getSharedPreferences("CHAPP_PREFS", Context.MODE_PRIVATE).edit();
            editor.putString("email", email);
            editor.putString("name", name);
            editor.putString("username", username);
            editor.putString("telefonnummer", telefonnummer);
            editor.putString("password", password);
            editor.commit();
        };

        @Override
        public void onCancelled(DatabaseError databaseError) {
            // ...
        }
    });
}
项目:android-dev-challenge    文件:SunshinePreferences.java   
/**
 * Returns the location coordinates associated with the location. Note that there is a
 * possibility that these coordinates may not be set, which results in (0,0) being returned.
 * Interestingly, (0,0) is in the middle of the ocean off the west coast of Africa.
 *
 * @param context used to access SharedPreferences
 * @return an array containing the two coordinate values for the user's preferred location
 */
public static double[] getLocationCoordinates(Context context) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);

    double[] preferredCoordinates = new double[2];

    /*
     * This is a hack we have to resort to since you can't store doubles in SharedPreferences.
     *
     * Double.doubleToLongBits returns an integer corresponding to the bits of the given
     * IEEE 754 double precision value.
     *
     * Double.longBitsToDouble does the opposite, converting a long (that represents a double)
     * into the double itself.
     */
    preferredCoordinates[0] = Double
             .longBitsToDouble(sp.getLong(PREF_COORD_LAT, Double.doubleToRawLongBits(0.0)));
    preferredCoordinates[1] = Double
            .longBitsToDouble(sp.getLong(PREF_COORD_LONG, Double.doubleToRawLongBits(0.0)));

    return preferredCoordinates;
}
项目:keepass2android    文件:AccessManager.java   
public static Set<String> getAllHostPackages(Context ctx)
{
    SharedPreferences prefs = ctx.getSharedPreferences("KP2A.PluginAccess.hosts", Context.MODE_PRIVATE);
    Set<String> result = new HashSet<String>();
    for (String host: prefs.getAll().keySet())
    {
        try
        {
            PackageInfo info = ctx.getPackageManager().getPackageInfo(host, PackageManager.GET_META_DATA);
            //if we get here, the package is still there
            result.add(host);
        }
        catch (PackageManager.NameNotFoundException e)
        {
            //host gone. ignore.
        }
    }
    return result;

}
项目:Mobike    文件:PersistentCookieStore.java   
@Override
public boolean clearExpired(Date date) {
    boolean clearedAny = false;
    SharedPreferences.Editor prefsWriter = cookiePrefs.edit();

    for (ConcurrentHashMap.Entry<String, Cookie> entry : cookies.entrySet()) {
        String name = entry.getKey();
        Cookie cookie = entry.getValue();
        if (cookie.isExpired(date)) {
            // Clear cookies from local store
            cookies.remove(name);

            // Clear cookies from persistent store
            prefsWriter.remove(COOKIE_NAME_PREFIX + name);

            // We've cleared at least one
            clearedAny = true;
        }
    }

    // Update names in persistent store
    if (clearedAny) {
        prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet()));
    }
    prefsWriter.commit();

    return clearedAny;
}
项目:DAPNETApp    文件:MainActivity.java   
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    Menu nv = navigationView.getMenu();
    MenuItem mloginstatus = nv.findItem(R.id.nav_loginstatus);
    SharedPreferences sharedPref = getSharedPreferences("sharedPref", Context.MODE_PRIVATE);
    loggedIn = sharedPref.getBoolean("isLoggedIn", false);
    mServer = sharedPref.getString("server", null);

    if (loggedIn) {
        mloginstatus.setTitle(R.string.nav_logout);
        Log.i(TAG, "User is logged in!");
    } else {
        mloginstatus.setTitle(R.string.nav_login);
        Log.i(TAG, "User is not logged in!");
    }
    if (mServer != null) {
        setVersion(mServer);
    } else {
        setVersion("http://hampager.de:8080");
        //if mServer == null
        // setVersion("http://dapnet.db0sda.ampr.org:8080")
    }

    return true;
}
项目:memento-app    文件:StorageHelper.java   
public static void setPersonGroupName(String personGroupIdToAdd, String personGroupName, Context context) {
    SharedPreferences personGroupIdNameMap =
            context.getSharedPreferences("PersonGroupIdNameMap", Context.MODE_PRIVATE);

    SharedPreferences.Editor personGroupIdNameMapEditor = personGroupIdNameMap.edit();
    personGroupIdNameMapEditor.putString(personGroupIdToAdd, personGroupName);
    personGroupIdNameMapEditor.commit();

    Set<String> personGroupIds = getAllPersonGroupIds(context);
    Set<String> newPersonGroupIds = new HashSet<>();
    for (String personGroupId: personGroupIds) {
        newPersonGroupIds.add(personGroupId);
    }
    newPersonGroupIds.add(personGroupIdToAdd);
    SharedPreferences personGroupIdSet =
            context.getSharedPreferences("PersonGroupIdSet", Context.MODE_PRIVATE);
    SharedPreferences.Editor personGroupIdSetEditor = personGroupIdSet.edit();
    personGroupIdSetEditor.putStringSet("PersonGroupIdSet", newPersonGroupIds);
    personGroupIdSetEditor.commit();
}
项目:Shared-Route    文件:PayBillActivity.java   
private void postInfo() {
    if (mAuthTask != null) {
        return;
    }
    showProgress(true);
    String payPath = "";
    RadioButton zhifubao = (RadioButton)findViewById(R.id.zhifubao);
    RadioButton wechat = (RadioButton)findViewById(R.id.wechat);
    if (zhifubao.isChecked()){
        payPath = "zhifubao";
    } else if (wechat.isChecked()) {
        payPath="wechat";
    }
    SharedPreferences sp = getSharedPreferences("now_account", Context.MODE_PRIVATE);
    stuNum=sp.getString("now_stu_num",null);
    Bundle bundle = getIntent().getExtras();
    mAuthTask = new PostTask(bundle.getString("money"),bundle.getString("name"),
            bundle.getString("phone"),bundle.getString("num"),bundle.getString("packsort"),
            bundle.getString("pickupplace"),bundle.getString("delieverplace"),
            bundle.getString("pickuptime"),bundle.getString("delievertime"),
            payPath,bundle.getString("remark"),stuNum,bundle.getString("securitymoney"));
    mAuthTask.execute((Void) null);

}
项目:TherapyGuide    文件:SettingsFragment.java   
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Define the settings file
    getPreferenceManager().setSharedPreferencesName(MainActivity.PREFERENCES);
    getPreferenceManager().setSharedPreferencesMode(Context.MODE_PRIVATE);

    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.preferences);

    // Set the summary for the diary reminder time
    SharedPreferences sharedPreferences = getActivity()
            .getSharedPreferences(MainActivity.PREFERENCES, Context.MODE_PRIVATE);
    setDiaryReminderTimeSummary(sharedPreferences);

    // Prepare alarm
    Intent intent = new Intent(getActivity(), AlarmHandler.class);
    intent.setAction(AlarmHandler.DIARY_ALERT);
    mAlarmIntent = PendingIntent.getBroadcast(getActivity(), 0, intent, 0);
    mAlarmManager = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);

    mReceiver = new ComponentName(getActivity(), BootHandler.class);
    mPackageManager = getActivity().getPackageManager();
}
项目:appinventor-extensions    文件:Pedometer.java   
/**
 * Saves the pedometer state to shared preferences.
 */
@SimpleFunction(description = "Saves the pedometer state to the phone. Permits " +
  "permits accumulation of steps and distance between invocations of an App that uses " +
  "the pedometer. Different Apps will have their own saved state.")
public void Save() {
  // Store preferences
  SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
  SharedPreferences.Editor editor = settings.edit();
  editor.putFloat("Pedometer.stridelength", strideLength);
  editor.putFloat("Pedometer.distance", totalDistance);
  editor.putInt("Pedometer.prevStepCount", numStepsRaw);
  if (pedometerPaused) {
    editor.putLong("Pedometer.clockTime", prevStopClockTime);
  } else {
    editor.putLong("Pedometer.clockTime", prevStopClockTime +
        (System.currentTimeMillis() - startTime));
  }
  editor.putLong("Pedometer.closeTime", System.currentTimeMillis());
  editor.commit();
  Log.d(TAG, "Pedometer state saved.");
}
项目:Android_watch_magpie    文件:MagpieActivity.java   
private void recreateAgents(SharedPreferences settings) {
    Message request = Message.obtain();
    request.what = Environment.RECREATE_AGENTS;
    request.replyTo = replyMessenger;

    Bundle bundle = new Bundle();

    HashSet<String> agentNamesFromActivity = (HashSet<String>)
            settings.getStringSet(ACTIVITY_NAME, new HashSet<String>());
    bundle.putSerializable(AGENT_NAMES, agentNamesFromActivity);

    request.setData(bundle);

    try {
        requestMessenger.send(request);
    } catch (RemoteException ex) {
        ex.printStackTrace();
    }
}
项目:MyBP    文件:RateApp.java   
public void appLaunched(Context context) {
    SharedPreferences preferences = context.getSharedPreferences("MyBPreferences", Context.MODE_PRIVATE);
    if(preferences.getBoolean("disabled", false)) {
        return;
    }

    SharedPreferences.Editor editor = preferences.edit();

    long launchCount = preferences.getLong("launchCount", 0) + 1;
    editor.putLong("launchCount", launchCount);

    long firstLaunchDate = preferences.getLong("firstLaunchDate", 0);
    if(firstLaunchDate == 0) {
        firstLaunchDate = System.currentTimeMillis();
        editor.putLong("firstLaunchDate", firstLaunchDate);
    }

    if(launchCount >= LAUNCHES_UNTIL_PROMPT) {
        if(System.currentTimeMillis() >= firstLaunchDate + (DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000)) {
            showRateDialog(context, editor);
        }
    }

    editor.commit();
}
项目:airgram    文件:ApplicationLoader.java   
public static void startPushService() {
    SharedPreferences preferences = applicationContext.getSharedPreferences("Notifications", MODE_PRIVATE);

    if (preferences.getBoolean("pushService", true)) {
        applicationContext.startService(new Intent(applicationContext, NotificationsService.class));
    } else {
        stopPushService();
    }
}
项目:underlx    文件:PairManager.java   
public void unpair() {
    SharedPreferences.Editor editor = sharedPref.edit();
    editor.putString(PREF_API_KEY, "");
    editor.putString(PREF_API_SECRET, "");
    editor.putLong(PREF_API_ACTIVATION, Long.MAX_VALUE);
    editor.commit();
}
项目:Checkerboard-IMU-Comparator    文件:SettingsActivity.java   
private void restoreSharedPreferences(){
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putInt(getString(R.string.sharedpreferences_necessary_images_number_key), DEFAULT_NECESSARY_IMAGES_NUMBER);
    editor.putInt(getString(R.string.sharedpreferences_checkerboard_width_key), DEFAULT_CHECKERBOARD_WIDTH);
    editor.putInt(getString(R.string.sharedpreferences_checkerboard_height_key), DEFAULT_CHECKERBOARD_HEIGHT);
    editor.apply();
}
项目:android-dev-challenge    文件:SunshinePreferences.java   
/**
 * Resets the location coordinates stores in SharedPreferences.
 *
 * @param context Context used to get the SharedPreferences
 */
public static void resetLocationCoordinates(Context context) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = sp.edit();

    editor.remove(PREF_COORD_LAT);
    editor.remove(PREF_COORD_LONG);
    editor.apply();
}
项目:android-metronome    文件:Metronome.java   
public void clickSetDefault(View btn)
{
    SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(this);
    SharedPreferences.Editor editor=prefs.edit();
    editor.putInt("default_bpm", npbpm.getValue());
    editor.putInt("default_measure", Integer.parseInt(etMeasure.getText().toString()));
    editor.commit();
}
项目:1946    文件:GcmPush.java   
public static String getStoredPendingLocalAlarm( Context context, int index )
{
    final SharedPreferences prefs = getGcmPreferences( context );
    String keyData = PROP_ALARM_DATA_N + Integer.toString(index);
    String alarmData = prefs.getString(keyData, null );
    return alarmData;
}
项目:AndroidMuseumBleManager    文件:PreferencesUtils.java   
/**
 * get int preferences
 *
 * @param context
 * @param key          The name of the preference to retrieve
 * @param defaultValue Value to return if this preference does not exist
 * @return The preference value if it exists, or defValue. Throws ClassCastException if there is a preference with
 * this name that is not a int
 */
public static int getInt(Context context, String key, int defaultValue) {
    try {
        SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        return settings.getInt(key, defaultValue);
    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }
    return defaultValue;
}
项目:letv    文件:ServerSetting.java   
public void setEnvironment(Context context, int i) {
    if (context != null && (this.c == null || this.c.get() == null)) {
        this.c = new WeakReference(context.getSharedPreferences("ServerPrefs", 0));
    }
    if (i == 0 || i == 1) {
        Editor edit;
        switch (i) {
            case 0:
                edit = ((SharedPreferences) this.c.get()).edit();
                edit.putInt("ServerType", 0);
                edit.putString(KEY_OPEN_ENV, "formal");
                edit.putString(KEY_HOST_QZS_QQ, KEY_HOST_QZS_QQ);
                edit.putString(KEY_HOST_OPEN_MOBILE, KEY_HOST_OPEN_MOBILE);
                edit.commit();
                changeServer();
                Toast.makeText(context, "已切换到正式环境", 0).show();
                return;
            case 1:
                edit = ((SharedPreferences) this.c.get()).edit();
                edit.putInt("ServerType", 1);
                edit.putString(KEY_OPEN_ENV, "exp");
                edit.putString(KEY_HOST_QZS_QQ, "testmobile.qq.com");
                edit.putString(KEY_HOST_OPEN_MOBILE, "test.openmobile.qq.com");
                edit.commit();
                changeServer();
                Toast.makeText(context, "已切换到体验环境", 0).show();
                return;
            default:
                return;
        }
    }
    f.e(a, "切换环境参数错误,正式环境为0,体验环境为1");
}
项目:Options    文件:SharedPreferencesStringDropdownOption.java   
private SharedPreferencesStringDropdownOption(SharedPreferences sharedPreferences, String key,
                                              String defaultValue, String title,
                                              List<Selection<String>> values) {
    mSharedPreferences = sharedPreferences;
    mKey = key;
    mDefaultValue = defaultValue;
    mTitle = title;
    mValues = values;
}
项目:simple-keyboard    文件:Settings.java   
public static boolean readKeyPreviewPopupEnabled(final SharedPreferences prefs,
        final Resources res) {
    final boolean defaultKeyPreviewPopup = res.getBoolean(
            R.bool.config_default_key_preview_popup);
    if (!readFromBuildConfigIfToShowKeyPreviewPopupOption(res)) {
        return defaultKeyPreviewPopup;
    }
    return prefs.getBoolean(PREF_POPUP_ON, defaultKeyPreviewPopup);
}
项目:DAPNETApp    文件:PostCallActivity.java   
private void saveData(TransmitterGroupResource[] input){
    SharedPreferences sharedPref = getSharedPreferences("sharedPref", Context.MODE_PRIVATE);
    SharedPreferences.Editor prefsEditor = sharedPref.edit();
    Gson gson = new Gson();
    String json = gson.toJson(input);
    prefsEditor.putString("transmitters", json);
    prefsEditor.apply();
}
项目:Pocket-Plays-for-Twitch    文件:Settings.java   
/**
 * Chat - Should the chat be able to be showed in landspace
 * @param enableChat True if yes, false if no.
 */

public void setShowChatInLandscape(boolean enableChat) {
    SharedPreferences.Editor editor = getEditor();
    editor.putBoolean(this.CHAT_LANDSCAPE_SWIPABLE, enableChat);
    editor.commit();
}
项目:ultrasonic    文件:MainActivity.java   
private void loadSettings()
{
    PreferenceManager.setDefaultValues(this, R.xml.settings, false);
    final SharedPreferences preferences = Util.getPreferences(this);

    if (!preferences.contains(Constants.PREFERENCES_KEY_CACHE_LOCATION))
    {
        final SharedPreferences.Editor editor = preferences.edit();
        editor.putString(Constants.PREFERENCES_KEY_CACHE_LOCATION, FileUtil.getDefaultMusicDirectory().getPath());
        editor.commit();
    }
}
项目:android-dev-challenge    文件:SunshinePreferences.java   
/**
 * Saves the time that a notification is shown. This will be used to get the ellapsed time
 * since a notification was shown.
 *
 * @param context Used to access SharedPreferences
 * @param timeOfNotification Time of last notification to save (in UNIX time)
 */
public static void saveLastNotificationTime(Context context, long timeOfNotification) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = sp.edit();
    String lastNotificationKey = context.getString(R.string.pref_last_notification);
    editor.putLong(lastNotificationKey, timeOfNotification);
    editor.apply();
}
项目:aos-MediaLib    文件:Trakt.java   
public static void setLoginPreferences(SharedPreferences pref, String user, String sha1) {
    Editor editor = pref.edit();
    if (user != null && sha1 != null) {
        editor.putString(KEY_TRAKT_USER, user);
        editor.putString(KEY_TRAKT_SHA1, sha1);
    } else {
        editor.remove(KEY_TRAKT_USER);
        editor.remove(KEY_TRAKT_SHA1);
    }
    editor.commit();
}
项目:airgram    文件:EmojiView.java   
private void saveRecentStickers() {
    SharedPreferences.Editor editor = getContext().getSharedPreferences("emoji", Activity.MODE_PRIVATE).edit();
    StringBuilder stringBuilder = new StringBuilder();
    for (int a = 0; a < newRecentStickers.size(); a++) {
        if (stringBuilder.length() != 0) {
            stringBuilder.append(",");
        }
        stringBuilder.append(newRecentStickers.get(a));
    }
    editor.putString("stickers2", stringBuilder.toString());
    editor.commit();
}
项目:Say_it    文件:UtilitySharedPrefs.java   
public static void savePrefs(Context context, int value, String prefs_key) {
    SharedPreferences settings = context.getSharedPreferences(MainActivity.PREFS_NAME, MODE_PRIVATE);
    SharedPreferences.Editor editor = settings.edit();

    editor.putInt(prefs_key, value);
    editor.apply();
}
项目:MeetMusic    文件:MyMusicUtil.java   
public static void setNightMode(Context context, boolean mode) {
    if (mode) {
        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
    } else {
        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
    }
    SharedPreferences sharedPreferences = context.getSharedPreferences(Constant.THEME, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor =  sharedPreferences.edit();
    editor.putBoolean("night", mode).commit();
}
项目:mousetodon    文件:MouseApp.java   
void addAccount() {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            // show the window where the user must enter his credentials
            UserInput.show(main, new NextAction() {
                public void run(String res) {
                    String[] ss = res.split(" ");
                    if (ss.length>2) {
                        useremail=ss[0];
                        userpwd=ss[1];
                        instanceDomain=ss[2];
                        if (useremail.length()==0 || userpwd.length()==0 || instanceDomain.length()==0)
                            message("All 3 fields are mandatory");
                        else {
                            SharedPreferences.Editor edit = pref.edit();
                            MouseApp.main.allinstances.add(instanceDomain);
                            String s = "";
                            for (String iss: MouseApp.main.allinstances) s+=iss+" ";
                            s=s.trim();
                            edit.putString("mouseapp_insts", s);
                            edit.putString(String.format("user_for_%s", instanceDomain), useremail);
                            edit.putString(String.format("pswd_for_%s", instanceDomain), userpwd);
                            edit.commit();
                            setInstanceSpinner();
                            serverStage1();
                        }
                    }
                }
            });
        }
    });
}
项目:hyperrail-for-android    文件:PersistentQueryProvider.java   
/**
 * Remove a query from a tag
 *
 * @param tag   The tag to remove from
 * @param query The query to remove
 */
private void remove(String tag, Suggestable query) {
    Set<String> items = new HashSet<>(sharedPreferences.getStringSet(tag, new HashSet<String>()));

    // If this query is already in the recents list, remove it (so we can update it)
    items = removeFromPersistentSet(items, query);

    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putStringSet(tag, items);
    editor.apply();
}
项目:SilicaGel    文件:TwitterUtil.java   
private static AccessToken loadAccessToken(Context context) {
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
    String token = pref.getString("twitter_token", null);
    String tokenSecret = pref.getString("twitter_secret", null);

    if (token != null && tokenSecret != null) {
        return new AccessToken(token, tokenSecret);
    } else {
        return null;
    }
}
项目:oma-riista-android    文件:GameDatabase.java   
public SyncMode getSyncMode(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    if (prefs.contains(syncModeKey)) {
        int syncMode = prefs.getInt(syncModeKey, 0);
        if (SyncMode.values().length > syncMode) {
            return SyncMode.values()[syncMode];
        }
    }
    return SyncMode.SYNC_AUTOMATIC;
}
项目:a_whattobuy    文件:SettingsService.java   
public void loadSettings(Activity c) {
    SharedPreferences sp = c.getPreferences(Context.MODE_PRIVATE);

    Map<String, ?> all = sp.getAll();

    for (Map.Entry<String, ?> e : all.entrySet()) {
        settings.put(e.getKey(), e.getValue());
    }
}
项目:ESSocialSDK-master    文件:AccessTokenKeeper.java   
/**
 * 保存 Token 对象到 SharedPreferences。
 *
 * @param context 应用程序上下文环境
 * @param token   Token 对象
 */
public static void writeAccessToken(Context context, Oauth2AccessToken token) {
    if (null == context || null == token) {
        return;
    }

    SharedPreferences pref = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_APPEND);
    Editor editor = pref.edit();
    editor.putString(KEY_UID, token.getUid());
    editor.putString(KEY_ACCESS_TOKEN, token.getToken());
    editor.putString(KEY_REFRESH_TOKEN, token.getRefreshToken());
    editor.putLong(KEY_EXPIRES_IN, token.getExpiresTime());
    editor.commit();
}
项目:PlusGram    文件:NotificationsController.java   
public void cleanup() {
    popupMessages.clear();
    popupReplyMessages.clear();
    notificationsQueue.postRunnable(new Runnable() {
        @Override
        public void run() {
            opened_dialog_id = 0;
            total_unread_count = 0;
            personal_count = 0;
            pushMessages.clear();
            pushMessagesDict.clear();
            pushDialogs.clear();
            wearNotificationsIds.clear();
            delayedPushMessages.clear();
            notifyCheck = false;
            lastBadgeCount = 0;
            try {
                if (notificationDelayWakelock.isHeld()) {
                    notificationDelayWakelock.release();
                }
            } catch (Exception e) {
                FileLog.e("tmessages", e);
            }
            setBadge(0);
            SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = preferences.edit();
            editor.clear();
            editor.commit();
        }
    });
}
项目:material-two-stage-rating    文件:PrefUtils.java   
public static void setIntSystemValue(final String key, final int value, final Context context) {
    SharedPreferences myPrefs = context
            .getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    SharedPreferences.Editor prefsEditor = myPrefs.edit();
    prefsEditor.putInt(key, value);
    prefsEditor.commit();
}
项目:Hexpert    文件:GameHelper.java   
int incrementSignInCancellations() {
    int cancellations = getSignInCancellations();
    SharedPreferences.Editor editor = mAppContext.getSharedPreferences(
            GAMEHELPER_SHARED_PREFS, Context.MODE_PRIVATE).edit();
    editor.putInt(KEY_SIGN_IN_CANCELLATIONS, cancellations + 1);
    editor.commit();
    return cancellations + 1;
}