aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/dialogs/color/ColorPickerView.kt2
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt12
-rw-r--r--library/src/main/res/values/strings_commons.xml2
-rw-r--r--sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt10
4 files changed, 13 insertions, 13 deletions
diff --git a/library/src/main/kotlin/ca/allanwang/kau/dialogs/color/ColorPickerView.kt b/library/src/main/kotlin/ca/allanwang/kau/dialogs/color/ColorPickerView.kt
index 2643d27..da864c9 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/dialogs/color/ColorPickerView.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/dialogs/color/ColorPickerView.kt
@@ -32,7 +32,7 @@ internal class ColorPickerView @JvmOverloads constructor(
var circleSize: Int = context.dimen(R.dimen.kau_color_circle_size).toInt()
val backgroundColor = context.resolveColor(R.attr.md_background_color,
if (context.resolveColor(android.R.attr.textColorPrimary).isColorDark()) Color.WHITE else 0xff424242.toInt())
- val backgroundColorTint = backgroundColor.colorToForeground(0.2f)
+ val backgroundColorTint = backgroundColor.colorToForeground()
lateinit var dialog: MaterialDialog
lateinit var builder: ColorContract
lateinit var colorsTop: IntArray
diff --git a/library/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt b/library/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt
index 2c5a395..8ae23d1 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt
@@ -69,25 +69,25 @@ fun Int.withMinAlpha(@IntRange(from = 0L, to = 255L) alpha: Int): Int
= Color.argb(Math.max(alpha, Color.alpha(this)), Color.red(this), Color.green(this), Color.blue(this))
@ColorInt
-fun Int.lighten(@FloatRange(from = 0.0, to = 1.0) factor: Float = 0.2f): Int {
+fun Int.lighten(@FloatRange(from = 0.0, to = 1.0) factor: Float = 0.1f): Int {
val (red, green, blue) = intArrayOf(Color.red(this), Color.green(this), Color.blue(this))
- .map { Math.min(255f * factor + it, 255f).toInt() }
+ .map { (it * (1f - factor) + 255f * factor).toInt() }
return Color.argb(Color.alpha(this), red, green, blue)
}
@ColorInt
-fun Int.darken(@FloatRange(from = 0.0, to = 1.0) factor: Float = 0.2f): Int {
+fun Int.darken(@FloatRange(from = 0.0, to = 1.0) factor: Float = 0.1f): Int {
val (red, green, blue) = intArrayOf(Color.red(this), Color.green(this), Color.blue(this))
- .map { Math.max(it - 255f * factor, 0f).toInt() }
+ .map { (it * (1f - factor)).toInt() }
return Color.argb(Color.alpha(this), red, green, blue)
}
@ColorInt
-fun Int.colorToBackground(@FloatRange(from = 0.0, to = 1.0) factor: Float = 0.2f): Int
+fun Int.colorToBackground(@FloatRange(from = 0.0, to = 1.0) factor: Float = 0.1f): Int
= if (isColorDark()) darken(factor) else lighten(factor)
@ColorInt
-fun Int.colorToForeground(@FloatRange(from = 0.0, to = 1.0) factor: Float = 0.2f): Int
+fun Int.colorToForeground(@FloatRange(from = 0.0, to = 1.0) factor: Float = 0.1f): Int
= if (isColorDark()) lighten(factor) else darken(factor)
@Throws(IllegalArgumentException::class)
diff --git a/library/src/main/res/values/strings_commons.xml b/library/src/main/res/values/strings_commons.xml
index 1bbca44..6bc8299 100644
--- a/library/src/main/res/values/strings_commons.xml
+++ b/library/src/main/res/values/strings_commons.xml
@@ -21,7 +21,9 @@ Most resources are verbatim and x represents a formatted item
<string name="kau_exit_confirmation">Are you sure you want to exit?</string>
<string name="kau_exit_confirmation_x">Are you sure you want to exit %s?</string>
<string name="kau_glass">Glass</string>
+ <string name="kau_got_it">Got it</string>
<string name="kau_great">Great</string>
+ <string name="kau_hide">Hide</string>
<string name="kau_light">Light</string>
<string name="kau_login">Login</string>
<string name="kau_logout">Logout</string>
diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt
index 849b49a..bb1fcff 100644
--- a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt
+++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt
@@ -57,9 +57,8 @@ class MainActivity : KPrefActivity() {
colorPicker(R.string.accent_color, { KPrefSample.accentColor }, {
KPrefSample.accentColor = it
reload()
- val darkerColor = it.darken()
- this@MainActivity.navigationBarColor = darkerColor
- toolbarCanvas.ripple(darkerColor, RippleCanvas.MIDDLE, RippleCanvas.END, duration = 500L)
+ this@MainActivity.navigationBarColor = it
+ toolbarCanvas.ripple(it, RippleCanvas.MIDDLE, RippleCanvas.END, duration = 500L)
}) {
descRes = R.string.color_no_custom
allowCustom = false
@@ -118,9 +117,8 @@ class MainActivity : KPrefActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
bgCanvas.set(KPrefSample.bgColor)
- val darkAccent = KPrefSample.accentColor.darken()
- toolbarCanvas.set(darkAccent)
- this.navigationBarColor = darkAccent
+ toolbarCanvas.set(KPrefSample.accentColor)
+ this.navigationBarColor = KPrefSample.accentColor
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {