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:sg.rghis.android.views.drawable.IconicsDrawable.java

private void prepare() {
    mIconPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

    mContourPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mContourPaint.setStyle(Paint.Style.STROKE);

    mPath = new Path();

    mPathBounds = new RectF();
    mPaddingBounds = new Rect();

    constantState = new ConstantState(this);
}

From source file:com.github.czy1121.view.CornerLabelView.java

private Path calcPath() {
    Path path = new Path();
    path.moveTo(-mHeight, 0);/*w w  w .ja  va2  s.  c  o  m*/
    path.lineTo(mHeight, 0);
    int factor = mIsTop ? -1 : 1;
    if (mIsTriangle) {
        path.lineTo(0, factor * mHeight);
    } else {
        int lineHeight = factor * (int) (mPaddingCenter + mPaddingBottom + mText1.height);
        path.lineTo(mHeight + lineHeight, lineHeight);
        path.lineTo(-mHeight + lineHeight, lineHeight);
    }
    path.close();
    return path;
}

From source file:com.example.zhangyangjing.roundcornerimageview.BezelImageView.java

private void generateMaskPath(int width, int height) {
    mMaskedPath = new Path();
    mMaskedPath.addRoundRect(new RectF(0.0F, 0.0F, width, height), mCornerRadius, mCornerRadius,
            Path.Direction.CW);//from  w w w.ja va2  s  . c o  m
    mMaskedPath.setFillType(Path.FillType.INVERSE_WINDING);
}

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

@Override
public Path getPath(float startX, float startY, float endX, float endY) {
    float dx = endX - startX;
    float dy = endY - startY;
    float length = distance(dx, dy);
    double angle = Math.atan2(dy, dx);

    mTempMatrix.setScale(length, length);
    mTempMatrix.postRotate((float) Math.toDegrees(angle));
    mTempMatrix.postTranslate(startX, startY);
    Path path = new Path();
    mPatternPath.transform(mTempMatrix, path);
    return path;//from  w w  w  . j ava2  s  .  c om
}

From source file:android.support.graphics.drawable.PathInterpolatorCompat.java

private void initQuad(float controlX, float controlY) {
    Path path = new Path();
    path.moveTo(0, 0);//w w  w .ja v a  2 s .co  m
    path.quadTo(controlX, controlY, 1f, 1f);
    initPath(path);
}

From source file:de.hs_bremen.aurora_hunter.ui.views.KpIndexChartView.java

public void onDraw(Canvas canvas) {

    if (points.size() == 0) {
        return;//www  .  java  2s.c o  m
    }
    Path path = new Path();
    int height = canvas.getHeight();
    int width = canvas.getWidth();

    for (Point point : points) {
        point.x = point.percentageX * width + 60;
        // Log.i("scaleFactor", " : " + scaleFactor);
        //Log.i("percent", " : " + percent);

        point.y = (float) ((1 - point.percentageY * scaleFactor) * height * 0.7 + 30);
    }

    if (points.size() > 1) {
        //calcuate x/y based on size of canvas
        for (int i = 0; i < points.size(); i++) {
            if (i >= 0) {
                Point point = points.get(i);
                //  Log.i("dx",point.x + " - " + point.y );
                if (i == 0) {
                    Point next = points.get(i + 1);
                    point.dx = ((next.x - point.x) / 5);
                    point.dy = ((next.y - point.y) / 5);
                } else if (i == points.size() - 1) {
                    Point prev = points.get(i - 1);
                    point.dx = ((point.x - prev.x) / 5);
                    point.dy = ((point.y - prev.y) / 5);
                } else {
                    Point next = points.get(i + 1);
                    Point prev = points.get(i - 1);
                    point.dx = ((next.x - prev.x) / 5);
                    point.dy = ((next.y - prev.y) / 5);
                }
            }
        }
    }

    if (points.size() > 0) {
        path.moveTo(0, (float) (canvas.getHeight() * 0.8));
        path.lineTo(0, points.get(0).y);

    }
    boolean first = true;

    for (int i = 0; i < points.size(); i++) {
        Point point = points.get(i);
        if (first) {
            first = false;
            path.cubicTo(point.x - point.x * 2, point.y - point.y / 5, point.x - point.dx, point.y - point.dy,
                    point.x, point.y);
        } else {
            Point prev = points.get(i - 1);
            //  Log.i("Draw", point.dx  + " " + point.dy);
            path.cubicTo(prev.x + prev.dx, prev.y + prev.dy, point.x - point.dx, point.y - point.dy, point.x,
                    point.y);
        }
    }
    path.lineTo(width, (float) (height * 0.8));

    path.lineTo(width, (float) (height * 0.9));
    path.lineTo(0, (float) (height * 0.9));

    canvas.drawPath(path, mGraphPaint);
    canvas.drawRect(0, (float) (height * 0.9), width, height, mGraphPaint);

    double Kp1Height = (1 - 0.6666666) * height;//points.get(points.size()-1).y;
    canvas.drawRect(0, (float) Kp1Height, width, (float) Kp1Height + 1, paintG1Line);
    canvas.drawText("G1", 2, (float) Kp1Height, paintTxt);
    int detlaY = 15;

    for (Point p : points) {
        int val = (int) Math.round(9 * p.percentageY);
        //if last element
        if (points.indexOf(p) == points.size() - 1) {
            //Log.i("last", p.toString());
            //   canvas.drawText(val + "", p.x-150,p.y - detlaY, paintTxt);
        } else {
            canvas.drawText(val + "", p.x - 10, p.y - detlaY, paintTxt);
        }
        //Log.i("point", p.toString());
    }
    // Log.i("Lenght", points.size() + " ");

}

