From fbf75e12636c05cfd794cd04e89ca0edd5cb1344 Mon Sep 17 00:00:00 2001 From: Oliver Woodman Date: Fri, 6 Feb 2015 11:31:13 +0000 Subject: [PATCH] Fix SubtitleView to redraw if text changes but bounds stay the same. --- .../android/exoplayer/text/SubtitleView.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer/text/SubtitleView.java b/library/src/main/java/com/google/android/exoplayer/text/SubtitleView.java index 6ff3015afa..7b977aa7cc 100644 --- a/library/src/main/java/com/google/android/exoplayer/text/SubtitleView.java +++ b/library/src/main/java/com/google/android/exoplayer/text/SubtitleView.java @@ -123,7 +123,7 @@ public class SubtitleView extends View { @Override public void setBackgroundColor(int color) { backgroundColor = color; - invalidate(); + forceUpdate(false); } /** @@ -134,8 +134,7 @@ public class SubtitleView extends View { public void setText(CharSequence text) { textBuilder.setLength(0); textBuilder.append(text); - hasMeasurements = false; - requestLayout(); + forceUpdate(true); } /** @@ -147,9 +146,7 @@ public class SubtitleView extends View { if (textPaint.getTextSize() != size) { textPaint.setTextSize(size); innerPaddingX = (int) (size * INNER_PADDING_RATIO + 0.5f); - hasMeasurements = false; - requestLayout(); - invalidate(); + forceUpdate(true); } } @@ -165,17 +162,22 @@ public class SubtitleView extends View { edgeColor = style.edgeColor; setTypeface(style.typeface); super.setBackgroundColor(style.windowColor); - hasMeasurements = false; - requestLayout(); + forceUpdate(true); } private void setTypeface(Typeface typeface) { if (textPaint.getTypeface() != typeface) { textPaint.setTypeface(typeface); + forceUpdate(true); + } + } + + private void forceUpdate(boolean needsLayout) { + if (needsLayout) { hasMeasurements = false; requestLayout(); - invalidate(); } + invalidate(); } @Override