Search in sources :

Example 36 with CheckBoxPreference

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);
    }
}
Also used : CheckBoxPreference(androidx.preference.CheckBoxPreference) SwitchPreference(androidx.preference.SwitchPreference) CheckBoxPreference(androidx.preference.CheckBoxPreference) SwitchPreference(androidx.preference.SwitchPreference) Preference(androidx.preference.Preference) ListPreference(androidx.preference.ListPreference) ListPreference(androidx.preference.ListPreference)

Aggregations

CheckBoxPreference (androidx.preference.CheckBoxPreference)36 Test (org.junit.Test)16 NotificationListenerFilter (android.service.notification.NotificationListenerFilter)14 Preference (androidx.preference.Preference)8 ListPreference (androidx.preference.ListPreference)7 Bundle (android.os.Bundle)6 VersionedPackage (android.content.pm.VersionedPackage)4 SparseLongArray (android.util.SparseLongArray)4 AppInfo (com.android.settings.fuelgauge.batterytip.AppInfo)4 AppCheckBoxPreference (com.android.settings.widget.AppCheckBoxPreference)4 Context (android.content.Context)3 SharedPreferences (android.content.SharedPreferences)3 PackageManager (android.content.pm.PackageManager)3 ArraySet (android.util.ArraySet)3 EditTextPreference (androidx.preference.EditTextPreference)3 PreferenceCategory (androidx.preference.PreferenceCategory)3 SeekBarPreference (androidx.preference.SeekBarPreference)3 ArrayList (java.util.ArrayList)3 ApplicationInfo (android.content.pm.ApplicationInfo)2 VisibleForTesting (androidx.annotation.VisibleForTesting)2