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;
});
}
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;
}
});
}
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);
}
}
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);
}
}
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);
}
Aggregations