Example usage for android.graphics RectF RectF

List of usage examples for android.graphics RectF RectF

Introduction

In this page you can find the example usage for android.graphics RectF RectF.

Prototype

public RectF(float left, float top, float right, float bottom) 

Source Link

Document

Create a new rectangle with the specified coordinates.

Usage

From source file:org.odk.collect.android.fragments.Camera2VideoFragment.java

/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `textureView`.
 * This method should not to be called until the camera preview size is determined in
 * openCamera, or until the size of `textureView` is fixed.
 *
 * @param viewWidth  The width of `textureView`
 * @param viewHeight The height of `textureView`
 *//*from   ww  w .j a  va  2s .co m*/
private void configureTransform(int viewWidth, int viewHeight) {
    Activity activity = getActivity();
    if (null == textureView || null == previewSize || 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, previewSize.getHeight(), previewSize.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 / previewSize.getHeight(),
                (float) viewWidth / previewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    }
    textureView.setTransform(matrix);
}

From source file:com.android.rahul.myselfieapp.Fragment.CamVideoFragment.java

/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
 * This method should not to be called until the camera preview size is determined in
 * openCamera, or until the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 *///from  w  w w.j a  v a2 s  .  c  o m
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);
    }
    mTextureView.setTransform(matrix);
}

From source file:com.raulh82vlc.face_detection_sample.camera2.presentation.FDCamera2Presenter.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`
 *///from  w  w  w  .ja  v  a  2s  .co m
private void configureTransform(int viewWidth, int viewHeight) {
    if (isViewAvailable()) {
        if (null == activityView.getTextureView()) {
            return;
        }
        int rotation = activityView.getWindowManager().getDefaultDisplay().getRotation();
        Matrix matrix = new Matrix();
        RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
        RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.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 / 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);
        }
        activityView.getTextureView().setTransform(matrix);
    }
}

From source file:com.caseystalnaker.android.popinvideodemo.fragments.Camera2VideoFragment.java

/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
 * This method should not to be called until the camera preview size is determined in
 * openCamera, or until the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 *///from w ww  .  j a  va 2s.  c om
private void configureTransform(final int viewWidth, final int viewHeight) {
    Activity activity = getActivity();
    if (null == mTextureView || null == mPreviewSize || 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, mPreviewSize.getHeight(), mPreviewSize.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 / mPreviewSize.getHeight(),
                (float) viewWidth / mPreviewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    }
    mTextureView.setTransform(matrix);
}

From source file:lollipop.iconics.IconicsDrawable.java

@Override
public void draw(Canvas canvas) {
    if (mIcon != null || mPlainIcon != null) {
        final Rect viewBounds = getBounds();

        updatePaddingBounds(viewBounds);
        updateTextSize(viewBounds);/*from   w w  w. j a va2  s . c  o  m*/
        offsetIcon(viewBounds);

        if (mBackgroundPaint != null && mRoundedCornerRy > -1 && mRoundedCornerRx > -1) {
            canvas.drawRoundRect(new RectF(0, 0, viewBounds.width(), viewBounds.height()), mRoundedCornerRx,
                    mRoundedCornerRy, mBackgroundPaint);
        }

        mPath.close();

        if (mDrawContour) {
            canvas.drawPath(mPath, mContourPaint);
        }

        mIconPaint.setAlpha(mAlpha);

        canvas.drawPath(mPath, mIconPaint);
    }
}

From source file:com.ezartech.ezar.videooverlay.ezAR.java

private void calculateFocusArea(int focusWidth, int focusHeight, float areaMultiple, int x, int y,
        int previewWidth, int previewHeight, Rect rect) {
    int areaWidth = (int) (focusWidth * areaMultiple);
    int areaHeight = (int) (focusHeight * areaMultiple);
    int left = Util.clamp(x - areaWidth / 2, 0, previewWidth - areaWidth);
    int top = Util.clamp(y - areaHeight / 2, 0, previewHeight - areaHeight);
    RectF rectF = new RectF(left, top, left + areaWidth, top + areaHeight);
    matrix.mapRect(rectF);/*w  ww .  ja v  a 2  s  . c o  m*/
    Util.rectFToRect(rectF, rect);
}

From source file:com.wanikani.androidnotifier.graph.TYPlot.java

@Override
protected void onSizeChanged(int width, int height, int ow, int oh) {
    meas.updateSize(new RectF(0, 0, width, height));
    vp.updateSize(pager != null ? pager.dsource.getMaxY() : 100);
    dsink.refresh();//from www .  ja va2  s .c o  m
}

From source file:com.appeaser.sublimepickerlibrary.datepicker.SimpleMonthView.java

/**
 * Draws the month days./*from  w  w w.  j a v  a 2  s .  c  o m*/
 */
@SuppressWarnings("ConstantConditions")
private void drawDays(Canvas canvas) {
    final TextPaint p = mDayPaint;
    final int headerHeight = mMonthHeight + mDayOfWeekHeight;
    //final int rowHeight = mDayHeight;
    final float rowHeight = mDayHeight;
    //final int colWidth = mCellWidth;
    final float colWidth = mCellWidth;

    // Text is vertically centered within the row height.
    final float halfLineHeight = (p.ascent() + p.descent()) / 2f;
    //int rowCenter = headerHeight + rowHeight / 2;
    float rowCenter = headerHeight + rowHeight / 2f;

    for (int day = 1, col = findDayOffset(); day <= mDaysInMonth; day++) {
        //final int colCenter = colWidth * col + colWidth / 2;
        final float colCenter = colWidth * col + colWidth / 2f;
        //final int colCenterRtl;
        final float colCenterRtl;
        if (SUtils.isLayoutRtlCompat(this)) {
            colCenterRtl = mPaddedWidth - colCenter;
        } else {
            colCenterRtl = colCenter;
        }

        int stateMask = 0;

        final boolean isDayEnabled = isDayEnabled(day);
        if (isDayEnabled) {
            stateMask |= SUtils.STATE_ENABLED;
        }

        final boolean isDayInActivatedRange = mActivatedDays.isValid() && mActivatedDays.isActivated(day);
        final boolean isSelected = mActivatedDays.isSelected(day);

        if (isSelected) {
            stateMask |= SUtils.STATE_ACTIVATED;
            canvas.drawCircle(colCenterRtl, rowCenter, mDaySelectorRadius, mDaySelectorPaint);
        } else if (isDayInActivatedRange) {
            stateMask |= SUtils.STATE_ACTIVATED;

            int bgShape = DRAW_RECT;

            if (mActivatedDays.isSingleDay()) {
                if (mActivatedDays.isStartOfMonth()) {
                    bgShape = DRAW_RECT_WITH_CURVE_ON_RIGHT;
                } else {
                    bgShape = DRAW_RECT_WITH_CURVE_ON_LEFT;
                }
            } else if (mActivatedDays.isStartingDayOfRange(day)) {
                bgShape = DRAW_RECT_WITH_CURVE_ON_LEFT;
            } else if (mActivatedDays.isEndingDayOfRange(day)) {
                bgShape = DRAW_RECT_WITH_CURVE_ON_RIGHT;
            }

            // Use height to constrain the protrusion of the arc
            boolean constrainProtrusion = colWidth > (rowHeight - (2 * mPaddingRangeIndicator));
            float horDistFromCenter = constrainProtrusion ? rowHeight / 2f - mPaddingRangeIndicator
                    : colWidth / 2f;

            switch (bgShape) {
            case DRAW_RECT_WITH_CURVE_ON_LEFT:
                int leftRectArcLeft = (int) (colCenterRtl - horDistFromCenter) % 2 == 1
                        ? (int) (colCenterRtl - horDistFromCenter) + 1
                        : (int) (colCenterRtl - horDistFromCenter);

                int leftRectArcRight = (int) (colCenterRtl + horDistFromCenter) % 2 == 1
                        ? (int) (colCenterRtl + horDistFromCenter) + 1
                        : (int) (colCenterRtl + horDistFromCenter);

                RectF leftArcRect = new RectF(leftRectArcLeft,
                        rowCenter - rowHeight / 2f + mPaddingRangeIndicator, leftRectArcRight,
                        rowCenter + rowHeight / 2f - mPaddingRangeIndicator);

                canvas.drawArc(leftArcRect, 90, 180, true, mDayRangeSelectorPaint);

                canvas.drawRect(new RectF(leftArcRect.centerX(),
                        rowCenter - rowHeight / 2f + mPaddingRangeIndicator, colCenterRtl + colWidth / 2f,
                        rowCenter + rowHeight / 2f - mPaddingRangeIndicator), mDayRangeSelectorPaint);
                break;
            case DRAW_RECT_WITH_CURVE_ON_RIGHT:
                int rightRectArcLeft = (int) (colCenterRtl - horDistFromCenter) % 2 == 1
                        ? (int) (colCenterRtl - horDistFromCenter) + 1
                        : (int) (colCenterRtl - horDistFromCenter);

                int rightRectArcRight = (int) (colCenterRtl + horDistFromCenter) % 2 == 1
                        ? (int) (colCenterRtl + horDistFromCenter) + 1
                        : (int) (colCenterRtl + horDistFromCenter);

                RectF rightArcRect = new RectF(rightRectArcLeft,
                        rowCenter - rowHeight / 2f + mPaddingRangeIndicator, rightRectArcRight,
                        rowCenter + rowHeight / 2f - mPaddingRangeIndicator);

                canvas.drawArc(rightArcRect, 270, 180, true, mDayRangeSelectorPaint);

                canvas.drawRect(new RectF(colCenterRtl - colWidth / 2f,
                        rowCenter - rowHeight / 2f + mPaddingRangeIndicator, rightArcRect.centerX(),
                        rowCenter + rowHeight / 2f - mPaddingRangeIndicator), mDayRangeSelectorPaint);
                break;
            default:
                canvas.drawRect(new RectF(colCenterRtl - colWidth / 2f,
                        rowCenter - rowHeight / 2f + mPaddingRangeIndicator, colCenterRtl + colWidth / 2f,
                        rowCenter + rowHeight / 2f - mPaddingRangeIndicator), mDayRangeSelectorPaint);
                break;
            }
        }

        if (mTouchedItem == day) {
            stateMask |= SUtils.STATE_PRESSED;

            if (isDayEnabled) {
                canvas.drawCircle(colCenterRtl, rowCenter, mDaySelectorRadius, mDayHighlightPaint);
            }
        }

        final boolean isDayToday = mToday == day;
        final int dayTextColor;

        if (isDayToday && !isDayInActivatedRange) {
            dayTextColor = mDaySelectorPaint.getColor();
        } else {
            final int[] stateSet = SUtils.resolveStateSet(stateMask);
            dayTextColor = mDayTextColor.getColorForState(stateSet, 0);
        }
        p.setColor(dayTextColor);

        canvas.drawText(mDayFormatter.format(day), colCenterRtl, rowCenter - halfLineHeight, p);

        col++;

        if (col == DAYS_IN_WEEK) {
            col = 0;
            rowCenter += rowHeight;
        }
    }
}

From source file:com.miuhouse.yourcompany.student.view.widget.date.datepicker.SimpleMonthView.java

/**
 * Draws the month days./*from  w  ww. j av  a 2  s .co  m*/
 */
@SuppressWarnings("ConstantConditions")
private void drawDays(Canvas canvas) {
    final TextPaint p = mDayPaint;
    final int headerHeight = mMonthHeight + mDayOfWeekHeight;

    final float rowHeight = mDayHeight;

    final float colWidth = mCellWidth;

    // Text is vertically centered within the row height.
    final float halfLineHeight = (p.ascent() + p.descent()) / 2f;
    //        int rowCenter = headerHeight + rowHeight / 2;
    float rowCenter = headerHeight + rowHeight / 2f;
    //mDaysInMonth303129
    for (int day = 1, col = findDayOffset(); day <= mDaysInMonth; day++) {
        final float colCenter = colWidth * col + colWidth / 2f;
        //final int colCenterRtl;
        final float colCenterRtl;
        if (SUtils.isLayoutRtlCompat(this)) {
            colCenterRtl = mPaddedWidth - colCenter;
        } else {
            colCenterRtl = colCenter;
        }

        int stateMask = 0;

        final boolean isDayEnabled = isDayEnabled(day);
        if (isDayEnabled) {
            stateMask |= SUtils.STATE_ENABLED;
        }

        final boolean isDayInActivatedRange = mActivatedDays.isValid() && mActivatedDays.isActivated(day);
        final boolean isSelected = mActivatedDays.isSelected(day);
        final boolean isSelectedAndTogether = mActivatedDays.isSelectedAndTogether(day);
        if (isSelectedAndTogether) {
            if ((!disable && !isDisable) || isFill) {
                stateMask |= SUtils.STATE_ACTIVATED;
                canvas.drawCircle(colCenterRtl, rowCenter, mDaySelectorRadius, mDaySelectorPaint);
            }
        }
        if (!isSelected && isDayInActivatedRange) {

            stateMask |= SUtils.STATE_ACTIVATED;
            int bgShape = DRAW_RECT;
            if (mActivatedDays.isSingleDay()) {
                if (mActivatedDays.isStartOfMonth()) {
                    bgShape = DRAW_RECT_WITH_CURVE_ON_RIGHT;
                } else {
                    bgShape = DRAW_RECT_WITH_CURVE_ON_LEFT;
                }
            } else if (mActivatedDays.isStartingDayOfRange(day)) {
                bgShape = DRAW_RECT_WITH_CURVE_ON_LEFT;
            } else if (mActivatedDays.isEndingDayOfRange(day)) {
                bgShape = DRAW_RECT_WITH_CURVE_ON_RIGHT;
            }

            // Use height to constrain the protrusion of the arc
            boolean constrainProtrusion = colWidth > (rowHeight - (2 * mPaddingRangeIndicator));

            float horDistFromCenter = constrainProtrusion ? rowHeight / 2f - mPaddingRangeIndicator
                    : colWidth / 2f;
            switch (bgShape) {
            case DRAW_RECT_WITH_CURVE_ON_LEFT:

                int leftRectArcLeft = (int) (colCenterRtl - horDistFromCenter) % 2 == 1
                        ? (int) (colCenterRtl - horDistFromCenter) + 1
                        : (int) (colCenterRtl - horDistFromCenter);

                int leftRectArcRight = (int) (colCenterRtl + horDistFromCenter) % 2 == 1
                        ? (int) (colCenterRtl + horDistFromCenter) + 1
                        : (int) (colCenterRtl + horDistFromCenter);

                RectF leftArcRect = new RectF(leftRectArcLeft,
                        rowCenter - rowHeight / 2f + mPaddingRangeIndicator, leftRectArcRight,
                        rowCenter + rowHeight / 2f - mPaddingRangeIndicator);

                canvas.drawArc(leftArcRect, 90, 180, true, mDayRangeSelectorPaint);

                canvas.drawRect(new RectF(leftArcRect.centerX(),
                        rowCenter - rowHeight / 2f + mPaddingRangeIndicator, colCenterRtl + colWidth / 2f,
                        rowCenter + rowHeight / 2f - mPaddingRangeIndicator), mDayRangeSelectorPaint);
                break;
            case DRAW_RECT_WITH_CURVE_ON_RIGHT:
                int rightRectArcLeft = (int) (colCenterRtl - horDistFromCenter) % 2 == 1
                        ? (int) (colCenterRtl - horDistFromCenter) + 1
                        : (int) (colCenterRtl - horDistFromCenter);

                int rightRectArcRight = (int) (colCenterRtl + horDistFromCenter) % 2 == 1
                        ? (int) (colCenterRtl + horDistFromCenter) + 1
                        : (int) (colCenterRtl + horDistFromCenter);

                RectF rightArcRect = new RectF(rightRectArcLeft,
                        rowCenter - rowHeight / 2f + mPaddingRangeIndicator, rightRectArcRight,
                        rowCenter + rowHeight / 2f - mPaddingRangeIndicator);

                canvas.drawArc(rightArcRect, 270, 180, true, mDayRangeSelectorPaint);

                canvas.drawRect(new RectF(colCenterRtl - colWidth / 2f,
                        rowCenter - rowHeight / 2f + mPaddingRangeIndicator, rightArcRect.centerX(),
                        rowCenter + rowHeight / 2f - mPaddingRangeIndicator), mDayRangeSelectorPaint);
                break;
            default:
                canvas.drawRect(new RectF(colCenterRtl - colWidth / 2f,
                        rowCenter - rowHeight / 2f + mPaddingRangeIndicator, colCenterRtl + colWidth / 2f,
                        rowCenter + rowHeight / 2f - mPaddingRangeIndicator), mDayRangeSelectorPaint);
                break;
            }
        }

        final boolean isDayToday = mToday == day;
        final int dayTextColor;
        if (isDayToday) {
            if (mActivatedDays.isClick && isSelected) {
                final int[] stateSet = SUtils.resolveStateSet(stateMask);
                dayTextColor = mDayTextColor.getColorForState(stateSet, 0);
            } else {
                dayTextColor = mDaySelectorPaint.getColor();
            }
        } else {
            final int[] stateSet = SUtils.resolveStateSet(stateMask);
            if (!mActivatedDays.isSingleDay()) {
                if (stateMask == 1) {
                    dayTextColor = mContext.getResources().getColor(R.color.textDarkfour);
                } else {
                    dayTextColor = mDayTextColor.getColorForState(stateSet, 0);
                }
            } else {
                dayTextColor = mDayTextColor.getColorForState(stateSet, 0);
            }
        }
        p.setColor(dayTextColor);

        canvas.drawText(mDayFormatter.format(day), colCenterRtl, rowCenter - halfLineHeight, p);

        col++;

        if (col == DAYS_IN_WEEK) {
            col = 0;
            rowCenter += rowHeight;
        }
        if (mDaysInMonth == day)
            mOnRangeClickListener.onRangeSelected(calendars, position);
    }
}

From source file:com.wanikani.androidnotifier.graph.HistogramPlot.java

protected void drawBar(Canvas canvas, Samples bar, float left, float right) {
    long base, height;
    float top, tbl;
    Paint lpaint;//from   w  w w .j  a va2  s . c  o m
    Paint paint;
    Path path;
    RectF rect;

    top = vp.getY(vp.yMax);
    base = 0;
    for (Sample sample : bar.samples) {
        if (sample.value > 0) {
            height = sample.value;

            if (base > vp.yMax)
                ;
            else if (base + height > vp.yMax) {
                path = new Path();
                path.moveTo(left, vp.getY(base));
                path.lineTo(left, top);
                path.lineTo(left + (right - left) / 3, top - 10);
                path.lineTo(left + (right - left) * 2 / 3, top + 5);
                path.lineTo(right, top);
                path.lineTo(right, vp.getY(base));
                path.close();
                canvas.drawPath(path, pas.series.get(sample.series));
            } else {
                rect = new RectF(left, vp.getY(base + height), right, vp.getY(base));
                rect.intersect(meas.plotArea);
                paint = pas.series.get(sample.series);
                paint.setStyle(Style.FILL);
                canvas.drawRect(rect, paint);
                paint.setStyle(Style.STROKE);
                canvas.drawRect(rect, paint);
            }
            base += height;
        }
    }

    if (base <= vp.yMax) {
        lpaint = pas.levelupPaint;
        tbl = vp.getY(base) - meas.headroom / 2;
    } else {
        lpaint = pas.levelupPaintInside;
        tbl = vp.getY(vp.yMax) + meas.margin;
    }

    if (base > 0 && drawTotal)
        canvas.drawText(Long.toString(base), (left + right) / 2, tbl, lpaint);
}