diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2016-12-16 01:44:11 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2016-12-16 01:44:11 +0000 |
commit | 79d299821731155556c04dc0b482b9006ad61097 (patch) | |
tree | b465b0cf0a32ec8838c7b52b400c8a75348c82d1 /InCallUI | |
parent | da394b5c7ecff30c724f0493e0bc7fc628d2eb7d (diff) | |
parent | df366319da1adc1af0bef2ad9c6cc6463895203f (diff) |
Merge "Remove duration_hours etc and use ICU data"
Diffstat (limited to 'InCallUI')
-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(); } } |