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
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:color="?attr/colorText"/>
|
||||
</selector>
|
||||
@@ -275,6 +275,49 @@
|
||||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
||||
<!-- Text colour -->
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:orientation="vertical"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:paddingVertical="8dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@font/mono_semibold_italic"
|
||||
android:text="@string/settings_text_colour_header"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_text_colour_code"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textSize="16sp"
|
||||
android:fontFamily="@font/mono_medium"/>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
style="@style/Widget.Material3.Button.TonalButton"
|
||||
android:id="@+id/button_text_colour_display"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
app:strokeColor="@color/list_button_stroke"
|
||||
app:strokeWidth="1dp"
|
||||
android:layout_marginStart="8dp"/>
|
||||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
@@ -454,6 +497,49 @@
|
||||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
||||
<!-- Highlight colour -->
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:orientation="vertical"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:paddingVertical="8dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@font/mono_semibold_italic"
|
||||
android:text="@string/settings_highlight_colour_header"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_highlight_colour_code"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textSize="16sp"
|
||||
android:fontFamily="@font/mono_medium"/>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
style="@style/Widget.Material3.Button.TonalButton"
|
||||
android:id="@+id/button_highlight_colour_display"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
app:strokeColor="@color/list_button_stroke"
|
||||
app:strokeWidth="1dp"
|
||||
android:layout_marginStart="8dp"/>
|
||||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
<string name="guide_fragment_title">Anleitung</string>
|
||||
|
||||
<string name="settings_fragment_title">Einstellungen</string>
|
||||
<string name="settings_colour_dialog_negative">Schließen</string>
|
||||
<string name="settings_colour_dialog_positive">Speichern</string>
|
||||
|
||||
<string name="settings_text_header">Textstil</string>
|
||||
<string name="settings_text_font_header">Textschrift</string>
|
||||
@@ -34,6 +36,8 @@
|
||||
<string name="settings_text_style_button_italic">Kursiv</string>
|
||||
<string name="settings_text_style_button_bolditalic">Fett & Kursiv</string>
|
||||
<string name="settings_text_size_header">Textgröße</string>
|
||||
<string name="settings_text_colour_header">Textfarbe</string>
|
||||
<string name="settings_text_colour_dialog_title">Wähle eine Textfarbe</string>
|
||||
<string name="settings_text_transparency_header">Textopazität</string>
|
||||
|
||||
<string name="settings_highlight_header">Highlight-Stil</string>
|
||||
@@ -43,6 +47,8 @@
|
||||
<string name="settings_highlight_style_button_stroke">Umrandet</string>
|
||||
<string name="settings_highlight_style_button_shadow">Schatten</string>
|
||||
<string name="settings_highlight_intensity_header">Stärke</string>
|
||||
<string name="settings_highlight_colour_header">Highlight-Farbe</string>
|
||||
<string name="settings_highlight_colour_dialog_title">Wähle eine Highlight-Farbe</string>
|
||||
<string name="settings_highlight_transparency_header">Highlight-Opazität</string>
|
||||
|
||||
<string name="settings_widget_header">Widget</string>
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
<string name="guide_fragment_title">Guide</string>
|
||||
|
||||
<string name="settings_fragment_title">Settings</string>
|
||||
<string name="settings_colour_dialog_negative">Close</string>
|
||||
<string name="settings_colour_dialog_positive">Save</string>
|
||||
|
||||
<string name="settings_text_header">Text Style</string>
|
||||
<string name="settings_text_font_header">Text font</string>
|
||||
@@ -33,6 +35,8 @@
|
||||
<string name="settings_text_style_button_italic">Italic</string>
|
||||
<string name="settings_text_style_button_bolditalic">Bold & Italic</string>
|
||||
<string name="settings_text_size_header">Text size</string>
|
||||
<string name="settings_text_colour_header">Text colour</string>
|
||||
<string name="settings_text_colour_dialog_title">Pick a text colour</string>
|
||||
<string name="settings_text_transparency_header">Text opacity</string>
|
||||
|
||||
<string name="settings_highlight_header">Highlight Style</string>
|
||||
@@ -42,6 +46,8 @@
|
||||
<string name="settings_highlight_style_button_stroke">Stroke</string>
|
||||
<string name="settings_highlight_style_button_shadow">Shadow</string>
|
||||
<string name="settings_highlight_intensity_header">Intensity</string>
|
||||
<string name="settings_highlight_colour_header">Highlight colour</string>
|
||||
<string name="settings_highlight_colour_dialog_title">Pick a highlight colour</string>
|
||||
<string name="settings_highlight_transparency_header">Opacity</string>
|
||||
|
||||
<string name="settings_widget_header">Widget</string>
|
||||
|
||||
Reference in New Issue
Block a user