Skip to content
Snippets Groups Projects
Commit 37bb0180 authored by Dani Mahardhika's avatar Dani Mahardhika
Browse files

Automatically set issue label title color based on background color

parent cb56e38d
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -2,6 +2,7 @@ package com.commit451.gitlab.extension
 
import android.graphics.Color
import android.support.annotation.ColorInt
import com.commit451.easel.Easel
import com.commit451.gitlab.model.api.Label
import com.commit451.gitlab.util.ColorUtil
 
Loading
Loading
@@ -16,5 +17,8 @@ fun Label.getColor(): Int {
 
@ColorInt
fun Label.getTitleColor(): Int {
return ColorUtil.getTitleColor(getColor())
if (Easel.isColorDark(getColor())) {
return Color.WHITE
}
return Easel.darkerColor(getColor(), 0.25f)
}
\ No newline at end of file
package com.commit451.gitlab.util
 
import android.graphics.Color
import android.support.annotation.ColorInt
 
/**
Loading
Loading
@@ -11,18 +10,4 @@ object ColorUtil {
fun convertColorIntToString(@ColorInt color: Int): String {
return String.format("#%06X", 0xFFFFFF and color)
}
fun getTitleColor(@ColorInt color: Int): Int {
val darkness = 1.0 - (0.299 * Color.red(color).toDouble() +
0.587 * Color.green(color).toDouble() +
0.114 * Color.blue(color).toDouble()) / 255.0
if (darkness < 0.35) {
val hsv = FloatArray(3)
Color.colorToHSV(color, hsv)
hsv[2] *= 0.25f
return Color.HSVToColor(hsv)
}
return Color.WHITE;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment