admin
2024-01-26 c2d382d99ca506932985d1843d4371d6ed0203ff
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
package com.weikou.beibeivideo.ui.dialog;
 
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
 
import com.alibaba.fastjson.JSONObject;
import com.bumptech.glide.GenericTransitionOptions;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.lcjian.library.util.SystemCommon;
import com.lcjian.library.util.common.TimeUtil;
import com.weikou.beibeivideo.R;
import com.weikou.beibeivideo.entity.JumpDetail;
import com.weikou.beibeivideo.util.JumpActivityUtil;
 
/**
 * 用户协议弹框
 */
public class FloatADDialog extends Dialog {
 
    private static String TAG = FloatADDialog.class.getName();
 
    public FloatADDialog(Context context) {
        super(context);
        this.setCancelable(false);
    }
 
    public FloatADDialog(Context context, int theme) {
        super(context, theme);
        this.setCancelable(false);
    }
 
 
    public static class Builder {
 
        private String id;
 
        private Activity context;
 
        public Builder(Activity context) {
            this.context = context;
        }
 
        private Drawable drawable;
 
        private JumpDetail jumpDetail;
 
        private JSONObject params;
 
 
        public Builder setImage(Drawable drawable) {
            this.drawable = drawable;
            return this;
        }
 
        public Builder setJump(JumpDetail jumpDetail, JSONObject params) {
            this.jumpDetail = jumpDetail;
            this.params = params;
            return this;
        }
 
        public Builder setId(String id) {
            this.id = id;
            return this;
        }
 
        /**
         * 是否可以显示
         *
         * @param context
         * @return
         */
        public static boolean canShow(Context context, String id) {
            final SharedPreferences share = context.getSharedPreferences("floatAD", Context.MODE_PRIVATE);
            long time = share.getLong("showTime-" + id, 0L);
            long now = System.currentTimeMillis();
            if (!TimeUtil.getGeneralTime(time, "yyyyMMdd").equalsIgnoreCase(TimeUtil.getGeneralTime(now, "yyyyMMdd"))) {
                return true;
            } else
                return false;
        }
 
        /**
         * 设置显示
         *
         * @param context
         * @param id
         */
        private static void setShow(Context context, String id) {
            final SharedPreferences share = context.getSharedPreferences("floatAD", Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = share.edit();
            editor.putLong("showTime-" + id, System.currentTimeMillis());
            editor.commit();
        }
 
 
        public FloatADDialog create() {
 
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            final FloatADDialog dialog = new FloatADDialog(context, R.style.Dialog);
            dialog.setCanceledOnTouchOutside(true);
            final View layout = inflater.inflate(R.layout.dialog_float_ad, null);
            ImageView imageView = layout.findViewById(R.id.iv_img);
            Glide.with(context).load(drawable).transition(GenericTransitionOptions.with(R.anim.anim_float_ad_show)).apply(new RequestOptions().centerInside()).into(imageView);
            ImageView close = layout.findViewById(R.id.iv_close);
            close.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    setShow(context, id);
                    if (dialog.isShowing())
                        dialog.dismiss();
                }
            });
 
            imageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    setShow(context, id);
                    JumpActivityUtil.jumpPage(context, jumpDetail, params);
                    if (dialog.isShowing())
                        dialog.dismiss();
                }
            });
 
 
            dialog.setContentView(layout);
 
            android.view.WindowManager.LayoutParams params = dialog.getWindow()
                    .getAttributes();
            params.width = WindowManager.LayoutParams.MATCH_PARENT;
            params.height = WindowManager.LayoutParams.MATCH_PARENT;
            dialog.getWindow().setAttributes(params);
            return dialog;
        }
    }
 
    public interface MeasureCallBack {
        public void onMeasure(int height);
    }
}