Compare commits
222 Commits
apputils-v
...
appbase
| Author | SHA1 | Date | |
|---|---|---|---|
| 0bb70fae6e | |||
| 4b11f27d09 | |||
| 12dc8eef6b | |||
| 8930c43bcd | |||
| a138635cae | |||
| ad6d29c27e | |||
| 8aafcabba9 | |||
| fc34ed0d5a | |||
| d51d693120 | |||
| 350118301d | |||
| e47a64cc87 | |||
| 65161b1a80 | |||
| aa24bc5e11 | |||
| 1b24fc99ef | |||
| be6b7841ed | |||
| e4dc8109aa | |||
| d0e818056a | |||
| c744289896 | |||
| 375c5c1168 | |||
| 5d2d397113 | |||
| fdba61f30c | |||
| d87172a60d | |||
| 3e573076f5 | |||
| 2a31658cf8 | |||
| b0a0569b28 | |||
| 27deec8bf0 | |||
| 8cfa83d025 | |||
| 6376bb7502 | |||
| f16b1bf74e | |||
| 962f64b689 | |||
| 896401f00a | |||
| 0876efc5ec | |||
| 51575a7b62 | |||
| a8a51c836e | |||
| 5996a9306e | |||
| f4f4768bfc | |||
| 5a9a138463 | |||
| ae601c1445 | |||
| c5cd274b0f | |||
| 07a53da918 | |||
| d52c87cacb | |||
| 6e32f0539d | |||
| 2aaf18f29f | |||
| 9892f3de2d | |||
|
|
c06a325c42 | ||
|
|
7897100659 | ||
|
|
51793077bd | ||
| ada29fb2b4 | |||
|
|
306f62f7ca | ||
|
|
50e2bd375d | ||
| 7d73845a28 | |||
| 052e8e8b82 | |||
|
|
e590928e67 | ||
|
|
8346eed8f4 | ||
|
|
2bde16523e | ||
|
|
0a34a90acc | ||
| 0f5d2cb34e | |||
|
|
9cec7bccdc | ||
|
|
faf8c39fe9 | ||
| 2480c8c1f0 | |||
|
|
81950699b3 | ||
| 47ea47cddc | |||
|
|
2404a9c532 | ||
| f039d798ae | |||
| 781d490667 | |||
|
|
2b8a026c0c | ||
|
|
82518af2d6 | ||
|
|
bb98d6bb1b | ||
|
|
230038f6f3 | ||
|
|
f8980446a8 | ||
|
|
643b84aece | ||
|
|
05850394ed | ||
|
|
2f1c4a5cc1 | ||
|
|
bec55fd51a | ||
|
|
e01fb0460f | ||
| e46fccf504 | |||
|
|
e6183780b3 | ||
| 74a1ef7fd3 | |||
| 1414c902d0 | |||
|
|
f7b30bebc0 | ||
| 564289a114 | |||
| a08daf142b | |||
|
|
bb1f3fba30 | ||
|
|
1aaf7ef639 | ||
| 66549aea4d | |||
| 7c6b215d89 | |||
|
|
042e25a3dc | ||
|
|
e2410531ab | ||
| b1bf37b859 | |||
|
|
93891313b3 | ||
|
|
2db3f2b872 | ||
| 1fb91e9bfa | |||
| 7e50147d0b | |||
|
|
6e469b2c18 | ||
|
|
f26c1ed0ef | ||
|
|
23ba2bdf0c | ||
|
|
53c871d61d | ||
| cb81e6e9e4 | |||
|
|
e53df4e5e9 | ||
|
|
25c7269029 | ||
|
|
8b290ebc3f | ||
| 4af10c74e9 | |||
|
|
7883ef93be | ||
|
|
398cb33a58 | ||
|
|
ac1858fba7 | ||
|
|
5a77a5e9e0 | ||
| fb7a372f29 | |||
| c3dbae9edb | |||
|
|
b93434887d | ||
| dc5a28dbef | |||
| 6371476f55 | |||
|
|
f7a273b2d4 | ||
|
|
56e5204379 | ||
|
|
0f08cf59ea | ||
|
|
8e8359aab4 | ||
|
|
c063175bd6 | ||
|
|
cb15fe5eb0 | ||
|
|
fbf5ceadc7 | ||
|
|
e6ce490436 | ||
|
|
6ddb599e6c | ||
|
|
f332abaa05 | ||
|
|
935dba200e | ||
|
|
02c9776062 | ||
|
|
dfc8de83d7 | ||
|
|
a34e3e1633 | ||
|
|
5dc87361cc | ||
| 74240104b9 | |||
| 1d0a9e468b | |||
| f943db17e0 | |||
|
|
d7a9cb2a20 | ||
| de34c33706 | |||
|
|
10b8da2e21 | ||
|
|
ca4e4c7feb | ||
| 4108371c20 | |||
|
|
e5c8624d9b | ||
| 561330697b | |||
|
|
f7b2c0d4c0 | ||
|
|
c3978a1e3c | ||
| 7e061d18bb | |||
|
|
0afe1de9bd | ||
|
|
98874bedc9 | ||
|
|
72cbe4f066 | ||
| b144d6d94c | |||
|
|
da7329ffb3 | ||
| 9511b594aa | |||
|
|
46ede050e1 | ||
|
|
269e7b30be | ||
|
|
ca953adec2 | ||
|
|
916e807f1b | ||
|
|
1f57ac5401 | ||
|
|
1ba19d8f77 | ||
|
|
435f7ced79 | ||
|
|
bd3270f8dd | ||
|
|
5489977a1a | ||
| 0bb909427c | |||
|
|
d4f054a86b | ||
| caef679d9a | |||
|
|
5194d7a188 | ||
| a0f88a423a | |||
|
|
81b5141608 | ||
| 3a1eaaf92d | |||
|
|
ddda54bd75 | ||
|
|
829268a9cc | ||
|
|
70a5405077 | ||
|
|
894edd5fa4 | ||
|
|
cf6209e2b4 | ||
|
|
80424c523d | ||
|
|
f5b2500f06 | ||
| ff8d09fb00 | |||
|
|
236339d256 | ||
|
|
edaf7007d6 | ||
|
|
12f4fd3f45 | ||
|
|
f7d9478f9e | ||
|
|
6ba57089cd | ||
|
|
94054c39e8 | ||
|
|
dee9586748 | ||
|
|
72ba518c6d | ||
| eccf9b9bde | |||
|
|
14abd9edd8 | ||
| fbd6f70b36 | |||
| 4ddc187b58 | |||
|
|
047de2bd1b | ||
|
|
0ede961391 | ||
|
|
33d4a1f0bb | ||
|
|
5c05eb62ff | ||
| c30588f174 | |||
| b5ccbd09f4 | |||
|
|
d8a6049abb | ||
|
|
efe0a0f136 | ||
| 8e15c82129 | |||
| 44fc3b1899 | |||
|
|
cdb9d8d41b | ||
| 3eeb808e07 | |||
| 56a3e12521 | |||
|
|
6ce48c8881 | ||
| eb0881ae6b | |||
|
|
51b6179df6 | ||
|
|
1ee069afca | ||
|
|
f32563b906 | ||
| 5cb6309134 | |||
| 27f84d9e18 | |||
|
|
3e8dde50ec | ||
|
|
ce131235c1 | ||
|
|
58369560b9 | ||
| 5e198d9c68 | |||
|
|
963a3bb7cd | ||
|
|
fd0315d3cf | ||
| e9bb789daa | |||
| dbff19e7f4 | |||
|
|
44679d0c8a | ||
| eb8d37c340 | |||
|
|
d65a839878 | ||
| c1af20009a | |||
|
|
cb3796bfea | ||
| 6656161903 | |||
|
|
0411d564b9 | ||
|
|
cc365f979e | ||
|
|
6435bd28ac | ||
|
|
9b190e7dfa | ||
|
|
e7f2263860 | ||
|
|
e7b5cfd9b8 | ||
|
|
a4b7c59919 |
@@ -28,12 +28,17 @@ android {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
|
||||||
signingConfig signingConfigs.winboll
|
|
||||||
}
|
|
||||||
debug {
|
debug {
|
||||||
signingConfig signingConfigs.winboll
|
signingConfig signingConfigs.winboll
|
||||||
}
|
}
|
||||||
|
release {
|
||||||
|
signingConfig signingConfigs.winboll
|
||||||
|
minifyEnabled true // 开启混淆(核心开关)
|
||||||
|
shrinkResources true // 可选:移除无用资源(进一步减小体积)
|
||||||
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), // 官方默认规则(优化版)
|
||||||
|
'proguard-rules.pro' // 自定义规则文件
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
flavorDimensions "WinBoLLApp"
|
flavorDimensions "WinBoLLApp"
|
||||||
@@ -71,6 +76,7 @@ android {
|
|||||||
// 2. 配置 Beta Debug 版应用包输出
|
// 2. 配置 Beta Debug 版应用包输出
|
||||||
//
|
//
|
||||||
if((variant.flavorName == "beta" && variant.buildType.name == "debug")
|
if((variant.flavorName == "beta" && variant.buildType.name == "debug")
|
||||||
|
|| (variant.flavorName == "beta" && variant.buildType.name == "release")
|
||||||
|| (variant.flavorName == "stage" && variant.buildType.name == "debug")
|
|| (variant.flavorName == "stage" && variant.buildType.name == "debug")
|
||||||
|| (variant.flavorName == "stage" && variant.buildType.name == "release")) {
|
|| (variant.flavorName == "stage" && variant.buildType.name == "release")) {
|
||||||
println "Project root directory: " + project.rootDir.toString()
|
println "Project root directory: " + project.rootDir.toString()
|
||||||
|
|||||||
@@ -3,8 +3,11 @@
|
|||||||
|
|
||||||
########
|
########
|
||||||
## ☁ ☁ ☁ WinBoLL APP ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁
|
## ☁ ☁ ☁ WinBoLL APP ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁
|
||||||
# ☁ ☁ WinBoLL Studio Android 应用开源项目。☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁
|
# ☁ ☁ WinBoLL Studio Android 应用开源项目。☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁
|
||||||
# ☁ ☁ ☁ WinBoLL 网站地址 https://www.winboll.cc/ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁
|
# ☁ ☁ ☁ WinBoLL 网站地址 https://www.winboll.cc/ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁
|
||||||
|
# ☁ ☁ ☁ WinBoLL 源码地址 <https://gitea.winboll.cc/Studio/APPBase> ☁ ☁ ☁ ☁ ☁ ☁ ☁
|
||||||
|
# ☁ ☁ ☁ GitHub 源码地址 <https://github.com/ZhanGSKen/APPBase.git> ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁
|
||||||
|
# ☁ ☁ ☁ 码云 源码地址 <https://gitee.com/zhangsken/appbase.git> ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁
|
||||||
|
|
||||||
## WinBoLL 提问
|
## WinBoLL 提问
|
||||||
同样是 /sdcard 目录,在开发 Android 应用时,
|
同样是 /sdcard 目录,在开发 Android 应用时,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# AES
|
# AES
|
||||||
|
|
||||||
#### 介绍
|
#### 介绍
|
||||||
安卓视图元素类库
|
WinBoLL 安卓可视化元素类库测试应用。
|
||||||
|
|
||||||
#### 软件架构
|
#### 软件架构
|
||||||
适配安卓应用 [AIDE Pro] 的 Gradle 编译结构。
|
适配安卓应用 [AIDE Pro] 的 Gradle 编译结构。
|
||||||
@@ -32,4 +32,4 @@
|
|||||||
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
|
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
|
||||||
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
||||||
|
|
||||||
#### 参考文档
|
#### 参考文档
|
||||||
|
|||||||
@@ -18,28 +18,30 @@ def genVersionName(def versionName){
|
|||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 32
|
|
||||||
buildToolsVersion "32.0.0"
|
// 1. compileSdkVersion:必须 ≥ targetSdkVersion,建议直接等于 targetSdkVersion(30)
|
||||||
|
compileSdkVersion 30
|
||||||
|
|
||||||
|
// 2. buildToolsVersion:需匹配 compileSdkVersion,建议使用 30.x.x 最新稳定版(无需高于 compileSdkVersion)
|
||||||
|
buildToolsVersion "30.0.3" // 这是 30 对应的最新稳定版,避免使用 beta 版
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "cc.winboll.studio.aes"
|
applicationId "cc.winboll.studio.aes"
|
||||||
minSdkVersion 24
|
minSdkVersion 23
|
||||||
targetSdkVersion 30
|
targetSdkVersion 30
|
||||||
versionCode 1
|
versionCode 1
|
||||||
// versionName 更新后需要手动设置
|
// versionName 更新后需要手动设置
|
||||||
// 项目模块目录的 build.gradle 文件的 stageCount=0
|
// 项目模块目录的 build.gradle 文件的 stageCount=0
|
||||||
// Gradle编译环境下合起来的 versionName 就是 "${versionName}.0"
|
// Gradle编译环境下合起来的 versionName 就是 "${versionName}.0"
|
||||||
versionName "15.9"
|
versionName "15.11"
|
||||||
if(true) {
|
if(true) {
|
||||||
versionName = genVersionName("${versionName}")
|
versionName = genVersionName("${versionName}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buildTypes {
|
// 米盟 SDK
|
||||||
release {
|
packagingOptions {
|
||||||
minifyEnabled false
|
doNotStrip "*/*/libmimo_1011.so"
|
||||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Sun Aug 31 23:40:17 HKT 2025
|
#Wed Nov 26 15:54:26 GMT 2025
|
||||||
stageCount=4
|
stageCount=7
|
||||||
libraryProject=libaes
|
libraryProject=libaes
|
||||||
baseVersion=15.9
|
baseVersion=15.11
|
||||||
publishVersion=15.9.3
|
publishVersion=15.11.6
|
||||||
buildCount=0
|
buildCount=32
|
||||||
baseBetaVersion=15.9.4
|
baseBetaVersion=15.11.7
|
||||||
|
|||||||
132
aes/proguard-rules.pro
vendored
132
aes/proguard-rules.pro
vendored
@@ -9,9 +9,129 @@
|
|||||||
|
|
||||||
# Add any project specific keep options here:
|
# 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:
|
-keep public class * extends android.app.Activity
|
||||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
-keep public class * extends android.app.Service
|
||||||
# public *;
|
-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.**
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,10 @@
|
|||||||
|
|
||||||
<activity android:name=".AboutActivity"/>
|
<activity android:name=".AboutActivity"/>
|
||||||
|
|
||||||
|
<activity android:name=".TestActivityManagerActivity"/>
|
||||||
|
|
||||||
|
<activity android:name=".SettingsActivity"/>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -12,18 +12,18 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
import cc.winboll.studio.libaes.winboll.APPInfo;
|
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
|
||||||
import cc.winboll.studio.libaes.winboll.AboutView;
|
import cc.winboll.studio.libaes.models.APPInfo;
|
||||||
import cc.winboll.studio.libappbase.GlobalApplication;
|
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
|
||||||
import cc.winboll.studio.libappbase.winboll.IWinBoLLActivity;
|
import cc.winboll.studio.libaes.views.AboutView;
|
||||||
|
|
||||||
public class AboutActivity extends AppCompatActivity implements IWinBoLLActivity {
|
public class AboutActivity extends WinBoLLActivity implements IWinBoLLActivity {
|
||||||
|
|
||||||
public static final String TAG = "AboutActivity";
|
public static final String TAG = "AboutActivity";
|
||||||
|
|
||||||
Context mContext;
|
Context mContext;
|
||||||
Toolbar mToolbar;
|
Toolbar mToolbar;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Activity getActivity() {
|
public Activity getActivity() {
|
||||||
return this;
|
return this;
|
||||||
@@ -33,7 +33,7 @@ public class AboutActivity extends AppCompatActivity implements IWinBoLLActivity
|
|||||||
public String getTag() {
|
public String getTag() {
|
||||||
return TAG;
|
return TAG;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@@ -64,13 +64,13 @@ public class AboutActivity extends AppCompatActivity implements IWinBoLLActivity
|
|||||||
);
|
);
|
||||||
layout.addView(aboutView, params);
|
layout.addView(aboutView, params);
|
||||||
|
|
||||||
GlobalApplication.getWinBoLLActivityManager().add(this);
|
WinBoLLActivityManager.getInstance().add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
GlobalApplication.getWinBoLLActivityManager().registeRemove(this);
|
WinBoLLActivityManager.getInstance().registeRemove(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AboutView CreateAboutView() {
|
public AboutView CreateAboutView() {
|
||||||
@@ -83,11 +83,11 @@ public class AboutActivity extends AppCompatActivity implements IWinBoLLActivity
|
|||||||
appInfo.setAppGitOwner("Studio");
|
appInfo.setAppGitOwner("Studio");
|
||||||
appInfo.setAppGitAPPBranch(szBranchName);
|
appInfo.setAppGitAPPBranch(szBranchName);
|
||||||
appInfo.setAppGitAPPSubProjectFolder(szBranchName);
|
appInfo.setAppGitAPPSubProjectFolder(szBranchName);
|
||||||
appInfo.setAppHomePage("https://discuz.winboll.cc/forum.php?mod=viewthread&tid=3&extra=page%3D1");
|
appInfo.setAppHomePage("https://www.winboll.cc/apks/index.php?project=AES");
|
||||||
appInfo.setAppAPKName("AES");
|
appInfo.setAppAPKName("AES");
|
||||||
appInfo.setAppAPKFolderName("AES");
|
appInfo.setAppAPKFolderName("AES");
|
||||||
//appInfo.setIsAddDebugTools(false);
|
//appInfo.setIsAddDebugTools(false);
|
||||||
appInfo.setIsAddDebugTools(BuildConfig.DEBUG);
|
//appInfo.setIsAddDebugTools(BuildConfig.DEBUG);
|
||||||
return new AboutView(mContext, appInfo);
|
return new AboutView(mContext, appInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ package cc.winboll.studio.aes;
|
|||||||
* @Describe AES应用类
|
* @Describe AES应用类
|
||||||
*/
|
*/
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
|
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
|
||||||
import cc.winboll.studio.libappbase.GlobalApplication;
|
import cc.winboll.studio.libappbase.GlobalApplication;
|
||||||
import com.hjq.toast.ToastUtils;
|
import cc.winboll.studio.libappbase.ToastUtils;
|
||||||
import com.hjq.toast.style.WhiteToastStyle;
|
|
||||||
|
|
||||||
|
|
||||||
public class App extends GlobalApplication {
|
public class App extends GlobalApplication {
|
||||||
@@ -18,14 +18,16 @@ public class App extends GlobalApplication {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
setIsDebugging(BuildConfig.DEBUG);
|
||||||
|
WinBoLLActivityManager.init(this);
|
||||||
|
|
||||||
// 初始化 Toast 框架
|
// 初始化 Toast 框架
|
||||||
ToastUtils.init(this);
|
ToastUtils.init(this);
|
||||||
// 设置 Toast 布局样式
|
|
||||||
//ToastUtils.setView(R.layout.view_toast);
|
|
||||||
ToastUtils.setStyle(new WhiteToastStyle());
|
|
||||||
ToastUtils.setGravity(Gravity.BOTTOM, 0, 200);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTerminate() {
|
||||||
|
super.onTerminate();
|
||||||
|
ToastUtils.release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,9 +15,10 @@ import android.widget.AdapterView;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import cc.winboll.studio.aes.R;
|
import cc.winboll.studio.aes.R;
|
||||||
import cc.winboll.studio.libaes.activitys.DrawerFragmentActivity;
|
import cc.winboll.studio.libaes.activitys.DrawerFragmentActivity;
|
||||||
import cc.winboll.studio.libaes.beans.DrawerMenuBean;
|
|
||||||
import cc.winboll.studio.libaes.dialogs.LocalFileSelectDialog;
|
import cc.winboll.studio.libaes.dialogs.LocalFileSelectDialog;
|
||||||
import cc.winboll.studio.libaes.dialogs.StoragePathDialog;
|
import cc.winboll.studio.libaes.dialogs.StoragePathDialog;
|
||||||
|
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
|
||||||
|
import cc.winboll.studio.libaes.models.DrawerMenuBean;
|
||||||
import cc.winboll.studio.libaes.unittests.SecondaryLibraryActivity;
|
import cc.winboll.studio.libaes.unittests.SecondaryLibraryActivity;
|
||||||
import cc.winboll.studio.libaes.unittests.TestAButtonFragment;
|
import cc.winboll.studio.libaes.unittests.TestAButtonFragment;
|
||||||
import cc.winboll.studio.libaes.unittests.TestASupportToolbarActivity;
|
import cc.winboll.studio.libaes.unittests.TestASupportToolbarActivity;
|
||||||
@@ -25,10 +26,10 @@ import cc.winboll.studio.libaes.unittests.TestAToolbarActivity;
|
|||||||
import cc.winboll.studio.libaes.unittests.TestDrawerFragmentActivity;
|
import cc.winboll.studio.libaes.unittests.TestDrawerFragmentActivity;
|
||||||
import cc.winboll.studio.libaes.unittests.TestViewPageFragment;
|
import cc.winboll.studio.libaes.unittests.TestViewPageFragment;
|
||||||
import cc.winboll.studio.libappbase.LogUtils;
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
import cc.winboll.studio.libappbase.winboll.IWinBoLLActivity;
|
import cc.winboll.studio.libappbase.ToastUtils;
|
||||||
import com.a4455jkjh.colorpicker.ColorPickerDialog;
|
import com.a4455jkjh.colorpicker.ColorPickerDialog;
|
||||||
import com.hjq.toast.ToastUtils;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
|
||||||
|
|
||||||
public class MainActivity extends DrawerFragmentActivity implements IWinBoLLActivity {
|
public class MainActivity extends DrawerFragmentActivity implements IWinBoLLActivity {
|
||||||
|
|
||||||
@@ -89,9 +90,9 @@ public class MainActivity extends DrawerFragmentActivity implements IWinBoLLActi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
getMenuInflater().inflate(R.menu.toolbar_library, menu);
|
getMenuInflater().inflate(R.menu.toolbar_main, menu);
|
||||||
if(App.isDebuging()) {
|
if(App.isDebugging()) {
|
||||||
getMenuInflater().inflate(cc.winboll.studio.libapputils.R.menu.toolbar_studio_debug, menu);
|
getMenuInflater().inflate(cc.winboll.studio.libaes.R.menu.toolbar_studio_debug, menu);
|
||||||
}
|
}
|
||||||
return super.onCreateOptionsMenu(menu);
|
return super.onCreateOptionsMenu(menu);
|
||||||
}
|
}
|
||||||
@@ -122,9 +123,10 @@ public class MainActivity extends DrawerFragmentActivity implements IWinBoLLActi
|
|||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
int nItemId = item.getItemId();
|
int nItemId = item.getItemId();
|
||||||
// if (item.getItemId() == R.id.item_log) {
|
if (item.getItemId() == R.id.item_testactivitymanager) {
|
||||||
// WinBoLLActivityManager.getInstance(this).startWinBoLLActivity(getApplicationContext(), LogActivity.class);
|
WinBoLLActivityManager.getInstance().startWinBoLLActivity(this, TestActivityManagerActivity.class);
|
||||||
// } else
|
//ToastUtils.show("item_testactivitymanager");
|
||||||
|
} else
|
||||||
if (nItemId == R.id.item_atoast) {
|
if (nItemId == R.id.item_atoast) {
|
||||||
Toast.makeText(getApplication(), "item_testatoast", Toast.LENGTH_SHORT).show();
|
Toast.makeText(getApplication(), "item_testatoast", Toast.LENGTH_SHORT).show();
|
||||||
} else if (nItemId == R.id.item_atoolbar) {
|
} else if (nItemId == R.id.item_atoolbar) {
|
||||||
@@ -183,8 +185,10 @@ public class MainActivity extends DrawerFragmentActivity implements IWinBoLLActi
|
|||||||
} else if (nItemId == R.id.item_drawerfragmentactivity) {
|
} else if (nItemId == R.id.item_drawerfragmentactivity) {
|
||||||
Intent intent = new Intent(this, TestDrawerFragmentActivity.class);
|
Intent intent = new Intent(this, TestDrawerFragmentActivity.class);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
} else if (nItemId == R.id.item_settings) {
|
||||||
else if (nItemId == R.id.item_about) {
|
Intent intent = new Intent(this, SettingsActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
} else if (nItemId == R.id.item_about) {
|
||||||
Intent intent = new Intent(this, AboutActivity.class);
|
Intent intent = new Intent(this, AboutActivity.class);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package cc.winboll.studio.aes;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import cc.winboll.studio.libaes.enums.ADsMode;
|
||||||
|
import cc.winboll.studio.libaes.views.ADsControlView;
|
||||||
|
import cc.winboll.studio.libappbase.ToastUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||||
|
* @Date 2025/11/26 18:01
|
||||||
|
* @Describe SettingsActivity
|
||||||
|
*/
|
||||||
|
public class SettingsActivity extends Activity {
|
||||||
|
|
||||||
|
public static final String TAG = "SettingsActivity";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_settings);
|
||||||
|
ADsControlView adsControlView = (ADsControlView) findViewById(R.id.ads_control_view);
|
||||||
|
|
||||||
|
// adsControlView.setOnAdsModeSelectedListener(new ADsControlView.OnAdsModeSelectedListener() {
|
||||||
|
// @Override
|
||||||
|
// public void onModeSelected(ADsMode selectedMode) {
|
||||||
|
// if (selectedMode == ADsMode.STANDALONE) {
|
||||||
|
// // 处理单机模式逻辑(如释放米盟资源)
|
||||||
|
// ToastUtils.show("STANDALONE");
|
||||||
|
// } else if (selectedMode == ADsMode.MIMO_SDK) {
|
||||||
|
// // 处理米盟SDK模式逻辑(如初始化SDK)
|
||||||
|
// ToastUtils.show("MIMO_SDK");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package cc.winboll.studio.aes;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||||
|
* @Date 2025/09/28 21:07
|
||||||
|
* @Describe 窗口管理类测试窗口
|
||||||
|
*/
|
||||||
|
public class TestActivityManagerActivity extends WinBoLLActivity implements IWinBoLLActivity {
|
||||||
|
|
||||||
|
public static final String TAG = "TestActivityManagerActivity";
|
||||||
|
|
||||||
|
@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_testactivitymanager);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
60
aes/src/main/java/cc/winboll/studio/aes/WinBoLLActivity.java
Normal file
60
aes/src/main/java/cc/winboll/studio/aes/WinBoLLActivity.java
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
package cc.winboll.studio.aes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||||
|
* @Date 2025/09/29 00:11
|
||||||
|
* @Describe WinBoLL 窗口基础类
|
||||||
|
*/
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
|
||||||
|
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
|
||||||
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
|
|
||||||
|
public class WinBoLLActivity extends AppCompatActivity implements IWinBoLLActivity {
|
||||||
|
|
||||||
|
public static final String TAG = "WinBoLLActivity";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Activity getActivity() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTag() {
|
||||||
|
return TAG;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
LogUtils.d(TAG, String.format("onResume %s", getTag()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
/*if (item.getItemId() == R.id.item_log) {
|
||||||
|
WinBoLLActivityManager.getInstance().startLogActivity(this);
|
||||||
|
return true;
|
||||||
|
} else if (item.getItemId() == R.id.item_home) {
|
||||||
|
startActivity(new Intent(this, MainActivity.class));
|
||||||
|
return true;
|
||||||
|
}*/
|
||||||
|
// 在switch语句中处理每个ID,并在处理完后返回true,未处理的情况返回false。
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostCreate(Bundle savedInstanceState) {
|
||||||
|
super.onPostCreate(savedInstanceState);
|
||||||
|
WinBoLLActivityManager.getInstance().add(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
WinBoLLActivityManager.getInstance().registeRemove(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
12
aes/src/main/res/layout/activity_settings.xml
Normal file
12
aes/src/main/res/layout/activity_settings.xml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
<cc.winboll.studio.libaes.views.ADsControlView
|
||||||
|
android:id="@+id/ads_control_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
</LinearLayout>
|
||||||
15
aes/src/main/res/layout/activity_testactivitymanager.xml
Normal file
15
aes/src/main/res/layout/activity_testactivitymanager.xml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="窗口管理类测试窗口"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item
|
||||||
|
android:id="@+id/item_testactivitymanager"
|
||||||
|
android:title="TestActivityManager"/>
|
||||||
<item
|
<item
|
||||||
android:id="@+id/item_log"
|
android:id="@+id/item_log"
|
||||||
android:title="LogActivity"/>
|
android:title="LogActivity"/>
|
||||||
@@ -29,4 +32,7 @@
|
|||||||
<item
|
<item
|
||||||
android:id="@+id/item_drawerfragmentactivity"
|
android:id="@+id/item_drawerfragmentactivity"
|
||||||
android:title="Test DrawerFragmentActivity"/>
|
android:title="Test DrawerFragmentActivity"/>
|
||||||
|
<item
|
||||||
|
android:id="@+id/item_settings"
|
||||||
|
android:title="Settings"/>
|
||||||
</menu>
|
</menu>
|
||||||
@@ -19,29 +19,31 @@ def genVersionName(def versionName){
|
|||||||
|
|
||||||
android {
|
android {
|
||||||
|
|
||||||
compileSdkVersion 32
|
// 1. compileSdkVersion:必须 ≥ targetSdkVersion,建议直接等于 targetSdkVersion(30)
|
||||||
buildToolsVersion "32.0.0"
|
compileSdkVersion 30
|
||||||
|
|
||||||
|
// 2. buildToolsVersion:需匹配 compileSdkVersion,建议使用 30.x.x 最新稳定版(无需高于 compileSdkVersion)
|
||||||
|
buildToolsVersion "30.0.3" // 这是 30 对应的最新稳定版,避免使用 beta 版
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "cc.winboll.studio.appbase"
|
applicationId "cc.winboll.studio.appbase"
|
||||||
minSdkVersion 24
|
minSdkVersion 23
|
||||||
targetSdkVersion 30
|
targetSdkVersion 30
|
||||||
versionCode 1
|
versionCode 1
|
||||||
// versionName 更新后需要手动设置
|
// versionName 更新后需要手动设置
|
||||||
// .winboll/winbollBuildProps.properties 文件的 stageCount=0
|
// .winboll/winbollBuildProps.properties 文件的 stageCount=0
|
||||||
// Gradle编译环境下合起来的 versionName 就是 "${versionName}.0"
|
// Gradle编译环境下合起来的 versionName 就是 "${versionName}.0"
|
||||||
versionName "15.10"
|
versionName "15.11"
|
||||||
if(true) {
|
if(true) {
|
||||||
versionName = genVersionName("${versionName}")
|
versionName = genVersionName("${versionName}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buildTypes {
|
// 确保 Java 7 兼容性(已适配项目技术栈)
|
||||||
release {
|
compileOptions {
|
||||||
minifyEnabled false
|
sourceCompatibility JavaVersion.VERSION_1_7
|
||||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
targetCompatibility JavaVersion.VERSION_1_7
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Mon Sep 22 06:01:08 HKT 2025
|
#Sun Nov 30 17:13:07 HKT 2025
|
||||||
stageCount=8
|
stageCount=7
|
||||||
libraryProject=libappbase
|
libraryProject=libappbase
|
||||||
baseVersion=15.10
|
baseVersion=15.11
|
||||||
publishVersion=15.10.7
|
publishVersion=15.11.6
|
||||||
buildCount=0
|
buildCount=0
|
||||||
baseBetaVersion=15.10.8
|
baseBetaVersion=15.11.7
|
||||||
|
|||||||
109
appbase/proguard-rules.pro
vendored
109
appbase/proguard-rules.pro
vendored
@@ -15,3 +15,112 @@
|
|||||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||||
# public *;
|
# public *;
|
||||||
#}
|
#}
|
||||||
|
|
||||||
|
# ============================== 基础通用规则 ==============================
|
||||||
|
# 保留系统组件
|
||||||
|
-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 public class * extends com.winboll.WinBoLLActivity
|
||||||
|
#-keep public class * extends com.winboll.WinBoLLFragment
|
||||||
|
# 主包名
|
||||||
|
-keep class cc.winboll.studio.*.** { *; }
|
||||||
|
# beta包名
|
||||||
|
-keep class cc.winboll.studio.*.beta.** { *; }
|
||||||
|
-keepclassmembers class cc.winboll.studio.*.** { *; }
|
||||||
|
-keepclassmembers class cc.winboll.studio.*.beta.** { *; }
|
||||||
|
|
||||||
|
# 保留所有类中的 public static final String TAG 字段
|
||||||
|
-keepclassmembers class * {
|
||||||
|
public static final java.lang.String TAG;
|
||||||
|
}
|
||||||
|
|
||||||
|
# 保留序列化类
|
||||||
|
-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 文件
|
||||||
|
-keepclassmembers class **.R$* {
|
||||||
|
public static <fields>;
|
||||||
|
}
|
||||||
|
|
||||||
|
# 保留 native 方法
|
||||||
|
-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.**
|
||||||
|
|
||||||
|
# ============================== 第三方框架规则 ==============================
|
||||||
|
# Retrofit + OkHttp
|
||||||
|
-keep class retrofit2.** { *; }
|
||||||
|
-keep interface retrofit2.** { *; }
|
||||||
|
-keep class okhttp3.** { *; }
|
||||||
|
-keep interface okhttp3.** { *; }
|
||||||
|
-keep class okio.** { *; }
|
||||||
|
-keepclasseswithmembers class * {
|
||||||
|
@retrofit2.http.* <methods>;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Glide 4.x
|
||||||
|
-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 *;
|
||||||
|
}
|
||||||
|
-dontwarn com.bumptech.glide.load.resource.bitmap.VideoDecoder
|
||||||
|
|
||||||
|
# GreenDAO 3.x
|
||||||
|
-keepclassmembers class * extends org.greenrobot.greendao.AbstractDao {
|
||||||
|
public static java.lang.String TABLENAME;
|
||||||
|
}
|
||||||
|
-keep class **$Properties
|
||||||
|
# 实体类包名(按实际调整)
|
||||||
|
#-keep class cc.winboll.studio.appbase.model.** { *; }
|
||||||
|
|
||||||
|
# ButterKnife 8.x
|
||||||
|
-keep class butterknife.** { *; }
|
||||||
|
-dontwarn butterknife.internal.**
|
||||||
|
-keep class **$$ViewBinder { *; }
|
||||||
|
-keepclasseswithmembernames class * {
|
||||||
|
@butterknife.BindView <fields>;
|
||||||
|
@butterknife.OnClick <methods>;
|
||||||
|
}
|
||||||
|
|
||||||
|
# EventBus 3.x
|
||||||
|
-keepclassmembers class ** {
|
||||||
|
@org.greenrobot.eventbus.Subscribe <methods>;
|
||||||
|
}
|
||||||
|
-keep enum org.greenrobot.eventbus.ThreadMode { *; }
|
||||||
|
|
||||||
|
# ============================== 优化与调试 ==============================
|
||||||
|
-optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*
|
||||||
|
-optimizationpasses 5
|
||||||
|
-verbose
|
||||||
|
-dontpreverify
|
||||||
|
-dontusemixedcaseclassnames
|
||||||
|
# 保留行号(便于崩溃定位)
|
||||||
|
-keepattributes SourceFile,LineNumberTable
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,7 @@
|
|||||||
<manifest
|
<manifest
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="cc.winboll.studio.appbase">
|
package="cc.winboll.studio.appbase">
|
||||||
|
|
||||||
<!-- 网络权限 -->
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name=".App"
|
android:name=".App"
|
||||||
android:icon="@drawable/ic_winboll"
|
android:icon="@drawable/ic_winboll"
|
||||||
@@ -14,7 +11,7 @@
|
|||||||
android:resizeableActivity="true"
|
android:resizeableActivity="true"
|
||||||
android:process=":App">
|
android:process=":App">
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
@@ -32,13 +29,15 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity android:name=".GlobalApplication$CrashActivity"/>
|
<activity android:name=".GlobalApplication$CrashActivity"/>
|
||||||
|
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.max_aspect"
|
android:name="android.max_aspect"
|
||||||
android:value="4.0"/>
|
android:value="4.0"/>
|
||||||
|
|
||||||
|
<activity android:name="cc.winboll.studio.libappbase.activities.CrashCopyReceiverActivity"/>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -1,19 +1,43 @@
|
|||||||
package cc.winboll.studio.appbase;
|
package cc.winboll.studio.appbase;
|
||||||
|
|
||||||
|
import cc.winboll.studio.libappbase.GlobalApplication;
|
||||||
|
import cc.winboll.studio.libappbase.ToastUtils;
|
||||||
|
import cc.winboll.studio.libappbase.BuildConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||||
* @Date 2025/01/05 09:54:42
|
* @Date 2025/01/05 09:54:42
|
||||||
* @Describe APPbase 应用类
|
* @Describe 应用全局入口类(继承基础库 GlobalApplication)
|
||||||
|
* 负责应用初始化、全局资源管理与生命周期回调处理,是整个应用的核心入口
|
||||||
*/
|
*/
|
||||||
import android.content.IntentFilter;
|
|
||||||
import cc.winboll.studio.libappbase.GlobalApplication;
|
|
||||||
|
|
||||||
public class App extends GlobalApplication {
|
public class App extends GlobalApplication {
|
||||||
|
|
||||||
|
/** 当前应用类的日志 TAG(用于调试输出,标识日志来源) */
|
||||||
public static final String TAG = "App";
|
public static final String TAG = "App";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用创建时回调(全局初始化入口)
|
||||||
|
* 在应用进程启动时执行,仅调用一次,用于初始化全局工具类、第三方库等
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate(); // 调用父类初始化逻辑(如基础库配置、全局上下文设置)
|
||||||
|
//setIsDebugging(false);
|
||||||
|
setIsDebugging(BuildConfig.DEBUG);
|
||||||
|
// 初始化 Toast 工具类(传入应用全局上下文,确保 Toast 可在任意地方调用)
|
||||||
|
ToastUtils.init(getApplicationContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用终止时回调(资源释放入口)
|
||||||
|
* 仅在模拟环境(如 Android Studio 模拟器)中可靠触发,真机上可能因系统回收进程不执行
|
||||||
|
* 用于释放全局资源,避免内存泄漏
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onTerminate() {
|
||||||
|
super.onTerminate(); // 调用父类终止逻辑(如基础库资源释放)
|
||||||
|
// 释放 Toast 工具类资源(销毁全局 Toast 实例,避免内存泄漏)
|
||||||
|
ToastUtils.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,67 +8,133 @@ 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.view.View;
|
||||||
import android.widget.Toast;
|
|
||||||
import android.widget.Toolbar;
|
import android.widget.Toolbar;
|
||||||
import cc.winboll.studio.appbase.R;
|
import cc.winboll.studio.appbase.R;
|
||||||
import cc.winboll.studio.libappbase.LogActivity;
|
import cc.winboll.studio.libappbase.LogActivity;
|
||||||
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
import cc.winboll.studio.libappbase.ToastUtils;
|
import cc.winboll.studio.libappbase.ToastUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||||
|
* @Date 未标注(建议补充创建日期)
|
||||||
|
* @Describe 应用主界面 Activity(入口界面)
|
||||||
|
* 包含功能测试按钮(崩溃测试、日志查看、Toast测试)、顶部工具栏(菜单功能),是应用交互的核心入口
|
||||||
|
*/
|
||||||
public class MainActivity extends Activity {
|
public class MainActivity extends Activity {
|
||||||
|
|
||||||
|
/** 当前 Activity 的日志 TAG(用于调试输出,标识日志来源) */
|
||||||
public static final String TAG = "MainActivity";
|
public static final String TAG = "MainActivity";
|
||||||
|
|
||||||
Toolbar mToolbar;
|
/** 顶部工具栏(用于展示标题、菜单,绑定布局中的 Toolbar 控件) */
|
||||||
|
private Toolbar mToolbar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Activity 创建时回调(初始化界面)
|
||||||
|
* 在 Activity 首次创建时执行,用于加载布局、初始化控件、设置事件监听
|
||||||
|
* @param savedInstanceState 保存 Activity 状态的 Bundle(如屏幕旋转时的数据恢复)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
ToastUtils.show("onCreate");
|
ToastUtils.show("onCreate"); // 显示 Activity 创建提示(调试用)
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main); // 加载主界面布局
|
||||||
|
|
||||||
|
// 初始化 Toolbar 并设置为 ActionBar
|
||||||
mToolbar = findViewById(R.id.toolbar);
|
mToolbar = findViewById(R.id.toolbar);
|
||||||
setActionBar(mToolbar);
|
setActionBar(mToolbar); // 将 Toolbar 替代系统默认 ActionBar
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建菜单时回调(加载工具栏菜单)
|
||||||
|
* 初始化 ActionBar 菜单,加载自定义菜单布局
|
||||||
|
* @param menu 菜单对象(用于承载菜单项)
|
||||||
|
* @return true:显示菜单;false:不显示菜单
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
// 加载菜单布局(R.menu.toolbar_main 为自定义菜单文件)
|
||||||
getMenuInflater().inflate(R.menu.toolbar_main, menu);
|
getMenuInflater().inflate(R.menu.toolbar_main, menu);
|
||||||
return super.onCreateOptionsMenu(menu);
|
return super.onCreateOptionsMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜单 item 点击时回调(处理菜单事件)
|
||||||
|
* 响应 Toolbar 菜单项的点击事件,执行对应业务逻辑
|
||||||
|
* @param item 被点击的菜单项
|
||||||
|
* @return true:消费点击事件;false:不消费(传递给父类)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.item_home : {
|
case R.id.item_home:
|
||||||
openWebsiteInBrowser(this);
|
// 点击 "首页/官网" 菜单项,唤起浏览器打开指定网站
|
||||||
}
|
openWebsiteInBrowser(this);
|
||||||
}
|
break;
|
||||||
// 在switch语句中处理每个ID,并在处理完后返回true,未处理的情况返回false。
|
// 可扩展其他菜单项(如设置、关于等)的处理逻辑
|
||||||
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 崩溃测试按钮点击事件(触发应用崩溃,用于调试异常捕获)
|
||||||
|
* 故意执行非法操作(循环获取不存在的字符串资源),强制应用崩溃
|
||||||
|
* @param view 触发事件的 View(对应布局中的崩溃测试按钮)
|
||||||
|
*/
|
||||||
public void onCrashTest(View view) {
|
public void onCrashTest(View view) {
|
||||||
for (int i = Integer.MIN_VALUE; i < Integer.MAX_VALUE; i++) {
|
// 循环从 Integer.MIN_VALUE 到 Integer.MAX_VALUE,获取不存在的字符串资源 ID,触发崩溃
|
||||||
getString(i);
|
for (int i = Integer.MIN_VALUE; i < Integer.MAX_VALUE; i++) {
|
||||||
}
|
getString(i); // i 超出资源 ID 范围,抛出 Resources.NotFoundException 导致崩溃
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志测试按钮点击事件(打开日志查看界面)
|
||||||
|
* 启动 LogActivity,用于查看应用运行日志
|
||||||
|
* @param view 触发事件的 View(对应布局中的日志测试按钮)
|
||||||
|
*/
|
||||||
public void onLogTest(View view) {
|
public void onLogTest(View view) {
|
||||||
|
// 启动日志查看 Activity(通过静态方法传入上下文,简化跳转逻辑)
|
||||||
LogActivity.startLogActivity(this);
|
LogActivity.startLogActivity(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 唤起默认浏览器打开指定网站
|
* Toast 工具测试按钮点击事件(测试全局 Toast 功能)
|
||||||
* @param context 上下文(如 Activity.this)
|
* 测试主线程、子线程中 Toast 的显示效果,验证 ToastUtils 的可用性
|
||||||
*/
|
* @param view 触发事件的 View(对应布局中的 Toast 测试按钮)
|
||||||
public void openWebsiteInBrowser(Context context) {
|
*/
|
||||||
// 目标网站地址
|
public void onToastUtilsTest(View view) {
|
||||||
String url = "https://www.winboll.cc";
|
LogUtils.d(TAG, "onToastUtilsTest"); // 打印调试日志,标识进入 Toast 测试
|
||||||
// 构建打开浏览器的意图
|
ToastUtils.show("Hello, WinBoLL!"); // 主线程显示 Toast
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
|
||||||
// 设置标志:避免创建新的任务栈(可选,按需求调整)
|
// 开启子线程,延迟 2 秒后显示 Toast(测试子线程 Toast 兼容性)
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
new Thread(new Runnable() {
|
||||||
context.startActivity(intent);
|
@Override
|
||||||
|
public void run() {
|
||||||
}
|
try {
|
||||||
|
Thread.sleep(2000); // 线程休眠 2 秒
|
||||||
|
// 若 ToastUtils 已处理主线程切换,此处可直接调用;否则需通过 Handler 切换到主线程
|
||||||
|
ToastUtils.show("Thread.sleep(2000);ToastUtils.show...");
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// 捕获线程中断异常(如线程被销毁时),不做处理(测试场景)
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 唤起系统默认浏览器打开指定网站(跳转至应用官网)
|
||||||
|
* 通过 Intent.ACTION_VIEW 隐式意图,触发浏览器打开目标 URL
|
||||||
|
* @param context 上下文对象(如 Activity、Application,此处为 MainActivity)
|
||||||
|
*/
|
||||||
|
public void openWebsiteInBrowser(Context context) {
|
||||||
|
String url = "https://www.winboll.cc"; // 目标网站 URL(应用官网)
|
||||||
|
// 构建隐式意图:ACTION_VIEW 表示查看指定数据(Uri 为网站地址)
|
||||||
|
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
||||||
|
// 设置标志:在新的任务栈中启动 Activity(避免与当前应用任务栈混淆)
|
||||||
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
// 启动意图(唤起浏览器)
|
||||||
|
context.startActivity(intent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,37 +11,57 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:id="@+id/toolbar"/>
|
android:id="@+id/toolbar"/>
|
||||||
|
|
||||||
<LinearLayout
|
<ScrollView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1.0">
|
||||||
android:orientation="vertical"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:spacing="12dp">
|
|
||||||
|
|
||||||
<Button
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="应用崩溃测试"
|
android:orientation="vertical"
|
||||||
android:textSize="16sp"
|
android:gravity="center_vertical"
|
||||||
android:textColor="@android:color/white"
|
android:spacing="12dp">
|
||||||
android:background="#81C7F5"
|
|
||||||
android:paddingVertical="12dp"
|
|
||||||
android:layout_marginHorizontal="24dp"
|
|
||||||
android:onClick="onCrashTest"/>
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="应用日志测试"
|
android:text="应用崩溃测试"
|
||||||
android:textSize="16sp"
|
android:textSize="16sp"
|
||||||
android:textColor="@android:color/white"
|
android:textColor="@android:color/white"
|
||||||
android:background="#81C7F5"
|
android:background="#81C7F5"
|
||||||
android:paddingVertical="12dp"
|
android:paddingVertical="12dp"
|
||||||
android:layout_marginHorizontal="24dp"
|
android:layout_marginHorizontal="24dp"
|
||||||
android:onClick="onLogTest"/>
|
android:onClick="onCrashTest"
|
||||||
|
android:layout_margin="10dp"/>
|
||||||
|
|
||||||
</LinearLayout>
|
<Button
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="应用日志测试"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:background="#81C7F5"
|
||||||
|
android:paddingVertical="12dp"
|
||||||
|
android:layout_marginHorizontal="24dp"
|
||||||
|
android:onClick="onLogTest"
|
||||||
|
android:layout_margin="10dp"/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="应用吐司测试"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:background="#81C7F5"
|
||||||
|
android:paddingVertical="12dp"
|
||||||
|
android:layout_marginHorizontal="24dp"
|
||||||
|
android:onClick="onToastUtilsTest"
|
||||||
|
android:layout_margin="10dp"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">AppBase</string>
|
<string name="app_name">AppBase</string>
|
||||||
<string name="tileservice_name">WinBoLL</string>
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Mon Sep 29 00:19:37 HKT 2025
|
#Mon Sep 29 01:16:05 HKT 2025
|
||||||
stageCount=2
|
stageCount=3
|
||||||
libraryProject=libapputils
|
libraryProject=libapputils
|
||||||
baseVersion=15.10
|
baseVersion=15.10
|
||||||
publishVersion=15.10.1
|
publishVersion=15.10.2
|
||||||
buildCount=0
|
buildCount=0
|
||||||
baseBetaVersion=15.10.2
|
baseBetaVersion=15.10.3
|
||||||
|
|||||||
27
build.gradle
27
build.gradle
@@ -5,6 +5,16 @@ buildscript {
|
|||||||
// 设置本地Maven仓库路径
|
// 设置本地Maven仓库路径
|
||||||
url 'file:///sdcard/.m2/repository/'
|
url 'file:///sdcard/.m2/repository/'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//米盟通过maven接入时,要做如下配置
|
||||||
|
maven {
|
||||||
|
url "https://repos.xiaomi.com/maven"
|
||||||
|
credentials {
|
||||||
|
username 'mimo-developer'
|
||||||
|
password 'AKCp8ih1PFG9tV8qaLyws67dLGZi8udFM39SfsHgihN15cgsiRvHuxj8JzFmuZjaViVeNawaA'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Nexus Maven 库地址
|
// Nexus Maven 库地址
|
||||||
// "WinBoLL Release"
|
// "WinBoLL Release"
|
||||||
maven { url "https://nexus.winboll.cc/repository/maven-public/" }
|
maven { url "https://nexus.winboll.cc/repository/maven-public/" }
|
||||||
@@ -23,9 +33,6 @@ buildscript {
|
|||||||
//println mavenLocal().url
|
//println mavenLocal().url
|
||||||
//println "mavenLocal : ==========="
|
//println "mavenLocal : ==========="
|
||||||
//mavenLocal()
|
//mavenLocal()
|
||||||
|
|
||||||
// WinBoLL.CC 紧急备用 Maven 仓库
|
|
||||||
maven { url 'https://spare-maven.winboll.cc/repository/' }
|
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:7.2.1' // 对应 compileSdkVersion 32
|
classpath 'com.android.tools.build:gradle:7.2.1' // 对应 compileSdkVersion 32
|
||||||
@@ -40,7 +47,15 @@ allprojects {
|
|||||||
// 设置本地Maven仓库路径
|
// 设置本地Maven仓库路径
|
||||||
url 'file:///sdcard/.m2/repository/'
|
url 'file:///sdcard/.m2/repository/'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//米盟通过maven接入时,要做如下配置
|
||||||
|
maven {
|
||||||
|
url "https://repos.xiaomi.com/maven"
|
||||||
|
credentials {
|
||||||
|
username 'mimo-developer'
|
||||||
|
password 'AKCp8ih1PFG9tV8qaLyws67dLGZi8udFM39SfsHgihN15cgsiRvHuxj8JzFmuZjaViVeNawaA'
|
||||||
|
}
|
||||||
|
}
|
||||||
// Nexus Maven 库地址
|
// Nexus Maven 库地址
|
||||||
// "WinBoLL Release"
|
// "WinBoLL Release"
|
||||||
maven { url "https://nexus.winboll.cc/repository/maven-public/" }
|
maven { url "https://nexus.winboll.cc/repository/maven-public/" }
|
||||||
@@ -59,9 +74,6 @@ allprojects {
|
|||||||
//println mavenLocal().url
|
//println mavenLocal().url
|
||||||
//println "mavenLocal : ==========="
|
//println "mavenLocal : ==========="
|
||||||
//mavenLocal()
|
//mavenLocal()
|
||||||
|
|
||||||
// WinBoLL.CC 紧急备用 Maven 仓库
|
|
||||||
maven { url 'https://spare-maven.winboll.cc/repository/' }
|
|
||||||
}
|
}
|
||||||
ext {
|
ext {
|
||||||
// 定义全局变量,常用于版本管理
|
// 定义全局变量,常用于版本管理
|
||||||
@@ -117,4 +129,3 @@ task clean(type: Delete) {
|
|||||||
delete rootProject.buildDir
|
delete rootProject.buildDir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ def genVersionName(def versionName){
|
|||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 32
|
compileSdkVersion 30
|
||||||
buildToolsVersion "32.0.0"
|
buildToolsVersion "30.0.3"
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "cc.winboll.studio.contacts"
|
applicationId "cc.winboll.studio.contacts"
|
||||||
@@ -66,7 +66,7 @@ dependencies {
|
|||||||
// 应用介绍页类库
|
// 应用介绍页类库
|
||||||
api 'io.github.medyo:android-about-page:2.0.0'
|
api 'io.github.medyo:android-about-page:2.0.0'
|
||||||
// 吐司类库
|
// 吐司类库
|
||||||
api 'com.github.getActivity:ToastUtils:10.5'
|
//api 'com.github.getActivity:ToastUtils:10.5'
|
||||||
// 网络连接类库
|
// 网络连接类库
|
||||||
api 'com.squareup.okhttp3:okhttp:4.4.1'
|
api 'com.squareup.okhttp3:okhttp:4.4.1'
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Sun Aug 31 06:05:42 CST 2025
|
#Mon Nov 03 12:01:02 HKT 2025
|
||||||
stageCount=17
|
stageCount=22
|
||||||
libraryProject=
|
libraryProject=
|
||||||
baseVersion=15.3
|
baseVersion=15.3
|
||||||
publishVersion=15.3.16
|
publishVersion=15.3.21
|
||||||
buildCount=0
|
buildCount=0
|
||||||
baseBetaVersion=15.3.17
|
baseBetaVersion=15.3.22
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ package cc.winboll.studio.contacts;
|
|||||||
*/
|
*/
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import cc.winboll.studio.libappbase.GlobalApplication;
|
import cc.winboll.studio.libappbase.GlobalApplication;
|
||||||
|
import cc.winboll.studio.libappbase.utils.ToastUtils;
|
||||||
import cc.winboll.studio.libappbase.winboll.WinBoLLActivityManager;
|
import cc.winboll.studio.libappbase.winboll.WinBoLLActivityManager;
|
||||||
import com.hjq.toast.ToastUtils;
|
|
||||||
|
|
||||||
public class App extends GlobalApplication {
|
public class App extends GlobalApplication {
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ public class App extends GlobalApplication {
|
|||||||
// 设置 Toast 布局样式
|
// 设置 Toast 布局样式
|
||||||
//ToastUtils.setView(R.layout.toast_custom_view);
|
//ToastUtils.setView(R.layout.toast_custom_view);
|
||||||
//ToastUtils.setStyle(new WhiteToastStyle());
|
//ToastUtils.setStyle(new WhiteToastStyle());
|
||||||
ToastUtils.setGravity(Gravity.BOTTOM, 0, 200);
|
//ToastUtils.setGravity(Gravity.BOTTOM, 0, 200);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ package cc.winboll.studio.contacts;
|
|||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
@@ -38,8 +39,10 @@ import cc.winboll.studio.contacts.fragments.CallLogFragment;
|
|||||||
import cc.winboll.studio.contacts.fragments.ContactsFragment;
|
import cc.winboll.studio.contacts.fragments.ContactsFragment;
|
||||||
import cc.winboll.studio.contacts.fragments.LogFragment;
|
import cc.winboll.studio.contacts.fragments.LogFragment;
|
||||||
import cc.winboll.studio.contacts.services.MainService;
|
import cc.winboll.studio.contacts.services.MainService;
|
||||||
|
import cc.winboll.studio.contacts.utils.AppGoToSettingsUtil;
|
||||||
import cc.winboll.studio.libappbase.LogUtils;
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
import cc.winboll.studio.libappbase.LogView;
|
import cc.winboll.studio.libappbase.LogView;
|
||||||
|
import cc.winboll.studio.libappbase.utils.ToastUtils;
|
||||||
import cc.winboll.studio.libappbase.winboll.IWinBoLLActivity;
|
import cc.winboll.studio.libappbase.winboll.IWinBoLLActivity;
|
||||||
import com.google.android.material.tabs.TabLayout;
|
import com.google.android.material.tabs.TabLayout;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -48,10 +51,9 @@ import java.util.List;
|
|||||||
final public class MainActivity extends AppCompatActivity implements IWinBoLLActivity, ViewPager.OnPageChangeListener, View.OnClickListener {
|
final public class MainActivity extends AppCompatActivity implements IWinBoLLActivity, ViewPager.OnPageChangeListener, View.OnClickListener {
|
||||||
|
|
||||||
public static final String TAG = "MainActivity";
|
public static final String TAG = "MainActivity";
|
||||||
|
|
||||||
public static final int REQUEST_HOME_ACTIVITY = 0;
|
public static final int REQUEST_HOME_ACTIVITY = 0;
|
||||||
public static final int REQUEST_ABOUT_ACTIVITY = 1;
|
public static final int REQUEST_ABOUT_ACTIVITY = 1;
|
||||||
|
public static final int REQUEST_APP_SETTINGS = 2;
|
||||||
public static final String ACTION_SOS = "cc.winboll.studio.libappbase.WinBoLL.ACTION_SOS";
|
public static final String ACTION_SOS = "cc.winboll.studio.libappbase.WinBoLL.ACTION_SOS";
|
||||||
|
|
||||||
static MainActivity _MainActivity;
|
static MainActivity _MainActivity;
|
||||||
@@ -72,6 +74,13 @@ final public class MainActivity extends AppCompatActivity implements IWinBoLLAct
|
|||||||
List<String> tabTitleList;
|
List<String> tabTitleList;
|
||||||
|
|
||||||
private static final int DIALER_REQUEST_CODE = 1;
|
private static final int DIALER_REQUEST_CODE = 1;
|
||||||
|
private static final int REQUEST_REQUIRED_PERMISSIONS = 1002;
|
||||||
|
// 关键修改1:新增 READ_CALL_LOG 权限到必需权限列表(解决通话记录读取崩溃)
|
||||||
|
private String[] REQUIRED_PERMISSIONS = new String[]{
|
||||||
|
Manifest.permission.READ_CONTACTS, // 通讯录读取(原)
|
||||||
|
Manifest.permission.CALL_PHONE, // 电话拨号(原)
|
||||||
|
Manifest.permission.READ_CALL_LOG // 通话记录读取(新增,核心修复)
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -88,9 +97,88 @@ final public class MainActivity extends AppCompatActivity implements IWinBoLLAct
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
_MainActivity = this;
|
_MainActivity = this;
|
||||||
|
|
||||||
|
// 优先检查所有必需权限(含新增的 READ_CALL_LOG)
|
||||||
|
if (!checkAllRequiredPermissions()) {
|
||||||
|
requestAllRequiredPermissions();
|
||||||
|
} else {
|
||||||
|
initUIAndLogic(savedInstanceState);
|
||||||
|
}
|
||||||
|
|
||||||
|
//ToastUtils.show("onCreate");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 权限检查方法(无需修改,自动包含新增的 READ_CALL_LOG)
|
||||||
|
private boolean checkAllRequiredPermissions() {
|
||||||
|
for (String permission : REQUIRED_PERMISSIONS) {
|
||||||
|
if (ActivityCompat.checkSelfPermission(this, permission)
|
||||||
|
!= PackageManager.PERMISSION_GRANTED) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 权限申请方法(无需修改,自动申请新增的 READ_CALL_LOG)
|
||||||
|
private void requestAllRequiredPermissions() {
|
||||||
|
ActivityCompat.requestPermissions(this, REQUIRED_PERMISSIONS, REQUEST_REQUIRED_PERMISSIONS);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 权限结果回调(无需修改,确保所有权限(含 READ_CALL_LOG)都通过才加载UI)
|
||||||
|
@Override
|
||||||
|
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||||
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
|
|
||||||
|
if (requestCode == REQUEST_REQUIRED_PERMISSIONS) {
|
||||||
|
boolean allPermissionsGranted = true;
|
||||||
|
for (int result : grantResults) {
|
||||||
|
if (result != PackageManager.PERMISSION_GRANTED) {
|
||||||
|
allPermissionsGranted = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allPermissionsGranted) {
|
||||||
|
initUIAndLogic(null);
|
||||||
|
} else {
|
||||||
|
// 关键修改2:更新提示文案,告知用户新增的“通话记录权限”
|
||||||
|
showPermissionDeniedDialogAndExit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 核心修改:新增“设置权限”按钮,点击调用 AppGoToSettingsUtil 跳转设置页
|
||||||
|
private void showPermissionDeniedDialogAndExit() {
|
||||||
|
new AlertDialog.Builder(this)
|
||||||
|
.setTitle("权限不足,无法使用")
|
||||||
|
// 文案修改:明确新增“通话记录读取”权限
|
||||||
|
.setMessage("应用需要「通讯录读取」、「电话」和「通话记录读取」权限才能正常运行,请授予权限后重新打开应用。")
|
||||||
|
.setCancelable(false)
|
||||||
|
// 新增:左侧“设置权限”按钮(先添加的按钮在左侧)
|
||||||
|
.setNegativeButton("设置权限", new AlertDialog.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(android.content.DialogInterface dialog, int which) {
|
||||||
|
dialog.dismiss();
|
||||||
|
// 调用工具类跳转应用设置页(按需求实现)
|
||||||
|
AppGoToSettingsUtil appGoToSettingsUtil = new AppGoToSettingsUtil();
|
||||||
|
appGoToSettingsUtil.GoToSetting(MainActivity.this);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// 原有:右侧“确定退出”按钮(后添加的按钮在右侧)
|
||||||
|
.setPositiveButton("确定退出", new AlertDialog.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(android.content.DialogInterface dialog, int which) {
|
||||||
|
dialog.dismiss();
|
||||||
|
finishAndRemoveTask();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始化UI和逻辑(无需修改,权限通过后才加载 CallLogFragment)
|
||||||
|
private void initUIAndLogic(Bundle savedInstanceState) {
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
|
||||||
// 初始化工具栏(仅加载基础UI)
|
|
||||||
mToolbar = (Toolbar) findViewById(R.id.activitymainToolbar1);
|
mToolbar = (Toolbar) findViewById(R.id.activitymainToolbar1);
|
||||||
setSupportActionBar(mToolbar);
|
setSupportActionBar(mToolbar);
|
||||||
getSupportActionBar().setSubtitle(TAG);
|
getSupportActionBar().setSubtitle(TAG);
|
||||||
@@ -98,34 +186,28 @@ final public class MainActivity extends AppCompatActivity implements IWinBoLLAct
|
|||||||
tabLayout = (TabLayout) findViewById(R.id.tabLayout);
|
tabLayout = (TabLayout) findViewById(R.id.tabLayout);
|
||||||
viewPager = (ViewPager) findViewById(R.id.viewPager);
|
viewPager = (ViewPager) findViewById(R.id.viewPager);
|
||||||
|
|
||||||
// 创建Fragment列表(仅实例化,不加载数据)
|
|
||||||
fragmentList = new ArrayList<Fragment>();
|
fragmentList = new ArrayList<Fragment>();
|
||||||
tabTitleList = new ArrayList<String>();
|
tabTitleList = new ArrayList<String>();
|
||||||
|
// CallLogFragment 仅在权限通过后才实例化(避免提前触发读取)
|
||||||
fragmentList.add(CallLogFragment.newInstance(0));
|
fragmentList.add(CallLogFragment.newInstance(0));
|
||||||
fragmentList.add(ContactsFragment.newInstance(1)); // 延迟加载联系人数据
|
fragmentList.add(ContactsFragment.newInstance(1));
|
||||||
fragmentList.add(LogFragment.newInstance(2));
|
fragmentList.add(LogFragment.newInstance(2));
|
||||||
tabTitleList.add("通话记录");
|
tabTitleList.add("通话记录");
|
||||||
tabTitleList.add("联系人");
|
tabTitleList.add("联系人");
|
||||||
tabTitleList.add("应用日志");
|
tabTitleList.add("应用日志");
|
||||||
|
|
||||||
// 设置ViewPager适配器
|
|
||||||
MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager(), fragmentList, tabTitleList);
|
MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager(), fragmentList, tabTitleList);
|
||||||
viewPager.setAdapter(adapter);
|
viewPager.setAdapter(adapter);
|
||||||
|
viewPager.setOffscreenPageLimit(0); // 关闭预加载,避免提前初始化 CallLogFragment
|
||||||
// 关键:关闭预加载,仅当前页初始化
|
|
||||||
viewPager.setOffscreenPageLimit(0);
|
|
||||||
|
|
||||||
// 关联TabLayout和ViewPager
|
|
||||||
tabLayout.setupWithViewPager(viewPager);
|
tabLayout.setupWithViewPager(viewPager);
|
||||||
|
|
||||||
// 初始化服务状态(延迟启动非核心服务)
|
// 原有服务启动、电话监听等逻辑...
|
||||||
MainServiceBean mMainServiceBean = MainServiceBean.loadBean(this, MainServiceBean.class);
|
MainServiceBean mMainServiceBean = MainServiceBean.loadBean(this, MainServiceBean.class);
|
||||||
if (mMainServiceBean == null) {
|
if (mMainServiceBean == null) {
|
||||||
mMainServiceBean = new MainServiceBean();
|
mMainServiceBean = new MainServiceBean();
|
||||||
MainServiceBean.saveBean(this, mMainServiceBean);
|
MainServiceBean.saveBean(this, mMainServiceBean);
|
||||||
}
|
}
|
||||||
if (mMainServiceBean.isEnable()) {
|
if (mMainServiceBean.isEnable()) {
|
||||||
// 延迟1秒启动服务,避免阻塞启动
|
|
||||||
new Handler().postDelayed(new Runnable() {
|
new Handler().postDelayed(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -134,16 +216,14 @@ final public class MainActivity extends AppCompatActivity implements IWinBoLLAct
|
|||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化电话状态监听(基础功能保留)
|
|
||||||
telephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
|
telephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
|
||||||
phoneStateListener = new MyPhoneStateListener();
|
phoneStateListener = new MyPhoneStateListener();
|
||||||
telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
|
telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ViewPager适配器(Java 7语法)
|
// 以下为原有代码(无需修改)
|
||||||
private class MyPagerAdapter extends FragmentPagerAdapter {
|
private class MyPagerAdapter extends FragmentPagerAdapter {
|
||||||
|
|
||||||
private List<Fragment> fragmentList;
|
private List<Fragment> fragmentList;
|
||||||
private List<String> tabTitleList;
|
private List<String> tabTitleList;
|
||||||
|
|
||||||
@@ -173,21 +253,18 @@ final public class MainActivity extends AppCompatActivity implements IWinBoLLAct
|
|||||||
Intent intent = new Intent(Intent.ACTION_DIAL);
|
Intent intent = new Intent(Intent.ACTION_DIAL);
|
||||||
intent.setData(android.net.Uri.parse("tel:" + phoneNumber));
|
intent.setData(android.net.Uri.parse("tel:" + phoneNumber));
|
||||||
if (ActivityCompat.checkSelfPermission(_MainActivity, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
|
if (ActivityCompat.checkSelfPermission(_MainActivity, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
|
||||||
|
Toast.makeText(_MainActivity, "拨号权限不足", Toast.LENGTH_SHORT).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_MainActivity.startActivity(intent);
|
_MainActivity.startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
// OnPageChangeListener接口实现
|
|
||||||
@Override
|
@Override
|
||||||
public void onPageScrollStateChanged(int state) {}
|
public void onPageScrollStateChanged(int state) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}
|
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPageSelected(int position) {}
|
public void onPageSelected(int position) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {}
|
public void onClick(View v) {}
|
||||||
|
|
||||||
@@ -239,9 +316,6 @@ final public class MainActivity extends AppCompatActivity implements IWinBoLLAct
|
|||||||
super.onResume();
|
super.onResume();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 检查是否是系统默认电话应用
|
|
||||||
*/
|
|
||||||
public boolean isDefaultPhoneCallApp() {
|
public boolean isDefaultPhoneCallApp() {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
TelecomManager manger = (TelecomManager) getSystemService(TELECOM_SERVICE);
|
TelecomManager manger = (TelecomManager) getSystemService(TELECOM_SERVICE);
|
||||||
@@ -272,7 +346,9 @@ final public class MainActivity extends AppCompatActivity implements IWinBoLLAct
|
|||||||
Toast.makeText(MainActivity.this, getString(R.string.app_name) + " 已成为默认电话应用",
|
Toast.makeText(MainActivity.this, getString(R.string.app_name) + " 已成为默认电话应用",
|
||||||
Toast.LENGTH_SHORT).show();
|
Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}
|
} else if (requestCode == REQUEST_APP_SETTINGS) {
|
||||||
|
recreate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ import cc.winboll.studio.contacts.dun.Rules;
|
|||||||
import cc.winboll.studio.contacts.services.MainService;
|
import cc.winboll.studio.contacts.services.MainService;
|
||||||
import cc.winboll.studio.contacts.views.DuInfoTextView;
|
import cc.winboll.studio.contacts.views.DuInfoTextView;
|
||||||
import cc.winboll.studio.libappbase.LogUtils;
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
|
import cc.winboll.studio.libappbase.utils.ToastUtils;
|
||||||
import cc.winboll.studio.libappbase.winboll.IWinBoLLActivity;
|
import cc.winboll.studio.libappbase.winboll.IWinBoLLActivity;
|
||||||
import com.hjq.toast.ToastUtils;
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -263,7 +263,7 @@ public class SettingsActivity extends AppCompatActivity implements IWinBoLLActiv
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (tomCat.downloadBoBullToon()) {
|
if (tomCat.downloadBoBullToon()) {
|
||||||
ToastUtils.show("BoBullToon downlaod OK!");
|
LogUtils.d(TAG, "BoBullToon downlaod OK!");
|
||||||
MainService.restartMainService(SettingsActivity.this);
|
MainService.restartMainService(SettingsActivity.this);
|
||||||
Rules.getInstance(SettingsActivity.this).reload();
|
Rules.getInstance(SettingsActivity.this).reload();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import cc.winboll.studio.contacts.R;
|
|||||||
import cc.winboll.studio.contacts.beans.CallLogModel;
|
import cc.winboll.studio.contacts.beans.CallLogModel;
|
||||||
import cc.winboll.studio.contacts.utils.ContactUtils;
|
import cc.winboll.studio.contacts.utils.ContactUtils;
|
||||||
import cc.winboll.studio.libaes.views.AOHPCTCSeekBar;
|
import cc.winboll.studio.libaes.views.AOHPCTCSeekBar;
|
||||||
import com.hjq.toast.ToastUtils;
|
import cc.winboll.studio.libappbase.utils.ToastUtils;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@@ -76,6 +76,9 @@ public class CallLogAdapter extends RecyclerView.Adapter<CallLogAdapter.CallLogV
|
|||||||
// Set the clipboard's primary clip.
|
// Set the clipboard's primary clip.
|
||||||
clipboard.setPrimaryClip(clip);
|
clipboard.setPrimaryClip(clip);
|
||||||
Toast.makeText(mContext, "Copy to clipboard.", Toast.LENGTH_SHORT).show();
|
Toast.makeText(mContext, "Copy to clipboard.", Toast.LENGTH_SHORT).show();
|
||||||
|
} else if (nItemId == R.id.item_calllog_phonenumber_add_contact) {
|
||||||
|
//ToastUtils.show(callLog.getPhoneNumber());
|
||||||
|
ContactUtils.jumpToAddContact(mContext, callLog.getPhoneNumber());
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -21,8 +21,9 @@ import androidx.annotation.NonNull;
|
|||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import cc.winboll.studio.contacts.R;
|
import cc.winboll.studio.contacts.R;
|
||||||
import cc.winboll.studio.contacts.beans.ContactModel;
|
import cc.winboll.studio.contacts.beans.ContactModel;
|
||||||
|
import cc.winboll.studio.contacts.utils.ContactUtils;
|
||||||
import cc.winboll.studio.libaes.views.AOHPCTCSeekBar;
|
import cc.winboll.studio.libaes.views.AOHPCTCSeekBar;
|
||||||
import com.hjq.toast.ToastUtils;
|
import cc.winboll.studio.libappbase.utils.ToastUtils;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ContactAdapter extends RecyclerView.Adapter<ContactAdapter.ContactViewHolder> {
|
public class ContactAdapter extends RecyclerView.Adapter<ContactAdapter.ContactViewHolder> {
|
||||||
@@ -69,6 +70,11 @@ public class ContactAdapter extends RecyclerView.Adapter<ContactAdapter.ContactV
|
|||||||
// Set the clipboard's primary clip.
|
// Set the clipboard's primary clip.
|
||||||
clipboard.setPrimaryClip(clip);
|
clipboard.setPrimaryClip(clip);
|
||||||
Toast.makeText(mContext, "Copy to clipboard.", Toast.LENGTH_SHORT).show();
|
Toast.makeText(mContext, "Copy to clipboard.", Toast.LENGTH_SHORT).show();
|
||||||
|
} else if (nItemId == R.id.item_calllog_phonenumber_edit_contact) {
|
||||||
|
//ToastUtils.show("Test");
|
||||||
|
Long nContactId = ContactUtils.getContactIdByPhone(mContext, contact.getNumber());
|
||||||
|
//ToastUtils.show(String.format("%d", nContactId));
|
||||||
|
ContactUtils.jumpToEditContact(mContext, contact.getNumber(), nContactId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -112,7 +118,7 @@ public class ContactAdapter extends RecyclerView.Adapter<ContactAdapter.ContactV
|
|||||||
TextView contactName;
|
TextView contactName;
|
||||||
TextView contactNumber;
|
TextView contactNumber;
|
||||||
AOHPCTCSeekBar dialAOHPCTCSeekBar;
|
AOHPCTCSeekBar dialAOHPCTCSeekBar;
|
||||||
|
|
||||||
public ContactViewHolder(@NonNull View itemView) {
|
public ContactViewHolder(@NonNull View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
llPhoneNumberMain = itemView.findViewById(R.id.itemcontactLinearLayout1);
|
llPhoneNumberMain = itemView.findViewById(R.id.itemcontactLinearLayout1);
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ package cc.winboll.studio.contacts.adapters;
|
|||||||
*/
|
*/
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MotionEvent;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
@@ -21,9 +20,8 @@ import cc.winboll.studio.contacts.R;
|
|||||||
import cc.winboll.studio.contacts.beans.PhoneConnectRuleModel;
|
import cc.winboll.studio.contacts.beans.PhoneConnectRuleModel;
|
||||||
import cc.winboll.studio.contacts.dun.Rules;
|
import cc.winboll.studio.contacts.dun.Rules;
|
||||||
import cc.winboll.studio.contacts.views.LeftScrollView;
|
import cc.winboll.studio.contacts.views.LeftScrollView;
|
||||||
import cc.winboll.studio.libappbase.LogUtils;
|
|
||||||
import cc.winboll.studio.libappbase.dialogs.YesNoAlertDialog;
|
import cc.winboll.studio.libappbase.dialogs.YesNoAlertDialog;
|
||||||
import com.hjq.toast.ToastUtils;
|
import cc.winboll.studio.libappbase.utils.ToastUtils;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import android.content.Context;
|
|||||||
import cc.winboll.studio.contacts.R;
|
import cc.winboll.studio.contacts.R;
|
||||||
import cc.winboll.studio.contacts.dun.Rules;
|
import cc.winboll.studio.contacts.dun.Rules;
|
||||||
import cc.winboll.studio.libappbase.LogUtils;
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
import com.hjq.toast.ToastUtils;
|
import cc.winboll.studio.libappbase.utils.ToastUtils;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileFilter;
|
import java.io.FileFilter;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||||||
import cc.winboll.studio.contacts.R;
|
import cc.winboll.studio.contacts.R;
|
||||||
import cc.winboll.studio.contacts.adapters.CallLogAdapter;
|
import cc.winboll.studio.contacts.adapters.CallLogAdapter;
|
||||||
import cc.winboll.studio.contacts.beans.CallLogModel;
|
import cc.winboll.studio.contacts.beans.CallLogModel;
|
||||||
import com.hjq.toast.ToastUtils;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -161,7 +160,7 @@ public class CallLogFragment extends Fragment {
|
|||||||
_CallLogFragment.triggerUpdate();
|
_CallLogFragment.triggerUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import cc.winboll.studio.contacts.R;
|
|||||||
import cc.winboll.studio.contacts.adapters.ContactAdapter;
|
import cc.winboll.studio.contacts.adapters.ContactAdapter;
|
||||||
import cc.winboll.studio.contacts.beans.ContactModel;
|
import cc.winboll.studio.contacts.beans.ContactModel;
|
||||||
import cc.winboll.studio.libappbase.LogUtils;
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
import com.hjq.toast.ToastUtils;
|
import cc.winboll.studio.libappbase.utils.ToastUtils;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
@@ -95,7 +95,7 @@ public class ContactsFragment extends Fragment {
|
|||||||
recyclerView = (RecyclerView) view.findViewById(R.id.contacts_recycler_view);
|
recyclerView = (RecyclerView) view.findViewById(R.id.contacts_recycler_view);
|
||||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||||
contactList = new ArrayList<ContactModel>();
|
contactList = new ArrayList<ContactModel>();
|
||||||
contactAdapter = new ContactAdapter(getContext(), contactList);
|
contactAdapter = new ContactAdapter(getActivity(), contactList);
|
||||||
recyclerView.setAdapter(contactAdapter);
|
recyclerView.setAdapter(contactAdapter);
|
||||||
// 初始隐藏列表,数据加载后显示
|
// 初始隐藏列表,数据加载后显示
|
||||||
recyclerView.setVisibility(View.GONE);
|
recyclerView.setVisibility(View.GONE);
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import androidx.annotation.Nullable;
|
|||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import cc.winboll.studio.contacts.R;
|
import cc.winboll.studio.contacts.R;
|
||||||
import cc.winboll.studio.libappbase.LogView;
|
import cc.winboll.studio.libappbase.LogView;
|
||||||
import com.hjq.toast.ToastUtils;
|
|
||||||
|
|
||||||
public class LogFragment extends Fragment {
|
public class LogFragment extends Fragment {
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import cc.winboll.studio.contacts.services.MainService;
|
import cc.winboll.studio.contacts.services.MainService;
|
||||||
import com.hjq.toast.ToastUtils;
|
import cc.winboll.studio.libappbase.utils.ToastUtils;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
public class MainReceiver extends BroadcastReceiver {
|
public class MainReceiver extends BroadcastReceiver {
|
||||||
|
|||||||
@@ -0,0 +1,270 @@
|
|||||||
|
package cc.winboll.studio.contacts.utils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||||
|
* @Date 2025/09/27 14:27
|
||||||
|
* @Describe 调用应用属性设置页工具类
|
||||||
|
* 来源:https://blog.csdn.net/zhuhai__yizhi/article/details/78737593
|
||||||
|
* Created by zyy on 2018/3/12.
|
||||||
|
* 直接跳转到权限后返回,可以监控权限授权情况,但是,跳转到应用详情页,无法监测权限情况
|
||||||
|
* 是否要加以区分,若是应用详情页,则跳转回来后,onRestart检测所求权限,如果授权,则收回提示,如果没授权,则继续提示
|
||||||
|
*/
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.ComponentName;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import cc.winboll.studio.contacts.MainActivity;
|
||||||
|
|
||||||
|
public class AppGoToSettingsUtil {
|
||||||
|
|
||||||
|
public static final String TAG = "AppGoToSettingsUtil";
|
||||||
|
|
||||||
|
public static final int ACTIVITY_RESULT_APP_SETTINGS = MainActivity.REQUEST_APP_SETTINGS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build.MANUFACTURER判断各大手机厂商品牌
|
||||||
|
*/
|
||||||
|
private static final String MANUFACTURER_HUAWEI = "Huawei";//华为
|
||||||
|
private static final String MANUFACTURER_MEIZU = "Meizu";//魅族
|
||||||
|
private static final String MANUFACTURER_XIAOMI = "Xiaomi";//小米
|
||||||
|
private static final String MANUFACTURER_SONY = "Sony";//索尼
|
||||||
|
private static final String MANUFACTURER_OPPO = "OPPO";
|
||||||
|
private static final String MANUFACTURER_LG = "LG";
|
||||||
|
private static final String MANUFACTURER_VIVO = "vivo";
|
||||||
|
private static final String MANUFACTURER_SAMSUNG = "samsung";//三星
|
||||||
|
private static final String MANUFACTURER_LETV = "Letv";//乐视
|
||||||
|
private static final String MANUFACTURER_ZTE = "ZTE";//中兴
|
||||||
|
private static final String MANUFACTURER_YULONG = "YuLong";//酷派
|
||||||
|
private static final String MANUFACTURER_LENOVO = "LENOVO";//联想
|
||||||
|
|
||||||
|
public static boolean isAppSettingOpen=false;
|
||||||
|
/**
|
||||||
|
* 跳转到相应品牌手机系统权限设置页,如果跳转不成功,则跳转到应用详情页
|
||||||
|
* 这里需要改造成返回true或者false,应用详情页:true,应用权限页:false
|
||||||
|
* @param activity
|
||||||
|
*/
|
||||||
|
public static void GoToSetting(Activity activity) {
|
||||||
|
switch (Build.MANUFACTURER) {
|
||||||
|
case MANUFACTURER_HUAWEI://华为
|
||||||
|
Huawei(activity);
|
||||||
|
break;
|
||||||
|
case MANUFACTURER_MEIZU://魅族
|
||||||
|
Meizu(activity);
|
||||||
|
break;
|
||||||
|
case MANUFACTURER_XIAOMI://小米
|
||||||
|
Xiaomi(activity);
|
||||||
|
break;
|
||||||
|
case MANUFACTURER_SONY://索尼
|
||||||
|
Sony(activity);
|
||||||
|
break;
|
||||||
|
case MANUFACTURER_OPPO://oppo
|
||||||
|
OPPO(activity);
|
||||||
|
break;
|
||||||
|
case MANUFACTURER_LG://lg
|
||||||
|
LG(activity);
|
||||||
|
break;
|
||||||
|
case MANUFACTURER_LETV://乐视
|
||||||
|
Letv(activity);
|
||||||
|
break;
|
||||||
|
default://其他
|
||||||
|
try {//防止应用详情页也找不到,捕获异常后跳转到设置,这里跳转最好是两级,太多用户也会觉得麻烦,还不如不跳
|
||||||
|
openAppDetailSetting(activity);
|
||||||
|
//activity.startActivityForResult(getAppDetailSettingIntent(activity), PERMISSION_SETTING_FOR_RESULT);
|
||||||
|
} catch (Exception e) {
|
||||||
|
SystemConfig(activity);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 华为跳转权限设置页
|
||||||
|
* @param activity
|
||||||
|
*/
|
||||||
|
public static void Huawei(Activity activity) {
|
||||||
|
try {
|
||||||
|
Intent intent = new Intent();
|
||||||
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
intent.putExtra("packageName", activity.getPackageName());
|
||||||
|
ComponentName comp = new ComponentName("com.huawei.systemmanager", "com.huawei.permissionmanager.ui.MainActivity");
|
||||||
|
intent.setComponent(comp);
|
||||||
|
activity.startActivityForResult(intent, ACTIVITY_RESULT_APP_SETTINGS);
|
||||||
|
isAppSettingOpen = false;
|
||||||
|
} catch (Exception e) {
|
||||||
|
openAppDetailSetting(activity);
|
||||||
|
//activity.startActivityForResult(getAppDetailSettingIntent(activity), PERMISSION_SETTING_FOR_RESULT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 魅族跳转权限设置页,测试时,点击无反应,具体原因不明
|
||||||
|
* @param activity
|
||||||
|
*/
|
||||||
|
public static void Meizu(Activity activity) {
|
||||||
|
try {
|
||||||
|
Intent intent = new Intent("com.meizu.safe.security.SHOW_APPSEC");
|
||||||
|
intent.addCategory(Intent.CATEGORY_DEFAULT);
|
||||||
|
intent.putExtra("packageName", activity.getPackageName());
|
||||||
|
activity.startActivity(intent);
|
||||||
|
isAppSettingOpen = false;
|
||||||
|
} catch (Exception e) {
|
||||||
|
openAppDetailSetting(activity);
|
||||||
|
//activity.startActivityForResult(getAppDetailSettingIntent(activity), PERMISSION_SETTING_FOR_RESULT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小米,功能正常
|
||||||
|
* @param activity
|
||||||
|
*/
|
||||||
|
public static void Xiaomi(Activity activity) {
|
||||||
|
try { //MIUI 8 9
|
||||||
|
Intent localIntent = new Intent("miui.intent.action.APP_PERM_EDITOR");
|
||||||
|
localIntent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.PermissionsEditorActivity");
|
||||||
|
localIntent.putExtra("extra_pkgname", activity.getPackageName());
|
||||||
|
activity.startActivityForResult(localIntent, ACTIVITY_RESULT_APP_SETTINGS);
|
||||||
|
isAppSettingOpen = false;
|
||||||
|
//activity.startActivity(localIntent);
|
||||||
|
} catch (Exception e) {
|
||||||
|
try { //MIUI 5/6/7
|
||||||
|
Intent localIntent = new Intent("miui.intent.action.APP_PERM_EDITOR");
|
||||||
|
localIntent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.AppPermissionsEditorActivity");
|
||||||
|
localIntent.putExtra("extra_pkgname", activity.getPackageName());
|
||||||
|
activity.startActivityForResult(localIntent, ACTIVITY_RESULT_APP_SETTINGS);
|
||||||
|
isAppSettingOpen = false;
|
||||||
|
//activity.startActivity(localIntent);
|
||||||
|
} catch (Exception e1) { //否则跳转到应用详情
|
||||||
|
openAppDetailSetting(activity);
|
||||||
|
//activity.startActivityForResult(getAppDetailSettingIntent(activity), PERMISSION_SETTING_FOR_RESULT);
|
||||||
|
//这里有个问题,进入活动后需要再跳一级活动,就检测不到返回结果
|
||||||
|
//activity.startActivity(getAppDetailSettingIntent());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 索尼,6.0以上的手机非常少,基本没看见
|
||||||
|
* @param activity
|
||||||
|
*/
|
||||||
|
public static void Sony(Activity activity) {
|
||||||
|
try {
|
||||||
|
Intent intent = new Intent();
|
||||||
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
intent.putExtra("packageName", activity.getPackageName());
|
||||||
|
ComponentName comp = new ComponentName("com.sonymobile.cta", "com.sonymobile.cta.SomcCTAMainActivity");
|
||||||
|
intent.setComponent(comp);
|
||||||
|
activity.startActivity(intent);
|
||||||
|
isAppSettingOpen = false;
|
||||||
|
} catch (Exception e) {
|
||||||
|
openAppDetailSetting(activity);
|
||||||
|
//activity.startActivityForResult(getAppDetailSettingIntent(activity), PERMISSION_SETTING_FOR_RESULT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OPPO
|
||||||
|
* @param activity
|
||||||
|
*/
|
||||||
|
public static void OPPO(Activity activity) {
|
||||||
|
try {
|
||||||
|
Intent intent = new Intent();
|
||||||
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
intent.putExtra("packageName", activity.getPackageName());
|
||||||
|
ComponentName comp = new ComponentName("com.color.safecenter", "com.color.safecenter.permission.PermissionManagerActivity");
|
||||||
|
intent.setComponent(comp);
|
||||||
|
activity.startActivity(intent);
|
||||||
|
isAppSettingOpen = false;
|
||||||
|
} catch (Exception e) {
|
||||||
|
openAppDetailSetting(activity);
|
||||||
|
//activity.startActivityForResult(getAppDetailSettingIntent(activity), PERMISSION_SETTING_FOR_RESULT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LG经过测试,正常使用
|
||||||
|
* @param activity
|
||||||
|
*/
|
||||||
|
public static void LG(Activity activity) {
|
||||||
|
try {
|
||||||
|
Intent intent = new Intent("android.intent.action.MAIN");
|
||||||
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
intent.putExtra("packageName", activity.getPackageName());
|
||||||
|
ComponentName comp = new ComponentName("com.android.settings", "com.android.settings.Settings$AccessLockSummaryActivity");
|
||||||
|
intent.setComponent(comp);
|
||||||
|
activity.startActivity(intent);
|
||||||
|
isAppSettingOpen = false;
|
||||||
|
} catch (Exception e) {
|
||||||
|
openAppDetailSetting(activity);
|
||||||
|
//activity.startActivityForResult(getAppDetailSettingIntent(activity), PERMISSION_SETTING_FOR_RESULT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 乐视6.0以上很少,基本都可以忽略了,现在乐视手机不多
|
||||||
|
* @param activity
|
||||||
|
*/
|
||||||
|
public static void Letv(Activity activity) {
|
||||||
|
try {
|
||||||
|
Intent intent = new Intent();
|
||||||
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
intent.putExtra("packageName", activity.getPackageName());
|
||||||
|
ComponentName comp = new ComponentName("com.letv.android.letvsafe", "com.letv.android.letvsafe.PermissionAndApps");
|
||||||
|
intent.setComponent(comp);
|
||||||
|
activity.startActivity(intent);
|
||||||
|
isAppSettingOpen = false;
|
||||||
|
} catch (Exception e) {
|
||||||
|
openAppDetailSetting(activity);
|
||||||
|
//activity.startActivityForResult(getAppDetailSettingIntent(activity), PERMISSION_SETTING_FOR_RESULT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 只能打开到自带安全软件
|
||||||
|
* @param activity
|
||||||
|
*/
|
||||||
|
public static void _360(Activity activity) {
|
||||||
|
try {
|
||||||
|
Intent intent = new Intent("android.intent.action.MAIN");
|
||||||
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
intent.putExtra("packageName", activity.getPackageName());
|
||||||
|
ComponentName comp = new ComponentName("com.qihoo360.mobilesafe", "com.qihoo360.mobilesafe.ui.index.AppEnterActivity");
|
||||||
|
intent.setComponent(comp);
|
||||||
|
activity.startActivity(intent);
|
||||||
|
} catch (Exception e) {
|
||||||
|
openAppDetailSetting(activity);
|
||||||
|
//activity.startActivityForResult(getAppDetailSettingIntent(activity), PERMISSION_SETTING_FOR_RESULT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 系统设置界面
|
||||||
|
* @param activity
|
||||||
|
*/
|
||||||
|
public static void SystemConfig(Activity activity) {
|
||||||
|
Intent intent = new Intent(Settings.ACTION_SETTINGS);
|
||||||
|
activity.startActivity(intent);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取应用详情页面
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private static Intent getAppDetailSettingIntent(Activity activity) {
|
||||||
|
Intent localIntent = new Intent();
|
||||||
|
localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
//if (Build.VERSION.SDK_INT >= 9) {
|
||||||
|
localIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
|
||||||
|
localIntent.setData(Uri.fromParts("package", activity.getPackageName(), null));
|
||||||
|
/*} else if (Build.VERSION.SDK_INT <= 8) {
|
||||||
|
localIntent.setAction(Intent.ACTION_VIEW);
|
||||||
|
localIntent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails");
|
||||||
|
localIntent.putExtra("com.android.settings.ApplicationPkgName", activity.getPackageName());
|
||||||
|
}*/
|
||||||
|
return localIntent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void openAppDetailSetting(Activity activity) {
|
||||||
|
activity.startActivityForResult(getAppDetailSettingIntent(activity), ACTIVITY_RESULT_APP_SETTINGS);
|
||||||
|
isAppSettingOpen = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,10 +6,14 @@ package cc.winboll.studio.contacts.utils;
|
|||||||
* @Describe 联系人工具集
|
* @Describe 联系人工具集
|
||||||
*/
|
*/
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
|
import android.content.ContentUris;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
import android.net.Uri;
|
||||||
import android.provider.ContactsContract;
|
import android.provider.ContactsContract;
|
||||||
import cc.winboll.studio.libappbase.LogUtils;
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
|
import cc.winboll.studio.libappbase.utils.ToastUtils;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -120,4 +124,92 @@ public class ContactUtils {
|
|||||||
}
|
}
|
||||||
return sbSpaceNumber.toString();
|
return sbSpaceNumber.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 跳转至系统添加联系人界面的工具函数
|
||||||
|
* @param context 上下文(如 PhoneCallService、Activity、Fragment 均可,需传入有效上下文)
|
||||||
|
* @param phoneNumber 可选参数:预填的联系人电话(传 null 则跳转空表单)
|
||||||
|
*/
|
||||||
|
public static void jumpToAddContact(Context mContext, String phoneNumber) {
|
||||||
|
Intent intent = new Intent(Intent.ACTION_INSERT);
|
||||||
|
intent.setType("vnd.android.cursor.dir/person");
|
||||||
|
intent.putExtra(android.provider.ContactsContract.Intents.Insert.PHONE, phoneNumber);
|
||||||
|
mContext.startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 跳转至系统编辑联系人界面(适配小米等定制机型)
|
||||||
|
* @param context 上下文(Activity/Service/Fragment)
|
||||||
|
* @param phoneNumber 待编辑联系人的电话号码(用于匹配已有联系人,必传)
|
||||||
|
* @param contactId 可选:已有联系人的ID(通过 ContactsContract 获取,传null则自动匹配号码)
|
||||||
|
*/
|
||||||
|
public static void jumpToEditContact(Context context, String phoneNumber, Long contactId) {
|
||||||
|
Intent intent = new Intent(Intent.ACTION_EDIT);
|
||||||
|
// 关键:小米等机型需明确设置数据类型为“单个联系人”,避免参数丢失
|
||||||
|
intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
|
||||||
|
|
||||||
|
// 场景A:已知联系人ID(精准定位,优先用此方式,参数传递最稳定)
|
||||||
|
if (contactId != null && contactId > 0) {
|
||||||
|
// 构建联系人的Uri(格式:content://contacts/people/[contactId],系统标准格式)
|
||||||
|
Uri contactUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId);
|
||||||
|
intent.setData(contactUri);
|
||||||
|
//ToastUtils.show("1");
|
||||||
|
} else if (phoneNumber != null && !phoneNumber.isEmpty()) {
|
||||||
|
// 方式1:小米等机型兼容的“通过号码定位联系人”参数(部分系统认此参数)
|
||||||
|
//intent.putExtra(ContactsContract.Intents.Insert.PHONE_NUMBER, phoneNumber);
|
||||||
|
// 方式2:补充系统标准的“数据Uri”,强化匹配(避免参数被定制系统忽略)
|
||||||
|
Uri phoneUri = Uri.withAppendedPath(ContactsContract.CommonDataKinds.Phone.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
|
||||||
|
intent.setData(phoneUri);
|
||||||
|
} else {
|
||||||
|
LogUtils.d(TAG, "编辑联系人失败:电话号码和联系人ID均为空");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 可选:预填最新号码(覆盖原有号码,若用户修改了号码,编辑时自动更新)
|
||||||
|
if (phoneNumber != null && !phoneNumber.isEmpty()) {
|
||||||
|
intent.putExtra(ContactsContract.CommonDataKinds.Phone.NUMBER, phoneNumber);
|
||||||
|
intent.putExtra(ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 启动活动(加防护,避免无联系人应用崩溃)
|
||||||
|
// 小米机型在Service/非Activity中调用,需加NEW_TASK标志,否则可能无法启动
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
context.startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过电话号码查询联系人ID(适配小米机型,解决编辑时匹配不稳定问题)
|
||||||
|
* @param context 上下文
|
||||||
|
* @param phoneNumber 待查询的电话号码
|
||||||
|
* @return 联系人ID(无匹配时返回-1)
|
||||||
|
*/
|
||||||
|
public static Long getContactIdByPhone(Context context, String phoneNumber) {
|
||||||
|
if (phoneNumber == null || phoneNumber.isEmpty()) {
|
||||||
|
return -1L;
|
||||||
|
}
|
||||||
|
|
||||||
|
ContentResolver cr = context.getContentResolver();
|
||||||
|
// 1. 构建电话查询Uri(系统标准:通过号码过滤联系人数据)
|
||||||
|
Uri queryUri = Uri.withAppendedPath(ContactsContract.CommonDataKinds.Phone.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
|
||||||
|
// 2. 只查询“联系人ID”字段(高效,避免冗余数据)
|
||||||
|
String[] projection = {ContactsContract.CommonDataKinds.Phone.CONTACT_ID};
|
||||||
|
Cursor cursor = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
cursor = cr.query(queryUri, projection, null, null, null);
|
||||||
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
|
// 3. 读取联系人ID(返回Long类型,避免int溢出)
|
||||||
|
return cursor.getLong(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_ID));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtils.d(TAG, "查询联系人ID失败。" + e);
|
||||||
|
} finally {
|
||||||
|
if (cursor != null) {
|
||||||
|
cursor.close(); // 关闭游标,避免内存泄漏
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1L; // 无匹配联系人
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,8 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.widget.RemoteViews;
|
import android.widget.RemoteViews;
|
||||||
import cc.winboll.studio.contacts.R;
|
import cc.winboll.studio.contacts.R;
|
||||||
import cc.winboll.studio.contacts.threads.MainServiceThread;
|
|
||||||
import cc.winboll.studio.libappbase.LogUtils;
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
import com.hjq.toast.ToastUtils;
|
import cc.winboll.studio.libappbase.utils.ToastUtils;
|
||||||
|
|
||||||
public class APPStatusWidget extends AppWidgetProvider {
|
public class APPStatusWidget extends AppWidgetProvider {
|
||||||
|
|
||||||
|
|||||||
@@ -5,5 +5,8 @@
|
|||||||
<item
|
<item
|
||||||
android:id="@+id/item_calllog_phonenumber_copy"
|
android:id="@+id/item_calllog_phonenumber_copy"
|
||||||
android:title="Copy"/>
|
android:title="Copy"/>
|
||||||
|
<item
|
||||||
|
android:id="@+id/item_calllog_phonenumber_add_contact"
|
||||||
|
android:title="Add Contact"/>
|
||||||
|
|
||||||
</menu>
|
</menu>
|
||||||
|
|||||||
@@ -5,5 +5,8 @@
|
|||||||
<item
|
<item
|
||||||
android:id="@+id/item_contact_phonenumber_copy"
|
android:id="@+id/item_contact_phonenumber_copy"
|
||||||
android:title="Copy"/>
|
android:title="Copy"/>
|
||||||
|
<item
|
||||||
|
android:id="@+id/item_calllog_phonenumber_edit_contact"
|
||||||
|
android:title="Edit Contact"/>
|
||||||
|
|
||||||
</menu>
|
</menu>
|
||||||
|
|||||||
@@ -4,29 +4,32 @@ apply from: '../.winboll/winboll_lib_build.gradle'
|
|||||||
apply from: '../.winboll/winboll_lint_build.gradle'
|
apply from: '../.winboll/winboll_lint_build.gradle'
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 32
|
|
||||||
buildToolsVersion "32.0.0"
|
// 1. compileSdkVersion:必须 ≥ targetSdkVersion,建议直接等于 targetSdkVersion(30)
|
||||||
|
compileSdkVersion 30
|
||||||
|
|
||||||
|
// 2. buildToolsVersion:需匹配 compileSdkVersion,建议使用 30.x.x 最新稳定版(无需高于 compileSdkVersion)
|
||||||
|
buildToolsVersion "30.0.3" // 这是 30 对应的最新稳定版,避免使用 beta 版
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 24
|
minSdkVersion 23
|
||||||
targetSdkVersion 30
|
targetSdkVersion 30
|
||||||
}
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
minifyEnabled false
|
minifyEnabled false
|
||||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 米盟 SDK
|
||||||
|
packagingOptions {
|
||||||
|
doNotStrip "*/*/libmimo_1011.so"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
api fileTree(dir: 'libs', include: ['*.jar'])
|
|
||||||
api 'cc.winboll.studio:libapputils:15.8.5'
|
|
||||||
api 'cc.winboll.studio:libappbase:15.9.5'
|
|
||||||
|
|
||||||
// 吐司类库
|
|
||||||
api 'com.github.getActivity:ToastUtils:10.5'
|
|
||||||
|
|
||||||
// 权限请求框架:https://github.com/getActivity/XXPermissions
|
// 权限请求框架:https://github.com/getActivity/XXPermissions
|
||||||
api 'com.github.getActivity:XXPermissions:18.63'
|
api 'com.github.getActivity:XXPermissions:18.63'
|
||||||
// 下拉控件
|
// 下拉控件
|
||||||
@@ -52,4 +55,17 @@ dependencies {
|
|||||||
//api 'androidx.vectordrawable:vectordrawable:1.1.0'
|
//api 'androidx.vectordrawable:vectordrawable:1.1.0'
|
||||||
//api 'androidx.vectordrawable:vectordrawable-animated:1.1.0'
|
//api 'androidx.vectordrawable:vectordrawable-animated:1.1.0'
|
||||||
//api 'androidx.fragment:fragment:1.1.0'
|
//api 'androidx.fragment:fragment:1.1.0'
|
||||||
|
|
||||||
|
// 米盟
|
||||||
|
api 'com.miui.zeus:mimo-ad-sdk:5.3.+'//请使用最新版sdk
|
||||||
|
//注意:以下5个库必须要引入
|
||||||
|
//implementation '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 'cc.winboll.studio:libappbase:15.11.0'
|
||||||
|
|
||||||
|
api fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Sun Aug 31 05:00:43 CST 2025
|
#Wed Nov 26 15:54:26 GMT 2025
|
||||||
stageCount=4
|
stageCount=7
|
||||||
libraryProject=libaes
|
libraryProject=libaes
|
||||||
baseVersion=15.9
|
baseVersion=15.11
|
||||||
publishVersion=15.9.3
|
publishVersion=15.11.6
|
||||||
buildCount=0
|
buildCount=32
|
||||||
baseBetaVersion=15.9.4
|
baseBetaVersion=15.11.7
|
||||||
|
|||||||
@@ -1,9 +1,25 @@
|
|||||||
<?xml version='1.0' encoding='utf-8'?>
|
<?xml version='1.0' encoding='utf-8'?>
|
||||||
<manifest
|
<manifest
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
package="cc.winboll.studio.libaes">
|
package="cc.winboll.studio.libaes">
|
||||||
|
|
||||||
<application>
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
|
||||||
|
tools:ignore="QueryAllPackagesPermission" />
|
||||||
|
|
||||||
|
<!-- 通过GPS得到精确位置 -->
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||||
|
<!-- 通过网络得到粗略位置 -->
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||||
|
|
||||||
|
<application
|
||||||
|
android:networkSecurityConfig="@xml/network_security_config"
|
||||||
|
android:usesCleartextTraffic="true"
|
||||||
|
tools:ignore="GoogleAppIndexingWarning">
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name="cc.winboll.studio.libaes.unittests.SecondaryLibraryActivity"
|
android:name="cc.winboll.studio.libaes.unittests.SecondaryLibraryActivity"
|
||||||
@@ -33,6 +49,18 @@
|
|||||||
android:name="cc.winboll.studio.libaes.winboll.WinBoLLMail"
|
android:name="cc.winboll.studio.libaes.winboll.WinBoLLMail"
|
||||||
android:exported="true"/>
|
android:exported="true"/>
|
||||||
|
|
||||||
|
|
||||||
|
<provider
|
||||||
|
android:name="androidx.core.content.FileProvider"
|
||||||
|
android:authorities="${applicationId}.fileprovider"
|
||||||
|
android:exported="false"
|
||||||
|
android:grantUriPermissions="true">
|
||||||
|
<meta-data
|
||||||
|
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||||
|
android:resource="@xml/file_provider" />
|
||||||
|
|
||||||
|
</provider>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|||||||
@@ -23,17 +23,19 @@ import androidx.fragment.app.FragmentManager;
|
|||||||
import androidx.fragment.app.FragmentTransaction;
|
import androidx.fragment.app.FragmentTransaction;
|
||||||
import cc.winboll.studio.libaes.DrawerMenuDataAdapter;
|
import cc.winboll.studio.libaes.DrawerMenuDataAdapter;
|
||||||
import cc.winboll.studio.libaes.R;
|
import cc.winboll.studio.libaes.R;
|
||||||
import cc.winboll.studio.libaes.beans.AESThemeBean;
|
import cc.winboll.studio.libaes.models.AESThemeBean;
|
||||||
import cc.winboll.studio.libaes.beans.DrawerMenuBean;
|
import cc.winboll.studio.libaes.models.DrawerMenuBean;
|
||||||
import cc.winboll.studio.libaes.utils.AESThemeUtil;
|
import cc.winboll.studio.libaes.utils.AESThemeUtil;
|
||||||
import cc.winboll.studio.libaes.views.ADrawerMenuListView;
|
import cc.winboll.studio.libaes.views.ADrawerMenuListView;
|
||||||
import cc.winboll.studio.libappbase.GlobalApplication;
|
|
||||||
import cc.winboll.studio.libappbase.LogUtils;
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
import cc.winboll.studio.libappbase.winboll.IWinBoLLActivity;
|
|
||||||
import com.baoyz.widget.PullRefreshLayout;
|
import com.baoyz.widget.PullRefreshLayout;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
|
||||||
|
import cc.winboll.studio.libaes.views.ADsBannerView;
|
||||||
|
import cc.winboll.studio.libappbase.LogActivity;
|
||||||
|
import cc.winboll.studio.libappbase.ToastUtils;
|
||||||
|
|
||||||
public abstract class DrawerFragmentActivity extends AppCompatActivity implements IWinBoLLActivity,AdapterView.OnItemClickListener {
|
public abstract class DrawerFragmentActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
|
||||||
|
|
||||||
public static final String TAG = "DrawerFragmentActivity";
|
public static final String TAG = "DrawerFragmentActivity";
|
||||||
|
|
||||||
@@ -72,17 +74,22 @@ public abstract class DrawerFragmentActivity extends AppCompatActivity implement
|
|||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
// 修复:释放广告资源,避免内存泄漏
|
||||||
|
ADsBannerView adsBannerView = findViewById(R.id.adsbanner);
|
||||||
|
if (adsBannerView != null) {
|
||||||
|
adsBannerView.releaseAdResources();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@Override
|
/*@Override
|
||||||
public Intent getIntent() {
|
public Intent getIntent() {
|
||||||
// TODO: Implement this method
|
// TODO: Implement this method
|
||||||
return super.getIntent();
|
return super.getIntent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Context getContext() {
|
public Context getContext() {
|
||||||
return this.mContext;
|
return this.mContext;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MenuInflater getMenuInflater() {
|
public MenuInflater getMenuInflater() {
|
||||||
@@ -91,9 +98,9 @@ public abstract class DrawerFragmentActivity extends AppCompatActivity implement
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*public void setSubtitle(CharSequence context) {
|
/*public void setSubtitle(CharSequence context) {
|
||||||
// TODO: Implement this method
|
// TODO: Implement this method
|
||||||
getSupportActionBar().setSubtitle(context);
|
getSupportActionBar().setSubtitle(context);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void recreate() {
|
public void recreate() {
|
||||||
@@ -101,9 +108,9 @@ public abstract class DrawerFragmentActivity extends AppCompatActivity implement
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*@Override
|
/*@Override
|
||||||
public boolean moveTaskToBack(boolean nonRoot) {
|
public boolean moveTaskToBack(boolean nonRoot) {
|
||||||
return super.moveTaskToBack(nonRoot);
|
return super.moveTaskToBack(nonRoot);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startActivity(Intent intent) {
|
public void startActivity(Intent intent) {
|
||||||
@@ -116,24 +123,24 @@ public abstract class DrawerFragmentActivity extends AppCompatActivity implement
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*@Override
|
/*@Override
|
||||||
public FragmentManager getSupportFragmentManager() {
|
public FragmentManager getSupportFragmentManager() {
|
||||||
return super.getSupportFragmentManager();
|
return super.getSupportFragmentManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSubtitle(int resId) {
|
public void setSubtitle(int resId) {
|
||||||
// TODO: Implement this method
|
// TODO: Implement this method
|
||||||
getSupportActionBar().setSubtitle(resId);
|
getSupportActionBar().setSubtitle(resId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTitle(CharSequence context) {
|
public void setTitle(CharSequence context) {
|
||||||
// TODO: Implement this method
|
// TODO: Implement this method
|
||||||
getSupportActionBar().setTitle(context);
|
getSupportActionBar().setTitle(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTitle(int resId) {
|
public void setTitle(int resId) {
|
||||||
// TODO: Implement this method
|
// TODO: Implement this method
|
||||||
getSupportActionBar().setTitle(resId);
|
getSupportActionBar().setTitle(resId);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SharedPreferences getSharedPreferences(String name, int mode) {
|
public SharedPreferences getSharedPreferences(String name, int mode) {
|
||||||
@@ -176,8 +183,9 @@ public abstract class DrawerFragmentActivity extends AppCompatActivity implement
|
|||||||
for (int i = Integer.MIN_VALUE; i < Integer.MAX_VALUE; i++) {
|
for (int i = Integer.MIN_VALUE; i < Integer.MAX_VALUE; i++) {
|
||||||
getString(i);
|
getString(i);
|
||||||
}
|
}
|
||||||
// } else if (R.id.item_log == item.getItemId()) {
|
} else if (R.id.item_log == item.getItemId()) {
|
||||||
// GlobalApplication.getWinBoLLActivityManager().startLogActivity(this);
|
ToastUtils.show("Test");
|
||||||
|
LogActivity.startLogActivity(this);
|
||||||
} else if (R.id.item_about == item.getItemId()) {
|
} else if (R.id.item_about == item.getItemId()) {
|
||||||
LogUtils.d(TAG, "onAbout");
|
LogUtils.d(TAG, "onAbout");
|
||||||
} else if (android.R.id.home == item.getItemId()) {
|
} else if (android.R.id.home == item.getItemId()) {
|
||||||
@@ -192,6 +200,11 @@ public abstract class DrawerFragmentActivity extends AppCompatActivity implement
|
|||||||
if (checkThemeStyleChange()) {
|
if (checkThemeStyleChange()) {
|
||||||
recreate();
|
recreate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ADsBannerView adsBannerView = findViewById(R.id.adsbanner);
|
||||||
|
if (adsBannerView != null) {
|
||||||
|
adsBannerView.resumeADs(DrawerFragmentActivity.this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void initRootView() {
|
void initRootView() {
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package cc.winboll.studio.libaes.dialogs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||||
|
* @Date 2025/03/28 17:40:47
|
||||||
|
* @Date 2024/08/12 14:46:25
|
||||||
|
* @Describe 询问用户确定与否的选择框
|
||||||
|
*/
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
|
||||||
|
public class YesNoAlertDialog {
|
||||||
|
|
||||||
|
public static final String TAG = "YesNoAlertDialog";
|
||||||
|
|
||||||
|
public static void show(Context context, String szTitle, String szMessage, final OnDialogResultListener listener) {
|
||||||
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
|
||||||
|
context);
|
||||||
|
|
||||||
|
// set title
|
||||||
|
alertDialogBuilder.setTitle(szTitle);
|
||||||
|
|
||||||
|
// set dialog message
|
||||||
|
alertDialogBuilder
|
||||||
|
.setMessage(szMessage)
|
||||||
|
.setCancelable(true)
|
||||||
|
.setOnCancelListener(new DialogInterface.OnCancelListener(){
|
||||||
|
@Override
|
||||||
|
public void onCancel(DialogInterface dialog) {
|
||||||
|
listener.onNo();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setPositiveButton("YES", new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
// if this button is clicked, close
|
||||||
|
// current activity
|
||||||
|
listener.onYes();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setNegativeButton("NO", new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
// if this button is clicked, just close
|
||||||
|
// the dialog box and do nothing
|
||||||
|
dialog.cancel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// create alert dialog
|
||||||
|
AlertDialog alertDialog = alertDialogBuilder.create();
|
||||||
|
|
||||||
|
// show it
|
||||||
|
alertDialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface OnDialogResultListener {
|
||||||
|
abstract void onYes();
|
||||||
|
abstract void onNo();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package cc.winboll.studio.libaes.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||||
|
* @Date 2025/11/26 17:49
|
||||||
|
* @Describe 广告控制模式枚举
|
||||||
|
*/
|
||||||
|
public enum ADsMode {
|
||||||
|
STANDALONE("单机模式"), // 单机模式(默认)
|
||||||
|
MIMO_SDK("米盟广告SDK支持模式"); // 米盟广告SDK模式
|
||||||
|
|
||||||
|
private final String modeName;
|
||||||
|
|
||||||
|
ADsMode(String modeName) {
|
||||||
|
this.modeName = modeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getModeName() {
|
||||||
|
return modeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据保存的字符串值解析枚举(SP读取时使用)
|
||||||
|
public static ADsMode fromValue(String value) {
|
||||||
|
if (value == null) return STANDALONE;
|
||||||
|
try {
|
||||||
|
return ADsMode.valueOf(value);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
return STANDALONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package cc.winboll.studio.libaes.interfaces;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||||
|
* @Date 2025/05/10 09:34
|
||||||
|
* @Describe WinBoLL 窗口操作接口
|
||||||
|
*/
|
||||||
|
import android.app.Activity;
|
||||||
|
|
||||||
|
public abstract interface IWinBoLLActivity {
|
||||||
|
|
||||||
|
public static final String TAG = "IWinBoLLActivity";
|
||||||
|
|
||||||
|
public static final String ACTION_BIND = IWinBoLLActivity.class.getName() + ".ACTION_BIND";
|
||||||
|
|
||||||
|
public Activity getActivity();
|
||||||
|
public String getTag();
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package cc.winboll.studio.libaes.beans;
|
package cc.winboll.studio.libaes.models;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package cc.winboll.studio.libaes.winboll;
|
package cc.winboll.studio.libaes.models;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package cc.winboll.studio.libaes.beans;
|
package cc.winboll.studio.libaes.models;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package cc.winboll.studio.libaes.beans;
|
package cc.winboll.studio.libaes.models;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author ZhanGSKen
|
* @Author ZhanGSKen
|
||||||
@@ -7,7 +7,7 @@ import android.view.MenuItem;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import cc.winboll.studio.libaes.R;
|
import cc.winboll.studio.libaes.R;
|
||||||
import cc.winboll.studio.libaes.activitys.DrawerFragmentActivity;
|
import cc.winboll.studio.libaes.activitys.DrawerFragmentActivity;
|
||||||
import cc.winboll.studio.libappbase.winboll.IWinBoLLActivity;
|
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import androidx.fragment.app.Fragment;
|
|||||||
import cc.winboll.studio.libaes.R;
|
import cc.winboll.studio.libaes.R;
|
||||||
import cc.winboll.studio.libaes.views.AButton;
|
import cc.winboll.studio.libaes.views.AButton;
|
||||||
import cc.winboll.studio.libappbase.LogUtils;
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
import com.hjq.toast.ToastUtils;
|
import cc.winboll.studio.libappbase.ToastUtils;
|
||||||
|
|
||||||
public class TestAButtonFragment extends Fragment {
|
public class TestAButtonFragment extends Fragment {
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ import android.os.Bundle;
|
|||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
import cc.winboll.studio.libaes.R;
|
import cc.winboll.studio.libaes.R;
|
||||||
|
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
|
||||||
import cc.winboll.studio.libaes.utils.AESThemeUtil;
|
import cc.winboll.studio.libaes.utils.AESThemeUtil;
|
||||||
import cc.winboll.studio.libappbase.winboll.IWinBoLLActivity;
|
|
||||||
|
|
||||||
public class TestASupportToolbarActivity extends AppCompatActivity implements IWinBoLLActivity {
|
public class TestASupportToolbarActivity extends AppCompatActivity implements IWinBoLLActivity {
|
||||||
|
|
||||||
|
|||||||
@@ -10,22 +10,11 @@ import android.os.Bundle;
|
|||||||
import android.widget.Toolbar;
|
import android.widget.Toolbar;
|
||||||
import cc.winboll.studio.libaes.R;
|
import cc.winboll.studio.libaes.R;
|
||||||
import cc.winboll.studio.libaes.utils.AESThemeUtil;
|
import cc.winboll.studio.libaes.utils.AESThemeUtil;
|
||||||
import cc.winboll.studio.libappbase.winboll.IWinBoLLActivity;
|
|
||||||
|
|
||||||
public class TestAToolbarActivity extends Activity implements IWinBoLLActivity {
|
public class TestAToolbarActivity extends Activity {
|
||||||
|
|
||||||
public static final String TAG = "TestAToolbarActivity";
|
public static final String TAG = "TestAToolbarActivity";
|
||||||
|
|
||||||
@Override
|
|
||||||
public Activity getActivity() {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getTag() {
|
|
||||||
return TAG;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
AESThemeUtil.applyAppTheme(this);
|
AESThemeUtil.applyAppTheme(this);
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ import android.widget.Toast;
|
|||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import cc.winboll.studio.libaes.R;
|
import cc.winboll.studio.libaes.R;
|
||||||
import cc.winboll.studio.libaes.activitys.DrawerFragmentActivity;
|
import cc.winboll.studio.libaes.activitys.DrawerFragmentActivity;
|
||||||
import cc.winboll.studio.libaes.beans.DrawerMenuBean;
|
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
|
||||||
|
import cc.winboll.studio.libaes.models.DrawerMenuBean;
|
||||||
import cc.winboll.studio.libappbase.LogUtils;
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
import cc.winboll.studio.libappbase.winboll.IWinBoLLActivity;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class TestDrawerFragmentActivity extends DrawerFragmentActivity implements IWinBoLLActivity {
|
public class TestDrawerFragmentActivity extends DrawerFragmentActivity implements IWinBoLLActivity {
|
||||||
|
|||||||
@@ -12,14 +12,13 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.Toast;
|
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.viewpager.widget.ViewPager;
|
import androidx.viewpager.widget.ViewPager;
|
||||||
import cc.winboll.studio.libaes.ImagePagerAdapter;
|
import cc.winboll.studio.libaes.ImagePagerAdapter;
|
||||||
import cc.winboll.studio.libaes.R;
|
import cc.winboll.studio.libaes.R;
|
||||||
import cc.winboll.studio.libaes.views.AOHPCTCSeekBar;
|
import cc.winboll.studio.libaes.views.AOHPCTCSeekBar;
|
||||||
import cc.winboll.studio.libappbase.LogView;
|
import cc.winboll.studio.libappbase.LogView;
|
||||||
import com.hjq.toast.ToastUtils;
|
import cc.winboll.studio.libappbase.ToastUtils;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import android.view.MenuItem;
|
|||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import cc.winboll.studio.libaes.R;
|
import cc.winboll.studio.libaes.R;
|
||||||
import cc.winboll.studio.libaes.activitys.DrawerFragmentActivity;
|
import cc.winboll.studio.libaes.activitys.DrawerFragmentActivity;
|
||||||
import cc.winboll.studio.libaes.beans.AESThemeBean;
|
import cc.winboll.studio.libaes.models.AESThemeBean;
|
||||||
|
|
||||||
public class AESThemeUtil {
|
public class AESThemeUtil {
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package cc.winboll.studio.libaes.utils;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.DisplayMetrics;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||||
|
* @Date 2025/11/18 15:23
|
||||||
|
* @Describe 米盟 MimoUtils
|
||||||
|
*/
|
||||||
|
public final class MimoUtils {
|
||||||
|
public static final String TAG = "Utils";
|
||||||
|
|
||||||
|
public static int dpToPx(Context context, float dp) {
|
||||||
|
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
|
||||||
|
return (int) (dp * displayMetrics.density + 0.5f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int pxToDp(Context context, float px) {
|
||||||
|
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
|
||||||
|
return (int) (px / displayMetrics.density + 0.5f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int pxToSp(Context context, float pxValue) {
|
||||||
|
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
|
||||||
|
return (int) (pxValue / displayMetrics.scaledDensity + 0.5f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int spToPx(Context context, float spValue) {
|
||||||
|
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
|
||||||
|
return (int) (spValue * displayMetrics.scaledDensity + 0.5f);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
package cc.winboll.studio.libaes.utils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||||
|
* @Date 2025/03/25 04:29:19
|
||||||
|
*/
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.Application;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
|
|
||||||
|
public class MyActivityLifecycleCallbacks implements Application.ActivityLifecycleCallbacks {
|
||||||
|
|
||||||
|
public static final String TAG = "MyActivityLifecycleCallbacks";
|
||||||
|
|
||||||
|
public String mInfo = "";
|
||||||
|
|
||||||
|
public MyActivityLifecycleCallbacks() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void createActivityeInfo(Activity activity) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
Intent receivedIntent = activity.getIntent();
|
||||||
|
sb.append("\nCallingActivity : \n");
|
||||||
|
if (activity.getCallingActivity() != null) {
|
||||||
|
sb.append(activity.getCallingActivity().getPackageName());
|
||||||
|
}
|
||||||
|
sb.append("\nReceived Intent Package : \n");
|
||||||
|
sb.append(receivedIntent.getPackage());
|
||||||
|
|
||||||
|
Bundle extras = receivedIntent.getExtras();
|
||||||
|
if (extras != null) {
|
||||||
|
for (String key : extras.keySet()) {
|
||||||
|
sb.append("\nIntentInfo");
|
||||||
|
sb.append("\n键: ");
|
||||||
|
sb.append(key);
|
||||||
|
sb.append(", 值: ");
|
||||||
|
sb.append(extras.get(key));
|
||||||
|
//Log.d("IntentInfo", "键: " + key + ", 值: " + extras.get(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mInfo = sb.toString();
|
||||||
|
//Log.d("IntentInfo", "发送Intent的应用包名: " + senderPackage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showActivityeInfo() {
|
||||||
|
//ToastUtils.show("ActivityeInfo : " + mInfo);
|
||||||
|
LogUtils.d(TAG, "ActivityeInfo : " + mInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
|
||||||
|
// 在这里可以做一些初始化相关的操作,例如记录Activity的创建时间等
|
||||||
|
//System.out.println(activity.getLocalClassName() + " was created");
|
||||||
|
LogUtils.d(TAG, activity.getLocalClassName() + " was created");
|
||||||
|
createActivityeInfo(activity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityStarted(Activity activity) {
|
||||||
|
//System.out.println(activity.getLocalClassName() + " was started");
|
||||||
|
LogUtils.d(TAG, activity.getLocalClassName() + " was started");
|
||||||
|
//createActivityeInfo(activity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityResumed(Activity activity) {
|
||||||
|
//System.out.println(activity.getLocalClassName() + " was resumed");
|
||||||
|
LogUtils.d(TAG, activity.getLocalClassName() + " was resumed");
|
||||||
|
//createActivityeInfo(activity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityPaused(Activity activity) {
|
||||||
|
//System.out.println(activity.getLocalClassName() + " was paused");
|
||||||
|
LogUtils.d(TAG, activity.getLocalClassName() + " was paused");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityStopped(Activity activity) {
|
||||||
|
//System.out.println(activity.getLocalClassName() + " was stopped");
|
||||||
|
LogUtils.d(TAG, activity.getLocalClassName() + " was stopped");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
|
||||||
|
// 可以在这里添加保存状态的自定义逻辑
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityDestroyed(Activity activity) {
|
||||||
|
//System.out.println(activity.getLocalClassName() + " was destroyed");
|
||||||
|
LogUtils.d(TAG, activity.getLocalClassName() + " was destroyed");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package cc.winboll.studio.libaes.utils;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||||
|
* @Date 2025/11/13 06:50
|
||||||
|
* @Describe 应用变量保存工具
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class PrefUtils {
|
||||||
|
|
||||||
|
public static final String TAG = "PrefUtils";
|
||||||
|
|
||||||
|
//
|
||||||
|
// 保存字符串到SharedPreferences的函数
|
||||||
|
//
|
||||||
|
public static void saveString(Context context, String key, String value) {
|
||||||
|
SharedPreferences sharedPreferences = context.getSharedPreferences("myPrefs", Context.MODE_PRIVATE);
|
||||||
|
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||||
|
editor.putString(key, value);
|
||||||
|
editor.apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// 从SharedPreferences读取字符串的函数
|
||||||
|
//
|
||||||
|
public static String getString(Context context, String key, String defaultValue) {
|
||||||
|
SharedPreferences sharedPreferences = context.getSharedPreferences("myPrefs", Context.MODE_PRIVATE);
|
||||||
|
return sharedPreferences.getString(key, defaultValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,292 @@
|
|||||||
|
package cc.winboll.studio.libaes.utils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||||
|
* @Date 2025/05/10 10:02
|
||||||
|
* @Describe 应用活动窗口管理器
|
||||||
|
* 参考 :
|
||||||
|
* android 类似微信小程序多任务窗口 及 设置 TaskDescription 修改 icon 和 label
|
||||||
|
* https://blog.csdn.net/qq_29364417/article/details/109379915?app_version=6.4.2&code=app_1562916241&csdn_share_tail=%7B%22type%22%3A%22blog%22%2C%22rType%22%3A%22article%22%2C%22rId%22%3A%22109379915%22%2C%22source%22%3A%22weixin_38986226%22%7D&uLinkId=usr1mkqgl919blen&utm_source=app
|
||||||
|
*/
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.ActivityManager;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
|
||||||
|
import cc.winboll.studio.libappbase.GlobalApplication;
|
||||||
|
import cc.winboll.studio.libappbase.LogActivity;
|
||||||
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
|
import cc.winboll.studio.libappbase.ToastUtils;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class WinBoLLActivityManager {
|
||||||
|
|
||||||
|
public static final String TAG = "WinBoLLActivityManager";
|
||||||
|
|
||||||
|
public static final String EXTRA_TAG = "EXTRA_TAG";
|
||||||
|
|
||||||
|
|
||||||
|
public enum WinBoLLUI_TYPE { Aplication, Service }
|
||||||
|
|
||||||
|
GlobalApplication mGlobalApplication;
|
||||||
|
volatile static WinBoLLActivityManager _mIWinBoLLActivityManager;
|
||||||
|
Map<String, IWinBoLLActivity> mActivityListMap;
|
||||||
|
|
||||||
|
volatile static WinBoLLUI_TYPE _WinBoLLUI_TYPE = WinBoLLUI_TYPE.Service;
|
||||||
|
public static void setWinBoLLUI_TYPE(WinBoLLUI_TYPE winBoLLUI_TYPE) {
|
||||||
|
_WinBoLLUI_TYPE = winBoLLUI_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WinBoLLUI_TYPE getWinBoLLUI_TYPE() {
|
||||||
|
return _WinBoLLUI_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
WinBoLLActivityManager(GlobalApplication application) {
|
||||||
|
mGlobalApplication = application;
|
||||||
|
mActivityListMap = new HashMap<String, IWinBoLLActivity>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WinBoLLActivityManager getInstance() {
|
||||||
|
return _mIWinBoLLActivityManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized <T extends GlobalApplication> void init(T application) {
|
||||||
|
if (_mIWinBoLLActivityManager == null) {
|
||||||
|
_mIWinBoLLActivityManager = new WinBoLLActivityManager(application);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 把Activity添加到管理中
|
||||||
|
*/
|
||||||
|
public <T extends IWinBoLLActivity> void add(T activity) {
|
||||||
|
if (isActivityActive(activity.getTag())) {
|
||||||
|
LogUtils.d(TAG, String.format("add(...) %s is active.", activity.getTag()));
|
||||||
|
} else {
|
||||||
|
mActivityListMap.put(activity.getTag(), activity);
|
||||||
|
LogUtils.d(TAG, String.format("Add activity : %s\n_mapActivityList.size() : %d", activity.getTag(), mActivityListMap.size()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// activity: 为 null 时,
|
||||||
|
// intent.putExtra 函数 "tag" 参数为 tag
|
||||||
|
// activity: 不为 null 时,
|
||||||
|
// intent.putExtra 函数 "tag" 参数为 activity.getTag()
|
||||||
|
//
|
||||||
|
public <T extends IWinBoLLActivity> void startWinBoLLActivity(Context context, Class<T> clazz) {
|
||||||
|
// 如果窗口已存在就重启窗口
|
||||||
|
if (!resumeActivity(clazz)) {
|
||||||
|
// 新建一个任务窗口
|
||||||
|
Intent intent = new Intent(context, clazz);
|
||||||
|
//打开多任务窗口 flags
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
|
||||||
|
//intent.putExtra("tag", tag);
|
||||||
|
context.startActivity(intent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T extends IWinBoLLActivity> void startWinBoLLActivity(Context context, Intent intent, Class<T> clazz) {
|
||||||
|
// 如果窗口已存在就重启窗口
|
||||||
|
if (!resumeActivity(clazz)) {
|
||||||
|
// 新建一个任务窗口
|
||||||
|
//Intent intent = new Intent(context, clazz);
|
||||||
|
//打开多任务窗口 flags
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
|
||||||
|
//intent.putExtra("tag", tag);
|
||||||
|
context.startActivity(intent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T extends IWinBoLLActivity> void startLogActivity(Context context) {
|
||||||
|
// 如果窗口已存在就重启窗口
|
||||||
|
//if (!resumeActivity(LogActivity.class)) {
|
||||||
|
// 新建一个任务窗口
|
||||||
|
Intent intent = new Intent(context, LogActivity.class);
|
||||||
|
//打开多任务窗口 flags
|
||||||
|
// Define the bounds.
|
||||||
|
// Rect bounds = new Rect(0, 0, 800, 200);
|
||||||
|
// // Set the bounds as an activity option.
|
||||||
|
// ActivityOptions options = ActivityOptions.makeBasic();
|
||||||
|
// options.setLaunchBounds(bounds);
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
|
||||||
|
|
||||||
|
//intent.putExtra(EXTRA_TAG, tag);
|
||||||
|
|
||||||
|
//context.startActivity(intent, options.toBundle());
|
||||||
|
context.startActivity(intent);
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// 判断 tag 绑定的 Activity 是否已经创建
|
||||||
|
//
|
||||||
|
public boolean isActivityActive(String tag) {
|
||||||
|
return mActivityListMap.get(tag) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Activity getActivityByTag(String tag) {
|
||||||
|
return (mActivityListMap.get(tag) == null) ?null: mActivityListMap.get(tag).getActivity();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// 找到tag 绑定的 BaseActivity ,通过 getTaskId() 移动到前台
|
||||||
|
//
|
||||||
|
public <T extends IWinBoLLActivity> boolean resumeActivity(Class<T> clazz) {
|
||||||
|
try {
|
||||||
|
Activity activity = getActivityByTag(clazz.newInstance().getTag());
|
||||||
|
if (activity != null) {
|
||||||
|
return resumeActivity(activity);
|
||||||
|
}
|
||||||
|
} catch (InstantiationException | IllegalAccessException e) {
|
||||||
|
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// 找到tag 绑定的 BaseActivity ,通过 getTaskId() 移动到前台
|
||||||
|
//
|
||||||
|
public <T extends IWinBoLLActivity> boolean resumeActivity(String tag) {
|
||||||
|
Activity activity = getActivityByTag(tag);
|
||||||
|
if (activity != null) {
|
||||||
|
return resumeActivity(activity);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// 找到tag 绑定的 BaseActivity ,通过 getTaskId() 移动到前台
|
||||||
|
//
|
||||||
|
public <T extends IWinBoLLActivity> boolean resumeActivity(Activity activity) {
|
||||||
|
ActivityManager am = (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE);
|
||||||
|
//返回启动它的根任务(home 或者 MainActivity)
|
||||||
|
//Intent intent = new Intent(mContext, activity.getClass());
|
||||||
|
//TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);
|
||||||
|
//stackBuilder.addNextIntentWithParentStack(intent);
|
||||||
|
//stackBuilder.startActivities();
|
||||||
|
am.moveTaskToFront(activity.getTaskId(), ActivityManager.MOVE_TASK_NO_USER_ACTION);
|
||||||
|
//ToastUtils.show("resumeActivity");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 结束所有 Activity
|
||||||
|
*/
|
||||||
|
public void finishAll() {
|
||||||
|
try {
|
||||||
|
//ToastUtils.show(String.format("finishAll() size : %d", _mIWinBoLLActivityList.size()));
|
||||||
|
for (int i = mActivityListMap.size() - 1; i > -1; i--) {
|
||||||
|
IWinBoLLActivity iWinBoLLActivity = mActivityListMap.get(i);
|
||||||
|
ToastUtils.show("finishAll() activity");
|
||||||
|
if (iWinBoLLActivity != null && iWinBoLLActivity.getActivity() != null && !iWinBoLLActivity.getActivity().isFinishing() && !iWinBoLLActivity.getActivity().isDestroyed()) {
|
||||||
|
//ToastUtils.show("activity != null ...");
|
||||||
|
if (getWinBoLLUI_TYPE() == WinBoLLUI_TYPE.Service) {
|
||||||
|
// 结束窗口和最近任务栏, 建议前台服务类应用使用,可以方便用户再次调用 UI 操作。
|
||||||
|
iWinBoLLActivity.getActivity().finishAndRemoveTask();
|
||||||
|
//ToastUtils.show("finishAll() activity.finishAndRemoveTask();");
|
||||||
|
} else if (getWinBoLLUI_TYPE() == WinBoLLUI_TYPE.Aplication) {
|
||||||
|
// 结束窗口保留最近任务栏,建议前台服务类应用使用,可以保持应用的系统自觉性。
|
||||||
|
iWinBoLLActivity.getActivity().finish();
|
||||||
|
//ToastUtils.show("finishAll() activity.finish();");
|
||||||
|
} else {
|
||||||
|
ToastUtils.show("WinBollApplication.WinBollUI_TYPE error.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 结束指定Activity
|
||||||
|
*/
|
||||||
|
public <T extends IWinBoLLActivity> void finish(T iWinBoLLActivity) {
|
||||||
|
try {
|
||||||
|
if (iWinBoLLActivity != null && iWinBoLLActivity.getActivity() != null && !iWinBoLLActivity.getActivity().isFinishing() && !iWinBoLLActivity.getActivity().isDestroyed()) {
|
||||||
|
//根据tag 移除 MyActivity
|
||||||
|
//String tag= activity.getTag();
|
||||||
|
//_mIWinBoLLActivityList.remove(tag);
|
||||||
|
//ToastUtils.show("remove");
|
||||||
|
//ToastUtils.show("_mIWinBoLLActivityArrayMap.size() " + Integer.toString(_mIWinBoLLActivityArrayMap.size()));
|
||||||
|
|
||||||
|
// 窗口回调规则:
|
||||||
|
// [] 当前窗口位置 >> 调度出的窗口位置
|
||||||
|
// ★:[0] 1 2 3 4 >> 1
|
||||||
|
// ★:0 1 [2] 3 4 >> 1
|
||||||
|
// ★:0 1 2 [3] 4 >> 2
|
||||||
|
// ★:0 1 2 3 [4] >> 3
|
||||||
|
// ★:[0] >> 直接关闭当前窗口
|
||||||
|
Activity preActivity = getPreActivity(iWinBoLLActivity);
|
||||||
|
iWinBoLLActivity.getActivity().finish();
|
||||||
|
if (preActivity != null) {
|
||||||
|
resumeActivity(preActivity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Activity getPreActivity(IWinBoLLActivity iWinBoLLActivity) {
|
||||||
|
try {
|
||||||
|
boolean bingo = false;
|
||||||
|
IWinBoLLActivity preIWinBoLLActivity = null;
|
||||||
|
for (Map.Entry<String, IWinBoLLActivity> entity : mActivityListMap.entrySet()) {
|
||||||
|
if (entity.getKey().equals(iWinBoLLActivity.getTag())) {
|
||||||
|
bingo = true;
|
||||||
|
LogUtils.d(TAG, "bingo");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
preIWinBoLLActivity = entity.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bingo) {
|
||||||
|
return preIWinBoLLActivity.getActivity();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T extends IWinBoLLActivity> boolean registeRemove(T iWinBoLLActivity) {
|
||||||
|
IWinBoLLActivity iWinBoLLActivityTest = mActivityListMap.get(iWinBoLLActivity.getTag());
|
||||||
|
if (iWinBoLLActivityTest != null) {
|
||||||
|
mActivityListMap.remove(iWinBoLLActivity.getTag());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void printAvtivityListInfo() {
|
||||||
|
if (!mActivityListMap.isEmpty()) {
|
||||||
|
StringBuilder sb = new StringBuilder("Map entries : " + Integer.toString(mActivityListMap.size()));
|
||||||
|
Iterator<Map.Entry<String, IWinBoLLActivity>> iterator = mActivityListMap.entrySet().iterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
Map.Entry<String, IWinBoLLActivity> entry = iterator.next();
|
||||||
|
sb.append("\nKey: " + entry.getKey() + ", \nValue: " + entry.getValue().getTag());
|
||||||
|
//ToastUtils.show("\nKey: " + entry.getKey() + ", Value: " + entry.getValue().getTag());
|
||||||
|
}
|
||||||
|
sb.append("\nMap entries end.");
|
||||||
|
LogUtils.d(TAG, sb.toString());
|
||||||
|
} else {
|
||||||
|
LogUtils.d(TAG, "The map is empty.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,498 @@
|
|||||||
|
package cc.winboll.studio.libaes.views;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.Display;
|
||||||
|
import android.view.Gravity;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.view.Window;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.Toast;
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import cc.winboll.studio.libaes.R;
|
||||||
|
import cc.winboll.studio.libaes.utils.MimoUtils;
|
||||||
|
import cc.winboll.studio.libappbase.GlobalApplication;
|
||||||
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
|
import cc.winboll.studio.libappbase.ToastUtils;
|
||||||
|
import com.miui.zeus.mimo.sdk.ADParams;
|
||||||
|
import com.miui.zeus.mimo.sdk.BannerAd;
|
||||||
|
import com.miui.zeus.mimo.sdk.MimoCustomController;
|
||||||
|
import com.miui.zeus.mimo.sdk.MimoLocation;
|
||||||
|
import com.miui.zeus.mimo.sdk.MimoSdk;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import cc.winboll.studio.libaes.enums.ADsMode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||||
|
* @Date 2025/11/18 14:41
|
||||||
|
* @Describe WinBoLL 横幅广告类
|
||||||
|
*/
|
||||||
|
public class ADsBannerView extends LinearLayout {
|
||||||
|
|
||||||
|
public static final String TAG = "ADsBannerView";
|
||||||
|
|
||||||
|
|
||||||
|
private String BANNER_POS_ID = "802e356f1726f9ff39c69308bfd6f06a";
|
||||||
|
private String BANNER_POS_ID_WINBOLL_BETA = "d129ee5a263911f981a6dc7a9802e3e7";
|
||||||
|
private String BANNER_POS_ID_WINBOLL = "4ec30efdb32271765b9a4efac902828b";
|
||||||
|
|
||||||
|
/*
|
||||||
|
private String BANNER_POS_ID = "802e356f1726f9ff39c69308bfd6f06a";
|
||||||
|
private String BANNER_POS_ID_WINBOLL_BETA = "802e356f1726f9ff39c69308bfd6f06a";
|
||||||
|
private String BANNER_POS_ID_WINBOLL = "802e356f1726f9ff39c69308bfd6f06a";
|
||||||
|
*/
|
||||||
|
|
||||||
|
Context mContext;
|
||||||
|
View mMianView;
|
||||||
|
SharedPreferences mSharedPreferences;
|
||||||
|
ViewGroup mContainer;
|
||||||
|
BannerAd mBannerAd;
|
||||||
|
List<BannerAd> mAllBanners = new ArrayList<>();
|
||||||
|
// 新增:主线程Handler,确保广告操作在主线程执行
|
||||||
|
private Handler mMainHandler;
|
||||||
|
|
||||||
|
public ADsBannerView(Context context) {
|
||||||
|
super(context);
|
||||||
|
initView(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ADsBannerView(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
initView(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ADsBannerView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
initView(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ADsBannerView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||||
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
|
initView(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
void initView(Context context) {
|
||||||
|
this.mContext = context;
|
||||||
|
|
||||||
|
initMimoSdk(this.mContext);
|
||||||
|
|
||||||
|
// 初始化主线程Handler(关键:确保广告操作在主线程执行)
|
||||||
|
mMainHandler = new Handler(Looper.getMainLooper());
|
||||||
|
|
||||||
|
this.mMianView = inflate(this.mContext, R.layout.view_adsbanner, null);
|
||||||
|
mContainer = this.mMianView.findViewById(R.id.ads_container);
|
||||||
|
addView(this.mMianView);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resumeADs(final Activity activity) {
|
||||||
|
// 没有设置米盟广告支持就退出
|
||||||
|
if (ADsControlView.getAdsModeFromStatic(this.mContext) != ADsMode.MIMO_SDK) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修复:优化广告请求逻辑(添加生命周期判断 + 主线程执行)
|
||||||
|
if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
|
||||||
|
if (ADsControlView.getAdsModeFromStatic(this.mContext) == ADsMode.MIMO_SDK) {
|
||||||
|
LogUtils.i(TAG, "已设置播放米盟广告,正在播放...");
|
||||||
|
mMainHandler.postDelayed(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
// 再次校验生命周期,避免延迟执行时Activity已销毁
|
||||||
|
if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
|
||||||
|
fetchAd(activity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 1000); // 延迟1秒请求广告,提升页面加载体验
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 释放广告资源(关键:避免内存泄漏和空Context调用)
|
||||||
|
*/
|
||||||
|
public void releaseAdResources() {
|
||||||
|
// 没有设置米盟广告支持就退出
|
||||||
|
if (ADsControlView.getAdsModeFromStatic(this.mContext) != ADsMode.MIMO_SDK) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LogUtils.d(TAG, "releaseAdResources()");
|
||||||
|
|
||||||
|
// 移除Handler回调
|
||||||
|
if (mMainHandler != null) {
|
||||||
|
mMainHandler.removeCallbacksAndMessages(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 销毁所有广告实例
|
||||||
|
if (mAllBanners != null && !mAllBanners.isEmpty()) {
|
||||||
|
for (BannerAd ad : mAllBanners) {
|
||||||
|
if (ad != null) {
|
||||||
|
ad.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mAllBanners.clear();
|
||||||
|
}
|
||||||
|
// 置空当前广告引用
|
||||||
|
mBannerAd = null;
|
||||||
|
// 移除广告容器中的视图
|
||||||
|
if (mContainer != null) {
|
||||||
|
mContainer.removeAllViews();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示广告(核心修复:传递安全的Context + 生命周期校验)
|
||||||
|
*/
|
||||||
|
private void showAd(final Activity activity) {
|
||||||
|
// 没有设置米盟广告支持就退出
|
||||||
|
if (ADsControlView.getAdsModeFromStatic(this.mContext) != ADsMode.MIMO_SDK) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LogUtils.d(TAG, "showAd()");
|
||||||
|
// 1. 生命周期校验:避免Activity已销毁时操作UI
|
||||||
|
if (activity == null || activity.isFinishing() || activity.isDestroyed()) {
|
||||||
|
LogUtils.e(TAG, "showAd: Activity is finishing or destroyed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 2. 非空校验:广告实例和容器
|
||||||
|
if (mBannerAd == null || mContainer == null) {
|
||||||
|
LogUtils.e(TAG, "showAd: BannerAd or Container is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 3. 创建广告容器(使用ApplicationContext避免内存泄漏)
|
||||||
|
final FrameLayout container = new FrameLayout(activity.getApplicationContext());
|
||||||
|
container.setPadding(0, 0, 0, MimoUtils.dpToPx(activity, 10));
|
||||||
|
mContainer.addView(container, new FrameLayout.LayoutParams(
|
||||||
|
FrameLayout.LayoutParams.MATCH_PARENT,
|
||||||
|
FrameLayout.LayoutParams.WRAP_CONTENT
|
||||||
|
));
|
||||||
|
|
||||||
|
// if (mIsBiddingWin) {
|
||||||
|
// mBannerAd.setPrice(getPrice());
|
||||||
|
// }
|
||||||
|
// 4. 显示广告:传递ApplicationContext,避免Activity Context失效
|
||||||
|
mBannerAd.showAd(activity, container, new BannerAd.BannerInteractionListener() {
|
||||||
|
@Override
|
||||||
|
public void onAdClick() {
|
||||||
|
LogUtils.d(TAG, "onAdClick");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAdShow() {
|
||||||
|
LogUtils.d(TAG, "onAdShow");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAdDismiss() {
|
||||||
|
LogUtils.d(TAG, "onAdDismiss");
|
||||||
|
// 修复:移除容器时校验Activity状态
|
||||||
|
if (activity != null && !activity.isFinishing() && !activity.isDestroyed() && mContainer != null) {
|
||||||
|
mContainer.removeView(container);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRenderSuccess() {
|
||||||
|
LogUtils.d(TAG, "onRenderSuccess");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRenderFail(int code, String msg) {
|
||||||
|
LogUtils.e(TAG, "onRenderFail errorCode " + code + " errorMsg " + msg);
|
||||||
|
// 修复:渲染失败时移除容器
|
||||||
|
if (activity != null && !activity.isFinishing() && !activity.isDestroyed() && mContainer != null) {
|
||||||
|
mContainer.removeView(container);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求广告(核心修复:Context安全校验 + 异常捕获 + 资源管理)
|
||||||
|
*/
|
||||||
|
private void fetchAd(final Activity activity) {
|
||||||
|
// 没有设置米盟广告支持就退出
|
||||||
|
if (ADsControlView.getAdsModeFromStatic(this.mContext) != ADsMode.MIMO_SDK) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LogUtils.d(TAG, "fetchAd()");
|
||||||
|
// 1. 双重校验:Activity未销毁 + Context非空
|
||||||
|
if (activity == null || activity.isFinishing() || activity.isDestroyed() || activity.getApplicationContext() == null) {
|
||||||
|
LogUtils.e(TAG, "fetchAd: Invalid Context or Activity state");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 2. 释放之前的广告资源,避免内存泄漏
|
||||||
|
if (mBannerAd != null) {
|
||||||
|
mBannerAd.destroy();
|
||||||
|
}
|
||||||
|
// 3. 初始化广告(使用ApplicationContext,避免Activity Context失效)
|
||||||
|
try {
|
||||||
|
mBannerAd = new BannerAd();
|
||||||
|
mAllBanners.add(mBannerAd);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtils.e(TAG, "fetchAd: Init BannerAd failed", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 4. 设置下载监听
|
||||||
|
mBannerAd.setDownLoadListener(new BannerAd.BannerDownloadListener() {
|
||||||
|
@Override
|
||||||
|
public void onDownloadStarted() {
|
||||||
|
LogUtils.d(TAG, "onDownloadStarted");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDownloadPaused() {
|
||||||
|
LogUtils.d(TAG, "onDownloadPaused");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDownloadFailed(int errorCode) {
|
||||||
|
String msg = "onDownloadFailed, errorCode = " + errorCode;
|
||||||
|
LogUtils.d(TAG, msg);
|
||||||
|
//ToastUtils.show(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDownloadFinished() {
|
||||||
|
LogUtils.d(TAG, "onDownloadFinished");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDownloadProgressUpdated(int progress) {
|
||||||
|
LogUtils.d(TAG, "onDownloadProgressUpdated " + progress + "%");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInstallFailed(int errorCode) {
|
||||||
|
LogUtils.d(TAG, "onInstallFailed, errorCode = " + errorCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInstallStart() {
|
||||||
|
LogUtils.d(TAG, "onInstallStart");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInstallSuccess() {
|
||||||
|
LogUtils.d(TAG, "onInstallSuccess");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDownloadCancel() {
|
||||||
|
LogUtils.d(TAG, "onDownloadCancel");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 5. 构建广告参数并请求
|
||||||
|
String currentAD_ID = getAD_ID();
|
||||||
|
LogUtils.d(TAG, String.format("currentAD_ID = %s", currentAD_ID));
|
||||||
|
ADParams params = new ADParams.Builder().setUpId(currentAD_ID).build();
|
||||||
|
mBannerAd.loadAd(params, new BannerAd.BannerLoadListener() {
|
||||||
|
@Override
|
||||||
|
public void onBannerAdLoadSuccess() {
|
||||||
|
LogUtils.d(TAG, "onBannerAdLoadSuccess()");
|
||||||
|
// 修复:广告加载成功后校验Activity状态
|
||||||
|
if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
|
||||||
|
showAd(activity);
|
||||||
|
//ToastUtils.show("showAd()");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAdLoadFailed(int errorCode, String errorMsg) {
|
||||||
|
String msg = "onAdLoadFailed: errorCode = " + errorCode + ", errorMsg = " + errorMsg;
|
||||||
|
LogUtils.d(TAG, msg);
|
||||||
|
removeAllBanners();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void removeAllBanners() {
|
||||||
|
// 没有设置米盟广告支持就退出
|
||||||
|
if (ADsControlView.getAdsModeFromStatic(this.mContext) != ADsMode.MIMO_SDK) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修复:加载失败时移除当前广告实例
|
||||||
|
if (mAllBanners.contains(mBannerAd)) {
|
||||||
|
mAllBanners.remove(mBannerAd);
|
||||||
|
}
|
||||||
|
mBannerAd.destroy();
|
||||||
|
mBannerAd = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据当前秒数获取广告ID(原逻辑保留)
|
||||||
|
*/
|
||||||
|
private String getAD_ID() {
|
||||||
|
long currentSecond = System.currentTimeMillis() / 1000;
|
||||||
|
return (currentSecond % 2 == 0) ? BANNER_POS_ID :
|
||||||
|
(GlobalApplication.isDebugging() ? BANNER_POS_ID_WINBOLL_BETA : BANNER_POS_ID_WINBOLL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取广告价格(原逻辑保留,添加空指针校验)
|
||||||
|
*/
|
||||||
|
// private long getPrice() {
|
||||||
|
// if (mBannerAd == null) {
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
// Map<String, Object> map = mBannerAd.getMediaExtraInfo();
|
||||||
|
// if (map == null || map.isEmpty() || !map.containsKey("price")) {
|
||||||
|
// LogUtils.w(TAG, "getPrice: media extra info is null or no price key");
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
// Object priceObj = map.get("price");
|
||||||
|
// if (priceObj instanceof Long) {
|
||||||
|
// return (Long) priceObj;
|
||||||
|
// } else if (priceObj instanceof Integer) {
|
||||||
|
// return ((Integer) priceObj).longValue();
|
||||||
|
// } else {
|
||||||
|
// LogUtils.e(TAG, "getPrice: price type is invalid");
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示隐私协议弹窗(原逻辑保留,优化Context使用)
|
||||||
|
*/
|
||||||
|
// private void showPrivacy() {
|
||||||
|
// // 校验Activity状态,避免弹窗泄露
|
||||||
|
// if (getActivity() == null || getActivity().isFinishing() || getActivity().isDestroyed()) {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// ADsMode adsMode = ADsControlView.getAdsModeFromStatic(this.mContext);
|
||||||
|
// if (adsMode == ADsMode.STANDALONE) {
|
||||||
|
// ADsControlView.updateAdsModeByStatic(this.mContext, ADsMode.STANDALONE);
|
||||||
|
// LogUtils.i(TAG, "单机模式,广告已处于不可用状态...");
|
||||||
|
// Toast.makeText(getActivity().getApplicationContext(), "单机模式,广告已处于不可用状态...", Toast.LENGTH_SHORT).show();
|
||||||
|
// return;
|
||||||
|
// } else if (adsMode == ADsMode.MIMO_SDK) {
|
||||||
|
// ADsControlView.updateAdsModeByStatic(this.mContext, ADsMode.MIMO_SDK);
|
||||||
|
// LogUtils.i(TAG, "米盟广告SDK支持模式,现在初始化SDK...");
|
||||||
|
// initMimoSdk();
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// else {
|
||||||
|
// LogUtils.i(TAG, "开始弹出隐私协议...");
|
||||||
|
// AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
|
// builder.setTitle("用户须知");
|
||||||
|
// builder.setMessage("小米广告SDK隐私政策: https://dev.mi.com/distribute/doc/details?pId=1688, 请复制到浏览器查看");
|
||||||
|
// builder.setIcon(R.drawable.ic_launcher);
|
||||||
|
// builder.setCancelable(false); // 点击对话框以外的区域不消失
|
||||||
|
// builder.setPositiveButton("同意", new DialogInterface.OnClickListener() {
|
||||||
|
// @Override
|
||||||
|
// public void onClick(DialogInterface dialog, int which) {
|
||||||
|
// getSharedPreferences().edit()
|
||||||
|
// .putString(PRIVACY_VALUE, String.valueOf(1))
|
||||||
|
// .apply();
|
||||||
|
// initMimoSdk();
|
||||||
|
// dialog.dismiss();
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// builder.setNegativeButton("拒绝", new DialogInterface.OnClickListener() {
|
||||||
|
// @Override
|
||||||
|
// public void onClick(DialogInterface dialog, int which) {
|
||||||
|
// getSharedPreferences().edit()
|
||||||
|
// .putString(PRIVACY_VALUE, String.valueOf(0))
|
||||||
|
// .apply();
|
||||||
|
// dialog.dismiss();
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// AlertDialog dialog = builder.create();
|
||||||
|
//
|
||||||
|
// // 配置弹窗位置(底部全屏)
|
||||||
|
// Window window = dialog.getWindow();
|
||||||
|
// if (window != null) {
|
||||||
|
// window.setGravity(Gravity.BOTTOM);
|
||||||
|
// WindowManager m = getActivity().getWindowManager();
|
||||||
|
// Display d = m.getDefaultDisplay();
|
||||||
|
// WindowManager.LayoutParams p = window.getAttributes();
|
||||||
|
// p.width = d.getWidth();
|
||||||
|
// window.setAttributes(p);
|
||||||
|
// }
|
||||||
|
// dialog.show();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化米盟SDK(核心修复:传递ApplicationContext + 异常捕获)
|
||||||
|
*/
|
||||||
|
private void initMimoSdk(Context context) {
|
||||||
|
// 1. 安全获取ApplicationContext,避免Activity Context失效
|
||||||
|
Context appContext = context.getApplicationContext();
|
||||||
|
if (appContext == null) {
|
||||||
|
LogUtils.e(TAG, "initMimoSdk: ApplicationContext is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 2. 初始化SDK,捕获异常避免崩溃
|
||||||
|
try {
|
||||||
|
MimoSdk.init(appContext, new MimoCustomController() {
|
||||||
|
@Override
|
||||||
|
public boolean isCanUseLocation() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MimoLocation getMimoLocation() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCanUseWifiState() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean alist() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}, new MimoSdk.InitCallback() {
|
||||||
|
@Override
|
||||||
|
public void success() {
|
||||||
|
LogUtils.d(TAG, "MimoSdk init success");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fail(int code, String msg) {
|
||||||
|
LogUtils.e(TAG, "MimoSdk init fail, code=" + code + ",msg=" + msg);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
MimoSdk.setDebugOn(true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtils.e(TAG, "initMimoSdk: init failed", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取SharedPreferences实例(原逻辑保留,添加空指针校验)
|
||||||
|
*/
|
||||||
|
// SharedPreferences getSharedPreferences() {
|
||||||
|
//// if (mSharedPreferences == null) {
|
||||||
|
//// // 修复:使用ApplicationContext获取SharedPreferences,避免Activity Context泄露
|
||||||
|
//// Context appContext = getActivity().getApplicationContext();
|
||||||
|
//// if (appContext != null) {
|
||||||
|
//// mSharedPreferences = appContext.getSharedPreferences(PRIVACY_FILE, Context.MODE_PRIVATE);
|
||||||
|
//// } else {
|
||||||
|
//// LogUtils.e(TAG, "getSharedPreferences: ApplicationContext is null");
|
||||||
|
//// // 降级方案:若ApplicationContext为空,使用Activity Context(仅作兼容)
|
||||||
|
//// mSharedPreferences = getActivity().getSharedPreferences(PRIVACY_FILE, Context.MODE_PRIVATE);
|
||||||
|
//// }
|
||||||
|
//// }
|
||||||
|
// return mSharedPreferences;
|
||||||
|
// }
|
||||||
|
}
|
||||||
@@ -0,0 +1,484 @@
|
|||||||
|
package cc.winboll.studio.libaes.views;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.Display;
|
||||||
|
import android.view.Gravity;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.Window;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.RadioButton;
|
||||||
|
import android.widget.RadioGroup;
|
||||||
|
import android.widget.Toast;
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import cc.winboll.studio.libaes.R;
|
||||||
|
import cc.winboll.studio.libaes.enums.ADsMode;
|
||||||
|
import cc.winboll.studio.libaes.views.ADsControlView;
|
||||||
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
|
import com.miui.zeus.mimo.sdk.MimoCustomController;
|
||||||
|
import com.miui.zeus.mimo.sdk.MimoLocation;
|
||||||
|
import com.miui.zeus.mimo.sdk.MimoSdk;
|
||||||
|
import cc.winboll.studio.libappbase.ToastUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||||
|
* @Date 2025/11/26 17:51
|
||||||
|
* @Describe 广告模式控制控件(Java 7 兼容)
|
||||||
|
* 支持:SP持久化、外部静态方法更新、Handler视图同步、外部静态方法读取
|
||||||
|
*/
|
||||||
|
public class ADsControlView extends LinearLayout {
|
||||||
|
public static final String TAG = "ADsControlView";
|
||||||
|
|
||||||
|
|
||||||
|
// SP存储配置
|
||||||
|
private static final String SP_NAME = "ads_control_config";
|
||||||
|
private static final String KEY_SELECTED_MODE = "selected_ads_mode";
|
||||||
|
// 单机模式与米盟模式标志位
|
||||||
|
ADsMode mADsMode;
|
||||||
|
private static final String PRIVACY_VALUE = "privacy_value";
|
||||||
|
// 隐私协议签约结果 0: 拒绝,1:赞同 2: 未签约
|
||||||
|
String privacyAgreeValue;
|
||||||
|
|
||||||
|
// Handler消息标识
|
||||||
|
private static final int MSG_UPDATE_MODE = 1001;
|
||||||
|
|
||||||
|
// 控件引用
|
||||||
|
private RadioGroup rgAdsMode;
|
||||||
|
private RadioButton rbStandalone;
|
||||||
|
private RadioButton rbMimoSdk;
|
||||||
|
|
||||||
|
// 外部监听、SP实例、Handler实例
|
||||||
|
private OnAdsModeSelectedListener listener;
|
||||||
|
private SharedPreferences sharedPreferences;
|
||||||
|
private InternalHandler mHandler;
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
|
// 静态列表:存储所有已创建的控件实例(Java 7 标准集合)
|
||||||
|
private static final java.util.List<ADsControlView> sControlViews = new java.util.ArrayList<ADsControlView>();
|
||||||
|
|
||||||
|
// 构造方法(Java 7 兼容)
|
||||||
|
public ADsControlView(Context context) {
|
||||||
|
super(context);
|
||||||
|
initView(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ADsControlView(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
initView(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public ADsControlView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
initView(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrivacyAgreeValue(String privacyAgreeValue) {
|
||||||
|
this.privacyAgreeValue = privacyAgreeValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPrivacyAgreeValue() {
|
||||||
|
String privacyAgreeValue = sharedPreferences.getString(PRIVACY_VALUE, "0");
|
||||||
|
return privacyAgreeValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setADsMode(ADsMode mADsMode) {
|
||||||
|
this.mADsMode = mADsMode;
|
||||||
|
sharedPreferences.edit().putString(KEY_SELECTED_MODE, this.mADsMode.name()).apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ADsMode getADsMode() {
|
||||||
|
String savedModeStr = sharedPreferences.getString(KEY_SELECTED_MODE, ADsMode.STANDALONE.name());
|
||||||
|
mADsMode = ADsMode.fromValue(savedModeStr);
|
||||||
|
return mADsMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化视图、SP、Handler
|
||||||
|
*/
|
||||||
|
private void initView(final Context context) {
|
||||||
|
this.mContext = context;
|
||||||
|
// 加载布局
|
||||||
|
LayoutInflater.from(context).inflate(R.layout.view_adscontrol, this, true);
|
||||||
|
|
||||||
|
// 初始化SP
|
||||||
|
sharedPreferences = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
|
||||||
|
|
||||||
|
// 绑定控件
|
||||||
|
rgAdsMode = (RadioGroup) findViewById(R.id.rg_ads_mode);
|
||||||
|
rbStandalone = (RadioButton) findViewById(R.id.rb_standalone);
|
||||||
|
rbMimoSdk = (RadioButton) findViewById(R.id.rb_mimo_sdk);
|
||||||
|
|
||||||
|
// 初始化Handler(主线程Looper)
|
||||||
|
mHandler = new InternalHandler(Looper.getMainLooper());
|
||||||
|
|
||||||
|
// 注册控件实例到静态列表(线程安全)
|
||||||
|
registerControlView(this);
|
||||||
|
|
||||||
|
// 从SP读取初始模式并设置
|
||||||
|
ToastUtils.show(String.format("savedMode : %s", getADsMode().name()));
|
||||||
|
setSelectedMode(getADsMode());
|
||||||
|
|
||||||
|
// 单选组选择事件监听
|
||||||
|
rgAdsMode.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(RadioGroup group, int checkedId) {
|
||||||
|
if (checkedId == R.id.rb_standalone) {
|
||||||
|
setADsMode(ADsMode.STANDALONE);
|
||||||
|
} else if (checkedId == R.id.rb_mimo_sdk) {
|
||||||
|
showPrivacy(context, new OnPrivacyChangeListener(){
|
||||||
|
@Override
|
||||||
|
public void onAgreePrivacy() {
|
||||||
|
setADsMode(ADsMode.MIMO_SDK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisagreePrivacy() {
|
||||||
|
setADsMode(ADsMode.STANDALONE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 【静态】显示隐私协议弹窗(供外部调用,带Context参数)
|
||||||
|
* @param context 上下文(需传入Activity Context,用于弹窗显示)
|
||||||
|
*/
|
||||||
|
public static void showPrivacy(Context context, OnPrivacyChangeListener onPrivacyChangeListener) {
|
||||||
|
if (context == null) {
|
||||||
|
LogUtils.e(TAG, "showPrivacy: Context is null, cannot show privacy dialog");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 校验是否为Activity Context(弹窗必须依附Activity)
|
||||||
|
Activity activity = null;
|
||||||
|
try {
|
||||||
|
activity = (Activity) context;
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
LogUtils.e(TAG, "showPrivacy: Context is not Activity Context", e);
|
||||||
|
Toast.makeText(context.getApplicationContext(), "请传入Activity上下文以显示隐私协议", Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 校验Activity状态
|
||||||
|
if (activity.isFinishing() || activity.isDestroyed()) {
|
||||||
|
LogUtils.e(TAG, "showPrivacy: Activity is finishing or destroyed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读取隐私协议状态并处理逻辑
|
||||||
|
SbhhharedPreferences sp = getPrivacySharedPreferences(context);
|
||||||
|
String privacyAgreeValue = sp.getString(PRIVACY_VALUE, null);
|
||||||
|
handlePrivacyLogic(activity, privacyAgreeValue, onPrivacyChangeListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 【静态】清理SP中存储的隐私协议状态(PRIVACY_VALUE)
|
||||||
|
* 函数名:cleanprivacystatus(按要求命名)
|
||||||
|
* @param context 上下文(建议使用ApplicationContext)
|
||||||
|
*/
|
||||||
|
public static void cleanPrivacyStatus(Context context) {
|
||||||
|
if (context == null) {
|
||||||
|
LogUtils.e(TAG, "cleanPrivacyStatus: Context is null, cannot clean privacy status");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 清空PRIVACY_VALUE值(移除该键,恢复初始未选择状态)
|
||||||
|
SharedPreferences sp = getPrivacySharedPreferences(context);
|
||||||
|
sp.edit().remove(PRIVACY_VALUE).apply();
|
||||||
|
LogUtils.i(TAG, "cleanPrivacyStatus: Privacy status cleaned successfully");
|
||||||
|
ToastUtils.show("cleanPrivacyStatus: Privacy status cleaned successfully");
|
||||||
|
// 清理后同步更新广告模式为单机模式(避免隐私状态为空时仍加载广告)
|
||||||
|
//ADsControlView.updateAdsModeByStatic(context, ADsMode.STANDALONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 【配套静态工具方法】获取隐私协议SP实例(供上述两个静态方法调用,需一并添加)
|
||||||
|
private static SharedPreferences getPrivacySharedPreferences(Context context) {
|
||||||
|
// 使用ApplicationContext获取SP,避免内存泄漏
|
||||||
|
Context appContext = context.getApplicationContext();
|
||||||
|
if (appContext != null) {
|
||||||
|
return appContext.getSharedPreferences(PRIVACY_FILE, Context.MODE_PRIVATE);
|
||||||
|
}
|
||||||
|
// 降级方案:若ApplicationContext为空,使用传入的Context
|
||||||
|
return context.getSharedPreferences(PRIVACY_FILE, Context.MODE_PRIVATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 【配套静态工具方法】隐私协议逻辑处理(供上述两个静态方法调用,需一并添加)
|
||||||
|
private static void handlePrivacyLogic(final Activity activity, String privacyAgreeValue, final OnPrivacyChangeListener onPrivacyChangeListener) {
|
||||||
|
if (TextUtils.equals(privacyAgreeValue, String.valueOf(0))) {
|
||||||
|
ADsControlView.updateAdsModeByStatic(activity.getApplicationContext(), ADsMode.STANDALONE);
|
||||||
|
LogUtils.i(TAG, "已拒绝隐私协议,广告已处于不可用状态...");
|
||||||
|
Toast.makeText(activity.getApplicationContext(), "已拒绝隐私协议,广告已处于不可用状态", Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
} else if (TextUtils.equals(privacyAgreeValue, String.valueOf(1))) {
|
||||||
|
ADsControlView.updateAdsModeByStatic(activity.getApplicationContext(), ADsMode.MIMO_SDK);
|
||||||
|
LogUtils.i(TAG, "已同意隐私协议,开始初始化米盟SDK...");
|
||||||
|
initMimoSdkStatic(activity.getApplicationContext());
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
LogUtils.i(TAG, "开始弹出隐私协议...");
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||||
|
builder.setTitle("用户须知");
|
||||||
|
builder.setMessage("小米广告SDK隐私政策: https://dev.mi.com/distribute/doc/details?pId=1688, 请复制到浏览器查看");
|
||||||
|
builder.setIcon(R.drawable.ic_launcher);
|
||||||
|
builder.setCancelable(false); // 点击对话框以外的区域不消失
|
||||||
|
builder.setPositiveButton("同意", new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
SharedPreferences sp = getPrivacySharedPreferences(activity);
|
||||||
|
sp.edit().putString(PRIVACY_VALUE, String.valueOf(1)).apply();
|
||||||
|
initMimoSdkStatic(activity.getApplicationContext());
|
||||||
|
dialog.dismiss();
|
||||||
|
onPrivacyChangeListener.onAgreePrivacy();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.setNegativeButton("拒绝", new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
SharedPreferences sp = getPrivacySharedPreferences(activity);
|
||||||
|
sp.edit().putString(PRIVACY_VALUE, String.valueOf(0)).apply();
|
||||||
|
ADsControlView.updateAdsModeByStatic(activity.getApplicationContext(), ADsMode.STANDALONE);
|
||||||
|
dialog.dismiss();
|
||||||
|
onPrivacyChangeListener.onDisagreePrivacy();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
AlertDialog dialog = builder.create();
|
||||||
|
|
||||||
|
// 配置弹窗位置(底部全屏)
|
||||||
|
Window window = dialog.getWindow();
|
||||||
|
if (window != null) {
|
||||||
|
window.setGravity(Gravity.BOTTOM);
|
||||||
|
WindowManager m = activity.getWindowManager();
|
||||||
|
Display d = m.getDefaultDisplay();
|
||||||
|
WindowManager.LayoutParams p = window.getAttributes();
|
||||||
|
p.width = d.getWidth();
|
||||||
|
window.setAttributes(p);
|
||||||
|
}
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 【配套静态工具方法】静态初始化米盟SDK(供上述静态方法调用,需一并添加)
|
||||||
|
private static void initMimoSdkStatic(Context appContext) {
|
||||||
|
if (appContext == null) {
|
||||||
|
LogUtils.e(TAG, "initMimoSdkStatic: ApplicationContext is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 初始化SDK,捕获异常避免崩溃
|
||||||
|
try {
|
||||||
|
MimoSdk.init(appContext, new MimoCustomController() {
|
||||||
|
@Override
|
||||||
|
public boolean isCanUseLocation() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MimoLocation getMimoLocation() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCanUseWifiState() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean alist() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}, new MimoSdk.InitCallback() {
|
||||||
|
@Override
|
||||||
|
public void success() {
|
||||||
|
LogUtils.d(TAG, "MimoSdk init success (static)");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fail(int code, String msg) {
|
||||||
|
LogUtils.e(TAG, "MimoSdk init fail (static), code=" + code + ",msg=" + msg);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
MimoSdk.setDebugOn(true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtils.e(TAG, "initMimoSdkStatic: init failed", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 静态方法:外部调用更新SP中的模式,并发送消息通知控件更新
|
||||||
|
* @param context 上下文(建议使用ApplicationContext)
|
||||||
|
* @param mode 要设置的广告模式
|
||||||
|
*/
|
||||||
|
public static void updateAdsModeByStatic(Context context, ADsMode mode) {
|
||||||
|
if (context == null || mode == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. 更新SP数据
|
||||||
|
SharedPreferences sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
|
||||||
|
sp.edit().putString(KEY_SELECTED_MODE, mode.name()).apply();
|
||||||
|
|
||||||
|
// 2. 发送Handler消息,通知所有控件更新
|
||||||
|
InternalHandler.sendUpdateModeMessage(mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增静态方法:外部调用读取SP中存储的广告模式(Java 7 兼容)
|
||||||
|
* @param context 上下文(建议使用ApplicationContext)
|
||||||
|
* @return 存储的AdsMode,默认返回单机模式(STANDALONE)
|
||||||
|
*/
|
||||||
|
public static ADsMode getAdsModeFromStatic(Context context) {
|
||||||
|
// 空指针校验:上下文为空时返回默认模式
|
||||||
|
if (context == null) {
|
||||||
|
return ADsMode.STANDALONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读取SP数据
|
||||||
|
SharedPreferences sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
|
||||||
|
String savedModeStr = sp.getString(KEY_SELECTED_MODE, ADsMode.STANDALONE.name());
|
||||||
|
|
||||||
|
// 解析枚举并返回(兼容SP中数据异常的情况)
|
||||||
|
return ADsMode.fromValue(savedModeStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册控件实例到静态列表(线程安全)
|
||||||
|
*/
|
||||||
|
private static void registerControlView(ADsControlView view) {
|
||||||
|
synchronized (sControlViews) {
|
||||||
|
if (!sControlViews.contains(view)) {
|
||||||
|
sControlViews.add(view);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移除控件实例(线程安全)
|
||||||
|
*/
|
||||||
|
private static void unregisterControlView(ADsControlView view) {
|
||||||
|
synchronized (sControlViews) {
|
||||||
|
sControlViews.remove(view);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置选中模式(内部使用,更新UI)
|
||||||
|
*/
|
||||||
|
private void setSelectedMode(final ADsMode mode) {
|
||||||
|
final ADsMode mode2;
|
||||||
|
if (mode == null) {
|
||||||
|
mode2 = ADsMode.STANDALONE;
|
||||||
|
} else {
|
||||||
|
mode2 = mode;
|
||||||
|
}
|
||||||
|
// 确保UI操作在主线程
|
||||||
|
if (Looper.myLooper() == Looper.getMainLooper()) {
|
||||||
|
if (mode2 == ADsMode.STANDALONE) {
|
||||||
|
rbStandalone.setChecked(true);
|
||||||
|
} else if (mode2 == ADsMode.MIMO_SDK) {
|
||||||
|
rbMimoSdk.setChecked(true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mHandler.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
setSelectedMode(mode2);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前选中模式
|
||||||
|
*/
|
||||||
|
public ADsMode getSelectedMode() {
|
||||||
|
int checkedId = rgAdsMode.getCheckedRadioButtonId();
|
||||||
|
return checkedId == R.id.rb_mimo_sdk ? ADsMode.MIMO_SDK : ADsMode.STANDALONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置外部监听
|
||||||
|
*/
|
||||||
|
public void setOnAdsModeSelectedListener(OnAdsModeSelectedListener listener) {
|
||||||
|
this.listener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内部Handler类(Java 7 静态内部类,无隐藏API依赖)
|
||||||
|
*/
|
||||||
|
private static class InternalHandler extends Handler {
|
||||||
|
static volatile InternalHandler _InternalHandler;
|
||||||
|
public InternalHandler(Looper looper) {
|
||||||
|
super(looper);
|
||||||
|
_InternalHandler = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 静态方法:发送模式更新消息
|
||||||
|
*/
|
||||||
|
public static void sendUpdateModeMessage(ADsMode mode) {
|
||||||
|
if (mode == null || _InternalHandler == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Message msg = _InternalHandler.obtainMessage();
|
||||||
|
msg.what = MSG_UPDATE_MODE;
|
||||||
|
msg.obj = mode;
|
||||||
|
_InternalHandler.sendMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleMessage(Message msg) {
|
||||||
|
super.handleMessage(msg);
|
||||||
|
if (msg.what == MSG_UPDATE_MODE) {
|
||||||
|
ADsMode mode = (ADsMode) msg.obj;
|
||||||
|
if (mode == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修复:替换isDetachedFromWindow()为isAttachedToWindow()(API 1兼容)
|
||||||
|
// 逻辑调整:view.isAttachedToWindow() → 控件已附加到窗口(活跃状态)
|
||||||
|
synchronized (sControlViews) {
|
||||||
|
for (ADsControlView view : sControlViews) {
|
||||||
|
// 三重校验:非空 + 可见 + 已附加到窗口(避免操作销毁/未初始化的控件)
|
||||||
|
if (view != null && view.isShown() && view.isAttachedToWindow()) {
|
||||||
|
view.setSelectedMode(mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生命周期方法:控件销毁时解除注册,避免内存泄漏
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void onDetachedFromWindow() {
|
||||||
|
super.onDetachedFromWindow();
|
||||||
|
// 移除Handler回调
|
||||||
|
if (mHandler != null) {
|
||||||
|
mHandler.removeCallbacksAndMessages(null);
|
||||||
|
}
|
||||||
|
// 从静态列表中移除当前控件
|
||||||
|
unregisterControlView(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 外部监听接口
|
||||||
|
*/
|
||||||
|
public interface OnAdsModeSelectedListener {
|
||||||
|
void onModeSelected(ADsMode selectedMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface OnPrivacyChangeListener {
|
||||||
|
void onAgreePrivacy();
|
||||||
|
void onDisagreePrivacy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package cc.winboll.studio.libaes.winboll;
|
package cc.winboll.studio.libaes.views;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||||
@@ -12,17 +12,18 @@ import android.content.res.TypedArray;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import cc.winboll.studio.libaes.R;
|
import cc.winboll.studio.libaes.R;
|
||||||
|
import cc.winboll.studio.libaes.dialogs.YesNoAlertDialog;
|
||||||
|
import cc.winboll.studio.libaes.models.APPInfo;
|
||||||
import cc.winboll.studio.libaes.utils.AppVersionUtils;
|
import cc.winboll.studio.libaes.utils.AppVersionUtils;
|
||||||
|
import cc.winboll.studio.libaes.utils.PrefUtils;
|
||||||
|
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
|
||||||
import cc.winboll.studio.libappbase.GlobalApplication;
|
import cc.winboll.studio.libappbase.GlobalApplication;
|
||||||
import cc.winboll.studio.libappbase.LogUtils;
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
import cc.winboll.studio.libappbase.dialogs.YesNoAlertDialog;
|
import cc.winboll.studio.libappbase.ToastUtils;
|
||||||
import cc.winboll.studio.libapputils.utils.PrefUtils;
|
|
||||||
import com.hjq.toast.ToastUtils;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import mehdi.sakout.aboutpage.AboutPage;
|
import mehdi.sakout.aboutpage.AboutPage;
|
||||||
import mehdi.sakout.aboutpage.Element;
|
import mehdi.sakout.aboutpage.Element;
|
||||||
@@ -32,7 +33,6 @@ import okhttp3.Credentials;
|
|||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import mehdi.sakout.aboutpage.BuildConfig;
|
|
||||||
|
|
||||||
public class AboutView extends LinearLayout {
|
public class AboutView extends LinearLayout {
|
||||||
|
|
||||||
@@ -40,10 +40,10 @@ public class AboutView extends LinearLayout {
|
|||||||
|
|
||||||
public static final int MSG_APPUPDATE_CHECKED = 0;
|
public static final int MSG_APPUPDATE_CHECKED = 0;
|
||||||
|
|
||||||
Context mContext;
|
static Context _mContext;
|
||||||
APPInfo mAPPInfo;
|
APPInfo mAPPInfo;
|
||||||
|
|
||||||
WinBoLLServiceStatusView mWinBoLLServiceStatusView;
|
//WinBoLLServiceStatusView mWinBoLLServiceStatusView;
|
||||||
OnRequestDevUserInfoAutofillListener mOnRequestDevUserInfoAutofillListener;
|
OnRequestDevUserInfoAutofillListener mOnRequestDevUserInfoAutofillListener;
|
||||||
String mszAppName = "";
|
String mszAppName = "";
|
||||||
String mszAppAPKFolderName = "";
|
String mszAppAPKFolderName = "";
|
||||||
@@ -64,7 +64,7 @@ public class AboutView extends LinearLayout {
|
|||||||
|
|
||||||
public AboutView(Context context, APPInfo appInfo) {
|
public AboutView(Context context, APPInfo appInfo) {
|
||||||
super(context);
|
super(context);
|
||||||
mContext = context;
|
_mContext = context;
|
||||||
|
|
||||||
setAPPInfo(appInfo);
|
setAPPInfo(appInfo);
|
||||||
initView(context);
|
initView(context);
|
||||||
@@ -72,7 +72,7 @@ public class AboutView extends LinearLayout {
|
|||||||
|
|
||||||
public AboutView(Context context, AttributeSet attrs) {
|
public AboutView(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
mContext = context;
|
_mContext = context;
|
||||||
|
|
||||||
initView(context, attrs);
|
initView(context, attrs);
|
||||||
}
|
}
|
||||||
@@ -107,10 +107,10 @@ public class AboutView extends LinearLayout {
|
|||||||
mszAppDescription = mAPPInfo.getAppDescription();
|
mszAppDescription = mAPPInfo.getAppDescription();
|
||||||
mnAppIcon = mAPPInfo.getAppIcon();
|
mnAppIcon = mAPPInfo.getAppIcon();
|
||||||
|
|
||||||
mszWinBoLLServerHost = GlobalApplication.isDebuging() ? "https://yun-preivew.winboll.cc": "https://yun.winboll.cc";
|
mszWinBoLLServerHost = GlobalApplication.isDebugging() ? "https://yun-preivew.winboll.cc": "https://yun.winboll.cc";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mszAppVersionName = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0).versionName;
|
mszAppVersionName = _mContext.getPackageManager().getPackageInfo(_mContext.getPackageName(), 0).versionName;
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||||
}
|
}
|
||||||
@@ -122,35 +122,8 @@ public class AboutView extends LinearLayout {
|
|||||||
} else {
|
} else {
|
||||||
mszGitea = "https://gitea.winboll.cc/" + mAPPInfo.getAppGitOwner() + "/" + mszAppGitName + "/src/branch/" + mAPPInfo.getAppGitAPPBranch() + "/" + mAPPInfo.getAppGitAPPSubProjectFolder();
|
mszGitea = "https://gitea.winboll.cc/" + mAPPInfo.getAppGitOwner() + "/" + mszAppGitName + "/src/branch/" + mAPPInfo.getAppGitAPPBranch() + "/" + mAPPInfo.getAppGitAPPSubProjectFolder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addView(createAboutPage());
|
||||||
if (GlobalApplication.isDebuging()) {
|
|
||||||
LayoutInflater inflater = LayoutInflater.from(mContext);
|
|
||||||
View addedView = inflater.inflate(R.layout.view_about_dev, this, false);
|
|
||||||
LinearLayout llMain = addedView.findViewById(R.id.viewaboutdevLinearLayout1);
|
|
||||||
metDevUserName = addedView.findViewById(R.id.viewaboutdevEditText1);
|
|
||||||
metDevUserPassword = addedView.findViewById(R.id.viewaboutdevEditText2);
|
|
||||||
metDevUserName.setText(PrefUtils.getString(mContext, "metDevUserName", ""));
|
|
||||||
metDevUserPassword.setText(PrefUtils.getString(mContext, "metDevUserPassword", ""));
|
|
||||||
//mDevelopHostConnectionStatusView = new DevelopHostConnectionStatusView(context);
|
|
||||||
mWinBoLLServiceStatusView = addedView.findViewById(R.id.viewaboutdevWinBoLLServiceStatusView1);
|
|
||||||
mWinBoLLServiceStatusView.setServerHost(mszWinBoLLServerHost);
|
|
||||||
mWinBoLLServiceStatusView.setAuthInfo(metDevUserName.getText().toString(), metDevUserPassword.getText().toString());
|
|
||||||
//llMain.addView(mDevelopHostConnectionStatusView);
|
|
||||||
llMain.addView(createAboutPage());
|
|
||||||
addView(addedView);
|
|
||||||
} else {
|
|
||||||
LayoutInflater inflater = LayoutInflater.from(mContext);
|
|
||||||
View addedView = inflater.inflate(R.layout.view_about_www, this, false);
|
|
||||||
LinearLayout llMain = addedView.findViewById(R.id.viewaboutwwwLinearLayout1);
|
|
||||||
//mDevelopHostConnectionStatusView = new DevelopHostConnectionStatusView(context);
|
|
||||||
mWinBoLLServiceStatusView = addedView.findViewById(R.id.viewaboutwwwWinBoLLServiceStatusView1);
|
|
||||||
mWinBoLLServiceStatusView.setServerHost(mszWinBoLLServerHost);
|
|
||||||
mWinBoLLServiceStatusView.setAuthInfo("", "");
|
|
||||||
//llMain.addView(mDevelopHostConnectionStatusView);
|
|
||||||
llMain.addView(createAboutPage());
|
|
||||||
addView(addedView);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 初始化标题栏
|
// 初始化标题栏
|
||||||
//setSubtitle(getContext().getString(R.string.text_about));
|
//setSubtitle(getContext().getString(R.string.text_about));
|
||||||
@@ -162,9 +135,9 @@ public class AboutView extends LinearLayout {
|
|||||||
String szReleaseAppVersionName = "";
|
String szReleaseAppVersionName = "";
|
||||||
try {
|
try {
|
||||||
//LogUtils.d(TAG, String.format("mContext.getPackageName() %s", mContext.getPackageName()));
|
//LogUtils.d(TAG, String.format("mContext.getPackageName() %s", mContext.getPackageName()));
|
||||||
String szSubBetaSuffix = subBetaSuffix(mContext.getPackageName());
|
String szSubBetaSuffix = subBetaSuffix(_mContext.getPackageName());
|
||||||
//LogUtils.d(TAG, String.format("szSubBetaSuffix : %s", szSubBetaSuffix));
|
//LogUtils.d(TAG, String.format("szSubBetaSuffix : %s", szSubBetaSuffix));
|
||||||
szReleaseAppVersionName = mContext.getPackageManager().getPackageInfo(szSubBetaSuffix, 0).versionName;
|
szReleaseAppVersionName = _mContext.getPackageManager().getPackageInfo(szSubBetaSuffix, 0).versionName;
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||||
}
|
}
|
||||||
@@ -205,7 +178,7 @@ public class AboutView extends LinearLayout {
|
|||||||
String szMsg = "Current app is :\n[ " + mszCurrentAppPackageName
|
String szMsg = "Current app is :\n[ " + mszCurrentAppPackageName
|
||||||
+ " ]\nThe last app is :\n[ " + mszNewestAppPackageName
|
+ " ]\nThe last app is :\n[ " + mszNewestAppPackageName
|
||||||
+ " ]\nIs download the last app?";
|
+ " ]\nIs download the last app?";
|
||||||
YesNoAlertDialog.show(mContext, "Application Update Prompt", szMsg, mIsDownlaodUpdateListener);
|
YesNoAlertDialog.show(_mContext, "Application Update Prompt", szMsg, mIsDownlaodUpdateListener);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -216,22 +189,23 @@ public class AboutView extends LinearLayout {
|
|||||||
protected View createAboutPage() {
|
protected View createAboutPage() {
|
||||||
// 定义 GitWeb 按钮
|
// 定义 GitWeb 按钮
|
||||||
//
|
//
|
||||||
Element elementGitWeb = new Element(mContext.getString(R.string.gitea_home), R.drawable.ic_winboll);
|
Element elementGitWeb = new Element(_mContext.getString(R.string.gitea_home), R.drawable.ic_winboll);
|
||||||
elementGitWeb.setOnClickListener(mGitWebOnClickListener);
|
elementGitWeb.setOnClickListener(mGitWebOnClickListener);
|
||||||
// 定义检查更新按钮
|
// 定义检查更新按钮
|
||||||
//
|
//
|
||||||
Element elementAppUpdate = new Element(mContext.getString(R.string.app_update), R.drawable.ic_winboll);
|
/*Element elementAppUpdate = new Element(_mContext.getString(R.string.app_update), R.drawable.ic_winboll);
|
||||||
elementAppUpdate.setOnClickListener(mAppUpdateOnClickListener);
|
elementAppUpdate.setOnClickListener(mAppUpdateOnClickListener);
|
||||||
|
*/
|
||||||
|
|
||||||
String szAppInfo = "";
|
String szAppInfo = "";
|
||||||
try {
|
try {
|
||||||
szAppInfo = mszAppName + " "
|
szAppInfo = mszAppName + " "
|
||||||
+ mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0).versionName
|
+ _mContext.getPackageManager().getPackageInfo(_mContext.getPackageName(), 0).versionName
|
||||||
+ "\n" + mszAppDescription;
|
+ "\n" + mszAppDescription;
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||||
}
|
}
|
||||||
AboutPage aboutPage = new AboutPage(mContext);
|
AboutPage aboutPage = new AboutPage(_mContext);
|
||||||
aboutPage.setDescription(szAppInfo)
|
aboutPage.setDescription(szAppInfo)
|
||||||
//.isRTL(false)
|
//.isRTL(false)
|
||||||
//.setCustomFont(String) // or Typeface
|
//.setCustomFont(String) // or Typeface
|
||||||
@@ -241,8 +215,8 @@ public class AboutView extends LinearLayout {
|
|||||||
//.addGroup("Connect with us")
|
//.addGroup("Connect with us")
|
||||||
.addEmail("ZhanGSKen<zhangsken@qq.com>")
|
.addEmail("ZhanGSKen<zhangsken@qq.com>")
|
||||||
.addWebsite(mszHomePage)
|
.addWebsite(mszHomePage)
|
||||||
.addItem(elementGitWeb)
|
.addItem(elementGitWeb);
|
||||||
.addItem(elementAppUpdate);
|
//.addItem(elementAppUpdate);
|
||||||
//.addFacebook("the.medy")
|
//.addFacebook("the.medy")
|
||||||
//.addTwitter("medyo80")
|
//.addTwitter("medyo80")
|
||||||
//.addYoutube("UCdPQtdWIsg7_pi4mrRu46vA")
|
//.addYoutube("UCdPQtdWIsg7_pi4mrRu46vA")
|
||||||
@@ -251,19 +225,19 @@ public class AboutView extends LinearLayout {
|
|||||||
//.addInstagram("medyo80")
|
//.addInstagram("medyo80")
|
||||||
//.create();
|
//.create();
|
||||||
|
|
||||||
if (mAPPInfo.isAddDebugTools()) {
|
/*if (mAPPInfo.isAddDebugTools()) {
|
||||||
// 定义应用调试按钮
|
// 定义应用调试按钮
|
||||||
//
|
//
|
||||||
Element elementAppMode;
|
Element elementAppMode;
|
||||||
if (GlobalApplication.isDebuging()) {
|
if (GlobalApplication.isDebugging()) {
|
||||||
elementAppMode = new Element(mContext.getString(R.string.app_normal), R.drawable.ic_winboll);
|
elementAppMode = new Element(_mContext.getString(R.string.app_normal), R.drawable.ic_winboll);
|
||||||
elementAppMode.setOnClickListener(mAppNormalOnClickListener);
|
elementAppMode.setOnClickListener(mAppNormalOnClickListener);
|
||||||
} else {
|
} else {
|
||||||
elementAppMode = new Element(mContext.getString(R.string.app_debug), R.drawable.ic_winboll);
|
elementAppMode = new Element(_mContext.getString(R.string.app_debug), R.drawable.ic_winboll);
|
||||||
elementAppMode.setOnClickListener(mAppDebugOnClickListener);
|
elementAppMode.setOnClickListener(mAppDebugOnClickListener);
|
||||||
}
|
}
|
||||||
aboutPage.addItem(elementAppMode);
|
aboutPage.addItem(elementAppMode);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
return aboutPage.create();
|
return aboutPage.create();
|
||||||
}
|
}
|
||||||
@@ -272,7 +246,7 @@ public class AboutView extends LinearLayout {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
//ToastUtils.show("mAppDebugOnClickListener");
|
//ToastUtils.show("mAppDebugOnClickListener");
|
||||||
setApp2DebugMode(mContext);
|
setApp2DebugMode(_mContext);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -280,7 +254,7 @@ public class AboutView extends LinearLayout {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
//ToastUtils.show("mAppNormalOnClickListener");
|
//ToastUtils.show("mAppNormalOnClickListener");
|
||||||
setApp2NormalMode(mContext);
|
setApp2NormalMode(_mContext);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -289,10 +263,10 @@ public class AboutView extends LinearLayout {
|
|||||||
if (intent != null) {
|
if (intent != null) {
|
||||||
//intent.setAction(cc.winboll.studio.libapputils.intent.action.DEBUGVIEW);
|
//intent.setAction(cc.winboll.studio.libapputils.intent.action.DEBUGVIEW);
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
GlobalApplication.setIsDebuging(true);
|
GlobalApplication.setIsDebugging(true);
|
||||||
GlobalApplication.saveDebugStatus();
|
GlobalApplication.saveDebugStatus((GlobalApplication)_mContext.getApplicationContext());
|
||||||
|
|
||||||
GlobalApplication.getWinBoLLActivityManager().finishAll();
|
WinBoLLActivityManager.getInstance().finishAll();
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -301,10 +275,10 @@ public class AboutView extends LinearLayout {
|
|||||||
Intent intent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
|
Intent intent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
|
||||||
if (intent != null) {
|
if (intent != null) {
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
GlobalApplication.setIsDebuging(false);
|
GlobalApplication.setIsDebugging(false);
|
||||||
GlobalApplication.saveDebugStatus();
|
GlobalApplication.saveDebugStatus((GlobalApplication)_mContext.getApplicationContext());
|
||||||
|
|
||||||
GlobalApplication.getWinBoLLActivityManager().finishAll();
|
WinBoLLActivityManager.getInstance().finishAll();
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -313,7 +287,7 @@ public class AboutView extends LinearLayout {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(mszGitea));
|
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(mszGitea));
|
||||||
mContext.startActivity(browserIntent);
|
_mContext.startActivity(browserIntent);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -327,10 +301,10 @@ public class AboutView extends LinearLayout {
|
|||||||
String szUrl = mszWinBoLLServerHost + "/studio/details.php?app=" + mszAppAPKFolderName;
|
String szUrl = mszWinBoLLServerHost + "/studio/details.php?app=" + mszAppAPKFolderName;
|
||||||
// 构建包含认证信息的请求
|
// 构建包含认证信息的请求
|
||||||
String credential = "";
|
String credential = "";
|
||||||
if (GlobalApplication.isDebuging()) {
|
if (GlobalApplication.isDebugging()) {
|
||||||
credential = Credentials.basic(metDevUserName.getText().toString(), metDevUserPassword.getText().toString());
|
credential = Credentials.basic(metDevUserName.getText().toString(), metDevUserPassword.getText().toString());
|
||||||
PrefUtils.saveString(mContext, "metDevUserName", metDevUserName.getText().toString());
|
PrefUtils.saveString(_mContext, "metDevUserName", metDevUserName.getText().toString());
|
||||||
PrefUtils.saveString(mContext, "metDevUserPassword", metDevUserPassword.getText().toString());
|
PrefUtils.saveString(_mContext, "metDevUserPassword", metDevUserPassword.getText().toString());
|
||||||
} else {
|
} else {
|
||||||
String username = "WinBoLL";
|
String username = "WinBoLL";
|
||||||
String password = "WinBoLLPowerByZhanGSKen";
|
String password = "WinBoLLPowerByZhanGSKen";
|
||||||
@@ -387,7 +361,7 @@ public class AboutView extends LinearLayout {
|
|||||||
public void onYes() {
|
public void onYes() {
|
||||||
String szUrl = mszWinBoLLServerHost + "/studio/download.php?appname=" + mszAppAPKFolderName + "&apkname=" + mszNewestAppPackageName;
|
String szUrl = mszWinBoLLServerHost + "/studio/download.php?appname=" + mszAppAPKFolderName + "&apkname=" + mszNewestAppPackageName;
|
||||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(szUrl));
|
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(szUrl));
|
||||||
mContext.startActivity(browserIntent);
|
_mContext.startActivity(browserIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:id="@+id/activitydrawerfragmentASupportToolbar1"/>
|
android:id="@+id/activitydrawerfragmentASupportToolbar1"/>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@@ -19,7 +19,8 @@
|
|||||||
|
|
||||||
<androidx.drawerlayout.widget.DrawerLayout
|
<androidx.drawerlayout.widget.DrawerLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="0dp"
|
||||||
|
android:layout_weight="1.0"
|
||||||
android:id="@+id/activitydrawerfragmentDrawerLayout1">
|
android:id="@+id/activitydrawerfragmentDrawerLayout1">
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
@@ -52,7 +53,13 @@
|
|||||||
|
|
||||||
</androidx.drawerlayout.widget.DrawerLayout>
|
</androidx.drawerlayout.widget.DrawerLayout>
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<cc.winboll.studio.libaes.views.ADsBannerView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/adsbanner"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|||||||
@@ -1,64 +0,0 @@
|
|||||||
<?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:id="@+id/viewaboutdevLinearLayout1">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="center_vertical">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="180dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="DevelopUserName :"/>
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:ems="10"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1.0"
|
|
||||||
android:id="@+id/viewaboutdevEditText1"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="center_vertical">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="180dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="DevelopUserPassword :"/>
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:inputType="textPassword"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:ems="10"
|
|
||||||
android:layout_weight="1.0"
|
|
||||||
android:id="@+id/viewaboutdevEditText2"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="center_horizontal">
|
|
||||||
|
|
||||||
<cc.winboll.studio.libaes.winboll.WinBoLLServiceStatusView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:id="@+id/viewaboutdevWinBoLLServiceStatusView1"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
<?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:id="@+id/viewaboutwwwLinearLayout1">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="center_horizontal">
|
|
||||||
|
|
||||||
<cc.winboll.studio.libaes.winboll.WinBoLLServiceStatusView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:id="@+id/viewaboutwwwWinBoLLServiceStatusView1"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
15
libaes/src/main/res/layout/view_adsbanner.xml
Normal file
15
libaes/src/main/res/layout/view_adsbanner.xml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:id="@+id/ads_container"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/ads_container"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
46
libaes/src/main/res/layout/view_adscontrol.xml
Normal file
46
libaes/src/main/res/layout/view_adscontrol.xml
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<?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="16dp"
|
||||||
|
android:background="@android:color/white">
|
||||||
|
|
||||||
|
<!-- 标题提示 -->
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="运行模式选择"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:textColor="@android:color/black"
|
||||||
|
android:layout_marginBottom="12dp" />
|
||||||
|
|
||||||
|
<!-- 单选组 -->
|
||||||
|
<RadioGroup
|
||||||
|
android:id="@+id/rg_ads_mode"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<!-- 单机模式单选框 -->
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/rb_standalone"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="单机模式"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:textColor="@android:color/darker_gray"
|
||||||
|
android:layout_marginBottom="8dp" />
|
||||||
|
|
||||||
|
<!-- 米盟广告SDK模式单选框 -->
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/rb_mimo_sdk"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="米盟广告SDK支持模式"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:textColor="@android:color/darker_gray" />
|
||||||
|
|
||||||
|
</RadioGroup>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
35
libaes/src/main/res/menu/toolbar_studio_debug.xml
Normal file
35
libaes/src/main/res/menu/toolbar_studio_debug.xml
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
<!--<item android:title="@string/app_theme">
|
||||||
|
<menu>-->
|
||||||
|
<!-- 定义一组单选按钮 -->
|
||||||
|
<!-- checkableBehavior的可选值由三个:single设置为单选,all为多选,none为普通选项 -->
|
||||||
|
<!-- <group android:checkableBehavior="single">
|
||||||
|
<item android:id="@+id/app_defaulttheme" android:title="@string/app_defaulttheme"/>
|
||||||
|
<item android:id="@+id/app_skytheme" android:title="@string/app_skytheme"/>
|
||||||
|
<item android:id="@+id/app_goldentheme" android:title="@string/app_goldentheme"/>
|
||||||
|
</group>
|
||||||
|
</menu>
|
||||||
|
</item>-->
|
||||||
|
|
||||||
|
<item android:title="DebugTools">
|
||||||
|
<menu>
|
||||||
|
<item
|
||||||
|
android:id="@+id/item_testcrashreport"
|
||||||
|
android:title="Test Application Crash Report"/>
|
||||||
|
<item
|
||||||
|
android:id="@+id/item_unittest"
|
||||||
|
android:title="UnitTest"/>
|
||||||
|
<item
|
||||||
|
android:id="@+id/item_log"
|
||||||
|
android:title="APPLOG"/>
|
||||||
|
<item
|
||||||
|
android:id="@+id/item_info"
|
||||||
|
android:title="Info"/>
|
||||||
|
<item
|
||||||
|
android:id="@+id/item_exitdebug"
|
||||||
|
android:title="ExitDebug"/>
|
||||||
|
</menu>
|
||||||
|
</item>
|
||||||
|
</menu>
|
||||||
@@ -12,5 +12,10 @@
|
|||||||
<string name="text_GoldenTheme">GoldenTheme</string>
|
<string name="text_GoldenTheme">GoldenTheme</string>
|
||||||
<string name="text_MemorTheme">MemorTheme</string>
|
<string name="text_MemorTheme">MemorTheme</string>
|
||||||
<string name="text_TaoTheme">TaoTheme</string>
|
<string name="text_TaoTheme">TaoTheme</string>
|
||||||
|
|
||||||
|
<string name="app_normal">Click here is switch to Normal APP</string>
|
||||||
|
<string name="app_debug">Click here is switch to APP DEBUG</string>
|
||||||
|
<string name="gitea_home">GITEA HOME</string>
|
||||||
|
<string name="app_update">APP UPDATE</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
5
libaes/src/main/res/xml/file_provider.xml
Normal file
5
libaes/src/main/res/xml/file_provider.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<paths>
|
||||||
|
<external-path path="mimoDownload" name="files_root" />
|
||||||
|
<external-path path="." name="external_storage_root" />
|
||||||
|
</paths>
|
||||||
16
libaes/src/main/res/xml/network_security_config.xml
Normal file
16
libaes/src/main/res/xml/network_security_config.xml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<network-security-config>
|
||||||
|
<!-- 允许 winboll.cc 及其子域名的明文流量(HTTP) -->
|
||||||
|
<domain-config cleartextTrafficPermitted="true">
|
||||||
|
<domain includeSubdomains="true">winboll.cc</domain>
|
||||||
|
</domain-config>
|
||||||
|
<!-- 米盟 SDK 配置 -->
|
||||||
|
<base-config cleartextTrafficPermitted="true" />
|
||||||
|
<debug-overrides>
|
||||||
|
<trust-anchors>
|
||||||
|
<!-- Trust user added CAs while debuggable only -->
|
||||||
|
<certificates src="system" />
|
||||||
|
<certificates src="user" />
|
||||||
|
</trust-anchors>
|
||||||
|
</debug-overrides>
|
||||||
|
</network-security-config>
|
||||||
@@ -5,11 +5,14 @@ apply from: '../.winboll/winboll_lint_build.gradle'
|
|||||||
|
|
||||||
android {
|
android {
|
||||||
|
|
||||||
compileSdkVersion 32
|
// 1. compileSdkVersion:必须 ≥ targetSdkVersion,建议直接等于 targetSdkVersion(30)
|
||||||
buildToolsVersion "32.0.0"
|
compileSdkVersion 30
|
||||||
|
|
||||||
|
// 2. buildToolsVersion:需匹配 compileSdkVersion,建议使用 30.x.x 最新稳定版(无需高于 compileSdkVersion)
|
||||||
|
buildToolsVersion "30.0.3" // 这是 30 对应的最新稳定版,避免使用 beta 版
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 24
|
minSdkVersion 23
|
||||||
targetSdkVersion 30
|
targetSdkVersion 30
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
@@ -22,9 +25,4 @@ android {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
api fileTree(dir: 'libs', include: ['*.jar'])
|
api fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
// 网络连接类库
|
|
||||||
api 'com.squareup.okhttp3:okhttp:4.4.1'
|
|
||||||
// https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind
|
|
||||||
|
|
||||||
api 'com.google.code.gson:gson:2.10.1'
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Mon Sep 22 02:57:06 HKT 2025
|
#Sun Nov 30 17:12:48 HKT 2025
|
||||||
stageCount=8
|
stageCount=7
|
||||||
libraryProject=libappbase
|
libraryProject=libappbase
|
||||||
baseVersion=15.10
|
baseVersion=15.11
|
||||||
publishVersion=15.10.7
|
publishVersion=15.11.6
|
||||||
buildCount=0
|
buildCount=0
|
||||||
baseBetaVersion=15.10.8
|
baseBetaVersion=15.11.7
|
||||||
|
|||||||
@@ -3,8 +3,9 @@
|
|||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="cc.winboll.studio.libappbase">
|
package="cc.winboll.studio.libappbase">
|
||||||
|
|
||||||
<application>
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||||
|
|
||||||
|
<application>
|
||||||
<activity
|
<activity
|
||||||
android:name=".CrashHandler$CrashActivity"
|
android:name=".CrashHandler$CrashActivity"
|
||||||
android:label="CrashActivity"
|
android:label="CrashActivity"
|
||||||
@@ -28,6 +29,22 @@
|
|||||||
|
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<!-- 崩溃通知复制活动(类库Manifest配置,确保宿主能合并注册) -->
|
||||||
|
<activity
|
||||||
|
android:name="cc.winboll.studio.libappbase.activities.CrashCopyReceiverActivity"
|
||||||
|
android:theme="@android:style/Theme.Translucent.NoTitleBar"
|
||||||
|
android:launchMode="singleTask"
|
||||||
|
android:excludeFromRecents="true"
|
||||||
|
android:taskAffinity=""
|
||||||
|
android:exported="true"
|
||||||
|
android:allowTaskReparenting="false"
|
||||||
|
android:clearTaskOnLaunch="true">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="cc.winboll.studio.action.COPY_CRASH_LOG" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|||||||
@@ -1,73 +1,138 @@
|
|||||||
package cc.winboll.studio.libappbase;
|
package cc.winboll.studio.libappbase;
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
|
||||||
* @Date 2025/03/02 10:28:08
|
|
||||||
* @Describe 应用调试模型
|
|
||||||
*/
|
|
||||||
import android.util.JsonReader;
|
import android.util.JsonReader;
|
||||||
import android.util.JsonWriter;
|
import android.util.JsonWriter;
|
||||||
import cc.winboll.studio.libappbase.BaseBean;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||||
|
* @Date 2025/11/11 20:01
|
||||||
|
* @Describe WinBoLL 应用全局数据模型类
|
||||||
|
* 继承自 BaseBean,用于存储和管理应用的核心配置信息(如调试状态),
|
||||||
|
* 支持 JSON 序列化/反序列化,便于数据持久化或跨组件传递
|
||||||
|
*/
|
||||||
public class APPModel extends BaseBean {
|
public class APPModel extends BaseBean {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志打印标签,用于区分当前类的日志输出
|
||||||
|
*/
|
||||||
public static final String TAG = "APPModel";
|
public static final String TAG = "APPModel";
|
||||||
|
|
||||||
// 应用是否处于正在调试状态
|
/**
|
||||||
//
|
* 应用调试状态标识
|
||||||
boolean isDebuging = false;
|
* true:应用处于调试模式(可输出详细日志、启用调试功能等)
|
||||||
|
* false:应用处于正式模式(关闭调试相关功能,优化性能)
|
||||||
|
*/
|
||||||
|
private boolean isDebugging = false; // 修正拼写:原 isDebuging -> isDebugging(符合命名规范)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 无参构造方法
|
||||||
|
* 初始化调试状态为默认值:false(正式模式)
|
||||||
|
*/
|
||||||
public APPModel() {
|
public APPModel() {
|
||||||
this.isDebuging = false;
|
this.isDebugging = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public APPModel(boolean isDebuging) {
|
/**
|
||||||
this.isDebuging = isDebuging;
|
* 带参构造方法
|
||||||
|
* 可通过参数指定应用的初始调试状态
|
||||||
|
* @param isDebugging 初始调试状态(true:调试模式;false:正式模式)
|
||||||
|
*/
|
||||||
|
public APPModel(boolean isDebugging) {
|
||||||
|
this.isDebugging = isDebugging;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIsDebuging(boolean isDebuging) {
|
/**
|
||||||
this.isDebuging = isDebuging;
|
* 设置应用调试状态
|
||||||
|
* @param isDebugging 目标调试状态(true:开启调试;false:关闭调试)
|
||||||
|
*/
|
||||||
|
public void setIsDebugging(boolean isDebugging) {
|
||||||
|
this.isDebugging = isDebugging;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDebuging() {
|
/**
|
||||||
return isDebuging;
|
* 获取当前应用调试状态
|
||||||
|
* @return 调试状态(true:调试中;false:非调试)
|
||||||
|
*/
|
||||||
|
public boolean isDebugging() {
|
||||||
|
return isDebugging;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重写父类方法,返回当前类的全限定名
|
||||||
|
* 用于标识数据模型的类类型(可用于反射、序列化校验等场景)
|
||||||
|
* @return 类的全限定名(如:cc.winboll.studio.libappbase.APPModel)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return APPModel.class.getName();
|
return APPModel.class.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重写父类方法,将当前模型的字段序列化到 JSON 中
|
||||||
|
* 用于将调试状态等核心数据转换为 JSON 格式(如持久化到文件、网络传输)
|
||||||
|
* @param jsonWriter JSON 写入器对象,用于输出 JSON 数据
|
||||||
|
* @throws IOException 当 JSON 写入失败时抛出(如流关闭、格式错误)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
|
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
|
||||||
|
// 先调用父类方法,序列化父类中的字段(若 BaseBean 有可序列化字段)
|
||||||
super.writeThisToJsonWriter(jsonWriter);
|
super.writeThisToJsonWriter(jsonWriter);
|
||||||
jsonWriter.name("isDebuging").value(isDebuging());
|
// 序列化当前类的调试状态字段:key 为 "isDebuging"(保持与原代码一致,避免兼容性问题),value 为当前状态
|
||||||
|
jsonWriter.name("isDebuging").value(isDebugging());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重写父类方法,从 JSON 中解析字段并初始化当前对象
|
||||||
|
* 用于将 JSON 格式的配置数据解析为 APPModel 实例(如从文件读取、网络接收后解析)
|
||||||
|
* @param jsonReader JSON 读取器对象,用于读取 JSON 数据
|
||||||
|
* @param name 当前解析的 JSON 字段名
|
||||||
|
* @return true:字段解析成功;false:字段不属于当前类,需由调用者处理
|
||||||
|
* @throws IOException 当 JSON 读取失败时抛出(如流关闭、数据格式错误)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean initObjectsFromJsonReader(JsonReader jsonReader, String name) throws IOException {
|
public boolean initObjectsFromJsonReader(JsonReader jsonReader, String name) throws IOException {
|
||||||
if (super.initObjectsFromJsonReader(jsonReader, name)) { return true; } else {
|
// 先调用父类方法,解析父类中的字段(若 BaseBean 有可解析字段)
|
||||||
|
if (super.initObjectsFromJsonReader(jsonReader, name)) {
|
||||||
|
return true; // 父类已处理该字段,直接返回成功
|
||||||
|
} else {
|
||||||
|
// 解析当前类的字段
|
||||||
if (name.equals("isDebuging")) {
|
if (name.equals("isDebuging")) {
|
||||||
setIsDebuging(jsonReader.nextBoolean());
|
// 读取 JSON 中 "isDebuging" 字段的值,设置为当前对象的调试状态
|
||||||
|
setIsDebugging(jsonReader.nextBoolean());
|
||||||
} else {
|
} else {
|
||||||
|
// 字段不属于当前类,返回 false 提示调用者跳过该字段
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 字段解析成功,返回 true
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重写父类方法,从 JSON 读取器中完整解析一个 APPModel 实例
|
||||||
|
* 负责处理 JSON 对象的开始/结束标记,循环解析所有字段
|
||||||
|
* @param jsonReader JSON 读取器对象,用于读取 JSON 数据
|
||||||
|
* @return 解析完成的当前 APPModel 实例(支持链式调用)
|
||||||
|
* @throws IOException 当 JSON 读取失败时抛出(如流关闭、数据格式错误)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public BaseBean readBeanFromJsonReader(JsonReader jsonReader) throws IOException {
|
public BaseBean readBeanFromJsonReader(JsonReader jsonReader) throws IOException {
|
||||||
|
// 开始解析 JSON 对象(对应 JSON 中的 '{')
|
||||||
jsonReader.beginObject();
|
jsonReader.beginObject();
|
||||||
|
// 循环读取 JSON 中的所有字段(直到对象结束)
|
||||||
while (jsonReader.hasNext()) {
|
while (jsonReader.hasNext()) {
|
||||||
|
// 获取当前字段名
|
||||||
String name = jsonReader.nextName();
|
String name = jsonReader.nextName();
|
||||||
|
// 解析字段:若当前类无法处理该字段,则跳过(避免解析异常)
|
||||||
if (!initObjectsFromJsonReader(jsonReader, name)) {
|
if (!initObjectsFromJsonReader(jsonReader, name)) {
|
||||||
jsonReader.skipValue();
|
jsonReader.skipValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 结束 JSON 对象
|
// 结束解析 JSON 对象(对应 JSON 中的 '}')
|
||||||
jsonReader.endObject();
|
jsonReader.endObject();
|
||||||
|
// 返回解析完成的实例(当前对象)
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
package cc.winboll.studio.libappbase;
|
package cc.winboll.studio.libappbase;
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
|
||||||
* @Date 2025/01/15 11:11:52
|
|
||||||
* @Describe Json Bean 基础类。
|
|
||||||
*/
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.JsonReader;
|
import android.util.JsonReader;
|
||||||
import android.util.JsonWriter;
|
import android.util.JsonWriter;
|
||||||
@@ -14,274 +9,428 @@ import java.io.StringReader;
|
|||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||||
|
* @Date 2025/11/11 20:03
|
||||||
|
* @Describe WinBoLL JSON 数据模型基类(抽象类)
|
||||||
|
* 定义 Json Bean 的核心规范:序列化/反序列化、文件持久化、列表处理等通用逻辑,
|
||||||
|
* 子类(如 APPModel)需实现抽象方法,实现自身字段的 JSON 读写
|
||||||
|
* @param <T> 泛型约束,限定子类必须继承自 BaseBean
|
||||||
|
*/
|
||||||
public abstract class BaseBean<T extends BaseBean> {
|
public abstract class BaseBean<T extends BaseBean> {
|
||||||
|
|
||||||
public static final String TAG = "BaseBean";
|
/** 日志标签,用于当前基类的日志输出标识 */
|
||||||
static final String BEAN_NAME = "BeanName";
|
public static final String TAG = "BaseBean";
|
||||||
|
/** JSON 中存储 Bean 类名的字段键(用于校验 Bean 类型一致性) */
|
||||||
|
static final String BEAN_NAME = "BeanName";
|
||||||
|
|
||||||
public BaseBean() {}
|
/**
|
||||||
|
* 无参构造方法(子类需默认实现,支持反射实例化)
|
||||||
|
*/
|
||||||
|
public BaseBean() {}
|
||||||
|
|
||||||
public abstract String getName();
|
/**
|
||||||
|
* 抽象方法:获取当前 Bean 的全限定类名
|
||||||
|
* 子类需实现,用于标识 Bean 类型(序列化/校验时使用)
|
||||||
|
* @return 类的全限定名(如:cc.winboll.studio.libappbase.APPModel)
|
||||||
|
*/
|
||||||
|
public abstract String getName();
|
||||||
|
|
||||||
public String getBeanJsonFilePath(Context context) {
|
/**
|
||||||
|
* 获取单个 Bean 的 JSON 持久化文件路径
|
||||||
|
* 路径:外部存储/应用私有目录/BaseBean/[类名].json
|
||||||
|
* @param context 上下文(用于获取应用存储目录)
|
||||||
|
* @return 单个 Bean 的文件绝对路径
|
||||||
|
*/
|
||||||
|
public String getBeanJsonFilePath(Context context) {
|
||||||
|
return context.getExternalFilesDir(TAG) + "/" + getName() + ".json";
|
||||||
|
}
|
||||||
|
|
||||||
return context.getExternalFilesDir(TAG) + "/" + getName() + ".json";
|
/**
|
||||||
}
|
* 获取 Bean 列表的 JSON 持久化文件路径
|
||||||
|
* 路径:外部存储/应用私有目录/BaseBean/[类名]_List.json
|
||||||
|
* @param context 上下文(用于获取应用存储目录)
|
||||||
|
* @return Bean 列表的文件绝对路径
|
||||||
|
*/
|
||||||
|
public String getBeanListJsonFilePath(Context context) {
|
||||||
|
return context.getExternalFilesDir(TAG) + "/" + getName() + "_List.json";
|
||||||
|
}
|
||||||
|
|
||||||
public String getBeanListJsonFilePath(Context context) {
|
/**
|
||||||
|
* 将 Bean 类名写入 JSON(序列化基础字段)
|
||||||
|
* 子类可重写扩展,添加自身字段的 JSON 写入逻辑
|
||||||
|
* @param jsonWriter JSON 写入器(用于输出 JSON 数据)
|
||||||
|
* @throws IOException JSON 写入失败时抛出(如流异常)
|
||||||
|
*/
|
||||||
|
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
|
||||||
|
// 写入 Bean 类名字段(用于反序列化时校验类型)
|
||||||
|
jsonWriter.name(BEAN_NAME).value(getName());
|
||||||
|
}
|
||||||
|
|
||||||
return context.getExternalFilesDir(TAG) + "/" + getName() + "_List.json";
|
/**
|
||||||
}
|
* 从 JSON 读取字段并初始化 Bean(反序列化基础逻辑)
|
||||||
|
* 子类需重写,实现自身字段的解析逻辑
|
||||||
|
* @param jsonReader JSON 读取器(用于读取 JSON 数据)
|
||||||
|
* @param name 当前解析的 JSON 字段名
|
||||||
|
* @return true:字段解析成功(当前类处理);false:字段未处理(需跳过)
|
||||||
|
* @throws IOException JSON 读取失败时抛出(如流异常)
|
||||||
|
*/
|
||||||
|
public boolean initObjectsFromJsonReader(JsonReader jsonReader, String name) throws IOException {
|
||||||
|
return false; // 基类未处理任何字段,返回 false
|
||||||
|
}
|
||||||
|
|
||||||
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
|
/**
|
||||||
jsonWriter.name(BEAN_NAME).value(getName());
|
* 抽象方法:从 JSON 读取器解析并返回 Bean 实例
|
||||||
}
|
* 子类需实现,处理自身字段的完整解析逻辑
|
||||||
|
* @param jsonReader JSON 读取器(用于读取 JSON 数据)
|
||||||
|
* @return 解析完成的 Bean 实例
|
||||||
|
* @throws IOException JSON 读取失败时抛出(如流异常)
|
||||||
|
*/
|
||||||
|
abstract public T readBeanFromJsonReader(JsonReader jsonReader) throws IOException;
|
||||||
|
|
||||||
public boolean initObjectsFromJsonReader(JsonReader jsonReader, String name) throws IOException {
|
/**
|
||||||
return false;
|
* 校验 JSON 文件中的 Bean 列表与目标类是否一致
|
||||||
}
|
* 对比文件中每个 Bean 的类名与目标类名,返回不一致信息
|
||||||
|
* @param szFilePath JSON 文件路径(存储 Bean 列表的文件)
|
||||||
|
* @param clazz 目标 Bean 类(用于校验类型)
|
||||||
|
* @return 空串:校验一致;非空串:不一致信息(总数/差异数)或异常信息
|
||||||
|
* @param <T> 泛型约束,限定为 BaseBean 子类
|
||||||
|
*/
|
||||||
|
public static <T extends BaseBean> String checkIsTheSameBeanListAndFile(String szFilePath, Class<T> clazz) {
|
||||||
|
StringBuilder sbResult = new StringBuilder();
|
||||||
|
String szErrorInfo = "Check Is The Same Bean List And File Error : ";
|
||||||
|
|
||||||
abstract public T readBeanFromJsonReader(JsonReader jsonReader) throws IOException;
|
try {
|
||||||
|
int sameCount = 0; // 类名匹配的 Bean 数量
|
||||||
|
int totalCount = 0; // 文件中 Bean 总数量
|
||||||
|
|
||||||
public static <T extends BaseBean> String checkIsTheSameBeanListAndFile(String szFilePath, Class<T> clazz) {
|
// 反射创建目标 Bean 实例(用于获取类名)
|
||||||
StringBuilder sbResult = new StringBuilder();
|
T beanTemp = clazz.newInstance();
|
||||||
String szErrorInfo = "Check Is The Same Bean List And File Error : ";
|
String targetBeanName = beanTemp.getName();
|
||||||
|
// 读取文件中的 JSON 字符串
|
||||||
|
String listJson = UTF8FileUtils.readStringFromFile(szFilePath);
|
||||||
|
StringReader stringReader = new StringReader(listJson);
|
||||||
|
JsonReader jsonReader = new JsonReader(stringReader);
|
||||||
|
|
||||||
try {
|
jsonReader.beginArray(); // 开始解析 JSON 数组(Bean 列表)
|
||||||
int nSameCount = 0;
|
while (jsonReader.hasNext()) {
|
||||||
int nBeanListCout = 0;
|
totalCount++;
|
||||||
|
jsonReader.beginObject(); // 开始解析单个 Bean 对象
|
||||||
|
while (jsonReader.hasNext()) {
|
||||||
|
String name = jsonReader.nextName();
|
||||||
|
// 只校验 BEAN_NAME 字段,其他字段跳过
|
||||||
|
if (name.equals(BEAN_NAME)) {
|
||||||
|
// 对比当前 Bean 类名与目标类名
|
||||||
|
if (targetBeanName.equals(jsonReader.nextString())) {
|
||||||
|
sameCount++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
jsonReader.skipValue(); // 跳过非目标字段
|
||||||
|
}
|
||||||
|
}
|
||||||
|
jsonReader.endObject(); // 结束单个 Bean 对象解析
|
||||||
|
}
|
||||||
|
jsonReader.endArray(); // 结束 JSON 数组解析
|
||||||
|
|
||||||
T beanTemp = clazz.newInstance();
|
// 生成校验结果
|
||||||
String szBeanSimpleName = beanTemp.getName();
|
if (sameCount == totalCount) {
|
||||||
String szListJson = UTF8FileUtils.readStringFromFile(szFilePath);
|
return ""; // 全部匹配,返回空串
|
||||||
StringReader stringReader = new StringReader(szListJson);
|
} else {
|
||||||
JsonReader jsonReader = new JsonReader(stringReader);
|
// 部分不匹配,返回统计信息
|
||||||
jsonReader.beginArray();
|
sbResult.append("Total : ").append(totalCount)
|
||||||
while (jsonReader.hasNext()) {
|
.append(" Diff : ").append(totalCount - sameCount);
|
||||||
nBeanListCout++;
|
}
|
||||||
jsonReader.beginObject();
|
} catch (InstantiationException e) {
|
||||||
while (jsonReader.hasNext()) {
|
// 反射实例化失败(如无无参构造)
|
||||||
String name = jsonReader.nextName();
|
sbResult.append(szErrorInfo).append(e);
|
||||||
if (name.equals(BEAN_NAME)) {
|
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||||
if (szBeanSimpleName.equals(jsonReader.nextString())) {
|
} catch (IllegalAccessException e) {
|
||||||
nSameCount++;
|
// 反射访问权限异常
|
||||||
}
|
sbResult.append(szErrorInfo).append(e);
|
||||||
} else {
|
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||||
jsonReader.skipValue();
|
} catch (IOException e) {
|
||||||
}
|
// 文件读取或 JSON 解析异常
|
||||||
}
|
sbResult.append(szErrorInfo).append(e);
|
||||||
jsonReader.endObject();
|
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||||
}
|
}
|
||||||
jsonReader.endArray();
|
return sbResult.toString();
|
||||||
|
}
|
||||||
|
|
||||||
// 返回检查结果
|
/**
|
||||||
if (nSameCount == nBeanListCout) {
|
* 将 JSON 字符串解析为目标 Bean 实例
|
||||||
// 检查一致直接返回空串
|
* 通过反射创建 Bean 实例,调用子类解析逻辑完成初始化
|
||||||
return "";
|
* @param szBean JSON 字符串(单个 Bean 的 JSON 数据)
|
||||||
} else {
|
* @param clazz 目标 Bean 类(用于反射实例化)
|
||||||
// 检查不一致返回对比信息
|
* @return 解析成功的 Bean 实例;失败返回 null
|
||||||
sbResult.append("Total : ");
|
* @throws IOException JSON 解析失败时抛出
|
||||||
sbResult.append(nBeanListCout);
|
* @param <T> 泛型约束,限定为 BaseBean 子类
|
||||||
sbResult.append(" Diff : ");
|
*/
|
||||||
sbResult.append(nBeanListCout - nSameCount);
|
public static <T extends BaseBean> T parseStringToBean(String szBean, Class<T> clazz) throws IOException {
|
||||||
}
|
StringReader stringReader = new StringReader(szBean);
|
||||||
} catch (InstantiationException e) {
|
JsonReader jsonReader = new JsonReader(stringReader);
|
||||||
sbResult.append(szErrorInfo);
|
|
||||||
sbResult.append(e);
|
|
||||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
sbResult.append(szErrorInfo);
|
|
||||||
sbResult.append(e);
|
|
||||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
|
||||||
} catch (IOException e) {
|
|
||||||
sbResult.append(szErrorInfo);
|
|
||||||
sbResult.append(e);
|
|
||||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
|
||||||
}
|
|
||||||
return sbResult.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T extends BaseBean> T parseStringToBean(String szBean, Class<T> clazz) throws IOException {
|
try {
|
||||||
// 创建 JsonWriter 对象
|
// 反射创建 Bean 实例
|
||||||
StringReader stringReader = new StringReader(szBean);
|
T beanTemp = clazz.newInstance();
|
||||||
JsonReader jsonReader = new JsonReader(stringReader);
|
// 调用子类解析方法,返回解析后的实例
|
||||||
try {
|
return (T) beanTemp.readBeanFromJsonReader(jsonReader);
|
||||||
T beanTemp = clazz.newInstance();
|
} catch (InstantiationException | IllegalAccessException e) {
|
||||||
return (T)beanTemp.readBeanFromJsonReader(jsonReader);
|
// 反射异常日志记录
|
||||||
} catch (InstantiationException e) {
|
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
}
|
||||||
} catch (IllegalAccessException e) {
|
return null;
|
||||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
}
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T extends BaseBean> boolean parseStringToBeanList(String szBeanList, ArrayList<T> beanList, Class<T> clazz) {
|
/**
|
||||||
try {
|
* 将 JSON 字符串解析为 Bean 列表
|
||||||
if(beanList == null) {
|
* 清空目标列表,将解析后的 Bean 逐个添加到列表中
|
||||||
beanList = new ArrayList<T>();
|
* @param szBeanList JSON 字符串(Bean 列表的 JSON 数组)
|
||||||
} else {
|
* @param beanList 目标列表(存储解析后的 Bean)
|
||||||
beanList.clear();
|
* @param clazz 目标 Bean 类(用于反射实例化)
|
||||||
}
|
* @return true:解析成功;false:解析失败
|
||||||
StringReader stringReader = new StringReader(szBeanList);
|
* @param <T> 泛型约束,限定为 BaseBean 子类
|
||||||
JsonReader jsonReader = new JsonReader(stringReader);
|
*/
|
||||||
jsonReader.beginArray();
|
public static <T extends BaseBean> boolean parseStringToBeanList(String szBeanList, ArrayList<T> beanList, Class<T> clazz) {
|
||||||
while (jsonReader.hasNext()) {
|
try {
|
||||||
T beanTemp = clazz.newInstance();
|
// 初始化目标列表(为空则创建,非空则清空)
|
||||||
T bean = (T)beanTemp.readBeanFromJsonReader(jsonReader);
|
if (beanList == null) {
|
||||||
if (bean != null) {
|
beanList = new ArrayList<T>();
|
||||||
beanList.add(bean);
|
} else {
|
||||||
//LogUtils.d(TAG, "beanList.add(bean)");
|
beanList.clear();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
jsonReader.endArray();
|
|
||||||
return true;
|
|
||||||
//LogUtils.d(TAG, "beanList.size() is " + Integer.toString(beanList.size()));
|
|
||||||
} catch (InstantiationException e) {
|
|
||||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
|
||||||
} catch (IOException e) {
|
|
||||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
StringReader stringReader = new StringReader(szBeanList);
|
||||||
public String toString() {
|
JsonReader jsonReader = new JsonReader(stringReader);
|
||||||
// 创建 JsonWriter 对象
|
|
||||||
StringWriter stringWriter = new StringWriter();
|
|
||||||
JsonWriter jsonWriter = new JsonWriter(stringWriter);
|
|
||||||
jsonWriter.setIndent(" ");
|
|
||||||
try {// 开始 JSON 对象
|
|
||||||
jsonWriter.beginObject();
|
|
||||||
// 写入键值对
|
|
||||||
writeThisToJsonWriter(jsonWriter);
|
|
||||||
// 结束 JSON 对象
|
|
||||||
jsonWriter.endObject();
|
|
||||||
return stringWriter.toString();
|
|
||||||
} catch (IOException e) {
|
|
||||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
|
||||||
}
|
|
||||||
// 获取 JSON 字符串
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T extends BaseBean> String toStringByBeanList(ArrayList<T> beanList) {
|
jsonReader.beginArray(); // 开始解析 JSON 数组
|
||||||
try {
|
while (jsonReader.hasNext()) {
|
||||||
StringWriter stringWriter = new StringWriter();
|
// 反射创建 Bean 实例,解析并添加到列表
|
||||||
JsonWriter jsonWriter = new JsonWriter(stringWriter);
|
T beanTemp = clazz.newInstance();
|
||||||
jsonWriter.setIndent(" ");
|
T bean = (T) beanTemp.readBeanFromJsonReader(jsonReader);
|
||||||
jsonWriter.beginArray();
|
if (bean != null) {
|
||||||
for (int i = 0; i < beanList.size(); i++) {
|
beanList.add(bean);
|
||||||
// 开始 JSON 对象
|
}
|
||||||
jsonWriter.beginObject();
|
}
|
||||||
// 写入键值对
|
jsonReader.endArray(); // 结束 JSON 数组解析
|
||||||
beanList.get(i).writeThisToJsonWriter(jsonWriter);
|
return true;
|
||||||
// 结束 JSON 对象
|
} catch (InstantiationException | IllegalAccessException | IOException e) {
|
||||||
jsonWriter.endObject();
|
// 异常日志记录
|
||||||
}
|
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||||
jsonWriter.endArray();
|
}
|
||||||
jsonWriter.close();
|
return false;
|
||||||
return stringWriter.toString();
|
}
|
||||||
} catch (IOException e) {
|
|
||||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重写 toString(),将 Bean 序列化为格式化的 JSON 字符串
|
||||||
|
* 调用自身序列化逻辑,生成带缩进的 JSON(便于调试)
|
||||||
|
* @return Bean 的 JSON 字符串;失败返回空串
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringWriter stringWriter = new StringWriter();
|
||||||
|
JsonWriter jsonWriter = new JsonWriter(stringWriter);
|
||||||
|
jsonWriter.setIndent(" "); // 设置 JSON 缩进(格式化输出)
|
||||||
|
|
||||||
public static <T extends BaseBean> T loadBean(Context context, Class<T> clazz) {
|
try {
|
||||||
try {
|
jsonWriter.beginObject(); // 开始 JSON 对象
|
||||||
T beanTemp = clazz.newInstance();
|
writeThisToJsonWriter(jsonWriter); // 写入 Bean 字段(子类扩展)
|
||||||
return loadBeanFromFile(beanTemp.getBeanJsonFilePath(context), clazz);
|
jsonWriter.endObject(); // 结束 JSON 对象
|
||||||
} catch (InstantiationException e) {
|
return stringWriter.toString();
|
||||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
} catch (IOException e) {
|
||||||
} catch (IllegalAccessException e) {
|
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
}
|
||||||
}
|
return "";
|
||||||
return null;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static <T extends BaseBean> T loadBeanFromFile(String szFilePath, Class<T> clazz) {
|
/**
|
||||||
try {
|
* 将 Bean 列表序列化为格式化的 JSON 字符串
|
||||||
try {
|
* 遍历列表,逐个序列化每个 Bean,生成 JSON 数组
|
||||||
File fTemp = new File(szFilePath);
|
* @param beanList 待序列化的 Bean 列表
|
||||||
if (fTemp.exists()) {
|
* @return 列表的 JSON 字符串;失败返回空串
|
||||||
T beanTemp = clazz.newInstance();String szJson = UTF8FileUtils.readStringFromFile(szFilePath);
|
* @param <T> 泛型约束,限定为 BaseBean 子类
|
||||||
return beanTemp.parseStringToBean(szJson, clazz);
|
*/
|
||||||
}
|
public static <T extends BaseBean> String toStringByBeanList(ArrayList<T> beanList) {
|
||||||
} catch (InstantiationException e) {
|
try {
|
||||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
StringWriter stringWriter = new StringWriter();
|
||||||
} catch (IllegalAccessException e) {
|
JsonWriter jsonWriter = new JsonWriter(stringWriter);
|
||||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
jsonWriter.setIndent(" "); // 格式化缩进
|
||||||
}
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
jsonWriter.beginArray(); // 开始 JSON 数组
|
||||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
for (int i = 0; i < beanList.size(); i++) {
|
||||||
}
|
jsonWriter.beginObject(); // 单个 Bean 开始
|
||||||
return null;
|
beanList.get(i).writeThisToJsonWriter(jsonWriter); // 调用 Bean 自身序列化
|
||||||
}
|
jsonWriter.endObject(); // 单个 Bean 结束
|
||||||
|
}
|
||||||
|
jsonWriter.endArray(); // 结束 JSON 数组
|
||||||
|
jsonWriter.close();
|
||||||
|
return stringWriter.toString();
|
||||||
|
} catch (IOException e) {
|
||||||
|
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
public static <T extends BaseBean> boolean saveBean(Context context, T bean) {
|
/**
|
||||||
return saveBeanToFile(bean.getBeanJsonFilePath(context), bean);
|
* 从默认路径(getBeanJsonFilePath)加载 Bean 实例
|
||||||
}
|
* 读取应用私有目录下的 JSON 文件,解析为目标 Bean
|
||||||
|
* @param context 上下文(用于获取文件路径)
|
||||||
|
* @param clazz 目标 Bean 类(用于反射实例化)
|
||||||
|
* @return 加载成功的 Bean 实例;失败返回 null
|
||||||
|
* @param <T> 泛型约束,限定为 BaseBean 子类
|
||||||
|
*/
|
||||||
|
public static <T extends BaseBean> T loadBean(Context context, Class<T> clazz) {
|
||||||
|
try {
|
||||||
|
// 反射创建 Bean 实例,获取默认文件路径
|
||||||
|
T beanTemp = clazz.newInstance();
|
||||||
|
return loadBeanFromFile(beanTemp.getBeanJsonFilePath(context), clazz);
|
||||||
|
} catch (InstantiationException | IllegalAccessException e) {
|
||||||
|
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static <T extends BaseBean> boolean saveBeanToFile(String szFilePath, T bean) {
|
/**
|
||||||
try {
|
* 从指定文件路径加载 Bean 实例
|
||||||
String szJson = bean.toString();
|
* 检查文件是否存在,存在则读取 JSON 并解析为目标 Bean
|
||||||
UTF8FileUtils.writeStringToFile(szFilePath, szJson);
|
* @param szFilePath 目标文件路径(存储 Bean 的 JSON 文件)
|
||||||
return true;
|
* @param clazz 目标 Bean 类(用于反射实例化)
|
||||||
} catch (IOException e) {
|
* @return 加载成功的 Bean 实例;失败返回 null
|
||||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
* @param <T> 泛型约束,限定为 BaseBean 子类
|
||||||
}
|
*/
|
||||||
return false;
|
public static <T extends BaseBean> T loadBeanFromFile(String szFilePath, Class<T> clazz) {
|
||||||
}
|
try {
|
||||||
|
File file = new File(szFilePath);
|
||||||
|
if (file.exists()) { // 检查文件是否存在
|
||||||
|
T beanTemp = clazz.newInstance();
|
||||||
|
// 读取文件 JSON 字符串,解析为 Bean
|
||||||
|
String json = UTF8FileUtils.readStringFromFile(szFilePath);
|
||||||
|
return beanTemp.parseStringToBean(json, clazz);
|
||||||
|
}
|
||||||
|
} catch (InstantiationException | IllegalAccessException | IOException e) {
|
||||||
|
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static <T extends BaseBean> boolean loadBeanList(Context context, ArrayList<T> beanListDst, Class<T> clazz) {
|
/**
|
||||||
try {
|
* 将 Bean 保存到默认路径(getBeanJsonFilePath)的文件中
|
||||||
T beanTemp = clazz.newInstance();
|
* 序列化 Bean 为 JSON,写入应用私有目录下的文件
|
||||||
return loadBeanListFromFile(beanTemp.getBeanListJsonFilePath(context), beanListDst, clazz);
|
* @param context 上下文(用于获取文件路径)
|
||||||
} catch (InstantiationException e) {} catch (IllegalAccessException e) {
|
* @param bean 待保存的 Bean 实例
|
||||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
* @return true:保存成功;false:保存失败
|
||||||
}
|
* @param <T> 泛型约束,限定为 BaseBean 子类
|
||||||
return false;
|
*/
|
||||||
}
|
public static <T extends BaseBean> boolean saveBean(Context context, T bean) {
|
||||||
|
return saveBeanToFile(bean.getBeanJsonFilePath(context), bean);
|
||||||
|
}
|
||||||
|
|
||||||
public static <T extends BaseBean> boolean loadBeanListFromFile(String szFilePath, ArrayList<T> beanList, Class<T> clazz) {
|
/**
|
||||||
try {
|
* 将 Bean 保存到指定文件路径
|
||||||
File fTemp = new File(szFilePath);
|
* 序列化 Bean 为 JSON 字符串,写入目标文件(覆盖原有内容)
|
||||||
if (fTemp.exists()) {
|
* @param szFilePath 目标文件路径(保存 JSON 的文件)
|
||||||
String szListJson = UTF8FileUtils.readStringFromFile(szFilePath);
|
* @param bean 待保存的 Bean 实例
|
||||||
return parseStringToBeanList(szListJson, beanList, clazz);
|
* @return true:保存成功;false:保存失败
|
||||||
}
|
* @param <T> 泛型约束,限定为 BaseBean 子类
|
||||||
} catch (IOException e) {
|
*/
|
||||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
public static <T extends BaseBean> boolean saveBeanToFile(String szFilePath, T bean) {
|
||||||
}
|
try {
|
||||||
return false;
|
// 序列化 Bean 为 JSON 字符串
|
||||||
}
|
String json = bean.toString();
|
||||||
|
// 写入文件(UTF-8 编码)
|
||||||
|
UTF8FileUtils.writeStringToFile(szFilePath, json);
|
||||||
|
return true;
|
||||||
|
} catch (IOException e) {
|
||||||
|
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public static <T extends BaseBean> boolean saveBeanList(Context context, ArrayList<T> beanList, Class<T> clazz) {
|
/**
|
||||||
try {
|
* 从默认路径(getBeanListJsonFilePath)加载 Bean 列表
|
||||||
T beanTemp = clazz.newInstance();
|
* 读取应用私有目录下的列表 JSON 文件,解析并填充到目标列表
|
||||||
return saveBeanListToFile(beanTemp.getBeanListJsonFilePath(context), beanList);
|
* @param context 上下文(用于获取文件路径)
|
||||||
} catch (InstantiationException e) {
|
* @param beanListDst 目标列表(存储加载后的 Bean)
|
||||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
* @param clazz 目标 Bean 类(用于反射实例化)
|
||||||
} catch (IllegalAccessException e) {
|
* @return true:加载成功;false:加载失败
|
||||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
* @param <T> 泛型约束,限定为 BaseBean 子类
|
||||||
}
|
*/
|
||||||
return false;
|
public static <T extends BaseBean> boolean loadBeanList(Context context, ArrayList<T> beanListDst, Class<T> clazz) {
|
||||||
}
|
try {
|
||||||
|
// 反射创建 Bean 实例,获取默认列表文件路径
|
||||||
|
T beanTemp = clazz.newInstance();
|
||||||
|
return loadBeanListFromFile(beanTemp.getBeanListJsonFilePath(context), beanListDst, clazz);
|
||||||
|
} catch (InstantiationException | IllegalAccessException e) {
|
||||||
|
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public static <T extends BaseBean> boolean saveBeanListToFile(String szFilePath, ArrayList<T> beanList) {
|
/**
|
||||||
try {
|
* 从指定文件路径加载 Bean 列表
|
||||||
String szJson = toStringByBeanList(beanList);
|
* 检查文件是否存在,存在则读取 JSON 数组,解析并填充到目标列表
|
||||||
UTF8FileUtils.writeStringToFile(szFilePath, szJson);
|
* @param szFilePath 目标文件路径(存储列表 JSON 的文件)
|
||||||
//LogUtils.d(TAG, "FileUtil.writeFile beanList.size() is " + Integer.toString(beanList.size()));
|
* @param beanList 目标列表(存储加载后的 Bean)
|
||||||
return true;
|
* @param clazz 目标 Bean 类(用于反射实例化)
|
||||||
} catch (IOException e) {
|
* @return true:加载成功;false:加载失败
|
||||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
* @param <T> 泛型约束,限定为 BaseBean 子类
|
||||||
}
|
*/
|
||||||
return false;
|
public static <T extends BaseBean> boolean loadBeanListFromFile(String szFilePath, ArrayList<T> beanList, Class<T> clazz) {
|
||||||
}
|
try {
|
||||||
|
File file = new File(szFilePath);
|
||||||
|
if (file.exists()) { // 检查文件是否存在
|
||||||
|
// 读取文件中的 JSON 字符串(Bean 列表数组)
|
||||||
|
String listJson = UTF8FileUtils.readStringFromFile(szFilePath);
|
||||||
|
// 解析 JSON 字符串为 Bean 列表,填充到目标列表
|
||||||
|
return parseStringToBeanList(listJson, beanList, clazz);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
// 日志记录文件读取或解析异常
|
||||||
|
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 Bean 列表保存到默认路径(getBeanListJsonFilePath)的文件中
|
||||||
|
* 序列化列表为 JSON 数组,写入应用私有目录下的文件
|
||||||
|
* @param context 上下文(用于获取文件路径)
|
||||||
|
* @param beanList 待保存的 Bean 列表
|
||||||
|
* @param clazz 目标 Bean 类(用于反射获取保存路径)
|
||||||
|
* @return true:保存成功;false:保存失败
|
||||||
|
* @param <T> 泛型约束,限定为 BaseBean 子类
|
||||||
|
*/
|
||||||
|
public static <T extends BaseBean> boolean saveBeanList(Context context, ArrayList<T> beanList, Class<T> clazz) {
|
||||||
|
try {
|
||||||
|
// 反射创建 Bean 实例,获取默认列表保存路径
|
||||||
|
T beanTemp = clazz.newInstance();
|
||||||
|
return saveBeanListToFile(beanTemp.getBeanListJsonFilePath(context), beanList);
|
||||||
|
} catch (InstantiationException | IllegalAccessException e) {
|
||||||
|
// 日志记录反射实例化异常
|
||||||
|
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 Bean 列表保存到指定文件路径
|
||||||
|
* 序列化列表为 JSON 数组字符串,写入目标文件(覆盖原有内容)
|
||||||
|
* @param szFilePath 目标文件路径(保存列表 JSON 的文件)
|
||||||
|
* @param beanList 待保存的 Bean 列表
|
||||||
|
* @return true:保存成功;false:保存失败
|
||||||
|
* @param <T> 泛型约束,限定为 BaseBean 子类
|
||||||
|
*/
|
||||||
|
public static <T extends BaseBean> boolean saveBeanListToFile(String szFilePath, ArrayList<T> beanList) {
|
||||||
|
try {
|
||||||
|
// 序列化 Bean 列表为 JSON 字符串(数组格式)
|
||||||
|
String json = toStringByBeanList(beanList);
|
||||||
|
// 将 JSON 字符串写入文件(UTF-8 编码)
|
||||||
|
UTF8FileUtils.writeStringToFile(szFilePath, json);
|
||||||
|
return true;
|
||||||
|
} catch (IOException e) {
|
||||||
|
// 日志记录文件写入或序列化异常
|
||||||
|
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
package cc.winboll.studio.libappbase;
|
package cc.winboll.studio.libappbase;
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
|
||||||
* @Date 2024/08/12 13:22:12
|
|
||||||
* @Describe 异常处理类
|
|
||||||
*/
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
@@ -12,29 +7,23 @@ import android.content.ClipData;
|
|||||||
import android.content.ClipboardManager;
|
import android.content.ClipboardManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ApplicationInfo;
|
|
||||||
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.graphics.Color;
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.text.SpannableString;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.text.style.ForegroundColorSpan;
|
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.HorizontalScrollView;
|
import android.widget.HorizontalScrollView;
|
||||||
import android.widget.LinearLayout;
|
|
||||||
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 android.widget.Toolbar;
|
import cc.winboll.studio.libappbase.utils.CrashHandleNotifyUtils;
|
||||||
import cc.winboll.studio.libappbase.R;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@@ -48,358 +37,522 @@ import java.text.SimpleDateFormat;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||||
|
* @Date 2025/11/11 20:14
|
||||||
|
* @Describe * 应用全局崩溃处理类(单例逻辑)
|
||||||
|
* 核心功能:捕获应用未捕获异常,记录崩溃日志到文件,启动崩溃报告页面,
|
||||||
|
* 并通过「崩溃保险丝」机制防止重复崩溃,保障基础功能可用
|
||||||
|
*/
|
||||||
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";
|
||||||
|
|
||||||
public static final String EXTRA_CRASH_INFO = "crashInfo";
|
/** Intent 传递崩溃信息的键(用于向崩溃页面传递日志) */
|
||||||
|
public static final String EXTRA_CRASH_LOG = "crashInfo";
|
||||||
|
|
||||||
final static String PREFS = CrashHandler.class.getName() + "PREFS";
|
/** SharedPreferences 存储键(用于记录崩溃状态) */
|
||||||
final static String PREFS_CRASHHANDLER_ISCRASHHAPPEN = "PREFS_CRASHHANDLER_ISCRASHHAPPEN";
|
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();
|
||||||
|
|
||||||
public static void init(Application app) {
|
/**
|
||||||
_CrashCountFilePath = app.getExternalFilesDir("CrashHandler") + "/IsCrashHandlerCrashHappen.dat";
|
* 初始化崩溃处理器(默认存储路径)
|
||||||
LogUtils.d(TAG, String.format("_CrashCountFilePath %s", _CrashCountFilePath));
|
* 调用重载方法,崩溃日志默认存储在应用外部私有目录的 crash 文件夹下
|
||||||
init(app, null);
|
* @param app 全局 Application 实例(用于获取存储目录、包信息等)
|
||||||
}
|
*/
|
||||||
|
public static void init(Application app) {
|
||||||
|
// 初始化崩溃保险丝状态文件路径(外部存储/CrashHandler/IsCrashHandlerCrashHappen.dat)
|
||||||
|
_CrashCountFilePath = app.getExternalFilesDir("CrashHandler") + "/IsCrashHandlerCrashHappen.dat";
|
||||||
|
LogUtils.d(TAG, String.format("_CrashCountFilePath %s", _CrashCountFilePath));
|
||||||
|
// 调用带目录参数的初始化方法,传入 null 使用默认路径
|
||||||
|
init(app, null);
|
||||||
|
}
|
||||||
|
|
||||||
public static void init(final Application app, final String crashDir) {
|
/**
|
||||||
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler(){
|
* 初始化崩溃处理器(指定日志存储目录)
|
||||||
|
* 替换系统默认的未捕获异常处理器,自定义崩溃处理逻辑
|
||||||
|
* @param app 全局 Application 实例
|
||||||
|
* @param crashDir 崩溃日志存储目录(null 则使用默认路径)
|
||||||
|
*/
|
||||||
|
public static void init(final Application app, final String crashDir) {
|
||||||
|
// 设置自定义未捕获异常处理器
|
||||||
|
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
|
||||||
|
@Override
|
||||||
|
public void uncaughtException(Thread thread, Throwable throwable) {
|
||||||
|
try {
|
||||||
|
// 尝试处理崩溃(捕获内部异常,避免 CrashHandler 自身崩溃)
|
||||||
|
tryUncaughtException(thread, throwable);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
// 处理失败时,交给系统默认处理器兜底
|
||||||
|
if (DEFAULT_UNCAUGHT_EXCEPTION_HANDLER != null) {
|
||||||
|
DEFAULT_UNCAUGHT_EXCEPTION_HANDLER.uncaughtException(thread, throwable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public void uncaughtException(Thread thread, Throwable throwable) {
|
* 实际处理崩溃的核心方法
|
||||||
try {
|
* 1. 熔断保险丝(记录崩溃次数);2. 收集崩溃信息;3. 写入日志文件;4. 启动崩溃报告页面
|
||||||
tryUncaughtException(thread, throwable);
|
* @param thread 发生崩溃的线程
|
||||||
} catch (Throwable e) {
|
* @param throwable 崩溃异常对象(包含堆栈信息)
|
||||||
e.printStackTrace();
|
*/
|
||||||
if (DEFAULT_UNCAUGHT_EXCEPTION_HANDLER != null)
|
private void tryUncaughtException(Thread thread, Throwable throwable) {
|
||||||
DEFAULT_UNCAUGHT_EXCEPTION_HANDLER.uncaughtException(thread, throwable);
|
// 触发崩溃保险丝(每次崩溃熔断一次,降低防护等级)
|
||||||
}
|
AppCrashSafetyWire.getInstance().burnSafetyWire();
|
||||||
}
|
|
||||||
|
|
||||||
private void tryUncaughtException(Thread thread, Throwable throwable) {
|
// 格式化崩溃发生时间(用于日志文件名和内容)
|
||||||
// 每到这里就燃烧一次保险丝
|
final String time = new SimpleDateFormat("yyyy_MM_dd-HH_mm_ss", Locale.getDefault()).format(new Date());
|
||||||
AppCrashSafetyWire.getInstance().burnSafetyWire();
|
// 创建崩溃日志文件(默认路径:外部存储/crash/[时间].txt)
|
||||||
|
File crashFile = new File(
|
||||||
|
TextUtils.isEmpty(crashDir) ? new File(app.getExternalFilesDir(null), "crash") : new File(crashDir),
|
||||||
|
"crash_" + time + ".txt"
|
||||||
|
);
|
||||||
|
|
||||||
final String time = new SimpleDateFormat("yyyy_MM_dd-HH_mm_ss", Locale.getDefault()).format(new Date());
|
// 获取应用版本信息(版本名、版本号)
|
||||||
File crashFile = new File(TextUtils.isEmpty(crashDir) ? new File(app.getExternalFilesDir(null), "crash")
|
String versionName = "unknown";
|
||||||
: new File(crashDir), "crash_" + time + ".txt");
|
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 versionName = "unknown";
|
// 将异常堆栈信息转换为字符串
|
||||||
long versionCode = 0;
|
String fullStackTrace;
|
||||||
try {
|
{
|
||||||
PackageInfo packageInfo = app.getPackageManager().getPackageInfo(app.getPackageName(), 0);
|
StringWriter sw = new StringWriter();
|
||||||
versionName = packageInfo.versionName;
|
PrintWriter pw = new PrintWriter(sw);
|
||||||
versionCode = Build.VERSION.SDK_INT >= 28 ? packageInfo.getLongVersionCode()
|
throwable.printStackTrace(pw); // 将异常堆栈写入 PrintWriter
|
||||||
: packageInfo.versionCode;
|
fullStackTrace = sw.toString();
|
||||||
} catch (PackageManager.NameNotFoundException ignored) {}
|
pw.close();
|
||||||
|
}
|
||||||
|
|
||||||
String fullStackTrace; {
|
// 拼接崩溃信息(设备信息 + 应用信息 + 堆栈信息)
|
||||||
StringWriter sw = new StringWriter();
|
StringBuilder sb = new StringBuilder();
|
||||||
PrintWriter pw = new PrintWriter(sw);
|
sb.append("************* Crash Head ****************\n");
|
||||||
throwable.printStackTrace(pw);
|
sb.append("Time Of Crash : ").append(time).append("\n");
|
||||||
fullStackTrace = sw.toString();
|
sb.append("Device Manufacturer : ").append(Build.MANUFACTURER).append("\n"); // 设备厂商
|
||||||
pw.close();
|
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); // 拼接异常堆栈
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
final String errorLog = sb.toString();
|
||||||
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);
|
|
||||||
|
|
||||||
String errorLog = sb.toString();
|
// 将崩溃日志写入文件(忽略写入失败)
|
||||||
|
try {
|
||||||
|
writeFile(crashFile, errorLog);
|
||||||
|
} catch (IOException ignored) {}
|
||||||
|
|
||||||
try {
|
// 启动崩溃报告页面(标签用于代码块折叠)
|
||||||
writeFile(crashFile, errorLog);
|
gotoCrashActiviy: {
|
||||||
} catch (IOException ignored) {}
|
Intent intent = new Intent();
|
||||||
|
LogUtils.d(TAG, "gotoCrashActiviy: ");
|
||||||
|
|
||||||
gotoCrashActiviy: {
|
// 根据保险丝状态选择启动的崩溃页面
|
||||||
Intent intent = new Intent();
|
if (AppCrashSafetyWire.getInstance().isAppCrashSafetyWireOK()) {
|
||||||
LogUtils.d(TAG, "gotoCrashActiviy: ");
|
LogUtils.d(TAG, "gotoCrashActiviy: isAppCrashSafetyWireOK");
|
||||||
if (AppCrashSafetyWire.getInstance().isAppCrashSafetyWireOK()) {
|
// 保险丝正常:启动自定义样式的崩溃报告页面(GlobalCrashActivity)
|
||||||
LogUtils.d(TAG, "gotoCrashActiviy: isAppCrashSafetyWireOK");
|
intent.setClass(app, GlobalCrashActivity.class);
|
||||||
intent.setClass(app, GlobalCrashActivity.class);
|
intent.putExtra(EXTRA_CRASH_LOG, errorLog); // 传递崩溃日志
|
||||||
intent.putExtra(EXTRA_CRASH_INFO, errorLog);
|
} else {
|
||||||
// 如果发生了 CrashHandler 内部崩溃, 就调用基础的应用崩溃显示类
|
LogUtils.d(TAG, "gotoCrashActiviy: else");
|
||||||
// intent.setClass(app, GlobalCrashActiviy.class);
|
// 保险丝熔断:启动基础版崩溃页面(CrashActivity,避免复杂页面再次崩溃)
|
||||||
// intent.putExtra(GlobalCrashActiviy.EXTRA_CRASH_INFO, errorLog);
|
intent.setClass(app, CrashActivity.class);
|
||||||
} else {
|
intent.putExtra(EXTRA_CRASH_LOG, errorLog);
|
||||||
LogUtils.d(TAG, "gotoCrashActiviy: else");
|
}
|
||||||
// 正常状态调用进阶的应用崩溃显示页
|
|
||||||
intent.setClass(app, CrashActivity.class);
|
|
||||||
intent.putExtra(EXTRA_CRASH_INFO, 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);
|
||||||
|
|
||||||
// intent.setClass(app, CrashActiviy.class);
|
} catch (ActivityNotFoundException e) {
|
||||||
// intent.putExtra(CrashActiviy.EXTRA_CRASH_INFO, errorLog);
|
// 未找到崩溃页面(如未在 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) {}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
intent.addFlags(
|
/**
|
||||||
Intent.FLAG_ACTIVITY_NEW_TASK
|
* 应用崩溃保险丝内部类(单例)
|
||||||
| Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK
|
* 核心作用:限制短时间内重复崩溃,通过「熔断等级」控制崩溃页面启动策略
|
||||||
);
|
* 等级范围:MINI(1)~ MAX(2),每次崩溃等级-1,熔断后启动基础版崩溃页面
|
||||||
|
*/
|
||||||
|
public static final class AppCrashSafetyWire {
|
||||||
|
|
||||||
try {
|
/** 单例实例(volatile 保证多线程可见性) */
|
||||||
app.startActivity(intent);
|
private static volatile AppCrashSafetyWire _AppCrashSafetyWire;
|
||||||
android.os.Process.killProcess(android.os.Process.myPid());
|
|
||||||
System.exit(0);
|
|
||||||
} catch (ActivityNotFoundException e) {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
/** 当前熔断等级(1:最低防护;2:最高防护;≤0:熔断) */
|
||||||
|
private volatile Integer currentSafetyLevel;
|
||||||
|
/** 最低熔断等级(1,再崩溃则熔断) */
|
||||||
|
private static final int _MINI = 1;
|
||||||
|
/** 最高熔断等级(2,初始状态) */
|
||||||
|
private static final int _MAX = 2;
|
||||||
|
|
||||||
private void writeFile(File file, String content) throws IOException {
|
/**
|
||||||
File parentFile = file.getParentFile();
|
* 私有构造方法(单例模式,禁止外部实例化)
|
||||||
if (parentFile != null && !parentFile.exists()) {
|
* 初始化时加载本地存储的熔断等级
|
||||||
parentFile.mkdirs();
|
*/
|
||||||
}
|
private AppCrashSafetyWire() {
|
||||||
file.createNewFile();
|
LogUtils.d(TAG, "AppCrashSafetyWire()");
|
||||||
FileOutputStream fos = new FileOutputStream(file);
|
currentSafetyLevel = loadCurrentSafetyLevel();
|
||||||
fos.write(content.getBytes());
|
}
|
||||||
try {
|
|
||||||
fos.close();
|
|
||||||
} catch (IOException e) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
/**
|
||||||
}
|
* 获取单例实例(双重检查锁定,线程安全)
|
||||||
|
* @return AppCrashSafetyWire 单例
|
||||||
|
*/
|
||||||
|
public static synchronized AppCrashSafetyWire getInstance() {
|
||||||
|
if (_AppCrashSafetyWire == null) {
|
||||||
|
_AppCrashSafetyWire = new AppCrashSafetyWire();
|
||||||
|
}
|
||||||
|
return _AppCrashSafetyWire;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
/**
|
||||||
// 应用崩溃保险丝
|
* 设置当前熔断等级(内存中)
|
||||||
//
|
* @param currentSafetyLevel 目标等级(1~2)
|
||||||
public static final class AppCrashSafetyWire {
|
*/
|
||||||
|
public void setCurrentSafetyLevel(int currentSafetyLevel) {
|
||||||
|
this.currentSafetyLevel = currentSafetyLevel;
|
||||||
|
}
|
||||||
|
|
||||||
volatile static AppCrashSafetyWire _AppCrashSafetyWire;
|
/**
|
||||||
|
* 获取当前熔断等级(内存中)
|
||||||
|
* @return 当前等级(1~2 或 null)
|
||||||
|
*/
|
||||||
|
public int getCurrentSafetyLevel() {
|
||||||
|
return currentSafetyLevel;
|
||||||
|
}
|
||||||
|
|
||||||
volatile Integer currentSafetyLevel; // 熔断值,为 0 表示熔断了。
|
/**
|
||||||
private static final int _MINI = 1;
|
* 保存熔断等级到本地文件(持久化,重启应用生效)
|
||||||
private static final int _MAX = 2;
|
* @param currentSafetyLevel 待保存的等级
|
||||||
|
*/
|
||||||
|
public void saveCurrentSafetyLevel(int currentSafetyLevel) {
|
||||||
|
LogUtils.d(TAG, "saveCurrentSafetyLevel()");
|
||||||
|
this.currentSafetyLevel = currentSafetyLevel;
|
||||||
|
try {
|
||||||
|
// 序列化等级到文件(ObjectOutputStream 写入 int)
|
||||||
|
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(_CrashCountFilePath));
|
||||||
|
oos.writeInt(currentSafetyLevel);
|
||||||
|
oos.flush();
|
||||||
|
oos.close();
|
||||||
|
LogUtils.d(TAG, String.format("saveCurrentSafetyLevel writeInt currentSafetyLevel %d", currentSafetyLevel));
|
||||||
|
} catch (IOException e) {
|
||||||
|
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
AppCrashSafetyWire() {
|
/**
|
||||||
LogUtils.d(TAG, "AppCrashSafetyWire()");
|
* 从本地文件加载熔断等级(应用启动时初始化)
|
||||||
currentSafetyLevel = loadCurrentSafetyLevel();
|
* @return 加载的等级(文件不存在则初始化为 MAX(2))
|
||||||
}
|
*/
|
||||||
|
public int loadCurrentSafetyLevel() {
|
||||||
|
LogUtils.d(TAG, "loadCurrentSafetyLevel()");
|
||||||
|
try {
|
||||||
|
File f = new File(_CrashCountFilePath);
|
||||||
|
if (f.exists()) {
|
||||||
|
// 反序列化从文件读取等级
|
||||||
|
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(_CrashCountFilePath));
|
||||||
|
currentSafetyLevel = ois.readInt();
|
||||||
|
LogUtils.d(TAG, String.format("loadCurrentSafetyLevel() readInt currentSafetyLevel %d", currentSafetyLevel));
|
||||||
|
} else {
|
||||||
|
// 文件不存在,初始化等级为最高(2)并保存
|
||||||
|
currentSafetyLevel = _MAX;
|
||||||
|
LogUtils.d(TAG, String.format("loadCurrentSafetyLevel() currentSafetyLevel init to _MAX->%d", _MAX));
|
||||||
|
saveCurrentSafetyLevel(currentSafetyLevel);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||||
|
}
|
||||||
|
return currentSafetyLevel;
|
||||||
|
}
|
||||||
|
|
||||||
public static synchronized AppCrashSafetyWire getInstance() {
|
/**
|
||||||
if (_AppCrashSafetyWire == null) {
|
* 熔断保险丝(每次崩溃调用,降低防护等级)
|
||||||
_AppCrashSafetyWire = new AppCrashSafetyWire();
|
* @return 熔断后是否仍在防护范围内(true:是;false:已熔断)
|
||||||
}
|
*/
|
||||||
return _AppCrashSafetyWire;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
public void setCurrentSafetyLevel(int currentSafetyLevel) {
|
/**
|
||||||
this.currentSafetyLevel = currentSafetyLevel;
|
* 检查熔断等级是否在有效范围内(1~2)
|
||||||
}
|
* @param safetyLevel 待检查的等级
|
||||||
|
* @return true:在范围内(防护有效);false:超出范围(已熔断)
|
||||||
|
*/
|
||||||
|
boolean isSafetyWireWorking(int safetyLevel) {
|
||||||
|
LogUtils.d(TAG, "isSafetyWireOK()");
|
||||||
|
LogUtils.d(TAG, String.format("SafetyLevel %d", safetyLevel));
|
||||||
|
|
||||||
public int getCurrentSafetyLevel() {
|
if (safetyLevel >= _MINI && safetyLevel <= _MAX) {
|
||||||
return currentSafetyLevel;
|
LogUtils.d(TAG, String.format("In Safety Level"));
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
|
LogUtils.d(TAG, String.format("Out of Safety Level"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public void saveCurrentSafetyLevel(int currentSafetyLevel) {
|
/**
|
||||||
LogUtils.d(TAG, "saveCurrentSafetyLevel()");
|
* 立即恢复熔断等级到最高(2)
|
||||||
this.currentSafetyLevel = currentSafetyLevel;
|
* 用于重启应用后重置防护状态
|
||||||
try {
|
*/
|
||||||
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(_CrashCountFilePath));
|
void resumeToMaximumImmediately() {
|
||||||
oos.writeInt(currentSafetyLevel);
|
LogUtils.d(TAG, "resumeToMaximumImmediately() call saveCurrentSafetyLevel(_MAX)");
|
||||||
oos.flush();
|
AppCrashSafetyWire.getInstance().saveCurrentSafetyLevel(_MAX);
|
||||||
oos.close();
|
}
|
||||||
LogUtils.d(TAG, String.format("saveCurrentSafetyLevel writeInt currentSafetyLevel %d", currentSafetyLevel));
|
|
||||||
} catch (IOException e) {
|
|
||||||
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int loadCurrentSafetyLevel() {
|
/**
|
||||||
LogUtils.d(TAG, "loadCurrentSafetyLevel()");
|
* 关闭防护(设置等级为最低(1))
|
||||||
try {
|
* 下次崩溃直接熔断
|
||||||
File f = new File(_CrashCountFilePath);
|
*/
|
||||||
if (f.exists()) {
|
void off() {
|
||||||
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(_CrashCountFilePath));
|
LogUtils.d(TAG, "off()");
|
||||||
currentSafetyLevel = ois.readInt();
|
saveCurrentSafetyLevel(_MINI);
|
||||||
LogUtils.d(TAG, String.format("loadCurrentSafetyLevel() readInt currentSafetyLevel %d", currentSafetyLevel));
|
}
|
||||||
} else {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean burnSafetyWire() {
|
/**
|
||||||
LogUtils.d(TAG, "burnSafetyWire()");
|
* 检查当前保险丝是否有效(防护未熔断)
|
||||||
// 崩溃计数进入崩溃保险值
|
* @return true:有效(等级 1~2);false:已熔断
|
||||||
int safeLevel = loadCurrentSafetyLevel();
|
*/
|
||||||
if (isSafetyWireWorking(safeLevel)) {
|
boolean isAppCrashSafetyWireOK() {
|
||||||
// 如果保险丝未熔断, 就增加一次熔断值
|
LogUtils.d(TAG, "isAppCrashSafetyWireOK()");
|
||||||
LogUtils.d(TAG, "burnSafetyWire() use");
|
currentSafetyLevel = loadCurrentSafetyLevel();
|
||||||
saveCurrentSafetyLevel(safeLevel - 1);
|
return isSafetyWireWorking(currentSafetyLevel);
|
||||||
return isSafetyWireWorking(safeLevel - 1);
|
}
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isSafetyWireWorking(int safetyLevel) {
|
/**
|
||||||
LogUtils.d(TAG, "isSafetyWireOK()");
|
* 延迟恢复保险丝到最高等级(500ms 后)
|
||||||
//safetyLevel = _MINI;
|
* 核心作用:崩溃页面启动后,若下次即将熔断,提前恢复防护等级,避免持续崩溃
|
||||||
//safetyLevel = _MINI - 1;
|
* @param context 上下文(用于获取主线程 Handler)
|
||||||
//safetyLevel = _MINI + 1;
|
*/
|
||||||
//safetyLevel = _MAX;
|
void postResumeCrashSafetyWireHandler(final Context context) {
|
||||||
//safetyLevel = _MAX + 1;
|
// 主线程延迟 500ms 执行(避免页面启动时阻塞)
|
||||||
LogUtils.d(TAG, String.format("SafetyLevel %d", safetyLevel));
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (safetyLevel >= _MINI && safetyLevel <= _MAX) {
|
/**
|
||||||
// 如果在保险值之内
|
* 基础版崩溃报告页面(保险丝熔断时启动)
|
||||||
LogUtils.d(TAG, String.format("In Safety Level"));
|
* 极简实现:仅展示崩溃日志,提供复制、重启功能,避免复杂布局导致二次崩溃
|
||||||
return true;
|
*/
|
||||||
}
|
public static final class CrashActivity extends Activity implements MenuItem.OnMenuItemClickListener {
|
||||||
LogUtils.d(TAG, String.format("Out of Safety Level"));
|
/** 菜单标识:复制崩溃日志 */
|
||||||
return false;
|
private static final int MENUITEM_COPY = 0;
|
||||||
}
|
/** 菜单标识:重启应用 */
|
||||||
|
private static final int MENUITEM_RESTART = 1;
|
||||||
|
|
||||||
void resumeToMaximumImmediately() {
|
/** 崩溃日志文本(从 CrashHandler 传递过来) */
|
||||||
LogUtils.d(TAG, "resumeToMaximumImmediately() call saveCurrentSafetyLevel(_MAX)");
|
private String mLog;
|
||||||
AppCrashSafetyWire.getInstance().saveCurrentSafetyLevel(_MAX);
|
|
||||||
}
|
|
||||||
|
|
||||||
void off() {
|
@Override
|
||||||
LogUtils.d(TAG, "off()");
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
saveCurrentSafetyLevel(_MINI);
|
super.onCreate(savedInstanceState);
|
||||||
}
|
// 初始化崩溃保险丝延迟恢复机制
|
||||||
|
AppCrashSafetyWire.getInstance().postResumeCrashSafetyWireHandler(getApplicationContext());
|
||||||
|
|
||||||
boolean isAppCrashSafetyWireOK() {
|
// 获取传递的崩溃日志
|
||||||
LogUtils.d(TAG, "isAppCrashSafetyWireOK()");
|
mLog = getIntent().getStringExtra(EXTRA_CRASH_LOG);
|
||||||
currentSafetyLevel = loadCurrentSafetyLevel();
|
// 设置系统默认主题(避免自定义主题冲突)
|
||||||
return isSafetyWireWorking(currentSafetyLevel);
|
setTheme(android.R.style.Theme_DeviceDefault_Light_DarkActionBar);
|
||||||
}
|
|
||||||
|
|
||||||
// 调用函数以启用持续崩溃保险,从而调用 CrashHandler 内部崩溃处理窗口
|
// 动态创建布局(避免 XML 布局加载异常)
|
||||||
void postResumeCrashSafetyWireHandler(final Context context) {
|
setContentView: {
|
||||||
new Handler(Looper.getMainLooper()).postDelayed(new Runnable(){
|
// 垂直滚动视图(处理日志过长)
|
||||||
@Override
|
ScrollView contentView = new ScrollView(this);
|
||||||
public void run() {
|
contentView.setFillViewport(true);
|
||||||
LogUtils.d(TAG, "Handler run()");
|
|
||||||
if (!AppCrashSafetyWire.getInstance().isSafetyWireWorking(currentSafetyLevel - 1)) {
|
|
||||||
// 如果下一次应用崩溃时,保险丝熔断,则先恢复保险丝满能状态
|
|
||||||
// 进程持续运行时,恢复保险丝熔断值
|
|
||||||
//Resume to maximum
|
|
||||||
AppCrashSafetyWire.getInstance().resumeToMaximumImmediately();
|
|
||||||
LogUtils.d(TAG, "postResumeCrashSafetyWireHandler");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 500);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final class CrashActivity extends Activity implements MenuItem.OnMenuItemClickListener {
|
// 水平滚动视图(处理日志行过长)
|
||||||
private static final int MENUITEM_COPY = 0;
|
HorizontalScrollView hw = new HorizontalScrollView(this);
|
||||||
private static final int MENUITEM_RESTART = 1;
|
hw.setBackgroundColor(Color.GRAY); // 背景色设为灰色
|
||||||
|
|
||||||
private String mLog;
|
// 日志显示文本框
|
||||||
|
TextView message = new TextView(this);
|
||||||
|
{
|
||||||
|
int padding = dp2px(16); // 内边距 16dp(适配不同屏幕)
|
||||||
|
message.setPadding(padding, padding, padding, padding);
|
||||||
|
message.setText(mLog); // 设置崩溃日志
|
||||||
|
message.setTextColor(Color.BLACK); // 文字黑色
|
||||||
|
message.setTextIsSelectable(true); // 支持文本选择(便于手动复制)
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
// 组装布局:TextView -> HorizontalScrollView -> ScrollView
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
hw.addView(message);
|
||||||
super.onCreate(savedInstanceState);
|
contentView.addView(hw, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||||
AppCrashSafetyWire.getInstance().postResumeCrashSafetyWireHandler(getApplicationContext());
|
// 设置当前 Activity 布局
|
||||||
|
setContentView(contentView);
|
||||||
|
|
||||||
mLog = getIntent().getStringExtra(EXTRA_CRASH_INFO);
|
// 配置 ActionBar 标题和副标题
|
||||||
setTheme(android.R.style.Theme_DeviceDefault_Light_DarkActionBar);
|
getActionBar().setTitle(TITTLE);
|
||||||
setContentView: {
|
getActionBar().setSubtitle(GlobalApplication.class.getSimpleName() + " Error");
|
||||||
ScrollView contentView = new ScrollView(this);
|
}
|
||||||
contentView.setFillViewport(true);
|
}
|
||||||
|
|
||||||
HorizontalScrollView hw = new HorizontalScrollView(this);
|
/**
|
||||||
hw.setBackgroundColor(Color.GRAY);
|
* 重写返回键逻辑:点击返回键直接重启应用
|
||||||
TextView message = new TextView(this); {
|
*/
|
||||||
int padding = dp2px(16);
|
@Override
|
||||||
message.setPadding(padding, padding, padding, padding);
|
public void onBackPressed() {
|
||||||
message.setText(mLog);
|
restart();
|
||||||
message.setTextColor(Color.BLACK);
|
}
|
||||||
message.setTextIsSelectable(true);
|
|
||||||
}
|
|
||||||
hw.addView(message);
|
|
||||||
|
|
||||||
contentView.addView(hw, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
/**
|
||||||
setContentView(contentView);
|
* 重启当前应用(与 GlobalCrashActivity 逻辑一致)
|
||||||
getActionBar().setTitle(TITTLE);
|
* 清除任务栈,启动主 Activity,终止当前进程
|
||||||
getActionBar().setSubtitle(GlobalApplication.class.getSimpleName() + " Error");
|
*/
|
||||||
}
|
private void restart() {
|
||||||
}
|
PackageManager pm = getPackageManager();
|
||||||
|
// 获取应用启动意图(默认启动主 Activity)
|
||||||
|
Intent intent = pm.getLaunchIntentForPackage(getPackageName());
|
||||||
|
if (intent != null) {
|
||||||
|
// 设置意图标志:清除原有任务栈,创建新任务
|
||||||
|
intent.addFlags(
|
||||||
|
Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
|
| Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||||
|
| Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||||
|
);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
// 关闭当前页面,终止进程,确保完全重启
|
||||||
|
finish();
|
||||||
|
android.os.Process.killProcess(android.os.Process.myPid());
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public void onBackPressed() {
|
* dp 转 px(适配不同屏幕密度)
|
||||||
restart();
|
* @param dpValue dp 值
|
||||||
}
|
* @return 转换后的 px 值
|
||||||
|
*/
|
||||||
|
private int dp2px(final float dpValue) {
|
||||||
|
final float scale = Resources.getSystem().getDisplayMetrics().density;
|
||||||
|
return (int) (dpValue * scale + 0.5f); // 四舍五入确保精度
|
||||||
|
}
|
||||||
|
|
||||||
private void restart() {
|
/**
|
||||||
PackageManager pm = getPackageManager();
|
* 菜单点击事件回调(处理复制、重启)
|
||||||
Intent intent = pm.getLaunchIntentForPackage(getPackageName());
|
* @param item 被点击的菜单项
|
||||||
if (intent != null) {
|
* @return false:不消费事件(保持默认行为)
|
||||||
intent.addFlags(
|
*/
|
||||||
Intent.FLAG_ACTIVITY_NEW_TASK
|
@Override
|
||||||
| Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
);
|
switch (item.getItemId()) {
|
||||||
startActivity(intent);
|
case MENUITEM_COPY:
|
||||||
}
|
// 复制日志到剪贴板
|
||||||
finish();
|
ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
android.os.Process.killProcess(android.os.Process.myPid());
|
cm.setPrimaryClip(ClipData.newPlainText(getPackageName(), mLog));
|
||||||
System.exit(0);
|
Toast.makeText(getApplication(), "The text is copied.", Toast.LENGTH_SHORT).show();
|
||||||
}
|
break;
|
||||||
|
case MENUITEM_RESTART:
|
||||||
|
// 恢复保险丝到最高等级,然后重启应用
|
||||||
|
AppCrashSafetyWire.getInstance().resumeToMaximumImmediately();
|
||||||
|
restart();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private int dp2px(final float dpValue) {
|
/**
|
||||||
final float scale = Resources.getSystem().getDisplayMetrics().density;
|
* 创建 ActionBar 菜单(添加复制、重启项)
|
||||||
return (int) (dpValue * scale + 0.5f);
|
* @param menu 菜单容器
|
||||||
}
|
* @return true:显示菜单
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
switch (item.getItemId()) {
|
// 添加「复制」菜单:有空间时显示在 ActionBar,否则放入溢出菜单
|
||||||
case MENUITEM_COPY:
|
menu.add(0, MENUITEM_COPY, 0, "Copy")
|
||||||
ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
.setOnMenuItemClickListener(this)
|
||||||
cm.setPrimaryClip(ClipData.newPlainText(getPackageName(), mLog));
|
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||||
Toast.makeText(getApplication(), "The text is copied.", Toast.LENGTH_SHORT).show();
|
// 添加「重启」菜单:同上
|
||||||
break;
|
menu.add(0, MENUITEM_RESTART, 0, "Restart")
|
||||||
case MENUITEM_RESTART:
|
.setOnMenuItemClickListener(this)
|
||||||
AppCrashSafetyWire.getInstance().resumeToMaximumImmediately();
|
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||||
restart();
|
return true;
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
|
||||||
menu.add(0, MENUITEM_COPY, 0, "Copy").setOnMenuItemClickListener(this)
|
|
||||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
|
||||||
menu.add(0, MENUITEM_RESTART, 0, "Restart").setOnMenuItemClickListener(this)
|
|
||||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,70 +1,176 @@
|
|||||||
package cc.winboll.studio.libappbase;
|
package cc.winboll.studio.libappbase;
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
|
||||||
* @Date 2025/01/05 10:10:23
|
|
||||||
* @Describe 全局应用类
|
|
||||||
*/
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import cc.winboll.studio.libappbase.GlobalApplication;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||||
|
* @Date 2025/11/11 19:56
|
||||||
|
* @Describe 全局 Application 类,用于初始化应用核心组件、管理全局状态(如调试模式)
|
||||||
|
* 需在 AndroidManifest.xml 中配置 android:name=".GlobalApplication" 使其生效
|
||||||
|
*/
|
||||||
public class GlobalApplication extends Application {
|
public class GlobalApplication extends Application {
|
||||||
|
|
||||||
|
/** 日志标签 */
|
||||||
public static final String TAG = "GlobalApplication";
|
public static final String TAG = "GlobalApplication";
|
||||||
|
|
||||||
// 应用是否处于调试状态
|
/** 全局 Application 单例实例(volatile 保证多线程可见性,避免指令重排) */
|
||||||
volatile static boolean isDebuging = false;
|
private static volatile GlobalApplication sInstance;
|
||||||
|
|
||||||
public static void setIsDebuging(boolean isDebuging) {
|
/**
|
||||||
GlobalApplication.isDebuging = isDebuging;
|
* 应用调试模式标记(volatile 保证多线程可见性)
|
||||||
|
* true:调试模式(开启日志、调试功能);false:正式模式(关闭调试相关功能)
|
||||||
|
*/
|
||||||
|
private static volatile boolean isDebugging = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取全局 Application 单例实例(外部可通过此方法获取上下文)
|
||||||
|
* @return GlobalApplication 单例(未初始化时返回 null,需确保配置 AndroidManifest)
|
||||||
|
*/
|
||||||
|
public static GlobalApplication getInstance() {
|
||||||
|
return sInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置应用调试模式
|
||||||
|
* @param debugging 调试模式状态(true/false)
|
||||||
|
*/
|
||||||
|
public static void setIsDebugging(boolean debugging) {
|
||||||
|
isDebugging = debugging;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存调试模式状态到本地文件(持久化存储,重启应用后生效)
|
||||||
|
* @param application 全局 Application 实例(通过 getInstance() 获取更规范)
|
||||||
|
*/
|
||||||
public static void saveDebugStatus(GlobalApplication application) {
|
public static void saveDebugStatus(GlobalApplication application) {
|
||||||
APPModel.saveBeanToFile(application.getAPPModelFilePath(application), new APPModel(GlobalApplication.isDebuging));
|
if (application == null) {
|
||||||
|
LogUtils.e(TAG, "saveDebugStatus: Application 实例为空,保存失败");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 将调试状态封装为 APPModel 并保存到文件
|
||||||
|
APPModel.saveBeanToFile(
|
||||||
|
getAppModelFilePath(application),
|
||||||
|
new APPModel(isDebugging)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static String getAPPModelFilePath(GlobalApplication application) {
|
/**
|
||||||
|
* 获取 APPModel 配置文件的存储路径
|
||||||
|
* 路径:应用私有数据目录 / APPModel.json(仅当前应用可访问,安全)
|
||||||
|
* @param application 全局 Application 实例
|
||||||
|
* @return 配置文件绝对路径
|
||||||
|
*/
|
||||||
|
private static String getAppModelFilePath(GlobalApplication application) {
|
||||||
return application.getDataDir().getPath() + "/APPModel.json";
|
return application.getDataDir().getPath() + "/APPModel.json";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isDebuging() {
|
/**
|
||||||
return isDebuging;
|
* 获取当前应用调试模式状态
|
||||||
|
* @return true:调试模式;false:正式模式
|
||||||
|
*/
|
||||||
|
public static boolean isDebugging() {
|
||||||
|
return isDebugging;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用启动时初始化(仅执行一次)
|
||||||
|
* 初始化核心框架、恢复调试状态、配置全局异常处理等
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
// 初始化单例实例(确保在所有初始化操作前完成)
|
||||||
|
sInstance = this;
|
||||||
|
|
||||||
setIsDebuging(true);
|
|
||||||
// 添加日志模块
|
|
||||||
LogUtils.init(this);
|
|
||||||
// 设置应用异常处理窗口
|
|
||||||
CrashHandler.init(this);
|
|
||||||
// 初始化 Toast 框架
|
|
||||||
ToastUtils.init(this);
|
|
||||||
|
|
||||||
// 应用保存的调试标志
|
// 初始化基础组件(日志、崩溃处理、Toast)
|
||||||
APPModel appModel = APPModel.loadBeanFromFile(getAPPModelFilePath(this), APPModel.class);
|
initCoreComponents();
|
||||||
|
// 恢复/初始化调试模式状态(从本地文件读取,无文件则默认关闭调试)
|
||||||
|
restoreDebugStatus();
|
||||||
|
|
||||||
|
LogUtils.d(TAG, "GlobalApplication 初始化完成,单例实例已创建");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化应用核心组件(日志、崩溃处理、Toast 框架)
|
||||||
|
*/
|
||||||
|
private void initCoreComponents() {
|
||||||
|
// 初始化日志工具(传入 Application 上下文)
|
||||||
|
LogUtils.init(this);
|
||||||
|
// 初始化全局异常处理器(捕获应用崩溃信息,用于调试或上报)
|
||||||
|
CrashHandler.init(this);
|
||||||
|
// 初始化 Toast 工具(统一 Toast 样式、避免内存泄漏等)
|
||||||
|
ToastUtils.init(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 恢复调试模式状态(从本地配置文件读取)
|
||||||
|
* 1. 读取本地 APPModel.json 文件
|
||||||
|
* 2. 读取成功:使用保存的调试状态;读取失败(文件不存在):默认关闭调试并创建配置文件
|
||||||
|
*/
|
||||||
|
private void restoreDebugStatus() {
|
||||||
|
// 从文件加载 APPModel 实例(存储调试状态的模型类)
|
||||||
|
APPModel appModel = APPModel.loadBeanFromFile(
|
||||||
|
getAppModelFilePath(this),
|
||||||
|
APPModel.class
|
||||||
|
);
|
||||||
|
|
||||||
if (appModel == null) {
|
if (appModel == null) {
|
||||||
setIsDebuging(false);
|
// 配置文件不存在,默认关闭调试模式并创建文件
|
||||||
|
setIsDebugging(false);
|
||||||
saveDebugStatus(this);
|
saveDebugStatus(this);
|
||||||
|
LogUtils.d(TAG, "调试配置文件不存在,默认关闭调试模式并创建配置文件");
|
||||||
} else {
|
} else {
|
||||||
setIsDebuging(appModel.isDebuging());
|
// 配置文件存在,使用保存的调试状态
|
||||||
|
setIsDebugging(appModel.isDebugging());
|
||||||
|
LogUtils.d(TAG, "从配置文件恢复调试模式:" + isDebugging);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getAppName(Context context) {
|
/**
|
||||||
|
* 获取应用名称(从 AndroidManifest.xml 的 android:label 读取)
|
||||||
|
* @param context 上下文(建议传入 Application 上下文,避免内存泄漏)
|
||||||
|
* @return 应用名称(读取失败返回 null)
|
||||||
|
*/
|
||||||
|
public static String getAppName(Context context) {
|
||||||
|
if (context == null) {
|
||||||
|
LogUtils.w(TAG, "getAppName: 上下文为空,返回 null");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
PackageManager packageManager = context.getPackageManager();
|
PackageManager packageManager = context.getPackageManager();
|
||||||
try {
|
try {
|
||||||
|
// 获取应用信息(包含应用名称、图标等)
|
||||||
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(
|
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(
|
||||||
context.getPackageName(), 0);
|
context.getPackageName(), // 当前应用包名
|
||||||
return (String) packageManager.getApplicationLabel(applicationInfo);
|
0 // 额外标志(0 表示默认获取基本信息)
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
);
|
||||||
|
// 从应用信息中获取应用名称(支持多语言)
|
||||||
|
String appName = (String) packageManager.getApplicationLabel(applicationInfo);
|
||||||
|
LogUtils.d(TAG, "获取应用名称成功:" + appName);
|
||||||
|
return appName;
|
||||||
|
} catch (NameNotFoundException e) {
|
||||||
|
// 包名不存在(理论上不会发生,捕获异常避免崩溃)
|
||||||
|
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||||
|
//LogUtils.e(TAG, "获取应用名称失败:包名不存在", e);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用终止时调用(仅用于释放全局资源)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onTerminate() {
|
||||||
|
super.onTerminate();
|
||||||
|
// 释放单例引用(可选,避免内存泄漏风险)
|
||||||
|
sInstance = null;
|
||||||
|
LogUtils.d(TAG, "GlobalApplication 终止,单例实例已释放");
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
package cc.winboll.studio.libappbase;
|
package cc.winboll.studio.libappbase;
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
|
||||||
* @Date 2025/02/11 00:14:05
|
|
||||||
*/
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ClipData;
|
import android.content.ClipData;
|
||||||
import android.content.ClipboardManager;
|
import android.content.ClipboardManager;
|
||||||
@@ -16,79 +12,175 @@ import android.view.MenuItem;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import cc.winboll.studio.libappbase.R;
|
import cc.winboll.studio.libappbase.R;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||||
|
* @Date 2025/11/11 19:58
|
||||||
|
* @Describe 应用异常报告观察活动窗口类
|
||||||
|
* 核心功能:应用发生未捕获崩溃时,由 CrashHandler 启动此页面,展示崩溃日志详情,
|
||||||
|
* 并提供「复制日志」「重启应用」操作入口,便于开发者定位问题和用户恢复应用
|
||||||
|
*/
|
||||||
public final class GlobalCrashActivity extends Activity implements MenuItem.OnMenuItemClickListener {
|
public final class GlobalCrashActivity extends Activity implements MenuItem.OnMenuItemClickListener {
|
||||||
|
|
||||||
private static final int MENUITEM_COPY = 0;
|
/** 日志标签(用于调试日志输出,唯一标识当前 Activity) */
|
||||||
private static final int MENUITEM_RESTART = 1;
|
|
||||||
|
|
||||||
GlobalCrashReportView mGlobalCrashReportView;
|
|
||||||
String mLog;
|
|
||||||
|
|
||||||
|
|
||||||
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_RESTART = 1;
|
||||||
|
|
||||||
|
/** 崩溃报告展示自定义视图 */
|
||||||
|
// 负责渲染崩溃日志文本、提供 Toolbar 容器,封装了日志展示和菜单样式控制逻辑
|
||||||
|
private GlobalCrashReportView mCrashReportView;
|
||||||
|
|
||||||
|
/** 崩溃日志文本内容 */
|
||||||
|
// 从 CrashHandler 通过 Intent 传递过来,包含异常堆栈、设备信息等完整崩溃数据
|
||||||
|
private String mCrashLog;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Activity 创建时初始化(生命周期核心方法,仅执行一次)
|
||||||
|
* @param savedInstanceState 保存的实例状态(崩溃页面无需恢复状态,此处仅作兼容)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
CrashHandler.AppCrashSafetyWire.getInstance().postResumeCrashSafetyWireHandler(getApplicationContext());
|
|
||||||
|
|
||||||
mLog = getIntent().getStringExtra(CrashHandler.EXTRA_CRASH_INFO);
|
// 初始化崩溃安全防护机制
|
||||||
//setTheme(android.R.style.Theme_Holo_Light_NoActionBar);
|
// 作用:防止应用重启后短时间内再次崩溃,由 CrashHandler 内部实现防护逻辑
|
||||||
//setTheme(R.style.APPBaseTheme);
|
CrashHandler.AppCrashSafetyWire.getInstance()
|
||||||
|
.postResumeCrashSafetyWireHandler(getApplicationContext());
|
||||||
|
|
||||||
|
// 从 Intent 中获取崩溃日志数据(EXTRA_CRASH_INFO 为 CrashHandler 定义的常量键)
|
||||||
|
mCrashLog = getIntent().getStringExtra(CrashHandler.EXTRA_CRASH_LOG);
|
||||||
|
|
||||||
|
// 设置当前 Activity 的布局文件(展示崩溃报告的 UI 结构)
|
||||||
setContentView(R.layout.activity_globalcrash);
|
setContentView(R.layout.activity_globalcrash);
|
||||||
mGlobalCrashReportView = findViewById(R.id.activityglobalcrashGlobalCrashReportView1);
|
|
||||||
mGlobalCrashReportView.setReport(mLog);
|
// 初始化崩溃报告展示视图(通过布局 ID 找到自定义 View 实例)
|
||||||
setActionBar(mGlobalCrashReportView.getToolbar());
|
mCrashReportView = findViewById(R.id.activityglobalcrashGlobalCrashReportView1);
|
||||||
|
// 将崩溃日志设置到视图中,由自定义 View 负责排版和显示
|
||||||
getActionBar().setTitle(CrashHandler.TITTLE);
|
mCrashReportView.setReport(mCrashLog);
|
||||||
getActionBar().setSubtitle(GlobalApplication.getAppName(getApplicationContext()));
|
|
||||||
|
// 设置页面的 ActionBar(复用自定义 View 中的 Toolbar 作为系统 ActionBar)
|
||||||
|
setActionBar(mCrashReportView.getToolbar());
|
||||||
|
|
||||||
|
// 配置 ActionBar 标题和副标题(非空判断避免空指针异常)
|
||||||
|
if (getActionBar() != null) {
|
||||||
|
// 设置标题:使用 CrashHandler 中定义的统一标题(如 "应用崩溃报告")
|
||||||
|
getActionBar().setTitle(CrashHandler.TITTLE);
|
||||||
|
// 设置副标题:显示当前应用名称(从全局 Application 工具方法获取)
|
||||||
|
getActionBar().setSubtitle(GlobalApplication.getAppName(getApplicationContext()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重写返回键点击事件
|
||||||
|
* 逻辑:点击手机返回键时,直接重启应用(而非返回上一页,因崩溃后上一页状态可能异常)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
restart();
|
restartApp();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void restart() {
|
/**
|
||||||
PackageManager pm = getPackageManager();
|
* 重启当前应用(核心工具方法)
|
||||||
Intent intent = pm.getLaunchIntentForPackage(getPackageName());
|
* 实现逻辑:
|
||||||
if (intent != null) {
|
* 1. 获取应用的启动意图(默认启动 AndroidManifest 中配置的主 Activity)
|
||||||
intent.addFlags(
|
* 2. 设置意图标志,清除原有任务栈,避免残留异常页面
|
||||||
Intent.FLAG_ACTIVITY_NEW_TASK
|
* 3. 启动主 Activity 并终止当前进程,确保应用完全重启
|
||||||
| Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK
|
*/
|
||||||
);
|
private void restartApp() {
|
||||||
startActivity(intent);
|
// 获取 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();
|
finish();
|
||||||
|
// 终止当前应用进程(确保释放所有资源,避免内存泄漏)
|
||||||
android.os.Process.killProcess(android.os.Process.myPid());
|
android.os.Process.killProcess(android.os.Process.myPid());
|
||||||
|
// 强制退出虚拟机(彻底终止应用,防止残留线程继续运行)
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜单项点击事件回调(实现 MenuItem.OnMenuItemClickListener 接口)
|
||||||
|
* @param item 被点击的菜单项实例
|
||||||
|
* @return boolean:true 表示事件已消费,不再向下传递;false 表示未消费
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
|
// 根据菜单项 ID 判断点击的是哪个功能
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case MENUITEM_COPY:
|
case MENU_ITEM_COPY:
|
||||||
ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
// 点击「复制」菜单,执行复制崩溃日志到剪贴板
|
||||||
cm.setPrimaryClip(ClipData.newPlainText(getPackageName(), mLog));
|
copyCrashLogToClipboard();
|
||||||
Toast.makeText(getApplication(), "The text is copied.", Toast.LENGTH_SHORT).show();
|
|
||||||
break;
|
break;
|
||||||
case MENUITEM_RESTART:
|
case MENU_ITEM_RESTART:
|
||||||
|
// 点击「重启」菜单:先恢复崩溃防护机制到最大等级,再重启应用
|
||||||
CrashHandler.AppCrashSafetyWire.getInstance().resumeToMaximumImmediately();
|
CrashHandler.AppCrashSafetyWire.getInstance().resumeToMaximumImmediately();
|
||||||
restart();
|
restartApp();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建页面顶部菜单(ActionBar 菜单)
|
||||||
|
* @param menu 菜单容器,用于添加菜单项
|
||||||
|
* @return boolean:true 表示显示菜单;false 表示不显示
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
menu.add(0, MENUITEM_COPY, 0, "Copy").setOnMenuItemClickListener(this)
|
// 添加「复制」菜单项:
|
||||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
// 参数说明:菜单组 ID(0 表示默认组)、菜单项 ID(MENU_ITEM_COPY)、排序号(0)、菜单文本("Copy")
|
||||||
menu.add(0, MENUITEM_RESTART, 0, "Restart").setOnMenuItemClickListener(this)
|
// setOnMenuItemClickListener(this):绑定点击事件到当前 Activity
|
||||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
// setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM):有空间时显示在 ActionBar 上,否则放入溢出菜单
|
||||||
|
menu.add(0, MENU_ITEM_COPY, 0, "Copy")
|
||||||
// 更新菜单文字风格
|
.setOnMenuItemClickListener(this)
|
||||||
mGlobalCrashReportView.updateMenuStyle();
|
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||||
|
|
||||||
|
// 添加「重启」菜单项(参数含义同上)
|
||||||
|
menu.add(0, MENU_ITEM_RESTART, 0, "Restart")
|
||||||
|
.setOnMenuItemClickListener(this)
|
||||||
|
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||||
|
|
||||||
|
// 调用自定义视图的方法,更新菜单文字样式(如颜色、字体大小等,由自定义 View 内部实现)
|
||||||
|
mCrashReportView.updateMenuStyle();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将崩溃日志复制到系统剪贴板(工具方法)
|
||||||
|
* 功能:用户点击复制菜单后,将完整崩溃日志存入剪贴板,方便粘贴到聊天工具或文档中
|
||||||
|
*/
|
||||||
|
private void copyCrashLogToClipboard() {
|
||||||
|
// 获取系统剪贴板服务(需通过 getSystemService 方法获取)
|
||||||
|
ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
|
|
||||||
|
// 创建剪贴板数据:
|
||||||
|
// 参数 1:标签(用于标识剪贴板内容来源,此处用应用包名)
|
||||||
|
// 参数 2:实际复制的文本内容(崩溃日志)
|
||||||
|
ClipData clipData = ClipData.newPlainText(getPackageName(), mCrashLog);
|
||||||
|
|
||||||
|
// 将数据设置到剪贴板(完成复制操作)
|
||||||
|
clipboardManager.setPrimaryClip(clipData);
|
||||||
|
|
||||||
|
// 显示复制成功的 Toast 提示(告知用户操作结果)
|
||||||
|
Toast.makeText(getApplication(), "The text is copied.", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
package cc.winboll.studio.libappbase;
|
package cc.winboll.studio.libappbase;
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
|
||||||
* @Date 2025/02/11 20:18:30
|
|
||||||
* @Describe 应用崩溃报告视图
|
|
||||||
*/
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
@@ -18,121 +13,297 @@ import android.widget.TextView;
|
|||||||
import android.widget.Toolbar;
|
import android.widget.Toolbar;
|
||||||
import cc.winboll.studio.libappbase.R;
|
import cc.winboll.studio.libappbase.R;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||||
|
* @Date 2025/11/11 20:21
|
||||||
|
* @Describe 全局崩溃报告视图控件
|
||||||
|
* 用于展示应用崩溃信息,包含顶部工具栏和崩溃日志文本区域,支持自定义配色
|
||||||
|
*/
|
||||||
public class GlobalCrashReportView extends LinearLayout {
|
public class GlobalCrashReportView extends LinearLayout {
|
||||||
|
|
||||||
public static final String TAG = "GlobalCrashReportView";
|
// 日志标签
|
||||||
|
public static final String TAG = "GlobalCrashReportView";
|
||||||
|
|
||||||
Context mContext;
|
// 上下文对象
|
||||||
Toolbar mToolbar;
|
private Context mContext;
|
||||||
int colorTittle;
|
// 顶部工具栏(标题栏)
|
||||||
int colorTittleBackground;
|
private Toolbar mToolbar;
|
||||||
int colorText;
|
// 标题文字颜色
|
||||||
int colorTextBackground;
|
private int mTitleColor;
|
||||||
TextView mtvReport;
|
// 标题栏背景颜色
|
||||||
|
private int mTitleBackgroundColor;
|
||||||
|
// 日志文本颜色
|
||||||
|
private int mTextColor;
|
||||||
|
// 日志区域背景颜色
|
||||||
|
private int mTextBackgroundColor;
|
||||||
|
// 崩溃日志显示文本控件
|
||||||
|
private TextView mTvReport;
|
||||||
|
|
||||||
public GlobalCrashReportView(Context context) {
|
/**
|
||||||
super(context);
|
* 构造方法:仅上下文
|
||||||
mContext = context;
|
* @param context 上下文
|
||||||
//initView();
|
*/
|
||||||
}
|
public GlobalCrashReportView(Context context) {
|
||||||
|
super(context);
|
||||||
|
mContext = context;
|
||||||
|
// 初始化默认配置(无自定义属性)
|
||||||
|
initDefaultConfig();
|
||||||
|
}
|
||||||
|
|
||||||
public GlobalCrashReportView(Context context, AttributeSet attrs) {
|
/**
|
||||||
super(context, attrs);
|
* 构造方法:上下文 + 自定义属性
|
||||||
mContext = context;
|
* @param context 上下文
|
||||||
initView(attrs);
|
* @param attrs 自定义属性集合
|
||||||
}
|
*/
|
||||||
|
public GlobalCrashReportView(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
mContext = context;
|
||||||
|
// 初始化视图(解析自定义属性)
|
||||||
|
initView(attrs);
|
||||||
|
}
|
||||||
|
|
||||||
public GlobalCrashReportView(Context context, AttributeSet attrs, int defStyleAttr) {
|
/**
|
||||||
super(context, attrs, defStyleAttr);
|
* 构造方法:上下文 + 自定义属性 + 样式属性
|
||||||
mContext = context;
|
* @param context 上下文
|
||||||
//initView();
|
* @param attrs 自定义属性集合
|
||||||
}
|
* @param defStyleAttr 样式属性
|
||||||
|
*/
|
||||||
|
public GlobalCrashReportView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
mContext = context;
|
||||||
|
// 初始化视图(解析自定义属性)
|
||||||
|
initView(attrs);
|
||||||
|
}
|
||||||
|
|
||||||
public GlobalCrashReportView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
/**
|
||||||
super(context, attrs, defStyleAttr, defStyleRes);
|
* 构造方法:上下文 + 自定义属性 + 样式属性 + 样式资源
|
||||||
mContext = context;
|
* @param context 上下文
|
||||||
//initView();
|
* @param attrs 自定义属性集合
|
||||||
}
|
* @param defStyleAttr 样式属性
|
||||||
|
* @param defStyleRes 样式资源
|
||||||
|
*/
|
||||||
|
public GlobalCrashReportView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||||
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
|
mContext = context;
|
||||||
|
// 初始化视图(解析自定义属性)
|
||||||
|
initView(attrs);
|
||||||
|
}
|
||||||
|
|
||||||
public void setColorTittle(int colorTittle) {
|
/**
|
||||||
this.colorTittle = colorTittle;
|
* 设置标题文字颜色
|
||||||
}
|
* @param titleColor 颜色值(如 Color.WHITE 或 #FFFFFF)
|
||||||
|
*/
|
||||||
|
public void setTitleColor(int titleColor) {
|
||||||
|
this.mTitleColor = titleColor;
|
||||||
|
// 实时更新工具栏标题颜色
|
||||||
|
if (mToolbar != null) {
|
||||||
|
mToolbar.setTitleTextColor(titleColor);
|
||||||
|
mToolbar.setSubtitleTextColor(titleColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int getColorTittle() {
|
/**
|
||||||
return colorTittle;
|
* 获取标题文字颜色
|
||||||
}
|
* @return 标题文字颜色值
|
||||||
|
*/
|
||||||
|
public int getTitleColor() {
|
||||||
|
return mTitleColor;
|
||||||
|
}
|
||||||
|
|
||||||
public void setColorTittleBackground(int colorTittleBackground) {
|
/**
|
||||||
this.colorTittleBackground = colorTittleBackground;
|
* 设置标题栏背景颜色
|
||||||
}
|
* @param titleBackgroundColor 颜色值(如 Color.BLACK 或 #000000)
|
||||||
|
*/
|
||||||
|
public void setTitleBackgroundColor(int titleBackgroundColor) {
|
||||||
|
this.mTitleBackgroundColor = titleBackgroundColor;
|
||||||
|
// 实时更新工具栏背景颜色
|
||||||
|
if (mToolbar != null) {
|
||||||
|
mToolbar.setBackgroundColor(titleBackgroundColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int getColorTittleBackground() {
|
/**
|
||||||
return colorTittleBackground;
|
* 获取标题栏背景颜色
|
||||||
}
|
* @return 标题栏背景颜色值
|
||||||
|
*/
|
||||||
|
public int getTitleBackgroundColor() {
|
||||||
|
return mTitleBackgroundColor;
|
||||||
|
}
|
||||||
|
|
||||||
public void setColorText(int colorText) {
|
/**
|
||||||
this.colorText = colorText;
|
* 设置日志文本颜色
|
||||||
}
|
* @param textColor 颜色值(如 Color.BLACK 或 #000000)
|
||||||
|
*/
|
||||||
|
public void setTextColor(int textColor) {
|
||||||
|
this.mTextColor = textColor;
|
||||||
|
// 实时更新日志文本颜色
|
||||||
|
if (mTvReport != null) {
|
||||||
|
mTvReport.setTextColor(textColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int getColorText() {
|
/**
|
||||||
return colorText;
|
* 获取日志文本颜色
|
||||||
}
|
* @return 日志文本颜色值
|
||||||
|
*/
|
||||||
|
public int getTextColor() {
|
||||||
|
return mTextColor;
|
||||||
|
}
|
||||||
|
|
||||||
public void setColorTextBackground(int colorTextBackground) {
|
/**
|
||||||
this.colorTextBackground = colorTextBackground;
|
* 设置日志区域背景颜色
|
||||||
}
|
* @param textBackgroundColor 颜色值(如 Color.WHITE 或 #FFFFFF)
|
||||||
|
*/
|
||||||
|
public void setTextBackgroundColor(int textBackgroundColor) {
|
||||||
|
this.mTextBackgroundColor = textBackgroundColor;
|
||||||
|
// 实时更新日志区域和主布局背景颜色
|
||||||
|
if (mTvReport != null) {
|
||||||
|
mTvReport.setBackgroundColor(textBackgroundColor);
|
||||||
|
}
|
||||||
|
setBackgroundColor(textBackgroundColor);
|
||||||
|
}
|
||||||
|
|
||||||
public int getColorTextBackground() {
|
/**
|
||||||
return colorTextBackground;
|
* 获取日志区域背景颜色
|
||||||
}
|
* @return 日志区域背景颜色值
|
||||||
|
*/
|
||||||
|
public int getTextBackgroundColor() {
|
||||||
|
return mTextBackgroundColor;
|
||||||
|
}
|
||||||
|
|
||||||
void initView(AttributeSet attrs) {
|
/**
|
||||||
TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.GlobalCrashActivity, R.attr.themeGlobalCrashActivity, 0);
|
* 初始化默认配置(无自定义属性时使用)
|
||||||
this.colorTittle = a.getColor(R.styleable.GlobalCrashActivity_colorTittle, Color.WHITE);
|
*/
|
||||||
this.colorTittleBackground = a.getColor(R.styleable.GlobalCrashActivity_colorTittleBackgound, Color.BLACK);
|
private void initDefaultConfig() {
|
||||||
this.colorText = a.getColor(R.styleable.GlobalCrashActivity_colorText, Color.BLACK);
|
// 设置默认配色
|
||||||
this.colorTextBackground = a.getColor(R.styleable.GlobalCrashActivity_colorTextBackgound, Color.WHITE);
|
mTitleColor = Color.WHITE;
|
||||||
// 返回一个绑定资源结束的信号给资源
|
mTitleBackgroundColor = Color.BLACK;
|
||||||
a.recycle();
|
mTextColor = Color.BLACK;
|
||||||
|
mTextBackgroundColor = Color.WHITE;
|
||||||
|
// 加载布局
|
||||||
|
inflateView();
|
||||||
|
// 初始化控件样式
|
||||||
|
initWidgetStyle();
|
||||||
|
}
|
||||||
|
|
||||||
/*this.colorTittle = Color.WHITE;
|
/**
|
||||||
this.colorTittleBackground = Color.BLACK;
|
* 初始化视图(解析自定义属性 + 加载布局 + 设置样式)
|
||||||
this.colorText = Color.BLACK;
|
* @param attrs 自定义属性集合
|
||||||
this.colorTextBackground = Color.WHITE;
|
*/
|
||||||
*/
|
private void initView(AttributeSet attrs) {
|
||||||
|
// 解析自定义属性(关联 attrs.xml 中的 GlobalCrashActivity 样式)
|
||||||
inflate(mContext, R.layout.view_globalcrashreport, this);
|
TypedArray typedArray = mContext.obtainStyledAttributes(
|
||||||
|
attrs,
|
||||||
|
R.styleable.GlobalCrashActivity,
|
||||||
|
R.attr.themeGlobalCrashActivity,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
LinearLayout llMain = findViewById(R.id.viewglobalcrashreportLinearLayout1);
|
// 读取自定义属性值(无设置时使用默认值)
|
||||||
llMain.setBackgroundColor(this.colorTextBackground);
|
mTitleColor = typedArray.getColor(
|
||||||
mToolbar = findViewById(R.id.viewglobalcrashreportToolbar1);
|
R.styleable.GlobalCrashActivity_colorTittle,
|
||||||
mToolbar.setBackgroundColor(this.colorTittleBackground);
|
Color.WHITE
|
||||||
mToolbar.setTitleTextColor(this.colorTittle);
|
);
|
||||||
mToolbar.setSubtitleTextColor(this.colorTittle);
|
mTitleBackgroundColor = typedArray.getColor(
|
||||||
mtvReport = findViewById(R.id.viewglobalcrashreportTextView1);
|
R.styleable.GlobalCrashActivity_colorTittleBackgound, // 注:原拼写错误(Backgound→Background),保持与 attrs.xml 一致
|
||||||
mtvReport.setTextColor(this.colorText);
|
Color.BLACK
|
||||||
mtvReport.setBackgroundColor(this.colorTextBackground);
|
);
|
||||||
}
|
mTextColor = typedArray.getColor(
|
||||||
|
R.styleable.GlobalCrashActivity_colorText,
|
||||||
|
Color.BLACK
|
||||||
|
);
|
||||||
|
mTextBackgroundColor = typedArray.getColor(
|
||||||
|
R.styleable.GlobalCrashActivity_colorTextBackgound, // 注:原拼写错误,保持与 attrs.xml 一致
|
||||||
|
Color.WHITE
|
||||||
|
);
|
||||||
|
|
||||||
public void setReport(String report) {
|
// 回收 TypedArray,避免内存泄漏
|
||||||
mtvReport.setText(report);
|
typedArray.recycle();
|
||||||
}
|
|
||||||
|
|
||||||
public Toolbar getToolbar() {
|
// 加载布局文件
|
||||||
return mToolbar;
|
inflateView();
|
||||||
}
|
// 初始化控件样式
|
||||||
|
initWidgetStyle();
|
||||||
|
}
|
||||||
|
|
||||||
//
|
/**
|
||||||
// 更新菜单文字风格
|
* 加载布局文件
|
||||||
//
|
*/
|
||||||
public void updateMenuStyle() {
|
private void inflateView() {
|
||||||
// 设置菜单文本颜色
|
// 加载自定义布局(R.layout.view_globalcrashreport)
|
||||||
Menu menu = mToolbar.getMenu();
|
inflate(mContext, R.layout.view_globalcrashreport, this);
|
||||||
for (int i = 0; i < menu.size(); i++) {
|
// 绑定控件
|
||||||
MenuItem item = menu.getItem(i);
|
mToolbar = findViewById(R.id.viewglobalcrashreportToolbar1);
|
||||||
SpannableString spanString = new SpannableString(item.getTitle().toString());
|
mTvReport = findViewById(R.id.viewglobalcrashreportTextView1);
|
||||||
spanString.setSpan(new ForegroundColorSpan(this.colorTittle), 0, spanString.length(), 0);
|
}
|
||||||
item.setTitle(spanString);
|
|
||||||
}
|
/**
|
||||||
}
|
* 初始化控件样式(设置配色和基础属性)
|
||||||
|
*/
|
||||||
|
private void initWidgetStyle() {
|
||||||
|
// 设置主布局背景颜色
|
||||||
|
setBackgroundColor(mTextBackgroundColor);
|
||||||
|
|
||||||
|
// 配置工具栏样式
|
||||||
|
if (mToolbar != null) {
|
||||||
|
mToolbar.setBackgroundColor(mTitleBackgroundColor);
|
||||||
|
mToolbar.setTitleTextColor(mTitleColor);
|
||||||
|
mToolbar.setSubtitleTextColor(mTitleColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 配置日志文本控件样式
|
||||||
|
if (mTvReport != null) {
|
||||||
|
mTvReport.setTextColor(mTextColor);
|
||||||
|
mTvReport.setBackgroundColor(mTextBackgroundColor);
|
||||||
|
// 可选:设置日志文本换行方式(默认已换行,此处增强可读性)
|
||||||
|
mTvReport.setSingleLine(false);
|
||||||
|
mTvReport.setHorizontallyScrolling(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置崩溃报告内容到文本控件
|
||||||
|
* @param report 崩溃日志字符串(通常包含异常信息、调用栈等)
|
||||||
|
*/
|
||||||
|
public void setReport(String report) {
|
||||||
|
if (mTvReport != null) {
|
||||||
|
mTvReport.setText(report);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取顶部工具栏对象(用于外部设置标题、添加菜单等)
|
||||||
|
* @return Toolbar 实例
|
||||||
|
*/
|
||||||
|
public Toolbar getToolbar() {
|
||||||
|
return mToolbar;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新工具栏菜单文字颜色(与标题颜色保持一致)
|
||||||
|
* 需在菜单加载完成后调用(如 Toolbar 加载菜单后)
|
||||||
|
*/
|
||||||
|
public void updateMenuStyle() {
|
||||||
|
if (mToolbar == null) return;
|
||||||
|
|
||||||
|
// 获取工具栏菜单
|
||||||
|
Menu menu = mToolbar.getMenu();
|
||||||
|
if (menu == null || menu.size() == 0) return;
|
||||||
|
|
||||||
|
// 遍历所有菜单项,设置文字颜色
|
||||||
|
for (int i = 0; i < menu.size(); i++) {
|
||||||
|
MenuItem menuItem = menu.getItem(i);
|
||||||
|
String title = menuItem.getTitle().toString();
|
||||||
|
// 使用 SpannableString 设置文字颜色
|
||||||
|
SpannableString spanString = new SpannableString(title);
|
||||||
|
spanString.setSpan(
|
||||||
|
new ForegroundColorSpan(mTitleColor),
|
||||||
|
0,
|
||||||
|
spanString.length(),
|
||||||
|
0 // Spannable.SPAN_INCLUSIVE_EXCLUSIVE(默认值,包含起始位置,不包含结束位置)
|
||||||
|
);
|
||||||
|
menuItem.setTitle(spanString);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
package cc.winboll.studio.libappbase;
|
package cc.winboll.studio.libappbase;
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
|
||||||
* @Date 2025/03/25 20:34:47
|
|
||||||
* @Describe 应用日志窗口
|
|
||||||
*/
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -12,35 +7,59 @@ import android.os.Bundle;
|
|||||||
import cc.winboll.studio.libappbase.LogView;
|
import cc.winboll.studio.libappbase.LogView;
|
||||||
import cc.winboll.studio.libappbase.R;
|
import cc.winboll.studio.libappbase.R;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||||
|
* @Date 2025/11/11 20:29
|
||||||
|
* @Describe 应用日志展示 Activity
|
||||||
|
* 用于单独启动窗口展示应用运行日志,依赖 LogView 控件实现日志加载与显示
|
||||||
|
*/
|
||||||
public class LogActivity extends Activity {
|
public class LogActivity extends Activity {
|
||||||
|
|
||||||
|
/** 日志标签,用于当前 Activity 的日志输出标识 */
|
||||||
public static final String TAG = "LogActivity";
|
public static final String TAG = "LogActivity";
|
||||||
|
|
||||||
LogView mLogView;
|
/** 日志展示控件(用于加载和显示应用日志) */
|
||||||
|
private LogView mLogView;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
// 设置布局文件(包含 LogView 控件)
|
||||||
setContentView(R.layout.activity_log);
|
setContentView(R.layout.activity_log);
|
||||||
//ToastUtils.show("LogActivity onCreate");
|
|
||||||
|
|
||||||
|
// 绑定布局中的 LogView 控件
|
||||||
mLogView = findViewById(R.id.logview);
|
mLogView = findViewById(R.id.logview);
|
||||||
|
// 启动 LogView 日志加载(如实时刷新日志内容)
|
||||||
mLogView.start();
|
mLogView.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
// 恢复 Activity 时重新启动 LogView(确保日志持续更新)
|
||||||
mLogView.start();
|
mLogView.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void startLogActivity(Context context) {
|
/**
|
||||||
Intent intent = new Intent(context, LogActivity.class);
|
* 启动日志 Activity 的静态方法(外部调用入口)
|
||||||
// 打开多任务窗口
|
* 配置 Intent 标志,以多任务/分屏模式启动,避免与主应用任务栈冲突
|
||||||
|
* @param context 上下文(Activity/Fragment),用于启动 Activity
|
||||||
|
*/
|
||||||
|
public static void startLogActivity(Context context) {
|
||||||
|
// 创建启动当前 Activity 的 Intent
|
||||||
|
Intent intent = new Intent(context, LogActivity.class);
|
||||||
|
|
||||||
|
// 添加 Intent 标志:支持分屏/多窗口模式(API 24+)
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);
|
intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);
|
||||||
|
// 添加 Intent 标志:创建新任务栈(避免并入调用者任务栈)
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
// 添加 Intent 标志:标记为新文档(多任务窗口中独立显示)
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
|
||||||
|
// 添加 Intent 标志:允许创建多个任务实例(支持多次启动独立窗口)
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
|
intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
|
||||||
|
|
||||||
|
// 启动 Activity
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
package cc.winboll.studio.libappbase;
|
package cc.winboll.studio.libappbase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
* @Author ZhanGSKen@QQ.COM
|
||||||
* @Date 2024/08/12 13:44:06
|
* @Date 2024/08/12 13:44:06
|
||||||
* @Describe LogUtils
|
* @Describe LogUtils
|
||||||
* @Describe 应用日志类
|
* @Describe 应用日志类(补全所有日志重载方法,适配不同调试场景)
|
||||||
*/
|
*/
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.widget.Toast;
|
||||||
import cc.winboll.studio.libappbase.GlobalApplication;
|
import cc.winboll.studio.libappbase.GlobalApplication;
|
||||||
import dalvik.system.DexFile;
|
import dalvik.system.DexFile;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
@@ -60,8 +61,8 @@ public class LogUtils {
|
|||||||
// 初始化函数
|
// 初始化函数
|
||||||
//
|
//
|
||||||
public static void init(Context context, LOG_LEVEL logLevel) {
|
public static void init(Context context, LOG_LEVEL logLevel) {
|
||||||
if (GlobalApplication.isDebuging()) {
|
if (GlobalApplication.isDebugging()) {
|
||||||
// 初始化日志缓存文件路径
|
// 初始化日志缓存文件路径(debug模式:外部存储)
|
||||||
_mfLogCacheDir = new File(context.getApplicationContext().getExternalCacheDir(), TAG);
|
_mfLogCacheDir = new File(context.getApplicationContext().getExternalCacheDir(), TAG);
|
||||||
if (!_mfLogCacheDir.exists()) {
|
if (!_mfLogCacheDir.exists()) {
|
||||||
_mfLogCacheDir.mkdirs();
|
_mfLogCacheDir.mkdirs();
|
||||||
@@ -75,7 +76,7 @@ public class LogUtils {
|
|||||||
}
|
}
|
||||||
_mfLogUtilsBeanFile = new File(_mfLogDataDir, TAG + ".json");
|
_mfLogUtilsBeanFile = new File(_mfLogDataDir, TAG + ".json");
|
||||||
} else {
|
} else {
|
||||||
// 初始化日志缓存文件路径
|
// 初始化日志缓存文件路径(release模式:内部存储)
|
||||||
_mfLogCacheDir = new File(context.getApplicationContext().getCacheDir(), TAG);
|
_mfLogCacheDir = new File(context.getApplicationContext().getCacheDir(), TAG);
|
||||||
if (!_mfLogCacheDir.exists()) {
|
if (!_mfLogCacheDir.exists()) {
|
||||||
_mfLogCacheDir.mkdirs();
|
_mfLogCacheDir.mkdirs();
|
||||||
@@ -90,11 +91,6 @@ public class LogUtils {
|
|||||||
_mfLogUtilsBeanFile = new File(_mfLogDataDir, TAG + ".json");
|
_mfLogUtilsBeanFile = new File(_mfLogDataDir, TAG + ".json");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Toast.makeText(context,
|
|
||||||
// "_mfLogUtilsBeanFile : " + _mfLogUtilsBeanFile
|
|
||||||
// + "\n_mfLogCatchFile : " + _mfLogCatchFile,
|
|
||||||
// Toast.LENGTH_SHORT).show();
|
|
||||||
//
|
|
||||||
_mLogUtilsBean = LogUtilsBean.loadBeanFromFile(_mfLogUtilsBeanFile.getPath(), LogUtilsBean.class);
|
_mLogUtilsBean = LogUtilsBean.loadBeanFromFile(_mfLogUtilsBeanFile.getPath(), LogUtilsBean.class);
|
||||||
if (_mLogUtilsBean == null) {
|
if (_mLogUtilsBean == null) {
|
||||||
_mLogUtilsBean = new LogUtilsBean();
|
_mLogUtilsBean = new LogUtilsBean();
|
||||||
@@ -122,7 +118,6 @@ public class LogUtils {
|
|||||||
entry.setValue(beanSetting.getEnable());
|
entry.setValue(beanSetting.getEnable());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,19 +130,14 @@ public class LogUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void addClassTAGList() {
|
static void addClassTAGList() {
|
||||||
//ClassLoader classLoader = getClass().getClassLoader();
|
|
||||||
try {
|
try {
|
||||||
//String packageName = context.getPackageName();
|
// 包名前缀(过滤当前应用的类)
|
||||||
String packageNamePrefix = "cc.winboll.studio";
|
String packageNamePrefix = "cc.winboll.studio";
|
||||||
List<String> classNames = new ArrayList<>();
|
List<String> classNames = new ArrayList<>();
|
||||||
String apkPath = _mContext.getPackageCodePath();
|
String apkPath = _mContext.getPackageCodePath();
|
||||||
//Log.d("APK_PATH", "The APK path is: " + apkPath);
|
|
||||||
LogUtils.d(TAG, String.format("apkPath : %s", apkPath));
|
LogUtils.d(TAG, String.format("apkPath : %s", apkPath));
|
||||||
//String apkPath = "/data/app/" + packageName + "-";
|
|
||||||
|
|
||||||
//DexFile dexfile = new DexFile(apkPath + "1/base.apk");
|
|
||||||
DexFile dexfile = new DexFile(apkPath);
|
DexFile dexfile = new DexFile(apkPath);
|
||||||
|
|
||||||
int countTemp = 0;
|
int countTemp = 0;
|
||||||
Enumeration<String> entries = dexfile.entries();
|
Enumeration<String> entries = dexfile.entries();
|
||||||
while (entries.hasMoreElements()) {
|
while (entries.hasMoreElements()) {
|
||||||
@@ -165,23 +155,21 @@ public class LogUtils {
|
|||||||
Class<?> clazz = Class.forName(className);
|
Class<?> clazz = Class.forName(className);
|
||||||
Field[] fields = clazz.getDeclaredFields();
|
Field[] fields = clazz.getDeclaredFields();
|
||||||
for (Field field : fields) {
|
for (Field field : fields) {
|
||||||
if (Modifier.isStatic(field.getModifiers()) && Modifier.isPublic(field.getModifiers()) && field.getType() == String.class && "TAG".equals(field.getName())) {
|
// 过滤静态、公共、String类型的 TAG 字段
|
||||||
|
if (Modifier.isStatic(field.getModifiers())
|
||||||
|
&& Modifier.isPublic(field.getModifiers())
|
||||||
|
&& field.getType() == String.class
|
||||||
|
&& "TAG".equals(field.getName())) {
|
||||||
String tagValue = (String) field.get(null);
|
String tagValue = (String) field.get(null);
|
||||||
//Log.d("TAG_INFO", "Class: " + className + ", TAG value: " + tagValue);
|
mapTAGList.put(tagValue, false); // 默认禁用,可通过设置开启
|
||||||
//LogUtils.d(TAG, String.format("Tag Value : %s", tagValue));
|
|
||||||
//mapTAGList.put(tagValue, true);
|
|
||||||
mapTAGList.put(tagValue, false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (NoClassDefFoundError | ClassNotFoundException | IllegalAccessException e) {
|
} catch (NoClassDefFoundError | ClassNotFoundException | IllegalAccessException e) {
|
||||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||||
//LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
|
||||||
//Toast.makeText(context, TAG + " : " + e.getMessage(), Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||||
//Toast.makeText(context, TAG + " : " + e.getMessage(), Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,7 +179,6 @@ public class LogUtils {
|
|||||||
Map.Entry<String, Boolean> entry = iterator.next();
|
Map.Entry<String, Boolean> entry = iterator.next();
|
||||||
if (tag.equals(entry.getKey())) {
|
if (tag.equals(entry.getKey())) {
|
||||||
entry.setValue(isEnable);
|
entry.setValue(isEnable);
|
||||||
//System.out.println("Key: " + entry.getKey() + ", Value: " + entry.getValue());
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -204,7 +191,6 @@ public class LogUtils {
|
|||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
Map.Entry<String, Boolean> entry = iterator.next();
|
Map.Entry<String, Boolean> entry = iterator.next();
|
||||||
entry.setValue(isEnable);
|
entry.setValue(isEnable);
|
||||||
//System.out.println("Key: " + entry.getKey() + ", Value: " + entry.getValue());
|
|
||||||
}
|
}
|
||||||
saveTAGBeanSettings();
|
saveTAGBeanSettings();
|
||||||
LogUtils.d(TAG, String.format("mapTAGList : %s", mapTAGList.toString()));
|
LogUtils.d(TAG, String.format("mapTAGList : %s", mapTAGList.toString()));
|
||||||
@@ -223,10 +209,11 @@ public class LogUtils {
|
|||||||
if (!_IsInited) {
|
if (!_IsInited) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (mapTAGList.get(tag) == null
|
// TAG 未配置或禁用时,不打印日志
|
||||||
|| !mapTAGList.get(tag)) {
|
if (mapTAGList.get(tag) == null || !mapTAGList.get(tag)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// 日志级别不符合时,不打印日志
|
||||||
if (!isInTheLevel(logLevel)) {
|
if (!isInTheLevel(logLevel)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -234,8 +221,8 @@ public class LogUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static boolean isInTheLevel(LOG_LEVEL logLevel) {
|
static boolean isInTheLevel(LOG_LEVEL logLevel) {
|
||||||
return (LogUtils._mLogUtilsBean.getLogLevel().ordinal() == logLevel.ordinal()
|
// 当前日志级别 >= 目标级别时,允许打印(级别顺序:Off < Error < Warn < Info < Debug < Verbose)
|
||||||
|| LogUtils._mLogUtilsBean.getLogLevel().ordinal() > logLevel.ordinal());
|
return LogUtils._mLogUtilsBean.getLogLevel().ordinal() >= logLevel.ordinal();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -245,136 +232,501 @@ public class LogUtils {
|
|||||||
return _mfLogCacheDir;
|
return _mfLogCacheDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
// ================================= 补全所有日志重载方法(Error 级别) =================================
|
||||||
// 调试日志写入函数
|
/**
|
||||||
//
|
* Error 级别日志(仅消息)
|
||||||
|
* @param szTAG 标签
|
||||||
|
* @param szMessage 日志消息
|
||||||
|
*/
|
||||||
public static void e(String szTAG, String szMessage) {
|
public static void e(String szTAG, String szMessage) {
|
||||||
if (isLoggable(szTAG, LogUtils.LOG_LEVEL.Error)) {
|
if (isLoggable(szTAG, LogUtils.LOG_LEVEL.Error)) {
|
||||||
saveLog(szTAG, LogUtils.LOG_LEVEL.Error, szMessage);
|
saveLog(szTAG, LogUtils.LOG_LEVEL.Error, szMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
/**
|
||||||
// 调试日志写入函数
|
* Error 级别日志(消息 + 异常)
|
||||||
//
|
* @param szTAG 标签
|
||||||
|
* @param szMessage 日志消息
|
||||||
|
* @param e 异常对象
|
||||||
|
*/
|
||||||
|
public static void e(String szTAG, String szMessage, Exception e) {
|
||||||
|
if (isLoggable(szTAG, LogUtils.LOG_LEVEL.Error)) {
|
||||||
|
StringBuilder sb = new StringBuilder(szMessage);
|
||||||
|
sb.append("\n【异常信息】: ").append(getExceptionInfo(e));
|
||||||
|
saveLog(szTAG, LogUtils.LOG_LEVEL.Error, sb.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error 级别日志(仅异常)
|
||||||
|
* @param szTAG 标签
|
||||||
|
* @param e 异常对象
|
||||||
|
*/
|
||||||
|
public static void e(String szTAG, Exception e) {
|
||||||
|
if (isLoggable(szTAG, LogUtils.LOG_LEVEL.Error)) {
|
||||||
|
String message = "【异常信息】: " + getExceptionInfo(e);
|
||||||
|
saveLog(szTAG, LogUtils.LOG_LEVEL.Error, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error 级别日志(消息 + 异常 + 堆栈)
|
||||||
|
* @param szTAG 标签
|
||||||
|
* @param szMessage 日志消息
|
||||||
|
* @param e 异常对象
|
||||||
|
* @param listStackTrace 堆栈信息
|
||||||
|
*/
|
||||||
|
public static void e(String szTAG, String szMessage, Exception e, StackTraceElement[] listStackTrace) {
|
||||||
|
if (isLoggable(szTAG, LogUtils.LOG_LEVEL.Error)) {
|
||||||
|
StringBuilder sb = new StringBuilder(szMessage);
|
||||||
|
sb.append("\n【异常信息】: ").append(getExceptionInfo(e));
|
||||||
|
sb.append("\n【堆栈信息】: ").append(getStackTraceInfo(listStackTrace));
|
||||||
|
saveLog(szTAG, LogUtils.LOG_LEVEL.Error, sb.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================================= 补全所有日志重载方法(Warn 级别) =================================
|
||||||
|
/**
|
||||||
|
* Warn 级别日志(仅消息)
|
||||||
|
* @param szTAG 标签
|
||||||
|
* @param szMessage 日志消息
|
||||||
|
*/
|
||||||
public static void w(String szTAG, String szMessage) {
|
public static void w(String szTAG, String szMessage) {
|
||||||
if (isLoggable(szTAG, LogUtils.LOG_LEVEL.Warn)) {
|
if (isLoggable(szTAG, LogUtils.LOG_LEVEL.Warn)) {
|
||||||
saveLog(szTAG, LogUtils.LOG_LEVEL.Warn, szMessage);
|
saveLog(szTAG, LogUtils.LOG_LEVEL.Warn, szMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
/**
|
||||||
// 调试日志写入函数
|
* Warn 级别日志(消息 + 异常)
|
||||||
//
|
* @param szTAG 标签
|
||||||
|
* @param szMessage 日志消息
|
||||||
|
* @param e 异常对象
|
||||||
|
*/
|
||||||
|
public static void w(String szTAG, String szMessage, Exception e) {
|
||||||
|
if (isLoggable(szTAG, LogUtils.LOG_LEVEL.Warn)) {
|
||||||
|
StringBuilder sb = new StringBuilder(szMessage);
|
||||||
|
sb.append("\n【异常信息】: ").append(getExceptionInfo(e));
|
||||||
|
saveLog(szTAG, LogUtils.LOG_LEVEL.Warn, sb.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Warn 级别日志(仅异常)
|
||||||
|
* @param szTAG 标签
|
||||||
|
* @param e 异常对象
|
||||||
|
*/
|
||||||
|
public static void w(String szTAG, Exception e) {
|
||||||
|
if (isLoggable(szTAG, LogUtils.LOG_LEVEL.Warn)) {
|
||||||
|
String message = "【异常信息】: " + getExceptionInfo(e);
|
||||||
|
saveLog(szTAG, LogUtils.LOG_LEVEL.Warn, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================================= 补全所有日志重载方法(Info 级别) =================================
|
||||||
|
/**
|
||||||
|
* Info 级别日志(仅消息)
|
||||||
|
* @param szTAG 标签
|
||||||
|
* @param szMessage 日志消息
|
||||||
|
*/
|
||||||
public static void i(String szTAG, String szMessage) {
|
public static void i(String szTAG, String szMessage) {
|
||||||
if (isLoggable(szTAG, LogUtils.LOG_LEVEL.Info)) {
|
if (isLoggable(szTAG, LogUtils.LOG_LEVEL.Info)) {
|
||||||
saveLog(szTAG, LogUtils.LOG_LEVEL.Info, szMessage);
|
saveLog(szTAG, LogUtils.LOG_LEVEL.Info, szMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
/**
|
||||||
// 调试日志写入函数
|
* Info 级别日志(消息 + 数据对象)
|
||||||
//
|
* @param szTAG 标签
|
||||||
|
* @param szMessage 日志消息
|
||||||
|
* @param obj 数据对象(自动转为字符串)
|
||||||
|
*/
|
||||||
|
public static void i(String szTAG, String szMessage, Object obj) {
|
||||||
|
if (isLoggable(szTAG, LogUtils.LOG_LEVEL.Info)) {
|
||||||
|
String objStr = obj == null ? "null" : obj.toString();
|
||||||
|
StringBuilder sb = new StringBuilder(szMessage);
|
||||||
|
sb.append("\n【数据对象】: ").append(objStr);
|
||||||
|
saveLog(szTAG, LogUtils.LOG_LEVEL.Info, sb.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================================= 补全所有日志重载方法(Debug 级别) =================================
|
||||||
|
/**
|
||||||
|
* Debug 级别日志(仅消息)
|
||||||
|
* @param szTAG 标签
|
||||||
|
* @param szMessage 日志消息
|
||||||
|
*/
|
||||||
public static void d(String szTAG, String szMessage) {
|
public static void d(String szTAG, String szMessage) {
|
||||||
if (isLoggable(szTAG, LogUtils.LOG_LEVEL.Debug)) {
|
if (isLoggable(szTAG, LogUtils.LOG_LEVEL.Debug)) {
|
||||||
saveLog(szTAG, LogUtils.LOG_LEVEL.Debug, szMessage);
|
saveLog(szTAG, LogUtils.LOG_LEVEL.Debug, szMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
/**
|
||||||
// 调试日志写入函数
|
* Debug 级别日志(消息 + 堆栈)
|
||||||
// 包含线程调试堆栈信息
|
* @param szTAG 标签
|
||||||
//
|
* @param szMessage 日志消息
|
||||||
|
* @param listStackTrace 堆栈信息
|
||||||
|
*/
|
||||||
public static void d(String szTAG, String szMessage, StackTraceElement[] listStackTrace) {
|
public static void d(String szTAG, String szMessage, StackTraceElement[] listStackTrace) {
|
||||||
if (isLoggable(szTAG, LogUtils.LOG_LEVEL.Debug)) {
|
if (isLoggable(szTAG, LogUtils.LOG_LEVEL.Debug)) {
|
||||||
StringBuilder sbMessage = new StringBuilder(szMessage);
|
StringBuilder sbMessage = new StringBuilder(szMessage);
|
||||||
sbMessage.append(" \nAt ");
|
sbMessage.append("\n【调用堆栈】: ").append(getStackTraceInfo(listStackTrace));
|
||||||
sbMessage.append(listStackTrace[2].getMethodName());
|
|
||||||
sbMessage.append(" (");
|
|
||||||
sbMessage.append(listStackTrace[2].getFileName());
|
|
||||||
sbMessage.append(":");
|
|
||||||
sbMessage.append(listStackTrace[2].getLineNumber());
|
|
||||||
sbMessage.append(")");
|
|
||||||
saveLog(szTAG, LogUtils.LOG_LEVEL.Debug, sbMessage.toString());
|
saveLog(szTAG, LogUtils.LOG_LEVEL.Debug, sbMessage.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
/**
|
||||||
// 调试日志写入函数
|
* Debug 级别日志(消息 + 异常)
|
||||||
// 包含异常信息和线程调试堆栈信息
|
* @param szTAG 标签
|
||||||
//
|
* @param szMessage 日志消息
|
||||||
|
* @param e 异常对象
|
||||||
|
*/
|
||||||
|
public static void d(String szTAG, String szMessage, Exception e) {
|
||||||
|
if (isLoggable(szTAG, LogUtils.LOG_LEVEL.Debug)) {
|
||||||
|
StringBuilder sb = new StringBuilder(szMessage);
|
||||||
|
sb.append("\n【异常信息】: ").append(getExceptionInfo(e));
|
||||||
|
saveLog(szTAG, LogUtils.LOG_LEVEL.Debug, sb.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Debug 级别日志(异常 + 堆栈)
|
||||||
|
* @param szTAG 标签
|
||||||
|
* @param e 异常对象
|
||||||
|
* @param listStackTrace 堆栈信息
|
||||||
|
*/
|
||||||
public static void d(String szTAG, Exception e, StackTraceElement[] listStackTrace) {
|
public static void d(String szTAG, Exception e, StackTraceElement[] listStackTrace) {
|
||||||
if (isLoggable(szTAG, LogUtils.LOG_LEVEL.Debug)) {
|
if (isLoggable(szTAG, LogUtils.LOG_LEVEL.Debug)) {
|
||||||
StringBuilder sbMessage = new StringBuilder(e.getClass().toGenericString());
|
StringBuilder sbMessage = new StringBuilder();
|
||||||
sbMessage.append(" : ");
|
sbMessage.append("【异常信息】: ").append(getExceptionInfo(e));
|
||||||
sbMessage.append(e.getMessage());
|
sbMessage.append("\n【调用堆栈】: ").append(getStackTraceInfo(listStackTrace));
|
||||||
sbMessage.append(" \nAt ");
|
|
||||||
sbMessage.append(listStackTrace[2].getMethodName());
|
|
||||||
sbMessage.append(" (");
|
|
||||||
sbMessage.append(listStackTrace[2].getFileName());
|
|
||||||
sbMessage.append(":");
|
|
||||||
sbMessage.append(listStackTrace[2].getLineNumber());
|
|
||||||
sbMessage.append(")");
|
|
||||||
saveLog(szTAG, LogUtils.LOG_LEVEL.Debug, sbMessage.toString());
|
saveLog(szTAG, LogUtils.LOG_LEVEL.Debug, sbMessage.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
/**
|
||||||
// 调试日志写入函数
|
* Debug 级别日志(消息 + 数据对象)
|
||||||
//
|
* @param szTAG 标签
|
||||||
|
* @param szMessage 日志消息
|
||||||
|
* @param obj 数据对象(自动转为字符串)
|
||||||
|
*/
|
||||||
|
public static void d(String szTAG, String szMessage, Object obj) {
|
||||||
|
if (isLoggable(szTAG, LogUtils.LOG_LEVEL.Debug)) {
|
||||||
|
String objStr = obj == null ? "null" : obj.toString();
|
||||||
|
StringBuilder sb = new StringBuilder(szMessage);
|
||||||
|
sb.append("\n【数据对象】: ").append(objStr);
|
||||||
|
saveLog(szTAG, LogUtils.LOG_LEVEL.Debug, sb.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Debug 级别日志(仅数据对象)
|
||||||
|
* @param szTAG 标签
|
||||||
|
* @param obj 数据对象(自动转为字符串)
|
||||||
|
*/
|
||||||
|
public static void d(String szTAG, Object obj) {
|
||||||
|
if (isLoggable(szTAG, LogUtils.LOG_LEVEL.Debug)) {
|
||||||
|
String objStr = obj == null ? "null" : obj.toString();
|
||||||
|
String message = "【数据对象】: " + objStr;
|
||||||
|
saveLog(szTAG, LogUtils.LOG_LEVEL.Debug, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================================= 补全所有日志重载方法(Verbose 级别) =================================
|
||||||
|
/**
|
||||||
|
* Verbose 级别日志(仅消息)
|
||||||
|
* @param szTAG 标签
|
||||||
|
* @param szMessage 日志消息
|
||||||
|
*/
|
||||||
public static void v(String szTAG, String szMessage) {
|
public static void v(String szTAG, String szMessage) {
|
||||||
if (isLoggable(szTAG, LogUtils.LOG_LEVEL.Verbose)) {
|
if (isLoggable(szTAG, LogUtils.LOG_LEVEL.Verbose)) {
|
||||||
saveLog(szTAG, LogUtils.LOG_LEVEL.Verbose, szMessage);
|
saveLog(szTAG, LogUtils.LOG_LEVEL.Verbose, szMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
/**
|
||||||
// 日志文件保存函数
|
* Verbose 级别日志(消息 + 数据对象)
|
||||||
//
|
* @param szTAG 标签
|
||||||
|
* @param szMessage 日志消息
|
||||||
|
* @param obj 数据对象(自动转为字符串)
|
||||||
|
*/
|
||||||
|
public static void v(String szTAG, String szMessage, Object obj) {
|
||||||
|
if (isLoggable(szTAG, LogUtils.LOG_LEVEL.Verbose)) {
|
||||||
|
String objStr = obj == null ? "null" : obj.toString();
|
||||||
|
StringBuilder sb = new StringBuilder(szMessage);
|
||||||
|
sb.append("\n【数据对象】: ").append(objStr);
|
||||||
|
saveLog(szTAG, LogUtils.LOG_LEVEL.Verbose, sb.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verbose 级别日志(仅数据对象)
|
||||||
|
* @param szTAG 标签
|
||||||
|
* @param obj 数据对象(自动转为字符串)
|
||||||
|
*/
|
||||||
|
public static void v(String szTAG, Object obj) {
|
||||||
|
if (isLoggable(szTAG, LogUtils.LOG_LEVEL.Verbose)) {
|
||||||
|
String objStr = obj == null ? "null" : obj.toString();
|
||||||
|
String message = "【数据对象】: " + objStr;
|
||||||
|
saveLog(szTAG, LogUtils.LOG_LEVEL.Verbose, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================================= 新增:通用日志工具方法(补充调试能力) =================================
|
||||||
|
/**
|
||||||
|
* 打印当前线程信息(Debug 级别)
|
||||||
|
* @param szTAG 标签
|
||||||
|
* @param szMessage 日志消息
|
||||||
|
*/
|
||||||
|
public static void printThreadInfo(String szTAG, String szMessage) {
|
||||||
|
if (isLoggable(szTAG, LogUtils.LOG_LEVEL.Debug)) {
|
||||||
|
Thread currentThread = Thread.currentThread();
|
||||||
|
StringBuilder sb = new StringBuilder(szMessage);
|
||||||
|
sb.append("\n【线程信息】: ")
|
||||||
|
.append("线程名=").append(currentThread.getName())
|
||||||
|
.append(", 线程ID=").append(currentThread.getId())
|
||||||
|
.append(", 线程状态=").append(currentThread.getState().name());
|
||||||
|
saveLog(szTAG, LogUtils.LOG_LEVEL.Debug, sb.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打印 Map 数据(Debug 级别,格式化输出,便于查看)
|
||||||
|
* @param szTAG 标签
|
||||||
|
* @param szMessage 日志消息
|
||||||
|
* @param map 要打印的 Map 数据
|
||||||
|
*/
|
||||||
|
public static <K, V> void printMap(String szTAG, String szMessage, Map<K, V> map) {
|
||||||
|
if (isLoggable(szTAG, LogUtils.LOG_LEVEL.Debug) && map != null) {
|
||||||
|
StringBuilder sb = new StringBuilder(szMessage);
|
||||||
|
sb.append("\n【Map 数据】(size=").append(map.size()).append("):");
|
||||||
|
for (Map.Entry<K, V> entry : map.entrySet()) {
|
||||||
|
String keyStr = entry.getKey() == null ? "null" : entry.getKey().toString();
|
||||||
|
String valueStr = entry.getValue() == null ? "null" : entry.getValue().toString();
|
||||||
|
sb.append("\n ").append(keyStr).append(" = ").append(valueStr);
|
||||||
|
}
|
||||||
|
saveLog(szTAG, LogUtils.LOG_LEVEL.Debug, sb.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打印 List 数据(Debug 级别,格式化输出)
|
||||||
|
* @param szTAG 标签
|
||||||
|
* @param szMessage 日志消息
|
||||||
|
* @param list 要打印的 List 数据
|
||||||
|
*/
|
||||||
|
public static <T> void printList(String szTAG, String szMessage, List<T> list) {
|
||||||
|
if (isLoggable(szTAG, LogUtils.LOG_LEVEL.Debug) && list != null) {
|
||||||
|
StringBuilder sb = new StringBuilder(szMessage);
|
||||||
|
sb.append("\n【List 数据】(size=").append(list.size()).append("):");
|
||||||
|
for (int i = 0; i < list.size(); i++) {
|
||||||
|
T item = list.get(i);
|
||||||
|
String itemStr = item == null ? "null" : item.toString();
|
||||||
|
sb.append("\n 索引").append(i).append(" = ").append(itemStr);
|
||||||
|
}
|
||||||
|
saveLog(szTAG, LogUtils.LOG_LEVEL.Debug, sb.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================================= 私有工具方法(异常/堆栈信息格式化) =================================
|
||||||
|
/**
|
||||||
|
* 格式化异常信息(提取异常类型、消息、简化堆栈)
|
||||||
|
* @param e 异常对象
|
||||||
|
* @return 格式化后的异常字符串
|
||||||
|
*/
|
||||||
|
private static String getExceptionInfo(Exception e) {
|
||||||
|
if (e == null) {
|
||||||
|
return "异常对象为null";
|
||||||
|
}
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
// 异常类型 + 异常消息
|
||||||
|
sb.append(e.getClass().getSimpleName()).append(" : ").append(e.getMessage() == null ? "无异常消息" : e.getMessage());
|
||||||
|
// 简化堆栈(取前5行,避免日志过长)
|
||||||
|
StackTraceElement[] stackTrace = e.getStackTrace();
|
||||||
|
if (stackTrace != null && stackTrace.length > 0) {
|
||||||
|
sb.append("\n 简化堆栈(前5行):");
|
||||||
|
int limit = Math.min(stackTrace.length, 5);
|
||||||
|
for (int i = 0; i < limit; i++) {
|
||||||
|
sb.append("\n ").append(stackTrace[i].toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化堆栈信息(提取关键调用链路)
|
||||||
|
* @param stackTrace 堆栈数组
|
||||||
|
* @return 格式化后的堆栈字符串
|
||||||
|
*/
|
||||||
|
private static String getStackTraceInfo(StackTraceElement[] stackTrace) {
|
||||||
|
if (stackTrace == null || stackTrace.length == 0) {
|
||||||
|
return "堆栈信息为空";
|
||||||
|
}
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
// 过滤 LogUtils 内部调用,取真实业务调用链路(前8行)
|
||||||
|
int count = 0;
|
||||||
|
for (StackTraceElement element : stackTrace) {
|
||||||
|
// 跳过 LogUtils 自身的堆栈(避免冗余)
|
||||||
|
if (element.getClassName().contains("cc.winboll.studio.libappbase.LogUtils")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
sb.append("\n ").append(element.getClassName()).append(".")
|
||||||
|
.append(element.getMethodName()).append("(")
|
||||||
|
.append(element.getFileName()).append(":").append(element.getLineNumber()).append(")");
|
||||||
|
count++;
|
||||||
|
if (count >= 8) { // 限制堆栈长度,避免日志过大
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================================= 原有核心方法(保留并优化) =================================
|
||||||
|
/**
|
||||||
|
* 日志文件保存函数(优化:增加异常捕获完整性,避免流泄漏)
|
||||||
|
* @param szTAG 标签
|
||||||
|
* @param logLevel 日志级别
|
||||||
|
* @param szMessage 日志消息
|
||||||
|
*/
|
||||||
static void saveLog(String szTAG, LogUtils.LOG_LEVEL logLevel, String szMessage) {
|
static void saveLog(String szTAG, LogUtils.LOG_LEVEL logLevel, String szMessage) {
|
||||||
|
BufferedWriter out = null;
|
||||||
try {
|
try {
|
||||||
BufferedWriter out = null;
|
// 确保日志文件存在(创建父目录 + 文件)
|
||||||
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(_mfLogCatchFile, true), "UTF-8"));
|
if (!_mfLogCatchFile.exists()) {
|
||||||
out.write("[" + logLevel + "] " + mSimpleDateFormat.format(System.currentTimeMillis()) + " [" + szTAG + "]\n" + szMessage + "\n");
|
File parentDir = _mfLogCatchFile.getParentFile();
|
||||||
out.close();
|
if (parentDir != null && !parentDir.exists()) {
|
||||||
} catch (IOException e) {
|
parentDir.mkdirs();
|
||||||
LogUtils.d(TAG, "IOException : " + e.getMessage());
|
}
|
||||||
}
|
_mfLogCatchFile.createNewFile();
|
||||||
}
|
}
|
||||||
|
// 追加写入日志(UTF-8编码,避免中文乱码)
|
||||||
//
|
out = new BufferedWriter(new OutputStreamWriter(
|
||||||
// 历史日志加载函数
|
new FileOutputStream(_mfLogCatchFile, true), "UTF-8"));
|
||||||
//
|
String logLine = "[" + logLevel + "] "
|
||||||
public static String loadLog() {
|
+ mSimpleDateFormat.format(System.currentTimeMillis())
|
||||||
if (_mfLogCatchFile.exists()) {
|
+ " [" + szTAG + "]\n"
|
||||||
StringBuffer sb = new StringBuffer();
|
+ szMessage + "\n\n"; // 增加空行,区分不同日志
|
||||||
try {
|
out.write(logLine);
|
||||||
BufferedReader in = null;
|
out.flush(); // 强制刷新,确保日志及时写入
|
||||||
in = new BufferedReader(new InputStreamReader(new FileInputStream(_mfLogCatchFile), "UTF-8"));
|
} catch (IOException e) {
|
||||||
String line = "";
|
// 日志写入失败时,打印系统日志(避免递归调用)
|
||||||
while ((line = in.readLine()) != null) {
|
android.util.Log.e(TAG, "日志写入失败: " + e.getMessage());
|
||||||
sb.append(line);
|
} finally {
|
||||||
sb.append("\n");
|
// 关闭流,避免资源泄漏(Java 7 手动关闭,无 try-with-resources)
|
||||||
|
if (out != null) {
|
||||||
|
try {
|
||||||
|
out.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
android.util.Log.e(TAG, "流关闭失败: " + e.getMessage());
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
|
||||||
LogUtils.d(TAG, "IOException : " + e.getMessage());
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// 清理日志函数
|
|
||||||
//
|
|
||||||
public static void cleanLog() {
|
|
||||||
if (_mfLogCatchFile.exists()) {
|
|
||||||
try {
|
|
||||||
UTF8FileUtils.writeStringToFile(_mfLogCatchFile.getPath(), "");
|
|
||||||
//LogUtils.d(TAG, "cleanLog");
|
|
||||||
} catch (IOException e) {
|
|
||||||
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 历史日志加载函数(优化:增加流关闭,避免内存泄漏)
|
||||||
|
* @return 日志内容字符串(空串表示无日志)
|
||||||
|
*/
|
||||||
|
public static String loadLog() {
|
||||||
|
if (_mfLogCatchFile == null || !_mfLogCatchFile.exists()) {
|
||||||
|
return "日志文件不存在";
|
||||||
|
}
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
BufferedReader in = null;
|
||||||
|
try {
|
||||||
|
in = new BufferedReader(new InputStreamReader(
|
||||||
|
new FileInputStream(_mfLogCatchFile), "UTF-8"));
|
||||||
|
String line = "";
|
||||||
|
while ((line = in.readLine()) != null) {
|
||||||
|
sb.append(line);
|
||||||
|
sb.append("\n");
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
sb.append("日志加载失败: ").append(e.getMessage());
|
||||||
|
LogUtils.e(TAG, "日志加载异常", e);
|
||||||
|
} finally {
|
||||||
|
// 关闭流,避免资源泄漏
|
||||||
|
if (in != null) {
|
||||||
|
try {
|
||||||
|
in.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
LogUtils.e(TAG, "流关闭异常", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清理日志函数(优化:支持清空日志,避免文件过大)
|
||||||
|
*/
|
||||||
|
public static void cleanLog() {
|
||||||
|
if (_mfLogCatchFile == null) {
|
||||||
|
LogUtils.d(TAG, "日志文件未初始化,无需清理");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// 清空文件内容(覆盖写入空字符串)
|
||||||
|
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
|
||||||
|
new FileOutputStream(_mfLogCatchFile, false), "UTF-8"));
|
||||||
|
out.write("");
|
||||||
|
out.flush();
|
||||||
|
out.close();
|
||||||
|
LogUtils.d(TAG, "日志已清空,文件路径: " + _mfLogCatchFile.getPath());
|
||||||
|
} catch (IOException e) {
|
||||||
|
LogUtils.e(TAG, "日志清空失败", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查日志文件大小(新增:避免日志文件过大占用内存)
|
||||||
|
* @param maxSizeMB 最大允许大小(MB)
|
||||||
|
* @return true:文件超过限制;false:文件大小正常
|
||||||
|
*/
|
||||||
|
public static boolean checkLogFileSize(int maxSizeMB) {
|
||||||
|
if (_mfLogCatchFile == null || !_mfLogCatchFile.exists()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 转换为字节(1MB = 1024*1024 字节)
|
||||||
|
long maxSizeByte = maxSizeMB * 1024 * 1024;
|
||||||
|
long fileSize = _mfLogCatchFile.length();
|
||||||
|
LogUtils.d(TAG, String.format("日志文件大小: %.2f MB(限制: %d MB)",
|
||||||
|
fileSize / (1024.0 * 1024), maxSizeMB));
|
||||||
|
return fileSize > maxSizeByte;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化检查(新增:快速判断 LogUtils 是否初始化完成)
|
||||||
|
* @return true:已初始化;false:未初始化
|
||||||
|
*/
|
||||||
|
public static boolean isInited() {
|
||||||
|
return _IsInited;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示短提示(新增:日志+Toast联动,调试时快速提示)
|
||||||
|
* @param context 上下文
|
||||||
|
* @param message 提示内容
|
||||||
|
*/
|
||||||
|
public static void showShortToast(final Context context, final String message) {
|
||||||
|
if (context == null || message == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 主线程显示Toast,避免子线程崩溃
|
||||||
|
if (Thread.currentThread().getId() == android.os.Process.myTid()) {
|
||||||
|
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
|
||||||
|
} else {
|
||||||
|
((android.app.Activity) context).runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// 同时写入日志
|
||||||
|
LogUtils.d(TAG, "Toast提示: " + message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,70 +1,131 @@
|
|||||||
package cc.winboll.studio.libappbase;
|
package cc.winboll.studio.libappbase;
|
||||||
|
|
||||||
|
import android.util.JsonReader;
|
||||||
|
import android.util.JsonWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||||
* @Date 2024/08/23 15:39:07
|
* @Date 2024/08/23 15:39:07
|
||||||
* @Describe LogUtils 数据配置类。
|
* @Describe LogUtils 配置数据模型(继承 BaseBean,实现 JSON 序列化/反序列化)
|
||||||
|
* 封装 LogUtils 的核心配置参数(当前仅日志级别),用于配置的持久化存储与读取
|
||||||
*/
|
*/
|
||||||
import android.util.JsonReader;
|
|
||||||
import android.util.JsonWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
public class LogUtilsBean extends BaseBean {
|
public class LogUtilsBean extends BaseBean {
|
||||||
|
|
||||||
|
/** 当前类的日志 TAG(用于调试输出) */
|
||||||
public static final String TAG = "LogUtilsBean";
|
public static final String TAG = "LogUtilsBean";
|
||||||
|
|
||||||
LogUtils.LOG_LEVEL logLevel;
|
/**
|
||||||
|
* 全局日志级别(默认值:Off,即不输出任何日志)
|
||||||
|
* 关联 LogUtils.LOG_LEVEL 枚举,存储日志输出的级别阈值
|
||||||
|
*/
|
||||||
|
private LogUtils.LOG_LEVEL logLevel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 无参构造方法(默认初始化日志级别为 Off)
|
||||||
|
* 用于 JSON 反序列化时的实例创建
|
||||||
|
*/
|
||||||
public LogUtilsBean() {
|
public LogUtilsBean() {
|
||||||
this.logLevel = LogUtils.LOG_LEVEL.Off;
|
this.logLevel = LogUtils.LOG_LEVEL.Off;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 有参构造方法(指定初始日志级别)
|
||||||
|
* @param logLevel 初始日志级别(如 LogUtils.LOG_LEVEL.Debug)
|
||||||
|
*/
|
||||||
public LogUtilsBean(LogUtils.LOG_LEVEL logLevel) {
|
public LogUtilsBean(LogUtils.LOG_LEVEL logLevel) {
|
||||||
this.logLevel = logLevel;
|
this.logLevel = logLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置日志级别(更新配置时使用)
|
||||||
|
* @param logLevel 目标日志级别
|
||||||
|
*/
|
||||||
public void setLogLevel(LogUtils.LOG_LEVEL logLevel) {
|
public void setLogLevel(LogUtils.LOG_LEVEL logLevel) {
|
||||||
this.logLevel = logLevel;
|
this.logLevel = logLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前日志级别(读取配置时使用)
|
||||||
|
* @return 当前配置的日志级别
|
||||||
|
*/
|
||||||
public LogUtils.LOG_LEVEL getLogLevel() {
|
public LogUtils.LOG_LEVEL getLogLevel() {
|
||||||
return logLevel;
|
return logLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重写父类方法:获取当前类的全限定名(用于 BaseBean 反射识别)
|
||||||
|
* @return 类全限定名(如 "cc.winboll.studio.libappbase.LogUtilsBean")
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return LogUtilsBean.class.getName();
|
return LogUtilsBean.class.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重写父类方法:将当前配置对象序列化为 JSON(持久化存储时调用)
|
||||||
|
* 序列化字段:logLevel(存储枚举的 ordinal 值,确保反序列化一致性)
|
||||||
|
* @param jsonWriter JSON 写入器(用于输出 JSON 数据)
|
||||||
|
* @throws IOException JSON 写入异常(如流关闭、格式错误)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
|
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
|
||||||
|
// 调用父类序列化逻辑(若 BaseBean 有公共字段,需优先处理)
|
||||||
super.writeThisToJsonWriter(jsonWriter);
|
super.writeThisToJsonWriter(jsonWriter);
|
||||||
LogUtilsBean bean = this;
|
// 序列化日志级别:存储枚举的索引值(如 Off=0、Error=1...),比存储名称更高效
|
||||||
jsonWriter.name("logLevel").value(bean.getLogLevel().ordinal());
|
jsonWriter.name("logLevel").value(this.getLogLevel().ordinal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重写父类方法:从 JSON 字段初始化当前对象(读取配置时调用)
|
||||||
|
* 解析字段:logLevel(通过索引值恢复 LogUtils.LOG_LEVEL 枚举)
|
||||||
|
* @param jsonReader JSON 读取器(用于读取 JSON 数据)
|
||||||
|
* @param name JSON 字段名(当前解析的字段)
|
||||||
|
* @return true:字段解析成功;false:字段不匹配(需父类处理或跳过)
|
||||||
|
* @throws IOException JSON 读取异常(如字段类型不匹配、流中断)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean initObjectsFromJsonReader(JsonReader jsonReader, String name) throws IOException {
|
public boolean initObjectsFromJsonReader(JsonReader jsonReader, String name) throws IOException {
|
||||||
if (super.initObjectsFromJsonReader(jsonReader, name)) { return true; } else {
|
// 先让父类处理公共字段,处理成功则直接返回
|
||||||
if (name.equals("logLevel")) {
|
if (super.initObjectsFromJsonReader(jsonReader, name)) {
|
||||||
setLogLevel(LogUtils.LOG_LEVEL.values()[jsonReader.nextInt()]);
|
return true;
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// 解析当前类专属字段
|
||||||
|
if ("logLevel".equals(name)) {
|
||||||
|
// 通过枚举索引值恢复枚举实例(确保与序列化时的 ordinal 对应)
|
||||||
|
int levelOrdinal = jsonReader.nextInt();
|
||||||
|
this.setLogLevel(LogUtils.LOG_LEVEL.values()[levelOrdinal]);
|
||||||
|
} else {
|
||||||
|
// 字段不匹配,返回 false 表示需要跳过该字段
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 字段解析成功
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重写父类方法:从 JSON 读取器完整解析配置对象(入口方法)
|
||||||
|
* 负责 JSON 对象的开始/结束解析,遍历所有字段并调用 initObjectsFromJsonReader 处理
|
||||||
|
* @param jsonReader JSON 读取器(传入待解析的 JSON 流)
|
||||||
|
* @return 解析后的当前 LogUtilsBean 实例(支持链式调用)
|
||||||
|
* @throws IOException JSON 解析异常(如格式错误、字段缺失)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public BaseBean readBeanFromJsonReader(JsonReader jsonReader) throws IOException {
|
public BaseBean readBeanFromJsonReader(JsonReader jsonReader) throws IOException {
|
||||||
|
// 开始解析 JSON 对象(必须与 writeThisToJsonWriter 中的结构对应)
|
||||||
jsonReader.beginObject();
|
jsonReader.beginObject();
|
||||||
|
// 遍历 JSON 中的所有字段
|
||||||
while (jsonReader.hasNext()) {
|
while (jsonReader.hasNext()) {
|
||||||
String name = jsonReader.nextName();
|
String fieldName = jsonReader.nextName();
|
||||||
if (!initObjectsFromJsonReader(jsonReader, name)) {
|
// 解析字段,若字段不匹配则跳过该值(避免解析失败)
|
||||||
|
if (!this.initObjectsFromJsonReader(jsonReader, fieldName)) {
|
||||||
jsonReader.skipValue();
|
jsonReader.skipValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 结束 JSON 对象
|
// 结束 JSON 对象解析(必须调用,否则会导致流异常)
|
||||||
jsonReader.endObject();
|
jsonReader.endObject();
|
||||||
|
// 返回当前实例,支持链式调用(如 new LogUtilsBean().readBeanFromJsonReader(reader))
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,87 +1,161 @@
|
|||||||
package cc.winboll.studio.libappbase;
|
package cc.winboll.studio.libappbase;
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
|
||||||
* @Date 2025/01/04 14:17:02
|
|
||||||
* @Describe 日志类class TAG 标签数据类
|
|
||||||
*/
|
|
||||||
import android.util.JsonReader;
|
import android.util.JsonReader;
|
||||||
import android.util.JsonWriter;
|
import android.util.JsonWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||||
|
* @Date 2025/01/04 14:17:02
|
||||||
|
* @Describe 日志 TAG 过滤配置模型(继承 BaseBean,实现 JSON 序列化/反序列化)
|
||||||
|
* 封装单个日志 TAG 的名称及其启用状态,用于 LogUtils 的 TAG 过滤规则持久化存储与读取
|
||||||
|
*/
|
||||||
public class LogUtilsClassTAGBean extends BaseBean {
|
public class LogUtilsClassTAGBean extends BaseBean {
|
||||||
|
|
||||||
|
/** 当前类的日志 TAG(用于调试输出) */
|
||||||
public static final String TAG = "LogUtilsClassTAGBean";
|
public static final String TAG = "LogUtilsClassTAGBean";
|
||||||
|
|
||||||
// 标签名
|
/**
|
||||||
String tag;
|
* 日志 TAG 名称(如 "LogViewThread"、"ToastUtils")
|
||||||
// 是否启用
|
* 与 LogUtils 中扫描的应用内 TAG 一一对应
|
||||||
Boolean enable;
|
*/
|
||||||
|
private String tag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TAG 启用状态(控制该 TAG 的日志是否输出)
|
||||||
|
* true:启用(输出该 TAG 的日志);false:禁用(不输出该 TAG 的日志)
|
||||||
|
*/
|
||||||
|
private Boolean enable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 无参构造方法(默认初始化:TAG 为当前类 TAG,启用状态为 true)
|
||||||
|
* 用于 JSON 反序列化时的实例创建,或默认配置生成
|
||||||
|
*/
|
||||||
public LogUtilsClassTAGBean() {
|
public LogUtilsClassTAGBean() {
|
||||||
this.tag = TAG;
|
this.tag = TAG; // 默认 TAG 为当前类的 TAG
|
||||||
this.enable = true;
|
this.enable = true; // 默认启用该 TAG 的日志输出
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 有参构造方法(指定 TAG 名称和启用状态)
|
||||||
|
* 用于主动创建 TAG 过滤配置实例
|
||||||
|
* @param tag 日志 TAG 名称
|
||||||
|
* @param enable TAG 启用状态(true/false)
|
||||||
|
*/
|
||||||
public LogUtilsClassTAGBean(String tag, Boolean enable) {
|
public LogUtilsClassTAGBean(String tag, Boolean enable) {
|
||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
this.enable = enable;
|
this.enable = enable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置日志 TAG 名称
|
||||||
|
* @param tag 目标 TAG 名称
|
||||||
|
*/
|
||||||
public void setTag(String tag) {
|
public void setTag(String tag) {
|
||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取日志 TAG 名称
|
||||||
|
* @return 当前配置的 TAG 名称
|
||||||
|
*/
|
||||||
public String getTag() {
|
public String getTag() {
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置 TAG 启用状态
|
||||||
|
* @param enable 目标启用状态(true:启用;false:禁用)
|
||||||
|
*/
|
||||||
public void setEnable(Boolean enable) {
|
public void setEnable(Boolean enable) {
|
||||||
this.enable = enable;
|
this.enable = enable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 TAG 启用状态
|
||||||
|
* @return 当前 TAG 的启用状态
|
||||||
|
*/
|
||||||
public Boolean getEnable() {
|
public Boolean getEnable() {
|
||||||
return enable;
|
return enable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重写父类方法:获取当前类的全限定名(用于 BaseBean 反射识别)
|
||||||
|
* @return 类全限定名(如 "cc.winboll.studio.libappbase.LogUtilsClassTAGBean")
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return LogUtilsClassTAGBean.class.getName();
|
return LogUtilsClassTAGBean.class.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重写父类方法:将当前 TAG 配置对象序列化为 JSON(持久化存储时调用)
|
||||||
|
* 序列化字段:tag(TAG 名称)、enable(启用状态)
|
||||||
|
* @param jsonWriter JSON 写入器(用于输出 JSON 数据)
|
||||||
|
* @throws IOException JSON 写入异常(如流关闭、格式错误)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
|
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
|
||||||
|
// 调用父类序列化逻辑(若 BaseBean 有公共字段,需优先处理)
|
||||||
super.writeThisToJsonWriter(jsonWriter);
|
super.writeThisToJsonWriter(jsonWriter);
|
||||||
LogUtilsClassTAGBean bean = this;
|
// 序列化 TAG 名称
|
||||||
jsonWriter.name("tag").value(bean.getTag());
|
jsonWriter.name("tag").value(this.getTag());
|
||||||
jsonWriter.name("enable").value(bean.getEnable());
|
// 序列化启用状态
|
||||||
|
jsonWriter.name("enable").value(this.getEnable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重写父类方法:从 JSON 字段初始化当前对象(读取配置时调用)
|
||||||
|
* 解析字段:tag(TAG 名称)、enable(启用状态)
|
||||||
|
* @param jsonReader JSON 读取器(用于读取 JSON 数据)
|
||||||
|
* @param name JSON 字段名(当前解析的字段)
|
||||||
|
* @return true:字段解析成功;false:字段不匹配(需父类处理或跳过)
|
||||||
|
* @throws IOException JSON 读取异常(如字段类型不匹配、流中断)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean initObjectsFromJsonReader(JsonReader jsonReader, String name) throws IOException {
|
public boolean initObjectsFromJsonReader(JsonReader jsonReader, String name) throws IOException {
|
||||||
if (super.initObjectsFromJsonReader(jsonReader, name)) { return true; } else {
|
// 先让父类处理公共字段,处理成功则直接返回
|
||||||
if (name.equals("tag")) {
|
if (super.initObjectsFromJsonReader(jsonReader, name)) {
|
||||||
setTag(jsonReader.nextString());
|
return true;
|
||||||
} else if (name.equals("enable")) {
|
|
||||||
setEnable(jsonReader.nextBoolean());
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// 解析当前类专属字段
|
||||||
|
if ("tag".equals(name)) {
|
||||||
|
// 读取 TAG 名称并设置
|
||||||
|
this.setTag(jsonReader.nextString());
|
||||||
|
} else if ("enable".equals(name)) {
|
||||||
|
// 读取启用状态并设置
|
||||||
|
this.setEnable(jsonReader.nextBoolean());
|
||||||
|
} else {
|
||||||
|
// 字段不匹配,返回 false 表示需要跳过该字段
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 字段解析成功
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重写父类方法:从 JSON 读取器完整解析配置对象(入口方法)
|
||||||
|
* 负责 JSON 对象的开始/结束解析,遍历所有字段并调用 initObjectsFromJsonReader 处理
|
||||||
|
* @param jsonReader JSON 读取器(传入待解析的 JSON 流)
|
||||||
|
* @return 解析后的当前 LogUtilsClassTAGBean 实例(支持链式调用)
|
||||||
|
* @throws IOException JSON 解析异常(如格式错误、字段缺失)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public BaseBean readBeanFromJsonReader(JsonReader jsonReader) throws IOException {
|
public BaseBean readBeanFromJsonReader(JsonReader jsonReader) throws IOException {
|
||||||
|
// 开始解析 JSON 对象(必须与 writeThisToJsonWriter 中的结构对应)
|
||||||
jsonReader.beginObject();
|
jsonReader.beginObject();
|
||||||
|
// 遍历 JSON 中的所有字段
|
||||||
while (jsonReader.hasNext()) {
|
while (jsonReader.hasNext()) {
|
||||||
String name = jsonReader.nextName();
|
String fieldName = jsonReader.nextName();
|
||||||
if (!initObjectsFromJsonReader(jsonReader, name)) {
|
// 解析字段,若字段不匹配则跳过该值(避免解析失败)
|
||||||
|
if (!this.initObjectsFromJsonReader(jsonReader, fieldName)) {
|
||||||
jsonReader.skipValue();
|
jsonReader.skipValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 结束 JSON 对象
|
// 结束 JSON 对象解析(必须调用,否则会导致流异常)
|
||||||
jsonReader.endObject();
|
jsonReader.endObject();
|
||||||
|
// 返回当前实例,支持链式调用(如 new LogUtilsClassTAGBean().readBeanFromJsonReader(reader))
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package cc.winboll.studio.libappbase;
|
package cc.winboll.studio.libappbase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
* @Author ZhanGSKen@QQ.COM
|
||||||
* @Date 2024/08/12 14:36:18
|
* @Date 2024/08/12 14:36:18
|
||||||
* @Describe 日志视图类,继承 RelativeLayout 类。
|
* @Describe 日志视图类,继承 RelativeLayout 类。
|
||||||
*/
|
*/
|
||||||
@@ -28,6 +28,7 @@ import android.widget.Spinner;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import cc.winboll.studio.libappbase.LogUtils;
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
import cc.winboll.studio.libappbase.R;
|
import cc.winboll.studio.libappbase.R;
|
||||||
|
import cc.winboll.studio.libappbase.views.HorizontalListView;
|
||||||
import java.text.Collator;
|
import java.text.Collator;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|||||||
@@ -1,80 +1,140 @@
|
|||||||
package cc.winboll.studio.libappbase;
|
package cc.winboll.studio.libappbase;
|
||||||
|
|
||||||
|
import android.os.FileObserver;
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||||
* @Date 2024/08/12 14:43:50
|
* @Date 2024/08/12 14:43:50
|
||||||
* @Describe 日志视图线程类
|
* @Describe 日志视图线程类
|
||||||
|
* 独立线程监听日志文件目录变化(如写入、删除),触发日志视图更新,避免阻塞主线程
|
||||||
*/
|
*/
|
||||||
import android.os.FileObserver;
|
|
||||||
import cc.winboll.studio.libappbase.LogUtils;
|
|
||||||
import java.lang.ref.WeakReference;
|
|
||||||
|
|
||||||
public class LogViewThread extends Thread {
|
public class LogViewThread extends Thread {
|
||||||
|
|
||||||
|
/** 日志标签(用于调试输出) */
|
||||||
public static final String TAG = "LogViewThread";
|
public static final String TAG = "LogViewThread";
|
||||||
|
|
||||||
// 线程退出标志
|
/** 线程退出标志(volatile 保证多线程可见性,控制循环退出) */
|
||||||
volatile boolean isExist = false;
|
private volatile boolean isExit = false;
|
||||||
// 应用日志文件监听实例
|
/** 日志文件目录监听实例(监听文件写入、删除事件) */
|
||||||
LogListener mLogListener;
|
private LogListener mLogListener;
|
||||||
// 日志视图弱引用
|
/** 日志视图弱引用(避免持有 LogView 强引用导致内存泄漏) */
|
||||||
WeakReference<LogView> mwrLogView;
|
private final WeakReference<LogView> mLogViewWeakRef;
|
||||||
|
|
||||||
//
|
/**
|
||||||
// 构造函数
|
* 构造函数
|
||||||
// @logView : 日志显示输出视图类
|
* @param logView 日志显示视图实例(需通过弱引用持有,避免内存泄漏)
|
||||||
|
*/
|
||||||
public LogViewThread(LogView logView) {
|
public LogViewThread(LogView logView) {
|
||||||
mwrLogView = new WeakReference<LogView>(logView);
|
// 使用弱引用包装 LogView,当视图销毁时可被 GC 回收
|
||||||
|
mLogViewWeakRef = new WeakReference<>(logView);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIsExist(boolean isExist) {
|
/**
|
||||||
this.isExist = isExist;
|
* 设置线程退出标志(触发线程停止监听并退出)
|
||||||
|
* @param exit true:退出线程;false:继续运行(默认)
|
||||||
|
*/
|
||||||
|
public void setExit(boolean exit) {
|
||||||
|
this.isExit = exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isExist() {
|
/**
|
||||||
return isExist;
|
* 获取当前线程退出状态
|
||||||
|
* @return true:已标记退出;false:运行中
|
||||||
|
*/
|
||||||
|
public boolean isExit() {
|
||||||
|
return isExit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 线程核心逻辑:初始化文件监听并启动循环,直到收到退出标志
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
String szLogDir = LogUtils.getLogCacheDir().getPath();
|
// 获取日志缓存目录路径(从 LogUtils 统一获取,确保路径一致性)
|
||||||
mLogListener = new LogListener(szLogDir);
|
String logDirPath = LogUtils.getLogCacheDir().getPath();
|
||||||
|
LogUtils.d(TAG, "启动日志文件监听,监听目录:" + logDirPath);
|
||||||
|
|
||||||
|
// 初始化日志文件监听器(监听目标目录的文件事件)
|
||||||
|
mLogListener = new LogListener(logDirPath);
|
||||||
|
// 开始监听文件事件(非阻塞,内部通过 Native 层实现)
|
||||||
mLogListener.startWatching();
|
mLogListener.startWatching();
|
||||||
while (isExist() == false) {
|
|
||||||
|
// 循环等待退出标志(每 1 秒检查一次,降低 CPU 占用)
|
||||||
|
while (!isExit()) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000); // 休眠 1 秒,避免忙等
|
||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {
|
||||||
|
// 线程被中断时,恢复中断标志并退出循环(避免无限阻塞)
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
LogUtils.d(TAG, "日志监听线程被中断,准备退出。" + e);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 收到退出标志,停止监听并释放资源
|
||||||
mLogListener.stopWatching();
|
mLogListener.stopWatching();
|
||||||
|
LogUtils.d(TAG, "日志文件监听已停止,线程退出");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志文件监听内部类(继承 FileObserver,监听目录下文件变化)
|
||||||
|
* 仅关注文件写入完成(CLOSE_WRITE)和文件删除(DELETE)事件
|
||||||
|
*/
|
||||||
|
private class LogListener extends FileObserver {
|
||||||
|
|
||||||
//
|
/**
|
||||||
// 日志文件监听类
|
* 构造函数
|
||||||
//
|
* @param path 监听的目录路径(此处为日志缓存目录)
|
||||||
class LogListener extends FileObserver {
|
*/
|
||||||
public LogListener(String path) {
|
public LogListener(String path) {
|
||||||
|
// 父类构造:监听指定目录的所有事件(通过位掩码 ALL_EVENTS 指定)
|
||||||
super(path);
|
super(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件事件回调(运行在系统私有线程,非主线程)
|
||||||
|
* @param event 事件类型(通过位掩码表示,需与 ALL_EVENTS 按位与解析)
|
||||||
|
* @param path 发生事件的文件名(相对监听目录的路径)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onEvent(int event, String path) {
|
public void onEvent(int event, String path) {
|
||||||
int e = event & FileObserver.ALL_EVENTS;
|
// 解析事件类型(排除无关事件,只处理目标事件)
|
||||||
switch (e) {
|
int eventType = event & FileObserver.ALL_EVENTS;
|
||||||
case FileObserver.CLOSE_WRITE:{
|
|
||||||
if (mwrLogView.get() != null) {
|
switch (eventType) {
|
||||||
mwrLogView.get().updateLogView();
|
// 事件:文件写入完成(如日志写入结束并关闭文件)
|
||||||
}
|
case FileObserver.CLOSE_WRITE:
|
||||||
break;
|
// 触发日志视图更新(需先判断 LogView 是否未被回收)
|
||||||
}
|
updateLogView();
|
||||||
case FileObserver.DELETE:{
|
break;
|
||||||
if (mwrLogView.get() != null) {
|
|
||||||
mwrLogView.get().updateLogView();
|
// 事件:文件被删除(如日志清理操作)
|
||||||
}
|
case FileObserver.DELETE:
|
||||||
break;
|
LogUtils.d(TAG, "日志文件被删除,文件名:" + (path != null ? path : "未知"));
|
||||||
}
|
// 触发日志视图更新(刷新视图显示空状态)
|
||||||
|
updateLogView();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// 忽略其他无关事件(如文件创建、访问等)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 触发日志视图更新(通过弱引用获取 LogView,避免内存泄漏)
|
||||||
|
*/
|
||||||
|
private void updateLogView() {
|
||||||
|
// 从弱引用中获取 LogView 实例(若视图已销毁,get() 返回 null)
|
||||||
|
LogView logView = mLogViewWeakRef.get();
|
||||||
|
if (logView != null) {
|
||||||
|
// 调用 LogView 的更新方法(需确保 updateLogView 内部处理主线程切换)
|
||||||
|
logView.updateLogView();
|
||||||
|
} else {
|
||||||
|
LogUtils.w(TAG, "LogView 已被回收,无法更新日志视图");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,34 +1,268 @@
|
|||||||
package cc.winboll.studio.libappbase;
|
package cc.winboll.studio.libappbase;
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
|
||||||
* @Date 2025/03/12 12:02:31
|
|
||||||
*/
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
|
import android.os.Message;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||||
|
* @Date 2025/11/11 20:51
|
||||||
|
* @Describe 吐司工具类(单例模式)
|
||||||
|
* 简化 Android 吐司的创建与展示,通过独立线程 + Handler 处理消息,最终切换到主线程显示吐司,避免内存泄漏
|
||||||
|
*/
|
||||||
public class ToastUtils {
|
public class ToastUtils {
|
||||||
|
|
||||||
|
/** 工具类日志 TAG(用于调试输出) */
|
||||||
public static final String TAG = "ToastUtils";
|
public static final String TAG = "ToastUtils";
|
||||||
|
/** 消息标识:显示短时长吐司 */
|
||||||
|
private static final int MSG_SHOW_SHORT_TOAST = 1001;
|
||||||
|
|
||||||
volatile static ToastUtils _ToastUtils;
|
/** 单例实例(volatile 保证多线程下可见性,避免指令重排) */
|
||||||
Context mContext;
|
private static volatile ToastUtils sInstance;
|
||||||
|
/** 全局上下文(volatile 保证多线程可见性,避免空指针) */
|
||||||
|
private volatile Context mContext;
|
||||||
|
/** 独立线程的 Handler(volatile 保证可见性) */
|
||||||
|
private volatile Handler mWorkerHandler;
|
||||||
|
/** 主线程 Handler(volatile 保证可见性) */
|
||||||
|
private volatile Handler mMainHandler;
|
||||||
|
/** 消息处理独立线程 */
|
||||||
|
private Thread mWorkerThread;
|
||||||
|
/** 资源释放标记(volatile 避免多线程误操作) */
|
||||||
|
private volatile boolean isReleased = false;
|
||||||
|
|
||||||
ToastUtils() {
|
/**
|
||||||
|
* 私有构造方法(禁止外部直接创建实例,确保单例)
|
||||||
|
* 1. 初始化主线程 Handler;
|
||||||
|
* 2. 创建并启动独立消息处理线程。
|
||||||
|
*/
|
||||||
|
private ToastUtils() {
|
||||||
|
initMainHandler(); // 优先初始化主线程 Handler
|
||||||
|
startWorkerThread(); // 启动独立消息处理线程
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized static ToastUtils getInstance() {
|
/**
|
||||||
if (_ToastUtils == null) {
|
* 初始化主线程 Handler
|
||||||
_ToastUtils = new ToastUtils();
|
*/
|
||||||
|
private void initMainHandler() {
|
||||||
|
if (Looper.getMainLooper() == null) {
|
||||||
|
LogUtils.e(TAG, "主线程 Looper 为空,无法初始化 mMainHandler");
|
||||||
|
throw new IllegalStateException("主线程 Looper 未初始化,无法创建 ToastUtils");
|
||||||
}
|
}
|
||||||
return _ToastUtils;
|
mMainHandler = new Handler(Looper.getMainLooper());
|
||||||
|
LogUtils.d(TAG, "主线程 Handler 初始化完成,线程ID:" + Looper.getMainLooper().getThread().getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启动独立消息处理线程
|
||||||
|
*/
|
||||||
|
private void startWorkerThread() {
|
||||||
|
mWorkerThread = new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
LogUtils.d(TAG, "消息处理线程启动,线程ID:" + Thread.currentThread().getId());
|
||||||
|
Looper.prepare();
|
||||||
|
|
||||||
|
mWorkerHandler = new Handler(Looper.myLooper()) {
|
||||||
|
@Override
|
||||||
|
public void handleMessage(Message msg) {
|
||||||
|
super.handleMessage(msg);
|
||||||
|
// 若已释放,直接返回,不处理消息
|
||||||
|
if (isReleased) {
|
||||||
|
LogUtils.w(TAG, "资源已释放,忽略消息处理");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LogUtils.d(TAG, "WorkerHandler 接收消息,当前线程ID:" + Thread.currentThread().getId());
|
||||||
|
if (msg.what == MSG_SHOW_SHORT_TOAST && msg.obj != null) {
|
||||||
|
String message = (String) msg.obj;
|
||||||
|
postToMainThreadShowToast(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Looper.loop();
|
||||||
|
LogUtils.d(TAG, "消息处理线程退出");
|
||||||
|
}
|
||||||
|
}, "ToastWorkerThread");
|
||||||
|
mWorkerThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取单例实例(双重检查锁定)
|
||||||
|
* @return ToastUtils 单例对象
|
||||||
|
*/
|
||||||
|
private static ToastUtils getInstance() {
|
||||||
|
if (sInstance == null) {
|
||||||
|
synchronized (ToastUtils.class) {
|
||||||
|
if (sInstance == null) {
|
||||||
|
sInstance = new ToastUtils();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化工具类(必须在 Application 启动时调用)
|
||||||
|
* @param context 全局上下文(推荐 Application 上下文)
|
||||||
|
*/
|
||||||
public static void init(Context context) {
|
public static void init(Context context) {
|
||||||
getInstance().mContext = context;
|
if (context == null) {
|
||||||
|
throw new IllegalArgumentException("初始化上下文不能为 null!");
|
||||||
|
}
|
||||||
|
ToastUtils instance = getInstance();
|
||||||
|
// 若已释放,重置释放标记
|
||||||
|
if (instance.isReleased) {
|
||||||
|
instance.isReleased = false;
|
||||||
|
instance.startWorkerThread(); // 重新启动线程
|
||||||
|
}
|
||||||
|
instance.mContext = context.getApplicationContext();
|
||||||
|
LogUtils.d(TAG, "ToastUtils 初始化完成,上下文已设置");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ===================================== 新增:isInited() 方法 =====================================
|
||||||
|
/**
|
||||||
|
* 判断 ToastUtils 是否已初始化(供外部调用,如 CrashHandleNotifyUtils 中的复制提示)
|
||||||
|
* @return true:已初始化(可正常显示吐司);false:未初始化/已释放(无法正常显示)
|
||||||
|
*/
|
||||||
|
public static boolean isInited() {
|
||||||
|
ToastUtils instance = getInstance();
|
||||||
|
// 双重校验:1. 未释放 2. 上下文已设置(确保初始化完成)
|
||||||
|
return !instance.isReleased && instance.mContext != null;
|
||||||
|
}
|
||||||
|
// ===================================== 新增结束 =====================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 外部接口:显示短时长吐司
|
||||||
|
* @param message 吐司内容
|
||||||
|
*/
|
||||||
public static void show(String message) {
|
public static void show(String message) {
|
||||||
Toast.makeText(getInstance().mContext, message, Toast.LENGTH_SHORT).show();
|
LogUtils.d(TAG, "外部调用 show(),当前线程ID:" + Thread.currentThread().getId());
|
||||||
|
if (message == null || message.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ToastUtils instance = getInstance();
|
||||||
|
// 校验资源是否已释放
|
||||||
|
if (instance.isReleased) {
|
||||||
|
LogUtils.w(TAG, "ToastUtils 已释放,无法显示吐司:" + message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 校验上下文是否初始化
|
||||||
|
if (instance.mContext == null) {
|
||||||
|
LogUtils.e(TAG, "ToastUtils 未初始化!请先调用 init(Context) 方法");
|
||||||
|
// 不抛出异常,避免崩溃,改为日志提示
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
instance.sendToastMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送吐司消息到 WorkerHandler
|
||||||
|
* @param message 吐司内容
|
||||||
|
*/
|
||||||
|
private void sendToastMessage(String message) {
|
||||||
|
LogUtils.d(TAG, "发送消息到 WorkerHandler");
|
||||||
|
// 校验 WorkerHandler 是否就绪
|
||||||
|
if (mWorkerHandler == null) {
|
||||||
|
LogUtils.w(TAG, "WorkerHandler 未就绪,直接主线程显示");
|
||||||
|
postToMainThreadShowToast(message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 发送消息
|
||||||
|
Message msg = mWorkerHandler.obtainMessage(MSG_SHOW_SHORT_TOAST);
|
||||||
|
msg.obj = message;
|
||||||
|
mWorkerHandler.sendMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 切换到主线程显示吐司
|
||||||
|
* @param message 吐司内容
|
||||||
|
*/
|
||||||
|
private void postToMainThreadShowToast(final String message) {
|
||||||
|
LogUtils.d(TAG, "切换到主线程显示吐司,当前线程ID:" + Thread.currentThread().getId());
|
||||||
|
// 校验资源是否已释放
|
||||||
|
if (isReleased) {
|
||||||
|
LogUtils.w(TAG, "资源已释放,取消显示吐司");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 校验并初始化 mMainHandler
|
||||||
|
if (mMainHandler == null) {
|
||||||
|
LogUtils.e(TAG, "mMainHandler 为空,尝试重新初始化");
|
||||||
|
initMainHandler();
|
||||||
|
if (mMainHandler == null) {
|
||||||
|
LogUtils.e(TAG, "mMainHandler 初始化失败,无法显示吐司:" + message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 主线程显示
|
||||||
|
mMainHandler.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (isReleased) return; // 释放后取消执行
|
||||||
|
showToastInternal(message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实际显示吐司(主线程)
|
||||||
|
* @param message 吐司内容
|
||||||
|
*/
|
||||||
|
private void showToastInternal(String message) {
|
||||||
|
LogUtils.d(TAG, "执行 showToastInternal()");
|
||||||
|
// 最终校验上下文
|
||||||
|
if (mContext == null) {
|
||||||
|
LogUtils.w(TAG, "上下文为空,无法显示吐司:" + message);
|
||||||
|
// 尝试重新获取 Application 上下文(降级策略)
|
||||||
|
Context appContext = GlobalApplication.getInstance();
|
||||||
|
if (appContext != null) {
|
||||||
|
mContext = appContext;
|
||||||
|
Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();
|
||||||
|
LogUtils.d(TAG, "通过 GlobalApplication 获取上下文,成功显示吐司");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 释放资源(仅在应用退出时调用)
|
||||||
|
*/
|
||||||
|
public static void release() {
|
||||||
|
LogUtils.d(TAG, "开始释放 ToastUtils 资源");
|
||||||
|
ToastUtils instance = getInstance();
|
||||||
|
// 标记为已释放,阻止后续消息处理
|
||||||
|
instance.isReleased = true;
|
||||||
|
|
||||||
|
// 停止 Worker 线程
|
||||||
|
if (instance.mWorkerHandler != null && instance.mWorkerHandler.getLooper() != null) {
|
||||||
|
instance.mWorkerHandler.getLooper().quit();
|
||||||
|
instance.mWorkerHandler = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 清理主线程 Handler
|
||||||
|
if (instance.mMainHandler != null) {
|
||||||
|
instance.mMainHandler.removeCallbacksAndMessages(null);
|
||||||
|
instance.mMainHandler = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 等待线程退出
|
||||||
|
if (instance.mWorkerThread != null && instance.mWorkerThread.isAlive()) {
|
||||||
|
try {
|
||||||
|
instance.mWorkerThread.join(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
instance.mWorkerThread = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 清空上下文(避免内存泄漏)
|
||||||
|
instance.mContext = null;
|
||||||
|
LogUtils.d(TAG, "ToastUtils 资源释放完成");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
package cc.winboll.studio.libappbase;
|
package cc.winboll.studio.libappbase;
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
|
||||||
* @Date 2024/07/19 14:30:57
|
|
||||||
* @Describe UTF-8编码文件工具类
|
|
||||||
*/
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@@ -13,37 +8,79 @@ import java.io.InputStreamReader;
|
|||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||||
|
* @Date 2025/11/11 20:45
|
||||||
|
* @Describe UTF-8 编码文件操作工具类
|
||||||
|
* 提供字符串与文件的相互转换,强制使用 UTF-8 编码,确保跨平台字符兼容性
|
||||||
|
*/
|
||||||
public class UTF8FileUtils {
|
public class UTF8FileUtils {
|
||||||
|
|
||||||
public static final String TAG = "FileUtils";
|
/** 工具类日志 TAG(用于调试输出) */
|
||||||
|
public static final String TAG = "UTF8FileUtils";
|
||||||
|
|
||||||
//
|
/**
|
||||||
// 把字符串写入文件,指定 UTF-8 编码
|
* 将字符串写入文件(强制 UTF-8 编码)
|
||||||
//
|
* 若文件父目录不存在,自动创建;覆盖原有文件内容
|
||||||
public static void writeStringToFile(String szFilePath, String szContent) throws IOException {
|
* @param filePath 文件路径(包含文件名,如 "/sdcard/test.txt")
|
||||||
File file = new File(szFilePath);
|
* @param content 要写入的字符串内容
|
||||||
if (!file.getParentFile().exists()) {
|
* @throws IOException 写入失败时抛出(如权限不足、路径无效等)
|
||||||
file.getParentFile().mkdirs();
|
*/
|
||||||
|
public static void writeStringToFile(String filePath, String content) throws IOException {
|
||||||
|
// 根据路径创建文件对象
|
||||||
|
File file = new File(filePath);
|
||||||
|
// 获取父目录,若不存在则递归创建
|
||||||
|
File parentDir = file.getParentFile();
|
||||||
|
if (parentDir != null && !parentDir.exists()) {
|
||||||
|
parentDir.mkdirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 初始化文件输出流(覆盖模式)
|
||||||
FileOutputStream outputStream = new FileOutputStream(file);
|
FileOutputStream outputStream = new FileOutputStream(file);
|
||||||
|
// 包装为 UTF-8 编码的字符输出流
|
||||||
OutputStreamWriter writer = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8);
|
OutputStreamWriter writer = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8);
|
||||||
writer.write(szContent);
|
|
||||||
writer.close();
|
try {
|
||||||
|
// 写入字符串内容
|
||||||
|
writer.write(content);
|
||||||
|
} finally {
|
||||||
|
// 强制关闭流,避免资源泄漏(即使写入失败也确保流关闭)
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
/**
|
||||||
// 读取文件到字符串,指定 UTF-8 编码
|
* 从文件读取字符串(强制 UTF-8 编码)
|
||||||
//
|
* 逐字符读取文件内容,拼接为完整字符串返回
|
||||||
public static String readStringFromFile(String szFilePath) throws IOException {
|
* @param filePath 文件路径(包含文件名,如 "/sdcard/test.txt")
|
||||||
File file = new File(szFilePath);
|
* @return 文件内容字符串(空文件返回空字符串)
|
||||||
|
* @throws IOException 读取失败时抛出(如文件不存在、权限不足等)
|
||||||
|
*/
|
||||||
|
public static String readStringFromFile(String filePath) throws IOException {
|
||||||
|
// 根据路径创建文件对象
|
||||||
|
File file = new File(filePath);
|
||||||
|
// 初始化文件输入流
|
||||||
FileInputStream inputStream = new FileInputStream(file);
|
FileInputStream inputStream = new FileInputStream(file);
|
||||||
|
// 包装为 UTF-8 编码的字符输入流
|
||||||
InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
|
InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
// 字符串构建器,用于拼接读取的字符
|
||||||
StringBuilder content = new StringBuilder();
|
StringBuilder content = new StringBuilder();
|
||||||
int character;
|
int charCode; // 存储单个字符的 ASCII 码
|
||||||
while ((character = reader.read()) != -1) {
|
|
||||||
content.append((char) character);
|
try {
|
||||||
|
// 逐字符读取(-1 表示读取到文件末尾)
|
||||||
|
while ((charCode = reader.read()) != -1) {
|
||||||
|
// 将 ASCII 码转换为字符,追加到字符串
|
||||||
|
content.append((char) charCode);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
// 强制关闭流,避免资源泄漏
|
||||||
|
reader.close();
|
||||||
}
|
}
|
||||||
reader.close();
|
|
||||||
|
// 返回读取的完整字符串
|
||||||
return content.toString();
|
return content.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,264 @@
|
|||||||
|
package cc.winboll.studio.libappbase.utils;
|
||||||
|
|
||||||
|
import android.app.Application;
|
||||||
|
import android.app.Notification;
|
||||||
|
import android.app.NotificationManager;
|
||||||
|
import android.app.PendingIntent;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import cc.winboll.studio.libappbase.CrashHandler;
|
||||||
|
import cc.winboll.studio.libappbase.GlobalCrashActivity;
|
||||||
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||||
|
* @Date 2025/11/29 21:12
|
||||||
|
* @Describe 应用崩溃处理通知实用工具集(类库兼容版)
|
||||||
|
* 核心功能:作为独立类库使用,发送崩溃通知,点击跳转宿主应用的 GlobalCrashActivity 并传递日志
|
||||||
|
* 适配说明:移除固定包名依赖,通过外部传入宿主包名,支持任意应用集成使用
|
||||||
|
*/
|
||||||
|
public class CrashHandleNotifyUtils {
|
||||||
|
|
||||||
|
public static final String TAG = "CrashHandleNotifyUtils";
|
||||||
|
|
||||||
|
/** 通知渠道ID(Android 8.0+ 必须) */
|
||||||
|
private static final String CRASH_NOTIFY_CHANNEL_ID = "crash_notify_channel";
|
||||||
|
/** 通知渠道名称(用户可见) */
|
||||||
|
private static final String CRASH_NOTIFY_CHANNEL_NAME = "应用崩溃通知";
|
||||||
|
/** 通知ID(唯一) */
|
||||||
|
public static final int CRASH_NOTIFY_ID = 0x001;
|
||||||
|
/** Android 12 对应 API 版本号(31) */
|
||||||
|
private static final int API_LEVEL_ANDROID_12 = 31;
|
||||||
|
/** PendingIntent.FLAG_IMMUTABLE 常量值(API 31+) */
|
||||||
|
private static final int FLAG_IMMUTABLE = 0x00000040;
|
||||||
|
|
||||||
|
/** 通知内容最大行数(控制在3行,超出部分省略) */
|
||||||
|
private static final int NOTIFICATION_MAX_LINES = 3;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理未捕获异常(核心方法,类库入口)
|
||||||
|
* 改进点:新增宿主包名参数,移除类库对固定包名的依赖
|
||||||
|
* @param hostApp 宿主应用的 Application 实例(用于获取宿主上下文)
|
||||||
|
* @param hostPackageName 宿主应用的包名(关键:用于绑定意图、匹配 Activity)
|
||||||
|
* @param errorLog 崩溃日志(从宿主 CrashHandler 传递过来)
|
||||||
|
*/
|
||||||
|
public static void handleUncaughtException(Application hostApp, String hostPackageName, String errorLog) {
|
||||||
|
// 1. 校验核心参数(类库场景必须严格校验,避免空指针)
|
||||||
|
if (hostApp == null || TextUtils.isEmpty(hostPackageName) || TextUtils.isEmpty(errorLog)) {
|
||||||
|
LogUtils.e(TAG, "发送崩溃通知失败:参数为空(hostApp=" + hostApp + ", hostPackageName=" + hostPackageName + ", errorLog=" + errorLog + ")");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 获取宿主应用名称(使用宿主上下文,避免类库包名混淆)
|
||||||
|
String hostAppName = getHostAppName(hostApp, hostPackageName);
|
||||||
|
|
||||||
|
// 3. 发送崩溃通知到宿主通知栏(点击跳转宿主的 GlobalCrashActivity)
|
||||||
|
sendCrashNotification(hostApp, hostPackageName, hostAppName, errorLog);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重载方法:兼容原有调用逻辑(避免宿主集成时改动过大)
|
||||||
|
* 从 Intent 中提取崩溃日志和宿主包名,适配原有 CrashHandler 调用方式
|
||||||
|
* @param hostApp 宿主应用的 Application 实例
|
||||||
|
* @param intent 存储崩溃信息的意图(extra 中携带崩溃日志)
|
||||||
|
*/
|
||||||
|
public static void handleUncaughtException(Application hostApp, Intent intent) {
|
||||||
|
// 从意图中提取宿主包名(优先使用意图中携带的包名,无则用宿主 Application 包名)
|
||||||
|
String hostPackageName = intent.getStringExtra("EXTRA_HOST_PACKAGE_NAME");
|
||||||
|
if (TextUtils.isEmpty(hostPackageName)) {
|
||||||
|
hostPackageName = hostApp.getPackageName();
|
||||||
|
LogUtils.w(TAG, "意图中未携带宿主包名,使用 Application 包名:" + hostPackageName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 从意图中提取崩溃日志(与 CrashHandler.EXTRA_CRASH_INFO 保持一致)
|
||||||
|
String errorLog = intent.getStringExtra(CrashHandler.EXTRA_CRASH_LOG);
|
||||||
|
|
||||||
|
// 调用核心方法处理
|
||||||
|
handleUncaughtException(hostApp, hostPackageName, errorLog);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取宿主应用名称(类库场景适配:使用宿主包名获取,避免类库包名干扰)
|
||||||
|
* @param hostContext 宿主应用的上下文(Application 实例)
|
||||||
|
* @param hostPackageName 宿主应用的包名
|
||||||
|
* @return 宿主应用名称(读取失败返回 "未知应用")
|
||||||
|
*/
|
||||||
|
private static String getHostAppName(Context hostContext, String hostPackageName) {
|
||||||
|
try {
|
||||||
|
// 用宿主包名获取宿主应用信息,确保获取的是宿主的应用名称(类库关键改进)
|
||||||
|
return hostContext.getPackageManager().getApplicationLabel(
|
||||||
|
hostContext.getPackageManager().getApplicationInfo(hostPackageName, 0)
|
||||||
|
).toString();
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtils.e(TAG, "获取宿主应用名称失败(包名:" + hostPackageName + ")", e);
|
||||||
|
return "未知应用";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送崩溃通知到宿主系统通知栏(类库兼容版)
|
||||||
|
* 改进点:全程使用宿主上下文和宿主包名,避免类库包名依赖
|
||||||
|
* @param hostContext 宿主应用的上下文(Application 实例)
|
||||||
|
* @param hostPackageName 宿主应用的包名
|
||||||
|
* @param hostAppName 宿主应用的名称(用于通知标题)
|
||||||
|
* @param errorLog 崩溃日志(传递给宿主的 GlobalCrashActivity)
|
||||||
|
*/
|
||||||
|
private static void sendCrashNotification(Context hostContext, String hostPackageName, String hostAppName, String errorLog) {
|
||||||
|
// 1. 获取宿主的通知管理器(使用宿主上下文,确保通知归属宿主应用)
|
||||||
|
NotificationManager notificationManager = (NotificationManager) hostContext.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
if (notificationManager == null) {
|
||||||
|
LogUtils.e(TAG, "获取宿主 NotificationManager 失败(包名:" + hostPackageName + ")");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 适配 Android 8.0+(API 26+):创建宿主的通知渠道(归属宿主,避免类库渠道冲突)
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
createCrashNotifyChannel(hostContext, notificationManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 notificationManager 宿主的通知管理器
|
||||||
|
*/
|
||||||
|
private static void createCrashNotifyChannel(Context hostContext, NotificationManager notificationManager) {
|
||||||
|
// 仅 Android 8.0+ 执行(避免低版本报错)
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
// 构建通知渠道(归属宿主应用,描述明确类库用途)
|
||||||
|
android.app.NotificationChannel channel = new android.app.NotificationChannel(
|
||||||
|
CRASH_NOTIFY_CHANNEL_ID,
|
||||||
|
CRASH_NOTIFY_CHANNEL_NAME,
|
||||||
|
NotificationManager.IMPORTANCE_DEFAULT
|
||||||
|
);
|
||||||
|
channel.setDescription("应用崩溃通知(由 WinBoLL Studio 类库提供,点击查看详情)");
|
||||||
|
// 注册渠道到宿主的通知管理器,确保渠道归属宿主
|
||||||
|
notificationManager.createNotificationChannel(channel);
|
||||||
|
LogUtils.d(TAG, "宿主崩溃通知渠道创建成功(宿主包名:" + hostContext.getPackageName() + ",渠道ID:" + CRASH_NOTIFY_CHANNEL_ID + ")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 核心改进:构建跳转宿主 GlobalCrashActivity 的意图(类库关键)
|
||||||
|
* 1. 绑定宿主包名,确保类库能正确启动宿主的 Activity;
|
||||||
|
* 2. 传递崩溃日志,与宿主 GlobalCrashActivity 日志接收逻辑匹配;
|
||||||
|
* 3. 使用宿主上下文,避免类库上下文导致的适配问题。
|
||||||
|
* @param hostContext 宿主应用的上下文
|
||||||
|
* @param hostPackageName 宿主应用的包名
|
||||||
|
* @param errorLog 崩溃日志(传递给宿主的 GlobalCrashActivity)
|
||||||
|
* @return 跳转崩溃详情页的 PendingIntent
|
||||||
|
*/
|
||||||
|
private static PendingIntent getGlobalCrashPendingIntent(Context hostContext, String hostPackageName, String errorLog) {
|
||||||
|
try {
|
||||||
|
// 1. 构建跳转宿主 GlobalCrashActivity 的显式意图(类库场景必须显式指定宿主包名)
|
||||||
|
Intent crashIntent = new Intent(hostContext, GlobalCrashActivity.class);
|
||||||
|
// 关键:绑定宿主包名,确保意图能正确匹配宿主的 Activity(避免类库包名干扰)
|
||||||
|
crashIntent.setPackage(hostPackageName);
|
||||||
|
// 传递崩溃日志(键:EXTRA_CRASH_INFO,与宿主 GlobalCrashActivity 完全匹配)
|
||||||
|
crashIntent.putExtra(CrashHandler.EXTRA_CRASH_LOG, errorLog);
|
||||||
|
// 设置意图标志:确保在宿主应用中正常启动,避免重复创建和任务栈混乱
|
||||||
|
crashIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
|
||||||
|
// 2. 构建 PendingIntent(使用宿主上下文,适配高版本)
|
||||||
|
int flags = PendingIntent.FLAG_UPDATE_CURRENT;
|
||||||
|
if (Build.VERSION.SDK_INT >= API_LEVEL_ANDROID_12) {
|
||||||
|
flags |= FLAG_IMMUTABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return PendingIntent.getActivity(
|
||||||
|
hostContext,
|
||||||
|
CRASH_NOTIFY_ID, // 用通知ID作为请求码,确保唯一(避免意图复用)
|
||||||
|
crashIntent,
|
||||||
|
flags
|
||||||
|
);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtils.e(TAG, "构建跳转意图失败(宿主包名:" + hostPackageName + ")", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建通知实例(类库兼容版)
|
||||||
|
* 改进点:使用宿主上下文加载资源,确保通知样式适配宿主应用
|
||||||
|
* @param hostContext 宿主应用的上下文
|
||||||
|
* @param hostAppName 宿主应用的名称(通知标题)
|
||||||
|
* @param errorLog 崩溃日志(通知内容)
|
||||||
|
* @param jumpIntent 通知点击跳转意图(跳转宿主的 GlobalCrashActivity)
|
||||||
|
* @return 构建完成的 Notification 对象
|
||||||
|
*/
|
||||||
|
private static Notification buildNotification(Context hostContext, String hostAppName, String errorLog, PendingIntent jumpIntent) {
|
||||||
|
// 兼容 Android 8.0+:指定宿主的通知渠道ID
|
||||||
|
Notification.Builder builder = new Notification.Builder(hostContext);
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
builder.setChannelId(CRASH_NOTIFY_CHANNEL_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 核心:用BigTextStyle控制“默认3行省略,下拉显示完整”(使用宿主上下文构建)
|
||||||
|
Notification.BigTextStyle bigTextStyle = new Notification.BigTextStyle();
|
||||||
|
bigTextStyle.setSummaryText("日志已省略,下拉查看完整内容");
|
||||||
|
bigTextStyle.bigText(errorLog);
|
||||||
|
bigTextStyle.setBigContentTitle(hostAppName + " 崩溃"); // 标题明确标识宿主和崩溃状态
|
||||||
|
builder.setStyle(bigTextStyle);
|
||||||
|
|
||||||
|
// 配置通知核心参数(全程使用宿主上下文,确保资源归属宿主)
|
||||||
|
builder
|
||||||
|
// 关键:使用宿主应用的小图标(避免类库图标显示异常)
|
||||||
|
.setSmallIcon(hostContext.getApplicationInfo().icon)
|
||||||
|
.setContentTitle(hostAppName + " 崩溃")
|
||||||
|
.setContentText(getShortContent(errorLog)) // 3行内缩略文本
|
||||||
|
.setContentIntent(jumpIntent) // 点击跳转宿主的 GlobalCrashActivity
|
||||||
|
.setAutoCancel(true) // 点击后自动关闭
|
||||||
|
.setWhen(System.currentTimeMillis())
|
||||||
|
.setPriority(Notification.PRIORITY_DEFAULT);
|
||||||
|
|
||||||
|
// 适配 Android 4.1+:确保在宿主应用中正常显示
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||||
|
return builder.build();
|
||||||
|
} else {
|
||||||
|
return builder.getNotification();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 辅助方法:截取日志文本,确保显示在3行内(通用逻辑,无包名依赖)
|
||||||
|
* @param content 完整崩溃日志
|
||||||
|
* @return 3行内的缩略文本
|
||||||
|
*/
|
||||||
|
private static String getShortContent(String content) {
|
||||||
|
if (content == null || content.isEmpty()) {
|
||||||
|
return "无崩溃日志";
|
||||||
|
}
|
||||||
|
int maxLength = 80; // 估算3行字符数(可根据需求调整)
|
||||||
|
return content.length() <= maxLength ? content : content.substring(0, maxLength) + "...";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 释放资源(类库场景:空实现,避免宿主调用时报错,预留扩展)
|
||||||
|
* @param hostContext 宿主应用的上下文(显式传入,避免类库上下文依赖)
|
||||||
|
*/
|
||||||
|
public static void release(Context hostContext) {
|
||||||
|
LogUtils.d(TAG, "CrashHandleNotifyUtils 资源释放完成(宿主包名:" + (hostContext != null ? hostContext.getPackageName() : "未知") + ")");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package cc.winboll.studio.libappbase;
|
package cc.winboll.studio.libappbase.views;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
* @Author ZhanGSKen@AliYun.Com
|
||||||
* @Date 2025/03/12 12:29:01
|
* @Date 2025/03/12 12:29:01
|
||||||
* @Describe 水平布局的 ListView
|
* @Describe 水平布局的 ListView
|
||||||
*/
|
*/
|
||||||
@@ -118,7 +118,7 @@ public class HorizontalListView extends ListView {
|
|||||||
smoothScrollTo(scrollX, 0);
|
smoothScrollTo(scrollX, 0);
|
||||||
LogUtils.d(TAG, String.format("滚动到position: %d, scrollX: %d computeHorizontalScrollRange() %d", position, scrollX, computeHorizontalScrollRange()));
|
LogUtils.d(TAG, String.format("滚动到position: %d, scrollX: %d computeHorizontalScrollRange() %d", position, scrollX, computeHorizontalScrollRange()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetScrollToStart() {
|
public void resetScrollToStart() {
|
||||||
// 强制重新布局和绘制
|
// 强制重新布局和绘制
|
||||||
requestLayout();
|
requestLayout();
|
||||||
11
libappbase/src/main/res/drawable/ic_content_copy.xml
Normal file
11
libappbase/src/main/res/drawable/ic_content_copy.xml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
android:viewportWidth="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#ff000000"
|
||||||
|
android:pathData="M19,21H8V7H19M19,5H8A2,2 0,0 0,6 7V21A2,2 0,0 0,8 23H19A2,2 0,0 0,21 21V7A2,2 0,0 0,19 5M16,1H4A2,2 0,0 0,2 3V17H4V3H16V1Z"/>
|
||||||
|
|
||||||
|
</vector>
|
||||||
@@ -99,7 +99,7 @@
|
|||||||
android:layout_weight="1.0"
|
android:layout_weight="1.0"
|
||||||
android:id="@+id/viewlogHorizontalScrollView1">
|
android:id="@+id/viewlogHorizontalScrollView1">
|
||||||
|
|
||||||
<cc.winboll.studio.libappbase.HorizontalListView
|
<cc.winboll.studio.libappbase.views.HorizontalListView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:id="@+id/tags_listview"/>
|
android:id="@+id/tags_listview"/>
|
||||||
|
|||||||
@@ -4,4 +4,5 @@
|
|||||||
<color name="colorPrimaryDark">#FF005C12</color>
|
<color name="colorPrimaryDark">#FF005C12</color>
|
||||||
<color name="colorAccent">#FF8DFFA2</color>
|
<color name="colorAccent">#FF8DFFA2</color>
|
||||||
<color name="colorText">#FFFFFB8D</color>
|
<color name="colorText">#FFFFFB8D</color>
|
||||||
|
<!-- 通知按钮颜色(启用/禁用) -->
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user