mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-12-23 01:20:35 +03:00
Workaround for wrongly aligned textView for RTL locales
Change-Id: I77e48dbc8a0c93337d9c2d2c56025ae222d291d8
This commit is contained in:
parent
813d3679cd
commit
dee1971814
1 changed files with 20 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
||||||
package im.vector.app.core.ui.views
|
package im.vector.app.core.ui.views
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.graphics.Canvas
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import androidx.appcompat.widget.AppCompatTextView
|
import androidx.appcompat.widget.AppCompatTextView
|
||||||
import kotlin.math.ceil
|
import kotlin.math.ceil
|
||||||
|
@ -19,10 +20,16 @@ class FooteredTextView @JvmOverloads constructor(
|
||||||
var footerWidth: Int = 0
|
var footerWidth: Int = 0
|
||||||
//var widthLimit: Float = 0f
|
//var widthLimit: Float = 0f
|
||||||
|
|
||||||
|
// Workaround to RTL languages with non-RTL content messages aligning left instead of start
|
||||||
|
private var requiredHorizontalCanvasMove = 0f
|
||||||
|
|
||||||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||||
// First, let super measure the content for our normal TextView use
|
// First, let super measure the content for our normal TextView use
|
||||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
||||||
|
|
||||||
|
// Default case
|
||||||
|
requiredHorizontalCanvasMove = 0f
|
||||||
|
|
||||||
// Get max available width
|
// Get max available width
|
||||||
//val widthMode = MeasureSpec.getMode(widthMeasureSpec)
|
//val widthMode = MeasureSpec.getMode(widthMeasureSpec)
|
||||||
val widthSize = MeasureSpec.getSize(widthMeasureSpec)
|
val widthSize = MeasureSpec.getSize(widthMeasureSpec)
|
||||||
|
@ -70,6 +77,10 @@ class FooteredTextView @JvmOverloads constructor(
|
||||||
// Reserve extra horizontal footer space if necessary
|
// Reserve extra horizontal footer space if necessary
|
||||||
if (widthWithHorizontalFooter > newWidth) {
|
if (widthWithHorizontalFooter > newWidth) {
|
||||||
newWidth = ceil(widthWithHorizontalFooter).toInt()
|
newWidth = ceil(widthWithHorizontalFooter).toInt()
|
||||||
|
|
||||||
|
if (viewIsRtl) {
|
||||||
|
requiredHorizontalCanvasMove = widthWithHorizontalFooter - measuredWidth
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Reserve vertical footer space
|
// Reserve vertical footer space
|
||||||
|
@ -78,4 +89,13 @@ class FooteredTextView @JvmOverloads constructor(
|
||||||
|
|
||||||
setMeasuredDimension(newWidth, newHeight)
|
setMeasuredDimension(newWidth, newHeight)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onDraw(canvas: Canvas?) {
|
||||||
|
// Workaround to RTL languages with non-RTL content messages aligning left instead of start
|
||||||
|
if (requiredHorizontalCanvasMove > 0f) {
|
||||||
|
canvas?.translate(requiredHorizontalCanvasMove, 0f)
|
||||||
|
}
|
||||||
|
|
||||||
|
super.onDraw(canvas)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue