android.graphics.RectF Java Examples

The following examples show how to use android.graphics.RectF. 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: CropWindowMoveHandler.java    From Android-Image-Cropper with Apache License 2.0 6 votes vote down vote up
/** Center move only changes the position of the crop window without changing the size. */
private void moveCenter(
    RectF rect, float x, float y, RectF bounds, int viewWidth, int viewHeight, float snapRadius) {
  float dx = x - rect.centerX();
  float dy = y - rect.centerY();
  if (rect.left + dx < 0
      || rect.right + dx > viewWidth
      || rect.left + dx < bounds.left
      || rect.right + dx > bounds.right) {
    dx /= 1.05f;
    mTouchOffset.x -= dx / 2;
  }
  if (rect.top + dy < 0
      || rect.bottom + dy > viewHeight
      || rect.top + dy < bounds.top
      || rect.bottom + dy > bounds.bottom) {
    dy /= 1.05f;
    mTouchOffset.y -= dy / 2;
  }
  rect.offset(dx, dy);
  snapEdgesToBounds(rect, bounds, snapRadius);
}
 
Example #2
Source File: KLetter.java    From ReadMark with Apache License 2.0 6 votes vote down vote up
@Override
protected void initConfig(int x, int y) {
    mPaint = new Paint();
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeWidth(mStrokeWidth);
    mPaint.setAntiAlias(true);
    mPaint.setColor(Config.WHITE);
    mPaint.setStrokeCap(Paint.Cap.SQUARE);

    mRectF = new RectF(x - MAX_RADIUS_CIRCLE
            , y - MAX_RADIUS_CIRCLE - MAX_RADIUS_CIRCLE / 2
            , x + MAX_RADIUS_CIRCLE
            , y + MAX_RADIUS_CIRCLE / 2);

    mFirPoint = new Point(x, y - 2 * MAX_RADIUS_CIRCLE);
    mSecPoint = new Point(mFirPoint);
    mThiPoint = new Point(x, y + MAX_RADIUS_CIRCLE / 2 + MAX_RADIUS_CIRCLE / 4);
    mFourPoint = new Point(mThiPoint);
    mFifPoint = new Point(mThiPoint);
}
 
Example #3
Source File: BubbleDrawable.java    From chatui with Apache License 2.0 6 votes vote down vote up
private void setUpLeftPath(RectF rect, Path path){

        path.moveTo(mArrowWidth + rect.left + mAngle, rect.top);
        path.lineTo(rect.width() - mAngle, rect.top);
        path.arcTo(new RectF(rect.right - mAngle , rect.top, rect.right,
                mAngle + rect.top), 270, 90);
        path.lineTo(rect.right, rect.bottom - mAngle);
        path.arcTo(new RectF(rect.right - mAngle , rect.bottom - mAngle,
                rect.right, rect.bottom), 0, 90);
        path.lineTo(rect.left + mArrowWidth + mAngle, rect.bottom);
        path.arcTo(new RectF(rect.left + mArrowWidth, rect.bottom - mAngle ,
                mAngle + rect.left + mArrowWidth, rect.bottom), 90, 90);
        path.lineTo(rect.left + mArrowWidth,  mArrowHeight + mArrowPosition);
        path.lineTo(rect.left, mArrowPosition + mArrowHeight / 2);
        path.lineTo(rect.left + mArrowWidth, mArrowPosition);
        path.lineTo(rect.left + mArrowWidth, rect.top + mAngle);
        path.arcTo(new RectF(rect.left + mArrowWidth, rect.top, mAngle
                + rect.left + mArrowWidth, mAngle + rect.top), 180, 90);
        path.close();
    }
 
Example #4
Source File: RoundImageView.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
private void createFramedPhotoBorder(int size) {
	Drawable imageDrawable = (image != null) ? new BitmapDrawable(
			getResources(), image) : placeholder;

	Bitmap output = Bitmap
			.createBitmap(size, size, Bitmap.Config.ARGB_8888);
	Canvas canvas = new Canvas(output);

	RectF outerRect = new RectF(0, 0, size, size);
	float cornerRadius = size / 20f;

	Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
	paint.setColor(Color.RED);
	canvas.drawRoundRect(outerRect, cornerRadius, cornerRadius, paint);

	paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
	imageDrawable.setBounds(0, 0, size, size);

	// Save the layer to apply the paint
	canvas.saveLayer(outerRect, paint, Canvas.ALL_SAVE_FLAG);
	imageDrawable.draw(canvas);
	canvas.restore();
	framedPhoto = output;
}
 
Example #5
Source File: ImageViewUtils.java    From PinchToZoom with MIT License 6 votes vote down vote up
/**
 *
 * @param imageView
 * @param width
 * @param height
 */
public static final void updateImageViewMatrix(ImageView imageView, float width, float height) {
    Drawable drawable = imageView.getDrawable();
    if(drawable == null) {
        throw new NullPointerException("ImageView drawable is null");
    }
    Matrix matrix = imageView.getImageMatrix();
    if(!matrix.isIdentity()) {
        float[] values = new float[9];
        matrix.getValues(values);

        RectF src = new RectF();
        src.left = 0;
        src.top = 0;
        src.right = width;
        src.bottom = height;

        RectF dst = new RectF();
        dst.left = values[Matrix.MTRANS_X];
        dst.top = values[Matrix.MTRANS_Y];
        dst.right = dst.left + (drawable.getIntrinsicWidth() * values[Matrix.MSCALE_X]);
        dst.bottom = dst.top + (drawable.getIntrinsicHeight() * values[Matrix.MSCALE_Y]);

        matrix.setRectToRect(src, dst, Matrix.ScaleToFit.CENTER);
    }
}
 
Example #6
Source File: OilTableLine.java    From OXChart with Apache License 2.0 6 votes vote down vote up
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    float size = Math.min(w, h) - tableWidth * 2;
    //油表的位置方框
    mTableRectF = new RectF(0, 0, size, size);
    mPath.reset();
    //在油表路径中增加一个从起始弧度
    mPath.addArc(mTableRectF, 60, 240);
    //计算路径的长度
    PathMeasure pathMeasure = new PathMeasure(mPath, false);
    float length = pathMeasure.getLength();
    float step = length / 60;
    dashPathEffect = new DashPathEffect(new float[]{step / 3, step * 2 / 3}, 0);

    float radius = size / 2;
    mColorShader = new SweepGradient(radius, radius,SWEEP_GRADIENT_COLORS,null);
    //设置指针的路径位置
    mPointerPath.reset();
    mPointerPath.moveTo(radius, radius - 20);
    mPointerPath.lineTo(radius, radius + 20);
    mPointerPath.lineTo(radius * 2 - tableWidth, radius);
    mPointerPath.close();
}
 
Example #7
Source File: RoundedCornerTransformation.java    From data-binding-sample with Apache License 2.0 6 votes vote down vote up
public static Bitmap getRoundedCornerBitmap(Bitmap input,
        float cornerRadius, int w, int h) {

    Bitmap output = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, w, h);
    final RectF rectF = new RectF(rect);

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, cornerRadius, cornerRadius, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(input, 0, 0, paint);

    return output;
}
 
Example #8
Source File: MaterialRippleLayoutNineOld.java    From AdvancedMaterialDrawer with Apache License 2.0 6 votes vote down vote up
@Override
public void draw(Canvas canvas) {
    final boolean positionChanged = adapterPositionChanged();
    if (rippleOverlay) {
        if (!positionChanged) {
            rippleBackground.draw(canvas);
        }
        super.draw(canvas);
        if (!positionChanged) {
            if (rippleRoundedCorners != 0) {
                Path clipPath = new Path();
                RectF rect = new RectF(0, 0, canvas.getWidth(), canvas.getHeight());
                clipPath.addRoundRect(rect, rippleRoundedCorners, rippleRoundedCorners, Path.Direction.CW);
                canvas.clipPath(clipPath);
            }
            canvas.drawCircle(currentCoords.x, currentCoords.y, radius, paint);
        }
    } else {
        if (!positionChanged) {
            rippleBackground.draw(canvas);
            canvas.drawCircle(currentCoords.x, currentCoords.y, radius, paint);
        }
        super.draw(canvas);
    }
}
 
Example #9
Source File: CameraConnectionFragment.java    From fritz-examples with MIT License 6 votes vote down vote up
/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 */
private void configureTransform(final int viewWidth, final int viewHeight) {
    final Activity activity = getActivity();
    if (null == textureView || null == previewSize || null == activity) {
        return;
    }
    final int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    final Matrix matrix = new Matrix();
    final RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    final RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth());
    final float centerX = viewRect.centerX();
    final float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        final float scale =
                Math.max(
                        (float) viewHeight / previewSize.getHeight(),
                        (float) viewWidth / previewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        matrix.postRotate(180, centerX, centerY);
    }
    textureView.setTransform(matrix);
}
 
Example #10
Source File: MaterialTapTargetPrompt.java    From MaterialTapTargetPrompt with Apache License 2.0 6 votes vote down vote up
/**
 * Update the icon drawable position or target render view position.
 */
void updateIconPosition()
{
    mView.mIconDrawable = mView.mPromptOptions.getIconDrawable();
    if (mView.mIconDrawable != null)
    {
        final RectF mFocalBounds = mView.mPromptOptions.getPromptFocal().getBounds();
        mView.mIconDrawableLeft = mFocalBounds.centerX()
                - (mView.mIconDrawable.getIntrinsicWidth() / 2);
        mView.mIconDrawableTop = mFocalBounds.centerY()
                - (mView.mIconDrawable.getIntrinsicHeight() / 2);
    }
    else if (mView.mTargetRenderView != null)
    {
        final int[] viewPosition = new int[2];
        mView.getLocationInWindow(viewPosition);
        final int[] targetPosition = new int[2];
        mView.mTargetRenderView.getLocationInWindow(targetPosition);

        mView.mIconDrawableLeft = targetPosition[0] - viewPosition[0] - mView.mTargetRenderView.getScrollX();
        mView.mIconDrawableTop = targetPosition[1] - viewPosition[1] - mView.mTargetRenderView.getScrollY();
    }
}
 
Example #11
Source File: OC_Numberlines_S3.java    From GLEXP-Team-onebillion with Apache License 2.0 6 votes vote down vote up
public void loadLine(int num,boolean clockwise)
{
    int rocknum = num;
    if(rocknum == 0)
        rocknum = 1;
    PointF position1 = OB_Maths.locationForRect(0.5f,0.01f,objectDict.get(String.format("rock%d", rocknum )).frame());
    PointF position2 = OB_Maths.locationForRect(0.5f,0.01f,objectDict.get(String.format("rock%d", rocknum+1 )).frame());

    OBPath curveLine = new OBPath();
    Path path = new Path();
    float radius = Math.abs(position1.x -position2.x)/2.0f;

    path.addArc(new RectF(position1.x,position1.y-radius,position2.x,position1.y+radius),clockwise ? 180 : 0, clockwise ? 180 : -180);
    curveLine.setPath(path);
    curveLine.sizeToBoundingBox();
    if(num == 0)
        curveLine.setRight ( curveLine.right()-curveLine.width());
    curveLine.setLineWidth((float)Math.ceil(applyGraphicScale(6)));
    curveLine.setStrokeColor( clockwise ? OBUtils.colorFromRGBString("255,252,0") : OBUtils.colorFromRGBString("255,83,0"));
    curveLine.setZPosition(0.8f);
    curveLine.hide();
    attachControl(curveLine);
    curveLine.sizeToBoundingBoxIncludingStroke();

    objectDict.put(String.format("line_%d_%d",clockwise ? 1 : 2, num),curveLine);
}
 
Example #12
Source File: BookmarkUtils.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Use touch-icon or higher-resolution favicon and round the corners.
 * @param context    Context used to get resources.
 * @param touchIcon  Touch icon bitmap.
 * @param canvas     Canvas that holds the touch icon.
 */
private static void drawTouchIconToCanvas(
        Context context, Bitmap touchIcon, Canvas canvas) {
    Rect iconBounds = new Rect(0, 0, canvas.getWidth(), canvas.getHeight());
    Rect src = new Rect(0, 0, touchIcon.getWidth(), touchIcon.getHeight());
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setFilterBitmap(true);
    canvas.drawBitmap(touchIcon, src, iconBounds, paint);
    // Convert dp to px.
    int borderRadii = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
            TOUCHICON_BORDER_RADII, context.getResources().getDisplayMetrics());
    Path path = new Path();
    path.setFillType(Path.FillType.INVERSE_WINDING);
    RectF rect = new RectF(iconBounds);
    rect.inset(INSET_DIMENSION_FOR_TOUCHICON, INSET_DIMENSION_FOR_TOUCHICON);
    path.addRoundRect(rect, borderRadii, borderRadii, Path.Direction.CW);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    canvas.drawPath(path, paint);
}
 
Example #13
Source File: Rings.java    From rings with Apache License 2.0 6 votes vote down vote up
private void initPainters() {
    // Ring Rectangle objects
    ringOverall = new RectF();
    ringInnerThird = new RectF();
    ringInnerSecond = new RectF();
    ringInnerFirst = new RectF();

    // Init rectangles used by texts
    rectOverallText = new Rect();
    rectInnerThirdText = new Rect();
    rectInnerSecondText = new Rect();
    rectInnerFirstText = new Rect();
    // Auxiliary rect to get the width size used by text
    auxRect = new Rect();

    // Ring Paint
    ringPaint = new Paint();
    ringPaint.setAntiAlias(true);
    ringPaint.setStyle(Paint.Style.STROKE);
    ringPaint.setStrokeCap(Paint.Cap.ROUND);

    // Text Paint
    textPaint = new TextPaint();
    textPaint.setTextSize(textSize);
    textPaint.setAntiAlias(true);
}
 
Example #14
Source File: SvgImageView.java    From ZzBeeLayout with Apache License 2.0 6 votes vote down vote up
public static Bitmap getBitmap(Context context, int width, int height, int svgRawResourceId) {
    Bitmap bitmap = Bitmap.createBitmap(width, height,
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.BLACK);

    if (svgRawResourceId > 0) {
        SVG svg = SVGParser.getSVGFromInputStream(
                context.getResources().openRawResource(svgRawResourceId), width, height);
        canvas.drawPicture(svg.getPicture());
    } else {
        canvas.drawRect(new RectF(0.0f, 0.0f, width, height), paint);
    }

    return bitmap;
}
 
Example #15
Source File: CameraConnectionFragment.java    From fritz-examples with MIT License 6 votes vote down vote up
/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 */
private void configureTransform(final int viewWidth, final int viewHeight) {
    final Activity activity = getActivity();
    if (null == textureView || null == previewSize || null == activity) {
        return;
    }
    final int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    final Matrix matrix = new Matrix();
    final RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    final RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth());
    final float centerX = viewRect.centerX();
    final float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        final float scale =
                Math.max(
                        (float) viewHeight / previewSize.getHeight(),
                        (float) viewWidth / previewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        matrix.postRotate(180, centerX, centerY);
    }
    textureView.setTransform(matrix);
}
 
Example #16
Source File: MusicUtils.java    From Rey-MusicPlayer with Apache License 2.0 6 votes vote down vote up
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {
    if (bitmap == null) {
        bitmap = BitmapFactory.decodeResource(Common.getInstance().getResources(),
                R.drawable.ic_placeholder);
    }


    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = pixels;

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;
}
 
Example #17
Source File: SearchModel.java    From document-viewer with GNU General Public License v3.0 6 votes vote down vote up
public RectF moveToNext(final ProgressCallback callback) {
    final IViewController ctrl = base.getDocumentController();
    final int firstVisiblePage = ctrl.getFirstVisiblePage();
    final int lastVisiblePage = ctrl.getLastVisiblePage();

    if (currentPage == null) {
        return searchFirstFrom(firstVisiblePage, callback);
    }

    final Matches m = getMatches(currentPage.index.docIndex);
    if (m == null) {
        return searchFirstFrom(currentPage.index.viewIndex, callback);
    }

    if (firstVisiblePage <= currentPage.index.viewIndex && currentPage.index.viewIndex <= lastVisiblePage) {
        currentMatchIndex++;
        final List<? extends RectF> mm = m.getMatches();
        if (0 <= currentMatchIndex && currentMatchIndex < LengthUtils.length(mm)) {
            return mm.get(currentMatchIndex);
        } else {
            return searchFirstFrom(currentPage.index.viewIndex + 1, callback);
        }
    } else {
        return searchFirstFrom(firstVisiblePage, callback);
    }
}
 
Example #18
Source File: PhotoViewAttacher.java    From imsdk-android with MIT License 5 votes vote down vote up
/**
 * Helper method that maps the supplied Matrix to the current Drawable
 *
 * @param matrix - Matrix to map Drawable against
 * @return RectF - Displayed Rectangle
 */
private RectF getDisplayRect(Matrix matrix) {
    Drawable d = mImageView.getDrawable();
    if (d != null) {
        mDisplayRect.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
        matrix.mapRect(mDisplayRect);
        return mDisplayRect;
    }
    return null;
}
 
Example #19
Source File: HighlightImageView.java    From QuranAndroid with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Function to init image view settings
 */
private void init() {
    this.context = super.getContext();
    mRects = new ArrayList<RectF>();
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setColor(Color.argb(150, 146, 144, 248));
    setOnLongClickListener(this);
    setOnTouchListener(this);
}
 
Example #20
Source File: RoundProgressBar.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    int centre = getWidth() / 2;
    int radius = (int) (((float) centre) - (this.roundWidth / 2.0f));
    this.paint.setColor(this.roundColor);
    this.paint.setStyle(Style.STROKE);
    this.paint.setStrokeWidth(this.roundWidth);
    this.paint.setAntiAlias(true);
    canvas.drawCircle((float) centre, (float) centre, (float) radius, this.paint);
    this.paint.setStrokeWidth(0.0f);
    this.paint.setColor(this.textColor);
    this.paint.setTextSize(this.textSize);
    this.paint.setStrokeCap(Cap.ROUND);
    this.paint.setTypeface(Typeface.DEFAULT_BOLD);
    int percent = (int) ((((float) this.progress) / ((float) this.max)) * 100.0f);
    float textWidth = this.paint.measureText(percent + "%");
    if (this.textIsDisplayable && this.style == 0) {
        canvas.drawText(percent + "%", ((float) centre) - (textWidth / 2.0f), ((float) centre) + (this.textSize / 2.0f), this.paint);
    }
    this.paint.setStrokeWidth(this.roundWidthPlan);
    this.paint.setColor(this.roundProgressColor);
    RectF oval = new RectF((float) (centre - radius), (float) (centre - radius), (float) (centre + radius), (float) (centre + radius));
    switch (this.style) {
        case 0:
            this.paint.setStyle(Style.STROKE);
            canvas.drawArc(oval, 270.0f, (float) ((this.progress * 360) / this.max), false, this.paint);
            return;
        case 1:
            this.paint.setStyle(Style.FILL_AND_STROKE);
            if (this.progress != 0) {
                canvas.drawArc(oval, 270.0f, (float) ((this.progress * 360) / this.max), true, this.paint);
                return;
            }
            return;
        default:
            return;
    }
}
 
