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:cn.jasonlv.siri.activity.MainActivity.java

/**
 * ?/*from ww  w . j  av  a  2  s . co m*/
 * @param intent
 */
public void bindParams(Intent intent) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    if (sp.getBoolean("tips_sound", true)) {
        intent.putExtra(Constant.EXTRA_SOUND_START, R.raw.bdspeech_recognition_start);
        intent.putExtra(Constant.EXTRA_SOUND_END, R.raw.bdspeech_speech_end);
        intent.putExtra(Constant.EXTRA_SOUND_SUCCESS, R.raw.bdspeech_recognition_success);
        intent.putExtra(Constant.EXTRA_SOUND_ERROR, R.raw.bdspeech_recognition_error);
        intent.putExtra(Constant.EXTRA_SOUND_CANCEL, R.raw.bdspeech_recognition_cancel);
    }
    if (sp.getBoolean(Constant.EXTRA_INFILE, false)) {
        String tmp = sp.getString(Constant.EXTRA_SAMPLE, "").replaceAll(",.*", "").trim();
        int sample = Constant.SAMPLE_8K;
        if (null != tmp && !"".equals(tmp)) {
            sample = Integer.parseInt(tmp);
        }
        if (sample == Constant.SAMPLE_8K) {
            intent.putExtra(Constant.EXTRA_INFILE, "res:///com/baidu/android/voicedemo/8k_test.pcm");
        } else if (sample == Constant.SAMPLE_16K) {
            intent.putExtra(Constant.EXTRA_INFILE, "res:///com/baidu/android/voicedemo/16k_test.pcm");
        }
    }
    if (sp.getBoolean(Constant.EXTRA_OUTFILE, false)) {
        intent.putExtra(Constant.EXTRA_OUTFILE, "sdcard/outfile.pcm");
    }
    if (sp.contains(Constant.EXTRA_SAMPLE)) {
        String tmp = sp.getString(Constant.EXTRA_SAMPLE, "").replaceAll(",.*", "").trim();
        if (null != tmp && !"".equals(tmp)) {
            intent.putExtra(Constant.EXTRA_SAMPLE, Integer.parseInt(tmp));
        }
    }
    if (sp.contains(Constant.EXTRA_LANGUAGE)) {
        String tmp = sp.getString(Constant.EXTRA_LANGUAGE, "").replaceAll(",.*", "").trim();
        if (null != tmp && !"".equals(tmp)) {
            intent.putExtra(Constant.EXTRA_LANGUAGE, tmp);
        }
    }
    if (sp.contains(Constant.EXTRA_NLU)) {
        String tmp = sp.getString(Constant.EXTRA_NLU, "").replaceAll(",.*", "").trim();
        if (null != tmp && !"".equals(tmp)) {
            intent.putExtra(Constant.EXTRA_NLU, tmp);
        }
    }

    if (sp.contains(Constant.EXTRA_VAD)) {
        String tmp = sp.getString(Constant.EXTRA_VAD, "").replaceAll(",.*", "").trim();
        if (null != tmp && !"".equals(tmp)) {
            intent.putExtra(Constant.EXTRA_VAD, tmp);
        }
    }
    String prop = null;
    if (sp.contains(Constant.EXTRA_PROP)) {
        String tmp = sp.getString(Constant.EXTRA_PROP, "").replaceAll(",.*", "").trim();
        if (null != tmp && !"".equals(tmp)) {
            intent.putExtra(Constant.EXTRA_PROP, Integer.parseInt(tmp));
            prop = tmp;
        }
    }

    // offline asr
    {
        intent.putExtra(Constant.EXTRA_OFFLINE_ASR_BASE_FILE_PATH, "/sdcard/easr/s_1");
        intent.putExtra(Constant.EXTRA_LICENSE_FILE_PATH, "/sdcard/easr/license-tmp-20150530.txt");
        if (null != prop) {
            int propInt = Integer.parseInt(prop);
            if (propInt == 10060) {
                intent.putExtra(Constant.EXTRA_OFFLINE_LM_RES_FILE_PATH, "/sdcard/easr/s_2_Navi");
            } else if (propInt == 20000) {
                intent.putExtra(Constant.EXTRA_OFFLINE_LM_RES_FILE_PATH, "/sdcard/easr/s_2_InputMethod");
            }
        }
        intent.putExtra(Constant.EXTRA_OFFLINE_SLOT_DATA, buildTestSlotData());
    }
}

