Search in sources :

Example 21 with Rect

use of android.graphics.Rect in project SimplifyReader by chentao0707.

the class PLAListView method drawContentBackground.

private void drawContentBackground(Canvas canvas) {
    if (getHeaderViewsCount() > 0) {
        Rect rect = mTempRect;
        rect.left = getLeft();
        rect.right = getRight();
        View firstVisibleView = getChildAt(getFirstVisiblePosition());
        if (isHeaderView(firstVisibleView)) {
            View lastHeader = mHeaderViewInfos.get(mHeaderViewInfos.size() - 1).view;
            rect.top = lastHeader.getBottom();
        } else
            rect.top = 0;
        rect.bottom = getBottom();
        canvas.drawRect(rect, mContentPaint);
    }
}
Also used : Rect(android.graphics.Rect) View(android.view.View)

Example 22 with Rect

use of android.graphics.Rect in project Launcher3 by chislon.

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);
        markCellsForView(c.x, c.y, c.spanX, c.spanY, mTmpOccupied, 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.
                    markCellsForView(c.x, c.y, c.spanX, c.spanY, mTmpOccupied, 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);
        markCellsForView(c.x, c.y, c.spanX, c.spanY, mTmpOccupied, true);
    }
    return foundSolution;
}
Also used : Rect(android.graphics.Rect) View(android.view.View) Point(android.graphics.Point) Paint(android.graphics.Paint)

Example 23 with Rect

use of android.graphics.Rect in project Launcher3 by chislon.

the class CellLayout method visualizeDropLocation.

void visualizeDropLocation(View v, Bitmap dragOutline, int originX, int originY, int cellX, int cellY, int spanX, int spanY, boolean resize, Point dragOffset, Rect dragRegion) {
    final int oldDragCellX = mDragCell[0];
    final int oldDragCellY = mDragCell[1];
    if (dragOutline == null && v == null) {
        return;
    }
    if (cellX != oldDragCellX || cellY != oldDragCellY) {
        mDragCell[0] = cellX;
        mDragCell[1] = cellY;
        // Find the top left corner of the rect the object will occupy
        final int[] topLeft = mTmpPoint;
        cellToPoint(cellX, cellY, topLeft);
        int left = topLeft[0];
        int top = topLeft[1];
        if (v != null && dragOffset == null) {
            // When drawing the drag outline, it did not account for margin offsets
            // added by the view's parent.
            MarginLayoutParams lp = (MarginLayoutParams) v.getLayoutParams();
            left += lp.leftMargin;
            top += lp.topMargin;
            // Offsets due to the size difference between the View and the dragOutline.
            // There is a size difference to account for the outer blur, which may lie
            // outside the bounds of the view.
            top += (v.getHeight() - dragOutline.getHeight()) / 2;
            // We center about the x axis
            left += ((mCellWidth * spanX) + ((spanX - 1) * mWidthGap) - dragOutline.getWidth()) / 2;
        } else {
            if (dragOffset != null && dragRegion != null) {
                // Center the drag region *horizontally* in the cell and apply a drag
                // outline offset
                left += dragOffset.x + ((mCellWidth * spanX) + ((spanX - 1) * mWidthGap) - dragRegion.width()) / 2;
                int cHeight = getShortcutsAndWidgets().getCellContentHeight();
                int cellPaddingY = (int) Math.max(0, ((mCellHeight - cHeight) / 2f));
                top += dragOffset.y + cellPaddingY;
            } else {
                // Center the drag outline in the cell
                left += ((mCellWidth * spanX) + ((spanX - 1) * mWidthGap) - dragOutline.getWidth()) / 2;
                top += ((mCellHeight * spanY) + ((spanY - 1) * mHeightGap) - dragOutline.getHeight()) / 2;
            }
        }
        final int oldIndex = mDragOutlineCurrent;
        mDragOutlineAnims[oldIndex].animateOut();
        mDragOutlineCurrent = (oldIndex + 1) % mDragOutlines.length;
        Rect r = mDragOutlines[mDragOutlineCurrent];
        r.set(left, top, left + dragOutline.getWidth(), top + dragOutline.getHeight());
        if (resize) {
            cellToRect(cellX, cellY, spanX, spanY, r);
        }
        mDragOutlineAnims[mDragOutlineCurrent].setTag(dragOutline);
        mDragOutlineAnims[mDragOutlineCurrent].animateIn();
    }
}
Also used : Rect(android.graphics.Rect) Point(android.graphics.Point) Paint(android.graphics.Paint)

Example 24 with Rect

use of android.graphics.Rect in project Launcher3 by chislon.

the class DeleteDropTarget method animateToTrashAndCompleteDrop.

private void animateToTrashAndCompleteDrop(final DragObject d) {
    final DragLayer dragLayer = mLauncher.getDragLayer();
    final Rect from = new Rect();
    dragLayer.getViewRectRelativeToSelf(d.dragView, from);
    final Rect to = getIconRect(d.dragView.getMeasuredWidth(), d.dragView.getMeasuredHeight(), mCurrentDrawable.getIntrinsicWidth(), mCurrentDrawable.getIntrinsicHeight());
    final float scale = (float) to.width() / from.width();
    mSearchDropTargetBar.deferOnDragEnd();
    deferCompleteDropIfUninstalling(d);
    Runnable onAnimationEndRunnable = new Runnable() {

        @Override
        public void run() {
            completeDrop(d);
            mSearchDropTargetBar.onDragEnd();
            mLauncher.exitSpringLoadedDragMode();
        }
    };
    dragLayer.animateView(d.dragView, from, to, scale, 1f, 1f, 0.1f, 0.1f, DELETE_ANIMATION_DURATION, new DecelerateInterpolator(2), new LinearInterpolator(), onAnimationEndRunnable, DragLayer.ANIMATION_END_DISAPPEAR, null);
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) Rect(android.graphics.Rect) LinearInterpolator(android.view.animation.LinearInterpolator)

Example 25 with Rect

use of android.graphics.Rect in project Launcher3 by chislon.

the class DeleteDropTarget method createFlingAlongVectorAnimatorListener.

private AnimatorUpdateListener createFlingAlongVectorAnimatorListener(final DragLayer dragLayer, DragObject d, PointF vel, final long startTime, final int duration, ViewConfiguration config) {
    final Rect from = new Rect();
    dragLayer.getViewRectRelativeToSelf(d.dragView, from);
    return new FlingAlongVectorAnimatorUpdateListener(dragLayer, vel, from, startTime, FLING_TO_DELETE_FRICTION);
}
Also used : Rect(android.graphics.Rect)

Aggregations

Rect (android.graphics.Rect)3823 Paint (android.graphics.Paint)791 View (android.view.View)533 Point (android.graphics.Point)470 Bitmap (android.graphics.Bitmap)333 Canvas (android.graphics.Canvas)255 Drawable (android.graphics.drawable.Drawable)203 RectF (android.graphics.RectF)176 Resources (android.content.res.Resources)101 Matrix (android.graphics.Matrix)99 SmallTest (android.test.suitebuilder.annotation.SmallTest)94 TextPaint (android.text.TextPaint)94 RemoteException (android.os.RemoteException)93 ViewGroup (android.view.ViewGroup)89 TextView (android.widget.TextView)87 ArrayList (java.util.ArrayList)87 AccessibilityNodeInfo (android.view.accessibility.AccessibilityNodeInfo)84 BitmapDrawable (android.graphics.drawable.BitmapDrawable)82 SuppressLint (android.annotation.SuppressLint)77 ImageView (android.widget.ImageView)70