From 2f7f6b62fda594941c6580ee8d636cc05f6a4ef8 Mon Sep 17 00:00:00 2001 From: ZhanGSKen Date: Tue, 23 Dec 2025 21:01:03 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=BA=94=E7=94=A8=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E8=83=8C=E6=99=AF=E9=A2=9C=E8=89=B2=E4=B8=BA=E7=99=BD?= =?UTF-8?q?=E8=89=B2=EF=BC=8C=E9=A2=9C=E8=89=B2=E6=B8=85=E7=90=86=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E7=82=B9=E5=87=BB=E5=90=8E=EF=BC=8C=E8=83=8C=E6=99=AF?= =?UTF-8?q?=E9=A2=9C=E8=89=B2=E6=94=B9=E4=B8=BA=E4=B8=BB=E9=A2=98=E9=A3=8E?= =?UTF-8?q?=E6=A0=BC=E7=9A=84=E5=9F=BA=E5=87=86=E8=89=B2=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- powerbell/build.properties | 4 +- .../java/cc/winboll/studio/powerbell/App.java | 3 - .../studio/powerbell/MainActivity.java | 1 - .../BackgroundSettingsActivity.java | 3 +- .../powerbell/models/BackgroundBean.java | 2 +- .../unittest/MainUnitTest2Activity.java | 2 + .../unittest/MainUnitTestActivity.java | 2 + .../utils/BackgroundSourceUtils.java | 4 ++ .../studio/powerbell/utils/ImageUtils.java | 55 ++++++++++++++++--- 9 files changed, 61 insertions(+), 15 deletions(-) diff --git a/powerbell/build.properties b/powerbell/build.properties index cbdc156..bae89b9 100644 --- a/powerbell/build.properties +++ b/powerbell/build.properties @@ -1,8 +1,8 @@ #Created by .winboll/winboll_app_build.gradle -#Tue Dec 23 19:45:28 HKT 2025 +#Tue Dec 23 12:56:20 GMT 2025 stageCount=27 libraryProject= baseVersion=15.14 publishVersion=15.14.26 -buildCount=0 +buildCount=17 baseBetaVersion=15.14.27 diff --git a/powerbell/src/main/java/cc/winboll/studio/powerbell/App.java b/powerbell/src/main/java/cc/winboll/studio/powerbell/App.java index 97ca721..59e1768 100644 --- a/powerbell/src/main/java/cc/winboll/studio/powerbell/App.java +++ b/powerbell/src/main/java/cc/winboll/studio/powerbell/App.java @@ -1,8 +1,6 @@ package cc.winboll.studio.powerbell; import android.content.Context; -import android.os.Build; -import android.os.Environment; import cc.winboll.studio.libaes.utils.WinBoLLActivityManager; import cc.winboll.studio.libappbase.GlobalApplication; import cc.winboll.studio.libappbase.LogUtils; @@ -13,7 +11,6 @@ import cc.winboll.studio.powerbell.utils.AppConfigUtils; import cc.winboll.studio.powerbell.utils.BitmapCacheUtils; import cc.winboll.studio.powerbell.utils.NotificationManagerUtils; import cc.winboll.studio.powerbell.views.MemoryCachedBackgroundView; -import java.io.File; /** * 应用全局入口类(适配Android API 30,基于Java 7编写) diff --git a/powerbell/src/main/java/cc/winboll/studio/powerbell/MainActivity.java b/powerbell/src/main/java/cc/winboll/studio/powerbell/MainActivity.java index 59c1b84..d2d62e2 100644 --- a/powerbell/src/main/java/cc/winboll/studio/powerbell/MainActivity.java +++ b/powerbell/src/main/java/cc/winboll/studio/powerbell/MainActivity.java @@ -12,7 +12,6 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewStub; -import android.widget.LinearLayout; import androidx.appcompat.widget.Toolbar; import cc.winboll.studio.libaes.activitys.AboutActivity; import cc.winboll.studio.libaes.models.APPInfo; diff --git a/powerbell/src/main/java/cc/winboll/studio/powerbell/activities/BackgroundSettingsActivity.java b/powerbell/src/main/java/cc/winboll/studio/powerbell/activities/BackgroundSettingsActivity.java index 5113c7e..d2423b4 100644 --- a/powerbell/src/main/java/cc/winboll/studio/powerbell/activities/BackgroundSettingsActivity.java +++ b/powerbell/src/main/java/cc/winboll/studio/powerbell/activities/BackgroundSettingsActivity.java @@ -33,6 +33,7 @@ import cc.winboll.studio.powerbell.utils.BackgroundSourceUtils; import cc.winboll.studio.powerbell.utils.BitmapCacheUtils; import cc.winboll.studio.powerbell.utils.FileUtils; import cc.winboll.studio.powerbell.utils.ImageCropUtils; +import cc.winboll.studio.powerbell.utils.ImageUtils; import cc.winboll.studio.powerbell.utils.UriUtils; import cc.winboll.studio.powerbell.views.BackgroundView; import java.io.File; @@ -317,7 +318,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity { return; } int oldColor = previewBean.getPixelColor(); - previewBean.setPixelColor(0xFF000000); + previewBean.setPixelColor(ImageUtils.getColorAccent(BackgroundSettingsActivity.this)); mBgSourceUtils.saveSettings(); doubleRefreshPreview(); isPreviewBackgroundChanged = true; diff --git a/powerbell/src/main/java/cc/winboll/studio/powerbell/models/BackgroundBean.java b/powerbell/src/main/java/cc/winboll/studio/powerbell/models/BackgroundBean.java index 630b148..1b056c2 100644 --- a/powerbell/src/main/java/cc/winboll/studio/powerbell/models/BackgroundBean.java +++ b/powerbell/src/main/java/cc/winboll/studio/powerbell/models/BackgroundBean.java @@ -39,7 +39,7 @@ public class BackgroundBean extends BaseBean implements Serializable { private int backgroundWidth = DEFAULT_DIMENSION; // 背景图宽度 private int backgroundHeight = DEFAULT_DIMENSION; // 背景图高度 // 像素颜色 - private int pixelColor = 0; // 拾取的像素颜色(纯色背景用) + private int pixelColor = 0xFFFFFFFF; // 拾取的像素颜色(纯色背景用) // ====================== 构造方法(无参构造,JSON反序列化必备) ====================== /** diff --git a/powerbell/src/main/java/cc/winboll/studio/powerbell/unittest/MainUnitTest2Activity.java b/powerbell/src/main/java/cc/winboll/studio/powerbell/unittest/MainUnitTest2Activity.java index 131d5c7..030f7b2 100644 --- a/powerbell/src/main/java/cc/winboll/studio/powerbell/unittest/MainUnitTest2Activity.java +++ b/powerbell/src/main/java/cc/winboll/studio/powerbell/unittest/MainUnitTest2Activity.java @@ -16,6 +16,7 @@ import cc.winboll.studio.powerbell.R; import cc.winboll.studio.powerbell.models.BackgroundBean; import cc.winboll.studio.powerbell.utils.FileUtils; import cc.winboll.studio.powerbell.utils.ImageCropUtils; +import cc.winboll.studio.powerbell.utils.ImageUtils; import cc.winboll.studio.powerbell.views.MemoryCachedBackgroundView; import java.io.File; import java.io.IOException; @@ -141,6 +142,7 @@ public class MainUnitTest2Activity extends AppCompatActivity { private void initBackgroundBean() { LogUtils.d(TAG, "initBackgroundBean:初始化背景Bean"); mPreviewBackgroundBean = new BackgroundBean(); + mPreviewBackgroundBean.setPixelColor(ImageUtils.getColorAccent(this)); mPreviewBackgroundBean.setBackgroundFileName(mPrivateTestImageFile.getName()); mPreviewBackgroundBean.setBackgroundFilePath(mPrivateTestImageFile.getAbsolutePath()); mPreviewBackgroundBean.setBackgroundScaledCompressFileName(mPrivateCropImageFile.getName()); diff --git a/powerbell/src/main/java/cc/winboll/studio/powerbell/unittest/MainUnitTestActivity.java b/powerbell/src/main/java/cc/winboll/studio/powerbell/unittest/MainUnitTestActivity.java index fcefa9a..f32e10e 100644 --- a/powerbell/src/main/java/cc/winboll/studio/powerbell/unittest/MainUnitTestActivity.java +++ b/powerbell/src/main/java/cc/winboll/studio/powerbell/unittest/MainUnitTestActivity.java @@ -15,6 +15,7 @@ import cc.winboll.studio.powerbell.R; import cc.winboll.studio.powerbell.models.BackgroundBean; import cc.winboll.studio.powerbell.utils.FileUtils; import cc.winboll.studio.powerbell.utils.ImageCropUtils; +import cc.winboll.studio.powerbell.utils.ImageUtils; import cc.winboll.studio.powerbell.views.BackgroundView; import java.io.File; import java.io.IOException; @@ -134,6 +135,7 @@ public class MainUnitTestActivity extends AppCompatActivity { private void initBackgroundBean() { LogUtils.d(TAG, "initBackgroundBean:初始化背景Bean"); mPreviewBackgroundBean = new BackgroundBean(); + mPreviewBackgroundBean.setPixelColor(ImageUtils.getColorAccent(this)); mPreviewBackgroundBean.setBackgroundFileName(mPrivateTestImageFile.getName()); mPreviewBackgroundBean.setBackgroundFilePath(mPrivateTestImageFile.getAbsolutePath()); mPreviewBackgroundBean.setBackgroundScaledCompressFileName(mPrivateCropImageFile.getName()); diff --git a/powerbell/src/main/java/cc/winboll/studio/powerbell/utils/BackgroundSourceUtils.java b/powerbell/src/main/java/cc/winboll/studio/powerbell/utils/BackgroundSourceUtils.java index cac7353..93b03d9 100644 --- a/powerbell/src/main/java/cc/winboll/studio/powerbell/utils/BackgroundSourceUtils.java +++ b/powerbell/src/main/java/cc/winboll/studio/powerbell/utils/BackgroundSourceUtils.java @@ -156,6 +156,7 @@ public class BackgroundSourceUtils { currentBackgroundBean = BackgroundBean.loadBeanFromFile(currentBackgroundBeanFile.getAbsolutePath(), BackgroundBean.class); if (currentBackgroundBean == null) { currentBackgroundBean = new BackgroundBean(); + currentBackgroundBean.setPixelColor(ImageUtils.getColorAccent(mContext)); BackgroundBean.saveBeanToFile(currentBackgroundBeanFile.getAbsolutePath(), currentBackgroundBean); LogUtils.d(TAG, "【配置加载】正式背景Bean不存在,已创建新实例"); } @@ -163,6 +164,7 @@ public class BackgroundSourceUtils { previewBackgroundBean = BackgroundBean.loadBeanFromFile(previewBackgroundBeanFile.getAbsolutePath(), BackgroundBean.class); if (previewBackgroundBean == null) { previewBackgroundBean = new BackgroundBean(); + previewBackgroundBean.setPixelColor(ImageUtils.getColorAccent(mContext)); BackgroundBean.saveBeanToFile(previewBackgroundBeanFile.getAbsolutePath(), previewBackgroundBean); LogUtils.d(TAG, "【配置加载】预览背景Bean不存在,已创建新实例"); } @@ -542,6 +544,7 @@ public class BackgroundSourceUtils { LogUtils.d(TAG, "【背景提交】开始深拷贝预览Bean到正式Bean"); // 深拷贝Bean属性 currentBackgroundBean = new BackgroundBean(); + currentBackgroundBean.setPixelColor(ImageUtils.getColorAccent(mContext)); copyBackgroundBeanProperties(previewBackgroundBean, currentBackgroundBean); // 复制文件 @@ -570,6 +573,7 @@ public class BackgroundSourceUtils { LogUtils.d(TAG, "【背景同步】开始深拷贝正式Bean到预览Bean"); // 深拷贝Bean属性 previewBackgroundBean = new BackgroundBean(); + previewBackgroundBean.setPixelColor(ImageUtils.getColorAccent(mContext)); copyBackgroundBeanProperties(currentBackgroundBean, previewBackgroundBean); saveSettings(); diff --git a/powerbell/src/main/java/cc/winboll/studio/powerbell/utils/ImageUtils.java b/powerbell/src/main/java/cc/winboll/studio/powerbell/utils/ImageUtils.java index 229653d..5230434 100644 --- a/powerbell/src/main/java/cc/winboll/studio/powerbell/utils/ImageUtils.java +++ b/powerbell/src/main/java/cc/winboll/studio/powerbell/utils/ImageUtils.java @@ -1,9 +1,12 @@ package cc.winboll.studio.powerbell.utils; import android.content.Context; +import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.graphics.Color; import cc.winboll.studio.libappbase.LogUtils; +import cc.winboll.studio.powerbell.R; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -12,9 +15,10 @@ import java.io.OutputStream; /** * 图片处理工具类(质量压缩专用) - * 功能:对图片进行JPEG质量压缩,并将压缩结果覆盖源文件 + * 功能:对图片进行JPEG质量压缩,并将压缩结果覆盖源文件;获取主题colorPrimary颜色值 * 适配:Java 7 + Android API 30 - * 核心逻辑:Bitmap.compress 质量压缩 + FileChannel 高效文件复制 + * 核心逻辑:Bitmap.compress 质量压缩 + FileChannel 高效文件复制;主题属性解析 + * @Author 豆包&ZhanGSKen */ public class ImageUtils { // ================================== 静态常量区(置顶归类,消除魔法值)================================= @@ -22,6 +26,39 @@ public class ImageUtils { private static final Bitmap.CompressFormat COMPRESS_FORMAT = Bitmap.CompressFormat.JPEG; private static final int MIN_COMPRESS_QUALITY = 0; private static final int MAX_COMPRESS_QUALITY = 100; + private static final int[] COLOR_ACCENT_ATTR = new int[]{R.attr.colorAccent}; // colorPrimary属性数组 + + // ================================== 新增:Accent 颜色获取方法 ================================= + /** + * 从当前应用主题中获取 colorAccent 颜色值 + * @param context 上下文,用于获取主题与资源 + * @return 解析到的 colorAccent 颜色值,解析失败返回默认白色#FFFFFFFF + */ + public static int getColorAccent(Context context) { + LogUtils.d(TAG, "【getColorAccent】方法调用"); + if (context == null) { + LogUtils.e(TAG, "【getColorAccent】参数异常:Context为空,返回默认颜色"); + return Color.parseColor("#FFFFFFFF"); + } + + TypedArray typedArray = null; + try { + // 从当前主题中解析 colorAccent 属性 + typedArray = context.obtainStyledAttributes(COLOR_ACCENT_ATTR); + int colorAccent = typedArray.getColor(0, Color.parseColor("#FFFFFFFF")); + LogUtils.d(TAG, String.format("【getColorAccent】解析成功 | colorAccent=0x%08X", colorAccent)); + return colorAccent; + } catch (Exception e) { + LogUtils.e(TAG, "【getColorAccent】解析失败,返回默认颜色", e); + return Color.parseColor("#FFFFFFFF"); + } finally { + // 回收TypedArray资源,避免内存泄漏 + if (typedArray != null) { + typedArray.recycle(); + LogUtils.d(TAG, "【getColorAccent】TypedArray资源已回收"); + } + } + } // ================================== 核心工具方法(图片质量压缩)================================= /** @@ -32,7 +69,8 @@ public class ImageUtils { * @param compressQuality 压缩质量(0-100,数值越小压缩率越高) */ public static void bitmapCompress(Context context, String srcImagePath, String dstImagePath, int compressQuality) { - LogUtils.d(TAG, "【bitmapCompress】调用开始 | 源路径=" + srcImagePath + " | 临时路径=" + dstImagePath + " | 压缩质量=" + compressQuality); + LogUtils.d(TAG, String.format("【bitmapCompress】调用开始 | 源路径=%s | 临时路径=%s | 压缩质量=%d", + srcImagePath, dstImagePath, compressQuality)); // 1. 前置参数校验 if (srcImagePath == null || srcImagePath.isEmpty()) { LogUtils.e(TAG, "【bitmapCompress】参数异常:源文件路径为空"); @@ -43,7 +81,7 @@ public class ImageUtils { return; } if (compressQuality < MIN_COMPRESS_QUALITY || compressQuality > MAX_COMPRESS_QUALITY) { - LogUtils.e(TAG, "【bitmapCompress】参数异常:压缩质量超出范围(0-100),当前值=" + compressQuality); + LogUtils.e(TAG, String.format("【bitmapCompress】参数异常:压缩质量超出范围(0-100),当前值=%d", compressQuality)); return; } @@ -62,14 +100,16 @@ public class ImageUtils { LogUtils.e(TAG, "【bitmapCompress】Bitmap解码失败:无法读取源图片 " + srcImagePath); return; } - LogUtils.d(TAG, "【bitmapCompress】Bitmap解码成功 | 尺寸=" + compressBitmap.getWidth() + "x" + compressBitmap.getHeight()); + LogUtils.d(TAG, String.format("【bitmapCompress】Bitmap解码成功 | 尺寸=%dx%d", + compressBitmap.getWidth(), compressBitmap.getHeight())); // 3. 创建临时压缩文件 File dstFile = new File(dstImagePath); File dstParentDir = dstFile.getParentFile(); if (dstParentDir != null && !dstParentDir.exists()) { boolean isDirCreated = dstParentDir.mkdirs(); - LogUtils.d(TAG, "【bitmapCompress】临时目录创建" + (isDirCreated ? "成功" : "失败") + ":" + dstParentDir.getAbsolutePath()); + LogUtils.d(TAG, String.format("【bitmapCompress】临时目录创建%s:%s", + isDirCreated ? "成功" : "失败", dstParentDir.getAbsolutePath())); } // 4. 写入压缩数据 @@ -83,7 +123,8 @@ public class ImageUtils { // 5. 复制压缩文件覆盖源文件 FileUtils.copyFileUsingFileChannels(dstFile, srcFile); - LogUtils.d(TAG, "【bitmapCompress】" + compressQuality + "%压缩结束:已覆盖源文件 " + srcImagePath); + LogUtils.d(TAG, String.format("【bitmapCompress】%d%%压缩结束:已覆盖源文件 %s", + compressQuality, srcImagePath)); } catch (FileNotFoundException e) { LogUtils.e(TAG, "【bitmapCompress】文件未找到异常", e);