We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,254 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Need help with drawing on surface view in for android

I would like to create a notebook type application that will accept touch input and allow you to draw on the surface view. I'm unsure what I'm doing wrong since I have not programmed for the Android before.

Here is what I have:

findViewById(R.id.pageSurface).setOnTouchListener(new View.OnTouchListener() {

			public boolean onTouch(View v, MotionEvent event) {
				SurfaceHolder holder = ((SurfaceView)findViewById(R.id.pageSurface)).getHolder();
				Canvas canvas = holder.lockCanvas();
				Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
				
				paint.setColor(Color.BLACK);
				paint.setDither(true); 
				paint.setColor(0xFFFFFF00);
				paint.setStyle(Paint.Style.STROKE);
				paint.setStrokeJoin(Paint.Join.ROUND);
				paint.setStrokeCap(Paint.Cap.ROUND);
				paint.setStrokeWidth(3);
				
				canvas.drawPoint(event.getX(), event.getY(), paint);
				holder.unlockCanvasAndPost(canvas);
return true;
				
			}
    	});
    }
1
Contributor
2
Replies
2 Hours
Discussion Span
1 Year Ago
Last Updated
3
Views
Question
Answered
woodenduck
Newbie Poster
23 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I would like to create a notebook type application that will accept touch input and allow you to draw on the surface view. I'm unsure what I'm doing wrong since I have not programmed for the Android before.

Here is what I have:

findViewById(R.id.pageSurface).setOnTouchListener(new View.OnTouchListener() {

			public boolean onTouch(View v, MotionEvent event) {
				SurfaceHolder holder = ((SurfaceView)findViewById(R.id.pageSurface)).getHolder();
				Canvas canvas = holder.lockCanvas();
				Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
				
				paint.setColor(Color.BLACK);
				paint.setDither(true); 
				paint.setColor(0xFFFFFF00);
				paint.setStyle(Paint.Style.STROKE);
				paint.setStrokeJoin(Paint.Join.ROUND);
				paint.setStrokeCap(Paint.Cap.ROUND);
				paint.setStrokeWidth(3);
				
				canvas.drawPoint(event.getX(), event.getY(), paint);
				holder.unlockCanvasAndPost(canvas);
return true;
				
			}
    	});
    }

This code actually will draw it turns out I cant have findViewById(R.id.pageSurface).setBackgroundColor(Color.WHITE); set outside of this method or it will cause the page to remain white...

woodenduck
Newbie Poster
23 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I still need help to make the line solid. I get a dotted line that is spaced apart based on how fast I move my finger. Is there a way to continue drawing and updating dots while my finger is down?

woodenduck
Newbie Poster
23 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Self-Answered as of 1 Year Ago

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0699 seconds using 2.78MB