Last active
April 30, 2019 08:46
-
-
Save raviteja83/6d907d200179783c9718553faa759aea to your computer and use it in GitHub Desktop.
sinewave
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.annotation.TargetApi; | |
import android.content.Context; | |
import android.graphics.Canvas; | |
import android.graphics.Paint; | |
import android.graphics.Path; | |
import android.graphics.RectF; | |
import android.os.Build; | |
import android.util.AttributeSet; | |
import android.view.View; | |
/** | |
* Created by rt12148 on 14/8/16. | |
**/ | |
public class SineView extends View { | |
Path path = new Path(); | |
RectF rect = new RectF(); | |
public SineView(Context context) { | |
super(context); | |
} | |
public SineView(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
} | |
public SineView(Context context, AttributeSet attrs, int defStyleAttr) { | |
super(context, attrs, defStyleAttr); | |
} | |
@TargetApi(Build.VERSION_CODES.LOLLIPOP) | |
public SineView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { | |
super(context, attrs, defStyleAttr, defStyleRes); | |
} | |
@Override | |
protected void onSizeChanged(int w, int h, int oldw, int oldh) { | |
super.onSizeChanged(w, h, oldw, oldh); | |
rect = new RectF(0,0,w,h); | |
} | |
@Override | |
protected void onDraw(Canvas canvas) { | |
super.onDraw(canvas); | |
setUp(canvas); | |
} | |
private void setUp(Canvas canvas) { | |
path.moveTo(rect.left,rect.centerY()); | |
path.quadTo(rect.left + 50, rect.top, rect.left+ 100, rect.centerY()); | |
path.quadTo(rect.left + 150, rect.bottom, rect.left+ 200, rect.centerY()); | |
path.quadTo(rect.left + 250, rect.top, rect.left+ 300, rect.centerY()); | |
path.quadTo(rect.left + 350, rect.bottom, rect.left+ 400, rect.centerY()); | |
path.quadTo(rect.left + 450, rect.top, rect.left+ 500, rect.centerY()); | |
Paint paint = new Paint(); | |
paint.setStyle(Paint.Style.STROKE); | |
canvas.drawPath(path,paint); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment