diff options
author | ByteHamster <info@bytehamster.com> | 2024-01-04 18:22:32 +0100 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2024-01-04 18:22:42 +0100 |
commit | c8230b70344468c0a624b21dcfd04749af498bb6 (patch) | |
tree | 9c5c4a55eac849d33fc73210370f12aab6fde40d | |
parent | 3410d79eb21c3966505b09f7f39246170f416bb6 (diff) | |
download | AntennaPod-c8230b70344468c0a624b21dcfd04749af498bb6.zip |
Ellipsize titles on Echo share image
-rw-r--r-- | ui/echo/src/main/java/de/danoeh/antennapod/ui/echo/screens/FinalShareScreen.java | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/ui/echo/src/main/java/de/danoeh/antennapod/ui/echo/screens/FinalShareScreen.java b/ui/echo/src/main/java/de/danoeh/antennapod/ui/echo/screens/FinalShareScreen.java index bf8e7eeea..fe938ae43 100644 --- a/ui/echo/src/main/java/de/danoeh/antennapod/ui/echo/screens/FinalShareScreen.java +++ b/ui/echo/src/main/java/de/danoeh/antennapod/ui/echo/screens/FinalShareScreen.java @@ -82,7 +82,8 @@ public class FinalShareScreen extends BubbleScreen { paintTextMain.setTextSize(fontSizePods); 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 textY += 1.3f * fontSizePods; paintTextMain.setTypeface(typefaceNormal); @@ -95,4 +96,14 @@ public class FinalShareScreen extends BubbleScreen { (int) (innerBoxY + innerBoxSize)); 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 + "…"; + } } |