Java Code Examples for android.graphics.Path

The following are top voted examples for showing how to use android.graphics.Path. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: PresenterLite   File: ShapedImageView.java   Source Code and License 7 votes vote down vote up
private Bitmap rotatedOval(Bitmap bitmap) {
    Bitmap bmp;
    float width = bitmap.getWidth();
    float height = bitmap.getHeight();

    bmp = Bitmap.createBitmap((int) width, (int) height, Bitmap.Config.ARGB_8888);
    BitmapShader shader = new BitmapShader(bitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);

    Canvas canvas = new Canvas(bmp);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setShader(shader);

    Path oval = new Path();
    Matrix matrix = new Matrix();
    RectF ovalRect = new RectF(width / OVAL_FACTOR, 0, width - (width / OVAL_FACTOR), height);

    oval.addOval(ovalRect, Path.Direction.CW);
    matrix.postRotate(ROTATION, width / 2, height / 2);
    oval.transform(matrix, oval);
    canvas.drawPath(oval, paint);

    return bmp;
}
 
Example 2
Project: OneWeather   File: Windmill.java   Source Code and License 7 votes vote down vote up
private void drawWind(Canvas canvas) {
    mWindPath = new Path();
    canvas.drawCircle(mCenterPoint.x,mCenterPoint.y,width/40,mWindmillPaint);
    mWindPath.moveTo(x1,y1);
    x2 = mCenterPoint.x + (float) (r1 * Math.cos(rad1 + angle));
    y2 = mCenterPoint.y + (float) (r1 * Math.sin(rad1 + angle));
    x3 = mCenterPoint.x + (float) (r2 * Math.cos(rad2 + angle));
    y3 = mCenterPoint.y + (float) (r2 * Math.sin(rad2 + angle));
    x4 = mCenterPoint.x + (float) (r3 * Math.cos(rad3 + angle));
    y4 = mCenterPoint.y + (float) (r3 * Math.sin(rad3 + angle));
    x5 = mCenterPoint.x + (float) (r4 * Math.cos(rad4 + angle));
    y5 = mCenterPoint.y + (float) (r4 * Math.sin(rad4 + angle));


    mWindPath.cubicTo(x2,y2,x3,y3,x4,y4);
    mWindPath.quadTo(x5,y5,x1,y1);
    mWindPath.close();
    canvas.drawPath(mWindPath,mWindmillPaint);
    canvas.rotate(120,mCenterPoint.x,mCenterPoint.y);
    canvas.drawPath(mWindPath,mWindmillPaint);
    canvas.rotate(120,mCenterPoint.x,mCenterPoint.y);
    canvas.drawPath(mWindPath,mWindmillPaint);
    canvas.rotate(120,mCenterPoint.x,mCenterPoint.y);
}
 
Example 3
Project: android-dev-challenge   File: TrailedShape.java   Source Code and License 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 4
Project: Aurora   File: WeatherView.java   Source Code and License 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 5
Project: PropertyAnimatorDemo   File: MyBezierView.java   Source Code and License 6 votes vote down vote up
private void init(Context context) {
    mTextPaint = new Paint();
    mPaint = new Paint();
    mPath = new Path();
    startPoint = new Point(200, 200);
    endPoint = new Point(800, 800);
    assistPoint = new Point(800, 200);
    // 抗锯齿
    mPaint.setAntiAlias(true);
    // 防抖动
    mPaint.setDither(true);
    //坐标
    mTextPaint.setColor(Color.RED);
    mTextPaint.setTextSize(20);
    mTextPaint.setStrokeWidth(10);
    mTextPaint.setAntiAlias(true);
    mTextPaint.setDither(true);
}
 
Example 6
Project: ColumnAnimViewProject   File: RadarView.java   Source Code and License 6 votes vote down vote up
/**
 * 绘制正多边形
 */
private void drawPolygon(Canvas canvas){
    Path path = new Path();
    float r = radius/(count-1);
    for(int i=1;i<count;i++){
        float curR = r*i;
        path.reset();
        for(int j=0;j<count;j++){
            if(j==0){
                path.moveTo(centerX+curR,centerY);
            }else{
                float x = (float) (centerX+curR*Math.cos(angle*j));
                float y = (float) (centerY+curR*Math.sin(angle*j));
                path.lineTo(x,y);
            }
        }
        path.close();
        canvas.drawPath(path, mainPaint);
    }
}
 
Example 7
Project: xwallet   File: CameraView.java   Source Code and License 6 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (canvas == null) return;

    mPath.reset();

    mPath.addCircle(canvas.getWidth() / 2, canvas.getHeight() / 2, 550, Path.Direction.CW);
    mPath.setFillType(Path.FillType.INVERSE_EVEN_ODD);

    canvas.drawCircle(canvas.getWidth() / 2, canvas.getHeight() / 2, 550, mTransparentPaint);

    canvas.drawPath(mPath, mSemiBlackPaint);
    canvas.clipPath(mPath);
    canvas.drawColor(Color.parseColor("#A6000000"));
}
 
Example 8
Project: RTLMaterialSpinner   File: RtlMaterialSpinner.java   Source Code and License 6 votes vote down vote up
private void initPaintObjects() {

        int labelTextSize = getResources().getDimensionPixelSize(R.dimen.label_text_size);

        paint = new Paint(Paint.ANTI_ALIAS_FLAG);

        textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
        textPaint.setTextSize(labelTextSize);
        if (typeface != null) {
            textPaint.setTypeface(typeface);
        }
        textPaint.setColor(baseColor);
        baseAlpha = textPaint.getAlpha();

        selectorPath = new Path();
        selectorPath.setFillType(Path.FillType.EVEN_ODD);

        selectorPoints = new Point[3];
        for (int i = 0; i < 3; i++) {
            selectorPoints[i] = new Point();
        }
    }
 
Example 9
Project: atlas   File: ShapeFill.java   Source Code and License 6 votes vote down vote up
static ShapeFill newInstance(JSONObject json, LottieComposition composition) {
  AnimatableColorValue color = null;
  boolean fillEnabled;
  AnimatableIntegerValue opacity = null;

  JSONObject jsonColor = json.optJSONObject("c");
  if (jsonColor != null) {
    color = AnimatableColorValue.Factory.newInstance(jsonColor, composition);
  }

  JSONObject jsonOpacity = json.optJSONObject("o");
  if (jsonOpacity != null) {
    opacity = AnimatableIntegerValue.Factory.newInstance(jsonOpacity, composition);
  }
  fillEnabled = json.optBoolean("fillEnabled");

  int fillTypeInt = json.optInt("r", 1);
  Path.FillType fillType = fillTypeInt == 1 ? Path.FillType.WINDING : Path.FillType.EVEN_ODD;

  return new ShapeFill(fillEnabled, fillType, color, opacity);
}
 
Example 10
Project: Material-Motion   File: BaseFragment.java   Source Code and License 6 votes vote down vote up
protected Path createArcPath(View view, float endX, float endY, float radius){
    Path arcPath=new Path();
    float startX=view.getTranslationX();
    float startY=view.getTranslationY();
    float midX = startX + ((endX - startX) / 2);
    float midY = startY + ((endY - startY) / 2);
    float xDiff = midX - startX;
    float yDiff = midY - startY;

    double angle = (Math.atan2(yDiff, xDiff) * (180 / Math.PI)) - 90;
    double angleRadians = Math.toRadians(angle);

    float pointX = (float) (midX + radius * Math.cos(angleRadians));
    float pointY = (float) (midY + radius * Math.sin(angleRadians));

    arcPath.moveTo(startX, startY);
    arcPath.cubicTo(startX,startY,pointX,pointY, endX, endY);
    return arcPath;
}
 
Example 11
Project: PopupCircleMenu   File: PopupLayer.java   Source Code and License 6 votes vote down vote up
/**
 * 用来给每一个button设置一个中心点
 *
 * @param orbit 一个特定角度的path
 */
private void setPos(Path orbit) {
    PathMeasure measure = new PathMeasure(orbit, false);
    TextLableView tv;
    for (int i = 0; i < mButtons.size(); i++) {
        PopupButton pp = mButtons.get(i);
        tv = kvs.get(pp);
        float[] coords = new float[]{0f, 0f};
        int length = (int) ((i) * measure.getLength() / mButtons.size());
        measure.getPosTan(length, coords, null);
        int px = (int) coords[0] - pp.getMeasuredWidth() / 2;
        int py = (int) coords[1] - pp.getMeasuredHeight() / 2;
        int tvx = (int) coords[0] - tv.getMeasuredWidth() / 2;
        tv.x = tvx;
        tv.y = py - 60;
        pp.x = px;
        pp.y = py;
    }
}
 
Example 12
Project: boohee_v5.6   File: AnimCheckBox.java   Source Code and License 6 votes vote down vote up
public AnimCheckBox(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.TAG = "AnimCheckBox";
    this.mPaint = new Paint(1);
    this.mRectF = new RectF();
    this.mInnerRectF = new RectF();
    this.mPath = new Path();
    this.mSin27 = Math.sin(Math.toRadians(27.0d));
    this.mSin63 = Math.sin(Math.toRadians(63.0d));
    this.mChecked = true;
    this.mInnerCircleAlpha = 255;
    this.mStrokeWidth = 2;
    this.mDuration = 500;
    this.mStrokeColor = -16776961;
    this.mCircleColor = -1;
    this.defaultSize = 40;
    this.mClickable = true;
    init(attrs);
}
 
Example 13
Project: open-rmbt   File: SimpleGraph.java   Source Code and License 6 votes vote down vote up
private SimpleGraph(final int color, final long maxNsecs, final float width, final float height, final float strokeWidth)
{
    this.maxNsecs = maxNsecs;
    // this.width = width;
    this.height = height;
    nsecWidth = width / maxNsecs;
    
    paintStroke = new Paint();
    paintStroke.setColor(color);
    paintStroke.setAlpha(204); // 80%
    paintStroke.setStyle(Style.STROKE);
    paintStroke.setStrokeWidth(strokeWidth);
    paintStroke.setStrokeCap(Cap.ROUND);
    paintStroke.setStrokeJoin(Join.ROUND);
    paintStroke.setAntiAlias(true);
    
    paintFill = new Paint();
    paintFill.setColor(color);
    paintFill.setAlpha(51); // 20%
    paintFill.setStyle(Style.FILL);
    paintFill.setAntiAlias(true);
    
    pathStroke = new Path();
    pathFill = new Path();
}
 
Example 14
Project: RNLearn_Project1   File: DrawView.java   Source Code and License 6 votes vote down vote up
/**
 * Update the path with which we'll clip this view
 */
private void updateClipPath() {
  mPath = new Path();

  TMP_RECT.set(
      getLeft(),
      getTop(),
      getRight(),
      getBottom());

  // set the path
  mPath.addRoundRect(
      TMP_RECT,
      mClipRadius,
      mClipRadius,
      Path.Direction.CW);
}
 
Example 15
Project: GitHub   File: LineRadarRenderer.java   Source Code and License 6 votes vote down vote up
/**
 * Draws the provided path in filled mode with the provided drawable.
 *
 * @param c
 * @param filledPath
 * @param drawable
 */
protected void drawFilledPath(Canvas c, Path filledPath, Drawable drawable) {

    if (clipPathSupported()) {

        int save = c.save();
        c.clipPath(filledPath);

        drawable.setBounds((int) mViewPortHandler.contentLeft(),
                (int) mViewPortHandler.contentTop(),
                (int) mViewPortHandler.contentRight(),
                (int) mViewPortHandler.contentBottom());
        drawable.draw(c);

        c.restoreToCount(save);
    } else {
        throw new RuntimeException("Fill-drawables not (yet) supported below API level 18, " +
                "this code was run on API level " + Utils.getSDKInt() + ".");
    }
}
 
Example 16
Project: android-slidr   File: Slidr.java   Source Code and License 6 votes vote down vote up
private void drawBubblePath(Canvas canvas, float triangleCenterX, float height, float width) {
    final Path path = new Path();

    int padding = 3;
    final Rect rect = new Rect(padding, padding, (int) width - padding, (int) (height - dpToPx(BUBBLE_ARROW_HEIGHT)) - padding);

    final float roundRectHeight = (height - dpToPx(BUBBLE_ARROW_HEIGHT)) / 2;

    path.moveTo(rect.left + roundRectHeight, rect.top);
    path.lineTo(rect.right - roundRectHeight, rect.top);
    path.quadTo(rect.right, rect.top, rect.right, rect.top + roundRectHeight);
    path.lineTo(rect.right, rect.bottom - roundRectHeight);
    path.quadTo(rect.right, rect.bottom, rect.right - roundRectHeight, rect.bottom);

    path.lineTo(triangleCenterX + dpToPx(BUBBLE_ARROW_WIDTH) / 2f, height - dpToPx(BUBBLE_ARROW_HEIGHT) - padding);
    path.lineTo(triangleCenterX, height - padding);
    path.lineTo(triangleCenterX - dpToPx(BUBBLE_ARROW_WIDTH) / 2f, height - dpToPx(BUBBLE_ARROW_HEIGHT) - padding);

    path.lineTo(rect.left + roundRectHeight, rect.bottom);
    path.quadTo(rect.left, rect.bottom, rect.left, rect.bottom - roundRectHeight);
    path.lineTo(rect.left, rect.top + roundRectHeight);
    path.quadTo(rect.left, rect.top, rect.left + roundRectHeight, rect.top);
    path.close();

    canvas.drawPath(path, settings.paintBubble);
}
 
Example 17
Project: MyRepository   File: RoundImageView.java   Source Code and License 6 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    Log.e("TAG", "onDraw");
    if (getDrawable() == null) {
        return;
    }
    setUpShader();

    if (type == TYPE_ROUND) {
        canvas.drawRoundRect(mRoundRect, mBorderRadius, mBorderRadius,
                mBitmapPaint);
    } else if (type == TYPE_LEFT_ROUND) {
        float[] radii = {mBorderRadius, mBorderRadius, 0f, 0f, 0f, 0f, mBorderRadius, mBorderRadius};
        Path path = new Path();
        path.addRoundRect(mRoundRect, radii, Path.Direction.CW);
        canvas.drawPath(path, mBitmapPaint);
    } else {
        canvas.drawCircle(mRadius, mRadius, mRadius, mBitmapPaint);
        // drawSomeThing(canvas);
    }
}
 
Example 18
Project: EasyChart   File: EasyGraphLine.java   Source Code and License 6 votes vote down vote up
private void init(int selectedBgColor, float pointStrokeWidth, int pathColor, float pathWidth) {
    pointPaint = new Paint();
    pointPaint.setAntiAlias(true);
    pointPaint.setColor(pointColor);
    pointPaint.setStrokeWidth(pointStrokeWidth);
    pointPaint.setStyle(Paint.Style.STROKE);
    pathPaint = new Paint();
    pathPaint.setAntiAlias(true);
    pathPaint.setColor(pathColor);
    pathPaint.setStrokeWidth(pathWidth);
    pathPaint.setStyle(Paint.Style.STROKE);
    selectedBgPaint = new Paint();
    selectedBgPaint.setAntiAlias(true);
    selectedBgPaint.setColor(selectedBgColor);
    selectedBgPaint.setStrokeWidth(0);
    selectedBgPaint.setStyle(Paint.Style.FILL);
    selectedBgPaint.setAlpha(100);
    path = new Path();
    pathDst = new Path();
    pm = new PathMeasure();
    rectOval = new RectF();
    selectedIndex = -1;
}
 
Example 19
Project: atlas   File: MergePathsContent.java   Source Code and License 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT)
private void mergePaths() {

  switch (mergePaths.getMode()) {
    case Merge:
      supportMergePaths();
      break;
    case Add:
      opFirstPathWithRest(Path.Op.UNION);
      break;
    case Subtract:
      opFirstPathWithRest(Path.Op.REVERSE_DIFFERENCE);
      break;
    case Intersect:
      opFirstPathWithRest(Path.Op.INTERSECT);
      break;
    case ExcludeIntersections:
      opFirstPathWithRest(Path.Op.XOR);
      break;
  }
}
 
Example 20
Project: open-rmbt   File: StaticGraph.java   Source Code and License 6 votes vote down vote up
private StaticGraph(final int color, final float width, final float height, final float strokeWidth)
{
    this.height = height;
    this.width = width;
    
    pathStroke = new Path();
    pathFill = new Path();
    paintStroke = new Paint();
    paintFill = new Paint();
    
    paintStroke.setColor(color);
    paintStroke.setAlpha(204); // 80%
    paintStroke.setStyle(Style.STROKE);
    paintStroke.setStrokeWidth(strokeWidth);
    paintStroke.setStrokeCap(Cap.ROUND);
    paintStroke.setStrokeJoin(Join.ROUND);
    paintStroke.setAntiAlias(true);
    
    paintFill.setColor(color);
    paintFill.setAlpha(51); // 20%
    paintFill.setStyle(Style.FILL);
    paintFill.setAntiAlias(true);
}
 
Example 21
Project: android-dev-challenge   File: TrailedShape.java   Source Code and License 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 22
Project: NovelReader   File: SimulationPageAnim.java   Source Code and License 6 votes vote down vote up
public SimulationPageAnim(int w, int h, View view, OnPageChangeListener listener) {
    super(w, h, view, listener);
    mPath0 = new Path();
    mPath1 = new Path();
    mMaxLength = (float) Math.hypot(mScreenWidth, mScreenHeight);
    mPaint = new Paint();

    mPaint.setStyle(Paint.Style.FILL);

    createDrawable();

    ColorMatrix cm = new ColorMatrix();//设置颜色数组
    float array[] = { 1, 0, 0, 0, 0,
            0, 1, 0, 0, 0,
            0, 0,1, 0, 0,
            0, 0, 0, 1, 0 };
    cm.set(array);
    mColorMatrixFilter = new ColorMatrixColorFilter(cm);
    mMatrix = new Matrix();

    mTouchX = 0.01f; // 不让x,y为0,否则在点计算时会有问题
    mTouchY = 0.01f;
}
 
Example 23
Project: PlayerBase   File: CornerCutView.java   Source Code and License 6 votes vote down vote up
private void drawRightTop(Canvas canvas) {

        // 初始化数据点和控制点的位置
        start.x = mWidth - mCornerRadius;
        start.y = 0;
        end.x = mWidth;
        end.y = mCornerRadius;
        control.x = mWidth;
        control.y = 0;

        Path rightTop = new Path();
        rightTop.moveTo(mWidth,0);
        rightTop.lineTo(mWidth - mCornerRadius,0);
        rightTop.quadTo(control.x,control.y,end.x,end.y);
        rightTop.lineTo(mWidth,0);
        canvas.drawPath(rightTop,mPaint);
    }
 
