Example usage for android.content SharedPreferences contains

List of usage examples for android.content SharedPreferences contains

Introduction

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

Prototype

boolean contains(String key);

Source Link

Document

Checks whether the preferences contains a preference.

Usage

From source file:com.josephblough.sbt.data.Bookmarks.java

public void loadBookmarks(final Context context) {
    // Probably do this in an async task
    try {//from   ww w  .  ja v  a 2s. com
        SharedPreferences prefs = context.getSharedPreferences(TAG, 0);

        // Awards
        int ctr = 1;
        while (prefs.contains(AWARDS_KEY + ctr)) {
            String awardAsJson = prefs.getString(AWARDS_KEY + ctr, null);
            awardBookmarks.add(new Award(new JSONObject(awardAsJson)));
            ctr++;
        }

        //   Generic Posts
        ctr = 1;
        while (prefs.contains(GENERIC_POSTS_KEY + ctr)) {
            String postAsJson = prefs.getString(GENERIC_POSTS_KEY + ctr, null);
            genericPostBookmarks.add(new GenericPost(new JSONObject(postAsJson)));
            ctr++;
        }

        //   Green Posts
        ctr = 1;
        while (prefs.contains(GREEN_POSTS_KEY + ctr)) {
            String postAsJson = prefs.getString(GREEN_POSTS_KEY + ctr, null);
            greenPostBookmarks.add(new GreenPost(new JSONObject(postAsJson)));
            ctr++;
        }

        //   License and Permit Data
        ctr = 1;
        while (prefs.contains(LICENSES_AND_PERMITS_KEY + ctr)) {
            String licensePermitAsJson = prefs.getString(LICENSES_AND_PERMITS_KEY + ctr, null);
            licensePermitBookmarks.add(new LicenseAndPermitData(new JSONObject(licensePermitAsJson)));
            ctr++;
        }

        //    Loan and Grant Data
        ctr = 1;
        while (prefs.contains(LOANS_AND_GRANTS_KEY + ctr)) {
            String loanGrantAsJson = prefs.getString(LOANS_AND_GRANTS_KEY + ctr, null);
            loanGrantBookmarks.add(new LoanAndGrantData(new JSONObject(loanGrantAsJson)));
            ctr++;
        }

        //   Locality Web Data
        ctr = 1;
        while (prefs.contains(LOCALITY_WEB_DATA_KEY + ctr)) {
            String webDataAsJson = prefs.getString(LOCALITY_WEB_DATA_KEY + ctr, null);
            localityWebDataBookmarks.add(new LocalityWebData(new JSONObject(webDataAsJson)));
            ctr++;
        }

        //   Recommended Sites
        ctr = 1;
        while (prefs.contains(RECOMMENDED_SITES_KEY + ctr)) {
            String siteAsJson = prefs.getString(RECOMMENDED_SITES_KEY + ctr, null);
            recommendedSitesBookmarks.add(new RecommendedSite(new JSONObject(siteAsJson)));
            ctr++;
        }

        //   Small Business Programs
        ctr = 1;
        while (prefs.contains(SMALL_BUSINESS_PROGRAMS_KEY + ctr)) {
            String programAsJson = prefs.getString(SMALL_BUSINESS_PROGRAMS_KEY + ctr, null);
            smallBusinessProgramBookmarks.add(new SmallBusinessProgram(new JSONObject(programAsJson)));
            ctr++;
        }

        //   Solicitations
        ctr = 1;
        while (prefs.contains(SOLICITATIONS_KEY + ctr)) {
            String solicitationAsJson = prefs.getString(SOLICITATIONS_KEY + ctr, null);
            solicitationBookmarks.add(new Solicitation(new JSONObject(solicitationAsJson)));
            ctr++;
        }

        //   Offices
        ctr = 1;
        while (prefs.contains(OFFICES_KEY + ctr)) {
            String officeAsJson = prefs.getString(OFFICES_KEY + ctr, null);
            officeBookmarks.add(new SbaDistrictOffice(new JSONObject(officeAsJson)));
            ctr++;
        }

    } catch (JSONException e) {
        Log.e(TAG, e.getMessage(), e);
    }
}

From source file:com.semaphore.sm.MainActivity.java

