Custom drawing view with tools
-
Hi, i need a little help. I'm creating my custom Drawing View. The functionality I am trying to achieve is: Arrow icon => touch one point and drag until other point draws line-arrow Text icon => touch in one point of screen and enter a text (open keyboard and write and close it) Eraser icon => erase canvas drawn These is the design of the menu I've made: TOOLS MENU And all interface is here: INTERFACE How can I edit my custom drawing view for make tools specified above? Whick portion of code will I put inside CustomDrawingView class? Here my DrawingView class:
public class DrawingView extends View
{
private Path mDrawPath;
private Paint mBackgroundPaint;
private Paint mDrawPaint;
private Canvas mDrawCanvas;
private Bitmap mCanvasBitmap;private ArrayList mPaths = new ArrayList<>(); private ArrayList mPaints = new ArrayList<>(); private ArrayList mUndonePaths = new ArrayList<>(); private ArrayList mUndonePaints = new ArrayList<>(); // Set default values private int mBackgroundColor = 0x00FFFFFF; private int mPaintColor = 0x00660000; private int mStrokeWidth = 10; public DrawingView(Context context, AttributeSet attrs) { super(context, attrs); init(); } private void init() { mDrawPath = new Path(); mBackgroundPaint = new Paint(); initPaint(); } private void initPaint() { mDrawPaint = new Paint(); mDrawPaint.setColor(mPaintColor); mDrawPaint.setAntiAlias(true); mDrawPaint.setStrokeWidth(mStrokeWidth); mDrawPaint.setStyle(Paint.Style.STROKE); mDrawPaint.setStrokeJoin(Paint.Join.ROUND); mDrawPaint.setStrokeCap(Paint.Cap.ROUND); } private void drawBackground(Canvas canvas) { mBackgroundPaint.setColor(Color.TRANSPARENT); mBackgroundPaint.setAntiAlias(true); mBackgroundPaint.setAlpha(0); canvas.drawRect(0, 0, this.getWidth(), this.getHeight(), mBackgroundPaint); } private void drawPaths(Canvas canvas) { int i = 0; for (Path p : mPaths) { canvas.drawPath(p, mPaints.get(i)); i++; } } @Override protected void onDraw(Canvas canvas) { drawBackground(canvas);
-
Hi, i need a little help. I'm creating my custom Drawing View. The functionality I am trying to achieve is: Arrow icon => touch one point and drag until other point draws line-arrow Text icon => touch in one point of screen and enter a text (open keyboard and write and close it) Eraser icon => erase canvas drawn These is the design of the menu I've made: TOOLS MENU And all interface is here: INTERFACE How can I edit my custom drawing view for make tools specified above? Whick portion of code will I put inside CustomDrawingView class? Here my DrawingView class:
public class DrawingView extends View
{
private Path mDrawPath;
private Paint mBackgroundPaint;
private Paint mDrawPaint;
private Canvas mDrawCanvas;
private Bitmap mCanvasBitmap;private ArrayList mPaths = new ArrayList<>(); private ArrayList mPaints = new ArrayList<>(); private ArrayList mUndonePaths = new ArrayList<>(); private ArrayList mUndonePaints = new ArrayList<>(); // Set default values private int mBackgroundColor = 0x00FFFFFF; private int mPaintColor = 0x00660000; private int mStrokeWidth = 10; public DrawingView(Context context, AttributeSet attrs) { super(context, attrs); init(); } private void init() { mDrawPath = new Path(); mBackgroundPaint = new Paint(); initPaint(); } private void initPaint() { mDrawPaint = new Paint(); mDrawPaint.setColor(mPaintColor); mDrawPaint.setAntiAlias(true); mDrawPaint.setStrokeWidth(mStrokeWidth); mDrawPaint.setStyle(Paint.Style.STROKE); mDrawPaint.setStrokeJoin(Paint.Join.ROUND); mDrawPaint.setStrokeCap(Paint.Cap.ROUND); } private void drawBackground(Canvas canvas) { mBackgroundPaint.setColor(Color.TRANSPARENT); mBackgroundPaint.setAntiAlias(true); mBackgroundPaint.setAlpha(0); canvas.drawRect(0, 0, this.getWidth(), this.getHeight(), mBackgroundPaint); } private void drawPaths(Canvas canvas) { int i = 0; for (Path p : mPaths) { canvas.drawPath(p, mPaints.get(i)); i++; } } @Override protected void onDraw(Canvas canvas) { drawBackground(canvas);
My first suggestion would be to trim your code down to just the absolute minimum needed to reproduce the problem. Everything else is just extra noise getting in the way. People here don't mind helping at all, but they can't be expected to wade through a bunch of code that only you understand. Have you tried using different colors for text and background? Have you tried drawing on the
DrawingView
canvas itself instead of the canvas that is created from within theonSizeChanged()
method? Have you tried stepping through the code using the debugger?"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
My first suggestion would be to trim your code down to just the absolute minimum needed to reproduce the problem. Everything else is just extra noise getting in the way. People here don't mind helping at all, but they can't be expected to wade through a bunch of code that only you understand. Have you tried using different colors for text and background? Have you tried drawing on the
DrawingView
canvas itself instead of the canvas that is created from within theonSizeChanged()
method? Have you tried stepping through the code using the debugger?"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
The usual answer. Thanks. Cris
-
The usual answer. Thanks. Cris
I do wonder what your expectation is when posting such a request, from volunteers! You seem to expect someone to go through your entire program and basically mentor you to get what you want to achieve. You don't post any error, there is no indication where the problem lies, just the entire code with a set of design requirements. So you should not expect anything but
the usual answer
. This implies that you have posted such requests before, it seems you do not learn fromthe usual answer
!Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP