Ellipsize titles on Echo share image
This commit is contained in:
parent
3410d79eb2
commit
c8230b7034
|
@ -82,7 +82,8 @@ public class FinalShareScreen extends BubbleScreen {
|
||||||
|
|
||||||
paintTextMain.setTextSize(fontSizePods);
|
paintTextMain.setTextSize(fontSizePods);
|
||||||
canvas.drawText((i + 1) + ".", innerBoxX, textY, paintTextMain);
|
canvas.drawText((i + 1) + ".", innerBoxX, textY, paintTextMain);
|
||||||
canvas.drawText(favoritePodNames.get(i), innerBoxX + 0.055f * innerBoxSize, textY, paintTextMain);
|
String ellipsizedTitle = ellipsize(favoritePodNames.get(i), paintTextMain, (1.0f - 0.055f) * innerBoxSize);
|
||||||
|
canvas.drawText(ellipsizedTitle, innerBoxX + 0.055f * innerBoxSize, textY, paintTextMain);
|
||||||
fontSizePods = innerBoxSize / 24; // Starting with second text is smaller
|
fontSizePods = innerBoxSize / 24; // Starting with second text is smaller
|
||||||
textY += 1.3f * fontSizePods;
|
textY += 1.3f * fontSizePods;
|
||||||
paintTextMain.setTypeface(typefaceNormal);
|
paintTextMain.setTypeface(typefaceNormal);
|
||||||
|
@ -95,4 +96,14 @@ public class FinalShareScreen extends BubbleScreen {
|
||||||
(int) (innerBoxY + innerBoxSize));
|
(int) (innerBoxY + innerBoxSize));
|
||||||
logo.draw(canvas);
|
logo.draw(canvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String ellipsize(String string, Paint paint, float maxWidth) {
|
||||||
|
if (paint.measureText(string) <= maxWidth) {
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
while (paint.measureText(string + "…") > maxWidth || string.endsWith(" ")) {
|
||||||
|
string = string.substring(0, string.length() - 1);
|
||||||
|
}
|
||||||
|
return string + "…";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue