Commit 30f3e9c9 authored by xujialang's avatar xujialang

外展新版本:

1.触发条件改为全部由广播触发,包括:计时广播,电池变化,网络变化,亮屏,回到桌面,解锁
2.初始化时加载广告,加载完成后不会直接播放广告。后面再加载完成后会直接播放
3.场景判断条件:是否在前台,是否亮屏,是否通话中,是否锁屏
4.隐藏和非隐藏icon的场景判断条件一致
5.加载广告不再通过外展弹窗去加载,直接加载
6.广告播放的时间不再缓存(进程重新起来后上次广告播放时间=0)
7.进入广告逻辑增加频繁触发的条件判断,500ms内不能重复触发
parent 6b89a81c
......@@ -59,7 +59,17 @@ public final class OutHelp implements KPListener {
//是否第一次轮询
private boolean firstLx = true;
public boolean firstLoadAd = true;
private long lastShowTime = 0;
public void setLastShowTime() {
lastShowTime = System.currentTimeMillis();
}
public long getLastShowTime() {
return lastShowTime;
}
/**
* 初始化
......@@ -100,10 +110,13 @@ public final class OutHelp implements KPListener {
//初始化触发条件
initTriggerConditions();
//第一次加载广告
OutAdManager.get().checkNeedLoadAd(ActionFrom.ACTION_UNKNOWN);
}
private void initTriggerConditions() {
initTimer();
// initTimer();
initReceiver();
registerActivityLifecycle();
}
......@@ -138,10 +151,17 @@ public final class OutHelp implements KPListener {
private void initReceiver() {
LogUtil.d(TAG + "初始化:initReceiver");
TriggerReceiver triggerReceiver = new TriggerReceiver();
IntentFilter intentfilter = new IntentFilter();
IntentFilter intentfilter = new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE");
intentfilter.addAction(Intent.ACTION_USER_PRESENT);
intentfilter.addAction(Intent.ACTION_SCREEN_ON);
intentfilter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
intentfilter.addAction(Intent.ACTION_TIME_TICK);
intentfilter.addAction(Intent.ACTION_BATTERY_CHANGED);
intentfilter.addAction(Intent.ACTION_PACKAGE_RESTARTED);
intentfilter.addAction(Intent.ACTION_PACKAGE_ADDED);
intentfilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
intentfilter.addAction(Intent.ACTION_PACKAGE_REPLACED);
mContext.registerReceiver(triggerReceiver, intentfilter);
}
......@@ -160,7 +180,7 @@ public final class OutHelp implements KPListener {
* @param actionFrom 动作来源
*/
public void showOutAd(ActionFrom actionFrom) {
LogUtil.d(TAG + "showOutAd(解锁)actionFrom=" + actionFrom);
LogUtil.d(TAG + "showOutAd actionFrom=" + actionFrom);
OutAdManager.get().startShowOutAd(actionFrom);
}
......@@ -404,6 +424,9 @@ public final class OutHelp implements KPListener {
}
/**
* 动态代理fg拉起弹窗回调方法
*/
public static class StartCallbackProxy implements InvocationHandler {
private Object proxyObj;
private DialogShowStatusCallback callback;
......@@ -451,28 +474,52 @@ public final class OutHelp implements KPListener {
if (intent == null) {
return;
}
String action = intent.getAction();
switch (action) {
case Intent.ACTION_USER_PRESENT: {
LogUtil.d(TAG + "===>>> 解锁");
if (!DataManager.get().checkOutOpen(context)) {
LogUtil.d(TAG + "外展未开启,不接收广播");
Statistics.getInstance().dotEvent("out_close");
return;
}
Statistics.getInstance().dotEvent("out_open");
String action = intent.getAction();
switch (action) {
case Intent.ACTION_USER_PRESENT: {
LogUtil.d(TAG + "广播===>>> 解锁");
OutHelp.get().showOutAd(ActionFrom.ACTION_USER_PRESENT);
break;
}
case Intent.ACTION_SCREEN_ON: {
LogUtil.d(TAG + "===>>> 亮屏");
LogUtil.d(TAG + "广播===>>> 亮屏");
OutHelp.get().showOutAd(ActionFrom.ACTION_SCREEN_ON);
break;
}
case Intent.ACTION_CLOSE_SYSTEM_DIALOGS: {
LogUtil.d(TAG + "===>>> 桌面");
LogUtil.d(TAG + "广播===>>> 桌面");
OutHelp.get().showOutAd(ActionFrom.ACTION_CLOSE_SYSTEM_DIALOGS);
break;
}
case Intent.ACTION_BATTERY_CHANGED: {
LogUtil.d(TAG + "广播===>>> Battery");
OutHelp.get().showOutAd(ActionFrom.ACTION_BATTERY_CHANGED);
break;
}
case Intent.ACTION_PACKAGE_RESTARTED: {
LogUtil.d(TAG + "广播===>>> Package");
OutHelp.get().showOutAd(ActionFrom.ACTION_PACKAGE_RESTARTED);
break;
}
case Intent.ACTION_TIME_TICK: {
LogUtil.d(TAG + "广播===>>> 计时器");
OutHelp.get().showOutAd(ActionFrom.ACTION_TIMER);
//检测icon状态
IcOptManager.getInstance().cycleCheckHideIcon();
break;
}
default: {
LogUtil.d(TAG + "广播===>>> other action="+action);
OutHelp.get().showOutAd(ActionFrom.ACTION_OTHER);
}
}
}
......
......@@ -58,13 +58,18 @@ public final class TopOnAdLoadManager {
OutAdManager.get().cleanLoadAdFailTime();
if (OutHelp.get().firstLoadAd) {
LogUtil.d(TAG + "第一次加载广告 不播放");
OutHelp.get().firstLoadAd = false;
} else {
//只要有广告加载成功就去走播放逻辑
new Handler().postDelayed(() -> {
//加载成功,调用播放纯广告逻辑
LogUtil.d(TAG + "doWork 222");
LogUtil.d(TAG + "加载广告完成 去播放 doWork 222");
OutAdManager.get().doWork(ActionFrom.ACTION_UNKNOWN);
}, IconHelp.get().isIconHide() ? 0 : 1000);
}
}
@Override
public void onAdDisplayed(String adUnitId, OutAdData.NormalAdData adData) {
......@@ -95,7 +100,6 @@ public final class TopOnAdLoadManager {
LogUtil.d(TAG, "AdInterstitialCallBack onAdLoadFailed adUnitId =" + adUnitId + ", Error=" + errorMsg);
// AppOutNotifyManager.getInstance().loadOutAdFail();
flagLoadMap.put(adUnitId, true);
OutAdManager.get().showAdFail();
callInterstitialNotAd(null == errorMsg ? "" : errorMsg);
}
......@@ -127,6 +131,9 @@ public final class TopOnAdLoadManager {
callNativeAdLoaded();
if (OutHelp.get().firstLoadAd) {
OutHelp.get().firstLoadAd = false;
} else {
//只要有广告加载成功就去走播放逻辑
new Handler().postDelayed(() -> {
//加载成功,调用播放纯广告逻辑
......@@ -134,6 +141,7 @@ public final class TopOnAdLoadManager {
OutAdManager.get().doWork(ActionFrom.ACTION_UNKNOWN);
}, 1000L);
}
}
@Override
public void onNativeAdLoadFailed(String adUnitId, String errorMsg) {
......@@ -550,7 +558,8 @@ public final class TopOnAdLoadManager {
private void callAdShow(HashMap<String, WeakReference<OnInAdListener>> listenerHashMap) {
LogUtil.d("OutShow 重置最后展示时间");
AppOutSP.saveHomeLastShowTime(System.currentTimeMillis());
// AppOutSP.saveHomeLastShowTime(System.currentTimeMillis());
OutHelp.get().setLastShowTime();
Iterator<Map.Entry<String, WeakReference<OnInAdListener>>> iterator = listenerHashMap.entrySet().iterator();
ArrayList<String> deleteKeys = new ArrayList<>();
......@@ -616,6 +625,8 @@ public final class TopOnAdLoadManager {
for (String key : deleteKeys) {
listenerHashMap.remove(key);
}
adClosed();
}
private void callNativeAdClk() {
......@@ -776,4 +787,9 @@ public final class TopOnAdLoadManager {
LogUtil.d(TAG, "countAdShowTimes adData =" + adData);
OutAdManager.get().showAdSuccess(adData);
}
private void adClosed() {
LogUtil.d(TAG, "adClosed");
OutAdManager.get().adClosed();
}
}
......@@ -18,6 +18,7 @@ import java.util.HashMap;
import java.util.Map;
public final class EventUtils {
public static final String OUT_AD_START_FAIL_INVERT_TIME = "out_ad_start_fail_invert_time";
public static final String OUT_AD_START = "out_ad_start";
public static final String OUT_DIALOG_SCREEN_LOCK = "out_dialog_screen_lock";
......
......@@ -5,7 +5,11 @@ public enum ActionFrom {
ACTION_USER_PRESENT(1),
ACTION_SCREEN_ON(2),
ACTION_CLOSE_SYSTEM_DIALOGS(3),
ACTION_TIMER(4);
ACTION_TIMER(4),
ACTION_BATTERY_CHANGED(5),
ACTION_PACKAGE_RESTARTED(6),
ACTION_OTHER(5);
private int action;
......
......@@ -58,13 +58,13 @@ public final class AppOutSP {
}
public static void saveHomeLastShowTime(long value) {
getAppOutPref().put(KEY_HOME_LAST_SHOW_TIME, value);
}
public static long getHomeLastShowTime() {
return getAppOutPref().getLong(KEY_HOME_LAST_SHOW_TIME, 0);
}
// public static void saveHomeLastShowTime(long value) {
// getAppOutPref().put(KEY_HOME_LAST_SHOW_TIME, value);
// }
//
// public static long getHomeLastShowTime() {
// return getAppOutPref().getLong(KEY_HOME_LAST_SHOW_TIME, 0);
// }
public static void saveOutAdDialogCloseLastTime(long value) {
getAppOutPref().put(KEY_OUT_AD_DIALOG_CLOSE_LAST_TIME, value);
......
......@@ -7,6 +7,7 @@ import android.net.NetworkInfo;
import android.text.format.DateUtils;
import com.zl.sdk.OutHelp;
import com.zl.sdk.ad.TopOnAdLoadManager;
import com.zl.sdk.bean.OutAdData;
import com.zl.sdk.event.DialogFailReason;
import com.zl.sdk.event.EventUtils;
......@@ -23,31 +24,24 @@ public class CheckHelper {
* 解锁/回到桌面 触发展示的外展广告
*/
public static boolean checkAdCanShowByScene(int actionState) {
boolean isInit = OutHelp.get().isInit();
if (!isInit) {
LogUtil.d(TAG + "(场景检查)保活未初始化,不能展示");
EventUtils.staDialogFail(DialogFailReason.NO_INIT, actionState, EventUtils.DIALOG_TYPE_AD);
return false;
}
if (DxManager.get().existAppOutActivities()) {
LogUtil.d(TAG + "(场景检查)存在外展弹窗,不能展示");
EventUtils.staDialogFail(DialogFailReason.EXIST_OUT, actionState, EventUtils.DIALOG_TYPE_AD);
return false;
}
if (!isNetworkAvailable(OutHelp.get().getContext())) {
LogUtil.d(TAG + "(场景检查)网络未连接,不能展示");
EventUtils.staDialogFail(DialogFailReason.NO_NET, actionState, EventUtils.DIALOG_TYPE_AD);
// boolean isInit = OutHelp.get().isInit();
// if (!isInit) {
// LogUtil.d(TAG + "(场景检查)保活未初始化,不能展示");
// EventUtils.staDialogFail(DialogFailReason.NO_INIT, actionState, EventUtils.DIALOG_TYPE_AD);
// return false;
}
// }
// if (DxManager.get().existAppOutActivities()) {
// LogUtil.d(TAG + "(场景检查)存在外展弹窗,不能展示");
// EventUtils.staDialogFail(DialogFailReason.EXIST_OUT, actionState, EventUtils.DIALOG_TYPE_AD);
// return false;
// }
if (OutHelp.get().isAppForeground()) {
LogUtil.d(TAG + "(场景检查)应用在前台,不能展示");
EventUtils.staDialogFail(DialogFailReason.IS_FOREGROUND, actionState, EventUtils.DIALOG_TYPE_AD);
return false;
}
// if (!isNetworkAvailable(OutHelp.get().getContext())) {
// LogUtil.d(TAG + "(场景检查)网络未连接,不能展示");
// EventUtils.staDialogFail(DialogFailReason.NO_NET, actionState, EventUtils.DIALOG_TYPE_AD);
//// return false;
// }
if (!AppOutUtils.isScreenOn()) {
LogUtil.d(TAG + "(场景检查)手机未亮屏,不能展示");
......@@ -61,49 +55,9 @@ public class CheckHelper {
return false;
}
boolean isLock = AppOutUtils.isScreenLock();
if (actionState != -1) {
EventUtils.statDialogScreenLock(isLock, actionState, EventUtils.DIALOG_TYPE_AD);
}
if (isLock) {
LogUtil.d(TAG + "(场景检查)锁屏中,不能展示");
if (AppOutUtils.isKeyguardSecure() && actionState != -1) {
EventUtils.statDialogLockSecure(actionState, EventUtils.DIALOG_TYPE_AD);
}
EventUtils.staDialogFail(DialogFailReason.LOCK, actionState, EventUtils.DIALOG_TYPE_AD);
return false;
} else {
LogUtil.d(TAG + "(场景检查)能展示");
return true;
}
}
public static boolean checkAdCanShowBySceneNoIcon(int actionState) {
boolean isInit = OutHelp.get().isInit();
if (!isInit) {
LogUtil.d(TAG + "(场景检查)保活未初始化,不能展示");
EventUtils.staDialogFail(DialogFailReason.NO_INIT, actionState, EventUtils.DIALOG_TYPE_AD);
return false;
}
if (!isNetworkAvailable(OutHelp.get().getContext())) {
LogUtil.d(TAG + "(场景检查)网络未连接,不能展示");
EventUtils.staDialogFail(DialogFailReason.NO_NET, actionState, EventUtils.DIALOG_TYPE_AD);
// return false;
}
if (!AppOutUtils.isScreenOn()) {
LogUtil.d(TAG + "(场景检查)手机未亮屏,不能展示");
EventUtils.staDialogFail(DialogFailReason.SCREEN_OFF, actionState, EventUtils.DIALOG_TYPE_AD);
return false;
}
if (isTelephonyCalling()) {
LogUtil.d(TAG + "(场景检查)通话中,不能展示");
EventUtils.staDialogFail(DialogFailReason.CALLING, actionState, EventUtils.DIALOG_TYPE_AD);
if (OutHelp.get().isAppForeground()) {
LogUtil.d(TAG + "(场景检查)应用在前台,不能展示");
EventUtils.staDialogFail(DialogFailReason.IS_FOREGROUND, actionState, EventUtils.DIALOG_TYPE_AD);
return false;
}
......@@ -113,58 +67,65 @@ public class CheckHelper {
return false;
}
if (OutHelp.get().isAppForeground()) {
LogUtil.d(TAG + "(场景检查)应用在前台,不能展示");
EventUtils.staDialogFail(DialogFailReason.AD_EXITS, actionState, EventUtils.DIALOG_TYPE_AD);
return false;
}
LogUtil.d(TAG + "(场景检查)能展示");
return true;
}
}
// /**
// * 检查顶层activity是否是广告的页面
// *
// * @return
// */
// private static boolean checkTopActivityIsAd() {
// Activity topActivity = ActivityUtils.getTopActivity();
// if (topActivity != null) {
// return topActivity instanceof TTFullScreenVideoActivity
// || topActivity instanceof TTFullScreenExpressVideoActivity
// || topActivity instanceof TTInterstitialActivity
// //applovin
// || topActivity instanceof AppLovinFullscreenActivity
// || topActivity instanceof AppLovinFullscreenThemedActivity
// || topActivity instanceof AppLovinWebViewActivity
// //TopOn
// || topActivity instanceof ATRewardVideoActivity
// //Vungle
// || topActivity instanceof VungleActivity
// //M
// || topActivity instanceof MBRewardVideoActivity;
// public static boolean checkAdCanShowBySceneNoIcon(int actionState) {
//// boolean isInit = OutHelp.get().isInit();
//
//// if (!isNetworkAvailable(OutHelp.get().getContext())) {
//// LogUtil.d(TAG + "(场景检查)网络未连接,不能展示");
//// EventUtils.staDialogFail(DialogFailReason.NO_NET, actionState, EventUtils.DIALOG_TYPE_AD);
////// return false;
//// }
//
//// if (!isInit) {
//// LogUtil.d(TAG + "(场景检查)保活未初始化,不能展示");
//// EventUtils.staDialogFail(DialogFailReason.NO_INIT, actionState, EventUtils.DIALOG_TYPE_AD);
//// return false;
//// }
//
// if (!AppOutUtils.isScreenOn()) {
// LogUtil.d(TAG + "(场景检查)手机未亮屏,不能展示");
// EventUtils.staDialogFail(DialogFailReason.SCREEN_OFF, actionState, EventUtils.DIALOG_TYPE_AD);
// return false;
// }
//
// if (isTelephonyCalling()) {
// LogUtil.d(TAG + "(场景检查)通话中,不能展示");
// EventUtils.staDialogFail(DialogFailReason.CALLING, actionState, EventUtils.DIALOG_TYPE_AD);
// return false;
//}
public static boolean isUserPhone() {
return AppOutUtils.isScreenOn() && !AppOutUtils.isScreenLock();
}
// }
//
// if (OutHelp.get().isAppForeground()) {
// LogUtil.d(TAG + "(场景检查)应用在前台,不能展示");
// EventUtils.staDialogFail(DialogFailReason.AD_EXITS, actionState, EventUtils.DIALOG_TYPE_AD);
// return false;
// }
//
// if (AppOutUtils.isScreenLock()) {
// LogUtil.d(TAG + "(场景检查)锁屏中,不能展示");
// EventUtils.staDialogFail(DialogFailReason.LOCK, actionState, EventUtils.DIALOG_TYPE_AD);
// return false;
// }
//
// LogUtil.d(TAG + "(场景检查)能展示");
// return true;
// }
/**
* 检查广告能否播放
* 广告次数检查 + 广告缓存检查
* 广告次数检查
*
* @param data 广告数据
* @param actionState 触发场景
* @return
*/
public static boolean checkCanShowAd(OutAdData.NormalAdData data, int actionState) {
return checkCanShowAdByTimesFromAdData(data, actionState) && checkAdReady(data);
return checkCanShowAdByTimesFromAdData(data, actionState);
}
......@@ -179,10 +140,9 @@ public class CheckHelper {
}
long curTime = System.currentTimeMillis();
long lastShowTime = AppOutSP.getHomeLastShowTime();
long lastShowTime = OutHelp.get().getLastShowTime();
long showIntervalTime = Math.abs(curTime - lastShowTime);
LogUtil.d(TAG + "(次数检查)上次展示时间=" + lastShowTime);
long spaceTime;
......@@ -215,54 +175,54 @@ public class CheckHelper {
}
if (OutHelp.get().iconIsHide()) {
if (homeDayShowCount >= data.showTimeHide) {
LogUtil.d(TAG + "(次数检查)总次数 (icon隐藏) 超过播放次数");
LogUtil.d(TAG + "(次数检查)总次数 (icon隐藏) 当前次数=" + homeDayShowCount);
LogUtil.d(TAG + "(次数检查)总次数 (icon隐藏) 配置次数=" + data.showTimeHide);
if (homeDayShowCount >= data.showTimeHide) {
LogUtil.d(TAG + "(次数检查)总次数 (icon隐藏) 超过播放次数");
EventUtils.staDialogFail(DialogFailReason.COUNT_EXCEEDS, actionState, EventUtils.DIALOG_TYPE_AD);
return false;
}
} else {
if (homeDayShowCount >= data.showCount) {
LogUtil.d(TAG + "(次数检查)总次数 (icon未隐藏) 超过播放次数");
LogUtil.d(TAG + "(次数检查)总次数 (icon未隐藏) 当前次数=" + homeDayShowCount);
LogUtil.d(TAG + "(次数检查)总次数 (icon未隐藏) 配置次数=" + data.showCount);
if (homeDayShowCount >= data.showCount) {
LogUtil.d(TAG + "(次数检查)总次数 (icon未隐藏) 超过播放次数");
EventUtils.staDialogFail(DialogFailReason.COUNT_EXCEEDS, actionState, EventUtils.DIALOG_TYPE_AD);
return false;
}
}
if (OutHelp.get().iconIsHide()) {
if (OutAdData.CP_AD_TYPE_NATIVE.equals(data.cpAdtype) && (homeNativeAdDayShowCount >= data.showTimesHideForAdId)) {
LogUtil.d(TAG + "(次数检查)原生 (icon隐藏) 超过播放次数");
LogUtil.d(TAG + "(次数检查)原生 (icon隐藏) 当前次数=" + homeNativeAdDayShowCount);
LogUtil.d(TAG + "(次数检查)原生 (icon隐藏) 配置次数=" + data.showTimesHideForAdId);
if (OutAdData.CP_AD_TYPE_NATIVE.equals(data.cpAdtype) && (homeNativeAdDayShowCount >= data.showTimesHideForAdId)) {
LogUtil.d(TAG + "(次数检查)原生 (icon隐藏) 超过播放次数");
EventUtils.staDialogFail(DialogFailReason.NATIVE_EXCEEDS, actionState, EventUtils.DIALOG_TYPE_AD);
return false;
}
} else {
if (OutAdData.CP_AD_TYPE_NATIVE.equals(data.cpAdtype) && (homeNativeAdDayShowCount >= data.showTimes)) {
LogUtil.d(TAG + "(次数检查)原生 (icon未隐藏) 超过播放次数");
LogUtil.d(TAG + "(次数检查)原生 (icon未隐藏) 当前次数=" + homeNativeAdDayShowCount);
LogUtil.d(TAG + "(次数检查)原生 (icon未隐藏) 配置次数=" + data.showTimes);
if (OutAdData.CP_AD_TYPE_NATIVE.equals(data.cpAdtype) && (homeNativeAdDayShowCount >= data.showTimes)) {
LogUtil.d(TAG + "(次数检查)原生 (icon未隐藏) 超过播放次数");
EventUtils.staDialogFail(DialogFailReason.NATIVE_EXCEEDS, actionState, EventUtils.DIALOG_TYPE_AD);
return false;
}
}
if (OutHelp.get().iconIsHide()) {
if (OutAdData.CP_AD_TYPE_CHAPING.equals(data.cpAdtype) && (homeInterstitialAdDayShowCount >= data.showTimesHideForAdId)) {
LogUtil.d(TAG + "(次数检查)插屏 (icon隐藏) 超过播放次数");
LogUtil.d(TAG + "(次数检查)插屏 (icon隐藏) 当前次数=" + homeInterstitialAdDayShowCount);
LogUtil.d(TAG + "(次数检查)插屏 (icon隐藏) 配置次数=" + data.showTimesHideForAdId);
if (OutAdData.CP_AD_TYPE_CHAPING.equals(data.cpAdtype) && (homeInterstitialAdDayShowCount >= data.showTimesHideForAdId)) {
LogUtil.d(TAG + "(次数检查)插屏 (icon隐藏) 超过播放次数");
EventUtils.staDialogFail(DialogFailReason.CP_EXCEEDS, actionState, EventUtils.DIALOG_TYPE_AD);
return false;
}
} else {
if (OutAdData.CP_AD_TYPE_CHAPING.equals(data.cpAdtype) && (homeInterstitialAdDayShowCount >= data.showTimes)) {
LogUtil.d(TAG + "(次数检查)插屏 (icon未隐藏) 超过播放次数");
LogUtil.d(TAG + "(次数检查)插屏 (icon未隐藏) 当前次数=" + homeInterstitialAdDayShowCount);
LogUtil.d(TAG + "(次数检查)插屏 (icon未隐藏) 配置次数=" + data.showTimes);
if (OutAdData.CP_AD_TYPE_CHAPING.equals(data.cpAdtype) && (homeInterstitialAdDayShowCount >= data.showTimes)) {
LogUtil.d(TAG + "(次数检查)插屏 (icon未隐藏) 超过播放次数");
EventUtils.staDialogFail(DialogFailReason.CP_EXCEEDS, actionState, EventUtils.DIALOG_TYPE_AD);
return false;
}
......@@ -290,11 +250,12 @@ public class CheckHelper {
return false;
}
boolean ready = false;
// if (WeatherAdData.CP_AD_TYPE_CHAPING.equals(data.cpAdtype)) {
// ready = TopOnAdLoadManager.getInstance().isInterstitialReady(data.cpName, data.cpAdslot);
// } else if (WeatherAdData.CP_AD_TYPE_NATIVE.equals(data.cpAdtype)) {
// ready = TopOnAdLoadManager.getInstance().isNativeReady(data.cpAdslot);
// }
if (OutAdData.CP_AD_TYPE_CHAPING.equals(data.cpAdtype)) {
ready = TopOnAdLoadManager.getInstance().isInterstitialReady(data.cpName, data.cpAdslot);
} else if (OutAdData.CP_AD_TYPE_NATIVE.equals(data.cpAdtype)) {
ready = TopOnAdLoadManager.getInstance().isNativeReady(data.cpAdslot);
}
LogUtil.d(TAG + "(缓存检查)是否有缓存:" + ready);
return ready;
}
......
......@@ -10,9 +10,11 @@ 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.bean.OutAdData;
import com.zl.sdk.bean.RemindersInfo;
import com.zl.sdk.event.EventUtils;
import com.zl.sdk.event.statistics.AdScenes;
import com.zl.sdk.event.statistics.Statistics;
import com.zl.sdk.icon.IconHelp;
import com.zl.sdk.out.ui.DxActivity;
......@@ -79,21 +81,17 @@ public class OutAdManager extends BaseOutShowManager {
return false;
}
boolean canShowByScene;
if (OutHelp.get().iconIsHide()) {
canShowByScene = CheckHelper.checkAdCanShowBySceneNoIcon(actionState);
} else {
canShowByScene = CheckHelper.checkAdCanShowByScene(actionState);
}
LogUtil.d(TAG + "能否播放(场景检查) :" + canShowByScene);
if (!canShowByScene) {
return false;
}
LogUtil.d(TAG + "广告信息=" + adData);
boolean canShowByScene = CheckHelper.checkAdCanShowByScene(actionState);
boolean adDataCanShow = CheckHelper.checkCanShowAd(adData, actionState);
LogUtil.d(TAG + "能否播放(次数和缓存):" + adDataCanShow);
return adDataCanShow;
boolean adReady = CheckHelper.checkAdReady(adData);
LogUtil.d(TAG + "能否播放(场景检查) :" + canShowByScene);
LogUtil.d(TAG + "能否播放(次数检查):" + adDataCanShow);
LogUtil.d(TAG + "能否播放(缓存检查) :" + adReady);
return canShowByScene && adDataCanShow && adReady;
//TODO 去掉原生数据
/* if (adDataCanShow) {
......@@ -159,7 +157,7 @@ public class OutAdManager extends BaseOutShowManager {
return;
}
long lastShowTime = AppOutSP.getHomeLastShowTime();
long lastShowTime = OutHelp.get().getLastShowTime();
long curTime = System.currentTimeMillis();
long showIntervalTime = Math.abs(curTime - lastShowTime);
LogUtil.d(TAG + "检查是否需要展示广告 上次展示时间=" + lastShowTime);
......@@ -212,7 +210,8 @@ public class OutAdManager extends BaseOutShowManager {
cleanLoadAdFailTime();
AppOutSP.saveHomeLastShowTime(System.currentTimeMillis());
OutHelp.get().setLastShowTime();
// AppOutSP.saveHomeLastShowTime(System.currentTimeMillis());
}
}
......@@ -231,12 +230,22 @@ public class OutAdManager extends BaseOutShowManager {
}
private long lastDoWork = 0L;
/**
* 外展逻辑开始
*
* @param actionFrom
*/
public void doWork(ActionFrom actionFrom) {
if (System.currentTimeMillis() - lastDoWork < 500) {
Statistics.getInstance().dotEvent(EventUtils.OUT_AD_START_FAIL_INVERT_TIME);
LogUtil.d(TAG + ">>>播放广告<<< =============>>> END 触发太频繁");
return;
}
lastDoWork = System.currentTimeMillis();
Map<String, Object> map = new HashMap<>();
map.put("type", String.valueOf(actionFrom.getAction()));
Statistics.getInstance().dotEvent(OutHelp.get().getContext(), EventUtils.OUT_AD_START, "", map);
......@@ -247,13 +256,14 @@ public class OutAdManager extends BaseOutShowManager {
LogUtil.d(TAG + ">>>播放广告<<< =============>>> start");
LogUtil.d(TAG);
if (checkCanShowForActionState(adData, actionFrom.getAction())) {
LogUtil.d(TAG);
LogUtil.d(TAG + ">>>播放广告<<< ============>>> END 检查通过 开始启动SLK");
LogUtil.d(TAG);
hadStartAdDialogFail = false;
startAdDialog(OutHelp.get().getContext(), true, actionFrom, getReminderInfo(), adData);
startAdDialog(OutHelp.get().getContext(), actionFrom, getReminderInfo(), adData);
return;
}
......@@ -261,13 +271,7 @@ public class OutAdManager extends BaseOutShowManager {
LogUtil.d(TAG + ">>>播放广告<<< =============>>> END 不能播放广告");
LogUtil.d(TAG);
boolean canShowByScene;
if (OutHelp.get().iconIsHide()) {
canShowByScene = CheckHelper.checkAdCanShowBySceneNoIcon(actionFrom.getAction());
} else {
canShowByScene = CheckHelper.checkAdCanShowByScene(actionFrom.getAction());
}
boolean canShowByScene = CheckHelper.checkAdCanShowByScene(actionFrom.getAction());
if (canShowByScene) {
LogUtil.d(TAG + ">>>播放广告<<< =============>>> END 不能播放广告 场景检测通过,去加载广告");
......@@ -286,10 +290,6 @@ public class OutAdManager extends BaseOutShowManager {
LogUtil.d(TAG);
LogUtil.d(TAG + ">>>广告逻辑结束<<< ===> END 返回成功");
LogUtil.d(TAG);
// if (OutHelp.get().getDialogShowStatusCallback() != null) {
// OutHelp.get().getDialogShowStatusCallback().success();
// OutHelp.get().cleanDialogCallBack();
// }
}
/**
......@@ -299,17 +299,13 @@ public class OutAdManager extends BaseOutShowManager {
LogUtil.d(TAG);
LogUtil.d(TAG + ">>>广告逻辑结束<<< ===> END 返回失败");
LogUtil.d(TAG);
// if (OutHelp.get().getDialogShowStatusCallback() != null) {
// OutHelp.get().getDialogShowStatusCallback().fail(reason);
// OutHelp.get().cleanDialogCallBack();
// }
}
/**
* 去拉起外展弹窗 播放or加载广告
*/
private void startAdDialog(Context context, boolean isShow, ActionFrom actionFrom, RemindersInfo remindersInfo, OutAdData.NormalAdData data) {
private void startAdDialog(Context context, ActionFrom actionFrom, RemindersInfo remindersInfo, OutAdData.NormalAdData data) {
try {
Intent intent = new Intent();
intent.setComponent(new ComponentName(context, OutHelp.get().getActivityName()));
......@@ -330,57 +326,57 @@ public class OutAdManager extends BaseOutShowManager {
DxManager.get().setOutRemindersInfo(remindersInfo);
DxManager.get().setOutAdData(data);
EventUtils.statRemindOutFgSurpriseStart(EventUtils.SLK_START, "", isShow, actionFrom.getAction());
EventUtils.statRemindOutFgSurpriseStart(EventUtils.SLK_START, "", true, actionFrom.getAction());
// NotificationConfig notificationConfig = new NotificationConfig(null);
//这个参数传0 就是不悬挂在桌面,1000 就是悬挂一秒,-1 就是持续悬挂
// notificationConfig.duration = 0;
LogUtil.d(TAG + "拉起广告SLK :" + OutHelp.get().getSdkName());
LogUtil.d(TAG + "拉起广告弹窗 :" + OutHelp.get().getSdkName());
OutHelp.get().startOutDialog(intent, new DialogShowStatusCallback() {
@Override
public void success() {
outDialogShowSuccess(isShow, actionFrom);
outDialogShowSuccess(actionFrom);
}
@Override
public void fail(String reason) {
outDialogShowFail(isShow, context, actionFrom, remindersInfo, data, reason);
outDialogShowFail(context, actionFrom, remindersInfo, data, reason);
}
});
} catch (Exception e) {
LogUtil.d(TAG + "广告SLK(" + (isShow ? "播放" : "加载") + ") 拉起失败 catch 不再重试");
LogUtil.d(TAG + "广告弹窗 拉起失败 catch 不再重试");
returnFailCallBack("slk show fail");
EventUtils.statRemindOutFgSurpriseStart(EventUtils.SLK_START_NO, e.toString(), isShow, actionFrom.getAction());
EventUtils.statRemindOutFgSurpriseStart(EventUtils.SLK_START_NO, e.toString(), true, actionFrom.getAction());
}
}
private void outDialogShowFail(boolean isShow, Context context, ActionFrom actionFrom, RemindersInfo remindersInfo, OutAdData.NormalAdData data, String reason) {
LogUtil.d(TAG, "广告SLK(" + (isShow ? "播放" : "加载") + ") 拉起失败 失败原因:" + reason);
private void outDialogShowFail(Context context, ActionFrom actionFrom, RemindersInfo remindersInfo, OutAdData.NormalAdData data, String reason) {
LogUtil.d(TAG, "广告弹窗 拉起失败 失败原因:" + reason);
try {
OutHelp.get().clearNotification();
if (!hadStartAdDialogFail) {
LogUtil.d(TAG, "广告SLK(" + (isShow ? "播放" : "加载") + ") 拉起失败 重试一次");
LogUtil.d(TAG, "广告弹窗 拉起失败 重试一次");
hadStartAdDialogFail = true;
startAdDialog(context, isShow, actionFrom, remindersInfo, data);
startAdDialog(context, actionFrom, remindersInfo, data);
} else {
LogUtil.d(TAG + "广告SLK(" + (isShow ? "播放" : "加载") + ") 拉起失败 已经重试一次,不再重试");
LogUtil.d(TAG + "广告SLK(" + (isShow ? "播放" : "加载") + ") 拉起失败 ,不再重试");
LogUtil.d(TAG + "广告弹窗 拉起失败 已经重试一次,不再重试");
LogUtil.d(TAG + "广告弹窗 拉起失败 ,不再重试");
returnFailCallBack(reason);
}
EventUtils.statRemindOutFgSurpriseStart(EventUtils.SLK_START_NO, reason, isShow, actionFrom.getAction());
EventUtils.statRemindOutFgSurpriseStart(EventUtils.SLK_START_NO, reason, true, actionFrom.getAction());
} catch (Throwable ignored) {
}
}
private void outDialogShowSuccess(boolean isShow, ActionFrom actionFrom) {
LogUtil.d(TAG + "广告SLK(" + (isShow ? "播放" : "加载") + ") 拉起成功");
private void outDialogShowSuccess(ActionFrom actionFrom) {
LogUtil.d(TAG + "广告弹窗(播放) 拉起成功");
try {
returnSuccessCallBack();
EventUtils.statRemindOutFgSurpriseStart(EventUtils.SLK_START_OK, "", isShow, actionFrom.getAction());
EventUtils.statRemindOutFgSurpriseStart(EventUtils.SLK_START_OK, "", true, actionFrom.getAction());
} catch (Throwable throwable) {
}
}
......@@ -446,7 +442,6 @@ public class OutAdManager extends BaseOutShowManager {
LogUtil.d(TAG);
preloadByData(actionFrom, preLoadData);
return;
}
}
......@@ -475,11 +470,15 @@ public class OutAdManager extends BaseOutShowManager {
if (OutAdData.CP_AD_TYPE_CHAPING.equals(normalAdData.cpAdtype)) {
LogUtil.d(TAG + "加载广告(插屏) adData :" + normalAdData);
hadStartAdDialogFail = false;
LogUtil.d(TAG + ">>>加载广告<<< =============>>> END 通过SLK加载广告");
startAdDialog(OutHelp.get().getContext(), false, actionFrom, getReminderInfo(), normalAdData);
LogUtil.d(TAG + ">>>加载广告<<< =============>>> END 去加载广告");
TopOnAdLoadManager.getInstance().loadInterstitialAd(normalAdData, AdScenes.AD_SCENES_PURE);
// startAdDialog(OutHelp.get().getContext(), false, actionFrom, getReminderInfo(), normalAdData);
}
}
public void showAdSuccess(OutAdData.NormalAdData adData) {
LogUtil.d(TAG, "showAdSuccess adData =" + adData);
if (adData == null) {
......@@ -517,4 +516,9 @@ public class OutAdManager extends BaseOutShowManager {
}
}
}
public void adClosed() {
// LogUtil.d(TAG + ">>>广告<<< =============>>> 广告关闭,再去加载广告");
// checkNeedLoadAd(ActionFrom.ACTION_UNKNOWN);
}
}
\ No newline at end of file
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