Search in sources :

Example 1 with DragObject

use of com.android.launcher2.DropTarget.DragObject in project android_packages_apps_Launcher2 by CyanogenMod.

the class LauncherTransitionable method completeAddShortcut.

/**
     * Add a shortcut to the workspace.
     *
     * @param data The intent describing the shortcut.
     * @param cellInfo The position on screen where to create the shortcut.
     */
private void completeAddShortcut(Intent data, long container, int screen, int cellX, int cellY) {
    int[] cellXY = mTmpAddItemCellCoordinates;
    int[] touchXY = mPendingAddInfo.dropPos;
    CellLayout layout = getCellLayout(container, screen);
    boolean foundCellSpan = false;
    ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
    if (info == null) {
        return;
    }
    final View view = createShortcut(info);
    // 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;
        // If appropriate, either create a folder or add to an existing folder
        if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0, true, null, null)) {
            return;
        }
        DragObject dragObject = new DragObject();
        dragObject.dragInfo = info;
        if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject, true)) {
            return;
        }
    } else if (touchXY != null) {
        // when dragging and dropping, just find the closest free spot
        int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
        foundCellSpan = (result != null);
    } else {
        foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
    }
    if (!foundCellSpan) {
        showOutOfSpaceMessage(isHotseatLayout(layout));
        return;
    }
    LauncherModel.addItemToDatabase(this, info, container, screen, cellXY[0], cellXY[1], false);
    if (!mRestoring) {
        mWorkspace.addInScreen(view, container, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
    }
}
Also used : DragObject(com.android.launcher2.DropTarget.DragObject) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) AppWidgetHostView(android.appwidget.AppWidgetHostView)

Example 2 with DragObject

use of com.android.launcher2.DropTarget.DragObject in project Launcher3 by chislon.

the class LauncherTransitionable method completeAddShortcut.

/**
     * Add a shortcut to the workspace.
     *
     * @param data The intent describing the shortcut.
     * @param cellInfo The position on screen where to create the shortcut.
     */
private void completeAddShortcut(Intent data, long container, long screenId, int cellX, int cellY) {
    int[] cellXY = mTmpAddItemCellCoordinates;
    int[] touchXY = mPendingAddInfo.dropPos;
    CellLayout layout = getCellLayout(container, screenId);
    boolean foundCellSpan = false;
    ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
    if (info == null) {
        return;
    }
    final View view = createShortcut(info);
    // 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;
        // If appropriate, either create a folder or add to an existing folder
        if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0, true, null, null)) {
            return;
        }
        DragObject dragObject = new DragObject();
        dragObject.dragInfo = info;
        if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject, true)) {
            return;
        }
    } else if (touchXY != null) {
        // when dragging and dropping, just find the closest free spot
        int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
        foundCellSpan = (result != null);
    } else {
        foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
    }
    if (!foundCellSpan) {
        showOutOfSpaceMessage(isHotseatLayout(layout));
        return;
    }
    LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
    if (!mRestoring) {
        mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
    }
}
Also used : DragObject(com.android.launcher3.DropTarget.DragObject) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) AppWidgetHostView(android.appwidget.AppWidgetHostView)

Aggregations

AppWidgetHostView (android.appwidget.AppWidgetHostView)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 DragObject (com.android.launcher2.DropTarget.DragObject)1 DragObject (com.android.launcher3.DropTarget.DragObject)1