diff options
Diffstat (limited to 'core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt')
-rw-r--r-- | core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt index ab7b341..0131302 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt @@ -36,6 +36,9 @@ import androidx.core.graphics.drawable.DrawableCompat import androidx.core.view.ViewCompat import com.afollestad.materialdialogs.R import java.util.Random +import kotlin.math.abs +import kotlin.math.max +import kotlin.math.roundToInt /** * Created by Allan Wang on 2017-06-08. @@ -86,9 +89,9 @@ fun Int.isColorVisibleOn( @IntRange(from = 0L, to = 255L) minAlpha: Int = 50 ): Boolean = if (Color.alpha(this) < minAlpha) false - else !(Math.abs(Color.red(this) - Color.red(color)) < delta && - Math.abs(Color.green(this) - Color.green(color)) < delta && - Math.abs(Color.blue(this) - Color.blue(color)) < delta) + else !(abs(Color.red(this) - Color.red(color)) < delta && + abs(Color.green(this) - Color.green(color)) < delta && + abs(Color.blue(this) - Color.blue(color)) < delta) @ColorInt fun Context.getDisabledColor(): Int { @@ -99,7 +102,7 @@ fun Context.getDisabledColor(): Int { @ColorInt fun Int.adjustAlpha(factor: Float): Int { - val alpha = Math.round(Color.alpha(this) * factor) + val alpha = (Color.alpha(this) * factor).roundToInt() return Color.argb(alpha, Color.red(this), Color.green(this), Color.blue(this)) } @@ -122,7 +125,7 @@ fun Int.withAlpha(@IntRange(from = 0, to = 0xFF) alpha: Int): Int = @ColorInt fun Int.withMinAlpha(@IntRange(from = 0, to = 0xFF) alpha: Int): Int = - withAlpha(Math.max(alpha, this ushr 24)) + withAlpha(max(alpha, this ushr 24)) @ColorInt private inline fun Int.colorFactor(rgbFactor: (Int) -> Float): Int { |