Skip to content
Snippets Groups Projects
Commit e2703b45 authored by Alex Hart's avatar Alex Hart
Browse files

Rework color selector and background.

parent 405d99fb
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@ import android.graphics.Color
import android.os.Parcelable
import androidx.annotation.ColorInt
import androidx.annotation.IntRange
import androidx.core.graphics.ColorUtils
import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize
import org.thoughtcrime.securesms.conversation.colors.ChatColors
......@@ -28,14 +29,27 @@ data class TextStoryPostCreationState(
val textForegroundColor: Int = when (textColorStyle) {
TextColorStyle.NO_BACKGROUND -> textColor
TextColorStyle.NORMAL -> textColor
TextColorStyle.INVERT -> Color.WHITE
TextColorStyle.INVERT -> getDefaultColorForLightness(textColor)
}
@ColorInt
@IgnoredOnParcel
val textBackgroundColor: Int = when (textColorStyle) {
TextColorStyle.NO_BACKGROUND -> Color.TRANSPARENT
TextColorStyle.NORMAL -> Color.WHITE
TextColorStyle.NORMAL -> getDefaultColorForLightness(textColor)
TextColorStyle.INVERT -> textColor
}
private fun getDefaultColorForLightness(textColor: Int): Int {
val hsl = floatArrayOf(0f, 0f, 0f)
ColorUtils.colorToHSL(textColor, hsl)
val lightness = hsl[2]
return if (lightness >= 0.9f) {
Color.BLACK
} else {
Color.WHITE
}
}
}
package org.thoughtcrime.securesms.scribbles
import android.animation.FloatEvaluator
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.ColorFilter
......@@ -15,6 +16,7 @@ import androidx.annotation.ColorInt
import androidx.annotation.Dimension
import androidx.appcompat.widget.AppCompatSeekBar
import androidx.core.graphics.ColorUtils
import org.thoughtcrime.securesms.scribbles.HSVColorSlider.toHue
import org.thoughtcrime.securesms.util.Util
import org.thoughtcrime.securesms.util.ViewUtil
import org.thoughtcrime.securesms.util.customizeOnDraw
......@@ -30,29 +32,30 @@ object HSVColorSlider {
private const val WHITE_DIVISIONS = 125
private const val MAX_SEEK_DIVISIONS = COLOR_DIVISIONS + BLACK_DIVISIONS + WHITE_DIVISIONS
private const val STANDARD_LIGHTNESS = 0.4f
private val EVALUATOR = FloatEvaluator()
private val colors: IntArray = (0..COLOR_DIVISIONS).map { hue ->
private val colors: IntArray = (0..BLACK_DIVISIONS).map { value ->
ColorUtils.HSLToColor(
floatArrayOf(
hue.toHue(COLOR_DIVISIONS),
MAX_HUE.toFloat(),
1f,
calculateLightness(hue.toFloat(), STANDARD_LIGHTNESS)
value / BLACK_DIVISIONS.toFloat() * STANDARD_LIGHTNESS
)
)
}.toIntArray() + (BLACK_DIVISIONS downTo 0).map { value ->
}.toIntArray() + (0..COLOR_DIVISIONS).map { hue ->
ColorUtils.HSLToColor(
floatArrayOf(
MAX_HUE.toFloat(),
hue.toHue(COLOR_DIVISIONS),
1f,
value / BLACK_DIVISIONS.toFloat() * STANDARD_LIGHTNESS
calculateLightness(hue.toFloat(), STANDARD_LIGHTNESS)
)
)
}.toIntArray() + (0..WHITE_DIVISIONS).map { value ->
ColorUtils.HSLToColor(
floatArrayOf(
MAX_HUE.toFloat(),
0f,
value / WHITE_DIVISIONS.toFloat()
COLOR_DIVISIONS.toHue(COLOR_DIVISIONS),
1f,
EVALUATOR.evaluate(value / WHITE_DIVISIONS.toFloat(), calculateLightness(COLOR_DIVISIONS.toFloat(), STANDARD_LIGHTNESS), 1f)
)
)
}.toIntArray()
......
......@@ -60,7 +60,7 @@ class StoryTextPostView @JvmOverloads constructor(
textView.typeface = typeface
}
fun setPostBackground(drawable: Drawable) {
private fun setPostBackground(drawable: Drawable) {
backgroundView.setImageDrawable(drawable)
}
......@@ -72,30 +72,30 @@ class StoryTextPostView @JvmOverloads constructor(
}
}
fun setText(text: CharSequence, isPlaceholder: Boolean) {
private fun setText(text: CharSequence, isPlaceholder: Boolean) {
this.isPlaceholder = isPlaceholder
textView.text = text
}
fun setTextSize(@Px textSize: Float) {
private fun setTextSize(@Px textSize: Float) {
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize)
}
fun setTextGravity(textAlignment: TextAlignment) {
private fun setTextGravity(textAlignment: TextAlignment) {
textView.gravity = textAlignment.gravity
}
fun setTextScale(scalePercent: Int) {
private fun setTextScale(scalePercent: Int) {
val scale = TextStoryScale.convertToScale(scalePercent)
textView.scaleX = scale
textView.scaleY = scale
}
fun setTextVisible(visible: Boolean) {
private fun setTextVisible(visible: Boolean) {
textView.visible = visible
}
fun setTextBackgroundColor(@ColorInt color: Int) {
private fun setTextBackgroundColor(@ColorInt color: Int) {
textView.setWrappedBackgroundColor(color)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment