Example usage for android.content SharedPreferences getAll

List of usage examples for android.content SharedPreferences getAll

Introduction

In this page you can find the example usage for android.content SharedPreferences getAll.

Prototype

Map<String, ?> getAll();

Source Link

Document

Retrieve all values from the preferences.

Usage

From source file:Main.java

public static boolean savePreferencesInExternal(Context ctx, SharedPreferences pref) {

    Properties propfile = new Properties();
    Map<String, ?> keymap = pref.getAll();
    Iterator<String> keyit = keymap.keySet().iterator();
    Log.d("External", "Saving prefrences to external Storages");

    while (keyit.hasNext()) {
        String key = keyit.next();
        propfile.put(key, keymap.get(key));
    }/*from w w  w . j  a  v a  2  s .c  o m*/
    if (isExternalStorageAvailableforWriting() == true) {
        try {
            propfile.storeToXML(new FileOutputStream(new File(ctx.getExternalFilesDir(null), "install_info")),
                    null);
        } catch (Exception e) {

            e.printStackTrace();
        }

        Log.d("External", "Saved prefrences to external ");
        return true;
    } else {
        Log.d("External", "Failed to Save prefrences for external ");
        return false;
    }
}

From source file:com.microsoft.azure.engagement.shared.EngagementDataPushReceiver.java

@TargetApi(9)
public static Map<String, String> getPendingDataPushes(Context context) {

    Map<String, String> smap = new TreeMap<String, String>();

    SharedPreferences settings = context.getSharedPreferences(ENGAGEMENT_PREFERENCES, 0/*MODE_PRIVATE*/);
    Map<String, ?> m = settings.getAll();

    // convert to treemap to keep the order by timestamp
    for (Map.Entry<String, ?> entry : m.entrySet()) {
        smap.put(entry.getKey(), entry.getValue().toString());

    }/*w w w .jav a  2s. c o m*/
    // remove all
    settings.edit().clear().apply();

    return smap;
}

From source file:at.wada811.utils.DumpUtils.java

