Java Code Examples for android.support.v7.preference.ListPreference#setSummary()

The following examples show how to use android.support.v7.preference.ListPreference#setSummary() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SettingsFragment.java    From android_gisapp with GNU General Public License v3.0 6 votes vote down vote up
public static void initializeMapBG(final ListPreference mapBG)
{
    mapBG.setSummary(mapBG.getEntry());

    mapBG.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
    {
        @Override
        public boolean onPreferenceChange(
                Preference preference,
                Object newValue)
        {
            preference.setSummary(
                    mapBG.getEntries()[mapBG.findIndexOfValue((String) newValue)]);
            return true;
        }
    });
}
 
Example 2
Source File: SettingsFragment.java    From android_gisapp with GNU General Public License v3.0 6 votes vote down vote up
public static void initializeShowCurrentLocation(
        final ListPreference listPreference)
{
    listPreference.setSummary(listPreference.getEntry());

    listPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
    {
        @Override
        public boolean onPreferenceChange(
                Preference preference,
                Object newValue)
        {
            preference.setSummary(listPreference.getEntries()[listPreference.findIndexOfValue(
                    (String) newValue)]);

            return true;
        }
    });
}
 
Example 3
Source File: SettingsFragment.java    From android_gisapp with GNU General Public License v3.0 6 votes vote down vote up
public static void initializeShowStatusPanel(final ListPreference listPreference)
{
    listPreference.setSummary(listPreference.getEntry());

    listPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
    {
        @Override
        public boolean onPreferenceChange(
                Preference preference,
                Object newValue)
        {
            preference.setSummary(listPreference.getEntries()[listPreference.findIndexOfValue(
                    (String) newValue)]);

            return true;
        }
    });
}
 
Example 4
Source File: SettingsFragment.java    From android_gisapp with GNU General Public License v3.0 6 votes vote down vote up
public static void initializeTheme(
        final Activity activity,
        final ListPreference theme)
{
    if (null != theme) {
        theme.setSummary(theme.getEntry());

        theme.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
        {
            @Override
            public boolean onPreferenceChange(
                    Preference preference,
                    Object newValue)
            {
                activity.startActivity(activity.getIntent());
                activity.finish();
                return true;
            }
        });
    }
}
 
Example 5
Source File: SettingsFragment.java    From android-dev-challenge with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the summary for the preference
 *
 * @param preference The preference to be updated
 * @param value      The value that the preference was updated to
 */
private void setPreferenceSummary(Preference preference, String value) {
    // COMPLETED (3) Don't forget to add code here to properly set the summary for an EditTextPreference
    if (preference instanceof ListPreference) {
        // For list preferences, figure out the label of the selected value
        ListPreference listPreference = (ListPreference) preference;
        int prefIndex = listPreference.findIndexOfValue(value);
        if (prefIndex >= 0) {
            // Set the summary to that label
            listPreference.setSummary(listPreference.getEntries()[prefIndex]);
        }
    } else if (preference instanceof EditTextPreference) {
        preference.setSummary(value);
    }
}
 
Example 6
Source File: SettingsActivity.java    From NominatimGeocoderBackend with Apache License 2.0 5 votes vote down vote up
private void updatePreference(Preference preference, String key) {
    refreshPrefs();

    if (preference == null) {
        return;
    }

    if (preference instanceof ListPreference) {
        ListPreference listPreference = (ListPreference) preference;
        listPreference.setSummary(listPreference.getEntry());
        return;
    }

    preference.setSummary(shPref.getString(key, "Default"));
}
 
Example 7
Source File: SettingsFragment.java    From android_gisapp with GNU General Public License v3.0 5 votes vote down vote up
public static void initializeLocationAccuracy(
        final ListPreference listPreference,
        final boolean isTracks)
{
    if (listPreference != null) {
        CharSequence[] entries = getAccuracyEntries(listPreference.getContext());
        listPreference.setEntries(entries);
        listPreference.setSummary(listPreference.getEntry());

        listPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
        {
            @Override
            public boolean onPreferenceChange(
                    Preference preference,
                    Object newValue)
            {
                int value = Integer.parseInt(newValue.toString());
                CharSequence summary = ((ListPreference) preference).getEntries()[value - 1];
                preference.setSummary(summary);

                sectionWork(preference.getContext(), isTracks);

                return true;
            }
        });
    }
}
 
Example 8
Source File: SettingsFragment.java    From android_gisapp with GNU General Public License v3.0 5 votes vote down vote up
public static void initializeUnits(final ListPreference lpUnits) {
    lpUnits.setSummary(lpUnits.getEntry());
    lpUnits.setOnPreferenceChangeListener(
            new Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(Preference preference, Object newValue) {
                    boolean metric = newValue.equals("metric");
                    preference.setSummary(lpUnits.getEntries()[metric ? 0 : 1]);
                    return true;
                }
            });
}
 
Example 9
Source File: ListSummaryPreferenceFragment.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
  ListPreference listPref   = (ListPreference) preference;
  int            entryIndex = Arrays.asList(listPref.getEntryValues()).indexOf(value);

  listPref.setSummary(entryIndex >= 0 && entryIndex < listPref.getEntries().length
                      ? listPref.getEntries()[entryIndex]
                      : getString(R.string.preferences__led_color_unknown));
  return true;
}
 
Example 10
Source File: BeaconActionPageFragment.java    From beaconloc with Apache License 2.0 5 votes vote down vote up
private void setActionType(String newValue) {
    final ListPreference action_list = (ListPreference) findPreference("ba_action_list");
    if (newValue != null && !newValue.isEmpty()) {
        int index = action_list.findIndexOfValue(newValue);
        action_list.setSummary(index >= 0
                ? action_list.getEntries()[index]
                : null);
        mActionBeacon.setActionType(ActionBeacon.ActionType.fromInt(index >= 0 ? index : 0));
    } else {
        action_list.setSummary(action_list.getEntries()[0]);
        mActionBeacon.setActionType(ActionBeacon.ActionType.fromInt(0));
    }
}
 
Example 11
Source File: SettingsActivity.java    From video-quickstart-android with MIT License 5 votes vote down vote up
private void setupCodecListPreference(Class codecClass,
                                      String key,
                                      String defaultValue,
                                      ListPreference preference) {
    List<String> codecEntries = new ArrayList<>();
    if(codecClass == AudioCodec.class){
        Collections.addAll(codecEntries, AUDIO_CODEC_NAMES);
    }else{
        Collections.addAll(codecEntries, VIDEO_CODEC_NAMES);
    }

    // Remove H264 if not supported
    if (!MediaCodecVideoDecoder.isH264HwSupported() ||
            !MediaCodecVideoEncoder.isH264HwSupported()) {
        codecEntries.remove(H264Codec.NAME);
    }
    String[] codecStrings = codecEntries.toArray(new String[codecEntries.size()]);

    // Saved value
    final String value = sharedPreferences.getString(key, defaultValue);

    // Bind values
    preference.setEntries(codecStrings);
    preference.setEntryValues(codecStrings);
    preference.setValue(value);
    preference.setSummary(value);
    preference.setOnPreferenceChangeListener((preference1, newValue) -> {
        preference1.setSummary(newValue.toString());
        return true;
    });
}
 
Example 12
Source File: SettingsFragment.java    From andela-crypto-app with Apache License 2.0 5 votes vote down vote up
private void loadSummaries(String key) {
    ListPreference preference = (ListPreference) findPreference("THEME");
    preference.setSummary(preference.getEntry());

    if (ObjectsCompat.equals(key, "THEME")) {
        getActivity().recreate();
    }
}
 
Example 13
Source File: SettingsActivity.java    From Camera-Roll-Android-App with Apache License 2.0 5 votes vote down vote up
private void initThemePref(String theme) {
    ListPreference themePref = (ListPreference)
            findPreference(getString(R.string.pref_key_theme));

    String theme_name = Settings.Utils.getThemeName(getActivity(), theme);
    themePref.setSummary(theme_name);
    themePref.setOnPreferenceChangeListener(this);
}
 
Example 14
Source File: SettingsFragment.java    From android-dev-challenge with Apache License 2.0 5 votes vote down vote up
private void setPreferenceSummary(Preference preference, String value) {
    if (preference instanceof ListPreference) {
        ListPreference listPreference = (ListPreference) preference;
        int prefIndex = listPreference.findIndexOfValue(value);

        if (prefIndex >= 0) {
            listPreference.setSummary(listPreference.getEntries()[prefIndex]);
        }
    }
}
 
Example 15
Source File: SettingsFragment.java    From android-dev-challenge with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the summary for the preference
 *
 * @param preference The preference to be updated
 * @param value      The value that the preference was updated to
 */
private void setPreferenceSummary(Preference preference, String value) {
    if (preference instanceof ListPreference) {
        // For list preferences, figure out the label of the selected value
        ListPreference listPreference = (ListPreference) preference;
        int prefIndex = listPreference.findIndexOfValue(value);
        if (prefIndex >= 0) {
            // Set the summary to that label
            listPreference.setSummary(listPreference.getEntries()[prefIndex]);
        }
    } else if (preference instanceof EditTextPreference) {
        // For EditTextPreferences, set the summary to the value's simple string representation.
        preference.setSummary(value);
    }
}
 
Example 16
Source File: ListSummaryPreferenceFragment.java    From Silence with GNU General Public License v3.0 4 votes vote down vote up
protected void initializeListSummary(ListPreference pref) {
  pref.setSummary(pref.getEntry());
}
 
Example 17
Source File: RecipientPreferenceActivity.java    From Silence with GNU General Public License v3.0 4 votes vote down vote up
private void setSummaries(Recipients recipients) {
  CheckBoxPreference         mutePreference     = (CheckBoxPreference) this.findPreference(PREFERENCE_MUTED);
  AdvancedRingtonePreference ringtonePreference = (AdvancedRingtonePreference) this.findPreference(PREFERENCE_TONE);
  ListPreference             vibratePreference  = (ListPreference) this.findPreference(PREFERENCE_VIBRATE);
  ColorPickerPreference      colorPreference    = (ColorPickerPreference) this.findPreference(PREFERENCE_COLOR);
  Preference                 blockPreference    = this.findPreference(PREFERENCE_BLOCK);

  mutePreference.setChecked(recipients.isMuted());

  final Uri toneUri = recipients.getRingtone();

  if (toneUri == null) {
    ringtonePreference.setSummary(R.string.preferences__default);
    ringtonePreference.setCurrentRingtone(Settings.System.DEFAULT_NOTIFICATION_URI);
  } else if (toneUri.toString().isEmpty()) {
    ringtonePreference.setSummary(R.string.preferences__silent);
    ringtonePreference.setCurrentRingtone(null);
  } else {
    Ringtone tone = RingtoneManager.getRingtone(getActivity(), toneUri);

    if (tone != null) {
      ringtonePreference.setSummary(tone.getTitle(getActivity()));
      ringtonePreference.setCurrentRingtone(toneUri);
    }
  }

  if (recipients.getVibrate() == VibrateState.DEFAULT) {
    vibratePreference.setSummary(R.string.preferences__default);
    vibratePreference.setValueIndex(0);
  } else if (recipients.getVibrate() == VibrateState.ENABLED) {
    vibratePreference.setSummary(R.string.RecipientPreferenceActivity_enabled);
    vibratePreference.setValueIndex(1);
  } else {
    vibratePreference.setSummary(R.string.RecipientPreferenceActivity_disabled);
    vibratePreference.setValueIndex(2);
  }

  if (!recipients.isSingleRecipient() || recipients.isGroupRecipient()) {
    if (colorPreference    != null) getPreferenceScreen().removePreference(colorPreference);
    if (blockPreference    != null) getPreferenceScreen().removePreference(blockPreference);
  } else {
    colorPreference.setColors(MaterialColors.CONVERSATION_PALETTE.asConversationColorArray(getActivity()));
    colorPreference.setColor(recipients.getColor().toActionBarColor(getActivity()));

    if (recipients.isBlocked()) blockPreference.setTitle(R.string.RecipientPreferenceActivity_unblock);
    else                        blockPreference.setTitle(R.string.RecipientPreferenceActivity_block);
  }
}
 
Example 18
Source File: FragmentSettings.java    From GPSLogger with GNU General Public License v3.0 4 votes vote down vote up
public void SetupPreferences() {

        ListPreference pUM = (ListPreference) findPreference("prefUM");
        ListPreference pUMSpeed = (ListPreference) findPreference("prefUMSpeed");
        ListPreference pGPSDistance = (ListPreference) findPreference("prefGPSdistance");
        ListPreference pGPSUpdateFrequency = (ListPreference) findPreference("prefGPSupdatefrequency");
        ListPreference pKMLAltitudeMode = (ListPreference) findPreference("prefKMLAltitudeMode");
        ListPreference pGPXVersion = (ListPreference) findPreference("prefGPXVersion");
        ListPreference pShowTrackStatsType = (ListPreference) findPreference("prefShowTrackStatsType");
        ListPreference pShowDirections = (ListPreference) findPreference("prefShowDirections");
        ListPreference pViewTracksWith = (ListPreference) findPreference("prefViewTracksWith");
        ListPreference pColorTheme = (ListPreference) findPreference("prefColorTheme");
        EditTextPreference pAltitudeCorrection = (EditTextPreference) findPreference("prefAltitudeCorrectionRaw");

        altcorm = Double.valueOf(prefs.getString("prefAltitudeCorrection", "0"));
        altcor = prefs.getString("prefUM", "0").equals("0") ? altcorm : altcorm * M_TO_FT;

        if (prefs.getString("prefUM", "0").equals("0")) {       // Metric
            pUMSpeed.setEntries(R.array.UMSpeed_Metric);
            pGPSDistance.setEntries(R.array.GPSDistance_Metric);
            pAltitudeCorrection.setSummary(altcor != 0 ? getString(R.string.pref_AltitudeCorrection_summary_offset) + " = " + Double.valueOf(Math.round(altcor*1000d)/1000d).toString() + " m" : getString(R.string.pref_AltitudeCorrection_summary_not_defined));

        }
        if (prefs.getString("prefUM", "0").equals("8")) {       // Imperial
            pUMSpeed.setEntries(R.array.UMSpeed_Imperial);
            pGPSDistance.setEntries(R.array.GPSDistance_Imperial);
            pAltitudeCorrection.setSummary(altcor != 0 ? getString(R.string.pref_AltitudeCorrection_summary_offset) + " = " + Double.valueOf(Math.round(altcor*1000d)/1000d).toString() + " ft" : getString(R.string.pref_AltitudeCorrection_summary_not_defined));
        }
        if (prefs.getString("prefUM", "0").equals("16")) {       // Aerial / Nautical
            pUMSpeed.setEntries(R.array.UMSpeed_AerialNautical);
            pGPSDistance.setEntries(R.array.GPSDistance_Imperial);
            pAltitudeCorrection.setSummary(altcor != 0 ? getString(R.string.pref_AltitudeCorrection_summary_offset) + " = " + Double.valueOf(Math.round(altcor*1000d)/1000d).toString() + " ft" : getString(R.string.pref_AltitudeCorrection_summary_not_defined));
        }

        Log.w("myApp", "[#] FragmentSettings.java - prefAltitudeCorrectionRaw = " + prefs.getString("prefAltitudeCorrectionRaw", "0")) ;
        Log.w("myApp", "[#] FragmentSettings.java - prefAltitudeCorrection = " + prefs.getString("prefAltitudeCorrection", "0")) ;

        // Set all summaries
        pColorTheme.setSummary(pColorTheme.getEntry());
        pUMSpeed.setSummary(pUMSpeed.getEntry());
        pUM.setSummary(pUM.getEntry());
        pGPSDistance.setSummary(pGPSDistance.getEntry());
        pGPSUpdateFrequency.setSummary(pGPSUpdateFrequency.getEntry());
        pKMLAltitudeMode.setSummary(pKMLAltitudeMode.getEntry());
        pGPXVersion.setSummary(pGPXVersion.getEntry());
        pShowTrackStatsType.setSummary(pShowTrackStatsType.getEntry());
        pShowDirections.setSummary(pShowDirections.getEntry());
        pViewTracksWith.setSummary(pViewTracksWith.getEntry());
    }
 
Example 19
Source File: PreferencesFragment.java    From fdroidclient with GNU General Public License v3.0 4 votes vote down vote up
private void entrySummary(String key) {
    ListPreference pref = (ListPreference) findPreference(key);
    if (pref != null) {
        pref.setSummary(pref.getEntry());
    }
}