Search in sources :

Example 76 with SharedPreferences

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: {}
}
Also used : TrayItem(net.grandcentrix.tray.core.TrayItem) SharedPreferences(android.content.SharedPreferences) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 77 with 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);
}
Also used : SharedPreferences(android.content.SharedPreferences)

Example 78 with SharedPreferences

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();
        }
    });
}
Also used : SharedPreferences(android.content.SharedPreferences) ThrottledContentObserver(com.google.samples.apps.iosched.util.ThrottledContentObserver)

Example 79 with SharedPreferences

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();
}
Also used : SharedPreferences(android.content.SharedPreferences)

Example 80 with SharedPreferences

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;
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) Calendar(java.util.Calendar)

Aggregations

SharedPreferences (android.content.SharedPreferences)1762 Intent (android.content.Intent)221 View (android.view.View)110 Editor (android.content.SharedPreferences.Editor)100 TextView (android.widget.TextView)74 ArrayList (java.util.ArrayList)67 Context (android.content.Context)59 PendingIntent (android.app.PendingIntent)57 File (java.io.File)57 IOException (java.io.IOException)56 Bundle (android.os.Bundle)45 JSONException (org.json.JSONException)41 JSONObject (org.json.JSONObject)41 DialogInterface (android.content.DialogInterface)37 AdapterView (android.widget.AdapterView)34 ImageView (android.widget.ImageView)34 ListView (android.widget.ListView)34 SuppressLint (android.annotation.SuppressLint)33 JSONArray (run.wallet.common.json.JSONArray)33 ComponentName (android.content.ComponentName)31