Search in sources :

Example 76 with Path

use of android.graphics.Path in project material by rey5137.

the class Switch method buildShadow.

private void buildShadow() {
    if (mShadowSize <= 0)
        return;
    if (mShadowPaint == null) {
        mShadowPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
        mShadowPaint.setStyle(Paint.Style.FILL);
        mShadowPaint.setDither(true);
    }
    float startRatio = (float) mThumbRadius / (mThumbRadius + mShadowSize + mShadowOffset);
    mShadowPaint.setShader(new RadialGradient(0, 0, mThumbRadius + mShadowSize, new int[] { COLOR_SHADOW_START, COLOR_SHADOW_START, COLOR_SHADOW_END }, new float[] { 0f, startRatio, 1f }, Shader.TileMode.CLAMP));
    if (mShadowPath == null) {
        mShadowPath = new Path();
        mShadowPath.setFillType(Path.FillType.EVEN_ODD);
    } else
        mShadowPath.reset();
    float radius = mThumbRadius + mShadowSize;
    mTempRect.set(-radius, -radius, radius, radius);
    mShadowPath.addOval(mTempRect, Path.Direction.CW);
    radius = mThumbRadius - 1;
    mTempRect.set(-radius, -radius - mShadowOffset, radius, radius - mShadowOffset);
    mShadowPath.addOval(mTempRect, Path.Direction.CW);
}
Also used : Path(android.graphics.Path) RadialGradient(android.graphics.RadialGradient) Paint(android.graphics.Paint)

Example 77 with Path

use of android.graphics.Path in project android-tooltips by rharter.

the class ToolTipPointerView method onDraw.

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    Path p = new Path();
    if ((Gravity.VERTICAL_GRAVITY_MASK & mGravity) == Gravity.TOP) {
        // Top
        p.moveTo(0, 0);
        p.lineTo(getWidth() / 2, getHeight());
        p.lineTo(getWidth(), 0);
        p.lineTo(0, 0);
    } else if ((Gravity.VERTICAL_GRAVITY_MASK & mGravity) == Gravity.BOTTOM) {
        // Bottom
        p.moveTo(0, getHeight());
        p.lineTo(getWidth() / 2, 0);
        p.lineTo(getWidth(), getHeight());
        p.lineTo(0, getHeight());
    } else if ((Gravity.LEFT & mGravity) == Gravity.LEFT) {
        // Left
        p.moveTo(0, 0);
        p.lineTo(getWidth(), getHeight() / 2);
        p.lineTo(0, getHeight());
        p.lineTo(0, 0);
    } else if ((Gravity.RIGHT & mGravity) == Gravity.RIGHT) {
        // Right
        p.moveTo(getWidth(), 0);
        p.lineTo(0, getHeight() / 2);
        p.lineTo(getWidth(), getHeight());
        p.lineTo(getWidth(), 0);
    }
    canvas.drawPath(p, mPaint);
}
Also used : Path(android.graphics.Path)

Example 78 with Path

use of android.graphics.Path in project fitscales by paulburton.

the class ScaleView method renderBmi.

private void renderBmi(Canvas canvas, float bmi, Paint bmiPaint, Paint bmiPaintTriangle, String text, Paint textPaint) {
    if (bmi < minBmi || bmi > maxBmi)
        return;
    if (w > h) {
        /* horizontal */
        float x = Math.round(w * ((bmi - minBmi) / (maxBmi - minBmi)));
        canvas.drawLine(x, barOffset / 2, x, h, bmiPaint);
        if (bmiPaintTriangle != null) {
            float len = barOffset * 0.6f;
            Path p = new Path();
            p.moveTo(x - (len / 2), barOffset / 2);
            /* tl */
            p.lineTo(x + (len / 2), barOffset / 2);
            /* tr */
            p.lineTo(x, (barOffset / 2) + (float) ((len / 2) / Math.sin(Math.PI / 6)));
            /* b */
            p.close();
            canvas.drawPath(p, bmiPaintTriangle);
        }
        if (text != null && textPaint != null)
            canvas.drawText(text, x + (h / 10), barRect.centerY() - (h / 8), textPaint);
    } else {
        /* vertical */
        float y = Math.round(h * (1.0f - (bmi - minBmi) / (maxBmi - minBmi)));
        canvas.drawLine(barOffset / 2, y, w, y, bmiPaint);
        if (bmiPaintTriangle != null) {
            float len = barOffset * 0.6f;
            Path p = new Path();
            p.moveTo(barOffset / 2, y - (len / 2));
            /* bl */
            p.lineTo(barOffset / 2, y + (len / 2));
            /* tl */
            p.lineTo((barOffset / 2) + (float) ((len / 2) / Math.sin(Math.PI / 6)), y);
            /* r */
            p.close();
            canvas.drawPath(p, bmiPaintTriangle);
        }
        if (text != null && textPaint != null)
            canvas.drawText(text, barRect.centerX(), y - (w / 10), textPaint);
    }
}
Also used : Path(android.graphics.Path)

