Search in sources :

Example 41 with FolderIcon

use of com.android.launcher3.tapl.FolderIcon in project Neo-Launcher by NeoApplications.

the class PreviewItemManager method onDrop.

/**
 * Handles the case where items in the preview are either:
 *  - Moving into the preview
 *  - Moving into a new position
 *  - Moving out of the preview
 *
 * @param oldItems The list of items in the old preview.
 * @param newItems The list of items in the new preview.
 * @param dropped The item that was dropped onto the FolderIcon.
 */
public void onDrop(List<WorkspaceItemInfo> oldItems, List<WorkspaceItemInfo> newItems, WorkspaceItemInfo dropped) {
    int numItems = newItems.size();
    final ArrayList<PreviewItemDrawingParams> params = mFirstPageParams;
    buildParamsForPage(0, params, false);
    // New preview items for items that are moving in (except for the dropped item).
    List<WorkspaceItemInfo> moveIn = new ArrayList<>();
    for (WorkspaceItemInfo newItem : newItems) {
        if (!oldItems.contains(newItem) && !newItem.equals(dropped)) {
            moveIn.add(newItem);
        }
    }
    for (int i = 0; i < moveIn.size(); ++i) {
        int prevIndex = newItems.indexOf(moveIn.get(i));
        PreviewItemDrawingParams p = params.get(prevIndex);
        computePreviewItemDrawingParams(prevIndex, numItems, p);
        updateTransitionParam(p, moveIn.get(i), ENTER_INDEX, newItems.indexOf(moveIn.get(i)), numItems);
    }
    // Items that are moving into new positions within the preview.
    for (int newIndex = 0; newIndex < newItems.size(); ++newIndex) {
        int oldIndex = oldItems.indexOf(newItems.get(newIndex));
        if (oldIndex >= 0 && newIndex != oldIndex) {
            PreviewItemDrawingParams p = params.get(newIndex);
            updateTransitionParam(p, newItems.get(newIndex), oldIndex, newIndex, numItems);
        }
    }
    // Old preview items that need to be moved out.
    List<WorkspaceItemInfo> moveOut = new ArrayList<>(oldItems);
    moveOut.removeAll(newItems);
    for (int i = 0; i < moveOut.size(); ++i) {
        WorkspaceItemInfo item = moveOut.get(i);
        int oldIndex = oldItems.indexOf(item);
        PreviewItemDrawingParams p = computePreviewItemDrawingParams(oldIndex, numItems, null);
        updateTransitionParam(p, item, oldIndex, EXIT_INDEX, numItems);
        // We want these items first so that they are on drawn last.
        params.add(0, p);
    }
    for (int i = 0; i < params.size(); ++i) {
        if (params.get(i).anim != null) {
            params.get(i).anim.start();
        }
    }
}
Also used : ArrayList(java.util.ArrayList) WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo)

Example 42 with FolderIcon

use of com.android.launcher3.tapl.FolderIcon in project Neo-Launcher by NeoApplications.

the class PreviewItemManager method setDrawable.

private void setDrawable(PreviewItemDrawingParams p, WorkspaceItemInfo item) {
    if (item.hasPromiseIconUi()) {
        PreloadIconDrawable drawable = mDrawableFactory.newPendingIcon(mContext, item);
        drawable.setLevel(item.getInstallProgress());
        p.drawable = drawable;
    } else {
        p.drawable = mDrawableFactory.newIcon(mContext, item);
    }
    p.drawable.setBounds(0, 0, mIconSize, mIconSize);
    p.item = item;
    // Set the callback to FolderIcon as it is responsible to drawing the icon. The
    // callback will be released when the folder is opened.
    p.drawable.setCallback(mIcon);
}
Also used : PreloadIconDrawable(com.android.launcher3.graphics.PreloadIconDrawable)

Example 43 with FolderIcon

use of com.android.launcher3.tapl.FolderIcon in project Neo-Launcher by NeoApplications.

the class DragPreviewProvider method drawDragView.

/**
 * Draws the {@link #mView} into the given {@param destCanvas}.
 */
protected void drawDragView(Canvas destCanvas, float scale) {
    destCanvas.save();
    destCanvas.scale(scale, scale);
    if (mView instanceof BubbleTextView) {
        Drawable d = ((BubbleTextView) mView).getIcon();
        Rect bounds = getDrawableBounds(d);
        destCanvas.translate(blurSizeOutline / 2 - bounds.left, blurSizeOutline / 2 - bounds.top);
        if (d instanceof FastBitmapDrawable) {
            ((FastBitmapDrawable) d).setScale(1);
        }
        d.draw(destCanvas);
    } else {
        final Rect clipRect = mTempRect;
        mView.getDrawingRect(clipRect);
        boolean textVisible = false;
        if (mView instanceof FolderIcon) {
            // hide the text completely (which can't be achieved by clipping).
            if (((FolderIcon) mView).getTextVisible()) {
                ((FolderIcon) mView).setTextVisible(false);
                textVisible = true;
            }
        }
        destCanvas.translate(-mView.getScrollX() + blurSizeOutline / 2, -mView.getScrollY() + blurSizeOutline / 2);
        destCanvas.clipRect(clipRect);
        mView.draw(destCanvas);
        // Restore text visibility of FolderIcon if necessary
        if (textVisible) {
            ((FolderIcon) mView).setTextVisible(true);
        }
    }
    destCanvas.restore();
}
Also used : FastBitmapDrawable(com.android.launcher3.FastBitmapDrawable) Rect(android.graphics.Rect) FolderIcon(com.android.launcher3.folder.FolderIcon) Drawable(android.graphics.drawable.Drawable) FastBitmapDrawable(com.android.launcher3.FastBitmapDrawable) BubbleTextView(com.android.launcher3.BubbleTextView)

Example 44 with FolderIcon

use of com.android.launcher3.tapl.FolderIcon in project Neo-Launcher by NeoApplications.

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, IconLoadResult iconLoadResult) {
    Drawable drawable = null;
    Drawable badge = null;
    boolean supportsAdaptiveIcons = ADAPTIVE_ICON_WINDOW_ANIM.get() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
    Drawable btvIcon = originalView instanceof BubbleTextView ? ((BubbleTextView) originalView).getIcon() : 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 {
        boolean isFolderIcon = originalView instanceof FolderIcon;
        int width = isFolderIcon ? originalView.getWidth() : (int) pos.width();
        int height = isFolderIcon ? originalView.getHeight() : (int) pos.height();
        if (supportsAdaptiveIcons) {
            drawable = getFullDrawable(l, info, width, height, false, 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, false, sTmpObjArray);
            }
        }
    }
    drawable = drawable == null ? null : drawable.getConstantState().newDrawable();
    int iconOffset = getOffsetForIconBounds(l, drawable, pos);
    synchronized (iconLoadResult) {
        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) FolderIcon(com.android.launcher3.folder.FolderIcon) AdaptiveIconDrawable(android.graphics.drawable.AdaptiveIconDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) ShiftedBitmapDrawable(com.android.launcher3.graphics.ShiftedBitmapDrawable) Utilities.getFullDrawable(com.android.launcher3.Utilities.getFullDrawable) ImageView(android.widget.ImageView) BubbleTextView(com.android.launcher3.BubbleTextView) AdaptiveIconDrawable(android.graphics.drawable.AdaptiveIconDrawable) DeepShortcutView(com.android.launcher3.shortcuts.DeepShortcutView) WorkerThread(androidx.annotation.WorkerThread)

Example 45 with FolderIcon

use of com.android.launcher3.tapl.FolderIcon in project Neo-Launcher by NeoApplications.

the class FloatingIconView method getLocationBoundsForView.

/**
 * Gets the location bounds of a view and returns the overall rotation.
 * - For DeepShortcutView, we return the bounds of the icon view.
 * - For BubbleTextView, we return the icon bounds.
 */
private static float getLocationBoundsForView(Launcher launcher, View v, boolean isOpening, RectF outRect) {
    boolean ignoreTransform = !isOpening;
    if (v instanceof DeepShortcutView) {
        v = ((DeepShortcutView) v).getBubbleText();
        ignoreTransform = false;
    } else if (v.getParent() instanceof DeepShortcutView) {
        v = ((DeepShortcutView) v.getParent()).getIconView();
        ignoreTransform = false;
    }
    if (v == null) {
        return 0;
    }
    Rect iconBounds = new Rect();
    if (v instanceof BubbleTextView) {
        ((BubbleTextView) v).getIconBounds(iconBounds);
    } else if (v instanceof FolderIcon) {
        ((FolderIcon) v).getPreviewBounds(iconBounds);
    } else {
        iconBounds.set(0, 0, v.getWidth(), v.getHeight());
    }
    float[] points = new float[] { iconBounds.left, iconBounds.top, iconBounds.right, iconBounds.bottom };
    float[] rotation = new float[] { 0 };
    Utilities.getDescendantCoordRelativeToAncestor(v, launcher.getDragLayer(), points, false, ignoreTransform, rotation);
    outRect.set(Math.min(points[0], points[2]), Math.min(points[1], points[3]), Math.max(points[0], points[2]), Math.max(points[1], points[3]));
    return rotation[0];
}
Also used : Rect(android.graphics.Rect) FolderIcon(com.android.launcher3.folder.FolderIcon) BubbleTextView(com.android.launcher3.BubbleTextView) DeepShortcutView(com.android.launcher3.shortcuts.DeepShortcutView)

Aggregations

FolderIcon (com.android.launcher3.folder.FolderIcon)124 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)82 View (android.view.View)81 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)70 AppWidgetHostView (android.appwidget.AppWidgetHostView)62 FolderInfo (com.android.launcher3.model.data.FolderInfo)58 DragView (com.android.launcher3.dragndrop.DragView)57 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)55 ItemInfo (com.android.launcher3.model.data.ItemInfo)48 SuppressLint (android.annotation.SuppressLint)42 BubbleTextView (com.android.launcher3.BubbleTextView)41 Folder (com.android.launcher3.folder.Folder)40 Point (android.graphics.Point)37 Rect (android.graphics.Rect)37 DraggableView (com.android.launcher3.dragndrop.DraggableView)35 Drawable (android.graphics.drawable.Drawable)33 PreviewBackground (com.android.launcher3.folder.PreviewBackground)33 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)30 ArrayList (java.util.ArrayList)27 PreloadIconDrawable (com.android.launcher3.graphics.PreloadIconDrawable)25