package com.innofang.viewsdemo.views;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * Author: Inno Fang
 * Time: 2017/4/23 10:49
 * Description:
 */


public class SpiderNetView extends View {

    private Paint mPaint = new Paint();
    private int mWidth, mHeight, mNetLength, mNetSegment;

    public SpiderNetView(Context context) {
        this(context, null);
    }

    public SpiderNetView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);

        mPaint.setStrokeWidth(8);
        mPaint.setAntiAlias(true);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setColor(Color.BLACK);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        mWidth = w;
        mHeight = h;
        mNetLength = Math.min(mWidth, mHeight) - 50;
        mNetSegment = mNetLength / 3;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.translate(mWidth / 2, mHeight / 2);
        canvas.scale(1, -1);
        drawNet(canvas);
    }

    private void drawNet(Canvas canvas) {
        canvas.save();
        for (int i = 0; i < 360; i+=45) {
            canvas.drawLine(0, 0, 0, mNetLength, mPaint);
            canvas.drawLine(0,mNetSegment - 20, mNetLength - 20, mNetLength - 20, mPaint);
            canvas.drawLine(0,mNetSegment, mNetLength, mNetLength, mPaint);
            canvas.drawLine(0,mNetSegment + 20, mNetLength + 20, mNetLength + 20, mPaint);
            canvas.rotate(45);
        }
        canvas.restore();
    }
}

@@ -397,16 +397,19 @@
  Paint m
+Net
 Paint = 
@@ -417,24 +417,24 @@
 ew Paint();%0A
-
     private 
@@ -667,32 +667,35 @@
 trs);%0A%0A        m
+Net
 Paint.setStrokeW
@@ -703,9 +703,9 @@
 dth(
-8
+5
 );%0A 
@@ -704,32 +704,35 @@
 th(5);%0A        m
+Net
 Paint.setAntiAli
@@ -742,32 +742,35 @@
 true);%0A        m
+Net
 Paint.setStyle(P
@@ -798,16 +798,19 @@
        m
+Net
 Paint.se
@@ -826,13 +826,12 @@
 lor.
-BLACK
+GRAY
 );%0A 
@@ -1058,11 +1058,16 @@
 ht) 
-- 5
+/ 2 - 12
 0;%0A 
@@ -1100,17 +1100,21 @@
 ength / 
-3
+4 - 8
 ;%0A    %7D%0A
@@ -1374,24 +1374,248 @@
 vas.save();%0A
+        float sqrt2div2 = (float) (Math.sqrt(2) / 2.0);%0A        float seg1 = mNetSegment - 30;%0A        float seg2 = mNetSegment * 2 - 20;%0A        float seg3 = mNetSegment * 3 + 20;%0A        float seg4 = mNetSegment * 4 + 30;%0A
         for 
@@ -1640,10 +1640,12 @@
 0; i
+ 
 +=
+ 
 45) 
@@ -1688,32 +1688,35 @@
 0, mNetLength, m
+Net
 Paint);%0A        
@@ -1741,228 +1741,310 @@
 e(0,
-mNetSegment - 20, mNetLength - 20, mNetLength - 20, mPaint);%0A            canvas.drawLine(0,mNetSegment, mNetLength, mNetLength, mPaint);%0A            canvas.drawLine(0,mNetSegment + 20, mNetLength + 20, mNetLength + 20, m
+ seg1, seg1 * sqrt2div2, seg1 * sqrt2div2, mNetPaint);%0A            canvas.drawLine(0, seg2, seg2 * sqrt2div2, seg2 * sqrt2div2, mNetPaint);%0A            canvas.drawLine(0, seg3, seg3 * sqrt2div2, seg3 * sqrt2div2, mNetPaint);%0A            canvas.drawLine(0, seg4, seg4 * sqrt2div2, seg4 * sqrt2div2, mNet
 Pain

update ViewsDemo(fix SpiderNetView Bugs)