Search in sources :

Example 16 with DragView

use of com.android.launcher3.dragndrop.DragView in project android_packages_apps_Launcher3 by crdroidandroid.

the class Workspace method animateWidgetDrop.

public void animateWidgetDrop(ItemInfo info, CellLayout cellLayout, final DragView dragView, final Runnable onCompleteRunnable, int animationType, final View finalView, boolean external) {
    Rect from = new Rect();
    mLauncher.getDragLayer().getViewRectRelativeToSelf(dragView, from);
    int[] finalPos = new int[2];
    float[] scaleXY = new float[2];
    boolean scalePreview = !(info instanceof PendingAddShortcutInfo);
    getFinalPositionForDropAnimation(finalPos, scaleXY, dragView, cellLayout, info, mTargetCell, scalePreview);
    Resources res = mLauncher.getResources();
    final int duration = res.getInteger(R.integer.config_dropAnimMaxDuration) - 200;
    boolean isWidget = info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET || info.itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET;
    if ((animationType == ANIMATE_INTO_POSITION_AND_RESIZE || external) && finalView != null && dragView.getContentView() != finalView) {
        Drawable crossFadeDrawable = createWidgetDrawable(info, finalView);
        dragView.crossFadeContent(crossFadeDrawable, (int) (duration * 0.8f));
    } else if (isWidget && external) {
        scaleXY[0] = scaleXY[1] = Math.min(scaleXY[0], scaleXY[1]);
    }
    DragLayer dragLayer = mLauncher.getDragLayer();
    if (animationType == CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION) {
        mLauncher.getDragLayer().animateViewIntoPosition(dragView, finalPos, 0f, 0.1f, 0.1f, DragLayer.ANIMATION_END_DISAPPEAR, onCompleteRunnable, duration);
    } else {
        int endStyle;
        if (animationType == ANIMATE_INTO_POSITION_AND_REMAIN) {
            endStyle = DragLayer.ANIMATION_END_REMAIN_VISIBLE;
        } else {
            endStyle = DragLayer.ANIMATION_END_DISAPPEAR;
        }
        Runnable onComplete = new Runnable() {

            @Override
            public void run() {
                if (finalView != null) {
                    finalView.setVisibility(VISIBLE);
                }
                if (onCompleteRunnable != null) {
                    onCompleteRunnable.run();
                }
            }
        };
        dragLayer.animateViewIntoPosition(dragView, from.left, from.top, finalPos[0], finalPos[1], 1, 1, 1, scaleXY[0], scaleXY[1], onComplete, endStyle, duration, this);
    }
}
Also used : Rect(android.graphics.Rect) DragLayer(com.android.launcher3.dragndrop.DragLayer) PendingAddShortcutInfo(com.android.launcher3.widget.PendingAddShortcutInfo) Drawable(android.graphics.drawable.Drawable) PreloadIconDrawable(com.android.launcher3.graphics.PreloadIconDrawable) FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) Resources(android.content.res.Resources) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 17 with DragView

use of com.android.launcher3.dragndrop.DragView in project android_packages_apps_Launcher3 by crdroidandroid.

the class Workspace method createUserFolderIfNecessary.

boolean createUserFolderIfNecessary(View newView, int container, CellLayout target, int[] targetCell, float distance, boolean external, DragObject d) {
    if (distance > mMaxDistanceForFolderCreation)
        return false;
    View v = target.getChildAt(targetCell[0], targetCell[1]);
    boolean hasntMoved = false;
    if (mDragInfo != null) {
        CellLayout cellParent = getParentCellLayoutForView(mDragInfo.cell);
        hasntMoved = (mDragInfo.cellX == targetCell[0] && mDragInfo.cellY == targetCell[1]) && (cellParent == target);
    }
    if (v == null || hasntMoved || !mCreateUserFolderOnDrop)
        return false;
    mCreateUserFolderOnDrop = false;
    final int screenId = getIdForScreen(target);
    boolean aboveShortcut = (v.getTag() instanceof WorkspaceItemInfo);
    boolean willBecomeShortcut = (newView.getTag() instanceof WorkspaceItemInfo);
    if (aboveShortcut && willBecomeShortcut) {
        WorkspaceItemInfo sourceInfo = (WorkspaceItemInfo) newView.getTag();
        WorkspaceItemInfo destInfo = (WorkspaceItemInfo) v.getTag();
        // if the drag started here, we need to remove it from the workspace
        if (!external) {
            getParentCellLayoutForView(mDragInfo.cell).removeView(mDragInfo.cell);
        }
        Rect folderLocation = new Rect();
        float scale = mLauncher.getDragLayer().getDescendantRectRelativeToSelf(v, folderLocation);
        target.removeView(v);
        mStatsLogManager.logger().withItemInfo(destInfo).withInstanceId(d.logInstanceId).log(LauncherEvent.LAUNCHER_ITEM_DROP_FOLDER_CREATED);
        FolderIcon fi = mLauncher.addFolder(target, container, screenId, targetCell[0], targetCell[1]);
        destInfo.cellX = -1;
        destInfo.cellY = -1;
        sourceInfo.cellX = -1;
        sourceInfo.cellY = -1;
        // If the dragView is null, we can't animate
        boolean animate = d != null;
        if (animate) {
            // In order to keep everything continuous, we hand off the currently rendered
            // folder background to the newly created icon. This preserves animation state.
            fi.setFolderBackground(mFolderCreateBg);
            mFolderCreateBg = new PreviewBackground();
            fi.performCreateAnimation(destInfo, v, sourceInfo, d, folderLocation, scale);
        } else {
            fi.prepareCreateAnimation(v);
            fi.addItem(destInfo);
            fi.addItem(sourceInfo);
        }
        return true;
    }
    return false;
}
Also used : Rect(android.graphics.Rect) PreviewBackground(com.android.launcher3.folder.PreviewBackground) FolderIcon(com.android.launcher3.folder.FolderIcon) 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) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 18 with DragView

use of com.android.launcher3.dragndrop.DragView in project android_packages_apps_Launcher3 by crdroidandroid.

the class Workspace method beginDragShared.

/**
 * Core functionality for beginning a drag operation for an item that will be dropped within
 * the workspace
 */
public DragView beginDragShared(View child, DraggableView draggableView, DragSource source, ItemInfo dragObject, DragPreviewProvider previewProvider, DragOptions dragOptions) {
    float iconScale = 1f;
    if (child instanceof BubbleTextView) {
        Drawable icon = ((BubbleTextView) child).getIcon();
        if (icon instanceof FastBitmapDrawable) {
            iconScale = ((FastBitmapDrawable) icon).getAnimatedScale();
        }
    }
    // Clear the pressed state if necessary
    child.clearFocus();
    child.setPressed(false);
    if (child instanceof BubbleTextView) {
        BubbleTextView icon = (BubbleTextView) child;
        icon.clearPressedBackground();
    }
    mOutlineProvider = previewProvider;
    if (draggableView == null && child instanceof DraggableView) {
        draggableView = (DraggableView) child;
    }
    final View contentView = previewProvider.getContentView();
    final float scale;
    // The draggable drawable follows the touch point around on the screen
    final Drawable drawable;
    if (contentView == null) {
        drawable = previewProvider.createDrawable();
        scale = previewProvider.getScaleAndPosition(drawable, mTempXY);
    } else {
        drawable = null;
        scale = previewProvider.getScaleAndPosition(contentView, mTempXY);
    }
    int halfPadding = previewProvider.previewPadding / 2;
    int dragLayerX = mTempXY[0];
    int dragLayerY = mTempXY[1];
    Point dragVisualizeOffset = null;
    Rect dragRect = new Rect();
    if (draggableView != null) {
        draggableView.getSourceVisualDragBounds(dragRect);
        dragLayerY += dragRect.top;
        dragVisualizeOffset = new Point(-halfPadding, halfPadding);
    }
    if (child.getParent() instanceof ShortcutAndWidgetContainer) {
        mDragSourceInternal = (ShortcutAndWidgetContainer) child.getParent();
    }
    if (child instanceof BubbleTextView && !dragOptions.isAccessibleDrag) {
        PopupContainerWithArrow popupContainer = PopupContainerWithArrow.showForIcon((BubbleTextView) child);
        if (popupContainer != null) {
            dragOptions.preDragCondition = popupContainer.createPreDragCondition();
        }
    }
    final DragView dv;
    if (contentView instanceof View) {
        if (contentView instanceof LauncherAppWidgetHostView) {
            mDragController.addDragListener(new AppWidgetHostViewDragListener(mLauncher));
        }
        dv = mDragController.startDrag(contentView, draggableView, dragLayerX, dragLayerY, source, dragObject, dragVisualizeOffset, dragRect, scale * iconScale, scale, dragOptions);
    } else {
        dv = mDragController.startDrag(drawable, draggableView, dragLayerX, dragLayerY, source, dragObject, dragVisualizeOffset, dragRect, scale * iconScale, scale, dragOptions);
    }
    return dv;
}
Also used : Rect(android.graphics.Rect) Drawable(android.graphics.drawable.Drawable) PreloadIconDrawable(com.android.launcher3.graphics.PreloadIconDrawable) FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) DragView(com.android.launcher3.dragndrop.DragView) Point(android.graphics.Point) DraggableView(com.android.launcher3.dragndrop.DraggableView) 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) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) AppWidgetHostViewDragListener(com.android.launcher3.widget.dragndrop.AppWidgetHostViewDragListener) PopupContainerWithArrow(com.android.launcher3.popup.PopupContainerWithArrow) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView)

