refactor(libappbase): 颜色赋值统一引用ViewColorTable常量

将libappbase模块内5个Java文件中的硬编码颜色值
(0xFFF5F5F5/Color.GRAY/R.color.white等)统一替换为
ViewColorTable静态常量引用,消除分散的颜色定义,
便于全局统一管理和主题切换。

涉及文件:
- CrashActivity: 2处
- GlobalCrashReportView: 8处
- LogView: 4处
- AboutView: 5处
- LogTagSpinner: 3处
This commit is contained in:
BigPickle
2026-07-21 12:12:16 +08:00
parent 33d832f8df
commit 7f4679a46a
7 changed files with 30 additions and 27 deletions
+2 -2
View File
@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle
#Tue Jul 21 09:07:10 HKT 2026
#Tue Jul 21 12:09:52 HKT 2026
stageCount=1
libraryProject=libappbase
baseVersion=15.21
publishVersion=15.21.0
buildCount=0
buildCount=3
baseBetaVersion=15.21.1
+2 -2
View File
@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle
#Tue Jul 21 09:06:49 HKT 2026
#Tue Jul 21 12:09:52 HKT 2026
stageCount=1
libraryProject=libappbase
baseVersion=15.21
publishVersion=15.21.0
buildCount=0
buildCount=3
baseBetaVersion=15.21.1
@@ -14,6 +14,7 @@ import android.widget.HorizontalScrollView;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import cc.winboll.studio.libappbase.common.ViewColorTable;
public final class CrashActivity extends Activity implements MenuItem.OnMenuItemClickListener {
private static final int MENUITEM_COPY = 0;
@@ -35,13 +36,13 @@ public final class CrashActivity extends Activity implements MenuItem.OnMenuItem
contentView.setFillViewport(true);
HorizontalScrollView hw = new HorizontalScrollView(this);
hw.setBackgroundColor(0xFFF5F5F5);
hw.setBackgroundColor(ViewColorTable.ListItemBgPressedColor);
TextView message = new TextView(this);
final int padding = dp2px(16);
message.setPadding(padding, padding, padding, padding);
message.setText(mLog);
message.setTextColor(0xFF000000);
message.setTextColor(ViewColorTable.TextPrimaryColor);
message.setTextIsSelectable(true);
hw.addView(message);
@@ -2,7 +2,6 @@ package cc.winboll.studio.libappbase;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.util.AttributeSet;
@@ -12,6 +11,7 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toolbar;
import cc.winboll.studio.libappbase.R;
import cc.winboll.studio.libappbase.common.ViewColorTable;
import android.content.res.Resources;
/**
@@ -179,9 +179,9 @@ public class GlobalCrashReportView extends LinearLayout {
// 设置默认配色(使用 debugTextColor 属性)
Resources.Theme theme = mContext.getTheme();
mTitleColor = theme.getResources().getColor(android.R.color.holo_green_dark);
mTitleBackgroundColor = Color.GRAY;
mTitleBackgroundColor = ViewColorTable.SwitchTrackNormalColor;
mTextColor = obtainDebugTextColor(theme);
mTextBackgroundColor = Color.WHITE;
mTextBackgroundColor = ViewColorTable.CardSurfaceColor;
// 加载布局
inflateView();
// 初始化控件样式
@@ -196,11 +196,11 @@ public class GlobalCrashReportView extends LinearLayout {
if (themeResId != 0) {
int[] debugAttrs = new int[] { cc.winboll.studio.libappbase.R.attr.debugTextColor };
TypedArray debugTypedArray = theme.obtainStyledAttributes(themeResId, debugAttrs);
int color = debugTypedArray.getColor(0, Color.GRAY);
int color = debugTypedArray.getColor(0, ViewColorTable.TextSecondaryColor);
debugTypedArray.recycle();
return color;
}
return Color.GRAY;
return ViewColorTable.TextSecondaryColor;
}
/**
@@ -219,16 +219,16 @@ public class GlobalCrashReportView extends LinearLayout {
// 读取自定义属性值(无设置时使用默认值)
mTitleColor = typedArray.getColor(
R.styleable.GlobalCrashActivity_colorTittle,
Color.BLACK
ViewColorTable.TextPrimaryColor
);
mTitleBackgroundColor = typedArray.getColor(
R.styleable.GlobalCrashActivity_colorTittleBackgound, // 注:原拼写错误(Backgound→Background),保持与 attrs.xml 一致
Color.BLACK
ViewColorTable.TextPrimaryColor
);
mTextColor = obtainDebugTextColor(mContext.getTheme());
mTextBackgroundColor = typedArray.getColor(
R.styleable.GlobalCrashActivity_colorTextBackgound, // 注:原拼写错误,保持与 attrs.xml 一致
Color.WHITE
ViewColorTable.CardSurfaceColor
);
// 回收 TypedArray,避免内存泄漏
@@ -28,6 +28,7 @@ import android.widget.ScrollView;
import android.widget.TextView;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.libappbase.R;
import cc.winboll.studio.libappbase.common.ViewColorTable;
import cc.winboll.studio.libappbase.views.HorizontalListView;
import cc.winboll.studio.libappbase.widget.LogTagSpinner;
import java.text.Collator;
@@ -117,7 +118,7 @@ public class LogView extends RelativeLayout {
// 获取Log Level spinner实例
mLogLevelSpinner = findViewById(cc.winboll.studio.libappbase.R.id.viewlogSpinner1);
metTagSearch.setTextColor(mContext.getResources().getColor(R.color.white));
metTagSearch.setTextColor(ViewColorTable.EditTextContentColor);
metTagSearch.addTextChangedListener(new TextWatcher() {
@Override
@@ -250,7 +251,7 @@ public class LogView extends RelativeLayout {
mSelectAllTAGCheckBox.setLayoutParams(layoutParams2);
//mSelectAllTAGCheckBox.setPadding(0,0,0,0);
TypedArray ta1 = mContext.obtainStyledAttributes(new int[] { R.attr.toolbarTextColor });
int toolbarTextColor1 = ta1.getColor(0, mContext.getResources().getColor(R.color.white));
int toolbarTextColor1 = ta1.getColor(0, ViewColorTable.ToolbarTitleTextColor);
ta1.recycle();
mSelectAllTAGCheckBox.setTextColor(toolbarTextColor1);
mSelectAllTAGCheckBox.setOnClickListener(new View.OnClickListener(){
@@ -507,14 +508,14 @@ public class LogView extends RelativeLayout {
holder.tvText.setLayoutParams(layoutParams);
holder.tvText.setPadding(0,0,0,0);
TypedArray ta2 = mContext.obtainStyledAttributes(new int[] { R.attr.toolbarTextColor });
int toolbarTextColor2 = ta2.getColor(0, mContext.getResources().getColor(R.color.white));
int toolbarTextColor2 = ta2.getColor(0, ViewColorTable.ToolbarTitleTextColor);
ta2.recycle();
holder.tvText.setTextColor(toolbarTextColor2);
holder.cbChecked.setChecked(item.isChecked());
holder.cbChecked.setLayoutParams(layoutParams);
holder.cbChecked.setPadding(0,0,0,0);
TypedArray ta3 = mContext.obtainStyledAttributes(new int[] { R.attr.toolbarTextColor });
int toolbarTextColor3 = ta3.getColor(0, mContext.getResources().getColor(R.color.white));
int toolbarTextColor3 = ta3.getColor(0, ViewColorTable.ToolbarTitleTextColor);
ta3.recycle();
holder.cbChecked.setTextColor(toolbarTextColor3);
holder.cbChecked.setOnClickListener(new View.OnClickListener(){
@@ -19,6 +19,7 @@ import cc.winboll.studio.libappbase.GlobalApplication;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.libappbase.R;
import cc.winboll.studio.libappbase.ToastUtils;
import cc.winboll.studio.libappbase.common.ViewColorTable;
import cc.winboll.studio.libappbase.dialogs.DebugHostDialog;
import cc.winboll.studio.libappbase.models.APPInfo;
@@ -465,10 +466,10 @@ public class AboutView extends LinearLayout {
*/
private android.graphics.drawable.Drawable create_item_background() {
android.graphics.drawable.GradientDrawable drawable = new android.graphics.drawable.GradientDrawable();
drawable.setStroke(1, mItemContext.getResources().getColor(R.color.gray_300));
drawable.setStroke(1, ViewColorTable.DividerDarkLineColor);
drawable.setCornerRadius(4);
boolean isNightMode = (mItemContext.getResources().getConfiguration().uiMode & android.content.res.Configuration.UI_MODE_NIGHT_MASK) == android.content.res.Configuration.UI_MODE_NIGHT_YES;
drawable.setColor(isNightMode ? mItemContext.getResources().getColor(R.color.gray_800) : mItemContext.getResources().getColor(android.R.color.white));
drawable.setColor(isNightMode ? ViewColorTable.StatusBarDarkBgColor : ViewColorTable.CardSurfaceColor);
return drawable;
}
@@ -495,7 +496,7 @@ public class AboutView extends LinearLayout {
tvTitle.setText(mTitle);
tvTitle.setTextSize(16);
boolean isNightMode = (mItemContext.getResources().getConfiguration().uiMode & android.content.res.Configuration.UI_MODE_NIGHT_MASK) == android.content.res.Configuration.UI_MODE_NIGHT_YES;
tvTitle.setTextColor(isNightMode ? mItemContext.getResources().getColor(R.color.gray_500) : mItemContext.getResources().getColor(R.color.gray_900));
tvTitle.setTextColor(isNightMode ? ViewColorTable.TextDisabledColor : ViewColorTable.TextPrimaryColor);
llText.addView(tvTitle);
// 内容
TextView tvContent = new TextView(mItemContext);
@@ -524,7 +525,7 @@ public class AboutView extends LinearLayout {
@Override
protected int getContentTextColor() {
return mItemContext.getResources().getColor(R.color.blue_normal);
return ViewColorTable.TextLinkColor;
}
@Override
@@ -567,7 +568,7 @@ public class AboutView extends LinearLayout {
@Override
protected int getContentTextColor() {
return mItemContext.getResources().getColor(R.color.blue_normal);
return ViewColorTable.TextLinkColor;
}
@Override
@@ -1,7 +1,6 @@
package cc.winboll.studio.libappbase.widget;
import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.content.res.TypedArray;
import android.util.AttributeSet;
@@ -13,6 +12,7 @@ import android.widget.Spinner;
import android.widget.TextView;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.libappbase.R;
import cc.winboll.studio.libappbase.common.ViewColorTable;
/**
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
@@ -105,7 +105,7 @@ public class LogTagSpinner extends Spinner {
setLayoutParams(layoutParams);
// 统一背景色(外部可通过 setBackground 手动覆盖)
setBackgroundColor(this.mContext.getColor(R.color.btn_gray_normal));
setBackgroundColor(ViewColorTable.SwitchTrackNormalColor);
}
@@ -156,10 +156,10 @@ public class LogTagSpinner extends Spinner {
//itemTv.setGravity(View.GRAVITY_CENTER_VERTICAL | View.GRAVITY_START);
// 5. 文字颜色(使用主题属性 ?attr/toolbarTextColor
TypedArray ta = mContext.obtainStyledAttributes(new int[] { R.attr.toolbarTextColor });
int toolbarTextColor = ta.getColor(0, mContext.getResources().getColor(R.color.white));
int toolbarTextColor = ta.getColor(0, ViewColorTable.ToolbarTitleTextColor);
ta.recycle();
itemTv.setTextColor(toolbarTextColor);
itemTv.setBackgroundColor(this.mContext.getResources().getColor(R.color.btn_gray_normal));
itemTv.setBackgroundColor(ViewColorTable.SwitchTrackNormalColor);
// 6. 文字溢出处理(最多 2 行,超出省略,避免长标签换行过多)
itemTv.setSingleLine(false);
itemTv.setMaxLines(2);