初始化代码

This commit is contained in:
2025-05-15 11:08:23 +08:00
commit a8d127a876
696 changed files with 481048 additions and 0 deletions

View File

@@ -0,0 +1,467 @@
package com.qxcm.moduleutil.utils;
import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;
import com.alibaba.fastjson.JSON;
import com.blankj.utilcode.util.SPUtils;
import com.qxcm.moduleutil.widget.CommonAppContext;
import java.util.Map;
/**
* Created by cxf on 2018/9/17.
* SharedPreferences 封装
*/
public class SpUtil {
private static SpUtil sInstance;
private SharedPreferences mSharedPreferences;
public static final String UID = "uid";
public static final String TOKEN = "token";
public static final String USER_INFO = "userInfo";
public static final String CONFIG = "config";
public static final String SYSTEM_MSG_COUNT = "systemMsgCount";
public static final String LOCATION_LNG = "locationLng";
public static final String LOCATION_LAT = "locationLat";
public static final String LOCATION_PROVINCE = "locationProvince";
public static final String LOCATION_CITY = "locationCity";
public static final String LOCATION_DISTRICT = "locationDistrict";
public static final String MH_BEAUTY_ENABLE = "mhBeautyEnable";
public static final String BRIGHTNESS = "brightness";//亮度
public static final String IM_MSG_RING = "imMsgRing";//私信音效
public static final String DEVICE_ID = "deviceId";
public static final String TEENAGER = "teenager";
public static final String TEENAGER_SHOW = "teenagerShow";
public static final String TX_IM_USER_SIGN = "txImUserSign";//腾讯IM用户签名登录腾讯IM用
public static final String TPNS_NOTIFY_EXT = "tpnsNotifyExt";//tpns通知携带参数
public static final String BASE_FUNCTION_MODE = "baseFunctionMode";//基本功能模式
public static final String LANGUAGE = "language";
private SpUtil() {
mSharedPreferences = CommonAppContext.getInstance().getSharedPreferences("SharedPreferences", Context.MODE_PRIVATE);
}
public static SpUtil getInstance() {
if (sInstance == null) {
synchronized (SpUtil.class) {
if (sInstance == null) {
sInstance = new SpUtil();
}
}
}
return sInstance;
}
public int getIntValue(String key, int defaultValue) {
return mSharedPreferences.getInt(key, defaultValue);
}
public void setIntValue(String key, int value) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putInt(key, value);
editor.apply();
}
/**
* 保存一个字符串
*/
public void setStringValue(String key, String value) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putString(key, value);
editor.apply();
}
/**
* 获取一个字符串
*/
public String getStringValue(String key) {
return mSharedPreferences.getString(key, "");
}
/**
* 保存多个字符串
*/
public void setMultiStringValue(Map<String, String> pairs) {
if (pairs == null || pairs.size() == 0) {
return;
}
SharedPreferences.Editor editor = mSharedPreferences.edit();
for (Map.Entry<String, String> entry : pairs.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (!TextUtils.isEmpty(key) && !TextUtils.isEmpty(value)) {
editor.putString(key, value);
}
}
editor.apply();
}
/**
* 获取多个字符串
*/
public String[] getMultiStringValue(String... keys) {
if (keys == null || keys.length == 0) {
return null;
}
int length = keys.length;
String[] result = new String[length];
for (int i = 0; i < length; i++) {
String temp = "";
if (!TextUtils.isEmpty(keys[i])) {
temp = mSharedPreferences.getString(keys[i], "");
}
result[i] = temp;
}
return result;
}
/**
* 保存一个布尔值
*/
public void setBooleanValue(String key, boolean value) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putBoolean(key, value);
editor.apply();
}
/**
* 获取一个布尔值
*/
public boolean getBooleanValue(String key) {
return mSharedPreferences.getBoolean(key, false);
}
/**
* 获取一个布尔值
*/
public boolean getBooleanValue(String key, boolean defaultValue) {
return mSharedPreferences.getBoolean(key, defaultValue);
}
/**
* 保存多个布尔值
*/
public void setMultiBooleanValue(Map<String, Boolean> pairs) {
if (pairs == null || pairs.size() == 0) {
return;
}
SharedPreferences.Editor editor = mSharedPreferences.edit();
for (Map.Entry<String, Boolean> entry : pairs.entrySet()) {
String key = entry.getKey();
Boolean value = entry.getValue();
if (!TextUtils.isEmpty(key)) {
editor.putBoolean(key, value);
}
}
editor.apply();
}
/**
* 获取多个布尔值
*/
public boolean[] getMultiBooleanValue(String[] keys) {
if (keys == null || keys.length == 0) {
return null;
}
int length = keys.length;
boolean[] result = new boolean[length];
for (int i = 0; i < length; i++) {
boolean temp = false;
if (!TextUtils.isEmpty(keys[i])) {
temp = mSharedPreferences.getBoolean(keys[i], false);
}
result[i] = temp;
}
return result;
}
public void removeValue(String... keys) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
for (String key : keys) {
editor.remove(key);
}
editor.apply();
}
/**
* 亮度
*/
public void setBrightness(float brightness) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putFloat(BRIGHTNESS, brightness);
editor.apply();
}
/**
* 亮度
*/
public float getBrightness() {
return mSharedPreferences.getFloat(BRIGHTNESS, -1.0f);
}
/**
* 私信音效
*/
public void setImMsgRingOpen(boolean imMsgRingOpen) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putBoolean(IM_MSG_RING, imMsgRingOpen);
editor.apply();
}
/**
* 私信音效
*/
public boolean isImMsgRingOpen() {
return mSharedPreferences.getBoolean(IM_MSG_RING, true);
}
public static String getToken() {
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getString(SPConstants.TOKEN);
}
public static String getUserId() {
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getString(SPConstants.USER_ID);
}
public static void saveUserId(String userId) {
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put(SPConstants.USER_ID, userId, true);
}
public static String getMyRoomId() {
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getString("MyRoomId");
}
public static void saveMyRoomId(String roomId) {
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put("MyRoomId", roomId, true);
}
public static void saveSearchHistory(String searchHistory) {
SPUtils.getInstance(SPConstants.PREFERENCE_SEARCH_HISTORY).put(SPConstants.SEARCH_HISTORY, searchHistory);
}
public static String getSearchHistory() {
return SPUtils.getInstance(SPConstants.PREFERENCE_SEARCH_HISTORY).getString(SPConstants.SEARCH_HISTORY);
}
public static void putToken(String token) {
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put(SPConstants.TOKEN, token, true);
}
// public static void saveCabin(CabinEvent cabinEvent) {
// String s = JSON.toJSONString(cabinEvent);
// SPUtils.getInstance(SPConstants.CABIN).put("cabin", s, true);
// }
//
// public static CabinEvent getCabin() {
// String s = SPUtils.getInstance(SPConstants.CABIN).getString("cabin");
// if (TextUtils.isEmpty(s)) {
// return null;
// }
// CabinEvent cabinEvent = JSON.parseObject(s, CabinEvent.class);
// return cabinEvent;
// }
//
// public static void saveUserInfo(UserBean userBean) {
// String s = JSON.toJSONString(userBean);
// SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put(SPConstants.USER_INFO, s, true);
// }
//
// public static UserBean getUserInfo() {
// String s = SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getString(SPConstants.USER_INFO);
// if (TextUtils.isEmpty(s)) {
// return new UserBean();
// }
// UserBean userBean = JSON.parseObject(s, UserBean.class);
// if (userBean == null) {
// return new UserBean();
// }
// return userBean;
// }
public static void saveTzbl(String roomId, float bl) {
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put(getUserId() + "-" + roomId + "_Tzbl", bl, true);
}
public static float getTzbl(String roomId) {
float bl = SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getFloat(getUserId() + "-" + roomId + "_Tzbl");
if (bl < 0.0f) {
if (roomId.equals(getMyRoomId())) {
return 0.8f;
} else {
return 0.0f;
}
} else {
return bl;
}
}
public static void saveEmqttId(String clientId) {
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put(SPConstants.EMQTT_CLIENT_ID, clientId);
}
public static String getEmqttId() {
String s = SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getString(SPConstants.EMQTT_CLIENT_ID);
return s;
}
//获取SharedPreferences音乐轮播方式
public static int getPlayPattern() {
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getInt(SPConstants.PLAY_MODE, 1);
}
//通过SharedPreferences设置音乐轮播方式
public static void setPlayPattern(int i) {
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put(SPConstants.PLAY_MODE, i);
}
//获取SharedPreferences音乐播放音量
public static int getChannelVolume() {
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getInt(SPConstants.VOLUME, 20);
}
//设置SharedPreferences音乐播放音量
public static void setChannelVolume(int i) {
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put(SPConstants.VOLUME, i);
}
//获取播放的音乐
public static int getPlayCurrentMusic() {
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getInt(SPConstants.CURRENT_MUSIC, 0);
}
//设置播放的音乐
public static void setPlayCurrentMusic(int i) {
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put(SPConstants.CURRENT_MUSIC, i);
}
//设置开启特效
public static void setOpenEffect(int i) {
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put(SPConstants.OPEN_EFFECT, i);
}
//获取开启特效
public static int getOpenEffect() {
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getInt(SPConstants.OPEN_EFFECT, 1);
}
//设置耳返
public static void setAuricularBack(int i) {
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put(SPConstants.OPEN_AU_BACK, i);
}
//获取耳返
public static int getAuricularBack() {
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getInt(SPConstants.OPEN_AU_BACK, 0);
}
//获取新的消息数量
public static int getOrderNewCounts() {
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getInt(SPConstants.ORDER_NEWS_COUNT, 0);
}
//设置新的消息数量
public static void setOrderNewCounts(int i) {
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put(SPConstants.ORDER_NEWS_COUNT, i);
}
//获取装载的消息
public static String getLastOrderMsg() {
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getString(SPConstants.ORDER_LAST_MSG, " ");
}
//设置装载的消息
public static void setLastOrderMsg(String s) {
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put(SPConstants.ORDER_LAST_MSG, s);
}
//新的token
public static void putNewToken(String token) {
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put("newToken", token, true);
}
//新的token
public static String getNewToken() {
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getString("newToken", "");
}
public static void setAgreeSkillProtocol() {
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put("agreeSkillProtocol", true, true);
}
public static boolean getAgreeSkillProtocol() {
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getBoolean("agreeSkillProtocol", false);
}
public static void setInReview(boolean inReview) {
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put("inReview", inReview, true);
}
public static boolean inReview() {
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getBoolean("inReview", false);
}
public static void setHomeBanner(String banner){
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put("homeBanner", banner, true);
}
public static String getHomeBanner(){
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getString("homeBanner", "");
}
public static void setTopRoom(String topRoom){
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put("topRoom", topRoom, true);
}
public static String getTopRoom(){
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getString("topRoom", "");
}
public static void setRoomTypeModel(String roomTypeModel){
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put("roomTypeModel", roomTypeModel, true);
}
public static String getRoomTypeModel(){
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getString("roomTypeModel", "");
}
public static void setHomeBean(String homeBean){
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put("homeBean", homeBean, true);
}
public static String getHomeBean(){
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getString("homeBean", "");
}
public static void setRoomModel(String roomModel){
SPUtils.getInstance(SPConstants.PREFERENCE_NAME).put("roomModel", roomModel, true);
}
public static String getRoomModel(){
return SPUtils.getInstance(SPConstants.PREFERENCE_NAME).getString("roomModel", "");
}
/**
* 是否同意协议
*
* @return
*/
public static boolean isAgreePolicy() {
return !SPUtils.getInstance("Constant").getBoolean("launchRequestPermission", true);
}
/**
* 同意协议
*/
public static void completeAgreePolicy() {
SPUtils.getInstance("Constant").put("launchRequestPermission",
false, true);
}
}