Search in sources :

Example 61 with PreferenceCategory

use of androidx.preference.PreferenceCategory in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AccessibilitySettings method initializePreBundledServicesMapFromArray.

private void initializePreBundledServicesMapFromArray(String categoryKey, int key) {
    String[] services = getResources().getStringArray(key);
    PreferenceCategory category = mCategoryToPrefCategoryMap.get(categoryKey);
    for (int i = 0; i < services.length; i++) {
        ComponentName component = ComponentName.unflattenFromString(services[i]);
        mPreBundledServiceComponentToCategoryMap.put(component, category);
    }
}
Also used : PreferenceCategory(androidx.preference.PreferenceCategory) ComponentName(android.content.ComponentName)

Example 62 with PreferenceCategory

use of androidx.preference.PreferenceCategory in project Resurrection_packages_apps_Settings by ResurrectionRemix.

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.
    // Generate.
    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_AUDIO_AND_CAPTIONS, R.array.config_preinstalled_audio_and_caption_services);
    initializePreBundledServicesMapFromArray(CATEGORY_DISPLAY, R.array.config_preinstalled_display_services);
    initializePreBundledServicesMapFromArray(CATEGORY_INTERACTION_CONTROL, R.array.config_preinstalled_interaction_control_services);
    AccessibilityManager accessibilityManager = AccessibilityManager.getInstance(getActivity());
    List<AccessibilityServiceInfo> installedServices = accessibilityManager.getInstalledAccessibilityServiceList();
    List<AccessibilityServiceInfo> enabledServiceInfos = accessibilityManager.getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_ALL_MASK);
    Set<ComponentName> enabledServices = AccessibilityUtils.getEnabledServicesFromSettings(getActivity());
    List<String> permittedServices = mDpm.getPermittedAccessibilityServices(UserHandle.myUserId());
    PreferenceCategory downloadedServicesCategory = mCategoryToPrefCategoryMap.get(CATEGORY_DOWNLOADED_SERVICES);
    // Temporarily add the downloaded services category back if it was previously removed.
    if (findPreference(CATEGORY_DOWNLOADED_SERVICES) == null) {
        getPreferenceScreen().addPreference(downloadedServicesCategory);
    }
    for (int i = 0, count = installedServices.size(); i < count; ++i) {
        final AccessibilityServiceInfo info = installedServices.get(i);
        final ResolveInfo resolveInfo = info.getResolveInfo();
        final RestrictedPreference preference = new RestrictedPreference(downloadedServicesCategory.getContext());
        final String title = resolveInfo.loadLabel(getPackageManager()).toString();
        Drawable icon;
        if (resolveInfo.getIconResource() == 0) {
            icon = ContextCompat.getDrawable(getContext(), R.drawable.ic_accessibility_generic);
        } else {
            icon = resolveInfo.loadIcon(getPackageManager());
        }
        final ServiceInfo serviceInfo = resolveInfo.serviceInfo;
        final String packageName = serviceInfo.packageName;
        final ComponentName componentName = new ComponentName(packageName, serviceInfo.name);
        preference.setKey(componentName.flattenToString());
        preference.setTitle(title);
        preference.setIconSize(ICON_SIZE_MEDIUM);
        Utils.setSafeIcon(preference, icon);
        final boolean serviceEnabled = enabledServices.contains(componentName);
        String description = info.loadDescription(getPackageManager());
        if (TextUtils.isEmpty(description)) {
            description = getString(R.string.accessibility_service_default_description);
        }
        if (serviceEnabled && AccessibilityUtils.hasServiceCrashed(packageName, serviceInfo.name, enabledServiceInfos)) {
            // Update the summaries for services that have crashed.
            preference.setSummary(R.string.accessibility_summary_state_stopped);
            description = getString(R.string.accessibility_description_state_stopped);
        } else {
            final CharSequence serviceSummary = getServiceSummary(getContext(), info, serviceEnabled);
            preference.setSummary(serviceSummary);
        }
        // Disable all accessibility services that are not permitted.
        final boolean serviceAllowed = permittedServices == null || permittedServices.contains(packageName);
        if (!serviceAllowed && !serviceEnabled) {
            final EnforcedAdmin admin = RestrictedLockUtilsInternal.checkIfAccessibilityServiceDisallowed(getActivity(), packageName, UserHandle.myUserId());
            if (admin != null) {
                preference.setDisabledByAdmin(admin);
            } else {
                preference.setEnabled(false);
            }
        } else {
            preference.setEnabled(true);
        }
        preference.setFragment(ToggleAccessibilityServicePreferenceFragment.class.getName());
        preference.setPersistent(true);
        final Bundle extras = preference.getExtras();
        extras.putString(EXTRA_PREFERENCE_KEY, preference.getKey());
        extras.putBoolean(EXTRA_CHECKED, serviceEnabled);
        extras.putString(EXTRA_TITLE, title);
        extras.putParcelable(EXTRA_RESOLVE_INFO, resolveInfo);
        extras.putString(EXTRA_SUMMARY, description);
        final String settingsClassName = info.getSettingsActivityName();
        if (!TextUtils.isEmpty(settingsClassName)) {
            extras.putString(EXTRA_SETTINGS_TITLE, getString(R.string.accessibility_menu_item_settings));
            extras.putString(EXTRA_SETTINGS_COMPONENT_NAME, new ComponentName(packageName, settingsClassName).flattenToString());
        }
        extras.putParcelable(EXTRA_COMPONENT_NAME, componentName);
        PreferenceCategory prefCategory = downloadedServicesCategory;
        // Set the appropriate category if the service comes pre-installed.
        if (mPreBundledServiceComponentToCategoryMap.containsKey(componentName)) {
            prefCategory = mPreBundledServiceComponentToCategoryMap.get(componentName);
        }
        preference.setOrder(FIRST_PREFERENCE_IN_CATEGORY_INDEX);
        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_AUDIO_AND_CAPTIONS, R.array.config_order_audio_and_caption_services);
    updateCategoryOrderFromArray(CATEGORY_INTERACTION_CONTROL, R.array.config_order_interaction_control_services);
    updateCategoryOrderFromArray(CATEGORY_DISPLAY, R.array.config_order_display_services);
    // If the user has not installed any additional services, hide the category.
    if (downloadedServicesCategory.getPreferenceCount() == 0) {
        final PreferenceScreen screen = getPreferenceScreen();
        screen.removePreference(downloadedServicesCategory);
    }
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) Drawable(android.graphics.drawable.Drawable) EnforcedAdmin(com.android.settingslib.RestrictedLockUtils.EnforcedAdmin) ResolveInfo(android.content.pm.ResolveInfo) AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) ServiceInfo(android.content.pm.ServiceInfo) AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) AccessibilityManager(android.view.accessibility.AccessibilityManager) RestrictedPreference(com.android.settingslib.RestrictedPreference) SwitchPreference(androidx.preference.SwitchPreference) RestrictedPreference(com.android.settingslib.RestrictedPreference) Preference(androidx.preference.Preference) ListPreference(androidx.preference.ListPreference) PreferenceCategory(androidx.preference.PreferenceCategory) ComponentName(android.content.ComponentName)

