Example usage for android.graphics Path Path

List of usage examples for android.graphics Path Path

Introduction

In this page you can find the example usage for android.graphics Path Path.

Prototype

public Path() 

Source Link

Document

Create an empty path

Usage

From source file:me.lizheng.deckview.helpers.FakeShadowDrawable.java

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 {//from ww  w  . j  a  v a  2  s .  c  o  m
        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));
}

From source file:android.support.transition.ArcMotion.java

@Override
public Path getPath(float startX, float startY, float endX, float endY) {
    // Here's a little ascii art to show how this is calculated:
    // c---------- b
    //  \        / |
    //    \     d  |
    //      \  /   e
    //        a----f
    // This diagram assumes that the horizontal distance is less than the vertical
    // distance between The start point (a) and end point (b).
    // d is the midpoint between a and b. c is the center point of the circle with
    // This path is formed by assuming that start and end points are in
    // an arc on a circle. The end point is centered in the circle vertically
    // and start is a point on the circle.

    // Triangles bfa and bde form similar right triangles. The control points
    // for the cubic Bezier arc path are the midpoints between a and e and e and b.

    Path path = new Path();
    path.moveTo(startX, startY);/*from   w  ww.  j  a v  a  2 s  . c o  m*/

    float ex;
    float ey;
    float deltaX = endX - startX;
    float deltaY = endY - startY;

    // hypotenuse squared.
    float h2 = deltaX * deltaX + deltaY * deltaY;

    // Midpoint between start and end
    float dx = (startX + endX) / 2;
    float dy = (startY + endY) / 2;

    // Distance squared between end point and mid point is (1/2 hypotenuse)^2
    float midDist2 = h2 * 0.25f;

    float minimumArcDist2;

    boolean isMovingUpwards = startY > endY;

    if ((Math.abs(deltaX) < Math.abs(deltaY))) {
        // Similar triangles bfa and bde mean that (ab/fb = eb/bd)
        // Therefore, eb = ab * bd / fb
        // ab = hypotenuse
        // bd = hypotenuse/2
        // fb = deltaY
        float eDistY = Math.abs(h2 / (2 * deltaY));
        if (isMovingUpwards) {
            ey = endY + eDistY;
            ex = endX;
        } else {
            ey = startY + eDistY;
            ex = startX;
        }

        minimumArcDist2 = midDist2 * mMinimumVerticalTangent * mMinimumVerticalTangent;
    } else {
        // Same as above, but flip X & Y and account for negative eDist
        float eDistX = h2 / (2 * deltaX);
        if (isMovingUpwards) {
            ex = startX + eDistX;
            ey = startY;
        } else {
            ex = endX - eDistX;
            ey = endY;
        }

        minimumArcDist2 = midDist2 * mMinimumHorizontalTangent * mMinimumHorizontalTangent;
    }
    float arcDistX = dx - ex;
    float arcDistY = dy - ey;
    float arcDist2 = arcDistX * arcDistX + arcDistY * arcDistY;

    float maximumArcDist2 = midDist2 * mMaximumTangent * mMaximumTangent;

    float newArcDistance2 = 0;
    if (arcDist2 < minimumArcDist2) {
        newArcDistance2 = minimumArcDist2;
    } else if (arcDist2 > maximumArcDist2) {
        newArcDistance2 = maximumArcDist2;
    }
    if (newArcDistance2 != 0) {
        float ratio2 = newArcDistance2 / arcDist2;
        float ratio = (float) Math.sqrt(ratio2);
        ex = dx + (ratio * (ex - dx));
        ey = dy + (ratio * (ey - dy));
    }
    float control1X = (startX + ex) / 2;
    float control1Y = (startY + ey) / 2;
    float control2X = (ex + endX) / 2;
    float control2Y = (ey + endY) / 2;
    path.cubicTo(control1X, control1Y, control2X, control2Y, endX, endY);
    return path;
}

From source file:com.fanfou.app.opensource.ui.viewpager.TitlePageIndicator.java

