<NME> SettingsActivity.java
<BEF> package cgeo.geocaching.settings;

import cgeo.geocaching.Intents;
import cgeo.geocaching.R;
import cgeo.geocaching.maps.mapsforge.v6.RenderThemeHelper;
import cgeo.geocaching.network.AndroidBeam;
import cgeo.geocaching.search.BaseSearchSuggestionCursor;
import cgeo.geocaching.search.BaseSuggestionsAdapter;
import cgeo.geocaching.search.SearchUtils;
import cgeo.geocaching.settings.fragments.BasePreferenceFragment;
import cgeo.geocaching.settings.fragments.PreferenceAppearanceFragment;
import cgeo.geocaching.settings.fragments.PreferenceBackupFragment;
import cgeo.geocaching.settings.fragments.PreferenceCachedetailsFragment;
import cgeo.geocaching.settings.fragments.PreferenceLoggingFragment;
import cgeo.geocaching.settings.fragments.PreferenceMapFragment;
import cgeo.geocaching.settings.fragments.PreferenceNavigationFragment;
import cgeo.geocaching.settings.fragments.PreferenceOfflinedataFragment;
import cgeo.geocaching.settings.fragments.PreferenceServiceGeocachingComFragment;
import cgeo.geocaching.settings.fragments.PreferenceServiceGeokretyOrgFragment;
import cgeo.geocaching.settings.fragments.PreferenceServiceSendToCgeoFragment;
import cgeo.geocaching.settings.fragments.PreferenceServicesFragment;
import cgeo.geocaching.settings.fragments.PreferenceSystemFragment;
import cgeo.geocaching.settings.fragments.PreferencesFragment;
import cgeo.geocaching.storage.ContentStorageActivityHelper;
import cgeo.geocaching.storage.PersistableFolder;
import cgeo.geocaching.utils.ApplicationSettings;
import cgeo.geocaching.utils.BackupUtils;
import cgeo.geocaching.utils.Log;
import static cgeo.geocaching.utils.SettingsUtils.initPublicFolders;

import android.app.SearchManager;
import android.app.backup.BackupManager;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.BackgroundColorSpan;
import android.text.style.ForegroundColorSpan;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SearchView;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceScreen;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

/**
 * An {@link AppCompatActivity} that presents a set of application settings. On
 * handset devices, settings are presented as a single list. On tablets,
 * settings are split by category, with category headers shown to the left of
 * the list of settings.
 * <p>
 * See <a href="http://developer.android.com/design/patterns/settings.html"> Android Design: Settings</a> for design
 * guidelines and the <a href="http://developer.android.com/guide/topics/ui/settings.html">Settings API Guide</a> for
 * more information on developing a Settings UI.
 */
public class SettingsActivity extends AppCompatActivity implements PreferenceFragmentCompat.OnPreferenceStartFragmentCallback {

    private static final String TITLE_TAG = "preferencesActivityTitle";
    private static final String INTENT_OPEN_SCREEN = "OPEN_SCREEN";
    public static final int NO_RESTART_NEEDED = 1;
    public static final int RESTART_NEEDED = 2;

    public static final String STATE_CSAH = "csah";
    public static final String STATE_BACKUPUTILS = "backuputils";

    private BackupUtils backupUtils = null;
    private ContentStorageActivityHelper contentStorageHelper = null;
    private CharSequence title;

    private static final ArrayList<BasePreferenceFragment.PrefSearchDescriptor> searchIndex = new ArrayList<>();

    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        ApplicationSettings.setLocale(this);
        setTheme(Settings.isLightSkin(this) ? R.style.settings_light : R.style.settings);
        super.onCreate(savedInstanceState);

        backupUtils = new BackupUtils(SettingsActivity.this, savedInstanceState == null ? null : savedInstanceState.getBundle(STATE_BACKUPUTILS));

