From e1c3c8f07245072f31a202077a4c3a9596a05104 Mon Sep 17 00:00:00 2001 From: ZhanGSKen Date: Wed, 24 Dec 2025 20:18:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=8D=E5=9B=BE=E5=A4=A7=E5=B0=8F=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E8=B0=83=E8=AF=95=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- powerbell/build.properties | 4 +- .../BackgroundSettingsActivity.java | 59 +++++++++++++++++-- .../powerbell/models/AppConfigBean.java | 6 +- .../powerbell/views/BackgroundView.java | 24 ++++---- 4 files changed, 69 insertions(+), 24 deletions(-) diff --git a/powerbell/build.properties b/powerbell/build.properties index 32c1149..199424b 100644 --- a/powerbell/build.properties +++ b/powerbell/build.properties @@ -1,8 +1,8 @@ #Created by .winboll/winboll_app_build.gradle -#Wed Dec 24 11:16:45 GMT 2025 +#Wed Dec 24 12:16:27 GMT 2025 stageCount=29 libraryProject= baseVersion=15.14 publishVersion=15.14.28 -buildCount=82 +buildCount=97 baseBetaVersion=15.14.29 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 0102a5f..6567b2f 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 @@ -15,6 +15,7 @@ import android.provider.MediaStore; import android.provider.Settings; import android.text.TextUtils; import android.view.View; +import android.view.ViewTreeObserver; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.Toolbar; @@ -102,13 +103,59 @@ public class BackgroundSettingsActivity extends WinBoLLActivity { initPreviewEnvironment(); LogUtils.d(TAG, "生命周期 onCreate 初始化完成"); } +// +// @Override +// protected void onPostCreate(Bundle savedInstanceState) { +// super.onPostCreate(savedInstanceState); +// LogUtils.d(TAG, "生命周期 onPostCreate 执行双重刷新预览"); +// +// // 初始化配置工具类并保存默认相框尺寸 +// AppConfigUtils appConfigUtils = AppConfigUtils.getInstance(this); +// appConfigUtils.loadAppConfig(); +// if (mBackgroundView.getWidth() > -1 && mBackgroundView.getHeight() > -1) { +// ToastUtils.show("mBackgroundView.getWidth() > 0 && mBackgroundView.getHeight() > 0"); +// appConfigUtils.mAppConfigBean.setDefaultFrameWidth(mBackgroundView.getWidth()); +// appConfigUtils.mAppConfigBean.setDefaultFrameHeight(mBackgroundView.getHeight()); +// appConfigUtils.saveAppConfig(); +// LogUtils.d(TAG, String.format("loadImage() 保存默认相框尺寸 | width=%d | height=%d", mBackgroundView.getWidth(), mBackgroundView.getHeight())); +// } +// LogUtils.d(TAG, String.format("mBackgroundView is %s", mBackgroundView)); +// LogUtils.d(TAG, String.format("mBackgroundView.getWidth() %d, mBackgroundView.getHeight() %d", mBackgroundView.getWidth(), mBackgroundView.getHeight())); +// doubleRefreshPreview(); +// } + + @Override + protected void onPostCreate(Bundle savedInstanceState) { + super.onPostCreate(savedInstanceState); + LogUtils.d(TAG, "生命周期 onPostCreate 执行双重刷新预览"); - @Override - protected void onPostCreate(Bundle savedInstanceState) { - super.onPostCreate(savedInstanceState); - LogUtils.d(TAG, "生命周期 onPostCreate 执行双重刷新预览"); - doubleRefreshPreview(); - } + // 监听视图布局完成事件 + mBackgroundView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + // 移除监听,避免重复回调 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + mBackgroundView.getViewTreeObserver().removeOnGlobalLayoutListener(this); + } else { + mBackgroundView.getViewTreeObserver().removeGlobalOnLayoutListener(this); + } + + // 此时已获取真实宽高 + int width = mBackgroundView.getWidth(); + int height = mBackgroundView.getHeight(); + if (width > 0 && height > 0) { + AppConfigUtils appConfigUtils = AppConfigUtils.getInstance(BackgroundSettingsActivity.this); + appConfigUtils.loadAppConfig(); + appConfigUtils.mAppConfigBean.setDefaultFrameWidth(width); + appConfigUtils.mAppConfigBean.setDefaultFrameHeight(height); + appConfigUtils.saveAppConfig(); + LogUtils.d(TAG, String.format("保存默认相框尺寸 | width=%d | height=%d", width, height)); + doubleRefreshPreview(); + } + } + }); + } + @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { diff --git a/powerbell/src/main/java/cc/winboll/studio/powerbell/models/AppConfigBean.java b/powerbell/src/main/java/cc/winboll/studio/powerbell/models/AppConfigBean.java index 0d3409c..1a0c4bc 100644 --- a/powerbell/src/main/java/cc/winboll/studio/powerbell/models/AppConfigBean.java +++ b/powerbell/src/main/java/cc/winboll/studio/powerbell/models/AppConfigBean.java @@ -28,8 +28,6 @@ public class AppConfigBean extends BaseBean implements Serializable, Parcelable private static final int BATTERY_MIN = 0; // 电量最小值 private static final int BATTERY_MAX = 100; // 电量最大值 private static final int INVALID_BATTERY = -1; // 无效电量标识 - private static final int MIN_FRAME_SIZE = 100; // 最小相框尺寸(px) - private static final int MAX_FRAME_SIZE = 2000; // 最大相框尺寸(px) private static final int DEFAULT_FRAME_WIDTH = 500; // 默认相框宽度(px) private static final int DEFAULT_FRAME_HEIGHT = 500; // 默认相框高度(px) @@ -184,7 +182,7 @@ public class AppConfigBean extends BaseBean implements Serializable, Parcelable * @param defaultFrameWidth 相框宽度(px,范围 MIN_FRAME_SIZE - MAX_FRAME_SIZE) */ public void setDefaultFrameWidth(int defaultFrameWidth) { - this.defaultFrameWidth = Math.min(Math.max(defaultFrameWidth, MIN_FRAME_SIZE), MAX_FRAME_SIZE); + this.defaultFrameWidth = defaultFrameWidth; LogUtils.d(TAG, String.format("setDefaultFrameWidth: 默认相框宽度设置为 %dpx(输入值:%d)", this.defaultFrameWidth, defaultFrameWidth)); } @@ -198,7 +196,7 @@ public class AppConfigBean extends BaseBean implements Serializable, Parcelable * @param defaultFrameHeight 相框高度(px,范围 MIN_FRAME_SIZE - MAX_FRAME_SIZE) */ public void setDefaultFrameHeight(int defaultFrameHeight) { - this.defaultFrameHeight = Math.min(Math.max(defaultFrameHeight, MIN_FRAME_SIZE), MAX_FRAME_SIZE); + this.defaultFrameHeight = defaultFrameHeight; LogUtils.d(TAG, String.format("setDefaultFrameHeight: 默认相框高度设置为 %dpx(输入值:%d)", this.defaultFrameHeight, defaultFrameHeight)); } diff --git a/powerbell/src/main/java/cc/winboll/studio/powerbell/views/BackgroundView.java b/powerbell/src/main/java/cc/winboll/studio/powerbell/views/BackgroundView.java index ade1f4c..0375be7 100644 --- a/powerbell/src/main/java/cc/winboll/studio/powerbell/views/BackgroundView.java +++ b/powerbell/src/main/java/cc/winboll/studio/powerbell/views/BackgroundView.java @@ -161,13 +161,9 @@ public class BackgroundView extends RelativeLayout { // 初始化配置工具类并保存默认相框尺寸 AppConfigUtils appConfigUtils = AppConfigUtils.getInstance(mContext); appConfigUtils.loadAppConfig(); - if (getWidth() > 0 && getHeight() > 0) { - appConfigUtils.mAppConfigBean.setDefaultFrameWidth(getWidth()); - appConfigUtils.mAppConfigBean.setDefaultFrameHeight(getHeight()); - appConfigUtils.saveAppConfig(); - LogUtils.d(TAG, String.format("loadImage() 保存默认相框尺寸 | width=%d | height=%d", getWidth(), getHeight())); - } - + LogUtils.d(TAG, String.format("W : %d, H : %d", appConfigUtils.mAppConfigBean.getDefaultFrameWidth(), + appConfigUtils.mAppConfigBean.getDefaultFrameHeight())); + // 刷新逻辑:重新解码原始品质图片并更新缓存 if (isRefresh) { LogUtils.d(TAG, "loadImage() 执行刷新逻辑:重新解码原始品质图片"); @@ -178,16 +174,20 @@ public class BackgroundView extends RelativeLayout { // 合成纯色背景图片(固定尺寸1197x2287) Bitmap combinedBitmap = ImageUtils.drawBitmapOnSolidBackground(bgColor, - 1197, - 2287, + appConfigUtils.mAppConfigBean.getDefaultFrameWidth(), + appConfigUtils.mAppConfigBean.getDefaultFrameHeight(), newBitmap); - +// Bitmap combinedBitmap = ImageUtils.drawBitmapOnSolidBackground(bgColor, +// 1200, +// 2283, +// newBitmap); + if (combinedBitmap == null) { - ToastUtils.show("合成背景图片失败,使用原始图片"); + //ToastUtils.show("合成背景图片失败,使用原始图片"); LogUtils.e(TAG, "loadImage() 纯色背景合成失败,使用原始Bitmap"); combinedBitmap = newBitmap; } else { - ToastUtils.show("合成背景图片成功"); + //ToastUtils.show("合成背景图片成功"); LogUtils.d(TAG, String.format("loadImage() 纯色背景合成成功 | combinedBitmap=%dx%d", combinedBitmap.getWidth(), combinedBitmap.getHeight())); // 回收原始Bitmap(避免重复缓存)