A WP8-style progress dialog box. Corresponds to the ProgressBar of the Android turn circle. Use the same way as normal dialog
public class win8progressdialog extends dialog { private Wploading loading; public win8progressdialog (Context context) { super (context); } public win8progressdialog (Context context, int theme) { super (context, theme); } public void setloading (wploading loading) { this.loading = loading; } @Override public void cancel () { loading.cancel (); super.cancel (); } public win8progressdialOG (context context, boolean cancelable, oncancellistener cancellistener) { Super (Context, cancelable, cancellistener); } public static class Builder { private context mcontext; private boolean Canceledontouchoutside = true; private boolean cancelable = true; public builder (Context context) { mcontext = context; } public builder setcanceledonTouchoutside (Boolean flag) { canceledontouchoutside = flag; return this; } public builder setcancelable (Boolean flag) { cancelable = flag; return this; } public win8progressdialog create () { final win8progressdialog dialog = new win8progressdialog (mcontext, &nbsP; r.style.wpdialog); Wploading loading = new wploading (Mcontext); dialog.setloading (Loading); dialog.setcancelable (cancelable); dialog.setcanceledontouchoutside (canceledontouchoutside); dialog.setcanceledontouchoutside (False); dialog.addcontentview (loading, new Layoutparams ( layoutparams.match_parent, layoutparams.wrap_content)); Loading.startanimate (); return dialog; } }}
Wploading is the view shown in Win8progressdialog, which is a relativelayout that contains five small blue dots of movement, The animation of the Little blue Dot uses an interpolator that slows down and accelerates first decelerateacceleratestopinterpolator
public class wploading extends relativelayout {private int size = 10;private int delay = 300;private int duration = 3200;private String color = "#0000ff";p rivate animatorset animatorset = new Animatorset ();p ublic wploading (context context) {super (Context); Layoutparams params0 = new layoutparams (displayutil.getscreenwidth (context), size); View view = new view (context); View.setlayoutparams (PARAMS0); AddView (view);} Public void startanimate () {layoutparams params = new layoutparams (size, size); Animatorset = new animatorset (); Arraylist<animator> animators = new arraylist<animator> ();for (int i = 0; i < 5; i++) {view view = new view (GetContext () ); View.setBackgroundColor (Color.parsecolor (Color)); AddView (view); View.setlayoutparams (params); View.setx (-size); O Bjectanimator headanimator = objectanimator.offloat (view, "x", View.getX (), Displayutil.getscreenwidth (GetContext ())); headanimator.setduration (duration); Headanimator.setinterpolator (new decelerateacceleratestopinterpolator ()); Headanimator.setstartdelay (delay * i); Headanimator.setrepeatcount ( -1); Animators.add (headanimator);} Animatorset.playtogether (animators); Animatorset.start ();} Public wploading (context context, attributeset attrs) {super (context, attrs);} Public wploading (Context context, attributeset attrs, int defstyle) {super ( Context, attrs, defstyle);} Public void cancel () {animatorset.end ();} speed up and then accelerate the interpolator, after the acceleration is completed will stop for a moment, the cycle of this animation, and WP8 's loading style is the same class decelerateacceleratestopinterpolator implementsandroid.view.animation.interpolator {Private float mfactor = 1.0f;private float tailfactor = 0.6f;public decelerateacceleratestopinterpolator () {}public decelerateacceleratestopinterpolator (float factor) {mfactor = factor;} Public float getinterpolation (float x) {float result;if (x > Tailfactor) {result = 1;} else if (x > tailfactor / 2) {result = (float) Math.pow (x - tailfactor / 2) * 2 / tailFactor, 2 * Mfactor) / 2 + 0.5f;} else {result = (float) (1.0f - math.pow (tailfactor - 2 * x) (/ tailfactor, 2 * mfactor)) / 2;} Return result;}}}
This article is from the "nashlegend" blog, make sure to keep this source http://nashlegend.blog.51cto.com/5635342/1566898
A WP8-style Android ProgressBar