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:com.ayogo.cordova.notification.ScheduledNotificationManager.java

public JSONArray getNotifications() {
    LOG.v(NotificationPlugin.TAG, "getNotifications");

    SharedPreferences prefs = getPrefs();
    Map<String, ?> notes = prefs.getAll();

    JSONArray notifications = new JSONArray();

    for (String key : notes.keySet()) {
        try {//ww w  .j  a  v  a2s. c o m
            JSONObject value = new JSONObject(notes.get(key).toString());
            notifications.put(value);
        } catch (JSONException e) {
        }
    }

    LOG.v(NotificationPlugin.TAG, notifications.toString());

    return notifications;
}

From source file:org.gluu.com.ox_push2.store.AndroidKeyDataStore.java

@Override
public List<byte[]> getKeyHandlesByIssuerAndAppId(String issuer, String application) {
    List<byte[]> result = new ArrayList<byte[]>();

    final SharedPreferences keySettings = context.getSharedPreferences(U2F_KEY_PAIR_FILE, Context.MODE_PRIVATE);
    Map<String, String> keyTokens = (Map<String, String>) keySettings.getAll();
    for (Map.Entry<String, String> keyToken : keyTokens.entrySet()) {
        String tokenEntryString = keyToken.getValue();

        TokenEntry tokenEntry = new Gson().fromJson(tokenEntryString, TokenEntry.class);

        if (((issuer == null) || issuer.equals(tokenEntry.getIssuer()))
                && ((application == null) || application.equals(tokenEntry.getApplication()))) {
            String keyHandleKey = keyToken.getKey();
            try {
                byte[] keyHandle = keyToKeyHandle(keyHandleKey);
                result.add(keyHandle);/*from  ww  w.j a  v  a2  s.  co m*/
            } catch (DecoderException ex) {
                Log.e(TAG, "Invalid keyHandle: " + keyHandleKey, ex);
            }
        }
    }
    return result;
}

From source file:m2.android.archetype.sharedpref.BaseSharedPrefModel.java

public Object get(String key, Object defaultValue) {
    if (!getDataMap().containsKey(key)) {
        SharedPreferences pref = getSharedPreferences();
        if (pref.contains(key)) {
            Map<String, ?> prefData = pref.getAll();

            for (Entry<String, ?> entry : prefData.entrySet()) {
                if (!getDataMap().containsKey(entry.getKey())) {
                    getDataMap().put(entry.getKey(), entry.getValue());
                    getDirtyMap().put(entry.getKey(), entry.getValue());
                }//  w  w  w . j  a  v  a2 s.  com
            }
        }
    }

    if (getDataMap().containsKey(key)) {
        return getDataMap().get(key);
    }

    return defaultValue;
}

From source file:com.grarak.kerneladiutor.fragments.kernel.CPUVoltageFragment.java

@Override
public void init(Bundle savedInstanceState) {
    super.init(savedInstanceState);
    SharedPreferences storedvoltagetable = getContext().getSharedPreferences("voltage_table", 0);
    for (Map.Entry entry : storedvoltagetable.getAll().entrySet())
        voltagetable.put(entry.getKey().toString(), entry.getValue().toString());

    Log.i(Constants.TAG, "Volt Table: " + voltagetable);

    mVoltageCard = new EditTextCardView.DEditTextCard[CPUVoltage.getFreqs().size()];
    List<String> voltages = CPUVoltage.getVoltages();
    List<String> frequencies = CPUVoltage.getFreqs();
    if (voltages.isEmpty())
        return;/*from  www .j  a  v  a  2 s. c o  m*/

    if (CPUVoltage.hasOverrideVmin()) {
        mOverrideVminCard = new SwitchCardView.DSwitchCard();
        mOverrideVminCard.setTitle(getString(R.string.override_vmin));
        mOverrideVminCard.setDescription(getString(R.string.override_vmin_summary));
        mOverrideVminCard.setChecked(CPUVoltage.isOverrideVminActive());
        mOverrideVminCard.setFullSpan(true);
        mOverrideVminCard.setOnDSwitchCardListener(this);

        addView(mOverrideVminCard);
    }

    for (int i = 0; i < frequencies.size(); i++) {
        mVoltageCard[i] = new EditTextCardView.DEditTextCard();
        String freq = CPUVoltage.isVddVoltage() ? String.valueOf(Utils.stringToInt(frequencies.get(i)) / 1000)
                : frequencies.get(i);
        mVoltageCard[i].setTitle(freq + getString(R.string.mhz));

        if (voltagetable.get(frequencies.get(i)) != null) {
            int stock = Integer.parseInt(voltagetable.get(frequencies.get(i)));
            int current = Integer.parseInt(voltages.get(i));
            String diff;
            if (stock > current) {
                diff = "(-" + (stock - current) + ")";
            } else if (stock < current) {
                diff = "(+" + (current - stock) + ")";
            } else {
                diff = "";
            }
            mVoltageCard[i].setDescription(voltages.get(i) + getString(R.string.mv) + diff);
        } else {
            mVoltageCard[i].setDescription(voltages.get(i) + getString(R.string.mv));
        }
        mVoltageCard[i].setValue(voltages.get(i));
        mVoltageCard[i].setBase(getString(R.string.mv));
        mVoltageCard[i]
                .setOnDEditTextCardListener(new EditTextCardView.DEditTextCard.OnDEditTextCardListener() {
                    @Override
                    public void onApply(EditTextCardView.DEditTextCard dEditTextCard, String value) {
                        List<String> freqs = CPUVoltage.getFreqs();

                        for (int i = 0; i < mVoltageCard.length; i++)
                            if (dEditTextCard == mVoltageCard[i])
                                CPUVoltage.setVoltage(freqs.get(i), value, getActivity());

                        dEditTextCard.setDescription(value + getString(R.string.mv));
                        refresh();
                    }
                });

        addView(mVoltageCard[i]);
    }

}