        this.contentStorageHelper = new ContentStorageActivityHelper(this, savedInstanceState == null ? null : savedInstanceState.getBundle(STATE_CSAH))
                .addSelectActionCallback(ContentStorageActivityHelper.SelectAction.SELECT_FOLDER_PERSISTED, PersistableFolder.class, folder -> {

                    final List<Fragment> fragments = getSupportFragmentManager().getFragments();
                    for (Fragment f : fragments) {
                        if (f instanceof PreferenceFragmentCompat) {
                            initPublicFolders((PreferenceFragmentCompat) f, contentStorageHelper);
                        }
                    }

                    if (PersistableFolder.OFFLINE_MAP_THEMES.equals(folder)) {
                        RenderThemeHelper.resynchronizeOrDeleteMapThemeFolder();
                    }
        int gotoPage = intent.getIntExtra(INTENT_GOTO, 0);
        if (gotoPage == INTENT_GOTO_SERVICES) {
            // start with services screen
            PreferenceScreen main = (PreferenceScreen) SettingsActivity.findPreference(this, getKey(R.string.pref_fakekey_main_screen));
            int index = SettingsActivity.findPreference(this, getKey(R.string.pref_fakekey_services_screen)).getOrder();
            main.onItemClick(null, null, index, 0);
        }
    }
                setTitle(R.string.settings_titlebar);
            }
        });
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        AndroidBeam.disable(this);

        setResult(NO_RESTART_NEEDED);
    }

    public BackupUtils getBackupUtils() {
        return backupUtils;
    }

    private void handleIntent(final Bundle savedInstanceState) {
        if (savedInstanceState == null) {
            final Intent intent = getIntent();
            final String action = intent.getAction();
            boolean found = false;
            if (Intents.ACTION_SETTINGS.equals(action)) {
                // user selected a search suggestion
                R.string.pref_mapDirectory, R.string.pref_defaultNavigationTool,
                R.string.pref_defaultNavigationTool2, R.string.pref_webDeviceName,
                R.string.pref_fakekey_preference_backup_info, }) {
            bindSummaryToStringValue(this, getKey(k));
        }
    }

                        if (StringUtils.containsIgnoreCase(item.prefTitle, query) || StringUtils.containsIgnoreCase(item.prefSummary, query)) {
        return cgeoapplication.getInstance().getString(prefKeyId);
    }

    // workaround, because OnContextItemSelected nor onMenuItemSelected is never called
    OnMenuItemClickListener TEMPLATE_CLICK = new OnMenuItemClickListener() {
        @Override
        } else {
            title = savedInstanceState.getCharSequence(TITLE_TAG);
        }
    }

    /**
     * This method sets the fragment which is used upon opening the settings. This may be the user directly or a
     * requesting Intent.
     */
    private void openRequestedFragment(final String preference) {
        final Intent intent = getIntent();
        final int fragmentId = intent.getIntExtra(INTENT_OPEN_SCREEN, -1);
        String fragment = "";
        // try to get fragment key from preference name (if necessary)
        if (fragmentId < 0 && StringUtils.isNotBlank(preference)) {
            synchronized (searchIndex) {
                for (BasePreferenceFragment.PrefSearchDescriptor pref : searchIndex) {
                    if (StringUtils.equals(preference, pref.prefKey)) {
                        fragment = pref.baseKey;
                        break;
                    }
                }
            }
        } else {
            try {
                fragment = getString(fragmentId);
            } catch (Exception ignore) {
                fragment = "";
            }

        }
        openRequestedFragment(fragment, preference);
    }

    /**
     * This method sets the fragment given by its base key,
     * Fill the choice list for map sources.
     */
    private void initMapSourcePreference() {
        ListPreference pref = (ListPreference) SettingsActivity.findPreference(this, getKey(R.string.pref_mapsource));

        List<MapSource> mapSources = MapProviderFactory.getMapSources();
        CharSequence[] entries = new CharSequence[mapSources.size()];
            preferenceFragment = new PreferenceAppearanceFragment();
        } else if (StringUtils.equals(baseKey, getString(R.string.preference_screen_cachedetails))) {
            preferenceFragment = new PreferenceCachedetailsFragment();
        } else if (StringUtils.equals(baseKey, getString(R.string.preference_screen_map))) {
            preferenceFragment = new PreferenceMapFragment();
        } else if (StringUtils.equals(baseKey, getString(R.string.preference_screen_map))) {
            preferenceFragment = new PreferenceMapFragment();
        } else if (StringUtils.equals(baseKey, getString(R.string.preference_screen_logging))) {
            preferenceFragment = new PreferenceLoggingFragment();
        } else if (StringUtils.equals(baseKey, getString(R.string.preference_screen_offlinedata))) {
            preferenceFragment = new PreferenceOfflinedataFragment();
        } else if (StringUtils.equals(baseKey, getString(R.string.preference_screen_navigation))) {
            preferenceFragment = new PreferenceNavigationFragment();
        } else if (StringUtils.equals(baseKey, getString(R.string.preference_screen_system))) {
            preferenceFragment = new PreferenceSystemFragment();
        } else if (StringUtils.equals(baseKey, getString(R.string.preference_screen_backup))) {
            preferenceFragment = new PreferenceBackupFragment();

        } else if (StringUtils.equals(baseKey, getString(R.string.preference_screen_sendtocgeo))) {
            preferenceFragment = new PreferenceServiceSendToCgeoFragment();
            values[i] = String.valueOf(apps.get(i).id);
        }

        ListPreference pref = (ListPreference) SettingsActivity.findPreference(this, getKey(R.string.pref_defaultNavigationTool));
        pref.setEntries(entries);
        pref.setEntryValues(values);
        pref = (ListPreference) SettingsActivity.findPreference(this, getKey(R.string.pref_defaultNavigationTool2));
        pref.setEntries(entries);
        pref.setEntryValues(values);
    }
                .replace(R.id.settings_fragment_root, preferenceFragment)
    private void initDirChoosers() {
        for (final DirChooserType dct : DirChooserType.values()) {

            SettingsActivity.findPreference(this, getKey(dct.keyId)).setOnPreferenceClickListener(
                    new OnPreferenceClickListener() {
                        @Override
                        public boolean onPreferenceClick(final Preference preference) {
        savedInstanceState.putBundle(STATE_BACKUPUTILS, backupUtils.getState());

        // Save current activity title so we can set it again after a configuration change
                    });
        }

        SettingsActivity.findPreference(this, getKey(R.string.pref_mapDirectory)).setOnPreferenceClickListener(
                new OnPreferenceClickListener() {
                    @Override
                    public boolean onPreferenceClick(final Preference preference) {
        super.onPause();
    }

    public static void openForScreen(final int preferenceScreenKey, final Context fromActivity) {
        final Intent intent = new Intent(fromActivity, SettingsActivity.class);
        intent.putExtra(INTENT_OPEN_SCREEN, preferenceScreenKey);
        fromActivity.startActivity(intent);
    }

    @Override
    public boolean onSupportNavigateUp() {
        if (getSupportFragmentManager().popBackStackImmediate()) {
            return true;
        }
        return super.onSupportNavigateUp();
    }


    @Override
    public boolean onPreferenceStartFragment(final PreferenceFragmentCompat caller, final Preference pref) {
        // Instantiate the new Fragment
        final Bundle args = pref.getExtras();
        final Fragment fragment = getSupportFragmentManager()
                .getFragmentFactory()
                .instantiate(getClassLoader(), pref.getFragment());
        fragment.setArguments(args);
        fragment.setTargetFragment(caller, 0);
        // Replace the existing Fragment with the new Fragment
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.settings_fragment_root, fragment)
                .addToBackStack(null)
                .commit();
        title = pref.getTitle();
        return true;
    }

    public ContentStorageActivityHelper getCsah() {
        return contentStorageHelper;
    private void setChosenDirectory(final DirChooserType dct, final Intent data) {
        final String directory = new File(data.getData().getPath()).getAbsolutePath();
        if (StringUtils.isNotBlank(directory)) {
            Preference p = SettingsActivity.findPreference(this, getKey(dct.keyId));
            if (p == null) {
                return;
            }
            return;
        }
        if (backupUtils.onActivityResult(requestCode, resultCode, data)) {
    }

    public void initBackupButtons() {
        Preference backup = SettingsActivity.findPreference(this, getKey(R.string.pref_fakekey_preference_backup));
        backup.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(final Preference preference) {
        synchronized (searchIndex) {
            if (searchIndex.size() > 0) {
                return;
            }
        }
        final ArrayList<BasePreferenceFragment> fragments = new ArrayList<>();
        fragments.add(new PreferenceServicesFragment().setIcon(R.drawable.settings_cloud));
        fragments.add(new PreferenceAppearanceFragment().setIcon(R.drawable.settings_eye));
        fragments.add(new PreferenceCachedetailsFragment().setIcon(R.drawable.settings_details));
        fragments.add(new PreferenceMapFragment().setIcon(R.drawable.settings_map));
        fragments.add(new PreferenceLoggingFragment().setIcon(R.drawable.settings_pen));
        fragments.add(new PreferenceOfflinedataFragment().setIcon(R.drawable.settings_sdcard));
        fragments.add(new PreferenceNavigationFragment().setIcon(R.drawable.settings_arrow));
        fragments.add(new PreferenceSystemFragment().setIcon(R.drawable.settings_nut));
        fragments.add(new PreferenceBackupFragment().setIcon(R.drawable.settings_backup));

        for (BasePreferenceFragment f : fragments) {
            f.setSearchdataCallback(this::collectSearchdataCallback);
        }
        final FragmentTransaction t = getSupportFragmentManager().beginTransaction();
        for (Fragment f : fragments) {
            t.add(R.id.settings_fragment_root, f);
        }
        t.commit();
                                                ? context.getString(R.string.init_backup_success)
                                                        + "\n" + backupFileName
                                                : context.getString(R.string.init_backup_failed));
                                VALUE_CHANGE_LISTENER.onPreferenceChange(SettingsActivity.findPreference(SettingsActivity.this, getKey(R.string.pref_fakekey_preference_backup_info)), "");
                            }
                        });
                    }
    private void collectSearchdataCallback(final ArrayList<BasePreferenceFragment.PrefSearchDescriptor> data) {
        synchronized (searchIndex) {
            }
        });

        Preference restore = SettingsActivity.findPreference(this, getKey(R.string.pref_fakekey_preference_restore));
        restore.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(final Preference preference) {
            final PreferenceScreen prefScreen = ((PreferenceFragmentCompat) fragment).getPreferenceScreen();
            if (prefScreen != null && StringUtils.equalsIgnoreCase(prefScreen.getKey(), baseKey)) {
                final Preference pref = prefScreen.findPreference(prefKey);
                if (pref != null) {
                    ((PreferenceFragmentCompat) fragment).scrollToPreference(pref);
    }

    private void initDbLocationPreference() {
        Preference p = SettingsActivity.findPreference(this, getKey(R.string.pref_dbonsdcard));
        p.setPersistent(false);
        p.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            @Override
    public boolean onCreateOptionsMenu(final Menu menu) {
        getMenuInflater().inflate(R.menu.settings_activity_options, menu);

        // prepare search in action bar
        final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        final MenuItem menuSearch = menu.findItem(R.id.menu_gosearch);
        final SearchView searchView = (SearchView) menuSearch.getActionView();
    }

    private void initDebugPreference() {
        Preference p = SettingsActivity.findPreference(this, getKey(R.string.pref_debug));
        p.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(final Preference preference, final Object newValue) {
        return true;
    }

    static class SettingsSuggestionsAdapter extends BaseSuggestionsAdapter {
    }

    void initBasicMemberPreferences() {
        SettingsActivity.findPreference(this, getKey(R.string.pref_fakekey_basicmembers_screen))
                .setEnabled(!Settings.isPremiumMember());
        SettingsActivity.findPreference(this, getKey(R.string.pref_loaddirectionimg))
                .setEnabled(!Settings.isPremiumMember());
        SettingsActivity.findPreference(this, getKey(R.string.pref_showcaptcha))
                .setEnabled(!Settings.isPremiumMember());

        redrawScreen(R.string.pref_fakekey_services_screen);
    }

    void redrawScreen(int key) {
        PreferenceScreen screen = (PreferenceScreen) SettingsActivity
                .findPreference(this, getKey(key));
        if (screen == null) {
            return;
        }
            if (searchTerm.length() > 2) {
                synchronized (searchdata) {
                    for (BasePreferenceFragment.PrefSearchDescriptor item : searchdata) {
                        if (StringUtils.containsIgnoreCase(item.prefTitle, searchTerm) || StringUtils.containsIgnoreCase(item.prefSummary, searchTerm)) {
                            resultCursor.addItem(item.prefTitle, item.prefSummary, item.prefKey, item.prefCategoryIconRes);
                        }
                    }
                }
    }

    void setOCDEAuthTitle() {
        SettingsActivity.findPreference(this, getKey(R.string.pref_fakekey_ocde_authorization))
                .setTitle(getString(Settings.hasOCDEAuthorization()
                        ? R.string.init_reregister_oc_de
                        : R.string.init_register_oc_de));
    }

    void setTwitterAuthTitle() {
        SettingsActivity.findPreference(this, getKey(R.string.pref_fakekey_twitter_authorization))
                .setTitle(getString(Settings.hasTwitterAuthorization()
                        ? R.string.init_twitter_reauthorize
                        : R.string.init_twitter_authorize));
            });
            rowId++;
        }
    }

    private static Spannable prepareDisplayString(final Context context, final String text, final String searchTerm) {
        if (StringUtils.isBlank(text)) {
            return null;
        }
        final int iPos = StringUtils.indexOfIgnoreCase(text, searchTerm);
        final Spannable s = new SpannableString(text);
        if (iPos >= 0) {
            s.setSpan(new BackgroundColorSpan(context.getResources().getColor(R.color.colorAccent)), iPos, iPos + searchTerm.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            s.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.colorText)), iPos, iPos + searchTerm.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        return s;
    }

}
                    }
                }
                initMapSourcePreference();
                SettingsActivity.findPreference(this, getKey(R.string.pref_mapDirectory)).setSummary(
                        Settings.getMapFileDirectory());
                break;
            case OAUTH_OCDE_REQUEST:
     *
     * @param key
     */
    private static void bindSummaryToStringValue(final PreferenceActivity preferenceActivity, final String key) {

        Preference pref = findPreference(preferenceActivity, key);

        if (pref == null) {
            return;
        }

<MSG> Merge pull request #3032 from koem/refactorGetPreference

Refactoring - Settings findPreference
<DFF> @@ -110,8 +110,8 @@ public class SettingsActivity extends PreferenceActivity {
         int gotoPage = intent.getIntExtra(INTENT_GOTO, 0);
         if (gotoPage == INTENT_GOTO_SERVICES) {
             // start with services screen
-            PreferenceScreen main = (PreferenceScreen) SettingsActivity.findPreference(this, getKey(R.string.pref_fakekey_main_screen));
-            int index = SettingsActivity.findPreference(this, getKey(R.string.pref_fakekey_services_screen)).getOrder();
+            PreferenceScreen main = (PreferenceScreen) getPreference(R.string.pref_fakekey_main_screen);
+            int index = getPreference(R.string.pref_fakekey_services_screen).getOrder();
             main.onItemClick(null, null, index, 0);
         }
     }
@@ -139,7 +139,7 @@ public class SettingsActivity extends PreferenceActivity {
                 R.string.pref_mapDirectory, R.string.pref_defaultNavigationTool,
                 R.string.pref_defaultNavigationTool2, R.string.pref_webDeviceName,
                 R.string.pref_fakekey_preference_backup_info, }) {
-            bindSummaryToStringValue(this, getKey(k));
+            bindSummaryToStringValue(k);
         }
     }
 
