Search in sources :

Example 21 with RectF

use of android.graphics.RectF in project LoadingDrawable by dinuscxj.

the class WaterBottleLoadingRenderer method createWaterPath.

private Path createWaterPath(RectF waterRect, float progress) {
    Path path = new Path();
    path.moveTo(waterRect.left, waterRect.top);
    //Similar to the way draw the bottle's bottom sides
    float radius = (waterRect.width() - mStrokeWidth) / 2.0f;
    float centerY = waterRect.bottom - 0.86f * radius;
    float bottleBottomWidth = waterRect.width() / 2.0f;
    RectF bodyRect = new RectF(waterRect.left, centerY - radius, waterRect.right, centerY + radius);
    path.addArc(bodyRect, 187.5f, -67.5f);
    path.lineTo(waterRect.centerX() - bottleBottomWidth / 2.0f, waterRect.bottom);
    path.lineTo(waterRect.centerX() + bottleBottomWidth / 2.0f, waterRect.bottom);
    path.addArc(bodyRect, 60, -67.5f);
    //draw the water waves
    float cubicXChangeSize = waterRect.width() * 0.35f * progress;
    float cubicYChangeSize = waterRect.height() * 1.2f * progress;
    path.cubicTo(waterRect.left + waterRect.width() * 0.80f - cubicXChangeSize, waterRect.top - waterRect.height() * 1.2f + cubicYChangeSize, waterRect.left + waterRect.width() * 0.55f - cubicXChangeSize, waterRect.top - cubicYChangeSize, waterRect.left, waterRect.top - mStrokeWidth / 2.0f);
    path.lineTo(waterRect.left, waterRect.top);
    return path;
}
Also used : Path(android.graphics.Path) RectF(android.graphics.RectF)

Example 22 with RectF

use of android.graphics.RectF in project LoadingDrawable by dinuscxj.

the class WaterBottleLoadingRenderer method computeRender.

@Override
protected void computeRender(float renderProgress) {
    if (mCurrentBounds.width() <= 0) {
        return;
    }
    RectF arcBounds = mCurrentBounds;
    //compute gas tube bounds
    mBottleBounds.set(arcBounds.centerX() - mBottleWidth / 2.0f, arcBounds.centerY() - mBottleHeight / 2.0f, arcBounds.centerX() + mBottleWidth / 2.0f, arcBounds.centerY() + mBottleHeight / 2.0f);
    //compute pipe body bounds
    mWaterBounds.set(mBottleBounds.left + mStrokeWidth * 1.5f, mBottleBounds.top + mWaterLowestPointToBottleneckDistance, mBottleBounds.right - mStrokeWidth * 1.5f, mBottleBounds.bottom - mStrokeWidth * 1.5f);
    //compute wave progress
    float totalWaveProgress = renderProgress * mWaveCount;
    float currentWaveProgress = totalWaveProgress - ((int) totalWaveProgress);
    if (currentWaveProgress > 0.5f) {
        mProgress = 1.0f - MATERIAL_INTERPOLATOR.getInterpolation((currentWaveProgress - 0.5f) * 2.0f);
    } else {
        mProgress = MATERIAL_INTERPOLATOR.getInterpolation(currentWaveProgress * 2.0f);
    }
    //init water drop holders
    if (mWaterDropHolders.isEmpty()) {
        initWaterDropHolders(mBottleBounds, mWaterBounds);
    }
    //compute the location of these water drops
    for (WaterDropHolder waterDropHolder : mWaterDropHolders) {
        if (waterDropHolder.mDelayDuration < renderProgress && waterDropHolder.mDelayDuration + waterDropHolder.mDuration > renderProgress) {
            float riseProgress = (renderProgress - waterDropHolder.mDelayDuration) / waterDropHolder.mDuration;
            riseProgress = riseProgress < 0.5f ? riseProgress * 2.0f : 1.0f - (riseProgress - 0.5f) * 2.0f;
            waterDropHolder.mCurrentY = waterDropHolder.mInitY - MATERIAL_INTERPOLATOR.getInterpolation(riseProgress) * waterDropHolder.mRiseHeight;
            waterDropHolder.mNeedDraw = true;
        } else {
            waterDropHolder.mNeedDraw = false;
        }
    }
    //measure loading text
    mPaint.setTextSize(mTextSize);
    mPaint.getTextBounds(LOADING_TEXT, 0, LOADING_TEXT.length(), mLoadingBounds);
}
Also used : RectF(android.graphics.RectF)

Example 23 with RectF

use of android.graphics.RectF in project LoadingDrawable by dinuscxj.

the class WaterBottleLoadingRenderer method draw.

@Override
protected void draw(Canvas canvas, Rect bounds) {
    int saveCount = canvas.save();
    RectF arcBounds = mCurrentBounds;
    arcBounds.set(bounds);
    //draw bottle
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setColor(mBottleColor);
    canvas.drawPath(createBottlePath(mBottleBounds), mPaint);
    //draw water
    mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
    mPaint.setColor(mWaterColor);
    canvas.drawPath(createWaterPath(mWaterBounds, mProgress), mPaint);
    //draw water drop
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setColor(mWaterColor);
    for (WaterDropHolder waterDropHolder : mWaterDropHolders) {
        if (waterDropHolder.mNeedDraw) {
            canvas.drawCircle(waterDropHolder.mInitX, waterDropHolder.mCurrentY, waterDropHolder.mRadius, mPaint);
        }
    }
    //draw loading text
    mPaint.setColor(mBottleColor);
    canvas.drawText(LOADING_TEXT, mBottleBounds.centerX() - mLoadingBounds.width() / 2.0f, mBottleBounds.bottom + mBottleBounds.height() * 0.2f, mPaint);
    canvas.restoreToCount(saveCount);
}
Also used : RectF(android.graphics.RectF) Paint(android.graphics.Paint)

Example 24 with RectF

use of android.graphics.RectF in project LoadingDrawable by dinuscxj.

the class FishLoadingRenderer method createRiverPath.

private Path createRiverPath(RectF arcBounds) {
    if (mRiverPath != null) {
        return mRiverPath;
    }
    mRiverPath = new Path();
    RectF rectF = new RectF(arcBounds.centerX() - mRiverWidth / 2.0f, arcBounds.centerY() - mRiverHeight / 2.0f, arcBounds.centerX() + mRiverWidth / 2.0f, arcBounds.centerY() + mRiverHeight / 2.0f);
    rectF.inset(mRiverBankWidth / 2.0f, mRiverBankWidth / 2.0f);
    mRiverPath.addRect(rectF, Path.Direction.CW);
    return mRiverPath;
}
Also used : Path(android.graphics.Path) RectF(android.graphics.RectF)

Example 25 with RectF

use of android.graphics.RectF in project LoadingDrawable by dinuscxj.

the class GhostsEyeLoadingRenderer method createRightEyeCircle.

private Path createRightEyeCircle(RectF arcBounds, float offsetY) {
    Path path = new Path();
    //the center of the right eye
    float rightEyeCenterX = arcBounds.centerX() + mEyeInterval / 2.0f + mEyeCircleRadius;
    float rightEyeCenterY = arcBounds.centerY() + offsetY;
    //the bounds of left eye
    RectF leftEyeBounds = new RectF(rightEyeCenterX - mEyeCircleRadius, rightEyeCenterY - mEyeCircleRadius, rightEyeCenterX + mEyeCircleRadius, rightEyeCenterY + mEyeCircleRadius);
    path.addArc(leftEyeBounds, 180, -(DEGREE_180 + 15));
    //the above radian of of the eye
    path.quadTo(leftEyeBounds.right - mAboveRadianEyeOffsetX, leftEyeBounds.top + mEyeCircleRadius * 0.2f, leftEyeBounds.right - mAboveRadianEyeOffsetX / 4.0f, leftEyeBounds.top - mEyeCircleRadius * 0.15f);
    return path;
}
Also used : Path(android.graphics.Path) RectF(android.graphics.RectF)

Aggregations

RectF (android.graphics.RectF)1216 Paint (android.graphics.Paint)437 Rect (android.graphics.Rect)176 Matrix (android.graphics.Matrix)150 Bitmap (android.graphics.Bitmap)148 Path (android.graphics.Path)140 Canvas (android.graphics.Canvas)134 Point (android.graphics.Point)78 ImageView (android.widget.ImageView)74 PorterDuffXfermode (android.graphics.PorterDuffXfermode)49 View (android.view.View)39 LinearGradient (android.graphics.LinearGradient)38 SuppressLint (android.annotation.SuppressLint)32 Drawable (android.graphics.drawable.Drawable)26 PointF (android.graphics.PointF)21 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