Example 19 with DragView

use of com.android.launcher3.dragndrop.DragView in project android_packages_apps_Launcher3 by crdroidandroid.

the class Workspace method addExtraEmptyScreenOnDrag.

private void addExtraEmptyScreenOnDrag(DragObject dragObject) {
    boolean lastChildOnScreen = false;
    boolean childOnFinalScreen = false;
    if (mDragSourceInternal != null) {
        // When the drag view content is a LauncherAppWidgetHostView, we should increment the
        // drag source child count by 1 because the widget in drag has been detached from its
        // original parent, ShortcutAndWidgetContainer, and reattached to the DragView.
        int dragSourceChildCount = dragObject.dragView.getContentView() instanceof LauncherAppWidgetHostView ? mDragSourceInternal.getChildCount() + 1 : mDragSourceInternal.getChildCount();
        if (dragSourceChildCount == 1) {
            lastChildOnScreen = true;
        }
        CellLayout cl = (CellLayout) mDragSourceInternal.getParent();
        if (indexOfChild(cl) == getChildCount() - 1) {
            childOnFinalScreen = true;
        }
    }
    // If this is the last item on the final screen
    if (lastChildOnScreen && childOnFinalScreen) {
        return;
    }
    if (!mWorkspaceScreens.containsKey(EXTRA_EMPTY_SCREEN_ID)) {
        insertNewWorkspaceScreen(EXTRA_EMPTY_SCREEN_ID);
    }
}
Also used : LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 20 with DragView

use of com.android.launcher3.dragndrop.DragView in project android_packages_apps_Launcher3 by crdroidandroid.

the class FloatingIconView method getIconResult.

/**
 * Loads the icon and saves the results to {@link #sIconLoadResult}.
 * Runs onIconLoaded callback (if any), which signifies that the FloatingIconView is
 * ready to display the icon. Otherwise, the FloatingIconView will grab the results when its
 * initialized.
 *
 * @param originalView The View that the FloatingIconView will replace.
 * @param info ItemInfo of the originalView
 * @param pos The position of the view.
 */