From source file:com.normalexception.app.rx8club.preferences.Preferences.java

/**
 * On older APIs android allowed you to save an integer based value
 * in a ListPreference, but when you would try to access it, it caused
 * some big issues.  This is a hack to fix that.
 *//*from w w  w  .  j  ava 2 s  .  c  om*/
@Override
public void addPreferencesFromResource(int resId) {
    SharedPreferences sharedPrefs = getActivity().getSharedPreferences(PreferenceHelper.PREFS_NAME, 0);
    Editor edit = sharedPrefs.edit();
    Map<String, ?> savedPrefs = sharedPrefs.getAll();
    for (Map.Entry<String, ?> entry : savedPrefs.entrySet()) {
        if (entry.getValue() instanceof Integer) {
            Log.w(TAG, String.format("Removing Integer Based Pref: %s", entry.getKey()));
            edit.remove(entry.getKey());
            edit.commit();
        }
    }
    super.addPreferencesFromResource(resId);
}

From source file:de.appplant.cordova.plugin.notification.NotificationWrapper.java

/** 
 * Update an existing notification /*from  ww  w  . ja v a  2  s.c  o m*/
 * 
 * @param updates JSONObject with update-content
 */
public void update(JSONObject updates) {
    String id = updates.optString("id", "0");

    // update shared preferences
    SharedPreferences settings = getSharedPreferences();
    Map<String, ?> alarms = settings.getAll();
    JSONObject arguments;
    try {
        arguments = new JSONObject(alarms.get(id).toString());
    } catch (JSONException e) {
        Log.e("NotificationWrapper", "Update failed. No Notification available for the given id: " + id);
        return;
    }
    arguments = updateArguments(arguments, updates);

    // cancel existing alarm
    Intent intent = new Intent(context, receiver).setAction("" + id);
    PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
    AlarmManager am = getAlarmManager();
    am.cancel(pi);

    //add new alarm
    Options options = new Options(context).parse(arguments);
    schedule(options);
}

From source file:org.gluu.super_gluu.store.AndroidKeyDataStore.java

@Override
public List<LogInfo> getLogs() {
    final SharedPreferences logSettings = context.getSharedPreferences(LOGS_STORE, Context.MODE_PRIVATE);
    Map<String, String> logsMap = (Map<String, String>) logSettings.getAll();
    List<LogInfo> logs = new ArrayList<>();
    for (Map.Entry<String, String> log : logsMap.entrySet()) {
        logs.add(new Gson().fromJson(log.getValue(), LogInfo.class));
    }/*w ww.j  a  v a  2s .com*/
    return logs;
}

From source file:de.appplant.cordova.plugin.notification.NotificationWrapper.java

/**
 * Clear a specific notification without canceling repeating alarms
 * /*from  w  w w.j  ava 2  s.  com*/
 * @param notificationID
 *            The original ID of the notification that was used when it was
 *            registered using add()
 */
public void clear(String notificationId) {
    SharedPreferences settings = getSharedPreferences();
    Map<String, ?> alarms = settings.getAll();
    NotificationManager nc = getNotificationManager();

    try {
        nc.cancel(Integer.parseInt(notificationId));
    } catch (Exception e) {
    }

    JSONObject arguments;
    try {
        arguments = new JSONObject(alarms.get(notificationId).toString());
        Options options = new Options(context).parse(arguments);
        Date now = new Date();
        if ((options.getInterval() != 0)) {
            persist(notificationId, setInitDate(arguments));
        } else if ((new Date(options.getDate()).before(now))) {
            unpersist(notificationId);
        }
    } catch (JSONException e) {
        unpersist(notificationId);
        e.printStackTrace();
        return;
    }
}

