Search in sources :

Example 76 with RectF

use of android.graphics.RectF in project Hummingbird-for-Android by xiprox.

the class PhotoViewAttacher method setImageViewMatrix.

private void setImageViewMatrix(Matrix matrix) {
    ImageView imageView = getImageView();
    if (null != imageView) {
        checkImageViewScaleType();
        imageView.setImageMatrix(matrix);
        // Call MatrixChangedListener if needed
        if (null != mMatrixChangeListener) {
            RectF displayRect = getDisplayRect(matrix);
            if (null != displayRect) {
                mMatrixChangeListener.onMatrixChanged(displayRect);
            }
        }
    }
}
Also used : RectF(android.graphics.RectF) ImageView(android.widget.ImageView)

Example 77 with RectF

use of android.graphics.RectF in project Hummingbird-for-Android by xiprox.

the class PhotoViewAttacher method updateBaseMatrix.

/**
     * Calculate Matrix for FIT_CENTER
     *
     * @param d - Drawable being displayed
     */
private void updateBaseMatrix(Drawable d) {
    ImageView imageView = getImageView();
    if (null == imageView || null == d) {
        return;
    }
    final float viewWidth = getImageViewWidth(imageView);
    final float viewHeight = getImageViewHeight(imageView);
    final int drawableWidth = d.getIntrinsicWidth();
    final int drawableHeight = d.getIntrinsicHeight();
    mBaseMatrix.reset();
    final float widthScale = viewWidth / drawableWidth;
    final float heightScale = viewHeight / drawableHeight;
    if (mScaleType == ScaleType.CENTER) {
        mBaseMatrix.postTranslate((viewWidth - drawableWidth) / 2F, (viewHeight - drawableHeight) / 2F);
    } else if (mScaleType == ScaleType.CENTER_CROP) {
        float scale = Math.max(widthScale, heightScale);
        mBaseMatrix.postScale(scale, scale);
        mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F, (viewHeight - drawableHeight * scale) / 2F);
    } else if (mScaleType == ScaleType.CENTER_INSIDE) {
        float scale = Math.min(1.0f, Math.min(widthScale, heightScale));
        mBaseMatrix.postScale(scale, scale);
        mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F, (viewHeight - drawableHeight * scale) / 2F);
    } else {
        RectF mTempSrc = new RectF(0, 0, drawableWidth, drawableHeight);
        RectF mTempDst = new RectF(0, 0, viewWidth, viewHeight);
        switch(mScaleType) {
            case FIT_CENTER:
                mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.CENTER);
                break;
            case FIT_START:
                mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.START);
                break;
            case FIT_END:
                mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.END);
                break;
            case FIT_XY:
                mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.FILL);
                break;
            default:
                break;
        }
    }
    resetMatrix();
}
Also used : RectF(android.graphics.RectF) ImageView(android.widget.ImageView)

Example 78 with RectF

use of android.graphics.RectF in project XobotOS by xamarin.

the class GradientDrawable method buildRing.

private Path buildRing(GradientState st) {
    if (mRingPath != null && (!st.mUseLevelForShape || !mPathIsDirty))
        return mRingPath;
    mPathIsDirty = false;
    float sweep = st.mUseLevelForShape ? (360.0f * getLevel() / 10000.0f) : 360f;
    RectF bounds = new RectF(mRect);
    float x = bounds.width() / 2.0f;
    float y = bounds.height() / 2.0f;
    float thickness = st.mThickness != -1 ? st.mThickness : bounds.width() / st.mThicknessRatio;
    // inner radius
    float radius = st.mInnerRadius != -1 ? st.mInnerRadius : bounds.width() / st.mInnerRadiusRatio;
    RectF innerBounds = new RectF(bounds);
    innerBounds.inset(x - radius, y - radius);
    bounds = new RectF(innerBounds);
    bounds.inset(-thickness, -thickness);
    if (mRingPath == null) {
        mRingPath = new Path();
    } else {
        mRingPath.reset();
    }
    final Path ringPath = mRingPath;
    // think 360 means draw the entire oval
    if (sweep < 360 && sweep > -360) {
        ringPath.setFillType(Path.FillType.EVEN_ODD);
        // inner top
        ringPath.moveTo(x + radius, y);
        // outer top
        ringPath.lineTo(x + radius + thickness, y);
        // outer arc
        ringPath.arcTo(bounds, 0.0f, sweep, false);
        // inner arc
        ringPath.arcTo(innerBounds, sweep, -sweep, false);
        ringPath.close();
    } else {
        // add the entire ovals
        ringPath.addOval(bounds, Path.Direction.CW);
        ringPath.addOval(innerBounds, Path.Direction.CCW);
    }
    return ringPath;
}
Also used : RectF(android.graphics.RectF) Path(android.graphics.Path)

Example 79 with RectF

use of android.graphics.RectF in project XobotOS by xamarin.

the class GradientDrawable method draw.

