Search in sources :

Example 21 with Callbacks

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

the class LauncherModel method addAndBindAddedWorkspaceItems.

/**
 * Adds the provided items to the workspace.
 */
public void addAndBindAddedWorkspaceItems(List<Pair<ItemInfo, Object>> itemList) {
    Callbacks callbacks = getCallback();
    if (callbacks != null) {
        callbacks.preAddApps();
    }
    enqueueModelUpdateTask(new AddWorkspaceItemsTask(itemList));
}
Also used : Callbacks(com.android.launcher3.model.BgDataModel.Callbacks) AddWorkspaceItemsTask(com.android.launcher3.model.AddWorkspaceItemsTask)

Example 22 with Callbacks

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

the class Workspace method removeAllWorkspaceScreens.

public void removeAllWorkspaceScreens() {
    // Disable all layout transitions before removing all pages to ensure that we don't get the
    // transition animations competing with us changing the scroll when we add pages
    disableLayoutTransitions();
    // Recycle the QSB widget
    View qsb = findViewById(R.id.search_container_workspace);
    if (qsb != null) {
        ((ViewGroup) qsb.getParent()).removeView(qsb);
    }
    // Remove the pages and clear the screen models
    removeFolderListeners();
    removeAllViews();
    mScreenOrder.clear();
    mWorkspaceScreens.clear();
    // Remove any deferred refresh callbacks
    mLauncher.mHandler.removeCallbacksAndMessages(DeferredWidgetRefresh.class);
    // Ensure that the first page is always present
    bindAndInitFirstWorkspaceScreen(qsb);
    // Re-enable the layout transitions
    enableLayoutTransitions();
}
Also used : ViewGroup(android.view.ViewGroup) View(android.view.View) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView) DragView(com.android.launcher3.dragndrop.DragView) OmegaBackgroundView(com.saggitt.omega.views.OmegaBackgroundView)

Example 23 with Callbacks

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

the class BaseLoaderResults method bindWorkspace.

/**
 * Binds all loaded data to actual views on the main thread.
 */
