当前位置: 首页>>代码示例>>Java>>正文


Java SharedPreferences.contains方法代码示例

本文整理汇总了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;
}
 
开发者ID:mahto56,项目名称:Qeet-Remote,代码行数:17,代码来源:SharedPreference.java

示例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();
    }
}
 
开发者ID:plweegie,项目名称:piast-trail,代码行数:25,代码来源:PlaceListFragment.java

示例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);
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:10,代码来源:UserManagerCompatVL.java

示例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();
}
 
开发者ID:informramiz,项目名称:Android-Face-Recognition,代码行数:17,代码来源:HelloJni.java

示例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();
				}
			}
		}
	}
}
 
开发者ID:1313ou,项目名称:Treebolic,代码行数:43,代码来源:Settings.java

示例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;
}
 
开发者ID:fjoglar,项目名称:android-dev-challenge,代码行数:21,代码来源:SunshinePreferences.java

示例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<>();
}
 
开发者ID:feup-infolab,项目名称:labtablet,代码行数:19,代码来源:FormMgr.java

示例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);
        }
    }
}
 
开发者ID:Akari10032,项目名称:12306_Android,代码行数:11,代码来源:LoginActivity.java

示例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;
}
 
开发者ID:SebastianRask,项目名称:Pocket-Plays-for-Twitch,代码行数:5,代码来源:Settings.java

示例10: hasString

import android.content.SharedPreferences; //导入方法依赖的package包/类
public static boolean hasString(String key) {

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(
        BilibiliApp.getInstance());
    return sharedPreferences.contains(key);
  }
 
开发者ID:MUFCRyan,项目名称:BilibiliClient,代码行数:7,代码来源:PreferenceUtil.java

示例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);
}
 
开发者ID:adorsys,项目名称:secure-storage-android,代码行数:6,代码来源:SecurePreferences.java

示例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;
}
 
开发者ID:MCMrARM,项目名称:revolution-irc,代码行数:7,代码来源:MaterialColorSetting.java

示例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);
}
 
开发者ID:lanyuanxiaoyao,项目名称:PicKing,代码行数:12,代码来源:SPUtils.java

示例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);
}
 
开发者ID:Webtrekk,项目名称:webtrekk-android-sdk,代码行数:13,代码来源:HelperFunctions.java

示例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);
}
 
开发者ID:li-yu,项目名称:FakeWeather,代码行数:12,代码来源:SPUtil.java


注:本文中的android.content.SharedPreferences.contains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。