Search in sources :

Example 36 with LayoutParams

use of com.android.launcher3.InsettableFrameLayout.LayoutParams in project Neo-Launcher by NeoApplications.

the class CellLayout method pushViewsToTempLocation.

private boolean pushViewsToTempLocation(ArrayList<View> views, Rect rectOccupiedByPotentialDrop, int[] direction, View dragView, ItemConfiguration currentState) {
    ViewCluster cluster = new ViewCluster(views, currentState);
    Rect clusterRect = cluster.getBoundingRect();
    int whichEdge;
    int pushDistance;
    boolean fail = false;
    // the cluster must be shifted.
    if (direction[0] < 0) {
        whichEdge = ViewCluster.LEFT;
        pushDistance = clusterRect.right - rectOccupiedByPotentialDrop.left;
    } else if (direction[0] > 0) {
        whichEdge = ViewCluster.RIGHT;
        pushDistance = rectOccupiedByPotentialDrop.right - clusterRect.left;
    } else if (direction[1] < 0) {
        whichEdge = ViewCluster.TOP;
        pushDistance = clusterRect.bottom - rectOccupiedByPotentialDrop.top;
    } else {
        whichEdge = ViewCluster.BOTTOM;
        pushDistance = rectOccupiedByPotentialDrop.bottom - clusterRect.top;
    }
    // Break early for invalid push distance.
    if (pushDistance <= 0) {
        return false;
    }
    // Mark the occupied state as false for the group of views we want to move.
    for (View v : views) {
        CellAndSpan c = currentState.map.get(v);
        mTmpOccupied.markCells(c, false);
    }
    // We save the current configuration -- if we fail to find a solution we will revert
    // to the initial state. The process of finding a solution modifies the configuration
    // in place, hence the need for revert in the failure case.
    currentState.save();
    // The pushing algorithm is simplified by considering the views in the order in which
    // they would be pushed by the cluster. For example, if the cluster is leading with its
    // left edge, we consider sort the views by their right edge, from right to left.
    cluster.sortConfigurationForEdgePush(whichEdge);
    while (pushDistance > 0 && !fail) {
        for (View v : currentState.sortedViews) {
            // cluster.
            if (!cluster.views.contains(v) && v != dragView) {
                if (cluster.isViewTouchingEdge(v, whichEdge)) {
                    LayoutParams lp = (LayoutParams) v.getLayoutParams();
                    if (!lp.canReorder) {
                        // The push solution includes the all apps button, this is not viable.
                        fail = true;
                        break;
                    }
                    cluster.addView(v);
                    CellAndSpan c = currentState.map.get(v);
                    // Adding view to cluster, mark it as not occupied.
                    mTmpOccupied.markCells(c, false);
                }
            }
        }
        pushDistance--;
        // The cluster has been completed, now we move the whole thing over in the appropriate
        // direction.
        cluster.shift(whichEdge, 1);
    }
    boolean foundSolution = false;
    clusterRect = cluster.getBoundingRect();
    // is to ensure that completed shifted cluster lies completely within the cell layout.
    if (!fail && clusterRect.left >= 0 && clusterRect.right <= mCountX && clusterRect.top >= 0 && clusterRect.bottom <= mCountY) {
        foundSolution = true;
    } else {
        currentState.restore();
    }
    // In either case, we set the occupied array as marked for the location of the views
    for (View v : cluster.views) {
        CellAndSpan c = currentState.map.get(v);
        mTmpOccupied.markCells(c, true);
    }
    return foundSolution;
}
Also used : Rect(android.graphics.Rect) CellAndSpan(com.android.launcher3.util.CellAndSpan) View(android.view.View) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 37 with LayoutParams

use of com.android.launcher3.InsettableFrameLayout.LayoutParams in project Neo-Launcher by NeoApplications.

the class CellLayout method beginOrAdjustReorderPreviewAnimations.

// This method starts or changes the reorder preview animations
private void beginOrAdjustReorderPreviewAnimations(ItemConfiguration solution, View dragView, int delay, int mode) {
    int childCount = mShortcutsAndWidgets.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = mShortcutsAndWidgets.getChildAt(i);
        if (child == dragView)
            continue;
        CellAndSpan c = solution.map.get(child);
        boolean skip = mode == ReorderPreviewAnimation.MODE_HINT && solution.intersectingViews != null && !solution.intersectingViews.contains(child);
        LayoutParams lp = (LayoutParams) child.getLayoutParams();
        if (c != null && !skip) {
            ReorderPreviewAnimation rha = new ReorderPreviewAnimation(child, mode, lp.cellX, lp.cellY, c.cellX, c.cellY, c.spanX, c.spanY);
            rha.animate();
        }
    }
}
Also used : CellAndSpan(com.android.launcher3.util.CellAndSpan) View(android.view.View) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 38 with LayoutParams

use of com.android.launcher3.InsettableFrameLayout.LayoutParams in project Neo-Launcher by NeoApplications.

the class DragLayer method onLayout.

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    RotationMode rotation = mActivity.getRotationMode();
    if (!rotation.isTransposed) {
        super.onLayout(changed, left, top, right, bottom);
        return;
    }
    final int count = getChildCount();
    final int parentWidth = right - left;
    final int parentHeight = bottom - top;
    for (int i = 0; i < count; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() == GONE) {
            continue;
        }
        final FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) child.getLayoutParams();
        if (lp instanceof LayoutParams) {
            final LayoutParams dlp = (LayoutParams) lp;
            if (dlp.customPosition) {
                child.layout(dlp.x, dlp.y, dlp.x + dlp.width, dlp.y + dlp.height);
                continue;
            }
        }
        final int width = child.getMeasuredWidth();
        final int height = child.getMeasuredHeight();
        int childLeft;
        int childTop;
        int gravity = lp.gravity;
        if (gravity == -1) {
            gravity = Gravity.TOP | Gravity.START;
        }
        final int layoutDirection = getLayoutDirection();
        int absoluteGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection);
        if (child instanceof Transposable) {
            absoluteGravity = rotation.toNaturalGravity(absoluteGravity);
            switch(absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
                case Gravity.CENTER_HORIZONTAL:
                    childTop = (parentHeight - height) / 2 + lp.topMargin - lp.bottomMargin;
                    break;
                case Gravity.RIGHT:
                    childTop = width / 2 + lp.rightMargin - height / 2;
                    break;
                case Gravity.LEFT:
                default:
                    childTop = parentHeight - lp.leftMargin - width / 2 - height / 2;
            }
            switch(absoluteGravity & Gravity.VERTICAL_GRAVITY_MASK) {
                case Gravity.CENTER_VERTICAL:
                    childLeft = (parentWidth - width) / 2 + lp.leftMargin - lp.rightMargin;
                    break;
                case Gravity.BOTTOM:
                    childLeft = parentWidth - width / 2 - height / 2 - lp.bottomMargin;
                    break;
                case Gravity.TOP:
                default:
                    childLeft = height / 2 - width / 2 + lp.topMargin;
            }
        } else {
            switch(absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
                case Gravity.CENTER_HORIZONTAL:
                    childLeft = (parentWidth - width) / 2 + lp.leftMargin - lp.rightMargin;
                    break;
                case Gravity.RIGHT:
                    childLeft = parentWidth - width - lp.rightMargin;
                    break;
                case Gravity.LEFT:
                default:
                    childLeft = lp.leftMargin;
            }
            switch(absoluteGravity & Gravity.VERTICAL_GRAVITY_MASK) {
                case Gravity.TOP:
                    childTop = lp.topMargin;
                    break;
                case Gravity.CENTER_VERTICAL:
                    childTop = (parentHeight - height) / 2 + lp.topMargin - lp.bottomMargin;
                    break;
                case Gravity.BOTTOM:
                    childTop = parentHeight - height - lp.bottomMargin;
                    break;
                default:
                    childTop = lp.topMargin;
            }
        }
        child.layout(childLeft, childTop, childLeft + width, childTop + height);
    }
}
Also used : FrameLayout(android.widget.FrameLayout) RotationMode(com.android.launcher3.graphics.RotationMode) Transposable(com.android.launcher3.views.Transposable) View(android.view.View) TextView(android.widget.TextView) AbstractFloatingView(com.android.launcher3.AbstractFloatingView)