Example 24
Project: Mire   File: PathBitmapMesh.java   Source Code and License 6 votes vote down vote up
public void matchVertsToPath(Path path, float bottomCoord, float extraOffset) {
    PathMeasure pm = new PathMeasure(path, false);

    for (int i = 0; i < staticVerts.length / 2; i++) {

        float yIndexValue = staticVerts[i * 2 + 1];
        float xIndexValue = staticVerts[i * 2];


        float percentOffsetX = (0.000001f + xIndexValue) / bitmap.getWidth();
        float percentOffsetX2 = (0.000001f + xIndexValue) / (bitmap.getWidth() + extraOffset);
        percentOffsetX2 += pathOffsetPercent;
        pm.getPosTan(pm.getLength() * (1f - percentOffsetX), coords, null);
        pm.getPosTan(pm.getLength() * (1f - percentOffsetX2), coords2, null);

        if (yIndexValue == 0) {
            setXY(drawingVerts, i, coords[0], coords2[1]);
        } else {
            float desiredYCoord = bottomCoord;
            setXY(drawingVerts, i, coords[0], desiredYCoord);

        }
    }
}
 
Example 25
Project: boohee_v5.6   File: ColumnChartRenderer.java   Source Code and License 6 votes vote down vote up
public void drawTargetCaloryLine(Canvas drawCanvas) {
    if (this.targetCalory > 0) {
        float currentLeft = 0.0f;
        float currentRight = 0.0f;
        int target = this.targetCalory;
        Viewport currentViewport = this.computator.getCurrentViewport();
        if (currentViewport != null) {
            currentLeft = currentViewport.left;
            currentRight = currentViewport.right;
        }
        float rawX1 = this.computator.computeRawX(currentLeft);
        float rawX2 = this.computator.computeRawX(currentRight);
        float y = this.computator.computeRawY((float) target);
        Path path1 = new Path();
        path1.moveTo(rawX1, y);
        path1.lineTo(rawX2, y);
        drawCanvas.drawPath(path1, this.caloryLinePaint);
    }
}
 
Example 26
Project: ColumnAnimViewProject   File: RadarView.java   Source Code and License 6 votes vote down vote up
/**
 * 绘制区域
 * @param canvas
 */
private void drawRegion(Canvas canvas){
    Path path = new Path();
    valuePaint.setAlpha(255);
    for(int i=0;i<count;i++){
        double percent = data[i]/maxValue;
        float x = (float) (centerX+radius*Math.cos(angle*i)*percent);
        float y = (float) (centerY+radius*Math.sin(angle*i)*percent);
        if(i==0){
            path.moveTo(x, centerY);
        }else{
            path.lineTo(x,y);
        }
        //绘制小圆点
        canvas.drawCircle(x,y,10,valuePaint);
    }
    valuePaint.setStyle(Paint.Style.STROKE);
    canvas.drawPath(path, valuePaint);
    valuePaint.setAlpha(127);
    //绘制填充区域
    valuePaint.setStyle(Paint.Style.FILL_AND_STROKE);
    canvas.drawPath(path, valuePaint);
}
 
Example 27
Project: GitHub   File: GhostsEyeLoadingRenderer.java   Source Code and License 6 votes vote down vote up
private Path createLeftEyeCircle(RectF arcBounds, float offsetY) {
    Path path = new Path();

    //the center of the left eye
    float leftEyeCenterX = arcBounds.centerX() - mEyeInterval / 2.0f - mEyeCircleRadius;
    float leftEyeCenterY = arcBounds.centerY() + offsetY;
    //the bounds of left eye
    RectF leftEyeBounds = new RectF(leftEyeCenterX - mEyeCircleRadius, leftEyeCenterY - mEyeCircleRadius,
            leftEyeCenterX + mEyeCircleRadius, leftEyeCenterY + mEyeCircleRadius);
    path.addArc(leftEyeBounds, 0, DEGREE_180 + 15);
    //the above radian of of the eye
    path.quadTo(leftEyeBounds.left + mAboveRadianEyeOffsetX, leftEyeBounds.top + mEyeCircleRadius * 0.2f,
            leftEyeBounds.left + mAboveRadianEyeOffsetX / 4.0f, leftEyeBounds.top - mEyeCircleRadius * 0.15f);

    return path;
}
 
Example 28
Project: SphereLayout   File: ElectricView.java   Source Code and License 6 votes vote down vote up
public ElectricView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    mPath = new Path();
    mRandom = new Random();
    mPaint = new Paint();
    mPaint.setColor(0xffffff8e);
    mPaint.setStrokeWidth(3);
    mPaint.setStyle(Paint.Style.STROKE);
    mMaxOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
            getContext().getResources().getDisplayMetrics());
    mStartMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2,
            getContext().getResources().getDisplayMetrics());

    TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ElectricView);
    mElectricCount = typedArray.getInt(R.styleable.ElectricView_electricCount, 1);
    mStartFromRight = typedArray.getInt(R.styleable.ElectricView_startFrom, 0) == 1;
    mDegree = typedArray.getInt(R.styleable.ElectricView_degree, 0);
    typedArray.recycle();
}
 
Example 29
Project: AOSP-Kayboard-7.1.2   File: SetupStartIndicatorView.java   Source Code and License 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 30
Project: GitHub   File: BGAMoocStyleRefreshView.java   Source Code and License 6 votes vote down vote up
private void initCanvas() {
    mOriginalBitmapWidth = mOriginalBitmap.getWidth();
    mOriginalBitmapHeight = mOriginalBitmap.getHeight();

    // 初始状态值
    mWaveOriginalY = mOriginalBitmapHeight;
    mWaveY = 1.2f * mWaveOriginalY;
    mBezierControlOriginalY = 1.25f * mWaveOriginalY;
    mBezierControlY = mBezierControlOriginalY;

    mXfermode = new PorterDuffXfermode(PorterDuff.Mode.SRC_IN);
    mBezierPath = new Path();

    mCanvas = new Canvas();
    mUltimateBitmap = Bitmap.createBitmap(mOriginalBitmapWidth, mOriginalBitmapHeight, Config.ARGB_8888);
    mCanvas.setBitmap(mUltimateBitmap);
}
 
