diff --git a/core/java/android/widget/Chronometer.java b/core/java/android/widget/Chronometer.java index b9224f36a9228..444ebc520cb79 100644 --- a/core/java/android/widget/Chronometer.java +++ b/core/java/android/widget/Chronometer.java @@ -17,8 +17,11 @@ package android.widget; import android.content.Context; -import android.content.res.Resources; import android.content.res.TypedArray; +import android.icu.text.MeasureFormat; +import android.icu.text.MeasureFormat.FormatWidth; +import android.icu.util.Measure; +import android.icu.util.MeasureUnit; import android.os.SystemClock; import android.text.format.DateUtils; import android.util.AttributeSet; @@ -28,6 +31,7 @@ import android.widget.RemoteViews.RemoteView; import com.android.internal.R; +import java.util.ArrayList; import java.util.Formatter; import java.util.IllegalFormatException; import java.util.Locale; @@ -329,9 +333,6 @@ public class Chronometer extends TextView { private static final int MIN_IN_SEC = 60; private static final int HOUR_IN_SEC = MIN_IN_SEC*60; private static String formatDuration(long ms) { - final Resources res = Resources.getSystem(); - final StringBuilder text = new StringBuilder(); - int duration = (int) (ms / DateUtils.SECOND_IN_MILLIS); if (duration < 0) { duration = -duration; @@ -348,31 +349,19 @@ public class Chronometer extends TextView { m = duration / MIN_IN_SEC; duration -= m * MIN_IN_SEC; } - int s = duration; + final int s = duration; - try { - if (h > 0) { - text.append(res.getQuantityString( - com.android.internal.R.plurals.duration_hours, h, h)); - } - if (m > 0) { - if (text.length() > 0) { - text.append(' '); - } - text.append(res.getQuantityString( - com.android.internal.R.plurals.duration_minutes, m, m)); - } - - if (text.length() > 0) { - text.append(' '); - } - text.append(res.getQuantityString( - com.android.internal.R.plurals.duration_seconds, s, s)); - } catch (Resources.NotFoundException e) { - // Ignore; plurals throws an exception for an untranslated quantity for a given locale. - return null; + final ArrayList measures = new ArrayList(); + if (h > 0) { + measures.add(new Measure(h, MeasureUnit.HOUR)); } - return text.toString(); + if (m > 0) { + measures.add(new Measure(m, MeasureUnit.MINUTE)); + } + measures.add(new Measure(s, MeasureUnit.SECOND)); + + return MeasureFormat.getInstance(Locale.getDefault(), FormatWidth.WIDE) + .formatMeasures((Measure[]) measures.toArray()); } @Override diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index 88c240aabe1e9..510e6affb4d03 100644 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -2385,22 +2385,6 @@ years - - - 1 second - %d seconds - - - - 1 minute - %d minutes - - - - 1 hour - %d hours - - now diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index b870a95c9296e..5126ae9086b0e 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -1135,9 +1135,6 @@ - - -