Search in sources :

Example 1 with PreviewBackground

use of com.android.launcher3.folder.PreviewBackground in project android_packages_apps_Launcher3 by crdroidandroid.

the class Workspace method manageFolderFeedback.

private void manageFolderFeedback(float distance, DragObject dragObject) {
    if (distance > mMaxDistanceForFolderCreation) {
        if ((mDragMode == DRAG_MODE_ADD_TO_FOLDER || mDragMode == DRAG_MODE_CREATE_FOLDER)) {
            setDragMode(DRAG_MODE_NONE);
        }
        return;
    }
    final View dragOverView = mDragTargetLayout.getChildAt(mTargetCell[0], mTargetCell[1]);
    ItemInfo info = dragObject.dragInfo;
    boolean userFolderPending = willCreateUserFolder(info, dragOverView, false);
    if (mDragMode == DRAG_MODE_NONE && userFolderPending) {
        mFolderCreateBg = new PreviewBackground();
        mFolderCreateBg.setup(mLauncher, mLauncher, null, dragOverView.getMeasuredWidth(), dragOverView.getPaddingTop());
        // The full preview background should appear behind the icon
        mFolderCreateBg.isClipping = false;
        mFolderCreateBg.animateToAccept(mDragTargetLayout, mTargetCell[0], mTargetCell[1]);
        mDragTargetLayout.clearDragOutlines();
        setDragMode(DRAG_MODE_CREATE_FOLDER);
        if (dragObject.stateAnnouncer != null) {
            dragObject.stateAnnouncer.announce(WorkspaceAccessibilityHelper.getDescriptionForDropOver(dragOverView, getContext()));
        }
        return;
    }
    boolean willAddToFolder = willAddToExistingUserFolder(info, dragOverView);
    if (willAddToFolder && mDragMode == DRAG_MODE_NONE) {
        mDragOverFolderIcon = ((FolderIcon) dragOverView);
        mDragOverFolderIcon.onDragEnter(info);
        if (mDragTargetLayout != null) {
            mDragTargetLayout.clearDragOutlines();
        }
        setDragMode(DRAG_MODE_ADD_TO_FOLDER);
        if (dragObject.stateAnnouncer != null) {
            dragObject.stateAnnouncer.announce(WorkspaceAccessibilityHelper.getDescriptionForDropOver(dragOverView, getContext()));
        }
        return;
    }
    if (mDragMode == DRAG_MODE_ADD_TO_FOLDER && !willAddToFolder) {
        setDragMode(DRAG_MODE_NONE);
    }
    if (mDragMode == DRAG_MODE_CREATE_FOLDER && !userFolderPending) {
        setDragMode(DRAG_MODE_NONE);
    }
}
Also used : WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ItemInfo(com.android.launcher3.model.data.ItemInfo) 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)

Example 2 with PreviewBackground

use of com.android.launcher3.folder.PreviewBackground in project android_packages_apps_Launcher3 by crdroidandroid.

the class FolderAdaptiveIcon method createDrawableOnUiThread.

private static FolderAdaptiveIcon createDrawableOnUiThread(FolderIcon icon, Point dragViewSize) {
    Preconditions.assertUIThread();
    icon.getPreviewBounds(sTmpRect);
    PreviewBackground bg = icon.getFolderBackground();
    // assume square
    assert (dragViewSize.x == dragViewSize.y);
    final int previewSize = sTmpRect.width();
    final int margin = (dragViewSize.x - previewSize) / 2;
    final float previewShiftX = -sTmpRect.left + margin;
    final float previewShiftY = -sTmpRect.top + margin;
    // Initialize badge, which consists of the outline stroke, shadow and dot; these
    // must be rendered above the foreground
    Bitmap badgeBmp = BitmapRenderer.createHardwareBitmap(dragViewSize.x, dragViewSize.y, (canvas) -> {
        canvas.save();
        canvas.translate(previewShiftX, previewShiftY);
        bg.drawShadow(canvas);
        bg.drawBackgroundStroke(canvas);
        icon.drawDot(canvas);
        canvas.restore();
    });
    // Initialize mask
    Path mask = new Path();
    Matrix m = new Matrix();
    m.setTranslate(previewShiftX, previewShiftY);
    bg.getClipPath().transform(m, mask);
    Bitmap previewBitmap = BitmapRenderer.createHardwareBitmap(dragViewSize.x, dragViewSize.y, (canvas) -> {
        canvas.save();
        canvas.translate(previewShiftX, previewShiftY);
        icon.getPreviewItemManager().draw(canvas);
        canvas.restore();
    });
    Bitmap bgBitmap = BitmapRenderer.createHardwareBitmap(dragViewSize.x, dragViewSize.y, (canvas) -> {
        Paint p = new Paint();
        p.setColor(bg.getBgColor());
        canvas.drawCircle(dragViewSize.x / 2f, dragViewSize.y / 2f, bg.getRadius(), p);
    });
    ShiftedBitmapDrawable badge = new ShiftedBitmapDrawable(badgeBmp, 0, 0);
    ShiftedBitmapDrawable foreground = new ShiftedBitmapDrawable(previewBitmap, 0, 0);
    ShiftedBitmapDrawable background = new ShiftedBitmapDrawable(bgBitmap, 0, 0);
    return new FolderAdaptiveIcon(background, foreground, badge, mask);
}
Also used : Path(android.graphics.Path) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) PreviewBackground(com.android.launcher3.folder.PreviewBackground) ShiftedBitmapDrawable(com.android.launcher3.graphics.ShiftedBitmapDrawable) Paint(android.graphics.Paint) Point(android.graphics.Point) Paint(android.graphics.Paint)

Example 3 with PreviewBackground

use of com.android.launcher3.folder.PreviewBackground 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)

Aggregations

PreviewBackground (com.android.launcher3.folder.PreviewBackground)3 AppWidgetHostView (android.appwidget.AppWidgetHostView)2 Point (android.graphics.Point)2 View (android.view.View)2 DragView (com.android.launcher3.dragndrop.DragView)2 DraggableView (com.android.launcher3.dragndrop.DraggableView)2 FolderIcon (com.android.launcher3.folder.FolderIcon)2 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)2 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)2 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)2 SuppressLint (android.annotation.SuppressLint)1 Bitmap (android.graphics.Bitmap)1 Matrix (android.graphics.Matrix)1 Paint (android.graphics.Paint)1 Path (android.graphics.Path)1 Rect (android.graphics.Rect)1 ShiftedBitmapDrawable (com.android.launcher3.graphics.ShiftedBitmapDrawable)1 ItemInfo (com.android.launcher3.model.data.ItemInfo)1