Skip to content

Commit

Permalink
fix a bug when static layout is null for image danmakus
Browse files Browse the repository at this point in the history
  • Loading branch information
xyczero committed Nov 10, 2015
1 parent eb6fdc7 commit 70757fc
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ public void measure(BaseDanmaku danmaku, TextPaint paint) {
text = new SpannedString(danmaku.text);
}
if (text != null) {
StaticLayout staticLayout = new StaticLayout(text, paint, (int) StaticLayout.getDesiredWidth(danmaku.text, paint), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true);
danmaku.paintWidth = staticLayout.getWidth();
danmaku.paintHeight = staticLayout.getHeight();
danmaku.obj = new SoftReference<StaticLayout>(staticLayout);
createStaticLayout(danmaku);
return;
}
}
Expand All @@ -57,8 +54,7 @@ public void drawText(BaseDanmaku danmaku, String lineText, Canvas canvas, float
SoftReference<StaticLayout> reference = (SoftReference<StaticLayout>) danmaku.obj;
StaticLayout staticLayout = reference.get();
if (staticLayout == null) {
super.drawText(danmaku, lineText, canvas, left, top, paint);
return;
createStaticLayout(danmaku);
}
boolean needRestore = false;
if (left != 0 && top != 0) {
Expand All @@ -77,4 +73,11 @@ public void clearCaches() {
super.clearCaches();
System.gc();
}

private void createAndMeasureStaticLayout(BaseDanmaku danmaku){
StaticLayout staticLayout = new StaticLayout(text, paint, (int) StaticLayout.getDesiredWidth(danmaku.text, paint), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true);
danmaku.paintWidth = staticLayout.getWidth();
danmaku.paintHeight = staticLayout.getHeight();
danmaku.obj = new SoftReference<StaticLayout>(staticLayout);
}
}

0 comments on commit 70757fc

Please sign in to comment.