@Override
public void draw(Canvas canvas) {
    if (!ensureValidRect()) {
        // nothing to draw
        return;
    }
    // remember the alpha values, in case we temporarily overwrite them
    // when we modulate them with mAlpha
    final int prevFillAlpha = mFillPaint.getAlpha();
    final int prevStrokeAlpha = mStrokePaint != null ? mStrokePaint.getAlpha() : 0;
    // compute the modulate alpha values
    final int currFillAlpha = modulateAlpha(prevFillAlpha);
    final int currStrokeAlpha = modulateAlpha(prevStrokeAlpha);
    final boolean haveStroke = currStrokeAlpha > 0 && mStrokePaint.getStrokeWidth() > 0;
    final boolean haveFill = currFillAlpha > 0;
    final GradientState st = mGradientState;
    /*  we need a layer iff we're drawing both a fill and stroke, and the
            stroke is non-opaque, and our shapetype actually supports
            fill+stroke. Otherwise we can just draw the stroke (if any) on top
            of the fill (if any) without worrying about blending artifacts.
         */
    final boolean useLayer = haveStroke && haveFill && st.mShape != LINE && currStrokeAlpha < 255 && (mAlpha < 255 || mColorFilter != null);
    /*  Drawing with a layer is slower than direct drawing, but it
            allows us to apply paint effects like alpha and colorfilter to
            the result of multiple separate draws. In our case, if the user
            asks for a non-opaque alpha value (via setAlpha), and we're
            stroking, then we need to apply the alpha AFTER we've drawn
            both the fill and the stroke.
        */
    if (useLayer) {
        if (mLayerPaint == null) {
            mLayerPaint = new Paint();
        }
        mLayerPaint.setDither(mDither);
        mLayerPaint.setAlpha(mAlpha);
        mLayerPaint.setColorFilter(mColorFilter);
        float rad = mStrokePaint.getStrokeWidth();
        canvas.saveLayer(mRect.left - rad, mRect.top - rad, mRect.right + rad, mRect.bottom + rad, mLayerPaint, Canvas.HAS_ALPHA_LAYER_SAVE_FLAG);
        // don't perform the filter in our individual paints
        // since the layer will do it for us
        mFillPaint.setColorFilter(null);
        mStrokePaint.setColorFilter(null);
    } else {
        /*  if we're not using a layer, apply the dither/filter to our
                individual paints
            */
        mFillPaint.setAlpha(currFillAlpha);
        mFillPaint.setDither(mDither);
        mFillPaint.setColorFilter(mColorFilter);
        if (haveStroke) {
            mStrokePaint.setAlpha(currStrokeAlpha);
            mStrokePaint.setDither(mDither);
            mStrokePaint.setColorFilter(mColorFilter);
        }
    }
    switch(st.mShape) {
        case RECTANGLE:
            if (st.mRadiusArray != null) {
                if (mPathIsDirty || mRectIsDirty) {
                    mPath.reset();
                    mPath.addRoundRect(mRect, st.mRadiusArray, Path.Direction.CW);
                    mPathIsDirty = mRectIsDirty = false;
                }
                canvas.drawPath(mPath, mFillPaint);
                if (haveStroke) {
                    canvas.drawPath(mPath, mStrokePaint);
                }
            } else if (st.mRadius > 0.0f) {
                // since the caller is only giving us 1 value, we will force
                // it to be square if the rect is too small in one dimension
                // to show it. If we did nothing, Skia would clamp the rad
                // independently along each axis, giving us a thin ellipse
                // if the rect were very wide but not very tall
                float rad = st.mRadius;
                float r = Math.min(mRect.width(), mRect.height()) * 0.5f;
                if (rad > r) {
                    rad = r;
                }
                canvas.drawRoundRect(mRect, rad, rad, mFillPaint);
                if (haveStroke) {
                    canvas.drawRoundRect(mRect, rad, rad, mStrokePaint);
                }
            } else {
                canvas.drawRect(mRect, mFillPaint);
                if (haveStroke) {
                    canvas.drawRect(mRect, mStrokePaint);
                }
            }
            break;
        case OVAL:
            canvas.drawOval(mRect, mFillPaint);
            if (haveStroke) {
                canvas.drawOval(mRect, mStrokePaint);
            }
            break;
        case LINE:
            {
                RectF r = mRect;
                float y = r.centerY();
                canvas.drawLine(r.left, y, r.right, y, mStrokePaint);
                break;
            }
        case RING:
            Path path = buildRing(st);
            canvas.drawPath(path, mFillPaint);
            if (haveStroke) {
                canvas.drawPath(path, mStrokePaint);
            }
            break;
    }
    if (useLayer) {
        canvas.restore();
    } else {
        mFillPaint.setAlpha(prevFillAlpha);
        if (haveStroke) {
            mStrokePaint.setAlpha(prevStrokeAlpha);
        }
    }
}
Also used : RectF(android.graphics.RectF) Path(android.graphics.Path) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 80 with RectF

use of android.graphics.RectF in project XobotOS by xamarin.

the class RectShape method clone.

@Override
public RectShape clone() throws CloneNotSupportedException {
    final RectShape shape = (RectShape) super.clone();
    shape.mRect = new RectF(mRect);
    return shape;
}
Also used : RectF(android.graphics.RectF)

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