Example 31
Project: Android-Code-Demos   File: SpiderNetView.java   Source Code and License 6 votes vote down vote up
private void drawPointsAndFill(Canvas canvas) {
    Path path = new Path();

    path.moveTo(mUnitPointFs[0].x * mOffsets[0] / 100 * mNetLength,
            mUnitPointFs[0].y * mOffsets[0] / 100 * mNetLength);

    for (int i = 0; i < mUnitPointFs.length; i++) {
        /* draw point */
        canvas.drawPoint(mUnitPointFs[i].x * mOffsets[i] / 100 * mNetLength,
                mUnitPointFs[i].y * mOffsets[i] / 100 * mNetLength,
                mPointPaint);
        /* draw line */
        if (i + 1 != mUnitPointFs.length) {
            path.lineTo(mUnitPointFs[i + 1].x * mOffsets[i + 1] / 100 * mNetLength,
                    mUnitPointFs[i + 1].y * mOffsets[i + 1] / 100 * mNetLength);
        } else {
           path.lineTo(mUnitPointFs[0].x * mOffsets[0] / 100 * mNetLength,
                   mUnitPointFs[0].y * mOffsets[0] / 100 * mNetLength);
        }

    }
    path.close();
    canvas.drawPath(path, mFillPaint);
}
 
Example 32
Project: miaosou   File: BounceBallView.java   Source Code and License 6 votes vote down vote up
private void initData() {

        defaultPadding = 2 * radius + dp2px(2);
        defaultPaddingBottom = 2 * radius + dp2px(15);
        defaultWidth = (int) (2 * defaultPadding + dp2px(200));
        defaultHeight = (int) (defaultPadding + defaultPaddingBottom + dp2px(80));

        paint = new Paint[ballCount];
        for (int i = 0; i < paint.length; i++) {
            paint[i] = new Paint(Paint.ANTI_ALIAS_FLAG);
            paint[i].setColor(ballColor);
            paint[i].setStyle(Paint.Style.FILL);
        }

        path = new Path();
        pathMeasure = new PathMeasure();
        randomBallColors = new int[ballCount];
        randomRadius = new float[ballCount];
        randomTransRatioX = new float[ballCount];
        randomTransRatioY = new float[ballCount];

        translateFraction = new float[ballCount];
        translateAnim = new ValueAnimator[ballCount];

    }
 
Example 33
Project: Depth   File: CircularSplashView.java   Source Code and License 6 votes vote down vote up
public Bitmap GetBitmapClippedCircle(Bitmap bitmap) {

            final int width = bitmap.getWidth();
            final int height = bitmap.getHeight();
            final Bitmap outputBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

            final Path path = new Path();
            path.addCircle(
                    (float) (width / 2)
                    , (float) (height / 2)
                    , (float) Math.min(width, (height / 2))
                    , Path.Direction.CCW);

            final Canvas canvas = new Canvas(outputBitmap);
            canvas.clipPath(path);
            canvas.drawBitmap(bitmap, 0, 0, null);
            bitmap.recycle();
            return outputBitmap;
        }
 
Example 34
Project: Musicoco   File: MarkerDrawable.java   Source Code and License 6 votes vote down vote up
private void computePath(Rect bounds) {
    final float currentScale = mCurrentScale;
    final Path path = mPath;
    final RectF rect = mRect;
    final Matrix matrix = mMatrix;

    path.reset();
    int totalSize = Math.min(bounds.width(), bounds.height());

    float initial = mClosedStateSize;
    float destination = totalSize;
    float currentSize = initial + (destination - initial) * currentScale;

    float halfSize = currentSize / 2f;
    float inverseScale = 1f - currentScale;
    float cornerSize = halfSize * inverseScale;
    float[] corners = new float[]{halfSize, halfSize, halfSize, halfSize, halfSize, halfSize, cornerSize, cornerSize};
    rect.set(bounds.left, bounds.top, bounds.left + currentSize, bounds.top + currentSize);
    path.addRoundRect(rect, corners, Path.Direction.CCW);
    matrix.reset();
    matrix.postRotate(-45, bounds.left + halfSize, bounds.top + halfSize);
    matrix.postTranslate((bounds.width() - currentSize) / 2, 0);
    float hDiff = (bounds.bottom - currentSize - mExternalOffset) * inverseScale;
    matrix.postTranslate(0, hDiff);
    path.transform(matrix);
}
 
Example 35
Project: SmartRefresh   File: MaterialHeader.java   Source Code and License 5 votes vote down vote up
private void initView(Context context, AttributeSet attrs) {
    setMinimumHeight(DensityUtil.dp2px(100));

    mProgress = new MaterialProgressDrawable(context, this);
    mProgress.setBackgroundColor(CIRCLE_BG_LIGHT);
    mProgress.setAlpha(255);
    mProgress.setColorSchemeColors(0xff0099cc,0xffff4444,0xff669900,0xffaa66cc,0xffff8800);
    mCircleView = new CircleImageView(context,CIRCLE_BG_LIGHT);
    mCircleView.setImageDrawable(mProgress);
    mCircleView.setVisibility(View.GONE);
    addView(mCircleView);

    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    mCircleDiameter = (int) (CIRCLE_DIAMETER * metrics.density);

    mBezierPath = new Path();
    mBezierPaint = new Paint();
    mBezierPaint.setAntiAlias(true);
    mBezierPaint.setStyle(Paint.Style.FILL);

    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.MaterialHeader);
    mShowBezierWave = ta.getBoolean(R.styleable.MaterialHeader_mhShowBezierWave, mShowBezierWave);
    mBezierPaint.setColor(ta.getColor(R.styleable.MaterialHeader_mhPrimaryColor, 0xff11bbff));
    if (ta.hasValue(R.styleable.MaterialHeader_mhShadowRadius)) {
        int radius = ta.getDimensionPixelOffset(R.styleable.MaterialHeader_mhShadowRadius, 0);
        int color = ta.getColor(R.styleable.MaterialHeader_mhShadowColor, 0xff000000);
        mBezierPaint.setShadowLayer(radius, 0, 0, color);
        setLayerType(LAYER_TYPE_SOFTWARE, null);
    }
    ta.recycle();

}
 
Example 36
Project: LaunchEnr   File: IconNormalizer.java   Source Code and License 5 votes vote down vote up
/**
 * Returns if the shape of the icon is same as the path.
 * For this method to work, the shape path bounds should be in [0,1]x[0,1] bounds.
 */
private boolean isShape(Path maskPath) {
    // Condition1:
    // If width and height of the path not close to a square, then the icon shape is
    // not same as the mask shape.
    float iconRatio = ((float) mBounds.width()) / mBounds.height();
    if (Math.abs(iconRatio - 1) > BOUND_RATIO_MARGIN) {
        return false;
    }

    // Condition 2:
    // Actual icon (white) and the fitted shape (e.g., circle)(red) XOR operation
    // should generate transparent image, if the actual icon is equivalent to the shape.
    mFileId = mRandom.nextInt();
    mBitmapARGB.eraseColor(Color.TRANSPARENT);
    mCanvasARGB.drawBitmap(mBitmap, 0, 0, mPaintIcon);

    // Fit the shape within the icon's bounding box
    mMatrix.reset();
    mMatrix.setScale(mBounds.width(), mBounds.height());
    mMatrix.postTranslate(mBounds.left, mBounds.top);
    maskPath.transform(mMatrix);

    // XOR operation
    mCanvasARGB.drawPath(maskPath, mPaintMaskShape);

    // DST_OUT operation around the mask path outline
    mCanvasARGB.drawPath(maskPath, mPaintMaskShapeOutline);

    boolean isTrans = isTransparentBitmap(mBitmapARGB);

    // Check if the result is almost transparent
    if (!isTrans) {
        return false;
    }
    return true;
}
 
Example 37
Project: Sprog-App   File: FastScrollPopup.java   Source Code and License 5 votes vote down vote up
public void draw(Canvas canvas) {
    if (isVisible()) {
        // Draw the fast scroller popup
        int restoreCount = canvas.save(Canvas.MATRIX_SAVE_FLAG);
        canvas.translate(mBgBounds.left, mBgBounds.top);
        mTmpRect.set(mBgBounds);
        mTmpRect.offsetTo(0, 0);

        mBackgroundPath.reset();
        mBackgroundRect.set(mTmpRect);

        float[] radii;

        if (Utils.isRtl(mRes)) {
            radii = new float[]{mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius, 0, 0};
        } else {

            radii = new float[]{mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius, 0, 0, mCornerRadius, mCornerRadius};
        }

        mBackgroundPath.addRoundRect(mBackgroundRect, radii, Path.Direction.CW);

        mBackgroundPaint.setAlpha((int) (mAlpha * 255));
        mTextPaint.setAlpha((int) (mAlpha * 255));
        canvas.drawPath(mBackgroundPath, mBackgroundPaint);
        canvas.drawText(mSectionName, (mBgBounds.width() - mTextBounds.width()) / 2,
                mBgBounds.height() - (mBgBounds.height() - mTextBounds.height()) / 2,
                mTextPaint);
        canvas.restoreToCount(restoreCount);
    }
}
 
Example 38
Project: MySelfDemo   File: MyView2.java   Source Code and License 5 votes vote down vote up
/**
 * 用 path 拼接的时候  moveTo 这个参数
 *
 * @param canvas
 */
private void drawPaht4(Canvas canvas) {
    Paint paint = new Paint();
    paint.setColor(Color.BLUE);
    paint.setStyle(Paint.Style.STROKE);
    paint.setAntiAlias(true);
    Path path = new Path();
    path.lineTo(100, 100);
    path.moveTo(200, 100);  //此为移动到某个点上去  用 moveTo可以移动起始点  =此过程不会绘制图形,不过会移动点
    path.lineTo(200, 0);   // lineTo 都是想对于上个点来说的
    canvas.drawPath(path, paint);
}
 
Example 39
Project: Vorolay   File: VoronoiRegion.java   Source Code and License 5 votes vote down vote up
private void initPath() {
    path = new Path();

    for (int i = 0; i < points.size(); i++) {
        VoronoiPoint point = points.get(i);
        if (i == 0) {
            path.moveTo((float)point.x, (float)point.y);
            continue;
        }
        path.lineTo((float)point.x, (float)point.y);
    }

    path.close();
}
 
Example 40
Project: https-github.com-hyb1996-NoRootScriptDroid   File: GlobalActionAutomator.java   Source Code and License 5 votes vote down vote up
private Path pointsToPath(int[][] points) {
    Path path = new Path();
    path.moveTo(scaleX(points[0][0]), scaleY(points[0][1]));
    for (int i = 1; i < points.length; i++) {
        int[] point = points[i];
        path.lineTo(scaleX(point[0]), scaleY(point[1]));
    }
    return path;
}
 
Example 41
Project: WeiXinRecordedDemo   File: TuyaView.java   Source Code and License 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    //绘制之前的线条
    for (int x=0; x<savePathList.size(); x++){
        Path path = savePathList.get(x);
        Paint paint = paintList.get(x);
        canvas.drawPath(path, paint);
    }
    //绘制刚画的线条
    if(touchMode) canvas.drawPath(mPath, mPaint);
}
 
Example 42
Project: PeSanKita-android   File: VerticalSlideColorPicker.java   Source Code and License 5 votes vote down vote up
private void init() {
  setWillNotDraw(false);

  paint = new Paint();
  paint.setStyle(Paint.Style.FILL);
  paint.setAntiAlias(true);

  path = new Path();

  strokePaint = new Paint();
  strokePaint.setStyle(Paint.Style.STROKE);
  strokePaint.setColor(borderColor);
  strokePaint.setAntiAlias(true);
  strokePaint.setStrokeWidth(borderWidth);
}
 
Example 43
Project: RNLearn_Project1   File: AbstractDrawBorder.java   Source Code and License 5 votes vote down vote up
protected final void updatePath(Path path, float correction) {
  path.reset();

  TMP_RECT.set(
      getLeft() + correction,
      getTop() + correction,
      getRight() - correction,
      getBottom() - correction);

  path.addRoundRect(
      TMP_RECT,
      mBorderRadius,
      mBorderRadius,
      Path.Direction.CW);
}
 
Example 44
Project: hsv-alpha-color-picker   File: HueSatView.java   Source Code and License 5 votes vote down vote up
public HueSatView(Context context, AttributeSet attrs) {
	super(context, attrs);

	borderPaint = Resources.makeLinePaint(context);
	pointerPaint = Resources.makeLinePaint(context);
	pointerPaint.setColor(0xff000000);
	pointerPath = Resources.makePointerPath(context);
	borderPath = new Path();
	if (bitmap == null) {
		bitmap = makeBitmap(optimalBitmapSize());
	}
}
 
