Fix SubtitleView to redraw if text changes but bounds stay the same.

This commit is contained in:
Oliver Woodman 2015-02-06 11:31:13 +00:00
parent 7505944497
commit fbf75e1263

View File

@ -123,7 +123,7 @@ public class SubtitleView extends View {
@Override @Override
public void setBackgroundColor(int color) { public void setBackgroundColor(int color) {
backgroundColor = color; backgroundColor = color;
invalidate(); forceUpdate(false);
} }
/** /**
@ -134,8 +134,7 @@ public class SubtitleView extends View {
public void setText(CharSequence text) { public void setText(CharSequence text) {
textBuilder.setLength(0); textBuilder.setLength(0);
textBuilder.append(text); textBuilder.append(text);
hasMeasurements = false; forceUpdate(true);
requestLayout();
} }
/** /**
@ -147,9 +146,7 @@ public class SubtitleView extends View {
if (textPaint.getTextSize() != size) { if (textPaint.getTextSize() != size) {
textPaint.setTextSize(size); textPaint.setTextSize(size);
innerPaddingX = (int) (size * INNER_PADDING_RATIO + 0.5f); innerPaddingX = (int) (size * INNER_PADDING_RATIO + 0.5f);
hasMeasurements = false; forceUpdate(true);
requestLayout();
invalidate();
} }
} }
@ -165,17 +162,22 @@ public class SubtitleView extends View {
edgeColor = style.edgeColor; edgeColor = style.edgeColor;
setTypeface(style.typeface); setTypeface(style.typeface);
super.setBackgroundColor(style.windowColor); super.setBackgroundColor(style.windowColor);
hasMeasurements = false; forceUpdate(true);
requestLayout();
} }
private void setTypeface(Typeface typeface) { private void setTypeface(Typeface typeface) {
if (textPaint.getTypeface() != typeface) { if (textPaint.getTypeface() != typeface) {
textPaint.setTypeface(typeface); textPaint.setTypeface(typeface);
forceUpdate(true);
}
}
private void forceUpdate(boolean needsLayout) {
if (needsLayout) {
hasMeasurements = false; hasMeasurements = false;
requestLayout(); requestLayout();
invalidate();
} }
invalidate();
} }
@Override @Override