SharedPreferences contains - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for SharedPreferences contains method.

This code example shows how to use the following methods:contains, edit
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:contains
		this.sharedPreferences = sharedPreferences;
		this.key = key;
	} 
 
	public final boolean exists() { 
		return sharedPreferences.contains(key);
	} 
 
	public final void remove() { 
		apply(edit().remove(key));
	} 
 
	protected Editor edit() {
		return sharedPreferences.edit();
	} 
 
	protected final void apply(Editor editor) {
		SharedPreferencesCompat.apply(editor);
	} 
 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:contains
		return sharedPrefs.getAll();
	} 
 
	@Override 
	public boolean contains (String key) {
		return sharedPrefs.contains(key);
	} 
 
	@Override 
	public void clear () { 
		edit(); 
		editor.clear();
	} 
 
	@Override 
	public void flush () { 
		if (editor != null) {
			editor.commit();
			editor = null;
		} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:contains
    } 
  } 
 
  public static boolean hasAsymmericMasterSecret(Context context) {
    SharedPreferences settings = context.getSharedPreferences(PREFERENCES_NAME, 0);
    return settings.contains(ASYMMETRIC_LOCAL_PUBLIC);
  } 
 
  public static boolean isPassphraseInitialized(Context context) {
    SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_NAME, 0);
    return preferences.getBoolean("passphrase_initialized", false);
  } 
 
  private static void encryptWithPassphraseAndSave(Context context, byte[] masterSecret, String passphrase) throws GeneralSecurityException {
    byte[] encryptedMasterSecret        = encryptWithPassphrase(context, masterSecret, passphrase);
    byte[] encryptedAndMacdMasterSecret = macWithPassphrase(context, encryptedMasterSecret, passphrase);
 
    save(context, "master_secret", encryptedAndMacdMasterSecret);
    save(context, "passphrase_initialized", true);
  } 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:contains
	 * Doesn't check for correctness of data. 
	 * @return <code>true</code> if XMPP connection parameters are all set, 
	 * 		<code>false</code> otherwise. 
	 */ 
	public boolean checkSetupDone() { 
		return mSharedPreferences.contains("pref_host") 
				&& mSharedPreferences.contains("pref_service") 
				&& mSharedPreferences.contains("pref_xmpp_user") 
				&& mSharedPreferences.contains("pref_xmpp_password");
	} 
 
	public SharedPreferences getSharedPreferences() {
		return mSharedPreferences;
	} 
 
	public void setSharedPreferencesName(Context ctx, String sharedPreferencesName) {
		this.sharedPreferencesName = sharedPreferencesName;
		this.mSharedPreferences = ctx.getSharedPreferences(sharedPreferencesName, Context.MODE_PRIVATE);
	} 
	 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:contains, edit
	} 
	 
	void applyToPrefs(SharedPreferences prefs, boolean landscape, boolean overwrite) { 
		final String prefLayoutBase = "Controls." + (landscape ? "Landscape." : "Portrait."); 
		final String prefBase = prefLayoutBase + getButtonName(id) + "." ; 
		if(prefs.contains(prefBase + "Left") && !overwrite) 
			return; 
		prefs.edit().putInt(prefBase + "Left", position.left).putInt(prefBase + "Top", position.top).putInt(prefBase + "Right", position.right).putInt(prefBase + "Bottom", position.bottom).apply(); 
	} 
	 
	static final int BUTTON_RIGHT = 0; 
	static final int BUTTON_DOWN = 1; 
	static final int BUTTON_UP = 2; 
	static final int BUTTON_LEFT = 3; 
	static final int BUTTON_A = 4; 
	static final int BUTTON_B = 5; 
	static final int BUTTON_X = 6; 
	static final int BUTTON_Y = 7; 
	static final int BUTTON_L = 8; 
	static final int BUTTON_R = 9; 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:contains, edit
    private static final String PAGE_SIZE = "page_size";
     
    private static final int DEFAULT_PAGE_SIZE = 30;
     
    public static void setupPreferences(SharedPreferences preferences) {
    	Editor editor = preferences.edit();
        if(!preferences.contains(TOKEN)) {
        	editor.putString(TOKEN, "");
        } 
        if(!preferences.contains(PAGE_SIZE)) {
        	editor.putInt(PAGE_SIZE, DEFAULT_PAGE_SIZE);
        } 
        editor.commit();
    } 
     
    public static boolean setToken(SharedPreferences prefs, String token) {
    	Editor editor = prefs.edit();
    	editor.putString(TOKEN, token);
    	return editor.commit();
    } 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:contains, getString
                || key.equals(CameraSettings.KEY_TIMER_SOUND_EFFECTS);
    } 
 
    @Override 
    public String getString(String key, String defValue) {
        if (isGlobal(key) || !mPrefLocal.contains(key)) {
            return mPrefGlobal.getString(key, defValue);
        } else { 
            return mPrefLocal.getString(key, defValue);
        } 
    } 
 
    @Override 
    public int getInt(String key, int defValue) {
        if (isGlobal(key) || !mPrefLocal.contains(key)) {
            return mPrefGlobal.getInt(key, defValue);
        } else { 
            return mPrefLocal.getInt(key, defValue);
        } 
    } 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:contains, edit, getBoolean
	} 
 
	/* Force values to match the defaults the first time round, so the preferences screen reflects that. This is only necessary 
	 * where the default is `true', since on-screen the default is `false'. */ 
	public boolean autoDbUpdate() { 
		if (!mPrefs.contains(AUTOUPDATE_KEY)) {
			mPrefs.edit().putBoolean(AUTOUPDATE_KEY, true).commit();
		} 
		return mPrefs.getBoolean(AUTOUPDATE_KEY, true);
	} 
 
	public boolean showAllBusses() { 
		return mPrefs.getBoolean(SHOWALLBUSSES_KEY, false);
	} 
 
	public boolean showAMPMTimes() { 
		return mPrefs.getBoolean(AMPMTIMES_KEY, false);
	} 
 
	public void AddBusstopFavourite(String busstop, String stopname) {
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:contains, getInt, getString
        SharedPreferences p = c.getSharedPreferences(PREFERENCES_FILE, MODE_WORLD_READABLE);
        /* 
         * Get the position and value of the spinner from the file, or a default value if the 
         * key-value pair does not exist. 
         */ 
        this.mPos = p.getInt(POSITION_KEY, SpinnerActivity.DEFAULT_POSITION);
        this.mSelection = p.getString(SELECTION_KEY, "");
 
        /* 
         * SharedPreferences doesn't fail if the code tries to get a non-existent key. The 
         * most straightforward way to indicate success is to return the results of a test that 
         * SharedPreferences contained the position key. 
         */ 
 
          return (p.contains(POSITION_KEY));
 
        } 
 
    /** 
     * Write the application's current state to a properties repository. 
7
CodeRank
Experience pair programming with AI  Get Codota for Java

Related SharedPreferences contains Questions & Answers:

contains Method Overview
Checks whether the preferences contains a preference.
See Code Examples for other Android SharedPreferences Methods: