admin
2021-05-28 98cc34dbca6d6218ec5e72baffda2d3a1dd72a55
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
110
111
112
113
114
115
116
117
118
119
package com.tejia.lijin.app.ui.dialog;
 
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
 
import com.wpc.library.util.SystemCommon;
import com.wpc.library.util.common.DimenUtils;
import com.tejia.lijin.app.R;
 
/**
 * 用户协议弹框
 */
public class MultiImageDownloadDialog extends Dialog {
 
    private static String TAG = "UserProtocolDialog";
 
    public MultiImageDownloadDialog(Context context) {
        super(context);
        this.setCancelable(false);
    }
 
    public MultiImageDownloadDialog(Context context, int theme) {
        super(context, theme);
        this.setCancelable(false);
    }
 
 
    public static class Builder {
        public final static int TEXT_ALIGIN_LEFT = 1;
        public final static int TEXT_ALIGIN_MIDDLE = 2;
        public final static int TEXT_ALIGIN_RIGHT = 3;
 
        private int downloadCount = 8;
        private int totalCount = 9;
 
        private Activity context;
        String title;
 
        public Builder setTotalCount(int count) {
            this.totalCount = count;
            return this;
        }
 
        public Builder(Activity context) {
            this.context = context;
        }
 
        public Builder setData(String data) {
            return this;
        }
 
        ImageView iv_progress_bg;
        ImageView iv_progress;
        ImageView iv_percent_top;
        View ll_percent;
        TextView tv_percent;
        TextView tv_progress_desc;
 
 
        public MultiImageDownloadDialog create() {
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            final MultiImageDownloadDialog dialog = new MultiImageDownloadDialog(context, R.style.Dialog);
            final View layout = inflater.inflate(R.layout.dialog_img_download_progress, null);
            dialog.addContentView(layout, new FrameLayout.LayoutParams(
                    FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT));
            dialog.setContentView(layout);
            iv_progress_bg = layout.findViewById(R.id.iv_progress_bg);
            iv_progress = layout.findViewById(R.id.iv_progress);
            iv_percent_top = layout.findViewById(R.id.iv_percent_top);
            ll_percent = layout.findViewById(R.id.ll_percent);
            tv_percent = layout.findViewById(R.id.tv_percent);
            tv_progress_desc = layout.findViewById(R.id.tv_progress_desc);
            //初始化进度
            setDownloadCount(0);
            android.view.WindowManager.LayoutParams params = dialog.getWindow()
                    .getAttributes();
            params.width = (int) ((SystemCommon.getScreenWidth(context) * 3) / 4);
            params.height = android.view.WindowManager.LayoutParams.WRAP_CONTENT;
            dialog.getWindow().setAttributes(params);
            return dialog;
        }
 
 
        public void setDownloadCount(int count) {
            int totalWidth = iv_progress_bg.getMeasuredWidth();
            int percentWidth = count * totalWidth / totalCount;
            if (percentWidth > totalWidth)
                percentWidth = totalWidth;
            //设置值
            ViewGroup.LayoutParams params1 = iv_progress.getLayoutParams();
            params1.width = percentWidth;
            iv_progress.setLayoutParams(params1);
            tv_percent.setText(count * 100 / totalCount + "%");
            tv_progress_desc.setText(String.format("已下载%s/%s张图片,请稍后...", count, totalCount));
            //设置偏移量
 
            ViewGroup.MarginLayoutParams param2 = (ViewGroup.MarginLayoutParams) iv_percent_top.getLayoutParams();
            ViewGroup.MarginLayoutParams param3 = (ViewGroup.MarginLayoutParams) tv_percent.getLayoutParams();
            ViewGroup.MarginLayoutParams param4 = (ViewGroup.MarginLayoutParams) ll_percent.getLayoutParams();
            if (percentWidth > 0)
                param4.leftMargin = percentWidth - (param2.leftMargin - param3.leftMargin);
            else
                param4.leftMargin = DimenUtils.dip2px(context, 10);
            ll_percent.requestLayout();
        }
    }
 
    public interface MeasureCallBack {
        public void onMeasure(int height);
    }
}