Skip to content

Commit

Permalink
加入白痴文案,修改部分设置,加入提示
Browse files Browse the repository at this point in the history
  • Loading branch information
fankes committed Feb 8, 2022
1 parent b43975e commit 60115b9
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 24 deletions.
18 changes: 15 additions & 3 deletions app/src/main/java/com/fankes/miui/notify/hook/HookMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 错误信息
Expand Down Expand Up @@ -248,7 +256,7 @@ class HookMain : IXposedHookLoadPackage {
}

/**
* - 这个是修复彩色图标的关键核心代码判断
* - 这个是修复彩色图标的关键核心代码判断
*
* 判断是否为灰度图标 - 反射执行系统方法
* @param context 实例
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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!!
Expand Down
24 changes: 7 additions & 17 deletions app/src/main/java/com/fankes/miui/notify/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ class MainActivity : BaseActivity() {
val hideIconInLauncherSwitch = findViewById<SwitchCompat>(R.id.hide_icon_in_launcher_switch)
val colorIconHookSwitch = findViewById<SwitchCompat>(R.id.color_icon_fix_switch)
val notifyIconHookSwitch = findViewById<SwitchCompat>(R.id.notify_icon_fix_switch)
/** 设置旧版本警告 */
findViewById<View>(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)
Expand All @@ -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
Expand All @@ -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<View>(R.id.title_restart_icon).setOnClickListener {
showDialog {
title = "重启系统界面"
msg = "你确定要立即重启系统界面吗?\n\n" +
"部分 MIUI 系统使用了状态栏主题可能会发生主题失效的情况,这种情况请再重启一次即可。"
confirmButton { restartSystemUI() }
cancelButton()
}
}
findViewById<View>(R.id.title_restart_icon).setOnClickListener { SystemUITool.restartSystemUI(context = this) }
/** 通知图标优化名单按钮点击事件 */
findViewById<View>(R.id.config_notify_app_button).setOnClickListener {
startActivity(Intent(this, ConfigureActivity::class.java))
Expand Down Expand Up @@ -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 名称
Expand Down
63 changes: 63 additions & 0 deletions app/src/main/java/com/fankes/miui/notify/utils/SystemUITool.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* Copyright (C) 2022. Fankes Studio([email protected])
*
* 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 <http://www.gnu.org/licenses/>.
*
* 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()
}
24 changes: 20 additions & 4 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@
<androidx.constraintlayout.utils.widget.ImageFilterView
android:id="@+id/title_restart_icon"
style="?android:attr/selectableItemBackgroundBorderless"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginEnd="5dp"
android:alpha="0.85"
android:src="@mipmap/restart"
android:tint="@color/colorTextGray" />
android:tint="@color/colorTextGray"
android:tooltipText="重启系统界面" />
</LinearLayout>

<LinearLayout
Expand Down Expand Up @@ -264,9 +266,23 @@
android:layout_marginBottom="10dp"
android:alpha="0.6"
android:lineSpacingExtra="6dp"
android:text="此选项默认开启,开启后将对优化名单内 APP 通知小图标进行色彩修复,使得它们的图标看起来更加美观"
android:text="此选项默认开启,开启后将对优化名单内 APP 通知小图标进行色彩修复,特别是通过 MIPUSH 推送的通知,它们始终是彩色的,修复后使得它们的图标看起来更加符合原生规范"
android:textColor="@color/colorTextDark"
android:textSize="12sp" />

<TextView
android:id="@+id/config_notify_app_icon_warn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="10dp"
android:alpha="0.6"
android:lineSpacingExtra="6dp"
android:text="⚠️ 由于你的系统版本过低,状态栏上 MIPUSH 的彩色图标由于不能识别反色将不会被优化为黑白小图标,仅在通知栏生效。"
android:textColor="#FF9800"
android:textSize="12sp"
android:visibility="gone" />
</LinearLayout>

<LinearLayout
Expand Down
Binary file modified app/src/main/res/mipmap-xxhdpi/restart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 60115b9

Please sign in to comment.