private void checkFirstRun() {
    boolean needRead = false;

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
    needRead = !prefs.contains("gov");
    if (Device == SemaDevices.Mako)
        needRead = needRead || !prefs.contains("led_red") || !prefs.contains("read_ahead")
                || !prefs.contains("uv_lower_uv") || !prefs.contains("hp_enabled")
                || !prefs.contains("hp_max_online") || !prefs.contains("scaling_min_freq")
                || !prefs.contains("min_br");
    if (Device == SemaDevices.I9000)
        needRead = needRead || !prefs.contains("ab_max_br_threshold") || !prefs.contains("scaling_min_freq");
    if (needRead) {
        PropTask pt = new PropTask();
        pt.execute(sp);/* ww w .  jav a  2 s .c o m*/
    } else {
        sp.getPreferences(this);
    }
}

From source file:org.dpadgett.timer.CountdownFragment.java

private void restoreState() {
    final SharedPreferences prefs = getContext().getSharedPreferences("Countdown", Context.MODE_PRIVATE);

    timingState = new CountdownState((CountdownTextView) timerLayout.findViewById(R.id.countdownTimer), prefs);

    if (prefs.contains("countdownInputs")) {
        long countdownInputs = prefs.getLong("countdownInputs", 0L);
        countdownInputs /= 1000;//ww  w  .  j  a  va  2  s  .c  o m
        countdownSeconds.setValue((int) (countdownInputs % 60));
        countdownInputs /= 60;
        countdownMinutes.setValue((int) (countdownInputs % 60));
        countdownInputs /= 60;
        countdownHours.setValue((int) (countdownInputs % 100));
        inputMode = !timingState.isRunning();
        if (!inputMode) {
            // countdown view
            final LinearLayout inputs = (LinearLayout) rootView.findViewById(R.id.inputsLayout);
            final Button startButton = (Button) rootView.findViewById(R.id.startButton);
            inputs.removeAllViews();
            inputs.addView(timerLayout);
            startButton.setText(getContext().getString(R.string.countdown_button_cancel));
            // timing thread will auto start itself
        }
    }

    alarmSelector.restoreState();
}

From source file:org.runnerup.view.MainLayout.java

void handleBundled(AssetManager mgr, String srcBase, String dstBase) {
    String list[] = null;//from w w  w .java 2  s  .  c  om

    try {
        list = mgr.list(srcBase);
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (list != null) {
        for (String add : list) {
            boolean isFile = false;

            String src = srcBase + File.separator + add;
            String dst = dstBase + File.separator + add;
            try {
                InputStream is = mgr.open(src);
                is.close();
                isFile = true;
            } catch (Exception ex) {
                //Normal, src is directory for first call
            }

            Log.v(getClass().getName(), "Found: " + src + ", " + dst + ", isFile: " + isFile);

            if (!isFile) {
                //The request is hierarchical, source is still on a directory level
                File dstDir = new File(dstBase);
                dstDir.mkdir();
                if (!dstDir.isDirectory()) {
                    Log.w(getClass().getName(),
                            "Failed to copy " + src + " as \"" + dstBase + "\" is not a directory!");
                    continue;
                }
                handleBundled(mgr, src, dst);
            } else {
                //Source is a file, ready to copy
                File dstFile = new File(dst);
                if (dstFile.isDirectory() || dstFile.isFile()) {
                    Log.v(getClass().getName(), "Skip: " + dst + ", isDirectory(): " + dstFile.isDirectory()
                            + ", isFile(): " + dstFile.isFile());
                    continue;
                }

                //Only copy if the key do not exist already
                String key = "install_bundled_" + add;
                SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
                if (pref.contains(key)) {
                    Log.v(getClass().getName(), "Skip already existing pref: " + key);
                    continue;
                }

                pref.edit().putBoolean(key, true).commit();

                Log.v(getClass().getName(), "Copying: " + dst);
                InputStream input = null;
                try {
                    input = mgr.open(src);
                    FileUtil.copy(input, dst);
                    handleHooks(add);
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    FileUtil.close(input);
                }
            }
        }
    }
}

From source file:com.mine.psf.PsfFileBrowserActivity.java

private void handleFirstTimeRun() {
    // Check if the psf root dir is set
    // If not, probably it's the first time run,
    // so ask user to set the psf root dir
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(c);
    if (!settings.contains(getString(R.string.key_psf_root_dir))) {
        Log.d(LOGTAG, "First time run");
        new AlertDialog.Builder(c).setMessage(R.string.first_time_run_dialog_msg)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // Direct to the psf root dir setting
                        Intent intent = new Intent(c, PsfSettingsActivity.class);
                        intent.putExtra(getString(R.string.extra_direct_show_dir_dialog), true);
                        startActivity(intent);
                    }/*from  ww w.  j  a v  a2 s.  com*/
                }).create().show();
    }
}

From source file:org.amahi.anywhere.fragment.NavigationFragment.java