@@ -147,6 +147,10 @@ public class SettingsActivity extends PreferenceActivity {
         return cgeoapplication.getInstance().getString(prefKeyId);
     }
 
+    private Preference getPreference(final int keyId) {
+        return SettingsActivity.findPreference(this, getKey(keyId));
+    }
+
     // workaround, because OnContextItemSelected nor onMenuItemSelected is never called
     OnMenuItemClickListener TEMPLATE_CLICK = new OnMenuItemClickListener() {
         @Override
@@ -189,7 +193,7 @@ public class SettingsActivity extends PreferenceActivity {
      * Fill the choice list for map sources.
      */
     private void initMapSourcePreference() {
-        ListPreference pref = (ListPreference) SettingsActivity.findPreference(this, getKey(R.string.pref_mapsource));
+        ListPreference pref = (ListPreference) getPreference(R.string.pref_mapsource);
 
         List<MapSource> mapSources = MapProviderFactory.getMapSources();
         CharSequence[] entries = new CharSequence[mapSources.size()];
@@ -216,10 +220,10 @@ public class SettingsActivity extends PreferenceActivity {
             values[i] = String.valueOf(apps.get(i).id);
         }
 
-        ListPreference pref = (ListPreference) SettingsActivity.findPreference(this, getKey(R.string.pref_defaultNavigationTool));
+        ListPreference pref = (ListPreference) getPreference(R.string.pref_defaultNavigationTool);
         pref.setEntries(entries);
         pref.setEntryValues(values);
-        pref = (ListPreference) SettingsActivity.findPreference(this, getKey(R.string.pref_defaultNavigationTool2));
+        pref = (ListPreference) getPreference(R.string.pref_defaultNavigationTool2);
         pref.setEntries(entries);
         pref.setEntryValues(values);
     }
@@ -227,7 +231,7 @@ public class SettingsActivity extends PreferenceActivity {
     private void initDirChoosers() {
         for (final DirChooserType dct : DirChooserType.values()) {
 
-            SettingsActivity.findPreference(this, getKey(dct.keyId)).setOnPreferenceClickListener(
+            getPreference(dct.keyId).setOnPreferenceClickListener(
                     new OnPreferenceClickListener() {
                         @Override
                         public boolean onPreferenceClick(final Preference preference) {
@@ -237,7 +241,7 @@ public class SettingsActivity extends PreferenceActivity {
                     });
         }
 
-        SettingsActivity.findPreference(this, getKey(R.string.pref_mapDirectory)).setOnPreferenceClickListener(
+        getPreference(R.string.pref_mapDirectory).setOnPreferenceClickListener(
                 new OnPreferenceClickListener() {
                     @Override
                     public boolean onPreferenceClick(final Preference preference) {
@@ -282,7 +286,7 @@ public class SettingsActivity extends PreferenceActivity {
     private void setChosenDirectory(final DirChooserType dct, final Intent data) {
         final String directory = new File(data.getData().getPath()).getAbsolutePath();
         if (StringUtils.isNotBlank(directory)) {
-            Preference p = SettingsActivity.findPreference(this, getKey(dct.keyId));
+            Preference p = getPreference(dct.keyId);
             if (p == null) {
                 return;
             }
@@ -292,7 +296,7 @@ public class SettingsActivity extends PreferenceActivity {
     }
 
     public void initBackupButtons() {
-        Preference backup = SettingsActivity.findPreference(this, getKey(R.string.pref_fakekey_preference_backup));
+        Preference backup = getPreference(R.string.pref_fakekey_preference_backup);
         backup.setOnPreferenceClickListener(new OnPreferenceClickListener() {
             @Override
             public boolean onPreferenceClick(final Preference preference) {
@@ -323,7 +327,7 @@ public class SettingsActivity extends PreferenceActivity {
                                                 ? context.getString(R.string.init_backup_success)
                                                         + "\n" + backupFileName
                                                 : context.getString(R.string.init_backup_failed));
-                                VALUE_CHANGE_LISTENER.onPreferenceChange(SettingsActivity.findPreference(SettingsActivity.this, getKey(R.string.pref_fakekey_preference_backup_info)), "");
+                                VALUE_CHANGE_LISTENER.onPreferenceChange(SettingsActivity.this.getPreference(R.string.pref_fakekey_preference_backup_info), "");
                             }
                         });
                     }
@@ -332,7 +336,7 @@ public class SettingsActivity extends PreferenceActivity {
             }
         });
 
-        Preference restore = SettingsActivity.findPreference(this, getKey(R.string.pref_fakekey_preference_restore));
+        Preference restore = getPreference(R.string.pref_fakekey_preference_restore);
         restore.setOnPreferenceClickListener(new OnPreferenceClickListener() {
             @Override
             public boolean onPreferenceClick(final Preference preference) {
@@ -344,7 +348,7 @@ public class SettingsActivity extends PreferenceActivity {
     }
 
     private void initDbLocationPreference() {
-        Preference p = SettingsActivity.findPreference(this, getKey(R.string.pref_dbonsdcard));
+        Preference p = getPreference(R.string.pref_dbonsdcard);
         p.setPersistent(false);
         p.setOnPreferenceClickListener(new OnPreferenceClickListener() {
             @Override
@@ -358,7 +362,7 @@ public class SettingsActivity extends PreferenceActivity {
     }
 
     private void initDebugPreference() {
-        Preference p = SettingsActivity.findPreference(this, getKey(R.string.pref_debug));
+        Preference p = getPreference(R.string.pref_debug);
         p.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
             @Override
             public boolean onPreferenceChange(final Preference preference, final Object newValue) {
@@ -369,19 +373,18 @@ public class SettingsActivity extends PreferenceActivity {
     }
 
     void initBasicMemberPreferences() {
-        SettingsActivity.findPreference(this, getKey(R.string.pref_fakekey_basicmembers_screen))
+        getPreference(R.string.pref_fakekey_basicmembers_screen)
                 .setEnabled(!Settings.isPremiumMember());
-        SettingsActivity.findPreference(this, getKey(R.string.pref_loaddirectionimg))
+        getPreference(R.string.pref_loaddirectionimg)
                 .setEnabled(!Settings.isPremiumMember());
-        SettingsActivity.findPreference(this, getKey(R.string.pref_showcaptcha))
+        getPreference(R.string.pref_showcaptcha)
                 .setEnabled(!Settings.isPremiumMember());
 
         redrawScreen(R.string.pref_fakekey_services_screen);
     }
 
     void redrawScreen(int key) {
-        PreferenceScreen screen = (PreferenceScreen) SettingsActivity
-                .findPreference(this, getKey(key));
+        PreferenceScreen screen = (PreferenceScreen) getPreference(key);
         if (screen == null) {
             return;
         }
@@ -396,14 +399,14 @@ public class SettingsActivity extends PreferenceActivity {
     }
 
     void setOCDEAuthTitle() {
-        SettingsActivity.findPreference(this, getKey(R.string.pref_fakekey_ocde_authorization))
+        getPreference(R.string.pref_fakekey_ocde_authorization)
                 .setTitle(getString(Settings.hasOCDEAuthorization()
                         ? R.string.init_reregister_oc_de
                         : R.string.init_register_oc_de));
     }
 
     void setTwitterAuthTitle() {
-        SettingsActivity.findPreference(this, getKey(R.string.pref_fakekey_twitter_authorization))
+        getPreference(R.string.pref_fakekey_twitter_authorization)
                 .setTitle(getString(Settings.hasTwitterAuthorization()
                         ? R.string.init_twitter_reauthorize
                         : R.string.init_twitter_authorize));
@@ -439,7 +442,7 @@ public class SettingsActivity extends PreferenceActivity {
                     }
                 }
                 initMapSourcePreference();
-                SettingsActivity.findPreference(this, getKey(R.string.pref_mapDirectory)).setSummary(
+                getPreference(R.string.pref_mapDirectory).setSummary(
                         Settings.getMapFileDirectory());
                 break;
             case OAUTH_OCDE_REQUEST:
@@ -527,10 +530,9 @@ public class SettingsActivity extends PreferenceActivity {
      *
      * @param key
      */
-    private static void bindSummaryToStringValue(final PreferenceActivity preferenceActivity, final String key) {
-
-        Preference pref = findPreference(preferenceActivity, key);
+    private void bindSummaryToStringValue(final int key) {
 
+        Preference pref = getPreference(key);
         if (pref == null) {
             return;
         }

Merge pull request #3032 from koem/refactorGetPreference