From 79843eb0d08dfc339259e85be8958e91a7c4c7a3 Mon Sep 17 00:00:00 2001 From: Fankesyooni Date: Sun, 20 Feb 2022 01:22:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=B8=AA=E5=BD=A9?= =?UTF-8?q?=E8=89=B2=E5=9B=BE=E6=A0=87=E5=88=A4=E6=96=AD=E5=A4=B1=E8=AF=AF?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E9=87=8D=E6=96=B0=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E7=89=88=E6=9C=AC=201.67?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- .../miui/notify/utils/BitmapCompatTool.kt | 18 ++++++++++++++---- build.gradle | 4 ++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 50f9a07..27576ec 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![Eclipse Marketplace](https://img.shields.io/badge/build-passing-brightgreen) ![Eclipse Marketplace](https://img.shields.io/badge/license-AGPL3.0-blue) -![Eclipse Marketplace](https://img.shields.io/badge/version-v1.66-green) +![Eclipse Marketplace](https://img.shields.io/badge/version-v1.67-green)


@@ -12,7 +12,7 @@ Fix the native notification bar icon function abandoned by the MIUI development # 开始使用 点击下载最新版本 -![Eclipse Marketplace](https://img.shields.io/badge/download-v1.66-green) +![Eclipse Marketplace](https://img.shields.io/badge/download-v1.67-green)

⚠️ 适配说明
diff --git a/app/src/main/java/com/fankes/miui/notify/utils/BitmapCompatTool.kt b/app/src/main/java/com/fankes/miui/notify/utils/BitmapCompatTool.kt index db3d5fd..355681d 100644 --- a/app/src/main/java/com/fankes/miui/notify/utils/BitmapCompatTool.kt +++ b/app/src/main/java/com/fankes/miui/notify/utils/BitmapCompatTool.kt @@ -23,7 +23,10 @@ package com.fankes.miui.notify.utils import android.graphics.* +import android.graphics.drawable.AnimationDrawable +import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable +import android.graphics.drawable.VectorDrawable import android.util.ArrayMap import androidx.core.graphics.drawable.toBitmap import kotlin.math.abs @@ -49,14 +52,21 @@ object BitmapCompatTool { * @param drawable 要判断的 [Drawable] * @return [Boolean] 是否灰度 */ - fun isGrayscaleDrawable(drawable: Drawable) = safeOfFalse { isGrayscale(drawable.toBitmap()) } + fun isGrayscaleDrawable(drawable: Drawable) = safeOfFalse { + when (drawable) { + is BitmapDrawable -> isGrayscaleBitmap(drawable.bitmap) + is AnimationDrawable -> !(drawable.numberOfFrames <= 0 || !isGrayscaleBitmap(drawable.getFrame(0).toBitmap())) + is VectorDrawable -> true + else -> isGrayscaleBitmap(drawable.toBitmap()) + } + } /** * 判断 [Bitmap] 是否为灰度位图 * @param bitmap 要判断的位图 * @return [Boolean] 是否灰度 */ - private fun isGrayscale(bitmap: Bitmap) = + private fun isGrayscaleBitmap(bitmap: Bitmap) = cachedBitmapGrayscales[bitmap.generationId] ?: let { var height = bitmap.height var width = bitmap.width @@ -77,7 +87,7 @@ object BitmapCompatTool { ensureBufferSize(size) tempCompactBitmap?.getPixels(tempBuffer, 0, width, 0, 0, width, height) for (i in 0 until size) - if (!isGrayscale(tempBuffer[i])) { + if (!isGrayscaleColor(tempBuffer[i])) { cachedBitmapGrayscales[bitmap.generationId] = false return@let false } @@ -90,7 +100,7 @@ object BitmapCompatTool { * @param color 颜色 * @return [Boolean] 是否灰度 */ - private fun isGrayscale(color: Int): Boolean { + private fun isGrayscaleColor(color: Int): Boolean { if (color shr 24 and 255 < 50) return true val r = color shr 16 and 255 val g = color shr 8 and 255 diff --git a/build.gradle b/build.gradle index 72540cf..bf41b32 100644 --- a/build.gradle +++ b/build.gradle @@ -5,8 +5,8 @@ plugins { } ext { - appVersionName = "1.66" - appVersionCode = 13 + appVersionName = "1.67" + appVersionCode = 14 } task clean(type: Delete) {