Search in sources :

Example 16 with AppPreference

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

the class ZenModeAllBypassingAppsPreferenceController method updateAppList.

@VisibleForTesting
void updateAppList(List<ApplicationsState.AppEntry> apps) {
    if (mPreferenceCategory == null || apps == null) {
        return;
    }
    List<Preference> appsBypassingDnd = new ArrayList<>();
    for (ApplicationsState.AppEntry app : apps) {
        String pkg = app.info.packageName;
        mApplicationsState.ensureIcon(app);
        final int appChannels = mNotificationBackend.getChannelCount(pkg, app.info.uid);
        final int appChannelsBypassingDnd = mNotificationBackend.getNotificationChannelsBypassingDnd(pkg, app.info.uid).getList().size();
        if (appChannelsBypassingDnd > 0) {
            final String key = getKey(pkg);
            // re-use previously created preference when possible
            Preference pref = mPreferenceCategory.findPreference(key);
            if (pref == null) {
                pref = new AppPreference(mPrefContext);
                pref.setKey(key);
                pref.setOnPreferenceClickListener(preference -> {
                    Bundle args = new Bundle();
                    args.putString(AppInfoBase.ARG_PACKAGE_NAME, app.info.packageName);
                    args.putInt(AppInfoBase.ARG_PACKAGE_UID, app.info.uid);
                    new SubSettingLauncher(mContext).setDestination(AppChannelsBypassingDndSettings.class.getName()).setArguments(args).setUserHandle(UserHandle.getUserHandleForUid(app.info.uid)).setResultListener(mHostFragment, 0).setSourceMetricsCategory(SettingsEnums.NOTIFICATION_ZEN_MODE_OVERRIDING_APP).launch();
                    return true;
                });
            }
            pref.setTitle(BidiFormatter.getInstance().unicodeWrap(app.label));
            pref.setIcon(app.icon);
            if (appChannels > appChannelsBypassingDnd) {
                pref.setSummary(R.string.zen_mode_bypassing_apps_summary_some);
            } else {
                pref.setSummary(R.string.zen_mode_bypassing_apps_summary_all);
            }
            appsBypassingDnd.add(pref);
        }
    }
    if (appsBypassingDnd.size() == 0) {
        Preference pref = mPreferenceCategory.findPreference(KEY_NO_APPS);
        if (pref == null) {
            pref = new Preference(mPrefContext);
            pref.setKey(KEY_NO_APPS);
            pref.setTitle(R.string.zen_mode_bypassing_apps_none);
        }
        appsBypassingDnd.add(pref);
    }
    if (hasAppListChanged(appsBypassingDnd, mPreferenceCategory)) {
        mPreferenceCategory.removeAll();
        for (Preference prefToAdd : appsBypassingDnd) {
            mPreferenceCategory.addPreference(prefToAdd);
        }
    }
}
Also used : 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) ArrayList(java.util.ArrayList) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 17 with AppPreference

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

the class AppsPreferenceController method displayRecentApps.

private void displayRecentApps() {
    if (mRecentAppsCategory != null) {
        final Map<String, Preference> existedAppPreferences = new ArrayMap<>();
        final int prefCount = mRecentAppsCategory.getPreferenceCount();
        for (int i = 0; i < prefCount; i++) {
            final Preference pref = mRecentAppsCategory.getPreference(i);
            final String key = pref.getKey();
            if (!TextUtils.equals(key, KEY_SEE_ALL)) {
                existedAppPreferences.put(key, pref);
            }
        }
        int showAppsCount = 0;
        for (UsageStats stat : mRecentApps) {
            final String pkgName = stat.getPackageName();
            final ApplicationsState.AppEntry appEntry = mApplicationsState.getEntry(pkgName, mUserId);
            if (appEntry == null) {
                continue;
            }
            boolean rebindPref = true;
            Preference pref = existedAppPreferences.remove(pkgName);
            if (pref == null) {
                pref = new AppPreference(mContext);
                rebindPref = false;
            }
            pref.setKey(pkgName);
            pref.setTitle(appEntry.label);
            pref.setIcon(Utils.getBadgedIcon(mContext, appEntry.info));
            pref.setSummary(StringUtil.formatRelativeTime(mContext, System.currentTimeMillis() - stat.getLastTimeUsed(), false, RelativeDateTimeFormatter.Style.SHORT));
            pref.setOrder(showAppsCount++);
            pref.setOnPreferenceClickListener(preference -> {
                AppInfoBase.startAppInfoFragment(AppInfoDashboardFragment.class, R.string.application_info_label, pkgName, appEntry.info.uid, mHost, 1001, /*RequestCode*/
                getMetricsCategory());
                return true;
            });
            if (!rebindPref) {
                mRecentAppsCategory.addPreference(pref);
            }
        }
        // Remove unused preferences from pref category.
        for (Preference unusedPref : existedAppPreferences.values()) {
            mRecentAppsCategory.removePreference(unusedPref);
        }
    }
}
Also used : AppPreference(com.android.settingslib.widget.AppPreference) Preference(androidx.preference.Preference) AppPreference(com.android.settingslib.widget.AppPreference) ApplicationsState(com.android.settingslib.applications.ApplicationsState) ArrayMap(android.util.ArrayMap) UsageStats(android.app.usage.UsageStats)

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