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.lt.adamlee.aagame.GameActivity.java

public void getState() {
    SharedPreferences preferences = getPreferences(Context.MODE_PRIVATE);
    if (preferences.contains("currentLevel")) {
        gameLevel = Integer.parseInt(preferences.getString("currentLevel", null));
    }//from  www. j  av  a  2s.c  o  m
}

From source file:locationkitapp.locationkit.locationkitapp.MapsActivity.java

private void updateLocation() {
    if (!stopShowingLocationUpdates) {
        SharedPreferences prefs = getSharedPreferences(AppConstants.PREFS_FILE, Context.MODE_PRIVATE);
        if (prefs.contains(AppConstants.LATITUDE)) {
            mCurrentLocation = new LatLng(prefs.getFloat(AppConstants.LATITUDE, 0f),
                    prefs.getFloat(AppConstants.LONGITUDE, 0f));
            if (mMap != null) {
                //                    mLocationMarker.setPosition(mCurrentLocation);
                mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mCurrentLocation, AppConstants.MAP_ZOOM));
            }/*  w w  w.  j av a2 s.c  o  m*/
        }
    }
}

From source file:com.dattasmoon.pebble.plugin.NotificationService.java

private void loadPrefs() {
    if (Constants.IS_LOGGABLE) {
        Log.i(Constants.LOG_TAG, "I am loading preferences");
    }//from w w  w  .  j  a  v a2  s .  c  o  m
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);

    SharedPreferences sharedPreferences = getSharedPreferences(Constants.LOG_TAG,
            MODE_MULTI_PROCESS | MODE_PRIVATE);
    //if old preferences exist, convert them.
    if (sharedPreferences.contains(Constants.LOG_TAG + ".mode")) {
        SharedPreferences.Editor editor = sharedPref.edit();
        editor.putInt(Constants.PREFERENCE_MODE,
                sharedPreferences.getInt(Constants.LOG_TAG + ".mode", Constants.Mode.OFF.ordinal()));
        editor.putString(Constants.PREFERENCE_PACKAGE_LIST,
                sharedPreferences.getString(Constants.LOG_TAG + ".packageList", ""));
        editor.putBoolean(Constants.PREFERENCE_NOTIFICATIONS_ONLY,
                sharedPreferences.getBoolean(Constants.LOG_TAG + ".notificationsOnly", true));
        editor.putBoolean(Constants.PREFERENCE_NOTIFICATION_EXTRA,
                sharedPreferences.getBoolean(Constants.LOG_TAG + ".fetchNotificationExtras", false));
        editor.commit();

        //clear out all old preferences
        editor = sharedPreferences.edit();
        editor.clear();
        editor.commit();
        if (Constants.IS_LOGGABLE) {
            Log.i(Constants.LOG_TAG,
                    "Converted preferences to new format. Old ones should be completely gone.");
        }

    }

    mode = Mode.values()[sharedPref.getInt(Constants.PREFERENCE_MODE, Mode.OFF.ordinal())];

    if (Constants.IS_LOGGABLE) {
        Log.i(Constants.LOG_TAG,
                "Service package list is: " + sharedPref.getString(Constants.PREFERENCE_PACKAGE_LIST, ""));
    }

    packages = sharedPref.getString(Constants.PREFERENCE_PACKAGE_LIST, "").split(",");
    notifications_only = sharedPref.getBoolean(Constants.PREFERENCE_NOTIFICATIONS_ONLY, true);
    no_ongoing_notifs = sharedPref.getBoolean(Constants.PREFERENCE_NO_ONGOING_NOTIF, false);
    min_notification_wait = sharedPref.getInt(Constants.PREFERENCE_MIN_NOTIFICATION_WAIT, 0) * 1000;
    notification_extras = sharedPref.getBoolean(Constants.PREFERENCE_NOTIFICATION_EXTRA, false);
    notifScreenOn = sharedPref.getBoolean(Constants.PREFERENCE_NOTIF_SCREEN_ON, true);
    quiet_hours = sharedPref.getBoolean(Constants.PREFERENCE_QUIET_HOURS, false);
    try {
        converts = new JSONArray(sharedPref.getString(Constants.PREFERENCE_CONVERTS, "[]"));
    } catch (JSONException e) {
        converts = new JSONArray();
    }
    try {
        ignores = new JSONArray(sharedPref.getString(Constants.PREFERENCE_IGNORE, "[]"));
    } catch (JSONException e) {
        ignores = new JSONArray();
    }
    try {
        pkg_renames = new JSONArray(sharedPref.getString(Constants.PREFERENCE_PKG_RENAMES, "[]"));
    } catch (JSONException e) {
        pkg_renames = new JSONArray();
    }
    //we only need to pull this if quiet hours are enabled. Save the cycles for the cpu! (haha)
    if (quiet_hours) {
        String[] pieces = sharedPref.getString(Constants.PREFERENCE_QUIET_HOURS_BEFORE, "00:00").split(":");
        quiet_hours_before = new Date(0, 0, 0, Integer.parseInt(pieces[0]), Integer.parseInt(pieces[1]));
        pieces = sharedPref.getString(Constants.PREFERENCE_QUIET_HOURS_AFTER, "23:59").split(":");
        quiet_hours_after = new Date(0, 0, 0, Integer.parseInt(pieces[0]), Integer.parseInt(pieces[1]));
    }

    lastChange = watchFile.lastModified();
}

From source file:net.bible.android.BibleApplication.java

private void upgradePersistentData() {
    SharedPreferences prefs = CommonUtils.getSharedPreferences();
    int prevInstalledVersion = prefs.getInt("version", -1);
    if (prevInstalledVersion < CommonUtils.getApplicationVersionNumber() && prevInstalledVersion > -1) {
        Editor editor = prefs.edit();//from   w  w w. ja va  2s  .c  o  m

        // ver 16 and 17 needed text size pref to be changed to int from string
        if (prevInstalledVersion < 16) {
            Log.d(TAG, "Upgrading preference");
            String textSize = "16";
            if (prefs.contains(TEXT_SIZE_PREF)) {
                Log.d(TAG, "text size pref exists");
                try {
                    textSize = prefs.getString(TEXT_SIZE_PREF, "16");
                } catch (Exception e) {
                    // maybe the conversion has already taken place e.g. in debug environment
                    textSize = Integer.toString(prefs.getInt(TEXT_SIZE_PREF, 16));
                }
                Log.d(TAG, "existing value:" + textSize);
                editor.remove(TEXT_SIZE_PREF);
            }

            int textSizeInt = Integer.parseInt(textSize);
            editor.putInt(TEXT_SIZE_PREF, textSizeInt);

            Log.d(TAG, "Finished Upgrading preference");
        }

        // there was a problematic Chinese index architecture before ver 24 so delete any old indexes
        if (prevInstalledVersion < 24) {
            Log.d(TAG, "Deleting old Chinese indexes");
            Language CHINESE = new Language("zh");

            List<Book> books = SwordDocumentFacade.getInstance().getDocuments();
            for (Book book : books) {
                if (CHINESE.equals(book.getLanguage())) {
                    try {
                        BookIndexer bookIndexer = new BookIndexer(book);
                        // Delete the book, if present
                        if (bookIndexer.isIndexed()) {
                            Log.d(TAG, "Deleting index for " + book.getInitials());
                            bookIndexer.deleteIndex();
                        }
                    } catch (Exception e) {
                        Log.e(TAG, "Error deleting index", e);
                    }
                }
            }
        }
        // add new  
        if (prevInstalledVersion < 61) {
            if (prefs.contains(ScreenSettings.NIGHT_MODE_PREF_NO_SENSOR)) {
                String pref2Val = prefs.getBoolean(ScreenSettings.NIGHT_MODE_PREF_NO_SENSOR, false) ? "true"
                        : "false";
                Log.d(TAG, "Setting new night mode pref list value:" + pref2Val);
                editor.putString(ScreenSettings.NIGHT_MODE_PREF_WITH_SENSOR, pref2Val);
            }
        }

        // add new  
        if (prevInstalledVersion < 89) {
            if (!prefs.contains(ScreenTimeoutSettings.SCREEN_TIMEOUT_PREF)) {
                Log.d(TAG, "Adding default screen timeout setting");
                editor.putString(ScreenTimeoutSettings.SCREEN_TIMEOUT_PREF,
                        Integer.toString(ScreenTimeoutSettings.DEFAULT_VALUE));
            }
        }

        editor.putInt("version", CommonUtils.getApplicationVersionNumber());
        editor.commit();
        Log.d(TAG, "Finished all Upgrading");
    }
}

From source file:com.raspi.chatapp.ui.chatting.ChatActivity.java

/**
 * Sets my username and password used to log into the XMPP server if they
 * aren't already set.<br>/*ww w .  ja  v  a  2s.  c  o m*/
 * The reason I am not hard coding these or making them constants is for
 * further improvements to be made easier. Probably I want the user to
 * choose his buddyId, so I can make a login from within the app possible.
 */