public TitlePageIndicator(final Context context, final AttributeSet attrs, final int defStyle) {
    super(context, attrs, defStyle);

    // Load defaults from resources
    final Resources res = getResources();
    final int defaultFooterColor = res.getColor(R.color.default_title_indicator_footer_color);
    final float defaultFooterLineHeight = res.getDimension(R.dimen.default_title_indicator_footer_line_height);
    final int defaultFooterIndicatorStyle = res
            .getInteger(R.integer.default_title_indicator_footer_indicator_style);
    final float defaultFooterIndicatorHeight = res
            .getDimension(R.dimen.default_title_indicator_footer_indicator_height);
    final float defaultFooterIndicatorUnderlinePadding = res
            .getDimension(R.dimen.default_title_indicator_footer_indicator_underline_padding);
    final float defaultFooterPadding = res.getDimension(R.dimen.default_title_indicator_footer_padding);
    final int defaultSelectedColor = res.getColor(R.color.default_title_indicator_selected_color);
    final boolean defaultSelectedBold = res.getBoolean(R.bool.default_title_indicator_selected_bold);
    final int defaultTextColor = res.getColor(R.color.default_title_indicator_text_color);
    final float defaultTextSize = res.getDimension(R.dimen.default_title_indicator_text_size);
    final float defaultTitlePadding = res.getDimension(R.dimen.default_title_indicator_title_padding);
    final float defaultClipPadding = res.getDimension(R.dimen.default_title_indicator_clip_padding);

    // Retrieve styles attributes
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TitlePageIndicator, defStyle,
            R.style.Widget_TitlePageIndicator);

    // Retrieve the colors to be used for this view and apply them.
    this.mFooterLineHeight = a.getDimension(R.styleable.TitlePageIndicator_footerLineHeight,
            defaultFooterLineHeight);//from   w w  w. j a v  a  2 s  .  c o  m
    this.mFooterIndicatorStyle = IndicatorStyle.fromValue(
            a.getInteger(R.styleable.TitlePageIndicator_footerIndicatorStyle, defaultFooterIndicatorStyle));
    this.mFooterIndicatorHeight = a.getDimension(R.styleable.TitlePageIndicator_footerIndicatorHeight,
            defaultFooterIndicatorHeight);
    this.mFooterIndicatorUnderlinePadding = a.getDimension(
            R.styleable.TitlePageIndicator_footerIndicatorUnderlinePadding,
            defaultFooterIndicatorUnderlinePadding);
    this.mFooterPadding = a.getDimension(R.styleable.TitlePageIndicator_footerPadding, defaultFooterPadding);
    this.mTitlePadding = a.getDimension(R.styleable.TitlePageIndicator_titlePadding, defaultTitlePadding);
    this.mClipPadding = a.getDimension(R.styleable.TitlePageIndicator_clipPadding, defaultClipPadding);
    this.mColorSelected = a.getColor(R.styleable.TitlePageIndicator_selectedColor, defaultSelectedColor);
    this.mColorText = a.getColor(R.styleable.TitlePageIndicator_textColor, defaultTextColor);
    this.mBoldText = a.getBoolean(R.styleable.TitlePageIndicator_selectedBold, defaultSelectedBold);

    final float textSize = a.getDimension(R.styleable.TitlePageIndicator_textSize, defaultTextSize);
    final int footerColor = a.getColor(R.styleable.TitlePageIndicator_footerColor, defaultFooterColor);
    this.mPaintText = new Paint();
    this.mPaintText.setTextSize(textSize);
    this.mPaintText.setAntiAlias(true);
    this.mPaintFooterLine = new Paint();
    this.mPaintFooterLine.setStyle(Paint.Style.FILL_AND_STROKE);
    this.mPaintFooterLine.setStrokeWidth(this.mFooterLineHeight);
    this.mPaintFooterLine.setColor(footerColor);
    this.mPaintFooterIndicator = new Paint();
    this.mPaintFooterIndicator.setStyle(Paint.Style.FILL_AND_STROKE);
    this.mPaintFooterIndicator.setColor(footerColor);

    a.recycle();

    this.mPath = new Path();
}

From source file:com.github.jorgecastillo.FillableLoader.java

private void buildPathData() {
    SvgPathParser parser = getPathParser();
    pathData = new PathData();
    try {//from  w ww  .  j a v a 2  s.c o  m
        pathData.path = parser.parsePath(svgPath);
    } catch (ParseException e) {
        pathData.path = new Path();
    }

    PathMeasure pm = new PathMeasure(pathData.path, true);
    while (true) {
        pathData.length = Math.max(pathData.length, pm.getLength());
        if (!pm.nextContour()) {
            break;
        }
    }
}

From source file:com.umeng.comm.ui.imagepicker.widgets.ViewPagerIndicator.java

/**
 * ?/* w w  w .  j  a va  2  s .  co  m*/
 */
private void initTriangle() {
    mPath = new Path();

    mTriangleHeight = (int) (mTriangleWidth * Math.sqrt(3) / 4); // 
    mPath.moveTo(0, 0);
    mPath.lineTo(mTriangleWidth, 0);
    mPath.lineTo(mTriangleWidth / 2, -mTriangleHeight);
    mPath.close();

}

From source file:com.google.android.apps.forscience.whistlepunk.RunReviewOverlay.java

private void init() {
    Resources res = getResources();

    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setStyle(Paint.Style.FILL);

    mDotPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mDotPaint.setStyle(Paint.Style.FILL);

    mDotBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mDotBackgroundPaint.setColor(res.getColor(R.color.chart_margins_color));
    mDotBackgroundPaint.setStyle(Paint.Style.FILL);

    Typeface valueTypeface = Typeface.create("sans-serif-medium", Typeface.NORMAL);
    Typeface timeTimeface = Typeface.create("sans-serif", Typeface.NORMAL);

    mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setTypeface(valueTypeface);
    mTextPaint.setTextSize(res.getDimension(R.dimen.run_review_overlay_label_text_size));
    mTextPaint.setColor(res.getColor(R.color.text_color_white));

    mTimePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTimePaint.setTypeface(timeTimeface);
    mTimePaint.setTextSize(res.getDimension(R.dimen.run_review_overlay_label_text_size));
    mTimePaint.setColor(res.getColor(R.color.text_color_white));

    mCenterLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mCenterLinePaint.setStrokeWidth(res.getDimensionPixelSize(R.dimen.chart_grid_line_width));
    mCenterLinePaint.setStyle(Paint.Style.STROKE);
    mCenterLinePaint.setColor(res.getColor(R.color.text_color_white));

    mLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mLinePaint.setStrokeWidth(res.getDimensionPixelSize(R.dimen.recording_overlay_bar_width));
    int dashSize = res.getDimensionPixelSize(R.dimen.run_review_overlay_dash_size);
    mLinePaint.setPathEffect(new DashPathEffect(new float[] { dashSize, dashSize }, dashSize));
    mLinePaint.setColor(res.getColor(R.color.note_overlay_line_color));
    mLinePaint.setStyle(Paint.Style.STROKE);

    mPath = new Path();

    // TODO: Need to make sure this is at least as detailed as the SensorAppearance number
    // format!//ww  w . ja  va2  s  . com
    mTextFormat = res.getString(R.string.run_review_chart_label_format);
    mTimeFormat = ElapsedTimeAxisFormatter.getInstance(getContext());

    mCropBackgroundPaint = new Paint();
    mCropBackgroundPaint.setStyle(Paint.Style.FILL);
    mCropBackgroundPaint.setColor(res.getColor(R.color.text_color_black));
    mCropBackgroundPaint.setAlpha(40);

    mCropVerticalLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mCropVerticalLinePaint.setStyle(Paint.Style.STROKE);
    mCropVerticalLinePaint.setStrokeWidth(res.getDimensionPixelSize(R.dimen.chart_grid_line_width));
}