Example 39 with LayoutParams

use of com.android.launcher3.InsettableFrameLayout.LayoutParams in project Neo-Launcher by NeoApplications.

the class FloatingIconView method matchPositionOf.

/**
 * Sets the size and position of this view to match {@param v}.
 *
 * @param v The view to copy
 * @param positionOut Rect that will hold the size and position of v.
 */
private void matchPositionOf(Launcher launcher, View v, boolean isOpening, RectF positionOut) {
    float rotation = getLocationBoundsForView(launcher, v, isOpening, positionOut);
    final LayoutParams lp = new LayoutParams(Math.round(positionOut.width()), Math.round(positionOut.height()));
    updatePosition(rotation, positionOut, lp);
    setLayoutParams(lp);
}
Also used : LayoutParams(com.android.launcher3.InsettableFrameLayout.LayoutParams)

Example 40 with LayoutParams

use of com.android.launcher3.InsettableFrameLayout.LayoutParams in project Neo-Launcher by NeoApplications.

the class FloatingIconView method setIcon.

/**
 * Sets the drawables of the {@param originalView} onto this view.
 *
 * @param originalView The View that the FloatingIconView will replace.
 * @param drawable The drawable of the original view.
 * @param badge The badge of the original view.
 * @param iconOffset The amount of offset needed to match this view with the original view.
 */
@UiThread
private void setIcon(View originalView, @Nullable Drawable drawable, @Nullable Drawable badge, int iconOffset) {
    mBadge = badge;
    mIsAdaptiveIcon = drawable instanceof AdaptiveIconDrawable;
    if (mIsAdaptiveIcon) {
        boolean isFolderIcon = drawable instanceof FolderAdaptiveIcon;
        AdaptiveIconDrawable adaptiveIcon = (AdaptiveIconDrawable) drawable;
        Drawable background = adaptiveIcon.getBackground();
        if (background == null) {
            background = new ColorDrawable(Color.TRANSPARENT);
        }
        mBackground = background;
        Drawable foreground = adaptiveIcon.getForeground();
        if (foreground == null) {
            foreground = new ColorDrawable(Color.TRANSPARENT);
        }
        mForeground = foreground;
        final LayoutParams lp = (LayoutParams) getLayoutParams();
        final int originalHeight = lp.height;
        final int originalWidth = lp.width;
        int blurMargin = mBlurSizeOutline / 2;
        mFinalDrawableBounds.set(0, 0, originalWidth, originalHeight);
        if (!isFolderIcon) {
            mFinalDrawableBounds.inset(iconOffset - blurMargin, iconOffset - blurMargin);
        }
        mForeground.setBounds(mFinalDrawableBounds);
        mBackground.setBounds(mFinalDrawableBounds);
        mStartRevealRect.set(0, 0, originalWidth, originalHeight);
        if (mBadge != null) {
            mBadge.setBounds(mStartRevealRect);
            if (!mIsOpening && !isFolderIcon) {
                DRAWABLE_ALPHA.set(mBadge, 0);
            }
        }
        if (isFolderIcon) {
            ((FolderIcon) originalView).getPreviewBounds(sTmpRect);
            float bgStroke = ((FolderIcon) originalView).getBackgroundStrokeWidth();
            if (mForeground instanceof ShiftedBitmapDrawable) {
                ShiftedBitmapDrawable sbd = (ShiftedBitmapDrawable) mForeground;
                sbd.setShiftX(sbd.getShiftX() - sTmpRect.left - bgStroke);
                sbd.setShiftY(sbd.getShiftY() - sTmpRect.top - bgStroke);
            }
            if (mBadge instanceof ShiftedBitmapDrawable) {
                ShiftedBitmapDrawable sbd = (ShiftedBitmapDrawable) mBadge;
                sbd.setShiftX(sbd.getShiftX() - sTmpRect.left - bgStroke);
                sbd.setShiftY(sbd.getShiftY() - sTmpRect.top - bgStroke);
            }
        } else {
            Utilities.scaleRectAboutCenter(mStartRevealRect, IconShape.getNormalizationScale());
        }
        float aspectRatio = mLauncher.getDeviceProfile().aspectRatio;
        if (mIsVerticalBarLayout) {
            lp.width = (int) Math.max(lp.width, lp.height * aspectRatio);
        } else {
            lp.height = (int) Math.max(lp.height, lp.width * aspectRatio);
        }
        int left = mIsRtl ? mLauncher.getDeviceProfile().widthPx - lp.getMarginStart() - lp.width : lp.leftMargin;
        layout(left, lp.topMargin, left + lp.width, lp.topMargin + lp.height);
        float scale = Math.max((float) lp.height / originalHeight, (float) lp.width / originalWidth);
        float bgDrawableStartScale;
        if (mIsOpening) {
            bgDrawableStartScale = 1f;
            mOutline.set(0, 0, originalWidth, originalHeight);
        } else {
            bgDrawableStartScale = scale;
            mOutline.set(0, 0, lp.width, lp.height);
        }
        setBackgroundDrawableBounds(bgDrawableStartScale);
        mEndRevealRect.set(0, 0, lp.width, lp.height);
        setOutlineProvider(new ViewOutlineProvider() {

            @Override
            public void getOutline(View view, Outline outline) {
                outline.setRoundRect(mOutline, mTaskCornerRadius);
            }
        });
        setClipToOutline(true);
    } else {
        setBackground(drawable);
        setClipToOutline(false);
    }
    invalidate();
    invalidateOutline();
}
Also used : FolderAdaptiveIcon(com.android.launcher3.dragndrop.FolderAdaptiveIcon) LayoutParams(com.android.launcher3.InsettableFrameLayout.LayoutParams) 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) Outline(android.graphics.Outline) ViewOutlineProvider(android.view.ViewOutlineProvider) ImageView(android.widget.ImageView) BubbleTextView(com.android.launcher3.BubbleTextView) View(android.view.View) DeepShortcutView(com.android.launcher3.shortcuts.DeepShortcutView) ColorDrawable(android.graphics.drawable.ColorDrawable) FolderIcon(com.android.launcher3.folder.FolderIcon) ShiftedBitmapDrawable(com.android.launcher3.graphics.ShiftedBitmapDrawable) AdaptiveIconDrawable(android.graphics.drawable.AdaptiveIconDrawable) UiThread(androidx.annotation.UiThread)

Aggregations

View (android.view.View)79 SuppressLint (android.annotation.SuppressLint)61 Paint (android.graphics.Paint)59 Point (android.graphics.Point)58 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)49 DraggableView (com.android.launcher3.dragndrop.DraggableView)40 CellAndSpan (com.android.launcher3.util.CellAndSpan)35 Rect (android.graphics.Rect)23 BubbleTextView (com.android.launcher3.BubbleTextView)21 ItemInfo (com.android.launcher3.model.data.ItemInfo)17 Animator (android.animation.Animator)16 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)16 ObjectAnimator (android.animation.ObjectAnimator)15 AbstractFloatingView (com.android.launcher3.AbstractFloatingView)15 FrameLayout (android.widget.FrameLayout)13 DeviceProfile (com.android.launcher3.DeviceProfile)13 PagedOrientationHandler (com.android.launcher3.touch.PagedOrientationHandler)10 ValueAnimator (android.animation.ValueAnimator)9 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)8 TimeInterpolator (android.animation.TimeInterpolator)7