Pro20Activity.java
package ps.pro20;
import android.app.Activity;
import android.os.Bundle;
public class Pro20Activity extends Activity {
/**
* www.master-gtu.blogspot.com
* pankaj sharma(8460479175),
* chavda vijay(8460420769)
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new ScreenActivity(this));
}
}
ScreenActivity.java
package ps.pro20;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.view.MotionEvent;
import android.view.View;
public class ScreenActivity extends View
{
/**
* www.master-gtu.blogspot.com
* pankaj sharma(8460479175),
* chavda vijay(8460420769)
*/
Paint paintBrush=new Paint(Paint.ANTI_ALIAS_FLAG);
Path path=new Path();
public ScreenActivity(Context context) {
super(context);
paintBrush.setColor(Color.RED);
paintBrush.setStrokeWidth(5);
paintBrush.setStyle(Paint.Style.STROKE);
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
canvas.drawPath(path, paintBrush);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
super.onTouchEvent(event);
//------getting position-------
float x=event.getX();
float y=event.getY();
switch(event.getAction())
{
case MotionEvent.ACTION_DOWN:
path.moveTo(x, y);
return true;
case MotionEvent.ACTION_MOVE:
path.lineTo(x, y);
break;
}
invalidate();
return true;
}
}
No comments:
Post a Comment