Search in sources :

Example 26 with Callbacks

use of com.android.launcher3.model.BgDataModel.Callbacks in project Neo-Launcher by NeoApplications.

the class PackageInstallStateChangedTask method execute.

@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
    if (mInstallInfo.state == PackageInstallerCompat.STATUS_INSTALLED) {
        try {
            // For instant apps we do not get package-add. Use setting events to update
            // any pinned icons.
            ApplicationInfo ai = app.getContext().getPackageManager().getApplicationInfo(mInstallInfo.packageName, 0);
            if (InstantAppResolver.newInstance(app.getContext()).isInstantApp(ai)) {
                app.getModel().onPackageAdded(ai.packageName, mInstallInfo.user);
            }
        } catch (PackageManager.NameNotFoundException e) {
        // Ignore
        }
        // Ignore install success events as they are handled by Package add events.
        return;
    }
    synchronized (apps) {
        PromiseAppInfo updated = apps.updatePromiseInstallInfo(mInstallInfo);
        if (updated != null) {
            scheduleCallbackTask(c -> c.bindPromiseAppProgressUpdated(updated));
        }
        bindApplicationsIfNeeded();
    }
    synchronized (dataModel) {
        final HashSet<ItemInfo> updates = new HashSet<>();
        for (ItemInfo info : dataModel.itemsIdMap) {
            if (info instanceof WorkspaceItemInfo) {
                WorkspaceItemInfo si = (WorkspaceItemInfo) info;
                ComponentName cn = si.getTargetComponent();
                if (si.hasPromiseIconUi() && (cn != null) && mInstallInfo.packageName.equals(cn.getPackageName())) {
                    si.setInstallProgress(mInstallInfo.progress);
                    if (mInstallInfo.state == PackageInstallerCompat.STATUS_FAILED) {
                        // Mark this info as broken.
                        si.status &= ~WorkspaceItemInfo.FLAG_INSTALL_SESSION_ACTIVE;
                    }
                    updates.add(si);
                }
            }
        }
        for (LauncherAppWidgetInfo widget : dataModel.appWidgets) {
            if (widget.providerName.getPackageName().equals(mInstallInfo.packageName)) {
                widget.installProgress = mInstallInfo.progress;
                updates.add(widget);
            }
        }
        if (!updates.isEmpty()) {
            scheduleCallbackTask(new CallbackTask() {

                @Override
                public void execute(Callbacks callbacks) {
                    callbacks.bindRestoreItemsChange(updates);
                }
            });
        }
    }
}
Also used : CallbackTask(com.android.launcher3.LauncherModel.CallbackTask) ItemInfo(com.android.launcher3.ItemInfo) WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo) ApplicationInfo(android.content.pm.ApplicationInfo) LauncherAppWidgetInfo(com.android.launcher3.LauncherAppWidgetInfo) PackageManager(android.content.pm.PackageManager) Callbacks(com.android.launcher3.model.BgDataModel.Callbacks) PromiseAppInfo(com.android.launcher3.PromiseAppInfo) ComponentName(android.content.ComponentName) HashSet(java.util.HashSet) WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo)

Example 27 with Callbacks

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

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 28 with Callbacks

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

the class LauncherModel method startLoader.

private boolean startLoader(Callbacks[] newCallbacks) {
    // Enable queue before starting loader. It will get disabled in Launcher#finishBindingItems
    ItemInstallQueue.INSTANCE.get(mApp.getContext()).pauseModelPush(ItemInstallQueue.FLAG_LOADER_RUNNING);
    synchronized (mLock) {
        // If there is already one running, tell it to stop.
        boolean wasRunning = stopLoader();
        boolean bindDirectly = mModelLoaded && !mIsLoaderTaskRunning;
        boolean bindAllCallbacks = wasRunning || !bindDirectly || newCallbacks.length == 0;
        final Callbacks[] callbacksList = bindAllCallbacks ? getCallbacks() : newCallbacks;
        if (callbacksList.length > 0) {
            // Clear any pending bind-runnables from the synchronized load process.
            for (Callbacks cb : callbacksList) {
                MAIN_EXECUTOR.execute(cb::clearPendingBinds);
            }
            LoaderResults loaderResults = new LoaderResults(mApp, mBgDataModel, mBgAllAppsList, callbacksList);
            if (bindDirectly) {
                // Divide the set of loaded items into those that we are binding synchronously,
                // and everything else that is to be bound normally (asynchronously).
                loaderResults.bindWorkspace(bindAllCallbacks);
                // For now, continue posting the binding of AllApps as there are other
                // issues that arise from that.
                loaderResults.bindAllApps();
                loaderResults.bindDeepShortcuts();
                loaderResults.bindWidgets();
                return true;
            } else {
                stopLoader();
                mLoaderTask = new LoaderTask(mApp, mBgAllAppsList, mBgDataModel, mModelDelegate, loaderResults);
                // Always post the loader task, instead of running directly
                // (even on same thread) so that we exit any nested synchronized blocks
                MODEL_EXECUTOR.post(mLoaderTask);
            }
        }
    }
    return false;
}
Also used : Callbacks(com.android.launcher3.model.BgDataModel.Callbacks) LoaderTask(com.android.launcher3.model.LoaderTask) LoaderResults(com.android.launcher3.model.LoaderResults)

Example 29 with Callbacks

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

the class GroupedTaskView method launchTaskAnimated.

@Nullable
@Override
public RunnableList launchTaskAnimated() {
    if (mTask == null || mSecondaryTask == null) {
        return null;
    }
    RunnableList endCallback = new RunnableList();
    RecentsView recentsView = getRecentsView();
    // Callbacks run from remote animation when recents animation not currently running
    recentsView.getSplitPlaceholder().launchTasks(this, /*groupedTaskView*/
    success -> endCallback.executeAllAndDestroy(), false);
    // Callbacks get run from recentsView for case when recents animation already running
    recentsView.addSideTaskLaunchCallback(endCallback);
    return endCallback;
}
Also used : RunnableList(com.android.launcher3.util.RunnableList) Nullable(androidx.annotation.Nullable)

Example 30 with Callbacks

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

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)

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