diff options
author | Roozbeh Pournader <roozbeh@google.com> | 2016-12-15 14:35:59 -0800 |
---|---|---|
committer | Roozbeh Pournader <roozbeh@google.com> | 2016-12-15 15:12:29 -0800 |
commit | df366319da1adc1af0bef2ad9c6cc6463895203f (patch) | |
tree | a46396f40bc45006ed8bb4862fad3eb8c7aee344 /InCallUI/src/com/android/incallui | |
parent | 5e154ee9538bbde4fcf69b7db11b15f8d1b639aa (diff) |
Remove duration_hours etc and use ICU data
The ICU data is higher quality and supports a wider selection of
locales.
Also, previously spaces were used to separate the fields, which is
not the correct separator in some locales.
Bug: 33670388
Test: manual
Change-Id: I99715dba63478a5bb319da041d1736ad247f2be1
Diffstat (limited to 'InCallUI/src/com/android/incallui')
-rw-r--r-- | InCallUI/src/com/android/incallui/CallCardFragment.java | 2 | ||||
-rw-r--r-- | InCallUI/src/com/android/incallui/InCallDateUtils.java | 49 |
2 files changed, 24 insertions, 27 deletions
diff --git a/InCallUI/src/com/android/incallui/CallCardFragment.java b/InCallUI/src/com/android/incallui/CallCardFragment.java index 4355ef2bd..c2022d18c 100644 --- a/InCallUI/src/com/android/incallui/CallCardFragment.java +++ b/InCallUI/src/com/android/incallui/CallCardFragment.java @@ -917,7 +917,7 @@ public class CallCardFragment extends BaseFragment<CallCardPresenter, CallCardPr mElapsedTime.setText(callTimeElapsed); String durationDescription = - InCallDateUtils.formatDuration(getView().getContext(), duration); + InCallDateUtils.formatDuration(duration); mElapsedTime.setContentDescription( !TextUtils.isEmpty(durationDescription) ? durationDescription : null); } else { diff --git a/InCallUI/src/com/android/incallui/InCallDateUtils.java b/InCallUI/src/com/android/incallui/InCallDateUtils.java index e6089d5f1..c737ae922 100644 --- a/InCallUI/src/com/android/incallui/InCallDateUtils.java +++ b/InCallUI/src/com/android/incallui/InCallDateUtils.java @@ -1,9 +1,12 @@ package com.android.incallui; -import android.content.Context; -import android.content.res.Resources; +import android.icu.text.MeasureFormat; +import android.icu.text.MeasureFormat.FormatWidth; +import android.icu.util.Measure; +import android.icu.util.MeasureUnit; -import com.android.dialer.R; +import java.util.ArrayList; +import java.util.Locale; /** * Methods to parse time and date information in the InCallUi @@ -14,7 +17,7 @@ public class 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. */ - public static String formatDuration(Context context, long millis) { + public static String formatDuration(long millis) { int hours = 0; int minutes = 0; int seconds = 0; @@ -29,28 +32,22 @@ public class InCallDateUtils { } seconds = elapsedSeconds; - final Resources res = context.getResources(); - StringBuilder duration = new StringBuilder(); - try { - if (hours > 0) { - duration.append(res.getQuantityString(R.plurals.duration_hours, hours, hours)); - } - 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)); - } - } catch (Resources.NotFoundException e) { - // Ignore; plurals throws an exception for an untranslated quantity for a given locale. - return null; + final ArrayList<Measure> measures = new ArrayList<Measure>(); + if (hours > 0) { + measures.add(new Measure(hours, MeasureUnit.HOUR)); + } + if (minutes > 0) { + measures.add(new Measure(minutes, MeasureUnit.MINUTE)); + } + if (seconds > 0) { + measures.add(new Measure(seconds, MeasureUnit.SECOND)); + } + + if (measures.isEmpty()) { + return ""; + } else { + return MeasureFormat.getInstance(Locale.getDefault(), FormatWidth.WIDE) + .formatMeasures((Measure[]) measures.toArray()); } - return duration.toString(); } } |