Merge "Switch Chronometer to use ICU instead of duration_hours etc"
This commit is contained in:
committed by
Android (Google) Code Review
commit
d681725437
@@ -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<Measure> measures = new ArrayList<Measure>();
|
||||
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
|
||||
|
||||
@@ -2385,22 +2385,6 @@
|
||||
<!-- Appened to express the value is this unit of time. -->
|
||||
<string name="years">years</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>
|
||||
|
||||
<!-- A string denoting the current point in time that should be as short as possible. Abbreviations are preferred to full strings as this might be shown repetitively. It is used in the header of notifications. [CHAR LIMIT=8]-->
|
||||
<string name="now_string_shortest">now</string>
|
||||
|
||||
|
||||
@@ -1135,9 +1135,6 @@
|
||||
|
||||
|
||||
<java-symbol type="plurals" name="bugreport_countdown" />
|
||||
<java-symbol type="plurals" name="duration_hours" />
|
||||
<java-symbol type="plurals" name="duration_minutes" />
|
||||
<java-symbol type="plurals" name="duration_seconds" />
|
||||
<java-symbol type="plurals" name="last_num_days" />
|
||||
<java-symbol type="plurals" name="matches_found" />
|
||||
<java-symbol type="plurals" name="restr_pin_countdown" />
|
||||
|
||||
Reference in New Issue
Block a user