use of android.preference.EditTextPreference in project collect by opendatakit.
the class ServerPreferencesFragment method addGooglePreferences.
public void addGooglePreferences() {
addPreferencesFromResource(R.xml.google_preferences);
selectedGoogleAccountPreference = findPreference(PreferenceKeys.KEY_SELECTED_GOOGLE_ACCOUNT);
EditTextPreference googleSheetsUrlPreference = (EditTextPreference) findPreference(PreferenceKeys.KEY_GOOGLE_SHEETS_URL);
googleSheetsUrlPreference.setOnPreferenceChangeListener(createChangeListener());
String currentGoogleSheetsURL = googleSheetsUrlPreference.getText();
if (currentGoogleSheetsURL != null && currentGoogleSheetsURL.length() > 0) {
googleSheetsUrlPreference.setSummary(currentGoogleSheetsURL + "\n\n" + getString(R.string.google_sheets_url_hint));
}
googleSheetsUrlPreference.getEditText().setFilters(new InputFilter[] { new ControlCharacterFilter(), new WhitespaceFilter() });
initAccountPreferences();
}
use of android.preference.EditTextPreference in project TrekAdvisor by peterLaurence.
the class MapSettingsFragment method initComponents.
private void initComponents() {
ListPreference mCalibrationListPreference = (ListPreference) getPreferenceManager().findPreference(getString(R.string.preference_projection_key));
ListPreference mCalibrationPointsNumberPreference = (ListPreference) getPreferenceManager().findPreference(getString(R.string.preference_numpoints_key));
EditTextPreference mapNamePreference = (EditTextPreference) getPreferenceManager().findPreference(getString(R.string.preference_map_title_key));
Preference calibrationButton = getPreferenceManager().findPreference(getString(R.string.preference_calibration_button_key));
Preference deleteButton = getPreferenceManager().findPreference(getString(R.string.preference_delete_button_key));
/* Set the summaries and the values of preferences according to the Map object */
final Map map = mMapWeakReference.get();
if (map != null) {
String projectionName;
if ((projectionName = map.getProjectionName()) == null) {
projectionName = getString(R.string.projection_none);
}
setListPreferenceSummaryAndValue(mCalibrationListPreference, projectionName);
setListPreferenceSummaryAndValue(mCalibrationPointsNumberPreference, String.valueOf(map.getCalibrationPointsNumber()));
setEditTextPreferenceSummaryAndValue(mapNamePreference, map.getName());
}
calibrationButton.setOnPreferenceClickListener(preference -> {
mMapCalibrationRequestListener.onMapCalibrationRequest();
return true;
});
mCalibrationPointsNumberPreference.setOnPreferenceChangeListener(((preference, newValue) -> {
Map map_ = mMapWeakReference.get();
if (map_ != null) {
switch((String) newValue) {
case "2":
map_.setCalibrationMethod(MapLoader.CALIBRATION_METHOD.SIMPLE_2_POINTS);
break;
case "3":
map_.setCalibrationMethod(MapLoader.CALIBRATION_METHOD.CALIBRATION_3_POINTS);
break;
case "4":
map_.setCalibrationMethod(MapLoader.CALIBRATION_METHOD.CALIBRATION_4_POINTS);
break;
default:
map_.setCalibrationMethod(MapLoader.CALIBRATION_METHOD.SIMPLE_2_POINTS);
}
return true;
}
return false;
}));
mapNamePreference.setOnPreferenceChangeListener((preference, newValue) -> {
try {
mMapWeakReference.get().setName((String) newValue);
return true;
} catch (Exception e) {
return false;
}
});
mCalibrationListPreference.setOnPreferenceChangeListener((preference, projectionName) -> {
try {
/* If the projection is set to none */
if (getString(R.string.projection_none).equals(projectionName)) {
mMapWeakReference.get().setProjection(null);
return true;
}
if (MapLoader.getInstance().mutateMapProjection(mMapWeakReference.get(), (String) projectionName)) {
String saveOkMsg = getString(R.string.calibration_projection_saved_ok);
Toast toast = Toast.makeText(getContext(), saveOkMsg, Toast.LENGTH_SHORT);
toast.show();
} else {
// TODO : show some warning ("Wrong Projection name").
}
return true;
} catch (Exception e) {
return false;
}
});
deleteButton.setOnPreferenceClickListener(preference -> {
ConfirmDeleteFragment f = new ConfirmDeleteFragment();
f.setMapWeakRef(mMapWeakReference);
f.setDeleteMapListener(mDeleteMapListener);
f.show(getFragmentManager(), "delete");
return true;
});
}
use of android.preference.EditTextPreference in project EngineDriver by JMRI.
the class preferences method limitFloatPrefValue.
@SuppressWarnings("deprecation")
private boolean limitFloatPrefValue(SharedPreferences sharedPreferences, String key, Float minVal, Float maxVal, String defaultVal) {
boolean isValid = true;
EditTextPreference prefText = (EditTextPreference) getPreferenceScreen().findPreference(key);
try {
Float newVal = Float.parseFloat(sharedPreferences.getString(key, defaultVal).trim());
if (newVal > maxVal) {
sharedPreferences.edit().putString(key, Float.toString(maxVal)).commit();
prefText.setText(Float.toString(maxVal));
isValid = false;
Toast.makeText(getApplicationContext(), getApplicationContext().getResources().getString(R.string.toastPreferencesOutsideLimits).replace("%%1%%", Float.toString(minVal)).replace("%%2%%", Float.toString(maxVal)).replace("%%3%%", Float.toString(maxVal)), Toast.LENGTH_LONG).show();
} else if (newVal < minVal) {
sharedPreferences.edit().putString(key, Float.toString(minVal)).commit();
prefText.setText(Float.toString(minVal));
isValid = false;
Toast.makeText(getApplicationContext(), getApplicationContext().getResources().getString(R.string.toastPreferencesOutsideLimits).replace("%%1%%", Float.toString(minVal)).replace("%%2%%", Float.toString(maxVal)).replace("%%3%%", Float.toString(minVal)), Toast.LENGTH_LONG).show();
}
} catch (NumberFormatException e) {
sharedPreferences.edit().putString(key, defaultVal).commit();
prefText.setText(defaultVal);
isValid = false;
Toast.makeText(getApplicationContext(), getApplicationContext().getResources().getString(R.string.toastPreferencesNotNumeric).replace("%%1%%", Float.toString(minVal)).replace("%%2%%", Float.toString(maxVal)).replace("%%3%%", defaultVal), Toast.LENGTH_LONG).show();
}
return isValid;
}
use of android.preference.EditTextPreference in project EngineDriver by JMRI.
the class preferences method limitIntPrefValue.
@SuppressWarnings("deprecation")
private boolean limitIntPrefValue(SharedPreferences sharedPreferences, String key, int minVal, int maxVal, String defaultVal) {
boolean isValid = true;
EditTextPreference prefText = (EditTextPreference) getPreferenceScreen().findPreference(key);
try {
int newVal = Integer.parseInt(sharedPreferences.getString(key, defaultVal).trim());
if (newVal > maxVal) {
sharedPreferences.edit().putString(key, Integer.toString(maxVal)).commit();
prefText.setText(Integer.toString(maxVal));
isValid = false;
Toast.makeText(getApplicationContext(), getApplicationContext().getResources().getString(R.string.toastPreferencesOutsideLimits).replace("%%1%%", Integer.toString(minVal)).replace("%%2%%", Integer.toString(minVal)).replace("%%3%%", Float.toString(maxVal)), Toast.LENGTH_LONG).show();
} else if (newVal < minVal) {
sharedPreferences.edit().putString(key, Integer.toString(minVal)).commit();
prefText.setText(Integer.toString(minVal));
isValid = false;
Toast.makeText(getApplicationContext(), getApplicationContext().getResources().getString(R.string.toastPreferencesOutsideLimits).replace("%%1%%", Integer.toString(minVal)).replace("%%2%%", Integer.toString(minVal)).replace("%%3%%", Float.toString(minVal)), Toast.LENGTH_LONG).show();
}
} catch (NumberFormatException e) {
sharedPreferences.edit().putString(key, defaultVal).commit();
prefText.setText(defaultVal);
isValid = false;
Toast.makeText(getApplicationContext(), getApplicationContext().getResources().getString(R.string.toastPreferencesNotNumeric).replace("%%1%%", Integer.toString(minVal)).replace("%%2%%", Integer.toString(maxVal)).replace("%%3%%", defaultVal), Toast.LENGTH_LONG).show();
}
return isValid;
}
use of android.preference.EditTextPreference in project android_packages_apps_Dialer by LineageOS.
the class ConfigOverrideFragment method onCreate.
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PreferenceManager.setDefaultValues(getActivity(), R.xml.vvm_config_override, false);
addPreferencesFromResource(R.xml.vvm_config_override);
// add listener so the value of a EditTextPreference will be updated to the summary.
for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); i++) {
Preference preference = getPreferenceScreen().getPreference(i);
preference.setOnPreferenceChangeListener(this);
updatePreference(preference);
}
}
Aggregations