當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。