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>
fun getColours(
isInverted: Boolean = isInvertedEnabled(),
transparency: Int = getBackgroundTransparency(),
textTransparency: Int = getTextTransparency(),
bgTransparency: Int = getBackgroundTransparency(),
context: Context
): Pair<Int, Int> {
val colours = when (isInverted) {
@@ -81,8 +82,8 @@ class QuoteStorage(context: Context) {
}
return Pair(
context.getColor(colours.first),//Color.parseColor(ColorTransparentUtils.transparentColor(colours.first, 10)),
Color.parseColor(ColorTransparentUtils.transparentColor(context.getColor(colours.second), transparency * 5))
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), bgTransparency * 5))
)
}
@@ -121,17 +121,6 @@ class CanvasText {
}
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
2, 5, 8 -> roundedRect(
-boundsText.right.toFloat() - 4f, 0f, 0f, staticLayout.height.toFloat(),
@@ -169,69 +158,67 @@ class CanvasText {
val strokeStaticLayout = StaticLayout.Builder
.obtain(quote, 0, quote.length, strokePaint, if (isPreview) 1024 else widgetSize.first * 3).build()
strokeStaticLayout.draw(canvas)
// canvas.drawText(quote, x, y, strokePaint)
}
}
staticLayout.draw(canvas)
// canvas.drawText(quote, x, y, paint)
return bmp
}
private fun calculateWidgetGravity(widgetGravity: Int, bitmap: Bitmap, boundsText: Rect, isPreview: Boolean) : Pair<Float, Float> {
return if (isPreview) {
Pair((bitmap.width - boundsText.width()) / 2f, (bitmap.height + boundsText.height()) / 2f)
} else when (widgetGravity) {
0 -> { // top left
Pair(0f + boundsText.left, (boundsText.height() - boundsText.top).toFloat())
}
1 -> { // top center
Pair(
(bitmap.width - boundsText.width()) / 2f,
(boundsText.height() - boundsText.top).toFloat()
)
}
2 -> { // top right
Pair(
(bitmap.width - (boundsText.right)).toFloat(),
(boundsText.height() - boundsText.top).toFloat()
)
}
3 -> { // center left
Pair(0f + boundsText.left, (bitmap.height + boundsText.height()) / 2f)
}
// 4 == else branch
5 -> { // center right
Pair(
(bitmap.width - (boundsText.right)).toFloat(),
(bitmap.height + boundsText.height()) / 2f
)
}
6 -> { // bottom left
Pair(0f + boundsText.left, (bitmap.height - boundsText.bottom).toFloat())
}
7 -> { // bottom center
Pair(
(bitmap.width - boundsText.width()) / 2f,
(bitmap.height - boundsText.bottom).toFloat()
)
}
8 -> { // bottom right
Pair(
(bitmap.width - (boundsText.right)).toFloat(),
(bitmap.height - boundsText.bottom).toFloat()
)
}
else -> { // center center LIKE 4
Pair(
(bitmap.width - boundsText.width()) / 2f,
(bitmap.height + boundsText.height()) / 2f
)
}
}
}
// private fun calculateWidgetGravity(widgetGravity: Int, bitmap: Bitmap, boundsText: Rect, isPreview: Boolean) : Pair<Float, Float> {
// return if (isPreview) {
// Pair((bitmap.width - boundsText.width()) / 2f, (bitmap.height + boundsText.height()) / 2f)
// } else when (widgetGravity) {
// 0 -> { // top left
// Pair(0f + boundsText.left, (boundsText.height() - boundsText.top).toFloat())
// }
// 1 -> { // top center
// Pair(
// (bitmap.width - boundsText.width()) / 2f,
// (boundsText.height() - boundsText.top).toFloat()
// )
// }
// 2 -> { // top right
// Pair(
// (bitmap.width - (boundsText.right)).toFloat(),
// (boundsText.height() - boundsText.top).toFloat()
// )
// }
// 3 -> { // center left
// Pair(0f + boundsText.left, (bitmap.height + boundsText.height()) / 2f)
// }
// // 4 == else branch
// 5 -> { // center right
// Pair(
// (bitmap.width - (boundsText.right)).toFloat(),
// (bitmap.height + boundsText.height()) / 2f
// )
// }
// 6 -> { // bottom left
// Pair(0f + boundsText.left, (bitmap.height - boundsText.bottom).toFloat())
// }
// 7 -> { // bottom center
// Pair(
// (bitmap.width - boundsText.width()) / 2f,
// (bitmap.height - boundsText.bottom).toFloat()
// )
// }
// 8 -> { // bottom right
// Pair(
// (bitmap.width - (boundsText.right)).toFloat(),
// (bitmap.height - boundsText.bottom).toFloat()
// )
// }
// else -> { // center center LIKE 4
// Pair(
// (bitmap.width - boundsText.width()) / 2f,
// (bitmap.height + boundsText.height()) / 2f
// )
// }
// }
// }
fun roundedRect(
private fun roundedRect(
left: Float, top: Float, right: Float, bottom: Float,
roundingX: Float, roundingY: Float
): Path {