use of androidx.preference.PreferenceScreen in project android_packages_apps_Settings by omnirom.
the class UserSettings method onResume.
@Override
public void onResume() {
super.onResume();
if (!mUserCaps.mEnabled) {
return;
}
final PreferenceScreen screen = getPreferenceScreen();
mAddUserWhenLockedPreferenceController.updateState(screen.findPreference(mAddUserWhenLockedPreferenceController.getPreferenceKey()));
if (mShouldUpdateUserList) {
updateUI();
}
}
use of androidx.preference.PreferenceScreen in project android_packages_apps_Settings by omnirom.
the class ManagedServiceSettings method updateList.
private void updateList(List<ServiceInfo> services) {
UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
final int managedProfileId = Utils.getManagedProfileId(um, UserHandle.myUserId());
final PreferenceScreen screen = getPreferenceScreen();
screen.removeAll();
services.sort(new PackageItemInfo.DisplayNameComparator(mPm));
for (ServiceInfo service : services) {
final ComponentName cn = new ComponentName(service.packageName, service.name);
CharSequence title = null;
try {
title = mPm.getApplicationInfoAsUser(service.packageName, 0, UserHandle.myUserId()).loadLabel(mPm);
} catch (PackageManager.NameNotFoundException e) {
// unlikely, as we are iterating over live services.
Log.e(TAG, "can't find package name", e);
}
final CharSequence finalTitle = title;
final String summary = service.loadLabel(mPm).toString();
final SwitchPreference pref = new AppSwitchPreference(getPrefContext());
pref.setPersistent(false);
pref.setIcon(mIconDrawableFactory.getBadgedIcon(service, service.applicationInfo, UserHandle.getUserId(service.applicationInfo.uid)));
if (title != null && !title.equals(summary)) {
pref.setTitle(title);
pref.setSummary(summary);
} else {
pref.setTitle(summary);
}
pref.setKey(cn.flattenToString());
pref.setChecked(isServiceEnabled(cn));
if (managedProfileId != UserHandle.USER_NULL && !mDpm.isNotificationListenerServicePermitted(service.packageName, managedProfileId)) {
pref.setSummary(R.string.work_profile_notification_access_blocked_summary);
}
pref.setOnPreferenceChangeListener((preference, newValue) -> {
final boolean enable = (boolean) newValue;
if (finalTitle != null) {
return setEnabled(cn, finalTitle.toString(), enable);
} else {
return setEnabled(cn, null, enable);
}
});
pref.setKey(cn.flattenToString());
screen.addPreference(pref);
}
highlightPreferenceIfNeeded();
}
use of androidx.preference.PreferenceScreen in project android_packages_apps_Settings by omnirom.
the class TopLevelSettings method onCreatePreferences.
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
super.onCreatePreferences(savedInstanceState, rootKey);
final PreferenceScreen screen = getPreferenceScreen();
if (screen == null) {
return;
}
// Tint the homepage icons
final int tintColor = Utils.getHomepageIconColor(getContext());
final int count = screen.getPreferenceCount();
for (int i = 0; i < count; i++) {
final Preference preference = screen.getPreference(i);
if (preference == null) {
break;
}
final Drawable icon = preference.getIcon();
if (icon != null) {
icon.setTint(tintColor);
}
}
}
use of androidx.preference.PreferenceScreen in project android_packages_apps_Settings by omnirom.
the class ScreenPinningSettings method onActivityCreated.
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final SettingsActivity activity = (SettingsActivity) getActivity();
activity.setTitle(R.string.screen_pinning_title);
mLockPatternUtils = new LockPatternUtils(activity);
mUserManager = activity.getSystemService(UserManager.class);
addPreferencesFromResource(R.xml.screen_pinning_settings);
final PreferenceScreen root = getPreferenceScreen();
mUseScreenLock = root.findPreference(KEY_USE_SCREEN_LOCK);
mFooterPreference = root.findPreference(KEY_FOOTER);
mSwitchBar = activity.getSwitchBar();
mSwitchBar.setTitle(getContext().getString(R.string.app_pinning_main_switch_title));
mSwitchBar.show();
mSwitchBar.setChecked(isLockToAppEnabled(getActivity()));
mSwitchBar.addOnSwitchChangeListener(this);
updateDisplay();
}
use of androidx.preference.PreferenceScreen in project android_packages_apps_Settings by omnirom.
the class BasePreferenceControllerTest method settingAvailable_disabledOnDisplayPreference_preferenceEnabled.
@Test
public void settingAvailable_disabledOnDisplayPreference_preferenceEnabled() {
final PreferenceScreen screen = mock(PreferenceScreen.class);
final Preference preference = new Preference(mContext);
preference.setEnabled(true);
when(screen.findPreference(anyString())).thenReturn(preference);
mPreferenceController.displayPreference(screen);
assertThat(preference.isEnabled()).isTrue();
}
Aggregations