Example 79 with Path

use of android.graphics.Path in project kickmaterial by byoutline.

the class CircleTransition method createAnimator.

@Override
public Animator createAnimator(final ViewGroup sceneRoot, TransitionValues startValues, final TransitionValues endValues) {
    if (startValues == null || endValues == null) {
        return null;
    }
    Rect startBounds = (Rect) startValues.values.get(PROPERTY_BOUNDS);
    Rect endBounds = (Rect) endValues.values.get(PROPERTY_BOUNDS);
    boolean boundsEqual = startBounds == null || endBounds == null || startBounds.equals(endBounds);
    if (boundsEqual) {
        return null;
    }
    int[] sceneRootLoc = new int[2];
    sceneRoot.getLocationInWindow(sceneRootLoc);
    int[] startLoc = (int[]) startValues.values.get(PROPERTY_POSITION);
    final View startView = getStartView(sceneRoot, startValues, sceneRootLoc, startLoc);
    final View endView = endValues.view;
    endView.setAlpha(0f);
    Path circlePath = getMovePath(endValues, startView, sceneRootLoc, startLoc, endView);
    Animator circleAnimator = ObjectAnimator.ofFloat(startView, View.TRANSLATION_X, View.TRANSLATION_Y, circlePath);
    circleAnimator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            startView.setVisibility(View.INVISIBLE);
            endView.setAlpha(1f);
            sceneRoot.getOverlay().remove(startView);
        }
    });
    AnimatorSet moveSet = new AnimatorSet();
    float scaleRatio = ((float) endView.getWidth()) / startView.getWidth();
    ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(startView, View.SCALE_X, 1, scaleRatio);
    ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(startView, View.SCALE_Y, 1, scaleRatio);
    moveSet.playTogether(circleAnimator, scaleXAnimator, scaleYAnimator);
    return moveSet;
}
Also used : Path(android.graphics.Path) Rect(android.graphics.Rect) ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ObjectAnimator(android.animation.ObjectAnimator) AnimatorSet(android.animation.AnimatorSet) View(android.view.View)

Example 80 with Path

use of android.graphics.Path in project UltimateAndroid by cymcsg.

the class SearchDrawable method createSearchPath.

private void createSearchPath(float phase) {
    RectF oval = new RectF(0.0f, 0.0f, mRadius * 2.0f, mRadius * 2.0f);
    float cx = oval.centerX();
    float cy = oval.centerY();
    float rx = oval.width() / 2.0f;
    float ry = oval.height() / 2.0f;
    final float TAN_PI_OVER_8 = 0.414213562f;
    final float ROOT_2_OVER_2 = 0.707106781f;
    float sx = rx * TAN_PI_OVER_8;
    float sy = ry * TAN_PI_OVER_8;
    float mx = rx * ROOT_2_OVER_2;
    float my = ry * ROOT_2_OVER_2;
    float L = oval.left;
    float T = oval.top;
    float R = oval.right;
    float B = oval.bottom;
    mPath = new Path();
    mPath.moveTo(cx + mx, cy + my);
    mPath.quadTo(cx + sx, B, cx, B);
    mPath.quadTo(cx - sx, B, cx - mx, cy + my);
    mPath.quadTo(L, cy + sy, L, cy);
    mPath.quadTo(L, cy - sy, cx - mx, cy - my);
    mPath.quadTo(cx - sx, T, cx, T);
    mPath.quadTo(cx + sx, T, cx + mx, cy - my);
    mPath.quadTo(R, cy - sy, R, cy);
    mPath.quadTo(R, cy + sy, cx + mx, cy + my);
    mPath.lineTo(1.5f * R, 1.5f * B);
}
Also used : RectF(android.graphics.RectF) Path(android.graphics.Path)

Aggregations

Path (android.graphics.Path)631 Paint (android.graphics.Paint)237 RectF (android.graphics.RectF)142 Rect (android.graphics.Rect)40 Canvas (android.graphics.Canvas)39 Matrix (android.graphics.Matrix)36 TextPaint (android.text.TextPaint)27 Bitmap (android.graphics.Bitmap)26 ObjectAnimator (android.animation.ObjectAnimator)18 LinearGradient (android.graphics.LinearGradient)18 PointF (android.graphics.PointF)18 Point (android.graphics.Point)16 View (android.view.View)16 RadialGradient (android.graphics.RadialGradient)15 Animator (android.animation.Animator)13 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)12 PathMeasure (android.graphics.PathMeasure)11 PropertyValuesHolder (android.animation.PropertyValuesHolder)10 InflateException (android.view.InflateException)10 ViewGroup (android.view.ViewGroup)10