gt:                 SettingsActivity activity = (SettingsActivity)getActivity();
context: package com.chanapps.four.fragment;
  
  import java.io.File;
  
  import android.app.Activity;
  import android.app.AlarmManager;
  import android.app.PendingIntent;
  import android.content.Context;
  import android.content.Intent;
  import android.os.Bundle;
  import android.os.Handler;
  import android.os.Message;
  import android.preference.Preference;
  import android.preference.PreferenceFragment;
  import android.widget.BaseAdapter;
  import android.widget.Toast;
  
  import com.chanapps.four.activity.AboutActivity;
  import com.chanapps.four.activity.R;
  import com.chanapps.four.activity.SettingsActivity;
  import com.chanapps.four.activity.StartupActivity;
  import com.chanapps.four.data.ChanFileStorage;
  
  
  /**
   * Created with IntelliJ IDEA.
   * User: arley
   * Date: 11/22/12
   * Time: 3:12 PM
   * To change this template use File | Settings | File Templates.
   */
  public class SettingsFragment
          extends PreferenceFragment
  //        implements SharedPreferences.OnSharedPreferenceChangeListener
  {
  
      protected static final boolean DEBUG = false;
      protected static final String TAG = SettingsFragment.class.getSimpleName();
  
      protected static final int STARTUP_INTENT = 0x80134148; // magic number
      protected static final int RESTART_DELAY_MS = 250;
  
      protected Preference downloadLocationButton;
  
      public Handler handler;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          initPreferenceScreen();
  //        getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
      }
  
      public void initPreferenceScreen() {
          addPreferencesFromResource(R.xml.preferences);
          /*
          Preference blocklistButton = findPreference(SettingsActivity.PREF_BLOCKLIST_BUTTON);
          blocklistButton.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
              @Override
              public boolean onPreferenceClick(Preference preference) {
                  List<Pair<String, ChanBlocklist.BlockType>> blocks = ChanBlocklist.getSorted(getActivity());
                  (new BlocklistViewAllDialogFragment(blocks)).show(getFragmentManager(),TAG);
                  return true;
              }
          });
          */
          Preference resetPrefsButton = findPreference(SettingsActivity.PREF_RESET_TO_DEFAULTS);
          resetPrefsButton.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
              @Override
              public boolean onPreferenceClick(Preference preference) {
                  (new ResetPreferencesDialogFragment(SettingsFragment.this))
                          .show(getFragmentManager(), SettingsFragment.TAG);
                  return true;
              }
          });
  
          Preference clearCacheButton = findPreference(SettingsActivity.PREF_CLEAR_CACHE);
          clearCacheButton.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
              @Override
              public boolean onPreferenceClick(Preference preference) {
                  (new ClearCacheDialogFragment(SettingsFragment.this))
                          .show(getFragmentManager(), SettingsFragment.TAG);
                  return true;
              }
          });
          /*
          Preference clearWatchlistButton = findPreference(SettingsActivity.PREF_CLEAR_WATCHLIST);
          clearWatchlistButton.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
              @Override
              public boolean onPreferenceClick(Preference preference) {
                  (new WatchlistClearDialogFragment())
                          .show(getFragmentManager(), WatchlistClearDialogFragment.TAG);
                  return true;
              }
          });
  
          Preference clearFavoritesButton = findPreference(SettingsActivity.PREF_CLEAR_FAVORITES);
          clearFavoritesButton.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
              @Override
              public boolean onPreferenceClick(Preference preference) {
                  (new FavoritesClearDialogFragment())
                          .show(getFragmentManager(), FavoritesClearDialogFragment.TAG);
                  return true;
              }
          });
          */
          Preference aboutButton = findPreference(SettingsActivity.PREF_ABOUT);
          aboutButton.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
              @Override
              public boolean onPreferenceClick(Preference preference) {
                  Intent intent = new Intent(getActivity(), AboutActivity.class);
                  startActivity(intent);
                  return true;
              }
          });
  
          downloadLocationButton = findPreference(SettingsActivity.PREF_DOWNLOAD_LOCATION);
          downloadLocationButton.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
              @Override
              public boolean onPreferenceClick(Preference preference) {
                  File downloadFolder = ChanFileStorage.getDownloadFolder(getActivity(), null, 0, true);
                  DialogChooseDirectory d = new DialogChooseDirectory(getActivity(), chooseDirectoryHandler,
                          downloadFolder.getAbsolutePath());
                  return true;
              }
          });
          File downloadFolder = ChanFileStorage.getDownloadFolder(getActivity(), null, 0, true);
          downloadLocationButton.setSummary(downloadFolder.getAbsolutePath());
  
          Preference forceEnglish = findPreference(SettingsActivity.PREF_FORCE_ENGLISH);
  
          forceEnglish.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
              @Override
              public boolean onPreferenceChange(Preference preference, Object newValue) {
                  //Toast.makeText(getActivity(), "onChange", Toast.LENGTH_SHORT).show();
                  restartApp();
                  return true;  //To change body of implemented methods use File | Settings | File Templates.
              }
          });
  
      };
  
  
          /*
          Preference.OnPreferenceClickListener namesListener = new Preference.OnPreferenceClickListener() {
              @Override
              public boolean onPreferenceClick(Preference preference) {
                  //NetworkProfileManager.instance().getUserStatistics().featureUsed(UserStatistics.ChanFeature.SETTINGS_NAMES);
                  return false;
              }
          };
          Preference name = findPreference(SettingsActivity.PREF_USER_NAME);
          Preference email = findPreference(SettingsActivity.PREF_USER_EMAIL);
          Preference password = findPreference(SettingsActivity.PREF_USER_PASSWORD);
          name.setOnPreferenceClickListener(namesListener);
          email.setOnPreferenceClickListener(namesListener);
          password.setOnPreferenceClickListener(namesListener);
          */
  
          /*
          Preference.OnPreferenceChangeListener abbrevBoardsListener = new Preference.OnPreferenceChangeListener() {
              @Override
              public boolean onPreferenceChange(Preference preference, Object newValue) {
                  if (DEBUG) Log.i(TAG, "onPrefrenceChange pref=" + preference.getKey() + " newVal=" + newValue);
                  Boolean b = newValue instanceof Boolean ? (Boolean) newValue : null;
                  BoardActivity.updateAbbrev(getActivity(), b != null ? b : false);
                  return true;
              }
          };
          Preference abbrevBoards = findPreference(SettingsActivity.PREF_USE_ABBREV_BOARDS);
          abbrevBoards.setOnPreferenceChangeListener(abbrevBoardsListener);
          */
          /*
          Preference.OnPreferenceChangeListener fastScrollBoardsListener = new Preference.OnPreferenceChangeListener() {
              @Override
              public boolean onPreferenceChange(Preference preference, Object newValue) {
                  if (DEBUG) Log.i(TAG, "onPrefrenceChange pref=" + preference.getKey() + " newVal=" + newValue);
                  Boolean b = newValue instanceof Boolean ? (Boolean) newValue : null;
                  BoardActivity.updateFastScroll(getActivity(), b != null ? b : false);
                  return true;
              }
          };
          Preference fastScrollBoards = findPreference(SettingsActivity.PREF_USE_FAST_SCROLL);
          fastScrollBoards.setOnPreferenceChangeListener(fastScrollBoardsListener);
          */
          /*
          Preference.OnPreferenceChangeListener catalogListener = new Preference.OnPreferenceChangeListener() {
              @Override
              public boolean onPreferenceChange(Preference preference, Object newValue) {
                  if (DEBUG) Log.i(TAG, "onPrefrenceChange pref=" + preference.getKey() + " newVal=" + newValue);
                  Boolean b = newValue instanceof Boolean ? (Boolean) newValue : null;
                  BoardActivity.updateCatalog(getActivity(), b != null ? b : false);
                  return true;
              }
          };
          Preference catalog = findPreference(SettingsActivity.PREF_USE_CATALOG);
          catalog.setOnPreferenceChangeListener(catalogListener);
          */
          /*
          Preference.OnPreferenceChangeListener hideLastRepliesListener = new Preference.OnPreferenceChangeListener() {
              @Override
              public boolean onPreferenceChange(Preference preference, Object newValue) {
                  if (DEBUG) Log.i(TAG, "onPrefrenceChange pref=" + preference.getKey() + " newVal=" + newValue);
                  Boolean b = newValue instanceof Boolean ? (Boolean) newValue : null;
                  BoardActivity.updateHideLastReplies(getActivity(), b != null ? b : false);
                  return true;
              }
          };
          Preference hideLastReplies = findPreference(SettingsActivity.PREF_HIDE_LAST_REPLIES);
          hideLastReplies.setOnPreferenceChangeListener(hideLastRepliesListener);
          */
          /*
          Preference.OnPreferenceChangeListener nsfwListener = new Preference.OnPreferenceChangeListener() {
              @Override
              public boolean onPreferenceChange(Preference preference, Object newValue) {
                  BoardActivity.refreshAllBoards();
                  return true;
              }
          };
          Preference showNsfw = findPreference(SettingsActivity.PREF_SHOW_NSFW_BOARDS);
          showNsfw.setOnPreferenceChangeListener(nsfwListener);
          */
          /*
          Preference.OnPreferenceChangeListener themeListener = new Preference.OnPreferenceChangeListener() {
              @Override
              public boolean onPreferenceChange(Preference preference, Object newValue) {
  