diff options
author | Roman Birg <roman@cyngn.com> | 2014-03-03 18:12:51 -0800 |
---|---|---|
committer | DvTonder <david.vantonder@gmail.com> | 2014-03-09 16:49:36 -0500 |
commit | 25c510af6883393e53476c1c4eb918e6b1598a7a (patch) | |
tree | 220e44a53187c0fa9de055a5eb52e19e64a6a46a /src/com/cyanogenmod | |
parent | 95c886e1e2f313d9c31f0ab122446e1df4ead8b7 (diff) | |
download | android_packages_apps_LockClock-25c510af6883393e53476c1c4eb918e6b1598a7a.tar.gz android_packages_apps_LockClock-25c510af6883393e53476c1c4eb918e6b1598a7a.tar.bz2 android_packages_apps_LockClock-25c510af6883393e53476c1c4eb918e6b1598a7a.zip |
LockClock: detect default units based on locale
US, Malasia, and Sri Lanka are the only countries
which still use imperial units, so do not use
metric units as defualt if possible.
Change-Id: Ie3d7de33fc3120926a5871b3814f488b145cd464
Signed-off-by: Roman Birg <roman@cyngn.com>
Diffstat (limited to 'src/com/cyanogenmod')
-rw-r--r-- | src/com/cyanogenmod/lockclock/misc/Preferences.java | 12 | ||||
-rw-r--r-- | src/com/cyanogenmod/lockclock/preference/WeatherPreferences.java | 7 |
2 files changed, 18 insertions, 1 deletions
diff --git a/src/com/cyanogenmod/lockclock/misc/Preferences.java b/src/com/cyanogenmod/lockclock/misc/Preferences.java index 8e4c165..01e1d45 100644 --- a/src/com/cyanogenmod/lockclock/misc/Preferences.java +++ b/src/com/cyanogenmod/lockclock/misc/Preferences.java @@ -26,6 +26,7 @@ import com.cyanogenmod.lockclock.weather.WeatherProvider; import com.cyanogenmod.lockclock.weather.YahooWeatherProvider; import java.util.Calendar; +import java.util.Locale; import java.util.Set; public class Preferences { @@ -145,7 +146,16 @@ public class Preferences { } public static boolean useMetricUnits(Context context) { - return getPrefs(context).getBoolean(Constants.WEATHER_USE_METRIC, true); + Locale locale = context.getResources().getConfiguration().locale; + boolean defValue = !(locale.equals(Locale.US) + || locale.toString().equals("ms_MY") // Malaysia + || locale.toString().equals("si_LK") // Sri Lanka + ); + return getPrefs(context).getBoolean(Constants.WEATHER_USE_METRIC, defValue); + } + + public static void setUseMetricUnits(Context context, boolean value) { + getPrefs(context).edit().putBoolean(Constants.WEATHER_USE_METRIC, value).apply(); } public static long weatherRefreshIntervalInMs(Context context) { diff --git a/src/com/cyanogenmod/lockclock/preference/WeatherPreferences.java b/src/com/cyanogenmod/lockclock/preference/WeatherPreferences.java index 9b06246..94537c0 100644 --- a/src/com/cyanogenmod/lockclock/preference/WeatherPreferences.java +++ b/src/com/cyanogenmod/lockclock/preference/WeatherPreferences.java @@ -81,6 +81,12 @@ public class WeatherPreferences extends PreferenceFragment implements mUseMetric = (CheckBoxPreference) findPreference(Constants.WEATHER_USE_METRIC); mUseCustomlocation = (CheckBoxPreference) findPreference(Constants.WEATHER_USE_CUSTOM_LOCATION); + // At first placement/start default the use of Metric units based on locale + // If we had a previously set value already, this will just reset the same value + Boolean defValue = Preferences.useMetricUnits(mContext); + Preferences.setUseMetricUnits(mContext, defValue); + mUseMetric.setChecked(defValue); + // Show a warning if location manager is disabled and there is no custom location set LocationManager lm = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); if (!lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER) && !mUseCustomLoc.isChecked()) { @@ -91,6 +97,7 @@ public class WeatherPreferences extends PreferenceFragment implements @Override public void onResume() { super.onResume(); + getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this); updateLocationSummary(); updateFontColorsSummary(); |