diff options
-rw-r--r-- | InCallUI/res/values/strings.xml | 16 | ||||
-rw-r--r-- | InCallUI/src/com/android/incallui/CallCardFragment.java | 2 | ||||
-rw-r--r-- | InCallUI/src/com/android/incallui/InCallDateUtils.java | 49 |
3 files changed, 24 insertions, 43 deletions
diff --git a/InCallUI/res/values/strings.xml b/InCallUI/res/values/strings.xml index d18c893ad..92de14042 100644 --- a/InCallUI/res/values/strings.xml +++ b/InCallUI/res/values/strings.xml @@ -472,22 +472,6 @@ <!-- This can be used in any application wanting to disable the text "Emergency number" --> <string name="emergency_call_dialog_number_for_display">Emergency number</string> - <!-- Phrase describing a time duration using seconds [CHAR LIMIT=16] --> - <plurals name="duration_seconds"> - <item quantity="one">1 second</item> - <item quantity="other"><xliff:g id="count">%d</xliff:g> seconds</item> - </plurals> - <!-- Phrase describing a time duration using minutes [CHAR LIMIT=16] --> - <plurals name="duration_minutes"> - <item quantity="one">1 minute</item> - <item quantity="other"><xliff:g id="count">%d</xliff:g> minutes</item> - </plurals> - <!-- Phrase describing a time duration using hours [CHAR LIMIT=16] --> - <plurals name="duration_hours"> - <item quantity="one">1 hour</item> - <item quantity="other"><xliff:g id="count">%d</xliff:g> hours</item> - </plurals> - <!-- Description of the profile photo shown when the device's camera is disabled udring a video call. [CHAR LIMIT=NONE] --> <string name="profile_photo_description">Profile photo</string> 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(); } } |