private void setUserPwd() {
    //this is straight forward.
    SharedPreferences preferences = getSharedPreferences(Constants.PREFERENCES, 0);
    if (!preferences.contains(Constants.USERNAME))
        preferences.edit().putString(Constants.USERNAME, "dummy").apply();

    if (!preferences.contains(Constants.PASSWORD))
        preferences.edit().putString(Constants.PASSWORD, "passwdDummy").apply();
}

From source file:com.campusconnect.GoogleSignInActivity.java

private void firebaseAuthWithGoogle(final GoogleSignInAccount acct) {
    Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());
    // [START_EXCLUDE silent]
    showProgressDialog();//from  w w  w  .  j a va  2 s . c o  m
    // [END_EXCLUDE]
    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    mAuth.signInWithCredential(credential).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());
            // If sign in fails, display a message to the user. If sign in succeeds
            // the auth state listener will be notified and logic to handle the
            // signed in user can be handled in the listener.

            if (!task.isSuccessful()) {
                Log.w(TAG, "signInWithCredential", task.getException());
                Toast.makeText(GoogleSignInActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show();
            } else {
                Bundle params = new Bundle();
                params.putString("firebaseauth", "success");
                firebaseAnalytics.logEvent("login_firebase", params);
                personName = acct.getDisplayName();
                personEmail = acct.getEmail();
                personId = acct.getId();
                Log.i("sw32", personId + ": here");
                if (acct.getPhotoUrl() != null) {
                    personPhoto = acct.getPhotoUrl().toString() + "";
                    Log.d("photourl", personPhoto);
                } else
                    personPhoto = "shit";
                //                            mStatusTextView.setText(getString(R.string.signed_in_fmt, acct.getDisplayName()));
                SharedPreferences sharedpreferences = getSharedPreferences("CC", Context.MODE_PRIVATE);
                if (sharedpreferences.contains("profileId")) {
                    Intent home = new Intent(GoogleSignInActivity.this, HomeActivity2.class);
                    home.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(home);
                    finish();
                } else {
                    //TODO: SIGN-IN
                    Retrofit retrofit = new Retrofit.Builder().baseUrl(MyApi.BASE_URL)
                            .addConverterFactory(GsonConverterFactory.create()).build();
                    MyApi myApi = retrofit.create(MyApi.class);
                    Log.i("sw32", personEmail + " : " + personId + " : "
                            + FirebaseInstanceId.getInstance().getToken());
                    MyApi.getProfileRequest body = new MyApi.getProfileRequest(personEmail, personId,
                            FirebaseInstanceId.getInstance().getToken());
                    Call<ModelGetProfile> call = myApi.getProfile(body);
                    call.enqueue(new Callback<ModelGetProfile>() {
                        @Override
                        public void onResponse(Call<ModelGetProfile> call, Response<ModelGetProfile> response) {
                            ModelGetProfile profile = response.body();
                            if (profile != null) {
                                if (profile.getResponse().equals("0")) {
                                    SharedPreferences sharedPreferences = getSharedPreferences("CC",
                                            MODE_PRIVATE);
                                    sharedPreferences.edit().putString("profileId", profile.getProfileId())
                                            .putString("collegeId", profile.getCollegeId())
                                            .putString("personId", personId)
                                            .putString("collegeName", profile.getCollegeName())
                                            .putString("batchName", profile.getBatchName())
                                            .putString("branchName", profile.getBranchName())
                                            .putString("sectionName", profile.getSectionName())
                                            .putString("profileName", personName)
                                            .putString("email", personEmail)
                                            .putString("photourl", profile.getPhotourl()).apply();
                                    Log.d("profileId", profile.getProfileId());
                                    Intent home = new Intent(GoogleSignInActivity.this, HomeActivity2.class);
                                    home.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                    startActivity(home);
                                    finish();
                                } else {
                                    try {
                                        String decider = Branch.getInstance().getLatestReferringParams()
                                                .getString("+clicked_branch_link");
                                        Intent registration = new Intent(GoogleSignInActivity.this,
                                                RegistrationPageActivity.class);
                                        if (decider.equals("false")) {
                                            registration.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                            registration.putExtra("personName", personName);
                                            registration.putExtra("personEmail", personEmail);
                                            registration.putExtra("personPhoto", personPhoto);
                                            registration.putExtra("personId", personId);

                                            startActivity(registration);
                                            finish();
                                            Log.d("branch", "regester called");
                                        }
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }
                                }
                            }
                        }

                        @Override
                        public void onFailure(Call<ModelGetProfile> call, Throwable t) {

                        }
                    });

                }
            }
            // [START_EXCLUDE]
            //Branch login
            try {
                String decider = Branch.getInstance().getLatestReferringParams()
                        .getString("+clicked_branch_link");
                if (decider.equals("true")) {

                    if (Branch.isAutoDeepLinkLaunch(GoogleSignInActivity.this)) {

                        final String collegeId = Branch.getInstance().getLatestReferringParams()
                                .getString("collegeId");
                        final String collegeName = Branch.getInstance().getLatestReferringParams()
                                .getString("collegeName");
                        final String batchName = Branch.getInstance().getLatestReferringParams()
                                .getString("batch");
                        final String branchName = Branch.getInstance().getLatestReferringParams()
                                .getString("branch");
                        final String sectionName = Branch.getInstance().getLatestReferringParams()
                                .getString("sectionName");

                        String brachCoursesId = Branch.getInstance().getLatestReferringParams()
                                .getString("coursesId");
                        Log.d("brancS:", brachCoursesId);
                        String replace = brachCoursesId.replace("[", "");
                        String replace1 = replace.replace("]", "");
                        final List<String> coursesId = new ArrayList<String>(
                                Arrays.asList(replace1.split("\\s*,\\s*")));
                        Log.d("brancL:", coursesId.toString());

                        Retrofit branchRetrofit = new Retrofit.Builder().baseUrl(FragmentCourses.BASE_URL)
                                .addConverterFactory(GsonConverterFactory.create()).build();
                        MyApi myApi = branchRetrofit.create(MyApi.class);
                        final MyApi.getProfileIdRequest request;
                        Log.d("firebase", FirebaseInstanceId.getInstance().getId());
                        request = new MyApi.getProfileIdRequest(personName, collegeId, batchName, branchName,
                                sectionName, personPhoto, personEmail, FirebaseInstanceId.getInstance().getId(),
                                personId);
                        Call<ModelSignUp> modelSignUpCall = myApi.getProfileId(request);
                        modelSignUpCall.enqueue(new Callback<ModelSignUp>() {
                            @Override
                            public void onResponse(Call<ModelSignUp> call, Response<ModelSignUp> response) {
                                ModelSignUp signUp = response.body();
                                if (signUp != null) {
                                    profileId = signUp.getKey();
                                    SharedPreferences sharedPreferences = getSharedPreferences("CC",
                                            MODE_PRIVATE);
                                    sharedPreferences.edit().putString("profileId", profileId)
                                            .putString("collegeId", collegeId).putString("personId", personId)
                                            .putString("collegeName", collegeName)
                                            .putString("batchName", batchName)
                                            .putString("branchName", branchName)
                                            .putString("sectionName", sectionName)
                                            .putString("profileName", personName)
                                            .putString("email", personEmail).putString("photourl", personPhoto)
                                            .apply();
                                    Log.d("branch login sucess", profileId);

                                    Retrofit retrofit = new Retrofit.Builder().baseUrl(FragmentCourses.BASE_URL)
                                            .addConverterFactory(GsonConverterFactory.create()).build();

                                    MyApi branchMyApi = retrofit.create(MyApi.class);
                                    MyApi.subscribeCourseRequest subscribeCourseRequest = new MyApi.subscribeCourseRequest(
                                            profileId, coursesId);
                                    Call<ModelSubscribe> courseSubscribeCall = branchMyApi
                                            .subscribeCourse(subscribeCourseRequest);
                                    courseSubscribeCall.enqueue(new Callback<ModelSubscribe>() {
                                        @Override
                                        public void onResponse(Call<ModelSubscribe> call,
                                                Response<ModelSubscribe> response) {
                                            ModelSubscribe subscribe = response.body();
                                            if (subscribe != null) {
                                                Log.d("branch response:", subscribe.getResponse());
                                                SharedPreferences sharedPreferences = getSharedPreferences("CC",
                                                        MODE_PRIVATE);
                                                sharedPreferences.edit()
                                                        .putString("coursesId", coursesId.toString()).apply();
                                            }
                                            Intent intent_temp = new Intent(getApplicationContext(),
                                                    HomeActivity2.class);
                                            intent_temp.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                            startActivity(intent_temp);
                                            Log.d("branch", "home activity");
                                            Bundle params = new Bundle();
                                            params.putString("course_subscribe", "success");
                                            firebaseAnalytics.logEvent("course_subscribe", params);
                                            finish();
                                        }

                                        @Override
                                        public void onFailure(Call<ModelSubscribe> call, Throwable t) {
                                            Log.d("couses", "failed");
                                        }
                                    });

                                }
                            }

                            @Override
                            public void onFailure(Call<ModelSignUp> call, Throwable t) {
                                Log.d("branch login", "failed");
                            }
                        });

                    } else {
                        Log.e("BRanch", "Launched by normal application flow");
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
            hideProgressDialog();
            // [END_EXCLUDE]

        }

    });
}

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

