Compare commits

..

18 Commits

Author SHA1 Message Date
1274bc7c05 <libappbase>Library Release 15.20.5 2026-05-11 14:46:01 +08:00
f67c57108a <appbase>APK 15.20.5 release Publish. 2026-05-11 14:45:48 +08:00
6d694992b7 <appbase>APK 15.20.4 release Publish. 2026-05-11 14:45:14 +08:00
6f5aa807c0 refactor: 重构崩溃处理机制与日志工具
- 优化 CrashHandler 崩溃处理逻辑,统一通知发送逻辑
- 新增 GlobalAppCrashSafetyWire 独立崩溃安全防护类
- 增强 LogUtils 日志工具,补齐异常日志重载方法
- 重构 GlobalCrashActivity 页面,提升稳定性与可读性
- 修复 activity_globalcrash.xml 布局多余符号
- 新增 CrashTestActivity 崩溃测试页面
- 更新 buildCount 编译计数
2026-05-11 14:43:18 +08:00
f897f6e9ab <libappbase>Library Release 15.20.3 2026-05-11 10:33:43 +08:00
e2c73fdec0 <appbase>APK 15.20.3 release Publish. 2026-05-11 10:32:47 +08:00
4fcc5f9689 提高应用崩溃时的基础处理能力 2026-05-11 10:31:20 +08:00
4208cda32f <libappbase>Library Release 15.20.2 2026-05-11 10:04:19 +08:00
7c83b903f3 <appbase>APK 15.20.2 release Publish. 2026-05-11 10:04:02 +08:00
54b040285c refactor: 主题颜色值统一引用 colors.xml 定义的命名颜色
1. 新增 colors.xml 颜色定义
   - 普通模式: mainWindowBackgroundColor, mainWindowTextColor, buttonBackgroundColor, debugTextColor
   - 深色模式: 同上,颜色值适配深色主题

2. 重构 styles.xml 颜色引用
   - APPBaseTheme 和 DebugActivityTheme 中的颜色值改为 @color/xxx 引用
   - 统一使用命名颜色属性

3. 重构 MyDebugActivityTheme
   - 继承父主题的颜色属性定义
2026-05-11 10:01:48 +08:00
e8667bb26f <libappbase>Library Release 15.20.1 2026-05-11 09:40:47 +08:00
05259e5ca9 <appbase>APK 15.20.1 release Publish. 2026-05-11 09:40:26 +08:00
a5a5b37121 refactor: 重构调试主题,统一定义应用调试文字颜色
1. 重命名调试主题属性
   - themeGlobalCrashActivity → themeDebug
   - GlobalCrashActivityTheme → DebugActivityTheme

2. 新增 debugTextColor 属性
   - 定义 debugTextColor 属性,用于统一应用调试文字颜色
   - 普通模式: 灰色 #808080
   - 深色模式: 绿色 #FF00FF00

3. 重构视图控件
   - view_globalcrashreport.xml 和 view_log.xml 使用 themeDebug 主题
   - 控件颜色统一引用主题属性
   - 日志显示文本使用 debugTextColor 属性

4. GlobalCrashReportView Java 代码
   - 新增 obtainDebugTextColor() 方法获取主题中的 debugTextColor
   - 崩溃视图文字颜色通过主题属性获取,与日志视图一致
2026-05-11 09:37:25 +08:00
29726828b0 refactor: 重构主题颜色系统,统一使用命名的颜色属性
1. 新增主窗口颜色属性定义
   - mainWindowBackgroundColor - 普通模式主窗口背景色
   - mainWindowTextColor - 普通模式主窗口文字色
   - mainWindowDarkBackgroundColor - 深色模式主窗口背景色
   - mainWindowDarkTextColor - 深色模式主窗口文字色

2. 重构 view_globalcrashreport.xml 布局
   - 添加 themeGlobalCrashActivity 主题
   - 控件颜色属性改为引用主题属性

3. 统一应用内颜色配置
   - APPBaseTheme 所有颜色属性统一引用命名颜色值
   - GlobalCrashActivityTheme 文字颜色引用主窗口文字色

4. 修复崩溃循环问题
   - 避免属性自引用导致的循环解析
2026-05-11 08:59:34 +08:00
436e92702f 把应用统一资源配置属性放到类库,方便其他应用统一调用。 2026-05-11 01:29:32 +08:00
3669a96768 chore: 移除文档质量不佳的docs目录 2026-05-10 15:44:36 +08:00
37c3d1563c refactor(build): 精简项目模块配置,统一Java编译版本
- 简化 settings.gradle,仅保留 appbase 和 libappbase 模块
- 更新根目录 build.gradle 编译语言为 Java 7
- 移除其他模块(aes、libaes、winboll、libwinboll)引用
- 添加技术文档:基于 sharedUserId + 自有签名 + LocalBroadcastManager 跨应用通信
- 确保 Java 源文件语法符合 API 26-30 适配范围
2026-05-10 15:39:12 +08:00
6741c41c83 <libappbase>Library Release 15.20.0 2026-05-10 13:31:38 +08:00
28 changed files with 631 additions and 315 deletions

View File

@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle #Created by .winboll/winboll_app_build.gradle
#Sun May 10 13:24:08 HKT 2026 #Mon May 11 14:45:59 HKT 2026
stageCount=1 stageCount=6
libraryProject=libappbase libraryProject=libappbase
baseVersion=15.20 baseVersion=15.20
publishVersion=15.20.0 publishVersion=15.20.5
buildCount=0 buildCount=0
baseBetaVersion=15.20.1 baseBetaVersion=15.20.6

View File

@@ -10,7 +10,7 @@
android:theme="@style/MyAPPBaseTheme" android:theme="@style/MyAPPBaseTheme"
android:resizeableActivity="true" android:resizeableActivity="true"
android:process=":App" android:process=":App"
android:sharedUserId="cc.winboll.studio" android:sharedUserId="@string/shared_user_id"
android:sharedUserLabel="@string/shared_user_label"> android:sharedUserLabel="@string/shared_user_label">
<activity <activity

View File

@@ -0,0 +1,28 @@
package cc.winboll.studio.appbase;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.libappbase.ToastUtils;
public class CrashTestActivity extends Activity {
public static final String TAG = "CrashTestActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_crash_test);
LogUtils.d(TAG, "CrashTestActivity onCreate()");
}
public void onBack(View view) {
finish();
}
public void onTestCrash(View view) {
LogUtils.d(TAG, "onTestCrash()");
ToastUtils.show("测试布局崩溃...");
}
}

View File

@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="0dp"
android:background="?attr/activityBackgroundColor">
<android.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/toolbarBackgroundColor"
android:id="@+id/toolbar"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.0">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_vertical">
<cc.winboll.studio.appbase.UndefinedCustomView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="返回"
android:textSize="16sp"
android:textColor="?attr/activityTextColor"
android:background="?attr/buttonBackgroundColor"
android:paddingVertical="12dp"
android:layout_marginHorizontal="24dp"
android:onClick="onBack"
android:layout_margin="10dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="测试崩溃"
android:textSize="16sp"
android:textColor="?attr/activityTextColor"
android:background="?attr/buttonBackgroundColor"
android:paddingVertical="12dp"
android:layout_marginHorizontal="24dp"
android:onClick="onTestCrash"
android:layout_margin="10dp"/>
</LinearLayout>
</ScrollView>
</LinearLayout>

View File

@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<style name="MyAPPBaseTheme" parent="APPBaseTheme"> <style name="MyAPPBaseTheme" parent="APPBaseTheme">
<item name="themeGlobalCrashActivity">@style/MyGlobalCrashActivityTheme</item> <item name="themeDebug">@style/MyDebugActivityTheme</item>
</style> </style>
<style name="MyGlobalCrashActivityTheme" parent="GlobalCrashActivityTheme"> <style name="MyDebugActivityTheme" parent="DebugActivityTheme">
<item name="colorTittle">#FFFFFFFF</item> <item name="colorTittle">?attr/mainWindowDarkTextColor</item>
<item name="colorTittleBackgound">#FF00A4B3</item> <item name="colorTittleBackgound">@color/buttonBackgroundColor</item>
<item name="colorText">#FFFFFFFF</item> <item name="colorText">?attr/debugTextColor</item>
<item name="colorTextBackgound">#FFFFFFFF</item> <item name="colorTextBackgound">?attr/mainWindowDarkBackgroundColor</item>
</style> </style>
</resources> </resources>

View File

@@ -6,5 +6,4 @@
<string name="app_debug">Click here is switch to APP DEBUG</string> <string name="app_debug">Click here is switch to APP DEBUG</string>
<string name="gitea_home">GITEA HOME</string> <string name="gitea_home">GITEA HOME</string>
<string name="app_update">APP UPDATE</string> <string name="app_update">APP UPDATE</string>
<string name="shared_user_label">studio@winboll.cc</string>
</resources> </resources>

View File

@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<style name="MyAPPBaseTheme" parent="APPBaseTheme"> <style name="MyAPPBaseTheme" parent="APPBaseTheme">
<item name="themeGlobalCrashActivity">@style/MyGlobalCrashActivityTheme</item> <item name="themeDebug">@style/MyDebugActivityTheme</item>
</style> </style>
<style name="MyGlobalCrashActivityTheme" parent="GlobalCrashActivityTheme"> <style name="MyDebugActivityTheme" parent="DebugActivityTheme">
<item name="colorTittle">#FFFFFFFF</item> <item name="colorTittle">?attr/mainWindowTextColor</item>
<item name="colorTittleBackgound">#FF00A4B3</item> <item name="colorTittleBackgound">@color/buttonBackgroundColor</item>
<item name="colorText">#FFFFFFFF</item> <item name="colorText">?attr/debugTextColor</item>
<item name="colorTextBackgound">#FF000000</item> <item name="colorTextBackgound">?attr/mainWindowBackgroundColor</item>
</style> </style>
</resources> </resources>

View File

@@ -93,11 +93,11 @@ allprojects {
} }
subprojects { subprojects {
// 1. 对纯 Java 模块的 JavaCompile 任务配置(升级为 Java 11 // 1. 对纯 Java 模块的 JavaCompile 任务配置(强制Java 7
tasks.withType(JavaCompile) { tasks.withType(JavaCompile) {
options.compilerArgs << "-parameters" options.compilerArgs << "-parameters"
sourceCompatibility = JavaVersion.VERSION_11 sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_1_7
options.encoding = "UTF-8" options.encoding = "UTF-8"
} }
} }

View File

@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle #Created by .winboll/winboll_app_build.gradle
#Sun May 10 13:24:08 HKT 2026 #Mon May 11 14:45:48 HKT 2026
stageCount=1 stageCount=6
libraryProject=libappbase libraryProject=libappbase
baseVersion=15.20 baseVersion=15.20
publishVersion=15.20.0 publishVersion=15.20.5
buildCount=0 buildCount=0
baseBetaVersion=15.20.1 baseBetaVersion=15.20.6

View File

@@ -10,7 +10,6 @@ import android.content.Intent;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Color;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
@@ -165,6 +164,7 @@ public final class CrashHandler {
Intent intent = new Intent(); Intent intent = new Intent();
LogUtils.d(TAG, "gotoCrashActiviy: "); LogUtils.d(TAG, "gotoCrashActiviy: ");
// 根据保险丝状态选择启动的崩溃页面 // 根据保险丝状态选择启动的崩溃页面
if (AppCrashSafetyWire.getInstance().isAppCrashSafetyWireOK()) { if (AppCrashSafetyWire.getInstance().isAppCrashSafetyWireOK()) {
LogUtils.d(TAG, "gotoCrashActiviy: isAppCrashSafetyWireOK"); LogUtils.d(TAG, "gotoCrashActiviy: isAppCrashSafetyWireOK");
@@ -186,13 +186,14 @@ public final class CrashHandler {
); );
try { try {
if (GlobalApplication.isDebugging()&&AppCrashSafetyWire.getInstance().isAppCrashSafetyWireOK()) { if (GlobalApplication.isDebugging()) {
// 如果是 debug 版,启动崩溃页面窗口 // 如果是 debug 版,启动崩溃页面窗口
app.startActivity(intent); app.startActivity(intent);
} else {
// 如果是 release 版,就只发送一个通知
CrashHandleNotifyUtils.handleUncaughtException(app, intent);
} }
// 发送一个通知
CrashHandleNotifyUtils.handleUncaughtException(app, intent);
// 终止当前进程(确保完全重启) // 终止当前进程(确保完全重启)
android.os.Process.killProcess(android.os.Process.myPid()); android.os.Process.killProcess(android.os.Process.myPid());
System.exit(0); System.exit(0);
@@ -440,9 +441,6 @@ public final class CrashHandler {
// 设置系统默认主题(避免自定义主题冲突) // 设置系统默认主题(避免自定义主题冲突)
setTheme(android.R.style.Theme_DeviceDefault_Light_DarkActionBar); setTheme(android.R.style.Theme_DeviceDefault_Light_DarkActionBar);
// 判断是否为深色模式
boolean isNightMode = (getResources().getConfiguration().uiMode & android.content.res.Configuration.UI_MODE_NIGHT_MASK) == android.content.res.Configuration.UI_MODE_NIGHT_YES;
// 动态创建布局(避免 XML 布局加载异常) // 动态创建布局(避免 XML 布局加载异常)
setContentView: { setContentView: {
// 垂直滚动视图(处理日志过长) // 垂直滚动视图(处理日志过长)
@@ -451,7 +449,7 @@ public final class CrashHandler {
// 水平滚动视图(处理日志行过长) // 水平滚动视图(处理日志行过长)
HorizontalScrollView hw = new HorizontalScrollView(this); HorizontalScrollView hw = new HorizontalScrollView(this);
hw.setBackgroundColor(isNightMode ? 0xFF0D1B2A : 0xFFF5F5F5); // 深色模式灰色背景 hw.setBackgroundColor(0xFFF5F5F5); // 深色模式灰色背景
// 日志显示文本框 // 日志显示文本框
TextView message = new TextView(this); TextView message = new TextView(this);
@@ -459,7 +457,7 @@ public final class CrashHandler {
int padding = dp2px(16); // 内边距 16dp适配不同屏幕 int padding = dp2px(16); // 内边距 16dp适配不同屏幕
message.setPadding(padding, padding, padding, padding); message.setPadding(padding, padding, padding, padding);
message.setText(mLog); // 设置崩溃日志 message.setText(mLog); // 设置崩溃日志
message.setTextColor(isNightMode ? 0xFFE0E0E0 : 0xFF000000); // 深色模式灰色文字,普通模式黑色文字 message.setTextColor(0xFF000000); // 深色模式灰色文字,普通模式黑色文字
message.setTextIsSelectable(true); // 支持文本选择(便于手动复制) message.setTextIsSelectable(true); // 支持文本选择(便于手动复制)
} }

View File

@@ -0,0 +1,219 @@
package cc.winboll.studio.libappbase;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
/**
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
* @CreateTime 2026-05-11 13:28:00
* @EditTime 2026-05-11 13:30:45
* @Describe 应用崩溃保险丝单例管理类
* 限制短时间内应用重复崩溃,通过分级熔断机制控制崩溃页面跳转策略;
* 防护等级区间 1~2每次崩溃自动降级等级溢出则判定为彻底熔断
* 支持本地文件持久化等级、延迟自动恢复、手动重置防护等级能力。
*/
public final class GlobalAppCrashSafetyWire {
/** 日志标识标签 */
public static final String TAG = "GlobalAppCrashSafetyWire";
/** 最低防护等级阈值 */
private static final int _MINI = 1;
/** 最高防护等级阈值 */
private static final int _MAX = 2;
/** 单例实例对象 */
private static volatile GlobalAppCrashSafetyWire _AppCrashSafetyWire;
/** 当前防护熔断等级 */
private volatile Integer currentSafetyLevel;
/**
* 私有构造方法
* 单例禁止外部实例化,初始化加载本地持久化防护等级
*/
private GlobalAppCrashSafetyWire() {
LogUtils.d(TAG, "构造方法执行:初始化崩溃保险丝实例");
currentSafetyLevel = loadCurrentSafetyLevel();
}
/**
* 获取单例对象
* @return GlobalAppCrashSafetyWire 单例
*/
public static synchronized GlobalAppCrashSafetyWire getInstance() {
if (_AppCrashSafetyWire == null) {
_AppCrashSafetyWire = new GlobalAppCrashSafetyWire();
}
return _AppCrashSafetyWire;
}
/**
* 设置当前防护等级
* @param currentSafetyLevel 待设置的防护等级
*/
public void setCurrentSafetyLevel(final int currentSafetyLevel) {
this.currentSafetyLevel = currentSafetyLevel;
LogUtils.d(TAG, "setCurrentSafetyLevel设置等级 = " + currentSafetyLevel);
}
/**
* 获取当前内存中防护等级
* @return 当前防护等级
*/
public int getCurrentSafetyLevel() {
return currentSafetyLevel;
}
/**
* 保存防护等级到本地文件持久化
* @param currentSafetyLevel 待保存防护等级
*/
public void saveCurrentSafetyLevel(final int currentSafetyLevel) {
LogUtils.d(TAG, "saveCurrentSafetyLevel开始持久化等级 = " + currentSafetyLevel);
this.currentSafetyLevel = currentSafetyLevel;
ObjectOutputStream oos = null;
try {
oos = new ObjectOutputStream(new FileOutputStream(CrashHandler._CrashCountFilePath));
oos.writeInt(currentSafetyLevel);
oos.flush();
LogUtils.d(TAG, "saveCurrentSafetyLevel写入文件成功等级 = " + currentSafetyLevel);
} catch (IOException e) {
LogUtils.e(TAG, "saveCurrentSafetyLevel写入文件异常", e);
} finally {
if (oos != null) {
try {
oos.close();
} catch (IOException e) {
LogUtils.e(TAG, "saveCurrentSafetyLevel关闭流异常", e);
}
}
}
}
/**
* 从本地文件读取防护等级
* @return 加载后的防护等级
*/
public int loadCurrentSafetyLevel() {
LogUtils.d(TAG, "loadCurrentSafetyLevel加载本地防护等级");
File file = new File(CrashHandler._CrashCountFilePath);
if (!file.exists()) {
currentSafetyLevel = _MAX;
LogUtils.d(TAG, "loadCurrentSafetyLevel文件不存在初始化为最高等级 = " + _MAX);
saveCurrentSafetyLevel(currentSafetyLevel);
return currentSafetyLevel;
}
ObjectInputStream ois = null;
try {
ois = new ObjectInputStream(new FileInputStream(CrashHandler._CrashCountFilePath));
currentSafetyLevel = ois.readInt();
LogUtils.d(TAG, "loadCurrentSafetyLevel读取文件成功当前等级 = " + currentSafetyLevel);
} catch (IOException e) {
LogUtils.e(TAG, "loadCurrentSafetyLevel读取文件异常", e);
currentSafetyLevel = _MAX;
} finally {
if (ois != null) {
try {
ois.close();
} catch (IOException e) {
LogUtils.e(TAG, "loadCurrentSafetyLevel关闭流异常", e);
}
}
}
return currentSafetyLevel;
}
/**
* 执行一次保险丝熔断降级
* @return 降级后是否仍在有效防护区间
*/
boolean burnSafetyWire() {
LogUtils.d(TAG, "burnSafetyWire执行一次熔断降级");
final int safeLevel = loadCurrentSafetyLevel();
if (isSafetyWireWorking(safeLevel)) {
saveCurrentSafetyLevel(safeLevel - 1);
return isSafetyWireWorking(safeLevel - 1);
}
return false;
}
/**
* 校验指定等级是否在有效防护区间
* @param safetyLevel 待校验防护等级
* @return true=防护有效 false=已熔断
*/
boolean isSafetyWireWorking(final int safetyLevel) {
LogUtils.d(TAG, "isSafetyWireWorking校验等级 = " + safetyLevel);
if (safetyLevel >= _MINI && safetyLevel <= _MAX) {
LogUtils.d(TAG, "isSafetyWireWorking等级在合法区间内");
return true;
}
LogUtils.d(TAG, "isSafetyWireWorking等级超出合法区间已熔断");
return false;
}
/**
* 立即恢复防护等级为最高等级
*/
void resumeToMaximumImmediately() {
LogUtils.d(TAG, "resumeToMaximumImmediately重置为最高防护等级");
GlobalAppCrashSafetyWire.getInstance().saveCurrentSafetyLevel(_MAX);
}
/**
* 关闭防护,设置为临界最低等级
*/
void off() {
LogUtils.d(TAG, "off设置为临界最低防护等级");
saveCurrentSafetyLevel(_MINI);
}
/**
* 检查当前整体保险丝是否处于可用防护状态
* @return true=防护正常 false=已熔断
*/
boolean isAppCrashSafetyWireOK() {
LogUtils.d(TAG, "isAppCrashSafetyWireOK检测当前防护状态");
currentSafetyLevel = loadCurrentSafetyLevel();
return isSafetyWireWorking(currentSafetyLevel);
}
/**
* 延迟异步检测并自动恢复防护等级
* @param context 上下文对象
*/
void postResumeCrashSafetyWireHandler(final Context context) {
LogUtils.d(TAG, "postResumeCrashSafetyWireHandler开启延迟自动恢复任务");
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
final int nextLevel = currentSafetyLevel - 1;
if (!GlobalAppCrashSafetyWire.getInstance().isSafetyWireWorking(nextLevel)) {
GlobalAppCrashSafetyWire.getInstance().resumeToMaximumImmediately();
LogUtils.d(TAG, "postResumeCrashSafetyWireHandler临近熔断自动重置最高等级");
}
}
}, 500);
}
public static void testGlobalAppCrashSafetyWire(Context context) {
if (GlobalAppCrashSafetyWire.getInstance().isAppCrashSafetyWireOK()) {
GlobalAppCrashSafetyWire.getInstance().burnSafetyWire();
for (int i = Integer.MIN_VALUE; i < Integer.MAX_VALUE; i++) {
context.getString(i);
}
}
}
}

View File

@@ -9,178 +9,127 @@ import android.content.pm.PackageManager;
import android.os.Bundle; import android.os.Bundle;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View;
import android.widget.Toast; import android.widget.Toast;
import cc.winboll.studio.libappbase.R; import cc.winboll.studio.libappbase.R;
/** /**
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com> * @Author 豆包&ZhanGSKen<zhangsken@qq.com>
* @Date 2025/11/11 19:58 * @CreateTime 2025-11-11 19:58:00
* @EditTime 2025-11-11 20:15:32
* @Describe 应用异常报告观察活动窗口类 * @Describe 应用异常报告观察活动窗口类
* 核心功能:应用发生未捕获崩溃时,由 CrashHandler 启动此页面,展示崩溃日志详情, * 应用发生未捕获崩溃时,由 CrashHandler 启动此页面,展示崩溃日志详情,
* 提供复制日志」「重启应用操作入口,便于开发者定位问题用户恢复应用 * 提供复制日志重启应用操作入口,便于开发者定位问题用户恢复应用
* 页面初始化异常时捕获错误并输出调试日志,提升崩溃页面自身稳定性。
*/ */
public final class GlobalCrashActivity extends Activity implements MenuItem.OnMenuItemClickListener { public final class GlobalCrashActivity extends Activity
implements MenuItem.OnMenuItemClickListener {
/** 日志标签(用于调试日志输出,唯一标识当前 Activity */ /** 日志标签 */
public static final String TAG = "GlobalCrashActivity"; public static final String TAG = "GlobalCrashActivity";
/** 菜单标识:复制崩溃日志(用于区分菜单项点击事件) */ /** 菜单标识:复制崩溃日志 */
private static final int MENU_ITEM_COPY = 0; private static final int MENU_ITEM_COPY = 0;
/** 菜单标识:重启应用(用于区分菜单项点击事件) */ /** 菜单标识:重启应用 */
private static final int MENU_ITEM_RESTART = 1; private static final int MENU_ITEM_RESTART = 1;
/** 崩溃报告展示自定义视图 */ /** 崩溃报告自定义视图 */
// 负责渲染崩溃日志文本、提供 Toolbar 容器,封装了日志展示和菜单样式控制逻辑
private GlobalCrashReportView mCrashReportView; private GlobalCrashReportView mCrashReportView;
/** 崩溃日志文本 */
/** 崩溃日志文本内容 */
// 从 CrashHandler 通过 Intent 传递过来,包含异常堆栈、设备信息等完整崩溃数据
private String mCrashLog; private String mCrashLog;
/**
* Activity 创建时初始化(生命周期核心方法,仅执行一次)
* @param savedInstanceState 保存的实例状态(崩溃页面无需恢复状态,此处仅作兼容)
*/
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
LogUtils.d(TAG, "onCreate: 初始化崩溃展示页面");
// 初始化崩溃安全防护机制 final Context appContext = getApplicationContext();
// 作用:防止应用重启后短时间内再次崩溃,由 CrashHandler 内部实现防护逻辑 GlobalAppCrashSafetyWire.getInstance()
CrashHandler.AppCrashSafetyWire.getInstance() .postResumeCrashSafetyWireHandler(appContext);
.postResumeCrashSafetyWireHandler(getApplicationContext());
// 从 Intent 中获取崩溃日志数据EXTRA_CRASH_INFO 为 CrashHandler 定义的常量键)
mCrashLog = getIntent().getStringExtra(CrashHandler.EXTRA_CRASH_LOG); mCrashLog = getIntent().getStringExtra(CrashHandler.EXTRA_CRASH_LOG);
// 设置当前 Activity 的布局文件(展示崩溃报告的 UI 结构)
setContentView(R.layout.activity_globalcrash); setContentView(R.layout.activity_globalcrash);
// 初始化崩溃报告展示视图(通过布局 ID 找到自定义 View 实例)
mCrashReportView = findViewById(R.id.activityglobalcrashGlobalCrashReportView1); mCrashReportView = findViewById(R.id.activityglobalcrashGlobalCrashReportView1);
// 将崩溃日志设置到视图中,由自定义 View 负责排版和显示 if (mCrashReportView != null) {
mCrashReportView.setReport(mCrashLog); mCrashReportView.setReport(mCrashLog);
// 设置页面的 ActionBar复用自定义 View 中的 Toolbar 作为系统 ActionBar
setActionBar(mCrashReportView.getToolbar()); setActionBar(mCrashReportView.getToolbar());
}
// 配置 ActionBar 标题和副标题(非空判断避免空指针异常)
if (getActionBar() != null) { if (getActionBar() != null) {
// 设置标题:使用 CrashHandler 中定义的统一标题(如 "应用崩溃报告"
getActionBar().setTitle(CrashHandler.TITTLE); getActionBar().setTitle(CrashHandler.TITTLE);
// 设置副标题:显示当前应用名称(从全局 Application 工具方法获取) final String appName = GlobalApplication.getAppName(appContext);
getActionBar().setSubtitle(GlobalApplication.getAppName(getApplicationContext())); getActionBar().setSubtitle(appName);
} }
LogUtils.d(TAG, "onCreate: 崩溃页面初始化完成");
} }
/**
* 重写返回键点击事件
* 逻辑:点击手机返回键时,直接重启应用(而非返回上一页,因崩溃后上一页状态可能异常)
*/
@Override @Override
public void onBackPressed() { public void onBackPressed() {
restartApp(); restartApp();
} }
/** /**
* 重启当前应用(核心工具方法) * 重启当前应用
* 实现逻辑:
* 1. 获取应用的启动意图(默认启动 AndroidManifest 中配置的主 Activity
* 2. 设置意图标志,清除原有任务栈,避免残留异常页面
* 3. 启动主 Activity 并终止当前进程,确保应用完全重启
*/ */
private void restartApp() { private void restartApp() {
// 获取 PackageManager 实例(用于获取应用相关信息和意图) LogUtils.d(TAG, "restartApp: 执行应用重启操作");
PackageManager packageManager = getPackageManager(); final PackageManager packageManager = getPackageManager();
// 获取应用的启动意图(参数为当前应用包名,返回主 Activity 的意图) final Intent launchIntent = packageManager.getLaunchIntentForPackage(getPackageName());
Intent launchIntent = packageManager.getLaunchIntentForPackage(getPackageName());
if (launchIntent != null) { if (launchIntent != null) {
// 设置意图标志:
// FLAG_ACTIVITY_NEW_TASK创建新的任务栈启动 Activity
// FLAG_ACTIVITY_CLEAR_TOP清除目标 Activity 之上的所有 Activity
// FLAG_ACTIVITY_CLEAR_TASK清除当前任务栈中的所有 Activity
launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_CLEAR_TASK); | Intent.FLAG_ACTIVITY_CLEAR_TASK);
// 启动应用主 Activity
startActivity(launchIntent); startActivity(launchIntent);
} }
// 关闭当前崩溃报告页面
finish(); finish();
// 终止当前应用进程(确保释放所有资源,避免内存泄漏)
android.os.Process.killProcess(android.os.Process.myPid()); android.os.Process.killProcess(android.os.Process.myPid());
// 强制退出虚拟机(彻底终止应用,防止残留线程继续运行)
System.exit(0); System.exit(0);
} }
/**
* 菜单项点击事件回调(实现 MenuItem.OnMenuItemClickListener 接口)
* @param item 被点击的菜单项实例
* @return booleantrue 表示事件已消费不再向下传递false 表示未消费
*/
@Override @Override
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
// 根据菜单项 ID 判断点击的是哪个功能 final int itemId = item.getItemId();
switch (item.getItemId()) { switch (itemId) {
case MENU_ITEM_COPY: case MENU_ITEM_COPY:
// 点击「复制」菜单,执行复制崩溃日志到剪贴板
copyCrashLogToClipboard(); copyCrashLogToClipboard();
break; break;
case MENU_ITEM_RESTART: case MENU_ITEM_RESTART:
// 点击「重启」菜单:先恢复崩溃防护机制到最大等级,再重启应用 GlobalAppCrashSafetyWire.getInstance().resumeToMaximumImmediately();
CrashHandler.AppCrashSafetyWire.getInstance().resumeToMaximumImmediately();
restartApp(); restartApp();
break; break;
default:
break;
} }
return false; return false;
} }
/**
* 创建页面顶部菜单ActionBar 菜单)
* @param menu 菜单容器,用于添加菜单项
* @return booleantrue 表示显示菜单false 表示不显示
*/
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
// 添加「复制」菜单项:
// 参数说明:菜单组 ID0 表示默认组)、菜单项 IDMENU_ITEM_COPY、排序号0、菜单文本"Copy"
// setOnMenuItemClickListener(this):绑定点击事件到当前 Activity
// setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM):有空间时显示在 ActionBar 上,否则放入溢出菜单
menu.add(0, MENU_ITEM_COPY, 0, "Copy") menu.add(0, MENU_ITEM_COPY, 0, "Copy")
.setOnMenuItemClickListener(this) .setOnMenuItemClickListener(this)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
// 添加「重启」菜单项(参数含义同上)
menu.add(0, MENU_ITEM_RESTART, 0, "Restart") menu.add(0, MENU_ITEM_RESTART, 0, "Restart")
.setOnMenuItemClickListener(this) .setOnMenuItemClickListener(this)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
// 调用自定义视图的方法,更新菜单文字样式(如颜色、字体大小等,由自定义 View 内部实现) if (mCrashReportView != null) {
mCrashReportView.updateMenuStyle(); mCrashReportView.updateMenuStyle();
}
return true; return true;
} }
/** /**
* 崩溃日志复制到系统剪贴板(工具方法) * 复制崩溃日志到系统剪贴板
* 功能:用户点击复制菜单后,将完整崩溃日志存入剪贴板,方便粘贴到聊天工具或文档中
*/ */
private void copyCrashLogToClipboard() { private void copyCrashLogToClipboard() {
// 获取系统剪贴板服务(需通过 getSystemService 方法获取) LogUtils.d(TAG, "copyCrashLogToClipboard: 复制崩溃日志到剪贴板");
ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); final ClipboardManager clipboardManager = (ClipboardManager)
getSystemService(Context.CLIPBOARD_SERVICE);
// 创建剪贴板数据: final ClipData clipData = ClipData.newPlainText(getPackageName(), mCrashLog);
// 参数 1标签用于标识剪贴板内容来源此处用应用包名
// 参数 2实际复制的文本内容崩溃日志
ClipData clipData = ClipData.newPlainText(getPackageName(), mCrashLog);
// 将数据设置到剪贴板(完成复制操作)
clipboardManager.setPrimaryClip(clipData); clipboardManager.setPrimaryClip(clipData);
// 显示复制成功的 Toast 提示(告知用户操作结果)
Toast.makeText(getApplication(), "The text is copied.", Toast.LENGTH_SHORT).show(); Toast.makeText(getApplication(), "The text is copied.", Toast.LENGTH_SHORT).show();
} }
} }

View File

@@ -12,6 +12,7 @@ import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toolbar; import android.widget.Toolbar;
import cc.winboll.studio.libappbase.R; import cc.winboll.studio.libappbase.R;
import android.content.res.Resources;
/** /**
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com> * @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
@@ -175,10 +176,11 @@ public class GlobalCrashReportView extends LinearLayout {
* 初始化默认配置(无自定义属性时使用) * 初始化默认配置(无自定义属性时使用)
*/ */
private void initDefaultConfig() { private void initDefaultConfig() {
// 设置默认配色(普通模式黑色文字 // 设置默认配色(使用 debugTextColor 属性
mTitleColor = Color.BLACK; Resources.Theme theme = mContext.getTheme();
mTitleBackgroundColor = Color.BLACK; mTitleColor = theme.getResources().getColor(android.R.color.holo_green_dark);
mTextColor = Color.BLACK; mTitleBackgroundColor = Color.GRAY;
mTextColor = obtainDebugTextColor(theme);
mTextBackgroundColor = Color.WHITE; mTextBackgroundColor = Color.WHITE;
// 加载布局 // 加载布局
inflateView(); inflateView();
@@ -186,6 +188,21 @@ public class GlobalCrashReportView extends LinearLayout {
initWidgetStyle(); initWidgetStyle();
} }
private int obtainDebugTextColor(Resources.Theme theme) {
int[] attrs = new int[] { cc.winboll.studio.libappbase.R.attr.themeDebug };
TypedArray themeTypedArray = theme.obtainStyledAttributes(attrs);
int themeResId = themeTypedArray.getResourceId(0, 0);
themeTypedArray.recycle();
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);
debugTypedArray.recycle();
return color;
}
return Color.GRAY;
}
/** /**
* 初始化视图(解析自定义属性 + 加载布局 + 设置样式) * 初始化视图(解析自定义属性 + 加载布局 + 设置样式)
* @param attrs 自定义属性集合 * @param attrs 自定义属性集合
@@ -195,7 +212,7 @@ public class GlobalCrashReportView extends LinearLayout {
TypedArray typedArray = mContext.obtainStyledAttributes( TypedArray typedArray = mContext.obtainStyledAttributes(
attrs, attrs,
R.styleable.GlobalCrashActivity, R.styleable.GlobalCrashActivity,
R.attr.themeGlobalCrashActivity, R.attr.themeDebug,
0 0
); );
@@ -208,10 +225,7 @@ public class GlobalCrashReportView extends LinearLayout {
R.styleable.GlobalCrashActivity_colorTittleBackgound, // 注原拼写错误Backgound→Background保持与 attrs.xml 一致 R.styleable.GlobalCrashActivity_colorTittleBackgound, // 注原拼写错误Backgound→Background保持与 attrs.xml 一致
Color.BLACK Color.BLACK
); );
mTextColor = typedArray.getColor( mTextColor = obtainDebugTextColor(mContext.getTheme());
R.styleable.GlobalCrashActivity_colorText,
Color.BLACK
);
mTextBackgroundColor = typedArray.getColor( mTextBackgroundColor = typedArray.getColor(
R.styleable.GlobalCrashActivity_colorTextBackgound, // 注:原拼写错误,保持与 attrs.xml 一致 R.styleable.GlobalCrashActivity_colorTextBackgound, // 注:原拼写错误,保持与 attrs.xml 一致
Color.WHITE Color.WHITE

View File

@@ -1,8 +1,8 @@
package cc.winboll.studio.libappbase; package cc.winboll.studio.libappbase;
import android.content.Context; import android.content.Context;
import android.widget.Toast;
import android.util.Log; import android.util.Log;
import android.widget.Toast;
import cc.winboll.studio.libappbase.GlobalApplication; import cc.winboll.studio.libappbase.GlobalApplication;
import dalvik.system.DexFile; import dalvik.system.DexFile;
@@ -28,28 +28,33 @@ import java.util.Map;
/** /**
* @Author 豆包&ZhanGSKen<zhangsken@qq.com> * @Author 豆包&ZhanGSKen<zhangsken@qq.com>
* @CreateTime 2026/05/09 15:46:28 * @CreateTime 2026-05-09 15:46:28
* @LastEditTime 2026/05/09 17:28:45 * @EditTime 2026-05-11 15:36:12
* @Describe 应用日志工具类 * @Describe 应用日志工具类
* 补全多级别日志重载、自动日志文件裁剪、应用内TAG自动扫描管理 * 补全多级别日志重载、自动日志文件裁剪、应用内TAG自动扫描管理
* 支持日志本地持久化、异常堆栈格式化、TAG开关配置、线程/集合打印工具 * 支持日志本地持久化、异常堆栈格式化、TAG开关配置、线程集合打印工具
* 完全兼容Java7语法严格遵循变量final编码规范 * 完全兼容Java7语法严格遵循变量final编码规范
* 重要说明:本类内部调试打印必须使用 android.util.Log禁止使用LogUtils自身方法 * 重要说明:本类内部调试打印必须使用 android.util.Log禁止使用LogUtils自身方法
* 若内部使用LogUtils打印会造成递归嵌套调用程序运行时会概率出现逻辑漩涡、循环无限制调用问题。 * 避免递归嵌套调用、逻辑漩涡与无限循环调用问题。
*/ */
public class LogUtils { public class LogUtils {
// ====================== 常量与枚举定义 ====================== // ====================== 常量与枚举 ======================
public static final String TAG = "LogUtils"; public static final String TAG = "LogUtils";
/** /**
* 日志级别枚举 * 日志级别枚举
*/ */
public static enum LOG_LEVEL { public static enum LOG_LEVEL {
Off, Error, Warn, Info, Debug, Verbose Off,
Error,
Warn,
Info,
Debug,
Verbose
} }
// ====================== 全局成员变量 ====================== // ====================== 全局静态成员 ======================
private static volatile boolean _IsInited = false; private static volatile boolean _IsInited = false;
private static Context _mContext; private static Context _mContext;
private static final SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat("[yyyyMMdd_HHmmss_SSS]", Locale.getDefault()); private static final SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat("[yyyyMMdd_HHmmss_SSS]", Locale.getDefault());
@@ -60,20 +65,11 @@ public class LogUtils {
private static LogUtilsBean _mLogUtilsBean; private static LogUtilsBean _mLogUtilsBean;
public static final Map<String, Boolean> mapTAGList = new HashMap<String, Boolean>(); public static final Map<String, Boolean> mapTAGList = new HashMap<String, Boolean>();
// ====================== 初始化入口方法 ====================== // ====================== 初始化入口 ======================
/**
* 初始化日志工具默认级别Off
* @param context 上下文
*/
public static void init(final Context context) { public static void init(final Context context) {
init(context, LOG_LEVEL.Off); init(context, LOG_LEVEL.Off);
} }
/**
* 初始化日志工具,指定日志级别
* @param context 上下文
* @param logLevel 日志级别
*/
public static void init(final Context context, final LOG_LEVEL logLevel) { public static void init(final Context context, final LOG_LEVEL logLevel) {
Log.d(TAG, "init 执行日志工具初始化"); Log.d(TAG, "init 执行日志工具初始化");
_mContext = context; _mContext = context;
@@ -93,10 +89,7 @@ public class LogUtils {
Log.d(TAG, "init 日志工具初始化完成"); Log.d(TAG, "init 日志工具初始化完成");
} }
// ====================== 目录初始化私有方法 ====================== // ====================== 目录初始化 ======================
/**
* 调试模式初始化外部存储日志目录
*/
private static void initDebugDir() { private static void initDebugDir() {
final Context appContext = _mContext.getApplicationContext(); final Context appContext = _mContext.getApplicationContext();
_mfLogCacheDir = new File(appContext.getExternalCacheDir(), TAG); _mfLogCacheDir = new File(appContext.getExternalCacheDir(), TAG);
@@ -112,9 +105,6 @@ public class LogUtils {
_mfLogUtilsBeanFile = new File(_mfLogDataDir, TAG + ".json"); _mfLogUtilsBeanFile = new File(_mfLogDataDir, TAG + ".json");
} }
/**
* 正式模式初始化内部存储日志目录
*/
private static void initReleaseDir() { private static void initReleaseDir() {
final Context appContext = _mContext.getApplicationContext(); final Context appContext = _mContext.getApplicationContext();
_mfLogCacheDir = new File(appContext.getCacheDir(), TAG); _mfLogCacheDir = new File(appContext.getCacheDir(), TAG);
@@ -130,9 +120,6 @@ public class LogUtils {
_mfLogUtilsBeanFile = new File(_mfLogDataDir, TAG + ".json"); _mfLogUtilsBeanFile = new File(_mfLogDataDir, TAG + ".json");
} }
/**
* 初始化日志配置Bean无配置则自动创建默认配置
*/
private static void initLogConfigBean() { private static void initLogConfigBean() {
_mLogUtilsBean = LogUtilsBean.loadBeanFromFile(_mfLogUtilsBeanFile.getPath(), LogUtilsBean.class); _mLogUtilsBean = LogUtilsBean.loadBeanFromFile(_mfLogUtilsBeanFile.getPath(), LogUtilsBean.class);
if (_mLogUtilsBean == null) { if (_mLogUtilsBean == null) {
@@ -142,10 +129,7 @@ public class LogUtils {
} }
} }
// ====================== 日志文件裁剪Java7 兼容) ====================== // ====================== 日志文件裁剪 ======================
/**
* 日志文件大小检查裁剪超6MB保留最新3MB
*/
private static void checkAndTrimLogFileSize() { private static void checkAndTrimLogFileSize() {
if (_mfLogCatchFile == null || !_mfLogCatchFile.exists()) { if (_mfLogCatchFile == null || !_mfLogCatchFile.exists()) {
return; return;
@@ -212,14 +196,11 @@ public class LogUtils {
} }
} }
// ====================== TAG配置管理 ====================== // ====================== TAG 配置管理 ======================
public static Map<String, Boolean> getMapTAGList() { public static Map<String, Boolean> getMapTAGList() {
return mapTAGList; return mapTAGList;
} }
/**
* 加载本地TAG启用配置
*/
private static void loadTAGBeanSettings() { private static void loadTAGBeanSettings() {
final ArrayList<LogUtilsClassTAGBean> list = new ArrayList<LogUtilsClassTAGBean>(); final ArrayList<LogUtilsClassTAGBean> list = new ArrayList<LogUtilsClassTAGBean>();
LogUtilsClassTAGBean.loadBeanList(_mContext, list, LogUtilsClassTAGBean.class); LogUtilsClassTAGBean.loadBeanList(_mContext, list, LogUtilsClassTAGBean.class);
@@ -232,9 +213,6 @@ public class LogUtils {
} }
} }
/**
* 保存当前TAG开关配置到本地
*/
private static void saveTAGBeanSettings() { private static void saveTAGBeanSettings() {
final ArrayList<LogUtilsClassTAGBean> list = new ArrayList<LogUtilsClassTAGBean>(); final ArrayList<LogUtilsClassTAGBean> list = new ArrayList<LogUtilsClassTAGBean>();
for (final Map.Entry<String, Boolean> entry : mapTAGList.entrySet()) { for (final Map.Entry<String, Boolean> entry : mapTAGList.entrySet()) {
@@ -243,9 +221,6 @@ public class LogUtils {
LogUtilsClassTAGBean.saveBeanList(_mContext, list, LogUtilsClassTAGBean.class); LogUtilsClassTAGBean.saveBeanList(_mContext, list, LogUtilsClassTAGBean.class);
} }
/**
* 自动扫描应用内含 public static String TAG 的类
*/
private static void addClassTAGList() { private static void addClassTAGList() {
try { try {
final String packageNamePrefix = "cc.winboll.studio"; final String packageNamePrefix = "cc.winboll.studio";
@@ -277,8 +252,12 @@ public class LogUtils {
mapTAGList.put(tagValue, false); mapTAGList.put(tagValue, false);
} }
} }
} catch (NoClassDefFoundError | ClassNotFoundException | IllegalAccessException e) { } catch (NoClassDefFoundError e) {
Log.w(TAG, "addClassTAGList 解析类TAG失败"); Log.w(TAG, "addClassTAGList 解析类TAG失败 NoClassDefFoundError");
} catch (ClassNotFoundException e) {
Log.w(TAG, "addClassTAGList 解析类TAG失败 ClassNotFoundException");
} catch (IllegalAccessException e) {
Log.w(TAG, "addClassTAGList 解析类TAG失败 IllegalAccessException");
} }
} }
} catch (IOException e) { } catch (IOException e) {
@@ -286,11 +265,6 @@ public class LogUtils {
} }
} }
/**
* 设置单个TAG日志开关
* @param tag 日志TAG
* @param isEnable 是否启用
*/
public static void setTAGListEnable(final String tag, final boolean isEnable) { public static void setTAGListEnable(final String tag, final boolean isEnable) {
final Iterator<Map.Entry<String, Boolean>> iterator = mapTAGList.entrySet().iterator(); final Iterator<Map.Entry<String, Boolean>> iterator = mapTAGList.entrySet().iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
@@ -304,10 +278,6 @@ public class LogUtils {
Log.d(TAG, "setTAGListEnable 更新TAG开关配置"); Log.d(TAG, "setTAGListEnable 更新TAG开关配置");
} }
/**
* 批量设置所有TAG日志开关
* @param isEnable 是否全量启用
*/
public static void setALlTAGListEnable(final boolean isEnable) { public static void setALlTAGListEnable(final boolean isEnable) {
for (final Map.Entry<String, Boolean> entry : mapTAGList.entrySet()) { for (final Map.Entry<String, Boolean> entry : mapTAGList.entrySet()) {
entry.setValue(isEnable); entry.setValue(isEnable);
@@ -326,12 +296,6 @@ public class LogUtils {
return _mLogUtilsBean.getLogLevel(); return _mLogUtilsBean.getLogLevel();
} }
/**
* 判断当前TAG及级别是否允许输出日志
* @param tag 日志标识
* @param logLevel 日志级别
* @return 是否允许打印
*/
private static boolean isLoggable(final String tag, final LOG_LEVEL logLevel) { private static boolean isLoggable(final String tag, final LOG_LEVEL logLevel) {
if (!_IsInited) { if (!_IsInited) {
return false; return false;
@@ -342,16 +306,11 @@ public class LogUtils {
return isInTheLevel(logLevel); return isInTheLevel(logLevel);
} }
/**
* 判断日志级别是否匹配输出等级
* @param logLevel 待判断级别
* @return 是否达标
*/
private static boolean isInTheLevel(final LOG_LEVEL logLevel) { private static boolean isInTheLevel(final LOG_LEVEL logLevel) {
return _mLogUtilsBean.getLogLevel().ordinal() >= logLevel.ordinal(); return _mLogUtilsBean.getLogLevel().ordinal() >= logLevel.ordinal();
} }
// ====================== 对外基础工具方法 ====================== // ====================== 基础对外方法 ======================
public static File getLogCacheDir() { public static File getLogCacheDir() {
return _mfLogCacheDir; return _mfLogCacheDir;
} }
@@ -360,7 +319,7 @@ public class LogUtils {
return _IsInited; return _IsInited;
} }
// ====================== Error 日志重载 ====================== // ====================== Error 日志重载(补齐缺失方法) ======================
public static void e(final String szTAG, final String szMessage) { public static void e(final String szTAG, final String szMessage) {
if (isLoggable(szTAG, LOG_LEVEL.Error)) { if (isLoggable(szTAG, LOG_LEVEL.Error)) {
saveLog(szTAG, LOG_LEVEL.Error, szMessage); saveLog(szTAG, LOG_LEVEL.Error, szMessage);
@@ -391,6 +350,17 @@ public class LogUtils {
} }
} }
/**
* 补齐你需要的LogUtils.e(TAG, "uncaughtException: 崩溃处理异常", e)
*/
public static void e(final String szTAG, final String szMessage, final Throwable e) {
if (isLoggable(szTAG, LOG_LEVEL.Error)) {
final StringBuilder sb = new StringBuilder(szMessage);
sb.append("\n【异常信息】: ").append(getThrowableInfo(e));
saveLog(szTAG, LOG_LEVEL.Error, sb.toString());
}
}
// ====================== Warn 日志重载 ====================== // ====================== Warn 日志重载 ======================
public static void w(final String szTAG, final String szMessage) { public static void w(final String szTAG, final String szMessage) {
if (isLoggable(szTAG, LOG_LEVEL.Warn)) { if (isLoggable(szTAG, LOG_LEVEL.Warn)) {
@@ -560,6 +530,24 @@ public class LogUtils {
return sb.toString(); return sb.toString();
} }
private static String getThrowableInfo(final Throwable e) {
if (e == null) {
return "异常对象为null";
}
final StringBuilder sb = new StringBuilder();
sb.append(e.getClass().getSimpleName()).append(" : ")
.append(e.getMessage() == null ? "无异常消息" : e.getMessage());
final StackTraceElement[] stackTrace = e.getStackTrace();
if (stackTrace != null && stackTrace.length > 0) {
final int limit = Math.min(stackTrace.length, 5);
for (int i = 0; i < limit; i++) {
sb.append("\n ").append(stackTrace[i].toString());
}
}
return sb.toString();
}
private static String getStackTraceInfo(final StackTraceElement[] stackTrace) { private static String getStackTraceInfo(final StackTraceElement[] stackTrace) {
if (stackTrace == null || stackTrace.length == 0) { if (stackTrace == null || stackTrace.length == 0) {
return "堆栈信息为空"; return "堆栈信息为空";
@@ -646,15 +634,23 @@ public class LogUtils {
Log.d(TAG, "cleanLog 日志文件未初始化"); Log.d(TAG, "cleanLog 日志文件未初始化");
return; return;
} }
BufferedWriter out = null;
try { try {
final BufferedWriter out = new BufferedWriter(new OutputStreamWriter( out = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(_mfLogCatchFile, false), "UTF-8")); new FileOutputStream(_mfLogCatchFile, false), "UTF-8"));
out.write(""); out.write("");
out.flush(); out.flush();
out.close();
Log.d(TAG, "cleanLog 日志已清空"); Log.d(TAG, "cleanLog 日志已清空");
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "cleanLog 清空日志失败", e); Log.e(TAG, "cleanLog 清空日志失败", e);
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
Log.e(TAG, "cleanLog 流关闭异常", e);
}
}
} }
} }
@@ -674,10 +670,11 @@ public class LogUtils {
if (Thread.currentThread().getId() == android.os.Process.myTid()) { if (Thread.currentThread().getId() == android.os.Process.myTid()) {
Toast.makeText(context, message, Toast.LENGTH_SHORT).show(); Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
} else { } else {
((android.app.Activity) context).runOnUiThread(new Runnable() { final Context uiContext = context;
((android.app.Activity) uiContext).runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
Toast.makeText(context, message, Toast.LENGTH_SHORT).show(); Toast.makeText(uiContext, message, Toast.LENGTH_SHORT).show();
} }
}); });
} }

View File

@@ -2,16 +2,18 @@
<LinearLayout <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:theme="?attr/themeDebug"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/activityBackgroundColor" android:background="?attr/colorTextBackgound"
android:id="@+id/viewglobalcrashreportLinearLayout1"> android:id="@+id/viewglobalcrashreportLinearLayout1">
<android.widget.Toolbar <android.widget.Toolbar
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/toolbarBackgroundColor" android:background="?attr/colorTittleBackgound"
android:titleTextColor="?attr/colorTittle"
android:id="@+id/viewglobalcrashreportToolbar1"/> android:id="@+id/viewglobalcrashreportToolbar1"/>
<ScrollView <ScrollView
@@ -28,7 +30,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="16dp" android:padding="16dp"
android:textColor="?attr/activityTextColor" android:textColor="?attr/colorText"
android:id="@+id/viewglobalcrashreportTextView1"/> android:id="@+id/viewglobalcrashreportTextView1"/>
</HorizontalScrollView> </HorizontalScrollView>

View File

@@ -1,17 +1,18 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:theme="?attr/themeDebug"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/activityBackgroundColor"> android:background="?attr/colorTextBackgound">
<RelativeLayout <RelativeLayout
android:orientation="horizontal" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="34dp" android:layout_height="34dp"
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:background="?attr/toolbarBackgroundColor" android:background="?attr/colorTittleBackgound"
android:id="@+id/viewlogRelativeLayoutToolbar"> android:id="@+id/viewlogRelativeLayoutToolbar">
<Button <Button
@@ -19,8 +20,8 @@
android:layout_height="@dimen/log_button_height" android:layout_height="@dimen/log_button_height"
android:textSize="@dimen/log_text_size" android:textSize="@dimen/log_text_size"
android:text="Clean" android:text="Clean"
android:textColor="?attr/buttonTextColor" android:textColor="?attr/colorText"
android:backgroundTint="?attr/buttonBackgroundColor" android:backgroundTint="?attr/colorTittleBackgound"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:id="@+id/viewlogButtonClean" android:id="@+id/viewlogButtonClean"
android:layout_marginLeft="5dp"/> android:layout_marginLeft="5dp"/>
@@ -34,8 +35,8 @@
android:layout_toRightOf="@+id/viewlogButtonClean" android:layout_toRightOf="@+id/viewlogButtonClean"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:id="@+id/viewlogTextView1" android:id="@+id/viewlogTextView1"
android:background="?attr/buttonBackgroundColor" android:background="?attr/colorTittleBackgound"
android:textColor="?attr/buttonTextColor"/> android:textColor="?attr/colorText"/>
<cc.winboll.studio.libappbase.widget.LogTagSpinner <cc.winboll.studio.libappbase.widget.LogTagSpinner
android:layout_width="wrap_content" android:layout_width="wrap_content"
@@ -52,17 +53,17 @@
android:layout_toLeftOf="@+id/viewlogButtonCopy" android:layout_toLeftOf="@+id/viewlogButtonCopy"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:text="Selectable" android:text="Selectable"
android:background="?attr/buttonBackgroundColor" android:background="?attr/colorTittleBackgound"
android:id="@+id/viewlogCheckBoxSelectable" android:id="@+id/viewlogCheckBoxSelectable"
android:padding="@dimen/log_text_padding" android:padding="@dimen/log_text_padding"
android:textColor="?attr/buttonTextColor"/> android:textColor="?attr/colorText"/>
<Button <Button
android:layout_width="@dimen/log_button_width" android:layout_width="@dimen/log_button_width"
android:layout_height="@dimen/log_button_height" android:layout_height="@dimen/log_button_height"
android:textSize="@dimen/log_text_size" android:textSize="@dimen/log_text_size"
android:textColor="?attr/buttonTextColor" android:textColor="?attr/colorText"
android:backgroundTint="?attr/buttonBackgroundColor" android:backgroundTint="?attr/colorTittleBackgound"
android:text="Copy" android:text="Copy"
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:layout_centerVertical="true" android:layout_centerVertical="true"
@@ -78,7 +79,7 @@
android:layout_below="@+id/viewlogRelativeLayoutToolbar" android:layout_below="@+id/viewlogRelativeLayoutToolbar"
android:id="@+id/viewlogLinearLayout1" android:id="@+id/viewlogLinearLayout1"
android:gravity="center_vertical" android:gravity="center_vertical"
android:background="?attr/toolbarBackgroundColor"> android:background="?attr/colorTittleBackgound">
<CheckBox <CheckBox
android:layout_width="wrap_content" android:layout_width="wrap_content"
@@ -87,8 +88,8 @@
android:text="ALL" android:text="ALL"
android:padding="2dp" android:padding="2dp"
android:id="@+id/viewlogCheckBox1" android:id="@+id/viewlogCheckBox1"
android:background="?attr/buttonBackgroundColor" android:background="?attr/colorTittleBackgound"
android:textColor="?attr/buttonTextColor" android:textColor="?attr/colorText"
android:layout_marginLeft="5dp" android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"/> android:layout_marginRight="5dp"/>
@@ -97,15 +98,15 @@
android:ems="10" android:ems="10"
android:layout_height="@dimen/log_button_height" android:layout_height="@dimen/log_button_height"
android:textSize="@dimen/log_text_size" android:textSize="@dimen/log_text_size"
android:textColor="?attr/activityTextColor" android:textColor="?attr/colorText"
android:background="?attr/buttonBackgroundColor" android:background="?attr/colorTittleBackgound"
android:singleLine="true" android:singleLine="true"
android:id="@+id/tagsearch_et"/> android:id="@+id/tagsearch_et"/>
<HorizontalScrollView <HorizontalScrollView
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/buttonBackgroundColor" android:background="?attr/colorTittleBackgound"
android:scrollbars="none" android:scrollbars="none"
android:padding="2dp" android:padding="2dp"
android:layout_weight="1.0" android:layout_weight="1.0"
@@ -131,7 +132,7 @@
<ScrollView <ScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/activityBackgroundColor" android:background="?attr/colorTextBackgound"
android:id="@+id/viewlogScrollViewLog"> android:id="@+id/viewlogScrollViewLog">
<TextView <TextView
@@ -139,7 +140,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:textSize="@dimen/log_text_size" android:textSize="@dimen/log_text_size"
android:text="Text" android:text="Text"
android:textColor="#FF00FF00" android:textColor="?attr/debugTextColor"
android:textIsSelectable="true" android:textIsSelectable="true"
android:id="@+id/viewlogTextViewLog"/> android:id="@+id/viewlogTextViewLog"/>

View File

@@ -5,7 +5,7 @@
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/activityBackgroundColor">> android:background="?attr/activityBackgroundColor">
<cc.winboll.studio.libappbase.GlobalCrashReportView <cc.winboll.studio.libappbase.GlobalCrashReportView
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@@ -2,16 +2,18 @@
<LinearLayout <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:theme="?attr/themeDebug"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/activityBackgroundColor" android:background="?attr/colorTextBackgound"
android:id="@+id/viewglobalcrashreportLinearLayout1"> android:id="@+id/viewglobalcrashreportLinearLayout1">
<android.widget.Toolbar <android.widget.Toolbar
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/toolbarBackgroundColor" android:background="?attr/colorTittleBackgound"
android:titleTextColor="?attr/colorTittle"
android:id="@+id/viewglobalcrashreportToolbar1"/> android:id="@+id/viewglobalcrashreportToolbar1"/>
<ScrollView <ScrollView
@@ -28,7 +30,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="16dp" android:padding="16dp"
android:textColor="?attr/activityTextColor" android:textColor="?attr/colorText"
android:id="@+id/viewglobalcrashreportTextView1"/> android:id="@+id/viewglobalcrashreportTextView1"/>
</HorizontalScrollView> </HorizontalScrollView>

View File

@@ -1,17 +1,18 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:theme="?attr/themeDebug"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/activityBackgroundColor"> android:background="?attr/colorTextBackgound">
<RelativeLayout <RelativeLayout
android:orientation="horizontal" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="34dp" android:layout_height="34dp"
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:background="?attr/toolbarBackgroundColor" android:background="?attr/colorTittleBackgound"
android:id="@+id/viewlogRelativeLayoutToolbar"> android:id="@+id/viewlogRelativeLayoutToolbar">
<Button <Button
@@ -19,8 +20,8 @@
android:layout_height="@dimen/log_button_height" android:layout_height="@dimen/log_button_height"
android:textSize="@dimen/log_text_size" android:textSize="@dimen/log_text_size"
android:text="Clean" android:text="Clean"
android:textColor="?attr/buttonTextColor" android:textColor="?attr/colorText"
android:backgroundTint="?attr/buttonBackgroundColor" android:backgroundTint="?attr/colorTittleBackgound"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:id="@+id/viewlogButtonClean" android:id="@+id/viewlogButtonClean"
android:layout_marginLeft="5dp"/> android:layout_marginLeft="5dp"/>
@@ -34,8 +35,8 @@
android:layout_toRightOf="@+id/viewlogButtonClean" android:layout_toRightOf="@+id/viewlogButtonClean"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:id="@+id/viewlogTextView1" android:id="@+id/viewlogTextView1"
android:background="?attr/buttonBackgroundColor" android:background="?attr/colorTittleBackgound"
android:textColor="?attr/buttonTextColor"/> android:textColor="?attr/colorText"/>
<cc.winboll.studio.libappbase.widget.LogTagSpinner <cc.winboll.studio.libappbase.widget.LogTagSpinner
android:layout_width="wrap_content" android:layout_width="wrap_content"
@@ -52,17 +53,17 @@
android:layout_toLeftOf="@+id/viewlogButtonCopy" android:layout_toLeftOf="@+id/viewlogButtonCopy"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:text="Selectable" android:text="Selectable"
android:background="?attr/buttonBackgroundColor" android:background="?attr/colorTittleBackgound"
android:id="@+id/viewlogCheckBoxSelectable" android:id="@+id/viewlogCheckBoxSelectable"
android:padding="@dimen/log_text_padding" android:padding="@dimen/log_text_padding"
android:textColor="?attr/buttonTextColor"/> android:textColor="?attr/colorText"/>
<Button <Button
android:layout_width="@dimen/log_button_width" android:layout_width="@dimen/log_button_width"
android:layout_height="@dimen/log_button_height" android:layout_height="@dimen/log_button_height"
android:textSize="@dimen/log_text_size" android:textSize="@dimen/log_text_size"
android:textColor="?attr/buttonTextColor" android:textColor="?attr/colorText"
android:backgroundTint="?attr/buttonBackgroundColor" android:backgroundTint="?attr/colorTittleBackgound"
android:text="Copy" android:text="Copy"
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:layout_centerVertical="true" android:layout_centerVertical="true"
@@ -78,7 +79,7 @@
android:layout_below="@+id/viewlogRelativeLayoutToolbar" android:layout_below="@+id/viewlogRelativeLayoutToolbar"
android:id="@+id/viewlogLinearLayout1" android:id="@+id/viewlogLinearLayout1"
android:gravity="center_vertical" android:gravity="center_vertical"
android:background="?attr/toolbarBackgroundColor"> android:background="?attr/colorTittleBackgound">
<CheckBox <CheckBox
android:layout_width="wrap_content" android:layout_width="wrap_content"
@@ -87,8 +88,8 @@
android:text="ALL" android:text="ALL"
android:padding="2dp" android:padding="2dp"
android:id="@+id/viewlogCheckBox1" android:id="@+id/viewlogCheckBox1"
android:background="?attr/buttonBackgroundColor" android:background="?attr/colorTittleBackgound"
android:textColor="?attr/buttonTextColor" android:textColor="?attr/colorText"
android:layout_marginLeft="5dp" android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"/> android:layout_marginRight="5dp"/>
@@ -97,15 +98,15 @@
android:ems="10" android:ems="10"
android:layout_height="@dimen/log_button_height" android:layout_height="@dimen/log_button_height"
android:textSize="@dimen/log_text_size" android:textSize="@dimen/log_text_size"
android:textColor="?attr/activityTextColor" android:textColor="?attr/colorText"
android:background="?attr/buttonBackgroundColor" android:background="?attr/colorTittleBackgound"
android:singleLine="true" android:singleLine="true"
android:id="@+id/tagsearch_et"/> android:id="@+id/tagsearch_et"/>
<HorizontalScrollView <HorizontalScrollView
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/buttonBackgroundColor" android:background="?attr/colorTittleBackgound"
android:scrollbars="none" android:scrollbars="none"
android:padding="2dp" android:padding="2dp"
android:layout_weight="1.0" android:layout_weight="1.0"
@@ -131,7 +132,7 @@
<ScrollView <ScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/activityBackgroundColor" android:background="?attr/colorTextBackgound"
android:id="@+id/viewlogScrollViewLog"> android:id="@+id/viewlogScrollViewLog">
<TextView <TextView
@@ -139,7 +140,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:textSize="@dimen/log_text_size" android:textSize="@dimen/log_text_size"
android:text="Text" android:text="Text"
android:textColor="#FF00FF00" android:textColor="?attr/debugTextColor"
android:textIsSelectable="true" android:textIsSelectable="true"
android:id="@+id/viewlogTextViewLog"/> android:id="@+id/viewlogTextViewLog"/>

View File

@@ -2,7 +2,7 @@
<resources> <resources>
<!-- 全局主题属性 --> <!-- 全局主题属性 -->
<attr name="themeGlobalCrashActivity" format="reference"/> <attr name="themeDebug" format="reference"/>
<!-- GlobalCrashActivity 样式属性 --> <!-- GlobalCrashActivity 样式属性 -->
<declare-styleable name="GlobalCrashActivity"> <declare-styleable name="GlobalCrashActivity">
@@ -47,4 +47,15 @@
<attr name="activityBackgroundColor" format="color"/> <attr name="activityBackgroundColor" format="color"/>
<attr name="activityTextColor" format="color"/> <attr name="activityTextColor" format="color"/>
<!-- MainWindowStyle 主窗口样式属性 -->
<attr name="mainWindowBackgroundColor" format="color"/>
<attr name="mainWindowTextColor" format="color"/>
<!-- MainWindowDarkStyle 深色模式主窗口样式属性 -->
<attr name="mainWindowDarkBackgroundColor" format="color"/>
<attr name="mainWindowDarkTextColor" format="color"/>
<!-- DebugLogStyle 应用调试日志样式属性 -->
<attr name="debugTextColor" format="color"/>
</resources> </resources>

View File

@@ -60,4 +60,10 @@
<color name="btn_gray_pressed">#4D4D4D</color> <color name="btn_gray_pressed">#4D4D4D</color>
<color name="btn_gray_disabled">#333333</color> <color name="btn_gray_disabled">#333333</color>
<!-- ============== 主题颜色 ============== -->
<color name="mainWindowBackgroundColor">#FF0D1B2A</color>
<color name="mainWindowTextColor">#FFE0E0E0</color>
<color name="buttonBackgroundColor">#FF1E3A5F</color>
<color name="debugTextColor">#FF00FF00</color>
</resources> </resources>

View File

@@ -3,33 +3,38 @@
<!-- APPBaseTheme 深色模式主题 --> <!-- APPBaseTheme 深色模式主题 -->
<style name="APPBaseTheme" parent="@android:style/Theme.DeviceDefault.NoActionBar"> <style name="APPBaseTheme" parent="@android:style/Theme.DeviceDefault.NoActionBar">
<item name="themeGlobalCrashActivity">@style/GlobalCrashActivityTheme</item> <item name="themeDebug">@style/DebugActivityTheme</item>
<item name="aboutViewBackgroundColor">#FF0D1B2A</item> <item name="aboutViewBackgroundColor">?attr/mainWindowDarkBackgroundColor</item>
<item name="aboutViewTextColor">#FFE0E0E0</item> <item name="aboutViewTextColor">?attr/mainWindowDarkTextColor</item>
<item name="aboutViewTitleColor">#FFE0E0E0</item> <item name="aboutViewTitleColor">?attr/mainWindowDarkTextColor</item>
<item name="aboutViewDividerColor">#FF333333</item> <item name="aboutViewDividerColor">?attr/mainWindowTextColor</item>
<item name="buttonBackgroundColor">#FF1E3A5F</item> <item name="buttonBackgroundColor">@color/buttonBackgroundColor</item>
<item name="buttonTextColor">#FFE0E0E0</item> <item name="buttonTextColor">?attr/mainWindowDarkTextColor</item>
<item name="dialogBackgroundColor">#FF0D1B2A</item> <item name="dialogBackgroundColor">?attr/mainWindowDarkBackgroundColor</item>
<item name="dialogTextColor">#FFE0E0E0</item> <item name="dialogTextColor">?attr/mainWindowDarkTextColor</item>
<item name="toolbarBackgroundColor">#FF1E3A5F</item> <item name="toolbarBackgroundColor">?attr/buttonBackgroundColor</item>
<item name="toolbarTextColor">#FFE0E0E0</item> <item name="toolbarTextColor">?attr/mainWindowDarkTextColor</item>
<item name="textViewBackgroundColor">#FF0D1B2A</item> <item name="textViewBackgroundColor">?attr/mainWindowDarkBackgroundColor</item>
<item name="textViewTextColor">#FFE0E0E0</item> <item name="textViewTextColor">?attr/mainWindowDarkTextColor</item>
<item name="editTextBackgroundColor">#FF1E3A5F</item> <item name="editTextBackgroundColor">?attr/mainWindowDarkBackgroundColor</item>
<item name="editTextTextColor">#FFE0E0E0</item> <item name="editTextTextColor">?attr/mainWindowDarkTextColor</item>
<item name="scrollViewBackgroundColor">#FF0D1B2A</item> <item name="scrollViewBackgroundColor">?attr/mainWindowDarkBackgroundColor</item>
<item name="activityBackgroundColor">#FF0D1B2A</item> <item name="activityBackgroundColor">?attr/mainWindowDarkBackgroundColor</item>
<item name="activityTextColor">#FFE0E0E0</item> <item name="activityTextColor">?attr/mainWindowDarkTextColor</item>
<item name="mainWindowBackgroundColor">@color/mainWindowBackgroundColor</item>
<item name="mainWindowTextColor">@color/mainWindowTextColor</item>
<item name="mainWindowDarkBackgroundColor">@color/mainWindowBackgroundColor</item>
<item name="mainWindowDarkTextColor">@color/mainWindowTextColor</item>
</style> </style>
<!-- GlobalCrashActivityTheme 深色模式样式 --> <!-- DebugActivityTheme 深色模式样式 -->
<style name="GlobalCrashActivityTheme" parent="@android:style/Theme.DeviceDefault.NoActionBar"> <style name="DebugActivityTheme" parent="@android:style/Theme.DeviceDefault.NoActionBar">
<item name="android:statusBarColor">#FF0D1B2A</item> <item name="android:statusBarColor">@color/mainWindowBackgroundColor</item>
<item name="colorTittle">#FFE0E0E0</item> <item name="colorTittle">?attr/mainWindowDarkTextColor</item>
<item name="colorTittleBackgound">#FF1E3A5F</item> <item name="colorTittleBackgound">@color/buttonBackgroundColor</item>
<item name="colorText">#FFE0E0E0</item> <item name="colorText">?attr/debugTextColor</item>
<item name="colorTextBackgound">#FF0D1B2A</item> <item name="colorTextBackgound">?attr/mainWindowDarkBackgroundColor</item>
<item name="debugTextColor">@color/debugTextColor</item>
</style> </style>
<!-- DialogStyle 对话框样式 --> <!-- DialogStyle 对话框样式 -->

View File

@@ -2,7 +2,7 @@
<resources> <resources>
<!-- 全局主题属性 --> <!-- 全局主题属性 -->
<attr name="themeGlobalCrashActivity" format="reference"/> <attr name="themeDebug" format="reference"/>
<!-- AboutView 样式属性 --> <!-- AboutView 样式属性 -->
<declare-styleable name="AboutView"> <declare-styleable name="AboutView">
@@ -53,4 +53,15 @@
<attr name="activityBackgroundColor" format="color"/> <attr name="activityBackgroundColor" format="color"/>
<attr name="activityTextColor" format="color"/> <attr name="activityTextColor" format="color"/>
<!-- MainWindowStyle 主窗口样式属性 -->
<attr name="mainWindowBackgroundColor" format="color"/>
<attr name="mainWindowTextColor" format="color"/>
<!-- MainWindowDarkStyle 深色模式主窗口样式属性 -->
<attr name="mainWindowDarkBackgroundColor" format="color"/>
<attr name="mainWindowDarkTextColor" format="color"/>
<!-- DebugLogStyle 应用调试日志样式属性 -->
<attr name="debugTextColor" format="color"/>
</resources> </resources>

View File

@@ -60,4 +60,10 @@
<color name="btn_gray_pressed">#757575</color> <color name="btn_gray_pressed">#757575</color>
<color name="btn_gray_disabled">#E0E0E0</color> <color name="btn_gray_disabled">#E0E0E0</color>
<!-- ============== 主题颜色 ============== -->
<color name="mainWindowBackgroundColor">#FFF5F5F5</color>
<color name="mainWindowTextColor">#FF000000</color>
<color name="buttonBackgroundColor">#FF00B322</color>
<color name="debugTextColor">#FF808080</color>
</resources> </resources>

View File

@@ -3,4 +3,6 @@
<string name="lib_name">libappbase</string> <string name="lib_name">libappbase</string>
<string name="hello_world">Hello, world!</string> <string name="hello_world">Hello, world!</string>
<string name="shared_user_id">cc.winboll.studio</string>
<string name="shared_user_label">studio@winboll.cc</string>
</resources> </resources>

View File

@@ -3,33 +3,38 @@
<!-- APPBaseTheme 普通模式主题 --> <!-- APPBaseTheme 普通模式主题 -->
<style name="APPBaseTheme" parent="@android:style/Theme.DeviceDefault.Light.NoActionBar"> <style name="APPBaseTheme" parent="@android:style/Theme.DeviceDefault.Light.NoActionBar">
<item name="themeGlobalCrashActivity">@style/GlobalCrashActivityTheme</item> <item name="themeDebug">@style/DebugActivityTheme</item>
<item name="aboutViewBackgroundColor">#FFF5F5F5</item> <item name="aboutViewBackgroundColor">?attr/mainWindowBackgroundColor</item>
<item name="aboutViewTextColor">#FF000000</item> <item name="aboutViewTextColor">?attr/mainWindowTextColor</item>
<item name="aboutViewTitleColor">#FF000000</item> <item name="aboutViewTitleColor">?attr/mainWindowTextColor</item>
<item name="aboutViewDividerColor">#FFE0E0E0</item> <item name="aboutViewDividerColor">?attr/mainWindowDarkTextColor</item>
<item name="buttonBackgroundColor">#FF00B322</item> <item name="buttonBackgroundColor">@color/buttonBackgroundColor</item>
<item name="buttonTextColor">#FF000000</item> <item name="buttonTextColor">?attr/mainWindowTextColor</item>
<item name="dialogBackgroundColor">#FFF5F5F5</item> <item name="dialogBackgroundColor">?attr/mainWindowBackgroundColor</item>
<item name="dialogTextColor">#FF000000</item> <item name="dialogTextColor">?attr/mainWindowTextColor</item>
<item name="toolbarBackgroundColor">#FF00B322</item> <item name="toolbarBackgroundColor">?attr/buttonBackgroundColor</item>
<item name="toolbarTextColor">#FF000000</item> <item name="toolbarTextColor">?attr/mainWindowTextColor</item>
<item name="textViewBackgroundColor">#FFF5F5F5</item> <item name="textViewBackgroundColor">?attr/mainWindowBackgroundColor</item>
<item name="textViewTextColor">#FF000000</item> <item name="textViewTextColor">?attr/mainWindowTextColor</item>
<item name="editTextBackgroundColor">#FFFFFFFF</item> <item name="editTextBackgroundColor">?attr/mainWindowBackgroundColor</item>
<item name="editTextTextColor">#FF000000</item> <item name="editTextTextColor">?attr/mainWindowTextColor</item>
<item name="scrollViewBackgroundColor">#FFF5F5F5</item> <item name="scrollViewBackgroundColor">?attr/mainWindowBackgroundColor</item>
<item name="activityBackgroundColor">#FFF5F5F5</item> <item name="activityBackgroundColor">?attr/mainWindowBackgroundColor</item>
<item name="activityTextColor">#FF000000</item> <item name="activityTextColor">?attr/mainWindowTextColor</item>
<item name="mainWindowBackgroundColor">@color/mainWindowBackgroundColor</item>
<item name="mainWindowTextColor">@color/mainWindowTextColor</item>
<item name="mainWindowDarkBackgroundColor">@color/mainWindowBackgroundColor</item>
<item name="mainWindowDarkTextColor">@color/mainWindowTextColor</item>
</style> </style>
<!-- GlobalCrashActivityTheme 普通模式样式 --> <!-- DebugActivityTheme 普通模式样式 -->
<style name="GlobalCrashActivityTheme" parent="@android:style/Theme.DeviceDefault.Light.NoActionBar"> <style name="DebugActivityTheme" parent="@android:style/Theme.DeviceDefault.Light.NoActionBar">
<item name="android:statusBarColor">#FF00B322</item> <item name="android:statusBarColor">@color/buttonBackgroundColor</item>
<item name="colorTittle">#FF000000</item> <item name="colorTittle">?attr/mainWindowTextColor</item>
<item name="colorTittleBackgound">#FF00B322</item> <item name="colorTittleBackgound">@color/buttonBackgroundColor</item>
<item name="colorText">#FF000000</item> <item name="colorText">?attr/debugTextColor</item>
<item name="colorTextBackgound">#FFF5F5F5</item> <item name="colorTextBackgound">?attr/mainWindowBackgroundColor</item>
<item name="debugTextColor">@color/debugTextColor</item>
</style> </style>
<!-- DialogStyle 对话框样式 --> <!-- DialogStyle 对话框样式 -->