Search in sources :

Example 1 with AppPreference

use of com.android.settingslib.widget.AppPreference in project android_packages_apps_Settings by omnirom.

the class InteractAcrossProfilesSettings method onResume.

@Override
public void onResume() {
    super.onResume();
    final PreferenceScreen screen = getPreferenceScreen();
    screen.removeAll();
    final ArrayList<Pair<ApplicationInfo, UserHandle>> crossProfileApps = collectConfigurableApps(mPackageManager, mUserManager, mCrossProfileApps);
    final Context prefContext = getPrefContext();
    for (final Pair<ApplicationInfo, UserHandle> appData : crossProfileApps) {
        final ApplicationInfo appInfo = appData.first;
        final UserHandle user = appData.second;
        final String packageName = appInfo.packageName;
        final CharSequence label = appInfo.loadLabel(mPackageManager);
        final Preference pref = new AppPreference(prefContext);
        pref.setIcon(mIconDrawableFactory.getBadgedIcon(appInfo, user.getIdentifier()));
        pref.setTitle(mPackageManager.getUserBadgedLabel(label, user));
        pref.setSummary(InteractAcrossProfilesDetails.getPreferenceSummary(prefContext, packageName));
        pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

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

Example 2 with AppPreference

use of com.android.settingslib.widget.AppPreference in project android_packages_apps_Settings by omnirom.

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) ApplicationInfo(android.content.pm.ApplicationInfo) OnPreferenceClickListener(androidx.preference.Preference.OnPreferenceClickListener) AppPreference(com.android.settingslib.widget.AppPreference) Preference(androidx.preference.Preference) UserHandle(android.os.UserHandle) Pair(android.util.Pair)

Example 3 with AppPreference

use of com.android.settingslib.widget.AppPreference in project android_packages_apps_Settings by omnirom.

the class ZenAccessSettings method reloadList.

private void reloadList() {
    if (mContext.getSystemService(UserManager.class).isManagedProfile(UserHandle.myUserId())) {
        Log.w(TAG, "DND access cannot be enabled in a work profile");
        return;
    }
    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());
    autoApproved.addAll(ZenAccessController.getPackagesWithManageNotifications());
    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) ApplicationInfo(android.content.pm.ApplicationInfo) ArrayList(java.util.ArrayList) UserManager(android.os.UserManager) PackageItemInfo(android.content.pm.PackageItemInfo)

Example 4 with AppPreference

use of com.android.settingslib.widget.AppPreference in project android_packages_apps_Settings by omnirom.

the class ConversationListPreferenceController method createConversationPref.

protected Preference createConversationPref(final ConversationChannelWrapper conversation, int order) {
    AppPreference pref = new AppPreference(mContext);
    pref.setOrder(order);
    pref.setTitle(getTitle(conversation));
    pref.setSummary(getSummary(conversation));
    pref.setIcon(mBackend.getConversationDrawable(mContext, conversation.getShortcutInfo(), conversation.getPkg(), conversation.getUid(), conversation.getNotificationChannel().isImportantConversation()));
    pref.setKey(conversation.getNotificationChannel().getId());
    pref.setOnPreferenceClickListener(preference -> {
        getSubSettingLauncher(conversation, pref.getTitle()).launch();
        return true;
    });
    return pref;
}
Also used : AppPreference(com.android.settingslib.widget.AppPreference)

Example 5 with AppPreference

use of com.android.settingslib.widget.AppPreference in project android_packages_apps_Settings by omnirom.

the class ZenModeAddBypassingAppsPreferenceController method updateAppList.

@VisibleForTesting
void updateAppList(List<ApplicationsState.AppEntry> apps) {
    if (apps == null) {
        return;
    }
    if (mPreferenceCategory == null) {
        mPreferenceCategory = new PreferenceCategory(mPrefContext);
        mPreferenceCategory.setTitle(R.string.zen_mode_bypassing_apps_add_header);
        mPreferenceScreen.addPreference(mPreferenceCategory);
    }
    List<Preference> appsWithNoBypassingDndNotificationChannels = new ArrayList<>();
    for (ApplicationsState.AppEntry entry : apps) {
        String pkg = entry.info.packageName;
        mApplicationsState.ensureIcon(entry);
        final int appChannels = mNotificationBackend.getChannelCount(pkg, entry.info.uid);
        final int appChannelsBypassingDnd = mNotificationBackend.getNotificationChannelsBypassingDnd(pkg, entry.info.uid).getList().size();
        if (appChannelsBypassingDnd == 0 && appChannels > 0) {
            final String key = ZenModeAllBypassingAppsPreferenceController.getKey(pkg);
            Preference pref = mPreferenceCategory.findPreference("");
            if (pref == null) {
                pref = new AppPreference(mPrefContext);
                pref.setKey(key);
                pref.setOnPreferenceClickListener(preference -> {
                    Bundle args = new Bundle();
                    args.putString(AppInfoBase.ARG_PACKAGE_NAME, entry.info.packageName);
                    args.putInt(AppInfoBase.ARG_PACKAGE_UID, entry.info.uid);
                    new SubSettingLauncher(mContext).setDestination(AppChannelsBypassingDndSettings.class.getName()).setArguments(args).setResultListener(mHostFragment, 0).setUserHandle(new UserHandle(UserHandle.getUserId(entry.info.uid))).setSourceMetricsCategory(SettingsEnums.NOTIFICATION_ZEN_MODE_OVERRIDING_APP).launch();
                    return true;
                });
            }
            pref.setTitle(BidiFormatter.getInstance().unicodeWrap(entry.label));
            pref.setIcon(entry.icon);
            appsWithNoBypassingDndNotificationChannels.add(pref);
        }
    }
    if (appsWithNoBypassingDndNotificationChannels.size() == 0) {
        Preference pref = mPreferenceCategory.findPreference(ZenModeAllBypassingAppsPreferenceController.KEY_NO_APPS);
        if (pref == null) {
            pref = new Preference(mPrefContext);
            pref.setKey(ZenModeAllBypassingAppsPreferenceController.KEY_NO_APPS);
            pref.setTitle(R.string.zen_mode_bypassing_apps_subtext_none);
        }
        mPreferenceCategory.addPreference(pref);
    }
    if (ZenModeAllBypassingAppsPreferenceController.hasAppListChanged(appsWithNoBypassingDndNotificationChannels, mPreferenceCategory)) {
        mPreferenceCategory.removeAll();
        for (Preference prefToAdd : appsWithNoBypassingDndNotificationChannels) {
            mPreferenceCategory.addPreference(prefToAdd);
        }
    }
}
Also used : PreferenceCategory(androidx.preference.PreferenceCategory) AppPreference(com.android.settingslib.widget.AppPreference) Preference(androidx.preference.Preference) AppPreference(com.android.settingslib.widget.AppPreference) SubSettingLauncher(com.android.settings.core.SubSettingLauncher) ApplicationsState(com.android.settingslib.applications.ApplicationsState) Bundle(android.os.Bundle) UserHandle(android.os.UserHandle) ArrayList(java.util.ArrayList) VisibleForTesting(androidx.annotation.VisibleForTesting)

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