From 73a49ddd0516e5c9a4b697c593d62c74e420403b Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期四, 24 十月 2024 12:27:31 +0800 Subject: [PATCH] 2024年10月24日12:27:28 --- HDLLinkPMSdk/src/main/java/com/hdl/linkpm/sdk/utils/HDLSDKSPUtils.java | 147 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 147 insertions(+), 0 deletions(-) diff --git a/HDLLinkPMSdk/src/main/java/com/hdl/linkpm/sdk/utils/HDLSDKSPUtils.java b/HDLLinkPMSdk/src/main/java/com/hdl/linkpm/sdk/utils/HDLSDKSPUtils.java new file mode 100644 index 0000000..ce21744 --- /dev/null +++ b/HDLLinkPMSdk/src/main/java/com/hdl/linkpm/sdk/utils/HDLSDKSPUtils.java @@ -0,0 +1,147 @@ +package com.hdl.linkpm.sdk.utils; + +import android.content.Context; +import android.content.SharedPreferences; + +import androidx.annotation.NonNull; + +import com.hdl.linkpm.sdk.HDLLinkPMSdk; + +import java.util.Collections; +import java.util.Map; +import java.util.Set; + +/** + * Created by Tong on 2021/11/3. + */ +public class HDLSDKSPUtils { + + private static final String APP_PREFERENCES_KEY = "com.hdl.link.sdk.profile"; + private static final SharedPreferences PREFERENCES = + HDLLinkPMSdk.getContext().getApplicationContext().getSharedPreferences(APP_PREFERENCES_KEY, Context.MODE_PRIVATE); + + private static SharedPreferences getAppPreference() { + return PREFERENCES; + } + + + //======閫氱敤瀛樺偍======== + public static void put(@NonNull final String key, final String value) { + getAppPreference().edit().putString(key, value).apply(); + } + + + public static String getString(@NonNull final String key) { + return getString(key, ""); + } + + + public static String getString(@NonNull final String key, final String defaultValue) { + return getAppPreference().getString(key, defaultValue); + } + + + public static void put(@NonNull final String key, final int value) { + put(key, value, false); + } + + + public static void put(@NonNull final String key, final int value, final boolean isCommit) { + getAppPreference().edit().putInt(key, value).apply(); + } + + + public static int getInt(@NonNull final String key) { + return getInt(key, -1); + } + + + public static int getInt(@NonNull final String key, final int defaultValue) { + return getAppPreference().getInt(key, defaultValue); + } + + + public static void put(@NonNull final String key, final long value) { + getAppPreference().edit().putLong(key, value).apply(); + } + + + public static long getLong(@NonNull final String key) { + return getLong(key, -1L); + } + + + public static long getLong(@NonNull final String key, final long defaultValue) { + return getAppPreference().getLong(key, defaultValue); + } + + + public static void put(@NonNull final String key, final float value) { + getAppPreference().edit().putFloat(key, value).apply(); + } + + + public static float getFloat(@NonNull final String key) { + return getFloat(key, -1f); + } + + + public static float getFloat(@NonNull final String key, final float defaultValue) { + return getAppPreference().getFloat(key, defaultValue); + } + + + public static void put(@NonNull final String key, final boolean value) { + getAppPreference().edit().putBoolean(key, value).apply(); + } + + + public static boolean getBoolean(@NonNull final String key) { + return getBoolean(key, false); + } + + + public static boolean getBoolean(@NonNull final String key, final boolean defaultValue) { + return getAppPreference().getBoolean(key, defaultValue); + } + + + public static void put(@NonNull final String key, final Set<String> value) { + getAppPreference().edit().putStringSet(key, value).apply(); + } + + + public static Set<String> getStringSet(@NonNull final String key) { + return getStringSet(key, Collections.emptySet()); + } + + + public static Set<String> getStringSet(@NonNull final String key, + final Set<String> defaultValue) { + return getAppPreference().getStringSet(key, defaultValue); + } + + + public static Map<String, ?> getAll() { + return getAppPreference().getAll(); + } + + + public static boolean contains(@NonNull final String key) { + return getAppPreference().contains(key); + } + + + public static void remove(@NonNull final String key) { + getAppPreference().edit().remove(key).apply(); + } + + public static void clear() { + getAppPreference() + .edit() + .clear() + .apply(); + } + + +} -- Gitblit v1.8.0