mirror of
https://github.com/fankes/ColorOSNotifyIcon.git
synced 2025-09-07 03:05:44 +08:00
Merge code
This commit is contained in:
@@ -27,14 +27,13 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.graphics.Outline
|
|
||||||
import android.graphics.drawable.BitmapDrawable
|
import android.graphics.drawable.BitmapDrawable
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.graphics.drawable.Icon
|
import android.graphics.drawable.Icon
|
||||||
import android.graphics.drawable.VectorDrawable
|
import android.graphics.drawable.VectorDrawable
|
||||||
import android.service.notification.StatusBarNotification
|
import android.service.notification.StatusBarNotification
|
||||||
|
import android.util.ArraySet
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewOutlineProvider
|
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import androidx.core.graphics.drawable.toBitmap
|
import androidx.core.graphics.drawable.toBitmap
|
||||||
import com.fankes.coloros.notify.application.CNNApplication.Companion.MODULE_PACKAGE_NAME
|
import com.fankes.coloros.notify.application.CNNApplication.Companion.MODULE_PACKAGE_NAME
|
||||||
@@ -62,10 +61,12 @@ import com.highcapable.yukihookapi.hook.factory.encase
|
|||||||
import com.highcapable.yukihookapi.hook.factory.field
|
import com.highcapable.yukihookapi.hook.factory.field
|
||||||
import com.highcapable.yukihookapi.hook.factory.method
|
import com.highcapable.yukihookapi.hook.factory.method
|
||||||
import com.highcapable.yukihookapi.hook.log.loggerD
|
import com.highcapable.yukihookapi.hook.log.loggerD
|
||||||
|
import com.highcapable.yukihookapi.hook.log.loggerE
|
||||||
import com.highcapable.yukihookapi.hook.log.loggerW
|
import com.highcapable.yukihookapi.hook.log.loggerW
|
||||||
import com.highcapable.yukihookapi.hook.param.PackageParam
|
import com.highcapable.yukihookapi.hook.param.PackageParam
|
||||||
import com.highcapable.yukihookapi.hook.type.android.*
|
import com.highcapable.yukihookapi.hook.type.android.*
|
||||||
import com.highcapable.yukihookapi.hook.type.java.BooleanType
|
import com.highcapable.yukihookapi.hook.type.java.BooleanType
|
||||||
|
import com.highcapable.yukihookapi.hook.type.java.FloatType
|
||||||
import com.highcapable.yukihookapi.hook.type.java.IntType
|
import com.highcapable.yukihookapi.hook.type.java.IntType
|
||||||
import com.highcapable.yukihookapi.hook.type.java.LongType
|
import com.highcapable.yukihookapi.hook.type.java.LongType
|
||||||
import com.highcapable.yukihookapi.hook.xposed.proxy.YukiHookXposedInitProxy
|
import com.highcapable.yukihookapi.hook.xposed.proxy.YukiHookXposedInitProxy
|
||||||
@@ -108,6 +109,18 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
"com.coloros.systemui.statusbar.policy.SystemPromptController"
|
"com.coloros.systemui.statusbar.policy.SystemPromptController"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/** 根据多个版本存在不同的包名相同的类 */
|
||||||
|
private val RoundRectDrawableUtilClass = VariousClass(
|
||||||
|
"com.oplusos.systemui.notification.util.RoundRectDrawableUtil",
|
||||||
|
"com.coloros.systemui.notification.util.RoundRectDrawableUtil"
|
||||||
|
)
|
||||||
|
|
||||||
|
/** 根据多个版本存在不同的包名相同的类 */
|
||||||
|
private val RoundRectDrawableUtil_CompanionClass = VariousClass(
|
||||||
|
"com.oplusos.systemui.notification.util.RoundRectDrawableUtil\$Companion",
|
||||||
|
"com.oplusos.systemui.notification.util.RoundRectDrawableUtil\$Companion"
|
||||||
|
)
|
||||||
|
|
||||||
/** 根据多个版本存在不同的包名相同的类 */
|
/** 根据多个版本存在不同的包名相同的类 */
|
||||||
private val DndAlertHelperClass = VariousClass(
|
private val DndAlertHelperClass = VariousClass(
|
||||||
"com.oplusos.systemui.notification.helper.DndAlertHelper",
|
"com.oplusos.systemui.notification.helper.DndAlertHelper",
|
||||||
@@ -149,7 +162,7 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
private var iconDatas = ArrayList<IconDataBean>()
|
private var iconDatas = ArrayList<IconDataBean>()
|
||||||
|
|
||||||
/** 缓存的状态栏小图标实例 */
|
/** 缓存的状态栏小图标实例 */
|
||||||
private var statusBarIconViews = HashSet<ImageView>()
|
private var statusBarIconViews = ArraySet<ImageView>()
|
||||||
|
|
||||||
/** 缓存的通知小图标包装纸实例 */
|
/** 缓存的通知小图标包装纸实例 */
|
||||||
private var notificationViewWrappers = HashSet<Any>()
|
private var notificationViewWrappers = HashSet<Any>()
|
||||||
@@ -195,36 +208,49 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
* @param view 实例
|
* @param view 实例
|
||||||
*/
|
*/
|
||||||
private fun PackageParam.registerWallpaperColorChanged(view: View) = runInSafe {
|
private fun PackageParam.registerWallpaperColorChanged(view: View) = runInSafe {
|
||||||
if (isUpperOfAndroidS && !isWallpaperColorListenerSetUp)
|
if (!isWallpaperColorListenerSetUp && isUpperOfAndroidS) view.apply {
|
||||||
WallpaperManager.getInstance(view.context).addOnColorsChangedListener({ _, _ -> refreshNotificationIcons() }, view.handler)
|
WallpaperManager.getInstance(context).addOnColorsChangedListener({ _, _ -> refreshNotificationIcons() }, handler)
|
||||||
|
}
|
||||||
isWallpaperColorListenerSetUp = true
|
isWallpaperColorListenerSetUp = true
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 刷新状态栏小图标 */
|
/** 刷新状态栏小图标 */
|
||||||
private fun PackageParam.refreshStatusBarIcons() = runInSafe {
|
private fun PackageParam.refreshStatusBarIcons() = runInSafe {
|
||||||
val unknown = StatusBarIconViewClass.clazz.field { name = "mIcon" }
|
val nfField = StatusBarIconViewClass.clazz.field { name = "mNotification" }
|
||||||
val iconScaleField = StatusBarIconViewClass.clazz.field { name = "mIconScale" }
|
val sRadiusField = StatusBarIconViewClass.clazz.field { name = "sIconRadiusFraction" }
|
||||||
val methodUnused = StatusBarIconViewClass.clazz.method { name = "maybeUpdateIconScaleDimens" }
|
val sNfSizeField = StatusBarIconViewClass.clazz.field { name = "sNotificationRoundIconSize" }
|
||||||
StatusBarIconViewClass.clazz.field { name = "mNotification" }.also { result ->
|
val roundUtil = RoundRectDrawableUtil_CompanionClass.clazz.method {
|
||||||
|
name = "getRoundRectDrawable"
|
||||||
|
param(DrawableClass, FloatType, IntType, IntType, ContextClass)
|
||||||
|
}.onNoSuchMethod { loggerE(msg = "Your system not support \"getRoundRectDrawable\"!", e = it) }
|
||||||
|
.get(RoundRectDrawableUtilClass.clazz.field { name = "Companion" }.get().self)
|
||||||
|
/** 启动一个线程防止卡顿 */
|
||||||
|
Thread {
|
||||||
statusBarIconViews.takeIf { it.isNotEmpty() }?.forEach {
|
statusBarIconViews.takeIf { it.isNotEmpty() }?.forEach {
|
||||||
/** 得到通知实例 */
|
runInSafe {
|
||||||
val nf = result.of<StatusBarNotification>(it) ?: return
|
/** 得到通知实例 */
|
||||||
val base = nf.notification.smallIcon.loadDrawable(it.context)
|
val nf = nfField.of<StatusBarNotification>(it) ?: return@Thread
|
||||||
|
|
||||||
/** 刷新状态栏图标 */
|
/** 得到原始通知图标 */
|
||||||
val icon = compatStatusIcon(
|
val iconDrawable = nf.notification.smallIcon.loadDrawable(it.context)
|
||||||
context = it.context,
|
/** 获取优化后的状态栏通知图标 */
|
||||||
isGrayscaleIcon = isGrayscaleIcon(it.context, base),
|
compatStatusIcon(
|
||||||
packageName = nf.packageName,
|
context = it.context,
|
||||||
drawable = base
|
isGrayscaleIcon = isGrayscaleIcon(it.context, iconDrawable),
|
||||||
)
|
packageName = nf.packageName,
|
||||||
/** 移除诡异的间距 FIXME 间距总是有问题不知道为什么 */
|
drawable = iconDrawable
|
||||||
methodUnused.get(it).call()
|
).also { pair ->
|
||||||
// FIXME ignored this mabe bugss --> iconScaleField.get(it).set(if (icon.second) 0.75f else 0.68f)
|
/** 得到图标圆角 */
|
||||||
it.setImageDrawable(icon.first.rounded(it.context))
|
val sRadius = sRadiusField.of<Float>(it)
|
||||||
it.invalidate()
|
|
||||||
|
/** 得到缩放大小 */
|
||||||
|
val sNfSize = sNfSizeField.of<Int>(it)
|
||||||
|
/** 在主线程设置图标 */
|
||||||
|
it.post { it.setImageDrawable(roundUtil.invoke(pair.first, sRadius, sNfSize, sNfSize, it.context)) }
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 刷新通知小图标 */
|
/** 刷新通知小图标 */
|
||||||
@@ -258,7 +284,7 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
* @return [Drawable]
|
* @return [Drawable]
|
||||||
*/
|
*/
|
||||||
private fun Drawable.rounded(context: Context) =
|
private fun Drawable.rounded(context: Context) =
|
||||||
safeOf(default = this) { BitmapDrawable(context.resources, toBitmap().round(10.dpFloat(context))) }
|
safeOf(default = this) { BitmapDrawable(context.resources, toBitmap().round(20.dpFloat(context))) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自动适配状态栏、通知栏自定义小图标
|
* 自动适配状态栏、通知栏自定义小图标
|
||||||
@@ -315,14 +341,13 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
drawable: Drawable,
|
drawable: Drawable,
|
||||||
iconColor: Int,
|
iconColor: Int,
|
||||||
iconView: ImageView
|
iconView: ImageView
|
||||||
) {
|
) = runInSafe {
|
||||||
compatCustomIcon(isGrayscaleIcon, packageName).also { customPair ->
|
compatCustomIcon(isGrayscaleIcon, packageName).also { customPair ->
|
||||||
when {
|
when {
|
||||||
customPair.first != null || isGrayscaleIcon -> iconView.apply {
|
customPair.first != null || isGrayscaleIcon -> iconView.apply {
|
||||||
/** 重新设置图标 */
|
/** 重新设置图标 */
|
||||||
setImageBitmap(customPair.first ?: drawable.toBitmap())
|
setImageBitmap(customPair.first ?: drawable.toBitmap())
|
||||||
/** 设置不要裁切到边界 */
|
|
||||||
clipToOutline = false
|
|
||||||
/** 是否开启 Android 12 风格 */
|
/** 是否开启 Android 12 风格 */
|
||||||
val isA12Style = prefs.getBoolean(ENABLE_ANDROID12_STYLE, isUpperOfAndroidS)
|
val isA12Style = prefs.getBoolean(ENABLE_ANDROID12_STYLE, isUpperOfAndroidS)
|
||||||
|
|
||||||
@@ -341,6 +366,7 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
|
|
||||||
/** 新版图标着色 */
|
/** 新版图标着色 */
|
||||||
val newApplyColor = customPair.second.takeIf { it != 0 } ?: iconColor.takeIf { it != 0 } ?: a12Style
|
val newApplyColor = customPair.second.takeIf { it != 0 } ?: iconColor.takeIf { it != 0 } ?: a12Style
|
||||||
|
|
||||||
/** 判断风格并开始 Hook */
|
/** 判断风格并开始 Hook */
|
||||||
if (isA12Style) {
|
if (isA12Style) {
|
||||||
background = DrawableBuilder().rounded().solidColor(newApplyColor).build()
|
background = DrawableBuilder().rounded().solidColor(newApplyColor).build()
|
||||||
@@ -354,18 +380,7 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
}
|
}
|
||||||
else -> iconView.apply {
|
else -> iconView.apply {
|
||||||
/** 重新设置图标 */
|
/** 重新设置图标 */
|
||||||
setImageDrawable(drawable)
|
setImageDrawable(drawable.rounded(context))
|
||||||
/** 设置裁切到边界 */
|
|
||||||
clipToOutline = true
|
|
||||||
/** 设置一个圆角轮廓裁切 */
|
|
||||||
outlineProvider = object : ViewOutlineProvider() {
|
|
||||||
override fun getOutline(view: View, out: Outline) {
|
|
||||||
out.setRoundRect(
|
|
||||||
0, 0,
|
|
||||||
view.width, view.height, 3.dpFloat(context)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/** 清除图标间距 */
|
/** 清除图标间距 */
|
||||||
setPadding(0, 0, 0, 0)
|
setPadding(0, 0, 0, 0)
|
||||||
/** 清除背景 */
|
/** 清除背景 */
|
||||||
@@ -509,17 +524,6 @@ class HookEntry : YukiHookXposedInitProxy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
injectMember {
|
|
||||||
method {
|
|
||||||
name = "onConfigurationChanged"
|
|
||||||
param(ConfigurationClass)
|
|
||||||
}
|
|
||||||
intercept()
|
|
||||||
}
|
|
||||||
injectMember {
|
|
||||||
method { name = "updateIconScaleForSystemIcons" }
|
|
||||||
intercept()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/** 替换通知图标和样式 */
|
/** 替换通知图标和样式 */
|
||||||
NotificationHeaderViewWrapperClass.hook {
|
NotificationHeaderViewWrapperClass.hook {
|
||||||
|
@@ -59,8 +59,7 @@ import java.io.ByteArrayOutputStream
|
|||||||
* 系统深色模式是否开启
|
* 系统深色模式是否开启
|
||||||
* @return [Boolean] 是否开启
|
* @return [Boolean] 是否开启
|
||||||
*/
|
*/
|
||||||
val isSystemInDarkMode
|
val isSystemInDarkMode get() = appContext.isSystemInDarkMode
|
||||||
get() = (appContext.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统深色模式是否没开启
|
* 系统深色模式是否没开启
|
||||||
|
@@ -375,7 +375,7 @@ object IconRuleManagerTool {
|
|||||||
Handler().postDelayed({
|
Handler().postDelayed({
|
||||||
context.getSystemService<NotificationManager>()?.cancel(1)
|
context.getSystemService<NotificationManager>()?.cancel(1)
|
||||||
cancel()
|
cancel()
|
||||||
}, 500)
|
}, 1000)
|
||||||
noCancelable()
|
noCancelable()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -40,7 +40,7 @@ object SystemUITool {
|
|||||||
context.showDialog {
|
context.showDialog {
|
||||||
title = "重启系统界面"
|
title = "重启系统界面"
|
||||||
msg = "你确定要立即重启系统界面吗?\n\n" +
|
msg = "你确定要立即重启系统界面吗?\n\n" +
|
||||||
"部分 MIUI 系统使用了状态栏主题可能会发生主题失效的情况,这种情况请再重启一次即可。"
|
"重启过程会黑屏并等待进入锁屏重新解锁。"
|
||||||
confirmButton {
|
confirmButton {
|
||||||
execShellSu(cmd = "pgrep systemui").also { pid ->
|
execShellSu(cmd = "pgrep systemui").also { pid ->
|
||||||
if (pid.isNotBlank())
|
if (pid.isNotBlank())
|
||||||
|
@@ -398,7 +398,7 @@
|
|||||||
android:layout_marginBottom="10dp"
|
android:layout_marginBottom="10dp"
|
||||||
android:alpha="0.6"
|
android:alpha="0.6"
|
||||||
android:lineSpacingExtra="6dp"
|
android:lineSpacingExtra="6dp"
|
||||||
android:text="无论任何版本,开启后都将使用 Android 12 原生通知图标方式为通知栏推送的通知图标增加外部圆形轮廓。"
|
android:text="无论任何版本,开启后都将使用 Android 12 原生通知图标方式为通知栏推送的通知图标增加外部圆形轮廓。\n目标为 Android 12 的系统将自动使用系统主题色着色。"
|
||||||
android:textColor="@color/colorTextDark"
|
android:textColor="@color/colorTextDark"
|
||||||
android:textSize="12sp" />
|
android:textSize="12sp" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -475,7 +475,7 @@
|
|||||||
android:layout_marginBottom="10dp"
|
android:layout_marginBottom="10dp"
|
||||||
android:alpha="0.6"
|
android:alpha="0.6"
|
||||||
android:lineSpacingExtra="6dp"
|
android:lineSpacingExtra="6dp"
|
||||||
android:text="首次安装请打开名单列表从云端更新数据,后期适配的内容也请手动打开名单列表重新拉取数据以检查更新,数据更新后重启系统界面即可生效。"
|
android:text="首次安装请打开名单列表从云端更新数据,后期适配的内容也请手动打开名单列表重新拉取数据以检查更新,数据更新后无需重启系统界面,实时生效。"
|
||||||
android:textColor="@color/colorTextDark"
|
android:textColor="@color/colorTextDark"
|
||||||
android:textSize="12sp" />
|
android:textSize="12sp" />
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user