Indeterminate ProgressBars really are a helpful tool for interacting to the customers that the operation is within progress whenever we cannot predict how lengthy chances are it will take. Formerly on Styling app developer we’ve covered how to produce a backwardly compatible approximation from the material styled horizontal indeterminate ProgressBar but we haven’t checked out the circular form – within this series we’ll create an approximation from the material circular indeterminate ProgressBar which is backwardly compatible to API 11 (Honeycomb).
Formerly we’ve taken an in-depth dive to the Lollipop implementation from the material circular indeterminate drawable, and today we’ll turn our focus on really creating our very own.
First we’ll consider the actual Drawable component (that is similar towards the VectorDrawable we checked out in AOSP) that accounts for really drawing the circular component (or perhaps a portion of one, a minimum of). We can’t use VectorDrawable because it’s Lollipop only and VectorDrawableCompat isn’t ready for serious use (during the time of writing). But we are able to use good, old-fashioned Canvas and Paint to complete what we should need.
First we determine the pixel values for that stroke width and internal padding from the drawable to carefully match individuals used my the particular material drawable. You should convert these from DIP to PX values based on the DisplayMetrics at runtime to make sure that we are able to consistency across shows with varying densities.
Next we produce a Paint object using the necessary colour and stroke width which is accustomed to really draw the portion of the circle. App developer are able to retrieve the right colour in the theme by carrying out the right research (we’re while using Design support library which means this will honor the within our Theme).
It’s vital that you switch on anti-aliasing around the Paint otherwise we’ll acquire some lovely jaggy edges. Also we set a square cap on the way which imitates what’s looking for the pathData within the material VectorDrawable that people checked out earlier within the series.