Java Code Examples for android.graphics.RectF#centerY()

The following examples show how to use android.graphics.RectF#centerY() . 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: CameraConnectionFragment.java    From android-yolo-v2 with Do What The F*ck You Want To Public 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 2
Source File: Transition.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
public Transition(RectF srcRect, RectF dstRect, long duration, Interpolator interpolator) {
    // Reduces precision to avoid problems when comparing aspect ratios.
    float srcRectRatio = MathUtils.truncate(MathUtils.getRectRatio(srcRect), 2);
    float dstRectRatio = MathUtils.truncate(MathUtils.getRectRatio(dstRect), 2);

    if (srcRectRatio != dstRectRatio) {
        throw new IncompatibleRatioException();
    }
    mSrcRect = srcRect;
    mDstRect = dstRect;
    mDuration = duration;
    mInterpolator = interpolator;

    // Precomputes a few variables to avoid doing it in onDraw().
    mWidthDiff = dstRect.width() - srcRect.width();
    mHeightDiff = dstRect.height() - srcRect.height();
    mCenterXDiff = dstRect.centerX() - srcRect.centerX();
    mCenterYDiff = dstRect.centerY() - srcRect.centerY();
}
 
Example 3
Source File: CameraConnectionFragment.java    From next18-ai-in-motion with Apache License 2.0 6 votes vote down vote up
/**
 * Configures the necessary {@link 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 4
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 5
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 6
Source File: Camera2BasicFragment.java    From Android-Camera2-Front-with-Face-Detection with Apache License 2.0 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(int viewWidth, int viewHeight) {
    Activity activity = getActivity();
    if (null == mTextureView || null == mPreviewSize || null == activity) {
        return;
    }
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    Matrix matrix = new Matrix();
    RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
    float centerX = viewRect.centerX();
    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);
        float scale = Math.max(
                (float) viewHeight / mPreviewSize.getHeight(),
                (float) viewWidth / mPreviewSize.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);
    }
    mTextureView.setTransform(matrix);
}
 
Example 7
Source File: MaterialTapTargetPrompt.java    From styT 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.mIconDrawableTop = targetPosition[1] - viewPosition[1];
    }
}
 
Example 8
Source File: PieChartTouchHandler.java    From hellocharts-android with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
    if (isRotationEnabled) {
        // Set the pie rotation directly.
        final RectF circleOval = pieChart.getCircleOval();
        final float centerX = circleOval.centerX();
        final float centerY = circleOval.centerY();
        float scrollTheta = vectorToScalarScroll(distanceX, distanceY, e2.getX() - centerX, e2.getY() -
                centerY);
        pieChart.setChartRotation(pieChart.getChartRotation() - (int) scrollTheta / FLING_VELOCITY_DOWNSCALE,
                false);
        return true;
    }

    return false;
}
 
Example 9
Source File: MatrixUtils.java    From EasyPhotos with Apache License 2.0 6 votes vote down vote up
private static Matrix generateCenterCropMatrix(Area area, int width, int height,
                                               float extraSize) {
  final RectF rectF = area.getAreaRect();

  Matrix matrix = new Matrix();

  float offsetX = rectF.centerX() - width / 2;
  float offsetY = rectF.centerY() - height / 2;

  matrix.postTranslate(offsetX, offsetY);

  float scale;

  if (width * rectF.height() > rectF.width() * height) {
    scale = (rectF.height() + extraSize) / height;
  } else {
    scale = (rectF.width() + extraSize) / width;
  }

  matrix.postScale(scale, scale, rectF.centerX(), rectF.centerY());

  return matrix;
}
 
Example 10
Source File: PromptFocal.java    From MaterialTapTargetPrompt with Apache License 2.0 6 votes vote down vote up
/**
 * Calculate the point on the focal edge based on the angle.
 * This is called after {@link #prepare(PromptOptions, float, float)} or
 * {@link #prepare(PromptOptions, View, int[])}.
 *
 * Base implementation assumes that focal is a rectangle.
 *
 * @param angle The angle with 0 based on the right.
 * @param padding The padding added to the focal bounds.
 * @return The calculated point
 */
@NonNull
public PointF calculateAngleEdgePoint(float angle, final float padding)
{
    // Calculate the x and y on the focal from the angle calculated
    final RectF bounds = this.getBounds();
    final float angleRadians = (float) Math.toRadians(angle);
    final float sin = (float) Math.sin(angleRadians);
    final float cos = (float) Math.cos(angleRadians);
    final float dx1 = (bounds.width() + padding) / (cos > 0 ? 2 : -2);
    final float dy1 = (bounds.height() + padding) / (sin > 0 ? 2 : -2);

    // Could go to part way along the target bounds but risk cutting off corners
    /*final float dxs = dx1 * sin;
    final float dyc = dy1 * cos;
    final float dx = Math.abs(dxs) < Math.abs(dyc) ? dx1 : dyc / sin;
    final float dy = Math.abs(dxs) < Math.abs(dyc) ? dxs / cos : dy1;*/

    return new PointF(bounds.centerX() + dx1, bounds.centerY() + dy1);
}
 
