private void drawIcon(Canvas canvas, Drawable icon, Matrix iconMatrix) { canvas.save(); canvas.concat(iconMatrix); // Drawing icon if it is within a visible part of the canvas canvas.getClipBounds(clipRect); final int width = icon.getIntrinsicWidth(); final int height = icon.getIntrinsicHeight(); if (clipRect.intersects(0, 0, width, height)) { icon.setBounds(0, 0, width, height); icon.draw(canvas); } canvas.restore(); }
@Test public void intersects() { Rect a = new Rect(0, 0, 10, 10); Rect b = new Rect(5, 0, 15, 10); assertThat(Rect.intersects(a, b)).isTrue(); }
@Test public void doesntIntersect() { Rect a = new Rect(0, 0, 10, 10); Rect b = new Rect(11, 11, 21, 21); assertThat(Rect.intersects(a, b)).isFalse(); }
@Test public void almostIntersects() { Rect a = new Rect(3, 0, 4, 2); Rect b = new Rect(1, 0, 3, 1); assertThat(Rect.intersects(a, b)).isFalse(); }
!isIncrementalMountEnabled || isMountedHostWithChildContent(currentMountItem) || Rect.intersects(localVisibleRect, layoutOutput.getBounds()) || isAnimationLocked(i) || (currentMountItem != null && currentMountItem == rootMountItem);
/** * 削除Viewと重なっているかチェックします。 * * @return 削除Viewと重なっている場合はtrue */ private boolean isIntersectWithTrash() { // 無効の場合は重なり判定を行わない if (!mTrashView.isTrashEnabled()) { return false; } // INFO:TrashViewとFloatingViewは同じGravityにする必要があります mTrashView.getWindowDrawingRect(mTrashViewRect); mTargetFloatingView.getWindowDrawingRect(mFloatingViewRect); return Rect.intersects(mTrashViewRect, mFloatingViewRect); }
public boolean intersectsWith(Rect rect) { return Rect.intersects(rect, bounds); }
if (rc1.intersects( rc2)) { // intersection is detected // here is your method call button.setText("Shrekt m9"); } Rect rc3 = new Rect(); brickimg2.getDrawingRect(rc3); Rect rc4 = new Rect(); playerimage2.getDrawingRect(rc3); if (rc3.intersects( rc4)) { // intersection is detected // here is your method call button.setText("this works"); } if(rc2.intersects( rc3)){ button.setText("this works too"); }
/** * Determines if a rectangle intersects any part of the area of interest * @param r * @return True if r intersects any rectangle in the list */ public boolean testIntersect(Rect r) { int l = list.size(); for (int i = 0; i<l; i++) { if (list.get(i).get().intersects(r.left, r.top, r.right, r.bottom)) return true; } return false; }
private Rect getScreenBounds(View view) { int[] location = new int[2]; view.getLocationOnScreen(location); return new Rect(location[0], location[1], location[0] + view.getWidth(), location[1] + view.getHeight()); } private boolean doViewsIntersect(View target, View item) { Rect targetRect = getScreenBounds(target); Rect itemRect = getScreenBounds(item); return targetRect.intersects(itemRect); }
/** * Determine if a block is within the visible region. This is used to avoid useless drawing * operations. * * @param rect The block boundaries * @return True if the block is visible */ private boolean isBlockVisible(@NonNull Rect rect) { return rect.intersects(0, 0, getWidth(), getHeight()); }
private void getViewsIntersectingRegion(int cellX, int cellY, int spanX, int spanY, View dragView, Rect boundingRect, ArrayList<View> intersectingViews) { if (boundingRect != null) { boundingRect.set(cellX, cellY, cellX + spanX, cellY + spanY); } intersectingViews.clear(); Rect r0 = new Rect(cellX, cellY, cellX + spanX, cellY + spanY); Rect r1 = new Rect(); final int count = mShortcutsAndWidgets.getChildCount(); for (int i = 0; i < count; i++) { View child = mShortcutsAndWidgets.getChildAt(i); if (child == dragView) continue; LayoutParams lp = (LayoutParams) child.getLayoutParams(); r1.set(lp.cellX, lp.cellY, lp.cellX + lp.cellHSpan, lp.cellY + lp.cellVSpan); if (Rect.intersects(r0, r1)) { mIntersectingViews.add(child); if (boundingRect != null) { boundingRect.union(r1); } } } }
private void getViewsIntersectingRegion(int cellX, int cellY, int spanX, int spanY, View dragView, Rect boundingRect, ArrayList<View> intersectingViews) { if (boundingRect != null) { boundingRect.set(cellX, cellY, cellX + spanX, cellY + spanY); } intersectingViews.clear(); Rect r0 = new Rect(cellX, cellY, cellX + spanX, cellY + spanY); Rect r1 = new Rect(); final int count = mShortcutsAndWidgets.getChildCount(); for (int i = 0; i < count; i++) { View child = mShortcutsAndWidgets.getChildAt(i); if (child == dragView) continue; LayoutParams lp = (LayoutParams) child.getLayoutParams(); r1.set(lp.cellX, lp.cellY, lp.cellX + lp.cellHSpan, lp.cellY + lp.cellVSpan); if (Rect.intersects(r0, r1)) { mIntersectingViews.add(child); if (boundingRect != null) { boundingRect.union(r1); } } } }
private void getViewsIntersectingRegion(int cellX, int cellY, int spanX, int spanY, View dragView, Rect boundingRect, ArrayList<View> intersectingViews) { if (boundingRect != null) { boundingRect.set(cellX, cellY, cellX + spanX, cellY + spanY); } intersectingViews.clear(); Rect r0 = new Rect(cellX, cellY, cellX + spanX, cellY + spanY); Rect r1 = new Rect(); final int count = mShortcutsAndWidgets.getChildCount(); for (int i = 0; i < count; i++) { View child = mShortcutsAndWidgets.getChildAt(i); if (child == dragView) continue; LayoutParams lp = (LayoutParams) child.getLayoutParams(); r1.set(lp.cellX, lp.cellY, lp.cellX + lp.cellHSpan, lp.cellY + lp.cellVSpan); if (Rect.intersects(r0, r1)) { mIntersectingViews.add(child); if (boundingRect != null) { boundingRect.union(r1); } } } }
private void getViewsIntersectingRegion(int cellX, int cellY, int spanX, int spanY, View dragView, Rect boundingRect, ArrayList<View> intersectingViews) { if (boundingRect != null) { boundingRect.set(cellX, cellY, cellX + spanX, cellY + spanY); } intersectingViews.clear(); Rect r0 = new Rect(cellX, cellY, cellX + spanX, cellY + spanY); Rect r1 = new Rect(); final int count = mShortcutsAndWidgets.getChildCount(); for (int i = 0; i < count; i++) { View child = mShortcutsAndWidgets.getChildAt(i); if (child == dragView) continue; LayoutParams lp = (LayoutParams) child.getLayoutParams(); r1.set(lp.cellX, lp.cellY, lp.cellX + lp.cellHSpan, lp.cellY + lp.cellVSpan); if (Rect.intersects(r0, r1)) { mIntersectingViews.add(child); if (boundingRect != null) { boundingRect.union(r1); } } } }
private void getViewsIntersectingRegion(int cellX, int cellY, int spanX, int spanY, View dragView, Rect boundingRect, ArrayList<View> intersectingViews) { if (boundingRect != null) { boundingRect.set(cellX, cellY, cellX + spanX, cellY + spanY); } intersectingViews.clear(); Rect r0 = new Rect(cellX, cellY, cellX + spanX, cellY + spanY); Rect r1 = new Rect(); final int count = mShortcutsAndWidgets.getChildCount(); for (int i = 0; i < count; i++) { View child = mShortcutsAndWidgets.getChildAt(i); if (child == dragView) { continue; } LayoutParams lp = (LayoutParams) child.getLayoutParams(); r1.set(lp.cellX, lp.cellY, lp.cellX + lp.cellHSpan, lp.cellY + lp.cellVSpan); if (Rect.intersects(r0, r1)) { mIntersectingViews.add(child); if (boundingRect != null) { boundingRect.union(r1); } } } }
/** * 根据目标对象相对中心位置,推导箭头朝向 * * @param bubble 气泡的区域 * @param target 目标区域 * @return 推导出的箭头朝向 */ private static ArrowDirection getAutoArrowDirection(Rect bubble, Rect target) { if (!bubble.intersects(target.left, target.top, target.right, target.bottom)) { Point offset = new Point(bubble.centerX() - target.centerX(), bubble.centerY() - target.centerY()); if (Math.abs(offset.x) < bubble.width() / 2 + target.width() / 2) { if (offset.y < 0) { return ArrowDirection.Down; } else if (offset.y > 0) { return ArrowDirection.Up; } } else if (Math.abs(offset.y) < bubble.height() / 2 + target.height() / 2) { if (offset.x < 0) { return ArrowDirection.Right; } else if (offset.x > 0) { return ArrowDirection.Left; } } } return ArrowDirection.None; } }
@Override public void findResultSelected(Rect rect) { super.findResultSelected(rect); boolean makeRoom = false; float density = getContext().getResources().getDisplayMetrics().density; if (rect != null && rect.intersects((int) (getLeft() / density), 0, (int) (getRight() / density), (int) (getHeight() / density))) { makeRoom = true; } setMakeRoomForResults(makeRoom); }
private void recycleChildrenIfNecessary(RecyclerView.Recycler recycler, RecyclerView.State state) { if (getItemCount() <= 0 || state.isPreLayout()) { return; } Rect childRect; for (int i = 0; i < getChildCount(); i++) { //这个方法获取的是RecyclerView中的View,注意区别Recycler中的View //下面几个方法能够获取每个View占用的空间的位置信息,包括ItemDecorator childRect = rectSparseArray.get(i); Log.i(TAG, "recycleChildrenIfNecessary: index = " + i); //如果Item没有在显示区域,就说明需要回收 if (!Rect.intersects(displayRect, childRect)) { //这获取的是实际的View View child = getChildAt(i); Log.i(TAG, "recycleChildrenIfNecessary: index = " + i + ", child = " + (child == null ? "null" : child.getId())); //移除并回收掉滑出屏幕的View removeAndRecycleView(child, recycler); //更新该View的状态为未依附 stateBooleanArray.put(i, false); } } }
public boolean isUserLocationVisible() { if (mLocationOverlay != null) { final Location pos = mLocationOverlay.getLastFix(); if (pos != null && isLayedOut()) { final Projection projection = getProjection(); final float accuracyInPixels = pos.getAccuracy() / (float) projection.groundResolution( pos.getLatitude()); final PointF point = projection.toMapPixels(pos.getLatitude(), pos.getLongitude(), null); return projection.getScreenRect().intersects((int) (point.x - accuracyInPixels), (int) (point.y - accuracyInPixels), (int) (point.x + accuracyInPixels), (int) (point.y + accuracyInPixels)); } } return false; }