优化
This commit is contained in:
1 parent
2c9dba7f1d
commit
297cdf852d
2 files changed
+65
-83
No files matched your search
@@ -1,16 +1,18 @@
|
||||
package io.legado.app.utils
|
||||
|
||||
import android.graphics.Color
|
||||
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.annotation.FloatRange
|
||||
import androidx.core.graphics.ColorUtils
|
||||
import java.util.*
|
||||
import kotlin.math.*
|
||||
|
||||
@Suppress("unused", "MemberVisibilityCanBePrivate")
|
||||
object ColorUtils {
|
||||
|
||||
fun isColorLight(@ColorInt color: Int): Boolean {
|
||||
return ColorUtils.calculateLuminance(color) >= 0.65
|
||||
}
|
||||
|
||||
fun intToString(intColor: Int): String {
|
||||
return String.format("#%06X", 0xFFFFFF and intColor)
|
||||
}
|
||||
@@ -39,10 +41,6 @@ object ColorUtils {
|
||||
return shiftColor(color, 1.1f)
|
||||
}
|
||||
|
||||
fun isColorLight(@ColorInt color: Int): Boolean {
|
||||
return ColorUtils.calculateLuminance(color) >= 0.65
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
fun invertColor(@ColorInt color: Int): Int {
|
||||
val r = 255 - Color.red(color)
|
||||
@@ -79,83 +77,6 @@ object ColorUtils {
|
||||
return Color.argb(a.toInt(), r.toInt(), g.toInt(), b.toInt())
|
||||
}
|
||||
|
||||
/**
|
||||
* 按条件的到随机颜色
|
||||
*
|
||||
* @param alpha 透明
|
||||
* @param lower 下边界
|
||||
* @param upper 上边界
|
||||
* @return 颜色值
|
||||
*/
|
||||
fun getRandomColor(alpha: Int, lower: Int, upper: Int): Int {
|
||||
return RandomColor(alpha, lower, upper).color
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 获取随机色
|
||||
*/
|
||||
fun getRandomColor(): Int {
|
||||
return RandomColor(255, 80, 200).color
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 随机颜色
|
||||
*/
|
||||
class RandomColor(alpha: Int, lower: Int, upper: Int) {
|
||||
private var alpha: Int = 0
|
||||
private var lower: Int = 0
|
||||
private var upper: Int = 0
|
||||
|
||||
//随机数是前闭 后开
|
||||
val color: Int
|
||||
get() {
|
||||
val red = getLower() + Random().nextInt(getUpper() - getLower() + 1)
|
||||
val green = getLower() + Random().nextInt(getUpper() - getLower() + 1)
|
||||
val blue = getLower() + Random().nextInt(getUpper() - getLower() + 1)
|
||||
|
||||
return Color.argb(getAlpha(), red, green, blue)
|
||||
}
|
||||
|
||||