首页启动窗口改用视图控件缓存替代位图缓存。

This commit is contained in:
2025-12-22 10:01:13 +08:00
parent 0cfbc43acb
commit 6d60d71991
6 changed files with 430 additions and 325 deletions

View File

@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle #Created by .winboll/winboll_app_build.gradle
#Mon Dec 22 00:53:45 GMT 2025 #Mon Dec 22 01:57:09 GMT 2025
stageCount=18 stageCount=18
libraryProject= libraryProject=
baseVersion=15.14 baseVersion=15.14
publishVersion=15.14.17 publishVersion=15.14.17
buildCount=7 buildCount=18
baseBetaVersion=15.14.18 baseBetaVersion=15.14.18

View File

@@ -15,6 +15,7 @@ import cc.winboll.studio.powerbell.utils.AppCacheUtils;
import cc.winboll.studio.powerbell.utils.AppConfigUtils; import cc.winboll.studio.powerbell.utils.AppConfigUtils;
import cc.winboll.studio.powerbell.utils.BitmapCacheUtils; import cc.winboll.studio.powerbell.utils.BitmapCacheUtils;
import cc.winboll.studio.powerbell.utils.NotificationManagerUtils; import cc.winboll.studio.powerbell.utils.NotificationManagerUtils;
import cc.winboll.studio.powerbell.views.MemoryCachedBackgroundView;
import java.io.File; import java.io.File;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@@ -40,7 +41,7 @@ public class App extends GlobalApplication {
private static final String TRIM_MEMORY_NOTIFY_CONTENT = "由于本应用使用时,系统通知内存紧张程度级别较高,图片缓存功能暂时不启用。"; private static final String TRIM_MEMORY_NOTIFY_CONTENT = "由于本应用使用时,系统通知内存紧张程度级别较高,图片缓存功能暂时不启用。";
// 定时任务间隔常量(分钟) // 定时任务间隔常量(分钟)
private static final long TIMER_INTERVAL_MINUTES = 1; //private static final long TIMER_INTERVAL_MINUTES = 1;
// ===================== 静态属性区 ===================== // ===================== 静态属性区 =====================
// 数据配置工具 // 数据配置工具
@@ -48,14 +49,16 @@ public class App extends GlobalApplication {
private static AppCacheUtils sAppCacheUtils; private static AppCacheUtils sAppCacheUtils;
// 全局Bitmap缓存工具 // 全局Bitmap缓存工具
public static BitmapCacheUtils sBitmapCacheUtils; public static BitmapCacheUtils sBitmapCacheUtils;
// 全局视图控件缓存工具
public static MemoryCachedBackgroundView sMemoryCachedBackgroundView;
// 临时文件夹路径 // 临时文件夹路径
private static String sTempDirPath = ""; private static String sTempDirPath = "";
// 定时任务静态属性(全局唯一) // 定时任务静态属性(全局唯一)
private static Handler sTimerHandler; // private static Handler sTimerHandler;
private static Runnable sTimerRunnable; // private static Runnable sTimerRunnable;
private static boolean sIsTimerRunning = false; // private static boolean sIsTimerRunning = false;
//
// ===================== 成员属性区 ===================== // ===================== 成员属性区 =====================
// 全局广播接收器 // 全局广播接收器
private GlobalApplicationReceiver mGlobalReceiver; private GlobalApplicationReceiver mGlobalReceiver;
@@ -121,7 +124,7 @@ public class App extends GlobalApplication {
// 初始化广播接收器 // 初始化广播接收器
initReceiver(); initReceiver();
// 启动定时任务 // 启动定时任务
initTimerTask(); //initTimerTask();
LogUtils.d(TAG, "onCreate() 应用初始化完成"); LogUtils.d(TAG, "onCreate() 应用初始化完成");
} }
@@ -136,7 +139,7 @@ public class App extends GlobalApplication {
// 释放通知工具 // 释放通知工具
releaseNotificationManager(); releaseNotificationManager();
// 停止定时任务 // 停止定时任务
stopTimerTask(); //stopTimerTask();
LogUtils.d(TAG, "onTerminate() 应用资源释放完成"); LogUtils.d(TAG, "onTerminate() 应用资源释放完成");
} }
@@ -145,20 +148,22 @@ public class App extends GlobalApplication {
public void onTrimMemory(int level) { public void onTrimMemory(int level) {
super.onTrimMemory(level); super.onTrimMemory(level);
LogUtils.d(TAG, "onTrimMemory() 调用内存等级level" + level); LogUtils.d(TAG, "onTrimMemory() 调用内存等级level" + level);
sMemoryCachedBackgroundView.clearAllCache();
// 初始化通知工具(若未初始化) sMemoryCachedBackgroundView.getLastInstance(this);
if (mNotificationManager == null) { //
mNotificationManager = new NotificationManagerUtils(this); // // 初始化通知工具(若未初始化)
LogUtils.d(TAG, "onTrimMemory()NotificationManagerUtils实例已初始化"); // if (mNotificationManager == null) {
} // mNotificationManager = new NotificationManagerUtils(this);
// LogUtils.d(TAG, "onTrimMemory()NotificationManagerUtils实例已初始化");
// 内存紧张等级判断 // }
if (level > ComponentCallbacks2.TRIM_MEMORY_MODERATE) { //
sendTrimMemoryNotification(level); // // 内存紧张等级判断
} else { // if (level > ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
sBitmapCacheUtils = BitmapCacheUtils.getInstance(); // sendTrimMemoryNotification(level);
LogUtils.d(TAG, "onTrimMemory()Bitmap缓存已启用"); // } else {
} // sBitmapCacheUtils = BitmapCacheUtils.getInstance();
// LogUtils.d(TAG, "onTrimMemory()Bitmap缓存已启用");
// }
} }
// ===================== 私有初始化方法区 ===================== // ===================== 私有初始化方法区 =====================
@@ -212,65 +217,65 @@ public class App extends GlobalApplication {
/** /**
* 初始化定时任务(全局唯一实例) * 初始化定时任务(全局唯一实例)
*/ */
private void initTimerTask() { // private void initTimerTask() {
LogUtils.d(TAG, "initTimerTask() 开始初始化定时任务,当前运行状态:" + sIsTimerRunning); // LogUtils.d(TAG, "initTimerTask() 开始初始化定时任务,当前运行状态:" + sIsTimerRunning);
//
// 已运行则直接返回 // // 已运行则直接返回
if (sIsTimerRunning) { // if (sIsTimerRunning) {
LogUtils.d(TAG, "initTimerTask() 定时任务已在运行,无需重复启动"); // LogUtils.d(TAG, "initTimerTask() 定时任务已在运行,无需重复启动");
return; // return;
} // }
//
// 初始化Handler // // 初始化Handler
if (sTimerHandler == null) { // if (sTimerHandler == null) {
sTimerHandler = new Handler(Looper.getMainLooper()); // sTimerHandler = new Handler(Looper.getMainLooper());
LogUtils.d(TAG, "initTimerTask() 定时任务Handler已初始化"); // LogUtils.d(TAG, "initTimerTask() 定时任务Handler已初始化");
} // }
//
// 初始化Runnable // // 初始化Runnable
if (sTimerRunnable == null) { // if (sTimerRunnable == null) {
sTimerRunnable = new Runnable() { // sTimerRunnable = new Runnable() {
@Override // @Override
public void run() { // public void run() {
try { // try {
LogUtils.d(TAG, "定时任务执行,间隔:" + TIMER_INTERVAL_MINUTES + "分钟"); // LogUtils.d(TAG, "定时任务执行,间隔:" + TIMER_INTERVAL_MINUTES + "分钟");
sBitmapCacheUtils = BitmapCacheUtils.getInstance(); // sBitmapCacheUtils = BitmapCacheUtils.getInstance();
LogUtils.d(TAG, "定时任务Bitmap缓存已重新初始化"); // LogUtils.d(TAG, "定时任务Bitmap缓存已重新初始化");
} catch (Exception e) { // } catch (Exception e) {
LogUtils.e(TAG, "定时任务执行异常:" + e.getMessage()); // LogUtils.e(TAG, "定时任务执行异常:" + e.getMessage());
} finally { // } finally {
if (sIsTimerRunning) { // if (sIsTimerRunning) {
long delayMillis = TimeUnit.MINUTES.toMillis(TIMER_INTERVAL_MINUTES); // long delayMillis = TimeUnit.MINUTES.toMillis(TIMER_INTERVAL_MINUTES);
sTimerHandler.postDelayed(this, delayMillis); // sTimerHandler.postDelayed(this, delayMillis);
LogUtils.d(TAG, "定时任务已预约下次执行,延迟:" + delayMillis + "ms"); // LogUtils.d(TAG, "定时任务已预约下次执行,延迟:" + delayMillis + "ms");
} // }
} // }
} // }
}; // };
LogUtils.d(TAG, "initTimerTask() 定时任务Runnable已初始化"); // LogUtils.d(TAG, "initTimerTask() 定时任务Runnable已初始化");
} // }
//
// 启动任务 // // 启动任务
sTimerHandler.post(sTimerRunnable); // sTimerHandler.post(sTimerRunnable);
sIsTimerRunning = true; // sIsTimerRunning = true;
LogUtils.d(TAG, "initTimerTask() 定时任务已启动,间隔:" + TIMER_INTERVAL_MINUTES + "分钟"); // LogUtils.d(TAG, "initTimerTask() 定时任务已启动,间隔:" + TIMER_INTERVAL_MINUTES + "分钟");
} // }
// ===================== 私有工具方法区 ===================== // ===================== 私有工具方法区 =====================
/** /**
* 停止定时任务 * 停止定时任务
*/ */
private void stopTimerTask() { // private void stopTimerTask() {
LogUtils.d(TAG, "stopTimerTask() 开始停止定时任务"); // LogUtils.d(TAG, "stopTimerTask() 开始停止定时任务");
if (sTimerHandler != null && sTimerRunnable != null) { // if (sTimerHandler != null && sTimerRunnable != null) {
sTimerHandler.removeCallbacks(sTimerRunnable); // sTimerHandler.removeCallbacks(sTimerRunnable);
sIsTimerRunning = false; // sIsTimerRunning = false;
LogUtils.d(TAG, "stopTimerTask() 定时任务已停止运行状态重置为false"); // LogUtils.d(TAG, "stopTimerTask() 定时任务已停止运行状态重置为false");
} else { // } else {
LogUtils.d(TAG, "stopTimerTask() 定时任务未初始化,无需停止"); // LogUtils.d(TAG, "stopTimerTask() 定时任务未初始化,无需停止");
} // }
} // }
//
/** /**
* 释放通知管理工具资源 * 释放通知管理工具资源
*/ */

View File

@@ -12,6 +12,7 @@ import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewStub; import android.view.ViewStub;
import android.widget.LinearLayout;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import cc.winboll.studio.libaes.activitys.AboutActivity; import cc.winboll.studio.libaes.activitys.AboutActivity;
import cc.winboll.studio.libaes.models.APPInfo; import cc.winboll.studio.libaes.models.APPInfo;

View File

@@ -7,6 +7,7 @@ import android.content.DialogInterface;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
@@ -14,6 +15,7 @@ import android.widget.RelativeLayout;
import android.widget.Switch; import android.widget.Switch;
import android.widget.TextView; import android.widget.TextView;
import cc.winboll.studio.libappbase.LogUtils; import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.powerbell.App;
import cc.winboll.studio.powerbell.R; import cc.winboll.studio.powerbell.R;
import cc.winboll.studio.powerbell.models.ControlCenterServiceBean; import cc.winboll.studio.powerbell.models.ControlCenterServiceBean;
import cc.winboll.studio.powerbell.services.ControlCenterService; import cc.winboll.studio.powerbell.services.ControlCenterService;
@@ -81,7 +83,8 @@ public class MainContentView {
// 视图控件(按「布局→开关→文本→进度条→图标」功能归类) // 视图控件(按「布局→开关→文本→进度条→图标」功能归类)
// 基础布局控件 // 基础布局控件
public RelativeLayout mainLayout; public RelativeLayout mainLayout;
public BackgroundView backgroundView; public MemoryCachedBackgroundView backgroundView;
LinearLayout mllBackgroundView;
// 容器布局控件 // 容器布局控件
public LinearLayout llLeftSeekBar; public LinearLayout llLeftSeekBar;
public LinearLayout llRightSeekBar; public LinearLayout llRightSeekBar;
@@ -144,7 +147,13 @@ public class MainContentView {
LogUtils.d(TAG, "bindViews() | rootView=" + rootView); LogUtils.d(TAG, "bindViews() | rootView=" + rootView);
// 基础布局绑定 // 基础布局绑定
mainLayout = (RelativeLayout) rootView.findViewById(R.id.activitymainRelativeLayout1); mainLayout = (RelativeLayout) rootView.findViewById(R.id.activitymainRelativeLayout1);
backgroundView = (BackgroundView) rootView.findViewById(R.id.fragmentmainviewBackgroundView1); //backgroundView = (BackgroundView) rootView.findViewById(R.id.fragmentmainviewBackgroundView1);
mllBackgroundView = (LinearLayout) rootView.findViewById(R.id.ll_backgroundview);
backgroundView = App.sMemoryCachedBackgroundView.getLastInstance(mContext);
if (backgroundView.getParent() != null) {
((ViewGroup) backgroundView.getParent()).removeView(backgroundView);
}
mllBackgroundView.addView(backgroundView);
// 容器布局绑定 // 容器布局绑定
llLeftSeekBar = (LinearLayout) rootView.findViewById(R.id.fragmentmainviewLinearLayout1); llLeftSeekBar = (LinearLayout) rootView.findViewById(R.id.fragmentmainviewLinearLayout1);
llRightSeekBar = (LinearLayout) rootView.findViewById(R.id.fragmentmainviewLinearLayout2); llRightSeekBar = (LinearLayout) rootView.findViewById(R.id.fragmentmainviewLinearLayout2);

View File

@@ -1,23 +1,27 @@
package cc.winboll.studio.powerbell.views; package cc.winboll.studio.powerbell.views;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.AttributeSet; import android.util.AttributeSet;
import cc.winboll.studio.libappbase.LogUtils; import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.powerbell.models.BackgroundBean; import cc.winboll.studio.powerbell.models.BackgroundBean;
import java.util.HashMap;
import java.util.Map;
/** /**
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com> * @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
* @Date 2025/12/21 20:43 * @Date 2025/12/21 20:43
* @Describe 内存缓存版背景视图控件基于Java7 * @Describe 单实例缓存版背景视图控件基于Java7
* 核心:通过静态Map缓存控件实例按图片路径唯一标识,支持强制重载图片 * 核心:通过静态属性保存当前缓存路径和实例,支持强制重载图片
* 新增SP持久化最后加载路径、获取最后加载实例功能
*/ */
public class MemoryCachedBackgroundView extends BackgroundView { public class MemoryCachedBackgroundView extends BackgroundView {
public static final String TAG = "MemoryCachedBackgroundView"; public static final String TAG = "MemoryCachedBackgroundView";
// 静态Map缓存<图片路径, 控件实例>,全局唯一 // 静态属性保存当前缓存的路径和实例替代原Map仅维护单实例
private static final Map<String, MemoryCachedBackgroundView> sViewCacheMap = new HashMap<String, MemoryCachedBackgroundView>(); private static String sCachedImagePath;
private static MemoryCachedBackgroundView sCachedView;
// SP相关常量
private static final String SP_NAME = "MemoryCachedBackgroundView_SP";
private static final String KEY_LAST_LOAD_IMAGE_PATH = "last_load_image_path";
// ====================================== 构造器(继承并兼容父类) ====================================== // ====================================== 构造器(继承并兼容父类) ======================================
private MemoryCachedBackgroundView(Context context) { private MemoryCachedBackgroundView(Context context) {
@@ -39,7 +43,7 @@ public class MemoryCachedBackgroundView extends BackgroundView {
/** /**
* 从缓存获取或创建MemoryCachedBackgroundView实例 * 从缓存获取或创建MemoryCachedBackgroundView实例
* @param context 上下文 * @param context 上下文
* @param imagePath 图片绝对路径(作为缓存Key * @param imagePath 图片绝对路径(作为缓存标识
* @param isReload 是否强制重新加载图片(路径匹配时仍刷新) * @param isReload 是否强制重新加载图片(路径匹配时仍刷新)
* @return 缓存/新创建的MemoryCachedBackgroundView实例 * @return 缓存/新创建的MemoryCachedBackgroundView实例
*/ */
@@ -50,30 +54,99 @@ public class MemoryCachedBackgroundView extends BackgroundView {
return new MemoryCachedBackgroundView(context); return new MemoryCachedBackgroundView(context);
} }
// 1. 从Map缓存中获取实例 // 1. 路径匹配缓存 → 判断是否强制重载
MemoryCachedBackgroundView cachedView = sViewCacheMap.get(imagePath); if (imagePath.equals(sCachedImagePath) && sCachedView != null) {
// 2. 缓存不存在 → 新建实例并加入Map LogUtils.d(TAG, "getInstance():路径已缓存,当前缓存实例有效");
if (cachedView == null) {
LogUtils.d(TAG, "getInstance():路径未缓存,新建实例 | " + imagePath);
cachedView = new MemoryCachedBackgroundView(context);
sViewCacheMap.put(imagePath, cachedView);
// 新建实例直接加载图片
cachedView.loadImage(imagePath);
} else {
// 3. 缓存存在 → 根据isReload判断是否强制重载
if (isReload) { if (isReload) {
LogUtils.d(TAG, "getInstance()路径已缓存,强制重载图片 | " + imagePath); LogUtils.d(TAG, "getInstance():强制重载图片 | " + imagePath);
cachedView.loadImage(imagePath); // 调用父类loadImage刷新 sCachedView.loadImage(imagePath);
} else { } else {
LogUtils.d(TAG, "getInstance():使用缓存实例,无需重载 | " + imagePath); LogUtils.d(TAG, "getInstance():使用缓存实例,无需重载 | " + imagePath);
} }
return sCachedView;
} }
return cachedView;
// 2. 路径不匹配/无缓存 → 新建实例并更新静态缓存
LogUtils.d(TAG, "getInstance():路径未缓存,新建实例 | " + imagePath);
sCachedView = new MemoryCachedBackgroundView(context);
sCachedImagePath = imagePath;
sCachedView.loadImage(imagePath);
return sCachedView;
}
// ====================================== 新增功能:获取最后加载的实例 ======================================
/**
* 获取最后一次loadImage的路径对应的实例
* 无实例则创建并加载图片,同时更新静态缓存
* @param context 上下文
* @return 最后加载路径对应的实例
*/
public static MemoryCachedBackgroundView getLastInstance(Context context) {
LogUtils.d(TAG, "getLastInstance() 调用");
// 1. 从SP获取最后加载的路径
String lastPath = getLastLoadImagePath(context);
if (TextUtils.isEmpty(lastPath)) {
LogUtils.e(TAG, "getLastInstance():无最后加载路径,创建空实例");
return new MemoryCachedBackgroundView(context);
}
// 2. 路径匹配当前缓存 → 直接返回
if (lastPath.equals(sCachedImagePath) && sCachedView != null) {
LogUtils.d(TAG, "getLastInstance():使用最后路径缓存实例 | " + lastPath);
return sCachedView;
}
// 3. 路径不匹配 → 新建实例并更新缓存
LogUtils.d(TAG, "getLastInstance():最后路径未缓存,新建实例并加载 | " + lastPath);
sCachedView = new MemoryCachedBackgroundView(context);
sCachedImagePath = lastPath;
sCachedView.loadImage(lastPath);
return sCachedView;
}
// ====================================== 工具方法SP持久化最后加载路径 ======================================
/**
* 保存最后一次loadImage的路径到SP
* @param context 上下文
* @param imagePath 图片路径
*/
private static void saveLastLoadImagePath(Context context, String imagePath) {
if (TextUtils.isEmpty(imagePath) || context == null) {
return;
}
SharedPreferences sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
sp.edit().putString(KEY_LAST_LOAD_IMAGE_PATH, imagePath).apply();
LogUtils.d(TAG, "saveLastLoadImagePath():已保存最后路径 | " + imagePath);
}
/**
* 从SP获取最后一次loadImage的路径
* @param context 上下文
* @return 最后加载的图片路径空则返回null
*/
public static String getLastLoadImagePath(Context context) {
if (context == null) {
return null;
}
SharedPreferences sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
String lastPath = sp.getString(KEY_LAST_LOAD_IMAGE_PATH, null);
LogUtils.d(TAG, "getLastLoadImagePath():获取最后路径 | " + lastPath);
return lastPath;
} }
// ====================================== 工具方法:缓存管理 ====================================== // ====================================== 工具方法:缓存管理 ======================================
/** /**
* 清除指定路径的缓存实例 * 清除当前缓存实例和路径
*/
public static void clearCache() {
LogUtils.d(TAG, "clearCache() 调用 | 当前缓存路径:" + sCachedImagePath);
sCachedView = null;
sCachedImagePath = null;
LogUtils.d(TAG, "clearCache():已清除当前缓存实例");
}
/**
* 清除指定路径的缓存(仅当路径匹配当前缓存时生效)
* @param imagePath 图片路径 * @param imagePath 图片路径
*/ */
public static void removeCache(String imagePath) { public static void removeCache(String imagePath) {
@@ -82,34 +155,63 @@ public class MemoryCachedBackgroundView extends BackgroundView {
LogUtils.e(TAG, "removeCache():图片路径为空,清除失败"); LogUtils.e(TAG, "removeCache():图片路径为空,清除失败");
return; return;
} }
sViewCacheMap.remove(imagePath); if (imagePath.equals(sCachedImagePath)) {
LogUtils.d(TAG, "removeCache():已清除缓存 | " + imagePath); clearCache();
// 同步删除SP中最后路径记录
clearLastLoadImagePath(getContextFromCache());
LogUtils.d(TAG, "removeCache():已清除匹配路径的缓存 | " + imagePath);
} else {
LogUtils.d(TAG, "removeCache():路径不匹配当前缓存,无需清除 | " + imagePath);
}
} }
/** /**
* 清除所有缓存实例 * 清除所有缓存同clearCache保持方法兼容性
*/ */
public static void clearAllCache() { public static void clearAllCache() {
LogUtils.d(TAG, "clearAllCache() 调用 | 缓存数量:" + sViewCacheMap.size()); LogUtils.d(TAG, "clearAllCache() 调用");
sViewCacheMap.clear(); clearCache();
LogUtils.d(TAG, "clearAllCache():已清除所有缓存实例"); clearLastLoadImagePath(getContextFromCache());
LogUtils.d(TAG, "clearAllCache():已清除所有缓存及最后路径记录");
} }
/** /**
* 获取当前缓存数量 * 判断是否存在缓存实例
* @return 缓存的实例数量 * @return 存在返回true否则返回false
*/ */
public static int getCacheCount() { public static boolean hasCache() {
int count = sViewCacheMap.size(); return sCachedView != null && !TextUtils.isEmpty(sCachedImagePath);
LogUtils.d(TAG, "getCacheCount() 调用 | 当前缓存数量:" + count);
return count;
} }
// ====================================== 重写父类方法:增强日志 ====================================== /**
* 清除SP中最后加载的路径记录
* @param context 上下文
*/
public static void clearLastLoadImagePath(Context context) {
if (context == null) {
return;
}
SharedPreferences sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
sp.edit().remove(KEY_LAST_LOAD_IMAGE_PATH).apply();
LogUtils.d(TAG, "clearLastLoadImagePath():已清除最后路径记录");
}
// ====================================== 辅助方法:从缓存获取上下文 ======================================
/**
* 从缓存实例中获取上下文用于无外部上下文时的SP操作
* @return 上下文实例无则返回null
*/
private static Context getContextFromCache() {
return sCachedView != null ? sCachedView.getContext() : null;
}
// ====================================== 重写父类方法:增强日志+SP持久化 ======================================
@Override @Override
public void loadImage(String imagePath) { public void loadImage(String imagePath) {
LogUtils.d(TAG, "loadImage() 重载方法调用 | 图片路径:" + imagePath); LogUtils.d(TAG, "loadImage() 重载方法调用 | 图片路径:" + imagePath);
super.loadImage(imagePath); super.loadImage(imagePath);
// 保存最后加载路径到SP
saveLastLoadImagePath(getContext(), imagePath);
} }
@Override @Override

View File

@@ -6,7 +6,6 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<!-- 顶部Toolbar首屏核心同步加载保留原有ASupportToolbar -->
<cc.winboll.studio.libaes.views.ASupportToolbar <cc.winboll.studio.libaes.views.ASupportToolbar
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height" android:layout_height="@dimen/toolbar_height"
@@ -14,31 +13,29 @@
android:gravity="center_vertical" android:gravity="center_vertical"
style="@style/DefaultAToolbar"/> style="@style/DefaultAToolbar"/>
<!-- 主内容区优化层级减少冗余RelativeLayout -->
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1.0"> android:layout_weight="1.0">
<!-- 首屏核心容器合并原冗余RelativeLayout减少层级 -->
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:id="@+id/activitymainRelativeLayout1"> android:id="@+id/activitymainRelativeLayout1">
<!-- 1. 背景视图(首屏核心,同步加载,保留原有) --> <LinearLayout
<cc.winboll.studio.powerbell.views.BackgroundView android:orientation="horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:id="@+id/fragmentmainviewBackgroundView1"/> android:id="@+id/ll_backgroundview">
</LinearLayout>
<!-- 2. 功能控件容器(首屏核心,同步加载,保留原有结构) -->
<LinearLayout <LinearLayout
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<!-- 服务总开关布局 -->
<LinearLayout <LinearLayout
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
@@ -67,7 +64,6 @@
</LinearLayout> </LinearLayout>
<!-- 电量控制核心布局SeekBar+图标) -->
<LinearLayout <LinearLayout
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
@@ -82,7 +78,6 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1.0"> android:layout_weight="1.0">
<!-- 耗电提醒布局 -->
<LinearLayout <LinearLayout
android:orientation="vertical" android:orientation="vertical"
android:layout_width="50dp" android:layout_width="50dp"
@@ -116,7 +111,6 @@
</LinearLayout> </LinearLayout>
<!-- 耗电提醒数值+图标 -->
<LinearLayout <LinearLayout
android:orientation="vertical" android:orientation="vertical"
android:layout_width="80dp" android:layout_width="80dp"
@@ -139,7 +133,6 @@
</LinearLayout> </LinearLayout>
<!-- 当前电量数值+图标 -->
<LinearLayout <LinearLayout
android:orientation="vertical" android:orientation="vertical"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@@ -163,7 +156,6 @@
</LinearLayout> </LinearLayout>
<!-- 充电提醒数值+图标 -->
<LinearLayout <LinearLayout
android:orientation="vertical" android:orientation="vertical"
android:layout_width="80dp" android:layout_width="80dp"
@@ -186,7 +178,6 @@
</LinearLayout> </LinearLayout>
<!-- 充电提醒布局 -->
<LinearLayout <LinearLayout
android:orientation="vertical" android:orientation="vertical"
android:layout_width="50dp" android:layout_width="50dp"
@@ -224,7 +215,6 @@
</LinearLayout> </LinearLayout>
<!-- Tips文本 -->
<LinearLayout <LinearLayout
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_width="match_parent"> android:layout_width="match_parent">
@@ -242,14 +232,12 @@
</LinearLayout> </LinearLayout>
<!-- 3. 广告视图关键优化→用ViewStub延迟加载替代原直接加载的ADsBannerView -->
<!-- 首次启动仅占位1px不inflate真实广告视图减少首次耗时 -->
<ViewStub <ViewStub
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/stub_ads_banner" android:id="@+id/stub_ads_banner"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout="@layout/view_ads_banner"/> <!-- 广告视图独立布局文件 --> android:layout="@layout/view_ads_banner"/>
</RelativeLayout> </RelativeLayout>