Java Code Examples for android.graphics.Rect#set()

The following examples show how to use android.graphics.Rect#set() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LiveWallpaperService.java    From Mysplash with GNU Lesser General Public License v3.0 6 votes vote down vote up
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);
    }
}
 
Example 2
Source File: ViewGroupDescriptor.java    From stetho with MIT License 6 votes vote down vote up
@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;
  }
}
 
Example 3
Source File: BaseSplitGridView.java    From customview-samples with Apache License 2.0 6 votes vote down vote up
@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);
        }
    }
}
 
Example 4
Source File: RatingGridView.java    From customview-samples with Apache License 2.0 6 votes vote down vote up
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);
            }
        }
    }
}
 
Example 5
Source File: SubsamplingScaleImageView.java    From subsampling-scale-image-view with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 6
Source File: Workspace.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 7
Source File: DividerItemDecoration.java    From OpenHub with GNU General Public License v3.0 5 votes vote down vote up
@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);
    }
}
 
Example 8
Source File: DownLoadRvAdapter.java    From BlueBoard with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example 9
Source File: Ripple.java    From HeadsUp with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 10
Source File: ToolbarLayout.java    From delion with Apache License 2.0 5 votes vote down vote up
@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]);
}
 
Example 11
Source File: DividerItemDecoration.java    From CoordinatorLayoutExample with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example 12
Source File: SupportDividerItemDecoration.java    From BookReader with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example 13
Source File: WXItemDecoration.java    From HightCopyWX with Apache License 2.0 4 votes vote down vote up
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    outRect.set(0,0,0,drawable.getIntrinsicHeight());
}
 
Example 14
Source File: RecycleViewDivider.java    From Bailan with Apache License 2.0 4 votes vote down vote up
@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);
}
 
Example 15
Source File: LocationBarLayout.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * @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());
}
 
Example 16
Source File: ListViewDecoration.java    From TestChat with Apache License 2.0 4 votes vote down vote up
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        outRect.set(0, 0, 0, divider.getIntrinsicHeight());
}
 
Example 17
Source File: ItemizedOverlay.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 18
Source File: RecyclerViewInsetDecoration.java    From PagerDatePicker with Apache License 2.0 4 votes vote down vote up
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    outRect.set(insets, insets, insets, insets);
}
 
Example 19
Source File: RectUtils.java    From talkback with Apache License 2.0 4 votes vote down vote up
/**
 * 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]);
}
 
Example 20
Source File: ViewGroupUtils.java    From FireFiles with Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}