forked from upstream-mirrors/OpenTracks
Localize number formatting. Only use NumberFormat. Remove all
direct calls to DecimalFormat.
This commit is contained in:
@@ -23,7 +23,7 @@ import android.graphics.Paint;
|
||||
import android.graphics.Paint.Style;
|
||||
import android.graphics.Path;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
|
||||
/**
|
||||
* This class encapsulates meta data about one series of values for a chart.
|
||||
@@ -33,7 +33,7 @@ import java.text.DecimalFormat;
|
||||
public class ChartValueSeries {
|
||||
|
||||
private final ExtremityMonitor monitor = new ExtremityMonitor();
|
||||
private final DecimalFormat format;
|
||||
private final NumberFormat format;
|
||||
private final Path path = new Path();
|
||||
private final Paint fillPaint;
|
||||
private final Paint strokePaint;
|
||||
@@ -132,7 +132,6 @@ public class ChartValueSeries {
|
||||
* Constructs a new chart value series.
|
||||
*
|
||||
* @param context The context for the chart
|
||||
* @param formatString The format of the decimal format for this series
|
||||
* @param fillColor The paint for filling the chart
|
||||
* @param strokeColor The paint for stroking the outside the chart, optional
|
||||
* @param zoomSettings The settings related to zooming
|
||||
@@ -140,9 +139,9 @@ public class ChartValueSeries {
|
||||
*
|
||||
* TODO: Get rid of Context and inject appropriate values instead.
|
||||
*/
|
||||
public ChartValueSeries(Context context, String formatString, int fillColor, int strokeColor,
|
||||
ZoomSettings zoomSettings, int titleId) {
|
||||
this.format = new DecimalFormat(formatString);
|
||||
public ChartValueSeries(
|
||||
Context context, int fillColor, int strokeColor, ZoomSettings zoomSettings, int titleId) {
|
||||
this.format = NumberFormat.getIntegerInstance();
|
||||
fillPaint = new Paint();
|
||||
fillPaint.setStyle(Style.FILL);
|
||||
fillPaint.setColor(context.getResources().getColor(fillColor));
|
||||
@@ -251,9 +250,9 @@ public class ChartValueSeries {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The format for the decimal format for this series
|
||||
* @return The number format for this series
|
||||
*/
|
||||
DecimalFormat getFormat() {
|
||||
NumberFormat getFormat() {
|
||||
return format;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@ import android.view.View;
|
||||
import android.view.ViewConfiguration;
|
||||
import android.widget.Scroller;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -120,8 +119,13 @@ public class ChartView extends View {
|
||||
private ChartValueSeries[] series;
|
||||
|
||||
private final ExtremityMonitor xMonitor = new ExtremityMonitor();
|
||||
private static final NumberFormat X_FORMAT = new DecimalFormat("###,###");
|
||||
private static final NumberFormat X_SHORT_FORMAT = new DecimalFormat("#.0");
|
||||
private static final NumberFormat X_FORMAT = NumberFormat.getIntegerInstance();
|
||||
private static final NumberFormat X_SHORT_FORMAT = NumberFormat.getNumberInstance();
|
||||
|
||||
static {
|
||||
X_SHORT_FORMAT.setMaximumFractionDigits(1);
|
||||
X_SHORT_FORMAT.setMinimumFractionDigits(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Paints etc. used when drawing the chart:
|
||||
@@ -205,7 +209,6 @@ public class ChartView extends View {
|
||||
// Create the value series.
|
||||
series[ELEVATION_SERIES] =
|
||||
new ChartValueSeries(context,
|
||||
"###,###",
|
||||
R.color.elevation_fill,
|
||||
R.color.elevation_border,
|
||||
new ZoomSettings(MAX_INTERVALS,
|
||||
@@ -214,7 +217,6 @@ public class ChartView extends View {
|
||||
|
||||
series[SPEED_SERIES] =
|
||||
new ChartValueSeries(context,
|
||||
"###,###",
|
||||
R.color.speed_fill,
|
||||
R.color.speed_border,
|
||||
new ZoomSettings(MAX_INTERVALS, 0, Integer.MIN_VALUE,
|
||||
@@ -222,14 +224,12 @@ public class ChartView extends View {
|
||||
R.string.stat_speed);
|
||||
series[POWER_SERIES] =
|
||||
new ChartValueSeries(context,
|
||||
"###,###",
|
||||
R.color.power_fill,
|
||||
R.color.power_border,
|
||||
new ZoomSettings(MAX_INTERVALS, 0, 1000, new int[] {5, 50, 100, 200}),
|
||||
R.string.sensor_state_power);
|
||||
series[CADENCE_SERIES] =
|
||||
new ChartValueSeries(context,
|
||||
"###,###",
|
||||
R.color.cadence_fill,
|
||||
R.color.cadence_border,
|
||||
new ZoomSettings(MAX_INTERVALS, 0, Integer.MIN_VALUE,
|
||||
@@ -237,7 +237,6 @@ public class ChartView extends View {
|
||||
R.string.sensor_state_cadence);
|
||||
series[HEART_RATE_SERIES] =
|
||||
new ChartValueSeries(context,
|
||||
"###,###",
|
||||
R.color.heartrate_fill,
|
||||
R.color.heartrate_border,
|
||||
new ZoomSettings(MAX_INTERVALS, 0, Integer.MIN_VALUE,
|
||||
|
||||
@@ -24,7 +24,6 @@ import android.app.Activity;
|
||||
import android.util.Log;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
|
||||
/**
|
||||
@@ -35,15 +34,20 @@ import java.text.NumberFormat;
|
||||
public class StatsUtilities {
|
||||
|
||||
private final Activity activity;
|
||||
private static final NumberFormat LAT_LONG_FORMAT =
|
||||
new DecimalFormat("##,###.00000");
|
||||
private static final NumberFormat ALTITUDE_FORMAT =
|
||||
new DecimalFormat("###,###");
|
||||
private static final NumberFormat SPEED_FORMAT =
|
||||
new DecimalFormat("#,###,###.00");
|
||||
private static final NumberFormat GRADE_FORMAT =
|
||||
new DecimalFormat("##.0%");
|
||||
private static final NumberFormat LAT_LONG_FORMAT = NumberFormat.getNumberInstance();
|
||||
private static final NumberFormat ALTITUDE_FORMAT = NumberFormat.getIntegerInstance();
|
||||
private static final NumberFormat SPEED_FORMAT = NumberFormat.getNumberInstance();
|
||||
private static final NumberFormat GRADE_FORMAT = NumberFormat.getPercentInstance();
|
||||
|
||||
static {
|
||||
LAT_LONG_FORMAT.setMaximumFractionDigits(5);
|
||||
LAT_LONG_FORMAT.setMinimumFractionDigits(5);
|
||||
SPEED_FORMAT.setMaximumFractionDigits(2);
|
||||
SPEED_FORMAT.setMinimumFractionDigits(2);
|
||||
GRADE_FORMAT.setMaximumFractionDigits(1);
|
||||
GRADE_FORMAT.setMinimumFractionDigits(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* True if distances should be displayed in metric units (from shared
|
||||
* preferences).
|
||||
|
||||
@@ -15,14 +15,10 @@
|
||||
*/
|
||||
package com.google.android.apps.mytracks.io.docs;
|
||||
|
||||
import com.google.android.apps.mytracks.util.ApiFeatures;
|
||||
import com.google.android.apps.mytracks.util.StringUtils;
|
||||
import com.google.android.apps.mytracks.util.UnitConversions;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* <p>This class builds a string of XML tags used to talk to Docs using GData.
|
||||
@@ -47,12 +43,13 @@ import java.util.Locale;
|
||||
*/
|
||||
class DocsTagBuilder {
|
||||
|
||||
private static final DecimalFormatSymbols FORMAT_SYMBOLS =
|
||||
ApiFeatures.getInstance().getApiAdapter().getDecimalFormatSymbols(Locale.ENGLISH);
|
||||
private static final NumberFormat LARGE_UNIT_FORMAT =
|
||||
new DecimalFormat("#,###,###.00", FORMAT_SYMBOLS);
|
||||
private static final NumberFormat SMALL_UNIT_FORMAT =
|
||||
new DecimalFormat("###,###", FORMAT_SYMBOLS);
|
||||
private static final NumberFormat LARGE_UNIT_FORMAT = NumberFormat.getIntegerInstance();
|
||||
private static final NumberFormat SMALL_UNIT_FORMAT = NumberFormat.getNumberInstance();
|
||||
|
||||
static {
|
||||
SMALL_UNIT_FORMAT.setMaximumFractionDigits(2);
|
||||
SMALL_UNIT_FORMAT.setMinimumFractionDigits(2);
|
||||
}
|
||||
|
||||
protected final boolean metricUnits;
|
||||
protected final StringBuilder stringBuilder;
|
||||
|
||||
@@ -33,8 +33,6 @@ import android.util.Log;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* API level 3 specific implementation of the {@link ApiLevelAdapter}.
|
||||
@@ -112,11 +110,6 @@ public class ApiLevel3Adapter implements ApiLevelAdapter {
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DecimalFormatSymbols getDecimalFormatSymbols(Locale locale) {
|
||||
return new DecimalFormatSymbols(locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpTransport getHttpTransport() {
|
||||
return new ApacheHttpTransport();
|
||||
|
||||
@@ -8,9 +8,7 @@ import android.content.SharedPreferences.Editor;
|
||||
import android.os.StrictMode;
|
||||
import android.util.Log;
|
||||
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* API level 9 specific implementation of the {@link ApiLevelAdapter}.
|
||||
@@ -43,12 +41,7 @@ public class ApiLevel9Adapter extends ApiLevel8Adapter {
|
||||
public byte[] copyByteArray(byte[] input, int start, int end) {
|
||||
return Arrays.copyOfRange(input, start, end);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DecimalFormatSymbols getDecimalFormatSymbols(Locale locale) {
|
||||
return DecimalFormatSymbols.getInstance(locale);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public HttpTransport getHttpTransport() {
|
||||
return new NetHttpTransport();
|
||||
|
||||
@@ -25,9 +25,6 @@ import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* A set of methods that may be implemented differently depending on the Android API level.
|
||||
*
|
||||
@@ -107,16 +104,6 @@ public interface ApiLevelAdapter {
|
||||
byte[] copyByteArray(byte[] input, int start, int end);
|
||||
|
||||
|
||||
/**
|
||||
* Gets an instance of {@link DecimalFormatSymbols} for a locale.
|
||||
*
|
||||
* Due to changes in API level 9.
|
||||
*
|
||||
* @param locale the locale
|
||||
* @return a new instance of {@link DecimalFormatSymbols}
|
||||
*/
|
||||
DecimalFormatSymbols getDecimalFormatSymbols(Locale locale);
|
||||
|
||||
/**
|
||||
* Gets a {@link HttpTransport}.
|
||||
*
|
||||
|
||||
@@ -25,7 +25,7 @@ import com.google.android.maps.mytracks.R;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.ParsePosition;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
@@ -66,7 +66,12 @@ public class StringUtils implements DescriptionGenerator {
|
||||
return formatTimeInternal(time, true);
|
||||
}
|
||||
|
||||
private static final DecimalFormat SINGLE_DECIMAL_PLACE_FORMAT = new DecimalFormat("#.#");
|
||||
private static final NumberFormat SINGLE_DECIMAL_PLACE_FORMAT = NumberFormat.getNumberInstance();
|
||||
|
||||
static {
|
||||
SINGLE_DECIMAL_PLACE_FORMAT.setMaximumFractionDigits(1);
|
||||
SINGLE_DECIMAL_PLACE_FORMAT.setMinimumFractionDigits(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a double precision number as decimal number with a single decimal
|
||||
|
||||
@@ -30,7 +30,6 @@ public class ChartValueSeriesTest extends AndroidTestCase {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
series = new ChartValueSeries(getContext(),
|
||||
"###,###",
|
||||
R.color.elevation_fill,
|
||||
R.color.elevation_border,
|
||||
new ZoomSettings(5, new int[] {100}),
|
||||
|
||||
Reference in New Issue
Block a user