Example 11
Source File: CameraConnectionFragment.java    From AndroidDemoProjects with Apache License 2.0 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 12
Source File: FaceDetectorUtil.java    From rtmp-rtsp-stream-client-java with Apache License 2.0 5 votes vote down vote up
private FaceParsed getFace(RectF rectF, PointF scale, View view) {
  //Position
  float posX = rectF.centerX() * 100 / view.getWidth();
  float posY = rectF.centerY() * 100 / view.getHeight();
  PointF positionParsed = new PointF(posX - scale.x / 2, posY - scale.y / 2);
  //Scale
  float scaleX = rectF.width() * 100 / view.getWidth();
  float scaleY = rectF.height() * 100 / view.getHeight();
  PointF scaleParsed = new PointF(scaleX, scaleY);
  return new FaceParsed(positionParsed, scaleParsed);
}
 
Example 13
Source File: AllAngleExpandableButton.java    From AllAngleExpandableButton with Apache License 2.0 5 votes vote down vote up
private void ripple(int index, float pressX, float pressY) {
    if (index < 0 || !allAngleExpandableButton.rippleEffect) {
        return;
    }
    allAngleExpandableButton.resetRippleInfo();
    ButtonData buttonData = allAngleExpandableButton.buttonDatas.get(index);
    RectF rectF = allAngleExpandableButton.buttonRects.get(buttonData);
    float centerX = rectF.centerX();
    float centerY = rectF.centerY();
    float radius = rectF.centerX() - rectF.left;
    float distanceX = pressX - centerX;
    float distanceY = pressY - centerY;
    float pressToCenterDistance = (float) Math.sqrt(distanceX * distanceX + distanceY * distanceY);
    if (pressToCenterDistance > radius) {
        //press out of the button circle
        return;
    }
    allAngleExpandableButton.rippleInfo.pressX = pressX;
    allAngleExpandableButton.rippleInfo.pressY = pressY;
    allAngleExpandableButton.rippleInfo.buttonIndex = index;
    allAngleExpandableButton.rippleInfo.rippleRadius = radius + pressToCenterDistance;
    allAngleExpandableButton.rippleInfo.rippleColor = getRippleColor(allAngleExpandableButton.rippleColor == Integer.MIN_VALUE ?
            buttonData.getBackgroundColor() : allAngleExpandableButton.rippleColor);

    rippleRadius = allAngleExpandableButton.rippleInfo.rippleRadius;
    startRippleAnimator();
}
 
Example 14
Source File: PXEllipse.java    From pixate-freestyle-android with Apache License 2.0 5 votes vote down vote up
public void setBounds(RectF bounds) {
    radiusX = bounds.centerX();
    radiusY = bounds.centerY();
    center.x = bounds.left + radiusX;
    center.y = bounds.top + radiusY;
    clearPath();
}
 
Example 15
Source File: CircleProgressView.java    From Circle-Progress-View with MIT License 5 votes vote down vote up
/**
 * Set the bounds of the component
 */
private void setupBounds() {
    // Width should equal to Height, find the min value to setup the circle
    int minValue = Math.min(mLayoutWidth, mLayoutHeight);

    // Calc the Offset if needed
    int xOffset = mLayoutWidth - minValue;
    int yOffset = mLayoutHeight - minValue;

    // Add the offset
    float paddingTop = this.getPaddingTop() + (yOffset / 2);
    float paddingBottom = this.getPaddingBottom() + (yOffset / 2);
    float paddingLeft = this.getPaddingLeft() + (xOffset / 2);
    float paddingRight = this.getPaddingRight() + (xOffset / 2);

    int width = getWidth(); //this.getLayoutParams().width;
    int height = getHeight(); //this.getLayoutParams().height;

    float circleWidthHalf = mBarWidth / 2f > mRimWidth / 2f + mOuterContourSize ? mBarWidth / 2f : mRimWidth / 2f + mOuterContourSize;

    mCircleBounds = new RectF(paddingLeft + circleWidthHalf,
            paddingTop + circleWidthHalf,
            width - paddingRight - circleWidthHalf,
            height - paddingBottom - circleWidthHalf);


    mInnerCircleBound = new RectF(paddingLeft + (mBarWidth),
            paddingTop + (mBarWidth),
            width - paddingRight - (mBarWidth),
            height - paddingBottom - (mBarWidth));
    mOuterTextBounds = getInnerCircleRect(mCircleBounds);
    mCircleInnerContour = new RectF(mCircleBounds.left + (mRimWidth / 2.0f) + (mInnerContourSize / 2.0f), mCircleBounds.top + (mRimWidth / 2.0f) + (mInnerContourSize / 2.0f), mCircleBounds.right - (mRimWidth / 2.0f) - (mInnerContourSize / 2.0f), mCircleBounds.bottom - (mRimWidth / 2.0f) - (mInnerContourSize / 2.0f));
    mCircleOuterContour = new RectF(mCircleBounds.left - (mRimWidth / 2.0f) - (mOuterContourSize / 2.0f), mCircleBounds.top - (mRimWidth / 2.0f) - (mOuterContourSize / 2.0f), mCircleBounds.right + (mRimWidth / 2.0f) + (mOuterContourSize / 2.0f), mCircleBounds.bottom + (mRimWidth / 2.0f) + (mOuterContourSize / 2.0f));

    mCenter = new PointF(mCircleBounds.centerX(), mCircleBounds.centerY());
}
 
Example 16
Source File: CropDrawingUtils.java    From imageCrop with MIT License 5 votes vote down vote up
public static void drawWallpaperSelectionFrame(Canvas canvas, RectF cropBounds, float spotX,
                                               float spotY, Paint p, Paint shadowPaint) {
    float sx = cropBounds.width() * spotX;
    float sy = cropBounds.height() * spotY;
    float cx = cropBounds.centerX();
    float cy = cropBounds.centerY();
    RectF r1 = new RectF(cx - sx / 2, cy - sy / 2, cx + sx / 2, cy + sy / 2);
    float temp = sx;
    sx = sy;
    sy = temp;
    RectF r2 = new RectF(cx - sx / 2, cy - sy / 2, cx + sx / 2, cy + sy / 2);
    canvas.save();
    canvas.clipRect(cropBounds);
    canvas.clipRect(r1, Region.Op.DIFFERENCE);
    canvas.clipRect(r2, Region.Op.DIFFERENCE);
    canvas.drawPaint(shadowPaint);
    canvas.restore();
    Path path = new Path();
    path.moveTo(r1.left, r1.top);
    path.lineTo(r1.right, r1.top);
    path.moveTo(r1.left, r1.top);
    path.lineTo(r1.left, r1.bottom);
    path.moveTo(r1.left, r1.bottom);
    path.lineTo(r1.right, r1.bottom);
    path.moveTo(r1.right, r1.top);
    path.lineTo(r1.right, r1.bottom);
    path.moveTo(r2.left, r2.top);
    path.lineTo(r2.right, r2.top);
    path.moveTo(r2.right, r2.top);
    path.lineTo(r2.right, r2.bottom);
    path.moveTo(r2.left, r2.bottom);
    path.lineTo(r2.right, r2.bottom);
    path.moveTo(r2.left, r2.top);
    path.lineTo(r2.left, r2.bottom);
    canvas.drawPath(path, p);
}
 
Example 17
Source File: FullscreenPromptBackground.java    From styT with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare(@NonNull final PromptOptions options, final boolean clipToBounds, @NonNull Rect clipBounds)
{
    final RectF focalBounds = options.getPromptFocal().getBounds();
    DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();

    mBaseBounds.set(0, 0, metrics.widthPixels, metrics.heightPixels);
    mFocalCentre.x = focalBounds.centerX();
    mFocalCentre.y = focalBounds.centerY();
}
 
Example 18
Source File: CropMath.java    From imageCrop with MIT License 5 votes vote down vote up
/**
 * Resizes rectangle to have a certain aspect ratio (center remains
 * stationary).
 *
 * @param r rectangle to resize
 * @param w new width aspect
 * @param h new height aspect
 */
public static void fixAspectRatio(RectF r, float w, float h) {
    float scale = Math.min(r.width() / w, r.height() / h);
    float centX = r.centerX();
    float centY = r.centerY();
    float hw = scale * w / 2;
    float hh = scale * h / 2;
    r.set(centX - hw, centY - hh, centX + hw, centY + hh);
}
 
Example 19
Source File: Transition.java    From MVPAndroidBootstrap with Apache License 2.0 5 votes vote down vote up
public Transition(RectF srcRect, RectF dstRect, long duration, Interpolator interpolator) {
    if (!MathUtils.haveSameAspectRatio(srcRect, dstRect)) {
        throw new IncompatibleRatioException();
    }
    mSrcRect = srcRect;
    mDstRect = dstRect;
    mDuration = duration;
    mInterpolator = interpolator;

    // Precomputes a few variables to avoid doing it in onDraw().
    mWidthDiff = dstRect.width() - srcRect.width();
    mHeightDiff = dstRect.height() - srcRect.height();
    mCenterXDiff = dstRect.centerX() - srcRect.centerX();
    mCenterYDiff = dstRect.centerY() - srcRect.centerY();
}
 
Example 20
Source File: VoronoiRegion.java    From Vorolay with Apache License 2.0 4 votes vote down vote up
private void prepareCenter() {
    RectF mRectF = new RectF();
    path.computeBounds(mRectF, true);
    center_rect = new VoronoiPoint(mRectF.centerX(), mRectF.centerY());
}