android - Changing the color of part of a path while it is being drawn -


i managed create own custom path drawing application , follows

public class canvasview extends view { context context; hashmap<integer,pathwrapper> loctopath=new hashmap<>(); arraylist<pathwrapper> activepaths=new arraylist<>(); comingleandroidruntime<screenshare> screenruntime; boolean inited=false; integer mylocation; public canvasview(context context,attributeset attr) {     super(context, attr);     setwillnotdraw(false);     this.context = context; }  public void init(comingleandroidruntime<screenshare> screenruntime){     inited=true;     this.screenruntime=screenruntime;     this.mylocation=screenruntime.getlocation();     addpath(mylocation);     invalidate(); }  public void addpath(int location){     paint mpaint=new paint();     mpaint.setcolor(color.black);     mpaint.setalpha(195);     mpaint.setstyle(paint.style.stroke);     mpaint.setstrokejoin(paint.join.round);     mpaint.setstrokewidth(50f);     loctopath.put(location, new pathwrapper(new path(), mpaint, location)); } @override protected void ondraw(canvas canvas) {     super.ondraw(canvas);     for(pathwrapper path:activepaths){         canvas.drawpath(path.path, path.paint);     }     invalidate(); } public void respondactioncolorchanged(int r,int g,int b){     loctopath.get(mylocation).paint.setcolor(color.rgb(r, g, b)); } public void respondactioncolorchanged(int loc,int r,int g,int b){     loctopath.get(loc).paint.setcolor(color.rgb(r, g, b)); } public void respondactiondown(final integer loc, int xtouch,int ytouch){     activepaths.add(loctopath.get(loc));     loctopath.get(loc).path.moveto(xtouch, ytouch);     loctopath.get(loc).lastpoint = new point(xtouch, ytouch);     if(loc==mylocation){         screenruntime.getrewritemachine().addactiondown(xtouch, ytouch);     } } public void respondactionmove(final integer loc,int xtouch,int ytouch){     float dx = math.abs(xtouch - loctopath.get(loc).lastpoint.x);     float dy = math.abs(ytouch - loctopath.get(loc).lastpoint.y);     if (dx >= 5 || dy >= 5) {         loctopath.get(loc).path.quadto(loctopath.get(loc).lastpoint.x, loctopath.get(loc).lastpoint.y, (xtouch + loctopath.get(loc).lastpoint.x) / 2, (ytouch + loctopath.get(loc).lastpoint.y) / 2);         loctopath.get(loc).lastpoint = new point(xtouch, ytouch);         if(loc==mylocation){             screenruntime.getrewritemachine().addactionmove(xtouch, ytouch);         }     }  } public void respondactionup(final integer loc,int x,int y){     loctopath.get(loc).path.lineto(loctopath.get(loc).lastpoint.x, loctopath.get(loc).lastpoint.y);      if(loc==mylocation){         screenruntime.getrewritemachine().addactionup(x, y);     }     activepaths.remove(loctopath.get(loc));     loctopath.get(loc).path.reset(); } @override public boolean ontouchevent(motionevent event) {     if(inited) {         int xtouch;         int ytouch;         xtouch = (int) event.getx(0);         ytouch = (int) event.gety(0);         switch (event.getaction()) {             case motionevent.action_down:                 respondactiondown(mylocation,xtouch,ytouch);                 break;             case motionevent.action_move:                 respondactionmove(mylocation, xtouch,ytouch);                 break;             case motionevent.action_up:                 respondactionup(mylocation, xtouch,ytouch);                 break;         }         return true;     }     return false; } 

this code works app (ignore location stuff , runtime , rewritemachine stuff).

my question is, have parts of path colored differently, ultimate goal last few pixels of path visible , remainder should have alpha of 0, such when user draws, sees last few pixels of path turns invisible. possible? , if how it?

thanks.

instead of adding points path, create list of paths, , every time add new path list has small chunk starts @ end point of previous path, , has 1 other point (end-point). can draw each path different color:

paint mpaint=new paint(); mpaint.setcolor(color.black); //rest of mpaint... canvas.drawpath(path1, mpaint);  mpaint=new paint(); mpaint.setcolor(color.blue); //rest of mpaint... canvas.drawpath(path2, mpaint); 

note path1 different path2, , more importantly create new mpaint each color. i'm not sure if work if call mpaint.setcolor(color.blue) on created , used paint.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -