Implemented text opacity setting

This commit is contained in:
denizk0461
2023-05-08 12:17:32 +02:00
parent f95ed24abc
commit d51cef64bb
2 changed files with 57 additions and 69 deletions
@@ -72,7 +72,8 @@ class QuoteStorage(context: Context) {
// Pair<text colour, background colour> // Pair<text colour, background colour>
fun getColours( fun getColours(
isInverted: Boolean = isInvertedEnabled(), isInverted: Boolean = isInvertedEnabled(),
transparency: Int = getBackgroundTransparency(), textTransparency: Int = getTextTransparency(),
bgTransparency: Int = getBackgroundTransparency(),
context: Context context: Context
): Pair<Int, Int> { ): Pair<Int, Int> {
val colours = when (isInverted) { val colours = when (isInverted) {
@@ -81,8 +82,8 @@ class QuoteStorage(context: Context) {
} }
return Pair( return Pair(
context.getColor(colours.first),//Color.parseColor(ColorTransparentUtils.transparentColor(colours.first, 10)), Color.parseColor(ColorTransparentUtils.transparentColor(context.getColor(colours.first), textTransparency * 5)),//Color.parseColor(ColorTransparentUtils.transparentColor(colours.first, 10)),
Color.parseColor(ColorTransparentUtils.transparentColor(context.getColor(colours.second), transparency * 5)) Color.parseColor(ColorTransparentUtils.transparentColor(context.getColor(colours.second), bgTransparency * 5))
) )
} }
@@ -121,17 +121,6 @@ class CanvasText {
} }
val rounding = 24f val rounding = 24f
// val rect = roundedRect(
// boundsText.left + x - padding,
// boundsText.top + y - padding,
// boundsText.right + x + padding,
// boundsText.bottom + y + padding, rounding, rounding
// )
// val rect = roundedRect(
// 0f, 0f, boundsText.right.toFloat() / 2, staticLayout.height.toFloat(),
// rounding, rounding
// )
val rect = when (widgetGravity) { // right val rect = when (widgetGravity) { // right
2, 5, 8 -> roundedRect( 2, 5, 8 -> roundedRect(
-boundsText.right.toFloat() - 4f, 0f, 0f, staticLayout.height.toFloat(), -boundsText.right.toFloat() - 4f, 0f, 0f, staticLayout.height.toFloat(),
@@ -169,69 +158,67 @@ class CanvasText {
val strokeStaticLayout = StaticLayout.Builder val strokeStaticLayout = StaticLayout.Builder
.obtain(quote, 0, quote.length, strokePaint, if (isPreview) 1024 else widgetSize.first * 3).build() .obtain(quote, 0, quote.length, strokePaint, if (isPreview) 1024 else widgetSize.first * 3).build()
strokeStaticLayout.draw(canvas) strokeStaticLayout.draw(canvas)
// canvas.drawText(quote, x, y, strokePaint)
} }
} }
staticLayout.draw(canvas) staticLayout.draw(canvas)
// canvas.drawText(quote, x, y, paint)
return bmp return bmp
} }
private fun calculateWidgetGravity(widgetGravity: Int, bitmap: Bitmap, boundsText: Rect, isPreview: Boolean) : Pair<Float, Float> { // private fun calculateWidgetGravity(widgetGravity: Int, bitmap: Bitmap, boundsText: Rect, isPreview: Boolean) : Pair<Float, Float> {
return if (isPreview) { // return if (isPreview) {
Pair((bitmap.width - boundsText.width()) / 2f, (bitmap.height + boundsText.height()) / 2f) // Pair((bitmap.width - boundsText.width()) / 2f, (bitmap.height + boundsText.height()) / 2f)
} else when (widgetGravity) { // } else when (widgetGravity) {
0 -> { // top left // 0 -> { // top left
Pair(0f + boundsText.left, (boundsText.height() - boundsText.top).toFloat()) // Pair(0f + boundsText.left, (boundsText.height() - boundsText.top).toFloat())
} // }
1 -> { // top center // 1 -> { // top center
Pair( // Pair(
(bitmap.width - boundsText.width()) / 2f, // (bitmap.width - boundsText.width()) / 2f,
(boundsText.height() - boundsText.top).toFloat() // (boundsText.height() - boundsText.top).toFloat()
) // )
} // }
2 -> { // top right // 2 -> { // top right
Pair( // Pair(
(bitmap.width - (boundsText.right)).toFloat(), // (bitmap.width - (boundsText.right)).toFloat(),
(boundsText.height() - boundsText.top).toFloat() // (boundsText.height() - boundsText.top).toFloat()
) // )
} // }
3 -> { // center left // 3 -> { // center left
Pair(0f + boundsText.left, (bitmap.height + boundsText.height()) / 2f) // Pair(0f + boundsText.left, (bitmap.height + boundsText.height()) / 2f)
} // }
// 4 == else branch // // 4 == else branch
5 -> { // center right // 5 -> { // center right
Pair( // Pair(
(bitmap.width - (boundsText.right)).toFloat(), // (bitmap.width - (boundsText.right)).toFloat(),
(bitmap.height + boundsText.height()) / 2f // (bitmap.height + boundsText.height()) / 2f
) // )
} // }
6 -> { // bottom left // 6 -> { // bottom left
Pair(0f + boundsText.left, (bitmap.height - boundsText.bottom).toFloat()) // Pair(0f + boundsText.left, (bitmap.height - boundsText.bottom).toFloat())
} // }
7 -> { // bottom center // 7 -> { // bottom center
Pair( // Pair(
(bitmap.width - boundsText.width()) / 2f, // (bitmap.width - boundsText.width()) / 2f,
(bitmap.height - boundsText.bottom).toFloat() // (bitmap.height - boundsText.bottom).toFloat()
) // )
} // }
8 -> { // bottom right // 8 -> { // bottom right
Pair( // Pair(
(bitmap.width - (boundsText.right)).toFloat(), // (bitmap.width - (boundsText.right)).toFloat(),
(bitmap.height - boundsText.bottom).toFloat() // (bitmap.height - boundsText.bottom).toFloat()
) // )
} // }
else -> { // center center LIKE 4 // else -> { // center center LIKE 4
Pair( // Pair(
(bitmap.width - boundsText.width()) / 2f, // (bitmap.width - boundsText.width()) / 2f,
(bitmap.height + boundsText.height()) / 2f // (bitmap.height + boundsText.height()) / 2f
) // )
} // }
} // }
} // }
fun roundedRect( private fun roundedRect(
left: Float, top: Float, right: Float, bottom: Float, left: Float, top: Float, right: Float, bottom: Float,
roundingX: Float, roundingY: Float roundingX: Float, roundingY: Float
): Path { ): Path {