use of androidx.preference.CheckBoxPreference in project openScale by oliexdev.
the class FloatMeasurementView method prepareExtraPreferencesScreen.
@Override
public void prepareExtraPreferencesScreen(PreferenceScreen screen) {
MeasurementViewSettings settings = getSettings();
CheckBoxPreference rightAxis = new CheckBoxPreference(screen.getContext());
rightAxis.setKey(settings.getOnRightAxisKey());
rightAxis.setTitle(R.string.label_is_on_right_axis);
rightAxis.setPersistent(true);
rightAxis.setDefaultValue(settings.isOnRightAxis());
screen.addPreference(rightAxis);
if (supportsConversion()) {
SwitchPreference percentage = new SwitchPreference(screen.getContext());
percentage.setKey(settings.getPercentageEnabledKey());
percentage.setTitle(R.string.label_measurement_in_percent);
percentage.setPersistent(true);
percentage.setDefaultValue(settings.isPercentageEnabled());
screen.addPreference(percentage);
}
if (isEstimationSupported()) {
final CheckBoxPreference estimate = new CheckBoxPreference(screen.getContext());
estimate.setKey(settings.getEstimationEnabledKey());
estimate.setTitle(R.string.label_estimate_measurement);
estimate.setSummary(R.string.label_estimate_measurement_summary);
estimate.setPersistent(true);
estimate.setDefaultValue(settings.isEstimationEnabled());
screen.addPreference(estimate);
final ListPreference formula = new ListPreferenceWithNeutralButton(screen.getContext());
formula.setKey(settings.getEstimationFormulaKey());
formula.setTitle(R.string.label_estimation_formula);
formula.setPersistent(true);
formula.setDefaultValue(settings.getEstimationFormula());
prepareEstimationFormulaPreference(formula);
formula.setEnabled(estimate.isChecked());
formula.setSummary(formula.getEntries()[formula.findIndexOfValue(settings.getEstimationFormula())]);
formula.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
ListPreference list = (ListPreference) preference;
int idx = list.findIndexOfValue((String) newValue);
if (idx == -1) {
return false;
}
preference.setSummary(list.getEntries()[idx]);
return true;
}
});
estimate.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if ((Boolean) newValue == true) {
formula.setEnabled(true);
} else {
formula.setEnabled(false);
}
return true;
}
});
screen.addPreference(formula);
}
}
Aggregations