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);
}
}
}
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);
}
}
}
Aggregations