android - How would I implement a swipe-based circular control like this? -


i working on android application, , have textview display price (for example 50$).

i have circular control similar picture:

enter image description here

  • swiping finger clockwise on dial increases amount $1 steps
  • swiping finger counter-clockwise on dial decreases amount $1 steps

i did research couldn't find working implementation of this.

how create such circular control driven swipes?

i've modified source of circularseekbar work want.

you can mofidied class modified cirucularseekbar

first include control in layout , set dial background

            <com.yourapp.circularseekbar                 android:id="@+id/circularseekbar"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:background="@drawable/amount_wheel_bg" /> 

then, in activity (it should implement oncircularseekbarchangelistener) add following:

//this reference layout control private circularseekbar circularseekbar; //this reference textbox want display amount private edittext amountedittext; private int previousprogress = -1; 

and add following callback methods:

@override    public void onprogresschanged(circularseekbar circularseekbar,                  int progress, boolean fromuser) {           if(previousprogress == -1)           {                  //this first user touch take reference                  previousprogress = progress;           }           else           {                  //the user holding finger down                  if(progress == previousprogress)                  {                        //he still in same position, don't                  }                  else                  {                        //the user moving finger need differences                         int difference = progress - previousprogress;                                                 if(math.abs(difference) > circularseekbar.default_max/2)                        {                               //the user @ top of wheel either moving 0 -> max or max -> 0                               //we have consider 1 step                                 //to force 1 unit , reverse sign;                               difference /= math.abs(difference);                                difference -= difference;                         }                                                  //update amount                        selectedamount += difference;                         previousprogress= progress;                        updateamounttext();                  }           }     }     @override    public void onstoptrackingtouch(circularseekbar seekbar) {            //reset tracking progress           previousprogress = -1;     }     @override    public void onstarttrackingtouch(circularseekbar seekbar) {     }     private void updateamounttext()    {           amountedittext.settext(string.format("%.2f", selectedamount));    } 

selectedamount double property store amount selected.

i hope can you.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -