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:Main.java

/**
 * Returns the cached device group key for this device. Device secret is generated when the device
 * is confirmed and is used for device identification.
 *
 * @param username          REQUIRED: The current user.
 * @param userPoolId        REQUIRED: Client ID of the application.
 * @param context           REQUIRED: Application context.
 * @return device group key as String, null if the device-key is not available.
 */// w  w w  .j  av a2s .co  m
public static String getDeviceGroupKey(String username, String userPoolId, Context context) {
    try {
        SharedPreferences cipCachedDeviceDetails = context
                .getSharedPreferences(getDeviceDetailsCacheForUser(username, userPoolId), 0);
        if (cipCachedDeviceDetails != null && cipCachedDeviceDetails.contains(COGNITO_DEVICE_GROUP_KEY)) {
            return cipCachedDeviceDetails.getString(COGNITO_DEVICE_GROUP_KEY, null);
        }
    } catch (Exception e) {
        Log.e(TAG, "Error accessing SharedPreferences" + e.getMessage());
    }
    return null;
}

From source file:Main.java

/**
 * Returns the cached device secret for this device. Device secret is generated when the device
 * is confirmed and is used for device identification.
 *
 * @param username          REQUIRED: The current user.
 * @param userPoolId        REQUIRED: Client ID of the application.
 * @param context           REQUIRED: Application context.
 * @return device secret as String, null if the device-key is not available.
 *//*  w  w w. j ava2 s  . co m*/
public static String getDeviceSecret(String username, String userPoolId, Context context) {
    try {
        SharedPreferences cipCachedDeviceDetails = context
                .getSharedPreferences(getDeviceDetailsCacheForUser(username, userPoolId), 0);
        if (cipCachedDeviceDetails != null && cipCachedDeviceDetails.contains(COGNITO_DEVICE_SECRET)) {
            return cipCachedDeviceDetails.getString(COGNITO_DEVICE_SECRET, null);
        }
    } catch (Exception e) {
        Log.e(TAG, "Error accessing SharedPreferences" + e.getMessage());
    }
    return null;
}

From source file:org.kde.kdeconnect.Helpers.SecurityHelpers.RsaHelper.java

public static void initialiseRsaKeys(Context context) {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);

    if (!settings.contains("publicKey") || !settings.contains("privateKey")) {

        KeyPair keyPair;/*  w ww  .  j  ava2  s. c  o  m*/
        try {
            KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
            keyGen.initialize(2048);
            keyPair = keyGen.genKeyPair();
        } catch (Exception e) {
            e.printStackTrace();
            Log.e("KDE/initializeRsaKeys", "Exception");
            return;
        }

        byte[] publicKey = keyPair.getPublic().getEncoded();
        byte[] privateKey = keyPair.getPrivate().getEncoded();

        SharedPreferences.Editor edit = settings.edit();
        edit.putString("publicKey", Base64.encodeToString(publicKey, 0).trim() + "\n");
        edit.putString("privateKey", Base64.encodeToString(privateKey, 0));
        edit.apply();

    }

}

From source file:net.texh.cordovapluginstepcounter.CordovaStepCounter.java

public static int getTotalCount(SharedPreferences sharedPref) {
    Integer totalCount = 0;/*from w ww  .  j  a  va  2s . c o  m*/
    if (sharedPref.contains(CordovaStepCounter.PEDOMETER_TOTAL_COUNT_PREF)) {
        totalCount = sharedPref.getInt(CordovaStepCounter.PEDOMETER_TOTAL_COUNT_PREF, 0);
    }
    return totalCount;
}

From source file:net.texh.cordovapluginstepcounter.CordovaStepCounter.java

public static boolean getPedometerIsActive(SharedPreferences sharedPref) {
    Boolean pActive = false;//  ww  w .  java 2s  .  c o  m
    if (sharedPref.contains(CordovaStepCounter.PEDOMETER_ACTIVE_PREF)) {
        pActive = sharedPref.getBoolean(CordovaStepCounter.PEDOMETER_ACTIVE_PREF, false);
    }
    return pActive;
}

From source file:com.google.android.apps.muzei.settings.Prefs.java

private static void migratePreferences(SharedPreferences source, SharedPreferences destination) {
    if (source.getBoolean(PREF_MIGRATED, false)) {
        return;//from   w w w. ja  v  a 2 s. c  o m
    }
    SharedPreferences.Editor sourceEditor = source.edit();
    SharedPreferences.Editor destinationEditor = destination.edit();

    if (source.contains(PREF_GREY_AMOUNT)) {
        destinationEditor.putInt(PREF_GREY_AMOUNT, source.getInt(PREF_GREY_AMOUNT, 0));
        sourceEditor.remove(PREF_GREY_AMOUNT);
    }
    if (source.contains(PREF_DIM_AMOUNT)) {
        destinationEditor.putInt(PREF_DIM_AMOUNT, source.getInt(PREF_DIM_AMOUNT, 0));
        sourceEditor.remove(PREF_DIM_AMOUNT);
    }
    if (source.contains(PREF_BLUR_AMOUNT)) {
        destinationEditor.putInt(PREF_BLUR_AMOUNT, source.getInt(PREF_BLUR_AMOUNT, 0));
        sourceEditor.remove(PREF_BLUR_AMOUNT);
    }
    if (source.contains(PREF_DISABLE_BLUR_WHEN_LOCKED)) {
        destinationEditor.putBoolean(PREF_DISABLE_BLUR_WHEN_LOCKED,
                source.getBoolean(PREF_DISABLE_BLUR_WHEN_LOCKED, false));
        sourceEditor.remove(PREF_DISABLE_BLUR_WHEN_LOCKED);
    }
    sourceEditor.putBoolean(PREF_MIGRATED, true);
    sourceEditor.apply();
    destinationEditor.apply();
}

