Search in sources :

Example 41 with Path

use of android.graphics.Path in project android_frameworks_base by ResurrectionRemix.

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 42 with Path

use of android.graphics.Path in project android_frameworks_base by ResurrectionRemix.

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 != null && mStrokePaint.getStrokeWidth() > 0;
    final boolean haveFill = currFillAlpha > 0;
    final GradientState st = mGradientState;
    final ColorFilter colorFilter = mColorFilter != null ? mColorFilter : mTintFilter;
    /*  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 || colorFilter != 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(st.mDither);
        mLayerPaint.setAlpha(mAlpha);
        mLayerPaint.setColorFilter(colorFilter);
        float rad = mStrokePaint.getStrokeWidth();
        canvas.saveLayer(mRect.left - rad, mRect.top - rad, mRect.right + rad, mRect.bottom + rad, mLayerPaint);
        // 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(st.mDither);
        mFillPaint.setColorFilter(colorFilter);
        if (colorFilter != null && st.mSolidColors == null) {
            mFillPaint.setColor(mAlpha << 24);
        }
        if (haveStroke) {
            mStrokePaint.setAlpha(currStrokeAlpha);
            mStrokePaint.setDither(st.mDither);
            mStrokePaint.setColorFilter(colorFilter);
        }
    }
    switch(st.mShape) {
        case RECTANGLE:
            if (st.mRadiusArray != null) {
                buildPathIfDirty();
                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 = Math.min(st.mRadius, Math.min(mRect.width(), mRect.height()) * 0.5f);
                canvas.drawRoundRect(mRect, rad, rad, mFillPaint);
                if (haveStroke) {
                    canvas.drawRoundRect(mRect, rad, rad, mStrokePaint);
                }
            } else {
                if (mFillPaint.getColor() != 0 || colorFilter != null || mFillPaint.getShader() != null) {
                    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();
                if (haveStroke) {
                    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) ColorFilter(android.graphics.ColorFilter) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 43 with Path

use of android.graphics.Path in project android_frameworks_base by ResurrectionRemix.

the class TaskStackLayoutAlgorithm method constructUnfocusedDimCurve.

/**
     * Creates a new path for the unfocused dim curve.
     */
private Path constructUnfocusedDimCurve() {
    float focusX = getNormalizedXFromUnfocusedY(mInitialTopOffset, FROM_TOP);
    float cpoint2X = focusX + (1f - focusX) / 2;
    Path p = new Path();
    // The unfocused dim interpolator starts at max dim, reduces to zero at 0.5 (the focused
    // task), then goes back to max dim towards the front of the stack
    p.moveTo(0f, MAX_DIM);
    p.cubicTo(focusX * 0.5f, MAX_DIM, focusX * 0.75f, MAX_DIM * 0.75f, focusX, 0f);
    p.cubicTo(cpoint2X, 0f, cpoint2X, MED_DIM, 1f, MED_DIM);
    return p;
}
Also used : Path(android.graphics.Path)

Example 44 with Path

use of android.graphics.Path in project android_frameworks_base by ResurrectionRemix.

the class FakeShadowDrawable method buildShadowCorners.

private void buildShadowCorners() {
    RectF innerBounds = new RectF(-mCornerRadius, -mCornerRadius, mCornerRadius, mCornerRadius);
    RectF outerBounds = new RectF(innerBounds);
    outerBounds.inset(-mShadowSize, -mShadowSize);
    if (mCornerShadowPath == null) {
        mCornerShadowPath = new Path();
    } else {
        mCornerShadowPath.reset();
    }
    mCornerShadowPath.setFillType(Path.FillType.EVEN_ODD);
    mCornerShadowPath.moveTo(-mCornerRadius, 0);
    mCornerShadowPath.rLineTo(-mShadowSize, 0);
    // outer arc
    mCornerShadowPath.arcTo(outerBounds, 180f, 90f, false);
    // inner arc
    mCornerShadowPath.arcTo(innerBounds, 270f, -90f, false);
    mCornerShadowPath.close();
    float startRatio = mCornerRadius / (mCornerRadius + mShadowSize);
    mCornerShadowPaint.setShader(new RadialGradient(0, 0, mCornerRadius + mShadowSize, new int[] { mShadowStartColor, mShadowStartColor, mShadowEndColor }, new float[] { 0f, startRatio, 1f }, Shader.TileMode.CLAMP));
    // we offset the content shadowSize/2 pixels up to make it more realistic.
    // this is why edge shadow shader has some extra space
    // When drawing bottom edge shadow, we use that extra space.
    mEdgeShadowPaint.setShader(new LinearGradient(0, -mCornerRadius + mShadowSize, 0, -mCornerRadius - mShadowSize, new int[] { mShadowStartColor, mShadowStartColor, mShadowEndColor }, new float[] { 0f, .5f, 1f }, Shader.TileMode.CLAMP));
}
Also used : RectF(android.graphics.RectF) Path(android.graphics.Path) LinearGradient(android.graphics.LinearGradient) RadialGradient(android.graphics.RadialGradient)

Example 45 with Path

use of android.graphics.Path in project android_frameworks_base by ResurrectionRemix.

the class TaskStackLayoutAlgorithm method constructFocusedDimCurve.

/**
     * Creates a new path for the focused dim curve.
     */
private Path constructFocusedDimCurve() {
    Path p = new Path();
    // The focused dim interpolator starts at max dim, reduces to zero at 0.5 (the focused
    // task), then goes back to max dim at the next task
    p.moveTo(0f, MAX_DIM);
    p.lineTo(0.5f, 0f);
    p.lineTo(0.5f + (0.5f / mFocusedRange.relativeMax), MAX_DIM);
    p.lineTo(1f, MAX_DIM);
    return p;
}
Also used : Path(android.graphics.Path)

Aggregations

Path (android.graphics.Path)1012 Paint (android.graphics.Paint)462 RectF (android.graphics.RectF)289 Matrix (android.graphics.Matrix)74 Rect (android.graphics.Rect)59 Canvas (android.graphics.Canvas)53 TextPaint (android.text.TextPaint)37 Bitmap (android.graphics.Bitmap)36 PointF (android.graphics.PointF)29 Point (android.graphics.Point)28 LinearGradient (android.graphics.LinearGradient)24 View (android.view.View)24 ObjectAnimator (android.animation.ObjectAnimator)23 Stack (java.util.Stack)22 Animator (android.animation.Animator)18 PathMeasure (android.graphics.PathMeasure)18 RadialGradient (android.graphics.RadialGradient)17 Test (org.junit.Test)15 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)14 DashPathEffect (android.graphics.DashPathEffect)14