display duration in bottom right corner
This commit is contained in:
parent
383120edcc
commit
428ae19d7c
@ -19,6 +19,7 @@ package ch.blinkenlights.android.vanilla;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.text.format.DateUtils;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
@ -196,10 +197,20 @@ public class DraggableRow extends LinearLayout implements Checkable {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a TextView intended to display duration
|
||||
* Display given duration, negative values
|
||||
* result in '--:--'
|
||||
*
|
||||
* @param duration the duration in ms to display
|
||||
*/
|
||||
public TextView getDurationView() {
|
||||
return mDurationView;
|
||||
public void setDuration(long duration) {
|
||||
String txt = "--:--";
|
||||
if (duration >= 0) {
|
||||
txt = DateUtils.formatElapsedTime(duration / 1000);
|
||||
}
|
||||
|
||||
SpannableStringBuilder sb = new SpannableStringBuilder("\n"+txt);
|
||||
sb.setSpan(new ForegroundColorSpan(Color.GRAY), 1, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
mDurationView.setText(sb);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -503,7 +503,7 @@ public class MediaAdapter
|
||||
Cursor cursor = mCursor;
|
||||
cursor.moveToPosition(position);
|
||||
holder.id = cursor.getLong(0);
|
||||
String duration = "--:--";
|
||||
long duration = -1;
|
||||
long cacheId = cursor.getLong(1);
|
||||
if (mProjection.length >= 4) {
|
||||
String line1 = cursor.getString(2);
|
||||
@ -515,7 +515,7 @@ public class MediaAdapter
|
||||
line2 += ", " + cursor.getString(4);
|
||||
|
||||
if (mProjection.length >= 6)
|
||||
duration = MediaUtils.getFormattedDuration(cursor.getLong(5));
|
||||
duration = cursor.getLong(5);
|
||||
|
||||
row.setText(line1, line2);
|
||||
holder.title = line1;
|
||||
@ -526,7 +526,7 @@ public class MediaAdapter
|
||||
holder.title = title;
|
||||
}
|
||||
|
||||
row.getDurationView().setText(duration);
|
||||
row.setDuration(duration);
|
||||
row.getCoverView().setCover(mCoverCacheType, cacheId, holder.title);
|
||||
|
||||
return row;
|
||||
|
@ -46,7 +46,6 @@ import android.net.Uri;
|
||||
import android.os.Environment;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.v4.content.FileProvider;
|
||||
import android.text.format.DateUtils;
|
||||
import android.text.TextUtils;
|
||||
import android.database.MatrixCursor;
|
||||
import android.util.Log;
|
||||
@ -627,11 +626,4 @@ public class MediaUtils {
|
||||
return TYPE_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return duration of this song.duration in the form "MM:SS" or "H:MM:SS"
|
||||
*/
|
||||
public static String getFormattedDuration(long duration) {
|
||||
return DateUtils.formatElapsedTime(duration / 1000);
|
||||
}
|
||||
}
|
||||
|
@ -110,9 +110,7 @@ public class PlaylistAdapter extends CursorAdapter implements Handler.Callback {
|
||||
dview.showDragger(mEditable);
|
||||
dview.setText(cursor.getString(1));
|
||||
dview.setTag(cursor.getLong(3));
|
||||
|
||||
String duration = MediaUtils.getFormattedDuration(cursor.getLong(6));
|
||||
dview.getDurationView().setText(duration);
|
||||
dview.setDuration(cursor.getLong(6));
|
||||
|
||||
LazyCoverView cover = dview.getCoverView();
|
||||
cover.setCover(MediaUtils.TYPE_ALBUM, cursor.getLong(4), null);
|
||||
|
@ -132,8 +132,8 @@ public class ShowQueueAdapter extends BaseAdapter {
|
||||
|
||||
if (song.isFilled()) {
|
||||
row.setText(song.title, song.album+", "+song.artist);
|
||||
row.setDuration(song.duration);
|
||||
row.getCoverView().setCover(MediaUtils.TYPE_ALBUM, song.albumId, null);
|
||||
row.getDurationView().setText(MediaUtils.getFormattedDuration(song.duration));
|
||||
}
|
||||
|
||||
row.highlightRow(position == mHighlightRow);
|
||||
|
Loading…
x
Reference in New Issue
Block a user