use of androidx.annotation.VisibleForTesting 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);
}
}
}
}
use of androidx.annotation.VisibleForTesting in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class RecentNotifyingAppsPreferenceController method reloadData.
@VisibleForTesting
void reloadData() {
mApps = new ArrayList<>();
mCal = Calendar.getInstance();
mCal.add(Calendar.DAY_OF_YEAR, -DAYS);
for (int userId : mUserIds) {
UsageEvents events = null;
try {
events = mUsageStatsManager.queryEventsForUser(mCal.getTimeInMillis(), System.currentTimeMillis(), userId, mContext.getPackageName());
} catch (RemoteException e) {
e.printStackTrace();
}
if (events != null) {
ArrayMap<String, NotifyingApp> aggregatedStats = new ArrayMap<>();
UsageEvents.Event event = new UsageEvents.Event();
while (events.hasNextEvent()) {
events.getNextEvent(event);
if (event.getEventType() == UsageEvents.Event.NOTIFICATION_INTERRUPTION) {
NotifyingApp app = aggregatedStats.get(getKey(userId, event.getPackageName()));
if (app == null) {
app = new NotifyingApp();
aggregatedStats.put(getKey(userId, event.getPackageName()), app);
app.setPackage(event.getPackageName());
app.setUserId(userId);
}
if (event.getTimeStamp() > app.getLastNotified()) {
app.setLastNotified(event.getTimeStamp());
}
}
}
mApps.addAll(aggregatedStats.values());
}
}
}
use of androidx.annotation.VisibleForTesting in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class CreateShortcutPreferenceController method createResultIntent.
/**
* Create {@link Intent} that will be consumed by ShortcutManager, which later generates a
* launcher widget using this intent.
*/
@VisibleForTesting
Intent createResultIntent(Intent shortcutIntent, ResolveInfo resolveInfo, CharSequence label) {
ShortcutInfo info = createShortcutInfo(mContext, shortcutIntent, resolveInfo, label);
Intent intent = mShortcutManager.createShortcutResultIntent(info);
if (intent == null) {
intent = new Intent();
}
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(mContext, R.mipmap.ic_launcher)).putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent).putExtra(Intent.EXTRA_SHORTCUT_NAME, label);
final ActivityInfo activityInfo = resolveInfo.activityInfo;
if (activityInfo.icon != 0) {
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, createIcon(mContext, activityInfo.applicationInfo, activityInfo.icon, R.layout.shortcut_badge, mContext.getResources().getDimensionPixelSize(R.dimen.shortcut_size)));
}
return intent;
}
use of androidx.annotation.VisibleForTesting in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class SettingsInitialize method refreshExistingShortcuts.
// Refresh settings shortcuts to have correct intent flags
@VisibleForTesting
void refreshExistingShortcuts(Context context) {
final ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
final List<ShortcutInfo> pinnedShortcuts = shortcutManager.getPinnedShortcuts();
final List<ShortcutInfo> updates = new ArrayList<>();
for (ShortcutInfo info : pinnedShortcuts) {
if (info.isImmutable()) {
continue;
}
final Intent shortcutIntent = info.getIntent();
shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
final ShortcutInfo updatedInfo = new ShortcutInfo.Builder(context, info.getId()).setIntent(shortcutIntent).build();
updates.add(updatedInfo);
}
shortcutManager.updateShortcuts(updates);
}
use of androidx.annotation.VisibleForTesting in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class SettingsPreferenceFragment method updateEmptyView.
@VisibleForTesting
void updateEmptyView() {
if (mEmptyView == null)
return;
if (getPreferenceScreen() != null) {
final View listContainer = getActivity().findViewById(android.R.id.list_container);
boolean show = (getPreferenceScreen().getPreferenceCount() - (mHeader != null ? 1 : 0) - (mFooterPreferenceMixin.hasFooter() ? 1 : 0)) <= 0 || (listContainer != null && listContainer.getVisibility() != View.VISIBLE);
mEmptyView.setVisibility(show ? View.VISIBLE : View.GONE);
} else {
mEmptyView.setVisibility(View.VISIBLE);
}
}
Aggregations