Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Change your code like this....</p> <pre><code>public MyView(Context context, Object object) { super(context); setFocusable(true); setFocusableInTouchMode(true); mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setColor(0xFFFFFF00); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(3); mCanvas = new Canvas(); mPath = new Path(); mBitmap = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_8888); mCanvas = new Canvas(mBitmap); selectedcolor=context.getResources().getColor(com.example.videoapp.R.color.red); } protected void onDraw(Canvas canvas) { canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); for (Path p : paths) { mPaint.setColor(colorsMap.get(p)); canvas.drawPath(p, mPaint); } mPaint.setColor(selectedcolor); canvas.drawPath(mPath, mPaint); } </code></pre> <p>In ontouch event..</p> <p>ACTION_DOWN:</p> <pre><code>undonePaths.clear(); mPath.reset(); mPath.moveTo(x, y); mX = x; mY = y; invalidate(); </code></pre> <p>ACTION_MOVE:</p> <pre><code>float dx = Math.abs(x - mX); float dy = Math.abs(y - mY); if (dx &gt;= TOUCH_TOLERANCE || dy &gt;= TOUCH_TOLERANCE) { mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2); mX = x; mY = y; } invalidate(); </code></pre> <p>ACTION_UP:</p> <pre><code>mPath.lineTo(mX, mY); paths.add(mPath); colorsMap.put(mPath,selectedcolor); mPath = new Path(); mPath.reset(); invalidate(); </code></pre> <p>Dont put this paths.add(mPath) in context and oncreate also...</p> <pre><code> public MyView(Context context, Object object) { super(context); // paths.add(mPath); // Dont put this line... } </code></pre> <p>Undo and Redo....</p> <pre><code> undo.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if(MyView.paths.size()&gt; 0) { MyView.undonePaths.add(MyView.paths.remove(MyView.paths.size() - 1)); mview.invalidate(); } } }); redo.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (MyView.undonePaths.size()&gt;0) { MyView.paths.add(MyView.undonePaths.remove(MyView.undonePaths.size()-1)); mview.invalidate(); } } }); </code></pre> <p>I hope this code is really veryuseful to u.. all the best</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload