public float contentHeight() { return mContentRect.height(); }
/** * Adjust left edge by current crop window height and the given aspect ratio, the right edge * remains in possition while the left adjusts to keep aspect ratio to the height. */ private void adjustLeftByAspectRatio(RectF rect, float aspectRatio) { rect.left = rect.right - rect.height() * aspectRatio; }
/** * Adjust right edge by current crop window height and the given aspect ratio, the left edge * remains in possition while the left adjusts to keep aspect ratio to the height. */ private void adjustRightByAspectRatio(RectF rect, float aspectRatio) { rect.right = rect.left + rect.height() * aspectRatio; }
/** * Returns the smallest extension of the content rect (width or height). * * @return */ public float getSmallestContentExtension() { return Math.min(mContentRect.width(), mContentRect.height()); }
@Override public float getRadius() { if (mCircleBox == null) return 0; else return Math.min(mCircleBox.width() / 2f, mCircleBox.height() / 2f); }
/** * Indicates whether the crop window is small enough that the guidelines should be shown. Public * because this function is also used to determine if the center handle should be focused. * * @return boolean Whether the guidelines should be shown or not */ public boolean showGuidelines() { return !(mEdges.width() < 100 || mEdges.height() < 100); }
private static void clearCanvas(Canvas canvas, RectF rect) { if (rect.width() <= 0 || rect.height() <= 0) { return; } canvas.drawRect(rect, PAINT); } }
/** * This method calculates image minimum and maximum scale values for current {@link #mCropRect}. * * @param drawableWidth - image width * @param drawableHeight - image height */ private void calculateImageScaleBounds(float drawableWidth, float drawableHeight) { float widthScale = Math.min(mCropRect.width() / drawableWidth, mCropRect.width() / drawableHeight); float heightScale = Math.min(mCropRect.height() / drawableHeight, mCropRect.height() / drawableWidth); mMinScale = Math.min(widthScale, heightScale); mMaxScale = mMinScale * mMaxScaleMultiplier; }
@Override public float getRadius() { RectF content = mViewPortHandler.getContentRect(); return Math.min(content.width() / 2f, content.height() / 2f); }
/** * Returns the factor that is needed to transform values into pixels. * * @return */ public float getFactor() { RectF content = mViewPortHandler.getContentRect(); return Math.min(content.width() / 2f, content.height() / 2f) / mYAxis.mAxisRange; }
private void updateShaderMatrix() { float scale; float dx = 0; float dy = 0; mShaderMatrix.set(null); if (mBitmapWidth * mDrawableRect.height() > mDrawableRect.width() * mBitmapHeight) { scale = mDrawableRect.height() / (float) mBitmapHeight; dx = (mDrawableRect.width() - mBitmapWidth * scale) * 0.5f; } else { scale = mDrawableRect.width() / (float) mBitmapWidth; dy = (mDrawableRect.height() - mBitmapHeight * scale) * 0.5f; } mShaderMatrix.setScale(scale, scale); mShaderMatrix.postTranslate((int) (dx + 0.5f) + mDrawableRect.left, (int) (dy + 0.5f) + mDrawableRect.top); mBitmapShader.setLocalMatrix(mShaderMatrix); }
private void buildShader() { if (mIsBrightnessGradient) { mShader = new LinearGradient(mGradientRect.left, mGradientRect.top, mGradientRect.right, mGradientRect.top, mSelectedColorGradient, null, Shader.TileMode.CLAMP); } else { LinearGradient gradientShader = new LinearGradient(mGradientRect.left, mGradientRect.top, mGradientRect.right, mGradientRect.top, GRAD_COLORS, null, Shader.TileMode.CLAMP); LinearGradient alphaShader = new LinearGradient(0, mGradientRect.top + (mGradientRect.height() / 3), 0, mGradientRect.bottom, GRAD_ALPHA, null, Shader.TileMode.CLAMP); mShader = new ComposeShader(alphaShader, gradientShader, PorterDuff.Mode.MULTIPLY); } mPaint.setShader(mShader); }
@Implementation protected void drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint) { describeBitmap(bitmap, paint); StringBuilder descriptionBuilder = new StringBuilder(); if (dst != null) { descriptionBuilder.append(" at (").append(dst.left).append(",").append(dst.top) .append(") with height=").append(dst.height()).append(" and width=").append(dst.width()); } if (src != null) { descriptionBuilder.append( " taken from ").append(src.toString()); } appendDescription(descriptionBuilder.toString()); }
private void updateGridPoints() { mCropGridCorners = RectUtils.getCornersFromRect(mCropViewRect); mCropGridCenter = RectUtils.getCenterFromRect(mCropViewRect); mGridPoints = null; mCircularPath.reset(); mCircularPath.addCircle(mCropViewRect.centerX(), mCropViewRect.centerY(), Math.min(mCropViewRect.width(), mCropViewRect.height()) / 2.f, Path.Direction.CW); }
private void make(Bitmap bitmap) { mBitmap = getCroppedRoundBitmap(bitmap, 255, 15); mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); mBitmapPaint.setAntiAlias(true); mBitmapPaint.setShader(mBitmapShader); mDrawableRect.set(0, 0, getWidth(), getHeight()); mDrawableRadius = Math.min(mDrawableRect.height() / 2, mDrawableRect.width() / 2); mBitmapHeight = mBitmap.getHeight(); mBitmapWidth = mBitmap.getWidth(); updateShaderMatrix(); invalidate(); }
/** * returns the diameter of the pie- or radar-chart * * @return */ public float getDiameter() { RectF content = mViewPortHandler.getContentRect(); content.left += getExtraLeftOffset(); content.top += getExtraTopOffset(); content.right -= getExtraRightOffset(); content.bottom -= getExtraBottomOffset(); return Math.min(content.width(), content.height()); }
private LinearGradient getLinearGradient() { int gradientHash = getGradientHash(); LinearGradient gradient = linearGradientCache.get(gradientHash); if (gradient != null) { return gradient; } PointF startPoint = startPointAnimation.getValue(); PointF endPoint = endPointAnimation.getValue(); GradientColor gradientColor = colorAnimation.getValue(); int[] colors = gradientColor.getColors(); float[] positions = gradientColor.getPositions(); int x0 = (int) (boundsRect.left + boundsRect.width() / 2 + startPoint.x); int y0 = (int) (boundsRect.top + boundsRect.height() / 2 + startPoint.y); int x1 = (int) (boundsRect.left + boundsRect.width() / 2 + endPoint.x); int y1 = (int) (boundsRect.top + boundsRect.height() / 2 + endPoint.y); gradient = new LinearGradient(x0, y0, x1, y1, colors, positions, Shader.TileMode.CLAMP); linearGradientCache.put(gradientHash, gradient); return gradient; }
private void updatePointerPosition() { if (mGradientRect.width() != 0 && mGradientRect.height() != 0) { if (!mIsBrightnessGradient) { mLastX = hueToPoint(mHSV[0]); mLastY = saturationToPoint(mHSV[1]); } else { mLastX = brightnessToPoint(mHSV[2]); } } }
private RadialGradient getRadialGradient() { int gradientHash = getGradientHash(); RadialGradient gradient = radialGradientCache.get(gradientHash); if (gradient != null) { return gradient; } PointF startPoint = startPointAnimation.getValue(); PointF endPoint = endPointAnimation.getValue(); GradientColor gradientColor = colorAnimation.getValue(); int[] colors = gradientColor.getColors(); float[] positions = gradientColor.getPositions(); int x0 = (int) (boundsRect.left + boundsRect.width() / 2 + startPoint.x); int y0 = (int) (boundsRect.top + boundsRect.height() / 2 + startPoint.y); int x1 = (int) (boundsRect.left + boundsRect.width() / 2 + endPoint.x); int y1 = (int) (boundsRect.top + boundsRect.height() / 2 + endPoint.y); float r = (float) Math.hypot(x1 - x0, y1 - y0); gradient = new RadialGradient(x0, y0, r, colors, positions, Shader.TileMode.CLAMP); radialGradientCache.put(gradientHash, gradient); return gradient; }
/** * Updates current crop rectangle with given. Also recalculates image properties and position * to fit new crop rectangle. * * @param cropRect - new crop rectangle */ public void setCropRect(RectF cropRect) { mTargetAspectRatio = cropRect.width() / cropRect.height(); mCropRect.set(cropRect.left - getPaddingLeft(), cropRect.top - getPaddingTop(), cropRect.right - getPaddingRight(), cropRect.bottom - getPaddingBottom()); calculateImageScaleBounds(); setImageToWrapCropBounds(); }