本文整理匯總了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);
}