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.binary_machinery.avalonschedule.view.ScheduleActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_schedule);
    GlobalEnvironment env = GlobalEnvironment.getInstance();
    if (env.dbProvider == null) {
        env.dbProvider = new DbProvider(this);
    }/* w  w w  . j a  va2  s . c  o  m*/
    List<ScheduleRecord> records = restoreScheduleFromDb();
    m_currentWeekIdx = findTodayCourse(records);
    printScheduleRecords(records);
    scrollToTodayCourse();

    Intent intent = getIntent();
    if (intent != null) {
        String message = intent.getStringExtra(Constants.MESSAGE_EXTRA);
        if (message != null) {
            Utils.showMessageDialog(this, message);
        }
    }

    SharedPreferences prefs = getSharedPreferences(Constants.PREFERENCES_NAME, MODE_PRIVATE);
    if (!prefs.contains(Constants.PREF_IS_SERVICE_ENABLED)) {
        new ServiceLauncher(this).start();
    }
}

From source file:de.fahrgemeinschaft.EditRideActivity.java

@Override
public void onClick(View v) {
    if (ride.getFrom() == null && ride.getTo() == null) {
        Crouton.makeText(this, getString(R.string.incomplete), Style.INFO).show();
    } else {/*from  w ww. j a  v  a 2s .co  m*/
        ride.set(FahrgemeinschaftConnector.COMMENT,
                ((EditText) findViewById(R.id.comment)).getText().toString());
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        if (!prefs.contains(FahrgemeinschaftConnector.EMAIL)) {
            prefs.edit().putString(FahrgemeinschaftConnector.EMAIL,
                    ((PrivacyImageButton) findViewById(R.id.email)).text.getText().toString()).commit();
        }
        ride.marked().dirty().store(this);
        ContentValues cv = new ContentValues();
        cv.put(CONTACT.USER, prefs.getString(CONTACT.USER, EMPTY));
        cv.put(CONTACT.EMAIL, ride.get(CONTACT.EMAIL));
        cv.put(CONTACT.MOBILE, ride.get(CONTACT.MOBILE));
        cv.put(CONTACT.LANDLINE, ride.get(CONTACT.LANDLINE));
        cv.put(CONTACT.PLATE, ride.get(CONTACT.PLATE));
        getContentResolver().insert(Uri.parse(ContactProvider.URI), cv);
        this.getContentResolver().update(RidesProvider.getRidesUri(this), null, null, null);
        startService(new Intent(this, ConnectorService.class).setAction(ConnectorService.PUBLISH));
        Toast.makeText(this, getString(R.string.stored), Toast.LENGTH_SHORT).show();
        overridePendingTransition(R.anim.slide_in_top, R.anim.slide_out_bottom);
        finish();
    }
}

From source file:com.example.administrator.myapplication2._2_exercise._2_End.LeftFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout._2_fragment_main_dummy, container, false);

    Intent myIntent = getActivity().getIntent();
    if (myIntent != null) {
        seq = myIntent.getStringExtra("seq");
    }//from   w ww  .  j  a  v  a  2  s  . c  om

    tvHeart = (TextView) rootView.findViewById(R.id.tvHeart);
    tvDistance = (TextView) rootView.findViewById(R.id.tvDistance);
    tvCalorie = (TextView) rootView.findViewById(R.id.tvCalorie);
    tvWeight = (TextView) rootView.findViewById(R.id.tvWeight);
    tvRuntime = (TextView) rootView.findViewById(R.id.tvRuntime);

    SharedPreferences myPrefs = this.getActivity().getSharedPreferences("login", Context.MODE_PRIVATE);
    if ((myPrefs != null) && (myPrefs.contains("id"))) {
        id = myPrefs.getString("id", "");
        Log.i("logintest", id.toString());
    }

    // getRecentSeq();
    getRecentData();

    return rootView;
}

From source file:com.kii.sample.balance.samples.SampleLoginDialogFragment.java

@OnClick(R.id.button_submit)
void submitClicked() {

    // gets username / password
    String username = mUsernameEdit.getText().toString();
    String password = mPasswordEdit.getText().toString();

    SharedPreferences prefs = getActivity().getSharedPreferences("data", Context.MODE_PRIVATE);

    if (!prefs.contains(username)) {
        showErrorMessage(MESSAGE_INVALID_USERNAME);
        return;/*ww  w .java  2 s. com*/
    }
    RAWPASS = prefs.getString(username, "");
    rawDecryptedToken = Base64.decode(RAWPASS, Base64.DEFAULT);

    FacebookConcealSample fc = new FacebookConcealSample();
    PASS = fc.decryption(rawDecryptedToken, getActivity());

    if (!PASS.equals(password)) {
        showErrorMessage(MESSAGE_INVALID_PASSWORD);
        return;
    }

    // show progress
    ProgressDialogFragment progress = ProgressDialogFragment.newInstance(getActivity(), R.string.login,
            R.string.login);
    progress.show(getFragmentManager(), ProgressDialogFragment.FRAGMENT_TAG);

    Fragment target = getTargetFragment();
    target.onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, null);
    dismiss();

    // call user login API
    //        KiiUser.logIn(new KiiUserCallBack() {
    //            @Override
    //            public void onLoginCompleted(int token, KiiUser user, Exception e) {
    //                super.onLoginCompleted(token, user, e);
    //
    //                ProgressDialogFragment.hide(getFragmentManager());
    //                if (e != null) {
    //                    showErrorMessage(MESSAGE_LOGIN_FAILED);
    //                    return;
    //                }
    //
    //                // notify caller fragment that registration is done.
    //                Fragment target = getTargetFragment();
    //                if (target == null) {
    //                    dismiss();
    //                    return;
    //                }
    //                target.onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, null);
    //                dismiss();
    //            }
    //        }, username, password);
}

From source file:rtandroid.benchmark.MainActivity.java

@Override
public List<TestCase> loadTestCases() {
    List<TestCase> testCaseList = new ArrayList<>();

    // Try to load from settings
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    if (prefs.contains(KEY_TEST_CASES)) {
        Gson gson = new Gson();
        String jsonTestCases = prefs.getString(KEY_TEST_CASES, "");
        TestCase[] cases = gson.fromJson(jsonTestCases, TestCase[].class);
        testCaseList.addAll(Arrays.asList(cases));
    }/*from   ww  w  .j ava2 s  .  c  o m*/

    // Take default ones on first run
    if (testCaseList.isEmpty()) {
        testCaseList.addAll(Arrays.asList(DEFAULT_TEST_CASES));
    }

    return testCaseList;
}

From source file:com.ericrgon.postmark.BaseFragmentActivity.java

protected boolean isPasswordSave() {
    SharedPreferences preferences = getSharedPreferences(CREDENTIALS_PREF_FILE, MODE_PRIVATE);
    return preferences.contains(ENCRYPTED_PASSWORD_PREF)
            && !preferences.getString(ENCRYPTED_PASSWORD_PREF, "").isEmpty();
}

From source file:net.sf.diningout.app.AppApplication.java

/**
 * Move non-user setting preferences from default to app preferences.
 *///  w  w  w.j a va  2  s .c  o m
private void migrateAppPrefs() {
    SharedPreferences def = Prefs.get(this);
    Editor editDef = def.edit();
    SharedPreferences app = Prefs.get(this, APP);
    Editor editApp = app.edit();
    if (def.contains(ACCOUNT_INITIALISED)) {
        editApp.putBoolean(ACCOUNT_INITIALISED, def.getBoolean(ACCOUNT_INITIALISED, false));
        editDef.remove(ACCOUNT_INITIALISED);
    }
    if (def.contains(ACCOUNT_NAME)) {
        editApp.putString(ACCOUNT_NAME, def.getString(ACCOUNT_NAME, null));
        editDef.remove(ACCOUNT_NAME);
    }
    if (def.contains(CLOUD_ID)) {
        editApp.putString(CLOUD_ID, def.getString(CLOUD_ID, null));
        editDef.remove(CLOUD_ID);
    }
    if (def.contains(INSTALL_ID)) {
        editApp.putLong(INSTALL_ID, def.getLong(INSTALL_ID, 0L));
        editDef.remove(INSTALL_ID);
    }
    if (def.contains(LAST_SYNC)) {
        editApp.putLong(LAST_SYNC, def.getLong(LAST_SYNC, 0L));
        editDef.remove(LAST_SYNC);
    }
    if (def.contains(NAVIGATION_DRAWER_OPENED)) {
        editApp.putBoolean(NAVIGATION_DRAWER_OPENED, def.getBoolean(NAVIGATION_DRAWER_OPENED, false));
        editDef.remove(NAVIGATION_DRAWER_OPENED);
    }
    if (def.contains(ONBOARDED)) {
        editApp.putBoolean(ONBOARDED, def.getBoolean(ONBOARDED, false));
        editDef.remove(ONBOARDED);
    }
    editDef.apply();
    editApp.apply();
}

