Search in sources :

Example 36 with AppInfo

use of com.android.launcher3.model.data.AppInfo in project android_packages_apps_Launcher3 by AOSPA.

the class AllAppsList method updateDisabledFlags.

/**
 * Updates the disabled flags of apps matching {@param matcher} based on {@param op}.
 */
public void updateDisabledFlags(ItemInfoMatcher matcher, FlagOp op) {
    final List<AppInfo> data = this.data;
    for (int i = data.size() - 1; i >= 0; i--) {
        AppInfo info = data.get(i);
        if (matcher.matches(info, info.componentName)) {
            info.runtimeStatusFlags = op.apply(info.runtimeStatusFlags);
            mDataChanged = true;
        }
    }
}
Also used : AppInfo(com.android.launcher3.model.data.AppInfo)

Example 37 with AppInfo

use of com.android.launcher3.model.data.AppInfo in project android_packages_apps_Launcher3 by AOSPA.

the class IconCache method getShortcutInfoBadge.

/**
 * Returns the badging info for the shortcut
 */
public BitmapInfo getShortcutInfoBadge(ShortcutInfo shortcutInfo) {
    ComponentName cn = shortcutInfo.getActivity();
    if (cn != null) {
        // Get the app info for the source activity.
        AppInfo appInfo = new AppInfo();
        appInfo.user = shortcutInfo.getUserHandle();
        appInfo.componentName = cn;
        appInfo.intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER).setComponent(cn);
        getTitleAndIcon(appInfo, false);
        return appInfo.bitmap;
    } else {
        PackageItemInfo pkgInfo = new PackageItemInfo(shortcutInfo.getPackage(), shortcutInfo.getUserHandle());
        getTitleAndIconForApp(pkgInfo, false);
        return pkgInfo.bitmap;
    }
}
Also used : PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) ComponentName(android.content.ComponentName) Intent(android.content.Intent) AppInfo(com.android.launcher3.model.data.AppInfo)

Example 38 with AppInfo

use of com.android.launcher3.model.data.AppInfo in project android_packages_apps_Trebuchet by LineageOS.

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#onDragEnd, 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) {
            AppWidgetResizeFrame.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)

Example 39 with AppInfo

use of com.android.launcher3.model.data.AppInfo in project android_packages_apps_Trebuchet by LineageOS.

the class LauncherAccessibilityDelegate method performAction.

public boolean performAction(final View host, final ItemInfo item, int action) {
    if (action == ACTION_LONG_CLICK) {
        if (PopupContainerWithArrow.canShow(host, item)) {
            // Long press should be consumed for workspace items, and it should invoke the
            // Shortcuts / Notifications / Actions pop-up menu, and not start a drag as the
            // standard long press path does.
            PopupContainerWithArrow.showForIcon((BubbleTextView) host);
            return true;
        } else {
            CustomActionsPopup popup = new CustomActionsPopup(mLauncher, host);
            if (popup.canShow()) {
                popup.show();
                return true;
            }
        }
    }
    if (host instanceof AccessibilityActionHandler && ((AccessibilityActionHandler) host).performAccessibilityAction(action, item)) {
        return true;
    }
    if (action == MOVE) {
        beginAccessibleDrag(host, item);
    } else if (action == ADD_TO_WORKSPACE) {
        final int[] coordinates = new int[2];
        final int screenId = findSpaceOnWorkspace(item, coordinates);
        mLauncher.getStateManager().goToState(NORMAL, true, new Runnable() {

            @Override
            public void run() {
                if (item instanceof AppInfo) {
                    WorkspaceItemInfo info = ((AppInfo) item).makeWorkspaceItem();
                    mLauncher.getModelWriter().addItemToDatabase(info, Favorites.CONTAINER_DESKTOP, screenId, coordinates[0], coordinates[1]);
                    ArrayList<ItemInfo> itemList = new ArrayList<>();
                    itemList.add(info);
                    mLauncher.bindItems(itemList, true);
                    announceConfirmation(R.string.item_added_to_workspace);
                } else if (item instanceof PendingAddItemInfo) {
                    PendingAddItemInfo info = (PendingAddItemInfo) item;
                    Workspace workspace = mLauncher.getWorkspace();
                    workspace.snapToPage(workspace.getPageIndexForScreenId(screenId));
                    mLauncher.addPendingItem(info, Favorites.CONTAINER_DESKTOP, screenId, coordinates, info.spanX, info.spanY);
                }
            }
        });
        return true;
    } else if (action == MOVE_TO_WORKSPACE) {
        Folder folder = Folder.getOpen(mLauncher);
        folder.close(true);
        WorkspaceItemInfo info = (WorkspaceItemInfo) item;
        folder.getInfo().remove(info, false);
        final int[] coordinates = new int[2];
        final int screenId = findSpaceOnWorkspace(item, coordinates);
        mLauncher.getModelWriter().moveItemInDatabase(info, LauncherSettings.Favorites.CONTAINER_DESKTOP, screenId, coordinates[0], coordinates[1]);
        // Bind the item in next frame so that if a new workspace page was created,
        // it will get laid out.
        new Handler().post(new Runnable() {

            @Override
            public void run() {
                ArrayList<ItemInfo> itemList = new ArrayList<>();
                itemList.add(item);
                mLauncher.bindItems(itemList, true);
                announceConfirmation(R.string.item_moved);
            }
        });
    } else if (action == RESIZE) {
        final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) item;
        final IntArray actions = getSupportedResizeActions(host, info);
        CharSequence[] labels = new CharSequence[actions.size()];
        for (int i = 0; i < actions.size(); i++) {
            labels[i] = mLauncher.getText(actions.get(i));
        }
        new AlertDialog.Builder(mLauncher).setTitle(R.string.action_resize).setItems(labels, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                performResizeAction(actions.get(which), host, info);
                dialog.dismiss();
            }
        }).show();
        return true;
    } else if (action == DEEP_SHORTCUTS) {
        return PopupContainerWithArrow.showForIcon((BubbleTextView) host) != null;
    } else {
        for (ButtonDropTarget dropTarget : mLauncher.getDropTargetBar().getDropTargets()) {
            if (dropTarget.supportsAccessibilityDrop(item, host) && action == dropTarget.getAccessibilityAction()) {
                dropTarget.onAccessibilityDrop(host, item);
                return true;
            }
        }
    }
    return false;
}
Also used : CustomActionsPopup(com.android.launcher3.keyboard.CustomActionsPopup) ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) PendingAddItemInfo(com.android.launcher3.PendingAddItemInfo) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) Handler(android.os.Handler) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) Folder(com.android.launcher3.folder.Folder) Point(android.graphics.Point) AppInfo(com.android.launcher3.model.data.AppInfo) IntArray(com.android.launcher3.util.IntArray) PendingAddItemInfo(com.android.launcher3.PendingAddItemInfo) ButtonDropTarget(com.android.launcher3.ButtonDropTarget) BubbleTextView(com.android.launcher3.BubbleTextView) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) Workspace(com.android.launcher3.Workspace)

Example 40 with AppInfo

use of com.android.launcher3.model.data.AppInfo in project android_packages_apps_Trebuchet by LineageOS.

the class LauncherAccessibilityDelegate method addSupportedActions.

public void addSupportedActions(View host, AccessibilityNodeInfo info, boolean fromKeyboard) {
    if (!(host.getTag() instanceof ItemInfo))
        return;
    ItemInfo item = (ItemInfo) host.getTag();
    if (host instanceof AccessibilityActionHandler) {
        ((AccessibilityActionHandler) host).addSupportedAccessibilityActions(info);
    }
    // exposed as a direct shortcut
    if (!fromKeyboard && ShortcutUtil.supportsShortcuts(item)) {
        info.addAction(mActions.get(NotificationListener.getInstanceIfConnected() != null ? SHORTCUTS_AND_NOTIFICATIONS : DEEP_SHORTCUTS));
    }
    for (ButtonDropTarget target : mLauncher.getDropTargetBar().getDropTargets()) {
        if (target.supportsAccessibilityDrop(item, host)) {
            info.addAction(mActions.get(target.getAccessibilityAction()));
        }
    }
    // Do not add move actions for keyboard request as this uses virtual nodes.
    if (!fromKeyboard && itemSupportsAccessibleDrag(item)) {
        info.addAction(mActions.get(MOVE));
        if (item.container >= 0) {
            info.addAction(mActions.get(MOVE_TO_WORKSPACE));
        } else if (item instanceof LauncherAppWidgetInfo) {
            if (!getSupportedResizeActions(host, (LauncherAppWidgetInfo) item).isEmpty()) {
                info.addAction(mActions.get(RESIZE));
            }
        }
    }
    if (!fromKeyboard && !itemSupportsLongClick(host, item)) {
        info.setLongClickable(false);
        info.removeAction(AccessibilityAction.ACTION_LONG_CLICK);
    }
    if ((item instanceof AppInfo) || (item instanceof PendingAddItemInfo)) {
        info.addAction(mActions.get(ADD_TO_WORKSPACE));
    }
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) PendingAddItemInfo(com.android.launcher3.PendingAddItemInfo) ButtonDropTarget(com.android.launcher3.ButtonDropTarget) PendingAddItemInfo(com.android.launcher3.PendingAddItemInfo) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) AppInfo(com.android.launcher3.model.data.AppInfo)

Aggregations

AppInfo (com.android.launcher3.model.data.AppInfo)181 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)86 ItemInfo (com.android.launcher3.model.data.ItemInfo)46 ArrayList (java.util.ArrayList)46 ComponentName (android.content.ComponentName)36 AppInfo (com.android.launcher3.AppInfo)33 View (android.view.View)32 LauncherActivityInfo (android.content.pm.LauncherActivityInfo)31 Intent (android.content.Intent)30 FolderInfo (com.android.launcher3.model.data.FolderInfo)30 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)30 UserHandle (android.os.UserHandle)21 PackageItemInfo (com.android.launcher3.model.data.PackageItemInfo)21 PendingAddShortcutInfo (com.android.launcher3.widget.PendingAddShortcutInfo)21 Point (android.graphics.Point)19 BubbleTextView (com.android.launcher3.BubbleTextView)19 LauncherApps (android.content.pm.LauncherApps)17 ItemInfoWithIcon (com.android.launcher3.model.data.ItemInfoWithIcon)17 PendingAddItemInfo (com.android.launcher3.PendingAddItemInfo)15 AppWidgetHostView (android.appwidget.AppWidgetHostView)14