Java Code Examples for androidx.preference.ListPreference#findIndexOfValue()

The following examples show how to use androidx.preference.ListPreference#findIndexOfValue() . 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: SketchPropertiesFragment.java    From APDE with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
	String stringValue = value.toString();
	
	if (preference instanceof ListPreference) {
		// For list preferences, look up the correct display value in
		// the preference's 'entries' list.
		ListPreference listPreference = (ListPreference) preference;
		int index = listPreference.findIndexOfValue(stringValue);
		
		// Set the summary to reflect the new value.
		preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);
	} else {
		// For all other preferences, set the summary to the value's
		// simple string representation.
		preference.setSummary(stringValue);
	}
	return true;
}
 
Example 2
Source File: SettingsActivity.java    From APDE with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
	String stringValue = value.toString();

	if (preference instanceof ListPreference) {
		// For list preferences, look up the correct display value in
		// the preference's 'entries' list.
		ListPreference listPreference = (ListPreference) preference;
		int index = listPreference.findIndexOfValue(stringValue);
		
		// Set the summary to reflect the new value.
		preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);
	} else {
		// For all other preferences, set the summary to the value's
		// simple string representation.
		preference.setSummary(stringValue);
	}
	return true;
}
 
Example 3
Source File: SettingsFragment.java    From Android-Application with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    ListPreference thermalPeletteList = (ListPreference) preference;

    try{
        String val = (String) newValue;
        //Try to get ThermalPalette from value...
        String className = ThermalPalette.class.getPackage().getName()+"."+val;
        Log.d("SettingsFragment", "Trying to load className: " + className);
        ThermalPalette palette = (ThermalPalette) Class.forName(className).newInstance();

        double min = palette.getDefaultMinTemperature();
        double max = palette.getDefaultMaxTemperature();

        findPreference("thermal_palette_default_range_info").setTitle("Default Range is from " + min + " to " + max + ".");

        //current selected to summary
        CharSequence entry = thermalPeletteList.getEntries()[thermalPeletteList.findIndexOfValue(val)];
        Log.d("SettingsFragment", "Changing summary to: " + entry);
        ((ListPreference)preference).setSummary(entry);

    } catch (Exception ex) {
        ex.printStackTrace();
    }



    return true;

}
 
Example 4
Source File: SettingsFragment.java    From SmsCode with GNU General Public License v3.0 5 votes vote down vote up
private void refreshListenModePreference(ListPreference listenModePref, String newValue) {
    if (TextUtils.isEmpty(newValue))
        return;
    CharSequence[] entries = listenModePref.getEntries();
    int index = listenModePref.findIndexOfValue(newValue);
    try {
        listenModePref.setSummary(entries[index]);
    } catch (Exception e) {
        //ignore
    }
}
 
Example 5
Source File: AutoInputSettingsFragment.java    From SmsCode with GNU General Public License v3.0 5 votes vote down vote up
private void refreshFocusModePreference(ListPreference focusModePref, String newValue) {
    if (TextUtils.isEmpty(newValue))
        return;
    CharSequence[] entries = focusModePref.getEntries();
    int index = focusModePref.findIndexOfValue(newValue);
    try {
        focusModePref.setSummary(entries[index]);
    } catch (Exception e) {
        //ignore
    }
}
 
Example 6
Source File: SettingsFragment.java    From android-popular-movies-app 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]);
        }
    }
}
 
Example 7
Source File: SettingsActivity.java    From Music-Player with GNU General Public License v3.0 5 votes vote down vote up
private static void setSummary(Preference preference, @NonNull Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);
        preference.setSummary(
                index >= 0
                        ? listPreference.getEntries()[index]
                        : null);
    } else {
        preference.setSummary(stringValue);
    }
}
 
Example 8
Source File: SettingsActivity.java    From VinylMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
private static void setSummary(Preference preference, @NonNull Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);
        preference.setSummary(
                index >= 0
                        ? listPreference.getEntries()[index]
                        : null);
    } else {
        preference.setSummary(stringValue);
    }
}
 
Example 9
Source File: SettingsFragment.java    From fastnfitness with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void updateSummary(ListPreference pref, String val, String prefix) {
    int prefIndex = pref.findIndexOfValue(val);
    if (prefIndex >= 0) {
        //finally set's it value changed
        pref.setSummary(prefix + pref.getEntries()[prefIndex]);
    }
}
 
