Restored option to center widget text; added option to change text opacity (currently non-functional)

This commit is contained in:
denizk0461
2023-05-08 12:05:56 +02:00
parent 94ac9aaf03
commit f95ed24abc
6 changed files with 111 additions and 95 deletions
@@ -17,7 +17,8 @@ class QuoteStorage(context: Context) {
private const val KEY_TEXT_SIZE = "textsize"
private const val KEY_INVERTED = "inverted"
private const val KEY_HIGH_CONTRAST = "hicontrast"
private const val KEY_TRANSPARENCY = "transparency"
private const val KEY_TEXT_TRANSPARENCY = "transparency_text"
private const val KEY_BG_TRANSPARENCY = "transparency"
private const val KEY_RANDOM = "random"
private const val KEY_WIDGET_POSITION = "widgetposition"
private const val KEY_BACKGROUND_TYPE = "backgroundtype"
@@ -51,10 +52,8 @@ class QuoteStorage(context: Context) {
fun getTextSize() = prefs.getInt(KEY_TEXT_SIZE, 18)
fun isInvertedEnabled(): Boolean = prefs.getBoolean(KEY_INVERTED, false)
// TODO remove high contrast option once custom colours have been implemented
fun isHighContrastEnabled(): Boolean = prefs.getBoolean(KEY_HIGH_CONTRAST, false)
fun getTransparency(): Int = prefs.getInt(KEY_TRANSPARENCY, 100)
fun getTextTransparency(): Int = prefs.getInt(KEY_TEXT_TRANSPARENCY, 100)
fun getBackgroundTransparency(): Int = prefs.getInt(KEY_BG_TRANSPARENCY, 100)
fun isOrderRandom(): Boolean = prefs.getBoolean(KEY_RANDOM, false)
fun getWidgetGravity(): Int = prefs.getInt(KEY_WIDGET_POSITION, 1)
fun getBackgroundType(): Int = prefs.getInt(KEY_BACKGROUND_TYPE, 0)
@@ -73,7 +72,7 @@ class QuoteStorage(context: Context) {
// Pair<text colour, background colour>
fun getColours(
isInverted: Boolean = isInvertedEnabled(),
transparency: Int = getTransparency(),
transparency: Int = getBackgroundTransparency(),
context: Context
): Pair<Int, Int> {
val colours = when (isInverted) {
@@ -97,14 +96,22 @@ class QuoteStorage(context: Context) {
fun getSize(): Pair<Int, Int> = Pair(prefs.getInt(KEY_AVG_WIDTH, 1), prefs.getInt(KEY_AVG_HEIGHT, 1))
fun saveSettings(
textSize: Int, inverted: Boolean, transparency: Int, random: Boolean,
widgetPosition: Int, backgroundType: Int, typefaceIndex: Int, typefaceStyleIndex: Int,
textSize: Int,
inverted: Boolean,
textTransparency: Int,
bgTransparency: Int,
random: Boolean,
widgetPosition: Int,
backgroundType: Int,
typefaceIndex: Int,
typefaceStyleIndex: Int,
outlineSize: Float
) {
prefs.edit().apply {
putInt(KEY_TEXT_SIZE, textSize)
putBoolean(KEY_INVERTED, inverted)
putInt(KEY_TRANSPARENCY, transparency)
putInt(KEY_TEXT_TRANSPARENCY, textTransparency)
putInt(KEY_BG_TRANSPARENCY, bgTransparency)
putBoolean(KEY_RANDOM, random)
putInt(KEY_WIDGET_POSITION, widgetPosition)
putInt(KEY_BACKGROUND_TYPE, backgroundType)
@@ -66,7 +66,7 @@ class SettingsFragment : BaseFragment(R.layout.fragment_settings) {
}
}
binding.transparencyPicker.apply {
binding.textTransparencyPicker.apply {
minValue = 0
maxValue = 20
val formatter = NumberPicker.Formatter { value ->
@@ -76,12 +76,35 @@ class SettingsFragment : BaseFragment(R.layout.fragment_settings) {
setFormatter(formatter)
descendantFocusability = ViewGroup.FOCUS_BLOCK_DESCENDANTS
wrapSelectorWheel = false
value = storage.getTransparency()
value = storage.getBackgroundTransparency()
// Do not touch - fix for value on spinner not showing up until touched
val f: Field = NumberPicker::class.java.getDeclaredField("mInputText")
f.isAccessible = true
val inputText: EditText = f.get(binding.transparencyPicker) as EditText
val inputText: EditText = f.get(binding.textTransparencyPicker) as EditText
inputText.filters = arrayOfNulls(0)
setOnValueChangedListener { _, _, _ ->
updatePreview()
}
}
binding.bgTransparencyPicker.apply {
minValue = 0
maxValue = 20
val formatter = NumberPicker.Formatter { value ->
val temp = value * 5
"" + temp
}
setFormatter(formatter)
descendantFocusability = ViewGroup.FOCUS_BLOCK_DESCENDANTS
wrapSelectorWheel = false
value = storage.getBackgroundTransparency()
// Do not touch - fix for value on spinner not showing up until touched
val f: Field = NumberPicker::class.java.getDeclaredField("mInputText")
f.isAccessible = true
val inputText: EditText = f.get(binding.bgTransparencyPicker) as EditText
inputText.filters = arrayOfNulls(0)
setOnValueChangedListener { _, _, _ ->
@@ -117,31 +140,6 @@ class SettingsFragment : BaseFragment(R.layout.fragment_settings) {
}
}
// binding.switchHighContrast.apply {
// isChecked = storage.isHighContrastEnabled()
//
// setOnCheckedChangeListener { _, _ ->
// updatePreview()
// }
// }
// binding.typefaceMenuTextview.apply {
// typefaceIndex = storage.getTypefaceIndex()
// val typefaces = context.resources.getStringArray(R.array.typefaces)
// val typefaceAdapter = ArrayAdapter(
// context,
// android.R.layout.simple_dropdown_item_1line,
// typefaces
// )
// setAdapter(typefaceAdapter)
// setText(typefaces[typefaceIndex], false)
//
// setOnItemClickListener { adapterView, view, index, l ->
// typefaceIndex = index
// updatePreview()
// }
// }
binding.typefaceToggleButton.apply {
typefaceIndex = storage.getTypefaceIndex()
@@ -244,36 +242,13 @@ class SettingsFragment : BaseFragment(R.layout.fragment_settings) {
}
}
// val isBackgroundDark = if (storage.isInvertedEnabled()) { // bg white
// (storage.getTransparency() * 5) <= 5
// } else { // bg black
// (storage.getTransparency() * 5) > 5
// }
// Log.d("ASDF", isBackgroundDark.toString())
// binding.textPreviewBackground.setBackgroundColor(
// Color.parseColor(ColorTransparentUtils.transparentColor(context.getColor(if (isBackgroundDark) {
// R.color.md_theme_light_background
// } else {
// R.color.md_theme_dark_background
// }), storage.getTransparency() * 5)))
// binding.textPreviewBackground.setBackgroundColor(
// storage.getColours(
// !storage.isInvertedEnabled(),
// abs(storage.getTransparency() - 100),
// context = context
// ).second
// )
binding.textPreviewBackgroundDark.setBackgroundColor(
Color.parseColor(ColorTransparentUtils.transparentColor(
context.getColor(R.color.md_theme_dark_background),
if (storage.isInvertedEnabled()) {
abs((storage.getTransparency() * 5))
abs((storage.getBackgroundTransparency() * 5))
} else {
abs((storage.getTransparency() * 5) - 100)
abs((storage.getBackgroundTransparency() * 5) - 100)
}
))
)
@@ -281,26 +256,14 @@ class SettingsFragment : BaseFragment(R.layout.fragment_settings) {
val bitmap = CanvasText.drawText(context, true)
binding.textPreview.setImageBitmap(bitmap)
// val colours = storage.getColours(
// binding.switchInvert.isChecked,
//// binding.switchHighContrast.isChecked,
// binding.transparencyPicker.value,
// context
// )
//// binding.exampleText.textSize = binding.textSizePicker.value.toFloat()
// binding.exampleText.setTextColor(colours.first)
// binding.background.setBackgroundColor(colours.second)
// Log.d("VALVALUE", "${(binding.transparencyPicker.value * 5).toString()} /// ${colours.second}")
}
private fun save() {
storage.saveSettings(
binding.textSizePicker.value,
binding.switchInvert.isChecked,
// binding.switchHighContrast.isChecked,
binding.transparencyPicker.value,
binding.textTransparencyPicker.value,
binding.bgTransparencyPicker.value,
binding.switchRandom.isChecked,
widgetGravity,
backgroundIndex,
@@ -71,46 +71,44 @@ class CanvasText {
val boundsText = Rect()
paint.getTextBounds(quote, 0, quote.length, boundsText)
val (x, y) = calculateWidgetGravity(storage.getWidgetGravity(), bmp, boundsText, isPreview)
// val x = canvas.width / 2
// val y = ((canvas.getHeight() / 2) - ((paint.descent() + paint.ascent()) / 2))
val padding = 16f
val alignment = when (widgetGravity) {
0 -> {
0 -> { // Align TOP LEFT
canvas.translate(boundsText.left.toFloat() + padding, 0f)
Paint.Align.LEFT
}
1 -> {
1 -> { // Align TOP CENTER
canvas.translate(canvas.width / 2f, 0f)
Paint.Align.CENTER
}
2 -> {
2 -> { // Align TOP RIGHT
canvas.translate(canvas.width.toFloat() - padding, 0f)
Paint.Align.RIGHT
}
3 -> {
canvas.translate(boundsText.left.toFloat() + padding, 0f)
3 -> { // Align CENTER LEFT
canvas.translate(boundsText.left.toFloat() + padding, (bmp.height.toFloat() / 2) - (staticLayout.height / 2))
Paint.Align.LEFT
}
5 -> {
canvas.translate(canvas.width.toFloat() - padding, 0f)
// 4 is defined further below
5 -> { // Align CENTER RIGHT
canvas.translate(canvas.width.toFloat() - padding, (bmp.height.toFloat() / 2) - (staticLayout.height / 2))
Paint.Align.RIGHT
}
6 -> {
6 -> { // Align BOTTOM LEFT
canvas.translate(boundsText.left.toFloat() + padding, bmp.height.toFloat() - staticLayout.height - padding)
Paint.Align.LEFT
}
7 -> {
7 -> { // Align BOTTOM CENTER
canvas.translate(canvas.width / 2f, bmp.height.toFloat() - staticLayout.height - padding)
Paint.Align.CENTER
}
8 -> {
8 -> { // Align BOTTOM RIGHT
canvas.translate(canvas.width.toFloat() - padding, bmp.height.toFloat() - staticLayout.height - padding)
Paint.Align.RIGHT
}
else -> { // 4
canvas.translate(canvas.width / 2f, 0f)
else -> { // 4; Align CENTER
canvas.translate(canvas.width / 2f, (bmp.height.toFloat() / 2) - (staticLayout.height / 2))
Paint.Align.CENTER
}
}
+26 -2
View File
@@ -42,13 +42,27 @@
<com.denizd.textbasic.VerticalTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/opacity"
android:text="@string/text_opacity"
android:textSize="12sp"
android:fontFamily="@font/mono_light"
android:padding="4dp"/>
<NumberPicker
android:id="@+id/transparency_picker"
android:id="@+id/text_transparency_picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="4dp"/>
<com.denizd.textbasic.VerticalTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/bg_opacity"
android:textSize="12sp"
android:fontFamily="@font/mono_light"
android:padding="4dp"/>
<NumberPicker
android:id="@+id/bg_transparency_picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="4dp"/>
@@ -287,6 +301,7 @@
android:id="@+id/text_preview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="@string/widget_preview_content_desc"
android:paddingHorizontal="4dp"/>
</LinearLayout>
@@ -340,6 +355,7 @@
android:layout_height="wrap_content"
android:src="@drawable/arrow_top_left"
android:background="@android:color/transparent"
android:contentDescription="@string/position_button_content_desc_tl"
android:padding="@dimen/orientation_button_padding"/>
<ImageButton
@@ -348,6 +364,7 @@
android:layout_height="wrap_content"
android:src="@drawable/arrow_top"
android:background="@android:color/transparent"
android:contentDescription="@string/position_button_content_desc_tc"
android:padding="@dimen/orientation_button_padding"/>
<ImageButton
@@ -356,6 +373,7 @@
android:layout_height="wrap_content"
android:src="@drawable/arrow_top_right"
android:background="@android:color/transparent"
android:contentDescription="@string/position_button_content_desc_tr"
android:padding="@dimen/orientation_button_padding"/>
</LinearLayout>
@@ -372,6 +390,7 @@
android:layout_height="wrap_content"
android:src="@drawable/arrow_left"
android:background="@android:color/transparent"
android:contentDescription="@string/position_button_content_desc_cl"
android:padding="@dimen/orientation_button_padding"/>
<ImageButton
@@ -380,6 +399,7 @@
android:layout_height="wrap_content"
android:src="@drawable/dot"
android:background="@android:color/transparent"
android:contentDescription="@string/position_button_content_desc_cc"
android:padding="@dimen/orientation_button_padding"/>
<ImageButton
@@ -388,6 +408,7 @@
android:layout_height="wrap_content"
android:src="@drawable/arrow_right"
android:background="@android:color/transparent"
android:contentDescription="@string/position_button_content_desc_cr"
android:padding="@dimen/orientation_button_padding"/>
</LinearLayout>
@@ -404,6 +425,7 @@
android:layout_height="wrap_content"
android:src="@drawable/arrow_bottom_left"
android:background="@android:color/transparent"
android:contentDescription="@string/position_button_content_desc_bl"
android:padding="@dimen/orientation_button_padding"/>
<ImageButton
@@ -412,6 +434,7 @@
android:layout_height="wrap_content"
android:src="@drawable/arrow_bottom"
android:background="@android:color/transparent"
android:contentDescription="@string/position_button_content_desc_bc"
android:padding="@dimen/orientation_button_padding"/>
<ImageButton
@@ -420,6 +443,7 @@
android:layout_height="wrap_content"
android:src="@drawable/arrow_bottom_right"
android:background="@android:color/transparent"
android:contentDescription="@string/position_button_content_desc_br"
android:padding="@dimen/orientation_button_padding"/>
</LinearLayout>
+13 -1
View File
@@ -4,7 +4,8 @@
<string name="enter_text">Gib etwas ein…</string>
<string name="example_text">Dies ist ein Beispieltext</string>
<string name="text_size">Textgröße</string>
<string name="opacity">Opazität</string>
<string name="text_opacity">Textopazität</string>
<string name="bg_opacity">Hintergrundopazität</string>
<string name="thickness">Dicke</string>
<string name="intensity">Stärke</string>
<string name="invert">Farben umkehren</string>
@@ -20,6 +21,17 @@
<string name="position">Position</string>
<string name="widget_preview_content_desc">Vorschau für das Widget</string>
<string name="position_button_content_desc_tl">Positioniere Widget oben links</string>
<string name="position_button_content_desc_tc">Positioniere Widget oben zentriert</string>
<string name="position_button_content_desc_tr">Positioniere Widget oben rechts</string>
<string name="position_button_content_desc_cl">Positioniere Widget zentriert links</string>
<string name="position_button_content_desc_cc">Positioniere Widget zentriert</string>
<string name="position_button_content_desc_cr">Positioniere Widget zentriert rechts</string>
<string name="position_button_content_desc_bl">Positioniere Widget unten links</string>
<string name="position_button_content_desc_bc">Positioniere Widget unten zentriert</string>
<string name="position_button_content_desc_br">Positioniere Widget unten rechts</string>
<string name="sansserif">Sans-Serif</string>
<string name="serif">Serif</string>
<string name="monospace">Monospace</string>
+13 -1
View File
@@ -3,7 +3,8 @@
<string name="enter_text">Enter something…</string>
<string name="example_text">This is an example text</string>
<string name="text_size">text size</string>
<string name="opacity">opacity</string>
<string name="text_opacity">text opacity</string>
<string name="bg_opacity">bg opacity</string>
<string name="thickness">thickness</string>
<string name="intensity">intensity</string>
<string name="invert">Invert colours</string>
@@ -19,6 +20,17 @@
<string name="position">position</string>
<string name="widget_preview_content_desc">Preview for the widget</string>
<string name="position_button_content_desc_tl">Position widget at top left</string>
<string name="position_button_content_desc_tc">Position widget at top center</string>
<string name="position_button_content_desc_tr">Position widget at top right</string>
<string name="position_button_content_desc_cl">Position widget at center left</string>
<string name="position_button_content_desc_cc">Position widget at center</string>
<string name="position_button_content_desc_cr">Position widget at center right</string>
<string name="position_button_content_desc_bl">Position widget at bottom left</string>
<string name="position_button_content_desc_bc">Position widget at bottom center</string>
<string name="position_button_content_desc_br">Position widget at bottom right</string>
<string name="sansserif">Sans-Serif</string>
<string name="serif">Serif</string>
<string name="monospace">Monospace</string>