Compare commits
5 Commits
winboll-v1
...
originmast
| Author | SHA1 | Date | |
|---|---|---|---|
| f30a269129 | |||
| 98b48a5926 | |||
| fec41fd737 | |||
| 2f58577537 | |||
| 75e047f1d5 |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -97,5 +97,10 @@ 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_1_7
|
||||
targetCompatibility JavaVersion.VERSION_1_7
|
||||
sourceCompatibility JavaVersion.VERSION_11
|
||||
targetCompatibility JavaVersion.VERSION_11
|
||||
}
|
||||
|
||||
// 应用包输出配置
|
||||
@@ -101,15 +101,12 @@ android {
|
||||
|
||||
// 创建 WinBoLL Studio 发布接口文件夹
|
||||
File fWinBoLLStudioDir = file("/sdcard/WinBoLLStudio/APKs");
|
||||
// 如果配置了APK接口文件夹路径,就设置应用APK输出文件夹为接口文件夹。
|
||||
if(winbollProps != null && winbollProps['APKOutputPath'] != null ) {
|
||||
fWinBoLLStudioDir = file(winbollProps['APKOutputPath']);
|
||||
}
|
||||
|
||||
if(!fWinBoLLStudioDir.exists()) {
|
||||
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 {
|
||||
//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 {
|
||||
/// WINBOLL 主机的 APK 发布和源码管理操作 ///
|
||||
variant.getAssembleProvider().get().doFirst {
|
||||
/* 后期管理预留代码 */
|
||||
|
||||
207
README.md
207
README.md
@@ -1,105 +1,104 @@
|
||||
# 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
|
||||
WinBoLL 源生态计划项目说明书
|
||||
|
||||
|
||||
## 八、WinBoLL 应用 APK 版本号命名规则
|
||||
### ☆ Stage 渠道:
|
||||
#### V<应用开发环境编号><应用功能变更号><应用调试阶段号> (示例: APPBase_15.7.0 )
|
||||
### ☆ Beta 渠道:
|
||||
#### V<应用开发环境编号><应用功能变更号><应用调试阶段号>-beta<调试编译计数>_<调试编译时间(分钟+秒钟)> (示例: APPBase_15.9.6-beta8_5413 )
|
||||
一、项目概述
|
||||
|
||||
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 )
|
||||
|
||||
@@ -24,13 +24,13 @@ android {
|
||||
|
||||
defaultConfig {
|
||||
applicationId "cc.winboll.studio.aes"
|
||||
minSdkVersion 26
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 30
|
||||
versionCode 1
|
||||
// versionName 更新后需要手动设置
|
||||
// 项目模块目录的 build.gradle 文件的 stageCount=0
|
||||
// Gradle编译环境下合起来的 versionName 就是 "${versionName}.0"
|
||||
versionName "15.20"
|
||||
versionName "15.15"
|
||||
if(true) {
|
||||
versionName = genVersionName("${versionName}")
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Tue May 12 10:47:54 CST 2026
|
||||
stageCount=3
|
||||
#Tue Jan 13 03:37:56 HKT 2026
|
||||
stageCount=2
|
||||
libraryProject=libaes
|
||||
baseVersion=15.20
|
||||
publishVersion=15.20.2
|
||||
buildCount=14
|
||||
baseBetaVersion=15.20.3
|
||||
baseVersion=15.15
|
||||
publishVersion=15.15.1
|
||||
buildCount=0
|
||||
baseBetaVersion=15.15.2
|
||||
|
||||
@@ -3,9 +3,6 @@
|
||||
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,29 +1,22 @@
|
||||
package cc.winboll.studio.aes;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import android.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/13 11:25
|
||||
* @Date 2026/01/11 15:16
|
||||
* @Describe 应用介绍窗口
|
||||
*/
|
||||
public class AboutActivity extends BaseWinBoLLActivity {
|
||||
public class AboutActivity extends Activity {
|
||||
|
||||
public static final String TAG = "AboutActivity";
|
||||
|
||||
private Toolbar mToolbar;
|
||||
|
||||
@Override
|
||||
public String getTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -31,33 +24,21 @@ public class AboutActivity extends BaseWinBoLLActivity {
|
||||
setContentView(R.layout.activity_about);
|
||||
|
||||
// 设置工具栏
|
||||
initToolbar();
|
||||
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()
|
||||
}
|
||||
});
|
||||
|
||||
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";
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
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 {
|
||||
public class MainActivity extends DrawerFragmentActivity implements IWinBoLLActivity {
|
||||
|
||||
|
||||
public static final String TAG = "MainActivity";
|
||||
@@ -38,6 +38,11 @@ public class MainActivity extends DrawerFragmentActivity {
|
||||
TestAButtonFragment mTestAButtonFragment;
|
||||
TestViewPageFragment mTestViewPageFragment;
|
||||
|
||||
@Override
|
||||
public Activity getActivity() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTag() {
|
||||
return TAG;
|
||||
@@ -183,9 +188,8 @@ public class MainActivity extends DrawerFragmentActivity {
|
||||
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);
|
||||
WinBoLLActivityManager.getInstance().startWinBoLLActivity(this, AboutActivity.class);
|
||||
Intent intent = new Intent(this, AboutActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -55,6 +55,6 @@ public class WinBoLLActivity extends AppCompatActivity implements IWinBoLLActivi
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
WinBoLLActivityManager.getInstance().finish(this);
|
||||
WinBoLLActivityManager.getInstance().registeRemove(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<cc.winboll.studio.libaes.views.ASupportToolbar
|
||||
<android.widget.Toolbar
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/toolbar"/>
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<style name="MyAESTheme" parent="AESTheme">
|
||||
<item name="themeDebug">@style/MyDebugActivityTheme</item>
|
||||
</style>
|
||||
|
||||
<style name="MyDebugActivityTheme" parent="Theme.AppCompat.NoActionBar">
|
||||
<item name="android:statusBarColor">@color/toolbarBackgroundColor</item>
|
||||
<item name="colorTittle">@color/mainWindowTextColor</item>
|
||||
<item name="colorTittleBackgound">@color/toolbarBackgroundColor</item>
|
||||
<item name="colorText">@color/debugTextColor</item>
|
||||
<item name="colorTextBackgound">@color/mainWindowBackgroundColor</item>
|
||||
<item name="debugTextColor">@color/debugTextColor</item>
|
||||
<item name="toolbarTextColor">@color/toolbarTextColor</item>
|
||||
</style>
|
||||
</resources>
|
||||
@@ -1,16 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<style name="MyAESTheme" parent="AESTheme">
|
||||
<item name="themeDebug">@style/MyDebugActivityTheme</item>
|
||||
</style>
|
||||
|
||||
<style name="MyDebugActivityTheme" parent="Theme.AppCompat.Light.NoActionBar">
|
||||
<item name="android:statusBarColor">@color/toolbarBackgroundColor</item>
|
||||
<item name="colorTittle">@color/mainWindowTextColor</item>
|
||||
<item name="colorTittleBackgound">@color/toolbarBackgroundColor</item>
|
||||
<item name="colorText">@color/debugTextColor</item>
|
||||
<item name="colorTextBackgound">@color/mainWindowBackgroundColor</item>
|
||||
<item name="debugTextColor">@color/debugTextColor</item>
|
||||
<item name="toolbarTextColor">@color/toolbarTextColor</item>
|
||||
</style>
|
||||
</resources>
|
||||
</resources>
|
||||
|
||||
@@ -24,13 +24,13 @@ android {
|
||||
|
||||
defaultConfig {
|
||||
applicationId "cc.winboll.studio.appbase"
|
||||
minSdkVersion 26
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 30
|
||||
versionCode 1
|
||||
// versionName 更新后需要手动设置
|
||||
// .winboll/winbollBuildProps.properties 文件的 stageCount=0
|
||||
// Gradle编译环境下合起来的 versionName 就是 "${versionName}.0"
|
||||
versionName "15.20"
|
||||
versionName "15.15"
|
||||
if(true) {
|
||||
versionName = genVersionName("${versionName}")
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Tue May 12 09:17:15 HKT 2026
|
||||
stageCount=10
|
||||
#Tue Jan 13 03:23:34 HKT 2026
|
||||
stageCount=5
|
||||
libraryProject=libappbase
|
||||
baseVersion=15.20
|
||||
publishVersion=15.20.9
|
||||
baseVersion=15.15
|
||||
publishVersion=15.15.4
|
||||
buildCount=0
|
||||
baseBetaVersion=15.20.10
|
||||
baseBetaVersion=15.15.5
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -9,39 +9,27 @@
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/MyAPPBaseTheme"
|
||||
android:resizeableActivity="true"
|
||||
android:process=":App"
|
||||
android:sharedUserId="@string/shared_user_id"
|
||||
android:sharedUserLabel="@string/shared_user_label">
|
||||
android:process=":App">
|
||||
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:exported="true"
|
||||
android:resizeableActivity="true"
|
||||
android:launchMode="singleTop"
|
||||
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation">
|
||||
|
||||
<intent-filter>
|
||||
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
|
||||
</intent-filter>
|
||||
|
||||
</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,8 +23,17 @@ public class AboutActivity extends Activity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_about);
|
||||
|
||||
// 设置工具栏
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setActionBar(toolbar);
|
||||
setActionBar(toolbar);
|
||||
getActionBar().setSubtitle(TAG);
|
||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish(); // 点击导航栏返回按钮,触发 finish()
|
||||
}
|
||||
});
|
||||
|
||||
AboutView aboutView = findViewById(R.id.aboutview);
|
||||
aboutView.setAPPInfo(genDefaultAppInfo());
|
||||
@@ -34,10 +43,10 @@ public class AboutActivity extends Activity {
|
||||
LogUtils.d(TAG, "genDefaultAppInfo() 调用");
|
||||
String branchName = "appbase";
|
||||
APPInfo appInfo = new APPInfo();
|
||||
appInfo.setAppName("APPBase");
|
||||
appInfo.setAppName(getString(R.string.app_name));
|
||||
appInfo.setAppIcon(R.drawable.ic_winboll);
|
||||
appInfo.setAppDescription(getString(R.string.app_description));
|
||||
appInfo.setAppGitName("WinBoLL");
|
||||
appInfo.setAppGitName("APPBase");
|
||||
appInfo.setAppGitOwner("Studio");
|
||||
appInfo.setAppGitAPPBranch(branchName);
|
||||
appInfo.setAppGitAPPSubProjectFolder(branchName);
|
||||
|
||||
@@ -21,14 +21,9 @@ public class App extends GlobalApplication {
|
||||
*/
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
// 如果应用不在调试状态,就根据编译类型设置调试状态
|
||||
if (isDebugging() != true) {
|
||||
setIsDebugging(BuildConfig.DEBUG);
|
||||
}
|
||||
// release 版调试码
|
||||
//setIsDebugging(!BuildConfig.DEBUG);
|
||||
|
||||
super.onCreate(); // 调用父类初始化逻辑(如基础库配置、全局上下文设置)
|
||||
//setIsDebugging(false);
|
||||
setIsDebugging(BuildConfig.DEBUG);
|
||||
// 初始化 Toast 工具类(传入应用全局上下文,确保 Toast 可在任意地方调用)
|
||||
ToastUtils.init(getApplicationContext());
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package cc.winboll.studio.appbase;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.ToastUtils;
|
||||
|
||||
public class CrashTestActivity extends Activity {
|
||||
|
||||
public static final String TAG = "CrashTestActivity";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_crash_test);
|
||||
LogUtils.d(TAG, "CrashTestActivity onCreate()");
|
||||
}
|
||||
|
||||
public void onBack(View view) {
|
||||
finish();
|
||||
}
|
||||
|
||||
public void onTestCrash(View view) {
|
||||
LogUtils.d(TAG, "onTestCrash()");
|
||||
ToastUtils.show("测试布局崩溃...");
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
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,7 +10,6 @@ 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;
|
||||
@@ -37,28 +36,13 @@ 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";
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建菜单时回调(加载工具栏菜单)
|
||||
@@ -103,17 +87,14 @@ public class MainActivity extends Activity {
|
||||
}
|
||||
}
|
||||
|
||||
public void onLogTestNewTask(View view) {
|
||||
LogActivity.startLogActivity(this, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 日志测试按钮点击事件(打开日志查看界面)
|
||||
* 启动 LogActivity,用于查看应用运行日志
|
||||
* @param view 触发事件的 View(对应布局中的日志测试按钮)
|
||||
*/
|
||||
public void onLogTest(View view) {
|
||||
LogActivity.startLogActivity(this, false);
|
||||
// 启动日志查看 Activity(通过静态方法传入上下文,简化跳转逻辑)
|
||||
LogActivity.startLogActivity(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,23 +136,12 @@ public class MainActivity extends Activity {
|
||||
// 启动意图(唤起浏览器)
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
|
||||
public void onAboutActivity(View view) {
|
||||
LogUtils.d(TAG, "onAboutActivity() 调用");
|
||||
LogUtils.d(TAG, "startAboutActivity() 调用");
|
||||
Intent aboutIntent = new Intent(getApplicationContext(), AboutActivity.class);
|
||||
startActivity(aboutIntent);
|
||||
}
|
||||
|
||||
|
||||
|
||||
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已启动");
|
||||
LogUtils.d(TAG, "startAboutActivity: 关于页面已启动");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,154 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
<?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:background="?attr/activityBackgroundColor">
|
||||
|
||||
<android.widget.Toolbar
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/toolbarBackgroundColor"
|
||||
android:id="@+id/toolbar"/>
|
||||
|
||||
<cc.winboll.studio.libappbase.views.AboutView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1.0"
|
||||
android:id="@+id/aboutview"/>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -1,106 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="0dp"
|
||||
android:background="?attr/activityBackgroundColor">
|
||||
|
||||
<android.widget.Toolbar
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/toolbarBackgroundColor"
|
||||
android:id="@+id/toolbar"/>
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1.0">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center_vertical"
|
||||
android:spacing="12dp">
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="关于应用"
|
||||
android:textSize="16sp"
|
||||
android:textColor="?attr/activityTextColor"
|
||||
android:background="?attr/toolbarBackgroundColor"
|
||||
android:paddingVertical="12dp"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:onClick="onAboutActivity"
|
||||
android:layout_margin="10dp"/>
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="应用崩溃测试"
|
||||
android:textSize="16sp"
|
||||
android:textColor="?attr/activityTextColor"
|
||||
android:background="?attr/toolbarBackgroundColor"
|
||||
android:paddingVertical="12dp"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:onClick="onCrashTest"
|
||||
android:layout_margin="10dp"/>
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="应用日志测试"
|
||||
android:textSize="16sp"
|
||||
android:textColor="?attr/activityTextColor"
|
||||
android:background="?attr/toolbarBackgroundColor"
|
||||
android:paddingVertical="12dp"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:onClick="onLogTest"
|
||||
android:layout_margin="10dp"/>
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="应用日志测试(新窗口)"
|
||||
android:textSize="16sp"
|
||||
android:textColor="?attr/activityTextColor"
|
||||
android:background="?attr/toolbarBackgroundColor"
|
||||
android:paddingVertical="12dp"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:onClick="onLogTestNewTask"
|
||||
android:layout_margin="10dp"/>
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="应用吐司测试"
|
||||
android:textSize="16sp"
|
||||
android:textColor="?attr/activityTextColor"
|
||||
android:background="?attr/toolbarBackgroundColor"
|
||||
android:paddingVertical="12dp"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:onClick="onToastUtilsTest"
|
||||
android:layout_margin="10dp"/>
|
||||
|
||||
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="多开窗口"
|
||||
android:textSize="16sp"
|
||||
android:textColor="?attr/activityTextColor"
|
||||
android:background="?attr/toolbarBackgroundColor"
|
||||
android:paddingVertical="12dp"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:onClick="onMultiInstance"
|
||||
android:layout_margin="10dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -4,13 +4,11 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/activityBackgroundColor">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<android.widget.Toolbar
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/toolbarBackgroundColor"
|
||||
android:id="@+id/toolbar"/>
|
||||
|
||||
<cc.winboll.studio.libappbase.views.AboutView
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="0dp"
|
||||
android:background="?attr/activityBackgroundColor">
|
||||
|
||||
<android.widget.Toolbar
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/toolbarBackgroundColor"
|
||||
android:id="@+id/toolbar"/>
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1.0">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<cc.winboll.studio.appbase.UndefinedCustomView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp"/>
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="返回"
|
||||
android:textSize="16sp"
|
||||
android:textColor="?attr/activityTextColor"
|
||||
android:background="?attr/toolbarBackgroundColor"
|
||||
android:paddingVertical="12dp"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:onClick="onBack"
|
||||
android:layout_margin="10dp"/>
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="测试崩溃"
|
||||
android:textSize="16sp"
|
||||
android:textColor="?attr/activityTextColor"
|
||||
android:background="?attr/toolbarBackgroundColor"
|
||||
android:paddingVertical="12dp"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:onClick="onTestCrash"
|
||||
android:layout_margin="10dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -4,13 +4,11 @@
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="0dp"
|
||||
android:background="?attr/activityBackgroundColor">
|
||||
android:padding="16dp">
|
||||
|
||||
<android.widget.Toolbar
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/toolbarBackgroundColor"
|
||||
android:id="@+id/toolbar"/>
|
||||
|
||||
<ScrollView
|
||||
@@ -25,25 +23,13 @@
|
||||
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="?attr/activityTextColor"
|
||||
android:background="?attr/toolbarBackgroundColor"
|
||||
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"
|
||||
android:text="应用崩溃测试"
|
||||
android:textSize="16sp"
|
||||
android:textColor="?attr/activityTextColor"
|
||||
android:background="?attr/toolbarBackgroundColor"
|
||||
android:textColor="@android:color/white"
|
||||
android:background="#81C7F5"
|
||||
android:paddingVertical="12dp"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:onClick="onCrashTest"
|
||||
@@ -54,53 +40,40 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:text="应用日志测试"
|
||||
android:textSize="16sp"
|
||||
android:textColor="?attr/activityTextColor"
|
||||
android:background="?attr/toolbarBackgroundColor"
|
||||
android:textColor="@android:color/white"
|
||||
android:background="#81C7F5"
|
||||
android:paddingVertical="12dp"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:onClick="onLogTest"
|
||||
android:layout_margin="10dp"/>
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="应用日志测试(新窗口)"
|
||||
android:textSize="16sp"
|
||||
android:textColor="?attr/activityTextColor"
|
||||
android:background="?attr/toolbarBackgroundColor"
|
||||
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"
|
||||
android:text="应用吐司测试"
|
||||
android:textSize="16sp"
|
||||
android:textColor="?attr/activityTextColor"
|
||||
android:background="?attr/toolbarBackgroundColor"
|
||||
android:textColor="@android:color/white"
|
||||
android:background="#81C7F5"
|
||||
android:paddingVertical="12dp"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:onClick="onToastUtilsTest"
|
||||
android:layout_margin="10dp"/>
|
||||
|
||||
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="多开窗口"
|
||||
android:text="关于应用"
|
||||
android:textSize="16sp"
|
||||
android:textColor="?attr/activityTextColor"
|
||||
android:background="?attr/toolbarBackgroundColor"
|
||||
android:textColor="@android:color/white"
|
||||
android:background="#81C7F5"
|
||||
android:paddingVertical="12dp"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:onClick="onMultiInstance"
|
||||
android:onClick="onAboutActivity"
|
||||
android:layout_margin="10dp"/>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:background="?attr/activityBackgroundColor">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Main2Activity"
|
||||
android:textSize="24sp"
|
||||
android:textColor="?attr/activityTextColor"/>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="colorPrimary">#FF1B8B29</color>
|
||||
<color name="colorPrimaryDark">#FF0A5520</color>
|
||||
<color name="colorAccent">#FF6EE87C</color>
|
||||
<color name="colorText">#FFB8FF7D</color>
|
||||
</resources>
|
||||
@@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<style name="MyAPPBaseTheme" parent="APPBaseTheme">
|
||||
<item name="themeDebug">@style/MyDebugActivityTheme</item>
|
||||
</style>
|
||||
|
||||
<style name="MyDebugActivityTheme" parent="DebugActivityTheme">
|
||||
<item name="colorTittle">?attr/mainWindowDarkTextColor</item>
|
||||
<item name="colorTittleBackgound">?attr/toolbarBackgroundColor</item>
|
||||
<item name="colorText">?attr/debugTextColor</item>
|
||||
<item name="colorTextBackgound">?attr/mainWindowDarkBackgroundColor</item>
|
||||
<item name="toolbarTextColor">@color/toolbarTextColor</item>
|
||||
</style>
|
||||
</resources>
|
||||
15
appbase/src/main/res/values/attrs.xml
Normal file
15
appbase/src/main/res/values/attrs.xml
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<declare-styleable name="AboutView">
|
||||
<attr name="app_name" format="string" />
|
||||
<attr name="app_apkfoldername" format="string" />
|
||||
<attr name="app_apkname" format="string" />
|
||||
<attr name="app_gitname" format="string" />
|
||||
<attr name="app_gitowner" format="string" />
|
||||
<attr name="app_gitappbranch" format="string" />
|
||||
<attr name="app_gitappsubprojectfolder" format="string" />
|
||||
<attr name="appdescription" format="string" />
|
||||
<attr name="appicon" format="reference" />
|
||||
<attr name="is_adddebugtools" format="boolean" />
|
||||
</declare-styleable>
|
||||
</resources>
|
||||
@@ -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>
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<style name="MyAPPBaseTheme" parent="APPBaseTheme">
|
||||
<item name="themeDebug">@style/MyDebugActivityTheme</item>
|
||||
<item name="themeGlobalCrashActivity">@style/MyGlobalCrashActivityTheme</item>
|
||||
</style>
|
||||
|
||||
<style name="MyDebugActivityTheme" parent="DebugActivityTheme">
|
||||
<item name="colorTittle">?attr/mainWindowTextColor</item>
|
||||
<item name="colorTittleBackgound">?attr/toolbarBackgroundColor</item>
|
||||
<item name="colorText">?attr/debugTextColor</item>
|
||||
<item name="colorTextBackgound">?attr/mainWindowBackgroundColor</item>
|
||||
<item name="toolbarTextColor">@color/toolbarTextColor</item>
|
||||
<style name="MyGlobalCrashActivityTheme" parent="GlobalCrashActivityTheme">
|
||||
<item name="colorTittle">#FFFFFFFF</item>
|
||||
<item name="colorTittleBackgound">#FF00A4B3</item>
|
||||
<item name="colorText">#FFFFFFFF</item>
|
||||
<item name="colorTextBackgound">#FF000000</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
||||
Binary file not shown.
44
build.gradle
44
build.gradle
@@ -1,15 +1,6 @@
|
||||
// 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/'
|
||||
@@ -20,6 +11,19 @@ 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
|
||||
@@ -31,15 +35,6 @@ 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/'
|
||||
@@ -50,6 +45,19 @@ 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 {
|
||||
// 定义全局变量,常用于版本管理
|
||||
|
||||
@@ -9,7 +9,7 @@ android {
|
||||
buildToolsVersion "30.0.3"
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 26
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 30
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// 权限请求框架:https://github.com/getActivity/XXPermissions
|
||||
api 'com.github.getActivity:XXPermissions:18.63'
|
||||
// 下拉控件
|
||||
api 'com.baoyz.pullrefreshlayout:library:1.2.0'
|
||||
// 拼音搜索
|
||||
@@ -61,7 +63,7 @@ dependencies {
|
||||
//annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
|
||||
|
||||
// WinBoLL库 nexus.winboll.cc 地址
|
||||
api 'cc.winboll.studio:libappbase:15.20.9'
|
||||
api 'cc.winboll.studio:libappbase:15.15.3'
|
||||
// 备用库 jitpack.io 地址
|
||||
//api 'com.github.ZhanGSKen:APPBase:appbase-v15.15.3'
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Tue May 12 10:47:54 CST 2026
|
||||
stageCount=3
|
||||
#Tue Jan 13 03:37:01 HKT 2026
|
||||
stageCount=2
|
||||
libraryProject=libaes
|
||||
baseVersion=15.20
|
||||
publishVersion=15.20.2
|
||||
buildCount=14
|
||||
baseBetaVersion=15.20.3
|
||||
baseVersion=15.15
|
||||
publishVersion=15.15.1
|
||||
buildCount=0
|
||||
baseBetaVersion=15.15.2
|
||||
|
||||
@@ -5,7 +5,6 @@ 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;
|
||||
@@ -28,17 +27,14 @@ 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.libaes.views.ASupportToolbar;
|
||||
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 IWinBoLLActivity, AdapterView.OnItemClickListener {
|
||||
public abstract class DrawerFragmentActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
|
||||
|
||||
public static final String TAG = "DrawerFragmentActivity";
|
||||
|
||||
@@ -65,28 +61,17 @@ public abstract class DrawerFragmentActivity extends AppCompatActivity implement
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
mThemeType = AESThemeBean.getThemeStyleType(AESThemeUtil.getThemeTypeID(getApplicationContext()));
|
||||
setTheme(AESThemeUtil.getThemeTypeID(getApplicationContext()));
|
||||
//mContext = this;
|
||||
mThemeType = getThemeType();
|
||||
setThemeStyle();
|
||||
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);
|
||||
@@ -172,12 +157,26 @@ 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)) {
|
||||
if (mToolbar instanceof ASupportToolbar) {
|
||||
((ASupportToolbar) mToolbar).refreshFromTheme();
|
||||
}
|
||||
recreate();
|
||||
} if (DevelopUtils.onDevelopItemSelected(this, item)) {
|
||||
LogUtils.d(TAG, String.format("onOptionsItemSelected item.getItemId() %d ", item.getItemId()));
|
||||
@@ -191,6 +190,9 @@ 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,24 +1,18 @@
|
||||
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 窗口操作接口
|
||||
*/
|
||||
public interface IWinBoLLActivity {
|
||||
String TAG = "IWinBoLLActivity";
|
||||
String ACTION_BIND = IWinBoLLActivity.class.getName() + ".ACTION_BIND";
|
||||
import android.app.Activity;
|
||||
|
||||
public abstract interface IWinBoLLActivity {
|
||||
|
||||
/**
|
||||
* 获取当前Activity实例
|
||||
*/
|
||||
Activity getActivity();
|
||||
public static final String TAG = "IWinBoLLActivity";
|
||||
|
||||
/**
|
||||
* 获取Activity唯一标识(建议使用类名+UUID或固定唯一字符串)
|
||||
*/
|
||||
String getTag();
|
||||
public static final String ACTION_BIND = IWinBoLLActivity.class.getName() + ".ACTION_BIND";
|
||||
|
||||
public Activity getActivity();
|
||||
public String getTag();
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,11 @@ public class SecondaryLibraryActivity extends DrawerFragmentActivity implements
|
||||
|
||||
SecondaryLibraryFragment mSecondaryLibraryFragment;
|
||||
|
||||
@Override
|
||||
public Activity getActivity() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTag() {
|
||||
return null;
|
||||
|
||||
@@ -12,8 +12,6 @@ import androidx.appcompat.widget.Toolbar;
|
||||
import cc.winboll.studio.libaes.R;
|
||||
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
|
||||
import cc.winboll.studio.libaes.utils.AESThemeUtil;
|
||||
import cc.winboll.studio.libaes.views.ASupportToolbar;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
|
||||
public class TestASupportToolbarActivity extends AppCompatActivity implements IWinBoLLActivity {
|
||||
|
||||
@@ -31,17 +29,14 @@ public class TestASupportToolbarActivity extends AppCompatActivity implements IW
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
LogUtils.d(TAG, "onCreate() start");
|
||||
AESThemeUtil.applyAppTheme(this);
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_testasupporttoolbar);
|
||||
LogUtils.d(TAG, "setContentView() done");
|
||||
Toolbar toolbar = findViewById(R.id.activitytestasupporttoolbarASupportToolbar1);
|
||||
LogUtils.d(TAG, "findViewById() done, toolbar=" + toolbar.getClass().getSimpleName());
|
||||
setSupportActionBar(toolbar);
|
||||
LogUtils.d(TAG, "setSupportActionBar() done");
|
||||
getSupportActionBar().setTitle(TAG);
|
||||
LogUtils.d(TAG, "setTitle() done");
|
||||
LogUtils.d(TAG, "onCreate() end");
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
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;
|
||||
@@ -15,292 +20,273 @@ 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 } // 规范命名 大写开头
|
||||
|
||||
private GlobalApplication mGlobalApplication;
|
||||
private static volatile WinBoLLActivityManager sInstance; // 单例命名规范
|
||||
private final Map<String, IWinBoLLActivity> mActivityListMap; // 私有不可变
|
||||
private static volatile WinBoLLUI_TYPE sWinBoLLUI_TYPE = WinBoLLUI_TYPE.SERVICE;
|
||||
public enum WinBoLLUI_TYPE { Aplication, Service }
|
||||
|
||||
// 私有构造 杜绝外部实例化
|
||||
private WinBoLLActivityManager(@NonNull GlobalApplication application) {
|
||||
mGlobalApplication = application;
|
||||
mActivityListMap = new HashMap<>(); // 菱形泛型简化
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化管理器(必须在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() {
|
||||
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;
|
||||
return _WinBoLLUI_TYPE;
|
||||
}
|
||||
|
||||
WinBoLLActivityManager(GlobalApplication application) {
|
||||
mGlobalApplication = application;
|
||||
mActivityListMap = new HashMap<String, IWinBoLLActivity>();
|
||||
}
|
||||
|
||||
// ===================== 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;
|
||||
public static WinBoLLActivityManager getInstance() {
|
||||
return _mIWinBoLLActivityManager;
|
||||
}
|
||||
|
||||
public static synchronized <T extends GlobalApplication> void init(T application) {
|
||||
if (_mIWinBoLLActivityManager == null) {
|
||||
_mIWinBoLLActivityManager = new WinBoLLActivityManager(application);
|
||||
}
|
||||
mActivityListMap.put(tag, activity);
|
||||
LogUtils.d(TAG, String.format("添加Activity:%s,当前管理数量:%d", tag, mActivityListMap.size()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断指定Tag的Activity是否活跃
|
||||
* 把Activity添加到管理中
|
||||
*/
|
||||
public boolean isActivityActive(@NonNull String tag) {
|
||||
return mActivityListMap.containsKey(tag) && mActivityListMap.get(tag) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据Tag获取Activity(空安全)
|
||||
*/
|
||||
@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;
|
||||
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()));
|
||||
}
|
||||
return activity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除指定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;
|
||||
}
|
||||
|
||||
// ===================== Activity 启动 =====================
|
||||
/**
|
||||
* 启动WinBoLLActivity(存在则前台恢复,不存在则新建多任务窗口)
|
||||
*/
|
||||
public <T extends IWinBoLLActivity> void startWinBoLLActivity(@NonNull Context context, @NonNull Class<T> clazz) {
|
||||
//
|
||||
// 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);
|
||||
setMultiTaskFlags(intent);
|
||||
//打开多任务窗口 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 带Intent参数启动WinBoLLActivity
|
||||
*/
|
||||
public <T extends IWinBoLLActivity> void startWinBoLLActivity(@NonNull Context context, @NonNull Intent intent, @NonNull Class<T> clazz) {
|
||||
public <T extends IWinBoLLActivity> void startWinBoLLActivity(Context context, Intent intent, Class<T> clazz) {
|
||||
// 如果窗口已存在就重启窗口
|
||||
if (!resumeActivity(clazz)) {
|
||||
setMultiTaskFlags(intent);
|
||||
// 新建一个任务窗口
|
||||
//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 void startLogActivity(@NonNull Context context) {
|
||||
public <T extends IWinBoLLActivity> void startLogActivity(Context context) {
|
||||
// 如果窗口已存在就重启窗口
|
||||
//if (!resumeActivity(LogActivity.class)) {
|
||||
// 新建一个任务窗口
|
||||
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) {
|
||||
//打开多任务窗口 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);
|
||||
//}
|
||||
}
|
||||
|
||||
// ===================== Activity 前台恢复 =====================
|
||||
/**
|
||||
* 根据Activity类 恢复前台(反射获取Tag,需保证无参构造)
|
||||
*/
|
||||
public <T extends IWinBoLLActivity> boolean resumeActivity(@NonNull Class<T> clazz) {
|
||||
//
|
||||
// 判断 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 {
|
||||
T instance = clazz.newInstance();
|
||||
return resumeActivity(instance.getTag());
|
||||
Activity activity = getActivityByTag(clazz.newInstance().getTag());
|
||||
if (activity != null) {
|
||||
return resumeActivity(activity);
|
||||
}
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
LogUtils.e(TAG, "恢复Activity失败,类需提供无参构造", e);
|
||||
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据Tag 恢复Activity前台
|
||||
*/
|
||||
public boolean resumeActivity(@NonNull String tag) {
|
||||
//
|
||||
// 找到tag 绑定的 BaseActivity ,通过 getTaskId() 移动到前台
|
||||
//
|
||||
public <T extends IWinBoLLActivity> boolean resumeActivity(String tag) {
|
||||
Activity activity = getActivityByTag(tag);
|
||||
return activity != null && resumeActivity(activity);
|
||||
if (activity != null) {
|
||||
return resumeActivity(activity);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 恢复指定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;
|
||||
}
|
||||
//
|
||||
// 找到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 关闭 =====================
|
||||
|
||||
/**
|
||||
* 结束所有管理的Activity(按UI类型选择关闭策略)
|
||||
* 结束所有 Activity
|
||||
*/
|
||||
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(); // 仅结束页面
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
} catch (Exception e) {
|
||||
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前Activity的上一个栈内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即为上一个
|
||||
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);
|
||||
}
|
||||
}
|
||||
preWinBoLLActivity = entry.getValue();
|
||||
|
||||
} catch (Exception e) {
|
||||
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||
}
|
||||
return preWinBoLLActivity != null ? preWinBoLLActivity.getActivity() : null;
|
||||
}
|
||||
|
||||
// ===================== 调试辅助 =====================
|
||||
/**
|
||||
* 打印所有管理的Activity信息(调试用)
|
||||
*/
|
||||
public void printActivityListInfo() {
|
||||
if (mActivityListMap.isEmpty()) {
|
||||
LogUtils.d(TAG, "当前管理的Activity列表为空");
|
||||
return;
|
||||
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());
|
||||
}
|
||||
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");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public <T extends IWinBoLLActivity> boolean registeRemove(T iWinBoLLActivity) {
|
||||
IWinBoLLActivity iWinBoLLActivityTest = mActivityListMap.get(iWinBoLLActivity.getTag());
|
||||
if (iWinBoLLActivityTest != null) {
|
||||
mActivityListMap.remove(iWinBoLLActivity.getTag());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void printAvtivityListInfo() {
|
||||
if (!mActivityListMap.isEmpty()) {
|
||||
StringBuilder sb = new StringBuilder("Map entries : " + Integer.toString(mActivityListMap.size()));
|
||||
Iterator<Map.Entry<String, IWinBoLLActivity>> iterator = mActivityListMap.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, IWinBoLLActivity> entry = iterator.next();
|
||||
sb.append("\nKey: " + entry.getKey() + ", \nValue: " + entry.getValue().getTag());
|
||||
//ToastUtils.show("\nKey: " + entry.getKey() + ", Value: " + entry.getValue().getTag());
|
||||
}
|
||||
sb.append("\nMap entries end.");
|
||||
LogUtils.d(TAG, sb.toString());
|
||||
} else {
|
||||
LogUtils.d(TAG, "The map is empty.");
|
||||
}
|
||||
LogUtils.d(TAG, sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,12 +7,15 @@ package cc.winboll.studio.libaes.views;
|
||||
*/
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.util.AttributeSet;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import cc.winboll.studio.libaes.R;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import android.graphics.PorterDuff;
|
||||
|
||||
public class ASupportToolbar extends Toolbar {
|
||||
|
||||
@@ -22,120 +25,65 @@ public class ASupportToolbar extends Toolbar {
|
||||
int mStartColor;
|
||||
int mCenterColor;
|
||||
int mEndColor;
|
||||
GradientDrawable[] array = new GradientDrawable[3];
|
||||
LayerDrawable ld;
|
||||
GradientDrawable[] array = new GradientDrawable[3];
|
||||
//private GradientDrawable gradientDrawable;
|
||||
|
||||
public ASupportToolbar(Context context) {
|
||||
super(context);
|
||||
LogUtils.d(TAG, "ASupportToolbar() constructor");
|
||||
}
|
||||
|
||||
public ASupportToolbar(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
LogUtils.d(TAG, "ASupportToolbar() attrs constructor");
|
||||
initStyledAttributes(attrs, R.attr.aSupportToolbar);
|
||||
}
|
||||
|
||||
public ASupportToolbar(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
LogUtils.d(TAG, "ASupportToolbar() attrs defStyleAttr constructor");
|
||||
initStyledAttributes(attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
void initStyledAttributes(AttributeSet attrs, int defStyleAttr) {
|
||||
LogUtils.d(TAG, "initStyledAttributes() start");
|
||||
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ASupportToolbar, defStyleAttr, 0);
|
||||
mTitleTextColor = a.getColor(R.styleable.ASupportToolbar_attrASupportToolbarTitleTextColor, 0xFF00FF00);
|
||||
mStartColor = a.getColor(R.styleable.ASupportToolbar_attrASupportToolbarStartColor, 0xFF03AB4E);
|
||||
mCenterColor = a.getColor(R.styleable.ASupportToolbar_attrASupportToolbarCenterColor, 0xFF03AB4E);
|
||||
mEndColor = a.getColor(R.styleable.ASupportToolbar_attrASupportToolbarEndColor, 0xFF3DDC84);
|
||||
LogUtils.d(TAG, String.format("initStyledAttributes() colors: title=0x%x, start=0x%x, center=0x%x, end=0x%x", mTitleTextColor, mStartColor, mCenterColor, mEndColor));
|
||||
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ASupportToolbar, R.attr.aSupportToolbar, 0);
|
||||
mTitleTextColor = a.getColor(R.styleable.ASupportToolbar_attrASupportToolbarTitleTextColor, Color.GREEN);
|
||||
mStartColor = a.getColor(R.styleable.ASupportToolbar_attrASupportToolbarStartColor, Color.BLUE);
|
||||
mCenterColor = a.getColor(R.styleable.ASupportToolbar_attrASupportToolbarCenterColor, Color.RED);
|
||||
mEndColor = a.getColor(R.styleable.ASupportToolbar_attrASupportToolbarEndColor, Color.YELLOW);
|
||||
// 返回一个绑定资源结束的信号给资源
|
||||
a.recycle();
|
||||
setTitleTextColor(mTitleTextColor);
|
||||
LogUtils.d(TAG, "initStyledAttributes() end");
|
||||
notifyColorChange();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
LogUtils.d(TAG, "onAttachedToWindow() start");
|
||||
refreshFromTheme();
|
||||
LogUtils.d(TAG, "onAttachedToWindow() end");
|
||||
}
|
||||
|
||||
public void refreshFromTheme() {
|
||||
LogUtils.d(TAG, "refreshFromTheme() start");
|
||||
TypedArray a = getContext().obtainStyledAttributes(R.styleable.ASupportToolbar);
|
||||
try {
|
||||
mTitleTextColor = a.getColor(R.styleable.ASupportToolbar_attrASupportToolbarTitleTextColor, 0xFF00FF00);
|
||||
mStartColor = a.getColor(R.styleable.ASupportToolbar_attrASupportToolbarStartColor, 0xFF03AB4E);
|
||||
mCenterColor = a.getColor(R.styleable.ASupportToolbar_attrASupportToolbarCenterColor, 0xFF03AB4E);
|
||||
mEndColor = a.getColor(R.styleable.ASupportToolbar_attrASupportToolbarEndColor, 0xFF3DDC84);
|
||||
LogUtils.d(TAG, String.format("refreshFromTheme() colors: title=0x%x, start=0x%x, center=0x%x, end=0x%x", mTitleTextColor, mStartColor, mCenterColor, mEndColor));
|
||||
} finally {
|
||||
a.recycle();
|
||||
}
|
||||
postNotifyColorChange();
|
||||
LogUtils.d(TAG, "refreshFromTheme() end");
|
||||
}
|
||||
|
||||
void postNotifyColorChange() {
|
||||
LogUtils.d(TAG, "postNotifyColorChange()");
|
||||
removeCallbacks(mRefreshRunnable);
|
||||
post(mRefreshRunnable);
|
||||
}
|
||||
|
||||
Runnable mRefreshRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
LogUtils.d(TAG, "mRefreshRunnable.run() start");
|
||||
notifyColorChange();
|
||||
LogUtils.d(TAG, "mRefreshRunnable.run() end");
|
||||
}
|
||||
};
|
||||
|
||||
void notifyColorChange() {
|
||||
LogUtils.d(TAG, "notifyColorChange() start");
|
||||
LogUtils.d(TAG, String.format("notifyColorChange() size: width=%d, height=%d", getWidth(), getHeight()));
|
||||
|
||||
int nWidth = getWidth();
|
||||
int nHeight = getHeight();
|
||||
if (nWidth == 0 || nHeight == 0) {
|
||||
LogUtils.d(TAG, "notifyColorChange() skipped: width or height is 0");
|
||||
return;
|
||||
}
|
||||
|
||||
// 工具栏描边
|
||||
int nStroke = 5;
|
||||
|
||||
int colors0[] = { mEndColor , mCenterColor, mStartColor };
|
||||
//分别为开始颜色,中间夜色,结束颜色
|
||||
int colors0[] = { mEndColor , mCenterColor, mStartColor};
|
||||
GradientDrawable gradientDrawable0;
|
||||
array[2] = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colors0);
|
||||
array[2].setShape(GradientDrawable.RECTANGLE);
|
||||
array[2].setColors(colors0);
|
||||
array[2].setGradientType(GradientDrawable.LINEAR_GRADIENT);
|
||||
array[2].setCornerRadius(20);
|
||||
gradientDrawable0 = array[2];
|
||||
gradientDrawable0.setShape(GradientDrawable.RECTANGLE);
|
||||
gradientDrawable0.setColors(colors0); //添加颜色组
|
||||
gradientDrawable0.setGradientType(GradientDrawable.LINEAR_GRADIENT);//设置线性渐变
|
||||
gradientDrawable0.setCornerRadius(20);
|
||||
|
||||
int colors1[] = { mCenterColor, mCenterColor, mCenterColor };
|
||||
int colors1[] = { mCenterColor , mCenterColor, mCenterColor };
|
||||
GradientDrawable gradientDrawable1;
|
||||
array[1] = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colors1);
|
||||
array[1].setShape(GradientDrawable.RECTANGLE);
|
||||
array[1].setColors(colors1);
|
||||
array[1].setGradientType(GradientDrawable.LINEAR_GRADIENT);
|
||||
array[1].setCornerRadius(20);
|
||||
gradientDrawable1 = array[1];
|
||||
gradientDrawable1.setShape(GradientDrawable.RECTANGLE);
|
||||
gradientDrawable1.setColors(colors1); //添加颜色组
|
||||
gradientDrawable1.setGradientType(GradientDrawable.LINEAR_GRADIENT);//设置线性渐变
|
||||
gradientDrawable1.setCornerRadius(20);
|
||||
|
||||
int colors2[] = { mEndColor, mCenterColor, mStartColor };
|
||||
int colors2[] = { mEndColor, mCenterColor, mStartColor };
|
||||
GradientDrawable gradientDrawable2;
|
||||
array[0] = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colors2);
|
||||
array[0].setShape(GradientDrawable.RECTANGLE);
|
||||
array[0].setColors(colors2);
|
||||
array[0].setGradientType(GradientDrawable.LINEAR_GRADIENT);
|
||||
array[0].setCornerRadius(20);
|
||||
gradientDrawable2 = array[0];
|
||||
gradientDrawable2.setShape(GradientDrawable.RECTANGLE);
|
||||
gradientDrawable2.setColors(colors2); //添加颜色组
|
||||
gradientDrawable2.setGradientType(GradientDrawable.LINEAR_GRADIENT);//设置线性渐变
|
||||
gradientDrawable2.setCornerRadius(20);
|
||||
|
||||
ld = new LayerDrawable(array);
|
||||
ld.setLayerInset(2, nStroke * 2, nStroke * 2, nWidth + nStroke * 2, nHeight + nStroke * 2);
|
||||
ld.setLayerInset(1, nStroke, nStroke, nWidth + nStroke, nHeight + nStroke);
|
||||
ld.setLayerInset(0, 0, 0, nWidth, nHeight);
|
||||
ld = new LayerDrawable(array); //参数为上面的Drawable数组
|
||||
ld.setLayerInset(2, nStroke * 2, nStroke * 2, getWidth() + nStroke * 2, getHeight() + nStroke * 2);
|
||||
ld.setLayerInset(1, nStroke, nStroke, getWidth() + nStroke, getHeight() + nStroke);
|
||||
ld.setLayerInset(0, 0, 0, getWidth(), getHeight());
|
||||
|
||||
setBackgroundDrawable(ld);
|
||||
setTitleTextColor(mTitleTextColor);
|
||||
setSubtitleTextColor(mTitleTextColor);
|
||||
LogUtils.d(TAG, "notifyColorChange() end");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<color name="colorTextColor">#FFFFFFFF</color>
|
||||
<color name="colorPrimary">#FF03AB4E</color>
|
||||
<color name="colorPrimaryDark">#FF027C39</color>
|
||||
<color name="colorAccent">#FF3DDC84</color>
|
||||
<color name="colorText">#FFFFFB8D</color>
|
||||
<color name="colorToastFrame">#FFA9A9A9</color>
|
||||
<color name="colorToastShadow">#FF000000</color>
|
||||
<color name="colorToastBackgroung">#FFFFFFFF</color>
|
||||
<color name="colorAToolbarStartColor">#FF7D3F12</color>
|
||||
<color name="colorAToolbarCenterColor">#FFCC6E2B</color>
|
||||
<color name="colorAToolbarEndColor">#FFF4B98F</color>
|
||||
|
||||
<color name="colorACardShadow">@color/colorPrimaryDark</color>
|
||||
<color name="colorACardFrame">@color/colorPrimary</color>
|
||||
<color name="colorACardBackgroung">@color/colorAccent</color>
|
||||
|
||||
<color name="colorATickProgressBarBackgroung">@color/colorAccent</color>
|
||||
<color name="colorATickProgressBarProgress">@color/colorPrimary</color>
|
||||
|
||||
<color name="colorOHPCTSBackground">@color/colorAccent</color>
|
||||
<color name="colorOHPCTSSecondaryProgress">@color/colorPrimary</color>
|
||||
<color name="colorOHPCTSProgress">@color/colorPrimaryDark</color>
|
||||
|
||||
<color name="toolbarBackgroundColor">#FF03AB4E</color>
|
||||
<color name="toolbarTextColor">#FFFFFFFF</color>
|
||||
<color name="mainWindowBackgroundColor">#FF2C2C2C</color>
|
||||
<color name="mainWindowTextColor">#FFFFFFFF</color>
|
||||
<color name="debugTextColor">#FFFF0000</color>
|
||||
|
||||
</resources>
|
||||
@@ -1,112 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<style name="AESTheme" parent="Theme.AppCompat.NoActionBar">
|
||||
<item name="themeDebug">@style/DebugActivityTheme</item>
|
||||
<item name="aboutViewBackgroundColor">@color/mainWindowBackgroundColor</item>
|
||||
<item name="aboutViewTextColor">@color/mainWindowTextColor</item>
|
||||
<item name="aboutViewTitleColor">@color/mainWindowTextColor</item>
|
||||
<item name="aboutViewDividerColor">@color/mainWindowTextColor</item>
|
||||
<item name="dialogBackgroundColor">@color/mainWindowBackgroundColor</item>
|
||||
<item name="dialogTextColor">@color/mainWindowTextColor</item>
|
||||
<item name="toolbarBackgroundColor">@color/toolbarBackgroundColor</item>
|
||||
<item name="toolbarTextColor">@color/toolbarTextColor</item>
|
||||
<item name="textViewBackgroundColor">@color/mainWindowBackgroundColor</item>
|
||||
<item name="textViewTextColor">@color/mainWindowTextColor</item>
|
||||
<item name="editTextBackgroundColor">@color/mainWindowBackgroundColor</item>
|
||||
<item name="editTextTextColor">@color/mainWindowTextColor</item>
|
||||
<item name="scrollViewBackgroundColor">@color/mainWindowBackgroundColor</item>
|
||||
<item name="activityBackgroundColor">@color/mainWindowBackgroundColor</item>
|
||||
<item name="activityTextColor">@color/mainWindowTextColor</item>
|
||||
<item name="mainWindowBackgroundColor">@color/mainWindowBackgroundColor</item>
|
||||
<item name="mainWindowTextColor">@color/mainWindowTextColor</item>
|
||||
<item name="mainWindowDarkBackgroundColor">@color/mainWindowBackgroundColor</item>
|
||||
<item name="mainWindowDarkTextColor">@color/mainWindowTextColor</item>
|
||||
<item name="android:statusBarColor">@color/toolbarBackgroundColor</item>
|
||||
|
||||
<item name="aToolbar">@style/AESAToolbar</item>
|
||||
<item name="aSupportToolbar">@style/AESASupportToolbar</item>
|
||||
</style>
|
||||
|
||||
<style name="DebugActivityTheme" parent="Theme.AppCompat.NoActionBar">
|
||||
<item name="android:statusBarColor">@color/toolbarBackgroundColor</item>
|
||||
<item name="colorTittle">@color/mainWindowTextColor</item>
|
||||
<item name="colorTittleBackgound">@color/toolbarBackgroundColor</item>
|
||||
<item name="colorText">@color/debugTextColor</item>
|
||||
<item name="colorTextBackgound">@color/mainWindowBackgroundColor</item>
|
||||
<item name="debugTextColor">@color/debugTextColor</item>
|
||||
<item name="toolbarTextColor">@color/toolbarTextColor</item>
|
||||
</style>
|
||||
|
||||
<style name="AESAToolbar">
|
||||
<item name="attrAToolbarTitleTextColor">@color/colorTextColor</item>
|
||||
<item name="attrAToolbarStartColor">@color/colorPrimaryDark</item>
|
||||
<item name="attrAToolbarCenterColor">@color/colorPrimary</item>
|
||||
<item name="attrAToolbarEndColor">@color/colorAccent</item>
|
||||
</style>
|
||||
|
||||
<style name="AESASupportToolbar">
|
||||
<item name="attrASupportToolbarTitleTextColor">@color/colorTextColor</item>
|
||||
<item name="attrASupportToolbarStartColor">@color/colorPrimaryDark</item>
|
||||
<item name="attrASupportToolbarCenterColor">@color/colorPrimary</item>
|
||||
<item name="attrASupportToolbarEndColor">@color/colorAccent</item>
|
||||
</style>
|
||||
|
||||
<style name="DepthAESTheme" parent="AESTheme">
|
||||
<item name="colorPrimary">#FF0065EC</item>
|
||||
<item name="colorPrimaryDark">#FF004DB4</item>
|
||||
<item name="colorAccent">#FF4A97FF</item>
|
||||
</style>
|
||||
|
||||
<style name="SkyAESTheme" parent="AESTheme">
|
||||
<item name="colorPrimary">#FF00A6FF</item>
|
||||
<item name="colorPrimaryDark">#FF007ABB</item>
|
||||
<item name="colorAccent">#FF84D4FF</item>
|
||||
</style>
|
||||
|
||||
<style name="GoldenAESTheme" parent="AESTheme">
|
||||
<item name="colorPrimary">#FFF0CA11</item>
|
||||
<item name="colorPrimaryDark">#FFD3AF00</item>
|
||||
<item name="colorAccent">#FFFFE35C</item>
|
||||
</style>
|
||||
|
||||
<style name="BearingAESTheme" parent="AESTheme">
|
||||
<item name="colorPrimary">#FF840FFF</item>
|
||||
<item name="colorPrimaryDark">#FF6900D7</item>
|
||||
<item name="colorAccent">#FFBA78FF</item>
|
||||
</style>
|
||||
|
||||
<style name="MemorAESTheme" parent="AESTheme">
|
||||
<item name="colorPrimary">#FFFF00F5</item>
|
||||
<item name="colorPrimaryDark">#FFE500DC</item>
|
||||
<item name="colorAccent">#FFFF76FA</item>
|
||||
</style>
|
||||
|
||||
<style name="TaoAESTheme" parent="AESTheme">
|
||||
<item name="colorPrimary">#FFACACAC</item>
|
||||
<item name="colorPrimaryDark">#FF898989</item>
|
||||
<item name="colorAccent">#FFD8D8D8</item>
|
||||
</style>
|
||||
|
||||
<style name="NormalDialogStyle" parent="Theme.AppCompat.Dialog">
|
||||
<item name="android:windowBackground">@android:color/transparent</item>
|
||||
<item name="android:windowFrame">@null</item>
|
||||
<item name="android:windowNoTitle">true</item>
|
||||
<item name="android:windowIsFloating">true</item>
|
||||
<item name="android:windowIsTranslucent">false</item>
|
||||
<item name="android:windowContentOverlay">@null</item>
|
||||
<item name="android:windowAnimationStyle">@style/cornerDialogAnim</item>
|
||||
<item name="android:backgroundDimEnabled">true</item>
|
||||
</style>
|
||||
|
||||
<style name="centerDialogAnim" parent="android:Animation">
|
||||
<item name="@android:windowEnterAnimation">@anim/normal_dialog_enter_center</item>
|
||||
<item name="@android:windowExitAnimation">@anim/normal_dialog_exit_center</item>
|
||||
</style>
|
||||
|
||||
<style name="cornerDialogAnim" parent="android:Animation">
|
||||
<item name="@android:windowEnterAnimation">@anim/normal_dialog_enter_corner</item>
|
||||
<item name="@android:windowExitAnimation">@anim/normal_dialog_exit_corner</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
@@ -43,7 +43,6 @@
|
||||
<attr name="attrASupportToolbarStartColor"/>
|
||||
<attr name="attrASupportToolbarCenterColor"/>
|
||||
<attr name="attrASupportToolbarEndColor"/>
|
||||
<attr name="android:background"/>
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="AButton">
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<color name="colorTextColor">#FF000000</color>
|
||||
|
||||
<!-- 默认方案 -->
|
||||
<color name="colorPrimary">#FF03AB4E</color>
|
||||
<color name="colorPrimaryDark">#FF027C39</color>
|
||||
<color name="colorAccent">#FF3DDC84</color>
|
||||
<color name="colorText">#FFFFFB8D</color>
|
||||
<color name="colorText">#FFFFFB8D</color>
|
||||
<color name="colorToastFrame">#FFA9A9A9</color>
|
||||
<color name="colorToastShadow">#FF000000</color>
|
||||
<color name="colorToastBackgroung">#FFFFFFFF</color>
|
||||
@@ -24,10 +24,22 @@
|
||||
<color name="colorOHPCTSSecondaryProgress">@color/colorPrimary</color>
|
||||
<color name="colorOHPCTSProgress">@color/colorPrimaryDark</color>
|
||||
|
||||
<color name="toolbarBackgroundColor">#FF03AB4E</color>
|
||||
<color name="toolbarTextColor">#FFFFFFFF</color>
|
||||
<color name="mainWindowBackgroundColor">#FFFFFFFF</color>
|
||||
<color name="mainWindowTextColor">#FF000000</color>
|
||||
<color name="debugTextColor">#FFFF0000</color>
|
||||
<!-- -->
|
||||
|
||||
</resources>
|
||||
<!-- 调试方案
|
||||
<color name="colorPrimary">#FF727272</color>
|
||||
<color name="colorPrimaryDark">#FF444444</color>
|
||||
<color name="colorAccent">#FF9EA19F</color>
|
||||
|
||||
<color name="colorAToolbarStartColor">#FF4776EB</color>
|
||||
<color name="colorAToolbarCenterColor">#FF0D4BE7</color>
|
||||
<color name="colorAToolbarEndColor">#FF8FA7E3</color>
|
||||
|
||||
<color name="colorACardShadow">#FF22A200</color>
|
||||
<color name="colorACardFrame">#FF3FCC19</color>
|
||||
<color name="colorACardBackgroung">#FF88F16B</color>
|
||||
|
||||
<color name="colorATickProgressBarBackgroung">#FF6DC4E2</color>
|
||||
<color name="colorATickProgressBarProgress">#FF22B0E1</color>
|
||||
-->
|
||||
</resources>
|
||||
|
||||
@@ -1,112 +1,255 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<style name="AESTheme" parent="Theme.AppCompat.Light.NoActionBar">
|
||||
<item name="themeDebug">@style/DebugActivityTheme</item>
|
||||
<item name="aboutViewBackgroundColor">@color/mainWindowBackgroundColor</item>
|
||||
<item name="aboutViewTextColor">@color/mainWindowTextColor</item>
|
||||
<item name="aboutViewTitleColor">@color/mainWindowTextColor</item>
|
||||
<item name="aboutViewDividerColor">@color/mainWindowTextColor</item>
|
||||
<item name="dialogBackgroundColor">@color/mainWindowBackgroundColor</item>
|
||||
<item name="dialogTextColor">@color/mainWindowTextColor</item>
|
||||
<item name="toolbarBackgroundColor">@color/toolbarBackgroundColor</item>
|
||||
<item name="toolbarTextColor">@color/toolbarTextColor</item>
|
||||
<item name="textViewBackgroundColor">@color/mainWindowBackgroundColor</item>
|
||||
<item name="textViewTextColor">@color/mainWindowTextColor</item>
|
||||
<item name="editTextBackgroundColor">@color/mainWindowBackgroundColor</item>
|
||||
<item name="editTextTextColor">@color/mainWindowTextColor</item>
|
||||
<item name="scrollViewBackgroundColor">@color/mainWindowBackgroundColor</item>
|
||||
<item name="activityBackgroundColor">@color/mainWindowBackgroundColor</item>
|
||||
<item name="activityTextColor">@color/mainWindowTextColor</item>
|
||||
<item name="mainWindowBackgroundColor">@color/mainWindowBackgroundColor</item>
|
||||
<item name="mainWindowTextColor">@color/mainWindowTextColor</item>
|
||||
<item name="mainWindowDarkBackgroundColor">@color/mainWindowBackgroundColor</item>
|
||||
<item name="mainWindowDarkTextColor">@color/mainWindowTextColor</item>
|
||||
<item name="android:statusBarColor">@color/toolbarBackgroundColor</item>
|
||||
|
||||
<item name="colorTextColor">#FF000000</item>
|
||||
<item name="colorPrimary">#FF18B05C</item>
|
||||
<item name="colorPrimaryDark">#FF008C3F</item>
|
||||
<item name="colorAccent">#FF24DC77</item>
|
||||
<item name="android:textColor">#FF000000</item>
|
||||
<item name="aToolbar">@style/AESAToolbar</item>
|
||||
<item name="aSupportToolbar">@style/AESASupportToolbar</item>
|
||||
</style>
|
||||
|
||||
<style name="DebugActivityTheme" parent="Theme.AppCompat.Light.NoActionBar">
|
||||
<item name="android:statusBarColor">@color/toolbarBackgroundColor</item>
|
||||
<item name="colorTittle">@color/mainWindowTextColor</item>
|
||||
<item name="colorTittleBackgound">@color/toolbarBackgroundColor</item>
|
||||
<item name="colorText">@color/debugTextColor</item>
|
||||
<item name="colorTextBackgound">@color/mainWindowBackgroundColor</item>
|
||||
<item name="debugTextColor">@color/debugTextColor</item>
|
||||
<item name="toolbarTextColor">@color/toolbarTextColor</item>
|
||||
</style>
|
||||
|
||||
<style name="AESAToolbar">
|
||||
<item name="attrAToolbarTitleTextColor">@color/colorTextColor</item>
|
||||
<item name="attrAToolbarStartColor">@color/colorPrimaryDark</item>
|
||||
<item name="attrAToolbarCenterColor">@color/colorPrimary</item>
|
||||
<item name="attrAToolbarEndColor">@color/colorAccent</item>
|
||||
<item name="attrAToolbarTitleTextColor">?attr/colorTextColor</item>
|
||||
<item name="attrAToolbarStartColor">?attr/colorPrimaryDark</item>
|
||||
<item name="attrAToolbarCenterColor">?attr/colorPrimary</item>
|
||||
<item name="attrAToolbarEndColor">?attr/colorAccent</item>
|
||||
</style>
|
||||
|
||||
<style name="AESASupportToolbar">
|
||||
<item name="attrASupportToolbarTitleTextColor">@color/colorTextColor</item>
|
||||
<item name="attrASupportToolbarStartColor">@color/colorPrimaryDark</item>
|
||||
<item name="attrASupportToolbarCenterColor">@color/colorPrimary</item>
|
||||
<item name="attrASupportToolbarEndColor">@color/colorAccent</item>
|
||||
<item name="attrASupportToolbarTitleTextColor">?attr/colorTextColor</item>
|
||||
<item name="attrASupportToolbarStartColor">?attr/colorPrimaryDark</item>
|
||||
<item name="attrASupportToolbarCenterColor">?attr/colorPrimary</item>
|
||||
<item name="attrASupportToolbarEndColor">?attr/colorAccent</item>
|
||||
</style>
|
||||
|
||||
<style name="DepthAESTheme" parent="AESTheme">
|
||||
<item name="colorTextColor">#FF000000</item>
|
||||
<item name="colorPrimary">#FF0065EC</item>
|
||||
<item name="colorPrimaryDark">#FF004DB4</item>
|
||||
<item name="colorAccent">#FF4A97FF</item>
|
||||
<item name="android:textColor">#FF000000</item>
|
||||
</style>
|
||||
|
||||
<style name="SkyAESTheme" parent="AESTheme">
|
||||
<item name="colorTextColor">#FF000000</item>
|
||||
<item name="colorPrimary">#FF00A6FF</item>
|
||||
<item name="colorPrimaryDark">#FF007ABB</item>
|
||||
<item name="colorAccent">#FF84D4FF</item>
|
||||
<item name="android:textColor">#FF000000</item>
|
||||
</style>
|
||||
|
||||
<style name="GoldenAESTheme" parent="AESTheme">
|
||||
<item name="colorTextColor">#FF000000</item>
|
||||
<item name="colorPrimary">#FFF0CA11</item>
|
||||
<item name="colorPrimaryDark">#FFD3AF00</item>
|
||||
<item name="colorAccent">#FFFFE35C</item>
|
||||
<item name="android:textColor">#FF000000</item>
|
||||
</style>
|
||||
|
||||
|
||||
<style name="BearingAESTheme" parent="AESTheme">
|
||||
<item name="colorTextColor">#FF000000</item>
|
||||
<item name="colorPrimary">#FF840FFF</item>
|
||||
<item name="colorPrimaryDark">#FF6900D7</item>
|
||||
<item name="colorAccent">#FFBA78FF</item>
|
||||
<item name="android:textColor">#FF000000</item>
|
||||
</style>
|
||||
|
||||
<style name="MemorAESTheme" parent="AESTheme">
|
||||
<item name="colorTextColor">#FF000000</item>
|
||||
<item name="colorPrimary">#FFFF00F5</item>
|
||||
<item name="colorPrimaryDark">#FFE500DC</item>
|
||||
<item name="colorAccent">#FFFF76FA</item>
|
||||
<item name="android:textColor">#FF000000</item>
|
||||
</style>
|
||||
|
||||
<style name="TaoAESTheme" parent="AESTheme">
|
||||
<item name="colorTextColor">#FF000000</item>
|
||||
<item name="colorPrimary">#FFACACAC</item>
|
||||
<item name="colorPrimaryDark">#FF898989</item>
|
||||
<item name="colorAccent">#FFD8D8D8</item>
|
||||
<item name="android:textColor">#FF000000</item>
|
||||
</style>
|
||||
|
||||
<style name="NormalDialogStyle" parent="Theme.AppCompat.Light.Dialog">
|
||||
<!--<style name="AESTheme" parent="Theme.AppCompat.Light.NoActionBar">
|
||||
<item name="colorTextColor">#FF000000</item>
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
<item name="android:textColor">#FF000000</item>
|
||||
<item name="aToolbar">@style/AESAToolbar</item>
|
||||
<item name="aSupportToolbar">@style/AESASupportToolbar</item>
|
||||
</style>
|
||||
|
||||
<style name="AESAToolbar">
|
||||
<item name="attrAToolbarTitleTextColor">?attr/colorTextColor</item>
|
||||
<item name="attrAToolbarStartColor">?attr/colorPrimaryDark</item>
|
||||
<item name="attrAToolbarCenterColor">?attr/colorPrimary</item>
|
||||
<item name="attrAToolbarEndColor">?attr/colorAccent</item>
|
||||
</style>
|
||||
|
||||
<style name="AESASupportToolbar">
|
||||
<item name="attrASupportToolbarTitleTextColor">?attr/colorTextColor</item>
|
||||
<item name="attrASupportToolbarStartColor">?attr/colorPrimaryDark</item>
|
||||
<item name="attrASupportToolbarCenterColor">?attr/colorPrimary</item>
|
||||
<item name="attrASupportToolbarEndColor">?attr/colorAccent</item>
|
||||
</style>-->
|
||||
|
||||
<!--<style name="DepthAESTheme" parent="Theme.AppCompat.Light.NoActionBar">
|
||||
<item name="colorTextColor">#FF000000</item>
|
||||
<item name="colorPrimary">#FF2566FE</item>
|
||||
<item name="colorPrimaryDark">#FF1359FF</item>
|
||||
<item name="colorAccent">#FF8BAEFF</item>
|
||||
<item name="android:textColor">#FF000000</item>
|
||||
<item name="aToolbar">@style/DepthAToolbar</item>
|
||||
<item name="aSupportToolbar">@style/DepthASupportToolbar</item>
|
||||
</style>
|
||||
|
||||
<style name="DepthAToolbar">
|
||||
<item name="attrAToolbarTitleTextColor">?attr/colorTextColor</item>
|
||||
<item name="attrAToolbarStartColor">?attr/colorPrimaryDark</item>
|
||||
<item name="attrAToolbarCenterColor">?attr/colorPrimary</item>
|
||||
<item name="attrAToolbarEndColor">?attr/colorAccent</item>
|
||||
</style>
|
||||
|
||||
<style name="DepthASupportToolbar">
|
||||
<item name="attrASupportToolbarTitleTextColor">?attr/colorTextColor</item>
|
||||
<item name="attrASupportToolbarStartColor">?attr/colorPrimaryDark</item>
|
||||
<item name="attrASupportToolbarCenterColor">?attr/colorPrimary</item>
|
||||
<item name="attrASupportToolbarEndColor">?attr/colorAccent</item>
|
||||
</style>
|
||||
|
||||
<style name="SkyAESTheme" parent="Theme.AppCompat.Light.NoActionBar">
|
||||
<item name="colorTextColor">#FF000000</item>
|
||||
<item name="colorPrimary">#FF1E98D4</item>
|
||||
<item name="colorPrimaryDark">#FF046A9C</item>
|
||||
<item name="colorAccent">#FF8CD9FF</item>
|
||||
<item name="android:textColor">#FF000000</item>
|
||||
<item name="aToolbar">@style/SkyAToolbar</item>
|
||||
<item name="aSupportToolbar">@style/SkyASupportToolbar</item>
|
||||
</style>
|
||||
|
||||
<style name="SkyAToolbar">
|
||||
<item name="attrAToolbarTitleTextColor">?attr/colorTextColor</item>
|
||||
<item name="attrAToolbarStartColor">?attr/colorPrimaryDark</item>
|
||||
<item name="attrAToolbarCenterColor">?attr/colorPrimary</item>
|
||||
<item name="attrAToolbarEndColor">?attr/colorAccent</item>
|
||||
</style>
|
||||
|
||||
<style name="SkyASupportToolbar">
|
||||
<item name="attrASupportToolbarTitleTextColor">?attr/colorTextColor</item>
|
||||
<item name="attrASupportToolbarStartColor">?attr/colorPrimaryDark</item>
|
||||
<item name="attrASupportToolbarCenterColor">?attr/colorPrimary</item>
|
||||
<item name="attrASupportToolbarEndColor">?attr/colorAccent</item>
|
||||
</style>
|
||||
|
||||
<style name="GoldenAESTheme" parent="Theme.AppCompat.Light.NoActionBar">
|
||||
<item name="colorTextColor">#FF000000</item>
|
||||
<item name="colorPrimary">#FFFFE22A</item>
|
||||
<item name="colorPrimaryDark">#FFAE9600</item>
|
||||
<item name="colorAccent">#FFFFED78</item>
|
||||
<item name="android:textColor">#FF000000</item>
|
||||
<item name="aToolbar">@style/GoldenAToolbar</item>
|
||||
<item name="aSupportToolbar">@style/GoldenASupportToolbar</item>
|
||||
</style>
|
||||
|
||||
<style name="GoldenAToolbar">
|
||||
<item name="attrAToolbarTitleTextColor">?attr/colorTextColor</item>
|
||||
<item name="attrAToolbarStartColor">?attr/colorPrimaryDark</item>
|
||||
<item name="attrAToolbarCenterColor">?attr/colorPrimary</item>
|
||||
<item name="attrAToolbarEndColor">?attr/colorAccent</item>
|
||||
</style>
|
||||
|
||||
<style name="GoldenASupportToolbar">
|
||||
<item name="attrASupportToolbarTitleTextColor">?attr/colorTextColor</item>
|
||||
<item name="attrASupportToolbarStartColor">?attr/colorPrimaryDark</item>
|
||||
<item name="attrASupportToolbarCenterColor">?attr/colorPrimary</item>
|
||||
<item name="attrASupportToolbarEndColor">?attr/colorAccent</item>
|
||||
</style>
|
||||
|
||||
<style name="MemorAESTheme" parent="Theme.AppCompat.Light.NoActionBar">
|
||||
<item name="colorTextColor">#FF000000</item>
|
||||
<item name="colorPrimary">#FFCE1ED4</item>
|
||||
<item name="colorPrimaryDark">#FFB500BC</item>
|
||||
<item name="colorAccent">#FFE653EB</item>
|
||||
<item name="android:textColor">#FF000000</item>
|
||||
<item name="aToolbar">@style/MemorAToolbar</item>
|
||||
<item name="aSupportToolbar">@style/MemorASupportToolbar</item>
|
||||
</style>
|
||||
|
||||
<style name="MemorAToolbar">
|
||||
<item name="attrAToolbarTitleTextColor">?attr/colorTextColor</item>
|
||||
<item name="attrAToolbarStartColor">?attr/colorPrimaryDark</item>
|
||||
<item name="attrAToolbarCenterColor">?attr/colorPrimary</item>
|
||||
<item name="attrAToolbarEndColor">?attr/colorAccent</item>
|
||||
</style>
|
||||
|
||||
<style name="MemorASupportToolbar">
|
||||
<item name="attrASupportToolbarTitleTextColor">?attr/colorTextColor</item>
|
||||
<item name="attrASupportToolbarStartColor">?attr/colorPrimaryDark</item>
|
||||
<item name="attrASupportToolbarCenterColor">?attr/colorPrimary</item>
|
||||
<item name="attrASupportToolbarEndColor">?attr/colorAccent</item>
|
||||
</style>
|
||||
|
||||
<style name="TaoAESTheme" parent="Theme.AppCompat.Light.NoActionBar">
|
||||
<item name="colorTextColor">#FF000000</item>
|
||||
<item name="colorPrimary">#FF9F9F9F</item>
|
||||
<item name="colorPrimaryDark">#FF5E5E5E</item>
|
||||
<item name="colorAccent">#FFD9D9D9</item>
|
||||
<item name="android:textColor">#FF000000</item>
|
||||
<item name="aToolbar">@style/TaoAToolbar</item>
|
||||
<item name="aSupportToolbar">@style/TaoASupportToolbar</item>
|
||||
</style>
|
||||
|
||||
<style name="TaoAToolbar">
|
||||
<item name="attrAToolbarTitleTextColor">?attr/colorTextColor</item>
|
||||
<item name="attrAToolbarStartColor">?attr/colorPrimaryDark</item>
|
||||
<item name="attrAToolbarCenterColor">?attr/colorPrimary</item>
|
||||
<item name="attrAToolbarEndColor">?attr/colorAccent</item>
|
||||
</style>
|
||||
|
||||
<style name="TaoASupportToolbar">
|
||||
<item name="attrASupportToolbarTitleTextColor">?attr/colorTextColor</item>
|
||||
<item name="attrASupportToolbarStartColor">?attr/colorPrimaryDark</item>
|
||||
<item name="attrASupportToolbarCenterColor">?attr/colorPrimary</item>
|
||||
<item name="attrASupportToolbarEndColor">?attr/colorAccent</item>
|
||||
</style>-->
|
||||
|
||||
<!--<style name="AToolbar">
|
||||
<item name="attrAToolbarTitleTextColor">#FF2DDA27</item>
|
||||
<item name="attrAToolbarStartColor">#FF2DDA27</item>
|
||||
<item name="attrAToolbarCenterColor">#FF2DDA27</item>
|
||||
<item name="attrAToolbarEndColor">#FF2DDA27</item>
|
||||
</style>-->
|
||||
|
||||
<!--对话框的样式-->
|
||||
<style name="NormalDialogStyle">
|
||||
<!--对话框背景 -->
|
||||
<item name="android:windowBackground">@android:color/transparent</item>
|
||||
<!--边框 -->
|
||||
<item name="android:windowFrame">@null</item>
|
||||
<!--没有标题 -->
|
||||
<item name="android:windowNoTitle">true</item>
|
||||
<!-- 是否浮现在Activity之上 -->
|
||||
<item name="android:windowIsFloating">true</item>
|
||||
<!--背景透明 -->
|
||||
<item name="android:windowIsTranslucent">false</item>
|
||||
<!-- 是否有覆盖 -->
|
||||
<item name="android:windowContentOverlay">@null</item>
|
||||
<!--进出的显示动画 -->
|
||||
<item name="android:windowAnimationStyle">@style/cornerDialogAnim</item>
|
||||
<!--背景变暗-->
|
||||
<item name="android:backgroundDimEnabled">true</item>
|
||||
</style>
|
||||
|
||||
<!--对话框动画,中间弹出-->
|
||||
<style name="centerDialogAnim" parent="android:Animation">
|
||||
<item name="@android:windowEnterAnimation">@anim/normal_dialog_enter_center</item>
|
||||
<item name="@android:windowExitAnimation">@anim/normal_dialog_exit_center</item>
|
||||
</style>
|
||||
|
||||
<!--对话框动画,角落弹出-->
|
||||
<style name="cornerDialogAnim" parent="android:Animation">
|
||||
<item name="@android:windowEnterAnimation">@anim/normal_dialog_enter_corner</item>
|
||||
<item name="@android:windowExitAnimation">@anim/normal_dialog_exit_corner</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
</resources>
|
||||
|
||||
@@ -9,7 +9,7 @@ android {
|
||||
buildToolsVersion "30.0.3"
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 26
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 30
|
||||
}
|
||||
buildTypes {
|
||||
@@ -18,21 +18,8 @@ android {
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_7
|
||||
targetCompatibility JavaVersion.VERSION_1_7
|
||||
}
|
||||
}
|
||||
|
||||
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 May 12 09:16:45 HKT 2026
|
||||
stageCount=10
|
||||
#Tue Jan 13 03:23:17 HKT 2026
|
||||
stageCount=5
|
||||
libraryProject=libappbase
|
||||
baseVersion=15.20
|
||||
publishVersion=15.20.9
|
||||
baseVersion=15.15
|
||||
publishVersion=15.15.4
|
||||
buildCount=0
|
||||
baseBetaVersion=15.20.10
|
||||
baseBetaVersion=15.15.5
|
||||
|
||||
@@ -3,21 +3,7 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="cc.winboll.studio.libappbase">
|
||||
|
||||
<!-- 拥有完全的网络访问权限 -->
|
||||
<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">
|
||||
<application>
|
||||
|
||||
<activity
|
||||
android:name=".CrashHandler$CrashActivity"
|
||||
@@ -38,22 +24,12 @@
|
||||
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"/>
|
||||
|
||||
<activity
|
||||
android:name=".utils.ShareLogActivity"
|
||||
android:label="ShareLogActivity"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTask"
|
||||
android:theme="@android:style/Theme.NoDisplay"/>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
</manifest>
|
||||
|
||||
@@ -1,194 +0,0 @@
|
||||
package cc.winboll.studio.libappbase;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
/**
|
||||
* 应用崩溃保险丝内部类(单例)
|
||||
* 核心作用:限制短时间内重复崩溃,通过「熔断等级」控制崩溃页面启动策略
|
||||
* 等级范围:MINI(1)~ MAX(2),每次崩溃等级-1,熔断后启动基础版崩溃页面
|
||||
*/
|
||||
public final class AppCrashSafetyWire {
|
||||
|
||||
public static final String TAG = "AppCrashSafetyWire";
|
||||
|
||||
/** 单例实例(volatile 保证多线程可见性) */
|
||||
private static volatile AppCrashSafetyWire _AppCrashSafetyWire;
|
||||
|
||||
/** 当前熔断等级(1:最低防护;2:最高防护;≤0:熔断) */
|
||||
private volatile Integer currentSafetyLevel;
|
||||
/** 最低熔断等级(1,再崩溃则熔断) */
|
||||
private static final int _MINI = 1;
|
||||
/** 最高熔断等级(2,初始状态) */
|
||||
private static final int _MAX = 2;
|
||||
|
||||
/**
|
||||
* 私有构造方法(单例模式,禁止外部实例化)
|
||||
* 初始化时加载本地存储的熔断等级
|
||||
*/
|
||||
private AppCrashSafetyWire() {
|
||||
LogUtils.d(TAG, "AppCrashSafetyWire()");
|
||||
currentSafetyLevel = loadCurrentSafetyLevel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单例实例(双重检查锁定,线程安全)
|
||||
* @return AppCrashSafetyWire 单例
|
||||
*/
|
||||
public static synchronized AppCrashSafetyWire getInstance() {
|
||||
if (_AppCrashSafetyWire == null) {
|
||||
_AppCrashSafetyWire = new AppCrashSafetyWire();
|
||||
}
|
||||
return _AppCrashSafetyWire;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置当前熔断等级(内存中)
|
||||
* @param currentSafetyLevel 目标等级(1~2)
|
||||
*/
|
||||
public void setCurrentSafetyLevel(int currentSafetyLevel) {
|
||||
this.currentSafetyLevel = currentSafetyLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前熔断等级(内存中)
|
||||
* @return 当前等级(1~2 或 null)
|
||||
*/
|
||||
public int getCurrentSafetyLevel() {
|
||||
return currentSafetyLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存熔断等级到本地文件(持久化,重启应用生效)
|
||||
* @param currentSafetyLevel 待保存的等级
|
||||
*/
|
||||
public void saveCurrentSafetyLevel(int currentSafetyLevel) {
|
||||
LogUtils.d(TAG, "saveCurrentSafetyLevel()");
|
||||
this.currentSafetyLevel = currentSafetyLevel;
|
||||
try {
|
||||
// 序列化等级到文件(ObjectOutputStream 写入 int)
|
||||
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(CrashHandler._CrashCountFilePath));
|
||||
oos.writeInt(currentSafetyLevel);
|
||||
oos.flush();
|
||||
oos.close();
|
||||
LogUtils.d(TAG, String.format("saveCurrentSafetyLevel writeInt currentSafetyLevel %d", currentSafetyLevel));
|
||||
} catch (IOException e) {
|
||||
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从本地文件加载熔断等级(应用启动时初始化)
|
||||
* @return 加载的等级(文件不存在则初始化为 MAX(2))
|
||||
*/
|
||||
public int loadCurrentSafetyLevel() {
|
||||
LogUtils.d(TAG, "loadCurrentSafetyLevel()");
|
||||
try {
|
||||
File f = new File(CrashHandler._CrashCountFilePath);
|
||||
if (f.exists()) {
|
||||
// 反序列化从文件读取等级
|
||||
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(CrashHandler._CrashCountFilePath));
|
||||
currentSafetyLevel = ois.readInt();
|
||||
LogUtils.d(TAG, String.format("loadCurrentSafetyLevel() readInt currentSafetyLevel %d", currentSafetyLevel));
|
||||
} else {
|
||||
// 文件不存在,初始化等级为最高(2)并保存
|
||||
currentSafetyLevel = _MAX;
|
||||
LogUtils.d(TAG, String.format("loadCurrentSafetyLevel() currentSafetyLevel init to _MAX->%d", _MAX));
|
||||
saveCurrentSafetyLevel(currentSafetyLevel);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||
}
|
||||
return currentSafetyLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 熔断保险丝(每次崩溃调用,降低防护等级)
|
||||
* @return 熔断后是否仍在防护范围内(true:是;false:已熔断)
|
||||
*/
|
||||
boolean burnSafetyWire() {
|
||||
LogUtils.d(TAG, "burnSafetyWire()");
|
||||
// 加载当前等级
|
||||
int safeLevel = loadCurrentSafetyLevel();
|
||||
// 若在防护范围内(1~2),等级-1 并保存
|
||||
if (isSafetyWireWorking(safeLevel)) {
|
||||
LogUtils.d(TAG, "burnSafetyWire() use");
|
||||
saveCurrentSafetyLevel(safeLevel - 1);
|
||||
// 返回熔断后的状态
|
||||
return isSafetyWireWorking(safeLevel - 1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查熔断等级是否在有效范围内(1~2)
|
||||
* @param safetyLevel 待检查的等级
|
||||
* @return true:在范围内(防护有效);false:超出范围(已熔断)
|
||||
*/
|
||||
boolean isSafetyWireWorking(int safetyLevel) {
|
||||
LogUtils.d(TAG, "isSafetyWireOK()");
|
||||
LogUtils.d(TAG, String.format("SafetyLevel %d", safetyLevel));
|
||||
|
||||
if (safetyLevel >= _MINI && safetyLevel <= _MAX) {
|
||||
LogUtils.d(TAG, String.format("In Safety Level"));
|
||||
return true;
|
||||
}
|
||||
LogUtils.d(TAG, String.format("Out of Safety Level"));
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 立即恢复熔断等级到最高(2)
|
||||
* 用于重启应用后重置防护状态
|
||||
*/
|
||||
void resumeToMaximumImmediately() {
|
||||
LogUtils.d(TAG, "resumeToMaximumImmediately() call saveCurrentSafetyLevel(_MAX)");
|
||||
AppCrashSafetyWire.getInstance().saveCurrentSafetyLevel(_MAX);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭防护(设置等级为最低(1))
|
||||
* 下次崩溃直接熔断
|
||||
*/
|
||||
void off() {
|
||||
LogUtils.d(TAG, "off()");
|
||||
saveCurrentSafetyLevel(_MINI);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查当前保险丝是否有效(防护未熔断)
|
||||
* @return true:有效(等级 1~2);false:已熔断
|
||||
*/
|
||||
public boolean isAppCrashSafetyWireOK() {
|
||||
LogUtils.d(TAG, "isAppCrashSafetyWireOK()");
|
||||
currentSafetyLevel = loadCurrentSafetyLevel();
|
||||
return isSafetyWireWorking(currentSafetyLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 延迟恢复保险丝到最高等级(500ms 后)
|
||||
* 核心作用:崩溃页面启动后,若下次即将熔断,提前恢复防护等级,避免持续崩溃
|
||||
* @param context 上下文(用于获取主线程 Handler)
|
||||
*/
|
||||
void postResumeCrashSafetyWireHandler(final Context context) {
|
||||
// 主线程延迟 500ms 执行(避免页面启动时阻塞)
|
||||
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
LogUtils.d(TAG, "Handler run()");
|
||||
// 检查:若当前等级-1 后超出防护范围(即将熔断),则恢复到最高等级
|
||||
if (!AppCrashSafetyWire.getInstance().isSafetyWireWorking(currentSafetyLevel - 1)) {
|
||||
AppCrashSafetyWire.getInstance().resumeToMaximumImmediately();
|
||||
LogUtils.d(TAG, "postResumeCrashSafetyWireHandler: 恢复保险丝到最高等级");
|
||||
}
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import android.content.Intent;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
@@ -22,9 +23,7 @@ import android.widget.HorizontalScrollView;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import cc.winboll.studio.libappbase.utils.CrashHandleNotifyUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -39,292 +38,521 @@ import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* 应用全局崩溃处理类(单例逻辑)
|
||||
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||
* @Date 2025/11/11 20:14
|
||||
* @Describe * 应用全局崩溃处理类(单例逻辑)
|
||||
* 核心功能:捕获应用未捕获异常,记录崩溃日志到文件,启动崩溃报告页面,
|
||||
* 并通过「崩溃保险丝」机制防止重复崩溃,保障基础功能可用
|
||||
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
|
||||
* @CreateTime 2025/11/11 20:14:00
|
||||
* @EditTime 2026/05/11 15:36:45
|
||||
*/
|
||||
public final class CrashHandler {
|
||||
|
||||
// ====================== 常量定义 ======================
|
||||
/** 日志标签 */
|
||||
public static final String TAG = "CrashHandler";
|
||||
/** 崩溃报告页面标题 */
|
||||
public static final String TITTLE = "CrashReport";
|
||||
/** Intent 传递崩溃信息键 */
|
||||
public static final String EXTRA_CRASH_LOG = "crashInfo";
|
||||
/** SharedPreferences 存储键 */
|
||||
static final String PREFS = CrashHandler.class.getName() + "PREFS";
|
||||
/** 标记是否发生崩溃键 */
|
||||
static final String PREFS_CRASHHANDLER_ISCRASHHAPPEN = "PREFS_CRASHHANDLER_ISCRASHHAPPEN";
|
||||
/** 日志标签,用于当前类的日志输出标识 */
|
||||
public static final String TAG = "CrashHandler";
|
||||
|
||||
// ====================== 成员变量 ======================
|
||||
/** 崩溃保险丝状态文件路径 */
|
||||
public static String _CrashCountFilePath;
|
||||
/** 系统默认异常处理器兜底 */
|
||||
public static final UncaughtExceptionHandler DEFAULT_UNCAUGHT_EXCEPTION_HANDLER
|
||||
= Thread.getDefaultUncaughtExceptionHandler();
|
||||
/** 崩溃报告页面标题 */
|
||||
public static final String TITTLE = "CrashReport";
|
||||
|
||||
// ====================== 对外初始化方法 ======================
|
||||
/**
|
||||
* 初始化崩溃处理器(默认存储路径)
|
||||
* @param app 全局Application实例
|
||||
*/
|
||||
public static void init(final Application app) {
|
||||
_CrashCountFilePath = app.getExternalFilesDir("CrashHandler") + "/IsCrashHandlerCrashHappen.dat";
|
||||
LogUtils.d(TAG, "init _CrashCountFilePath = " + _CrashCountFilePath);
|
||||
init(app, null);
|
||||
}
|
||||
/** Intent 传递崩溃信息的键(用于向崩溃页面传递日志) */
|
||||
public static final String EXTRA_CRASH_LOG = "crashInfo";
|
||||
|
||||
/**
|
||||
* 初始化崩溃处理器(自定义日志目录)
|
||||
* @param app 全局Application实例
|
||||
* @param crashDir 自定义崩溃日志目录,传null使用默认
|
||||
*/
|
||||
public static void init(final Application app, final String crashDir) {
|
||||
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
|
||||
/** SharedPreferences 存储键(用于记录崩溃状态) */
|
||||
final static String PREFS = CrashHandler.class.getName() + "PREFS";
|
||||
/** SharedPreferences 中存储「是否发生崩溃」的键 */
|
||||
final static String PREFS_CRASHHANDLER_ISCRASHHAPPEN = "PREFS_CRASHHANDLER_ISCRASHHAPPEN";
|
||||
|
||||
/** 崩溃保险丝状态文件路径(存储当前熔断等级) */
|
||||
public static String _CrashCountFilePath;
|
||||
|
||||
/** 系统默认的未捕获异常处理器(用于降级处理,避免 CrashHandler 自身崩溃) */
|
||||
public static final UncaughtExceptionHandler DEFAULT_UNCAUGHT_EXCEPTION_HANDLER = Thread.getDefaultUncaughtExceptionHandler();
|
||||
|
||||
/**
|
||||
* 初始化崩溃处理器(默认存储路径)
|
||||
* 调用重载方法,崩溃日志默认存储在应用外部私有目录的 crash 文件夹下
|
||||
* @param app 全局 Application 实例(用于获取存储目录、包信息等)
|
||||
*/
|
||||
public static void init(Application app) {
|
||||
// 初始化崩溃保险丝状态文件路径(外部存储/CrashHandler/IsCrashHandlerCrashHappen.dat)
|
||||
_CrashCountFilePath = app.getExternalFilesDir("CrashHandler") + "/IsCrashHandlerCrashHappen.dat";
|
||||
LogUtils.d(TAG, String.format("_CrashCountFilePath %s", _CrashCountFilePath));
|
||||
// 调用带目录参数的初始化方法,传入 null 使用默认路径
|
||||
init(app, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化崩溃处理器(指定日志存储目录)
|
||||
* 替换系统默认的未捕获异常处理器,自定义崩溃处理逻辑
|
||||
* @param app 全局 Application 实例
|
||||
* @param crashDir 崩溃日志存储目录(null 则使用默认路径)
|
||||
*/
|
||||
public static void init(final Application app, final String crashDir) {
|
||||
// 设置自定义未捕获异常处理器
|
||||
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
|
||||
@Override
|
||||
public void uncaughtException(final Thread thread, final Throwable throwable) {
|
||||
public void uncaughtException(Thread thread, Throwable throwable) {
|
||||
try {
|
||||
tryUncaughtException(thread, throwable, crashDir, app);
|
||||
// 尝试处理崩溃(捕获内部异常,避免 CrashHandler 自身崩溃)
|
||||
tryUncaughtException(thread, throwable);
|
||||
} catch (Throwable e) {
|
||||
LogUtils.e(TAG, "uncaughtException error", e);
|
||||
e.printStackTrace();
|
||||
// 处理失败时,交给系统默认处理器兜底
|
||||
if (DEFAULT_UNCAUGHT_EXCEPTION_HANDLER != null) {
|
||||
DEFAULT_UNCAUGHT_EXCEPTION_HANDLER.uncaughtException(thread, throwable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 实际处理崩溃的核心方法
|
||||
* 1. 熔断保险丝(记录崩溃次数);2. 收集崩溃信息;3. 写入日志文件;4. 启动崩溃报告页面
|
||||
* @param thread 发生崩溃的线程
|
||||
* @param throwable 崩溃异常对象(包含堆栈信息)
|
||||
*/
|
||||
private void tryUncaughtException(Thread thread, Throwable throwable) {
|
||||
// 触发崩溃保险丝(每次崩溃熔断一次,降低防护等级)
|
||||
AppCrashSafetyWire.getInstance().burnSafetyWire();
|
||||
|
||||
// 格式化崩溃发生时间(用于日志文件名和内容)
|
||||
final String time = new SimpleDateFormat("yyyy_MM_dd-HH_mm_ss", Locale.getDefault()).format(new Date());
|
||||
// 创建崩溃日志文件(默认路径:外部存储/crash/[时间].txt)
|
||||
File crashFile = new File(
|
||||
TextUtils.isEmpty(crashDir) ? new File(app.getExternalFilesDir(null), "crash") : new File(crashDir),
|
||||
"crash_" + time + ".txt"
|
||||
);
|
||||
|
||||
// 获取应用版本信息(版本名、版本号)
|
||||
String versionName = "unknown";
|
||||
long versionCode = 0;
|
||||
try {
|
||||
PackageInfo packageInfo = app.getPackageManager().getPackageInfo(app.getPackageName(), 0);
|
||||
versionName = packageInfo.versionName;
|
||||
// 适配 Android 9.0+(API 28)的版本号获取方式
|
||||
versionCode = Build.VERSION.SDK_INT >= 28 ? packageInfo.getLongVersionCode() : packageInfo.versionCode;
|
||||
} catch (PackageManager.NameNotFoundException ignored) {}
|
||||
|
||||
// 将异常堆栈信息转换为字符串
|
||||
String fullStackTrace;
|
||||
{
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
throwable.printStackTrace(pw); // 将异常堆栈写入 PrintWriter
|
||||
fullStackTrace = sw.toString();
|
||||
pw.close();
|
||||
}
|
||||
|
||||
// 拼接崩溃信息(设备信息 + 应用信息 + 堆栈信息)
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("************* Crash Head ****************\n");
|
||||
sb.append("Time Of Crash : ").append(time).append("\n");
|
||||
sb.append("Device Manufacturer : ").append(Build.MANUFACTURER).append("\n"); // 设备厂商
|
||||
sb.append("Device Model : ").append(Build.MODEL).append("\n"); // 设备型号
|
||||
sb.append("Android Version : ").append(Build.VERSION.RELEASE).append("\n"); // Android 版本
|
||||
sb.append("Android SDK : ").append(Build.VERSION.SDK_INT).append("\n"); // SDK 版本
|
||||
sb.append("App VersionName : ").append(versionName).append("\n"); // 应用版本名
|
||||
sb.append("App VersionCode : ").append(versionCode).append("\n"); // 应用版本号
|
||||
sb.append("************* Crash Head ****************\n");
|
||||
sb.append("\n").append(fullStackTrace); // 拼接异常堆栈
|
||||
|
||||
final String errorLog = sb.toString();
|
||||
|
||||
// 将崩溃日志写入文件(忽略写入失败)
|
||||
try {
|
||||
writeFile(crashFile, errorLog);
|
||||
} catch (IOException ignored) {}
|
||||
|
||||
// 启动崩溃报告页面(标签用于代码块折叠)
|
||||
gotoCrashActiviy: {
|
||||
Intent intent = new Intent();
|
||||
LogUtils.d(TAG, "gotoCrashActiviy: ");
|
||||
|
||||
// 根据保险丝状态选择启动的崩溃页面
|
||||
if (AppCrashSafetyWire.getInstance().isAppCrashSafetyWireOK()) {
|
||||
LogUtils.d(TAG, "gotoCrashActiviy: isAppCrashSafetyWireOK");
|
||||
// 保险丝正常:启动自定义样式的崩溃报告页面(GlobalCrashActivity)
|
||||
intent.setClass(app, GlobalCrashActivity.class);
|
||||
intent.putExtra(EXTRA_CRASH_LOG, errorLog); // 传递崩溃日志
|
||||
} else {
|
||||
LogUtils.d(TAG, "gotoCrashActiviy: else");
|
||||
// 保险丝熔断:启动基础版崩溃页面(CrashActivity,避免复杂页面再次崩溃)
|
||||
intent.setClass(app, CrashActivity.class);
|
||||
intent.putExtra(EXTRA_CRASH_LOG, errorLog);
|
||||
}
|
||||
|
||||
// 设置意图标志:清除原有任务栈,创建新任务(避免回到崩溃前页面)
|
||||
intent.addFlags(
|
||||
Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
);
|
||||
|
||||
try {
|
||||
if (GlobalApplication.isDebugging()&&AppCrashSafetyWire.getInstance().isAppCrashSafetyWireOK()) {
|
||||
// 如果是 debug 版,启动崩溃页面窗口
|
||||
app.startActivity(intent);
|
||||
} else {
|
||||
// 如果是 release 版,就只发送一个通知
|
||||
CrashHandleNotifyUtils.handleUncaughtException(app, intent);
|
||||
}
|
||||
// 终止当前进程(确保完全重启)
|
||||
android.os.Process.killProcess(android.os.Process.myPid());
|
||||
System.exit(0);
|
||||
|
||||
} catch (ActivityNotFoundException e) {
|
||||
// 未找到崩溃页面(如未在 Manifest 注册),交给系统默认处理器
|
||||
e.printStackTrace();
|
||||
if (DEFAULT_UNCAUGHT_EXCEPTION_HANDLER != null) {
|
||||
DEFAULT_UNCAUGHT_EXCEPTION_HANDLER.uncaughtException(thread, throwable);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 其他异常,兜底处理
|
||||
e.printStackTrace();
|
||||
if (DEFAULT_UNCAUGHT_EXCEPTION_HANDLER != null) {
|
||||
DEFAULT_UNCAUGHT_EXCEPTION_HANDLER.uncaughtException(thread, throwable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符串内容写入文件(创建父目录、覆盖写入)
|
||||
* @param file 目标文件(包含路径)
|
||||
* @param content 待写入的内容(崩溃日志)
|
||||
* @throws IOException 文件创建或写入失败时抛出
|
||||
*/
|
||||
private void writeFile(File file, String content) throws IOException {
|
||||
File parentFile = file.getParentFile();
|
||||
// 父目录不存在则创建
|
||||
if (parentFile != null && !parentFile.exists()) {
|
||||
parentFile.mkdirs();
|
||||
}
|
||||
file.createNewFile(); // 创建文件
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
fos.write(content.getBytes()); // 写入内容(默认 UTF-8 编码)
|
||||
try {
|
||||
fos.close(); // 关闭流
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ====================== 内部崩溃处理核心 ======================
|
||||
/**
|
||||
* 执行崩溃信息收集、日志写入、跳转崩溃页面
|
||||
*/
|
||||
private static void tryUncaughtException(final Thread thread,
|
||||
final Throwable throwable,
|
||||
final String crashDir,
|
||||
final Application app) {
|
||||
// 触发崩溃保险丝
|
||||
AppCrashSafetyWire.getInstance().burnSafetyWire();
|
||||
/**
|
||||
* 应用崩溃保险丝内部类(单例)
|
||||
* 核心作用:限制短时间内重复崩溃,通过「熔断等级」控制崩溃页面启动策略
|
||||
* 等级范围:MINI(1)~ MAX(2),每次崩溃等级-1,熔断后启动基础版崩溃页面
|
||||
*/
|
||||
public static final class AppCrashSafetyWire {
|
||||
|
||||
// 格式化时间
|
||||
final String time = new SimpleDateFormat("yyyy_MM_dd-HH_mm_ss",
|
||||
Locale.getDefault()).format(new Date());
|
||||
/** 单例实例(volatile 保证多线程可见性) */
|
||||
private static volatile AppCrashSafetyWire _AppCrashSafetyWire;
|
||||
|
||||
// 创建日志文件
|
||||
File logParent = TextUtils.isEmpty(crashDir)
|
||||
? new File(app.getExternalFilesDir(null), "crash")
|
||||
: new File(crashDir);
|
||||
final File crashFile = new File(logParent, "crash_" + time + ".txt");
|
||||
/** 当前熔断等级(1:最低防护;2:最高防护;≤0:熔断) */
|
||||
private volatile Integer currentSafetyLevel;
|
||||
/** 最低熔断等级(1,再崩溃则熔断) */
|
||||
private static final int _MINI = 1;
|
||||
/** 最高熔断等级(2,初始状态) */
|
||||
private static final int _MAX = 2;
|
||||
|
||||
// 获取应用版本信息
|
||||
String versionName = "unknown";
|
||||
long versionCode = 0;
|
||||
try {
|
||||
final PackageInfo packageInfo = app.getPackageManager()
|
||||
.getPackageInfo(app.getPackageName(), 0);
|
||||
versionName = packageInfo.versionName;
|
||||
if (Build.VERSION.SDK_INT >= 28) {
|
||||
versionCode = packageInfo.getLongVersionCode();
|
||||
} else {
|
||||
versionCode = packageInfo.versionCode;
|
||||
}
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
LogUtils.e(TAG, "get package info fail");
|
||||
}
|
||||
/**
|
||||
* 私有构造方法(单例模式,禁止外部实例化)
|
||||
* 初始化时加载本地存储的熔断等级
|
||||
*/
|
||||
private AppCrashSafetyWire() {
|
||||
LogUtils.d(TAG, "AppCrashSafetyWire()");
|
||||
currentSafetyLevel = loadCurrentSafetyLevel();
|
||||
}
|
||||
|
||||
// 抓取异常堆栈
|
||||
String fullStackTrace;
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
throwable.printStackTrace(pw);
|
||||
fullStackTrace = sw.toString();
|
||||
pw.close();
|
||||
/**
|
||||
* 获取单例实例(双重检查锁定,线程安全)
|
||||
* @return AppCrashSafetyWire 单例
|
||||
*/
|
||||
public static synchronized AppCrashSafetyWire getInstance() {
|
||||
if (_AppCrashSafetyWire == null) {
|
||||
_AppCrashSafetyWire = new AppCrashSafetyWire();
|
||||
}
|
||||
return _AppCrashSafetyWire;
|
||||
}
|
||||
|
||||
// 拼接崩溃头部信息
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("************* Crash Head ****************\n");
|
||||
sb.append("Time Of Crash : ").append(time).append("\n");
|
||||
sb.append("Device Manufacturer : ").append(Build.MANUFACTURER).append("\n");
|
||||
sb.append("Device Model : ").append(Build.MODEL).append("\n");
|
||||
sb.append("Android Version : ").append(Build.VERSION.RELEASE).append("\n");
|
||||
sb.append("Android SDK : ").append(Build.VERSION.SDK_INT).append("\n");
|
||||
sb.append("App VersionName : ").append(versionName).append("\n");
|
||||
sb.append("App VersionCode : ").append(versionCode).append("\n");
|
||||
sb.append("************* Crash Head ****************\n");
|
||||
sb.append("\n").append(fullStackTrace);
|
||||
/**
|
||||
* 设置当前熔断等级(内存中)
|
||||
* @param currentSafetyLevel 目标等级(1~2)
|
||||
*/
|
||||
public void setCurrentSafetyLevel(int currentSafetyLevel) {
|
||||
this.currentSafetyLevel = currentSafetyLevel;
|
||||
}
|
||||
|
||||
final String errorLog = sb.toString();
|
||||
/**
|
||||
* 获取当前熔断等级(内存中)
|
||||
* @return 当前等级(1~2 或 null)
|
||||
*/
|
||||
public int getCurrentSafetyLevel() {
|
||||
return currentSafetyLevel;
|
||||
}
|
||||
|
||||
// 写入日志文件
|
||||
try {
|
||||
writeFile(crashFile, errorLog);
|
||||
} catch (IOException e) {
|
||||
LogUtils.e(TAG, "write crash log file fail");
|
||||
}
|
||||
/**
|
||||
* 保存熔断等级到本地文件(持久化,重启应用生效)
|
||||
* @param currentSafetyLevel 待保存的等级
|
||||
*/
|
||||
public void saveCurrentSafetyLevel(int currentSafetyLevel) {
|
||||
LogUtils.d(TAG, "saveCurrentSafetyLevel()");
|
||||
this.currentSafetyLevel = currentSafetyLevel;
|
||||
try {
|
||||
// 序列化等级到文件(ObjectOutputStream 写入 int)
|
||||
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(_CrashCountFilePath));
|
||||
oos.writeInt(currentSafetyLevel);
|
||||
oos.flush();
|
||||
oos.close();
|
||||
LogUtils.d(TAG, String.format("saveCurrentSafetyLevel writeInt currentSafetyLevel %d", currentSafetyLevel));
|
||||
} catch (IOException e) {
|
||||
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||
}
|
||||
}
|
||||
|
||||
// 跳转崩溃页面
|
||||
gotoCrashActivity(errorLog, app);
|
||||
}
|
||||
/**
|
||||
* 从本地文件加载熔断等级(应用启动时初始化)
|
||||
* @return 加载的等级(文件不存在则初始化为 MAX(2))
|
||||
*/
|
||||
public int loadCurrentSafetyLevel() {
|
||||
LogUtils.d(TAG, "loadCurrentSafetyLevel()");
|
||||
try {
|
||||
File f = new File(_CrashCountFilePath);
|
||||
if (f.exists()) {
|
||||
// 反序列化从文件读取等级
|
||||
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(_CrashCountFilePath));
|
||||
currentSafetyLevel = ois.readInt();
|
||||
LogUtils.d(TAG, String.format("loadCurrentSafetyLevel() readInt currentSafetyLevel %d", currentSafetyLevel));
|
||||
} else {
|
||||
// 文件不存在,初始化等级为最高(2)并保存
|
||||
currentSafetyLevel = _MAX;
|
||||
LogUtils.d(TAG, String.format("loadCurrentSafetyLevel() currentSafetyLevel init to _MAX->%d", _MAX));
|
||||
saveCurrentSafetyLevel(currentSafetyLevel);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||
}
|
||||
return currentSafetyLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入文本到文件
|
||||
*/
|
||||
private static void writeFile(final File file, final String content) throws IOException {
|
||||
final File parentFile = file.getParentFile();
|
||||
if (parentFile != null && !parentFile.exists()) {
|
||||
parentFile.mkdirs();
|
||||
}
|
||||
file.createNewFile();
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
fos.write(content.getBytes());
|
||||
fos.close();
|
||||
}
|
||||
/**
|
||||
* 熔断保险丝(每次崩溃调用,降低防护等级)
|
||||
* @return 熔断后是否仍在防护范围内(true:是;false:已熔断)
|
||||
*/
|
||||
boolean burnSafetyWire() {
|
||||
LogUtils.d(TAG, "burnSafetyWire()");
|
||||
// 加载当前等级
|
||||
int safeLevel = loadCurrentSafetyLevel();
|
||||
// 若在防护范围内(1~2),等级-1 并保存
|
||||
if (isSafetyWireWorking(safeLevel)) {
|
||||
LogUtils.d(TAG, "burnSafetyWire() use");
|
||||
saveCurrentSafetyLevel(safeLevel - 1);
|
||||
// 返回熔断后的状态
|
||||
return isSafetyWireWorking(safeLevel - 1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据保险丝状态跳转对应崩溃页面
|
||||
*/
|
||||
private static void gotoCrashActivity(final String errorLog, final Application app) {
|
||||
final Intent intent = new Intent();
|
||||
if (AppCrashSafetyWire.getInstance().isAppCrashSafetyWireOK()) {
|
||||
intent.setClass(app, GlobalCrashActivity.class);
|
||||
} else {
|
||||
intent.setClass(app, CrashActivity.class);
|
||||
}
|
||||
intent.putExtra(EXTRA_CRASH_LOG, errorLog);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
/**
|
||||
* 检查熔断等级是否在有效范围内(1~2)
|
||||
* @param safetyLevel 待检查的等级
|
||||
* @return true:在范围内(防护有效);false:超出范围(已熔断)
|
||||
*/
|
||||
boolean isSafetyWireWorking(int safetyLevel) {
|
||||
LogUtils.d(TAG, "isSafetyWireOK()");
|
||||
LogUtils.d(TAG, String.format("SafetyLevel %d", safetyLevel));
|
||||
|
||||
try {
|
||||
if (GlobalApplication.isDebugging()) {
|
||||
app.startActivity(intent);
|
||||
} else {
|
||||
CrashHandleNotifyUtils.handleUncaughtException(app, intent, GlobalCrashActivity.class);
|
||||
}
|
||||
android.os.Process.killProcess(android.os.Process.myPid());
|
||||
System.exit(0);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
LogUtils.e(TAG, "CrashActivity not found");
|
||||
if (DEFAULT_UNCAUGHT_EXCEPTION_HANDLER != null) {
|
||||
DEFAULT_UNCAUGHT_EXCEPTION_HANDLER.uncaughtException(Thread.currentThread(), e);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "start CrashActivity error");
|
||||
if (DEFAULT_UNCAUGHT_EXCEPTION_HANDLER != null) {
|
||||
DEFAULT_UNCAUGHT_EXCEPTION_HANDLER.uncaughtException(Thread.currentThread(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (safetyLevel >= _MINI && safetyLevel <= _MAX) {
|
||||
LogUtils.d(TAG, String.format("In Safety Level"));
|
||||
return true;
|
||||
}
|
||||
LogUtils.d(TAG, String.format("Out of Safety Level"));
|
||||
return false;
|
||||
}
|
||||
|
||||
// ====================== 内部Activity页面 ======================
|
||||
/**
|
||||
* 基础极简崩溃页面
|
||||
* 保险丝熔断时启动,避免复杂布局二次崩溃
|
||||
*/
|
||||
public static final class CrashActivity extends Activity implements MenuItem.OnMenuItemClickListener {
|
||||
private static final int MENUITEM_COPY = 0;
|
||||
private static final int MENUITEM_RESTART = 1;
|
||||
/**
|
||||
* 立即恢复熔断等级到最高(2)
|
||||
* 用于重启应用后重置防护状态
|
||||
*/
|
||||
void resumeToMaximumImmediately() {
|
||||
LogUtils.d(TAG, "resumeToMaximumImmediately() call saveCurrentSafetyLevel(_MAX)");
|
||||
AppCrashSafetyWire.getInstance().saveCurrentSafetyLevel(_MAX);
|
||||
}
|
||||
|
||||
private String mLog;
|
||||
/**
|
||||
* 关闭防护(设置等级为最低(1))
|
||||
* 下次崩溃直接熔断
|
||||
*/
|
||||
void off() {
|
||||
LogUtils.d(TAG, "off()");
|
||||
saveCurrentSafetyLevel(_MINI);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
AppCrashSafetyWire.getInstance().postResumeCrashSafetyWireHandler(getApplicationContext());
|
||||
mLog = getIntent().getStringExtra(EXTRA_CRASH_LOG);
|
||||
setTheme(android.R.style.Theme_DeviceDefault_Light_DarkActionBar);
|
||||
initLayout();
|
||||
}
|
||||
/**
|
||||
* 检查当前保险丝是否有效(防护未熔断)
|
||||
* @return true:有效(等级 1~2);false:已熔断
|
||||
*/
|
||||
boolean isAppCrashSafetyWireOK() {
|
||||
LogUtils.d(TAG, "isAppCrashSafetyWireOK()");
|
||||
currentSafetyLevel = loadCurrentSafetyLevel();
|
||||
return isSafetyWireWorking(currentSafetyLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 动态初始化布局
|
||||
*/
|
||||
private void initLayout() {
|
||||
ScrollView contentView = new ScrollView(this);
|
||||
contentView.setFillViewport(true);
|
||||
/**
|
||||
* 延迟恢复保险丝到最高等级(500ms 后)
|
||||
* 核心作用:崩溃页面启动后,若下次即将熔断,提前恢复防护等级,避免持续崩溃
|
||||
* @param context 上下文(用于获取主线程 Handler)
|
||||
*/
|
||||
void postResumeCrashSafetyWireHandler(final Context context) {
|
||||
// 主线程延迟 500ms 执行(避免页面启动时阻塞)
|
||||
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
LogUtils.d(TAG, "Handler run()");
|
||||
// 检查:若当前等级-1 后超出防护范围(即将熔断),则恢复到最高等级
|
||||
if (!AppCrashSafetyWire.getInstance().isSafetyWireWorking(currentSafetyLevel - 1)) {
|
||||
AppCrashSafetyWire.getInstance().resumeToMaximumImmediately();
|
||||
LogUtils.d(TAG, "postResumeCrashSafetyWireHandler: 恢复保险丝到最高等级");
|
||||
}
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
|
||||
HorizontalScrollView hw = new HorizontalScrollView(this);
|
||||
hw.setBackgroundColor(0xFFF5F5F5);
|
||||
/**
|
||||
* 基础版崩溃报告页面(保险丝熔断时启动)
|
||||
* 极简实现:仅展示崩溃日志,提供复制、重启功能,避免复杂布局导致二次崩溃
|
||||
*/
|
||||
public static final class CrashActivity extends Activity implements MenuItem.OnMenuItemClickListener {
|
||||
/** 菜单标识:复制崩溃日志 */
|
||||
private static final int MENUITEM_COPY = 0;
|
||||
/** 菜单标识:重启应用 */
|
||||
private static final int MENUITEM_RESTART = 1;
|
||||
|
||||
TextView message = new TextView(this);
|
||||
final int padding = dp2px(16);
|
||||
message.setPadding(padding, padding, padding, padding);
|
||||
message.setText(mLog);
|
||||
message.setTextColor(0xFF000000);
|
||||
message.setTextIsSelectable(true);
|
||||
/** 崩溃日志文本(从 CrashHandler 传递过来) */
|
||||
private String mLog;
|
||||
|
||||
hw.addView(message);
|
||||
contentView.addView(hw, ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
setContentView(contentView);
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// 初始化崩溃保险丝延迟恢复机制
|
||||
AppCrashSafetyWire.getInstance().postResumeCrashSafetyWireHandler(getApplicationContext());
|
||||
|
||||
getActionBar().setTitle(TITTLE);
|
||||
getActionBar().setSubtitle(GlobalApplication.class.getSimpleName() + " Error");
|
||||
}
|
||||
// 获取传递的崩溃日志
|
||||
mLog = getIntent().getStringExtra(EXTRA_CRASH_LOG);
|
||||
// 设置系统默认主题(避免自定义主题冲突)
|
||||
setTheme(android.R.style.Theme_DeviceDefault_Light_DarkActionBar);
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
restartApp();
|
||||
}
|
||||
// 动态创建布局(避免 XML 布局加载异常)
|
||||
setContentView: {
|
||||
// 垂直滚动视图(处理日志过长)
|
||||
ScrollView contentView = new ScrollView(this);
|
||||
contentView.setFillViewport(true);
|
||||
|
||||
/**
|
||||
* 重启应用
|
||||
*/
|
||||
private void restartApp() {
|
||||
final Intent intent = getPackageManager()
|
||||
.getLaunchIntentForPackage(getPackageName());
|
||||
if (intent != null) {
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
startActivity(intent);
|
||||
}
|
||||
finish();
|
||||
android.os.Process.killProcess(android.os.Process.myPid());
|
||||
System.exit(0);
|
||||
}
|
||||
// 水平滚动视图(处理日志行过长)
|
||||
HorizontalScrollView hw = new HorizontalScrollView(this);
|
||||
hw.setBackgroundColor(Color.GRAY); // 背景色设为灰色
|
||||
|
||||
/**
|
||||
* dp转px
|
||||
*/
|
||||
private int dp2px(final float dpValue) {
|
||||
final float scale = Resources.getSystem().getDisplayMetrics().density;
|
||||
return (int) (dpValue * scale + 0.5f);
|
||||
}
|
||||
// 日志显示文本框
|
||||
TextView message = new TextView(this);
|
||||
{
|
||||
int padding = dp2px(16); // 内边距 16dp(适配不同屏幕)
|
||||
message.setPadding(padding, padding, padding, padding);
|
||||
message.setText(mLog); // 设置崩溃日志
|
||||
message.setTextColor(Color.BLACK); // 文字黑色
|
||||
message.setTextIsSelectable(true); // 支持文本选择(便于手动复制)
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(final Menu menu) {
|
||||
menu.add(0, MENUITEM_COPY, 0, "Copy")
|
||||
// 组装布局:TextView -> HorizontalScrollView -> ScrollView
|
||||
hw.addView(message);
|
||||
contentView.addView(hw, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
// 设置当前 Activity 布局
|
||||
setContentView(contentView);
|
||||
|
||||
// 配置 ActionBar 标题和副标题
|
||||
getActionBar().setTitle(TITTLE);
|
||||
getActionBar().setSubtitle(GlobalApplication.class.getSimpleName() + " Error");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 重写返回键逻辑:点击返回键直接重启应用
|
||||
*/
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
restart();
|
||||
}
|
||||
|
||||
/**
|
||||
* 重启当前应用(与 GlobalCrashActivity 逻辑一致)
|
||||
* 清除任务栈,启动主 Activity,终止当前进程
|
||||
*/
|
||||
private void restart() {
|
||||
PackageManager pm = getPackageManager();
|
||||
// 获取应用启动意图(默认启动主 Activity)
|
||||
Intent intent = pm.getLaunchIntentForPackage(getPackageName());
|
||||
if (intent != null) {
|
||||
// 设置意图标志:清除原有任务栈,创建新任务
|
||||
intent.addFlags(
|
||||
Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
);
|
||||
startActivity(intent);
|
||||
}
|
||||
// 关闭当前页面,终止进程,确保完全重启
|
||||
finish();
|
||||
android.os.Process.killProcess(android.os.Process.myPid());
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* dp 转 px(适配不同屏幕密度)
|
||||
* @param dpValue dp 值
|
||||
* @return 转换后的 px 值
|
||||
*/
|
||||
private int dp2px(final float dpValue) {
|
||||
final float scale = Resources.getSystem().getDisplayMetrics().density;
|
||||
return (int) (dpValue * scale + 0.5f); // 四舍五入确保精度
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单点击事件回调(处理复制、重启)
|
||||
* @param item 被点击的菜单项
|
||||
* @return false:不消费事件(保持默认行为)
|
||||
*/
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case MENUITEM_COPY:
|
||||
// 复制日志到剪贴板
|
||||
ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
cm.setPrimaryClip(ClipData.newPlainText(getPackageName(), mLog));
|
||||
Toast.makeText(getApplication(), "The text is copied.", Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case MENUITEM_RESTART:
|
||||
// 恢复保险丝到最高等级,然后重启应用
|
||||
AppCrashSafetyWire.getInstance().resumeToMaximumImmediately();
|
||||
restart();
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建 ActionBar 菜单(添加复制、重启项)
|
||||
* @param menu 菜单容器
|
||||
* @return true:显示菜单
|
||||
*/
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// 添加「复制」菜单:有空间时显示在 ActionBar,否则放入溢出菜单
|
||||
menu.add(0, MENUITEM_COPY, 0, "Copy")
|
||||
.setOnMenuItemClickListener(this)
|
||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
|
||||
menu.add(0, MENUITEM_RESTART, 0, "Restart")
|
||||
// 添加「重启」菜单:同上
|
||||
menu.add(0, MENUITEM_RESTART, 0, "Restart")
|
||||
.setOnMenuItemClickListener(this)
|
||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemClick(final MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case MENUITEM_COPY:
|
||||
ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
cm.setPrimaryClip(ClipData.newPlainText(getPackageName(), mLog));
|
||||
Toast.makeText(getApplication(), "The text is copied.", Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case MENUITEM_RESTART:
|
||||
AppCrashSafetyWire.getInstance().resumeToMaximumImmediately();
|
||||
restartApp();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ 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;
|
||||
@@ -27,12 +26,6 @@ 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)
|
||||
@@ -60,7 +53,7 @@ public class GlobalApplication extends Application {
|
||||
}
|
||||
// 将调试状态封装为 APPModel 并保存到文件
|
||||
APPModel.saveBeanToFile(
|
||||
getAppModelFilePath(application),
|
||||
getAppModelFilePath(application),
|
||||
new APPModel(isDebugging)
|
||||
);
|
||||
}
|
||||
@@ -83,42 +76,6 @@ public class GlobalApplication extends Application {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用启动时初始化(仅执行一次)
|
||||
* 初始化核心框架、恢复调试状态、配置全局异常处理等
|
||||
@@ -128,13 +85,12 @@ public class GlobalApplication extends Application {
|
||||
super.onCreate();
|
||||
// 初始化单例实例(确保在所有初始化操作前完成)
|
||||
sInstance = this;
|
||||
|
||||
|
||||
// 初始化基础组件(日志、崩溃处理、Toast)
|
||||
initCoreComponents();
|
||||
// 恢复/初始化调试模式状态(从本地文件读取,无文件则默认关闭调试)
|
||||
restoreDebugStatus();
|
||||
// 新增:初始化服务器地址(从 SP 读取到内存,提高后续访问效率)
|
||||
initWinbollHost();
|
||||
|
||||
LogUtils.d(TAG, "GlobalApplication 初始化完成,单例实例已创建");
|
||||
}
|
||||
@@ -159,7 +115,7 @@ public class GlobalApplication extends Application {
|
||||
private void restoreDebugStatus() {
|
||||
// 从文件加载 APPModel 实例(存储调试状态的模型类)
|
||||
APPModel appModel = APPModel.loadBeanFromFile(
|
||||
getAppModelFilePath(this),
|
||||
getAppModelFilePath(this),
|
||||
APPModel.class
|
||||
);
|
||||
|
||||
@@ -175,11 +131,6 @@ public class GlobalApplication extends Application {
|
||||
}
|
||||
}
|
||||
|
||||
// 新增:初始化服务器地址(应用启动时从 SP 读取到内存)
|
||||
private void initWinbollHost() {
|
||||
getWinbollHost(); // 触发从 SP 读取并更新内存
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取应用名称(从 AndroidManifest.xml 的 android:label 读取)
|
||||
* @param context 上下文(建议传入 Application 上下文,避免内存泄漏)
|
||||
@@ -203,7 +154,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();
|
||||
}
|
||||
@@ -219,6 +170,7 @@ public class GlobalApplication extends Application {
|
||||
// 释放单例引用(可选,避免内存泄漏风险)
|
||||
sInstance = null;
|
||||
LogUtils.d(TAG, "GlobalApplication 终止,单例实例已释放");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,141 +10,176 @@ import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.Toast;
|
||||
|
||||
import cc.winboll.studio.libappbase.utils.CrashHandleNotifyUtils;
|
||||
import cc.winboll.studio.libappbase.R;
|
||||
|
||||
/**
|
||||
* 应用异常报告观察活动窗口类
|
||||
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||
* @Date 2025/11/11 19:58
|
||||
* @Describe 应用异常报告观察活动窗口类
|
||||
* 核心功能:应用发生未捕获崩溃时,由 CrashHandler 启动此页面,展示崩溃日志详情,
|
||||
* 并提供「复制日志」「重启应用」操作入口,便于开发者定位问题和用户恢复应用
|
||||
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
|
||||
* @CreateTime 2025/11/11 19:58:00
|
||||
* @EditTime 2026/05/11 15:40:12
|
||||
*/
|
||||
public final class GlobalCrashActivity extends Activity implements MenuItem.OnMenuItemClickListener {
|
||||
|
||||
// ====================== 常量定义 ======================
|
||||
/** 日志标签(用于调试日志输出,唯一标识当前 Activity) */
|
||||
public static final String TAG = "GlobalCrashActivity";
|
||||
/** 菜单标识:复制崩溃日志 */
|
||||
|
||||
/** 菜单标识:复制崩溃日志(用于区分菜单项点击事件) */
|
||||
private static final int MENU_ITEM_COPY = 0;
|
||||
/** 菜单标识:重启应用 */
|
||||
/** 菜单标识:重启应用(用于区分菜单项点击事件) */
|
||||
private static final int MENU_ITEM_RESTART = 1;
|
||||
|
||||
// ====================== 成员变量 ======================
|
||||
/** 崩溃报告展示自定义视图 */
|
||||
// 负责渲染崩溃日志文本、提供 Toolbar 容器,封装了日志展示和菜单样式控制逻辑
|
||||
private GlobalCrashReportView mCrashReportView;
|
||||
|
||||
/** 崩溃日志文本内容 */
|
||||
// 从 CrashHandler 通过 Intent 传递过来,包含异常堆栈、设备信息等完整崩溃数据
|
||||
private String mCrashLog;
|
||||
|
||||
// ====================== 生命周期方法 ======================
|
||||
/**
|
||||
* Activity 创建时初始化(生命周期核心方法,仅执行一次)
|
||||
* @param savedInstanceState 保存的实例状态(崩溃页面无需恢复状态,此处仅作兼容)
|
||||
*/
|
||||
@Override
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
LogUtils.d(TAG, "onCreate 方法进入");
|
||||
try {
|
||||
super.onCreate(savedInstanceState);
|
||||
final Context appContext = getApplicationContext();
|
||||
// 初始化崩溃安全防护机制
|
||||
AppCrashSafetyWire.getInstance().postResumeCrashSafetyWireHandler(appContext);
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// 获取传递的崩溃日志
|
||||
mCrashLog = getIntent().getStringExtra(CrashHandler.EXTRA_CRASH_LOG);
|
||||
LogUtils.d(TAG, "获取到崩溃日志,长度:" + (mCrashLog != null ? mCrashLog.length() : 0));
|
||||
// 初始化崩溃安全防护机制
|
||||
// 作用:防止应用重启后短时间内再次崩溃,由 CrashHandler 内部实现防护逻辑
|
||||
CrashHandler.AppCrashSafetyWire.getInstance()
|
||||
.postResumeCrashSafetyWireHandler(getApplicationContext());
|
||||
|
||||
setContentView(R.layout.activity_globalcrash);
|
||||
mCrashReportView = findViewById(R.id.activityglobalcrashGlobalCrashReportView1);
|
||||
mCrashReportView.setReport(mCrashLog);
|
||||
// 从 Intent 中获取崩溃日志数据(EXTRA_CRASH_INFO 为 CrashHandler 定义的常量键)
|
||||
mCrashLog = getIntent().getStringExtra(CrashHandler.EXTRA_CRASH_LOG);
|
||||
|
||||
setActionBar(mCrashReportView.getToolbar());
|
||||
if (getActionBar() != null) {
|
||||
getActionBar().setTitle(CrashHandler.TITTLE);
|
||||
getActionBar().setSubtitle(GlobalApplication.getAppName(appContext));
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
LogUtils.e(TAG, "GlobalCrashActivity onCreate 发生异常", e);
|
||||
AppCrashSafetyWire.getInstance().burnSafetyWire();
|
||||
// 设置当前 Activity 的布局文件(展示崩溃报告的 UI 结构)
|
||||
setContentView(R.layout.activity_globalcrash);
|
||||
|
||||
mCrashLog = getIntent().getStringExtra(CrashHandler.EXTRA_CRASH_LOG);
|
||||
final Intent intent = new Intent();
|
||||
intent.putExtra(CrashHandler.EXTRA_CRASH_LOG, mCrashLog);
|
||||
CrashHandleNotifyUtils.handleUncaughtException(GlobalApplication.getInstance(), intent, CrashHandler.CrashActivity.class);
|
||||
// 初始化崩溃报告展示视图(通过布局 ID 找到自定义 View 实例)
|
||||
mCrashReportView = findViewById(R.id.activityglobalcrashGlobalCrashReportView1);
|
||||
// 将崩溃日志设置到视图中,由自定义 View 负责排版和显示
|
||||
mCrashReportView.setReport(mCrashLog);
|
||||
|
||||
StackTraceElement[] stackElements = Thread.currentThread().getStackTrace();
|
||||
StringBuilder sb = new StringBuilder("GlobalCrashActivity onCreate StackTrace");
|
||||
for (StackTraceElement item : stackElements) {
|
||||
sb.append("\n").append(item.toString());
|
||||
}
|
||||
LogUtils.d(TAG, sb.toString());
|
||||
finish();
|
||||
// 设置页面的 ActionBar(复用自定义 View 中的 Toolbar 作为系统 ActionBar)
|
||||
setActionBar(mCrashReportView.getToolbar());
|
||||
|
||||
// 配置 ActionBar 标题和副标题(非空判断避免空指针异常)
|
||||
if (getActionBar() != null) {
|
||||
// 设置标题:使用 CrashHandler 中定义的统一标题(如 "应用崩溃报告")
|
||||
getActionBar().setTitle(CrashHandler.TITTLE);
|
||||
// 设置副标题:显示当前应用名称(从全局 Application 工具方法获取)
|
||||
getActionBar().setSubtitle(GlobalApplication.getAppName(getApplicationContext()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 重写返回键点击事件
|
||||
* 逻辑:点击手机返回键时,直接重启应用(而非返回上一页,因崩溃后上一页状态可能异常)
|
||||
*/
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
LogUtils.d(TAG, "onBackPressed 触发重启应用");
|
||||
restartApp();
|
||||
}
|
||||
|
||||
// ====================== 菜单相关回调 ======================
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(final Menu menu) {
|
||||
LogUtils.d(TAG, "onCreateOptionsView 初始化菜单");
|
||||
menu.add(0, MENU_ITEM_COPY, 0, "Copy")
|
||||
.setOnMenuItemClickListener(this)
|
||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
/**
|
||||
* 重启当前应用(核心工具方法)
|
||||
* 实现逻辑:
|
||||
* 1. 获取应用的启动意图(默认启动 AndroidManifest 中配置的主 Activity)
|
||||
* 2. 设置意图标志,清除原有任务栈,避免残留异常页面
|
||||
* 3. 启动主 Activity 并终止当前进程,确保应用完全重启
|
||||
*/
|
||||
private void restartApp() {
|
||||
// 获取 PackageManager 实例(用于获取应用相关信息和意图)
|
||||
PackageManager packageManager = getPackageManager();
|
||||
// 获取应用的启动意图(参数为当前应用包名,返回主 Activity 的意图)
|
||||
Intent launchIntent = packageManager.getLaunchIntentForPackage(getPackageName());
|
||||
|
||||
menu.add(0, MENU_ITEM_RESTART, 0, "Restart")
|
||||
.setOnMenuItemClickListener(this)
|
||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
if (launchIntent != null) {
|
||||
// 设置意图标志:
|
||||
// FLAG_ACTIVITY_NEW_TASK:创建新的任务栈启动 Activity
|
||||
// FLAG_ACTIVITY_CLEAR_TOP:清除目标 Activity 之上的所有 Activity
|
||||
// FLAG_ACTIVITY_CLEAR_TASK:清除当前任务栈中的所有 Activity
|
||||
launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
// 启动应用主 Activity
|
||||
startActivity(launchIntent);
|
||||
}
|
||||
|
||||
mCrashReportView.updateMenuStyle();
|
||||
return true;
|
||||
// 关闭当前崩溃报告页面
|
||||
finish();
|
||||
// 终止当前应用进程(确保释放所有资源,避免内存泄漏)
|
||||
android.os.Process.killProcess(android.os.Process.myPid());
|
||||
// 强制退出虚拟机(彻底终止应用,防止残留线程继续运行)
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单项点击事件回调(实现 MenuItem.OnMenuItemClickListener 接口)
|
||||
* @param item 被点击的菜单项实例
|
||||
* @return boolean:true 表示事件已消费,不再向下传递;false 表示未消费
|
||||
*/
|
||||
@Override
|
||||
public boolean onMenuItemClick(final MenuItem item) {
|
||||
LogUtils.d(TAG, "菜单项被点击,ID:" + item.getItemId());
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
// 根据菜单项 ID 判断点击的是哪个功能
|
||||
switch (item.getItemId()) {
|
||||
case MENU_ITEM_COPY:
|
||||
// 点击「复制」菜单,执行复制崩溃日志到剪贴板
|
||||
copyCrashLogToClipboard();
|
||||
break;
|
||||
case MENU_ITEM_RESTART:
|
||||
AppCrashSafetyWire.getInstance().resumeToMaximumImmediately();
|
||||
// 点击「重启」菜单:先恢复崩溃防护机制到最大等级,再重启应用
|
||||
CrashHandler.AppCrashSafetyWire.getInstance().resumeToMaximumImmediately();
|
||||
restartApp();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ====================== 内部私有工具方法 ======================
|
||||
/**
|
||||
* 重启当前应用
|
||||
* 创建页面顶部菜单(ActionBar 菜单)
|
||||
* @param menu 菜单容器,用于添加菜单项
|
||||
* @return boolean:true 表示显示菜单;false 表示不显示
|
||||
*/
|
||||
private void restartApp() {
|
||||
LogUtils.d(TAG, "开始执行应用重启逻辑");
|
||||
final PackageManager packageManager = getPackageManager();
|
||||
final Intent launchIntent = packageManager.getLaunchIntentForPackage(getPackageName());
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// 添加「复制」菜单项:
|
||||
// 参数说明:菜单组 ID(0 表示默认组)、菜单项 ID(MENU_ITEM_COPY)、排序号(0)、菜单文本("Copy")
|
||||
// setOnMenuItemClickListener(this):绑定点击事件到当前 Activity
|
||||
// setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM):有空间时显示在 ActionBar 上,否则放入溢出菜单
|
||||
menu.add(0, MENU_ITEM_COPY, 0, "Copy")
|
||||
.setOnMenuItemClickListener(this)
|
||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
|
||||
if (launchIntent != null) {
|
||||
launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
startActivity(launchIntent);
|
||||
}
|
||||
finish();
|
||||
android.os.Process.killProcess(android.os.Process.myPid());
|
||||
System.exit(0);
|
||||
// 添加「重启」菜单项(参数含义同上)
|
||||
menu.add(0, MENU_ITEM_RESTART, 0, "Restart")
|
||||
.setOnMenuItemClickListener(this)
|
||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
|
||||
// 调用自定义视图的方法,更新菜单文字样式(如颜色、字体大小等,由自定义 View 内部实现)
|
||||
mCrashReportView.updateMenuStyle();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将崩溃日志复制到系统剪贴板
|
||||
* 将崩溃日志复制到系统剪贴板(工具方法)
|
||||
* 功能:用户点击复制菜单后,将完整崩溃日志存入剪贴板,方便粘贴到聊天工具或文档中
|
||||
*/
|
||||
private void copyCrashLogToClipboard() {
|
||||
LogUtils.d(TAG, "执行复制崩溃日志到剪贴板");
|
||||
final ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
final ClipData clipData = ClipData.newPlainText(getPackageName(), mCrashLog);
|
||||
// 获取系统剪贴板服务(需通过 getSystemService 方法获取)
|
||||
ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
|
||||
// 创建剪贴板数据:
|
||||
// 参数 1:标签(用于标识剪贴板内容来源,此处用应用包名)
|
||||
// 参数 2:实际复制的文本内容(崩溃日志)
|
||||
ClipData clipData = ClipData.newPlainText(getPackageName(), mCrashLog);
|
||||
|
||||
// 将数据设置到剪贴板(完成复制操作)
|
||||
clipboardManager.setPrimaryClip(clipData);
|
||||
|
||||
// 显示复制成功的 Toast 提示(告知用户操作结果)
|
||||
Toast.makeText(getApplication(), "The text is copied.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toolbar;
|
||||
import cc.winboll.studio.libappbase.R;
|
||||
import android.content.res.Resources;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||
@@ -176,11 +175,10 @@ public class GlobalCrashReportView extends LinearLayout {
|
||||
* 初始化默认配置(无自定义属性时使用)
|
||||
*/
|
||||
private void initDefaultConfig() {
|
||||
// 设置默认配色(使用 debugTextColor 属性)
|
||||
Resources.Theme theme = mContext.getTheme();
|
||||
mTitleColor = theme.getResources().getColor(android.R.color.holo_green_dark);
|
||||
mTitleBackgroundColor = Color.GRAY;
|
||||
mTextColor = obtainDebugTextColor(theme);
|
||||
// 设置默认配色
|
||||
mTitleColor = Color.WHITE;
|
||||
mTitleBackgroundColor = Color.BLACK;
|
||||
mTextColor = Color.BLACK;
|
||||
mTextBackgroundColor = Color.WHITE;
|
||||
// 加载布局
|
||||
inflateView();
|
||||
@@ -188,21 +186,6 @@ public class GlobalCrashReportView extends LinearLayout {
|
||||
initWidgetStyle();
|
||||
}
|
||||
|
||||
private int obtainDebugTextColor(Resources.Theme theme) {
|
||||
int[] attrs = new int[] { cc.winboll.studio.libappbase.R.attr.themeDebug };
|
||||
TypedArray themeTypedArray = theme.obtainStyledAttributes(attrs);
|
||||
int themeResId = themeTypedArray.getResourceId(0, 0);
|
||||
themeTypedArray.recycle();
|
||||
if (themeResId != 0) {
|
||||
int[] debugAttrs = new int[] { cc.winboll.studio.libappbase.R.attr.debugTextColor };
|
||||
TypedArray debugTypedArray = theme.obtainStyledAttributes(themeResId, debugAttrs);
|
||||
int color = debugTypedArray.getColor(0, Color.GRAY);
|
||||
debugTypedArray.recycle();
|
||||
return color;
|
||||
}
|
||||
return Color.GRAY;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化视图(解析自定义属性 + 加载布局 + 设置样式)
|
||||
* @param attrs 自定义属性集合
|
||||
@@ -212,20 +195,23 @@ public class GlobalCrashReportView extends LinearLayout {
|
||||
TypedArray typedArray = mContext.obtainStyledAttributes(
|
||||
attrs,
|
||||
R.styleable.GlobalCrashActivity,
|
||||
R.attr.themeDebug,
|
||||
R.attr.themeGlobalCrashActivity,
|
||||
0
|
||||
);
|
||||
|
||||
// 读取自定义属性值(无设置时使用默认值)
|
||||
mTitleColor = typedArray.getColor(
|
||||
R.styleable.GlobalCrashActivity_colorTittle,
|
||||
Color.BLACK
|
||||
Color.WHITE
|
||||
);
|
||||
mTitleBackgroundColor = typedArray.getColor(
|
||||
R.styleable.GlobalCrashActivity_colorTittleBackgound, // 注:原拼写错误(Backgound→Background),保持与 attrs.xml 一致
|
||||
Color.BLACK
|
||||
);
|
||||
mTextColor = obtainDebugTextColor(mContext.getTheme());
|
||||
mTextColor = typedArray.getColor(
|
||||
R.styleable.GlobalCrashActivity_colorText,
|
||||
Color.BLACK
|
||||
);
|
||||
mTextBackgroundColor = typedArray.getColor(
|
||||
R.styleable.GlobalCrashActivity_colorTextBackgound, // 注:原拼写错误,保持与 attrs.xml 一致
|
||||
Color.WHITE
|
||||
@@ -255,8 +241,12 @@ public class GlobalCrashReportView extends LinearLayout {
|
||||
* 初始化控件样式(设置配色和基础属性)
|
||||
*/
|
||||
private void initWidgetStyle() {
|
||||
// 设置主布局背景颜色
|
||||
setBackgroundColor(mTextBackgroundColor);
|
||||
|
||||
// 配置工具栏样式
|
||||
if (mToolbar != null) {
|
||||
mToolbar.setBackgroundColor(mTitleBackgroundColor);
|
||||
mToolbar.setTitleTextColor(mTitleColor);
|
||||
mToolbar.setSubtitleTextColor(mTitleColor);
|
||||
}
|
||||
@@ -264,6 +254,8 @@ public class GlobalCrashReportView extends LinearLayout {
|
||||
// 配置日志文本控件样式
|
||||
if (mTvReport != null) {
|
||||
mTvReport.setTextColor(mTextColor);
|
||||
mTvReport.setBackgroundColor(mTextBackgroundColor);
|
||||
// 可选:设置日志文本换行方式(默认已换行,此处增强可读性)
|
||||
mTvReport.setSingleLine(false);
|
||||
mTvReport.setHorizontallyScrolling(false);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
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;
|
||||
@@ -49,39 +46,20 @@ public class LogActivity extends Activity {
|
||||
* @param context 上下文(Activity/Fragment),用于启动 Activity
|
||||
*/
|
||||
public static void startLogActivity(Context context) {
|
||||
startLogActivity(context, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动日志 Activity 的静态方法重载(外部调用入口)
|
||||
* @param context 上下文(Activity/Fragment),用于启动 Activity
|
||||
* @param newTask 是否在新窗口中启动
|
||||
*/
|
||||
public static void startLogActivity(Context context, boolean newTask) {
|
||||
// 创建启动当前 Activity 的 Intent
|
||||
Intent intent = new Intent(context, LogActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
|
||||
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);
|
||||
// 添加 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);
|
||||
|
||||
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);
|
||||
}
|
||||
// 启动 Activity
|
||||
context.startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -8,7 +8,6 @@ package cc.winboll.studio.libappbase;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.text.Editable;
|
||||
@@ -249,10 +248,7 @@ public class LogView extends RelativeLayout {
|
||||
}
|
||||
mSelectAllTAGCheckBox.setLayoutParams(layoutParams2);
|
||||
//mSelectAllTAGCheckBox.setPadding(0,0,0,0);
|
||||
TypedArray ta1 = mContext.obtainStyledAttributes(new int[] { R.attr.toolbarTextColor });
|
||||
int toolbarTextColor1 = ta1.getColor(0, mContext.getResources().getColor(R.color.white));
|
||||
ta1.recycle();
|
||||
mSelectAllTAGCheckBox.setTextColor(toolbarTextColor1);
|
||||
mSelectAllTAGCheckBox.setTextColor(mContext.getResources().getColor(R.color.white));
|
||||
mSelectAllTAGCheckBox.setOnClickListener(new View.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@@ -506,17 +502,10 @@ public class LogView extends RelativeLayout {
|
||||
}
|
||||
holder.tvText.setLayoutParams(layoutParams);
|
||||
holder.tvText.setPadding(0,0,0,0);
|
||||
TypedArray ta2 = mContext.obtainStyledAttributes(new int[] { R.attr.toolbarTextColor });
|
||||
int toolbarTextColor2 = ta2.getColor(0, mContext.getResources().getColor(R.color.white));
|
||||
ta2.recycle();
|
||||
holder.tvText.setTextColor(toolbarTextColor2);
|
||||
holder.tvText.setTextColor(mContext.getResources().getColor(R.color.white));
|
||||
holder.cbChecked.setChecked(item.isChecked());
|
||||
holder.cbChecked.setLayoutParams(layoutParams);
|
||||
holder.cbChecked.setPadding(0,0,0,0);
|
||||
TypedArray ta3 = mContext.obtainStyledAttributes(new int[] { R.attr.toolbarTextColor });
|
||||
int toolbarTextColor3 = ta3.getColor(0, mContext.getResources().getColor(R.color.white));
|
||||
ta3.recycle();
|
||||
holder.cbChecked.setTextColor(toolbarTextColor3);
|
||||
holder.cbChecked.setOnClickListener(new View.OnClickListener(){
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,186 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,99 +0,0 @@
|
||||
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(); // 关闭对话框
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,306 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,199 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,272 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,305 +0,0 @@
|
||||
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<String, String>(dataDirFileMap)
|
||||
: new HashMap<String, String>();
|
||||
this.mSdcardFileMap = (sdcardFileMap != null && !sdcardFileMap.isEmpty())
|
||||
? new HashMap<String, String>(sdcardFileMap)
|
||||
: new HashMap<String, String>();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,33 @@
|
||||
package cc.winboll.studio.libappbase.utils;
|
||||
|
||||
import android.app.Application;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import cc.winboll.studio.libappbase.CrashHandler;
|
||||
import cc.winboll.studio.libappbase.GlobalCrashActivity;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.R;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* 应用崩溃处理通知实用工具集(类库兼容版)
|
||||
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||
* @Date 2025/11/29 21:12
|
||||
* @Describe 应用崩溃处理通知实用工具集(类库兼容版)
|
||||
* 核心功能:作为独立类库使用,发送崩溃通知,点击跳转宿主应用的 GlobalCrashActivity 并传递日志
|
||||
* 适配说明:移除固定包名依赖,通过外部传入宿主包名,支持任意应用集成使用
|
||||
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
|
||||
* @CreateTime 2025/11/29 21:12:00
|
||||
* @EditTime 2026/05/11 21:55:00
|
||||
*/
|
||||
public class CrashHandleNotifyUtils {
|
||||
|
||||
// ====================== 常量定义 ======================
|
||||
public static final String TAG = "CrashHandleNotifyUtils";
|
||||
|
||||
/** 通知渠道ID(Android 8.0+ 必须) */
|
||||
private static final String CRASH_NOTIFY_CHANNEL_ID = "crash_notify_channel";
|
||||
/** 通知渠道名称(用户可见) */
|
||||
@@ -41,322 +38,202 @@ public class CrashHandleNotifyUtils {
|
||||
private static final int API_LEVEL_ANDROID_12 = 31;
|
||||
/** PendingIntent.FLAG_IMMUTABLE 常量值(API 31+) */
|
||||
private static final int FLAG_IMMUTABLE = 0x00000040;
|
||||
/** 通知摘要最大长度 */
|
||||
private static final int SUMMARY_MAX_LENGTH = 200;
|
||||
/** 分享日志请求码 */
|
||||
private static final int REQUEST_CODE_SHARE_LOG = 0x002;
|
||||
/** 缓存崩溃日志子目录 */
|
||||
private static final String CRASH_LOG_CACHE_SUBDIR = "crashnotify";
|
||||
/** 缓存崩溃日志文件名 */
|
||||
private static final String CRASH_LOG_CACHE_FILENAME = "crash_log.txt";
|
||||
|
||||
// ====================== 静态成员 ======================
|
||||
private static String sHostPackageName = "";
|
||||
private static String sCrashLogCacheFilePath = "";
|
||||
/** 通知内容最大行数(控制在3行,超出部分省略) */
|
||||
private static final int NOTIFICATION_MAX_LINES = 3;
|
||||
|
||||
// ====================== 正则表达式定义 ======================
|
||||
private static final String REGEX_EXCEPTION_TYPE = "([\\w.]+Exception|[\\w.]+Error)";
|
||||
private static final String REGEX_EXCEPTION_MESSAGE = "(?<=:\\s)(.+?)(?=\\n|\\r|$)";
|
||||
private static final String REGEX_STACK_TRACE = "\\s+at\\s+([\\w.$]+)\\.([\\w<>]+)\\(([^:]+\\.java):(\\d+)\\)";
|
||||
private static final String REGEX_CAUSE = "(?<=Caused by:\\s)" + REGEX_EXCEPTION_TYPE + "\\s*:";
|
||||
|
||||
// ====================== 对外核心方法 ======================
|
||||
/**
|
||||
* 处理未捕获异常(类库入口核心方法)
|
||||
* @param hostApp 宿主Application实例
|
||||
* @param hostPackageName 宿主应用包名
|
||||
* @param errorLog 崩溃日志内容
|
||||
* @param reportCrashActivity 崩溃详情跳转Activity类
|
||||
* 处理未捕获异常(核心方法,类库入口)
|
||||
* 改进点:新增宿主包名参数,移除类库对固定包名的依赖
|
||||
* @param hostApp 宿主应用的 Application 实例(用于获取宿主上下文)
|
||||
* @param hostPackageName 宿主应用的包名(关键:用于绑定意图、匹配 Activity)
|
||||
* @param errorLog 崩溃日志(从宿主 CrashHandler 传递过来)
|
||||
*/
|
||||
public static void handleUncaughtException(final android.app.Application hostApp,
|
||||
final String hostPackageName,
|
||||
final String errorLog,
|
||||
final Class<?> reportCrashActivity) {
|
||||
LogUtils.d(TAG, "handleUncaughtException 进入方法");
|
||||
public static void handleUncaughtException(Application hostApp, String hostPackageName, String errorLog) {
|
||||
// 1. 校验核心参数(类库场景必须严格校验,避免空指针)
|
||||
if (hostApp == null || TextUtils.isEmpty(hostPackageName) || TextUtils.isEmpty(errorLog)) {
|
||||
LogUtils.e(TAG, "handleUncaughtException 参数为空校验不通过");
|
||||
LogUtils.e(TAG, "发送崩溃通知失败:参数为空(hostApp=" + hostApp + ", hostPackageName=" + hostPackageName + ", errorLog=" + errorLog + ")");
|
||||
return;
|
||||
}
|
||||
sHostPackageName = hostPackageName;
|
||||
final String hostAppName = getHostAppName(hostApp, hostPackageName);
|
||||
final String crashLogFilePath = saveCrashLogToCache(hostApp, errorLog);
|
||||
if (TextUtils.isEmpty(crashLogFilePath)) {
|
||||
LogUtils.e(TAG, "保存崩溃日志到缓存文件失败");
|
||||
return;
|
||||
}
|
||||
sCrashLogCacheFilePath = crashLogFilePath;
|
||||
final Intent shareIntent = new Intent(hostApp, ShareLogActivity.class);
|
||||
shareIntent.putExtra(ShareLogActivity.EXTRA_CRASH_LOG_FILEPATH, crashLogFilePath);
|
||||
shareIntent.putExtra(ShareLogActivity.EXTRA_CRASH_LOG_SUBJECT, "崩溃日志");
|
||||
shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
final PendingIntent sharePendingIntent = createSharePendingIntent(hostApp, shareIntent);
|
||||
sendCrashNotification(hostApp, hostPackageName, hostAppName, errorLog, reportCrashActivity, sharePendingIntent);
|
||||
|
||||
// 2. 获取宿主应用名称(使用宿主上下文,避免类库包名混淆)
|
||||
String hostAppName = getHostAppName(hostApp, hostPackageName);
|
||||
|
||||
// 3. 发送崩溃通知到宿主通知栏(点击跳转宿主的 GlobalCrashActivity)
|
||||
sendCrashNotification(hostApp, hostPackageName, hostAppName, errorLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重载兼容方法:适配原有CrashHandler调用方式
|
||||
* @param hostApp 宿主Application实例
|
||||
* @param intent 携带崩溃信息Intent
|
||||
* @param reportCrashActivity 崩溃详情Activity
|
||||
* 重载方法:兼容原有调用逻辑(避免宿主集成时改动过大)
|
||||
* 从 Intent 中提取崩溃日志和宿主包名,适配原有 CrashHandler 调用方式
|
||||
* @param hostApp 宿主应用的 Application 实例
|
||||
* @param intent 存储崩溃信息的意图(extra 中携带崩溃日志)
|
||||
*/
|
||||
public static void handleUncaughtException(final android.app.Application hostApp,
|
||||
final Intent intent,
|
||||
final Class<?> reportCrashActivity) {
|
||||
LogUtils.d(TAG, "handleUncaughtException 重载方法进入");
|
||||
public static void handleUncaughtException(Application hostApp, Intent intent) {
|
||||
// 从意图中提取宿主包名(优先使用意图中携带的包名,无则用宿主 Application 包名)
|
||||
String hostPackageName = intent.getStringExtra("EXTRA_HOST_PACKAGE_NAME");
|
||||
if (TextUtils.isEmpty(hostPackageName)) {
|
||||
hostPackageName = hostApp.getPackageName();
|
||||
LogUtils.w(TAG, "未携带宿主包名,默认使用应用自身包名");
|
||||
LogUtils.w(TAG, "意图中未携带宿主包名,使用 Application 包名:" + hostPackageName);
|
||||
}
|
||||
final String errorLog = intent.getStringExtra(CrashHandler.EXTRA_CRASH_LOG);
|
||||
handleUncaughtException(hostApp, hostPackageName, errorLog, reportCrashActivity);
|
||||
|
||||
// 从意图中提取崩溃日志(与 CrashHandler.EXTRA_CRASH_INFO 保持一致)
|
||||
String errorLog = intent.getStringExtra(CrashHandler.EXTRA_CRASH_LOG);
|
||||
|
||||
// 调用核心方法处理
|
||||
handleUncaughtException(hostApp, hostPackageName, errorLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 资源释放
|
||||
* @param hostContext 宿主上下文
|
||||
* 获取宿主应用名称(类库场景适配:使用宿主包名获取,避免类库包名干扰)
|
||||
* @param hostContext 宿主应用的上下文(Application 实例)
|
||||
* @param hostPackageName 宿主应用的包名
|
||||
* @return 宿主应用名称(读取失败返回 "未知应用")
|
||||
*/
|
||||
public static void release(final Context hostContext) {
|
||||
LogUtils.d(TAG, "release 执行资源释放");
|
||||
sHostPackageName = "";
|
||||
sCrashLogCacheFilePath = "";
|
||||
}
|
||||
|
||||
// ====================== 内部工具方法 ======================
|
||||
/**
|
||||
* 获取宿主应用名称
|
||||
* @param hostContext 宿主上下文
|
||||
* @param hostPackageName 宿主包名
|
||||
* @return 应用名称,失败返回未知应用
|
||||
*/
|
||||
private static String getHostAppName(final Context hostContext, final String hostPackageName) {
|
||||
private static String getHostAppName(Context hostContext, String hostPackageName) {
|
||||
try {
|
||||
return hostContext.getPackageManager()
|
||||
.getApplicationLabel(hostContext.getPackageManager()
|
||||
.getApplicationInfo(hostPackageName, 0)).toString();
|
||||
// 用宿主包名获取宿主应用信息,确保获取的是宿主的应用名称(类库关键改进)
|
||||
return hostContext.getPackageManager().getApplicationLabel(
|
||||
hostContext.getPackageManager().getApplicationInfo(hostPackageName, 0)
|
||||
).toString();
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "获取宿主应用名称失败", e);
|
||||
LogUtils.e(TAG, "获取宿主应用名称失败(包名:" + hostPackageName + ")", e);
|
||||
return "未知应用";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存崩溃日志到缓存文件
|
||||
* @param hostContext 宿主上下文
|
||||
* @param crashLog 崩溃日志内容
|
||||
* @return 缓存文件路径,失败返回空字符串
|
||||
* 发送崩溃通知到宿主系统通知栏(类库兼容版)
|
||||
* 改进点:全程使用宿主上下文和宿主包名,避免类库包名依赖
|
||||
* @param hostContext 宿主应用的上下文(Application 实例)
|
||||
* @param hostPackageName 宿主应用的包名
|
||||
* @param hostAppName 宿主应用的名称(用于通知标题)
|
||||
* @param errorLog 崩溃日志(传递给宿主的 GlobalCrashActivity)
|
||||
*/
|
||||
private static String saveCrashLogToCache(final Context hostContext, final String crashLog) {
|
||||
if (hostContext == null || TextUtils.isEmpty(crashLog)) {
|
||||
return "";
|
||||
}
|
||||
BufferedReader reader = null;
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
final File cacheDir = new File(hostContext.getCacheDir(), CRASH_LOG_CACHE_SUBDIR);
|
||||
if (!cacheDir.exists()) {
|
||||
cacheDir.mkdirs();
|
||||
}
|
||||
final File cacheFile = new File(cacheDir, CRASH_LOG_CACHE_FILENAME);
|
||||
if (cacheFile.exists()) {
|
||||
cacheFile.delete();
|
||||
}
|
||||
cacheFile.createNewFile();
|
||||
fos = new FileOutputStream(cacheFile);
|
||||
fos.write(crashLog.getBytes("UTF-8"));
|
||||
fos.flush();
|
||||
LogUtils.d(TAG, "saveCrashLogToCache 保存崩溃日志到缓存: " + cacheFile.getAbsolutePath());
|
||||
return cacheFile.getAbsolutePath();
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "saveCrashLogToCache 异常", e);
|
||||
return "";
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
try { reader.close(); } catch (Exception e) {}
|
||||
}
|
||||
if (fos != null) {
|
||||
try { fos.close(); } catch (Exception e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取缓存的崩溃日志文件内容
|
||||
* @param hostContext 宿主上下文
|
||||
* @return 日志内容,失败返回空字符串
|
||||
*/
|
||||
private static String readCachedCrashLog(final Context hostContext) {
|
||||
if (hostContext == null || TextUtils.isEmpty(sCrashLogCacheFilePath)) {
|
||||
return "";
|
||||
}
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
final File cacheFile = new File(sCrashLogCacheFilePath);
|
||||
if (!cacheFile.exists()) {
|
||||
LogUtils.w(TAG, "readCachedCrashLog 缓存文件不存在");
|
||||
return "";
|
||||
}
|
||||
reader = new BufferedReader(new InputStreamReader(new FileInputStream(cacheFile), "UTF-8"));
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
sb.append(line).append("\n");
|
||||
}
|
||||
return sb.toString();
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "readCachedCrashLog 异常", e);
|
||||
return "";
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
try { reader.close(); } catch (Exception e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送崩溃系统通知
|
||||
* @param hostContext 宿主上下文
|
||||
* @param hostPackageName 宿主包名
|
||||
* @param hostAppName 宿主应用名
|
||||
* @param errorLog 崩溃日志
|
||||
* @param reportCrashActivity 跳转Activity
|
||||
* @param sharePendingIntent 分享日志PendingIntent
|
||||
*/
|
||||
private static void sendCrashNotification(final Context hostContext,
|
||||
final String hostPackageName,
|
||||
final String hostAppName,
|
||||
final String errorLog,
|
||||
final Class<?> reportCrashActivity,
|
||||
final PendingIntent sharePendingIntent) {
|
||||
final NotificationManager notificationManager =
|
||||
(NotificationManager) hostContext.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
private static void sendCrashNotification(Context hostContext, String hostPackageName, String hostAppName, String errorLog) {
|
||||
// 1. 获取宿主的通知管理器(使用宿主上下文,确保通知归属宿主应用)
|
||||
NotificationManager notificationManager = (NotificationManager) hostContext.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
if (notificationManager == null) {
|
||||
LogUtils.e(TAG, "获取NotificationManager失败");
|
||||
LogUtils.e(TAG, "获取宿主 NotificationManager 失败(包名:" + hostPackageName + ")");
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 适配 Android 8.0+(API 26+):创建宿主的通知渠道(归属宿主,避免类库渠道冲突)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
createCrashNotifyChannel(hostContext, notificationManager);
|
||||
}
|
||||
final PendingIntent jumpIntent = getGlobalCrashPendingIntent(hostContext,
|
||||
hostPackageName, errorLog, reportCrashActivity);
|
||||
|
||||
// 3. 构建通知意图(核心改进:绑定宿主包名,跳转宿主的 GlobalCrashActivity)
|
||||
PendingIntent jumpIntent = getGlobalCrashPendingIntent(hostContext, hostPackageName, errorLog);
|
||||
if (jumpIntent == null) {
|
||||
LogUtils.e(TAG, "构建跳转PendingIntent失败");
|
||||
LogUtils.e(TAG, "构建跳转意图失败(宿主包名:" + hostPackageName + ")");
|
||||
return;
|
||||
}
|
||||
final Notification notification = buildNotification(hostContext, hostPackageName, hostAppName, errorLog, jumpIntent, sharePendingIntent);
|
||||
|
||||
// 4. 构建通知实例(使用宿主上下文,确保通知资源归属宿主)
|
||||
Notification notification = buildNotification(hostContext, hostAppName, errorLog, jumpIntent);
|
||||
|
||||
// 5. 发送通知(归属宿主应用,避免类库与宿主通知混淆)
|
||||
notificationManager.notify(CRASH_NOTIFY_ID, notification);
|
||||
LogUtils.d(TAG, "崩溃通知发送成功,宿主包名:" + hostPackageName);
|
||||
LogUtils.d(TAG, "崩溃通知发送成功(宿主包名:" + hostPackageName + ",标题:" + hostAppName + ",日志长度:" + errorLog.length() + "字符)");
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建分享日志PendingIntent
|
||||
* @param hostContext 宿主上下文
|
||||
* @param shareIntent 分享意图
|
||||
* @return PendingIntent实例
|
||||
* 创建宿主应用的崩溃通知渠道(类库场景:渠道归属宿主,避免类库与宿主渠道冲突)
|
||||
* @param hostContext 宿主应用的上下文
|
||||
* @param notificationManager 宿主的通知管理器
|
||||
*/
|
||||
private static PendingIntent createSharePendingIntent(final Context hostContext, final Intent shareIntent) {
|
||||
int flags = PendingIntent.FLAG_UPDATE_CURRENT;
|
||||
if (Build.VERSION.SDK_INT >= API_LEVEL_ANDROID_12) {
|
||||
flags |= FLAG_IMMUTABLE;
|
||||
}
|
||||
return PendingIntent.getActivity(
|
||||
hostContext,
|
||||
REQUEST_CODE_SHARE_LOG,
|
||||
shareIntent,
|
||||
flags
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建通知渠道(适配Android O及以上)
|
||||
* @param hostContext 宿主上下文
|
||||
* @param notificationManager 通知管理器
|
||||
*/
|
||||
private static void createCrashNotifyChannel(final Context hostContext,
|
||||
final NotificationManager notificationManager) {
|
||||
private static void createCrashNotifyChannel(Context hostContext, NotificationManager notificationManager) {
|
||||
// 仅 Android 8.0+ 执行(避免低版本报错)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
// 构建通知渠道(归属宿主应用,描述明确类库用途)
|
||||
android.app.NotificationChannel channel = new android.app.NotificationChannel(
|
||||
CRASH_NOTIFY_CHANNEL_ID,
|
||||
CRASH_NOTIFY_CHANNEL_NAME,
|
||||
NotificationManager.IMPORTANCE_DEFAULT
|
||||
);
|
||||
channel.setDescription("应用崩溃通知(由 WinBoLL Studio 类库提供,点击查看详情)");
|
||||
// 注册渠道到宿主的通知管理器,确保渠道归属宿主
|
||||
notificationManager.createNotificationChannel(channel);
|
||||
LogUtils.d(TAG, "通知渠道创建完成");
|
||||
LogUtils.d(TAG, "宿主崩溃通知渠道创建成功(宿主包名:" + hostContext.getPackageName() + ",渠道ID:" + CRASH_NOTIFY_CHANNEL_ID + ")");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建跳转崩溃详情页PendingIntent
|
||||
* @param hostContext 宿主上下文
|
||||
* @param hostPackageName 宿主包名
|
||||
* @param errorLog 崩溃日志
|
||||
* @param reportCrashActivity 目标Activity
|
||||
* @return PendingIntent实例
|
||||
* 核心改进:构建跳转宿主 GlobalCrashActivity 的意图(类库关键)
|
||||
* 1. 绑定宿主包名,确保类库能正确启动宿主的 Activity;
|
||||
* 2. 传递崩溃日志,与宿主 GlobalCrashActivity 日志接收逻辑匹配;
|
||||
* 3. 使用宿主上下文,避免类库上下文导致的适配问题。
|
||||
* @param hostContext 宿主应用的上下文
|
||||
* @param hostPackageName 宿主应用的包名
|
||||
* @param errorLog 崩溃日志(传递给宿主的 GlobalCrashActivity)
|
||||
* @return 跳转崩溃详情页的 PendingIntent
|
||||
*/
|
||||
private static PendingIntent getGlobalCrashPendingIntent(final Context hostContext,
|
||||
final String hostPackageName,
|
||||
final String errorLog,
|
||||
final Class<?> reportCrashActivity) {
|
||||
private static PendingIntent getGlobalCrashPendingIntent(Context hostContext, String hostPackageName, String errorLog) {
|
||||
try {
|
||||
final Intent crashIntent = new Intent(hostContext, reportCrashActivity);
|
||||
// 1. 构建跳转宿主 GlobalCrashActivity 的显式意图(类库场景必须显式指定宿主包名)
|
||||
Intent crashIntent = new Intent(hostContext, GlobalCrashActivity.class);
|
||||
// 关键:绑定宿主包名,确保意图能正确匹配宿主的 Activity(避免类库包名干扰)
|
||||
crashIntent.setPackage(hostPackageName);
|
||||
// 传递崩溃日志(键:EXTRA_CRASH_INFO,与宿主 GlobalCrashActivity 完全匹配)
|
||||
crashIntent.putExtra(CrashHandler.EXTRA_CRASH_LOG, errorLog);
|
||||
// 设置意图标志:确保在宿主应用中正常启动,避免重复创建和任务栈混乱
|
||||
crashIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
|
||||
// 2. 构建 PendingIntent(使用宿主上下文,适配高版本)
|
||||
int flags = PendingIntent.FLAG_UPDATE_CURRENT;
|
||||
if (Build.VERSION.SDK_INT >= API_LEVEL_ANDROID_12) {
|
||||
flags |= FLAG_IMMUTABLE;
|
||||
}
|
||||
|
||||
return PendingIntent.getActivity(
|
||||
hostContext,
|
||||
CRASH_NOTIFY_ID,
|
||||
CRASH_NOTIFY_ID, // 用通知ID作为请求码,确保唯一(避免意图复用)
|
||||
crashIntent,
|
||||
flags
|
||||
);
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "构建跳转Intent异常", e);
|
||||
LogUtils.e(TAG, "构建跳转意图失败(宿主包名:" + hostPackageName + ")", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建Notification通知实例
|
||||
* @param hostContext 宿主上下文
|
||||
* @param hostPackageName 宿主包名
|
||||
* @param hostAppName 宿主应用名
|
||||
* @param errorLog 崩溃日志
|
||||
* @param jumpIntent 点击跳转意图
|
||||
* @param shareIntent 分享日志意图
|
||||
* @return 构建好的Notification
|
||||
* 构建通知实例(类库兼容版)
|
||||
* 改进点:使用宿主上下文加载资源,确保通知样式适配宿主应用
|
||||
* @param hostContext 宿主应用的上下文
|
||||
* @param hostAppName 宿主应用的名称(通知标题)
|
||||
* @param errorLog 崩溃日志(通知内容)
|
||||
* @param jumpIntent 通知点击跳转意图(跳转宿主的 GlobalCrashActivity)
|
||||
* @return 构建完成的 Notification 对象
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
private static Notification buildNotification(final Context hostContext,
|
||||
final String hostPackageName,
|
||||
final String hostAppName,
|
||||
final String errorLog,
|
||||
final PendingIntent jumpIntent,
|
||||
final PendingIntent shareIntent) {
|
||||
private static Notification buildNotification(Context hostContext, String hostAppName, String errorLog, PendingIntent jumpIntent) {
|
||||
// 兼容 Android 8.0+:指定宿主的通知渠道ID
|
||||
Notification.Builder builder = new Notification.Builder(hostContext);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
builder.setChannelId(CRASH_NOTIFY_CHANNEL_ID);
|
||||
}
|
||||
final String briefInfo = extractBriefInfo(errorLog);
|
||||
final Notification.BigTextStyle bigTextStyle = new Notification.BigTextStyle();
|
||||
bigTextStyle.setBigContentTitle(hostAppName + " 崩溃");
|
||||
bigTextStyle.bigText(briefInfo);
|
||||
bigTextStyle.setSummaryText("点击查看详情");
|
||||
|
||||
// 核心:用BigTextStyle控制“默认3行省略,下拉显示完整”(使用宿主上下文构建)
|
||||
Notification.BigTextStyle bigTextStyle = new Notification.BigTextStyle();
|
||||
bigTextStyle.setSummaryText("日志已省略,下拉查看完整内容");
|
||||
bigTextStyle.bigText(errorLog);
|
||||
bigTextStyle.setBigContentTitle(hostAppName + " 崩溃"); // 标题明确标识宿主和崩溃状态
|
||||
builder.setStyle(bigTextStyle);
|
||||
builder.setSmallIcon(hostContext.getApplicationInfo().icon)
|
||||
|
||||
// 配置通知核心参数(全程使用宿主上下文,确保资源归属宿主)
|
||||
builder
|
||||
// 关键:使用宿主应用的小图标(避免类库图标显示异常)
|
||||
.setSmallIcon(hostContext.getApplicationInfo().icon)
|
||||
.setContentTitle(hostAppName + " 崩溃")
|
||||
.setContentText(briefInfo.split("\n")[0])
|
||||
.setContentIntent(jumpIntent)
|
||||
.setAutoCancel(true)
|
||||
.setContentText(getShortContent(errorLog)) // 3行内缩略文本
|
||||
.setContentIntent(jumpIntent) // 点击跳转宿主的 GlobalCrashActivity
|
||||
.setAutoCancel(true) // 点击后自动关闭
|
||||
.setWhen(System.currentTimeMillis())
|
||||
.setPriority(Notification.PRIORITY_DEFAULT);
|
||||
if (shareIntent != null) {
|
||||
builder.addAction(android.R.drawable.ic_menu_send, "分享日志", shareIntent);
|
||||
}
|
||||
|
||||
// 适配 Android 4.1+:确保在宿主应用中正常显示
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
return builder.build();
|
||||
} else {
|
||||
@@ -365,79 +242,23 @@ public class CrashHandleNotifyUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* 截取缩略日志文本
|
||||
* @param content 原始日志
|
||||
* @return 缩略文案
|
||||
* 辅助方法:截取日志文本,确保显示在3行内(通用逻辑,无包名依赖)
|
||||
* @param content 完整崩溃日志
|
||||
* @return 3行内的缩略文本
|
||||
*/
|
||||
private static String getShortContent(final String errorLog) {
|
||||
if (errorLog == null || errorLog.isEmpty()) {
|
||||
private static String getShortContent(String content) {
|
||||
if (content == null || content.isEmpty()) {
|
||||
return "无崩溃日志";
|
||||
}
|
||||
final String brief = extractBriefInfo(errorLog);
|
||||
final String firstLine = brief.split("\n")[0];
|
||||
if (firstLine.length() > 80) {
|
||||
return firstLine.substring(0, 80) + "...";
|
||||
}
|
||||
return firstLine;
|
||||
int maxLength = 80; // 估算3行字符数(可根据需求调整)
|
||||
return content.length() <= maxLength ? content : content.substring(0, maxLength) + "...";
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用正则表达式从崩溃日志中提取简要信息
|
||||
* @param crashLog 完整崩溃日志
|
||||
* @return 简要崩溃信息
|
||||
* 释放资源(类库场景:空实现,避免宿主调用时报错,预留扩展)
|
||||
* @param hostContext 宿主应用的上下文(显式传入,避免类库上下文依赖)
|
||||
*/
|
||||
private static String extractBriefInfo(final String crashLog) {
|
||||
if (crashLog == null || crashLog.isEmpty()) {
|
||||
return "无崩溃日志";
|
||||
}
|
||||
final StringBuilder brief = new StringBuilder();
|
||||
try {
|
||||
java.util.regex.Pattern exceptionPattern = java.util.regex.Pattern.compile(REGEX_EXCEPTION_TYPE);
|
||||
java.util.regex.Matcher exceptionMatcher = exceptionPattern.matcher(crashLog);
|
||||
if (exceptionMatcher.find()) {
|
||||
brief.append(exceptionMatcher.group(1));
|
||||
}
|
||||
java.util.regex.Pattern messagePattern = java.util.regex.Pattern.compile(REGEX_EXCEPTION_MESSAGE);
|
||||
java.util.regex.Matcher messageMatcher = messagePattern.matcher(crashLog);
|
||||
if (messageMatcher.find()) {
|
||||
String message = messageMatcher.group(1).trim();
|
||||
if (message.length() > 100) {
|
||||
message = message.substring(0, 100) + "...";
|
||||
}
|
||||
if (brief.length() > 0) {
|
||||
brief.append(" - ");
|
||||
}
|
||||
brief.append(message);
|
||||
}
|
||||
java.util.regex.Pattern causePattern = java.util.regex.Pattern.compile(REGEX_CAUSE);
|
||||
java.util.regex.Matcher causeMatcher = causePattern.matcher(crashLog);
|
||||
if (causeMatcher.find()) {
|
||||
if (brief.length() > 0) {
|
||||
brief.append("\n");
|
||||
}
|
||||
brief.append("原因: ").append(causeMatcher.group(1));
|
||||
}
|
||||
java.util.regex.Pattern stackPattern = java.util.regex.Pattern.compile(REGEX_STACK_TRACE);
|
||||
java.util.regex.Matcher stackMatcher = stackPattern.matcher(crashLog);
|
||||
int lineCount = 0;
|
||||
while (stackMatcher.find() && lineCount < 3) {
|
||||
if (brief.length() > 0) {
|
||||
brief.append("\n");
|
||||
}
|
||||
brief.append(" at ").append(stackMatcher.group(1)).append(".")
|
||||
.append(stackMatcher.group(2)).append("(")
|
||||
.append(stackMatcher.group(3)).append(":")
|
||||
.append(stackMatcher.group(4)).append(")");
|
||||
lineCount++;
|
||||
}
|
||||
if (brief.length() == 0) {
|
||||
brief.append(crashLog.length() > SUMMARY_MAX_LENGTH ? crashLog.substring(0, SUMMARY_MAX_LENGTH) + "..." : crashLog);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "提取崩溃简要信息失败", e);
|
||||
brief.setLength(0);
|
||||
brief.append(crashLog.length() > SUMMARY_MAX_LENGTH ? crashLog.substring(0, SUMMARY_MAX_LENGTH) + "..." : crashLog);
|
||||
}
|
||||
return brief.toString();
|
||||
public static void release(Context hostContext) {
|
||||
LogUtils.d(TAG, "CrashHandleNotifyUtils 资源释放完成(宿主包名:" + (hostContext != null ? hostContext.getPackageName() : "未知") + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,487 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
package cc.winboll.studio.libappbase.utils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
/**
|
||||
* 分享崩溃日志窗口类
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
* @CreateTime 2026/05/11 22:30:00
|
||||
*/
|
||||
public class ShareLogActivity extends Activity {
|
||||
|
||||
public static final String TAG = "ShareLogActivity";
|
||||
public static final String EXTRA_CRASH_LOG_FILEPATH = "crash_log_filepath";
|
||||
public static final String EXTRA_CRASH_LOG_SUBJECT = "crash_log_subject";
|
||||
|
||||
@Override
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Log.d(TAG, "onCreate 进入方法");
|
||||
|
||||
final Intent intent = getIntent();
|
||||
if (intent == null) {
|
||||
Log.e(TAG, "onCreate intent 为空");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
final String crashLogFilePath = intent.getStringExtra(EXTRA_CRASH_LOG_FILEPATH);
|
||||
if (crashLogFilePath == null || crashLogFilePath.isEmpty()) {
|
||||
Log.e(TAG, "onCreate crashLogFilePath 为空");
|
||||
Toast.makeText(this, "日志文件路径无效", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
final String subject = intent.getStringExtra(EXTRA_CRASH_LOG_SUBJECT);
|
||||
handleShareCrashLog(crashLogFilePath, subject);
|
||||
}
|
||||
|
||||
private void handleShareCrashLog(final String crashLogFilePath, final String subject) {
|
||||
Log.d(TAG, "handleShareCrashLog crashLogFilePath = " + crashLogFilePath);
|
||||
|
||||
final File crashLogFile = new File(crashLogFilePath);
|
||||
if (!crashLogFile.exists()) {
|
||||
Log.e(TAG, "handleShareCrashLog 文件不存在");
|
||||
Toast.makeText(this, "日志文件不存在", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(new InputStreamReader(new FileInputStream(crashLogFile), "UTF-8"));
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
sb.append(line).append("\n");
|
||||
}
|
||||
final String logContent = sb.toString();
|
||||
|
||||
final Intent shareIntent = new Intent(Intent.ACTION_SEND);
|
||||
shareIntent.setType("text/plain");
|
||||
shareIntent.putExtra(Intent.EXTRA_TEXT, logContent);
|
||||
if (subject != null && !subject.isEmpty()) {
|
||||
shareIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
|
||||
} else {
|
||||
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "崩溃日志");
|
||||
}
|
||||
|
||||
startActivity(Intent.createChooser(shareIntent, "分享日志到"));
|
||||
Log.d(TAG, "handleShareCrashLog 分享成功");
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "handleShareCrashLog 异常", e);
|
||||
Toast.makeText(this, "分享失败: " + e.getMessage(), Toast.LENGTH_SHORT).show();
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
try { reader.close(); } catch (Exception e) {}
|
||||
}
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
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,7 +8,6 @@ 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;
|
||||
@@ -17,204 +16,163 @@ 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>
|
||||
* @CreateTime 2026-01-11 12:23:00
|
||||
* @LastEditTime 2026-01-24 20:50:00
|
||||
* @Describe AboutView 原生实现关于页面,无第三方依赖,适配API30;抽象通用功能控件(邮件/网页跳转),支持调试工具入口动态显隐,集成应用正版校验、调试地址配置弹窗
|
||||
* @Date 2026/01/11 12:23:00
|
||||
* @LastEditTime 2026/01/12 01:05:30
|
||||
*/
|
||||
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 static final String SERVER_DEBUG_HOST = "https://yun-preivew.winboll.cc";
|
||||
private static final String SERVER_RELEASE_HOST = "https://yun.winboll.cc";
|
||||
// 成员属性区(按 核心依赖→业务配置→视图相关 归类排序,注释清晰)
|
||||
private Context mContext; // 上下文对象,全局复用
|
||||
private APPInfo mAPPInfo; // 应用核心信息实体
|
||||
private OnRequestDevUserInfoAutofillListener mOnRequestDevUserInfoAutofillListener; // 调试信息填充监听
|
||||
|
||||
// ===================================== 核心成员属性 =====================================
|
||||
// 上下文与业务实体
|
||||
private Context mContext;
|
||||
private APPInfo mAPPInfo;
|
||||
private OnRequestDevUserInfoAutofillListener mOnRequestDevUserInfoAutofillListener;
|
||||
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 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;
|
||||
|
||||
// ===================================== 构造方法(按参数从少到多排序) =====================================
|
||||
// 构造方法区(按 参数从少到多 排序,适配 代码创建+XML引用 场景)
|
||||
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):传入应用信息,appName=" + (appInfo == null ? "null" : appInfo.getAppName()));
|
||||
// this.mContext = context;
|
||||
// this.mAPPInfo = appInfo;
|
||||
// initViewFromXml();
|
||||
// initAll();
|
||||
// }
|
||||
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, 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():重置应用信息,appName=" + (appInfo == null ? "null" : appInfo.getAppName()));
|
||||
// this.mAPPInfo = appInfo;
|
||||
// if (llFunctionContainer != null) llFunctionContainer.removeAllViews();
|
||||
// initAll();
|
||||
// LogUtils.d(TAG, "setAPPInfoAndInit():应用信息重置+页面重构完成");
|
||||
// }
|
||||
public void setAPPInfoAndInit(APPInfo appInfo) {
|
||||
LogUtils.d(TAG, "setAPPInfoAndInit() 调用,传入新APPInfo:" + (appInfo == null ? "null" : appInfo.getAppName()));
|
||||
this.mAPPInfo = appInfo;
|
||||
removeAllViews();
|
||||
initAll();
|
||||
LogUtils.d(TAG, "setAPPInfoAndInit() 应用信息重置+页面重构完成");
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置应用信息,兼容旧调用逻辑,设置后自动重构页面
|
||||
* 设置应用信息(兼容旧调用逻辑),设置后自动重构页面
|
||||
* @param appInfo 应用核心信息实体
|
||||
*/
|
||||
public void setAPPInfo(APPInfo appInfo) {
|
||||
LogUtils.d(TAG, "setAPPInfo():设置应用信息,appName=" + (appInfo == null ? "null" : appInfo.getAppName()));
|
||||
LogUtils.d(TAG, "setAPPInfo() 调用,传入APPInfo:" + (appInfo == null ? "null" : appInfo.getAppName()));
|
||||
this.mAPPInfo = appInfo;
|
||||
if (llFunctionContainer != null) llFunctionContainer.removeAllViews();
|
||||
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() ? SERVER_DEBUG_HOST : SERVER_RELEASE_HOST;
|
||||
mnAppIcon = (mnAppIcon == 0) ? R.drawable.ic_winboll : mnAppIcon;
|
||||
LogUtils.d(TAG, "initDefaultParams() 执行默认参数初始化");
|
||||
mszWinBoLLServerHost = GlobalApplication.isDebugging() ? "https://yun-preivew.winboll.cc" : "https://yun.winboll.cc";
|
||||
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();
|
||||
@@ -222,44 +180,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.e(TAG, "initAPPVersionInfo():获取版本号失败,默认赋值unknown", e);
|
||||
LogUtils.d(TAG, "initAppVersionInfo() 获取版本号失败,默认赋值unknown", e);
|
||||
mszAppVersionName = "unknown";
|
||||
}
|
||||
mszCurrentAppPackageName = String.format("%s_%s.apk", mszAppVersionName, mszAppVersionName);
|
||||
LogUtils.d(TAG, "initAPPVersionInfo():版本信息初始化完成,版本号=" + mszAppVersionName + ",当前APK名=" + mszCurrentAppPackageName);
|
||||
mszCurrentAppPackageName = String.format("%s_%s.apk", mszAppAPKName, 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 {
|
||||
@@ -267,98 +225,102 @@ 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.e(TAG, "initReleaseAPKInfo():获取正式版版本号失败", e);
|
||||
LogUtils.d(TAG, "initReleaseAPKInfo() 获取正式版版本号失败", e);
|
||||
}
|
||||
mszReleaseAPKName = String.format("%s_%s.apk", mszAppAPKName, szReleaseAppVersionName);
|
||||
LogUtils.d(TAG, "initReleaseAPKInfo():正式版APK信息初始化完成,APK名=" + mszReleaseAPKName);
|
||||
LogUtils.d(TAG, "initReleaseAPKInfo() 完成,正式版APK名:" + mszReleaseAPKName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 核心视图组装:赋值基础信息到控件,添加通用功能项到容器
|
||||
* 核心视图组装:按 图标→应用信息→分割线→通用功能控件 顺序构建页面
|
||||
*/
|
||||
private void initAboutPageView() {
|
||||
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));
|
||||
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));
|
||||
if (!mszHomePage.isEmpty()) {
|
||||
addFunctionView(new WebJumpFunctionItemView(mContext, "应用APK下载地址", mszHomePage, R.drawable.ic_winboll));
|
||||
addView(new WebJumpFunctionItemView(mContext, "应用APK下载地址", mszHomePage, R.drawable.ic_winboll));
|
||||
}
|
||||
if (!mszGitea.isEmpty()) {
|
||||
addFunctionView(new WebJumpFunctionItemView(mContext, "应用Git源码地址", mszGitea, R.drawable.ic_winboll));
|
||||
addView(new WebJumpFunctionItemView(mContext, "应用Git源码地址", mszGitea, R.drawable.ic_winboll));
|
||||
}
|
||||
LogUtils.d(TAG, "initAboutPageView():视图组装完成,功能项加载完毕");
|
||||
LogUtils.d(TAG, "initAboutPageView() 视图组装完成,功能项加载完毕");
|
||||
}
|
||||
|
||||
// ===================================== 内部工具/事件方法 =====================================
|
||||
// 视图构建辅助方法区(基础视图组件)
|
||||
/**
|
||||
* 绑定功能按钮点击事件,处理正版校验、调试地址配置弹窗唤起
|
||||
* 添加应用图标组件,居中展示
|
||||
*/
|
||||
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():功能按钮点击事件绑定完成");
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加功能项视图到容器,统一设置间距
|
||||
* @param view 功能项视图
|
||||
* 添加应用名称+版本号+描述信息组件,垂直居中展示
|
||||
*/
|
||||
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 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* dp转px工具方法,适配不同屏幕密度,保证布局一致性
|
||||
* 添加视图分割线,区分不同功能模块
|
||||
*/
|
||||
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 工具方法,适配不同屏幕密度,保证布局一致性
|
||||
* @param dpValue dp单位尺寸
|
||||
* @return 转换后的px单位尺寸
|
||||
*/
|
||||
@@ -373,20 +335,17 @@ 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;
|
||||
@@ -404,33 +363,17 @@ 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);
|
||||
setBackground(create_item_background());
|
||||
setBackgroundResource(android.R.drawable.list_selector_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_300));
|
||||
drawable.setCornerRadius(4);
|
||||
boolean isNightMode = (mItemContext.getResources().getConfiguration().uiMode & android.content.res.Configuration.UI_MODE_NIGHT_MASK) == android.content.res.Configuration.UI_MODE_NIGHT_YES;
|
||||
drawable.setColor(isNightMode ? mItemContext.getResources().getColor(R.color.gray_800) : mItemContext.getResources().getColor(android.R.color.white));
|
||||
return drawable;
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一构建功能项视图(左侧图标+右侧标题/内容)
|
||||
*/
|
||||
// 统一视图构建
|
||||
private void initItemViews() {
|
||||
// 左侧图标
|
||||
if (mIconRes != 0) {
|
||||
@@ -441,18 +384,20 @@ 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);
|
||||
boolean isNightMode = (mItemContext.getResources().getConfiguration().uiMode & android.content.res.Configuration.UI_MODE_NIGHT_MASK) == android.content.res.Configuration.UI_MODE_NIGHT_YES;
|
||||
tvTitle.setTextColor(isNightMode ? mItemContext.getResources().getColor(R.color.gray_500) : mItemContext.getResources().getColor(R.color.gray_900));
|
||||
tvTitle.setTextColor(mItemContext.getResources().getColor(R.color.gray_900));
|
||||
llText.addView(tvTitle);
|
||||
|
||||
// 内容
|
||||
TextView tvContent = new TextView(mItemContext);
|
||||
tvContent.setText(mContent);
|
||||
@@ -462,17 +407,11 @@ 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);
|
||||
@@ -485,37 +424,36 @@ public class AboutView extends LinearLayout {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
LogUtils.d(TAG, "EmailFunctionItemView onClick:触发邮件唤起逻辑");
|
||||
// 方案1:纯邮件客户端唤起
|
||||
LogUtils.d(TAG, "EmailFunctionItemView onClick 触发邮件唤起");
|
||||
// 双方案邮件唤起逻辑
|
||||
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, "EmailFunctionItemView:纯邮件客户端唤起成功");
|
||||
LogUtils.d(TAG, "邮件唤起成功:系统纯邮件客户端");
|
||||
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, "EmailFunctionItemView:通用邮件应用唤起成功");
|
||||
LogUtils.d(TAG, "邮件唤起成功:通用邮件应用");
|
||||
} else {
|
||||
ToastUtils.show("未找到可发送邮件的应用");
|
||||
LogUtils.w(TAG, "EmailFunctionItemView:邮件唤起失败,无可用邮件应用");
|
||||
LogUtils.w(TAG, "邮件唤起失败:无可用邮件相关应用");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ===================================== 内部网页跳转功能项子类 =====================================
|
||||
/**
|
||||
* 网页跳转类功能控件,实现专属网页唤起逻辑,包含空地址校验、异常捕获
|
||||
*/
|
||||
// 网页跳转类功能控件 - 专属网页跳转逻辑
|
||||
private class WebJumpFunctionItemView extends BaseFunctionItemView {
|
||||
public WebJumpFunctionItemView(Context context, String title, String content, int iconRes) {
|
||||
super(context, title, content, iconRes);
|
||||
@@ -528,28 +466,25 @@ 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, "WebJumpFunctionItemView:网页跳转失败,地址为空");
|
||||
LogUtils.w(TAG, "网页跳转失败:地址为空");
|
||||
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, "WebJumpFunctionItemView:网页跳转成功");
|
||||
LogUtils.d(TAG, "网页跳转成功");
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "WebJumpFunctionItemView:网页跳转失败", e);
|
||||
LogUtils.d(TAG, "网页跳转失败,异常捕获", e);
|
||||
ToastUtils.show("链接无法打开");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ===================================== 内部回调接口 =====================================
|
||||
/**
|
||||
* 调试信息自动填充回调接口
|
||||
*/
|
||||
// 内部接口区(置于类末尾,逻辑闭环)
|
||||
public interface OnRequestDevUserInfoAutofillListener {
|
||||
void requestAutofill(EditText etDevUserName, EditText etDevUserPassword);
|
||||
}
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package cc.winboll.studio.libappbase.widget;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.text.TextUtils;
|
||||
import android.content.res.TypedArray;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
@@ -154,12 +153,9 @@ public class LogTagSpinner extends Spinner {
|
||||
itemTv.setPadding(mTextPadding, 0, mTextPadding, 0);
|
||||
// 4. 文字对齐(垂直居中+靠左,符合常规 UI 设计)
|
||||
//itemTv.setGravity(View.GRAVITY_CENTER_VERTICAL | View.GRAVITY_START);
|
||||
// 5. 文字颜色(使用主题属性 ?attr/toolbarTextColor)
|
||||
TypedArray ta = mContext.obtainStyledAttributes(new int[] { R.attr.toolbarTextColor });
|
||||
int toolbarTextColor = ta.getColor(0, mContext.getResources().getColor(R.color.white));
|
||||
ta.recycle();
|
||||
itemTv.setTextColor(toolbarTextColor);
|
||||
itemTv.setBackgroundColor(this.mContext.getResources().getColor(R.color.btn_gray_normal));
|
||||
// 5. 文字颜色(统一深色,可改为项目颜色资源)
|
||||
itemTv.setTextColor(this.mContext.getColor(R.color.white));
|
||||
itemTv.setBackgroundColor(this.mContext.getColor(R.color.btn_gray_normal));
|
||||
// 6. 文字溢出处理(最多 2 行,超出省略,避免长标签换行过多)
|
||||
itemTv.setSingleLine(false);
|
||||
itemTv.setMaxLines(2);
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
<?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>
|
||||
@@ -1,11 +0,0 @@
|
||||
<?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>
|
||||
@@ -1,18 +0,0 @@
|
||||
<?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>
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
<?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:background="?attr/activityBackgroundColor">
|
||||
|
||||
<android.widget.Toolbar
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/toolbarBackgroundColor"
|
||||
android:id="@+id/toolbar"/>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1.0"
|
||||
android:id="@+id/aboutviewroot_ll"/>
|
||||
</LinearLayout>
|
||||
@@ -1,16 +0,0 @@
|
||||
<?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:background="?attr/activityBackgroundColor">>
|
||||
|
||||
<cc.winboll.studio.libappbase.GlobalCrashReportView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/activityglobalcrashGlobalCrashReportView1"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="24dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:background="?attr/activityBackgroundColor">
|
||||
|
||||
<!-- NFC状态提示文本 -->
|
||||
<TextView
|
||||
android:id="@+id/tv_nfc_state"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="正在监听NFC卡片,请贴近设备检测密钥..."
|
||||
android:textSize="17sp"
|
||||
android:textColor="?attr/activityTextColor"
|
||||
android:gravity="center"
|
||||
android:padding="12dp"
|
||||
android:layout_marginBottom="30dp"/>
|
||||
|
||||
<!-- 私钥显示区域 -->
|
||||
<TextView
|
||||
android:id="@+id/tv_private_key"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="私钥内容:无"
|
||||
android:textSize="14sp"
|
||||
android:textColor="?attr/activityTextColor"
|
||||
android:layout_marginBottom="12dp"
|
||||
android:maxLines="5"
|
||||
android:ellipsize="end"/>
|
||||
|
||||
<!-- 公钥显示区域 -->
|
||||
<TextView
|
||||
android:id="@+id/tv_public_key"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="公钥内容:无"
|
||||
android:textSize="14sp"
|
||||
android:textColor="?attr/activityTextColor"
|
||||
android:layout_marginBottom="40dp"
|
||||
android:maxLines="5"
|
||||
android:ellipsize="end"/>
|
||||
|
||||
<!-- 核心功能按钮(复用:保存本地/初始化密钥) -->
|
||||
<Button
|
||||
android:id="@+id/btn_create_write_key"
|
||||
android:layout_width="300dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="功能按钮待激活"
|
||||
android:textSize="16sp"
|
||||
android:textColor="?attr/toolbarTextColor"
|
||||
android:backgroundTint="?attr/toolbarBackgroundColor"
|
||||
android:padding="14dp"
|
||||
android:enabled="false"/>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -1,52 +0,0 @@
|
||||
<?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="?attr/dialogBackgroundColor">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="应用指纹校验"
|
||||
android:textSize="16sp"
|
||||
android:textColor="?attr/dialogTextColor"
|
||||
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="?attr/dialogTextColor"/>/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
<?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="?attr/dialogBackgroundColor">
|
||||
|
||||
<!-- 标题 -->
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="设置服务器地址"
|
||||
android:textSize="16sp"
|
||||
android:textColor="?attr/dialogTextColor"
|
||||
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:textColor="?attr/dialogTextColor"
|
||||
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:textColor="?attr/dialogTextColor"
|
||||
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="?attr/toolbarBackgroundColor"
|
||||
android:textColor="?attr/toolbarTextColor"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
<?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="horizontal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/bg_border_round">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/log_button_height"
|
||||
android:textSize="@dimen/log_text_size"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:id="@+id/viewlogtagTextView1"/>
|
||||
|
||||
<CheckBox
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/log_button_height"
|
||||
android:textSize="@dimen/log_text_size"
|
||||
android:textColor="?attr/toolbarTextColor"
|
||||
android:id="@+id/viewlogtagCheckBox1"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
<?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"
|
||||
android:background="?attr/aboutViewBackgroundColor">
|
||||
|
||||
<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="?attr/aboutViewTitleColor"/>
|
||||
|
||||
<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="?attr/aboutViewTextColor"/>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1px"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:background="?attr/aboutViewDividerColor"/>
|
||||
|
||||
<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>
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
<?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:theme="?attr/themeDebug"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/colorTextBackgound"
|
||||
android:id="@+id/viewglobalcrashreportLinearLayout1">
|
||||
|
||||
<android.widget.Toolbar
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/colorTittleBackgound"
|
||||
android:titleTextColor="?attr/colorTittle"
|
||||
android:id="@+id/viewglobalcrashreportToolbar1"/>
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1.0"
|
||||
android:fillViewport="true">
|
||||
|
||||
<HorizontalScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp"
|
||||
android:textColor="?attr/colorText"
|
||||
android:id="@+id/viewglobalcrashreportTextView1"/>
|
||||
|
||||
</HorizontalScrollView>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -1,151 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:theme="?attr/themeDebug"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/colorTextBackgound">
|
||||
|
||||
<RelativeLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="34dp"
|
||||
android:layout_alignParentTop="true"
|
||||
android:background="?attr/colorTittleBackgound"
|
||||
android:id="@+id/viewlogRelativeLayoutToolbar">
|
||||
|
||||
<Button
|
||||
android:layout_width="@dimen/log_button_width"
|
||||
android:layout_height="@dimen/log_button_height"
|
||||
android:textSize="@dimen/log_text_size"
|
||||
android:text="Clean"
|
||||
android:textColor="?attr/activityTextColor"
|
||||
android:background="?attr/toolbarBackgroundColor"
|
||||
android:layout_centerVertical="true"
|
||||
android:id="@+id/viewlogButtonClean"
|
||||
android:layout_marginLeft="5dp"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="20dp"
|
||||
android:textSize="@dimen/log_text_size"
|
||||
android:padding="@dimen/log_text_padding"
|
||||
android:text="LV:"
|
||||
android:layout_toRightOf="@+id/viewlogButtonClean"
|
||||
android:layout_centerVertical="true"
|
||||
android:id="@+id/viewlogTextView1"
|
||||
android:background="?attr/colorTittleBackgound"
|
||||
android:textColor="?attr/toolbarTextColor"/>
|
||||
|
||||
<cc.winboll.studio.libappbase.widget.LogTagSpinner
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toRightOf="@+id/viewlogTextView1"
|
||||
android:layout_centerVertical="true"
|
||||
android:id="@+id/viewlogSpinner1"
|
||||
android:padding="@dimen/log_spinner_text_padding"/>
|
||||
|
||||
<CheckBox
|
||||
android:layout_width="@dimen/log_checkbox_width"
|
||||
android:layout_height="@dimen/log_checkbox_height"
|
||||
android:textSize="@dimen/log_text_size"
|
||||
android:layout_toLeftOf="@+id/viewlogButtonCopy"
|
||||
android:layout_centerVertical="true"
|
||||
android:text="Selectable"
|
||||
android:background="?attr/colorTittleBackgound"
|
||||
android:id="@+id/viewlogCheckBoxSelectable"
|
||||
android:padding="@dimen/log_text_padding"
|
||||
android:textColor="?attr/toolbarTextColor"/>
|
||||
|
||||
<Button
|
||||
android:layout_width="@dimen/log_button_width"
|
||||
android:layout_height="@dimen/log_button_height"
|
||||
android:textSize="@dimen/log_text_size"
|
||||
android:textColor="?attr/activityTextColor"
|
||||
android:background="?attr/toolbarBackgroundColor"
|
||||
android:text="Copy"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:id="@+id/viewlogButtonCopy"
|
||||
android:layout_marginRight="5dp"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/log_button_height"
|
||||
android:layout_below="@+id/viewlogRelativeLayoutToolbar"
|
||||
android:id="@+id/viewlogLinearLayout1"
|
||||
android:gravity="center_vertical"
|
||||
android:background="?attr/colorTittleBackgound">
|
||||
|
||||
<CheckBox
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/log_button_height"
|
||||
android:textSize="@dimen/log_text_size"
|
||||
android:text="ALL"
|
||||
android:padding="2dp"
|
||||
android:id="@+id/viewlogCheckBox1"
|
||||
android:background="?attr/colorTittleBackgound"
|
||||
android:textColor="?attr/toolbarTextColor"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_marginRight="5dp"/>
|
||||
|
||||
<EditText
|
||||
android:layout_width="50dp"
|
||||
android:ems="10"
|
||||
android:layout_height="@dimen/log_button_height"
|
||||
android:textSize="@dimen/log_text_size"
|
||||
android:textColor="?attr/colorText"
|
||||
android:background="?attr/colorTittleBackgound"
|
||||
android:singleLine="true"
|
||||
android:id="@+id/tagsearch_et"/>
|
||||
|
||||
<HorizontalScrollView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/colorTittleBackgound"
|
||||
android:scrollbars="none"
|
||||
android:padding="2dp"
|
||||
android:layout_weight="1.0"
|
||||
android:id="@+id/viewlogHorizontalScrollView1">
|
||||
|
||||
<cc.winboll.studio.libappbase.views.HorizontalListView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/tags_listview"/>
|
||||
|
||||
</HorizontalScrollView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1.0"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_below="@+id/viewlogLinearLayout1">
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/colorTextBackgound"
|
||||
android:id="@+id/viewlogScrollViewLog">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:textSize="@dimen/log_text_size"
|
||||
android:text="Text"
|
||||
android:textColor="?attr/debugTextColor"
|
||||
android:textIsSelectable="true"
|
||||
android:id="@+id/viewlogTextViewLog"/>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
@@ -4,13 +4,11 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/activityBackgroundColor">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<android.widget.Toolbar
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/toolbarBackgroundColor"
|
||||
android:id="@+id/toolbar"/>
|
||||
|
||||
<LinearLayout
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/activityBackgroundColor">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<cc.winboll.studio.libappbase.GlobalCrashReportView
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/activityBackgroundColor">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<cc.winboll.studio.libappbase.LogView
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
android:orientation="vertical"
|
||||
android:padding="24dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:background="?attr/activityBackgroundColor">
|
||||
android:background="@android:color/white">
|
||||
|
||||
<!-- NFC状态提示文本 -->
|
||||
<TextView
|
||||
@@ -14,7 +14,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:text="正在监听NFC卡片,请贴近设备检测密钥..."
|
||||
android:textSize="17sp"
|
||||
android:textColor="?attr/activityTextColor"
|
||||
android:textColor="@android:color/black"
|
||||
android:gravity="center"
|
||||
android:padding="12dp"
|
||||
android:layout_marginBottom="30dp"/>
|
||||
@@ -26,7 +26,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:text="私钥内容:无"
|
||||
android:textSize="14sp"
|
||||
android:textColor="?attr/activityTextColor"
|
||||
android:textColor="@android:color/darker_gray"
|
||||
android:layout_marginBottom="12dp"
|
||||
android:maxLines="5"
|
||||
android:ellipsize="end"/>
|
||||
@@ -38,7 +38,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:text="公钥内容:无"
|
||||
android:textSize="14sp"
|
||||
android:textColor="?attr/activityTextColor"
|
||||
android:textColor="@android:color/darker_gray"
|
||||
android:layout_marginBottom="40dp"
|
||||
android:maxLines="5"
|
||||
android:ellipsize="end"/>
|
||||
@@ -50,9 +50,10 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:text="功能按钮待激活"
|
||||
android:textSize="16sp"
|
||||
android:textColor="?attr/toolbarTextColor"
|
||||
android:backgroundTint="?attr/toolbarBackgroundColor"
|
||||
android:textColor="@android:color/white"
|
||||
android:backgroundTint="@android:color/holo_blue_light"
|
||||
android:padding="14dp"
|
||||
android:enabled="false"/>
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
<?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="?attr/dialogBackgroundColor">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="应用指纹校验"
|
||||
android:textSize="16sp"
|
||||
android:textColor="?attr/dialogTextColor"
|
||||
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="?attr/dialogTextColor"/>/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
<?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="?attr/dialogBackgroundColor">
|
||||
|
||||
<!-- 标题 -->
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="设置服务器地址"
|
||||
android:textSize="16sp"
|
||||
android:textColor="?attr/dialogTextColor"
|
||||
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:textColor="?attr/dialogTextColor"
|
||||
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:textColor="?attr/dialogTextColor"
|
||||
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="?attr/toolbarBackgroundColor"
|
||||
android:textColor="?attr/toolbarTextColor"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/log_button_height"
|
||||
android:textSize="@dimen/log_text_size"
|
||||
android:textColor="?attr/toolbarTextColor"
|
||||
android:id="@+id/viewlogtagCheckBox1"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
<?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"
|
||||
android:background="?attr/aboutViewBackgroundColor">
|
||||
|
||||
<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="?attr/aboutViewTitleColor"/>
|
||||
|
||||
<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="?attr/aboutViewTextColor"/>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1px"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:background="?attr/aboutViewDividerColor"/>
|
||||
|
||||
<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>
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="12dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/notification_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="#333333"
|
||||
android:singleLine="true"
|
||||
android:ellipsize="end" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/notification_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:textSize="14sp"
|
||||
android:textColor="#666666"
|
||||
android:minHeight="200dp" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -1,27 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="12dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/notification_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="#333333"
|
||||
android:singleLine="true"
|
||||
android:ellipsize="end" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/notification_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:textSize="13sp"
|
||||
android:textColor="#666666"
|
||||
android:scrollbars="vertical" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -2,35 +2,29 @@
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:theme="?attr/themeDebug"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/colorTextBackgound"
|
||||
android:id="@+id/viewglobalcrashreportLinearLayout1">
|
||||
|
||||
<android.widget.Toolbar
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/colorTittleBackgound"
|
||||
android:titleTextColor="?attr/colorTittle"
|
||||
android:id="@+id/viewglobalcrashreportToolbar1"/>
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1.0"
|
||||
android:fillViewport="true">
|
||||
android:layout_weight="1.0">
|
||||
|
||||
<HorizontalScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp"
|
||||
android:textColor="?attr/colorText"
|
||||
android:background="#FFFFFFFF"
|
||||
android:id="@+id/viewglobalcrashreportTextView1"/>
|
||||
|
||||
</HorizontalScrollView>
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:theme="?attr/themeDebug"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/colorTextBackgound">
|
||||
android:background="#FF000000">
|
||||
|
||||
<RelativeLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="34dp"
|
||||
android:layout_alignParentTop="true"
|
||||
android:background="?attr/colorTittleBackgound"
|
||||
android:background="@drawable/bg_toolbar_log"
|
||||
android:id="@+id/viewlogRelativeLayoutToolbar">
|
||||
|
||||
<Button
|
||||
@@ -20,8 +19,8 @@
|
||||
android:layout_height="@dimen/log_button_height"
|
||||
android:textSize="@dimen/log_text_size"
|
||||
android:text="Clean"
|
||||
android:textColor="?attr/activityTextColor"
|
||||
android:background="?attr/toolbarBackgroundColor"
|
||||
android:textColor="@color/white"
|
||||
android:backgroundTint="@drawable/btn_gray_bg"
|
||||
android:layout_centerVertical="true"
|
||||
android:id="@+id/viewlogButtonClean"
|
||||
android:layout_marginLeft="5dp"/>
|
||||
@@ -35,8 +34,8 @@
|
||||
android:layout_toRightOf="@+id/viewlogButtonClean"
|
||||
android:layout_centerVertical="true"
|
||||
android:id="@+id/viewlogTextView1"
|
||||
android:background="?attr/colorTittleBackgound"
|
||||
android:textColor="?attr/toolbarTextColor"/>
|
||||
android:background="@color/btn_gray_normal"
|
||||
android:textColor="@color/black"/>
|
||||
|
||||
<cc.winboll.studio.libappbase.widget.LogTagSpinner
|
||||
android:layout_width="wrap_content"
|
||||
@@ -53,17 +52,17 @@
|
||||
android:layout_toLeftOf="@+id/viewlogButtonCopy"
|
||||
android:layout_centerVertical="true"
|
||||
android:text="Selectable"
|
||||
android:background="?attr/colorTittleBackgound"
|
||||
android:background="@color/btn_gray_normal"
|
||||
android:id="@+id/viewlogCheckBoxSelectable"
|
||||
android:padding="@dimen/log_text_padding"
|
||||
android:textColor="?attr/toolbarTextColor"/>
|
||||
android:textColor="@color/white"/>
|
||||
|
||||
<Button
|
||||
android:layout_width="@dimen/log_button_width"
|
||||
android:layout_height="@dimen/log_button_height"
|
||||
android:textSize="@dimen/log_text_size"
|
||||
android:textColor="?attr/activityTextColor"
|
||||
android:background="?attr/toolbarBackgroundColor"
|
||||
android:textColor="@color/white"
|
||||
android:backgroundTint="@drawable/btn_gray_bg"
|
||||
android:text="Copy"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
@@ -79,7 +78,7 @@
|
||||
android:layout_below="@+id/viewlogRelativeLayoutToolbar"
|
||||
android:id="@+id/viewlogLinearLayout1"
|
||||
android:gravity="center_vertical"
|
||||
android:background="?attr/colorTittleBackgound">
|
||||
android:background="@drawable/bg_toolbar_log">
|
||||
|
||||
<CheckBox
|
||||
android:layout_width="wrap_content"
|
||||
@@ -88,8 +87,7 @@
|
||||
android:text="ALL"
|
||||
android:padding="2dp"
|
||||
android:id="@+id/viewlogCheckBox1"
|
||||
android:background="?attr/colorTittleBackgound"
|
||||
android:textColor="?attr/toolbarTextColor"
|
||||
android:background="@drawable/bg_border_round"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_marginRight="5dp"/>
|
||||
|
||||
@@ -98,15 +96,13 @@
|
||||
android:ems="10"
|
||||
android:layout_height="@dimen/log_button_height"
|
||||
android:textSize="@dimen/log_text_size"
|
||||
android:textColor="?attr/colorText"
|
||||
android:background="?attr/colorTittleBackgound"
|
||||
android:singleLine="true"
|
||||
android:id="@+id/tagsearch_et"/>
|
||||
|
||||
<HorizontalScrollView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/colorTittleBackgound"
|
||||
android:background="@drawable/bg_border"
|
||||
android:scrollbars="none"
|
||||
android:padding="2dp"
|
||||
android:layout_weight="1.0"
|
||||
@@ -132,7 +128,7 @@
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/colorTextBackgound"
|
||||
android:background="#FF000000"
|
||||
android:id="@+id/viewlogScrollViewLog">
|
||||
|
||||
<TextView
|
||||
@@ -140,7 +136,7 @@
|
||||
android:layout_height="match_parent"
|
||||
android:textSize="@dimen/log_text_size"
|
||||
android:text="Text"
|
||||
android:textColor="?attr/debugTextColor"
|
||||
android:textColor="#FF00FF00"
|
||||
android:textIsSelectable="true"
|
||||
android:id="@+id/viewlogTextViewLog"/>
|
||||
|
||||
@@ -148,4 +144,5 @@
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
</RelativeLayout>
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user