Example usage for android.preference ListPreference setSummary

List of usage examples for android.preference ListPreference setSummary

Introduction

In this page you can find the example usage for android.preference ListPreference setSummary.

Prototype

@Override
public void setSummary(CharSequence summary) 

Source Link

Document

Sets the summary for this Preference with a CharSequence.

Usage

From source file:com.jmstudios.redmoon.fragment.ShadesFragment.java

private boolean onAutomaticFilterPreferenceChange(Preference preference, Object newValue) {
    if (newValue.toString().equals("sun") && ContextCompat.checkSelfPermission(getActivity(),
            Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(getActivity(),
                new String[] { Manifest.permission.ACCESS_COARSE_LOCATION }, 0);
        return false;
    }/*from  w  ww.  j a va2  s  .c  om*/

    boolean custom = newValue.toString().equals("custom");
    automaticTurnOnPref.setEnabled(custom);
    automaticTurnOffPref.setEnabled(custom);

    boolean sun = newValue.toString().equals("sun");
    locationPref.setEnabled(sun);

    // From something to sun
    if (newValue.toString().equals("sun")) {
        // Update the FilterTimePreferences
        updateFilterTimesFromSun();

        // Attempt to get a new location
        locationPref.searchLocation(false);
    }

    // From sun to something
    String oldValue = preference.getSharedPreferences().getString(preference.getKey(), "never");
    if (oldValue.equals("sun") && !newValue.equals("sun")) {
        automaticTurnOnPref.setToCustomTime();
        automaticTurnOffPref.setToCustomTime();
    }

    ListPreference lp = (ListPreference) preference;
    String entry = lp.getEntries()[lp.findIndexOfValue(newValue.toString())].toString();
    lp.setSummary(entry);

    return true;
}

From source file:com.vonglasow.michael.satstat.SettingsActivity.java

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    if (key.equals(SettingsActivity.KEY_PREF_NOTIFY_FIX)
            || key.equals(SettingsActivity.KEY_PREF_NOTIFY_SEARCH)) {
        boolean notifyFix = sharedPreferences.getBoolean(SettingsActivity.KEY_PREF_NOTIFY_FIX, false);
        boolean notifySearch = sharedPreferences.getBoolean(SettingsActivity.KEY_PREF_NOTIFY_SEARCH, false);
        if (!(notifyFix || notifySearch)) {
            Intent stopServiceIntent = new Intent(this, PasvLocListenerService.class);
            this.stopService(stopServiceIntent);
        }/*from w  ww .  ja  va2  s  .c  om*/
    } else if (key.equals(SettingsActivity.KEY_PREF_UPDATE_FREQ)) {
        // this piece of code is necessary because Android has no way
        // of updating the preference summary automatically. I am
        // told the absence of such functionality is a feature...
        SettingsFragment sf = (SettingsFragment) getFragmentManager().findFragmentById(android.R.id.content);
        ListPreference prefUpdateFreq = (ListPreference) sf.findPreference(KEY_PREF_UPDATE_FREQ);
        final String value = sharedPreferences.getString(key, key);
        final int index = prefUpdateFreq.findIndexOfValue(value);
        if (index >= 0) {
            final String summary = (String) prefUpdateFreq.getEntries()[index];
            prefUpdateFreq.setSummary(summary);
        }
    }
}

From source file:com.mantz_it.rfanalyzer.SettingsFragment.java

/**
 * Will go through each preference element and initialize/update the summary according to its value.
 * @note this will also correct invalid user inputs on EdittextPreferences!
 *///from   w ww  . j a v  a 2s  .  c  o  m
public void updateSummaries() {
    // Source Type
    ListPreference listPref = (ListPreference) findPreference(getString(R.string.pref_sourceType));
    listPref.setSummary(getString(R.string.pref_sourceType_summ, listPref.getEntry()));

    // Direct Sampling
    listPref = (ListPreference) findPreference(getString(R.string.pref_rtlsdr_directSamp));
    listPref.setSummary(getString(R.string.pref_rtlsdr_directSamp_summ, listPref.getEntry()));

    // Frequency display
    listPref = (ListPreference) findPreference(getString(R.string.pref_surface_unit));
    listPref.setSummary(getString(R.string.pref_surface_unit_summ, listPref.getEntry()));

    // FileSource Frequency
    EditTextPreference editTextPref = (EditTextPreference) findPreference(
            getString(R.string.pref_filesource_frequency));
    if (editTextPref.getText().length() == 0)
        editTextPref.setText(getString(R.string.pref_filesource_frequency_default));
    editTextPref.setSummary(getString(R.string.pref_filesource_frequency_summ, editTextPref.getText()));

    // FileSource Sample Rate
    editTextPref = (EditTextPreference) findPreference(getString(R.string.pref_filesource_sampleRate));
    if (editTextPref.getText().length() == 0)
        editTextPref.setText(getString(R.string.pref_filesource_sampleRate_default));
    editTextPref.setSummary(getString(R.string.pref_filesource_sampleRate_summ, editTextPref.getText()));

    // FileSource File
    editTextPref = (EditTextPreference) findPreference(getString(R.string.pref_filesource_file));
    editTextPref.setSummary(getString(R.string.pref_filesource_file_summ, editTextPref.getText()));

    // FileSource Format
    listPref = (ListPreference) findPreference(getString(R.string.pref_filesource_format));
    listPref.setSummary(getString(R.string.pref_filesource_format_summ, listPref.getEntry()));

    // HackRF frequency shift
    editTextPref = (EditTextPreference) findPreference(getString(R.string.pref_hackrf_frequencyOffset));
    if (editTextPref.getText().length() == 0)
        editTextPref.setText("0");
    editTextPref.setSummary(getString(R.string.pref_hackrf_frequencyOffset_summ, editTextPref.getText()));

    // RTL-SDR IP
    editTextPref = (EditTextPreference) findPreference(getString(R.string.pref_rtlsdr_ip));
    editTextPref.setSummary(getString(R.string.pref_rtlsdr_ip_summ, editTextPref.getText()));

    // RTL-SDR Port
    editTextPref = (EditTextPreference) findPreference(getString(R.string.pref_rtlsdr_port));
    editTextPref.setSummary(getString(R.string.pref_rtlsdr_port_summ, editTextPref.getText()));

    // RTL-SDR frequency correction
    editTextPref = (EditTextPreference) findPreference(getString(R.string.pref_rtlsdr_frequencyCorrection));
    if (editTextPref.getText().length() == 0)
        editTextPref.setText(getString(R.string.pref_rtlsdr_frequencyCorrection_default));
    editTextPref.setSummary(getString(R.string.pref_rtlsdr_frequencyCorrection_summ, editTextPref.getText()));

    // RTL-SDR frequency shift
    editTextPref = (EditTextPreference) findPreference(getString(R.string.pref_rtlsdr_frequencyOffset));
    if (editTextPref.getText().length() == 0)
        editTextPref.setText("0");
    editTextPref.setSummary(getString(R.string.pref_rtlsdr_frequencyOffset_summ, editTextPref.getText()));

    // FFT size
    listPref = (ListPreference) findPreference(getString(R.string.pref_fftSize));
    listPref.setSummary(getString(R.string.pref_fftSize_summ, listPref.getEntry()));

    // Color map type
    listPref = (ListPreference) findPreference(getString(R.string.pref_colorMapType));
    listPref.setSummary(getString(R.string.pref_colorMapType_summ, listPref.getEntry()));

    // FFT drawing type
    listPref = (ListPreference) findPreference(getString(R.string.pref_fftDrawingType));
    listPref.setSummary(getString(R.string.pref_fftDrawingType_summ, listPref.getEntry()));

    // Averaging
    listPref = (ListPreference) findPreference(getString(R.string.pref_averaging));
    listPref.setSummary(getString(R.string.pref_averaging_summ, listPref.getEntry()));

    // Screen Orientation
    listPref = (ListPreference) findPreference(getString(R.string.pref_screenOrientation));
    listPref.setSummary(getString(R.string.pref_screenOrientation_summ, listPref.getEntry()));

    // Spectrum Waterfall Ratio
    listPref = (ListPreference) findPreference(getString(R.string.pref_spectrumWaterfallRatio));
    listPref.setSummary(getString(R.string.pref_spectrumWaterfallRatio_summ, listPref.getEntry()));

    // Font Size
    listPref = (ListPreference) findPreference(getString(R.string.pref_fontSize));
    listPref.setSummary(getString(R.string.pref_fontSize_summ, listPref.getEntry()));

    // Frame Rate
    SwitchPreference switchPref = (SwitchPreference) findPreference(getString(R.string.pref_dynamicFrameRate));
    listPref = (ListPreference) findPreference(getString(R.string.pref_frameRate));
    if (switchPref.isChecked())
        listPref.setSummary(getString(R.string.pref_frameRate_summ, "auto"));
    else
        listPref.setSummary(getString(R.string.pref_frameRate_summ, listPref.getEntry()));

    // Logfile
    editTextPref = (EditTextPreference) findPreference(getString(R.string.pref_logfile));
    editTextPref.setSummary(getString(R.string.pref_logfile_summ, editTextPref.getText()));

    // Shared preferences updated in e.g. the onRequestPermissionResult() method are
    // not automatically updated in the preference fragment gui. do it manually:
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
    switchPref = (SwitchPreference) findPreference(getString(R.string.pref_logging));
    switchPref.setChecked(preferences.getBoolean(getString(R.string.pref_logging), false));
}

From source file:fr.s13d.photobackup.preferences.PBPreferenceFragment.java

private void setSummaries() {
    final String wifiOnly = preferences.getString(PBConstants.PREF_WIFI_ONLY,
            getResources().getString(R.string.only_wifi_default)); // default
    final ListPreference wifiPreference = (ListPreference) findPreference(PBConstants.PREF_WIFI_ONLY);
    wifiPreference.setSummary(wifiOnly);

    final String recentUploadOnly = preferences.getString(PBConstants.PREF_RECENT_UPLOAD_ONLY,
            getResources().getString(R.string.only_recent_upload_default)); // default
    final ListPreference recentUploadPreference = (ListPreference) findPreference(
            PBConstants.PREF_RECENT_UPLOAD_ONLY);
    recentUploadPreference.setSummary(recentUploadOnly);

    final String serverUrl = preferences.getString(PBServerPreferenceFragment.PREF_SERVER_URL, null);
    if (serverUrl != null) {
        final String serverName = preferences.getString(PBConstants.PREF_SERVER, null);
        if (serverName != null) {
            final PBServerListPreference serverPreference = (PBServerListPreference) findPreference(
                    PBConstants.PREF_SERVER);
            serverPreference.setSummary(serverName + " @ " + serverUrl);

            // bonus: left icon of the server
            final int serverNamesId = getResources().getIdentifier("pref_server_names", "array",
                    getActivity().getPackageName());
            final String[] serverNames = getResources().getStringArray(serverNamesId);
            final int serverPosition = Arrays.asList(serverNames).indexOf(serverName);
            final int serverIconsId = getResources().getIdentifier("pref_server_icons", "array",
                    getActivity().getPackageName());
            final String[] serverIcons = getResources().getStringArray(serverIconsId);
            final String serverIcon = serverIcons[serverPosition];
            final String[] parts = serverIcon.split("\\.");
            final String drawableName = parts[parts.length - 1];
            final int id = getResources().getIdentifier(drawableName, "drawable",
                    getActivity().getPackageName());
            if (id != 0) {
                serverPreference.setIcon(id);
            }//ww w . j  a v a 2 s. c om
        }
    }

    String bucketSummary = "";
    final Set<String> selectedBuckets = preferences.getStringSet(PBConstants.PREF_PICTURE_FOLDER_LIST, null);
    if (selectedBuckets != null && bucketNames != null) {
        final ArrayList<String> selectedBucketNames = new ArrayList<>();
        for (String entry : selectedBuckets) {
            String oneName = bucketNames.get(entry);
            if (oneName != null) {
                oneName = oneName.substring(0, oneName.lastIndexOf('(') - 1);
                selectedBucketNames.add(oneName);
            }
        }
        bucketSummary = TextUtils.join(", ", selectedBucketNames);
    }
    final MultiSelectListPreference bucketListPreference = (MultiSelectListPreference) findPreference(
            PBConstants.PREF_PICTURE_FOLDER_LIST);
    bucketListPreference.setSummary(bucketSummary);
}

From source file:net.willwebberley.gowertides.ui.PrferencesActivity.java

public void onSharedPreferenceChanged(SharedPreferences arg0, String arg1) {
    CheckBoxPreference timeBox = (CheckBoxPreference) getPreferenceScreen().findPreference("show_graph_time");
    CheckBoxPreference sunriseSunsetBox = (CheckBoxPreference) getPreferenceScreen()
            .findPreference("show_graph_sunrise_sunset");
    ListPreference metric = (ListPreference) getPreferenceScreen().findPreference("unitFormat");
    CheckBoxPreference timerBox = (CheckBoxPreference) getPreferenceScreen()
            .findPreference("show_sunset_timer");

    if (!arg0.getBoolean("show_graph", true)) {
        timeBox.setEnabled(false);//from www.ja  v a  2  s  .  com
        sunriseSunsetBox.setEnabled(false);
    } else {
        timeBox.setEnabled(true);
        sunriseSunsetBox.setEnabled(true);
    }

    if (arg0.getString("unitFormat", "true").equals("true")) {
        metric.setSummary("Display weather units in metric (km/h, Celcius).");
    } else {
        metric.setSummary("Display weather units in imperial (mph, Faranheit).");
    }

    if (!arg0.getBoolean("show_sunrise_sunset", true)) {
        timerBox.setEnabled(false);
    } else {
        timerBox.setEnabled(true);
    }

}

From source file:org.dmfs.webcal.fragments.PreferencesFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.webcal_preference);
    ListPreference locales = (ListPreference) findPreference("content_location");

    locales.setOnPreferenceChangeListener(PrefUpdater);

    try {/* w  ww.  j  av  a2 s  . c om*/
        getCountries();

        locales.setEntries(mCountryNames);
        locales.setEntryValues(mCountryCodes);
    } catch (Exception e) {
        Log.e(TAG, "could not load country list", e);
    }

    int index = locales.findIndexOfValue(locales.getValue());
    if (index >= 0) {
        locales.setSummary(locales.getEntries()[index]);
    } else {
        locales.setSummary(locales.getEntries()[0]);
        locales.setValueIndex(0);
    }
}

From source file:be.ppareit.swiftp.gui.PreferenceFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);

    final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
    Resources resources = getResources();

    TwoStatePreference runningPref = findPref("running_switch");
    updateRunningState();/*from w  w w.  ja v  a 2  s.  co  m*/
    runningPref.setOnPreferenceChangeListener((preference, newValue) -> {
        if ((Boolean) newValue) {
            startServer();
        } else {
            stopServer();
        }
        return true;
    });

    PreferenceScreen prefScreen = findPref("preference_screen");
    Preference marketVersionPref = findPref("market_version");
    marketVersionPref.setOnPreferenceClickListener(preference -> {
        // start the market at our application
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setData(Uri.parse("market://details?id=be.ppareit.swiftp"));
        try {
            // this can fail if there is no market installed
            startActivity(intent);
        } catch (Exception e) {
            Cat.e("Failed to launch the market.");
            e.printStackTrace();
        }
        return false;
    });
    if (!App.isFreeVersion()) {
        prefScreen.removePreference(marketVersionPref);
    }

    updateLoginInfo();

    EditTextPreference usernamePref = findPref("username");
    usernamePref.setOnPreferenceChangeListener((preference, newValue) -> {
        String newUsername = (String) newValue;
        if (preference.getSummary().equals(newUsername))
            return false;
        if (!newUsername.matches("[a-zA-Z0-9]+")) {
            Toast.makeText(getActivity(), R.string.username_validation_error, Toast.LENGTH_LONG).show();
            return false;
        }
        stopServer();
        return true;
    });

    mPassWordPref = findPref("password");
    mPassWordPref.setOnPreferenceChangeListener((preference, newValue) -> {
        stopServer();
        return true;
    });
    mAutoconnectListPref = findPref("autoconnect_preference");
    mAutoconnectListPref.setOnPopulateListener(pref -> {
        Cat.d("autoconnect populate listener");

        WifiManager wifiManager = (WifiManager) getActivity().getApplicationContext()
                .getSystemService(Context.WIFI_SERVICE);
        List<WifiConfiguration> configs = wifiManager.getConfiguredNetworks();
        if (configs == null) {
            Cat.e("Unable to receive wifi configurations, bark at user and bail");
            Toast.makeText(getActivity(), R.string.autoconnect_error_enable_wifi_for_access_points,
                    Toast.LENGTH_LONG).show();
            return;
        }
        CharSequence[] ssids = new CharSequence[configs.size()];
        CharSequence[] niceSsids = new CharSequence[configs.size()];
        for (int i = 0; i < configs.size(); ++i) {
            ssids[i] = configs.get(i).SSID;
            String ssid = configs.get(i).SSID;
            if (ssid.length() > 2 && ssid.startsWith("\"") && ssid.endsWith("\"")) {
                ssid = ssid.substring(1, ssid.length() - 1);
            }
            niceSsids[i] = ssid;
        }
        pref.setEntries(niceSsids);
        pref.setEntryValues(ssids);
    });
    mAutoconnectListPref.setOnPreferenceClickListener(preference -> {
        Cat.d("Clicked");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (ActivityCompat.checkSelfPermission(getContext(),
                    Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_DENIED) {
                if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(),
                        Manifest.permission.ACCESS_COARSE_LOCATION)) {
                    new AlertDialog.Builder(getContext()).setTitle(R.string.request_coarse_location_dlg_title)
                            .setMessage(R.string.request_coarse_location_dlg_message)
                            .setPositiveButton(android.R.string.ok, (dialog, which) -> {
                                requestPermissions(new String[] { Manifest.permission.ACCESS_COARSE_LOCATION },
                                        ACCESS_COARSE_LOCATION_REQUEST_CODE);
                            }).setOnCancelListener(dialog -> {
                                mAutoconnectListPref.getDialog().cancel();
                            }).create().show();
                } else {
                    requestPermissions(new String[] { Manifest.permission.ACCESS_COARSE_LOCATION },
                            ACCESS_COARSE_LOCATION_REQUEST_CODE);
                }
            }
        }
        return false;
    });

    EditTextPreference portnum_pref = findPref("portNum");
    portnum_pref.setSummary(sp.getString("portNum", resources.getString(R.string.portnumber_default)));
    portnum_pref.setOnPreferenceChangeListener((preference, newValue) -> {
        String newPortnumString = (String) newValue;
        if (preference.getSummary().equals(newPortnumString))
            return false;
        int portnum = 0;
        try {
            portnum = Integer.parseInt(newPortnumString);
        } catch (Exception e) {
            Cat.d("Error parsing port number! Moving on...");
        }
        if (portnum <= 0 || 65535 < portnum) {
            Toast.makeText(getActivity(), R.string.port_validation_error, Toast.LENGTH_LONG).show();
            return false;
        }
        preference.setSummary(newPortnumString);
        stopServer();
        return true;
    });

    Preference chroot_pref = findPref("chrootDir");
    chroot_pref.setSummary(FsSettings.getChrootDirAsString());
    chroot_pref.setOnPreferenceClickListener(preference -> {
        AlertDialog folderPicker = new FolderPickerDialogBuilder(getActivity(), FsSettings.getChrootDir())
                .setSelectedButton(R.string.select, path -> {
                    if (preference.getSummary().equals(path))
                        return;
                    if (!FsSettings.setChrootDir(path))
                        return;
                    // TODO: this is a hotfix, create correct resources, improve UI/UX
                    final File root = new File(path);
                    if (!root.canRead()) {
                        Toast.makeText(getActivity(), "Notice that we can't read/write in this folder.",
                                Toast.LENGTH_LONG).show();
                    } else if (!root.canWrite()) {
                        Toast.makeText(getActivity(),
                                "Notice that we can't write in this folder, reading will work. Writing in sub folders might work.",
                                Toast.LENGTH_LONG).show();
                    }

                    preference.setSummary(path);
                    stopServer();
                }).setNegativeButton(R.string.cancel, null).create();
        folderPicker.show();
        return true;
    });

    final CheckBoxPreference wakelock_pref = findPref("stayAwake");
    wakelock_pref.setOnPreferenceChangeListener((preference, newValue) -> {
        stopServer();
        return true;
    });

    final CheckBoxPreference writeExternalStorage_pref = findPref("writeExternalStorage");
    String externalStorageUri = FsSettings.getExternalStorageUri();
    if (externalStorageUri == null) {
        writeExternalStorage_pref.setChecked(false);
    }
    writeExternalStorage_pref.setOnPreferenceChangeListener((preference, newValue) -> {
        if ((boolean) newValue) {
            Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
            startActivityForResult(intent, ACTION_OPEN_DOCUMENT_TREE);
            return false;
        } else {
            FsSettings.setExternalStorageUri(null);
            return true;
        }
    });

    ListPreference theme = findPref("theme");
    theme.setSummary(theme.getEntry());
    theme.setOnPreferenceChangeListener((preference, newValue) -> {
        theme.setSummary(theme.getEntry());
        getActivity().recreate();
        return true;
    });

    Preference help = findPref("help");
    help.setOnPreferenceClickListener(preference -> {
        Cat.v("On preference help clicked");
        Context context = getActivity();
        AlertDialog ad = new AlertDialog.Builder(context).setTitle(R.string.help_dlg_title)
                .setMessage(R.string.help_dlg_message).setPositiveButton(android.R.string.ok, null).create();
        ad.show();
        Linkify.addLinks((TextView) ad.findViewById(android.R.id.message), Linkify.ALL);
        return true;
    });

    Preference about = findPref("about");
    about.setOnPreferenceClickListener(preference -> {
        startActivity(new Intent(getActivity(), AboutActivity.class));
        return true;
    });

}

From source file:ml.puredark.hviewer.ui.fragments.SettingFragment.java

@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    if (preference.getKey().equals(KEY_PREF_PROXY_SERVER)) {
        preference.setSummary((String) newValue);
    } else if (preference.getKey().equals(KEY_PREF_VIEW_DIRECTION)) {
        ListPreference directionPreference = (ListPreference) preference;
        CharSequence[] entries = directionPreference.getEntries();
        int i = directionPreference.findIndexOfValue((String) newValue);
        i = (i <= 0) ? 0 : i;/*  www . j  a v a2  s.  c o  m*/
        directionPreference.setSummary(entries[i]);
    } else if (preference.getKey().equals(KEY_PREF_VIEW_VIDEO_PLAYER)) {
        ListPreference videoPlayerPreference = (ListPreference) preference;
        CharSequence[] entries = videoPlayerPreference.getEntries();
        int i = videoPlayerPreference.findIndexOfValue((String) newValue);
        i = (i <= 0) ? 0 : i;
        videoPlayerPreference.setSummary(entries[i]);
        if (VIDEO_IJKPLAYER.equals(newValue) && !DynamicIjkLibLoader.isLibrariesDownloaded()) {
            // ?so
            new DynamicLibDownloader(activity).checkDownloadLib();
        }
    }
    return true;
}

From source file:com.vonglasow.michael.satstat.ui.SettingsActivity.java

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    boolean needsLocationPerm = false;
    if (key.equals(Const.KEY_PREF_NOTIFY_FIX) || key.equals(Const.KEY_PREF_NOTIFY_SEARCH)) {
        boolean notifyFix = sharedPreferences.getBoolean(Const.KEY_PREF_NOTIFY_FIX, false);
        boolean notifySearch = sharedPreferences.getBoolean(Const.KEY_PREF_NOTIFY_SEARCH, false);
        if (!(notifyFix || notifySearch)) {
            Intent stopServiceIntent = new Intent(this, PasvLocListenerService.class);
            this.stopService(stopServiceIntent);
        } else if (ContextCompat.checkSelfPermission(this,
                Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            needsLocationPerm = true;/*from  w  w  w  .  j  a v a 2s.  co m*/
        }
    } else if (key.equals(Const.KEY_PREF_UPDATE_FREQ)) {
        // this piece of code is necessary because Android has no way
        // of updating the preference summary automatically. I am
        // told the absence of such functionality is a feature...
        SettingsFragment sf = (SettingsFragment) getFragmentManager().findFragmentById(android.R.id.content);
        ListPreference prefUpdateFreq = (ListPreference) sf.findPreference(Const.KEY_PREF_UPDATE_FREQ);
        final String value = sharedPreferences.getString(key, key);
        final int index = prefUpdateFreq.findIndexOfValue(value);
        if (index >= 0) {
            final String summary = (String) prefUpdateFreq.getEntries()[index];
            prefUpdateFreq.setSummary(summary);
        }
    } else if (key.equals(Const.KEY_PREF_MAP_PATH)) {
        SettingsFragment sf = (SettingsFragment) getFragmentManager().findFragmentById(android.R.id.content);
        Preference prefMapPath = sf.findPreference(Const.KEY_PREF_MAP_PATH);
        prefMapPathValue = mSharedPreferences.getString(Const.KEY_PREF_MAP_PATH, prefMapPathValue);
        prefMapPath.setSummary(prefMapPathValue);
    } else if (key.equals(Const.KEY_PREF_UPDATE_NETWORKS)) {
        if (ContextCompat.checkSelfPermission(this,
                Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            Set<String> updateNetworks = sharedPreferences.getStringSet(Const.KEY_PREF_UPDATE_NETWORKS,
                    new HashSet<String>());
            if (!updateNetworks.isEmpty())
                needsLocationPerm = true;
        }
    }
    if (needsLocationPerm)
        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
                Const.PERM_REQUEST_LOCATION_PREF);
}

From source file:com.ovrhere.android.currencyconverter.ui.fragments.SettingsFragment.java

/** Finds and sets the update summary. Additionally sets default
 * value based on interval //from   w w w. j a  v  a  2  s .  co  m
 * @param interval The interval to show 
 * @param updateList The preference to update the summary */
private void findAndSetUpdateSummary(final int interval, ListPreference updateList) {
    CharSequence[] labels = updateList.getEntries();
    CharSequence[] values = updateList.getEntryValues();

    if (labels.length != values.length) {
        Log.w(CLASS_NAME, "Labels and values mismatch!");
        //if there is a mismatch, we know nothing.
        return;
    }
    final int SIZE = labels.length;
    for (int index = 0; index < SIZE; index++) {
        if (values[index].equals(String.valueOf(interval))) {
            //same value, so label it as such.
            updateList.setSummary(labels[index]);
            updateList.setValueIndex(index);
            return;
        }
    }
}