package com.jpardogo.android.flabbylistview.lib;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.Region;
import android.util.AttributeSet;
import android.view.Gravity;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.Random;

public class FlabbyLayout extends FrameLayout {
    private static final float MAX_CURVATURE = 100;
    private Path mPath;
    private Paint mPaint;
    private Rect mRect;
    private float mDeltaY = 0;
    private float mCurvature;
    private int mWidth;
    private int mHeight;
    private int mOneFifthWidth;
    private int mFourFifthWith;
    private TextView mTextView;

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

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

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

    private void init(Context context) {
        setWillNotDraw(false);
        mPath = new Path();
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPaint.setStyle(Paint.Style.FILL);
        mTextView = new TextView(context);
        mTextView.setGravity(Gravity.CENTER);
        addView(mTextView);
    }

    @Override
    protected void onDraw(final Canvas canvas) {
        if(mWidth==0) mWidth = getWidth();
        if(mHeight==0) mHeight = getHeight();
        if(mOneFifthWidth ==0) mOneFifthWidth = mWidth / 5;
        if(mFourFifthWith ==0) mFourFifthWith = mOneFifthWidth * 4;

        mRect = canvas.getClipBounds();
        mRect.inset(0, -mHeight / 2);
        canvas.clipRect(mRect, Region.Op.REPLACE);

        if (mDeltaY > -MAX_CURVATURE && mDeltaY < MAX_CURVATURE) mCurvature = mDeltaY * 2 * -1;
        canvas.drawPath(makeFlabberPath(), mPaint);
    }

    private Path makeFlabberPath() {
        mPath.reset();
        mPath.moveTo(0, 0);
        mPath.cubicTo(mOneFifthWidth, -mCurvature, mFourFifthWith, -mCurvature, mWidth, 0);
        mPath.lineTo(mWidth, mHeight);
        mPath.cubicTo(mFourFifthWith, mHeight - mCurvature, mOneFifthWidth, mHeight - mCurvature, 0, mHeight);
        mPath.lineTo(0, 0);
        return mPath;
    }

    public void updateControlPoints(float deltaY) {
        mTextView.setText("DeltaY: " + deltaY);
        mDeltaY = deltaY;
        invalidate();
    }

    public void setFlabbyColor(int color) {
        mPaint.setColor(color);
    }
}
@@ -111,39 +111,8 @@
 as;%0A
-import android.graphics.Color;%0A
 impo
@@ -138,16 +138,16 @@
 .Paint;%0A
+
 import a
@@ -268,37 +268,8 @@
 et;%0A
-import android.view.Gravity;%0A
 impo
@@ -302,102 +302,8 @@
 out;
-%0Aimport android.widget.LinearLayout;%0Aimport android.widget.TextView;%0A%0Aimport java.util.Random;
 %0A%0Apu
@@ -651,40 +651,8 @@
 ith;
-%0A    private TextView mTextView;
 %0A%0A  
@@ -1224,125 +1224,8 @@
 L);%0A
-        mTextView = new TextView(context);%0A        mTextView.setGravity(Gravity.CENTER);%0A        addView(mTextView);%0A
     
@@ -2172,32 +2172,32 @@
 n mPath;%0A    %7D%0A%0A
+
     public void 
@@ -2236,56 +2236,8 @@
 ) %7B%0A
-        mTextView.setText(%22DeltaY: %22 + deltaY);%0A
     

Remove textView for delta data