Home | History | Annotate | Download | only in incallui
      1 package com.android.incallui;
      2 
      3 import android.content.res.Resources;
      4 
      5 /**
      6  * Methods to parse time and date information in the InCallUi
      7  */
      8 public class InCallDateUtils {
      9     public InCallDateUtils() {
     10 
     11     }
     12 
     13     /**
     14      * Return given duration in a human-friendly format. For example, "4
     15      * minutes 3 seconds" or "3 hours 1 second". Returns the hours, minutes and seconds in that
     16      * order if they exist.
     17      */
     18     public static String formatDetailedDuration(long millis) {
     19         int hours = 0;
     20         int minutes = 0;
     21         int seconds = 0;
     22         int elapsedSeconds = (int) (millis / 1000);
     23         if (elapsedSeconds >= 3600) {
     24             hours = elapsedSeconds / 3600;
     25             elapsedSeconds -= hours * 3600;
     26         }
     27         if (elapsedSeconds >= 60) {
     28             minutes = elapsedSeconds / 60;
     29             elapsedSeconds -= minutes * 60;
     30         }
     31         seconds = elapsedSeconds;
     32 
     33         final Resources res = Resources.getSystem();
     34         StringBuilder duration = new StringBuilder();
     35         if (hours > 0) {
     36             duration.append(res.getQuantityString(
     37                     com.android.internal.R.plurals.duration_hours, hours, hours));
     38         }
     39         if (minutes > 0) {
     40             if (hours > 0) {
     41                 duration.append(' ');
     42             }
     43             duration.append(res.getQuantityString(
     44                     com.android.internal.R.plurals.duration_minutes, minutes, minutes));
     45         }
     46         if (seconds > 0) {
     47             if (hours > 0 || minutes > 0) {
     48                 duration.append(' ');
     49             }
     50             duration.append(res.getQuantityString(
     51                     com.android.internal.R.plurals.duration_seconds, seconds, seconds));
     52         }
     53         return duration.toString();
     54     }
     55 
     56 }
     57