Search in sources :

Example 46 with ItemOperator

use of com.android.launcher3.Workspace.ItemOperator in project android_packages_apps_Launcher3 by ArrowOS.

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);
}
Also used : AndroidJUnit4(androidx.test.runner.AndroidJUnit4) Launcher(com.android.launcher3.Launcher) PackageManager(android.content.pm.PackageManager) ItemOperator(com.android.launcher3.util.LauncherBindableItemsContainer.ItemOperator) RunWith(org.junit.runner.RunWith) TextUtils(android.text.TextUtils) Test(org.junit.Test) UUID(java.util.UUID) SessionParams(android.content.pm.PackageInstaller.SessionParams) LauncherState(com.android.launcher3.LauncherState) Bitmap(android.graphics.Bitmap) After(org.junit.After) AbstractLauncherUiTest(com.android.launcher3.ui.AbstractLauncherUiTest) LargeTest(androidx.test.filters.LargeTest) ItemOperator(com.android.launcher3.util.LauncherBindableItemsContainer.ItemOperator) Test(org.junit.Test) AbstractLauncherUiTest(com.android.launcher3.ui.AbstractLauncherUiTest) LargeTest(androidx.test.filters.LargeTest)

Example 47 with ItemOperator

use of com.android.launcher3.Workspace.ItemOperator in project android_packages_apps_Launcher3 by ArrowOS.

the class PromiseIconUiTest method testPromiseIcon_notAddedFromIneligibleSession.

@Test
public void testPromiseIcon_notAddedFromIneligibleSession() 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 without icon or label
    mSessionId = createSession(null, null);
    // Sleep for duration of animation if a view was to be added + some buffer time.
    Thread.sleep(Launcher.NEW_APPS_PAGE_MOVE_DELAY + Launcher.NEW_APPS_ANIMATION_DELAY + 500);
    // Verify promise icon is not added
    waitForLauncherCondition("Test Promise App not found on workspace", launcher -> launcher.getWorkspace().getFirstMatch(findPromiseApp) == null);
}
Also used : AndroidJUnit4(androidx.test.runner.AndroidJUnit4) Launcher(com.android.launcher3.Launcher) PackageManager(android.content.pm.PackageManager) ItemOperator(com.android.launcher3.util.LauncherBindableItemsContainer.ItemOperator) RunWith(org.junit.runner.RunWith) TextUtils(android.text.TextUtils) Test(org.junit.Test) UUID(java.util.UUID) SessionParams(android.content.pm.PackageInstaller.SessionParams) LauncherState(com.android.launcher3.LauncherState) Bitmap(android.graphics.Bitmap) After(org.junit.After) AbstractLauncherUiTest(com.android.launcher3.ui.AbstractLauncherUiTest) LargeTest(androidx.test.filters.LargeTest) ItemOperator(com.android.launcher3.util.LauncherBindableItemsContainer.ItemOperator) Test(org.junit.Test) AbstractLauncherUiTest(com.android.launcher3.ui.AbstractLauncherUiTest) LargeTest(androidx.test.filters.LargeTest)

Example 48 with ItemOperator

use of com.android.launcher3.Workspace.ItemOperator in project android_packages_apps_Launcher3 by ArrowOS.

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);
    }
}
Also used : Folder(com.android.launcher3.folder.Folder) ActivityContext(com.android.launcher3.views.ActivityContext) ItemInfo(com.android.launcher3.model.data.ItemInfo) FolderIcon(com.android.launcher3.folder.FolderIcon) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) Drawable(android.graphics.drawable.Drawable) BubbleTextView(com.android.launcher3.BubbleTextView) HashSet(java.util.HashSet) List(java.util.List) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) FolderInfo(com.android.launcher3.model.data.FolderInfo) View(android.view.View) PreloadIconDrawable(com.android.launcher3.graphics.PreloadIconDrawable) FolderIcon(com.android.launcher3.folder.FolderIcon) Drawable(android.graphics.drawable.Drawable) PreloadIconDrawable(com.android.launcher3.graphics.PreloadIconDrawable) BubbleTextView(com.android.launcher3.BubbleTextView) Folder(com.android.launcher3.folder.Folder) FolderInfo(com.android.launcher3.model.data.FolderInfo) PreloadIconDrawable(com.android.launcher3.graphics.PreloadIconDrawable) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) HashSet(java.util.HashSet)

Example 49 with ItemOperator

use of com.android.launcher3.Workspace.ItemOperator in project android_packages_apps_Launcher3 by ArrowOS.

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;
}
Also used : DraggableView(com.android.launcher3.dragndrop.DraggableView) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView) View(android.view.View) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) DragView(com.android.launcher3.dragndrop.DragView) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 50 with ItemOperator

use of com.android.launcher3.Workspace.ItemOperator in project android_packages_apps_Launcher3 by ProtonAOSP.

the class RequestPinItemTest method runTest.

private void runTest(String activityMethod, boolean isWidget, ItemOperator itemMatcher, Intent... commandIntents) throws Throwable {
    clearHomescreen();
    mDevice.pressHome();
    // Open Pin item activity
    BlockingBroadcastReceiver openMonitor = new BlockingBroadcastReceiver(RequestPinItemActivity.class.getName());
    mLauncher.getWorkspace().switchToAllApps().getAppIcon("Test Pin Item").launch(getAppPackageName());
    assertNotNull(openMonitor.blockingGetExtraIntent());
    // Set callback
    PendingIntent callback = PendingIntent.getBroadcast(mTargetContext, 0, new Intent(mCallbackAction), PendingIntent.FLAG_ONE_SHOT);
    mTargetContext.sendBroadcast(RequestPinItemActivity.getCommandIntent(RequestPinItemActivity.class, "setCallback").putExtra(RequestPinItemActivity.EXTRA_PARAM + "0", callback));
    for (Intent command : commandIntents) {
        mTargetContext.sendBroadcast(command);
    }
    // call the requested method to start the flow
    mTargetContext.sendBroadcast(RequestPinItemActivity.getCommandIntent(RequestPinItemActivity.class, activityMethod));
    final AddToHomeScreenPrompt addToHomeScreenPrompt = mLauncher.getAddToHomeScreenPrompt();
    // Accept confirmation:
    BlockingBroadcastReceiver resultReceiver = new BlockingBroadcastReceiver(mCallbackAction);
    addToHomeScreenPrompt.addAutomatically();
    Intent result = resultReceiver.blockingGetIntent();
    assertNotNull(result);
    mAppWidgetId = result.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
    if (isWidget) {
        assertNotSame(-1, mAppWidgetId);
    }
    // Go back to home
    mLauncher.pressHome();
    Wait.atMost("", new ItemSearchCondition(itemMatcher), DEFAULT_ACTIVITY_TIMEOUT, mLauncher);
}
Also used : AddToHomeScreenPrompt(com.android.launcher3.tapl.AddToHomeScreenPrompt) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) RequestPinItemActivity(com.android.launcher3.testcomponent.RequestPinItemActivity)

Aggregations

View (android.view.View)42 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)35 ItemInfo (com.android.launcher3.model.data.ItemInfo)30 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)30 AppWidgetHostView (android.appwidget.AppWidgetHostView)27 DragView (com.android.launcher3.dragndrop.DragView)27 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)27 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)24 DraggableView (com.android.launcher3.dragndrop.DraggableView)22 Bitmap (android.graphics.Bitmap)21 Drawable (android.graphics.drawable.Drawable)21 Folder (com.android.launcher3.folder.Folder)21 FolderIcon (com.android.launcher3.folder.FolderIcon)21 SuppressLint (android.annotation.SuppressLint)20 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)20 Point (android.graphics.Point)20 FolderInfo (com.android.launcher3.model.data.FolderInfo)18 PreloadIconDrawable (com.android.launcher3.graphics.PreloadIconDrawable)17 HashSet (java.util.HashSet)17 List (java.util.List)15