public static String toString(SharedPreferences preferences) {
    if (preferences == null) {
        return "null";
    }//w w  w.  j  a v  a2  s .  c o  m
    JSONObject json = new JSONObject();
    Map<String, ?> map = preferences.getAll();
    for (Entry<String, ?> entry : map.entrySet()) {
        try {
            json.put(entry.getKey(), DumpUtils.toString(entry.getValue()));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    return json.toString();
}

From source file:org.projectbuendia.client.ui.SettingsActivity.java

/**
 * Shows a preference's string value on its summary line (below the title
 * of the preference), and keep the summary updated when the value changes.
 *
 * @see #sListener// w  w w  .  java  2  s . c o  m
 */
private static void showValueAsSummary(Preference pref) {
    // Set the listener to watch for value changes.
    pref.setOnPreferenceChangeListener(sListener);

    // Trigger the listener immediately with the preference's current value.
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(pref.getContext());
    sListener.onPreferenceChange(pref, prefs.getAll().get(pref.getKey()));
}

From source file:de.vanita5.twittnuker.util.UserColorNameUtils.java

public static void initUserColor(final Context context) {
    if (context == null)
        return;/*from   w  ww.  ja  v a2s .c o m*/
    final SharedPreferences prefs = context.getSharedPreferences(USER_COLOR_PREFERENCES_NAME,
            Context.MODE_PRIVATE);
    for (final Map.Entry<String, ?> entry : prefs.getAll().entrySet()) {
        sUserColors.put(ParseUtils.parseLong(entry.getKey()),
                ParseUtils.parseInt(ParseUtils.parseString(entry.getValue())));
    }
}

From source file:at.wada811.android.library.demos.CrashExceptionHandler.java

/**
 * Preferences?/*from   w  w  w  .ja  va  2  s  .  c o  m*/
 * 
 * @return
 * @throws JSONException
 */
private static JSONObject getPreferencesInfo(Context context) {
    SharedPreferences preferences = PreferenceUtils.getDefaultSharedPreferences(context);
    JSONObject json = new JSONObject();
    Map<String, ?> map = preferences.getAll();
    for (Entry<String, ?> entry : map.entrySet()) {
        try {
            json.put(entry.getKey(), entry.getValue());
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    return json;
}

From source file:com.amitshekhar.utils.PrefHelper.java

public static TableDataResponse getAllPrefData(Context context, String tag) {

    TableDataResponse response = new TableDataResponse();
    response.isSuccessful = true;/*from   w w w .  j av  a 2 s  .c  om*/
    response.isSelectQuery = true;

    TableDataResponse.TableInfo keyInfo = new TableDataResponse.TableInfo();
    keyInfo.isPrimary = true;
    keyInfo.title = "Key";

    TableDataResponse.TableInfo valueInfo = new TableDataResponse.TableInfo();
    valueInfo.isPrimary = false;
    valueInfo.title = "Value";

    response.tableInfos = new ArrayList<>();
    response.tableInfos.add(keyInfo);
    response.tableInfos.add(valueInfo);

    response.rows = new ArrayList<>();

    SharedPreferences preferences = context.getSharedPreferences(tag, Context.MODE_PRIVATE);
    Map<String, ?> allEntries = preferences.getAll();
    for (Map.Entry<String, ?> entry : allEntries.entrySet()) {
        List<TableDataResponse.ColumnData> row = new ArrayList<>();
        TableDataResponse.ColumnData keyColumnData = new TableDataResponse.ColumnData();
        keyColumnData.dataType = DataType.TEXT;
        keyColumnData.value = entry.getKey();

        row.add(keyColumnData);

        TableDataResponse.ColumnData valueColumnData = new TableDataResponse.ColumnData();
        valueColumnData.value = entry.getValue().toString();
        if (entry.getValue() != null) {
            if (entry.getValue() instanceof String) {
                valueColumnData.dataType = DataType.TEXT;
            } else if (entry.getValue() instanceof Integer) {
                valueColumnData.dataType = DataType.INTEGER;
            } else if (entry.getValue() instanceof Long) {
                valueColumnData.dataType = DataType.LONG;
            } else if (entry.getValue() instanceof Float) {
                valueColumnData.dataType = DataType.FLOAT;
            } else if (entry.getValue() instanceof Boolean) {
                valueColumnData.dataType = DataType.BOOLEAN;
            } else if (entry.getValue() instanceof Set) {
                valueColumnData.dataType = DataType.STRING_SET;
            }
        } else {
            valueColumnData.dataType = DataType.TEXT;
        }
        row.add(valueColumnData);
        response.rows.add(row);
    }

    return response;

}

From source file:at.wada811.dayscounter.CrashExceptionHandler.java

/**
 * Preferences?/*from  ww  w  .ja  v a 2  s.  c  o  m*/
 *
 * @return
 *
 * @throws JSONException
 */
public static JSONObject getPreferencesInfo(Context context) {
    SharedPreferences preferences = PreferenceUtils.getDefaultSharedPreferences(context);
    JSONObject json = new JSONObject();
    Map<String, ?> map = preferences.getAll();
    for (Entry<String, ?> entry : map.entrySet()) {
        try {
            json.put(entry.getKey(), entry.getValue());
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    return json;
}

From source file:at.wada811.utils.PreferenceUtils.java

/**
 * All SharedPreference to JSON String/* www  .j  av a  2 s.  c o  m*/
 * 
 * @param context
 * @return jsonString|null
 */
public static String toJsonString(Context context) {
    SharedPreferences preferences = PreferenceUtils.getDefaultSharedPreferences(context);
    JSONObject jsonObject = new JSONObject();
    Map<String, ?> map = preferences.getAll();
    try {
        for (Entry<String, ?> entry : map.entrySet()) {
            jsonObject.put(entry.getKey(), entry.getValue());
        }
    } catch (JSONException e) {
        e.printStackTrace();
        return null;
    }
    return jsonObject.toString();
}

From source file:com.footprint.cordova.plugin.localnotification.LocalNotification.java

/**
 * Checks wether a notification with an ID is scheduled.
 *
 * @param id//from   ww w  .  j a  v a2s .c  o m
 *          The notification ID to be check.
 * @param callbackContext
 */
public static void isScheduled(String id, CallbackContext command) {
    SharedPreferences settings = getSharedPreferences();
    Map<String, ?> alarms = settings.getAll();
    boolean isScheduled = alarms.containsKey(id);
    PluginResult result = new PluginResult(PluginResult.Status.OK, isScheduled);

    command.sendPluginResult(result);
}