Search in sources :

Example 71 with Callbacks

use of com.android.launcher3.model.BgDataModel.Callbacks in project android_packages_apps_Launcher3 by ProtonAOSP.

the class LauncherModelHelper method executeTaskForTest.

/**
 * Synchronously executes the task and returns all the UI callbacks posted.
 */
public List<Runnable> executeTaskForTest(ModelUpdateTask task) throws Exception {
    LauncherModel model = getModel();
    if (!model.isModelLoaded()) {
        ReflectionHelpers.setField(model, "mModelLoaded", true);
    }
    Executor mockExecutor = mock(Executor.class);
    model.enqueueModelUpdateTask(new ModelUpdateTask() {

        @Override
        public void init(LauncherAppState app, LauncherModel model, BgDataModel dataModel, AllAppsList allAppsList, Executor uiExecutor) {
            task.init(app, model, dataModel, allAppsList, mockExecutor);
        }

        @Override
        public void run() {
            task.run();
        }
    });
    MODEL_EXECUTOR.submit(() -> null).get();
    ArgumentCaptor<Runnable> captor = ArgumentCaptor.forClass(Runnable.class);
    verify(mockExecutor, atLeast(0)).execute(captor.capture());
    return captor.getAllValues();
}
Also used : LauncherModel(com.android.launcher3.LauncherModel) ModelUpdateTask(com.android.launcher3.LauncherModel.ModelUpdateTask) Executor(java.util.concurrent.Executor) LauncherAppState(com.android.launcher3.LauncherAppState) BgDataModel(com.android.launcher3.model.BgDataModel) AllAppsList(com.android.launcher3.model.AllAppsList)

Example 72 with Callbacks

use of com.android.launcher3.model.BgDataModel.Callbacks in project android_packages_apps_Launcher3 by ProtonAOSP.

the class AddWorkspaceItemsTaskTest method testAddItem_some_items_added.

@Test
public void testAddItem_some_items_added() throws Exception {
    Callbacks callbacks = mock(Callbacks.class);
    Executors.MAIN_EXECUTOR.submit(() -> mModelHelper.getModel().addCallbacks(callbacks)).get();
    WorkspaceItemInfo info = new WorkspaceItemInfo();
    info.intent = new Intent().setComponent(mComponent1);
    WorkspaceItemInfo info2 = new WorkspaceItemInfo();
    info2.intent = new Intent().setComponent(mComponent2);
    // Setup a screen with a hole
    setupWorkspaceWithHoles(1, 1, new Rect(2, 2, 3, 3));
    mModelHelper.executeTaskForTest(newTask(info, info2)).get(0).run();
    ArgumentCaptor<ArrayList> notAnimated = ArgumentCaptor.forClass(ArrayList.class);
    ArgumentCaptor<ArrayList> animated = ArgumentCaptor.forClass(ArrayList.class);
    // only info2 should be added because info was already added to the workspace
    // in setupWorkspaceWithHoles()
    verify(callbacks).bindAppsAdded(any(IntArray.class), notAnimated.capture(), animated.capture());
    assertTrue(notAnimated.getValue().isEmpty());
    assertEquals(1, animated.getValue().size());
    assertTrue(animated.getValue().contains(info2));
}
Also used : Rect(android.graphics.Rect) Callbacks(com.android.launcher3.model.BgDataModel.Callbacks) IntArray(com.android.launcher3.util.IntArray) ArrayList(java.util.ArrayList) Intent(android.content.Intent) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

Example 73 with Callbacks

use of com.android.launcher3.model.BgDataModel.Callbacks in project android_packages_apps_Launcher3 by AOSPA.

the class TouchInteractionService method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    // Initialize anything here that is needed in direct boot mode.
    // Everything else should be initialized in onUserUnlocked() below.
    mMainChoreographer = Choreographer.getInstance();
    mAM = ActivityManagerWrapper.getInstance();
    mDeviceState = new RecentsAnimationDeviceState(this, true);
    mDisplayManager = getSystemService(DisplayManager.class);
    mTaskbarManager = new TaskbarManager(this);
    mRotationTouchHelper = mDeviceState.getRotationTouchHelper();
    // Call runOnUserUnlocked() before any other callbacks to ensure everything is initialized.
    mDeviceState.runOnUserUnlocked(this::onUserUnlocked);
    mDeviceState.runOnUserUnlocked(mTaskbarManager::onUserUnlocked);
    mDeviceState.addNavigationModeChangedCallback(this::onNavigationModeChanged);
    mDeviceState.addOneHandedModeChangedCallback(this::onOneHandedModeOverlayChanged);
    ProtoTracer.INSTANCE.get(this).add(this);
    LauncherSplitScreenListener.INSTANCE.get(this).init();
    sConnected = true;
}
Also used : DisplayManager(android.hardware.display.DisplayManager) TaskbarManager(com.android.launcher3.taskbar.TaskbarManager)

Example 74 with Callbacks

use of com.android.launcher3.model.BgDataModel.Callbacks in project android_packages_apps_Launcher3 by AOSPA.

the class AddWorkspaceItemsTask method execute.

@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
    if (mItemList.isEmpty()) {
        return;
    }
    final ArrayList<ItemInfo> addedItemsFinal = new ArrayList<>();
    final IntArray addedWorkspaceScreensFinal = new IntArray();
    synchronized (dataModel) {
        IntArray workspaceScreens = dataModel.collectWorkspaceScreens();
        List<ItemInfo> filteredItems = new ArrayList<>();
        for (Pair<ItemInfo, Object> entry : mItemList) {
            ItemInfo item = entry.first;
            if (item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION || item.itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) {
                // Short-circuit this logic if the icon exists somewhere on the workspace
                if (shortcutExists(dataModel, item.getIntent(), item.user)) {
                    continue;
                }
                // b/139663018 Short-circuit this logic if the icon is a system app
                if (PackageManagerHelper.isSystemApp(app.getContext(), item.getIntent())) {
                    continue;
                }
            }
            if (item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
                if (item instanceof AppInfo) {
                    item = ((AppInfo) item).makeWorkspaceItem();
                }
            }
            if (item != null) {
                filteredItems.add(item);
            }
        }
        InstallSessionHelper packageInstaller = InstallSessionHelper.INSTANCE.get(app.getContext());
        LauncherApps launcherApps = app.getContext().getSystemService(LauncherApps.class);
        for (ItemInfo item : filteredItems) {
            // Find appropriate space for the item.
            int[] coords = findSpaceForItem(app, dataModel, workspaceScreens, addedWorkspaceScreensFinal, item.spanX, item.spanY);
            int screenId = coords[0];
            ItemInfo itemInfo;
            if (item instanceof WorkspaceItemInfo || item instanceof FolderInfo || item instanceof LauncherAppWidgetInfo) {
                itemInfo = item;
            } else if (item instanceof AppInfo) {
                itemInfo = ((AppInfo) item).makeWorkspaceItem();
            } else {
                throw new RuntimeException("Unexpected info type");
            }
            if (item instanceof WorkspaceItemInfo && ((WorkspaceItemInfo) item).isPromise()) {
                WorkspaceItemInfo workspaceInfo = (WorkspaceItemInfo) item;
                String packageName = item.getTargetComponent() != null ? item.getTargetComponent().getPackageName() : null;
                if (packageName == null) {
                    continue;
                }
                SessionInfo sessionInfo = packageInstaller.getActiveSessionInfo(item.user, packageName);
                if (!packageInstaller.verifySessionInfo(sessionInfo)) {
                    FileLog.d(LOG, "Item info failed session info verification. " + "Skipping : " + workspaceInfo);
                    continue;
                }
                List<LauncherActivityInfo> activities = launcherApps.getActivityList(packageName, item.user);
                boolean hasActivity = activities != null && !activities.isEmpty();
                if (sessionInfo == null) {
                    if (!hasActivity) {
                        // Session was cancelled, do not add.
                        continue;
                    }
                } else {
                    workspaceInfo.setProgressLevel((int) (sessionInfo.getProgress() * 100), PackageInstallInfo.STATUS_INSTALLING);
                }
                if (hasActivity) {
                    // App was installed while launcher was in the background,
                    // or app was already installed for another user.
                    itemInfo = new AppInfo(app.getContext(), activities.get(0), item.user).makeWorkspaceItem();
                    if (shortcutExists(dataModel, itemInfo.getIntent(), itemInfo.user)) {
                        // Icon already exists on the workspace and should not be auto-added.
                        continue;
                    }
                    WorkspaceItemInfo wii = (WorkspaceItemInfo) itemInfo;
                    wii.title = "";
                    wii.bitmap = app.getIconCache().getDefaultIcon(item.user);
                    app.getIconCache().getTitleAndIcon(wii, ((WorkspaceItemInfo) itemInfo).usingLowResIcon());
                }
            }
            // Add the shortcut to the db
            getModelWriter().addItemToDatabase(itemInfo, LauncherSettings.Favorites.CONTAINER_DESKTOP, screenId, coords[1], coords[2]);
            // Save the WorkspaceItemInfo for binding in the workspace
            addedItemsFinal.add(itemInfo);
            // log bitmap and label
            FileLog.d(LOG, "Adding item info to workspace: " + itemInfo);
        }
    }
    if (!addedItemsFinal.isEmpty()) {
        scheduleCallbackTask(new CallbackTask() {

            @Override
            public void execute(Callbacks callbacks) {
                final ArrayList<ItemInfo> addAnimated = new ArrayList<>();
                final ArrayList<ItemInfo> addNotAnimated = new ArrayList<>();
                if (!addedItemsFinal.isEmpty()) {
                    ItemInfo info = addedItemsFinal.get(addedItemsFinal.size() - 1);
                    int lastScreenId = info.screenId;
                    for (ItemInfo i : addedItemsFinal) {
                        if (i.screenId == lastScreenId) {
                            addAnimated.add(i);
                        } else {
                            addNotAnimated.add(i);
                        }
                    }
                }
                callbacks.bindAppsAdded(addedWorkspaceScreensFinal, addNotAnimated, addAnimated);
            }
        });
    }
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ArrayList(java.util.ArrayList) SessionInfo(android.content.pm.PackageInstaller.SessionInfo) IntArray(com.android.launcher3.util.IntArray) Callbacks(com.android.launcher3.model.BgDataModel.Callbacks) CallbackTask(com.android.launcher3.LauncherModel.CallbackTask) LauncherApps(android.content.pm.LauncherApps) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) FolderInfo(com.android.launcher3.model.data.FolderInfo) AppInfo(com.android.launcher3.model.data.AppInfo) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) InstallSessionHelper(com.android.launcher3.pm.InstallSessionHelper) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 75 with Callbacks

use of com.android.launcher3.model.BgDataModel.Callbacks in project android_packages_apps_Launcher3 by AOSPA.

the class BaseLoaderResults method bindWorkspace.

/**
 * Binds all loaded data to actual views on the main thread.
 */
public void bindWorkspace(boolean incrementBindId) {
    // Save a copy of all the bg-thread collections
    ArrayList<ItemInfo> workspaceItems = new ArrayList<>();
    ArrayList<LauncherAppWidgetInfo> appWidgets = new ArrayList<>();
    final IntArray orderedScreenIds = new IntArray();
    ArrayList<FixedContainerItems> extraItems = new ArrayList<>();
    synchronized (mBgDataModel) {
        workspaceItems.addAll(mBgDataModel.workspaceItems);
        appWidgets.addAll(mBgDataModel.appWidgets);
        orderedScreenIds.addAll(mBgDataModel.collectWorkspaceScreens());
        mBgDataModel.extraItems.forEach(extraItems::add);
        if (incrementBindId) {
            mBgDataModel.lastBindId++;
        }
        mMyBindingId = mBgDataModel.lastBindId;
    }
    for (Callbacks cb : mCallbacksList) {
        new WorkspaceBinder(cb, mUiExecutor, mApp, mBgDataModel, mMyBindingId, workspaceItems, appWidgets, extraItems, orderedScreenIds).bind();
    }
}
Also used : IntArray(com.android.launcher3.util.IntArray) Callbacks(com.android.launcher3.model.BgDataModel.Callbacks) ItemInfo(com.android.launcher3.model.data.ItemInfo) ArrayList(java.util.ArrayList) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) FixedContainerItems(com.android.launcher3.model.BgDataModel.FixedContainerItems)

Aggregations

Callbacks (com.android.launcher3.model.BgDataModel.Callbacks)39 ArrayList (java.util.ArrayList)22 IntArray (com.android.launcher3.util.IntArray)21 ItemInfo (com.android.launcher3.model.data.ItemInfo)18 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)18 Nullable (androidx.annotation.Nullable)16 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)13 AppInfo (com.android.launcher3.model.data.AppInfo)11 CallbackTask (com.android.launcher3.LauncherModel.CallbackTask)9 Animator (android.animation.Animator)8 AnimatorSet (android.animation.AnimatorSet)8 Intent (android.content.Intent)7 ApplicationInfo (android.content.pm.ApplicationInfo)7 LauncherActivityInfo (android.content.pm.LauncherActivityInfo)7 SessionInfo (android.content.pm.PackageInstaller.SessionInfo)7 PackageManager (android.content.pm.PackageManager)7 Rect (android.graphics.Rect)7 LauncherAppState (com.android.launcher3.LauncherAppState)7 LauncherModel (com.android.launcher3.LauncherModel)7 LoaderResults (com.android.launcher3.model.LoaderResults)7