Implemented functionality in settings for text style, size, opacity, highlight style, intensity, opacity, and order

This commit is contained in:
denizk0461
2023-05-16 09:49:16 +02:00
parent 8454d4f924
commit 7b598903ae
7 changed files with 124 additions and 30 deletions
@@ -41,6 +41,7 @@ class QuoteStorage private constructor(context: Context) {
private const val KEY_AVG_WIDTH = "avgwidth"
private const val KEY_AVG_HEIGHT = "avgheight"
private const val KEY_OUTLINE_SIZE = "outlinesize"
const val KEY_OUTLINE_SIZE_NEW = "outlinesizeint"
}
private val prefs = context.getSharedPreferences(PREF_NAME, 0)
@@ -108,13 +109,19 @@ class QuoteStorage private constructor(context: Context) {
2 -> Typeface.MONOSPACE
else -> Typeface.SANS_SERIF
},
getTypefaceStyle()
when (getTypefaceStyle()) {
1 -> Typeface.BOLD
2 -> Typeface.ITALIC
3 -> Typeface.BOLD_ITALIC
else -> Typeface.NORMAL
}
)
fun getTypefaceStyle(): Int = prefs.getInt(KEY_TYPEFACE_STYLE, 0)
fun setTypefaceStyle(newValue: Int) {
prefs.edit().putInt(KEY_TYPEFACE_STYLE, newValue).apply()
}
fun getOutlineSize(): Float = prefs.getFloat(KEY_OUTLINE_SIZE, 8f)
fun getOutlineSizeNew(): Int = prefs.getInt(KEY_OUTLINE_SIZE_NEW, 8)
// Pair<text colour, background colour>
fun getColours(
@@ -132,13 +139,13 @@ class QuoteStorage private constructor(context: Context) {
Color.parseColor(
ColorTransparentUtils.transparentColor(
context.getColor(colours.first),
textTransparency * 5
textTransparency,
)
),//Color.parseColor(ColorTransparentUtils.transparentColor(colours.first, 10)),
Color.parseColor(
ColorTransparentUtils.transparentColor(
context.getColor(colours.second),
bgTransparency * 5
bgTransparency,
)
)
)
@@ -10,6 +10,7 @@ import com.denizd.textbasic.databinding.FragmentSettingsNewBinding
import com.denizd.textbasic.db.QuoteStorage
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
class SettingsNewFragment : BaseFragment(R.layout.fragment_settings_new) {
@@ -23,6 +24,9 @@ class SettingsNewFragment : BaseFragment(R.layout.fragment_settings_new) {
storage = QuoteStorage.getInstance(context)
// --- text font --- //
// --- font style --- //
binding.toggleGroupFont.apply {
check(when (storage.getTypefaceStyle()) {
@@ -40,6 +44,8 @@ class SettingsNewFragment : BaseFragment(R.layout.fragment_settings_new) {
R.id.toggle_button_font_bold_italic -> 3
else -> 0
})
updatePreview()
}
}
}
@@ -118,25 +124,70 @@ class SettingsNewFragment : BaseFragment(R.layout.fragment_settings_new) {
// --- highlight style --- //
binding.toggleGroupHighlightStyle.apply {
check(when (storage.getBackgroundType()) {
0 -> R.id.toggle_button_highlight_background
1 -> R.id.toggle_button_highlight_stroke
2 -> R.id.toggle_button_highlight_shadow
else -> R.id.toggle_button_highlight_none // 3
})
check(checkBackgroundIntensity(storage.getBackgroundType()))
addOnButtonCheckedListener { _, checkedId, isChecked ->
if (isChecked) {
storage.setBackgroundType(when (checkedId) {
R.id.toggle_button_highlight_background -> 0
R.id.toggle_button_highlight_stroke -> 1
R.id.toggle_button_highlight_shadow -> 2
else -> 3 // none
})
when (checkedId) {
R.id.toggle_button_highlight_background -> {
storage.setBackgroundType(0)
checkBackgroundIntensity(0)
}
R.id.toggle_button_highlight_stroke -> {
storage.setBackgroundType(1)
checkBackgroundIntensity(1)
}
R.id.toggle_button_highlight_shadow -> {
storage.setBackgroundType(2)
checkBackgroundIntensity(2)
}
else -> {
storage.setBackgroundType(3)
checkBackgroundIntensity(3)
} // none
}
updatePreview()
}
}
}
// --- highlight intensity --- //
binding.textIntensity.text = storage.getInt(SettingsPreference.HIGHLIGHT_INTENSITY, 100).toString()
binding.buttonIntensityDecreaseFast.setOnClickAction(
0,
100,
isPositive = false,
isFast = true,
binding.textIntensity,
SettingsPreference.HIGHLIGHT_INTENSITY,
)
binding.buttonIntensityDecrease.setOnClickAction(
0,
100,
isPositive = false,
isFast = false,
binding.textIntensity,
SettingsPreference.HIGHLIGHT_INTENSITY,
)
binding.buttonIntensityIncrease.setOnClickAction(
0,
100,
isPositive = true,
isFast = false,
binding.textIntensity,
SettingsPreference.HIGHLIGHT_INTENSITY,
)
binding.buttonIntensityIncreaseFast.setOnClickAction(
0,
100,
isPositive = true,
isFast = true,
binding.textIntensity,
SettingsPreference.HIGHLIGHT_INTENSITY,
)
// --- text highlight transparency --- //
binding.textHighlightTransparency.text = storage.getInt(SettingsPreference.HIGHLIGHT_TRANSPARENCY, 100).toString()
@@ -189,6 +240,31 @@ class SettingsNewFragment : BaseFragment(R.layout.fragment_settings_new) {
@SuppressLint("SetTextI18n")
binding.appVersionText.text =
"${BuildConfig.VERSION_NAME}-${if (BuildConfig.DEBUG) "dev" else "release"}"
updatePreview()
}
/**
* Retrieves which button to check for the highlight, and sets the visibility of the intensity
* modifying layout accordingly.
*/
private fun checkBackgroundIntensity(index: Int): Int = when (index) {
0 -> { // background
binding.layoutIntensity.visibility = View.GONE
R.id.toggle_button_highlight_background
}
1 -> { // stroke
binding.layoutIntensity.visibility = View.VISIBLE
R.id.toggle_button_highlight_stroke
}
2 -> { // shadow
binding.layoutIntensity.visibility = View.VISIBLE
R.id.toggle_button_highlight_shadow
}
else -> { // none
binding.layoutIntensity.visibility = View.GONE
R.id.toggle_button_highlight_none
}
}
// TODO horrible, horrible, horrible function. but it works. fix this in the future. please.
@@ -223,6 +299,15 @@ class SettingsNewFragment : BaseFragment(R.layout.fragment_settings_new) {
storage.setInt(pref, value)
textField.text = value.toString()
updatePreview()
}
}
private fun updatePreview() {
val bitmap = CanvasText.drawText(context, true)
binding.textPreview.setImageBitmap(bitmap)
}
}
@@ -5,7 +5,7 @@ import com.denizd.textbasic.db.QuoteStorage
enum class SettingsPreference(val key: String) {
TEXT_SIZE(QuoteStorage.KEY_TEXT_SIZE),
TEXT_TRANSPARENCY(QuoteStorage.KEY_TEXT_TRANSPARENCY),
HIGHLIGHT_INTENSITY(""), // TODO
HIGHLIGHT_INTENSITY(QuoteStorage.KEY_OUTLINE_SIZE_NEW), // TODO
HIGHLIGHT_TRANSPARENCY(QuoteStorage.KEY_BG_TRANSPARENCY),
;
}
@@ -22,7 +22,7 @@ class CanvasText {
}
val widgetSize = storage.getSize()
val outlineSize = storage.getOutlineSize()
val outlineSize = storage.getOutlineSizeNew().toFloat()
val bmp = if (isPreview) {
Bitmap.createBitmap(1024, 256, Bitmap.Config.ARGB_8888)
@@ -30,14 +30,14 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="@color/md_theme_light_background"
app:layout_scrollFlags="scroll|snap">
<!-- android:background="@color/md_theme_light_background"-->
<LinearLayout
android:id="@+id/text_preview_background_dark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/md_theme_dark_background">
<!-- <LinearLayout-->
<!-- android:id="@+id/text_preview_background_dark"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:background="@color/md_theme_dark_background">-->
<ImageView
android:id="@+id/text_preview"
@@ -46,7 +46,7 @@
android:contentDescription="@string/widget_preview_content_desc"
android:paddingHorizontal="4dp"/>
</LinearLayout>
<!-- </LinearLayout>-->
</LinearLayout>
@@ -387,7 +387,8 @@
android:layout_marginEnd="8dp"
android:orientation="vertical"
android:paddingHorizontal="16dp"
android:paddingVertical="8dp">
android:paddingVertical="8dp"
android:animateLayoutChanges="true">
<TextView
android:layout_width="wrap_content"
@@ -454,6 +455,7 @@
<!-- Highlight intensity -->
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/layout_intensity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
+3 -3
View File
@@ -34,7 +34,7 @@
<string name="settings_text_style_button_italic">Kursiv</string>
<string name="settings_text_style_button_bolditalic">Fett &amp; Kursiv</string>
<string name="settings_text_size_header">Textgröße</string>
<string name="settings_text_transparency_header">Texttransparenz</string>
<string name="settings_text_transparency_header">Textopazität</string>
<string name="settings_highlight_header">Highlight-Stil</string>
<string name="settings_highlight_style_header">Stil</string>
@@ -43,11 +43,11 @@
<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_transparency_header">Highlight-Transparenz</string>
<string name="settings_highlight_transparency_header">Highlight-Opazität</string>
<string name="settings_widget_header">Widget</string>
<string name="settings_widget_order_title">Nutze zufällige Reihenfolge</string>
<string name="settings_widget_order_subtitle">Sonst wird die Reihenfolge der Liste genutzt; ändere sie durch D rag &amp; Drop</string>
<string name="settings_widget_order_subtitle">Sonst wird die Reihenfolge der Liste genutzt; ändere sie durch Drag &amp; Drop</string>
<string name="settings_widget_order_default">Standard</string>
<string name="settings_widget_order_random">Zufall</string>
<string name="settings_widget_position_title">Setze Position des Texts</string>
+2 -2
View File
@@ -33,7 +33,7 @@
<string name="settings_text_style_button_italic">Italic</string>
<string name="settings_text_style_button_bolditalic">Bold &amp; Italic</string>
<string name="settings_text_size_header">Text size</string>
<string name="settings_text_transparency_header">Text transparency</string>
<string name="settings_text_transparency_header">Text opacity</string>
<string name="settings_highlight_header">Highlight Style</string>
<string name="settings_highlight_style_header">Style</string>
@@ -42,7 +42,7 @@
<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_transparency_header">Transparency</string>
<string name="settings_highlight_transparency_header">Opacity</string>
<string name="settings_widget_header">Widget</string>
<string name="settings_widget_order_title">Randomise entry order</string>