Compare commits
234 Commits
webpagesou
...
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 | |||
| c88dcd7316 | |||
|
|
0ab2fdea66 | ||
|
|
51b6179df6 | ||
|
|
1ee069afca | ||
|
|
f32563b906 | ||
| 5cb6309134 | |||
| 27f84d9e18 | |||
|
|
3e8dde50ec | ||
|
|
ce131235c1 | ||
|
|
58369560b9 | ||
| 5e198d9c68 | |||
|
|
963a3bb7cd | ||
|
|
fd0315d3cf | ||
| eb8d37c340 | |||
|
|
d65a839878 | ||
| ce83a08eb8 | |||
| 7679c9a0d9 | |||
|
|
23eca69a3c | ||
| c1af20009a | |||
|
|
cb3796bfea | ||
| 1362d7a5cf | |||
|
|
8963d2a5df | ||
|
|
f2726ddc7a | ||
|
|
fa09da4e56 | ||
| 52185ed7da | |||
| 355a1c70e5 | |||
| a808310a7c | |||
|
|
839a9e2054 | ||
|
|
471ca23585 | ||
|
|
56be1767bb | ||
|
|
b66d53da1b | ||
|
|
0411d564b9 | ||
|
|
cc365f979e | ||
|
|
6435bd28ac | ||
|
|
9b190e7dfa | ||
|
|
e7f2263860 | ||
|
|
e7b5cfd9b8 | ||
|
|
a4b7c59919 |
@@ -28,12 +28,17 @@ android {
|
||||
}
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
signingConfig signingConfigs.winboll
|
||||
}
|
||||
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"
|
||||
@@ -71,6 +76,7 @@ android {
|
||||
// 2. 配置 Beta 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 == "release")) {
|
||||
println "Project root directory: " + project.rootDir.toString()
|
||||
|
||||
@@ -3,8 +3,11 @@
|
||||
|
||||
########
|
||||
## ☁ ☁ ☁ WinBoLL APP ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁
|
||||
# ☁ ☁ WinBoLL Studio Android 应用开源项目。☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁
|
||||
# ☁ ☁ WinBoLL Studio Android 应用开源项目。☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁ ☁
|
||||
# ☁ ☁ ☁ 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 提问
|
||||
同样是 /sdcard 目录,在开发 Android 应用时,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# AES
|
||||
|
||||
#### 介绍
|
||||
安卓视图元素类库
|
||||
WinBoLL 安卓可视化元素类库测试应用。
|
||||
|
||||
#### 软件架构
|
||||
适配安卓应用 [AIDE Pro] 的 Gradle 编译结构。
|
||||
@@ -32,4 +32,4 @@
|
||||
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
|
||||
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
||||
|
||||
#### 参考文档
|
||||
#### 参考文档
|
||||
|
||||
@@ -18,28 +18,30 @@ def genVersionName(def versionName){
|
||||
}
|
||||
|
||||
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 {
|
||||
applicationId "cc.winboll.studio.aes"
|
||||
minSdkVersion 24
|
||||
minSdkVersion 23
|
||||
targetSdkVersion 30
|
||||
versionCode 1
|
||||
// versionName 更新后需要手动设置
|
||||
// 项目模块目录的 build.gradle 文件的 stageCount=0
|
||||
// Gradle编译环境下合起来的 versionName 就是 "${versionName}.0"
|
||||
versionName "15.9"
|
||||
versionName "15.11"
|
||||
if(true) {
|
||||
versionName = genVersionName("${versionName}")
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
|
||||
// 米盟 SDK
|
||||
packagingOptions {
|
||||
doNotStrip "*/*/libmimo_1011.so"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Sun Aug 31 23:40:17 HKT 2025
|
||||
stageCount=4
|
||||
#Wed Nov 26 15:54:26 GMT 2025
|
||||
stageCount=7
|
||||
libraryProject=libaes
|
||||
baseVersion=15.9
|
||||
publishVersion=15.9.3
|
||||
buildCount=0
|
||||
baseBetaVersion=15.9.4
|
||||
baseVersion=15.11
|
||||
publishVersion=15.11.6
|
||||
buildCount=32
|
||||
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:
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
# ============================== 基础通用规则 ==============================
|
||||
# 保留系统组件
|
||||
-keep public class * extends android.app.Activity
|
||||
-keep public class * extends android.app.Service
|
||||
-keep public class * extends android.content.BroadcastReceiver
|
||||
-keep public class * extends android.content.ContentProvider
|
||||
-keep public class * extends android.app.backup.BackupAgentHelper
|
||||
-keep public class * extends android.preference.Preference
|
||||
|
||||
# 保留 WinBoLL 核心包及子类(合并简化规则)
|
||||
-keep class cc.winboll.studio.** { *; }
|
||||
-keepclassmembers class cc.winboll.studio.** { *; }
|
||||
|
||||
# 保留所有类中的 public static final String TAG 字段(便于日志定位)
|
||||
-keepclassmembers class * {
|
||||
public static final java.lang.String TAG;
|
||||
}
|
||||
|
||||
# 保留序列化类(避免Parcelable/Gson解析异常)
|
||||
-keep class * implements android.os.Parcelable {
|
||||
public static final android.os.Parcelable$Creator *;
|
||||
}
|
||||
-keepclassmembers class * implements java.io.Serializable {
|
||||
static final long serialVersionUID;
|
||||
private static final java.io.ObjectStreamField[] serialPersistentFields;
|
||||
private void writeObject(java.io.ObjectOutputStream);
|
||||
private void readObject(java.io.ObjectInputStream);
|
||||
java.lang.Object writeReplace();
|
||||
java.lang.Object readResolve();
|
||||
}
|
||||
|
||||
# 保留 R 文件(避免资源ID混淆)
|
||||
-keepclassmembers class **.R$* {
|
||||
public static <fields>;
|
||||
}
|
||||
|
||||
# 保留 native 方法(避免JNI调用失败)
|
||||
-keepclasseswithmembernames class * {
|
||||
native <methods>;
|
||||
}
|
||||
|
||||
# 保留注解和泛型(避免反射/序列化异常)
|
||||
-keepattributes *Annotation*
|
||||
-keepattributes Signature
|
||||
|
||||
# 屏蔽 Java 8+ 警告(适配 Java 7 语法)
|
||||
-dontwarn java.lang.invoke.*
|
||||
-dontwarn android.support.v8.renderscript.*
|
||||
-dontwarn java.util.function.**
|
||||
|
||||
# ============================== 第三方框架专项规则 ==============================
|
||||
# OkHttp 4.4.1(米盟广告请求依赖,完善Lambda兼容)
|
||||
-keep class okhttp3.** { *; }
|
||||
-keep interface okhttp3.** { *; }
|
||||
-keep class okhttp3.internal.** { *; }
|
||||
-keep class okio.** { *; }
|
||||
-dontwarn okhttp3.internal.platform.**
|
||||
-dontwarn okio.**
|
||||
|
||||
# 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=".TestActivityManagerActivity"/>
|
||||
|
||||
<activity android:name=".SettingsActivity"/>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
</manifest>
|
||||
@@ -12,18 +12,18 @@ import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import cc.winboll.studio.libaes.winboll.APPInfo;
|
||||
import cc.winboll.studio.libaes.winboll.AboutView;
|
||||
import cc.winboll.studio.libappbase.GlobalApplication;
|
||||
import cc.winboll.studio.libappbase.winboll.IWinBoLLActivity;
|
||||
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
|
||||
import cc.winboll.studio.libaes.models.APPInfo;
|
||||
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
|
||||
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";
|
||||
|
||||
Context mContext;
|
||||
Toolbar mToolbar;
|
||||
|
||||
|
||||
@Override
|
||||
public Activity getActivity() {
|
||||
return this;
|
||||
@@ -33,7 +33,7 @@ public class AboutActivity extends AppCompatActivity implements IWinBoLLActivity
|
||||
public String getTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -64,13 +64,13 @@ public class AboutActivity extends AppCompatActivity implements IWinBoLLActivity
|
||||
);
|
||||
layout.addView(aboutView, params);
|
||||
|
||||
GlobalApplication.getWinBoLLActivityManager().add(this);
|
||||
WinBoLLActivityManager.getInstance().add(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
GlobalApplication.getWinBoLLActivityManager().registeRemove(this);
|
||||
WinBoLLActivityManager.getInstance().registeRemove(this);
|
||||
}
|
||||
|
||||
public AboutView CreateAboutView() {
|
||||
@@ -83,11 +83,11 @@ public class AboutActivity extends AppCompatActivity implements IWinBoLLActivity
|
||||
appInfo.setAppGitOwner("Studio");
|
||||
appInfo.setAppGitAPPBranch(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.setAppAPKFolderName("AES");
|
||||
//appInfo.setIsAddDebugTools(false);
|
||||
appInfo.setIsAddDebugTools(BuildConfig.DEBUG);
|
||||
//appInfo.setIsAddDebugTools(BuildConfig.DEBUG);
|
||||
return new AboutView(mContext, appInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@ package cc.winboll.studio.aes;
|
||||
* @Describe AES应用类
|
||||
*/
|
||||
import android.view.Gravity;
|
||||
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
|
||||
import cc.winboll.studio.libappbase.GlobalApplication;
|
||||
import com.hjq.toast.ToastUtils;
|
||||
import com.hjq.toast.style.WhiteToastStyle;
|
||||
import cc.winboll.studio.libappbase.ToastUtils;
|
||||
|
||||
|
||||
public class App extends GlobalApplication {
|
||||
@@ -18,14 +18,16 @@ public class App extends GlobalApplication {
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
setIsDebugging(BuildConfig.DEBUG);
|
||||
WinBoLLActivityManager.init(this);
|
||||
|
||||
// 初始化 Toast 框架
|
||||
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 cc.winboll.studio.aes.R;
|
||||
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.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.TestAButtonFragment;
|
||||
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.TestViewPageFragment;
|
||||
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.hjq.toast.ToastUtils;
|
||||
import java.util.ArrayList;
|
||||
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
|
||||
|
||||
public class MainActivity extends DrawerFragmentActivity implements IWinBoLLActivity {
|
||||
|
||||
@@ -89,9 +90,9 @@ public class MainActivity extends DrawerFragmentActivity implements IWinBoLLActi
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.toolbar_library, menu);
|
||||
if(App.isDebuging()) {
|
||||
getMenuInflater().inflate(cc.winboll.studio.libapputils.R.menu.toolbar_studio_debug, menu);
|
||||
getMenuInflater().inflate(R.menu.toolbar_main, menu);
|
||||
if(App.isDebugging()) {
|
||||
getMenuInflater().inflate(cc.winboll.studio.libaes.R.menu.toolbar_studio_debug, menu);
|
||||
}
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
@@ -122,9 +123,10 @@ public class MainActivity extends DrawerFragmentActivity implements IWinBoLLActi
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int nItemId = item.getItemId();
|
||||
// if (item.getItemId() == R.id.item_log) {
|
||||
// WinBoLLActivityManager.getInstance(this).startWinBoLLActivity(getApplicationContext(), LogActivity.class);
|
||||
// } else
|
||||
if (item.getItemId() == R.id.item_testactivitymanager) {
|
||||
WinBoLLActivityManager.getInstance().startWinBoLLActivity(this, TestActivityManagerActivity.class);
|
||||
//ToastUtils.show("item_testactivitymanager");
|
||||
} else
|
||||
if (nItemId == R.id.item_atoast) {
|
||||
Toast.makeText(getApplication(), "item_testatoast", Toast.LENGTH_SHORT).show();
|
||||
} 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) {
|
||||
Intent intent = new Intent(this, TestDrawerFragmentActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
else if (nItemId == R.id.item_about) {
|
||||
} else if (nItemId == R.id.item_settings) {
|
||||
Intent intent = new Intent(this, SettingsActivity.class);
|
||||
startActivity(intent);
|
||||
} else if (nItemId == R.id.item_about) {
|
||||
Intent intent = new Intent(this, AboutActivity.class);
|
||||
startActivity(intent);
|
||||
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"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:id="@+id/item_testactivitymanager"
|
||||
android:title="TestActivityManager"/>
|
||||
<item
|
||||
android:id="@+id/item_log"
|
||||
android:title="LogActivity"/>
|
||||
@@ -29,4 +32,7 @@
|
||||
<item
|
||||
android:id="@+id/item_drawerfragmentactivity"
|
||||
android:title="Test DrawerFragmentActivity"/>
|
||||
<item
|
||||
android:id="@+id/item_settings"
|
||||
android:title="Settings"/>
|
||||
</menu>
|
||||
@@ -19,29 +19,31 @@ def genVersionName(def versionName){
|
||||
|
||||
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 {
|
||||
applicationId "cc.winboll.studio.appbase"
|
||||
minSdkVersion 24
|
||||
minSdkVersion 23
|
||||
targetSdkVersion 30
|
||||
versionCode 1
|
||||
// versionName 更新后需要手动设置
|
||||
// .winboll/winbollBuildProps.properties 文件的 stageCount=0
|
||||
// Gradle编译环境下合起来的 versionName 就是 "${versionName}.0"
|
||||
versionName "15.10"
|
||||
versionName "15.11"
|
||||
if(true) {
|
||||
versionName = genVersionName("${versionName}")
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
// 确保 Java 7 兼容性(已适配项目技术栈)
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_7
|
||||
targetCompatibility JavaVersion.VERSION_1_7
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Sat Sep 27 21:03:20 HKT 2025
|
||||
stageCount=10
|
||||
#Sun Nov 30 17:13:07 HKT 2025
|
||||
stageCount=7
|
||||
libraryProject=libappbase
|
||||
baseVersion=15.10
|
||||
publishVersion=15.10.9
|
||||
baseVersion=15.11
|
||||
publishVersion=15.11.6
|
||||
buildCount=0
|
||||
baseBetaVersion=15.10.10
|
||||
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 {
|
||||
# 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
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="cc.winboll.studio.appbase">
|
||||
|
||||
<!-- 网络权限 -->
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
|
||||
<application
|
||||
android:name=".App"
|
||||
android:icon="@drawable/ic_winboll"
|
||||
@@ -14,7 +11,7 @@
|
||||
android:resizeableActivity="true"
|
||||
android:process=":App">
|
||||
|
||||
<activity
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:exported="true"
|
||||
@@ -32,13 +29,15 @@
|
||||
</intent-filter>
|
||||
|
||||
</activity>
|
||||
|
||||
|
||||
<activity android:name=".GlobalApplication$CrashActivity"/>
|
||||
|
||||
|
||||
<meta-data
|
||||
android:name="android.max_aspect"
|
||||
android:value="4.0"/>
|
||||
|
||||
<activity android:name="cc.winboll.studio.libappbase.activities.CrashCopyReceiverActivity"/>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
</manifest>
|
||||
@@ -1,19 +1,43 @@
|
||||
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>
|
||||
* @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 {
|
||||
|
||||
/** 当前应用类的日志 TAG(用于调试输出,标识日志来源) */
|
||||
public static final String TAG = "App";
|
||||
|
||||
|
||||
/**
|
||||
* 应用创建时回调(全局初始化入口)
|
||||
* 在应用进程启动时执行,仅调用一次,用于初始化全局工具类、第三方库等
|
||||
*/
|
||||
@Override
|
||||
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.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
import android.widget.Toolbar;
|
||||
import cc.winboll.studio.appbase.R;
|
||||
import cc.winboll.studio.libappbase.LogActivity;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.ToastUtils;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 未标注(建议补充创建日期)
|
||||
* @Describe 应用主界面 Activity(入口界面)
|
||||
* 包含功能测试按钮(崩溃测试、日志查看、Toast测试)、顶部工具栏(菜单功能),是应用交互的核心入口
|
||||
*/
|
||||
public class MainActivity extends Activity {
|
||||
|
||||
/** 当前 Activity 的日志 TAG(用于调试输出,标识日志来源) */
|
||||
public static final String TAG = "MainActivity";
|
||||
|
||||
Toolbar mToolbar;
|
||||
/** 顶部工具栏(用于展示标题、菜单,绑定布局中的 Toolbar 控件) */
|
||||
private Toolbar mToolbar;
|
||||
|
||||
/**
|
||||
* Activity 创建时回调(初始化界面)
|
||||
* 在 Activity 首次创建时执行,用于加载布局、初始化控件、设置事件监听
|
||||
* @param savedInstanceState 保存 Activity 状态的 Bundle(如屏幕旋转时的数据恢复)
|
||||
*/
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
ToastUtils.show("onCreate");
|
||||
setContentView(R.layout.activity_main);
|
||||
ToastUtils.show("onCreate"); // 显示 Activity 创建提示(调试用)
|
||||
setContentView(R.layout.activity_main); // 加载主界面布局
|
||||
|
||||
// 初始化 Toolbar 并设置为 ActionBar
|
||||
mToolbar = findViewById(R.id.toolbar);
|
||||
setActionBar(mToolbar);
|
||||
setActionBar(mToolbar); // 将 Toolbar 替代系统默认 ActionBar
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建菜单时回调(加载工具栏菜单)
|
||||
* 初始化 ActionBar 菜单,加载自定义菜单布局
|
||||
* @param menu 菜单对象(用于承载菜单项)
|
||||
* @return true:显示菜单;false:不显示菜单
|
||||
*/
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// 加载菜单布局(R.menu.toolbar_main 为自定义菜单文件)
|
||||
getMenuInflater().inflate(R.menu.toolbar_main, menu);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单 item 点击时回调(处理菜单事件)
|
||||
* 响应 Toolbar 菜单项的点击事件,执行对应业务逻辑
|
||||
* @param item 被点击的菜单项
|
||||
* @return true:消费点击事件;false:不消费(传递给父类)
|
||||
*/
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.item_home : {
|
||||
openWebsiteInBrowser(this);
|
||||
}
|
||||
}
|
||||
// 在switch语句中处理每个ID,并在处理完后返回true,未处理的情况返回false。
|
||||
switch (item.getItemId()) {
|
||||
case R.id.item_home:
|
||||
// 点击 "首页/官网" 菜单项,唤起浏览器打开指定网站
|
||||
openWebsiteInBrowser(this);
|
||||
break;
|
||||
// 可扩展其他菜单项(如设置、关于等)的处理逻辑
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* 崩溃测试按钮点击事件(触发应用崩溃,用于调试异常捕获)
|
||||
* 故意执行非法操作(循环获取不存在的字符串资源),强制应用崩溃
|
||||
* @param view 触发事件的 View(对应布局中的崩溃测试按钮)
|
||||
*/
|
||||
public void onCrashTest(View view) {
|
||||
for (int i = Integer.MIN_VALUE; i < Integer.MAX_VALUE; i++) {
|
||||
getString(i);
|
||||
}
|
||||
// 循环从 Integer.MIN_VALUE 到 Integer.MAX_VALUE,获取不存在的字符串资源 ID,触发崩溃
|
||||
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) {
|
||||
// 启动日志查看 Activity(通过静态方法传入上下文,简化跳转逻辑)
|
||||
LogActivity.startLogActivity(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 唤起默认浏览器打开指定网站
|
||||
* @param context 上下文(如 Activity.this)
|
||||
*/
|
||||
public void openWebsiteInBrowser(Context context) {
|
||||
// 目标网站地址
|
||||
String url = "https://www.winboll.cc";
|
||||
// 构建打开浏览器的意图
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
||||
// 设置标志:避免创建新的任务栈(可选,按需求调整)
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
|
||||
}
|
||||
/**
|
||||
* Toast 工具测试按钮点击事件(测试全局 Toast 功能)
|
||||
* 测试主线程、子线程中 Toast 的显示效果,验证 ToastUtils 的可用性
|
||||
* @param view 触发事件的 View(对应布局中的 Toast 测试按钮)
|
||||
*/
|
||||
public void onToastUtilsTest(View view) {
|
||||
LogUtils.d(TAG, "onToastUtilsTest"); // 打印调试日志,标识进入 Toast 测试
|
||||
ToastUtils.show("Hello, WinBoLL!"); // 主线程显示 Toast
|
||||
|
||||
// 开启子线程,延迟 2 秒后显示 Toast(测试子线程 Toast 兼容性)
|
||||
new Thread(new Runnable() {
|
||||
@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:id="@+id/toolbar"/>
|
||||
|
||||
<LinearLayout
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center_vertical"
|
||||
android:spacing="12dp">
|
||||
android:layout_weight="1.0">
|
||||
|
||||
<Button
|
||||
<LinearLayout
|
||||
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="onCrashTest"/>
|
||||
android:orientation="vertical"
|
||||
android:gravity="center_vertical"
|
||||
android:spacing="12dp">
|
||||
|
||||
<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"/>
|
||||
<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="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>
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">AppBase</string>
|
||||
<string name="tileservice_name">WinBoLL</string>
|
||||
</resources>
|
||||
|
||||
35
apputils/README.md
Normal file
35
apputils/README.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# APPUtils
|
||||
|
||||
#### 介绍
|
||||
应用开发工具套件类
|
||||
|
||||
#### 软件架构
|
||||
适配安卓应用 [AIDE Pro] 的 Gradle 编译结构。
|
||||
也适配安卓应用 [AndroidIDE] 的 Gradle 编译结构。
|
||||
|
||||
|
||||
#### Gradle 编译说明
|
||||
调试版编译命令 :gradle assembleBetaDebug
|
||||
阶段版编译命令 :git pull && bash .winboll/bashPublishAPKAddTag.sh apputils
|
||||
阶段版类库发布命令 :git pull &&bash .winboll/bashPublishLIBAddTag.sh libapputils
|
||||
|
||||
#### 使用说明
|
||||
|
||||
#### 参与贡献
|
||||
|
||||
1. Fork 本仓库
|
||||
2. 新建 Feat_xxx 分支
|
||||
3. 提交代码 : ZhanGSKen(ZhanGSKen<zhangsken@188.com>)
|
||||
4. 新建 Pull Request
|
||||
|
||||
|
||||
#### 特技
|
||||
|
||||
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
|
||||
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
|
||||
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
|
||||
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
|
||||
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
|
||||
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
||||
|
||||
#### 参考文档
|
||||
@@ -29,7 +29,7 @@ android {
|
||||
// versionName 更新后需要手动设置
|
||||
// 项目模块目录的 build.gradle 文件的 stageCount=0
|
||||
// Gradle编译环境下合起来的 versionName 就是 "${versionName}.0"
|
||||
versionName "15.8"
|
||||
versionName "15.10"
|
||||
if(true) {
|
||||
versionName = genVersionName("${versionName}")
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Mon Sep 01 07:56:33 HKT 2025
|
||||
stageCount=7
|
||||
#Mon Sep 29 01:16:05 HKT 2025
|
||||
stageCount=3
|
||||
libraryProject=libapputils
|
||||
baseVersion=15.8
|
||||
publishVersion=15.8.6
|
||||
baseVersion=15.10
|
||||
publishVersion=15.10.2
|
||||
buildCount=0
|
||||
baseBetaVersion=15.8.7
|
||||
baseBetaVersion=15.10.3
|
||||
|
||||
@@ -2,14 +2,20 @@
|
||||
<manifest
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="cc.winboll.studio.apputils">
|
||||
|
||||
|
||||
<!-- 读取外部存储权限(Android 10 以下) -->
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
|
||||
<application
|
||||
android:name=".App"
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/ic_winboll"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/MyUtilsTheme"
|
||||
android:supportsRtl="true">
|
||||
android:supportsRtl="true"
|
||||
android:resizeableActivity="true"
|
||||
android:screenOrientation="unspecified"
|
||||
android:requestLegacyExternalStorage="true">
|
||||
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
@@ -35,6 +41,8 @@
|
||||
|
||||
<activity android:name=".QRCodeDecodeActivity"/>
|
||||
|
||||
<activity android:name=".QRGeneratorActivity"/>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
</manifest>
|
||||
|
||||
@@ -15,12 +15,11 @@ import android.view.MenuItem;
|
||||
import android.widget.Toolbar;
|
||||
import cc.winboll.studio.apputils.R;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.winboll.IWinBoLLActivity;
|
||||
import cc.winboll.studio.libapputils.views.SimpleWebView;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class AssetsHtmlActivity extends WinBoLLActivity implements IWinBoLLActivity {
|
||||
public class AssetsHtmlActivity extends Activity {
|
||||
|
||||
public static final String TAG = "AssetsHtmlActivity";
|
||||
|
||||
@@ -32,16 +31,6 @@ public class AssetsHtmlActivity extends WinBoLLActivity implements IWinBoLLActiv
|
||||
|
||||
// Assets 文件夹里的 Html 文件的名称
|
||||
String mszHtmlFileName;
|
||||
|
||||
@Override
|
||||
public Activity getActivity() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
|
||||
@@ -15,9 +15,10 @@ import android.widget.Toolbar;
|
||||
import cc.winboll.studio.apputils.R;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.LogView;
|
||||
import cc.winboll.studio.libappbase.utils.ToastUtils;
|
||||
import cc.winboll.studio.libappbase.ToastUtils;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import cc.winboll.studio.libappbase.LogActivity;
|
||||
|
||||
final public class MainActivity extends Activity {
|
||||
|
||||
@@ -26,21 +27,21 @@ final public class MainActivity extends Activity {
|
||||
public static final int REQUEST_QRCODEDECODE_ACTIVITY = 0;
|
||||
|
||||
Toolbar mToolbar;
|
||||
LogView mLogView;
|
||||
//LogView mLogView;
|
||||
//
|
||||
// @Override
|
||||
// public Activity getActivity() {
|
||||
// return this;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
mLogView = findViewById(R.id.logview);
|
||||
mLogView.start();
|
||||
// mLogView = findViewById(R.id.logview);
|
||||
// mLogView.start();
|
||||
|
||||
// 初始化工具栏
|
||||
mToolbar = findViewById(R.id.toolbar);
|
||||
@@ -145,13 +146,21 @@ final public class MainActivity extends Activity {
|
||||
}
|
||||
|
||||
public void onTestLogActivity(View view) {
|
||||
// Intent intent = new Intent(this, LogActivity.class);
|
||||
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
|
||||
// intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
|
||||
// startActivity(intent);
|
||||
/* 分屏代码有效
|
||||
// 1. 创建启动 SecondActivity 的 Intent
|
||||
Intent splitIntent = new Intent(MainActivity.this, LogActivity.class);
|
||||
|
||||
//WinBoLLActivityManager.getInstance().printAvtivityListInfo();
|
||||
//WinBoLLActivityManager.getInstance(this).startWinBoLLActivity(this, LogActivity.class);
|
||||
// 2. 添加分屏启动必需的两个标志(API 30 兼容)
|
||||
// FLAG_ACTIVITY_LAUNCH_ADJACENT:相邻分屏显示
|
||||
// FLAG_ACTIVITY_NEW_TASK:分屏需要新任务栈
|
||||
splitIntent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT
|
||||
| Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
|
||||
// 3. 启动分屏活动(若设备不支持分屏,会默认全屏启动)
|
||||
startActivity(splitIntent);
|
||||
*/
|
||||
|
||||
LogActivity.startLogActivity(this);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -217,10 +226,9 @@ final public class MainActivity extends Activity {
|
||||
if (item.getItemId() == R.id.item_exit) {
|
||||
//exit();
|
||||
return true;
|
||||
// } else if (item.getItemId() == R.id.item_teststringtoqrcodeview) {
|
||||
// Intent intent = new Intent(this, TestStringToQRCodeViewActivity.class);
|
||||
// startActivityForResult(intent, REQUEST_QRCODEDECODE_ACTIVITY);
|
||||
// //WinBoLLActivityManager.getInstance(this).startWinBoLLActivity(this, TestStringToQrCodeViewActivity.class);
|
||||
} else if (item.getItemId() == R.id.item_testqrgeneratoractivity) {
|
||||
Intent intent = new Intent(this, QRGeneratorActivity.class);
|
||||
startActivity(intent);
|
||||
} else if (item.getItemId() == R.id.item_testqrcodedecodeactivity) {
|
||||
Intent intent = new Intent(this, QRCodeDecodeActivity.class);
|
||||
startActivityForResult(intent, REQUEST_QRCODEDECODE_ACTIVITY);
|
||||
@@ -268,7 +276,7 @@ final public class MainActivity extends Activity {
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void onTestAssetsHtmlActivity(View view) {
|
||||
Intent intent = new Intent(this, AssetsHtmlActivity.class);
|
||||
intent.putExtra(AssetsHtmlActivity.EXTRA_HTMLFILENAME, "javascript_test.html");
|
||||
@@ -281,7 +289,7 @@ final public class MainActivity extends Activity {
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
mLogView.start();
|
||||
//mLogView.start();
|
||||
}
|
||||
|
||||
/*@Override
|
||||
|
||||
@@ -1,89 +1,323 @@
|
||||
package cc.winboll.studio.apputils;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||
* @Date 2025/01/18 10:32:21
|
||||
* @Describe 二维码扫码解码窗口
|
||||
* @Describe 二维码解码窗口
|
||||
*/
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.ColorMatrix;
|
||||
import android.graphics.ColorMatrixColorFilter;
|
||||
import android.graphics.Paint;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.MediaStore;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toolbar;
|
||||
import cc.winboll.studio.apputils.R;
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.BinaryBitmap;
|
||||
import com.google.zxing.DecodeHintType;
|
||||
import com.google.zxing.LuminanceSource;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.RGBLuminanceSource;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.ResultPoint;
|
||||
import com.google.zxing.common.HybridBinarizer;
|
||||
import com.journeyapps.barcodescanner.BarcodeCallback;
|
||||
import com.journeyapps.barcodescanner.BarcodeResult;
|
||||
import com.journeyapps.barcodescanner.DecoratedBarcodeView;
|
||||
import com.journeyapps.barcodescanner.DefaultDecoderFactory;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
|
||||
public class QRCodeDecodeActivity extends Activity {
|
||||
|
||||
public static final String TAG = "QRCodeDecodeActivity";
|
||||
|
||||
public static final String EXTRA_RESULT = "EXTRA_RESULT";
|
||||
private static final int REQUEST_CAMERA_PERMISSION = 1;
|
||||
private static final int REQUEST_PICK_IMAGE = 2;
|
||||
private static final int REQUEST_READ_STORAGE_PERMISSION = 3;
|
||||
// 图片压缩阈值:超过1000px时压缩,避免内存溢出和解码效率低
|
||||
private static final int MAX_BITMAP_SIZE = 1000;
|
||||
|
||||
TextView resultTextView;
|
||||
DecoratedBarcodeView barcodeView;
|
||||
|
||||
// @Override
|
||||
// public Activity getActivity() {
|
||||
// return this;
|
||||
// }
|
||||
private TextView resultTextView;
|
||||
private DecoratedBarcodeView barcodeView;
|
||||
private Button btnDecodeFromAlbum;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_qrcodedecode);
|
||||
|
||||
// 初始化工具栏
|
||||
// Toolbar mToolbar = findViewById(R.id.toolbar);
|
||||
// setActionBar(mToolbar);
|
||||
|
||||
//resultTextView = findViewById(R.id.activityqrcodedecodeTextView1);
|
||||
barcodeView = findViewById(R.id.activityqrcodedecodeDecoratedBarcodeView1);
|
||||
// 请求相机权限
|
||||
// if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.CAMERA)
|
||||
// != PackageManager.PERMISSION_GRANTED) {
|
||||
// ActivityCompat.requestPermissions(this,
|
||||
// new String[]{android.Manifest.permission.CAMERA},
|
||||
// REQUEST_CAMERA_PERMISSION);
|
||||
// } else {
|
||||
// startScanning();
|
||||
// }
|
||||
startScanning();
|
||||
initToolbar();
|
||||
initViews();
|
||||
checkCameraPermission();
|
||||
setAlbumDecodeClickListener();
|
||||
}
|
||||
|
||||
private void startScanning() {
|
||||
barcodeView.getBarcodeView().setDecoderFactory(null);
|
||||
barcodeView.decodeContinuous(barcodeCallback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode,
|
||||
String[] permissions, int[] grantResults) {
|
||||
if (requestCode == REQUEST_CAMERA_PERMISSION) {
|
||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
startScanning();
|
||||
} else {
|
||||
// 权限被拒绝的处理
|
||||
private void initToolbar() {
|
||||
Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
if (mToolbar != null) {
|
||||
setActionBar(mToolbar);
|
||||
if (getActionBar() != null) {
|
||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BarcodeCallback barcodeCallback = new BarcodeCallback(){
|
||||
private void initViews() {
|
||||
resultTextView = (TextView) findViewById(R.id.activityqrcodedecodeTextView1);
|
||||
barcodeView = (DecoratedBarcodeView) findViewById(R.id.activityqrcodedecodeDecoratedBarcodeView1);
|
||||
btnDecodeFromAlbum = (Button) findViewById(R.id.btn_decode_from_album);
|
||||
// 初始化扫码解码器(支持所有常见码制,避免仅支持QR_CODE的局限)
|
||||
List<BarcodeFormat> formats = new ArrayList<BarcodeFormat>();
|
||||
formats.add(BarcodeFormat.QR_CODE);
|
||||
formats.add(BarcodeFormat.CODE_128);
|
||||
formats.add(BarcodeFormat.EAN_13);
|
||||
barcodeView.getBarcodeView().setDecoderFactory(new DefaultDecoderFactory(formats));
|
||||
}
|
||||
|
||||
private void setAlbumDecodeClickListener() {
|
||||
btnDecodeFromAlbum.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (checkSelfPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
requestPermissions(new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE},
|
||||
REQUEST_READ_STORAGE_PERMISSION);
|
||||
} else {
|
||||
openAlbum();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void openAlbum() {
|
||||
Intent pickImageIntent = new Intent(Intent.ACTION_PICK);
|
||||
pickImageIntent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
|
||||
startActivityForResult(pickImageIntent, REQUEST_PICK_IMAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == REQUEST_PICK_IMAGE && resultCode == RESULT_OK && data != null) {
|
||||
Uri selectedImageUri = data.getData();
|
||||
if (selectedImageUri != null) {
|
||||
try {
|
||||
// 1. 读取图片并压缩(关键优化:避免大图片解码失败)
|
||||
InputStream imageStream = getContentResolver().openInputStream(selectedImageUri);
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inJustDecodeBounds = true; // 先获取图片尺寸,不加载像素
|
||||
BitmapFactory.decodeStream(imageStream, null, options);
|
||||
imageStream.close(); // 关闭流,重新读取
|
||||
|
||||
// 计算压缩比例:超过MAX_BITMAP_SIZE时按比例压缩
|
||||
options.inSampleSize = calculateInSampleSize(options, MAX_BITMAP_SIZE, MAX_BITMAP_SIZE);
|
||||
options.inJustDecodeBounds = false; // 开始加载压缩后的像素
|
||||
imageStream = getContentResolver().openInputStream(selectedImageUri);
|
||||
Bitmap originalBitmap = BitmapFactory.decodeStream(imageStream, null, options);
|
||||
imageStream.close();
|
||||
|
||||
if (originalBitmap == null) {
|
||||
showToast("图片损坏,无法解析");
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 图片预处理:转为灰度图+提高对比度(解决模糊/低对比度图片识别问题)
|
||||
Bitmap processedBitmap = processBitmap(originalBitmap);
|
||||
|
||||
// 3. 解码预处理后的图片
|
||||
String decodeResult = decodeQrFromBitmap(processedBitmap);
|
||||
|
||||
// 4. 结果处理
|
||||
if (decodeResult != null && !decodeResult.isEmpty()) {
|
||||
resultTextView.setText("图片解码结果:" + decodeResult);
|
||||
showDecodeResultDialog(decodeResult);
|
||||
returnResultToPreviousPage(decodeResult);
|
||||
} else {
|
||||
// 尝试直接解码原图(防止预处理过度导致识别失败)
|
||||
String originalResult = decodeQrFromBitmap(originalBitmap);
|
||||
if (originalResult != null && !originalResult.isEmpty()) {
|
||||
resultTextView.setText("图片解码结果:" + originalResult);
|
||||
showDecodeResultDialog(originalResult);
|
||||
returnResultToPreviousPage(originalResult);
|
||||
} else {
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle("解码失败")
|
||||
.setMessage("图片中未识别到二维码/条码,建议选择清晰、完整的图片")
|
||||
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
// 回收Bitmap,避免内存泄漏
|
||||
if (!originalBitmap.isRecycled()) originalBitmap.recycle();
|
||||
if (!processedBitmap.isRecycled() && processedBitmap != originalBitmap) {
|
||||
processedBitmap.recycle();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
showToast("图片处理失败:" + e.getMessage());
|
||||
}
|
||||
} else {
|
||||
showToast("未选择图片");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 核心优化1:计算图片压缩比例
|
||||
*/
|
||||
private int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
|
||||
final int height = options.outHeight;
|
||||
final int width = options.outWidth;
|
||||
int inSampleSize = 1;
|
||||
|
||||
if (height > reqHeight || width > reqWidth) {
|
||||
final int halfHeight = height / 2;
|
||||
final int halfWidth = width / 2;
|
||||
// 找到最接近reqWidth/reqHeight的压缩比例(2的倍数,保证图片质量)
|
||||
while ((halfHeight / inSampleSize) >= reqHeight
|
||||
&& (halfWidth / inSampleSize) >= reqWidth) {
|
||||
inSampleSize *= 2;
|
||||
}
|
||||
}
|
||||
return inSampleSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* 核心优化2:图片预处理(灰度化+提高对比度)
|
||||
* 解决模糊、低亮度、低对比度图片识别率低的问题
|
||||
*/
|
||||
private Bitmap processBitmap(Bitmap bitmap) {
|
||||
int width = bitmap.getWidth();
|
||||
int height = bitmap.getHeight();
|
||||
|
||||
// 创建灰度图
|
||||
Bitmap grayBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(grayBitmap);
|
||||
Paint paint = new Paint();
|
||||
|
||||
// 1. 灰度化矩阵
|
||||
ColorMatrix grayMatrix = new ColorMatrix();
|
||||
grayMatrix.setSaturation(0); // 饱和度设为0,转为灰度
|
||||
|
||||
// 2. 提高对比度矩阵(alpha=1.5,亮度=0,可根据需求调整)
|
||||
ColorMatrix contrastMatrix = new ColorMatrix();
|
||||
contrastMatrix.set(new float[]{
|
||||
1.5f, 0, 0, 0, 0, // 红通道对比度
|
||||
0, 1.5f, 0, 0, 0, // 绿通道对比度
|
||||
0, 0, 1.5f, 0, 0, // 蓝通道对比度
|
||||
0, 0, 0, 1f, 0 // alpha通道不变
|
||||
});
|
||||
|
||||
// 合并灰度+对比度矩阵
|
||||
ColorMatrix combinedMatrix = new ColorMatrix();
|
||||
combinedMatrix.postConcat(grayMatrix);
|
||||
combinedMatrix.postConcat(contrastMatrix);
|
||||
|
||||
paint.setColorFilter(new ColorMatrixColorFilter(combinedMatrix));
|
||||
canvas.drawBitmap(bitmap, 0, 0, paint);
|
||||
|
||||
return grayBitmap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 核心优化3:修复解码参数,支持更多场景
|
||||
*/
|
||||
private String decodeQrFromBitmap(Bitmap bitmap) {
|
||||
if (bitmap == null) return null;
|
||||
|
||||
try {
|
||||
int width = bitmap.getWidth();
|
||||
int height = bitmap.getHeight();
|
||||
int[] pixels = new int[width * height];
|
||||
bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
|
||||
|
||||
// 修复1:使用RGBLuminanceSource,避免YUV格式导致的颜色偏差
|
||||
LuminanceSource source = new RGBLuminanceSource(width, height, pixels);
|
||||
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source));
|
||||
|
||||
// 修复2:完善解码参数,解决模糊、变形二维码识别问题
|
||||
Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
|
||||
// 支持所有常见码制(不仅限于QR_CODE)
|
||||
List<BarcodeFormat> formats = new ArrayList<BarcodeFormat>();
|
||||
formats.add(BarcodeFormat.QR_CODE);
|
||||
formats.add(BarcodeFormat.CODE_128);
|
||||
formats.add(BarcodeFormat.EAN_8);
|
||||
formats.add(BarcodeFormat.EAN_13);
|
||||
hints.put(DecodeHintType.POSSIBLE_FORMATS, formats);
|
||||
// 字符编码:支持中文等多语言
|
||||
hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");
|
||||
// 容错模式:允许二维码有一定损坏(关键!解决轻微变形/污染的二维码)
|
||||
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
|
||||
// 不使用纯条码模式,兼容带logo的二维码
|
||||
hints.put(DecodeHintType.PURE_BARCODE, Boolean.FALSE);
|
||||
|
||||
MultiFormatReader reader = new MultiFormatReader();
|
||||
reader.setHints(hints);
|
||||
Result result = reader.decode(binaryBitmap);
|
||||
return result.getText();
|
||||
|
||||
} catch (NotFoundException e) {
|
||||
// 正常未识别到,不打印异常(避免日志冗余)
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 原有逻辑(不变) ====================
|
||||
private void checkCameraPermission() {
|
||||
if (checkSelfPermission(android.Manifest.permission.CAMERA)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
requestPermissions(new String[]{android.Manifest.permission.CAMERA},
|
||||
REQUEST_CAMERA_PERMISSION);
|
||||
} else {
|
||||
startScanning();
|
||||
}
|
||||
}
|
||||
|
||||
private void startScanning() {
|
||||
barcodeView.decodeContinuous(barcodeCallback);
|
||||
}
|
||||
|
||||
private BarcodeCallback barcodeCallback = new BarcodeCallback() {
|
||||
@Override
|
||||
public void barcodeResult(BarcodeResult result) {
|
||||
if (result.getText() != null) {
|
||||
//Toast.makeText(MainActivity.this, "Scanned: " + result.getText(), Toast.LENGTH_SHORT).show();
|
||||
//ToastUtils.show("Scanned: " + result.getText());
|
||||
if (result != null && result.getText() != null) {
|
||||
barcodeView.pause();
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(EXTRA_RESULT, result.getText());
|
||||
setResult(RESULT_OK, intent);
|
||||
finish();
|
||||
String decodeResult = result.getText();
|
||||
resultTextView.setText("扫码结果:" + decodeResult);
|
||||
showDecodeResultDialog(decodeResult);
|
||||
returnResultToPreviousPage(decodeResult);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,16 +326,111 @@ public class QRCodeDecodeActivity extends Activity {
|
||||
}
|
||||
};
|
||||
|
||||
private void showDecodeResultDialog(String result) {
|
||||
ScrollView scrollView = new ScrollView(this);
|
||||
scrollView.setPadding(dip2px(16), dip2px(16), dip2px(16), dip2px(16));
|
||||
|
||||
TextView dialogTv = new TextView(this);
|
||||
dialogTv.setTextSize(16);
|
||||
dialogTv.setTextColor(getResources().getColor(android.R.color.black));
|
||||
dialogTv.setText(result);
|
||||
scrollView.addView(dialogTv);
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle("解码结果");
|
||||
builder.setView(scrollView);
|
||||
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
barcodeView.resume();
|
||||
}
|
||||
});
|
||||
builder.setCancelable(false);
|
||||
builder.show();
|
||||
}
|
||||
|
||||
private void returnResultToPreviousPage(String result) {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(EXTRA_RESULT, result);
|
||||
setResult(RESULT_OK, intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
if (requestCode == REQUEST_CAMERA_PERMISSION) {
|
||||
if (grantResults != null && grantResults.length > 0) {
|
||||
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
startScanning();
|
||||
} else {
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle("权限申请")
|
||||
.setMessage("扫码需要相机权限,请在设置中开启")
|
||||
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
finish();
|
||||
}
|
||||
})
|
||||
.setCancelable(false)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
} else if (requestCode == REQUEST_READ_STORAGE_PERMISSION) {
|
||||
if (grantResults != null && grantResults.length > 0) {
|
||||
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
openAlbum();
|
||||
} else {
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle("权限申请")
|
||||
.setMessage("从相册解码需要存储权限,请在设置中开启")
|
||||
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
})
|
||||
.setCancelable(false)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
barcodeView.resume();
|
||||
if (barcodeView != null) {
|
||||
barcodeView.resume();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
barcodeView.pause();
|
||||
if (barcodeView != null) {
|
||||
barcodeView.pause();
|
||||
}
|
||||
}
|
||||
|
||||
private int dip2px(float dpValue) {
|
||||
final float scale = getResources().getDisplayMetrics().density;
|
||||
return (int) (dpValue * scale + 0.5f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(android.view.MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private void showToast(String message) {
|
||||
android.widget.Toast.makeText(this, message, android.widget.Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
package cc.winboll.studio.apputils;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||
* @Date 2025/09/22 07:09
|
||||
* @Describe 二维码生成窗口
|
||||
*/
|
||||
import android.app.Activity;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Toast;
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.WriterException;
|
||||
import com.journeyapps.barcodescanner.BarcodeEncoder;
|
||||
|
||||
public class QRGeneratorActivity extends Activity {
|
||||
public static final String TAG = "QrGeneratorActivity";
|
||||
|
||||
// 控件引用
|
||||
private EditText etInputText;
|
||||
private ImageView ivQrPreview;
|
||||
private Button btnGenerateQr;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_qrgenerator);
|
||||
|
||||
// 初始化控件
|
||||
initViews();
|
||||
// 设置按钮点击事件
|
||||
setGenerateClickListener();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化布局控件
|
||||
*/
|
||||
private void initViews() {
|
||||
etInputText = findViewById(R.id.et_input_text);
|
||||
ivQrPreview = findViewById(R.id.iv_qr_preview);
|
||||
btnGenerateQr = findViewById(R.id.btn_generate_qr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置生成按钮点击事件:获取输入文字 → 生成二维码 → 显示到 ImageView
|
||||
*/
|
||||
private void setGenerateClickListener() {
|
||||
btnGenerateQr.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// 1. 获取输入框文字(去除前后空格)
|
||||
String inputText = etInputText.getText().toString().trim();
|
||||
|
||||
// 2. 空输入判断
|
||||
if (inputText.isEmpty()) {
|
||||
Toast.makeText(QRGeneratorActivity.this, "请先输入要生成二维码的文字", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. 生成二维码 Bitmap(宽高 500px,可调整)
|
||||
Bitmap qrBitmap = generateQrCodeBitmap(inputText, 500, 500);
|
||||
|
||||
// 4. 显示二维码到 ImageView
|
||||
if (qrBitmap != null) {
|
||||
ivQrPreview.setImageBitmap(qrBitmap);
|
||||
} else {
|
||||
Toast.makeText(QRGeneratorActivity.this, "二维码生成失败,请重试", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 核心方法:生成二维码 Bitmap
|
||||
* @param content 二维码内容(输入的文字)
|
||||
* @param width 二维码宽度(px)
|
||||
* @param height 二维码高度(px)
|
||||
* @return 生成的二维码 Bitmap,失败返回 null
|
||||
*/
|
||||
private Bitmap generateQrCodeBitmap(String content, int width, int height) {
|
||||
try {
|
||||
// 初始化二维码编码器(指定格式为 QR_CODE)
|
||||
BarcodeEncoder encoder = new BarcodeEncoder();
|
||||
// 生成二维码 Bitmap(参数:内容、格式、宽、高)
|
||||
return encoder.encodeBitmap(content, BarcodeFormat.QR_CODE, width, height);
|
||||
} catch (WriterException e) {
|
||||
// 生成失败(如内容过长、宽高非法),打印异常信息
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,19 +6,9 @@ package cc.winboll.studio.apputils;
|
||||
* @Describe WinBoLLActivity
|
||||
*/
|
||||
import android.app.Activity;
|
||||
import cc.winboll.studio.libappbase.winboll.IWinBoLLActivity;
|
||||
|
||||
public class WinBoLLActivity extends Activity implements IWinBoLLActivity {
|
||||
public class WinBoLLActivity extends Activity {
|
||||
|
||||
public static final String TAG = "WinBoLLActivity";
|
||||
|
||||
@Override
|
||||
public Activity getActivity() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTag() {
|
||||
return TAG;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,13 +54,6 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<cc.winboll.studio.libappbase.LogView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:text="Button"
|
||||
android:id="@+id/logview"
|
||||
android:layout_weight="1.0"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -1,20 +1,43 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
<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">
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="QRCodeDecodeActivity"/>
|
||||
<!-- 工具栏(原有) -->
|
||||
<Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<!-- 扫码控件(原有) -->
|
||||
<com.journeyapps.barcodescanner.DecoratedBarcodeView
|
||||
android:layout_width="wrap_content"
|
||||
android:id="@+id/activityqrcodedecodeDecoratedBarcodeView1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<!-- 新增:从相册解码按钮 -->
|
||||
<Button
|
||||
android:id="@+id/btn_decode_from_album"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/activityqrcodedecodeDecoratedBarcodeView1"/>
|
||||
android:text="从相册选图解码"
|
||||
android:textSize="16sp"
|
||||
android:textColor="@android:color/white"
|
||||
android:background="#2196F3"
|
||||
android:paddingVertical="12dp"
|
||||
android:layout_margin="16dp"/>
|
||||
|
||||
<!-- 结果显示TextView(原有) -->
|
||||
<TextView
|
||||
android:id="@+id/activityqrcodedecodeTextView1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp"
|
||||
android:text="等待扫码或选择图片..."
|
||||
android:textSize="16sp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
45
apputils/src/main/res/layout/activity_qrgenerator.xml
Normal file
45
apputils/src/main/res/layout/activity_qrgenerator.xml
Normal file
@@ -0,0 +1,45 @@
|
||||
<?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="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="20dp"
|
||||
android:gravity="top|center_horizontal">
|
||||
|
||||
<!-- 文字输入框 -->
|
||||
<EditText
|
||||
android:id="@+id/et_input_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="请输入要生成二维码的文字"
|
||||
android:inputType="textMultiLine"
|
||||
android:minLines="3"
|
||||
android:maxLines="5"
|
||||
android:padding="12dp"
|
||||
android:background="@android:drawable/editbox_background_normal"
|
||||
android:layout_marginBottom="16dp"/>
|
||||
|
||||
<!-- 生成二维码按钮 -->
|
||||
<Button
|
||||
android:id="@+id/btn_generate_qr"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="生成二维码"
|
||||
android:textSize="16sp"
|
||||
android:background="#4CAF50"
|
||||
android:textColor="@android:color/white"
|
||||
android:paddingVertical="12dp"
|
||||
android:layout_marginBottom="24dp"/>
|
||||
|
||||
<!-- 二维码预览图片 -->
|
||||
<ImageView
|
||||
android:id="@+id/iv_qr_preview"
|
||||
android:layout_width="280dp"
|
||||
android:layout_height="280dp"
|
||||
android:scaleType="fitCenter"
|
||||
android:background="@android:drawable/dialog_holo_light_frame"
|
||||
android:contentDescription="二维码预览"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/item_teststringtoqrcodeview"
|
||||
android:title="TestStringToQRCodeViewActivity"/>
|
||||
android:id="@+id/item_testqrgeneratoractivity"
|
||||
android:title="TestQRGeneratorActivity"/>
|
||||
<item
|
||||
android:id="@+id/item_testqrcodedecodeactivity"
|
||||
android:title="TestQRCodeDecodeActivity"/>
|
||||
|
||||
27
build.gradle
27
build.gradle
@@ -5,6 +5,16 @@ buildscript {
|
||||
// 设置本地Maven仓库路径
|
||||
url 'file:///sdcard/.m2/repository/'
|
||||
}
|
||||
|
||||
//米盟通过maven接入时,要做如下配置
|
||||
maven {
|
||||
url "https://repos.xiaomi.com/maven"
|
||||
credentials {
|
||||
username 'mimo-developer'
|
||||
password 'AKCp8ih1PFG9tV8qaLyws67dLGZi8udFM39SfsHgihN15cgsiRvHuxj8JzFmuZjaViVeNawaA'
|
||||
}
|
||||
}
|
||||
|
||||
// Nexus Maven 库地址
|
||||
// "WinBoLL Release"
|
||||
maven { url "https://nexus.winboll.cc/repository/maven-public/" }
|
||||
@@ -23,9 +33,6 @@ buildscript {
|
||||
//println mavenLocal().url
|
||||
//println "mavenLocal : ==========="
|
||||
//mavenLocal()
|
||||
|
||||
// WinBoLL.CC 紧急备用 Maven 仓库
|
||||
maven { url 'https://spare-maven.winboll.cc/repository/' }
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:7.2.1' // 对应 compileSdkVersion 32
|
||||
@@ -40,7 +47,15 @@ allprojects {
|
||||
// 设置本地Maven仓库路径
|
||||
url 'file:///sdcard/.m2/repository/'
|
||||
}
|
||||
|
||||
|
||||
//米盟通过maven接入时,要做如下配置
|
||||
maven {
|
||||
url "https://repos.xiaomi.com/maven"
|
||||
credentials {
|
||||
username 'mimo-developer'
|
||||
password 'AKCp8ih1PFG9tV8qaLyws67dLGZi8udFM39SfsHgihN15cgsiRvHuxj8JzFmuZjaViVeNawaA'
|
||||
}
|
||||
}
|
||||
// Nexus Maven 库地址
|
||||
// "WinBoLL Release"
|
||||
maven { url "https://nexus.winboll.cc/repository/maven-public/" }
|
||||
@@ -59,9 +74,6 @@ allprojects {
|
||||
//println mavenLocal().url
|
||||
//println "mavenLocal : ==========="
|
||||
//mavenLocal()
|
||||
|
||||
// WinBoLL.CC 紧急备用 Maven 仓库
|
||||
maven { url 'https://spare-maven.winboll.cc/repository/' }
|
||||
}
|
||||
ext {
|
||||
// 定义全局变量,常用于版本管理
|
||||
@@ -117,4 +129,3 @@ task clean(type: Delete) {
|
||||
delete rootProject.buildDir
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ def genVersionName(def versionName){
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 32
|
||||
buildToolsVersion "32.0.0"
|
||||
compileSdkVersion 30
|
||||
buildToolsVersion "30.0.3"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "cc.winboll.studio.contacts"
|
||||
@@ -66,7 +66,7 @@ dependencies {
|
||||
// 应用介绍页类库
|
||||
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'
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Sun Aug 31 06:05:42 CST 2025
|
||||
stageCount=17
|
||||
#Mon Nov 03 12:01:02 HKT 2025
|
||||
stageCount=22
|
||||
libraryProject=
|
||||
baseVersion=15.3
|
||||
publishVersion=15.3.16
|
||||
publishVersion=15.3.21
|
||||
buildCount=0
|
||||
baseBetaVersion=15.3.17
|
||||
baseBetaVersion=15.3.22
|
||||
|
||||
@@ -7,8 +7,8 @@ package cc.winboll.studio.contacts;
|
||||
*/
|
||||
import android.view.Gravity;
|
||||
import cc.winboll.studio.libappbase.GlobalApplication;
|
||||
import cc.winboll.studio.libappbase.utils.ToastUtils;
|
||||
import cc.winboll.studio.libappbase.winboll.WinBoLLActivityManager;
|
||||
import com.hjq.toast.ToastUtils;
|
||||
|
||||
public class App extends GlobalApplication {
|
||||
|
||||
@@ -30,7 +30,7 @@ public class App extends GlobalApplication {
|
||||
// 设置 Toast 布局样式
|
||||
//ToastUtils.setView(R.layout.toast_custom_view);
|
||||
//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.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
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.LogFragment;
|
||||
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.LogView;
|
||||
import cc.winboll.studio.libappbase.utils.ToastUtils;
|
||||
import cc.winboll.studio.libappbase.winboll.IWinBoLLActivity;
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
import java.util.ArrayList;
|
||||
@@ -48,10 +51,9 @@ import java.util.List;
|
||||
final public class MainActivity extends AppCompatActivity implements IWinBoLLActivity, ViewPager.OnPageChangeListener, View.OnClickListener {
|
||||
|
||||
public static final String TAG = "MainActivity";
|
||||
|
||||
public static final int REQUEST_HOME_ACTIVITY = 0;
|
||||
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";
|
||||
|
||||
static MainActivity _MainActivity;
|
||||
@@ -72,6 +74,13 @@ final public class MainActivity extends AppCompatActivity implements IWinBoLLAct
|
||||
List<String> tabTitleList;
|
||||
|
||||
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
|
||||
@@ -88,9 +97,88 @@ final public class MainActivity extends AppCompatActivity implements IWinBoLLAct
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
_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);
|
||||
|
||||
// 初始化工具栏(仅加载基础UI)
|
||||
mToolbar = (Toolbar) findViewById(R.id.activitymainToolbar1);
|
||||
setSupportActionBar(mToolbar);
|
||||
getSupportActionBar().setSubtitle(TAG);
|
||||
@@ -98,34 +186,28 @@ final public class MainActivity extends AppCompatActivity implements IWinBoLLAct
|
||||
tabLayout = (TabLayout) findViewById(R.id.tabLayout);
|
||||
viewPager = (ViewPager) findViewById(R.id.viewPager);
|
||||
|
||||
// 创建Fragment列表(仅实例化,不加载数据)
|
||||
fragmentList = new ArrayList<Fragment>();
|
||||
tabTitleList = new ArrayList<String>();
|
||||
// CallLogFragment 仅在权限通过后才实例化(避免提前触发读取)
|
||||
fragmentList.add(CallLogFragment.newInstance(0));
|
||||
fragmentList.add(ContactsFragment.newInstance(1)); // 延迟加载联系人数据
|
||||
fragmentList.add(ContactsFragment.newInstance(1));
|
||||
fragmentList.add(LogFragment.newInstance(2));
|
||||
tabTitleList.add("通话记录");
|
||||
tabTitleList.add("联系人");
|
||||
tabTitleList.add("应用日志");
|
||||
|
||||
// 设置ViewPager适配器
|
||||
MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager(), fragmentList, tabTitleList);
|
||||
viewPager.setAdapter(adapter);
|
||||
|
||||
// 关键:关闭预加载,仅当前页初始化
|
||||
viewPager.setOffscreenPageLimit(0);
|
||||
|
||||
// 关联TabLayout和ViewPager
|
||||
viewPager.setOffscreenPageLimit(0); // 关闭预加载,避免提前初始化 CallLogFragment
|
||||
tabLayout.setupWithViewPager(viewPager);
|
||||
|
||||
// 初始化服务状态(延迟启动非核心服务)
|
||||
// 原有服务启动、电话监听等逻辑...
|
||||
MainServiceBean mMainServiceBean = MainServiceBean.loadBean(this, MainServiceBean.class);
|
||||
if (mMainServiceBean == null) {
|
||||
mMainServiceBean = new MainServiceBean();
|
||||
MainServiceBean.saveBean(this, mMainServiceBean);
|
||||
}
|
||||
if (mMainServiceBean.isEnable()) {
|
||||
// 延迟1秒启动服务,避免阻塞启动
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -134,16 +216,14 @@ final public class MainActivity extends AppCompatActivity implements IWinBoLLAct
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
// 初始化电话状态监听(基础功能保留)
|
||||
telephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
|
||||
phoneStateListener = new MyPhoneStateListener();
|
||||
telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
|
||||
}
|
||||
|
||||
|
||||
// ViewPager适配器(Java 7语法)
|
||||
// 以下为原有代码(无需修改)
|
||||
private class MyPagerAdapter extends FragmentPagerAdapter {
|
||||
|
||||
private List<Fragment> fragmentList;
|
||||
private List<String> tabTitleList;
|
||||
|
||||
@@ -173,21 +253,18 @@ final public class MainActivity extends AppCompatActivity implements IWinBoLLAct
|
||||
Intent intent = new Intent(Intent.ACTION_DIAL);
|
||||
intent.setData(android.net.Uri.parse("tel:" + phoneNumber));
|
||||
if (ActivityCompat.checkSelfPermission(_MainActivity, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
|
||||
Toast.makeText(_MainActivity, "拨号权限不足", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
_MainActivity.startActivity(intent);
|
||||
}
|
||||
|
||||
// OnPageChangeListener接口实现
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {}
|
||||
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {}
|
||||
|
||||
@@ -239,9 +316,6 @@ final public class MainActivity extends AppCompatActivity implements IWinBoLLAct
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否是系统默认电话应用
|
||||
*/
|
||||
public boolean isDefaultPhoneCallApp() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
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.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.views.DuInfoTextView;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.utils.ToastUtils;
|
||||
import cc.winboll.studio.libappbase.winboll.IWinBoLLActivity;
|
||||
import com.hjq.toast.ToastUtils;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
|
||||
@@ -263,7 +263,7 @@ public class SettingsActivity extends AppCompatActivity implements IWinBoLLActiv
|
||||
@Override
|
||||
public void run() {
|
||||
if (tomCat.downloadBoBullToon()) {
|
||||
ToastUtils.show("BoBullToon downlaod OK!");
|
||||
LogUtils.d(TAG, "BoBullToon downlaod OK!");
|
||||
MainService.restartMainService(SettingsActivity.this);
|
||||
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.utils.ContactUtils;
|
||||
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.util.List;
|
||||
import java.util.Locale;
|
||||
@@ -76,6 +76,9 @@ public class CallLogAdapter extends RecyclerView.Adapter<CallLogAdapter.CallLogV
|
||||
// Set the clipboard's primary clip.
|
||||
clipboard.setPrimaryClip(clip);
|
||||
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;
|
||||
|
||||
@@ -21,8 +21,9 @@ import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import cc.winboll.studio.contacts.R;
|
||||
import cc.winboll.studio.contacts.beans.ContactModel;
|
||||
import cc.winboll.studio.contacts.utils.ContactUtils;
|
||||
import cc.winboll.studio.libaes.views.AOHPCTCSeekBar;
|
||||
import com.hjq.toast.ToastUtils;
|
||||
import cc.winboll.studio.libappbase.utils.ToastUtils;
|
||||
import java.util.List;
|
||||
|
||||
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.
|
||||
clipboard.setPrimaryClip(clip);
|
||||
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;
|
||||
@@ -112,7 +118,7 @@ public class ContactAdapter extends RecyclerView.Adapter<ContactAdapter.ContactV
|
||||
TextView contactName;
|
||||
TextView contactNumber;
|
||||
AOHPCTCSeekBar dialAOHPCTCSeekBar;
|
||||
|
||||
|
||||
public ContactViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
llPhoneNumberMain = itemView.findViewById(R.id.itemcontactLinearLayout1);
|
||||
|
||||
@@ -7,7 +7,6 @@ package cc.winboll.studio.contacts.adapters;
|
||||
*/
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
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.dun.Rules;
|
||||
import cc.winboll.studio.contacts.views.LeftScrollView;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
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.List;
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import android.content.Context;
|
||||
import cc.winboll.studio.contacts.R;
|
||||
import cc.winboll.studio.contacts.dun.Rules;
|
||||
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.FileFilter;
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
@@ -25,7 +25,6 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
import cc.winboll.studio.contacts.R;
|
||||
import cc.winboll.studio.contacts.adapters.CallLogAdapter;
|
||||
import cc.winboll.studio.contacts.beans.CallLogModel;
|
||||
import com.hjq.toast.ToastUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -161,7 +160,7 @@ public class CallLogFragment extends Fragment {
|
||||
_CallLogFragment.triggerUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void 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.beans.ContactModel;
|
||||
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.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -95,7 +95,7 @@ public class ContactsFragment extends Fragment {
|
||||
recyclerView = (RecyclerView) view.findViewById(R.id.contacts_recycler_view);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
contactList = new ArrayList<ContactModel>();
|
||||
contactAdapter = new ContactAdapter(getContext(), contactList);
|
||||
contactAdapter = new ContactAdapter(getActivity(), contactList);
|
||||
recyclerView.setAdapter(contactAdapter);
|
||||
// 初始隐藏列表,数据加载后显示
|
||||
recyclerView.setVisibility(View.GONE);
|
||||
|
||||
@@ -14,7 +14,6 @@ import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import cc.winboll.studio.contacts.R;
|
||||
import cc.winboll.studio.libappbase.LogView;
|
||||
import com.hjq.toast.ToastUtils;
|
||||
|
||||
public class LogFragment extends Fragment {
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import cc.winboll.studio.contacts.services.MainService;
|
||||
import com.hjq.toast.ToastUtils;
|
||||
import cc.winboll.studio.libappbase.utils.ToastUtils;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
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 联系人工具集
|
||||
*/
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentUris;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.provider.ContactsContract;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.utils.ToastUtils;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -120,4 +124,92 @@ public class ContactUtils {
|
||||
}
|
||||
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.widget.RemoteViews;
|
||||
import cc.winboll.studio.contacts.R;
|
||||
import cc.winboll.studio.contacts.threads.MainServiceThread;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import com.hjq.toast.ToastUtils;
|
||||
import cc.winboll.studio.libappbase.utils.ToastUtils;
|
||||
|
||||
public class APPStatusWidget extends AppWidgetProvider {
|
||||
|
||||
|
||||
@@ -5,5 +5,8 @@
|
||||
<item
|
||||
android:id="@+id/item_calllog_phonenumber_copy"
|
||||
android:title="Copy"/>
|
||||
<item
|
||||
android:id="@+id/item_calllog_phonenumber_add_contact"
|
||||
android:title="Add Contact"/>
|
||||
|
||||
</menu>
|
||||
|
||||
@@ -5,5 +5,8 @@
|
||||
<item
|
||||
android:id="@+id/item_contact_phonenumber_copy"
|
||||
android:title="Copy"/>
|
||||
<item
|
||||
android:id="@+id/item_calllog_phonenumber_edit_contact"
|
||||
android:title="Edit Contact"/>
|
||||
|
||||
</menu>
|
||||
|
||||
@@ -4,29 +4,32 @@ apply from: '../.winboll/winboll_lib_build.gradle'
|
||||
apply from: '../.winboll/winboll_lint_build.gradle'
|
||||
|
||||
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 {
|
||||
minSdkVersion 24
|
||||
minSdkVersion 23
|
||||
targetSdkVersion 30
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
// 米盟 SDK
|
||||
packagingOptions {
|
||||
doNotStrip "*/*/libmimo_1011.so"
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
api 'com.github.getActivity:XXPermissions:18.63'
|
||||
// 下拉控件
|
||||
@@ -52,4 +55,17 @@ dependencies {
|
||||
//api 'androidx.vectordrawable:vectordrawable:1.1.0'
|
||||
//api 'androidx.vectordrawable:vectordrawable-animated: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
|
||||
#Sun Aug 31 05:00:43 CST 2025
|
||||
stageCount=4
|
||||
#Wed Nov 26 15:54:26 GMT 2025
|
||||
stageCount=7
|
||||
libraryProject=libaes
|
||||
baseVersion=15.9
|
||||
publishVersion=15.9.3
|
||||
buildCount=0
|
||||
baseBetaVersion=15.9.4
|
||||
baseVersion=15.11
|
||||
publishVersion=15.11.6
|
||||
buildCount=32
|
||||
baseBetaVersion=15.11.7
|
||||
|
||||
@@ -1,9 +1,25 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<manifest
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
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
|
||||
android:name="cc.winboll.studio.libaes.unittests.SecondaryLibraryActivity"
|
||||
@@ -33,6 +49,18 @@
|
||||
android:name="cc.winboll.studio.libaes.winboll.WinBoLLMail"
|
||||
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>
|
||||
|
||||
</manifest>
|
||||
</manifest>
|
||||
|
||||
@@ -23,17 +23,19 @@ import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import cc.winboll.studio.libaes.DrawerMenuDataAdapter;
|
||||
import cc.winboll.studio.libaes.R;
|
||||
import cc.winboll.studio.libaes.beans.AESThemeBean;
|
||||
import cc.winboll.studio.libaes.beans.DrawerMenuBean;
|
||||
import cc.winboll.studio.libaes.models.AESThemeBean;
|
||||
import cc.winboll.studio.libaes.models.DrawerMenuBean;
|
||||
import cc.winboll.studio.libaes.utils.AESThemeUtil;
|
||||
import cc.winboll.studio.libaes.views.ADrawerMenuListView;
|
||||
import cc.winboll.studio.libappbase.GlobalApplication;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.winboll.IWinBoLLActivity;
|
||||
import com.baoyz.widget.PullRefreshLayout;
|
||||
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";
|
||||
|
||||
@@ -72,17 +74,22 @@ public abstract class DrawerFragmentActivity extends AppCompatActivity implement
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
// 修复:释放广告资源,避免内存泄漏
|
||||
ADsBannerView adsBannerView = findViewById(R.id.adsbanner);
|
||||
if (adsBannerView != null) {
|
||||
adsBannerView.releaseAdResources();
|
||||
}
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public Intent getIntent() {
|
||||
// TODO: Implement this method
|
||||
return super.getIntent();
|
||||
}
|
||||
public Intent getIntent() {
|
||||
// TODO: Implement this method
|
||||
return super.getIntent();
|
||||
}
|
||||
|
||||
public Context getContext() {
|
||||
return this.mContext;
|
||||
}*/
|
||||
public Context getContext() {
|
||||
return this.mContext;
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public MenuInflater getMenuInflater() {
|
||||
@@ -91,9 +98,9 @@ public abstract class DrawerFragmentActivity extends AppCompatActivity implement
|
||||
}
|
||||
|
||||
/*public void setSubtitle(CharSequence context) {
|
||||
// TODO: Implement this method
|
||||
getSupportActionBar().setSubtitle(context);
|
||||
}*/
|
||||
// TODO: Implement this method
|
||||
getSupportActionBar().setSubtitle(context);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void recreate() {
|
||||
@@ -101,9 +108,9 @@ public abstract class DrawerFragmentActivity extends AppCompatActivity implement
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public boolean moveTaskToBack(boolean nonRoot) {
|
||||
return super.moveTaskToBack(nonRoot);
|
||||
}*/
|
||||
public boolean moveTaskToBack(boolean nonRoot) {
|
||||
return super.moveTaskToBack(nonRoot);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void startActivity(Intent intent) {
|
||||
@@ -116,24 +123,24 @@ public abstract class DrawerFragmentActivity extends AppCompatActivity implement
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public FragmentManager getSupportFragmentManager() {
|
||||
return super.getSupportFragmentManager();
|
||||
}
|
||||
public FragmentManager getSupportFragmentManager() {
|
||||
return super.getSupportFragmentManager();
|
||||
}
|
||||
|
||||
public void setSubtitle(int resId) {
|
||||
// TODO: Implement this method
|
||||
getSupportActionBar().setSubtitle(resId);
|
||||
}
|
||||
public void setSubtitle(int resId) {
|
||||
// TODO: Implement this method
|
||||
getSupportActionBar().setSubtitle(resId);
|
||||
}
|
||||
|
||||
public void setTitle(CharSequence context) {
|
||||
// TODO: Implement this method
|
||||
getSupportActionBar().setTitle(context);
|
||||
}
|
||||
public void setTitle(CharSequence context) {
|
||||
// TODO: Implement this method
|
||||
getSupportActionBar().setTitle(context);
|
||||
}
|
||||
|
||||
public void setTitle(int resId) {
|
||||
// TODO: Implement this method
|
||||
getSupportActionBar().setTitle(resId);
|
||||
}*/
|
||||
public void setTitle(int resId) {
|
||||
// TODO: Implement this method
|
||||
getSupportActionBar().setTitle(resId);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
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++) {
|
||||
getString(i);
|
||||
}
|
||||
// } else if (R.id.item_log == item.getItemId()) {
|
||||
// GlobalApplication.getWinBoLLActivityManager().startLogActivity(this);
|
||||
} else if (R.id.item_log == item.getItemId()) {
|
||||
ToastUtils.show("Test");
|
||||
LogActivity.startLogActivity(this);
|
||||
} else if (R.id.item_about == item.getItemId()) {
|
||||
LogUtils.d(TAG, "onAbout");
|
||||
} else if (android.R.id.home == item.getItemId()) {
|
||||
@@ -192,6 +200,11 @@ public abstract class DrawerFragmentActivity extends AppCompatActivity implement
|
||||
if (checkThemeStyleChange()) {
|
||||
recreate();
|
||||
}
|
||||
|
||||
ADsBannerView adsBannerView = findViewById(R.id.adsbanner);
|
||||
if (adsBannerView != null) {
|
||||
adsBannerView.resumeADs(DrawerFragmentActivity.this);
|
||||
}
|
||||
}
|
||||
|
||||
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>
|
||||
@@ -1,4 +1,4 @@
|
||||
package cc.winboll.studio.libaes.winboll;
|
||||
package cc.winboll.studio.libaes.models;
|
||||
|
||||
/**
|
||||
* @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>
|
||||
@@ -1,4 +1,4 @@
|
||||
package cc.winboll.studio.libaes.beans;
|
||||
package cc.winboll.studio.libaes.models;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen
|
||||
@@ -7,7 +7,7 @@ import android.view.MenuItem;
|
||||
import android.widget.Toast;
|
||||
import cc.winboll.studio.libaes.R;
|
||||
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>
|
||||
|
||||
@@ -13,7 +13,7 @@ import androidx.fragment.app.Fragment;
|
||||
import cc.winboll.studio.libaes.R;
|
||||
import cc.winboll.studio.libaes.views.AButton;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import com.hjq.toast.ToastUtils;
|
||||
import cc.winboll.studio.libappbase.ToastUtils;
|
||||
|
||||
public class TestAButtonFragment extends Fragment {
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@ import android.os.Bundle;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import cc.winboll.studio.libaes.R;
|
||||
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
|
||||
import cc.winboll.studio.libaes.utils.AESThemeUtil;
|
||||
import cc.winboll.studio.libappbase.winboll.IWinBoLLActivity;
|
||||
|
||||
public class TestASupportToolbarActivity extends AppCompatActivity implements IWinBoLLActivity {
|
||||
|
||||
|
||||
@@ -10,22 +10,11 @@ import android.os.Bundle;
|
||||
import android.widget.Toolbar;
|
||||
import cc.winboll.studio.libaes.R;
|
||||
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";
|
||||
|
||||
@Override
|
||||
public Activity getActivity() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
AESThemeUtil.applyAppTheme(this);
|
||||
|
||||
@@ -14,9 +14,9 @@ import android.widget.Toast;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import cc.winboll.studio.libaes.R;
|
||||
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.winboll.IWinBoLLActivity;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class TestDrawerFragmentActivity extends DrawerFragmentActivity implements IWinBoLLActivity {
|
||||
|
||||
@@ -12,14 +12,13 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Toast;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
import cc.winboll.studio.libaes.ImagePagerAdapter;
|
||||
import cc.winboll.studio.libaes.R;
|
||||
import cc.winboll.studio.libaes.views.AOHPCTCSeekBar;
|
||||
import cc.winboll.studio.libappbase.LogView;
|
||||
import com.hjq.toast.ToastUtils;
|
||||
import cc.winboll.studio.libappbase.ToastUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import android.view.MenuItem;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import cc.winboll.studio.libaes.R;
|
||||
import cc.winboll.studio.libaes.activitys.DrawerFragmentActivity;
|
||||
import cc.winboll.studio.libaes.beans.AESThemeBean;
|
||||
import cc.winboll.studio.libaes.models.AESThemeBean;
|
||||
|
||||
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>
|
||||
@@ -12,17 +12,18 @@ import android.content.res.TypedArray;
|
||||
import android.net.Uri;
|
||||
import android.os.Message;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
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.PrefUtils;
|
||||
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
|
||||
import cc.winboll.studio.libappbase.GlobalApplication;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.dialogs.YesNoAlertDialog;
|
||||
import cc.winboll.studio.libapputils.utils.PrefUtils;
|
||||
import com.hjq.toast.ToastUtils;
|
||||
import cc.winboll.studio.libappbase.ToastUtils;
|
||||
import java.io.IOException;
|
||||
import mehdi.sakout.aboutpage.AboutPage;
|
||||
import mehdi.sakout.aboutpage.Element;
|
||||
@@ -32,7 +33,6 @@ import okhttp3.Credentials;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import mehdi.sakout.aboutpage.BuildConfig;
|
||||
|
||||
public class AboutView extends LinearLayout {
|
||||
|
||||
@@ -40,10 +40,10 @@ public class AboutView extends LinearLayout {
|
||||
|
||||
public static final int MSG_APPUPDATE_CHECKED = 0;
|
||||
|
||||
Context mContext;
|
||||
static Context _mContext;
|
||||
APPInfo mAPPInfo;
|
||||
|
||||
WinBoLLServiceStatusView mWinBoLLServiceStatusView;
|
||||
//WinBoLLServiceStatusView mWinBoLLServiceStatusView;
|
||||
OnRequestDevUserInfoAutofillListener mOnRequestDevUserInfoAutofillListener;
|
||||
String mszAppName = "";
|
||||
String mszAppAPKFolderName = "";
|
||||
@@ -64,7 +64,7 @@ public class AboutView extends LinearLayout {
|
||||
|
||||
public AboutView(Context context, APPInfo appInfo) {
|
||||
super(context);
|
||||
mContext = context;
|
||||
_mContext = context;
|
||||
|
||||
setAPPInfo(appInfo);
|
||||
initView(context);
|
||||
@@ -72,7 +72,7 @@ public class AboutView extends LinearLayout {
|
||||
|
||||
public AboutView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
mContext = context;
|
||||
_mContext = context;
|
||||
|
||||
initView(context, attrs);
|
||||
}
|
||||
@@ -107,10 +107,10 @@ public class AboutView extends LinearLayout {
|
||||
mszAppDescription = mAPPInfo.getAppDescription();
|
||||
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 {
|
||||
mszAppVersionName = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0).versionName;
|
||||
mszAppVersionName = _mContext.getPackageManager().getPackageInfo(_mContext.getPackageName(), 0).versionName;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||
}
|
||||
@@ -122,35 +122,8 @@ public class AboutView extends LinearLayout {
|
||||
} else {
|
||||
mszGitea = "https://gitea.winboll.cc/" + mAPPInfo.getAppGitOwner() + "/" + mszAppGitName + "/src/branch/" + mAPPInfo.getAppGitAPPBranch() + "/" + mAPPInfo.getAppGitAPPSubProjectFolder();
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
addView(createAboutPage());
|
||||
|
||||
// 初始化标题栏
|
||||
//setSubtitle(getContext().getString(R.string.text_about));
|
||||
@@ -162,9 +135,9 @@ public class AboutView extends LinearLayout {
|
||||
String szReleaseAppVersionName = "";
|
||||
try {
|
||||
//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));
|
||||
szReleaseAppVersionName = mContext.getPackageManager().getPackageInfo(szSubBetaSuffix, 0).versionName;
|
||||
szReleaseAppVersionName = _mContext.getPackageManager().getPackageInfo(szSubBetaSuffix, 0).versionName;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||
}
|
||||
@@ -205,7 +178,7 @@ public class AboutView extends LinearLayout {
|
||||
String szMsg = "Current app is :\n[ " + mszCurrentAppPackageName
|
||||
+ " ]\nThe last app is :\n[ " + mszNewestAppPackageName
|
||||
+ " ]\nIs download the last app?";
|
||||
YesNoAlertDialog.show(mContext, "Application Update Prompt", szMsg, mIsDownlaodUpdateListener);
|
||||
YesNoAlertDialog.show(_mContext, "Application Update Prompt", szMsg, mIsDownlaodUpdateListener);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -216,22 +189,23 @@ public class AboutView extends LinearLayout {
|
||||
protected View createAboutPage() {
|
||||
// 定义 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);
|
||||
// 定义检查更新按钮
|
||||
//
|
||||
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);
|
||||
*/
|
||||
|
||||
String szAppInfo = "";
|
||||
try {
|
||||
szAppInfo = mszAppName + " "
|
||||
+ mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0).versionName
|
||||
+ _mContext.getPackageManager().getPackageInfo(_mContext.getPackageName(), 0).versionName
|
||||
+ "\n" + mszAppDescription;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||
}
|
||||
AboutPage aboutPage = new AboutPage(mContext);
|
||||
AboutPage aboutPage = new AboutPage(_mContext);
|
||||
aboutPage.setDescription(szAppInfo)
|
||||
//.isRTL(false)
|
||||
//.setCustomFont(String) // or Typeface
|
||||
@@ -241,8 +215,8 @@ public class AboutView extends LinearLayout {
|
||||
//.addGroup("Connect with us")
|
||||
.addEmail("ZhanGSKen<zhangsken@qq.com>")
|
||||
.addWebsite(mszHomePage)
|
||||
.addItem(elementGitWeb)
|
||||
.addItem(elementAppUpdate);
|
||||
.addItem(elementGitWeb);
|
||||
//.addItem(elementAppUpdate);
|
||||
//.addFacebook("the.medy")
|
||||
//.addTwitter("medyo80")
|
||||
//.addYoutube("UCdPQtdWIsg7_pi4mrRu46vA")
|
||||
@@ -251,19 +225,19 @@ public class AboutView extends LinearLayout {
|
||||
//.addInstagram("medyo80")
|
||||
//.create();
|
||||
|
||||
if (mAPPInfo.isAddDebugTools()) {
|
||||
/*if (mAPPInfo.isAddDebugTools()) {
|
||||
// 定义应用调试按钮
|
||||
//
|
||||
Element elementAppMode;
|
||||
if (GlobalApplication.isDebuging()) {
|
||||
elementAppMode = new Element(mContext.getString(R.string.app_normal), R.drawable.ic_winboll);
|
||||
if (GlobalApplication.isDebugging()) {
|
||||
elementAppMode = new Element(_mContext.getString(R.string.app_normal), R.drawable.ic_winboll);
|
||||
elementAppMode.setOnClickListener(mAppNormalOnClickListener);
|
||||
} 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);
|
||||
}
|
||||
aboutPage.addItem(elementAppMode);
|
||||
}
|
||||
}*/
|
||||
|
||||
return aboutPage.create();
|
||||
}
|
||||
@@ -272,7 +246,7 @@ public class AboutView extends LinearLayout {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
//ToastUtils.show("mAppDebugOnClickListener");
|
||||
setApp2DebugMode(mContext);
|
||||
setApp2DebugMode(_mContext);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -280,7 +254,7 @@ public class AboutView extends LinearLayout {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
//ToastUtils.show("mAppNormalOnClickListener");
|
||||
setApp2NormalMode(mContext);
|
||||
setApp2NormalMode(_mContext);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -289,10 +263,10 @@ public class AboutView extends LinearLayout {
|
||||
if (intent != null) {
|
||||
//intent.setAction(cc.winboll.studio.libapputils.intent.action.DEBUGVIEW);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
GlobalApplication.setIsDebuging(true);
|
||||
GlobalApplication.saveDebugStatus();
|
||||
GlobalApplication.setIsDebugging(true);
|
||||
GlobalApplication.saveDebugStatus((GlobalApplication)_mContext.getApplicationContext());
|
||||
|
||||
GlobalApplication.getWinBoLLActivityManager().finishAll();
|
||||
WinBoLLActivityManager.getInstance().finishAll();
|
||||
context.startActivity(intent);
|
||||
}
|
||||
}
|
||||
@@ -301,10 +275,10 @@ public class AboutView extends LinearLayout {
|
||||
Intent intent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
|
||||
if (intent != null) {
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
GlobalApplication.setIsDebuging(false);
|
||||
GlobalApplication.saveDebugStatus();
|
||||
GlobalApplication.setIsDebugging(false);
|
||||
GlobalApplication.saveDebugStatus((GlobalApplication)_mContext.getApplicationContext());
|
||||
|
||||
GlobalApplication.getWinBoLLActivityManager().finishAll();
|
||||
WinBoLLActivityManager.getInstance().finishAll();
|
||||
context.startActivity(intent);
|
||||
}
|
||||
}
|
||||
@@ -313,7 +287,7 @@ public class AboutView extends LinearLayout {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
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 credential = "";
|
||||
if (GlobalApplication.isDebuging()) {
|
||||
if (GlobalApplication.isDebugging()) {
|
||||
credential = Credentials.basic(metDevUserName.getText().toString(), metDevUserPassword.getText().toString());
|
||||
PrefUtils.saveString(mContext, "metDevUserName", metDevUserName.getText().toString());
|
||||
PrefUtils.saveString(mContext, "metDevUserPassword", metDevUserPassword.getText().toString());
|
||||
PrefUtils.saveString(_mContext, "metDevUserName", metDevUserName.getText().toString());
|
||||
PrefUtils.saveString(_mContext, "metDevUserPassword", metDevUserPassword.getText().toString());
|
||||
} else {
|
||||
String username = "WinBoLL";
|
||||
String password = "WinBoLLPowerByZhanGSKen";
|
||||
@@ -387,7 +361,7 @@ public class AboutView extends LinearLayout {
|
||||
public void onYes() {
|
||||
String szUrl = mszWinBoLLServerHost + "/studio/download.php?appname=" + mszAppAPKFolderName + "&apkname=" + mszNewestAppPackageName;
|
||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(szUrl));
|
||||
mContext.startActivity(browserIntent);
|
||||
_mContext.startActivity(browserIntent);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -10,7 +10,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/activitydrawerfragmentASupportToolbar1"/>
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
@@ -19,7 +19,8 @@
|
||||
|
||||
<androidx.drawerlayout.widget.DrawerLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1.0"
|
||||
android:id="@+id/activitydrawerfragmentDrawerLayout1">
|
||||
|
||||
<FrameLayout
|
||||
@@ -52,7 +53,13 @@
|
||||
|
||||
</androidx.drawerlayout.widget.DrawerLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<cc.winboll.studio.libaes.views.ADsBannerView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/adsbanner"/>
|
||||
|
||||
</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_MemorTheme">MemorTheme</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>
|
||||
|
||||
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 {
|
||||
|
||||
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 {
|
||||
minSdkVersion 24
|
||||
minSdkVersion 23
|
||||
targetSdkVersion 30
|
||||
}
|
||||
buildTypes {
|
||||
@@ -22,9 +25,4 @@ android {
|
||||
|
||||
dependencies {
|
||||
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
|
||||
#Sat Sep 27 21:03:08 HKT 2025
|
||||
stageCount=10
|
||||
#Sun Nov 30 17:12:48 HKT 2025
|
||||
stageCount=7
|
||||
libraryProject=libappbase
|
||||
baseVersion=15.10
|
||||
publishVersion=15.10.9
|
||||
baseVersion=15.11
|
||||
publishVersion=15.11.6
|
||||
buildCount=0
|
||||
baseBetaVersion=15.10.10
|
||||
baseBetaVersion=15.11.7
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="cc.winboll.studio.libappbase">
|
||||
|
||||
<application>
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
|
||||
<application>
|
||||
<activity
|
||||
android:name=".CrashHandler$CrashActivity"
|
||||
android:label="CrashActivity"
|
||||
@@ -28,6 +29,22 @@
|
||||
|
||||
</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>
|
||||
|
||||
</manifest>
|
||||
|
||||
@@ -1,73 +1,138 @@
|
||||
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.JsonWriter;
|
||||
import cc.winboll.studio.libappbase.BaseBean;
|
||||
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 static final String TAG = "APPModel";
|
||||
|
||||
// 应用是否处于正在调试状态
|
||||
//
|
||||
boolean isDebuging = false;
|
||||
/**
|
||||
* 应用调试状态标识
|
||||
* true:应用处于调试模式(可输出详细日志、启用调试功能等)
|
||||
* false:应用处于正式模式(关闭调试相关功能,优化性能)
|
||||
*/
|
||||
private boolean isDebugging = false; // 修正拼写:原 isDebuging -> isDebugging(符合命名规范)
|
||||
|
||||
/**
|
||||
* 无参构造方法
|
||||
* 初始化调试状态为默认值:false(正式模式)
|
||||
*/
|
||||
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
|
||||
public String getName() {
|
||||
return APPModel.class.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* 重写父类方法,将当前模型的字段序列化到 JSON 中
|
||||
* 用于将调试状态等核心数据转换为 JSON 格式(如持久化到文件、网络传输)
|
||||
* @param jsonWriter JSON 写入器对象,用于输出 JSON 数据
|
||||
* @throws IOException 当 JSON 写入失败时抛出(如流关闭、格式错误)
|
||||
*/
|
||||
@Override
|
||||
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
|
||||
// 先调用父类方法,序列化父类中的字段(若 BaseBean 有可序列化字段)
|
||||
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
|
||||
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")) {
|
||||
setIsDebuging(jsonReader.nextBoolean());
|
||||
// 读取 JSON 中 "isDebuging" 字段的值,设置为当前对象的调试状态
|
||||
setIsDebugging(jsonReader.nextBoolean());
|
||||
} else {
|
||||
// 字段不属于当前类,返回 false 提示调用者跳过该字段
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// 字段解析成功,返回 true
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重写父类方法,从 JSON 读取器中完整解析一个 APPModel 实例
|
||||
* 负责处理 JSON 对象的开始/结束标记,循环解析所有字段
|
||||
* @param jsonReader JSON 读取器对象,用于读取 JSON 数据
|
||||
* @return 解析完成的当前 APPModel 实例(支持链式调用)
|
||||
* @throws IOException 当 JSON 读取失败时抛出(如流关闭、数据格式错误)
|
||||
*/
|
||||
@Override
|
||||
public BaseBean readBeanFromJsonReader(JsonReader jsonReader) throws IOException {
|
||||
// 开始解析 JSON 对象(对应 JSON 中的 '{')
|
||||
jsonReader.beginObject();
|
||||
// 循环读取 JSON 中的所有字段(直到对象结束)
|
||||
while (jsonReader.hasNext()) {
|
||||
// 获取当前字段名
|
||||
String name = jsonReader.nextName();
|
||||
// 解析字段:若当前类无法处理该字段,则跳过(避免解析异常)
|
||||
if (!initObjectsFromJsonReader(jsonReader, name)) {
|
||||
jsonReader.skipValue();
|
||||
}
|
||||
}
|
||||
// 结束 JSON 对象
|
||||
// 结束解析 JSON 对象(对应 JSON 中的 '}')
|
||||
jsonReader.endObject();
|
||||
// 返回解析完成的实例(当前对象)
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
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.util.JsonReader;
|
||||
import android.util.JsonWriter;
|
||||
@@ -14,274 +9,428 @@ import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
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 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) {
|
||||
StringBuilder sbResult = new StringBuilder();
|
||||
String szErrorInfo = "Check Is The Same Bean List And File Error : ";
|
||||
// 反射创建目标 Bean 实例(用于获取类名)
|
||||
T beanTemp = clazz.newInstance();
|
||||
String targetBeanName = beanTemp.getName();
|
||||
// 读取文件中的 JSON 字符串
|
||||
String listJson = UTF8FileUtils.readStringFromFile(szFilePath);
|
||||
StringReader stringReader = new StringReader(listJson);
|
||||
JsonReader jsonReader = new JsonReader(stringReader);
|
||||
|
||||
try {
|
||||
int nSameCount = 0;
|
||||
int nBeanListCout = 0;
|
||||
jsonReader.beginArray(); // 开始解析 JSON 数组(Bean 列表)
|
||||
while (jsonReader.hasNext()) {
|
||||
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();
|
||||
String szListJson = UTF8FileUtils.readStringFromFile(szFilePath);
|
||||
StringReader stringReader = new StringReader(szListJson);
|
||||
JsonReader jsonReader = new JsonReader(stringReader);
|
||||
jsonReader.beginArray();
|
||||
while (jsonReader.hasNext()) {
|
||||
nBeanListCout++;
|
||||
jsonReader.beginObject();
|
||||
while (jsonReader.hasNext()) {
|
||||
String name = jsonReader.nextName();
|
||||
if (name.equals(BEAN_NAME)) {
|
||||
if (szBeanSimpleName.equals(jsonReader.nextString())) {
|
||||
nSameCount++;
|
||||
}
|
||||
} else {
|
||||
jsonReader.skipValue();
|
||||
}
|
||||
}
|
||||
jsonReader.endObject();
|
||||
}
|
||||
jsonReader.endArray();
|
||||
// 生成校验结果
|
||||
if (sameCount == totalCount) {
|
||||
return ""; // 全部匹配,返回空串
|
||||
} else {
|
||||
// 部分不匹配,返回统计信息
|
||||
sbResult.append("Total : ").append(totalCount)
|
||||
.append(" Diff : ").append(totalCount - sameCount);
|
||||
}
|
||||
} catch (InstantiationException e) {
|
||||
// 反射实例化失败(如无无参构造)
|
||||
sbResult.append(szErrorInfo).append(e);
|
||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||
} catch (IllegalAccessException e) {
|
||||
// 反射访问权限异常
|
||||
sbResult.append(szErrorInfo).append(e);
|
||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||
} catch (IOException e) {
|
||||
// 文件读取或 JSON 解析异常
|
||||
sbResult.append(szErrorInfo).append(e);
|
||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||
}
|
||||
return sbResult.toString();
|
||||
}
|
||||
|
||||
// 返回检查结果
|
||||
if (nSameCount == nBeanListCout) {
|
||||
// 检查一致直接返回空串
|
||||
return "";
|
||||
} else {
|
||||
// 检查不一致返回对比信息
|
||||
sbResult.append("Total : ");
|
||||
sbResult.append(nBeanListCout);
|
||||
sbResult.append(" Diff : ");
|
||||
sbResult.append(nBeanListCout - nSameCount);
|
||||
}
|
||||
} catch (InstantiationException e) {
|
||||
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();
|
||||
}
|
||||
/**
|
||||
* 将 JSON 字符串解析为目标 Bean 实例
|
||||
* 通过反射创建 Bean 实例,调用子类解析逻辑完成初始化
|
||||
* @param szBean JSON 字符串(单个 Bean 的 JSON 数据)
|
||||
* @param clazz 目标 Bean 类(用于反射实例化)
|
||||
* @return 解析成功的 Bean 实例;失败返回 null
|
||||
* @throws IOException JSON 解析失败时抛出
|
||||
* @param <T> 泛型约束,限定为 BaseBean 子类
|
||||
*/
|
||||
public static <T extends BaseBean> T parseStringToBean(String szBean, Class<T> clazz) throws IOException {
|
||||
StringReader stringReader = new StringReader(szBean);
|
||||
JsonReader jsonReader = new JsonReader(stringReader);
|
||||
|
||||
public static <T extends BaseBean> T parseStringToBean(String szBean, Class<T> clazz) throws IOException {
|
||||
// 创建 JsonWriter 对象
|
||||
StringReader stringReader = new StringReader(szBean);
|
||||
JsonReader jsonReader = new JsonReader(stringReader);
|
||||
try {
|
||||
T beanTemp = clazz.newInstance();
|
||||
return (T)beanTemp.readBeanFromJsonReader(jsonReader);
|
||||
} catch (InstantiationException e) {
|
||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||
} catch (IllegalAccessException e) {
|
||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
// 反射创建 Bean 实例
|
||||
T beanTemp = clazz.newInstance();
|
||||
// 调用子类解析方法,返回解析后的实例
|
||||
return (T) beanTemp.readBeanFromJsonReader(jsonReader);
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
// 反射异常日志记录
|
||||
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 {
|
||||
if(beanList == null) {
|
||||
beanList = new ArrayList<T>();
|
||||
} else {
|
||||
beanList.clear();
|
||||
}
|
||||
StringReader stringReader = new StringReader(szBeanList);
|
||||
JsonReader jsonReader = new JsonReader(stringReader);
|
||||
jsonReader.beginArray();
|
||||
while (jsonReader.hasNext()) {
|
||||
T beanTemp = clazz.newInstance();
|
||||
T bean = (T)beanTemp.readBeanFromJsonReader(jsonReader);
|
||||
if (bean != null) {
|
||||
beanList.add(bean);
|
||||
//LogUtils.d(TAG, "beanList.add(bean)");
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
/**
|
||||
* 将 JSON 字符串解析为 Bean 列表
|
||||
* 清空目标列表,将解析后的 Bean 逐个添加到列表中
|
||||
* @param szBeanList JSON 字符串(Bean 列表的 JSON 数组)
|
||||
* @param beanList 目标列表(存储解析后的 Bean)
|
||||
* @param clazz 目标 Bean 类(用于反射实例化)
|
||||
* @return true:解析成功;false:解析失败
|
||||
* @param <T> 泛型约束,限定为 BaseBean 子类
|
||||
*/
|
||||
public static <T extends BaseBean> boolean parseStringToBeanList(String szBeanList, ArrayList<T> beanList, Class<T> clazz) {
|
||||
try {
|
||||
// 初始化目标列表(为空则创建,非空则清空)
|
||||
if (beanList == null) {
|
||||
beanList = new ArrayList<T>();
|
||||
} else {
|
||||
beanList.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
// 创建 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 "";
|
||||
}
|
||||
StringReader stringReader = new StringReader(szBeanList);
|
||||
JsonReader jsonReader = new JsonReader(stringReader);
|
||||
|
||||
public static <T extends BaseBean> String toStringByBeanList(ArrayList<T> beanList) {
|
||||
try {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
JsonWriter jsonWriter = new JsonWriter(stringWriter);
|
||||
jsonWriter.setIndent(" ");
|
||||
jsonWriter.beginArray();
|
||||
for (int i = 0; i < beanList.size(); i++) {
|
||||
// 开始 JSON 对象
|
||||
jsonWriter.beginObject();
|
||||
// 写入键值对
|
||||
beanList.get(i).writeThisToJsonWriter(jsonWriter);
|
||||
// 结束 JSON 对象
|
||||
jsonWriter.endObject();
|
||||
}
|
||||
jsonWriter.endArray();
|
||||
jsonWriter.close();
|
||||
return stringWriter.toString();
|
||||
} catch (IOException e) {
|
||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
jsonReader.beginArray(); // 开始解析 JSON 数组
|
||||
while (jsonReader.hasNext()) {
|
||||
// 反射创建 Bean 实例,解析并添加到列表
|
||||
T beanTemp = clazz.newInstance();
|
||||
T bean = (T) beanTemp.readBeanFromJsonReader(jsonReader);
|
||||
if (bean != null) {
|
||||
beanList.add(bean);
|
||||
}
|
||||
}
|
||||
jsonReader.endArray(); // 结束 JSON 数组解析
|
||||
return true;
|
||||
} catch (InstantiationException | IllegalAccessException | IOException e) {
|
||||
// 异常日志记录
|
||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重写 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 {
|
||||
T beanTemp = clazz.newInstance();
|
||||
return loadBeanFromFile(beanTemp.getBeanJsonFilePath(context), clazz);
|
||||
} catch (InstantiationException e) {
|
||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||
} catch (IllegalAccessException e) {
|
||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
jsonWriter.beginObject(); // 开始 JSON 对象
|
||||
writeThisToJsonWriter(jsonWriter); // 写入 Bean 字段(子类扩展)
|
||||
jsonWriter.endObject(); // 结束 JSON 对象
|
||||
return stringWriter.toString();
|
||||
} catch (IOException e) {
|
||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static <T extends BaseBean> T loadBeanFromFile(String szFilePath, Class<T> clazz) {
|
||||
try {
|
||||
try {
|
||||
File fTemp = new File(szFilePath);
|
||||
if (fTemp.exists()) {
|
||||
T beanTemp = clazz.newInstance();String szJson = UTF8FileUtils.readStringFromFile(szFilePath);
|
||||
return beanTemp.parseStringToBean(szJson, clazz);
|
||||
}
|
||||
} catch (InstantiationException e) {
|
||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||
} catch (IllegalAccessException e) {
|
||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||
}
|
||||
/**
|
||||
* 将 Bean 列表序列化为格式化的 JSON 字符串
|
||||
* 遍历列表,逐个序列化每个 Bean,生成 JSON 数组
|
||||
* @param beanList 待序列化的 Bean 列表
|
||||
* @return 列表的 JSON 字符串;失败返回空串
|
||||
* @param <T> 泛型约束,限定为 BaseBean 子类
|
||||
*/
|
||||
public static <T extends BaseBean> String toStringByBeanList(ArrayList<T> beanList) {
|
||||
try {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
JsonWriter jsonWriter = new JsonWriter(stringWriter);
|
||||
jsonWriter.setIndent(" "); // 格式化缩进
|
||||
|
||||
} catch (IOException e) {
|
||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
jsonWriter.beginArray(); // 开始 JSON 数组
|
||||
for (int i = 0; i < beanList.size(); i++) {
|
||||
jsonWriter.beginObject(); // 单个 Bean 开始
|
||||
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 {
|
||||
String szJson = bean.toString();
|
||||
UTF8FileUtils.writeStringToFile(szFilePath, szJson);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* 从指定文件路径加载 Bean 实例
|
||||
* 检查文件是否存在,存在则读取 JSON 并解析为目标 Bean
|
||||
* @param szFilePath 目标文件路径(存储 Bean 的 JSON 文件)
|
||||
* @param clazz 目标 Bean 类(用于反射实例化)
|
||||
* @return 加载成功的 Bean 实例;失败返回 null
|
||||
* @param <T> 泛型约束,限定为 BaseBean 子类
|
||||
*/
|
||||
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 {
|
||||
T beanTemp = clazz.newInstance();
|
||||
return loadBeanListFromFile(beanTemp.getBeanListJsonFilePath(context), beanListDst, clazz);
|
||||
} catch (InstantiationException e) {} catch (IllegalAccessException e) {
|
||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* 将 Bean 保存到默认路径(getBeanJsonFilePath)的文件中
|
||||
* 序列化 Bean 为 JSON,写入应用私有目录下的文件
|
||||
* @param context 上下文(用于获取文件路径)
|
||||
* @param bean 待保存的 Bean 实例
|
||||
* @return true:保存成功;false:保存失败
|
||||
* @param <T> 泛型约束,限定为 BaseBean 子类
|
||||
*/
|
||||
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 {
|
||||
File fTemp = new File(szFilePath);
|
||||
if (fTemp.exists()) {
|
||||
String szListJson = UTF8FileUtils.readStringFromFile(szFilePath);
|
||||
return parseStringToBeanList(szListJson, beanList, clazz);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* 将 Bean 保存到指定文件路径
|
||||
* 序列化 Bean 为 JSON 字符串,写入目标文件(覆盖原有内容)
|
||||
* @param szFilePath 目标文件路径(保存 JSON 的文件)
|
||||
* @param bean 待保存的 Bean 实例
|
||||
* @return true:保存成功;false:保存失败
|
||||
* @param <T> 泛型约束,限定为 BaseBean 子类
|
||||
*/
|
||||
public static <T extends BaseBean> boolean saveBeanToFile(String szFilePath, T bean) {
|
||||
try {
|
||||
// 序列化 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 {
|
||||
T beanTemp = clazz.newInstance();
|
||||
return saveBeanListToFile(beanTemp.getBeanListJsonFilePath(context), beanList);
|
||||
} catch (InstantiationException e) {
|
||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||
} catch (IllegalAccessException e) {
|
||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* 从默认路径(getBeanListJsonFilePath)加载 Bean 列表
|
||||
* 读取应用私有目录下的列表 JSON 文件,解析并填充到目标列表
|
||||
* @param context 上下文(用于获取文件路径)
|
||||
* @param beanListDst 目标列表(存储加载后的 Bean)
|
||||
* @param clazz 目标 Bean 类(用于反射实例化)
|
||||
* @return true:加载成功;false:加载失败
|
||||
* @param <T> 泛型约束,限定为 BaseBean 子类
|
||||
*/
|
||||
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 {
|
||||
String szJson = toStringByBeanList(beanList);
|
||||
UTF8FileUtils.writeStringToFile(szFilePath, szJson);
|
||||
//LogUtils.d(TAG, "FileUtil.writeFile beanList.size() is " + Integer.toString(beanList.size()));
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* 从指定文件路径加载 Bean 列表
|
||||
* 检查文件是否存在,存在则读取 JSON 数组,解析并填充到目标列表
|
||||
* @param szFilePath 目标文件路径(存储列表 JSON 的文件)
|
||||
* @param beanList 目标列表(存储加载后的 Bean)
|
||||
* @param clazz 目标 Bean 类(用于反射实例化)
|
||||
* @return true:加载成功;false:加载失败
|
||||
* @param <T> 泛型约束,限定为 BaseBean 子类
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2024/08/12 13:22:12
|
||||
* @Describe 异常处理类
|
||||
*/
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.content.ActivityNotFoundException;
|
||||
@@ -12,29 +7,23 @@ import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.text.SpannableString;
|
||||
import android.text.TextUtils;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.HorizontalScrollView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.widget.Toolbar;
|
||||
import cc.winboll.studio.libappbase.R;
|
||||
import cc.winboll.studio.libappbase.utils.CrashHandleNotifyUtils;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -48,358 +37,522 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||
* @Date 2025/11/11 20:14
|
||||
* @Describe * 应用全局崩溃处理类(单例逻辑)
|
||||
* 核心功能:捕获应用未捕获异常,记录崩溃日志到文件,启动崩溃报告页面,
|
||||
* 并通过「崩溃保险丝」机制防止重复崩溃,保障基础功能可用
|
||||
*/
|
||||
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";
|
||||
final static String PREFS_CRASHHANDLER_ISCRASHHAPPEN = "PREFS_CRASHHANDLER_ISCRASHHAPPEN";
|
||||
/** SharedPreferences 存储键(用于记录崩溃状态) */
|
||||
final static String PREFS = CrashHandler.class.getName() + "PREFS";
|
||||
/** SharedPreferences 中存储「是否发生崩溃」的键 */
|
||||
final static String PREFS_CRASHHANDLER_ISCRASHHAPPEN = "PREFS_CRASHHANDLER_ISCRASHHAPPEN";
|
||||
|
||||
public static String _CrashCountFilePath;
|
||||
/** 崩溃保险丝状态文件路径(存储当前熔断等级) */
|
||||
public static String _CrashCountFilePath;
|
||||
|
||||
public static final UncaughtExceptionHandler DEFAULT_UNCAUGHT_EXCEPTION_HANDLER = Thread.getDefaultUncaughtExceptionHandler();
|
||||
/** 系统默认的未捕获异常处理器(用于降级处理,避免 CrashHandler 自身崩溃) */
|
||||
public static final UncaughtExceptionHandler DEFAULT_UNCAUGHT_EXCEPTION_HANDLER = Thread.getDefaultUncaughtExceptionHandler();
|
||||
|
||||
public static void init(Application app) {
|
||||
_CrashCountFilePath = app.getExternalFilesDir("CrashHandler") + "/IsCrashHandlerCrashHappen.dat";
|
||||
LogUtils.d(TAG, String.format("_CrashCountFilePath %s", _CrashCountFilePath));
|
||||
init(app, null);
|
||||
}
|
||||
/**
|
||||
* 初始化崩溃处理器(默认存储路径)
|
||||
* 调用重载方法,崩溃日志默认存储在应用外部私有目录的 crash 文件夹下
|
||||
* @param app 全局 Application 实例(用于获取存储目录、包信息等)
|
||||
*/
|
||||
public static void init(Application app) {
|
||||
// 初始化崩溃保险丝状态文件路径(外部存储/CrashHandler/IsCrashHandlerCrashHappen.dat)
|
||||
_CrashCountFilePath = app.getExternalFilesDir("CrashHandler") + "/IsCrashHandlerCrashHappen.dat";
|
||||
LogUtils.d(TAG, String.format("_CrashCountFilePath %s", _CrashCountFilePath));
|
||||
// 调用带目录参数的初始化方法,传入 null 使用默认路径
|
||||
init(app, null);
|
||||
}
|
||||
|
||||
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 {
|
||||
tryUncaughtException(thread, throwable);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
if (DEFAULT_UNCAUGHT_EXCEPTION_HANDLER != null)
|
||||
DEFAULT_UNCAUGHT_EXCEPTION_HANDLER.uncaughtException(thread, throwable);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 实际处理崩溃的核心方法
|
||||
* 1. 熔断保险丝(记录崩溃次数);2. 收集崩溃信息;3. 写入日志文件;4. 启动崩溃报告页面
|
||||
* @param thread 发生崩溃的线程
|
||||
* @param throwable 崩溃异常对象(包含堆栈信息)
|
||||
*/
|
||||
private void tryUncaughtException(Thread thread, Throwable throwable) {
|
||||
// 触发崩溃保险丝(每次崩溃熔断一次,降低防护等级)
|
||||
AppCrashSafetyWire.getInstance().burnSafetyWire();
|
||||
|
||||
private void tryUncaughtException(Thread thread, Throwable throwable) {
|
||||
// 每到这里就燃烧一次保险丝
|
||||
AppCrashSafetyWire.getInstance().burnSafetyWire();
|
||||
// 格式化崩溃发生时间(用于日志文件名和内容)
|
||||
final String time = new SimpleDateFormat("yyyy_MM_dd-HH_mm_ss", Locale.getDefault()).format(new Date());
|
||||
// 创建崩溃日志文件(默认路径:外部存储/crash/[时间].txt)
|
||||
File crashFile = new File(
|
||||
TextUtils.isEmpty(crashDir) ? new File(app.getExternalFilesDir(null), "crash") : new File(crashDir),
|
||||
"crash_" + time + ".txt"
|
||||
);
|
||||
|
||||
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")
|
||||
: new File(crashDir), "crash_" + time + ".txt");
|
||||
// 获取应用版本信息(版本名、版本号)
|
||||
String versionName = "unknown";
|
||||
long versionCode = 0;
|
||||
try {
|
||||
PackageInfo packageInfo = app.getPackageManager().getPackageInfo(app.getPackageName(), 0);
|
||||
versionName = packageInfo.versionName;
|
||||
// 适配 Android 9.0+(API 28)的版本号获取方式
|
||||
versionCode = Build.VERSION.SDK_INT >= 28 ? packageInfo.getLongVersionCode() : packageInfo.versionCode;
|
||||
} catch (PackageManager.NameNotFoundException ignored) {}
|
||||
|
||||
String versionName = "unknown";
|
||||
long versionCode = 0;
|
||||
try {
|
||||
PackageInfo packageInfo = app.getPackageManager().getPackageInfo(app.getPackageName(), 0);
|
||||
versionName = packageInfo.versionName;
|
||||
versionCode = Build.VERSION.SDK_INT >= 28 ? packageInfo.getLongVersionCode()
|
||||
: packageInfo.versionCode;
|
||||
} catch (PackageManager.NameNotFoundException ignored) {}
|
||||
// 将异常堆栈信息转换为字符串
|
||||
String fullStackTrace;
|
||||
{
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
throwable.printStackTrace(pw); // 将异常堆栈写入 PrintWriter
|
||||
fullStackTrace = sw.toString();
|
||||
pw.close();
|
||||
}
|
||||
|
||||
String fullStackTrace; {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
throwable.printStackTrace(pw);
|
||||
fullStackTrace = sw.toString();
|
||||
pw.close();
|
||||
}
|
||||
// 拼接崩溃信息(设备信息 + 应用信息 + 堆栈信息)
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("************* Crash Head ****************\n");
|
||||
sb.append("Time Of Crash : ").append(time).append("\n");
|
||||
sb.append("Device Manufacturer : ").append(Build.MANUFACTURER).append("\n"); // 设备厂商
|
||||
sb.append("Device Model : ").append(Build.MODEL).append("\n"); // 设备型号
|
||||
sb.append("Android Version : ").append(Build.VERSION.RELEASE).append("\n"); // 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();
|
||||
sb.append("************* Crash Head ****************\n");
|
||||
sb.append("Time Of Crash : ").append(time).append("\n");
|
||||
sb.append("Device Manufacturer : ").append(Build.MANUFACTURER).append("\n");
|
||||
sb.append("Device Model : ").append(Build.MODEL).append("\n");
|
||||
sb.append("Android Version : ").append(Build.VERSION.RELEASE).append("\n");
|
||||
sb.append("Android SDK : ").append(Build.VERSION.SDK_INT).append("\n");
|
||||
sb.append("App VersionName : ").append(versionName).append("\n");
|
||||
sb.append("App VersionCode : ").append(versionCode).append("\n");
|
||||
sb.append("************* Crash Head ****************\n");
|
||||
sb.append("\n").append(fullStackTrace);
|
||||
final String errorLog = sb.toString();
|
||||
|
||||
String errorLog = sb.toString();
|
||||
// 将崩溃日志写入文件(忽略写入失败)
|
||||
try {
|
||||
writeFile(crashFile, errorLog);
|
||||
} catch (IOException ignored) {}
|
||||
|
||||
try {
|
||||
writeFile(crashFile, errorLog);
|
||||
} catch (IOException ignored) {}
|
||||
// 启动崩溃报告页面(标签用于代码块折叠)
|
||||
gotoCrashActiviy: {
|
||||
Intent intent = new Intent();
|
||||
LogUtils.d(TAG, "gotoCrashActiviy: ");
|
||||
|
||||
gotoCrashActiviy: {
|
||||
Intent intent = new Intent();
|
||||
LogUtils.d(TAG, "gotoCrashActiviy: ");
|
||||
if (AppCrashSafetyWire.getInstance().isAppCrashSafetyWireOK()) {
|
||||
LogUtils.d(TAG, "gotoCrashActiviy: isAppCrashSafetyWireOK");
|
||||
intent.setClass(app, GlobalCrashActivity.class);
|
||||
intent.putExtra(EXTRA_CRASH_INFO, errorLog);
|
||||
// 如果发生了 CrashHandler 内部崩溃, 就调用基础的应用崩溃显示类
|
||||
// intent.setClass(app, GlobalCrashActiviy.class);
|
||||
// intent.putExtra(GlobalCrashActiviy.EXTRA_CRASH_INFO, errorLog);
|
||||
} else {
|
||||
LogUtils.d(TAG, "gotoCrashActiviy: else");
|
||||
// 正常状态调用进阶的应用崩溃显示页
|
||||
intent.setClass(app, CrashActivity.class);
|
||||
intent.putExtra(EXTRA_CRASH_INFO, errorLog);
|
||||
}
|
||||
// 根据保险丝状态选择启动的崩溃页面
|
||||
if (AppCrashSafetyWire.getInstance().isAppCrashSafetyWireOK()) {
|
||||
LogUtils.d(TAG, "gotoCrashActiviy: isAppCrashSafetyWireOK");
|
||||
// 保险丝正常:启动自定义样式的崩溃报告页面(GlobalCrashActivity)
|
||||
intent.setClass(app, GlobalCrashActivity.class);
|
||||
intent.putExtra(EXTRA_CRASH_LOG, errorLog); // 传递崩溃日志
|
||||
} else {
|
||||
LogUtils.d(TAG, "gotoCrashActiviy: else");
|
||||
// 保险丝熔断:启动基础版崩溃页面(CrashActivity,避免复杂页面再次崩溃)
|
||||
intent.setClass(app, CrashActivity.class);
|
||||
intent.putExtra(EXTRA_CRASH_LOG, errorLog);
|
||||
}
|
||||
|
||||
// 设置意图标志:清除原有任务栈,创建新任务(避免回到崩溃前页面)
|
||||
intent.addFlags(
|
||||
Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
);
|
||||
|
||||
try {
|
||||
if (GlobalApplication.isDebugging()&&AppCrashSafetyWire.getInstance().isAppCrashSafetyWireOK()) {
|
||||
// 如果是 debug 版,启动崩溃页面窗口
|
||||
app.startActivity(intent);
|
||||
} else {
|
||||
// 如果是 release 版,就只发送一个通知
|
||||
CrashHandleNotifyUtils.handleUncaughtException(app, intent);
|
||||
}
|
||||
// 终止当前进程(确保完全重启)
|
||||
android.os.Process.killProcess(android.os.Process.myPid());
|
||||
System.exit(0);
|
||||
|
||||
// intent.setClass(app, CrashActiviy.class);
|
||||
// intent.putExtra(CrashActiviy.EXTRA_CRASH_INFO, errorLog);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
// 未找到崩溃页面(如未在 Manifest 注册),交给系统默认处理器
|
||||
e.printStackTrace();
|
||||
if (DEFAULT_UNCAUGHT_EXCEPTION_HANDLER != null) {
|
||||
DEFAULT_UNCAUGHT_EXCEPTION_HANDLER.uncaughtException(thread, throwable);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 其他异常,兜底处理
|
||||
e.printStackTrace();
|
||||
if (DEFAULT_UNCAUGHT_EXCEPTION_HANDLER != null) {
|
||||
DEFAULT_UNCAUGHT_EXCEPTION_HANDLER.uncaughtException(thread, throwable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符串内容写入文件(创建父目录、覆盖写入)
|
||||
* @param file 目标文件(包含路径)
|
||||
* @param content 待写入的内容(崩溃日志)
|
||||
* @throws IOException 文件创建或写入失败时抛出
|
||||
*/
|
||||
private void writeFile(File file, String content) throws IOException {
|
||||
File parentFile = file.getParentFile();
|
||||
// 父目录不存在则创建
|
||||
if (parentFile != null && !parentFile.exists()) {
|
||||
parentFile.mkdirs();
|
||||
}
|
||||
file.createNewFile(); // 创建文件
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
fos.write(content.getBytes()); // 写入内容(默认 UTF-8 编码)
|
||||
try {
|
||||
fos.close(); // 关闭流
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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 {
|
||||
app.startActivity(intent);
|
||||
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);
|
||||
}
|
||||
}
|
||||
/** 单例实例(volatile 保证多线程可见性) */
|
||||
private static volatile AppCrashSafetyWire _AppCrashSafetyWire;
|
||||
|
||||
}
|
||||
/** 当前熔断等级(1:最低防护;2:最高防护;≤0:熔断) */
|
||||
private volatile Integer currentSafetyLevel;
|
||||
/** 最低熔断等级(1,再崩溃则熔断) */
|
||||
private static final int _MINI = 1;
|
||||
/** 最高熔断等级(2,初始状态) */
|
||||
private static final int _MAX = 2;
|
||||
|
||||
private 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());
|
||||
try {
|
||||
fos.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
/**
|
||||
* 私有构造方法(单例模式,禁止外部实例化)
|
||||
* 初始化时加载本地存储的熔断等级
|
||||
*/
|
||||
private AppCrashSafetyWire() {
|
||||
LogUtils.d(TAG, "AppCrashSafetyWire()");
|
||||
currentSafetyLevel = loadCurrentSafetyLevel();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 获取单例实例(双重检查锁定,线程安全)
|
||||
* @return AppCrashSafetyWire 单例
|
||||
*/
|
||||
public static synchronized AppCrashSafetyWire getInstance() {
|
||||
if (_AppCrashSafetyWire == null) {
|
||||
_AppCrashSafetyWire = new AppCrashSafetyWire();
|
||||
}
|
||||
return _AppCrashSafetyWire;
|
||||
}
|
||||
|
||||
//
|
||||
// 应用崩溃保险丝
|
||||
//
|
||||
public static final class AppCrashSafetyWire {
|
||||
/**
|
||||
* 设置当前熔断等级(内存中)
|
||||
* @param currentSafetyLevel 目标等级(1~2)
|
||||
*/
|
||||
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 _AppCrashSafetyWire;
|
||||
}
|
||||
/**
|
||||
* 熔断保险丝(每次崩溃调用,降低防护等级)
|
||||
* @return 熔断后是否仍在防护范围内(true:是;false:已熔断)
|
||||
*/
|
||||
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() {
|
||||
return currentSafetyLevel;
|
||||
}
|
||||
if (safetyLevel >= _MINI && safetyLevel <= _MAX) {
|
||||
LogUtils.d(TAG, String.format("In Safety Level"));
|
||||
return true;
|
||||
}
|
||||
LogUtils.d(TAG, String.format("Out of Safety Level"));
|
||||
return false;
|
||||
}
|
||||
|
||||
public void saveCurrentSafetyLevel(int currentSafetyLevel) {
|
||||
LogUtils.d(TAG, "saveCurrentSafetyLevel()");
|
||||
this.currentSafetyLevel = currentSafetyLevel;
|
||||
try {
|
||||
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());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 立即恢复熔断等级到最高(2)
|
||||
* 用于重启应用后重置防护状态
|
||||
*/
|
||||
void resumeToMaximumImmediately() {
|
||||
LogUtils.d(TAG, "resumeToMaximumImmediately() call saveCurrentSafetyLevel(_MAX)");
|
||||
AppCrashSafetyWire.getInstance().saveCurrentSafetyLevel(_MAX);
|
||||
}
|
||||
|
||||
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 {
|
||||
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;
|
||||
}
|
||||
/**
|
||||
* 关闭防护(设置等级为最低(1))
|
||||
* 下次崩溃直接熔断
|
||||
*/
|
||||
void off() {
|
||||
LogUtils.d(TAG, "off()");
|
||||
saveCurrentSafetyLevel(_MINI);
|
||||
}
|
||||
|
||||
boolean burnSafetyWire() {
|
||||
LogUtils.d(TAG, "burnSafetyWire()");
|
||||
// 崩溃计数进入崩溃保险值
|
||||
int safeLevel = loadCurrentSafetyLevel();
|
||||
if (isSafetyWireWorking(safeLevel)) {
|
||||
// 如果保险丝未熔断, 就增加一次熔断值
|
||||
LogUtils.d(TAG, "burnSafetyWire() use");
|
||||
saveCurrentSafetyLevel(safeLevel - 1);
|
||||
return isSafetyWireWorking(safeLevel - 1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* 检查当前保险丝是否有效(防护未熔断)
|
||||
* @return true:有效(等级 1~2);false:已熔断
|
||||
*/
|
||||
boolean isAppCrashSafetyWireOK() {
|
||||
LogUtils.d(TAG, "isAppCrashSafetyWireOK()");
|
||||
currentSafetyLevel = loadCurrentSafetyLevel();
|
||||
return isSafetyWireWorking(currentSafetyLevel);
|
||||
}
|
||||
|
||||
boolean isSafetyWireWorking(int safetyLevel) {
|
||||
LogUtils.d(TAG, "isSafetyWireOK()");
|
||||
//safetyLevel = _MINI;
|
||||
//safetyLevel = _MINI - 1;
|
||||
//safetyLevel = _MINI + 1;
|
||||
//safetyLevel = _MAX;
|
||||
//safetyLevel = _MAX + 1;
|
||||
LogUtils.d(TAG, String.format("SafetyLevel %d", safetyLevel));
|
||||
/**
|
||||
* 延迟恢复保险丝到最高等级(500ms 后)
|
||||
* 核心作用:崩溃页面启动后,若下次即将熔断,提前恢复防护等级,避免持续崩溃
|
||||
* @param context 上下文(用于获取主线程 Handler)
|
||||
*/
|
||||
void postResumeCrashSafetyWireHandler(final Context context) {
|
||||
// 主线程延迟 500ms 执行(避免页面启动时阻塞)
|
||||
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
LogUtils.d(TAG, "Handler run()");
|
||||
// 检查:若当前等级-1 后超出防护范围(即将熔断),则恢复到最高等级
|
||||
if (!AppCrashSafetyWire.getInstance().isSafetyWireWorking(currentSafetyLevel - 1)) {
|
||||
AppCrashSafetyWire.getInstance().resumeToMaximumImmediately();
|
||||
LogUtils.d(TAG, "postResumeCrashSafetyWireHandler: 恢复保险丝到最高等级");
|
||||
}
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
|
||||
if (safetyLevel >= _MINI && safetyLevel <= _MAX) {
|
||||
// 如果在保险值之内
|
||||
LogUtils.d(TAG, String.format("In Safety Level"));
|
||||
return true;
|
||||
}
|
||||
LogUtils.d(TAG, String.format("Out of Safety Level"));
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* 基础版崩溃报告页面(保险丝熔断时启动)
|
||||
* 极简实现:仅展示崩溃日志,提供复制、重启功能,避免复杂布局导致二次崩溃
|
||||
*/
|
||||
public static final class CrashActivity extends Activity implements MenuItem.OnMenuItemClickListener {
|
||||
/** 菜单标识:复制崩溃日志 */
|
||||
private static final int MENUITEM_COPY = 0;
|
||||
/** 菜单标识:重启应用 */
|
||||
private static final int MENUITEM_RESTART = 1;
|
||||
|
||||
void resumeToMaximumImmediately() {
|
||||
LogUtils.d(TAG, "resumeToMaximumImmediately() call saveCurrentSafetyLevel(_MAX)");
|
||||
AppCrashSafetyWire.getInstance().saveCurrentSafetyLevel(_MAX);
|
||||
}
|
||||
/** 崩溃日志文本(从 CrashHandler 传递过来) */
|
||||
private String mLog;
|
||||
|
||||
void off() {
|
||||
LogUtils.d(TAG, "off()");
|
||||
saveCurrentSafetyLevel(_MINI);
|
||||
}
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// 初始化崩溃保险丝延迟恢复机制
|
||||
AppCrashSafetyWire.getInstance().postResumeCrashSafetyWireHandler(getApplicationContext());
|
||||
|
||||
boolean isAppCrashSafetyWireOK() {
|
||||
LogUtils.d(TAG, "isAppCrashSafetyWireOK()");
|
||||
currentSafetyLevel = loadCurrentSafetyLevel();
|
||||
return isSafetyWireWorking(currentSafetyLevel);
|
||||
}
|
||||
// 获取传递的崩溃日志
|
||||
mLog = getIntent().getStringExtra(EXTRA_CRASH_LOG);
|
||||
// 设置系统默认主题(避免自定义主题冲突)
|
||||
setTheme(android.R.style.Theme_DeviceDefault_Light_DarkActionBar);
|
||||
|
||||
// 调用函数以启用持续崩溃保险,从而调用 CrashHandler 内部崩溃处理窗口
|
||||
void postResumeCrashSafetyWireHandler(final Context context) {
|
||||
new Handler(Looper.getMainLooper()).postDelayed(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
LogUtils.d(TAG, "Handler run()");
|
||||
if (!AppCrashSafetyWire.getInstance().isSafetyWireWorking(currentSafetyLevel - 1)) {
|
||||
// 如果下一次应用崩溃时,保险丝熔断,则先恢复保险丝满能状态
|
||||
// 进程持续运行时,恢复保险丝熔断值
|
||||
//Resume to maximum
|
||||
AppCrashSafetyWire.getInstance().resumeToMaximumImmediately();
|
||||
LogUtils.d(TAG, "postResumeCrashSafetyWireHandler");
|
||||
}
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
// 动态创建布局(避免 XML 布局加载异常)
|
||||
setContentView: {
|
||||
// 垂直滚动视图(处理日志过长)
|
||||
ScrollView contentView = new ScrollView(this);
|
||||
contentView.setFillViewport(true);
|
||||
|
||||
public static final class CrashActivity extends Activity implements MenuItem.OnMenuItemClickListener {
|
||||
private static final int MENUITEM_COPY = 0;
|
||||
private static final int MENUITEM_RESTART = 1;
|
||||
// 水平滚动视图(处理日志行过长)
|
||||
HorizontalScrollView hw = new HorizontalScrollView(this);
|
||||
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
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
AppCrashSafetyWire.getInstance().postResumeCrashSafetyWireHandler(getApplicationContext());
|
||||
// 组装布局:TextView -> HorizontalScrollView -> ScrollView
|
||||
hw.addView(message);
|
||||
contentView.addView(hw, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
// 设置当前 Activity 布局
|
||||
setContentView(contentView);
|
||||
|
||||
mLog = getIntent().getStringExtra(EXTRA_CRASH_INFO);
|
||||
setTheme(android.R.style.Theme_DeviceDefault_Light_DarkActionBar);
|
||||
setContentView: {
|
||||
ScrollView contentView = new ScrollView(this);
|
||||
contentView.setFillViewport(true);
|
||||
// 配置 ActionBar 标题和副标题
|
||||
getActionBar().setTitle(TITTLE);
|
||||
getActionBar().setSubtitle(GlobalApplication.class.getSimpleName() + " Error");
|
||||
}
|
||||
}
|
||||
|
||||
HorizontalScrollView hw = new HorizontalScrollView(this);
|
||||
hw.setBackgroundColor(Color.GRAY);
|
||||
TextView message = new TextView(this); {
|
||||
int padding = dp2px(16);
|
||||
message.setPadding(padding, padding, padding, padding);
|
||||
message.setText(mLog);
|
||||
message.setTextColor(Color.BLACK);
|
||||
message.setTextIsSelectable(true);
|
||||
}
|
||||
hw.addView(message);
|
||||
/**
|
||||
* 重写返回键逻辑:点击返回键直接重启应用
|
||||
*/
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
restart();
|
||||
}
|
||||
|
||||
contentView.addView(hw, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
setContentView(contentView);
|
||||
getActionBar().setTitle(TITTLE);
|
||||
getActionBar().setSubtitle(GlobalApplication.class.getSimpleName() + " Error");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 重启当前应用(与 GlobalCrashActivity 逻辑一致)
|
||||
* 清除任务栈,启动主 Activity,终止当前进程
|
||||
*/
|
||||
private void restart() {
|
||||
PackageManager pm = getPackageManager();
|
||||
// 获取应用启动意图(默认启动主 Activity)
|
||||
Intent intent = pm.getLaunchIntentForPackage(getPackageName());
|
||||
if (intent != null) {
|
||||
// 设置意图标志:清除原有任务栈,创建新任务
|
||||
intent.addFlags(
|
||||
Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
);
|
||||
startActivity(intent);
|
||||
}
|
||||
// 关闭当前页面,终止进程,确保完全重启
|
||||
finish();
|
||||
android.os.Process.killProcess(android.os.Process.myPid());
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
restart();
|
||||
}
|
||||
/**
|
||||
* dp 转 px(适配不同屏幕密度)
|
||||
* @param dpValue dp 值
|
||||
* @return 转换后的 px 值
|
||||
*/
|
||||
private int dp2px(final float dpValue) {
|
||||
final float scale = Resources.getSystem().getDisplayMetrics().density;
|
||||
return (int) (dpValue * scale + 0.5f); // 四舍五入确保精度
|
||||
}
|
||||
|
||||
private void restart() {
|
||||
PackageManager pm = getPackageManager();
|
||||
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);
|
||||
}
|
||||
/**
|
||||
* 菜单点击事件回调(处理复制、重启)
|
||||
* @param item 被点击的菜单项
|
||||
* @return false:不消费事件(保持默认行为)
|
||||
*/
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case MENUITEM_COPY:
|
||||
// 复制日志到剪贴板
|
||||
ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
cm.setPrimaryClip(ClipData.newPlainText(getPackageName(), mLog));
|
||||
Toast.makeText(getApplication(), "The text is copied.", Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case MENUITEM_RESTART:
|
||||
// 恢复保险丝到最高等级,然后重启应用
|
||||
AppCrashSafetyWire.getInstance().resumeToMaximumImmediately();
|
||||
restart();
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private int dp2px(final float dpValue) {
|
||||
final float scale = Resources.getSystem().getDisplayMetrics().density;
|
||||
return (int) (dpValue * scale + 0.5f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case MENUITEM_COPY:
|
||||
ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
cm.setPrimaryClip(ClipData.newPlainText(getPackageName(), mLog));
|
||||
Toast.makeText(getApplication(), "The text is copied.", Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case MENUITEM_RESTART:
|
||||
AppCrashSafetyWire.getInstance().resumeToMaximumImmediately();
|
||||
restart();
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 创建 ActionBar 菜单(添加复制、重启项)
|
||||
* @param menu 菜单容器
|
||||
* @return true:显示菜单
|
||||
*/
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// 添加「复制」菜单:有空间时显示在 ActionBar,否则放入溢出菜单
|
||||
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;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2025/01/05 10:10:23
|
||||
* @Describe 全局应用类
|
||||
*/
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
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 static final String TAG = "GlobalApplication";
|
||||
|
||||
// 应用是否处于调试状态
|
||||
volatile static boolean isDebuging = false;
|
||||
|
||||
public static void setIsDebuging(boolean isDebuging) {
|
||||
GlobalApplication.isDebuging = isDebuging;
|
||||
}
|
||||
|
||||
public static void saveDebugStatus(Context context) {
|
||||
APPModel.saveBeanToFile(getAPPModelFilePath(context), new APPModel(GlobalApplication.isDebuging));
|
||||
}
|
||||
|
||||
static String getAPPModelFilePath(Context context) {
|
||||
return context.getDataDir().getPath() + "/APPModel.json";
|
||||
|
||||
/** 全局 Application 单例实例(volatile 保证多线程可见性,避免指令重排) */
|
||||
private static volatile GlobalApplication sInstance;
|
||||
|
||||
/**
|
||||
* 应用调试模式标记(volatile 保证多线程可见性)
|
||||
* true:调试模式(开启日志、调试功能);false:正式模式(关闭调试相关功能)
|
||||
*/
|
||||
private static volatile boolean isDebugging = false;
|
||||
|
||||
/**
|
||||
* 获取全局 Application 单例实例(外部可通过此方法获取上下文)
|
||||
* @return GlobalApplication 单例(未初始化时返回 null,需确保配置 AndroidManifest)
|
||||
*/
|
||||
public static GlobalApplication getInstance() {
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public static boolean isDebuging() {
|
||||
return isDebuging;
|
||||
/**
|
||||
* 设置应用调试模式
|
||||
* @param debugging 调试模式状态(true/false)
|
||||
*/
|
||||
public static void setIsDebugging(boolean debugging) {
|
||||
isDebugging = debugging;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存调试模式状态到本地文件(持久化存储,重启应用后生效)
|
||||
* @param application 全局 Application 实例(通过 getInstance() 获取更规范)
|
||||
*/
|
||||
public static void saveDebugStatus(GlobalApplication application) {
|
||||
if (application == null) {
|
||||
LogUtils.e(TAG, "saveDebugStatus: Application 实例为空,保存失败");
|
||||
return;
|
||||
}
|
||||
// 将调试状态封装为 APPModel 并保存到文件
|
||||
APPModel.saveBeanToFile(
|
||||
getAppModelFilePath(application),
|
||||
new APPModel(isDebugging)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 APPModel 配置文件的存储路径
|
||||
* 路径:应用私有数据目录 / APPModel.json(仅当前应用可访问,安全)
|
||||
* @param application 全局 Application 实例
|
||||
* @return 配置文件绝对路径
|
||||
*/
|
||||
private static String getAppModelFilePath(GlobalApplication application) {
|
||||
return application.getDataDir().getPath() + "/APPModel.json";
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前应用调试模式状态
|
||||
* @return true:调试模式;false:正式模式
|
||||
*/
|
||||
public static boolean isDebugging() {
|
||||
return isDebugging;
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用启动时初始化(仅执行一次)
|
||||
* 初始化核心框架、恢复调试状态、配置全局异常处理等
|
||||
*/
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
// 初始化单例实例(确保在所有初始化操作前完成)
|
||||
sInstance = this;
|
||||
|
||||
setIsDebuging(true);
|
||||
// 添加日志模块
|
||||
LogUtils.init(this);
|
||||
// 设置应用异常处理窗口
|
||||
CrashHandler.init(this);
|
||||
// 初始化 Toast 框架
|
||||
ToastUtils.init(this);
|
||||
|
||||
// 应用保存的调试标志
|
||||
APPModel appModel = APPModel.loadBeanFromFile(getAPPModelFilePath(this), APPModel.class);
|
||||
// 初始化基础组件(日志、崩溃处理、Toast)
|
||||
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) {
|
||||
setIsDebuging(false);
|
||||
// 配置文件不存在,默认关闭调试模式并创建文件
|
||||
setIsDebugging(false);
|
||||
saveDebugStatus(this);
|
||||
LogUtils.d(TAG, "调试配置文件不存在,默认关闭调试模式并创建配置文件");
|
||||
} 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();
|
||||
try {
|
||||
// 获取应用信息(包含应用名称、图标等)
|
||||
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(
|
||||
context.getPackageName(), 0);
|
||||
return (String) packageManager.getApplicationLabel(applicationInfo);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
context.getPackageName(), // 当前应用包名
|
||||
0 // 额外标志(0 表示默认获取基本信息)
|
||||
);
|
||||
// 从应用信息中获取应用名称(支持多语言)
|
||||
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();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用终止时调用(仅用于释放全局资源)
|
||||
*/
|
||||
@Override
|
||||
public void onTerminate() {
|
||||
super.onTerminate();
|
||||
// 释放单例引用(可选,避免内存泄漏风险)
|
||||
sInstance = null;
|
||||
LogUtils.d(TAG, "GlobalApplication 终止,单例实例已释放");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
package cc.winboll.studio.libappbase;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2025/02/11 00:14:05
|
||||
*/
|
||||
import android.app.Activity;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
@@ -16,79 +12,175 @@ import android.view.MenuItem;
|
||||
import android.widget.Toast;
|
||||
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 {
|
||||
|
||||
private static final int MENUITEM_COPY = 0;
|
||||
private static final int MENUITEM_RESTART = 1;
|
||||
|
||||
GlobalCrashReportView mGlobalCrashReportView;
|
||||
String mLog;
|
||||
|
||||
|
||||
/** 日志标签(用于调试日志输出,唯一标识当前 Activity) */
|
||||
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
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
CrashHandler.AppCrashSafetyWire.getInstance().postResumeCrashSafetyWireHandler(getApplicationContext());
|
||||
|
||||
mLog = getIntent().getStringExtra(CrashHandler.EXTRA_CRASH_INFO);
|
||||
//setTheme(android.R.style.Theme_Holo_Light_NoActionBar);
|
||||
//setTheme(R.style.APPBaseTheme);
|
||||
// 初始化崩溃安全防护机制
|
||||
// 作用:防止应用重启后短时间内再次崩溃,由 CrashHandler 内部实现防护逻辑
|
||||
CrashHandler.AppCrashSafetyWire.getInstance()
|
||||
.postResumeCrashSafetyWireHandler(getApplicationContext());
|
||||
|
||||
// 从 Intent 中获取崩溃日志数据(EXTRA_CRASH_INFO 为 CrashHandler 定义的常量键)
|
||||
mCrashLog = getIntent().getStringExtra(CrashHandler.EXTRA_CRASH_LOG);
|
||||
|
||||
// 设置当前 Activity 的布局文件(展示崩溃报告的 UI 结构)
|
||||
setContentView(R.layout.activity_globalcrash);
|
||||
mGlobalCrashReportView = findViewById(R.id.activityglobalcrashGlobalCrashReportView1);
|
||||
mGlobalCrashReportView.setReport(mLog);
|
||||
setActionBar(mGlobalCrashReportView.getToolbar());
|
||||
|
||||
getActionBar().setTitle(CrashHandler.TITTLE);
|
||||
getActionBar().setSubtitle(GlobalApplication.getAppName(getApplicationContext()));
|
||||
|
||||
// 初始化崩溃报告展示视图(通过布局 ID 找到自定义 View 实例)
|
||||
mCrashReportView = findViewById(R.id.activityglobalcrashGlobalCrashReportView1);
|
||||
// 将崩溃日志设置到视图中,由自定义 View 负责排版和显示
|
||||
mCrashReportView.setReport(mCrashLog);
|
||||
|
||||
// 设置页面的 ActionBar(复用自定义 View 中的 Toolbar 作为系统 ActionBar)
|
||||
setActionBar(mCrashReportView.getToolbar());
|
||||
|
||||
// 配置 ActionBar 标题和副标题(非空判断避免空指针异常)
|
||||
if (getActionBar() != null) {
|
||||
// 设置标题:使用 CrashHandler 中定义的统一标题(如 "应用崩溃报告")
|
||||
getActionBar().setTitle(CrashHandler.TITTLE);
|
||||
// 设置副标题:显示当前应用名称(从全局 Application 工具方法获取)
|
||||
getActionBar().setSubtitle(GlobalApplication.getAppName(getApplicationContext()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 重写返回键点击事件
|
||||
* 逻辑:点击手机返回键时,直接重启应用(而非返回上一页,因崩溃后上一页状态可能异常)
|
||||
*/
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
restart();
|
||||
restartApp();
|
||||
}
|
||||
|
||||
private void restart() {
|
||||
PackageManager pm = getPackageManager();
|
||||
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);
|
||||
/**
|
||||
* 重启当前应用(核心工具方法)
|
||||
* 实现逻辑:
|
||||
* 1. 获取应用的启动意图(默认启动 AndroidManifest 中配置的主 Activity)
|
||||
* 2. 设置意图标志,清除原有任务栈,避免残留异常页面
|
||||
* 3. 启动主 Activity 并终止当前进程,确保应用完全重启
|
||||
*/
|
||||
private void restartApp() {
|
||||
// 获取 PackageManager 实例(用于获取应用相关信息和意图)
|
||||
PackageManager packageManager = getPackageManager();
|
||||
// 获取应用的启动意图(参数为当前应用包名,返回主 Activity 的意图)
|
||||
Intent launchIntent = packageManager.getLaunchIntentForPackage(getPackageName());
|
||||
|
||||
if (launchIntent != null) {
|
||||
// 设置意图标志:
|
||||
// FLAG_ACTIVITY_NEW_TASK:创建新的任务栈启动 Activity
|
||||
// FLAG_ACTIVITY_CLEAR_TOP:清除目标 Activity 之上的所有 Activity
|
||||
// FLAG_ACTIVITY_CLEAR_TASK:清除当前任务栈中的所有 Activity
|
||||
launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
// 启动应用主 Activity
|
||||
startActivity(launchIntent);
|
||||
}
|
||||
|
||||
// 关闭当前崩溃报告页面
|
||||
finish();
|
||||
// 终止当前应用进程(确保释放所有资源,避免内存泄漏)
|
||||
android.os.Process.killProcess(android.os.Process.myPid());
|
||||
// 强制退出虚拟机(彻底终止应用,防止残留线程继续运行)
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单项点击事件回调(实现 MenuItem.OnMenuItemClickListener 接口)
|
||||
* @param item 被点击的菜单项实例
|
||||
* @return boolean:true 表示事件已消费,不再向下传递;false 表示未消费
|
||||
*/
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
// 根据菜单项 ID 判断点击的是哪个功能
|
||||
switch (item.getItemId()) {
|
||||
case MENUITEM_COPY:
|
||||
ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
cm.setPrimaryClip(ClipData.newPlainText(getPackageName(), mLog));
|
||||
Toast.makeText(getApplication(), "The text is copied.", Toast.LENGTH_SHORT).show();
|
||||
case MENU_ITEM_COPY:
|
||||
// 点击「复制」菜单,执行复制崩溃日志到剪贴板
|
||||
copyCrashLogToClipboard();
|
||||
break;
|
||||
case MENUITEM_RESTART:
|
||||
case MENU_ITEM_RESTART:
|
||||
// 点击「重启」菜单:先恢复崩溃防护机制到最大等级,再重启应用
|
||||
CrashHandler.AppCrashSafetyWire.getInstance().resumeToMaximumImmediately();
|
||||
restart();
|
||||
restartApp();
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建页面顶部菜单(ActionBar 菜单)
|
||||
* @param menu 菜单容器,用于添加菜单项
|
||||
* @return boolean:true 表示显示菜单;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);
|
||||
|
||||
// 更新菜单文字风格
|
||||
mGlobalCrashReportView.updateMenuStyle();
|
||||
// 添加「复制」菜单项:
|
||||
// 参数说明:菜单组 ID(0 表示默认组)、菜单项 ID(MENU_ITEM_COPY)、排序号(0)、菜单文本("Copy")
|
||||
// setOnMenuItemClickListener(this):绑定点击事件到当前 Activity
|
||||
// setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM):有空间时显示在 ActionBar 上,否则放入溢出菜单
|
||||
menu.add(0, MENU_ITEM_COPY, 0, "Copy")
|
||||
.setOnMenuItemClickListener(this)
|
||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
|
||||
// 添加「重启」菜单项(参数含义同上)
|
||||
menu.add(0, MENU_ITEM_RESTART, 0, "Restart")
|
||||
.setOnMenuItemClickListener(this)
|
||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
|
||||
// 调用自定义视图的方法,更新菜单文字样式(如颜色、字体大小等,由自定义 View 内部实现)
|
||||
mCrashReportView.updateMenuStyle();
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2025/02/11 20:18:30
|
||||
* @Describe 应用崩溃报告视图
|
||||
*/
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Color;
|
||||
@@ -18,121 +13,297 @@ import android.widget.TextView;
|
||||
import android.widget.Toolbar;
|
||||
import cc.winboll.studio.libappbase.R;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||
* @Date 2025/11/11 20:21
|
||||
* @Describe 全局崩溃报告视图控件
|
||||
* 用于展示应用崩溃信息,包含顶部工具栏和崩溃日志文本区域,支持自定义配色
|
||||
*/
|
||||
public class GlobalCrashReportView extends LinearLayout {
|
||||
|
||||
public static final String TAG = "GlobalCrashReportView";
|
||||
// 日志标签
|
||||
public static final String TAG = "GlobalCrashReportView";
|
||||
|
||||
Context mContext;
|
||||
Toolbar mToolbar;
|
||||
int colorTittle;
|
||||
int colorTittleBackground;
|
||||
int colorText;
|
||||
int colorTextBackground;
|
||||
TextView mtvReport;
|
||||
// 上下文对象
|
||||
private Context mContext;
|
||||
// 顶部工具栏(标题栏)
|
||||
private Toolbar mToolbar;
|
||||
// 标题文字颜色
|
||||
private int mTitleColor;
|
||||
// 标题栏背景颜色
|
||||
private int mTitleBackgroundColor;
|
||||
// 日志文本颜色
|
||||
private int mTextColor;
|
||||
// 日志区域背景颜色
|
||||
private int mTextBackgroundColor;
|
||||
// 崩溃日志显示文本控件
|
||||
private TextView mTvReport;
|
||||
|
||||
public GlobalCrashReportView(Context context) {
|
||||
super(context);
|
||||
mContext = context;
|
||||
//initView();
|
||||
}
|
||||
/**
|
||||
* 构造方法:仅上下文
|
||||
* @param context 上下文
|
||||
*/
|
||||
public GlobalCrashReportView(Context context) {
|
||||
super(context);
|
||||
mContext = context;
|
||||
// 初始化默认配置(无自定义属性)
|
||||
initDefaultConfig();
|
||||
}
|
||||
|
||||
public GlobalCrashReportView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
mContext = context;
|
||||
initView(attrs);
|
||||
}
|
||||
/**
|
||||
* 构造方法:上下文 + 自定义属性
|
||||
* @param context 上下文
|
||||
* @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;
|
||||
//initView();
|
||||
}
|
||||
/**
|
||||
* 构造方法:上下文 + 自定义属性 + 样式属性
|
||||
* @param context 上下文
|
||||
* @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;
|
||||
//initView();
|
||||
}
|
||||
/**
|
||||
* 构造方法:上下文 + 自定义属性 + 样式属性 + 样式资源
|
||||
* @param context 上下文
|
||||
* @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);
|
||||
this.colorText = a.getColor(R.styleable.GlobalCrashActivity_colorText, Color.BLACK);
|
||||
this.colorTextBackground = a.getColor(R.styleable.GlobalCrashActivity_colorTextBackgound, Color.WHITE);
|
||||
// 返回一个绑定资源结束的信号给资源
|
||||
a.recycle();
|
||||
/**
|
||||
* 初始化默认配置(无自定义属性时使用)
|
||||
*/
|
||||
private void initDefaultConfig() {
|
||||
// 设置默认配色
|
||||
mTitleColor = Color.WHITE;
|
||||
mTitleBackgroundColor = Color.BLACK;
|
||||
mTextColor = Color.BLACK;
|
||||
mTextBackgroundColor = Color.WHITE;
|
||||
// 加载布局
|
||||
inflateView();
|
||||
// 初始化控件样式
|
||||
initWidgetStyle();
|
||||
}
|
||||
|
||||
/*this.colorTittle = Color.WHITE;
|
||||
this.colorTittleBackground = Color.BLACK;
|
||||
this.colorText = Color.BLACK;
|
||||
this.colorTextBackground = Color.WHITE;
|
||||
*/
|
||||
|
||||
inflate(mContext, R.layout.view_globalcrashreport, this);
|
||||
/**
|
||||
* 初始化视图(解析自定义属性 + 加载布局 + 设置样式)
|
||||
* @param attrs 自定义属性集合
|
||||
*/
|
||||
private void initView(AttributeSet attrs) {
|
||||
// 解析自定义属性(关联 attrs.xml 中的 GlobalCrashActivity 样式)
|
||||
TypedArray typedArray = mContext.obtainStyledAttributes(
|
||||
attrs,
|
||||
R.styleable.GlobalCrashActivity,
|
||||
R.attr.themeGlobalCrashActivity,
|
||||
0
|
||||
);
|
||||
|
||||
LinearLayout llMain = findViewById(R.id.viewglobalcrashreportLinearLayout1);
|
||||
llMain.setBackgroundColor(this.colorTextBackground);
|
||||
mToolbar = findViewById(R.id.viewglobalcrashreportToolbar1);
|
||||
mToolbar.setBackgroundColor(this.colorTittleBackground);
|
||||
mToolbar.setTitleTextColor(this.colorTittle);
|
||||
mToolbar.setSubtitleTextColor(this.colorTittle);
|
||||
mtvReport = findViewById(R.id.viewglobalcrashreportTextView1);
|
||||
mtvReport.setTextColor(this.colorText);
|
||||
mtvReport.setBackgroundColor(this.colorTextBackground);
|
||||
}
|
||||
// 读取自定义属性值(无设置时使用默认值)
|
||||
mTitleColor = typedArray.getColor(
|
||||
R.styleable.GlobalCrashActivity_colorTittle,
|
||||
Color.WHITE
|
||||
);
|
||||
mTitleBackgroundColor = typedArray.getColor(
|
||||
R.styleable.GlobalCrashActivity_colorTittleBackgound, // 注:原拼写错误(Backgound→Background),保持与 attrs.xml 一致
|
||||
Color.BLACK
|
||||
);
|
||||
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) {
|
||||
mtvReport.setText(report);
|
||||
}
|
||||
// 回收 TypedArray,避免内存泄漏
|
||||
typedArray.recycle();
|
||||
|
||||
public Toolbar getToolbar() {
|
||||
return mToolbar;
|
||||
}
|
||||
// 加载布局文件
|
||||
inflateView();
|
||||
// 初始化控件样式
|
||||
initWidgetStyle();
|
||||
}
|
||||
|
||||
//
|
||||
// 更新菜单文字风格
|
||||
//
|
||||
public void updateMenuStyle() {
|
||||
// 设置菜单文本颜色
|
||||
Menu menu = mToolbar.getMenu();
|
||||
for (int i = 0; i < menu.size(); i++) {
|
||||
MenuItem item = menu.getItem(i);
|
||||
SpannableString spanString = new SpannableString(item.getTitle().toString());
|
||||
spanString.setSpan(new ForegroundColorSpan(this.colorTittle), 0, spanString.length(), 0);
|
||||
item.setTitle(spanString);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 加载布局文件
|
||||
*/
|
||||
private void inflateView() {
|
||||
// 加载自定义布局(R.layout.view_globalcrashreport)
|
||||
inflate(mContext, R.layout.view_globalcrashreport, this);
|
||||
// 绑定控件
|
||||
mToolbar = findViewById(R.id.viewglobalcrashreportToolbar1);
|
||||
mTvReport = findViewById(R.id.viewglobalcrashreportTextView1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化控件样式(设置配色和基础属性)
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2025/03/25 20:34:47
|
||||
* @Describe 应用日志窗口
|
||||
*/
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -12,35 +7,59 @@ import android.os.Bundle;
|
||||
import cc.winboll.studio.libappbase.LogView;
|
||||
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 {
|
||||
|
||||
/** 日志标签,用于当前 Activity 的日志输出标识 */
|
||||
public static final String TAG = "LogActivity";
|
||||
|
||||
LogView mLogView;
|
||||
/** 日志展示控件(用于加载和显示应用日志) */
|
||||
private LogView mLogView;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// 设置布局文件(包含 LogView 控件)
|
||||
setContentView(R.layout.activity_log);
|
||||
//ToastUtils.show("LogActivity onCreate");
|
||||
|
||||
// 绑定布局中的 LogView 控件
|
||||
mLogView = findViewById(R.id.logview);
|
||||
// 启动 LogView 日志加载(如实时刷新日志内容)
|
||||
mLogView.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
// 恢复 Activity 时重新启动 LogView(确保日志持续更新)
|
||||
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 标志:创建新任务栈(避免并入调用者任务栈)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
// 添加 Intent 标志:标记为新文档(多任务窗口中独立显示)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
|
||||
// 添加 Intent 标志:允许创建多个任务实例(支持多次启动独立窗口)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
|
||||
|
||||
// 启动 Activity
|
||||
context.startActivity(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user