use of com.android.settingslib.widget.AppSwitchPreference 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 com.android.settingslib.widget.AppSwitchPreference in project android_packages_apps_Settings by omnirom.
the class DeviceAdminListPreferenceController method refreshUI.
private void refreshUI() {
if (mPreferenceGroup == null) {
return;
}
if (mFooterPreference != null) {
mFooterPreference.setVisible(mAdmins.isEmpty());
}
final Map<String, AppSwitchPreference> preferenceCache = new ArrayMap<>();
final Context prefContext = mPreferenceGroup.getContext();
final int childrenCount = mPreferenceGroup.getPreferenceCount();
for (int i = 0; i < childrenCount; i++) {
final Preference pref = mPreferenceGroup.getPreference(i);
if (!(pref instanceof AppSwitchPreference)) {
continue;
}
final AppSwitchPreference appSwitch = (AppSwitchPreference) pref;
preferenceCache.put(appSwitch.getKey(), appSwitch);
}
for (DeviceAdminListItem item : mAdmins) {
final String key = item.getKey();
AppSwitchPreference pref = preferenceCache.remove(key);
if (pref == null) {
pref = new AppSwitchPreference(prefContext);
mPreferenceGroup.addPreference(pref);
}
bindPreference(item, pref);
}
for (AppSwitchPreference unusedCacheItem : preferenceCache.values()) {
mPreferenceGroup.removePreference(unusedCacheItem);
}
}
Aggregations