private void setZops(final boolean force) {
    Activity activity = getActivity();//from   w ww . j  a v  a  2s. co  m
    adapter = new TypedZopListViewAdapter(getActivity(), R.id.listViewItem, typedZops);
    final SharedPreferences preferences = activity.getPreferences(0);

    final SharedPreferences.Editor editor = preferences.edit();
    final ZopType type = (ZopType) getArguments().get(ARG_ZOP_TYPE);
    final String key = StorageKeys.ZOPS_KEY + type.toString();

    zopType = type;

    if (!preferences.contains(key)) {
        InputStream is = getResources().openRawResource(R.raw.zops);
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));

        typedZops = new ArrayList<>(Collections2.filter(
                (ArrayList<MobileZop>) new Gson().fromJson(reader, new TypeToken<ArrayList<MobileZop>>() {
                }.getType()), new Predicate<MobileZop>() {
                    @Override
                    public boolean apply(MobileZop input) {
                        return input.Type == type && (!preferences.contains(StorageKeys.COUNTRY_KEY)
                                || preferences.getString(StorageKeys.COUNTRY_KEY, "").equals("")
                                || input.CountryID.equals(preferences.getString(StorageKeys.COUNTRY_KEY, "")));
                    }
                }));

        try {
            FileOutputStream fos = activity.openFileOutput(key, Context.MODE_PRIVATE);
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            int count = typedZops.size();

            oos.writeObject(typedZops);
            oos.close();
            fos.close();
            editor.putString(key, Integer.toString(count));
            editor.commit();
            setCount(count);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    else if (preferences.contains(key)) {
        try {
            FileInputStream fis = activity.openFileInput(key);
            ObjectInputStream ois = new ObjectInputStream(fis);

            ArrayList<MobileZop> temp = (ArrayList) ois.readObject();
            typedZops = new ArrayList<>(Collections2.filter(temp, new Predicate<MobileZop>() {
                @Override
                public boolean apply(MobileZop input) {
                    return input.Type == type && (!preferences.contains(StorageKeys.COUNTRY_KEY)
                            || preferences.getString(StorageKeys.COUNTRY_KEY, "").equals("")
                            || input.CountryID.equals(preferences.getString(StorageKeys.COUNTRY_KEY, "")));
                }
            }));
            ois.close();
            fis.close();
            setCount(typedZops.size());
            if (adapter != null) {
                adapter.setObjects(typedZops);
                adapter.notifyDataSetChanged();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (StreamCorruptedException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    if (force) {
        final ArrayList<Pair<String, String>> parameters;
        if (MainActivity.LastLocation != null) {
            parameters = new ArrayList<Pair<String, String>>() {
                {
                    add(new Pair<>("latitude", Double.toString(MainActivity.LastLocation.Latitude)));
                    add(new Pair<>("longitude", Double.toString(MainActivity.LastLocation.Longitude)));
                    add(new Pair<>("type", type.getText()));
                }
            };
        } else {
            parameters = new ArrayList<Pair<String, String>>() {
                {
                    add(new Pair<>("type", type.getText()));
                }
            };
        }

        ListenableFuture<JsonElement> result = MainActivity.MobileClient.invokeApi("mobileZop", "GET",
                parameters);

        Futures.addCallback(result, new FutureCallback<JsonElement>() {
            Activity activity = getActivity();

            @Override
            public void onSuccess(JsonElement result) {
                JsonArray typesAsJson = result.getAsJsonArray();
                if (typesAsJson != null) {
                    ArrayList<MobileZop> temp = new Gson().fromJson(result,
                            new TypeToken<ArrayList<MobileZop>>() {
                            }.getType());

                    int max = Collections.max(temp, new Comparator<MobileZop>() {
                        @Override
                        public int compare(MobileZop lhs, MobileZop rhs) {
                            if (lhs.DataVersion < rhs.DataVersion) {
                                return -1;
                            } else if (lhs.DataVersion > rhs.DataVersion) {
                                return 1;
                            } else {
                                return 0;
                            }
                        }
                    }).DataVersion;
                    ((MainActivity) activity).Versions.put(zopType, max);

                    try {
                        FileOutputStream fos = activity.openFileOutput(key, Context.MODE_PRIVATE);
                        ObjectOutputStream oos = new ObjectOutputStream(fos);
                        int count = typedZops.size();

                        typedZops = new ArrayList<>(Collections2.filter(temp, new Predicate<MobileZop>() {
                            @Override
                            public boolean apply(MobileZop input) {
                                return input.Type == type && (!preferences.contains(StorageKeys.COUNTRY_KEY)
                                        || preferences.getString(StorageKeys.COUNTRY_KEY, "").equals("")
                                        || input.CountryID
                                                .equals(preferences.getString(StorageKeys.COUNTRY_KEY, "")));
                            }
                        }));
                        oos.writeObject(typedZops);
                        oos.close();
                        fos.close();
                        editor.putString(key, Integer.toString(count));
                        editor.commit();
                        setCount(count);
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }

                if (adapter != null) {
                    adapter.setObjects(typedZops);
                    resetVisibility(false);
                    adapter.notifyDataSetChanged();
                }
            }

            @Override
            public void onFailure(@NonNull Throwable t) {
                ListView zops = (ListView) activity.findViewById(R.id.listViewZops);
                RelativeLayout loader = (RelativeLayout) activity.findViewById(R.id.relativeLayoutLoader);
                LinearLayout noZops = (LinearLayout) activity.findViewById(R.id.noZops);

                resetVisibility(zops, noZops, loader, false);
            }
        });
    }
}

From source file:com.piusvelte.taplock.client.core.TapLockService.java

@Override
public void onCreate() {
    super.onCreate();
    int currVer = 0;
    try {/*w  w  w  . j a v  a  2 s . com*/
        currVer = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    SharedPreferences sp = (SharedPreferences) getSharedPreferences(KEY_PREFS, MODE_PRIVATE);
    if (!sp.contains(KEY_VERSION) || (currVer > sp.getInt(KEY_VERSION, 0))) {
        sp.edit().putInt(KEY_VERSION, currVer).commit();
        (new BackupManager(this)).dataChanged();
    }
    onSharedPreferenceChanged(getSharedPreferences(KEY_PREFS, MODE_PRIVATE), KEY_DEVICES);
    mBtAdapter = BluetoothAdapter.getDefaultAdapter();
}

From source file:jackpal.androidterm.TermPreferences.java

private boolean readPrefs(Uri uri, boolean clearPrefs) {
    try {/*from ww w .  j  ava2  s.  c o m*/
        InputStream is = this.getApplicationContext().getContentResolver().openInputStream(uri);
        SharedPreferences.Editor prefEdit = PreferenceManager.getDefaultSharedPreferences(this).edit();

        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        Map<String, ?> entries = XmlUtils.readMapXml(is);

        int error = 0;
        for (Map.Entry<String, ?> entry : entries.entrySet()) {
            if (!prefs.contains(entry.getKey()))
                error += 1;
            if (error > 3)
                throw new Exception();
        }
        if (clearPrefs && error == 0)
            prefEdit.clear();

        for (Map.Entry<String, ?> entry : entries.entrySet()) {
            putObject(prefEdit, entry.getKey(), entry.getValue());
        }
        prefEdit.apply();
    } catch (Exception e) {
        AlertDialog.Builder bld = new AlertDialog.Builder(this);
        bld.setIcon(android.R.drawable.ic_dialog_alert);
        bld.setTitle(this.getString(R.string.prefs_read_error_title));
        bld.setMessage(this.getString(R.string.prefs_read_error));
        bld.setPositiveButton(this.getString(android.R.string.ok), null);
        bld.create().show();
        return false;
    }
    return true;
}

From source file:com.aujur.ebookreader.Configuration.java

public List<HighLight> getHightLights(String fileName) {
    SharedPreferences prefs = getPrefsForBook(fileName);

    if (prefs.contains(KEY_HIGHLIGHTS)) {
        return HighLight.fromJSON(fileName, prefs.getString(KEY_HIGHLIGHTS, "[]"));
    }//from   w  w  w.  j  a  v a 2  s.c  o m

    return new ArrayList<HighLight>();
}