Commit 1e39f373 authored by shenpc's avatar shenpc

优化代码

parent b28738d9
......@@ -133,7 +133,7 @@ public final class OutHelp implements KPListener {
LogUtil.d(TAG + ", 定时触发 !");
showOutAd(ActionFrom.ACTION_TIMER);
}
}, 0, 60 * 1000);
}, 5, 60 * 1000);
}
private void initReceiver() {
......
package com.zl.sdk.ad;
import android.app.Activity;
import android.text.TextUtils;
import com.anythink.core.api.ATAdInfo;
import com.anythink.core.api.ATAdStatusInfo;
......@@ -11,16 +12,18 @@ 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.event.statistics.Statistics;
import com.zl.sdk.out.AppOutSP;
import com.zl.sdk.util.AppOutUtils;
import com.zl.sdk.util.LogUtil;
import java.lang.ref.WeakReference;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public class AdManagerV2 implements ATInterstitialListener {
private volatile ATInterstitial atInterstitial = null;
private WeakReference<OnInAdListener> mListener = null;
private OnInAdListener mListener = null;
private int reloadCount = 3;
......@@ -95,8 +98,9 @@ public class AdManagerV2 implements ATInterstitialListener {
requestTime = System.currentTimeMillis();
EventUtils.statAdReport(getReportRequestBean(adId));
LogUtil.d("OutShow", "Topon: ad show mListener=" + mListener);
if (mListener != null) {
mListener.get().onShow();
mListener.onShow();
}
}
......@@ -105,7 +109,8 @@ public class AdManagerV2 implements ATInterstitialListener {
LogUtil.d("OutShow", "Topon: ad close");
EventUtils.statAdClose(getReportBean(atAdInfo, null));
if (mListener != null) {
mListener.get().onCloseAd();
mListener.onCloseAd();
removeListener();
}
}
......@@ -128,7 +133,8 @@ public class AdManagerV2 implements ATInterstitialListener {
EventUtils.statDisplayFail(getReportBean(null, builder));
if (mListener != null) {
mListener.get().showFail();
mListener.showFail();
removeListener();
}
}
......@@ -137,6 +143,7 @@ public class AdManagerV2 implements ATInterstitialListener {
adId = id;
if (atInterstitial != null) {
ATAdStatusInfo atAdStatusInfo = atInterstitial.checkAdStatus();
LogUtil.d("OutShow", "atAdStatusInfo :" + atAdStatusInfo );
if (atAdStatusInfo.isReady()) {
LogUtil.d("OutShow", "ad isReady!");
return false;
......@@ -163,10 +170,29 @@ public class AdManagerV2 implements ATInterstitialListener {
public void showAd(Activity activity, OnInAdListener listener) {
LogUtil.d("OutShow", "Topon: showAd");
mListener = new WeakReference<>(listener);
mListener = listener;
ATInterstitial.entryAdScenario("111", "");
atInterstitial.show(activity);
statCallShow(activity);
}
public void removeListener() {
mListener = null;
}
private void statCallShow(Activity activity) {
try {
Map<String, Object> para = new HashMap<>();
para.put("screen_state", String.valueOf(AppOutUtils.isScreenOn()));
para.put("foreground", OutHelp.get().isAppForeground());
String adPage = OutHelp.get().getPage();
if (!TextUtils.isEmpty(adPage)) {
para.put("page", adPage);
}
Statistics.getInstance().dotEvent(activity, "ad_call_show", "", para);
} catch (Exception e) {
}
}
......
......@@ -23,8 +23,7 @@ public class CheckHelper {
* 解锁/回到桌面 触发展示的外展广告
*/
public static boolean checkAdCanShowByScene(int actionState, String scenes) {
if ((actionState == ActionFrom.ACTION_TIMER.getAction()
|| actionState == ActionFrom.ACTION_BATTERY_CHANGED.getAction())
if ((actionState == ActionFrom.ACTION_TIMER.getAction())
&& !AppOutUtils.isScreenOn()) {
LogUtil.d(TAG + "(场景检查)手机未亮屏,不能展示");
EventUtils.staDialogFail(DialogFailReason.SCREEN_OFF, actionState, scenes, EventUtils.DIALOG_TYPE_AD);
......
......@@ -5,6 +5,7 @@ import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;
......@@ -96,6 +97,7 @@ public class DxActivity extends BaseActivity {
LogUtil.d(TAG + "onDestroy hashCode=" + hashCode());
mainHandler.removeCallbacksAndMessages(null);
AdManagerV2.get().removeListener();
final long time = Math.abs(onceStayTime - System.currentTimeMillis());
Map<String, Object> map = new HashMap<>();
......@@ -110,7 +112,11 @@ public class DxActivity extends BaseActivity {
}
public void close() {
try {
activity.finish();
} catch (Throwable e) {
LogUtil.d(TAG + "close e=" + Log.getStackTraceString(e));
}
}
public void finishAndRemoveTask() {
......@@ -150,16 +156,18 @@ public class DxActivity extends BaseActivity {
AdManagerV2.get().showAd(activity, new OnInAdListener() {
@Override
public void onCloseAd() {
LogUtil.d(TAG + "onCloseAd");
close();
}
@Override
public void onShow() {
LogUtil.d(TAG + "onShow");
}
@Override
public void showFail() {
LogUtil.d(TAG + "showFail");
close();
}
});
......
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