[Android] Change time format in video list/grid
Sébastien Toque
git at videolan.org
Thu Sep 5 19:48:08 CEST 2013
vlc-ports/android | branch: master | Sébastien Toque <xilasz at gmail.com> | Thu Sep 5 19:36:18 2013 +0200| [72be68edac0dcfd352fa04dc7dc829eddd8ef06f] | committer: Sébastien Toque
Change time format in video list/grid
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=72be68edac0dcfd352fa04dc7dc829eddd8ef06f
---
vlc-android/src/org/videolan/vlc/Util.java | 34 +++++++++++++++++---
.../videolan/vlc/gui/video/VideoListAdapter.java | 7 ++--
2 files changed, 32 insertions(+), 9 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/Util.java b/vlc-android/src/org/videolan/vlc/Util.java
index 7a1d98b..7ca400c 100644
--- a/vlc-android/src/org/videolan/vlc/Util.java
+++ b/vlc-android/src/org/videolan/vlc/Util.java
@@ -197,7 +197,22 @@ public class Util {
* @param millis e.g.time/length from file
* @return formated string (hh:)mm:ss
*/
- public static String millisToString(long millis) {
+ public static String millisToString(long millis)
+ {
+ return millisToString(millis, false);
+ }
+
+ /**
+ * Convert time to a string
+ * @param millis e.g.time/length from file
+ * @return formated string "[hh]h[mm]min" / "[mm]min[s]s"
+ */
+ public static String millisToText(long millis)
+ {
+ return millisToString(millis, true);
+ }
+
+ private static String millisToString(long millis, boolean text) {
boolean negative = millis < 0;
millis = java.lang.Math.abs(millis);
@@ -211,10 +226,19 @@ public class Util {
String time;
DecimalFormat format = (DecimalFormat)NumberFormat.getInstance(Locale.US);
format.applyPattern("00");
- if (millis > 0) {
- time = (negative ? "-" : "") + hours + ":" + format.format(min) + ":" + format.format(sec);
- } else {
- time = (negative ? "-" : "") + min + ":" + format.format(sec);
+ if (text) {
+ if (millis > 0)
+ time = (negative ? "-" : "") + hours + "h" + format.format(min) + "min";
+ else if (min > 0)
+ time = (negative ? "-" : "") + min + "min";
+ else
+ time = (negative ? "-" : "") + sec + "s";
+ }
+ else {
+ if (millis > 0)
+ time = (negative ? "-" : "") + hours + ":" + format.format(min) + ":" + format.format(sec);
+ else
+ time = (negative ? "-" : "") + min + ":" + format.format(sec);
}
return time;
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
index 299761c..0282500 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -177,14 +177,13 @@ public class VideoListAdapter extends ArrayAdapter<Media>
String text;
if (lastTime > 0) {
text = String.format("%s / %s",
- Util.millisToString(lastTime),
- Util.millisToString(media.getLength()));
+ Util.millisToText(lastTime),
+ Util.millisToText(media.getLength()));
holder.progress.setVisibility(View.VISIBLE);
holder.progress.setMax((int) (media.getLength() / 1000));
holder.progress.setProgress((int) (lastTime / 1000));
} else {
- text = String.format("%s",
- Util.millisToString(media.getLength()));
+ text = Util.millisToText(media.getLength());
holder.progress.setVisibility(View.GONE);
}
More information about the Android
mailing list