Search in sources :

Example 11 with CheckBoxPreference

use of androidx.preference.CheckBoxPreference in project android_packages_apps_Settings by omnirom.

the class TypeFilterPreferenceController method updateState.

@Override
public void updateState(Preference pref) {
    mNlf = mNm.getListenerFilter(mCn, mUserId);
    CheckBoxPreference check = (CheckBoxPreference) pref;
    check.setChecked(hasFlag(mNlf.getTypes(), getType()));
    boolean disableRequestedByApp = false;
    if (mSi != null) {
        if (mSi.metaData != null && mSi.metaData.containsKey(NotificationListenerService.META_DATA_DISABLED_FILTER_TYPES)) {
            String typeList = mSi.metaData.get(NotificationListenerService.META_DATA_DISABLED_FILTER_TYPES).toString();
            if (typeList != null) {
                int types = 0;
                String[] typeStrings = typeList.split(FLAG_SEPARATOR);
                for (int i = 0; i < typeStrings.length; i++) {
                    final String typeString = typeStrings[i];
                    if (TextUtils.isEmpty(typeString)) {
                        continue;
                    }
                    if (typeString.equalsIgnoreCase("ONGOING")) {
                        types |= FLAG_FILTER_TYPE_ONGOING;
                    } else if (typeString.equalsIgnoreCase("CONVERSATIONS")) {
                        types |= FLAG_FILTER_TYPE_CONVERSATIONS;
                    } else if (typeString.equalsIgnoreCase("SILENT")) {
                        types |= FLAG_FILTER_TYPE_SILENT;
                    } else if (typeString.equalsIgnoreCase("ALERTING")) {
                        types |= FLAG_FILTER_TYPE_ALERTING;
                    } else {
                        try {
                            types |= Integer.parseInt(typeString);
                        } catch (NumberFormatException e) {
                        // skip
                        }
                    }
                }
                if (hasFlag(types, getType())) {
                    disableRequestedByApp = true;
                }
            }
        }
    }
    // Apps can prevent a category from being turned on, but not turned off
    boolean disabledByApp = disableRequestedByApp && !check.isChecked();
    pref.setEnabled(getAvailabilityStatus() == AVAILABLE && !disabledByApp);
}
Also used : CheckBoxPreference(androidx.preference.CheckBoxPreference)

Example 12 with CheckBoxPreference

use of androidx.preference.CheckBoxPreference in project android_packages_apps_Settings by omnirom.

the class RestrictedAppDetails method onBatteryTipHandled.

@Override
public void onBatteryTipHandled(BatteryTip batteryTip) {
    final AppInfo appInfo;
    final boolean isRestricted = batteryTip instanceof RestrictAppTip;
    if (isRestricted) {
        appInfo = ((RestrictAppTip) batteryTip).getRestrictAppList().get(0);
    } else {
        appInfo = ((UnrestrictAppTip) batteryTip).getUnrestrictAppInfo();
    }
    CheckBoxPreference preference = (CheckBoxPreference) mRestrictedAppListGroup.findPreference(getKeyFromAppInfo(appInfo));
    if (preference != null) {
        preference.setChecked(isRestricted);
    }
}
Also used : CheckBoxPreference(androidx.preference.CheckBoxPreference) AppCheckBoxPreference(com.android.settings.widget.AppCheckBoxPreference) RestrictAppTip(com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip) AppInfo(com.android.settings.fuelgauge.batterytip.AppInfo)

Example 13 with CheckBoxPreference

use of androidx.preference.CheckBoxPreference in project openScale by oliexdev.

the class ReminderPreferences method onCreatePreferences.

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    setPreferencesFromResource(R.xml.reminder_preferences, rootKey);
    setHasOptionsMenu(true);
    reminderEnable = (CheckBoxPreference) findPreference(PREFERENCE_KEY_REMINDER_ENABLE);
    final MultiSelectListPreference prefDays = findPreference("reminderWeekdays");
    prefDays.setSummaryProvider(new Preference.SummaryProvider<MultiSelectListPreference>() {

        @Override
        public CharSequence provideSummary(MultiSelectListPreference preference) {
            final String[] values = getResources().getStringArray(R.array.weekdays_values);
            final String[] translated = getResources().getStringArray(R.array.weekdays_entries);
            return IntStream.range(0, values.length).mapToObj(i -> new Pair<>(values[i], translated[i])).filter(p -> preference.getValues().contains(p.first)).map(p -> p.second).collect(Collectors.joining(", "));
        }
    });
    updateAlarmPreferences();
}
Also used : IntStream(java.util.stream.IntStream) Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) ComponentName(android.content.ComponentName) Pair(android.util.Pair) Preference(androidx.preference.Preference) PreferenceFragmentCompat(androidx.preference.PreferenceFragmentCompat) Collectors(java.util.stream.Collectors) ReminderBootReceiver(com.health.openscale.core.alarm.ReminderBootReceiver) CheckBoxPreference(androidx.preference.CheckBoxPreference) SharedPreferences(android.content.SharedPreferences) MultiSelectListPreference(androidx.preference.MultiSelectListPreference) MenuInflater(android.view.MenuInflater) Menu(android.view.Menu) AlarmHandler(com.health.openscale.core.alarm.AlarmHandler) R(com.health.openscale.R) DialogFragment(androidx.fragment.app.DialogFragment) Preference(androidx.preference.Preference) CheckBoxPreference(androidx.preference.CheckBoxPreference) MultiSelectListPreference(androidx.preference.MultiSelectListPreference) MultiSelectListPreference(androidx.preference.MultiSelectListPreference)

