Search in sources :

Example 6 with EditTextPreference

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();
}
Also used : WhitespaceFilter(org.odk.collect.android.preferences.filters.WhitespaceFilter) EditTextPreference(android.preference.EditTextPreference) ControlCharacterFilter(org.odk.collect.android.preferences.filters.ControlCharacterFilter)

Example 7 with EditTextPreference

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;
    });
}
Also used : Context(android.content.Context) LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) LayoutInflater(android.view.LayoutInflater) MapLoader(com.peterlaurence.trekadvisor.core.map.maploader.MapLoader) Dialog(android.app.Dialog) ViewGroup(android.view.ViewGroup) AlertDialog(android.app.AlertDialog) EditTextPreference(android.preference.EditTextPreference) Map(com.peterlaurence.trekadvisor.core.map.Map) ListPreference(android.preference.ListPreference) SharedPreferences(android.content.SharedPreferences) Preference(android.preference.Preference) PreferenceFragment(android.preference.PreferenceFragment) R(com.peterlaurence.trekadvisor.R) Toast(android.widget.Toast) View(android.view.View) DialogFragment(android.app.DialogFragment) WeakReference(java.lang.ref.WeakReference) DialogInterface(android.content.DialogInterface) Toast(android.widget.Toast) EditTextPreference(android.preference.EditTextPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) ListPreference(android.preference.ListPreference) EditTextPreference(android.preference.EditTextPreference) Map(com.peterlaurence.trekadvisor.core.map.Map)

Example 8 with EditTextPreference

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;
}
Also used : EditTextPreference(android.preference.EditTextPreference)

Example 9 with EditTextPreference

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;
}
Also used : EditTextPreference(android.preference.EditTextPreference)

Example 10 with EditTextPreference

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);
    }
}
Also used : EditTextPreference(android.preference.EditTextPreference) Preference(android.preference.Preference) SwitchPreference(android.preference.SwitchPreference)

Aggregations

EditTextPreference (android.preference.EditTextPreference)77 ListPreference (android.preference.ListPreference)32 Preference (android.preference.Preference)32 CheckBoxPreference (android.preference.CheckBoxPreference)17 SharedPreferences (android.content.SharedPreferences)11 PreferenceScreen (android.preference.PreferenceScreen)11 Test (org.junit.Test)9 MultiSelectListPreference (android.preference.MultiSelectListPreference)8 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)8 Intent (android.content.Intent)7 ArrayList (java.util.ArrayList)7 DialogInterface (android.content.DialogInterface)6 Bundle (android.os.Bundle)6 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)5 View (android.view.View)5 SwitchPreference (android.preference.SwitchPreference)4 EditText (android.widget.EditText)4 File (java.io.File)4 Activity (android.app.Activity)3 AlertDialog (android.app.AlertDialog)3