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:eu.focusnet.app.util.ApplicationHelper.java

/**
 * Get all values for the SharedPreferences store
 *
 * @return The complete set of preferences.
 *///  w  ww .  j  a v a 2 s .c o  m
public static HashMap<String, String> getPreferences() {
    SharedPreferences store = getApplicationContext().getSharedPreferences(
            Constant.SharedPreferences.SHARED_PREFERENCES_STORE_NAME, Context.MODE_PRIVATE);

    HashMap<String, String> ret = new HashMap<>();
    Map<String, ?> prefs = store.getAll();
    for (Map.Entry e : prefs.entrySet()) {
        ret.put((String) e.getKey(), (String) e.getValue());
    }
    return ret;
}

From source file:eu.faircode.netguard.IAB.java

public static boolean isPurchasedAny(Context context) {
    if (Util.isDebuggable(context)) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        return !(prefs.getBoolean("debug_iab", false) || prefs.getBoolean("debug_ads", false));
    }//from  w ww .j a v a2  s .co  m

    SharedPreferences prefs = context.getSharedPreferences("IAB", Context.MODE_PRIVATE);
    for (String key : prefs.getAll().keySet())
        if (prefs.getBoolean(key, false))
            return true;
    return false;
}

From source file:com.aegiswallet.utils.BasicUtils.java

public static ArrayList<SMSTransactionPojo> getAllPendingTransactions(SharedPreferences prefs) {
    ArrayList<SMSTransactionPojo> list = new ArrayList<SMSTransactionPojo>();

    for (Map.Entry<String, ?> entry : prefs.getAll().entrySet()) {
        SMSTransactionPojo pojo = new SMSTransactionPojo(entry.getValue() + "");
        list.add(pojo);/*from w w  w.  java2  s  .c om*/
    }
    return list;
}

From source file:com.aegiswallet.utils.BasicUtils.java

public static ArrayList<SMSTransactionPojo> getAllRespondedSMSTransactions(SharedPreferences prefs) {
    ArrayList<SMSTransactionPojo> list = new ArrayList<SMSTransactionPojo>();

    for (Map.Entry<String, ?> entry : prefs.getAll().entrySet()) {
        SMSTransactionPojo pojo = new SMSTransactionPojo(entry.getValue() + "");
        if (pojo.getStatus() == Constants.SMS_STATUS_REC) {
            list.add(pojo);//from  w w w . j  av  a  2s  .  c om
        }
    }
    return list;
}

From source file:com.aegiswallet.utils.BasicUtils.java

public static ArrayList<SMSTransactionPojo> getAllNotRespondedSMSTransactions(SharedPreferences prefs) {
    ArrayList<SMSTransactionPojo> list = new ArrayList<SMSTransactionPojo>();

    for (Map.Entry<String, ?> entry : prefs.getAll().entrySet()) {
        SMSTransactionPojo pojo = new SMSTransactionPojo(entry.getValue() + "");
        if (pojo.getStatus() == Constants.SMS_STATUS_INIT) {
            list.add(pojo);//from www.  j  a  v  a2s  . co  m
        }
    }
    return list;
}

From source file:com.unovo.frame.utils.SharedPreferencesHelper.java

/**
 * ?Bean{@link SharedPreferences}// w ww .  jav  a 2 s  .  co  m
 * {@link #getSharedPreferences(Context, Class)}
 * SharedPreferences??
 *
 * @param context Context
 * @param t Bean
 * @param <T> Any Bean
 * @return ???
 */
public static <T> boolean save(Context context, T t) {
    final Class<?> clx = t.getClass();

    // We should remove all data before save data
    remove(context, clx);

    // Get all data form t
    Map<String, Data> map = new ArrayMap<>();
    buildValuesToMap(clx, t, "", map);

    SharedPreferences sp = getSharedPreferences(context, clx);
    SharedPreferences.Editor editor = sp.edit();

    // Get all existing key
    Set<String> existKeys = sp.getAll().keySet();

    // Foreach the sava data
    Set<String> keys = map.keySet();
    for (String key : keys) {
        Data data = map.get(key);

        final Class<?> type = data.type;
        final Object value = data.value;

        try {
            if (value == null) {
                removeKeyFamily(editor, existKeys, key);
            } else if (type.equals(Byte.class) || type.equals(byte.class)) {
                editor.putInt(key, (Byte) value);
            } else if (type.equals(Short.class) || type.equals(short.class)) {
                editor.putInt(key, (Short) value);
            } else if (type.equals(Integer.class) || type.equals(int.class)) {
                editor.putInt(key, (Integer) value);
            } else if (type.equals(Long.class) || type.equals(long.class)) {
                editor.putLong(key, (Long) value);
            } else if (type.equals(Float.class) || type.equals(float.class)) {
                editor.putFloat(key, (Float) value);
            } else if (type.equals(Double.class) || type.equals(double.class)) {
                editor.putString(key, (String.valueOf(value)));
            } else if (type.equals(Boolean.class) || type.equals(boolean.class)) {
                editor.putBoolean(key, (Boolean) value);
            } else if (type.equals(Character.class) || type.equals(char.class)) {
                editor.putString(key, value.toString());
            } else if (type.equals(String.class)) {
                editor.putString(key, value.toString());
            } else {
                Logger.e(TAG,
                        String.format("Con't support save this type:%s, value:%s, key:%s", type, value, key));
            }
        } catch (IllegalArgumentException e) {
            Logger.e(TAG, "Save error:" + e.getMessage());
        }
    }

    SharedPreferencesCompat.EditorCompat.getInstance().apply(editor);
    return true;
}

