1 Commits
1.66 ... 1.67

3 changed files with 18 additions and 8 deletions

View File

@@ -2,7 +2,7 @@
![Eclipse Marketplace](https://img.shields.io/badge/build-passing-brightgreen) ![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/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)
<br/><br/> <br/><br/>
<img src="https://github.com/fankes/MIUINativeNotifyIcon/blob/master/app/src/main/ic_launcher-playstore.png" width = "100" height = "100"/> <img src="https://github.com/fankes/MIUINativeNotifyIcon/blob/master/app/src/main/ic_launcher-playstore.png" width = "100" height = "100"/>
<br/> <br/>
@@ -12,7 +12,7 @@ Fix the native notification bar icon function abandoned by the MIUI development
# 开始使用 # 开始使用
点击下载最新版本 点击下载最新版本
<a href='https://github.com/fankes/MIUINativeNotifyIcon/releases'>![Eclipse Marketplace](https://img.shields.io/badge/download-v1.66-green)</a> <a href='https://github.com/fankes/MIUINativeNotifyIcon/releases'>![Eclipse Marketplace](https://img.shields.io/badge/download-v1.67-green)</a>
<br/><br/> <br/><br/>
⚠️ 适配说明<br/> ⚠️ 适配说明<br/>

View File

@@ -23,7 +23,10 @@
package com.fankes.miui.notify.utils package com.fankes.miui.notify.utils
import android.graphics.* import android.graphics.*
import android.graphics.drawable.AnimationDrawable
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.graphics.drawable.VectorDrawable
import android.util.ArrayMap import android.util.ArrayMap
import androidx.core.graphics.drawable.toBitmap import androidx.core.graphics.drawable.toBitmap
import kotlin.math.abs import kotlin.math.abs
@@ -49,14 +52,21 @@ object BitmapCompatTool {
* @param drawable 要判断的 [Drawable] * @param drawable 要判断的 [Drawable]
* @return [Boolean] 是否灰度 * @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] 是否为灰度位图 * 判断 [Bitmap] 是否为灰度位图
* @param bitmap 要判断的位图 * @param bitmap 要判断的位图
* @return [Boolean] 是否灰度 * @return [Boolean] 是否灰度
*/ */
private fun isGrayscale(bitmap: Bitmap) = private fun isGrayscaleBitmap(bitmap: Bitmap) =
cachedBitmapGrayscales[bitmap.generationId] ?: let { cachedBitmapGrayscales[bitmap.generationId] ?: let {
var height = bitmap.height var height = bitmap.height
var width = bitmap.width var width = bitmap.width
@@ -77,7 +87,7 @@ object BitmapCompatTool {
ensureBufferSize(size) ensureBufferSize(size)
tempCompactBitmap?.getPixels(tempBuffer, 0, width, 0, 0, width, height) tempCompactBitmap?.getPixels(tempBuffer, 0, width, 0, 0, width, height)
for (i in 0 until size) for (i in 0 until size)
if (!isGrayscale(tempBuffer[i])) { if (!isGrayscaleColor(tempBuffer[i])) {
cachedBitmapGrayscales[bitmap.generationId] = false cachedBitmapGrayscales[bitmap.generationId] = false
return@let false return@let false
} }
@@ -90,7 +100,7 @@ object BitmapCompatTool {
* @param color 颜色 * @param color 颜色
* @return [Boolean] 是否灰度 * @return [Boolean] 是否灰度
*/ */
private fun isGrayscale(color: Int): Boolean { private fun isGrayscaleColor(color: Int): Boolean {
if (color shr 24 and 255 < 50) return true if (color shr 24 and 255 < 50) return true
val r = color shr 16 and 255 val r = color shr 16 and 255
val g = color shr 8 and 255 val g = color shr 8 and 255

View File

@@ -5,8 +5,8 @@ plugins {
} }
ext { ext {
appVersionName = "1.66" appVersionName = "1.67"
appVersionCode = 13 appVersionCode = 14
} }
task clean(type: Delete) { task clean(type: Delete) {