Modify change hideOrShowLauncherIcon in a hard-code way

This commit is contained in:
2022-09-28 20:29:04 +08:00
parent 06ef371f82
commit 2e4bc3e802
3 changed files with 26 additions and 10 deletions

View File

@@ -25,7 +25,6 @@ import com.highcapable.yukihookapi.hook.xposed.prefs.data.PrefsData
object DataConst {
val ENABLE_HIDE_ICON = PrefsData("_hide_icon", false)
val ENABLE_RUN_INFO = PrefsData("_tip_run_info", false)
val ENABLE_NOTIFY_TIP = PrefsData("_tip_in_notify", true)
val ENABLE_SETTING_TIP = PrefsData("_tip_in_setting", true)

View File

@@ -23,8 +23,6 @@
package com.fankes.tsbattery.ui.activity
import android.content.ComponentName
import android.content.pm.PackageManager
import android.view.HapticFeedbackConstants
import androidx.core.view.isVisible
import com.fankes.tsbattery.BuildConfig
@@ -152,11 +150,11 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
it.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP)
}
/** 获取 Sp 存储的信息 */
binding.hideIconInLauncherSwitch.isChecked = isLauncherIconShowing.not()
binding.qqtimProtectModeSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_QQTIM_WHITE_MODE)
binding.qqTimCoreServiceSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_QQTIM_CORESERVICE_BAN)
binding.qqTimCoreServiceKnSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_QQTIM_CORESERVICE_CHILD_BAN)
binding.wechatDisableHookSwitch.isChecked = modulePrefs.get(DataConst.DISABLE_WECHAT_HOOK)
binding.hideIconInLauncherSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_HIDE_ICON)
binding.notifyModuleInfoSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_RUN_INFO)
binding.notifyNotifyTipSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_NOTIFY_TIP)
binding.settingModuleTipSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_SETTING_TIP)
@@ -180,12 +178,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
}
binding.hideIconInLauncherSwitch.setOnCheckedChangeListener { btn, b ->
if (btn.isPressed.not()) return@setOnCheckedChangeListener
modulePrefs.put(DataConst.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
)
hideOrShowLauncherIcon(b)
}
binding.notifyModuleInfoSwitch.setOnCheckedChangeListener { btn, b ->
if (btn.isPressed.not()) return@setOnCheckedChangeListener

View File

@@ -24,6 +24,7 @@
package com.fankes.tsbattery.utils.factory
import android.app.Activity
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.pm.PackageInfo
@@ -35,6 +36,7 @@ import android.net.Uri
import android.provider.Settings
import android.widget.Toast
import androidx.core.content.getSystemService
import com.fankes.tsbattery.BuildConfig
import com.google.android.material.snackbar.Snackbar
import com.highcapable.yukihookapi.hook.xposed.application.ModuleApplication.Companion.appContext
@@ -178,3 +180,25 @@ fun Context.openBrowser(url: String, packageName: String = "") = runCatching {
else snake(msg = "启动系统浏览器失败")
}
/**
* 隐藏或显示启动器图标
*
* - 你可能需要 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