Commit 25ca2809 authored by xujialang's avatar xujialang

新版广告管理类

取消自动亮屏
增加亮屏条件判断
parent 3c413ef3
......@@ -140,7 +140,7 @@ public final class OutHelp implements KPListener {
}
private void initTriggerConditions() {
// initTimer();
initTimer();
// initReceiver();
registerActivityLifecycle();
registerAction();
......@@ -154,13 +154,14 @@ public final class OutHelp implements KPListener {
timer.schedule(new TimerTask() {
@Override
public void run() {
/* if (!DataManager.get().checkOutOpen(mContext)) {
Map<String, String> map = new HashMap<>();
map.put("position", "time");
Statistics.getInstance().dotEvent("out_close", map);
LogUtil.d(TAG + "外展未开启,不轮询检测");
return;
}*/
// if (!DataManager.get().checkOutOpen(mContext)) {
// Map<String, String> map = new HashMap<>();
// map.put("position", "time");
// Statistics.getInstance().dotEvent("out_close", map);
// LogUtil.d(TAG + "外展未开启,不轮询检测");
// return;
// }
Statistics.getInstance().dotEvent("out_open");
LogUtil.d(TAG, "firstLx : " + firstLx);
showOutAd(firstLx);
......@@ -486,7 +487,7 @@ public final class OutHelp implements KPListener {
// new StartCallbackProxy(callObj, callback)
// );
surpriseMethod.invoke(null, mContext, intent, "", true, null, notificationConfig);
surpriseMethod.invoke(null, mContext, intent, "", true, null, null);
} catch (ClassNotFoundException | InvocationTargetException | NoSuchMethodException |
IllegalAccessException | InstantiationException e) {
......@@ -503,7 +504,7 @@ public final class OutHelp implements KPListener {
try {
PowerManager pm = (PowerManager) mContext.getSystemService(POWER_SERVICE);
mWakelock = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK, "target");
mWakelock.acquire(60 * 1000L);
mWakelock.acquire(30 * 1000L);
} catch (Exception ignored) {
if (mWakelock != null) {
mWakelock.release();
......
package com.zl.sdk.ad;
import android.app.Activity;
import android.util.Log;
import com.anythink.core.api.ATAdInfo;
import com.anythink.core.api.ATAdStatusInfo;
import com.anythink.core.api.AdError;
import com.anythink.interstitial.api.ATInterstitial;
import com.anythink.interstitial.api.ATInterstitialListener;
import com.zl.sdk.OutHelp;
import com.zl.sdk.event.AdsParamsInfo;
import com.zl.sdk.event.EventUtils;
import com.zl.sdk.event.ReportBean;
import com.zl.sdk.out.AppOutSP;
import java.util.Date;
public class AdManagerV2 implements ATInterstitialListener {
private ATInterstitial atInterstitial = null;
private int reloadCount = 3;
private String adId = "";
private long requestTime = 0L;
private static final AdManagerV2 mgr = new AdManagerV2();
private AdManagerV2() {
}
public static AdManagerV2 get() {
return mgr;
}
@Override
public void onInterstitialAdLoaded() {
Log.d("OutShow", "Topon: ad loaded");
reloadCount = 3;
if (atInterstitial.checkValidAdCaches() == null || atInterstitial.checkValidAdCaches().isEmpty()) {
EventUtils.statAdLoaded(getReportBean(null, null), requestTime);
} else {
EventUtils.statAdLoaded(getReportBean(atInterstitial.checkValidAdCaches().get(0), null), requestTime);
}
//记录广告返回的时间,供上报缓存时间和价格
requestTime = System.currentTimeMillis();
}
@Override
public void onInterstitialAdLoadFail(AdError adError) {
Log.d("OutShow", "Topon: ad load fail");
String builder = "error info : code=" + adError.getCode() +
" msg=" + adError.getDesc() +
" all=" + adError.getFullErrorInfo();
EventUtils.statAdLoadFail(getReportBean(null, builder), requestTime);
reloadCount--;
if (reloadCount > 0) {
atInterstitial = new ATInterstitial(OutHelp.get().getContext(), adId);
atInterstitial.setAdListener(this);
atInterstitial.load();
requestTime = System.currentTimeMillis();
EventUtils.statAdReport(getReportRequestBean(adId));
} else {
reloadCount = 3;
}
}
@Override
public void onInterstitialAdClicked(ATAdInfo atAdInfo) {
Log.d("OutShow", "Topon: ad click");
EventUtils.statAdClick(getReportBean(atAdInfo, null));
}
@Override
public void onInterstitialAdShow(ATAdInfo atAdInfo) {
Log.d("OutShow", "Topon: ad show");
int outInterstitialAdDayShowCount = AppOutSP.getOutInterstitialAdDayShowCount() + 1;
AppOutSP.saveOutInterstitialAdDayShowCount(outInterstitialAdDayShowCount);
Log.d("OutShow", "Topon: ad show times=" + outInterstitialAdDayShowCount);
EventUtils.statAdExpose(getReportBean(atAdInfo, null));
atInterstitial = new ATInterstitial(OutHelp.get().getContext(), adId);
atInterstitial.setAdListener(this);
atInterstitial.load();
requestTime = System.currentTimeMillis();
EventUtils.statAdReport(getReportRequestBean(adId));
}
@Override
public void onInterstitialAdClose(ATAdInfo atAdInfo) {
Log.d("OutShow", "Topon: ad close");
EventUtils.statAdClose(getReportBean(atAdInfo, null));
}
@Override
public void onInterstitialAdVideoStart(ATAdInfo atAdInfo) {
Log.d("OutShow", "Topon: ad video start");
}
@Override
public void onInterstitialAdVideoEnd(ATAdInfo atAdInfo) {
Log.d("OutShow", "Topon: ad video end");
}
@Override
public void onInterstitialAdVideoError(AdError adError) {
Log.d("OutShow", "Topon: ad video error");
}
public void loadAd(String id) {
Log.d("OutShow", "Topon: loadAd : " + id);
adId = id;
if (atInterstitial != null) {
ATAdStatusInfo atAdStatusInfo = atInterstitial.checkAdStatus();
if (!atAdStatusInfo.isReady() && !atAdStatusInfo.isLoading()) {
atInterstitial.load();
requestTime = System.currentTimeMillis();
EventUtils.statAdReport(getReportRequestBean(adId));
}
} else {
atInterstitial = new ATInterstitial(OutHelp.get().getContext(), adId);
atInterstitial.setAdListener(this);
atInterstitial.load();
requestTime = System.currentTimeMillis();
EventUtils.statAdReport(getReportRequestBean(adId));
}
}
public boolean isAdReady() {
if (atInterstitial != null) {
ATAdStatusInfo atAdStatusInfo = atInterstitial.checkAdStatus();
return atAdStatusInfo.isReady();
} else {
return false;
}
}
public void showAd(Activity activity) {
Log.d("OutShow", "Topon: showAd");
ATInterstitial.entryAdScenario("111", "");
atInterstitial.show(activity);
}
private ReportBean getReportBean(ATAdInfo adInfo, String errorMsg) {
ReportBean bean = new ReportBean();
bean.adtype = AdsParamsInfo.INTERSTITIAL;
bean.adUnitId = adId;
if (null != adInfo) {
bean.platform = adInfo.getNetworkPlacementId();
bean.source = adInfo.getAdNetworkType();
}
bean.ad_msg_error = errorMsg;
bean.time = (new Date()).getTime();
return bean;
}
private ReportBean getReportRequestBean(String adId) {
ReportBean bean = new ReportBean();
bean.eventid = AdsParamsInfo.F_REQUEST;
bean.adtype = AdsParamsInfo.INTERSTITIAL;
bean.adUnitId = adId;
return bean;
}
}
......@@ -7,11 +7,12 @@ import android.net.NetworkInfo;
import android.text.format.DateUtils;
import com.zl.sdk.OutHelp;
import com.zl.sdk.ad.TopOnAdLoadManager;
import com.zl.sdk.ad.AdManagerV2;
import com.zl.sdk.bean.OutAdData;
import com.zl.sdk.event.DialogFailReason;
import com.zl.sdk.event.EventUtils;
import com.zl.sdk.event.statistics.Statistics;
import com.zl.sdk.util.AppOutUtils;
import com.zl.sdk.util.LogUtil;
import java.util.Calendar;
......@@ -45,11 +46,11 @@ public class CheckHelper {
// return false;
// }
//
// if (needCheckScreenOff(actionState) && !AppOutUtils.isScreenOn()) {
// LogUtil.d(TAG + "(场景检查)手机未亮屏,不能展示");
// EventUtils.staDialogFail(DialogFailReason.SCREEN_OFF, actionState, scenes, EventUtils.DIALOG_TYPE_AD);
// return false;
// }
if (needCheckScreenOff(actionState) && !AppOutUtils.isScreenOn()) {
LogUtil.d(TAG + "(场景检查)手机未亮屏,不能展示");
EventUtils.staDialogFail(DialogFailReason.SCREEN_OFF, actionState, scenes, EventUtils.DIALOG_TYPE_AD);
return false;
}
if (actionState != ActionFrom.ACTION_INIT_START.getAction() && isTelephonyCalling()) {
LogUtil.d(TAG + "(场景检查)通话中,不能展示");
......@@ -240,7 +241,8 @@ public class CheckHelper {
return false;
}
try {
boolean ready = TopOnAdLoadManager.getInstance().isInterstitialReady(data.cpName, data.cpAdslot);
// boolean ready = TopOnAdLoadManager.getInstance().isInterstitialReady(data.cpName, data.cpAdslot);
boolean ready = AdManagerV2.get().isAdReady();
LogUtil.d(TAG + "(缓存检查)是否有缓存:" + ready);
if (!ready) {
EventUtils.staDialogFail(DialogFailReason.NOT_READY, -1, scenes, EventUtils.DIALOG_TYPE_AD);
......
......@@ -10,7 +10,7 @@ import android.text.format.DateUtils;
import com.zl.sdk.Config;
import com.zl.sdk.OutHelp;
import com.zl.sdk.ad.AdDataManager;
import com.zl.sdk.ad.TopOnAdLoadManager;
import com.zl.sdk.ad.AdManagerV2;
import com.zl.sdk.bean.OutAdData;
import com.zl.sdk.bean.RemindersInfo;
import com.zl.sdk.event.EventUtils;
......@@ -40,18 +40,19 @@ public class OutAdManager extends BaseOutShowManager {
private static final String TAG = "OutShow OutAdManager --> ";
//展示广告失败次数
private int showAdFailTimes = 0;
//是否重试了
private volatile boolean hadStartAdDialogFail = false;
//上次拉起外展弹窗时间
private long lastStartAdDialogTime = 0L;
// 展示广告失败次数
// private int showAdFailTimes = 0;
// //是否重试了
// private volatile boolean hadStartAdDialogFail = false;
// //上次拉起外展弹窗时间
// private long lastStartAdDialogTime = 0L;
//限制不能重复拉起外展弹窗的时间
// private final long startAdDialogIntervalTime = 5 * 1000L;
public void cleanLoadAdFailTime() {
showAdFailTimes = 0;
}
// public void cleanLoadAdFailTime() {
// showAdFailTimes = 0;
// }
@Override
OutAdData.NormalAdData getAdData() {
......@@ -166,25 +167,22 @@ public class OutAdManager extends BaseOutShowManager {
* 广告播放失败时,检查重试次数,间隔重试时间再次播放
*/
public void showAdFail() {
showAdFailTimes++;
// showAdFailTimes++;
LogUtil.d(TAG + ">>>重试检查<<< =============>>> START");
LogUtil.d(TAG + ">>>重试检查<<< 配置 重试间隔时间:" + IconHelp.get().getRetryShowAdTime() + "ms 重试次数:" + IconHelp.get().getRetryShowAdCount());
if (showAdFailTimes <= IconHelp.get().getRetryShowAdCount()) {
LogUtil.d(TAG + ">>>重试检查<<< =============>>> END 需要重试 计时" + IconHelp.get().getRetryShowAdTime() + "ms后再次重试 当前重试次数:" + showAdFailTimes);
new Handler(Looper.getMainLooper()).postDelayed(() -> {
checkNeedLoadAd(ActionFrom.ACTION_UNKNOWN);
LogUtil.d(TAG + ">>>重试检查<<< 计时完成,去重新加载广告");
}, IconHelp.get().getRetryShowAdTime());
} else {
LogUtil.d(TAG + ">>>重试检查<<< =============>>> END 重试超过次数 不再重试");
returnFailCallBack("retry over time");
cleanLoadAdFailTime();
OutHelp.get().setLastShowTime();
// if (showAdFailTimes <= IconHelp.get().getRetryShowAdCount()) {
// LogUtil.d(TAG + ">>>重试检查<<< =============>>> END 需要重试 计时" + IconHelp.get().getRetryShowAdTime() + "ms后再次重试 当前重试次数:" + showAdFailTimes);
// new Handler(Looper.getMainLooper()).postDelayed(() -> {
// checkNeedLoadAd(ActionFrom.ACTION_UNKNOWN);
// LogUtil.d(TAG + ">>>重试检查<<< 计时完成,去重新加载广告");
// }, IconHelp.get().getRetryShowAdTime());
// } else {
LogUtil.d(TAG + ">>>重试检查<<< =============>>> END 重试超过次数 不再重试");
returnFailCallBack("retry over time");
OutHelp.get().setLastShowTime();
// cleanLoadAdFailTime();
// AppOutSP.saveHomeLastShowTime(System.currentTimeMillis());
}
// }
}
/**
......@@ -247,11 +245,13 @@ public class OutAdManager extends BaseOutShowManager {
LogUtil.d(TAG + ">>>播放广告<<< ============>>> END 检查通过 开始启动SLK");
LogUtil.d(TAG);
hadStartAdDialogFail = false;
// hadStartAdDialogFail = false;
// OutHelp.get().setShowLock(true);
// if (!AppOutUtils.isScreenOn()) {
// OutHelp.get().wakeOn();
// }
if (!AppOutUtils.isScreenOn()) {
OutHelp.get().wakeOn();
}
startAdDialog(OutHelp.get().getContext(), actionFrom, getReminderInfo(), adData);
return;
......@@ -330,6 +330,8 @@ public class OutAdManager extends BaseOutShowManager {
LogUtil.d(TAG + "拉起广告弹窗 :" + OutHelp.get().getSdkName());
OutHelp.get().setLastShowTime();
OutHelp.get().startOutDialog(intent, new DialogShowStatusCallback() {
@Override
public void success() {
......@@ -457,11 +459,12 @@ public class OutAdManager extends BaseOutShowManager {
LogUtil.d(TAG + "加载广告(插屏) adData :" + normalAdData);
hadStartAdDialogFail = false;
// hadStartAdDialogFail = false;
LogUtil.d(TAG + ">>>加载广告<<< =============>>> END 去加载广告");
try {
TopOnAdLoadManager.getInstance().loadInterstitialAd(normalAdData, AdScenes.AD_SCENES_PURE);
}catch (Exception e){
// TopOnAdLoadManager.getInstance().loadInterstitialAd(normalAdData, AdScenes.AD_SCENES_PURE);
AdManagerV2.get().loadAd(normalAdData.cpAdslot);
} catch (Exception e) {
Map<String, Object> map = new HashMap<>();
map.put("reason", e.getMessage());
map.put("scenes", "load ad");
......
......@@ -8,6 +8,7 @@ public final class DialogFactory {
if (remindersInfo == null) {
return null;
}
return new PureAdDialog(remindersInfo, data);
return null;
// return new PureAdDialog(remindersInfo, data);
}
}
......@@ -12,6 +12,7 @@ import android.widget.FrameLayout;
import com.zl.sdk.Config;
import com.zl.sdk.OutHelp;
import com.zl.sdk.ad.AdManagerV2;
import com.zl.sdk.bean.OutAdData;
import com.zl.sdk.bean.RemindersInfo;
import com.zl.sdk.event.EventUtils;
......@@ -26,14 +27,15 @@ import java.util.Map;
public class DxActivity extends BaseActivity {
private static final String TAG = "OutShow Dx ---> ";
private Intent intent = null;
private RemindersInfo remindersInfo;
private OutAdData.NormalAdData adData;
private IView proxyView;
// private Intent intent = null;
// private RemindersInfo remindersInfo;
// private OutAdData.NormalAdData adData;
// private IView proxyView;
private long onceStayTime;
private boolean hadStart = false;
private Handler mainHandler = new Handler(Looper.getMainLooper());
......@@ -43,13 +45,14 @@ public class DxActivity extends BaseActivity {
@Override
public void onBeforeCreate(Bundle bundle) {
OutHelp.get().setShowLock(true);
// OutHelp.get().setShowLock(true);
hadStart = false;
}
@Override
public void onAfterCreate(Bundle bundle) {
LogUtil.d(TAG + "onCreate");
DxManager.get().addActivity(this);
// DxManager.get().addActivity(this);
}
......@@ -62,35 +65,42 @@ public class DxActivity extends BaseActivity {
// }
}
@Override
public void onStart() {
super.onStart();
if (hadStart) {
close();
return;
}
LogUtil.d(TAG + "onStart");
mainHandler.removeCallbacksAndMessages(null);
mainHandler.postDelayed(new Runnable() {
@Override
public void run() {
execute();
hadStart = true;
}
},200);
}, 200);
}
@Override
public void onResume() {
super.onResume();
LogUtil.d(TAG + "onResume hashCode=" + hashCode());
if (proxyView != null) {
proxyView.onResume();
}
// if (proxyView != null) {
// proxyView.onResume();
// }
}
@Override
public void onPause() {
super.onPause();
LogUtil.d(TAG + "onPause hashCode=" + hashCode());
if (proxyView != null) {
proxyView.onPause();
}
// if (proxyView != null) {
// proxyView.onPause();
// }
}
@Override
......@@ -102,10 +112,10 @@ public class DxActivity extends BaseActivity {
@Override
public void onDestroy() {
LogUtil.d(TAG + "onDestroy hashCode=" + hashCode());
if (proxyView != null) {
proxyView.onDestroy();
proxyView = null;
}
// if (proxyView != null) {
// proxyView.onDestroy();
// proxyView = null;
// }
mainHandler.removeCallbacksAndMessages(null);
......@@ -115,7 +125,7 @@ public class DxActivity extends BaseActivity {
Statistics.getInstance().onEvent(OutHelp.get().getContext(), EventUtils.OUT_DIALOG_EXPOSE_ONCE_STAY_TIME, null, map);
super.onDestroy();
DxManager.get().removeActivity(this);
// DxManager.get().removeActivity(this);
}
@Override
......@@ -124,10 +134,10 @@ public class DxActivity extends BaseActivity {
}
public void close() {
if (proxyView != null) {
proxyView.onDestroy();
proxyView = null;
}
// if (proxyView != null) {
// proxyView.onDestroy();
// proxyView = null;
// }
activity.finish();
}
......@@ -145,44 +155,44 @@ public class DxActivity extends BaseActivity {
private void statSLKStart(RemindersInfo remindersInfo, boolean isHide) {
Map<String, Object> map = new HashMap<>();
String type = "";
if (remindersInfo != null) {
type = String.valueOf(remindersInfo.reminderType);
}
// if (remindersInfo != null) {
// type = String.valueOf(remindersInfo.reminderType);
// }
map.put("type", type);
map.put("hide", String.valueOf(isHide));
Statistics.getInstance().dotEvent(activity, "slk_start", "", map);
}
private void execute() {
checkIntent();
// checkIntent();
startShowDialog();
}
private void checkIntent() {
adData = null;
remindersInfo = null;
adData = (OutAdData.NormalAdData) DxManager.get().getOutAdData();
LogUtil.d(TAG + "广告信息 =" + adData);
remindersInfo = DxManager.get().getOutRemindersInfo();
LogUtil.d(TAG + "弹窗信息 =" + remindersInfo);
}
// private void checkIntent() {
// adData = null;
// remindersInfo = null;
//
// adData = (OutAdData.NormalAdData) DxManager.get().getOutAdData();
// LogUtil.d(TAG + "广告信息 =" + adData);
//
// remindersInfo = DxManager.get().getOutRemindersInfo();
// LogUtil.d(TAG + "弹窗信息 =" + remindersInfo);
// }
private void startShowDialog() {
statSLKStart(remindersInfo, IconHelp.get().isIconHide());
if (remindersInfo == null) {
LogUtil.d(TAG + "finish remindersInfo为空");
close();
return;
}
statSLKStart(null, IconHelp.get().isIconHide());
if (remindersInfo.reminderType != Config.REMINDER_TYPE_WEATHER_PURE_AD && IconHelp.get().isIconHide()) {
LogUtil.d(TAG + "finish 不是纯广告并且隐藏了icon");
close();
return;
}
// if (remindersInfo == null) {
// LogUtil.d(TAG + "finish remindersInfo为空");
// close();
// return;
// }
//
// if (remindersInfo.reminderType != Config.REMINDER_TYPE_WEATHER_PURE_AD && IconHelp.get().isIconHide()) {
// LogUtil.d(TAG + "finish 不是纯广告并且隐藏了icon");
// close();
// return;
// }
Window window = activity.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_SECURE);
......@@ -192,15 +202,21 @@ public class DxActivity extends BaseActivity {
onceStayTime = System.currentTimeMillis();
LogUtil.d(TAG + "加载新的Dialog");
proxyView = DialogFactory.createDialog(remindersInfo, adData);
if (proxyView == null) {
LogUtil.d(TAG + "finish 5 View=null");
if (AdManagerV2.get().isAdReady()) {
AdManagerV2.get().showAd(activity);
} else {
close();
return;
}
proxyView.onCreate(activity, intent, rootView);
// LogUtil.d(TAG + "加载新的Dialog");
// proxyView = DialogFactory.createDialog(remindersInfo, adData);
//
// if (proxyView == null) {
// LogUtil.d(TAG + "finish 5 View=null");
// close();
// return;
// }
//
// proxyView.onCreate(activity, intent, rootView);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment