From fa2aa675d06b458a74169d9ed25b61636f3b0b14 Mon Sep 17 00:00:00 2001 From: fankesyooni Date: Thu, 6 Oct 2022 03:28:07 +0800 Subject: [PATCH] Modify change hideOrShowLauncherIcon in a hard-code way --- .../fankes/coloros/notify/data/DataConst.kt | 1 - .../notify/ui/activity/MainActivity.kt | 18 ++++------- .../notify/utils/factory/FunctionFactory.kt | 32 ++++++++++++++++--- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/fankes/coloros/notify/data/DataConst.kt b/app/src/main/java/com/fankes/coloros/notify/data/DataConst.kt index 3e1a939..6204b1f 100644 --- a/app/src/main/java/com/fankes/coloros/notify/data/DataConst.kt +++ b/app/src/main/java/com/fankes/coloros/notify/data/DataConst.kt @@ -30,7 +30,6 @@ object DataConst { val ENABLE_MODULE = PrefsData("_enable_module", true) val ENABLE_MODULE_LOG = PrefsData("_enable_module_log", false) - val ENABLE_HIDE_ICON = PrefsData("_hide_icon", false) val ENABLE_ANDROID12_STYLE = PrefsData("_notify_android12_style", isUpperOfAndroidS) val ENABLE_NOTIFY_ICON_FIX = PrefsData("_notify_icon_fix", true) val ENABLE_NOTIFY_ICON_FORCE_APP_ICON = PrefsData("_notify_icon_force_app_icon", false) diff --git a/app/src/main/java/com/fankes/coloros/notify/ui/activity/MainActivity.kt b/app/src/main/java/com/fankes/coloros/notify/ui/activity/MainActivity.kt index 537b3ed..ec182f7 100644 --- a/app/src/main/java/com/fankes/coloros/notify/ui/activity/MainActivity.kt +++ b/app/src/main/java/com/fankes/coloros/notify/ui/activity/MainActivity.kt @@ -24,8 +24,6 @@ package com.fankes.coloros.notify.ui.activity -import android.content.ComponentName -import android.content.pm.PackageManager import android.widget.SeekBar import android.widget.SeekBar.OnSeekBarChangeListener import androidx.core.view.isVisible @@ -140,7 +138,6 @@ class MainActivity : BaseActivity() { binding.notifyMediaPanelAutoExpSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_NOTIFY_MEDIA_PANEL_AUTO_EXP) binding.moduleEnableSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_MODULE) binding.moduleEnableLogSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_MODULE_LOG) - binding.hideIconInLauncherSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_HIDE_ICON) binding.notifyIconFixSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX) binding.notifyIconForceAppIconSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FORCE_APP_ICON) binding.notifyIconFixNotifySwitch.isChecked = modulePrefs.get(DataConst.ENABLE_NOTIFY_ICON_FIX_NOTIFY) @@ -170,15 +167,6 @@ class MainActivity : BaseActivity() { modulePrefs.put(DataConst.ENABLE_MODULE_LOG, b) SystemUITool.showNeedRestartSnake(context = this) } - binding.hideIconInLauncherSwitch.setOnCheckedChangeListener { btn, b -> - if (btn.isPressed.not()) return@setOnCheckedChangeListener - modulePrefs.put(DataConst.ENABLE_HIDE_ICON, b) - packageManager.setComponentEnabledSetting( - ComponentName(packageName, "com.fankes.coloros.notify.Home"), - if (b) PackageManager.COMPONENT_ENABLED_STATE_DISABLED else PackageManager.COMPONENT_ENABLED_STATE_ENABLED, - PackageManager.DONT_KILL_APP - ) - } binding.notifyIconFixSwitch.setOnCheckedChangeListener { btn, b -> if (btn.isPressed.not()) return@setOnCheckedChangeListener modulePrefs.put(DataConst.ENABLE_NOTIFY_ICON_FIX, b) @@ -274,6 +262,12 @@ class MainActivity : BaseActivity() { override fun onStartTrackingTouch(seekBar: SeekBar?) {} }) + /** 设置桌面图标显示隐藏 */ + binding.hideIconInLauncherSwitch.isChecked = isLauncherIconShowing.not() + binding.hideIconInLauncherSwitch.setOnCheckedChangeListener { btn, b -> + if (btn.isPressed.not()) return@setOnCheckedChangeListener + hideOrShowLauncherIcon(b) + } /** 通知图标优化名单按钮点击事件 */ binding.notifyIconFixButton.setOnClickListener { navigate() } /** 自动更新在线规则修改时间按钮点击事件 */ diff --git a/app/src/main/java/com/fankes/coloros/notify/utils/factory/FunctionFactory.kt b/app/src/main/java/com/fankes/coloros/notify/utils/factory/FunctionFactory.kt index 211ed61..42a310c 100644 --- a/app/src/main/java/com/fankes/coloros/notify/utils/factory/FunctionFactory.kt +++ b/app/src/main/java/com/fankes/coloros/notify/utils/factory/FunctionFactory.kt @@ -28,12 +28,10 @@ import android.app.Activity import android.app.Notification import android.app.Service import android.app.WallpaperManager -import android.content.ClipData -import android.content.ClipboardManager -import android.content.Context -import android.content.Intent +import android.content.* import android.content.pm.ApplicationInfo import android.content.pm.PackageInfo +import android.content.pm.PackageManager import android.content.pm.PackageManager.PackageInfoFlags import android.content.res.Configuration import android.content.res.Resources @@ -54,6 +52,7 @@ import androidx.core.app.NotificationManagerCompat import androidx.core.content.getSystemService import androidx.core.content.pm.PackageInfoCompat import androidx.core.content.res.ResourcesCompat +import com.fankes.coloros.notify.BuildConfig import com.google.android.material.snackbar.Snackbar import com.highcapable.yukihookapi.hook.factory.field import com.highcapable.yukihookapi.hook.factory.hasClass @@ -504,4 +503,27 @@ fun Long.stampToDate(format: String = "yyyy-MM-dd HH:mm:ss") = fun Any?.delayedRun(ms: Long = 150, it: () -> Unit) = runInSafe { @Suppress("DEPRECATION") Handler().postDelayed({ it() }, ms) -} \ No newline at end of file +} + +/** + * 隐藏或显示启动器图标 + * + * - 你可能需要 LSPosed 的最新版本以开启高版本系统中隐藏 APP 桌面图标功能 + * @param isShow 是否显示 + */ +fun Context.hideOrShowLauncherIcon(isShow: Boolean) { + packageManager?.setComponentEnabledSetting( + ComponentName(packageName, "${BuildConfig.APPLICATION_ID}.Home"), + if (isShow) PackageManager.COMPONENT_ENABLED_STATE_DISABLED else PackageManager.COMPONENT_ENABLED_STATE_ENABLED, + PackageManager.DONT_KILL_APP + ) +} + +/** + * 获取启动器图标状态 + * @return [Boolean] 是否显示 + */ +val Context.isLauncherIconShowing + get() = packageManager?.getComponentEnabledSetting( + ComponentName(packageName, "${BuildConfig.APPLICATION_ID}.Home") + ) != PackageManager.COMPONENT_ENABLED_STATE_DISABLED \ No newline at end of file