Search in sources :

Example 31 with ShortcutAndWidgetContainer

use of com.android.launcher3.ShortcutAndWidgetContainer 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 32 with ShortcutAndWidgetContainer

use of com.android.launcher3.ShortcutAndWidgetContainer in project android_packages_apps_Launcher3 by ProtonAOSP.

the class Workspace method mapOverCellLayout.

private View mapOverCellLayout(CellLayout layout, ItemOperator op) {
    // TODO(b/128460496) Potential race condition where layout is not yet loaded
    if (layout == null) {
        return null;
    }
    ShortcutAndWidgetContainer container = layout.getShortcutsAndWidgets();
    // map over all the shortcuts on the workspace
    final int itemCount = container.getChildCount();
    for (int itemIdx = 0; itemIdx < itemCount; itemIdx++) {
        View item = container.getChildAt(itemIdx);
        if (op.evaluate((ItemInfo) item.getTag(), item)) {
            return item;
        }
    }
    return null;
}
Also used : 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)

Example 33 with ShortcutAndWidgetContainer

use of com.android.launcher3.ShortcutAndWidgetContainer in project android_packages_apps_Launcher3 by ProtonAOSP.

the class FolderAnimationManager method addPreviewItemAnimators.

/**
 * Animate the items on the current page.
 */
private void addPreviewItemAnimators(AnimatorSet animatorSet, final float folderScale, int previewItemOffsetX, int previewItemOffsetY) {
    ClippedFolderIconLayoutRule rule = mFolderIcon.getLayoutRule();
    boolean isOnFirstPage = mFolder.mContent.getCurrentPage() == 0;
    final List<BubbleTextView> itemsInPreview = getPreviewIconsOnPage(isOnFirstPage ? 0 : mFolder.mContent.getCurrentPage());
    final int numItemsInPreview = itemsInPreview.size();
    final int numItemsInFirstPagePreview = isOnFirstPage ? numItemsInPreview : MAX_NUM_ITEMS_IN_PREVIEW;
    TimeInterpolator previewItemInterpolator = getPreviewItemInterpolator();
    ShortcutAndWidgetContainer cwc = mContent.getPageAt(0).getShortcutsAndWidgets();
    for (int i = 0; i < numItemsInPreview; ++i) {
        final BubbleTextView btv = itemsInPreview.get(i);
        CellLayout.LayoutParams btvLp = (CellLayout.LayoutParams) btv.getLayoutParams();
        // Calculate the final values in the LayoutParams.
        btvLp.isLockedToGrid = true;
        cwc.setupLp(btv);
        // Match scale of icons in the preview of the items on the first page.
        float previewScale = rule.scaleForItem(numItemsInFirstPagePreview);
        float previewSize = rule.getIconSize() * previewScale;
        float iconScale = previewSize / itemsInPreview.get(i).getIconSize();
        final float initialScale = iconScale / folderScale;
        final float finalScale = 1f;
        float scale = mIsOpening ? initialScale : finalScale;
        btv.setScaleX(scale);
        btv.setScaleY(scale);
        // Match positions of the icons in the folder with their positions in the preview
        rule.computePreviewItemDrawingParams(i, numItemsInFirstPagePreview, mTmpParams);
        // The PreviewLayoutRule assumes that the icon size takes up the entire width so we
        // offset by the actual size.
        int iconOffsetX = (int) ((btvLp.width - btv.getIconSize()) * iconScale) / 2;
        final int previewPosX = (int) ((mTmpParams.transX - iconOffsetX + previewItemOffsetX) / folderScale);
        final float paddingTop = btv.getPaddingTop() * iconScale;
        final int previewPosY = (int) ((mTmpParams.transY + previewItemOffsetY - paddingTop) / folderScale);
        final float xDistance = previewPosX - btvLp.x;
        final float yDistance = previewPosY - btvLp.y;
        Animator translationX = getAnimator(btv, View.TRANSLATION_X, xDistance, 0f);
        translationX.setInterpolator(previewItemInterpolator);
        play(animatorSet, translationX);
        Animator translationY = getAnimator(btv, View.TRANSLATION_Y, yDistance, 0f);
        translationY.setInterpolator(previewItemInterpolator);
        play(animatorSet, translationY);
        Animator scaleAnimator = getAnimator(btv, SCALE_PROPERTY, initialScale, finalScale);
        scaleAnimator.setInterpolator(previewItemInterpolator);
        play(animatorSet, scaleAnimator);
        if (mFolder.getItemCount() > MAX_NUM_ITEMS_IN_PREVIEW) {
            // These delays allows the preview items to move as part of the Folder's motion,
            // and its only necessary for large folders because of differing interpolators.
            int delay = mIsOpening ? mDelay : mDelay * 2;
            if (mIsOpening) {
                translationX.setStartDelay(delay);
                translationY.setStartDelay(delay);
                scaleAnimator.setStartDelay(delay);
            }
            translationX.setDuration(translationX.getDuration() - delay);
            translationY.setDuration(translationY.getDuration() - delay);
            scaleAnimator.setDuration(scaleAnimator.getDuration() - delay);
        }
        animatorSet.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationStart(Animator animation) {
                super.onAnimationStart(animation);
                // Necessary to initialize values here because of the start delay.
                if (mIsOpening) {
                    btv.setTranslationX(xDistance);
                    btv.setTranslationY(yDistance);
                    btv.setScaleX(initialScale);
                    btv.setScaleY(initialScale);
                }
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                btv.setTranslationX(0.0f);
                btv.setTranslationY(0.0f);
                btv.setScaleX(1f);
                btv.setScaleY(1f);
            }
        });
    }
}
Also used : ShortcutAndWidgetContainer(com.android.launcher3.ShortcutAndWidgetContainer) TimeInterpolator(android.animation.TimeInterpolator) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) CellLayout(com.android.launcher3.CellLayout) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) BubbleTextView(com.android.launcher3.BubbleTextView)

