List of usage examples for android.graphics RectF width
public final float width()
From source file:org.getlantern.firetweet.view.ShapedImageView.java
private void drawBorder(@NonNull final Canvas canvas, @NonNull final RectF dest) { if (mBorderColors == null) return;/*from w ww.j av a2 s . co m*/ final RectF transitionSrc = mTransitionSource, transitionDst = mTransitionDestination; final float strokeWidth; if (transitionSrc != null && transitionDst != null) { final float progress = 1 - (dest.width() - transitionDst.width()) / (transitionSrc.width() - transitionDst.width()); strokeWidth = mStrokeWidth * progress; mBorderPaint.setAlpha(Math.round(mBorderAlpha * progress)); ViewCompat.setTranslationZ(this, -ViewCompat.getElevation(this) * (1 - progress)); } else { strokeWidth = mStrokeWidth; mBorderPaint.setAlpha(mBorderAlpha); ViewCompat.setTranslationZ(this, 0); } mBorderPaint.setStrokeWidth(strokeWidth); if (getStyle() == SHAPE_CIRCLE) { final float circleRadius = Math.min(dest.width(), dest.height()) / 2f - strokeWidth / 2; canvas.drawCircle(dest.centerX(), dest.centerY(), circleRadius, mBorderPaint); } else { final float radius = getCalculatedCornerRadius(); final float inset = mStrokeWidth / 2; dest.inset(inset, inset); canvas.drawRoundRect(dest, radius, radius, mBorderPaint); dest.inset(-inset, -inset); } }
From source file:com.example.linhdq.test.documents.creation.crop.CropImageActivity.java
@OnClick(R.id.item_save) void onSaveClicked() { if (!mCropData.isPresent() || mSaving || (mCrop == null)) { return;//ww w . jav a2s .com } mSaving = true; Util.startBackgroundJob(this, null, getText(R.string.cropping_image).toString(), new Runnable() { public void run() { try { float scale = 1f / mCropData.get().getScaleResult().getScaleFactor(); Matrix scaleMatrix = new Matrix(); scaleMatrix.setScale(scale, scale); final float[] trapezoid = mCrop.getTrapezoid(); final RectF perspectiveCorrectedBoundingRect = new RectF( mCrop.getPerspectiveCorrectedBoundingRect()); scaleMatrix.mapRect(perspectiveCorrectedBoundingRect); Box bb = new Box((int) perspectiveCorrectedBoundingRect.left, (int) perspectiveCorrectedBoundingRect.top, (int) perspectiveCorrectedBoundingRect.width(), (int) perspectiveCorrectedBoundingRect.height()); Pix pix8 = Convert.convertTo8(mPix); mPix.recycle(); Pix croppedPix = Clip.clipRectangle2(pix8, bb); if (croppedPix == null) { throw new IllegalStateException(); } pix8.recycle(); scaleMatrix.postTranslate(-bb.getX(), -bb.getY()); scaleMatrix.mapPoints(trapezoid); final float[] dest = new float[] { 0, 0, bb.getWidth(), 0, bb.getWidth(), bb.getHeight(), 0, bb.getHeight() }; Pix bilinear = Projective.projectiveTransform(croppedPix, dest, trapezoid); if (bilinear == null) { bilinear = croppedPix; } else { croppedPix.recycle(); } if (mRotation != 0 && mRotation != 4) { Pix rotatedPix = Rotate.rotateOrth(bilinear, mRotation); bilinear.recycle(); bilinear = rotatedPix; } if (bilinear == null) { throw new IllegalStateException(); } Intent result = new Intent(); OCR.savePixToCacheDir(CropImageActivity.this, bilinear.copy()); result.putExtra(DocumentGridActivity.EXTRA_NATIVE_PIX, bilinear.getNativePix()); setResult(RESULT_OK, result); } catch (IllegalStateException e) { setResult(RESULT_CANCELED); } finally { finish(); } } }, mHandler); }
From source file:com.ferdi2005.secondgram.AndroidUtilities.java
public static void setRectToRect(Matrix matrix, RectF src, RectF dst, int rotation, Matrix.ScaleToFit align) { float tx, sx; float ty, sy; if (rotation == 90 || rotation == 270) { sx = dst.height() / src.width(); sy = dst.width() / src.height(); } else {//from w ww. ja va 2 s .c o m sx = dst.width() / src.width(); sy = dst.height() / src.height(); } if (align != Matrix.ScaleToFit.FILL) { if (sx > sy) { sx = sy; } else { sy = sx; } } tx = -src.left * sx; ty = -src.top * sy; matrix.setTranslate(dst.left, dst.top); if (rotation == 90) { matrix.preRotate(90); matrix.preTranslate(0, -dst.width()); } else if (rotation == 180) { matrix.preRotate(180); matrix.preTranslate(-dst.width(), -dst.height()); } else if (rotation == 270) { matrix.preRotate(270); matrix.preTranslate(-dst.height(), 0); } matrix.preScale(sx, sy); matrix.preTranslate(tx, ty); }
From source file:com.huyn.demogroup.freechild.FixedViewAttacher.java
private boolean checkMatrixBounds() { final RectF rect = getVisibleRect(); if (rect == null) { return false; }// w ww . ja va 2s . c o m RectF src = new RectF(); src.set(rect); final float h = rect.height(), w = rect.width(); float deltaX = 0, deltaY = 0; View parent = (View) mImageView.getParent(); final int viewHeight = parent.getHeight();//getImageViewHeight(mImageView); final int viewWidth = parent.getWidth();//getImageViewWidth(mImageView); System.out.println("===============================================width:" + viewWidth + "/" + viewHeight); System.out .println("+++++++++rect.left:" + rect.left + "/" + rect.top + "/" + rect.right + "/" + rect.bottom); float scale = getScale(); float centerX = rect.centerX(); float centerY = rect.centerY(); float targetW = w * scale; float targetH = h * scale; RectF targetRect = new RectF(centerX - targetW / 2, centerY - targetH / 2, centerX + targetW / 2, centerY + targetH / 2); rect.set(targetRect); final float height = rect.height(), width = rect.width(); if (height <= viewHeight) { deltaY = (viewHeight - height) / 2 - rect.top; } else if (rect.top > 0) { deltaY = -rect.top; } else if (rect.bottom < viewHeight) { deltaY = viewHeight - rect.bottom; } if (width <= viewWidth) { deltaX = (viewWidth - width) / 2 - rect.left; mScrollEdge = EDGE_BOTH; } else if (rect.left > 0) { mScrollEdge = EDGE_LEFT; deltaX = -rect.left; } else if (rect.right < viewWidth) { deltaX = viewWidth - rect.right; mScrollEdge = EDGE_RIGHT; } else { mScrollEdge = EDGE_NONE; } // Finally actually translate the matrix if (!mStable) { System.out.println("+++++++++++deltaX:" + deltaX + "/deltaY:" + deltaY + "---" + getScale()); postTranslate(deltaX, deltaY); } return true; }
From source file:com.undatech.opaque.RemoteCanvas.java
/** * Redraws the location of the remote pointer. *///from w ww. ja v a 2 s.c o m public void reDrawRemotePointer() { if (myDrawable != null) { myDrawable.moveCursorRect(pointer.getX(), pointer.getY()); RectF r = myDrawable.getCursorRect(); reDraw(r.left, r.top, r.width(), r.height()); } }
From source file:com.undatech.opaque.RemoteCanvas.java
/** * Moves soft cursor into a particular location. * @param x/* w w w . jav a 2 s . com*/ * @param y */ synchronized void softCursorMove(int x, int y) { if (myDrawable.isNotInitSoftCursor()) { initializeSoftCursor(); } if (!cursorBeingMoved) { pointer.setX(x); pointer.setY(y); RectF prevR = new RectF(myDrawable.getCursorRect()); // Move the cursor. myDrawable.moveCursorRect(x, y); // Show the cursor. RectF r = myDrawable.getCursorRect(); reDraw(r.left, r.top, r.width(), r.height()); reDraw(prevR.left, prevR.top, prevR.width(), prevR.height()); } }
From source file:com.mediatek.galleryfeature.stereo.segment.ImageShow.java
protected void constrainTranslation(Point translation, float scale) { int currentEdgeEffect = 0; if (scale <= 1) { finishEdgeEffect();/*w w w. ja va 2s . c o m*/ return; } Rect originalBounds = mMasterImage.getOriginalBounds(); Matrix originalToScreen = mMasterImage.getImageToScreenMatrix(originalBounds.width(), originalBounds.height(), getWidth(), getHeight()); if (originalToScreen == null) { finishEdgeEffect(); return; } RectF screenPos = new RectF(originalBounds); originalToScreen.mapRect(screenPos); boolean rightConstraint = screenPos.right < getWidth(); boolean leftConstraint = screenPos.left > 0; boolean topConstraint = screenPos.top > 0; boolean bottomConstraint = screenPos.bottom < getHeight(); if (screenPos.width() > getWidth()) { if (rightConstraint && !leftConstraint) { float tx = screenPos.right - translation.x * scale; translation.x = (int) ((getWidth() - tx) / scale); currentEdgeEffect = EDGE_RIGHT; } else if (leftConstraint && !rightConstraint) { float tx = screenPos.left - translation.x * scale; translation.x = (int) ((-tx) / scale); currentEdgeEffect = EDGE_LEFT; } } else { float tx = screenPos.right - translation.x * scale; float dx = (getWidth() - screenPos.width()) / 2f; translation.x = (int) ((getWidth() - tx - dx) / scale); } if (screenPos.height() > getHeight()) { if (bottomConstraint && !topConstraint) { float ty = screenPos.bottom - translation.y * scale; translation.y = (int) ((getHeight() - ty) / scale); currentEdgeEffect = EDGE_BOTTOM; } else if (topConstraint && !bottomConstraint) { float ty = screenPos.top - translation.y * scale; translation.y = (int) ((-ty) / scale); currentEdgeEffect = EDGE_TOP; } } else { float ty = screenPos.bottom - translation.y * scale; float dy = (getHeight() - screenPos.height()) / 2f; translation.y = (int) ((getHeight() - ty - dy) / scale); } if (mCurrentEdgeEffect != currentEdgeEffect) { if (mCurrentEdgeEffect == 0 || currentEdgeEffect != 0) { mCurrentEdgeEffect = currentEdgeEffect; mEdgeEffect.finish(); } mEdgeEffect.setSize(getWidth(), mEdgeSize); } if (currentEdgeEffect != 0) { mEdgeEffect.onPull(mEdgeSize); } }
From source file:com.huyn.demogroup.leaveblank.PhotoViewAttacher.java
private boolean checkMatrixBounds() { final RectF rect = getDisplayRect(getDrawMatrix()); if (rect == null) { return false; }/*from ww w . j a va2 s . c om*/ final float height = rect.height(), width = rect.width(); float deltaX = 0, deltaY = 0; final int viewHeight = getImageViewHeight(mImageView); if (height <= viewHeight) { switch (mScaleType) { case FIT_START: deltaY = -rect.top; break; case FIT_END: deltaY = viewHeight - height - rect.top; break; default: deltaY = (viewHeight - height) / 2 - rect.top; break; } } else if (rect.top > 0) { deltaY = -rect.top; } else if (rect.bottom < viewHeight) { deltaY = viewHeight - rect.bottom; } final int viewWidth = getImageViewWidth(mImageView); if (width <= viewWidth) { switch (mScaleType) { case FIT_START: deltaX = -rect.left; break; case FIT_END: deltaX = viewWidth - width - rect.left; break; default: deltaX = (viewWidth - width) / 2 - rect.left; break; } mScrollEdge = EDGE_BOTH; } else if (rect.left > 0) { mScrollEdge = EDGE_LEFT; deltaX = -rect.left; } else if (rect.right < viewWidth) { deltaX = viewWidth - rect.right; mScrollEdge = EDGE_RIGHT; } else { mScrollEdge = EDGE_NONE; } // Finally actually translate the matrix if (!mStable) { System.out.println("+++++++++++deltaX:" + deltaX + "/deltaY:" + deltaY + "---" + getScale()); mSuppMatrix.postTranslate(deltaX, deltaY); } return true; }
From source file:de.vanita5.twittnuker.view.ColorPickerView.java
private Point alphaToPoint(final int alpha) { final RectF rect = mAlphaRect; final float width = rect.width(); final Point p = new Point(); p.x = (int) (width - alpha * width / 0xff + rect.left); p.y = (int) rect.top; return p;/*from www .jav a2 s . c o m*/ }
From source file:de.vanita5.twittnuker.view.ColorPickerView.java
private int pointToAlpha(int x) { final RectF rect = mAlphaRect; final int width = (int) rect.width(); if (x < rect.left) { x = 0;// w w w . ja v a2 s . c o m } else if (x > rect.right) { x = width; } else { x = x - (int) rect.left; } return 0xff - x * 0xff / width; }