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
|
||||
|
||||
Reference in New Issue
Block a user