determine the colorpicker rectangle background based on the actual background

This commit is contained in:
tibbi 2017-01-10 18:48:36 +01:00
parent be7c9c9ca1
commit e1d82817d6
3 changed files with 8 additions and 7 deletions

View file

@ -101,7 +101,7 @@ class CustomizationActivity : BaseSimpleActivity() {
private fun setupColorsPickers() { private fun setupColorsPickers() {
customization_text_color.setBackgroundColor(curTextColor) customization_text_color.setBackgroundColor(curTextColor)
customization_primary_color.setBackgroundColor(curPrimaryColor) customization_primary_color.setBackgroundColor(curPrimaryColor)
customization_background_color.setBackgroundWithStroke(curBackgroundColor) customization_background_color.setBackgroundWithStroke(curBackgroundColor, curBackgroundColor)
} }
private fun hasColorChanged(old: Int, new: Int) = Math.abs(old - new) > 1 private fun hasColorChanged(old: Int, new: Int) = Math.abs(old - new) > 1

View file

@ -29,6 +29,7 @@ class ColorPickerDialog(val context: Context, color: Int, val callback: (color:
init { init {
Color.colorToHSV(color, currentColorHsv) Color.colorToHSV(color, currentColorHsv)
val backgroundColor = BaseConfig.newInstance(context).backgroundColor
val view = LayoutInflater.from(context).inflate(R.layout.dialog_colorpicker, null).apply { val view = LayoutInflater.from(context).inflate(R.layout.dialog_colorpicker, null).apply {
viewHue = color_picker_hue viewHue = color_picker_hue
viewSatVal = color_picker_square viewSatVal = color_picker_square
@ -39,8 +40,8 @@ class ColorPickerDialog(val context: Context, color: Int, val callback: (color:
viewContainer = color_picker_holder viewContainer = color_picker_holder
viewSatVal.setHue(getHue()) viewSatVal.setHue(getHue())
viewNewColor.setBackgroundWithStroke(getColor()) viewNewColor.setBackgroundWithStroke(getColor(), backgroundColor)
color_picker_old_color.setBackgroundWithStroke(color) color_picker_old_color.setBackgroundWithStroke(color, backgroundColor)
} }
viewHue.setOnTouchListener(OnTouchListener { v, event -> viewHue.setOnTouchListener(OnTouchListener { v, event ->
@ -55,7 +56,7 @@ class ColorPickerDialog(val context: Context, color: Int, val callback: (color:
currentColorHsv[0] = hue currentColorHsv[0] = hue
viewSatVal.setHue(getHue()) viewSatVal.setHue(getHue())
moveHuePicker() moveHuePicker()
viewNewColor.setBackgroundWithStroke(getColor()) viewNewColor.setBackgroundWithStroke(getColor(), backgroundColor)
return@OnTouchListener true return@OnTouchListener true
} }
false false
@ -79,7 +80,7 @@ class ColorPickerDialog(val context: Context, color: Int, val callback: (color:
currentColorHsv[2] = 1f - 1f / viewSatVal.measuredHeight * y currentColorHsv[2] = 1f - 1f / viewSatVal.measuredHeight * y
moveColorPicker() moveColorPicker()
viewNewColor.setBackgroundWithStroke(getColor()) viewNewColor.setBackgroundWithStroke(getColor(), backgroundColor)
return@OnTouchListener true return@OnTouchListener true
} }
false false

View file

@ -3,8 +3,8 @@ package com.simplemobiletools.commons.extensions
import android.graphics.drawable.GradientDrawable import android.graphics.drawable.GradientDrawable
import android.widget.ImageView import android.widget.ImageView
fun ImageView.setBackgroundWithStroke(backgroundColor: Int) { fun ImageView.setBackgroundWithStroke(backgroundColor: Int, realStrokeColor: Int) {
val strokeColor = backgroundColor.getContrastColor() val strokeColor = realStrokeColor.getContrastColor()
GradientDrawable().apply { GradientDrawable().apply {
shape = GradientDrawable.RECTANGLE shape = GradientDrawable.RECTANGLE
setColor(backgroundColor) setColor(backgroundColor)