Search in sources :

Example 1 with ITEM_TYPE_APPLICATION

use of com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION in project android_packages_apps_Launcher3 by crdroidandroid.

the class ItemInfo method buildProto.

/**
 * Creates {@link LauncherAtom.ItemInfo} with important fields and parent container info.
 */
public LauncherAtom.ItemInfo buildProto(FolderInfo fInfo) {
    LauncherAtom.ItemInfo.Builder itemBuilder = getDefaultItemInfoBuilder();
    Optional<ComponentName> nullableComponent = Optional.ofNullable(getTargetComponent());
    switch(itemType) {
        case ITEM_TYPE_APPLICATION:
            itemBuilder.setApplication(nullableComponent.map(component -> LauncherAtom.Application.newBuilder().setComponentName(component.flattenToShortString()).setPackageName(component.getPackageName())).orElse(LauncherAtom.Application.newBuilder()));
            break;
        case ITEM_TYPE_DEEP_SHORTCUT:
            itemBuilder.setShortcut(nullableComponent.map(component -> {
                Shortcut.Builder lsb = Shortcut.newBuilder().setShortcutName(component.flattenToShortString());
                Optional.ofNullable(getIntent()).map(i -> i.getStringExtra(EXTRA_SHORTCUT_ID)).ifPresent(lsb::setShortcutId);
                return lsb;
            }).orElse(LauncherAtom.Shortcut.newBuilder()));
            break;
        case ITEM_TYPE_SHORTCUT:
            itemBuilder.setShortcut(nullableComponent.map(component -> LauncherAtom.Shortcut.newBuilder().setShortcutName(component.flattenToShortString())).orElse(LauncherAtom.Shortcut.newBuilder()));
            break;
        case ITEM_TYPE_APPWIDGET:
            itemBuilder.setWidget(nullableComponent.map(component -> LauncherAtom.Widget.newBuilder().setComponentName(component.flattenToShortString()).setPackageName(component.getPackageName())).orElse(LauncherAtom.Widget.newBuilder()).setSpanX(spanX).setSpanY(spanY));
            break;
        case ITEM_TYPE_TASK:
            itemBuilder.setTask(LauncherAtom.Task.newBuilder().setComponentName(getTargetComponent().flattenToShortString()).setIndex(screenId));
            break;
        default:
            break;
    }
    if (fInfo != null) {
        LauncherAtom.FolderContainer.Builder folderBuilder = LauncherAtom.FolderContainer.newBuilder();
        folderBuilder.setGridX(cellX).setGridY(cellY).setPageIndex(screenId);
        switch(fInfo.container) {
            case CONTAINER_HOTSEAT:
            case CONTAINER_HOTSEAT_PREDICTION:
                folderBuilder.setHotseat(LauncherAtom.HotseatContainer.newBuilder().setIndex(fInfo.screenId));
                break;
            case CONTAINER_DESKTOP:
                folderBuilder.setWorkspace(LauncherAtom.WorkspaceContainer.newBuilder().setPageIndex(fInfo.screenId).setGridX(fInfo.cellX).setGridY(fInfo.cellY));
                break;
        }
        itemBuilder.setContainerInfo(ContainerInfo.newBuilder().setFolder(folderBuilder));
    } else {
        ContainerInfo containerInfo = getContainerInfo();
        if (!containerInfo.getContainerCase().equals(CONTAINER_NOT_SET)) {
            itemBuilder.setContainerInfo(containerInfo);
        }
    }
    return itemBuilder.build();
}
Also used : ContainerInfo(com.android.launcher3.logger.LauncherAtom.ContainerInfo) CONTAINER_WIDGETS_TRAY(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_TRAY) ITEM_TYPE_APPLICATION(com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) Intent(android.content.Intent) LauncherSettings(com.android.launcher3.LauncherSettings) Process(android.os.Process) AllAppsContainer(com.android.launcher3.logger.LauncherAtom.AllAppsContainer) SearchResultContainer(com.android.launcher3.logger.LauncherAtom.SearchResultContainer) CONTAINER_TASKSWITCHER(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_TASKSWITCHER) CONTAINER_HOTSEAT(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT) LauncherAtom(com.android.launcher3.logger.LauncherAtom) ITEM_TYPE_APPWIDGET(com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET) UserHandle(android.os.UserHandle) TaskSwitcherContainer(com.android.launcher3.logger.LauncherAtom.TaskSwitcherContainer) ExtendedContainers(com.android.launcher3.logger.LauncherAtomExtensions.ExtendedContainers) Shortcut(com.android.launcher3.logger.LauncherAtom.Shortcut) EXTRA_SHORTCUT_ID(com.android.launcher3.shortcuts.ShortcutKey.EXTRA_SHORTCUT_ID) Favorites(com.android.launcher3.LauncherSettings.Favorites) ComponentName(android.content.ComponentName) CONTAINER_SHORTCUTS(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_SHORTCUTS) ITEM_TYPE_DEEP_SHORTCUT(com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) ITEM_TYPE_SHORTCUT(com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) CONTAINER_DESKTOP(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_DESKTOP) CONTAINER_SEARCH_RESULTS(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_SEARCH_RESULTS) CONTAINER_HOTSEAT_PREDICTION(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION) ShortcutsContainer(com.android.launcher3.logger.LauncherAtom.ShortcutsContainer) Nullable(androidx.annotation.Nullable) PredictionContainer(com.android.launcher3.logger.LauncherAtom.PredictionContainer) ITEM_TYPE_TASK(com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_TASK) ContentWriter(com.android.launcher3.util.ContentWriter) EXTENDED_CONTAINERS(com.android.launcher3.LauncherSettings.Favorites.EXTENDED_CONTAINERS) CONTAINER_SETTINGS(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_SETTINGS) CONTAINER_NOT_SET(com.android.launcher3.logger.LauncherAtom.ContainerInfo.ContainerCase.CONTAINER_NOT_SET) Optional(java.util.Optional) Workspace(com.android.launcher3.Workspace) CONTAINER_ALL_APPS(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_ALL_APPS) ContentValues(android.content.ContentValues) CONTAINER_PREDICTION(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_PREDICTION) SettingsContainer(com.android.launcher3.logger.LauncherAtom.SettingsContainer) ModelWriter(com.android.launcher3.model.ModelWriter) Shortcut(com.android.launcher3.logger.LauncherAtom.Shortcut) ContainerInfo(com.android.launcher3.logger.LauncherAtom.ContainerInfo) ComponentName(android.content.ComponentName)

Example 2 with ITEM_TYPE_APPLICATION

use of com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION in project android_packages_apps_Launcher3 by crdroidandroid.

the class LoaderCursorTest method getAppShortcutInfo_allowMissing_invalidComponent.

@Test
public void getAppShortcutInfo_allowMissing_invalidComponent() throws Exception {
    initCursor(ITEM_TYPE_APPLICATION, "");
    assertTrue(mLoaderCursor.moveToNext());
    ComponentName cn = new ComponentName(mContext.getPackageName(), "placeholder-do");
    WorkspaceItemInfo info = Executors.MODEL_EXECUTOR.submit(() -> mLoaderCursor.getAppShortcutInfo(new Intent().setComponent(cn), true, /* allowMissingTarget */
    true)).get();
    assertNotNull(info);
    assertTrue(PackageManagerHelper.isLauncherAppTarget(info.getIntent()));
}
Also used : ComponentName(android.content.ComponentName) Intent(android.content.Intent) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) Test(org.junit.Test)

Example 3 with ITEM_TYPE_APPLICATION

use of com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION in project android_packages_apps_Launcher3 by crdroidandroid.

the class QuickstepLauncher method logAppLaunch.

@Override
protected void logAppLaunch(ItemInfo info, InstanceId instanceId) {
    // LiveSearchManager to recreate the AllApps session on the server side.
    if (mAllAppsSessionLogId != null && ALL_APPS.equals(getStateManager().getCurrentStableState())) {
        instanceId = mAllAppsSessionLogId;
    }
    StatsLogger logger = getStatsLogManager().logger().withItemInfo(info).withInstanceId(instanceId);
    if (mAllAppsPredictions != null && (info.itemType == ITEM_TYPE_APPLICATION || info.itemType == ITEM_TYPE_SHORTCUT || info.itemType == ITEM_TYPE_DEEP_SHORTCUT)) {
        int count = mAllAppsPredictions.items.size();
        for (int i = 0; i < count; i++) {
            ItemInfo targetInfo = mAllAppsPredictions.items.get(i);
            if (targetInfo.itemType == info.itemType && targetInfo.user.equals(info.user) && Objects.equals(targetInfo.getIntent(), info.getIntent())) {
                logger.withRank(i);
                break;
            }
        }
    }
    logger.log(LAUNCHER_APP_LAUNCH_TAP);
    mHotseatPredictionController.logLaunchedAppRankingInfo(info, instanceId);
}
Also used : StatsLogger(com.android.launcher3.logging.StatsLogManager.StatsLogger) ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 4 with ITEM_TYPE_APPLICATION

use of com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION in project android_packages_apps_Launcher3 by crdroidandroid.

the class LoaderCursorTest method getAppShortcutInfo_dontAllowMissing_validComponent.

@Test
public void getAppShortcutInfo_dontAllowMissing_validComponent() throws Exception {
    ComponentName cn = new ComponentName(TEST_PACKAGE, TEST_PACKAGE);
    shadowOf(mContext.getPackageManager()).addActivityIfNotPresent(cn);
    initCursor(ITEM_TYPE_APPLICATION, "");
    assertTrue(mLoaderCursor.moveToNext());
    WorkspaceItemInfo info = Executors.MODEL_EXECUTOR.submit(() -> mLoaderCursor.getAppShortcutInfo(new Intent().setComponent(cn), false, /* allowMissingTarget */
    true)).get();
    assertNotNull(info);
    assertTrue(PackageManagerHelper.isLauncherAppTarget(info.getIntent()));
}
Also used : ComponentName(android.content.ComponentName) Intent(android.content.Intent) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) Test(org.junit.Test)

Example 5 with ITEM_TYPE_APPLICATION

use of com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION in project android_packages_apps_Launcher3 by crdroidandroid.

the class Workspace method onDropExternal.

/**
 * Drop an item that didn't originate on one of the workspace screens.
 * It may have come from Launcher (e.g. from all apps or customize), or it may have
 * come from another app altogether.
 *
 * NOTE: This can also be called when we are outside of a drag event, when we want
 * to add an item to one of the workspace screens.
 */
private void onDropExternal(final int[] touchXY, final CellLayout cellLayout, DragObject d) {
    if (d.dragInfo instanceof PendingAddShortcutInfo) {
        WorkspaceItemInfo si = ((PendingAddShortcutInfo) d.dragInfo).activityInfo.createWorkspaceItemInfo();
        if (si != null) {
            d.dragInfo = si;
        }
    }
    ItemInfo info = d.dragInfo;
    int spanX = info.spanX;
    int spanY = info.spanY;
    if (mDragInfo != null) {
        spanX = mDragInfo.spanX;
        spanY = mDragInfo.spanY;
    }
    final int container = mLauncher.isHotseatLayout(cellLayout) ? LauncherSettings.Favorites.CONTAINER_HOTSEAT : LauncherSettings.Favorites.CONTAINER_DESKTOP;
    final int screenId = getIdForScreen(cellLayout);
    if (!mLauncher.isHotseatLayout(cellLayout) && screenId != getScreenIdForPageIndex(mCurrentPage) && !mLauncher.isInState(SPRING_LOADED)) {
        snapToPage(getPageIndexForScreenId(screenId));
    }
    if (info instanceof PendingAddItemInfo) {
        final PendingAddItemInfo pendingInfo = (PendingAddItemInfo) info;
        boolean findNearestVacantCell = true;
        if (pendingInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) {
            mTargetCell = findNearestArea(touchXY[0], touchXY[1], spanX, spanY, cellLayout, mTargetCell);
            float distance = cellLayout.getDistanceFromCell(mDragViewVisualCenter[0], mDragViewVisualCenter[1], mTargetCell);
            if (willCreateUserFolder(d.dragInfo, cellLayout, mTargetCell, distance, true) || willAddToExistingUserFolder(d.dragInfo, cellLayout, mTargetCell, distance)) {
                findNearestVacantCell = false;
            }
        }
        final ItemInfo item = d.dragInfo;
        boolean updateWidgetSize = false;
        if (findNearestVacantCell) {
            int minSpanX = item.spanX;
            int minSpanY = item.spanY;
            if (item.minSpanX > 0 && item.minSpanY > 0) {
                minSpanX = item.minSpanX;
                minSpanY = item.minSpanY;
            }
            int[] resultSpan = new int[2];
            mTargetCell = cellLayout.performReorder((int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], minSpanX, minSpanY, info.spanX, info.spanY, null, mTargetCell, resultSpan, CellLayout.MODE_ON_DROP_EXTERNAL);
            if (resultSpan[0] != item.spanX || resultSpan[1] != item.spanY) {
                updateWidgetSize = true;
            }
            item.spanX = resultSpan[0];
            item.spanY = resultSpan[1];
        }
        Runnable onAnimationCompleteRunnable = new Runnable() {

            @Override
            public void run() {
                // Normally removeExtraEmptyScreen is called in Workspace#onDrop, but when
                // adding an item that may not be dropped right away (due to a config activity)
                // we defer the removal until the activity returns.
                deferRemoveExtraEmptyScreen();
                // When dragging and dropping from customization tray, we deal with creating
                // widgets/shortcuts/folders in a slightly different way
                mLauncher.addPendingItem(pendingInfo, container, screenId, mTargetCell, item.spanX, item.spanY);
                mStatsLogManager.logger().withItemInfo(d.dragInfo).withInstanceId(d.logInstanceId).log(LauncherEvent.LAUNCHER_ITEM_DROP_COMPLETED);
            }
        };
        boolean isWidget = pendingInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET || pendingInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET;
        AppWidgetHostView finalView = isWidget ? ((PendingAddWidgetInfo) pendingInfo).boundWidget : null;
        if (finalView != null && updateWidgetSize) {
            WidgetSizes.updateWidgetSizeRanges(finalView, mLauncher, item.spanX, item.spanY);
        }
        int animationStyle = ANIMATE_INTO_POSITION_AND_DISAPPEAR;
        if (isWidget && ((PendingAddWidgetInfo) pendingInfo).info != null && ((PendingAddWidgetInfo) pendingInfo).getHandler().needsConfigure()) {
            animationStyle = ANIMATE_INTO_POSITION_AND_REMAIN;
        }
        animateWidgetDrop(info, cellLayout, d.dragView, onAnimationCompleteRunnable, animationStyle, finalView, true);
    } else {
        // This is for other drag/drop cases, like dragging from All Apps
        mLauncher.getStateManager().goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
        View view;
        switch(info.itemType) {
            case ITEM_TYPE_APPLICATION:
            case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
            case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT:
                if (info instanceof AppInfo) {
                    // Came from all apps -- make a copy
                    info = ((AppInfo) info).makeWorkspaceItem();
                    d.dragInfo = info;
                }
                view = mLauncher.createShortcut(cellLayout, (WorkspaceItemInfo) info);
                break;
            case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
                view = FolderIcon.inflateFolderAndIcon(R.layout.folder_icon, mLauncher, cellLayout, (FolderInfo) info);
                break;
            default:
                throw new IllegalStateException("Unknown item type: " + info.itemType);
        }
        // dropped, without any consideration to whether there is an item there.
        if (touchXY != null) {
            mTargetCell = findNearestArea(touchXY[0], touchXY[1], spanX, spanY, cellLayout, mTargetCell);
            float distance = cellLayout.getDistanceFromCell(mDragViewVisualCenter[0], mDragViewVisualCenter[1], mTargetCell);
            if (createUserFolderIfNecessary(view, container, cellLayout, mTargetCell, distance, true, d)) {
                return;
            }
            if (addToExistingFolderIfNecessary(view, cellLayout, mTargetCell, distance, d, true)) {
                return;
            }
        }
        if (touchXY != null) {
            // when dragging and dropping, just find the closest free spot
            mTargetCell = cellLayout.performReorder((int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], 1, 1, 1, 1, null, mTargetCell, null, CellLayout.MODE_ON_DROP_EXTERNAL);
        } else {
            cellLayout.findCellForSpan(mTargetCell, 1, 1);
        }
        // Add the item to DB before adding to screen ensures that the container and other
        // values of the info is properly updated.
        mLauncher.getModelWriter().addOrMoveItemInDatabase(info, container, screenId, mTargetCell[0], mTargetCell[1]);
        addInScreen(view, container, screenId, mTargetCell[0], mTargetCell[1], info.spanX, info.spanY);
        cellLayout.onDropChild(view);
        cellLayout.getShortcutsAndWidgets().measureChild(view);
        if (d.dragView != null) {
            // We wrap the animation call in the temporary set and reset of the current
            // cellLayout to its final transform -- this means we animate the drag view to
            // the correct final location.
            setFinalTransitionTransform();
            mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, view, this);
            resetTransitionTransform();
        }
        mStatsLogManager.logger().withItemInfo(d.dragInfo).withInstanceId(d.logInstanceId).log(LauncherEvent.LAUNCHER_ITEM_DROP_COMPLETED);
    }
}
Also used : WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ItemInfo(com.android.launcher3.model.data.ItemInfo) PendingAddShortcutInfo(com.android.launcher3.widget.PendingAddShortcutInfo) DraggableView(com.android.launcher3.dragndrop.DraggableView) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView) View(android.view.View) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) DragView(com.android.launcher3.dragndrop.DragView) FolderInfo(com.android.launcher3.model.data.FolderInfo) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) AppInfo(com.android.launcher3.model.data.AppInfo) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) PendingAddWidgetInfo(com.android.launcher3.widget.PendingAddWidgetInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Aggregations

WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)4 ComponentName (android.content.ComponentName)3 Intent (android.content.Intent)3 ItemInfo (com.android.launcher3.model.data.ItemInfo)2 SuppressLint (android.annotation.SuppressLint)1 AppWidgetHostView (android.appwidget.AppWidgetHostView)1 ContentValues (android.content.ContentValues)1 Point (android.graphics.Point)1 Process (android.os.Process)1 UserHandle (android.os.UserHandle)1 View (android.view.View)1 Nullable (androidx.annotation.Nullable)1 LauncherSettings (com.android.launcher3.LauncherSettings)1 Favorites (com.android.launcher3.LauncherSettings.Favorites)1 CONTAINER_ALL_APPS (com.android.launcher3.LauncherSettings.Favorites.CONTAINER_ALL_APPS)1 CONTAINER_DESKTOP (com.android.launcher3.LauncherSettings.Favorites.CONTAINER_DESKTOP)1 CONTAINER_HOTSEAT (com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT)1 CONTAINER_HOTSEAT_PREDICTION (com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION)1 CONTAINER_PREDICTION (com.android.launcher3.LauncherSettings.Favorites.CONTAINER_PREDICTION)1 CONTAINER_SEARCH_RESULTS (com.android.launcher3.LauncherSettings.Favorites.CONTAINER_SEARCH_RESULTS)1