Archived
ColorPickerDialog has been implemented - picking colours for text and highlight now works!
This commit is contained in:
@@ -126,6 +126,16 @@ class QuoteStorage private constructor(context: Context) {
|
||||
fun getOutlineSize(): Float = prefs.getFloat(KEY_OUTLINE_SIZE, 8f)
|
||||
fun getOutlineSizeNew(): Int = prefs.getInt(KEY_OUTLINE_SIZE_NEW, 8)
|
||||
|
||||
fun getTextColour(): String = prefs.getString(SettingsPreference.TEXT_COLOUR.key, "ffffff") ?: "ffffff"
|
||||
fun setTextColour(newValue: String) {
|
||||
prefs.edit().putString(SettingsPreference.TEXT_COLOUR.key, newValue).apply()
|
||||
}
|
||||
|
||||
fun getHighlightColour(): String = prefs.getString(SettingsPreference.HIGHLIGHT_COLOUR.key, "000000") ?: "000000"
|
||||
fun setHighlightColour(newValue: String) {
|
||||
prefs.edit().putString(SettingsPreference.HIGHLIGHT_COLOUR.key, newValue).apply()
|
||||
}
|
||||
|
||||
// Pair<text colour, background colour>
|
||||
fun getColours(
|
||||
isInverted: Boolean = isInvertedEnabled(),
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.denizd.textbasic.fragment
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.util.TypedValue
|
||||
import android.view.View
|
||||
@@ -9,6 +12,7 @@ import android.widget.ImageButton
|
||||
import android.widget.PopupMenu
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.transition.TransitionManager
|
||||
import com.denizd.textbasic.BuildConfig
|
||||
import com.denizd.textbasic.R
|
||||
@@ -19,6 +23,9 @@ import com.denizd.textbasic.util.SettingsPreference
|
||||
import com.denizd.textbasic.util.viewBinding
|
||||
import com.denizd.textbasic.widget.CanvasText
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import com.skydoves.colorpickerview.ColorEnvelope
|
||||
import com.skydoves.colorpickerview.ColorPickerDialog
|
||||
import com.skydoves.colorpickerview.listeners.ColorEnvelopeListener
|
||||
import java.util.Calendar
|
||||
|
||||
class SettingsNewFragment : BaseFragment(R.layout.fragment_settings_new) {
|
||||
@@ -146,6 +153,13 @@ class SettingsNewFragment : BaseFragment(R.layout.fragment_settings_new) {
|
||||
SettingsPreference.TEXT_SIZE,
|
||||
)
|
||||
|
||||
// --- text colour --- //
|
||||
setTextColour(storage.getTextColour())
|
||||
|
||||
binding.buttonTextColourDisplay.setOnClickListener {
|
||||
showColorPickerDialog(context, R.string.settings_text_colour_dialog_title, true)//, storage.getTextColour())
|
||||
}
|
||||
|
||||
// --- highlight style --- //
|
||||
binding.toggleGroupHighlightStyle.apply {
|
||||
check(checkBackgroundIntensity(storage.getBackgroundType()))
|
||||
@@ -212,6 +226,13 @@ class SettingsNewFragment : BaseFragment(R.layout.fragment_settings_new) {
|
||||
SettingsPreference.HIGHLIGHT_INTENSITY,
|
||||
)
|
||||
|
||||
// --- highlight colour --- //
|
||||
setHighlightColour(storage.getHighlightColour())
|
||||
|
||||
binding.buttonHighlightColourDisplay.setOnClickListener {
|
||||
showColorPickerDialog(context, R.string.settings_highlight_colour_dialog_title, false)
|
||||
}
|
||||
|
||||
// --- randomise order entries --- //
|
||||
binding.switchOrderRandom.apply {
|
||||
isChecked = storage.isOrderRandom()
|
||||
@@ -344,6 +365,54 @@ class SettingsNewFragment : BaseFragment(R.layout.fragment_settings_new) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun setTextColour(colour: String) {
|
||||
binding.textTextColourCode.text = "#$colour"
|
||||
|
||||
binding.buttonTextColourDisplay.backgroundTintList = ColorStateList.valueOf(
|
||||
Color.parseColor("#$colour")
|
||||
)
|
||||
}
|
||||
|
||||
private fun setHighlightColour(colour: String) {
|
||||
binding.textHighlightColourCode.text = "#$colour"
|
||||
|
||||
binding.buttonHighlightColourDisplay.backgroundTintList = ColorStateList.valueOf(
|
||||
Color.parseColor("#$colour")
|
||||
)
|
||||
}
|
||||
|
||||
// TODO this should start with the current colour of the attribute that's to be changed!
|
||||
private fun showColorPickerDialog(
|
||||
context: Context,
|
||||
@StringRes title: Int,
|
||||
isText: Boolean,
|
||||
// tag: String,
|
||||
// colour: String,
|
||||
) {
|
||||
ColorPickerDialog.Builder(context)
|
||||
// .setInitialColor(Color.parseColor("#$colour"))
|
||||
// .setPreferenceName(tag)
|
||||
// .setLifecycleOwner(this)
|
||||
// .build()
|
||||
.setTitle(getString(title))
|
||||
.setPositiveButton(getString(R.string.settings_colour_dialog_positive), object : ColorEnvelopeListener {
|
||||
override fun onColorSelected(envelope: ColorEnvelope, fromUser: Boolean) {
|
||||
if (isText) {
|
||||
storage.setTextColour(envelope.hexCode)
|
||||
setTextColour(envelope.hexCode)
|
||||
} else {
|
||||
storage.setHighlightColour(envelope.hexCode)
|
||||
setHighlightColour(envelope.hexCode)
|
||||
}
|
||||
updatePreview()
|
||||
}})
|
||||
.setNegativeButton(getString(R.string.settings_colour_dialog_negative)
|
||||
) { dialogInterface, _ ->
|
||||
dialogInterface.dismiss()
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun updatePreview() {
|
||||
|
||||
val bitmap = CanvasText.drawText(context, true)
|
||||
|
||||
@@ -40,7 +40,7 @@ class CanvasText {
|
||||
storage.getNextQuote()
|
||||
}.ifBlank { context.getString(R.string.info_add_text) }
|
||||
|
||||
val colours = storage.getColours(context = context)
|
||||
// val colours = storage.getColours(context = context)
|
||||
|
||||
val scaledTextSize =
|
||||
context.resources.displayMetrics.scaledDensity * if (/*isPreview*/false) previewSize else {
|
||||
@@ -52,7 +52,7 @@ class CanvasText {
|
||||
|
||||
val paint = TextPaint().apply {
|
||||
style = Paint.Style.FILL
|
||||
color = colours.first
|
||||
color = Color.parseColor("#${storage.getTextColour()}")
|
||||
textSize = scaledTextSize
|
||||
textAlign = when (widgetGravity) {
|
||||
0, 3, 6 -> Paint.Align.LEFT
|
||||
@@ -116,7 +116,7 @@ class CanvasText {
|
||||
0 -> { // background
|
||||
val bgPaint = Paint().apply {
|
||||
style = Paint.Style.FILL
|
||||
color = colours.second
|
||||
color = Color.parseColor("#${storage.getHighlightColour()}")
|
||||
}
|
||||
val rounding = 24f
|
||||
|
||||
@@ -142,7 +142,7 @@ class CanvasText {
|
||||
val strokePaint = TextPaint().apply {
|
||||
style = Paint.Style.STROKE
|
||||
strokeWidth = outlineSize //if (isPreview) previewSize / 1.5f else
|
||||
color = colours.second
|
||||
color = Color.parseColor("#${storage.getHighlightColour()}")
|
||||
textSize = scaledTextSize
|
||||
textAlign = alignment
|
||||
|
||||
|
||||
Reference in New Issue
Block a user