From source file:android.support.design.widget.ShadowDrawableWrapper.java

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 {//w w  w .j ava  2 s  . c  o  m
        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 shadowRadius = -outerBounds.top;
    if (shadowRadius > 0f) {
        float startRatio = mCornerRadius / shadowRadius;
        float midRatio = startRatio + ((1f - startRatio) / 2f);
        mCornerShadowPaint.setShader(new RadialGradient(0, 0, shadowRadius,
                new int[] { 0, mShadowStartColor, mShadowMiddleColor, mShadowEndColor },
                new float[] { 0f, startRatio, midRatio, 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, innerBounds.top, 0, outerBounds.top,
            new int[] { mShadowStartColor, mShadowMiddleColor, mShadowEndColor }, new float[] { 0f, .5f, 1f },
            Shader.TileMode.CLAMP));
    mEdgeShadowPaint.setAntiAlias(false);
}

From source file:com.morninz.ninepinview.widget.NinePINView.java

/**
 * Compute the coordinates of 9 center points and wrong triangles.
 *///from   ww  w  .  j  a va2 s  .  c o m
protected void computePointsAndWrongTriangleCoordinate() {
    int drawWidth = getWidth() - getPaddingLeft() - getPaddingRight();
    int drawHeight = getHeight() - getPaddingTop() - getPaddingBottom();

    float baseX = getPaddingLeft() + mCircleRadius;
    float baseY = getPaddingTop() + mCircleRadius;
    float gapX = drawWidth / 2.0f - mCircleRadius;
    float gapY = drawHeight / 2.0f - mCircleRadius;

    float r = mCircleRadius;

    for (int i = 0; i < POINT_COUNT; i++) {
        // compute center point's coordinate
        Point point = new Point();
        point.x = baseX + gapX * (i % 3);
        point.y = baseY + gapY * (i / 3);
        point.index = i;
        mCenterPoints[i] = point;
        // compute wrong triangle path of this point.
        Path path = new Path();
        float x1, y1, x2, y2, x3, y3;
        x1 = point.x + r;
        y1 = point.y;
        x2 = point.x + r * (2.0f / 3);
        y2 = point.y - r * (1.0f / 3);
        x3 = x2;
        y3 = point.y + r * (1.0f / 3);
        path.moveTo(x1, y1);
        path.lineTo(x2, y2);
        path.lineTo(x3, y3);
        path.lineTo(x1, y1);
        path.close();
        mWrongPaths[i] = path;
        Log.d(TAG,
                "[ " + x1 + ", " + y1 + " ], " + "[ " + x2 + ", " + y2 + " ], " + "[ " + x3 + ", " + y3 + " ]");
    }
}

From source file:com.kmagic.solitaire.DrawMaster.java

/**
 * Draw a pedestal ( clubs and spades stand on this )
 * @param canvas canvas to draw on/*w ww  .j ava2s. c  o m*/
 * @param width width of the pedestal
 * @param height height of the pedestal
 */
public void drawPedestal(final Canvas canvas, final float width, final float height) {
    final Paint paint = getBlackPaint();
    final float width_half = width / 2;
    final float width_fifth = width / 5;
    final float width_3_5ths = width_fifth * 3;
    final float height_5th = height / 5;
    canvas.drawRect(width_3_5ths, height_5th, width - width_3_5ths, height, paint);
    final Path path = new Path();
    path.moveTo(width_fifth, height);
    path.lineTo(width_half, height - height_5th);
    path.lineTo(width - width_fifth, height);
    path.lineTo(width_fifth, height);
    path.close();
    canvas.drawPath(path, paint);
}

From source file:de.uni.stuttgart.informatik.ToureNPlaner.UI.Activities.MapScreen.MapScreen.java

private void setupWayOverlay() {
    Path p = new Path();
    p.moveTo(4.f, 0.f);//from w w  w .  j  ava 2s . c o m
    p.lineTo(0.f, -4.f);
    p.lineTo(8.f, -4.f);
    p.lineTo(12.f, 0.f);
    p.lineTo(8.f, 4.f);
    p.lineTo(0.f, 4.f);

    Paint fastWayOverlayColor = new Paint(Paint.ANTI_ALIAS_FLAG);
    fastWayOverlayColor.setStyle(Paint.Style.STROKE);
    fastWayOverlayColor.setColor(Color.BLUE);
    fastWayOverlayColor.setAlpha(160);
    fastWayOverlayColor.setStrokeWidth(5.f);
    fastWayOverlayColor.setStrokeJoin(Paint.Join.ROUND);
    fastWayOverlayColor.setPathEffect(new ComposePathEffect(
            new PathDashPathEffect(p, 12.f, 0.f, PathDashPathEffect.Style.ROTATE), new CornerPathEffect(30.f)));

    // create the WayOverlay and add the ways
    this.fastWayOverlay = new FastWayOverlay(session, fastWayOverlayColor);
    mapView.getOverlays().add(this.fastWayOverlay);
    Result result = session.getResult();
    if (result != null) {
        addPathToMap(result.getWay());
    }
}