22
33import android .app .Dialog ;
44import android .content .Context ;
5+ import android .os .Handler ;
6+ import android .os .Message ;
57import android .support .annotation .ColorInt ;
68import android .view .LayoutInflater ;
79import android .view .View ;
@@ -37,6 +39,7 @@ public class LoadingDialog {
3739 private boolean openSuccessAnim = true ;
3840 private boolean openFailedAnim = true ;
3941 private int speed = 1 ;
42+ private long time = 1000 ;
4043
4144 public enum Speed {
4245 SPEED_ONE ,
@@ -103,6 +106,13 @@ private void setParams(int size) {
103106 mFailedView .setLayoutParams (failedParams );
104107 }
105108
109+ private Handler h = new Handler () {
110+ @ Override
111+ public void handleMessage (Message msg ) {
112+ LoadingDialog .this .close ();
113+ }
114+ };
115+
106116
107117 //----------------------------------对外提供的api------------------------------//
108118
@@ -123,8 +133,7 @@ public void show() {
123133 */
124134 public void close () {
125135 viewList .clear ();
126- SizeUtils .RightFirst = true ;
127- SizeUtils .WrongFirst = true ;
136+ h .removeCallbacksAndMessages (null );
128137 if (mLoadingDialog != null ) {
129138 mLoadingView .stopAnim ();
130139 mLoadingDialog .dismiss ();
@@ -177,6 +186,7 @@ public void loadSuccess() {
177186 mSuccessView .setDrawDynamic (openSuccessAnim );
178187 mSuccessView .setVisibility (View .VISIBLE );
179188 loadingText .setText (loadSuccessStr );
189+ h .sendEmptyMessageDelayed (1 , time );
180190 }
181191
182192 /**
@@ -188,6 +198,7 @@ public void loadFailed() {
188198 mFailedView .setDrawDynamic (openFailedAnim );
189199 mFailedView .setVisibility (View .VISIBLE );
190200 loadingText .setText (loadFailedStr );
201+ h .sendEmptyMessageDelayed (2 , time );
191202 }
192203
193204 /**
@@ -293,5 +304,18 @@ public LoadingDialog setRepeatCount(int count) {
293304 return this ;
294305 }
295306
307+ /**
308+ * 设置反馈展示时间
309+ *
310+ * @param time 时间
311+ * @return 这个对象
312+ */
313+ public LoadingDialog setShowTime (long time ) {
314+ if (time < 0 )
315+ return this ;
316+ this .time = time ;
317+ return this ;
318+ }
319+
296320
297321}
0 commit comments