Example 63 with PreferenceCategory

use of androidx.preference.PreferenceCategory in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AccessibilitySettings method initializeAllPreferences.

private void initializeAllPreferences() {
    for (int i = 0; i < CATEGORIES.length; i++) {
        PreferenceCategory prefCategory = (PreferenceCategory) findPreference(CATEGORIES[i]);
        mCategoryToPrefCategoryMap.put(CATEGORIES[i], prefCategory);
    }
    // Text contrast.
    mToggleHighTextContrastPreference = (SwitchPreference) findPreference(TOGGLE_HIGH_TEXT_CONTRAST_PREFERENCE);
    // Display inversion.
    mToggleInversionPreference = (SwitchPreference) findPreference(TOGGLE_INVERSION_PREFERENCE);
    mInversionPreferenceController = new ColorInversionPreferenceController(getContext(), TOGGLE_INVERSION_PREFERENCE);
    mInversionPreferenceController.displayPreference(getPreferenceScreen());
    // Power button ends calls.
    mTogglePowerButtonEndsCallPreference = (SwitchPreference) findPreference(TOGGLE_POWER_BUTTON_ENDS_CALL_PREFERENCE);
    if (!KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_POWER) || !Utils.isVoiceCapable(getActivity())) {
        mCategoryToPrefCategoryMap.get(CATEGORY_INTERACTION_CONTROL).removePreference(mTogglePowerButtonEndsCallPreference);
    }
    // Lock screen rotation.
    mToggleLockScreenRotationPreference = (SwitchPreference) findPreference(TOGGLE_LOCK_SCREEN_ROTATION_PREFERENCE);
    if (!RotationPolicy.isRotationSupported(getActivity())) {
        mCategoryToPrefCategoryMap.get(CATEGORY_INTERACTION_CONTROL).removePreference(mToggleLockScreenRotationPreference);
    }
    // Large pointer icon.
    mToggleLargePointerIconPreference = (SwitchPreference) findPreference(TOGGLE_LARGE_POINTER_ICON);
    mToggleDisableAnimationsPreference = (SwitchPreference) findPreference(TOGGLE_DISABLE_ANIMATIONS);
    // Master Mono
    mToggleMasterMonoPreference = (SwitchPreference) findPreference(TOGGLE_MASTER_MONO);
    // Long press timeout.
    mSelectLongPressTimeoutPreference = (ListPreference) findPreference(SELECT_LONG_PRESS_TIMEOUT_PREFERENCE);
    mSelectLongPressTimeoutPreference.setOnPreferenceChangeListener(this);
    if (mLongPressTimeoutValueToTitleMap.size() == 0) {
        String[] timeoutValues = getResources().getStringArray(R.array.long_press_timeout_selector_values);
        mLongPressTimeoutDefault = Integer.parseInt(timeoutValues[0]);
        String[] timeoutTitles = getResources().getStringArray(R.array.long_press_timeout_selector_titles);
        final int timeoutValueCount = timeoutValues.length;
        for (int i = 0; i < timeoutValueCount; i++) {
            mLongPressTimeoutValueToTitleMap.put(timeoutValues[i], timeoutTitles[i]);
        }
    }
    // Hearing Aid.
    mHearingAidPreference = findPreference(HEARING_AID_PREFERENCE);
    mHearingAidPreferenceController.displayPreference(getPreferenceScreen());
    // RTT Setting
    mRTTPreference = findPreference(RTT_SETTINGS_SCREEN);
    mRTTSettingPreferenceController.displayPreference(getPreferenceScreen());
    // Captioning.
    mCaptioningPreferenceScreen = findPreference(CAPTIONING_PREFERENCE_SCREEN);
    // Live caption
    mLiveCaptionPreference = findPreference(LIVE_CAPTION_PREFERENCE_KEY);
    mLiveCaptionPreferenceController.displayPreference(getPreferenceScreen());
    // Display magnification.
    mDisplayMagnificationPreferenceScreen = findPreference(DISPLAY_MAGNIFICATION_PREFERENCE_SCREEN);
    configureMagnificationPreferenceIfNeeded(mDisplayMagnificationPreferenceScreen);
    // Font size.
    mFontSizePreferenceScreen = findPreference(FONT_SIZE_PREFERENCE_SCREEN);
    // Autoclick after pointer stops.
    mAutoclickPreferenceScreen = findPreference(AUTOCLICK_PREFERENCE_SCREEN);
    // Display color adjustments.
    mDisplayDaltonizerPreferenceScreen = findPreference(DISPLAY_DALTONIZER_PREFERENCE_SCREEN);
    // Accessibility shortcut.
    mAccessibilityShortcutPreferenceScreen = findPreference(ACCESSIBILITY_SHORTCUT_PREFERENCE);
    // Vibrations.
    mVibrationPreferenceScreen = findPreference(VIBRATION_PREFERENCE_SCREEN);
    // Dark Mode.
    mDarkUIModePreference = findPreference(DARK_UI_MODE_PREFERENCE);
    mDarkUIPreferenceController = new DarkUIPreferenceController(getContext(), DARK_UI_MODE_PREFERENCE);
    mDarkUIPreferenceController.setParentFragment(this);
    mDarkUIPreferenceController.displayPreference(getPreferenceScreen());
}
Also used : DarkUIPreferenceController(com.android.settings.display.DarkUIPreferenceController) PreferenceCategory(androidx.preference.PreferenceCategory)

Example 64 with PreferenceCategory

use of androidx.preference.PreferenceCategory in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class WifiCallingPreferenceControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(RuntimeEnvironment.application);
    when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
    when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
    when(mTelephonyManager.createForSubscriptionId(SUB_ID)).thenReturn(mTelephonyManager);
    mPreference = new Preference(mContext);
    mController = new WifiCallingPreferenceController(mContext, "wifi_calling");
    mController.mCarrierConfigManager = mCarrierConfigManager;
    mController.init(SUB_ID);
    mController.mImsManager = mImsManager;
    mPreference.setKey(mController.getPreferenceKey());
    mCarrierConfig = new PersistableBundle();
    when(mCarrierConfigManager.getConfigForSubId(SUB_ID)).thenReturn(mCarrierConfig);
    mPreferenceCategory = new PreferenceCategory(mContext);
    when(mPreferenceScreen.findPreference(WifiCallingPreferenceController.KEY_PREFERENCE_CATEGORY)).thenReturn(mPreferenceCategory);
    when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
}
Also used : PersistableBundle(android.os.PersistableBundle) Preference(androidx.preference.Preference) PreferenceCategory(androidx.preference.PreferenceCategory) Before(org.junit.Before)

Example 65 with PreferenceCategory

use of androidx.preference.PreferenceCategory in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class EnterpriseSetDefaultAppsListPreferenceController method updateUi.

private void updateUi() {
    final Context prefContext = mParent.getPreferenceManager().getContext();
    final PreferenceScreen screen = mParent.getPreferenceScreen();
    if (screen == null) {
        return;
    }
    if (!mEnterprisePrivacyFeatureProvider.isInCompMode() && mUsers.size() == 1) {
        createPreferences(prefContext, screen, mApps.get(0));
    } else {
        for (int i = 0; i < mUsers.size(); i++) {
            final UserInfo userInfo = mUsers.get(i);
            final PreferenceCategory category = new PreferenceCategory(prefContext);
            screen.addPreference(category);
            if (userInfo.isManagedProfile()) {
                category.setTitle(R.string.managed_device_admin_title);
            } else {
                category.setTitle(R.string.personal_device_admin_title);
            }
            category.setOrder(i);
            createPreferences(prefContext, category, mApps.get(i));
        }
    }
}
Also used : Context(android.content.Context) PreferenceScreen(androidx.preference.PreferenceScreen) PreferenceCategory(androidx.preference.PreferenceCategory) UserInfo(android.content.pm.UserInfo)

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