diff --git a/app/src/main/java/com/fankes/miui/notify/hook/HookMain.kt b/app/src/main/java/com/fankes/miui/notify/hook/HookMain.kt index 9f984da9..d68ad3c8 100644 --- a/app/src/main/java/com/fankes/miui/notify/hook/HookMain.kt +++ b/app/src/main/java/com/fankes/miui/notify/hook/HookMain.kt @@ -99,6 +99,14 @@ class HookMain : IXposedHookLoadPackage { } } + /** 仅作用于替换的 Hook 方法体 */ + @Suppress("unused") + private val replaceToFalse = object : XC_MethodReplacement() { + override fun replaceHookedMethod(param: MethodHookParam?): Any { + return false + } + } + /** * 忽略异常运行 * @param error 错误信息 @@ -248,7 +256,7 @@ class HookMain : IXposedHookLoadPackage { } /** - * - 这个是修复彩色图标的关键核心代码判断 + * - ⚡这个是修复彩色图标的关键核心代码判断 * * 判断是否为灰度图标 - 反射执行系统方法 * @param context 实例 @@ -642,8 +650,12 @@ class HookMain : IXposedHookLoadPackage { isAccessible = true }[param.thisObject] as? StatusBarNotification? - /** 强制设置图标 - 防止 MIPUSH 不生效 */ - if (lpparam.hasIgnoreStatusBarIconColor() || !lpparam.isShowMiuiStyle()) + /** + * 强制设置图标 - 防止 MIPUSH 不生效 + * 由于之前版本没有 [hasIgnoreStatusBarIconColor] 判断 - MIPUSH 的图标颜色也是白色的 + * 所以之前的版本取消这个 Hook - 实在找不到设置图标的地方 - 状态栏图标就彩色吧 + */ + if (lpparam.hasIgnoreStatusBarIconColor()) lpparam.hookSmallIconOnSet( context = iconImageView.context, expandedNf, diff --git a/app/src/main/java/com/fankes/miui/notify/ui/ConfigureActivity.kt b/app/src/main/java/com/fankes/miui/notify/ui/ConfigureActivity.kt index be62b504..c1c59488 100644 --- a/app/src/main/java/com/fankes/miui/notify/ui/ConfigureActivity.kt +++ b/app/src/main/java/com/fankes/miui/notify/ui/ConfigureActivity.kt @@ -37,6 +37,7 @@ import com.fankes.miui.notify.R import com.fankes.miui.notify.hook.HookMedium import com.fankes.miui.notify.params.IconPackParams import com.fankes.miui.notify.ui.base.BaseActivity +import com.fankes.miui.notify.utils.SystemUITool import com.fankes.miui.notify.view.MaterialSwitch class ConfigureActivity : BaseActivity() { @@ -92,11 +93,13 @@ class ConfigureActivity : BaseActivity() { if (!btn.isPressed) return@setOnCheckedChangeListener HookMedium.putAppNotifyHookOf(it, b) holder.switchAll.isEnabled = b + SystemUITool.showNeedRestartSnake(context = this@ConfigureActivity) } holder.switchAll.isChecked = HookMedium.isAppNotifyHookAllOf(it) holder.switchAll.setOnCheckedChangeListener { btn, b -> if (!btn.isPressed) return@setOnCheckedChangeListener HookMedium.putAppNotifyHookAllOf(it, b) + SystemUITool.showNeedRestartSnake(context = this@ConfigureActivity) } } return cView!! diff --git a/app/src/main/java/com/fankes/miui/notify/ui/MainActivity.kt b/app/src/main/java/com/fankes/miui/notify/ui/MainActivity.kt index 5892ee2a..5e85c5d4 100644 --- a/app/src/main/java/com/fankes/miui/notify/ui/MainActivity.kt +++ b/app/src/main/java/com/fankes/miui/notify/ui/MainActivity.kt @@ -108,6 +108,8 @@ class MainActivity : BaseActivity() { val hideIconInLauncherSwitch = findViewById(R.id.hide_icon_in_launcher_switch) val colorIconHookSwitch = findViewById(R.id.color_icon_fix_switch) val notifyIconHookSwitch = findViewById(R.id.notify_icon_fix_switch) + /** 设置旧版本警告 */ + findViewById(R.id.config_notify_app_icon_warn).isVisible = miuiVersion == "12" /** 获取 Sp 存储的信息 */ notifyIconConfigItem.isVisible = getBoolean(HookMedium.ENABLE_COLOR_ICON_HOOK, default = true) moduleEnableLogSwitch.isVisible = getBoolean(HookMedium.ENABLE_MODULE, default = true) @@ -120,10 +122,12 @@ class MainActivity : BaseActivity() { if (!btn.isPressed) return@setOnCheckedChangeListener putBoolean(HookMedium.ENABLE_MODULE, b) moduleEnableLogSwitch.isVisible = b + SystemUITool.showNeedRestartSnake(context = this) } moduleEnableLogSwitch.setOnCheckedChangeListener { btn, b -> if (!btn.isPressed) return@setOnCheckedChangeListener putBoolean(HookMedium.ENABLE_MODULE_LOG, b) + SystemUITool.showNeedRestartSnake(context = this) } hideIconInLauncherSwitch.setOnCheckedChangeListener { btn, b -> if (!btn.isPressed) return@setOnCheckedChangeListener @@ -138,21 +142,15 @@ class MainActivity : BaseActivity() { if (!btn.isPressed) return@setOnCheckedChangeListener putBoolean(HookMedium.ENABLE_COLOR_ICON_HOOK, b) notifyIconConfigItem.isVisible = b + SystemUITool.showNeedRestartSnake(context = this) } notifyIconHookSwitch.setOnCheckedChangeListener { btn, b -> if (!btn.isPressed) return@setOnCheckedChangeListener putBoolean(HookMedium.ENABLE_NOTIFY_ICON_HOOK, b) + SystemUITool.showNeedRestartSnake(context = this) } /** 重启按钮点击事件 */ - findViewById(R.id.title_restart_icon).setOnClickListener { - showDialog { - title = "重启系统界面" - msg = "你确定要立即重启系统界面吗?\n\n" + - "部分 MIUI 系统使用了状态栏主题可能会发生主题失效的情况,这种情况请再重启一次即可。" - confirmButton { restartSystemUI() } - cancelButton() - } - } + findViewById(R.id.title_restart_icon).setOnClickListener { SystemUITool.restartSystemUI(context = this) } /** 通知图标优化名单按钮点击事件 */ findViewById(R.id.config_notify_app_button).setOnClickListener { startActivity(Intent(this, ConfigureActivity::class.java)) @@ -206,14 +204,6 @@ class MainActivity : BaseActivity() { */ private fun isHooked() = HookMedium.isHooked() - /** 重启系统界面 */ - private fun restartSystemUI() = - execShellSu(cmd = "pgrep systemui").also { pid -> - if (pid.isNotBlank()) - execShellSu(cmd = "kill -9 $pid") - else Toast.makeText(this, "ROOT 权限获取失败", Toast.LENGTH_SHORT).show() - } - /** * 获取保存的值 * @param key 名称 diff --git a/app/src/main/java/com/fankes/miui/notify/utils/SystemUITool.kt b/app/src/main/java/com/fankes/miui/notify/utils/SystemUITool.kt new file mode 100644 index 00000000..45c14051 --- /dev/null +++ b/app/src/main/java/com/fankes/miui/notify/utils/SystemUITool.kt @@ -0,0 +1,63 @@ +/** + * Copyright (C) 2022. Fankes Studio(qzmmcn@163.com) + * + * This file is part of MIUINativeNotifyIcon. + * + * MIUINativeNotifyIcon 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. + * + * MIUINativeNotifyIcon 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 . + * + * This file is Created by fankes on 2022/02/08. + */ +package com.fankes.miui.notify.utils + +import android.app.Activity +import android.content.Context +import android.graphics.Color +import android.widget.Toast +import com.google.android.material.snackbar.Snackbar + +/** + * 系统界面工具 + */ +object SystemUITool { + + /** + * 重启系统界面 + * @param context 实例 + */ + fun restartSystemUI(context: Context) = + context.showDialog { + title = "重启系统界面" + msg = "你确定要立即重启系统界面吗?\n\n" + + "部分 MIUI 系统使用了状态栏主题可能会发生主题失效的情况,这种情况请再重启一次即可。" + confirmButton { + execShellSu(cmd = "pgrep systemui").also { pid -> + if (pid.isNotBlank()) + execShellSu(cmd = "kill -9 $pid") + else Toast.makeText(context, "ROOT 权限获取失败", Toast.LENGTH_SHORT).show() + } + } + cancelButton() + } + + /** + * 显示需要重启系统界面的 [Snackbar] + * @param context 实例 + */ + fun showNeedRestartSnake(context: Context) = + Snackbar.make((context as Activity).findViewById(android.R.id.content), "设置需要重启系统界面才能生效", Snackbar.LENGTH_LONG) + .apply { + setActionTextColor(Color.WHITE) + setAction("立即重启") { restartSystemUI(context) } + }.show() +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 5f17592a..a40650f6 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -32,11 +32,13 @@ + android:tint="@color/colorTextGray" + android:tooltipText="重启系统界面" /> + +