From source file:im.vector.util.PhoneNumberUtils.java

/**
 * Provide the selected country code/*from w  w  w .  j av  a 2 s .co  m*/
 *
 * @param context the application context
 * @return the ISO country code or "" if it does not exist
 */
public static String getCountryCode(final Context context) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);

    if (!preferences.contains(COUNTRY_CODE_PREF_KEY)
            || TextUtils.isEmpty(preferences.getString(COUNTRY_CODE_PREF_KEY, ""))) {
        try {
            TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
            String countryCode = tm.getNetworkCountryIso().toUpperCase();
            setCountryCode(context, countryCode);
        } catch (Exception e) {
            Log.e(LOG_TAG, "## getCountryCode failed " + e.getMessage());
        }
    }

    return preferences.getString(COUNTRY_CODE_PREF_KEY, "");
}

From source file:com.example.cal.mysunshine.Utility.java

public static boolean isLocationAvailable(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    return prefs.contains(context.getString(R.string.pref_location_latitude))
            && prefs.contains(context.getString(R.string.pref_location_longitude));
}

From source file:org.opendatakit.survey.android.logic.PropertiesSingleton.java

public static boolean containsKey(String appName, String propertyName) {
    if (isSecureProperty(propertyName)) {
        // this needs to be stored in a protected area
        SharedPreferences sharedPreferences = PreferenceManager
                .getDefaultSharedPreferences(Survey.getInstance().getApplicationContext());
        return sharedPreferences.contains(appName + "_" + propertyName);
    } else {//w  ww  .  j  a  va 2 s.  c  om
        PropertiesSingleton s = getSingleton(appName);
        return s.containsKey(propertyName);
    }
}

From source file:com.jerrellmardis.amphitheatre.util.Utils.java

public static void checkPrefs(SharedPreferences sharedPrefs) {
    SharedPreferences.Editor editor = sharedPrefs.edit();

    if (!sharedPrefs.contains(Constants.PALETTE_BACKGROUND_VISIBLE)) {
        editor.putString(Constants.PALETTE_BACKGROUND_VISIBLE, Enums.PalettePresenterType.FOCUSEDCARD.name());
    }//from   w  w w.  j a  v  a  2 s.  com
    if (!sharedPrefs.contains(Constants.PALETTE_BACKGROUND_UNSELECTED)) {
        editor.putString(Constants.PALETTE_BACKGROUND_UNSELECTED, "");
    }
    if (!sharedPrefs.contains(Constants.PALETTE_BACKGROUND_SELECTED)) {
        editor.putString(Constants.PALETTE_BACKGROUND_SELECTED, Enums.PaletteColor.DARKMUTED.name());
    }
    if (!sharedPrefs.contains(Constants.PALETTE_TITLE_VISIBLE)) {
        editor.putString(Constants.PALETTE_TITLE_VISIBLE, Enums.PalettePresenterType.NOTHING.name());
    }
    if (!sharedPrefs.contains(Constants.PALETTE_TITLE_UNSELECTED)) {
        editor.putString(Constants.PALETTE_TITLE_UNSELECTED, "");
    }
    if (!sharedPrefs.contains(Constants.PALETTE_TITLE_SELECTED)) {
        editor.putString(Constants.PALETTE_TITLE_UNSELECTED, "");
    }
    if (!sharedPrefs.contains(Constants.PALETTE_CONTENT_VISIBLE)) {
        editor.putString(Constants.PALETTE_CONTENT_VISIBLE, Enums.PalettePresenterType.NOTHING.name());
    }
    if (!sharedPrefs.contains(Constants.PALETTE_CONTENT_UNSELECTED)) {
        editor.putString(Constants.PALETTE_CONTENT_UNSELECTED, "");
    }
    if (!sharedPrefs.contains(Constants.PALETTE_CONTENT_SELECTED)) {
        editor.putString(Constants.PALETTE_CONTENT_UNSELECTED, "");
    }
    if (!sharedPrefs.contains(Constants.BACKGROUND_BLUR)) {
        editor.putString(Constants.BACKGROUND_BLUR, Enums.BlurState.ON.name());
    }

    editor.apply();
}