Example 14 with CheckBoxPreference

use of androidx.preference.CheckBoxPreference in project openScale by oliexdev.

the class AboutPreferences method onCreatePreferences.

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    setPreferencesFromResource(R.xml.about_preferences, rootKey);
    setHasOptionsMenu(true);
    findPreference(KEY_APP_VERSION).setSummary(String.format("v%s (%d)", BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE));
    debugLog = (CheckBoxPreference) findPreference(KEY_DEBUG_LOG);
    debugLog.setChecked(getEnabledFileDebugTree() != null);
    debugLog.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (debugLog.isChecked()) {
                DateFormat format = new SimpleDateFormat("yyyy-MM-dd_HH-mm");
                String fileName = String.format("openScale_%s.txt", format.format(new Date()));
                Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
                intent.addCategory(Intent.CATEGORY_OPENABLE);
                intent.setType("text/plain");
                intent.putExtra(Intent.EXTRA_TITLE, fileName);
                startActivityForResult(intent, DEBUG_LOG_REQUEST);
            } else {
                FileDebugTree tree = getEnabledFileDebugTree();
                if (tree != null) {
                    Timber.d("Debug log disabled");
                    Timber.uproot(tree);
                    tree.close();
                    OpenScale.DEBUG_MODE = false;
                }
            }
            return true;
        }
    });
}
Also used : Preference(androidx.preference.Preference) CheckBoxPreference(androidx.preference.CheckBoxPreference) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Intent(android.content.Intent) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 15 with CheckBoxPreference

use of androidx.preference.CheckBoxPreference in project RespawnIRC-Android by FranckRJ.

the class SettingsFragment method updatePrefDefaultValue.

/* Le but de la clef temporaire est de ne pas sauvegarder l'option par défaut si c'est celle ci
     * qui est retourné par "PrefsManager.getX()". La clef temporaire n'est pas vide pour empêcher
     * des possibles crash (des histoires de requireKey() etc). Elle est unique par type de pref pour
     * ne pas causer de crash lors de l'assignation d'un string à ce qui était précédement un bool.
     * La persistance est temporairement à false pour plus de sécurité, au cas où, dans le doute,
     * mais ça reste plutôt assez moche comme solution au final. */
private static void updatePrefDefaultValue(Preference pref) {
    String realPrefKey = pref.getKey();
    pref.setPersistent(false);
    if (pref instanceof CheckBoxPreference) {
        pref.setKey("tmpKeyBool");
        CheckBoxPreference checkBoxPref = (CheckBoxPreference) pref;
        checkBoxPref.setChecked(PrefsManager.getBool(realPrefKey));
    } else if (pref instanceof SwitchPreferenceCompat) {
        pref.setKey("tmpKeyBool");
        SwitchPreferenceCompat switchPref = (SwitchPreferenceCompat) pref;
        switchPref.setChecked(PrefsManager.getBool(realPrefKey));
    } else if (pref instanceof EditTextPreference) {
        pref.setKey("tmpKeyString");
        EditTextPreference editTextPref = (EditTextPreference) pref;
        editTextPref.setText(PrefsManager.getString(realPrefKey));
    } else if (pref instanceof ListPreference) {
        pref.setKey("tmpKeyString");
        ListPreference listPref = (ListPreference) pref;
        listPref.setValue(PrefsManager.getString(realPrefKey));
    }
    pref.setPersistent(true);
    pref.setKey(realPrefKey);
}
Also used : CheckBoxPreference(androidx.preference.CheckBoxPreference) SwitchPreferenceCompat(androidx.preference.SwitchPreferenceCompat) EditTextPreference(com.takisoft.preferencex.EditTextPreference) 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