From b7dd3964006c3cdc5881358ae34227bf8d4df324 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Tue, 26 May 2015 18:48:18 -0700 Subject: 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 --- .../src/com/android/incallui/InCallDateUtils.java | 41 +++++++++++----------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'InCallUI/src/com/android/incallui/InCallDateUtils.java') 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(); } - } -- cgit v1.2.3