mirror of
https://github.com/fankes/MIUINativeNotifyIcon.git
synced 2025-09-05 18:25:23 +08:00
Merge code
This commit is contained in:
@@ -249,26 +249,10 @@ class SystemUIHooker : YukiBaseHooker() {
|
||||
private fun StatusBarNotification.compatPushingIcon(context: Context, iconDrawable: Drawable) = safeOf(iconDrawable) {
|
||||
/** 给 MIPUSH 设置 APP 自己的图标 */
|
||||
if (isXmsf && opPkgName.isNotBlank())
|
||||
findAppIcon(context)
|
||||
context.findAppIcon(xmsfPkgName) ?: iconDrawable
|
||||
else iconDrawable
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取推送通知的应用名称
|
||||
* @param context 实例
|
||||
* @return [String]
|
||||
*/
|
||||
private fun StatusBarNotification.findAppName(context: Context) = context.findAppName(opPkgName)
|
||||
|
||||
/**
|
||||
* 获取通知栏、状态栏 APP 图标
|
||||
* @param context 实例
|
||||
* @return [Drawable] 适配的图标
|
||||
*/
|
||||
private fun StatusBarNotification.findAppIcon(context: Context) = safeOf(notification.smallIcon.loadDrawable(context)) {
|
||||
context.packageManager.getPackageInfo(opPkgName, 0).applicationInfo.loadIcon(context.packageManager)
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印日志
|
||||
* @param tag 标识
|
||||
@@ -285,7 +269,7 @@ class SystemUIHooker : YukiBaseHooker() {
|
||||
isGrayscale: Boolean
|
||||
) {
|
||||
if (prefs.getBoolean(ENABLE_MODULE_LOG)) loggerD(
|
||||
msg = "$tag --> [${expandedNf?.findAppName(context)}][${expandedNf?.opPkgName}] " +
|
||||
msg = "$tag --> [${context.findAppName(name = expandedNf?.compatOpPkgName ?: "")}][${expandedNf?.opPkgName}] " +
|
||||
"custom [$isCustom] " +
|
||||
"grayscale [$isGrayscale] " +
|
||||
"xmsf [${expandedNf?.isXmsf}]"
|
||||
@@ -399,7 +383,7 @@ class SystemUIHooker : YukiBaseHooker() {
|
||||
expandedNf?.also { notifyInstance ->
|
||||
/** 判断是 MIUI 样式就停止 Hook */
|
||||
if (context.isMiuiNotifyStyle) {
|
||||
it(notifyInstance.findAppIcon(context), true)
|
||||
it(context.findAppIcon(notifyInstance.compatOpPkgName) ?: iconDrawable, true)
|
||||
return@runInSafe
|
||||
}
|
||||
/** 判断是否不是灰度图标 */
|
||||
|
@@ -34,6 +34,7 @@ import android.content.pm.PackageInfo
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.*
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.net.ConnectivityManager
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
@@ -42,7 +43,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.miui.notify.application.MNNApplication.Companion.appContext
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.highcapable.yukihookapi.hook.factory.classOf
|
||||
@@ -228,15 +228,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.miui.notify.const.Const
|
||||
import com.fankes.miui.notify.hook.HookEntry
|
||||
import com.fankes.miui.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