From source file:net.pictulog.otgdb.MainActivityFragment.java

private void backupFiles() {

    Context context = getContext();
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);

    if (!settings.contains(PreferencesActivity.PREFS_FROM_FILE)
            || !settings.contains(PreferencesActivity.PREFS_TO_FILE)) {
        Log.e("MainActivityFragment", "Missing from/to preferences...");
        Toast.makeText(context, R.string.missingFromTo, Toast.LENGTH_LONG).show();
        btnBackup.setEnabled(false);//  w w w  .  j a  v  a  2 s .  c  o m
        return;
    }

    File to = new File(settings.getString(PreferencesActivity.PREFS_TO_FILE, ""));
    if (!to.exists()) {
        Log.e("MainActivityFragment", "Invalid from/to preferences...");
        Toast.makeText(context, R.string.invalidFromTo, Toast.LENGTH_LONG).show();
        btnBackup.setEnabled(false);
        return;
    }
    Log.i("MainActivityFragment", "Copying all files from OTG Disk to " + to);
    try {
        FsDirectory srcDir = fromDir;
        File destDir = new File(settings.getString(PreferencesActivity.PREFS_TO_FILE, Environment
                .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath()));
        List<String> extensions = Arrays
                .asList(settings.getString(PreferencesActivity.PREFS_EXTENSION, "").split(","));
        boolean delete = settings.getBoolean(PreferencesActivity.PREFS_DELETE, false);
        boolean overwrite = settings.getBoolean(PreferencesActivity.PREFS_OVERWRITE, false);
        new BackupTask(this, srcDir, destDir, extensions, delete, overwrite).execute();
    } catch (Exception e) {
        progressDialog.dismiss();
        Log.e("MainActivityFragment", e.getMessage(), e);
        Toast.makeText(context, R.string.backingUpFailed, Toast.LENGTH_LONG).show();
    }
}

From source file:com.zia.freshdocs.preference.CMISPreferencesManager.java

@SuppressWarnings("unchecked")
public Set<NodeRef> getFavorites(Context ctx) {
    Set<NodeRef> favorites = new HashSet<NodeRef>();
    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(ctx);
    String enc = null;// ww  w .  j  a  va  2s  .  com

    if (sharedPrefs.contains(FAVORITES_KEY)) {
        enc = sharedPrefs.getString(FAVORITES_KEY, null);

        if (enc != null) {
            byte[] repr = Base64.decodeBase64(enc.getBytes());
            Object obj = SerializationUtils.deserialize(repr);

            if (obj != null) {
                favorites = (Set<NodeRef>) obj;
            }
        }
    }

    return favorites;
}

From source file:com.ericrgon.postmark.BaseFragmentActivity.java

private byte[] getSalt() {
    SharedPreferences preferences = getSharedPreferences(CREDENTIALS_PREF_FILE, MODE_PRIVATE);
    byte[] salt;/*from  w w  w .j a  v a 2  s  . c om*/
    if (preferences.contains(SALT_PREF)) {
        salt = Base64.decode(preferences.getString(SALT_PREF, ""), Base64.DEFAULT);
    } else {
        //Generate a new salt if one doesn't exist.
        salt = SecurityUtil.generateSalt().getEncoded();
        SharedPreferences.Editor editor = preferences.edit().putString(SALT_PREF,
                Base64.encodeToString(salt, Base64.DEFAULT));
        editor.apply();
    }

    return salt;
}