Skip to content

Commit

Permalink
SpannedCacheStuffer: use clone of danmaku.text instead when staticLay…
Browse files Browse the repository at this point in the history
…out-recreating
  • Loading branch information
ctiao committed Nov 16, 2015
1 parent daafd5c commit 5bbf435
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,19 @@ public void drawText(BaseDanmaku danmaku, String lineText, Canvas canvas, float
SoftReference<StaticLayout> reference = (SoftReference<StaticLayout>) danmaku.obj;
StaticLayout staticLayout = reference.get();
if (staticLayout == null) {
staticLayout = new StaticLayout(danmaku.text, paint, (int) danmaku.paintWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true);
CharSequence text = null;
if (danmaku.text instanceof SpannableStringBuilder) {
text = new SpannableStringBuilder(danmaku.text);
} else if (danmaku.text instanceof Spannable) {
text = Spannable.Factory.getInstance().newSpannable(danmaku.text);
} else if (danmaku.text instanceof SpannedString) {
text = new SpannedString(danmaku.text);
}
if (text == null) {
super.drawText(danmaku, lineText, canvas, left, top, paint);
return;
}
staticLayout = new StaticLayout(text, paint, (int) danmaku.paintWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true);
danmaku.obj = new SoftReference<>(staticLayout);
}
boolean needRestore = false;
Expand Down

0 comments on commit 5bbf435

Please sign in to comment.