summaryrefslogtreecommitdiff
path: root/InCallUI/src/com/android/incallui/InCallDateUtils.java
diff options
context:
space:
mode:
authorAndrew Lee <anwlee@google.com>2015-05-26 18:48:18 -0700
committerAndrew Lee <anwlee@google.com>2015-05-26 18:56:50 -0700
commitb7dd3964006c3cdc5881358ae34227bf8d4df324 (patch)
tree752897faeeac0131a474aba89c9f78fdb209c6e3 /InCallUI/src/com/android/incallui/InCallDateUtils.java
parent9b8d23fb8efec702f2d2940ddaf924896763e047 (diff)
Fix call duration talkback verbalization.
+ Uncomment code which generates content description. + Pass in local context, rather than System context, for getting the plurals resource strings. This fixes a crash happening in languages even if correctly translations existed. + Catch Resource.NotFoundExceptions in the utility which generates this human-readable string so that for locales missing the translation we don't crash the whole Dialer. Bug: 20813003 Change-Id: I861078a116d2d31f3ac361757a14581726a78f1c
Diffstat (limited to 'InCallUI/src/com/android/incallui/InCallDateUtils.java')
-rw-r--r--InCallUI/src/com/android/incallui/InCallDateUtils.java41
1 files changed, 21 insertions, 20 deletions
diff --git a/InCallUI/src/com/android/incallui/InCallDateUtils.java b/InCallUI/src/com/android/incallui/InCallDateUtils.java
index 156eea06f..da3bb6bf4 100644
--- a/InCallUI/src/com/android/incallui/InCallDateUtils.java
+++ b/InCallUI/src/com/android/incallui/InCallDateUtils.java
@@ -1,21 +1,18 @@
package com.android.incallui;
+import android.content.Context;
import android.content.res.Resources;
/**
* Methods to parse time and date information in the InCallUi
*/
public class InCallDateUtils {
- public InCallDateUtils() {
-
- }
/**
- * Return given duration in a human-friendly format. For example, "4
- * minutes 3 seconds" or "3 hours 1 second". Returns the hours, minutes and seconds in that
- * order if they exist.
+ * Return given duration in a human-friendly format. For example, "4 minutes 3 seconds" or
+ * "3 hours 1 second". Returns the hours, minutes and seconds in that order if they exist.
*/
- public static String formatDetailedDuration(long millis) {
+ public static String formatDuration(Context context, long millis) {
int hours = 0;
int minutes = 0;
int seconds = 0;
@@ -30,24 +27,28 @@ public class InCallDateUtils {
}
seconds = elapsedSeconds;
- final Resources res = Resources.getSystem();
+ final Resources res = context.getResources();
StringBuilder duration = new StringBuilder();
- if (hours > 0) {
- duration.append(res.getQuantityString(R.plurals.duration_hours, hours, hours));
- }
- if (minutes > 0) {
+ try {
if (hours > 0) {
- duration.append(' ');
+ duration.append(res.getQuantityString(R.plurals.duration_hours, hours, hours));
}
- duration.append(res.getQuantityString(R.plurals.duration_minutes, minutes, minutes));
- }
- if (seconds > 0) {
- if (hours > 0 || minutes > 0) {
- duration.append(' ');
+ if (minutes > 0) {
+ if (hours > 0) {
+ duration.append(' ');
+ }
+ duration.append(res.getQuantityString(R.plurals.duration_minutes, minutes, minutes));
+ }
+ if (seconds > 0) {
+ if (hours > 0 || minutes > 0) {
+ duration.append(' ');
+ }
+ duration.append(res.getQuantityString(R.plurals.duration_seconds, seconds, seconds));
}
- duration.append(res.getQuantityString(R.plurals.duration_seconds, seconds, seconds));
+ } catch (Resources.NotFoundException e) {
+ // Ignore; plurals throws an exception for an untranslated quantity for a given locale.
+ return null;
}
return duration.toString();
}
-
}