mirror of
https://github.com/fankes/ColorOSNotifyIcon.git
synced 2025-09-05 18:25:28 +08:00
Merge code
This commit is contained in:
@@ -221,6 +221,12 @@ class SystemUIHooker : YukiBaseHooker() {
|
||||
prefs.getBoolean(ENABLE_NOTIFY_ICON_FIX, default = true) &&
|
||||
(if (isHooking) prefs.getBoolean(ENABLE_NOTIFY_ICON_FIX_NOTIFY, default = true) else true)
|
||||
|
||||
/**
|
||||
* 判断通知是否来自系统推送
|
||||
* @return [Boolean]
|
||||
*/
|
||||
private val StatusBarNotification.isOplusPush get() = opPkg == ANDROID_PACKAGE_NAME && opPkg != packageName
|
||||
|
||||
/**
|
||||
* 打印日志
|
||||
* @param tag 标识
|
||||
@@ -321,6 +327,21 @@ class SystemUIHooker : YukiBaseHooker() {
|
||||
}.get().invoke(context)).callBoolean(drawable)
|
||||
}
|
||||
|
||||
/**
|
||||
* 适配通知栏、状态栏来自系统推送的彩色 APP 图标
|
||||
*
|
||||
* 适配第三方图标包对系统包管理器更换图标后的彩色图标
|
||||
* @param context 实例
|
||||
* @param iconDrawable 原始图标
|
||||
* @return [Drawable] 适配的图标
|
||||
*/
|
||||
private fun StatusBarNotification.compatPushingIcon(context: Context, iconDrawable: Drawable) = safeOf(iconDrawable) {
|
||||
/** 给系统推送设置 APP 自己的图标 */
|
||||
if (isOplusPush && opPkg.isNotBlank())
|
||||
context.findAppIcon(packageName) ?: iconDrawable
|
||||
else iconDrawable
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动适配状态栏、通知栏自定义小图标
|
||||
* @param isGrayscaleIcon 是否为灰度图标
|
||||
|
@@ -38,6 +38,7 @@ import android.content.res.Configuration
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.net.ConnectivityManager
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
@@ -46,7 +47,6 @@ import android.util.Base64
|
||||
import android.widget.Toast
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
import androidx.core.content.getSystemService
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import com.fankes.coloros.notify.application.CNNApplication.Companion.appContext
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.highcapable.yukihookapi.hook.factory.classOf
|
||||
@@ -179,15 +179,15 @@ val Context.versionCode get() = packageInfo.versionCode
|
||||
* @return [String]
|
||||
*/
|
||||
fun Context.findAppName(name: String) =
|
||||
safeOfNothing { packageManager.getPackageInfo(name, 0).applicationInfo.loadLabel(packageManager).toString() }
|
||||
safeOfNothing { packageManager?.getPackageInfo(name, 0)?.applicationInfo?.loadLabel(packageManager).toString() }
|
||||
|
||||
/**
|
||||
* 得到 APP 图标
|
||||
* @param name APP 包名
|
||||
* @return [Bitmap] or null
|
||||
* @return [Drawable] or null
|
||||
*/
|
||||
fun Context.findAppIcon(name: String) =
|
||||
safeOfNull { packageManager.getPackageInfo(name, 0).applicationInfo.loadIcon(packageManager).toBitmap() }
|
||||
safeOfNull { packageManager?.getPackageInfo(name, 0)?.applicationInfo?.loadIcon(packageManager) }
|
||||
|
||||
/**
|
||||
* 是否关闭了通知权限
|
||||
|
@@ -32,6 +32,7 @@ import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.drawable.Icon
|
||||
import android.os.Build
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import com.fankes.coloros.notify.const.Const
|
||||
import com.fankes.coloros.notify.hook.HookEntry
|
||||
import com.fankes.coloros.notify.utils.factory.bitmap
|
||||
@@ -126,7 +127,7 @@ object IconAdaptationTool {
|
||||
setColor(0xFF2993F0.toInt())
|
||||
setAutoCancel(true)
|
||||
setSmallIcon(Icon.createWithBitmap(smallIcon))
|
||||
setLargeIcon(context.findAppIcon(packageName))
|
||||
setLargeIcon(context.findAppIcon(packageName)?.toBitmap())
|
||||
setContentIntent(
|
||||
PendingIntent.getActivity(
|
||||
context, packageName.hashCode(),
|
||||
|
Reference in New Issue
Block a user