android.graphics.Rect.intersects()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(149)

本文整理了Java中android.graphics.Rect.intersects方法的一些代码示例,展示了Rect.intersects的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Rect.intersects方法的具体详情如下:
包路径:android.graphics.Rect
类名称:Rect
方法名:intersects

Rect.intersects介绍

[英]Returns true if this rectangle intersects the specified rectangle. In no event is this rectangle modified. No check is performed to see if either rectangle is empty. To record the intersection, use intersect() or setIntersect().
[中]如果此矩形与指定矩形相交,则返回true。在任何情况下都不会修改此矩形。不执行任何检查以查看任一矩形是否为空。要记录交点,请使用intersect()或setIntersect()。

代码示例

代码示例来源:origin: alexvasilkov/GestureViews

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();
}

代码示例来源:origin: robolectric/robolectric

@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();
}

代码示例来源:origin: robolectric/robolectric

@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();
}

代码示例来源:origin: robolectric/robolectric

@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();
}

代码示例来源:origin: facebook/litho

!isIncrementalMountEnabled ||
  isMountedHostWithChildContent(currentMountItem) ||
  Rect.intersects(localVisibleRect, layoutOutput.getBounds()) ||
  isAnimationLocked(i) ||
  (currentMountItem != null && currentMountItem == rootMountItem);

代码示例来源:origin: recruit-lifestyle/FloatingView

/**
 * 削除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);
}

代码示例来源:origin: elevenetc/InteractiveCanvas

public boolean intersectsWith(Rect rect) {
  return Rect.intersects(rect, bounds);
}

代码示例来源:origin: stackoverflow.com

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"); 
 }

代码示例来源:origin: limboemu/limbo

/**
 * 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;
}

代码示例来源:origin: stackoverflow.com

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);
}

代码示例来源:origin: ultramega/elementary

/**
 * 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());
}

代码示例来源:origin: fookwood/Launcher3

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);
      }
    }
  }
}

代码示例来源:origin: klinker24/Android-Blur-Launcher

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);
      }
    }
  }
}

代码示例来源:origin: enricocid/LaunchEnr

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);
      }
    }
  }
}

代码示例来源:origin: klinker24/launcher3

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);
      }
    }
  }
}

代码示例来源:origin: WeAreFairphone/FP2-Launcher

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);
      }
    }
  }
}

代码示例来源:origin: cpiz/BubbleView

/**
   * 根据目标对象相对中心位置,推导箭头朝向
   *
   * @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;
  }
}

代码示例来源:origin: derry/delion

@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);
}

代码示例来源:origin: JustinRoom/JSCKit

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);
    }
  }
}

代码示例来源:origin: posm/OpenMapKitAndroid

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;
}

相关文章