diff options
author | Eric Erfanian <erfanian@google.com> | 2017-05-05 15:29:54 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-05-05 15:29:54 +0000 |
commit | 43b3152d075138b11e1fe297682b3bbc775e5641 (patch) | |
tree | 3a325b0effac02fbd228b8ddf2f96589e5df72cd /java/com/android/dialer/calllogutils/CallEntryFormatter.java | |
parent | 2034759538273aed8a0b412d8fb90994eba1f7ea (diff) | |
parent | 300a8683b9c28424fb0f0c571a0abe128c461f69 (diff) |
Update Dialer to V10 RC16 am: 10b34a5ebf
am: 300a8683b9
Change-Id: If5695bad59f8a4dab6e6c90b54943b900bd2652a
Diffstat (limited to 'java/com/android/dialer/calllogutils/CallEntryFormatter.java')
-rw-r--r-- | java/com/android/dialer/calllogutils/CallEntryFormatter.java | 74 |
1 files changed, 56 insertions, 18 deletions
diff --git a/java/com/android/dialer/calllogutils/CallEntryFormatter.java b/java/com/android/dialer/calllogutils/CallEntryFormatter.java index bd184bb89..6aa93af52 100644 --- a/java/com/android/dialer/calllogutils/CallEntryFormatter.java +++ b/java/com/android/dialer/calllogutils/CallEntryFormatter.java @@ -17,6 +17,7 @@ package com.android.dialer.calllogutils; import android.content.Context; +import android.content.res.Resources; import android.icu.lang.UCharacter; import android.icu.text.BreakIterator; import android.os.Build.VERSION; @@ -24,9 +25,12 @@ import android.os.Build.VERSION_CODES; import android.text.format.DateUtils; import android.text.format.Formatter; import com.android.dialer.util.DialerUtils; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.Locale; +import java.util.concurrent.TimeUnit; /** Utility class for formatting data and data usage in call log entries. */ public class CallEntryFormatter { @@ -76,24 +80,41 @@ public class CallEntryFormatter { UCharacter.TITLECASE_NO_LOWERCASE); } - private static CharSequence formatDuration(Context context, long elapsedSeconds, boolean a11y) { - long minutes = 0; - long seconds = 0; + private static CharSequence formatDuration(Context context, long elapsedSeconds) { + Resources res = context.getResources(); + String formatPattern; + if (elapsedSeconds >= 60) { + String minutesString = res.getString(R.string.call_details_minutes_abbreviation); + String secondsString = res.getString(R.string.call_details_seconds_abbreviation); + // example output: "1m 1s" + formatPattern = + context.getString( + R.string.call_duration_format_pattern, "m", minutesString, "s", secondsString); + } else { + String secondsString = res.getString(R.string.call_details_seconds_abbreviation); + // example output: "1s" + formatPattern = + context.getString(R.string.call_duration_short_format_pattern, "s", secondsString); + } + SimpleDateFormat format = new SimpleDateFormat(formatPattern); + return format.format(new Date(TimeUnit.SECONDS.toMillis(elapsedSeconds))); + } + private static CharSequence formatDurationA11y(Context context, long elapsedSeconds) { + Resources res = context.getResources(); if (elapsedSeconds >= 60) { - minutes = elapsedSeconds / 60; - elapsedSeconds -= minutes * 60; - seconds = elapsedSeconds; - int stringId = - a11y ? R.string.call_details_duration_format_a11y : R.string.call_details_duration_format; - return context.getString(stringId, minutes, seconds); + int minutes = (int) (elapsedSeconds / 60); + int seconds = (int) elapsedSeconds - minutes * 60; + String minutesString = res.getQuantityString(R.plurals.a11y_minutes, minutes); + String secondsString = res.getQuantityString(R.plurals.a11y_seconds, seconds); + // example output: "1 minute 1 second", "2 minutes 2 seconds", ect. + return context.getString( + R.string.a11y_call_duration_format, minutes, minutesString, seconds, secondsString); } else { - seconds = elapsedSeconds; - int stringId = - a11y - ? R.string.call_details_short_duration_format_a11y - : R.string.call_details_short_duration_format; - return context.getString(stringId, seconds); + String secondsString = res.getQuantityString(R.plurals.a11y_seconds, (int) elapsedSeconds); + // example output: "1 second", "2 seconds" + return context.getString( + R.string.a11y_call_duration_short_format, elapsedSeconds, secondsString); } } @@ -102,12 +123,29 @@ public class CallEntryFormatter { * * @param elapsedSeconds Total elapsed seconds. * @param dataUsage Data usage in bytes, or null if not specified. - * @param a11y {@code true} if string should be talk back friendly. * @return String containing call duration and data usage. */ public static CharSequence formatDurationAndDataUsage( - Context context, long elapsedSeconds, long dataUsage, boolean a11y) { - CharSequence duration = formatDuration(context, elapsedSeconds, a11y); + Context context, long elapsedSeconds, long dataUsage) { + return formatDurationAndDataUsageInternal( + context, formatDuration(context, elapsedSeconds), dataUsage); + } + + /** + * Formats a string containing the call duration and the data usage (if specified) for TalkBack. + * + * @param elapsedSeconds Total elapsed seconds. + * @param dataUsage Data usage in bytes, or null if not specified. + * @return String containing call duration and data usage. + */ + public static CharSequence formatDurationAndDataUsageA11y( + Context context, long elapsedSeconds, long dataUsage) { + return formatDurationAndDataUsageInternal( + context, formatDurationA11y(context, elapsedSeconds), dataUsage); + } + + private static CharSequence formatDurationAndDataUsageInternal( + Context context, CharSequence duration, long dataUsage) { List<CharSequence> durationItems = new ArrayList<>(); if (dataUsage > 0) { durationItems.add(duration); |