Code example for Rect

Methods: heightwidth

0
		Rect r = computeLayout();
		if (edge == GROW_NONE) {
			return; 
		} else if (edge == MOVE) {
			// Convert to image space before sending to moveBy(). 
			moveBy(dx * (mCropRect.width() / r.width()), dy * (mCropRect.height() / r.height()));
		} else { 
			if (((GROW_LEFT_EDGE | GROW_RIGHT_EDGE) & edge) == 0) {
				dx = 0;
			} 
 
			if (((GROW_TOP_EDGE | GROW_BOTTOM_EDGE) & edge) == 0) {
				dy = 0;
			} 
 
			// Convert to image space before sending to growBy(). 
			float xDelta = dx * (mCropRect.width() / r.width());
			float yDelta = dy * (mCropRect.height() / r.height());
			growBy((((edge & GROW_LEFT_EDGE) != 0) ? -1 : 1) * xDelta, (((edge & GROW_TOP_EDGE) != 0) ? -1 : 1)
					* yDelta);
		} 
	} 
 
	// Grows the cropping rectange by (dx, dy) in image space. 
	void moveBy(float dx, float dy) {
		Rect invalRect = new Rect(mDrawRect);
 
		mCropRect.offset(dx, dy);
 
		// Put the cropping rectangle inside image rectangle. 
		mCropRect.offset(Math.max(0, mImageRect.left - mCropRect.left), Math.max(0, mImageRect.top - mCropRect.top));
 
		mCropRect.offset(Math.min(0, mImageRect.right - mCropRect.right),
				Math.min(0, mImageRect.bottom - mCropRect.bottom));
 
		mDrawRect = computeLayout();
		invalRect.union(mDrawRect);
		invalRect.inset(-10, -10);
		mContext.invalidate(invalRect);
	} 
 
	protected void draw(Canvas canvas) {
		canvas.save();
 
		mOutlinePath.reset();
		mOutlinePath.addRect(mDrawRect.left, mDrawRect.top, mDrawRect.right, mDrawRect.bottom, Path.Direction.CW);
 
		if (!Platform.isCanvasHardwareAccelerated(canvas)) {
			canvas.clipPath(mOutlinePath, Region.Op.DIFFERENCE);
			canvas.drawPaint(mFocusPaint);
		} 
 
		canvas.restore();
 
		canvas.drawPath(mOutlinePath, mOutlinePaint);
 
		/** 
		 * Draw Handle Drawables 
		 */ 
		int left = mDrawRect.left + 1;
		int right = mDrawRect.right + 1;
		int top = mDrawRect.top + 4;
		int bottom = mDrawRect.bottom + 3;
 
		int widthWidth = mResizeDrawableWidth.getIntrinsicWidth() / 2;
		int widthHeight = mResizeDrawableWidth.getIntrinsicHeight() / 2;
		int heightHeight = mResizeDrawableHeight.getIntrinsicHeight() / 2;
		int heightWidth = mResizeDrawableHeight.getIntrinsicWidth() / 2;
 
		int xMiddle = mDrawRect.left + ((mDrawRect.right - mDrawRect.left) / 2);
		int yMiddle = mDrawRect.top + ((mDrawRect.bottom - mDrawRect.top) / 2);
 
		mResizeDrawableWidth.setBounds(left - widthWidth, yMiddle - widthHeight, left + widthWidth, yMiddle
				+ widthHeight);
		mResizeDrawableWidth.draw(canvas);
 
		mResizeDrawableWidth.setBounds(right - widthWidth, yMiddle - widthHeight, right + widthWidth, yMiddle
				+ widthHeight);
		mResizeDrawableWidth.draw(canvas);
 
		mResizeDrawableHeight.setBounds(xMiddle - heightWidth, top - heightHeight, xMiddle + heightWidth, top
				+ heightHeight);
		mResizeDrawableHeight.draw(canvas);
 
		mResizeDrawableHeight.setBounds(xMiddle - heightWidth, bottom - heightHeight, xMiddle + heightWidth, bottom
				+ heightHeight);
		mResizeDrawableHeight.draw(canvas);
	} 
 
	// Maps the cropping rectangle from image space to screen space. 
	private Rect computeLayout() {
		RectF r = new RectF(mCropRect.left, mCropRect.top, mCropRect.right, mCropRect.bottom);
		mMatrix.mapRect(r);
		return new Rect(Math.round(r.left), Math.round(r.top), Math.round(r.right), Math.round(r.bottom));
	} 
 
	private void init() { 
		android.content.res.Resources resources = mContext.getResources();
		mResizeDrawableWidth = resources.getDrawable(R.drawable.crop_handle_x);