From source file:nu.yona.app.customview.graph.SpreadGraph.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    this.mCanvas = canvas;
    float fullWidth = canvas.getWidth();

    float heightOfbar = GraphUtils.convertSizeToDeviceDependent(mContext, graphHeight);
    //first bar//from w  w w.ja  va2s.  c  o  m
    float mXStart = 0, mYStart = heightOfbar; // basically (X1, Y1)

    float bottom = heightOfbar; // height (distance from Y1 to Y2)

    mStartPoint = 0;
    mMiddlePoint = (fullWidth / 2);

    float spreadtime = fullWidth;

    float mPartSize = spreadtime / mNoParts;

    //todraw text from height
    float heightDraw = bottom + (GraphUtils.MARGIN_TOP * scaleFactor);

    //draw graphics of sun and moon
    Bitmap moonBitmap = drawableToBitmap(ContextCompat.getDrawable(mContext, R.drawable.icon_moon));
    float bitmapWidth = moonBitmap.getWidth() / 2;
    mCanvas.drawBitmap(moonBitmap, mStartPoint - (5 * scaleFactor), bottom + (5 * scaleFactor), null);
    mCanvas.drawBitmap(drawableToBitmap(ContextCompat.getDrawable(mContext, R.drawable.icn_sun)),
            mMiddlePoint - bitmapWidth, bottom + (5 * scaleFactor), null);

    float textPoint = (mMiddlePoint / 2) / 2;
    mCanvas.drawText(mContext.getString(R.string.four_hours), textPoint, heightDraw + scaleFactor,
            getFontStyle());
    float textPoint2 = textPoint * 2 + ((textPoint / 2));
    mCanvas.drawText(mContext.getString(R.string.eight_hours), textPoint2, heightDraw + scaleFactor,
            getFontStyle());
    float textPoint3 = textPoint * 5;
    mCanvas.drawText(mContext.getString(R.string.sixteen_hours), textPoint3 - bitmapWidth,
            heightDraw + scaleFactor, getFontStyle());
    float textPoint4 = textPoint * 6 + ((textPoint / 2));
    mCanvas.drawText(mContext.getString(R.string.twenty_hours), textPoint4 - bitmapWidth,
            heightDraw + scaleFactor, getFontStyle());
    float textPoint5 = textPoint * 7 + ((textPoint / 2));
    mCanvas.drawBitmap(drawableToBitmap(ContextCompat.getDrawable(mContext, R.drawable.icon_moon)), textPoint5,
            bottom + (5 * scaleFactor), null);

    if (mListZoneSpread != null && mListZoneSpread.size() > 0) {
        float currentStartPos;
        float currentEndPos;
        Paint barGraphPaint = new Paint();
        barGraphPaint.setStyle(Paint.Style.STROKE);
        barGraphPaint.setStrokeWidth(5);
        boolean skipThis;
        for (TimeZoneSpread timeZoneSpread : mListZoneSpread) {
            skipThis = false;
            currentStartPos = (float) timeZoneSpread.getIndex() * mPartSize;
            Path barPath = new Path();
            if (timeZoneSpread.getColor() == GraphUtils.COLOR_PINK
                    || timeZoneSpread.getColor() == GraphUtils.COLOR_BLUE) {
                currentEndPos = timeZoneSpread.getUsedValue();
                barGraphPaint.setColor(timeZoneSpread.getColor());
            } else if (timeZoneSpread.getColor() == GraphUtils.COLOR_GREEN) {
                if (timeZoneSpread.getUsedValue() == 15) {
                    currentEndPos = startEndPoint;
                    barGraphPaint.setColor(GraphUtils.COLOR_BULLET_DOT);
                } else {
                    currentEndPos = startEndPoint;
                    barGraphPaint.setColor(GraphUtils.COLOR_BLUE);
                }
            } else if (timeZoneSpread.getUsedValue() != 15
                    && timeZoneSpread.getColor() == GraphUtils.COLOR_BULLET_LIGHT_DOT) {
                currentEndPos = startEndPoint;
                barGraphPaint.setColor(timeZoneSpread.getColor());
                skipThis = true;
            } else {
                currentEndPos = startEndPoint;
                barGraphPaint.setColor(timeZoneSpread.getColor());
            }
            if (!skipThis) {
                float newXPos = mXStart + currentStartPos;
                barPath.moveTo(newXPos + 2, mYStart);
                float noPartsHeight = heightOfbar / 15;
                barPath.lineTo(currentStartPos + 2, mYStart - (currentEndPos * noPartsHeight) - 1);
                canvas.drawPath(barPath, barGraphPaint);
            }
        }

    }

}

