Compare commits
12 Commits
powerbell-
...
powerbell-
| Author | SHA1 | Date | |
|---|---|---|---|
| bba48a4458 | |||
| b7ae6ce190 | |||
| ba5470ebcb | |||
| 78c7763212 | |||
| d051b1f737 | |||
| d6323bc1ed | |||
| dffcc0f8a0 | |||
| 9426618b59 | |||
| 68d98d4be3 | |||
| 4db458dda8 | |||
| 83a8f5dada | |||
| 8e1d6ba197 |
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Sun Dec 14 19:58:14 HKT 2025
|
||||
stageCount=7
|
||||
#Tue Dec 16 20:17:03 HKT 2025
|
||||
stageCount=9
|
||||
libraryProject=
|
||||
baseVersion=15.14
|
||||
publishVersion=15.14.6
|
||||
publishVersion=15.14.8
|
||||
buildCount=0
|
||||
baseBetaVersion=15.14.7
|
||||
baseBetaVersion=15.14.9
|
||||
|
||||
@@ -15,7 +15,6 @@ import android.os.Looper;
|
||||
import android.provider.MediaStore;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.core.content.FileProvider;
|
||||
@@ -24,6 +23,7 @@ import cc.winboll.studio.libappbase.ToastUtils;
|
||||
import cc.winboll.studio.powerbell.App;
|
||||
import cc.winboll.studio.powerbell.R;
|
||||
import cc.winboll.studio.powerbell.dialogs.BackgroundPicturePreviewDialog;
|
||||
import cc.winboll.studio.powerbell.dialogs.ColorPaletteDialog;
|
||||
import cc.winboll.studio.powerbell.dialogs.YesNoAlertDialog;
|
||||
import cc.winboll.studio.powerbell.models.BackgroundBean;
|
||||
import cc.winboll.studio.powerbell.utils.BackgroundSourceUtils;
|
||||
@@ -32,6 +32,7 @@ import cc.winboll.studio.powerbell.utils.FileUtils;
|
||||
import cc.winboll.studio.powerbell.utils.ImageCropUtils;
|
||||
import cc.winboll.studio.powerbell.utils.UriUtils;
|
||||
import cc.winboll.studio.powerbell.views.BackgroundView;
|
||||
import com.a4455jkjh.colorpicker.ColorPickerDialog;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -207,6 +208,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
||||
findViewById(R.id.activitybackgroundpictureAButton6).setOnClickListener(onCropFreePictureClickListener);
|
||||
findViewById(R.id.activitybackgroundpictureAButton7).setOnClickListener(onPixelPickerClickListener);
|
||||
findViewById(R.id.activitybackgroundpictureAButton8).setOnClickListener(onCleanPixelClickListener);
|
||||
findViewById(R.id.activitybackgroundsettingsAButton1).setOnClickListener(onColorPaletteClickListener);
|
||||
}
|
||||
|
||||
// ====================== 按钮点击事件 ======================
|
||||
@@ -321,7 +323,7 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
||||
LogUtils.d(TAG, "【按钮点击】清空像素颜色");
|
||||
BackgroundBean bean = mBgSourceUtils.getPreviewBackgroundBean();
|
||||
int oldColor = bean.getPixelColor();
|
||||
bean.setPixelColor(0);
|
||||
bean.setPixelColor(0xFF000000);
|
||||
mBgSourceUtils.saveSettings();
|
||||
doubleRefreshPreview();
|
||||
isPreviewBackgroundChanged = true;
|
||||
@@ -330,6 +332,32 @@ public class BackgroundSettingsActivity extends WinBoLLActivity {
|
||||
}
|
||||
};
|
||||
|
||||
private View.OnClickListener onColorPaletteClickListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
LogUtils.d(TAG, "【按钮点击】调色板按钮");
|
||||
|
||||
// 初始颜色(白色,含透明度)
|
||||
//int initialColor = 0xFFFFFFFF;
|
||||
int initialColor = mBgSourceUtils.getPreviewBackgroundBean().getPixelColor();
|
||||
// 显示对话框
|
||||
ColorPaletteDialog dialog = new ColorPaletteDialog(BackgroundSettingsActivity.this, initialColor, new ColorPaletteDialog.OnColorSelectedListener() {
|
||||
@Override
|
||||
public void onColorSelected(int color) {
|
||||
// 回调返回 0xAARRGGBB 格式颜色,直接使用
|
||||
mBgSourceUtils.getPreviewBackgroundBean().setPixelColor(color);
|
||||
mBgSourceUtils.saveSettings();
|
||||
doubleRefreshPreview();
|
||||
isPreviewBackgroundChanged = true;
|
||||
LogUtils.d("选择颜色", String.format("#%08X", color));
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
|
||||
LogUtils.d(TAG, "调色板按钮响应完成。");
|
||||
}
|
||||
};
|
||||
|
||||
// ====================== 工具方法 ======================
|
||||
/**
|
||||
* 生成 FileProvider Uri,适配 Android 7.0+
|
||||
|
||||
@@ -0,0 +1,747 @@
|
||||
package cc.winboll.studio.powerbell.dialogs;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.HorizontalScrollView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.ToastUtils;
|
||||
import cc.winboll.studio.powerbell.R;
|
||||
import com.a4455jkjh.colorpicker.ColorPickerDialog;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2025/12/16 11:47
|
||||
* @Describe 调色板对话框(支持颜色拾取、RGB输入、透明度/亮度调节,兼容 API29-30+ 小米机型)
|
||||
*/
|
||||
public class ColorPaletteDialog extends Dialog implements View.OnClickListener, SeekBar.OnSeekBarChangeListener {
|
||||
// ====================== 常量定义(首屏可见,统一管理) ======================
|
||||
public static final String TAG = "ColorPaletteDialog";
|
||||
private static final int MAX_RGB_VALUE = 255; // RGB分量最大值(0-255)
|
||||
private static final int DEFAULT_BRIGHTNESS = 100; // 默认亮度百分比(100%,无调节)
|
||||
private static final int BRIGHTNESS_STEP = 5; // 亮度调节步长(每次±5%,精准流畅)
|
||||
private static final int MIN_BRIGHTNESS = 10; // 亮度最小值(10%,避免全黑看不见)
|
||||
private static final int MAX_BRIGHTNESS = 200; // 亮度最大值(200%,避免过曝失真)
|
||||
private static final int MAX_ALPHA_PERCENT = 100; // 透明度最大值(100%=不透明)
|
||||
private static final int MIN_ALPHA_PERCENT = 0; // 透明度最小值(0%=完全透明)
|
||||
|
||||
// ====================== 回调接口(紧跟常量,逻辑关联) ======================
|
||||
public interface OnColorSelectedListener {
|
||||
void onColorSelected(int color); // 返回0xAARRGGBB格式颜色(含透明度)
|
||||
}
|
||||
|
||||
// ====================== 成员变量(按优先级排序:核心数据→控件引用) ======================
|
||||
// 核心数据:原始基准值(用户输入/选择颜色时更新)+ 实时调节值(亮度/透明度变化时更新)
|
||||
private OnColorSelectedListener mListener; // 颜色选择回调(非空校验)
|
||||
private int mInitialColor; // 初始颜色(传入的默认颜色)
|
||||
private int mCurrentColor; // 当前最终颜色(含亮度+透明度调节)
|
||||
private int mCurrentBrightnessPercent; // 当前亮度百分比(10%-200%)
|
||||
// 透明度:百分比(0-100%,用户直观操作)+ 原始/实时值(0-255,颜色计算用)
|
||||
private int mOriginalAlphaPercent; // 原始透明度百分比(基准值,用户输入/选色时更新)
|
||||
private int mCurrentAlphaPercent; // 实时透明度百分比(调节进度条时更新)
|
||||
private int mOriginalAlpha; // 原始透明度(0-255,基准值)
|
||||
private int mCurrentAlpha; // 实时透明度(0-255,计算用)
|
||||
// RGB:原始基准值+实时调节值
|
||||
private int mOriginalR; // 原始R分量(基准值,用户输入/选色时更新)
|
||||
private int mOriginalG; // 原始G分量(基准值,用户输入/选色时更新)
|
||||
private int mOriginalB; // 原始B分量(基准值,用户输入/选色时更新)
|
||||
private int mCurrentR; // 实时R分量(亮度调节后,同步输入框显示)
|
||||
private int mCurrentG; // 实时G分量(亮度调节后,同步输入框显示)
|
||||
private int mCurrentB; // 实时B分量(亮度调节后,同步输入框显示)
|
||||
// 并发控制标记:是否是应用程序自身在更新颜色(避免循环回调/重复触发)
|
||||
private static volatile boolean isAppSelfUpdatingColor = false;
|
||||
|
||||
// 控件引用(新增透明度进度条+文本)
|
||||
private ImageView ivColorPicker; // 颜色预览拾取框
|
||||
private ImageView ivColorScaler; // 颜色渐变拾取框
|
||||
private EditText etR; // R分量输入框(显示实时调节值)
|
||||
private EditText etG; // G分量输入框(显示实时调节值)
|
||||
private EditText etB; // B分量输入框(显示实时调节值)
|
||||
private EditText etColorValue; // 颜色值输入框(#AARRGGBB,显示最终值)
|
||||
private SeekBar sbAlpha; // 透明度调节进度条(0-100%)
|
||||
private TextView tvAlphaValue; // 透明度数值显示(X%)
|
||||
private TextView tvBrightnessMinus;// 亮度减少按钮(-)
|
||||
private TextView tvBrightnessValue;// 亮度数值显示(X%,直观易懂)
|
||||
private TextView tvBrightnessPlus; // 亮度增加按钮(+)
|
||||
private TextView tvConfirm; // 确认按钮
|
||||
private TextView tvCancel; // 取消按钮
|
||||
|
||||
// ====================== 构造方法(初始化核心数据,严格校验) ======================
|
||||
public ColorPaletteDialog(Context context, int initialColor, OnColorSelectedListener listener) {
|
||||
super(context, R.style.CustomDialogStyle);
|
||||
this.mInitialColor = initialColor;
|
||||
this.mListener = listener;
|
||||
|
||||
// 1. 强制回调非空,避免后续空指针(容错)
|
||||
if (mListener == null) {
|
||||
throw new IllegalArgumentException("OnColorSelectedListener can not be null!");
|
||||
}
|
||||
|
||||
// 2. 解析初始颜色:原始基准值 = 实时值(初始无调节)
|
||||
// 透明度:初始颜色的alpha(0-255)转百分比(0-100%)
|
||||
this.mOriginalAlpha = Color.alpha(initialColor);
|
||||
this.mOriginalAlphaPercent = alpha2Percent(mOriginalAlpha);
|
||||
this.mCurrentAlpha = mOriginalAlpha;
|
||||
this.mCurrentAlphaPercent = mOriginalAlphaPercent;
|
||||
// RGB:初始颜色的RGB分量
|
||||
this.mOriginalR = Color.red(initialColor);
|
||||
this.mOriginalG = Color.green(initialColor);
|
||||
this.mOriginalB = Color.blue(initialColor);
|
||||
this.mCurrentR = mOriginalR;
|
||||
this.mCurrentG = mOriginalG;
|
||||
this.mCurrentB = mOriginalB;
|
||||
|
||||
// 3. 初始化当前状态(默认亮度100%,当前颜色=初始颜色)
|
||||
this.mCurrentBrightnessPercent = DEFAULT_BRIGHTNESS;
|
||||
this.mCurrentColor = initialColor;
|
||||
|
||||
LogUtils.d(TAG, "init dialog success | 初始颜色:" + String.format("#%08X", initialColor)
|
||||
+ " | 原始RGB:" + mOriginalR + "," + mOriginalG + "," + mOriginalB
|
||||
+ " | 原始透明度:" + mOriginalAlphaPercent + "%"
|
||||
+ " | 初始亮度:" + mCurrentBrightnessPercent + "%");
|
||||
}
|
||||
|
||||
// ====================== 生命周期方法(按执行顺序排列,逻辑清晰) ======================
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE); // 隐藏标题栏
|
||||
View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_color_palette, null);
|
||||
setContentView(view);
|
||||
|
||||
// 初始化流程:控件绑定→数据赋值→监听设置→尺寸适配(小米机型优先适配)
|
||||
initViewBind(view);
|
||||
initData();
|
||||
initListener();
|
||||
adjustDialogSize();
|
||||
LogUtils.d(TAG, "dialog create complete | 适配小米API29-30机型");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dismiss() {
|
||||
super.dismiss();
|
||||
// 释放资源,避免内存泄漏(回调引用置空)
|
||||
mListener = null;
|
||||
LogUtils.d(TAG, "dialog dismiss | 释放资源完成");
|
||||
}
|
||||
|
||||
// ====================== 初始化核心方法(职责单一,便于维护) ======================
|
||||
/**
|
||||
* 控件绑定(新增透明度进度条+文本绑定)
|
||||
*/
|
||||
private void initViewBind(View view) {
|
||||
ivColorPicker = view.findViewById(R.id.iv_color_picker);
|
||||
ivColorScaler = view.findViewById(R.id.iv_color_scaler);
|
||||
etR = view.findViewById(R.id.et_r);
|
||||
etG = view.findViewById(R.id.et_g);
|
||||
etB = view.findViewById(R.id.et_b);
|
||||
etColorValue = view.findViewById(R.id.et_color_value);
|
||||
sbAlpha = view.findViewById(R.id.sb_alpha);
|
||||
tvAlphaValue = view.findViewById(R.id.tv_alpha_value);
|
||||
tvBrightnessMinus = view.findViewById(R.id.tv_brightness_minus);
|
||||
tvBrightnessValue = view.findViewById(R.id.tv_brightness_value);
|
||||
tvBrightnessPlus = view.findViewById(R.id.tv_brightness_plus);
|
||||
tvConfirm = view.findViewById(R.id.tv_confirm);
|
||||
tvCancel = view.findViewById(R.id.tv_cancel);
|
||||
|
||||
// 控件非空校验(小米低版本容错,绑定失败直接关闭对话框)
|
||||
if (ivColorPicker == null || ivColorScaler == null || etR == null || etG == null || etB == null || etColorValue == null
|
||||
|| sbAlpha == null || tvAlphaValue == null
|
||||
|| tvBrightnessMinus == null || tvBrightnessValue == null || tvBrightnessPlus == null
|
||||
|| tvConfirm == null || tvCancel == null) {
|
||||
LogUtils.e(TAG, "view bind failed | 请检查布局ID是否正确!");
|
||||
dismiss();
|
||||
return;
|
||||
}
|
||||
LogUtils.d(TAG, "view bind complete | 所有控件绑定成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据初始化(无监听状态下赋值,避免循环回调)
|
||||
*/
|
||||
private void initData() {
|
||||
// 1. 颜色预览(显示当前最终颜色,初始=原始颜色)
|
||||
ivColorPicker.setBackgroundColor(mCurrentColor);
|
||||
|
||||
// 2. RGB输入框(显示「实时分量」,初始=原始值)
|
||||
etR.setText(String.valueOf(mCurrentR));
|
||||
etG.setText(String.valueOf(mCurrentG));
|
||||
etB.setText(String.valueOf(mCurrentB));
|
||||
|
||||
// 3. 颜色值输入框(显示当前最终颜色,格式#AARRGGBB,大写更规范)
|
||||
etColorValue.setText(String.format("#%08X", mCurrentColor));
|
||||
|
||||
// 4. 透明度控件(进度条+文本,初始=原始透明度)
|
||||
sbAlpha.setProgress(mCurrentAlphaPercent);
|
||||
tvAlphaValue.setText(mCurrentAlphaPercent + "%");
|
||||
|
||||
// 5. 亮度控件(显示默认100%,初始化按钮状态)
|
||||
tvBrightnessValue.setText(mCurrentBrightnessPercent + "%");
|
||||
updateBrightnessBtnStatus(); // 禁用边界值按钮(初始100%,都可用)
|
||||
|
||||
LogUtils.d(TAG, "init data complete | 原始透明度:" + mOriginalAlphaPercent + "%");
|
||||
}
|
||||
|
||||
/**
|
||||
* 监听初始化(新增透明度进度条监听)
|
||||
*/
|
||||
private void initListener() {
|
||||
// 点击监听(按钮+颜色拾取框)
|
||||
ivColorPicker.setOnClickListener(this);
|
||||
ivColorScaler.setOnClickListener(this);
|
||||
tvConfirm.setOnClickListener(this);
|
||||
tvCancel.setOnClickListener(this);
|
||||
tvBrightnessMinus.setOnClickListener(this);
|
||||
tvBrightnessPlus.setOnClickListener(this);
|
||||
// 透明度进度条监听
|
||||
sbAlpha.setOnSeekBarChangeListener(this);
|
||||
// 输入框监听(RGB+颜色值,避免循环同步)
|
||||
initTextWatcherListener();
|
||||
LogUtils.d(TAG, "all listener init complete | 监听绑定成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 对话框尺寸适配(小米全面屏+软键盘优化,避免输入框被遮挡)
|
||||
*/
|
||||
private void adjustDialogSize() {
|
||||
Window window = getWindow();
|
||||
if (window != null) {
|
||||
WindowManager.LayoutParams lp = window.getAttributes();
|
||||
// 宽度占屏幕80%,高度自适应(适配不同屏幕尺寸)
|
||||
lp.width = (int) (getContext().getResources().getDisplayMetrics().widthPixels * 0.8);
|
||||
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
|
||||
// 软键盘适配:小米虚拟导航栏兼容,避免输入框被遮挡
|
||||
window.setAttributes(lp);
|
||||
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN
|
||||
| WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
|
||||
LogUtils.d(TAG, "dialog size adjust complete | 适配全面屏+软键盘");
|
||||
}
|
||||
}
|
||||
|
||||
// ====================== 监听子方法(细分类型,逻辑清晰) ======================
|
||||
/**
|
||||
* 输入框文本监听(RGB+颜色值,传入触发ID避免循环同步)
|
||||
*/
|
||||
private void initTextWatcherListener() {
|
||||
// RGB输入框监听(复用方法,减少冗余)
|
||||
setEditTextWatcher(etR, R.id.et_r);
|
||||
setEditTextWatcher(etG, R.id.et_g);
|
||||
setEditTextWatcher(etB, R.id.et_b);
|
||||
|
||||
// 颜色值输入框监听(支持#RRGGBB/#AARRGGBB格式)
|
||||
etColorValue.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
// 关键:判断非应用自身更新,才执行解析(避免循环回调)
|
||||
if (!isAppSelfUpdatingColor) {
|
||||
parseColorFromStr(s.toString().trim(), R.id.et_color_value);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ====================== 透明度进度条监听实现(核心新增) ======================
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
// 仅处理用户手动拖动进度条(避免应用自身更新时触发)
|
||||
if (fromUser && !isAppSelfUpdatingColor) {
|
||||
updateAlphaBySeekBar(progress);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {}
|
||||
|
||||
/**
|
||||
* 拖动透明度进度条更新颜色(核心新增逻辑)
|
||||
*/
|
||||
private synchronized void updateAlphaBySeekBar(int alphaPercent) {
|
||||
if (!isAppSelfUpdatingColor) {
|
||||
isAppSelfUpdatingColor = true; // 标记为应用自身更新
|
||||
try {
|
||||
// 更新实时透明度(百分比+0-255值)
|
||||
mCurrentAlphaPercent = alphaPercent;
|
||||
mCurrentAlpha = percent2Alpha(alphaPercent);
|
||||
// 重新计算最终颜色(基于当前亮度+新透明度)
|
||||
calculateBrightnessAndUpdate();
|
||||
// 同步所有控件
|
||||
updateAllViews();
|
||||
LogUtils.d(TAG, "update alpha by seekbar | 透明度:" + mCurrentAlphaPercent + "%");
|
||||
} finally {
|
||||
// 直接释放标记,避免卡顿
|
||||
isAppSelfUpdatingColor = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ====================== 颜色核心逻辑(新增透明度参数,全功能兼容) ======================
|
||||
/**
|
||||
* 核心计算:基于原始RGB+当前亮度+当前透明度,计算实时RGB+最终颜色
|
||||
* 逻辑:亮度百分比→调节系数→原始RGB×系数→限制0-255→拼接透明度→最终颜色
|
||||
*/
|
||||
private void calculateBrightnessAndUpdate() {
|
||||
// 亮度百分比转调节系数(10%→0.1,100%→1.0,200%→2.0)
|
||||
float brightnessFactor = mCurrentBrightnessPercent / 100.0f;
|
||||
|
||||
// RGB三个分量同时调节(基于原始基准值,避免叠加失真),限制0-255
|
||||
mCurrentR = Math.min(Math.max(Math.round(mOriginalR * brightnessFactor), 0), MAX_RGB_VALUE);
|
||||
mCurrentG = Math.min(Math.max(Math.round(mOriginalG * brightnessFactor), 0), MAX_RGB_VALUE);
|
||||
mCurrentB = Math.min(Math.max(Math.round(mOriginalB * brightnessFactor), 0), MAX_RGB_VALUE);
|
||||
|
||||
// 拼接「实时透明度」+「实时RGB」,得到最终颜色(0xAARRGGBB)
|
||||
mCurrentColor = Color.argb(mCurrentAlpha, mCurrentR, mCurrentG, mCurrentB);
|
||||
}
|
||||
|
||||
/**
|
||||
* 亮度减少(每次减5%,最低10%,防止过暗)
|
||||
*/
|
||||
private void decreaseBrightness() {
|
||||
changeBrightness(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 亮度增加(每次加5%,最高200%,防止过曝)
|
||||
*/
|
||||
private void increaseBrightness() {
|
||||
changeBrightness(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 亮度调节核心方法(统一逻辑,加并发控制,同步所有控件)
|
||||
*/
|
||||
private synchronized void changeBrightness(boolean isIncrease) {
|
||||
// 关键:判断非应用自身更新,才执行调节(避免重复触发/循环)
|
||||
if (!isAppSelfUpdatingColor) {
|
||||
isAppSelfUpdatingColor = true; // 标记为应用自身更新
|
||||
try {
|
||||
if (isIncrease) {
|
||||
if (mCurrentBrightnessPercent >= MAX_BRIGHTNESS) return; // 达到最大值,不处理
|
||||
mCurrentBrightnessPercent += BRIGHTNESS_STEP; // 增加步长
|
||||
} else {
|
||||
if (mCurrentBrightnessPercent <= MIN_BRIGHTNESS) return; // 达到最小值,不处理
|
||||
mCurrentBrightnessPercent -= BRIGHTNESS_STEP; // 减少步长
|
||||
}
|
||||
// 计算亮度调节后的实时RGB+最终颜色(含当前透明度)
|
||||
calculateBrightnessAndUpdate();
|
||||
// 同步所有控件
|
||||
updateAllViews();
|
||||
LogUtils.d(TAG, (isIncrease ? "increase" : "decrease") + " brightness | "
|
||||
+ "亮度:" + mCurrentBrightnessPercent + "% | 实时RGB:" + mCurrentR + "," + mCurrentG + "," + mCurrentB);
|
||||
} finally {
|
||||
// 直接释放标记,避免卡顿
|
||||
isAppSelfUpdatingColor = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析颜色字符串(支持#RRGGBB/#AARRGGBB,容错处理,更新原始基准值+实时值)
|
||||
* 新增:解析颜色的透明度,同步更新透明度进度条
|
||||
*/
|
||||
private void parseColorFromStr(String colorStr, int triggerViewId) {
|
||||
// 关键:判断非应用自身更新,才执行解析(避免循环回调)
|
||||
if (!isAppSelfUpdatingColor) {
|
||||
isAppSelfUpdatingColor = true; // 标记为应用自身更新
|
||||
try {
|
||||
if (TextUtils.isEmpty(colorStr)) return;
|
||||
|
||||
// 补全#前缀(兼容用户输入习惯,如直接输AARRGGBB)
|
||||
if (!colorStr.startsWith("#")) {
|
||||
colorStr = "#" + colorStr;
|
||||
}
|
||||
|
||||
// 格式校验(仅支持6位RRGGBB/8位AARRGGBB,避免非法格式)
|
||||
if (colorStr.length() != 7 && colorStr.length() != 9) {
|
||||
LogUtils.e(TAG, "parse color failed | 格式错误(需#RRGGBB/#AARRGGBB),输入:" + colorStr);
|
||||
return;
|
||||
}
|
||||
|
||||
// 解析颜色(系统API,安全可靠)
|
||||
int parsedColor = Color.parseColor(colorStr);
|
||||
|
||||
// 更新原始基准值(用户输入颜色,重置基准)
|
||||
// 透明度:解析颜色的alpha(0-255)转百分比(0-100%)
|
||||
mOriginalAlpha = Color.alpha(parsedColor);
|
||||
mOriginalAlphaPercent = alpha2Percent(mOriginalAlpha);
|
||||
// RGB:解析颜色的RGB分量
|
||||
mOriginalR = Color.red(parsedColor);
|
||||
mOriginalG = Color.green(parsedColor);
|
||||
mOriginalB = Color.blue(parsedColor);
|
||||
// 更新实时值(原始值=实时值,无调节)
|
||||
mCurrentAlpha = mOriginalAlpha;
|
||||
mCurrentAlphaPercent = mOriginalAlphaPercent;
|
||||
mCurrentR = mOriginalR;
|
||||
mCurrentG = mOriginalG;
|
||||
mCurrentB = mOriginalB;
|
||||
// 重置亮度为100%
|
||||
mCurrentBrightnessPercent = DEFAULT_BRIGHTNESS;
|
||||
mCurrentColor = parsedColor;
|
||||
|
||||
// 同步所有控件
|
||||
updateAllViews();
|
||||
LogUtils.d(TAG, "parse color success | 解析颜色:" + String.format("#%08X", parsedColor)
|
||||
+ " | 透明度:" + mCurrentAlphaPercent + "% | 重置亮度:" + DEFAULT_BRIGHTNESS + "%");
|
||||
} catch (IllegalArgumentException e) {
|
||||
LogUtils.e(TAG, "parse color failed | 非法颜色格式,输入:" + colorStr, e);
|
||||
} finally {
|
||||
// 直接释放标记,避免卡顿
|
||||
isAppSelfUpdatingColor = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过RGB输入框更新颜色(用户输入后,更新原始基准值+实时值,重置亮度为100%)
|
||||
* 新增:透明度基准值保持不变,仅更新RGB
|
||||
*/
|
||||
private synchronized void updateColorByRGB(int triggerViewId) {
|
||||
// 关键:判断非应用自身更新,才执行更新(避免循环回调)
|
||||
if (!isAppSelfUpdatingColor) {
|
||||
isAppSelfUpdatingColor = true; // 标记为应用自身更新
|
||||
try {
|
||||
// 解析用户输入的RGB值(限制0-255,非法输入设为0)
|
||||
int inputR = parseInputValue(etR.getText().toString());
|
||||
int inputG = parseInputValue(etG.getText().toString());
|
||||
int inputB = parseInputValue(etB.getText().toString());
|
||||
|
||||
// 更新原始基准值(用户手动输入,作为新的调节基准)
|
||||
mOriginalR = inputR;
|
||||
mOriginalG = inputG;
|
||||
mOriginalB = inputB;
|
||||
// 更新实时值(输入值=实时值,无亮度调节)
|
||||
mCurrentR = inputR;
|
||||
mCurrentG = inputG;
|
||||
mCurrentB = inputB;
|
||||
// 重置亮度为100%(透明度保持当前值不变)
|
||||
mCurrentBrightnessPercent = DEFAULT_BRIGHTNESS;
|
||||
// 计算最终颜色(无亮度调节,拼接当前透明度)
|
||||
mCurrentColor = Color.argb(mCurrentAlpha, mCurrentR, mCurrentG, mCurrentB);
|
||||
|
||||
// 同步所有控件
|
||||
updateAllViews();
|
||||
LogUtils.d(TAG, "update color by RGB | 新原始RGB:" + mOriginalR + "," + mOriginalG + "," + mOriginalB
|
||||
+ " | 透明度:" + mCurrentAlphaPercent + "% | 重置亮度:" + DEFAULT_BRIGHTNESS + "%");
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "update color by RGB failed", e);
|
||||
} finally {
|
||||
// 直接释放标记,避免卡顿
|
||||
isAppSelfUpdatingColor = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 核心同步:更新所有控件显示(新增透明度控件同步,统一方法)
|
||||
*/
|
||||
private void updateAllViews() {
|
||||
// 1. 同步颜色预览(显示最终颜色,含透明度+亮度)
|
||||
ivColorPicker.setBackgroundColor(mCurrentColor);
|
||||
|
||||
// 2. 同步RGB输入框(显示实时调节值)
|
||||
etR.setText(String.valueOf(mCurrentR));
|
||||
etG.setText(String.valueOf(mCurrentG));
|
||||
etB.setText(String.valueOf(mCurrentB));
|
||||
|
||||
// 3. 同步颜色值输入框(显示最终颜色,含透明度,格式#AARRGGBB)
|
||||
etColorValue.setText(String.format("#%08X", mCurrentColor));
|
||||
|
||||
// 4. 同步透明度控件(进度条+文本,显示实时透明度)
|
||||
sbAlpha.setProgress(mCurrentAlphaPercent);
|
||||
tvAlphaValue.setText(mCurrentAlphaPercent + "%");
|
||||
|
||||
// 5. 同步亮度控件(数值+按钮状态)
|
||||
tvBrightnessValue.setText(mCurrentBrightnessPercent + "%");
|
||||
updateBrightnessBtnStatus();
|
||||
|
||||
LogUtils.d(TAG, "sync all views complete | 最终颜色:" + String.format("#%08X", mCurrentColor)
|
||||
+ " | 实时RGB:" + mCurrentR + "," + mCurrentG + "," + mCurrentB
|
||||
+ " | 透明度:" + mCurrentAlphaPercent + "% | 亮度:" + mCurrentBrightnessPercent + "%");
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新亮度按钮状态(边界值禁用,提升交互体验)
|
||||
*/
|
||||
private void updateBrightnessBtnStatus() {
|
||||
// 亮度≤10%:禁用减号(文字变浅灰);≥200%:禁用加号(文字变浅灰)
|
||||
boolean canMinus = mCurrentBrightnessPercent > MIN_BRIGHTNESS;
|
||||
boolean canPlus = mCurrentBrightnessPercent < MAX_BRIGHTNESS;
|
||||
|
||||
tvBrightnessMinus.setEnabled(canMinus);
|
||||
tvBrightnessPlus.setEnabled(canPlus);
|
||||
tvBrightnessMinus.setTextColor(canMinus ? Color.BLACK : Color.parseColor("#CCCCCC"));
|
||||
tvBrightnessPlus.setTextColor(canPlus ? Color.BLACK : Color.parseColor("#CCCCCC"));
|
||||
}
|
||||
|
||||
// ====================== 工具方法(新增透明度转换工具,通用复用) ======================
|
||||
/**
|
||||
* 透明度:0-255 → 0-100%(颜色计算值转用户直观百分比)
|
||||
*/
|
||||
private int alpha2Percent(int alpha) {
|
||||
return Math.round((float) alpha / MAX_RGB_VALUE * MAX_ALPHA_PERCENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* 透明度:0-100% → 0-255(用户操作百分比转颜色计算值)
|
||||
*/
|
||||
private int percent2Alpha(int percent) {
|
||||
return Math.round((float) percent / MAX_ALPHA_PERCENT * MAX_RGB_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析输入值(限制0-255,非法输入返回0,容错处理)
|
||||
*/
|
||||
private int parseInputValue(String input) {
|
||||
if (TextUtils.isEmpty(input)) return 0;
|
||||
try {
|
||||
int value = Integer.parseInt(input);
|
||||
return Math.min(Math.max(value, 0), MAX_RGB_VALUE); // 限制范围,避免溢出
|
||||
} catch (NumberFormatException e) {
|
||||
LogUtils.e(TAG, "parse input failed | 非法数字,输入:" + input, e);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* RGB输入框监听复用(减少冗余代码,统一逻辑)
|
||||
*/
|
||||
private void setEditTextWatcher(EditText editText, final int viewId) {
|
||||
editText.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
// 关键:判断非应用自身更新,才执行更新(避免循环回调)
|
||||
if (!isAppSelfUpdatingColor) {
|
||||
updateColorByRGB(viewId); // 输入变化后更新颜色
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* dp转px(适配小米不同分辨率,避免尺寸错乱,通用工具)
|
||||
*/
|
||||
private int dp2px(float dp) {
|
||||
return (int) (dp * getContext().getResources().getDisplayMetrics().density + 0.5f);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示系统颜色选择器(兼容API29-30,无高版本依赖,小米机型适配)
|
||||
* 核心调整:新增「水平滚动容器+颜色排列容器」二级结构,内置圆形按钮,无额外drawable依赖
|
||||
*/
|
||||
private void showSystemColorPicker() {
|
||||
LogUtils.d(TAG, "show system color picker | 兼容小米API29-30,支持横向滚动");
|
||||
final android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(getContext());
|
||||
builder.setTitle("选择基础颜色");
|
||||
|
||||
// 50种常用颜色:按「红→橙→黄→绿→青→蓝→紫→粉→棕→灰→黑白」彩虹光谱顺序排列
|
||||
final int[] systemColors = {
|
||||
// 红色系(6种:深红→大红→浅红→玫红→暗红→橘红)
|
||||
0xFFCC0000, 0xFFFF0000, 0xFFFF6666, 0xFFFF1493, 0xFF8B0000, 0xFFFF4500,
|
||||
// 橙色系(5种:深橙→橙→浅橙→橙黄→橘橙)
|
||||
0xFFCC6600, 0xFFFF8800, 0xFFFFAA33, 0xFFFFBB00, 0xFFF5A623,
|
||||
// 黄色系(5种:深黄→黄→浅黄→鹅黄→金黄)
|
||||
0xFFCCCC00, 0xFFFFFF00, 0xFFFFEE99, 0xFFFFFACD, 0xFFFFD700,
|
||||
// 绿色系(7种:深绿→绿→浅绿→草绿→薄荷绿→翠绿→墨绿)
|
||||
0xFF006600, 0xFF00FF00, 0xFF99FF99, 0xFF66CC66, 0xFF98FB98, 0xFF00FF99, 0xFF003300,
|
||||
// 青色系(5种:深青→青→浅青→蓝绿→青绿)
|
||||
0xFF006666, 0xFF00FFFF, 0xFF99FFFF, 0xFF00CCCC, 0xFF40E0D0,
|
||||
// 蓝色系(8种:深蓝→藏蓝→蓝→浅蓝→天蓝→宝蓝→湖蓝→靛蓝)
|
||||
0xFF0000CC, 0xFF00008B, 0xFF0000FF, 0xFF6666FF, 0xFF87CEEB, 0xFF0066FF, 0xFF0099FF, 0xFF4B0082,
|
||||
// 紫色系(6种:深紫→紫→浅紫→紫罗兰→紫红→蓝紫)
|
||||
0xFF660099, 0xFF8800FF, 0xFFAA99FF, 0xFF9370DB, 0xFFCBC3E3, 0xFF8A2BE2,
|
||||
// 粉色系(5种:深粉→粉→浅粉→嫩粉→桃粉)
|
||||
0xFFFF00FF, 0xFFFF99CC, 0xFFFFCCDD, 0xFFFFB6C1, 0xFFFFA5A5,
|
||||
// 棕色系(4种:深棕→棕→浅棕→棕黄)
|
||||
0xFF8B4513, 0xFFA0522D, 0xFFD2B48C, 0xFFCD853F,
|
||||
// 灰色系(6种:深灰→灰→浅灰→银灰→淡灰→浅银灰)
|
||||
0xFF333333, 0xFF666666, 0xFF888888, 0xFFAAAAAA, 0xFFCCCCCC, 0xFFE6E6E6,
|
||||
// 黑白系(3种:黑→白→米白)
|
||||
0xFF000000, 0xFFFFFFFF, 0xFFFFFAFA
|
||||
};
|
||||
|
||||
// 1. 第一级:水平滚动容器
|
||||
HorizontalScrollView horizontalScrollView = new HorizontalScrollView(getContext());
|
||||
horizontalScrollView.setHorizontalScrollBarEnabled(true);
|
||||
horizontalScrollView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
|
||||
horizontalScrollView.setPadding(dp2px(5), dp2px(5), dp2px(5), dp2px(5));
|
||||
|
||||
// 2. 第二级:颜色排列容器(横向)
|
||||
LinearLayout colorLayout = new LinearLayout(getContext());
|
||||
colorLayout.setOrientation(LinearLayout.HORIZONTAL);
|
||||
colorLayout.setGravity(Gravity.CENTER_VERTICAL);
|
||||
colorLayout.setPadding(dp2px(10), dp2px(10), dp2px(10), dp2px(10));
|
||||
|
||||
// 3. 循环添加颜色按钮(内置圆形效果,无额外依赖)
|
||||
for (int i = 0; i < systemColors.length; i++) {
|
||||
final int color = systemColors[i];
|
||||
ImageView colorBtn = new ImageView(getContext());
|
||||
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(dp2px(40), dp2px(40));
|
||||
if (i != systemColors.length - 1) {
|
||||
lp.setMargins(0, 0, dp2px(10), 0); // 按钮间距
|
||||
}
|
||||
colorBtn.setLayoutParams(lp);
|
||||
|
||||
// 核心:内置圆形背景(白色边框+圆形形状,无需drawable文件)
|
||||
GradientDrawable circleBg = new GradientDrawable();
|
||||
circleBg.setShape(GradientDrawable.OVAL); // 圆形
|
||||
circleBg.setColor(color); // 按钮颜色
|
||||
circleBg.setStroke(dp2px(2), Color.WHITE); // 白色边框(2dp宽,区分颜色)
|
||||
colorBtn.setBackground(circleBg); // 设置圆形背景
|
||||
|
||||
colorBtn.setClickable(true);
|
||||
colorBtn.setFocusable(true);
|
||||
|
||||
// 点击事件(逻辑不变)
|
||||
colorBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (!isAppSelfUpdatingColor) {
|
||||
isAppSelfUpdatingColor = true;
|
||||
try {
|
||||
mOriginalAlpha = Color.alpha(color);
|
||||
mOriginalAlphaPercent = alpha2Percent(mOriginalAlpha);
|
||||
mOriginalR = Color.red(color);
|
||||
mOriginalG = Color.green(color);
|
||||
mOriginalB = Color.blue(color);
|
||||
mCurrentAlpha = mOriginalAlpha;
|
||||
mCurrentAlphaPercent = mOriginalAlphaPercent;
|
||||
mCurrentR = mOriginalR;
|
||||
mCurrentG = mOriginalG;
|
||||
mCurrentB = mOriginalB;
|
||||
mCurrentBrightnessPercent = DEFAULT_BRIGHTNESS;
|
||||
mCurrentColor = color;
|
||||
updateAllViews();
|
||||
builder.create().dismiss();
|
||||
LogUtils.d(TAG, "select system color | 选择颜色:" + String.format("#%08X", color)
|
||||
+ " | 透明度:" + mCurrentAlphaPercent + "%");
|
||||
} finally {
|
||||
isAppSelfUpdatingColor = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
colorLayout.addView(colorBtn);
|
||||
}
|
||||
|
||||
// 层级嵌套(滚动容器→颜色容器)
|
||||
horizontalScrollView.addView(colorLayout);
|
||||
builder.setView(horizontalScrollView).setNegativeButton("关闭", null).show();
|
||||
}
|
||||
|
||||
// ====================== 点击事件实现(统一处理,逻辑清晰) ======================
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
//ToastUtils.show("onClick");
|
||||
int id = v.getId();
|
||||
// 关键:所有点击事件均加判断(避免并发冲突/重复触发)
|
||||
if (!isAppSelfUpdatingColor) {
|
||||
if (id == R.id.iv_color_picker) {
|
||||
showSystemColorPicker(); // 打开系统颜色选择器
|
||||
} if (id == R.id.iv_color_scaler) {
|
||||
//ToastUtils.show("iv_color_scale");
|
||||
openColorScalerDialog(mCurrentColor); // 打开系统颜色选择器
|
||||
} else if (id == R.id.tv_confirm) {
|
||||
mListener.onColorSelected(mCurrentColor); // 确认选择,回调颜色
|
||||
LogUtils.d(TAG, "confirm color | 回调颜色:" + String.format("#%08X", mCurrentColor));
|
||||
dismiss();
|
||||
} else if (id == R.id.tv_cancel) {
|
||||
dismiss(); // 取消,关闭对话框
|
||||
LogUtils.d(TAG, "cancel color | 取消选择,关闭对话框");
|
||||
} else if (id == R.id.tv_brightness_minus) {
|
||||
decreaseBrightness(); // 减少亮度
|
||||
} else if (id == R.id.tv_brightness_plus) {
|
||||
increaseBrightness(); // 增加亮度
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void openColorScalerDialog(int nColor) {
|
||||
//ToastUtils.show("openColorPickerDialog");
|
||||
final ColorScalerDialog dlg = new ColorScalerDialog(getContext(), nColor);
|
||||
dlg.setOnColorChangedListener(new com.a4455jkjh.colorpicker.view.OnColorChangedListener() {
|
||||
|
||||
@Override
|
||||
public void beforeColorChanged() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onColorChanged(int color) {
|
||||
dlg.currentColorScalerDialogColor = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterColorChanged() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
dlg.show();
|
||||
}
|
||||
|
||||
class ColorScalerDialog extends ColorPickerDialog {
|
||||
public int currentColorScalerDialogColor = 0;
|
||||
public ColorScalerDialog(Context context, int p) {
|
||||
super(context, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dismiss() {
|
||||
super.dismiss();
|
||||
int color = currentColorScalerDialogColor;
|
||||
ToastUtils.show(String.format("dismiss color %d", color));
|
||||
if (!isAppSelfUpdatingColor) {
|
||||
isAppSelfUpdatingColor = true;
|
||||
try {
|
||||
mOriginalAlpha = Color.alpha(color);
|
||||
mOriginalAlphaPercent = alpha2Percent(mOriginalAlpha);
|
||||
mOriginalR = Color.red(color);
|
||||
mOriginalG = Color.green(color);
|
||||
mOriginalB = Color.blue(color);
|
||||
mCurrentAlpha = mOriginalAlpha;
|
||||
mCurrentAlphaPercent = mOriginalAlphaPercent;
|
||||
mCurrentR = mOriginalR;
|
||||
mCurrentG = mOriginalG;
|
||||
mCurrentB = mOriginalB;
|
||||
mCurrentBrightnessPercent = DEFAULT_BRIGHTNESS;
|
||||
mCurrentColor = color;
|
||||
updateAllViews();
|
||||
LogUtils.d(TAG, "select system color | 选择颜色:" + String.format("#%08X", color)
|
||||
+ " | 透明度:" + mCurrentAlphaPercent + "%");
|
||||
} finally {
|
||||
isAppSelfUpdatingColor = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
7
powerbell/src/main/res/drawable/btn_bg_gray.xml
Normal file
7
powerbell/src/main/res/drawable/btn_bg_gray.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="@android:color/darker_gray" />
|
||||
<corners android:radius="6dp" />
|
||||
</shape>
|
||||
|
||||
7
powerbell/src/main/res/drawable/btn_bg_primary.xml
Normal file
7
powerbell/src/main/res/drawable/btn_bg_primary.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="@android:color/holo_blue_light" />
|
||||
<corners android:radius="6dp" />
|
||||
</shape>
|
||||
|
||||
20
powerbell/src/main/res/drawable/btn_brightness_bg.xml
Normal file
20
powerbell/src/main/res/drawable/btn_brightness_bg.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<!-- 按压状态:浅灰色背景 -->
|
||||
<item android:state_pressed="true">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#E0E0E0" /> <!-- 按压深色 -->
|
||||
<corners android:radius="8dp" /> <!-- 圆角适配小米UI风格 -->
|
||||
<stroke android:width="1dp" android:color="#CCCCCC" /> <!-- 边框 -->
|
||||
</shape>
|
||||
</item>
|
||||
<!-- 正常状态:白色背景 -->
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#FFFFFF" /> <!-- 正常白色 -->
|
||||
<corners android:radius="8dp" />
|
||||
<stroke android:width="1dp" android:color="#CCCCCC" />
|
||||
</shape>
|
||||
</item>
|
||||
</selector>
|
||||
|
||||
18
powerbell/src/main/res/drawable/btn_cancel_bg.xml
Normal file
18
powerbell/src/main/res/drawable/btn_cancel_bg.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<!-- 按压状态:深灰色背景 -->
|
||||
<item android:state_pressed="true">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#D0D0D0" />
|
||||
<corners android:radius="8dp" /> <!-- 与亮度按钮圆角一致,统一风格 -->
|
||||
</shape>
|
||||
</item>
|
||||
<!-- 正常状态:浅灰色背景 -->
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#F0F0F0" />
|
||||
<corners android:radius="8dp" />
|
||||
</shape>
|
||||
</item>
|
||||
</selector>
|
||||
|
||||
20
powerbell/src/main/res/drawable/btn_common.xml
Normal file
20
powerbell/src/main/res/drawable/btn_common.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<!-- 按压状态:深灰色 -->
|
||||
<item android:state_pressed="true">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#CCCCCC" /> <!-- 按压时颜色 -->
|
||||
<corners android:radius="8dp" /> <!-- 圆角(可按需调整) -->
|
||||
<stroke android:width="1dp" android:color="#EEEEEE" /> <!-- 边框(可选,不加可删除) -->
|
||||
</shape>
|
||||
</item>
|
||||
<!-- 正常状态:浅灰色 -->
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#F5F5F5" /> <!-- 正常时颜色 -->
|
||||
<corners android:radius="8dp" /> <!-- 圆角(和按压状态一致) -->
|
||||
<stroke android:width="1dp" android:color="#EEEEEE" /> <!-- 边框(可选) -->
|
||||
</shape>
|
||||
</item>
|
||||
</selector>
|
||||
|
||||
18
powerbell/src/main/res/drawable/btn_confirm_bg.xml
Normal file
18
powerbell/src/main/res/drawable/btn_confirm_bg.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<!-- 按压状态:加深深色背景 -->
|
||||
<item android:state_pressed="true">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#2D7CFF" /> <!-- 按压深蓝 -->
|
||||
<corners android:radius="8dp" />
|
||||
</shape>
|
||||
</item>
|
||||
<!-- 正常状态:主色背景(可改为项目主题色) -->
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#4096FF" /> <!-- 正常浅蓝,适配小米系统UI -->
|
||||
<corners android:radius="8dp" />
|
||||
</shape>
|
||||
</item>
|
||||
</selector>
|
||||
|
||||
BIN
powerbell/src/main/res/drawable/color_scale_logo.png
Normal file
BIN
powerbell/src/main/res/drawable/color_scale_logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 299 KiB |
17
powerbell/src/main/res/drawable/dialog_bg_radius.xml
Normal file
17
powerbell/src/main/res/drawable/dialog_bg_radius.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<!-- 背景色:白色 -->
|
||||
<solid android:color="@android:color/white" />
|
||||
<!-- 圆角:12dp(适配小米机型圆角无锯齿) -->
|
||||
<corners android:radius="12dp" />
|
||||
<!-- 边框:浅灰色细边框(避免弹窗边缘模糊) -->
|
||||
<stroke
|
||||
android:width="1dp"
|
||||
android:color="@android:color/darker_gray" />
|
||||
<!-- 内边距:轻微留白,避免内容贴边 -->
|
||||
<padding
|
||||
android:bottom="5dp"
|
||||
android:top="5dp" />
|
||||
</shape>
|
||||
|
||||
10
powerbell/src/main/res/drawable/edittext_bg.xml
Normal file
10
powerbell/src/main/res/drawable/edittext_bg.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="@android:color/white" />
|
||||
<corners android:radius="6dp" />
|
||||
<stroke
|
||||
android:width="1dp"
|
||||
android:color="@android:color/darker_gray" />
|
||||
</shape>
|
||||
|
||||
20
powerbell/src/main/res/drawable/seekbar_progress.xml
Normal file
20
powerbell/src/main/res/drawable/seekbar_progress.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<!-- 进度条未完成部分:浅灰色 -->
|
||||
<item android:id="@android:id/background">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@android:color/darker_gray" />
|
||||
<corners android:radius="10dp" />
|
||||
</shape>
|
||||
</item>
|
||||
<!-- 进度条已完成部分:系统蓝色(无需额外定义颜色) -->
|
||||
<item android:id="@android:id/progress">
|
||||
<clip>
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@android:color/holo_blue_light" />
|
||||
<corners android:radius="10dp" />
|
||||
</shape>
|
||||
</clip>
|
||||
</item>
|
||||
</layer-list>
|
||||
|
||||
15
powerbell/src/main/res/drawable/seekbar_thumb.xml
Normal file
15
powerbell/src/main/res/drawable/seekbar_thumb.xml
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval">
|
||||
<!-- 滑块颜色:系统蓝色 -->
|
||||
<solid android:color="@android:color/holo_blue_light" />
|
||||
<!-- 滑块大小:20dp(适配小米机型触摸区域) -->
|
||||
<size
|
||||
android:width="20dp"
|
||||
android:height="20dp" />
|
||||
<!-- 白色边框:区分滑块与进度条 -->
|
||||
<stroke
|
||||
android:width="2dp"
|
||||
android:color="@android:color/white" />
|
||||
</shape>
|
||||
|
||||
@@ -117,6 +117,15 @@
|
||||
android:layout_margin="5dp"
|
||||
android:id="@+id/activitybackgroundpictureAButton7"/>
|
||||
|
||||
<cc.winboll.studio.libaes.views.AButton
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="36dp"
|
||||
android:text="[©]"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_margin="5dp"
|
||||
android:id="@+id/activitybackgroundsettingsAButton1"
|
||||
android:onClick="onColorPaletteDialog"/>
|
||||
|
||||
<cc.winboll.studio.libaes.views.AButton
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="36dp"
|
||||
|
||||
198
powerbell/src/main/res/layout/dialog_color_palette.xml
Normal file
198
powerbell/src/main/res/layout/dialog_color_palette.xml
Normal file
@@ -0,0 +1,198 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="20dp"
|
||||
android:background="#FFFFFFFF">
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_color_picker"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
android:background="#FF0000"
|
||||
android:clickable="true"
|
||||
android:focusable="true"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_color_scaler"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:src="@drawable/color_scale_logo"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_marginBottom="15dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="RGB:"
|
||||
android:textSize="16sp"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/et_r"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:hint="R"
|
||||
android:inputType="number"
|
||||
android:gravity="center"
|
||||
android:maxLength="3"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/et_g"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:hint="G"
|
||||
android:inputType="number"
|
||||
android:gravity="center"
|
||||
android:maxLength="3"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/et_b"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:hint="B"
|
||||
android:inputType="number"
|
||||
android:gravity="center"
|
||||
android:maxLength="3"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/et_color_value"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"
|
||||
android:hint="#AARRGGBB"
|
||||
android:inputType="text"
|
||||
android:gravity="center"
|
||||
android:maxLength="9"
|
||||
android:layout_marginBottom="15dp"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:layout_marginBottom="15dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_marginBottom="5dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="透明度:"
|
||||
android:textSize="16sp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_alpha_value"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="100%"
|
||||
android:textSize="16sp"
|
||||
android:layout_marginLeft="10dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/sb_alpha"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:max="100"
|
||||
android:progress="100"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_horizontal"
|
||||
android:layout_marginBottom="20dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_brightness_minus"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:text="-"
|
||||
android:textSize="20sp"
|
||||
android:gravity="center"
|
||||
android:background="@drawable/btn_common"
|
||||
android:clickable="true"
|
||||
android:focusable="true"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_brightness_value"
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="40dp"
|
||||
android:text="100%"
|
||||
android:textSize="16sp"
|
||||
android:gravity="center"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_brightness_plus"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:text="+"
|
||||
android:textSize="20sp"
|
||||
android:gravity="center"
|
||||
android:background="@drawable/btn_common"
|
||||
android:clickable="true"
|
||||
android:focusable="true"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_cancel"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="45dp"
|
||||
android:text="取消"
|
||||
android:textSize="16sp"
|
||||
android:gravity="center"
|
||||
android:background="@drawable/btn_common"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:layout_marginRight="20dp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_confirm"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="45dp"
|
||||
android:text="确认"
|
||||
android:textSize="16sp"
|
||||
android:gravity="center"
|
||||
android:background="@drawable/btn_common"
|
||||
android:clickable="true"
|
||||
android:focusable="true"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
9
powerbell/src/main/res/layout/layout_color_grid.xml
Normal file
9
powerbell/src/main/res/layout/layout_color_grid.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center"
|
||||
android:padding="10dp">
|
||||
</LinearLayout>
|
||||
|
||||
@@ -58,9 +58,73 @@
|
||||
<color name="colorUsege">@color/colorRed</color>
|
||||
<color name="colorCurrent">@color/colorBlue</color>
|
||||
<color name="colorCharge">@color/colorYellow</color>
|
||||
|
||||
|
||||
<!--CustomSlideToUnlockView控件配置-->
|
||||
<color name="colorCustomSlideToUnlockViewWhite">#FFFFFFFF</color>
|
||||
|
||||
<!---->
|
||||
|
||||
<!-- ============== 基础黑白(必含,适配文字/背景) ============== -->
|
||||
<color name="white">#FFFFFF</color> <!-- 纯白色(文字/背景) -->
|
||||
<color name="black">#000000</color> <!-- 近黑色(重要文字) -->
|
||||
|
||||
<!-- ============== 基础色系(按钮/强调色常用) ============== -->
|
||||
<!-- 蓝色系(常用:确认/链接/主题色) -->
|
||||
<color name="blue_light">#4A90E2</color> <!-- 浅蓝(次要按钮) -->
|
||||
<color name="blue_normal">#2196F3</color> <!-- 标准蓝(主题/确认按钮) -->
|
||||
<color name="blue_dark">#1976D2</color> <!-- 深蓝(按压态/重要强调) -->
|
||||
<!-- 绿色系(常用:成功/完成/安全提示) -->
|
||||
<color name="green_light">#66BB6A</color> <!-- 浅绿(次要成功态) -->
|
||||
<color name="green_normal">#4CAF50</color> <!-- 标准绿(成功按钮/提示) -->
|
||||
<color name="green_dark">#388E3C</color> <!-- 深绿(按压态/重要成功) -->
|
||||
<!-- 红色系(常用:错误/警告/删除按钮) -->
|
||||
<color name="red_light">#EF5350</color> <!-- 浅红(次要错误提示) -->
|
||||
<color name="red_normal">#F44336</color> <!-- 标准红(删除/错误按钮) -->
|
||||
<color name="red_dark">#D32F2F</color> <!-- 深红(按压态/重要错误) -->
|
||||
<!-- 黄色系(常用:警告/提醒/高亮) -->
|
||||
<color name="yellow_light">#FFF59D</color> <!-- 浅黄(次要提醒) -->
|
||||
<color name="yellow_normal">#FFC107</color> <!-- 标准黄(警告提示/高亮) -->
|
||||
<color name="yellow_dark">#FFA000</color> <!-- 深黄(重要警告) -->
|
||||
<!-- 橙色系(常用:提醒/进度/活力色) -->
|
||||
<color name="orange_normal">#FF9800</color> <!-- 标准橙(提醒按钮/进度) -->
|
||||
<!-- 紫色系(常用:特殊强调/个性按钮) -->
|
||||
<color name="purple_normal">#9C27B0</color> <!-- 标准紫(特殊功能按钮) -->
|
||||
|
||||
<!-- ============== 透明色(遮罩/背景叠加) ============== -->
|
||||
<color name="transparent">#00000000</color> <!-- 全透明 -->
|
||||
<color name="black_transparent_50">#80000000</color> <!-- 50%透明黑(遮罩) -->
|
||||
|
||||
|
||||
|
||||
<!-- 1. 不透明灰色(常用深浅梯度,直接用) -->
|
||||
<color name="gray_100">#F5F5F5</color> <!-- 极浅灰(接近白色,背景用) -->
|
||||
<color name="gray_200">#EEEEEE</color> <!-- 浅灰(卡片/分割线背景) -->
|
||||
<color name="gray_300">#E0E0E0</color> <!-- 中浅灰(边框/次要背景) -->
|
||||
<color name="gray_400">#BDBDBD</color> <!-- 中灰(次要文字/图标) -->
|
||||
<color name="gray_500">#9E9E9E</color> <!-- 标准中灰(常用辅助文字) -->
|
||||
<color name="gray_600">#757575</color> <!-- 中深灰(常规辅助文字) -->
|
||||
<color name="gray_700">#616161</color> <!-- 深灰(重要辅助文字) -->
|
||||
<color name="gray_800">#424242</color> <!-- 极深灰(接近黑色,标题副文本) -->
|
||||
<color name="gray_900">#212121</color> <!-- 近黑色(特殊场景用) -->
|
||||
|
||||
<!-- 2. 半透明灰色(带透明度,遮罩/蒙层用) -->
|
||||
<color name="gray_transparent_30">#4D9E9E9E</color> <!-- 30%透明中灰(A=4D) -->
|
||||
<color name="gray_transparent_50">#809E9E9E</color> <!-- 50%透明中灰(A=80) -->
|
||||
<color name="gray_transparent_70">#B39E9E9E</color> <!-- 70%透明中灰(A=B3) -->
|
||||
|
||||
<color name="gray_light">#EEE</color> <!-- 等价 #EEEEEE(浅灰) -->
|
||||
<color name="gray_mid">#999</color> <!-- 等价 #999999(中灰) -->
|
||||
<color name="gray_dark">#666</color> <!-- 等价 #666666(深灰) -->
|
||||
<color name="gray_black">#333</color> <!-- 等价 #333333(极深灰) -->
|
||||
|
||||
<!-- 50% 透明中灰(弹窗遮罩常用) -->
|
||||
<color name="mask_gray">#809E9E9E</color>
|
||||
<!-- 30% 透明深灰(背景叠加) -->
|
||||
<color name="bg_overlay_gray">#4D424242</color>
|
||||
|
||||
<!-- 1. 常规灰色(按钮默认态,常用中灰) -->
|
||||
<color name="btn_gray_normal">#9E9E9E</color>
|
||||
<!-- 2. 按压深色(按钮点击态,加深一级,提升交互感) -->
|
||||
<color name="btn_gray_pressed">#757575</color>
|
||||
<!-- 3. 禁用灰色(按钮不可点击态,浅灰) -->
|
||||
<color name="btn_gray_disabled">#E0E0E0</color>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -26,4 +26,18 @@
|
||||
<item name="android:textSize">@dimen/text_subtitle_size</item>
|
||||
</style>
|
||||
|
||||
<!-- 自定义调色板对话框样式 -->
|
||||
<style name="CustomDialogStyle" parent="@android:style/Theme.Dialog">
|
||||
<!-- 去除标题栏 -->
|
||||
<item name="android:windowNoTitle">true</item>
|
||||
<!-- 背景透明(避免小米机型弹窗周围黑边) -->
|
||||
<item name="android:windowBackground">@android:color/transparent</item>
|
||||
<!-- 禁止弹窗全屏 -->
|
||||
<item name="android:windowFullscreen">false</item>
|
||||
<!-- 小米机型适配:弹窗大小自适应 -->
|
||||
<item name="android:windowContentOverlay">@null</item>
|
||||
<!-- 禁止触摸外部关闭(可选,避免误触) -->
|
||||
<item name="android:windowCloseOnTouchOutside">false</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user