@WorkerThread
@SuppressWarnings("WrongThread")
private static void getIconResult(Launcher l, View originalView, ItemInfo info, RectF pos, Drawable btvIcon, IconLoadResult iconLoadResult) {
    Drawable drawable;
    boolean supportsAdaptiveIcons = ADAPTIVE_ICON_WINDOW_ANIM.get() && // Use original icon for disabled icons.
    !info.isDisabled();
    Drawable badge = null;
    if (info instanceof SystemShortcut) {
        if (originalView instanceof ImageView) {
            drawable = ((ImageView) originalView).getDrawable();
        } else if (originalView instanceof DeepShortcutView) {
            drawable = ((DeepShortcutView) originalView).getIconView().getBackground();
        } else {
            drawable = originalView.getBackground();
        }
    } else if (btvIcon instanceof PreloadIconDrawable) {
        // Force the progress bar to display.
        drawable = btvIcon;
    } else {
        int width = (int) pos.width();
        int height = (int) pos.height();
        if (supportsAdaptiveIcons) {
            drawable = getFullDrawable(l, info, width, height, sTmpObjArray);
            if (drawable instanceof AdaptiveIconDrawable) {
                badge = getBadge(l, info, sTmpObjArray[0]);
            } else {
                // The drawable we get back is not an adaptive icon, so we need to use the
                // BubbleTextView icon that is already legacy treated.
                drawable = btvIcon;
            }
        } else {
            if (originalView instanceof BubbleTextView) {
                // Similar to DragView, we simply use the BubbleTextView icon here.
                drawable = btvIcon;
            } else {
                drawable = getFullDrawable(l, info, width, height, sTmpObjArray);
            }
        }
    }
    drawable = drawable == null ? null : drawable.getConstantState().newDrawable();
    int iconOffset = getOffsetForIconBounds(l, drawable, pos);
    synchronized (iconLoadResult) {
        iconLoadResult.btvDrawable = btvIcon == null || drawable == btvIcon ? null : btvIcon.getConstantState().newDrawable();
        iconLoadResult.drawable = drawable;
        iconLoadResult.badge = badge;
        iconLoadResult.iconOffset = iconOffset;
        if (iconLoadResult.onIconLoaded != null) {
            l.getMainExecutor().execute(iconLoadResult.onIconLoaded);
            iconLoadResult.onIconLoaded = null;
        }
        iconLoadResult.isIconLoaded = true;
    }
}
Also used : SystemShortcut(com.android.launcher3.popup.SystemShortcut) AdaptiveIconDrawable(android.graphics.drawable.AdaptiveIconDrawable) Drawable(android.graphics.drawable.Drawable) PreloadIconDrawable(com.android.launcher3.graphics.PreloadIconDrawable) Utilities.getFullDrawable(com.android.launcher3.Utilities.getFullDrawable) FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) ImageView(android.widget.ImageView) BubbleTextView(com.android.launcher3.BubbleTextView) AdaptiveIconDrawable(android.graphics.drawable.AdaptiveIconDrawable) DeepShortcutView(com.android.launcher3.shortcuts.DeepShortcutView) PreloadIconDrawable(com.android.launcher3.graphics.PreloadIconDrawable) WorkerThread(androidx.annotation.WorkerThread)

Aggregations

Point (android.graphics.Point)14 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)13 SuppressLint (android.annotation.SuppressLint)12 Rect (android.graphics.Rect)11 View (android.view.View)11 DragView (com.android.launcher3.dragndrop.DragView)8 Paint (android.graphics.Paint)7 CellAndSpan (com.android.launcher3.util.CellAndSpan)5 AppWidgetHostView (android.appwidget.AppWidgetHostView)4 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)4 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)4 Drawable (android.graphics.drawable.Drawable)3 PreloadIconDrawable (com.android.launcher3.graphics.PreloadIconDrawable)3 FastBitmapDrawable (com.android.launcher3.icons.FastBitmapDrawable)3 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)2 Resources (android.content.res.Resources)2 BubbleTextView (com.android.launcher3.BubbleTextView)2 CellLayout (com.android.launcher3.CellLayout)2 Launcher (com.android.launcher3.Launcher)2 Workspace (com.android.launcher3.Workspace)2