Search in sources :

Example 66 with FolderIcon

use of com.android.launcher3.tapl.FolderIcon in project android_packages_apps_Launcher3 by ProtonAOSP.

the class Workspace method removeItemsByMatcher.

/**
 * Removes items that match the {@param matcher}. When applications are removed
 * as a part of an update, this is called to ensure that other widgets and application
 * shortcuts are not removed.
 */
public void removeItemsByMatcher(final ItemInfoMatcher matcher) {
    for (CellLayout layout : getWorkspaceAndHotseatCellLayouts()) {
        ShortcutAndWidgetContainer container = layout.getShortcutsAndWidgets();
        // Iterate in reverse order as we are removing items
        for (int i = container.getChildCount() - 1; i >= 0; i--) {
            View child = container.getChildAt(i);
            ItemInfo info = (ItemInfo) child.getTag();
            if (matcher.matchesInfo(info)) {
                layout.removeViewInLayout(child);
                if (child instanceof DropTarget) {
                    mDragController.removeDropTarget((DropTarget) child);
                }
            } else if (child instanceof FolderIcon) {
                FolderInfo folderInfo = (FolderInfo) info;
                List<WorkspaceItemInfo> matches = folderInfo.contents.stream().filter(matcher::matchesInfo).collect(Collectors.toList());
                if (!matches.isEmpty()) {
                    folderInfo.removeAll(matches, false);
                    if (((FolderIcon) child).getFolder().isOpen()) {
                        ((FolderIcon) child).getFolder().close(false);
                    }
                }
            }
        }
    }
    // Strip all the empty screens
    stripEmptyScreens();
}
Also used : WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ItemInfo(com.android.launcher3.model.data.ItemInfo) SearchActionItemInfo(com.android.launcher3.model.data.SearchActionItemInfo) FolderIcon(com.android.launcher3.folder.FolderIcon) ArrayList(java.util.ArrayList) RunnableList(com.android.launcher3.util.RunnableList) List(java.util.List) 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) FolderInfo(com.android.launcher3.model.data.FolderInfo) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 67 with FolderIcon

use of com.android.launcher3.tapl.FolderIcon in project android_packages_apps_Launcher3 by ProtonAOSP.

the class Workspace method manageFolderFeedback.

private void manageFolderFeedback(float distance, DragObject dragObject) {
    if (distance > mDragTargetLayout.getFolderCreationRadius(mTargetCell)) {
        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) SearchActionItemInfo(com.android.launcher3.model.data.SearchActionItemInfo) 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 68 with FolderIcon

use of com.android.launcher3.tapl.FolderIcon in project android_packages_apps_Launcher3 by ProtonAOSP.

the class TaskbarView method updateHotseatItems.

/**
 * Inflates/binds the Hotseat views to show in the Taskbar given their ItemInfos.
 */
protected void updateHotseatItems(ItemInfo[] hotseatItemInfos) {
    int nextViewIndex = 0;
    int numViewsAnimated = 0;
    for (int i = 0; i < hotseatItemInfos.length; i++) {
        ItemInfo hotseatItemInfo = hotseatItemInfos[i];
        if (hotseatItemInfo == null) {
            continue;
        }
        // Replace any Hotseat views with the appropriate type if it's not already that type.
        final int expectedLayoutResId;
        boolean isFolder = false;
        if (hotseatItemInfo.isPredictedItem()) {
            expectedLayoutResId = R.layout.taskbar_predicted_app_icon;
        } else if (hotseatItemInfo instanceof FolderInfo) {
            expectedLayoutResId = R.layout.folder_icon;
            isFolder = true;
        } else {
            expectedLayoutResId = R.layout.taskbar_app_icon;
        }
        View hotseatView = null;
        while (nextViewIndex < getChildCount()) {
            hotseatView = getChildAt(nextViewIndex);
            // see if the view can be reused
            if ((hotseatView.getSourceLayoutResId() != expectedLayoutResId) || (isFolder && (hotseatView.getTag() != hotseatItemInfo))) {
                // Unlike for BubbleTextView, we can't reapply a new FolderInfo after inflation,
                // so if the info changes we need to reinflate. This should only happen if a new
                // folder is dragged to the position that another folder previously existed.
                removeAndRecycle(hotseatView);
                hotseatView = null;
            } else {
                // View found
                break;
            }
        }
        if (hotseatView == null) {
            if (isFolder) {
                FolderInfo folderInfo = (FolderInfo) hotseatItemInfo;
                FolderIcon folderIcon = FolderIcon.inflateFolderAndIcon(expectedLayoutResId, mActivityContext, this, folderInfo);
                folderIcon.setTextVisible(false);
                hotseatView = folderIcon;
            } else {
                hotseatView = inflate(expectedLayoutResId);
            }
            LayoutParams lp = new LayoutParams(mIconTouchSize, mIconTouchSize);
            hotseatView.setPadding(mItemPadding, mItemPadding, mItemPadding, mItemPadding);
            addView(hotseatView, nextViewIndex, lp);
        }
        // Apply the Hotseat ItemInfos, or hide the view if there is none for a given index.
        if (hotseatView instanceof BubbleTextView && hotseatItemInfo instanceof WorkspaceItemInfo) {
            BubbleTextView btv = (BubbleTextView) hotseatView;
            WorkspaceItemInfo workspaceInfo = (WorkspaceItemInfo) hotseatItemInfo;
            boolean animate = btv.shouldAnimateIconChange((WorkspaceItemInfo) hotseatItemInfo);
            btv.applyFromWorkspaceItem(workspaceInfo, animate, numViewsAnimated);
            if (animate) {
                numViewsAnimated++;
            }
        }
        setClickAndLongClickListenersForIcon(hotseatView);
        nextViewIndex++;
    }
    // Remove remaining views
    while (nextViewIndex < getChildCount()) {
        removeAndRecycle(getChildAt(nextViewIndex));
    }
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) FolderIcon(com.android.launcher3.folder.FolderIcon) BubbleTextView(com.android.launcher3.BubbleTextView) FolderInfo(com.android.launcher3.model.data.FolderInfo) BubbleTextView(com.android.launcher3.BubbleTextView) View(android.view.View) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 69 with FolderIcon

use of com.android.launcher3.tapl.FolderIcon in project android_packages_apps_Launcher3 by ProtonAOSP.

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 70 with FolderIcon

use of com.android.launcher3.tapl.FolderIcon in project android_packages_apps_Launcher3 by ProtonAOSP.

the class PreviewItemManager method setDrawable.

private void setDrawable(PreviewItemDrawingParams p, WorkspaceItemInfo item) {
    if (item.hasPromiseIconUi() || (item.runtimeStatusFlags & ItemInfoWithIcon.FLAG_SHOW_DOWNLOAD_PROGRESS_MASK) != 0) {
        PreloadIconDrawable drawable = newPendingIcon(mContext, item);
        drawable.setLevel(item.getProgressLevel());
        p.drawable = drawable;
    } else {
        p.drawable = item.newIcon(mContext, true);
    }
    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)

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