android.graphics.Rect#set ( )源码实例Demo

下面列出了android.graphics.Rect#set ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Mysplash   文件: LiveWallpaperService.java
private void ensureSrcRect(Bitmap bitmap, Rect src, Canvas canvas) {
    if (1.0 * bitmap.getWidth() / bitmap.getHeight()
            > 1.0 * canvas.getWidth() / canvas.getHeight()) {
        // landscape.
        src.set(0,
                0,
                (int) (bitmap.getHeight() * 1.0 * canvas.getWidth() / canvas.getHeight()),
                bitmap.getHeight());
        src.right = Math.min(src.right, bitmap.getWidth());
        src.offset((bitmap.getWidth() - src.width()) / 2, 0);
        src.offset((int) ((bitmap.getWidth() - src.width()) / 2 * horizontalOffset), 0);
    } else {
        // portrait.
        src.set(0,
                0,
                bitmap.getWidth(),
                (int) (bitmap.getWidth() * 1.0 * canvas.getHeight() / canvas.getWidth()));
        src.bottom = Math.min(src.bottom, bitmap.getHeight());
        src.offset(0, (bitmap.getHeight() - src.height()) / 2);
    }
}
 
源代码2 项目: stetho   文件: ViewGroupDescriptor.java
@Nullable
@Override
public Object getElementToHighlightAtPosition(ViewGroup element, int x, int y, Rect bounds) {
  View hitChild = null;
  for (int i = element.getChildCount() - 1; i >= 0; --i) {
    final View childView = element.getChildAt(i);
    if (isChildVisible(childView) &&
        childView.getVisibility() == View.VISIBLE) {
      childView.getHitRect(bounds);
      if (bounds.contains(x, y)) {
        hitChild = childView;
        break;
      }
    }
  }

  if (hitChild != null) {
    return hitChild;
  } else {
    bounds.set(0, 0, element.getWidth(), element.getHeight());
    return element;
  }
}
 
源代码3 项目: customview-samples   文件: BaseSplitGridView.java
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    mWidth = w;
    mHeight = h;

    int perWidth = mWidth/getPerLineCount();
    int perHeight = mHeight/getLineCount();

    for(int i=0;i<getLineCount();i++){
        for(int j=0;j<getPerLineCount();j++){
            Rect rect = new Rect();
            int l = perWidth * j;
            int t = perHeight * i;
            rect.set(l,t,l+perWidth,t+perHeight);
            mRectList.add(rect);
        }
    }
}
 
源代码4 项目: customview-samples   文件: RatingGridView.java
private void updateRect(){
    if(mWidth > 0 && mHeight > 0) {
        mRectList.clear();
        int perWidth = mWidth / mColumnCount;
        int perHeight = mHeight / mLineCount;
        for (int i = 0; i < mLineCount; i++) {
            for (int j = 0; j < mColumnCount; j++) {
                Rect rect = new Rect();
                int l = perWidth * j;
                int t = perHeight * i;
                rect.set(l, t, l + perWidth, t + perHeight);
                mRectList.add(rect);
            }
        }
    }
}
 
源代码5 项目: BookReader   文件: SupportDividerItemDecoration.java
@Override
public void getItemOffsets(Rect outRect, int itemPosition, RecyclerView parent) {
    if (mOrientation == VERTICAL_LIST) {
        outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
    } else {
        outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
    }
}
 
/**
 * Find the area of the source file that is currently visible on screen, taking into account the
 * current scale, translation, orientation and clipped region. This is a convenience method; see
 * {@link #viewToFileRect(Rect, Rect)}.
 * @param fRect rectangle instance to which the result will be written. Re-use for efficiency.
 */
public void visibleFileRect(Rect fRect) {
    if (vTranslate == null || !readySent) {
        return;
    }
    fRect.set(0, 0, getWidth(), getHeight());
    viewToFileRect(fRect, fRect);
}
 
@Override
public void getItemOffsets(Rect outRect, int itemPosition, RecyclerView parent) {
    if (mOrientation == VERTICAL_LIST) {
        outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
    } else {
        outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
    }
}
 
源代码8 项目: delion   文件: ToolbarLayout.java
@Override
public void getLocationBarContentRect(Rect outRect) {
    View container = getLocationBar().getContainerView();
    outRect.set(container.getPaddingLeft(), container.getPaddingTop(),
            container.getWidth() - container.getPaddingRight(),
            container.getHeight() - container.getPaddingBottom());
    ViewUtils.getRelativeDrawPosition(
            this, getLocationBar().getContainerView(), mTempPosition);
    outRect.offset(mTempPosition[0], mTempPosition[1]);
}
 
