@Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (key.equalsIgnoreCase(getString(R.string.pref_keys_location))) { // Wipe out any potential PlacePicker latlng values so that we can use this text entry. SharedPreferences.Editor editor = sharedPreferences.edit(); editor.remove(getString(R.string.pref_location_latitude)); editor.remove(getString(R.string.pref_location_longitude)); editor.commit(); // Remove attributions for our any PlacePicker locations. if (mAttribution != null) { mAttribution.setVisibility(View.GONE); } Utility.resetLocationStatus(this); SunshineSyncAdapter.syncImmediately(this); } else if (key.equalsIgnoreCase(getString(R.string.pref_keys_location_key_status))) { // our location status has changed. Update the summary accordingly Preference locationPreference = findPreference(getString(R.string.pref_keys_location)); bindPreferenceSummaryToValue(locationPreference); } else if (key.equals(getString(R.string.pref_keys_unit_type))) { // units have changed. update lists of weather entries accordingly getContentResolver().notifyChange(WeatherContract.WeatherEntry.CONTENT_URI, null); } else if (key.equals(getString(R.string.pref_key_icon))) { // art pack have changed. update lists of weather entries accordingly getContentResolver().notifyChange(WeatherContract.WeatherEntry.CONTENT_URI, null); } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // Check to see if the result is from our Place Picker intent if (requestCode == PLACE_PICKER_REQUEST) { // Make sure the request was successful if (resultCode == RESULT_OK) { Place place = PlacePicker.getPlace(data, this); String address = place.getAddress().toString(); LatLng latLong = place.getLatLng(); // If the provided place doesn't have an address, we'll form a display-friendly // string from the latlng values. if (TextUtils.isEmpty(address)) { address = String.format("(%.2f, %.2f)", latLong.latitude, latLong.longitude); } SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString(getString(R.string.pref_keys_location), address); // Also store the latitude and longitude so that we can use these to get a precise // result from our weather service. We cannot expect the weather service to // understand addresses that Google formats. editor.putFloat(getString(R.string.pref_location_latitude), (float) latLong.latitude); editor.putFloat(getString(R.string.pref_location_longitude), (float) latLong.longitude); editor.commit(); /*Refresh The Preference*/ // Tell the SyncAdapter that we've changed the location, so that we can update // our UI with new values. We need to do this manually because we are responding // to the PlacePicker widget result here instead of allowing the // LocationEditTextPreference to handle these changes and invoke our callbacks Preference locationPreference = findPreference(getString(R.string.pref_keys_location)); locationPreference.setSummary(address); // Add attributions for our new PlacePicker location. if (mAttribution != null) { mAttribution.setVisibility(View.VISIBLE); } else { // For pre-Honeycomb devices, we cannot add a footer, so we will use a snackbar View rootView = findViewById(android.R.id.content); Snackbar.make(rootView, getString(R.string.attribution_text), Snackbar.LENGTH_LONG) .show(); } Utility.resetLocationStatus(this); SunshineSyncAdapter.syncImmediately(this); } } else { super.onActivityResult(requestCode, resultCode, data); } }