From source file:org.broeuschmeul.android.gps.usb.provider.driver.USBGpsManager.java

public void enableSirfConfig(final SharedPreferences extra) {
    debugLog("spooling SiRF config: " + extra);
    if (isEnabled()) {
        notificationPool.execute(new Runnable() {
            @Override//from  w  ww  . j  a v a2s .c om
            public void run() {
                while ((enabled) && ((!connected) || (connectedGps == null) || (!connectedGps.isReady()))) {
                    debugLog("writing thread is not ready");
                    SystemClock.sleep(500);
                }
                if (isEnabled() && (connected) && (connectedGps != null) && (connectedGps.isReady())) {
                    debugLog("init SiRF config: " + extra);
                    if (extra.contains(USBGpsProviderService.PREF_SIRF_ENABLE_GLL)) {
                        enableNmeaGLL(extra.getBoolean(USBGpsProviderService.PREF_SIRF_ENABLE_GLL, false));
                    }
                    if (extra.contains(USBGpsProviderService.PREF_SIRF_ENABLE_VTG)) {
                        enableNmeaVTG(extra.getBoolean(USBGpsProviderService.PREF_SIRF_ENABLE_VTG, false));
                    }
                    if (extra.contains(USBGpsProviderService.PREF_SIRF_ENABLE_GSA)) {
                        enableNmeaGSA(extra.getBoolean(USBGpsProviderService.PREF_SIRF_ENABLE_GSA, false));
                    }
                    if (extra.contains(USBGpsProviderService.PREF_SIRF_ENABLE_GSV)) {
                        enableNmeaGSV(extra.getBoolean(USBGpsProviderService.PREF_SIRF_ENABLE_GSV, false));
                    }
                    if (extra.contains(USBGpsProviderService.PREF_SIRF_ENABLE_ZDA)) {
                        enableNmeaZDA(extra.getBoolean(USBGpsProviderService.PREF_SIRF_ENABLE_ZDA, false));
                    }
                    if (extra.contains(USBGpsProviderService.PREF_SIRF_ENABLE_STATIC_NAVIGATION)) {
                        enableStaticNavigation(extra
                                .getBoolean(USBGpsProviderService.PREF_SIRF_ENABLE_STATIC_NAVIGATION, false));
                    } else if (extra.contains(USBGpsProviderService.PREF_SIRF_ENABLE_NMEA)) {
                        enableNMEA(extra.getBoolean(USBGpsProviderService.PREF_SIRF_ENABLE_NMEA, true));
                    }
                    if (extra.contains(USBGpsProviderService.PREF_SIRF_ENABLE_SBAS)) {
                        enableSBAS(extra.getBoolean(USBGpsProviderService.PREF_SIRF_ENABLE_SBAS, true));
                    }
                    sendNmeaCommand(callingService.getString(R.string.sirf_nmea_gga_on));
                    sendNmeaCommand(callingService.getString(R.string.sirf_nmea_rmc_on));
                    if (extra.contains(USBGpsProviderService.PREF_SIRF_ENABLE_GGA)) {
                        enableNmeaGGA(extra.getBoolean(USBGpsProviderService.PREF_SIRF_ENABLE_GGA, true));
                    }
                    if (extra.contains(USBGpsProviderService.PREF_SIRF_ENABLE_RMC)) {
                        enableNmeaRMC(extra.getBoolean(USBGpsProviderService.PREF_SIRF_ENABLE_RMC, true));
                    }
                }
            }
        });
    }
}

From source file:com.newsrob.EntryManager.java

