Search in sources :

Example 1 with AppPreference

use of com.android.settingslib.widget.apppreference.AppPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class RecentLocationRequestSeeAllPreferenceController method updateState.

@Override
public void updateState(Preference preference) {
    mCategoryAllRecentLocationRequests.removeAll();
    mPreference = preference;
    List<RecentLocationApps.Request> requests = mRecentLocationApps.getAppListSorted(mShowSystem);
    if (requests.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);
        mCategoryAllRecentLocationRequests.addPreference(banner);
    } else {
        for (RecentLocationApps.Request request : requests) {
            Preference appPreference = createAppPreference(preference.getContext(), request);
            mCategoryAllRecentLocationRequests.addPreference(appPreference);
        }
    }
}
Also used : AppPreference(com.android.settingslib.widget.apppreference.AppPreference) Preference(androidx.preference.Preference) AppPreference(com.android.settingslib.widget.apppreference.AppPreference) RecentLocationApps(com.android.settingslib.location.RecentLocationApps)

Example 2 with AppPreference

use of com.android.settingslib.widget.apppreference.AppPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

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.AppPreference) Preference(androidx.preference.Preference) AppPreference(com.android.settingslib.widget.apppreference.AppPreference) UserAppInfo(com.android.settings.applications.UserAppInfo) IconDrawableFactory(android.util.IconDrawableFactory)

Example 3 with AppPreference

use of com.android.settingslib.widget.apppreference.AppPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ZenModeAllBypassingAppsPreferenceController method updateNotificationChannelList.

@VisibleForTesting
void updateNotificationChannelList(List<ApplicationsState.AppEntry> apps) {
    if (mPreferenceScreen == null || apps == null) {
        return;
    }
    List<Preference> channelsBypassingDnd = new ArrayList<>();
    for (ApplicationsState.AppEntry entry : apps) {
        String pkg = entry.info.packageName;
        mApplicationsState.ensureIcon(entry);
        for (NotificationChannel channel : mNotificationBackend.getNotificationChannelsBypassingDnd(pkg, entry.info.uid).getList()) {
            Preference pref = new AppPreference(mPrefContext);
            pref.setKey(pkg + "|" + channel.getId());
            pref.setTitle(BidiFormatter.getInstance().unicodeWrap(entry.label));
            pref.setIcon(entry.icon);
            pref.setSummary(BidiFormatter.getInstance().unicodeWrap(channel.getName()));
            pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

                @Override
                public boolean onPreferenceClick(Preference preference) {
                    Bundle args = new Bundle();
                    args.putString(AppInfoBase.ARG_PACKAGE_NAME, entry.info.packageName);
                    args.putInt(AppInfoBase.ARG_PACKAGE_UID, entry.info.uid);
                    args.putString(Settings.EXTRA_CHANNEL_ID, channel.getId());
                    new SubSettingLauncher(mContext).setDestination(ChannelNotificationSettings.class.getName()).setArguments(args).setTitleRes(R.string.notification_channel_title).setResultListener(mHostFragment, 0).setSourceMetricsCategory(SettingsEnums.NOTIFICATION_ZEN_MODE_OVERRIDING_APP).launch();
                    return true;
                }
            });
            channelsBypassingDnd.add(pref);
        }
        mPreferenceScreen.removeAll();
        if (channelsBypassingDnd.size() > 0) {
            for (Preference prefToAdd : channelsBypassingDnd) {
                mPreferenceScreen.addPreference(prefToAdd);
            }
        }
    }
}
Also used : AppPreference(com.android.settingslib.widget.apppreference.AppPreference) ApplicationsState(com.android.settingslib.applications.ApplicationsState) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) NotificationChannel(android.app.NotificationChannel) AppPreference(com.android.settingslib.widget.apppreference.AppPreference) Preference(androidx.preference.Preference) SubSettingLauncher(com.android.settings.core.SubSettingLauncher) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 4 with AppPreference

use of com.android.settingslib.widget.apppreference.AppPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ZenAccessSettings method reloadList.

private void reloadList() {
    final PreferenceScreen screen = getPreferenceScreen();
    screen.removeAll();
    final ArrayList<ApplicationInfo> apps = new ArrayList<>();
    final Set<String> requesting = ZenAccessController.getPackagesRequestingNotificationPolicyAccess();
    if (!requesting.isEmpty()) {
        final List<ApplicationInfo> installed = mPkgMan.getInstalledApplications(0);
        if (installed != null) {
            for (ApplicationInfo app : installed) {
                if (requesting.contains(app.packageName)) {
                    apps.add(app);
                }
            }
        }
    }
    ArraySet<String> autoApproved = new ArraySet<>();
    autoApproved.addAll(mNoMan.getEnabledNotificationListenerPackages());
    requesting.addAll(autoApproved);
    Collections.sort(apps, new PackageItemInfo.DisplayNameComparator(mPkgMan));
    for (ApplicationInfo app : apps) {
        final String pkg = app.packageName;
        final CharSequence label = app.loadLabel(mPkgMan);
        final AppPreference pref = new AppPreference(getPrefContext());
        pref.setKey(pkg);
        pref.setIcon(app.loadIcon(mPkgMan));
        pref.setTitle(label);
        if (autoApproved.contains(pkg)) {
            // Auto approved, user cannot do anything. Hard code summary and disable preference.
            pref.setEnabled(false);
            pref.setSummary(getString(R.string.zen_access_disabled_package_warning));
        } else {
            // Not auto approved, update summary according to notification backend.
            pref.setSummary(getPreferenceSummary(pkg));
        }
        pref.setOnPreferenceClickListener(preference -> {
            AppInfoBase.startAppInfoFragment(ZenAccessDetails.class, /* fragment */
            R.string.manage_zen_access_title, /* titleRes */
            pkg, app.uid, this, /* source */
            -1, /* requestCode */
            getMetricsCategory());
            return true;
        });
        screen.addPreference(pref);
    }
}
Also used : ArraySet(android.util.ArraySet) PreferenceScreen(androidx.preference.PreferenceScreen) AppPreference(com.android.settingslib.widget.apppreference.AppPreference) ApplicationInfo(android.content.pm.ApplicationInfo) ArrayList(java.util.ArrayList) PackageItemInfo(android.content.pm.PackageItemInfo)

Example 5 with AppPreference

use of com.android.settingslib.widget.apppreference.AppPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class PictureInPictureSettings method onResume.

@Override
public void onResume() {
    super.onResume();
    // Clear the prefs
    final PreferenceScreen screen = getPreferenceScreen();
    screen.removeAll();
    // Fetch the set of applications for each profile which have at least one activity that
    // declare that they support picture-in-picture
    final ArrayList<Pair<ApplicationInfo, Integer>> pipApps = collectPipApps(UserHandle.myUserId());
    Collections.sort(pipApps, new AppComparator(mPackageManager));
    // Rebuild the list of prefs
    final Context prefContext = getPrefContext();
    for (final Pair<ApplicationInfo, Integer> appData : pipApps) {
        final ApplicationInfo appInfo = appData.first;
        final int userId = appData.second;
        final UserHandle user = UserHandle.of(userId);
        final String packageName = appInfo.packageName;
        final CharSequence label = appInfo.loadLabel(mPackageManager);
        final Preference pref = new AppPreference(prefContext);
        pref.setIcon(mIconDrawableFactory.getBadgedIcon(appInfo, userId));
        pref.setTitle(mPackageManager.getUserBadgedLabel(label, user));
        pref.setSummary(PictureInPictureDetails.getPreferenceSummary(prefContext, appInfo.uid, packageName));
        pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                AppInfoBase.startAppInfoFragment(PictureInPictureDetails.class, R.string.picture_in_picture_app_detail_title, packageName, appInfo.uid, PictureInPictureSettings.this, -1, getMetricsCategory());
                return true;
            }
        });
        screen.addPreference(pref);
    }
}
Also used : Context(android.content.Context) PreferenceScreen(androidx.preference.PreferenceScreen) AppPreference(com.android.settingslib.widget.apppreference.AppPreference) ApplicationInfo(android.content.pm.ApplicationInfo) OnPreferenceClickListener(androidx.preference.Preference.OnPreferenceClickListener) AppPreference(com.android.settingslib.widget.apppreference.AppPreference) Preference(androidx.preference.Preference) UserHandle(android.os.UserHandle) Pair(android.util.Pair)

Aggregations

AppPreference (com.android.settingslib.widget.apppreference.AppPreference)7 Preference (androidx.preference.Preference)4 VisibleForTesting (androidx.annotation.VisibleForTesting)3 PreferenceScreen (androidx.preference.PreferenceScreen)3 Context (android.content.Context)2 ApplicationInfo (android.content.pm.ApplicationInfo)2 ArrayList (java.util.ArrayList)2 NotificationChannel (android.app.NotificationChannel)1 PackageItemInfo (android.content.pm.PackageItemInfo)1 Bundle (android.os.Bundle)1 UserHandle (android.os.UserHandle)1 ArraySet (android.util.ArraySet)1 IconDrawableFactory (android.util.IconDrawableFactory)1 Pair (android.util.Pair)1 OnPreferenceClickListener (androidx.preference.Preference.OnPreferenceClickListener)1 UserAppInfo (com.android.settings.applications.UserAppInfo)1 SubSettingLauncher (com.android.settings.core.SubSettingLauncher)1 ApplicationsState (com.android.settingslib.applications.ApplicationsState)1 RecentLocationApps (com.android.settingslib.location.RecentLocationApps)1