List of usage examples for android.content SharedPreferences contains
boolean contains(String key);
From source file:com.baidu.android.voicedemo.ActivityTouch.java
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); }// w w w .j a va 2 s. co m if (sp.contains(Constant.EXTRA_INFILE)) { String tmp = sp.getString(Constant.EXTRA_INFILE, "").replaceAll(",.*", "").trim(); intent.putExtra(Constant.EXTRA_INFILE, tmp); } 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:github.daneren2005.dsub.activity.SubsonicFragmentActivity.java
private void loadSettings() { PreferenceManager.setDefaultValues(this, R.xml.settings, false); SharedPreferences prefs = Util.getPreferences(this); if (!prefs.contains(Constants.PREFERENCES_KEY_CACHE_LOCATION) || prefs.getString(Constants.PREFERENCES_KEY_CACHE_LOCATION, null) == null) { resetCacheLocation(prefs);// ww w.jav a 2 s. c o m } else { String path = prefs.getString(Constants.PREFERENCES_KEY_CACHE_LOCATION, null); File cacheLocation = new File(path); if (!FileUtil.verifyCanWrite(cacheLocation)) { // Only warn user if there is a difference saved if (resetCacheLocation(prefs)) { Util.info(this, R.string.common_warning, R.string.settings_cache_location_reset); } } } if (!prefs.contains(Constants.PREFERENCES_KEY_OFFLINE)) { SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean(Constants.PREFERENCES_KEY_OFFLINE, false); editor.putString(Constants.PREFERENCES_KEY_SERVER_NAME + 1, "Demo Server"); editor.putString(Constants.PREFERENCES_KEY_SERVER_URL + 1, "http://demo.subsonic.org"); editor.putString(Constants.PREFERENCES_KEY_USERNAME + 1, "guest"); editor.putString(Constants.PREFERENCES_KEY_PASSWORD + 1, "guest"); editor.putInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1); editor.commit(); } if (!prefs.contains(Constants.PREFERENCES_KEY_SERVER_COUNT)) { SharedPreferences.Editor editor = prefs.edit(); editor.putInt(Constants.PREFERENCES_KEY_SERVER_COUNT, 1); editor.commit(); } }
From source file:in.andres.kandroid.ui.MainActivity.java
private boolean createKandoardAPI() { // Check if API object already exists if (kanboardAPI != null) return true; Log.d(Constants.TAG, "Creating API object"); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getBaseContext()); boolean showLoginScreen = false; if (!preferences.contains("serverurl")) showLoginScreen = true;/*w w w . j av a2 s . c o m*/ serverURL = preferences.getString("serverurl", ""); if (!preferences.contains("username")) showLoginScreen = true; username = preferences.getString("username", ""); if (!preferences.contains("password")) showLoginScreen = true; password = preferences.getString("password", ""); if (showLoginScreen) { Log.i("Kandroid", "No credential found. Launching login activity."); Intent iLoginScreen = new Intent(this, LoginActivity.class); startActivity(iLoginScreen); return false; } else { try { kanboardAPI = new KanboardAPI(serverURL, username, password); kanboardAPI.addListener(eventHandler); kanboardAPI.addErrorListener(errorListener); kanboardAPI.addOnGetMeListener(getMeListener); kanboardAPI.addOnGetMyDashboardListener(getMyDashboardListener); kanboardAPI.addOnGetMyActivityStreamListener(getMyActivityStreamListener); kanboardAPI.addOnGetMyOverdueTasksListener(getMyOverdueTasksListener); kanboardAPI.addOnGetProjectByIdListener(getProjectByIdListener); kanboardAPI.addOnGetColumnsListener(getColumnsListener); kanboardAPI.addOnGetActiveSwimlanesListener(getActiveSwimlanesListener); kanboardAPI.addOnGetAllCategoriesListener(getAllCategoriesListener); kanboardAPI.addOnGetAllTasksListener(getAllTasksListener); kanboardAPI.addOnGetOverdueTasksByProjectListener(getOverdueTasksByProjectListener); kanboardAPI.addOnGetProjectUsersListener(getProjectUsersListener); kanboardAPI.addOnGetDefaultColorsListener(getDefaultColorsListener); kanboardAPI.addOnGetMyProjectsListener(getMyProjectsListener); return true; } catch (IOException e) { Log.e(Constants.TAG, "Failed to create API object."); e.printStackTrace(); } } return false; }
From source file:com.socialdisasters.other.service.ChatService.java
@Override protected void onSessionConnected(Session session) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); /**//from ww w . ja va2 s .com * Upgrade from "checkBroadcastPresence" option */ if (prefs.contains("checkBroadcastPresence")) { if (!prefs.getBoolean("checkBroadcastPresence", false)) { prefs.edit().putString("presencetag", "unavailable").remove("checkBroadcastPresence").commit(); } else { prefs.edit().remove("checkBroadcastPresence").commit(); } } /** * Activate presence by default */ if (!prefs.contains("presencetag")) prefs.edit().putString("presencetag", "auto").commit(); mPrefListener.onSharedPreferenceChanged(prefs, "presencetag"); // register own data handler for incoming bundles session.setDataHandler(_data_handler); // store session locally _session = session; // signal updated user info Intent i = new Intent(ACTION_USERINFO_UPDATED); sendBroadcast(i); }
From source file:org.transdroid.gui.search.Search.java
private void saveSearch() { // Find the url to match an RSS feed to the last query String url = TorrentSearchTask.buildRssFeedFromSearch(this, defaultSite.getKey(), query); if (url != null) { // Build new RSS feed settings object SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); int i = 0; String nextUrl = Preferences.KEY_PREF_RSSURL + Integer.toString(i); while (prefs.contains(nextUrl)) { i++;/* w w w . ja v a 2s . c o m*/ nextUrl = Preferences.KEY_PREF_RSSURL + Integer.toString(i); } // Store an RSS feed setting for this feed Editor editor = prefs.edit(); editor.putString(Preferences.KEY_PREF_RSSNAME + Integer.toString(i), query); editor.putString(nextUrl, url); editor.commit(); Toast.makeText(this, R.string.search_savedrssfeed, Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, R.string.search_savenotsupported, Toast.LENGTH_SHORT).show(); } }
From source file:org.opendatakit.common.android.logic.PropertiesSingleton.java
void init() { // (re)set values to defaults lastGeneralModified = 0L;/*from w w w . ja va2s. c o m*/ lastDeviceModified = 0L; mGeneralProps.clear(); mDeviceProps.clear(); // populate the caches from disk... readProperties(); boolean dirtyProps = false; // see if there are missing values in the general props // and update them from the mGeneralDefaults map. for (TreeMap.Entry<String, String> entry : mGeneralDefaults.entrySet()) { if (mGeneralProps.containsKey(entry.getKey()) == false) { mGeneralProps.setProperty(entry.getKey(), entry.getValue()); dirtyProps = true; } } // scan for device properties in the (syncable) app properties file. // update the provided mDeviceDefaults with these new default values. for (TreeMap.Entry<String, String> entry : mDeviceDefaults.entrySet()) { if (mGeneralProps.containsKey(entry.getKey())) { entry.setValue(mGeneralProps.getProperty(entry.getKey())); } } // see if there are missing values in the device props // and update them from the mGeneralDefaults map. for (TreeMap.Entry<String, String> entry : mDeviceDefaults.entrySet()) { if (mDeviceProps.containsKey(entry.getKey()) == false) { mDeviceProps.setProperty(entry.getKey(), entry.getValue()); dirtyProps = true; } } // scan for secure properties in the (syncable) app properties file. // remove these and do not propagate them into SharedPreferences. for (TreeMap.Entry<String, String> entry : mSecureDefaults.entrySet()) { if (mGeneralProps.containsKey(entry.getKey())) { mGeneralProps.remove(entry.getKey()); dirtyProps = true; } } // Now, scan through the shared preferences. These will only be available // from within ODK Services. If we try to access them outside of that // application, this will be a no-op. SharedPreferences sharedPreferences = getSharedPreferences(mBaseContext); if (sharedPreferences != null) { for (TreeMap.Entry<String, String> entry : mSecureDefaults.entrySet()) { // NOTE: can't use the methods because this object is not yet fully created if (!sharedPreferences.contains(mAppName + "_" + entry.getKey())) { sharedPreferences.edit().putString(mAppName + "_" + entry.getKey(), entry.getValue()).commit(); } } } if (dirtyProps) { writeProperties(); } }
From source file:org.kde.kdeconnect.Device.java
public boolean deviceShouldBeKeptAlive() { SharedPreferences preferences = context.getSharedPreferences("trusted_devices", Context.MODE_PRIVATE); if (preferences.contains(getDeviceId())) { //Log.e("DeviceShouldBeKeptAlive", "because it's a paired device"); return true; //Already paired }/*w w w . j a v a 2 s. com*/ for (BaseLink l : links) { if (l.linkShouldBeKeptAlive()) { return true; } } return false; }
From source file:com.baidu.android.voicedemo.ApiActivity.java
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); }//from ww w . j av a 2s.c om if (sp.contains(Constant.EXTRA_INFILE)) { String tmp = sp.getString(Constant.EXTRA_INFILE, "").replaceAll(",.*", "").trim(); intent.putExtra(Constant.EXTRA_INFILE, tmp); } 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:com.cerema.cloud2.ui.fragment.OCFileListFragment.java
private boolean endWhile(OCFile parentDir, SharedPreferences setting) { if (parentDir.getRemotePath().compareToIgnoreCase(OCFile.ROOT_PATH) == 0) { return false; } else {//from w w w .ja v a 2 s .co m return !setting.contains(String.valueOf(parentDir.getFileId())); } }
From source file:com.example.administrator.myapplication2._2_exercise._2_Status_heart.fragments.LeftFragment.java
public void postJsonData1() { try {/* w w w . j a v a2s .com*/ SharedPreferences myPrefs = getActivity().getSharedPreferences("login", Context.MODE_PRIVATE); if ((myPrefs != null) && (myPrefs.contains("id"))) { id = myPrefs.getString("id", ""); } SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.KOREA); String str_date = df.format(new Date()); RequestParams a = new RequestParams(); a.put("id", id); a.put("ldate", str_date); a.put("ldistance", "0.0"); a.put("kal", "0"); a.put("hb", "0"); a.put("weight", "0"); a.put("runtime", "0"); a.setUseJsonStreamer(true); Log.i("boogil", a.toString()); HttpPostDateTest1(a); } catch (Exception e) { e.printStackTrace(); } }