public boolean shouldAskForUsageDataCollectionPermission() {
    SharedPreferences sp = getSharedPreferences();
    if (!sp.contains(SETTINGS_USAGE_DATA_COLLECTION_PERMISSION_VERSION))
        return true;

    return false;

}

From source file:net.sf.diningout.content.SyncAdapter.java

@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider,
        SyncResult result) {//from  w  ww  .  j av a2 s .  c o  m
    Account selected = Accounts.selected();
    if (!account.equals(selected)) {
        if (selected != null) { // never going to sync this account that wasn't selected
            ContentResolver.setIsSyncable(account, AUTHORITY, 0);
        }
        return;
    }
    if (extras.containsKey(SYNC_EXTRAS_INITIALIZE)) {
        return; // will initialise on first normal sync
    }
    Context context = getContext();
    SharedPreferences prefs = Prefs.get(context, APP);
    try {
        if (!prefs.getBoolean(ACCOUNT_INITIALISED, false)) { // first run, log the user in
            initUser(context, provider);
        }
        if (extras.getBoolean(SYNC_EXTRAS_CONTACTS_ONLY)) {
            refreshContacts(context, provider);
            uploadContacts(context, provider);
            return;
        }
        if (!prefs.getBoolean(ONBOARDED, false)) {
            return; // don't sync yet
        }
        long now = System.currentTimeMillis(); // full upload and download daily
        boolean dailySync = now - prefs.getLong(LAST_SYNC, 0L) >= DAY_IN_MILLIS;
        if (dailySync || extras.containsKey(SYNC_EXTRAS_MANUAL)) {
            extras.putBoolean(SYNC_EXTRAS_UPLOAD, true);
            extras.putBoolean(SYNC_EXTRAS_DOWNLOAD, true);
            refreshContacts(context, provider);
        }
        if (extras.containsKey(SYNC_EXTRAS_UPLOAD) || extras.containsKey(SYNC_EXTRAS_DOWNLOAD)) {
            uploadContacts(context, provider);
            uploadRestaurants(provider);
            uploadReviews(provider);
            uploadReviewDrafts(provider);
        }
        if (extras.containsKey(SYNC_EXTRAS_DOWNLOAD)) {
            download(provider);
            prefs.edit().putLong(LAST_SYNC, now).apply();
            if (dailySync) {
                refreshRestaurants(context, provider);
                geofenceRestaurants(context, provider);
            }
            Notifications.sync(context);
        }
        if (!prefs.contains(CLOUD_ID)) { // get GCM registration ID and user notification key
            String id = uploadCloudId(context);
            if (!TextUtils.isEmpty(id)) {
                prefs.edit().putString(CLOUD_ID, id).apply();
                // todo service returns HTTP 401, probably should decouple this from cloud_id
                // String key = getCloudNotificationKey(context, selected, id);
                // if (!TextUtils.isEmpty(key)) {
                //     prefs.edit().putString(CLOUD_NOTIFICATION_KEY, key).apply();
                // }
            }
        }
    } catch (RemoteException e) {
        result.databaseError = true;
        Log.e(TAG, "syncing the ContentProvider", e);
        exception(e);
    }
}

From source file:kr.wdream.ui.Components.EmojiView.java

public void loadRecents() {
    SharedPreferences preferences = getContext().getSharedPreferences("emoji", Activity.MODE_PRIVATE);

    String str;//  w w w .  ja  va2 s  . c  o  m
    try {
        emojiUseHistory.clear();
        if (preferences.contains("emojis")) {
            str = preferences.getString("emojis", "");
            if (str != null && str.length() > 0) {
                String[] args = str.split(",");
                for (String arg : args) {
                    String[] args2 = arg.split("=");
                    long value = Utilities.parseLong(args2[0]);
                    String string = "";
                    for (int a = 0; a < 4; a++) {
                        char ch = (char) value;
                        string = String.valueOf(ch) + string;
                        value >>= 16;
                        if (value == 0) {
                            break;
                        }
                    }
                    if (string.length() > 0) {
                        emojiUseHistory.put(string, Utilities.parseInt(args2[1]));
                    }
                }
            }
            preferences.edit().remove("emojis").commit();
            saveRecentEmoji();
        } else {
            str = preferences.getString("emojis2", "");
            if (str != null && str.length() > 0) {
                String[] args = str.split(",");
                for (String arg : args) {
                    String[] args2 = arg.split("=");
                    emojiUseHistory.put(args2[0], Utilities.parseInt(args2[1]));
                }
            }
        }
        if (emojiUseHistory.isEmpty()) {
            if (!preferences.getBoolean("filled_default", false)) {
                String[] newRecent = new String[] { "\uD83D\uDE02", "\uD83D\uDE18", "\u2764", "\uD83D\uDE0D",
                        "\uD83D\uDE0A", "\uD83D\uDE01", "\uD83D\uDC4D", "\u263A", "\uD83D\uDE14",
                        "\uD83D\uDE04", "\uD83D\uDE2D", "\uD83D\uDC8B", "\uD83D\uDE12", "\uD83D\uDE33",
                        "\uD83D\uDE1C", "\uD83D\uDE48", "\uD83D\uDE09", "\uD83D\uDE03", "\uD83D\uDE22",
                        "\uD83D\uDE1D", "\uD83D\uDE31", "\uD83D\uDE21", "\uD83D\uDE0F", "\uD83D\uDE1E",
                        "\uD83D\uDE05", "\uD83D\uDE1A", "\uD83D\uDE4A", "\uD83D\uDE0C", "\uD83D\uDE00",
                        "\uD83D\uDE0B", "\uD83D\uDE06", "\uD83D\uDC4C", "\uD83D\uDE10", "\uD83D\uDE15" };
                for (int i = 0; i < newRecent.length; i++) {
                    emojiUseHistory.put(newRecent[i], newRecent.length - i);
                }
                preferences.edit().putBoolean("filled_default", true).commit();
                saveRecentEmoji();
            }
        }
        sortEmoji();
        adapters.get(0).notifyDataSetChanged();
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }

    try {
        str = preferences.getString("color", "");
        if (str != null && str.length() > 0) {
            String[] args = str.split(",");
            for (int a = 0; a < args.length; a++) {
                String arg = args[a];
                String[] args2 = arg.split("=");
                emojiColor.put(args2[0], args2[1]);
            }
        }
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
}

From source file:com.updetector.MainActivity.java

/** Make sure that Bluetooth is enabled */
public void checkBluetoothEnabled() {
    if (mBluetoothAdapter == null) {
        // Device does not support Bluetooth
        AlertDialog noBluetoothAlert = new AlertDialog.Builder(this).setTitle("Bluetooth not supported.")
                .setPositiveButton("Exit", new DialogInterface.OnClickListener() {
                    public void onClick(final DialogInterface dialog, final int id) {
                    }//w  ww. j av a 2 s  . c  om
                }).setCancelable(true).create();
        noBluetoothAlert.show();
        writeToConsole(
                "This phone does not have Bluetooth capability. Bluetooth connection method will not work.");
    }
    if (!mBluetoothAdapter.isEnabled()) {
        Log.e(LOG_TAG, "bluetooth not enabled yet");
        /** Ask user to enable Bluetooth */
        AlertDialog enableBluetoothDialog = new AlertDialog.Builder(this)
                .setTitle("Please enable Bluetooth on your phone.").setCancelable(false)
                .setPositiveButton("Enable Bluetooth", new DialogInterface.OnClickListener() {
                    public void onClick(final DialogInterface dialog, final int id) {
                        startActivityForResult(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE),
                                Constants.SENSOR_BLUETOOTH);
                    }
                }).setNegativeButton("Skip", new DialogInterface.OnClickListener() {
                    public void onClick(final DialogInterface dialog, final int id) {
                    }
                }).create();
        enableBluetoothDialog.show();
    } else {
        //bluetooth is enabled (directed from onActivityResult())         
        SharedPreferences mPrefs = getSharedPreferences(Constants.SHARED_PREFERENCES, Context.MODE_PRIVATE);
        String carBluetoothDeviceName = null;
        if (mPrefs.contains(Constants.BLUETOOTH_CAR_DEVICE_NAME)) {
            carBluetoothDeviceName = mPrefs.getString(Constants.BLUETOOTH_CAR_DEVICE_NAME, null);
        }
        Log.e(LOG_TAG, "bluetooth enabled " + carBluetoothDeviceName);

        if (carBluetoothDeviceName != null) {
            Intent intent = new Intent(MainActivity.this, BluetoothConnectionService.class);
            startService(intent);
        } else {//ask the user to select a car bluetooth device
            selectBluetoothDevice();
        }
    }
}