Example 45
Project: MySelfDemo   File: MyView2.java   Source Code and License 5 votes vote down vote up
/**
 * 这个是画复杂的图形
 * Path 可以描述直线、二次曲线、三次曲线、圆、椭圆、弧形、矩形、圆角矩形。把这些图形结合起来,就可以描述出很多复杂的图形。
 *
 * @param canvas
 */
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void drawPath(Canvas canvas) {
    Paint paint = new Paint();
    paint.setStyle(Paint.Style.FILL);
    paint.setAntiAlias(true);
    paint.setColor(Color.RED);

    // 使用 path 对图形进行描述(这段描述代码不必看懂
    Path path = new Path(); // 初始化 Path 对象
    path.addArc(200, 200, 400, 400, -225, 225);
    path.arcTo(400, 200, 600, 400, -180, 225, false);
    path.lineTo(400, 542);
    canvas.drawPath(path, paint); // 绘制出 path 描述的图形(心形),大功告成
}
 
Example 46
Project: Gauge   File: Gauge.java   Source Code and License 5 votes vote down vote up
private void setNeedle() {
    needlePath.reset();
    needlePath.moveTo(canvasCenterX - needleTailLength, canvasCenterY);
    needlePath.lineTo(canvasCenterX, canvasCenterY - (needleWidth / 2));
    needlePath.lineTo(canvasCenterX + needleLength, canvasCenterY);
    needlePath.lineTo(canvasCenterX, canvasCenterY + (needleWidth / 2));
    needlePath.lineTo(canvasCenterX - needleTailLength, canvasCenterY);
    needlePath.addCircle(canvasCenterX, canvasCenterY, canvasWidth / 49f, Path.Direction.CW);
    needlePath.close();

    needleScrewPaint.setShader(new RadialGradient(canvasCenterX, canvasCenterY, needleWidth / 2,
            Color.DKGRAY, Color.BLACK, Shader.TileMode.CLAMP));
}
 
Example 47
Project: buildAPKsApps   File: CubicLineChart.java   Source Code and License 5 votes vote down vote up
@Override
protected void drawPath(Canvas canvas, List<Float> points, Paint paint, boolean circular) {
  Path p = new Path();
  float x = points.get(0);
  float y = points.get(1);
  p.moveTo(x, y);

  int length = points.size();
  if (circular) {
    length -= 4;
  }

  for (int i = 0; i < length; i += 2) {
    int nextIndex = i + 2 < length ? i + 2 : i;
    int nextNextIndex = i + 4 < length ? i + 4 : nextIndex;
    calc(points, p1, i, nextIndex, secondMultiplier);
    p2.setX(points.get(nextIndex));
    p2.setY(points.get(nextIndex + 1));
    calc(points, p3, nextIndex, nextNextIndex, firstMultiplier);
    // From last point, approaching x1/y1 and x2/y2 and ends up at x3/y3
    p.cubicTo(p1.getX(), p1.getY(), p2.getX(), p2.getY(), p3.getX(), p3.getY());
  }
  if (circular) {
    for (int i = length; i < length + 4; i += 2) {
      p.lineTo(points.get(i), points.get(i + 1));
    }
    p.lineTo(points.get(0), points.get(1));
  }
  canvas.drawPath(p, paint);
}
 
Example 48
Project: JueDiQiuSheng   File: CircleBroodLoadingRenderer.java   Source Code and License 5 votes vote down vote up
private Path createMotherPath() {
    mMotherOvalPath.reset();

    mMotherOvalPath.addOval(new RectF(mMotherPosition[0] - mMotherOvalHalfWidth, mMotherPosition[1] - mMotherOvalHalfHeight,
            mMotherPosition[0] + mMotherOvalHalfWidth, mMotherPosition[1] + mMotherOvalHalfHeight), Path.Direction.CW);

    return mMotherOvalPath;
}
 
Example 49
Project: LandscapeView   File: Tree.java   Source Code and License 5 votes vote down vote up
@Override
public void update() {
    path.reset();
    path.addRect(x - size / 10, y - size / 6, x + size / 10, y + size / 10, Path.Direction.CCW);
    path.moveTo(x - size / 3, y - size / 6);
    path.quadTo(
            x - size / 6, y - size * 7 / 12,
            x + landscapeView.wind, y - size);
    path.quadTo(
            x + size / 6, y - size * 7 / 12,
            x + size / 3, y - size / 6);
    path.close();
}
 
Example 50
Project: android-study   File: XfermodeView.java   Source Code and License 5 votes vote down vote up
private void init() {
  mPaint = new Paint();
  mPaint.setAlpha(0);
  mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
  mPaint.setStyle(Paint.Style.STROKE);
  mPaint.setStrokeJoin(Paint.Join.ROUND);
  mPaint.setStrokeWidth(50);
  mPaint.setStrokeCap(Paint.Cap.ROUND);
  mPath = new Path();
  mBgBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.test4);
  mFgBitmap =
      Bitmap.createBitmap(mBgBitmap.getWidth(), mBgBitmap.getHeight(), Bitmap.Config.ARGB_8888);
  mCanvas = new Canvas(mFgBitmap);
  mCanvas.drawColor(Color.GRAY);
}
 
Example 51
Project: ucar-weex-core   File: BorderDrawable.java   Source Code and License 5 votes vote down vote up
private void prepareBorderPath(int topPadding,
                               int rightPadding,
                               int bottomPadding,
                               int leftPadding,
                               @NonNull RectF rectF,
                               @NonNull Path path) {
  if (mBorderRadius != null) {
    prepareBorderRadius(rectF);
    float topLeftRadius = getBorderRadius(mOverlappingBorderRadius, BORDER_TOP_LEFT_RADIUS);
    float topRightRadius = getBorderRadius(mOverlappingBorderRadius, BORDER_TOP_RIGHT_RADIUS);
    float bottomRightRadius = getBorderRadius(mOverlappingBorderRadius,
                                              BORDER_BOTTOM_RIGHT_RADIUS);
    float bottomLeftRadius = getBorderRadius(mOverlappingBorderRadius,
                                             BORDER_BOTTOM_LEFT_RADIUS);
    path.addRoundRect(
        rectF,
        new float[]{
            topLeftRadius - leftPadding,
            topLeftRadius - topPadding,
            topRightRadius - rightPadding,
            topRightRadius - topPadding,
            bottomRightRadius - rightPadding,
            bottomRightRadius - bottomPadding,
            bottomLeftRadius - leftPadding,
            bottomLeftRadius - bottomPadding
        },
        Path.Direction.CW);
  } else {
    path.addRect(rectF, Path.Direction.CW);
  }
}
 
Example 52
Project: Android-Code-Demos   File: Bezier3View.java   Source Code and License 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    // 绘制数据点和控制点
    mPaint.setColor(Color.GRAY);
    mPaint.setStrokeWidth(10);
    canvas.drawPoint(mStart.x, mStart.y, mPaint);
    canvas.drawPoint(mEnd.x, mEnd.y, mPaint);
    canvas.drawPoint(mControl1.x, mControl1.y, mPaint);
    canvas.drawPoint(mControl2.x, mControl2.y, mPaint);

    // 绘制辅助线
    mPaint.setStrokeWidth(4);
    canvas.drawLine(mStart.x, mStart.y, mControl1.x, mControl1.y, mPaint);
    canvas.drawLine(mControl1.x, mControl1.y, mControl2.x, mControl2.y, mPaint);
    canvas.drawLine(mControl2.x, mControl2.y, mEnd.x, mEnd.y, mPaint);

    // 绘制贝塞尔曲线
    mPaint.setColor(Color.RED);
    mPaint.setStrokeWidth(8);

    Path path = new Path();
    path.moveTo(mStart.x, mStart.y);
    path.cubicTo(mControl1.x, mControl1.y, mControl2.x, mControl2.y, mEnd.x, mEnd.y);

    canvas.drawPath(path, mPaint);
}
 
Example 53
Project: firefox-tv   File: ShiftDrawable.java   Source Code and License 5 votes vote down vote up
private void updateBounds() {
    final Rect b = getBounds();
    final int width = (int) ((float) b.width() * getLevel() / MAX_LEVEL);
    final float radius = b.height() / 2f;
    mVisibleRect.set(b.left, b.top, b.left + width, b.height());

    // draw round to head of progressbar. I know it looks stupid, don't blame me now.
    mPath = new Path();
    mPath.addRect(b.left, b.top, b.left + width - radius, b.height(), Path.Direction.CCW);
    mPath.addCircle(b.left + width - radius, radius, radius, Path.Direction.CCW);
}
 
Example 54
Project: ThunderMusic   File: ColorPicker.java   Source Code and License 5 votes vote down vote up
private void init() {

        colorPointerPaint = new Paint();
        colorPointerPaint.setStyle(Style.STROKE);
        colorPointerPaint.setStrokeWidth(2f);
        colorPointerPaint.setARGB(128, 0, 0, 0);

        valuePointerPaint = new Paint();
        valuePointerPaint.setStyle(Style.STROKE);
        valuePointerPaint.setStrokeWidth(2f);

        valuePointerArrowPaint = new Paint();

        colorWheelPaint = new Paint();
        colorWheelPaint.setAntiAlias(true);
        colorWheelPaint.setDither(true);

        valueSliderPaint = new Paint();
        valueSliderPaint.setAntiAlias(true);
        valueSliderPaint.setDither(true);

        colorViewPaint = new Paint();
        colorViewPaint.setAntiAlias(true);

        colorViewPath = new Path();
        valueSliderPath = new Path();
        arrowPointerPath = new Path();

        outerWheelRect = new RectF();
        innerWheelRect = new RectF();

        colorPointerCoords = new RectF();

    }
 
Example 55
Project: microMathematics   File: SVGAndroidRenderer.java   Source Code and License 5 votes vote down vote up
private void addObjectToClip(SVG.GraphicsElement obj, Path combinedPath,
		Matrix combinedPathMatrix) {
	updateStyleForElement(state, obj);

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

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

	Path path;
	if (obj instanceof SVG.Rect)
		path = makePathAndBoundingBox((SVG.Rect) obj);
	else if (obj instanceof SVG.Circle)
		path = makePathAndBoundingBox((SVG.Circle) obj);
	else if (obj instanceof SVG.Ellipse)
		path = makePathAndBoundingBox((SVG.Ellipse) obj);
	else if (obj instanceof SVG.PolyLine)
		path = makePathAndBoundingBox((SVG.PolyLine) obj);
	else
		return;

	checkForClipPath(obj);

	combinedPath.setFillType(path.getFillType());
	combinedPath.addPath(path, combinedPathMatrix);
}
 
Example 56
Project: atlas   File: ShapeContent.java   Source Code and License 5 votes vote down vote up
@Override public Path getPath() {
  if (isPathValid) {
    return path;
  }

  path.reset();

  path.set(shapeAnimation.getValue());
  path.setFillType(Path.FillType.EVEN_ODD);

  Utils.applyTrimPathIfNeeded(path, trimPath);

  isPathValid = true;
  return path;
}
 
Example 57
Project: GitHub   File: RoundedCornersDrawable.java   Source Code and License 5 votes vote down vote up
private void updatePath() {
  mPath.reset();
  mBorderPath.reset();
  mTempRectangle.set(getBounds());

  mTempRectangle.inset(mPadding, mPadding);
  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 58
Project: BezierView   File: StarViewGroup.java   Source Code and License 5 votes vote down vote up
/**
 * 进行一些初始化的操作
 */
private void initView() {
    //初始化画笔,路径
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setStrokeWidth(8);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setColor(Color.BLACK);
    mPath = new Path();
    mRandom = new Random();
    //获取资源图片转化Bitmap(不可修改)
    mBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.icon_star);

    setOnClickListener(this);
}
 
Example 59
Project: BookPage   File: BookPageView.java   Source Code and License 5 votes vote down vote up
/**
 * 绘制B区域内容
 * @param canvas
 * @param pathA
 */
private void drawPathBContent(Canvas canvas, Path pathA){
    canvas.save();
    canvas.clipPath(pathA);//裁剪出A区域
    canvas.clipPath(getPathC(),Region.Op.UNION);//裁剪出A和C区域的全集
    canvas.clipPath(getPathB(), Region.Op.REVERSE_DIFFERENCE);//裁剪出B区域中不同于与AC区域的部分
    canvas.drawBitmap(pathBContentBitmap, 0, 0, null);

    drawPathBShadow(canvas);
    canvas.restore();
}
 
Example 60
Project: SmileyRating   File: BaseRating.java   Source Code and License 5 votes vote down vote up
private Path cube(Path path, Point[] curve) {
    path.cubicTo(
            curve[0].x, curve[0].y,
            curve[1].x, curve[1].y,
            curve[2].x, curve[2].y
    );
    return path;
}