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)