Example usage for android.content SharedPreferences getStringSet

List of usage examples for android.content SharedPreferences getStringSet

Introduction

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

Prototype

@Nullable
Set<String> getStringSet(String key, @Nullable Set<String> defValues);

Source Link

Document

Retrieve a set of String values from the preferences.

Usage

From source file:com.moto.miletus.application.DeviceListAdapter.java

/**
 * loadDevices//from ww w .java  2  s . c  o  m
 *
 * @param context Context
 * @return Set<String>
 */
Set<String> loadDevices(final Context context) {
    final SharedPreferences sp = context.getSharedPreferences(Strings.STORED_DEVICES, 0);
    return sp.getStringSet(Strings.STORED_DEVICES, new HashSet<String>());
}

From source file:org.epstudios.epcoding.ScreenSlideActivity.java

private Set<String> loadCodeNumbers() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    Set<String> defaultStringSet = new TreeSet<String>();
    Set<String> codeNumbersChecked = new TreeSet<String>();
    codeNumbersChecked.addAll(prefs.getStringSet("wizardremovalcodes", defaultStringSet));
    codeNumbersChecked.addAll(prefs.getStringSet("wizardaddingcodes", defaultStringSet));
    codeNumbersChecked.addAll(prefs.getStringSet("wizardfinalcodes", defaultStringSet));
    return codeNumbersChecked;
}

From source file:com.android.madpausa.cardnotificationviewer.ConcreteNotificationListenerService.java

private NotificationFilter initAlwaysHideFilter() {
    NotificationFilter filter = (NotificationFilter) baseNotificationFilter.clone();
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    Set<String> set = sp.getStringSet(ALWAYS_ARCHIVE_PREF, new HashSet<String>());
    return filter.setPkgFilter(set).addPkgFilter("");
}

From source file:com.android.madpausa.cardnotificationviewer.ConcreteNotificationListenerService.java

public void addToAlwaysArchived(StatusBarNotification sbn) {
    alwaysArchiveFilter.addPkgFilter(sbn.getPackageName());
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    Set<String> set = sp.getStringSet(ALWAYS_ARCHIVE_PREF, null);
    if (set == null) {
        set = new HashSet<>();
    }/*  ww  w.  j  ava 2  s  . co  m*/
    set.add(sbn.getPackageName());

    SharedPreferences.Editor editor = sp.edit();
    editor.putStringSet(ALWAYS_ARCHIVE_PREF, set);

    editor.apply();
}

From source file:com.careme.apvereda.careme.AccumulatorService.java

private void updateList(Location loc) {
    SharedPreferences shared = getApplicationContext().getSharedPreferences("monitor", Context.MODE_PRIVATE);
    Set<String> ids = shared.getStringSet("routines", new HashSet<String>());
    Iterator<String> it = ids.iterator();
    List<RoutinePlace> rlist;
    RoutinePlace r;/*from w w  w . ja v a 2s.  c o  m*/
    Location l1 = new Location("l1");
    Location l2 = new Location("l2");
    while (it.hasNext()) {
        String id = it.next();
        rlist = db.getRoutinePlaces(Integer.parseInt(id));
        l1.setLongitude(rlist.get(0).getPlace().getLongitude());
        l2.setLongitude(rlist.get(1).getPlace().getLongitude());
        l1.setLatitude(rlist.get(0).getPlace().getLatitude());
        l2.setLatitude(rlist.get(1).getPlace().getLatitude());

        double v1 = (l1.distanceTo(l2) + 500) / (rlist.get(0).getRoutine().getEnd().getTime()
                - rlist.get(0).getRoutine().getStart().getTime());
        long t1 = new Date().getTime() % 86400000;
        long t2 = rlist.get(0).getRoutine().getEnd().getTime() % 86400000;
        double v2 = (loc.distanceTo(l2)) / (t2 - t1);
        if (v2 > v1) {
            ids.remove(id);
            if (id.compareTo(shared.getString("probably", Integer.toString(-1))) == 0) {
                shownot("Se ha salido de la rutina ms probable!");
            }
        }
    }
    SharedPreferences.Editor editor = shared.edit();
    editor.putStringSet("routines", ids);
    editor.commit();
    if (ids.size() == 0) {
        shownot("Se ha salido de la rutina!");
    }
}

From source file:com.imobilize.blogposts.fragments.SubscribeFragment.java

public void enableDisableCheckBoxes() {

    final SharedPreferences prefs = getGcmPreferences(context);
    Set<String> checkedCategories = prefs.getStringSet(Constants.CHECKED_CATEGORIES, null);
    CheckBox checkedCheckBox;/*  w w  w .  j  a va 2  s . c  o m*/

    if (checkedCategories != null) {

        Iterator<String> iterator = checkedCategories.iterator();
        while (iterator.hasNext()) {

            checkedCheckBox = findCheckBoxByName(iterator.next());
            checkedCheckBox.setChecked(true);
        }

        for (Entry<String, CheckBox> e : checkList.entrySet()) {
            CheckBox checkBoxVal = e.getValue();
            checkBoxVal.setEnabled(false);
        }
    }
}

From source file:com.android.madpausa.cardnotificationviewer.ConcreteNotificationListenerService.java

public void removeFromAlwaysArchived(StatusBarNotification sbn) {
    alwaysArchiveFilter.removePkgFilter(sbn.getPackageName());
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    Set<String> set = sp.getStringSet(ALWAYS_ARCHIVE_PREF, null);
    if (set == null) {
        return;// w  ww  .  j  a va2s.c o m
    }
    set.remove(sbn.getPackageName());

    SharedPreferences.Editor editor = sp.edit();

    if (set.isEmpty())
        editor.remove(ALWAYS_ARCHIVE_PREF);
    else
        editor.putStringSet(ALWAYS_ARCHIVE_PREF, set);

    editor.apply();
}

From source file:com.google.android.apps.dashclock.gmail.GmailExtension.java

private Set<String> getSelectedAccounts() {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    final String[] accounts = GmailExtension.getAllAccountNames(this);
    Set<String> allAccountsSet = new HashSet<String>();
    allAccountsSet.addAll(Arrays.asList(accounts));
    return sp.getStringSet(PREF_ACCOUNTS, allAccountsSet);
}

From source file:org.xbmc.kore.ui.AddonDetailsFragment.java

private void updatePinButton() {
    SharedPreferences prefs = getActivity().getSharedPreferences("addons", Context.MODE_PRIVATE);
    Set<String> bookmarked = prefs.getStringSet("bookmarked", Collections.<String>emptySet());
    setupPinButton(bookmarked.contains(addonId));
}

From source file:dude.morrildl.weatherport.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // this gets a little hairy, but each class is too trivial to bother
    // moving to its own file; but together they add up to be a little
    // irritating. So it goes.

    // first we need to inflate the View for the Action Bar operations, and
    // then set click handlers on them. This one is is the add-new-airport
    // dialog,/*from w ww .  j a v  a2s.c  om*/
    // which cascades a bit
    getMenuInflater().inflate(R.menu.main, menu);
    menu.findItem(R.id.action_add).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            // yo dawg, I hurd you like callbacks
            LayoutInflater inflater = MainActivity.this.getLayoutInflater();
            View v = inflater.inflate(R.layout.dialog, null);
            final EditText et = (EditText) v.findViewById(R.id.dialog_input);

            // this is the
            // "enter a new airport code to add to the list" dialog
            AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
            final AlertDialog dialog = builder.setTitle(R.string.dialog_title).setIcon(R.drawable.ic_launcher)
                    .setView(v).setPositiveButton(R.string.dialog_pos, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            String newAirport = et.getText().toString().toUpperCase();
                            SharedPreferences prefs = MainActivity.this.getSharedPreferences("prefs",
                                    Context.MODE_PRIVATE);
                            Set<String> currentList = prefs.getStringSet("airports", new HashSet<String>());
                            HashSet<String> newSet = new HashSet<String>();
                            newSet.addAll(currentList);
                            newSet.add(newAirport);
                            prefs.edit().putStringSet("airports", newSet).commit();
                            ArrayList<String> newList = new ArrayList<String>();
                            newList.addAll(newSet);
                            Collections.sort(newList);
                            adapter.clear();
                            adapter.addAll(newList);
                            // I N C E P T I O N
                        }
                    }).setNegativeButton(R.string.dialog_neg, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    }).create();
            et.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                @Override
                public void onFocusChange(View v, boolean focused) {
                    if (focused) {
                        dialog.getWindow()
                                .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                    }
                }
            });
            dialog.show();
            return true;
        }
    });

    // ...and this one launches our FOSS compliance screen.
    menu.findItem(R.id.action_settings).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Intent intent = new Intent();
            intent.setClass(MainActivity.this, AboutActivity.class);
            MainActivity.this.startActivity(intent);
            return true;
        }
    });
    return true;
}