设置应用初始背景颜色为白色,颜色清理按钮点击后,背景颜色改为主题风格的基准色。

This commit is contained in:
2025-12-23 21:01:03 +08:00
parent db096e716c
commit 2f7f6b62fd
9 changed files with 61 additions and 15 deletions

View File

@@ -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

View File

@@ -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编写

View File

@@ -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;

View File

@@ -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;

View File

@@ -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反序列化必备 ======================
/**

View File

@@ -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());

View File

@@ -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());

View File

@@ -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();

View File

@@ -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<zhangsken@qq.com>
*/
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);