Archived
Implemented functionality to pick a font, currently limited to 3 default fonts (sans-serif, serif, monospace)
This commit is contained in:
@@ -103,6 +103,9 @@ class QuoteStorage private constructor(context: Context) {
|
||||
prefs.edit().putInt(KEY_BACKGROUND_TYPE, newValue).apply()
|
||||
}
|
||||
fun getTypefaceIndex(): Int = prefs.getInt(KEY_TYPEFACE, 0)
|
||||
fun setTypefaceIndex(newValue: Int) {
|
||||
prefs.edit().putInt(KEY_TYPEFACE, newValue).apply()
|
||||
}
|
||||
fun getTypeface(): Typeface = Typeface.create(
|
||||
when (getTypefaceIndex()) {
|
||||
1 -> Typeface.SERIF
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.os.Bundle
|
||||
import android.util.TypedValue
|
||||
import android.view.View
|
||||
import android.widget.ImageButton
|
||||
import android.widget.PopupMenu
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.ColorInt
|
||||
import com.denizd.textbasic.BuildConfig
|
||||
@@ -28,7 +29,59 @@ class SettingsNewFragment : BaseFragment(R.layout.fragment_settings_new) {
|
||||
storage = QuoteStorage.getInstance(context)
|
||||
|
||||
// --- text font --- //
|
||||
// binding.autoCompleteFont.setOnClickListener {
|
||||
// // Create menu for selecting a new canteen
|
||||
// PopupMenu(binding.root.context, binding.textLayoutFont).apply {
|
||||
// setOnMenuItemClickListener { item ->
|
||||
// item?.itemId?.let { id ->
|
||||
// storage.setTypefaceStyle(id)
|
||||
// }
|
||||
//
|
||||
// // Update the preview
|
||||
// updatePreview()
|
||||
// true
|
||||
// }
|
||||
// menu.add(0, 0, 0, getString(R.string.sansserif))
|
||||
// menu.add(1, 1, 1, getString(R.string.serif))
|
||||
// menu.add(2, 2, 2, getString(R.string.monospace))
|
||||
// show()
|
||||
// }
|
||||
// }
|
||||
|
||||
// val fontAdapter = ArrayAdapter(
|
||||
// context,
|
||||
// R.layout.item_dropdown_menu,
|
||||
// resources.getStringArray(R.array.text_fonts),
|
||||
// )
|
||||
//
|
||||
// binding.autoCompleteFont.setAdapter(fontAdapter)
|
||||
|
||||
binding.autoCompleteFont
|
||||
.setText(context.resources.getStringArray(R.array.text_fonts)[storage.getTypefaceIndex()])
|
||||
|
||||
binding.autoCompleteFont.setOnClickListener {
|
||||
PopupMenu(binding.root.context, binding.autoCompleteFont).apply {
|
||||
setOnMenuItemClickListener { item ->
|
||||
item?.itemId?.let { id ->
|
||||
val index = when (id) {
|
||||
R.id.serif -> 1
|
||||
R.id.monospace -> 2
|
||||
else -> 0 // sans-serif
|
||||
}
|
||||
storage.setTypefaceIndex(index)
|
||||
|
||||
binding.autoCompleteFont
|
||||
.setText(context.resources.getStringArray(R.array.text_fonts)[index])
|
||||
}
|
||||
|
||||
// Refresh the canteen menu for the newly selected canteen
|
||||
updatePreview()
|
||||
true
|
||||
}
|
||||
inflate(R.menu.list_fonts)
|
||||
show()
|
||||
}
|
||||
}
|
||||
|
||||
// --- font style --- //
|
||||
binding.toggleGroupFont.apply {
|
||||
|
||||
Reference in New Issue
Block a user