content: package com.github.cjj.library.core;
  
  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 cjj on 2015/8/5.
   * 绘制贝塞尔来绘制波浪形
   */
  public class WaveView extends View {
      private int waveHeight;
      private int headHeight;
      private Path path;
      private Paint paint;
      private int color;
  
      public WaveView(Context context) {
          this(context, null, 0);
      }
  
      public WaveView(Context context, AttributeSet attrs) {
          this(context, attrs, 0);
      }
  
      public WaveView(Context context, AttributeSet attrs, int defStyleAttr) {
          super(context, attrs, defStyleAttr);
          init();
      }
  
      private void init() {
          path = new Path();
          paint = new Paint();
          paint.setColor(Color.argb(150, 43, 43, 43));
          paint.setAntiAlias(true);
      }
  
      public void setColor(int color) {
          this.color = color;
          paint.setColor(color);
          invalidate();
      }
  
      public int getHeadHeight() {
          return headHeight;
      }
  
      public void setHeadHeight(int headHeight) {
          this.headHeight = headHeight;
      }
  
      public int getWaveHeight() {
          return waveHeight;
      }
  
      public void setWaveHeight(int waveHeight) {
          this.waveHeight = waveHeight;
      }
  
  
      @Override
      protected void onDraw(Canvas canvas) {
          super.onDraw(canvas);
          //重置画笔
          path.reset();
          path.lineTo(0, headHeight);
          //绘制贝塞尔曲线
          path.quadTo(getMeasuredWidth() / 2, headHeight + waveHeight, getMeasuredWidth(), headHeight);
          path.lineTo(getMeasuredWidth(), 0);
          canvas.drawPath(path, paint);
      }
  
  }
  