android.graphics.Path Java Examples

The following examples show how to use android.graphics.Path. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WeatherView.java    From Aurora with Apache License 2.0 6 votes vote down vote up
private void drawCloud(Canvas canvas) {
    mPath.reset();
    mPaint.setShader(mCloudLinearGradient);
    if (mCircleInfoBottomOne.isCanDraw())
        mPath.addCircle(mCircleInfoBottomOne.getX(),mCircleInfoBottomOne.getY(),mCircleInfoBottomOne.getRadius(), Path.Direction.CW);//左下1
    if (mCircleInfoBottomTwo.isCanDraw())
        mPath.addCircle(mCircleInfoBottomTwo.getX(),mCircleInfoBottomTwo.getY(),mCircleInfoBottomTwo.getRadius(), Path.Direction.CW);//底部2
    if (mCircleInfoBottomThree.isCanDraw())
        mPath.addCircle(mCircleInfoBottomThree.getX(),mCircleInfoBottomThree.getY(),mCircleInfoBottomThree.getRadius(), Path.Direction.CW);//底3
    if (mCircleInfoTopOne.isCanDraw())
        mPath.addCircle(mCircleInfoTopOne.getX(),mCircleInfoTopOne.getY(),mCircleInfoTopOne.getRadius(), Path.Direction.CW);//顶1
    if (mCircleInfoTopTwo.isCanDraw())
        mPath.addCircle(mCircleInfoTopTwo.getX(),mCircleInfoTopTwo.getY(),mCircleInfoTopTwo.getRadius(), Path.Direction.CW);//顶2
    canvas.save();
    canvas.clipRect(0,0,getMeasuredWidth(),getMeasuredHeight()/2+getMeasuredWidth()/7f);
    canvas.drawPath(mPath,mPaint);
    canvas.restore();
    mPaint.setShader(null);
}
 
Example #2
Source File: TextSticker.java    From imsdk-android with MIT License 6 votes vote down vote up
public TextSticker(Context context, String text, int viewGroupCenterX, int viewGroupCenterY) {
    super(context);

    this.text = text;
    if (TextUtils.isEmpty(this.text)) {
        this.text = context.getString(R.string.text_sticker_hint_easy_photos);
    }
    path = new Path();
    textLayoutWidth = getResources().getDisplayMetrics().widthPixels / 2;
    initButtons();
    initPaints();
    resetSize();
    initStartPoint(viewGroupCenterX, viewGroupCenterY);
    initPs();
    resetBitmap();
    initMatrix();
    initCanvasPosition();
    lastDegree = computeDegree(new Point((int) textWidth, (int) textHeight), new Point((int) textWidth / 2, (int) textHeight / 2));
    lastDoubleDegress = 1000;
    gestureDetector = new GestureDetector(context, new StickerGestureListener());

}
 
Example #3
Source File: RatioKeyline.java    From Rhythm with Apache License 2.0 6 votes vote down vote up
protected RatioKeyline(DisplayMetrics metrics) {
    mTempRect = new Rect();
    mBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBackgroundPaint.setStyle(Paint.Style.FILL);
    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mLabelPath = new Path();

    // Hard-coded defaults
    mTextPaint.setTextSize((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_TEXT_SIZE, metrics));

    // Make default keyline path
    mLabelHeight = (int) ((DEFAULT_LABEL_HEIGHT) * metrics.density);
    mLabelRectWidth = mLabelHeight * 2;
    mLabelSideWidth = mLabelHeight * 3 / 4;

    mLabelPath.rLineTo(0, -mLabelHeight);
    mLabelPath.rLineTo(-mLabelRectWidth, 0);
    mLabelPath.rLineTo(-mLabelSideWidth, mLabelHeight);
    mLabelPath.close();
}
 
Example #4
Source File: TrailedShape.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
TrailedShape(float multiplier) {
    this.mMultiplier = multiplier;

    // Setup trail variables
    this.mTrailPath = new Path();
    this.mTrailList = new LinkedList<>();

    // Setup paint and attributes
    this.mPaint = new Paint();
    this.mTrailPaint = new Paint();

    mPaint.setStyle(Paint.Style.FILL);
    mTrailPaint.setStyle(Paint.Style.STROKE);
    mTrailPaint.setStrokeWidth(5);
    mTrailPaint.setStrokeJoin(Paint.Join.ROUND);
    mTrailPaint.setStrokeCap(Paint.Cap.ROUND);
}
 
