use of com.android.launcher3.util.LauncherBindableItemsContainer.ItemOperator in project android_packages_apps_Launcher3 by crdroidandroid.
the class Workspace method widgetsRestored.
public void widgetsRestored(final ArrayList<LauncherAppWidgetInfo> changedInfo) {
if (!changedInfo.isEmpty()) {
DeferredWidgetRefresh widgetRefresh = new DeferredWidgetRefresh(changedInfo, mLauncher.getAppWidgetHost());
LauncherAppWidgetInfo item = changedInfo.get(0);
final AppWidgetProviderInfo widgetInfo;
WidgetManagerHelper widgetHelper = new WidgetManagerHelper(getContext());
if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
widgetInfo = widgetHelper.findProvider(item.providerName, item.user);
} else {
widgetInfo = widgetHelper.getLauncherAppWidgetInfo(item.appWidgetId);
}
if (widgetInfo != null) {
// Re-inflate the widgets which have changed status
widgetRefresh.run();
} else {
// widgetRefresh will automatically run when the packages are updated.
// For now just update the progress bars
mapOverItems(new ItemOperator() {
@Override
public boolean evaluate(ItemInfo info, View view) {
if (view instanceof PendingAppWidgetHostView && changedInfo.contains(info)) {
((LauncherAppWidgetInfo) info).installProgress = 100;
((PendingAppWidgetHostView) view).applyState();
}
// process all the shortcuts
return false;
}
});
}
}
}
use of com.android.launcher3.util.LauncherBindableItemsContainer.ItemOperator in project android_packages_apps_Launcher3 by crdroidandroid.
the class Workspace method mapOverCellLayout.
private View mapOverCellLayout(CellLayout layout, ItemOperator op) {
// TODO(b/128460496) Potential race condition where layout is not yet loaded
if (layout == null) {
return null;
}
ShortcutAndWidgetContainer container = layout.getShortcutsAndWidgets();
// map over all the shortcuts on the workspace
final int itemCount = container.getChildCount();
for (int itemIdx = 0; itemIdx < itemCount; itemIdx++) {
View item = container.getChildAt(itemIdx);
if (op.evaluate((ItemInfo) item.getTag(), item)) {
return item;
}
}
return null;
}
use of com.android.launcher3.util.LauncherBindableItemsContainer.ItemOperator in project android_packages_apps_Launcher3 by crdroidandroid.
the class Workspace method updateNotificationDots.
public void updateNotificationDots(Predicate<PackageUserKey> updatedDots) {
final PackageUserKey packageUserKey = new PackageUserKey(null, null);
Predicate<ItemInfo> matcher = info -> !packageUserKey.updateFromItemInfo(info) || updatedDots.test(packageUserKey);
ItemOperator op = (info, v) -> {
if (info instanceof WorkspaceItemInfo && v instanceof BubbleTextView) {
if (matcher.test(info)) {
((BubbleTextView) v).applyDotState(info, true);
}
} else if (info instanceof FolderInfo && v instanceof FolderIcon) {
FolderInfo fi = (FolderInfo) info;
if (fi.contents.stream().anyMatch(matcher)) {
FolderDotInfo folderDotInfo = new FolderDotInfo();
for (WorkspaceItemInfo si : fi.contents) {
folderDotInfo.addDotInfo(mLauncher.getDotInfoForItem(si));
}
((FolderIcon) v).setDotInfo(folderDotInfo);
}
}
// process all the shortcuts
return false;
};
mapOverItems(op);
Folder folder = Folder.getOpen(mLauncher);
if (folder != null) {
folder.iterateOverItems(op);
}
}
use of com.android.launcher3.util.LauncherBindableItemsContainer.ItemOperator in project android_packages_apps_Launcher3 by AOSPA.
the class LauncherBindableItemsContainer method updateWorkspaceItems.
/**
* Called to update workspace items as a result of
* {@link com.android.launcher3.model.BgDataModel.Callbacks#bindWorkspaceItemsChanged(List)}
*/
default void updateWorkspaceItems(List<WorkspaceItemInfo> shortcuts, ActivityContext context) {
final HashSet<WorkspaceItemInfo> updates = new HashSet<>(shortcuts);
ItemOperator op = (info, v) -> {
if (v instanceof BubbleTextView && updates.contains(info)) {
WorkspaceItemInfo si = (WorkspaceItemInfo) info;
BubbleTextView shortcut = (BubbleTextView) v;
Drawable oldIcon = shortcut.getIcon();
boolean oldPromiseState = (oldIcon instanceof PreloadIconDrawable) && ((PreloadIconDrawable) oldIcon).hasNotCompleted();
shortcut.applyFromWorkspaceItem(si, si.isPromise() != oldPromiseState);
} else if (info instanceof FolderInfo && v instanceof FolderIcon) {
((FolderIcon) v).updatePreviewItems(updates::contains);
}
// Iterate all items
return false;
};
mapOverItems(op);
Folder openFolder = Folder.getOpen(context);
if (openFolder != null) {
openFolder.iterateOverItems(op);
}
}
use of com.android.launcher3.util.LauncherBindableItemsContainer.ItemOperator in project android_packages_apps_Launcher3 by AOSPA.
the class PromiseIconUiTest method testPromiseIcon_addedFromEligibleSession.
@Test
public void testPromiseIcon_addedFromEligibleSession() throws Throwable {
final String appLabel = "Test Promise App " + UUID.randomUUID().toString();
final ItemOperator findPromiseApp = (info, view) -> info != null && TextUtils.equals(info.title, appLabel);
// Create and add test session
mSessionId = createSession(appLabel, Bitmap.createBitmap(100, 100, Bitmap.Config.ALPHA_8));
// Verify promise icon is added
waitForLauncherCondition("Test Promise App not found on workspace", launcher -> launcher.getWorkspace().getFirstMatch(findPromiseApp) != null);
// Remove session
mTargetContext.getPackageManager().getPackageInstaller().abandonSession(mSessionId);
mSessionId = -1;
// Verify promise icon is removed
waitForLauncherCondition("Test Promise App not removed from workspace", launcher -> launcher.getWorkspace().getFirstMatch(findPromiseApp) == null);
}
Aggregations