title: Android - Save path and draw later
body: <p>I'm using the following code to get a touch event, draw the path and store it on an ArrayList and it is working.</p>
  
  <pre><code>@Override
  public boolean onTouchEvent(MotionEvent event) {
      float touchX = event.getX();
      float touchY = event.getY();
  
      switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
          drawPath.moveTo(touchX, touchY);
          break;
      case MotionEvent.ACTION_MOVE:
          drawPath.lineTo(touchX, touchY);
          drawCanvas.drawPath(drawPath, drawPaint);
          paths.add(drawPath);
          drawPath.reset();
          drawPath.moveTo(touchX, touchY);
          break;
      case MotionEvent.ACTION_UP:
          drawCanvas.drawPath(drawPath, drawPaint);
          paths.add(drawPath);
          drawPath.reset();
          break;
      default:
          return false;
      }
  
      invalidate();
      return true;
  }
  </code></pre>
  
  <p>After I want to draw it again but with a diferent color and it doesn't work. If I create the path, as commented, it works :s</p>
  
  <pre><code>public void printPath(){
  
      Path testePath = new Path();
      //testePath.moveTo(0, 0);
      //testePath.lineTo(300, 300);
  
      Paint testePaint = new Paint();
      testePaint.setColor(0xFF00FF00);
      testePaint.setAntiAlias(true);
      testePaint.setStrokeWidth(brushSize);
      testePaint.setStyle(Paint.Style.STROKE);
      testePaint.setStrokeJoin(Paint.Join.ROUND);
      testePaint.setStrokeCap(Paint.Cap.ROUND);
  
      testePath = paths.remove(0);
      drawCanvas.drawPath(testePath, testePaint);
  }
  </code></pre>
  
  <p>How I create the math:</p>
  
  <pre><code>public class DrawingView extends View {
  
      //drawing path
      private Path drawPath;
      //drawing and canvas paint
      private Paint drawPaint, canvasPaint;
      //initial color
      private int paintColor = 0x00660000;
      //canvas
      private Canvas drawCanvas;
      //canvas bitmap
      private Bitmap canvasBitmap;
  
      private float brushSize, lastBrushSize;
  
      private ArrayList&lt;Path&gt; paths;
  
      private boolean erase=false;
  
      public DrawingView(Context context, AttributeSet attrs) {
          super(context, attrs);
          setupDrawing();
      }
  
      private void setupDrawing(){
          brushSize = getResources().getInteger(R.integer.medium_size);
          lastBrushSize = brushSize;
  
          //get drawing area setup for interaction
          drawPath = new Path();
          drawPaint = new Paint();
  
          drawPaint.setColor(paintColor);
          drawPaint.setAntiAlias(true);
          drawPaint.setStrokeWidth(brushSize);
          drawPaint.setStyle(Paint.Style.STROKE);
          drawPaint.setStrokeJoin(Paint.Join.ROUND);
          drawPaint.setStrokeCap(Paint.Cap.ROUND);
          drawPaint.setAlpha(150);
  
          canvasPaint = new Paint(Paint.DITHER_FLAG);
  
          paths = new ArrayList&lt;Path&gt;();
      }
      ...
  </code></pre>