lets use oval colorpicker instead of square ones

This commit is contained in:
tibbi 2021-11-04 16:34:28 +01:00
parent b828635a33
commit 593606ea0e
4 changed files with 20 additions and 23 deletions

View file

@ -400,13 +400,12 @@ class CustomizationActivity : BaseSimpleActivity() {
} }
private fun setupColorsPickers() { private fun setupColorsPickers() {
val cornerRadius = getCornerRadius() customization_text_color.setFillWithStroke(curTextColor, curBackgroundColor)
customization_text_color.setFillWithStroke(curTextColor, curBackgroundColor, cornerRadius) customization_primary_color.setFillWithStroke(curPrimaryColor, curBackgroundColor)
customization_primary_color.setFillWithStroke(curPrimaryColor, curBackgroundColor, cornerRadius) customization_accent_color.setFillWithStroke(curAccentColor, curBackgroundColor)
customization_accent_color.setFillWithStroke(curAccentColor, curBackgroundColor, cornerRadius) customization_background_color.setFillWithStroke(curBackgroundColor, curBackgroundColor)
customization_background_color.setFillWithStroke(curBackgroundColor, curBackgroundColor, cornerRadius) customization_app_icon_color.setFillWithStroke(curAppIconColor, curBackgroundColor)
customization_app_icon_color.setFillWithStroke(curAppIconColor, curBackgroundColor, cornerRadius) customization_navigation_bar_color.setFillWithStroke(curNavigationBarColor, curBackgroundColor)
customization_navigation_bar_color.setFillWithStroke(curNavigationBarColor, curBackgroundColor, cornerRadius)
customization_text_color_holder.setOnClickListener { pickTextColor() } customization_text_color_holder.setOnClickListener { pickTextColor() }
customization_background_color_holder.setOnClickListener { pickBackgroundColor() } customization_background_color_holder.setOnClickListener { pickBackgroundColor() }

View file

@ -37,7 +37,6 @@ class ColorPickerDialog(
private val baseConfig = activity.baseConfig private val baseConfig = activity.baseConfig
private val currentColorHsv = FloatArray(3) private val currentColorHsv = FloatArray(3)
private val backgroundColor = baseConfig.backgroundColor private val backgroundColor = baseConfig.backgroundColor
private val cornerRadius = activity.getCornerRadius()
private var isHueBeingDragged = false private var isHueBeingDragged = false
private var wasDimmedBackgroundRemoved = false private var wasDimmedBackgroundRemoved = false
private var dialog: AlertDialog? = null private var dialog: AlertDialog? = null
@ -57,8 +56,8 @@ class ColorPickerDialog(
viewSatVal.setHue(getHue()) viewSatVal.setHue(getHue())
viewNewColor.setFillWithStroke(getColor(), backgroundColor, cornerRadius) viewNewColor.setFillWithStroke(getColor(), backgroundColor)
color_picker_old_color.setFillWithStroke(color, backgroundColor, cornerRadius) color_picker_old_color.setFillWithStroke(color, backgroundColor)
val hexCode = getHexCode(color) val hexCode = getHexCode(color)
color_picker_old_hex.text = "#$hexCode" color_picker_old_hex.text = "#$hexCode"
@ -117,7 +116,7 @@ class ColorPickerDialog(
currentColorHsv[2] = 1f - 1f / viewSatVal.measuredHeight * y currentColorHsv[2] = 1f - 1f / viewSatVal.measuredHeight * y
moveColorPicker() moveColorPicker()
viewNewColor.setFillWithStroke(getColor(), backgroundColor, cornerRadius) viewNewColor.setFillWithStroke(getColor(), backgroundColor)
newHexField.setText(getHexCode(getColor())) newHexField.setText(getHexCode(getColor()))
return@OnTouchListener true return@OnTouchListener true
} }
@ -169,7 +168,7 @@ class ColorPickerDialog(
val recentColorView = ImageView(context) val recentColorView = ImageView(context)
recentColorView.id = View.generateViewId() recentColorView.id = View.generateViewId()
recentColorView.layoutParams = ViewGroup.LayoutParams(squareSize, squareSize) recentColorView.layoutParams = ViewGroup.LayoutParams(squareSize, squareSize)
recentColorView.setFillWithStroke(recentColor, backgroundColor, cornerRadius) recentColorView.setFillWithStroke(recentColor, backgroundColor)
recentColorView.setOnClickListener { newHexField.setText(getHexCode(recentColor)) } recentColorView.setOnClickListener { newHexField.setText(getHexCode(recentColor)) }
recent_colors.addView(recentColorView) recent_colors.addView(recentColorView)
recent_colors_flow.addView(recentColorView) recent_colors_flow.addView(recentColorView)
@ -218,7 +217,7 @@ class ColorPickerDialog(
private fun updateHue() { private fun updateHue() {
viewSatVal.setHue(getHue()) viewSatVal.setHue(getHue())
moveHuePicker() moveHuePicker()
viewNewColor.setFillWithStroke(getColor(), backgroundColor, cornerRadius) viewNewColor.setFillWithStroke(getColor(), backgroundColor)
if (removeDimmedBackground && !wasDimmedBackgroundRemoved) { if (removeDimmedBackground && !wasDimmedBackgroundRemoved) {
dialog?.window?.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND) dialog?.window?.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
wasDimmedBackgroundRemoved = true wasDimmedBackgroundRemoved = true

View file

@ -4,16 +4,15 @@ import android.graphics.PorterDuff
import android.graphics.drawable.GradientDrawable import android.graphics.drawable.GradientDrawable
import android.widget.ImageView import android.widget.ImageView
fun ImageView.setFillWithStroke(fillColor: Int, backgroundColor: Int, cornerRadiusSize: Float = 0f) { fun ImageView.setFillWithStroke(fillColor: Int, backgroundColor: Int) {
val strokeColor = backgroundColor.getContrastColor()
GradientDrawable().apply { GradientDrawable().apply {
shape = GradientDrawable.RECTANGLE shape = GradientDrawable.OVAL
setColor(fillColor) setColor(fillColor)
setStroke(2, strokeColor)
background = this background = this
if (cornerRadiusSize != 0f) { if (backgroundColor == fillColor) {
cornerRadius = cornerRadiusSize val strokeColor = backgroundColor.getContrastColor().adjustAlpha(0.5f)
setStroke(2, strokeColor)
} }
} }
} }

View file

@ -137,8 +137,8 @@
<ImageView <ImageView
android:id="@+id/color_picker_old_color" android:id="@+id/color_picker_old_color"
android:layout_width="@dimen/colorpicker_color_width" android:layout_width="@dimen/colorpicker_items_height"
android:layout_height="match_parent" android:layout_height="@dimen/colorpicker_items_height"
android:layout_toStartOf="@+id/color_picker_arrow" android:layout_toStartOf="@+id/color_picker_arrow"
android:background="@android:color/white" /> android:background="@android:color/white" />
@ -154,8 +154,8 @@
<ImageView <ImageView
android:id="@+id/color_picker_new_color" android:id="@+id/color_picker_new_color"
android:layout_width="@dimen/colorpicker_color_width" android:layout_width="@dimen/colorpicker_items_height"
android:layout_height="match_parent" android:layout_height="@dimen/colorpicker_items_height"
android:layout_toEndOf="@+id/color_picker_arrow" android:layout_toEndOf="@+id/color_picker_arrow"
android:background="@android:color/white" /> android:background="@android:color/white" />
</RelativeLayout> </RelativeLayout>