添加应用基础数据模型

This commit is contained in:
ZhanGSKen 2025-03-25 03:23:45 +08:00
parent c203557a6a
commit 64051bb9fe
6 changed files with 108 additions and 28 deletions

View File

@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle
#Mon Mar 24 14:06:25 HKT 2025
#Mon Mar 24 19:22:39 GMT 2025
stageCount=10
libraryProject=libappbase
baseVersion=15.0
publishVersion=15.0.9
buildCount=0
buildCount=5
baseBetaVersion=15.0.10

View File

@ -19,7 +19,6 @@ public class App extends GlobalApplication {
@Override
public void onCreate() {
super.onCreate();
GlobalApplication.setIsDebuging(this, BuildConfig.DEBUG);
mSOSCenterServiceReceiver = new SOSCenterServiceReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(SOS.ACTION_SOS);

View File

@ -17,6 +17,7 @@ import cc.winboll.studio.libappbase.LogView;
import cc.winboll.studio.libappbase.sos.SOS;
import cc.winboll.studio.libappbase.utils.ToastUtils;
import cc.winboll.studio.libappbase.widgets.StatusWidget;
import cc.winboll.studio.libappbase.APPBaseModel;
public class MainActivity extends Activity {
@ -59,7 +60,8 @@ public class MainActivity extends Activity {
}
public void onSwitchDebugMode(View view) {
GlobalApplication.setIsDebuging(this, ((CheckBox)view).isChecked());
boolean isDebuging = ((CheckBox)view).isChecked();
GlobalApplication.setIsDebuging(isDebuging);
}
public void onStartCenter(View view) {

View File

@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle
#Mon Mar 24 14:06:10 HKT 2025
#Mon Mar 24 19:22:39 GMT 2025
stageCount=10
libraryProject=libappbase
baseVersion=15.0
publishVersion=15.0.9
buildCount=0
buildCount=5
baseBetaVersion=15.0.10

View File

@ -0,0 +1,73 @@
package cc.winboll.studio.libappbase;
/**
* @Author ZhanGSKen@AliYun.Com
* @Date 2025/03/25 02:52:46
* @Describe 基础应用数据模型
*/
import android.util.JsonReader;
import android.util.JsonWriter;
import cc.winboll.studio.libappbase.BaseBean;
import java.io.IOException;
public class APPBaseModel extends BaseBean {
public static final String TAG = "APPBaseModel";
// 应用是否处于正在调试状态
//
boolean isDebuging = false;
public APPBaseModel() {
this.isDebuging = false;
}
public APPBaseModel(boolean isDebuging) {
this.isDebuging = isDebuging;
}
public void setIsDebuging(boolean isDebuging) {
this.isDebuging = isDebuging;
}
public boolean isDebuging() {
return isDebuging;
}
@Override
public String getName() {
return APPBaseModel.class.getName();
}
@Override
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
super.writeThisToJsonWriter(jsonWriter);
jsonWriter.name("isDebuging").value(isDebuging());
}
@Override
public boolean initObjectsFromJsonReader(JsonReader jsonReader, String name) throws IOException {
if (super.initObjectsFromJsonReader(jsonReader, name)) { return true; } else {
if (name.equals("isDebuging")) {
setIsDebuging(jsonReader.nextBoolean());
} else {
return false;
}
}
return true;
}
@Override
public BaseBean readBeanFromJsonReader(JsonReader jsonReader) throws IOException {
jsonReader.beginObject();
while (jsonReader.hasNext()) {
String name = jsonReader.nextName();
if (!initObjectsFromJsonReader(jsonReader, name)) {
jsonReader.skipValue();
}
}
// 结束 JSON 对象
jsonReader.endObject();
return this;
}
}

View File

@ -7,7 +7,6 @@ package cc.winboll.studio.libappbase;
*/
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Handler;
@ -21,22 +20,29 @@ public class GlobalApplication extends Application {
final static String PREFS = GlobalApplication.class.getName() + "PREFS";
final static String PREFS_ISDEBUGING = "PREFS_ISDEBUGING";
private static Handler MAIN_HANDLER = new Handler(Looper.getMainLooper());
volatile static GlobalApplication _GlobalApplication;
// 是否处于调试状态
volatile static boolean isDebuging = false;
public static void setIsDebuging(Context context, boolean isDebuging) {
GlobalApplication.isDebuging = isDebuging;
// 获取SharedPreferences实例
SharedPreferences sharedPreferences = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE);
// 获取编辑器
SharedPreferences.Editor editor = sharedPreferences.edit();
// 保存数据
editor.putBoolean(PREFS_ISDEBUGING, GlobalApplication.isDebuging);
// 提交更改
editor.apply();
public static void setIsDebuging(boolean isDebuging) {
if (_GlobalApplication != null) {
GlobalApplication.isDebuging = isDebuging;
APPBaseModel.saveBeanToFile(getAPPBaseModelFilePath(), new APPBaseModel(isDebuging));
// 获取SharedPreferences实例
// SharedPreferences sharedPreferences = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE);
// // 获取编辑器
// SharedPreferences.Editor editor = sharedPreferences.edit();
// // 保存数据
// editor.putBoolean(PREFS_ISDEBUGING, GlobalApplication.isDebuging);
// // 提交更改
// editor.apply();
}
}
static String getAPPBaseModelFilePath() {
return _GlobalApplication.getDataDir().getPath() + "/APPBaseModel.json";
}
public static boolean isDebuging() {
@ -55,8 +61,16 @@ public class GlobalApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
//GlobalApplication.isDebuging = true;
//GlobalApplication.setIsDebuging(this, true);
_GlobalApplication = this;
// 设置应用调试标志
APPBaseModel appBaseModel = APPBaseModel.loadBeanFromFile(getAPPBaseModelFilePath(), APPBaseModel.class);
if (appBaseModel == null) {
setIsDebuging(false);
} else {
setIsDebuging(appBaseModel.isDebuging());
}
LogUtils.init(this);
//LogUtils.setLogLevel(LogUtils.LOG_LEVEL.Debug);
//LogUtils.setTAGListEnable(GlobalApplication.TAG, true);
@ -66,16 +80,8 @@ public class GlobalApplication extends Application {
// 设置应用异常处理窗口
CrashHandler.init(this);
// 设置应用调试状态
//SharedPreferences sharedPreferences = getSharedPreferences(PREFS, Context.MODE_PRIVATE);
//GlobalApplication.isDebuging = sharedPreferences.getBoolean(PREFS_ISDEBUGING, GlobalApplication.isDebuging);
// 初始化 Toast 框架
ToastUtils.init(this);
// 设置 Toast 布局样式
//ToastUtils.setView(R.layout.toast_custom_view);
//ToastUtils.setStyle(new WhiteToastStyle());
//ToastUtils.setGravity(Gravity.BOTTOM, 0, 200);
}
public static String getAppName(Context context) {