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