diff --git a/android/assets/defaultCover.png b/android/assets/defaultCover.png index dae11c7..f6cc866 100755 Binary files a/android/assets/defaultCover.png and b/android/assets/defaultCover.png differ diff --git a/core/src/zero1hd/rhythmbullet/graphics/ui/components/MusicSelectable.java b/core/src/zero1hd/rhythmbullet/graphics/ui/components/MusicSelectable.java index 46187bd..2b30c16 100755 --- a/core/src/zero1hd/rhythmbullet/graphics/ui/components/MusicSelectable.java +++ b/core/src/zero1hd/rhythmbullet/graphics/ui/components/MusicSelectable.java @@ -19,9 +19,9 @@ public class MusicSelectable extends WidgetGroup implements Disposable { private Table table; private Image imageIcon; - private Label displayName; + private ShortenedTextLabel displayName; private Label durationLabel; - private Label authorLabel; + private ShortenedTextLabel authorLabel; private FileHandle musicFile; @@ -47,16 +47,16 @@ public class MusicSelectable extends WidgetGroup implements Disposable { imageIcon = new Image(albumCover); table.add(imageIcon).size(180f).left().expandX(); - displayName = new Label(musicFile.nameWithoutExtension().replace('_', ' '), skin, "sub-font", skin.getColor("default")); + displayName = new ShortenedTextLabel(musicFile.nameWithoutExtension().replace('_', ' '), skin, "sub-font", skin.getColor("default")); vGroup.addActor(displayName); durationLabel = new Label("Loading...", skin, "sub-font", skin.getColor("default")); vGroup.addActor(durationLabel); - authorLabel = new Label("Loading...", skin, "sub-font", skin.getColor("default")); + authorLabel = new ShortenedTextLabel("Loading...", skin, "sub-font", skin.getColor("default")); vGroup.addActor(authorLabel); - table.add(vGroup).center(); + table.add(vGroup).expandX().center().fillX(); addActor(table); } @@ -66,18 +66,28 @@ public class MusicSelectable extends WidgetGroup implements Disposable { * needs to be called in thread with gl context. */ public void updateInfo() { + displayName.setOriginalText(songInfo.getSongName()); + displayName.setToOriginalText(); durationLabel.setText("Runtime: " + ((songInfo.getDurationInSeconds() / 60 < 1) ? "00" : songInfo.getDurationInSeconds() / 60) + ":" + ((songInfo.getDurationInSeconds() - (songInfo.getDurationInSeconds() / 60) * 60) < 10 ? "0" + (songInfo.getDurationInSeconds() - (songInfo.getDurationInSeconds() / 60) * 60) : (songInfo.getDurationInSeconds() - (songInfo.getDurationInSeconds() / 60) * 60))); - authorLabel.setText("Author: " + songInfo.getAuthor()); - + authorLabel.setOriginalText("Author: " + songInfo.getAuthor()); + authorLabel.setToOriginalText(); songInfo.setupTexture(albumCover); albumCover = songInfo.getAlbumCover(); imageIcon.setDrawable((new TextureRegionDrawable(new TextureRegion(albumCover)))); } + + @Override + public void layout() { + displayName.setTargetWidth((int) (getWidth() - 300)); + authorLabel.setTargetWidth((int) (getWidth() - 300)); + super.layout(); + } + @Override public void act(float delta) { table.setSize(getWidth(), getHeight()); diff --git a/core/src/zero1hd/rhythmbullet/graphics/ui/components/ShortenedTextLabel.java b/core/src/zero1hd/rhythmbullet/graphics/ui/components/ShortenedTextLabel.java new file mode 100755 index 0000000..05ece1c --- /dev/null +++ b/core/src/zero1hd/rhythmbullet/graphics/ui/components/ShortenedTextLabel.java @@ -0,0 +1,42 @@ +package zero1hd.rhythmbullet.graphics.ui.components; + +import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.scenes.scene2d.ui.Label; +import com.badlogic.gdx.scenes.scene2d.ui.Skin; + +public class ShortenedTextLabel extends Label { + private String originalText; + private int targetWidth; + + public ShortenedTextLabel(CharSequence text, Skin skin, String fontName, Color color) { + super(text, skin, fontName, color); + originalText = text.toString(); + } + + public void setTargetWidth(int targetWidth) { + this.targetWidth = targetWidth; + validate(); + } + + @Override + public void act(float delta) { + if (getGlyphLayout().width > targetWidth && getText().length - 4 > 0) { + setText(getText().substring(0, getText().length - 4).concat("...")); + validate(); + } + super.act(delta); + } + + public void setToOriginalText() { + setText(originalText); + } + + @Override + public void layout() { + super.layout(); + } + + public void setOriginalText(String originalText) { + this.originalText = originalText; + } +}