android - seekbar thumb onclicklistener -


i need customize default android seekbar control music player. know sounds simple, don't know how set seekbar thumb listener. want control music , change icon accordingly play , pause when user press on seekbar thumb icon. how can achieve this? know possible because saw apps pocketguide functionality implemented. here's screenshot pocketguide app enter image description here

maybe helps you. adjust code needs.

public class seekbarwiththumbtouch extends seekbar {      private int     scaledtouchslop = 0;     private float   inittouchx      = 0;     private boolean thumbpressed    = false;      public seekbarwiththumbtouch(context context) {         super(context);         init(context);     }      public seekbarwiththumbtouch(context context, attributeset attrs) {         super(context, attrs);         init(context);     }      public seekbarwiththumbtouch(context context, attributeset attrs, int defstyleattr) {         super(context, attrs, defstyleattr);         init(context);     }      private void init(context context) {         scaledtouchslop = viewconfiguration.get(context).getscaledtouchslop();     }      @override     public boolean ontouchevent(motionevent event) {         drawable thumb = null;         switch (event.getaction()) {             case motionevent.action_down:                 thumb = getthumb();//works api >=16!                 if (thumb != null) {                     //contains current position of thumb in view bounds                     rectf bounds = new rectf(thumb.getbounds());                     thumbpressed = bounds.contains(event.getx(), event.gety());                     if (thumbpressed) {                         log.d("thumb", "pressed");                         inittouchx = event.getx();                         return true;                     }                 }                 break;             case motionevent.action_up:                 if (thumbpressed) {                     log.d("thumb", "was pressed -- listener call");                     thumbpressed = false;                 }                 break;             case motionevent.action_move:                 if (thumbpressed) {                     if (math.abs(inittouchx - event.getx()) > scaledtouchslop) {                         inittouchx = 0;                         thumbpressed = false;                         return super.ontouchevent(event);                     }                     log.d("thumb", "move blocked");                     return true;                 }                 break;         }          return super.ontouchevent(event);     } } 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -