Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions commons/src/main/kotlin/org/fossify/commons/extensions/Int.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ import kotlin.math.log10
import kotlin.math.pow

fun Int.getContrastColor(): Int {
val luminance = ColorUtils.calculateLuminance(this)
return if (luminance > 0.5) DARK_GREY else Color.WHITE
return getContrastColor(DARK_GREY, Color.WHITE)
}

fun Int.getContrastColor(colorFirst: Int, colorSecond: Int): Int {
val contrastFirst = ColorUtils.calculateContrast(colorFirst, this)
val contrastSecond = ColorUtils.calculateContrast(colorSecond, this)

return if (contrastFirst >= contrastSecond) colorFirst else colorSecond
}

fun Int.toHex() = String.format("#%06X", 0xFFFFFF and this).uppercase(Locale.getDefault())
Expand Down
Loading