From 1afb68b233663eeab3771fa7296ef24a71bab6f4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 19:55:31 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/utils/BitmapUtils.kt | 2 +- app/src/main/java/io/legado/app/utils/ColorUtils.kt | 7 +++++-- app/src/main/java/io/legado/app/utils/FloatExtensions.kt | 5 ++--- app/src/main/java/io/legado/app/utils/StringExtensions.kt | 2 -- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/utils/BitmapUtils.kt b/app/src/main/java/io/legado/app/utils/BitmapUtils.kt index 00f1d4c58..14212f442 100644 --- a/app/src/main/java/io/legado/app/utils/BitmapUtils.kt +++ b/app/src/main/java/io/legado/app/utils/BitmapUtils.kt @@ -147,7 +147,7 @@ object BitmapUtils { //图片不被压缩 fun convertViewToBitmap(view: View, bitmapWidth: Int, bitmapHeight: Int): Bitmap { - val bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888) + val bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Config.ARGB_8888) view.draw(Canvas(bitmap)) return bitmap } diff --git a/app/src/main/java/io/legado/app/utils/ColorUtils.kt b/app/src/main/java/io/legado/app/utils/ColorUtils.kt index 3ca7ab5bc..9eceb6724 100644 --- a/app/src/main/java/io/legado/app/utils/ColorUtils.kt +++ b/app/src/main/java/io/legado/app/utils/ColorUtils.kt @@ -4,6 +4,9 @@ import android.graphics.Color import androidx.annotation.ColorInt import androidx.annotation.FloatRange +import kotlin.math.max +import kotlin.math.min +import kotlin.math.roundToInt @Suppress("unused") object ColorUtils { @@ -53,7 +56,7 @@ object ColorUtils { @ColorInt fun adjustAlpha(@ColorInt color: Int, @FloatRange(from = 0.0, to = 1.0) factor: Float): Int { - val alpha = Math.round(Color.alpha(color) * factor) + val alpha = (Color.alpha(color) * factor).roundToInt() val red = Color.red(color) val green = Color.green(color) val blue = Color.blue(color) @@ -62,7 +65,7 @@ object ColorUtils { @ColorInt fun withAlpha(@ColorInt baseColor: Int, @FloatRange(from = 0.0, to = 1.0) alpha: Float): Int { - val a = Math.min(255, Math.max(0, (alpha * 255).toInt())) shl 24 + val a = min(255, max(0, (alpha * 255).toInt())) shl 24 val rgb = 0x00ffffff and baseColor return a + rgb } diff --git a/app/src/main/java/io/legado/app/utils/FloatExtensions.kt b/app/src/main/java/io/legado/app/utils/FloatExtensions.kt index af9576c00..4e3c7f9ed 100644 --- a/app/src/main/java/io/legado/app/utils/FloatExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/FloatExtensions.kt @@ -2,14 +2,13 @@ package io.legado.app.utils import android.content.res.Resources - -val Float.dp: Float // [xxhdpi](360 -> 1080) +val Float.dp: Float get() = android.util.TypedValue.applyDimension( android.util.TypedValue.COMPLEX_UNIT_DIP, this, Resources.getSystem().displayMetrics ) -val Float.sp: Float // [xxhdpi](360 -> 1080) +val Float.sp: Float get() = android.util.TypedValue.applyDimension( android.util.TypedValue.COMPLEX_UNIT_SP, this, Resources.getSystem().displayMetrics ) diff --git a/app/src/main/java/io/legado/app/utils/StringExtensions.kt b/app/src/main/java/io/legado/app/utils/StringExtensions.kt index 02faf53c3..63954162e 100644 --- a/app/src/main/java/io/legado/app/utils/StringExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/StringExtensions.kt @@ -1,7 +1,5 @@ package io.legado.app.utils -// import org.apache.commons.text.StringEscapeUtils - fun String?.safeTrim() = if (this.isNullOrBlank()) null else this.trim() fun String?.isContentPath(): Boolean = this?.startsWith("content://") == true