Example #5
Source File: OC_LTrace.java    From GLEXP-Team-onebillion with Apache License 2.0 6 votes vote down vote up
public void createConvexHull()
{
    UPath up = new UPath();
    for(List<UPath>lup : letterupaths)
    {
        for (UPath upx : lup)
            up.subPaths.addAll(upx.subPaths);
    }
    USubPath uspch = up.convexHull();
    Path bez = uspch.bezierPath();
    bez.close();
    hotPath = new OBPath(bez);
    int col = Color.argb((int)(0.7*255),255,0,0);
    hotPath.setFillColor(col);
    hotPath.setStrokeColor(col);
    hotPath.setLineWidth(applyGraphicScale(paths.get(0).lineWidth() ));
    hotPath.setLineJoin(OBStroke.kCALineJoinRound);
    hotPath.sizeToBoundingBoxIncludingStroke();
    hotPath.setZPosition(100);
    //attachControl(hotPath);
}
 
Example #6
Source File: SVGAndroidRenderer.java    From XDroidAnimation with Apache License 2.0 6 votes vote down vote up
private void addObjectToClip(SVG.Use obj, Path combinedPath, Matrix combinedPathMatrix)
{
   updateStyleForElement(state, obj);

   if (!display())
      return;
   if (!visible())
      return;

   if (obj.transform != null)
      combinedPathMatrix.preConcat(obj.transform);

   // Locate the referenced object
   SVG.SvgObject  ref = obj.document.resolveIRI(obj.href);
   if (ref == null) {
      error("Use reference '%s' not found", obj.href);
      return;
   }

   checkForClipPath(obj);
   
   addObjectToClip(ref, false, combinedPath, combinedPathMatrix);
}
 
Example #7
Source File: CustomRoundAngleImageView.java    From a with GNU General Public License v3.0 6 votes vote down vote up
@Override protected void onDraw(Canvas canvas) {
        if (width >= 12 && height > 12)
    {
        Path path = new Path(); //四个圆角
        path.moveTo(12, 0);
        path.lineTo(width - 12, 0);
        path.quadTo(width, 0, width, 12);
        path.lineTo(width, height - 12);
        path.quadTo(width, height, width - 12, height);
        path.lineTo(12, height);
        path.quadTo(0, height, 0, height - 12);
        path.lineTo(0, 12);
        path.quadTo(0, 0, 12, 0);
        canvas.clipPath(path); }
        super.onDraw(canvas);
}
 
Example #8
Source File: ReflectItemView.java    From AndroidTVWidget with Apache License 2.0 6 votes vote down vote up
/**
 * 绘制倒影.
 */
public void drawReflection(Canvas reflectionCanvas) {
    int width = getWidth();
    int height = getHeight();
    int count = reflectionCanvas.save();
    int count2 = reflectionCanvas.saveLayer(0, 0, width, mRefHeight, null, Canvas.ALL_SAVE_FLAG);
    //
    reflectionCanvas.save();
    reflectionCanvas.clipRect(0, 0, getWidth(), mRefHeight);
    reflectionCanvas.save();
    reflectionCanvas.scale(1, -1);
    reflectionCanvas.translate(0, -getHeight());
    super.draw(reflectionCanvas);
    if (mIsDrawShape) {
        Path path = getShapePath(width, height, mRadius);
        reflectionCanvas.drawPath(path, mShapePaint);
    }
    reflectionCanvas.restore();
    reflectionCanvas.drawRect(0, 0, getWidth(), mRefHeight, mRefPaint);
    reflectionCanvas.restore();
    //
    if (count2 > 0) {
        reflectionCanvas.restoreToCount(count2);
    }
    reflectionCanvas.restoreToCount(count);
}
 
Example #9
Source File: PathInfo.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
PathInfo(Path path, float width, float height) {
    this.path = path;

    float tmpWidth = width;
    float tmpHeight = height;
    RectF bounds = new RectF();
    path.computeBounds(bounds, true);
    if(width <= 0 && height <= 0) {
        tmpWidth = (float) Math.ceil(bounds.width());
        tmpHeight = (float) Math.ceil(bounds.height());
        path.offset(-1 * (float) Math.floor(bounds.left),
                -1 * (float) Math.round(bounds.top));
    }

    this.width = tmpWidth;
    this.height = tmpHeight;
}
 
Example #10
Source File: SimpleTagImageView.java    From SprintNBA with Apache License 2.0 6 votes vote down vote up
public SimpleTagImageView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SimpleTagImageView, defStyleAttr, 0);
    mTagOrientation = a.getInteger(R.styleable.SimpleTagImageView_simple_tag_orientation, 0);
    mTagWidth = a.getDimensionPixelSize(R.styleable.SimpleTagImageView_simple_tag_width, DimenUtils.dpToPxInt(DEFAULT_TAG_WIDTH));
    mCornerDistance = a.getDimensionPixelSize(R.styleable.SimpleTagImageView_simple_corner_distance, DimenUtils.dpToPxInt(DEFAULT_CORNER_DISTANCE));
    mTagBackgroundColor = a.getColor(R.styleable.SimpleTagImageView_simple_tag_background_color, DEFAULT_TAG_BACKGROUND_COLOR);
    mTagText = a.getString(R.styleable.SimpleTagImageView_simple_tag_text);
    mTagTextSize = a.getDimensionPixelSize(R.styleable.SimpleTagImageView_simple_tag_textSize, DimenUtils.dpToPxInt(DEFAULT_TAG_TEXT_SIZE));
    mTagTextColor = a.getColor(R.styleable.SimpleTagImageView_simple_tag_textColor, DEFAULT_TAG_TEXT_COLOR);
    mTagEnable = a.getBoolean(R.styleable.SimpleTagImageView_simple_tag_enable, true);
    mRoundRadius = a.getDimensionPixelSize(R.styleable.SimpleTagImageView_simple_tag_round_radius, 0);
    a.recycle();
    if (TextUtils.isEmpty(mTagText)) mTagText = "";
    mPaint = new Paint();
    mPath = new Path();
    mTextPaint = new Paint();
    mTagTextBound = new Rect();
    startPoint = new MyPoint();
    endPoint = new MyPoint();
    mRoundRect = new RectF();
}
 
Example #11
Source File: SetupStartIndicatorView.java    From Indic-Keyboard with Apache License 2.0 6 votes vote down vote up
@Override
protected void onDraw(final Canvas canvas) {
    super.onDraw(canvas);
    final int layoutDirection = ViewCompat.getLayoutDirection(this);
    final int width = getWidth();
    final int height = getHeight();
    final float halfHeight = height / 2.0f;
    final Path path = mIndicatorPath;
    path.rewind();
    if (layoutDirection == ViewCompat.LAYOUT_DIRECTION_RTL) {
        // Left arrow
        path.moveTo(width, 0.0f);
        path.lineTo(0.0f, halfHeight);
        path.lineTo(width, height);
    } else { // LAYOUT_DIRECTION_LTR
        // Right arrow
        path.moveTo(0.0f, 0.0f);
        path.lineTo(width, halfHeight);
        path.lineTo(0.0f, height);
    }
    path.close();
    final int[] stateSet = getDrawableState();
    final int color = mIndicatorColor.getColorForState(stateSet, 0);
    mIndicatorPaint.setColor(color);
    canvas.drawPath(path, mIndicatorPaint);
}
 
Example #12
Source File: BarcodeConfirmingGraphic.java    From mlkit-material-android with Apache License 2.0 6 votes vote down vote up
@Override
public void draw(Canvas canvas) {
  super.draw(canvas);

  // Draws a highlighted path to indicate the current progress to meet size requirement.
  float sizeProgress = PreferenceUtils.getProgressToMeetBarcodeSizeRequirement(overlay, barcode);
  Path path = new Path();
  if (sizeProgress > 0.95f) {
    // To have a completed path with all corners rounded.
    path.moveTo(boxRect.left, boxRect.top);
    path.lineTo(boxRect.right, boxRect.top);
    path.lineTo(boxRect.right, boxRect.bottom);
    path.lineTo(boxRect.left, boxRect.bottom);
    path.close();

  } else {
    path.moveTo(boxRect.left, boxRect.top + boxRect.height() * sizeProgress);
    path.lineTo(boxRect.left, boxRect.top);
    path.lineTo(boxRect.left + boxRect.width() * sizeProgress, boxRect.top);

    path.moveTo(boxRect.right, boxRect.bottom - boxRect.height() * sizeProgress);
    path.lineTo(boxRect.right, boxRect.bottom);
    path.lineTo(boxRect.right - boxRect.width() * sizeProgress, boxRect.bottom);
  }
  canvas.drawPath(path, pathPaint);
}
 
Example #13
Source File: ReflectItemView.java    From Android-tv-widget with Apache License 2.0 6 votes vote down vote up
/**
 * 绘制圆角控件. 修复使用clipPath有锯齿问题.
 */
private void drawShapePathCanvas(Canvas shapeCanvas) {
    if (shapeCanvas != null) {
        int width = getWidth();
        int height = getHeight();
        if (width == 0 || height == 0)
            return;
        int count = shapeCanvas.save();
        int count2 = shapeCanvas.saveLayer(0, 0, width, height, null, Canvas.ALL_SAVE_FLAG);
        //
        Path path = getShapePath(width, height, mRadius);
        super.draw(shapeCanvas);
        shapeCanvas.drawPath(path, mShapePaint);
        //
        if (count2 > 0) {
            shapeCanvas.restoreToCount(count2);
        }
        shapeCanvas.restoreToCount(count);
    }
}
 
Example #14
Source File: PathParser.java    From CollapsingRefresh with Apache License 2.0 5 votes vote down vote up
/**
 * @param pathData The string representing a path, the same as "d" string in svg file.
 * @return the generated Path object.
 */
public static Path createPathFromPathData(String pathData) {
    Path path = new Path();
    PathDataNode[] nodes = createNodesFromPathData(pathData);
    if (nodes != null) {
        try {
            PathDataNode.nodesToPath(nodes, path);
        } catch (RuntimeException e) {
            throw new RuntimeException("Error in parsing " + pathData, e);
        }
        return path;
    }
    return null;
}
 
Example #15
Source File: BadgeDrawable.java    From SegmentedButton with Apache License 2.0 5 votes vote down vote up
@Override
protected void onBoundsChange(Rect bounds) {
    path.reset();

    path.addRect(bounds.left, bounds.top, bounds.right, bounds.bottom, Path.Direction.CW);
    rect.set(bounds.left + borderWidth, bounds.top + borderWidth,
            bounds.right - borderWidth, bounds.bottom - borderWidth);
    path.addRoundRect(rect, borderRadius, borderRadius, Path.Direction.CW);
}
 
Example #16
Source File: LineDrawStrategy.java    From styT with Apache License 2.0 5 votes vote down vote up
@Override
public void drawAppName(Canvas canvas, float fraction, String name, int colorOfAppName,
                        WidthAndHeightOfView widthAndHeightOfView) {
    canvas.save();
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(colorOfAppName);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(5);
    paint.setTextSize(50);
    paint.setStrokeJoin(Paint.Join.ROUND);
    paint.setTextAlign(Paint.Align.LEFT);
    float x = widthAndHeightOfView.getWidth() / 2;
    int centerY = widthAndHeightOfView.getHeight() / 2;
    float y = centerY - 275;
    Path path = new Path();
    path.moveTo(x, y);
    if (fraction <= 0.50) {
        path.lineTo(x, y + (25 + name.length() + 250) * (fraction / 0.50f));
        canvas.drawPath(path, paint);
    } else {
        path.lineTo(x, y + (25 + name.length() + 250) * ((1 - fraction)/ 0.50f));
        canvas.drawPath(path, paint);
        paint.setStyle(Paint.Style.FILL);
        canvas.drawText(name, x + 20, y + 150, paint);
    }
    canvas.restore();
}
 
Example #17
Source File: SecondActivity.java    From android-pathview with Apache License 2.0 5 votes vote down vote up
private Path makeConvexArrow(float length, float height) {
    final Path path = new Path();
    path.moveTo(0.0f, 0.0f);
    path.lineTo(length / 4f, 0.0f);
    path.lineTo(length, height / 2.0f);
    path.lineTo(length / 4f, height);
    path.lineTo(0.0f, height);
    path.lineTo(length * 3f / 4f, height / 2f);
    path.lineTo(0.0f, 0.0f);
    path.close();
    return path;
}
 
Example #18
Source File: TooltipErrorView.java    From buddycloud-android with Apache License 2.0 5 votes vote down vote up
/**
 * Create the shape path
 * 
 * @param rectPath
 * @param rectBorderPath
 * @param width
 * @param height
 * @param pointHeightPx
 * @param pointedHeightPx
 * @param pointStartPx
 */
private void createShapePath(Path rectPath, Path rectBorderPath,
		float width, float height, int pointHeightPx, int pointedHeightPx,
		int pointStartPx) {

	int w = (int) width;
	int h = (int) height;

	Point a = new Point(0, h);
	Point b = new Point(w, h);
	Point c = new Point(w, pointHeightPx);
	Point d = new Point((w - (w - pointStartPx)) + (pointedHeightPx / 2),
			pointHeightPx);
	Point e = new Point((w - (w - pointStartPx)), 0); // this is the sharp
														// point of the
														// triangle
	Point f = new Point((w - (w - pointStartPx)) - (pointedHeightPx / 2),
			pointHeightPx);
	Point g = new Point(0, pointHeightPx);

	rectPath.reset();
	rectPath.moveTo(a.x, a.y);
	rectPath.lineTo(b.x, b.y);
	rectPath.lineTo(c.x, c.y);
	rectPath.lineTo(d.x, d.y);
	rectPath.lineTo(e.x, e.y);
	rectPath.lineTo(f.x, f.y);
	rectPath.lineTo(g.x, g.y);
	rectPath.close();

	rectBorderPath.reset();
	rectBorderPath.moveTo(a.x, a.y);
	rectBorderPath.lineTo(b.x, b.y);
	rectBorderPath.lineTo(c.x, c.y);
	rectBorderPath.lineTo(d.x, d.y);
	rectBorderPath.lineTo(e.x, e.y);
	rectBorderPath.lineTo(f.x, f.y);
	rectBorderPath.lineTo(g.x, g.y);
	rectBorderPath.close();
}
 
Example #19
Source File: MainLayout.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
MainLayout(Context context) {
    super(context);
    setWillNotDraw(false);
    setOrientation(LinearLayout.HORIZONTAL);
    setGravity(Gravity.CENTER_VERTICAL);
    mCornerCrop.setFillType(Path.FillType.EVEN_ODD);
    mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    mCropPath.setFillType(Path.FillType.EVEN_ODD);
}
 
Example #20
Source File: SummaryGraph.java    From tickmate with GNU General Public License v3.0 5 votes vote down vote up
private void init(Context context) {
	setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));		
	paint = new Paint(Paint.ANTI_ALIAS_FLAG);
	path = new Path();

	this.data = new LinkedList<>();
	this.keys = new LinkedList<>();
	this.cyclic = false;
	this.mColor = ContextCompat.getColor(context, android.R.color.holo_blue_light);
	this.mTextColor = ContextCompat.getColor(context, android.R.color.secondary_text_dark);
	this.mMarkerColor = ContextCompat.getColor(context, android.R.color.white);
}
 
Example #21
Source File: ActionButtonItems.java    From SpringActionMenu with Apache License 2.0 5 votes vote down vote up
private void init() {
    mPaint = new Paint();

    mPaint.setAntiAlias(true);
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setDither(true);
    mPaint.setColor(normalColor);

    mPath = new Path();
    extra = (int)(circleRadius * 2 * factor / 5);
    offSet = circleRadius * 2 / 3.6f;
    factor = 0;
    isPress = false;
    isOpen = false;
}
 
