Search in sources :

Example 6 with AppPreference

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);
    }
}
Also used : Context(android.content.Context) RecentLocationAccesses(com.android.settingslib.location.RecentLocationAccesses) AppPreference(com.android.settingslib.widget.AppPreference) Preference(androidx.preference.Preference) AppPreference(com.android.settingslib.widget.AppPreference) UserManager(android.os.UserManager) ArrayList(java.util.ArrayList)

Example 7 with AppPreference

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;
}
Also used : AppPreference(com.android.settingslib.widget.AppPreference)

Example 8 with AppPreference

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);
        }
    }
}
Also used : RecentLocationAccesses(com.android.settingslib.location.RecentLocationAccesses) RecentLocationAccessPreferenceController.createAppPreference(com.android.settings.location.RecentLocationAccessPreferenceController.createAppPreference) AppPreference(com.android.settingslib.widget.AppPreference) Preference(androidx.preference.Preference) RecentLocationAccessPreferenceController.createAppPreference(com.android.settings.location.RecentLocationAccessPreferenceController.createAppPreference) AppPreference(com.android.settingslib.widget.AppPreference) UserManager(android.os.UserManager) ArrayList(java.util.ArrayList)

Example 9 with 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);
    }
}
Also used : Context(android.content.Context) PreferenceScreen(androidx.preference.PreferenceScreen) AppPreference(com.android.settingslib.widget.AppPreference) Preference(androidx.preference.Preference) AppPreference(com.android.settingslib.widget.AppPreference) UserAppInfo(com.android.settings.applications.UserAppInfo) IconDrawableFactory(android.util.IconDrawableFactory)

Example 10 with AppPreference

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();
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) AppPreference(com.android.settingslib.widget.AppPreference) Bundle(android.os.Bundle) ServiceInfo(android.content.pm.ServiceInfo) PackageManager(android.content.pm.PackageManager) PreferenceCategory(androidx.preference.PreferenceCategory) SubSettingLauncher(com.android.settings.core.SubSettingLauncher) UserManager(android.os.UserManager) PackageItemInfo(android.content.pm.PackageItemInfo) ComponentName(android.content.ComponentName) NotificationAccessDetails(com.android.settings.applications.specialaccess.notificationaccess.NotificationAccessDetails)

Aggregations

AppPreference (com.android.settingslib.widget.AppPreference)17 Preference (androidx.preference.Preference)10 ArrayList (java.util.ArrayList)7 UserManager (android.os.UserManager)6 Context (android.content.Context)5 PreferenceScreen (androidx.preference.PreferenceScreen)5 ApplicationInfo (android.content.pm.ApplicationInfo)3 Bundle (android.os.Bundle)3 UserHandle (android.os.UserHandle)3 SubSettingLauncher (com.android.settings.core.SubSettingLauncher)3 ApplicationsState (com.android.settingslib.applications.ApplicationsState)3 PackageItemInfo (android.content.pm.PackageItemInfo)2 ServiceInfo (android.content.pm.ServiceInfo)2 Pair (android.util.Pair)2 VisibleForTesting (androidx.annotation.VisibleForTesting)2 OnPreferenceClickListener (androidx.preference.Preference.OnPreferenceClickListener)2 PreferenceCategory (androidx.preference.PreferenceCategory)2 RecentLocationAccesses (com.android.settingslib.location.RecentLocationAccesses)2 RecentLocationApps (com.android.settingslib.location.RecentLocationApps)2 UsageStats (android.app.usage.UsageStats)1