android.graphics.RectF#centerY ( )源码实例Demo

下面列出了android.graphics.RectF#centerY ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * 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);
}
 
/**
 * 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);
}
 
源代码3 项目: MaterialTapTargetPrompt   文件: PromptFocal.java
/**
 * 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);
}
 
源代码4 项目: EasyPhotos   文件: MatrixUtils.java
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;
}
 
@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;
}
 
源代码6 项目: styT   文件: MaterialTapTargetPrompt.java
/**
 * 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];
    }
}
 
/**
 * 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);
}
 
源代码8 项目: fritz-examples   文件: CameraConnectionFragment.java
/**
 * 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);
}
 
/**
 * 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();
    }
}
 
/**
 * 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);
}
 
源代码11 项目: UltimateAndroid   文件: Transition.java
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();
}
 
源代码12 项目: MVPAndroidBootstrap   文件: Transition.java
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();
}
 
源代码13 项目: imageCrop   文件: CropDrawingUtils.java
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);
}
 
源代码14 项目: Circle-Progress-View   文件: CircleProgressView.java
/**
 * 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());
}
 
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);
}
 
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();
}
 
源代码17 项目: pixate-freestyle-android   文件: PXEllipse.java
public void setBounds(RectF bounds) {
    radiusX = bounds.centerX();
    radiusY = bounds.centerY();
    center.x = bounds.left + radiusX;
    center.y = bounds.top + radiusY;
    clearPath();
}
 
源代码18 项目: styT   文件: FullscreenPromptBackground.java
@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();
}
 
源代码19 项目: imageCrop   文件: CropMath.java
/**
 * 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);
}
 
源代码20 项目: Vorolay   文件: VoronoiRegion.java
private void prepareCenter() {
    RectF mRectF = new RectF();
    path.computeBounds(mRectF, true);
    center_rect = new VoronoiPoint(mRectF.centerX(), mRectF.centerY());
}