本文整理汇总了Java中android.content.SharedPreferences.contains方法的典型用法代码示例。如果您正苦于以下问题:Java SharedPreferences.contains方法的具体用法?Java SharedPreferences.contains怎么用?Java SharedPreferences.contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.SharedPreferences
的用法示例。
在下文中一共展示了SharedPreferences.contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getToast
import android.content.SharedPreferences; //导入方法依赖的package包/类
public ArrayList<ToastListObjects> getToast(Context context) {
SharedPreferences prefs;
List<ToastListObjects> toastList;
prefs = context.getSharedPreferences(PREFS_NAME,Context.MODE_PRIVATE);
if(prefs.contains(ToastList)){
String jsonList = prefs.getString(ToastList,null);
Gson gson = new Gson();
ToastListObjects[] toast = gson.fromJson(jsonList,ToastListObjects[].class);
toastList = Arrays.asList(toast);
toastList = new ArrayList<ToastListObjects>(toastList);
}else
return null;
return (ArrayList<ToastListObjects>) toastList;
}
示例2: updateUI
import android.content.SharedPreferences; //导入方法依赖的package包/类
private void updateUI() {
mPlaces = VisitableGenerator.get(getActivity()).getPlaces();
// the visited (or not) status of places is persisted in preferences
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
for (int i = 0; i < mPlaces.size(); i++) {
Visitable place = mPlaces.get(i);
String placeName = getString(place.getPlaceNameResId());
if (prefs.contains(placeName)) {
place.setVisited(prefs.getBoolean(placeName, false));
}
}
if (mAdapter == null) {
mAdapter = new PlaceGridAdapter(mPlaces);
mAdapter.setHasStableIds(true);
mPlaceRecyclerView.setAdapter(mAdapter);
} else {
mAdapter.setPlaces(mPlaces);
mAdapter.notifyDataSetChanged();
}
}
示例3: getUserCreationTime
import android.content.SharedPreferences; //导入方法依赖的package包/类
@Override
public long getUserCreationTime(UserHandle user) {
SharedPreferences prefs = Utilities.getPrefs(mContext);
String key = USER_CREATION_TIME_KEY + getSerialNumberForUser(user);
if (!prefs.contains(key)) {
prefs.edit().putLong(key, System.currentTimeMillis()).apply();
}
return prefs.getLong(key, 0);
}
示例4: createPreferences
import android.content.SharedPreferences; //导入方法依赖的package包/类
private void createPreferences ( )
{
SharedPreferences pref = getSharedPreferences( Constant.PREF_NAME , Context.MODE_PRIVATE );
boolean isAlreadyCreated = pref.contains( Constant.PASSWORD_PREF );
if ( isAlreadyCreated )
return;
SharedPreferences.Editor editor = pref.edit();
editor.putBoolean ( Constant.FACE_LOCK_STATUS_PREF , false );
editor.putBoolean( Constant.IS_TRAINED_PREF , false );
editor.putString( Constant.PASSWORD_PREF , "12345" );
editor.commit();
}
示例5: setDefaults
import android.content.SharedPreferences; //导入方法依赖的package包/类
/**
* Set providers default settings from provider data
*
* @param context locatorContext
*/
@SuppressLint({"CommitPrefEdits", "ApplySharedPref"})
@SuppressWarnings("boxing")
static public void setDefaults(@NonNull final Context context)
{
// create providers
final List<HashMap<String, Object>> providers = Providers.getProviders(context, false);
// create prefs for built-in providers
if (providers != null)
{
for (int i = 0; i < providers.size(); i++)
{
final HashMap<String, Object> provider = providers.get(i);
if (provider.get(Providers.ISPLUGIN).equals(true))
{
continue;
}
// provider shared preferences
final SharedPreferences providerSharedPrefs = context.getSharedPreferences(Settings.PREF_FILE_PREFIX + provider.get(Providers.NAME), Context.MODE_PRIVATE);
// commit non existent values
final Editor providerEditor = providerSharedPrefs.edit();
final String[] keys = new String[]{TreebolicIface.PREF_SOURCE, TreebolicIface.PREF_BASE, TreebolicIface.PREF_IMAGEBASE, TreebolicIface.PREF_SETTINGS, Settings.PREF_PROVIDER};
final String[] providerKeys = new String[]{Providers.SOURCE, Providers.BASE, Providers.IMAGEBASE, Providers.SETTINGS, Providers.PROVIDER};
for (int j = 0; j < keys.length; j++)
{
final String key = keys[j];
if (!providerSharedPrefs.contains(key))
{
final String value = (String) provider.get(providerKeys[j]);
providerEditor.putString(key, value).commit();
}
}
}
}
}
示例6: isLocationLatLonAvailable
import android.content.SharedPreferences; //导入方法依赖的package包/类
/**
* Returns true if the latitude and longitude values are available. The latitude and
* longitude will not be available until the lesson where the PlacePicker API is taught.
*
* @param context used to get the SharedPreferences
* @return true if lat/long are saved in SharedPreferences
*/
public static boolean isLocationLatLonAvailable(Context context) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
boolean spContainLatitude = sp.contains(PREF_COORD_LAT);
boolean spContainLongitude = sp.contains(PREF_COORD_LONG);
boolean spContainBothLatitudeAndLongitude = false;
if (spContainLatitude && spContainLongitude) {
spContainBothLatitudeAndLongitude = true;
}
return spContainBothLatitudeAndLongitude;
}
示例7: getCurrentBaseForms
import android.content.SharedPreferences; //导入方法依赖的package包/类
/**
* Returns the currently registered form items (if any), or an empty set otherwise
* @param context used to access the preference manager
*/
public static ArrayList<Form> getCurrentBaseForms(Context context) {
SharedPreferences settings = context.getSharedPreferences(
context.getResources().getString(R.string.app_name),
Context.MODE_PRIVATE);
if (settings.contains(Utils.BASE_FORMS_ENTRY)) {
return new Gson().fromJson(settings
.getString(Utils.BASE_FORMS_ENTRY, ""),
Utils.ARRAY_FORM);
}
return new ArrayList<>();
}
示例8: loadData
import android.content.SharedPreferences; //导入方法依赖的package包/类
private void loadData() {
SharedPreferences pref = getSharedPreferences("data", MODE_PRIVATE);
etUsername.setText(pref.getString("username", ""));
if (pref.contains("remembered")) {
if (pref.getBoolean("remembered", false)) {
etPassword.setText(pref.getString("password", ""));
checkBox.setChecked(true);
}
}
}
示例9: getValue
import android.content.SharedPreferences; //导入方法依赖的package包/类
public <T> T getValue(String key, Type type, T defaultValue) {
SharedPreferences preferences = getPreferences();
return preferences.contains(key) ? (T) new Gson().fromJson(preferences.getString(key, ""), type) : defaultValue;
}
示例10: hasString
import android.content.SharedPreferences; //导入方法依赖的package包/类
public static boolean hasString(String key) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(
BilibiliApp.getInstance());
return sharedPreferences.contains(key);
}
示例11: contains
import android.content.SharedPreferences; //导入方法依赖的package包/类
public static boolean contains(@NonNull String key) {
SharedPreferences preferences = context.get()
.getSharedPreferences(KEY_SHARED_PREFERENCES_NAME, MODE_PRIVATE);
return preferences.contains(key);
}
示例12: linkPreference
import android.content.SharedPreferences; //导入方法依赖的package包/类
public MaterialColorSetting linkPreference(SharedPreferences prefs, String pref) {
if (prefs.contains(pref))
setSelectedColor(prefs.getInt(pref, 0));
setAssociatedPreference(prefs, pref);
return this;
}
示例13: contains
import android.content.SharedPreferences; //导入方法依赖的package包/类
/**
* 查询某个key是否已经存在
*
* @param context
* @param key
* @return
*/
public static boolean contains(Context context, String key) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
return sp.contains(key);
}
示例14: firstStart
import android.content.SharedPreferences; //导入方法依赖的package包/类
/**
* returns true when the app is started for the first time,
* it detects the first start when there is no everid set by the application
*
* @param context
* @return
*/
public static boolean firstStart(Context context) {
// if no everid is set, this is the first start
SharedPreferences preferences = getWebTrekkSharedPreference(context);
return !preferences.contains(Webtrekk.PREFERENCE_KEY_EVER_ID);
}
示例15: contains
import android.content.SharedPreferences; //导入方法依赖的package包/类
/**
* 查询某个key是否已经存在
* @param context
* @param key
* @return
*/
public static boolean contains(Context context, String key) {
SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
Context.MODE_PRIVATE);
return sp.contains(key);
}