本文整理汇总了Java中android.text.format.DateUtils.formatElapsedTime方法的典型用法代码示例。如果您正苦于以下问题:Java DateUtils.formatElapsedTime方法的具体用法?Java DateUtils.formatElapsedTime怎么用?Java DateUtils.formatElapsedTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.format.DateUtils
的用法示例。
在下文中一共展示了DateUtils.formatElapsedTime方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setPGTime
import android.text.format.DateUtils; //导入方法依赖的package包/类
private void setPGTime(int progress) {
try {
String timeString = "00.00";
int linePG = 0;
currentSong = streamingManager.getCurrentAudio();
if (currentSong != null && progress != Long.parseLong(currentSong.getMediaDuration())) {
timeString = DateUtils.formatElapsedTime(progress / 1000);
Long audioDuration = Long.parseLong(currentSong.getMediaDuration());
linePG = (int) (((progress / 1000) * 100) / audioDuration);
}
time_progress_bottom.setText(timeString);
time_progress_slide.setText(timeString);
lineProgress.setLineProgress(linePG);
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
示例2: formatSeconds
import android.text.format.DateUtils; //导入方法依赖的package包/类
public static String formatSeconds(long seconds) {
/* Takes number of seconds and returns a String with format HH:MM. */
String timeString = DateUtils.formatElapsedTime(seconds);
//If the time is less than an hour, then add "00:" to the beginning:
if (seconds < 3600) timeString = "00:" + timeString;
//Otherwise, if the time is less than 10 hours, then add "0" to the beginning:
else if (seconds < 36000) timeString = "0" + timeString;
//Removes seconds from time, because it's unneeded information
return timeString.substring(0, timeString.length()-3);
}
示例3: setMaxTime
import android.text.format.DateUtils; //导入方法依赖的package包/类
private void setMaxTime() {
try {
String timeString = DateUtils.formatElapsedTime(Long.parseLong(currentSong.getMediaDuration()));
time_total_bottom.setText(timeString);
time_total_slide.setText(timeString);
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
示例4: formatTime
import android.text.format.DateUtils; //导入方法依赖的package包/类
private String formatTime(String duration) {
try {
long dur = Long.valueOf(duration);
return DateUtils.formatElapsedTime(dur);
} catch (NumberFormatException e) {
return duration;
}
}
示例5: getFormatedDuration
import android.text.format.DateUtils; //导入方法依赖的package包/类
public String getFormatedDuration(){
if(!TextUtils.isEmpty(duration)){
long time=Long.parseLong(duration);
return DateUtils.formatElapsedTime(time/1000);
}
return null;
}
示例6: onBindViewHolder
import android.text.format.DateUtils; //导入方法依赖的package包/类
@Override
public void onBindViewHolder(@NonNull final TwoLinesViewHolder holder,
@NonNull final Cursor cursor, final int position) {
final SpannableStringBuilder primary = new SpannableStringBuilder();
final String cachedName = cursor.getString(cursor.getColumnIndexOrThrow(CallLog.Calls.CACHED_NAME));
final String number = cursor.getString(cursor.getColumnIndexOrThrow(CallLog.Calls.NUMBER));
SpannableStringBuilderCompat.append(primary, (cachedName != null ? cachedName : number),
new StyleSpan(Typeface.BOLD), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
primary.append(" ");
final long duration = cursor.getLong(cursor.getColumnIndexOrThrow(CallLog.Calls.DURATION));
if (duration > 0) {
final CharSequence formattedDuration = DateUtils.formatElapsedTime(duration);
primary.append(formattedDuration);
}
holder.setText1(primary);
final SpannableStringBuilder summary = new SpannableStringBuilder();
final int type = cursor.getInt(cursor.getColumnIndexOrThrow(CallLog.Calls.TYPE));
switch (type) {
case CallLog.Calls.INCOMING_TYPE:
SpannableStringBuilderCompat.append(summary, "←", new ForegroundColorSpan(Color.BLUE),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
summary.append(" ");
break;
case CallLog.Calls.OUTGOING_TYPE:
SpannableStringBuilderCompat.append(summary, "→", new ForegroundColorSpan(Color.GREEN),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
summary.append(" ");
break;
case CallLog.Calls.MISSED_TYPE:
case CallLog.Calls.REJECTED_TYPE:
SpannableStringBuilderCompat.append(summary, "☇", new ForegroundColorSpan(Color.RED),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
summary.append(" ");
break;
case CallLog.Calls.BLOCKED_TYPE:
SpannableStringBuilderCompat.append(summary, "☓", new ForegroundColorSpan(Color.BLACK),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
summary.append(" ");
break;
}
final long date = cursor.getLong(cursor.getColumnIndexOrThrow(CallLog.Calls.DATE));
final CharSequence relativeDate = DateUtils.getRelativeTimeSpanString(date,
System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS);
summary.append(relativeDate);
holder.setText2(summary);
}
示例7: formatMillis
import android.text.format.DateUtils; //导入方法依赖的package包/类
/**
* Formats time from milliseconds to hh:mm:ss string format.
*/
public static String formatMillis(int millis) {
return DateUtils.formatElapsedTime(millis/1000);
}