源码整理
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Fri Dec 26 02:58:19 HKT 2025
|
#Fri Dec 26 09:26:07 GMT 2025
|
||||||
stageCount=35
|
stageCount=35
|
||||||
libraryProject=
|
libraryProject=
|
||||||
baseVersion=15.14
|
baseVersion=15.14
|
||||||
publishVersion=15.14.34
|
publishVersion=15.14.34
|
||||||
buildCount=0
|
buildCount=13
|
||||||
baseBetaVersion=15.14.35
|
baseBetaVersion=15.14.35
|
||||||
|
|||||||
@@ -64,11 +64,12 @@ public class App extends GlobalApplication {
|
|||||||
// 全局广播接收器
|
// 全局广播接收器
|
||||||
private GlobalApplicationReceiver mGlobalReceiver;
|
private GlobalApplicationReceiver mGlobalReceiver;
|
||||||
|
|
||||||
// ===================== 公共静态方法区(工具类实例获取/单例) =====================
|
// ===================== 公共静态方法区(单例/工具类实例获取) =====================
|
||||||
/**
|
/**
|
||||||
* 获取应用单例实例
|
* 获取应用单例实例
|
||||||
*/
|
*/
|
||||||
public static App getInstance() {
|
public static App getInstance() {
|
||||||
|
LogUtils.d(TAG, "getInstance() 调用 | 返回实例:" + sApp);
|
||||||
return sApp;
|
return sApp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,12 +77,14 @@ public class App extends GlobalApplication {
|
|||||||
* 获取应用配置工具实例
|
* 获取应用配置工具实例
|
||||||
*/
|
*/
|
||||||
public static AppConfigUtils getAppConfigUtils(Context context) {
|
public static AppConfigUtils getAppConfigUtils(Context context) {
|
||||||
LogUtils.d(TAG, String.format("getAppConfigUtils() 调用 | 传入Context类型=%s",
|
String contextType = context != null ? context.getClass().getSimpleName() : "null";
|
||||||
context != null ? context.getClass().getSimpleName() : "null"));
|
LogUtils.d(TAG, "getAppConfigUtils() 调用 | 入参Context类型:" + contextType);
|
||||||
|
|
||||||
if (sAppConfigUtils == null) {
|
if (sAppConfigUtils == null) {
|
||||||
sAppConfigUtils = AppConfigUtils.getInstance(context);
|
sAppConfigUtils = AppConfigUtils.getInstance(context);
|
||||||
LogUtils.d(TAG, "getAppConfigUtils():AppConfigUtils实例已初始化");
|
LogUtils.d(TAG, "getAppConfigUtils() | AppConfigUtils实例初始化完成");
|
||||||
}
|
}
|
||||||
|
LogUtils.d(TAG, "getAppConfigUtils() | 返回实例:" + sAppConfigUtils);
|
||||||
return sAppConfigUtils;
|
return sAppConfigUtils;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,12 +92,14 @@ public class App extends GlobalApplication {
|
|||||||
* 获取应用缓存工具实例
|
* 获取应用缓存工具实例
|
||||||
*/
|
*/
|
||||||
public static AppCacheUtils getAppCacheUtils(Context context) {
|
public static AppCacheUtils getAppCacheUtils(Context context) {
|
||||||
LogUtils.d(TAG, String.format("getAppCacheUtils() 调用 | 传入Context类型=%s",
|
String contextType = context != null ? context.getClass().getSimpleName() : "null";
|
||||||
context != null ? context.getClass().getSimpleName() : "null"));
|
LogUtils.d(TAG, "getAppCacheUtils() 调用 | 入参Context类型:" + contextType);
|
||||||
|
|
||||||
if (sAppCacheUtils == null) {
|
if (sAppCacheUtils == null) {
|
||||||
sAppCacheUtils = AppCacheUtils.getInstance(context);
|
sAppCacheUtils = AppCacheUtils.getInstance(context);
|
||||||
LogUtils.d(TAG, "getAppCacheUtils():AppCacheUtils实例已初始化");
|
LogUtils.d(TAG, "getAppCacheUtils() | AppCacheUtils实例初始化完成");
|
||||||
}
|
}
|
||||||
|
LogUtils.d(TAG, "getAppCacheUtils() | 返回实例:" + sAppCacheUtils);
|
||||||
return sAppCacheUtils;
|
return sAppCacheUtils;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,9 +111,9 @@ public class App extends GlobalApplication {
|
|||||||
LogUtils.d(TAG, "clearBatteryHistory() 调用");
|
LogUtils.d(TAG, "clearBatteryHistory() 调用");
|
||||||
if (sAppCacheUtils != null) {
|
if (sAppCacheUtils != null) {
|
||||||
sAppCacheUtils.clearBatteryHistory();
|
sAppCacheUtils.clearBatteryHistory();
|
||||||
LogUtils.d(TAG, "clearBatteryHistory():电池历史数据已清除");
|
LogUtils.d(TAG, "clearBatteryHistory() | 电池历史数据清除成功");
|
||||||
} else {
|
} else {
|
||||||
LogUtils.w(TAG, "clearBatteryHistory():AppCacheUtils未初始化,清除失败");
|
LogUtils.w(TAG, "clearBatteryHistory() | 失败:AppCacheUtils未初始化");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,28 +122,27 @@ public class App extends GlobalApplication {
|
|||||||
* 极致强制缓存策略下,仅提供手动清理入口,永不自动调用
|
* 极致强制缓存策略下,仅提供手动清理入口,永不自动调用
|
||||||
*/
|
*/
|
||||||
public static void manualClearAllCache() {
|
public static void manualClearAllCache() {
|
||||||
LogUtils.w(TAG, String.format("%s 手动清理缓存调用(极致强制缓存策略下,需谨慎使用)", CACHE_PROTECT_TAG));
|
LogUtils.w(CACHE_PROTECT_TAG, "manualClearAllCache() 调用 | 极致缓存策略下谨慎使用");
|
||||||
|
|
||||||
// 清理Bitmap缓存
|
// 清理Bitmap缓存
|
||||||
if (sBitmapCacheUtils != null) {
|
if (sBitmapCacheUtils != null) {
|
||||||
sBitmapCacheUtils.clearAllCache();
|
sBitmapCacheUtils.clearAllCache();
|
||||||
LogUtils.d(TAG, String.format("%s Bitmap缓存已手动清理", CACHE_PROTECT_TAG));
|
LogUtils.d(CACHE_PROTECT_TAG, "manualClearAllCache() | Bitmap缓存手动清理完成");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 清理视图控件缓存(仅清除静态引用,不销毁实例)
|
// 清理视图控件缓存(仅清除静态引用,不销毁实例)
|
||||||
if (sMemoryCachedBackgroundView != null) {
|
if (sMemoryCachedBackgroundView != null) {
|
||||||
LogUtils.d(TAG, String.format("%s 视图控件缓存实例保持,仅清除静态引用", CACHE_PROTECT_TAG));
|
LogUtils.d(CACHE_PROTECT_TAG, "manualClearAllCache() | 视图缓存保留实例,仅清除静态引用");
|
||||||
sMemoryCachedBackgroundView = null;
|
sMemoryCachedBackgroundView = null;
|
||||||
}
|
}
|
||||||
LogUtils.w(TAG, String.format("%s 手动清理缓存完成(部分缓存实例仍可能保留在内存中)", CACHE_PROTECT_TAG));
|
LogUtils.w(CACHE_PROTECT_TAG, "manualClearAllCache() | 手动清理完成 | 部分缓存实例仍驻留内存");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取视图控件缓存实例(非通用:仅通过App实例调用,避免全局直接访问)
|
* 获取视图控件缓存实例(非通用:仅通过App实例调用,避免全局直接访问)
|
||||||
*/
|
*/
|
||||||
public MemoryCachedBackgroundView getMemoryCachedBackgroundView() {
|
public MemoryCachedBackgroundView getMemoryCachedBackgroundView() {
|
||||||
LogUtils.d(TAG, "getMemoryCachedBackgroundView() 调用 | 视图控件缓存实例获取");
|
LogUtils.d(TAG, "getMemoryCachedBackgroundView() 调用 | 当前实例:" + sMemoryCachedBackgroundView);
|
||||||
if (sMemoryCachedBackgroundView == null) {
|
|
||||||
LogUtils.w(TAG, "getMemoryCachedBackgroundView():视图控件缓存实例未初始化,返回null");
|
|
||||||
}
|
|
||||||
return sMemoryCachedBackgroundView;
|
return sMemoryCachedBackgroundView;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,13 +150,15 @@ public class App extends GlobalApplication {
|
|||||||
* 发送调试通知
|
* 发送调试通知
|
||||||
*/
|
*/
|
||||||
public static void notifyMessage(String title, String content) {
|
public static void notifyMessage(String title, String content) {
|
||||||
LogUtils.d(TAG, String.format("notifyMessage() 调用 | title=%s | content=%s", title, content));
|
LogUtils.d(TAG, "notifyMessage() 调用 | 入参title:" + title + " | content:" + content);
|
||||||
if (isDebugging() && sApp != null && sNotificationManagerUtils != null) {
|
|
||||||
|
boolean canNotify = isDebugging() && sApp != null && sNotificationManagerUtils != null;
|
||||||
|
if (canNotify) {
|
||||||
NotificationMessage message = new NotificationMessage(title, content, "");
|
NotificationMessage message = new NotificationMessage(title, content, "");
|
||||||
sNotificationManagerUtils.showMessageNotification(sApp, message);
|
sNotificationManagerUtils.showMessageNotification(sApp, message);
|
||||||
LogUtils.d(TAG, "notifyMessage():调试通知发送成功");
|
LogUtils.d(TAG, "notifyMessage() | 调试通知发送成功");
|
||||||
} else {
|
} else {
|
||||||
LogUtils.d(TAG, "notifyMessage():调试通知发送失败(条件不满足)");
|
LogUtils.d(TAG, "notifyMessage() | 发送失败:调试模式未开启/工具类未初始化");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,58 +166,51 @@ public class App extends GlobalApplication {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
LogUtils.d(TAG, "onCreate() 应用启动,开始初始化");
|
LogUtils.d(TAG, "onCreate() | 应用启动,开始初始化流程");
|
||||||
sApp = this;
|
sApp = this;
|
||||||
|
|
||||||
// 初始化调试模式
|
// 初始化调试模式
|
||||||
setIsDebugging(BuildConfig.DEBUG);
|
setIsDebugging(BuildConfig.DEBUG);
|
||||||
LogUtils.d(TAG, String.format("onCreate() 调试模式=%b", BuildConfig.DEBUG));
|
LogUtils.d(TAG, "onCreate() | 调试模式状态:" + BuildConfig.DEBUG);
|
||||||
|
|
||||||
// 初始化基础工具
|
// 初始化核心组件
|
||||||
initBaseTools();
|
initBaseTools();
|
||||||
// 初始化工具类实例(核心:极致强制缓存,永不销毁)
|
|
||||||
initUtils();
|
initUtils();
|
||||||
// 初始化广播接收器
|
|
||||||
initReceiver();
|
initReceiver();
|
||||||
|
|
||||||
LogUtils.d(TAG, "onCreate() 应用初始化完成,极致强制缓存策略已启用");
|
LogUtils.d(TAG, "onCreate() | 应用初始化完成 | 极致强制缓存策略已启用");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTerminate() {
|
public void onTerminate() {
|
||||||
super.onTerminate();
|
super.onTerminate();
|
||||||
LogUtils.d(TAG, "onTerminate() 应用终止,开始释放非缓存资源");
|
LogUtils.d(TAG, "onTerminate() | 应用终止,释放非缓存资源");
|
||||||
|
|
||||||
// 释放Toast工具
|
// 释放轻量级工具
|
||||||
ToastUtils.release();
|
ToastUtils.release();
|
||||||
LogUtils.d(TAG, "onTerminate():Toast工具已释放");
|
LogUtils.d(TAG, "onTerminate() | Toast工具资源释放完成");
|
||||||
// 释放通知工具
|
|
||||||
releaseNotificationManager();
|
releaseNotificationManager();
|
||||||
// 释放广播接收器
|
|
||||||
releaseReceiver();
|
releaseReceiver();
|
||||||
|
|
||||||
// 核心修改:应用终止时也不清理缓存,保持静态实例
|
// 核心策略:应用终止不清理任何缓存
|
||||||
LogUtils.w(TAG, String.format("%s 应用终止,极致强制缓存策略生效,不清理任何缓存", CACHE_PROTECT_TAG));
|
LogUtils.w(CACHE_PROTECT_TAG, "onTerminate() | 极致缓存策略生效 | 所有缓存实例保持驻留");
|
||||||
|
LogUtils.d(TAG, "onTerminate() | 非缓存资源释放完成");
|
||||||
LogUtils.d(TAG, "onTerminate() 非缓存资源释放完成,缓存实例保持");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTrimMemory(int level) {
|
public void onTrimMemory(int level) {
|
||||||
super.onTrimMemory(level);
|
super.onTrimMemory(level);
|
||||||
// 极致强制缓存:禁止任何缓存清理操作,仅记录日志
|
// 极致缓存策略:拒绝系统触发的缓存清理
|
||||||
LogUtils.w(TAG, String.format("%s onTrimMemory() 调用 | 内存等级level=%d | 极致强制保持所有缓存",
|
LogUtils.w(CACHE_PROTECT_TAG, "onTrimMemory() 调用 | 内存等级:" + level + " | 强制保持所有缓存");
|
||||||
CACHE_PROTECT_TAG, level));
|
|
||||||
// 记录详细缓存状态,不执行任何清理
|
|
||||||
logDetailedCacheStatus();
|
logDetailedCacheStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLowMemory() {
|
public void onLowMemory() {
|
||||||
super.onLowMemory();
|
super.onLowMemory();
|
||||||
// 极致强制缓存:低内存时也不清理任何缓存
|
// 低内存场景:不清理缓存,仅记录状态
|
||||||
LogUtils.w(TAG, String.format("%s onLowMemory() 调用 | 极致强制保持所有缓存", CACHE_PROTECT_TAG));
|
LogUtils.w(CACHE_PROTECT_TAG, "onLowMemory() 调用 | 极致缓存策略:不执行任何清理操作");
|
||||||
// 记录详细缓存状态,不执行任何清理
|
|
||||||
logDetailedCacheStatus();
|
logDetailedCacheStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,54 +219,46 @@ public class App extends GlobalApplication {
|
|||||||
* 初始化基础工具(Activity管理、Toast、通知工具)
|
* 初始化基础工具(Activity管理、Toast、通知工具)
|
||||||
*/
|
*/
|
||||||
private void initBaseTools() {
|
private void initBaseTools() {
|
||||||
LogUtils.d(TAG, "initBaseTools() 开始初始化基础工具");
|
LogUtils.d(TAG, "initBaseTools() | 开始初始化基础工具集");
|
||||||
WinBoLLActivityManager.init(this);
|
WinBoLLActivityManager.init(this);
|
||||||
ToastUtils.init(this);
|
ToastUtils.init(this);
|
||||||
sNotificationManagerUtils = new NotificationManagerUtils(this);
|
sNotificationManagerUtils = new NotificationManagerUtils(this);
|
||||||
LogUtils.d(TAG, "initBaseTools() 基础工具+通知工具初始化完成,极致强制缓存策略已生效");
|
LogUtils.d(TAG, "initBaseTools() | ActivityManager/Toast/Notification工具初始化完成");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化工具类实例(核心:极致强制缓存,一旦初始化永不销毁)
|
* 初始化核心工具类(极致强制缓存:一旦初始化永不销毁)
|
||||||
*/
|
*/
|
||||||
private void initUtils() {
|
private void initUtils() {
|
||||||
LogUtils.d(TAG, "initUtils() 开始初始化工具类,启用极致强制缓存策略");
|
LogUtils.d(TAG, "initUtils() | 开始初始化核心工具类 | 启用极致强制缓存策略");
|
||||||
// 初始化配置&缓存工具
|
|
||||||
|
// 初始化配置与缓存工具
|
||||||
sAppConfigUtils = getAppConfigUtils(this);
|
sAppConfigUtils = getAppConfigUtils(this);
|
||||||
sAppCacheUtils = getAppCacheUtils(this);
|
sAppCacheUtils = getAppCacheUtils(this);
|
||||||
|
|
||||||
// 初始化背景资源工具
|
// 初始化背景资源与Bitmap缓存
|
||||||
sBackgroundSourceUtils = BackgroundSourceUtils.getInstance(this);
|
sBackgroundSourceUtils = BackgroundSourceUtils.getInstance(this);
|
||||||
sBackgroundSourceUtils.loadSettings();
|
sBackgroundSourceUtils.loadSettings();
|
||||||
LogUtils.d(TAG, "initUtils() 背景资源工具已初始化");
|
|
||||||
|
|
||||||
// 极致强制初始化Bitmap缓存工具(必初始化,永不销毁)
|
|
||||||
sBitmapCacheUtils = BitmapCacheUtils.getInstance();
|
sBitmapCacheUtils = BitmapCacheUtils.getInstance();
|
||||||
LogUtils.d(TAG, "initUtils() Bitmap缓存工具已初始化(极致强制保持,永不销毁)");
|
LogUtils.d(TAG, "initUtils() | BackgroundSource/BitmapCache工具初始化完成 | 永久驻留内存");
|
||||||
|
|
||||||
// 极致强制初始化视图控件缓存工具(必初始化,永不销毁)
|
// 初始化视图控件缓存
|
||||||
// if(sMemoryCachedBackgroundView == null) {
|
|
||||||
// App.notifyMessage(TAG, "sMemoryCachedBackgroundView == null");
|
|
||||||
// }
|
|
||||||
sMemoryCachedBackgroundView = MemoryCachedBackgroundView.getLastInstance(this);
|
sMemoryCachedBackgroundView = MemoryCachedBackgroundView.getLastInstance(this);
|
||||||
if (sMemoryCachedBackgroundView == null) {
|
if (sMemoryCachedBackgroundView == null) {
|
||||||
sMemoryCachedBackgroundView = MemoryCachedBackgroundView.getInstance(this, sBackgroundSourceUtils.getCurrentBackgroundBean(), true);
|
sMemoryCachedBackgroundView = MemoryCachedBackgroundView.getInstance(this, sBackgroundSourceUtils.getCurrentBackgroundBean(), true);
|
||||||
LogUtils.d(TAG, "initUtils() 视图控件缓存工具已新建实例");
|
LogUtils.d(TAG, "initUtils() | 视图缓存工具:新建实例完成");
|
||||||
//App.notifyMessage(TAG, "没有使用缓存控件");
|
|
||||||
}
|
}
|
||||||
|
LogUtils.d(TAG, "initUtils() | MemoryCachedBackgroundView初始化完成 | 永久驻留内存");
|
||||||
//App.notifyMessage(TAG, "initUtils() 视图控件缓存工具已初始化(极致强制保持,永不销毁)");
|
|
||||||
LogUtils.d(TAG, "initUtils() 视图控件缓存工具已初始化(极致强制保持,永不销毁)");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化广播接收器
|
* 初始化全局广播接收器
|
||||||
*/
|
*/
|
||||||
private void initReceiver() {
|
private void initReceiver() {
|
||||||
LogUtils.d(TAG, "initReceiver() 开始初始化广播接收器");
|
LogUtils.d(TAG, "initReceiver() | 开始初始化广播接收器");
|
||||||
mGlobalReceiver = new GlobalApplicationReceiver(this);
|
mGlobalReceiver = new GlobalApplicationReceiver(this);
|
||||||
mGlobalReceiver.registerAction();
|
mGlobalReceiver.registerAction();
|
||||||
LogUtils.d(TAG, "initReceiver() 广播接收器注册完成");
|
LogUtils.d(TAG, "initReceiver() | 广播接收器注册完成");
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===================== 私有释放方法区(按资源重要性排序) =====================
|
// ===================== 私有释放方法区(按资源重要性排序) =====================
|
||||||
@@ -275,13 +266,13 @@ public class App extends GlobalApplication {
|
|||||||
* 释放广播接收器资源
|
* 释放广播接收器资源
|
||||||
*/
|
*/
|
||||||
private void releaseReceiver() {
|
private void releaseReceiver() {
|
||||||
LogUtils.d(TAG, "releaseReceiver() 开始释放广播接收器");
|
LogUtils.d(TAG, "releaseReceiver() | 开始释放广播接收器");
|
||||||
if (mGlobalReceiver != null) {
|
if (mGlobalReceiver != null) {
|
||||||
mGlobalReceiver.unregisterAction();
|
mGlobalReceiver.unregisterAction();
|
||||||
mGlobalReceiver = null;
|
mGlobalReceiver = null;
|
||||||
LogUtils.d(TAG, "releaseReceiver() 广播接收器资源已释放");
|
LogUtils.d(TAG, "releaseReceiver() | 广播接收器资源释放完成");
|
||||||
} else {
|
} else {
|
||||||
LogUtils.d(TAG, "releaseReceiver() 广播接收器未初始化,无需释放");
|
LogUtils.d(TAG, "releaseReceiver() | 无需释放:广播接收器未初始化");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,13 +280,13 @@ public class App extends GlobalApplication {
|
|||||||
* 释放通知管理工具资源
|
* 释放通知管理工具资源
|
||||||
*/
|
*/
|
||||||
private void releaseNotificationManager() {
|
private void releaseNotificationManager() {
|
||||||
LogUtils.d(TAG, "releaseNotificationManager() 开始释放通知工具");
|
LogUtils.d(TAG, "releaseNotificationManager() | 开始释放通知工具");
|
||||||
if (sNotificationManagerUtils != null) {
|
if (sNotificationManagerUtils != null) {
|
||||||
sNotificationManagerUtils.release();
|
sNotificationManagerUtils.release();
|
||||||
sNotificationManagerUtils = null;
|
sNotificationManagerUtils = null;
|
||||||
LogUtils.d(TAG, "releaseNotificationManager() 通知工具资源已释放");
|
LogUtils.d(TAG, "releaseNotificationManager() | 通知工具资源释放完成");
|
||||||
} else {
|
} else {
|
||||||
LogUtils.d(TAG, "releaseNotificationManager() 通知工具未初始化,无需释放");
|
LogUtils.d(TAG, "releaseNotificationManager() | 无需释放:通知工具未初始化");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,27 +295,26 @@ public class App extends GlobalApplication {
|
|||||||
* 记录详细缓存状态(用于调试,监控极致强制缓存效果)
|
* 记录详细缓存状态(用于调试,监控极致强制缓存效果)
|
||||||
*/
|
*/
|
||||||
private void logDetailedCacheStatus() {
|
private void logDetailedCacheStatus() {
|
||||||
LogUtils.d(TAG, "logDetailedCacheStatus() 开始记录详细缓存状态");
|
LogUtils.d(TAG, "logDetailedCacheStatus() | 开始记录缓存状态");
|
||||||
// Bitmap缓存状态
|
|
||||||
|
// 记录Bitmap缓存状态
|
||||||
if (sBitmapCacheUtils != null) {
|
if (sBitmapCacheUtils != null) {
|
||||||
LogUtils.d(TAG, String.format("%s Bitmap缓存工具实例有效(极致强制保持)", CACHE_PROTECT_TAG));
|
LogUtils.d(CACHE_PROTECT_TAG, "Bitmap缓存工具:实例有效(永久驻留)");
|
||||||
// 假设BitmapCacheUtils有获取缓存数量的方法
|
|
||||||
try {
|
try {
|
||||||
int cacheCount = sBitmapCacheUtils.getCacheCount();
|
int cacheCount = sBitmapCacheUtils.getCacheCount();
|
||||||
LogUtils.d(TAG, String.format("%s Bitmap缓存数量=%d", CACHE_PROTECT_TAG, cacheCount));
|
LogUtils.d(CACHE_PROTECT_TAG, "Bitmap缓存数量:" + cacheCount);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtils.d(TAG, String.format("%s Bitmap缓存数量获取失败(不影响缓存)| 异常信息=%s",
|
LogUtils.d(CACHE_PROTECT_TAG, "Bitmap缓存数量获取失败 | 异常信息:" + e.getMessage());
|
||||||
CACHE_PROTECT_TAG, e.getMessage()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 视图控件缓存状态
|
|
||||||
|
// 记录视图缓存状态
|
||||||
if (sMemoryCachedBackgroundView != null) {
|
if (sMemoryCachedBackgroundView != null) {
|
||||||
LogUtils.d(TAG, String.format("%s 视图控件缓存工具实例有效(极致强制保持)", CACHE_PROTECT_TAG));
|
LogUtils.d(CACHE_PROTECT_TAG, "视图缓存工具:实例有效(永久驻留)");
|
||||||
// 记录视图实例总数
|
int viewCount = MemoryCachedBackgroundView.getInstanceCount();
|
||||||
int viewInstanceCount = MemoryCachedBackgroundView.getInstanceCount();
|
LogUtils.d(CACHE_PROTECT_TAG, "视图缓存实例总数:" + viewCount);
|
||||||
LogUtils.d(TAG, String.format("%s 视图控件实例总数=%d", CACHE_PROTECT_TAG, viewInstanceCount));
|
|
||||||
}
|
}
|
||||||
LogUtils.d(TAG, "logDetailedCacheStatus() 详细缓存状态记录完成,所有缓存均极致强制保持");
|
LogUtils.d(TAG, "logDetailedCacheStatus() | 缓存状态记录完成");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ import cc.winboll.studio.powerbell.utils.BackgroundSourceUtils;
|
|||||||
import cc.winboll.studio.powerbell.utils.PermissionUtils;
|
import cc.winboll.studio.powerbell.utils.PermissionUtils;
|
||||||
import cc.winboll.studio.powerbell.utils.ServiceUtils;
|
import cc.winboll.studio.powerbell.utils.ServiceUtils;
|
||||||
import cc.winboll.studio.powerbell.views.MainContentView;
|
import cc.winboll.studio.powerbell.views.MainContentView;
|
||||||
import cc.winboll.studio.libappbase.ToastUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 应用核心主活动
|
* 应用核心主活动
|
||||||
@@ -45,38 +44,40 @@ import cc.winboll.studio.libappbase.ToastUtils;
|
|||||||
*/
|
*/
|
||||||
public class MainActivity extends WinBoLLActivity implements MainContentView.OnViewActionListener {
|
public class MainActivity extends WinBoLLActivity implements MainContentView.OnViewActionListener {
|
||||||
|
|
||||||
// ======================== 静态常量(置顶统一,抽离魔法值)========================
|
// ======================== 静态常量区(抽离魔法值,按功能分类)========================
|
||||||
public static final String TAG = "MainActivity";
|
public static final String TAG = "MainActivity";
|
||||||
private static final int REQUEST_BACKGROUND_SETTINGS_ACTIVITY = 1001;
|
private static final int REQUEST_BACKGROUND_SETTINGS_ACTIVITY = 1001;
|
||||||
public static final String EXTRA_ISRELOAD_BACKGROUNDVIEW = "EXTRA_ISRELOAD_BACKGROUNDVIEW";
|
public static final String EXTRA_ISRELOAD_BACKGROUNDVIEW = "EXTRA_ISRELOAD_BACKGROUNDVIEW";
|
||||||
private static final long DELAY_LOAD_NON_CRITICAL = 500L;
|
private static final long DELAY_LOAD_NON_CRITICAL = 500L;
|
||||||
|
|
||||||
|
// Handler 消息常量
|
||||||
public static final int MSG_RELOAD_APPCONFIG = 0;
|
public static final int MSG_RELOAD_APPCONFIG = 0;
|
||||||
public static final int MSG_CURRENTVALUEBATTERY = 1;
|
public static final int MSG_CURRENTVALUEBATTERY = 1;
|
||||||
public static final int MSG_LOAD_BACKGROUND = 2;
|
public static final int MSG_LOAD_BACKGROUND = 2;
|
||||||
private static final int MSG_UPDATE_SERVICE_SWITCH = 3;
|
private static final int MSG_UPDATE_SERVICE_SWITCH = 3;
|
||||||
|
|
||||||
// ======================== 静态成员(全局共享,严格管控生命周期)========================
|
// ======================== 静态成员区(全局共享,管控生命周期)========================
|
||||||
private static MainActivity sMainActivity;
|
private static MainActivity sMainActivity;
|
||||||
private static Handler sGlobalHandler;
|
private static Handler sGlobalHandler;
|
||||||
|
|
||||||
// ======================== 工具类实例(单例,避免重复初始化)========================
|
// ======================== 工具类实例区(单例化,避免重复初始化)========================
|
||||||
private PermissionUtils mPermissionUtils;
|
private PermissionUtils mPermissionUtils;
|
||||||
private AppConfigUtils mAppConfigUtils;
|
private AppConfigUtils mAppConfigUtils;
|
||||||
private BackgroundSourceUtils mBgSourceUtils;
|
private BackgroundSourceUtils mBgSourceUtils;
|
||||||
|
|
||||||
// ======================== 应用核心实例 =========================
|
// ======================== 应用核心实例区 =========================
|
||||||
private App mApplication;
|
private App mApplication;
|
||||||
private MainContentView mMainContentView;
|
private MainContentView mMainContentView;
|
||||||
private ControlCenterServiceBean mServiceControlBean;
|
private ControlCenterServiceBean mServiceControlBean;
|
||||||
|
|
||||||
// ======================== 基础视图组件 =========================
|
// ======================== 基础视图组件区 =========================
|
||||||
private Toolbar mToolbar;
|
private Toolbar mToolbar;
|
||||||
private ViewStub mAdsViewStub;
|
private ViewStub mAdsViewStub;
|
||||||
private ADsBannerView mADsBannerView;
|
private ADsBannerView mADsBannerView;
|
||||||
private Drawable mFrameDrawable;
|
private Drawable mFrameDrawable;
|
||||||
private Menu mMenu;
|
private Menu mMenu;
|
||||||
|
|
||||||
// ======================== 生命周期方法(按系统调用顺序排列)========================
|
// ======================== 生命周期方法区(按系统调用顺序排列)========================
|
||||||
@Override
|
@Override
|
||||||
public Activity getActivity() {
|
public Activity getActivity() {
|
||||||
return this;
|
return this;
|
||||||
@@ -90,7 +91,7 @@ public class MainActivity extends WinBoLLActivity implements MainContentView.OnV
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
LogUtils.d(TAG, String.format("onCreate() | savedInstanceState=%s", savedInstanceState));
|
LogUtils.d(TAG, "onCreate() 调用 | savedInstanceState: " + savedInstanceState);
|
||||||
|
|
||||||
initGlobalHandler();
|
initGlobalHandler();
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
@@ -99,51 +100,32 @@ public class MainActivity extends WinBoLLActivity implements MainContentView.OnV
|
|||||||
initCriticalView();
|
initCriticalView();
|
||||||
initCoreUtilsAsync();
|
initCoreUtilsAsync();
|
||||||
loadNonCriticalViewDelayed();
|
loadNonCriticalViewDelayed();
|
||||||
|
|
||||||
// 处理首次启动的参数
|
// 处理首次启动参数
|
||||||
handleReloadBackgroundParam(getIntent());
|
handleReloadBackgroundParam(getIntent());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onNewIntent(Intent intent) {
|
||||||
|
super.onNewIntent(intent);
|
||||||
|
LogUtils.d(TAG, "onNewIntent() 调用 | intent: " + intent);
|
||||||
|
// 关键:更新Activity持有的Intent,确保后续获取最新值
|
||||||
|
setIntent(intent);
|
||||||
|
// 统一处理刷新背景参数
|
||||||
|
handleReloadBackgroundParam(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onNewIntent(Intent intent) {
|
|
||||||
super.onNewIntent(intent);
|
|
||||||
// 关键:将新 Intent 赋值给 Activity 的 Intent,确保后续 getIntent() 获取最新值
|
|
||||||
setIntent(intent);
|
|
||||||
// 统一处理参数
|
|
||||||
handleReloadBackgroundParam(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 统一处理刷新背景的参数
|
|
||||||
* @param intent 启动 MainActivity 的 Intent
|
|
||||||
*/
|
|
||||||
private void handleReloadBackgroundParam(Intent intent) {
|
|
||||||
if (intent == null) {
|
|
||||||
LogUtils.d(TAG, "handleReloadBackgroundParam: Intent 为空");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 获取传递的参数,默认值为 false
|
|
||||||
boolean isReloadBackgroundView = intent.getBooleanExtra(EXTRA_ISRELOAD_BACKGROUNDVIEW, false);
|
|
||||||
if (isReloadBackgroundView) {
|
|
||||||
LogUtils.d(TAG, "接收到刷新背景视图指令");
|
|
||||||
// 执行背景刷新逻辑
|
|
||||||
//App.notifyMessage(TAG, "reloadBackgroundView");
|
|
||||||
reloadBackgroundView();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostCreate(Bundle savedInstanceState) {
|
protected void onPostCreate(Bundle savedInstanceState) {
|
||||||
super.onPostCreate(savedInstanceState);
|
super.onPostCreate(savedInstanceState);
|
||||||
LogUtils.d(TAG, String.format("onPostCreate() | savedInstanceState=%s", savedInstanceState));
|
LogUtils.d(TAG, "onPostCreate() 调用 | savedInstanceState: " + savedInstanceState);
|
||||||
mPermissionUtils.startPermissionRequest(this);
|
mPermissionUtils.startPermissionRequest(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
LogUtils.d(TAG, "onResume()");
|
LogUtils.d(TAG, "onResume() 调用");
|
||||||
|
|
||||||
if (mADsBannerView != null) {
|
if (mADsBannerView != null) {
|
||||||
mADsBannerView.resumeADs(this);
|
mADsBannerView.resumeADs(this);
|
||||||
@@ -154,13 +136,13 @@ public class MainActivity extends WinBoLLActivity implements MainContentView.OnV
|
|||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
LogUtils.d(TAG, "onPause()");
|
LogUtils.d(TAG, "onPause() 调用");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
LogUtils.d(TAG, "onDestroy()");
|
LogUtils.d(TAG, "onDestroy() 调用");
|
||||||
|
|
||||||
// 释放广告资源
|
// 释放广告资源
|
||||||
if (mADsBannerView != null) {
|
if (mADsBannerView != null) {
|
||||||
@@ -174,7 +156,7 @@ public class MainActivity extends WinBoLLActivity implements MainContentView.OnV
|
|||||||
mMainContentView = null;
|
mMainContentView = null;
|
||||||
LogUtils.d(TAG, "onDestroy: 核心视图资源已释放");
|
LogUtils.d(TAG, "onDestroy: 核心视图资源已释放");
|
||||||
}
|
}
|
||||||
// 销毁Handler,防止内存泄漏
|
// 销毁Handler防止内存泄漏
|
||||||
if (sGlobalHandler != null) {
|
if (sGlobalHandler != null) {
|
||||||
sGlobalHandler.removeCallbacksAndMessages(null);
|
sGlobalHandler.removeCallbacksAndMessages(null);
|
||||||
sGlobalHandler = null;
|
sGlobalHandler = null;
|
||||||
@@ -186,7 +168,7 @@ public class MainActivity extends WinBoLLActivity implements MainContentView.OnV
|
|||||||
mFrameDrawable = null;
|
mFrameDrawable = null;
|
||||||
LogUtils.d(TAG, "onDestroy: 框架Drawable已释放");
|
LogUtils.d(TAG, "onDestroy: 框架Drawable已释放");
|
||||||
}
|
}
|
||||||
// 置空所有引用
|
// 置空所有引用,消除内存泄漏风险
|
||||||
sMainActivity = null;
|
sMainActivity = null;
|
||||||
mPermissionUtils = null;
|
mPermissionUtils = null;
|
||||||
mAppConfigUtils = null;
|
mAppConfigUtils = null;
|
||||||
@@ -201,21 +183,23 @@ public class MainActivity extends WinBoLLActivity implements MainContentView.OnV
|
|||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
LogUtils.d(TAG, String.format("onActivityResult() | requestCode=%d | resultCode=%d | data=%s",
|
LogUtils.d(TAG, "onActivityResult() 调用 | requestCode: " + requestCode + " | resultCode: " + resultCode + " | data: " + data);
|
||||||
requestCode, resultCode, data));
|
|
||||||
mPermissionUtils.handlePermissionRequest(this, requestCode, resultCode, data);
|
mPermissionUtils.handlePermissionRequest(this, requestCode, resultCode, data);
|
||||||
|
|
||||||
if (requestCode == REQUEST_BACKGROUND_SETTINGS_ACTIVITY && sGlobalHandler != null) {
|
if (requestCode == REQUEST_BACKGROUND_SETTINGS_ACTIVITY && sGlobalHandler != null) {
|
||||||
sGlobalHandler.sendEmptyMessage(MSG_LOAD_BACKGROUND);
|
sGlobalHandler.sendEmptyMessage(MSG_LOAD_BACKGROUND);
|
||||||
LogUtils.d(TAG, "onActivityResult: 发送背景加载消息");
|
LogUtils.d(TAG, "onActivityResult: 发送背景加载消息");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ======================== 菜单与导航方法 ========================
|
// ======================== 菜单与导航方法区 ========================
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
LogUtils.d(TAG, String.format("onCreateOptionsMenu() | menu=%s", menu));
|
LogUtils.d(TAG, "onCreateOptionsMenu() 调用 | menu: " + menu);
|
||||||
mMenu = menu;
|
mMenu = menu;
|
||||||
AESThemeUtil.inflateMenu(this, menu);
|
AESThemeUtil.inflateMenu(this, menu);
|
||||||
|
|
||||||
|
// 调试模式加载测试菜单
|
||||||
if (App.isDebugging()) {
|
if (App.isDebugging()) {
|
||||||
DevelopUtils.inflateMenu(this, menu);
|
DevelopUtils.inflateMenu(this, menu);
|
||||||
getMenuInflater().inflate(R.menu.toolbar_unittest, mMenu);
|
getMenuInflater().inflate(R.menu.toolbar_unittest, mMenu);
|
||||||
@@ -227,14 +211,17 @@ public class MainActivity extends WinBoLLActivity implements MainContentView.OnV
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
LogUtils.d(TAG, String.format("onOptionsItemSelected() | itemId=%d", item.getItemId()));
|
LogUtils.d(TAG, "onOptionsItemSelected() 调用 | itemId: " + item.getItemId());
|
||||||
|
// 主题切换处理
|
||||||
if (AESThemeUtil.onAppThemeItemSelected(this, item)) {
|
if (AESThemeUtil.onAppThemeItemSelected(this, item)) {
|
||||||
recreate();
|
recreate();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
// 开发者功能处理
|
||||||
if (DevelopUtils.onDevelopItemSelected(this, item)) {
|
if (DevelopUtils.onDevelopItemSelected(this, item)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
// 菜单点击事件分发
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.action_settings:
|
case R.id.action_settings:
|
||||||
startActivity(new Intent(this, SettingsActivity.class));
|
startActivity(new Intent(this, SettingsActivity.class));
|
||||||
@@ -266,7 +253,7 @@ public class MainActivity extends WinBoLLActivity implements MainContentView.OnV
|
|||||||
@Override
|
@Override
|
||||||
public void setupToolbar() {
|
public void setupToolbar() {
|
||||||
super.setupToolbar();
|
super.setupToolbar();
|
||||||
LogUtils.d(TAG, "setupToolbar()");
|
LogUtils.d(TAG, "setupToolbar() 调用");
|
||||||
if (getSupportActionBar() != null) {
|
if (getSupportActionBar() != null) {
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
||||||
LogUtils.d(TAG, "setupToolbar: 已隐藏返回按钮");
|
LogUtils.d(TAG, "setupToolbar: 已隐藏返回按钮");
|
||||||
@@ -275,35 +262,37 @@ public class MainActivity extends WinBoLLActivity implements MainContentView.OnV
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
LogUtils.d(TAG, "onBackPressed()");
|
LogUtils.d(TAG, "onBackPressed() 调用");
|
||||||
moveTaskToBack(true);
|
moveTaskToBack(true);
|
||||||
LogUtils.d(TAG, "onBackPressed: 应用已退至后台");
|
LogUtils.d(TAG, "onBackPressed: 应用已退至后台");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||||
LogUtils.d(TAG, String.format("dispatchKeyEvent() | event=%s", event));
|
LogUtils.d(TAG, "dispatchKeyEvent() 调用 | event: " + event);
|
||||||
return super.dispatchKeyEvent(event);
|
return super.dispatchKeyEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ======================== 核心初始化方法 ========================
|
// ======================== 核心初始化方法区 ========================
|
||||||
private void initPermissionUtils() {
|
private void initPermissionUtils() {
|
||||||
LogUtils.d(TAG, "initPermissionUtils()");
|
LogUtils.d(TAG, "initPermissionUtils() 调用");
|
||||||
mPermissionUtils = PermissionUtils.getInstance();
|
mPermissionUtils = PermissionUtils.getInstance();
|
||||||
LogUtils.d(TAG, "initPermissionUtils: 权限工具类已初始化");
|
LogUtils.d(TAG, "initPermissionUtils: 权限工具类已初始化");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initGlobalHandler() {
|
private void initGlobalHandler() {
|
||||||
LogUtils.d(TAG, "initGlobalHandler()");
|
LogUtils.d(TAG, "initGlobalHandler() 调用");
|
||||||
if (sGlobalHandler == null) {
|
if (sGlobalHandler == null) {
|
||||||
sGlobalHandler = new Handler() {
|
sGlobalHandler = new Handler() {
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message msg) {
|
public void handleMessage(Message msg) {
|
||||||
|
// Activity已销毁则跳过消息处理
|
||||||
if (sMainActivity == null || sMainActivity.isFinishing() || sMainActivity.isDestroyed()) {
|
if (sMainActivity == null || sMainActivity.isFinishing() || sMainActivity.isDestroyed()) {
|
||||||
LogUtils.w(TAG, String.format("handleMessage: Activity已销毁,跳过消息 | what=%d", msg.what));
|
LogUtils.w(TAG, "handleMessage: Activity已销毁,跳过消息 | what: " + msg.what);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LogUtils.d(TAG, String.format("handleMessage() | what=%d", msg.what));
|
LogUtils.d(TAG, "handleMessage() 调用 | what: " + msg.what);
|
||||||
|
|
||||||
switch (msg.what) {
|
switch (msg.what) {
|
||||||
case MSG_RELOAD_APPCONFIG:
|
case MSG_RELOAD_APPCONFIG:
|
||||||
sMainActivity.updateViewData();
|
sMainActivity.updateViewData();
|
||||||
@@ -311,7 +300,7 @@ public class MainActivity extends WinBoLLActivity implements MainContentView.OnV
|
|||||||
case MSG_CURRENTVALUEBATTERY:
|
case MSG_CURRENTVALUEBATTERY:
|
||||||
if (sMainActivity.mMainContentView != null) {
|
if (sMainActivity.mMainContentView != null) {
|
||||||
sMainActivity.mMainContentView.updateCurrentBattery(msg.arg1);
|
sMainActivity.mMainContentView.updateCurrentBattery(msg.arg1);
|
||||||
LogUtils.d(TAG, String.format("handleMessage: 更新当前电量 | value=%d", msg.arg1));
|
LogUtils.d(TAG, "handleMessage: 更新当前电量 | value: " + msg.arg1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MSG_LOAD_BACKGROUND:
|
case MSG_LOAD_BACKGROUND:
|
||||||
@@ -330,18 +319,14 @@ public class MainActivity extends WinBoLLActivity implements MainContentView.OnV
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initMainContentView() {
|
private void initMainContentView() {
|
||||||
LogUtils.d(TAG, "initMainContentView()");
|
LogUtils.d(TAG, "initMainContentView() 调用");
|
||||||
View rootView = findViewById(android.R.id.content);
|
View rootView = findViewById(android.R.id.content);
|
||||||
mMainContentView = new MainContentView(this, rootView, this);
|
mMainContentView = new MainContentView(this, rootView, this);
|
||||||
LogUtils.d(TAG, "initMainContentView: 核心内容视图已初始化");
|
LogUtils.d(TAG, "initMainContentView: 核心内容视图已初始化");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reloadBackgroundView() {
|
|
||||||
mMainContentView.reloadBackgroundView();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initCriticalView() {
|
private void initCriticalView() {
|
||||||
LogUtils.d(TAG, "initCriticalView()");
|
LogUtils.d(TAG, "initCriticalView() 调用");
|
||||||
sMainActivity = this;
|
sMainActivity = this;
|
||||||
mToolbar = findViewById(R.id.toolbar);
|
mToolbar = findViewById(R.id.toolbar);
|
||||||
setSupportActionBar(mToolbar);
|
setSupportActionBar(mToolbar);
|
||||||
@@ -354,11 +339,11 @@ public class MainActivity extends WinBoLLActivity implements MainContentView.OnV
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initCoreUtilsAsync() {
|
private void initCoreUtilsAsync() {
|
||||||
LogUtils.d(TAG, "initCoreUtilsAsync()");
|
LogUtils.d(TAG, "initCoreUtilsAsync() 调用");
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
LogUtils.d(TAG, String.format("initCoreUtilsAsync: 异步线程启动 | threadId=%d", Thread.currentThread().getId()));
|
LogUtils.d(TAG, "initCoreUtilsAsync: 异步线程启动 | threadId: " + Thread.currentThread().getId());
|
||||||
mApplication = (App) getApplication();
|
mApplication = (App) getApplication();
|
||||||
mAppConfigUtils = AppConfigUtils.getInstance(getApplicationContext());
|
mAppConfigUtils = AppConfigUtils.getInstance(getApplicationContext());
|
||||||
mBgSourceUtils = BackgroundSourceUtils.getInstance(getActivity());
|
mBgSourceUtils = BackgroundSourceUtils.getInstance(getActivity());
|
||||||
@@ -374,8 +359,8 @@ public class MainActivity extends WinBoLLActivity implements MainContentView.OnV
|
|||||||
// 根据配置启停服务
|
// 根据配置启停服务
|
||||||
final boolean isServiceEnable = mServiceControlBean.isEnableService();
|
final boolean isServiceEnable = mServiceControlBean.isEnableService();
|
||||||
final boolean isServiceAlive = ServiceUtils.isServiceAlive(getApplicationContext(), ControlCenterService.class.getName());
|
final boolean isServiceAlive = ServiceUtils.isServiceAlive(getApplicationContext(), ControlCenterService.class.getName());
|
||||||
LogUtils.d(TAG, String.format("initCoreUtilsAsync: 服务配置状态 | isServiceEnable=%b | isServiceAlive=%b",
|
LogUtils.d(TAG, "initCoreUtilsAsync: 服务配置状态 | isServiceEnable: " + isServiceEnable + " | isServiceAlive: " + isServiceAlive);
|
||||||
isServiceEnable, isServiceAlive));
|
|
||||||
if (isServiceEnable && !isServiceAlive) {
|
if (isServiceEnable && !isServiceAlive) {
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
@@ -402,7 +387,7 @@ public class MainActivity extends WinBoLLActivity implements MainContentView.OnV
|
|||||||
LogUtils.w(TAG, "initCoreUtilsAsync: Activity已销毁,跳过UI更新");
|
LogUtils.w(TAG, "initCoreUtilsAsync: Activity已销毁,跳过UI更新");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 加载框架背景(适配API23+)
|
// 适配API30,兼容低版本Drawable加载
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
mFrameDrawable = getResources().getDrawable(R.drawable.bg_frame, getTheme());
|
mFrameDrawable = getResources().getDrawable(R.drawable.bg_frame, getTheme());
|
||||||
} else {
|
} else {
|
||||||
@@ -419,7 +404,7 @@ public class MainActivity extends WinBoLLActivity implements MainContentView.OnV
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadNonCriticalViewDelayed() {
|
private void loadNonCriticalViewDelayed() {
|
||||||
LogUtils.d(TAG, String.format("loadNonCriticalViewDelayed() | 延迟时长=%dms", DELAY_LOAD_NON_CRITICAL));
|
LogUtils.d(TAG, "loadNonCriticalViewDelayed() 调用 | 延迟时长: " + DELAY_LOAD_NON_CRITICAL + "ms");
|
||||||
new Handler().postDelayed(new Runnable() {
|
new Handler().postDelayed(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -432,9 +417,27 @@ public class MainActivity extends WinBoLLActivity implements MainContentView.OnV
|
|||||||
}, DELAY_LOAD_NON_CRITICAL);
|
}, DELAY_LOAD_NON_CRITICAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ======================== 视图操作方法 ========================
|
// ======================== 视图操作方法区 ========================
|
||||||
|
private void handleReloadBackgroundParam(Intent intent) {
|
||||||
|
LogUtils.d(TAG, "handleReloadBackgroundParam() 调用 | intent: " + intent);
|
||||||
|
if (intent == null) {
|
||||||
|
LogUtils.d(TAG, "handleReloadBackgroundParam: Intent 为空");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
boolean isReloadBackgroundView = intent.getBooleanExtra(EXTRA_ISRELOAD_BACKGROUNDVIEW, false);
|
||||||
|
if (isReloadBackgroundView) {
|
||||||
|
LogUtils.d(TAG, "handleReloadBackgroundParam: 接收到刷新背景视图指令");
|
||||||
|
reloadBackgroundView();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void reloadBackgroundView() {
|
||||||
|
LogUtils.d(TAG, "reloadBackgroundView() 调用");
|
||||||
|
mMainContentView.reloadBackgroundView();
|
||||||
|
}
|
||||||
|
|
||||||
private void loadAdsView() {
|
private void loadAdsView() {
|
||||||
LogUtils.d(TAG, "loadAdsView()");
|
LogUtils.d(TAG, "loadAdsView() 调用");
|
||||||
if (mAdsViewStub == null) {
|
if (mAdsViewStub == null) {
|
||||||
LogUtils.e(TAG, "loadAdsView: 广告ViewStub为空,加载失败");
|
LogUtils.e(TAG, "loadAdsView: 广告ViewStub为空,加载失败");
|
||||||
return;
|
return;
|
||||||
@@ -449,7 +452,7 @@ public class MainActivity extends WinBoLLActivity implements MainContentView.OnV
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateViewData() {
|
private void updateViewData() {
|
||||||
LogUtils.d(TAG, "updateViewData()");
|
LogUtils.d(TAG, "updateViewData() 调用");
|
||||||
if (mMainContentView == null || mFrameDrawable == null) {
|
if (mMainContentView == null || mFrameDrawable == null) {
|
||||||
LogUtils.e(TAG, "updateViewData: 核心视图或框架背景为空,更新失败");
|
LogUtils.e(TAG, "updateViewData: 核心视图或框架背景为空,更新失败");
|
||||||
return;
|
return;
|
||||||
@@ -459,14 +462,13 @@ public class MainActivity extends WinBoLLActivity implements MainContentView.OnV
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void reloadBackground() {
|
private void reloadBackground() {
|
||||||
LogUtils.d(TAG, "reloadBackground()");
|
LogUtils.d(TAG, "reloadBackground() 调用");
|
||||||
if (mMainContentView == null || mBgSourceUtils == null) {
|
if (mMainContentView == null || mBgSourceUtils == null) {
|
||||||
LogUtils.e(TAG, "reloadBackground: 核心视图或背景工具类为空,加载失败");
|
LogUtils.e(TAG, "reloadBackground: 核心视图或背景工具类为空,加载失败");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BackgroundBean currentBgBean = mBgSourceUtils.getCurrentBackgroundBean();
|
BackgroundBean currentBgBean = mBgSourceUtils.getCurrentBackgroundBean();
|
||||||
if (currentBgBean != null) {
|
if (currentBgBean != null) {
|
||||||
//ToastUtils.show("currentBgBean");
|
|
||||||
mMainContentView.backgroundView.loadByBackgroundBean(currentBgBean, true);
|
mMainContentView.backgroundView.loadByBackgroundBean(currentBgBean, true);
|
||||||
LogUtils.d(TAG, "reloadBackground: 已加载自定义背景");
|
LogUtils.d(TAG, "reloadBackground: 已加载自定义背景");
|
||||||
} else {
|
} else {
|
||||||
@@ -476,7 +478,7 @@ public class MainActivity extends WinBoLLActivity implements MainContentView.OnV
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateServiceSwitchUI() {
|
private void updateServiceSwitchUI() {
|
||||||
LogUtils.d(TAG, "updateServiceSwitchUI()");
|
LogUtils.d(TAG, "updateServiceSwitchUI() 调用");
|
||||||
if (mMainContentView == null || mServiceControlBean == null) {
|
if (mMainContentView == null || mServiceControlBean == null) {
|
||||||
LogUtils.e(TAG, "updateServiceSwitchUI: 核心视图或服务配置为空,更新失败");
|
LogUtils.e(TAG, "updateServiceSwitchUI: 核心视图或服务配置为空,更新失败");
|
||||||
return;
|
return;
|
||||||
@@ -485,12 +487,12 @@ public class MainActivity extends WinBoLLActivity implements MainContentView.OnV
|
|||||||
mMainContentView.setServiceSwitchEnabled(false);
|
mMainContentView.setServiceSwitchEnabled(false);
|
||||||
mMainContentView.setServiceSwitchChecked(configEnabled);
|
mMainContentView.setServiceSwitchChecked(configEnabled);
|
||||||
mMainContentView.setServiceSwitchEnabled(true);
|
mMainContentView.setServiceSwitchEnabled(true);
|
||||||
LogUtils.d(TAG, String.format("updateServiceSwitchUI: 服务开关已更新 | 状态=%b", configEnabled));
|
LogUtils.d(TAG, "updateServiceSwitchUI: 服务开关已更新 | 状态: " + configEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ======================== 服务与线程管理方法 ========================
|
// ======================== 服务与线程管理方法区 ========================
|
||||||
private void toggleServiceEnableState(boolean isEnable) {
|
private void toggleServiceEnableState(boolean isEnable) {
|
||||||
LogUtils.d(TAG, String.format("toggleServiceEnableState() | 目标状态=%b", isEnable));
|
LogUtils.d(TAG, "toggleServiceEnableState() 调用 | 目标状态: " + isEnable);
|
||||||
if (mServiceControlBean == null) {
|
if (mServiceControlBean == null) {
|
||||||
LogUtils.e(TAG, "toggleServiceEnableState: 服务配置为空,切换失败");
|
LogUtils.e(TAG, "toggleServiceEnableState: 服务配置为空,切换失败");
|
||||||
return;
|
return;
|
||||||
@@ -513,9 +515,9 @@ public class MainActivity extends WinBoLLActivity implements MainContentView.OnV
|
|||||||
sGlobalHandler.sendEmptyMessage(MSG_UPDATE_SERVICE_SWITCH);
|
sGlobalHandler.sendEmptyMessage(MSG_UPDATE_SERVICE_SWITCH);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ======================== 页面跳转方法 ========================
|
// ======================== 页面跳转方法区 ========================
|
||||||
private void startAboutActivity() {
|
private void startAboutActivity() {
|
||||||
LogUtils.d(TAG, "startAboutActivity()");
|
LogUtils.d(TAG, "startAboutActivity() 调用");
|
||||||
Intent aboutIntent = new Intent(getApplicationContext(), AboutActivity.class);
|
Intent aboutIntent = new Intent(getApplicationContext(), AboutActivity.class);
|
||||||
APPInfo appInfo = genDefaultAppInfo();
|
APPInfo appInfo = genDefaultAppInfo();
|
||||||
aboutIntent.putExtra(AboutActivity.EXTRA_APPINFO, appInfo);
|
aboutIntent.putExtra(AboutActivity.EXTRA_APPINFO, appInfo);
|
||||||
@@ -523,16 +525,16 @@ public class MainActivity extends WinBoLLActivity implements MainContentView.OnV
|
|||||||
LogUtils.d(TAG, "startAboutActivity: 关于页面已启动");
|
LogUtils.d(TAG, "startAboutActivity: 关于页面已启动");
|
||||||
}
|
}
|
||||||
|
|
||||||
// ======================== 消息发送方法 ========================
|
// ======================== 消息发送方法区 ========================
|
||||||
private void notifyServiceAppConfigChange() {
|
private void notifyServiceAppConfigChange() {
|
||||||
LogUtils.d(TAG, "notifyServiceAppConfigChange()");
|
LogUtils.d(TAG, "notifyServiceAppConfigChange() 调用");
|
||||||
ControlCenterService.sendAppConfigStatusUpdateMessage(this);
|
ControlCenterService.sendAppConfigStatusUpdateMessage(this);
|
||||||
reloadAppConfig();
|
reloadAppConfig();
|
||||||
LogUtils.d(TAG, "notifyServiceAppConfigChange: 服务配置已通知更新");
|
LogUtils.d(TAG, "notifyServiceAppConfigChange: 服务配置已通知更新");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reloadAppConfig() {
|
public static void reloadAppConfig() {
|
||||||
LogUtils.d(TAG, "reloadAppConfig()");
|
LogUtils.d(TAG, "reloadAppConfig() 调用");
|
||||||
if (sGlobalHandler != null) {
|
if (sGlobalHandler != null) {
|
||||||
sGlobalHandler.sendEmptyMessage(MSG_RELOAD_APPCONFIG);
|
sGlobalHandler.sendEmptyMessage(MSG_RELOAD_APPCONFIG);
|
||||||
LogUtils.d(TAG, "reloadAppConfig: 配置重载消息已发送");
|
LogUtils.d(TAG, "reloadAppConfig: 配置重载消息已发送");
|
||||||
@@ -542,7 +544,7 @@ public class MainActivity extends WinBoLLActivity implements MainContentView.OnV
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void sendCurrentBatteryValueMessage(int value) {
|
public static void sendCurrentBatteryValueMessage(int value) {
|
||||||
LogUtils.d(TAG, String.format("sendCurrentBatteryValueMessage() | 电量=%d", value));
|
LogUtils.d(TAG, "sendCurrentBatteryValueMessage() 调用 | 电量: " + value);
|
||||||
if (sGlobalHandler != null) {
|
if (sGlobalHandler != null) {
|
||||||
Message msg = sGlobalHandler.obtainMessage(MSG_CURRENTVALUEBATTERY);
|
Message msg = sGlobalHandler.obtainMessage(MSG_CURRENTVALUEBATTERY);
|
||||||
msg.arg1 = value;
|
msg.arg1 = value;
|
||||||
@@ -553,9 +555,9 @@ public class MainActivity extends WinBoLLActivity implements MainContentView.OnV
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ======================== 辅助工具方法 ========================
|
// ======================== 辅助工具方法区 ========================
|
||||||
private APPInfo genDefaultAppInfo() {
|
private APPInfo genDefaultAppInfo() {
|
||||||
LogUtils.d(TAG, "genDefaultAppInfo()");
|
LogUtils.d(TAG, "genDefaultAppInfo() 调用");
|
||||||
String branchName = "powerbell";
|
String branchName = "powerbell";
|
||||||
APPInfo appInfo = new APPInfo();
|
APPInfo appInfo = new APPInfo();
|
||||||
appInfo.setAppName(getString(R.string.app_name));
|
appInfo.setAppName(getString(R.string.app_name));
|
||||||
@@ -572,34 +574,34 @@ public class MainActivity extends WinBoLLActivity implements MainContentView.OnV
|
|||||||
return appInfo;
|
return appInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ======================== MainContentView 事件回调 ========================
|
// ======================== MainContentView 事件回调区 ========================
|
||||||
@Override
|
@Override
|
||||||
public void onChargeReminderSwitchChanged(boolean isChecked) {
|
public void onChargeReminderSwitchChanged(boolean isChecked) {
|
||||||
LogUtils.d(TAG, String.format("onChargeReminderSwitchChanged() | isChecked=%b", isChecked));
|
LogUtils.d(TAG, "onChargeReminderSwitchChanged() 调用 | isChecked: " + isChecked);
|
||||||
notifyServiceAppConfigChange();
|
notifyServiceAppConfigChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUsageReminderSwitchChanged(boolean isChecked) {
|
public void onUsageReminderSwitchChanged(boolean isChecked) {
|
||||||
LogUtils.d(TAG, String.format("onUsageReminderSwitchChanged() | isChecked=%b", isChecked));
|
LogUtils.d(TAG, "onUsageReminderSwitchChanged() 调用 | isChecked: " + isChecked);
|
||||||
notifyServiceAppConfigChange();
|
notifyServiceAppConfigChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onServiceSwitchChanged(boolean isChecked) {
|
public void onServiceSwitchChanged(boolean isChecked) {
|
||||||
LogUtils.d(TAG, String.format("onServiceSwitchChanged() | isChecked=%b", isChecked));
|
LogUtils.d(TAG, "onServiceSwitchChanged() 调用 | isChecked: " + isChecked);
|
||||||
toggleServiceEnableState(isChecked);
|
toggleServiceEnableState(isChecked);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onChargeReminderProgressChanged(int progress) {
|
public void onChargeReminderProgressChanged(int progress) {
|
||||||
LogUtils.d(TAG, String.format("onChargeReminderProgressChanged() | progress=%d", progress));
|
LogUtils.d(TAG, "onChargeReminderProgressChanged() 调用 | progress: " + progress);
|
||||||
notifyServiceAppConfigChange();
|
notifyServiceAppConfigChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUsageReminderProgressChanged(int progress) {
|
public void onUsageReminderProgressChanged(int progress) {
|
||||||
LogUtils.d(TAG, String.format("onUsageReminderProgressChanged() | progress=%d", progress));
|
LogUtils.d(TAG, "onUsageReminderProgressChanged() 调用 | progress: " + progress);
|
||||||
notifyServiceAppConfigChange();
|
notifyServiceAppConfigChange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import cc.winboll.studio.libappbase.LogUtils;
|
|||||||
*/
|
*/
|
||||||
public class ControlCenterServiceBean extends BaseBean implements Parcelable, Serializable {
|
public class ControlCenterServiceBean extends BaseBean implements Parcelable, Serializable {
|
||||||
// ====================== 静态常量(置顶统一管理,避免魔法值) ======================
|
// ====================== 静态常量(置顶统一管理,避免魔法值) ======================
|
||||||
private static final long serialVersionUID = 1L; // Serializable 必备,保障反序列化兼容
|
//private static final long serialVersionUID = 1L; // Serializable 必备,保障反序列化兼容
|
||||||
private static final String TAG = "ControlCenterServiceBean";
|
private static final String TAG = "ControlCenterServiceBean";
|
||||||
private static final String JSON_FIELD_IS_ENABLE_SERVICE = "isEnableService"; // JSON 字段常量,避免硬编码
|
private static final String JSON_FIELD_IS_ENABLE_SERVICE = "isEnableService"; // JSON 字段常量,避免硬编码
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public class ControlCenterServiceReceiver extends BroadcastReceiver {
|
|||||||
public ControlCenterServiceReceiver(ControlCenterService service) {
|
public ControlCenterServiceReceiver(ControlCenterService service) {
|
||||||
LogUtils.d(TAG, String.format("ControlCenterServiceReceiver() 构造 | 服务实例:%s",
|
LogUtils.d(TAG, String.format("ControlCenterServiceReceiver() 构造 | 服务实例:%s",
|
||||||
service != null ? service.getClass().getSimpleName() : "null"));
|
service != null ? service.getClass().getSimpleName() : "null"));
|
||||||
this.mwrControlCenterService = new WeakReference<>(service);
|
this.mwrControlCenterService = new WeakReference<ControlCenterService>(service);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ====================== 广播核心接收逻辑(入口方法,分Action分发处理) ======================
|
// ====================== 广播核心接收逻辑(入口方法,分Action分发处理) ======================
|
||||||
|
|||||||
@@ -189,11 +189,11 @@ public class MemoryCachedBackgroundView extends BackgroundView {
|
|||||||
* 从缓存实例中获取上下文(用于无外部上下文时的SP操作)
|
* 从缓存实例中获取上下文(用于无外部上下文时的SP操作)
|
||||||
* @return 上下文实例,无则返回null
|
* @return 上下文实例,无则返回null
|
||||||
*/
|
*/
|
||||||
private static Context getContextFromCache() {
|
// private static Context getContextFromCache() {
|
||||||
Context context = sCachedView != null ? sCachedView.getContext() : null;
|
// Context context = sCachedView != null ? sCachedView.getContext() : null;
|
||||||
LogUtils.d(TAG, String.format("getContextFromCache 调用 | 从缓存获取上下文=%s", context));
|
// LogUtils.d(TAG, String.format("getContextFromCache 调用 | 从缓存获取上下文=%s", context));
|
||||||
return context;
|
// return context;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// ====================================== 重写父类方法:增强日志+SP持久化(强制保持版) ======================================
|
// ====================================== 重写父类方法:增强日志+SP持久化(强制保持版) ======================================
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user