From source file:com.filemanager.free.ui.views.Indicator.java

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

    final int density = (int) context.getResources().getDisplayMetrics().density;

    // Load attributes
    final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.Indicator, defStyle, 0);

    dotDiameter = a.getDimensionPixelSize(R.styleable.Indicator_dotDiameter, DEFAULT_DOT_SIZE * density);
    dotRadius = dotDiameter / 2;/* www.  ja va 2 s.co  m*/
    halfDotRadius = dotRadius / 2;
    gap = a.getDimensionPixelSize(R.styleable.Indicator_dotGap, DEFAULT_GAP * density);
    animDuration = (long) a.getInteger(R.styleable.Indicator_animationDuration, DEFAULT_ANIM_DURATION);
    animHalfDuration = animDuration / 2;
    int unselectedColour = a.getColor(R.styleable.Indicator_pageIndicatorColor, DEFAULT_UNSELECTED_COLOUR);
    int selectedColour = a.getColor(R.styleable.Indicator_currentPageIndicatorColor, DEFAULT_SELECTED_COLOUR);

    a.recycle();

    unselectedPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    unselectedPaint.setColor(unselectedColour);
    selectedPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    selectedPaint.setColor(selectedColour);
    interpolator = AnimUtils.getFastOutSlowInInterpolator(context);

    // create paths & rect now  reuse & rewind later
    combinedUnselectedPath = new Path();
    unselectedDotPath = new Path();
    unselectedDotLeftPath = new Path();
    unselectedDotRightPath = new Path();
    rectF = new RectF();

    addOnAttachStateChangeListener(this);
}

From source file:android.support.graphics.drawable.PathInterpolatorCompat.java

private void initCubic(float x1, float y1, float x2, float y2) {
    Path path = new Path();
    path.moveTo(0, 0);/*from w  w w . j  a  v a  2 s. c om*/
    path.cubicTo(x1, y1, x2, y2, 1f, 1f);
    initPath(path);
}

From source file:com.karthikb351.vitinfo2.customwidget.TimeLineView.java

private void initialize() {

    density = getContext().getResources().getDisplayMetrics().density;

    PADDING_TOP *= density;//from   w w w.j  a  va 2  s . co m
    BORDER_THICKNESS += CIRCLE_RADIUS;
    BORDER_THICKNESS *= density;
    CIRCLE_RADIUS *= density;
    STROKE_WIDTH_RING *= density;
    STROKE_WIDTH_BORDER *= density;
    STROKE_WIDTH_LINE *= density;

    paintDot = new Paint();
    paintDot.setColor(ContextCompat.getColor(getContext(), R.color.text_secondary));
    paintDot.setFlags(Paint.ANTI_ALIAS_FLAG);

    paintRing = new Paint();
    paintRing.setColor(ContextCompat.getColor(getContext(), R.color.text_secondary));
    paintRing.setFlags(Paint.ANTI_ALIAS_FLAG);
    paintRing.setStrokeWidth(STROKE_WIDTH_RING);
    paintRing.setStyle(Paint.Style.FILL_AND_STROKE);

    paintBorder = new Paint();
    paintBorder.setColor(ContextCompat.getColor(getContext(), R.color.text_secondary));
    paintBorder.setAlpha(90);
    paintBorder.setFlags(Paint.ANTI_ALIAS_FLAG);
    paintBorder.setStrokeWidth(STROKE_WIDTH_BORDER);
    paintBorder.setStyle(Paint.Style.FILL_AND_STROKE);

    paintLine = new Paint();
    paintLine.setColor(ContextCompat.getColor(getContext(), R.color.text_secondary));
    paintLine.setAlpha(70);
    paintLine.setFlags(Paint.ANTI_ALIAS_FLAG);
    paintLine.setStrokeWidth(STROKE_WIDTH_LINE);
    paintLine.setStyle(Paint.Style.FILL_AND_STROKE);

    widgetState = STATE_SCHEDULED;
    widgetType = TYPE_INNER;

    rectF = new RectF();
    mPath = new Path();

}