Compare commits

..

19 Commits

Author SHA1 Message Date
c6e9d3ff7e 恢复winboll项目文件为当前origin/winboll分支最新提交版 2026-05-13 15:00:58 +08:00
b017f84449 恢复appbase项目文件为当前origin/appbase分支最新提交版 2026-05-13 14:56:15 +08:00
899673cec4 <mymessagemanager>APK 15.12.11 release Publish. 2026-05-09 14:21:58 +08:00
f544ecb283 fix: AboutActivity引入错误的AboutView/APPInfo类导致崩溃
将 import 从 cc.winboll.studio.libaes 修正为
cc.winboll.studio.libappbase,与布局文件保持一致,
修复打开应用介绍窗口时的 ClassCastException。
2026-05-09 14:16:54 +08:00
862157309b 更新应用介绍窗口资源 2026-05-09 14:03:46 +08:00
dc97f43a72 <mymessagemanager>APK 15.12.10 release Publish. 2026-05-09 13:46:04 +08:00
222538d259 fix: SMSView/TTSRuleView 圆角统一为全局属性,修复 CardView 裁剪边框
SMSView/TTSRuleView 的 cardCornerRadius 统一为全局配置:
  - 5 个布局文件 app:cardCornerRadius="12dp" → "?attr/borderCornerRadius"
    (listview_sms / listview_smsrecycle / listview_ttsplayrule
     listview_ttsplayrule_simple / view_smssend)

修复 CardView 裁剪内部 bg_container_border 圆角描边:
  - view_smssend.xml:SMSView(CardView)添加 android:padding="2dp"
    使内部 LinearLayout 的 bg_container_border 描边不被裁剪
  - view_smssend_part1.xml:android:padding 10dp→6dp 与圆角半径对齐
2026-05-09 13:42:39 +08:00
14f0b7c935 <mymessagemanager>APK 15.12.9 release Publish. 2026-05-09 11:16:04 +08:00
4e4673a93b feat: 容器统一加灰色边框,borderCornerRadius 属性统一管理圆角
创建通用灰色边框 drawable(5 模块各一份):
  - bg_container_border.xml:透明填充 + 1dp #B0B0B0 描边
  - 自动应用到 80 个无背景容器的布局文件

深色模式 bg_frame 加边框:
  - drawable-night/bg_frame.xml(mymessagemanager + aes):
    背景 shape 添加 1dp #666666 描边,保留渐变蒙版

统一圆角为 6dp(borderCornerRadius 属性化):
  - 5 模块 attrs.xml 声明 borderCornerRadius(dimension)
  - 12 个主题(6 普通 + 6 深色)设置 borderCornerRadius=6dp
  - 12 个 drawable 文件约 40 处 corners 改用 ?attr/borderCornerRadius
    (bg_frame / bg_frame_black/white / bg_shadow / bg_border_round
     bg_toolbar_log / acard_frame_main / atoolbar_frame / ohpcts_frame
     bg_container_border 等)
  - 3 个 Java 自定义控件(AToolbar / ASupportToolbar / AboutView)
    从硬编码 px 改为读取 ?attr/borderCornerRadius

受益布局模块:libaes / libappbase / appbase / mymessagemanager / aes / winboll
2026-05-09 10:59:55 +08:00
b385aa7030 feat: 各主题独立文本颜色,深色模式 bg_frame 去白底加渐变蒙版
主题文本颜色独立化(mymessagemanager):
  - values/colors.xml:text_color_primary 拆分为 6 个主题独立色
    default=#FF212121(暗灰)、depth=#FF1A237E(深靛蓝)
    sky=#FF01579B(深蓝)、golden=#FF3E2723(深棕)
    memor=#FF4A148C(深紫)、tao=#FF424242(深灰)
  - values/styles.xml:6 个主题分别引用各自的 text_color_primary_*

深色模式文本统一中灰色:
  - values-night/colors.xml:6 个主题统一使用 #FF999999
    与各主题 SMS 气泡色(黄/绿/蓝/紫/金/灰)明显区分
  - values-night/styles.xml:6 个主题引用各自的 text_color_primary_* 资源

深色模式 bg_frame 背景去白改蒙版:
  - drawable-night/bg_frame.xml(mymessagemanager + aes):
    第二层渐变从 #FFFFFFFF→#0FFFFFFF 改为 #1AFFFFFF→#00000000
    去除白底,保留 10% 白渐变过渡蒙版提供边框定义感
2026-05-09 10:29:56 +08:00
55c7f7d327 feat: 统一应用文本颜色由主题控制,支持深色/普通模式自适应
主题改造(mymessagemanager):
  - values/styles.xml + values-night/styles.xml:6种风格x2模式共12个主题
    统一设置 android:textColorPrimary / textColorPrimary / android:textColor / colorTextColor
    指向 @color/text_color_primary
  - values/colors.xml:text_color_primary=#FF000000(普通模式黑色)
  - values-night/colors.xml:text_color_primary=#FF00FF00(深色模式绿色)
  - attrs.xml:声明 textColorPrimary 属性解决 AAPT2 编译错误

清除硬编码文本颜色(跨模块):
  - 移除 13 个布局文件中的 android:textColor 属性(libappbase/libaes/winboll/appbase)
  - 移除 3 个 Java 文件中的 setTextColor(Color.BLACK/white/gray) 调用
  - 移除 ComposeSMSActivity / CharsetRefuseEditDialog 中的自定义文本颜色
  - 移除 toast_custom_view.xml / view_tts_back.xml 中的 android:textColor

CompoundButton 文本颜色适配:
  - ConfirmSwitchView:initView 中读取主题 textColorPrimary 的 ColorStateList 并显式设置
  - activity_appsettings.xml:平台 Switch 替换为 ConfirmSwitchView
  - fragment_main.xml:Switch 添加 textColor=?android:attr/textColorPrimary
  - 10个 RadioButton + 4个 CheckBox 添加 textColor=?android:attr/textColorPrimary
2026-05-09 10:02:44 +08:00
99de6c05ba <mymessagemanager>APK 15.12.8 release Publish. 2026-05-08 20:59:57 +08:00
4c856367f5 Merge branch 'winboll' into mymessagemanager 2026-05-08 20:50:27 +08:00
63580b111c feat: 新增SMSRecycle2Activity自由模式回收站与刻度全局同步
- 新增SMSRecycle2Activity窗口,每项使用ProtectModeTextView显示短信内容
- 顶部添加示例ProtectModeTextView,刻度值通过SP全局同步到列表所有项
- AppSettingsActivity新增回收站模式RadioGroup:简洁模式/自由模式
- MainActivity回收站菜单根据配置路由到对应Activity
- AppConfigBean新增recycleBinClass字段持久化模式选择
- ProtectModeTextView新增OnScaleChangedListener与setContentTextWithScale
2026-05-08 20:46:27 +08:00
3b60a3b713 feat: 新增ProtectModeTextView自定义控件
1. 继承LinearLayout,内置TextView与0~12刻度SeekBar
2. 刻度0保持原始文本不打乱,1~12为每组相邻字符个数
3. 按刻度固定长度从头至尾字符分组,分组列表随机打乱后拼接输出
4. 支持含空格/标点完整字符解析,对外提供setContentText设置文本接口
2026-05-08 19:35:39 +08:00
3231cd557a Merge branch 'winboll' into mymessagemanager 2026-04-09 13:16:14 +08:00
65f0515139 <mymessagemanager>APK 15.12.7 release Publish. 2026-02-11 05:29:20 +08:00
5316ac1815 设置窗口UI优化。添加TTS悬浮窗口位置调整功能。 2026-02-11 05:22:36 +08:00
6c2581276e 复制 https://gitea.winboll.cc/Studio/WinBoLL_Bck20260112_122031_590.git mymessagemanager 分支最新源码。 2026-02-11 03:13:39 +08:00
257 changed files with 15473 additions and 1284 deletions

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:left="2dp"
android:top="2dp"
android:right="2dp"
android:bottom="2dp">
<shape android:shape="rectangle" >
<gradient
android:angle="270"
android:endColor="#0F000000"
android:startColor="#0F000000" />
<corners android:radius="?attr/borderCornerRadius" />
</shape>
</item>
<item
android:left="3dp"
android:top="3dp"
android:right="3dp"
android:bottom="5dp">
<shape android:shape="rectangle" >
<gradient
android:angle="270"
android:endColor="#00000000"
android:startColor="#1AFFFFFF" />
<stroke
android:width="1dp"
android:color="#FF666666" />
<corners android:radius="?attr/borderCornerRadius" />
</shape>
</item>
</layer-list>

View File

@@ -12,11 +12,7 @@
android:angle="270" android:angle="270"
android:endColor="#0F000000" android:endColor="#0F000000"
android:startColor="#0F000000" /> android:startColor="#0F000000" />
<corners <corners android:radius="?attr/borderCornerRadius" />
android:bottomLeftRadius="6dip"
android:bottomRightRadius="6dip"
android:topLeftRadius="6dip"
android:topRightRadius="6dip" />
</shape> </shape>
</item> </item>
<!-- 背景部分 --> <!-- 背景部分 -->
@@ -31,11 +27,7 @@
android:angle="270" android:angle="270"
android:endColor="#0FFFFFFF" android:endColor="#0FFFFFFF"
android:startColor="#FFFFFFFF" /> android:startColor="#FFFFFFFF" />
<corners <corners android:radius="?attr/borderCornerRadius" />
android:bottomLeftRadius="6dip"
android:bottomRightRadius="6dip"
android:topLeftRadius="6dip"
android:topRightRadius="6dip" />
</shape> </shape>
</item> </item>
</layer-list> </layer-list>

View File

@@ -4,7 +4,7 @@
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="@drawable/bg_container_border">
<cc.winboll.studio.libaes.views.ASupportToolbar <cc.winboll.studio.libaes.views.ASupportToolbar
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@@ -4,7 +4,7 @@
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="@drawable/bg_container_border">
<cc.winboll.studio.libaes.views.ADsControlView <cc.winboll.studio.libaes.views.ADsControlView
android:id="@+id/ads_control_view" android:id="@+id/ads_control_view"

View File

@@ -4,7 +4,7 @@
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="@drawable/bg_container_border">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"

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

@@ -0,0 +1,17 @@
package cc.winboll.studio.appbase;
import android.os.Bundle;
import android.view.View;
import android.widget.Toolbar;
import cc.winboll.studio.appbase.R;
public class MainActivityAlias extends MainActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setActionBar(toolbar);
}
}

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@android:color/transparent" />
<stroke android:width="1dp" android:color="#FFB0B0B0" />
<corners android:radius="?attr/borderCornerRadius" />
</shape>

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

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="borderCornerRadius" format="dimension" />
<declare-styleable name="AboutView">
<attr name="app_name" format="string" />
<attr name="app_apkfoldername" format="string" />
<attr name="app_apkname" format="string" />
<attr name="app_gitname" format="string" />
<attr name="app_gitowner" format="string" />
<attr name="app_gitappbranch" format="string" />
<attr name="app_gitappsubprojectfolder" format="string" />
<attr name="appdescription" format="string" />
<attr name="appicon" format="reference" />
<attr name="is_adddebugtools" format="boolean" />
</declare-styleable>
</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

@@ -49,6 +49,10 @@ public class ASupportToolbar extends Toolbar {
// 工具栏描边 // 工具栏描边
int nStroke = 5; int nStroke = 5;
TypedArray taBorder = getContext().obtainStyledAttributes(new int[]{R.attr.borderCornerRadius});
float cornerRadius = taBorder.getDimension(0, 6 * getResources().getDisplayMetrics().density);
taBorder.recycle();
//分别为开始颜色,中间夜色,结束颜色 //分别为开始颜色,中间夜色,结束颜色
int colors0[] = { mEndColor , mCenterColor, mStartColor}; int colors0[] = { mEndColor , mCenterColor, mStartColor};
GradientDrawable gradientDrawable0; GradientDrawable gradientDrawable0;
@@ -57,7 +61,7 @@ public class ASupportToolbar extends Toolbar {
gradientDrawable0.setShape(GradientDrawable.RECTANGLE); gradientDrawable0.setShape(GradientDrawable.RECTANGLE);
gradientDrawable0.setColors(colors0); //添加颜色组 gradientDrawable0.setColors(colors0); //添加颜色组
gradientDrawable0.setGradientType(GradientDrawable.LINEAR_GRADIENT);//设置线性渐变 gradientDrawable0.setGradientType(GradientDrawable.LINEAR_GRADIENT);//设置线性渐变
gradientDrawable0.setCornerRadius(20); gradientDrawable0.setCornerRadius(cornerRadius);
int colors1[] = { mCenterColor , mCenterColor, mCenterColor }; int colors1[] = { mCenterColor , mCenterColor, mCenterColor };
GradientDrawable gradientDrawable1; GradientDrawable gradientDrawable1;
@@ -66,7 +70,7 @@ public class ASupportToolbar extends Toolbar {
gradientDrawable1.setShape(GradientDrawable.RECTANGLE); gradientDrawable1.setShape(GradientDrawable.RECTANGLE);
gradientDrawable1.setColors(colors1); //添加颜色组 gradientDrawable1.setColors(colors1); //添加颜色组
gradientDrawable1.setGradientType(GradientDrawable.LINEAR_GRADIENT);//设置线性渐变 gradientDrawable1.setGradientType(GradientDrawable.LINEAR_GRADIENT);//设置线性渐变
gradientDrawable1.setCornerRadius(20); gradientDrawable1.setCornerRadius(cornerRadius);
int colors2[] = { mEndColor, mCenterColor, mStartColor }; int colors2[] = { mEndColor, mCenterColor, mStartColor };
GradientDrawable gradientDrawable2; GradientDrawable gradientDrawable2;
@@ -75,7 +79,7 @@ public class ASupportToolbar extends Toolbar {
gradientDrawable2.setShape(GradientDrawable.RECTANGLE); gradientDrawable2.setShape(GradientDrawable.RECTANGLE);
gradientDrawable2.setColors(colors2); //添加颜色组 gradientDrawable2.setColors(colors2); //添加颜色组
gradientDrawable2.setGradientType(GradientDrawable.LINEAR_GRADIENT);//设置线性渐变 gradientDrawable2.setGradientType(GradientDrawable.LINEAR_GRADIENT);//设置线性渐变
gradientDrawable2.setCornerRadius(20); gradientDrawable2.setCornerRadius(cornerRadius);
ld = new LayerDrawable(array); //参数为上面的Drawable数组 ld = new LayerDrawable(array); //参数为上面的Drawable数组
ld.setLayerInset(2, nStroke * 2, nStroke * 2, getWidth() + nStroke * 2, getHeight() + nStroke * 2); ld.setLayerInset(2, nStroke * 2, nStroke * 2, getWidth() + nStroke * 2, getHeight() + nStroke * 2);

View File

@@ -51,6 +51,10 @@ public class AToolbar extends Toolbar {
// 工具栏描边 // 工具栏描边
int nStroke = 5; int nStroke = 5;
TypedArray taBorder = getContext().obtainStyledAttributes(new int[]{R.attr.borderCornerRadius});
float cornerRadius = taBorder.getDimension(0, 6 * getResources().getDisplayMetrics().density);
taBorder.recycle();
//分别为开始颜色,中间夜色,结束颜色 //分别为开始颜色,中间夜色,结束颜色
int colors0[] = { mEndColor , mCenterColor, mStartColor}; int colors0[] = { mEndColor , mCenterColor, mStartColor};
GradientDrawable gradientDrawable0; GradientDrawable gradientDrawable0;
@@ -59,7 +63,7 @@ public class AToolbar extends Toolbar {
gradientDrawable0.setShape(GradientDrawable.RECTANGLE); gradientDrawable0.setShape(GradientDrawable.RECTANGLE);
gradientDrawable0.setColors(colors0); //添加颜色组 gradientDrawable0.setColors(colors0); //添加颜色组
gradientDrawable0.setGradientType(GradientDrawable.LINEAR_GRADIENT);//设置线性渐变 gradientDrawable0.setGradientType(GradientDrawable.LINEAR_GRADIENT);//设置线性渐变
gradientDrawable0.setCornerRadius(20); gradientDrawable0.setCornerRadius(cornerRadius);
int colors1[] = { mCenterColor , mCenterColor, mCenterColor }; int colors1[] = { mCenterColor , mCenterColor, mCenterColor };
GradientDrawable gradientDrawable1; GradientDrawable gradientDrawable1;
@@ -68,7 +72,7 @@ public class AToolbar extends Toolbar {
gradientDrawable1.setShape(GradientDrawable.RECTANGLE); gradientDrawable1.setShape(GradientDrawable.RECTANGLE);
gradientDrawable1.setColors(colors1); //添加颜色组 gradientDrawable1.setColors(colors1); //添加颜色组
gradientDrawable1.setGradientType(GradientDrawable.LINEAR_GRADIENT);//设置线性渐变 gradientDrawable1.setGradientType(GradientDrawable.LINEAR_GRADIENT);//设置线性渐变
gradientDrawable1.setCornerRadius(20); gradientDrawable1.setCornerRadius(cornerRadius);
int colors2[] = { mEndColor, mCenterColor, mStartColor }; int colors2[] = { mEndColor, mCenterColor, mStartColor };
GradientDrawable gradientDrawable2; GradientDrawable gradientDrawable2;
@@ -77,7 +81,7 @@ public class AToolbar extends Toolbar {
gradientDrawable2.setShape(GradientDrawable.RECTANGLE); gradientDrawable2.setShape(GradientDrawable.RECTANGLE);
gradientDrawable2.setColors(colors2); //添加颜色组 gradientDrawable2.setColors(colors2); //添加颜色组
gradientDrawable2.setGradientType(GradientDrawable.LINEAR_GRADIENT);//设置线性渐变 gradientDrawable2.setGradientType(GradientDrawable.LINEAR_GRADIENT);//设置线性渐变
gradientDrawable2.setCornerRadius(20); gradientDrawable2.setCornerRadius(cornerRadius);
ld = new LayerDrawable(array); //参数为上面的Drawable数组 ld = new LayerDrawable(array); //参数为上面的Drawable数组

View File

@@ -13,11 +13,7 @@
android:startColor="@color/colorACardShadow" android:startColor="@color/colorACardShadow"
android:centerColor="@color/colorACardShadow" android:centerColor="@color/colorACardShadow"
android:endColor="@color/colorACardShadow"/> android:endColor="@color/colorACardShadow"/>
<corners <corners android:radius="?attr/borderCornerRadius" />
android:bottomLeftRadius="6dip"
android:bottomRightRadius="6dip"
android:topLeftRadius="6dip"
android:topRightRadius="6dip" />
</shape> </shape>
</item> </item>
<!-- 边框部分 --> <!-- 边框部分 -->
@@ -32,11 +28,7 @@
android:startColor="@color/colorACardFrame" android:startColor="@color/colorACardFrame"
android:centerColor="@color/colorACardFrame" android:centerColor="@color/colorACardFrame"
android:endColor="@color/colorACardFrame"/> android:endColor="@color/colorACardFrame"/>
<corners <corners android:radius="?attr/borderCornerRadius" />
android:bottomLeftRadius="6dip"
android:bottomRightRadius="6dip"
android:topLeftRadius="6dip"
android:topRightRadius="6dip" />
</shape> </shape>
</item> </item>
<!-- 背景主体部分 --> <!-- 背景主体部分 -->
@@ -52,11 +44,7 @@
android:startColor="@color/colorACardBackgroung" android:startColor="@color/colorACardBackgroung"
android:centerColor="@color/colorACardBackgroung" android:centerColor="@color/colorACardBackgroung"
android:endColor="@color/colorACardBackgroung"/> android:endColor="@color/colorACardBackgroung"/>
<corners <corners android:radius="?attr/borderCornerRadius" />
android:bottomLeftRadius="6dip"
android:bottomRightRadius="6dip"
android:topLeftRadius="6dip"
android:topRightRadius="6dip" />
</shape> </shape>
</item> </item>
</layer-list> </layer-list>

View File

@@ -13,11 +13,7 @@
android:startColor="?attr/attrAToolbarEndColor" android:startColor="?attr/attrAToolbarEndColor"
android:centerColor="?attr/attrAToolbarCenterColor" android:centerColor="?attr/attrAToolbarCenterColor"
android:endColor="?attr/attrAToolbarStartColor"/> android:endColor="?attr/attrAToolbarStartColor"/>
<corners <corners android:radius="?attr/borderCornerRadius" />
android:bottomLeftRadius="6dip"
android:bottomRightRadius="6dip"
android:topLeftRadius="6dip"
android:topRightRadius="6dip" />
</shape> </shape>
</item> </item>
<!-- 边框部分 --> <!-- 边框部分 -->
@@ -32,11 +28,7 @@
android:startColor="?attr/attrAToolbarCenterColor" android:startColor="?attr/attrAToolbarCenterColor"
android:centerColor="?attr/attrAToolbarCenterColor" android:centerColor="?attr/attrAToolbarCenterColor"
android:endColor="?attr/attrAToolbarCenterColor"/> android:endColor="?attr/attrAToolbarCenterColor"/>
<corners <corners android:radius="?attr/borderCornerRadius" />
android:bottomLeftRadius="6dip"
android:bottomRightRadius="6dip"
android:topLeftRadius="6dip"
android:topRightRadius="6dip" />
</shape> </shape>
</item> </item>
<!-- 背景主体部分 --> <!-- 背景主体部分 -->
@@ -52,11 +44,7 @@
android:startColor="?attr/attrAToolbarStartColor" android:startColor="?attr/attrAToolbarStartColor"
android:centerColor="?attr/attrAToolbarCenterColor" android:centerColor="?attr/attrAToolbarCenterColor"
android:endColor="?attr/attrAToolbarEndColor"/> android:endColor="?attr/attrAToolbarEndColor"/>
<corners <corners android:radius="?attr/borderCornerRadius" />
android:bottomLeftRadius="6dip"
android:bottomRightRadius="6dip"
android:topLeftRadius="6dip"
android:topRightRadius="6dip" />
</shape> </shape>
</item> </item>
</layer-list> </layer-list>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@android:color/transparent" />
<stroke android:width="1dp" android:color="#FFB0B0B0" />
<corners android:radius="?attr/borderCornerRadius" />
</shape>

View File

@@ -12,11 +12,7 @@
android:angle="270" android:angle="270"
android:endColor="#0F000000" android:endColor="#0F000000"
android:startColor="#0F000000" /> android:startColor="#0F000000" />
<corners <corners android:radius="?attr/borderCornerRadius" />
android:bottomLeftRadius="6dip"
android:bottomRightRadius="6dip"
android:topLeftRadius="6dip"
android:topRightRadius="6dip" />
</shape> </shape>
</item> </item>
<!-- 背景部分 --> <!-- 背景部分 -->
@@ -31,11 +27,7 @@
android:angle="270" android:angle="270"
android:endColor="@color/colorAccent" android:endColor="@color/colorAccent"
android:startColor="@color/colorAccent" /> android:startColor="@color/colorAccent" />
<corners <corners android:radius="?attr/borderCornerRadius" />
android:bottomLeftRadius="6dip"
android:bottomRightRadius="6dip"
android:topLeftRadius="6dip"
android:topRightRadius="6dip" />
</shape> </shape>
</item> </item>
</layer-list> </layer-list>

View File

@@ -9,7 +9,7 @@
android:startColor="@color/colorOHPCTSBackground" android:startColor="@color/colorOHPCTSBackground"
android:centerColor="@color/colorOHPCTSBackground" android:centerColor="@color/colorOHPCTSBackground"
android:endColor="@color/colorOHPCTSBackground"/> android:endColor="@color/colorOHPCTSBackground"/>
<corners android:radius="6dip"/> <corners android:radius="?attr/borderCornerRadius"/>
</shape> </shape>
</item> </item>
<!-- 第二进度条 --> <!-- 第二进度条 -->
@@ -22,7 +22,7 @@
android:startColor="@color/colorOHPCTSSecondaryProgress" android:startColor="@color/colorOHPCTSSecondaryProgress"
android:centerColor="@color/colorOHPCTSSecondaryProgress" android:centerColor="@color/colorOHPCTSSecondaryProgress"
android:endColor="@color/colorOHPCTSSecondaryProgress"/> android:endColor="@color/colorOHPCTSSecondaryProgress"/>
<corners android:radius="6dip"/> <corners android:radius="?attr/borderCornerRadius"/>
</shape> </shape>
</clip> </clip>
</item> </item>
@@ -36,7 +36,7 @@
android:startColor="@color/colorOHPCTSProgress" android:startColor="@color/colorOHPCTSProgress"
android:centerColor="@color/colorOHPCTSProgress" android:centerColor="@color/colorOHPCTSProgress"
android:endColor="@color/colorOHPCTSProgress"/> android:endColor="@color/colorOHPCTSProgress"/>
<corners android:radius="6dip"/> <corners android:radius="?attr/borderCornerRadius"/>
</shape> </shape>
</clip> </clip>
</item> </item>

View File

@@ -4,7 +4,7 @@
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="@drawable/bg_container_border">
<cc.winboll.studio.libaes.views.ASupportToolbar <cc.winboll.studio.libaes.views.ASupportToolbar
android:layout_width="match_parent" android:layout_width="match_parent"
@@ -16,6 +16,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1.0" android:layout_weight="1.0"
android:id="@+id/aboutviewroot_ll"/> android:id="@+id/aboutviewroot_ll" android:background="@drawable/bg_container_border" />
</LinearLayout> </LinearLayout>

View File

@@ -3,7 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content" android:background="@drawable/bg_container_border">
<cc.winboll.studio.libaes.views.ASupportToolbar <cc.winboll.studio.libaes.views.ASupportToolbar
android:layout_width="match_parent" android:layout_width="match_parent"
@@ -19,13 +19,13 @@
<LinearLayout <LinearLayout
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="@drawable/bg_container_border">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1.0" android:layout_weight="1.0"
android:id="@+id/activitydrawerLinearLayout1"/> android:id="@+id/activitydrawerLinearLayout1" android:background="@drawable/bg_container_border" />
</LinearLayout> </LinearLayout>
<com.baoyz.widget.PullRefreshLayout <com.baoyz.widget.PullRefreshLayout

View File

@@ -4,7 +4,7 @@
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="@drawable/bg_container_border">
<cc.winboll.studio.libaes.views.ASupportToolbar <cc.winboll.studio.libaes.views.ASupportToolbar
android:layout_width="match_parent" android:layout_width="match_parent"
@@ -15,7 +15,7 @@
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1.0"> android:layout_weight="1.0" android:background="@drawable/bg_container_border">
<androidx.drawerlayout.widget.DrawerLayout <androidx.drawerlayout.widget.DrawerLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@@ -26,7 +26,7 @@
<FrameLayout <FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:id="@+id/activitydrawerfragmentFrameLayout1"/> android:id="@+id/activitydrawerfragmentFrameLayout1" android:background="@drawable/bg_container_border" />
<com.baoyz.widget.PullRefreshLayout <com.baoyz.widget.PullRefreshLayout
android:orientation="vertical" android:orientation="vertical"

View File

@@ -4,7 +4,7 @@
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="@drawable/bg_container_border">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@@ -4,12 +4,12 @@
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="@drawable/bg_container_border">
<FrameLayout <FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:id="@+id/activitytestaboutfragmentFrameLayout1"/> android:id="@+id/activitytestaboutfragmentFrameLayout1" android:background="@drawable/bg_container_border" />
</LinearLayout> </LinearLayout>

View File

@@ -4,7 +4,7 @@
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="@drawable/bg_container_border">
<cc.winboll.studio.libaes.views.ASupportToolbar <cc.winboll.studio.libaes.views.ASupportToolbar
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@@ -4,7 +4,7 @@
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="@drawable/bg_container_border">
<cc.winboll.studio.libaes.views.AToolbar <cc.winboll.studio.libaes.views.AToolbar
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@@ -13,7 +13,6 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="用户须知" android:text="用户须知"
android:textSize="18sp" android:textSize="18sp"
android:textColor="@android:color/black"
android:textStyle="bold" android:textStyle="bold"
android:layout_marginBottom="16dp" /> android:layout_marginBottom="16dp" />
@@ -22,14 +21,13 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:layout_marginBottom="20dp"> android:layout_marginBottom="20dp" android:background="@drawable/bg_container_border">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="小米广告SDK隐私政策: " android:text="小米广告SDK隐私政策: "
android:textSize="14sp" android:textSize="14sp" />
android:textColor="@android:color/darker_gray" />
<!-- 可点击链接用TextView承载通过代码设置蓝色+下划线) --> <!-- 可点击链接用TextView承载通过代码设置蓝色+下划线) -->
<TextView <TextView
@@ -44,8 +42,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text=",点击链接查看完整政策" android:text=",点击链接查看完整政策"
android:textSize="14sp" android:textSize="14sp" />
android:textColor="@android:color/darker_gray" />
</LinearLayout> </LinearLayout>
<!-- 按钮容器(水平排列) --> <!-- 按钮容器(水平排列) -->
@@ -53,7 +50,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:orientation="horizontal"
android:gravity="end"> android:gravity="end" android:background="@drawable/bg_container_border">
<Button <Button
android:id="@+id/btn_disagree" android:id="@+id/btn_disagree"

View File

@@ -3,7 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
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="@drawable/bg_container_border">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
@@ -22,7 +22,7 @@
android:orientation="horizontal" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="end"> android:gravity="end" android:background="@drawable/bg_container_border">
<Button <Button
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@@ -3,7 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
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="@drawable/bg_container_border">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@@ -5,7 +5,7 @@
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:gravity="center_vertical"> android:gravity="center_vertical" android:background="@drawable/bg_container_border">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
@@ -23,7 +23,7 @@
android:layout_height="60dp" android:layout_height="60dp"
android:orientation="horizontal" android:orientation="horizontal"
android:gravity="center" android:gravity="center"
android:id="@+id/fragmentviewpageLinearLayout1"> android:id="@+id/fragmentviewpageLinearLayout1" android:background="@drawable/bg_container_border">
<ImageView <ImageView
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@@ -5,7 +5,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="48dp" android:layout_height="48dp"
android:gravity="center_vertical" android:gravity="center_vertical"
android:orientation="horizontal"> android:orientation="horizontal" android:background="@drawable/bg_container_border">
<ImageView <ImageView
android:layout_centerVertical="true" android:layout_centerVertical="true"

View File

@@ -4,12 +4,12 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/ads_container" android:id="@+id/ads_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content" android:background="@drawable/bg_container_border">
<LinearLayout <LinearLayout
android:id="@+id/ads_container" android:id="@+id/ads_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"/> android:orientation="vertical" android:background="@drawable/bg_container_border" />
</LinearLayout> </LinearLayout>

View File

@@ -4,14 +4,13 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:padding="16dp"> android:padding="16dp" android:background="@drawable/bg_container_border">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="应用支持模式设置:" android:text="应用支持模式设置:"
android:textSize="16sp" android:textSize="16sp"
android:textColor="@android:color/black"
android:layout_marginBottom="12dp"/> android:layout_marginBottom="12dp"/>
<RadioGroup <RadioGroup
@@ -26,7 +25,6 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="无扰单机模式" android:text="无扰单机模式"
android:textSize="14sp" android:textSize="14sp"
android:textColor="@android:color/darker_gray"
android:layout_marginBottom="8dp"/> android:layout_marginBottom="8dp"/>
<RadioButton <RadioButton
@@ -35,7 +33,6 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="米盟广告模式" android:text="米盟广告模式"
android:textSize="14sp" android:textSize="14sp"
android:textColor="@android:color/darker_gray"
android:layout_marginBottom="8dp"/> android:layout_marginBottom="8dp"/>
<RadioButton <RadioButton
@@ -43,8 +40,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="云宝物语模式" android:text="云宝物语模式"
android:textSize="14sp" android:textSize="14sp"/>
android:textColor="@android:color/darker_gray"/>
</RadioGroup> </RadioGroup>
@@ -54,7 +50,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:visibility="gone" android:visibility="gone"
android:layout_marginTop="0dp"> <!-- 移除顶部多余间距 --> android:layout_marginTop="0dp"> <!-- 移除顶部多余间距 -- android:background="@drawable/bg_container_border">
<ImageView <ImageView
android:id="@+id/iv_winboll_store" android:id="@+id/iv_winboll_store"

View File

@@ -3,7 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
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="@drawable/bg_container_border">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@@ -3,7 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
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="@drawable/bg_container_border">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@@ -4,7 +4,7 @@
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:gravity="center"> android:gravity="center" android:background="@drawable/bg_container_border">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
@@ -15,7 +15,7 @@
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center"> android:gravity="center" android:background="@drawable/bg_container_border">
<cc.winboll.studio.libaes.views.AOHPCTCSeekBar <cc.winboll.studio.libaes.views.AOHPCTCSeekBar
android:layout_width="300dp" android:layout_width="300dp"

View File

@@ -3,7 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
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="@drawable/bg_container_border">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<attr name="borderCornerRadius" format="dimension" />
<attr name="colorTextColor" format="color" /> <attr name="colorTextColor" format="color" />
<attr name="colorPrimary" format="color" /> <attr name="colorPrimary" format="color" />
<attr name="colorPrimaryDark" format="color" /> <attr name="colorPrimaryDark" format="color" />

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"; public static final String TITTLE = "CrashReport";
/** Intent 传递崩溃信息键 */
/** Intent 传递崩溃信息的键(用于向崩溃页面传递日志) */
public static final String EXTRA_CRASH_LOG = "crashInfo"; 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";
/** SharedPreferences 存储键(用于记录崩溃状态) */ // ====================== 成员变量 ======================
final static String PREFS = CrashHandler.class.getName() + "PREFS"; /** 崩溃保险丝状态文件路径 */
/** SharedPreferences 中存储「是否发生崩溃」的键 */
final static String PREFS_CRASHHANDLER_ISCRASHHAPPEN = "PREFS_CRASHHANDLER_ISCRASHHAPPEN";
/** 崩溃保险丝状态文件路径(存储当前熔断等级) */
public static String _CrashCountFilePath; public static String _CrashCountFilePath;
/** 系统默认异常处理器兜底 */
public static final UncaughtExceptionHandler DEFAULT_UNCAUGHT_EXCEPTION_HANDLER
= Thread.getDefaultUncaughtExceptionHandler();
/** 系统默认的未捕获异常处理器(用于降级处理,避免 CrashHandler 自身崩溃) */ // ====================== 对外初始化方法 ======================
public static final UncaughtExceptionHandler DEFAULT_UNCAUGHT_EXCEPTION_HANDLER = Thread.getDefaultUncaughtExceptionHandler();
/** /**
* 初始化崩溃处理器(默认存储路径) * 初始化崩溃处理器(默认存储路径)
* 调用重载方法,崩溃日志默认存储在应用外部私有目录的 crash 文件夹下 * @param app 全局Application实例
* @param app 全局 Application 实例(用于获取存储目录、包信息等)
*/ */
public static void init(Application app) { public static void init(final Application app) {
// 初始化崩溃保险丝状态文件路径(外部存储/CrashHandler/IsCrashHandlerCrashHappen.dat
_CrashCountFilePath = app.getExternalFilesDir("CrashHandler") + "/IsCrashHandlerCrashHappen.dat"; _CrashCountFilePath = app.getExternalFilesDir("CrashHandler") + "/IsCrashHandlerCrashHappen.dat";
LogUtils.d(TAG, String.format("_CrashCountFilePath %s", _CrashCountFilePath)); LogUtils.d(TAG, "init _CrashCountFilePath = " + _CrashCountFilePath);
// 调用带目录参数的初始化方法,传入 null 使用默认路径
init(app, null); init(app, null);
} }
/** /**
* 初始化崩溃处理器(指定日志存储目录) * 初始化崩溃处理器(自定义日志目录)
* 替换系统默认的未捕获异常处理器,自定义崩溃处理逻辑
* @param app 全局Application实例 * @param app 全局Application实例
* @param crashDir 崩溃日志存储目录(null使用默认路径) * @param crashDir 自定义崩溃日志目录,传null使用默认
*/ */
public static void init(final Application app, final String crashDir) { public static void init(final Application app, final String crashDir) {
// 设置自定义未捕获异常处理器
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { 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熔断后启动基础版崩溃页面
*/ */
public static final class AppCrashSafetyWire { private static void tryUncaughtException(final Thread thread,
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;
*/
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 { try {
// 序列化等级到文件ObjectOutputStream 写入 int final PackageInfo packageInfo = app.getPackageManager()
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(_CrashCountFilePath)); .getPackageInfo(app.getPackageName(), 0);
oos.writeInt(currentSafetyLevel); versionName = packageInfo.versionName;
oos.flush(); if (Build.VERSION.SDK_INT >= 28) {
oos.close(); versionCode = packageInfo.getLongVersionCode();
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(_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 { } else {
// 文件不存在初始化等级为最高2并保存 versionCode = packageInfo.versionCode;
currentSafetyLevel = _MAX;
LogUtils.d(TAG, String.format("loadCurrentSafetyLevel() currentSafetyLevel init to _MAX->%d", _MAX));
saveCurrentSafetyLevel(currentSafetyLevel);
} }
} catch (PackageManager.NameNotFoundException e) {
LogUtils.e(TAG, "get package info fail");
}
// 抓取异常堆栈
String fullStackTrace;
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
throwable.printStackTrace(pw);
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");
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();
// 写入日志文件
try {
writeFile(crashFile, errorLog);
} catch (IOException e) { } catch (IOException e) {
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace()); LogUtils.e(TAG, "write crash log file fail");
} }
return currentSafetyLevel;
// 跳转崩溃页面
gotoCrashActivity(errorLog, app);
} }
/** /**
* 熔断保险丝(每次崩溃调用,降低防护等级) * 写入文本到文件
* @return 熔断后是否仍在防护范围内truefalse已熔断
*/ */
boolean burnSafetyWire() { private static void writeFile(final File file, final String content) throws IOException {
LogUtils.d(TAG, "burnSafetyWire()"); final File parentFile = file.getParentFile();
// 加载当前等级 if (parentFile != null && !parentFile.exists()) {
int safeLevel = loadCurrentSafetyLevel(); parentFile.mkdirs();
// 若在防护范围内1~2等级-1 并保存
if (isSafetyWireWorking(safeLevel)) {
LogUtils.d(TAG, "burnSafetyWire() use");
saveCurrentSafetyLevel(safeLevel - 1);
// 返回熔断后的状态
return isSafetyWireWorking(safeLevel - 1);
} }
return false; file.createNewFile();
FileOutputStream fos = new FileOutputStream(file);
fos.write(content.getBytes());
fos.close();
} }
/** /**
* 检查熔断等级是否在有效范围内1~2 * 根据保险丝状态跳转对应崩溃页面
* @param safetyLevel 待检查的等级
* @return true在范围内防护有效false超出范围已熔断
*/ */
boolean isSafetyWireWorking(int safetyLevel) { private static void gotoCrashActivity(final String errorLog, final Application app) {
LogUtils.d(TAG, "isSafetyWireOK()"); final Intent intent = new Intent();
LogUtils.d(TAG, String.format("SafetyLevel %d", safetyLevel)); if (AppCrashSafetyWire.getInstance().isAppCrashSafetyWireOK()) {
intent.setClass(app, GlobalCrashActivity.class);
if (safetyLevel >= _MINI && safetyLevel <= _MAX) { } else {
LogUtils.d(TAG, String.format("In Safety Level")); intent.setClass(app, CrashActivity.class);
return true; }
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()) {
app.startActivity(intent);
} else {
CrashHandleNotifyUtils.handleUncaughtException(app, intent, GlobalCrashActivity.class);
}
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);
}
} }
LogUtils.d(TAG, String.format("Out of Safety Level"));
return false;
} }
// ====================== 内部Activity页面 ======================
/** /**
* 立即恢复熔断等级到最高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已熔断
*/
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);
}
}
/**
* 基础版崩溃报告页面(保险丝熔断时启动)
* 极简实现:仅展示崩溃日志,提供复制、重启功能,避免复杂布局导致二次崩溃
*/ */
public static final class CrashActivity extends Activity implements MenuItem.OnMenuItemClickListener { public static final class CrashActivity extends Activity implements MenuItem.OnMenuItemClickListener {
/** 菜单标识:复制崩溃日志 */
private static final int MENUITEM_COPY = 0; private static final int MENUITEM_COPY = 0;
/** 菜单标识:重启应用 */
private static final int MENUITEM_RESTART = 1; private static final int MENUITEM_RESTART = 1;
/** 崩溃日志文本(从 CrashHandler 传递过来) */
private String mLog; private String mLog;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
// 初始化崩溃保险丝延迟恢复机制
AppCrashSafetyWire.getInstance().postResumeCrashSafetyWireHandler(getApplicationContext()); AppCrashSafetyWire.getInstance().postResumeCrashSafetyWireHandler(getApplicationContext());
// 获取传递的崩溃日志
mLog = getIntent().getStringExtra(EXTRA_CRASH_LOG); mLog = getIntent().getStringExtra(EXTRA_CRASH_LOG);
// 设置系统默认主题(避免自定义主题冲突)
setTheme(android.R.style.Theme_DeviceDefault_Light_DarkActionBar); setTheme(android.R.style.Theme_DeviceDefault_Light_DarkActionBar);
initLayout();
}
// 动态创建布局(避免 XML 布局加载异常) /**
setContentView: { * 动态初始化布局
// 垂直滚动视图(处理日志过长) */
private void initLayout() {
ScrollView contentView = new ScrollView(this); ScrollView contentView = new ScrollView(this);
contentView.setFillViewport(true); contentView.setFillViewport(true);
// 水平滚动视图(处理日志行过长)
HorizontalScrollView hw = new HorizontalScrollView(this); HorizontalScrollView hw = new HorizontalScrollView(this);
hw.setBackgroundColor(0xFFF5F5F5); // 深色模式灰色背景 hw.setBackgroundColor(0xFFF5F5F5);
// 日志显示文本框
TextView message = new TextView(this); TextView message = new TextView(this);
{ final int padding = dp2px(16);
int padding = dp2px(16); // 内边距 16dp适配不同屏幕
message.setPadding(padding, padding, padding, padding); message.setPadding(padding, padding, padding, padding);
message.setText(mLog); // 设置崩溃日志 message.setText(mLog);
message.setTextColor(0xFF000000); // 深色模式灰色文字,普通模式黑色文字 message.setTextColor(0xFF000000);
message.setTextIsSelectable(true); // 支持文本选择(便于手动复制) message.setTextIsSelectable(true);
}
// 组装布局TextView -> HorizontalScrollView -> ScrollView
hw.addView(message); hw.addView(message);
contentView.addView(hw, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); contentView.addView(hw, ViewGroup.LayoutParams.MATCH_PARENT,
// 设置当前 Activity 布局 ViewGroup.LayoutParams.MATCH_PARENT);
setContentView(contentView); setContentView(contentView);
// 配置 ActionBar 标题和副标题
getActionBar().setTitle(TITTLE); getActionBar().setTitle(TITTLE);
getActionBar().setSubtitle(GlobalApplication.class.getSimpleName() + " Error"); getActionBar().setSubtitle(GlobalApplication.class.getSimpleName() + " Error");
} }
}
/**
* 重写返回键逻辑:点击返回键直接重启应用
*/
@Override @Override
public void onBackPressed() { public void onBackPressed() {
restart(); restartApp();
} }
/** /**
* 重启当前应用(与 GlobalCrashActivity 逻辑一致) * 重启应用
* 清除任务栈,启动主 Activity终止当前进程
*/ */
private void restart() { private void restartApp() {
PackageManager pm = getPackageManager(); final Intent intent = getPackageManager()
// 获取应用启动意图(默认启动主 Activity .getLaunchIntentForPackage(getPackageName());
Intent intent = pm.getLaunchIntentForPackage(getPackageName());
if (intent != null) { if (intent != null) {
// 设置意图标志:清除原有任务栈,创建新任务 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
intent.addFlags(
Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
);
startActivity(intent); startActivity(intent);
} }
// 关闭当前页面,终止进程,确保完全重启
finish(); finish();
android.os.Process.killProcess(android.os.Process.myPid()); android.os.Process.killProcess(android.os.Process.myPid());
System.exit(0); System.exit(0);
} }
/** /**
* dp 转 px适配不同屏幕密度 * dp转px
* @param dpValue dp 值
* @return 转换后的 px 值
*/ */
private int dp2px(final float dpValue) { private int dp2px(final float dpValue) {
final float scale = Resources.getSystem().getDisplayMetrics().density; final float scale = Resources.getSystem().getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f); // 四舍五入确保精度 return (int) (dpValue * scale + 0.5f);
} }
/**
* 菜单点击事件回调(处理复制、重启)
* @param item 被点击的菜单项
* @return false不消费事件保持默认行为
*/
@Override @Override
public boolean onMenuItemClick(MenuItem item) { public boolean onCreateOptionsMenu(final Menu menu) {
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") 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) {
LogUtils.d(TAG, "onCreate 方法进入");
try {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
final Context appContext = getApplicationContext();
// 初始化崩溃安全防护机制 // 初始化崩溃安全防护机制
// 作用:防止应用重启后短时间内再次崩溃,由 CrashHandler 内部实现防护逻辑 AppCrashSafetyWire.getInstance().postResumeCrashSafetyWireHandler(appContext);
CrashHandler.AppCrashSafetyWire.getInstance()
.postResumeCrashSafetyWireHandler(getApplicationContext());
// 从 Intent 中获取崩溃日志数据EXTRA_CRASH_INFO 为 CrashHandler 定义的常量键) // 获取传递的崩溃日志
mCrashLog = getIntent().getStringExtra(CrashHandler.EXTRA_CRASH_LOG); mCrashLog = getIntent().getStringExtra(CrashHandler.EXTRA_CRASH_LOG);
LogUtils.d(TAG, "获取到崩溃日志,长度:" + (mCrashLog != null ? mCrashLog.length() : 0));
// 设置当前 Activity 的布局文件(展示崩溃报告的 UI 结构)
setContentView(R.layout.activity_globalcrash); setContentView(R.layout.activity_globalcrash);
// 初始化崩溃报告展示视图(通过布局 ID 找到自定义 View 实例)
mCrashReportView = findViewById(R.id.activityglobalcrashGlobalCrashReportView1); mCrashReportView = findViewById(R.id.activityglobalcrashGlobalCrashReportView1);
// 将崩溃日志设置到视图中,由自定义 View 负责排版和显示
mCrashReportView.setReport(mCrashLog); mCrashReportView.setReport(mCrashLog);
// 设置页面的 ActionBar复用自定义 View 中的 Toolbar 作为系统 ActionBar
setActionBar(mCrashReportView.getToolbar()); setActionBar(mCrashReportView.getToolbar());
// 配置 ActionBar 标题和副标题(非空判断避免空指针异常)
if (getActionBar() != null) { if (getActionBar() != null) {
// 设置标题:使用 CrashHandler 中定义的统一标题(如 "应用崩溃报告"
getActionBar().setTitle(CrashHandler.TITTLE); getActionBar().setTitle(CrashHandler.TITTLE);
// 设置副标题:显示当前应用名称(从全局 Application 工具方法获取) getActionBar().setSubtitle(GlobalApplication.getAppName(appContext));
getActionBar().setSubtitle(GlobalApplication.getAppName(getApplicationContext())); }
} catch (final Exception e) {
LogUtils.e(TAG, "GlobalCrashActivity onCreate 发生异常", e);
AppCrashSafetyWire.getInstance().burnSafetyWire();
mCrashLog = getIntent().getStringExtra(CrashHandler.EXTRA_CRASH_LOG);
final Intent intent = new Intent();
intent.putExtra(CrashHandler.EXTRA_CRASH_LOG, mCrashLog);
CrashHandleNotifyUtils.handleUncaughtException(GlobalApplication.getInstance(), intent, CrashHandler.CrashActivity.class);
StackTraceElement[] stackElements = Thread.currentThread().getStackTrace();
StringBuilder sb = new StringBuilder("GlobalCrashActivity onCreate StackTrace");
for (StackTraceElement item : stackElements) {
sb.append("\n").append(item.toString());
}
LogUtils.d(TAG, sb.toString());
finish();
} }
} }
/**
* 重写返回键点击事件
* 逻辑:点击手机返回键时,直接重启应用(而非返回上一页,因崩溃后上一页状态可能异常)
*/
@Override @Override
public void onBackPressed() { public void onBackPressed() {
LogUtils.d(TAG, "onBackPressed 触发重启应用");
restartApp(); restartApp();
} }
/** // ====================== 菜单相关回调 ======================
* 重启当前应用(核心工具方法)
* 实现逻辑:
* 1. 获取应用的启动意图(默认启动 AndroidManifest 中配置的主 Activity
* 2. 设置意图标志,清除原有任务栈,避免残留异常页面
* 3. 启动主 Activity 并终止当前进程,确保应用完全重启
*/
private void restartApp() {
// 获取 PackageManager 实例(用于获取应用相关信息和意图)
PackageManager packageManager = getPackageManager();
// 获取应用的启动意图(参数为当前应用包名,返回主 Activity 的意图)
Intent launchIntent = packageManager.getLaunchIntentForPackage(getPackageName());
if (launchIntent != null) {
// 设置意图标志:
// FLAG_ACTIVITY_NEW_TASK创建新的任务栈启动 Activity
// FLAG_ACTIVITY_CLEAR_TOP清除目标 Activity 之上的所有 Activity
// FLAG_ACTIVITY_CLEAR_TASK清除当前任务栈中的所有 Activity
launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
// 启动应用主 Activity
startActivity(launchIntent);
}
// 关闭当前崩溃报告页面
finish();
// 终止当前应用进程(确保释放所有资源,避免内存泄漏)
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 onCreateOptionsMenu(final Menu menu) {
// 根据菜单项 ID 判断点击的是哪个功能 LogUtils.d(TAG, "onCreateOptionsView 初始化菜单");
menu.add(0, MENU_ITEM_COPY, 0, "Copy")
.setOnMenuItemClickListener(this)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add(0, MENU_ITEM_RESTART, 0, "Restart")
.setOnMenuItemClickListener(this)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
mCrashReportView.updateMenuStyle();
return true;
}
@Override
public boolean onMenuItemClick(final MenuItem item) {
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;
@@ -217,9 +201,6 @@ public class LogUtils {
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

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@android:color/transparent" />
<stroke android:width="1dp" android:color="#FFB0B0B0" />
<corners android:radius="?attr/borderCornerRadius" />
</shape>

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

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

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

View File

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

@@ -1,38 +0,0 @@
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
apply from: '../.winboll/winboll_lib_build.gradle'
apply from: '../.winboll/winboll_lint_build.gradle'
android {
// 适配MIUI12
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
minSdkVersion 26
targetSdkVersion 30
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
// 网络连接类库
api 'com.squareup.okhttp3:okhttp:4.4.1'
// Gson
api 'com.google.code.gson:gson:2.8.9'
// Html 解析
api 'org.jsoup:jsoup:1.13.1'
// 添加JSch依赖SFTP核心com.jcraft:jsch:0.1.54
api 'com.jcraft:jsch:0.1.54'
// WinBoLL库 nexus.winboll.cc 地址
api 'cc.winboll.studio:libaes:15.15.2'
api 'cc.winboll.studio:libappbase:15.15.11'
api fileTree(dir: 'libs', include: ['*.jar'])
}

View File

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

View File

@@ -1,17 +0,0 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:/tools/adt-bundle-windows-x86_64-20131030/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

View File

@@ -1,12 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cc.winboll.studio.libwinboll" >
<application>
<activity
android:name=".WinBoLLLibraryActivity">
</activity>
</application>
</manifest>

View File

@@ -1,17 +0,0 @@
package cc.winboll.studio.libwinboll;
import android.app.Activity;
import android.os.Bundle;
import cc.winboll.studio.libappbase.ToastUtils;
public class WinBoLLLibraryActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_winbolllibrary);
ToastUtils.show("WinBoLLLibraryActivity onCreate");
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

View File

@@ -1,11 +0,0 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="cc.winboll.studio.libwinboll.WinBoLLLibraryActivity"/>
</LinearLayout>

View File

@@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="@android:style/Theme.Material.Light">
</style>
</resources>

View File

@@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="lib_name">libwinboll</string>
<string name="hello_world">Hello world!</string>
</resources>

View File

@@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="@android:style/Theme.Holo.Light">
</style>
</resources>

View File

@@ -0,0 +1,45 @@
# MyMessageManager
#### 介绍
用正则表达式方法自定义短信过滤和语音播报的短信应用。
#### 软件架构
软件架构说明
#### 安装教程
1. xxxx
2. xxxx
3. xxxx
#### 使用说明
1. xxxx
2. xxxx
3. xxxx
#### 参与贡献
1. Fork 本仓库
2. 新建 Feat_xxx 分支
3. 提交代码ZhanGSKen(ZhanGSKen<zhangsken@188.com>)
4. 新建 Pull Request
#### 特技
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
#### 参考文档
使用GitHub Actions实现Android自动打包apk
https://blog.csdn.net/ZZL23333/article/details/115798615?app_version=6.0.0&code=app_1562916241&csdn_share_tail=%7B%22type%22%3A%22blog%22%2C%22rType%22%3A%22article%22%2C%22rId%22%3A%22115798615%22%2C%22source%22%3A%22weixin_38986226%22%7D&uLinkId=usr1mkqgl919blen&utm_source=app
Android中assets的使用用于读取内容
https://blog.csdn.net/qq_27664947/article/details/103924058?app_version=6.0.0&code=app_1562916241&csdn_share_tail=%7B%22type%22%3A%22blog%22%2C%22rType%22%3A%22article%22%2C%22rId%22%3A%22103924058%22%2C%22source%22%3A%22weixin_38986226%22%7D&uLinkId=usr1mkqgl919blen&utm_source=app

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,91 @@
apply plugin: 'com.android.application'
apply from: '../.winboll/winboll_app_build.gradle'
apply from: '../.winboll/winboll_lint_build.gradle'
def genVersionName(def versionName){
// 检查编译标志位配置
assert (winbollBuildProps['stageCount'] != null)
assert (winbollBuildProps['baseVersion'] != null)
// 保存基础版本号
winbollBuildProps.setProperty("baseVersion", "${versionName}");
//保存编译标志配置
FileOutputStream fos = new FileOutputStream(winbollBuildPropsFile)
winbollBuildProps.store(fos, "${winbollBuildPropsDesc}");
fos.close();
// 返回编译版本号
return "${versionName}." + winbollBuildProps['stageCount']
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
defaultConfig {
applicationId "cc.winboll.studio.mymessagemanager"
minSdkVersion 26
targetSdkVersion 30
versionCode 8
// versionName 更新后需要手动设置
// .winboll/winbollBuildProps.properties 文件的 stageCount=0
// Gradle编译环境下合起来的 versionName 就是 "${versionName}.0"
versionName "15.12"
if(true) {
versionName = genVersionName("${versionName}")
}
}
// 米盟 SDK
packagingOptions {
doNotStrip "*/*/libmimo_1011.so"
}
}
dependencies {
// 米盟
api 'com.miui.zeus:mimo-ad-sdk:5.3.+'//请使用最新版sdk
//注意以下5个库必须要引入
//api 'androidx.appcompat:appcompat:1.4.1'
api 'androidx.recyclerview:recyclerview:1.0.0'
api 'com.google.code.gson:gson:2.8.5'
api 'com.github.bumptech.glide:glide:4.9.0'
//annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
api 'io.github.medyo:android-about-page:2.0.0'
api 'com.jcraft:jsch:0.1.55'
api 'org.jsoup:jsoup:1.13.1'
api 'com.squareup.okhttp3:okhttp:4.4.1'
api 'com.belerweb:pinyin4j:2.5.1'
// 权限请求框架https://github.com/getActivity/XXPermissions
api 'com.github.getActivity:XXPermissions:18.63'
api 'com.baoyz.pullrefreshlayout:library:1.2.0'
// AndroidX 类库
api 'androidx.appcompat:appcompat:1.1.0'
api 'com.google.android.material:material:1.4.0'
//api 'androidx.viewpager:viewpager:1.0.0'
//api 'androidx.vectordrawable:vectordrawable:1.1.0'
//api 'androidx.vectordrawable:vectordrawable-animated:1.1.0'
//api 'androidx.fragment:fragment:1.1.0'
api 'com.google.android.material:material:1.0.0'
// WinBoLL库 nexus.winboll.cc 地址
api 'cc.winboll.studio:libaes:15.15.9'
api 'cc.winboll.studio:libappbase:15.15.21'
// WinBoLL备用库 jitpack.io 地址
//api 'com.github.ZhanGSKen:AES:aes-v15.12.9'
//api 'com.github.ZhanGSKen:APPBase:appbase-v15.14.1'
api fileTree(dir: 'libs', include: ['*.jar'])
}

View File

@@ -0,0 +1,8 @@
#Created by .winboll/winboll_app_build.gradle
#Sat May 09 14:21:58 HKT 2026
stageCount=12
libraryProject=
baseVersion=15.12
publishVersion=15.12.11
buildCount=0
baseBetaVersion=15.12.12

143
mymessagemanager/proguard-rules.pro vendored Normal file
View File

@@ -0,0 +1,143 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\tools\adt-bundle-windows-x86_64-20131030\sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# ============================== 基础通用规则 ==============================
# 保留系统组件
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
# 保留 WinBoLL 核心包及子类(合并简化规则)
-keep class cc.winboll.studio.** { *; }
-keepclassmembers class cc.winboll.studio.** { *; }
# 保留所有类中的 public static final String TAG 字段(便于日志定位)
-keepclassmembers class * {
public static final java.lang.String TAG;
}
# 保留序列化类避免Parcelable/Gson解析异常
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
# 保留 R 文件避免资源ID混淆
-keepclassmembers class **.R$* {
public static <fields>;
}
# 保留 native 方法避免JNI调用失败
-keepclasseswithmembernames class * {
native <methods>;
}
# 保留注解和泛型(避免反射/序列化异常)
-keepattributes *Annotation*
-keepattributes Signature
# 屏蔽 Java 8+ 警告(适配 Java 7 语法)
-dontwarn java.lang.invoke.*
-dontwarn android.support.v8.renderscript.*
-dontwarn java.util.function.**
# ============================== 第三方框架专项规则 ==============================
# OkHttp 4.4.1米盟广告请求依赖完善Lambda兼容
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-keep class okhttp3.internal.** { *; }
-keep class okio.** { *; }
-dontwarn okhttp3.internal.platform.**
-dontwarn okio.**
# ============================== 必要补充规则 ==============================
# OkHttp 4.4.1 补充规则Java 7 兼容)
-keep class okhttp3.internal.concurrent.** { *; }
-keep class okhttp3.internal.connection.** { *; }
-dontwarn okhttp3.internal.concurrent.TaskRunner
-dontwarn okhttp3.internal.connection.RealCall
# Glide 4.9.0(米盟广告图片加载依赖)
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.ImageHeaderParser$ImageType {
**[] $VALUES;
public *;
}
-keepclassmembers class * implements com.bumptech.glide.module.AppGlideModule {
<init>();
}
-dontwarn com.bumptech.glide.**
# Gson 2.8.5(米盟广告数据序列化依赖)
-keep class com.google.gson.** { *; }
-keep interface com.google.gson.** { *; }
-keepclassmembers class * {
@com.google.gson.annotations.SerializedName <fields>;
}
# 米盟 SDK(核心广告组件,完整保留避免加载失败)
-keep class com.miui.zeus.** { *; }
-keep interface com.miui.zeus.** { *; }
# 保留米盟日志字段(便于广告加载失败排查)
-keepclassmembers class com.miui.zeus.mimo.sdk.** {
public static final java.lang.String TAG;
}
# RecyclerView 1.0.0(米盟广告布局渲染依赖)
-keep class androidx.recyclerview.** { *; }
-keep interface androidx.recyclerview.** { *; }
-keepclassmembers class androidx.recyclerview.widget.RecyclerView$Adapter {
public *;
}
# 其他第三方框架(按引入依赖保留,无则可删除)
# XXPermissions 18.63
-keep class com.hjq.permissions.** { *; }
-keep interface com.hjq.permissions.** { *; }
# ZXing 二维码(核心解析组件)
-keep class com.google.zxing.** { *; }
-keep class com.journeyapps.zxing.** { *; }
# Jsoup HTML解析
-keep class org.jsoup.** { *; }
# Pinyin4j 拼音搜索
-keep class net.sourceforge.pinyin4j.** { *; }
# JSch SSH组件
-keep class com.jcraft.jsch.** { *; }
# AndroidX 基础组件
-keep class androidx.appcompat.** { *; }
-keep interface androidx.appcompat.** { *; }
# ============================== 优化与调试配置 ==============================
# 优化级别(平衡混淆效果与性能)
-optimizationpasses 5
-optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*
# 调试辅助(保留行号便于崩溃定位)
-verbose
-dontpreverify
-dontusemixedcaseclassnames
-keepattributes SourceFile,LineNumberTable

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" >
<application>
<!-- Put flavor specific code here -->
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="cc.winboll.studio.mymessagemanager.beta.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider"/>
</provider>
</application>
</manifest>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">我的短信管家 ☆</string>
</resources>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">My Message Manager +</string>
</resources>

View File

@@ -0,0 +1,227 @@
<?xml version='1.0' encoding='utf-8'?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="cc.winboll.studio.mymessagemanager">
<!-- 发送短信 -->
<uses-permission android:name="android.permission.SEND_SMS"/>
<!-- 接收讯息(短信) -->
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<!-- 读取短信 -->
<uses-permission android:name="android.permission.READ_SMS"/>
<!-- WRITE_SMS -->
<uses-permission android:name="android.permission.WRITE_SMS"/>
<!-- 接收讯息(彩信) -->
<uses-permission android:name="android.permission.RECEIVE_MMS"/>
<!-- 开机启动 -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<!-- 运行前台服务 -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<!-- 读取联系人 -->
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<!-- 读取您共享存储空间中的内容 -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<!-- 修改或删除您共享存储空间中的内容 -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- 接收讯息 (WAP) -->
<uses-permission android:name="android.permission.RECEIVE_WAP_PUSH"/>
<!-- MANAGE_EXTERNAL_STORAGE -->
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<!-- 此应用可显示在其他应用上方 -->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<queries>
<intent>
<action android:name="android.intent.action.TTS_SERVICE"/>
</intent>
</queries>
<application
android:name=".App"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:roundIcon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/MyAppTheme"
android:persistent="true"
android:resizeableActivity="true"
android:supportsRtl="true"
android:requestLegacyExternalStorage="true"
android:networkSecurityConfig="@xml/network_security_config">
<activity android:name=".activitys.SMSActivity"/>
<activity android:name=".activitys.SMSReceiveRuleActivity">
</activity>
<activity
android:name=".activitys.SharedJSONReceiveActivity"
android:exported="true">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.SEND"/>
<action android:name="android.intent.action.VIEW"/>
<action android:name="android.intent.action.EDIT"/>
<data android:mimeType="application/json"/>
<data android:mimeType="text/x-json"/>
</intent-filter>
</activity>
<activity android:name=".activitys.TTSPlayRuleActivity"/>
<activity android:name=".activitys.AboutActivity"/>
<activity
android:name=".activitys.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".activitys.ComposeSMSActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<action android:name="android.intent.action.SENDTO"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="sms"/>
<data android:scheme="smsto"/>
<data android:scheme="mms"/>
<data android:scheme="mmsto"/>
</intent-filter>
</activity>
<activity android:name=".activitys.AppSettingsActivity"/>
<service android:name=".services.TTSPlayService"/>
<service android:name=".services.MainService"/>
<service android:name=".services.AssistantService"/>
<service
android:name=".services.DefaultSMSManagerService"
android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.RESPOND_VIA_MESSAGE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="sms"/>
<data android:scheme="smsto"/>
<data android:scheme="mms"/>
<data android:scheme="mmsto"/>
</intent-filter>
</service>
<receiver
android:name=".receivers.MainReceiver"
android:enabled="true"
android:exported="false"
android:directBootAware="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<receiver
android:name=".receivers.SMSRecevier"
android:exported="true"
android:permission="android.permission.BROADCAST_SMS">
<intent-filter android:priority="1">
<action android:name="android.provider.Telephony.SMS_DELIVER"/>
</intent-filter>
</receiver>
<receiver
android:name=".receivers.MmsReceiver"
android:exported="true"
android:permission="android.permission.BROADCAST_WAP_PUSH">
<intent-filter>
<action android:name="android.provider.Telephony.WAP_PUSH_DELIVER"/>
<data android:mimeType="application/vnd.wap.mms-message"/>
</intent-filter>
</receiver>
<meta-data
android:name="android.max_aspect"
android:value="4.0"/>
<activity android:name="cc.winboll.studio.mymessagemanager.activitys.SMSRecycleActivity"/>
<activity android:name="cc.winboll.studio.mymessagemanager.activitys.SMSRecycle2Activity"/>
<activity android:name="cc.winboll.studio.mymessagemanager.unittest.UnitTestActivity"/>
<activity android:name="cc.winboll.studio.mymessagemanager.activitys.TTSFloatSettingsActivity"/>
</application>
</manifest>

View File

@@ -0,0 +1,7 @@
[
{
"userId": -1,
"ruleData": ".*",
"isEnable": true
}
]

View File

@@ -0,0 +1,38 @@
[
{
"userId": 1,
"ruleName": "规则1",
"demoSMSText": "【短信应用A】验证码123456",
"patternText": "^(【.*】)验证码(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)$",
"ttdRuleText": "$1验证码是($2)($3)($4)($5)($6)($7)。",
"isSimpleView": false,
"isEnable": true
},
{
"userId": 1,
"ruleName": "规则2",
"demoSMSText": "[短信应用A]验证码123456",
"patternText": "^(\\[.*\\])验证码(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)$",
"ttdRuleText": "$1验证码是($2)($3)($4)($5)($6)($7)。",
"isSimpleView": false,
"isEnable": true
},
{
"userId": 1,
"ruleName": "规则3",
"demoSMSText": "【短信应用A】验证码123456",
"patternText": ".*(【.+】).*",
"ttdRuleText": "短信来自$1。",
"isSimpleView": false,
"isEnable": true
},
{
"userId": 1,
"ruleName": "规则4",
"demoSMSText": "[短信应用A]验证码123456",
"patternText": ".*(\\[.*\\]).*",
"ttdRuleText": "短信来自$1。",
"isSimpleView": false,
"isEnable": true
}
]

View File

@@ -0,0 +1,52 @@
package cc.winboll.studio.mymessagemanager;
/**
* @Author ZhanGSKen@QQ.COM
* @Date 2023/07/24 01:46:59
* @Describe 全局应用类
*/
import android.view.Gravity;
import cc.winboll.studio.libappbase.GlobalApplication;
import cc.winboll.studio.libappbase.ToastUtils;
import cc.winboll.studio.mymessagemanager.R;
import java.io.File;
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
public class App extends GlobalApplication {
public static final String TAG = "GlobalApplication";
static String _mszAppExternalFilesDir;
static String _mszConfigUtilFileName = "ConfigUtil.json";
static String _mszConfigUtilPath;
static String _mszSMSReceiveRuleUtilFileName = "SMSReceiveRuleUtil.json";
static String _mszSMSReceiveRuleUtilPath;
public static final int USER_ID = -1;
Long mszVersionName = 1L;
Long mszDataVersionName = 1L;
@Override
public void onCreate() {
super.onCreate();
setIsDebugging(BuildConfig.DEBUG);
//setIsDebugging(false);
// 初始化窗口管理类
WinBoLLActivityManager.init(this);
// 初始化 Toast 框架
ToastUtils.init(this);
_mszAppExternalFilesDir = getExternalFilesDir(TAG).toString();
_mszConfigUtilPath = _mszAppExternalFilesDir + File.separator + _mszConfigUtilFileName;
_mszSMSReceiveRuleUtilPath = _mszAppExternalFilesDir + File.separator + _mszSMSReceiveRuleUtilFileName;
}
@Override
public void onTerminate() {
super.onTerminate();
ToastUtils.release();
}
}

View File

@@ -0,0 +1,52 @@
package cc.winboll.studio.mymessagemanager.activitys;
import android.os.Bundle;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import cc.winboll.studio.libappbase.models.APPInfo;
import cc.winboll.studio.libappbase.views.AboutView;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.mymessagemanager.R;
public class AboutActivity extends AppCompatActivity {
public static final String TAG = "AboutActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
AboutView aboutView = findViewById(R.id.aboutview);
aboutView.setAPPInfo(genDefaultAppInfo());
}
private APPInfo genDefaultAppInfo() {
LogUtils.d(TAG, "genDefaultAppInfo() 调用");
String branchName = "mymessagemanager";
APPInfo appInfo = new APPInfo();
appInfo.setAppName("MyMessageManager");
appInfo.setAppIcon(R.drawable.ic_winboll);
appInfo.setAppDescription(getString(R.string.app_description));
appInfo.setAppGitName("WinBoLL");
appInfo.setAppGitOwner("Studio");
appInfo.setAppGitAPPBranch(branchName);
appInfo.setAppGitAPPSubProjectFolder(branchName);
appInfo.setAppHomePage("https://www.winboll.cc/apks/index.php?project=MyMessageManager");
appInfo.setAppAPKName("MyMessageManager");
appInfo.setAppAPKFolderName("MyMessageManager");
LogUtils.d(TAG, "genDefaultAppInfo: 应用信息已生成");
return appInfo;
}
}

View File

@@ -0,0 +1,170 @@
package cc.winboll.studio.mymessagemanager.activitys;
/**
* @Author ZhanGSKen<zhangsken@qq.com>
* @Date 2024/05/12 20:03:42
* @Describe 应用设置窗口
*/
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Switch;
import android.widget.Toast;
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
import cc.winboll.studio.libaes.views.AOHPCTCSeekBar;
import cc.winboll.studio.libaes.views.AToolbar;
import cc.winboll.studio.libappbase.ToastUtils;
import cc.winboll.studio.mymessagemanager.R;
import cc.winboll.studio.mymessagemanager.dialogs.CharsetRefuseEditDialog;
import cc.winboll.studio.mymessagemanager.utils.AppConfigUtil;
import cc.winboll.studio.mymessagemanager.utils.PermissionUtil;
public class AppSettingsActivity extends WinBoLLActivity implements IWinBoLLActivity {
public static final String TAG = "AppSettingsActivity";
// 讯飞语记官网下载页链接
private static final String XUNFEI_YUJI_DOWNLOAD_URL = "https://iflynote.com/h/share-download-app.html";
AppConfigUtil mAppConfigUtil;
AToolbar mAToolbar;
AOHPCTCSeekBar mAOHPCTCSeekBar;
EditText metTTSPlayDelayTimes;
EditText metPhoneMergePrefix;
Switch mswMergePrefixPhone;
Switch mswSMSRecycleProtectMode;
//EditText metProtectModerRefuseChars;
EditText metProtectModerReplaceChars;
String mszProtectModerRefuseChars = "";
RadioGroup mRadioGroupRecycleBin;
@Override
public Activity getActivity() {
return this;
}
@Override
public String getTag() {
return TAG;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_appsettings);
// 初始化属性
mAppConfigUtil = AppConfigUtil.getInstance(this);
int nTtsPlayDelayTimes = mAppConfigUtil.mAppConfigBean.getTtsPlayDelayTimes();
metTTSPlayDelayTimes = findViewById(R.id.activityappsettingsEditText1);
metTTSPlayDelayTimes.setText(Integer.toString(nTtsPlayDelayTimes / 1000));
// 初始化标题栏
mAToolbar = findViewById(R.id.activityappsettingsAToolbar1);
mAToolbar.setSubtitle(getString(R.string.activity_name_appsettings));
setActionBar(mAToolbar);
metPhoneMergePrefix = findViewById(R.id.activityappsettingsEditText2);
metPhoneMergePrefix.setText(mAppConfigUtil.mAppConfigBean.getCountryCode());
mswMergePrefixPhone = findViewById(R.id.activityappsettingsSwitch1);
mswMergePrefixPhone.setChecked(mAppConfigUtil.mAppConfigBean.isMergeCountryCodePrefix());
mswSMSRecycleProtectMode = findViewById(R.id.activityappsettingsSwitch3);
mswSMSRecycleProtectMode.setChecked(mAppConfigUtil.mAppConfigBean.isSMSRecycleProtectMode());
//metProtectModerRefuseChars = findViewById(R.id.activityappsettingsEditText3);
//metProtectModerRefuseChars.setText(mAppConfigUtil.mAppConfigBean.getProtectModerRefuseChars());
mszProtectModerRefuseChars = mAppConfigUtil.mAppConfigBean.getProtectModerRefuseChars();
metProtectModerReplaceChars = findViewById(R.id.activityappsettingsEditText4);
metProtectModerReplaceChars.setText(mAppConfigUtil.mAppConfigBean.getProtectModerReplaceChars());
mRadioGroupRecycleBin = findViewById(R.id.activityappsettingsRadioGroup1);
if (mAppConfigUtil.mAppConfigBean.getRecycleBinClass().equals("SMSRecycle2Activity")) {
mRadioGroupRecycleBin.check(R.id.activityappsettingsRadioButton2);
} else {
mRadioGroupRecycleBin.check(R.id.activityappsettingsRadioButton1);
}
mAOHPCTCSeekBar = findViewById(R.id.activityappsettingsAOHPCTCSeekBar1);
mAOHPCTCSeekBar.setThumb(getDrawable(R.drawable.cursor_pointer));
mAOHPCTCSeekBar.setThumbOffset(0);
mAOHPCTCSeekBar.setOnOHPCListener(new AOHPCTCSeekBar.OnOHPCListener(){
@Override
public void onOHPCommit() {
mAppConfigUtil.reLoadConfig();
mAppConfigUtil.mAppConfigBean.setIsSMSRecycleProtectMode(mswSMSRecycleProtectMode.isChecked());
if (mRadioGroupRecycleBin.getCheckedRadioButtonId() == R.id.activityappsettingsRadioButton2) {
mAppConfigUtil.mAppConfigBean.setRecycleBinClass("SMSRecycle2Activity");
} else {
mAppConfigUtil.mAppConfigBean.setRecycleBinClass("SMSRecycleActivity");
}
//mAppConfigUtil.mAppConfigBean.setProtectModerRefuseChars(metProtectModerRefuseChars.getText().toString());
mAppConfigUtil.mAppConfigBean.setProtectModerRefuseChars(mszProtectModerRefuseChars);
mAppConfigUtil.mAppConfigBean.setProtectModerReplaceChars(metProtectModerReplaceChars.getText().toString());
mAppConfigUtil.mAppConfigBean.setCountryCode(metPhoneMergePrefix.getText().toString());
mAppConfigUtil.mAppConfigBean.setIsMergeCountryCodePrefix(mswMergePrefixPhone.isChecked());
int nTtsPlayDelayTimes = 1000 * Integer.parseInt(metTTSPlayDelayTimes.getText().toString());
mAppConfigUtil.mAppConfigBean.setTtsPlayDelayTimes(nTtsPlayDelayTimes);
mAppConfigUtil.saveConfig();
Toast.makeText(getApplication(), "App config data is saved.", Toast.LENGTH_SHORT).show();
//LogUtils.d(TAG, "TTS Play Delay Times is setting to : " + Integer.toString(mAppConfigData.getTtsPlayDelayTimes()));Toast.makeText(getApplication(), "onOHPCommit", Toast.LENGTH_SHORT).show();
}
});
};
public void onOpenSystemDefaultAppSettings(View view) {
Intent intent = new Intent(Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS);
startActivity(intent);
}
public void onCheckAndGetAppPermission(View view) {
//LogUtils.d(TAG, "onCheckAndGetAppPermission");
if (PermissionUtil.checkAndGetAppPermission(this)) {
Toast.makeText(getApplication(), "应用已获得所需权限。", Toast.LENGTH_SHORT).show();
}
}
public void onAddTTSSupport(View view) {
try {
// 1. 创建IntentAction为“打开网页”
Intent intent = new Intent(Intent.ACTION_VIEW);
// 2. 设置要跳转的URL
intent.setData(Uri.parse(XUNFEI_YUJI_DOWNLOAD_URL));
// 3. 确保Intent可被解析避免无浏览器时崩溃
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent); // 跳转至浏览器打开下载页
} else {
// 无浏览器时的提示
Toast.makeText(this, "未找到浏览器应用,请安装后重试", Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(this, "无法打开下载页面,请稍后再试", Toast.LENGTH_SHORT).show();
}
}
public void onCharsetRefuseEditDialog(View view) {
CharsetRefuseEditDialog dlg = new CharsetRefuseEditDialog(this, new CharsetRefuseEditDialog.OnTextConfirmListener(){
@Override
public void onTextConfirmed(String editText) {
//ToastUtils.show(editText);
mszProtectModerRefuseChars = editText;
}
}, mszProtectModerRefuseChars);
dlg.show();
}
public void onTTSFloatSettingsActivity(View view) {
Intent intent = new Intent(this, TTSFloatSettingsActivity.class);
startActivity(intent);
}
}

