use of com.android.settingslib.widget.AppPreference in project android_packages_apps_Settings by omnirom.
the class RecentLocationAccessPreferenceController method displayPreference.
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mCategoryRecentLocationRequests = screen.findPreference(getPreferenceKey());
final Context prefContext = mCategoryRecentLocationRequests.getContext();
final List<RecentLocationAccesses.Access> recentLocationAccesses = new ArrayList<>();
final UserManager userManager = UserManager.get(mContext);
for (RecentLocationAccesses.Access access : mRecentLocationApps.getAppListSorted(/* showSystemApps= */
false)) {
if (isRequestMatchesProfileType(userManager, access, mType)) {
recentLocationAccesses.add(access);
if (recentLocationAccesses.size() == MAX_APPS) {
break;
}
}
}
if (recentLocationAccesses.size() > 0) {
// Add preferences to container in original order (already sorted by recency).
for (RecentLocationAccesses.Access access : recentLocationAccesses) {
mCategoryRecentLocationRequests.addPreference(createAppPreference(prefContext, access, mFragment));
}
} else {
// If there's no item to display, add a "No recent apps" item.
final Preference banner = new AppPreference(prefContext);
banner.setTitle(R.string.location_no_recent_accesses);
banner.setSelectable(false);
mCategoryRecentLocationRequests.addPreference(banner);
}
}
use of com.android.settingslib.widget.AppPreference in project android_packages_apps_Settings by omnirom.
the class RecentLocationRequestPreferenceController method createAppPreference.
/**
* Create a {@link AppPreference}
*/
public static AppPreference createAppPreference(Context prefContext, RecentLocationApps.Request request, DashboardFragment fragment) {
final AppPreference pref = new AppPreference(prefContext);
pref.setIcon(request.icon);
pref.setTitle(request.label);
pref.setOnPreferenceClickListener(new PackageEntryClickedListener(fragment, request.packageName, request.userHandle));
return pref;
}
use of com.android.settingslib.widget.AppPreference in project android_packages_apps_Settings by omnirom.
the class RecentLocationAccessSeeAllPreferenceController method updateState.
@Override
public void updateState(Preference preference) {
mCategoryAllRecentLocationAccess.removeAll();
mPreference = preference;
final UserManager userManager = UserManager.get(mContext);
final List<RecentLocationAccesses.Access> recentLocationAccesses = new ArrayList<>();
for (RecentLocationAccesses.Access access : mRecentLocationAccesses.getAppListSorted(mShowSystem)) {
if (isRequestMatchesProfileType(userManager, access, mType)) {
recentLocationAccesses.add(access);
}
}
if (recentLocationAccesses.isEmpty()) {
// If there's no item to display, add a "No recent apps" item.
final Preference banner = new AppPreference(mContext);
banner.setTitle(R.string.location_no_recent_apps);
banner.setSelectable(false);
mCategoryAllRecentLocationAccess.addPreference(banner);
} else {
for (RecentLocationAccesses.Access request : recentLocationAccesses) {
final Preference appPreference = createAppPreference(preference.getContext(), request, mFragment);
mCategoryAllRecentLocationAccess.addPreference(appPreference);
}
}
}
use of com.android.settingslib.widget.AppPreference in project android_packages_apps_Settings by omnirom.
the class ApplicationListPreferenceController method onListOfAppsResult.
@Override
public void onListOfAppsResult(List<UserAppInfo> result) {
final PreferenceScreen screen = mParent.getPreferenceScreen();
if (screen == null) {
return;
}
final IconDrawableFactory iconDrawableFactory = IconDrawableFactory.newInstance(mContext);
final Context prefContext = mParent.getPreferenceManager().getContext();
for (int position = 0; position < result.size(); position++) {
final UserAppInfo item = result.get(position);
final Preference preference = new AppPreference(prefContext);
preference.setTitle(item.appInfo.loadLabel(mPm));
preference.setIcon(iconDrawableFactory.getBadgedIcon(item.appInfo));
preference.setOrder(position);
preference.setSelectable(false);
screen.addPreference(preference);
}
}
use of com.android.settingslib.widget.AppPreference in project android_packages_apps_Settings by omnirom.
the class NotificationAccessSettings method updateList.
private void updateList(List<ServiceInfo> services) {
final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
final int managedProfileId = Utils.getManagedProfileId(um, UserHandle.myUserId());
final PreferenceScreen screen = getPreferenceScreen();
final PreferenceCategory allowedCategory = screen.findPreference(ALLOWED_KEY);
allowedCategory.removeAll();
final PreferenceCategory notAllowedCategory = screen.findPreference(NOT_ALLOWED_KEY);
notAllowedCategory.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 AppPreference pref = new AppPreference(getPrefContext());
pref.setTitle(title);
pref.setIcon(mIconDrawableFactory.getBadgedIcon(service, service.applicationInfo, UserHandle.getUserId(service.applicationInfo.uid)));
pref.setKey(cn.flattenToString());
pref.setSummary(mBackend.getDeviceList(ICompanionDeviceManager.Stub.asInterface(ServiceManager.getService(Context.COMPANION_DEVICE_SERVICE)), com.android.settings.bluetooth.Utils.getLocalBtManager(mContext), service.packageName, UserHandle.myUserId()));
if (managedProfileId != UserHandle.USER_NULL && !mDpm.isNotificationListenerServicePermitted(service.packageName, managedProfileId)) {
pref.setSummary(R.string.work_profile_notification_access_blocked_summary);
}
pref.setOnPreferenceClickListener(preference -> {
final Bundle args = new Bundle();
args.putString(AppInfoBase.ARG_PACKAGE_NAME, cn.getPackageName());
args.putInt(AppInfoBase.ARG_PACKAGE_UID, service.applicationInfo.uid);
Bundle extras = new Bundle();
extras.putString(Settings.EXTRA_NOTIFICATION_LISTENER_COMPONENT_NAME, cn.flattenToString());
new SubSettingLauncher(getContext()).setDestination(NotificationAccessDetails.class.getName()).setSourceMetricsCategory(getMetricsCategory()).setTitleRes(R.string.manage_notification_access_title).setArguments(args).setExtras(extras).setUserHandle(UserHandle.getUserHandleForUid(service.applicationInfo.uid)).launch();
return true;
});
pref.setKey(cn.flattenToString());
if (mNm.isNotificationListenerAccessGranted(cn)) {
allowedCategory.addPreference(pref);
} else {
notAllowedCategory.addPreference(pref);
}
}
highlightPreferenceIfNeeded();
}
Aggregations