Search in sources :

Example 76 with PreferenceCategory

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

the class TextAndDisplayFragment method updateSystemPreferences.

/**
 * Updates preferences related to system configurations.
 */
private void updateSystemPreferences() {
    final PreferenceCategory experimentalCategory = getPreferenceScreen().findPreference(CATEGORY_EXPERIMENTAL);
    if (ColorDisplayManager.isColorTransformAccelerated(getContext())) {
        mDisplayDaltonizerPreferenceScreen.setSummary(AccessibilityUtil.getSummary(getContext(), Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED));
        getPreferenceScreen().removePreference(experimentalCategory);
    } else {
        // Move following preferences to experimental category if device don't supports HWC
        // hardware-accelerated color transform.
        getPreferenceScreen().removePreference(mDisplayDaltonizerPreferenceScreen);
        getPreferenceScreen().removePreference(mToggleDisableAnimationsPreference);
        getPreferenceScreen().removePreference(mToggleLargePointerIconPreference);
        experimentalCategory.addPreference(mDisplayDaltonizerPreferenceScreen);
        experimentalCategory.addPreference(mToggleDisableAnimationsPreference);
        experimentalCategory.addPreference(mToggleLargePointerIconPreference);
    }
}
Also used : PreferenceCategory(androidx.preference.PreferenceCategory)

Example 77 with PreferenceCategory

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

the class AccessibilityShortcutPreferenceFragment method initGeneralCategory.

@VisibleForTesting
void initGeneralCategory() {
    final PreferenceCategory generalCategory = new PreferenceCategory(getPrefContext());
    generalCategory.setKey(KEY_GENERAL_CATEGORY);
    generalCategory.setTitle(getGeneralCategoryDescription(null));
    getPreferenceScreen().addPreference(generalCategory);
}
Also used : PreferenceCategory(androidx.preference.PreferenceCategory) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 78 with PreferenceCategory

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

the class AccessibilitySettings method updatePreferenceCategoryVisibility.

/**
 * Updates the visibility of a category according to its child preference count.
 *
 * @param categoryKey The key of the category which needs to check
 */
private void updatePreferenceCategoryVisibility(String categoryKey) {
    final PreferenceCategory category = mCategoryToPrefCategoryMap.get(categoryKey);
    category.setVisible(category.getPreferenceCount() != 0);
}
Also used : PreferenceCategory(androidx.preference.PreferenceCategory)

Example 79 with PreferenceCategory

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

the class AccessibilitySettings method updateServicePreferences.

protected void updateServicePreferences() {
    // Since services category is auto generated we have to do a pass
    // to generate it since services can come and go and then based on
    // the global accessibility state to decided whether it is enabled.
    final ArrayList<Preference> servicePreferences = new ArrayList<>(mServicePreferenceToPreferenceCategoryMap.keySet());
    for (int i = 0; i < servicePreferences.size(); i++) {
        Preference service = servicePreferences.get(i);
        PreferenceCategory category = mServicePreferenceToPreferenceCategoryMap.get(service);
        category.removePreference(service);
    }
    initializePreBundledServicesMapFromArray(CATEGORY_SCREEN_READER, R.array.config_preinstalled_screen_reader_services);
    initializePreBundledServicesMapFromArray(CATEGORY_CAPTIONS, R.array.config_preinstalled_captions_services);
    initializePreBundledServicesMapFromArray(CATEGORY_AUDIO, R.array.config_preinstalled_audio_services);
    initializePreBundledServicesMapFromArray(CATEGORY_DISPLAY, R.array.config_preinstalled_display_services);
    initializePreBundledServicesMapFromArray(CATEGORY_INTERACTION_CONTROL, R.array.config_preinstalled_interaction_control_services);
    final List<RestrictedPreference> preferenceList = getInstalledAccessibilityList(getPrefContext());
    final PreferenceCategory downloadedServicesCategory = mCategoryToPrefCategoryMap.get(CATEGORY_DOWNLOADED_SERVICES);
    for (int i = 0, count = preferenceList.size(); i < count; ++i) {
        final RestrictedPreference preference = preferenceList.get(i);
        final ComponentName componentName = preference.getExtras().getParcelable(EXTRA_COMPONENT_NAME);
        PreferenceCategory prefCategory = downloadedServicesCategory;
        // Set the appropriate category if the service comes pre-installed.
        if (mPreBundledServiceComponentToCategoryMap.containsKey(componentName)) {
            prefCategory = mPreBundledServiceComponentToCategoryMap.get(componentName);
        }
        prefCategory.addPreference(preference);
        mServicePreferenceToPreferenceCategoryMap.put(preference, prefCategory);
    }
    // Update the order of all the category according to the order defined in xml file.
    updateCategoryOrderFromArray(CATEGORY_SCREEN_READER, R.array.config_order_screen_reader_services);
    updateCategoryOrderFromArray(CATEGORY_CAPTIONS, R.array.config_order_captions_services);
    updateCategoryOrderFromArray(CATEGORY_AUDIO, R.array.config_order_audio_services);
    updateCategoryOrderFromArray(CATEGORY_INTERACTION_CONTROL, R.array.config_order_interaction_control_services);
    updateCategoryOrderFromArray(CATEGORY_DISPLAY, R.array.config_order_display_services);
    // Need to check each time when updateServicePreferences() called.
    if (downloadedServicesCategory.getPreferenceCount() == 0) {
        getPreferenceScreen().removePreference(downloadedServicesCategory);
    } else {
        getPreferenceScreen().addPreference(downloadedServicesCategory);
    }
    // Hide screen reader category if it is empty.
    updatePreferenceCategoryVisibility(CATEGORY_SCREEN_READER);
}
Also used : RestrictedPreference(com.android.settingslib.RestrictedPreference) RestrictedPreference(com.android.settingslib.RestrictedPreference) Preference(androidx.preference.Preference) PreferenceCategory(androidx.preference.PreferenceCategory) ArrayList(java.util.ArrayList) ComponentName(android.content.ComponentName)