public void bindWorkspace() {
    Callbacks callbacks = mCallbacks.get();
    // Otherwise we hold a reference to them.
    if (callbacks == null) {
        // This launcher has exited and nobody bothered to tell us.  Just bail.
        Log.w(TAG, "LoaderTask running with no launcher");
        return;
    }
    // Save a copy of all the bg-thread collections
    ArrayList<ItemInfo> workspaceItems = new ArrayList<>();
    ArrayList<LauncherAppWidgetInfo> appWidgets = new ArrayList<>();
    final IntArray orderedScreenIds = new IntArray();
    synchronized (mBgDataModel) {
        workspaceItems.addAll(mBgDataModel.workspaceItems);
        appWidgets.addAll(mBgDataModel.appWidgets);
        orderedScreenIds.addAll(mBgDataModel.collectWorkspaceScreens());
        mBgDataModel.lastBindId++;
        mMyBindingId = mBgDataModel.lastBindId;
    }
    final int currentScreen;
    {
        int currScreen = mPageToBindFirst != PagedView.INVALID_RESTORE_PAGE ? mPageToBindFirst : callbacks.getCurrentWorkspaceScreen();
        if (currScreen >= orderedScreenIds.size()) {
            // There may be no workspace screens (just hotseat items and an empty page).
            currScreen = PagedView.INVALID_RESTORE_PAGE;
        }
        currentScreen = currScreen;
    }
    final boolean validFirstPage = currentScreen >= 0;
    final int currentScreenId = validFirstPage ? orderedScreenIds.get(currentScreen) : INVALID_SCREEN_ID;
    // Separate the items that are on the current screen, and all the other remaining items
    ArrayList<ItemInfo> currentWorkspaceItems = new ArrayList<>();
    ArrayList<ItemInfo> otherWorkspaceItems = new ArrayList<>();
    ArrayList<LauncherAppWidgetInfo> currentAppWidgets = new ArrayList<>();
    ArrayList<LauncherAppWidgetInfo> otherAppWidgets = new ArrayList<>();
    filterCurrentWorkspaceItems(currentScreenId, workspaceItems, currentWorkspaceItems, otherWorkspaceItems);
    filterCurrentWorkspaceItems(currentScreenId, appWidgets, currentAppWidgets, otherAppWidgets);
    sortWorkspaceItemsSpatially(currentWorkspaceItems);
    sortWorkspaceItemsSpatially(otherWorkspaceItems);
    // Tell the workspace that we're about to start binding items
    executeCallbacksTask(c -> {
        c.clearPendingBinds();
        c.startBinding();
    }, mUiExecutor);
    // Bind workspace screens
    executeCallbacksTask(c -> c.bindScreens(orderedScreenIds), mUiExecutor);
    Executor mainExecutor = mUiExecutor;
    // Load items on the current page.
    bindWorkspaceItems(currentWorkspaceItems, mainExecutor);
    bindAppWidgets(currentAppWidgets, mainExecutor);
    // In case of validFirstPage, only bind the first screen, and defer binding the
    // remaining screens after first onDraw (and an optional the fade animation whichever
    // happens later).
    // This ensures that the first screen is immediately visible (eg. during rotation)
    // In case of !validFirstPage, bind all pages one after other.
    final Executor deferredExecutor = validFirstPage ? new ViewOnDrawExecutor() : mainExecutor;
    executeCallbacksTask(c -> c.finishFirstPageBind(validFirstPage ? (ViewOnDrawExecutor) deferredExecutor : null), mainExecutor);
    bindWorkspaceItems(otherWorkspaceItems, deferredExecutor);
    bindAppWidgets(otherAppWidgets, deferredExecutor);
    // Tell the workspace that we're done binding items
    executeCallbacksTask(c -> c.finishBindingItems(mPageToBindFirst), deferredExecutor);
    if (validFirstPage) {
        executeCallbacksTask(c -> {
            // not complete, and schedule the remaining pages.
            if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
                c.onPageBoundSynchronously(currentScreen);
            }
            c.executeOnNextDraw((ViewOnDrawExecutor) deferredExecutor);
        }, mUiExecutor);
    }
}
Also used : ViewOnDrawExecutor(com.android.launcher3.util.ViewOnDrawExecutor) Executor(java.util.concurrent.Executor) Callbacks(com.android.launcher3.model.BgDataModel.Callbacks) IntArray(com.android.launcher3.util.IntArray) ItemInfo(com.android.launcher3.ItemInfo) ArrayList(java.util.ArrayList) ViewOnDrawExecutor(com.android.launcher3.util.ViewOnDrawExecutor) LauncherAppWidgetInfo(com.android.launcher3.LauncherAppWidgetInfo)

Example 24 with Callbacks

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

the class BaseModelUpdateTask method scheduleCallbackTask.

/**
 * Schedules a {@param task} to be executed on the current callbacks.
 */
public final void scheduleCallbackTask(final CallbackTask task) {
    final Callbacks callbacks = mModel.getCallback();
    mUiExecutor.execute(() -> {
        Callbacks cb = mModel.getCallback();
        if (callbacks == cb && cb != null) {
            task.execute(callbacks);
        }
    });
}
Also used : Callbacks(com.android.launcher3.model.BgDataModel.Callbacks)

Example 25 with Callbacks

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

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);
            }
        }
        PackageInstallerCompat packageInstaller = PackageInstallerCompat.getInstance(app.getContext());
        LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(app.getContext());
        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);
                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.setInstallProgress((int) sessionInfo.getProgress());
                }
                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.applyFrom(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);
        }
    }
    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 : LauncherAppsCompat(com.android.launcher3.compat.LauncherAppsCompat) ItemInfo(com.android.launcher3.ItemInfo) WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo) ArrayList(java.util.ArrayList) SessionInfo(android.content.pm.PackageInstaller.SessionInfo) IntArray(com.android.launcher3.util.IntArray) Callbacks(com.android.launcher3.model.BgDataModel.Callbacks) PackageInstallerCompat(com.android.launcher3.compat.PackageInstallerCompat) CallbackTask(com.android.launcher3.LauncherModel.CallbackTask) LauncherAppWidgetInfo(com.android.launcher3.LauncherAppWidgetInfo) FolderInfo(com.android.launcher3.FolderInfo) AppInfo(com.android.launcher3.AppInfo) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo)

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