View File

@@ -0,0 +1,368 @@
package cc.winboll.studio.mymessagemanager.activitys;
/**
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
* @Date 2025/08/30 14:32
* @Describe 联系人查询与短信发送窗口
*/
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toolbar;
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
import cc.winboll.studio.libaes.views.AOHPCTCSeekBar;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.libappbase.ToastUtils;
import cc.winboll.studio.mymessagemanager.R;
import cc.winboll.studio.mymessagemanager.beans.PhoneBean;
import cc.winboll.studio.mymessagemanager.utils.PhoneUtil;
import cc.winboll.studio.mymessagemanager.utils.SMSUtil;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.Activity;
public class ComposeSMSActivity extends WinBoLLActivity implements IWinBoLLActivity {
public static String TAG = "ComposeSMSActivity";
public static String EXTRA_SMSBODY = "sms_body";
private static final String MAP_NAME = "NAME";
private static final String MAP_PHONE = "PHONE";
private String mszSMSBody;
private String mszScheme;
private String mszPhoneTo;
private TextView mtvTOName;
private EditText metTONameSearch;
private EditText metTO;
private EditText metSMSBody;
private SimpleAdapter mSimpleAdapter;
private List<Map<String, Object>> mAdapterData = new ArrayList<Map<String, Object>>();
private ListView mlvContracts;
private List<PhoneBean> mListPhoneBeanContracts;
private Toolbar mToolbar;
private AOHPCTCSeekBar mAOHPCTCSeekBar;
private RelativeLayout mrlContracts;
@Override
public Activity getActivity() {
return this;
}
@Override
public String getTag() {
return TAG;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LogUtils.d(TAG, "onCreate");
setContentView(R.layout.activity_composesms);
// 初始化Intent数据增加空判断避免NullPointerException
Intent intent = getIntent();
if (intent != null) {
mszSMSBody = intent.getStringExtra(EXTRA_SMSBODY);
if (intent.getData() != null) {
mszScheme = intent.getData().getScheme();
mszPhoneTo = intent.getData().getSchemeSpecificPart();
}
}
// 校验启动方式非smsto则退出
if (mszScheme == null || !"smsto".equals(mszScheme)) {
ToastUtils.show("不支持的启动方式");
finish();
return;
}
initView();
initAdapter(null); // 初始加载所有联系人
setListViewPrePositionByPhone();
}
private void initView() {
// 初始化标题栏
mToolbar = (Toolbar) findViewById(R.id.activitycomposesmsASupportToolbar1);
mToolbar.setSubtitle(getString(R.string.activity_name_composesms));
setActionBar(mToolbar);
// 初始化联系人姓名显示和搜索栏
mtvTOName = (TextView) findViewById(R.id.activitycomposesmsTextView2);
mrlContracts = (RelativeLayout) findViewById(R.id.activitycomposesmsRelativeLayout1);
metTONameSearch = (EditText) findViewById(R.id.activitycomposesmsEditText2);
// 姓名搜索框文本变化监听
metTONameSearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
metTO.setText(""); // 清空号码输入框,避免冲突
String input = s == null ? "" : s.toString().trim();
if (input.isEmpty()) {
initAdapter(null); // 空搜索时显示所有联系人
} else {
setListViewPrePositionByName(); // 按姓名搜索
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// 无操作
}
@Override
public void afterTextChanged(Editable s) {
// 无操作
}
});
// 初始化联系人列表(关键:设置单选模式,确保选中状态生效)
mlvContracts = (ListView) findViewById(R.id.activitycomposesmsListView1);
mlvContracts.setChoiceMode(ListView.CHOICE_MODE_SINGLE); // 开启单选,与布局中一致
// 初始化号码输入框(核心:优化文本变化监听逻辑)
metTO = (EditText) findViewById(R.id.activitycomposesmsEditText1);
if (mszPhoneTo != null) {
metTO.setText(mszPhoneTo);
}
metTO.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
mtvTOName.setText(""); // 清空姓名显示
String inputPhone = s == null ? "" : s.toString().trim();
if (inputPhone.isEmpty()) {
// 输入为空时,显示所有联系人
initAdapter(null);
} else {
// 输入非空时,按号码搜索并更新列表(无结果则清空)
filterListByPhone(inputPhone);
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// 无操作
}
@Override
public void afterTextChanged(Editable s) {
// 无操作
}
});
// 初始化发送控件
mAOHPCTCSeekBar = (AOHPCTCSeekBar) findViewById(R.id.viewsmssendpart1AOHPCTCSeekBar1);
Drawable thumbDrawable = getResources().getDrawable(R.drawable.ic_message); // Java 7兼容写法
mAOHPCTCSeekBar.setThumb(thumbDrawable);
mAOHPCTCSeekBar.setThumbOffset(20);
mAOHPCTCSeekBar.setOnOHPCListener(new AOHPCTCSeekBar.OnOHPCListener() {
@Override
public void onOHPCommit() {
sendSMS();
}
});
// 初始化短信内容输入框
TextView tvAOHPCTCSeekBarMSG = (TextView) findViewById(R.id.viewsmssendpart1TextView1);
tvAOHPCTCSeekBarMSG.setText(R.string.msg_100sendmsg);
metSMSBody = (EditText) findViewById(R.id.viewsmssendpart1EditText1);
if (mszSMSBody != null) {
metSMSBody.setText(mszSMSBody);
}
}
// 核心优化:根据输入号码筛选列表(无结果则显示空列表,优化选中逻辑)
private void filterListByPhone(String inputPhone) {
PhoneUtil phoneUtil = new PhoneUtil(this);
List<PhoneBean> allContacts = phoneUtil.getPhoneList();
List<PhoneBean> matchedContacts = new ArrayList<PhoneBean>();
// 遍历所有联系人,匹配包含输入号码的联系人
for (PhoneBean contact : allContacts) {
if (contact.getTelPhone().contains(inputPhone)
|| phoneUtil.isTheSamePhoneNumber(contact.getTelPhone(), inputPhone)) {
matchedContacts.add(contact);
}
}
LogUtils.d(TAG, "号码搜索:输入'" + inputPhone + "', 匹配" + matchedContacts.size() + "个结果");
// 用筛选结果更新列表(无结果则传入空列表)
initAdapter(matchedContacts.isEmpty() ? new ArrayList<PhoneBean>() : matchedContacts);
// 定位并选中匹配项(如果有)
if (!matchedContacts.isEmpty()) {
boolean isFound = false;
for (int i = 0; i < matchedContacts.size(); i++) {
PhoneBean item = matchedContacts.get(i);
// 精确匹配号码(兼容区域码格式)
if (phoneUtil.isTheSamePhoneNumber(item.getTelPhone(), inputPhone)) {
mtvTOName.setText(item.getName());
// 关键:先滚动到目标位置,再设置选中状态
mlvContracts.setSelection(i);
// 主动设置选中(确保样式生效,兼容部分系统)
mlvContracts.setItemChecked(i, true);
LogUtils.d(TAG, String.format("%s 匹配 %s选中位置%d", inputPhone, item.getTelPhone(), i));
isFound = true;
break;
}
}
// 若未精确匹配,选中第一个结果
/*if (!isFound) {
mlvContracts.setSelection(0);
mlvContracts.setItemChecked(0, true);
mtvTOName.setText(matchedContacts.get(0).getName());
}*/
} else {
mtvTOName.setText(""); // 无结果时清空姓名显示
}
}
// 根据姓名搜索联系人
private void setListViewPrePositionByName() {
String searchName = metTONameSearch.getText().toString().trim();
PhoneUtil phoneUtil = new PhoneUtil(this);
List<PhoneBean> matchedContacts = phoneUtil.getPhonesByName(searchName);
initAdapter(matchedContacts);
if (!matchedContacts.isEmpty()) {
// 选中第一个结果并设置样式
mlvContracts.setSelection(0);
mlvContracts.setItemChecked(0, true);
}
}
// 初始定位号码对应的联系人
private void setListViewPrePositionByPhone() {
String inputPhone = metTO.getText().toString().trim();
if (inputPhone.isEmpty()) {
return;
}
filterListByPhone(inputPhone); // 复用筛选逻辑
}
// 获取号码匹配的位置(兼容旧逻辑)
private int getContractsDataPrePositionByPhone(String szPhone) {
if (mListPhoneBeanContracts == null || mListPhoneBeanContracts.isEmpty()) {
return 0;
}
for (int i = 0; i < mListPhoneBeanContracts.size(); i++) {
PhoneBean bean = mListPhoneBeanContracts.get(i);
if (bean.getTelPhone().compareTo(szPhone) >= 0) {
return i;
}
}
return 0;
}
// 获取姓名匹配的位置(兼容旧逻辑)
private int getContractsDataPrePositionByName(String szName) {
if (mListPhoneBeanContracts == null || mListPhoneBeanContracts.isEmpty()) {
return 0;
}
for (int i = 0; i < mListPhoneBeanContracts.size(); i++) {
if (mListPhoneBeanContracts.get(i).getName().startsWith(szName)) {
return i;
}
}
return 0;
}
// 初始化或更新列表适配器
private void initAdapter(List<PhoneBean> initData) {
mAdapterData.clear(); // 清空旧数据
final PhoneUtil phoneUtil = new PhoneUtil(this);
// 确定数据源:传入的筛选数据或所有联系人
if (initData != null) {
mListPhoneBeanContracts = initData;
} else {
mListPhoneBeanContracts = phoneUtil.getPhoneList();
}
// 转换数据为SimpleAdapter所需格式
if (mListPhoneBeanContracts != null) {
for (PhoneBean bean : mListPhoneBeanContracts) {
Map<String, Object> map = new HashMap<String, Object>();
map.put(MAP_NAME, bean.getName());
map.put(MAP_PHONE, bean.getTelPhone());
mAdapterData.add(map);
}
}
// 初始化或更新适配器
if (mSimpleAdapter == null) {
mSimpleAdapter = new SimpleAdapter(
ComposeSMSActivity.this,
mAdapterData,
R.layout.listview_contracts,
new String[]{MAP_NAME, MAP_PHONE},
new int[]{R.id.listviewcontractsTextView1, R.id.listviewcontractsTextView2}
);
mSimpleAdapter.setDropDownViewResource(R.layout.listview_contracts);
mlvContracts.setAdapter(mSimpleAdapter);
// 列表项点击事件:点击时主动设置选中状态,确保样式突显
mlvContracts.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (position < mAdapterData.size()) {
// 1. 主动设置当前项为选中状态
mlvContracts.setItemChecked(position, true);
// 2. 更新号码输入框和姓名显示
String phone = mAdapterData.get(position).get(MAP_PHONE).toString();
metTO.setText(phone);
mtvTOName.setText(phoneUtil.getNameByPhone(phone));
// 3. 滚动到点击位置(确保可见)
mlvContracts.setSelection(position);
}
}
});
// 列表项选中状态变化监听(可选,增强选中反馈)
mlvContracts.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// 未选中时无操作
}
});
} else {
// 数据更新时,先取消所有旧选中状态,再通知适配器刷新
mlvContracts.clearChoices();
mSimpleAdapter.notifyDataSetChanged();
}
}
// 发送短信逻辑
private void sendSMS() {
String phoneTo = metTO.getText().toString().trim();
if (phoneTo.isEmpty()) {
ToastUtils.show("没有设置接收号码。");
return;
}
String smsBody = metSMSBody.getText().toString().trim();
if (smsBody.isEmpty()) {
ToastUtils.show("没有消息内容可发送。");
return;
}
if (SMSUtil.sendMessageByInterface2(ComposeSMSActivity.this, phoneTo, smsBody)) {
finish();
}
}
}

Some files were not shown because too many files have changed in this diff Show More