Compare commits
162 Commits
originmast
...
4c856367f5
| Author | SHA1 | Date | |
|---|---|---|---|
| 4c856367f5 | |||
| 63580b111c | |||
| 3b60a3b713 | |||
| c6591e83a5 | |||
| 7119b3b7a5 | |||
| 48d36c6d96 | |||
| 2850d3ca3b | |||
| 74443950c4 | |||
| 0607af429b | |||
| 55baf0afac | |||
| 1d0dec8de5 | |||
| 39e825f03e | |||
| cd0599d639 | |||
| aef5a62e47 | |||
| 06253feba8 | |||
| 1dbca0f290 | |||
| 14d0227158 | |||
| 3fcdbabcc9 | |||
| f3b3036591 | |||
| 28ecc605e1 | |||
| 523a8e49e0 | |||
| 59a9e0ee45 | |||
| cbf1341435 | |||
| dadf573675 | |||
| 7420a5cd48 | |||
| dc6a589db4 | |||
| e3f47043ef | |||
| a825951aad | |||
| 79cb841349 | |||
| d3c40efffa | |||
| 4baee6f0e1 | |||
| 8f6b615949 | |||
| d02d57d4dd | |||
| e337bb7a04 | |||
| 9ae848e4c2 | |||
| 9c66f61891 | |||
| bfaf3543b9 | |||
| b44fe3aaf3 | |||
| d518ac50a9 | |||
| d532eae971 | |||
| f661acbbbc | |||
| ecced75a4d | |||
| 5e5d34c90c | |||
| 85a0d39498 | |||
| c542d8dca7 | |||
| ccbdb4010e | |||
| fe4060f00e | |||
| 676a3466ef | |||
| d6243b052d | |||
| 2e7b9173f2 | |||
| 4f12a5de4f | |||
| 7ab399e520 | |||
| dd2d9f3e55 | |||
| 098516d4d7 | |||
| 5d72ee1a6a | |||
| b1fab5ce46 | |||
| eeb64b00b8 | |||
| 8bcd803404 | |||
| 76d20c32bf | |||
| e68098aa10 | |||
| d673ba46a1 | |||
| 3231cd557a | |||
| 6c8867e15c | |||
| 5a1342156f | |||
| 4e1784d99f | |||
| 069e5a66ad | |||
| e9a1dca8ca | |||
| 7e3a3d1446 | |||
| 7414cd0f33 | |||
| b2b3f949b7 | |||
| 83c1b888b6 | |||
| 6afc81939d | |||
| 1cf4c67b4f | |||
| 89697f8c49 | |||
| 5419fad1cf | |||
| 610d3811db | |||
| 2d949eb5a3 | |||
| e6940805d9 | |||
| 1641424276 | |||
| 5d1cdff283 | |||
| da66cea1e5 | |||
| 5eb7441dc7 | |||
| 5f3168e17f | |||
| e3c4bab6c9 | |||
| 2af6427ca8 | |||
| b8c70bef98 | |||
| 7713d6c460 | |||
| 73c69bd665 | |||
| a076fe50cd | |||
| 1512b76c36 | |||
| 850b9af6ec | |||
| 31c1592086 | |||
| b3976a8633 | |||
| ea896228d7 | |||
| d49ecb3943 | |||
| ad3aecf867 | |||
| c417d9732a | |||
| 7bd1357c8c | |||
| 16a2c3c0c8 | |||
| b747d83972 | |||
| f2788dda96 | |||
| ea3a66bebe | |||
| a53a0cbcdc | |||
| 65f0515139 | |||
| 5316ac1815 | |||
| 6c2581276e | |||
| 17d1c2f321 | |||
| 9e2affbc4d | |||
| aed4aa1a86 | |||
| 447b7fa5a8 | |||
| dae39b43d6 | |||
| 530316b976 | |||
| 3f924b004c | |||
| 1db94b52e6 | |||
| 55c653af09 | |||
| 9d97d6ed94 | |||
| e21bb9058d | |||
| ad6175f977 | |||
| 8b659f4b24 | |||
| 13b841f923 | |||
| e9ad701db4 | |||
| 0aaf71f285 | |||
| 4ea2b5fad0 | |||
| 760fe4613f | |||
| a656dfcc62 | |||
| e9605fa991 | |||
| 8546b6c8ad | |||
| f5ddefa895 | |||
| 35527374da | |||
| 2751ce4a39 | |||
| 730022a9f0 | |||
| a3bc90d9b8 | |||
| 32ee7c8845 | |||
| 6e34ee73e9 | |||
| 7eed7357f0 | |||
| d20192cb36 | |||
| 5846784940 | |||
| ef64d6a317 | |||
| 8b2a8328eb | |||
| 88a20d9a85 | |||
| aeaea253cb | |||
| 4890ca42cc | |||
| 2896b6401b | |||
| 1aa270482e | |||
| 3f544f6097 | |||
| 6b44f852a8 | |||
| 952c8d8017 | |||
| 80b4b87e95 | |||
| 8b99844d0c | |||
| 9f46f400b0 | |||
| 40ea79c6b7 | |||
| 64693e384e | |||
| aebf83bc44 | |||
| 7ae716bccb | |||
| 3e67a5d0a4 | |||
| 05a1fb1302 | |||
| aa2e8e1a72 | |||
| 622d474410 | |||
| 504b78c04e | |||
| 7ee79a44c7 | |||
| e459791c67 | |||
| 749ec3d562 |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -97,10 +97,5 @@ lint-results.html
|
||||
## WinBoLL 基础应用(避免上传敏感配置)
|
||||
/winboll.properties
|
||||
/local.properties
|
||||
|
||||
## WinBoLL 衍生应用,
|
||||
## 外派类型类库应用需要注释掉以下部分,以便部署通用类库编译配置。
|
||||
## APPBase,AES需要上传以下两种配置。
|
||||
## OriginMaster 仓库合并各类分支需要忽略的文件修改
|
||||
/settings.gradle
|
||||
/gradle.properties
|
||||
|
||||
@@ -66,8 +66,8 @@ android {
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_11
|
||||
targetCompatibility JavaVersion.VERSION_11
|
||||
sourceCompatibility JavaVersion.VERSION_1_7
|
||||
targetCompatibility JavaVersion.VERSION_1_7
|
||||
}
|
||||
|
||||
// 应用包输出配置
|
||||
@@ -101,12 +101,15 @@ android {
|
||||
|
||||
// 创建 WinBoLL Studio 发布接口文件夹
|
||||
File fWinBoLLStudioDir = file("/sdcard/WinBoLLStudio/APKs");
|
||||
// 如果配置了APK接口文件夹路径,就设置应用APK输出文件夹为接口文件夹。
|
||||
if(winbollProps != null && winbollProps['APKOutputPath'] != null ) {
|
||||
fWinBoLLStudioDir = file(winbollProps['APKOutputPath']);
|
||||
}
|
||||
|
||||
if(!fWinBoLLStudioDir.exists()) {
|
||||
//fWinBoLLStudioDir.mkdirs();
|
||||
// 如果没有发布接口文件就不用进行APK发布和源码管理操作
|
||||
// 当前编译环境不是 WinBoLL 主机, 以下将忽略APK发布和源码管理操作。
|
||||
println 'The current compilation environment is not in WinBoLL host, and the following APK publishing and source management operations will be ignore.'
|
||||
} else {
|
||||
println "[ WinBoLLStudio ] : " + fWinBoLLStudioDir.getAbsolutePath() + " Folder does not exist."
|
||||
println '[ WinBoLLStudio ] : The APKOutputPath property is not defined in winboll.properties, please configure APK output folder first.'
|
||||
} else {
|
||||
/// WINBOLL 主机的 APK 发布和源码管理操作 ///
|
||||
variant.getAssembleProvider().get().doFirst {
|
||||
/* 后期管理预留代码 */
|
||||
|
||||
207
README.md
207
README.md
@@ -1,104 +1,105 @@
|
||||
WinBoLL 源生态计划项目说明书
|
||||
# WinBoLL 源生态计划项目说明书
|
||||
|
||||
## 一、项目概述
|
||||
|
||||
### 1. 核心定位
|
||||
WinBoLL 手机源码计划,旨在通过核心项目 WinBoLL 构建手机端与服务器端的 Android 项目的开发源码生态。实现手机与服务器的源码的联合开发。
|
||||
|
||||
### 2. 仓库架构
|
||||
#### **仓库类型:功能说明**
|
||||
☆ 基础项目分支 WinBoLL:手机端安卓应用开发基础模板。
|
||||
☆ 应用项目分支 APPBase、AES、PowerBell、Positions**:安卓应用单一管理系列项目。
|
||||
☆ 源码汇总管理 OriginMaster**:各类分支源码合并存档,不适宜作为开发库使用。
|
||||
|
||||
### 3. 源码合并管理推送路线图
|
||||
⚠️ **注意**:仅仅展示不同应用模块源码的综合管理路线。分支合并操作时,必须具备 Git 管理经验。
|
||||
|
||||
★ WinBoLL → APPBase → OriginMaster
|
||||
★ WinBoLL → AES → OriginMaster
|
||||
★ WinBoLL → PowerBell → OriginMaster
|
||||
★ WinBoLL → Positions → OriginMaster
|
||||
|
||||
## 二、WinBoLL 项目核心信息
|
||||
|
||||
### 1. 项目简介
|
||||
☆ WinBoLL 项目是为手机端开发Android 项目的需求而设计的项目。
|
||||
|
||||
### 2. 官方资源
|
||||
#### ☆ 官方网站**:https://www.winboll.cc/
|
||||
#### ☆ 源码地址:
|
||||
★ Gitea:https://gitea.winboll.cc/Studio/WinBoLL.git
|
||||
★ GitHub:https://github.com/ZhanGSKen/WinBoLL.git
|
||||
★ 码云:https://gitee.com/zhangsken/winboll.git
|
||||
|
||||
## 三、应用编译环境检查问题
|
||||
### 核心判断条件:
|
||||
☆ WinBoLL 项目以文件夹 `"/sdcard/WinBoLLStudio/APKs"` 是否存在为判断环境编译输出条件,因为编译输出的APK文件需要一个可供保存的环境。
|
||||
|
||||
☆ 文件夹"/sdcard/WinBoLLStudio/APKs" 目录条件设置方法:
|
||||
***Linux 服务器端方面***:建立 `/sdcard/WinBoLLStudio/APKs` 目录即可。
|
||||
***手机开发端方面***:建立 `"/sdcard/WinBoLLStudio/APKs"` 目录(即 `"/storage/emulated/0/WinBoLLStudio/APKs"` 目录) 即可。
|
||||
|
||||
## 四、前置条件
|
||||
|
||||
### 1. WinBoLL APP 开发环境配置介绍
|
||||
#### WinBoLL APK 编译输出内容包括:
|
||||
☆ "/sdcard/WinBoLLStudio/APKs"` 目录内的所有应用分支的 APK 文件。
|
||||
winboll.properties 文件的 APKOutputPath 属性可配置这个 APK 输出目录的路径。
|
||||
☆ "/sdcard/AppProjects/app.apk"文件。
|
||||
winboll.properties 文件的 ExtraAPKOutputPath 属性可配置这个 APK 额外输出文件的路径
|
||||
#### WinBoLL APK 源码命名空间规范
|
||||
☆ WinBoLL 项目使用 "cc.winboll.studio" 作为源码命名空间。在此命名空间下进行源码定义。
|
||||
|
||||
## 五、核心需求规划
|
||||
|
||||
### 1. WinBoLL 应用安全验证需求
|
||||
#### ☆ 支持访问 https://console.winboll.cc/ 服务器以校验应用包签名与版本。
|
||||
|
||||
### 2. 手机端源码开发管理需求
|
||||
#### ☆ 支持切换不同 WinBoLL 分支,以开发不同安卓应用。
|
||||
|
||||
## 六、编译与使用指南
|
||||
|
||||
### 1. 项目初始化(必须)
|
||||
#### 1. 复制 `settings.gradle-demo` 为 `settings.gradle`。编辑 `settings.gradle` 文件内容,取消对应项目模块注释。
|
||||
#### 2. 复制 `gradle.properties-androidx-demo` (Android X 项目) 或 `gradle.properties-android-demo` (基本 Android 项目) 为 `gradle.properties`。
|
||||
#### 3. 复制(可选)`local.properties-demo` 为 `local.properties`,编辑 `local.properties` 文件内容,配置 Android SDK 目录。
|
||||
#### 4. **签名设置**:
|
||||
☆ **调试编译秘钥制作**:使用 Termux 应用终端,cd 进入 GenKeyStore 目录,运行 `bash gen_debug_keystore.sh` 脚本即可生成应用调试秘钥。
|
||||
☆ **应用秘钥配置方法**:拷贝调试编译秘钥制作生成的 `appkey.jks` 与 `appkey.keystore` 文件到项目根目录即可。
|
||||
|
||||
## 七、应用编译命令介绍
|
||||
|
||||
### (1)类库型模块配置要点
|
||||
#### 1. **优先修改配置文件**:优先修改应用测试项目(目录为 `"<WinBoLl根目录>/<类库测试应用>/"`)内 `build.properties` 文件,设置对应的类库项目名称:`libraryProject=<类库项目模块名>`。
|
||||
#### 2. **编译优先启动步骤**:使用 Termux 应用,进入 `"<WinBoLl根目录>"`,运行 `$ bash .winboll/bashPublishAPKAddTag.sh <类库测试项目模块名>` 命令。运行后可生成测试项目与类库项目的编译参数文件 `build.properties`。生成的 `build.properties` 文件有两份,一份在测试项目模块的文件夹内,一份在类库项目本身的模块文件夹内。
|
||||
#### 3. **最后类库编译发布步骤**:使用 Termux 应用,进入 `"<WinBoLl根目录>"`,运行 `$ bash .winboll/bashPublishLIBAddTag.sh <类库项目模块名>` 命令。运行后可发布至 WinBoLL Nexus Maven 库、本地 maven 目录或者是通用默认的 Gradle Maven 库。
|
||||
|
||||
### (2)单一应用型模块与类库测试型模块配置要点
|
||||
#### ☆ APK 编译方法:
|
||||
使用 Termux 应用,进入 `"<WinBoLl根目录>"`,运行 `$ bash .winboll/bashPublishAPKAddTag.sh <应用项目模块名>`。
|
||||
#### ☆ 运行后的 APK 输出路径:
|
||||
★ 默认路径 (`$ bash gradlew assembleBetaDebug` 任务):APK 在 `/sdcard/WinBoLLStudio/APKs/<项目根目录名称>/debug/` 目录。
|
||||
★ 默认路径 (`$ bash assembleStageRelease` 任务):APK 在 `/sdcard/WinBoLLStudio/APKs/<项目根目录名称>/tag/` 目录。
|
||||
★ 额外输出路径:(假设 `winboll.properties` 文件已配置 `ExtraAPKOutputPath` 属性) 输出至 `ExtraAPKOutputPath` 属性配置的目录下。
|
||||
|
||||
### (3)手机端应用调试命令介绍
|
||||
#### ☆ Beta 渠道调试命令
|
||||
$bash gradlew assembleBetaDebug
|
||||
|
||||
#### ☆ Stage 渠道调试命令
|
||||
$bash gradlew assembleStageDebug
|
||||
|
||||
### (4)服务器端开发命令介绍
|
||||
##### ☆ Stage 渠道应用发布命令为:
|
||||
("<WinBoLl根目录>/settings.gradle"文件需要配置编译模块开启参数,拷贝 settings.gradle-demo 为 settings.gradle 文件取消对应的分支配置部分即可。)
|
||||
$bash .winboll/bashPublishAPKAddTag.sh <应用项目模块名>
|
||||
或者是
|
||||
$bash gradlew assembleStageRelease
|
||||
|
||||
一、项目概述
|
||||
|
||||
1. 核心定位
|
||||
|
||||
【OriginMaster】WinBoLL 源生态计划,旨在通过核心项目 WinBoLL 联动系列开发库,构建手机端 Android 项目开发与多端编译同步的完整生态,实现手机与电脑的源码同步开发。
|
||||
|
||||
2. 仓库架构
|
||||
|
||||
仓库类型 包含仓库 功能说明
|
||||
开发库 WinBoLL、APPBase、AES、PowerBell、Positions 核心开发依赖库,其中 WinBoLL 可作为应用开发的基础继承模板
|
||||
分支汇总存档库 OriginMaster 仅用于汇总各开发库分支,不适宜作为开发库克隆使用,非应用开发基础库
|
||||
|
||||
3. 源码推送路径
|
||||
|
||||
- WinBoLL → APPBase → OriginMaster
|
||||
- WinBoLL → AES → OriginMaster
|
||||
- WinBoLL → PowerBell → OriginMaster
|
||||
- WinBoLL → Positions → OriginMaster
|
||||
|
||||
二、WinBoLL APP 核心信息
|
||||
|
||||
1. 项目简介
|
||||
|
||||
WinBoLL Studio Android 应用开源项目,专注于手机端 Android 开发与多端编译同步。
|
||||
|
||||
2. 官方资源
|
||||
|
||||
- 官方网站:https://www.winboll.cc/
|
||||
- 源码地址:
|
||||
- Gitea:https://gitea.winboll.cc/Studio/WinBoLL.git
|
||||
- GitHub:https://github.com/ZhanGSKen/WinBoLL.git
|
||||
- 码云:https://gitee.com/zhangsken/winboll.git
|
||||
- 托管类库源码:
|
||||
- APPBase(jitpack.io):https://github.com/ZhanGSKen/APPBase.git
|
||||
- AES(jitpack.io):https://github.com/ZhanGSKen/AES.git
|
||||
|
||||
三、通用特征文件夹前置(/sdcard)
|
||||
|
||||
- Linux 系统文件夹直接使用 /sdcard 。
|
||||
- 手机 SD 卡存储( /storage/emulated/0 )挂载的别名也可为 /sdcard 。
|
||||
|
||||
四、前置条件
|
||||
|
||||
1. WinBoLL-APP 配置
|
||||
|
||||
- APK 编译输出目录: /sdcard/WinBoLLStudio/APKs/ ,以及 /sdcard/AppProjects/ (命名为 app.apk )
|
||||
- 签名与命名空间:支持应用签名验证定制化,与衍生 APP 共享 cc.winboll.studio 命名空间
|
||||
|
||||
五、核心需求规划
|
||||
|
||||
1. 主机端需求
|
||||
|
||||
- 支持 winboll.cc 域名的用户注册登录服务
|
||||
- 支持 https://console.winboll.cc/api 访问
|
||||
|
||||
2. APP 端需求
|
||||
|
||||
- 实现手机端 Android 应用开发与管理功能
|
||||
|
||||
六、编译与使用指南
|
||||
|
||||
1. 项目初始化(必须)
|
||||
|
||||
1. 复制 settings.gradle-demo 为 settings.gradle ,取消对应项目模块注释
|
||||
2. 复制 gradle.properties-androidx-demo 或 gradle.properties-android-demo 为 gradle.properties
|
||||
3. (可选)复制 local.properties-demo 为 local.properties ,配置 Android SDK 目录
|
||||
4. 签名设置:
|
||||
- 调试编译:进入 GenKeyStore 目录执行 bash gen_debug_keystore.sh
|
||||
- 非必须:clone keystore 模块,拷贝 appkey.jks 与 appkey.keystore 到项目根目录
|
||||
|
||||
2. 编译命令
|
||||
|
||||
(1)类库型项目
|
||||
|
||||
1. 修改测试项目 build.properties ,设置 libraryProject=<类库项目模块名>
|
||||
2. 编译测试项目: bash .winboll/bashPublishAPKAddTag.sh <应用项目模块名>
|
||||
3. 编译类库项目: bash .winboll/bashPublishLIBAddTag.sh <类库项目模块名> (发布至 WinBoLL Nexus Maven 库)
|
||||
|
||||
(2)应用型项目
|
||||
|
||||
- 编译命令: bash .winboll/bashPublishAPKAddTag.sh <应用项目模块名>
|
||||
|
||||
(3)调试编译
|
||||
|
||||
- Beta 调试: bash gradlew assembleBetaDebug
|
||||
- Stage 调试: bash gradlew assembleStageDebug
|
||||
|
||||
(4)发布编译
|
||||
|
||||
- Stage 发布:bash .winboll/bashPublishAPKAddTag.sh <应用项目模块名>
|
||||
或者执行 bash gradlew assembleStageRelease
|
||||
|
||||
3. 编译输出路径
|
||||
|
||||
- 默认路径(assembleBetaDebug任务): /sdcard/WinBoLLStudio/APKs/<项目根目录名称>/debug/
|
||||
- 默认路径(assembleStageRelease任务): /sdcard/WinBoLLStudio/APKs/<项目根目录名称>/tag/
|
||||
- 额外路径:若 winboll.properties 配置 ExtraAPKOutputPath ,APK 同步拷贝至该ExtraAPKOutputPath路径
|
||||
|
||||
4. 版本号命名规则
|
||||
|
||||
- Stage 渠道: V<应用开发环境编号><应用功能变更号><应用调试阶段号> (示例: APPBase_15.7.0 )
|
||||
- Beta 渠道: V<应用开发环境编号><应用功能变更号><应用调试阶段号>-beta<调试编译计数>_<调试编译时间(分钟+秒钟)> (示例: APPBase_15.9.6-beta8_5413 )
|
||||
|
||||
## 八、WinBoLL 应用 APK 版本号命名规则
|
||||
### ☆ Stage 渠道:
|
||||
#### V<应用开发环境编号><应用功能变更号><应用调试阶段号> (示例: APPBase_15.7.0 )
|
||||
### ☆ Beta 渠道:
|
||||
#### V<应用开发环境编号><应用功能变更号><应用调试阶段号>-beta<调试编译计数>_<调试编译时间(分钟+秒钟)> (示例: APPBase_15.9.6-beta8_5413 )
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Tue Jan 13 03:37:56 HKT 2026
|
||||
stageCount=2
|
||||
#Sat Apr 25 04:16:42 HKT 2026
|
||||
stageCount=10
|
||||
libraryProject=libaes
|
||||
baseVersion=15.15
|
||||
publishVersion=15.15.1
|
||||
publishVersion=15.15.9
|
||||
buildCount=0
|
||||
baseBetaVersion=15.15.2
|
||||
baseBetaVersion=15.15.10
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="cc.winboll.studio.aes">
|
||||
|
||||
<!-- 对正在运行的应用重新排序 -->
|
||||
<uses-permission android:name="android.permission.REORDER_TASKS"/>
|
||||
|
||||
<application
|
||||
android:name=".App"
|
||||
android:allowBackup="true"
|
||||
|
||||
@@ -1,22 +1,29 @@
|
||||
package cc.winboll.studio.aes;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Toolbar;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import cc.winboll.studio.aes.R;
|
||||
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.models.APPInfo;
|
||||
import cc.winboll.studio.libappbase.views.AboutView;
|
||||
|
||||
/**
|
||||
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2026/01/11 15:16
|
||||
* @Date 2026/01/13 11:25
|
||||
* @Describe 应用介绍窗口
|
||||
*/
|
||||
public class AboutActivity extends Activity {
|
||||
public class AboutActivity extends BaseWinBoLLActivity {
|
||||
|
||||
public static final String TAG = "AboutActivity";
|
||||
|
||||
private Toolbar mToolbar;
|
||||
|
||||
@Override
|
||||
public String getTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -24,21 +31,33 @@ public class AboutActivity extends Activity {
|
||||
setContentView(R.layout.activity_about);
|
||||
|
||||
// 设置工具栏
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setActionBar(toolbar);
|
||||
getActionBar().setSubtitle(TAG);
|
||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish(); // 点击导航栏返回按钮,触发 finish()
|
||||
}
|
||||
});
|
||||
initToolbar();
|
||||
|
||||
AboutView aboutView = findViewById(R.id.aboutview);
|
||||
aboutView.setAPPInfo(genDefaultAppInfo());
|
||||
}
|
||||
|
||||
private void initToolbar() {
|
||||
LogUtils.d(TAG, "initToolbar() 开始初始化");
|
||||
mToolbar = findViewById(R.id.toolbar);
|
||||
if (mToolbar == null) {
|
||||
LogUtils.e(TAG, "initToolbar() | Toolbar未找到");
|
||||
return;
|
||||
}
|
||||
setSupportActionBar(mToolbar);
|
||||
mToolbar.setSubtitle(getTag());
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
LogUtils.d(TAG, "导航栏 点击返回按钮");
|
||||
WinBoLLActivityManager.getInstance().resumeActivity(MainActivity.class);
|
||||
WinBoLLActivityManager.getInstance().finish(AboutActivity.this);
|
||||
}
|
||||
});
|
||||
LogUtils.d(TAG, "initToolbar() 配置完成");
|
||||
}
|
||||
|
||||
private APPInfo genDefaultAppInfo() {
|
||||
LogUtils.d(TAG, "genDefaultAppInfo() 调用");
|
||||
String branchName = "aes";
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package cc.winboll.studio.aes;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
|
||||
import cc.winboll.studio.libaes.models.AESThemeBean;
|
||||
import cc.winboll.studio.libaes.utils.AESThemeUtil;
|
||||
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
|
||||
|
||||
/**
|
||||
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2026/01/13 16:35
|
||||
* @Describe BaseWinBollActivity 【继承AppCompatActivity,保留核心能力,不额外暴露方法】
|
||||
* 继承链路:BaseWinBoLLActivity → AppCompatActivity → FragmentActivity,AppCompat能力天然继承可用
|
||||
*/
|
||||
public abstract class BaseWinBoLLActivity extends AppCompatActivity implements IWinBoLLActivity {
|
||||
public static final String TAG = "BaseWinBoLLActivity";
|
||||
|
||||
protected volatile AESThemeBean.ThemeType mThemeType;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
mThemeType = AESThemeBean.getThemeStyleType(AESThemeUtil.getThemeTypeID(getApplicationContext()));
|
||||
setTheme(AESThemeUtil.getThemeTypeID(getApplicationContext()));
|
||||
super.onCreate(savedInstanceState);
|
||||
WinBoLLActivityManager.getInstance().add(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
WinBoLLActivityManager.getInstance().registeRemove(this);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
// 子类必须实现getTag(),确保唯一标识
|
||||
@Override
|
||||
public abstract String getTag();
|
||||
|
||||
@Override
|
||||
public Activity getActivity() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import cc.winboll.studio.libappbase.LogUtils;
|
||||
import com.a4455jkjh.colorpicker.ColorPickerDialog;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class MainActivity extends DrawerFragmentActivity implements IWinBoLLActivity {
|
||||
public class MainActivity extends DrawerFragmentActivity {
|
||||
|
||||
|
||||
public static final String TAG = "MainActivity";
|
||||
@@ -38,11 +38,6 @@ public class MainActivity extends DrawerFragmentActivity implements IWinBoLLActi
|
||||
TestAButtonFragment mTestAButtonFragment;
|
||||
TestViewPageFragment mTestViewPageFragment;
|
||||
|
||||
@Override
|
||||
public Activity getActivity() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTag() {
|
||||
return TAG;
|
||||
@@ -188,8 +183,9 @@ public class MainActivity extends DrawerFragmentActivity implements IWinBoLLActi
|
||||
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);
|
||||
// Intent intent = new Intent(this, AboutActivity.class);
|
||||
// startActivity(intent);
|
||||
WinBoLLActivityManager.getInstance().startWinBoLLActivity(this, AboutActivity.class);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -55,6 +55,6 @@ public class WinBoLLActivity extends AppCompatActivity implements IWinBoLLActivi
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
WinBoLLActivityManager.getInstance().registeRemove(this);
|
||||
WinBoLLActivityManager.getInstance().finish(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<android.widget.Toolbar
|
||||
<cc.winboll.studio.libaes.views.ASupportToolbar
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/toolbar"/>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Tue Jan 13 03:23:34 HKT 2026
|
||||
stageCount=5
|
||||
#Tue Apr 28 17:08:30 HKT 2026
|
||||
stageCount=22
|
||||
libraryProject=libappbase
|
||||
baseVersion=15.15
|
||||
publishVersion=15.15.4
|
||||
publishVersion=15.15.21
|
||||
buildCount=0
|
||||
baseBetaVersion=15.15.5
|
||||
baseBetaVersion=15.15.22
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="app_name">AppBase+</string>
|
||||
<string name="app_name">APPBase+</string>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -16,6 +16,17 @@
|
||||
android:label="@string/app_name"
|
||||
android:exported="true"
|
||||
android:resizeableActivity="true"
|
||||
android:launchMode="singleTop"
|
||||
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation">
|
||||
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".MainActivityAlias"
|
||||
android:label="@string/app_name"
|
||||
android:exported="true"
|
||||
android:resizeableActivity="true"
|
||||
android:launchMode="singleTop"
|
||||
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation">
|
||||
|
||||
<intent-filter>
|
||||
@@ -30,6 +41,17 @@
|
||||
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".Main2Activity"
|
||||
android:label="@string/app_name"
|
||||
android:exported="true"
|
||||
android:resizeableActivity="true"
|
||||
android:launchMode="singleTop"
|
||||
android:taskAffinity="cc.winboll.studio.appbase.Main2Activity"
|
||||
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation">
|
||||
|
||||
</activity>
|
||||
|
||||
<activity android:name=".GlobalApplication$CrashActivity"/>
|
||||
|
||||
<meta-data
|
||||
|
||||
@@ -23,17 +23,8 @@ public class AboutActivity extends Activity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_about);
|
||||
|
||||
// 设置工具栏
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setActionBar(toolbar);
|
||||
getActionBar().setSubtitle(TAG);
|
||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish(); // 点击导航栏返回按钮,触发 finish()
|
||||
}
|
||||
});
|
||||
setActionBar(toolbar);
|
||||
|
||||
AboutView aboutView = findViewById(R.id.aboutview);
|
||||
aboutView.setAPPInfo(genDefaultAppInfo());
|
||||
@@ -43,10 +34,10 @@ public class AboutActivity extends Activity {
|
||||
LogUtils.d(TAG, "genDefaultAppInfo() 调用");
|
||||
String branchName = "appbase";
|
||||
APPInfo appInfo = new APPInfo();
|
||||
appInfo.setAppName(getString(R.string.app_name));
|
||||
appInfo.setAppName("APPBase");
|
||||
appInfo.setAppIcon(R.drawable.ic_winboll);
|
||||
appInfo.setAppDescription(getString(R.string.app_description));
|
||||
appInfo.setAppGitName("APPBase");
|
||||
appInfo.setAppGitName("WinBoLL");
|
||||
appInfo.setAppGitOwner("Studio");
|
||||
appInfo.setAppGitAPPBranch(branchName);
|
||||
appInfo.setAppGitAPPSubProjectFolder(branchName);
|
||||
|
||||
@@ -21,9 +21,12 @@ public class App extends GlobalApplication {
|
||||
*/
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate(); // 调用父类初始化逻辑(如基础库配置、全局上下文设置)
|
||||
//setIsDebugging(false);
|
||||
setIsDebugging(BuildConfig.DEBUG);
|
||||
super.onCreate();
|
||||
// 如果应用不在调试状态,就根据编译类型设置调试状态
|
||||
if (isDebugging() != true) {
|
||||
setIsDebugging(BuildConfig.DEBUG);
|
||||
}
|
||||
|
||||
// 初始化 Toast 工具类(传入应用全局上下文,确保 Toast 可在任意地方调用)
|
||||
ToastUtils.init(getApplicationContext());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package cc.winboll.studio.appbase;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.widget.Toolbar;
|
||||
import cc.winboll.studio.appbase.R;
|
||||
|
||||
public class Main2Activity extends MainActivity {
|
||||
|
||||
public static final String TAG = "Main2Activity";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main2);
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
if (toolbar != null) {
|
||||
setActionBar(toolbar);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Toolbar;
|
||||
import cc.winboll.studio.appbase.R;
|
||||
import cc.winboll.studio.appbase.model.TestBean;
|
||||
import cc.winboll.studio.libappbase.LogActivity;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.ToastUtils;
|
||||
@@ -36,13 +37,28 @@ public class MainActivity extends Activity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
ToastUtils.show("onCreate"); // 显示 Activity 创建提示(调试用)
|
||||
//ToastUtils.show("onCreate"); // 显示 Activity 创建提示(调试用)
|
||||
setContentView(R.layout.activity_main); // 加载主界面布局
|
||||
|
||||
// 初始化 Toolbar 并设置为 ActionBar
|
||||
mToolbar = findViewById(R.id.toolbar);
|
||||
setActionBar(mToolbar); // 将 Toolbar 替代系统默认 ActionBar
|
||||
|
||||
initTestData();
|
||||
}
|
||||
|
||||
void initTestData() {
|
||||
TestBean bean1 = new TestBean();
|
||||
bean1.setTestNum1(456);
|
||||
TestBean.saveBeanToFile(getFilesDir().getAbsolutePath() + getTestBeanRelativePath(), bean1);
|
||||
TestBean bean2 = new TestBean();
|
||||
bean2.setTestNum1(789);
|
||||
TestBean.saveBeanToFile(getExternalFilesDir(null).getAbsolutePath() + getTestBeanRelativePath(), bean2);
|
||||
}
|
||||
|
||||
String getTestBeanRelativePath() {
|
||||
return "/BaseBaen/"+TestBean.class.getName()+".json";
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建菜单时回调(加载工具栏菜单)
|
||||
@@ -87,14 +103,17 @@ public class MainActivity extends Activity {
|
||||
}
|
||||
}
|
||||
|
||||
public void onLogTestNewTask(View view) {
|
||||
LogActivity.startLogActivity(this, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 日志测试按钮点击事件(打开日志查看界面)
|
||||
* 启动 LogActivity,用于查看应用运行日志
|
||||
* @param view 触发事件的 View(对应布局中的日志测试按钮)
|
||||
*/
|
||||
public void onLogTest(View view) {
|
||||
// 启动日志查看 Activity(通过静态方法传入上下文,简化跳转逻辑)
|
||||
LogActivity.startLogActivity(this);
|
||||
LogActivity.startLogActivity(this, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,12 +155,41 @@ public class MainActivity extends Activity {
|
||||
// 启动意图(唤起浏览器)
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
|
||||
public void onAboutActivity(View view) {
|
||||
LogUtils.d(TAG, "startAboutActivity() 调用");
|
||||
LogUtils.d(TAG, "onAboutActivity() 调用");
|
||||
Intent aboutIntent = new Intent(getApplicationContext(), AboutActivity.class);
|
||||
startActivity(aboutIntent);
|
||||
LogUtils.d(TAG, "startAboutActivity: 关于页面已启动");
|
||||
}
|
||||
|
||||
public void onSplitScreenMode(View view) {
|
||||
LogUtils.d(TAG, "onSplitScreenMode() 分屏测试按钮已点击");
|
||||
ToastUtils.show("分屏测试:已启动新窗口");
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
|
||||
android.graphics.Rect bounds = new android.graphics.Rect();
|
||||
getWindow().getDecorView().getDisplay().getRectSize(bounds);
|
||||
int height = bounds.height();
|
||||
int width = bounds.width();
|
||||
bounds.set(0, 0, width, height / 2);
|
||||
LogUtils.d(TAG, "onSplitScreenMode() 分屏窗口范围: " + bounds);
|
||||
android.content.Intent intent = new android.content.Intent(this, MainActivityAlias.class);
|
||||
intent.setFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
LogUtils.d(TAG, "onSplitScreenMode() 准备启动MainActivityAlias");
|
||||
android.app.ActivityOptions options = android.app.ActivityOptions.makeBasic();
|
||||
options.setLaunchBounds(bounds);
|
||||
startActivity(intent, options.toBundle());
|
||||
LogUtils.d(TAG, "onSplitScreenMode() MainActivityAlias已启动");
|
||||
}
|
||||
}
|
||||
|
||||
public void onMultiInstance(View view) {
|
||||
LogUtils.d(TAG, "onMultiInstance() 多开窗口按钮已点击");
|
||||
ToastUtils.show("多开窗口:已启动新窗口");
|
||||
android.content.Intent intent = new android.content.Intent(this, Main2Activity.class);
|
||||
intent.setFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
LogUtils.d(TAG, "onMultiInstance() 准备启动Main2Activity");
|
||||
startActivity(intent);
|
||||
LogUtils.d(TAG, "onMultiInstance() Main2Activity已启动");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package cc.winboll.studio.appbase;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Toolbar;
|
||||
import cc.winboll.studio.appbase.R;
|
||||
|
||||
public class MainActivityAlias extends MainActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setActionBar(toolbar);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
package cc.winboll.studio.appbase.model;
|
||||
|
||||
import android.util.JsonReader;
|
||||
import android.util.JsonWriter;
|
||||
import cc.winboll.studio.libappbase.BaseBean;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 测试实体类
|
||||
* 继承BaseBean实现JSON序列化/反序列化能力,提供基础int类型属性的封装与数据持久化支持
|
||||
* 适配Java7语法,遵循BaseBean统一的反射识别、JSON读写规范
|
||||
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2026/01/31 19:16:00
|
||||
* @LastEditTime 2026/02/01 10:46:00
|
||||
*/
|
||||
public class TestBean extends BaseBean {
|
||||
|
||||
// ====================================== 常量定义 ======================================
|
||||
/** 当前类的日志 TAG(用于调试输出) */
|
||||
public static final String TAG = "TestBean";
|
||||
|
||||
// ====================================== 成员属性 ======================================
|
||||
/**
|
||||
* 测试数字属性(默认值:123)
|
||||
* 基础int类型属性,用于测试BaseBean的JSON序列化/反序列化能力
|
||||
*/
|
||||
private int testNum1;
|
||||
|
||||
// ====================================== 构造方法 ======================================
|
||||
/**
|
||||
* 无参构造器(默认初始化)
|
||||
* 给testNum1赋值默认值123,满足反射实例化、JSON解析的无参构造要求
|
||||
*/
|
||||
public TestBean() {
|
||||
this.testNum1 = 123;
|
||||
LogUtils.d(TAG, "TestBean无参构造器调用,testNum1默认初始化值:" + this.testNum1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 有参构造器(自定义初始化)
|
||||
* @param testNum1 测试数字初始值
|
||||
*/
|
||||
public TestBean(int testNum1) {
|
||||
this.testNum1 = testNum1;
|
||||
LogUtils.d(TAG, "TestBean有参构造器调用,传入testNum1:" + testNum1);
|
||||
}
|
||||
|
||||
// ====================================== Get/Set 方法 ======================================
|
||||
/**
|
||||
* 设置测试数字属性值
|
||||
* @param testNum1 待设置的int类型值
|
||||
*/
|
||||
public void setTestNum1(int testNum1) {
|
||||
LogUtils.d(TAG, "setTestNum1调用,传入参数:" + testNum1);
|
||||
this.testNum1 = testNum1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取测试数字属性值
|
||||
* @return 当前testNum1的int类型值
|
||||
*/
|
||||
public int getTestNum1() {
|
||||
LogUtils.d(TAG, "getTestNum1调用,返回值:" + this.testNum1);
|
||||
return testNum1;
|
||||
}
|
||||
|
||||
// ====================================== 重写父类BaseBean方法 ======================================
|
||||
/**
|
||||
* 重写父类方法:获取当前类的全限定名
|
||||
* 用于BaseBean反射识别、类名匹配等统一逻辑
|
||||
* @return 类全限定名(cc.winboll.studio.appbase.model.TestBean)
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
LogUtils.d(TAG, "getName方法调用,返回类全限定名:" + TestBean.class.getName());
|
||||
return TestBean.class.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* 重写父类方法:将当前对象序列化为JSON(持久化存储专用)
|
||||
* 遵循BaseBean规范,先执行父类序列化逻辑,再处理子类专属字段
|
||||
* @param jsonWriter JSON写入器(外部传入的JSON流操作实例)
|
||||
* @throws IOException JSON写入异常(流关闭、格式错误等)
|
||||
*/
|
||||
@Override
|
||||
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
|
||||
LogUtils.d(TAG, "writeThisToJsonWriter调用,传入参数JsonWriter:" + jsonWriter);
|
||||
// 执行父类公共字段的序列化逻辑
|
||||
super.writeThisToJsonWriter(jsonWriter);
|
||||
// 序列化子类专属字段testNum1
|
||||
jsonWriter.name("testNum1").value(this.getTestNum1());
|
||||
LogUtils.d(TAG, "writeThisToJsonWriter执行完成,已序列化testNum1:" + this.getTestNum1());
|
||||
}
|
||||
|
||||
/**
|
||||
* 重写父类方法:从JSON字段初始化当前对象属性(解析JSON专用)
|
||||
* 先让父类处理公共字段,再匹配子类专属字段,不匹配则返回false跳过
|
||||
* @param jsonReader JSON读取器(外部传入的JSON流操作实例)
|
||||
* @param name 当前解析的JSON字段名
|
||||
* @return true-字段解析成功;false-字段不匹配,需跳过/父类处理
|
||||
* @throws IOException JSON读取异常(字段类型不匹配、流中断等)
|
||||
*/
|
||||
@Override
|
||||
public boolean initObjectsFromJsonReader(JsonReader jsonReader, String name) throws IOException {
|
||||
LogUtils.d(TAG, "initObjectsFromJsonReader调用,传入参数:name=" + name + ",JsonReader=" + jsonReader);
|
||||
// 父类优先处理公共字段,处理成功则直接返回
|
||||
if (super.initObjectsFromJsonReader(jsonReader, name)) {
|
||||
LogUtils.d(TAG, "initObjectsFromJsonReader:字段" + name + "由父类BaseBean处理成功");
|
||||
return true;
|
||||
}
|
||||
// 解析子类专属字段
|
||||
if ("testNum1".equals(name)) {
|
||||
this.setTestNum1(jsonReader.nextInt());
|
||||
LogUtils.d(TAG, "initObjectsFromJsonReader:解析testNum1成功,值为:" + this.getTestNum1());
|
||||
} else {
|
||||
LogUtils.w(TAG, "initObjectsFromJsonReader:字段" + name + "不匹配,返回false跳过解析");
|
||||
// 字段不匹配,返回false表示跳过
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重写父类方法:从JSON读取器完整解析并初始化当前对象(JSON解析入口)
|
||||
* 负责JSON对象的开始/结束标识处理,遍历所有字段并调用字段解析方法
|
||||
* 严格遵循writeThisToJsonWriter的序列化结构,保证解析一致性
|
||||
* @param jsonReader JSON读取器(外部传入的JSON流操作实例)
|
||||
* @return 解析后的当前TestBean实例(支持链式调用)
|
||||
* @throws IOException JSON解析异常(格式错误、字段缺失、流异常等)
|
||||
*/
|
||||
@Override
|
||||
public BaseBean readBeanFromJsonReader(JsonReader jsonReader) throws IOException {
|
||||
LogUtils.d(TAG, "readBeanFromJsonReader调用,传入参数JsonReader:" + jsonReader);
|
||||
// 开始解析JSON对象,与序列化结构保持一致
|
||||
jsonReader.beginObject();
|
||||
// 遍历所有JSON字段
|
||||
while (jsonReader.hasNext()) {
|
||||
String fieldName = jsonReader.nextName();
|
||||
LogUtils.d(TAG, "readBeanFromJsonReader:开始解析字段,fieldName=" + fieldName);
|
||||
// 解析字段,不匹配则跳过该值
|
||||
if (!this.initObjectsFromJsonReader(jsonReader, fieldName)) {
|
||||
jsonReader.skipValue();
|
||||
LogUtils.w(TAG, "readBeanFromJsonReader:字段" + fieldName + "解析失败,已跳过该值");
|
||||
}
|
||||
}
|
||||
// 结束JSON对象解析,必须调用避免流异常
|
||||
jsonReader.endObject();
|
||||
LogUtils.d(TAG, "readBeanFromJsonReader执行完成,JSON解析结束,当前TestBean实例testNum1:" + this.getTestNum1());
|
||||
// 返回当前实例,支持链式调用
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,18 @@
|
||||
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="onAboutActivity"
|
||||
android:layout_margin="10dp"/>
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -47,6 +59,18 @@
|
||||
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="onLogTestNewTask"
|
||||
android:layout_margin="10dp"/>
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -62,18 +86,29 @@
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="关于应用"
|
||||
android:text="分屏测试"
|
||||
android:textSize="16sp"
|
||||
android:textColor="@android:color/white"
|
||||
android:background="#81C7F5"
|
||||
android:paddingVertical="12dp"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:onClick="onAboutActivity"
|
||||
android:onClick="onSplitScreenMode"
|
||||
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="onMultiInstance"
|
||||
android:layout_margin="10dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -1,17 +1,17 @@
|
||||
<?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"
|
||||
android:id="@+id/ll_notification">
|
||||
android:gravity="center"
|
||||
android:background="@android:color/white">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Text"
|
||||
android:id="@+id/info_tv"/>
|
||||
|
||||
</LinearLayout>
|
||||
android:text="Main2Activity"
|
||||
android:textSize="24sp"
|
||||
android:textColor="@color/gray_900"/>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">AppBase</string>
|
||||
<string name="app_name">APPBase</string>
|
||||
<string name="app_description">WinBoLL 安卓手机端安卓应用开发基础类库。</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>
|
||||
|
||||
44
build.gradle
44
build.gradle
@@ -1,6 +1,15 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
buildscript {
|
||||
repositories {
|
||||
maven { url 'https://maven.aliyun.com/repository/public/' }
|
||||
maven { url 'https://maven.aliyun.com/repository/google/' }
|
||||
maven { url 'https://maven.aliyun.com/repository/gradle-plugin/' }
|
||||
maven { url 'https://dl.bintray.com/ppartisan/maven/' }
|
||||
maven { url "https://clojars.org/repo/" }
|
||||
maven { url "https://jitpack.io" }
|
||||
mavenCentral()
|
||||
google()
|
||||
|
||||
mavenLocal {
|
||||
// 设置本地Maven仓库路径
|
||||
url 'file:///sdcard/.m2/repository/'
|
||||
@@ -11,19 +20,6 @@ buildscript {
|
||||
maven { url "https://nexus.winboll.cc/repository/maven-public/" }
|
||||
// "WinBoLL Snapshot"
|
||||
maven { url "https://nexus.winboll.cc/repository/maven-snapshots/" }
|
||||
|
||||
maven { url 'https://maven.aliyun.com/repository/public/' }
|
||||
maven { url 'https://maven.aliyun.com/repository/google/' }
|
||||
maven { url 'https://maven.aliyun.com/repository/gradle-plugin/' }
|
||||
maven { url 'https://dl.bintray.com/ppartisan/maven/' }
|
||||
maven { url "https://clojars.org/repo/" }
|
||||
maven { url "https://jitpack.io" }
|
||||
mavenCentral()
|
||||
google()
|
||||
//println "mavenLocal : ==========="
|
||||
//println mavenLocal().url
|
||||
//println "mavenLocal : ==========="
|
||||
//mavenLocal()
|
||||
}
|
||||
dependencies {
|
||||
// 适配MIUI12
|
||||
@@ -35,6 +31,15 @@ buildscript {
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
maven { url 'https://maven.aliyun.com/repository/public/' }
|
||||
maven { url 'https://maven.aliyun.com/repository/google/' }
|
||||
maven { url 'https://maven.aliyun.com/repository/gradle-plugin/' }
|
||||
maven { url 'https://dl.bintray.com/ppartisan/maven/' }
|
||||
maven { url "https://clojars.org/repo/" }
|
||||
maven { url "https://jitpack.io" }
|
||||
mavenCentral()
|
||||
google()
|
||||
|
||||
mavenLocal {
|
||||
// 设置本地Maven仓库路径
|
||||
url 'file:///sdcard/.m2/repository/'
|
||||
@@ -45,19 +50,6 @@ allprojects {
|
||||
maven { url "https://nexus.winboll.cc/repository/maven-public/" }
|
||||
// "WinBoLL Snapshot"
|
||||
maven { url "https://nexus.winboll.cc/repository/maven-snapshots/" }
|
||||
|
||||
maven { url 'https://maven.aliyun.com/repository/public/' }
|
||||
maven { url 'https://maven.aliyun.com/repository/google/' }
|
||||
maven { url 'https://maven.aliyun.com/repository/gradle-plugin/' }
|
||||
maven { url 'https://dl.bintray.com/ppartisan/maven/' }
|
||||
maven { url "https://clojars.org/repo/" }
|
||||
maven { url "https://jitpack.io" }
|
||||
mavenCentral()
|
||||
google()
|
||||
//println "mavenLocal : ==========="
|
||||
//println mavenLocal().url
|
||||
//println "mavenLocal : ==========="
|
||||
//mavenLocal()
|
||||
}
|
||||
ext {
|
||||
// 定义全局变量,常用于版本管理
|
||||
|
||||
@@ -63,7 +63,7 @@ dependencies {
|
||||
//annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
|
||||
|
||||
// WinBoLL库 nexus.winboll.cc 地址
|
||||
api 'cc.winboll.studio:libappbase:15.15.3'
|
||||
api 'cc.winboll.studio:libappbase:15.15.19'
|
||||
// 备用库 jitpack.io 地址
|
||||
//api 'com.github.ZhanGSKen:APPBase:appbase-v15.15.3'
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Tue Jan 13 03:37:01 HKT 2026
|
||||
stageCount=2
|
||||
#Sat Apr 25 04:16:30 HKT 2026
|
||||
stageCount=10
|
||||
libraryProject=libaes
|
||||
baseVersion=15.15
|
||||
publishVersion=15.15.1
|
||||
publishVersion=15.15.9
|
||||
buildCount=0
|
||||
baseBetaVersion=15.15.2
|
||||
baseBetaVersion=15.15.10
|
||||
|
||||
@@ -5,6 +5,7 @@ package cc.winboll.studio.libaes.activitys;
|
||||
* @Date 2024/06/13 18:58:54
|
||||
* @Describe 可以加入Fragment的有抽屉的活动窗口抽象类
|
||||
*/
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
@@ -27,14 +28,16 @@ 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.utils.DevelopUtils;
|
||||
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
|
||||
import cc.winboll.studio.libaes.views.ADrawerMenuListView;
|
||||
import cc.winboll.studio.libaes.views.ADsBannerView;
|
||||
import cc.winboll.studio.libappbase.GlobalApplication;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import com.baoyz.widget.PullRefreshLayout;
|
||||
import java.util.ArrayList;
|
||||
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
|
||||
|
||||
public abstract class DrawerFragmentActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
|
||||
public abstract class DrawerFragmentActivity extends AppCompatActivity implements IWinBoLLActivity, AdapterView.OnItemClickListener {
|
||||
|
||||
public static final String TAG = "DrawerFragmentActivity";
|
||||
|
||||
@@ -61,17 +64,28 @@ public abstract class DrawerFragmentActivity extends AppCompatActivity implement
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
//mContext = this;
|
||||
mThemeType = getThemeType();
|
||||
setThemeStyle();
|
||||
mThemeType = AESThemeBean.getThemeStyleType(AESThemeUtil.getThemeTypeID(getApplicationContext()));
|
||||
setTheme(AESThemeUtil.getThemeTypeID(getApplicationContext()));
|
||||
super.onCreate(savedInstanceState);
|
||||
WinBoLLActivityManager.getInstance().add(this);
|
||||
mActivityType = initActivityType();
|
||||
initRootView();
|
||||
LogUtils.d(TAG, "onCreate end.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Activity getActivity() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
WinBoLLActivityManager.getInstance().registeRemove(this);
|
||||
super.onDestroy();
|
||||
// 修复:释放广告资源,避免内存泄漏
|
||||
ADsBannerView adsBannerView = findViewById(R.id.adsbanner);
|
||||
@@ -157,23 +171,6 @@ public abstract class DrawerFragmentActivity extends AppCompatActivity implement
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
void setThemeStyle() {
|
||||
//setTheme(AESThemeBean.getThemeStyle(getThemeType()));
|
||||
setTheme(AESThemeUtil.getThemeTypeID(getApplicationContext()));
|
||||
}
|
||||
|
||||
boolean checkThemeStyleChange() {
|
||||
return mThemeType != getThemeType();
|
||||
}
|
||||
|
||||
AESThemeBean.ThemeType getThemeType() {
|
||||
/*SharedPreferences sharedPreferences = getSharedPreferences(
|
||||
SHAREDPREFERENCES_NAME, MODE_PRIVATE);
|
||||
return AESThemeBean.ThemeType.values()[((sharedPreferences.getInt(DRAWER_THEME_TYPE, AESThemeBean.ThemeType.DEFAULT.ordinal())))];
|
||||
*/
|
||||
return AESThemeBean.getThemeStyleType(AESThemeUtil.getThemeTypeID(getApplicationContext()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (AESThemeUtil.onAppThemeItemSelected(this, item)) {
|
||||
@@ -190,9 +187,6 @@ public abstract class DrawerFragmentActivity extends AppCompatActivity implement
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (checkThemeStyleChange()) {
|
||||
recreate();
|
||||
}
|
||||
|
||||
ADsBannerView adsBannerView = findViewById(R.id.adsbanner);
|
||||
if (adsBannerView != null) {
|
||||
|
||||
@@ -1,18 +1,24 @@
|
||||
package cc.winboll.studio.libaes.interfaces;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2025/05/10 09:34
|
||||
* @Describe WinBoLL 窗口操作接口
|
||||
* @Describe WinBoll 窗口操作接口(规范定义,职责单一)
|
||||
*/
|
||||
import android.app.Activity;
|
||||
|
||||
public abstract interface IWinBoLLActivity {
|
||||
public interface IWinBoLLActivity {
|
||||
String TAG = "IWinBoLLActivity";
|
||||
String ACTION_BIND = IWinBoLLActivity.class.getName() + ".ACTION_BIND";
|
||||
|
||||
public static final String TAG = "IWinBoLLActivity";
|
||||
/**
|
||||
* 获取当前Activity实例
|
||||
*/
|
||||
Activity getActivity();
|
||||
|
||||
public static final String ACTION_BIND = IWinBoLLActivity.class.getName() + ".ACTION_BIND";
|
||||
|
||||
public Activity getActivity();
|
||||
public String getTag();
|
||||
/**
|
||||
* 获取Activity唯一标识(建议使用类名+UUID或固定唯一字符串)
|
||||
*/
|
||||
String getTag();
|
||||
}
|
||||
|
||||
|
||||
@@ -20,11 +20,6 @@ public class SecondaryLibraryActivity extends DrawerFragmentActivity implements
|
||||
|
||||
SecondaryLibraryFragment mSecondaryLibraryFragment;
|
||||
|
||||
@Override
|
||||
public Activity getActivity() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTag() {
|
||||
return null;
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
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 android.os.Build;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
|
||||
import cc.winboll.studio.libappbase.GlobalApplication;
|
||||
import cc.winboll.studio.libappbase.LogActivity;
|
||||
@@ -20,273 +15,292 @@ import cc.winboll.studio.libappbase.ToastUtils;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2025/05/10 10:02
|
||||
* @Describe 应用活动窗口管理器(改进版)
|
||||
* 核心能力:多任务窗口管理、Activity栈维护、任务前台恢复、批量关闭、前后Activity切换
|
||||
* 参考 :android 类似微信小程序多任务窗口 及 设置 TaskDescription 修改 icon 和 label
|
||||
*/
|
||||
public class WinBoLLActivityManager {
|
||||
|
||||
public static final String TAG = "WinBoLLActivityManager";
|
||||
|
||||
public static final String EXTRA_TAG = "EXTRA_TAG";
|
||||
|
||||
public enum WinBoLLUI_TYPE { APPLICATION, SERVICE } // 规范命名 大写开头
|
||||
|
||||
public enum WinBoLLUI_TYPE { Aplication, Service }
|
||||
private GlobalApplication mGlobalApplication;
|
||||
private static volatile WinBoLLActivityManager sInstance; // 单例命名规范
|
||||
private final Map<String, IWinBoLLActivity> mActivityListMap; // 私有不可变
|
||||
private static volatile WinBoLLUI_TYPE sWinBoLLUI_TYPE = WinBoLLUI_TYPE.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) {
|
||||
// 私有构造 杜绝外部实例化
|
||||
private WinBoLLActivityManager(@NonNull GlobalApplication application) {
|
||||
mGlobalApplication = application;
|
||||
mActivityListMap = new HashMap<String, IWinBoLLActivity>();
|
||||
mActivityListMap = new HashMap<>(); // 菱形泛型简化
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化管理器(必须在Application onCreate中调用)
|
||||
*/
|
||||
public static <T extends GlobalApplication> void init(@NonNull T application) {
|
||||
if (sInstance == null) {
|
||||
synchronized (WinBoLLActivityManager.class) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new WinBoLLActivityManager(application);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单例(需先调用init初始化,否则抛异常)
|
||||
*/
|
||||
@NonNull
|
||||
public static WinBoLLActivityManager getInstance() {
|
||||
return _mIWinBoLLActivityManager;
|
||||
}
|
||||
|
||||
public static synchronized <T extends GlobalApplication> void init(T application) {
|
||||
if (_mIWinBoLLActivityManager == null) {
|
||||
_mIWinBoLLActivityManager = new WinBoLLActivityManager(application);
|
||||
if (sInstance == null) {
|
||||
throw new IllegalStateException("WinBoLLActivityManager 未初始化,请先在Application中调用 init()");
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
// ===================== 基础配置 =====================
|
||||
public static void setWinBoLLUI_TYPE(@NonNull WinBoLLUI_TYPE winBoLLUI_TYPE) {
|
||||
sWinBoLLUI_TYPE = winBoLLUI_TYPE;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static WinBoLLUI_TYPE getWinBoLLUI_TYPE() {
|
||||
return sWinBoLLUI_TYPE;
|
||||
}
|
||||
|
||||
// ===================== Activity 增删查 =====================
|
||||
/**
|
||||
* 把Activity添加到管理中(自动去重)
|
||||
*/
|
||||
public <T extends IWinBoLLActivity> void add(@NonNull T activity) {
|
||||
String tag = activity.getTag();
|
||||
if (isActivityActive(tag)) {
|
||||
LogUtils.d(TAG, String.format("Activity[%s] 已处于活跃状态,无需重复添加", tag));
|
||||
return;
|
||||
}
|
||||
mActivityListMap.put(tag, activity);
|
||||
LogUtils.d(TAG, String.format("添加Activity:%s,当前管理数量:%d", tag, mActivityListMap.size()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 把Activity添加到管理中
|
||||
* 判断指定Tag的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());
|
||||
}
|
||||
public boolean isActivityActive(@NonNull String tag) {
|
||||
return mActivityListMap.containsKey(tag) && mActivityListMap.get(tag) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 结束指定Activity
|
||||
* 根据Tag获取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());
|
||||
@Nullable
|
||||
public Activity getActivityByTag(@NonNull String tag) {
|
||||
IWinBoLLActivity winBoLLActivity = mActivityListMap.get(tag);
|
||||
if (winBoLLActivity == null) return null;
|
||||
Activity activity = winBoLLActivity.getActivity();
|
||||
// 过滤已销毁/已结束的Activity
|
||||
if (activity == null || activity.isFinishing() || (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && activity.isDestroyed())) {
|
||||
registeRemove(winBoLLActivity);
|
||||
return null;
|
||||
}
|
||||
return activity;
|
||||
}
|
||||
|
||||
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());
|
||||
/**
|
||||
* 移除指定Activity(销毁时调用)
|
||||
*/
|
||||
public <T extends IWinBoLLActivity> boolean registeRemove(@NonNull T iWinBoLLActivity) {
|
||||
String tag = iWinBoLLActivity.getTag();
|
||||
if (mActivityListMap.containsKey(tag)) {
|
||||
mActivityListMap.remove(tag);
|
||||
LogUtils.d(TAG, String.format("移除Activity:%s,剩余管理数量:%d", tag, mActivityListMap.size()));
|
||||
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.");
|
||||
// ===================== Activity 启动 =====================
|
||||
/**
|
||||
* 启动WinBoLLActivity(存在则前台恢复,不存在则新建多任务窗口)
|
||||
*/
|
||||
public <T extends IWinBoLLActivity> void startWinBoLLActivity(@NonNull Context context, @NonNull Class<T> clazz) {
|
||||
if (!resumeActivity(clazz)) {
|
||||
Intent intent = new Intent(context, clazz);
|
||||
setMultiTaskFlags(intent);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 带Intent参数启动WinBoLLActivity
|
||||
*/
|
||||
public <T extends IWinBoLLActivity> void startWinBoLLActivity(@NonNull Context context, @NonNull Intent intent, @NonNull Class<T> clazz) {
|
||||
if (!resumeActivity(clazz)) {
|
||||
setMultiTaskFlags(intent);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动日志页面(固定多任务模式)
|
||||
*/
|
||||
public void startLogActivity(@NonNull Context context) {
|
||||
Intent intent = new Intent(context, LogActivity.class);
|
||||
setMultiTaskFlags(intent);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT); // 分屏相关
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置多任务窗口通用Flags
|
||||
*/
|
||||
private void setMultiTaskFlags(@NonNull Intent intent) {
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
|
||||
}
|
||||
|
||||
// ===================== Activity 前台恢复 =====================
|
||||
/**
|
||||
* 根据Activity类 恢复前台(反射获取Tag,需保证无参构造)
|
||||
*/
|
||||
public <T extends IWinBoLLActivity> boolean resumeActivity(@NonNull Class<T> clazz) {
|
||||
try {
|
||||
T instance = clazz.newInstance();
|
||||
return resumeActivity(instance.getTag());
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
LogUtils.e(TAG, "恢复Activity失败,类需提供无参构造", e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据Tag 恢复Activity前台
|
||||
*/
|
||||
public boolean resumeActivity(@NonNull String tag) {
|
||||
Activity activity = getActivityByTag(tag);
|
||||
return activity != null && resumeActivity(activity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 恢复指定Activity到前台(适配高版本权限)
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean resumeActivity(@NonNull Activity activity) {
|
||||
if (activity.isFinishing() || (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && activity.isDestroyed())) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
ActivityManager am = (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
if (am == null) {
|
||||
LogUtils.w(TAG, "获取ActivityManager失败,无法恢复前台");
|
||||
return false;
|
||||
}
|
||||
// Android 11+ 限制,低版本正常使用
|
||||
am.moveTaskToFront(activity.getTaskId(), ActivityManager.MOVE_TASK_NO_USER_ACTION);
|
||||
//ToastUtils.show(String.format("Activity[%s] 已恢复到前台", activity.getClass().getSimpleName()));
|
||||
LogUtils.d(TAG, String.format("Activity[%s] 已恢复到前台", activity.getClass().getSimpleName()));
|
||||
return true;
|
||||
} catch (SecurityException e) {
|
||||
//ToastUtils.show("恢复Activity前台失败,缺少权限或系统限制 :" + e.getMessage());
|
||||
LogUtils.e(TAG, "恢复Activity前台失败,缺少权限或系统限制", e);
|
||||
//ToastUtils.show("窗口恢复失败,请手动打开");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// ===================== Activity 关闭 =====================
|
||||
/**
|
||||
* 结束所有管理的Activity(按UI类型选择关闭策略)
|
||||
*/
|
||||
public void finishAll() {
|
||||
if (mActivityListMap.isEmpty()) {
|
||||
LogUtils.d(TAG, "当前无管理的Activity,无需结束");
|
||||
return;
|
||||
}
|
||||
LogUtils.d(TAG, String.format("开始结束所有Activity,共%d个", mActivityListMap.size()));
|
||||
Iterator<Map.Entry<String, IWinBoLLActivity>> iterator = mActivityListMap.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
IWinBoLLActivity winBoLLActivity = iterator.next().getValue();
|
||||
Activity activity = winBoLLActivity.getActivity();
|
||||
if (activity == null) {
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
// 安全关闭,避免重复操作
|
||||
if (!activity.isFinishing() && !(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && activity.isDestroyed())) {
|
||||
if (sWinBoLLUI_TYPE == WinBoLLUI_TYPE.SERVICE) {
|
||||
activity.finishAndRemoveTask(); // 结束+移除最近任务
|
||||
} else if (sWinBoLLUI_TYPE == WinBoLLUI_TYPE.APPLICATION) {
|
||||
activity.finish(); // 仅结束页面
|
||||
}
|
||||
}
|
||||
iterator.remove(); // 移除已处理的项
|
||||
}
|
||||
LogUtils.d(TAG, "所有Activity结束完成");
|
||||
}
|
||||
|
||||
/**
|
||||
* 结束指定Activity,自动恢复上一个Activity前台
|
||||
*/
|
||||
public <T extends IWinBoLLActivity> void finish(@NonNull T iWinBoLLActivity) {
|
||||
Activity currentActivity = iWinBoLLActivity.getActivity();
|
||||
if (currentActivity == null || currentActivity.isFinishing() || (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && currentActivity.isDestroyed())) {
|
||||
registeRemove(iWinBoLLActivity);
|
||||
return;
|
||||
}
|
||||
|
||||
// 先获取上一个Activity,再关闭当前
|
||||
Activity preActivity = getPreActivity(iWinBoLLActivity);
|
||||
currentActivity.finish();
|
||||
registeRemove(iWinBoLLActivity); // 关闭后移除管理
|
||||
|
||||
// 恢复上一个Activity前台
|
||||
if (preActivity != null) {
|
||||
resumeActivity(preActivity);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前Activity的上一个栈内Activity(修复原遍历逻辑错误)
|
||||
*/
|
||||
@Nullable
|
||||
private Activity getPreActivity(@NonNull IWinBoLLActivity currentActivity) {
|
||||
String currentTag = currentActivity.getTag();
|
||||
IWinBoLLActivity preWinBoLLActivity = null;
|
||||
for (Map.Entry<String, IWinBoLLActivity> entry : mActivityListMap.entrySet()) {
|
||||
String tag = entry.getKey();
|
||||
if (Objects.equals(tag, currentTag)) {
|
||||
break; // 找到当前Activity,循环终止,pre即为上一个
|
||||
}
|
||||
preWinBoLLActivity = entry.getValue();
|
||||
}
|
||||
return preWinBoLLActivity != null ? preWinBoLLActivity.getActivity() : null;
|
||||
}
|
||||
|
||||
// ===================== 调试辅助 =====================
|
||||
/**
|
||||
* 打印所有管理的Activity信息(调试用)
|
||||
*/
|
||||
public void printActivityListInfo() {
|
||||
if (mActivityListMap.isEmpty()) {
|
||||
LogUtils.d(TAG, "当前管理的Activity列表为空");
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder(String.format("Activity管理列表(总数:%d)\n", mActivityListMap.size()));
|
||||
for (Map.Entry<String, IWinBoLLActivity> entry : mActivityListMap.entrySet()) {
|
||||
sb.append("Tag: ").append(entry.getKey())
|
||||
.append(" | Activity: ").append(entry.getValue().getActivity().getClass().getSimpleName())
|
||||
.append("\n");
|
||||
}
|
||||
LogUtils.d(TAG, sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,5 +21,14 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// 网络连接类库
|
||||
api 'com.squareup.okhttp3:okhttp:4.4.1'
|
||||
// Gson
|
||||
api 'com.google.code.gson:gson:2.8.9'
|
||||
// Html 解析
|
||||
api 'org.jsoup:jsoup:1.13.1'
|
||||
// 添加JSch依赖(SFTP核心,com.jcraft:jsch:0.1.54)
|
||||
api 'com.jcraft:jsch:0.1.54'
|
||||
|
||||
api fileTree(dir: 'libs', include: ['*.jar'])
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Tue Jan 13 03:23:17 HKT 2026
|
||||
stageCount=5
|
||||
#Tue Apr 28 17:08:04 HKT 2026
|
||||
stageCount=22
|
||||
libraryProject=libappbase
|
||||
baseVersion=15.15
|
||||
publishVersion=15.15.4
|
||||
publishVersion=15.15.21
|
||||
buildCount=0
|
||||
baseBetaVersion=15.15.5
|
||||
baseBetaVersion=15.15.22
|
||||
|
||||
@@ -3,7 +3,21 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="cc.winboll.studio.libappbase">
|
||||
|
||||
<application>
|
||||
<!-- 拥有完全的网络访问权限 -->
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
|
||||
<!-- 读取您共享存储空间中的内容 -->
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||
|
||||
<!-- 修改或删除您共享存储空间中的内容 -->
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
|
||||
<!-- MANAGE_EXTERNAL_STORAGE -->
|
||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
|
||||
|
||||
<application
|
||||
android:requestLegacyExternalStorage="true"
|
||||
android:networkSecurityConfig="@xml/network_security_config">
|
||||
|
||||
<activity
|
||||
android:name=".CrashHandler$CrashActivity"
|
||||
@@ -24,12 +38,15 @@
|
||||
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
|
||||
android:exported="true"
|
||||
android:launchMode="singleInstance"
|
||||
android:taskAffinity="cc.winboll.studio.libappbase.LogActivity"
|
||||
android:process=":LogActivity">
|
||||
|
||||
</activity>
|
||||
|
||||
<activity android:name="cc.winboll.studio.libappbase.activities.NfcRsaLoginActivity"/>
|
||||
|
||||
<activity android:name="cc.winboll.studio.libappbase.activities.FTPBackupsActivity"/>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
</manifest>
|
||||
@@ -2,6 +2,7 @@ package cc.winboll.studio.libappbase;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
@@ -26,6 +27,12 @@ public class GlobalApplication extends Application {
|
||||
*/
|
||||
private static volatile boolean isDebugging = false;
|
||||
|
||||
// 新增:WinBoLL 服务器主机地址(volatile 保证多线程可见性)
|
||||
private static volatile String winbollHost = null;
|
||||
// 新增:SP 存储相关常量(私有存储,仅当前应用可访问)
|
||||
private static final String SP_NAME = "WinBoLL_SP_CONFIG";
|
||||
private static final String SP_KEY_WINBOLL_HOST = "winboll_host";
|
||||
|
||||
/**
|
||||
* 获取全局 Application 单例实例(外部可通过此方法获取上下文)
|
||||
* @return GlobalApplication 单例(未初始化时返回 null,需确保配置 AndroidManifest)
|
||||
@@ -53,7 +60,7 @@ public class GlobalApplication extends Application {
|
||||
}
|
||||
// 将调试状态封装为 APPModel 并保存到文件
|
||||
APPModel.saveBeanToFile(
|
||||
getAppModelFilePath(application),
|
||||
getAppModelFilePath(application),
|
||||
new APPModel(isDebugging)
|
||||
);
|
||||
}
|
||||
@@ -75,6 +82,42 @@ public class GlobalApplication extends Application {
|
||||
public static boolean isDebugging() {
|
||||
return isDebugging;
|
||||
}
|
||||
|
||||
// 新增:设置 WinBoLL 服务器主机地址(同时保存到 SP 持久化)
|
||||
public static void setWinbollHost(String host) {
|
||||
if (sInstance == null) {
|
||||
LogUtils.e(TAG, "setWinbollHost: 应用未初始化,设置失败");
|
||||
return;
|
||||
}
|
||||
// 检查并补全末尾 / 核心改动
|
||||
if (host != null && !host.isEmpty() && !host.endsWith("/")) {
|
||||
host += "/";
|
||||
}
|
||||
// 更新内存中的字段
|
||||
winbollHost = host;
|
||||
// 保存到 SP 持久化(私有模式,安全)
|
||||
SharedPreferences sp = sInstance.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
|
||||
sp.edit().putString(SP_KEY_WINBOLL_HOST, host).apply();
|
||||
LogUtils.d(TAG, "setWinbollHost: 服务器地址已设置并持久化,host=" + host);
|
||||
}
|
||||
|
||||
|
||||
// 新增:获取 WinBoLL 服务器主机地址(优先内存,内存为空则从 SP 读取)
|
||||
public static String getWinbollHost() {
|
||||
if (winbollHost != null) {
|
||||
// 内存中存在,直接返回(提高效率)
|
||||
return winbollHost;
|
||||
}
|
||||
if (sInstance == null) {
|
||||
LogUtils.e(TAG, "getWinbollHost: 应用未初始化,获取失败");
|
||||
return null;
|
||||
}
|
||||
// 内存中不存在,从 SP 读取并更新到内存
|
||||
SharedPreferences sp = sInstance.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
|
||||
winbollHost = sp.getString(SP_KEY_WINBOLL_HOST, "https://console.winboll.cc/");
|
||||
LogUtils.d(TAG, "getWinbollHost: 从 SP 读取服务器地址,host=" + winbollHost);
|
||||
return winbollHost;
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用启动时初始化(仅执行一次)
|
||||
@@ -85,12 +128,13 @@ public class GlobalApplication extends Application {
|
||||
super.onCreate();
|
||||
// 初始化单例实例(确保在所有初始化操作前完成)
|
||||
sInstance = this;
|
||||
|
||||
|
||||
// 初始化基础组件(日志、崩溃处理、Toast)
|
||||
initCoreComponents();
|
||||
// 恢复/初始化调试模式状态(从本地文件读取,无文件则默认关闭调试)
|
||||
restoreDebugStatus();
|
||||
// 新增:初始化服务器地址(从 SP 读取到内存,提高后续访问效率)
|
||||
initWinbollHost();
|
||||
|
||||
LogUtils.d(TAG, "GlobalApplication 初始化完成,单例实例已创建");
|
||||
}
|
||||
@@ -115,7 +159,7 @@ public class GlobalApplication extends Application {
|
||||
private void restoreDebugStatus() {
|
||||
// 从文件加载 APPModel 实例(存储调试状态的模型类)
|
||||
APPModel appModel = APPModel.loadBeanFromFile(
|
||||
getAppModelFilePath(this),
|
||||
getAppModelFilePath(this),
|
||||
APPModel.class
|
||||
);
|
||||
|
||||
@@ -131,6 +175,11 @@ public class GlobalApplication extends Application {
|
||||
}
|
||||
}
|
||||
|
||||
// 新增:初始化服务器地址(应用启动时从 SP 读取到内存)
|
||||
private void initWinbollHost() {
|
||||
getWinbollHost(); // 触发从 SP 读取并更新内存
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取应用名称(从 AndroidManifest.xml 的 android:label 读取)
|
||||
* @param context 上下文(建议传入 Application 上下文,避免内存泄漏)
|
||||
@@ -154,7 +203,7 @@ public class GlobalApplication extends Application {
|
||||
return appName;
|
||||
} catch (NameNotFoundException e) {
|
||||
// 包名不存在(理论上不会发生,捕获异常避免崩溃)
|
||||
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||
//LogUtils.e(TAG, "获取应用名称失败:包名不存在", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -170,7 +219,6 @@ public class GlobalApplication extends Application {
|
||||
// 释放单例引用(可选,避免内存泄漏风险)
|
||||
sInstance = null;
|
||||
LogUtils.d(TAG, "GlobalApplication 终止,单例实例已释放");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package cc.winboll.studio.libappbase;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityOptions;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import cc.winboll.studio.libappbase.LogView;
|
||||
import cc.winboll.studio.libappbase.R;
|
||||
@@ -46,20 +49,39 @@ public class LogActivity extends Activity {
|
||||
* @param context 上下文(Activity/Fragment),用于启动 Activity
|
||||
*/
|
||||
public static void startLogActivity(Context context) {
|
||||
// 创建启动当前 Activity 的 Intent
|
||||
startLogActivity(context, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动日志 Activity 的静态方法重载(外部调用入口)
|
||||
* @param context 上下文(Activity/Fragment),用于启动 Activity
|
||||
* @param newTask 是否在新窗口中启动
|
||||
*/
|
||||
public static void startLogActivity(Context context, boolean newTask) {
|
||||
Intent intent = new Intent(context, LogActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
|
||||
// 添加 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);
|
||||
if (newTask) {
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
|
||||
context.startActivity(intent);
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
|
||||
|
||||
// 启动 Activity
|
||||
context.startActivity(intent);
|
||||
Rect bounds = new Rect();
|
||||
if (context instanceof Activity) {
|
||||
Activity activity = (Activity) context;
|
||||
activity.getWindow().getDecorView().getDisplay().getRectSize(bounds);
|
||||
bounds.set(0, bounds.height() / 2, bounds.width(), bounds.height());
|
||||
}
|
||||
ActivityOptions options = ActivityOptions.makeBasic();
|
||||
options.setLaunchBounds(bounds);
|
||||
context.startActivity(intent, options.toBundle());
|
||||
} else {
|
||||
context.startActivity(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -100,10 +100,52 @@ public class LogUtils {
|
||||
// 加载当前应用下的所有类的 TAG
|
||||
addClassTAGList();
|
||||
loadTAGBeanSettings();
|
||||
checkAndTrimLogFileSize();
|
||||
_IsInited = true;
|
||||
LogUtils.d(TAG, String.format("mapTAGList : %s", mapTAGList.toString()));
|
||||
}
|
||||
|
||||
private static void checkAndTrimLogFileSize() {
|
||||
if (_mfLogCatchFile == null || !_mfLogCatchFile.exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final long MAX_FILE_SIZE = 6291456L;
|
||||
final long KEEP_FILE_SIZE = 3145728L;
|
||||
|
||||
long fileSize = _mfLogCatchFile.length();
|
||||
if (fileSize <= MAX_FILE_SIZE) {
|
||||
return;
|
||||
}
|
||||
|
||||
long needSkip = fileSize - KEEP_FILE_SIZE;
|
||||
|
||||
try (FileInputStream fis = new FileInputStream(_mfLogCatchFile);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
|
||||
FileOutputStream fos = new FileOutputStream(_mfLogCatchFile);
|
||||
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fos))) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String line;
|
||||
long skippedTotal = 0;
|
||||
final String lineBreak = System.lineSeparator();
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
byte[] lineBytes = line.getBytes();
|
||||
skippedTotal += lineBytes.length + lineBreak.getBytes().length;
|
||||
|
||||
if (skippedTotal > needSkip) {
|
||||
sb.append(line).append(lineBreak);
|
||||
}
|
||||
}
|
||||
|
||||
writer.write(sb.toString());
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<String, Boolean> getMapTAGList() {
|
||||
return mapTAGList;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,186 @@
|
||||
package cc.winboll.studio.libappbase.dialogs;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.R;
|
||||
import cc.winboll.studio.libappbase.ToastUtils;
|
||||
import cc.winboll.studio.libappbase.utils.APPUtils;
|
||||
import cc.winboll.studio.libappbase.utils.ApkSignUtils;
|
||||
|
||||
/**
|
||||
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
|
||||
* @CreateTime 2026-01-20 21:20:00
|
||||
* @LastEditTime 2026-01-24 18:45:00
|
||||
* @Describe 签名显示+正版校验对话框:展示应用签名字节位信息,调用网络接口完成正版合法性校验,实时返回校验结果
|
||||
*/
|
||||
public class APPValidationDialog extends Dialog {
|
||||
// ===================================== 全局常量 =====================================
|
||||
public static final String TAG = "AppValidationDialog";
|
||||
// 签名字节位分组大小
|
||||
private static final int BIT_GROUP_SIZE = 16;
|
||||
|
||||
// ===================================== 控件与上下文属性 =====================================
|
||||
private Context mContext;
|
||||
private EditText etSignFingerprint;
|
||||
private TextView tvAuthResult;
|
||||
|
||||
// ===================================== 业务入参属性 =====================================
|
||||
private String appName;
|
||||
private String versionName;
|
||||
private String clientSign;
|
||||
private String clientHash;
|
||||
|
||||
// ===================================== 构造方法 =====================================
|
||||
public APPValidationDialog(Context context, String appName, String versionName) {
|
||||
super(context, R.style.DialogStyle);
|
||||
this.mContext = context;
|
||||
this.appName = appName;
|
||||
this.versionName = versionName;
|
||||
LogUtils.d(TAG, "AppValidationDialog: 构造方法初始化,入参-> projectName=" + appName + ", versionName=" + versionName);
|
||||
}
|
||||
|
||||
// ===================================== 生命周期方法 =====================================
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
LogUtils.d(TAG, "onCreate: 对话框创建,开始初始化布局与业务逻辑");
|
||||
setContentView(R.layout.dialog_sign_get);
|
||||
setCancelable(true);
|
||||
// 初始化应用签名与哈希
|
||||
initSignAndHash();
|
||||
// 初始化页面控件
|
||||
initView();
|
||||
// 执行签名展示与正版校验
|
||||
doSignShowAndAuthCheck();
|
||||
LogUtils.d(TAG, "onCreate: 对话框初始化流程执行完成");
|
||||
}
|
||||
|
||||
// ===================================== 页面与数据初始化方法 =====================================
|
||||
/**
|
||||
* 初始化页面控件,绑定视图并设置基础属性
|
||||
*/
|
||||
private void initView() {
|
||||
LogUtils.d(TAG, "initView: 开始初始化页面控件");
|
||||
etSignFingerprint = findViewById(R.id.et_sign_fingerprint);
|
||||
tvAuthResult = findViewById(R.id.tv_auth_result);
|
||||
// 签名显示框设为只读,方便用户复制
|
||||
etSignFingerprint.setEnabled(false);
|
||||
// 填充签名字节位信息
|
||||
etSignFingerprint.setText(convertSignToBitArrayWithWrap(clientSign));
|
||||
LogUtils.d(TAG, "initView: 控件初始化完成,已填充签名字节位信息");
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化应用签名与SHA256哈希,调用工具类获取与服务端对齐的参数
|
||||
*/
|
||||
private void initSignAndHash() {
|
||||
LogUtils.d(TAG, "initSignAndHash: 开始获取应用签名与SHA256哈希");
|
||||
this.clientSign = ApkSignUtils.getApkSignAlignedWithServer(mContext);
|
||||
this.clientHash = ApkSignUtils.getApkSHA256Hash(mContext);
|
||||
LogUtils.d(TAG, "initSignAndHash: 签名与哈希获取完成-> clientSign=" + clientSign + ", clientHash=" + clientHash);
|
||||
}
|
||||
|
||||
// ===================================== 核心业务方法 =====================================
|
||||
/**
|
||||
* 核心业务:展示签名字节位信息,发起网络正版校验请求
|
||||
*/
|
||||
private void doSignShowAndAuthCheck() {
|
||||
LogUtils.d(TAG, "doSignShowAndAuthCheck: 开始执行应用正版合法性校验");
|
||||
// 校验签名与哈希非空,避免空参请求
|
||||
if (clientSign == null || clientHash == null) {
|
||||
String errorMsg = "应用签名或哈希获取失败,无法执行正版校验";
|
||||
LogUtils.e(TAG, "doSignShowAndAuthCheck: " + errorMsg);
|
||||
tvAuthResult.setTextColor(Color.RED);
|
||||
tvAuthResult.setText(errorMsg);
|
||||
ToastUtils.show(errorMsg);
|
||||
return;
|
||||
}
|
||||
// 调用网络校验接口
|
||||
new APPUtils().checkAPKValidation(
|
||||
mContext,
|
||||
appName,
|
||||
versionName,
|
||||
clientSign,
|
||||
clientHash,
|
||||
new APPUtils.CheckResultCallback() {
|
||||
@Override
|
||||
public void onResult(boolean isValid, String message) {
|
||||
LogUtils.d(TAG, "checkAPKValidation: 校验结果返回-> isValid=" + isValid + ", message=" + message);
|
||||
handleAuthResult(isValid, message);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理正版校验结果,更新UI并提示用户
|
||||
* @param isValid 校验是否通过
|
||||
* @param message 服务端返回提示信息
|
||||
*/
|
||||
private void handleAuthResult(boolean isValid, String message) {
|
||||
String showMessage;
|
||||
if (isValid) {
|
||||
showMessage = "< 这是正版的 WinBoLL 应用,请放心使用。 >";
|
||||
tvAuthResult.setTextColor(Color.BLUE);
|
||||
LogUtils.d(TAG, "handleAuthResult: 正版校验通过," + showMessage + ",服务端信息:" + message);
|
||||
} else {
|
||||
showMessage = "< 您使用的可能不是正版的 WinBoLL 应用。 >";
|
||||
tvAuthResult.setTextColor(Color.RED);
|
||||
LogUtils.e(TAG, "handleAuthResult: 正版校验失败," + showMessage + ",失败原因:" + message);
|
||||
}
|
||||
// 更新UI并弹提示
|
||||
tvAuthResult.setText(showMessage);
|
||||
ToastUtils.show(showMessage);
|
||||
}
|
||||
|
||||
// ===================================== 工具方法 =====================================
|
||||
/**
|
||||
* 签名字符串转0/1比特数组格式:每2个bit加空格,每16位换行,提升可读性
|
||||
* @param signStr 原始签名字符串
|
||||
* @return 格式化后的比特数字符串,签名字符为空返回空串
|
||||
*/
|
||||
private String convertSignToBitArrayWithWrap(String signStr) {
|
||||
LogUtils.d(TAG, "convertSignToBitArrayWithWrap: 开始格式化签名字符串为比特数组");
|
||||
if (signStr == null || signStr.isEmpty()) {
|
||||
LogUtils.w(TAG, "convertSignToBitArrayWithWrap: 原始签名字符串为空,返回空串");
|
||||
return "";
|
||||
}
|
||||
// 字符转8位补零的二进制字符串
|
||||
StringBuilder bitBuilder = new StringBuilder();
|
||||
for (char c : signStr.toCharArray()) {
|
||||
String bit8 = String.format("%8s", Integer.toBinaryString(c)).replace(' ', '0');
|
||||
bitBuilder.append(bit8);
|
||||
}
|
||||
String fullBitStr = bitBuilder.toString();
|
||||
LogUtils.d(TAG, "convertSignToBitArrayWithWrap: 签名转二进制完成,总长度=" + fullBitStr.length() + "bit");
|
||||
|
||||
// 按16位分组,组内每2bit加空格,分组后换行
|
||||
StringBuilder finalBuilder = new StringBuilder();
|
||||
for (int i = 0; i < fullBitStr.length(); i += BIT_GROUP_SIZE) {
|
||||
int end = Math.min(i + BIT_GROUP_SIZE, fullBitStr.length());
|
||||
String group = fullBitStr.substring(i, end);
|
||||
// 组内加空格
|
||||
StringBuilder groupWithSpace = new StringBuilder();
|
||||
for (int j = 0; j < group.length(); j++) {
|
||||
groupWithSpace.append(group.charAt(j));
|
||||
if ((j + 1) % 2 == 0 && j != group.length() - 1) {
|
||||
groupWithSpace.append(" ");
|
||||
}
|
||||
}
|
||||
finalBuilder.append(groupWithSpace);
|
||||
// 最后一组不换行
|
||||
if (end < fullBitStr.length()) {
|
||||
finalBuilder.append("\n");
|
||||
}
|
||||
}
|
||||
LogUtils.d(TAG, "convertSignToBitArrayWithWrap: 签名比特数组格式化完成");
|
||||
return finalBuilder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
package cc.winboll.studio.libappbase.dialogs;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
import cc.winboll.studio.libappbase.GlobalApplication;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.R;
|
||||
import cc.winboll.studio.libappbase.ToastUtils;
|
||||
|
||||
/**
|
||||
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2026/01/22 20:59
|
||||
* @Describe WinBoLL服务器地址设置对话框(调试模式专用)
|
||||
*/
|
||||
public class DebugHostDialog extends Dialog implements View.OnClickListener {
|
||||
public static final String TAG = "DebugHostDialog";
|
||||
|
||||
private Context mContext;
|
||||
private EditText etHostInput;
|
||||
private Button btnConfirm;
|
||||
private Button btnCancel;
|
||||
|
||||
// 构造方法(适配默认样式)
|
||||
public DebugHostDialog(Context context) {
|
||||
super(context, R.style.DialogStyle);
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.dialog_winboll_host); // 绑定XML布局
|
||||
setCancelable(true); // 点击外部可关闭
|
||||
initView();
|
||||
initData();
|
||||
LogUtils.d(TAG, "DebugHostDialog 初始化完成");
|
||||
}
|
||||
|
||||
// 初始化视图
|
||||
private void initView() {
|
||||
etHostInput = findViewById(R.id.et_host_input);
|
||||
btnConfirm = findViewById(R.id.btn_confirm);
|
||||
btnCancel = findViewById(R.id.btn_cancel);
|
||||
|
||||
// 绑定点击事件
|
||||
btnConfirm.setOnClickListener(this);
|
||||
btnCancel.setOnClickListener(this);
|
||||
}
|
||||
|
||||
// 初始化数据(显示当前已保存的地址)
|
||||
private void initData() {
|
||||
String currentHost = GlobalApplication.getWinbollHost();
|
||||
if (!TextUtils.isEmpty(currentHost)) {
|
||||
etHostInput.setText(currentHost);
|
||||
etHostInput.setSelection(currentHost.length()); // 光标定位到末尾
|
||||
LogUtils.d(TAG, "当前已保存的服务器地址:" + currentHost);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int id = v.getId();
|
||||
if (id == R.id.btn_confirm) {
|
||||
handleConfirm(); // 确认设置
|
||||
} else if (id == R.id.btn_cancel) {
|
||||
dismiss(); // 取消对话框
|
||||
}
|
||||
}
|
||||
|
||||
// 处理确认设置逻辑
|
||||
private void handleConfirm() {
|
||||
String inputHost = etHostInput.getText().toString().trim();
|
||||
if (TextUtils.isEmpty(inputHost)) {
|
||||
ToastUtils.show("服务器地址不能为空");
|
||||
LogUtils.w(TAG, "设置失败:地址为空");
|
||||
return;
|
||||
}
|
||||
|
||||
// 简单校验URL格式(避免明显错误)
|
||||
if (!inputHost.startsWith("http://") && !inputHost.startsWith("https://")) {
|
||||
ToastUtils.show("地址需以http://或https://开头");
|
||||
LogUtils.w(TAG, "设置失败:地址格式错误,input=" + inputHost);
|
||||
return;
|
||||
}
|
||||
|
||||
// 保存地址到SP+内存
|
||||
GlobalApplication.setWinbollHost(inputHost);
|
||||
ToastUtils.show("服务器地址设置成功");
|
||||
LogUtils.d(TAG, "服务器地址设置成功:" + inputHost);
|
||||
dismiss(); // 关闭对话框
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
package cc.winboll.studio.libappbase.models;
|
||||
|
||||
/**
|
||||
* SFTP登录验证信息实体类
|
||||
* 封装SFTP登录所需的所有配置信息:服务端地址、端口、账号密码、秘钥信息、编码
|
||||
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2026/01/30 19:08:00
|
||||
* @LastEditTime 2026/01/31 22:45:00
|
||||
*/
|
||||
public class SFTPAuthModel {
|
||||
public static final String TAG = "SFTPAuthModel";
|
||||
|
||||
// SFTP服务器地址(必填,如192.168.1.100、sftp.xxx.com)
|
||||
private String ftpServer;
|
||||
// SFTP服务器端口(必填,默认22)
|
||||
private int ftpPort = 22;
|
||||
// SFTP登录用户名(匿名登录传null/空)
|
||||
private String ftpUsername;
|
||||
// SFTP登录密码(匿名登录传null/空)
|
||||
private String ftpPassword;
|
||||
// SFTP登录秘钥路径(秘钥登录时使用,本地绝对路径,如/sdcard/sftp/key.pem,账号密码登录传null/空)
|
||||
private String ftpKeyPath;
|
||||
// SFTP登录秘钥密码(秘钥有密码时填写,无密码传null/空)
|
||||
private String ftpKeyPwd;
|
||||
// SFTP编码(默认UTF-8,解决中文文件名乱码)
|
||||
private String ftpCharset = "UTF-8";
|
||||
|
||||
// 空参构造(JavaBean规范)
|
||||
public SFTPAuthModel() {
|
||||
}
|
||||
|
||||
// 全参构造(快速初始化)
|
||||
public SFTPAuthModel(String ftpServer, int ftpPort, String ftpUsername, String ftpPassword,
|
||||
String ftpKeyPath, String ftpKeyPwd, String ftpCharset) {
|
||||
this.ftpServer = ftpServer;
|
||||
this.ftpPort = ftpPort;
|
||||
this.ftpUsername = ftpUsername;
|
||||
this.ftpPassword = ftpPassword;
|
||||
this.ftpKeyPath = ftpKeyPath;
|
||||
this.ftpKeyPwd = ftpKeyPwd;
|
||||
this.ftpCharset = ftpCharset;
|
||||
}
|
||||
|
||||
// ==================== Get/Set 方法 ====================
|
||||
public String getFtpServer() {
|
||||
return ftpServer;
|
||||
}
|
||||
|
||||
public void setFtpServer(String ftpServer) {
|
||||
this.ftpServer = ftpServer;
|
||||
}
|
||||
|
||||
public int getFtpPort() {
|
||||
return ftpPort;
|
||||
}
|
||||
|
||||
public void setFtpPort(int ftpPort) {
|
||||
this.ftpPort = ftpPort;
|
||||
}
|
||||
|
||||
public String getFtpUsername() {
|
||||
return ftpUsername;
|
||||
}
|
||||
|
||||
public void setFtpUsername(String ftpUsername) {
|
||||
this.ftpUsername = ftpUsername;
|
||||
}
|
||||
|
||||
public String getFtpPassword() {
|
||||
return ftpPassword;
|
||||
}
|
||||
|
||||
public void setFtpPassword(String ftpPassword) {
|
||||
this.ftpPassword = ftpPassword;
|
||||
}
|
||||
|
||||
public String getFtpKeyPath() {
|
||||
return ftpKeyPath;
|
||||
}
|
||||
|
||||
public void setFtpKeyPath(String ftpKeyPath) {
|
||||
this.ftpKeyPath = ftpKeyPath;
|
||||
}
|
||||
|
||||
public String getFtpKeyPwd() {
|
||||
return ftpKeyPwd;
|
||||
}
|
||||
|
||||
public void setFtpKeyPwd(String ftpKeyPwd) {
|
||||
this.ftpKeyPwd = ftpKeyPwd;
|
||||
}
|
||||
|
||||
public String getFtpCharset() {
|
||||
return ftpCharset;
|
||||
}
|
||||
|
||||
public void setFtpCharset(String ftpCharset) {
|
||||
this.ftpCharset = ftpCharset;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package cc.winboll.studio.libappbase.models;
|
||||
|
||||
/**
|
||||
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2026/01/22 20:37
|
||||
*/
|
||||
// ==================== JSON响应模型(与后端返回字段完全匹配)====================
|
||||
public class SignCheckResponse {
|
||||
private int code; // 根节点code(后端返回)
|
||||
private String msg; // 根节点提示信息(后端返回,替换原message)
|
||||
private DataBean data; // 根节点data对象(后端返回)
|
||||
|
||||
// 内部DataBean:对应后端返回的data字段内容
|
||||
public static class DataBean {
|
||||
private boolean valid; // 实际是否合法的标识(后端data.valid)
|
||||
private String signature; // 加密后的签名
|
||||
private String decryptedSign;// 解密后的原始签名
|
||||
private long validTime; // 时间戳
|
||||
}
|
||||
|
||||
// Getter/Setter(关键:获取data中的valid字段)
|
||||
public boolean isValid() {
|
||||
return data != null && data.valid; // 从data中获取valid值
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return msg; // 对应后端根节点的msg字段
|
||||
}
|
||||
|
||||
// 其他必要的Getter/Setter(用于后续扩展)
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public DataBean getData() {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,306 @@
|
||||
package cc.winboll.studio.libappbase.utils;
|
||||
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Base64;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
/**
|
||||
* APK文件工具类(单例)- 生产级签名+哈希双校验版(修复Too short异常)
|
||||
* 1. 稳定解析CERT.RSA原始字节,与客户端Signature.toByteArray()1:1对齐,解决X509解析异常
|
||||
* 2. 支持SHA256文件哈希字节级唯一校验,签名+哈希双重验证
|
||||
* 3. 入参包含:项目名/版本名/APK名/客户端签名/客户端哈希,适配生产级版本管理
|
||||
* 4. APK路径规范:apks_root/项目名/debug/tag/APK文件(支持调试/正式环境)
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
*/
|
||||
public class APKFileUtils {
|
||||
// 单例实例
|
||||
private static volatile APKFileUtils sInstance;
|
||||
// 配置项
|
||||
private static final String CONFIG_SECTION = "APP";
|
||||
private static final String KEY_APKS_FOLDER = "apks_folder_path";
|
||||
// 算法常量(与客户端严格对齐)
|
||||
private static final String SIGN_ALGORITHM = "SHA1"; // 签名摘要算法
|
||||
private static final String HASH_ALGORITHM = "SHA-256"; // 文件哈希算法
|
||||
// 签名文件(兼容大小写,适配所有打包工具)
|
||||
private static final String CERT_RSA_UPPER = "META-INF/CERT.RSA";
|
||||
private static final String CERT_RSA_LOWER = "META-INF/cert.rsa";
|
||||
// APK根目录
|
||||
private String apksRootPath;
|
||||
|
||||
private APKFileUtils() {}
|
||||
|
||||
/**
|
||||
* 初始化工具类(需在应用启动时调用)
|
||||
*/
|
||||
public static void init() {
|
||||
if (sInstance == null) {
|
||||
synchronized (APKFileUtils.class) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new APKFileUtils();
|
||||
//sInstance.loadConfig();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单例实例
|
||||
*/
|
||||
public static APKFileUtils getInstance() {
|
||||
if (sInstance == null) {
|
||||
LogUtils.e("APKFileUtils", "请先调用init()初始化工具类");
|
||||
throw new IllegalStateException("APKFileUtils未初始化,请先调用init()");
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载配置文件中的APK根目录
|
||||
*/
|
||||
// private void loadConfig() {
|
||||
// try {
|
||||
// apksRootPath = IniConfigUtils.getConfigValue(CONFIG_SECTION, KEY_APKS_FOLDER, "").trim();
|
||||
// if (apksRootPath.isEmpty()) {
|
||||
// LogUtils.e("APKFileUtils", "配置项apks_folder_path为空,初始化失败");
|
||||
// return;
|
||||
// }
|
||||
// File rootDir = new File(apksRootPath);
|
||||
// if (!rootDir.exists() && !rootDir.mkdirs()) {
|
||||
// LogUtils.e("APKFileUtils", "APK根目录创建失败:" + apksRootPath);
|
||||
// apksRootPath = "";
|
||||
// return;
|
||||
// }
|
||||
// LogUtils.i("APKFileUtils", "APK根目录加载成功:" + apksRootPath);
|
||||
// } catch (Exception e) {
|
||||
// LogUtils.e("APKFileUtils", "加载APK根目录配置失败", e);
|
||||
// apksRootPath = "";
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 对外暴露核心校验方法:签名 + SHA256文件哈希 双校验
|
||||
* 入参包含:项目名/版本名/APK文件名/客户端签名Base64/客户端文件哈希
|
||||
* APK路径规范:apksRootPath/项目名/版本名/APK文件
|
||||
* @param projectName 项目名(非空)
|
||||
* @param versionName 版本名(非空,如15.11.11)
|
||||
* @param apkFileName APK文件名(非空,需以.apk结尾)
|
||||
* @param clientSignBase64 客户端传入的签名Base64(非空)
|
||||
* @param clientFileHash 客户端传入的APK文件SHA256哈希(小写/大写均可,非空)
|
||||
* @return 校验通过返回true,否则false
|
||||
*/
|
||||
public static boolean checkAPK(String projectName, String versionName, String apkFileName,
|
||||
String clientSignBase64, String clientFileHash) {
|
||||
return getInstance().doCheckAPK(projectName, versionName, apkFileName, clientSignBase64, clientFileHash);
|
||||
}
|
||||
|
||||
/**
|
||||
* 核心校验实现:严格按「哈希先验,签名后验」顺序,哈希不匹配直接返回
|
||||
*/
|
||||
private boolean doCheckAPK(String projectName, String versionName, String apkFileName,
|
||||
String clientSignBase64, String clientFileHash) {
|
||||
// 1. 基础入参非空校验
|
||||
if (isParamEmpty(projectName) || isParamEmpty(versionName) || isParamEmpty(apkFileName)
|
||||
|| isParamEmpty(clientSignBase64) || isParamEmpty(clientFileHash)) {
|
||||
LogUtils.w("APKFileUtils", "基础参数不能为空:projectName/versionName/apkFileName/clientSignBase64/clientFileHash");
|
||||
return false;
|
||||
}
|
||||
// 2. APK文件名格式校验
|
||||
if (!apkFileName.endsWith(".apk")) {
|
||||
LogUtils.w("APKFileUtils", "APK文件名格式错误,需以.apk结尾:" + apkFileName);
|
||||
return false;
|
||||
}
|
||||
// 3. APK根目录校验
|
||||
if (isParamEmpty(apksRootPath)) {
|
||||
LogUtils.w("APKFileUtils", "APK根目录未配置,无法进行校验");
|
||||
return false;
|
||||
}
|
||||
// 4. 拼接标准APK路径:根目录/项目名/debug/项目名_版本名.apk(调试环境,可切换tag)
|
||||
String apkFullPath = String.format("%s/%s/debug/%s_%s.apk",
|
||||
apksRootPath,
|
||||
projectName,
|
||||
projectName,
|
||||
versionName);
|
||||
//正式环境路径(注释保留,切换时解开即可)
|
||||
// String apkFullPath = String.format("%s/%s/tag/%s_%s.apk",
|
||||
// apksRootPath,
|
||||
// projectName,
|
||||
// projectName,
|
||||
// versionName);
|
||||
LogUtils.d("APKFileUtils", String.format("apkFullPath : %s", apkFullPath));
|
||||
File apkFile = new File(apkFullPath);
|
||||
// 5. APK文件存在性校验
|
||||
if (!apkFile.exists() || !apkFile.isFile()) {
|
||||
LogUtils.w("APKFileUtils", "APK文件不存在或非文件类型:" + apkFullPath);
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
// ===== 第一步:SHA256文件哈希校验(字节级唯一,优先级最高)=====
|
||||
String serverFileHash = getAPKFileHash(apkFile);
|
||||
if (isParamEmpty(serverFileHash)) {
|
||||
LogUtils.w("APKFileUtils", "解析服务端APK文件哈希失败:" + apkFileName);
|
||||
return false;
|
||||
}
|
||||
boolean isHashMatch = serverFileHash.equalsIgnoreCase(clientFileHash.trim());
|
||||
LogUtils.d("APKFileUtils", "【哈希对比】服务端SHA256:" + serverFileHash);
|
||||
LogUtils.d("APKFileUtils", "【哈希对比】客户端SHA256:" + clientFileHash.trim());
|
||||
if (!isHashMatch) {
|
||||
LogUtils.i("APKFileUtils", "【哈希对比结果】❌ 不匹配(字节级文件不一致)");
|
||||
return false;
|
||||
}
|
||||
LogUtils.i("APKFileUtils", "【哈希对比结果】✅ 匹配(字节级文件完全一致)");
|
||||
|
||||
// ===== 第二步:签名校验(直接读取CERT.RSA原始字节,与客户端严格对齐)=====
|
||||
String serverSignBase64 = getAPKSign(apkFile);
|
||||
if (isParamEmpty(serverSignBase64)) {
|
||||
LogUtils.w("APKFileUtils", "解析服务端APK签名失败:" + apkFileName);
|
||||
return false;
|
||||
}
|
||||
boolean isSignMatch = serverSignBase64.equals(clientSignBase64.trim());
|
||||
LogUtils.d("APKFileUtils", "【签名对比】服务端Base64:" + serverSignBase64);
|
||||
LogUtils.d("APKFileUtils", "【签名对比】客户端Base64:" + clientSignBase64.trim());
|
||||
if (!isSignMatch) {
|
||||
LogUtils.i("APKFileUtils", "【签名对比结果】❌ 不匹配(签名不一致)");
|
||||
return false;
|
||||
}
|
||||
LogUtils.i("APKFileUtils", "【签名对比结果】✅ 匹配(签名完全一致)");
|
||||
|
||||
// 所有校验通过
|
||||
LogUtils.i("APKFileUtils", "APK双校验全部通过:项目名=" + projectName + ",版本名=" + versionName + ",文件名=" + apkFileName);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("APKFileUtils", "APK双校验异常", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 稳定解析APK签名:直接读取CERT.RSA原始字节,SHA1+Base64(与客户端1:1对齐)
|
||||
* 解决X509证书解析的Too short异常,兼容所有APK(普通/加固/自定义打包)
|
||||
* @param apkFile APK文件
|
||||
* @return 签名Base64字符串,失败返回null
|
||||
*/
|
||||
private String getAPKSign(File apkFile) {
|
||||
JarFile jarFile = null;
|
||||
InputStream certIs = null;
|
||||
try {
|
||||
jarFile = new JarFile(apkFile);
|
||||
// 先找大写CERT.RSA,找不到再找小写,兼容所有打包工具
|
||||
JarEntry certEntry = jarFile.getJarEntry(CERT_RSA_UPPER);
|
||||
if (certEntry == null) {
|
||||
certEntry = jarFile.getJarEntry(CERT_RSA_LOWER);
|
||||
if (certEntry == null) {
|
||||
LogUtils.w("APKFileUtils", "APK中未找到签名文件:META-INF/CERT.RSA/cert.rsa");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// 核心:直接读取CERT.RSA的原始字节流(不做证书解析,适配PKCS7签名块)
|
||||
certIs = jarFile.getInputStream(certEntry);
|
||||
byte[] sigRawBytes = readStreamToBytes(certIs);
|
||||
if (sigRawBytes == null || sigRawBytes.length == 0) {
|
||||
LogUtils.w("APKFileUtils", "读取CERT.RSA原始字节为空");
|
||||
return null;
|
||||
}
|
||||
// 与客户端完全一致的处理流程:SHA1摘要 → Base64编码(去换行)
|
||||
MessageDigest md = MessageDigest.getInstance(SIGN_ALGORITHM);
|
||||
byte[] signDigest = md.digest(sigRawBytes);
|
||||
String signBase64 = Base64.getEncoder().encodeToString(signDigest)
|
||||
.replaceAll("\\r", "").replaceAll("\\n", "");
|
||||
|
||||
LogUtils.d("APKFileUtils", "APK签名解析成功(Base64):" + signBase64);
|
||||
return signBase64;
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
LogUtils.e("APKFileUtils", "解析签名失败:" + SIGN_ALGORITHM + "算法不存在", e);
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("APKFileUtils", "解析APK签名异常", e);
|
||||
return null;
|
||||
} finally {
|
||||
// 强制关闭流资源,避免内存泄漏
|
||||
try {
|
||||
if (certIs != null) certIs.close();
|
||||
if (jarFile != null) jarFile.close();
|
||||
} catch (IOException e) {
|
||||
LogUtils.e("APKFileUtils", "关闭签名文件流失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析APK文件的SHA256哈希(字节级唯一,任何字节修改都会改变)
|
||||
* @param apkFile APK文件
|
||||
* @return 小写64位SHA256哈希字符串,失败返回null
|
||||
*/
|
||||
private String getAPKFileHash(File apkFile) {
|
||||
FileInputStream fis = null;
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance(HASH_ALGORITHM);
|
||||
fis = new FileInputStream(apkFile);
|
||||
byte[] buffer = new byte[8192]; // 8K缓冲区,提升大APK读取效率
|
||||
int len;
|
||||
while ((len = fis.read(buffer)) != -1) {
|
||||
md.update(buffer, 0, len);
|
||||
}
|
||||
// 哈希字节转小写16进制字符串(64位,官方标准格式)
|
||||
byte[] hashBytes = md.digest();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (byte b : hashBytes) {
|
||||
sb.append(String.format("%02x", b));
|
||||
}
|
||||
String fileHash = sb.toString();
|
||||
LogUtils.d("APKFileUtils", "APK文件SHA256哈希解析成功:" + fileHash);
|
||||
return fileHash;
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
LogUtils.e("APKFileUtils", "获取文件哈希失败:" + HASH_ALGORITHM + "算法不存在", e);
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("APKFileUtils", "解析APK文件哈希异常", e);
|
||||
return null;
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
try {
|
||||
fis.close();
|
||||
} catch (IOException e) {
|
||||
LogUtils.e("APKFileUtils", "关闭APK文件流失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 流转字节数组工具方法:稳定读取任意输入流,无截断/空指针问题
|
||||
*/
|
||||
private byte[] readStreamToBytes(InputStream is) throws IOException {
|
||||
if (is == null) {
|
||||
LogUtils.w("APKFileUtils", "readStreamToBytes: 输入流为null");
|
||||
return new byte[0];
|
||||
}
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[4096];
|
||||
int len;
|
||||
while ((len = is.read(buffer)) != -1) {
|
||||
bos.write(buffer, 0, len);
|
||||
}
|
||||
byte[] result = bos.toByteArray();
|
||||
// 按顺序关闭流
|
||||
is.close();
|
||||
bos.close();
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 工具方法:判断参数是否为空(null/空字符串/全空格)
|
||||
*/
|
||||
private boolean isParamEmpty(String param) {
|
||||
return param == null || param.trim().isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
package cc.winboll.studio.libappbase.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Base64;
|
||||
|
||||
import cc.winboll.studio.libappbase.GlobalApplication;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.models.SignCheckResponse;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
/**
|
||||
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
|
||||
* @CreateTime 2026-01-20 19:17:00
|
||||
* @LastEditTime 2026-01-24 17:58:00
|
||||
* @Describe APPUtils 应用合法性校验工具类(OKHTTP网络校验版,兼容Java7)
|
||||
* 对外传入签名/哈希值,拼接调试标识后发起网络校验,主线程返回校验结果
|
||||
*/
|
||||
public class APPUtils {
|
||||
// ===================================== 全局常量/单例属性 =====================================
|
||||
public static final String TAG = "APPUtils";
|
||||
// 网络校验接口基础地址
|
||||
private static final String CHECK_API_URI = "api/app-signatures-check";
|
||||
// OKHTTP客户端单例(复用连接,避免资源浪费)
|
||||
private static final OkHttpClient sOkHttpClient = new OkHttpClient();
|
||||
// Gson解析单例(全局复用,提高解析效率)
|
||||
private static final Gson sGson = new Gson();
|
||||
|
||||
// ===================================== 对外核心校验方法 =====================================
|
||||
/**
|
||||
* 检查应用合法性(外部传入签名+哈希,拼接调试标识发起网络校验)
|
||||
* @param context 上下文,用于主线程回调
|
||||
* @param projectName 项目名称(服务端区分项目标识)
|
||||
* @param versionName 应用版本名(服务端版本校验)
|
||||
* @param clientSign 外部计算的应用签名字符串(Base64)
|
||||
* @param clientHash 外部计算的APK SHA256哈希字符串(小写16进制)
|
||||
* @param callback 校验结果回调(主线程调用,返回是否合法+提示信息)
|
||||
*/
|
||||
public void checkAPKValidation(Context context, String appName, String versionName,
|
||||
String clientSign, String clientHash, final CheckResultCallback callback) {
|
||||
// 方法调用+全量入参调试日志
|
||||
LogUtils.d(TAG, "checkAPKValidation: 方法调用,入参-> appName=" + appName
|
||||
+ ", versionName=" + versionName + ", clientSign=" + clientSign + ", clientHash=" + clientHash);
|
||||
|
||||
// 1. 核心入参空值校验(快速失败)
|
||||
if (context == null) {
|
||||
LogUtils.w(TAG, "checkAPKValidation: 入参context为空,直接返回校验失败");
|
||||
callCallbackOnMainThread(callback, false, "上下文对象不能为空");
|
||||
return;
|
||||
}
|
||||
if (isStringEmpty(appName)) {
|
||||
LogUtils.w(TAG, "checkAPKValidation: 入参projectName为空/空白,直接返回校验失败");
|
||||
callCallbackOnMainThread(callback, false, "项目名称不能为空");
|
||||
return;
|
||||
}
|
||||
if (isStringEmpty(versionName)) {
|
||||
LogUtils.w(TAG, "checkAPKValidation: 入参versionName为空/空白,直接返回校验失败");
|
||||
callCallbackOnMainThread(callback, false, "应用版本名不能为空");
|
||||
return;
|
||||
}
|
||||
if (isStringEmpty(clientSign)) {
|
||||
LogUtils.w(TAG, "checkAPKValidation: 入参clientSign为空/空白,直接返回校验失败");
|
||||
callCallbackOnMainThread(callback, false, "应用签名字符串不能为空");
|
||||
return;
|
||||
}
|
||||
if (isStringEmpty(clientHash)) {
|
||||
LogUtils.w(TAG, "checkAPKValidation: 入参clientHash为空/空白,直接返回校验失败");
|
||||
callCallbackOnMainThread(callback, false, "APK SHA256哈希字符串不能为空");
|
||||
return;
|
||||
}
|
||||
LogUtils.d(TAG, "checkAPKValidation: 入参校验通过,开始处理网络请求");
|
||||
|
||||
// 2. 动态参数URL编码(避免特殊字符导致请求解析异常)
|
||||
LogUtils.d(TAG, "checkAPKValidation: 开始对动态参数进行UTF-8 URL编码");
|
||||
String encodeProjectName = urlEncode(appName);
|
||||
String encodeVersionName = urlEncode(versionName);
|
||||
String encodeClientSign = urlEncode(clientSign);
|
||||
String encodeClientHash = urlEncode(clientHash);
|
||||
String isDebug = String.valueOf(GlobalApplication.isDebugging());
|
||||
LogUtils.d(TAG, "checkAPKValidation: 参数编码完成,debug标识=" + isDebug);
|
||||
|
||||
// 3. 构建完整网络校验请求URL
|
||||
String requestUrl = String.format("%s?isDebug=%s&projectName=%s&versionName=%s&clientSign=%s&clientHash=%s",
|
||||
GlobalApplication.getWinbollHost() + CHECK_API_URI,
|
||||
isDebug,
|
||||
encodeProjectName,
|
||||
encodeVersionName,
|
||||
encodeClientSign,
|
||||
encodeClientHash);
|
||||
LogUtils.d(TAG, "checkAPKValidation: 构建网络校验请求URL=" + requestUrl);
|
||||
|
||||
// 4. 发起OKHTTP异步GET请求(避免阻塞主线程)
|
||||
LogUtils.d(TAG, "checkAPKValidation: 发起异步网络校验请求");
|
||||
Request request = new Request.Builder().url(requestUrl).build();
|
||||
sOkHttpClient.newCall(request).enqueue(new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
String errorMsg = "网络校验请求失败:" + e.getMessage();
|
||||
LogUtils.e(TAG, "checkAPKValidation: " + errorMsg, e);
|
||||
callCallbackOnMainThread(callback, false, errorMsg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
// 响应成功,解析返回JSON
|
||||
String responseJson = response.body().string();
|
||||
LogUtils.d(TAG, "checkAPKValidation: 网络校验响应成功,JSON=" + responseJson);
|
||||
SignCheckResponse checkResponse = sGson.fromJson(responseJson, SignCheckResponse.class);
|
||||
boolean isValid = checkResponse != null && checkResponse.isValid();
|
||||
String msg = checkResponse != null ? checkResponse.getMessage() : "服务端响应解析失败";
|
||||
LogUtils.d(TAG, "checkAPKValidation: 校验结果解析完成,isValid=" + isValid + ", 提示信息=" + msg);
|
||||
callCallbackOnMainThread(callback, isValid, msg);
|
||||
} else {
|
||||
// 响应失败,返回状态码信息
|
||||
String errorMsg = "网络校验响应失败,服务端状态码=" + response.code();
|
||||
LogUtils.e(TAG, "checkAPKValidation: " + errorMsg);
|
||||
callCallbackOnMainThread(callback, false, errorMsg);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ===================================== 内部工具方法 =====================================
|
||||
/**
|
||||
* 字符串空值/空白校验工具
|
||||
* @param str 待校验字符串
|
||||
* @return true=空/空白,false=非空
|
||||
*/
|
||||
private boolean isStringEmpty(String str) {
|
||||
return str == null || str.trim().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* URL编码工具(Java7适配,UTF-8编码,处理特殊字符)
|
||||
* @param content 待编码内容
|
||||
* @return 编码后的字符串,编码失败返回原内容
|
||||
*/
|
||||
private String urlEncode(String content) {
|
||||
try {
|
||||
return URLEncoder.encode(content, "UTF-8");
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "urlEncode: 字符串编码失败,content=" + content, e);
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 主线程执行回调(统一处理,避免外部线程切换)
|
||||
* @param callback 回调接口
|
||||
* @param isValid 是否合法
|
||||
* @param message 提示信息
|
||||
*/
|
||||
private void callCallbackOnMainThread(final CheckResultCallback callback,
|
||||
final boolean isValid, final String message) {
|
||||
if (callback == null) {
|
||||
LogUtils.w(TAG, "callCallbackOnMainThread: 回调接口为null,无需执行");
|
||||
return;
|
||||
}
|
||||
// 已在主线程直接执行,否则切换主线程
|
||||
if (Looper.myLooper() == Looper.getMainLooper()) {
|
||||
callback.onResult(isValid, message);
|
||||
} else {
|
||||
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
callback.onResult(isValid, message);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ===================================== 校验结果回调接口 =====================================
|
||||
/**
|
||||
* 应用合法性校验结果回调接口(主线程调用)
|
||||
*/
|
||||
public interface CheckResultCallback {
|
||||
/**
|
||||
* 校验结果回调方法
|
||||
* @param isValid 是否合法(true=校验通过,false=校验失败)
|
||||
* @param message 校验提示信息(失败时返回错误原因,成功时返回服务端提示)
|
||||
*/
|
||||
void onResult(boolean isValid, String message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,272 @@
|
||||
package cc.winboll.studio.libappbase.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.Signature;
|
||||
import android.util.Base64;
|
||||
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
/**
|
||||
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
|
||||
* @CreateTime 2026-01-24 10:00:00
|
||||
* @LastEditTime 2026-01-24 22:00:00
|
||||
* @Describe 客户端签名工具类:与服务端APKFileUtils签名/哈希校验逻辑严格对齐,纯Java7实现;兼容MT重签名(遍历META-INF所有RSA文件),增加PackageManager兜底方案
|
||||
*/
|
||||
public class ApkSignUtils {
|
||||
// ===================================== 全局常量定义 =====================================
|
||||
private static final String TAG = "ApkSignUtils";
|
||||
// 加密算法常量
|
||||
private static final String ALGORITHM_SHA1 = "SHA1";
|
||||
private static final String ALGORITHM_SHA256 = "SHA-256";
|
||||
// 缓冲区大小常量(按业务场景区分)
|
||||
private static final int BUFFER_4K = 4096;
|
||||
private static final int BUFFER_8K = 8192;
|
||||
// 签名文件目录与后缀
|
||||
private static final String META_INF_DIR = "META-INF/";
|
||||
private static final String RSA_SUFFIX_UPPER = ".RSA";
|
||||
private static final String RSA_SUFFIX_LOWER = ".rsa";
|
||||
|
||||
// ===================================== 对外核心方法 =====================================
|
||||
/**
|
||||
* 获取与服务端对齐的签名Base64串(兼容MT重签名)
|
||||
* 优先逻辑:遍历APK内META-INF所有.RSA文件 → 读取第一个有效文件原始字节 → SHA1摘要 → Base64.NO_WRAP
|
||||
* 兜底逻辑:PackageManager获取系统解析的签名 → SHA1摘要 → Base64.NO_WRAP
|
||||
* @param context 上下文,用于获取当前应用APK路径/包信息
|
||||
* @return 签名Base64字符串,任意步骤失败返回null
|
||||
*/
|
||||
public static String getApkSignAlignedWithServer(Context context) {
|
||||
LogUtils.d(TAG, "getApkSignAlignedWithServer: 方法调用,开始执行服务端对齐签名计算(兼容MT重签名)");
|
||||
// 入参空值快速校验
|
||||
if (context == null) {
|
||||
LogUtils.w(TAG, "getApkSignAlignedWithServer: 入参context为null,直接返回null");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 方案1:优先读取APK内META-INF目录下所有RSA文件(兼容MT重签名任意命名)
|
||||
String signBase64 = getSignFromApkRsaFile(context);
|
||||
if (signBase64 != null) {
|
||||
LogUtils.d(TAG, "getApkSignAlignedWithServer: 方案1成功(APK内读取RSA文件),返回签名Base64");
|
||||
return signBase64;
|
||||
}
|
||||
|
||||
// 方案2:兜底 - PackageManager获取系统解析的应用签名(避免APK文件读取失败)
|
||||
signBase64 = getSignFromPackageManager(context);
|
||||
if (signBase64 != null) {
|
||||
LogUtils.d(TAG, "getApkSignAlignedWithServer: 方案2成功(PackageManager兜底),返回签名Base64");
|
||||
return signBase64;
|
||||
}
|
||||
|
||||
// 所有方案失败
|
||||
LogUtils.e(TAG, "getApkSignAlignedWithServer: 所有签名获取方案均失败");
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前运行APK的SHA256哈希值(兼容重签名APK)
|
||||
* 逻辑:读取APK完整文件字节流 → SHA256摘要 → 转小写64位16进制字符串,服务端同款校验逻辑
|
||||
* @param context 上下文,用于获取当前应用APK的真实安装路径
|
||||
* @return SHA256小写16进制字符串,任意步骤失败返回null
|
||||
*/
|
||||
public static String getApkSHA256Hash(Context context) {
|
||||
LogUtils.d(TAG, "getApkSHA256Hash: 方法调用,开始执行APK文件SHA256哈希计算");
|
||||
// 入参空值快速校验
|
||||
if (context == null) {
|
||||
LogUtils.w(TAG, "getApkSHA256Hash: 入参context为null,直接返回null");
|
||||
return null;
|
||||
}
|
||||
|
||||
JarFile jarFile = null;
|
||||
FileInputStream fis = null;
|
||||
try {
|
||||
// 1. 获取当前应用APK真实路径
|
||||
ApplicationInfo appInfo = context.getApplicationContext().getApplicationInfo();
|
||||
String apkPath = appInfo.sourceDir;
|
||||
LogUtils.d(TAG, "getApkSHA256Hash: 成功获取APK路径,path=" + apkPath);
|
||||
if (apkPath == null || apkPath.trim().isEmpty()) {
|
||||
LogUtils.e(TAG, "getApkSHA256Hash: 获取到的APK路径为空,无法读取文件计算哈希");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 2. 读取APK文件并计算SHA256哈希(完善流关闭)
|
||||
File apkFile = new File(apkPath);
|
||||
MessageDigest md = MessageDigest.getInstance(ALGORITHM_SHA256);
|
||||
fis = new FileInputStream(apkFile);
|
||||
byte[] buffer = new byte[BUFFER_8K];
|
||||
int readLen;
|
||||
while ((readLen = fis.read(buffer)) != -1) {
|
||||
md.update(buffer, 0, readLen);
|
||||
}
|
||||
LogUtils.d(TAG, "getApkSHA256Hash: APK文件读取完成,开始转换哈希结果");
|
||||
|
||||
// 3. 哈希字节数组转小写64位16进制字符串
|
||||
byte[] hashBytes = md.digest();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (byte b : hashBytes) {
|
||||
sb.append(String.format("%02x", b));
|
||||
}
|
||||
String sha256Hash = sb.toString();
|
||||
LogUtils.d(TAG, "getApkSHA256Hash: APK SHA256哈希计算完成,成功返回结果");
|
||||
return sha256Hash;
|
||||
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
LogUtils.e(TAG, "getApkSHA256Hash: 获取SHA-256算法实例失败", e);
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "getApkSHA256Hash: 计算APK SHA256哈希发生未知异常", e);
|
||||
} finally {
|
||||
// 强制关闭流,避免重签名APK解析的流泄漏
|
||||
try {
|
||||
if (fis != null) fis.close();
|
||||
if (jarFile != null) jarFile.close();
|
||||
} catch (IOException e) {
|
||||
LogUtils.e(TAG, "getApkSHA256Hash: 关闭流资源异常", e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// ===================================== 内部核心工具方法(兼容重签名) =====================================
|
||||
/**
|
||||
* 方案1:遍历APK内META-INF所有.RSA/.rsa文件,读取第一个有效文件计算签名
|
||||
* @param context 上下文
|
||||
* @return 签名Base64,失败返回null
|
||||
*/
|
||||
private static String getSignFromApkRsaFile(Context context) {
|
||||
JarFile jarFile = null;
|
||||
InputStream is = null;
|
||||
try {
|
||||
// 获取APK路径
|
||||
ApplicationInfo appInfo = context.getApplicationContext().getApplicationInfo();
|
||||
String apkPath = appInfo.sourceDir;
|
||||
if (apkPath == null || apkPath.trim().isEmpty()) {
|
||||
LogUtils.w(TAG, "getSignFromApkRsaFile: APK路径为空,跳过该方案");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 打开APK的JarFile
|
||||
jarFile = new JarFile(apkPath);
|
||||
Enumeration<JarEntry> entries = jarFile.entries();
|
||||
JarEntry targetRsaEntry = null;
|
||||
|
||||
// 遍历所有条目,找到META-INF下第一个.RSA/.rsa文件
|
||||
while (entries.hasMoreElements()) {
|
||||
JarEntry entry = entries.nextElement();
|
||||
String entryName = entry.getName();
|
||||
// 过滤:META-INF目录下 + 以.RSA/.rsa结尾 + 非目录
|
||||
if (entryName.startsWith(META_INF_DIR) && !entry.isDirectory()
|
||||
&& (entryName.endsWith(RSA_SUFFIX_UPPER) || entryName.endsWith(RSA_SUFFIX_LOWER))) {
|
||||
targetRsaEntry = entry;
|
||||
LogUtils.d(TAG, "getSignFromApkRsaFile: 找到有效签名文件,name=" + entryName);
|
||||
break; // 取第一个有效RSA文件即可
|
||||
}
|
||||
}
|
||||
|
||||
// 未找到任何RSA文件
|
||||
if (targetRsaEntry == null) {
|
||||
LogUtils.w(TAG, "getSignFromApkRsaFile: 未在META-INF找到任何.RSA/.rsa签名文件");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 读取RSA文件原始字节
|
||||
is = jarFile.getInputStream(targetRsaEntry);
|
||||
byte[] certRawBytes = readStreamToBytes(is);
|
||||
if (certRawBytes == null || certRawBytes.length == 0) {
|
||||
LogUtils.w(TAG, "getSignFromApkRsaFile: 读取RSA文件字节为空");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 计算SHA1+Base64
|
||||
MessageDigest md = MessageDigest.getInstance(ALGORITHM_SHA1);
|
||||
byte[] signDigest = md.digest(certRawBytes);
|
||||
return Base64.encodeToString(signDigest, Base64.NO_WRAP);
|
||||
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "getSignFromApkRsaFile: 从APK内读取RSA文件失败", e);
|
||||
return null;
|
||||
} finally {
|
||||
// 强制关闭所有流
|
||||
try {
|
||||
if (is != null) is.close();
|
||||
if (jarFile != null) jarFile.close();
|
||||
} catch (IOException e) {
|
||||
LogUtils.e(TAG, "getSignFromApkRsaFile: 关闭流资源异常", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 方案2:兜底 - 通过PackageManager获取系统解析的应用签名
|
||||
* 避免APK文件读取失败(如权限、解析问题),兼容所有重签名场景
|
||||
* @param context 上下文
|
||||
* @return 签名Base64,失败返回null
|
||||
*/
|
||||
private static String getSignFromPackageManager(Context context) {
|
||||
try {
|
||||
// 获取当前应用包信息(包含签名)
|
||||
PackageInfo packageInfo = context.getPackageManager()
|
||||
.getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES);
|
||||
if (packageInfo == null || packageInfo.signatures == null || packageInfo.signatures.length == 0) {
|
||||
LogUtils.w(TAG, "getSignFromPackageManager: 未获取到应用签名信息");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 取第一个签名(重签名后一般只有一个签名)
|
||||
Signature signature = packageInfo.signatures[0];
|
||||
byte[] signBytes = signature.toByteArray();
|
||||
|
||||
// 计算SHA1+Base64,与服务端逻辑对齐
|
||||
MessageDigest md = MessageDigest.getInstance(ALGORITHM_SHA1);
|
||||
byte[] signDigest = md.digest(signBytes);
|
||||
return Base64.encodeToString(signDigest, Base64.NO_WRAP);
|
||||
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
LogUtils.e(TAG, "getSignFromPackageManager: 包名未找到,无法获取签名", e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
LogUtils.e(TAG, "getSignFromPackageManager: 获取SHA1算法实例失败", e);
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "getSignFromPackageManager: PackageManager获取签名失败", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 输入流转字节数组,通用工具方法(完善try-finally)
|
||||
* 4K缓冲区,适配小文件读取(如RSA签名文件),保证流资源正常关闭
|
||||
* @param is 待读取的输入流
|
||||
* @return 转换后的字节数组,流为null/读取失败返回空字节数组
|
||||
* @throws IOException 流读取相关异常向上抛出
|
||||
*/
|
||||
private static byte[] readStreamToBytes(InputStream is) throws IOException {
|
||||
if (is == null) {
|
||||
LogUtils.w(TAG, "readStreamToBytes: 入参输入流为null,返回空字节数组");
|
||||
return new byte[0];
|
||||
}
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[BUFFER_4K];
|
||||
int readLen;
|
||||
try {
|
||||
while ((readLen = is.read(buffer)) != -1) {
|
||||
bos.write(buffer, 0, readLen);
|
||||
}
|
||||
return bos.toByteArray();
|
||||
} finally {
|
||||
// 强制关闭所有流
|
||||
is.close();
|
||||
bos.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,305 @@
|
||||
package cc.winboll.studio.libappbase.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Environment;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.models.SFTPAuthModel;
|
||||
|
||||
/**
|
||||
* 文件备份工具类(单例模式)
|
||||
* 区分应用Data目录/应用专属外部文件目录双Map管理备份文件路径
|
||||
* 核心功能:文件添加/移除 + ZIP打包(分data/sdcard目录) + SFTP分步式上传(登录→传输→登出)
|
||||
* 依赖:FTPUtils(单例)、SFTPAuthModel(外部实体类)、Android上下文
|
||||
* 兼容:Java7、Android 6.0+,无第三方依赖(ZIP为原生实现),免动态读写权限
|
||||
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2026/01/30 20:18:00
|
||||
* @LastEditTime 2026/02/01 02:05:00
|
||||
*/
|
||||
public class BackupUtils {
|
||||
public static final String TAG = "BackupUtils";
|
||||
// ZIP内部分级目录常量(统一维护,便于修改)
|
||||
private static final String ZIP_DIR_DATA = "data/";
|
||||
private static final String ZIP_DIR_SDCARD = "sdcard/";
|
||||
|
||||
// 单例实例(双重校验锁,volatile保证可见性,线程安全)
|
||||
private static volatile BackupUtils sInstance;
|
||||
|
||||
// 双Map分目录管理:key=文件唯一标识,value=对应目录下的相对路径
|
||||
private final Map<String, String> mDataDirFileMap; // 基础根目录:应用私有Data目录(/data/data/[包名]/files)
|
||||
private final Map<String, String> mSdcardFileMap; // 基础根目录:应用专属外部文件目录(/storage/emulated/0/Android/data/[包名]/files)
|
||||
|
||||
// 全局上下文(持有Application上下文,避免Activity内存泄漏)
|
||||
private Context mAppContext;
|
||||
// SFTP认证配置(直接引用外部实体类,无内部封装)
|
||||
private SFTPAuthModel mFtpAuthModel;
|
||||
// SFTP服务器指定上传目录(独立参数传入,标准化后作为成员变量)
|
||||
private String mFtpTargetDir;
|
||||
// 应用专属外部文件目录(SDCard Map的基础根目录,初始化时赋值,避免重复创建)
|
||||
private File mAppExternalFilesDir;
|
||||
|
||||
// 私有构造器:新增双Map入参,空值则使用内部默认初始化,非空则用入参初始化
|
||||
private BackupUtils(Context context, SFTPAuthModel ftpAuthModel, String ftpTargetDir,
|
||||
Map<String, String> dataDirFileMap, Map<String, String> sdcardFileMap) {
|
||||
this.mAppContext = context.getApplicationContext();
|
||||
this.mFtpAuthModel = ftpAuthModel;
|
||||
// 初始化SDCard Map的基础根目录:应用专属外部文件目录(/storage/emulated/0/Android/data/[包名]/files)
|
||||
this.mAppExternalFilesDir = mAppContext.getExternalFilesDir(null);
|
||||
// 标准化SFTP上传目录:空则默认/,非空则补全结尾斜杠
|
||||
this.mFtpTargetDir = TextUtils.isEmpty(ftpTargetDir) ? "/" : (ftpTargetDir.endsWith("/") ? ftpTargetDir : ftpTargetDir + "/");
|
||||
|
||||
// 核心修改:入参Map非空且非空集合时,使用入参初始化;否则内部new HashMap()
|
||||
this.mDataDirFileMap = (dataDirFileMap != null && !dataDirFileMap.isEmpty())
|
||||
? new HashMap<>(dataDirFileMap) // 新建Map避免外部篡改内部数据
|
||||
: new HashMap<>();
|
||||
this.mSdcardFileMap = (sdcardFileMap != null && !sdcardFileMap.isEmpty())
|
||||
? new HashMap<>(sdcardFileMap) // 深拷贝,隔离外部引用
|
||||
: new HashMap<>();
|
||||
|
||||
LogUtils.d(TAG, "BackupUtils初始化完成 → SFTP服务器:" + ftpAuthModel.getFtpServer() + ":" + ftpAuthModel.getFtpPort() + " | 上传目录:" + mFtpTargetDir);
|
||||
LogUtils.d(TAG, "SDCard Map基础根目录:" + (mAppExternalFilesDir == null ? "获取失败" : mAppExternalFilesDir.getAbsolutePath()));
|
||||
LogUtils.d(TAG, "初始化后DataMap大小:" + mDataDirFileMap.size() + " | SdcardMap大小:" + mSdcardFileMap.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* 单例初始化方法(必须先调用,否则getInstance()会抛异常)
|
||||
* 新增双Map入参,支持外部初始化待备份文件列表
|
||||
* @param context 上下文(推荐传Application,避免内存泄漏)
|
||||
* @param ftpAuthModel 外部SFTP认证实体类(含服务器/账号/端口等)
|
||||
* @param ftpTargetDir SFTP服务器指定上传目录(如/backup,自动补全斜杠)
|
||||
* @param dataDirFileMap 外部传入的Data目录文件Map,null/空则内部默认初始化
|
||||
* @param sdcardFileMap 外部传入的SDCard目录文件Map,null/空则内部默认初始化
|
||||
* @return BackupUtils单例实例
|
||||
*/
|
||||
public static BackupUtils getInstance(Context context, SFTPAuthModel ftpAuthModel, String ftpTargetDir,
|
||||
Map<String, String> dataDirFileMap, Map<String, String> sdcardFileMap) {
|
||||
if (sInstance == null) {
|
||||
synchronized (BackupUtils.class) {
|
||||
if (sInstance == null) {
|
||||
// 前置强校验:避免空参数导致后续空指针
|
||||
if (context == null) {
|
||||
throw new IllegalArgumentException("初始化失败:Context 不能为空");
|
||||
}
|
||||
if (ftpAuthModel == null || TextUtils.isEmpty(ftpAuthModel.getFtpServer())) {
|
||||
throw new IllegalArgumentException("初始化失败:SFTPAuthModel/ftpServer 不能为空");
|
||||
}
|
||||
// 透传新增的双Map入参至构造器
|
||||
sInstance = new BackupUtils(context, ftpAuthModel, ftpTargetDir, dataDirFileMap, sdcardFileMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重载默认初始化方法:兼容原有调用逻辑,无需传入Map,内部默认初始化
|
||||
* 避免修改后影响原有代码调用
|
||||
*/
|
||||
public static BackupUtils getInstance(Context context, SFTPAuthModel ftpAuthModel, String ftpTargetDir) {
|
||||
return getInstance(context, ftpAuthModel, ftpTargetDir, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单例实例(需先调用带参getInstance初始化)
|
||||
* @return BackupUtils单例实例
|
||||
*/
|
||||
public static BackupUtils getInstance() {
|
||||
if (sInstance == null) {
|
||||
throw new IllegalStateException("BackupUtils未初始化,请先调用getInstance(Context, SFTPAuthModel, String[, Map, Map])");
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
// ====================================== 以下原有方法均未修改 ======================================
|
||||
public void addDataDirFile(String key, String relativePath) {
|
||||
if (!TextUtils.isEmpty(key) && !TextUtils.isEmpty(relativePath)) {
|
||||
mDataDirFileMap.put(key, relativePath);
|
||||
LogUtils.d(TAG, "添加Data目录文件:" + key + " → " + relativePath);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeDataDirFile(String key) {
|
||||
if (!TextUtils.isEmpty(key) && mDataDirFileMap.containsKey(key)) {
|
||||
mDataDirFileMap.remove(key);
|
||||
LogUtils.d(TAG, "移除Data目录文件:" + key);
|
||||
}
|
||||
}
|
||||
|
||||
public String getDataDirFile(String key) {
|
||||
return mDataDirFileMap.get(key);
|
||||
}
|
||||
|
||||
public Map<String, String> getAllDataDirFiles() {
|
||||
return new HashMap<>(mDataDirFileMap);
|
||||
}
|
||||
|
||||
public void clearDataDirFiles() {
|
||||
mDataDirFileMap.clear();
|
||||
LogUtils.d(TAG, "清空Data目录所有备份文件");
|
||||
}
|
||||
|
||||
public void addSdcardFile(String key, String relativePath) {
|
||||
if (!TextUtils.isEmpty(key) && !TextUtils.isEmpty(relativePath) && mAppExternalFilesDir != null) {
|
||||
mSdcardFileMap.put(key, relativePath);
|
||||
LogUtils.d(TAG, "添加外部文件目录文件:" + key + " → " + relativePath);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeSdcardFile(String key) {
|
||||
if (!TextUtils.isEmpty(key) && mSdcardFileMap.containsKey(key)) {
|
||||
mSdcardFileMap.remove(key);
|
||||
LogUtils.d(TAG, "移除外部文件目录文件:" + key);
|
||||
}
|
||||
}
|
||||
|
||||
public String getSdcardFile(String key) {
|
||||
return mSdcardFileMap.get(key);
|
||||
}
|
||||
|
||||
public Map<String, String> getAllSdcardFiles() {
|
||||
return new HashMap<>(mSdcardFileMap);
|
||||
}
|
||||
|
||||
public void clearSdcardFiles() {
|
||||
mSdcardFileMap.clear();
|
||||
LogUtils.d(TAG, "清空外部文件目录所有备份文件");
|
||||
}
|
||||
|
||||
public boolean packAndUploadByFtp() {
|
||||
if (mDataDirFileMap.isEmpty() && mSdcardFileMap.isEmpty()) {
|
||||
LogUtils.e(TAG, "SFTP上传失败:无待备份文件(DataDir+外部文件目录均为空)");
|
||||
return false;
|
||||
}
|
||||
if (mAppExternalFilesDir == null) {
|
||||
LogUtils.e(TAG, "SFTP上传失败:应用专属外部文件目录获取失败,无法访问文件");
|
||||
return false;
|
||||
}
|
||||
|
||||
String zipFileName = UUID.randomUUID().toString().replace("-", "")
|
||||
+ "-" + System.currentTimeMillis() + ".zip";
|
||||
File tempZipFile = new File(mAppContext.getExternalCacheDir(), zipFileName);
|
||||
String remoteFtpFilePath = mFtpTargetDir + zipFileName;
|
||||
|
||||
FTPUtils ftpUtils = FTPUtils.getInstance();
|
||||
boolean isUploadSuccess = false;
|
||||
|
||||
try {
|
||||
LogUtils.d(TAG, "开始SFTP登录:" + mFtpAuthModel.getFtpServer() + ":" + mFtpAuthModel.getFtpPort());
|
||||
boolean isFtpLogin = ftpUtils.login(mFtpAuthModel);
|
||||
if (!isFtpLogin) {
|
||||
LogUtils.e(TAG, "SFTP上传失败:SFTP登录失败(账号/密码/服务器/端口错误)");
|
||||
return false;
|
||||
}
|
||||
LogUtils.i(TAG, "SFTP登录成功,准备打包文件:" + zipFileName);
|
||||
|
||||
LogUtils.d(TAG, "开始本地ZIP打包(分data/sdcard目录),临时文件路径:" + tempZipFile.getAbsolutePath());
|
||||
boolean isPackSuccess = packFilesToZip(tempZipFile);
|
||||
if (!isPackSuccess || !tempZipFile.exists() || tempZipFile.length() == 0) {
|
||||
LogUtils.e(TAG, "SFTP上传失败:ZIP打包失败(文件不存在/空文件)");
|
||||
return false;
|
||||
}
|
||||
LogUtils.i(TAG, "ZIP打包成功,文件大小:" + tempZipFile.length() / 1024 + "KB");
|
||||
|
||||
LogUtils.d(TAG, "开始SFTP上传:本地→SFTP" + remoteFtpFilePath);
|
||||
isUploadSuccess = ftpUtils.uploadFile(tempZipFile.getAbsolutePath(), remoteFtpFilePath);
|
||||
if (isUploadSuccess) {
|
||||
LogUtils.i(TAG, "SFTP上传全流程成功:" + remoteFtpFilePath);
|
||||
} else {
|
||||
LogUtils.e(TAG, "SFTP上传失败:文件传输到服务器失败(响应码异常/权限不足)");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "SFTP上传异常:" + e.getMessage(), e);
|
||||
isUploadSuccess = false;
|
||||
} finally {
|
||||
if (ftpUtils.isConnected()) {
|
||||
ftpUtils.logout();
|
||||
}
|
||||
ftpUtils.disconnect();
|
||||
if (tempZipFile.exists()) {
|
||||
boolean isDelete = tempZipFile.delete();
|
||||
LogUtils.d(TAG, "本地临时ZIP文件删除:" + (isDelete ? "成功" : "失败"));
|
||||
}
|
||||
System.gc();
|
||||
}
|
||||
|
||||
return isUploadSuccess;
|
||||
}
|
||||
|
||||
private boolean packFilesToZip(File zipFile) {
|
||||
ZipOutputStream zos = null;
|
||||
try {
|
||||
zos = new ZipOutputStream(new FileOutputStream(zipFile), Charset.forName("UTF-8"));
|
||||
zos.setLevel(ZipOutputStream.DEFLATED);
|
||||
|
||||
if (!mDataDirFileMap.isEmpty()) {
|
||||
packDirFilesToZip(zos, mDataDirFileMap, mAppContext.getFilesDir(), ZIP_DIR_DATA);
|
||||
LogUtils.d(TAG, "Data目录文件已打包到ZIP→" + ZIP_DIR_DATA + "子目录");
|
||||
}
|
||||
if (!mSdcardFileMap.isEmpty() && mAppExternalFilesDir != null) {
|
||||
packDirFilesToZip(zos, mSdcardFileMap, mAppExternalFilesDir, ZIP_DIR_SDCARD);
|
||||
LogUtils.d(TAG, "应用专属外部文件目录文件已打包到ZIP→" + ZIP_DIR_SDCARD + "子目录");
|
||||
}
|
||||
|
||||
zos.flush();
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
LogUtils.e(TAG, "ZIP打包IO异常:" + e.getMessage(), e);
|
||||
return false;
|
||||
} finally {
|
||||
if (zos != null) {
|
||||
try {
|
||||
zos.close();
|
||||
} catch (IOException e) {
|
||||
LogUtils.e(TAG, "关闭ZIP流异常:" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void packDirFilesToZip(ZipOutputStream zos, Map<String, String> fileMap, File baseDir, String zipSubDir) {
|
||||
for (Map.Entry<String, String> entry : fileMap.entrySet()) {
|
||||
String relativePath = entry.getValue();
|
||||
if (TextUtils.isEmpty(relativePath)) {
|
||||
continue;
|
||||
}
|
||||
File localFile = new File(baseDir, relativePath);
|
||||
if (!localFile.exists() || !localFile.isFile()) {
|
||||
LogUtils.w(TAG, "跳过无效文件:" + localFile.getAbsolutePath());
|
||||
continue;
|
||||
}
|
||||
String zipInnerPath = zipSubDir + relativePath;
|
||||
try {
|
||||
addSingleFileToZip(zos, localFile, zipInnerPath);
|
||||
} catch (IOException e) {
|
||||
LogUtils.e(TAG, "打包单个文件失败:" + zipInnerPath, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addSingleFileToZip(ZipOutputStream zos, File localFile, String zipInnerPath) throws IOException {
|
||||
ZipEntry zipEntry = new ZipEntry(zipInnerPath);
|
||||
zos.putNextEntry(zipEntry);
|
||||
FileInputStream fis = new FileInputStream(localFile);
|
||||
byte[] buffer = new byte[4096];
|
||||
int len;
|
||||
while ((len = fis.read(buffer)) != -1) {
|
||||
zos.write(buffer, 0, len);
|
||||
}
|
||||
fis.close();
|
||||
zos.closeEntry();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,487 @@
|
||||
package cc.winboll.studio.libappbase.utils;
|
||||
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.models.SFTPAuthModel;
|
||||
import com.jcraft.jsch.ChannelSftp;
|
||||
import com.jcraft.jsch.JSch;
|
||||
import com.jcraft.jsch.JSchException;
|
||||
import com.jcraft.jsch.Session;
|
||||
import com.jcraft.jsch.SftpATTRS;
|
||||
import com.jcraft.jsch.SftpException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Properties;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* SFTP/FTP工具类(单例模式)- Java7兼容 · 适配FTPAuthModel实体类
|
||||
* 底层严格基于JSch 0.1.54原生ChannelSftp+SftpException接口实现,替换原commons-net FTP
|
||||
* 核心功能:登录/登出、文件上传/下载、文件夹列举、文件/文件夹存在性判断
|
||||
* 依赖:com.jcraft:jsch:0.1.54
|
||||
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2026/01/30 19:04
|
||||
*/
|
||||
public class FTPUtils {
|
||||
// 单例实例(双重校验锁 volatile 保证可见性,Java7兼容)
|
||||
private static volatile FTPUtils sInstance;
|
||||
// JSch核心对象:Session(连接会话)、ChannelSftp(SFTP通道)
|
||||
private JSch mJSch;
|
||||
private Session mSession;
|
||||
private ChannelSftp mSftpChannel;
|
||||
// 日志TAG
|
||||
public static final String TAG = "FTPUtils";
|
||||
// SFTP默认端口(FTPAuthModel未设置时使用)
|
||||
private static final int DEFAULT_SFTP_PORT = 22;
|
||||
// 连接超时时间 5s(Java7原生Socket超时)
|
||||
private static final int CONNECT_TIMEOUT = 5000;
|
||||
|
||||
// 私有构造器:禁止外部实例化
|
||||
private FTPUtils() {
|
||||
initSftpClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单例实例(双重校验锁,线程安全,Java7兼容)
|
||||
* @return FTPUtils 单例
|
||||
*/
|
||||
public static FTPUtils getInstance() {
|
||||
if (sInstance == null) {
|
||||
synchronized (FTPUtils.class) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new FTPUtils();
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化SFTP客户端(JSch),创建核心原生对象
|
||||
*/
|
||||
private void initSftpClient() {
|
||||
if (mJSch == null) {
|
||||
mJSch = new JSch();
|
||||
LogUtils.d(TAG, "SFTP客户端(JSch)初始化完成");
|
||||
}
|
||||
// 重置会话和通道,避免连接残留
|
||||
mSession = null;
|
||||
mSftpChannel = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 【推荐】SFTP登录(基于FTPAuthModel实体类,完全兼容原有参数)
|
||||
* @param ftpAuthModel 登录配置实体类(不能为空,端口默认22,编码默认UTF-8)
|
||||
* @return 登录成功返回true,失败false
|
||||
*/
|
||||
public boolean login(SFTPAuthModel ftpAuthModel) {
|
||||
// 1. 实体类非空校验
|
||||
if (ftpAuthModel == null) {
|
||||
LogUtils.e(TAG, "SFTP登录失败:FTPAuthModel实体类为null");
|
||||
return false;
|
||||
}
|
||||
// 2. 核心参数校验(服务器地址不能为空)
|
||||
if (isParamEmpty(ftpAuthModel.getFtpServer())) {
|
||||
LogUtils.e(TAG, "SFTP登录失败:服务器地址(ftpServer)不能为空");
|
||||
return false;
|
||||
}
|
||||
// 3. 若已连接,先断开
|
||||
if (isConnected()) {
|
||||
logout();
|
||||
}
|
||||
// 4. 重新初始化客户端
|
||||
initSftpClient();
|
||||
|
||||
try {
|
||||
// 获取服务器地址、端口(默认22)、账号、密码
|
||||
String host = ftpAuthModel.getFtpServer();
|
||||
int port = ftpAuthModel.getFtpPort() <= 0 ? DEFAULT_SFTP_PORT : ftpAuthModel.getFtpPort();
|
||||
String username = ftpAuthModel.getFtpUsername();
|
||||
String password = ftpAuthModel.getFtpPassword();
|
||||
|
||||
// SFTP不支持匿名登录,账号密码不能为空(原生接口无匿名登录能力)
|
||||
if (isParamEmpty(username) || isParamEmpty(password)) {
|
||||
LogUtils.e(TAG, "SFTP登录失败:SFTP不支持匿名登录,请配置有效账号密码");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 1. 创建JSch会话(原生接口)
|
||||
mSession = mJSch.getSession(username, host, port);
|
||||
mSession.setPassword(password);
|
||||
|
||||
// 2. 设置会话属性(跳过SSH密钥校验,适配大部分服务器)
|
||||
Properties sessionProps = new Properties();
|
||||
sessionProps.put("StrictHostKeyChecking", "no");
|
||||
sessionProps.put("PreferredAuthentications", "password");
|
||||
mSession.setConfig(sessionProps);
|
||||
|
||||
// 3. 设置会话连接超时(原生接口,底层Socket超时)
|
||||
mSession.setTimeout(CONNECT_TIMEOUT);
|
||||
|
||||
// 4. 建立会话连接(原生接口)
|
||||
mSession.connect();
|
||||
LogUtils.d(TAG, "SFTP会话连接成功:" + host + ":" + port);
|
||||
|
||||
// 5. 打开SFTP通道(类型:sftp,原生接口强转)
|
||||
mSftpChannel = (ChannelSftp) mSession.openChannel("sftp");
|
||||
mSftpChannel.connect();
|
||||
|
||||
// 6. 设置文件名编码(解决中文乱码,ChannelSftp原生接口)
|
||||
String charset = isParamEmpty(ftpAuthModel.getFtpCharset()) ? "UTF-8" : ftpAuthModel.getFtpCharset();
|
||||
mSftpChannel.setFilenameEncoding(charset);
|
||||
LogUtils.d(TAG, "SFTP文件名编码设置成功:" + charset);
|
||||
|
||||
LogUtils.i(TAG, "SFTP登录成功,服务器:" + host + ":" + port + ",用户名:" + username);
|
||||
return true;
|
||||
|
||||
} catch (JSchException e) {
|
||||
LogUtils.e(TAG, "SFTP登录JSch异常:" + e.getMessage(), e);
|
||||
logout();
|
||||
return false;
|
||||
} catch (SftpException e) {
|
||||
// 匹配SftpException原生属性和方法
|
||||
LogUtils.e(TAG, "SFTP通道初始化异常:id=" + e.id + ",msg=" + e.getMessage() + ",detail=" + e.toString());
|
||||
logout();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 【已废弃】原FTP多参数登录方法,适配JSch后保留,推荐使用login(FTPAuthModel)
|
||||
* @deprecated 请使用基于FTPAuthModel的登录方法
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean login(String host, int port, String username, String password) {
|
||||
SFTPAuthModel ftpAuthModel = new SFTPAuthModel();
|
||||
ftpAuthModel.setFtpServer(host);
|
||||
ftpAuthModel.setFtpPort(port <= 0 ? DEFAULT_SFTP_PORT : port);
|
||||
ftpAuthModel.setFtpUsername(username);
|
||||
ftpAuthModel.setFtpPassword(password);
|
||||
return login(ftpAuthModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* SFTP登出并断开连接,释放所有资源(严格调用原生disconnect接口)
|
||||
* @return 登出成功返回true,失败false
|
||||
*/
|
||||
public boolean logout() {
|
||||
boolean isSuccess = true;
|
||||
// 关闭SFTP通道(原生接口disconnect,非空判断即可)
|
||||
if (mSftpChannel != null) {
|
||||
try {
|
||||
mSftpChannel.disconnect();
|
||||
LogUtils.d(TAG, "SFTP通道已断开");
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "关闭SFTP通道异常:" + e.getMessage(), e);
|
||||
isSuccess = false;
|
||||
}
|
||||
}
|
||||
// 关闭JSch会话(原生接口disconnect,非空判断即可)
|
||||
if (mSession != null) {
|
||||
try {
|
||||
mSession.disconnect();
|
||||
LogUtils.d(TAG, "SFTP会话已断开");
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "关闭SFTP会话异常:" + e.getMessage(), e);
|
||||
isSuccess = false;
|
||||
}
|
||||
}
|
||||
// 重置客户端,避免资源残留
|
||||
initSftpClient();
|
||||
if (isSuccess) {
|
||||
LogUtils.i(TAG, "SFTP登出成功");
|
||||
} else {
|
||||
LogUtils.w(TAG, "SFTP登出失败:部分资源未正常释放");
|
||||
}
|
||||
return isSuccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* 强制断开连接(兜底资源释放),同logout方法
|
||||
*/
|
||||
public void disconnect() {
|
||||
logout();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断SFTP是否已连接(会话+通道均调用原生isConnected接口)
|
||||
* @return 已连接返回true,否则false
|
||||
*/
|
||||
public boolean isConnected() {
|
||||
return mSession != null && mSession.isConnected()
|
||||
&& mSftpChannel != null && mSftpChannel.isConnected();
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件到SFTP指定路径(覆盖式上传,调用ChannelSftp原生put接口,OVERWRITE模式)
|
||||
* @param localFilePath 本地文件绝对路径(如/sdcard/test.apk)
|
||||
* @param remoteFilePath SFTP服务器目标路径(如/ftp/apk/test.apk,需包含文件名)
|
||||
* @return 上传成功返回true,失败false
|
||||
*/
|
||||
public boolean uploadFile(String localFilePath, String remoteFilePath) {
|
||||
// 前置校验
|
||||
if (!isConnected()) {
|
||||
LogUtils.e(TAG, "文件上传失败:SFTP未连接服务器");
|
||||
return false;
|
||||
}
|
||||
if (isParamEmpty(localFilePath) || isParamEmpty(remoteFilePath)) {
|
||||
LogUtils.e(TAG, "文件上传失败:本地/远程路径不能为空");
|
||||
return false;
|
||||
}
|
||||
File localFile = new File(localFilePath);
|
||||
if (!localFile.exists() || !localFile.isFile()) {
|
||||
LogUtils.e(TAG, "文件上传失败:本地文件不存在/非文件,路径:" + localFilePath);
|
||||
return false;
|
||||
}
|
||||
|
||||
InputStream fis = null;
|
||||
try {
|
||||
// 自动创建远程多级目录(基于原生mkdir/stat接口)
|
||||
createRemoteDir(remoteFilePath);
|
||||
// 读取本地文件,上传到SFTP(原生put接口,OVERWRITE覆盖模式)
|
||||
fis = new FileInputStream(localFile);
|
||||
mSftpChannel.put(fis, remoteFilePath, ChannelSftp.OVERWRITE);
|
||||
LogUtils.i(TAG, "文件上传成功:本地" + localFilePath + " → 远程" + remoteFilePath);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
LogUtils.e(TAG, "文件上传IO异常:" + e.getMessage(), e);
|
||||
return false;
|
||||
} catch (SftpException e) {
|
||||
// 严格匹配SftpException原生属性:id、getMessage()、toString()
|
||||
LogUtils.e(TAG, "文件上传SFTP异常:id=" + e.id + ",msg=" + e.getMessage() + ",detail=" + e.toString());
|
||||
return false;
|
||||
} finally {
|
||||
// 关闭流资源,避免内存泄漏
|
||||
closeStream(fis, null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从SFTP下载文件到本地指定路径(覆盖式下载,调用ChannelSftp原生get接口)
|
||||
* @param remoteFilePath SFTP服务器文件路径(如/ftp/apk/test.apk)
|
||||
* @param localFilePath 本地目标路径(如/sdcard/test.apk,需包含文件名)
|
||||
* @return 下载成功返回true,失败false
|
||||
*/
|
||||
public boolean downloadFile(String remoteFilePath, String localFilePath) {
|
||||
// 前置校验
|
||||
if (!isConnected()) {
|
||||
LogUtils.e(TAG, "文件下载失败:SFTP未连接服务器");
|
||||
return false;
|
||||
}
|
||||
if (isParamEmpty(remoteFilePath) || isParamEmpty(localFilePath)) {
|
||||
LogUtils.e(TAG, "文件下载失败:远程/本地路径不能为空");
|
||||
return false;
|
||||
}
|
||||
// 校验远程文件是否存在(基于ChannelSftp原生stat接口)
|
||||
if (!isFileExists(remoteFilePath)) {
|
||||
LogUtils.e(TAG, "文件下载失败:远程文件不存在,路径:" + remoteFilePath);
|
||||
return false;
|
||||
}
|
||||
|
||||
OutputStream fos = null;
|
||||
try {
|
||||
// 创建本地多级目录
|
||||
File localFile = new File(localFilePath);
|
||||
File parentDir = localFile.getParentFile();
|
||||
if (!parentDir.exists() && !parentDir.mkdirs()) {
|
||||
LogUtils.e(TAG, "文件下载失败:创建本地目录失败,路径:" + parentDir.getAbsolutePath());
|
||||
return false;
|
||||
}
|
||||
// 从SFTP读取文件,写入本地(原生get接口)
|
||||
fos = new FileOutputStream(localFile);
|
||||
mSftpChannel.get(remoteFilePath, fos);
|
||||
LogUtils.i(TAG, "文件下载成功:远程" + remoteFilePath + " → 本地" + localFilePath);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
LogUtils.e(TAG, "文件下载IO异常:" + e.getMessage(), e);
|
||||
// 删除未下载完成的本地文件
|
||||
new File(localFilePath).delete();
|
||||
return false;
|
||||
} catch (SftpException e) {
|
||||
// 严格匹配SftpException原生属性:id、getMessage()、toString()
|
||||
LogUtils.e(TAG, "文件下载SFTP异常:id=" + e.id + ",msg=" + e.getMessage() + ",detail=" + e.toString());
|
||||
// 删除未下载完成的本地文件
|
||||
new File(localFilePath).delete();
|
||||
return false;
|
||||
} finally {
|
||||
// 关闭流资源,避免内存泄漏
|
||||
closeStream(null, fos);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 列举SFTP指定文件夹下的所有文件/文件夹(返回ChannelSftp原生Vector,过滤.和..)
|
||||
* @param remoteDir SFTP服务器目录路径(如/ftp/apk/,结尾带/或不带均可)
|
||||
* @return 成功返回原生Vector<ChannelSftp.LsEntry>,失败返回空Vector
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Vector listDir(String remoteDir) {
|
||||
Vector fileList = new Vector();
|
||||
// 前置校验
|
||||
if (!isConnected()) {
|
||||
LogUtils.e(TAG, "列举目录失败:SFTP未连接服务器");
|
||||
return fileList;
|
||||
}
|
||||
if (isParamEmpty(remoteDir)) {
|
||||
LogUtils.e(TAG, "列举目录失败:远程目录路径不能为空");
|
||||
return fileList;
|
||||
}
|
||||
// 校验目录是否存在(基于ChannelSftp原生stat接口)
|
||||
if (!isDirExists(remoteDir)) {
|
||||
LogUtils.e(TAG, "列举目录失败:远程目录不存在,路径:" + remoteDir);
|
||||
return fileList;
|
||||
}
|
||||
|
||||
try {
|
||||
// 列举目录下所有文件/文件夹(调用ChannelSftp原生ls接口,返回原生Vector)
|
||||
Vector vector = mSftpChannel.ls(remoteDir);
|
||||
if (vector != null && vector.size() > 0) {
|
||||
for (Object obj : vector) {
|
||||
// 过滤.和..上级目录,仅保留有效文件/目录
|
||||
ChannelSftp.LsEntry entry = (ChannelSftp.LsEntry) obj;
|
||||
String fileName = entry.getFilename();
|
||||
if (!".".equals(fileName) && !"..".equals(fileName)) {
|
||||
fileList.add(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
LogUtils.i(TAG, "列举目录成功:" + remoteDir + ",共" + fileList.size() + "个文件/文件夹");
|
||||
} catch (SftpException e) {
|
||||
// 严格匹配SftpException原生属性:id、getMessage()、toString()
|
||||
LogUtils.e(TAG, "列举目录SFTP异常:id=" + e.id + ",msg=" + e.getMessage() + ",detail=" + e.toString());
|
||||
}
|
||||
return fileList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断SFTP服务器上**文件**是否存在(基于ChannelSftp原生stat接口,匹配SftpException原生异常)
|
||||
* @param remoteFilePath SFTP服务器文件路径(如/ftp/apk/test.apk)
|
||||
* @return 存在且为文件返回true,否则false
|
||||
*/
|
||||
public boolean isFileExists(String remoteFilePath) {
|
||||
// 前置校验
|
||||
if (!isConnected()) {
|
||||
LogUtils.e(TAG, "判断文件存在性失败:SFTP未连接服务器");
|
||||
return false;
|
||||
}
|
||||
if (isParamEmpty(remoteFilePath)) {
|
||||
LogUtils.e(TAG, "判断文件存在性失败:远程文件路径不能为空");
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
// 调用ChannelSftp原生stat接口获取属性,不存在会抛出SSH_FX_NO_SUCH_FILE异常
|
||||
SftpATTRS attrs = mSftpChannel.stat(remoteFilePath);
|
||||
// 原生isReg()判断是否为文件
|
||||
return attrs.isReg();
|
||||
} catch (SftpException e) {
|
||||
// 仅匹配原生异常码SSH_FX_NO_SUCH_FILE(2):文件/目录不存在,不记错误日志
|
||||
if (e.id != ChannelSftp.SSH_FX_NO_SUCH_FILE) {
|
||||
LogUtils.e(TAG, "判断文件存在性SFTP异常:id=" + e.id + ",msg=" + e.getMessage() + ",detail=" + e.toString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断SFTP服务器上**文件夹**是否存在(基于ChannelSftp原生stat接口,匹配SftpException原生异常)
|
||||
* @param remoteDir SFTP服务器目录路径(如/ftp/apk/,结尾带/或不带均可)
|
||||
* @return 存在且为目录返回true,否则false
|
||||
*/
|
||||
public boolean isDirExists(String remoteDir) {
|
||||
// 前置校验
|
||||
if (!isConnected()) {
|
||||
LogUtils.e(TAG, "判断目录存在性失败:SFTP未连接服务器");
|
||||
return false;
|
||||
}
|
||||
if (isParamEmpty(remoteDir)) {
|
||||
LogUtils.e(TAG, "判断目录存在性失败:远程目录路径不能为空");
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
// 调用ChannelSftp原生stat接口获取属性,不存在会抛出SSH_FX_NO_SUCH_FILE异常
|
||||
SftpATTRS attrs = mSftpChannel.stat(remoteDir);
|
||||
// 原生isDir()判断是否为目录
|
||||
return attrs.isDir();
|
||||
} catch (SftpException e) {
|
||||
// 仅匹配原生异常码SSH_FX_NO_SUCH_FILE(2):文件/目录不存在,不记错误日志
|
||||
if (e.id != ChannelSftp.SSH_FX_NO_SUCH_FILE) {
|
||||
LogUtils.e(TAG, "判断目录存在性SFTP异常:id=" + e.id + ",msg=" + e.getMessage() + ",detail=" + e.toString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// ===================================== 内部工具方法(仅调用原生接口) =====================================
|
||||
/**
|
||||
* 递归创建SFTP远程多级目录(基于ChannelSftp原生mkdir/stat接口,不存在则创建)
|
||||
* @param remoteFilePath SFTP远程文件路径/目录路径
|
||||
*/
|
||||
private void createRemoteDir(String remoteFilePath) {
|
||||
if (!isConnected()) {
|
||||
LogUtils.e(TAG, "创建远程目录失败:SFTP未连接服务器");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// 提取目录路径(文件路径→目录路径,目录路径直接使用)
|
||||
String remoteDir = remoteFilePath.lastIndexOf("/") > 0
|
||||
? remoteFilePath.substring(0, remoteFilePath.lastIndexOf("/"))
|
||||
: remoteFilePath;
|
||||
// 按/分割多级目录,递归创建(避免多级目录不存在)
|
||||
String[] dirs = remoteDir.split("/");
|
||||
StringBuilder currentDir = new StringBuilder();
|
||||
for (String dir : dirs) {
|
||||
if (isParamEmpty(dir)) {
|
||||
continue;
|
||||
}
|
||||
currentDir.append("/").append(dir);
|
||||
String dirPath = currentDir.toString();
|
||||
// 目录不存在则调用ChannelSftp原生mkdir创建
|
||||
if (!isDirExists(dirPath)) {
|
||||
mSftpChannel.mkdir(dirPath);
|
||||
LogUtils.d(TAG, "创建SFTP远程目录成功:" + dirPath);
|
||||
}
|
||||
}
|
||||
} catch (SftpException e) {
|
||||
// 严格匹配SftpException原生属性:id、getMessage()、toString()
|
||||
LogUtils.e(TAG, "创建远程目录SFTP异常:id=" + e.id + ",msg=" + e.getMessage() + ",detail=" + e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭流资源(通用工具方法,Java7原生IO,避免内存泄漏)
|
||||
* @param is 输入流(可为null)
|
||||
* @param os 输出流(可为null)
|
||||
*/
|
||||
private void closeStream(InputStream is, OutputStream os) {
|
||||
if (is != null) {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
LogUtils.e(TAG, "关闭输入流异常:" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
if (os != null) {
|
||||
try {
|
||||
os.close();
|
||||
} catch (IOException e) {
|
||||
LogUtils.e(TAG, "关闭输出流异常:" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断参数是否为空(null/空字符串/全空格,Java7原生字符串操作)
|
||||
* @param param 待判断参数
|
||||
* @return 为空返回true,否则false
|
||||
*/
|
||||
private boolean isParamEmpty(String param) {
|
||||
return param == null || param.trim().isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package cc.winboll.studio.libappbase.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.Signature;
|
||||
import android.util.Base64;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
/**
|
||||
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2026/01/20 19:50
|
||||
* @Describe 获取应用签名指纹(SHA1+Base64,直接复制用)
|
||||
*/
|
||||
public class SignGetUtils {
|
||||
private static final String TAG = "SignGetUtils";
|
||||
|
||||
/**
|
||||
* 一键获取当前应用签名指纹(直接调用,看日志复制结果)
|
||||
*/
|
||||
public static void getCurrentAppSign(Context context) {
|
||||
if (context == null) {
|
||||
LogUtils.e(TAG, "context不能为空");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
PackageInfo pkgInfo = pm.getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES);
|
||||
Signature[] signatures = pkgInfo.signatures;
|
||||
if (signatures == null || signatures.length == 0) {
|
||||
LogUtils.e(TAG, "未获取到应用签名");
|
||||
return;
|
||||
}
|
||||
// 和APPUtils校验格式完全一致(SHA1+Base64 NO_WRAP)
|
||||
MessageDigest md = MessageDigest.getInstance("SHA1");
|
||||
md.update(signatures[0].toByteArray());
|
||||
String signBase64 = Base64.encodeToString(md.digest(), Base64.NO_WRAP);
|
||||
|
||||
// 关键日志:复制【】里的内容到APPUtils的TARGET_SIGN_FINGERPRINT
|
||||
LogUtils.d(TAG, "当前应用包名:" + context.getPackageName());
|
||||
LogUtils.d(TAG, "当前应用签名指纹(直接复制):【" + signBase64 + "】");
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
LogUtils.e(TAG, "获取签名失败:包名不存在", e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
LogUtils.e(TAG, "获取签名失败:不支持SHA1", e);
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "获取签名失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
// 新增:直接返回签名字符串,供对话框调用
|
||||
// public static String getSignStr(Context context) {
|
||||
// if (context == null) return null;
|
||||
// try {
|
||||
// PackageManager pm = context.getPackageManager();
|
||||
// PackageInfo pkgInfo = pm.getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES);
|
||||
// Signature[] signatures = pkgInfo.signatures;
|
||||
// if (signatures == null || signatures.length == 0) return null;
|
||||
//
|
||||
// MessageDigest md = MessageDigest.getInstance("SHA1");
|
||||
// md.update(signatures[0].toByteArray());
|
||||
// return Base64.encodeToString(md.digest(), Base64.NO_WRAP);
|
||||
// } catch (Exception e) {
|
||||
// LogUtils.e(TAG, "获取签名字符串失败", e);
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.util.AttributeSet;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
@@ -16,163 +17,204 @@ import cc.winboll.studio.libappbase.GlobalApplication;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.R;
|
||||
import cc.winboll.studio.libappbase.ToastUtils;
|
||||
import cc.winboll.studio.libappbase.dialogs.DebugHostDialog;
|
||||
import cc.winboll.studio.libappbase.dialogs.APPValidationDialog;
|
||||
import cc.winboll.studio.libappbase.models.APPInfo;
|
||||
|
||||
/**
|
||||
* @Describe AboutView 原生实现关于页面,无第三方依赖,适配API30,抽象通用功能控件(邮件/网页跳转)
|
||||
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2026/01/11 12:23:00
|
||||
* @LastEditTime 2026/01/12 01:05:30
|
||||
* @CreateTime 2026-01-11 12:23:00
|
||||
* @LastEditTime 2026-01-24 20:50:00
|
||||
* @Describe AboutView 原生实现关于页面,无第三方依赖,适配API30;抽象通用功能控件(邮件/网页跳转),支持调试工具入口动态显隐,集成应用正版校验、调试地址配置弹窗
|
||||
*/
|
||||
public class AboutView extends LinearLayout {
|
||||
// 全局常量区(标识、回调标识)
|
||||
// ===================================== 全局常量 =====================================
|
||||
public static final String TAG = "AboutView";
|
||||
public static final int MSG_APPUPDATE_CHECKED = 0;
|
||||
|
||||
// 固定链接常量
|
||||
// 固定链接/邮件常量
|
||||
private static final String WINBOLL_OFFICIAL_HOME = "https://www.winboll.cc";
|
||||
// 邮件相关常量(统一封装,便于维护)
|
||||
private static final String EMAIL_TITLE = "联系WinBoLLStudio";
|
||||
private static final String EMAIL_ADDRESS = "studio@winboll.cc";
|
||||
private static final String EMAIL_TYPE = "message/rfc822";
|
||||
|
||||
// 布局尺寸常量(统一管理,适配多屏幕,dp为基准单位)
|
||||
// 布局尺寸常量(dp)
|
||||
private static final int PADDING_LARGE = 32;
|
||||
private static final int PADDING_MID = 16;
|
||||
private static final int PADDING_SMALL = 8;
|
||||
private static final int ICON_SIZE = 48;
|
||||
private static final int LINE_HEIGHT = 1;
|
||||
private static final int ITEM_ICON_SIZE = 24;
|
||||
|
||||
// 成员属性区(按 核心依赖→业务配置→视图相关 归类排序,注释清晰)
|
||||
private Context mContext; // 上下文对象,全局复用
|
||||
private APPInfo mAPPInfo; // 应用核心信息实体
|
||||
private OnRequestDevUserInfoAutofillListener mOnRequestDevUserInfoAutofillListener; // 调试信息填充监听
|
||||
// 服务器默认地址常量
|
||||
private static final String SERVER_DEBUG_HOST = "https://yun-preivew.winboll.cc";
|
||||
private static final String SERVER_RELEASE_HOST = "https://yun.winboll.cc";
|
||||
|
||||
private String mszAppName = ""; // 应用名称
|
||||
private String mszAppVersionName = ""; // 应用版本号
|
||||
private String mszAppDescription = ""; // 应用描述文案
|
||||
private String mszHomePage = ""; // 应用主页/APK下载地址
|
||||
private String mszGitea = ""; // 应用Git源码地址
|
||||
private String mszAppGitName = ""; // 应用Git仓库名称
|
||||
private String mszAppAPKName = ""; // 应用APK基础名称
|
||||
private String mszAppAPKFolderName = ""; // 应用APK存储文件夹
|
||||
private String mszCurrentAppPackageName = "";// 当前APK完整文件名
|
||||
private String mszReleaseAPKName = ""; // 正式版APK完整文件名
|
||||
private volatile String mszNewestAppPackageName = ""; // 最新版APK文件名(支持异步更新)
|
||||
private String mszWinBoLLServerHost = ""; // 服务器地址
|
||||
private int mnAppIcon = 0; // 应用图标资源ID
|
||||
private boolean mIsAddDebugTools = false; // 是否启用调试工具标识
|
||||
private EditText metDevUserName; // 调试用户名输入框
|
||||
private EditText metDevUserPassword; // 调试密码输入框
|
||||
// ===================================== 核心成员属性 =====================================
|
||||
// 上下文与业务实体
|
||||
private Context mContext;
|
||||
private APPInfo mAPPInfo;
|
||||
private OnRequestDevUserInfoAutofillListener mOnRequestDevUserInfoAutofillListener;
|
||||
|
||||
// 构造方法区(按 参数从少到多 排序,适配 代码创建+XML引用 场景)
|
||||
// 应用基础信息
|
||||
private String mszAppName = "";
|
||||
private String mszAppVersionName = "";
|
||||
private String mszAppDescription = "";
|
||||
private String mszHomePage = "";
|
||||
private String mszGitea = "";
|
||||
private String mszAppGitName = "";
|
||||
private String mszAppAPKName = "";
|
||||
private String mszAppAPKFolderName = "";
|
||||
private String mszCurrentAppPackageName = "";
|
||||
private String mszReleaseAPKName = "";
|
||||
private volatile String mszNewestAppPackageName = "";
|
||||
private String mszWinBoLLServerHost = "";
|
||||
private int mnAppIcon = 0;
|
||||
private boolean mIsAddDebugTools = false;
|
||||
|
||||
// 调试视图
|
||||
private EditText metDevUserName;
|
||||
private EditText metDevUserPassword;
|
||||
|
||||
// ===================================== 页面视图控件 =====================================
|
||||
private DebugSwitchImageView ivAppIcon;
|
||||
private TextView tvAppNameVersion;
|
||||
private TextView tvAppDesc;
|
||||
private LinearLayout llFunctionContainer;
|
||||
private ImageButton ibSebugStepOver;
|
||||
private ImageButton ibSigngetDialog;
|
||||
private ImageButton ibWinBoLLHostDialog;
|
||||
|
||||
// ===================================== 构造方法(按参数从少到多排序) =====================================
|
||||
public AboutView(Context context) {
|
||||
super(context);
|
||||
LogUtils.d(TAG, "AboutView(Context) 构造方法调用,代码创建视图场景");
|
||||
LogUtils.d(TAG, "AboutView(Context):代码创建视图,执行默认初始化");
|
||||
this.mContext = context;
|
||||
initDefaultParams();
|
||||
initViewFromXml();
|
||||
}
|
||||
|
||||
public AboutView(Context context, APPInfo appInfo) {
|
||||
super(context);
|
||||
LogUtils.d(TAG, "AboutView(Context,APPInfo) 构造调用,入参APPInfo:" + (appInfo == null ? "null" : appInfo.getAppName()));
|
||||
this.mContext = context;
|
||||
this.mAPPInfo = appInfo;
|
||||
initAll();
|
||||
}
|
||||
// public AboutView(Context context, APPInfo appInfo) {
|
||||
// super(context);
|
||||
// LogUtils.d(TAG, "AboutView(Context,APPInfo):传入应用信息,appName=" + (appInfo == null ? "null" : appInfo.getAppName()));
|
||||
// this.mContext = context;
|
||||
// this.mAPPInfo = appInfo;
|
||||
// initViewFromXml();
|
||||
// initAll();
|
||||
// }
|
||||
|
||||
public AboutView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
LogUtils.d(TAG, "AboutView(Context,AttributeSet) 构造调用,XML布局引用场景");
|
||||
LogUtils.d(TAG, "AboutView(Context,AttributeSet):XML布局引用,执行默认初始化");
|
||||
this.mContext = context;
|
||||
initDefaultParams();
|
||||
initViewFromXml();
|
||||
}
|
||||
|
||||
public AboutView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
LogUtils.d(TAG, "AboutView(Context,AttributeSet,int) 构造调用,XML布局+样式配置,defStyleAttr:" + defStyleAttr);
|
||||
LogUtils.d(TAG, "AboutView(Context,AttributeSet,int):XML布局+样式配置,defStyleAttr=" + defStyleAttr);
|
||||
this.mContext = context;
|
||||
initDefaultParams();
|
||||
initViewFromXml();
|
||||
}
|
||||
|
||||
// 对外公开方法区(供外部调用,职责单一,注释明确)
|
||||
// ===================================== 对外公开方法 =====================================
|
||||
/**
|
||||
* 一站式初始化所有关于页逻辑,包含参数、信息、视图全流程初始化
|
||||
* 一站式初始化所有关于页逻辑,包含参数、应用信息、页面视图全流程
|
||||
*/
|
||||
public void initAll() {
|
||||
LogUtils.d(TAG, "initAll() 一站式初始化调用,APPInfo是否为空:" + (mAPPInfo == null));
|
||||
LogUtils.d(TAG, "initAll():开始一站式初始化,APPInfo是否为空=" + (mAPPInfo == null));
|
||||
if (mAPPInfo == null) {
|
||||
LogUtils.w(TAG, "initAll() 初始化终止:APPInfo 为 null,无法获取应用核心信息");
|
||||
LogUtils.w(TAG, "initAll():初始化终止,APPInfo为null");
|
||||
return;
|
||||
}
|
||||
// 基础布局配置
|
||||
setOrientation(VERTICAL);
|
||||
setPadding(dp2px(PADDING_MID), dp2px(PADDING_LARGE), dp2px(PADDING_MID), dp2px(PADDING_LARGE));
|
||||
setGravity(Gravity.CENTER_HORIZONTAL);
|
||||
|
||||
// 按初始化流程执行,有序无冗余
|
||||
initDefaultParams();
|
||||
initAppBaseInfo();
|
||||
initAppVersionInfo();
|
||||
initAPPBaseInfo();
|
||||
initAPPVersionInfo();
|
||||
initServerConfig();
|
||||
initAppLinkInfo();
|
||||
initAPPLinkInfo();
|
||||
initReleaseAPKInfo();
|
||||
initAboutPageView();
|
||||
LogUtils.d(TAG, "initAll() 所有初始化流程执行完成");
|
||||
LogUtils.d(TAG, "initAll():所有初始化流程执行完成");
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置应用信息并重新初始化关于页,支持动态更新页面内容
|
||||
* 重置应用信息并重新初始化页面,支持动态更新关于页内容
|
||||
* @param appInfo 新的应用信息实体
|
||||
*/
|
||||
public void setAPPInfoAndInit(APPInfo appInfo) {
|
||||
LogUtils.d(TAG, "setAPPInfoAndInit() 调用,传入新APPInfo:" + (appInfo == null ? "null" : appInfo.getAppName()));
|
||||
this.mAPPInfo = appInfo;
|
||||
removeAllViews();
|
||||
initAll();
|
||||
LogUtils.d(TAG, "setAPPInfoAndInit() 应用信息重置+页面重构完成");
|
||||
}
|
||||
// public void setAPPInfoAndInit(APPInfo appInfo) {
|
||||
// LogUtils.d(TAG, "setAPPInfoAndInit():重置应用信息,appName=" + (appInfo == null ? "null" : appInfo.getAppName()));
|
||||
// this.mAPPInfo = appInfo;
|
||||
// if (llFunctionContainer != null) llFunctionContainer.removeAllViews();
|
||||
// initAll();
|
||||
// LogUtils.d(TAG, "setAPPInfoAndInit():应用信息重置+页面重构完成");
|
||||
// }
|
||||
|
||||
/**
|
||||
* 设置应用信息(兼容旧调用逻辑),设置后自动重构页面
|
||||
* 设置应用信息,兼容旧调用逻辑,设置后自动重构页面
|
||||
* @param appInfo 应用核心信息实体
|
||||
*/
|
||||
public void setAPPInfo(APPInfo appInfo) {
|
||||
LogUtils.d(TAG, "setAPPInfo() 调用,传入APPInfo:" + (appInfo == null ? "null" : appInfo.getAppName()));
|
||||
LogUtils.d(TAG, "setAPPInfo():设置应用信息,appName=" + (appInfo == null ? "null" : appInfo.getAppName()));
|
||||
this.mAPPInfo = appInfo;
|
||||
removeAllViews();
|
||||
if (llFunctionContainer != null) llFunctionContainer.removeAllViews();
|
||||
initAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置调试信息自动填充监听,用于调试场景的信息回调
|
||||
* 设置调试信息自动填充监听,供调试场景回调使用
|
||||
* @param l 监听回调接口实现
|
||||
*/
|
||||
public void setOnRequestDevUserInfoAutofillListener(OnRequestDevUserInfoAutofillListener l) {
|
||||
LogUtils.d(TAG, "setOnRequestDevUserInfoAutofillListener() 调试监听设置完成");
|
||||
LogUtils.d(TAG, "setOnRequestDevUserInfoAutofillListener():设置调试信息填充监听完成");
|
||||
this.mOnRequestDevUserInfoAutofillListener = l;
|
||||
}
|
||||
|
||||
// 内部初始化方法区(按 基础→业务→视图 流程排序,单一职责)
|
||||
// ===================================== 内部初始化方法 =====================================
|
||||
/**
|
||||
* 初始化默认兜底参数,防止空指针,为后续初始化做基础铺垫
|
||||
*/
|
||||
private void initDefaultParams() {
|
||||
LogUtils.d(TAG, "initDefaultParams() 执行默认参数初始化");
|
||||
mszWinBoLLServerHost = GlobalApplication.isDebugging() ? "https://yun-preivew.winboll.cc" : "https://yun.winboll.cc";
|
||||
mnAppIcon = mnAppIcon == 0 ? R.drawable.ic_winboll : mnAppIcon;
|
||||
LogUtils.d(TAG, "initDefaultParams():开始初始化默认参数");
|
||||
mszWinBoLLServerHost = GlobalApplication.isDebugging() ? SERVER_DEBUG_HOST : SERVER_RELEASE_HOST;
|
||||
mnAppIcon = (mnAppIcon == 0) ? R.drawable.ic_winboll : mnAppIcon;
|
||||
mIsAddDebugTools = false;
|
||||
LogUtils.d(TAG, "initDefaultParams() 完成,默认服务器地址:" + mszWinBoLLServerHost + ",默认图标ID:" + mnAppIcon);
|
||||
LogUtils.d(TAG, "initDefaultParams():默认参数初始化完成,服务器地址=" + mszWinBoLLServerHost + ",应用图标ID=" + mnAppIcon);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载XML布局并绑定所有视图控件,初始化按钮点击事件
|
||||
*/
|
||||
private void initViewFromXml() {
|
||||
LogUtils.d(TAG, "initViewFromXml():开始加载布局并绑定控件");
|
||||
View.inflate(mContext, R.layout.layout_about_view, this);
|
||||
// 基础控件绑定
|
||||
ivAppIcon = findViewById(R.id.iv_app_icon);
|
||||
tvAppNameVersion = findViewById(R.id.tv_app_name_version);
|
||||
tvAppDesc = findViewById(R.id.tv_app_desc);
|
||||
llFunctionContainer = findViewById(R.id.ll_function_container);
|
||||
// 功能按钮绑定
|
||||
ibSebugStepOver = findViewById(R.id.ib_debug_step_over);
|
||||
ibSigngetDialog = findViewById(R.id.ib_signgetdialog);
|
||||
ibWinBoLLHostDialog = findViewById(R.id.ib_winbollhostdialog);
|
||||
|
||||
// 调试按钮统一只在调试模式显示
|
||||
ibWinBoLLHostDialog.setVisibility(GlobalApplication.isDebugging() ? View.VISIBLE : View.GONE);
|
||||
//ibSigngetDialog.setVisibility(GlobalApplication.isDebugging() ? View.VISIBLE : View.GONE);
|
||||
ibSebugStepOver.setVisibility(GlobalApplication.isDebugging() ? View.VISIBLE : View.GONE);
|
||||
|
||||
// 绑定按钮点击事件
|
||||
setBtnClickListener();
|
||||
LogUtils.d(TAG, "initViewFromXml():布局加载+控件绑定+事件初始化完成");
|
||||
}
|
||||
|
||||
/**
|
||||
* 从APPInfo实体读取应用基础核心配置,赋值到本地属性
|
||||
*/
|
||||
private void initAppBaseInfo() {
|
||||
LogUtils.d(TAG, "initAppBaseInfo() 读取APPInfo基础配置");
|
||||
private void initAPPBaseInfo() {
|
||||
LogUtils.d(TAG, "initAPPBaseInfo():开始读取APPInfo基础配置");
|
||||
if (mAPPInfo == null) {
|
||||
LogUtils.w(TAG, "initAppBaseInfo() 跳过执行:APPInfo 为 null");
|
||||
LogUtils.w(TAG, "initAPPBaseInfo():跳过执行,APPInfo为null");
|
||||
return;
|
||||
}
|
||||
mszAppName = mAPPInfo.getAppName() == null ? "" : mAPPInfo.getAppName();
|
||||
@@ -180,44 +222,44 @@ public class AboutView extends LinearLayout {
|
||||
mszAppAPKName = mAPPInfo.getAppAPKName() == null ? "" : mAPPInfo.getAppAPKName();
|
||||
mszAppGitName = mAPPInfo.getAppGitName() == null ? "" : mAPPInfo.getAppGitName();
|
||||
mszAppDescription = mAPPInfo.getAppDescription() == null ? "" : mAPPInfo.getAppDescription();
|
||||
mnAppIcon = mAPPInfo.getAppIcon() != 0 ? mAPPInfo.getAppIcon() : mnAppIcon;
|
||||
mnAppIcon = (mAPPInfo.getAppIcon() != 0) ? mAPPInfo.getAppIcon() : mnAppIcon;
|
||||
mIsAddDebugTools = mAPPInfo.isAddDebugTools();
|
||||
LogUtils.d(TAG, "initAppBaseInfo() 读取完成,应用名:" + mszAppName + ",调试开关:" + mIsAddDebugTools);
|
||||
LogUtils.d(TAG, "initAPPBaseInfo():基础配置读取完成,应用名=" + mszAppName + ",调试开关=" + mIsAddDebugTools);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化应用版本信息,从包管理中获取当前应用版本号
|
||||
* 从包管理中获取当前应用版本号,初始化版本相关信息
|
||||
*/
|
||||
private void initAppVersionInfo() {
|
||||
LogUtils.d(TAG, "initAppVersionInfo() 初始化应用版本信息");
|
||||
private void initAPPVersionInfo() {
|
||||
LogUtils.d(TAG, "initAPPVersionInfo():开始初始化应用版本信息");
|
||||
try {
|
||||
mszAppVersionName = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0).versionName;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
LogUtils.d(TAG, "initAppVersionInfo() 获取版本号失败,默认赋值unknown", e);
|
||||
LogUtils.e(TAG, "initAPPVersionInfo():获取版本号失败,默认赋值unknown", e);
|
||||
mszAppVersionName = "unknown";
|
||||
}
|
||||
mszCurrentAppPackageName = String.format("%s_%s.apk", mszAppAPKName, mszAppVersionName);
|
||||
LogUtils.d(TAG, "initAppVersionInfo() 完成,版本号:" + mszAppVersionName + ",当前APK名:" + mszCurrentAppPackageName);
|
||||
mszCurrentAppPackageName = String.format("%s_%s.apk", mszAppVersionName, mszAppVersionName);
|
||||
LogUtils.d(TAG, "initAPPVersionInfo():版本信息初始化完成,版本号=" + mszAppVersionName + ",当前APK名=" + mszCurrentAppPackageName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化服务器相关配置,预留扩展接口
|
||||
*/
|
||||
private void initServerConfig() {
|
||||
LogUtils.d(TAG, "initServerConfig() 服务器配置初始化(预留扩展)");
|
||||
LogUtils.d(TAG, "initServerConfig():服务器配置初始化,预留扩展接口");
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化应用相关链接(主页+Git源码地址),动态拼接Git地址
|
||||
* 初始化应用相关链接(主页+Git源码地址),根据分支配置动态拼接Git地址
|
||||
*/
|
||||
private void initAppLinkInfo() {
|
||||
LogUtils.d(TAG, "initAppLinkInfo() 初始化应用链接信息");
|
||||
private void initAPPLinkInfo() {
|
||||
LogUtils.d(TAG, "initAPPLinkInfo():开始初始化应用链接信息");
|
||||
if (mAPPInfo == null) {
|
||||
LogUtils.w(TAG, "initAppLinkInfo() 跳过执行:APPInfo 为 null");
|
||||
LogUtils.w(TAG, "initAPPLinkInfo():跳过执行,APPInfo为null");
|
||||
return;
|
||||
}
|
||||
mszHomePage = mAPPInfo.getAppHomePage() == null ? "" : mAPPInfo.getAppHomePage();
|
||||
// 分场景拼接Git地址,兼容无分支配置场景
|
||||
// 拼接Git地址,兼容无分支配置场景
|
||||
if (mAPPInfo.getAppGitAPPBranch() == null || mAPPInfo.getAppGitAPPBranch().trim().isEmpty()) {
|
||||
mszGitea = String.format("https://gitea.winboll.cc/%s/%s", mAPPInfo.getAppGitOwner(), mszAppGitName);
|
||||
} else {
|
||||
@@ -225,102 +267,98 @@ public class AboutView extends LinearLayout {
|
||||
mAPPInfo.getAppGitOwner(), mszAppGitName,
|
||||
mAPPInfo.getAppGitAPPBranch(), mAPPInfo.getAppGitAPPSubProjectFolder());
|
||||
}
|
||||
LogUtils.d(TAG, "initAppLinkInfo() 完成,应用主页:" + mszHomePage + ",Git地址:" + mszGitea);
|
||||
LogUtils.d(TAG, "initAPPLinkInfo():链接信息初始化完成,应用主页=" + mszHomePage + ",Git地址=" + mszGitea);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化正式版APK信息,去除beta后缀适配正式包命名规范
|
||||
*/
|
||||
private void initReleaseAPKInfo() {
|
||||
LogUtils.d(TAG, "initReleaseAPKInfo() 初始化正式版APK信息");
|
||||
LogUtils.d(TAG, "initReleaseAPKInfo():开始初始化正式版APK信息");
|
||||
String szReleaseAppVersionName = "unknown";
|
||||
try {
|
||||
String szSubBetaSuffix = subBetaSuffix(mContext.getPackageName());
|
||||
szReleaseAppVersionName = mContext.getPackageManager().getPackageInfo(szSubBetaSuffix, 0).versionName;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
LogUtils.d(TAG, "initReleaseAPKInfo() 获取正式版版本号失败", e);
|
||||
LogUtils.e(TAG, "initReleaseAPKInfo():获取正式版版本号失败", e);
|
||||
}
|
||||
mszReleaseAPKName = String.format("%s_%s.apk", mszAppAPKName, szReleaseAppVersionName);
|
||||
LogUtils.d(TAG, "initReleaseAPKInfo() 完成,正式版APK名:" + mszReleaseAPKName);
|
||||
LogUtils.d(TAG, "initReleaseAPKInfo():正式版APK信息初始化完成,APK名=" + mszReleaseAPKName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 核心视图组装:按 图标→应用信息→分割线→通用功能控件 顺序构建页面
|
||||
* 核心视图组装:赋值基础信息到控件,添加通用功能项到容器
|
||||
*/
|
||||
private void initAboutPageView() {
|
||||
LogUtils.d(TAG, "initAboutPageView() 开始组装关于页视图");
|
||||
addAppIcon();
|
||||
addAppInfoDesc();
|
||||
addLineSeparator();
|
||||
|
||||
// 通用功能控件:网页跳转类+邮件类,复用抽象控件
|
||||
addView(new WebJumpFunctionItemView(mContext, "WinBoLL 主页", WINBOLL_OFFICIAL_HOME, R.drawable.ic_winboll));
|
||||
addView(new EmailFunctionItemView(mContext, "联系邮箱", "WinBoLLStudio<studio@winboll.cc>", R.drawable.ic_winboll));
|
||||
LogUtils.d(TAG, "initAboutPageView():开始组装关于页视图");
|
||||
// 赋值基础信息
|
||||
ivAppIcon.setImageResource(mnAppIcon);
|
||||
tvAppNameVersion.setText(String.format("%s %s", mszAppName, mszAppVersionName));
|
||||
if (mszAppDescription.isEmpty()) {
|
||||
tvAppDesc.setVisibility(GONE);
|
||||
} else {
|
||||
tvAppDesc.setVisibility(VISIBLE);
|
||||
tvAppDesc.setText(mszAppDescription);
|
||||
}
|
||||
// 添加通用功能项
|
||||
addFunctionView(new WebJumpFunctionItemView(mContext, "WinBoLL 主页", WINBOLL_OFFICIAL_HOME, R.drawable.ic_winboll));
|
||||
addFunctionView(new EmailFunctionItemView(mContext, "联系邮箱", "WinBoLLStudio<studio@winboll.cc>", R.drawable.ic_winboll));
|
||||
if (!mszHomePage.isEmpty()) {
|
||||
addView(new WebJumpFunctionItemView(mContext, "应用APK下载地址", mszHomePage, R.drawable.ic_winboll));
|
||||
addFunctionView(new WebJumpFunctionItemView(mContext, "应用APK下载地址", mszHomePage, R.drawable.ic_winboll));
|
||||
}
|
||||
if (!mszGitea.isEmpty()) {
|
||||
addView(new WebJumpFunctionItemView(mContext, "应用Git源码地址", mszGitea, R.drawable.ic_winboll));
|
||||
addFunctionView(new WebJumpFunctionItemView(mContext, "应用Git源码地址", mszGitea, R.drawable.ic_winboll));
|
||||
}
|
||||
LogUtils.d(TAG, "initAboutPageView() 视图组装完成,功能项加载完毕");
|
||||
LogUtils.d(TAG, "initAboutPageView():视图组装完成,功能项加载完毕");
|
||||
}
|
||||
|
||||
// 视图构建辅助方法区(基础视图组件)
|
||||
// ===================================== 内部工具/事件方法 =====================================
|
||||
/**
|
||||
* 添加应用图标组件,居中展示
|
||||
* 绑定功能按钮点击事件,处理正版校验、调试地址配置弹窗唤起
|
||||
*/
|
||||
private void addAppIcon() {
|
||||
ImageView ivIcon = new ImageView(mContext);
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(dp2px(ICON_SIZE), dp2px(ICON_SIZE));
|
||||
params.bottomMargin = dp2px(PADDING_MID);
|
||||
ivIcon.setLayoutParams(params);
|
||||
ivIcon.setImageResource(mnAppIcon);
|
||||
ivIcon.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||
addView(ivIcon);
|
||||
private void setBtnClickListener() {
|
||||
LogUtils.d(TAG, "setBtnClickListener():开始绑定功能按钮点击事件");
|
||||
// 取消调试状态按钮
|
||||
ibSebugStepOver.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
LogUtils.d(TAG, "ibSebugStepOver onClick:取消调试状态按钮已点击");
|
||||
GlobalApplication.setIsDebugging(false);
|
||||
GlobalApplication.saveDebugStatus(GlobalApplication.getInstance());
|
||||
ToastUtils.show("已取消调试状态,重启应用可生效。");
|
||||
}
|
||||
});
|
||||
// 正版校验弹窗
|
||||
ibSigngetDialog.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
LogUtils.d(TAG, "ibSigngetDialog onClick:唤起应用正版校验弹窗");
|
||||
new APPValidationDialog(mContext, mszAppName, mszAppVersionName).show();
|
||||
}
|
||||
});
|
||||
// 调试地址配置弹窗
|
||||
ibWinBoLLHostDialog.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
LogUtils.d(TAG, "ibWinBoLLHostDialog onClick:唤起调试地址配置弹窗");
|
||||
new DebugHostDialog(mContext).show();
|
||||
}
|
||||
});
|
||||
LogUtils.d(TAG, "setBtnClickListener():功能按钮点击事件绑定完成");
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加应用名称+版本号+描述信息组件,垂直居中展示
|
||||
* 添加功能项视图到容器,统一设置间距
|
||||
* @param view 功能项视图
|
||||
*/
|
||||
private void addAppInfoDesc() {
|
||||
LinearLayout llDesc = new LinearLayout(mContext);
|
||||
llDesc.setOrientation(VERTICAL);
|
||||
llDesc.setGravity(Gravity.CENTER);
|
||||
llDesc.setPadding(0, 0, 0, dp2px(PADDING_MID));
|
||||
|
||||
TextView tvAppName = new TextView(mContext);
|
||||
tvAppName.setText(String.format("%s %s", mszAppName, mszAppVersionName));
|
||||
tvAppName.setTextSize(18);
|
||||
tvAppName.setTextColor(mContext.getResources().getColor(R.color.gray_900));
|
||||
llDesc.addView(tvAppName);
|
||||
|
||||
if (!mszAppDescription.isEmpty()) {
|
||||
TextView tvDesc = new TextView(mContext);
|
||||
tvDesc.setText(mszAppDescription);
|
||||
tvDesc.setTextSize(14);
|
||||
tvDesc.setTextColor(mContext.getResources().getColor(R.color.gray_500));
|
||||
tvDesc.setPadding(0, dp2px(PADDING_SMALL), 0, 0);
|
||||
llDesc.addView(tvDesc);
|
||||
}
|
||||
addView(llDesc);
|
||||
private void addFunctionView(View view) {
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
|
||||
params.topMargin = 0;
|
||||
llFunctionContainer.addView(view, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加视图分割线,区分不同功能模块
|
||||
*/
|
||||
private void addLineSeparator() {
|
||||
View line = new View(mContext);
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, dp2px(LINE_HEIGHT));
|
||||
params.topMargin = dp2px(PADDING_SMALL);
|
||||
params.bottomMargin = dp2px(PADDING_MID);
|
||||
line.setLayoutParams(params);
|
||||
line.setBackgroundColor(mContext.getResources().getColor(R.color.gray_200));
|
||||
addView(line);
|
||||
}
|
||||
|
||||
// 工具方法区(通用工具+业务工具,静态优先,便于复用)
|
||||
/**
|
||||
* dp 转 px 工具方法,适配不同屏幕密度,保证布局一致性
|
||||
* dp转px工具方法,适配不同屏幕密度,保证布局一致性
|
||||
* @param dpValue dp单位尺寸
|
||||
* @return 转换后的px单位尺寸
|
||||
*/
|
||||
@@ -335,17 +373,20 @@ public class AboutView extends LinearLayout {
|
||||
* @return 去除beta后缀后的正式包名
|
||||
*/
|
||||
public static String subBetaSuffix(String input) {
|
||||
LogUtils.d(TAG, "subBetaSuffix() 执行包名beta后缀去除,原始包名:" + input);
|
||||
LogUtils.d(TAG, "subBetaSuffix():执行包名beta后缀去除,原始包名=" + input);
|
||||
if (input != null && input.endsWith(".beta")) {
|
||||
String result = input.substring(0, input.length() - ".beta".length());
|
||||
LogUtils.d(TAG, "subBetaSuffix() 处理成功,正式包名:" + result);
|
||||
LogUtils.d(TAG, "subBetaSuffix():处理成功,正式包名=" + result);
|
||||
return result;
|
||||
}
|
||||
LogUtils.d(TAG, "subBetaSuffix() 无需处理,包名不含beta后缀");
|
||||
LogUtils.d(TAG, "subBetaSuffix():无需处理,包名不含beta后缀");
|
||||
return input == null ? "" : input;
|
||||
}
|
||||
|
||||
// 内部抽象通用功能项基类 - 统一样式,减少冗余
|
||||
// ===================================== 内部抽象通用功能项基类 =====================================
|
||||
/**
|
||||
* 通用功能项基类,统一样式、布局、视图构建,减少冗余代码
|
||||
*/
|
||||
private abstract class BaseFunctionItemView extends LinearLayout implements OnClickListener {
|
||||
protected Context mItemContext;
|
||||
protected String mTitle;
|
||||
@@ -363,17 +404,32 @@ public class AboutView extends LinearLayout {
|
||||
setOnClickListener(this);
|
||||
}
|
||||
|
||||
// 统一布局配置
|
||||
/**
|
||||
* 统一初始化功能项布局属性
|
||||
*/
|
||||
private void initItemLayout() {
|
||||
setOrientation(HORIZONTAL);
|
||||
setGravity(Gravity.CENTER_VERTICAL);
|
||||
setPadding(dp2px(PADDING_MID), dp2px(PADDING_SMALL), dp2px(PADDING_MID), dp2px(PADDING_SMALL));
|
||||
setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
|
||||
setClickable(true);
|
||||
setBackgroundResource(android.R.drawable.list_selector_background);
|
||||
setBackground(create_item_background());
|
||||
}
|
||||
|
||||
// 统一视图构建
|
||||
/**
|
||||
* 创建带1像素边框的背景drawable
|
||||
*/
|
||||
private android.graphics.drawable.Drawable create_item_background() {
|
||||
android.graphics.drawable.GradientDrawable drawable = new android.graphics.drawable.GradientDrawable();
|
||||
drawable.setStroke(1, mItemContext.getResources().getColor(R.color.gray_200));
|
||||
drawable.setCornerRadius(4);
|
||||
drawable.setColor(mItemContext.getResources().getColor(android.R.color.white));
|
||||
return drawable;
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一构建功能项视图(左侧图标+右侧标题/内容)
|
||||
*/
|
||||
private void initItemViews() {
|
||||
// 左侧图标
|
||||
if (mIconRes != 0) {
|
||||
@@ -384,20 +440,17 @@ public class AboutView extends LinearLayout {
|
||||
ivIcon.setImageResource(mIconRes);
|
||||
addView(ivIcon);
|
||||
}
|
||||
|
||||
// 右侧文本容器
|
||||
LinearLayout llText = new LinearLayout(mItemContext);
|
||||
llText.setOrientation(VERTICAL);
|
||||
llText.setLayoutParams(new LayoutParams(0, LayoutParams.WRAP_CONTENT, 1.0f));
|
||||
addView(llText);
|
||||
|
||||
// 标题
|
||||
TextView tvTitle = new TextView(mItemContext);
|
||||
tvTitle.setText(mTitle);
|
||||
tvTitle.setTextSize(16);
|
||||
tvTitle.setTextColor(mItemContext.getResources().getColor(R.color.gray_900));
|
||||
llText.addView(tvTitle);
|
||||
|
||||
// 内容
|
||||
TextView tvContent = new TextView(mItemContext);
|
||||
tvContent.setText(mContent);
|
||||
@@ -407,11 +460,17 @@ public class AboutView extends LinearLayout {
|
||||
llText.addView(tvContent);
|
||||
}
|
||||
|
||||
// 子类指定内容文本颜色
|
||||
/**
|
||||
* 子类抽象方法:指定内容文本颜色
|
||||
* @return 颜色值
|
||||
*/
|
||||
protected abstract int getContentTextColor();
|
||||
}
|
||||
|
||||
// 邮件类功能控件 - 专属邮件唤起逻辑
|
||||
// ===================================== 内部邮件功能项子类 =====================================
|
||||
/**
|
||||
* 邮件类功能控件,实现专属邮件唤起逻辑,双方案兼容(纯邮件客户端/通用邮件应用)
|
||||
*/
|
||||
private class EmailFunctionItemView extends BaseFunctionItemView {
|
||||
public EmailFunctionItemView(Context context, String title, String content, int iconRes) {
|
||||
super(context, title, content, iconRes);
|
||||
@@ -424,36 +483,37 @@ public class AboutView extends LinearLayout {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
LogUtils.d(TAG, "EmailFunctionItemView onClick 触发邮件唤起");
|
||||
// 双方案邮件唤起逻辑
|
||||
LogUtils.d(TAG, "EmailFunctionItemView onClick:触发邮件唤起逻辑");
|
||||
// 方案1:纯邮件客户端唤起
|
||||
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
|
||||
emailIntent.setData(Uri.parse("mailto:" + EMAIL_ADDRESS));
|
||||
emailIntent.putExtra(Intent.EXTRA_SUBJECT, EMAIL_TITLE);
|
||||
emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
|
||||
if (emailIntent.resolveActivity(mItemContext.getPackageManager()) != null) {
|
||||
mItemContext.startActivity(emailIntent);
|
||||
LogUtils.d(TAG, "邮件唤起成功:系统纯邮件客户端");
|
||||
LogUtils.d(TAG, "EmailFunctionItemView:纯邮件客户端唤起成功");
|
||||
return;
|
||||
}
|
||||
|
||||
// 方案2:通用邮件应用兜底
|
||||
Intent fallbackIntent = new Intent(Intent.ACTION_SEND);
|
||||
fallbackIntent.setType(EMAIL_TYPE);
|
||||
fallbackIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{EMAIL_ADDRESS});
|
||||
fallbackIntent.putExtra(Intent.EXTRA_SUBJECT, EMAIL_TITLE);
|
||||
fallbackIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
|
||||
if (fallbackIntent.resolveActivity(mItemContext.getPackageManager()) != null) {
|
||||
mItemContext.startActivity(fallbackIntent);
|
||||
LogUtils.d(TAG, "邮件唤起成功:通用邮件应用");
|
||||
LogUtils.d(TAG, "EmailFunctionItemView:通用邮件应用唤起成功");
|
||||
} else {
|
||||
ToastUtils.show("未找到可发送邮件的应用");
|
||||
LogUtils.w(TAG, "邮件唤起失败:无可用邮件相关应用");
|
||||
LogUtils.w(TAG, "EmailFunctionItemView:邮件唤起失败,无可用邮件应用");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 网页跳转类功能控件 - 专属网页跳转逻辑
|
||||
// ===================================== 内部网页跳转功能项子类 =====================================
|
||||
/**
|
||||
* 网页跳转类功能控件,实现专属网页唤起逻辑,包含空地址校验、异常捕获
|
||||
*/
|
||||
private class WebJumpFunctionItemView extends BaseFunctionItemView {
|
||||
public WebJumpFunctionItemView(Context context, String title, String content, int iconRes) {
|
||||
super(context, title, content, iconRes);
|
||||
@@ -466,25 +526,28 @@ public class AboutView extends LinearLayout {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
LogUtils.d(TAG, "WebJumpFunctionItemView onClick 触发网页跳转,地址:" + mContent);
|
||||
LogUtils.d(TAG, "WebJumpFunctionItemView onClick:触发网页跳转,地址=" + mContent);
|
||||
if (mContent.isEmpty()) {
|
||||
ToastUtils.show("跳转地址为空");
|
||||
LogUtils.w(TAG, "网页跳转失败:地址为空");
|
||||
LogUtils.w(TAG, "WebJumpFunctionItemView:网页跳转失败,地址为空");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(mContent));
|
||||
browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
mItemContext.startActivity(browserIntent);
|
||||
LogUtils.d(TAG, "网页跳转成功");
|
||||
LogUtils.d(TAG, "WebJumpFunctionItemView:网页跳转成功");
|
||||
} catch (Exception e) {
|
||||
LogUtils.d(TAG, "网页跳转失败,异常捕获", e);
|
||||
LogUtils.e(TAG, "WebJumpFunctionItemView:网页跳转失败", e);
|
||||
ToastUtils.show("链接无法打开");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 内部接口区(置于类末尾,逻辑闭环)
|
||||
// ===================================== 内部回调接口 =====================================
|
||||
/**
|
||||
* 调试信息自动填充回调接口
|
||||
*/
|
||||
public interface OnRequestDevUserInfoAutofillListener {
|
||||
void requestAutofill(EditText etDevUserName, EditText etDevUserPassword);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package cc.winboll.studio.libappbase.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Toast;
|
||||
import cc.winboll.studio.libappbase.GlobalApplication;
|
||||
|
||||
/**
|
||||
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2026/04/06 19:32
|
||||
* @Describe 具有调试模式切换功能的应用Logo控件,连续点击10次弹出提示
|
||||
*/
|
||||
public class DebugSwitchImageView extends ImageView {
|
||||
|
||||
public static final String TAG = "DebugSwitchImageView";
|
||||
|
||||
// 连续点击计数
|
||||
private int mClickCount = 0;
|
||||
// 目标点击次数
|
||||
private static final int TARGET_CLICK_COUNT = 10;
|
||||
|
||||
public DebugSwitchImageView(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public DebugSwitchImageView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public DebugSwitchImageView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
}
|
||||
|
||||
public DebugSwitchImageView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mClickCount++;
|
||||
if (mClickCount == TARGET_CLICK_COUNT) {
|
||||
// 达到10次,弹出Toast
|
||||
Toast.makeText(getContext(), "连续点击已达到10次,现在开启应用调试功能。", Toast.LENGTH_SHORT).show();
|
||||
GlobalApplication.setIsDebugging(true);
|
||||
GlobalApplication.saveDebugStatus(GlobalApplication.getInstance());
|
||||
// 重置计数,可再次触发
|
||||
mClickCount = 0;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
11
libappbase/src/main/res/drawable/ic_bug.xml
Normal file
11
libappbase/src/main/res/drawable/ic_bug.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportHeight="24"
|
||||
android:viewportWidth="24">
|
||||
<path
|
||||
android:fillColor="#ff000000"
|
||||
android:pathData="M14,12H10V10H14M14,16H10V14H14M20,8H17.19C16.74,7.22 16.12,6.55 15.37,6.04L17,4.41L15.59,3L13.42,5.17C12.96,5.06 12.5,5 12,5C11.5,5 11.04,5.06 10.59,5.17L8.41,3L7,4.41L8.62,6.04C7.88,6.55 7.26,7.22 6.81,8H4V10H6.09C6.04,10.33 6,10.66 6,11V12H4V14H6V15C6,15.34 6.04,15.67 6.09,16H4V18H6.81C7.85,19.79 9.78,21 12,21C14.22,21 16.15,19.79 17.19,18H20V16H17.91C17.96,15.67 18,15.34 18,15V14H20V12H18V11C18,10.66 17.96,10.33 17.91,10H20V8Z"/>
|
||||
|
||||
</vector>
|
||||
11
libappbase/src/main/res/drawable/ic_debug_step_over.xml
Normal file
11
libappbase/src/main/res/drawable/ic_debug_step_over.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportHeight="24"
|
||||
android:viewportWidth="24">
|
||||
<path
|
||||
android:fillColor="#ff000000"
|
||||
android:pathData="M19,7H16.19C15.74,6.2 15.12,5.5 14.37,5L16,3.41L14.59,2L12.42,4.17C11.96,4.06 11.5,4 11,4S10.05,4.06 9.59,4.17L7.41,2L6,3.41L7.62,5C6.87,5.5 6.26,6.21 5.81,7H3V9H5.09C5.03,9.33 5,9.66 5,10V11H3V13H5V14C5,14.34 5.03,14.67 5.09,15H3V17H5.81C7.26,19.5 10.28,20.61 13,19.65V19C13,18.43 13.09,17.86 13.25,17.31C12.59,17.76 11.8,18 11,18C8.79,18 7,16.21 7,14V10C7,7.79 8.79,6 11,6S15,7.79 15,10V14C15,14.19 15,14.39 14.95,14.58C15.54,14.04 16.24,13.62 17,13.35V13H19V11H17V10C17,9.66 16.97,9.33 16.91,9H19V7M13,9V11H9V9H13M13,13V15H9V13H13M16,16H22V22H16V16Z"/>
|
||||
|
||||
</vector>
|
||||
11
libappbase/src/main/res/drawable/ic_key.xml
Normal file
11
libappbase/src/main/res/drawable/ic_key.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportHeight="24"
|
||||
android:viewportWidth="24">
|
||||
<path
|
||||
android:fillColor="#ff000000"
|
||||
android:pathData="M7,14C5.9,14 5,13.1 5,12S5.9,10 7,10 9,10.9 9,12 8.1,14 7,14M12.6,10C11.8,7.7 9.6,6 7,6C3.7,6 1,8.7 1,12S3.7,18 7,18C9.6,18 11.8,16.3 12.6,14H16V18H20V14H23V10H12.6Z"/>
|
||||
|
||||
</vector>
|
||||
18
libappbase/src/main/res/drawable/shape_edittext_bg.xml
Normal file
18
libappbase/src/main/res/drawable/shape_edittext_bg.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_focused="true">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#FFFFFF"/>
|
||||
<stroke android:width="1dp" android:color="#007AFF"/>
|
||||
<corners android:radius="8dp"/>
|
||||
</shape>
|
||||
</item>
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#FFFFFF"/>
|
||||
<stroke android:width="1dp" android:color="#E5E5E5"/>
|
||||
<corners android:radius="8dp"/>
|
||||
</shape>
|
||||
</item>
|
||||
</selector>
|
||||
|
||||
52
libappbase/src/main/res/layout/dialog_sign_get.xml
Normal file
52
libappbase/src/main/res/layout/dialog_sign_get.xml
Normal file
@@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp"
|
||||
android:gravity="center"
|
||||
android:background="#FFDCDCDC">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="应用指纹校验"
|
||||
android:textSize="16sp"
|
||||
android:textColor="@color/gray_900"
|
||||
android:textStyle="bold"
|
||||
android:layout_marginBottom="12dp"/>
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/et_sign_fingerprint"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@android:drawable/edit_text"
|
||||
android:textSize="12sp"
|
||||
android:gravity="top"
|
||||
android:hint="签名获取中..."
|
||||
android:singleLine="false"
|
||||
android:scrollHorizontally="false"
|
||||
android:scrollbars="vertical"
|
||||
android:overScrollMode="always"
|
||||
android:typeface="monospace"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="10dp"/>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_auth_result"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:textSize="11sp"
|
||||
android:gravity="center"
|
||||
android:textColor="@color/gray_900"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
60
libappbase/src/main/res/layout/dialog_winboll_host.xml
Normal file
60
libappbase/src/main/res/layout/dialog_winboll_host.xml
Normal file
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp"
|
||||
android:background="#FFFFFF">
|
||||
|
||||
<!-- 标题 -->
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="设置服务器地址"
|
||||
android:textSize="16sp"
|
||||
android:textColor="#212121"
|
||||
android:textStyle="bold"
|
||||
android:layout_marginBottom="16dp"/>
|
||||
|
||||
<!-- 地址输入框 -->
|
||||
<EditText
|
||||
android:id="@+id/et_host_input"
|
||||
android:layout_width="300dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="请输入服务器地址(如http://localhost:8080)"
|
||||
android:textSize="14sp"
|
||||
android:inputType="textUri"
|
||||
android:padding="8dp"
|
||||
android:background="@android:drawable/edit_text"
|
||||
android:layout_marginBottom="16dp"/>
|
||||
|
||||
<!-- 按钮容器 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="end">
|
||||
|
||||
<!-- 取消按钮 -->
|
||||
<Button
|
||||
android:id="@+id/btn_cancel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="取消"
|
||||
android:textSize="14sp"
|
||||
android:layout_marginRight="8dp"/>
|
||||
|
||||
<!-- 确认按钮 -->
|
||||
<Button
|
||||
android:id="@+id/btn_confirm"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="确认"
|
||||
android:textSize="14sp"
|
||||
android:backgroundTint="#2196F3"
|
||||
android:textColor="#FFFFFF"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
92
libappbase/src/main/res/layout/layout_about_view.xml
Normal file
92
libappbase/src/main/res/layout/layout_about_view.xml
Normal file
@@ -0,0 +1,92 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center_horizontal"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingRight="16dp"
|
||||
android:paddingBottom="16dp">
|
||||
|
||||
<cc.winboll.studio.libappbase.views.DebugSwitchImageView
|
||||
android:id="@+id/iv_app_icon"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:scaleType="centerCrop"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_app_name_version"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="18sp"
|
||||
android:textColor="@color/gray_900"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_app_desc"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@color/gray_500"/>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1px"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:background="@color/gray_200"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ll_function_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"/>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:layout_marginTop="8dp"
|
||||
android:spacing="20dp">
|
||||
|
||||
<ImageButton
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:src="@drawable/ic_debug_step_over"
|
||||
android:id="@+id/ib_debug_step_over"
|
||||
android:scaleType="fitCenter"
|
||||
android:adjustViewBounds="true"
|
||||
android:background="@null"/>
|
||||
|
||||
<ImageButton
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:src="@drawable/ic_winboll"
|
||||
android:id="@+id/ib_winbollhostdialog"
|
||||
android:scaleType="fitCenter"
|
||||
android:adjustViewBounds="true"
|
||||
android:background="@null"/>
|
||||
|
||||
<ImageButton
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:src="@drawable/ic_key"
|
||||
android:id="@+id/ib_signgetdialog"
|
||||
android:scaleType="fitCenter"
|
||||
android:adjustViewBounds="true"
|
||||
android:background="@null"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
||||
@@ -11,5 +11,10 @@
|
||||
<item name="colorText">#FF00B322</item>
|
||||
<item name="colorTextBackgound">#FF000000</item>
|
||||
</style>
|
||||
|
||||
<style name="DialogStyle" parent="@android:style/Theme.Dialog">
|
||||
<item name="android:windowBackground">@android:color/transparent</item>
|
||||
<item name="android:windowNoTitle">true</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
||||
35
libappbase/src/main/res/xml/network_security_config.xml
Normal file
35
libappbase/src/main/res/xml/network_security_config.xml
Normal file
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<network-security-config>
|
||||
<domain-config cleartextTrafficPermitted="true">
|
||||
<!-- 原有配置 保留 -->
|
||||
<domain includeSubdomains="true">winboll.cc</domain>
|
||||
<domain includeSubdomains="true">localhost</domain>
|
||||
<domain includeSubdomains="true">127.0.0.1</domain>
|
||||
|
||||
<!-- 精准配置10.8.0.0/24 前20个IP(10.8.0.0~10.8.0.19)-->
|
||||
<domain includeSubdomains="false">10.8.0.0</domain>
|
||||
<domain includeSubdomains="false">10.8.0.1</domain>
|
||||
<domain includeSubdomains="false">10.8.0.2</domain>
|
||||
<domain includeSubdomains="false">10.8.0.3</domain>
|
||||
<domain includeSubdomains="false">10.8.0.4</domain>
|
||||
<domain includeSubdomains="false">10.8.0.5</domain>
|
||||
<domain includeSubdomains="false">10.8.0.6</domain>
|
||||
<domain includeSubdomains="false">10.8.0.7</domain>
|
||||
<domain includeSubdomains="false">10.8.0.8</domain>
|
||||
<domain includeSubdomains="false">10.8.0.9</domain>
|
||||
<domain includeSubdomains="false">10.8.0.10</domain>
|
||||
<domain includeSubdomains="false">10.8.0.11</domain>
|
||||
<domain includeSubdomains="false">10.8.0.12</domain>
|
||||
<domain includeSubdomains="false">10.8.0.13</domain>
|
||||
<domain includeSubdomains="false">10.8.0.14</domain>
|
||||
<domain includeSubdomains="false">10.8.0.15</domain>
|
||||
<domain includeSubdomains="false">10.8.0.16</domain>
|
||||
<domain includeSubdomains="false">10.8.0.17</domain>
|
||||
<domain includeSubdomains="false">10.8.0.18</domain>
|
||||
<domain includeSubdomains="false">10.8.0.19</domain>
|
||||
</domain-config>
|
||||
</network-security-config>
|
||||
|
||||
|
||||
|
||||
|
||||
45
mymessagemanager/README.md
Normal file
45
mymessagemanager/README.md
Normal file
@@ -0,0 +1,45 @@
|
||||
# MyMessageManager
|
||||
|
||||
#### 介绍
|
||||
用正则表达式方法自定义短信过滤和语音播报的短信应用。
|
||||
|
||||
#### 软件架构
|
||||
软件架构说明
|
||||
|
||||
|
||||
#### 安装教程
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### 使用说明
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### 参与贡献
|
||||
|
||||
1. Fork 本仓库
|
||||
2. 新建 Feat_xxx 分支
|
||||
3. 提交代码:ZhanGSKen(ZhanGSKen<zhangsken@188.com>)
|
||||
4. 新建 Pull Request
|
||||
|
||||
|
||||
#### 特技
|
||||
|
||||
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
|
||||
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
|
||||
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
|
||||
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
|
||||
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
|
||||
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
||||
|
||||
#### 参考文档
|
||||
|
||||
使用GitHub Actions实现Android自动打包apk
|
||||
https://blog.csdn.net/ZZL23333/article/details/115798615?app_version=6.0.0&code=app_1562916241&csdn_share_tail=%7B%22type%22%3A%22blog%22%2C%22rType%22%3A%22article%22%2C%22rId%22%3A%22115798615%22%2C%22source%22%3A%22weixin_38986226%22%7D&uLinkId=usr1mkqgl919blen&utm_source=app
|
||||
|
||||
Android中assets的使用(用于读取内容)
|
||||
https://blog.csdn.net/qq_27664947/article/details/103924058?app_version=6.0.0&code=app_1562916241&csdn_share_tail=%7B%22type%22%3A%22blog%22%2C%22rType%22%3A%22article%22%2C%22rId%22%3A%22103924058%22%2C%22source%22%3A%22weixin_38986226%22%7D&uLinkId=usr1mkqgl919blen&utm_source=app
|
||||
@@ -18,27 +18,30 @@ def genVersionName(def versionName){
|
||||
}
|
||||
|
||||
android {
|
||||
|
||||
// 关键:改为你已安装的 SDK 32(≥ targetSdkVersion 30,兼容已安装环境)
|
||||
compileSdkVersion 32
|
||||
|
||||
// 直接使用已安装的构建工具 33.0.3(无需修改)
|
||||
buildToolsVersion "33.0.3"
|
||||
compileSdkVersion 30
|
||||
|
||||
buildToolsVersion "30.0.3"
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_7
|
||||
targetCompatibility JavaVersion.VERSION_1_7
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
applicationId "cc.winboll.studio.powerbell"
|
||||
minSdkVersion 23
|
||||
applicationId "cc.winboll.studio.mymessagemanager"
|
||||
minSdkVersion 26
|
||||
targetSdkVersion 30
|
||||
versionCode 7
|
||||
versionCode 8
|
||||
// versionName 更新后需要手动设置
|
||||
// .winboll/winbollBuildProps.properties 文件的 stageCount=0
|
||||
// Gradle编译环境下合起来的 versionName 就是 "${versionName}.0"
|
||||
versionName "15.14"
|
||||
versionName "15.12"
|
||||
if(true) {
|
||||
versionName = genVersionName("${versionName}")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 米盟 SDK
|
||||
packagingOptions {
|
||||
doNotStrip "*/*/libmimo_1011.so"
|
||||
@@ -56,23 +59,16 @@ dependencies {
|
||||
api 'com.github.bumptech.glide:glide:4.9.0'
|
||||
//annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
|
||||
|
||||
// uCrop 核心依赖(最新稳定版)
|
||||
implementation 'com.github.yalantis:ucrop:2.2.8'
|
||||
// 兼容AndroidX(若项目用AndroidX,必须添加)
|
||||
//implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||
implementation 'androidx.exifinterface:exifinterface:1.3.6'
|
||||
|
||||
// 应用介绍页类库
|
||||
api 'io.github.medyo:android-about-page:2.0.0'
|
||||
// SSH
|
||||
api 'io.github.medyo:android-about-page:2.0.0'
|
||||
api 'com.jcraft:jsch:0.1.55'
|
||||
// Html 解析
|
||||
api 'org.jsoup:jsoup:1.13.1'
|
||||
// 二维码类库
|
||||
api 'com.google.zxing:core:3.4.1'
|
||||
api 'com.journeyapps:zxing-android-embedded:3.6.0'
|
||||
// 网络连接类库
|
||||
api 'com.squareup.okhttp3:okhttp:4.4.1'
|
||||
|
||||
api 'com.belerweb:pinyin4j:2.5.1'
|
||||
|
||||
// 权限请求框架:https://github.com/getActivity/XXPermissions
|
||||
api 'com.github.getActivity:XXPermissions:18.63'
|
||||
api 'com.baoyz.pullrefreshlayout:library:1.2.0'
|
||||
|
||||
// AndroidX 类库
|
||||
api 'androidx.appcompat:appcompat:1.1.0'
|
||||
@@ -81,15 +77,15 @@ 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.google.android.material:material:1.0.0'
|
||||
|
||||
// WinBoLL库 nexus.winboll.cc 地址
|
||||
api 'cc.winboll.studio:libaes:15.12.13'
|
||||
api 'cc.winboll.studio:libaes:15.12.12'
|
||||
api 'cc.winboll.studio:libappbase:15.14.2'
|
||||
|
||||
// WinBoLL备用库 jitpack.io 地址
|
||||
//api 'com.github.ZhanGSKen:AES:aes-v15.12.9'
|
||||
//api 'com.github.ZhanGSKen:APPBase:appbase-v15.14.1'
|
||||
|
||||
//api fileTree(dir: 'libs', include: ['*.aar'])
|
||||
api fileTree(dir: 'libs', include: ['*.jar'])
|
||||
api fileTree(dir: 'libs', include: ['*.jar'])
|
||||
}
|
||||
8
mymessagemanager/build.properties
Normal file
8
mymessagemanager/build.properties
Normal file
@@ -0,0 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Fri May 08 20:38:36 CST 2026
|
||||
stageCount=8
|
||||
libraryProject=
|
||||
baseVersion=15.12
|
||||
publishVersion=15.12.7
|
||||
buildCount=18
|
||||
baseBetaVersion=15.12.8
|
||||
23
mymessagemanager/src/beta/AndroidManifest.xml
Normal file
23
mymessagemanager/src/beta/AndroidManifest.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools" >
|
||||
|
||||
<application>
|
||||
|
||||
<!-- Put flavor specific code here -->
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="cc.winboll.studio.mymessagemanager.beta.fileprovider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/file_provider"/>
|
||||
|
||||
</provider>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
||||
6
mymessagemanager/src/beta/res/values-zh/strings.xml
Normal file
6
mymessagemanager/src/beta/res/values-zh/strings.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="app_name">我的短信管家 ☆</string>
|
||||
|
||||
</resources>
|
||||
6
mymessagemanager/src/beta/res/values/strings.xml
Normal file
6
mymessagemanager/src/beta/res/values/strings.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="app_name">My Message Manager +</string>
|
||||
|
||||
</resources>
|
||||
227
mymessagemanager/src/main/AndroidManifest.xml
Normal file
227
mymessagemanager/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,227 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<manifest
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="cc.winboll.studio.mymessagemanager">
|
||||
|
||||
<!-- 发送短信 -->
|
||||
<uses-permission android:name="android.permission.SEND_SMS"/>
|
||||
|
||||
<!-- 接收讯息(短信) -->
|
||||
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
|
||||
|
||||
<!-- 读取短信 -->
|
||||
<uses-permission android:name="android.permission.READ_SMS"/>
|
||||
|
||||
<!-- WRITE_SMS -->
|
||||
<uses-permission android:name="android.permission.WRITE_SMS"/>
|
||||
|
||||
<!-- 接收讯息(彩信) -->
|
||||
<uses-permission android:name="android.permission.RECEIVE_MMS"/>
|
||||
|
||||
<!-- 开机启动 -->
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
||||
|
||||
<!-- 运行前台服务 -->
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
|
||||
|
||||
<!-- 读取联系人 -->
|
||||
<uses-permission android:name="android.permission.READ_CONTACTS"/>
|
||||
|
||||
<!-- 读取您共享存储空间中的内容 -->
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||
|
||||
<!-- 修改或删除您共享存储空间中的内容 -->
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
|
||||
<!-- 接收讯息 (WAP) -->
|
||||
<uses-permission android:name="android.permission.RECEIVE_WAP_PUSH"/>
|
||||
|
||||
<!-- MANAGE_EXTERNAL_STORAGE -->
|
||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
|
||||
|
||||
<!-- 此应用可显示在其他应用上方 -->
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
|
||||
|
||||
<queries>
|
||||
|
||||
<intent>
|
||||
|
||||
<action android:name="android.intent.action.TTS_SERVICE"/>
|
||||
|
||||
</intent>
|
||||
|
||||
</queries>
|
||||
|
||||
<application
|
||||
android:name=".App"
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:roundIcon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/MyAppTheme"
|
||||
android:persistent="true"
|
||||
android:resizeableActivity="true"
|
||||
android:supportsRtl="true"
|
||||
android:requestLegacyExternalStorage="true"
|
||||
android:networkSecurityConfig="@xml/network_security_config">
|
||||
|
||||
<activity android:name=".activitys.SMSActivity"/>
|
||||
|
||||
<activity android:name=".activitys.SMSReceiveRuleActivity">
|
||||
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".activitys.SharedJSONReceiveActivity"
|
||||
android:exported="true">
|
||||
|
||||
<intent-filter>
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
|
||||
<action android:name="android.intent.action.SEND"/>
|
||||
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
|
||||
<action android:name="android.intent.action.EDIT"/>
|
||||
|
||||
<data android:mimeType="application/json"/>
|
||||
|
||||
<data android:mimeType="text/x-json"/>
|
||||
|
||||
</intent-filter>
|
||||
|
||||
</activity>
|
||||
|
||||
<activity android:name=".activitys.TTSPlayRuleActivity"/>
|
||||
|
||||
<activity android:name=".activitys.AboutActivity"/>
|
||||
|
||||
<activity
|
||||
android:name=".activitys.MainActivity"
|
||||
android:exported="true">
|
||||
|
||||
<intent-filter>
|
||||
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
|
||||
</intent-filter>
|
||||
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".activitys.ComposeSMSActivity"
|
||||
android:exported="true">
|
||||
|
||||
<intent-filter>
|
||||
|
||||
<action android:name="android.intent.action.SEND"/>
|
||||
|
||||
<action android:name="android.intent.action.SENDTO"/>
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
|
||||
<category android:name="android.intent.category.BROWSABLE"/>
|
||||
|
||||
<data android:scheme="sms"/>
|
||||
|
||||
<data android:scheme="smsto"/>
|
||||
|
||||
<data android:scheme="mms"/>
|
||||
|
||||
<data android:scheme="mmsto"/>
|
||||
|
||||
</intent-filter>
|
||||
|
||||
</activity>
|
||||
|
||||
<activity android:name=".activitys.AppSettingsActivity"/>
|
||||
|
||||
<service android:name=".services.TTSPlayService"/>
|
||||
|
||||
<service android:name=".services.MainService"/>
|
||||
|
||||
<service android:name=".services.AssistantService"/>
|
||||
|
||||
<service
|
||||
android:name=".services.DefaultSMSManagerService"
|
||||
android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE"
|
||||
android:exported="true">
|
||||
|
||||
<intent-filter>
|
||||
|
||||
<action android:name="android.intent.action.RESPOND_VIA_MESSAGE"/>
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
|
||||
<data android:scheme="sms"/>
|
||||
|
||||
<data android:scheme="smsto"/>
|
||||
|
||||
<data android:scheme="mms"/>
|
||||
|
||||
<data android:scheme="mmsto"/>
|
||||
|
||||
</intent-filter>
|
||||
|
||||
</service>
|
||||
|
||||
<receiver
|
||||
android:name=".receivers.MainReceiver"
|
||||
android:enabled="true"
|
||||
android:exported="false"
|
||||
android:directBootAware="true">
|
||||
|
||||
<intent-filter>
|
||||
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED"/>
|
||||
|
||||
</intent-filter>
|
||||
|
||||
</receiver>
|
||||
|
||||
<receiver
|
||||
android:name=".receivers.SMSRecevier"
|
||||
android:exported="true"
|
||||
android:permission="android.permission.BROADCAST_SMS">
|
||||
|
||||
<intent-filter android:priority="1">
|
||||
|
||||
<action android:name="android.provider.Telephony.SMS_DELIVER"/>
|
||||
|
||||
</intent-filter>
|
||||
|
||||
</receiver>
|
||||
|
||||
<receiver
|
||||
android:name=".receivers.MmsReceiver"
|
||||
android:exported="true"
|
||||
android:permission="android.permission.BROADCAST_WAP_PUSH">
|
||||
|
||||
<intent-filter>
|
||||
|
||||
<action android:name="android.provider.Telephony.WAP_PUSH_DELIVER"/>
|
||||
|
||||
<data android:mimeType="application/vnd.wap.mms-message"/>
|
||||
|
||||
</intent-filter>
|
||||
|
||||
</receiver>
|
||||
|
||||
<meta-data
|
||||
android:name="android.max_aspect"
|
||||
android:value="4.0"/>
|
||||
|
||||
<activity android:name="cc.winboll.studio.mymessagemanager.activitys.SMSRecycleActivity"/>
|
||||
|
||||
<activity android:name="cc.winboll.studio.mymessagemanager.activitys.SMSRecycle2Activity"/>
|
||||
|
||||
<activity android:name="cc.winboll.studio.mymessagemanager.unittest.UnitTestActivity"/>
|
||||
|
||||
<activity android:name="cc.winboll.studio.mymessagemanager.activitys.TTSFloatSettingsActivity"/>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -0,0 +1,7 @@
|
||||
[
|
||||
{
|
||||
"userId": -1,
|
||||
"ruleData": ".*",
|
||||
"isEnable": true
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,38 @@
|
||||
[
|
||||
{
|
||||
"userId": 1,
|
||||
"ruleName": "规则1",
|
||||
"demoSMSText": "【短信应用A】验证码123456",
|
||||
"patternText": "^(【.*】)验证码(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)$",
|
||||
"ttdRuleText": "$1验证码是($2)($3)($4)($5)($6)($7)。",
|
||||
"isSimpleView": false,
|
||||
"isEnable": true
|
||||
},
|
||||
{
|
||||
"userId": 1,
|
||||
"ruleName": "规则2",
|
||||
"demoSMSText": "[短信应用A]验证码123456",
|
||||
"patternText": "^(\\[.*\\])验证码(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)$",
|
||||
"ttdRuleText": "$1验证码是($2)($3)($4)($5)($6)($7)。",
|
||||
"isSimpleView": false,
|
||||
"isEnable": true
|
||||
},
|
||||
{
|
||||
"userId": 1,
|
||||
"ruleName": "规则3",
|
||||
"demoSMSText": "【短信应用A】验证码123456",
|
||||
"patternText": ".*(【.+】).*",
|
||||
"ttdRuleText": "短信来自$1。",
|
||||
"isSimpleView": false,
|
||||
"isEnable": true
|
||||
},
|
||||
{
|
||||
"userId": 1,
|
||||
"ruleName": "规则4",
|
||||
"demoSMSText": "[短信应用A]验证码123456",
|
||||
"patternText": ".*(\\[.*\\]).*",
|
||||
"ttdRuleText": "短信来自$1。",
|
||||
"isSimpleView": false,
|
||||
"isEnable": true
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,52 @@
|
||||
package cc.winboll.studio.mymessagemanager;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen@QQ.COM
|
||||
* @Date 2023/07/24 01:46:59
|
||||
* @Describe 全局应用类
|
||||
*/
|
||||
import android.view.Gravity;
|
||||
import cc.winboll.studio.libappbase.GlobalApplication;
|
||||
import cc.winboll.studio.libappbase.ToastUtils;
|
||||
import cc.winboll.studio.mymessagemanager.R;
|
||||
import java.io.File;
|
||||
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
|
||||
|
||||
public class App extends GlobalApplication {
|
||||
|
||||
public static final String TAG = "GlobalApplication";
|
||||
|
||||
static String _mszAppExternalFilesDir;
|
||||
static String _mszConfigUtilFileName = "ConfigUtil.json";
|
||||
static String _mszConfigUtilPath;
|
||||
static String _mszSMSReceiveRuleUtilFileName = "SMSReceiveRuleUtil.json";
|
||||
static String _mszSMSReceiveRuleUtilPath;
|
||||
|
||||
public static final int USER_ID = -1;
|
||||
Long mszVersionName = 1L;
|
||||
Long mszDataVersionName = 1L;
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
setIsDebugging(BuildConfig.DEBUG);
|
||||
//setIsDebugging(false);
|
||||
|
||||
// 初始化窗口管理类
|
||||
WinBoLLActivityManager.init(this);
|
||||
|
||||
// 初始化 Toast 框架
|
||||
ToastUtils.init(this);
|
||||
|
||||
_mszAppExternalFilesDir = getExternalFilesDir(TAG).toString();
|
||||
_mszConfigUtilPath = _mszAppExternalFilesDir + File.separator + _mszConfigUtilFileName;
|
||||
_mszSMSReceiveRuleUtilPath = _mszAppExternalFilesDir + File.separator + _mszSMSReceiveRuleUtilFileName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTerminate() {
|
||||
super.onTerminate();
|
||||
ToastUtils.release();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package cc.winboll.studio.mymessagemanager.activitys;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2024/07/14 13:20:33
|
||||
* @Describe 应用介绍窗口
|
||||
*/
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
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;
|
||||
import cc.winboll.studio.mymessagemanager.App;
|
||||
import cc.winboll.studio.mymessagemanager.R;
|
||||
|
||||
public class AboutActivity extends WinBoLLActivity implements IWinBoLLActivity {
|
||||
|
||||
public static final String TAG = "AboutActivity";
|
||||
|
||||
Context mContext;
|
||||
Toolbar mToolbar;
|
||||
|
||||
@Override
|
||||
public Activity getActivity() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mContext = this;
|
||||
setContentView(R.layout.activity_about);
|
||||
|
||||
mToolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(mToolbar);
|
||||
mToolbar.setSubtitle(TAG);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
AboutView aboutView = CreateAboutView();
|
||||
// 在 Activity 的 onCreate 或其他生命周期方法中调用
|
||||
// LinearLayout layout = new LinearLayout(this);
|
||||
// layout.setOrientation(LinearLayout.VERTICAL);
|
||||
// // 创建布局参数(宽度和高度)
|
||||
// ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(
|
||||
// ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
// ViewGroup.LayoutParams.MATCH_PARENT
|
||||
// );
|
||||
// addContentView(aboutView, params);
|
||||
|
||||
LinearLayout layout = findViewById(R.id.aboutviewroot_ll);
|
||||
// 创建布局参数(宽度和高度)
|
||||
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
);
|
||||
layout.addView(aboutView, params);
|
||||
|
||||
WinBoLLActivityManager.getInstance().add(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
WinBoLLActivityManager.getInstance().registeRemove(this);
|
||||
}
|
||||
|
||||
public AboutView CreateAboutView() {
|
||||
String szBranchName = "mymessagemanager";
|
||||
APPInfo appInfo = new APPInfo();
|
||||
appInfo.setAppName(getString(R.string.app_name));
|
||||
appInfo.setAppIcon(cc.winboll.studio.libaes.R.drawable.ic_winboll);
|
||||
appInfo.setAppDescription(getString(R.string.app_description));
|
||||
appInfo.setAppGitName("APPBase");
|
||||
appInfo.setAppGitOwner("Studio");
|
||||
appInfo.setAppGitAPPBranch(szBranchName);
|
||||
appInfo.setAppGitAPPSubProjectFolder(szBranchName);
|
||||
appInfo.setAppHomePage("https://discuz.winboll.cc/forum.php?mod=viewthread&tid=5&extra=page%3D1");
|
||||
appInfo.setAppAPKName("MyMessageManager");
|
||||
appInfo.setAppAPKFolderName("MyMessageManager");
|
||||
return new AboutView(mContext, appInfo);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
package cc.winboll.studio.mymessagemanager.activitys;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2024/05/12 20:03:42
|
||||
* @Describe 应用设置窗口
|
||||
*/
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.Switch;
|
||||
import android.widget.Toast;
|
||||
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
|
||||
import cc.winboll.studio.libaes.views.AOHPCTCSeekBar;
|
||||
import cc.winboll.studio.libaes.views.AToolbar;
|
||||
import cc.winboll.studio.libappbase.ToastUtils;
|
||||
import cc.winboll.studio.mymessagemanager.R;
|
||||
import cc.winboll.studio.mymessagemanager.dialogs.CharsetRefuseEditDialog;
|
||||
import cc.winboll.studio.mymessagemanager.utils.AppConfigUtil;
|
||||
import cc.winboll.studio.mymessagemanager.utils.PermissionUtil;
|
||||
|
||||
public class AppSettingsActivity extends WinBoLLActivity implements IWinBoLLActivity {
|
||||
|
||||
public static final String TAG = "AppSettingsActivity";
|
||||
|
||||
// 讯飞语记官网下载页链接
|
||||
private static final String XUNFEI_YUJI_DOWNLOAD_URL = "https://iflynote.com/h/share-download-app.html";
|
||||
|
||||
AppConfigUtil mAppConfigUtil;
|
||||
AToolbar mAToolbar;
|
||||
AOHPCTCSeekBar mAOHPCTCSeekBar;
|
||||
EditText metTTSPlayDelayTimes;
|
||||
EditText metPhoneMergePrefix;
|
||||
Switch mswMergePrefixPhone;
|
||||
Switch mswSMSRecycleProtectMode;
|
||||
//EditText metProtectModerRefuseChars;
|
||||
EditText metProtectModerReplaceChars;
|
||||
String mszProtectModerRefuseChars = "";
|
||||
RadioGroup mRadioGroupRecycleBin;
|
||||
|
||||
@Override
|
||||
public Activity getActivity() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_appsettings);
|
||||
|
||||
// 初始化属性
|
||||
mAppConfigUtil = AppConfigUtil.getInstance(this);
|
||||
int nTtsPlayDelayTimes = mAppConfigUtil.mAppConfigBean.getTtsPlayDelayTimes();
|
||||
metTTSPlayDelayTimes = findViewById(R.id.activityappsettingsEditText1);
|
||||
metTTSPlayDelayTimes.setText(Integer.toString(nTtsPlayDelayTimes / 1000));
|
||||
|
||||
// 初始化标题栏
|
||||
mAToolbar = findViewById(R.id.activityappsettingsAToolbar1);
|
||||
mAToolbar.setSubtitle(getString(R.string.activity_name_appsettings));
|
||||
setActionBar(mAToolbar);
|
||||
|
||||
metPhoneMergePrefix = findViewById(R.id.activityappsettingsEditText2);
|
||||
metPhoneMergePrefix.setText(mAppConfigUtil.mAppConfigBean.getCountryCode());
|
||||
|
||||
mswMergePrefixPhone = findViewById(R.id.activityappsettingsSwitch1);
|
||||
mswMergePrefixPhone.setChecked(mAppConfigUtil.mAppConfigBean.isMergeCountryCodePrefix());
|
||||
|
||||
mswSMSRecycleProtectMode = findViewById(R.id.activityappsettingsSwitch3);
|
||||
mswSMSRecycleProtectMode.setChecked(mAppConfigUtil.mAppConfigBean.isSMSRecycleProtectMode());
|
||||
|
||||
//metProtectModerRefuseChars = findViewById(R.id.activityappsettingsEditText3);
|
||||
//metProtectModerRefuseChars.setText(mAppConfigUtil.mAppConfigBean.getProtectModerRefuseChars());
|
||||
mszProtectModerRefuseChars = mAppConfigUtil.mAppConfigBean.getProtectModerRefuseChars();
|
||||
|
||||
metProtectModerReplaceChars = findViewById(R.id.activityappsettingsEditText4);
|
||||
metProtectModerReplaceChars.setText(mAppConfigUtil.mAppConfigBean.getProtectModerReplaceChars());
|
||||
|
||||
mRadioGroupRecycleBin = findViewById(R.id.activityappsettingsRadioGroup1);
|
||||
if (mAppConfigUtil.mAppConfigBean.getRecycleBinClass().equals("SMSRecycle2Activity")) {
|
||||
mRadioGroupRecycleBin.check(R.id.activityappsettingsRadioButton2);
|
||||
} else {
|
||||
mRadioGroupRecycleBin.check(R.id.activityappsettingsRadioButton1);
|
||||
}
|
||||
|
||||
mAOHPCTCSeekBar = findViewById(R.id.activityappsettingsAOHPCTCSeekBar1);
|
||||
mAOHPCTCSeekBar.setThumb(getDrawable(R.drawable.cursor_pointer));
|
||||
mAOHPCTCSeekBar.setThumbOffset(0);
|
||||
mAOHPCTCSeekBar.setOnOHPCListener(new AOHPCTCSeekBar.OnOHPCListener(){
|
||||
|
||||
@Override
|
||||
public void onOHPCommit() {
|
||||
mAppConfigUtil.reLoadConfig();
|
||||
mAppConfigUtil.mAppConfigBean.setIsSMSRecycleProtectMode(mswSMSRecycleProtectMode.isChecked());
|
||||
if (mRadioGroupRecycleBin.getCheckedRadioButtonId() == R.id.activityappsettingsRadioButton2) {
|
||||
mAppConfigUtil.mAppConfigBean.setRecycleBinClass("SMSRecycle2Activity");
|
||||
} else {
|
||||
mAppConfigUtil.mAppConfigBean.setRecycleBinClass("SMSRecycleActivity");
|
||||
}
|
||||
//mAppConfigUtil.mAppConfigBean.setProtectModerRefuseChars(metProtectModerRefuseChars.getText().toString());
|
||||
mAppConfigUtil.mAppConfigBean.setProtectModerRefuseChars(mszProtectModerRefuseChars);
|
||||
mAppConfigUtil.mAppConfigBean.setProtectModerReplaceChars(metProtectModerReplaceChars.getText().toString());
|
||||
mAppConfigUtil.mAppConfigBean.setCountryCode(metPhoneMergePrefix.getText().toString());
|
||||
mAppConfigUtil.mAppConfigBean.setIsMergeCountryCodePrefix(mswMergePrefixPhone.isChecked());
|
||||
int nTtsPlayDelayTimes = 1000 * Integer.parseInt(metTTSPlayDelayTimes.getText().toString());
|
||||
mAppConfigUtil.mAppConfigBean.setTtsPlayDelayTimes(nTtsPlayDelayTimes);
|
||||
mAppConfigUtil.saveConfig();
|
||||
Toast.makeText(getApplication(), "App config data is saved.", Toast.LENGTH_SHORT).show();
|
||||
//LogUtils.d(TAG, "TTS Play Delay Times is setting to : " + Integer.toString(mAppConfigData.getTtsPlayDelayTimes()));Toast.makeText(getApplication(), "onOHPCommit", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
public void onOpenSystemDefaultAppSettings(View view) {
|
||||
Intent intent = new Intent(Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
public void onCheckAndGetAppPermission(View view) {
|
||||
//LogUtils.d(TAG, "onCheckAndGetAppPermission");
|
||||
if (PermissionUtil.checkAndGetAppPermission(this)) {
|
||||
Toast.makeText(getApplication(), "应用已获得所需权限。", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
public void onAddTTSSupport(View view) {
|
||||
try {
|
||||
// 1. 创建Intent,Action为“打开网页”
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
// 2. 设置要跳转的URL
|
||||
intent.setData(Uri.parse(XUNFEI_YUJI_DOWNLOAD_URL));
|
||||
// 3. 确保Intent可被解析(避免无浏览器时崩溃)
|
||||
if (intent.resolveActivity(getPackageManager()) != null) {
|
||||
startActivity(intent); // 跳转至浏览器打开下载页
|
||||
} else {
|
||||
// 无浏览器时的提示
|
||||
Toast.makeText(this, "未找到浏览器应用,请安装后重试", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(this, "无法打开下载页面,请稍后再试", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
public void onCharsetRefuseEditDialog(View view) {
|
||||
CharsetRefuseEditDialog dlg = new CharsetRefuseEditDialog(this, new CharsetRefuseEditDialog.OnTextConfirmListener(){
|
||||
@Override
|
||||
public void onTextConfirmed(String editText) {
|
||||
//ToastUtils.show(editText);
|
||||
mszProtectModerRefuseChars = editText;
|
||||
}
|
||||
}, mszProtectModerRefuseChars);
|
||||
dlg.show();
|
||||
}
|
||||
|
||||
public void onTTSFloatSettingsActivity(View view) {
|
||||
Intent intent = new Intent(this, TTSFloatSettingsActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,375 @@
|
||||
package cc.winboll.studio.mymessagemanager.activitys;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||
* @Date 2025/08/30 14:32
|
||||
* @Describe 联系人查询与短信发送窗口
|
||||
*/
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.SimpleAdapter;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toolbar;
|
||||
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
|
||||
import cc.winboll.studio.libaes.views.AOHPCTCSeekBar;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.ToastUtils;
|
||||
import cc.winboll.studio.mymessagemanager.R;
|
||||
import cc.winboll.studio.mymessagemanager.beans.PhoneBean;
|
||||
import cc.winboll.studio.mymessagemanager.utils.PhoneUtil;
|
||||
import cc.winboll.studio.mymessagemanager.utils.SMSUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import android.app.Activity;
|
||||
|
||||
public class ComposeSMSActivity extends WinBoLLActivity implements IWinBoLLActivity {
|
||||
|
||||
public static String TAG = "ComposeSMSActivity";
|
||||
public static String EXTRA_SMSBODY = "sms_body";
|
||||
private static final String MAP_NAME = "NAME";
|
||||
private static final String MAP_PHONE = "PHONE";
|
||||
|
||||
private String mszSMSBody;
|
||||
private String mszScheme;
|
||||
private String mszPhoneTo;
|
||||
private TextView mtvTOName;
|
||||
private EditText metTONameSearch;
|
||||
private EditText metTO;
|
||||
private EditText metSMSBody;
|
||||
private SimpleAdapter mSimpleAdapter;
|
||||
private List<Map<String, Object>> mAdapterData = new ArrayList<Map<String, Object>>();
|
||||
private ListView mlvContracts;
|
||||
private List<PhoneBean> mListPhoneBeanContracts;
|
||||
private Toolbar mToolbar;
|
||||
private AOHPCTCSeekBar mAOHPCTCSeekBar;
|
||||
private RelativeLayout mrlContracts;
|
||||
|
||||
@Override
|
||||
public Activity getActivity() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
LogUtils.d(TAG, "onCreate");
|
||||
setContentView(R.layout.activity_composesms);
|
||||
|
||||
// 初始化Intent数据(增加空判断,避免NullPointerException)
|
||||
Intent intent = getIntent();
|
||||
if (intent != null) {
|
||||
mszSMSBody = intent.getStringExtra(EXTRA_SMSBODY);
|
||||
if (intent.getData() != null) {
|
||||
mszScheme = intent.getData().getScheme();
|
||||
mszPhoneTo = intent.getData().getSchemeSpecificPart();
|
||||
}
|
||||
}
|
||||
|
||||
// 校验启动方式,非smsto则退出
|
||||
if (mszScheme == null || !"smsto".equals(mszScheme)) {
|
||||
ToastUtils.show("不支持的启动方式");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
initView();
|
||||
initAdapter(null); // 初始加载所有联系人
|
||||
setListViewPrePositionByPhone();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
// 初始化标题栏
|
||||
mToolbar = (Toolbar) findViewById(R.id.activitycomposesmsASupportToolbar1);
|
||||
mToolbar.setSubtitle(getString(R.string.activity_name_composesms));
|
||||
setActionBar(mToolbar);
|
||||
|
||||
// 初始化联系人姓名显示和搜索栏
|
||||
mtvTOName = (TextView) findViewById(R.id.activitycomposesmsTextView2);
|
||||
mrlContracts = (RelativeLayout) findViewById(R.id.activitycomposesmsRelativeLayout1);
|
||||
metTONameSearch = (EditText) findViewById(R.id.activitycomposesmsEditText2);
|
||||
|
||||
// 姓名搜索框文本变化监听
|
||||
metTONameSearch.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
metTO.setText(""); // 清空号码输入框,避免冲突
|
||||
String input = s == null ? "" : s.toString().trim();
|
||||
if (input.isEmpty()) {
|
||||
initAdapter(null); // 空搜索时显示所有联系人
|
||||
} else {
|
||||
setListViewPrePositionByName(); // 按姓名搜索
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
// 无操作
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
// 无操作
|
||||
}
|
||||
});
|
||||
|
||||
// 初始化联系人列表(关键:设置单选模式,确保选中状态生效)
|
||||
mlvContracts = (ListView) findViewById(R.id.activitycomposesmsListView1);
|
||||
mlvContracts.setChoiceMode(ListView.CHOICE_MODE_SINGLE); // 开启单选,与布局中一致
|
||||
|
||||
// 初始化号码输入框(核心:优化文本变化监听逻辑)
|
||||
metTO = (EditText) findViewById(R.id.activitycomposesmsEditText1);
|
||||
if (mszPhoneTo != null) {
|
||||
metTO.setText(mszPhoneTo);
|
||||
}
|
||||
metTO.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
mtvTOName.setText(""); // 清空姓名显示
|
||||
String inputPhone = s == null ? "" : s.toString().trim();
|
||||
|
||||
if (inputPhone.isEmpty()) {
|
||||
// 输入为空时,显示所有联系人
|
||||
initAdapter(null);
|
||||
} else {
|
||||
// 输入非空时,按号码搜索并更新列表(无结果则清空)
|
||||
filterListByPhone(inputPhone);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
// 无操作
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
// 无操作
|
||||
}
|
||||
});
|
||||
|
||||
// 初始化发送控件
|
||||
mAOHPCTCSeekBar = (AOHPCTCSeekBar) findViewById(R.id.viewsmssendpart1AOHPCTCSeekBar1);
|
||||
Drawable thumbDrawable = getResources().getDrawable(R.drawable.ic_message); // Java 7兼容写法
|
||||
mAOHPCTCSeekBar.setThumb(thumbDrawable);
|
||||
mAOHPCTCSeekBar.setThumbOffset(20);
|
||||
mAOHPCTCSeekBar.setOnOHPCListener(new AOHPCTCSeekBar.OnOHPCListener() {
|
||||
@Override
|
||||
public void onOHPCommit() {
|
||||
sendSMS();
|
||||
}
|
||||
});
|
||||
|
||||
// 初始化短信内容输入框
|
||||
TextView tvAOHPCTCSeekBarMSG = (TextView) findViewById(R.id.viewsmssendpart1TextView1);
|
||||
tvAOHPCTCSeekBarMSG.setText(R.string.msg_100sendmsg);
|
||||
metSMSBody = (EditText) findViewById(R.id.viewsmssendpart1EditText1);
|
||||
if (mszSMSBody != null) {
|
||||
metSMSBody.setText(mszSMSBody);
|
||||
}
|
||||
}
|
||||
|
||||
// 核心优化:根据输入号码筛选列表(无结果则显示空列表,优化选中逻辑)
|
||||
private void filterListByPhone(String inputPhone) {
|
||||
PhoneUtil phoneUtil = new PhoneUtil(this);
|
||||
List<PhoneBean> allContacts = phoneUtil.getPhoneList();
|
||||
List<PhoneBean> matchedContacts = new ArrayList<PhoneBean>();
|
||||
|
||||
// 遍历所有联系人,匹配包含输入号码的联系人
|
||||
for (PhoneBean contact : allContacts) {
|
||||
if (contact.getTelPhone().contains(inputPhone)
|
||||
|| phoneUtil.isTheSamePhoneNumber(contact.getTelPhone(), inputPhone)) {
|
||||
matchedContacts.add(contact);
|
||||
}
|
||||
}
|
||||
|
||||
LogUtils.d(TAG, "号码搜索:输入'" + inputPhone + "', 匹配" + matchedContacts.size() + "个结果");
|
||||
|
||||
// 用筛选结果更新列表(无结果则传入空列表)
|
||||
initAdapter(matchedContacts.isEmpty() ? new ArrayList<PhoneBean>() : matchedContacts);
|
||||
|
||||
// 定位并选中匹配项(如果有)
|
||||
if (!matchedContacts.isEmpty()) {
|
||||
boolean isFound = false;
|
||||
for (int i = 0; i < matchedContacts.size(); i++) {
|
||||
PhoneBean item = matchedContacts.get(i);
|
||||
// 精确匹配号码(兼容区域码格式)
|
||||
if (phoneUtil.isTheSamePhoneNumber(item.getTelPhone(), inputPhone)) {
|
||||
mtvTOName.setText(item.getName());
|
||||
// 关键:先滚动到目标位置,再设置选中状态
|
||||
mlvContracts.setSelection(i);
|
||||
// 主动设置选中(确保样式生效,兼容部分系统)
|
||||
mlvContracts.setItemChecked(i, true);
|
||||
LogUtils.d(TAG, String.format("%s 匹配 %s,选中位置:%d", inputPhone, item.getTelPhone(), i));
|
||||
isFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 若未精确匹配,选中第一个结果
|
||||
/*if (!isFound) {
|
||||
mlvContracts.setSelection(0);
|
||||
mlvContracts.setItemChecked(0, true);
|
||||
mtvTOName.setText(matchedContacts.get(0).getName());
|
||||
}*/
|
||||
} else {
|
||||
mtvTOName.setText(""); // 无结果时清空姓名显示
|
||||
}
|
||||
}
|
||||
|
||||
// 根据姓名搜索联系人
|
||||
private void setListViewPrePositionByName() {
|
||||
String searchName = metTONameSearch.getText().toString().trim();
|
||||
PhoneUtil phoneUtil = new PhoneUtil(this);
|
||||
List<PhoneBean> matchedContacts = phoneUtil.getPhonesByName(searchName);
|
||||
initAdapter(matchedContacts);
|
||||
if (!matchedContacts.isEmpty()) {
|
||||
// 选中第一个结果并设置样式
|
||||
mlvContracts.setSelection(0);
|
||||
mlvContracts.setItemChecked(0, true);
|
||||
}
|
||||
}
|
||||
|
||||
// 初始定位号码对应的联系人
|
||||
private void setListViewPrePositionByPhone() {
|
||||
String inputPhone = metTO.getText().toString().trim();
|
||||
if (inputPhone.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
filterListByPhone(inputPhone); // 复用筛选逻辑
|
||||
}
|
||||
|
||||
// 获取号码匹配的位置(兼容旧逻辑)
|
||||
private int getContractsDataPrePositionByPhone(String szPhone) {
|
||||
if (mListPhoneBeanContracts == null || mListPhoneBeanContracts.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
for (int i = 0; i < mListPhoneBeanContracts.size(); i++) {
|
||||
PhoneBean bean = mListPhoneBeanContracts.get(i);
|
||||
if (bean.getTelPhone().compareTo(szPhone) >= 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 获取姓名匹配的位置(兼容旧逻辑)
|
||||
private int getContractsDataPrePositionByName(String szName) {
|
||||
if (mListPhoneBeanContracts == null || mListPhoneBeanContracts.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
for (int i = 0; i < mListPhoneBeanContracts.size(); i++) {
|
||||
if (mListPhoneBeanContracts.get(i).getName().startsWith(szName)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 初始化或更新列表适配器
|
||||
private void initAdapter(List<PhoneBean> initData) {
|
||||
mAdapterData.clear(); // 清空旧数据
|
||||
final PhoneUtil phoneUtil = new PhoneUtil(this);
|
||||
|
||||
// 确定数据源:传入的筛选数据或所有联系人
|
||||
if (initData != null) {
|
||||
mListPhoneBeanContracts = initData;
|
||||
} else {
|
||||
mListPhoneBeanContracts = phoneUtil.getPhoneList();
|
||||
}
|
||||
|
||||
// 转换数据为SimpleAdapter所需格式
|
||||
if (mListPhoneBeanContracts != null) {
|
||||
for (PhoneBean bean : mListPhoneBeanContracts) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put(MAP_NAME, bean.getName());
|
||||
map.put(MAP_PHONE, bean.getTelPhone());
|
||||
mAdapterData.add(map);
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化或更新适配器
|
||||
if (mSimpleAdapter == null) {
|
||||
mSimpleAdapter = new SimpleAdapter(
|
||||
ComposeSMSActivity.this,
|
||||
mAdapterData,
|
||||
R.layout.listview_contracts,
|
||||
new String[]{MAP_NAME, MAP_PHONE},
|
||||
new int[]{R.id.listviewcontractsTextView1, R.id.listviewcontractsTextView2}
|
||||
);
|
||||
mSimpleAdapter.setDropDownViewResource(R.layout.listview_contracts);
|
||||
mlvContracts.setAdapter(mSimpleAdapter);
|
||||
|
||||
// 列表项点击事件:点击时主动设置选中状态,确保样式突显
|
||||
mlvContracts.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
if (position < mAdapterData.size()) {
|
||||
// 1. 主动设置当前项为选中状态
|
||||
mlvContracts.setItemChecked(position, true);
|
||||
// 2. 更新号码输入框和姓名显示
|
||||
String phone = mAdapterData.get(position).get(MAP_PHONE).toString();
|
||||
metTO.setText(phone);
|
||||
mtvTOName.setText(phoneUtil.getNameByPhone(phone));
|
||||
// 3. 滚动到点击位置(确保可见)
|
||||
mlvContracts.setSelection(position);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 列表项选中状态变化监听(可选,增强选中反馈)
|
||||
mlvContracts.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
// 选中时可添加额外反馈(如改变文本颜色,可选)
|
||||
if (view != null) {
|
||||
TextView tvName = (TextView) view.findViewById(R.id.listviewcontractsTextView1);
|
||||
TextView tvPhone = (TextView) view.findViewById(R.id.listviewcontractsTextView2);
|
||||
if (tvName != null) tvName.setTextColor(getResources().getColor(R.color.white));
|
||||
if (tvPhone != null) tvPhone.setTextColor(getResources().getColor(R.color.white));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
// 未选中时无操作
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// 数据更新时,先取消所有旧选中状态,再通知适配器刷新
|
||||
mlvContracts.clearChoices();
|
||||
mSimpleAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
// 发送短信逻辑
|
||||
private void sendSMS() {
|
||||
String phoneTo = metTO.getText().toString().trim();
|
||||
if (phoneTo.isEmpty()) {
|
||||
ToastUtils.show("没有设置接收号码。");
|
||||
return;
|
||||
}
|
||||
String smsBody = metSMSBody.getText().toString().trim();
|
||||
if (smsBody.isEmpty()) {
|
||||
ToastUtils.show("没有消息内容可发送。");
|
||||
return;
|
||||
}
|
||||
if (SMSUtil.sendMessageByInterface2(ComposeSMSActivity.this, phoneTo, smsBody)) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,346 @@
|
||||
package cc.winboll.studio.mymessagemanager.activitys;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ScrollView;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import cc.winboll.studio.libaes.utils.AESThemeUtil;
|
||||
import cc.winboll.studio.libaes.utils.DevelopUtils;
|
||||
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
|
||||
import cc.winboll.studio.libaes.views.ADsBannerView;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.mymessagemanager.App;
|
||||
import cc.winboll.studio.mymessagemanager.BuildConfig;
|
||||
import cc.winboll.studio.mymessagemanager.R;
|
||||
import cc.winboll.studio.mymessagemanager.activitys.MainActivity;
|
||||
import cc.winboll.studio.mymessagemanager.adapters.PhoneArrayAdapter;
|
||||
import cc.winboll.studio.mymessagemanager.services.MainService;
|
||||
import cc.winboll.studio.mymessagemanager.unittest.UnitTestActivity;
|
||||
import cc.winboll.studio.mymessagemanager.utils.AppConfigUtil;
|
||||
import cc.winboll.studio.mymessagemanager.utils.AppGoToSettingsUtil;
|
||||
import cc.winboll.studio.mymessagemanager.utils.PermissionUtil;
|
||||
import cc.winboll.studio.mymessagemanager.utils.SMSUtil;
|
||||
import cc.winboll.studio.mymessagemanager.utils.ViewUtil;
|
||||
import cc.winboll.studio.mymessagemanager.views.ConfirmSwitchView;
|
||||
import cc.winboll.studio.mymessagemanager.views.PhoneListViewForScrollView;
|
||||
import com.baoyz.widget.PullRefreshLayout;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class MainActivity extends WinBoLLActivity {
|
||||
|
||||
public final static String TAG = "MainActivity";
|
||||
|
||||
public static final int ACTIVITY_RESULT_APP_SETTINGS = -1;
|
||||
|
||||
public final static int MSG_RELOADSMS = 0;
|
||||
|
||||
public static final int PERMISSION_SETTING_FOR_RESULT = 0;
|
||||
public static final int MY_PERMISSIONS_REQUEST = 0;
|
||||
|
||||
static MainActivity _mMainActivity;
|
||||
ADsBannerView mADsBannerView;
|
||||
|
||||
//LogView mLogView;
|
||||
AppConfigUtil mAppConfigUtil;
|
||||
ConfirmSwitchView msvEnableService;
|
||||
ConfirmSwitchView msvOnlyReceiveContacts;
|
||||
ConfirmSwitchView msvEnableTTS;
|
||||
ConfirmSwitchView msvEnableTTSRuleMode;
|
||||
PhoneListViewForScrollView mListViewPhone;
|
||||
Toolbar mToolbar;
|
||||
PhoneArrayAdapter mPhoneArrayAdapter;
|
||||
AppGoToSettingsUtil mAppGoToSettingsUtil;
|
||||
String[] mPermissionList = {Manifest.permission.READ_CONTACTS,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.READ_SMS};
|
||||
ArrayList<String> listPerms;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
_mMainActivity = MainActivity.this;
|
||||
|
||||
// 米盟广告栏
|
||||
mADsBannerView = findViewById(R.id.adsbanner);
|
||||
|
||||
mAppConfigUtil = AppConfigUtil.getInstance(this);
|
||||
initView();
|
||||
|
||||
// 调用调试检查函数
|
||||
onOnceAndroidStory(null);
|
||||
}
|
||||
|
||||
//
|
||||
// 这是一个测试函数,
|
||||
// 用于调试读取 string.xml string-array使用。
|
||||
//
|
||||
public void onOnceAndroidStory(View view) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
// 获取strings.xml文件中的tab_names数组
|
||||
String[] tab_names = getResources().getStringArray(R.array.strings_OnceAndroidStory);
|
||||
// 这里R.array.tab_names是你在XML文件中定义的数组资源ID
|
||||
// 例如,在strings.xml中可能这样定义:
|
||||
/*/ <!-- strings.xml -->
|
||||
<resources>
|
||||
<string-array name="tab_names">
|
||||
<item>Tab 1</item>
|
||||
<item>Tab 2</item>
|
||||
<item>Tab 3</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
*/
|
||||
// 现在你可以遍历这个数组来访问每个元素
|
||||
for (int i = 0; i < tab_names.length; i++) {
|
||||
// 创建Random实例并传入任意非负种子(这里是1)
|
||||
java.util.Random r = new java.util.Random(1);
|
||||
// 调用nextInt(6),范围是0到5(包括0和5),加1后得到1到5
|
||||
int randomNum = r.nextInt(6) + 1;
|
||||
System.out.println("Random number between 1 and 5: " + randomNum);
|
||||
LogUtils.d("OnceAndroidStory", tab_names[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void scrollScrollView() {
|
||||
ScrollView sv = findViewById(R.id.activitymainScrollView1);
|
||||
ViewUtil.scrollScrollView(sv);
|
||||
}
|
||||
|
||||
void genTestData() {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
SMSUtil.saveReceiveSms(this, "13172887736", "调试阶段生成的短信" + Integer.toString(i), "0", -1, "inbox");
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// 初始化视图控件
|
||||
//
|
||||
void initView() {
|
||||
// 设置调试日志
|
||||
// mLogView = findViewById(R.id.logview);
|
||||
// mLogView.start();
|
||||
|
||||
// 设置消息处理函数
|
||||
setOnActivityMessageReceived(mIOnActivityMessageReceived);
|
||||
|
||||
// 设置标题栏
|
||||
mToolbar = findViewById(R.id.activitymainASupportToolbar1);
|
||||
mToolbar.setSubtitle(getString(R.string.activity_name_main));
|
||||
setSupportActionBar(mToolbar);
|
||||
|
||||
boolean isEnableService = mAppConfigUtil.mAppConfigBean.isEnableService();
|
||||
msvEnableService = findViewById(R.id.activitymainSwitchView1);
|
||||
msvEnableService.setChecked(isEnableService);
|
||||
msvEnableService.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
boolean isEnable = ((ConfirmSwitchView)v).isChecked();
|
||||
mAppConfigUtil.reLoadConfig();
|
||||
mAppConfigUtil.mAppConfigBean.setIsEnableService(isEnable);
|
||||
mAppConfigUtil.saveConfig();
|
||||
initService(isEnable);
|
||||
}
|
||||
});
|
||||
|
||||
boolean isOnlyReceiveContacts = mAppConfigUtil.mAppConfigBean.isEnableOnlyReceiveContacts();
|
||||
msvOnlyReceiveContacts = findViewById(R.id.activitymainSwitchView2);
|
||||
msvOnlyReceiveContacts.setChecked(isOnlyReceiveContacts);
|
||||
msvOnlyReceiveContacts.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
boolean isEnable = ((ConfirmSwitchView)v).isChecked();
|
||||
mAppConfigUtil.reLoadConfig();
|
||||
mAppConfigUtil.mAppConfigBean.setIsEnableOnlyReceiveContacts(isEnable);
|
||||
mAppConfigUtil.saveConfig();
|
||||
}
|
||||
});
|
||||
|
||||
boolean isEnableTTS = mAppConfigUtil.mAppConfigBean.isEnableTTS();
|
||||
msvEnableTTS = findViewById(R.id.activitymainSwitchView3);
|
||||
msvEnableTTS.setChecked(isEnableTTS);
|
||||
msvEnableTTS.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
boolean isEnable = ((ConfirmSwitchView)v).isChecked();
|
||||
mAppConfigUtil.reLoadConfig();
|
||||
mAppConfigUtil.mAppConfigBean.setIsEnableTTS(isEnable);
|
||||
mAppConfigUtil.saveConfig();
|
||||
}
|
||||
});
|
||||
|
||||
boolean isEnableTTSRuleMode = mAppConfigUtil.mAppConfigBean.isEnableTTSRuleMode();
|
||||
msvEnableTTSRuleMode = findViewById(R.id.activitymainSwitchView4);
|
||||
msvEnableTTSRuleMode.setChecked(isEnableTTSRuleMode);
|
||||
msvEnableTTSRuleMode.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
boolean isEnable = ((ConfirmSwitchView)v).isChecked();
|
||||
mAppConfigUtil.reLoadConfig();
|
||||
mAppConfigUtil.mAppConfigBean.setIsEnableTTSRuleMode(isEnable);
|
||||
mAppConfigUtil.saveConfig();
|
||||
}
|
||||
});
|
||||
|
||||
initService(isEnableService);
|
||||
|
||||
// 短信发送窗口按钮
|
||||
Button btnSendSMS = findViewById(R.id.activitymainButton1);
|
||||
btnSendSMS.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Uri uri = Uri.parse("smsto:");
|
||||
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
|
||||
it.putExtra("sms_body", "");
|
||||
startActivity(it);
|
||||
}
|
||||
});
|
||||
|
||||
mListViewPhone = (PhoneListViewForScrollView) findViewById(R.id.activitymainListView1);
|
||||
//准备数据
|
||||
mPhoneArrayAdapter = new PhoneArrayAdapter(MainActivity.this);
|
||||
|
||||
final PullRefreshLayout layout = (PullRefreshLayout) findViewById(R.id.activitymainPullRefreshLayout1);
|
||||
//将适配器加载到控件中
|
||||
mListViewPhone.setAdapter(mPhoneArrayAdapter);
|
||||
|
||||
// listen refresh event
|
||||
layout.setOnRefreshListener(new PullRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
// start refresh
|
||||
reloadSMS();
|
||||
layout.setRefreshing(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void initService(boolean isEnableService) {
|
||||
if (isEnableService) {
|
||||
Intent service = new Intent(this, MainService.class);
|
||||
startService(service);
|
||||
} else {
|
||||
Intent service = new Intent(this, MainService.class);
|
||||
stopService(service);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// 定义应用内消息处理函数
|
||||
//
|
||||
IOnActivityMessageReceived mIOnActivityMessageReceived = new IOnActivityMessageReceived(){
|
||||
|
||||
@Override
|
||||
public void onActivityMessageReceived(Message msg) {
|
||||
switch (msg.arg1) {
|
||||
case MSG_RELOADSMS : {
|
||||
LogUtils.d(TAG, "MSG_RELOADSMS");
|
||||
if (PermissionUtil.checkAppPermission(MainActivity.this)) {
|
||||
mPhoneArrayAdapter.loadData();
|
||||
mPhoneArrayAdapter.notifyDataSetChanged();
|
||||
} else {
|
||||
LogUtils.i(TAG, "遇到应用权限问题,请打开应用设置检查一下应用权限。");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean onCreatePanelMenu(int featureId, Menu menu) {
|
||||
return super.onCreatePanelMenu(featureId, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (mADsBannerView != null) {
|
||||
mADsBannerView.releaseAdResources();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
reloadSMS();
|
||||
if (mADsBannerView != null) {
|
||||
mADsBannerView.resumeADs(MainActivity.this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.toolbar_main_first, menu);
|
||||
// 主题菜单
|
||||
AESThemeUtil.inflateMenu(this, menu);
|
||||
// 调试工具菜单
|
||||
if (App.isDebugging()) {
|
||||
DevelopUtils.inflateMenu(this, menu);
|
||||
getMenuInflater().inflate(R.menu.toolbar_main_debug, menu);
|
||||
}
|
||||
getMenuInflater().inflate(R.menu.toolbar_main_last, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void reloadSMS() {
|
||||
if (_mMainActivity != null) {
|
||||
Message msg = new Message();
|
||||
msg.arg1 = MSG_RELOADSMS;
|
||||
_mMainActivity.sendActivityMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int nItemId = item.getItemId();
|
||||
int menuItemId = item.getItemId();
|
||||
if (AESThemeUtil.onAppThemeItemSelected(this, item)) {
|
||||
recreate();
|
||||
} if (DevelopUtils.onDevelopItemSelected(this, item)) {
|
||||
LogUtils.d(TAG, String.format("onOptionsItemSelected item.getItemId() %d ", item.getItemId()));
|
||||
} else if (nItemId == R.id.app_ttsrule) {
|
||||
Intent i = new Intent(MainActivity.this, TTSPlayRuleActivity.class);
|
||||
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(i);
|
||||
} else if (nItemId == R.id.app_smsrule) {
|
||||
Intent i = new Intent(MainActivity.this, SMSReceiveRuleActivity.class);
|
||||
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(i);
|
||||
} else if (nItemId == R.id.app_appsettings) {
|
||||
Intent i = new Intent(MainActivity.this, AppSettingsActivity.class);
|
||||
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(i);
|
||||
} else if (nItemId == R.id.app_unittest) {
|
||||
Intent i = new Intent(MainActivity.this, UnitTestActivity.class);
|
||||
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(i);
|
||||
} else if (nItemId == R.id.app_about) {
|
||||
Intent i = new Intent(MainActivity.this, AboutActivity.class);
|
||||
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(i);
|
||||
} else if (nItemId == R.id.app_smsrecycle) {
|
||||
Class<?> recycleClass;
|
||||
if (mAppConfigUtil.mAppConfigBean.getRecycleBinClass().equals("SMSRecycle2Activity")) {
|
||||
recycleClass = SMSRecycle2Activity.class;
|
||||
} else {
|
||||
recycleClass = SMSRecycleActivity.class;
|
||||
}
|
||||
Intent i = new Intent(MainActivity.this, recycleClass);
|
||||
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(i);
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,281 @@
|
||||
package cc.winboll.studio.mymessagemanager.activitys;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.widget.Toolbar;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
|
||||
import cc.winboll.studio.libaes.views.AOHPCTCSeekBar;
|
||||
import cc.winboll.studio.mymessagemanager.R;
|
||||
import cc.winboll.studio.mymessagemanager.adapters.SMSArrayAdapter;
|
||||
import cc.winboll.studio.mymessagemanager.utils.AddressUtils;
|
||||
import cc.winboll.studio.mymessagemanager.utils.SMSUtil;
|
||||
import cc.winboll.studio.mymessagemanager.utils.ViewUtil;
|
||||
import cc.winboll.studio.mymessagemanager.views.BottomPositionFixedScrollView;
|
||||
import cc.winboll.studio.mymessagemanager.views.SMSListViewForScrollView;
|
||||
import android.app.Activity;
|
||||
|
||||
public class SMSActivity extends WinBoLLActivity implements IWinBoLLActivity {
|
||||
public static String TAG = "SMSActivity";
|
||||
public static final String ACTION_NOTIFY_SMS_CHANGED = "cc.winboll.studio.mymessagemanager.activitys.SMSActivity.ACTION_NOTIFY_SMS_CHANGED";
|
||||
public static final String EXTRA_PHONE = "Phone";
|
||||
final static int MSG_SET_FOCUS = 0;
|
||||
|
||||
SMSListViewForScrollView mlvSMS;
|
||||
Toolbar mToolbar;
|
||||
String mszPhoneTo;
|
||||
SMSArrayAdapter mSMSArrayAdapter;
|
||||
BottomPositionFixedScrollView mScrollView1;
|
||||
EditText metSMSBody;
|
||||
SMSActivityBroadcastReceiver mSMSActivityBroadcastReceiver;
|
||||
Handler mSetFocusHandler;
|
||||
private boolean isImeVisible = false;
|
||||
|
||||
@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_sms);
|
||||
|
||||
initView();
|
||||
scrollScrollView();
|
||||
setupImeStatusListener();
|
||||
|
||||
// 新增:监听窗口加载完成,触发mScrollView1滚动到底部
|
||||
setupScrollToBottomAfterWindowLoaded();
|
||||
}
|
||||
|
||||
// 新增:窗口加载完成后让mScrollView1滚动到底部
|
||||
private void setupScrollToBottomAfterWindowLoaded() {
|
||||
final View rootView = findViewById(android.R.id.content);
|
||||
// 监听根布局绘制完成(窗口加载完成的标志)
|
||||
rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
// 滚动到底部
|
||||
mScrollView1.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mScrollView1.fullScroll(ScrollView.FOCUS_DOWN);
|
||||
}
|
||||
});
|
||||
|
||||
// 移除监听,避免重复触发
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
rootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||
} else {
|
||||
rootView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setupImeStatusListener() {
|
||||
final View rootView = findViewById(android.R.id.content);
|
||||
rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
int rootViewHeight = rootView.getHeight();
|
||||
int screenHeight = getResources().getDisplayMetrics().heightPixels;
|
||||
int imeThreshold = dp2px(200);
|
||||
|
||||
boolean currentImeVisible = (screenHeight - rootViewHeight) > imeThreshold;
|
||||
|
||||
if (currentImeVisible != isImeVisible) {
|
||||
isImeVisible = currentImeVisible;
|
||||
setupScrollView1Height();
|
||||
if (!isImeVisible) {
|
||||
metSMSBody.clearFocus();
|
||||
}
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
rootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||
} else {
|
||||
rootView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
|
||||
}
|
||||
setupImeStatusListener();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private int dp2px(int dp) {
|
||||
return (int) (dp * getResources().getDisplayMetrics().density + 0.5f);
|
||||
}
|
||||
|
||||
/*static class MyHandler extends Handler {
|
||||
WeakReference<SMSActivity> mActivity;
|
||||
MyHandler(SMSActivity activity) {
|
||||
mActivity = new WeakReference<SMSActivity>(activity);
|
||||
}
|
||||
public void handleMessage(Message msg) {
|
||||
SMSActivity theActivity = mActivity.get();
|
||||
switch (msg.what) {
|
||||
case MSG_SET_FOCUS:
|
||||
theActivity.metSMSBody.setFocusable(true);
|
||||
theActivity.metSMSBody.requestFocus();
|
||||
theActivity.setupScrollView1Height();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
super.handleMessage(msg);
|
||||
}
|
||||
}*/
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(mSMSActivityBroadcastReceiver);
|
||||
}
|
||||
|
||||
void initView() {
|
||||
mszPhoneTo = getIntent().getStringExtra(EXTRA_PHONE);
|
||||
if (mszPhoneTo == null || mszPhoneTo.trim().equals("")) {
|
||||
finish();
|
||||
}
|
||||
|
||||
mToolbar = (Toolbar) findViewById(R.id.activitysmsASupportToolbar1);
|
||||
mToolbar.setSubtitle(getString(R.string.activity_name_smsinphone) + " < Phone : " + AddressUtils.getFormattedAddress(mszPhoneTo) + " >");
|
||||
setActionBar(mToolbar);
|
||||
|
||||
mScrollView1 = (BottomPositionFixedScrollView) findViewById(R.id.activitysmsScrollView1);
|
||||
|
||||
metSMSBody = (EditText) findViewById(R.id.viewsmssendpart1EditText1);
|
||||
metSMSBody.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
setupScrollView1Height();
|
||||
}
|
||||
});
|
||||
metSMSBody.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
||||
@Override
|
||||
public void onFocusChange(View v, boolean hasFocus) {
|
||||
setupScrollView1Height();
|
||||
}
|
||||
});
|
||||
|
||||
final AOHPCTCSeekBar aOHPCTCSeekBar = (AOHPCTCSeekBar) findViewById(R.id.viewsmssendpart1AOHPCTCSeekBar1);
|
||||
aOHPCTCSeekBar.setThumb(getDrawable(R.drawable.ic_message));
|
||||
aOHPCTCSeekBar.setThumbOffset(20);
|
||||
aOHPCTCSeekBar.setOnOHPCListener(new AOHPCTCSeekBar.OnOHPCListener() {
|
||||
@Override
|
||||
public void onOHPCommit() {
|
||||
sendSMS();
|
||||
}
|
||||
});
|
||||
|
||||
TextView tvAOHPCTCSeekBarMSG = (TextView) findViewById(R.id.viewsmssendpart1TextView1);
|
||||
tvAOHPCTCSeekBarMSG.setText(R.string.msg_100sendmsg);
|
||||
|
||||
mlvSMS = (SMSListViewForScrollView) findViewById(R.id.activitysmsSMSListViewForScrollView1);
|
||||
mSMSArrayAdapter = new SMSArrayAdapter(SMSActivity.this, mszPhoneTo);
|
||||
mlvSMS.setAdapter(mSMSArrayAdapter);
|
||||
|
||||
mlvSMS.setOnScrollListener(new AbsListView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrollStateChanged(AbsListView view, int scrollState) {}
|
||||
|
||||
@Override
|
||||
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
||||
if (firstVisibleItem + visibleItemCount == totalItemCount && totalItemCount > 0) {
|
||||
mSMSArrayAdapter.cancelMessageNotification();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
mSMSActivityBroadcastReceiver = new SMSActivityBroadcastReceiver();
|
||||
IntentFilter intentFilter = new IntentFilter(ACTION_NOTIFY_SMS_CHANGED);
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(mSMSActivityBroadcastReceiver, intentFilter);
|
||||
}
|
||||
|
||||
private void setupScrollView1Height() {
|
||||
mScrollView1.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final ScrollView scrollView2 = (ScrollView) findViewById(R.id.activitysmsScrollView2);
|
||||
final BottomPositionFixedScrollView scrollView1 = (BottomPositionFixedScrollView) findViewById(R.id.activitysmsScrollView1);
|
||||
final View includeView = findViewById(R.id.activitysmsinclude1);
|
||||
|
||||
scrollView2.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int scrollView2Height = scrollView2.getHeight();
|
||||
int includeHeight = includeView.getHeight();
|
||||
int targetHeight = Math.max(scrollView2Height - includeHeight, 0);
|
||||
|
||||
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) scrollView1.getLayoutParams();
|
||||
params.height = targetHeight;
|
||||
scrollView1.setLayoutParams(params);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
|
||||
public void updateSMSView() {
|
||||
mSMSArrayAdapter.reLoadSMSList(SMSActivity.this, mszPhoneTo);
|
||||
mSMSArrayAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
void scrollScrollView() {
|
||||
ViewUtil.scrollScrollView(mScrollView1);
|
||||
}
|
||||
|
||||
void sendSMS() {
|
||||
String szSMSBody = metSMSBody.getText().toString();
|
||||
if (szSMSBody.equals("")) {
|
||||
Toast.makeText(getApplication(), "没有消息内容可发送。", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (SMSUtil.sendMessageByInterface2(this, mszPhoneTo, szSMSBody)) {
|
||||
metSMSBody.setText("");
|
||||
metSMSBody.clearFocus();
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateSMSView();
|
||||
ViewUtil.scrollScrollView(mScrollView1);
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
class SMSActivityBroadcastReceiver extends BroadcastReceiver {
|
||||
public SMSActivityBroadcastReceiver() {}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (ACTION_NOTIFY_SMS_CHANGED.equals(intent.getAction())) {
|
||||
updateSMSView();
|
||||
ViewUtil.scrollScrollView(mScrollView1);
|
||||
} else {
|
||||
throw new IllegalStateException("Unexpected value: " + intent.getAction());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,244 @@
|
||||
package cc.winboll.studio.mymessagemanager.activitys;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2024/07/19 12:50:52
|
||||
* @Describe 短信匹配过滤规则设置窗口
|
||||
*/
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.Toast;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
|
||||
import cc.winboll.studio.mymessagemanager.App;
|
||||
import cc.winboll.studio.mymessagemanager.R;
|
||||
import cc.winboll.studio.mymessagemanager.activitys.SMSReceiveRuleActivity;
|
||||
import cc.winboll.studio.mymessagemanager.adapters.SMSAcceptRuleArrayAdapter;
|
||||
import cc.winboll.studio.mymessagemanager.beans.SMSAcceptRuleBean;
|
||||
import cc.winboll.studio.mymessagemanager.utils.FileUtil;
|
||||
import cc.winboll.studio.mymessagemanager.utils.SMSReceiveRuleUtil;
|
||||
import com.baoyz.widget.PullRefreshLayout;
|
||||
import android.app.Activity;
|
||||
|
||||
public class SMSReceiveRuleActivity extends WinBoLLActivity implements IWinBoLLActivity {
|
||||
|
||||
public static final String TAG = "SMSReceiveRuleActivity";
|
||||
|
||||
Context mContext;
|
||||
RecyclerView mRecyclerView;
|
||||
Toolbar mToolbar;
|
||||
RadioButton mrbAccept;
|
||||
RadioButton mrbRefuse;
|
||||
CheckBox mcbEnable;
|
||||
SMSAcceptRuleBean mSMSAcceptRuleBeanAdd;
|
||||
SMSAcceptRuleArrayAdapter mSMSAcceptRuleArrayAdapter;
|
||||
|
||||
@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_smsacceptrulesetting);
|
||||
mContext = SMSReceiveRuleActivity.this;
|
||||
initSMSAcceptRuleBeanAdd();
|
||||
// 初始化视图
|
||||
initView();
|
||||
}
|
||||
|
||||
//
|
||||
// 初始化视图
|
||||
//
|
||||
public void initView() {
|
||||
// 初始化标题栏
|
||||
mToolbar = findViewById(R.id.activitysmsacceptrulesettingASupportToolbar1);
|
||||
mToolbar.setSubtitle(getString(R.string.text_smsrule));
|
||||
setSupportActionBar(mToolbar);
|
||||
|
||||
mrbAccept = findViewById(R.id.activitysmsacceptrulesettingRadioButton1);
|
||||
mrbRefuse = findViewById(R.id.activitysmsacceptrulesettingRadioButton2);
|
||||
mcbEnable = findViewById(R.id.activitysmsacceptrulesettingCheckBox1);
|
||||
if (mSMSAcceptRuleBeanAdd.getRuleType() == SMSAcceptRuleBean.RuleType.ACCEPT) {
|
||||
mrbAccept.setChecked(true);
|
||||
mrbRefuse.setChecked(false);
|
||||
}
|
||||
if (mSMSAcceptRuleBeanAdd.getRuleType() == SMSAcceptRuleBean.RuleType.REFUSE) {
|
||||
mrbAccept.setChecked(false);
|
||||
mrbRefuse.setChecked(true);
|
||||
}
|
||||
mcbEnable.setChecked(mSMSAcceptRuleBeanAdd.isEnable());
|
||||
|
||||
Button btnAddSMSAcceptRule = findViewById(R.id.activitysmsacceptrulesettingButton1);
|
||||
btnAddSMSAcceptRule.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
EditText et = findViewById(R.id.activitysmsacceptrulesettingEditText1);
|
||||
String szRule = et.getText().toString().trim();
|
||||
if (szRule.equals("")) {
|
||||
Toast.makeText(getApplication(), "空字符串规则不能添加", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
mSMSAcceptRuleBeanAdd.setRuleData(et.getText().toString());
|
||||
mSMSAcceptRuleBeanAdd.setIsEnable(mcbEnable.isChecked());
|
||||
mSMSAcceptRuleBeanAdd.setRuleType(mrbRefuse.isChecked() ?SMSAcceptRuleBean.RuleType.REFUSE: SMSAcceptRuleBean.RuleType.ACCEPT);
|
||||
mSMSAcceptRuleArrayAdapter.addSMSAcceptRule(mSMSAcceptRuleBeanAdd);
|
||||
initSMSAcceptRuleBeanAdd();
|
||||
et.setText("");
|
||||
Toast.makeText(getApplication(), "已添加规则 : " + szRule, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 绑定控件
|
||||
mRecyclerView = findViewById(R.id.activitysmsacceptrulesettingRecyclerView1);
|
||||
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
|
||||
mRecyclerView.setLayoutManager(layoutManager);
|
||||
mSMSAcceptRuleArrayAdapter = new SMSAcceptRuleArrayAdapter(this);
|
||||
mRecyclerView.setAdapter(mSMSAcceptRuleArrayAdapter);
|
||||
|
||||
final PullRefreshLayout pullRefreshLayout = findViewById(R.id.activitysmsacceptrulesettingPullRefreshLayout1);
|
||||
pullRefreshLayout.setOnRefreshListener(new PullRefreshLayout.OnRefreshListener(){
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
pullRefreshLayout.setRefreshing(false);
|
||||
mSMSAcceptRuleArrayAdapter.loadConfigData();
|
||||
mSMSAcceptRuleArrayAdapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void initSMSAcceptRuleBeanAdd() {
|
||||
mSMSAcceptRuleBeanAdd = new SMSAcceptRuleBean(App.USER_ID, "", true, SMSAcceptRuleBean.RuleType.REFUSE, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
//return super.onCreateOptionsMenu(menu);
|
||||
getMenuInflater().inflate(R.menu.toolbar_rule, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int nItemId = item.getItemId();
|
||||
if (nItemId == R.id.item_rule_share) {
|
||||
//SMSReceiveRuleUtil smsAcceptRuleConfig = SMSReceiveRuleUtil.getInstance(this, false);
|
||||
SMSAcceptRuleBean beanTemp = new SMSAcceptRuleBean();
|
||||
String szConfigPath = beanTemp.getBeanListJsonFilePath(mContext);
|
||||
FileUtil.shareJSONFile(SMSReceiveRuleActivity.this, szConfigPath);
|
||||
} else if (nItemId == R.id.item_rule_reset) {
|
||||
showResetConfigDialog();
|
||||
} else if (nItemId == R.id.item_rule_clean) {
|
||||
showCleanConfigDialog();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
// 短信匹配过滤规则数据重置对话框
|
||||
//
|
||||
void showResetConfigDialog() {
|
||||
Dialog alertDialog = new AlertDialog.Builder(this).
|
||||
setTitle("确定重置?").
|
||||
setMessage("您确定重置短信接收规则为默认设置吗?").
|
||||
setIcon(R.drawable.ic_launcher).
|
||||
setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// TODO Auto-generated method stub
|
||||
SMSReceiveRuleUtil smsAcceptRuleConfig = SMSReceiveRuleUtil.getInstance(getApplicationContext(), false);
|
||||
smsAcceptRuleConfig.resetConfig();
|
||||
mSMSAcceptRuleArrayAdapter.notifyDataSetChanged();
|
||||
Toast.makeText(getApplication(), "Rules Reset", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}).
|
||||
setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}).
|
||||
/*setNeutralButton("查看详情", new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
}).*/
|
||||
create();
|
||||
alertDialog.show();
|
||||
}
|
||||
|
||||
//
|
||||
// 短信匹配过滤规则数据清空对话框
|
||||
//
|
||||
void showCleanConfigDialog() {
|
||||
Dialog alertDialog = new AlertDialog.Builder(this).
|
||||
setTitle("确定清理").
|
||||
setMessage("您确定清理所有短信接收规则吗?").
|
||||
setIcon(R.drawable.ic_launcher).
|
||||
setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// TODO Auto-generated method stub
|
||||
SMSReceiveRuleUtil smsAcceptRuleConfig = SMSReceiveRuleUtil.getInstance(getApplicationContext(), false);
|
||||
smsAcceptRuleConfig.cleanConfig();
|
||||
mSMSAcceptRuleArrayAdapter.notifyDataSetChanged();
|
||||
Toast.makeText(getApplication(), "Rules Cleaned.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}).
|
||||
setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}).
|
||||
/*setNeutralButton("查看详情", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
}).*/
|
||||
create();
|
||||
alertDialog.show();
|
||||
}
|
||||
|
||||
public void onAcceptRuleType(View view) {
|
||||
mrbRefuse.setChecked(false);
|
||||
}
|
||||
|
||||
public void onRefuseRuleType(View view) {
|
||||
mrbAccept.setChecked(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
mSMSAcceptRuleArrayAdapter.loadConfigData();
|
||||
mSMSAcceptRuleArrayAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package cc.winboll.studio.mymessagemanager.activitys;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import cc.winboll.studio.libaes.dialogs.YesNoAlertDialog;
|
||||
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
|
||||
import cc.winboll.studio.mymessagemanager.R;
|
||||
import cc.winboll.studio.mymessagemanager.adapters.SMSRecycle2Adapter;
|
||||
import cc.winboll.studio.mymessagemanager.utils.SMSRecycleUtil;
|
||||
import cc.winboll.studio.mymessagemanager.views.ProtectModeTextView;
|
||||
import com.baoyz.widget.PullRefreshLayout;
|
||||
import java.io.File;
|
||||
|
||||
public class SMSRecycle2Activity extends WinBoLLActivity implements IWinBoLLActivity {
|
||||
|
||||
public static final String TAG = "SMSRecycle2Activity";
|
||||
private static final String SP_NAME = "smsrecycle2_config";
|
||||
private static final String KEY_SCALE = "recycle2_scale";
|
||||
|
||||
Toolbar mToolbar;
|
||||
RecyclerView mRecyclerView;
|
||||
SMSRecycle2Adapter mSMSRecycle2Adapter;
|
||||
ProtectModeTextView mSampleProtectModeTextView;
|
||||
SharedPreferences mSP;
|
||||
|
||||
@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_smsrecycle2);
|
||||
mToolbar = findViewById(R.id.activitysmsrecycle2ASupportToolbar1);
|
||||
mToolbar.setSubtitle(getString(R.string.activity_name_about));
|
||||
setSupportActionBar(mToolbar);
|
||||
|
||||
mSP = getSharedPreferences(SP_NAME, MODE_PRIVATE);
|
||||
|
||||
mSampleProtectModeTextView = findViewById(R.id.activitysmsrecycle2SampleProtectModeTextView);
|
||||
mSampleProtectModeTextView.setContentTextWithScale(
|
||||
"调节本短信下方刻度滑条,可预览文本打乱效果;同时该进度条数值将作为回收站短信全局默认初始值。\n"
|
||||
+ "刻度0 = 保持原文不打乱;\n"
|
||||
+ "刻度数值越小,字符分组越细碎,文本打乱混乱程度越大;\n"
|
||||
+ "刻度数值越大,字符连串分组越长,文本打乱混乱程度越小。",
|
||||
mSP.getInt(KEY_SCALE, 0));
|
||||
|
||||
mSampleProtectModeTextView.setOnScaleChangedListener(new ProtectModeTextView.OnScaleChangedListener() {
|
||||
@Override
|
||||
public void onScaleChanged(int progress) {
|
||||
mSP.edit().putInt(KEY_SCALE, progress).apply();
|
||||
mSMSRecycle2Adapter.setScaleProgress(progress);
|
||||
mSMSRecycle2Adapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
|
||||
initView();
|
||||
}
|
||||
|
||||
void initView() {
|
||||
mRecyclerView = findViewById(R.id.activitysmsrecycle2RecyclerView1);
|
||||
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
|
||||
mRecyclerView.setLayoutManager(layoutManager);
|
||||
|
||||
mSMSRecycle2Adapter = new SMSRecycle2Adapter(this, mSP.getInt(KEY_SCALE, 0));
|
||||
mRecyclerView.setAdapter(mSMSRecycle2Adapter);
|
||||
|
||||
final PullRefreshLayout pullRefreshLayout = findViewById(R.id.activitysmsrecycle2PullRefreshLayout1);
|
||||
pullRefreshLayout.setOnRefreshListener(new PullRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
mSMSRecycle2Adapter.loadSMSRecycleList();
|
||||
mSMSRecycle2Adapter.notifyDataSetChanged();
|
||||
pullRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.toolbar_smsrecycle, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int nItemId = item.getItemId();
|
||||
if (nItemId == R.id.item_cleansmsrecycle) {
|
||||
YesNoAlertDialog.show(this, "回收站清空确认", "是否清空回收站", mDeleteListener);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
YesNoAlertDialog.OnDialogResultListener mDeleteListener = new YesNoAlertDialog.OnDialogResultListener() {
|
||||
|
||||
@Override
|
||||
public void onNo() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onYes() {
|
||||
File file = new File(SMSRecycleUtil.getSMSRecycleListDataPath(SMSRecycle2Activity.this));
|
||||
file.delete();
|
||||
mSMSRecycle2Adapter.loadSMSRecycleList();
|
||||
mSMSRecycle2Adapter.notifyDataSetChanged();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package cc.winboll.studio.mymessagemanager.activitys;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2024/07/19 16:56:18
|
||||
* @Describe 短信回收站
|
||||
*/
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import cc.winboll.studio.libaes.dialogs.YesNoAlertDialog;
|
||||
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
|
||||
import cc.winboll.studio.mymessagemanager.R;
|
||||
import cc.winboll.studio.mymessagemanager.activitys.SMSRecycleActivity;
|
||||
import cc.winboll.studio.mymessagemanager.adapters.SMSRecycleAdapter;
|
||||
import cc.winboll.studio.mymessagemanager.utils.SMSRecycleUtil;
|
||||
import com.baoyz.widget.PullRefreshLayout;
|
||||
import java.io.File;
|
||||
|
||||
public class SMSRecycleActivity extends WinBoLLActivity implements IWinBoLLActivity {
|
||||
|
||||
public static final String TAG = "SMSRecycleActivity";
|
||||
|
||||
Toolbar mToolbar;
|
||||
RecyclerView mRecyclerView;
|
||||
SMSRecycleAdapter mSMSRecycleAdapter;
|
||||
|
||||
@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_smsrecycle);
|
||||
// 初始化标题栏
|
||||
mToolbar = findViewById(R.id.activitysmsrecycleASupportToolbar1);
|
||||
mToolbar.setSubtitle(getString(R.string.activity_name_about));
|
||||
setSupportActionBar(mToolbar);
|
||||
initView();
|
||||
}
|
||||
|
||||
void initView() {
|
||||
// 绑定控件
|
||||
mRecyclerView = findViewById(R.id.activitysmsrecycleRecyclerView1);
|
||||
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
|
||||
mRecyclerView.setLayoutManager(layoutManager);
|
||||
|
||||
mSMSRecycleAdapter = new SMSRecycleAdapter(this);
|
||||
mRecyclerView.setAdapter(mSMSRecycleAdapter);
|
||||
|
||||
final PullRefreshLayout pullRefreshLayout = findViewById(R.id.activitysmsrecyclePullRefreshLayout1);
|
||||
pullRefreshLayout.setOnRefreshListener(new PullRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
mSMSRecycleAdapter.loadSMSRecycleList();
|
||||
mSMSRecycleAdapter.notifyDataSetChanged();
|
||||
pullRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
//return super.onCreateOptionsMenu(menu);
|
||||
getMenuInflater().inflate(R.menu.toolbar_smsrecycle, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int nItemId = item.getItemId();
|
||||
if (nItemId == R.id.item_cleansmsrecycle) {
|
||||
YesNoAlertDialog.show(this, "回收站清空确认", "是否清空回收站", mDeleteListener);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
YesNoAlertDialog.OnDialogResultListener mDeleteListener = new YesNoAlertDialog.OnDialogResultListener() {
|
||||
|
||||
@Override
|
||||
public void onNo() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onYes() {
|
||||
File file = new File(SMSRecycleUtil.getSMSRecycleListDataPath(SMSRecycleActivity.this));
|
||||
file.delete();
|
||||
mSMSRecycleAdapter.loadSMSRecycleList();
|
||||
mSMSRecycleAdapter.notifyDataSetChanged();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
package cc.winboll.studio.mymessagemanager.activitys;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.widget.Toolbar;
|
||||
import cc.winboll.studio.libaes.dialogs.YesNoAlertDialog;
|
||||
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
|
||||
import cc.winboll.studio.mymessagemanager.R;
|
||||
import cc.winboll.studio.mymessagemanager.activitys.SMSReceiveRuleActivity;
|
||||
import cc.winboll.studio.mymessagemanager.activitys.SharedJSONReceiveActivity;
|
||||
import cc.winboll.studio.mymessagemanager.activitys.TTSPlayRuleActivity;
|
||||
import cc.winboll.studio.mymessagemanager.beans.SMSAcceptRuleBean;
|
||||
import cc.winboll.studio.mymessagemanager.beans.TTSPlayRuleBean;
|
||||
import cc.winboll.studio.mymessagemanager.utils.UriUtil;
|
||||
import java.util.ArrayList;
|
||||
import android.app.Activity;
|
||||
|
||||
public class SharedJSONReceiveActivity extends WinBoLLActivity implements IWinBoLLActivity {
|
||||
|
||||
public static final String TAG = "SharedJSONReceive";
|
||||
|
||||
Toolbar mToolbar;
|
||||
|
||||
@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_sharedjsonreceive);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
// 接收分享数据
|
||||
Intent intent = getIntent();
|
||||
String action = intent.getAction();//action
|
||||
String type = intent.getType();//类型
|
||||
//LogUtils.d(TAG, "action is " + action);
|
||||
//LogUtils.d(TAG, "type is " + type);
|
||||
if ((Intent.ACTION_SEND.equals(action) || Intent.ACTION_VIEW.equals(action) || Intent.ACTION_EDIT.equals(action))
|
||||
&& type != null && (("application/json".equals(type)) || ("text/x-json".equals(type)))) {
|
||||
|
||||
//取出文件uri
|
||||
Uri uri = intent.getData();
|
||||
if (uri == null) {
|
||||
uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
||||
}
|
||||
//获取文件真实地址
|
||||
String szSrcJSON = UriUtil.getFileFromUri(getApplication(), uri);
|
||||
if (TextUtils.isEmpty(szSrcJSON)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String szCheck = TTSPlayRuleBean.checkIsTheSameBeanListAndFile(szSrcJSON, TTSPlayRuleBean.class);
|
||||
if (szCheck.equals("")) {
|
||||
importTTSPlayRuleBean(szSrcJSON);
|
||||
} else {
|
||||
sb.append("\n语音规则数据检测结果\n");
|
||||
sb.append(szCheck);
|
||||
}
|
||||
//LogUtils.d(TAG, "szCheck is " + szCheck);
|
||||
|
||||
szCheck = SMSAcceptRuleBean.checkIsTheSameBeanListAndFile(szSrcJSON, SMSAcceptRuleBean.class);
|
||||
if (szCheck.equals("")) {
|
||||
importSMSAcceptRuleBean(szSrcJSON);
|
||||
} else {
|
||||
sb.append("\n短信接收规则数据检测结果\n");
|
||||
sb.append(szCheck);
|
||||
}
|
||||
//LogUtils.d(TAG, "szCheck is " + szCheck);
|
||||
} else {
|
||||
sb.append("Not supported action.");
|
||||
}
|
||||
|
||||
mToolbar = findViewById(R.id.activitysharedjsonreceiveASupportToolbar1);
|
||||
mToolbar.setSubtitle(getString(R.string.activity_name_sharedjsonreceive));
|
||||
setActionBar(mToolbar);
|
||||
|
||||
TextView tvMessage = findViewById(R.id.activitysharedjsonreceiveTextView1);
|
||||
tvMessage.setText(sb.toString());
|
||||
}
|
||||
|
||||
void importSMSAcceptRuleBean(final String szSrcJSON) {
|
||||
ArrayList<SMSAcceptRuleBean> beanList = new ArrayList<SMSAcceptRuleBean>();
|
||||
boolean bCheck = SMSAcceptRuleBean.loadBeanListFromFile(szSrcJSON, beanList, SMSAcceptRuleBean.class);
|
||||
if (bCheck && beanList.size() > 0) {
|
||||
YesNoAlertDialog.show(SharedJSONReceiveActivity.this,
|
||||
"短信接收规则共享提示",
|
||||
"已收到短信接收规则" + Integer.toString(beanList.size()) + "个,\n是否导入应用?"
|
||||
, (new YesNoAlertDialog.OnDialogResultListener(){
|
||||
|
||||
@Override
|
||||
public void onYes() {
|
||||
ArrayList<SMSAcceptRuleBean> beanListShare = new ArrayList<SMSAcceptRuleBean>();
|
||||
SMSAcceptRuleBean.loadBeanListFromFile(szSrcJSON, beanListShare, SMSAcceptRuleBean.class);
|
||||
ArrayList<SMSAcceptRuleBean> beanListApp = new ArrayList<SMSAcceptRuleBean>();
|
||||
SMSAcceptRuleBean.loadBeanList(SharedJSONReceiveActivity.this, beanListApp, SMSAcceptRuleBean.class);
|
||||
beanListApp.addAll(0, beanListShare);
|
||||
SMSAcceptRuleBean.saveBeanList(SharedJSONReceiveActivity.this, beanListApp, SMSAcceptRuleBean.class);
|
||||
Toast.makeText(getApplication(), "已导入" + Integer.toString(beanListShare.size()) + "个数据。", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
Intent intent = new Intent(SharedJSONReceiveActivity.this, SMSReceiveRuleActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNo() {
|
||||
finish();
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
void importTTSPlayRuleBean(final String szSrcJSON) {
|
||||
ArrayList<TTSPlayRuleBean> beanList = new ArrayList<TTSPlayRuleBean>();
|
||||
boolean bCheck = TTSPlayRuleBean.loadBeanListFromFile(szSrcJSON, beanList, TTSPlayRuleBean.class);
|
||||
if (bCheck && beanList.size() > 0) {
|
||||
YesNoAlertDialog.show(SharedJSONReceiveActivity.this,
|
||||
"语音规则共享提示",
|
||||
"已收到语音规则" + Integer.toString(beanList.size()) + "个,\n是否导入应用?"
|
||||
, (new YesNoAlertDialog.OnDialogResultListener(){
|
||||
|
||||
@Override
|
||||
public void onYes() {
|
||||
ArrayList<TTSPlayRuleBean> beanListShare = new ArrayList<TTSPlayRuleBean>();
|
||||
TTSPlayRuleBean.loadBeanListFromFile(szSrcJSON, beanListShare, TTSPlayRuleBean.class);
|
||||
ArrayList<TTSPlayRuleBean> beanListApp = new ArrayList<TTSPlayRuleBean>();
|
||||
TTSPlayRuleBean.loadBeanList(SharedJSONReceiveActivity.this, beanListApp, TTSPlayRuleBean.class);
|
||||
beanListApp.addAll(0, beanListShare);
|
||||
TTSPlayRuleBean.saveBeanList(SharedJSONReceiveActivity.this, beanListApp, TTSPlayRuleBean.class);
|
||||
Toast.makeText(getApplication(), "已导入" + Integer.toString(beanListShare.size()) + "个数据。", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
Intent intent = new Intent(SharedJSONReceiveActivity.this, TTSPlayRuleActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNo() {
|
||||
finish();
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package cc.winboll.studio.mymessagemanager.activitys;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import cc.winboll.studio.mymessagemanager.R;
|
||||
|
||||
/**
|
||||
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2026/02/11 03:45
|
||||
* @Describe TTS悬浮窗设置类(使用可拖动自定义控件)
|
||||
*/
|
||||
public class TTSFloatSettingsActivity extends Activity {
|
||||
|
||||
public static final String TAG = "TTSFloatSettingsActivity";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// 直接加载包含自定义拖动控件的布局
|
||||
setContentView(R.layout.activity_ttsfloatsettings);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,200 @@
|
||||
package cc.winboll.studio.mymessagemanager.activitys;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2024/07/19 12:50:52
|
||||
* @Describe TTS 语音播放规则规则设置窗口
|
||||
*/
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
|
||||
import cc.winboll.studio.mymessagemanager.R;
|
||||
import cc.winboll.studio.mymessagemanager.adapters.TTSRuleBeanRecyclerViewAdapter;
|
||||
import cc.winboll.studio.mymessagemanager.beans.TTSPlayRuleBean;
|
||||
import cc.winboll.studio.mymessagemanager.utils.FileUtil;
|
||||
import cc.winboll.studio.mymessagemanager.utils.TTSPlayRuleUtil;
|
||||
import android.app.Activity;
|
||||
|
||||
public class TTSPlayRuleActivity extends WinBoLLActivity implements IWinBoLLActivity {
|
||||
|
||||
public static final String TAG = "TTSPlayRuleActivity";
|
||||
|
||||
public static final int MSG_RELOAD = 0;
|
||||
|
||||
public static final String EXTRA_TTSDEMOTEXT = "EXTRA_TTSDEMOTEXT";
|
||||
|
||||
Toolbar mToolbar;
|
||||
TTSRuleBeanRecyclerViewAdapter mTTSRuleBeanRecyclerViewAdapter;
|
||||
TTSPlayRuleUtil mTTSPlayRuleUtil;
|
||||
TTSPlayRuleBean mTTSRuleBeanCurrent;
|
||||
RecyclerView mRecyclerView;
|
||||
EditText metCurrentDemoSMSText;
|
||||
EditText metPatternText;
|
||||
EditText metCurrentTTSRuleText;
|
||||
|
||||
@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_ttsplayrule);
|
||||
|
||||
mTTSPlayRuleUtil = TTSPlayRuleUtil.getInstance(TTSPlayRuleActivity.this);
|
||||
|
||||
initView();
|
||||
|
||||
// 设置窗口消息处理
|
||||
setOnActivityMessageReceived(new IOnActivityMessageReceived(){
|
||||
@Override
|
||||
public void onActivityMessageReceived(Message msg) {
|
||||
switch (msg.what) {
|
||||
case MSG_RELOAD : {
|
||||
//Toast.makeText(getApplication(), "MSG_RELOAD", Toast.LENGTH_SHORT).show();
|
||||
mTTSRuleBeanRecyclerViewAdapter.reloadConfigData();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void initView() {
|
||||
// 初始化标题栏
|
||||
mToolbar = findViewById(R.id.activityttsplayruleASupportToolbar1);
|
||||
mToolbar.setSubtitle(getString(R.string.text_ttsrule));
|
||||
setSupportActionBar(mToolbar);
|
||||
|
||||
metCurrentDemoSMSText = findViewById(R.id.activityttsplayruleEditText1);
|
||||
metPatternText = findViewById(R.id.activityttsplayruleEditText2);
|
||||
metCurrentTTSRuleText = findViewById(R.id.activityttsplayruleEditText3);
|
||||
|
||||
Button btnTestTTSRule = findViewById(R.id.activityttsplayruleButton1);
|
||||
btnTestTTSRule.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
TTSPlayRuleBean ttsRuleBean = new TTSPlayRuleBean();
|
||||
ttsRuleBean.setDemoSMSText(metCurrentDemoSMSText.getText().toString());
|
||||
ttsRuleBean.setPatternText(metPatternText.getText().toString());
|
||||
ttsRuleBean.setTtsRuleText(metCurrentTTSRuleText.getText().toString());
|
||||
|
||||
String sz = mTTSPlayRuleUtil.testTTSAnalyzeModeReply(ttsRuleBean);
|
||||
Toast.makeText(getApplication(), sz, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
Button btnAcceptTTSRule = findViewById(R.id.activityttsplayruleButton2);
|
||||
btnAcceptTTSRule.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mTTSRuleBeanCurrent != null) {
|
||||
mTTSRuleBeanCurrent.setDemoSMSText(metCurrentDemoSMSText.getText().toString());
|
||||
mTTSRuleBeanCurrent.setPatternText(metPatternText.getText().toString());
|
||||
mTTSRuleBeanCurrent.setTtsRuleText(metCurrentTTSRuleText.getText().toString());
|
||||
mTTSRuleBeanRecyclerViewAdapter.saveConfigData();
|
||||
} else {
|
||||
if (!metCurrentDemoSMSText.getText().toString().equals("")) {
|
||||
mTTSRuleBeanCurrent = new TTSPlayRuleBean();
|
||||
mTTSRuleBeanCurrent.setDemoSMSText(metCurrentDemoSMSText.getText().toString());
|
||||
mTTSRuleBeanCurrent.setPatternText(metPatternText.getText().toString());
|
||||
mTTSRuleBeanCurrent.setTtsRuleText(metCurrentTTSRuleText.getText().toString());
|
||||
mTTSRuleBeanRecyclerViewAdapter.addNewTTSRuleBean(mTTSRuleBeanCurrent);
|
||||
LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
|
||||
layoutManager.scrollToPositionWithOffset(0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 绑定控件
|
||||
mRecyclerView = findViewById(R.id.activityttsplayruleRecyclerView1);
|
||||
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
|
||||
mRecyclerView.setLayoutManager(layoutManager);
|
||||
|
||||
mTTSRuleBeanRecyclerViewAdapter = new TTSRuleBeanRecyclerViewAdapter(TTSPlayRuleActivity.this, mOnTTSRuleChangeListener);
|
||||
mRecyclerView.setAdapter(mTTSRuleBeanRecyclerViewAdapter);
|
||||
|
||||
// 处理传入的窗口启动参数
|
||||
//
|
||||
String szNewDemoText = getIntent().getStringExtra(EXTRA_TTSDEMOTEXT);
|
||||
metCurrentDemoSMSText.setText(szNewDemoText);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
//return super.onCreateOptionsMenu(menu);
|
||||
getMenuInflater().inflate(R.menu.toolbar_rule, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onScrollToDemoSMSTextMatchingRule(View view) {
|
||||
int rowIndex = mTTSPlayRuleUtil.speakTTSAnalyzeModeText(metCurrentDemoSMSText.getText().toString());
|
||||
|
||||
LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
|
||||
layoutManager.scrollToPositionWithOffset(rowIndex, 0);
|
||||
Toast.makeText(getApplication(), "当前文本匹配的规则序号为 " + Integer.toString(rowIndex + 1), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int nItemId = item.getItemId();
|
||||
if (nItemId == R.id.item_rule_share) {
|
||||
TTSPlayRuleBean bean = new TTSPlayRuleBean();
|
||||
FileUtil.shareJSONFile(this, bean.getBeanListJsonFilePath(TTSPlayRuleActivity.this));
|
||||
} else if (nItemId == R.id.item_rule_reset) {
|
||||
showResetConfigDialog();
|
||||
} else if (nItemId == R.id.item_rule_clean) {
|
||||
showCleanConfigDialog();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
// 规则数据重置对话框
|
||||
//
|
||||
void showResetConfigDialog() {
|
||||
mTTSPlayRuleUtil.resetConfig();
|
||||
}
|
||||
|
||||
//
|
||||
// 规则数据重置对话框
|
||||
//
|
||||
void showCleanConfigDialog() {
|
||||
mTTSPlayRuleUtil.cleanConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
//
|
||||
// 规则项选择事件监听类
|
||||
//
|
||||
TTSRuleBeanRecyclerViewAdapter.OnTTSRuleChangeListener mOnTTSRuleChangeListener = new TTSRuleBeanRecyclerViewAdapter.OnTTSRuleChangeListener() {
|
||||
@Override
|
||||
public void onTTSRuleChange(TTSPlayRuleBean bean) {
|
||||
metCurrentDemoSMSText.setText(bean.getDemoSMSText());
|
||||
metPatternText.setText(bean.getPatternText());
|
||||
metCurrentTTSRuleText.setText(bean.getTtsRuleText());
|
||||
mTTSRuleBeanCurrent = bean;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package cc.winboll.studio.mymessagemanager.activitys;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen@AliYun.Com
|
||||
* @Date 2025/03/31 01:31:17
|
||||
* @Describe 应用活动窗口基类
|
||||
*/
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.view.MenuItem;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
|
||||
import cc.winboll.studio.mymessagemanager.enums.ThemeStyleEnum;
|
||||
|
||||
public class WinBoLLActivity extends AppCompatActivity implements IWinBoLLActivity {
|
||||
|
||||
public static final String TAG = "WinBoLLActivity";
|
||||
|
||||
IOnActivityMessageReceived mIOnActivityMessageReceived;
|
||||
|
||||
@Override
|
||||
public Activity getActivity() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
// 1. 优先读取SP中保存的主题(必须在setContentView前调用!)
|
||||
ThemeStyleEnum savedTheme = ThemeStyleEnum.getThemeFromSP(this);
|
||||
// 2. 设置主题
|
||||
setTheme(savedTheme.getStyleId());
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int selectedMenuId = item.getItemId();
|
||||
// 1. 根据菜单ID获取对应的主题枚举
|
||||
ThemeStyleEnum selectedTheme = ThemeStyleEnum.getThemeByMenuId(selectedMenuId);
|
||||
|
||||
if (selectedTheme != null) {
|
||||
// 2. 调用枚举自带方法保存主题到SP(替代AESThemeUtil)
|
||||
ThemeStyleEnum.saveThemeToSP(this, selectedTheme);
|
||||
recreate(); // 重建Activity生效主题
|
||||
} else if (selectedMenuId == android.R.id.home) {
|
||||
finish();
|
||||
} else {
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected interface IOnActivityMessageReceived {
|
||||
void onActivityMessageReceived(Message msg);
|
||||
}
|
||||
|
||||
public void sendActivityMessage(Message msg) {
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
|
||||
protected void setOnActivityMessageReceived(IOnActivityMessageReceived iOnActivityMessageReceived) {
|
||||
mIOnActivityMessageReceived = iOnActivityMessageReceived;
|
||||
}
|
||||
|
||||
Handler mHandler = new Handler(){
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
if (mIOnActivityMessageReceived != null) {
|
||||
mIOnActivityMessageReceived.onActivityMessageReceived(msg);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package cc.winboll.studio.mymessagemanager.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.mymessagemanager.R;
|
||||
import cc.winboll.studio.mymessagemanager.activitys.SMSActivity;
|
||||
import cc.winboll.studio.mymessagemanager.beans.PhoneBean;
|
||||
import cc.winboll.studio.mymessagemanager.beans.SMSBean;
|
||||
import cc.winboll.studio.mymessagemanager.utils.AddressUtils;
|
||||
import cc.winboll.studio.mymessagemanager.utils.PhoneUtil;
|
||||
import cc.winboll.studio.mymessagemanager.utils.SMSUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PhoneArrayAdapter extends BaseAdapter {
|
||||
|
||||
public final static String TAG = "PhoneArrayAdapter";
|
||||
|
||||
Context mContext;
|
||||
ArrayList<SMSBean> mData;
|
||||
List<PhoneBean> mlistContacts;
|
||||
PhoneUtil mPhoneUtil;
|
||||
|
||||
public PhoneArrayAdapter(Context context) {
|
||||
mContext = context;
|
||||
mData = new ArrayList<SMSBean>();
|
||||
}
|
||||
|
||||
public void loadData() {
|
||||
ArrayList<SMSBean> listTemp = SMSUtil.getAllSMSList(mContext);
|
||||
mData.clear();
|
||||
mData.addAll(listTemp);
|
||||
mPhoneUtil = new PhoneUtil(mContext);
|
||||
mlistContacts = mPhoneUtil.getPhoneList();
|
||||
LogUtils.i(TAG, "SMS List Reload.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mData.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int p1) {
|
||||
return mData.get(p1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int p1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
final ViewHolder viewHolder;
|
||||
if (convertView == null) {
|
||||
viewHolder = new ViewHolder();
|
||||
convertView = LayoutInflater.from(mContext).inflate(R.layout.listview_phone, parent, false);
|
||||
|
||||
//分别获取 image view 和 textview 的实例
|
||||
viewHolder.tvAddress = convertView.findViewById(R.id.listviewphoneTextView1);
|
||||
viewHolder.tvName = convertView.findViewById(R.id.listviewphoneTextView2);
|
||||
viewHolder.ll = convertView.findViewById(R.id.listviewphoneLinearLayout1);
|
||||
|
||||
convertView.setTag(viewHolder);
|
||||
} else {
|
||||
viewHolder = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
final String szAddress = ((SMSBean)getItem(position)).getAddress();
|
||||
|
||||
viewHolder.tvAddress.setText(AddressUtils.getFormattedAddress(szAddress));
|
||||
viewHolder.tvName.setText(getName(szAddress));
|
||||
|
||||
//Drawable drawableFrame = AppCompatResources.getDrawable(mContext, R.drawable.bg_frame);
|
||||
//viewHolder.ll.setBackground(drawableFrame);
|
||||
viewHolder.ll.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
|
||||
//Toast.makeText(mContext, tv.getText(), Toast.LENGTH_SHORT).show();
|
||||
Intent intent = new Intent(mContext, SMSActivity.class);
|
||||
intent.putExtra(SMSActivity.EXTRA_PHONE, szAddress);
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
|
||||
});
|
||||
return convertView;
|
||||
|
||||
}
|
||||
|
||||
String getName(String szAddress) {
|
||||
for (int i = 0; i < mlistContacts.size(); i++) {
|
||||
if (mlistContacts.get(i).getTelPhone().equals(szAddress)) {
|
||||
return mlistContacts.get(i).getName();
|
||||
}
|
||||
}
|
||||
return mContext.getString(R.string.text_notincontacts);
|
||||
}
|
||||
|
||||
class ViewHolder {
|
||||
TextView tvAddress;
|
||||
TextView tvName;
|
||||
LinearLayout ll;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
package cc.winboll.studio.mymessagemanager.adapters;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2024/07/20 12:27:34
|
||||
* @Describe 短信过滤规则数据适配器
|
||||
*/
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.TextView;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import cc.winboll.studio.libappbase.ToastUtils;
|
||||
import cc.winboll.studio.mymessagemanager.R;
|
||||
import cc.winboll.studio.mymessagemanager.beans.SMSAcceptRuleBean;
|
||||
import cc.winboll.studio.mymessagemanager.utils.SMSReceiveRuleUtil;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SMSAcceptRuleArrayAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
public static final String TAG = "SMSAcceptRuleArrayAdapter";
|
||||
|
||||
Context mContext;
|
||||
ArrayList<SMSAcceptRuleBean> mDataList;
|
||||
SMSReceiveRuleUtil mSMSReceiveRuleUtil;
|
||||
|
||||
public SMSAcceptRuleArrayAdapter(Context context) {
|
||||
mContext = context;
|
||||
mSMSReceiveRuleUtil = SMSReceiveRuleUtil.getInstance(mContext, true);
|
||||
loadConfigData();
|
||||
}
|
||||
|
||||
public void addSMSAcceptRule(SMSAcceptRuleBean bean) {
|
||||
mSMSReceiveRuleUtil.addRule(bean);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void loadConfigData() {
|
||||
mDataList = mSMSReceiveRuleUtil.loadConfigData();
|
||||
for (int i = 0; i < mDataList.size(); i++) {
|
||||
mDataList.get(i).setIsSimpleView(true);
|
||||
//LogUtils.d(TAG, "loadConfigData isEnable : " + Boolean.toString(mDataList.get(i).isEnable()));
|
||||
}
|
||||
}
|
||||
|
||||
void deleteItem(int position) {
|
||||
mDataList.remove(position);
|
||||
mSMSReceiveRuleUtil.saveConfigData();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (mDataList.get(position).isSimpleView()) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
if (viewType == 0) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.listview_smsacceptrule_simple, parent, false);
|
||||
return new SimpleViewHolder(view);
|
||||
} else {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.listview_smsacceptrule, parent, false);
|
||||
return new ComplexViewHolder(view);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
|
||||
final SMSAcceptRuleBean item = mDataList.get(position);
|
||||
if (holder.getItemViewType() == 0) {
|
||||
final SimpleViewHolder viewHolder = (SimpleViewHolder) holder;
|
||||
viewHolder.mtvContent.setText(item.getRuleData());
|
||||
viewHolder.mcbEnable.setChecked(item.isEnable());
|
||||
viewHolder.mcbEnable.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View p1) {
|
||||
item.setIsEnable(viewHolder.mcbEnable.isChecked());
|
||||
item.setIsSimpleView(true);
|
||||
mSMSReceiveRuleUtil.saveConfigData();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
viewHolder.mtvRuleType.setText(item.getRuleType().toString());
|
||||
viewHolder.mbtnEdit.setOnClickListener(new View.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
for (int i = 0; i < mDataList.size(); i++) {
|
||||
mDataList.get(i).setIsSimpleView(true);
|
||||
}
|
||||
item.setIsSimpleView(false);
|
||||
notifyDataSetChanged();
|
||||
//ToastUtils.show("setIsSimpleView");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
final ComplexViewHolder viewHolder = (ComplexViewHolder) holder;
|
||||
if (item != null) {
|
||||
//Drawable drawableFrame = AppCompatResources.getDrawable(mContext, R.drawable.bg_frame);
|
||||
viewHolder.metContent.setText(item.getRuleData());
|
||||
if (item.getRuleType() == SMSAcceptRuleBean.RuleType.ACCEPT) {
|
||||
viewHolder.mrbAccept.setChecked(true);
|
||||
viewHolder.mrbRefuse.setChecked(false);
|
||||
}
|
||||
if (item.getRuleType() == SMSAcceptRuleBean.RuleType.REFUSE) {
|
||||
viewHolder.mrbAccept.setChecked(false);
|
||||
viewHolder.mrbRefuse.setChecked(true);
|
||||
}
|
||||
viewHolder.mrbAccept.setOnClickListener(new View.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
viewHolder.mrbRefuse.setChecked(false);
|
||||
item.setRuleType(SMSAcceptRuleBean.RuleType.ACCEPT);
|
||||
mSMSReceiveRuleUtil.saveConfigData();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
viewHolder.mrbRefuse.setOnClickListener(new View.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
viewHolder.mrbAccept.setChecked(false);
|
||||
item.setRuleType(SMSAcceptRuleBean.RuleType.REFUSE);
|
||||
mSMSReceiveRuleUtil.saveConfigData();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
viewHolder.mbtnUp.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View p1) {
|
||||
if (position > 0) {
|
||||
mDataList.add(position-1, mDataList.get(position));
|
||||
mDataList.remove(position+1);
|
||||
mSMSReceiveRuleUtil.saveConfigData();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
});
|
||||
viewHolder.mbtnDown.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View p1) {
|
||||
if (position < mDataList.size() - 1) {
|
||||
//ToastUtils.show("mbtnDown");
|
||||
ToastUtils.show("position " + Integer.toString(position));
|
||||
mDataList.add(position+2, mDataList.get(position));
|
||||
mDataList.remove(position);
|
||||
mSMSReceiveRuleUtil.saveConfigData();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
});
|
||||
viewHolder.mbtnOK.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View p1) {
|
||||
item.setRuleData(viewHolder.metContent.getText().toString());
|
||||
item.setRuleType(viewHolder.mrbAccept.isChecked() ?SMSAcceptRuleBean.RuleType.ACCEPT: SMSAcceptRuleBean.RuleType.REFUSE);
|
||||
item.setIsEnable(viewHolder.mcbEnable.isChecked());
|
||||
item.setIsSimpleView(true);
|
||||
mSMSReceiveRuleUtil.saveConfigData();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
viewHolder.mbtnDelete.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View p1) {
|
||||
deleteItem(position);
|
||||
}
|
||||
});
|
||||
viewHolder.mcbEnable.setChecked(item.isEnable());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mDataList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int posttion) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static class SimpleViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView mtvContent;
|
||||
CheckBox mcbEnable;
|
||||
TextView mtvRuleType;
|
||||
Button mbtnEdit;
|
||||
|
||||
SimpleViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
mtvContent = itemView.findViewById(R.id.listviewsmsacceptrulesimpleTextView1);
|
||||
mcbEnable = itemView.findViewById(R.id.listviewsmsacceptrulesimpleCheckBox1);
|
||||
mtvRuleType = itemView.findViewById(R.id.listviewsmsacceptrulesimpleTextView2);
|
||||
mbtnEdit = itemView.findViewById(R.id.listviewsmsacceptrulesimpleButton1);
|
||||
}
|
||||
}
|
||||
|
||||
private static class ComplexViewHolder extends RecyclerView.ViewHolder {
|
||||
EditText metContent;
|
||||
RadioButton mrbAccept;
|
||||
RadioButton mrbRefuse;
|
||||
CheckBox mcbEnable;
|
||||
Button mbtnUp;
|
||||
Button mbtnDown;
|
||||
Button mbtnOK;
|
||||
Button mbtnDelete;
|
||||
|
||||
ComplexViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
metContent = itemView.findViewById(R.id.listviewsmsacceptruleEditText1);
|
||||
mrbAccept = itemView.findViewById(R.id.listviewsmsacceptruleRadioButton1);
|
||||
mrbRefuse = itemView.findViewById(R.id.listviewsmsacceptruleRadioButton2);
|
||||
mcbEnable = itemView.findViewById(R.id.listviewsmsacceptruleCheckBox1);
|
||||
mbtnUp = itemView.findViewById(R.id.listviewsmsacceptruleButton3);
|
||||
mbtnDown = itemView.findViewById(R.id.listviewsmsacceptruleButton4);
|
||||
mbtnOK = itemView.findViewById(R.id.listviewsmsacceptruleButton1);
|
||||
mbtnDelete = itemView.findViewById(R.id.listviewsmsacceptruleButton2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,214 @@
|
||||
package cc.winboll.studio.mymessagemanager.adapters;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.PopupMenu;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import cc.winboll.studio.libaes.dialogs.YesNoAlertDialog;
|
||||
import cc.winboll.studio.libappbase.ToastUtils;
|
||||
import cc.winboll.studio.mymessagemanager.R;
|
||||
import cc.winboll.studio.mymessagemanager.activitys.TTSPlayRuleActivity;
|
||||
import cc.winboll.studio.mymessagemanager.beans.SMSAcceptRuleBean;
|
||||
import cc.winboll.studio.mymessagemanager.beans.SMSBean;
|
||||
import cc.winboll.studio.mymessagemanager.utils.NotificationHelper;
|
||||
import cc.winboll.studio.mymessagemanager.utils.SMSReceiveRuleUtil;
|
||||
import cc.winboll.studio.mymessagemanager.utils.SMSRecycleUtil;
|
||||
import cc.winboll.studio.mymessagemanager.utils.SMSUtil;
|
||||
import cc.winboll.studio.mymessagemanager.utils.TTSPlayRuleUtil;
|
||||
import cc.winboll.studio.mymessagemanager.views.DateAgoTextView;
|
||||
import cc.winboll.studio.mymessagemanager.views.SMSView;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SMSArrayAdapter extends BaseAdapter {
|
||||
|
||||
public static String TAG = "SMSArrayAdapter";
|
||||
|
||||
Context mContext;
|
||||
String mszPhone;
|
||||
ArrayList<SMSBean> mData;
|
||||
|
||||
public SMSArrayAdapter(Context context, String szPhone) {
|
||||
mContext = context;
|
||||
mszPhone = szPhone;
|
||||
mData = new ArrayList<SMSBean>();
|
||||
mData = loadSMSList(context, szPhone);
|
||||
}
|
||||
|
||||
ArrayList<SMSBean> loadSMSList(Context context, String szPhone) {
|
||||
ArrayList<SMSBean> data = SMSUtil.getSMSListByPhone(context, szPhone);
|
||||
SMSBean.sortSMSByDateDesc(data, false);
|
||||
mData.clear();
|
||||
mData.addAll(data);
|
||||
return mData;
|
||||
}
|
||||
|
||||
public void cancelMessageNotification() {
|
||||
for (SMSBean bean : mData) {
|
||||
NotificationHelper notificationHelper = new NotificationHelper(mContext);
|
||||
notificationHelper.cancelNotification(bean.getId());
|
||||
}
|
||||
}
|
||||
|
||||
void deleteSMSById(final int position) {
|
||||
YesNoAlertDialog.show(mContext,
|
||||
"短信删除提示",
|
||||
"请确认删除动作!"
|
||||
, (new YesNoAlertDialog.OnDialogResultListener(){
|
||||
|
||||
@Override
|
||||
public void onYes() {
|
||||
SMSRecycleUtil.addSMSRecycleItem(mContext, (SMSBean)getItem(position));
|
||||
SMSUtil.deleteSMSById(mContext, ((SMSBean)getItem(position)).getId());
|
||||
mData.remove(position);
|
||||
notifyDataSetChanged();
|
||||
Toast.makeText(mContext, "SMS delete.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNo() {
|
||||
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public void reLoadSMSList(Context context, String szPhone) {
|
||||
mData = loadSMSList(context, szPhone);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mData.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int p1) {
|
||||
return mData.get(p1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int p1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||
final ViewHolder viewHolder;
|
||||
if (convertView == null) {
|
||||
viewHolder = new ViewHolder();
|
||||
convertView = LayoutInflater.from(mContext).inflate(R.layout.listview_sms, parent, false);
|
||||
viewHolder.mSMSView = convertView.findViewById(R.id.listviewsmsSMSView1);
|
||||
|
||||
viewHolder.mllMain = convertView.findViewById(R.id.listviewsmspart1LinearLayout1);
|
||||
viewHolder.mllContent = convertView.findViewById(R.id.listviewsmspart1LinearLayout2);
|
||||
viewHolder.mvMenu = convertView.findViewById(R.id.listviewsmspart1View1);
|
||||
viewHolder.mtvBody = (TextView) convertView
|
||||
.findViewById(R.id.listviewsmspart1TextView1);
|
||||
viewHolder.mdatvDate = convertView.findViewById(R.id.listviewsmspart1DateAgoTextView1);
|
||||
|
||||
viewHolder.mvLeft = convertView.findViewById(R.id.listviewsmsView1);
|
||||
viewHolder.mvRight = convertView.findViewById(R.id.listviewsmsView2);
|
||||
|
||||
convertView.setTag(viewHolder);
|
||||
} else {
|
||||
viewHolder = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
final SMSBean item = (SMSBean) getItem(position);
|
||||
if (item != null) {
|
||||
if (item.getType() == SMSBean.Type.INBOX) {
|
||||
viewHolder.mvLeft.setVisibility(View.GONE);
|
||||
viewHolder.mvRight.setVisibility(View.VISIBLE);
|
||||
|
||||
viewHolder.mSMSView.setSMSType(SMSView.SMSType.INBOX);
|
||||
viewHolder.mllMain.setGravity(Gravity.LEFT);
|
||||
} else {
|
||||
viewHolder.mvLeft.setVisibility(View.VISIBLE);
|
||||
viewHolder.mvRight.setVisibility(View.GONE);
|
||||
viewHolder.mSMSView.setSMSType(SMSView.SMSType.SEND);
|
||||
}
|
||||
|
||||
//Drawable drawableFrame = AppCompatResources.getDrawable(mContext, R.drawable.bg_frame);
|
||||
//viewHolder.mllContent.setBackground(drawableFrame);
|
||||
|
||||
viewHolder.mtvBody.setText(item.getBody());
|
||||
viewHolder.mdatvDate.setDate(item.getDate());
|
||||
//viewHolder.mtvType.setText(" [" + item.getType().name() + "] ");
|
||||
|
||||
viewHolder.mSMSView.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View p1) {
|
||||
// 弹出复制菜单
|
||||
PopupMenu menu = new PopupMenu(mContext, viewHolder.mvMenu);
|
||||
//加载菜单资源
|
||||
menu.getMenuInflater().inflate(R.menu.toolbar_item_sms, menu.getMenu());
|
||||
//设置点击事件的响应
|
||||
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem menuItem) {
|
||||
int nItemId = menuItem.getItemId();
|
||||
if (nItemId == R.id.copy) {
|
||||
// Gets a handle to the clipboard service.
|
||||
ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
// Creates a new text clip to put on the clipboard
|
||||
ClipData clip = ClipData.newPlainText("simple text", item.getBody());
|
||||
// Set the clipboard's primary clip.
|
||||
clipboard.setPrimaryClip(clip);
|
||||
Toast.makeText(mContext, "Copy to clipboard.", Toast.LENGTH_SHORT).show();
|
||||
} else if (nItemId == R.id.delete) {
|
||||
deleteSMSById(position);
|
||||
} else if (nItemId == R.id.addttsrule) {
|
||||
Intent intent = new Intent(mContext, TTSPlayRuleActivity.class);
|
||||
intent.putExtra(TTSPlayRuleActivity.EXTRA_TTSDEMOTEXT, viewHolder.mtvBody.getText().toString());
|
||||
mContext.startActivity(intent);
|
||||
} else if (nItemId == R.id.testtts) {
|
||||
//Toast.makeText(mContext, "Testing TTS.", Toast.LENGTH_SHORT).show();
|
||||
TTSPlayRuleUtil ttsPlayRuleUtil = TTSPlayRuleUtil.getInstance(mContext);
|
||||
ttsPlayRuleUtil.speakTTSAnalyzeModeText(viewHolder.mtvBody.getText().toString());
|
||||
} else if (nItemId == R.id.testreceivetule) {
|
||||
//Toast.makeText(mContext, "Testing Receive Rule.", Toast.LENGTH_SHORT).show();
|
||||
SMSReceiveRuleUtil smsReceiveRuleUtil = SMSReceiveRuleUtil.getInstance(mContext, true);
|
||||
SMSReceiveRuleUtil.MatchResult matchResult = smsReceiveRuleUtil.getReceiveRuleMatchResult(mContext, viewHolder.mtvBody.getText().toString());
|
||||
if (matchResult.matchPositionInRules == SMSReceiveRuleUtil.VALID_MATCHRESULT_POSITION
|
||||
|| matchResult.matchRuleType == SMSAcceptRuleBean.RuleType.REGEXPPIUTILS_ISPPIOK_FALSE) {
|
||||
//ToastUtils.show("Test");
|
||||
ToastUtils.show("Not Receive Rule is Matched.\nResult is : " + matchResult.matchRuleType);
|
||||
} else {
|
||||
ToastUtils.show("MatchResult : " + matchResult.matchRuleType + "\nReceiveRule Match Position : " + Integer.toString(matchResult.matchPositionInRules + 1));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
//一定要调用show()来显示弹出式菜单
|
||||
menu.show();
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
class ViewHolder {
|
||||
SMSView mSMSView;
|
||||
LinearLayout mllMain;
|
||||
LinearLayout mllContent;
|
||||
TextView mtvBody;
|
||||
View mvMenu;
|
||||
DateAgoTextView mdatvDate;
|
||||
View mvLeft;
|
||||
View mvRight;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package cc.winboll.studio.mymessagemanager.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import cc.winboll.studio.mymessagemanager.R;
|
||||
import cc.winboll.studio.mymessagemanager.beans.SMSRecycleBean;
|
||||
import cc.winboll.studio.mymessagemanager.utils.AddressUtils;
|
||||
import cc.winboll.studio.mymessagemanager.utils.SMSRecycleUtil;
|
||||
import cc.winboll.studio.mymessagemanager.views.DateAgoTextView;
|
||||
import cc.winboll.studio.mymessagemanager.views.ProtectModeTextView;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SMSRecycle2Adapter extends RecyclerView.Adapter<SMSRecycle2Adapter.ViewHolder> {
|
||||
|
||||
public static final String TAG = "SMSRecycle2Adapter";
|
||||
|
||||
Context mContext;
|
||||
ArrayList<SMSRecycleBean> mDataList;
|
||||
String mszSMSRecycleListDataPath;
|
||||
int mScaleProgress;
|
||||
|
||||
public SMSRecycle2Adapter(Context context, int scaleProgress) {
|
||||
mContext = context;
|
||||
mScaleProgress = scaleProgress;
|
||||
mszSMSRecycleListDataPath = SMSRecycleUtil.getSMSRecycleListDataPath(mContext);
|
||||
mDataList = new ArrayList<SMSRecycleBean>();
|
||||
mDataList = loadSMSRecycleList();
|
||||
}
|
||||
|
||||
public void setScaleProgress(int scaleProgress) {
|
||||
mScaleProgress = scaleProgress;
|
||||
}
|
||||
|
||||
public ArrayList<SMSRecycleBean> loadSMSRecycleList() {
|
||||
ArrayList<SMSRecycleBean> list = new ArrayList<SMSRecycleBean>();
|
||||
SMSRecycleBean.loadBeanListFromFile(mszSMSRecycleListDataPath, list, SMSRecycleBean.class);
|
||||
SMSRecycleBean.sortSMSByDeleteDateDesc(list, true);
|
||||
mDataList.clear();
|
||||
mDataList.addAll(list);
|
||||
return mDataList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.listview_smsrecycle2, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(ViewHolder holder, int position) {
|
||||
SMSRecycleBean item = mDataList.get(position);
|
||||
holder.mtvAddress.setText(AddressUtils.getFormattedAddress(item.getAddress()));
|
||||
holder.mdatvDeleteDate.setDate(item.getDeleteDate());
|
||||
holder.mProtectModeTextView.setContentTextWithScale(item.getBody(), mScaleProgress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mDataList.size();
|
||||
}
|
||||
|
||||
static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView mtvAddress;
|
||||
DateAgoTextView mdatvDeleteDate;
|
||||
ProtectModeTextView mProtectModeTextView;
|
||||
|
||||
ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
mtvAddress = itemView.findViewById(R.id.listviewsmsrecycle2TextViewAddress);
|
||||
mdatvDeleteDate = itemView.findViewById(R.id.listviewsmsrecycle2DateAgoTextViewDelete);
|
||||
mProtectModeTextView = itemView.findViewById(R.id.listviewsmsrecycle2ProtectModeTextView);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,290 @@
|
||||
package cc.winboll.studio.mymessagemanager.adapters;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2024/07/19 17:07:34
|
||||
* @Describe 短信回收站短信数据适配器
|
||||
*/
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.PopupMenu;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import cc.winboll.studio.libaes.dialogs.YesNoAlertDialog;
|
||||
import cc.winboll.studio.libappbase.ToastUtils;
|
||||
import cc.winboll.studio.mymessagemanager.R;
|
||||
import cc.winboll.studio.mymessagemanager.activitys.TTSPlayRuleActivity;
|
||||
import cc.winboll.studio.mymessagemanager.beans.SMSBean;
|
||||
import cc.winboll.studio.mymessagemanager.beans.SMSRecycleBean;
|
||||
import cc.winboll.studio.mymessagemanager.utils.AddressUtils;
|
||||
import cc.winboll.studio.mymessagemanager.utils.AppConfigUtil;
|
||||
import cc.winboll.studio.mymessagemanager.utils.SMSRecycleUtil;
|
||||
import cc.winboll.studio.mymessagemanager.utils.SMSUtil;
|
||||
import cc.winboll.studio.mymessagemanager.utils.TTSPlayRuleUtil;
|
||||
import cc.winboll.studio.mymessagemanager.utils.UserVisionSystemProtectModeUtil;
|
||||
import cc.winboll.studio.mymessagemanager.views.DateAgoTextView;
|
||||
import cc.winboll.studio.mymessagemanager.views.SMSView;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SMSRecycleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
public static final String TAG = "SMSRecycleAdapter";
|
||||
|
||||
Context mContext;
|
||||
ArrayList<SMSRecycleBean> mDataList;
|
||||
String mszSMSRecycleListDataPath;
|
||||
AppConfigUtil mAppConfigUtil;
|
||||
|
||||
public SMSRecycleAdapter(Context context) {
|
||||
mContext = context;
|
||||
mAppConfigUtil = AppConfigUtil.getInstance(mContext);
|
||||
mszSMSRecycleListDataPath = SMSRecycleUtil.getSMSRecycleListDataPath(mContext);
|
||||
mDataList = new ArrayList<SMSRecycleBean>();
|
||||
mDataList = loadSMSRecycleList();
|
||||
}
|
||||
|
||||
public ArrayList<SMSRecycleBean> loadSMSRecycleList() {
|
||||
ArrayList<SMSRecycleBean> list = new ArrayList<SMSRecycleBean>();
|
||||
SMSRecycleBean.loadBeanListFromFile(mszSMSRecycleListDataPath, list, SMSRecycleBean.class);
|
||||
SMSRecycleBean.sortSMSByDeleteDateDesc(list, true);
|
||||
mDataList.clear();
|
||||
mDataList.addAll(list);
|
||||
for (int i = 0; i < mDataList.size(); i++) {
|
||||
mDataList.get(i).setIsSimpleView(true);
|
||||
}
|
||||
//ToastUtils.show("mDataList.size() : " + Integer.toString(mDataList.size()));
|
||||
return mDataList;
|
||||
}
|
||||
|
||||
public void saveSMSRecycleList() {
|
||||
SMSBean.saveBeanListToFile(mszSMSRecycleListDataPath, mDataList);
|
||||
}
|
||||
|
||||
void restoreSMSRecycleItem(final int position) {
|
||||
YesNoAlertDialog.show(mContext,
|
||||
"短信恢复提示",
|
||||
"是否恢复该短信!"
|
||||
, (new YesNoAlertDialog.OnDialogResultListener(){
|
||||
|
||||
@Override
|
||||
public void onYes() {
|
||||
SMSBean item = mDataList.get(position);
|
||||
long nResultId = 0;
|
||||
//LogUtils.d(TAG, "item.getType() : " + item.getType());
|
||||
if (item.getType() == SMSBean.Type.INBOX) {
|
||||
nResultId = SMSUtil.saveReceiveSms(mContext, item.getAddress(), item.getBody(),
|
||||
(item.getReadStatus() == SMSBean.ReadStatus.READ) ?"1": "0",
|
||||
item.getDate(), "inbox");
|
||||
} else if (item.getType() == SMSBean.Type.SENT) {
|
||||
nResultId = SMSUtil.saveOldSendedSMS(mContext, item);
|
||||
}
|
||||
if (nResultId == 0) {
|
||||
ToastUtils.show("SMS Restored Failed!\nPlease confirm that the application has the SMS management authority.");
|
||||
} else {
|
||||
mDataList.remove(position);
|
||||
SMSBean.saveBeanListToFile(mszSMSRecycleListDataPath, mDataList);
|
||||
notifyDataSetChanged();
|
||||
ToastUtils.show("SMS Restored. ID : " + Long.toString(nResultId));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNo() {
|
||||
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
void deleteSMSRecycleItem(final int position) {
|
||||
YesNoAlertDialog.show(mContext,
|
||||
"短信删除提示",
|
||||
"请确认删除动作!"
|
||||
, (new YesNoAlertDialog.OnDialogResultListener(){
|
||||
|
||||
@Override
|
||||
public void onYes() {
|
||||
mDataList.remove(position);
|
||||
SMSBean.saveBeanListToFile(mszSMSRecycleListDataPath, mDataList);
|
||||
notifyDataSetChanged();
|
||||
Toast.makeText(mContext, "SMS delete.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNo() {
|
||||
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public void reLoadSMSList(Context context, String szPhone) {
|
||||
mDataList = loadSMSRecycleList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (mDataList.get(position).isSimpleView()) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
if (viewType == 0) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.listview_smsrecycle_simple, parent, false);
|
||||
return new SimpleViewHolder(view);
|
||||
} else {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.listview_smsrecycle, parent, false);
|
||||
return new ComplexViewHolder(view);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
|
||||
final SMSRecycleBean item = mDataList.get(position);
|
||||
if (holder.getItemViewType() == 0) {
|
||||
SimpleViewHolder viewHolder = (SimpleViewHolder) holder;
|
||||
viewHolder.mtvAddress.setText(AddressUtils.getFormattedAddress(item.getAddress()));
|
||||
viewHolder.mbtnViewBody.setOnClickListener(new View.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
for (int i = 0; i < mDataList.size(); i++) {
|
||||
mDataList.get(i).setIsSimpleView(true);
|
||||
}
|
||||
item.setIsSimpleView(false);
|
||||
notifyDataSetChanged();
|
||||
//ToastUtils.show("setIsSimpleView");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
final ComplexViewHolder viewHolder = (ComplexViewHolder) holder;
|
||||
if (item.getType() == SMSBean.Type.INBOX) {
|
||||
viewHolder.mvLeft.setVisibility(View.GONE);
|
||||
viewHolder.mvRight.setVisibility(View.VISIBLE);
|
||||
|
||||
viewHolder.mSMSView.setSMSType(SMSView.SMSType.INBOX);
|
||||
viewHolder.mllMain.setGravity(Gravity.LEFT);
|
||||
} else {
|
||||
viewHolder.mvLeft.setVisibility(View.VISIBLE);
|
||||
viewHolder.mvRight.setVisibility(View.GONE);
|
||||
viewHolder.mSMSView.setSMSType(SMSView.SMSType.SEND);
|
||||
}
|
||||
viewHolder.mtvAddress.setText(AddressUtils.getFormattedAddress(item.getAddress()));
|
||||
viewHolder.mdatvDeleteDate.setDate(item.getDeleteDate());
|
||||
viewHolder.mdatvDate.setDate(item.getDate());
|
||||
if(mAppConfigUtil.mAppConfigBean.isSMSRecycleProtectMode()) {
|
||||
viewHolder.mtvBody.setText("ProtectMode : " + UserVisionSystemProtectModeUtil.PreviewShuffleSMS(item.getBody(), mAppConfigUtil.mAppConfigBean.getProtectModerRefuseChars(), mAppConfigUtil.mAppConfigBean.getProtectModerReplaceChars()));
|
||||
} else {
|
||||
viewHolder.mtvBody.setText(item.getBody());
|
||||
}
|
||||
/*viewHolder.mTagsAdapter = new TagsAdapter(mContext, item);
|
||||
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(mContext);
|
||||
viewHolder.mTagsRecyclerView.setLayoutManager(layoutManager);
|
||||
viewHolder.mTagsRecyclerView.setAdapter(viewHolder.mTagsAdapter);
|
||||
// 这个设置可以解决嵌套listvew的内部listview拉动问题。
|
||||
viewHolder.mTagsRecyclerView.setParentScrollView(viewHolder.mScrollView);*/
|
||||
viewHolder.mllMain.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View p1) {
|
||||
// 弹出复制菜单
|
||||
PopupMenu menu = new PopupMenu(mContext, viewHolder.mvMenu);
|
||||
//加载菜单资源
|
||||
menu.getMenuInflater().inflate(R.menu.toolbar_item_smsrecycle, menu.getMenu());
|
||||
menu.getMenuInflater().inflate(R.menu.toolbar_item_sms, menu.getMenu());
|
||||
//设置点击事件的响应
|
||||
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem menuItem) {
|
||||
int nItemId = menuItem.getItemId();
|
||||
if (nItemId == R.id.item_restoresms) {
|
||||
restoreSMSRecycleItem(position);
|
||||
} else if (nItemId == R.id.copy) {
|
||||
// Gets a handle to the clipboard service.
|
||||
ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
// Creates a new text clip to put on the clipboard
|
||||
ClipData clip = ClipData.newPlainText("simple text", item.getBody());
|
||||
// Set the clipboard's primary clip.
|
||||
clipboard.setPrimaryClip(clip);
|
||||
Toast.makeText(mContext, "Copy to clipboard.", Toast.LENGTH_SHORT).show();
|
||||
} else if (nItemId == R.id.delete) {
|
||||
deleteSMSRecycleItem(position);
|
||||
/*loadSMSRecycleList();
|
||||
mDataList.remove(item);
|
||||
saveSMSRecycleList();*/
|
||||
notifyDataSetChanged();
|
||||
} else if (nItemId == R.id.addttsrule) {
|
||||
Intent intent = new Intent(mContext, TTSPlayRuleActivity.class);
|
||||
intent.putExtra(TTSPlayRuleActivity.EXTRA_TTSDEMOTEXT, viewHolder.mtvBody.getText().toString());
|
||||
mContext.startActivity(intent);
|
||||
} else if (nItemId == R.id.testtts) {
|
||||
//Toast.makeText(mContext, "Testing TTS.", Toast.LENGTH_SHORT).show();
|
||||
TTSPlayRuleUtil ttsPlayRuleUtil = TTSPlayRuleUtil.getInstance(mContext);
|
||||
ttsPlayRuleUtil.speakTTSAnalyzeModeText(viewHolder.mtvBody.getText().toString());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
//一定要调用show()来显示弹出式菜单
|
||||
menu.show();
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mDataList.size();
|
||||
}
|
||||
|
||||
private static class SimpleViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView mtvAddress;
|
||||
Button mbtnViewBody;
|
||||
|
||||
SimpleViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
mtvAddress = itemView.findViewById(R.id.listviewsmsrecyclesimpleTextView1);
|
||||
mbtnViewBody = itemView.findViewById(R.id.listviewsmsrecyclesimpleButton1);
|
||||
}
|
||||
}
|
||||
|
||||
private static class ComplexViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView mtvAddress;
|
||||
DateAgoTextView mdatvDeleteDate;
|
||||
SMSView mSMSView;
|
||||
LinearLayout mllMain;
|
||||
LinearLayout mllContent;
|
||||
TextView mtvBody;
|
||||
View mvMenu;
|
||||
DateAgoTextView mdatvDate;
|
||||
View mvLeft;
|
||||
View mvRight;
|
||||
|
||||
ComplexViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
mtvAddress = itemView.findViewById(R.id.listviewsmsrecycleTextView1);
|
||||
mdatvDeleteDate = itemView.findViewById(R.id.listviewsmsrecycleDateAgoTextView1);
|
||||
mSMSView = itemView.findViewById(R.id.listviewsmsrecycleSMSView1);
|
||||
mllMain = itemView.findViewById(R.id.listviewsmspart1LinearLayout1);
|
||||
mllContent = itemView.findViewById(R.id.listviewsmspart1LinearLayout2);
|
||||
mvMenu = itemView.findViewById(R.id.listviewsmsrecycleView1);
|
||||
mtvBody = itemView.findViewById(R.id.listviewsmspart1TextView1);
|
||||
mdatvDate = itemView.findViewById(R.id.listviewsmspart1DateAgoTextView1);
|
||||
mvLeft = itemView.findViewById(R.id.listviewsmsrecycleView1);
|
||||
mvRight = itemView.findViewById(R.id.listviewsmsrecycleView2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
package cc.winboll.studio.mymessagemanager.adapters;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2024/05/18 16:08:20
|
||||
* @Describe TTSRuleBean RecyclerView Adapter
|
||||
*/
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.PopupMenu;
|
||||
import android.widget.TextView;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import cc.winboll.studio.mymessagemanager.R;
|
||||
import cc.winboll.studio.mymessagemanager.activitys.TTSPlayRuleActivity;
|
||||
import cc.winboll.studio.mymessagemanager.beans.TTSPlayRuleBean;
|
||||
import cc.winboll.studio.mymessagemanager.utils.TTSPlayRuleUtil;
|
||||
import cc.winboll.studio.mymessagemanager.views.TTSRuleView;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class TTSRuleBeanRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
public static final String TAG = "TTSRuleBeanRecyclerViewAdapter";
|
||||
|
||||
Context mContext;
|
||||
ArrayList<TTSPlayRuleBean> mDataList;
|
||||
OnTTSRuleChangeListener mOnTTSRuleChangeListener;
|
||||
TTSPlayRuleUtil mTTSPlayRuleUtil;
|
||||
|
||||
public TTSRuleBeanRecyclerViewAdapter(TTSPlayRuleActivity ttsPlayRuleActivity, OnTTSRuleChangeListener onTTSRuleChangeListener) {
|
||||
mContext = ttsPlayRuleActivity;
|
||||
mOnTTSRuleChangeListener = onTTSRuleChangeListener;
|
||||
|
||||
mTTSPlayRuleUtil = TTSPlayRuleUtil.getInstance(ttsPlayRuleActivity);
|
||||
mTTSPlayRuleUtil.initTTSPlayRuleActivity(ttsPlayRuleActivity);
|
||||
mDataList = mTTSPlayRuleUtil.loadConfigData();
|
||||
}
|
||||
|
||||
public void addNewTTSRuleBean(TTSPlayRuleBean bean) {
|
||||
mTTSPlayRuleUtil.addNewTTSRuleBean(bean);
|
||||
//notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void saveConfigData() {
|
||||
mTTSPlayRuleUtil.saveConfigData();
|
||||
//notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void reloadConfigData() {
|
||||
mDataList = mTTSPlayRuleUtil.loadConfigData();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public interface OnTTSRuleChangeListener {
|
||||
abstract void onTTSRuleChange(TTSPlayRuleBean bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (mDataList.get(position).isSimpleView()) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
if (viewType == 0) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.listview_ttsplayrule_simple, parent, false);
|
||||
return new SimpleViewHolder(view);
|
||||
} else {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.listview_ttsplayrule, parent, false);
|
||||
return new ComplexViewHolder(view);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
|
||||
final TTSPlayRuleBean item = mDataList.get(position);
|
||||
if (holder.getItemViewType() == 0) {
|
||||
SimpleViewHolder viewHolder = (SimpleViewHolder) holder;
|
||||
viewHolder.mSortNumber.setText(Integer.toString(position + 1));
|
||||
viewHolder.mtvDemoSMSText.setText(item.getDemoSMSText());
|
||||
} else {
|
||||
final ComplexViewHolder viewHolder = (ComplexViewHolder) holder;
|
||||
viewHolder.mSortNumber.setText(Integer.toString(position + 1));
|
||||
viewHolder.mtvDemoSMSText.setText(item.getDemoSMSText());
|
||||
viewHolder.mTTSRuleView.setOnClickListener(new View.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mOnTTSRuleChangeListener.onTTSRuleChange(item);
|
||||
}
|
||||
});
|
||||
viewHolder.mbtnUp.setOnClickListener(new View.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
//Toast.makeText(mContext, Integer.toString(position), Toast.LENGTH_SHORT).show();
|
||||
mTTSPlayRuleUtil.changeBeanPosition(position, true);
|
||||
//notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
viewHolder.mbtnDown.setOnClickListener(new View.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
//Toast.makeText(mContext, Integer.toString(position), Toast.LENGTH_SHORT).show();
|
||||
mTTSPlayRuleUtil.changeBeanPosition(position, false);
|
||||
//notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
viewHolder.mchbEnable.setChecked(item.isEnable());
|
||||
viewHolder.mchbEnable.setOnClickListener(new View.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mTTSPlayRuleUtil.setBeanEnable(position, ((CheckBox)v).isChecked());
|
||||
//notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
viewHolder.mTTSRuleView.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View p1) {
|
||||
// 弹出复制菜单
|
||||
PopupMenu menu = new PopupMenu(mContext, viewHolder.mSortNumber);
|
||||
//加载菜单资源
|
||||
menu.getMenuInflater().inflate(R.menu.toolbar_ttsrule, menu.getMenu());
|
||||
//设置点击事件的响应
|
||||
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem menuItem) {
|
||||
int nItemId = menuItem.getItemId();
|
||||
if (nItemId == R.id.deletettsrule) {
|
||||
mTTSPlayRuleUtil.deleteTTSRuleBean(position);
|
||||
//notifyDataSetChanged();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
//一定要调用show()来显示弹出式菜单
|
||||
menu.show();
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mDataList.size();
|
||||
}
|
||||
|
||||
private static class SimpleViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView mSortNumber;
|
||||
TextView mtvDemoSMSText;
|
||||
|
||||
|
||||
SimpleViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
mSortNumber = itemView.findViewById(R.id.itemttsplayrulesimpleTextView2);
|
||||
mtvDemoSMSText = itemView.findViewById(R.id.itemttsplayrulesimpleTextView1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static class ComplexViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView mSortNumber;
|
||||
TTSRuleView mTTSRuleView;
|
||||
LinearLayout mllMain;
|
||||
TextView mtvDemoSMSText;
|
||||
Button mbtnUp;
|
||||
Button mbtnDown;
|
||||
CheckBox mchbEnable;
|
||||
|
||||
ComplexViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
mSortNumber = itemView.findViewById(R.id.itemttsplayruleTextView2);
|
||||
mTTSRuleView = itemView.findViewById(R.id.listviewttsplayruleTTSRuleView1);
|
||||
mllMain = itemView.findViewById(R.id.itemttsplayruleLinearLayout1);
|
||||
mtvDemoSMSText = itemView.findViewById(R.id.itemttsplayruleTextView1);
|
||||
mbtnUp = itemView.findViewById(R.id.itemttsplayruleButton1);
|
||||
mbtnDown = itemView.findViewById(R.id.itemttsplayruleButton2);
|
||||
mchbEnable = itemView.findViewById(R.id.itemttsplayruleCheckBox1);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
package cc.winboll.studio.mymessagemanager.beans;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2024/06/02 20:07:44
|
||||
* @Describe 应用配置数据类
|
||||
*/
|
||||
import android.util.JsonReader;
|
||||
import android.util.JsonWriter;
|
||||
import cc.winboll.studio.libappbase.BaseBean;
|
||||
import java.io.IOException;
|
||||
|
||||
public class AppConfigBean extends BaseBean {
|
||||
|
||||
public static final String TAG = "AppConfigBean";
|
||||
|
||||
// 当前国家代码(如+8612345678901代码就是86.)
|
||||
String countryCode = "86";
|
||||
// 是否合并的手机号码前缀
|
||||
boolean isMergeCountryCodePrefix = true;
|
||||
// TT语音延时播放毫秒数
|
||||
int ttsPlayDelayTimes = 3000;
|
||||
boolean isEnableService = false;
|
||||
boolean isEnableOnlyReceiveContacts = false;
|
||||
boolean isEnableTTS = false;
|
||||
boolean isEnableTTSRuleMode = false;
|
||||
boolean isSMSRecycleProtectMode = false;
|
||||
// 保护式预览拒绝显示的字符集
|
||||
String protectModerRefuseChars = "设定被和谐的字符";
|
||||
// 保护式预览拒绝显示的字符集的替代字符
|
||||
String protectModerReplaceChars = "当前替代显示字符";
|
||||
// 回收站打开的窗口类名 SMSRecycleActivity / SMSRecycle2Activity
|
||||
String recycleBinClass = "SMSRecycleActivity";
|
||||
//int appThemeID = ThemeUtil.getThemeID(ThemeUtil.BaseTheme.DEFAULT);
|
||||
|
||||
public void setProtectModerRefuseChars(String protectModerRefuseChars) {
|
||||
this.protectModerRefuseChars = protectModerRefuseChars;
|
||||
}
|
||||
|
||||
public String getProtectModerRefuseChars() {
|
||||
return protectModerRefuseChars;
|
||||
}
|
||||
|
||||
public void setProtectModerReplaceChars(String protectModerReplaceChars) {
|
||||
this.protectModerReplaceChars = protectModerReplaceChars;
|
||||
}
|
||||
|
||||
public String getProtectModerReplaceChars() {
|
||||
return protectModerReplaceChars;
|
||||
}
|
||||
|
||||
public void setRecycleBinClass(String recycleBinClass) {
|
||||
this.recycleBinClass = recycleBinClass;
|
||||
}
|
||||
|
||||
public String getRecycleBinClass() {
|
||||
return recycleBinClass;
|
||||
}
|
||||
|
||||
public void setIsSMSRecycleProtectMode(boolean isSMSRecycleProtectMode) {
|
||||
this.isSMSRecycleProtectMode = isSMSRecycleProtectMode;
|
||||
}
|
||||
|
||||
public boolean isSMSRecycleProtectMode() {
|
||||
return isSMSRecycleProtectMode;
|
||||
}
|
||||
|
||||
public void setCountryCode(String countryCode) {
|
||||
this.countryCode = countryCode;
|
||||
}
|
||||
|
||||
public String getCountryCode() {
|
||||
return countryCode;
|
||||
}
|
||||
|
||||
public void setIsMergeCountryCodePrefix(boolean isMergeCountryCodePrefix) {
|
||||
this.isMergeCountryCodePrefix = isMergeCountryCodePrefix;
|
||||
}
|
||||
|
||||
public boolean isMergeCountryCodePrefix() {
|
||||
return isMergeCountryCodePrefix;
|
||||
}
|
||||
|
||||
public void setTtsPlayDelayTimes(int ttsPlayDelayTimes) {
|
||||
this.ttsPlayDelayTimes = ttsPlayDelayTimes;
|
||||
}
|
||||
|
||||
public int getTtsPlayDelayTimes() {
|
||||
return ttsPlayDelayTimes;
|
||||
}
|
||||
|
||||
public void setIsEnableService(boolean isEnableService) {
|
||||
this.isEnableService = isEnableService;
|
||||
}
|
||||
|
||||
public boolean isEnableService() {
|
||||
return isEnableService;
|
||||
}
|
||||
|
||||
public void setIsEnableOnlyReceiveContacts(boolean isEnableOnlyReceiveContacts) {
|
||||
this.isEnableOnlyReceiveContacts = isEnableOnlyReceiveContacts;
|
||||
}
|
||||
|
||||
public boolean isEnableOnlyReceiveContacts() {
|
||||
return isEnableOnlyReceiveContacts;
|
||||
}
|
||||
|
||||
public void setIsEnableTTS(boolean isEnableTTS) {
|
||||
this.isEnableTTS = isEnableTTS;
|
||||
}
|
||||
|
||||
public boolean isEnableTTS() {
|
||||
return isEnableTTS;
|
||||
}
|
||||
|
||||
public void setIsEnableTTSRuleMode(boolean isEnableTTSRuleMode) {
|
||||
this.isEnableTTSRuleMode = isEnableTTSRuleMode;
|
||||
}
|
||||
|
||||
public boolean isEnableTTSRuleMode() {
|
||||
return isEnableTTSRuleMode;
|
||||
}
|
||||
|
||||
/*public void setAppThemeID(int appThemeID) {
|
||||
this.appThemeID = appThemeID;
|
||||
}
|
||||
|
||||
public int getAppThemeID() {
|
||||
return appThemeID;
|
||||
}
|
||||
|
||||
public void setAppTheme(ThemeUtil.BaseTheme baseTheme) {
|
||||
setAppThemeID(ThemeUtil.getThemeID(baseTheme));
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return AppConfigBean.class.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
|
||||
super.writeThisToJsonWriter(jsonWriter);
|
||||
AppConfigBean bean = this;
|
||||
jsonWriter.name("countryCode").value(bean.getCountryCode());
|
||||
jsonWriter.name("isMergeCountryCodePrefix").value(bean.isMergeCountryCodePrefix());
|
||||
jsonWriter.name("ttsPlayDelayTimes").value(bean.getTtsPlayDelayTimes());
|
||||
jsonWriter.name("isEnableService").value(bean.isEnableService());
|
||||
jsonWriter.name("isEnableOnlyReceiveContacts").value(bean.isEnableOnlyReceiveContacts());
|
||||
jsonWriter.name("isEnableTTS").value(bean.isEnableTTS());
|
||||
jsonWriter.name("isEnableTTSRuleMode").value(bean.isEnableTTSRuleMode());
|
||||
jsonWriter.name("isSMSRecycleProtectMode").value(bean.isSMSRecycleProtectMode());
|
||||
jsonWriter.name("protectModerRefuseChars").value(bean.getProtectModerRefuseChars());
|
||||
jsonWriter.name("protectModerReplaceChars").value(bean.getProtectModerReplaceChars());
|
||||
jsonWriter.name("recycleBinClass").value(bean.getRecycleBinClass());
|
||||
//jsonWriter.name("appThemeID").value(bean.getAppThemeID());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBean readBeanFromJsonReader(JsonReader jsonReader) throws IOException {
|
||||
AppConfigBean bean = new AppConfigBean();
|
||||
jsonReader.beginObject();
|
||||
while (jsonReader.hasNext()) {
|
||||
String name = jsonReader.nextName();
|
||||
if (name.equals("countryCode")) {
|
||||
bean.setCountryCode(jsonReader.nextString());
|
||||
} else if (name.equals("isMergeCountryCodePrefix")) {
|
||||
bean.setIsMergeCountryCodePrefix(jsonReader.nextBoolean());
|
||||
} else if (name.equals("ttsPlayDelayTimes")) {
|
||||
bean.setTtsPlayDelayTimes(jsonReader.nextInt());
|
||||
} else if (name.equals("isEnableService")) {
|
||||
bean.setIsEnableService(jsonReader.nextBoolean());
|
||||
} else if (name.equals("isEnableOnlyReceiveContacts")) {
|
||||
bean.setIsEnableOnlyReceiveContacts(jsonReader.nextBoolean());
|
||||
} else if (name.equals("isEnableTTS")) {
|
||||
bean.setIsEnableTTS(jsonReader.nextBoolean());
|
||||
} else if (name.equals("isEnableTTSRuleMode")) {
|
||||
bean.setIsEnableTTSRuleMode(jsonReader.nextBoolean());
|
||||
} else if (name.equals("isSMSRecycleProtectMode")) {
|
||||
bean.setIsSMSRecycleProtectMode(jsonReader.nextBoolean());
|
||||
} else if (name.equals("protectModerRefuseChars")) {
|
||||
bean.setProtectModerRefuseChars(jsonReader.nextString());
|
||||
} else if (name.equals("protectModerReplaceChars")) {
|
||||
bean.setProtectModerReplaceChars(jsonReader.nextString());
|
||||
} else if (name.equals("recycleBinClass")) {
|
||||
bean.setRecycleBinClass(jsonReader.nextString());
|
||||
} /*else if (name.equals("appThemeID")) {
|
||||
bean.setAppThemeID(jsonReader.nextInt());
|
||||
}*/ else {
|
||||
jsonReader.skipValue();
|
||||
}
|
||||
}
|
||||
// 结束 JSON 对象
|
||||
jsonReader.endObject();
|
||||
return bean;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package cc.winboll.studio.mymessagemanager.beans;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2023/06/30 23:21:27
|
||||
* @Describe 应用配置数据类,V1 旧版。
|
||||
*/
|
||||
import cc.winboll.studio.mymessagemanager.utils.ThemeUtil;
|
||||
|
||||
public class AppConfigBean_V1 {
|
||||
|
||||
// 当前国家代码(如+8612345678901代码就是86.)
|
||||
String countryCode = "86";
|
||||
// 是否合并的手机号码前缀
|
||||
boolean isMergeCountryCodePrefix = true;
|
||||
// TT语音延时播放毫秒数
|
||||
int ttsPlayDelayTimes = 3000;
|
||||
boolean enableService = false;
|
||||
boolean enableOnlyReceiveContacts = false;
|
||||
boolean enableTTS = false;
|
||||
boolean enableTTSRuleMode = false;
|
||||
//int appThemeID = ThemeUtil.getThemeID(ThemeUtil.BaseTheme.DEFAULT);
|
||||
|
||||
public void setCountryCode(String countryCode) {
|
||||
this.countryCode = countryCode;
|
||||
}
|
||||
|
||||
public String getCountryCode() {
|
||||
return countryCode;
|
||||
}
|
||||
|
||||
public void setIsMergeCountryCodePrefix(boolean isMergeCountryCodePrefix) {
|
||||
this.isMergeCountryCodePrefix = isMergeCountryCodePrefix;
|
||||
}
|
||||
|
||||
public boolean isMergeCountryCodePrefix() {
|
||||
return isMergeCountryCodePrefix;
|
||||
}
|
||||
|
||||
public void setTtsPlayDelayTimes(int ttsPlayDelayTimes) {
|
||||
this.ttsPlayDelayTimes = ttsPlayDelayTimes;
|
||||
}
|
||||
|
||||
public int getTtsPlayDelayTimes() {
|
||||
return ttsPlayDelayTimes;
|
||||
}
|
||||
|
||||
public void setEnableService(boolean enableService) {
|
||||
this.enableService = enableService;
|
||||
}
|
||||
|
||||
public boolean isEnableService() {
|
||||
return enableService;
|
||||
}
|
||||
|
||||
public void setEnableOnlyReceiveContacts(boolean enableOnlyReceiveContacts) {
|
||||
this.enableOnlyReceiveContacts = enableOnlyReceiveContacts;
|
||||
}
|
||||
|
||||
public boolean isEnableOnlyReceiveContacts() {
|
||||
return enableOnlyReceiveContacts;
|
||||
}
|
||||
|
||||
public void setEnableTTS(boolean enableTTS) {
|
||||
this.enableTTS = enableTTS;
|
||||
}
|
||||
|
||||
public boolean isEnableTTS() {
|
||||
return enableTTS;
|
||||
}
|
||||
|
||||
public void setEnableTTSRuleMode(boolean enableTTSRuleMode) {
|
||||
this.enableTTSRuleMode = enableTTSRuleMode;
|
||||
}
|
||||
|
||||
public boolean isEnableTTSRuleMode() {
|
||||
return enableTTSRuleMode;
|
||||
}
|
||||
|
||||
/*public void setAppThemeID(int appThemeID) {
|
||||
this.appThemeID = appThemeID;
|
||||
}
|
||||
|
||||
public int getAppThemeID() {
|
||||
return appThemeID;
|
||||
}*/
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package cc.winboll.studio.mymessagemanager.beans;
|
||||
|
||||
public class ContractsBean {
|
||||
|
||||
private String mszName;
|
||||
private String mszTelPhone;
|
||||
|
||||
public ContractsBean(String szName, String szTelPhone) {
|
||||
this.mszName = szName;
|
||||
this.mszTelPhone = szTelPhone;
|
||||
}
|
||||
|
||||
public void setName(String szName) {
|
||||
this.mszName = szName;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return mszName;
|
||||
}
|
||||
|
||||
public void setTelPhone(String szTelPhone) {
|
||||
this.mszTelPhone = szTelPhone;
|
||||
}
|
||||
|
||||
public String getTelPhone() {
|
||||
return mszTelPhone;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package cc.winboll.studio.mymessagemanager.beans;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2024/07/19 13:10:44
|
||||
* @Describe 短信通知栏消息结构
|
||||
*/
|
||||
public class MessageNotificationBean {
|
||||
|
||||
private int messageId;
|
||||
private String mszPhone;
|
||||
private String mszTitle;
|
||||
private String mszContent;
|
||||
|
||||
public MessageNotificationBean(int messageId, String mszPhone, String mszTitle, String mszContent) {
|
||||
this.messageId = messageId;
|
||||
this.mszPhone = mszPhone;
|
||||
this.mszTitle = mszTitle;
|
||||
this.mszContent = mszContent;
|
||||
}
|
||||
|
||||
public void setMessageId(int messageId) {
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
public int getMessageId() {
|
||||
return messageId;
|
||||
}
|
||||
|
||||
public void setPhone(String szPhone) {
|
||||
this.mszPhone = szPhone;
|
||||
}
|
||||
|
||||
public String getPhone() {
|
||||
return mszPhone;
|
||||
}
|
||||
|
||||
public void setTitle(String szTitle) {
|
||||
this.mszTitle = szTitle;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return mszTitle;
|
||||
}
|
||||
|
||||
public void setContent(String szContent) {
|
||||
this.mszContent = szContent;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return mszContent;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package cc.winboll.studio.mymessagemanager.beans;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2024/07/19 13:10:44
|
||||
* @Describe 联系人信息类
|
||||
*/
|
||||
public class PhoneBean {
|
||||
|
||||
//联系人姓名
|
||||
private String mszName;
|
||||
//电话号码
|
||||
private String mszTelPhone;
|
||||
|
||||
public String getName() {
|
||||
return mszName;
|
||||
}
|
||||
|
||||
public void setName(String szName) {
|
||||
this.mszName = szName;
|
||||
}
|
||||
|
||||
public String getTelPhone() {
|
||||
return mszTelPhone;
|
||||
}
|
||||
|
||||
public void setTelPhone(String szTelPhone) {
|
||||
this.mszTelPhone = szTelPhone;
|
||||
}
|
||||
|
||||
public PhoneBean() {
|
||||
}
|
||||
|
||||
public PhoneBean(String szName, String szTelPhone) {
|
||||
this.mszName = szName;
|
||||
this.mszTelPhone = szTelPhone;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package cc.winboll.studio.mymessagemanager.beans;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2024/05/30 10:57:14
|
||||
* @Describe 短信接收规则类
|
||||
*/
|
||||
import android.util.JsonReader;
|
||||
import android.util.JsonWriter;
|
||||
import cc.winboll.studio.libappbase.BaseBean;
|
||||
import java.io.IOException;
|
||||
|
||||
public class SMSAcceptRuleBean extends BaseBean {
|
||||
|
||||
public static final String TAG = "SMSAcceptRuleBean";
|
||||
|
||||
// 规则类型枚举
|
||||
public enum RuleType { ACCEPT, REFUSE, REGEXPPIUTILS_ISPPIOK_FALSE }
|
||||
|
||||
// 用户ID
|
||||
int userId = -1;
|
||||
// 规则数据
|
||||
String ruleData = "";
|
||||
// 是否启用
|
||||
boolean isEnable = false;
|
||||
// 规则类型
|
||||
RuleType ruleType = RuleType.REFUSE;
|
||||
// 是否简单视图
|
||||
boolean isSimpleView = false;
|
||||
|
||||
public SMSAcceptRuleBean() {}
|
||||
|
||||
public SMSAcceptRuleBean(int userId, String ruleData, boolean isEnable, RuleType ruleType, boolean isSimpleView) {
|
||||
this.userId = userId;
|
||||
this.ruleData = ruleData;
|
||||
this.isEnable = isEnable;
|
||||
this.ruleType = ruleType;
|
||||
this.isSimpleView = isSimpleView;
|
||||
}
|
||||
|
||||
public void setRuleType(RuleType ruleType) {
|
||||
this.ruleType = ruleType;
|
||||
}
|
||||
|
||||
public RuleType getRuleType() {
|
||||
return ruleType;
|
||||
}
|
||||
|
||||
public void setIsSimpleView(boolean isSimpleView) {
|
||||
this.isSimpleView = isSimpleView;
|
||||
}
|
||||
|
||||
public boolean isSimpleView() {
|
||||
return isSimpleView;
|
||||
}
|
||||
|
||||
public void setUserId(int userID) {
|
||||
this.userId = userID;
|
||||
}
|
||||
|
||||
public int getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setRuleData(String ruleData) {
|
||||
this.ruleData = ruleData;
|
||||
}
|
||||
|
||||
public String getRuleData() {
|
||||
return ruleData;
|
||||
}
|
||||
|
||||
public void setIsEnable(boolean isEnable) {
|
||||
this.isEnable = isEnable;
|
||||
}
|
||||
|
||||
public boolean isEnable() {
|
||||
return isEnable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return SMSAcceptRuleBean.class.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
|
||||
super.writeThisToJsonWriter(jsonWriter);
|
||||
SMSAcceptRuleBean bean = this;
|
||||
jsonWriter.name("userId").value(bean.getUserId());
|
||||
jsonWriter.name("ruleData").value(bean.getRuleData());
|
||||
jsonWriter.name("isEnable").value(bean.isEnable());
|
||||
jsonWriter.name("ruleType").value(bean.getRuleType().ordinal());
|
||||
jsonWriter.name("isSimpleView").value(bean.isSimpleView());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBean readBeanFromJsonReader(JsonReader jsonReader) throws IOException {
|
||||
SMSAcceptRuleBean bean = new SMSAcceptRuleBean();
|
||||
jsonReader.beginObject();
|
||||
while (jsonReader.hasNext()) {
|
||||
String name = jsonReader.nextName();
|
||||
if (name.equals("userId")) {
|
||||
bean.setUserId(jsonReader.nextInt());
|
||||
} else if (name.equals("ruleData")) {
|
||||
bean.setRuleData(jsonReader.nextString());
|
||||
} else if (name.equals("isEnable")) {
|
||||
bean.setIsEnable(jsonReader.nextBoolean());
|
||||
} else if (name.equals("ruleType")) {
|
||||
bean.setRuleType(RuleType.values()[jsonReader.nextInt()]);
|
||||
} else if (name.equals("isSimpleView")) {
|
||||
bean.setIsSimpleView(jsonReader.nextBoolean());
|
||||
} else {
|
||||
jsonReader.skipValue();
|
||||
}
|
||||
}
|
||||
// 结束 JSON 对象
|
||||
jsonReader.endObject();
|
||||
return bean;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package cc.winboll.studio.mymessagemanager.beans;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2024/05/30 10:57:14
|
||||
* @Describe 短信接收规则类,V1 旧版。
|
||||
*/
|
||||
public class SMSAcceptRuleBean_V1 {
|
||||
|
||||
public static final String TAG = "SMSAcceptRuleBean_V1";
|
||||
|
||||
// 用户ID
|
||||
String userID = "";
|
||||
// 规则数据
|
||||
String ruleData = "";
|
||||
// 是否启用
|
||||
boolean enable = false;
|
||||
|
||||
public SMSAcceptRuleBean_V1() {}
|
||||
|
||||
public SMSAcceptRuleBean_V1(String userID, String ruleData, boolean enable) {
|
||||
this.userID = userID;
|
||||
this.ruleData = ruleData;
|
||||
this.enable = enable;
|
||||
}
|
||||
|
||||
public void setUserID(String userID) {
|
||||
this.userID = userID;
|
||||
}
|
||||
|
||||
public String getUserID() {
|
||||
return userID;
|
||||
}
|
||||
|
||||
public void setRuleData(String ruleData) {
|
||||
this.ruleData = ruleData;
|
||||
}
|
||||
|
||||
public String getRuleData() {
|
||||
return ruleData;
|
||||
}
|
||||
|
||||
public void setEnable(boolean enable) {
|
||||
this.enable = enable;
|
||||
}
|
||||
|
||||
public boolean isEnable() {
|
||||
return enable;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,272 @@
|
||||
package cc.winboll.studio.mymessagemanager.beans;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2024/05/30 10:57:14
|
||||
* @Describe 短信信息类
|
||||
参考资料:
|
||||
https://blog.csdn.net/freeking101/article/details/121575985
|
||||
|
||||
获取短信只需要得到 ContentResolver 就行了,它的 URI 主要有:
|
||||
content://sms/ 所有短信
|
||||
content://sms/inbox 收件箱
|
||||
content://sms/sent 已发送
|
||||
content://sms/draft 草稿
|
||||
content://sms/outbox 发件箱
|
||||
content://sms/failed 发送失败
|
||||
content://sms/queued 待发送列表
|
||||
SMS 数据库中的字段如下:
|
||||
_id 一个自增字段,从1开始
|
||||
thread_id 序号,同一发信人的id相同
|
||||
address 发件人手机号码
|
||||
person 联系人列表里的序号,陌生人为null
|
||||
date 发件日期
|
||||
protocol 协议,分为: 0 SMS_RPOTO, 1 MMS_PROTO
|
||||
read 是否阅读 0未读, 1已读
|
||||
status 状态 -1接收,0 complete, 64 pending, 128 failed
|
||||
type ALL = 0;INBOX = 1;SENT = 2;DRAFT = 3;OUTBOX = 4;FAILED = 5; QUEUED = 6;
|
||||
body 短信内容
|
||||
service_center 短信服务中心号码编号。如+8613800755500
|
||||
subject 短信的主题
|
||||
reply_path_present TP-Reply-Path
|
||||
locked
|
||||
*/
|
||||
import android.content.ContentValues;
|
||||
import android.util.JsonReader;
|
||||
import android.util.JsonWriter;
|
||||
import cc.winboll.studio.libappbase.BaseBean;
|
||||
import java.io.IOException;
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
||||
public class SMSBean extends BaseBean {
|
||||
|
||||
//public enum Type { ALL(8), INBOX(0), SENT, DRAFT, OUTBOX, FAILED, QUEUED, TRASH }
|
||||
public enum Type { ALL(0), INBOX(1), SENT(2), DRAFT(3), OUTBOX(4), FAILED(5), QUEUED(6), TRASH(7);
|
||||
static String[] _mlistName = { "所有短信", "接收", "发送", "草稿", "发件箱", "发送失败", "待发送列表", "回收站" };
|
||||
private int value = 0;
|
||||
private Type(int value) { //必须是private的,否则编译错误
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public enum ReadStatus { UNREAD, READ }
|
||||
|
||||
transient private static String _ContentValuesName_address = "address";
|
||||
transient private static String _ContentValuesName_body = "body";
|
||||
transient private static String _ContentValuesName_read = "read";
|
||||
transient private static String _ContentValuesName_date = "date";
|
||||
|
||||
// 短信标识
|
||||
protected int id;
|
||||
// 发件人手机号码
|
||||
protected String mszAddress;
|
||||
// 短信内容
|
||||
protected String mszBody;
|
||||
// 发件日期
|
||||
protected long mnDate;
|
||||
// 短息归类
|
||||
protected Type mType;
|
||||
// 是否阅读
|
||||
protected ReadStatus mReadStatus;
|
||||
// 联系人列表里的序号,陌生人为null
|
||||
protected int mnPerson;
|
||||
|
||||
public SMSBean() {
|
||||
this.id = -1;
|
||||
this.mszAddress = "";
|
||||
this.mszBody = "";
|
||||
this.mnDate = 0;
|
||||
this.mType = Type.INBOX;
|
||||
this.mReadStatus = ReadStatus.UNREAD;
|
||||
this.mnPerson = 0;
|
||||
}
|
||||
|
||||
public SMSBean(int id, String mszAddress, String mszBody, long mnDate, Type mType, ReadStatus mReadStatus, int mnPerson) {
|
||||
this.id = id;
|
||||
this.mszAddress = mszAddress;
|
||||
this.mszBody = mszBody;
|
||||
this.mnDate = mnDate;
|
||||
this.mType = mType;
|
||||
this.mReadStatus = mReadStatus;
|
||||
this.mnPerson = mnPerson;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setAddress(String szAddress) {
|
||||
this.mszAddress = szAddress;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return mszAddress;
|
||||
}
|
||||
|
||||
public void setBody(String szBody) {
|
||||
this.mszBody = szBody;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return mszBody;
|
||||
}
|
||||
|
||||
public void setDate(long date) {
|
||||
this.mnDate = date;
|
||||
}
|
||||
|
||||
public long getDate() {
|
||||
return mnDate;
|
||||
}
|
||||
|
||||
public void setType(Type type) {
|
||||
this.mType = type;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return mType;
|
||||
}
|
||||
|
||||
public void setReadStatus(ReadStatus readStatus) {
|
||||
this.mReadStatus = readStatus;
|
||||
}
|
||||
|
||||
public ReadStatus getReadStatus() {
|
||||
return mReadStatus;
|
||||
}
|
||||
|
||||
public void setPerson(int person) {
|
||||
this.mnPerson = person;
|
||||
}
|
||||
|
||||
public int getPerson() {
|
||||
return mnPerson;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return SMSBean.class.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
|
||||
super.writeThisToJsonWriter(jsonWriter);
|
||||
SMSBean bean = this;
|
||||
jsonWriter.name("id").value(bean.getId());
|
||||
jsonWriter.name("mszAddress").value(bean.getAddress());
|
||||
jsonWriter.name("mszBody").value(bean.getBody());
|
||||
jsonWriter.name("mnDate").value(bean.getDate());
|
||||
jsonWriter.name("mType").value(bean.getType().ordinal());
|
||||
jsonWriter.name("mReadStatus").value(bean.getReadStatus().ordinal());
|
||||
jsonWriter.name("mnPerson").value(bean.getPerson());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean initObjectsFromJsonReader(JsonReader jsonReader, String name) throws IOException {
|
||||
if(super.initObjectsFromJsonReader(jsonReader, name)) { return true; }
|
||||
else{
|
||||
if (name.equals("id")) {
|
||||
setId(jsonReader.nextInt());
|
||||
} else if (name.equals("mszAddress")) {
|
||||
setAddress(jsonReader.nextString());
|
||||
} else if (name.equals("mszBody")) {
|
||||
setBody(jsonReader.nextString());
|
||||
} else if (name.equals("mnDate")) {
|
||||
setDate(jsonReader.nextLong());
|
||||
} else if (name.equals("mType")) {
|
||||
setType(Type.values()[jsonReader.nextInt()]);
|
||||
} else if (name.equals("mReadStatus")) {
|
||||
setReadStatus(ReadStatus.values()[jsonReader.nextInt()]);
|
||||
} else if (name.equals("mnPerson")) {
|
||||
setPerson(jsonReader.nextInt());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBean readBeanFromJsonReader(JsonReader jsonReader) throws IOException {
|
||||
jsonReader.beginObject();
|
||||
while (jsonReader.hasNext()) {
|
||||
String name = jsonReader.nextName();
|
||||
if(!initObjectsFromJsonReader(jsonReader, name)) {
|
||||
jsonReader.skipValue();
|
||||
}
|
||||
}
|
||||
// 结束 JSON 对象
|
||||
jsonReader.endObject();
|
||||
return this;
|
||||
}
|
||||
|
||||
public static ContentValues createOldSendedSMSContentValues(SMSBean smsBean) {
|
||||
ContentValues result = new ContentValues();
|
||||
result.put(_ContentValuesName_address, smsBean.mszAddress);
|
||||
result.put(_ContentValuesName_body, smsBean.mszBody);
|
||||
result.put(_ContentValuesName_read, smsBean.mReadStatus.toString()); //"0" for have not read sms and "1" for have read sms
|
||||
result.put(_ContentValuesName_date, Long.toString(smsBean.getDate()));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ContentValues createSendedSMSContentValues(SMSBean smsBean) {
|
||||
ContentValues result = new ContentValues();
|
||||
result.put(_ContentValuesName_address, smsBean.mszAddress);
|
||||
result.put(_ContentValuesName_body, smsBean.mszBody);
|
||||
result.put(_ContentValuesName_read, smsBean.mReadStatus.toString()); //"0" for have not read sms and "1" for have read sms
|
||||
result.put(_ContentValuesName_date, Long.toString(System.currentTimeMillis()));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getTypeName(Type type) {
|
||||
return Type._mlistName[type.ordinal()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String szResult = "\n";
|
||||
szResult += "mszAddress is (" + mszAddress + ")\n";
|
||||
szResult += "mszBody is (" + mszBody + ")\n";
|
||||
szResult += "mnDate is (" + Long.toString(mnDate) + ")\n";
|
||||
szResult += "mType is (" + mType.name() + ")\n";
|
||||
if (mReadStatus != null) {
|
||||
szResult += "mReadStatus is (" + mReadStatus.name() + ")\n";
|
||||
}
|
||||
szResult += "mnPerson is (" + Integer.toString(mnPerson) + ")\n";
|
||||
|
||||
|
||||
return szResult;
|
||||
}
|
||||
|
||||
public static void sortSMSByDateDesc(ArrayList<SMSBean> list, boolean isDesc) {
|
||||
Collections.sort(list, new SortSMSByDateDesc(isDesc));
|
||||
|
||||
}
|
||||
|
||||
private static class SortSMSByDateDesc implements Comparator<SMSBean> {
|
||||
private boolean mIsDesc = true;
|
||||
// isDesc 是否降序排列
|
||||
public SortSMSByDateDesc(boolean isDesc) {
|
||||
mIsDesc = isDesc;
|
||||
}
|
||||
Collator cmp = Collator.getInstance(java.util.Locale.CHINA);
|
||||
@Override
|
||||
public int compare(SMSBean o1, SMSBean o2) {
|
||||
boolean b0_1 = (o1.getDate() < o2.getDate());
|
||||
if (mIsDesc) {
|
||||
return b0_1 ?1: -1;
|
||||
} else {
|
||||
return b0_1 ?-1: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
package cc.winboll.studio.mymessagemanager.beans;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2024/07/20 01:51:44
|
||||
* @Describe 回收站短信存储类
|
||||
*/
|
||||
import android.util.JsonReader;
|
||||
import android.util.JsonWriter;
|
||||
import cc.winboll.studio.libappbase.BaseBean;
|
||||
import java.io.IOException;
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
||||
public class SMSRecycleBean extends SMSBean {
|
||||
|
||||
public static final String TAG = "SMSRecycleBean";
|
||||
|
||||
// 短信删除日期
|
||||
long deleteDate;
|
||||
// 当前是否是简单视图
|
||||
boolean isSimpleView;
|
||||
|
||||
public void setDeleteDate(long deleteDate) {
|
||||
this.deleteDate = deleteDate;
|
||||
}
|
||||
|
||||
public long getDeleteDate() {
|
||||
return deleteDate;
|
||||
}
|
||||
|
||||
public void setIsSimpleView(boolean isSimpleView) {
|
||||
this.isSimpleView = isSimpleView;
|
||||
}
|
||||
|
||||
public boolean isSimpleView() {
|
||||
return isSimpleView;
|
||||
}
|
||||
|
||||
public SMSRecycleBean() {
|
||||
|
||||
}
|
||||
|
||||
public SMSRecycleBean(SMSBean smsBean, long deleteDate) {
|
||||
super.id = smsBean.getId();
|
||||
super.mszAddress = smsBean.getAddress();
|
||||
super.mszBody = smsBean.getBody();
|
||||
super.mnDate = smsBean.getDate();
|
||||
super.mType = smsBean.getType();
|
||||
super.mReadStatus = smsBean.getReadStatus();
|
||||
super.mnPerson = smsBean.getPerson();
|
||||
this.deleteDate = deleteDate;
|
||||
this.isSimpleView = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return SMSRecycleBean.class.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
|
||||
super.writeThisToJsonWriter(jsonWriter);
|
||||
SMSRecycleBean bean = this;
|
||||
jsonWriter.name("deleteDate").value(bean.getDeleteDate());
|
||||
jsonWriter.name("isSimpleView").value(bean.isSimpleView());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBean readBeanFromJsonReader(JsonReader jsonReader) throws IOException {
|
||||
/*SMSRecycleBean bean = new SMSRecycleBean((SMSBean)super.readBeanFromJsonReader(jsonReader), 0);
|
||||
// 只有在读取完成后,才能获取整个JSON字符串
|
||||
String completeJson = jsonReader.toString();
|
||||
JsonReader newJsonReader = new JsonReader(new StringReader(completeJson));
|
||||
newJsonReader.setLenient(true);
|
||||
LogUtils.d(TAG, completeJson);*/
|
||||
jsonReader.beginObject();
|
||||
while (jsonReader.hasNext()) {
|
||||
String name = jsonReader.nextName();
|
||||
if (!initObjectsFromJsonReader(jsonReader, name)) {
|
||||
jsonReader.skipValue();
|
||||
}
|
||||
}
|
||||
// 结束 JSON 对象
|
||||
jsonReader.endObject();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean initObjectsFromJsonReader(JsonReader jsonReader, String name) throws IOException {
|
||||
if(super.initObjectsFromJsonReader(jsonReader, name)) { return true; }
|
||||
else{
|
||||
if (name.equals("deleteDate")) {
|
||||
setDeleteDate(jsonReader.nextLong());
|
||||
} else if (name.equals("isSimpleView")) {
|
||||
setIsSimpleView(jsonReader.nextBoolean());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void sortSMSByDeleteDateDesc(ArrayList<SMSRecycleBean> list, boolean isDesc) {
|
||||
Collections.sort(list, new SortSMSByDeleteDateDesc(isDesc));
|
||||
}
|
||||
|
||||
private static class SortSMSByDeleteDateDesc implements Comparator<SMSRecycleBean> {
|
||||
private boolean mIsDesc = true;
|
||||
// isDesc 是否降序排列
|
||||
public SortSMSByDeleteDateDesc(boolean isDesc) {
|
||||
mIsDesc = isDesc;
|
||||
}
|
||||
Collator cmp = Collator.getInstance(java.util.Locale.CHINA);
|
||||
@Override
|
||||
public int compare(SMSRecycleBean o1, SMSRecycleBean o2) {
|
||||
boolean b0_1 = (o1.getDeleteDate() < o2.getDeleteDate());
|
||||
if (mIsDesc) {
|
||||
return b0_1 ?1: -1;
|
||||
} else {
|
||||
return b0_1 ?-1: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
package cc.winboll.studio.mymessagemanager.beans;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2024/05/28 20:22:12
|
||||
* @Describe TTS 语音播放规则类
|
||||
*/
|
||||
import android.util.JsonReader;
|
||||
import android.util.JsonWriter;
|
||||
import cc.winboll.studio.libappbase.BaseBean;
|
||||
import java.io.IOException;
|
||||
|
||||
public class TTSPlayRuleBean extends BaseBean {
|
||||
|
||||
public static final String TAG = "TTSPlayRuleBean";
|
||||
|
||||
// 用户ID
|
||||
int userId = -1;
|
||||
// TTS语音规则名称
|
||||
String ruleName = "";
|
||||
// 短信测试文本
|
||||
String demoSMSText = "";
|
||||
// 短信内容查询正则文本
|
||||
String patternText = "";
|
||||
// TTS语音播报正则文本
|
||||
String ttsRuleText = "";
|
||||
// 是否启用简单视图
|
||||
boolean isSimpleView = false;
|
||||
// 是否启用规则
|
||||
boolean isEnable = false;
|
||||
|
||||
public TTSPlayRuleBean() {}
|
||||
|
||||
public TTSPlayRuleBean(int userId, String ruleName, String demoSMSText, String patternText, String ttsRuleText, boolean isSimpleView, boolean isEnable) {
|
||||
this.userId = userId;
|
||||
this.ruleName = ruleName;
|
||||
this.demoSMSText = demoSMSText;
|
||||
this.patternText = patternText;
|
||||
this.ttsRuleText = ttsRuleText;
|
||||
this.isSimpleView = isSimpleView;
|
||||
this.isEnable = isEnable;
|
||||
}
|
||||
|
||||
public void setUserId(int userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public int getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setRuleName(String ruleName) {
|
||||
this.ruleName = ruleName;
|
||||
}
|
||||
|
||||
public String getRuleName() {
|
||||
return ruleName;
|
||||
}
|
||||
|
||||
public void setDemoSMSText(String demoSMSText) {
|
||||
this.demoSMSText = demoSMSText;
|
||||
}
|
||||
|
||||
public String getDemoSMSText() {
|
||||
return demoSMSText;
|
||||
}
|
||||
|
||||
public void setPatternText(String patternText) {
|
||||
this.patternText = patternText;
|
||||
}
|
||||
|
||||
public String getPatternText() {
|
||||
return patternText;
|
||||
}
|
||||
|
||||
public void setTtsRuleText(String ttsRuleText) {
|
||||
this.ttsRuleText = ttsRuleText;
|
||||
}
|
||||
|
||||
public String getTtsRuleText() {
|
||||
return ttsRuleText;
|
||||
}
|
||||
|
||||
public void setIsSimpleView(boolean isSimpleView) {
|
||||
this.isSimpleView = isSimpleView;
|
||||
}
|
||||
|
||||
public boolean isSimpleView() {
|
||||
return isSimpleView;
|
||||
}
|
||||
|
||||
public void setIsEnable(boolean isEnable) {
|
||||
this.isEnable = isEnable;
|
||||
}
|
||||
|
||||
public boolean isEnable() {
|
||||
return isEnable;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return TTSPlayRuleBean.class.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
|
||||
super.writeThisToJsonWriter(jsonWriter);
|
||||
TTSPlayRuleBean bean = this;
|
||||
jsonWriter.name("userId").value(bean.userId);
|
||||
jsonWriter.name("ruleName").value(bean.ruleName);
|
||||
jsonWriter.name("demoSMSText").value(bean.demoSMSText);
|
||||
jsonWriter.name("patternText").value(bean.patternText);
|
||||
jsonWriter.name("ttdRuleText").value(bean.ttsRuleText);
|
||||
jsonWriter.name("isSimpleView").value(bean.isSimpleView);
|
||||
jsonWriter.name("isEnable").value(bean.isEnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBean readBeanFromJsonReader(JsonReader jsonReader) throws IOException {
|
||||
TTSPlayRuleBean bean = new TTSPlayRuleBean();
|
||||
jsonReader.beginObject();
|
||||
while (jsonReader.hasNext()) {
|
||||
String name = jsonReader.nextName();
|
||||
if (name.equals("userId")) {
|
||||
bean.setUserId(jsonReader.nextInt());
|
||||
} else if (name.equals("ruleName")) {
|
||||
bean.setRuleName(jsonReader.nextString());
|
||||
} else if (name.equals("demoSMSText")) {
|
||||
bean.setDemoSMSText(jsonReader.nextString());
|
||||
} else if (name.equals("patternText")) {
|
||||
bean.setPatternText(jsonReader.nextString());
|
||||
} else if (name.equals("ttdRuleText")) {
|
||||
bean.setTtsRuleText(jsonReader.nextString());
|
||||
} else if (name.equals("isSimpleView")) {
|
||||
bean.setIsSimpleView(jsonReader.nextBoolean());
|
||||
} else if (name.equals("isEnable")) {
|
||||
bean.setIsEnable(jsonReader.nextBoolean());
|
||||
} else {
|
||||
jsonReader.skipValue();
|
||||
}
|
||||
}
|
||||
// 结束 JSON 对象
|
||||
jsonReader.endObject();
|
||||
return bean;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,281 @@
|
||||
package cc.winboll.studio.mymessagemanager.beans;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2024/05/28 20:22:12
|
||||
* @Describe TTS 语音播放规则类,V1 旧版。
|
||||
*/
|
||||
import android.content.Context;
|
||||
import android.util.JsonReader;
|
||||
import android.util.JsonWriter;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.mymessagemanager.utils.FileUtil;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class TTSPlayRuleBean_V1 {
|
||||
|
||||
public static final String TAG = "TTSPlayRuleBean2";
|
||||
|
||||
// 用户ID
|
||||
int userId = -1;
|
||||
// TTS语音规则名称
|
||||
String ruleName = "";
|
||||
// 短信测试文本
|
||||
String demoSMSText = "";
|
||||
// 短信内容查询正则文本
|
||||
String patternText = "";
|
||||
// TTS语音播报正则文本
|
||||
String ttsRuleText = "";
|
||||
// 是否启用简单视图
|
||||
boolean isSimpleView = false;
|
||||
// 是否启用规则
|
||||
boolean isEnable = false;
|
||||
|
||||
public TTSPlayRuleBean_V1(int userId, String ruleName, String demoSMSText, String patternText, String ttsRuleText, boolean isSimpleView, boolean isEnable) {
|
||||
this.userId = userId;
|
||||
this.ruleName = ruleName;
|
||||
this.demoSMSText = demoSMSText;
|
||||
this.patternText = patternText;
|
||||
this.ttsRuleText = ttsRuleText;
|
||||
this.isSimpleView = isSimpleView;
|
||||
this.isEnable = isEnable;
|
||||
}
|
||||
|
||||
public TTSPlayRuleBean_V1() {}
|
||||
|
||||
public void setRuleName(String ruleName) {
|
||||
this.ruleName = ruleName;
|
||||
}
|
||||
|
||||
public String getRuleName() {
|
||||
return ruleName;
|
||||
}
|
||||
|
||||
public void setUserId(int userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public int getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setDemoSMSText(String demoSMSText) {
|
||||
this.demoSMSText = demoSMSText;
|
||||
}
|
||||
|
||||
public String getDemoSMSText() {
|
||||
return demoSMSText;
|
||||
}
|
||||
|
||||
public void setPatternText(String patternText) {
|
||||
this.patternText = patternText;
|
||||
}
|
||||
|
||||
public String getPatternText() {
|
||||
return patternText;
|
||||
}
|
||||
|
||||
public void setTtsRuleText(String ttsRuleText) {
|
||||
this.ttsRuleText = ttsRuleText;
|
||||
}
|
||||
|
||||
public String getTtsRuleText() {
|
||||
return ttsRuleText;
|
||||
}
|
||||
|
||||
public void setIsSimpleView(boolean isSimpleView) {
|
||||
this.isSimpleView = isSimpleView;
|
||||
}
|
||||
|
||||
public boolean isSimpleView() {
|
||||
return isSimpleView;
|
||||
}
|
||||
|
||||
public void setIsEnable(boolean isEnable) {
|
||||
this.isEnable = isEnable;
|
||||
}
|
||||
|
||||
public boolean isEnable() {
|
||||
return isEnable;
|
||||
}
|
||||
|
||||
static String getBeanJsonFilePath(Context context) {
|
||||
return context.getExternalFilesDir(TAG) + "/" + TAG + ".json";
|
||||
}
|
||||
|
||||
static String getBeanListJsonFilePath(Context context) {
|
||||
return context.getExternalFilesDir(TAG) + "/" + TAG + "_List.json";
|
||||
}
|
||||
|
||||
static void writeBean(JsonWriter writer, TTSPlayRuleBean_V1 bean) throws IOException {
|
||||
// 开始 JSON 对象
|
||||
writer.beginObject();
|
||||
// 写入键值对
|
||||
writer.name("userId").value(bean.userId);
|
||||
writer.name("ruleName").value(bean.ruleName);
|
||||
writer.name("demoSMSText").value(bean.demoSMSText);
|
||||
writer.name("patternText").value(bean.patternText);
|
||||
writer.name("ttdRuleText").value(bean.ttsRuleText);
|
||||
writer.name("isSimpleView").value(bean.isSimpleView);
|
||||
writer.name("isEnable").value(bean.isEnable);
|
||||
// 结束 JSON 对象
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
static TTSPlayRuleBean_V1 parseBean(JsonReader jsonReader) {
|
||||
try {
|
||||
TTSPlayRuleBean_V1 bean = new TTSPlayRuleBean_V1();
|
||||
// 开始 JSON 对象
|
||||
jsonReader.beginObject();
|
||||
// 写入键值对
|
||||
while (jsonReader.hasNext()) {
|
||||
String name = jsonReader.nextName();
|
||||
if (name.equals("ruleName")) {
|
||||
bean.setRuleName(jsonReader.nextString());
|
||||
} else if (name.equals("userId")) {
|
||||
bean.setUserId(jsonReader.nextInt());
|
||||
} else if (name.equals("demoSMSText")) {
|
||||
bean.setDemoSMSText(jsonReader.nextString());
|
||||
} else if (name.equals("patternText")) {
|
||||
bean.setPatternText(jsonReader.nextString());
|
||||
} else if (name.equals("ttdRuleText")) {
|
||||
bean.setTtsRuleText(jsonReader.nextString());
|
||||
} else if (name.equals("isSimpleView")) {
|
||||
bean.setIsSimpleView(jsonReader.nextBoolean());
|
||||
} else if (name.equals("isEnable")) {
|
||||
bean.setIsEnable(jsonReader.nextBoolean());
|
||||
} else {
|
||||
jsonReader.skipValue();
|
||||
}
|
||||
}
|
||||
// 结束 JSON 对象
|
||||
jsonReader.endObject();
|
||||
return bean;
|
||||
} catch (IOException e) {
|
||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static ArrayList<TTSPlayRuleBean_V1> parseBeanList(String beanList) {
|
||||
try {
|
||||
StringReader stringReader = new StringReader(beanList);
|
||||
JsonReader jsonReader = new JsonReader(stringReader);
|
||||
ArrayList<TTSPlayRuleBean_V1> list = new ArrayList<TTSPlayRuleBean_V1>();
|
||||
jsonReader.beginArray();
|
||||
while (jsonReader.hasNext()) {
|
||||
TTSPlayRuleBean_V1 bean = parseBean(jsonReader);
|
||||
if (bean != null) {
|
||||
list.add(bean);
|
||||
}
|
||||
}
|
||||
jsonReader.endArray();
|
||||
return list;
|
||||
} catch (IOException e) {
|
||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
// 创建 JsonWriter 对象
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
JsonWriter jsonWriter = new JsonWriter(stringWriter);
|
||||
jsonWriter.setIndent(" ");
|
||||
try {
|
||||
writeBean(jsonWriter, this);
|
||||
return stringWriter.toString();
|
||||
} catch (IOException e) {
|
||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||
}
|
||||
// 获取 JSON 字符串
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String toStringByBeanList(ArrayList<TTSPlayRuleBean_V1> beanList) {
|
||||
try {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
JsonWriter writer = new JsonWriter(stringWriter);
|
||||
writer.setIndent(" ");
|
||||
writer.beginArray();
|
||||
for (TTSPlayRuleBean_V1 bean : beanList) {
|
||||
writeBean(writer, bean);
|
||||
}
|
||||
writer.endArray();
|
||||
writer.close();
|
||||
return stringWriter.toString();
|
||||
} catch (IOException e) {
|
||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static TTSPlayRuleBean_V1 parseBean(String szBean) {
|
||||
// 创建 JsonWriter 对象
|
||||
StringReader stringReader = new StringReader(szBean);
|
||||
JsonReader jsonReader = new JsonReader(stringReader);
|
||||
return parseBean(jsonReader);
|
||||
}
|
||||
|
||||
/*public static TTSPlayRuleBean_V1 loadBean(Context context) {
|
||||
return loadBeanFromFile(getBeanJsonFilePath(context));
|
||||
}
|
||||
|
||||
public static TTSPlayRuleBean_V1 loadBeanFromFile(String szFilePath) {
|
||||
TTSPlayRuleBean_V1 bean = null;
|
||||
try {
|
||||
String szJson = FileUtil.readFile(szFilePath);
|
||||
bean = TTSPlayRuleBean_V1.parseBean(szJson);
|
||||
} catch (IOException e) {
|
||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
|
||||
public static void saveBean(Context context, TTSPlayRuleBean_V1 bean) {
|
||||
saveBeanToFile(getBeanJsonFilePath(context), bean);
|
||||
}
|
||||
|
||||
public static void saveBeanToFile(String szFilePath, TTSPlayRuleBean_V1 bean) {
|
||||
try {
|
||||
String szJson = bean.toString();
|
||||
FileUtil.writeFile(szFilePath, szJson);
|
||||
} catch (IOException e) {
|
||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<TTSPlayRuleBean_V1> loadBeanList(Context context) {
|
||||
return loadBeanListFromFile(getBeanListJsonFilePath(context));
|
||||
}*/
|
||||
|
||||
public static ArrayList<TTSPlayRuleBean_V1> loadBeanListFromFile(String szFilePath) {
|
||||
ArrayList<TTSPlayRuleBean_V1> beanList = null;
|
||||
try {
|
||||
String szListJson = FileUtil.readFile(szFilePath);
|
||||
beanList = TTSPlayRuleBean_V1.parseBeanList(szListJson);
|
||||
} catch (IOException e) {
|
||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||
}
|
||||
return beanList;
|
||||
}
|
||||
|
||||
/*public static boolean saveBeanList(Context context, ArrayList<TTSPlayRuleBean_V1> beanList) {
|
||||
return saveBeanListToFile(getBeanListJsonFilePath(context), beanList);
|
||||
}
|
||||
|
||||
public static boolean saveBeanListToFile(String szFilePath, ArrayList<TTSPlayRuleBean_V1> beanList) {
|
||||
try {
|
||||
String szJson = TTSPlayRuleBean_V1.toStringByBeanList(beanList);
|
||||
FileUtil.writeFile(szFilePath, szJson);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||
}
|
||||
return false;
|
||||
}*/
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package cc.winboll.studio.mymessagemanager.beans;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2024/05/28 20:22:12
|
||||
* @Describe TTS 语音播放文本内容类
|
||||
*/
|
||||
import java.io.Serializable;
|
||||
|
||||
public class TTSSpeakTextBean implements Serializable {
|
||||
|
||||
transient public static final String TAG = "TTSSpeakTextBean";
|
||||
|
||||
// 延迟播放
|
||||
public int mnDelay = 0;
|
||||
// 语音播放内容
|
||||
public String mszSpeakContent = "";
|
||||
|
||||
public TTSSpeakTextBean(int nDelay, String szSpeakContent) {
|
||||
this.mnDelay = nDelay;
|
||||
this.mszSpeakContent = szSpeakContent;
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user