Compare commits
8 Commits
powerbell-
...
powerbell-
| Author | SHA1 | Date | |
|---|---|---|---|
| f771225830 | |||
| 72794dc6e5 | |||
| 2ffdb26f69 | |||
| 3c6d269caf | |||
| 2f7f6b62fd | |||
| db096e716c | |||
| 1ce0a86b53 | |||
| 1e04bd463f |
@@ -83,11 +83,11 @@ dependencies {
|
|||||||
//api 'androidx.fragment:fragment:1.1.0'
|
//api 'androidx.fragment:fragment:1.1.0'
|
||||||
|
|
||||||
// WinBoLL库 nexus.winboll.cc 地址
|
// WinBoLL库 nexus.winboll.cc 地址
|
||||||
api 'cc.winboll.studio:libaes:15.12.6'
|
//api 'cc.winboll.studio:libaes:15.12.7'
|
||||||
//api 'cc.winboll.studio:libappbase:15.12.2'
|
//api 'cc.winboll.studio:libappbase:15.12.2'
|
||||||
|
|
||||||
// WinBoLL备用库 jitpack.io 地址
|
// WinBoLL备用库 jitpack.io 地址
|
||||||
//api 'com.github.ZhanGSKen:AES:aes-v15.12.3'
|
api 'com.github.ZhanGSKen:AES:aes-v15.12.7'
|
||||||
api 'com.github.ZhanGSKen:APPBase:appbase-v15.14.1'
|
api 'com.github.ZhanGSKen:APPBase:appbase-v15.14.1'
|
||||||
|
|
||||||
//api fileTree(dir: 'libs', include: ['*.aar'])
|
//api fileTree(dir: 'libs', include: ['*.aar'])
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Tue Dec 23 15:23:07 HKT 2025
|
#Wed Dec 24 12:22:06 HKT 2025
|
||||||
stageCount=26
|
stageCount=29
|
||||||
libraryProject=
|
libraryProject=
|
||||||
baseVersion=15.14
|
baseVersion=15.14
|
||||||
publishVersion=15.14.25
|
publishVersion=15.14.28
|
||||||
buildCount=0
|
buildCount=0
|
||||||
baseBetaVersion=15.14.26
|
baseBetaVersion=15.14.29
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package cc.winboll.studio.powerbell;
|
package cc.winboll.studio.powerbell;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Environment;
|
|
||||||
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
|
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
|
||||||
import cc.winboll.studio.libappbase.GlobalApplication;
|
import cc.winboll.studio.libappbase.GlobalApplication;
|
||||||
import cc.winboll.studio.libappbase.LogUtils;
|
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.BitmapCacheUtils;
|
||||||
import cc.winboll.studio.powerbell.utils.NotificationManagerUtils;
|
import cc.winboll.studio.powerbell.utils.NotificationManagerUtils;
|
||||||
import cc.winboll.studio.powerbell.views.MemoryCachedBackgroundView;
|
import cc.winboll.studio.powerbell.views.MemoryCachedBackgroundView;
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 应用全局入口类(适配Android API 30,基于Java 7编写)
|
* 应用全局入口类(适配Android API 30,基于Java 7编写)
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ 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;
|
||||||
@@ -46,7 +45,7 @@ public class MainActivity extends WinBoLLActivity implements MainContentView.OnV
|
|||||||
|
|
||||||
// ======================== 静态常量(置顶统一,抽离魔法值)========================
|
// ======================== 静态常量(置顶统一,抽离魔法值)========================
|
||||||
public static final String TAG = "MainActivity";
|
public static final String TAG = "MainActivity";
|
||||||
private static final int REQUEST_READ_MEDIA_IMAGES = 1001;
|
private static final int REQUEST_BACKGROUND_SETTINGS_ACTIVITY = 1001;
|
||||||
private static final long DELAY_LOAD_NON_CRITICAL = 500L;
|
private static final long DELAY_LOAD_NON_CRITICAL = 500L;
|
||||||
public static final int MSG_RELOAD_APPCONFIG = 0;
|
public static final int MSG_RELOAD_APPCONFIG = 0;
|
||||||
public static final int MSG_CURRENTVALUEBATTERY = 1;
|
public static final int MSG_CURRENTVALUEBATTERY = 1;
|
||||||
@@ -111,10 +110,7 @@ public class MainActivity extends WinBoLLActivity implements MainContentView.OnV
|
|||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
LogUtils.d(TAG, "onResume()");
|
LogUtils.d(TAG, "onResume()");
|
||||||
if (sGlobalHandler != null) {
|
|
||||||
sGlobalHandler.sendEmptyMessage(MSG_LOAD_BACKGROUND);
|
|
||||||
sGlobalHandler.sendEmptyMessage(MSG_UPDATE_SERVICE_SWITCH);
|
|
||||||
}
|
|
||||||
if (mADsBannerView != null) {
|
if (mADsBannerView != null) {
|
||||||
mADsBannerView.resumeADs(this);
|
mADsBannerView.resumeADs(this);
|
||||||
}
|
}
|
||||||
@@ -168,7 +164,7 @@ public class MainActivity extends WinBoLLActivity implements MainContentView.OnV
|
|||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
LogUtils.d(TAG, "onActivityResult() | requestCode=" + requestCode + " | resultCode=" + resultCode + " | data=" + data);
|
LogUtils.d(TAG, "onActivityResult() | requestCode=" + requestCode + " | resultCode=" + resultCode + " | data=" + data);
|
||||||
mPermissionUtils.handlePermissionRequest(this, requestCode, resultCode, data);
|
mPermissionUtils.handlePermissionRequest(this, requestCode, resultCode, data);
|
||||||
if (requestCode == REQUEST_READ_MEDIA_IMAGES && sGlobalHandler != null) {
|
if (requestCode == REQUEST_BACKGROUND_SETTINGS_ACTIVITY && sGlobalHandler != null) {
|
||||||
sGlobalHandler.sendEmptyMessage(MSG_LOAD_BACKGROUND);
|
sGlobalHandler.sendEmptyMessage(MSG_LOAD_BACKGROUND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -208,7 +204,7 @@ public class MainActivity extends WinBoLLActivity implements MainContentView.OnV
|
|||||||
startActivity(new Intent(this, ClearRecordActivity.class));
|
startActivity(new Intent(this, ClearRecordActivity.class));
|
||||||
break;
|
break;
|
||||||
case R.id.action_changepicture:
|
case R.id.action_changepicture:
|
||||||
startActivityForResult(new Intent(this, BackgroundSettingsActivity.class), REQUEST_READ_MEDIA_IMAGES);
|
startActivityForResult(new Intent(this, BackgroundSettingsActivity.class), REQUEST_BACKGROUND_SETTINGS_ACTIVITY);
|
||||||
break;
|
break;
|
||||||
case R.id.action_unittestactivity:
|
case R.id.action_unittestactivity:
|
||||||
startActivity(new Intent(this, MainUnitTestActivity.class));
|
startActivity(new Intent(this, MainUnitTestActivity.class));
|
||||||
@@ -275,7 +271,7 @@ public class MainActivity extends WinBoLLActivity implements MainContentView.OnV
|
|||||||
break;
|
break;
|
||||||
case MSG_LOAD_BACKGROUND:
|
case MSG_LOAD_BACKGROUND:
|
||||||
sMainActivity.reloadBackground();
|
sMainActivity.reloadBackground();
|
||||||
sMainActivity.setMainLayoutBackgroundColor();
|
//sMainActivity.setMainLayoutBackgroundColor();
|
||||||
break;
|
break;
|
||||||
case MSG_UPDATE_SERVICE_SWITCH:
|
case MSG_UPDATE_SERVICE_SWITCH:
|
||||||
sMainActivity.updateServiceSwitchUI();
|
sMainActivity.updateServiceSwitchUI();
|
||||||
@@ -407,24 +403,24 @@ public class MainActivity extends WinBoLLActivity implements MainContentView.OnV
|
|||||||
}
|
}
|
||||||
BackgroundBean currentBgBean = mBgSourceUtils.getCurrentBackgroundBean();
|
BackgroundBean currentBgBean = mBgSourceUtils.getCurrentBackgroundBean();
|
||||||
if (currentBgBean != null) {
|
if (currentBgBean != null) {
|
||||||
mMainContentView.backgroundView.loadByBackgroundBean(currentBgBean);
|
mMainContentView.backgroundView.loadByBackgroundBean(currentBgBean, true);
|
||||||
} else {
|
} else {
|
||||||
mMainContentView.backgroundView.setBackgroundResource(R.drawable.default_background);
|
mMainContentView.backgroundView.setBackgroundResource(R.drawable.default_background);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setMainLayoutBackgroundColor() {
|
// private void setMainLayoutBackgroundColor() {
|
||||||
LogUtils.d(TAG, "setMainLayoutBackgroundColor()");
|
// LogUtils.d(TAG, "setMainLayoutBackgroundColor()");
|
||||||
if (isFinishing() || isDestroyed() || mMainContentView == null || mBgSourceUtils == null) {
|
// if (isFinishing() || isDestroyed() || mMainContentView == null || mBgSourceUtils == null) {
|
||||||
LogUtils.e(TAG, "setMainLayoutBackgroundColor: 上下文无效,设置失败");
|
// LogUtils.e(TAG, "setMainLayoutBackgroundColor: 上下文无效,设置失败");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
BackgroundBean currentBgBean = mBgSourceUtils.getCurrentBackgroundBean();
|
// BackgroundBean currentBgBean = mBgSourceUtils.getCurrentBackgroundBean();
|
||||||
if (currentBgBean != null) {
|
// if (currentBgBean != null) {
|
||||||
mMainContentView.mainLayout.setBackgroundColor(currentBgBean.getPixelColor());
|
// mMainContentView.mainLayout.setBackgroundColor(currentBgBean.getPixelColor());
|
||||||
LogUtils.d(TAG, "setMainLayoutBackgroundColor: 主布局背景色设置完成 | color=" + currentBgBean.getPixelColor());
|
// LogUtils.d(TAG, "setMainLayoutBackgroundColor: 主布局背景色设置完成 | color=" + currentBgBean.getPixelColor2());
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
private void updateServiceSwitchUI() {
|
private void updateServiceSwitchUI() {
|
||||||
LogUtils.d(TAG, "updateServiceSwitchUI()");
|
LogUtils.d(TAG, "updateServiceSwitchUI()");
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import cc.winboll.studio.powerbell.utils.BackgroundSourceUtils;
|
|||||||
import cc.winboll.studio.powerbell.utils.BitmapCacheUtils;
|
import cc.winboll.studio.powerbell.utils.BitmapCacheUtils;
|
||||||
import cc.winboll.studio.powerbell.utils.FileUtils;
|
import cc.winboll.studio.powerbell.utils.FileUtils;
|
||||||
import cc.winboll.studio.powerbell.utils.ImageCropUtils;
|
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.utils.UriUtils;
|
||||||
import cc.winboll.studio.powerbell.views.BackgroundView;
|
import cc.winboll.studio.powerbell.views.BackgroundView;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -317,7 +318,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int oldColor = previewBean.getPixelColor();
|
int oldColor = previewBean.getPixelColor();
|
||||||
previewBean.setPixelColor(0xFF000000);
|
previewBean.setPixelColor(ImageUtils.getColorAccent(BackgroundSettingsActivity.this));
|
||||||
mBgSourceUtils.saveSettings();
|
mBgSourceUtils.saveSettings();
|
||||||
doubleRefreshPreview();
|
doubleRefreshPreview();
|
||||||
isPreviewBackgroundChanged = true;
|
isPreviewBackgroundChanged = true;
|
||||||
@@ -403,7 +404,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
mBgSourceUtils.loadSettings();
|
mBgSourceUtils.loadSettings();
|
||||||
BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
|
BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
|
||||||
mBackgroundView.loadByBackgroundBean(previewBean, true);
|
mBackgroundView.loadByBackgroundBean(previewBean, true);
|
||||||
mBackgroundView.setBackgroundColor(previewBean.getPixelColor());
|
//mBackgroundView.setBackgroundColor(previewBean.getPixelColor());
|
||||||
LogUtils.d(TAG, "【双重刷新】第一重完成");
|
LogUtils.d(TAG, "【双重刷新】第一重完成");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtils.e(TAG, "【双重刷新】第一重异常:" + e.getMessage());
|
LogUtils.e(TAG, "【双重刷新】第一重异常:" + e.getMessage());
|
||||||
@@ -419,7 +420,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
|||||||
mBgSourceUtils.loadSettings();
|
mBgSourceUtils.loadSettings();
|
||||||
BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
|
BackgroundBean previewBean = mBgSourceUtils.getPreviewBackgroundBean();
|
||||||
mBackgroundView.loadByBackgroundBean(previewBean, true);
|
mBackgroundView.loadByBackgroundBean(previewBean, true);
|
||||||
mBackgroundView.setBackgroundColor(previewBean.getPixelColor());
|
//mBackgroundView.setBackgroundColor(previewBean.getPixelColor());
|
||||||
LogUtils.d(TAG, "【双重刷新】第二重完成");
|
LogUtils.d(TAG, "【双重刷新】第二重完成");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtils.e(TAG, "【双重刷新】第二重异常:" + e.getMessage());
|
LogUtils.e(TAG, "【双重刷新】第二重异常:" + e.getMessage());
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public class BackgroundBean extends BaseBean implements Serializable {
|
|||||||
private int backgroundWidth = DEFAULT_DIMENSION; // 背景图宽度
|
private int backgroundWidth = DEFAULT_DIMENSION; // 背景图宽度
|
||||||
private int backgroundHeight = DEFAULT_DIMENSION; // 背景图高度
|
private int backgroundHeight = DEFAULT_DIMENSION; // 背景图高度
|
||||||
// 像素颜色
|
// 像素颜色
|
||||||
private int pixelColor = 0; // 拾取的像素颜色(纯色背景用)
|
private int pixelColor = 0xFFFFFFFF; // 拾取的像素颜色(纯色背景用)
|
||||||
|
|
||||||
// ====================== 构造方法(无参构造,JSON反序列化必备) ======================
|
// ====================== 构造方法(无参构造,JSON反序列化必备) ======================
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import cc.winboll.studio.powerbell.R;
|
|||||||
import cc.winboll.studio.powerbell.models.BackgroundBean;
|
import cc.winboll.studio.powerbell.models.BackgroundBean;
|
||||||
import cc.winboll.studio.powerbell.utils.FileUtils;
|
import cc.winboll.studio.powerbell.utils.FileUtils;
|
||||||
import cc.winboll.studio.powerbell.utils.ImageCropUtils;
|
import cc.winboll.studio.powerbell.utils.ImageCropUtils;
|
||||||
|
import cc.winboll.studio.powerbell.utils.ImageUtils;
|
||||||
import cc.winboll.studio.powerbell.views.MemoryCachedBackgroundView;
|
import cc.winboll.studio.powerbell.views.MemoryCachedBackgroundView;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -141,6 +142,7 @@ public class MainUnitTest2Activity extends AppCompatActivity {
|
|||||||
private void initBackgroundBean() {
|
private void initBackgroundBean() {
|
||||||
LogUtils.d(TAG, "initBackgroundBean:初始化背景Bean");
|
LogUtils.d(TAG, "initBackgroundBean:初始化背景Bean");
|
||||||
mPreviewBackgroundBean = new BackgroundBean();
|
mPreviewBackgroundBean = new BackgroundBean();
|
||||||
|
mPreviewBackgroundBean.setPixelColor(ImageUtils.getColorAccent(this));
|
||||||
mPreviewBackgroundBean.setBackgroundFileName(mPrivateTestImageFile.getName());
|
mPreviewBackgroundBean.setBackgroundFileName(mPrivateTestImageFile.getName());
|
||||||
mPreviewBackgroundBean.setBackgroundFilePath(mPrivateTestImageFile.getAbsolutePath());
|
mPreviewBackgroundBean.setBackgroundFilePath(mPrivateTestImageFile.getAbsolutePath());
|
||||||
mPreviewBackgroundBean.setBackgroundScaledCompressFileName(mPrivateCropImageFile.getName());
|
mPreviewBackgroundBean.setBackgroundScaledCompressFileName(mPrivateCropImageFile.getName());
|
||||||
@@ -241,7 +243,7 @@ public class MainUnitTest2Activity extends AppCompatActivity {
|
|||||||
// 第一重刷新
|
// 第一重刷新
|
||||||
try {
|
try {
|
||||||
mMemoryCachedBackgroundView.loadByBackgroundBean(mPreviewBackgroundBean, true);
|
mMemoryCachedBackgroundView.loadByBackgroundBean(mPreviewBackgroundBean, true);
|
||||||
mMemoryCachedBackgroundView.setBackgroundColor(mPreviewBackgroundBean.getPixelColor());
|
//mMemoryCachedBackgroundView.setBackgroundColor(mPreviewBackgroundBean.getPixelColor());
|
||||||
LogUtils.d(TAG, "doubleRefreshPreview:【双重刷新】第一重完成");
|
LogUtils.d(TAG, "doubleRefreshPreview:【双重刷新】第一重完成");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtils.e(TAG, String.format("doubleRefreshPreview:【双重刷新】第一重异常 | %s", e.getMessage()));
|
LogUtils.e(TAG, String.format("doubleRefreshPreview:【双重刷新】第一重异常 | %s", e.getMessage()));
|
||||||
@@ -255,7 +257,7 @@ public class MainUnitTest2Activity extends AppCompatActivity {
|
|||||||
if (mMemoryCachedBackgroundView != null && !isFinishing()) {
|
if (mMemoryCachedBackgroundView != null && !isFinishing()) {
|
||||||
try {
|
try {
|
||||||
mMemoryCachedBackgroundView.loadByBackgroundBean(mPreviewBackgroundBean, true);
|
mMemoryCachedBackgroundView.loadByBackgroundBean(mPreviewBackgroundBean, true);
|
||||||
mMemoryCachedBackgroundView.setBackgroundColor(mPreviewBackgroundBean.getPixelColor());
|
//mMemoryCachedBackgroundView.setBackgroundColor(mPreviewBackgroundBean.getPixelColor());
|
||||||
LogUtils.d(TAG, "doubleRefreshPreview:【双重刷新】第二重完成");
|
LogUtils.d(TAG, "doubleRefreshPreview:【双重刷新】第二重完成");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtils.e(TAG, String.format("doubleRefreshPreview:【双重刷新】第二重异常 | %s", e.getMessage()));
|
LogUtils.e(TAG, String.format("doubleRefreshPreview:【双重刷新】第二重异常 | %s", e.getMessage()));
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import cc.winboll.studio.powerbell.R;
|
|||||||
import cc.winboll.studio.powerbell.models.BackgroundBean;
|
import cc.winboll.studio.powerbell.models.BackgroundBean;
|
||||||
import cc.winboll.studio.powerbell.utils.FileUtils;
|
import cc.winboll.studio.powerbell.utils.FileUtils;
|
||||||
import cc.winboll.studio.powerbell.utils.ImageCropUtils;
|
import cc.winboll.studio.powerbell.utils.ImageCropUtils;
|
||||||
|
import cc.winboll.studio.powerbell.utils.ImageUtils;
|
||||||
import cc.winboll.studio.powerbell.views.BackgroundView;
|
import cc.winboll.studio.powerbell.views.BackgroundView;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -134,6 +135,7 @@ public class MainUnitTestActivity extends AppCompatActivity {
|
|||||||
private void initBackgroundBean() {
|
private void initBackgroundBean() {
|
||||||
LogUtils.d(TAG, "initBackgroundBean:初始化背景Bean");
|
LogUtils.d(TAG, "initBackgroundBean:初始化背景Bean");
|
||||||
mPreviewBackgroundBean = new BackgroundBean();
|
mPreviewBackgroundBean = new BackgroundBean();
|
||||||
|
mPreviewBackgroundBean.setPixelColor(ImageUtils.getColorAccent(this));
|
||||||
mPreviewBackgroundBean.setBackgroundFileName(mPrivateTestImageFile.getName());
|
mPreviewBackgroundBean.setBackgroundFileName(mPrivateTestImageFile.getName());
|
||||||
mPreviewBackgroundBean.setBackgroundFilePath(mPrivateTestImageFile.getAbsolutePath());
|
mPreviewBackgroundBean.setBackgroundFilePath(mPrivateTestImageFile.getAbsolutePath());
|
||||||
mPreviewBackgroundBean.setBackgroundScaledCompressFileName(mPrivateCropImageFile.getName());
|
mPreviewBackgroundBean.setBackgroundScaledCompressFileName(mPrivateCropImageFile.getName());
|
||||||
|
|||||||
@@ -156,6 +156,7 @@ public class BackgroundSourceUtils {
|
|||||||
currentBackgroundBean = BackgroundBean.loadBeanFromFile(currentBackgroundBeanFile.getAbsolutePath(), BackgroundBean.class);
|
currentBackgroundBean = BackgroundBean.loadBeanFromFile(currentBackgroundBeanFile.getAbsolutePath(), BackgroundBean.class);
|
||||||
if (currentBackgroundBean == null) {
|
if (currentBackgroundBean == null) {
|
||||||
currentBackgroundBean = new BackgroundBean();
|
currentBackgroundBean = new BackgroundBean();
|
||||||
|
currentBackgroundBean.setPixelColor(ImageUtils.getColorAccent(mContext));
|
||||||
BackgroundBean.saveBeanToFile(currentBackgroundBeanFile.getAbsolutePath(), currentBackgroundBean);
|
BackgroundBean.saveBeanToFile(currentBackgroundBeanFile.getAbsolutePath(), currentBackgroundBean);
|
||||||
LogUtils.d(TAG, "【配置加载】正式背景Bean不存在,已创建新实例");
|
LogUtils.d(TAG, "【配置加载】正式背景Bean不存在,已创建新实例");
|
||||||
}
|
}
|
||||||
@@ -163,6 +164,7 @@ public class BackgroundSourceUtils {
|
|||||||
previewBackgroundBean = BackgroundBean.loadBeanFromFile(previewBackgroundBeanFile.getAbsolutePath(), BackgroundBean.class);
|
previewBackgroundBean = BackgroundBean.loadBeanFromFile(previewBackgroundBeanFile.getAbsolutePath(), BackgroundBean.class);
|
||||||
if (previewBackgroundBean == null) {
|
if (previewBackgroundBean == null) {
|
||||||
previewBackgroundBean = new BackgroundBean();
|
previewBackgroundBean = new BackgroundBean();
|
||||||
|
previewBackgroundBean.setPixelColor(ImageUtils.getColorAccent(mContext));
|
||||||
BackgroundBean.saveBeanToFile(previewBackgroundBeanFile.getAbsolutePath(), previewBackgroundBean);
|
BackgroundBean.saveBeanToFile(previewBackgroundBeanFile.getAbsolutePath(), previewBackgroundBean);
|
||||||
LogUtils.d(TAG, "【配置加载】预览背景Bean不存在,已创建新实例");
|
LogUtils.d(TAG, "【配置加载】预览背景Bean不存在,已创建新实例");
|
||||||
}
|
}
|
||||||
@@ -542,6 +544,7 @@ public class BackgroundSourceUtils {
|
|||||||
LogUtils.d(TAG, "【背景提交】开始深拷贝预览Bean到正式Bean");
|
LogUtils.d(TAG, "【背景提交】开始深拷贝预览Bean到正式Bean");
|
||||||
// 深拷贝Bean属性
|
// 深拷贝Bean属性
|
||||||
currentBackgroundBean = new BackgroundBean();
|
currentBackgroundBean = new BackgroundBean();
|
||||||
|
currentBackgroundBean.setPixelColor(ImageUtils.getColorAccent(mContext));
|
||||||
copyBackgroundBeanProperties(previewBackgroundBean, currentBackgroundBean);
|
copyBackgroundBeanProperties(previewBackgroundBean, currentBackgroundBean);
|
||||||
|
|
||||||
// 复制文件
|
// 复制文件
|
||||||
@@ -570,6 +573,7 @@ public class BackgroundSourceUtils {
|
|||||||
LogUtils.d(TAG, "【背景同步】开始深拷贝正式Bean到预览Bean");
|
LogUtils.d(TAG, "【背景同步】开始深拷贝正式Bean到预览Bean");
|
||||||
// 深拷贝Bean属性
|
// 深拷贝Bean属性
|
||||||
previewBackgroundBean = new BackgroundBean();
|
previewBackgroundBean = new BackgroundBean();
|
||||||
|
previewBackgroundBean.setPixelColor(ImageUtils.getColorAccent(mContext));
|
||||||
copyBackgroundBeanProperties(currentBackgroundBean, previewBackgroundBean);
|
copyBackgroundBeanProperties(currentBackgroundBean, previewBackgroundBean);
|
||||||
|
|
||||||
saveSettings();
|
saveSettings();
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
package cc.winboll.studio.powerbell.utils;
|
package cc.winboll.studio.powerbell.utils;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.graphics.Color;
|
||||||
import cc.winboll.studio.libappbase.LogUtils;
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
|
import cc.winboll.studio.powerbell.R;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@@ -12,9 +15,10 @@ import java.io.OutputStream;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 图片处理工具类(质量压缩专用)
|
* 图片处理工具类(质量压缩专用)
|
||||||
* 功能:对图片进行JPEG质量压缩,并将压缩结果覆盖源文件
|
* 功能:对图片进行JPEG质量压缩,并将压缩结果覆盖源文件;获取主题colorPrimary颜色值
|
||||||
* 适配:Java 7 + Android API 30
|
* 适配:Java 7 + Android API 30
|
||||||
* 核心逻辑:Bitmap.compress 质量压缩 + FileChannel 高效文件复制
|
* 核心逻辑:Bitmap.compress 质量压缩 + FileChannel 高效文件复制;主题属性解析
|
||||||
|
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
|
||||||
*/
|
*/
|
||||||
public class ImageUtils {
|
public class ImageUtils {
|
||||||
// ================================== 静态常量区(置顶归类,消除魔法值)=================================
|
// ================================== 静态常量区(置顶归类,消除魔法值)=================================
|
||||||
@@ -22,6 +26,39 @@ public class ImageUtils {
|
|||||||
private static final Bitmap.CompressFormat COMPRESS_FORMAT = Bitmap.CompressFormat.JPEG;
|
private static final Bitmap.CompressFormat COMPRESS_FORMAT = Bitmap.CompressFormat.JPEG;
|
||||||
private static final int MIN_COMPRESS_QUALITY = 0;
|
private static final int MIN_COMPRESS_QUALITY = 0;
|
||||||
private static final int MAX_COMPRESS_QUALITY = 100;
|
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,数值越小压缩率越高)
|
* @param compressQuality 压缩质量(0-100,数值越小压缩率越高)
|
||||||
*/
|
*/
|
||||||
public static void bitmapCompress(Context context, String srcImagePath, String dstImagePath, int compressQuality) {
|
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. 前置参数校验
|
// 1. 前置参数校验
|
||||||
if (srcImagePath == null || srcImagePath.isEmpty()) {
|
if (srcImagePath == null || srcImagePath.isEmpty()) {
|
||||||
LogUtils.e(TAG, "【bitmapCompress】参数异常:源文件路径为空");
|
LogUtils.e(TAG, "【bitmapCompress】参数异常:源文件路径为空");
|
||||||
@@ -43,7 +81,7 @@ public class ImageUtils {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (compressQuality < MIN_COMPRESS_QUALITY || compressQuality > MAX_COMPRESS_QUALITY) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,14 +100,16 @@ public class ImageUtils {
|
|||||||
LogUtils.e(TAG, "【bitmapCompress】Bitmap解码失败:无法读取源图片 " + srcImagePath);
|
LogUtils.e(TAG, "【bitmapCompress】Bitmap解码失败:无法读取源图片 " + srcImagePath);
|
||||||
return;
|
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. 创建临时压缩文件
|
// 3. 创建临时压缩文件
|
||||||
File dstFile = new File(dstImagePath);
|
File dstFile = new File(dstImagePath);
|
||||||
File dstParentDir = dstFile.getParentFile();
|
File dstParentDir = dstFile.getParentFile();
|
||||||
if (dstParentDir != null && !dstParentDir.exists()) {
|
if (dstParentDir != null && !dstParentDir.exists()) {
|
||||||
boolean isDirCreated = dstParentDir.mkdirs();
|
boolean isDirCreated = dstParentDir.mkdirs();
|
||||||
LogUtils.d(TAG, "【bitmapCompress】临时目录创建" + (isDirCreated ? "成功" : "失败") + ":" + dstParentDir.getAbsolutePath());
|
LogUtils.d(TAG, String.format("【bitmapCompress】临时目录创建%s:%s",
|
||||||
|
isDirCreated ? "成功" : "失败", dstParentDir.getAbsolutePath()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. 写入压缩数据
|
// 4. 写入压缩数据
|
||||||
@@ -83,7 +123,8 @@ public class ImageUtils {
|
|||||||
|
|
||||||
// 5. 复制压缩文件覆盖源文件
|
// 5. 复制压缩文件覆盖源文件
|
||||||
FileUtils.copyFileUsingFileChannels(dstFile, srcFile);
|
FileUtils.copyFileUsingFileChannels(dstFile, srcFile);
|
||||||
LogUtils.d(TAG, "【bitmapCompress】" + compressQuality + "%压缩结束:已覆盖源文件 " + srcImagePath);
|
LogUtils.d(TAG, String.format("【bitmapCompress】%d%%压缩结束:已覆盖源文件 %s",
|
||||||
|
compressQuality, srcImagePath));
|
||||||
|
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
LogUtils.e(TAG, "【bitmapCompress】文件未找到异常", e);
|
LogUtils.e(TAG, "【bitmapCompress】文件未找到异常", e);
|
||||||
|
|||||||
@@ -149,6 +149,7 @@ public class BackgroundView extends RelativeLayout {
|
|||||||
}
|
}
|
||||||
// 加载图片
|
// 加载图片
|
||||||
loadImage(targetPath);
|
loadImage(targetPath);
|
||||||
|
setBackgroundColor(bean.getPixelColor());
|
||||||
LogUtils.d(TAG, "=== loadByBackgroundBean 完成 ===");
|
LogUtils.d(TAG, "=== loadByBackgroundBean 完成 ===");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user