mirror of
https://github.com/fankes/ColorOSNotifyIcon.git
synced 2025-09-06 02:35:41 +08:00
增加模块激活状态判断以及模块更新提醒
This commit is contained in:
@@ -27,16 +27,12 @@ package com.fankes.coloros.notify.application
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import com.fankes.coloros.notify.BuildConfig
|
||||
import me.weishu.reflection.Reflection
|
||||
|
||||
class CNNApplication : Application() {
|
||||
|
||||
companion object {
|
||||
|
||||
/** 当前模块的包名 */
|
||||
const val MODULE_PACKAGE_NAME = BuildConfig.APPLICATION_ID
|
||||
|
||||
/** 全局静态实例 */
|
||||
private var context: CNNApplication? = null
|
||||
|
||||
|
54
app/src/main/java/com/fankes/coloros/notify/const/Const.kt
Normal file
54
app/src/main/java/com/fankes/coloros/notify/const/Const.kt
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* ColorOSNotifyIcon - Optimize notification icons for ColorOS and adapt to native notification icon specifications.
|
||||
* Copyright (C) 2019-2022 Fankes Studio(qzmmcn@163.com)
|
||||
* https://github.com/fankes/ColorOSNotifyIcon
|
||||
*
|
||||
* This software is non-free but opensource software: you can redistribute it
|
||||
* and/or modify it under the terms of the GNU Affero General Public License
|
||||
* as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
* <p>
|
||||
*
|
||||
* This software 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
|
||||
* Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* and eula along with this software. If not, see
|
||||
* <https://www.gnu.org/licenses/>
|
||||
*
|
||||
* This file is Created by fankes on 2022/3/24.
|
||||
*/
|
||||
@file:Suppress("MemberVisibilityCanBePrivate")
|
||||
|
||||
package com.fankes.coloros.notify.const
|
||||
|
||||
import com.fankes.coloros.notify.BuildConfig
|
||||
|
||||
/**
|
||||
* 存储一些静态编译后的值
|
||||
*/
|
||||
object Const {
|
||||
|
||||
/** 当前模块的包名 */
|
||||
const val MODULE_PACKAGE_NAME = BuildConfig.APPLICATION_ID
|
||||
|
||||
/** 当前模块的版本名称 */
|
||||
const val MODULE_VERSION_NAME = BuildConfig.VERSION_NAME
|
||||
|
||||
/** 当前模块的版本号 */
|
||||
const val MODULE_VERSION_CODE = BuildConfig.VERSION_CODE
|
||||
|
||||
/** 当前模块的版本校验 */
|
||||
const val MODULE_VERSION_VERIFY = "${MODULE_VERSION_NAME}_${MODULE_VERSION_CODE}_202103240401"
|
||||
|
||||
/** 当前模块的版本校验标签 */
|
||||
const val MODULE_VERSION_VERIFY_TAG = "module_version_verify"
|
||||
|
||||
/** 发送通讯广播号标签 */
|
||||
const val MODULE_CHECKING_RECEIVER = "cnn_checking_action"
|
||||
|
||||
/** 接收通讯广播号标签 */
|
||||
const val MODULE_HANDLER_RECEIVER = "cnn_handler_action"
|
||||
}
|
@@ -23,8 +23,10 @@
|
||||
package com.fankes.coloros.notify.hook
|
||||
|
||||
import android.app.WallpaperManager
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Color
|
||||
import android.graphics.Outline
|
||||
@@ -38,8 +40,8 @@ import android.view.View
|
||||
import android.view.ViewOutlineProvider
|
||||
import android.widget.ImageView
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import com.fankes.coloros.notify.application.CNNApplication.Companion.MODULE_PACKAGE_NAME
|
||||
import com.fankes.coloros.notify.bean.IconDataBean
|
||||
import com.fankes.coloros.notify.const.Const
|
||||
import com.fankes.coloros.notify.hook.HookConst.ENABLE_ANDROID12_STYLE
|
||||
import com.fankes.coloros.notify.hook.HookConst.ENABLE_MODULE
|
||||
import com.fankes.coloros.notify.hook.HookConst.ENABLE_MODULE_LOG
|
||||
@@ -172,6 +174,32 @@ class HookEntry : YukiHookXposedInitProxy {
|
||||
/** 仅监听一次主题壁纸颜色变化 */
|
||||
private var isWallpaperColorListenerSetUp = false
|
||||
|
||||
/** 是否已经注册广播 */
|
||||
private var isRegisterModuleReceiver = false
|
||||
|
||||
/** 模块广播接收器 */
|
||||
private val moduleReceiver by lazy {
|
||||
object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
context?.sendBroadcast(Intent().apply {
|
||||
action = Const.MODULE_HANDLER_RECEIVER
|
||||
putExtra("isAction", true)
|
||||
putExtra("isValied", intent?.getStringExtra(Const.MODULE_VERSION_VERIFY_TAG) == Const.MODULE_VERSION_VERIFY)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册模块广播接收器
|
||||
* @param context 实例
|
||||
*/
|
||||
private fun registerModuleReceiver(context: Context) {
|
||||
if (isRegisterModuleReceiver) return
|
||||
context.registerReceiver(moduleReceiver, IntentFilter().apply { addAction(Const.MODULE_CHECKING_RECEIVER) })
|
||||
isRegisterModuleReceiver = true
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否启用通知图标优化功能
|
||||
* @param isHooking 是否判断启用通知功能 - 默认:是
|
||||
@@ -508,7 +536,7 @@ class HookEntry : YukiHookXposedInitProxy {
|
||||
type = IconClass
|
||||
}.get(result).set(Icon.createWithBitmap(pair.first.toBitmap()))
|
||||
/** 刷新缓存 */
|
||||
if (nf.packageName == MODULE_PACKAGE_NAME &&
|
||||
if (nf.packageName == Const.MODULE_PACKAGE_NAME &&
|
||||
nf.notification.channelId == IconRuleManagerTool.NOTIFY_CHANNEL
|
||||
) recachingPrefs()
|
||||
}
|
||||
@@ -528,6 +556,7 @@ class HookEntry : YukiHookXposedInitProxy {
|
||||
afterHook {
|
||||
if (firstArgs != null) instance<ImageView>().also {
|
||||
registerWallpaperColorChanged(it)
|
||||
registerModuleReceiver(it.context)
|
||||
statusBarIconViews.add(it)
|
||||
}
|
||||
}
|
||||
|
@@ -24,11 +24,12 @@
|
||||
|
||||
package com.fankes.coloros.notify.ui.activity
|
||||
|
||||
import android.content.ComponentName
|
||||
import android.content.*
|
||||
import android.content.pm.PackageManager
|
||||
import androidx.core.view.isVisible
|
||||
import com.fankes.coloros.notify.BuildConfig
|
||||
import com.fankes.coloros.notify.R
|
||||
import com.fankes.coloros.notify.const.Const
|
||||
import com.fankes.coloros.notify.databinding.ActivityMainBinding
|
||||
import com.fankes.coloros.notify.hook.HookConst.ENABLE_ANDROID12_STYLE
|
||||
import com.fankes.coloros.notify.hook.HookConst.ENABLE_HIDE_ICON
|
||||
@@ -46,6 +47,7 @@ import com.fankes.coloros.notify.utils.tool.GithubReleaseTool
|
||||
import com.fankes.coloros.notify.utils.tool.SystemUITool
|
||||
import com.highcapable.yukihookapi.hook.factory.isXposedModuleActive
|
||||
import com.highcapable.yukihookapi.hook.factory.modulePrefs
|
||||
import com.highcapable.yukihookapi.hook.xposed.YukiHookModuleStatus
|
||||
|
||||
class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
|
||||
@@ -58,6 +60,12 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
private const val pendingFlag = "[pending]"
|
||||
}
|
||||
|
||||
/** 模块是否激活 */
|
||||
private var isModuleAction = false
|
||||
|
||||
/** 模块是否有效 */
|
||||
private var isModuleValied = false
|
||||
|
||||
override fun onCreate() {
|
||||
/** 检查更新 */
|
||||
GithubReleaseTool.checkingForUpdate(context = this, moduleVersion) { version, function ->
|
||||
@@ -82,9 +90,6 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
}
|
||||
/** 判断是否 Hook */
|
||||
isXposedModuleActive -> {
|
||||
binding.mainLinStatus.setBackgroundResource(R.drawable.bg_green_round)
|
||||
binding.mainImgStatus.setImageResource(R.mipmap.ic_success)
|
||||
binding.mainTextStatus.text = "模块已激活"
|
||||
if (IconPackParams(context = this).iconDatas.isEmpty()
|
||||
&& modulePrefs.getBoolean(ENABLE_NOTIFY_ICON_FIX, default = true)
|
||||
) showDialog {
|
||||
@@ -195,5 +200,63 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
binding.linkWithFollowMe.setOnClickListener {
|
||||
openBrowser(url = "https://www.coolapk.com/u/876977", packageName = "com.coolapk.market")
|
||||
}
|
||||
/** 注册广播检查模块激活状态 */
|
||||
registerReceiver(hostReceiver, IntentFilter().apply { addAction(Const.MODULE_HANDLER_RECEIVER) })
|
||||
}
|
||||
|
||||
/** 刷新模块状态 */
|
||||
private fun refreshModuleStatus() {
|
||||
binding.mainLinStatus.setBackgroundResource(
|
||||
when {
|
||||
isXposedModuleActive && (!isModuleAction || !isModuleValied) -> R.drawable.bg_yellow_round
|
||||
isXposedModuleActive -> R.drawable.bg_green_round
|
||||
else -> R.drawable.bg_dark_round
|
||||
}
|
||||
)
|
||||
binding.mainImgStatus.setImageResource(
|
||||
when {
|
||||
isXposedModuleActive -> R.mipmap.ic_success
|
||||
else -> R.mipmap.ic_warn
|
||||
}
|
||||
)
|
||||
binding.mainTextStatus.text =
|
||||
when {
|
||||
isXposedModuleActive && !isModuleAction &&
|
||||
!modulePrefs.getBoolean(ENABLE_MODULE, default = true) -> "模块已停用"
|
||||
isXposedModuleActive && !isModuleAction -> "模块已激活,请重启系统界面"
|
||||
isXposedModuleActive && !isModuleValied -> "模块已更新,请重启系统界面"
|
||||
isXposedModuleActive -> "模块已激活"
|
||||
else -> "模块未激活"
|
||||
}
|
||||
binding.mainTextApiWay.isVisible = isXposedModuleActive
|
||||
binding.mainTextApiWay.text = "Activate by ${YukiHookModuleStatus.executorName} API ${YukiHookModuleStatus.executorVersion}"
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
/** 刷新模块状态 */
|
||||
refreshModuleStatus()
|
||||
/** 发送广播检查模块激活状态 */
|
||||
sendBroadcast(Intent().apply {
|
||||
action = Const.MODULE_CHECKING_RECEIVER
|
||||
putExtra(Const.MODULE_VERSION_VERIFY_TAG, Const.MODULE_VERSION_VERIFY)
|
||||
})
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
/** 取消注册广播 */
|
||||
unregisterReceiver(hostReceiver)
|
||||
}
|
||||
|
||||
/** 宿主广播接收器 */
|
||||
private val hostReceiver by lazy {
|
||||
object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
isModuleAction = intent?.getBooleanExtra("isAction", false) ?: false
|
||||
isModuleValied = intent?.getBooleanExtra("isValied", false) ?: false
|
||||
refreshModuleStatus()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -32,7 +32,7 @@ import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.drawable.Icon
|
||||
import android.os.Build
|
||||
import com.fankes.coloros.notify.application.CNNApplication.Companion.MODULE_PACKAGE_NAME
|
||||
import com.fankes.coloros.notify.const.Const
|
||||
import com.fankes.coloros.notify.hook.HookEntry
|
||||
import com.fankes.coloros.notify.utils.factory.bitmap
|
||||
import com.fankes.coloros.notify.utils.factory.findAppIcon
|
||||
@@ -132,8 +132,8 @@ object IconAdaptationTool {
|
||||
context, packageName.hashCode(),
|
||||
Intent().apply {
|
||||
component = ComponentName(
|
||||
MODULE_PACKAGE_NAME,
|
||||
"$MODULE_PACKAGE_NAME.ui.activity.ConfigureActivity"
|
||||
Const.MODULE_PACKAGE_NAME,
|
||||
"${Const.MODULE_PACKAGE_NAME}.ui.activity.ConfigureActivity"
|
||||
)
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
}.apply {
|
||||
|
@@ -58,7 +58,10 @@ object SystemUITool {
|
||||
* 刷新系统界面状态栏与通知图标
|
||||
* @param context 实例
|
||||
*/
|
||||
fun refreshSystemUI(context: Context) = IconRuleManagerTool.refreshSystemUI(context)
|
||||
fun refreshSystemUI(context: Context) =
|
||||
if (isXposedModuleActive)
|
||||
IconRuleManagerTool.refreshSystemUI(context)
|
||||
else context.snake(msg = "模块没有激活,更改不会生效")
|
||||
|
||||
/**
|
||||
* 显示需要重启系统界面的 [Snackbar]
|
||||
|
@@ -87,6 +87,8 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:ellipsize="end"
|
||||
android:singleLine="true"
|
||||
android:text="模块未激活"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="18sp" />
|
||||
@@ -137,6 +139,19 @@
|
||||
android:text="系统版本:%1"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="13sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/main_text_api_way"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5dp"
|
||||
android:alpha="0.6"
|
||||
android:ellipsize="end"
|
||||
android:singleLine="true"
|
||||
android:text="%1"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="11sp"
|
||||
android:visibility="gone" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
|
Reference in New Issue
Block a user