private boolean isConnectionAvailable() {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());

    return preferences.contains(getString(R.string.preference_key_server_connection));
}

From source file:org.creativecommons.thelist.utils.SharedPreferencesMethods.java

public Boolean getAnalyticsOptOut() {
    SharedPreferences sharedPref = mContext.getSharedPreferences(APP_PREFERENCES_KEY, Context.MODE_PRIVATE);
    Boolean bol = null;//from  w w w .j  a  v  a  2s.  c o m

    sharedPref.getBoolean(ANALYTICS_OPTOUT, false);

    if (sharedPref.contains(SharedPreferencesMethods.ANALYTICS_OPTOUT)) {
        bol = sharedPref.getBoolean(ANALYTICS_OPTOUT, false); //defaults to false
        return bol;
    } else {
        return bol;
    }
}

From source file:dynamite.zafroshops.app.fragment.AddZopFragment.java

public ArrayList<MobileCountry> getCountries() {
    ArrayList<MobileCountry> result = new ArrayList<>();

    final SharedPreferences preferences = getActivity().getPreferences(0);
    final SharedPreferences.Editor editor = preferences.edit();
    boolean fromFile = false;

    if (preferences.contains(StorageKeys.COUNTRIES_KEY)) {
        try {/*from w ww  .j a  v  a2 s. c  o  m*/
            ObjectInputStream ois = new ObjectInputStream(
                    getActivity().getBaseContext().openFileInput(StorageKeys.COUNTRIES_KEY));

            zopCountries = (ArrayList<MobileCountry>) ois.readObject();
            zopCountryAdapter.clear();
            zopCountryAdapter.addAll(zopCountries);
            fromFile = true;
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    if (!fromFile) {
        if (zopCountries == null || zopCountries.size() == 0) {
            ListenableFuture<JsonElement> query = MainActivity.MobileClient.invokeApi("mobileCountry", "GET",
                    new ArrayList<Pair<String, String>>());
            Futures.addCallback(query, new FutureCallback<JsonElement>() {
                @Override
                public void onSuccess(JsonElement result) {
                    JsonArray typesAsJson = result.getAsJsonArray();
                    if (typesAsJson != null) {
                        zopCountries = new Gson().fromJson(result, new TypeToken<ArrayList<MobileCountry>>() {
                        }.getType());
                    }
                    zopCountryAdapter.clear();
                    zopCountryAdapter.addAll(zopCountries);
                    setLocation(null);

                    try {
                        ObjectOutputStream oos = new ObjectOutputStream(getActivity().getBaseContext()
                                .openFileOutput(StorageKeys.COUNTRIES_KEY, Context.MODE_PRIVATE));

                        oos.writeObject(zopCountries);
                        oos.flush();
                        oos.close();
                        editor.putString(StorageKeys.COUNTRIES_KEY, StorageKeys.COUNTRIES_KEY);
                        editor.commit();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }

                @Override
                public void onFailure(@NonNull Throwable t) {

                }
            });
        }
    }

    return result;
}

From source file:com.mobilesolutionworks.android.twitter.TwitterPluginFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Bundle arguments = getArguments();/*from  w ww .j a v a  2 s .com*/

    if (arguments == null) {
        throw new IllegalArgumentException("arguments is not set");
    }

    mConsumerKey = arguments.getString("consumerKey");
    mConsumerSecret = arguments.getString("consumerSecret");
    if (TextUtils.isEmpty(mConsumerKey) || TextUtils.isEmpty(mConsumerSecret)) {
        throw new IllegalArgumentException("both consumerKey and consumerSecret is required");
    }

    SharedPreferences preferences = getActivity().getSharedPreferences("twitter", Activity.MODE_PRIVATE);
    if (preferences.contains("access_token_str")) {
        String ats = preferences.getString("access_token_str", "");
        if (!TextUtils.isEmpty(ats)) {
            byte[] decode = Base64.decode(ats, Base64.DEFAULT);
            mAccessToken = SerializationUtils.deserialize(decode);
        }
    }

}

From source file:com.samknows.measurement.AppSettings.java

public LocationType getLocationServiceType() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
    if (prefs.contains(Constants.PREF_LOCATION_TYPE)) {
        String pref = prefs.getString(Constants.PREF_LOCATION_TYPE, null);
        if (pref == null) {
            return null;
        }/*from   w w  w . j  a v a  2  s .c om*/
        if (pref == ctx.getString(R.string.GPS)) {
            return LocationType.gps;
        }
        return LocationType.network;
    }
    return LocationType.gps;
}