Search in sources :

Example 16 with RectF

use of android.graphics.RectF in project CircleBar by songnick.

the class AccelerationProgress method drawAccBall.

private void drawAccBall(Canvas canvas) {
    //start position is in the (radius, 0)
    //so sweep angle must be started 270
    double sweepAngle = Math.PI / 180 * ratio + Math.PI / 180 * 270;
    float y = (float) Math.sin(sweepAngle) * (getBigCircleRadius());
    float x = (float) Math.cos(sweepAngle) * (getBigCircleRadius());
    int restoreCount = canvas.save();
    //change aix center position
    canvas.translate(rectF.centerX(), rectF.centerY());
    if (mNeedDrawTime) {
        if (mTimeTextSize > mAccBallRadius) {
            mAccBallRadius = mTimeTextSize;
        }
    }
    canvas.drawCircle(x, y, mAccBallRadius, mAccBallPaint);
    if (mNeedDrawTime) {
        RectF textRect = new RectF(x - mAccBallRadius, y - mAccBallRadius, x + mAccBallRadius, y + mAccBallRadius);
        Paint.FontMetrics fontMetrics = mTextPaint.getFontMetrics();
        float baseline = textRect.top + (textRect.bottom - textRect.top - fontMetrics.bottom + fontMetrics.top) / 2 - fontMetrics.top;
        String curTime = String.valueOf(animator.getDuration() / 1000 - animator.getCurrentPlayTime() / 1000);
        if (animator.getCurrentPlayTime() == 0 && !animator.isRunning()) {
            curTime = String.valueOf(0);
        }
        canvas.drawText(curTime, textRect.centerX(), baseline, mTextPaint);
    }
    canvas.restoreToCount(restoreCount);
}
Also used : RectF(android.graphics.RectF) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 17 with RectF

use of android.graphics.RectF in project CircleBar by songnick.

the class NotchProgress method onDraw.

@Override
protected void onDraw(Canvas canvas) {
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColor(Color.RED);
    paint.setStrokeWidth(5);
    paint.setStyle(Paint.Style.STROKE);
    canvas.drawArc(new RectF(20, 20, 120, 120), 120, 300, false, paint);
}
Also used : RectF(android.graphics.RectF) Paint(android.graphics.Paint)

Example 18 with RectF

use of android.graphics.RectF in project EazeGraph by blackfizz.

the class ValueLineChart method calculateLegendBounds.

private boolean calculateLegendBounds() {
    int index = 0;
    int size = mSeries.get(0).getSeries().size();
    // Only calculate if more than one point is available
    if (size > 1) {
        for (ValueLinePoint valueLinePoint : mSeries.get(0).getSeries()) {
            if (!(index == 0 || index == size - 1)) {
                valueLinePoint.setLegendBounds(new RectF(valueLinePoint.getCoordinates().getX() - mSeries.get(0).getWidthOffset() / 2, 0, valueLinePoint.getCoordinates().getX() + mSeries.get(0).getWidthOffset() / 2, mLegendHeight));
            } else {
                valueLinePoint.setIgnore(true);
            }
            index++;
        }
        return true;
    } else {
        return false;
    }
}
Also used : RectF(android.graphics.RectF) ValueLinePoint(org.eazegraph.lib.models.ValueLinePoint) ValueLinePoint(org.eazegraph.lib.models.ValueLinePoint) Paint(android.graphics.Paint)

Example 19 with RectF

use of android.graphics.RectF in project EazeGraph by blackfizz.

the class ValueLineChart method onLegendDraw.

@Override
protected void onLegendDraw(Canvas _Canvas) {
    super.onLegendDraw(_Canvas);
    mLegendPaint.setColor(mLegendColor);
    mLegendPaint.setStrokeWidth(DEF_LEGEND_STROKE);
    if (!mSeries.isEmpty()) {
        _Canvas.translate(Utils.getTranslationX(mDrawMatrixValues), 0);
        if (mUseCustomLegend) {
            for (LegendModel model : mLegendList) {
                RectF bounds = model.getLegendBounds();
                _Canvas.drawText(model.getLegendLabel(), model.getLegendLabelPosition(), bounds.bottom - mMaxFontHeight, mLegendPaint);
                _Canvas.drawLine(bounds.centerX(), bounds.bottom - mMaxFontHeight * 2 - mLegendTopPadding, bounds.centerX(), mLegendTopPadding, mLegendPaint);
            }
        } else {
            List<? extends BaseModel> list = mSeries.get(0).getSeries();
            for (BaseModel model : list) {
                if (model.canShowLabel()) {
                    RectF bounds = model.getLegendBounds();
                    _Canvas.drawText(model.getLegendLabel(), model.getLegendLabelPosition(), bounds.bottom - mMaxFontHeight, mLegendPaint);
                    _Canvas.drawLine(bounds.centerX(), bounds.bottom - mMaxFontHeight * 2 - mLegendTopPadding, bounds.centerX(), mLegendTopPadding, mLegendPaint);
                }
            }
        }
    }
}
Also used : RectF(android.graphics.RectF) BaseModel(org.eazegraph.lib.models.BaseModel) LegendModel(org.eazegraph.lib.models.LegendModel)

Example 20 with RectF

use of android.graphics.RectF in project EazeGraph by blackfizz.

the class Utils method calculateLegendInformation.

/**
     * Calculates the legend positions and which legend title should be displayed or not.
     *
     * Important: the LegendBounds in the _Models should be set and correctly calculated before this
     * function is called!
     * @param _Models The graph data which should have the BaseModel class as parent class.
     * @param _StartX Left starting point on the screen. Should be the absolute pixel value!
     * @param _Paint  The correctly set Paint which will be used for the text painting in the later process
     */
public static void calculateLegendInformation(List<? extends BaseModel> _Models, float _StartX, float _EndX, Paint _Paint) {
    float textMargin = Utils.dpToPx(10.f);
    float lastX = _StartX;
    // if not the label will not be shown
    for (BaseModel model : _Models) {
        if (!model.isIgnore()) {
            Rect textBounds = new Rect();
            RectF legendBounds = model.getLegendBounds();
            _Paint.getTextBounds(model.getLegendLabel(), 0, model.getLegendLabel().length(), textBounds);
            model.setTextBounds(textBounds);
            float centerX = legendBounds.centerX();
            float centeredTextPos = centerX - (textBounds.width() / 2);
            float textStartPos = centeredTextPos - textMargin;
            // check if the text is too big to fit on the screen
            if (centeredTextPos + textBounds.width() > _EndX - textMargin) {
                model.setShowLabel(false);
            } else {
                // If not the label will be shown and the label position is calculated
                if (textStartPos < lastX) {
                    if (lastX + textMargin < legendBounds.left) {
                        model.setLegendLabelPosition((int) (lastX + textMargin));
                        model.setShowLabel(true);
                        lastX = lastX + textMargin + textBounds.width();
                    } else {
                        model.setShowLabel(false);
                    }
                } else {
                    model.setShowLabel(true);
                    model.setLegendLabelPosition((int) centeredTextPos);
                    lastX = centerX + (textBounds.width() / 2);
                }
            }
        }
    }
}
Also used : RectF(android.graphics.RectF) Rect(android.graphics.Rect) BaseModel(org.eazegraph.lib.models.BaseModel)

Aggregations

RectF (android.graphics.RectF)1274 Paint (android.graphics.Paint)451 Rect (android.graphics.Rect)178 Matrix (android.graphics.Matrix)155 Bitmap (android.graphics.Bitmap)150 Path (android.graphics.Path)141 Canvas (android.graphics.Canvas)136 Point (android.graphics.Point)86 ImageView (android.widget.ImageView)78 PorterDuffXfermode (android.graphics.PorterDuffXfermode)51 LinearGradient (android.graphics.LinearGradient)41 View (android.view.View)39 SuppressLint (android.annotation.SuppressLint)35 Drawable (android.graphics.drawable.Drawable)27 PointF (android.graphics.PointF)23 RadialGradient (android.graphics.RadialGradient)21 TextPaint (android.text.TextPaint)21 ArrayList (java.util.ArrayList)21 BitmapDrawable (android.graphics.drawable.BitmapDrawable)20 TypedArray (android.content.res.TypedArray)14