Example #22
Source File: SearchPathBuilder.java    From AndroidWallet with GNU General Public License v3.0 5 votes vote down vote up
private void initPaths()
{
    float r = mR * 0.4f;

    mPath = new Path();
    mPath.addArc(new RectF(getViewCenterX() - mR, getViewCenterY() - mR, getViewCenterX() + mR, getViewCenterY() + mR), 45, 359.9f);
    mPathMeasure.setPath(mPath, false);
    float[] pos = new float[2];
    mPathMeasure.getPosTan(0, pos, null);

    mPathZoom = new Path();
    mPathZoom.addArc(new RectF(getViewCenterX() - r, getViewCenterY() - r, getViewCenterX() + r, getViewCenterY() + r), 45, 359.9f);
    mPathZoom.lineTo(pos[0], pos[1]);
}
 
Example #23
Source File: CompassView.java    From android with Apache License 2.0 5 votes vote down vote up
private void initArrows(int w, int h) {
    mArrowBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    mArrowBitmap.eraseColor(Color.TRANSPARENT);
    Canvas arrowCanvas = new Canvas(mArrowBitmap);
    mArrowRotator = new Matrix();

    int hw = w / 2;
    int hh = h / 2;

    int t1 = (int) (w * 0.35);
    int t2 = (int) (w * 0.05);

    Point d = new Point(hw - t2, hh);
    Point e = new Point(hw + t2, hh);
    Point f = new Point(hw, hh - t1);
    Point g = new Point(hw, hh + t1);

    Path path = new Path();
    path.setFillType(Path.FillType.EVEN_ODD);
    path.moveTo(d.x, d.y);
    path.lineTo(e.x, e.y);
    path.lineTo(f.x, f.y);
    path.close();

    Path path2 = new Path();
    path2.setFillType(Path.FillType.EVEN_ODD);
    path2.moveTo(d.x, d.y);
    path2.lineTo(e.x, e.y);
    path2.lineTo(g.x, g.y);
    path2.close();

    arrowCanvas.drawPath(path, mCirclePaint);
    arrowCanvas.drawPath(path2, mWhiteArrowPaint);
    arrowCanvas.save();
}
 
Example #24
Source File: HeartView.java    From LoveHeartView with Apache License 2.0 5 votes vote down vote up
private void init() {

        paint =new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setColor(Color.BLUE);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(5);

        //-------------这里是绘制心形,大家可以自己画任何曲线---------------------------
        mPath = new Path();
        mPath.moveTo(396-50,313);
        mPath.cubicTo(207-50,114, 339-50,46, 396-50,111);
        mPath.cubicTo(453-50, 46,585-50, 114,396-50,313);

        //----------------------------------------------
        pathMeasure =new PathMeasure(mPath,false);//false表示是否强制闭合路径

        valueAnimator = ValueAnimator.ofFloat(0,pathMeasure.getLength());
        valueAnimator.setDuration(5000);
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                mLength= (float) animation.getAnimatedValue();
                invalidate();
            }
        });

    }
 
Example #25
Source File: PathAnimatorCompat.java    From Transitions-Everywhere with Apache License 2.0 5 votes vote down vote up
@Nullable
public static <T> PathAnimatorCompat ofPointF(@Nullable T target, @Nullable PointFProperty<T> property, @Nullable Path path) {
    PathAnimatorCompat animator = null;
    if (target != null && property != null && path != null) {
        animator = new PathAnimatorCompat(target, property);
        animator.mPathMeasure = new PathMeasure(path, false);
        animator.mPathLength = animator.mPathMeasure.getLength();
    }
    return animator;
}
 
