package com.msapps.smilyrating;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by sujith on 11/10/16.
 */
public class RatingView extends View {

    private static final String TAG = "RatingView";

    private Paint mPathPaint = new Paint();
    private Paint mPointPaint = new Paint();
    private Path mDrawingPath = new Path();

    public RatingView(Context context) {
        super(context);
        init();
    }

    public RatingView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public RatingView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
//        mPathPaint.setStrokeWidth(3);
        mPathPaint.setColor(Color.RED);
        mPathPaint.setStyle(Paint.Style.FILL);

        mPointPaint.setColor(Color.BLACK);
        mPointPaint.setStyle(Paint.Style.FILL);

        refreshPath();
    }

    private void refreshPath() {
        mDrawingPath.reset();
        mDrawingPath.moveTo(50, 50);
        mDrawingPath.cubicTo(100, 100, 150, 100, 200, 50);
        mDrawingPath.close();
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        setMeasuredDimension(400, 400);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawPath(mDrawingPath, mPathPaint);
        canvas.drawCircle(50, 50, 5, mPointPaint);
        canvas.drawCircle(100, 100, 5, mPointPaint);
        canvas.drawCircle(150, 100, 5, mPointPaint);
        canvas.drawCircle(200, 50, 5, mPointPaint);
    }
}

@@ -447,24 +447,71 @@
  mPointPaint
+1 = new Paint();%0A    private Paint mPointPaint2
  = new Paint
@@ -939,10 +939,8 @@
 ) %7B%0A
-//
     
@@ -1076,24 +1076,25 @@
  mPointPaint
+1
 .setColor(Co
@@ -1120,24 +1120,25 @@
  mPointPaint
+1
 .setStyle(Pa
@@ -1147,32 +1147,125 @@
 t.Style.FILL);%0A%0A
+        mPointPaint2.setColor(Color.GREEN);%0A        mPointPaint2.setStyle(Paint.Style.FILL);%0A
         refreshP
@@ -1337,24 +1337,25 @@
 th.reset();%0A
+%0A
         mDra
@@ -1374,76 +1374,349 @@
 eTo(
-50, 50);%0A        mDrawingPath.cubicTo(100, 100, 150, 1
+100, 500);%0A        // top curve%0A        mDrawingPath.cubicTo(150, 500, 350, 500, 400, 500);%0A        //Right curve%0A        mDrawingPath.cubicTo(450, 500, 450, 550, 400, 550);%0A%0A        // bottom curve%0A        mDrawingPath.cubicTo(350, 550, 150, 550, 100, 550);%0A%0A        // Left curve%0A        mDrawingPath.cubicTo(50, 550, 50, 5
 00, 
-2
+1
 00, 50
+0
 );%0A
+%0A
     
@@ -1904,47 +1904,8 @@
 c);%0A
-        setMeasuredDimension(400, 400);
 %0A   
@@ -1991,24 +1991,63 @@
 aw(canvas);%0A
+        canvas.clipPath(mDrawingPath);%0A
         canv
@@ -2093,217 +2093,9 @@
     
-    canvas.drawCircle(50, 50, 5, mPointPaint);%0A        canvas.drawCircle(100, 100, 5, mPointPaint);%0A        canvas.drawCircle(150, 100, 5, mPointPaint);%0A        canvas.drawCircle(200, 50, 5, mPointPaint);%0A    
 %7D
+%0A
 %0A%7D%0A

Create a full filled capsule shape