Example 80 with PreferenceCategory

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

the class ChannelListPreferenceController method updateGroupList.

private void updateGroupList(@NonNull PreferenceCategory groupPrefsList, @NonNull List<NotificationChannelGroup> channelGroups) {
    // Update the list, but optimize for the most common case where the list hasn't changed.
    int numFinalGroups = channelGroups.size();
    int initialPrefCount = groupPrefsList.getPreferenceCount();
    List<PreferenceCategory> finalOrderedGroups = new ArrayList<>(numFinalGroups);
    for (int i = 0; i < numFinalGroups; i++) {
        NotificationChannelGroup group = channelGroups.get(i);
        PreferenceCategory groupCategory = findOrCreateGroupCategoryForKey(groupPrefsList, group.getId(), i);
        finalOrderedGroups.add(groupCategory);
        updateGroupPreferences(group, groupCategory);
    }
    int postAddPrefCount = groupPrefsList.getPreferenceCount();
    // If any groups were inserted (into a non-empty list) or need to be removed, we need to
    // remove all groups and re-add them all.
    // This is required to ensure proper ordering of inserted groups, and it simplifies logic
    // at the cost of computation in the rare case that the list is changing.
    boolean hasInsertions = initialPrefCount != 0 && initialPrefCount != numFinalGroups;
    boolean requiresRemoval = postAddPrefCount != numFinalGroups;
    if (hasInsertions || requiresRemoval) {
        groupPrefsList.removeAll();
        for (PreferenceCategory group : finalOrderedGroups) {
            groupPrefsList.addPreference(group);
        }
    }
}
Also used : NotificationChannelGroup(android.app.NotificationChannelGroup) PreferenceCategory(androidx.preference.PreferenceCategory) ArrayList(java.util.ArrayList)

Aggregations

PreferenceCategory (androidx.preference.PreferenceCategory)111 Preference (androidx.preference.Preference)38 PreferenceManager (androidx.preference.PreferenceManager)24 Before (org.junit.Before)24 PreferenceScreen (androidx.preference.PreferenceScreen)22 Test (org.junit.Test)19 SwitchPreference (androidx.preference.SwitchPreference)13 NotificationChannel (android.app.NotificationChannel)11 ArrayList (java.util.ArrayList)11 NotificationChannelGroup (android.app.NotificationChannelGroup)9 ShortcutInfo (android.content.pm.ShortcutInfo)9 Context (android.content.Context)8 ConversationChannel (android.app.people.ConversationChannel)7 View (android.view.View)7 PreferenceViewHolder (androidx.preference.PreferenceViewHolder)7 Lifecycle (com.android.settingslib.core.lifecycle.Lifecycle)7 ListPreference (androidx.preference.ListPreference)6 ComponentName (android.content.ComponentName)5 ContentResolver (android.content.ContentResolver)5 Bundle (android.os.Bundle)5