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