BaseNotifyActivity.java
11.4 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
package com.lotus.town.notify;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.ad.lib.AdInfo;
import com.ad.lib.AdManager;
import com.ad.lib.IAdCallback;
import com.ad.lib.RequestInfo;
import com.ad.lib.tt.TTInterstitialActivity;
import com.bumptech.glide.Glide;
import com.lotus.town.R;
import com.lotus.town.utils.NotificationUtils;
import com.manager.AdCache;
import com.sdk.EventBus;
import com.umeng.analytics.MobclickAgent;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public abstract class BaseNotifyActivity extends Activity implements View.OnClickListener , EventBus.Listener{
protected TextView title;
protected Context mContext;
protected ImageView close;
protected RelativeLayout delete_icon;
protected int bigRetryTimes = 0;
private int smallRetryTimes = 0;
protected ImageView adCloseButton;
// private Handler handler = new Handler(){
// @Override
// public void handleMessage(Message msg) {
// initBigAd();
// handler.sendEmptyMessageDelayed(0,8000);
// }
// };
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
NotificationUtils.clearNotification(this);
EventBus.getInstance().register(EventBus.PHONE_COMING,this);
AdCache.getInstance().pushActivity(getBigAdNotifyType(),this);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED|WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
initLayout();
mContext = this;
setFinishOnTouchOutside(false);
initView();
initInfo();
initSmallView();
initBigView();
initBigAd();
// handler.sendEmptyMessageDelayed(0,8000);
// initSmallAd();
}
protected void initLayout(){
// setContentView(R.layout.notify_layout);notify_layout
}
abstract protected String getEventName();
abstract protected String getEventClickName();
abstract protected String getEventPageName();
protected abstract RequestInfo getSmallPlacementId();
protected abstract RequestInfo getBigPlacementId();
@Override
protected void onResume() {
super.onResume();
MobclickAgent.onEvent(this,getEventPageName());
MobclickAgent.onPageStart(this.getLocalClassName()); //手动统计页面("SplashScreen"为页面名称,可自定义)
MobclickAgent.onResume(this); //统计时长
}
@Override
protected void onPause() {
super.onPause();
MobclickAgent.onPageEnd(this.getLocalClassName()); //手动统计页面("SplashScreen"为页面名称,可自定义),必须保证 onPageEnd 在 onPause 之前调用,因为SDK会在 onPause 中保存onPageEnd统计到的页面数据。
MobclickAgent.onPause(this);
}
protected abstract void initInfo();
protected void initView(){
close = findViewById(R.id.close);
delete_icon = findViewById(R.id.delete_icon);
close.setOnClickListener(this);
adCloseButton = (ImageView)findViewById(R.id.close_ad);
}
ImageView smallAdFromLogo;
ImageView smallAdImage;
TextView smallTitle;
TextView smallSubtTitle;
Button smallButton;
RelativeLayout smallLayout;
protected void initSmallView(){
smallAdFromLogo = (ImageView) findViewById(R.id.small_ad_from_logo);
smallAdImage = (ImageView) findViewById(R.id.small_ad_image);
smallTitle = (TextView) findViewById(R.id.small_title);
smallSubtTitle = (TextView) findViewById(R.id.small_subtitle);
smallButton = (Button)findViewById(R.id.small_btn);
smallLayout = (RelativeLayout)findViewById(R.id.small_layout);
}
ImageView bigAdFromLogo;
ImageView bigAdImage;
ImageView bigAdIcon;
TextView bigTitle;
TextView bigSubtTitle;
Button bigButton;
LinearLayout bigLayout;
protected void initBigView(){
bigLayout = (LinearLayout) findViewById(R.id.big_layout);
bigAdFromLogo = (ImageView) findViewById(R.id.big_ad_from_logo);
bigAdImage = (ImageView) findViewById(R.id.big_ad_image);
bigAdIcon = (ImageView) findViewById(R.id.big_ad_icon);
bigTitle = (TextView) findViewById(R.id.big_ad_title);
bigSubtTitle = (TextView) findViewById(R.id.big_ad_subtitle);
bigButton = (Button)findViewById(R.id.big_btn);
}
protected abstract int getSmallAdType();
protected abstract int getBitAdType();
protected abstract int getBigAdNotifyType();
protected void initSmallAd() {
}
protected void initBigAd() {
RequestInfo rInfo = getBigPlacementId();
final AdInfo info = AdCache.getInstance().getCacheAdInfo(getBigAdNotifyType());
if(info == null){
AdManager.getInstance().getAdController(this,getBitAdType()).loadNativeAd(rInfo, new IAdCallback() {
@Override
public void onADLoaded(final AdInfo info) {
if(info.getView() != null){
bigLayout.removeAllViews();
bigLayout.addView(info.getView());
info.getReporter().render();
return;
}
if(info.getAdIcon() != null) {
bigAdFromLogo.setImageBitmap(info.getAdIcon());
}
if(info.getImageList() != null && info.getImageList().size()>0){
Glide.with(mContext).load(info.getImageList().get(0)).into(bigAdImage);
} else {
Glide.with(mContext).load(info.getIconUrl()).into(bigAdImage);
}
Glide.with(mContext).load(info.getIconUrl()).into(bigAdIcon);
bigTitle.setText(info.getTitle());
bigSubtTitle.setText(info.getSubtitle());
bigButton.setText(info.getButtonLabel());
if(getBitAdType() == 0){
List<View> clickViewList = new ArrayList<>();
clickViewList.add(bigLayout);
clickViewList.add(bigButton);
info.getReporter().impress(bigLayout,clickViewList,getEventName(),getEventClickName());
} else if(getBitAdType() == 1 || getBitAdType() == 2){
info.getReporter().impress(bigLayout,getEventName());
info.getReporter().impress(bigButton,getEventName());
bigLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
info.getReporter().click(view,getEventClickName()); // 点击接口
}
});
bigButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
info.getReporter().click(view,getEventClickName()); // 点击接口
}
});
}
}
@Override
public void onADError() {
if (bigRetryTimes++ < 1){
initBigAd();
}
}
@Override
public void onClicked() {
finish();
}
});
return;
}
if(info != null && info.getReporter() != null) {
info.getReporter().bindDislikeView(this, adCloseButton);
}
adCloseButton.setVisibility(View.VISIBLE);
if (info.getView() != null) {
bigLayout.removeAllViews();
bigLayout.addView(info.getView());
if(info != null && info.getReporter() != null) {
info.getReporter().render();
}
return;
}
if (info.getAdIcon() != null) {
bigAdFromLogo.setImageBitmap(info.getAdIcon());
}
if (info.getImageList() != null && info.getImageList().size() > 0) {
Glide.with(mContext).load(info.getImageList().get(0)).into(bigAdImage);
} else {
Glide.with(mContext).load(info.getIconUrl()).into(bigAdImage);
}
Glide.with(mContext).load(info.getIconUrl()).into(bigAdIcon);
bigTitle.setText(info.getTitle());
bigSubtTitle.setText(info.getSubtitle());
bigButton.setText(info.getButtonLabel());
if (getBitAdType() == 0) {
List<View> clickViewList = new ArrayList<>();
clickViewList.add(bigLayout);
clickViewList.add(bigButton);
clickViewList.add(delete_icon);
if(info != null && info.getReporter() != null) {
info.getReporter().impress(bigLayout, clickViewList, getEventName(), getEventClickName());
}
} else if (getBitAdType() == 1 || getBitAdType() == 2) {
info.getReporter().impress(bigLayout, getEventName());
info.getReporter().impress(bigButton, getEventName());
bigLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
info.getReporter().click(view, getEventClickName()); // 点击接口
}
});
bigButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
info.getReporter().click(view, getEventClickName()); // 点击接口
}
});
}
}
@Override
public void onClick(View v) {
if(v == close){
int i = new Random().nextInt(100);
Intent intent = new Intent();
intent.setClass(this, TTInterstitialActivity.class);
this.startActivity(intent);
finish();
}
}
private volatile boolean isBackPressed = false;
@Override
public void onBackPressed() {
if(isBackPressed){
return;
}
isBackPressed = true;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
int i = new Random().nextInt(100);
Intent intent = new Intent();
intent.setClass(BaseNotifyActivity.this, TTInterstitialActivity.class);
BaseNotifyActivity.this.startActivity(intent);
finish();
isBackPressed = false;
}
},1500);
}
@Override
protected void onDestroy() {
super.onDestroy();
// if (handler.hasMessages(0)) {
// handler.removeMessages(0);
// }
EventBus.getInstance().unregister(EventBus.PHONE_COMING,this);
AdCache.getInstance().popActivity(getBigAdNotifyType());
}
@Override
public void onEvent(int notify) {
if(notify == EventBus.PHONE_COMING){
finish();
}
}
}