admin
2022-05-07 4c7cde7ae5ed57335405459e47de4bbd2726c4ba
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package com.yeshi.makemoney.video.app.ui.dialog;
 
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;
 
import com.demo.lib.common.util.common.DimenUtils;
import com.demo.library_ad.AdUtil;
import com.demo.library_ad.ExpressAdManager;
import com.demo.library_ad.entity.ExpressAdContainer;
import com.yeshi.makemoney.video.R;
import com.demo.lib.common.util.SystemCommon;
 
import java.util.List;
 
 
/**
 * 用户协议弹框
 */
public class ExitDialog extends Dialog {
 
    private static String TAG = "ExitDialog";
 
    public ExitDialog(Context context) {
        super(context);
        this.setCancelable(false);
    }
 
    public ExitDialog(Context context, int theme) {
        super(context, theme);
        this.setCancelable(false);
    }
 
 
    public static class Builder {
        private Activity context;
        private OnClickListener positiveButtonClickListener;
        private OnClickListener negativeButtonClickListener;
 
        public Builder(Activity context) {
            this.context = context;
        }
 
 
        public Builder setPositiveClickListener(
                OnClickListener listener) {
            this.positiveButtonClickListener = listener;
            return this;
        }
 
        public Builder setNegativeClickListener(OnClickListener listener) {
            this.negativeButtonClickListener = listener;
            return this;
        }
 
        //是否展示过
        private boolean shown = false;
 
        public ExitDialog create() {
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            final ExitDialog dialog = new ExitDialog(context, R.style.Dialog);
            dialog.setCanceledOnTouchOutside(false);
            final View layout = inflater.inflate(R.layout.dialog_exit, null);
            dialog.addContentView(layout, new FrameLayout.LayoutParams(
                    FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT));
            TextView tv_positive = layout.findViewById(R.id.tv_positive);
            TextView tv_negative = layout.findViewById(R.id.tv_negative);
 
 
            // set the confirm button
            if (positiveButtonClickListener != null) {
                tv_positive.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        positiveButtonClickListener.onClick(dialog,
                                DialogInterface.BUTTON_POSITIVE);
                    }
                });
            }
            if (negativeButtonClickListener != null) {
                tv_negative.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        negativeButtonClickListener.onClick(dialog,
                                DialogInterface.BUTTON_NEGATIVE);
                    }
                });
            }
 
            dialog.setOnShowListener(new OnShowListener() {
                @Override
                public void onShow(DialogInterface dialog) {
                    if (!shown) {
                        shown = true;
                        return;
                    }
                    //刷新广告
                    loadAd(context, layout.findViewById(R.id.fl_ad));
                }
            });
 
            loadAd(context, layout.findViewById(R.id.fl_ad));
 
            dialog.setContentView(layout);
 
            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;
        }
 
        private void loadAd(Activity activity, FrameLayout fl_ad) {
            AdUtil.AD_TYPE adType = AdUtil.getAdType(context, "exitAppAd");
            if (adType == null) {
                return;
            }
 
            int width = (int) ((SystemCommon.getScreenWidth(context) * 3) / 4);
            width = DimenUtils.px2dip(context, width);
            int height = (int) (width * 0.56);
 
            String pid = (adType == AdUtil.AD_TYPE.csj ? context.getString(R.string.ad_csj_pid_exit) : context.getString(R.string.ad_gdt_pid_exit));
 
            ExpressAdManager.getInstance(context).loadAd(width, height, pid, 1, adType, context, new ExpressAdManager.IAdLoadListener() {
 
                @Override
                public void onSuccess(List<ExpressAdContainer> adList) {
                    if (adList != null && adList.size() > 0) {
                        ExpressAdContainer adContainer = adList.get(0);
                        ExpressAdManager.renderAndFillAd(activity, adContainer, fl_ad, new ExpressAdManager.IAdEventListener() {
 
                            @Override
                            public void closeAd(ExpressAdContainer ad) {
                                fl_ad.removeAllViews();
                            }
                        });
                    }
                }
            });
 
        }
 
    }
 
 
    public interface MeasureCallBack {
        void onMeasure(int height);
    }
}