java - Changing setStrokeWidth changes all drawn paths Stroke - Paint Android -


i changing android stroke path randomly. when change stroke of paint, changes previous paint paths drawn. so, how change stroke not affect previous drawn paths?

here drawing panel looks like:

public class write extends appcompatactivity  { private drawingpanel dp; private paint mpaint; customlayout linearlayout2; @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_write);     mpaint = new paint();     mpaint.setantialias(true);     mpaint.setdither(true);     mpaint.setcolor(color);     mpaint.setstyle(paint.style.stroke);     mpaint.setstrokejoin(paint.join.round);     mpaint.setstrokecap(paint.cap.round);     mpaint.setstrokewidth(3);     linearlayout2 = (customlayout) findviewbyid(r.id.linearlayout2);     dp = new drawingpanel(this);     linearlayout2.addview(dp); }  public void changestrokedynamic(view view) {     mpaint.setstrokewidth(20); // here changing occurs }  public class drawingpanel extends view implements view.ontouchlistener {      private map<path, integer> colorsmap = new hashmap<path, integer>();     private arraylist<path> mmaindialog = new arraylist<path>();     private arraylist<path> undonepaths = new arraylist<path>();     private canvas mcanvas;     private path mpath;      public drawingpanel(context c) {         super(c);         mcanvas = new canvas();         mpath = new path();      }      @override     protected void onsizechanged(int w, int h, int oldw, int oldh) {         super.onsizechanged(w, h, oldw, oldh);      }      @override     protected void ondraw(canvas canvas) {         (path p : mmaindialog) {             mpaint.setcolor(colorsmap.get(p));             canvas.drawpath(p, mpaint);         }         mpaint.setcolor(slll);         canvas.drawpath(mpath, mpaint);     }      private float mx, my;     private static final float touch_tolerance = 0;      @override     public boolean ontouchevent(motionevent event) {         float x = event.getx();         float y = event.gety();         switch (event.getaction()) {             case motionevent.action_down:                 // touch_start(x, y);                 // invalidate();                 undonepaths.clear();                 mpath.reset();                 mpath.moveto(x, y);                 mx = x;                 = y;                 invalidate();                 break;             case motionevent.action_move:                 // touch_move(x, y);                 // invalidate();                 float dx = math.abs(x - mx);                 float dy = math.abs(y - my);                 if (dx >= touch_tolerance || dy >= touch_tolerance) {                     mpath.quadto(mx, my, (x + mx) / 2, (y + my) / 2);                     mx = x;                     = y;                 }                 invalidate();                 break;             case motionevent.action_up:                 // touch_up();                 // invalidate();                 mpath.lineto(mx, my);                 mmaindialog.add(mpath);                 colorsmap.put(mpath, slll);                 mpath = new path();                 mpath.reset();                 invalidate();                 break;         }         return true;     } // end of touch events image      @override     public boolean ontouch(view arg0, motionevent arg1) {         // todo auto-generated method stub         return false;     } } 

i want change stroke on button click. here doing far:

public void changestrokedynamic(view view) {     mpaint.setstrokewidth(20); // here changing occurs } 

how change stroke not affect previous drawn paths?


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -