Search in sources :

Example 6 with Callbacks

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

the class AddWorkspaceItemsTaskTest method testAddItem_some_items_added.

@Test
public void testAddItem_some_items_added() throws Exception {
    Callbacks callbacks = mock(Callbacks.class);
    mModelHelper.getModel().addCallbacks(callbacks);
    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) Test(org.junit.Test)

Example 7 with Callbacks

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

the class LauncherModelHelper method loadModelSync.

/**
 * Loads the model in memory synchronously
 */
public void loadModelSync() throws ExecutionException, InterruptedException {
    // Since robolectric tests run on main thread, we run the loader-UI calls on a temp thread,
    // so that we can wait appropriately for the loader to complete.
    ShadowLooperExecutor sle = Shadow.extract(Executors.MAIN_EXECUTOR);
    sle.setHandler(Executors.UI_HELPER_EXECUTOR.getHandler());
    Callbacks mockCb = mock(Callbacks.class);
    getModel().addCallbacksAndLoad(mockCb);
    Executors.MODEL_EXECUTOR.submit(() -> {
    }).get();
    Executors.UI_HELPER_EXECUTOR.submit(() -> {
    }).get();
    sle.setHandler(null);
    getModel().removeCallbacks(mockCb);
}
Also used : Callbacks(com.android.launcher3.model.BgDataModel.Callbacks) ShadowLooperExecutor(com.android.launcher3.shadows.ShadowLooperExecutor)

Example 8 with Callbacks

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

the class FallbackActivityInterface method getParallelAnimationToLauncher.

@Override
@Nullable
public Animator getParallelAnimationToLauncher(GestureEndTarget endTarget, long duration, RecentsAnimationCallbacks callbacks) {
    FallbackTaskbarUIController uiController = getTaskbarController();
    Animator superAnimator = super.getParallelAnimationToLauncher(endTarget, duration, callbacks);
    if (uiController == null) {
        return superAnimator;
    }
    RecentsState toState = stateFromGestureEndTarget(endTarget);
    Animator taskbarAnimator = uiController.createAnimToRecentsState(toState, duration);
    if (taskbarAnimator == null) {
        return superAnimator;
    }
    if (superAnimator == null) {
        return taskbarAnimator;
    }
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(superAnimator, taskbarAnimator);
    return animatorSet;
}
Also used : Animator(android.animation.Animator) FallbackTaskbarUIController(com.android.launcher3.taskbar.FallbackTaskbarUIController) RecentsState(com.android.quickstep.fallback.RecentsState) AnimatorSet(android.animation.AnimatorSet) Nullable(androidx.annotation.Nullable)

Example 9 with Callbacks

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

the class LauncherActivityInterface method getParallelAnimationToLauncher.

@Override
@Nullable
public Animator getParallelAnimationToLauncher(GestureEndTarget endTarget, long duration, RecentsAnimationCallbacks callbacks) {
    LauncherTaskbarUIController uiController = getTaskbarController();
    Animator superAnimator = super.getParallelAnimationToLauncher(endTarget, duration, callbacks);
    if (uiController == null || callbacks == null) {
        return superAnimator;
    }
    LauncherState toState = stateFromGestureEndTarget(endTarget);
    Animator taskbarAnimator = uiController.createAnimToLauncher(toState, callbacks, duration);
    if (superAnimator == null) {
        return taskbarAnimator;
    } else {
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(superAnimator, taskbarAnimator);
        return animatorSet;
    }
}
Also used : LauncherState(com.android.launcher3.LauncherState) LauncherTaskbarUIController(com.android.launcher3.taskbar.LauncherTaskbarUIController) Animator(android.animation.Animator) AnimatorSet(android.animation.AnimatorSet) Nullable(androidx.annotation.Nullable)

Example 10 with Callbacks

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

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)

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