Search in sources :

Example 81 with WorkspaceItemInfo

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

the class WorkspaceAccessibilityHelper method intersectsValidDropTarget.

/**
 * Find the virtual view id corresponding to the top left corner of any drop region by which
 * the passed id is contained. For an icon, this is simply
 */
@Override
protected int intersectsValidDropTarget(int id) {
    int mCountX = mView.getCountX();
    int mCountY = mView.getCountY();
    int x = id % mCountX;
    int y = id / mCountX;
    LauncherAccessibilityDelegate.DragInfo dragInfo = mDelegate.getDragInfo();
    if (dragInfo.dragType == DragType.WIDGET && !mView.acceptsWidget()) {
        return INVALID_POSITION;
    }
    if (dragInfo.dragType == DragType.WIDGET) {
        // For a widget, every cell must be vacant. In addition, we will return any valid
        // drop target by which the passed id is contained.
        boolean fits = false;
        // These represent the amount that we can back off if we hit a problem. They
        // get consumed as we move up and to the right, trying new regions.
        int spanX = dragInfo.info.spanX;
        int spanY = dragInfo.info.spanY;
        for (int m = 0; m < spanX; m++) {
            for (int n = 0; n < spanY; n++) {
                fits = true;
                int x0 = x - m;
                int y0 = y - n;
                if (x0 < 0 || y0 < 0)
                    continue;
                for (int i = x0; i < x0 + spanX; i++) {
                    if (!fits)
                        break;
                    for (int j = y0; j < y0 + spanY; j++) {
                        if (i >= mCountX || j >= mCountY || mView.isOccupied(i, j)) {
                            fits = false;
                            break;
                        }
                    }
                }
                if (fits) {
                    return x0 + mCountX * y0;
                }
            }
        }
        return INVALID_POSITION;
    } else {
        // For an icon, we simply check the view directly below
        View child = mView.getChildAt(x, y);
        if (child == null || child == dragInfo.item) {
            // Empty cell. Good for an icon or folder.
            return id;
        } else if (dragInfo.dragType != DragType.FOLDER) {
            // For icons, we can consider cells that have another icon or a folder.
            ItemInfo info = (ItemInfo) child.getTag();
            if (info instanceof AppInfo || info instanceof FolderInfo || info instanceof WorkspaceItemInfo) {
                return id;
            }
        }
        return INVALID_POSITION;
    }
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) View(android.view.View) FolderInfo(com.android.launcher3.model.data.FolderInfo) AppInfo(com.android.launcher3.model.data.AppInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 82 with WorkspaceItemInfo

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

the class Launcher method removeItem.

/**
 * Unbinds the view for the specified item, and removes the item and all its children.
 *
 * @param v the view being removed.
 * @param itemInfo the {@link ItemInfo} for this view.
 * @param deleteFromDb whether or not to delete this item from the db.
 */
public boolean removeItem(View v, final ItemInfo itemInfo, boolean deleteFromDb) {
    if (itemInfo instanceof WorkspaceItemInfo) {
        // Remove the shortcut from the folder before removing it from launcher
        View folderIcon = mWorkspace.getHomescreenIconByItemId(itemInfo.container);
        if (folderIcon instanceof FolderIcon) {
            ((FolderInfo) folderIcon.getTag()).remove((WorkspaceItemInfo) itemInfo, true);
        } else {
            mWorkspace.removeWorkspaceItem(v);
        }
        if (deleteFromDb) {
            getModelWriter().deleteItemFromDatabase(itemInfo);
        }
    } else if (itemInfo instanceof FolderInfo) {
        final FolderInfo folderInfo = (FolderInfo) itemInfo;
        if (v instanceof FolderIcon) {
            ((FolderIcon) v).removeListeners();
        }
        mWorkspace.removeWorkspaceItem(v);
        if (deleteFromDb) {
            getModelWriter().deleteFolderAndContentsFromDatabase(folderInfo);
        }
    } else if (itemInfo instanceof LauncherAppWidgetInfo) {
        final LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) itemInfo;
        mWorkspace.removeWorkspaceItem(v);
        if (deleteFromDb) {
            getModelWriter().deleteWidgetInfo(widgetInfo, getAppWidgetHost());
        }
    } else {
        return false;
    }
    return true;
}
Also used : FolderIcon(com.android.launcher3.folder.FolderIcon) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) QsbContainerView(com.android.launcher3.qsb.QsbContainerView) FloatingSurfaceView(com.android.launcher3.views.FloatingSurfaceView) AppWidgetHostView(android.appwidget.AppWidgetHostView) OptionsPopupView(com.android.launcher3.views.OptionsPopupView) View(android.view.View) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) AllAppsContainerView(com.android.launcher3.allapps.AllAppsContainerView) ScrimView(com.android.launcher3.views.ScrimView) DragView(com.android.launcher3.dragndrop.DragView) FolderInfo(com.android.launcher3.model.data.FolderInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 83 with WorkspaceItemInfo

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

the class Launcher method completeAddShortcut.

/**
 * Add a shortcut to the workspace or to a Folder.
 *
 * @param data The intent describing the shortcut.
 */
private void completeAddShortcut(Intent data, int container, int screenId, int cellX, int cellY, PendingRequestArgs args) {
    if (args.getRequestCode() != REQUEST_CREATE_SHORTCUT || args.getPendingIntent().getComponent() == null) {
        return;
    }
    int[] cellXY = mTmpAddItemCellCoordinates;
    CellLayout layout = getCellLayout(container, screenId);
    WorkspaceItemInfo info = null;
    if (Utilities.ATLEAST_OREO) {
        info = PinRequestHelper.createWorkspaceItemFromPinItemRequest(this, PinRequestHelper.getPinItemRequest(data), 0);
    }
    if (info == null) {
        // Legacy shortcuts are only supported for primary profile.
        info = Process.myUserHandle().equals(args.user) ? InstallShortcutReceiver.fromShortcutIntent(this, data) : null;
        if (info == null) {
            Log.e(TAG, "Unable to parse a valid custom shortcut result");
            return;
        } else if (!new PackageManagerHelper(this).hasPermissionForActivity(info.intent, args.getPendingIntent().getComponent().getPackageName())) {
            // The app is trying to add a shortcut without sufficient permissions
            Log.e(TAG, "Ignoring malicious intent " + info.intent.toUri(0));
            return;
        }
    }
    if (container < 0) {
        // Adding a shortcut to the Workspace.
        final View view = createShortcut(info);
        boolean foundCellSpan = false;
        // First we check if we already know the exact location where we want to add this item.
        if (cellX >= 0 && cellY >= 0) {
            cellXY[0] = cellX;
            cellXY[1] = cellY;
            foundCellSpan = true;
            DragObject dragObject = new DragObject(getApplicationContext());
            dragObject.dragInfo = info;
            // If appropriate, either create a folder or add to an existing folder
            if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0, true, dragObject)) {
                return;
            }
            if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject, true)) {
                return;
            }
        } else {
            foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
        }
        if (!foundCellSpan) {
            mWorkspace.onNoCellFound(layout);
            return;
        }
        getModelWriter().addItemToDatabase(info, container, screenId, cellXY[0], cellXY[1]);
        mWorkspace.addInScreen(view, info);
    } else {
        // Adding a shortcut to a Folder.
        FolderIcon folderIcon = findFolderIcon(container);
        if (folderIcon != null) {
            FolderInfo folderInfo = (FolderInfo) folderIcon.getTag();
            folderInfo.add(info, args.rank, false);
        } else {
            Log.e(TAG, "Could not find folder with id " + container + " to add shortcut.");
        }
    }
}
Also used : FolderIcon(com.android.launcher3.folder.FolderIcon) DragObject(com.android.launcher3.DropTarget.DragObject) PackageManagerHelper(com.android.launcher3.util.PackageManagerHelper) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) QsbContainerView(com.android.launcher3.qsb.QsbContainerView) FloatingSurfaceView(com.android.launcher3.views.FloatingSurfaceView) AppWidgetHostView(android.appwidget.AppWidgetHostView) OptionsPopupView(com.android.launcher3.views.OptionsPopupView) View(android.view.View) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) AllAppsContainerView(com.android.launcher3.allapps.AllAppsContainerView) ScrimView(com.android.launcher3.views.ScrimView) DragView(com.android.launcher3.dragndrop.DragView) FolderInfo(com.android.launcher3.model.data.FolderInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 84 with WorkspaceItemInfo

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

the class InstallShortcutReceiver method createWorkspaceItemInfo.

private static WorkspaceItemInfo createWorkspaceItemInfo(Intent data, UserHandle user, LauncherAppState app) {
    if (data == null) {
        Log.e(TAG, "Can't construct WorkspaceItemInfo with null data");
        return null;
    }
    Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    Parcelable bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
    if (intent == null) {
        // If the intent is null, return null as we can't construct a valid WorkspaceItemInfo
        Log.e(TAG, "Can't construct WorkspaceItemInfo with null intent");
        return null;
    }
    final WorkspaceItemInfo info = new WorkspaceItemInfo();
    info.user = user;
    BitmapInfo iconInfo = null;
    LauncherIcons li = LauncherIcons.obtain(app.getContext());
    if (bitmap instanceof Bitmap) {
        iconInfo = li.createIconBitmap((Bitmap) bitmap);
    } else {
        Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
        if (extra instanceof Intent.ShortcutIconResource) {
            info.iconResource = (Intent.ShortcutIconResource) extra;
            iconInfo = li.createIconBitmap(info.iconResource);
        }
    }
    li.recycle();
    if (iconInfo == null) {
        iconInfo = app.getIconCache().getDefaultIcon(info.user);
    }
    info.bitmap = iconInfo;
    info.title = Utilities.trim(name);
    info.contentDescription = app.getContext().getPackageManager().getUserBadgedLabel(info.title, info.user);
    info.intent = intent;
    return info;
}
Also used : Bitmap(android.graphics.Bitmap) LauncherIcons(com.android.launcher3.icons.LauncherIcons) Intent(android.content.Intent) Parcelable(android.os.Parcelable) BitmapInfo(com.android.launcher3.icons.BitmapInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 85 with WorkspaceItemInfo

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

the class ItemInfoMatcher method filterItemInfos.

/**
 * Filters {@param infos} to those satisfying the {@link #matches(ItemInfo, ComponentName)}.
 */
default HashSet<ItemInfo> filterItemInfos(Iterable<ItemInfo> infos) {
    HashSet<ItemInfo> filtered = new HashSet<>();
    for (ItemInfo i : infos) {
        if (i instanceof WorkspaceItemInfo) {
            WorkspaceItemInfo info = (WorkspaceItemInfo) i;
            ComponentName cn = info.getTargetComponent();
            if (cn != null && matches(info, cn)) {
                filtered.add(info);
            }
        } else if (i instanceof FolderInfo) {
            FolderInfo info = (FolderInfo) i;
            for (WorkspaceItemInfo s : info.contents) {
                ComponentName cn = s.getTargetComponent();
                if (cn != null && matches(s, cn)) {
                    filtered.add(s);
                }
            }
        } else if (i instanceof LauncherAppWidgetInfo) {
            LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) i;
            ComponentName cn = info.providerName;
            if (cn != null && matches(info, cn)) {
                filtered.add(info);
            }
        }
    }
    return filtered;
}
Also used : WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ItemInfo(com.android.launcher3.model.data.ItemInfo) ComponentName(android.content.ComponentName) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) FolderInfo(com.android.launcher3.model.data.FolderInfo) HashSet(java.util.HashSet) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Aggregations

WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)418 View (android.view.View)168 ArrayList (java.util.ArrayList)145 ItemInfo (com.android.launcher3.model.data.ItemInfo)125 Intent (android.content.Intent)119 FolderInfo (com.android.launcher3.model.data.FolderInfo)100 AppInfo (com.android.launcher3.model.data.AppInfo)94 BubbleTextView (com.android.launcher3.BubbleTextView)87 AppWidgetHostView (android.appwidget.AppWidgetHostView)84 SuppressLint (android.annotation.SuppressLint)78 DragView (com.android.launcher3.dragndrop.DragView)78 ComponentName (android.content.ComponentName)76 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)73 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)72 Rect (android.graphics.Rect)68 FolderIcon (com.android.launcher3.folder.FolderIcon)68 Context (android.content.Context)62 HashSet (java.util.HashSet)62 Point (android.graphics.Point)59 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)57