use of android.content.SharedPreferences in project tray by grandcentrix.
the class ImportTrayPreferences method importSharedPreferencesWithLogging.
/**
* logging wrapper for:
* example how to import shared preferences
*/
private void importSharedPreferencesWithLogging() {
final SharedPreferences sharedPreferences = getContext().getSharedPreferences(SampleActivity.SHARED_PREF_NAME, Context.MODE_MULTI_PROCESS);
final HashMap<String, ?> allBefore = new HashMap<>(sharedPreferences.getAll());
Log.v(TAG, allBefore.size() + " items in sharedPreferences: " + allBefore.toString());
// 2 items in sharedPreferences: {userToken=cf26535a-6949-4728-b595-c6d80c094eff, gcmToken=2ca7e9a0-9114-4d55-8d2d-870b8d49fafe}
importSharedPreferences();
final ArrayList<TrayItem> all = new ArrayList<>(getAll());
Log.v(TAG, "imported " + all.size() + " items: " + all.toString());
// imported 2 items: [
// {key: gcm:token, value: 2ca7e9a0-9114-4d55-8d2d-870b8d49fafe, module: imported, created: 14:06:04 05.06.2015, updated: 14:06:04 05.06.2015, migratedKey: gcmToken},
// {key: user:token, value: cf26535a-6949-4728-b595-c6d80c094eff, module: imported, created: 14:06:04 05.06.2015, updated: 14:06:04 05.06.2015, migratedKey: userToken}
// ]
final HashMap<String, ?> allAfter = new HashMap<>(sharedPreferences.getAll());
Log.v(TAG, allAfter.size() + " items in sharedPreferences: " + allAfter.toString());
// 0 items in sharedPreferences: {}
}
use of android.content.SharedPreferences in project iosched by google.
the class ExploreIOFragment method onDetach.
@Override
public void onDetach() {
super.onDetach();
if (mConfMessagesAnswerChangeListener != null) {
ConfMessageCardUtils.unregisterPreferencesChangeListener(getContext(), mConfMessagesAnswerChangeListener);
}
if (mSettingsChangeListener != null) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
sp.unregisterOnSharedPreferenceChangeListener(mSettingsChangeListener);
}
getActivity().getContentResolver().unregisterContentObserver(mSessionsObserver);
getActivity().getContentResolver().unregisterContentObserver(mTagsObserver);
}
use of android.content.SharedPreferences in project iosched by google.
the class ExploreIOFragment method onAttach.
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
// Register preference change listeners
ConfMessageCardUtils.registerPreferencesChangeListener(getContext(), mConfMessagesAnswerChangeListener);
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
sp.registerOnSharedPreferenceChangeListener(mSettingsChangeListener);
// Register content observers
mSessionsObserver = new ThrottledContentObserver(new ThrottledContentObserver.Callbacks() {
@Override
public void onThrottledContentObserverFired() {
fireReloadEvent();
fireReloadTagsEvent();
}
});
mTagsObserver = new ThrottledContentObserver(new ThrottledContentObserver.Callbacks() {
@Override
public void onThrottledContentObserverFired() {
fireReloadTagsEvent();
}
});
}
use of android.content.SharedPreferences in project iosched by google.
the class FeedbackHelper method setFeedbackNotificationAsFiredForSession.
/**
* Sets feedback notification as fired for a particular {@code sessionId}.
*/
public void setFeedbackNotificationAsFiredForSession(String sessionId) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
final String key = createKeyForNotification(sessionId);
sp.edit().putBoolean(key, true).apply();
}
use of android.content.SharedPreferences in project iosched by google.
the class ServerUtilities method isRegisteredOnServer.
/**
* Checks whether the device was successfully registered in the server side.
*
* @param context Current context
* @return True if registration was successful, false otherwise
*/
public static boolean isRegisteredOnServer(Context context, String gcmKey) {
final SharedPreferences prefs = context.getSharedPreferences(PREFERENCES, Context.MODE_PRIVATE);
// Find registration threshold
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -1);
long yesterdayTS = cal.getTimeInMillis();
long regTS = prefs.getLong(PROPERTY_REGISTERED_TS, 0);
gcmKey = gcmKey == null ? "" : gcmKey;
if (regTS > yesterdayTS) {
LOGV(TAG, "GCM registration current. regTS=" + regTS + " yesterdayTS=" + yesterdayTS);
final String registeredGcmKey = prefs.getString(PROPERTY_GCM_KEY, "");
if (registeredGcmKey.equals(gcmKey)) {
LOGD(TAG, "GCM registration is valid and for the correct gcm key: " + AccountUtils.sanitizeGcmKey(registeredGcmKey));
return true;
}
LOGD(TAG, "GCM registration is for DIFFERENT gcm key " + AccountUtils.sanitizeGcmKey(registeredGcmKey) + ". We were expecting " + AccountUtils.sanitizeGcmKey(gcmKey));
return false;
} else {
LOGV(TAG, "GCM registration expired. regTS=" + regTS + " yesterdayTS=" + yesterdayTS);
return false;
}
}
Aggregations