Example #21
Source File: CropWindowMoveHandler.java    From timecat with Apache License 2.0 5 votes vote down vote up
/**
 * Adjust left and right edges by current crop window height and the given aspect ratio,
 * both right and left edges adjusts equally relative to center to keep aspect ratio to the height.
 */
private void adjustLeftRightByAspectRatio(RectF rect, RectF bounds, float aspectRatio) {
    rect.inset((rect.width() - rect.height() * aspectRatio) / 2, 0);
    if (rect.left < bounds.left) {
        rect.offset(bounds.left - rect.left, 0);
    }
    if (rect.right > bounds.right) {
        rect.offset(bounds.right - rect.right, 0);
    }
}
 
Example #22
Source File: DocumentCacheFile.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
void saveCropping(final DataOutputStream out, final int tag, final int index, final RectF cropping)
        throws IOException {
    out.writeByte(tag);
    out.writeShort(index);
    out.writeFloat(cropping.left);
    out.writeFloat(cropping.top);
    out.writeFloat(cropping.right);
    out.writeFloat(cropping.bottom);
}
 
Example #23
Source File: HighlightView.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private Rect computeLayout() {
    RectF r = new RectF(cropRect.left, cropRect.top,
                        cropRect.right, cropRect.bottom);
    matrix.mapRect(r);
    return new Rect(Math.round(r.left), Math.round(r.top),
                    Math.round(r.right), Math.round(r.bottom));
}
 
Example #24
Source File: PhotoViewAttacher.java    From PicturePicker with Apache License 2.0 5 votes vote down vote up
@Override
public final boolean onSingleTapConfirmed(MotionEvent e) {
    ImageView imageView = getImageView();

    if (null != imageView) {
        if (null != mPhotoTapListener) {
            final RectF displayRect = getDisplayRect();

            if (null != displayRect) {
                final float x = e.getX(), y = e.getY();

                // Check to see if the user tapped on the photo
                if (displayRect.contains(x, y)) {

                    float xResult = (x - displayRect.left) / displayRect.width();
                    float yResult = (y - displayRect.top) / displayRect.height();

                    mPhotoTapListener.onPhotoTap(imageView, xResult, yResult);
                    return true;
                }
            }
        }
        if (null != mViewTapListener) {
            mViewTapListener.onViewTap(imageView, e.getX(), e.getY());
        }
    }

    return false;
}
 
Example #25
Source File: ImageViewScaler.java    From MultiView with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method that maps the supplied Matrix to the current Drawable
 *
 * @param matrix - Matrix to map Drawable against
 * @return RectF - Displayed Rectangle
 */
private RectF getDisplayRect(Matrix matrix) {
    ImageView imageView = getImageView();

    if (null != imageView) {
        Drawable d = imageView.getDrawable();
        if (null != d) {
            mDisplayRect.set(0, 0, d.getIntrinsicWidth(),
                    d.getIntrinsicHeight());
            matrix.mapRect(mDisplayRect);
            return mDisplayRect;
        }
    }
    return null;
}
 
Example #26
Source File: CircularDrawingDelegate.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
/**
 * Adjusts the canvas for drawing circular progress indicator. It rotates the canvas -90 degrees
 * to keep the 0 at the top. The canvas is clipped to a square with the size just includes the
 * inset. It will also pre-calculate the bound for drawing the arc based on the indicate radius
 * and current indicator width.
 *
 * @param canvas Canvas to draw.
 * @param progressIndicator The component currently serving.
 * @param widthFraction A fraction representing how wide the arc stroke should be.
 */
@Override
public void adjustCanvas(
    @NonNull Canvas canvas,
    @NonNull ProgressIndicator progressIndicator,
    @FloatRange(from = 0.0, to = 1.0) float widthFraction) {
  int outerRadiusWithInset =
      progressIndicator.getCircularRadius()
          + progressIndicator.getIndicatorWidth() / 2
          + progressIndicator.getCircularInset();
  canvas.translate(outerRadiusWithInset, outerRadiusWithInset);
  // Rotates canvas so that arc starts at top.
  canvas.rotate(-90f);

  // Clip all drawing to the designated area, so it doesn't draw outside of its bounds (which can
  // happen in certain configuration of clipToPadding and clipChildren)
  canvas.clipRect(
      -outerRadiusWithInset, -outerRadiusWithInset, outerRadiusWithInset, outerRadiusWithInset);

  // Adjusts the bounds of the arc.
  float adjustedRadius = progressIndicator.getCircularRadius();
  if (progressIndicator.getGrowMode() == ProgressIndicator.GROW_MODE_INCOMING) {
    // Increases the radius by half of the full width, then reduces it half way of the displayed
    // width to match the outer edges of the displayed indicator and the full indicator.
    adjustedRadius += (1 - widthFraction) * progressIndicator.getIndicatorWidth() / 2;
  } else if (progressIndicator.getGrowMode() == ProgressIndicator.GROW_MODE_OUTGOING) {
    // Decreases the radius by half of the full width, then raises it half way of the displayed
    // width to match the inner edges of the displayed indicator and the full indicator.
    adjustedRadius -= (1 - widthFraction) * progressIndicator.getIndicatorWidth() / 2;
  }

  // These are set for the drawing the indicator and track in fillTrackWithColor().
  arcBound = new RectF(-adjustedRadius, -adjustedRadius, adjustedRadius, adjustedRadius);
  arcInverseFactor = progressIndicator.isInverse() ? -1 : 1;
}
 
Example #27
Source File: FontDrawable.java    From FontDrawable with Apache License 2.0 5 votes vote down vote up
private void applyPadding(Path path, RectF textBounds, Rect paddingBounds) {
    final Rect viewBounds = getBounds();
    float deltaWidth = ((float) paddingBounds.width() / textBounds.width());
    float deltaHeight = ((float) paddingBounds.height() / textBounds.height());
    float attenuate = (deltaWidth < deltaHeight) ? deltaWidth : deltaHeight;
    float textSize = paint.getTextSize();
    textSize *= attenuate;
    paint.setTextSize(textSize);
    paint.getTextPath(String.valueOf(fontCode), 0, 1, 0, viewBounds.height(), path);
    path.computeBounds(textBounds, true);
}
 
Example #28
Source File: CircleProgressBar.java    From ProgressBar with MIT License 5 votes vote down vote up
@Override
public void drawProgress(Canvas canvas) {
    //绘制外环
    paint.setColor(backgroundColor);
    canvas.drawCircle(width / 2, height / 2, width / 2, paint);

    //绘制进度
    paint.setColor(fillColor);
    float angle = (progress / 1f /this.maxProgress * 360);
    RectF rectF = new RectF(0, 0, width, height);
    canvas.drawArc(rectF, -90, angle, true, paint);
    //绘制内环
    paint.setColor(smallCircleColor);
    canvas.drawCircle(width / 2, height / 2, width / 2 - progressWidth, paint);
}
 
Example #29
Source File: PieChartView.java    From bither-android with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Canvas canvas, Paint paint) {
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(color);
    canvas.drawOval(new RectF(2, 2, canvas.getWidth() - 2, canvas.getHeight() - 2), paint);
}
 
Example #30
Source File: Page.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
public Page(final IActivityController base, final PageIndex index, final PageType pt, final CodecPageInfo cpi) {
    this.base = base;
    this.index = index;
    this.cpi = cpi;
    this.type = pt != null ? pt : PageType.FULL_PAGE;
    this.bounds = new RectF(0, 0, cpi.width / type.getWidthScale(), cpi.height);

    setAspectRatio(cpi);

    nodes = new PageTree(this);
}