mirror of
https://github.com/fankes/TSBattery.git
synced 2025-09-04 17:55:30 +08:00
Compare commits
55 Commits
Author | SHA1 | Date | |
---|---|---|---|
7a1c53ed17 | |||
a4d62137a2 | |||
beb8da210d | |||
60aecc67bf | |||
69faade0e4 | |||
4ecc694dd4 | |||
674f0a9cd7 | |||
b14b9e02e2 | |||
bacff6b275 | |||
5eb2729eb6 | |||
d93b4bdc7f | |||
f1e64c293c | |||
8b2663c3cb | |||
a5b1a57a93 | |||
d2dd6c9f88 | |||
e4d1ea8519 | |||
d293e4656d | |||
731cfc13d4 | |||
342128a692 | |||
c08facd9f6 | |||
3dfd69dbc7 | |||
d13aee534e | |||
9f8f21dc9a | |||
90258a07c1 | |||
c6bed6549e | |||
b26b78e268 | |||
ef97306151 | |||
26a4a11149 | |||
dc14585805 | |||
8841ad7f59 | |||
190f59451f | |||
7ce09ac4ef | |||
a182e0e4d5 | |||
bb69b762d0 | |||
e276ee4172 | |||
692acd3358 | |||
6360859255 | |||
22f8e14afb | |||
07a6fb6cf7 | |||
163eecc0b8 | |||
5707a8b394 | |||
11aa064b90 | |||
15b1bfa498 | |||
|
673dc8127b | ||
|
7d9c360c9d | ||
d5e885db6c | |||
7481bbd7ef | |||
23c94e4e26 | |||
ead73eb23d | |||
5d82e9a104 | |||
|
14d1b9c5ac | ||
|
44ea28edda | ||
b075fd8424 | |||
4395f31895 | |||
a25d2b814b |
3
.idea/gradle.xml
generated
3
.idea/gradle.xml
generated
@@ -4,9 +4,10 @@
|
|||||||
<component name="GradleSettings">
|
<component name="GradleSettings">
|
||||||
<option name="linkedExternalProjectsSettings">
|
<option name="linkedExternalProjectsSettings">
|
||||||
<GradleProjectSettings>
|
<GradleProjectSettings>
|
||||||
<option name="testRunner" value="PLATFORM" />
|
<option name="testRunner" value="GRADLE" />
|
||||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
|
<option name="gradleJvm" value="11" />
|
||||||
<option name="modules">
|
<option name="modules">
|
||||||
<set>
|
<set>
|
||||||
<option value="$PROJECT_DIR$" />
|
<option value="$PROJECT_DIR$" />
|
||||||
|
15
.idea/jarRepositories.xml
generated
15
.idea/jarRepositories.xml
generated
@@ -26,5 +26,20 @@
|
|||||||
<option name="name" value="Google" />
|
<option name="name" value="Google" />
|
||||||
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
|
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
|
||||||
</remote-repository>
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="maven3" />
|
||||||
|
<option name="name" value="maven3" />
|
||||||
|
<option name="url" value="https://www.jitpack.io" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="maven" />
|
||||||
|
<option name="name" value="maven" />
|
||||||
|
<option name="url" value="https://maven.aliyun.com/nexus/content/groups/public/" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="maven2" />
|
||||||
|
<option name="name" value="maven2" />
|
||||||
|
<option name="url" value="https://maven.aliyun.com/nexus/content/repositories/jcenter" />
|
||||||
|
</remote-repository>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
14
.idea/misc.xml
generated
14
.idea/misc.xml
generated
@@ -1,6 +1,18 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
<component name="DesignSurface">
|
||||||
|
<option name="filePathToZoomLevelMap">
|
||||||
|
<map>
|
||||||
|
<entry key="app/src/main/res/drawable-v24/dark_round.xml" value="0.4482051282051282" />
|
||||||
|
<entry key="app/src/main/res/drawable/button_round.xml" value="0.44871794871794873" />
|
||||||
|
<entry key="app/src/main/res/drawable/dark_round.xml" value="0.4482051282051282" />
|
||||||
|
<entry key="app/src/main/res/drawable/permotion_round.xml" value="0.4482051282051282" />
|
||||||
|
<entry key="app/src/main/res/drawable/red_round.xml" value="0.4482051282051282" />
|
||||||
|
<entry key="app/src/main/res/layout/activity_main.xml" value="0.3586910327241819" />
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectType">
|
<component name="ProjectType">
|
||||||
|
10
.idea/runConfigurations.xml
generated
10
.idea/runConfigurations.xml
generated
@@ -1,10 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="RunConfigurationProducerService">
|
|
||||||
<option name="ignoredProducers">
|
|
||||||
<set>
|
|
||||||
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
|
|
||||||
</set>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
47
CONTRIBUTING.md
Normal file
47
CONTRIBUTING.md
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
# 开始贡献
|
||||||
|
|
||||||
|
欢迎为此项目进行新版本的适配代码贡献!<br/>
|
||||||
|
|
||||||
|
## 分支规定
|
||||||
|
|
||||||
|
不管是直接 Push 代码还是提交 Pull Request,都必须使 commit 指向 master 分支。
|
||||||
|
|
||||||
|
## 代码格式规范
|
||||||
|
|
||||||
|
- 1.全部提交代码必须使用 IDE(Android Studio 或 IDEA) 进行格式化,未经格式化的代码将拒绝合并提交请求
|
||||||
|
- 2.代码必须使用 4 spaces 缩进格式化
|
||||||
|
|
||||||
|
## 代码注释规范
|
||||||
|
|
||||||
|
- 1.第一种注释方式:可使用在方法名或顶级变量名上
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
/** 注释内容 */
|
||||||
|
fun a() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注释名称
|
||||||
|
* @param test 方法名称
|
||||||
|
* @return 返回值名称
|
||||||
|
*/
|
||||||
|
fun a(test: String) {
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- 2.第二种注释方式:仅可使用在变量后方
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
val a = "" // 变量注释
|
||||||
|
```
|
||||||
|
|
||||||
|
- ⚠️注意:只允许两个 // 后方要有空格
|
||||||
|
|
||||||
|
## 项目要求
|
||||||
|
|
||||||
|
- 1.调试性质或大批量注释代码,禁止提交
|
||||||
|
- 2.类名和方法名仅能由开发者进行修改和提交,禁止随意修改项目名称、方法名称以及类名
|
||||||
|
- 3.禁止随意更新项目依赖以及增加新的依赖,有问题请提前提交到 issues 进行说明
|
||||||
|
- 4.禁止更新项目版本号,版本号交由开发者合并代码并发布 release 版本
|
||||||
|
- 5.代码语言要求,请统一使用 Kotlin,除特殊情况外,不接受其他语言的提交
|
||||||
|
- 6.以上
|
43
README.md
43
README.md
@@ -1,7 +1,44 @@
|
|||||||
# TSBattery
|
# TSBattery
|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|
<br/><br/>
|
||||||
|
<br/>
|
||||||
TSBattery a new way to save your battery avoid cancer apps hacker it.<br/>
|
TSBattery a new way to save your battery avoid cancer apps hacker it.<br/>
|
||||||
TSBattery 是一个旨在使 QQ、TIM 变得更省电的开源 Xposed 模块
|
TSBattery 是一个旨在使 QQ、TIM、微信 变得更省电的开源 Xposed 模块
|
||||||
# Get startted
|
|
||||||
此模块支持原生 Xposed、Lsposed(作用域 QQ、TIM 如果不起作用勾选系统框架)、EdXposed(不推荐)、太极无极(阴和阳)、Pine(梦境模块)
|
# 开始使用
|
||||||
|
|
||||||
|
点击下载最新版本
|
||||||
|
<a href='https://github.com/fankes/TSBattery/releases'></a>
|
||||||
|
<br/><br/>
|
||||||
|
⚠️适配说明:此模块支持原生 Xposed、Lsposed(作用域 QQ、TIM、微信 如果不起作用勾选系统框架)、EdXposed(不推荐)、太极无极(阴和阳)、Pine(梦境模块)
|
||||||
|
|
||||||
# 禁止任何商业用途
|
# 禁止任何商业用途
|
||||||
|
|
||||||
本模块完全开源免费,如果好用你可以打赏支持开发,严禁未经许可进行二改贩卖,违者必惩必究。
|
本模块完全开源免费,如果好用你可以打赏支持开发,严禁未经许可进行二改贩卖,违者必惩必究。
|
||||||
|
|
||||||
|
# 开始贡献
|
||||||
|
|
||||||
|
欢迎为此项目进行新版本的适配代码贡献!<br/>
|
||||||
|
|
||||||
|
- [CONTRIBUTING](https://github.com/fankes/TSBattery/blob/master/CONTRIBUTING.md)
|
||||||
|
|
||||||
|
# 许可证
|
||||||
|
|
||||||
|
- [GPL-3.0](https://www.gnu.org/licenses/gpl-3.0.html)
|
||||||
|
|
||||||
|
```
|
||||||
|
Copyright (C) 2020-2022 Fankes Studio(qzmmcn@163.com)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
```
|
@@ -6,7 +6,7 @@ plugins {
|
|||||||
android {
|
android {
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
debug {
|
debug {
|
||||||
storeFile file('/Users/fankes/ProjectPath/AndroidStudioProjects/TSBattery/keystore/public')
|
storeFile file('../keystore/public')
|
||||||
storePassword '123456'
|
storePassword '123456'
|
||||||
keyAlias 'public'
|
keyAlias 'public'
|
||||||
keyPassword '123456'
|
keyPassword '123456'
|
||||||
@@ -14,16 +14,16 @@ android {
|
|||||||
v2SigningEnabled true
|
v2SigningEnabled true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
compileSdkVersion 30
|
compileSdkVersion 31
|
||||||
buildToolsVersion "30.0.3"
|
buildToolsVersion "31.0.0"
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.fankes.tsbattery"
|
applicationId "com.fankes.tsbattery"
|
||||||
minSdkVersion 22
|
minSdkVersion 22
|
||||||
//noinspection ExpiredTargetSdkVersion,OldTargetApi
|
//noinspection ExpiredTargetSdkVersion
|
||||||
targetSdkVersion 26
|
targetSdkVersion 26
|
||||||
versionCode 5
|
versionCode 10
|
||||||
versionName "2.2"
|
versionName "3.1"
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
@@ -46,25 +46,18 @@ android {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly 'de.robv.android.xposed:api:82'
|
compileOnly 'de.robv.android.xposed:api:82'
|
||||||
// 基础依赖包,必须要依赖
|
// 基础依赖包
|
||||||
implementation 'com.gyf.immersionbar:immersionbar:3.0.0'
|
implementation 'com.gyf.immersionbar:immersionbar:3.0.0'
|
||||||
// fragment快速实现(可选)
|
// Fragment 快速实现
|
||||||
implementation 'com.gyf.immersionbar:immersionbar-components:3.0.0'
|
implementation 'com.gyf.immersionbar:immersionbar-components:3.0.0'
|
||||||
// kotlin扩展(可选)
|
// Kotlin 扩展
|
||||||
implementation 'com.gyf.immersionbar:immersionbar-ktx:3.0.0'
|
implementation 'com.gyf.immersionbar:immersionbar-ktx:3.0.0'
|
||||||
//noinspection GradleDependency,DifferentStdlibGradleVersion
|
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
//noinspection GradleDependency
|
implementation 'androidx.core:core-ktx:1.7.0'
|
||||||
implementation 'androidx.core:core-ktx:1.5.0'
|
implementation 'androidx.appcompat:appcompat:1.4.1'
|
||||||
//noinspection GradleDependency
|
implementation 'com.google.android.material:material:1.5.0'
|
||||||
implementation 'androidx.appcompat:appcompat:1.3.0'
|
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
|
||||||
//noinspection GradleDependency
|
|
||||||
implementation 'com.google.android.material:material:1.3.0'
|
|
||||||
//noinspection GradleDependency
|
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
|
|
||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
//noinspection GradleDependency
|
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
||||||
//noinspection GradleDependency
|
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
|
|
||||||
}
|
}
|
Binary file not shown.
@@ -1,18 +1,20 @@
|
|||||||
{
|
{
|
||||||
"version": 2,
|
"version": 3,
|
||||||
"artifactType": {
|
"artifactType": {
|
||||||
"type": "APK",
|
"type": "APK",
|
||||||
"kind": "Directory"
|
"kind": "Directory"
|
||||||
},
|
},
|
||||||
"applicationId": "com.fankes.tsbattery",
|
"applicationId": "com.fankes.tsbattery",
|
||||||
"variantName": "processReleaseResources",
|
"variantName": "release",
|
||||||
"elements": [
|
"elements": [
|
||||||
{
|
{
|
||||||
"type": "SINGLE",
|
"type": "SINGLE",
|
||||||
"filters": [],
|
"filters": [],
|
||||||
"versionCode": 5,
|
"attributes": [],
|
||||||
"versionName": "2.2",
|
"versionCode": 10,
|
||||||
|
"versionName": "3.1",
|
||||||
"outputFile": "app-release.apk"
|
"outputFile": "app-release.apk"
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"elementType": "File"
|
||||||
}
|
}
|
@@ -4,6 +4,7 @@
|
|||||||
package="com.fankes.tsbattery">
|
package="com.fankes.tsbattery">
|
||||||
|
|
||||||
<application
|
<application
|
||||||
|
android:name=".application.TSApplication"
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
@@ -20,7 +21,7 @@
|
|||||||
<!-- 模块描述 -->
|
<!-- 模块描述 -->
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="xposeddescription"
|
android:name="xposeddescription"
|
||||||
android:value="抵制毒瘤,拒绝疯狂耗电,Tencent 社交毒瘤一键省电模块(目前支持 QQ、TIM),通过干掉电源锁常驻减少电量消耗,理论支持最新版本。by 酷安 @星夜不荟" />
|
android:value="Tencent 社交毒瘤一键省电模块。\n目前支持 QQ、TIM、微信\n开发者:酷安 @星夜不荟" />
|
||||||
|
|
||||||
<!-- 最低xposed版本号 -->
|
<!-- 最低xposed版本号 -->
|
||||||
<meta-data
|
<meta-data
|
||||||
@@ -28,8 +29,11 @@
|
|||||||
android:value="82" />
|
android:value="82" />
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name="com.fankes.tsbattery.MainActivity"
|
android:name="com.fankes.tsbattery.ui.MainActivity"
|
||||||
android:label="@string/app_name">
|
android:exported="true"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:screenOrientation="behind">
|
||||||
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="de.robv.android.xposed.category.MODULE_SETTINGS" />
|
<category android:name="de.robv.android.xposed.category.MODULE_SETTINGS" />
|
||||||
@@ -39,8 +43,11 @@
|
|||||||
<activity-alias
|
<activity-alias
|
||||||
android:name="com.fankes.tsbattery.Home"
|
android:name="com.fankes.tsbattery.Home"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
|
android:exported="true"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:targetActivity="com.fankes.tsbattery.MainActivity">
|
android:screenOrientation="behind"
|
||||||
|
android:targetActivity="com.fankes.tsbattery.ui.MainActivity">
|
||||||
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
@@ -1,234 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
|
||||||
*
|
|
||||||
* This file is part of TSBattery.
|
|
||||||
*
|
|
||||||
* TSBattery is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* TSBattery is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* This file is Created by fankes on 2021/9/4.
|
|
||||||
*/
|
|
||||||
@file:Suppress(
|
|
||||||
"DEPRECATION", "SetTextI18n", "SetWorldReadable", "WorldReadableFiles",
|
|
||||||
"LocalVariableName"
|
|
||||||
)
|
|
||||||
|
|
||||||
package com.fankes.tsbattery
|
|
||||||
|
|
||||||
import android.content.ComponentName
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
|
||||||
import android.content.pm.PackageManager
|
|
||||||
import android.net.Uri
|
|
||||||
import android.os.Bundle
|
|
||||||
import android.os.Handler
|
|
||||||
import android.util.Log
|
|
||||||
import android.view.View
|
|
||||||
import android.widget.LinearLayout
|
|
||||||
import android.widget.TextView
|
|
||||||
import android.widget.Toast
|
|
||||||
import androidx.annotation.Keep
|
|
||||||
import androidx.appcompat.app.AlertDialog
|
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
|
||||||
import androidx.appcompat.widget.SwitchCompat
|
|
||||||
import androidx.constraintlayout.utils.widget.ImageFilterView
|
|
||||||
import com.fankes.tsbattery.hook.HookMain
|
|
||||||
import com.fankes.tsbattery.utils.FileUtils
|
|
||||||
import com.gyf.immersionbar.ImmersionBar
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
@Keep
|
|
||||||
class MainActivity : AppCompatActivity() {
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
|
|
||||||
private const val moduleVersion = BuildConfig.VERSION_NAME
|
|
||||||
private const val moduleSupport = "QQ 8.5.5~8.8.23、TIM 2+"
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
|
||||||
super.onCreate(savedInstanceState)
|
|
||||||
setContentView(R.layout.activity_main)
|
|
||||||
/*禁止系统夜间模式对自己造成干扰*/
|
|
||||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
|
||||||
/*隐藏系统的标题栏*/
|
|
||||||
supportActionBar?.hide()
|
|
||||||
/*初始化沉浸状态栏*/
|
|
||||||
ImmersionBar.with(this)
|
|
||||||
.statusBarColor("#FFFFFFFF")
|
|
||||||
.autoDarkModeEnable(false)
|
|
||||||
.statusBarDarkFont(true)
|
|
||||||
.navigationBarColor("#FFFFFFFF")
|
|
||||||
.navigationBarDarkIcon(true)
|
|
||||||
.fitsSystemWindows(true)
|
|
||||||
.init()
|
|
||||||
/*判断 Hook 状态*/
|
|
||||||
if (isHooked()) {
|
|
||||||
findViewById<LinearLayout>(R.id.main_lin_status).setBackgroundResource(R.drawable.green_round)
|
|
||||||
findViewById<ImageFilterView>(R.id.main_img_status).setImageResource(R.mipmap.succcess)
|
|
||||||
findViewById<TextView>(R.id.main_text_status).text = "模块已激活"
|
|
||||||
} else
|
|
||||||
AlertDialog.Builder(this)
|
|
||||||
.setTitle("模块没有激活")
|
|
||||||
.setMessage(
|
|
||||||
"检测到模块没有激活,模块需要 Xposed 环境依赖,同时需要系统拥有 Root 权限(太极阴可以免 Root),请自行查看本页面使用帮助与说明第三条。\n" +
|
|
||||||
"太极、应用转生、梦境(Pine)和第三方 Xposed 激活后可能不会提示激活,若想验证是否激活请打开“提示模块运行信息”自行检查,如果生效就代表模块运行正常,这里的激活状态只是一个显示意义上的存在。"
|
|
||||||
)
|
|
||||||
.setPositiveButton("我知道了", null)
|
|
||||||
.setCancelable(false)
|
|
||||||
.show()
|
|
||||||
/*设置文本*/
|
|
||||||
findViewById<TextView>(R.id.main_text_version).text = "当前版本:$moduleVersion"
|
|
||||||
findViewById<TextView>(R.id.main_text_support).text = "支持 $moduleSupport"
|
|
||||||
/*初始化 View*/
|
|
||||||
val protectModeSwitch = findViewById<SwitchCompat>(R.id.protect_mode_switch)
|
|
||||||
val hideIconInLauncherSwitch = findViewById<SwitchCompat>(R.id.hide_icon_in_launcher_switch)
|
|
||||||
val notifyModuleInfoSwitch = findViewById<SwitchCompat>(R.id.notify_module_info_switch)
|
|
||||||
/*获取 Sp 存储的信息*/
|
|
||||||
protectModeSwitch.isChecked = getBoolean("_white_mode")
|
|
||||||
hideIconInLauncherSwitch.isChecked = getBoolean("_hide_icon")
|
|
||||||
notifyModuleInfoSwitch.isChecked = getBoolean("_tip_run_info")
|
|
||||||
protectModeSwitch.setOnCheckedChangeListener { btn, b ->
|
|
||||||
if (!btn.isPressed) return@setOnCheckedChangeListener
|
|
||||||
putBoolean("_white_mode", b)
|
|
||||||
}
|
|
||||||
hideIconInLauncherSwitch.setOnCheckedChangeListener { btn, b ->
|
|
||||||
if (!btn.isPressed) return@setOnCheckedChangeListener
|
|
||||||
putBoolean("_hide_icon", b)
|
|
||||||
packageManager.setComponentEnabledSetting(
|
|
||||||
ComponentName(this@MainActivity, "com.fankes.tsbattery.Home"),
|
|
||||||
if (b) PackageManager.COMPONENT_ENABLED_STATE_DISABLED else PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
|
|
||||||
PackageManager.DONT_KILL_APP
|
|
||||||
)
|
|
||||||
}
|
|
||||||
notifyModuleInfoSwitch.setOnCheckedChangeListener { btn, b ->
|
|
||||||
if (!btn.isPressed) return@setOnCheckedChangeListener
|
|
||||||
putBoolean("_tip_run_info", b)
|
|
||||||
}
|
|
||||||
/*项目地址点击事件*/
|
|
||||||
findViewById<View>(R.id.link_with_project_address).setOnClickListener {
|
|
||||||
try {
|
|
||||||
val intent = Intent()
|
|
||||||
intent.action = "android.intent.action.VIEW"
|
|
||||||
val content_url = Uri.parse("https://github.com/fankes/TSBattery")
|
|
||||||
intent.data = content_url
|
|
||||||
startActivity(intent)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Toast.makeText(this, "无法启动系统默认浏览器", Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断模块是否激活
|
|
||||||
* 在 [HookMain] 中 Hook 掉此方法
|
|
||||||
* @return 激活状态
|
|
||||||
*/
|
|
||||||
private fun isHooked(): Boolean {
|
|
||||||
Log.d("TSBattery", "isHooked: true")
|
|
||||||
return isExpModuleActive()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增太极判断方式
|
|
||||||
* @return 是否激活
|
|
||||||
*/
|
|
||||||
private fun isExpModuleActive(): Boolean {
|
|
||||||
var isExp = false
|
|
||||||
try {
|
|
||||||
val uri = Uri.parse("content://me.weishu.exposed.CP/")
|
|
||||||
var result: Bundle? = null
|
|
||||||
try {
|
|
||||||
result = contentResolver.call(uri, "active", null, null)
|
|
||||||
} catch (e: RuntimeException) {
|
|
||||||
// TaiChi is killed, try invoke
|
|
||||||
try {
|
|
||||||
val intent = Intent("me.weishu.exp.ACTION_ACTIVE")
|
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
||||||
startActivity(intent)
|
|
||||||
} catch (e1: Throwable) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (result == null) result = contentResolver.call(uri, "active", null, null)
|
|
||||||
if (result == null) return false
|
|
||||||
isExp = result.getBoolean("active", false)
|
|
||||||
} catch (ignored: Throwable) {
|
|
||||||
}
|
|
||||||
return isExp
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onResume() {
|
|
||||||
super.onResume()
|
|
||||||
setWorldReadable()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onRestart() {
|
|
||||||
super.onRestart()
|
|
||||||
setWorldReadable()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onPause() {
|
|
||||||
super.onPause()
|
|
||||||
setWorldReadable()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取保存的值
|
|
||||||
* @param key 名称
|
|
||||||
* @return 保存的值
|
|
||||||
*/
|
|
||||||
private fun getBoolean(key: String) =
|
|
||||||
getSharedPreferences(
|
|
||||||
packageName + "_preferences",
|
|
||||||
Context.MODE_PRIVATE
|
|
||||||
).getBoolean(key, false)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 保存值
|
|
||||||
* @param key 名称
|
|
||||||
* @param bool 值
|
|
||||||
*/
|
|
||||||
private fun putBoolean(key: String, bool: Boolean) {
|
|
||||||
getSharedPreferences(
|
|
||||||
packageName + "_preferences",
|
|
||||||
Context.MODE_PRIVATE
|
|
||||||
).edit().putBoolean(key, bool).apply()
|
|
||||||
setWorldReadable()
|
|
||||||
Handler().postDelayed({ setWorldReadable() }, 500)
|
|
||||||
Handler().postDelayed({ setWorldReadable() }, 1000)
|
|
||||||
Handler().postDelayed({ setWorldReadable() }, 1500)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 强制设置 Sp 存储为全局可读可写
|
|
||||||
* 以供模块使用
|
|
||||||
*/
|
|
||||||
private fun setWorldReadable() {
|
|
||||||
try {
|
|
||||||
if (FileUtils.getDefaultPrefFile(this).exists()) {
|
|
||||||
for (file in arrayOf<File>(
|
|
||||||
FileUtils.getDataDir(this),
|
|
||||||
FileUtils.getPrefDir(this),
|
|
||||||
FileUtils.getDefaultPrefFile(this)
|
|
||||||
)) {
|
|
||||||
file.setReadable(true, false)
|
|
||||||
file.setExecutable(true, false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Toast.makeText(this, "无法写入模块设置,请检查权限\n如果此提示一直显示,请不要双开模块", Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
||||||
|
*
|
||||||
|
* This file is part of TSBattery.
|
||||||
|
*
|
||||||
|
* TSBattery is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* TSBattery is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This file is Created by fankes on 2021/11/9.
|
||||||
|
*/
|
||||||
|
@file:Suppress("unused")
|
||||||
|
|
||||||
|
package com.fankes.tsbattery.application
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
|
|
||||||
|
class TSApplication : Application() {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
/** 全局静态实例 */
|
||||||
|
private var context: TSApplication? = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调用全局静态实例
|
||||||
|
* @return [TSApplication]
|
||||||
|
*/
|
||||||
|
val appContext get() = context ?: error("App is death")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreate() {
|
||||||
|
super.onCreate()
|
||||||
|
/** 设置静态实例 */
|
||||||
|
context = this
|
||||||
|
/** 禁止系统夜间模式对自己造成干扰 - 模块要什么夜间模式?😅 (其实是我懒) */
|
||||||
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
||||||
|
}
|
||||||
|
}
|
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/**
|
||||||
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
||||||
*
|
*
|
||||||
* This file is part of TSBattery.
|
* This file is part of TSBattery.
|
||||||
@@ -23,12 +23,20 @@
|
|||||||
package com.fankes.tsbattery.hook
|
package com.fankes.tsbattery.hook
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.app.AlertDialog
|
import android.app.Service
|
||||||
|
import android.content.Intent
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.annotation.Keep
|
import androidx.annotation.Keep
|
||||||
|
import com.fankes.tsbattery.hook.HookMedium.QQ_PACKAGE_NAME
|
||||||
|
import com.fankes.tsbattery.hook.HookMedium.SELF_PACKAGE_NAME
|
||||||
|
import com.fankes.tsbattery.hook.HookMedium.TIM_PACKAGE_NAME
|
||||||
|
import com.fankes.tsbattery.hook.HookMedium.WECHAT_PACKAGE_NAME
|
||||||
import com.fankes.tsbattery.utils.XPrefUtils
|
import com.fankes.tsbattery.utils.XPrefUtils
|
||||||
|
import com.fankes.tsbattery.utils.showDialog
|
||||||
|
import com.fankes.tsbattery.utils.versionCode
|
||||||
|
import com.fankes.tsbattery.utils.versionName
|
||||||
import de.robv.android.xposed.*
|
import de.robv.android.xposed.*
|
||||||
import de.robv.android.xposed.callbacks.XC_LoadPackage
|
import de.robv.android.xposed.callbacks.XC_LoadPackage
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@@ -36,12 +44,108 @@ import java.util.*
|
|||||||
@Keep
|
@Keep
|
||||||
class HookMain : IXposedHookLoadPackage {
|
class HookMain : IXposedHookLoadPackage {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
/** 旧版类名 */
|
||||||
|
private const val BASE_CHAT_PIE_LEGACY = "activity.BaseChatPie"
|
||||||
|
|
||||||
|
/** 新版类名 */
|
||||||
|
private const val BASE_CHAT_PIE = "activity.aio.core.BaseChatPie"
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 仅作用于替换的 Hook 方法体 */
|
||||||
|
private val replaceToNull = object : XC_MethodReplacement() {
|
||||||
|
override fun replaceHookedMethod(param: MethodHookParam?): Any? {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 仅作用于替换的 Hook 方法体 */
|
||||||
|
private val replaceToTrue = object : XC_MethodReplacement() {
|
||||||
|
override fun replaceHookedMethod(param: MethodHookParam?): Any {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 干掉目标方法体封装
|
||||||
|
* @param clazz 类名缩写
|
||||||
|
* @param name 方法名
|
||||||
|
*/
|
||||||
|
private fun XC_LoadPackage.LoadPackageParam.replaceToNull(clazz: String, name: String) {
|
||||||
|
XposedHelpers.findAndHookMethod(
|
||||||
|
"$QQ_PACKAGE_NAME.$clazz",
|
||||||
|
classLoader,
|
||||||
|
name,
|
||||||
|
replaceToNull
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 忽略异常运行
|
||||||
|
* @param it 正常回调
|
||||||
|
*/
|
||||||
|
private fun runWithoutError(error: String, it: () -> Unit) {
|
||||||
|
try {
|
||||||
|
it()
|
||||||
|
} catch (e: Error) {
|
||||||
|
logE("hookFailed: $error", e)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
logE("hookFailed: $error", e)
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
logE("hookFailed: $error", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 这个类 QQ 的 BaseChatPie 是控制聊天界面的
|
||||||
|
* 里面有两个随机混淆的方法 ⬇️
|
||||||
|
* remainScreenOn、cancelRemainScreenOn
|
||||||
|
* 这两个方法一个是挂起电源锁常驻亮屏
|
||||||
|
* 一个是停止常驻亮屏
|
||||||
|
* 不由分说每个版本混淆的方法名都会变
|
||||||
|
* 所以说每个版本重新适配 - 也可以提交分支帮我适配
|
||||||
|
* ⚠️ Hook 错了方法会造成闪退!
|
||||||
|
* @param version QQ 版本
|
||||||
|
*/
|
||||||
|
private fun XC_LoadPackage.LoadPackageParam.hookQQBaseChatPie(version: String) {
|
||||||
|
when (version) {
|
||||||
|
"8.2.11" -> {
|
||||||
|
replaceToNull(BASE_CHAT_PIE_LEGACY, "bE")
|
||||||
|
replaceToNull(BASE_CHAT_PIE_LEGACY, "aV")
|
||||||
|
}
|
||||||
|
"8.8.17" -> {
|
||||||
|
replaceToNull(BASE_CHAT_PIE, "bd")
|
||||||
|
replaceToNull(BASE_CHAT_PIE, "be")
|
||||||
|
}
|
||||||
|
"8.8.23" -> {
|
||||||
|
replaceToNull(BASE_CHAT_PIE, "bf")
|
||||||
|
replaceToNull(BASE_CHAT_PIE, "bg")
|
||||||
|
}
|
||||||
|
/** 8.8.35 贡献者:StarWishsama */
|
||||||
|
"8.8.35", "8.8.38" -> {
|
||||||
|
replaceToNull(BASE_CHAT_PIE, "bi")
|
||||||
|
replaceToNull(BASE_CHAT_PIE, "bj")
|
||||||
|
}
|
||||||
|
/** 贡献者:JiZhi-Error */
|
||||||
|
"8.8.50" -> {
|
||||||
|
replaceToNull(BASE_CHAT_PIE, "bj")
|
||||||
|
replaceToNull(BASE_CHAT_PIE, "bk")
|
||||||
|
}
|
||||||
|
"8.8.55", "8.8.68" -> {
|
||||||
|
replaceToNull(BASE_CHAT_PIE, "bk")
|
||||||
|
replaceToNull(BASE_CHAT_PIE, "bl")
|
||||||
|
}
|
||||||
|
else -> logD("$version not supported!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print the log
|
* Print the log
|
||||||
* @param content
|
* @param content
|
||||||
*/
|
*/
|
||||||
private fun logD(content: String) {
|
private fun logD(content: String) {
|
||||||
XposedBridge.log(content)
|
XposedBridge.log("[TSBattery][D]>$content")
|
||||||
Log.d("TSBattery", content)
|
Log.d("TSBattery", content)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,175 +154,252 @@ class HookMain : IXposedHookLoadPackage {
|
|||||||
* @param content
|
* @param content
|
||||||
*/
|
*/
|
||||||
private fun logE(content: String, e: Throwable? = null) {
|
private fun logE(content: String, e: Throwable? = null) {
|
||||||
XposedBridge.log(content)
|
XposedBridge.log("[TSBattery][E]>$content")
|
||||||
|
XposedBridge.log(e)
|
||||||
Log.e("TSBattery", content, e)
|
Log.e("TSBattery", content, e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Hook 系统电源锁 */
|
||||||
|
private fun XC_LoadPackage.LoadPackageParam.hookSystemWakeLock() {
|
||||||
|
runWithoutError("wakeLock acquire()") {
|
||||||
|
XposedHelpers.findAndHookMethod(
|
||||||
|
"android.os.PowerManager\$WakeLock",
|
||||||
|
classLoader,
|
||||||
|
"acquire",
|
||||||
|
replaceToNull
|
||||||
|
)
|
||||||
|
}
|
||||||
|
runWithoutError("hook wakeLock acquire(time)") {
|
||||||
|
XposedHelpers.findAndHookMethod(
|
||||||
|
"android.os.PowerManager\$WakeLock",
|
||||||
|
classLoader,
|
||||||
|
"acquire",
|
||||||
|
Long::class.java,
|
||||||
|
replaceToNull
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 增加通知栏文本显示守护状态 */
|
||||||
|
private fun XC_LoadPackage.LoadPackageParam.hookNotification() =
|
||||||
|
runWithoutError("Notification") {
|
||||||
|
XposedHelpers.findAndHookMethod(
|
||||||
|
"android.app.Notification\$Builder",
|
||||||
|
classLoader,
|
||||||
|
"setContentText",
|
||||||
|
CharSequence::class.java,
|
||||||
|
object : XC_MethodHook() {
|
||||||
|
override fun beforeHookedMethod(param: MethodHookParam?) {
|
||||||
|
when (param?.args?.get(0) as? CharSequence?) {
|
||||||
|
"QQ正在后台运行" ->
|
||||||
|
param.args?.set(0, "QQ正在后台运行 - TSBattery 守护中")
|
||||||
|
"TIM正在后台运行" ->
|
||||||
|
param.args?.set(0, "TIM正在后台运行 - TSBattery 守护中")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 提示模块运行信息 QQ、TIM、微信 */
|
||||||
|
private fun XC_LoadPackage.LoadPackageParam.hookModuleRunningInfo() =
|
||||||
|
if (packageName != WECHAT_PACKAGE_NAME)
|
||||||
|
runWithoutError("SplashActivity") {
|
||||||
|
/** 判断是否开启提示模块运行信息 */
|
||||||
|
if (XPrefUtils.getBoolean(HookMedium.ENABLE_RUN_INFO))
|
||||||
|
XposedHelpers.findAndHookMethod(
|
||||||
|
"$QQ_PACKAGE_NAME.activity.SplashActivity",
|
||||||
|
classLoader,
|
||||||
|
"doOnCreate",
|
||||||
|
Bundle::class.java,
|
||||||
|
object : XC_MethodHook() {
|
||||||
|
|
||||||
|
override fun afterHookedMethod(param: MethodHookParam?) {
|
||||||
|
/**
|
||||||
|
* Hook 启动界面的第一个 [Activity]
|
||||||
|
* QQ 和 TIM 都是一样的类
|
||||||
|
* 在里面加入提示运行信息的对话框测试模块是否激活
|
||||||
|
*/
|
||||||
|
(param?.thisObject as? Activity?)?.apply {
|
||||||
|
showDialog {
|
||||||
|
title = "TSBattery 已激活"
|
||||||
|
msg = "[提示模块运行信息功能已打开]\n\n" +
|
||||||
|
"模块工作看起来一切正常,请自行测试是否能达到省电效果。\n\n" +
|
||||||
|
"已生效模块版本:${XPrefUtils.getString(HookMedium.ENABLE_MODULE_VERSION)}\n" +
|
||||||
|
"当前模式:${if (XPrefUtils.getBoolean(HookMedium.ENABLE_QQTIM_WHITE_MODE)) "保守模式" else "完全模式"}" +
|
||||||
|
"\n\n包名:${packageName}\n版本:$versionName($versionCode)" +
|
||||||
|
"\n\n模块只对挂后台锁屏情况下有省电效果,请不要将过多的群提醒,消息通知打开,这样子在使用过程时照样会极其耗电。\n\n" +
|
||||||
|
"如果你不想看到此提示。请在模块设置中关闭“提示模块运行信息”,此设置默认关闭。\n\n" +
|
||||||
|
"持续常驻使用 QQ 依然会耗电,任何软件都是如此,模块无法帮你做到前台不耗电,永远记住这一点。\n\n" +
|
||||||
|
"开发者 酷安 @星夜不荟\n未经允许禁止转载、修改或复制我的劳动成果。"
|
||||||
|
confirmButton(text = "我知道了")
|
||||||
|
noCancelable()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else
|
||||||
|
runWithoutError("LauncherUI") {
|
||||||
|
/** 判断是否开启提示模块运行信息 */
|
||||||
|
if (XPrefUtils.getBoolean(HookMedium.ENABLE_RUN_INFO))
|
||||||
|
XposedHelpers.findAndHookMethod(
|
||||||
|
"$WECHAT_PACKAGE_NAME.ui.LauncherUI",
|
||||||
|
classLoader,
|
||||||
|
"onCreate",
|
||||||
|
Bundle::class.java,
|
||||||
|
object : XC_MethodHook() {
|
||||||
|
|
||||||
|
override fun afterHookedMethod(param: MethodHookParam?) {
|
||||||
|
/**
|
||||||
|
* Hook 启动界面的第一个 [Activity]
|
||||||
|
* 在里面加入提示运行信息的对话框测试模块是否激活
|
||||||
|
*/
|
||||||
|
(param?.thisObject as? Activity?)?.apply {
|
||||||
|
showDialog(isUseBlackTheme = true) {
|
||||||
|
title = "TSBattery 已激活"
|
||||||
|
msg = "[提示模块运行信息功能已打开]\n\n" +
|
||||||
|
"模块工作看起来一切正常,请自行测试是否能达到省电效果。\n\n" +
|
||||||
|
"已生效模块版本:${XPrefUtils.getString(HookMedium.ENABLE_MODULE_VERSION)}\n" +
|
||||||
|
"当前模式:基础省电" +
|
||||||
|
"\n\n包名:${packageName}\n版本:$versionName($versionCode)" +
|
||||||
|
"\n\n当前只支持微信的基础省电,即系统电源锁,后续会继续适配微信相关的省电功能(在新建文件夹了)。\n\n" +
|
||||||
|
"如果你不想看到此提示。请在模块设置中关闭“提示模块运行信息”,此设置默认关闭。\n\n" +
|
||||||
|
"持续常驻使用微信依然会耗电,任何软件都是如此,模块无法帮你做到前台不耗电,永远记住这一点。\n\n" +
|
||||||
|
"开发者 酷安 @星夜不荟\n未经允许禁止转载、修改或复制我的劳动成果。"
|
||||||
|
confirmButton(text = "我知道了")
|
||||||
|
noCancelable()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Hook CoreService QQ、TIM */
|
||||||
|
private fun XC_LoadPackage.LoadPackageParam.hookCoreService() {
|
||||||
|
/** Hook CoreService 指定方法 */
|
||||||
|
if (packageName == QQ_PACKAGE_NAME)
|
||||||
|
runWithoutError("CoreServiceKnownMethods") {
|
||||||
|
if (XPrefUtils.getBoolean(HookMedium.ENABLE_QQTIM_CORESERVICE_BAN)) {
|
||||||
|
XposedHelpers.findAndHookMethod(
|
||||||
|
"$QQ_PACKAGE_NAME.app.CoreService",
|
||||||
|
classLoader, "startTempService", replaceToNull
|
||||||
|
)
|
||||||
|
XposedHelpers.findAndHookMethod(
|
||||||
|
"$QQ_PACKAGE_NAME.app.CoreService",
|
||||||
|
classLoader, "startCoreService", Boolean::class.java, replaceToNull
|
||||||
|
)
|
||||||
|
XposedHelpers.findAndHookMethod(
|
||||||
|
"$QQ_PACKAGE_NAME.app.CoreService",
|
||||||
|
classLoader,
|
||||||
|
"onStartCommand",
|
||||||
|
Intent::class.java, Int::class.java, Int::class.java,
|
||||||
|
object : XC_MethodReplacement() {
|
||||||
|
|
||||||
|
override fun replaceHookedMethod(param: MethodHookParam?) = 2
|
||||||
|
})
|
||||||
|
logD("hook CoreService OK!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/** Hook CoreService 启动方法 */
|
||||||
|
runWithoutError("CoreService") {
|
||||||
|
if (XPrefUtils.getBoolean(HookMedium.ENABLE_QQTIM_CORESERVICE_BAN)) {
|
||||||
|
XposedHelpers.findAndHookMethod(
|
||||||
|
"$QQ_PACKAGE_NAME.app.CoreService",
|
||||||
|
classLoader, "onCreate",
|
||||||
|
object : XC_MethodHook() {
|
||||||
|
|
||||||
|
override fun afterHookedMethod(param: MethodHookParam?) {
|
||||||
|
(param?.thisObject as? Service)?.apply {
|
||||||
|
runWithoutError("StopCoreService") {
|
||||||
|
stopForeground(true)
|
||||||
|
stopService(Intent(applicationContext, javaClass))
|
||||||
|
logD("Shutdown CoreService OK!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
logD("hook CoreService [onCreate] OK!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/** Hook CoreService$KernelService 启动方法 */
|
||||||
|
runWithoutError("CoreService\$KernelService") {
|
||||||
|
if (XPrefUtils.getBoolean(HookMedium.ENABLE_QQTIM_CORESERVICE_CHILD_BAN)) {
|
||||||
|
XposedHelpers.findAndHookMethod(
|
||||||
|
"$QQ_PACKAGE_NAME.app.CoreService\$KernelService",
|
||||||
|
classLoader, "onCreate",
|
||||||
|
object : XC_MethodHook() {
|
||||||
|
|
||||||
|
override fun afterHookedMethod(param: MethodHookParam?) {
|
||||||
|
(param?.thisObject as? Service)?.apply {
|
||||||
|
runWithoutError("StopKernelService") {
|
||||||
|
stopForeground(true)
|
||||||
|
stopService(Intent(applicationContext, javaClass))
|
||||||
|
logD("Shutdown CoreService\$KernelService OK!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
XposedHelpers.findAndHookMethod(
|
||||||
|
"$QQ_PACKAGE_NAME.app.CoreService\$KernelService",
|
||||||
|
classLoader,
|
||||||
|
"onStartCommand",
|
||||||
|
Intent::class.java, Int::class.java, Int::class.java,
|
||||||
|
object : XC_MethodReplacement() {
|
||||||
|
|
||||||
|
override fun replaceHookedMethod(param: MethodHookParam?) = 2
|
||||||
|
})
|
||||||
|
logD("hook CoreService\$KernelService [onCreate] OK!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam?) {
|
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam?) {
|
||||||
if (lpparam == null) return
|
if (lpparam == null) return
|
||||||
when (lpparam.packageName) {
|
when (lpparam.packageName) {
|
||||||
/*Hook 自身*/
|
/** Hook 自身 */
|
||||||
"com.fankes.tsbattery" ->
|
SELF_PACKAGE_NAME ->
|
||||||
XposedHelpers.findAndHookMethod(
|
XposedHelpers.findAndHookMethod(
|
||||||
"com.fankes.tsbattery.MainActivity",
|
"$SELF_PACKAGE_NAME.hook.HookMedium",
|
||||||
lpparam.classLoader,
|
lpparam.classLoader,
|
||||||
"isHooked",
|
"isHooked",
|
||||||
object : XC_MethodReplacement() {
|
replaceToTrue
|
||||||
override fun replaceHookedMethod(param: MethodHookParam?): Any {
|
)
|
||||||
return true
|
/** Hook TIM */
|
||||||
}
|
TIM_PACKAGE_NAME ->
|
||||||
})
|
lpparam.apply {
|
||||||
/*经过测试 QQ 与 TIM 这两个是一个模子里面的东西,所以他们的类名也基本上是一样的*/
|
hookSystemWakeLock()
|
||||||
"com.tencent.mobileqq", "com.tencent.tim" -> {
|
hookNotification()
|
||||||
try {
|
hookModuleRunningInfo()
|
||||||
XposedHelpers.findAndHookMethod(
|
hookCoreService()
|
||||||
"android.os.PowerManager\$WakeLock",
|
logD("hook Completed!")
|
||||||
lpparam.classLoader,
|
|
||||||
"acquire",
|
|
||||||
object : XC_MethodReplacement() {
|
|
||||||
override fun replaceHookedMethod(param: MethodHookParam?): Any? {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} catch (e: Throwable) {
|
|
||||||
logE("handleLoadPackage: hook wakeLock acquire() Failed", e)
|
|
||||||
}
|
}
|
||||||
try {
|
/** Hook QQ */
|
||||||
XposedHelpers.findAndHookMethod(
|
QQ_PACKAGE_NAME -> {
|
||||||
"android.os.PowerManager\$WakeLock",
|
lpparam.apply {
|
||||||
lpparam.classLoader,
|
hookSystemWakeLock()
|
||||||
"acquire",
|
hookNotification()
|
||||||
Long::class.java,
|
hookModuleRunningInfo()
|
||||||
object : XC_MethodReplacement() {
|
hookCoreService()
|
||||||
override fun replaceHookedMethod(param: MethodHookParam?): Any? {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} catch (e: Throwable) {
|
|
||||||
logE("handleLoadPackage: hook wakeLock acquire(time) Failed", e)
|
|
||||||
}
|
}
|
||||||
/*判断是否开启提示模块运行信息*/
|
/** 关闭保守模式后不再仅仅作用于系统电源锁 */
|
||||||
if (XPrefUtils.getBoolean("_tip_run_info"))
|
if (!XPrefUtils.getBoolean(HookMedium.ENABLE_QQTIM_WHITE_MODE)) {
|
||||||
try {
|
runWithoutError("BaseChatPie(first time)") {
|
||||||
/**
|
/** 通过在 SplashActivity 里取到应用的版本号 */
|
||||||
* Hook 启动界面的第一个 [Activity]
|
|
||||||
* QQ 和 TIM 都是一样的类
|
|
||||||
* 在里面加入提示运行信息的对话框测试模块是否激活
|
|
||||||
*/
|
|
||||||
XposedHelpers.findAndHookMethod(
|
XposedHelpers.findAndHookMethod(
|
||||||
"com.tencent.mobileqq.activity.SplashActivity",
|
"$QQ_PACKAGE_NAME.activity.SplashActivity",
|
||||||
lpparam.classLoader,
|
|
||||||
"doOnCreate",
|
|
||||||
Bundle::class.java,
|
|
||||||
object : XC_MethodHook() {
|
|
||||||
|
|
||||||
override fun afterHookedMethod(param: MethodHookParam?) {
|
|
||||||
val self = param!!.thisObject as Activity
|
|
||||||
AlertDialog.Builder(
|
|
||||||
self,
|
|
||||||
android.R.style.Theme_Material_Dialog_Alert
|
|
||||||
).setCancelable(false)
|
|
||||||
.setTitle("TSBattery 已激活")
|
|
||||||
.setMessage(
|
|
||||||
"模块工作看起来一切正常,请自行测试是否能达到省电效果。\n\n" +
|
|
||||||
"当前模式:${if (XPrefUtils.getBoolean("_white_mode")) "保守模式" else "完全模式"}" +
|
|
||||||
"\n\n包名:${self.packageName}\n版本:${
|
|
||||||
self.packageManager.getPackageInfo(
|
|
||||||
self.packageName,
|
|
||||||
0
|
|
||||||
).versionName
|
|
||||||
}(${
|
|
||||||
self.packageManager.getPackageInfo(
|
|
||||||
self.packageName,
|
|
||||||
0
|
|
||||||
).versionCode
|
|
||||||
})" + "\n\nPS:模块只对挂后台锁屏情况下有省电效果,请不要将过多的群提醒,消息通知打开,这样子在使用过程时照样会极其耗电。\n" +
|
|
||||||
"如果你不想看到此提示。请在模块设置中关闭运行信息提醒,此设置默认关闭。\n" +
|
|
||||||
"开发者 酷安 @星夜不荟\n未经允许禁止转载、修改或复制我的劳动成果。"
|
|
||||||
)
|
|
||||||
.setPositiveButton("我知道了", null)
|
|
||||||
.show()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} catch (e: Exception) {
|
|
||||||
logE("handleLoadPackage: hook SplashActivity Failed", e)
|
|
||||||
}
|
|
||||||
/*关闭保守模式后不再仅仅作用于系统电源锁*/
|
|
||||||
if (!XPrefUtils.getBoolean("_white_mode")) {
|
|
||||||
val replaceMent = object : XC_MethodReplacement() {
|
|
||||||
override fun replaceHookedMethod(param: MethodHookParam?): Any? {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 这个类 BaseChatPie 是控制聊天界面的
|
|
||||||
* 里面有两个随机混淆的方法
|
|
||||||
* 这两个方法一个是挂起电源锁常驻亮屏
|
|
||||||
* 一个是停止常驻亮屏
|
|
||||||
* 不由分说每个版本混淆的方法名都会变
|
|
||||||
* 所以说每个版本重新适配 - 也可以提交分支帮我适配
|
|
||||||
* 8.8.17 版本是 bd be
|
|
||||||
* 8.8.23 版本是 bf bg
|
|
||||||
* ⚠️ Hook 错了方法会造成闪退!
|
|
||||||
*/
|
|
||||||
try {
|
|
||||||
/*通过在 SplashActivity 里取到应用的版本号*/
|
|
||||||
XposedHelpers.findAndHookMethod(
|
|
||||||
"com.tencent.mobileqq.activity.SplashActivity",
|
|
||||||
lpparam.classLoader,
|
lpparam.classLoader,
|
||||||
"doOnCreate",
|
"doOnCreate",
|
||||||
Bundle::class.java,
|
Bundle::class.java,
|
||||||
object : XC_MethodHook() {
|
object : XC_MethodHook() {
|
||||||
|
|
||||||
override fun beforeHookedMethod(param: MethodHookParam?) {
|
override fun beforeHookedMethod(param: MethodHookParam?) {
|
||||||
val self = param!!.thisObject as Activity
|
val self = param?.thisObject as? Activity ?: return
|
||||||
val name = self.packageName
|
val version = self.versionName
|
||||||
val version =
|
runWithoutError("BaseChatPie") { lpparam.hookQQBaseChatPie(version) }
|
||||||
self.packageManager.getPackageInfo(name, 0).versionName
|
|
||||||
/*这个地方我们只处理 QQ*/
|
|
||||||
try {
|
|
||||||
if (name == "com.tencent.mobileqq") {
|
|
||||||
when (version) {
|
|
||||||
"8.8.17" -> {
|
|
||||||
XposedHelpers.findAndHookMethod(
|
|
||||||
"com.tencent.mobileqq.activity.aio.core.BaseChatPie",
|
|
||||||
lpparam.classLoader,
|
|
||||||
"bd",
|
|
||||||
replaceMent
|
|
||||||
)
|
|
||||||
XposedHelpers.findAndHookMethod(
|
|
||||||
"com.tencent.mobileqq.activity.aio.core.BaseChatPie",
|
|
||||||
lpparam.classLoader,
|
|
||||||
"be",
|
|
||||||
replaceMent
|
|
||||||
)
|
|
||||||
}
|
|
||||||
"8.8.23" -> {
|
|
||||||
XposedHelpers.findAndHookMethod(
|
|
||||||
"com.tencent.mobileqq.activity.aio.core.BaseChatPie",
|
|
||||||
lpparam.classLoader,
|
|
||||||
"bf",
|
|
||||||
replaceMent
|
|
||||||
)
|
|
||||||
XposedHelpers.findAndHookMethod(
|
|
||||||
"com.tencent.mobileqq.activity.aio.core.BaseChatPie",
|
|
||||||
lpparam.classLoader,
|
|
||||||
"bg",
|
|
||||||
replaceMent
|
|
||||||
)
|
|
||||||
}
|
|
||||||
//TODO 后面的版本逐个适配 此方法没封装 目前比较笨蛋 主要是我懒得写
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
logE("handleLoadPackage: hook BaseChatPie Failed", e)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} catch (e: Exception) {
|
|
||||||
logE("handleLoadPackage: hook BaseChatPie(first time) Failed", e)
|
|
||||||
}
|
}
|
||||||
try {
|
runWithoutError("WakerLock") {
|
||||||
/**
|
/**
|
||||||
* 一个不知道是什么作用的电源锁
|
* 一个不知道是什么作用的电源锁
|
||||||
* 同样直接干掉
|
* 同样直接干掉
|
||||||
@@ -227,18 +408,17 @@ class HookMain : IXposedHookLoadPackage {
|
|||||||
"com.tencent.mars.ilink.comm.WakerLock",
|
"com.tencent.mars.ilink.comm.WakerLock",
|
||||||
lpparam.classLoader,
|
lpparam.classLoader,
|
||||||
"lock", Long::class.java,
|
"lock", Long::class.java,
|
||||||
replaceMent
|
replaceToNull
|
||||||
)
|
)
|
||||||
} catch (e: Exception) {
|
|
||||||
logE("handleLoadPackage: hook WakerLock Failed", e)
|
|
||||||
}
|
}
|
||||||
try {
|
runWithoutError("QQLSActivity") {
|
||||||
/**
|
/**
|
||||||
* Hook 掉一个一像素保活 [Activity] 真的我怎么都想不到讯哥的程序员做出这种事情
|
* Hook 掉一个一像素保活 [Activity] 真的我怎么都想不到讯哥的程序员做出这种事情
|
||||||
* 这个东西经过测试会在锁屏的时候吊起来,解锁的时候自动 finish(),无限耍流氓耗电
|
* 这个东西经过测试会在锁屏的时候吊起来,解锁的时候自动 finish(),无限耍流氓耗电
|
||||||
|
* 2022/1/25 后期查证:锁屏界面消息快速回复窗口的解锁后拉起保活界面,也是毒瘤
|
||||||
*/
|
*/
|
||||||
XposedHelpers.findAndHookMethod(
|
XposedHelpers.findAndHookMethod(
|
||||||
"com.tencent.mobileqq.activity.QQLSUnlockActivity",
|
"$QQ_PACKAGE_NAME.activity.QQLSUnlockActivity",
|
||||||
lpparam.classLoader,
|
lpparam.classLoader,
|
||||||
"onCreate", Bundle::class.java,
|
"onCreate", Bundle::class.java,
|
||||||
object : XC_MethodHook() {
|
object : XC_MethodHook() {
|
||||||
@@ -246,7 +426,7 @@ class HookMain : IXposedHookLoadPackage {
|
|||||||
private var origDevice = ""
|
private var origDevice = ""
|
||||||
|
|
||||||
override fun beforeHookedMethod(param: MethodHookParam?) {
|
override fun beforeHookedMethod(param: MethodHookParam?) {
|
||||||
/*由于在 onCreate 里有一行判断只要型号是 xiaomi 的设备就开电源锁,所以说这里临时替换成菊花厂*/
|
/** 由于在 onCreate 里有一行判断只要型号是 xiaomi 的设备就开电源锁,所以说这里临时替换成菊花厂 */
|
||||||
origDevice = Build.MANUFACTURER
|
origDevice = Build.MANUFACTURER
|
||||||
if (Build.MANUFACTURER.toLowerCase(Locale.ROOT) == "xiaomi")
|
if (Build.MANUFACTURER.toLowerCase(Locale.ROOT) == "xiaomi")
|
||||||
XposedHelpers.setStaticObjectField(
|
XposedHelpers.setStaticObjectField(
|
||||||
@@ -258,7 +438,7 @@ class HookMain : IXposedHookLoadPackage {
|
|||||||
|
|
||||||
override fun afterHookedMethod(param: MethodHookParam?) {
|
override fun afterHookedMethod(param: MethodHookParam?) {
|
||||||
(param?.thisObject as? Activity)?.finish()
|
(param?.thisObject as? Activity)?.finish()
|
||||||
/*这里再把型号替换回去 - 不影响应用变量等 Xposed 模块修改的型号*/
|
/** 这里再把型号替换回去 - 不影响应用变量等 Xposed 模块修改的型号 */
|
||||||
XposedHelpers.setStaticObjectField(
|
XposedHelpers.setStaticObjectField(
|
||||||
Build::class.java,
|
Build::class.java,
|
||||||
"MANUFACTURER",
|
"MANUFACTURER",
|
||||||
@@ -268,20 +448,19 @@ class HookMain : IXposedHookLoadPackage {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
/**
|
/**
|
||||||
* 这个东西同上,不知道是啥时候调用
|
* 这个东西同上
|
||||||
* 反正也是一个一像素保活的 [Activity]
|
* 反正也是一个一像素保活的 [Activity]
|
||||||
* 讯哥的程序员真的有你的
|
* 讯哥的程序员真的有你的
|
||||||
|
* 2022/1/25 后期查证:锁屏界面消息快速回复窗口
|
||||||
*/
|
*/
|
||||||
XposedHelpers.findAndHookMethod(
|
XposedHelpers.findAndHookMethod(
|
||||||
"com.tencent.mobileqq.activity.QQLSActivity\$14",
|
"$QQ_PACKAGE_NAME.activity.QQLSActivity\$14",
|
||||||
lpparam.classLoader,
|
lpparam.classLoader,
|
||||||
"run",
|
"run",
|
||||||
replaceMent
|
replaceToNull
|
||||||
)
|
)
|
||||||
} catch (e: Exception) {
|
|
||||||
logE("handleLoadPackage: hook QQLSActivity Failed", e)
|
|
||||||
}
|
}
|
||||||
try {
|
runWithoutError("WakerLockMonitor") {
|
||||||
/**
|
/**
|
||||||
* 这个是毒瘤核心类
|
* 这个是毒瘤核心类
|
||||||
* WakeLockMonitor
|
* WakeLockMonitor
|
||||||
@@ -289,6 +468,7 @@ class HookMain : IXposedHookLoadPackage {
|
|||||||
* 带给用户的却是 shit 一样的体验
|
* 带给用户的却是 shit 一样的体验
|
||||||
* 里面有各种使用 Handler 和 Timer 的各种耗时常驻后台耗电办法持续接收消息
|
* 里面有各种使用 Handler 和 Timer 的各种耗时常驻后台耗电办法持续接收消息
|
||||||
* 直接循环全部方法全部干掉
|
* 直接循环全部方法全部干掉
|
||||||
|
* 👮🏻 经过排查 Play 版本没这个类...... Emmmm 不想说啥了
|
||||||
*/
|
*/
|
||||||
lpparam.classLoader.loadClass("com.tencent.qapmsdk.qqbattery.monitor.WakeLockMonitor")
|
lpparam.classLoader.loadClass("com.tencent.qapmsdk.qqbattery.monitor.WakeLockMonitor")
|
||||||
.apply {
|
.apply {
|
||||||
@@ -345,22 +525,31 @@ class HookMain : IXposedHookLoadPackage {
|
|||||||
"writeReport",
|
"writeReport",
|
||||||
Boolean::class.java
|
Boolean::class.java
|
||||||
).apply { isAccessible = true }
|
).apply { isAccessible = true }
|
||||||
XposedBridge.hookMethod(onHook, replaceMent)
|
XposedBridge.hookMethod(onHook, replaceToNull)
|
||||||
XposedBridge.hookMethod(doReport, replaceMent)
|
XposedBridge.hookMethod(doReport, replaceToNull)
|
||||||
XposedBridge.hookMethod(afterHookedMethod, replaceMent)
|
XposedBridge.hookMethod(afterHookedMethod, replaceToNull)
|
||||||
XposedBridge.hookMethod(beforeHookedMethod, replaceMent)
|
XposedBridge.hookMethod(beforeHookedMethod, replaceToNull)
|
||||||
XposedBridge.hookMethod(onAppBackground, replaceMent)
|
XposedBridge.hookMethod(onAppBackground, replaceToNull)
|
||||||
XposedBridge.hookMethod(onOtherProcReport, replaceMent)
|
XposedBridge.hookMethod(onOtherProcReport, replaceToNull)
|
||||||
XposedBridge.hookMethod(onProcessRun30Min, replaceMent)
|
XposedBridge.hookMethod(onProcessRun30Min, replaceToNull)
|
||||||
XposedBridge.hookMethod(onProcessBG5Min, replaceMent)
|
XposedBridge.hookMethod(onProcessBG5Min, replaceToNull)
|
||||||
XposedBridge.hookMethod(writeReport, replaceMent)
|
XposedBridge.hookMethod(writeReport, replaceToNull)
|
||||||
}
|
}
|
||||||
} catch (e: Throwable) {
|
|
||||||
logE("handleLoadPackage: hook WakerLockMonitor Failed", e)
|
|
||||||
}
|
}
|
||||||
logD("handleLoadPackage: hook Complete!")
|
logD("hook Completed!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/** 微信 */
|
||||||
|
WECHAT_PACKAGE_NAME -> {
|
||||||
|
/** 判断是否关闭 Hook */
|
||||||
|
if (XPrefUtils.getBoolean(HookMedium.DISABLE_WECHAT_HOOK)) return
|
||||||
|
lpparam.apply {
|
||||||
|
hookSystemWakeLock()
|
||||||
|
hookModuleRunningInfo()
|
||||||
|
}
|
||||||
|
// TODO 新建文件夹
|
||||||
|
logD("ウイチャット:それが機能するかどうかはわかりませんでした")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
87
app/src/main/java/com/fankes/tsbattery/hook/HookMedium.kt
Normal file
87
app/src/main/java/com/fankes/tsbattery/hook/HookMedium.kt
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
||||||
|
*
|
||||||
|
* This file is part of TSBattery.
|
||||||
|
*
|
||||||
|
* TSBattery is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* TSBattery is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This file is Created by fankes on 2021/11/9.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.fankes.tsbattery.hook
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
|
import androidx.annotation.Keep
|
||||||
|
import com.fankes.tsbattery.ui.MainActivity
|
||||||
|
|
||||||
|
@Keep
|
||||||
|
object HookMedium {
|
||||||
|
|
||||||
|
const val ENABLE_HIDE_ICON = "_hide_icon"
|
||||||
|
const val ENABLE_RUN_INFO = "_tip_run_info"
|
||||||
|
const val ENABLE_QQTIM_WHITE_MODE = "_qqtim_white_mode"
|
||||||
|
const val ENABLE_QQTIM_CORESERVICE_BAN = "_qqtim_core_service_ban"
|
||||||
|
const val ENABLE_QQTIM_CORESERVICE_CHILD_BAN = "_qqtim_core_service_child_ban"
|
||||||
|
const val DISABLE_WECHAT_HOOK = "_disable_wechat_hook"
|
||||||
|
const val ENABLE_MODULE_VERSION = "_module_version"
|
||||||
|
|
||||||
|
const val SELF_PACKAGE_NAME = "com.fankes.tsbattery"
|
||||||
|
const val QQ_PACKAGE_NAME = "com.tencent.mobileqq"
|
||||||
|
const val TIM_PACKAGE_NAME = "com.tencent.tim"
|
||||||
|
const val WECHAT_PACKAGE_NAME = "com.tencent.mm"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断模块是否激活
|
||||||
|
* 在 [HookMain] 中 Hook 掉此方法
|
||||||
|
* @return [Boolean] 激活状态
|
||||||
|
*/
|
||||||
|
fun isHooked(): Boolean {
|
||||||
|
Log.d("TSBattery", "isHooked: true")
|
||||||
|
return isExpModuleActive()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 太极激活判断方式
|
||||||
|
* @return [Boolean] 是否激活
|
||||||
|
*/
|
||||||
|
private fun isExpModuleActive(): Boolean {
|
||||||
|
var isExp = false
|
||||||
|
MainActivity.instance?.also {
|
||||||
|
try {
|
||||||
|
val uri = Uri.parse("content://me.weishu.exposed.CP/")
|
||||||
|
var result: Bundle? = null
|
||||||
|
try {
|
||||||
|
result = it.contentResolver.call(uri, "active", null, null)
|
||||||
|
} catch (_: RuntimeException) {
|
||||||
|
// TaiChi is killed, try invoke
|
||||||
|
try {
|
||||||
|
val intent = Intent("me.weishu.exp.ACTION_ACTIVE")
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
|
it.startActivity(intent)
|
||||||
|
} catch (_: Throwable) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (result == null) result = it.contentResolver.call(uri, "active", null, null)
|
||||||
|
if (result == null) return false
|
||||||
|
isExp = result.getBoolean("active", false)
|
||||||
|
} catch (_: Throwable) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return isExp
|
||||||
|
}
|
||||||
|
}
|
317
app/src/main/java/com/fankes/tsbattery/ui/MainActivity.kt
Normal file
317
app/src/main/java/com/fankes/tsbattery/ui/MainActivity.kt
Normal file
@@ -0,0 +1,317 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
||||||
|
*
|
||||||
|
* This file is part of TSBattery.
|
||||||
|
*
|
||||||
|
* TSBattery is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* TSBattery is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This file is Created by fankes on 2021/9/4.
|
||||||
|
*/
|
||||||
|
@file:Suppress(
|
||||||
|
"DEPRECATION", "SetTextI18n", "SetWorldReadable", "WorldReadableFiles",
|
||||||
|
"LocalVariableName", "SameParameterValue"
|
||||||
|
)
|
||||||
|
|
||||||
|
package com.fankes.tsbattery.ui
|
||||||
|
|
||||||
|
import android.content.ComponentName
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.pm.PackageManager
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.os.Handler
|
||||||
|
import android.view.View
|
||||||
|
import android.widget.LinearLayout
|
||||||
|
import android.widget.TextView
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.appcompat.widget.SwitchCompat
|
||||||
|
import androidx.constraintlayout.utils.widget.ImageFilterView
|
||||||
|
import androidx.core.view.isGone
|
||||||
|
import com.fankes.tsbattery.BuildConfig
|
||||||
|
import com.fankes.tsbattery.R
|
||||||
|
import com.fankes.tsbattery.hook.HookMedium
|
||||||
|
import com.fankes.tsbattery.hook.HookMedium.QQ_PACKAGE_NAME
|
||||||
|
import com.fankes.tsbattery.hook.HookMedium.TIM_PACKAGE_NAME
|
||||||
|
import com.fankes.tsbattery.hook.HookMedium.WECHAT_PACKAGE_NAME
|
||||||
|
import com.fankes.tsbattery.utils.FileUtils
|
||||||
|
import com.fankes.tsbattery.utils.isInstall
|
||||||
|
import com.fankes.tsbattery.utils.openSelfSetting
|
||||||
|
import com.fankes.tsbattery.utils.showDialog
|
||||||
|
import com.gyf.immersionbar.ImmersionBar
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
private const val moduleVersion = BuildConfig.VERSION_NAME
|
||||||
|
private const val qqSupportVersion =
|
||||||
|
"8.2.11(Play)、8.8.17、8.8.23、8.8.35、8.8.38、8.8.50、8.8.55、8.8.68 (8.2.11、8.5.5~8.8.68)"
|
||||||
|
private const val timSupportVersion = "2+、3+ (并未完全测试每个版本)"
|
||||||
|
private const val wechatSupportVersion = "全版本仅支持基础省电,更多功能依然画饼"
|
||||||
|
|
||||||
|
/** 声明当前实例 */
|
||||||
|
var instance: MainActivity? = null
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
/** 设置自身实例 */
|
||||||
|
instance = this
|
||||||
|
setContentView(R.layout.activity_main)
|
||||||
|
/** 隐藏系统的标题栏 */
|
||||||
|
supportActionBar?.hide()
|
||||||
|
/** 初始化沉浸状态栏 */
|
||||||
|
ImmersionBar.with(this)
|
||||||
|
.statusBarColor(R.color.white)
|
||||||
|
.autoDarkModeEnable(false)
|
||||||
|
.statusBarDarkFont(true)
|
||||||
|
.navigationBarColor(R.color.white)
|
||||||
|
.navigationBarDarkIcon(true)
|
||||||
|
.fitsSystemWindows(true)
|
||||||
|
.init()
|
||||||
|
/** 判断 Hook 状态 */
|
||||||
|
if (isHooked()) {
|
||||||
|
findViewById<LinearLayout>(R.id.main_lin_status).setBackgroundResource(R.drawable.green_round)
|
||||||
|
findViewById<ImageFilterView>(R.id.main_img_status).setImageResource(R.mipmap.succcess)
|
||||||
|
findViewById<TextView>(R.id.main_text_status).text = "模块已激活"
|
||||||
|
/** 写入激活的模块版本 */
|
||||||
|
putString(HookMedium.ENABLE_MODULE_VERSION, moduleVersion)
|
||||||
|
} else
|
||||||
|
showDialog {
|
||||||
|
title = "模块没有激活"
|
||||||
|
msg = "检测到模块没有激活,模块需要 Xposed 环境依赖," +
|
||||||
|
"同时需要系统拥有 Root 权限(太极阴可以免 Root)," +
|
||||||
|
"请自行查看本页面使用帮助与说明第三条。\n" +
|
||||||
|
"太极、应用转生、梦境(Pine)和第三方 Xposed 激活后" +
|
||||||
|
"可能不会提示激活,若想验证是否激活请打开“提示模块运行信息”自行检查," +
|
||||||
|
"如果生效就代表模块运行正常,这里的激活状态只是一个显示意义上的存在。\n" +
|
||||||
|
"太极(无极)在 MIUI 设备上会提示打开授权,请进行允许,然后再次打开本应用查看激活状态。"
|
||||||
|
confirmButton(text = "我知道了")
|
||||||
|
noCancelable()
|
||||||
|
}
|
||||||
|
/** 设置安装状态 */
|
||||||
|
findViewById<View>(R.id.main_text_qq_noinstall).isGone = QQ_PACKAGE_NAME.isInstall
|
||||||
|
findViewById<View>(R.id.main_text_tim_noinstall).isGone = TIM_PACKAGE_NAME.isInstall
|
||||||
|
findViewById<View>(R.id.main_text_wechat_noinstall).isGone = WECHAT_PACKAGE_NAME.isInstall
|
||||||
|
/** 设置文本 */
|
||||||
|
findViewById<TextView>(R.id.main_text_version).text = "当前版本:$moduleVersion"
|
||||||
|
findViewById<TextView>(R.id.main_text_support_qq).apply {
|
||||||
|
text = qqSupportVersion
|
||||||
|
setOnClickListener {
|
||||||
|
showDialog {
|
||||||
|
title = "兼容的 QQ 版本"
|
||||||
|
msg = qqSupportVersion
|
||||||
|
confirmButton(text = "我知道了")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
findViewById<TextView>(R.id.main_text_support_tim).apply {
|
||||||
|
text = timSupportVersion
|
||||||
|
setOnClickListener {
|
||||||
|
showDialog {
|
||||||
|
title = "兼容的 TIM 版本"
|
||||||
|
msg = timSupportVersion
|
||||||
|
confirmButton(text = "我知道了")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
findViewById<TextView>(R.id.main_text_support_wechat).apply {
|
||||||
|
text = wechatSupportVersion
|
||||||
|
setOnClickListener {
|
||||||
|
showDialog {
|
||||||
|
title = "兼容的微信版本"
|
||||||
|
msg = wechatSupportVersion
|
||||||
|
confirmButton(text = "我知道了")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/** 初始化 View */
|
||||||
|
val qqTimProtectModeSwitch = findViewById<SwitchCompat>(R.id.qqtim_protect_mode_switch)
|
||||||
|
val qqTimCoreServiceSwitch = findViewById<SwitchCompat>(R.id.shut_core_sv_qqtim_switch)
|
||||||
|
val qqTimCoreServiceKnSwitch = findViewById<SwitchCompat>(R.id.shut_core_sv_kn_qqtim_switch)
|
||||||
|
val wechatDisableHookSwitch = findViewById<SwitchCompat>(R.id.disable_wechat_sv_switch)
|
||||||
|
val hideIconInLauncherSwitch = findViewById<SwitchCompat>(R.id.hide_icon_in_launcher_switch)
|
||||||
|
val notifyModuleInfoSwitch = findViewById<SwitchCompat>(R.id.notify_module_info_switch)
|
||||||
|
/** 获取 Sp 存储的信息 */
|
||||||
|
qqTimProtectModeSwitch.isChecked = getBoolean(HookMedium.ENABLE_QQTIM_WHITE_MODE)
|
||||||
|
qqTimCoreServiceSwitch.isChecked = getBoolean(HookMedium.ENABLE_QQTIM_CORESERVICE_BAN)
|
||||||
|
qqTimCoreServiceKnSwitch.isChecked = getBoolean(HookMedium.ENABLE_QQTIM_CORESERVICE_CHILD_BAN)
|
||||||
|
wechatDisableHookSwitch.isChecked = getBoolean(HookMedium.DISABLE_WECHAT_HOOK)
|
||||||
|
hideIconInLauncherSwitch.isChecked = getBoolean(HookMedium.ENABLE_HIDE_ICON)
|
||||||
|
notifyModuleInfoSwitch.isChecked = getBoolean(HookMedium.ENABLE_RUN_INFO)
|
||||||
|
qqTimProtectModeSwitch.setOnCheckedChangeListener { btn, b ->
|
||||||
|
if (!btn.isPressed) return@setOnCheckedChangeListener
|
||||||
|
putBoolean(HookMedium.ENABLE_QQTIM_WHITE_MODE, b)
|
||||||
|
}
|
||||||
|
qqTimCoreServiceSwitch.setOnCheckedChangeListener { btn, b ->
|
||||||
|
if (!btn.isPressed) return@setOnCheckedChangeListener
|
||||||
|
putBoolean(HookMedium.ENABLE_QQTIM_CORESERVICE_BAN, b)
|
||||||
|
}
|
||||||
|
qqTimCoreServiceKnSwitch.setOnCheckedChangeListener { btn, b ->
|
||||||
|
if (!btn.isPressed) return@setOnCheckedChangeListener
|
||||||
|
putBoolean(HookMedium.ENABLE_QQTIM_CORESERVICE_CHILD_BAN, b)
|
||||||
|
}
|
||||||
|
wechatDisableHookSwitch.setOnCheckedChangeListener { btn, b ->
|
||||||
|
if (!btn.isPressed) return@setOnCheckedChangeListener
|
||||||
|
putBoolean(HookMedium.DISABLE_WECHAT_HOOK, b)
|
||||||
|
}
|
||||||
|
hideIconInLauncherSwitch.setOnCheckedChangeListener { btn, b ->
|
||||||
|
if (!btn.isPressed) return@setOnCheckedChangeListener
|
||||||
|
putBoolean(HookMedium.ENABLE_HIDE_ICON, b)
|
||||||
|
packageManager.setComponentEnabledSetting(
|
||||||
|
ComponentName(this@MainActivity, "com.fankes.tsbattery.Home"),
|
||||||
|
if (b) PackageManager.COMPONENT_ENABLED_STATE_DISABLED else PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
|
||||||
|
PackageManager.DONT_KILL_APP
|
||||||
|
)
|
||||||
|
}
|
||||||
|
notifyModuleInfoSwitch.setOnCheckedChangeListener { btn, b ->
|
||||||
|
if (!btn.isPressed) return@setOnCheckedChangeListener
|
||||||
|
putBoolean(HookMedium.ENABLE_RUN_INFO, b)
|
||||||
|
}
|
||||||
|
/** 快捷操作 QQ */
|
||||||
|
findViewById<View>(R.id.quick_qq_button).setOnClickListener { openSelfSetting(QQ_PACKAGE_NAME) }
|
||||||
|
/** 快捷操作 TIM */
|
||||||
|
findViewById<View>(R.id.quick_tim_button).setOnClickListener { openSelfSetting(TIM_PACKAGE_NAME) }
|
||||||
|
/** 快捷操作微信 */
|
||||||
|
findViewById<View>(R.id.quick_wechat_button).setOnClickListener { openSelfSetting(WECHAT_PACKAGE_NAME) }
|
||||||
|
/** 恰饭! */
|
||||||
|
findViewById<View>(R.id.link_with_follow_me).setOnClickListener {
|
||||||
|
try {
|
||||||
|
startActivity(Intent().apply {
|
||||||
|
setPackage("com.coolapk.market")
|
||||||
|
action = "android.intent.action.VIEW"
|
||||||
|
data = Uri.parse("https://www.coolapk.com/u/876977")
|
||||||
|
/** 防止顶栈一样重叠在自己的 APP 中 */
|
||||||
|
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
|
})
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Toast.makeText(this, "你可能没有安装酷安", Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/** 项目地址点击事件 */
|
||||||
|
findViewById<View>(R.id.link_with_project_address).setOnClickListener {
|
||||||
|
try {
|
||||||
|
startActivity(Intent().apply {
|
||||||
|
action = "android.intent.action.VIEW"
|
||||||
|
data = Uri.parse("https://github.com/fankes/TSBattery")
|
||||||
|
/** 防止顶栈一样重叠在自己的 APP 中 */
|
||||||
|
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
|
})
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Toast.makeText(this, "无法启动系统默认浏览器", Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断模块是否激活
|
||||||
|
* @return [Boolean] 激活状态
|
||||||
|
*/
|
||||||
|
private fun isHooked() = HookMedium.isHooked()
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
setWorldReadable()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onRestart() {
|
||||||
|
super.onRestart()
|
||||||
|
setWorldReadable()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPause() {
|
||||||
|
super.onPause()
|
||||||
|
setWorldReadable()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取保存的值
|
||||||
|
* @param key 名称
|
||||||
|
* @return [Boolean] 保存的值
|
||||||
|
*/
|
||||||
|
private fun getBoolean(key: String) =
|
||||||
|
getSharedPreferences(
|
||||||
|
packageName + "_preferences",
|
||||||
|
Context.MODE_PRIVATE
|
||||||
|
).getBoolean(key, false)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存值
|
||||||
|
* @param key 名称
|
||||||
|
* @param bool 值
|
||||||
|
*/
|
||||||
|
private fun putBoolean(key: String, bool: Boolean) {
|
||||||
|
getSharedPreferences(
|
||||||
|
packageName + "_preferences",
|
||||||
|
Context.MODE_PRIVATE
|
||||||
|
).edit().putBoolean(key, bool).apply()
|
||||||
|
setWorldReadable()
|
||||||
|
/** 延迟继续设置强制允许 SP 可读可写 */
|
||||||
|
Handler().postDelayed({ setWorldReadable() }, 500)
|
||||||
|
Handler().postDelayed({ setWorldReadable() }, 1000)
|
||||||
|
Handler().postDelayed({ setWorldReadable() }, 1500)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存值
|
||||||
|
* @param key 名称
|
||||||
|
* @param value 值
|
||||||
|
*/
|
||||||
|
private fun putString(key: String, value: String) {
|
||||||
|
getSharedPreferences(
|
||||||
|
packageName + "_preferences",
|
||||||
|
Context.MODE_PRIVATE
|
||||||
|
).edit().putString(key, value).apply()
|
||||||
|
setWorldReadable()
|
||||||
|
/** 延迟继续设置强制允许 SP 可读可写 */
|
||||||
|
Handler().postDelayed({ setWorldReadable() }, 500)
|
||||||
|
Handler().postDelayed({ setWorldReadable() }, 1000)
|
||||||
|
Handler().postDelayed({ setWorldReadable() }, 1500)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 强制设置 Sp 存储为全局可读可写
|
||||||
|
* 以供模块使用
|
||||||
|
*/
|
||||||
|
private fun setWorldReadable() {
|
||||||
|
try {
|
||||||
|
if (FileUtils.getDefaultPrefFile(this).exists()) {
|
||||||
|
for (file in arrayOf<File>(
|
||||||
|
FileUtils.getDataDir(this),
|
||||||
|
FileUtils.getPrefDir(this),
|
||||||
|
FileUtils.getDefaultPrefFile(this)
|
||||||
|
)) {
|
||||||
|
file.setReadable(true, false)
|
||||||
|
file.setExecutable(true, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (_: Exception) {
|
||||||
|
Toast.makeText(this, "无法写入模块设置,请检查权限\n如果此提示一直显示,请不要双开模块", Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBackPressed() {
|
||||||
|
setWorldReadable()
|
||||||
|
super.onBackPressed()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
super.onDestroy()
|
||||||
|
/** 销毁实例防止内存泄漏 */
|
||||||
|
instance = null
|
||||||
|
}
|
||||||
|
}
|
107
app/src/main/java/com/fankes/tsbattery/utils/DialogBuilder.kt
Normal file
107
app/src/main/java/com/fankes/tsbattery/utils/DialogBuilder.kt
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
||||||
|
*
|
||||||
|
* This file is part of TSBattery.
|
||||||
|
*
|
||||||
|
* TSBattery is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* TSBattery is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This file is Created by fankes on 2022/1/7.
|
||||||
|
*/
|
||||||
|
@file:Suppress("unused")
|
||||||
|
|
||||||
|
package com.fankes.tsbattery.utils
|
||||||
|
|
||||||
|
import android.app.AlertDialog
|
||||||
|
import android.content.Context
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.graphics.drawable.GradientDrawable
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造对话框
|
||||||
|
* @param isUseBlackTheme 是否使用深色主题
|
||||||
|
* @param it 对话框方法体
|
||||||
|
*/
|
||||||
|
fun Context.showDialog(isUseBlackTheme: Boolean = false, it: DialogBuilder.() -> Unit) =
|
||||||
|
DialogBuilder(this, isUseBlackTheme).apply(it).show()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对话框构造器
|
||||||
|
* @param context 实例
|
||||||
|
* @param isUseBlackTheme 是否使用深色主题
|
||||||
|
*/
|
||||||
|
class DialogBuilder(private val context: Context, private val isUseBlackTheme: Boolean) {
|
||||||
|
|
||||||
|
private var instance: AlertDialog.Builder? = null // 实例对象
|
||||||
|
|
||||||
|
init {
|
||||||
|
instance = AlertDialog.Builder(
|
||||||
|
context,
|
||||||
|
if (isUseBlackTheme) android.R.style.Theme_Material_Dialog else android.R.style.Theme_Material_Light_Dialog
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 设置对话框不可关闭 */
|
||||||
|
fun noCancelable() = instance?.setCancelable(false)
|
||||||
|
|
||||||
|
/** 设置对话框标题 */
|
||||||
|
var title
|
||||||
|
get() = ""
|
||||||
|
set(value) {
|
||||||
|
instance?.setTitle(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 设置对话框消息内容 */
|
||||||
|
var msg
|
||||||
|
get() = ""
|
||||||
|
set(value) {
|
||||||
|
instance?.setMessage(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置对话框确定按钮
|
||||||
|
* @param text 按钮文本内容
|
||||||
|
* @param it 点击事件
|
||||||
|
*/
|
||||||
|
fun confirmButton(text: String = "确定", it: () -> Unit = {}) =
|
||||||
|
instance?.setPositiveButton(text) { _, _ -> it() }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置对话框取消按钮
|
||||||
|
* @param text 按钮文本内容
|
||||||
|
* @param it 点击事件
|
||||||
|
*/
|
||||||
|
fun cancelButton(text: String = "取消", it: () -> Unit = {}) =
|
||||||
|
instance?.setNegativeButton(text) { _, _ -> it() }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置对话框第三个按钮
|
||||||
|
* @param text 按钮文本内容
|
||||||
|
* @param it 点击事件
|
||||||
|
*/
|
||||||
|
fun neutralButton(text: String = "更多", it: () -> Unit = {}) =
|
||||||
|
instance?.setNeutralButton(text) { _, _ -> it() }
|
||||||
|
|
||||||
|
/** 显示对话框 */
|
||||||
|
internal fun show() = instance?.create()?.apply {
|
||||||
|
window?.setBackgroundDrawable(GradientDrawable(
|
||||||
|
GradientDrawable.Orientation.TOP_BOTTOM,
|
||||||
|
if (isUseBlackTheme) intArrayOf(0xFF2D2D2D.toInt(), 0xFF2D2D2D.toInt())
|
||||||
|
else intArrayOf(Color.WHITE, Color.WHITE)
|
||||||
|
).apply {
|
||||||
|
shape = GradientDrawable.RECTANGLE
|
||||||
|
gradientType = GradientDrawable.LINEAR_GRADIENT
|
||||||
|
cornerRadius = 15.dp(this@DialogBuilder.context)
|
||||||
|
})
|
||||||
|
}?.show()
|
||||||
|
}
|
@@ -21,7 +21,6 @@
|
|||||||
package com.fankes.tsbattery.utils;
|
package com.fankes.tsbattery.utils;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Environment;
|
|
||||||
|
|
||||||
import com.fankes.tsbattery.BuildConfig;
|
import com.fankes.tsbattery.BuildConfig;
|
||||||
|
|
||||||
@@ -83,12 +82,4 @@ public class FileUtils {
|
|||||||
public static File getDefaultPrefFile(Context context) {
|
public static File getDefaultPrefFile(Context context) {
|
||||||
return new File(getPrefDir(context), FILE_PREF_NAME);
|
return new File(getPrefDir(context), FILE_PREF_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File getBackupPrefsFile() {
|
|
||||||
return new File(getBackupDir(), FILE_PREF_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static File getBackupDir() {
|
|
||||||
return new File(Environment.getExternalStorageDirectory(), "QQPurify");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
98
app/src/main/java/com/fankes/tsbattery/utils/Utils.kt
Normal file
98
app/src/main/java/com/fankes/tsbattery/utils/Utils.kt
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
||||||
|
*
|
||||||
|
* This file is part of TSBattery.
|
||||||
|
*
|
||||||
|
* TSBattery is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* TSBattery is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This file is Created by fankes on 2022/1/7.
|
||||||
|
*/
|
||||||
|
@file:Suppress("DEPRECATION")
|
||||||
|
|
||||||
|
package com.fankes.tsbattery.utils
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.pm.PackageInfo
|
||||||
|
import android.content.pm.PackageManager
|
||||||
|
import android.net.Uri
|
||||||
|
import android.provider.Settings
|
||||||
|
import android.widget.Toast
|
||||||
|
import com.fankes.tsbattery.application.TSApplication.Companion.appContext
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 得到安装包信息
|
||||||
|
* @return [PackageInfo]
|
||||||
|
*/
|
||||||
|
val Context.packageInfo get() = packageManager?.getPackageInfo(packageName, 0) ?: PackageInfo()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断应用是否安装
|
||||||
|
* @return [Boolean]
|
||||||
|
*/
|
||||||
|
val String.isInstall
|
||||||
|
get() =
|
||||||
|
try {
|
||||||
|
appContext.packageManager.getPackageInfo(
|
||||||
|
this,
|
||||||
|
PackageManager.GET_UNINSTALLED_PACKAGES
|
||||||
|
)
|
||||||
|
true
|
||||||
|
} catch (e: Exception) {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 得到版本信息
|
||||||
|
* @return [String]
|
||||||
|
*/
|
||||||
|
val Context.versionName get() = packageInfo.versionName ?: ""
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 得到版本号
|
||||||
|
* @return [Int]
|
||||||
|
*/
|
||||||
|
val Context.versionCode get() = packageInfo.versionCode
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dp 转换为 px
|
||||||
|
* @return [Int]
|
||||||
|
*/
|
||||||
|
val Number.dp get() = (toFloat() * appContext.resources.displayMetrics.density).toInt()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dp 转换为 px
|
||||||
|
* @param context 使用的实例
|
||||||
|
* @return [Float]
|
||||||
|
*/
|
||||||
|
fun Number.dp(context: Context) = toFloat() * context.resources.displayMetrics.density
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 跳转 APP 自身设置界面
|
||||||
|
* @param packageName 包名
|
||||||
|
*/
|
||||||
|
fun Context.openSelfSetting(packageName: String) {
|
||||||
|
try {
|
||||||
|
if (packageName.isInstall)
|
||||||
|
startActivity(Intent().apply {
|
||||||
|
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
|
action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS
|
||||||
|
data = Uri.fromParts("package", packageName, null)
|
||||||
|
})
|
||||||
|
else Toast.makeText(this, "你没有安装此应用", Toast.LENGTH_SHORT).show()
|
||||||
|
} catch (_: Exception) {
|
||||||
|
Toast.makeText(this, "启动 $packageName 应用信息失败", Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@@ -26,6 +26,8 @@ object XPrefUtils {
|
|||||||
|
|
||||||
fun getBoolean(key: String) = pref.getBoolean(key, false)
|
fun getBoolean(key: String) = pref.getBoolean(key, false)
|
||||||
|
|
||||||
|
fun getString(key: String) = pref.getString(key, "unknown")
|
||||||
|
|
||||||
private val pref: XSharedPreferences
|
private val pref: XSharedPreferences
|
||||||
get() {
|
get() {
|
||||||
val preferences = XSharedPreferences("com.fankes.tsbattery")
|
val preferences = XSharedPreferences("com.fankes.tsbattery")
|
||||||
|
@@ -0,0 +1,291 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
||||||
|
*
|
||||||
|
* This file is part of TSBattery.
|
||||||
|
*
|
||||||
|
* TSBattery is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* TSBattery is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This file is Created by fankes on 2022/1/8.
|
||||||
|
*/
|
||||||
|
@file:Suppress("SameParameterValue")
|
||||||
|
|
||||||
|
package com.fankes.tsbattery.utils.drawable.drawabletoolbox
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
|
import android.graphics.drawable.GradientDrawable
|
||||||
|
import android.graphics.drawable.RippleDrawable
|
||||||
|
import android.graphics.drawable.RotateDrawable
|
||||||
|
import android.os.Build
|
||||||
|
import java.lang.reflect.Field
|
||||||
|
import java.lang.reflect.Method
|
||||||
|
|
||||||
|
private val gradientState = resolveGradientState()
|
||||||
|
|
||||||
|
private fun resolveGradientState(): Class<*> {
|
||||||
|
val classes = GradientDrawable::class.java.declaredClasses
|
||||||
|
for (singleClass in classes) {
|
||||||
|
if (singleClass.simpleName == "GradientState") return singleClass
|
||||||
|
}
|
||||||
|
throw RuntimeException("GradientState could not be found in thisAny GradientDrawable implementation")
|
||||||
|
}
|
||||||
|
|
||||||
|
private val rotateState = resolveRotateState()
|
||||||
|
|
||||||
|
private fun resolveRotateState(): Class<*> {
|
||||||
|
val classes = RotateDrawable::class.java.declaredClasses
|
||||||
|
for (singleClass in classes) {
|
||||||
|
if (singleClass.simpleName == "RotateState") return singleClass
|
||||||
|
}
|
||||||
|
throw RuntimeException("RotateState could not be found in thisAny RotateDrawable implementation")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Throws(SecurityException::class, NoSuchFieldException::class)
|
||||||
|
private fun resolveField(source: Class<*>, fieldName: String): Field {
|
||||||
|
val field = source.getDeclaredField(fieldName)
|
||||||
|
field.isAccessible = true
|
||||||
|
return field
|
||||||
|
}
|
||||||
|
|
||||||
|
@Throws(SecurityException::class, NoSuchMethodException::class)
|
||||||
|
private fun resolveMethod(
|
||||||
|
source: Class<*>,
|
||||||
|
methodName: String,
|
||||||
|
vararg parameterTypes: Class<*>
|
||||||
|
): Method {
|
||||||
|
val method = source.getDeclaredMethod(methodName, *parameterTypes)
|
||||||
|
method.isAccessible = true
|
||||||
|
return method
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setInnerRadius(drawable: GradientDrawable, value: Int) {
|
||||||
|
try {
|
||||||
|
val innerRadius = resolveField(gradientState, "mInnerRadius")
|
||||||
|
innerRadius.setInt(drawable.constantState, value)
|
||||||
|
} catch (e: NoSuchFieldException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
} catch (e: IllegalAccessException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setInnerRadiusRatio(drawable: GradientDrawable, value: Float) {
|
||||||
|
try {
|
||||||
|
val innerRadius = resolveField(gradientState, "mInnerRadiusRatio")
|
||||||
|
innerRadius.setFloat(drawable.constantState, value)
|
||||||
|
} catch (e: NoSuchFieldException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
} catch (e: IllegalAccessException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setThickness(drawable: GradientDrawable, value: Int) {
|
||||||
|
try {
|
||||||
|
val innerRadius = resolveField(gradientState, "mThickness")
|
||||||
|
innerRadius.setInt(drawable.constantState, value)
|
||||||
|
} catch (e: NoSuchFieldException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
} catch (e: IllegalAccessException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setThicknessRatio(drawable: GradientDrawable, value: Float) {
|
||||||
|
try {
|
||||||
|
val innerRadius = resolveField(gradientState, "mThicknessRatio")
|
||||||
|
innerRadius.setFloat(drawable.constantState, value)
|
||||||
|
} catch (e: NoSuchFieldException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
} catch (e: IllegalAccessException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setUseLevelForShape(drawable: GradientDrawable, value: Boolean) {
|
||||||
|
try {
|
||||||
|
val useLevelForShape = resolveField(gradientState, "mUseLevelForShape")
|
||||||
|
useLevelForShape.setBoolean(drawable.constantState, value)
|
||||||
|
} catch (e: NoSuchFieldException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
} catch (e: IllegalAccessException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("ObsoleteSdkInt")
|
||||||
|
fun setOrientation(drawable: GradientDrawable, value: GradientDrawable.Orientation) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||||
|
drawable.orientation = value
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
val orientation = resolveField(gradientState, "mOrientation")
|
||||||
|
orientation.set(drawable.constantState, value)
|
||||||
|
val rectIdDirty = resolveField(GradientDrawable::class.java, "mRectIsDirty")
|
||||||
|
rectIdDirty.setBoolean(drawable, true)
|
||||||
|
drawable.invalidateSelf()
|
||||||
|
} catch (e: NoSuchFieldException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
} catch (e: IllegalAccessException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("ObsoleteSdkInt")
|
||||||
|
fun setColors(drawable: GradientDrawable, value: IntArray) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||||
|
drawable.colors = value
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
val colors = resolveField(gradientState, "mColors")
|
||||||
|
colors.set(drawable.constantState, value)
|
||||||
|
drawable.invalidateSelf()
|
||||||
|
} catch (e: NoSuchFieldException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
} catch (e: IllegalAccessException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setGradientRadiusType(drawable: GradientDrawable, value: Int) {
|
||||||
|
try {
|
||||||
|
val type = resolveField(gradientState, "mGradientRadiusType")
|
||||||
|
type.setInt(drawable.constantState, value)
|
||||||
|
} catch (e: NoSuchFieldException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
} catch (e: IllegalAccessException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setGradientRadius(drawable: GradientDrawable, value: Float) {
|
||||||
|
try {
|
||||||
|
val gradientRadius = resolveField(gradientState, "mGradientRadius")
|
||||||
|
gradientRadius.setFloat(drawable.constantState, value)
|
||||||
|
} catch (e: NoSuchFieldException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
} catch (e: IllegalAccessException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setStrokeColor(drawable: GradientDrawable, value: Int) {
|
||||||
|
try {
|
||||||
|
val type = resolveField(gradientState, "mStrokeColor")
|
||||||
|
type.setInt(drawable.constantState, value)
|
||||||
|
} catch (e: NoSuchFieldException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
} catch (e: IllegalAccessException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setDrawable(rotateDrawable: RotateDrawable, drawable: Drawable) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
rotateDrawable.drawable = drawable
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
val drawableField = resolveField(rotateState, "mDrawable")
|
||||||
|
val stateField = resolveField(RotateDrawable::class.java, "mState")
|
||||||
|
drawableField.set(stateField.get(rotateDrawable), drawable)
|
||||||
|
drawable.callback = rotateDrawable
|
||||||
|
} catch (e: NoSuchFieldException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
} catch (e: IllegalAccessException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setPivotX(rotateDrawable: RotateDrawable, value: Float) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
rotateDrawable.pivotX = value
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
val pivotXField = resolveField(rotateState, "mPivotX")
|
||||||
|
pivotXField.setFloat(rotateDrawable.constantState, value)
|
||||||
|
val pivotXRelField = resolveField(rotateState, "mPivotXRel")
|
||||||
|
pivotXRelField.setBoolean(rotateDrawable.constantState, true)
|
||||||
|
} catch (e: NoSuchFieldException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
} catch (e: IllegalAccessException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setPivotY(rotateDrawable: RotateDrawable, value: Float) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
rotateDrawable.pivotY = value
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
val pivotYField = resolveField(rotateState, "mPivotY")
|
||||||
|
pivotYField.setFloat(rotateDrawable.constantState, value)
|
||||||
|
val pivotYRelField = resolveField(rotateState, "mPivotYRel")
|
||||||
|
pivotYRelField.setBoolean(rotateDrawable.constantState, true)
|
||||||
|
} catch (e: NoSuchFieldException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
} catch (e: IllegalAccessException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setFromDegrees(rotateDrawable: RotateDrawable, value: Float) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
rotateDrawable.fromDegrees = value
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
val fromDegreesField = resolveField(rotateState, "mFromDegrees")
|
||||||
|
fromDegreesField.setFloat(rotateDrawable.constantState, value)
|
||||||
|
} catch (e: NoSuchFieldException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
} catch (e: IllegalAccessException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setToDegrees(rotateDrawable: RotateDrawable, value: Float) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
rotateDrawable.toDegrees = value
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
val toDegreesField = resolveField(rotateState, "mToDegrees")
|
||||||
|
toDegreesField.setFloat(rotateDrawable.constantState, value)
|
||||||
|
} catch (e: NoSuchFieldException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
} catch (e: IllegalAccessException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setRadius(rippleDrawable: RippleDrawable, value: Int) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
rippleDrawable.radius = value
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
val setRadiusMethod =
|
||||||
|
resolveMethod(RippleDrawable::class.java, "setMaxRadius", Int::class.java)
|
||||||
|
setRadiusMethod.invoke(rippleDrawable, value)
|
||||||
|
} catch (e: NoSuchFieldException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
} catch (e: IllegalAccessException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
||||||
|
*
|
||||||
|
* This file is part of TSBattery.
|
||||||
|
*
|
||||||
|
* TSBattery is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* TSBattery is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This file is Created by fankes on 2022/1/8.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.fankes.tsbattery.utils.drawable.drawabletoolbox
|
||||||
|
|
||||||
|
class Constants {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val DEFAULT_COLOR = 0xFFBA68C8.toInt()
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,488 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
||||||
|
*
|
||||||
|
* This file is part of TSBattery.
|
||||||
|
*
|
||||||
|
* TSBattery is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* TSBattery is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This file is Created by fankes on 2022/1/8.
|
||||||
|
*/
|
||||||
|
@file:Suppress("unused", "MemberVisibilityCanBePrivate")
|
||||||
|
|
||||||
|
package com.fankes.tsbattery.utils.drawable.drawabletoolbox
|
||||||
|
|
||||||
|
import android.content.res.ColorStateList
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
|
import android.graphics.drawable.GradientDrawable
|
||||||
|
import android.util.StateSet
|
||||||
|
import java.util.*
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger
|
||||||
|
|
||||||
|
class DrawableBuilder {
|
||||||
|
|
||||||
|
private var properties = DrawableProperties()
|
||||||
|
private var order: AtomicInteger = AtomicInteger(1)
|
||||||
|
private var transformsMap = TreeMap<Int, (Drawable) -> Drawable>()
|
||||||
|
private var baseDrawable: Drawable? = null
|
||||||
|
|
||||||
|
fun batch(properties: DrawableProperties) = apply { this.properties = properties.copy() }
|
||||||
|
fun baseDrawable(drawable: Drawable) = apply { baseDrawable = drawable }
|
||||||
|
|
||||||
|
// <shape>
|
||||||
|
fun shape(shape: Int) = apply { properties.shape = shape }
|
||||||
|
|
||||||
|
fun rectangle() = apply { shape(GradientDrawable.RECTANGLE) }
|
||||||
|
fun oval() = apply { shape(GradientDrawable.OVAL) }
|
||||||
|
fun line() = apply { shape(GradientDrawable.LINE) }
|
||||||
|
fun ring() = apply { shape(GradientDrawable.RING) }
|
||||||
|
fun innerRadius(innerRadius: Int) = apply { properties.innerRadius = innerRadius }
|
||||||
|
fun innerRadiusRatio(innerRadiusRatio: Float) =
|
||||||
|
apply { properties.innerRadiusRatio = innerRadiusRatio }
|
||||||
|
|
||||||
|
fun thickness(thickness: Int) = apply { properties.thickness = thickness }
|
||||||
|
fun thicknessRatio(thicknessRatio: Float) = apply { properties.thicknessRatio = thicknessRatio }
|
||||||
|
|
||||||
|
fun useLevelForRing(use: Boolean = true) = apply { properties.useLevelForRing = use }
|
||||||
|
|
||||||
|
// <corner>
|
||||||
|
fun cornerRadius(cornerRadius: Int) = apply { properties.cornerRadius = cornerRadius }
|
||||||
|
|
||||||
|
fun topLeftRadius(topLeftRadius: Int) = apply { properties.topLeftRadius = topLeftRadius }
|
||||||
|
fun topRightRadius(topRightRadius: Int) = apply { properties.topRightRadius = topRightRadius }
|
||||||
|
fun bottomRightRadius(bottomRightRadius: Int) =
|
||||||
|
apply { properties.bottomRightRadius = bottomRightRadius }
|
||||||
|
|
||||||
|
fun bottomLeftRadius(bottomLeftRadius: Int) =
|
||||||
|
apply { properties.bottomLeftRadius = bottomLeftRadius }
|
||||||
|
|
||||||
|
fun rounded() = apply { cornerRadius(Int.MAX_VALUE) }
|
||||||
|
fun cornerRadii(
|
||||||
|
topLeftRadius: Int,
|
||||||
|
topRightRadius: Int,
|
||||||
|
bottomRightRadius: Int,
|
||||||
|
bottomLeftRadius: Int
|
||||||
|
) = apply {
|
||||||
|
topLeftRadius(topLeftRadius); topRightRadius(topRightRadius); bottomRightRadius(
|
||||||
|
bottomRightRadius
|
||||||
|
); bottomLeftRadius(bottomLeftRadius)
|
||||||
|
}
|
||||||
|
|
||||||
|
// <gradient>
|
||||||
|
|
||||||
|
fun gradient(useGradient: Boolean = true) = apply { properties.useGradient = useGradient }
|
||||||
|
|
||||||
|
fun gradientType(type: Int) = apply { properties.type = type }
|
||||||
|
fun linearGradient() = apply { gradientType(GradientDrawable.LINEAR_GRADIENT) }
|
||||||
|
fun radialGradient() = apply { gradientType(GradientDrawable.RADIAL_GRADIENT) }
|
||||||
|
fun sweepGradient() = apply { gradientType(GradientDrawable.SWEEP_GRADIENT) }
|
||||||
|
fun angle(angle: Int) = apply { properties.angle = angle }
|
||||||
|
fun centerX(centerX: Float) = apply { properties.centerX = centerX }
|
||||||
|
fun centerY(centerY: Float) = apply { properties.centerY = centerY }
|
||||||
|
fun center(centerX: Float, centerY: Float) = apply { centerX(centerX); centerY(centerY) }
|
||||||
|
|
||||||
|
fun useCenterColor(useCenterColor: Boolean = true) =
|
||||||
|
apply { properties.useCenterColor = useCenterColor }
|
||||||
|
|
||||||
|
fun startColor(startColor: Int) = apply { properties.startColor = startColor }
|
||||||
|
fun centerColor(centerColor: Int) = apply {
|
||||||
|
properties.centerColor = centerColor
|
||||||
|
useCenterColor(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun endColor(endColor: Int) = apply { properties.endColor = endColor }
|
||||||
|
fun gradientColors(startColor: Int, endColor: Int, centerColor: Int?) = apply {
|
||||||
|
startColor(startColor); endColor(endColor)
|
||||||
|
useCenterColor(centerColor != null)
|
||||||
|
centerColor?.let {
|
||||||
|
centerColor(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun gradientRadiusType(gradientRadiusType: Int) =
|
||||||
|
apply { properties.gradientRadiusType = gradientRadiusType }
|
||||||
|
|
||||||
|
fun gradientRadius(gradientRadius: Float) = apply { properties.gradientRadius = gradientRadius }
|
||||||
|
fun gradientRadius(radius: Float, type: Int) =
|
||||||
|
apply { gradientRadius(radius); gradientRadiusType(type) }
|
||||||
|
|
||||||
|
fun gradientRadiusInPixel(radius: Float) =
|
||||||
|
apply { gradientRadius(radius); gradientRadiusType(DrawableProperties.RADIUS_TYPE_PIXELS) }
|
||||||
|
|
||||||
|
fun gradientRadiusInFraction(radius: Float) =
|
||||||
|
apply { gradientRadius(radius); gradientRadiusType(DrawableProperties.RADIUS_TYPE_FRACTION) }
|
||||||
|
|
||||||
|
fun useLevelForGradient(use: Boolean) = apply { properties.useLevelForGradient = use }
|
||||||
|
fun useLevelForGradient() = apply { useLevelForGradient(true) }
|
||||||
|
|
||||||
|
// <size>
|
||||||
|
fun width(width: Int) = apply { properties.width = width }
|
||||||
|
|
||||||
|
fun height(height: Int) = apply { properties.height = height }
|
||||||
|
fun size(width: Int, height: Int) = apply { width(width); height(height) }
|
||||||
|
fun size(size: Int) = apply { width(size).height(size) }
|
||||||
|
|
||||||
|
// <solid>
|
||||||
|
fun solidColor(solidColor: Int) = apply { properties.solidColor = solidColor }
|
||||||
|
|
||||||
|
private var solidColorPressed: Int? = null
|
||||||
|
fun solidColorPressed(color: Int?) = apply { solidColorPressed = color }
|
||||||
|
private var solidColorPressedWhenRippleUnsupported: Int? = null
|
||||||
|
fun solidColorPressedWhenRippleUnsupported(color: Int?) =
|
||||||
|
apply { solidColorPressedWhenRippleUnsupported = color }
|
||||||
|
|
||||||
|
private var solidColorDisabled: Int? = null
|
||||||
|
fun solidColorDisabled(color: Int?) = apply { solidColorDisabled = color }
|
||||||
|
private var solidColorSelected: Int? = null
|
||||||
|
fun solidColorSelected(color: Int?) = apply { solidColorSelected = color }
|
||||||
|
fun solidColorStateList(colorStateList: ColorStateList) =
|
||||||
|
apply { properties.solidColorStateList = colorStateList }
|
||||||
|
|
||||||
|
// <stroke>
|
||||||
|
fun strokeWidth(strokeWidth: Int) = apply { properties.strokeWidth = strokeWidth }
|
||||||
|
|
||||||
|
fun strokeColor(strokeColor: Int) = apply { properties.strokeColor = strokeColor }
|
||||||
|
private var strokeColorPressed: Int? = null
|
||||||
|
fun strokeColorPressed(color: Int?) = apply { strokeColorPressed = color }
|
||||||
|
private var strokeColorDisabled: Int? = null
|
||||||
|
fun strokeColorDisabled(color: Int?) = apply { strokeColorDisabled = color }
|
||||||
|
private var strokeColorSelected: Int? = null
|
||||||
|
fun strokeColorSelected(color: Int?) = apply { strokeColorSelected = color }
|
||||||
|
fun strokeColorStateList(colorStateList: ColorStateList) =
|
||||||
|
apply { properties.strokeColorStateList = colorStateList }
|
||||||
|
|
||||||
|
fun dashWidth(dashWidth: Int) = apply { properties.dashWidth = dashWidth }
|
||||||
|
fun dashGap(dashGap: Int) = apply { properties.dashGap = dashGap }
|
||||||
|
fun hairlineBordered() = apply { strokeWidth(1) }
|
||||||
|
fun shortDashed() = apply { dashWidth(12).dashGap(12) }
|
||||||
|
fun mediumDashed() = apply { dashWidth(24).dashGap(24) }
|
||||||
|
fun longDashed() = apply { dashWidth(36).dashGap(36) }
|
||||||
|
fun dashed() = apply { mediumDashed() }
|
||||||
|
|
||||||
|
// <rotate>
|
||||||
|
private var rotateOrder = 0
|
||||||
|
|
||||||
|
|
||||||
|
fun rotate(boolean: Boolean = true) = apply {
|
||||||
|
properties.useRotate = boolean
|
||||||
|
rotateOrder = if (boolean) {
|
||||||
|
order.getAndIncrement()
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun pivotX(pivotX: Float) = apply { properties.pivotX = pivotX }
|
||||||
|
fun pivotY(pivotY: Float) = apply { properties.pivotY = pivotY }
|
||||||
|
fun pivot(pivotX: Float, pivotY: Float) = apply { pivotX(pivotX).pivotY(pivotY) }
|
||||||
|
fun fromDegrees(degrees: Float) = apply { properties.fromDegrees = degrees }
|
||||||
|
fun toDegrees(degrees: Float) = apply { properties.toDegrees = degrees }
|
||||||
|
fun degrees(fromDegrees: Float, toDegrees: Float) =
|
||||||
|
apply { fromDegrees(fromDegrees).toDegrees(toDegrees) }
|
||||||
|
|
||||||
|
fun degrees(degrees: Float) = apply { fromDegrees(degrees).toDegrees(degrees) }
|
||||||
|
fun rotate(fromDegrees: Float, toDegrees: Float) =
|
||||||
|
apply { rotate().fromDegrees(fromDegrees).toDegrees(toDegrees) }
|
||||||
|
|
||||||
|
fun rotate(degrees: Float) = apply { rotate().degrees(degrees) }
|
||||||
|
|
||||||
|
// <scale>
|
||||||
|
private var scaleOrder = 0
|
||||||
|
|
||||||
|
|
||||||
|
fun scale(boolean: Boolean = true) = apply {
|
||||||
|
properties.useScale = boolean
|
||||||
|
scaleOrder = if (boolean) {
|
||||||
|
order.getAndIncrement()
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun scaleLevel(level: Int) = apply { properties.scaleLevel = level }
|
||||||
|
fun scaleGravity(gravity: Int) = apply { properties.scaleGravity = gravity }
|
||||||
|
fun scaleWidth(scale: Float) = apply { properties.scaleWidth = scale }
|
||||||
|
fun scaleHeight(scale: Float) = apply { properties.scaleHeight = scale }
|
||||||
|
fun scale(scale: Float) = apply { scale().scaleWidth(scale).scaleHeight(scale) }
|
||||||
|
fun scale(scaleWidth: Float, scaleHeight: Float) =
|
||||||
|
apply { scale().scaleWidth(scaleWidth).scaleHeight(scaleHeight) }
|
||||||
|
|
||||||
|
// flip
|
||||||
|
|
||||||
|
fun flip(boolean: Boolean = true) = apply { properties.useFlip = boolean }
|
||||||
|
|
||||||
|
fun orientation(orientation: Int) = apply { properties.orientation = orientation }
|
||||||
|
fun flipVertical() = apply { flip().orientation(FlipDrawable.ORIENTATION_VERTICAL) }
|
||||||
|
|
||||||
|
// <ripple>
|
||||||
|
|
||||||
|
fun ripple(boolean: Boolean = true) = apply { properties.useRipple = boolean }
|
||||||
|
|
||||||
|
fun rippleColor(color: Int) = apply { properties.rippleColor = color }
|
||||||
|
fun rippleColorStateList(colorStateList: ColorStateList) =
|
||||||
|
apply { properties.rippleColorStateList = colorStateList }
|
||||||
|
|
||||||
|
fun rippleRadius(radius: Int) = apply { properties.rippleRadius = radius }
|
||||||
|
|
||||||
|
fun build(): Drawable {
|
||||||
|
if (baseDrawable != null) {
|
||||||
|
return wrap(baseDrawable!!)
|
||||||
|
}
|
||||||
|
|
||||||
|
var drawable: Drawable
|
||||||
|
|
||||||
|
// fall back when ripple is unavailable on devices with API < 21
|
||||||
|
if (shouldFallbackRipple()) {
|
||||||
|
if (solidColorPressedWhenRippleUnsupported != null) {
|
||||||
|
solidColorPressed(solidColorPressedWhenRippleUnsupported)
|
||||||
|
} else {
|
||||||
|
solidColorPressed(properties.rippleColor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (needStateListDrawable()) {
|
||||||
|
drawable = StateListDrawableBuilder()
|
||||||
|
.pressed(buildPressedDrawable())
|
||||||
|
.disabled(buildDisabledDrawable())
|
||||||
|
.selected(buildSelectedDrawable())
|
||||||
|
.normal(buildNormalDrawable())
|
||||||
|
.build()
|
||||||
|
} else {
|
||||||
|
drawable = GradientDrawable()
|
||||||
|
setupGradientDrawable(drawable)
|
||||||
|
}
|
||||||
|
drawable = wrap(drawable)
|
||||||
|
return drawable
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getSolidColorStateList(): ColorStateList {
|
||||||
|
if (properties.solidColorStateList != null) {
|
||||||
|
return properties.solidColorStateList!!
|
||||||
|
}
|
||||||
|
|
||||||
|
val states = mutableListOf<IntArray>()
|
||||||
|
val colors = mutableListOf<Int>()
|
||||||
|
|
||||||
|
solidColorPressed?.let {
|
||||||
|
states.add(intArrayOf(android.R.attr.state_pressed))
|
||||||
|
colors.add(it)
|
||||||
|
}
|
||||||
|
solidColorDisabled?.let {
|
||||||
|
states.add(intArrayOf(-android.R.attr.state_enabled))
|
||||||
|
colors.add(it)
|
||||||
|
}
|
||||||
|
solidColorSelected?.let {
|
||||||
|
states.add(intArrayOf(android.R.attr.state_selected))
|
||||||
|
colors.add(it)
|
||||||
|
}
|
||||||
|
states.add(StateSet.WILD_CARD)
|
||||||
|
colors.add(properties.solidColor)
|
||||||
|
|
||||||
|
return ColorStateList(states.toTypedArray(), colors.toIntArray())
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getStrokeColorStateList(): ColorStateList {
|
||||||
|
if (properties.strokeColorStateList != null) {
|
||||||
|
return properties.strokeColorStateList!!
|
||||||
|
}
|
||||||
|
|
||||||
|
val states = mutableListOf<IntArray>()
|
||||||
|
val colors = mutableListOf<Int>()
|
||||||
|
|
||||||
|
strokeColorPressed?.let {
|
||||||
|
states.add(intArrayOf(android.R.attr.state_pressed))
|
||||||
|
colors.add(it)
|
||||||
|
}
|
||||||
|
strokeColorDisabled?.let {
|
||||||
|
states.add(intArrayOf(-android.R.attr.state_enabled))
|
||||||
|
colors.add(it)
|
||||||
|
}
|
||||||
|
strokeColorSelected?.let {
|
||||||
|
states.add(intArrayOf(android.R.attr.state_selected))
|
||||||
|
colors.add(it)
|
||||||
|
}
|
||||||
|
states.add(StateSet.WILD_CARD)
|
||||||
|
colors.add(properties.strokeColor)
|
||||||
|
|
||||||
|
return ColorStateList(states.toTypedArray(), colors.toIntArray())
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun buildPressedDrawable(): Drawable? {
|
||||||
|
if (solidColorPressed == null && strokeColorPressed == null) return null
|
||||||
|
|
||||||
|
val pressedDrawable = GradientDrawable()
|
||||||
|
setupGradientDrawable(pressedDrawable)
|
||||||
|
solidColorPressed?.let {
|
||||||
|
pressedDrawable.setColor(it)
|
||||||
|
}
|
||||||
|
strokeColorPressed?.let {
|
||||||
|
setStrokeColor(pressedDrawable, it)
|
||||||
|
}
|
||||||
|
return pressedDrawable
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun buildDisabledDrawable(): Drawable? {
|
||||||
|
if (solidColorDisabled == null && strokeColorDisabled == null) return null
|
||||||
|
|
||||||
|
val disabledDrawable = GradientDrawable()
|
||||||
|
setupGradientDrawable(disabledDrawable)
|
||||||
|
solidColorDisabled?.let {
|
||||||
|
disabledDrawable.setColor(it)
|
||||||
|
}
|
||||||
|
strokeColorDisabled?.let {
|
||||||
|
setStrokeColor(disabledDrawable, it)
|
||||||
|
}
|
||||||
|
return disabledDrawable
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun buildSelectedDrawable(): Drawable? {
|
||||||
|
if (solidColorSelected == null && strokeColorSelected == null) return null
|
||||||
|
|
||||||
|
val selectedDrawable = GradientDrawable()
|
||||||
|
setupGradientDrawable(selectedDrawable)
|
||||||
|
solidColorSelected?.let {
|
||||||
|
selectedDrawable.setColor(it)
|
||||||
|
}
|
||||||
|
strokeColorSelected?.let {
|
||||||
|
setStrokeColor(selectedDrawable, it)
|
||||||
|
}
|
||||||
|
return selectedDrawable
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun buildNormalDrawable(): Drawable {
|
||||||
|
val pressedDrawable = GradientDrawable()
|
||||||
|
setupGradientDrawable(pressedDrawable)
|
||||||
|
return pressedDrawable
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupGradientDrawable(drawable: GradientDrawable) {
|
||||||
|
properties.apply {
|
||||||
|
drawable.shape = shape
|
||||||
|
if (shape == GradientDrawable.RING) {
|
||||||
|
setInnerRadius(drawable, innerRadius)
|
||||||
|
setInnerRadiusRatio(drawable, innerRadiusRatio)
|
||||||
|
setThickness(drawable, thickness)
|
||||||
|
setThicknessRatio(drawable, thicknessRatio)
|
||||||
|
setUseLevelForShape(drawable, useLevelForRing)
|
||||||
|
}
|
||||||
|
drawable.cornerRadii = getCornerRadii()
|
||||||
|
if (useGradient) {
|
||||||
|
drawable.gradientType = type
|
||||||
|
setGradientRadiusType(drawable, gradientRadiusType)
|
||||||
|
setGradientRadius(drawable, gradientRadius)
|
||||||
|
drawable.setGradientCenter(centerX, centerY)
|
||||||
|
setOrientation(drawable, getOrientation())
|
||||||
|
setColors(drawable, getColors())
|
||||||
|
drawable.useLevel = useLevelForGradient
|
||||||
|
} else {
|
||||||
|
drawable.color = getSolidColorStateList()
|
||||||
|
}
|
||||||
|
drawable.setSize(width, height)
|
||||||
|
drawable.setStroke(
|
||||||
|
strokeWidth,
|
||||||
|
getStrokeColorStateList(),
|
||||||
|
dashWidth.toFloat(),
|
||||||
|
dashGap.toFloat()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun needStateListDrawable(): Boolean {
|
||||||
|
return (hasStrokeColorStateList() || (!properties.useGradient && hasSolidColorStateList()))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun needRotateDrawable(): Boolean {
|
||||||
|
return properties.useRotate &&
|
||||||
|
!(properties.pivotX == 0.5f && properties.pivotY == 0.5f
|
||||||
|
&& properties.fromDegrees == 0f && properties.toDegrees == 0f)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun needScaleDrawable(): Boolean {
|
||||||
|
return properties.useScale
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun wrap(drawable: Drawable): Drawable {
|
||||||
|
var wrappedDrawable = drawable
|
||||||
|
|
||||||
|
if (rotateOrder > 0) {
|
||||||
|
transformsMap[rotateOrder] = ::wrapRotateIfNeeded
|
||||||
|
}
|
||||||
|
if (scaleOrder > 0) {
|
||||||
|
transformsMap[scaleOrder] = ::wrapScaleIfNeeded
|
||||||
|
}
|
||||||
|
|
||||||
|
for (action in transformsMap.values) {
|
||||||
|
wrappedDrawable = action.invoke(wrappedDrawable)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (properties.useFlip) {
|
||||||
|
wrappedDrawable = FlipDrawableBuilder()
|
||||||
|
.drawable(wrappedDrawable)
|
||||||
|
.orientation(properties.orientation)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isRippleSupported() && properties.useRipple) {
|
||||||
|
wrappedDrawable = RippleDrawableBuilder()
|
||||||
|
.drawable(wrappedDrawable)
|
||||||
|
.color(properties.rippleColor)
|
||||||
|
.colorStateList(properties.rippleColorStateList)
|
||||||
|
.radius(properties.rippleRadius)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
return wrappedDrawable
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun shouldFallbackRipple(): Boolean {
|
||||||
|
return properties.useRipple && !isRippleSupported()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isRippleSupported() = true
|
||||||
|
|
||||||
|
private fun wrapRotateIfNeeded(drawable: Drawable): Drawable {
|
||||||
|
if (!needRotateDrawable()) return drawable
|
||||||
|
|
||||||
|
with(properties) {
|
||||||
|
return RotateDrawableBuilder()
|
||||||
|
.drawable(drawable)
|
||||||
|
.pivotX(pivotX)
|
||||||
|
.pivotY(pivotY)
|
||||||
|
.fromDegrees(fromDegrees)
|
||||||
|
.toDegrees(toDegrees)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun wrapScaleIfNeeded(drawable: Drawable): Drawable {
|
||||||
|
if (!needScaleDrawable()) return drawable
|
||||||
|
|
||||||
|
with(properties) {
|
||||||
|
return ScaleDrawableBuilder()
|
||||||
|
.drawable(drawable)
|
||||||
|
.level(scaleLevel)
|
||||||
|
.scaleGravity(scaleGravity)
|
||||||
|
.scaleWidth(scaleWidth)
|
||||||
|
.scaleHeight(scaleHeight)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun hasSolidColorStateList(): Boolean {
|
||||||
|
return solidColorPressed != null || solidColorDisabled != null || solidColorSelected != null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun hasStrokeColorStateList(): Boolean {
|
||||||
|
return strokeColorPressed != null || strokeColorDisabled != null || strokeColorSelected != null
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,220 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
||||||
|
*
|
||||||
|
* This file is part of TSBattery.
|
||||||
|
*
|
||||||
|
* TSBattery is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* TSBattery is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This file is Created by fankes on 2022/1/8.
|
||||||
|
*/
|
||||||
|
@file:Suppress("SetterBackingFieldAssignment", "unused")
|
||||||
|
|
||||||
|
package com.fankes.tsbattery.utils.drawable.drawabletoolbox
|
||||||
|
|
||||||
|
import android.content.res.ColorStateList
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
|
import android.graphics.drawable.GradientDrawable
|
||||||
|
import android.os.Parcel
|
||||||
|
import android.os.Parcelable
|
||||||
|
import android.view.Gravity
|
||||||
|
import java.io.Serializable
|
||||||
|
|
||||||
|
data class DrawableProperties(
|
||||||
|
|
||||||
|
// <shape>
|
||||||
|
@JvmField var shape: Int = GradientDrawable.RECTANGLE,
|
||||||
|
@JvmField var innerRadius: Int = -1,
|
||||||
|
@JvmField var innerRadiusRatio: Float = 9f,
|
||||||
|
@JvmField var thickness: Int = -1,
|
||||||
|
@JvmField var thicknessRatio: Float = 3f,
|
||||||
|
@JvmField var useLevelForRing: Boolean = false,
|
||||||
|
|
||||||
|
// <corner>
|
||||||
|
private var _cornerRadius: Int = 0,
|
||||||
|
@JvmField var topLeftRadius: Int = 0,
|
||||||
|
@JvmField var topRightRadius: Int = 0,
|
||||||
|
@JvmField var bottomRightRadius: Int = 0,
|
||||||
|
@JvmField var bottomLeftRadius: Int = 0,
|
||||||
|
|
||||||
|
// <gradient>
|
||||||
|
@JvmField var useGradient: Boolean = false,
|
||||||
|
@JvmField var type: Int = GradientDrawable.RADIAL_GRADIENT,
|
||||||
|
@JvmField var angle: Int = 0,
|
||||||
|
@JvmField var centerX: Float = 0.5f,
|
||||||
|
@JvmField var centerY: Float = 0.5f,
|
||||||
|
@JvmField var useCenterColor: Boolean = false,
|
||||||
|
@JvmField var startColor: Int = Constants.DEFAULT_COLOR,
|
||||||
|
@JvmField var centerColor: Int? = null,
|
||||||
|
@JvmField var endColor: Int = 0x7FFFFFFF,
|
||||||
|
@JvmField var gradientRadiusType: Int = RADIUS_TYPE_FRACTION,
|
||||||
|
@JvmField var gradientRadius: Float = 0.5f,
|
||||||
|
@JvmField var useLevelForGradient: Boolean = false,
|
||||||
|
|
||||||
|
// <size>
|
||||||
|
@JvmField var width: Int = -1,
|
||||||
|
@JvmField var height: Int = -1,
|
||||||
|
|
||||||
|
// <solid>
|
||||||
|
@JvmField var solidColor: Int = Color.TRANSPARENT,
|
||||||
|
@JvmField var solidColorStateList: ColorStateList? = null,
|
||||||
|
|
||||||
|
// <stroke>
|
||||||
|
@JvmField var strokeWidth: Int = 0,
|
||||||
|
@JvmField var strokeColor: Int = Color.DKGRAY,
|
||||||
|
@JvmField var strokeColorStateList: ColorStateList? = null,
|
||||||
|
@JvmField var dashWidth: Int = 0,
|
||||||
|
@JvmField var dashGap: Int = 0,
|
||||||
|
|
||||||
|
// <rotate>
|
||||||
|
@JvmField var useRotate: Boolean = false,
|
||||||
|
@JvmField var pivotX: Float = 0.5f,
|
||||||
|
@JvmField var pivotY: Float = 0.5f,
|
||||||
|
@JvmField var fromDegrees: Float = 0f,
|
||||||
|
@JvmField var toDegrees: Float = 0f,
|
||||||
|
|
||||||
|
// <scale>
|
||||||
|
@JvmField var useScale: Boolean = false,
|
||||||
|
@JvmField var scaleLevel: Int = 10000,
|
||||||
|
@JvmField var scaleGravity: Int = Gravity.CENTER,
|
||||||
|
@JvmField var scaleWidth: Float = 0f,
|
||||||
|
@JvmField var scaleHeight: Float = 0f,
|
||||||
|
|
||||||
|
// flip
|
||||||
|
@JvmField var useFlip: Boolean = false,
|
||||||
|
@JvmField var orientation: Int = FlipDrawable.ORIENTATION_HORIZONTAL,
|
||||||
|
|
||||||
|
// ripple
|
||||||
|
@JvmField var useRipple: Boolean = false,
|
||||||
|
@JvmField var rippleColor: Int = Constants.DEFAULT_COLOR,
|
||||||
|
@JvmField var rippleColorStateList: ColorStateList? = null,
|
||||||
|
@JvmField var rippleRadius: Int = -1
|
||||||
|
) : Serializable {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val RADIUS_TYPE_PIXELS = 0
|
||||||
|
const val RADIUS_TYPE_FRACTION = 1
|
||||||
|
|
||||||
|
@JvmField
|
||||||
|
val CREATOR = object : Parcelable.Creator<DrawableProperties> {
|
||||||
|
override fun createFromParcel(parcel: Parcel): DrawableProperties {
|
||||||
|
return DrawableProperties(parcel)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun newArray(size: Int): Array<DrawableProperties?> {
|
||||||
|
return arrayOfNulls(size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var cornerRadius: Int = _cornerRadius
|
||||||
|
set(value) {
|
||||||
|
_cornerRadius = value
|
||||||
|
topLeftRadius = value
|
||||||
|
topRightRadius = value
|
||||||
|
bottomRightRadius = value
|
||||||
|
bottomLeftRadius = value
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(parcel: Parcel) : this(
|
||||||
|
parcel.readInt(),
|
||||||
|
parcel.readInt(),
|
||||||
|
parcel.readFloat(),
|
||||||
|
parcel.readInt(),
|
||||||
|
parcel.readFloat(),
|
||||||
|
parcel.readByte() != 0.toByte(),
|
||||||
|
parcel.readInt(),
|
||||||
|
parcel.readInt(),
|
||||||
|
parcel.readInt(),
|
||||||
|
parcel.readInt(),
|
||||||
|
parcel.readInt(),
|
||||||
|
parcel.readByte() != 0.toByte(),
|
||||||
|
parcel.readInt(),
|
||||||
|
parcel.readInt(),
|
||||||
|
parcel.readFloat(),
|
||||||
|
parcel.readFloat(),
|
||||||
|
parcel.readByte() != 0.toByte(),
|
||||||
|
parcel.readInt(),
|
||||||
|
parcel.readValue(Int::class.java.classLoader) as? Int,
|
||||||
|
parcel.readInt(),
|
||||||
|
parcel.readInt(),
|
||||||
|
parcel.readFloat(),
|
||||||
|
parcel.readByte() != 0.toByte(),
|
||||||
|
parcel.readInt(),
|
||||||
|
parcel.readInt(),
|
||||||
|
parcel.readInt(),
|
||||||
|
parcel.readParcelable(ColorStateList::class.java.classLoader),
|
||||||
|
parcel.readInt(),
|
||||||
|
parcel.readInt(),
|
||||||
|
parcel.readParcelable(ColorStateList::class.java.classLoader),
|
||||||
|
parcel.readInt(),
|
||||||
|
parcel.readInt(),
|
||||||
|
parcel.readByte() != 0.toByte(),
|
||||||
|
parcel.readFloat(),
|
||||||
|
parcel.readFloat(),
|
||||||
|
parcel.readFloat(),
|
||||||
|
parcel.readFloat(),
|
||||||
|
parcel.readByte() != 0.toByte(),
|
||||||
|
parcel.readInt(),
|
||||||
|
parcel.readInt(),
|
||||||
|
parcel.readFloat(),
|
||||||
|
parcel.readFloat(),
|
||||||
|
parcel.readByte() != 0.toByte(),
|
||||||
|
parcel.readInt(),
|
||||||
|
parcel.readByte() != 0.toByte(),
|
||||||
|
parcel.readInt(),
|
||||||
|
parcel.readParcelable(ColorStateList::class.java.classLoader),
|
||||||
|
parcel.readInt()
|
||||||
|
)
|
||||||
|
|
||||||
|
fun copy(): DrawableProperties {
|
||||||
|
val parcel = Parcel.obtain()
|
||||||
|
parcel.setDataPosition(0)
|
||||||
|
val properties = CREATOR.createFromParcel(parcel)
|
||||||
|
parcel.recycle()
|
||||||
|
return properties
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getCornerRadii(): FloatArray {
|
||||||
|
return floatArrayOf(
|
||||||
|
topLeftRadius.toFloat(), topLeftRadius.toFloat(),
|
||||||
|
topRightRadius.toFloat(), topRightRadius.toFloat(),
|
||||||
|
bottomRightRadius.toFloat(), bottomRightRadius.toFloat(),
|
||||||
|
bottomLeftRadius.toFloat(), bottomLeftRadius.toFloat()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getOrientation(): GradientDrawable.Orientation {
|
||||||
|
val orientation: GradientDrawable.Orientation = when (val angle = this.angle % 360) {
|
||||||
|
0 -> GradientDrawable.Orientation.LEFT_RIGHT
|
||||||
|
45 -> GradientDrawable.Orientation.BL_TR
|
||||||
|
90 -> GradientDrawable.Orientation.BOTTOM_TOP
|
||||||
|
135 -> GradientDrawable.Orientation.BR_TL
|
||||||
|
180 -> GradientDrawable.Orientation.RIGHT_LEFT
|
||||||
|
225 -> GradientDrawable.Orientation.TR_BL
|
||||||
|
270 -> GradientDrawable.Orientation.TOP_BOTTOM
|
||||||
|
315 -> GradientDrawable.Orientation.TL_BR
|
||||||
|
else -> throw IllegalArgumentException("Unsupported angle: $angle")
|
||||||
|
}
|
||||||
|
return orientation
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getColors(): IntArray {
|
||||||
|
return if (useCenterColor && centerColor != null) {
|
||||||
|
intArrayOf(startColor, centerColor!!, endColor)
|
||||||
|
} else intArrayOf(startColor, endColor)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun materialization(): Drawable = DrawableBuilder().batch(this).build()
|
||||||
|
}
|
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
||||||
|
*
|
||||||
|
* This file is part of TSBattery.
|
||||||
|
*
|
||||||
|
* TSBattery is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* TSBattery is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This file is Created by fankes on 2022/1/8.
|
||||||
|
*/
|
||||||
|
package com.fankes.tsbattery.utils.drawable.drawabletoolbox
|
||||||
|
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
|
|
||||||
|
abstract class DrawableWrapperBuilder<T: DrawableWrapperBuilder<T>> {
|
||||||
|
|
||||||
|
protected var drawable: Drawable? = null
|
||||||
|
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
fun drawable(drawable: Drawable): T = apply { this.drawable = drawable } as T
|
||||||
|
|
||||||
|
abstract fun build(): Drawable
|
||||||
|
}
|
@@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
||||||
|
*
|
||||||
|
* This file is part of TSBattery.
|
||||||
|
*
|
||||||
|
* TSBattery is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* TSBattery is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This file is Created by fankes on 2022/1/8.
|
||||||
|
*/
|
||||||
|
@file:Suppress("DEPRECATION", "CanvasSize")
|
||||||
|
|
||||||
|
package com.fankes.tsbattery.utils.drawable.drawabletoolbox
|
||||||
|
|
||||||
|
import android.graphics.Canvas
|
||||||
|
import android.graphics.ColorFilter
|
||||||
|
import android.graphics.Rect
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
|
|
||||||
|
class FlipDrawable(
|
||||||
|
private var drawable: Drawable,
|
||||||
|
private var orientation: Int = ORIENTATION_HORIZONTAL
|
||||||
|
) : Drawable() {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val ORIENTATION_HORIZONTAL = 0
|
||||||
|
const val ORIENTATION_VERTICAL = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun draw(canvas: Canvas) {
|
||||||
|
val saveCount = canvas.save()
|
||||||
|
if (orientation == ORIENTATION_VERTICAL) {
|
||||||
|
canvas.scale(1f, -1f, (canvas.width / 2).toFloat(), (canvas.height / 2).toFloat())
|
||||||
|
} else {
|
||||||
|
canvas.scale(-1f, 1f, (canvas.width / 2).toFloat(), (canvas.height / 2).toFloat())
|
||||||
|
}
|
||||||
|
drawable.bounds = Rect(0, 0, canvas.width, canvas.height)
|
||||||
|
drawable.draw(canvas)
|
||||||
|
canvas.restoreToCount(saveCount)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onLevelChange(level: Int): Boolean {
|
||||||
|
drawable.level = level
|
||||||
|
invalidateSelf()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getIntrinsicWidth(): Int {
|
||||||
|
return drawable.intrinsicWidth
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getIntrinsicHeight(): Int {
|
||||||
|
return drawable.intrinsicHeight
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setAlpha(alpha: Int) {
|
||||||
|
drawable.alpha = alpha
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getOpacity(): Int {
|
||||||
|
return drawable.opacity
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setColorFilter(colorFilter: ColorFilter?) {
|
||||||
|
drawable.colorFilter = colorFilter
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
||||||
|
*
|
||||||
|
* This file is part of TSBattery.
|
||||||
|
*
|
||||||
|
* TSBattery is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* TSBattery is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This file is Created by fankes on 2022/1/8.
|
||||||
|
*/
|
||||||
|
package com.fankes.tsbattery.utils.drawable.drawabletoolbox
|
||||||
|
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
|
|
||||||
|
class FlipDrawableBuilder : DrawableWrapperBuilder<FlipDrawableBuilder>() {
|
||||||
|
|
||||||
|
private var orientation: Int = FlipDrawable.ORIENTATION_HORIZONTAL
|
||||||
|
|
||||||
|
fun orientation(orientation: Int) = apply { this.orientation = orientation }
|
||||||
|
|
||||||
|
override fun build(): Drawable {
|
||||||
|
return FlipDrawable(drawable!!, orientation)
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,181 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
||||||
|
*
|
||||||
|
* This file is part of TSBattery.
|
||||||
|
*
|
||||||
|
* TSBattery is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* TSBattery is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This file is Created by fankes on 2022/1/8.
|
||||||
|
*/
|
||||||
|
package com.fankes.tsbattery.utils.drawable.drawabletoolbox
|
||||||
|
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
|
import android.graphics.drawable.LayerDrawable
|
||||||
|
import android.os.Build
|
||||||
|
import android.view.Gravity
|
||||||
|
import androidx.annotation.RequiresApi
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
class LayerDrawableBuilder {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val DIMEN_UNDEFINED = Int.MIN_VALUE
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
|
||||||
|
private var paddingMode = LayerDrawable.PADDING_MODE_NEST
|
||||||
|
private var paddingLeft = 0
|
||||||
|
private var paddingTop = 0
|
||||||
|
private var paddingRight = 0
|
||||||
|
private var paddingBottom = 0
|
||||||
|
private var paddingStart = 0
|
||||||
|
private var paddingEnd = 0
|
||||||
|
private val layers = ArrayList<Layer>()
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
|
||||||
|
fun paddingMode(mode: Int) = apply { paddingMode = mode }
|
||||||
|
fun paddingLeft(padding: Int) = apply { paddingLeft = padding }
|
||||||
|
fun paddingTop(padding: Int) = apply { paddingTop = padding }
|
||||||
|
fun paddingRight(padding: Int) = apply { paddingRight = padding }
|
||||||
|
fun paddingBottom(padding: Int) = apply { paddingBottom = padding }
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.M)
|
||||||
|
fun paddingStart(padding: Int) = apply { paddingStart = padding }
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.M)
|
||||||
|
fun paddingEnd(padding: Int) = apply { paddingEnd = padding }
|
||||||
|
fun padding(padding: Int) = apply {
|
||||||
|
paddingLeft(padding).paddingTop(padding).paddingRight(padding).paddingBottom(padding)
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.M)
|
||||||
|
fun paddingRelative(padding: Int) = apply {
|
||||||
|
paddingStart(padding).paddingTop(padding).paddingEnd(padding).paddingBottom(padding)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun add(drawable: Drawable) = apply { layers.add(Layer(drawable)) }
|
||||||
|
|
||||||
|
fun width(width: Int) = apply { layers.last().width = width }
|
||||||
|
fun height(height: Int) = apply { layers.last().height = height }
|
||||||
|
|
||||||
|
fun insetLeft(inset: Int) = apply { layers.last().insetLeft = inset }
|
||||||
|
fun insetTop(inset: Int) = apply { layers.last().insetTop = inset }
|
||||||
|
fun insetRight(inset: Int) = apply { layers.last().insetRight = inset }
|
||||||
|
fun insetBottom(inset: Int) = apply { layers.last().insetBottom = inset }
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.M)
|
||||||
|
fun insetStart(inset: Int) = apply { layers.last().insetStart = inset }
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.M)
|
||||||
|
fun insetEnd(inset: Int) = apply { layers.last().insetEnd = inset }
|
||||||
|
fun inset(inset: Int) =
|
||||||
|
apply { insetLeft(inset).insetTop(inset).insetRight(inset).insetBottom(inset) }
|
||||||
|
|
||||||
|
fun inset(insetLeft: Int, insetTop: Int, insetRight: Int, insetBottom: Int) = apply {
|
||||||
|
insetLeft(insetLeft).insetTop(insetTop).insetRight(insetRight).insetBottom(insetBottom)
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.M)
|
||||||
|
fun insetRelative(inset: Int) =
|
||||||
|
apply { insetStart(inset).insetTop(inset).insetEnd(inset).insetBottom(inset) }
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.M)
|
||||||
|
fun insetRelative(insetStart: Int, insetTop: Int, insetEnd: Int, insetBottom: Int) = apply {
|
||||||
|
insetStart(insetStart).insetTop(insetTop).insetEnd(insetEnd).insetBottom(insetBottom)
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.M)
|
||||||
|
fun gravity(gravity: Int) = apply { layers.last().gravity = gravity }
|
||||||
|
|
||||||
|
fun modify(
|
||||||
|
index: Int, drawable: Drawable,
|
||||||
|
width: Int = DIMEN_UNDEFINED,
|
||||||
|
height: Int = DIMEN_UNDEFINED,
|
||||||
|
insetLeft: Int = DIMEN_UNDEFINED,
|
||||||
|
insetTop: Int = DIMEN_UNDEFINED,
|
||||||
|
insetRight: Int = DIMEN_UNDEFINED,
|
||||||
|
insetBottom: Int = DIMEN_UNDEFINED,
|
||||||
|
insetStart: Int = DIMEN_UNDEFINED,
|
||||||
|
insetEnd: Int = DIMEN_UNDEFINED
|
||||||
|
) =
|
||||||
|
apply {
|
||||||
|
val layer = layers[index]
|
||||||
|
layer.drawable = drawable
|
||||||
|
if (width != DIMEN_UNDEFINED) layer.width = width
|
||||||
|
if (height != DIMEN_UNDEFINED) layer.height = height
|
||||||
|
if (insetLeft != DIMEN_UNDEFINED) layer.insetLeft = insetLeft
|
||||||
|
if (insetTop != DIMEN_UNDEFINED) layer.insetTop = insetTop
|
||||||
|
if (insetRight != DIMEN_UNDEFINED) layer.insetRight = insetRight
|
||||||
|
if (insetBottom != DIMEN_UNDEFINED) layer.insetBottom = insetBottom
|
||||||
|
if (insetStart != DIMEN_UNDEFINED) layer.insetStart = insetStart
|
||||||
|
if (insetEnd != DIMEN_UNDEFINED) layer.insetEnd = insetEnd
|
||||||
|
}
|
||||||
|
|
||||||
|
fun build(): LayerDrawable {
|
||||||
|
val layerDrawable = LayerDrawable(layers.map { it -> it.drawable }.toTypedArray())
|
||||||
|
for (i in 0 until layers.size) {
|
||||||
|
val layer = layers[i]
|
||||||
|
layerDrawable.setLayerInset(
|
||||||
|
i,
|
||||||
|
layer.insetLeft,
|
||||||
|
layer.insetTop,
|
||||||
|
layer.insetRight,
|
||||||
|
layer.insetBottom
|
||||||
|
)
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
if (layer.insetStart != DIMEN_UNDEFINED || layer.insetEnd != DIMEN_UNDEFINED) {
|
||||||
|
layerDrawable.setLayerInsetRelative(
|
||||||
|
i,
|
||||||
|
layer.insetStart,
|
||||||
|
layer.insetTop,
|
||||||
|
layer.insetEnd,
|
||||||
|
layer.insetBottom
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
layerDrawable.setId(i, i)
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
layerDrawable.setLayerGravity(i, layer.gravity)
|
||||||
|
layerDrawable.setLayerInsetStart(i, layer.insetStart)
|
||||||
|
layerDrawable.setLayerInsetEnd(i, layer.insetEnd)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
layerDrawable.paddingMode = paddingMode
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
layerDrawable.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom)
|
||||||
|
if (paddingStart != DIMEN_UNDEFINED || paddingEnd != DIMEN_UNDEFINED) {
|
||||||
|
layerDrawable.setPaddingRelative(
|
||||||
|
paddingStart,
|
||||||
|
paddingTop,
|
||||||
|
paddingEnd,
|
||||||
|
paddingBottom
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return layerDrawable
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class Layer(var drawable: Drawable) {
|
||||||
|
var gravity: Int = Gravity.NO_GRAVITY
|
||||||
|
var width: Int = -1
|
||||||
|
var height: Int = -1
|
||||||
|
var insetLeft: Int = 0
|
||||||
|
var insetTop: Int = 0
|
||||||
|
var insetRight: Int = 0
|
||||||
|
var insetBottom: Int = 0
|
||||||
|
var insetStart: Int = DIMEN_UNDEFINED
|
||||||
|
var insetEnd: Int = DIMEN_UNDEFINED
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
||||||
|
*
|
||||||
|
* This file is part of TSBattery.
|
||||||
|
*
|
||||||
|
* TSBattery is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* TSBattery is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This file is Created by fankes on 2022/1/8.
|
||||||
|
*/
|
||||||
|
package com.fankes.tsbattery.utils.drawable.drawabletoolbox
|
||||||
|
|
||||||
|
import android.graphics.Path
|
||||||
|
import android.graphics.drawable.ShapeDrawable
|
||||||
|
import android.graphics.drawable.shapes.PathShape
|
||||||
|
|
||||||
|
class PathShapeDrawableBuilder {
|
||||||
|
|
||||||
|
private var path: Path? = null
|
||||||
|
private var pathStandardWidth: Float = 100f
|
||||||
|
private var pathStandardHeight: Float = 100f
|
||||||
|
private var width: Int = -1
|
||||||
|
private var height: Int = -1
|
||||||
|
|
||||||
|
fun path(path: Path, pathStandardWidth: Float, pathStandardHeight: Float) = apply {
|
||||||
|
this.path = path
|
||||||
|
this.pathStandardWidth = pathStandardWidth
|
||||||
|
this.pathStandardHeight = pathStandardHeight
|
||||||
|
}
|
||||||
|
|
||||||
|
fun width(width: Int) = apply { this.width = width }
|
||||||
|
fun height(height: Int) = apply { this.height = height }
|
||||||
|
fun size(size: Int) = apply { width(size).height(size) }
|
||||||
|
|
||||||
|
fun build(custom: ((shapeDrawable: ShapeDrawable) -> Unit)? = null): ShapeDrawable {
|
||||||
|
val shapeDrawable = ShapeDrawable()
|
||||||
|
if (path == null || width <= 0 || height <= 0) {
|
||||||
|
return shapeDrawable
|
||||||
|
}
|
||||||
|
val pathShape = PathShape(path!!, pathStandardWidth, pathStandardHeight)
|
||||||
|
|
||||||
|
shapeDrawable.shape = pathShape
|
||||||
|
shapeDrawable.intrinsicWidth = width
|
||||||
|
shapeDrawable.intrinsicHeight = height
|
||||||
|
if (custom != null) {
|
||||||
|
custom(shapeDrawable)
|
||||||
|
}
|
||||||
|
return shapeDrawable
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
||||||
|
*
|
||||||
|
* This file is part of TSBattery.
|
||||||
|
*
|
||||||
|
* TSBattery is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* TSBattery is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This file is Created by fankes on 2022/1/8.
|
||||||
|
*/
|
||||||
|
package com.fankes.tsbattery.utils.drawable.drawabletoolbox
|
||||||
|
|
||||||
|
import android.content.res.ColorStateList
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.graphics.drawable.*
|
||||||
|
import android.util.StateSet
|
||||||
|
|
||||||
|
class RippleDrawableBuilder : DrawableWrapperBuilder<RippleDrawableBuilder>() {
|
||||||
|
|
||||||
|
private var color: Int = Constants.DEFAULT_COLOR
|
||||||
|
private var colorStateList: ColorStateList? = null
|
||||||
|
private var radius: Int = -1
|
||||||
|
|
||||||
|
fun color(color: Int) = apply { this.color = color }
|
||||||
|
fun colorStateList(colorStateList: ColorStateList?) =
|
||||||
|
apply { this.colorStateList = colorStateList }
|
||||||
|
|
||||||
|
fun radius(radius: Int) = apply { this.radius = radius }
|
||||||
|
|
||||||
|
override fun build(): Drawable {
|
||||||
|
var drawable = this.drawable!!
|
||||||
|
val colorStateList = this.colorStateList ?: ColorStateList(
|
||||||
|
arrayOf(StateSet.WILD_CARD),
|
||||||
|
intArrayOf(color)
|
||||||
|
)
|
||||||
|
|
||||||
|
var mask = if (drawable is DrawableContainer) drawable.getCurrent() else drawable
|
||||||
|
if (mask is ShapeDrawable) {
|
||||||
|
val state = mask.getConstantState()
|
||||||
|
if (state != null) {
|
||||||
|
val temp = state.newDrawable().mutate() as ShapeDrawable
|
||||||
|
temp.paint.color = Color.BLACK
|
||||||
|
mask = temp
|
||||||
|
}
|
||||||
|
} else if (mask is GradientDrawable) {
|
||||||
|
val state = mask.getConstantState()
|
||||||
|
if (state != null) {
|
||||||
|
val temp = state.newDrawable().mutate() as GradientDrawable
|
||||||
|
temp.setColor(Color.BLACK)
|
||||||
|
mask = temp
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mask = ColorDrawable(Color.BLACK)
|
||||||
|
}
|
||||||
|
|
||||||
|
val rippleDrawable = RippleDrawable(colorStateList, drawable, mask)
|
||||||
|
setRadius(rippleDrawable, radius)
|
||||||
|
rippleDrawable.invalidateSelf()
|
||||||
|
drawable = rippleDrawable
|
||||||
|
return drawable
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
||||||
|
*
|
||||||
|
* This file is part of TSBattery.
|
||||||
|
*
|
||||||
|
* TSBattery is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* TSBattery is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This file is Created by fankes on 2022/1/8.
|
||||||
|
*/
|
||||||
|
package com.fankes.tsbattery.utils.drawable.drawabletoolbox
|
||||||
|
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
|
import android.graphics.drawable.RotateDrawable
|
||||||
|
|
||||||
|
class RotateDrawableBuilder : DrawableWrapperBuilder<RotateDrawableBuilder>() {
|
||||||
|
|
||||||
|
private var pivotX: Float = 0.5f
|
||||||
|
private var pivotY: Float = 0.5f
|
||||||
|
private var fromDegrees: Float = 0f
|
||||||
|
private var toDegrees: Float = 360f
|
||||||
|
|
||||||
|
fun pivotX(x: Float) = apply { pivotX = x }
|
||||||
|
fun pivotY(y: Float) = apply { pivotY = y }
|
||||||
|
fun fromDegrees(degree: Float) = apply { fromDegrees = degree }
|
||||||
|
fun toDegrees(degree: Float) = apply { toDegrees = degree }
|
||||||
|
|
||||||
|
override fun build(): Drawable {
|
||||||
|
val rotateDrawable = RotateDrawable()
|
||||||
|
drawable?.let {
|
||||||
|
setDrawable(rotateDrawable, it)
|
||||||
|
apply {
|
||||||
|
setPivotX(rotateDrawable, pivotX)
|
||||||
|
setPivotY(rotateDrawable, pivotY)
|
||||||
|
setFromDegrees(rotateDrawable, fromDegrees)
|
||||||
|
setToDegrees(rotateDrawable, toDegrees)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rotateDrawable
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
||||||
|
*
|
||||||
|
* This file is part of TSBattery.
|
||||||
|
*
|
||||||
|
* TSBattery is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* TSBattery is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This file is Created by fankes on 2022/1/8.
|
||||||
|
*/
|
||||||
|
package com.fankes.tsbattery.utils.drawable.drawabletoolbox
|
||||||
|
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
|
import android.graphics.drawable.ScaleDrawable
|
||||||
|
import android.view.Gravity
|
||||||
|
|
||||||
|
class ScaleDrawableBuilder : DrawableWrapperBuilder<ScaleDrawableBuilder>() {
|
||||||
|
|
||||||
|
private var level: Int = 10000
|
||||||
|
private var scaleGravity = Gravity.CENTER
|
||||||
|
private var scaleWidth: Float = 0f
|
||||||
|
private var scaleHeight: Float = 0f
|
||||||
|
|
||||||
|
fun level(level: Int) = apply { this.level = level }
|
||||||
|
fun scaleGravity(gravity: Int) = apply { this.scaleGravity = gravity }
|
||||||
|
fun scaleWidth(scale: Float) = apply { this.scaleWidth = scale }
|
||||||
|
fun scaleHeight(scale: Float) = apply { this.scaleHeight = scale }
|
||||||
|
|
||||||
|
override fun build(): Drawable {
|
||||||
|
val scaleDrawable = ScaleDrawable(drawable, scaleGravity, scaleWidth, scaleHeight)
|
||||||
|
scaleDrawable.level = level
|
||||||
|
return scaleDrawable
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
||||||
|
*
|
||||||
|
* This file is part of TSBattery.
|
||||||
|
*
|
||||||
|
* TSBattery is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* TSBattery is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This file is Created by fankes on 2022/1/8.
|
||||||
|
*/
|
||||||
|
package com.fankes.tsbattery.utils.drawable.drawabletoolbox
|
||||||
|
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.graphics.drawable.ColorDrawable
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
|
import android.graphics.drawable.StateListDrawable
|
||||||
|
import android.util.StateSet
|
||||||
|
|
||||||
|
class StateListDrawableBuilder {
|
||||||
|
|
||||||
|
private var pressed: Drawable? = null
|
||||||
|
private var disabled: Drawable? = null
|
||||||
|
private var selected: Drawable? = null
|
||||||
|
private var normal: Drawable = ColorDrawable(Color.TRANSPARENT)
|
||||||
|
|
||||||
|
fun pressed(pressed: Drawable?) = apply { this.pressed = pressed }
|
||||||
|
fun disabled(disabled: Drawable?) = apply { this.disabled = disabled }
|
||||||
|
fun selected(selected: Drawable?) = apply { this.selected = selected }
|
||||||
|
fun normal(normal: Drawable) = apply { this.normal = normal }
|
||||||
|
|
||||||
|
fun build(): StateListDrawable {
|
||||||
|
val stateListDrawable = StateListDrawable()
|
||||||
|
setupStateListDrawable(stateListDrawable)
|
||||||
|
return stateListDrawable
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupStateListDrawable(stateListDrawable: StateListDrawable) {
|
||||||
|
pressed?.let {
|
||||||
|
stateListDrawable.addState(intArrayOf(android.R.attr.state_pressed), it)
|
||||||
|
}
|
||||||
|
disabled?.let {
|
||||||
|
stateListDrawable.addState(intArrayOf(-android.R.attr.state_enabled), it)
|
||||||
|
}
|
||||||
|
selected?.let {
|
||||||
|
stateListDrawable.addState(intArrayOf(android.R.attr.state_selected), it)
|
||||||
|
}
|
||||||
|
stateListDrawable.addState(StateSet.WILD_CARD, normal)
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
||||||
|
*
|
||||||
|
* This file is part of TSBattery.
|
||||||
|
*
|
||||||
|
* TSBattery is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* TSBattery is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This file is Created by fankes on 2022/1/8.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@file:Suppress("SameParameterValue")
|
||||||
|
|
||||||
|
package com.fankes.tsbattery.view
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.res.ColorStateList
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import androidx.appcompat.widget.SwitchCompat
|
||||||
|
import com.fankes.tsbattery.utils.dp
|
||||||
|
import com.fankes.tsbattery.utils.drawable.drawabletoolbox.DrawableBuilder
|
||||||
|
|
||||||
|
class MaterialSwitch(context: Context, attrs: AttributeSet?) : SwitchCompat(context, attrs) {
|
||||||
|
|
||||||
|
private fun toColors(selected: Int, pressed: Int, normal: Int): ColorStateList {
|
||||||
|
val colors = intArrayOf(selected, pressed, normal)
|
||||||
|
val states = arrayOfNulls<IntArray>(3)
|
||||||
|
states[0] = intArrayOf(android.R.attr.state_checked)
|
||||||
|
states[1] = intArrayOf(android.R.attr.state_pressed)
|
||||||
|
states[2] = intArrayOf()
|
||||||
|
return ColorStateList(states, colors)
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
trackDrawable = DrawableBuilder()
|
||||||
|
.rectangle()
|
||||||
|
.rounded()
|
||||||
|
.solidColor(0xFF656565.toInt())
|
||||||
|
.height(20.dp)
|
||||||
|
.cornerRadius(15.dp)
|
||||||
|
.build()
|
||||||
|
thumbDrawable = DrawableBuilder()
|
||||||
|
.rectangle()
|
||||||
|
.rounded()
|
||||||
|
.solidColor(Color.WHITE)
|
||||||
|
.size(20.dp, 20.dp)
|
||||||
|
.cornerRadius(20.dp)
|
||||||
|
.strokeWidth(2.dp)
|
||||||
|
.strokeColor(Color.TRANSPARENT)
|
||||||
|
.build()
|
||||||
|
trackTintList = toColors(
|
||||||
|
0xFF656565.toInt(),
|
||||||
|
0xFFCCCCCC.toInt(),
|
||||||
|
0xFFCCCCCC.toInt()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
10
app/src/main/res/drawable/button_round.xml
Normal file
10
app/src/main/res/drawable/button_round.xml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:color="#777777">
|
||||||
|
<item>
|
||||||
|
<shape android:shape="rectangle">
|
||||||
|
<solid android:color="#66DAD9D9" />
|
||||||
|
<corners android:radius="15dp" />
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
</ripple>
|
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:shape="rectangle">
|
android:shape="rectangle">
|
||||||
<solid android:color="#6A6A6A" />
|
<solid android:color="#661B1B1B" />
|
||||||
<corners android:radius="15dp" />
|
<corners android:radius="15dp" />
|
||||||
</shape>
|
</shape>
|
6
app/src/main/res/drawable/permotion_round.xml
Normal file
6
app/src/main/res/drawable/permotion_round.xml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shape="rectangle">
|
||||||
|
<solid android:color="#66E4E4E4" />
|
||||||
|
<corners android:radius="15dp" />
|
||||||
|
</shape>
|
6
app/src/main/res/drawable/red_round.xml
Executable file
6
app/src/main/res/drawable/red_round.xml
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shape="rectangle">
|
||||||
|
<solid android:color="#FF786F" />
|
||||||
|
<corners android:radius="30dp" />
|
||||||
|
</shape>
|
@@ -1,18 +1,22 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
tools:context=".MainActivity"
|
tools:context=".ui.MainActivity"
|
||||||
tools:ignore="HardcodedText">
|
tools:ignore="HardcodedText,UseCompoundDrawables,ContentDescription,TooManyViews">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@color/white"
|
android:background="@color/white"
|
||||||
android:elevation="5dp"
|
android:elevation="0dp"
|
||||||
android:padding="15dp">
|
android:paddingLeft="15dp"
|
||||||
|
android:paddingTop="13dp"
|
||||||
|
android:paddingRight="15dp"
|
||||||
|
android:paddingBottom="5dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@@ -20,7 +24,7 @@
|
|||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:text="TSBattery"
|
android:text="TSBattery"
|
||||||
android:textColor="#FF323B42"
|
android:textColor="#FF323B42"
|
||||||
android:textSize="18sp"
|
android:textSize="30sp"
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
@@ -28,9 +32,12 @@
|
|||||||
android:id="@+id/main_lin_status"
|
android:id="@+id/main_lin_status"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_margin="15dp"
|
android:layout_marginLeft="15dp"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
android:layout_marginRight="15dp"
|
||||||
|
android:layout_marginBottom="5dp"
|
||||||
android:background="@drawable/dark_round"
|
android:background="@drawable/dark_round"
|
||||||
android:elevation="3dp"
|
android:elevation="0dp"
|
||||||
android:gravity="center">
|
android:gravity="center">
|
||||||
|
|
||||||
<androidx.constraintlayout.utils.widget.ImageFilterView
|
<androidx.constraintlayout.utils.widget.ImageFilterView
|
||||||
@@ -46,7 +53,10 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:padding="20dp">
|
android:paddingLeft="20dp"
|
||||||
|
android:paddingTop="10dp"
|
||||||
|
android:paddingRight="20dp"
|
||||||
|
android:paddingBottom="10dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/main_text_status"
|
android:id="@+id/main_text_status"
|
||||||
@@ -61,30 +71,160 @@
|
|||||||
android:id="@+id/main_text_version"
|
android:id="@+id/main_text_version"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="3dp"
|
android:layout_marginBottom="10dp"
|
||||||
android:alpha="0.8"
|
android:alpha="0.8"
|
||||||
android:text="当前版本:%1"
|
android:text="当前版本:%1"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
android:textSize="13sp" />
|
android:textSize="13sp" />
|
||||||
|
|
||||||
<TextView
|
<LinearLayout
|
||||||
android:id="@+id/main_text_support"
|
android:layout_width="match_parent"
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="3dp"
|
android:layout_marginBottom="7dp"
|
||||||
android:alpha="0.8"
|
android:gravity="center|start"
|
||||||
android:text="支持 %1"
|
android:orientation="horizontal">
|
||||||
android:textColor="@color/white"
|
|
||||||
android:textSize="12sp" />
|
|
||||||
|
|
||||||
<TextView
|
<ImageView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="15dp"
|
||||||
|
android:layout_height="15dp"
|
||||||
|
android:layout_marginEnd="5dp"
|
||||||
|
android:src="@mipmap/qq_icon" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/main_text_qq_noinstall"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="3dp"
|
||||||
|
android:alpha="0.8"
|
||||||
|
android:background="@drawable/red_round"
|
||||||
|
android:paddingLeft="2dp"
|
||||||
|
android:paddingTop="1dp"
|
||||||
|
android:paddingRight="2dp"
|
||||||
|
android:paddingBottom="1dp"
|
||||||
|
android:text="未安装"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textSize="9sp"
|
||||||
|
tools:ignore="SmallSp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="5dp"
|
||||||
|
android:alpha="0.8"
|
||||||
|
android:text="兼容"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textSize="11sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/main_text_support_qq"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:alpha="0.8"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:text="%1"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textSize="11sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:alpha="0.6"
|
android:layout_marginBottom="7dp"
|
||||||
android:text="理论在小更新内还会生效,如果失效请看下方的联系方式"
|
android:gravity="center|start"
|
||||||
android:textColor="@color/white"
|
android:orientation="horizontal">
|
||||||
android:textSize="10sp"
|
|
||||||
tools:ignore="SmallSp" />
|
<ImageView
|
||||||
|
android:layout_width="15dp"
|
||||||
|
android:layout_height="15dp"
|
||||||
|
android:layout_marginEnd="5dp"
|
||||||
|
android:src="@mipmap/tim_icon" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/main_text_tim_noinstall"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="3dp"
|
||||||
|
android:alpha="0.8"
|
||||||
|
android:background="@drawable/red_round"
|
||||||
|
android:paddingLeft="2dp"
|
||||||
|
android:paddingTop="1dp"
|
||||||
|
android:paddingRight="2dp"
|
||||||
|
android:paddingBottom="1dp"
|
||||||
|
android:text="未安装"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textSize="9sp"
|
||||||
|
tools:ignore="SmallSp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="5dp"
|
||||||
|
android:alpha="0.8"
|
||||||
|
android:text="兼容"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textSize="11sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/main_text_support_tim"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:alpha="0.8"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:text="%1"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textSize="11sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center|start"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="15dp"
|
||||||
|
android:layout_height="15dp"
|
||||||
|
android:layout_marginEnd="5dp"
|
||||||
|
android:src="@mipmap/wechat_icon" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/main_text_wechat_noinstall"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="3dp"
|
||||||
|
android:alpha="0.8"
|
||||||
|
android:background="@drawable/red_round"
|
||||||
|
android:paddingLeft="2dp"
|
||||||
|
android:paddingTop="1dp"
|
||||||
|
android:paddingRight="2dp"
|
||||||
|
android:paddingBottom="1dp"
|
||||||
|
android:text="未安装"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textSize="9sp"
|
||||||
|
tools:ignore="SmallSp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="5dp"
|
||||||
|
android:alpha="0.8"
|
||||||
|
android:text="兼容"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textSize="11sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/main_text_support_wechat"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:alpha="0.8"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:text="%1"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textSize="11sp" />
|
||||||
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
@@ -94,7 +234,6 @@
|
|||||||
android:layout_marginBottom="10dp"
|
android:layout_marginBottom="10dp"
|
||||||
android:fadingEdgeLength="10dp"
|
android:fadingEdgeLength="10dp"
|
||||||
android:fillViewport="true"
|
android:fillViewport="true"
|
||||||
android:overScrollMode="never"
|
|
||||||
android:requiresFadingEdge="vertical">
|
android:requiresFadingEdge="vertical">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
@@ -108,18 +247,76 @@
|
|||||||
android:layout_marginLeft="15dp"
|
android:layout_marginLeft="15dp"
|
||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="10dp"
|
||||||
android:layout_marginRight="15dp"
|
android:layout_marginRight="15dp"
|
||||||
android:background="@drawable/white_round"
|
android:background="@drawable/permotion_round"
|
||||||
android:elevation="2dp"
|
android:elevation="0dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:padding="15dp">
|
||||||
|
|
||||||
|
<androidx.constraintlayout.utils.widget.ImageFilterView
|
||||||
|
android:layout_width="15dp"
|
||||||
|
android:layout_height="15dp"
|
||||||
|
android:layout_marginEnd="15dp"
|
||||||
|
android:alpha="0.85"
|
||||||
|
android:src="@mipmap/about"
|
||||||
|
android:tint="#FF777777" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:alpha="0.6"
|
||||||
|
android:lineSpacingExtra="5dp"
|
||||||
|
android:text="上述列出的版本号为最佳兼容版本,你可以点击进行查看。\n没有标注的版本在适配范围内的 APP 适用性都将有效,但可能不能达到最佳使用效果。\n如果当前版本失效请看下方的联系方式。"
|
||||||
|
android:textColor="#FF323B42"
|
||||||
|
android:textSize="10sp"
|
||||||
|
tools:ignore="SmallSp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="15dp"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
android:layout_marginRight="15dp"
|
||||||
|
android:background="@drawable/permotion_round"
|
||||||
|
android:elevation="0dp"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingLeft="15dp"
|
android:padding="15dp">
|
||||||
android:paddingRight="15dp">
|
|
||||||
|
|
||||||
<androidx.appcompat.widget.SwitchCompat
|
<LinearLayout
|
||||||
android:id="@+id/protect_mode_switch"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="启用保守模式"
|
android:layout_marginBottom="5dp"
|
||||||
|
android:gravity="center|start">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="15dp"
|
||||||
|
android:layout_height="15dp"
|
||||||
|
android:layout_marginEnd="5dp"
|
||||||
|
android:src="@mipmap/qq_icon" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="15dp"
|
||||||
|
android:layout_height="15dp"
|
||||||
|
android:layout_marginEnd="10dp"
|
||||||
|
android:src="@mipmap/tim_icon" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:alpha="0.85"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:text="QQ、TIM"
|
||||||
|
android:textColor="#FF323B42"
|
||||||
|
android:textSize="12sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<com.fankes.tsbattery.view.MaterialSwitch
|
||||||
|
android:id="@+id/qqtim_protect_mode_switch"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="启用保守模式 [QQ]"
|
||||||
android:textColor="#FF323B42"
|
android:textColor="#FF323B42"
|
||||||
android:textSize="15sp" />
|
android:textSize="15sp" />
|
||||||
|
|
||||||
@@ -129,25 +326,193 @@
|
|||||||
android:layout_marginBottom="10dp"
|
android:layout_marginBottom="10dp"
|
||||||
android:alpha="0.6"
|
android:alpha="0.6"
|
||||||
android:lineSpacingExtra="6dp"
|
android:lineSpacingExtra="6dp"
|
||||||
android:text="此选项默认关闭,默认情况下模块将会干掉 QQ 和 TIM 自身的电源锁控制类,开启后模块将只对系统电源锁生效,如果你的 QQ 或 TIM 视频通话等设置发生了故障,可以尝试开启这个功能,开启后请重启 QQ 或 TIM。"
|
android:text="此选项默认关闭,默认情况下模块将会干掉 QQ 自身的电源锁控制类,开启后模块将只对系统电源锁生效,如果你的 QQ 视频通话等设置发生了故障,可以尝试开启这个功能,开启后请重启 QQ。"
|
||||||
|
android:textColor="#777777"
|
||||||
|
android:textSize="12sp" />
|
||||||
|
|
||||||
|
<com.fankes.tsbattery.view.MaterialSwitch
|
||||||
|
android:id="@+id/shut_core_sv_qqtim_switch"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="关闭 CoreService"
|
||||||
|
android:textColor="#FF323B42"
|
||||||
|
android:textSize="15sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="10dp"
|
||||||
|
android:alpha="0.6"
|
||||||
|
android:lineSpacingExtra="6dp"
|
||||||
|
android:text="关闭后可能会影响消息接收与视频通话,但是会达到省电效果,如果你的系统拥有推送服务(HMS)或(GMS)可以尝试关闭。"
|
||||||
|
android:textColor="#777777"
|
||||||
|
android:textSize="12sp" />
|
||||||
|
|
||||||
|
<com.fankes.tsbattery.view.MaterialSwitch
|
||||||
|
android:id="@+id/shut_core_sv_kn_qqtim_switch"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="关闭 CoreService$KernelService"
|
||||||
|
android:textColor="#FF323B42"
|
||||||
|
android:textSize="15sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:alpha="0.6"
|
||||||
|
android:lineSpacingExtra="6dp"
|
||||||
|
android:text="这是一个辅助子服务,理论主服务关闭后子服务同样不会被启动,建议在保证消息接收的前提下可以尝试关闭子服务。"
|
||||||
android:textColor="#777777"
|
android:textColor="#777777"
|
||||||
android:textSize="12sp" />
|
android:textSize="12sp" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="15dp"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
android:layout_marginRight="15dp"
|
||||||
|
android:background="@drawable/permotion_round"
|
||||||
|
android:elevation="0dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="15dp">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="5dp"
|
||||||
|
android:gravity="center|start">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="15dp"
|
||||||
|
android:layout_height="15dp"
|
||||||
|
android:layout_marginEnd="10dp"
|
||||||
|
android:src="@mipmap/wechat_icon" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:alpha="0.85"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:text="微信"
|
||||||
|
android:textColor="#FF323B42"
|
||||||
|
android:textSize="12sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<com.fankes.tsbattery.view.MaterialSwitch
|
||||||
|
android:id="@+id/disable_wechat_sv_switch"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="停用省电策略"
|
||||||
|
android:textColor="#FF323B42"
|
||||||
|
android:textSize="15sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:alpha="0.6"
|
||||||
|
android:lineSpacingExtra="6dp"
|
||||||
|
android:text="选择停用后模块将不再对微信生效,可解决通话耳边不会黑屏和闪退问题,微信省电功能依然在开(画)发(饼),敬请期待。"
|
||||||
|
android:textColor="#777777"
|
||||||
|
android:textSize="12sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="15dp"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
android:layout_marginRight="15dp"
|
||||||
|
android:background="@drawable/permotion_round"
|
||||||
|
android:elevation="0dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="15dp">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="10dp"
|
||||||
|
android:gravity="center|start">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="15dp"
|
||||||
|
android:layout_height="15dp"
|
||||||
|
android:layout_marginEnd="10dp"
|
||||||
|
android:src="@mipmap/shot_icon" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:alpha="0.85"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:text="快捷操作"
|
||||||
|
android:textColor="#FF323B42"
|
||||||
|
android:textSize="12sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/quick_qq_button"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="5dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:background="@drawable/button_round"
|
||||||
|
android:gravity="center"
|
||||||
|
android:padding="10dp"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:text="QQ"
|
||||||
|
android:textColor="#FF323B42"
|
||||||
|
android:textSize="15sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/quick_tim_button"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="5dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:background="@drawable/button_round"
|
||||||
|
android:gravity="center"
|
||||||
|
android:padding="10dp"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:text="TIM"
|
||||||
|
android:textColor="#FF323B42"
|
||||||
|
android:textSize="15sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/quick_wechat_button"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:background="@drawable/button_round"
|
||||||
|
android:gravity="center"
|
||||||
|
android:padding="10dp"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:text="微信"
|
||||||
|
android:textColor="#FF323B42"
|
||||||
|
android:textSize="15sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginLeft="15dp"
|
android:layout_marginLeft="15dp"
|
||||||
android:layout_marginTop="15dp"
|
android:layout_marginTop="15dp"
|
||||||
android:layout_marginRight="15dp"
|
android:layout_marginRight="15dp"
|
||||||
android:background="@drawable/white_round"
|
android:background="@drawable/permotion_round"
|
||||||
android:elevation="2dp"
|
android:elevation="0dp"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingLeft="15dp"
|
android:paddingLeft="15dp"
|
||||||
android:paddingRight="15dp">
|
android:paddingRight="15dp">
|
||||||
|
|
||||||
<androidx.appcompat.widget.SwitchCompat
|
<com.fankes.tsbattery.view.MaterialSwitch
|
||||||
android:id="@+id/notify_module_info_switch"
|
android:id="@+id/notify_module_info_switch"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@@ -161,7 +526,7 @@
|
|||||||
android:layout_marginBottom="10dp"
|
android:layout_marginBottom="10dp"
|
||||||
android:alpha="0.6"
|
android:alpha="0.6"
|
||||||
android:lineSpacingExtra="6dp"
|
android:lineSpacingExtra="6dp"
|
||||||
android:text="模块工作正常情况下不要开启,如果你想测试模块是否正常激活,可以打开此提示,开启后将会在启动 QQ 或 TIM 的时候提示运行信息。"
|
android:text="模块工作正常情况下无需开启,如果你想测试模块是否正常激活,可以打开此提示,开启后将会在启动 QQ、TIM 或微信的时候提示运行信息。"
|
||||||
android:textColor="#777777"
|
android:textColor="#777777"
|
||||||
android:textSize="12sp" />
|
android:textSize="12sp" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -172,14 +537,14 @@
|
|||||||
android:layout_marginLeft="15dp"
|
android:layout_marginLeft="15dp"
|
||||||
android:layout_marginTop="15dp"
|
android:layout_marginTop="15dp"
|
||||||
android:layout_marginRight="15dp"
|
android:layout_marginRight="15dp"
|
||||||
android:background="@drawable/white_round"
|
android:background="@drawable/permotion_round"
|
||||||
android:elevation="2dp"
|
android:elevation="0dp"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingLeft="15dp"
|
android:paddingLeft="15dp"
|
||||||
android:paddingRight="15dp">
|
android:paddingRight="15dp">
|
||||||
|
|
||||||
<androidx.appcompat.widget.SwitchCompat
|
<com.fankes.tsbattery.view.MaterialSwitch
|
||||||
android:id="@+id/hide_icon_in_launcher_switch"
|
android:id="@+id/hide_icon_in_launcher_switch"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@@ -193,7 +558,7 @@
|
|||||||
android:layout_marginBottom="10dp"
|
android:layout_marginBottom="10dp"
|
||||||
android:alpha="0.6"
|
android:alpha="0.6"
|
||||||
android:lineSpacingExtra="6dp"
|
android:lineSpacingExtra="6dp"
|
||||||
android:text="隐藏模块图标后,模块不会再在桌面显示,你可以在 EdXposed、太极、LsPosed 中找到模块设置并打开。"
|
android:text="隐藏模块图标后,模块不会再在桌面显示,你可以在 EdXposed、太极、LsPosed 中找到模块设置并打开,对原生系统无效。"
|
||||||
android:textColor="#777777"
|
android:textColor="#777777"
|
||||||
android:textSize="12sp" />
|
android:textSize="12sp" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -204,17 +569,15 @@
|
|||||||
android:layout_marginLeft="15dp"
|
android:layout_marginLeft="15dp"
|
||||||
android:layout_marginTop="15dp"
|
android:layout_marginTop="15dp"
|
||||||
android:layout_marginRight="15dp"
|
android:layout_marginRight="15dp"
|
||||||
android:background="@drawable/white_round"
|
android:background="@drawable/permotion_round"
|
||||||
android:elevation="2dp"
|
android:elevation="0dp"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingLeft="15dp"
|
android:padding="15dp">
|
||||||
android:paddingRight="15dp">
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="10dp"
|
|
||||||
android:layout_marginBottom="10dp"
|
android:layout_marginBottom="10dp"
|
||||||
android:gravity="center|start">
|
android:gravity="center|start">
|
||||||
|
|
||||||
@@ -282,6 +645,35 @@
|
|||||||
android:layout_marginBottom="10dp"
|
android:layout_marginBottom="10dp"
|
||||||
android:alpha="0.8"
|
android:alpha="0.8"
|
||||||
android:lineSpacingExtra="6dp"
|
android:lineSpacingExtra="6dp"
|
||||||
|
android:text="Q.模块是否需要挂后台?\nA.模块完全不需要挂后台,模块只是一个控制和显示的工具,真正的任务交由 Hook 处理,若出现失效的情况请发送模块运行日志给我们而不是将模块挂后台。"
|
||||||
|
android:textColor="#777777"
|
||||||
|
android:textSize="12sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="10dp"
|
||||||
|
android:alpha="0.8"
|
||||||
|
android:lineSpacingExtra="6dp"
|
||||||
|
android:text="Q.关于目前微信的适配情况?\nA.微信适配尚在实验阶段,敬请期待。"
|
||||||
|
android:textColor="#777777"
|
||||||
|
android:textSize="12sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="10dp"
|
||||||
|
android:alpha="0.8"
|
||||||
|
android:lineSpacingExtra="6dp"
|
||||||
|
android:text="Q.如何对单独的 APP 生效模块?\nA.请在 LsPosed 中勾选对应定义域即可,我们不建议使用 EdXposed。"
|
||||||
|
android:textColor="#777777"
|
||||||
|
android:textSize="12sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:alpha="0.8"
|
||||||
|
android:lineSpacingExtra="6dp"
|
||||||
android:text="Q.如何反馈问题?\nA.酷安关注 @星夜不荟"
|
android:text="Q.如何反馈问题?\nA.酷安关注 @星夜不荟"
|
||||||
android:textColor="#777777"
|
android:textColor="#777777"
|
||||||
android:textSize="12sp" />
|
android:textSize="12sp" />
|
||||||
@@ -294,17 +686,15 @@
|
|||||||
android:layout_marginLeft="15dp"
|
android:layout_marginLeft="15dp"
|
||||||
android:layout_marginTop="15dp"
|
android:layout_marginTop="15dp"
|
||||||
android:layout_marginRight="15dp"
|
android:layout_marginRight="15dp"
|
||||||
android:background="@drawable/white_round"
|
android:background="@drawable/permotion_round"
|
||||||
android:elevation="2dp"
|
android:elevation="0dp"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingLeft="15dp"
|
android:padding="15dp">
|
||||||
android:paddingRight="15dp">
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="10dp"
|
|
||||||
android:layout_marginBottom="10dp"
|
android:layout_marginBottom="10dp"
|
||||||
android:gravity="center|start">
|
android:gravity="center|start">
|
||||||
|
|
||||||
@@ -329,7 +719,6 @@
|
|||||||
<TextView
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="10dp"
|
|
||||||
android:alpha="0.8"
|
android:alpha="0.8"
|
||||||
android:lineSpacingExtra="6dp"
|
android:lineSpacingExtra="6dp"
|
||||||
android:text="本软件是免费开源项目,遵循 GPL 协议,你可以点击这里前往 Github 查看源码以及获取模块更新。\n严禁以任何形式贩卖、商用本软件,否则开发者有权追究其法律责任。"
|
android:text="本软件是免费开源项目,遵循 GPL 协议,你可以点击这里前往 Github 查看源码以及获取模块更新。\n严禁以任何形式贩卖、商用本软件,否则开发者有权追究其法律责任。"
|
||||||
@@ -344,30 +733,37 @@
|
|||||||
android:layout_marginTop="15dp"
|
android:layout_marginTop="15dp"
|
||||||
android:layout_marginRight="15dp"
|
android:layout_marginRight="15dp"
|
||||||
android:layout_marginBottom="10dp"
|
android:layout_marginBottom="10dp"
|
||||||
android:background="@drawable/white_round"
|
android:background="@drawable/permotion_round"
|
||||||
android:elevation="2dp"
|
android:elevation="0dp"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingLeft="15dp"
|
android:paddingLeft="15dp"
|
||||||
android:paddingRight="15dp">
|
android:paddingRight="15dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/link_with_follow_me"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="10dp"
|
||||||
android:layout_marginBottom="10dp"
|
android:layout_marginBottom="10dp"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:lineSpacingExtra="6dp"
|
android:lineSpacingExtra="6dp"
|
||||||
android:text="恰饭时间\n酷安关注我,获取我的更多应用"
|
android:text="恰饭时间\n点击前往酷安关注我,获取我的更多应用"
|
||||||
android:textColor="#FF323B42"
|
android:textColor="#FF323B42"
|
||||||
android:textSize="16sp" />
|
android:textSize="16sp" />
|
||||||
|
|
||||||
<ImageView
|
<androidx.cardview.widget.CardView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="10dp"
|
android:layout_marginBottom="10dp"
|
||||||
android:src="@mipmap/qr_pay"
|
app:cardCornerRadius="15dp"
|
||||||
tools:ignore="ContentDescription" />
|
app:cardElevation="0dp">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:src="@mipmap/qr_pay" />
|
||||||
|
</androidx.cardview.widget.CardView>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
BIN
app/src/main/res/mipmap-xxhdpi/qq_icon.png
Normal file
BIN
app/src/main/res/mipmap-xxhdpi/qq_icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.8 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/shot_icon.png
Normal file
BIN
app/src/main/res/mipmap-xxhdpi/shot_icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.0 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/tim_icon.png
Normal file
BIN
app/src/main/res/mipmap-xxhdpi/tim_icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.3 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/wechat_icon.png
Normal file
BIN
app/src/main/res/mipmap-xxhdpi/wechat_icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.2 KiB |
BIN
banner.png
Normal file
BIN
banner.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 38 KiB |
18
build.gradle
18
build.gradle
@@ -1,15 +1,15 @@
|
|||||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
buildscript {
|
buildscript {
|
||||||
ext.kotlin_version = "1.4.20"
|
ext.kotlin_version = "1.6.10"
|
||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
//noinspection JcenterRepositoryObsolete
|
maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
|
||||||
jcenter()
|
maven { url 'https://maven.aliyun.com/nexus/content/repositories/jcenter' }
|
||||||
|
maven { url "https://www.jitpack.io" }
|
||||||
|
mavenCentral()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
//noinspection AndroidGradlePluginVersion
|
classpath "com.android.tools.build:gradle:7.0.4"
|
||||||
classpath "com.android.tools.build:gradle:4.1.1"
|
|
||||||
//noinspection DifferentKotlinGradleVersion
|
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
@@ -20,8 +20,10 @@ buildscript {
|
|||||||
allprojects {
|
allprojects {
|
||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
//noinspection JcenterRepositoryObsolete
|
maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
|
||||||
jcenter()
|
maven { url 'https://maven.aliyun.com/nexus/content/repositories/jcenter' }
|
||||||
|
maven { url "https://www.jitpack.io" }
|
||||||
|
mavenCentral()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
|||||||
#Sat Sep 04 04:05:23 CST 2021
|
#Sat Sep 04 04:05:23 CST 2021
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
Reference in New Issue
Block a user