Introduced the constant for measurement units in the settings.

This commit is contained in:
Alex Zolotarev 2016-03-13 21:41:03 +03:00 committed by Sergey Yershov
parent e5eea122a8
commit 569b37c29d
13 changed files with 28 additions and 26 deletions

View file

@ -9,14 +9,14 @@ extern "C"
Java_com_mapswithme_maps_settings_UnitLocale_setCurrentUnits(JNIEnv * env, jobject thiz, jint units)
{
Settings::Units const u = static_cast<Settings::Units>(units);
Settings::Set("Units", u);
Settings::Set(Settings::kMeasurementUnits, u);
g_framework->SetupMeasurementSystem();
}
JNIEXPORT jint JNICALL
Java_com_mapswithme_maps_settings_UnitLocale_getCurrentUnits(JNIEnv * env, jobject thiz)
{
Settings::Units u = Settings::Metric;
return (Settings::Get("Units", u) ? u : -1);
Settings::Units u;
return (Settings::Get(Settings::kMeasurementUnits, u) ? u : -1);
}
}

View file

@ -225,7 +225,7 @@ double RulerHelper::CalcMetresDiff(double value)
ConversionFn conversionFn = &identity;
Settings::Units units = Settings::Metric;
Settings::Get("Units", units);
Settings::Get(Settings::kMeasurementUnits, units);
if (units == Settings::Foot)
{

View file

@ -11,13 +11,12 @@
+ (void)setup
{
Settings::Units u;
string const units = "Units";
if (!Settings::Get(units, u))
if (!Settings::Get(Settings::kMeasurementUnits, u))
{
// get system locale preferences
BOOL const isMetric = [[[NSLocale autoupdatingCurrentLocale] objectForKey:NSLocaleUsesMetricSystem] boolValue];
u = isMetric ? Settings::Metric : Settings::Foot;
Settings::Set(units, u);
Settings::Set(Settings::kMeasurementUnits, u);
}
GetFramework().SetupMeasurementSystem();
}

View file

@ -88,7 +88,7 @@ typedef NS_ENUM(NSUInteger, Section)
{
cell = [tableView dequeueReusableCellWithIdentifier:[SelectableCell className]];
Settings::Units units = Settings::Metric;
(void)Settings::Get("Units", units);
(void)Settings::Get(Settings::kMeasurementUnits, units);
BOOL const selected = units == unitsForIndex(indexPath.row);
SelectableCell * customCell = (SelectableCell *)cell;
customCell.accessoryType = selected ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
@ -322,7 +322,7 @@ Settings::Units unitsForIndex(NSInteger index)
Settings::Units units = unitsForIndex(indexPath.row);
[[Statistics instance] logEvent:kStatEventName(kStatSettings, kStatChangeMeasureUnits)
withParameters:@{kStatValue : (units == Settings::Units::Metric ? kStatKilometers : kStatMiles)}];
Settings::Set("Units", units);
Settings::Set(Settings::kMeasurementUnits, units);
[tableView reloadSections:[NSIndexSet indexSetWithIndex:SectionMetrics] withRowAnimation:UITableViewRowAnimationFade];
GetFramework().SetupMeasurementSystem();
break;

View file

@ -1521,7 +1521,7 @@ void Framework::SetupMeasurementSystem()
GetPlatform().SetupMeasurementSystem();
Settings::Units units = Settings::Metric;
Settings::Get("Units", units);
Settings::Get(Settings::kMeasurementUnits, units);
m_routingSession.SetTurnNotificationsUnits(units);
}

View file

@ -49,7 +49,7 @@ bool FormatDistanceImpl(double m, string & res,
bool FormatDistance(double m, string & res)
{
Units u = Metric;
(void)Get("Units", u);
(void)Get(Settings::kMeasurementUnits, u);
/// @todo Put string units resources.
switch (u)
@ -152,7 +152,7 @@ void FormatMercator(m2::PointD const & mercator, string & lat, string & lon, int
string FormatAltitude(double altitudeInMeters)
{
Units u = Metric;
(void)Get("Units", u);
(void)Get(Settings::kMeasurementUnits, u);
ostringstream ss;
ss << fixed << setprecision(0);
@ -169,7 +169,7 @@ string FormatAltitude(double altitudeInMeters)
string FormatSpeed(double metersPerSecond)
{
Units u = Metric;
(void)Get("Units", u);
(void)Get(Settings::kMeasurementUnits, u);
double perHour;
string res;

View file

@ -252,11 +252,11 @@ Platform::EError Platform::MkDir(string const & dirName) const
void Platform::SetupMeasurementSystem() const
{
Settings::Units u;
if (Settings::Get("Units", u))
if (Settings::Get(Settings::kMeasurementUnits, u))
return;
// @TODO Add correct implementation
u = Settings::Metric;
Settings::Set("Units", u);
Settings::Set(Settings::kMeasurementUnits, u);
}
namespace

View file

@ -263,11 +263,11 @@ Platform::EConnectionType Platform::ConnectionStatus()
void Platform::SetupMeasurementSystem() const
{
Settings::Units u;
if (Settings::Get("Units", u))
if (Settings::Get(Settings::kMeasurementUnits, u))
return;
BOOL const isMetric = [[[NSLocale autoupdatingCurrentLocale] objectForKey:NSLocaleUsesMetricSystem] boolValue];
u = isMetric ? Settings::Metric : Settings::Foot;
Settings::Set("Units", u);
Settings::Set(Settings::kMeasurementUnits, u);
}
////////////////////////////////////////////////////////////////////////

View file

@ -75,11 +75,11 @@ Platform::EError Platform::MkDir(string const & dirName) const
void Platform::SetupMeasurementSystem() const
{
Settings::Units u;
if (Settings::Get("Units", u))
if (Settings::Get(Settings::kMeasurementUnits, u))
return;
bool const isMetric = QLocale::system().measurementSystem() == QLocale::MetricSystem;
u = isMetric ? Settings::Metric : Settings::Foot;
Settings::Set("Units", u);
Settings::Set(Settings::kMeasurementUnits, u);
}
#if defined(OMIM_OS_LINUX)

View file

@ -8,7 +8,7 @@ using namespace MeasurementUtils;
UNIT_TEST(Measurement_Smoke)
{
Settings::Set("Units", Settings::Metric);
Settings::Set(Settings::kMeasurementUnits, Settings::Metric);
typedef pair<double, char const *> PairT;
@ -66,15 +66,15 @@ UNIT_TEST(LatLonToDMS_NoRounding)
UNIT_TEST(FormatAltitude)
{
Settings::Set("Units", Settings::Foot);
Settings::Set(Settings::kMeasurementUnits, Settings::Foot);
TEST_EQUAL(FormatAltitude(10000), "32808ft", ());
Settings::Set("Units", Settings::Metric);
Settings::Set(Settings::kMeasurementUnits, Settings::Metric);
TEST_EQUAL(FormatAltitude(5), "5m", ());
}
UNIT_TEST(FormatSpeed)
{
Settings::Set("Units", Settings::Metric);
Settings::Set(Settings::kMeasurementUnits, Settings::Metric);
TEST_EQUAL(FormatSpeed(10), "36km/h", ());
TEST_EQUAL(FormatSpeed(1), "3.6km/h", ());
}

View file

@ -25,6 +25,7 @@ char const DELIM_CHAR = '=';
}
char const * Settings::kLocationStateMode = "LastLocationStateMode";
char const * Settings::kMeasurementUnits = "Units";
namespace Settings
{

View file

@ -6,8 +6,10 @@
namespace Settings
{
// Current location state mode. @See location::EMyPositionMode.
/// Current location state mode. @See location::EMyPositionMode.
extern char const * kLocationStateMode;
/// Metric or Feet.
extern char const * kMeasurementUnits;
template <class T>
bool FromString(string const & str, T & outValue);

View file

@ -53,7 +53,7 @@ namespace qt
radioBox->setLayout(pLayout);
Units u;
if (!Settings::Get("Units", u))
if (!Settings::Get(Settings::kMeasurementUnits, u))
{
// set default measurement from system locale
if (QLocale::system().measurementSystem() == QLocale::MetricSystem)
@ -101,6 +101,6 @@ namespace qt
case 1: u = Foot; break;
}
Settings::Set("Units", u);
Settings::Set(kMeasurementUnits, u);
}
}