Commit 4fe678f9 authored by jyx's avatar jyx

添加插屏广告

parent e7b0ce9f
...@@ -68,6 +68,7 @@ android { ...@@ -68,6 +68,7 @@ android {
buildConfigField "String", "GROMORE_EXPRESS_CODE", GROMORE_EXPRESS_CODE buildConfigField "String", "GROMORE_EXPRESS_CODE", GROMORE_EXPRESS_CODE
buildConfigField "String", "GROMORE_MY_EXPRESS_CODE", GROMORE_MY_EXPRESS_CODE buildConfigField "String", "GROMORE_MY_EXPRESS_CODE", GROMORE_MY_EXPRESS_CODE
buildConfigField "String", "GROMORE_BANNER_CODE", GROMORE_BANNER_CODE buildConfigField "String", "GROMORE_BANNER_CODE", GROMORE_BANNER_CODE
buildConfigField "String", "GROMORE_FULL_CODE", GROMORE_FULL_CODE
buildConfigField "String", "RELEASE_TALKING_DATA_KEY", RELEASE_TALKING_DATA_KEY buildConfigField "String", "RELEASE_TALKING_DATA_KEY", RELEASE_TALKING_DATA_KEY
buildConfigField "String", "WEIXIN_APP_PAY_ID", WEIXIN_APP_PAY_ID buildConfigField "String", "WEIXIN_APP_PAY_ID", WEIXIN_APP_PAY_ID
...@@ -92,6 +93,7 @@ android { ...@@ -92,6 +93,7 @@ android {
buildConfigField "String", "GROMORE_EXPRESS_CODE", GROMORE_EXPRESS_CODE buildConfigField "String", "GROMORE_EXPRESS_CODE", GROMORE_EXPRESS_CODE
buildConfigField "String", "GROMORE_MY_EXPRESS_CODE", GROMORE_MY_EXPRESS_CODE buildConfigField "String", "GROMORE_MY_EXPRESS_CODE", GROMORE_MY_EXPRESS_CODE
buildConfigField "String", "GROMORE_BANNER_CODE", GROMORE_BANNER_CODE buildConfigField "String", "GROMORE_BANNER_CODE", GROMORE_BANNER_CODE
buildConfigField "String", "GROMORE_FULL_CODE", GROMORE_FULL_CODE
buildConfigField "String", "RELEASE_TALKING_DATA_KEY", RELEASE_TALKING_DATA_KEY buildConfigField "String", "RELEASE_TALKING_DATA_KEY", RELEASE_TALKING_DATA_KEY
buildConfigField "String", "WEIXIN_APP_PAY_ID", WEIXIN_APP_PAY_ID buildConfigField "String", "WEIXIN_APP_PAY_ID", WEIXIN_APP_PAY_ID
......
package com.mints.helivideo.ad package com.mints.helivideo.ad
import android.app.Activity import android.app.Activity
import com.mints.helivideo.ad.splash.SplashManager import com.mints.helivideo.ad.full.FullScreenManager
import com.mints.helivideo.ad.video.InMoneyVideo import com.mints.helivideo.ad.video.InMoneyVideo
import com.mints.helivideo.manager.UserManager
/** /**
* 预加载-全屏及激励视频管理类 * 预加载-全屏及激励视频管理类
...@@ -21,6 +20,8 @@ class AdManager { ...@@ -21,6 +20,8 @@ class AdManager {
} }
/** /**
* 激励视频
*
* 根据服务器概率预加载广告 * 根据服务器概率预加载广告
* *
* isPreLoad:是否是预加载调用,需要躲避监听 * isPreLoad:是否是预加载调用,需要躲避监听
...@@ -30,6 +31,8 @@ class AdManager { ...@@ -30,6 +31,8 @@ class AdManager {
} }
/** /**
* 激励视频
*
* 根据预加载类型 展示广告 * 根据预加载类型 展示广告
*/ */
fun showAd( fun showAd(
...@@ -37,11 +40,31 @@ class AdManager { ...@@ -37,11 +40,31 @@ class AdManager {
carrierType: String, carrierType: String,
AdStatusListener: AdStatusListener?, AdStatusListener: AdStatusListener?,
) { ) {
InMoneyVideo.getInstance() InMoneyVideo.getInstance().showRewardAd(activity, AdStatusListener, carrierType)
.showRewardAd( }
activity,
AdStatusListener,
carrierType, /**
) * 插全屏
*
* 根据服务器概率预加载广告
*
* isPreLoad:是否是预加载调用,需要躲避监听
*/
fun preLoadFullAd(activity: Activity, isPreLoad: Boolean = false) {
FullScreenManager.getInstance().preLoadAd(activity, isPreLoad)
}
/**
* 插全屏
*
* 根据预加载类型 展示广告
*/
fun showFullAd(
activity: Activity,
carrierType: String,
AdStatusListener: AdStatusListener?,
) {
FullScreenManager.getInstance().showAd(activity, AdStatusListener, carrierType)
} }
} }
\ No newline at end of file
package com.mints.helivideo.ad package com.mints.helivideo.ad
import android.app.Activity import android.app.Activity
import com.mints.helivideo.ad.full.NoPreFullScreenManager
import com.mints.helivideo.ad.video.InMoneyVideoNoPre import com.mints.helivideo.ad.video.InMoneyVideoNoPre
import java.util.HashMap import java.util.HashMap
...@@ -11,6 +12,9 @@ object NoPreAdManager { ...@@ -11,6 +12,9 @@ object NoPreAdManager {
private val TAG = NoPreAdManager::class.java.simpleName private val TAG = NoPreAdManager::class.java.simpleName
/**
* 激励视频
*/
fun loadVideoAd( fun loadVideoAd(
activity: Activity, activity: Activity,
carrierType: String, carrierType: String,
...@@ -26,11 +30,37 @@ object NoPreAdManager { ...@@ -26,11 +30,37 @@ object NoPreAdManager {
} }
override fun adClose(vo : HashMap<String, Any>?) { override fun adClose(vo: HashMap<String, Any>?) {
listener?.adClose(vo) listener?.adClose(vo)
} }
} }
InMoneyVideoNoPre.getInstance().loadAd(activity, adNoProListener, carrierType) InMoneyVideoNoPre.getInstance().loadAd(activity, adNoProListener, carrierType)
} }
/**
* 插全屏
*/
fun loadFullAd(
activity: Activity,
carrierType: String,
listener: AdStatusListener?
) {
val adNoProListener = object : AdStatusListener {
override fun adFail() {
listener?.adFail()
}
override fun adSuccess() {
listener?.adSuccess()
}
override fun adClose(vo: HashMap<String, Any>?) {
listener?.adClose(vo)
}
}
NoPreFullScreenManager.getInstance().loadAd(activity, adNoProListener, carrierType)
}
} }
\ No newline at end of file
package com.mints.helivideo.ad.full;
import android.app.Activity;
import com.bytedance.sdk.openadsdk.AdSlot;
import com.bytedance.sdk.openadsdk.TTAdConstant;
import com.bytedance.sdk.openadsdk.TTAdNative;
import com.bytedance.sdk.openadsdk.TTAdSdk;
import com.bytedance.sdk.openadsdk.TTFullScreenVideoAd;
import com.bytedance.sdk.openadsdk.mediation.ad.MediationAdSlot;
import com.mints.helivideo.BuildConfig;
import com.mints.helivideo.ad.AdManager;
import com.mints.helivideo.ad.AdStatusListener;
import com.mints.helivideo.common.Constant;
import com.mints.helivideo.utils.AppPreferencesManager;
import com.mints.helivideo.utils.LogUtil;
import com.mints.helivideo.utils.TimeRender;
import java.lang.ref.WeakReference;
import java.util.HashMap;
/**
* GroMore 插全屏广告
* <p>
* 注意*****这个类有预加载逻辑,不能复用
*/
public class FullScreenManager {
private static final String TAG = FullScreenManager.class.getSimpleName();
private static FullScreenManager _inst;
public static FullScreenManager getInstance() {
if (_inst == null) {
_inst = new FullScreenManager();
}
return _inst;
}
private FullScreenManager() {
}
private String carrierType = "";
// 当前播放的广告
private String nowAdcode = "";
private String nowEcpm = "";
private String nowAdSource = "";
private int isLoadSuccess = 0; // 0-加载失败/未加载 1-加载中 2-加载成功
private long adLoadTime = 0; // 广告展示时间,45分钟后当前广告失效,重新预加载广告
private long adPreingTime = 0; // 防止预加载超时 2分钟
private TTFullScreenVideoAd mTtFullScreenVideoAd;
private WeakReference<Activity> weakActivity;
private boolean isPreLoad = false;//是否是预加载调用,需要躲避监听
private AdStatusListener adStatusListener;
/**
* 插全屏
*/
public void preLoadAd(Activity activity, boolean isPreLoad) {
this.isPreLoad = isPreLoad;
boolean isOversped = TimeRender.INSTANCE.isOverspedMin(adLoadTime, AdManager.AD_NO_SHOWTIME_OUT);
boolean isPreingOversped = TimeRender.INSTANCE.isOverspedMin(adPreingTime, AdManager.AD_REQUEST_TIME_OUT);
this.weakActivity = new WeakReference(activity);
LogUtil.d(TAG, "gromore预加载 插全屏广告-> 1、进入预加载 isPreLoad[为true是预加载调用]=" + isPreLoad);
if ((isLoadSuccess == 0 // 加载失败
|| (adLoadTime > 0 && isOversped) // 超过45分钟
|| (adPreingTime > 0 && isPreingOversped
&& isLoadSuccess == 1)) // 预加载超时
&& this.weakActivity.get() != null) {
adPreingTime = System.currentTimeMillis();
isLoadSuccess = 1;
LogUtil.d(TAG, "gromore预加载 插全屏广告-> 2、执行预加载去了=" + isLoadSuccess);
preLoadAd(activity);
}
}
public void showAd(Activity _activity, AdStatusListener adStatusListener
, String carrier) {
this.carrierType = carrier;
this.adStatusListener = adStatusListener;
this.weakActivity = new WeakReference(_activity);
if (isLoadSuccess == 0) {
LogUtil.e(TAG, "gromore预加载 插全屏广告--> showRewardAd isLoadSuccess=" + isLoadSuccess);
if (this.adStatusListener != null)
this.adStatusListener.adFail();
return;
}
// 请求未超过1分钟且上一个广告还在异步加载中,这次触发展示广告回调还没回来则返回
boolean isPreingOversped = TimeRender.INSTANCE.isOverspedMin(adPreingTime, AdManager.AD_REQUEST_TIME_OUT);
if (isLoadSuccess == 1 && isPreingOversped) {
LogUtil.e(TAG, "gromore预加载 插全屏广告-->请求未超过1分钟且上一个广告还在异步加载中 isLoadSuccess=" + isLoadSuccess + " isPreingOversped=" + isPreingOversped);
if (this.adStatusListener != null)
this.adStatusListener.adFail();
return;
}
// 预加载广告成功 且 预加载广告时长未超过45分钟
boolean isOversped = TimeRender.INSTANCE.isOverspedMin(adLoadTime, AdManager.AD_NO_SHOWTIME_OUT);
if (isLoadSuccess == 2 && !isOversped && mTtFullScreenVideoAd != null
&& mTtFullScreenVideoAd.getMediationManager().isReady()
&& this.weakActivity.get() != null) {
mTtFullScreenVideoAd.showFullScreenVideoAd(weakActivity.get());
mTtFullScreenVideoAd.setFullScreenVideoAdInteractionListener(mTTFullScreenAdListener);
} else {
if (this.adStatusListener != null)
this.adStatusListener.adFail();
LogUtil.e(TAG, "gromore预加载 插全屏广告--> 5、展示广告时失败了,广告可能超时45分钟 onError ");
}
// 广告加载完成状态重置
isLoadSuccess = 0;
}
private void preLoadAd(Activity activity) {
TTAdNative adNativeLoader = TTAdSdk.getAdManager().createAdNative(activity);
AdSlot adSlot = new AdSlot.Builder()
.setCodeId(BuildConfig.GROMORE_FULL_CODE)
.setOrientation(TTAdConstant.ORIENTATION_VERTICAL)
.setMediationAdSlot(
new MediationAdSlot.Builder()
.setMuted(false)
.setVolume(0.7f)
.setBidNotify(true)
.build()
).build();
adNativeLoader.loadFullScreenVideoAd(adSlot, new TTAdNative.FullScreenVideoAdListener() {
@Override
public void onError(int i, String s) {
isLoadSuccess = 0;
LogUtil.e(TAG, "gromore预加载 插全屏广告-->onError " + i + s + "isPreLoad[为true是预加载调用]=" + isPreLoad);
// isPreLoad=true 表示是预加载调用 不需要调用监听回调
if (!isPreLoad) {
if (adStatusListener != null) {
adStatusListener.adFail();
}
}
isPreLoad = false;
}
@Override
public void onFullScreenVideoAdLoad(TTFullScreenVideoAd ttFullScreenVideoAd) {
}
@Override
public void onFullScreenVideoCached() {
}
@Override
public void onFullScreenVideoCached(TTFullScreenVideoAd ttFullScreenVideoAd) {
LogUtil.d(TAG, "gromore预加载 插全屏广告--> 4、onRewardVideoCached ");
isLoadSuccess = 2;
adLoadTime = System.currentTimeMillis();
if (adStatusListener != null) {
adStatusListener.adSuccess();
}
mTtFullScreenVideoAd = ttFullScreenVideoAd;
}
});
}
private final TTFullScreenVideoAd.FullScreenVideoAdInteractionListener mTTFullScreenAdListener = new TTFullScreenVideoAd.FullScreenVideoAdInteractionListener() {
@Override
public void onAdShow() {
if (mTtFullScreenVideoAd != null) {
if (mTtFullScreenVideoAd.getMediationManager().getShowEcpm() != null) {
nowAdcode = mTtFullScreenVideoAd.getMediationManager().getShowEcpm().getSlotId();
nowEcpm = mTtFullScreenVideoAd.getMediationManager().getShowEcpm().getEcpm();
nowAdSource = mTtFullScreenVideoAd.getMediationManager().getShowEcpm().getSdkName();
}
}
LogUtil.d(TAG, "gromore预加载 插全屏广告-->onAdShow");
if (weakActivity.get() != null) {
LogUtil.d(TAG, "gromore预加载 插全屏广告->onAdShow 触发预加载下次广告");
AdManager.Companion.getInstance().preLoadAd(weakActivity.get(), true);
}
}
@Override
public void onAdVideoBarClick() {
LogUtil.d(TAG, "gromore预加载 插全屏广告-->onAdVideoBarClick");
}
@Override
public void onAdClose() {
LogUtil.d(TAG, "gromore预加载 插全屏广告-->onAdClose");
int adCount = AppPreferencesManager.INSTANCE.get().getInt(Constant.VEDIO_AD_COUNT, 0);
if (adCount < 50) {
AppPreferencesManager.INSTANCE.get().put(Constant.VEDIO_AD_COUNT, adCount + 1);
}
HashMap<String, Object> vo = new HashMap<>();
vo.put("adcode", nowAdcode);
vo.put("ecpm", nowEcpm);
vo.put("adSource", nowAdSource);
vo.put("carrierType", carrierType);
vo.put("adid", BuildConfig.GROMORE_VIDEO_CODE);
if (adStatusListener != null) {
adStatusListener.adClose(vo);
}
adStatusListener = null;
}
@Override
public void onVideoComplete() {
LogUtil.d(TAG, "gromore预加载 插全屏广告-->onVideoComplete");
}
@Override
public void onSkippedVideo() {
}
};
}
package com.mints.helivideo.ad.full;
import android.app.Activity;
import com.bytedance.sdk.openadsdk.AdSlot;
import com.bytedance.sdk.openadsdk.TTAdConstant;
import com.bytedance.sdk.openadsdk.TTAdNative;
import com.bytedance.sdk.openadsdk.TTAdSdk;
import com.bytedance.sdk.openadsdk.TTFullScreenVideoAd;
import com.bytedance.sdk.openadsdk.mediation.ad.MediationAdSlot;
import com.mints.helivideo.BuildConfig;
import com.mints.helivideo.ad.AdManager;
import com.mints.helivideo.ad.AdStatusListener;
import com.mints.helivideo.common.Constant;
import com.mints.helivideo.utils.AppPreferencesManager;
import com.mints.helivideo.utils.LogUtil;
import java.lang.ref.WeakReference;
import java.util.HashMap;
/**
* **实时加载
* <p>
* GroMore 插全屏广告
*/
public class NoPreFullScreenManager {
private static final String TAG = NoPreFullScreenManager.class.getSimpleName();
private static NoPreFullScreenManager _inst;
public static NoPreFullScreenManager getInstance() {
if (_inst == null) {
_inst = new NoPreFullScreenManager();
}
return _inst;
}
private NoPreFullScreenManager() {
}
private String carrierType = "";
// 当前播放的广告
private String nowAdcode = "";
private String nowEcpm = "";
private String nowAdSource = "";
private TTFullScreenVideoAd mTtFullScreenVideoAd;
private WeakReference<Activity> weakActivity;
private AdStatusListener adStatusListener;
/**
* 插全屏
*/
public void loadAd(Activity _activity, AdStatusListener adStatusListener, String carrier) {
this.carrierType = carrier;
this.adStatusListener = adStatusListener;
this.weakActivity = new WeakReference(_activity);
preLoadAd(_activity);
}
private void preLoadAd(Activity activity) {
TTAdNative adNativeLoader = TTAdSdk.getAdManager().createAdNative(activity);
AdSlot adSlot = new AdSlot.Builder()
.setCodeId(BuildConfig.GROMORE_FULL_CODE)
.setOrientation(TTAdConstant.ORIENTATION_VERTICAL)
.setMediationAdSlot(
new MediationAdSlot.Builder()
.setMuted(false)
.setVolume(0.7f)
.setBidNotify(true)
.build()
).build();
adNativeLoader.loadFullScreenVideoAd(adSlot, new TTAdNative.FullScreenVideoAdListener() {
@Override
public void onError(int i, String s) {
LogUtil.e(TAG, "gromore实时加载 插全屏广告-->onError " + i + s);
if (adStatusListener != null) {
adStatusListener.adFail();
}
}
@Override
public void onFullScreenVideoAdLoad(TTFullScreenVideoAd ttFullScreenVideoAd) {
}
@Override
public void onFullScreenVideoCached() {
}
@Override
public void onFullScreenVideoCached(TTFullScreenVideoAd ttFullScreenVideoAd) {
LogUtil.d(TAG, "gromore实时加载 插全屏广告--> 4、onRewardVideoCached");
mTtFullScreenVideoAd = ttFullScreenVideoAd;
if (mTtFullScreenVideoAd != null && weakActivity != null && mTtFullScreenVideoAd.getMediationManager().isReady()) {
mTtFullScreenVideoAd.setFullScreenVideoAdInteractionListener(mTTFullScreenAdListener);
mTtFullScreenVideoAd.showFullScreenVideoAd(weakActivity.get());
} else {
LogUtil.e(TAG, "gromore实时加载 onRewardVideoCached onError ");
if (adStatusListener != null) {
adStatusListener.adFail();
}
}
}
});
}
private final TTFullScreenVideoAd.FullScreenVideoAdInteractionListener mTTFullScreenAdListener = new TTFullScreenVideoAd.FullScreenVideoAdInteractionListener() {
@Override
public void onAdShow() {
if (adStatusListener != null) {
adStatusListener.adSuccess();
}
if (mTtFullScreenVideoAd != null) {
if (mTtFullScreenVideoAd.getMediationManager().getShowEcpm() != null) {
nowAdcode = mTtFullScreenVideoAd.getMediationManager().getShowEcpm().getSlotId();
nowEcpm = mTtFullScreenVideoAd.getMediationManager().getShowEcpm().getEcpm();
nowAdSource = mTtFullScreenVideoAd.getMediationManager().getShowEcpm().getSdkName();
}
}
LogUtil.d(TAG, "gromore实时加载 插全屏广告-->onAdShow");
// 预加载
if (weakActivity.get() != null) {
LogUtil.d(TAG, "gromore实时加载 插全屏广告->onAdShow 触发预加载下次广告");
AdManager.Companion.getInstance().preLoadAd(weakActivity.get(), true);
}
}
@Override
public void onAdVideoBarClick() {
}
@Override
public void onAdClose() {
LogUtil.d(TAG, "gromore实时加载 插全屏广告-->onAdClose nowAdcode=" + nowAdcode);
int adCount = AppPreferencesManager.INSTANCE.get().getInt(Constant.VEDIO_AD_COUNT, 0);
if (adCount < 50) {
AppPreferencesManager.INSTANCE.get().put(Constant.VEDIO_AD_COUNT, adCount + 1);
}
HashMap<String, Object> vo = new HashMap<>();
vo.put("adcode", nowAdcode);
vo.put("ecpm", nowEcpm);
vo.put("adSource", nowAdSource);
vo.put("carrierType", carrierType);
vo.put("adid", BuildConfig.GROMORE_VIDEO_CODE);
if (adStatusListener != null) {
adStatusListener.adClose(vo);
}
adStatusListener = null;
}
@Override
public void onVideoComplete() {
LogUtil.d(TAG, "gromore实时加载 插全屏广告-->onVideoComplete");
}
@Override
public void onSkippedVideo() {
}
};
}
...@@ -53,3 +53,4 @@ GROMORE_EXPRESS_CODE="102405261" ...@@ -53,3 +53,4 @@ GROMORE_EXPRESS_CODE="102405261"
GROMORE_MY_EXPRESS_CODE="102413160" GROMORE_MY_EXPRESS_CODE="102413160"
GROMORE_DRAW_CODE="102405069" GROMORE_DRAW_CODE="102405069"
GROMORE_BANNER_CODE="102405532" GROMORE_BANNER_CODE="102405532"
GROMORE_FULL_CODE="102405532"
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