java - Android : Rectangle Progress Bar with Curved Edges -




i developing android app in have implement sos button, square shaped button rounded corners. want implement progress bar in it's boundary when press button 4 seconds, sos can activated. unable create square progress bar round edges.

here implementation till now, using path. if have better implementation please help.

mainactiivty.java

 button = (button) findviewbyid(r.id.activity_main_button1);     relativelayout = (relativelayout) findviewbyid(r.id.main_container);     final v v = new v(this);     relativelayout.addview(v);      button.setonlongclicklistener(new view.onlongclicklistener() {         @override         public boolean onlongclick(view view) {             new countdowntimer(6000, 58) {                 @override                 public void ontick(long millisuntilfinished) {                     //this done every 1000 milliseconds ( 1 seconds )                     int progress = (int)(6000 - millisuntilfinished) / 58;                     v.setprogress(progress);                 }                  @override                 public void onfinish() {                     //the progressbar invisible after 60 000 miliseconds ( 1 minute)             /*v.dismiss();*/                 }              }.start();             return true;         }     }); 

v.java

class v extends view { path path = new path(); paint paint = new paint(paint.anti_alias_flag); float length; float[] intervals = {0, 0};  public v(context context) {     super(context);     paint.setcolor(color.red);     paint.setstyle(paint.style.stroke);     paint.setstrokewidth(10); }  @override protected void onsizechanged(int w, int h, int oldw, int oldh) {     path.reset();     rectf rect = new rectf(0, 0, 400, 400);     float inset = paint.getstrokewidth();     rect.inset(inset, inset);      path.addroundrect(rect, 50, 50, path.direction.cw);     length = new pathmeasure(path, false).getlength();     intervals[0] = intervals[1] = length;     patheffect effect = new dashpatheffect(intervals, length);     paint.setpatheffect(effect); }  public void setprogress(int progress) {     patheffect effect = new dashpatheffect(intervals, length - length * progress / 100);     paint.setpatheffect(effect);     invalidate(); }  @override protected void ondraw(canvas canvas) {     canvas.drawpath(path, paint); }} 





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -