Compare commits

...

45 Commits

Author SHA1 Message Date
998cb3d193 <winboll>APK 15.20.0 release Publish. 2026-05-12 12:16:45 +08:00
9ba3374b16 基线版本号对齐 2026-05-12 12:11:17 +08:00
4ded8537e8 升级 WinBoLL 库依赖版本并完善应用主题配置
- 升级 WinBoLL 库依赖版本至 15.20.x 系列:
  - libaes: 15.15.10 → 15.20.2
  - libappbase: 15.15.23 → 15.20.9
- 完善 winboll 模块主题配置:
  - MyAppTheme 改用 Theme.AppCompat.Light.NoActionBar 解决 AppCompat 兼容问题
  - 添加完整的应用主题属性定义
  - 添加 MyDebugActivityTheme 调试主题
- 添加主窗口、工具栏、调试文字颜色定义
2026-05-12 12:05:28 +08:00
59e51da991 Merge remote-tracking branch 'origin/aes' into winboll 2026-05-12 11:42:13 +08:00
070e2fb4f0 Merge remote-tracking branch 'origin/appbase' into winboll 2026-05-12 11:42:07 +08:00
632ecc51d8 重构ASupportToolbar自定义控件,支持AES主题切换
- 优化ASupportToolbar控件的绘图流程
- 移除atoolbar_frame.xml依赖,改用Java代码内部绘图
- 添加notifyColorChange()方法绘制三层渐变背景
- 在onAttachedToWindow()时自动调用refreshFromTheme()刷新背景
- 主题切换时通过DrawerFragmentActivity调用refreshFromTheme()
- 添加attrs.xml属性:android:background用于自定义style
- 添加详细调试日志追踪整个绘制流程
- TestASupportToolbarActivity添加日志便于测试验证

修改文件:
- libaes/src/main/java/.../views/ASupportToolbar.java:重构绘图逻辑,添加调试日志
- libaes/src/main/java/.../activitys/DrawerFragmentActivity.java:主题切换时刷新Toolbar
- libaes/src/main/java/.../unittests/TestASupportToolbarActivity.java:添加调试日志
- libaes/src/main/res/values/attrs.xml:添加android:background属性
- aes/build.properties:版本号更新
- libaes/build.properties:版本号更新
2026-05-12 10:53:18 +08:00
58b2cace16 重构AES主题配置,继承APPBaseTheme属性支持
- AESTheme改为继承Theme.AppCompat并支持APPBaseTheme属性
- 修复运行时inflate错误:将?attr/xxx引用改为@color/xxx直接引用
- 添加DebugActivityTheme调试样式支持
- 添加必需的颜色定义(toolbarBackgroundColor、mainWindowBackgroundColor等)
- 新增夜间模式主题配置(values-night目录)
- 清理冗余注释和无用的调试配色方案
- aes模块的MyAESTheme添加themeDebug属性

修改文件:
- aes/src/main/res/values/styles.xml:添加MyDebugActivityTheme
- aes/src/main/res/values-night/:新增夜间模式样式
- libaes/src/main/res/values/colors.xml:添加主题必需颜色
- libaes/src/main/res/values/styles.xml:重构使用AppCompat主题
- libaes/src/main/res/values-night/:新增夜间模式颜色和样式
2026-05-12 09:52:57 +08:00
3648fa3361 更新基础类库版本 2026-05-12 09:26:33 +08:00
122122ef80 Merge remote-tracking branch 'origin/appbase' into aes 2026-05-12 09:22:37 +08:00
4caeb83e5e <libappbase>Library Release 15.20.9 2026-05-12 09:17:18 +08:00
f36ee0d9b1 <appbase>APK 15.20.9 release Publish. 2026-05-12 09:16:45 +08:00
fe0b2f97ea 重构日志窗口UI主题颜色系统,统一使用toolbarTextColor和toolbarBackgroundColor
【主要变更】

1. 新增主题颜色属性
   - 新增 toolbarTextColor 属性定义(普通模式:黑色, 深色模式:#E0E0E0)
   - 新增 toolbarBackgroundColor 属性定义(普通模式:绿色, 深色模式:深蓝色)

2. 移除废弃颜色属性
   - 移除 buttonTextColor 属性定义
   - 移除 buttonBackgroundColor 属性定义

3. 更新布局文件(普通模式+深色模式)
   - view_log.xml: TextView(LV:)、CheckBox(Selectable/ALL) 使用 toolbarTextColor
   - view_log.xml: Button(Clean/Copy) 使用 toolbarBackgroundColor
   - item_logtag.xml: CheckBox 使用 toolbarTextColor
   - activity_main.xml: 所有Button使用 toolbarBackgroundColor
   - activity_crash_test.xml: 所有Button使用 toolbarBackgroundColor
   - activity_nfc_rsa_operate.xml: Button使用 toolbarBackgroundColor
   - dialog_winboll_host.xml: Button使用 toolbarBackgroundColor

4. 更新Java代码
   - LogView.java: CheckBox和TextView使用主题属性获取 toolbarTextColor
   - LogTagSpinner.java: 下拉框文本颜色使用 toolbarTextColor

5. 更新样式定义
   - styles.xml: 主题属性引用新的 toolbarTextColor/toolbarBackgroundColor
   - attrs.xml: 移除废弃属性,保留 toolbarTextColor/toolbarBackgroundColor
   - colors.xml: 添加新的颜色定义

【适配说明】
- 统一普通模式和深色模式的颜色管理
- 确保日志窗口所有控件颜色与主窗口保持一致
2026-05-12 09:13:16 +08:00
43da2bc03a 统一日志窗口Clean/Copy按钮样式与主窗口保持一致 2026-05-12 00:33:14 +08:00
d26ef7bf7f Merge remote-tracking branch 'origin/appbase' into aes 2026-05-11 21:18:47 +08:00
6baca2779d 同步build.gradle至origin/winboll分支最新配置 2026-05-11 21:13:50 +08:00
83da84371c Merge remote-tracking branch 'origin/aes' into winboll 2026-05-11 20:59:23 +08:00
f0fbdaf121 <libaes>Library Release 15.20.2 2026-05-11 20:41:44 +08:00
a20f29728e <aes>APK 15.20.2 release Publish. 2026-05-11 20:41:30 +08:00
9669fe2a8d 更新应用基础类库,改进应用调试接口。 2026-05-11 20:38:17 +08:00
ff8cb2fb42 <libappbase>Library Release 15.20.8 2026-05-11 20:30:07 +08:00
e42219ac5a <appbase>APK 15.20.8 release Publish. 2026-05-11 20:29:55 +08:00
42112eb677 LibAppBase: 添加崩溃通知分享日志功能
- 在崩溃通知中添加"分享日志"按钮,点击可分享崩溃日志
- 新增 ShareLogActivity 窗口类处理分享逻辑
- 崩溃日志先保存到缓存文件,再读取分享
- 移除广播接收器方案,简化实现
- 更新 AndroidManifest 注册新 Activity

修改文件:
- libappbase/src/main/AndroidManifest.xml
- libappbase/src/main/java/.../utils/CrashHandleNotifyUtils.java
- libappbase/src/main/java/.../utils/ShareLogActivity.java (新增)

影响范围: 崩溃通知功能
2026-05-11 20:27:40 +08:00
f3114a8121 <libappbase>Library Release 15.20.7 2026-05-11 19:10:54 +08:00
b5b29b8a77 <appbase>APK 15.20.7 release Publish. 2026-05-11 19:10:34 +08:00
01b0a7736d feat(CrashHandleNotifyUtils): 增强崩溃通知摘要提取与展示逻辑
- 新增正则表达式解析崩溃日志,提取异常类型、消息、原因及堆栈信息
- 实现 extractBriefInfo() 方法,生成结构化的崩溃摘要
- 优化通知内容展示:异常类型 + 错误信息 + 关键堆栈(最多3行)
- 添加摘要最大长度控制(200字符),防止内容过长
- 新增展开通知布局文件支持
2026-05-11 19:02:51 +08:00
ed5ab24bd3 <libaes>Library Release 15.20.1 2026-05-11 17:17:23 +08:00
b5c989b5f9 <aes>APK 15.20.1 release Publish. 2026-05-11 17:17:05 +08:00
725b336501 更新基础类库版本,提高应用调试能力。 2026-05-11 17:14:00 +08:00
d20923eaee <libappbase>Library Release 15.20.6 2026-05-11 16:56:33 +08:00
9db3b3b703 <appbase>APK 15.20.6 release Publish. 2026-05-11 16:56:19 +08:00
744fb23291 完成应用崩溃事务处理逻辑。 2026-05-11 16:53:51 +08:00
bd01220892 20260511_164013_233 2026-05-11 16:40:16 +08:00
4b2b5acc99 20260511_152720_122 2026-05-11 15:27:25 +08:00
57e4f8770b <libaes>Library Release 15.20.0 2026-05-11 15:02:44 +08:00
3b313e2362 <aes>APK 15.20.0 release Publish. 2026-05-11 15:02:27 +08:00
1e96cd02bc 对齐基础类库基准型号版本。 2026-05-11 14:58:21 +08:00
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
8f869e19cc 更新基础类库 2026-05-10 05:12:19 +08:00
270e21ed23 <libaes>Library Release 15.15.10 2026-05-10 05:04:34 +08:00
6412554096 <aes>APK 15.15.10 release Publish. 2026-05-10 05:04:15 +08:00
286f8513d4 refactor: 升级编译配置并调整最低API版本
- 升级 Gradle 编译版本为 Java 11
  根目录 build.gradle 中 JavaCompile 配置从 VERSION_1_7 改为 VERSION_11

- 调整 minSdkVersion 从 21 升级至 26
  适配 Android 8.0 (API 26) 及以上系统
  修改范围: aes/build.gradle, libaes/build.gradle

- 移除未使用的 XXPermissions 依赖
  该库使用 Java 8 字节码与 minSdkVersion 21 不兼容,项目中未引用此库
2026-05-10 04:48:29 +08:00
57 changed files with 1660 additions and 1179 deletions

View File

@@ -24,13 +24,13 @@ android {
defaultConfig { defaultConfig {
applicationId "cc.winboll.studio.aes" applicationId "cc.winboll.studio.aes"
minSdkVersion 21 minSdkVersion 26
targetSdkVersion 30 targetSdkVersion 30
versionCode 1 versionCode 1
// versionName 更新后需要手动设置 // versionName 更新后需要手动设置
// 项目模块目录的 build.gradle 文件的 stageCount=0 // 项目模块目录的 build.gradle 文件的 stageCount=0
// Gradle编译环境下合起来的 versionName 就是 "${versionName}.0" // Gradle编译环境下合起来的 versionName 就是 "${versionName}.0"
versionName "15.15" versionName "15.20"
if(true) { if(true) {
versionName = genVersionName("${versionName}") versionName = genVersionName("${versionName}")
} }

View File

@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle #Created by .winboll/winboll_app_build.gradle
#Sat Apr 25 04:16:42 HKT 2026 #Tue May 12 10:47:54 CST 2026
stageCount=10 stageCount=3
libraryProject=libaes libraryProject=libaes
baseVersion=15.15 baseVersion=15.20
publishVersion=15.15.9 publishVersion=15.20.2
buildCount=0 buildCount=14
baseBetaVersion=15.15.10 baseBetaVersion=15.20.3

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyAESTheme" parent="AESTheme">
<item name="themeDebug">@style/MyDebugActivityTheme</item>
</style>
<style name="MyDebugActivityTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:statusBarColor">@color/toolbarBackgroundColor</item>
<item name="colorTittle">@color/mainWindowTextColor</item>
<item name="colorTittleBackgound">@color/toolbarBackgroundColor</item>
<item name="colorText">@color/debugTextColor</item>
<item name="colorTextBackgound">@color/mainWindowBackgroundColor</item>
<item name="debugTextColor">@color/debugTextColor</item>
<item name="toolbarTextColor">@color/toolbarTextColor</item>
</style>
</resources>

View File

@@ -1,5 +1,16 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<style name="MyAESTheme" parent="AESTheme"> <style name="MyAESTheme" parent="AESTheme">
<item name="themeDebug">@style/MyDebugActivityTheme</item>
</style>
<style name="MyDebugActivityTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:statusBarColor">@color/toolbarBackgroundColor</item>
<item name="colorTittle">@color/mainWindowTextColor</item>
<item name="colorTittleBackgound">@color/toolbarBackgroundColor</item>
<item name="colorText">@color/debugTextColor</item>
<item name="colorTextBackgound">@color/mainWindowBackgroundColor</item>
<item name="debugTextColor">@color/debugTextColor</item>
<item name="toolbarTextColor">@color/toolbarTextColor</item>
</style> </style>
</resources> </resources>

View File

@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle #Created by .winboll/winboll_app_build.gradle
#Mon May 11 10:32:47 HKT 2026 #Tue May 12 09:17:15 HKT 2026
stageCount=4 stageCount=10
libraryProject=libappbase libraryProject=libappbase
baseVersion=15.20 baseVersion=15.20
publishVersion=15.20.3 publishVersion=15.20.9
buildCount=0 buildCount=0
baseBetaVersion=15.20.4 baseBetaVersion=15.20.10

View File

@@ -26,6 +26,8 @@ public class App extends GlobalApplication {
if (isDebugging() != true) { if (isDebugging() != true) {
setIsDebugging(BuildConfig.DEBUG); setIsDebugging(BuildConfig.DEBUG);
} }
// release 版调试码
//setIsDebugging(!BuildConfig.DEBUG);
// 初始化 Toast 工具类(传入应用全局上下文,确保 Toast 可在任意地方调用) // 初始化 Toast 工具类(传入应用全局上下文,确保 Toast 可在任意地方调用)
ToastUtils.init(getApplicationContext()); ToastUtils.init(getApplicationContext());

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

@@ -31,7 +31,7 @@
android:text="关于应用" android:text="关于应用"
android:textSize="16sp" android:textSize="16sp"
android:textColor="?attr/activityTextColor" android:textColor="?attr/activityTextColor"
android:background="?attr/buttonBackgroundColor" android:background="?attr/toolbarBackgroundColor"
android:paddingVertical="12dp" android:paddingVertical="12dp"
android:layout_marginHorizontal="24dp" android:layout_marginHorizontal="24dp"
android:onClick="onAboutActivity" android:onClick="onAboutActivity"
@@ -43,7 +43,7 @@
android:text="应用崩溃测试" android:text="应用崩溃测试"
android:textSize="16sp" android:textSize="16sp"
android:textColor="?attr/activityTextColor" android:textColor="?attr/activityTextColor"
android:background="?attr/buttonBackgroundColor" android:background="?attr/toolbarBackgroundColor"
android:paddingVertical="12dp" android:paddingVertical="12dp"
android:layout_marginHorizontal="24dp" android:layout_marginHorizontal="24dp"
android:onClick="onCrashTest" android:onClick="onCrashTest"
@@ -55,7 +55,7 @@
android:text="应用日志测试" android:text="应用日志测试"
android:textSize="16sp" android:textSize="16sp"
android:textColor="?attr/activityTextColor" android:textColor="?attr/activityTextColor"
android:background="?attr/buttonBackgroundColor" android:background="?attr/toolbarBackgroundColor"
android:paddingVertical="12dp" android:paddingVertical="12dp"
android:layout_marginHorizontal="24dp" android:layout_marginHorizontal="24dp"
android:onClick="onLogTest" android:onClick="onLogTest"
@@ -67,7 +67,7 @@
android:text="应用日志测试(新窗口)" android:text="应用日志测试(新窗口)"
android:textSize="16sp" android:textSize="16sp"
android:textColor="?attr/activityTextColor" android:textColor="?attr/activityTextColor"
android:background="?attr/buttonBackgroundColor" android:background="?attr/toolbarBackgroundColor"
android:paddingVertical="12dp" android:paddingVertical="12dp"
android:layout_marginHorizontal="24dp" android:layout_marginHorizontal="24dp"
android:onClick="onLogTestNewTask" android:onClick="onLogTestNewTask"
@@ -79,7 +79,7 @@
android:text="应用吐司测试" android:text="应用吐司测试"
android:textSize="16sp" android:textSize="16sp"
android:textColor="?attr/activityTextColor" android:textColor="?attr/activityTextColor"
android:background="?attr/buttonBackgroundColor" android:background="?attr/toolbarBackgroundColor"
android:paddingVertical="12dp" android:paddingVertical="12dp"
android:layout_marginHorizontal="24dp" android:layout_marginHorizontal="24dp"
android:onClick="onToastUtilsTest" android:onClick="onToastUtilsTest"
@@ -93,7 +93,7 @@
android:text="多开窗口" android:text="多开窗口"
android:textSize="16sp" android:textSize="16sp"
android:textColor="?attr/activityTextColor" android:textColor="?attr/activityTextColor"
android:background="?attr/buttonBackgroundColor" android:background="?attr/toolbarBackgroundColor"
android:paddingVertical="12dp" android:paddingVertical="12dp"
android:layout_marginHorizontal="24dp" android:layout_marginHorizontal="24dp"
android:onClick="onMultiInstance" android:onClick="onMultiInstance"

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/toolbarBackgroundColor"
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/toolbarBackgroundColor"
android:paddingVertical="12dp"
android:layout_marginHorizontal="24dp"
android:onClick="onTestCrash"
android:layout_margin="10dp"/>
</LinearLayout>
</ScrollView>
</LinearLayout>

View File

@@ -31,7 +31,7 @@
android:text="关于应用" android:text="关于应用"
android:textSize="16sp" android:textSize="16sp"
android:textColor="?attr/activityTextColor" android:textColor="?attr/activityTextColor"
android:background="?attr/buttonBackgroundColor" android:background="?attr/toolbarBackgroundColor"
android:paddingVertical="12dp" android:paddingVertical="12dp"
android:layout_marginHorizontal="24dp" android:layout_marginHorizontal="24dp"
android:onClick="onAboutActivity" android:onClick="onAboutActivity"
@@ -43,7 +43,7 @@
android:text="应用崩溃测试" android:text="应用崩溃测试"
android:textSize="16sp" android:textSize="16sp"
android:textColor="?attr/activityTextColor" android:textColor="?attr/activityTextColor"
android:background="?attr/buttonBackgroundColor" android:background="?attr/toolbarBackgroundColor"
android:paddingVertical="12dp" android:paddingVertical="12dp"
android:layout_marginHorizontal="24dp" android:layout_marginHorizontal="24dp"
android:onClick="onCrashTest" android:onClick="onCrashTest"
@@ -55,7 +55,7 @@
android:text="应用日志测试" android:text="应用日志测试"
android:textSize="16sp" android:textSize="16sp"
android:textColor="?attr/activityTextColor" android:textColor="?attr/activityTextColor"
android:background="?attr/buttonBackgroundColor" android:background="?attr/toolbarBackgroundColor"
android:paddingVertical="12dp" android:paddingVertical="12dp"
android:layout_marginHorizontal="24dp" android:layout_marginHorizontal="24dp"
android:onClick="onLogTest" android:onClick="onLogTest"
@@ -67,7 +67,7 @@
android:text="应用日志测试(新窗口)" android:text="应用日志测试(新窗口)"
android:textSize="16sp" android:textSize="16sp"
android:textColor="?attr/activityTextColor" android:textColor="?attr/activityTextColor"
android:background="?attr/buttonBackgroundColor" android:background="?attr/toolbarBackgroundColor"
android:paddingVertical="12dp" android:paddingVertical="12dp"
android:layout_marginHorizontal="24dp" android:layout_marginHorizontal="24dp"
android:onClick="onLogTestNewTask" android:onClick="onLogTestNewTask"
@@ -79,7 +79,7 @@
android:text="应用吐司测试" android:text="应用吐司测试"
android:textSize="16sp" android:textSize="16sp"
android:textColor="?attr/activityTextColor" android:textColor="?attr/activityTextColor"
android:background="?attr/buttonBackgroundColor" android:background="?attr/toolbarBackgroundColor"
android:paddingVertical="12dp" android:paddingVertical="12dp"
android:layout_marginHorizontal="24dp" android:layout_marginHorizontal="24dp"
android:onClick="onToastUtilsTest" android:onClick="onToastUtilsTest"
@@ -93,7 +93,7 @@
android:text="多开窗口" android:text="多开窗口"
android:textSize="16sp" android:textSize="16sp"
android:textColor="?attr/activityTextColor" android:textColor="?attr/activityTextColor"
android:background="?attr/buttonBackgroundColor" android:background="?attr/toolbarBackgroundColor"
android:paddingVertical="12dp" android:paddingVertical="12dp"
android:layout_marginHorizontal="24dp" android:layout_marginHorizontal="24dp"
android:onClick="onMultiInstance" android:onClick="onMultiInstance"

View File

@@ -6,8 +6,9 @@
<style name="MyDebugActivityTheme" parent="DebugActivityTheme"> <style name="MyDebugActivityTheme" parent="DebugActivityTheme">
<item name="colorTittle">?attr/mainWindowDarkTextColor</item> <item name="colorTittle">?attr/mainWindowDarkTextColor</item>
<item name="colorTittleBackgound">@color/buttonBackgroundColor</item> <item name="colorTittleBackgound">?attr/toolbarBackgroundColor</item>
<item name="colorText">?attr/debugTextColor</item> <item name="colorText">?attr/debugTextColor</item>
<item name="colorTextBackgound">?attr/mainWindowDarkBackgroundColor</item> <item name="colorTextBackgound">?attr/mainWindowDarkBackgroundColor</item>
<item name="toolbarTextColor">@color/toolbarTextColor</item>
</style> </style>
</resources> </resources>

View File

@@ -6,8 +6,9 @@
<style name="MyDebugActivityTheme" parent="DebugActivityTheme"> <style name="MyDebugActivityTheme" parent="DebugActivityTheme">
<item name="colorTittle">?attr/mainWindowTextColor</item> <item name="colorTittle">?attr/mainWindowTextColor</item>
<item name="colorTittleBackgound">@color/buttonBackgroundColor</item> <item name="colorTittleBackgound">?attr/toolbarBackgroundColor</item>
<item name="colorText">?attr/debugTextColor</item> <item name="colorText">?attr/debugTextColor</item>
<item name="colorTextBackgound">?attr/mainWindowBackgroundColor</item> <item name="colorTextBackgound">?attr/mainWindowBackgroundColor</item>
<item name="toolbarTextColor">@color/toolbarTextColor</item>
</style> </style>
</resources> </resources>

View File

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

View File

@@ -9,7 +9,7 @@ android {
buildToolsVersion "30.0.3" buildToolsVersion "30.0.3"
defaultConfig { defaultConfig {
minSdkVersion 21 minSdkVersion 26
targetSdkVersion 30 targetSdkVersion 30
} }
@@ -27,8 +27,6 @@ android {
} }
dependencies { dependencies {
// 权限请求框架https://github.com/getActivity/XXPermissions
api 'com.github.getActivity:XXPermissions:18.63'
// 下拉控件 // 下拉控件
api 'com.baoyz.pullrefreshlayout:library:1.2.0' api 'com.baoyz.pullrefreshlayout:library:1.2.0'
// 拼音搜索 // 拼音搜索
@@ -63,7 +61,7 @@ dependencies {
//annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0' //annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
// WinBoLL库 nexus.winboll.cc 地址 // WinBoLL库 nexus.winboll.cc 地址
api 'cc.winboll.studio:libappbase:15.15.19' api 'cc.winboll.studio:libappbase:15.20.9'
// 备用库 jitpack.io 地址 // 备用库 jitpack.io 地址
//api 'com.github.ZhanGSKen:APPBase:appbase-v15.15.3' //api 'com.github.ZhanGSKen:APPBase:appbase-v15.15.3'

View File

@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle #Created by .winboll/winboll_app_build.gradle
#Sat Apr 25 04:16:30 HKT 2026 #Tue May 12 10:47:54 CST 2026
stageCount=10 stageCount=3
libraryProject=libaes libraryProject=libaes
baseVersion=15.15 baseVersion=15.20
publishVersion=15.15.9 publishVersion=15.20.2
buildCount=0 buildCount=14
baseBetaVersion=15.15.10 baseBetaVersion=15.20.3

View File

@@ -31,6 +31,7 @@ import cc.winboll.studio.libaes.utils.DevelopUtils;
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager; import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
import cc.winboll.studio.libaes.views.ADrawerMenuListView; import cc.winboll.studio.libaes.views.ADrawerMenuListView;
import cc.winboll.studio.libaes.views.ADsBannerView; import cc.winboll.studio.libaes.views.ADsBannerView;
import cc.winboll.studio.libaes.views.ASupportToolbar;
import cc.winboll.studio.libappbase.GlobalApplication; import cc.winboll.studio.libappbase.GlobalApplication;
import cc.winboll.studio.libappbase.LogUtils; import cc.winboll.studio.libappbase.LogUtils;
import com.baoyz.widget.PullRefreshLayout; import com.baoyz.widget.PullRefreshLayout;
@@ -174,6 +175,9 @@ public abstract class DrawerFragmentActivity extends AppCompatActivity implement
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
if (AESThemeUtil.onAppThemeItemSelected(this, item)) { if (AESThemeUtil.onAppThemeItemSelected(this, item)) {
if (mToolbar instanceof ASupportToolbar) {
((ASupportToolbar) mToolbar).refreshFromTheme();
}
recreate(); recreate();
} if (DevelopUtils.onDevelopItemSelected(this, item)) { } if (DevelopUtils.onDevelopItemSelected(this, item)) {
LogUtils.d(TAG, String.format("onOptionsItemSelected item.getItemId() %d ", item.getItemId())); LogUtils.d(TAG, String.format("onOptionsItemSelected item.getItemId() %d ", item.getItemId()));

View File

@@ -12,6 +12,8 @@ import androidx.appcompat.widget.Toolbar;
import cc.winboll.studio.libaes.R; import cc.winboll.studio.libaes.R;
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity; import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
import cc.winboll.studio.libaes.utils.AESThemeUtil; import cc.winboll.studio.libaes.utils.AESThemeUtil;
import cc.winboll.studio.libaes.views.ASupportToolbar;
import cc.winboll.studio.libappbase.LogUtils;
public class TestASupportToolbarActivity extends AppCompatActivity implements IWinBoLLActivity { public class TestASupportToolbarActivity extends AppCompatActivity implements IWinBoLLActivity {
@@ -29,14 +31,17 @@ public class TestASupportToolbarActivity extends AppCompatActivity implements IW
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
LogUtils.d(TAG, "onCreate() start");
AESThemeUtil.applyAppTheme(this); AESThemeUtil.applyAppTheme(this);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_testasupporttoolbar); setContentView(R.layout.activity_testasupporttoolbar);
LogUtils.d(TAG, "setContentView() done");
Toolbar toolbar = findViewById(R.id.activitytestasupporttoolbarASupportToolbar1); Toolbar toolbar = findViewById(R.id.activitytestasupporttoolbarASupportToolbar1);
LogUtils.d(TAG, "findViewById() done, toolbar=" + toolbar.getClass().getSimpleName());
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
LogUtils.d(TAG, "setSupportActionBar() done");
getSupportActionBar().setTitle(TAG); getSupportActionBar().setTitle(TAG);
LogUtils.d(TAG, "setTitle() done");
LogUtils.d(TAG, "onCreate() end");
} }
} }

View File

@@ -7,15 +7,12 @@ package cc.winboll.studio.libaes.views;
*/ */
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable; import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.LayerDrawable; import android.graphics.drawable.LayerDrawable;
import android.util.AttributeSet; import android.util.AttributeSet;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import cc.winboll.studio.libaes.R; import cc.winboll.studio.libaes.R;
import android.graphics.drawable.Drawable; import cc.winboll.studio.libappbase.LogUtils;
import androidx.core.content.ContextCompat;
import android.graphics.PorterDuff;
public class ASupportToolbar extends Toolbar { public class ASupportToolbar extends Toolbar {
@@ -25,65 +22,120 @@ public class ASupportToolbar extends Toolbar {
int mStartColor; int mStartColor;
int mCenterColor; int mCenterColor;
int mEndColor; int mEndColor;
LayerDrawable ld;
GradientDrawable[] array = new GradientDrawable[3]; GradientDrawable[] array = new GradientDrawable[3];
//private GradientDrawable gradientDrawable; LayerDrawable ld;
public ASupportToolbar(Context context) { public ASupportToolbar(Context context) {
super(context); super(context);
LogUtils.d(TAG, "ASupportToolbar() constructor");
} }
public ASupportToolbar(Context context, AttributeSet attrs) { public ASupportToolbar(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ASupportToolbar, R.attr.aSupportToolbar, 0); LogUtils.d(TAG, "ASupportToolbar() attrs constructor");
mTitleTextColor = a.getColor(R.styleable.ASupportToolbar_attrASupportToolbarTitleTextColor, Color.GREEN); initStyledAttributes(attrs, R.attr.aSupportToolbar);
mStartColor = a.getColor(R.styleable.ASupportToolbar_attrASupportToolbarStartColor, Color.BLUE);
mCenterColor = a.getColor(R.styleable.ASupportToolbar_attrASupportToolbarCenterColor, Color.RED);
mEndColor = a.getColor(R.styleable.ASupportToolbar_attrASupportToolbarEndColor, Color.YELLOW);
// 返回一个绑定资源结束的信号给资源
a.recycle();
notifyColorChange();
} }
public ASupportToolbar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
LogUtils.d(TAG, "ASupportToolbar() attrs defStyleAttr constructor");
initStyledAttributes(attrs, defStyleAttr);
}
void initStyledAttributes(AttributeSet attrs, int defStyleAttr) {
LogUtils.d(TAG, "initStyledAttributes() start");
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ASupportToolbar, defStyleAttr, 0);
mTitleTextColor = a.getColor(R.styleable.ASupportToolbar_attrASupportToolbarTitleTextColor, 0xFF00FF00);
mStartColor = a.getColor(R.styleable.ASupportToolbar_attrASupportToolbarStartColor, 0xFF03AB4E);
mCenterColor = a.getColor(R.styleable.ASupportToolbar_attrASupportToolbarCenterColor, 0xFF03AB4E);
mEndColor = a.getColor(R.styleable.ASupportToolbar_attrASupportToolbarEndColor, 0xFF3DDC84);
LogUtils.d(TAG, String.format("initStyledAttributes() colors: title=0x%x, start=0x%x, center=0x%x, end=0x%x", mTitleTextColor, mStartColor, mCenterColor, mEndColor));
a.recycle();
setTitleTextColor(mTitleTextColor);
LogUtils.d(TAG, "initStyledAttributes() end");
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
LogUtils.d(TAG, "onAttachedToWindow() start");
refreshFromTheme();
LogUtils.d(TAG, "onAttachedToWindow() end");
}
public void refreshFromTheme() {
LogUtils.d(TAG, "refreshFromTheme() start");
TypedArray a = getContext().obtainStyledAttributes(R.styleable.ASupportToolbar);
try {
mTitleTextColor = a.getColor(R.styleable.ASupportToolbar_attrASupportToolbarTitleTextColor, 0xFF00FF00);
mStartColor = a.getColor(R.styleable.ASupportToolbar_attrASupportToolbarStartColor, 0xFF03AB4E);
mCenterColor = a.getColor(R.styleable.ASupportToolbar_attrASupportToolbarCenterColor, 0xFF03AB4E);
mEndColor = a.getColor(R.styleable.ASupportToolbar_attrASupportToolbarEndColor, 0xFF3DDC84);
LogUtils.d(TAG, String.format("refreshFromTheme() colors: title=0x%x, start=0x%x, center=0x%x, end=0x%x", mTitleTextColor, mStartColor, mCenterColor, mEndColor));
} finally {
a.recycle();
}
postNotifyColorChange();
LogUtils.d(TAG, "refreshFromTheme() end");
}
void postNotifyColorChange() {
LogUtils.d(TAG, "postNotifyColorChange()");
removeCallbacks(mRefreshRunnable);
post(mRefreshRunnable);
}
Runnable mRefreshRunnable = new Runnable() {
@Override
public void run() {
LogUtils.d(TAG, "mRefreshRunnable.run() start");
notifyColorChange();
LogUtils.d(TAG, "mRefreshRunnable.run() end");
}
};
void notifyColorChange() { void notifyColorChange() {
// 工具栏描边 LogUtils.d(TAG, "notifyColorChange() start");
LogUtils.d(TAG, String.format("notifyColorChange() size: width=%d, height=%d", getWidth(), getHeight()));
int nWidth = getWidth();
int nHeight = getHeight();
if (nWidth == 0 || nHeight == 0) {
LogUtils.d(TAG, "notifyColorChange() skipped: width or height is 0");
return;
}
int nStroke = 5; int nStroke = 5;
//分别为开始颜色,中间夜色,结束颜色 int colors0[] = { mEndColor , mCenterColor, mStartColor };
int colors0[] = { mEndColor , mCenterColor, mStartColor};
GradientDrawable gradientDrawable0;
array[2] = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colors0); array[2] = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colors0);
gradientDrawable0 = array[2]; array[2].setShape(GradientDrawable.RECTANGLE);
gradientDrawable0.setShape(GradientDrawable.RECTANGLE); array[2].setColors(colors0);
gradientDrawable0.setColors(colors0); //添加颜色组 array[2].setGradientType(GradientDrawable.LINEAR_GRADIENT);
gradientDrawable0.setGradientType(GradientDrawable.LINEAR_GRADIENT);//设置线性渐变 array[2].setCornerRadius(20);
gradientDrawable0.setCornerRadius(20);
int colors1[] = { mCenterColor , mCenterColor, mCenterColor }; int colors1[] = { mCenterColor, mCenterColor, mCenterColor };
GradientDrawable gradientDrawable1;
array[1] = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colors1); array[1] = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colors1);
gradientDrawable1 = array[1]; array[1].setShape(GradientDrawable.RECTANGLE);
gradientDrawable1.setShape(GradientDrawable.RECTANGLE); array[1].setColors(colors1);
gradientDrawable1.setColors(colors1); //添加颜色组 array[1].setGradientType(GradientDrawable.LINEAR_GRADIENT);
gradientDrawable1.setGradientType(GradientDrawable.LINEAR_GRADIENT);//设置线性渐变 array[1].setCornerRadius(20);
gradientDrawable1.setCornerRadius(20);
int colors2[] = { mEndColor, mCenterColor, mStartColor }; int colors2[] = { mEndColor, mCenterColor, mStartColor };
GradientDrawable gradientDrawable2;
array[0] = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colors2); array[0] = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colors2);
gradientDrawable2 = array[0]; array[0].setShape(GradientDrawable.RECTANGLE);
gradientDrawable2.setShape(GradientDrawable.RECTANGLE); array[0].setColors(colors2);
gradientDrawable2.setColors(colors2); //添加颜色组 array[0].setGradientType(GradientDrawable.LINEAR_GRADIENT);
gradientDrawable2.setGradientType(GradientDrawable.LINEAR_GRADIENT);//设置线性渐变 array[0].setCornerRadius(20);
gradientDrawable2.setCornerRadius(20);
ld = new LayerDrawable(array); //参数为上面的Drawable数组 ld = new LayerDrawable(array);
ld.setLayerInset(2, nStroke * 2, nStroke * 2, getWidth() + nStroke * 2, getHeight() + nStroke * 2); ld.setLayerInset(2, nStroke * 2, nStroke * 2, nWidth + nStroke * 2, nHeight + nStroke * 2);
ld.setLayerInset(1, nStroke, nStroke, getWidth() + nStroke, getHeight() + nStroke); ld.setLayerInset(1, nStroke, nStroke, nWidth + nStroke, nHeight + nStroke);
ld.setLayerInset(0, 0, 0, getWidth(), getHeight()); ld.setLayerInset(0, 0, 0, nWidth, nHeight);
setBackgroundDrawable(ld); setBackgroundDrawable(ld);
setTitleTextColor(mTitleTextColor); setTitleTextColor(mTitleTextColor);
setSubtitleTextColor(mTitleTextColor); setSubtitleTextColor(mTitleTextColor);
LogUtils.d(TAG, "notifyColorChange() end");
} }
} }

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorTextColor">#FFFFFFFF</color>
<color name="colorPrimary">#FF03AB4E</color>
<color name="colorPrimaryDark">#FF027C39</color>
<color name="colorAccent">#FF3DDC84</color>
<color name="colorText">#FFFFFB8D</color>
<color name="colorToastFrame">#FFA9A9A9</color>
<color name="colorToastShadow">#FF000000</color>
<color name="colorToastBackgroung">#FFFFFFFF</color>
<color name="colorAToolbarStartColor">#FF7D3F12</color>
<color name="colorAToolbarCenterColor">#FFCC6E2B</color>
<color name="colorAToolbarEndColor">#FFF4B98F</color>
<color name="colorACardShadow">@color/colorPrimaryDark</color>
<color name="colorACardFrame">@color/colorPrimary</color>
<color name="colorACardBackgroung">@color/colorAccent</color>
<color name="colorATickProgressBarBackgroung">@color/colorAccent</color>
<color name="colorATickProgressBarProgress">@color/colorPrimary</color>
<color name="colorOHPCTSBackground">@color/colorAccent</color>
<color name="colorOHPCTSSecondaryProgress">@color/colorPrimary</color>
<color name="colorOHPCTSProgress">@color/colorPrimaryDark</color>
<color name="toolbarBackgroundColor">#FF03AB4E</color>
<color name="toolbarTextColor">#FFFFFFFF</color>
<color name="mainWindowBackgroundColor">#FF2C2C2C</color>
<color name="mainWindowTextColor">#FFFFFFFF</color>
<color name="debugTextColor">#FFFF0000</color>
</resources>

View File

@@ -0,0 +1,112 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AESTheme" parent="Theme.AppCompat.NoActionBar">
<item name="themeDebug">@style/DebugActivityTheme</item>
<item name="aboutViewBackgroundColor">@color/mainWindowBackgroundColor</item>
<item name="aboutViewTextColor">@color/mainWindowTextColor</item>
<item name="aboutViewTitleColor">@color/mainWindowTextColor</item>
<item name="aboutViewDividerColor">@color/mainWindowTextColor</item>
<item name="dialogBackgroundColor">@color/mainWindowBackgroundColor</item>
<item name="dialogTextColor">@color/mainWindowTextColor</item>
<item name="toolbarBackgroundColor">@color/toolbarBackgroundColor</item>
<item name="toolbarTextColor">@color/toolbarTextColor</item>
<item name="textViewBackgroundColor">@color/mainWindowBackgroundColor</item>
<item name="textViewTextColor">@color/mainWindowTextColor</item>
<item name="editTextBackgroundColor">@color/mainWindowBackgroundColor</item>
<item name="editTextTextColor">@color/mainWindowTextColor</item>
<item name="scrollViewBackgroundColor">@color/mainWindowBackgroundColor</item>
<item name="activityBackgroundColor">@color/mainWindowBackgroundColor</item>
<item name="activityTextColor">@color/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>
<item name="android:statusBarColor">@color/toolbarBackgroundColor</item>
<item name="aToolbar">@style/AESAToolbar</item>
<item name="aSupportToolbar">@style/AESASupportToolbar</item>
</style>
<style name="DebugActivityTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:statusBarColor">@color/toolbarBackgroundColor</item>
<item name="colorTittle">@color/mainWindowTextColor</item>
<item name="colorTittleBackgound">@color/toolbarBackgroundColor</item>
<item name="colorText">@color/debugTextColor</item>
<item name="colorTextBackgound">@color/mainWindowBackgroundColor</item>
<item name="debugTextColor">@color/debugTextColor</item>
<item name="toolbarTextColor">@color/toolbarTextColor</item>
</style>
<style name="AESAToolbar">
<item name="attrAToolbarTitleTextColor">@color/colorTextColor</item>
<item name="attrAToolbarStartColor">@color/colorPrimaryDark</item>
<item name="attrAToolbarCenterColor">@color/colorPrimary</item>
<item name="attrAToolbarEndColor">@color/colorAccent</item>
</style>
<style name="AESASupportToolbar">
<item name="attrASupportToolbarTitleTextColor">@color/colorTextColor</item>
<item name="attrASupportToolbarStartColor">@color/colorPrimaryDark</item>
<item name="attrASupportToolbarCenterColor">@color/colorPrimary</item>
<item name="attrASupportToolbarEndColor">@color/colorAccent</item>
</style>
<style name="DepthAESTheme" parent="AESTheme">
<item name="colorPrimary">#FF0065EC</item>
<item name="colorPrimaryDark">#FF004DB4</item>
<item name="colorAccent">#FF4A97FF</item>
</style>
<style name="SkyAESTheme" parent="AESTheme">
<item name="colorPrimary">#FF00A6FF</item>
<item name="colorPrimaryDark">#FF007ABB</item>
<item name="colorAccent">#FF84D4FF</item>
</style>
<style name="GoldenAESTheme" parent="AESTheme">
<item name="colorPrimary">#FFF0CA11</item>
<item name="colorPrimaryDark">#FFD3AF00</item>
<item name="colorAccent">#FFFFE35C</item>
</style>
<style name="BearingAESTheme" parent="AESTheme">
<item name="colorPrimary">#FF840FFF</item>
<item name="colorPrimaryDark">#FF6900D7</item>
<item name="colorAccent">#FFBA78FF</item>
</style>
<style name="MemorAESTheme" parent="AESTheme">
<item name="colorPrimary">#FFFF00F5</item>
<item name="colorPrimaryDark">#FFE500DC</item>
<item name="colorAccent">#FFFF76FA</item>
</style>
<style name="TaoAESTheme" parent="AESTheme">
<item name="colorPrimary">#FFACACAC</item>
<item name="colorPrimaryDark">#FF898989</item>
<item name="colorAccent">#FFD8D8D8</item>
</style>
<style name="NormalDialogStyle" parent="Theme.AppCompat.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowFrame">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">false</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowAnimationStyle">@style/cornerDialogAnim</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
<style name="centerDialogAnim" parent="android:Animation">
<item name="@android:windowEnterAnimation">@anim/normal_dialog_enter_center</item>
<item name="@android:windowExitAnimation">@anim/normal_dialog_exit_center</item>
</style>
<style name="cornerDialogAnim" parent="android:Animation">
<item name="@android:windowEnterAnimation">@anim/normal_dialog_enter_corner</item>
<item name="@android:windowExitAnimation">@anim/normal_dialog_exit_corner</item>
</style>
</resources>

View File

@@ -43,6 +43,7 @@
<attr name="attrASupportToolbarStartColor"/> <attr name="attrASupportToolbarStartColor"/>
<attr name="attrASupportToolbarCenterColor"/> <attr name="attrASupportToolbarCenterColor"/>
<attr name="attrASupportToolbarEndColor"/> <attr name="attrASupportToolbarEndColor"/>
<attr name="android:background"/>
</declare-styleable> </declare-styleable>
<declare-styleable name="AButton"> <declare-styleable name="AButton">

View File

@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<!-- 默认方案 --> <color name="colorTextColor">#FF000000</color>
<color name="colorPrimary">#FF03AB4E</color> <color name="colorPrimary">#FF03AB4E</color>
<color name="colorPrimaryDark">#FF027C39</color> <color name="colorPrimaryDark">#FF027C39</color>
<color name="colorAccent">#FF3DDC84</color> <color name="colorAccent">#FF3DDC84</color>
<color name="colorText">#FFFFFB8D</color> <color name="colorText">#FFFFFB8D</color>
<color name="colorToastFrame">#FFA9A9A9</color> <color name="colorToastFrame">#FFA9A9A9</color>
<color name="colorToastShadow">#FF000000</color> <color name="colorToastShadow">#FF000000</color>
<color name="colorToastBackgroung">#FFFFFFFF</color> <color name="colorToastBackgroung">#FFFFFFFF</color>
@@ -24,22 +24,10 @@
<color name="colorOHPCTSSecondaryProgress">@color/colorPrimary</color> <color name="colorOHPCTSSecondaryProgress">@color/colorPrimary</color>
<color name="colorOHPCTSProgress">@color/colorPrimaryDark</color> <color name="colorOHPCTSProgress">@color/colorPrimaryDark</color>
<!-- --> <color name="toolbarBackgroundColor">#FF03AB4E</color>
<color name="toolbarTextColor">#FFFFFFFF</color>
<color name="mainWindowBackgroundColor">#FFFFFFFF</color>
<color name="mainWindowTextColor">#FF000000</color>
<color name="debugTextColor">#FFFF0000</color>
<!-- 调试方案
<color name="colorPrimary">#FF727272</color>
<color name="colorPrimaryDark">#FF444444</color>
<color name="colorAccent">#FF9EA19F</color>
<color name="colorAToolbarStartColor">#FF4776EB</color>
<color name="colorAToolbarCenterColor">#FF0D4BE7</color>
<color name="colorAToolbarEndColor">#FF8FA7E3</color>
<color name="colorACardShadow">#FF22A200</color>
<color name="colorACardFrame">#FF3FCC19</color>
<color name="colorACardBackgroung">#FF88F16B</color>
<color name="colorATickProgressBarBackgroung">#FF6DC4E2</color>
<color name="colorATickProgressBarProgress">#FF22B0E1</color>
-->
</resources> </resources>

View File

@@ -1,255 +1,112 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<style name="AESTheme" parent="Theme.AppCompat.Light.NoActionBar"> <style name="AESTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorTextColor">#FF000000</item> <item name="themeDebug">@style/DebugActivityTheme</item>
<item name="colorPrimary">#FF18B05C</item> <item name="aboutViewBackgroundColor">@color/mainWindowBackgroundColor</item>
<item name="colorPrimaryDark">#FF008C3F</item> <item name="aboutViewTextColor">@color/mainWindowTextColor</item>
<item name="colorAccent">#FF24DC77</item> <item name="aboutViewTitleColor">@color/mainWindowTextColor</item>
<item name="android:textColor">#FF000000</item> <item name="aboutViewDividerColor">@color/mainWindowTextColor</item>
<item name="dialogBackgroundColor">@color/mainWindowBackgroundColor</item>
<item name="dialogTextColor">@color/mainWindowTextColor</item>
<item name="toolbarBackgroundColor">@color/toolbarBackgroundColor</item>
<item name="toolbarTextColor">@color/toolbarTextColor</item>
<item name="textViewBackgroundColor">@color/mainWindowBackgroundColor</item>
<item name="textViewTextColor">@color/mainWindowTextColor</item>
<item name="editTextBackgroundColor">@color/mainWindowBackgroundColor</item>
<item name="editTextTextColor">@color/mainWindowTextColor</item>
<item name="scrollViewBackgroundColor">@color/mainWindowBackgroundColor</item>
<item name="activityBackgroundColor">@color/mainWindowBackgroundColor</item>
<item name="activityTextColor">@color/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>
<item name="android:statusBarColor">@color/toolbarBackgroundColor</item>
<item name="aToolbar">@style/AESAToolbar</item> <item name="aToolbar">@style/AESAToolbar</item>
<item name="aSupportToolbar">@style/AESASupportToolbar</item> <item name="aSupportToolbar">@style/AESASupportToolbar</item>
</style> </style>
<style name="DebugActivityTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:statusBarColor">@color/toolbarBackgroundColor</item>
<item name="colorTittle">@color/mainWindowTextColor</item>
<item name="colorTittleBackgound">@color/toolbarBackgroundColor</item>
<item name="colorText">@color/debugTextColor</item>
<item name="colorTextBackgound">@color/mainWindowBackgroundColor</item>
<item name="debugTextColor">@color/debugTextColor</item>
<item name="toolbarTextColor">@color/toolbarTextColor</item>
</style>
<style name="AESAToolbar"> <style name="AESAToolbar">
<item name="attrAToolbarTitleTextColor">?attr/colorTextColor</item> <item name="attrAToolbarTitleTextColor">@color/colorTextColor</item>
<item name="attrAToolbarStartColor">?attr/colorPrimaryDark</item> <item name="attrAToolbarStartColor">@color/colorPrimaryDark</item>
<item name="attrAToolbarCenterColor">?attr/colorPrimary</item> <item name="attrAToolbarCenterColor">@color/colorPrimary</item>
<item name="attrAToolbarEndColor">?attr/colorAccent</item> <item name="attrAToolbarEndColor">@color/colorAccent</item>
</style> </style>
<style name="AESASupportToolbar"> <style name="AESASupportToolbar">
<item name="attrASupportToolbarTitleTextColor">?attr/colorTextColor</item> <item name="attrASupportToolbarTitleTextColor">@color/colorTextColor</item>
<item name="attrASupportToolbarStartColor">?attr/colorPrimaryDark</item> <item name="attrASupportToolbarStartColor">@color/colorPrimaryDark</item>
<item name="attrASupportToolbarCenterColor">?attr/colorPrimary</item> <item name="attrASupportToolbarCenterColor">@color/colorPrimary</item>
<item name="attrASupportToolbarEndColor">?attr/colorAccent</item> <item name="attrASupportToolbarEndColor">@color/colorAccent</item>
</style> </style>
<style name="DepthAESTheme" parent="AESTheme"> <style name="DepthAESTheme" parent="AESTheme">
<item name="colorTextColor">#FF000000</item>
<item name="colorPrimary">#FF0065EC</item> <item name="colorPrimary">#FF0065EC</item>
<item name="colorPrimaryDark">#FF004DB4</item> <item name="colorPrimaryDark">#FF004DB4</item>
<item name="colorAccent">#FF4A97FF</item> <item name="colorAccent">#FF4A97FF</item>
<item name="android:textColor">#FF000000</item>
</style> </style>
<style name="SkyAESTheme" parent="AESTheme"> <style name="SkyAESTheme" parent="AESTheme">
<item name="colorTextColor">#FF000000</item>
<item name="colorPrimary">#FF00A6FF</item> <item name="colorPrimary">#FF00A6FF</item>
<item name="colorPrimaryDark">#FF007ABB</item> <item name="colorPrimaryDark">#FF007ABB</item>
<item name="colorAccent">#FF84D4FF</item> <item name="colorAccent">#FF84D4FF</item>
<item name="android:textColor">#FF000000</item>
</style> </style>
<style name="GoldenAESTheme" parent="AESTheme"> <style name="GoldenAESTheme" parent="AESTheme">
<item name="colorTextColor">#FF000000</item>
<item name="colorPrimary">#FFF0CA11</item> <item name="colorPrimary">#FFF0CA11</item>
<item name="colorPrimaryDark">#FFD3AF00</item> <item name="colorPrimaryDark">#FFD3AF00</item>
<item name="colorAccent">#FFFFE35C</item> <item name="colorAccent">#FFFFE35C</item>
<item name="android:textColor">#FF000000</item>
</style> </style>
<style name="BearingAESTheme" parent="AESTheme"> <style name="BearingAESTheme" parent="AESTheme">
<item name="colorTextColor">#FF000000</item>
<item name="colorPrimary">#FF840FFF</item> <item name="colorPrimary">#FF840FFF</item>
<item name="colorPrimaryDark">#FF6900D7</item> <item name="colorPrimaryDark">#FF6900D7</item>
<item name="colorAccent">#FFBA78FF</item> <item name="colorAccent">#FFBA78FF</item>
<item name="android:textColor">#FF000000</item>
</style> </style>
<style name="MemorAESTheme" parent="AESTheme"> <style name="MemorAESTheme" parent="AESTheme">
<item name="colorTextColor">#FF000000</item>
<item name="colorPrimary">#FFFF00F5</item> <item name="colorPrimary">#FFFF00F5</item>
<item name="colorPrimaryDark">#FFE500DC</item> <item name="colorPrimaryDark">#FFE500DC</item>
<item name="colorAccent">#FFFF76FA</item> <item name="colorAccent">#FFFF76FA</item>
<item name="android:textColor">#FF000000</item>
</style> </style>
<style name="TaoAESTheme" parent="AESTheme"> <style name="TaoAESTheme" parent="AESTheme">
<item name="colorTextColor">#FF000000</item>
<item name="colorPrimary">#FFACACAC</item> <item name="colorPrimary">#FFACACAC</item>
<item name="colorPrimaryDark">#FF898989</item> <item name="colorPrimaryDark">#FF898989</item>
<item name="colorAccent">#FFD8D8D8</item> <item name="colorAccent">#FFD8D8D8</item>
<item name="android:textColor">#FF000000</item>
</style> </style>
<!--<style name="AESTheme" parent="Theme.AppCompat.Light.NoActionBar"> <style name="NormalDialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="colorTextColor">#FF000000</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:textColor">#FF000000</item>
<item name="aToolbar">@style/AESAToolbar</item>
<item name="aSupportToolbar">@style/AESASupportToolbar</item>
</style>
<style name="AESAToolbar">
<item name="attrAToolbarTitleTextColor">?attr/colorTextColor</item>
<item name="attrAToolbarStartColor">?attr/colorPrimaryDark</item>
<item name="attrAToolbarCenterColor">?attr/colorPrimary</item>
<item name="attrAToolbarEndColor">?attr/colorAccent</item>
</style>
<style name="AESASupportToolbar">
<item name="attrASupportToolbarTitleTextColor">?attr/colorTextColor</item>
<item name="attrASupportToolbarStartColor">?attr/colorPrimaryDark</item>
<item name="attrASupportToolbarCenterColor">?attr/colorPrimary</item>
<item name="attrASupportToolbarEndColor">?attr/colorAccent</item>
</style>-->
<!--<style name="DepthAESTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorTextColor">#FF000000</item>
<item name="colorPrimary">#FF2566FE</item>
<item name="colorPrimaryDark">#FF1359FF</item>
<item name="colorAccent">#FF8BAEFF</item>
<item name="android:textColor">#FF000000</item>
<item name="aToolbar">@style/DepthAToolbar</item>
<item name="aSupportToolbar">@style/DepthASupportToolbar</item>
</style>
<style name="DepthAToolbar">
<item name="attrAToolbarTitleTextColor">?attr/colorTextColor</item>
<item name="attrAToolbarStartColor">?attr/colorPrimaryDark</item>
<item name="attrAToolbarCenterColor">?attr/colorPrimary</item>
<item name="attrAToolbarEndColor">?attr/colorAccent</item>
</style>
<style name="DepthASupportToolbar">
<item name="attrASupportToolbarTitleTextColor">?attr/colorTextColor</item>
<item name="attrASupportToolbarStartColor">?attr/colorPrimaryDark</item>
<item name="attrASupportToolbarCenterColor">?attr/colorPrimary</item>
<item name="attrASupportToolbarEndColor">?attr/colorAccent</item>
</style>
<style name="SkyAESTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorTextColor">#FF000000</item>
<item name="colorPrimary">#FF1E98D4</item>
<item name="colorPrimaryDark">#FF046A9C</item>
<item name="colorAccent">#FF8CD9FF</item>
<item name="android:textColor">#FF000000</item>
<item name="aToolbar">@style/SkyAToolbar</item>
<item name="aSupportToolbar">@style/SkyASupportToolbar</item>
</style>
<style name="SkyAToolbar">
<item name="attrAToolbarTitleTextColor">?attr/colorTextColor</item>
<item name="attrAToolbarStartColor">?attr/colorPrimaryDark</item>
<item name="attrAToolbarCenterColor">?attr/colorPrimary</item>
<item name="attrAToolbarEndColor">?attr/colorAccent</item>
</style>
<style name="SkyASupportToolbar">
<item name="attrASupportToolbarTitleTextColor">?attr/colorTextColor</item>
<item name="attrASupportToolbarStartColor">?attr/colorPrimaryDark</item>
<item name="attrASupportToolbarCenterColor">?attr/colorPrimary</item>
<item name="attrASupportToolbarEndColor">?attr/colorAccent</item>
</style>
<style name="GoldenAESTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorTextColor">#FF000000</item>
<item name="colorPrimary">#FFFFE22A</item>
<item name="colorPrimaryDark">#FFAE9600</item>
<item name="colorAccent">#FFFFED78</item>
<item name="android:textColor">#FF000000</item>
<item name="aToolbar">@style/GoldenAToolbar</item>
<item name="aSupportToolbar">@style/GoldenASupportToolbar</item>
</style>
<style name="GoldenAToolbar">
<item name="attrAToolbarTitleTextColor">?attr/colorTextColor</item>
<item name="attrAToolbarStartColor">?attr/colorPrimaryDark</item>
<item name="attrAToolbarCenterColor">?attr/colorPrimary</item>
<item name="attrAToolbarEndColor">?attr/colorAccent</item>
</style>
<style name="GoldenASupportToolbar">
<item name="attrASupportToolbarTitleTextColor">?attr/colorTextColor</item>
<item name="attrASupportToolbarStartColor">?attr/colorPrimaryDark</item>
<item name="attrASupportToolbarCenterColor">?attr/colorPrimary</item>
<item name="attrASupportToolbarEndColor">?attr/colorAccent</item>
</style>
<style name="MemorAESTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorTextColor">#FF000000</item>
<item name="colorPrimary">#FFCE1ED4</item>
<item name="colorPrimaryDark">#FFB500BC</item>
<item name="colorAccent">#FFE653EB</item>
<item name="android:textColor">#FF000000</item>
<item name="aToolbar">@style/MemorAToolbar</item>
<item name="aSupportToolbar">@style/MemorASupportToolbar</item>
</style>
<style name="MemorAToolbar">
<item name="attrAToolbarTitleTextColor">?attr/colorTextColor</item>
<item name="attrAToolbarStartColor">?attr/colorPrimaryDark</item>
<item name="attrAToolbarCenterColor">?attr/colorPrimary</item>
<item name="attrAToolbarEndColor">?attr/colorAccent</item>
</style>
<style name="MemorASupportToolbar">
<item name="attrASupportToolbarTitleTextColor">?attr/colorTextColor</item>
<item name="attrASupportToolbarStartColor">?attr/colorPrimaryDark</item>
<item name="attrASupportToolbarCenterColor">?attr/colorPrimary</item>
<item name="attrASupportToolbarEndColor">?attr/colorAccent</item>
</style>
<style name="TaoAESTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorTextColor">#FF000000</item>
<item name="colorPrimary">#FF9F9F9F</item>
<item name="colorPrimaryDark">#FF5E5E5E</item>
<item name="colorAccent">#FFD9D9D9</item>
<item name="android:textColor">#FF000000</item>
<item name="aToolbar">@style/TaoAToolbar</item>
<item name="aSupportToolbar">@style/TaoASupportToolbar</item>
</style>
<style name="TaoAToolbar">
<item name="attrAToolbarTitleTextColor">?attr/colorTextColor</item>
<item name="attrAToolbarStartColor">?attr/colorPrimaryDark</item>
<item name="attrAToolbarCenterColor">?attr/colorPrimary</item>
<item name="attrAToolbarEndColor">?attr/colorAccent</item>
</style>
<style name="TaoASupportToolbar">
<item name="attrASupportToolbarTitleTextColor">?attr/colorTextColor</item>
<item name="attrASupportToolbarStartColor">?attr/colorPrimaryDark</item>
<item name="attrASupportToolbarCenterColor">?attr/colorPrimary</item>
<item name="attrASupportToolbarEndColor">?attr/colorAccent</item>
</style>-->
<!--<style name="AToolbar">
<item name="attrAToolbarTitleTextColor">#FF2DDA27</item>
<item name="attrAToolbarStartColor">#FF2DDA27</item>
<item name="attrAToolbarCenterColor">#FF2DDA27</item>
<item name="attrAToolbarEndColor">#FF2DDA27</item>
</style>-->
<!--对话框的样式-->
<style name="NormalDialogStyle">
<!--对话框背景 -->
<item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowBackground">@android:color/transparent</item>
<!--边框 -->
<item name="android:windowFrame">@null</item> <item name="android:windowFrame">@null</item>
<!--没有标题 -->
<item name="android:windowNoTitle">true</item> <item name="android:windowNoTitle">true</item>
<!-- 是否浮现在Activity之上 -->
<item name="android:windowIsFloating">true</item> <item name="android:windowIsFloating">true</item>
<!--背景透明 -->
<item name="android:windowIsTranslucent">false</item> <item name="android:windowIsTranslucent">false</item>
<!-- 是否有覆盖 -->
<item name="android:windowContentOverlay">@null</item> <item name="android:windowContentOverlay">@null</item>
<!--进出的显示动画 -->
<item name="android:windowAnimationStyle">@style/cornerDialogAnim</item> <item name="android:windowAnimationStyle">@style/cornerDialogAnim</item>
<!--背景变暗-->
<item name="android:backgroundDimEnabled">true</item> <item name="android:backgroundDimEnabled">true</item>
</style> </style>
<!--对话框动画,中间弹出-->
<style name="centerDialogAnim" parent="android:Animation"> <style name="centerDialogAnim" parent="android:Animation">
<item name="@android:windowEnterAnimation">@anim/normal_dialog_enter_center</item> <item name="@android:windowEnterAnimation">@anim/normal_dialog_enter_center</item>
<item name="@android:windowExitAnimation">@anim/normal_dialog_exit_center</item> <item name="@android:windowExitAnimation">@anim/normal_dialog_exit_center</item>
</style> </style>
<!--对话框动画,角落弹出-->
<style name="cornerDialogAnim" parent="android:Animation"> <style name="cornerDialogAnim" parent="android:Animation">
<item name="@android:windowEnterAnimation">@anim/normal_dialog_enter_corner</item> <item name="@android:windowEnterAnimation">@anim/normal_dialog_enter_corner</item>
<item name="@android:windowExitAnimation">@anim/normal_dialog_exit_corner</item> <item name="@android:windowExitAnimation">@anim/normal_dialog_exit_corner</item>
</style> </style>
</resources> </resources>

View File

@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle #Created by .winboll/winboll_app_build.gradle
#Mon May 11 10:32:47 HKT 2026 #Tue May 12 09:16:45 HKT 2026
stageCount=4 stageCount=10
libraryProject=libappbase libraryProject=libappbase
baseVersion=15.20 baseVersion=15.20
publishVersion=15.20.3 publishVersion=15.20.9
buildCount=0 buildCount=0
baseBetaVersion=15.20.4 baseBetaVersion=15.20.10

View File

@@ -47,6 +47,13 @@
<activity android:name="cc.winboll.studio.libappbase.activities.FTPBackupsActivity"/> <activity android:name="cc.winboll.studio.libappbase.activities.FTPBackupsActivity"/>
<activity
android:name=".utils.ShareLogActivity"
android:label="ShareLogActivity"
android:exported="true"
android:launchMode="singleTask"
android:theme="@android:style/Theme.NoDisplay"/>
</application> </application>
</manifest> </manifest>

View File

@@ -0,0 +1,194 @@
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;
/**
* 应用崩溃保险丝内部类(单例)
* 核心作用:限制短时间内重复崩溃,通过「熔断等级」控制崩溃页面启动策略
* 等级范围MINI1~ MAX2每次崩溃等级-1熔断后启动基础版崩溃页面
*/
public final class AppCrashSafetyWire {
public static final String TAG = "AppCrashSafetyWire";
/** 单例实例volatile 保证多线程可见性) */
private static volatile AppCrashSafetyWire _AppCrashSafetyWire;
/** 当前熔断等级1最低防护2最高防护≤0熔断 */
private volatile Integer currentSafetyLevel;
/** 最低熔断等级1再崩溃则熔断 */
private static final int _MINI = 1;
/** 最高熔断等级2初始状态 */
private static final int _MAX = 2;
/**
* 私有构造方法(单例模式,禁止外部实例化)
* 初始化时加载本地存储的熔断等级
*/
private AppCrashSafetyWire() {
LogUtils.d(TAG, "AppCrashSafetyWire()");
currentSafetyLevel = loadCurrentSafetyLevel();
}
/**
* 获取单例实例(双重检查锁定,线程安全)
* @return AppCrashSafetyWire 单例
*/
public static synchronized AppCrashSafetyWire getInstance() {
if (_AppCrashSafetyWire == null) {
_AppCrashSafetyWire = new AppCrashSafetyWire();
}
return _AppCrashSafetyWire;
}
/**
* 设置当前熔断等级(内存中)
* @param currentSafetyLevel 目标等级1~2
*/
public void setCurrentSafetyLevel(int currentSafetyLevel) {
this.currentSafetyLevel = currentSafetyLevel;
}
/**
* 获取当前熔断等级(内存中)
* @return 当前等级1~2 或 null
*/
public int getCurrentSafetyLevel() {
return currentSafetyLevel;
}
/**
* 保存熔断等级到本地文件(持久化,重启应用生效)
* @param currentSafetyLevel 待保存的等级
*/
public void saveCurrentSafetyLevel(int currentSafetyLevel) {
LogUtils.d(TAG, "saveCurrentSafetyLevel()");
this.currentSafetyLevel = currentSafetyLevel;
try {
// 序列化等级到文件ObjectOutputStream 写入 int
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(CrashHandler._CrashCountFilePath));
oos.writeInt(currentSafetyLevel);
oos.flush();
oos.close();
LogUtils.d(TAG, String.format("saveCurrentSafetyLevel writeInt currentSafetyLevel %d", currentSafetyLevel));
} catch (IOException e) {
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
}
}
/**
* 从本地文件加载熔断等级(应用启动时初始化)
* @return 加载的等级(文件不存在则初始化为 MAX2
*/
public int loadCurrentSafetyLevel() {
LogUtils.d(TAG, "loadCurrentSafetyLevel()");
try {
File f = new File(CrashHandler._CrashCountFilePath);
if (f.exists()) {
// 反序列化从文件读取等级
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(CrashHandler._CrashCountFilePath));
currentSafetyLevel = ois.readInt();
LogUtils.d(TAG, String.format("loadCurrentSafetyLevel() readInt currentSafetyLevel %d", currentSafetyLevel));
} else {
// 文件不存在初始化等级为最高2并保存
currentSafetyLevel = _MAX;
LogUtils.d(TAG, String.format("loadCurrentSafetyLevel() currentSafetyLevel init to _MAX->%d", _MAX));
saveCurrentSafetyLevel(currentSafetyLevel);
}
} catch (IOException e) {
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
}
return currentSafetyLevel;
}
/**
* 熔断保险丝(每次崩溃调用,降低防护等级)
* @return 熔断后是否仍在防护范围内truefalse已熔断
*/
boolean burnSafetyWire() {
LogUtils.d(TAG, "burnSafetyWire()");
// 加载当前等级
int safeLevel = loadCurrentSafetyLevel();
// 若在防护范围内1~2等级-1 并保存
if (isSafetyWireWorking(safeLevel)) {
LogUtils.d(TAG, "burnSafetyWire() use");
saveCurrentSafetyLevel(safeLevel - 1);
// 返回熔断后的状态
return isSafetyWireWorking(safeLevel - 1);
}
return false;
}
/**
* 检查熔断等级是否在有效范围内1~2
* @param safetyLevel 待检查的等级
* @return true在范围内防护有效false超出范围已熔断
*/
boolean isSafetyWireWorking(int safetyLevel) {
LogUtils.d(TAG, "isSafetyWireOK()");
LogUtils.d(TAG, String.format("SafetyLevel %d", safetyLevel));
if (safetyLevel >= _MINI && safetyLevel <= _MAX) {
LogUtils.d(TAG, String.format("In Safety Level"));
return true;
}
LogUtils.d(TAG, String.format("Out of Safety Level"));
return false;
}
/**
* 立即恢复熔断等级到最高2
* 用于重启应用后重置防护状态
*/
void resumeToMaximumImmediately() {
LogUtils.d(TAG, "resumeToMaximumImmediately() call saveCurrentSafetyLevel(_MAX)");
AppCrashSafetyWire.getInstance().saveCurrentSafetyLevel(_MAX);
}
/**
* 关闭防护设置等级为最低1
* 下次崩溃直接熔断
*/
void off() {
LogUtils.d(TAG, "off()");
saveCurrentSafetyLevel(_MINI);
}
/**
* 检查当前保险丝是否有效(防护未熔断)
* @return true有效等级 1~2false已熔断
*/
public boolean isAppCrashSafetyWireOK() {
LogUtils.d(TAG, "isAppCrashSafetyWireOK()");
currentSafetyLevel = loadCurrentSafetyLevel();
return isSafetyWireWorking(currentSafetyLevel);
}
/**
* 延迟恢复保险丝到最高等级500ms 后)
* 核心作用:崩溃页面启动后,若下次即将熔断,提前恢复防护等级,避免持续崩溃
* @param context 上下文(用于获取主线程 Handler
*/
void postResumeCrashSafetyWireHandler(final Context context) {
// 主线程延迟 500ms 执行(避免页面启动时阻塞)
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
LogUtils.d(TAG, "Handler run()");
// 检查:若当前等级-1 后超出防护范围(即将熔断),则恢复到最高等级
if (!AppCrashSafetyWire.getInstance().isSafetyWireWorking(currentSafetyLevel - 1)) {
AppCrashSafetyWire.getInstance().resumeToMaximumImmediately();
LogUtils.d(TAG, "postResumeCrashSafetyWireHandler: 恢复保险丝到最高等级");
}
}
}, 500);
}
}

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;
@@ -23,7 +22,9 @@ import android.widget.HorizontalScrollView;
import android.widget.ScrollView; import android.widget.ScrollView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import cc.winboll.studio.libappbase.utils.CrashHandleNotifyUtils; import cc.winboll.studio.libappbase.utils.CrashHandleNotifyUtils;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@@ -38,521 +39,292 @@ import java.util.Date;
import java.util.Locale; import java.util.Locale;
/** /**
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com> * 应用全局崩溃处理类(单例逻辑)
* @Date 2025/11/11 20:14
* @Describe * 应用全局崩溃处理类(单例逻辑)
* 核心功能:捕获应用未捕获异常,记录崩溃日志到文件,启动崩溃报告页面, * 核心功能:捕获应用未捕获异常,记录崩溃日志到文件,启动崩溃报告页面,
* 并通过「崩溃保险丝」机制防止重复崩溃,保障基础功能可用 * 并通过「崩溃保险丝」机制防止重复崩溃,保障基础功能可用
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
* @CreateTime 2025/11/11 20:14:00
* @EditTime 2026/05/11 15:36:45
*/ */
public final class CrashHandler { public final class CrashHandler {
/** 日志标签,用于当前类的日志输出标识 */ // ====================== 常量定义 ======================
public static final String TAG = "CrashHandler"; /** 日志标签 */
public static final String TAG = "CrashHandler";
/** 崩溃报告页面标题 */
public static final String TITTLE = "CrashReport";
/** Intent 传递崩溃信息键 */
public static final String EXTRA_CRASH_LOG = "crashInfo";
/** SharedPreferences 存储键 */
static final String PREFS = CrashHandler.class.getName() + "PREFS";
/** 标记是否发生崩溃键 */
static final String PREFS_CRASHHANDLER_ISCRASHHAPPEN = "PREFS_CRASHHANDLER_ISCRASHHAPPEN";
/** 崩溃报告页面标题 */ // ====================== 成员变量 ======================
public static final String TITTLE = "CrashReport"; /** 崩溃保险丝状态文件路径 */
public static String _CrashCountFilePath;
/** 系统默认异常处理器兜底 */
public static final UncaughtExceptionHandler DEFAULT_UNCAUGHT_EXCEPTION_HANDLER
= Thread.getDefaultUncaughtExceptionHandler();
/** Intent 传递崩溃信息的键(用于向崩溃页面传递日志) */ // ====================== 对外初始化方法 ======================
public static final String EXTRA_CRASH_LOG = "crashInfo"; /**
* 初始化崩溃处理器(默认存储路径)
* @param app 全局Application实例
*/
public static void init(final Application app) {
_CrashCountFilePath = app.getExternalFilesDir("CrashHandler") + "/IsCrashHandlerCrashHappen.dat";
LogUtils.d(TAG, "init _CrashCountFilePath = " + _CrashCountFilePath);
init(app, null);
}
/** SharedPreferences 存储键(用于记录崩溃状态) */ /**
final static String PREFS = CrashHandler.class.getName() + "PREFS"; * 初始化崩溃处理器(自定义日志目录)
/** SharedPreferences 中存储「是否发生崩溃」的键 */ * @param app 全局Application实例
final static String PREFS_CRASHHANDLER_ISCRASHHAPPEN = "PREFS_CRASHHANDLER_ISCRASHHAPPEN"; * @param crashDir 自定义崩溃日志目录传null使用默认
*/
/** 崩溃保险丝状态文件路径(存储当前熔断等级) */ public static void init(final Application app, final String crashDir) {
public static String _CrashCountFilePath; Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
/** 系统默认的未捕获异常处理器(用于降级处理,避免 CrashHandler 自身崩溃) */
public static final UncaughtExceptionHandler DEFAULT_UNCAUGHT_EXCEPTION_HANDLER = Thread.getDefaultUncaughtExceptionHandler();
/**
* 初始化崩溃处理器(默认存储路径)
* 调用重载方法,崩溃日志默认存储在应用外部私有目录的 crash 文件夹下
* @param app 全局 Application 实例(用于获取存储目录、包信息等)
*/
public static void init(Application app) {
// 初始化崩溃保险丝状态文件路径(外部存储/CrashHandler/IsCrashHandlerCrashHappen.dat
_CrashCountFilePath = app.getExternalFilesDir("CrashHandler") + "/IsCrashHandlerCrashHappen.dat";
LogUtils.d(TAG, String.format("_CrashCountFilePath %s", _CrashCountFilePath));
// 调用带目录参数的初始化方法,传入 null 使用默认路径
init(app, null);
}
/**
* 初始化崩溃处理器(指定日志存储目录)
* 替换系统默认的未捕获异常处理器,自定义崩溃处理逻辑
* @param app 全局 Application 实例
* @param crashDir 崩溃日志存储目录null 则使用默认路径)
*/
public static void init(final Application app, final String crashDir) {
// 设置自定义未捕获异常处理器
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override @Override
public void uncaughtException(Thread thread, Throwable throwable) { public void uncaughtException(final Thread thread, final Throwable throwable) {
try { try {
// 尝试处理崩溃(捕获内部异常,避免 CrashHandler 自身崩溃) tryUncaughtException(thread, throwable, crashDir, app);
tryUncaughtException(thread, throwable);
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); LogUtils.e(TAG, "uncaughtException error", e);
// 处理失败时,交给系统默认处理器兜底
if (DEFAULT_UNCAUGHT_EXCEPTION_HANDLER != null) { if (DEFAULT_UNCAUGHT_EXCEPTION_HANDLER != null) {
DEFAULT_UNCAUGHT_EXCEPTION_HANDLER.uncaughtException(thread, throwable); DEFAULT_UNCAUGHT_EXCEPTION_HANDLER.uncaughtException(thread, throwable);
} }
} }
} }
/**
* 实际处理崩溃的核心方法
* 1. 熔断保险丝记录崩溃次数2. 收集崩溃信息3. 写入日志文件4. 启动崩溃报告页面
* @param thread 发生崩溃的线程
* @param throwable 崩溃异常对象(包含堆栈信息)
*/
private void tryUncaughtException(Thread thread, Throwable throwable) {
// 触发崩溃保险丝(每次崩溃熔断一次,降低防护等级)
AppCrashSafetyWire.getInstance().burnSafetyWire();
// 格式化崩溃发生时间(用于日志文件名和内容)
final String time = new SimpleDateFormat("yyyy_MM_dd-HH_mm_ss", Locale.getDefault()).format(new Date());
// 创建崩溃日志文件(默认路径:外部存储/crash/[时间].txt
File crashFile = new File(
TextUtils.isEmpty(crashDir) ? new File(app.getExternalFilesDir(null), "crash") : new File(crashDir),
"crash_" + time + ".txt"
);
// 获取应用版本信息(版本名、版本号)
String versionName = "unknown";
long versionCode = 0;
try {
PackageInfo packageInfo = app.getPackageManager().getPackageInfo(app.getPackageName(), 0);
versionName = packageInfo.versionName;
// 适配 Android 9.0+API 28的版本号获取方式
versionCode = Build.VERSION.SDK_INT >= 28 ? packageInfo.getLongVersionCode() : packageInfo.versionCode;
} catch (PackageManager.NameNotFoundException ignored) {}
// 将异常堆栈信息转换为字符串
String fullStackTrace;
{
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
throwable.printStackTrace(pw); // 将异常堆栈写入 PrintWriter
fullStackTrace = sw.toString();
pw.close();
}
// 拼接崩溃信息(设备信息 + 应用信息 + 堆栈信息)
StringBuilder sb = new StringBuilder();
sb.append("************* Crash Head ****************\n");
sb.append("Time Of Crash : ").append(time).append("\n");
sb.append("Device Manufacturer : ").append(Build.MANUFACTURER).append("\n"); // 设备厂商
sb.append("Device Model : ").append(Build.MODEL).append("\n"); // 设备型号
sb.append("Android Version : ").append(Build.VERSION.RELEASE).append("\n"); // Android 版本
sb.append("Android SDK : ").append(Build.VERSION.SDK_INT).append("\n"); // SDK 版本
sb.append("App VersionName : ").append(versionName).append("\n"); // 应用版本名
sb.append("App VersionCode : ").append(versionCode).append("\n"); // 应用版本号
sb.append("************* Crash Head ****************\n");
sb.append("\n").append(fullStackTrace); // 拼接异常堆栈
final String errorLog = sb.toString();
// 将崩溃日志写入文件(忽略写入失败)
try {
writeFile(crashFile, errorLog);
} catch (IOException ignored) {}
// 启动崩溃报告页面(标签用于代码块折叠)
gotoCrashActiviy: {
Intent intent = new Intent();
LogUtils.d(TAG, "gotoCrashActiviy: ");
// 根据保险丝状态选择启动的崩溃页面
if (AppCrashSafetyWire.getInstance().isAppCrashSafetyWireOK()) {
LogUtils.d(TAG, "gotoCrashActiviy: isAppCrashSafetyWireOK");
// 保险丝正常启动自定义样式的崩溃报告页面GlobalCrashActivity
intent.setClass(app, GlobalCrashActivity.class);
intent.putExtra(EXTRA_CRASH_LOG, errorLog); // 传递崩溃日志
} else {
LogUtils.d(TAG, "gotoCrashActiviy: else");
// 保险丝熔断启动基础版崩溃页面CrashActivity避免复杂页面再次崩溃
intent.setClass(app, CrashActivity.class);
intent.putExtra(EXTRA_CRASH_LOG, errorLog);
}
// 设置意图标志:清除原有任务栈,创建新任务(避免回到崩溃前页面)
intent.addFlags(
Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_CLEAR_TASK
);
try {
if (GlobalApplication.isDebugging()&&AppCrashSafetyWire.getInstance().isAppCrashSafetyWireOK()) {
// 如果是 debug 版,启动崩溃页面窗口
app.startActivity(intent);
} else {
// 如果是 release 版,就只发送一个通知
CrashHandleNotifyUtils.handleUncaughtException(app, intent);
}
// 终止当前进程(确保完全重启)
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(0);
} catch (ActivityNotFoundException e) {
// 未找到崩溃页面(如未在 Manifest 注册),交给系统默认处理器
e.printStackTrace();
if (DEFAULT_UNCAUGHT_EXCEPTION_HANDLER != null) {
DEFAULT_UNCAUGHT_EXCEPTION_HANDLER.uncaughtException(thread, throwable);
}
} catch (Exception e) {
// 其他异常,兜底处理
e.printStackTrace();
if (DEFAULT_UNCAUGHT_EXCEPTION_HANDLER != null) {
DEFAULT_UNCAUGHT_EXCEPTION_HANDLER.uncaughtException(thread, throwable);
}
}
}
}
/**
* 将字符串内容写入文件(创建父目录、覆盖写入)
* @param file 目标文件(包含路径)
* @param content 待写入的内容(崩溃日志)
* @throws IOException 文件创建或写入失败时抛出
*/
private void writeFile(File file, String content) throws IOException {
File parentFile = file.getParentFile();
// 父目录不存在则创建
if (parentFile != null && !parentFile.exists()) {
parentFile.mkdirs();
}
file.createNewFile(); // 创建文件
FileOutputStream fos = new FileOutputStream(file);
fos.write(content.getBytes()); // 写入内容(默认 UTF-8 编码)
try {
fos.close(); // 关闭流
} catch (IOException e) {}
}
}); });
} }
/** // ====================== 内部崩溃处理核心 ======================
* 应用崩溃保险丝内部类(单例) /**
* 核心作用:限制短时间内重复崩溃,通过「熔断等级」控制崩溃页面启动策略 * 执行崩溃信息收集、日志写入、跳转崩溃页面
* 等级范围MINI1~ MAX2每次崩溃等级-1熔断后启动基础版崩溃页面 */
*/ private static void tryUncaughtException(final Thread thread,
public static final class AppCrashSafetyWire { final Throwable throwable,
final String crashDir,
final Application app) {
// 触发崩溃保险丝
AppCrashSafetyWire.getInstance().burnSafetyWire();
/** 单例实例volatile 保证多线程可见性) */ // 格式化时间
private static volatile AppCrashSafetyWire _AppCrashSafetyWire; final String time = new SimpleDateFormat("yyyy_MM_dd-HH_mm_ss",
Locale.getDefault()).format(new Date());
/** 当前熔断等级1最低防护2最高防护≤0熔断 */ // 创建日志文件
private volatile Integer currentSafetyLevel; File logParent = TextUtils.isEmpty(crashDir)
/** 最低熔断等级1再崩溃则熔断 */ ? new File(app.getExternalFilesDir(null), "crash")
private static final int _MINI = 1; : new File(crashDir);
/** 最高熔断等级2初始状态 */ final File crashFile = new File(logParent, "crash_" + time + ".txt");
private static final int _MAX = 2;
/** // 获取应用版本信息
* 私有构造方法(单例模式,禁止外部实例化) String versionName = "unknown";
* 初始化时加载本地存储的熔断等级 long versionCode = 0;
*/ try {
private AppCrashSafetyWire() { final PackageInfo packageInfo = app.getPackageManager()
LogUtils.d(TAG, "AppCrashSafetyWire()"); .getPackageInfo(app.getPackageName(), 0);
currentSafetyLevel = loadCurrentSafetyLevel(); versionName = packageInfo.versionName;
} if (Build.VERSION.SDK_INT >= 28) {
versionCode = packageInfo.getLongVersionCode();
} else {
versionCode = packageInfo.versionCode;
}
} catch (PackageManager.NameNotFoundException e) {
LogUtils.e(TAG, "get package info fail");
}
/** // 抓取异常堆栈
* 获取单例实例(双重检查锁定,线程安全) String fullStackTrace;
* @return AppCrashSafetyWire 单例 StringWriter sw = new StringWriter();
*/ PrintWriter pw = new PrintWriter(sw);
public static synchronized AppCrashSafetyWire getInstance() { throwable.printStackTrace(pw);
if (_AppCrashSafetyWire == null) { fullStackTrace = sw.toString();
_AppCrashSafetyWire = new AppCrashSafetyWire(); pw.close();
}
return _AppCrashSafetyWire;
}
/** // 拼接崩溃头部信息
* 设置当前熔断等级(内存中) StringBuilder sb = new StringBuilder();
* @param currentSafetyLevel 目标等级1~2 sb.append("************* Crash Head ****************\n");
*/ sb.append("Time Of Crash : ").append(time).append("\n");
public void setCurrentSafetyLevel(int currentSafetyLevel) { sb.append("Device Manufacturer : ").append(Build.MANUFACTURER).append("\n");
this.currentSafetyLevel = currentSafetyLevel; sb.append("Device Model : ").append(Build.MODEL).append("\n");
} sb.append("Android Version : ").append(Build.VERSION.RELEASE).append("\n");
sb.append("Android SDK : ").append(Build.VERSION.SDK_INT).append("\n");
sb.append("App VersionName : ").append(versionName).append("\n");
sb.append("App VersionCode : ").append(versionCode).append("\n");
sb.append("************* Crash Head ****************\n");
sb.append("\n").append(fullStackTrace);
/** final String errorLog = sb.toString();
* 获取当前熔断等级(内存中)
* @return 当前等级1~2 或 null
*/
public int getCurrentSafetyLevel() {
return currentSafetyLevel;
}
/** // 写入日志文件
* 保存熔断等级到本地文件(持久化,重启应用生效) try {
* @param currentSafetyLevel 待保存的等级 writeFile(crashFile, errorLog);
*/ } catch (IOException e) {
public void saveCurrentSafetyLevel(int currentSafetyLevel) { LogUtils.e(TAG, "write crash log file fail");
LogUtils.d(TAG, "saveCurrentSafetyLevel()"); }
this.currentSafetyLevel = currentSafetyLevel;
try {
// 序列化等级到文件ObjectOutputStream 写入 int
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(_CrashCountFilePath));
oos.writeInt(currentSafetyLevel);
oos.flush();
oos.close();
LogUtils.d(TAG, String.format("saveCurrentSafetyLevel writeInt currentSafetyLevel %d", currentSafetyLevel));
} catch (IOException e) {
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
}
}
/** // 跳转崩溃页面
* 从本地文件加载熔断等级(应用启动时初始化) gotoCrashActivity(errorLog, app);
* @return 加载的等级(文件不存在则初始化为 MAX2 }
*/
public int loadCurrentSafetyLevel() {
LogUtils.d(TAG, "loadCurrentSafetyLevel()");
try {
File f = new File(_CrashCountFilePath);
if (f.exists()) {
// 反序列化从文件读取等级
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(_CrashCountFilePath));
currentSafetyLevel = ois.readInt();
LogUtils.d(TAG, String.format("loadCurrentSafetyLevel() readInt currentSafetyLevel %d", currentSafetyLevel));
} else {
// 文件不存在初始化等级为最高2并保存
currentSafetyLevel = _MAX;
LogUtils.d(TAG, String.format("loadCurrentSafetyLevel() currentSafetyLevel init to _MAX->%d", _MAX));
saveCurrentSafetyLevel(currentSafetyLevel);
}
} catch (IOException e) {
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
}
return currentSafetyLevel;
}
/** /**
* 熔断保险丝(每次崩溃调用,降低防护等级) * 写入文本到文件
* @return 熔断后是否仍在防护范围内truefalse已熔断 */
*/ private static void writeFile(final File file, final String content) throws IOException {
boolean burnSafetyWire() { final File parentFile = file.getParentFile();
LogUtils.d(TAG, "burnSafetyWire()"); if (parentFile != null && !parentFile.exists()) {
// 加载当前等级 parentFile.mkdirs();
int safeLevel = loadCurrentSafetyLevel(); }
// 若在防护范围内1~2等级-1 并保存 file.createNewFile();
if (isSafetyWireWorking(safeLevel)) { FileOutputStream fos = new FileOutputStream(file);
LogUtils.d(TAG, "burnSafetyWire() use"); fos.write(content.getBytes());
saveCurrentSafetyLevel(safeLevel - 1); fos.close();
// 返回熔断后的状态 }
return isSafetyWireWorking(safeLevel - 1);
}
return false;
}
/** /**
* 检查熔断等级是否在有效范围内1~2 * 根据保险丝状态跳转对应崩溃页面
* @param safetyLevel 待检查的等级 */
* @return true在范围内防护有效false超出范围已熔断 private static void gotoCrashActivity(final String errorLog, final Application app) {
*/ final Intent intent = new Intent();
boolean isSafetyWireWorking(int safetyLevel) { if (AppCrashSafetyWire.getInstance().isAppCrashSafetyWireOK()) {
LogUtils.d(TAG, "isSafetyWireOK()"); intent.setClass(app, GlobalCrashActivity.class);
LogUtils.d(TAG, String.format("SafetyLevel %d", safetyLevel)); } else {
intent.setClass(app, CrashActivity.class);
}
intent.putExtra(EXTRA_CRASH_LOG, errorLog);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
if (safetyLevel >= _MINI && safetyLevel <= _MAX) { try {
LogUtils.d(TAG, String.format("In Safety Level")); if (GlobalApplication.isDebugging()) {
return true; app.startActivity(intent);
} } else {
LogUtils.d(TAG, String.format("Out of Safety Level")); CrashHandleNotifyUtils.handleUncaughtException(app, intent, GlobalCrashActivity.class);
return false; }
} android.os.Process.killProcess(android.os.Process.myPid());
System.exit(0);
} catch (ActivityNotFoundException e) {
LogUtils.e(TAG, "CrashActivity not found");
if (DEFAULT_UNCAUGHT_EXCEPTION_HANDLER != null) {
DEFAULT_UNCAUGHT_EXCEPTION_HANDLER.uncaughtException(Thread.currentThread(), e);
}
} catch (Exception e) {
LogUtils.e(TAG, "start CrashActivity error");
if (DEFAULT_UNCAUGHT_EXCEPTION_HANDLER != null) {
DEFAULT_UNCAUGHT_EXCEPTION_HANDLER.uncaughtException(Thread.currentThread(), e);
}
}
}
/** // ====================== 内部Activity页面 ======================
* 立即恢复熔断等级到最高2 /**
* 用于重启应用后重置防护状态 * 基础极简崩溃页面
*/ * 保险丝熔断时启动,避免复杂布局二次崩溃
void resumeToMaximumImmediately() { */
LogUtils.d(TAG, "resumeToMaximumImmediately() call saveCurrentSafetyLevel(_MAX)"); public static final class CrashActivity extends Activity implements MenuItem.OnMenuItemClickListener {
AppCrashSafetyWire.getInstance().saveCurrentSafetyLevel(_MAX); private static final int MENUITEM_COPY = 0;
} private static final int MENUITEM_RESTART = 1;
/** private String mLog;
* 关闭防护设置等级为最低1
* 下次崩溃直接熔断
*/
void off() {
LogUtils.d(TAG, "off()");
saveCurrentSafetyLevel(_MINI);
}
/** @Override
* 检查当前保险丝是否有效(防护未熔断) protected void onCreate(final Bundle savedInstanceState) {
* @return true有效等级 1~2false已熔断 super.onCreate(savedInstanceState);
*/ AppCrashSafetyWire.getInstance().postResumeCrashSafetyWireHandler(getApplicationContext());
boolean isAppCrashSafetyWireOK() { mLog = getIntent().getStringExtra(EXTRA_CRASH_LOG);
LogUtils.d(TAG, "isAppCrashSafetyWireOK()"); setTheme(android.R.style.Theme_DeviceDefault_Light_DarkActionBar);
currentSafetyLevel = loadCurrentSafetyLevel(); initLayout();
return isSafetyWireWorking(currentSafetyLevel); }
}
/** /**
* 延迟恢复保险丝到最高等级500ms 后) * 动态初始化布局
* 核心作用:崩溃页面启动后,若下次即将熔断,提前恢复防护等级,避免持续崩溃 */
* @param context 上下文(用于获取主线程 Handler private void initLayout() {
*/ ScrollView contentView = new ScrollView(this);
void postResumeCrashSafetyWireHandler(final Context context) { contentView.setFillViewport(true);
// 主线程延迟 500ms 执行(避免页面启动时阻塞)
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
LogUtils.d(TAG, "Handler run()");
// 检查:若当前等级-1 后超出防护范围(即将熔断),则恢复到最高等级
if (!AppCrashSafetyWire.getInstance().isSafetyWireWorking(currentSafetyLevel - 1)) {
AppCrashSafetyWire.getInstance().resumeToMaximumImmediately();
LogUtils.d(TAG, "postResumeCrashSafetyWireHandler: 恢复保险丝到最高等级");
}
}
}, 500);
}
}
/** HorizontalScrollView hw = new HorizontalScrollView(this);
* 基础版崩溃报告页面(保险丝熔断时启动) hw.setBackgroundColor(0xFFF5F5F5);
* 极简实现:仅展示崩溃日志,提供复制、重启功能,避免复杂布局导致二次崩溃
*/
public static final class CrashActivity extends Activity implements MenuItem.OnMenuItemClickListener {
/** 菜单标识:复制崩溃日志 */
private static final int MENUITEM_COPY = 0;
/** 菜单标识:重启应用 */
private static final int MENUITEM_RESTART = 1;
/** 崩溃日志文本(从 CrashHandler 传递过来) */ TextView message = new TextView(this);
private String mLog; final int padding = dp2px(16);
message.setPadding(padding, padding, padding, padding);
message.setText(mLog);
message.setTextColor(0xFF000000);
message.setTextIsSelectable(true);
@Override hw.addView(message);
protected void onCreate(Bundle savedInstanceState) { contentView.addView(hw, ViewGroup.LayoutParams.MATCH_PARENT,
super.onCreate(savedInstanceState); ViewGroup.LayoutParams.MATCH_PARENT);
// 初始化崩溃保险丝延迟恢复机制 setContentView(contentView);
AppCrashSafetyWire.getInstance().postResumeCrashSafetyWireHandler(getApplicationContext());
// 获取传递的崩溃日志 getActionBar().setTitle(TITTLE);
mLog = getIntent().getStringExtra(EXTRA_CRASH_LOG); getActionBar().setSubtitle(GlobalApplication.class.getSimpleName() + " Error");
// 设置系统默认主题(避免自定义主题冲突) }
setTheme(android.R.style.Theme_DeviceDefault_Light_DarkActionBar);
// 动态创建布局(避免 XML 布局加载异常) @Override
setContentView: { public void onBackPressed() {
// 垂直滚动视图(处理日志过长) restartApp();
ScrollView contentView = new ScrollView(this); }
contentView.setFillViewport(true);
// 水平滚动视图(处理日志行过长) /**
HorizontalScrollView hw = new HorizontalScrollView(this); * 重启应用
hw.setBackgroundColor(0xFFF5F5F5); // 深色模式灰色背景 */
private void restartApp() {
final Intent intent = getPackageManager()
.getLaunchIntentForPackage(getPackageName());
if (intent != null) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
}
finish();
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(0);
}
// 日志显示文本框 /**
TextView message = new TextView(this); * dp转px
{ */
int padding = dp2px(16); // 内边距 16dp适配不同屏幕 private int dp2px(final float dpValue) {
message.setPadding(padding, padding, padding, padding); final float scale = Resources.getSystem().getDisplayMetrics().density;
message.setText(mLog); // 设置崩溃日志 return (int) (dpValue * scale + 0.5f);
message.setTextColor(0xFF000000); // 深色模式灰色文字,普通模式黑色文字 }
message.setTextIsSelectable(true); // 支持文本选择(便于手动复制)
}
// 组装布局TextView -> HorizontalScrollView -> ScrollView @Override
hw.addView(message); public boolean onCreateOptionsMenu(final Menu menu) {
contentView.addView(hw, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); menu.add(0, MENUITEM_COPY, 0, "Copy")
// 设置当前 Activity 布局
setContentView(contentView);
// 配置 ActionBar 标题和副标题
getActionBar().setTitle(TITTLE);
getActionBar().setSubtitle(GlobalApplication.class.getSimpleName() + " Error");
}
}
/**
* 重写返回键逻辑:点击返回键直接重启应用
*/
@Override
public void onBackPressed() {
restart();
}
/**
* 重启当前应用(与 GlobalCrashActivity 逻辑一致)
* 清除任务栈,启动主 Activity终止当前进程
*/
private void restart() {
PackageManager pm = getPackageManager();
// 获取应用启动意图(默认启动主 Activity
Intent intent = pm.getLaunchIntentForPackage(getPackageName());
if (intent != null) {
// 设置意图标志:清除原有任务栈,创建新任务
intent.addFlags(
Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_CLEAR_TASK
);
startActivity(intent);
}
// 关闭当前页面,终止进程,确保完全重启
finish();
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(0);
}
/**
* dp 转 px适配不同屏幕密度
* @param dpValue dp 值
* @return 转换后的 px 值
*/
private int dp2px(final float dpValue) {
final float scale = Resources.getSystem().getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f); // 四舍五入确保精度
}
/**
* 菜单点击事件回调(处理复制、重启)
* @param item 被点击的菜单项
* @return false不消费事件保持默认行为
*/
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case MENUITEM_COPY:
// 复制日志到剪贴板
ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
cm.setPrimaryClip(ClipData.newPlainText(getPackageName(), mLog));
Toast.makeText(getApplication(), "The text is copied.", Toast.LENGTH_SHORT).show();
break;
case MENUITEM_RESTART:
// 恢复保险丝到最高等级,然后重启应用
AppCrashSafetyWire.getInstance().resumeToMaximumImmediately();
restart();
break;
}
return false;
}
/**
* 创建 ActionBar 菜单(添加复制、重启项)
* @param menu 菜单容器
* @return true显示菜单
*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// 添加「复制」菜单:有空间时显示在 ActionBar否则放入溢出菜单
menu.add(0, MENUITEM_COPY, 0, "Copy")
.setOnMenuItemClickListener(this) .setOnMenuItemClickListener(this)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
// 添加「重启」菜单:同上
menu.add(0, MENUITEM_RESTART, 0, "Restart") menu.add(0, MENUITEM_RESTART, 0, "Restart")
.setOnMenuItemClickListener(this) .setOnMenuItemClickListener(this)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
return true; return true;
} }
}
@Override
public boolean onMenuItemClick(final MenuItem item) {
switch (item.getItemId()) {
case MENUITEM_COPY:
ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
cm.setPrimaryClip(ClipData.newPlainText(getPackageName(), mLog));
Toast.makeText(getApplication(), "The text is copied.", Toast.LENGTH_SHORT).show();
break;
case MENUITEM_RESTART:
AppCrashSafetyWire.getInstance().resumeToMaximumImmediately();
restartApp();
break;
default:
break;
}
return false;
}
}
} }

View File

@@ -9,178 +9,142 @@ 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.utils.CrashHandleNotifyUtils;
/** /**
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com> * 应用异常报告观察活动窗口类
* @Date 2025/11/11 19:58
* @Describe 应用异常报告观察活动窗口类
* 核心功能:应用发生未捕获崩溃时,由 CrashHandler 启动此页面,展示崩溃日志详情, * 核心功能:应用发生未捕获崩溃时,由 CrashHandler 启动此页面,展示崩溃日志详情,
* 并提供「复制日志」「重启应用」操作入口,便于开发者定位问题和用户恢复应用 * 并提供「复制日志」「重启应用」操作入口,便于开发者定位问题和用户恢复应用
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
* @CreateTime 2025/11/11 19:58:00
* @EditTime 2026/05/11 15:40:12
*/ */
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(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); LogUtils.d(TAG, "onCreate 方法进入");
try {
super.onCreate(savedInstanceState);
final Context appContext = getApplicationContext();
// 初始化崩溃安全防护机制
AppCrashSafetyWire.getInstance().postResumeCrashSafetyWireHandler(appContext);
// 初始化崩溃安全防护机制 // 获取传递的崩溃日志
// 作用:防止应用重启后短时间内再次崩溃,由 CrashHandler 内部实现防护逻辑 mCrashLog = getIntent().getStringExtra(CrashHandler.EXTRA_CRASH_LOG);
CrashHandler.AppCrashSafetyWire.getInstance() LogUtils.d(TAG, "获取到崩溃日志,长度:" + (mCrashLog != null ? mCrashLog.length() : 0));
.postResumeCrashSafetyWireHandler(getApplicationContext());
// 从 Intent 中获取崩溃日志数据EXTRA_CRASH_INFO 为 CrashHandler 定义的常量键) setContentView(R.layout.activity_globalcrash);
mCrashLog = getIntent().getStringExtra(CrashHandler.EXTRA_CRASH_LOG); mCrashReportView = findViewById(R.id.activityglobalcrashGlobalCrashReportView1);
mCrashReportView.setReport(mCrashLog);
// 设置当前 Activity 的布局文件(展示崩溃报告的 UI 结构) setActionBar(mCrashReportView.getToolbar());
setContentView(R.layout.activity_globalcrash); if (getActionBar() != null) {
getActionBar().setTitle(CrashHandler.TITTLE);
getActionBar().setSubtitle(GlobalApplication.getAppName(appContext));
}
} catch (final Exception e) {
LogUtils.e(TAG, "GlobalCrashActivity onCreate 发生异常", e);
AppCrashSafetyWire.getInstance().burnSafetyWire();
// 初始化崩溃报告展示视图(通过布局 ID 找到自定义 View 实例) mCrashLog = getIntent().getStringExtra(CrashHandler.EXTRA_CRASH_LOG);
mCrashReportView = findViewById(R.id.activityglobalcrashGlobalCrashReportView1); final Intent intent = new Intent();
// 将崩溃日志设置到视图中,由自定义 View 负责排版和显示 intent.putExtra(CrashHandler.EXTRA_CRASH_LOG, mCrashLog);
mCrashReportView.setReport(mCrashLog); CrashHandleNotifyUtils.handleUncaughtException(GlobalApplication.getInstance(), intent, CrashHandler.CrashActivity.class);
// 设置页面的 ActionBar复用自定义 View 中的 Toolbar 作为系统 ActionBar StackTraceElement[] stackElements = Thread.currentThread().getStackTrace();
setActionBar(mCrashReportView.getToolbar()); StringBuilder sb = new StringBuilder("GlobalCrashActivity onCreate StackTrace");
for (StackTraceElement item : stackElements) {
// 配置 ActionBar 标题和副标题(非空判断避免空指针异常) sb.append("\n").append(item.toString());
if (getActionBar() != null) { }
// 设置标题:使用 CrashHandler 中定义的统一标题(如 "应用崩溃报告" LogUtils.d(TAG, sb.toString());
getActionBar().setTitle(CrashHandler.TITTLE); finish();
// 设置副标题:显示当前应用名称(从全局 Application 工具方法获取)
getActionBar().setSubtitle(GlobalApplication.getAppName(getApplicationContext()));
} }
} }
/**
* 重写返回键点击事件
* 逻辑:点击手机返回键时,直接重启应用(而非返回上一页,因崩溃后上一页状态可能异常)
*/
@Override @Override
public void onBackPressed() { public void onBackPressed() {
LogUtils.d(TAG, "onBackPressed 触发重启应用");
restartApp(); restartApp();
} }
/** // ====================== 菜单相关回调 ======================
* 重启当前应用(核心工具方法) @Override
* 实现逻辑: public boolean onCreateOptionsMenu(final Menu menu) {
* 1. 获取应用的启动意图(默认启动 AndroidManifest 中配置的主 Activity LogUtils.d(TAG, "onCreateOptionsView 初始化菜单");
* 2. 设置意图标志,清除原有任务栈,避免残留异常页面 menu.add(0, MENU_ITEM_COPY, 0, "Copy")
* 3. 启动主 Activity 并终止当前进程,确保应用完全重启 .setOnMenuItemClickListener(this)
*/ .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
private void restartApp() {
// 获取 PackageManager 实例(用于获取应用相关信息和意图)
PackageManager packageManager = getPackageManager();
// 获取应用的启动意图(参数为当前应用包名,返回主 Activity 的意图)
Intent launchIntent = packageManager.getLaunchIntentForPackage(getPackageName());
if (launchIntent != null) { menu.add(0, MENU_ITEM_RESTART, 0, "Restart")
// 设置意图标志: .setOnMenuItemClickListener(this)
// FLAG_ACTIVITY_NEW_TASK创建新的任务栈启动 Activity .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
// FLAG_ACTIVITY_CLEAR_TOP清除目标 Activity 之上的所有 Activity
// FLAG_ACTIVITY_CLEAR_TASK清除当前任务栈中的所有 Activity
launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
// 启动应用主 Activity
startActivity(launchIntent);
}
// 关闭当前崩溃报告页面 mCrashReportView.updateMenuStyle();
finish(); return true;
// 终止当前应用进程(确保释放所有资源,避免内存泄漏)
android.os.Process.killProcess(android.os.Process.myPid());
// 强制退出虚拟机(彻底终止应用,防止残留线程继续运行)
System.exit(0);
} }
/**
* 菜单项点击事件回调(实现 MenuItem.OnMenuItemClickListener 接口)
* @param item 被点击的菜单项实例
* @return booleantrue 表示事件已消费不再向下传递false 表示未消费
*/
@Override @Override
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(final MenuItem item) {
// 根据菜单项 ID 判断点击的是哪个功能 LogUtils.d(TAG, "菜单项被点击ID" + item.getItemId());
switch (item.getItemId()) { switch (item.getItemId()) {
case MENU_ITEM_COPY: case MENU_ITEM_COPY:
// 点击「复制」菜单,执行复制崩溃日志到剪贴板
copyCrashLogToClipboard(); copyCrashLogToClipboard();
break; break;
case MENU_ITEM_RESTART: case MENU_ITEM_RESTART:
// 点击「重启」菜单:先恢复崩溃防护机制到最大等级,再重启应用 AppCrashSafetyWire.getInstance().resumeToMaximumImmediately();
CrashHandler.AppCrashSafetyWire.getInstance().resumeToMaximumImmediately();
restartApp(); restartApp();
break; break;
default:
break;
} }
return false; return false;
} }
// ====================== 内部私有工具方法 ======================
/** /**
* 创建页面顶部菜单ActionBar 菜单) * 重启当前应用
* @param menu 菜单容器,用于添加菜单项
* @return booleantrue 表示显示菜单false 表示不显示
*/ */
@Override private void restartApp() {
public boolean onCreateOptionsMenu(Menu menu) { LogUtils.d(TAG, "开始执行应用重启逻辑");
// 添加「复制」菜单项: final PackageManager packageManager = getPackageManager();
// 参数说明:菜单组 ID0 表示默认组)、菜单项 IDMENU_ITEM_COPY、排序号0、菜单文本"Copy" final Intent launchIntent = packageManager.getLaunchIntentForPackage(getPackageName());
// setOnMenuItemClickListener(this):绑定点击事件到当前 Activity
// setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM):有空间时显示在 ActionBar 上,否则放入溢出菜单
menu.add(0, MENU_ITEM_COPY, 0, "Copy")
.setOnMenuItemClickListener(this)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
// 添加「重启」菜单项(参数含义同上) if (launchIntent != null) {
menu.add(0, MENU_ITEM_RESTART, 0, "Restart") launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
.setOnMenuItemClickListener(this) | Intent.FLAG_ACTIVITY_CLEAR_TOP
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(launchIntent);
// 调用自定义视图的方法,更新菜单文字样式(如颜色、字体大小等,由自定义 View 内部实现) }
mCrashReportView.updateMenuStyle(); finish();
android.os.Process.killProcess(android.os.Process.myPid());
return true; System.exit(0);
} }
/** /**
* 将崩溃日志复制到系统剪贴板(工具方法) * 将崩溃日志复制到系统剪贴板
* 功能:用户点击复制菜单后,将完整崩溃日志存入剪贴板,方便粘贴到聊天工具或文档中
*/ */
private void copyCrashLogToClipboard() { private void copyCrashLogToClipboard() {
// 获取系统剪贴板服务(需通过 getSystemService 方法获取) LogUtils.d(TAG, "执行复制崩溃日志到剪贴板");
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

@@ -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

@@ -8,6 +8,7 @@ package cc.winboll.studio.libappbase;
import android.content.ClipData; import android.content.ClipData;
import android.content.ClipboardManager; import android.content.ClipboardManager;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.text.Editable; import android.text.Editable;
@@ -248,7 +249,10 @@ public class LogView extends RelativeLayout {
} }
mSelectAllTAGCheckBox.setLayoutParams(layoutParams2); mSelectAllTAGCheckBox.setLayoutParams(layoutParams2);
//mSelectAllTAGCheckBox.setPadding(0,0,0,0); //mSelectAllTAGCheckBox.setPadding(0,0,0,0);
mSelectAllTAGCheckBox.setTextColor(mContext.getResources().getColor(R.color.white)); TypedArray ta1 = mContext.obtainStyledAttributes(new int[] { R.attr.toolbarTextColor });
int toolbarTextColor1 = ta1.getColor(0, mContext.getResources().getColor(R.color.white));
ta1.recycle();
mSelectAllTAGCheckBox.setTextColor(toolbarTextColor1);
mSelectAllTAGCheckBox.setOnClickListener(new View.OnClickListener(){ mSelectAllTAGCheckBox.setOnClickListener(new View.OnClickListener(){
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@@ -502,10 +506,17 @@ public class LogView extends RelativeLayout {
} }
holder.tvText.setLayoutParams(layoutParams); holder.tvText.setLayoutParams(layoutParams);
holder.tvText.setPadding(0,0,0,0); holder.tvText.setPadding(0,0,0,0);
holder.tvText.setTextColor(mContext.getResources().getColor(R.color.white)); TypedArray ta2 = mContext.obtainStyledAttributes(new int[] { R.attr.toolbarTextColor });
int toolbarTextColor2 = ta2.getColor(0, mContext.getResources().getColor(R.color.white));
ta2.recycle();
holder.tvText.setTextColor(toolbarTextColor2);
holder.cbChecked.setChecked(item.isChecked()); holder.cbChecked.setChecked(item.isChecked());
holder.cbChecked.setLayoutParams(layoutParams); holder.cbChecked.setLayoutParams(layoutParams);
holder.cbChecked.setPadding(0,0,0,0); 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));
ta3.recycle();
holder.cbChecked.setTextColor(toolbarTextColor3);
holder.cbChecked.setOnClickListener(new View.OnClickListener(){ holder.cbChecked.setOnClickListener(new View.OnClickListener(){
@Override @Override

View File

@@ -1,33 +1,36 @@
package cc.winboll.studio.libappbase.utils; package cc.winboll.studio.libappbase.utils;
import android.app.Application;
import android.app.Notification; import android.app.Notification;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.text.TextUtils; import android.text.TextUtils;
import cc.winboll.studio.libappbase.CrashHandler; import cc.winboll.studio.libappbase.CrashHandler;
import cc.winboll.studio.libappbase.GlobalCrashActivity;
import cc.winboll.studio.libappbase.LogUtils; import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.libappbase.R;
import java.text.SimpleDateFormat; import java.io.BufferedReader;
import java.util.Date; import java.io.File;
import java.util.Locale; import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
/** /**
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com> * 应用崩溃处理通知实用工具集(类库兼容版)
* @Date 2025/11/29 21:12
* @Describe 应用崩溃处理通知实用工具集(类库兼容版)
* 核心功能:作为独立类库使用,发送崩溃通知,点击跳转宿主应用的 GlobalCrashActivity 并传递日志 * 核心功能:作为独立类库使用,发送崩溃通知,点击跳转宿主应用的 GlobalCrashActivity 并传递日志
* 适配说明:移除固定包名依赖,通过外部传入宿主包名,支持任意应用集成使用 * 适配说明:移除固定包名依赖,通过外部传入宿主包名,支持任意应用集成使用
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
* @CreateTime 2025/11/29 21:12:00
* @EditTime 2026/05/11 21:55:00
*/ */
public class CrashHandleNotifyUtils { public class CrashHandleNotifyUtils {
// ====================== 常量定义 ======================
public static final String TAG = "CrashHandleNotifyUtils"; public static final String TAG = "CrashHandleNotifyUtils";
/** 通知渠道IDAndroid 8.0+ 必须) */ /** 通知渠道IDAndroid 8.0+ 必须) */
private static final String CRASH_NOTIFY_CHANNEL_ID = "crash_notify_channel"; private static final String CRASH_NOTIFY_CHANNEL_ID = "crash_notify_channel";
/** 通知渠道名称(用户可见) */ /** 通知渠道名称(用户可见) */
@@ -38,202 +41,322 @@ public class CrashHandleNotifyUtils {
private static final int API_LEVEL_ANDROID_12 = 31; private static final int API_LEVEL_ANDROID_12 = 31;
/** PendingIntent.FLAG_IMMUTABLE 常量值API 31+ */ /** PendingIntent.FLAG_IMMUTABLE 常量值API 31+ */
private static final int FLAG_IMMUTABLE = 0x00000040; private static final int FLAG_IMMUTABLE = 0x00000040;
/** 通知摘要最大长度 */
private static final int SUMMARY_MAX_LENGTH = 200;
/** 分享日志请求码 */
private static final int REQUEST_CODE_SHARE_LOG = 0x002;
/** 缓存崩溃日志子目录 */
private static final String CRASH_LOG_CACHE_SUBDIR = "crashnotify";
/** 缓存崩溃日志文件名 */
private static final String CRASH_LOG_CACHE_FILENAME = "crash_log.txt";
/** 通知内容最大行数控制在3行超出部分省略 */ // ====================== 静态成员 ======================
private static final int NOTIFICATION_MAX_LINES = 3; private static String sHostPackageName = "";
private static String sCrashLogCacheFilePath = "";
// ====================== 正则表达式定义 ======================
private static final String REGEX_EXCEPTION_TYPE = "([\\w.]+Exception|[\\w.]+Error)";
private static final String REGEX_EXCEPTION_MESSAGE = "(?<=:\\s)(.+?)(?=\\n|\\r|$)";
private static final String REGEX_STACK_TRACE = "\\s+at\\s+([\\w.$]+)\\.([\\w<>]+)\\(([^:]+\\.java):(\\d+)\\)";
private static final String REGEX_CAUSE = "(?<=Caused by:\\s)" + REGEX_EXCEPTION_TYPE + "\\s*:";
// ====================== 对外核心方法 ======================
/** /**
* 处理未捕获异常(核心方法,类库入口) * 处理未捕获异常(类库入口核心方法
* 改进点:新增宿主包名参数,移除类库对固定包名的依赖 * @param hostApp 宿主Application实例
* @param hostApp 宿主应用的 Application 实例(用于获取宿主上下文) * @param hostPackageName 宿主应用包名
* @param hostPackageName 宿主应用的包名(关键:用于绑定意图、匹配 Activity * @param errorLog 崩溃日志内容
* @param errorLog 崩溃日志(从宿主 CrashHandler 传递过来) * @param reportCrashActivity 崩溃详情跳转Activity类
*/ */
public static void handleUncaughtException(Application hostApp, String hostPackageName, String errorLog) { public static void handleUncaughtException(final android.app.Application hostApp,
// 1. 校验核心参数(类库场景必须严格校验,避免空指针) final String hostPackageName,
final String errorLog,
final Class<?> reportCrashActivity) {
LogUtils.d(TAG, "handleUncaughtException 进入方法");
if (hostApp == null || TextUtils.isEmpty(hostPackageName) || TextUtils.isEmpty(errorLog)) { if (hostApp == null || TextUtils.isEmpty(hostPackageName) || TextUtils.isEmpty(errorLog)) {
LogUtils.e(TAG, "发送崩溃通知失败参数为空hostApp=" + hostApp + ", hostPackageName=" + hostPackageName + ", errorLog=" + errorLog + ""); LogUtils.e(TAG, "handleUncaughtException 参数为空校验不通过");
return; return;
} }
sHostPackageName = hostPackageName;
// 2. 获取宿主应用名称(使用宿主上下文,避免类库包名混淆) final String hostAppName = getHostAppName(hostApp, hostPackageName);
String hostAppName = getHostAppName(hostApp, hostPackageName); final String crashLogFilePath = saveCrashLogToCache(hostApp, errorLog);
if (TextUtils.isEmpty(crashLogFilePath)) {
// 3. 发送崩溃通知到宿主通知栏(点击跳转宿主的 GlobalCrashActivity LogUtils.e(TAG, "保存崩溃日志到缓存文件失败");
sendCrashNotification(hostApp, hostPackageName, hostAppName, errorLog); return;
}
sCrashLogCacheFilePath = crashLogFilePath;
final Intent shareIntent = new Intent(hostApp, ShareLogActivity.class);
shareIntent.putExtra(ShareLogActivity.EXTRA_CRASH_LOG_FILEPATH, crashLogFilePath);
shareIntent.putExtra(ShareLogActivity.EXTRA_CRASH_LOG_SUBJECT, "崩溃日志");
shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
final PendingIntent sharePendingIntent = createSharePendingIntent(hostApp, shareIntent);
sendCrashNotification(hostApp, hostPackageName, hostAppName, errorLog, reportCrashActivity, sharePendingIntent);
} }
/** /**
* 重载方法:兼容原有调用逻辑(避免宿主集成时改动过大) * 重载兼容方法:适配原有CrashHandler调用方式
* 从 Intent 中提取崩溃日志和宿主包名,适配原有 CrashHandler 调用方式 * @param hostApp 宿主Application实例
* @param hostApp 宿主应用的 Application 实例 * @param intent 携带崩溃信息Intent
* @param intent 存储崩溃信息的意图extra 中携带崩溃日志) * @param reportCrashActivity 崩溃详情Activity
*/ */
public static void handleUncaughtException(Application hostApp, Intent intent) { public static void handleUncaughtException(final android.app.Application hostApp,
// 从意图中提取宿主包名(优先使用意图中携带的包名,无则用宿主 Application 包名) final Intent intent,
final Class<?> reportCrashActivity) {
LogUtils.d(TAG, "handleUncaughtException 重载方法进入");
String hostPackageName = intent.getStringExtra("EXTRA_HOST_PACKAGE_NAME"); String hostPackageName = intent.getStringExtra("EXTRA_HOST_PACKAGE_NAME");
if (TextUtils.isEmpty(hostPackageName)) { if (TextUtils.isEmpty(hostPackageName)) {
hostPackageName = hostApp.getPackageName(); hostPackageName = hostApp.getPackageName();
LogUtils.w(TAG, "意图中未携带宿主包名,使用 Application 包名" + hostPackageName); LogUtils.w(TAG, "未携带宿主包名,默认使用应用自身包名");
} }
final String errorLog = intent.getStringExtra(CrashHandler.EXTRA_CRASH_LOG);
// 从意图中提取崩溃日志(与 CrashHandler.EXTRA_CRASH_INFO 保持一致) handleUncaughtException(hostApp, hostPackageName, errorLog, reportCrashActivity);
String errorLog = intent.getStringExtra(CrashHandler.EXTRA_CRASH_LOG);
// 调用核心方法处理
handleUncaughtException(hostApp, hostPackageName, errorLog);
} }
/** /**
* 获取宿主应用名称(类库场景适配:使用宿主包名获取,避免类库包名干扰) * 资源释放
* @param hostContext 宿主应用的上下文Application 实例) * @param hostContext 宿主上下文
* @param hostPackageName 宿主应用的包名
* @return 宿主应用名称(读取失败返回 "未知应用"
*/ */
private static String getHostAppName(Context hostContext, String hostPackageName) { public static void release(final Context hostContext) {
LogUtils.d(TAG, "release 执行资源释放");
sHostPackageName = "";
sCrashLogCacheFilePath = "";
}
// ====================== 内部工具方法 ======================
/**
* 获取宿主应用名称
* @param hostContext 宿主上下文
* @param hostPackageName 宿主包名
* @return 应用名称,失败返回未知应用
*/
private static String getHostAppName(final Context hostContext, final String hostPackageName) {
try { try {
// 用宿主包名获取宿主应用信息,确保获取的是宿主的应用名称(类库关键改进) return hostContext.getPackageManager()
return hostContext.getPackageManager().getApplicationLabel( .getApplicationLabel(hostContext.getPackageManager()
hostContext.getPackageManager().getApplicationInfo(hostPackageName, 0) .getApplicationInfo(hostPackageName, 0)).toString();
).toString();
} catch (Exception e) { } catch (Exception e) {
LogUtils.e(TAG, "获取宿主应用名称失败(包名:" + hostPackageName + "", e); LogUtils.e(TAG, "获取宿主应用名称失败", e);
return "未知应用"; return "未知应用";
} }
} }
/** /**
* 发送崩溃通知到宿主系统通知栏(类库兼容版) * 保存崩溃日志到缓存文件
* 改进点:全程使用宿主上下文和宿主包名,避免类库包名依赖 * @param hostContext 宿主上下文
* @param hostContext 宿主应用的上下文Application 实例) * @param crashLog 崩溃日志内容
* @param hostPackageName 宿主应用的包名 * @return 缓存文件路径,失败返回空字符串
* @param hostAppName 宿主应用的名称(用于通知标题)
* @param errorLog 崩溃日志(传递给宿主的 GlobalCrashActivity
*/ */
private static void sendCrashNotification(Context hostContext, String hostPackageName, String hostAppName, String errorLog) { private static String saveCrashLogToCache(final Context hostContext, final String crashLog) {
// 1. 获取宿主的通知管理器(使用宿主上下文,确保通知归属宿主应用) if (hostContext == null || TextUtils.isEmpty(crashLog)) {
NotificationManager notificationManager = (NotificationManager) hostContext.getSystemService(Context.NOTIFICATION_SERVICE); return "";
if (notificationManager == null) {
LogUtils.e(TAG, "获取宿主 NotificationManager 失败(包名:" + hostPackageName + "");
return;
} }
BufferedReader reader = null;
// 2. 适配 Android 8.0+API 26+):创建宿主的通知渠道(归属宿主,避免类库渠道冲突) FileOutputStream fos = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { try {
createCrashNotifyChannel(hostContext, notificationManager); final File cacheDir = new File(hostContext.getCacheDir(), CRASH_LOG_CACHE_SUBDIR);
if (!cacheDir.exists()) {
cacheDir.mkdirs();
}
final File cacheFile = new File(cacheDir, CRASH_LOG_CACHE_FILENAME);
if (cacheFile.exists()) {
cacheFile.delete();
}
cacheFile.createNewFile();
fos = new FileOutputStream(cacheFile);
fos.write(crashLog.getBytes("UTF-8"));
fos.flush();
LogUtils.d(TAG, "saveCrashLogToCache 保存崩溃日志到缓存: " + cacheFile.getAbsolutePath());
return cacheFile.getAbsolutePath();
} catch (Exception e) {
LogUtils.e(TAG, "saveCrashLogToCache 异常", e);
return "";
} finally {
if (reader != null) {
try { reader.close(); } catch (Exception e) {}
}
if (fos != null) {
try { fos.close(); } catch (Exception e) {}
}
} }
// 3. 构建通知意图(核心改进:绑定宿主包名,跳转宿主的 GlobalCrashActivity
PendingIntent jumpIntent = getGlobalCrashPendingIntent(hostContext, hostPackageName, errorLog);
if (jumpIntent == null) {
LogUtils.e(TAG, "构建跳转意图失败(宿主包名:" + hostPackageName + "");
return;
}
// 4. 构建通知实例(使用宿主上下文,确保通知资源归属宿主)
Notification notification = buildNotification(hostContext, hostAppName, errorLog, jumpIntent);
// 5. 发送通知(归属宿主应用,避免类库与宿主通知混淆)
notificationManager.notify(CRASH_NOTIFY_ID, notification);
LogUtils.d(TAG, "崩溃通知发送成功(宿主包名:" + hostPackageName + ",标题:" + hostAppName + ",日志长度:" + errorLog.length() + "字符)");
} }
/** /**
* 创建宿主应用的崩溃通知渠道(类库场景:渠道归属宿主,避免类库与宿主渠道冲突) * 读取缓存的崩溃日志文件内容
* @param hostContext 宿主应用的上下文 * @param hostContext 宿主上下文
* @param notificationManager 宿主的通知管理器 * @return 日志内容,失败返回空字符串
*/ */
private static void createCrashNotifyChannel(Context hostContext, NotificationManager notificationManager) { private static String readCachedCrashLog(final Context hostContext) {
// 仅 Android 8.0+ 执行(避免低版本报错) if (hostContext == null || TextUtils.isEmpty(sCrashLogCacheFilePath)) {
return "";
}
BufferedReader reader = null;
try {
final File cacheFile = new File(sCrashLogCacheFilePath);
if (!cacheFile.exists()) {
LogUtils.w(TAG, "readCachedCrashLog 缓存文件不存在");
return "";
}
reader = new BufferedReader(new InputStreamReader(new FileInputStream(cacheFile), "UTF-8"));
final StringBuilder sb = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
sb.append(line).append("\n");
}
return sb.toString();
} catch (Exception e) {
LogUtils.e(TAG, "readCachedCrashLog 异常", e);
return "";
} finally {
if (reader != null) {
try { reader.close(); } catch (Exception e) {}
}
}
}
/**
* 发送崩溃系统通知
* @param hostContext 宿主上下文
* @param hostPackageName 宿主包名
* @param hostAppName 宿主应用名
* @param errorLog 崩溃日志
* @param reportCrashActivity 跳转Activity
* @param sharePendingIntent 分享日志PendingIntent
*/
private static void sendCrashNotification(final Context hostContext,
final String hostPackageName,
final String hostAppName,
final String errorLog,
final Class<?> reportCrashActivity,
final PendingIntent sharePendingIntent) {
final NotificationManager notificationManager =
(NotificationManager) hostContext.getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager == null) {
LogUtils.e(TAG, "获取NotificationManager失败");
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createCrashNotifyChannel(hostContext, notificationManager);
}
final PendingIntent jumpIntent = getGlobalCrashPendingIntent(hostContext,
hostPackageName, errorLog, reportCrashActivity);
if (jumpIntent == null) {
LogUtils.e(TAG, "构建跳转PendingIntent失败");
return;
}
final Notification notification = buildNotification(hostContext, hostPackageName, hostAppName, errorLog, jumpIntent, sharePendingIntent);
notificationManager.notify(CRASH_NOTIFY_ID, notification);
LogUtils.d(TAG, "崩溃通知发送成功,宿主包名:" + hostPackageName);
}
/**
* 创建分享日志PendingIntent
* @param hostContext 宿主上下文
* @param shareIntent 分享意图
* @return PendingIntent实例
*/
private static PendingIntent createSharePendingIntent(final Context hostContext, final Intent shareIntent) {
int flags = PendingIntent.FLAG_UPDATE_CURRENT;
if (Build.VERSION.SDK_INT >= API_LEVEL_ANDROID_12) {
flags |= FLAG_IMMUTABLE;
}
return PendingIntent.getActivity(
hostContext,
REQUEST_CODE_SHARE_LOG,
shareIntent,
flags
);
}
/**
* 创建通知渠道适配Android O及以上
* @param hostContext 宿主上下文
* @param notificationManager 通知管理器
*/
private static void createCrashNotifyChannel(final Context hostContext,
final NotificationManager notificationManager) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// 构建通知渠道(归属宿主应用,描述明确类库用途)
android.app.NotificationChannel channel = new android.app.NotificationChannel( android.app.NotificationChannel channel = new android.app.NotificationChannel(
CRASH_NOTIFY_CHANNEL_ID, CRASH_NOTIFY_CHANNEL_ID,
CRASH_NOTIFY_CHANNEL_NAME, CRASH_NOTIFY_CHANNEL_NAME,
NotificationManager.IMPORTANCE_DEFAULT NotificationManager.IMPORTANCE_DEFAULT
); );
channel.setDescription("应用崩溃通知(由 WinBoLL Studio 类库提供,点击查看详情)"); channel.setDescription("应用崩溃通知(由 WinBoLL Studio 类库提供,点击查看详情)");
// 注册渠道到宿主的通知管理器,确保渠道归属宿主
notificationManager.createNotificationChannel(channel); notificationManager.createNotificationChannel(channel);
LogUtils.d(TAG, "宿主崩溃通知渠道创建成功(宿主包名:" + hostContext.getPackageName() + "渠道ID" + CRASH_NOTIFY_CHANNEL_ID + ""); LogUtils.d(TAG, "通知渠道创建");
} }
} }
/** /**
* 核心改进:构建跳转宿主 GlobalCrashActivity 的意图(类库关键) * 构建跳转崩溃详情页PendingIntent
* 1. 绑定宿主包名,确保类库能正确启动宿主的 Activity * @param hostContext 宿主上下文
* 2. 传递崩溃日志,与宿主 GlobalCrashActivity 日志接收逻辑匹配; * @param hostPackageName 宿主包名
* 3. 使用宿主上下文,避免类库上下文导致的适配问题。 * @param errorLog 崩溃日志
* @param hostContext 宿主应用的上下文 * @param reportCrashActivity 目标Activity
* @param hostPackageName 宿主应用的包名 * @return PendingIntent实例
* @param errorLog 崩溃日志(传递给宿主的 GlobalCrashActivity
* @return 跳转崩溃详情页的 PendingIntent
*/ */
private static PendingIntent getGlobalCrashPendingIntent(Context hostContext, String hostPackageName, String errorLog) { private static PendingIntent getGlobalCrashPendingIntent(final Context hostContext,
final String hostPackageName,
final String errorLog,
final Class<?> reportCrashActivity) {
try { try {
// 1. 构建跳转宿主 GlobalCrashActivity 的显式意图(类库场景必须显式指定宿主包名) final Intent crashIntent = new Intent(hostContext, reportCrashActivity);
Intent crashIntent = new Intent(hostContext, GlobalCrashActivity.class);
// 关键:绑定宿主包名,确保意图能正确匹配宿主的 Activity避免类库包名干扰
crashIntent.setPackage(hostPackageName); crashIntent.setPackage(hostPackageName);
// 传递崩溃日志EXTRA_CRASH_INFO与宿主 GlobalCrashActivity 完全匹配)
crashIntent.putExtra(CrashHandler.EXTRA_CRASH_LOG, errorLog); crashIntent.putExtra(CrashHandler.EXTRA_CRASH_LOG, errorLog);
// 设置意图标志:确保在宿主应用中正常启动,避免重复创建和任务栈混乱
crashIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); crashIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
// 2. 构建 PendingIntent使用宿主上下文适配高版本
int flags = PendingIntent.FLAG_UPDATE_CURRENT; int flags = PendingIntent.FLAG_UPDATE_CURRENT;
if (Build.VERSION.SDK_INT >= API_LEVEL_ANDROID_12) { if (Build.VERSION.SDK_INT >= API_LEVEL_ANDROID_12) {
flags |= FLAG_IMMUTABLE; flags |= FLAG_IMMUTABLE;
} }
return PendingIntent.getActivity( return PendingIntent.getActivity(
hostContext, hostContext,
CRASH_NOTIFY_ID, // 用通知ID作为请求码确保唯一避免意图复用 CRASH_NOTIFY_ID,
crashIntent, crashIntent,
flags flags
); );
} catch (Exception e) { } catch (Exception e) {
LogUtils.e(TAG, "构建跳转意图失败(宿主包名:" + hostPackageName + "", e); LogUtils.e(TAG, "构建跳转Intent异常", e);
return null; return null;
} }
} }
/** /**
* 构建通知实例(类库兼容版) * 构建Notification通知实例
* 改进点:使用宿主上下文加载资源,确保通知样式适配宿主应用 * @param hostContext 宿主上下文
* @param hostContext 宿主应用的上下文 * @param hostPackageName 宿主包名
* @param hostAppName 宿主应用的名称(通知标题) * @param hostAppName 宿主应用
* @param errorLog 崩溃日志(通知内容) * @param errorLog 崩溃日志
* @param jumpIntent 通知点击跳转意图(跳转宿主的 GlobalCrashActivity * @param jumpIntent 点击跳转意图
* @return 构建完成的 Notification 对象 * @param shareIntent 分享日志意图
* @return 构建好的Notification
*/ */
private static Notification buildNotification(Context hostContext, String hostAppName, String errorLog, PendingIntent jumpIntent) { @SuppressWarnings("deprecation")
// 兼容 Android 8.0+指定宿主的通知渠道ID private static Notification buildNotification(final Context hostContext,
final String hostPackageName,
final String hostAppName,
final String errorLog,
final PendingIntent jumpIntent,
final PendingIntent shareIntent) {
Notification.Builder builder = new Notification.Builder(hostContext); Notification.Builder builder = new Notification.Builder(hostContext);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
builder.setChannelId(CRASH_NOTIFY_CHANNEL_ID); builder.setChannelId(CRASH_NOTIFY_CHANNEL_ID);
} }
final String briefInfo = extractBriefInfo(errorLog);
// 核心用BigTextStyle控制“默认3行省略下拉显示完整”使用宿主上下文构建 final Notification.BigTextStyle bigTextStyle = new Notification.BigTextStyle();
Notification.BigTextStyle bigTextStyle = new Notification.BigTextStyle(); bigTextStyle.setBigContentTitle(hostAppName + " 崩溃");
bigTextStyle.setSummaryText("日志已省略,下拉查看完整内容"); bigTextStyle.bigText(briefInfo);
bigTextStyle.bigText(errorLog); bigTextStyle.setSummaryText("点击查看详情");
bigTextStyle.setBigContentTitle(hostAppName + " 崩溃"); // 标题明确标识宿主和崩溃状态
builder.setStyle(bigTextStyle); builder.setStyle(bigTextStyle);
builder.setSmallIcon(hostContext.getApplicationInfo().icon)
// 配置通知核心参数(全程使用宿主上下文,确保资源归属宿主)
builder
// 关键:使用宿主应用的小图标(避免类库图标显示异常)
.setSmallIcon(hostContext.getApplicationInfo().icon)
.setContentTitle(hostAppName + " 崩溃") .setContentTitle(hostAppName + " 崩溃")
.setContentText(getShortContent(errorLog)) // 3行内缩略文本 .setContentText(briefInfo.split("\n")[0])
.setContentIntent(jumpIntent) // 点击跳转宿主的 GlobalCrashActivity .setContentIntent(jumpIntent)
.setAutoCancel(true) // 点击后自动关闭 .setAutoCancel(true)
.setWhen(System.currentTimeMillis()) .setWhen(System.currentTimeMillis())
.setPriority(Notification.PRIORITY_DEFAULT); .setPriority(Notification.PRIORITY_DEFAULT);
if (shareIntent != null) {
// 适配 Android 4.1+:确保在宿主应用中正常显示 builder.addAction(android.R.drawable.ic_menu_send, "分享日志", shareIntent);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
return builder.build(); return builder.build();
} else { } else {
@@ -242,23 +365,79 @@ public class CrashHandleNotifyUtils {
} }
/** /**
* 辅助方法截取日志文本确保显示在3行内通用逻辑无包名依赖 * 截取缩略日志文本
* @param content 完整崩溃日志 * @param content 原始日志
* @return 3行内的缩略文 * @return 缩略文
*/ */
private static String getShortContent(String content) { private static String getShortContent(final String errorLog) {
if (content == null || content.isEmpty()) { if (errorLog == null || errorLog.isEmpty()) {
return "无崩溃日志"; return "无崩溃日志";
} }
int maxLength = 80; // 估算3行字符数可根据需求调整 final String brief = extractBriefInfo(errorLog);
return content.length() <= maxLength ? content : content.substring(0, maxLength) + "..."; final String firstLine = brief.split("\n")[0];
if (firstLine.length() > 80) {
return firstLine.substring(0, 80) + "...";
}
return firstLine;
} }
/** /**
* 释放资源(类库场景:空实现,避免宿主调用时报错,预留扩展) * 使用正则表达式从崩溃日志中提取简要信息
* @param hostContext 宿主应用的上下文(显式传入,避免类库上下文依赖) * @param crashLog 完整崩溃日志
* @return 简要崩溃信息
*/ */
public static void release(Context hostContext) { private static String extractBriefInfo(final String crashLog) {
LogUtils.d(TAG, "CrashHandleNotifyUtils 资源释放完成(宿主包名:" + (hostContext != null ? hostContext.getPackageName() : "未知") + ""); if (crashLog == null || crashLog.isEmpty()) {
return "无崩溃日志";
}
final StringBuilder brief = new StringBuilder();
try {
java.util.regex.Pattern exceptionPattern = java.util.regex.Pattern.compile(REGEX_EXCEPTION_TYPE);
java.util.regex.Matcher exceptionMatcher = exceptionPattern.matcher(crashLog);
if (exceptionMatcher.find()) {
brief.append(exceptionMatcher.group(1));
}
java.util.regex.Pattern messagePattern = java.util.regex.Pattern.compile(REGEX_EXCEPTION_MESSAGE);
java.util.regex.Matcher messageMatcher = messagePattern.matcher(crashLog);
if (messageMatcher.find()) {
String message = messageMatcher.group(1).trim();
if (message.length() > 100) {
message = message.substring(0, 100) + "...";
}
if (brief.length() > 0) {
brief.append(" - ");
}
brief.append(message);
}
java.util.regex.Pattern causePattern = java.util.regex.Pattern.compile(REGEX_CAUSE);
java.util.regex.Matcher causeMatcher = causePattern.matcher(crashLog);
if (causeMatcher.find()) {
if (brief.length() > 0) {
brief.append("\n");
}
brief.append("原因: ").append(causeMatcher.group(1));
}
java.util.regex.Pattern stackPattern = java.util.regex.Pattern.compile(REGEX_STACK_TRACE);
java.util.regex.Matcher stackMatcher = stackPattern.matcher(crashLog);
int lineCount = 0;
while (stackMatcher.find() && lineCount < 3) {
if (brief.length() > 0) {
brief.append("\n");
}
brief.append(" at ").append(stackMatcher.group(1)).append(".")
.append(stackMatcher.group(2)).append("(")
.append(stackMatcher.group(3)).append(":")
.append(stackMatcher.group(4)).append(")");
lineCount++;
}
if (brief.length() == 0) {
brief.append(crashLog.length() > SUMMARY_MAX_LENGTH ? crashLog.substring(0, SUMMARY_MAX_LENGTH) + "..." : crashLog);
}
} catch (Exception e) {
LogUtils.e(TAG, "提取崩溃简要信息失败", e);
brief.setLength(0);
brief.append(crashLog.length() > SUMMARY_MAX_LENGTH ? crashLog.substring(0, SUMMARY_MAX_LENGTH) + "..." : crashLog);
}
return brief.toString();
} }
} }

View File

@@ -0,0 +1,91 @@
package cc.winboll.studio.libappbase.utils;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
/**
* 分享崩溃日志窗口类
* @Author ZhanGSKen<zhangsken@qq.com>
* @CreateTime 2026/05/11 22:30:00
*/
public class ShareLogActivity extends Activity {
public static final String TAG = "ShareLogActivity";
public static final String EXTRA_CRASH_LOG_FILEPATH = "crash_log_filepath";
public static final String EXTRA_CRASH_LOG_SUBJECT = "crash_log_subject";
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, "onCreate 进入方法");
final Intent intent = getIntent();
if (intent == null) {
Log.e(TAG, "onCreate intent 为空");
finish();
return;
}
final String crashLogFilePath = intent.getStringExtra(EXTRA_CRASH_LOG_FILEPATH);
if (crashLogFilePath == null || crashLogFilePath.isEmpty()) {
Log.e(TAG, "onCreate crashLogFilePath 为空");
Toast.makeText(this, "日志文件路径无效", Toast.LENGTH_SHORT).show();
finish();
return;
}
final String subject = intent.getStringExtra(EXTRA_CRASH_LOG_SUBJECT);
handleShareCrashLog(crashLogFilePath, subject);
}
private void handleShareCrashLog(final String crashLogFilePath, final String subject) {
Log.d(TAG, "handleShareCrashLog crashLogFilePath = " + crashLogFilePath);
final File crashLogFile = new File(crashLogFilePath);
if (!crashLogFile.exists()) {
Log.e(TAG, "handleShareCrashLog 文件不存在");
Toast.makeText(this, "日志文件不存在", Toast.LENGTH_SHORT).show();
finish();
return;
}
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(new FileInputStream(crashLogFile), "UTF-8"));
final StringBuilder sb = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
sb.append(line).append("\n");
}
final String logContent = sb.toString();
final Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, logContent);
if (subject != null && !subject.isEmpty()) {
shareIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
} else {
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "崩溃日志");
}
startActivity(Intent.createChooser(shareIntent, "分享日志到"));
Log.d(TAG, "handleShareCrashLog 分享成功");
} catch (Exception e) {
Log.e(TAG, "handleShareCrashLog 异常", e);
Toast.makeText(this, "分享失败: " + e.getMessage(), Toast.LENGTH_SHORT).show();
} finally {
if (reader != null) {
try { reader.close(); } catch (Exception e) {}
}
finish();
}
}
}

View File

@@ -3,6 +3,7 @@ package cc.winboll.studio.libappbase.widget;
import android.content.Context; import android.content.Context;
import android.graphics.Color; import android.graphics.Color;
import android.text.TextUtils; import android.text.TextUtils;
import android.content.res.TypedArray;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.View; import android.view.View;
@@ -153,9 +154,12 @@ public class LogTagSpinner extends Spinner {
itemTv.setPadding(mTextPadding, 0, mTextPadding, 0); itemTv.setPadding(mTextPadding, 0, mTextPadding, 0);
// 4. 文字对齐(垂直居中+靠左,符合常规 UI 设计) // 4. 文字对齐(垂直居中+靠左,符合常规 UI 设计)
//itemTv.setGravity(View.GRAVITY_CENTER_VERTICAL | View.GRAVITY_START); //itemTv.setGravity(View.GRAVITY_CENTER_VERTICAL | View.GRAVITY_START);
// 5. 文字颜色(统一深色,可改为项目颜色资源 // 5. 文字颜色(使用主题属性 ?attr/toolbarTextColor
itemTv.setTextColor(this.mContext.getColor(R.color.white)); TypedArray ta = mContext.obtainStyledAttributes(new int[] { R.attr.toolbarTextColor });
itemTv.setBackgroundColor(this.mContext.getColor(R.color.btn_gray_normal)); int toolbarTextColor = ta.getColor(0, mContext.getResources().getColor(R.color.white));
ta.recycle();
itemTv.setTextColor(toolbarTextColor);
itemTv.setBackgroundColor(this.mContext.getResources().getColor(R.color.btn_gray_normal));
// 6. 文字溢出处理(最多 2 行,超出省略,避免长标签换行过多) // 6. 文字溢出处理(最多 2 行,超出省略,避免长标签换行过多)
itemTv.setSingleLine(false); itemTv.setSingleLine(false);
itemTv.setMaxLines(2); itemTv.setMaxLines(2);

View File

@@ -50,8 +50,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="功能按钮待激活" android:text="功能按钮待激活"
android:textSize="16sp" android:textSize="16sp"
android:textColor="?attr/buttonTextColor" android:textColor="?attr/toolbarTextColor"
android:backgroundTint="?attr/buttonBackgroundColor" android:backgroundTint="?attr/toolbarBackgroundColor"
android:padding="14dp" android:padding="14dp"
android:enabled="false"/> android:enabled="false"/>

View File

@@ -53,8 +53,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="确认" android:text="确认"
android:textSize="14sp" android:textSize="14sp"
android:backgroundTint="?attr/buttonBackgroundColor" android:backgroundTint="?attr/toolbarBackgroundColor"
android:textColor="?attr/buttonTextColor"/> android:textColor="?attr/toolbarTextColor"/>
</LinearLayout> </LinearLayout>

View File

@@ -18,6 +18,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
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/toolbarTextColor"
android:id="@+id/viewlogtagCheckBox1"/> android:id="@+id/viewlogtagCheckBox1"/>
</LinearLayout> </LinearLayout>

View File

@@ -15,13 +15,13 @@
android:background="?attr/colorTittleBackgound" android:background="?attr/colorTittleBackgound"
android:id="@+id/viewlogRelativeLayoutToolbar"> android:id="@+id/viewlogRelativeLayoutToolbar">
<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:text="Clean" android:text="Clean"
android:textColor="?attr/colorText" android:textColor="?attr/activityTextColor"
android:backgroundTint="?attr/colorTittleBackgound" android:background="?attr/toolbarBackgroundColor"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:id="@+id/viewlogButtonClean" android:id="@+id/viewlogButtonClean"
android:layout_marginLeft="5dp"/> android:layout_marginLeft="5dp"/>
@@ -36,7 +36,7 @@
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:id="@+id/viewlogTextView1" android:id="@+id/viewlogTextView1"
android:background="?attr/colorTittleBackgound" android:background="?attr/colorTittleBackgound"
android:textColor="?attr/colorText"/> android:textColor="?attr/toolbarTextColor"/>
<cc.winboll.studio.libappbase.widget.LogTagSpinner <cc.winboll.studio.libappbase.widget.LogTagSpinner
android:layout_width="wrap_content" android:layout_width="wrap_content"
@@ -56,14 +56,14 @@
android:background="?attr/colorTittleBackgound" 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/colorText"/> android:textColor="?attr/toolbarTextColor"/>
<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/colorText" android:textColor="?attr/activityTextColor"
android:backgroundTint="?attr/colorTittleBackgound" android:background="?attr/toolbarBackgroundColor"
android:text="Copy" android:text="Copy"
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:layout_centerVertical="true" android:layout_centerVertical="true"
@@ -89,7 +89,7 @@
android:padding="2dp" android:padding="2dp"
android:id="@+id/viewlogCheckBox1" android:id="@+id/viewlogCheckBox1"
android:background="?attr/colorTittleBackgound" android:background="?attr/colorTittleBackgound"
android:textColor="?attr/colorText" android:textColor="?attr/toolbarTextColor"
android:layout_marginLeft="5dp" android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"/> android:layout_marginRight="5dp"/>

View File

@@ -2,10 +2,10 @@
<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: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

@@ -50,8 +50,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="功能按钮待激活" android:text="功能按钮待激活"
android:textSize="16sp" android:textSize="16sp"
android:textColor="?attr/buttonTextColor" android:textColor="?attr/toolbarTextColor"
android:backgroundTint="?attr/buttonBackgroundColor" android:backgroundTint="?attr/toolbarBackgroundColor"
android:padding="14dp" android:padding="14dp"
android:enabled="false"/> android:enabled="false"/>

View File

@@ -53,8 +53,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="确认" android:text="确认"
android:textSize="14sp" android:textSize="14sp"
android:backgroundTint="?attr/buttonBackgroundColor" android:backgroundTint="?attr/toolbarBackgroundColor"
android:textColor="?attr/buttonTextColor"/> android:textColor="?attr/toolbarTextColor"/>
</LinearLayout> </LinearLayout>

View File

@@ -18,6 +18,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
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/toolbarTextColor"
android:id="@+id/viewlogtagCheckBox1"/> android:id="@+id/viewlogtagCheckBox1"/>
</LinearLayout> </LinearLayout>

View File

@@ -0,0 +1,27 @@
<?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="12dp">
<TextView
android:id="@+id/notification_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#333333"
android:singleLine="true"
android:ellipsize="end" />
<TextView
android:id="@+id/notification_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:textSize="14sp"
android:textColor="#666666"
android:minHeight="200dp" />
</LinearLayout>

View File

@@ -0,0 +1,27 @@
<?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="12dp">
<TextView
android:id="@+id/notification_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#333333"
android:singleLine="true"
android:ellipsize="end" />
<TextView
android:id="@+id/notification_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:textSize="13sp"
android:textColor="#666666"
android:scrollbars="vertical" />
</LinearLayout>

View File

@@ -20,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/colorText" android:textColor="?attr/activityTextColor"
android:backgroundTint="?attr/colorTittleBackgound" android:background="?attr/toolbarBackgroundColor"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:id="@+id/viewlogButtonClean" android:id="@+id/viewlogButtonClean"
android:layout_marginLeft="5dp"/> android:layout_marginLeft="5dp"/>
@@ -36,7 +36,7 @@
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:id="@+id/viewlogTextView1" android:id="@+id/viewlogTextView1"
android:background="?attr/colorTittleBackgound" android:background="?attr/colorTittleBackgound"
android:textColor="?attr/colorText"/> android:textColor="?attr/toolbarTextColor"/>
<cc.winboll.studio.libappbase.widget.LogTagSpinner <cc.winboll.studio.libappbase.widget.LogTagSpinner
android:layout_width="wrap_content" android:layout_width="wrap_content"
@@ -56,14 +56,14 @@
android:background="?attr/colorTittleBackgound" 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/colorText"/> android:textColor="?attr/toolbarTextColor"/>
<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/colorText" android:textColor="?attr/activityTextColor"
android:backgroundTint="?attr/colorTittleBackgound" android:background="?attr/toolbarBackgroundColor"
android:text="Copy" android:text="Copy"
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:layout_centerVertical="true" android:layout_centerVertical="true"
@@ -89,7 +89,7 @@
android:padding="2dp" android:padding="2dp"
android:id="@+id/viewlogCheckBox1" android:id="@+id/viewlogCheckBox1"
android:background="?attr/colorTittleBackgound" android:background="?attr/colorTittleBackgound"
android:textColor="?attr/colorText" android:textColor="?attr/toolbarTextColor"
android:layout_marginLeft="5dp" android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"/> android:layout_marginRight="5dp"/>

View File

@@ -20,11 +20,7 @@
<attr name="aboutViewDividerColor" format="color" /> <attr name="aboutViewDividerColor" format="color" />
</declare-styleable> </declare-styleable>
<!-- ButtonStyle 样式属性 -->
<declare-styleable name="ButtonStyle">
<attr name="buttonBackgroundColor" format="color" />
<attr name="buttonTextColor" format="color" />
</declare-styleable>
<!-- DialogStyle 样式属性 --> <!-- DialogStyle 样式属性 -->
<declare-styleable name="DialogStyle"> <declare-styleable name="DialogStyle">

View File

@@ -63,7 +63,9 @@
<!-- ============== 主题颜色 ============== --> <!-- ============== 主题颜色 ============== -->
<color name="mainWindowBackgroundColor">#FF0D1B2A</color> <color name="mainWindowBackgroundColor">#FF0D1B2A</color>
<color name="mainWindowTextColor">#FFE0E0E0</color> <color name="mainWindowTextColor">#FFE0E0E0</color>
<color name="buttonBackgroundColor">#FF1E3A5F</color> <color name="toolbarTextColor">#FFE0E0E0</color>
<color name="toolbarBackgroundColor">#FF1E3A5F</color>
<color name="debugTextColor">#FF00FF00</color> <color name="debugTextColor">#FF00FF00</color>
</resources> </resources>

View File

@@ -8,12 +8,12 @@
<item name="aboutViewTextColor">?attr/mainWindowDarkTextColor</item> <item name="aboutViewTextColor">?attr/mainWindowDarkTextColor</item>
<item name="aboutViewTitleColor">?attr/mainWindowDarkTextColor</item> <item name="aboutViewTitleColor">?attr/mainWindowDarkTextColor</item>
<item name="aboutViewDividerColor">?attr/mainWindowTextColor</item> <item name="aboutViewDividerColor">?attr/mainWindowTextColor</item>
<item name="buttonBackgroundColor">@color/buttonBackgroundColor</item>
<item name="buttonTextColor">?attr/mainWindowDarkTextColor</item>
<item name="dialogBackgroundColor">?attr/mainWindowDarkBackgroundColor</item> <item name="dialogBackgroundColor">?attr/mainWindowDarkBackgroundColor</item>
<item name="dialogTextColor">?attr/mainWindowDarkTextColor</item> <item name="dialogTextColor">?attr/mainWindowDarkTextColor</item>
<item name="toolbarBackgroundColor">?attr/buttonBackgroundColor</item> <item name="toolbarBackgroundColor">@color/toolbarBackgroundColor</item>
<item name="toolbarTextColor">?attr/mainWindowDarkTextColor</item> <item name="toolbarTextColor">@color/toolbarTextColor</item>
<item name="textViewBackgroundColor">?attr/mainWindowDarkBackgroundColor</item> <item name="textViewBackgroundColor">?attr/mainWindowDarkBackgroundColor</item>
<item name="textViewTextColor">?attr/mainWindowDarkTextColor</item> <item name="textViewTextColor">?attr/mainWindowDarkTextColor</item>
<item name="editTextBackgroundColor">?attr/mainWindowDarkBackgroundColor</item> <item name="editTextBackgroundColor">?attr/mainWindowDarkBackgroundColor</item>
@@ -29,12 +29,14 @@
<!-- DebugActivityTheme 深色模式样式 --> <!-- DebugActivityTheme 深色模式样式 -->
<style name="DebugActivityTheme" parent="@android:style/Theme.DeviceDefault.NoActionBar"> <style name="DebugActivityTheme" parent="@android:style/Theme.DeviceDefault.NoActionBar">
<item name="android:statusBarColor">@color/mainWindowBackgroundColor</item> <item name="android:statusBarColor">@color/toolbarBackgroundColor</item>
<item name="colorTittle">?attr/mainWindowDarkTextColor</item> <item name="colorTittle">?attr/mainWindowDarkTextColor</item>
<item name="colorTittleBackgound">@color/buttonBackgroundColor</item> <item name="colorTittleBackgound">@color/toolbarBackgroundColor</item>
<item name="colorText">?attr/debugTextColor</item> <item name="colorText">?attr/debugTextColor</item>
<item name="colorTextBackgound">?attr/mainWindowDarkBackgroundColor</item> <item name="colorTextBackgound">?attr/mainWindowDarkBackgroundColor</item>
<item name="debugTextColor">@color/debugTextColor</item> <item name="debugTextColor">@color/debugTextColor</item>
<item name="toolbarTextColor">@color/toolbarTextColor</item>
</style> </style>
<!-- DialogStyle 对话框样式 --> <!-- DialogStyle 对话框样式 -->

View File

@@ -26,11 +26,7 @@
<attr name="aboutViewDividerColor" format="color" /> <attr name="aboutViewDividerColor" format="color" />
</declare-styleable> </declare-styleable>
<!-- ButtonStyle 样式属性 -->
<declare-styleable name="ButtonStyle">
<attr name="buttonBackgroundColor" format="color" />
<attr name="buttonTextColor" format="color" />
</declare-styleable>
<!-- DialogStyle 样式属性 --> <!-- DialogStyle 样式属性 -->
<declare-styleable name="DialogStyle"> <declare-styleable name="DialogStyle">

View File

@@ -63,7 +63,9 @@
<!-- ============== 主题颜色 ============== --> <!-- ============== 主题颜色 ============== -->
<color name="mainWindowBackgroundColor">#FFF5F5F5</color> <color name="mainWindowBackgroundColor">#FFF5F5F5</color>
<color name="mainWindowTextColor">#FF000000</color> <color name="mainWindowTextColor">#FF000000</color>
<color name="buttonBackgroundColor">#FF00B322</color> <color name="toolbarTextColor">#FF000000</color>
<color name="toolbarBackgroundColor">#FF00B322</color>
<color name="debugTextColor">#FF808080</color> <color name="debugTextColor">#FF808080</color>
</resources> </resources>

View File

@@ -8,12 +8,12 @@
<item name="aboutViewTextColor">?attr/mainWindowTextColor</item> <item name="aboutViewTextColor">?attr/mainWindowTextColor</item>
<item name="aboutViewTitleColor">?attr/mainWindowTextColor</item> <item name="aboutViewTitleColor">?attr/mainWindowTextColor</item>
<item name="aboutViewDividerColor">?attr/mainWindowDarkTextColor</item> <item name="aboutViewDividerColor">?attr/mainWindowDarkTextColor</item>
<item name="buttonBackgroundColor">@color/buttonBackgroundColor</item>
<item name="buttonTextColor">?attr/mainWindowTextColor</item>
<item name="dialogBackgroundColor">?attr/mainWindowBackgroundColor</item> <item name="dialogBackgroundColor">?attr/mainWindowBackgroundColor</item>
<item name="dialogTextColor">?attr/mainWindowTextColor</item> <item name="dialogTextColor">?attr/mainWindowTextColor</item>
<item name="toolbarBackgroundColor">?attr/buttonBackgroundColor</item> <item name="toolbarBackgroundColor">@color/toolbarBackgroundColor</item>
<item name="toolbarTextColor">?attr/mainWindowTextColor</item> <item name="toolbarTextColor">@color/toolbarTextColor</item>
<item name="textViewBackgroundColor">?attr/mainWindowBackgroundColor</item> <item name="textViewBackgroundColor">?attr/mainWindowBackgroundColor</item>
<item name="textViewTextColor">?attr/mainWindowTextColor</item> <item name="textViewTextColor">?attr/mainWindowTextColor</item>
<item name="editTextBackgroundColor">?attr/mainWindowBackgroundColor</item> <item name="editTextBackgroundColor">?attr/mainWindowBackgroundColor</item>
@@ -29,12 +29,14 @@
<!-- DebugActivityTheme 普通模式样式 --> <!-- DebugActivityTheme 普通模式样式 -->
<style name="DebugActivityTheme" parent="@android:style/Theme.DeviceDefault.Light.NoActionBar"> <style name="DebugActivityTheme" parent="@android:style/Theme.DeviceDefault.Light.NoActionBar">
<item name="android:statusBarColor">@color/buttonBackgroundColor</item> <item name="android:statusBarColor">@color/toolbarBackgroundColor</item>
<item name="colorTittle">?attr/mainWindowTextColor</item> <item name="colorTittle">?attr/mainWindowTextColor</item>
<item name="colorTittleBackgound">@color/buttonBackgroundColor</item> <item name="colorTittleBackgound">@color/toolbarBackgroundColor</item>
<item name="colorText">?attr/debugTextColor</item> <item name="colorText">?attr/debugTextColor</item>
<item name="colorTextBackgound">?attr/mainWindowBackgroundColor</item> <item name="colorTextBackgound">?attr/mainWindowBackgroundColor</item>
<item name="debugTextColor">@color/debugTextColor</item> <item name="debugTextColor">@color/debugTextColor</item>
<item name="toolbarTextColor">@color/toolbarTextColor</item>
</style> </style>
<!-- DialogStyle 对话框样式 --> <!-- DialogStyle 对话框样式 -->

View File

@@ -31,8 +31,8 @@ dependencies {
api 'com.jcraft:jsch:0.1.54' api 'com.jcraft:jsch:0.1.54'
// WinBoLL库 nexus.winboll.cc 地址 // WinBoLL库 nexus.winboll.cc 地址
api 'cc.winboll.studio:libaes:15.15.2' api 'cc.winboll.studio:libaes:15.20.2'
api 'cc.winboll.studio:libappbase:15.15.11' api 'cc.winboll.studio:libappbase:15.20.9'
api fileTree(dir: 'libs', include: ['*.jar']) api fileTree(dir: 'libs', include: ['*.jar'])
} }

View File

@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle #Created by .winboll/winboll_app_build.gradle
#Sat May 09 19:01:46 GMT 2026 #Tue May 12 12:16:45 HKT 2026
stageCount=27 stageCount=1
libraryProject=libwinboll libraryProject=libwinboll
baseVersion=15.11 baseVersion=15.20
publishVersion=15.11.26 publishVersion=15.20.0
buildCount=29 buildCount=0
baseBetaVersion=15.11.27 baseBetaVersion=15.20.1

View File

@@ -31,7 +31,7 @@ android {
// versionName 更新后需要手动设置 // versionName 更新后需要手动设置
// .winboll/winbollBuildProps.properties 文件的 stageCount=0 // .winboll/winbollBuildProps.properties 文件的 stageCount=0
// Gradle编译环境下合起来的 versionName 就是 "${versionName}.0" // Gradle编译环境下合起来的 versionName 就是 "${versionName}.0"
versionName "15.11" versionName "15.20"
if(true) { if(true) {
versionName = genVersionName("${versionName}") versionName = genVersionName("${versionName}")
} }
@@ -109,8 +109,8 @@ dependencies {
implementation 'com.termux:termux-shared:0.118.0' implementation 'com.termux:termux-shared:0.118.0'
// WinBoLL库 nexus.winboll.cc 地址 // WinBoLL库 nexus.winboll.cc 地址
api 'cc.winboll.studio:libaes:15.15.2' api 'cc.winboll.studio:libaes:15.20.2'
api 'cc.winboll.studio:libappbase:15.15.11' api 'cc.winboll.studio:libappbase:15.20.9'
// WinBoLL备用库 jitpack.io 地址 // WinBoLL备用库 jitpack.io 地址
//api 'com.github.ZhanGSKen:AES:aes-v15.15.7' //api 'com.github.ZhanGSKen:AES:aes-v15.15.7'

View File

@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle #Created by .winboll/winboll_app_build.gradle
#Sat May 09 19:01:46 GMT 2026 #Tue May 12 12:16:45 HKT 2026
stageCount=27 stageCount=1
libraryProject=libwinboll libraryProject=libwinboll
baseVersion=15.11 baseVersion=15.20
publishVersion=15.11.26 publishVersion=15.20.0
buildCount=29 buildCount=0
baseBetaVersion=15.11.27 baseBetaVersion=15.20.1

View File

@@ -4,4 +4,10 @@
<color name="colorPrimaryDark">#00796B</color> <color name="colorPrimaryDark">#00796B</color>
<color name="colorAccent">#FF9800</color> <color name="colorAccent">#FF9800</color>
<color name="pattern_lock_black">#000000</color> <color name="pattern_lock_black">#000000</color>
<color name="mainWindowBackgroundColor">#FFF5F5F5</color>
<color name="mainWindowTextColor">#FF000000</color>
<color name="toolbarTextColor">#FF000000</color>
<color name="toolbarBackgroundColor">#FF00B322</color>
<color name="debugTextColor">#FF808080</color>
</resources> </resources>

View File

@@ -1,5 +1,35 @@
<resources> <resources>
<style name="MyAppTheme" parent="AESTheme"> <style name="MyAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="themeDebug">@style/MyDebugActivityTheme</item>
<item name="aboutViewBackgroundColor">@color/mainWindowBackgroundColor</item>
<item name="aboutViewTextColor">@color/mainWindowTextColor</item>
<item name="aboutViewTitleColor">@color/mainWindowTextColor</item>
<item name="aboutViewDividerColor">@color/mainWindowTextColor</item>
<item name="dialogBackgroundColor">@color/mainWindowBackgroundColor</item>
<item name="dialogTextColor">@color/mainWindowTextColor</item>
<item name="toolbarBackgroundColor">@color/toolbarBackgroundColor</item>
<item name="toolbarTextColor">@color/toolbarTextColor</item>
<item name="textViewBackgroundColor">@color/mainWindowBackgroundColor</item>
<item name="textViewTextColor">@color/mainWindowTextColor</item>
<item name="editTextBackgroundColor">@color/mainWindowBackgroundColor</item>
<item name="editTextTextColor">@color/mainWindowTextColor</item>
<item name="scrollViewBackgroundColor">@color/mainWindowBackgroundColor</item>
<item name="activityBackgroundColor">@color/mainWindowBackgroundColor</item>
<item name="activityTextColor">@color/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>
<item name="android:statusBarColor">@color/toolbarBackgroundColor</item>
</style> </style>
<style name="MyDebugActivityTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:statusBarColor">@color/toolbarBackgroundColor</item>
<item name="colorTittle">@color/mainWindowTextColor</item>
<item name="colorTittleBackgound">@color/toolbarBackgroundColor</item>
<item name="colorText">@color/debugTextColor</item>
<item name="colorTextBackgound">@color/mainWindowBackgroundColor</item>
<item name="debugTextColor">@color/debugTextColor</item>
<item name="toolbarTextColor">@color/toolbarTextColor</item>
</style>
</resources> </resources>