Back to project page demo-flickr-feed-android.
The source code is released under:
This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...
If you think the Android project demo-flickr-feed-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package uk.org.tomek.flickrfeed.fagment; /*from ww w . j av a 2s. c o m*/ import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceFragment; import uk.org.tomek.flickrfeed.R; import uk.org.tomek.flickrfeed.utils.Logger; /** * Preference Fragment implementation. * <p/> * Created by tomek on 23/11/14. */ public class SettingsFragment extends PreferenceFragment { public static final String FLICKR_SEARCH_TERM_KEY = "pref_flickr_search_term_key"; private final Logger mLogger = Logger.getLogger(SettingsFragment.class); /** * Listener to shared preferences changes (change to search term) * * @param sharedPreferences * @param key */ private SharedPreferences.OnSharedPreferenceChangeListener mListener = new SharedPreferences.OnSharedPreferenceChangeListener() { public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { // listener implementation if (key.equalsIgnoreCase(SettingsFragment.FLICKR_SEARCH_TERM_KEY)) { String searchTerm = sharedPreferences.getString(key, "rome"); mLogger.v("SearchTerm changed to:%s", searchTerm); // TODO: Do something with it //getActivity().finish(); } } }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); } @Override public void onResume() { super.onResume(); getPreferenceScreen().getSharedPreferences() .registerOnSharedPreferenceChangeListener(mListener); } @Override public void onPause() { super.onPause(); getPreferenceScreen().getSharedPreferences() .unregisterOnSharedPreferenceChangeListener(mListener); } }