From source file:vrisini.cordova.plugin.schedule.Schedule.java

/**
 * Cancel all notifications that were created by this plugin.
 *
 * Android can only unregister a specific alarm. There is no such thing
 * as cancelAll. Therefore we rely on the Shared Preferences which holds
 * all our alarms to loop through these alarms and unregister them one
 * by one./*from w w  w . ja  v a  2  s.  c om*/
 */
public static void cancelAll() {
    SharedPreferences settings = getSharedPreferences();
    NotificationManager nc = getNotificationManager();
    Map<String, ?> alarms = settings.getAll();
    Set<String> alarmIds = alarms.keySet();

    for (String alarmId : alarmIds) {
        cancel(alarmId);
    }

    nc.cancelAll();
}

From source file:de.schaeuffelhut.android.openvpn.Preferences.java

public final static ArrayList<File> listKnownConfigs(Context context) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    HashSet<File> configs = new HashSet<File>();
    for (String key : preferences.getAll().keySet())
        if (isConfigKey(key))
            configs.add(configOf(key));/*from ww  w  .j a v a2 s .c o  m*/
    configs.addAll(configs(getConfigDir(context, preferences)));
    ArrayList<File> sortedConfigs = new ArrayList<File>(configs);
    Collections.sort(sortedConfigs);
    return sortedConfigs;
}

From source file:com.segment.analytics.internal.Utils.java

/** Copies all the values from {@code src} to {@code target}. */
public static void copySharedPreferences(SharedPreferences src, SharedPreferences target) {
    SharedPreferences.Editor editor = target.edit();
    for (Map.Entry<String, ?> entry : src.getAll().entrySet()) {
        String key = entry.getKey();
        Object value = entry.getValue();
        if (value instanceof String) {
            editor.putString(key, (String) value);
        } else if (value instanceof Set) {
            editor.putStringSet(key, (Set<String>) value);
        } else if (value instanceof Integer) {
            editor.putInt(key, (Integer) value);
        } else if (value instanceof Long) {
            editor.putLong(key, (Long) value);
        } else if (value instanceof Float) {
            editor.putFloat(key, (Float) value);
        } else if (value instanceof Boolean) {
            editor.putBoolean(key, (Boolean) value);
        }/*from w ww  . j  a va  2 s . com*/
    }
    editor.apply();
}

From source file:fr.simon.marquis.preferencesmanager.util.Utils.java

private static void backportBackups(Context ctx) {
    Log.d(TAG, "backportBackups");
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(ctx);
    Editor editor = sp.edit();/*www.  j  a  va2  s . c om*/
    Map<String, ?> keys = sp.getAll();
    if (keys == null) {
        return;
    }

    for (Map.Entry<String, ?> entry : keys.entrySet()) {
        String key = entry.getKey();
        String value = String.valueOf(entry.getValue());

        Log.d(TAG, "key: " + key);

        if (!key.startsWith(BACKUP_PREFIX) && key.matches(PACKAGE_NAME_PATTERN) && value.contains("FILE")
                && value.contains("BACKUPS")) {
            Log.d(TAG, " need to be updated");
            JSONArray array = null;
            try {
                array = new JSONArray(value);
                for (int i = 0; i < array.length(); i++) {
                    JSONObject container = array.getJSONObject(i);
                    String file = container.getString("FILE");
                    if (!file.startsWith(FILE_SEPARATOR)) {
                        container.put("FILE", FILE_SEPARATOR + file);
                    }
                    JSONArray backups = container.getJSONArray("BACKUPS");
                    ArrayList<String> values = new ArrayList<String>(backups.length());
                    for (int j = 0; j < backups.length(); j++) {
                        values.add(String.valueOf(backups.getJSONObject(j).getLong("TIME")));
                    }
                    container.put("BACKUPS", new JSONArray(values));
                }
            } catch (JSONException e) {
                Log.e(TAG, "Error trying to backport Backups", e);
            }
            if (array != null) {
                editor.putString(BACKUP_PREFIX + key, array.toString());
            }
            editor.remove(key);
        }
    }

    editor.commit();
}