Example #26
Source File: CropImageView.java    From Android-CropView with Apache License 2.0 5 votes vote down vote up
private void drawOverlay(Canvas canvas) {
    mPaintTranslucent.setAntiAlias(true);
    mPaintTranslucent.setFilterBitmap(true);
    mPaintTranslucent.setColor(mOverlayColor);
    mPaintTranslucent.setStyle(Paint.Style.FILL);
    Path path = new Path();
    RectF overlayRect = new RectF((float) Math.floor(mImageRect.left),
            (float) Math.floor(mImageRect.top),
            (float) Math.ceil(mImageRect.right),
            (float) Math.ceil(mImageRect.bottom));
    if (!mIsAnimating
            && (mCropMode == CropMode.CIRCLE || mCropMode == CropMode.CIRCLE_SQUARE)) {
        path.addRect(
                overlayRect,
                Path.Direction.CW
        );
        PointF circleCenter = new PointF((mFrameRect.left + mFrameRect.right) / 2,
                (mFrameRect.top + mFrameRect.bottom) / 2);
        float circleRadius = (mFrameRect.right - mFrameRect.left) / 2;
        path.addCircle(circleCenter.x, circleCenter.y, circleRadius, Path.Direction.CCW);
        canvas.drawPath(path, mPaintTranslucent);
    } else {
        path.addRect(
                overlayRect,
                Path.Direction.CW
        );
        path.addRect(mFrameRect, Path.Direction.CCW);
        canvas.drawPath(path, mPaintTranslucent);
    }
}
 
Example #27
Source File: RoundedCornersDrawable.java    From fresco with MIT License 5 votes vote down vote up
private void updatePath() {
  mPath.reset();
  mBorderPath.reset();
  mTempRectangle.set(getBounds());

  mTempRectangle.inset(mPadding, mPadding);
  if (mType == Type.OVERLAY_COLOR) {
    mPath.addRect(mTempRectangle, Path.Direction.CW);
  }
  if (mIsCircle) {
    mPath.addCircle(
        mTempRectangle.centerX(),
        mTempRectangle.centerY(),
        Math.min(mTempRectangle.width(), mTempRectangle.height()) / 2,
        Path.Direction.CW);
  } else {
    mPath.addRoundRect(mTempRectangle, mRadii, Path.Direction.CW);
  }
  mTempRectangle.inset(-mPadding, -mPadding);

  mTempRectangle.inset(mBorderWidth / 2, mBorderWidth / 2);
  if (mIsCircle) {
    float radius = Math.min(mTempRectangle.width(), mTempRectangle.height()) / 2;
    mBorderPath.addCircle(
        mTempRectangle.centerX(), mTempRectangle.centerY(), radius, Path.Direction.CW);
  } else {
    for (int i = 0; i < mBorderRadii.length; i++) {
      mBorderRadii[i] = mRadii[i] + mPadding - mBorderWidth / 2;
    }
    mBorderPath.addRoundRect(mTempRectangle, mBorderRadii, Path.Direction.CW);
  }
  mTempRectangle.inset(-mBorderWidth / 2, -mBorderWidth / 2);
}
 
Example #28
Source File: SVGAndroidRenderer.java    From starcor.xul with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void render(SVG.PolyLine obj)
{
   debug("PolyLine render");

   updateStyleForElement(state, obj);

   if (!display())
      return;
   if (!visible())
      return;
   if (!state.hasStroke && !state.hasFill)
      return;

   if (obj.transform != null)
      canvas.concat(obj.transform);

   int  numPoints = obj.points.length;
   if (numPoints < 2)
      return;

   Path  path = makePathAndBoundingBox(obj);
   updateParentBoundingBox(obj);

   checkForGradiantsAndPatterns(obj);      
   checkForClipPath(obj);
   
   boolean  compositing = pushLayer();

   if (state.hasFill)
      doFilledPath(obj, path);
   if (state.hasStroke)
      doStroke(path);

   renderMarkers(obj);

   if (compositing)
      popLayer(obj);
}
 
Example #29
Source File: SVGAndroidRenderer.java    From XDroidAnimation with Apache License 2.0 5 votes vote down vote up
private Path.FillType  getClipRuleFromState()
{
   if (state.style.clipRule == null)
      return Path.FillType.WINDING;
   switch (state.style.clipRule)
   {
      case EvenOdd:
         return Path.FillType.EVEN_ODD;
      case NonZero:
      default:
         return Path.FillType.WINDING;
   }
}
 
Example #30
Source File: Chart.java    From WaveHeartRate with Apache License 2.0 5 votes vote down vote up
/**
 * transform a path with all the given matrices VERY IMPORTANT: keep order
 * to value-touch-offset
 * 
 * @param path
 */
protected void transformPath(Path path) {

    path.transform(mMatrixValueToPx);
    path.transform(mMatrixTouch);
    path.transform(mMatrixOffset);
}