I've done a project using FingerPaint.
You could look at it : https://github.com/jrm2k6/ElectronicCalendar
Best,
On Oct 31, 9:56 pm, Hassy <hasith....@gmail.com> wrote:
> Hello,
>
> I'm trying to create a finger paint application using surfaceview.
> I have tried and able to paint on the screen using view but when I use
> surfaceview
> ,I can't draw on the screen.
>
> can anybody tell me how to solve this problem.
>
> CODE
>
> Main Activity
>
> public class MainAct extends Activity {
> DrawView drawView;
> @Override
> public void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> // Set full screen view
>
> getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
> WindowManager.LayoutParams.FLAG_FULLSCREEN);
> requestWindowFeature(Window.FEATURE_NO_TITLE);
>
> drawView = new DrawView(this);
> setContentView(drawView);
> drawView.requestFocus();
> }
>
> }
>
> DrawView.class
>
> public class DrawView extends SurfaceView implements
> SurfaceHolder.Callback{
> private static final String TAG = "DrawView";
>
> List<Point> points = new ArrayList<Point>();
> Paint paint = new Paint();
> Thread mainLoop = null;
>
> public DrawView(Context context) {
> super(context);
>
> getHolder().addCallback(this);
> setFocusable(true);
> setFocusableInTouchMode(true);
> paint.setAntiAlias(true);
> paint.setColor(Color.WHITE);
> paint.setAntiAlias(true);
> }
> public void doDraw(){
> Canvas canvas = getHolder().lockCanvas();
> canvas.drawColor(Color.BLACK);
> canvas.drawCircle(50, 50, 50, paint);
> for (Point point : points) {
> canvas.drawCircle(point.x, point.y, 25, paint);
> // Log.d(TAG, "Painting: "+point);
>
> }
> getHolder().unlockCanvasAndPost(canvas);
> }
>
> @Override
> public void surfaceChanged(SurfaceHolder holder, int format, int
> width,
> int height) {
> // TODO Auto-generated method stub
>
> }
>
> @Override
> public void surfaceCreated(SurfaceHolder holder) {
> // TODO Auto-generated method stub
> Log.d(getClass().getName(), "surfaceCreated");
> doDraw();
> }
>
> @Override
> public void surfaceDestroyed(SurfaceHolder holder) {
> // TODO Auto-generated method stub
>
> }
> @Override
> public boolean onTouchEvent(MotionEvent event) {
> // if(event.getAction() != MotionEvent.ACTION_DOWN)
> //return super.onTouchEvent(event);
> Point point = new Point();
> point.x = event.getX();
> point.y = event.getY();
> points.add(point);
> Log.d(TAG, "point: " + point);
> return super.onTouchEvent(event);
> }
> }
>
> class Point {
> float x, y;
>
> @Override
> public String toString() {
> return x + ", " + y;
> }
> }
>
> Thank you
> Hassy
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
No comments:
Post a Comment