admin
2021-05-28 5965c01b38a2e83cecd7616daa11185fc2499303
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package com.tejia.lijin.app.ui.dialog;
 
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
 
import com.wang.avi.AVLoadingIndicatorView;
import com.tejia.lijin.app.R;
 
/**
 * Created by weikou2015 on 2017/2/28.
 */
 
public class ShapeLoadingDialog extends Dialog {
    private AVLoadingIndicatorView mLoadingView;
 
    private Builder mBuilder;
 
    private ShapeLoadingDialog(Builder builder) {
        super(builder.mContext, R.style.custom_dialog);
        mBuilder = builder;
        setCancelable(mBuilder.mCancelable);
        setCanceledOnTouchOutside(mBuilder.mCanceledOnTouchOutside);
    }
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_dialog);
 
        mLoadingView = findViewById(R.id.avi);
        Animation ani = AnimationUtils.loadAnimation(mLoadingView.getContext(), R.anim.touming); //申明一个动画
        mLoadingView.setAnimation(ani);//为图片绑定动画
 
        setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                mLoadingView.setVisibility(View.GONE);
            }
        });
    }
 
    @Override
    public void show() {
        super.show();
        mLoadingView.setVisibility(View.VISIBLE);
    }
 
    public Builder getBuilder() {
        return mBuilder;
    }
 
    public static class Builder {
 
        private Context mContext;
 
        private int mDelay = 80;
 
        private CharSequence mLoadText;
 
        private boolean mCancelable = true;
 
        private boolean mCanceledOnTouchOutside = true;
 
        public Builder(Context context) {
            mContext = context;
        }
 
        public Builder delay(int delay) {
            mDelay = delay;
            return this;
        }
 
        public Builder loadText(CharSequence loadText) {
            mLoadText = loadText;
            return this;
        }
 
        public Builder loadText(int resId) {
            mLoadText = mContext.getString(resId);
            return this;
        }
 
        public Builder cancelable(boolean cancelable) {
            mCancelable = cancelable;
            mCanceledOnTouchOutside = cancelable;
            return this;
        }
 
        public Builder canceledOnTouchOutside(boolean canceledOnTouchOutside) {
            mCanceledOnTouchOutside = canceledOnTouchOutside;
            return this;
        }
 
        public ShapeLoadingDialog build() {
            return new ShapeLoadingDialog(this);
        }
 
//        public ShapeLoadingDialog show(){
//            ShapeLoadingDialog dialog = build();
//            dialog.show();
//            return dialog;
//        }
    }
}