diff options
author | Allan Wang <me@allanwang.ca> | 2019-10-19 22:30:16 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2019-10-19 22:31:14 -0700 |
commit | 7007e61879bf33c09115b5d8bc16f27af2731045 (patch) | |
tree | 19bc5e07f16ce1b6b9d13c711fed5160e25bc3ad /core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt | |
parent | 63f920c3257e955da1ef63c91f8b5e2de5478e55 (diff) | |
download | kau-7007e61879bf33c09115b5d8bc16f27af2731045.tar.gz kau-7007e61879bf33c09115b5d8bc16f27af2731045.tar.bz2 kau-7007e61879bf33c09115b5d8bc16f27af2731045.zip |
Convert java math to kotlin math
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 { |