Revert "Remove reflection to get TextView color field (closes #2469)"

This reverts commit 5f2aaeac57.
This commit is contained in:
arkon 2020-01-09 21:51:34 -05:00
parent 5f2aaeac57
commit f715478070

View file

@ -24,12 +24,12 @@ class PageIndicatorTextView(
private val strokeColor = Color.rgb(45, 45, 45) private val strokeColor = Color.rgb(45, 45, 45)
override fun onDraw(canvas: Canvas) { override fun onDraw(canvas: Canvas) {
setTextColor(strokeColor) textColorField.set(this, strokeColor)
paint.strokeWidth = 4f paint.strokeWidth = 4f
paint.style = Paint.Style.STROKE paint.style = Paint.Style.STROKE
super.onDraw(canvas) super.onDraw(canvas)
setTextColor(fillColor) textColorField.set(this, fillColor)
paint.strokeWidth = 0f paint.strokeWidth = 0f
paint.style = Paint.Style.FILL paint.style = Paint.Style.FILL
super.onDraw(canvas) super.onDraw(canvas)
@ -50,4 +50,12 @@ class PageIndicatorTextView(
super.setText(finalText, TextView.BufferType.SPANNABLE) super.setText(finalText, TextView.BufferType.SPANNABLE)
} }
private companion object {
// We need to use reflection to set the text color instead of using [setTextColor],
// otherwise the view is invalidated inside [onDraw] and there's an infinite loop
val textColorField = TextView::class.java.getDeclaredField("mCurTextColor").apply {
isAccessible = true
}!!
}
} }