@@ -40,6 +40,9 @@ public class App extends GlobalApplication {
private static final int INVALID_BATTERY_VALUE = - 1 ;
// ===================== 静态属性区(按工具类优先级排序) =====================
// 应用单例
private static App sApp ;
// 数据配置工具
public static AppConfigUtils sAppConfigUtils ;
private static AppCacheUtils sAppCacheUtils ;
@@ -49,25 +52,32 @@ public class App extends GlobalApplication {
public static BitmapCacheUtils sBitmapCacheUtils ;
// 全局视图控件缓存工具(极致强制保持:一旦初始化,永不销毁)
// 核心修改:改为私有静态,通过实例方法获取,避免全局通用暴露
private static MemoryCachedBackgroundView sMemoryCachedBackgroundView ;
// 电池状态
public static volatile int sQuantityOfElectricity = INVALID_BATTERY_VALUE ;
// 通知管理工具
private static NotificationManagerUtils sNotificationManagerUtils ;
// ===================== 成员属性区(按生命周期关联度排序) =====================
// 全局广播接收器
private GlobalApplicationReceiver mGlobalReceiver ;
// 通知管理工具
private static NotificationManagerUtils sNotificationManagerUtils ;
private static App sApp ;
// ===================== 公共静态方法区(工具类实例获取/单例) =====================
/**
* 获取应用单例实例
*/
public static App getInstance ( ) {
return sApp ;
}
// ===================== 公共静态方法区(工具类实例获取) =====================
/**
* 获取应用配置工具实例
*/
public static AppConfigUtils getAppConfigUtils ( Context context ) {
LogUtils . d ( TAG , String . format ( " getAppConfigUtils() 调用 | 传入Context类型=%s " ,
context ! = null ? context . getClass ( ) . getSimpleName ( ) : " null " ) ) ;
context ! = null ? context . getClass ( ) . getSimpleName ( ) : " null " ) ) ;
if ( sAppConfigUtils = = null ) {
sAppConfigUtils = AppConfigUtils . getInstance ( context ) ;
LogUtils . d ( TAG , " getAppConfigUtils(): AppConfigUtils实例已初始化 " ) ;
@@ -80,7 +90,7 @@ public class App extends GlobalApplication {
*/
public static AppCacheUtils getAppCacheUtils ( Context context ) {
LogUtils . d ( TAG , String . format ( " getAppCacheUtils() 调用 | 传入Context类型=%s " ,
context ! = null ? context . getClass ( ) . getSimpleName ( ) : " null " ) ) ;
context ! = null ? context . getClass ( ) . getSimpleName ( ) : " null " ) ) ;
if ( sAppCacheUtils = = null ) {
sAppCacheUtils = AppCacheUtils . getInstance ( context ) ;
LogUtils . d ( TAG , " getAppCacheUtils(): AppCacheUtils实例已初始化 " ) ;
@@ -88,13 +98,6 @@ public class App extends GlobalApplication {
return sAppCacheUtils ;
}
/**
* 获取应用单例实例
*/
public static App getInstance ( ) {
return sApp ;
}
// ===================== 公共成员方法区(业务功能) =====================
/**
* 清除电池历史数据
@@ -139,12 +142,26 @@ public class App extends GlobalApplication {
return sMemoryCachedBackgroundView ;
}
/**
* 发送调试通知
*/
public static void notifyMessage ( String title , String content ) {
LogUtils . d ( TAG , String . format ( " notifyMessage() 调用 | title=%s | content=%s " , title , content ) ) ;
if ( isDebugging ( ) & & sApp ! = null & & sNotificationManagerUtils ! = null ) {
NotificationMessage message = new NotificationMessage ( title , content , " " ) ;
sNotificationManagerUtils . showMessageNotification ( sApp , message ) ;
LogUtils . d ( TAG , " notifyMessage():调试通知发送成功 " ) ;
} else {
LogUtils . d ( TAG , " notifyMessage():调试通知发送失败(条件不满足) " ) ;
}
}
// ===================== 生命周期方法区(按执行顺序排序) =====================
@Override
public void onCreate ( ) {
super . onCreate ( ) ;
sApp = this ;
LogUtils . d ( TAG , " onCreate() 应用启动,开始初始化 " ) ;
sApp = this ;
// 初始化调试模式
setIsDebugging ( BuildConfig . DEBUG ) ;
@@ -152,7 +169,6 @@ public class App extends GlobalApplication {
// 初始化基础工具
initBaseTools ( ) ;
//App.notifyMessage(TAG, "onCreate() 应用启动中。。。");
// 初始化工具类实例(核心:极致强制缓存,永不销毁)
initUtils ( ) ;
// 初始化广播接收器
@@ -185,7 +201,7 @@ public class App extends GlobalApplication {
super . onTrimMemory ( level ) ;
// 极致强制缓存:禁止任何缓存清理操作,仅记录日志
LogUtils . w ( TAG , String . format ( " %s onTrimMemory() 调用 | 内存等级level=%d | 极致强制保持所有缓存 " ,
CACHE_PROTECT_TAG , level ) ) ;
CACHE_PROTECT_TAG , level ) ) ;
// 记录详细缓存状态,不执行任何清理
logDetailedCacheStatus ( ) ;
}
@@ -201,15 +217,14 @@ public class App extends GlobalApplication {
// ===================== 私有初始化方法区(按初始化顺序排序) =====================
/**
* 初始化基础工具( Activity管理、Toast)
* 初始化基础工具( Activity管理、Toast、通知工具 )
*/
private void initBaseTools ( ) {
LogUtils . d ( TAG , " initBaseTools() 开始初始化基础工具 " ) ;
WinBoLLActivityManager . init ( this ) ;
ToastUtils . init ( this ) ;
LogUtils . d ( TAG , " initBaseTools() 基础工具初始化完成 " ) ;
sNotificationManagerUtils = new NotificationManagerUtils ( this ) ;
LogUtils . d ( TAG , " initBaseTools() 工具类 初始化完成,极致强制缓存策略已生效 " ) ;
LogUtils . d ( TAG , " initBaseTools() 基础工具+通知 工具初始化完成,极致强制缓存策略已生效 " ) ;
}
/**
@@ -217,22 +232,31 @@ public class App extends GlobalApplication {
*/
private void initUtils ( ) {
LogUtils . d ( TAG , " initUtils() 开始初始化工具类,启用极致强制缓存策略 " ) ;
//App.notifyMessage(TAG, "initUtils() 开始初始化工具类,启用极致强制缓存策略");
// 初始化配置&缓存工具
sAppConfigUtils = getAppConfigUtils ( this ) ;
sAppCacheUtils = getAppCacheUtils ( this ) ;
// 初始化背景资源工具
sBackgroundSourceUtils = BackgroundSourceUtils . getInstance ( this ) ;
sBackgroundSourceUtils . loadSettings ( ) ;
LogUtils . d ( TAG , " initUtils() 背景资源工具已初始化 " ) ;
// 极致强制初始化Bitmap缓存工具( 必初始化, 永不销毁)
sBitmapCacheUtils = BitmapCacheUtils . getInstance ( ) ;
LogUtils . d ( TAG , " initUtils() Bitmap缓存工具已初始化( 极致强制保持, 永不销毁) " ) ;
// 极致强制初始化视图控件缓存工具(必初始化,永不销毁)
// if(sMemoryCachedBackgroundView == null) {
// App.notifyMessage(TAG, "sMemoryCachedBackgroundView == null");
// }
sMemoryCachedBackgroundView = MemoryCachedBackgroundView . getLastInstance ( this ) ;
if ( sMemoryCachedBackgroundView = = null ) {
//App.notifyMessage(TAG, "sMemoryCachedBackgroundView == null");
sMemoryCachedBackgroundView = MemoryCachedBackgroundView . getInstance ( this , sBackgroundSourceUtils . getCurrentBackgroundBean ( ) , true ) ;
LogUtils . d ( TAG , " initUtils() 视图控件缓存工具已新建实例 " ) ;
//App.notifyMessage(TAG, "没有使用缓存控件");
}
//App.notifyMessage(TAG, "initUtils() 视图控件缓存工具已初始化(极致强制保持,永不销毁)");
LogUtils . d ( TAG , " initUtils() 视图控件缓存工具已初始化(极致强制保持,永不销毁) " ) ;
}
@@ -290,7 +314,7 @@ public class App extends GlobalApplication {
LogUtils . d ( TAG , String . format ( " %s Bitmap缓存数量=%d " , CACHE_PROTECT_TAG , cacheCount ) ) ;
} catch ( Exception e ) {
LogUtils . d ( TAG , String . format ( " %s Bitmap缓存数量获取失败( 不影响缓存) | 异常信息=%s " ,
CACHE_PROTECT_TAG , e . getMessage ( ) ) ) ;
CACHE_PROTECT_TAG , e . getMessage ( ) ) ) ;
}
}
// 视图控件缓存状态
@@ -302,12 +326,5 @@ public class App extends GlobalApplication {
}
LogUtils . d ( TAG , " logDetailedCacheStatus() 详细缓存状态记录完成,所有缓存均极致强制保持 " ) ;
}
public static void notifyMessage ( String title , String content ) {
if ( isDebugging ( ) & & sApp ! = null & & sNotificationManagerUtils ! = null ) {
NotificationMessage message = new NotificationMessage ( title , content , " " ) ;
sNotificationManagerUtils . showMessageNotification ( sApp , message ) ;
}
}
}