This repository was archived by the owner on Jan 8, 2022. It is now read-only.
File tree Expand file tree Collapse file tree
LoadingDialog/src/main/java/com/xiasuhuei321/loadingdialog/view
app/src/main/java/com/xiasuhuei321/sample Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package com .xiasuhuei321 .loadingdialog .view ;
22
3+ import android .annotation .SuppressLint ;
34import android .app .Dialog ;
45import android .content .Context ;
56import android .content .DialogInterface ;
@@ -58,6 +59,7 @@ public enum Speed {
5859 }
5960
6061 private OnFinshListener o ;
62+ private DismissListener d ;
6163
6264 public LoadingDialog (Context context ) {
6365 mContext = context ;
@@ -85,6 +87,7 @@ public void onBackPressed() {
8587 @ Override
8688 public void onDismiss (DialogInterface dialog ) {
8789 mContext = null ;
90+ if (d != null ) d .dimiss ();
8891 }
8992 });
9093 initStyle ();
@@ -145,6 +148,8 @@ private void setParams(int size) {
145148 loadingParams .width = size ;
146149 }
147150
151+ // 会在最后将所有消息移除
152+ @ SuppressLint ("HandlerLeak" )
148153 private Handler h = new Handler () {
149154 @ Override
150155 public void handleMessage (Message msg ) {
@@ -426,12 +431,24 @@ public void setOnFinishListener(OnFinshListener o) {
426431 this .o = o ;
427432 }
428433
434+ /**
435+ * 设置 dismiss 监听
436+ *
437+ * @param d dismiss callback
438+ */
439+ public LoadingDialog setDimissListener (DismissListener d ) {
440+ this .d = d ;
441+ return this ;
442+ }
443+
429444 /**
430445 * 监听器
431446 */
432447 public interface OnFinshListener {
433448 void onFinish ();
434449 }
435450
436-
451+ public interface DismissListener {
452+ void dimiss ();
453+ }
437454}
Original file line number Diff line number Diff line change @@ -41,7 +41,6 @@ protected void onCreate(Bundle savedInstanceState) {
4141 super .onCreate (savedInstanceState );
4242 setContentView (R .layout .activity_main );
4343 initView ();
44- ld = new LoadingDialog (this );
4544 }
4645
4746 private void initView () {
@@ -74,7 +73,7 @@ protected void handleMessage(Message msg) {
7473 ld .loadSuccess ();
7574 break ;
7675 case SAVE_YOU :
77- ld . close ();
76+ dismissLoading ();
7877 break ;
7978 }
8079 }
@@ -83,7 +82,7 @@ protected void handleMessage(Message msg) {
8382 public void onClick (View v ) {
8483 switch (v .getId ()) {
8584 case R .id .btn1 :
86- ld . show ();
85+ showLoading ();
8786 h .sendEmptyMessageDelayed (SAVE_YOU , 5000 );
8887 break ;
8988
Original file line number Diff line number Diff line change 11package com .xiasuhuei321 .sample .base ;
22
3+ import android .os .Bundle ;
34import android .os .Handler ;
45import android .os .Message ;
6+ import android .support .annotation .Nullable ;
57import android .support .v7 .app .AppCompatActivity ;
68
79import com .xiasuhuei321 .loadingdialog .view .LoadingDialog ;
@@ -17,6 +19,19 @@ public class BaseLoadingActivity extends AppCompatActivity {
1719
1820 protected LoadingDialog ld ;
1921
22+ @ Override
23+ protected void onCreate (@ Nullable Bundle savedInstanceState ) {
24+ super .onCreate (savedInstanceState );
25+ ld = new LoadingDialog (this )
26+ .setInterceptBack (false )
27+ .setDimissListener (new LoadingDialog .DismissListener () {
28+ @ Override
29+ public void dimiss () {
30+ h .removeCallbacksAndMessages (null );
31+ }
32+ });
33+ }
34+
2035 // will remove all callback in onDestroy method
2136 @ SuppressWarnings ("HandlerLeak" )
2237 protected Handler h = new Handler () {
You can’t perform that action at this time.
0 commit comments