diff options
author | DvTonder <david.vantonder@gmail.com> | 2013-01-07 08:55:01 -0500 |
---|---|---|
committer | Danny Baumann <dannybaumann@web.de> | 2013-01-07 18:12:19 +0100 |
commit | 2948010ddb281ca2f1221ccaa4f39beedc61dc30 (patch) | |
tree | 0042db1d5ebb4c90801ef7bdd09f6dab46d57036 /src/com/cyanogenmod | |
parent | 177033977bc2300ea6d61f6beceb049efbf67988 (diff) | |
download | android_packages_apps_LockClock-2948010ddb281ca2f1221ccaa4f39beedc61dc30.tar.gz android_packages_apps_LockClock-2948010ddb281ca2f1221ccaa4f39beedc61dc30.tar.bz2 android_packages_apps_LockClock-2948010ddb281ca2f1221ccaa4f39beedc61dc30.zip |
Chronus: Location provider fixes and cleanup
This commit switches Chronus to only use the Passive location
provider and adds the FINE location permission. It also includes
some general cleanup and better handling of the setting of a
custom location, fixing a NPE and ensuring the summary text is
updated correctly.
Change-Id: Ic3e870eefb66b0b81fa45ab9da6b3a8b04e63334
Diffstat (limited to 'src/com/cyanogenmod')
4 files changed, 29 insertions, 25 deletions
diff --git a/src/com/cyanogenmod/lockclock/ClockWidgetService.java b/src/com/cyanogenmod/lockclock/ClockWidgetService.java index ec7384e..95a5338 100644 --- a/src/com/cyanogenmod/lockclock/ClockWidgetService.java +++ b/src/com/cyanogenmod/lockclock/ClockWidgetService.java @@ -304,16 +304,7 @@ public class ClockWidgetService extends Service { } } else { // network location - Criteria crit = new Criteria(); - crit.setAccuracy(Criteria.ACCURACY_COARSE); - String bestProvider = locationManager.getBestProvider(crit, true); - Location loc = null; - - if (bestProvider != null) { - loc = locationManager.getLastKnownLocation(bestProvider); - } else { - loc = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER); - } + Location loc = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER); if (loc != null) { try { diff --git a/src/com/cyanogenmod/lockclock/preference/CalendarPreferences.java b/src/com/cyanogenmod/lockclock/preference/CalendarPreferences.java index 6caf183..884bce9 100644 --- a/src/com/cyanogenmod/lockclock/preference/CalendarPreferences.java +++ b/src/com/cyanogenmod/lockclock/preference/CalendarPreferences.java @@ -55,7 +55,7 @@ public class CalendarPreferences extends PreferenceFragment implements mContext = getActivity(); // Load the required settings from preferences - SharedPreferences prefs = mContext.getSharedPreferences(PREF_NAME, Context.MODE_MULTI_PROCESS); + SharedPreferences prefs = mContext.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE); // The calendar list entries and values are determined at run time, not in XML mCalendarList = (MultiSelectListPreference) findPreference(Constants.CALENDAR_LIST); diff --git a/src/com/cyanogenmod/lockclock/preference/ClockPreferences.java b/src/com/cyanogenmod/lockclock/preference/ClockPreferences.java index 17b9b1f..e8d9f1c 100644 --- a/src/com/cyanogenmod/lockclock/preference/ClockPreferences.java +++ b/src/com/cyanogenmod/lockclock/preference/ClockPreferences.java @@ -45,7 +45,7 @@ public class ClockPreferences extends PreferenceFragment implements mContext = getActivity(); // Load the required settings from preferences - SharedPreferences prefs = mContext.getSharedPreferences(PREF_NAME, Context.MODE_MULTI_PROCESS); + SharedPreferences prefs = mContext.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE); prefs.registerOnSharedPreferenceChangeListener(this); } diff --git a/src/com/cyanogenmod/lockclock/preference/WeatherPreferences.java b/src/com/cyanogenmod/lockclock/preference/WeatherPreferences.java index 114b87b..c63ba81 100644 --- a/src/com/cyanogenmod/lockclock/preference/WeatherPreferences.java +++ b/src/com/cyanogenmod/lockclock/preference/WeatherPreferences.java @@ -34,6 +34,7 @@ import android.preference.CheckBoxPreference; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; +import android.preference.PreferenceScreen; import android.preference.Preference.OnPreferenceClickListener; import android.preference.PreferenceFragment; import android.provider.Settings; @@ -69,7 +70,7 @@ public class WeatherPreferences extends PreferenceFragment implements mResolver = mContext.getContentResolver(); // Load the required settings from preferences - SharedPreferences prefs = mContext.getSharedPreferences(PREF_NAME, Context.MODE_MULTI_PROCESS); + SharedPreferences prefs = mContext.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE); // Some preferences need to be set to a default value in code since we cannot do them in XML mUseMetric = (CheckBoxPreference) findPreference(Constants.WEATHER_USE_METRIC); @@ -83,9 +84,11 @@ public class WeatherPreferences extends PreferenceFragment implements // Load items that need custom summaries etc. mUseCustomLoc = (CheckBoxPreference) findPreference(Constants.WEATHER_USE_CUSTOM_LOCATION); + mUseCustomLoc.setChecked(prefs.getBoolean(Constants.WEATHER_USE_CUSTOM_LOCATION, false)); + mUseCustomLoc.setOnPreferenceClickListener(this); mCustomWeatherLoc = (EditTextPreference) findPreference(Constants.WEATHER_CUSTOM_LOCATION_STRING); - updateLocationSummary(); mCustomWeatherLoc.setOnPreferenceClickListener(this); + updateLocationSummary(); // Show a warning if location manager is disabled and there is no custom location set if (!Settings.Secure.isLocationProviderEnabled(mResolver, @@ -98,8 +101,7 @@ public class WeatherPreferences extends PreferenceFragment implements } @Override - public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, - String key) { + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { Preference pref = findPreference(key); if (pref instanceof ListPreference) { ListPreference listPref = (ListPreference) pref; @@ -111,13 +113,25 @@ public class WeatherPreferences extends PreferenceFragment implements } @Override - public boolean onPreferenceClick(Preference preference) { + public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { + if (preference == mUseCustomLoc) { + SharedPreferences prefs = mContext.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE); + prefs.edit().putBoolean(Constants.WEATHER_USE_CUSTOM_LOCATION, mUseCustomLoc.isChecked()).apply(); + updateLocationSummary(); + return true; + } + return super.onPreferenceTreeClick(preferenceScreen, preference); + } + @Override + public boolean onPreferenceClick(Preference preference) { if (preference == mCustomWeatherLoc) { - SharedPreferences prefs = mContext.getSharedPreferences(PREF_NAME, Context.MODE_MULTI_PROCESS); - String location = prefs.getString(Constants.WEATHER_CUSTOM_LOCATION_STRING, ""); - mCustomWeatherLoc.getEditText().setText(location); - mCustomWeatherLoc.getEditText().setSelection(location.length()); + SharedPreferences prefs = mContext.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE); + String location = prefs.getString(Constants.WEATHER_CUSTOM_LOCATION_STRING, null); + if (location != null) { + mCustomWeatherLoc.getEditText().setText(location); + mCustomWeatherLoc.getEditText().setSelection(location.length()); + } mCustomWeatherLoc.getDialog().findViewById(android.R.id.button1) .setOnClickListener(new View.OnClickListener() { @@ -142,8 +156,7 @@ public class WeatherPreferences extends PreferenceFragment implements mCustomWeatherLoc.setSummary(location); mCustomWeatherLoc.getDialog().dismiss(); - SharedPreferences prefs = mContext.getSharedPreferences( - PREF_NAME, Context.MODE_MULTI_PROCESS); + SharedPreferences prefs = mContext.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE); prefs.edit().putString(Constants.WEATHER_CUSTOM_LOCATION_STRING, location).apply(); } d.dismiss(); @@ -178,8 +191,8 @@ public class WeatherPreferences extends PreferenceFragment implements private void updateLocationSummary() { if (mUseCustomLoc.isChecked()) { - SharedPreferences prefs = mContext.getSharedPreferences(PREF_NAME, Context.MODE_MULTI_PROCESS); - String location = prefs.getString(Constants.WEATHER_CUSTOM_LOCATION_STRING, + SharedPreferences prefs = mContext.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE); + String location = prefs.getString(Constants.WEATHER_CUSTOM_LOCATION_STRING, getResources().getString(R.string.unknown)); mCustomWeatherLoc.setSummary(location); } else { |