Example 10
Source File: LoginSettingsFragment.java    From tindroid with Apache License 2.0 5 votes vote down vote up
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    Preference preference = findPreference(key);
    Context context = getContext();
    if (preference == null || context == null) {
        return;
    }

    switch (preference.getKey()) {
        case "pref_wireTransport":
            ListPreference listPreference = (ListPreference) preference;
            int prefIndex = listPreference.findIndexOfValue(sharedPreferences.getString(key,null));
            if (prefIndex >= 0) {
                preference.setSummary(getString(R.string.settings_wire_explained,
                        listPreference.getEntries()[prefIndex]));
            }
            break;
        case "pref_useTLS":
            break;
        case "pref_hostName":
            preference.setSummary(getString(R.string.settings_host_name_explained,
                    sharedPreferences.getString("pref_hostName", TindroidApp.getDefaultHostName(context))));
            break;
        default:
            Log.w(TAG, "Unknown preference '" + key + "'");
            // do nothing.
    }
}
 
Example 11
Source File: SettingsActivity.java    From Phonograph with GNU General Public License v3.0 5 votes vote down vote up
private static void setSummary(Preference preference, @NonNull Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);
        preference.setSummary(
                index >= 0
                        ? listPreference.getEntries()[index]
                        : null);
    } else {
        preference.setSummary(stringValue);
    }
}
 
Example 12
Source File: TalkBackPreferencesActivity.java    From talkback with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
  if (preference instanceof ListPreference && newValue instanceof String) {
    final ListPreference listPreference = (ListPreference) preference;
    final int index = listPreference.findIndexOfValue((String) newValue);
    final CharSequence[] entries = listPreference.getEntries();

    if (index >= 0 && index < entries.length) {
      preference.setSummary(entries[index].toString().replaceAll("%", "%%"));
    } else {
      preference.setSummary("");
    }
  }

  final String key = preference.getKey();
  if (getString(R.string.pref_resume_talkback_key).equals(key)) {
    final String oldValue =
        SharedPreferencesUtils.getStringPref(
            prefs,
            getResources(),
            R.string.pref_resume_talkback_key,
            R.string.pref_resume_talkback_default);
    if (!newValue.equals(oldValue)) {
      // Reset the suspend warning dialog when the resume
      // preference changes.
      SharedPreferencesUtils.putBooleanPref(
          prefs, getResources(), R.string.pref_show_suspension_confirmation_dialog, true);
    }
  }

  return true;
}
 
Example 13
Source File: SettingsFragment.java    From fresco with MIT License 5 votes vote down vote up
private void updateNumberOfDecodingThreadSummary(final Preference preference) {
  final ListPreference listPreference = (ListPreference) preference;
  final int valueIndex = listPreference.findIndexOfValue(listPreference.getValue());
  String summary = getResources().getStringArray(R.array.decoding_thread_summaries)[valueIndex];
  if (valueIndex == 0) {
    summary += Const.NUMBER_OF_PROCESSORS;
  }
  preference.setSummary(summary);
}
 
Example 14
Source File: SettingsActivity.java    From APDE with GNU General Public License v2.0 5 votes vote down vote up
protected void updateSketchbookDrivePref(ListPreference sketchbookDrive, Preference sketchbookLocation, ArrayList<APDE.StorageDrive> drives) {
	int selectedIndex = sketchbookDrive.findIndexOfValue(sketchbookDrive.getValue());
	
	if (selectedIndex == -1) {
		//Uh-oh
		return;
	}
	
	APDE.StorageDrive selected = drives.get(selectedIndex);
	
	sketchbookLocation.setEnabled(!(selected.type.equals(APDE.StorageDrive.StorageDriveType.INTERNAL) || selected.type.equals(APDE.StorageDrive.StorageDriveType.SECONDARY_EXTERNAL)));
	sketchbookDrive.setSummary(selected.space + " " + selected.type.title);
}
 
Example 15
Source File: SettingsFragment.java    From fresco with MIT License 4 votes vote down vote up
private static void updateListPreference(
    Resources resources, ListPreference preference, int arrayValuesId) {
  final int valueIndex = preference.findIndexOfValue(preference.getValue());
  final String summary = resources.getStringArray(arrayValuesId)[valueIndex];
  preference.setSummary(summary);
}