Search in sources :

Example 6 with LauncherModel

use of com.android.launcher3.LauncherModel in project android_packages_apps_404Launcher by P-404.

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 7 with LauncherModel

use of com.android.launcher3.LauncherModel in project android_packages_apps_Launcher3 by crdroidandroid.

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) ShadowLooperExecutor(com.android.launcher3.shadows.ShadowLooperExecutor) Executor(java.util.concurrent.Executor) LauncherAppState(com.android.launcher3.LauncherAppState) BgDataModel(com.android.launcher3.model.BgDataModel) AllAppsList(com.android.launcher3.model.AllAppsList)

Example 8 with LauncherModel

use of com.android.launcher3.LauncherModel in project android_packages_apps_Launcher3 by crdroidandroid.

the class WorkspaceLayoutManager method addInScreen.

/**
 * Adds the specified child in the specified screen. The position and dimension of
 * the child are defined by x, y, spanX and spanY.
 *
 * @param child The child to add in one of the workspace's screens.
 * @param screenId The screen in which to add the child.
 * @param x The X position of the child in the screen's grid.
 * @param y The Y position of the child in the screen's grid.
 * @param spanX The number of cells spanned horizontally by the child.
 * @param spanY The number of cells spanned vertically by the child.
 */
default void addInScreen(View child, int container, int screenId, int x, int y, int spanX, int spanY) {
    if (container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
        if (getScreenWithId(screenId) == null) {
            Log.e(TAG, "Skipping child, screenId " + screenId + " not found");
            // DEBUGGING - Print out the stack trace to see where we are adding from
            new Throwable().printStackTrace();
            return;
        }
    }
    if (screenId == EXTRA_EMPTY_SCREEN_ID) {
        // This should never happen
        throw new RuntimeException("Screen id should not be EXTRA_EMPTY_SCREEN_ID");
    }
    final CellLayout layout;
    if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT || container == LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION) {
        layout = getHotseat();
        // Hide folder title in the hotseat
        if (child instanceof FolderIcon) {
            ((FolderIcon) child).setTextVisible(false);
        }
    } else {
        // Show folder title if not in the hotseat
        if (child instanceof FolderIcon) {
            ((FolderIcon) child).setTextVisible(true);
        }
        layout = getScreenWithId(screenId);
    }
    ViewGroup.LayoutParams genericLp = child.getLayoutParams();
    CellLayout.LayoutParams lp;
    if (genericLp == null || !(genericLp instanceof CellLayout.LayoutParams)) {
        lp = new CellLayout.LayoutParams(x, y, spanX, spanY);
    } else {
        lp = (CellLayout.LayoutParams) genericLp;
        lp.cellX = x;
        lp.cellY = y;
        lp.cellHSpan = spanX;
        lp.cellVSpan = spanY;
    }
    if (spanX < 0 && spanY < 0) {
        lp.isLockedToGrid = false;
    }
    // Get the canonical child id to uniquely represent this view in this screen
    ItemInfo info = (ItemInfo) child.getTag();
    int childId = info.getViewId();
    boolean markCellsAsOccupied = !(child instanceof Folder);
    if (!layout.addViewToCellLayout(child, -1, childId, lp, markCellsAsOccupied)) {
        // TODO: This branch occurs when the workspace is adding views
        // outside of the defined grid
        // maybe we should be deleting these items from the LauncherModel?
        Log.e(TAG, "Failed to add to item at (" + lp.cellX + "," + lp.cellY + ") to CellLayout");
    }
    child.setHapticFeedbackEnabled(false);
    child.setOnLongClickListener(getWorkspaceChildOnLongClickListener());
    if (child instanceof DropTarget) {
        onAddDropTarget((DropTarget) child);
    }
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) FolderIcon(com.android.launcher3.folder.FolderIcon) ViewGroup(android.view.ViewGroup) Folder(com.android.launcher3.folder.Folder)

Example 9 with LauncherModel

use of com.android.launcher3.LauncherModel in project Neo-Launcher by NeoApplications.

the class InstallShortcutReceiver method flushQueueInBackground.

@WorkerThread
private static void flushQueueInBackground(Context context) {
    LauncherModel model = LauncherAppState.getInstance(context).getModel();
    if (model.getCallback() == null) {
        // Launcher not loaded
        return;
    }
    ArrayList<Pair<ItemInfo, Object>> installQueue = new ArrayList<>();
    SharedPreferences prefs = Utilities.getPrefs(context);
    Set<String> strings = prefs.getStringSet(APPS_PENDING_INSTALL, null);
    if (DBG)
        Log.d(TAG, "Getting and clearing APPS_PENDING_INSTALL: " + strings);
    if (strings == null) {
        return;
    }
    LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(context);
    for (String encoded : strings) {
        PendingInstallShortcutInfo info = decode(encoded, context);
        if (info == null) {
            continue;
        }
        String pkg = getIntentPackage(info.launchIntent);
        if (!TextUtils.isEmpty(pkg) && !launcherApps.isPackageEnabledForProfile(pkg, info.user) && !info.isActivity) {
            if (DBG) {
                Log.d(TAG, "Ignoring shortcut for absent package: " + info.launchIntent);
            }
            continue;
        }
        // Generate a shortcut info to add into the model
        installQueue.add(info.getItemInfo());
    }
    prefs.edit().remove(APPS_PENDING_INSTALL).apply();
    if (!installQueue.isEmpty()) {
        model.addAndBindAddedWorkspaceItems(installQueue);
    }
}
Also used : LauncherAppsCompat(com.android.launcher3.compat.LauncherAppsCompat) SharedPreferences(android.content.SharedPreferences) ArrayList(java.util.ArrayList) Pair(android.util.Pair) WorkerThread(androidx.annotation.WorkerThread)

Example 10 with LauncherModel

use of com.android.launcher3.LauncherModel in project android_packages_apps_Trebuchet by LineageOS.

the class WorkspaceLayoutManager method addInScreen.

/**
 * Adds the specified child in the specified screen. The position and dimension of
 * the child are defined by x, y, spanX and spanY.
 *
 * @param child The child to add in one of the workspace's screens.
 * @param screenId The screen in which to add the child.
 * @param x The X position of the child in the screen's grid.
 * @param y The Y position of the child in the screen's grid.
 * @param spanX The number of cells spanned horizontally by the child.
 * @param spanY The number of cells spanned vertically by the child.
 */
default void addInScreen(View child, int container, int screenId, int x, int y, int spanX, int spanY) {
    if (container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
        if (getScreenWithId(screenId) == null) {
            Log.e(TAG, "Skipping child, screenId " + screenId + " not found");
            // DEBUGGING - Print out the stack trace to see where we are adding from
            new Throwable().printStackTrace();
            return;
        }
    }
    if (screenId == EXTRA_EMPTY_SCREEN_ID) {
        // This should never happen
        throw new RuntimeException("Screen id should not be EXTRA_EMPTY_SCREEN_ID");
    }
    final CellLayout layout;
    if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT || container == LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION) {
        layout = getHotseat();
        // Hide folder title in the hotseat
        if (child instanceof FolderIcon) {
            ((FolderIcon) child).setTextVisible(false);
        }
    } else {
        // Show folder title if not in the hotseat
        if (child instanceof FolderIcon) {
            ((FolderIcon) child).setTextVisible(true);
        }
        layout = getScreenWithId(screenId);
    }
    ViewGroup.LayoutParams genericLp = child.getLayoutParams();
    CellLayout.LayoutParams lp;
    if (genericLp == null || !(genericLp instanceof CellLayout.LayoutParams)) {
        lp = new CellLayout.LayoutParams(x, y, spanX, spanY);
    } else {
        lp = (CellLayout.LayoutParams) genericLp;
        lp.cellX = x;
        lp.cellY = y;
        lp.cellHSpan = spanX;
        lp.cellVSpan = spanY;
    }
    if (spanX < 0 && spanY < 0) {
        lp.isLockedToGrid = false;
    }
    // Get the canonical child id to uniquely represent this view in this screen
    ItemInfo info = (ItemInfo) child.getTag();
    int childId = info.getViewId();
    boolean markCellsAsOccupied = !(child instanceof Folder);
    if (!layout.addViewToCellLayout(child, -1, childId, lp, markCellsAsOccupied)) {
        // TODO: This branch occurs when the workspace is adding views
        // outside of the defined grid
        // maybe we should be deleting these items from the LauncherModel?
        Log.e(TAG, "Failed to add to item at (" + lp.cellX + "," + lp.cellY + ") to CellLayout");
    }
    child.setHapticFeedbackEnabled(false);
    child.setOnLongClickListener(ItemLongClickListener.INSTANCE_WORKSPACE);
    if (child instanceof DropTarget) {
        onAddDropTarget((DropTarget) child);
    }
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) FolderIcon(com.android.launcher3.folder.FolderIcon) ViewGroup(android.view.ViewGroup) Folder(com.android.launcher3.folder.Folder)

Aggregations

LauncherAppState (com.android.launcher3.LauncherAppState)10 AllAppsList (com.android.launcher3.model.AllAppsList)10 BgDataModel (com.android.launcher3.model.BgDataModel)10 ViewGroup (android.view.ViewGroup)6 LauncherModel (com.android.launcher3.LauncherModel)6 ModelUpdateTask (com.android.launcher3.LauncherModel.ModelUpdateTask)6 Folder (com.android.launcher3.folder.Folder)6 FolderIcon (com.android.launcher3.folder.FolderIcon)6 ItemInfo (com.android.launcher3.model.data.ItemInfo)6 Executor (java.util.concurrent.Executor)6 LauncherIcons (com.android.launcher3.icons.LauncherIcons)4 BaseModelUpdateTask (com.android.launcher3.model.BaseModelUpdateTask)4 SharedPreferences (android.content.SharedPreferences)1 Pair (android.util.Pair)1 WorkerThread (androidx.annotation.WorkerThread)1 LauncherAppsCompat (com.android.launcher3.compat.LauncherAppsCompat)1 ShadowLooperExecutor (com.android.launcher3.shadows.ShadowLooperExecutor)1 ArrayList (java.util.ArrayList)1