* @param secs The track in seconds.
* @return Duration of a track that's properly formatted.
*/
- public static final String makeTimeString(final Context context, long secs) {
+ public static final String makeShortTimeString(final Context context, long secs) {
long hours, mins;
hours = secs / 3600;
- secs -= hours * 3600;
+ secs %= 3600;
mins = secs / 60;
- secs -= mins * 60;
+ secs %= 60;
final String durationFormat = context.getResources().getString(
hours == 0 ? R.string.durationformatshort : R.string.durationformatlong);
}
/**
+ * * Used to create a formatted time string in the format of #d #h #m #s
+ *
+ * @param context The {@link Context} to use.
+ * @param secs The duration seconds.
+ * @return Duration properly formatted in #d #h #m #s format
+ */
+ public static final String makeLongTimeString(final Context context, long secs) {
+ long days, hours, mins;
+
+ days = secs / (3600 * 24);
+ secs %= (3600 * 24);
+ hours = secs / 3600;
+ secs %= 3600;
+ mins = secs / 60;
+ secs %= 60;
+
+ int stringId = R.string.duration_mins;
+ if (days != 0) {
+ stringId = R.string.duration_days;
+ } else if (hours != 0) {
+ stringId = R.string.duration_hours;
+ }
+
+ final String durationFormat = context.getResources().getString(stringId);
+ return String.format(durationFormat, days, hours, mins, secs);
+ }
+
+ /**
* Changes to the next track
*/
public static void next() {
try {
return mService.duration();
} catch (final RemoteException ignored) {
+ } catch (final IllegalStateException ignored) {
}
}
return 0;