源代码9 项目: HeadsUp   文件: Ripple.java
/**
 * Returns the maximum bounds of the ripple relative to the ripple center.
 */
public void getBounds(Rect bounds) {
    final int outerX = (int) mOuterX;
    final int outerY = (int) mOuterY;
    final int r = (int) mOuterRadius + 1;
    bounds.set(outerX - r, outerY - r, outerX + r, outerY + r);
}
 
源代码10 项目: BlueBoard   文件: DownLoadRvAdapter.java
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    int position = ((RecyclerView.LayoutParams) view.getLayoutParams()).getViewLayoutPosition();
    int marginRight = OkUtils.dp2px(parent.getContext(), 7);
    if (position == 1 | position == 3) {
        outRect.set(0, 0, marginRight, 0);
    }
}
 
源代码11 项目: OpenHub   文件: DividerItemDecoration.java
@Override
public void getItemOffsets(@NonNull Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    if (mOrientation == VERTICAL_LIST) {
        outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
    } else {
        outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
    }
}
 
源代码12 项目: Trebuchet   文件: Workspace.java
/**
 * Draw the View v into the given Canvas.
 *
 * @param v the view to draw
 * @param destCanvas the canvas to draw on
 * @param padding the horizontal and vertical padding to use when drawing
 */
private static void drawDragView(View v, Canvas destCanvas, int padding) {
    final Rect clipRect = sTempRect;
    v.getDrawingRect(clipRect);

    boolean textVisible = false;

    destCanvas.save();
    if (v instanceof TextView) {
        Drawable d = getTextViewIcon((TextView) v);
        Rect bounds = getDrawableBounds(d);
        clipRect.set(0, 0, bounds.width() + padding, bounds.height() + padding);
        destCanvas.translate(padding / 2 - bounds.left, padding / 2 - bounds.top);
        d.draw(destCanvas);
    } else {
        if (v instanceof FolderIcon) {
            // For FolderIcons the text can bleed into the icon area, and so we need to
            // hide the text completely (which can't be achieved by clipping).
            if (((FolderIcon) v).getTextVisible()) {
                ((FolderIcon) v).setTextVisible(false);
                textVisible = true;
            }
        }
        destCanvas.translate(-v.getScrollX() + padding / 2, -v.getScrollY() + padding / 2);
        destCanvas.clipRect(clipRect, Op.REPLACE);
        v.draw(destCanvas);

        // Restore text visibility of FolderIcon if necessary
        if (textVisible) {
            ((FolderIcon) v).setTextVisible(true);
        }
    }
    destCanvas.restore();
}
 
源代码13 项目: Bailan   文件: RecycleViewDivider.java
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    super.getItemOffsets(outRect, view, parent, state);
    outRect.set(0, 0, 0, mDividerHeight);
}
 
源代码14 项目: HightCopyWX   文件: WXItemDecoration.java
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    outRect.set(0,0,0,drawable.getIntrinsicHeight());
}
 
源代码15 项目: AndroidChromium   文件: LocationBarLayout.java
/**
 * @param outRect Populated with a {@link Rect} that represents the {@link Tab} specific content
 *                of this {@link LocationBar}.
 */
public void getContentRect(Rect outRect) {
    outRect.set(getPaddingLeft(), getPaddingTop(), getWidth() - getPaddingRight(),
            getHeight() - getPaddingBottom());
}
 
源代码16 项目: TestChat   文件: ListViewDecoration.java
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        outRect.set(0, 0, 0, divider.getIntrinsicHeight());
}
 
源代码17 项目: osmdroid   文件: ItemizedOverlay.java
/**
 * Calculates the screen rect for an item.
 *
 * @param item
 * @param coords
 * @param reuse
 * @return
 */
protected Rect calculateItemRect(Item item, Point coords, Rect reuse) {
	final Rect out = reuse != null ? reuse : new Rect();

	HotspotPlace hotspot = item.getMarkerHotspot();
	if (hotspot == null) {
		hotspot = HotspotPlace.BOTTOM_CENTER;
	}

	final int state = (mDrawFocusedItem && (mFocusedItem == item) ? OverlayItem.ITEM_STATE_FOCUSED_MASK : 0);
	final Drawable marker = (item.getMarker(state) == null) ? getDefaultMarker(state) : item.getMarker(state);
	int itemWidth = marker.getIntrinsicWidth();
	int itemHeight = marker.getIntrinsicHeight();

	switch (hotspot) {
		case NONE:
			out.set(coords.x - itemWidth / 2,
					coords.y - itemHeight / 2,
					coords.x + itemWidth / 2,
					coords.y + itemHeight / 2);
			break;
		case CENTER:
			out.set(coords.x - itemWidth / 2,
					coords.y - itemHeight / 2,
					coords.x + itemWidth / 2,
					coords.y + itemHeight / 2);
			break;
		case BOTTOM_CENTER:
			out.set(coords.x - itemWidth / 2,
					coords.y - itemHeight,
					coords.x + itemWidth / 2,
					coords.y);
			break;
		case TOP_CENTER:
			out.set(coords.x - itemWidth / 2,
					coords.y,
					coords.x + itemWidth / 2,
					coords.y + itemHeight);
			break;
		case RIGHT_CENTER:
			out.set(coords.x - itemWidth,
					coords.y - itemHeight / 2,
					coords.x ,
					coords.y + itemHeight / 2);
			break;
		case LEFT_CENTER:
			out.set(coords.x,
					coords.y - itemHeight / 2,
					coords.x + itemWidth,
					coords.y + itemHeight / 2);
			break;
		case UPPER_RIGHT_CORNER:
			out.set(coords.x - itemWidth,
					coords.y,
					coords.x ,
					coords.y + itemHeight);
			break;
		case LOWER_RIGHT_CORNER:
			out.set(coords.x - itemWidth,
					coords.y - itemHeight,
					coords.x,
					coords.y);
			break;
		case UPPER_LEFT_CORNER:
			out.set(coords.x ,
					coords.y,
					coords.x + itemWidth,
					coords.y + itemHeight);
			break;
		case LOWER_LEFT_CORNER:
			out.set(coords.x ,
					coords.y - itemHeight,
					coords.x + itemWidth,
					coords.y);
			break;
	}

	return out;
}
 
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    outRect.set(insets, insets, insets, insets);
}
 
源代码19 项目: talkback   文件: RectUtils.java
/**
 * Find the largest sub-rectangle that doesn't intersect a specified one. <strong>Note:</strong>
 * {@code rectToModify} and {@code otherRect} will be sorted after operation.
 *
 * @param rectToModify The rect that may be modified to avoid intersections
 * @param otherRect The rect that should be avoided
 */
public static void adjustRectToAvoidIntersection(Rect rectToModify, Rect otherRect) {
  /*
   * Some rectangles are flipped around (left > right). Make sure we have two Rects free of
   * such pathologies.
   */
  rectToModify.sort();
  otherRect.sort();

  if (rectToModify.contains(otherRect) || !Rect.intersects(rectToModify, otherRect)) {
    return;
  }

  /*
   * Intersect rectToModify with four rects that represent cuts of the entire space along
   * lines defined by the otherRect's edges
   */
  Rect[] cuts = {
    new Rect(rectToModify.left, rectToModify.top, otherRect.left, rectToModify.bottom),
    new Rect(rectToModify.left, rectToModify.top, rectToModify.right, otherRect.top),
    new Rect(otherRect.right, rectToModify.top, rectToModify.right, rectToModify.bottom),
    new Rect(rectToModify.left, otherRect.bottom, rectToModify.right, rectToModify.bottom)
  };

  int maxIntersectingRectArea = 0;
  int indexOfLargestIntersection = -1;
  for (int i = 0; i < cuts.length; i++) {
    if (!isSorted(cuts[i])) {
      continue;
    }
    if (Rect.intersects(cuts[i], rectToModify)) {
      /* Reassign this cut to its intersection with rectToModify */
      int visibleRectArea = cuts[i].width() * cuts[i].height();
      if (visibleRectArea > maxIntersectingRectArea) {
        maxIntersectingRectArea = visibleRectArea;
        indexOfLargestIntersection = i;
      }
    }
  }
  if (maxIntersectingRectArea <= 0) {
    // The rectToModify isn't within any of our cuts, so it's entirely occuled by otherRect.
    rectToModify.setEmpty();
    return;
  }
  rectToModify.set(cuts[indexOfLargestIntersection]);
}
 
源代码20 项目: FireFiles   文件: ViewGroupUtils.java
/**
 * Retrieve the transformed bounding rect of an arbitrary descendant view.
 * This does not need to be a direct child.
 *
 * @param descendant descendant view to reference
 * @param out rect to set to the bounds of the descendant view
 */
static void getDescendantRect(ViewGroup parent, View descendant, Rect out) {
    out.set(0, 0, descendant.getWidth(), descendant.getHeight());
    offsetDescendantRect(parent, descendant, out);
}