Search in sources :

Example 11 with ListPreference

use of android.preference.ListPreference 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 12 with ListPreference

use of android.preference.ListPreference in project MyJapanese by 54wall.

the class SettingFragment method initPreference.

private void initPreference() {
    mTTSListPreference = (ListPreference) getPreferenceManager().findPreference("setting_tts");
    mTTSListPreference.setEntries(R.array.tts_entries);
    mTTSListPreference.setEntryValues(R.array.tts_values);
    mTTSListPreference.setValue(tts_type);
    mTTSListPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            SharedPreferenceManager.getInstance().putString(Constants.TTS_TYPE, (String) newValue);
            JpTTSUtils.getInstance().updateTtsType();
            RxBus.getDefault().post(new EventContainer(EventContainer.TYPE_SETTING, new SettingEvent(R.string.setting_effect)));
            return true;
        }
    });
    mThemesListPreference = (ListPreference) getPreferenceManager().findPreference("setting_theme");
    mThemesListPreference.setEntries(R.array.themes_entries);
    mThemesListPreference.setEntryValues(R.array.themes_values);
    mThemesListPreference.setValue(mode_theme);
    mThemesListPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            SharedPreferenceManager.getInstance().putString(Constants.MODE_THEME, (String) newValue);
            RxBus.getDefault().post(new EventContainer(EventContainer.TYPE_SETTING, new SettingEvent(R.string.reboot_to_take_effect)));
            return true;
        }
    });
    mConnectCheckBoxPreference = (CheckBoxPreference) getPreferenceManager().findPreference("setting_wifi");
    mConnectCheckBoxPreference.setChecked(allow_connect);
    mConnectCheckBoxPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Log.i(TAG, "onPreferenceChange: " + newValue);
            SharedPreferenceManager.getInstance().putBoolean(Constants.ALLOW_CONNECT_WITHOUT_WIFI, (Boolean) newValue);
            RxBus.getDefault().post(new EventContainer(EventContainer.TYPE_SETTING, new SettingEvent(R.string.setting_effect)));
            return true;
        }
    });
}
Also used : CheckBoxPreference(android.preference.CheckBoxPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) EventContainer(pri.weiqiang.myjapanese.rxbus.event.EventContainer) SettingEvent(pri.weiqiang.myjapanese.rxbus.event.SettingEvent)

Example 13 with ListPreference

use of android.preference.ListPreference in project EngineDriver by JMRI.

the class preferences method onCreate.

/**
 * Called when the activity is first created.
 */
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
    ListPreference preference;
    SharedPreferences sharedPreferences = getSharedPreferences("jmri.enginedriver_preferences", 0);
    mainapp = (threaded_application) getApplication();
    mainapp.applyTheme(this);
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);
    if (!mainapp.isPowerControlAllowed()) {
        enableDisablePreference("show_layout_power_button_preference", false);
    }
    if (mainapp.androidVersion < mainapp.minWebSocketVersion) {
        enableDisablePreference("ClockDisplayTypePreference", false);
    }
    if (mainapp.androidVersion < mainapp.minImmersiveModeVersion) {
        enableDisablePreference("prefThrottleViewImmersiveMode", false);
    }
    if (mainapp.androidVersion < mainapp.minThemeVersion) {
        enableDisablePreference("prefTheme", false);
    }
    result = RESULT_OK;
    if (mainapp.connectedHostName.equals("")) {
        // option is only available when there is no curent connection
        getConnectionsList();
        preference = (ListPreference) findPreference("prefHostImportExport");
        preference.setEntries(prefHostImportExportEntriesFound);
        preference.setEntryValues(prefHostImportExportEntryValuesFound);
    } else {
        enableDisablePreference("prefHostImportExport", false);
    }
    // SharedPreferences sharedPreferences = getSharedPreferences("jmri.enginedriver_preferences", 0);
    setGamePadPrefLabels(sharedPreferences);
    // Disable ESU MCII preferences if not an ESU MCII
    if (!MobileControl2.isMobileControl2()) {
        enableDisablePreference("prefEsuMc2", false);
    }
    // reset the preference
    sharedPreferences.edit().putBoolean("prefGamepadTestNow", false).commit();
    if (mainapp.androidVersion < mainapp.minActivatedButtonsVersion) {
        enableDisablePreference("prefSelectedLocoIndicator", false);
    }
    deviceId = Settings.System.getString(getContentResolver(), Settings.System.ANDROID_ID);
    sharedPreferences.edit().putString("prefAndroidId", deviceId).commit();
    String currentValue = sharedPreferences.getString("prefTtsWhen", "");
    if (currentValue.equals("None")) {
        enableDisablePreference("prefTtsThrottleResponse", false);
        enableDisablePreference("prefTtsGamepadTest", false);
        enableDisablePreference("prefTtsGamepadTestComplete", false);
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) ListPreference(android.preference.ListPreference)

Example 14 with ListPreference

use of android.preference.ListPreference in project android_packages_apps_OmniClock by omnirom.

the class SettingsActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(Utils.getThemeResourceId(this));
    getWindow().getDecorView().setBackgroundColor(Utils.getViewBackgroundColor(this));
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.settings);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    // We don't want to reconstruct the timezone list every single time
    // onResume() is called so we do it once in onCreate
    ListPreference listPref;
    listPref = (ListPreference) findPreference(KEY_HOME_TZ);
    if (mTimezones == null) {
        mTime = System.currentTimeMillis();
        mTimezones = getAllTimezones();
    }
    listPref.setEntryValues(mTimezones[0]);
    listPref.setEntries(mTimezones[1]);
    listPref.setSummary(listPref.getEntry());
    listPref.setOnPreferenceChangeListener(this);
    mTimerAlarmPref = (RingtonePreference) findPreference(KEY_TIMER_ALARM);
    mTimerAlarmPref.setOnPreferenceChangeListener(this);
    mSnoozeMinutes = (NumberPickerPreference) findPreference(KEY_ALARM_SNOOZE_MINUTES);
    mSnoozeMinutes.setValue(Utils.getSnoozeTimeoutValue(this));
    mSnoozeMinutes.setMinValue(1);
    mSnoozeMinutes.setMaxValue(30);
    mSnoozeMinutes.setSummary(getSnoozedMinutes(mSnoozeMinutes.getValue()));
    mSnoozeMinutes.setOnPreferenceChangeListener(this);
    mSilenceMinutes = (AutoSilencePickerPreference) findPreference(KEY_ALARM_SILENCE_AFTER);
    mSilenceMinutes.setValue(Utils.getTimeoutValue(this));
    mSilenceMinutes.setMinValue(1);
    mSilenceMinutes.setMaxValue(30);
    updateSilenceAfterSummary(mSilenceMinutes, mSilenceMinutes.getValue());
    mSilenceMinutes.setOnPreferenceChangeListener(this);
    addSettings();
    if (!getResources().getBoolean(R.bool.config_disableSensorOnWirelessCharging)) {
        Preference p = findPreference(KEY_ALARM_ACTION_WIRELESS_HEADER);
        PreferenceCategory alarmActionsCategory = (PreferenceCategory) findPreference(KEY_ALARM_ACTION_CATEGORY);
        alarmActionsCategory.removePreference(p);
    }
}
Also used : NumberPickerPreference(org.omnirom.deskclock.preference.NumberPickerPreference) CheckBoxPreference(android.preference.CheckBoxPreference) AutoSilencePickerPreference(org.omnirom.deskclock.preference.AutoSilencePickerPreference) RingtonePreference(android.preference.RingtonePreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) PreferenceCategory(android.preference.PreferenceCategory) ListPreference(android.preference.ListPreference)

Example 15 with ListPreference

use of android.preference.ListPreference in project android_packages_apps_OmniClock by omnirom.

the class SettingsActivity method addSettings.

private void addSettings() {
    ListPreference listPref = (ListPreference) findPreference(KEY_CLOCK_STYLE);
    listPref.setSummary(listPref.getEntry());
    listPref.setOnPreferenceChangeListener(this);
    Preference pref = findPreference(KEY_AUTO_HOME_CLOCK);
    boolean state = ((CheckBoxPreference) pref).isChecked();
    pref.setOnPreferenceChangeListener(this);
    listPref = (ListPreference) findPreference(KEY_HOME_TZ);
    listPref.setEnabled(state);
    listPref.setSummary(listPref.getEntry());
    listPref.setOnPreferenceChangeListener(this);
    listPref = (ListPreference) findPreference(KEY_VOLUME_BUTTONS);
    listPref.setSummary(listPref.getEntry());
    listPref.setOnPreferenceChangeListener(this);
    final SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    final boolean hasAccelSensor = sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER).size() >= 1;
    final boolean hasOrientationSensor = sensorManager.getSensorList(Sensor.TYPE_ORIENTATION).size() >= 1;
    final PreferenceCategory alarmCategory = (PreferenceCategory) findPreference(KEY_FULLSCREEN_ALARM_SETTINGS);
    listPref = (ListPreference) findPreference(KEY_FLIP_ACTION);
    if (hasOrientationSensor) {
        listPref.setSummary(listPref.getEntry());
        listPref.setOnPreferenceChangeListener(this);
    } else {
        alarmCategory.removePreference(listPref);
    }
    listPref = (ListPreference) findPreference(KEY_SHAKE_ACTION);
    if (hasAccelSensor) {
        listPref.setSummary(listPref.getEntry());
        listPref.setOnPreferenceChangeListener(this);
    } else {
        alarmCategory.removePreference(listPref);
    }
    listPref = (ListPreference) findPreference(KEY_ALARM_SNOOZE_COUNT);
    listPref.setSummary(listPref.getEntry());
    listPref.setOnPreferenceChangeListener(this);
    listPref = (ListPreference) findPreference(KEY_VOLUME_INCREASE_SPEED);
    listPref.setSummary(listPref.getEntry());
    listPref.setOnPreferenceChangeListener(this);
    listPref = (ListPreference) findPreference(KEY_WEEK_START);
    listPref.setEntries(getWeekdays());
    listPref.setSummary(listPref.getEntry());
    listPref.setOnPreferenceChangeListener(this);
    listPref = (ListPreference) findPreference(KEY_AUDIO_STREAM);
    listPref.setSummary(listPref.getEntry());
    listPref.setOnPreferenceChangeListener(this);
    listPref = (ListPreference) findPreference(KEY_TIMER_ALARM_INCREASE_VOLUME_SPEED);
    listPref.setSummary(listPref.getEntry());
    listPref.setOnPreferenceChangeListener(this);
    mCustomTimerAlarm = (CheckBoxPreference) findPreference(KEY_TIMER_ALARM_CUSTOM);
    listPref = (ListPreference) findPreference(KEY_PRE_ALARM_NOTIFICATION_TIME);
    listPref.setSummary(listPref.getEntry());
    listPref.setOnPreferenceChangeListener(this);
    listPref = (ListPreference) findPreference(KEY_COLOR_THEME);
    listPref.setSummary(listPref.getEntry());
    listPref.setOnPreferenceChangeListener(this);
    listPref = (ListPreference) findPreference(KEY_DEFAULT_PAGE);
    listPref.setSummary(listPref.getEntry());
    listPref.setOnPreferenceChangeListener(this);
}
Also used : SensorManager(android.hardware.SensorManager) NumberPickerPreference(org.omnirom.deskclock.preference.NumberPickerPreference) CheckBoxPreference(android.preference.CheckBoxPreference) AutoSilencePickerPreference(org.omnirom.deskclock.preference.AutoSilencePickerPreference) RingtonePreference(android.preference.RingtonePreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) CheckBoxPreference(android.preference.CheckBoxPreference) PreferenceCategory(android.preference.PreferenceCategory) ListPreference(android.preference.ListPreference)

Aggregations

ListPreference (android.preference.ListPreference)152 Preference (android.preference.Preference)76 CheckBoxPreference (android.preference.CheckBoxPreference)47 EditTextPreference (android.preference.EditTextPreference)32 PreferenceScreen (android.preference.PreferenceScreen)20 ArrayList (java.util.ArrayList)18 SharedPreferences (android.content.SharedPreferences)17 Intent (android.content.Intent)14 PreferenceCategory (android.preference.PreferenceCategory)14 SuppressLint (android.annotation.SuppressLint)13 MultiSelectListPreference (android.preference.MultiSelectListPreference)8 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)8 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)8 File (java.io.File)8 Bundle (android.os.Bundle)7 SwitchPreference (android.preference.SwitchPreference)7 View (android.view.View)7 Context (android.content.Context)6 DialogInterface (android.content.DialogInterface)6 RingtonePreference (android.preference.RingtonePreference)6