From source file:tv.piratemedia.lightcontroler.controller.java

private void newDeviceFound(final String IP, final String Mac) {
    final SharedPreferences Devices = this.getSharedPreferences("devices", MODE_PRIVATE);
    DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
        @Override/*  w w  w .  j  a  v a2 s  . c om*/
        public void onClick(DialogInterface dialog, int which) {
            switch (which) {
            case DialogInterface.BUTTON_POSITIVE:
                Devices.edit().putBoolean(Mac + "-known", true).commit();
                prefs.edit().putString("pref_light_controller_ip", IP).commit();
                Devices.edit().putString(Mac + "-online", Utils.getWifiName());
                gotDevice = true;
                DeviceMac = Mac;
                break;
            case DialogInterface.BUTTON_NEGATIVE:
                Devices.edit().putBoolean(Mac + "-known", false).commit();
                break;
            }
        }
    };

    if (Devices.getAll().size() < 1) {
        prefs.edit().putString("pref_light_controller_ip", IP).commit();
        Devices.edit().putBoolean(Mac + "-known", true);
        Devices.edit().putString(Mac + "-online", Utils.getWifiName());
        gotDevice = true;
        DeviceMac = Mac;
    } else {
        if (!Devices.contains(Mac + "-known")) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setMessage("A new Light Control device has been found, Would you like to save/control it?")
                    .setPositiveButton("Yes", dialogClickListener).setNegativeButton("No", dialogClickListener)
                    .show();
        } else {
            if (Devices.getBoolean(Mac + "-known", false)) {
                gotDevice = true;
                prefs.edit().putString("pref_light_controller_ip", IP).commit();
                DeviceMac = Mac;
            }
        }
    }
}

From source file:com.grazerss.EntryManager.java

public boolean shouldAskForUsageDataCollectionPermission() {
    SharedPreferences sp = getSharedPreferences();
    if (!sp.contains(SETTINGS_USAGE_DATA_COLLECTION_PERMISSION_VERSION)) {
        return true;
    }/*from  w ww  .  j  av a2 s  .co m*/

    return false;

}

From source file:com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser.java

/**
 * Determines whether this user has an active session or not
 * //www  .j  a v  a 2s. c o m
 * @return True if the user has an active session
 */
public boolean isSignedIn() {
    if (usernameInternal == null) {
        return false;
    }
    final SharedPreferences prefs = context.getSharedPreferences("CognitoIdentityProviderCache", 0);
    final String csiIdTokenKey = String.format("CognitoIdentityProvider.%s.%s.idToken", clientId, userId);
    return prefs.contains(csiIdTokenKey);
}

From source file:com.jtschohl.androidfirewall.MainActivity.java

/**
 * Check if the stored preferences are OK
 *//* w w  w.j av a 2 s . c  o  m*/
private void checkPreferences() {
    final SharedPreferences prefs = getSharedPreferences(Api.PREFS_NAME, 0);
    final Editor editor = prefs.edit();
    boolean changed = false;
    if (prefs.getString(Api.PREF_MODE, "").length() == 0) {
        editor.putString(Api.PREF_MODE, Api.MODE_WHITELIST);
        changed = true;
    }
    /* delete the old preference names */
    if (prefs.contains("AllowedUids")) {
        editor.remove("AllowedUids");
        changed = true;
    }
    if (prefs.contains("Interfaces")) {
        editor.remove("Interfaces");
        changed = true;
    }
    if (changed)
        editor.commit();
}