From source file:org.gluu.super_gluu.store.AndroidKeyDataStore.java

@Override
public void changeKeyHandleName(TokenEntry tokenEntry, String newName) {
    final SharedPreferences keySettings = context.getSharedPreferences(U2F_KEY_PAIR_FILE, Context.MODE_PRIVATE);
    Map<String, String> keyTokens = (Map<String, String>) keySettings.getAll();
    for (Map.Entry<String, String> keyToken : keyTokens.entrySet()) {
        String tokenEntryString = keyToken.getValue();

        TokenEntry tokenEntryFromDB = new Gson().fromJson(tokenEntryString, TokenEntry.class);

        if (tokenEntryFromDB.getUserName().equalsIgnoreCase(tokenEntry.getUserName())
                && tokenEntryFromDB.getIssuer().equalsIgnoreCase(tokenEntry.getIssuer())) {//keyHandleID != null && StringUtils.equals(keyHandleID, tokenEntry.getIssuer())
            tokenEntry.setKeyName(newName);
            SharedPreferences tokenSettings = context.getSharedPreferences(U2F_KEY_PAIR_FILE,
                    Context.MODE_PRIVATE);
            String tokenEntryStr = new Gson().toJson(tokenEntry);
            String keyHandleKey = keyHandleToKey(tokenEntry.getKeyHandle());
            tokenSettings.edit().putString(keyHandleKey, tokenEntryStr).commit();
            return;
        }//from  www  .  j  a  va 2  s .  c o m
    }
}

From source file:org.phillyopen.mytracks.cyclephilly.UserInfoActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.userprefs);//from   w  w w.  j  a  v a  2s  .c  om
    //Firebase Init
    Firebase.setAndroidContext(this);

    // Don't pop up the soft keyboard until user clicks!
    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    SeekBar sb = (SeekBar) findViewById(R.id.SeekCycleFreq);
    sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar arg0) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onStartTrackingTouch(SeekBar arg0) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
            TextView tv = (TextView) findViewById(R.id.TextFreq);
            tv.setText(freqDesc[arg1 / 100]);
        }
    });

    Button btn = (Button) findViewById(R.id.saveButton);
    btn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            Intent intent = new Intent(UserInfoActivity.this, MainInput.class);
            startActivity(intent);
            finish();
        }

    });

    SharedPreferences settings = getSharedPreferences("PREFS", 0);
    Map<String, ?> prefs = settings.getAll();
    for (Entry<String, ?> p : prefs.entrySet()) {
        int key = Integer.parseInt(p.getKey());
        // CharSequence value = (CharSequence) p.getValue();

        switch (key) {
        case PREF_AGE:
            ((Spinner) findViewById(R.id.ageSpinner)).setSelection(((Integer) p.getValue()).intValue());
            break;
        case PREF_ETHNICITY:
            ((Spinner) findViewById(R.id.ethnicitySpinner)).setSelection(((Integer) p.getValue()).intValue());
            break;
        case PREF_INCOME:
            ((Spinner) findViewById(R.id.incomeSpinner)).setSelection(((Integer) p.getValue()).intValue());
            break;
        case PREF_RIDERTYPE:
            ((Spinner) findViewById(R.id.ridertypeSpinner)).setSelection(((Integer) p.getValue()).intValue());
            break;
        case PREF_RIDERHISTORY:
            ((Spinner) findViewById(R.id.riderhistorySpinner))
                    .setSelection(((Integer) p.getValue()).intValue());
            break;
        case PREF_ZIPHOME:
            ((EditText) findViewById(R.id.TextZipHome)).setText((CharSequence) p.getValue());
            break;
        case PREF_ZIPWORK:
            ((EditText) findViewById(R.id.TextZipWork)).setText((CharSequence) p.getValue());
            break;
        case PREF_ZIPSCHOOL:
            ((EditText) findViewById(R.id.TextZipSchool)).setText((CharSequence) p.getValue());
            break;
        case PREF_EMAIL:
            ((EditText) findViewById(R.id.TextEmail)).setText((CharSequence) p.getValue());
            break;
        case PREF_CYCLEFREQ:
            ((SeekBar) findViewById(R.id.SeekCycleFreq)).setProgress(((Integer) p.getValue()).intValue());
            break;
        case PREF_GENDER:
            int x = ((Integer) p.getValue()).intValue();
            if (x == 2) {
                ((RadioButton) findViewById(R.id.ButtonMale)).setChecked(true);
            } else if (x == 1) {
                ((RadioButton) findViewById(R.id.ButtonFemale)).setChecked(true);
            }
            break;
        }
    }
}