Example 34 with ShortcutAndWidgetContainer

use of com.android.launcher3.ShortcutAndWidgetContainer in project android_packages_apps_Launcher3 by ProtonAOSP.

the class FolderPagedView method getViewInCurrentPage.

private View getViewInCurrentPage(ToIntFunction<ShortcutAndWidgetContainer> rankProvider) {
    if (getChildCount() < 1) {
        return null;
    }
    ShortcutAndWidgetContainer container = getCurrentCellLayout().getShortcutsAndWidgets();
    int rank = rankProvider.applyAsInt(container);
    if (mGridCountX > 0) {
        return container.getChildAt(rank % mGridCountX, rank / mGridCountX);
    } else {
        return container.getChildAt(rank);
    }
}
Also used : ShortcutAndWidgetContainer(com.android.launcher3.ShortcutAndWidgetContainer) SuppressLint(android.annotation.SuppressLint)

Example 35 with ShortcutAndWidgetContainer

use of com.android.launcher3.ShortcutAndWidgetContainer in project android_packages_apps_Launcher3 by ProtonAOSP.

the class DragLayer method animateViewIntoPosition.

public void animateViewIntoPosition(DragView dragView, final View child, int duration, View anchorView) {
    ShortcutAndWidgetContainer parentChildren = (ShortcutAndWidgetContainer) child.getParent();
    CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
    parentChildren.measureChild(child);
    parentChildren.layoutChild(child);
    float[] coord = new float[2];
    float childScale = child.getScaleX();
    coord[0] = lp.x + (child.getMeasuredWidth() * (1 - childScale) / 2);
    coord[1] = lp.y + (child.getMeasuredHeight() * (1 - childScale) / 2);
    // Since the child hasn't necessarily been laid out, we force the lp to be updated with
    // the correct coordinates (above) and use these to determine the final location
    float scale = getDescendantCoordRelativeToSelf((View) child.getParent(), coord);
    // We need to account for the scale of the child itself, as the above only accounts for
    // for the scale in parents.
    scale *= childScale;
    int toX = Math.round(coord[0]);
    int toY = Math.round(coord[1]);
    float toScale = scale;
    if (child instanceof DraggableView) {
        // This code is fairly subtle. Please verify drag and drop is pixel-perfect in a number
        // of scenarios before modifying (from all apps, from workspace, different grid-sizes,
        // shortcuts from in and out of Launcher etc).
        DraggableView d = (DraggableView) child;
        Rect destRect = new Rect();
        d.getWorkspaceVisualDragBounds(destRect);
        // In most cases this additional scale factor should be a no-op (1). It mainly accounts
        // for alternate grids where the source and destination icon sizes are different
        toScale *= ((1f * destRect.width()) / (dragView.getMeasuredWidth() - dragView.getBlurSizeOutline()));
        // This accounts for the offset of the DragView created by scaling it about its
        // center as it animates into place.
        float scaleShiftX = dragView.getMeasuredWidth() * (1 - toScale) / 2;
        float scaleShiftY = dragView.getMeasuredHeight() * (1 - toScale) / 2;
        toX += scale * destRect.left - toScale * dragView.getBlurSizeOutline() / 2 - scaleShiftX;
        toY += scale * destRect.top - toScale * dragView.getBlurSizeOutline() / 2 - scaleShiftY;
    }
    child.setVisibility(INVISIBLE);
    Runnable onCompleteRunnable = () -> child.setVisibility(VISIBLE);
    animateViewIntoPosition(dragView, toX, toY, 1, toScale, toScale, onCompleteRunnable, ANIMATION_END_DISAPPEAR, duration, anchorView);
}
Also used : Rect(android.graphics.Rect) CellLayout(com.android.launcher3.CellLayout) ShortcutAndWidgetContainer(com.android.launcher3.ShortcutAndWidgetContainer)

Aggregations

SuppressLint (android.annotation.SuppressLint)63 ShortcutAndWidgetContainer (com.android.launcher3.ShortcutAndWidgetContainer)54 View (android.view.View)44 CellLayout (com.android.launcher3.CellLayout)38 Point (android.graphics.Point)36 AppWidgetHostView (android.appwidget.AppWidgetHostView)28 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)26 DragView (com.android.launcher3.dragndrop.DragView)23 BubbleTextView (com.android.launcher3.BubbleTextView)21 DraggableView (com.android.launcher3.dragndrop.DraggableView)21 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)21 Animator (android.animation.Animator)20 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)20 ObjectAnimator (android.animation.ObjectAnimator)19 Rect (android.graphics.Rect)14 Drawable (android.graphics.drawable.Drawable)14 ItemInfo (com.android.launcher3.model.data.ItemInfo)14 ValueAnimator (android.animation.ValueAnimator)13 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)8 Paint (android.graphics.Paint)8