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);
}
}
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);
}
}
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());
}
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);
}
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));
}
}
}
Aggregations