@@ -4,20 +4,28 @@ import android.app.Activity
44import android.app.Dialog
55import android.content.Context
66import android.view.animation.Animation
7+ import android.view.animation.Animation.INFINITE
8+ import android.view.animation.LinearInterpolator
79import android.view.animation.RotateAnimation
810import android.widget.ImageView
911import org.ninetripods.mq.study.R
1012
11- class LoadingDialog (context : Context , canNotCancel : Boolean ) : Dialog(
12- context ,
13+ class LoadingDialog (val mContext : Context , private val isCancelable : Boolean ) : Dialog(
14+ mContext ,
1315 R .style.LoadingDialog
1416) {
15-
16- private var loadingDialog: LoadingDialog ? = null
17+ private var imageView: ImageView
1718
1819 init {
1920 setContentView(R .layout.layout_loading_view)
20- val imageView: ImageView = findViewById(R .id.iv_image)
21+ imageView = findViewById(R .id.iv_image)
22+ }
23+
24+ /* *
25+ * 展示Loading
26+ */
27+ fun showDialog () {
28+ if (mContext is Activity && mContext.isFinishing) return
2129 val animation: Animation = RotateAnimation (
2230 0f ,
2331 360f ,
@@ -27,26 +35,19 @@ class LoadingDialog(context: Context, canNotCancel: Boolean) : Dialog(
2735 0.5f
2836 )
2937 animation.duration = 2000
30- animation.repeatCount = 10
38+ animation.repeatCount = INFINITE
39+ animation.interpolator = LinearInterpolator ()
3140 animation.fillAfter = true
3241 imageView.startAnimation(animation)
42+ setCancelable(isCancelable)
43+ show()
3344 }
3445
35- fun showDialog (context : Context , isCancel : Boolean ) {
36- if (context is Activity ) {
37- if (context.isFinishing) {
38- return
39- }
40- }
41-
42- if (loadingDialog == null ) {
43- loadingDialog = LoadingDialog (context, isCancel)
44- }
45- loadingDialog?.show()
46- }
47-
46+ /* *
47+ * 关闭Loading
48+ */
4849 fun dismissDialog () {
49- loadingDialog?. dismiss()
50+ dismiss()
5051 }
5152
5253}
0 commit comments