Commit 7e74c21e authored by mengcuiguang's avatar mengcuiguang

添加插屏功能

parent 884561f5
...@@ -42,8 +42,6 @@ public class FullGroManager { ...@@ -42,8 +42,6 @@ public class FullGroManager {
private boolean isMain = false; private boolean isMain = false;
private String fullId; private String fullId;
private ArrayList<WeightBean> weightList;
public void loadFullAd(Activity activity, boolean isMain) { public void loadFullAd(Activity activity, boolean isMain) {
// 加载到广告且未展示 则返回 // 加载到广告且未展示 则返回
if (isLoadSuccess) return; if (isLoadSuccess) return;
...@@ -66,10 +64,6 @@ public class FullGroManager { ...@@ -66,10 +64,6 @@ public class FullGroManager {
activity = null; activity = null;
isLoadSuccess = false; isLoadSuccess = false;
if (weightList != null) {
weightList.clear();
}
weightList = null;
} }
/** /**
...@@ -84,7 +78,7 @@ public class FullGroManager { ...@@ -84,7 +78,7 @@ public class FullGroManager {
}; };
private void loadAd() { private void loadAd() {
fullId = getFullId(getRandomWeightType()); fullId = getFullId();
/** /**
* 选择的模板类型 * 选择的模板类型
...@@ -96,8 +90,8 @@ public class FullGroManager { ...@@ -96,8 +90,8 @@ public class FullGroManager {
* 注:每次加载全屏视频广告的时候需要新建一个TTFullVideoAd,否则可能会出现广告填充问题 * 注:每次加载全屏视频广告的时候需要新建一个TTFullVideoAd,否则可能会出现广告填充问题
* ( 例如:mTTFullVideoAd = new TTFullVideoAd(this, adUnitId);) * ( 例如:mTTFullVideoAd = new TTFullVideoAd(this, adUnitId);)
*/ */
// mTTFullVideoAd = new TTFullVideoAd(activity, CsjGroMoreManager.INSTANCE.getAPP_IN_COMMON_AD_UNIT_INTERSTITIAL_ID()); mTTFullVideoAd = new TTFullVideoAd(activity, CsjGroMoreManager.INSTANCE.getAPP_OUT_AD_UNIT_NEW_INTERSTITIAL_ID());
mTTFullVideoAd = new TTFullVideoAd(activity, fullId); // mTTFullVideoAd = new TTFullVideoAd(activity, fullId);
// mTTFullVideoAd = new TTFullVideoAd(activity, "946369785"); // mTTFullVideoAd = new TTFullVideoAd(activity, "946369785");
//声音控制 模板 2.0 //声音控制 模板 2.0
// TTVideoOption videoOption = VideoOptionUtil.getTTVideoOption(); // TTVideoOption videoOption = VideoOptionUtil.getTTVideoOption();
...@@ -138,64 +132,19 @@ public class FullGroManager { ...@@ -138,64 +132,19 @@ public class FullGroManager {
}); });
} }
private String getFullId(String type) { private String getFullId() {
String id = CsjGroMoreManager.INSTANCE.getAPP_IN_COMMON_AD_FULL_UNIT_NEW_INTERSTITIAL_ID(); String id ;
switch (type) { if (isMain) {
case Constant.GROMORE_NEW_FULL_AD: id = CsjGroMoreManager.INSTANCE.getAPP_IN_COMMON_AD_FULL_UNIT_NEW_INTERSTITIAL_ID();
if (isMain) { } else {
id = CsjGroMoreManager.INSTANCE.getAPP_IN_COMMON_AD_FULL_UNIT_NEW_INTERSTITIAL_ID(); id = CsjGroMoreManager.INSTANCE.getAPP_OUT_AD_UNIT_FULL_NEW_INTERSTITIAL_ID();
} else {
id = CsjGroMoreManager.INSTANCE.getAPP_OUT_AD_UNIT_FULL_NEW_INTERSTITIAL_ID();
}
break;
case Constant.GROMORE_NEW_INSERTSCREEN_AD:
if (isMain) {
id = CsjGroMoreManager.INSTANCE.getAPP_IN_COMMON_AD_UNIT_NEW_INTERSTITIAL_ID();
} else {
id = CsjGroMoreManager.INSTANCE.getAPP_OUT_AD_UNIT_NEW_INTERSTITIAL_ID();
}
break;
} }
LogUtil.d("id:" + id); LogUtil.d("id:" + id);
return id; return id;
} }
private String getRandomWeightType() {
if (weightList != null) {
weightList.clear();
} else {
weightList = new ArrayList<>();
}
int weight = 0;
int fullInterstitialWeight = CsjGroMoreManager.INSTANCE.getAPP_FULL_NEW_INTERSTITIAL_WEIGHT();
if (fullInterstitialWeight > 0) {
weightList.add(new WeightBean(fullInterstitialWeight, Constant.GROMORE_NEW_FULL_AD));
weight = weight + fullInterstitialWeight;
}
int interstitialWeight = CsjGroMoreManager.INSTANCE.getAPP_NEW_INTERSTITIAL_WEIGHT();
if (interstitialWeight > 0) {
weightList.add(new WeightBean(interstitialWeight, Constant.GROMORE_NEW_INSERTSCREEN_AD));
weight = weight + interstitialWeight;
}
if (weightList != null && weightList.size() > 0 && weight > 0) {
LogUtil.d(TAG, "1、权重总值:" + weight);
Random r = new Random();
int randomWeight = r.nextInt(weight) + 1;
LogUtil.d(TAG, "2、权重随机值:" + randomWeight);
// ToastUtil.show(MintsApplication.getContext(),"权重随机值:" + randomWeight);
for (WeightBean weightBean : weightList) {
randomWeight -= weightBean.getWeight();
if (randomWeight <= 0) {
LogUtil.d(TAG, "3、权重结果:" + weightBean.getType());
return weightBean.getType();
}
}
}
return Constant.GROMORE_NEW_FULL_AD;
}
public void showFullAd() { public void showFullAd() {
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
......
...@@ -36,6 +36,7 @@ public class InterstitialGroManager { ...@@ -36,6 +36,7 @@ public class InterstitialGroManager {
private boolean isLoadSuccess = false; private boolean isLoadSuccess = false;
private boolean isMain = false; private boolean isMain = false;
private String interstitialId;
public void loadInsertScreenAd(Activity activity, boolean isMain) { public void loadInsertScreenAd(Activity activity, boolean isMain) {
// 加载到广告且未展示 则返回 // 加载到广告且未展示 则返回
...@@ -77,8 +78,13 @@ public class InterstitialGroManager { ...@@ -77,8 +78,13 @@ public class InterstitialGroManager {
* 注:每次加载插屏广告的时候需要新建一个TTInterstitialAd,否则可能会出现广告填充问题 * 注:每次加载插屏广告的时候需要新建一个TTInterstitialAd,否则可能会出现广告填充问题
* ( 例如:mInterstitialAd = new TTInterstitialAd(this, adUnitId);) * ( 例如:mInterstitialAd = new TTInterstitialAd(this, adUnitId);)
*/ */
if (isMain) {
interstitialId = CsjGroMoreManager.INSTANCE.getAPP_IN_COMMON_AD_UNIT_NEW_INTERSTITIAL_ID();
} else {
interstitialId = CsjGroMoreManager.INSTANCE.getAPP_OUT_AD_UNIT_NEW_INTERSTITIAL_ID();
}
// mInterstitialAd = new TTInterstitialAd(activity, CsjGroMoreManager.INSTANCE.getAPP_IN_MAIN_AD_UNIT_INTERSTITIAL_ID()); // mInterstitialAd = new TTInterstitialAd(activity, CsjGroMoreManager.INSTANCE.getAPP_IN_MAIN_AD_UNIT_INTERSTITIAL_ID());
mInterstitialAd = new TTInterstitialAd(activity, "946369785"); mInterstitialAd = new TTInterstitialAd(activity, interstitialId);
//模板1.0 //模板1.0
TTVideoOption videoOption = VideoOptionUtil.getTTVideoOption(); TTVideoOption videoOption = VideoOptionUtil.getTTVideoOption();
...@@ -153,11 +159,7 @@ public class InterstitialGroManager { ...@@ -153,11 +159,7 @@ public class InterstitialGroManager {
vo.put("ecpm", mInterstitialAd.getPreEcpm()); vo.put("ecpm", mInterstitialAd.getPreEcpm());
vo.put("adSource", mInterstitialAd.getAdNetworkPlatformId()); vo.put("adSource", mInterstitialAd.getAdNetworkPlatformId());
vo.put("adType", Constant.GRO_MORE_ADTYPE3); vo.put("adType", Constant.GRO_MORE_ADTYPE3);
if (isMain) { vo.put("adid", interstitialId);
vo.put("adid", CsjGroMoreManager.INSTANCE.getAPP_IN_MAIN_AD_UNIT_INTERSTITIAL_ID());
} else {
vo.put("adid", CsjGroMoreManager.INSTANCE.getAPP_IN_MAIN_AD_UNIT_INTERSTITIAL_ID());
}
TrackManager.getInstance().cmtGroMoreInfo(vo); TrackManager.getInstance().cmtGroMoreInfo(vo);
} else { } else {
// 当加载到广告后 ,长时间未展示失效时 改变状态 // 当加载到广告后 ,长时间未展示失效时 改变状态
......
...@@ -2,6 +2,12 @@ package com.mints.flowbox.ad.wifi ...@@ -2,6 +2,12 @@ package com.mints.flowbox.ad.wifi
import android.app.Activity import android.app.Activity
import com.mints.flowbox.ad.full.FullGroManager import com.mints.flowbox.ad.full.FullGroManager
import com.mints.flowbox.ad.inscreen.InterstitialGroManager
import com.mints.flowbox.common.Constant
import com.mints.flowbox.manager.CsjGroMoreManager
import com.mints.flowbox.mvp.model.WeightBean
import com.mints.flowbox.utils.LogUtil
import java.util.*
/** /**
* wifi广告管理 * wifi广告管理
...@@ -10,6 +16,9 @@ import com.mints.flowbox.ad.full.FullGroManager ...@@ -10,6 +16,9 @@ import com.mints.flowbox.ad.full.FullGroManager
*/ */
class WifiAdManager private constructor() { class WifiAdManager private constructor() {
private val TAG = WifiAdManager::class.java.simpleName
companion object { companion object {
val instance: WifiAdManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { val instance: WifiAdManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
WifiAdManager() WifiAdManager()
...@@ -19,58 +28,79 @@ class WifiAdManager private constructor() { ...@@ -19,58 +28,79 @@ class WifiAdManager private constructor() {
private var wifiAdStatusListener: WifiAdStatusListener? = null private var wifiAdStatusListener: WifiAdStatusListener? = null
// groMore插屏 // groMore插屏
// private var interstitialGroManager: InterstitialGroManager? = null private var interstitialGroManager: InterstitialGroManager? = null
// groMore全屏 // groMore全屏
private var fullGroManager: FullGroManager? = null private var fullGroManager: FullGroManager? = null
// 当前广告类型 // 当前广告类型
// private var currentAdType = "" private var currentAdType = ""
private var weightList: ArrayList<WeightBean>? = null
/** /**
* 预加载广告,必须传入activity * 预加载广告,必须传入activity
*/ */
fun loadWifiAd(activity: Activity) { fun loadWifiAd(activity: Activity) {
// currentAdType = getCurrentAdType() currentAdType = getRandomWeightType()
//
// when (currentAdType) { when (currentAdType) {
// Constant.GROMORE_INSERTSCREEN_AD -> { Constant.GROMORE_INSERTSCREEN_AD -> {
// preLoadInterstitialGroMore(activity) preLoadInterstitialGroMore(activity,true)
// } }
// Constant.GROMORE_FULL_AD -> { Constant.GROMORE_FULL_AD -> {
// preLoadFullGroMore(activity,true) preLoadFullGroMore(activity, true)
// } }
// } }
preLoadFullGroMore(activity, true)
} }
/** /**
* 定义广告类型规则 * 定义广告类型规则
*/ */
// private fun getCurrentAdType(): String { private fun getRandomWeightType(): String {
// var tempAdType = "" if (weightList != null) {
// val randomInt = Random().nextInt(10) weightList!!.clear()
// if (randomInt % 2 == 0) { } else {
// tempAdType = Constant.GROMORE_INSERTSCREEN_AD weightList = ArrayList<WeightBean>()
// } else { }
// tempAdType = Constant.GROMORE_FULL_AD var weight = 0
// } val fullInterstitialWeight = CsjGroMoreManager.APP_FULL_NEW_INTERSTITIAL_WEIGHT
// if (fullInterstitialWeight > 0) {
// return tempAdType weightList!!.add(WeightBean(fullInterstitialWeight, Constant.GROMORE_FULL_AD))
// return Constant.GROMORE_FULL_AD weight = weight + fullInterstitialWeight
// } }
val interstitialWeight = CsjGroMoreManager.APP_NEW_INTERSTITIAL_WEIGHT
if (interstitialWeight > 0) {
weightList!!.add(WeightBean(interstitialWeight, Constant.GROMORE_NEW_INSERTSCREEN_AD))
weight = weight + interstitialWeight
}
if (weightList != null && weightList!!.size > 0 && weight > 0) {
LogUtil.d(TAG, "1、权重总值:$weight")
val r = Random()
var randomWeight = r.nextInt(weight) + 1
LogUtil.d(TAG, "2、权重随机值:$randomWeight")
// ToastUtil.show(MintsApplication.getContext(),"权重随机值:" + randomWeight);
for (weightBean in weightList!!) {
randomWeight -= weightBean.weight
if (randomWeight <= 0) {
LogUtil.d(TAG, "3、权重结果:" + weightBean.type)
return weightBean.type
}
}
}
return Constant.GROMORE_FULL_AD
}
/** /**
* 插屏 * 插屏
*/ */
// private fun preLoadInterstitialGroMore(activity: Activity) { private fun preLoadInterstitialGroMore(activity: Activity, isMain: Boolean) {
// if (interstitialGroManager != null) { if (interstitialGroManager != null) {
// interstitialGroManager?.onDestroy() interstitialGroManager?.onDestroy()
// } }
// interstitialGroManager = InterstitialGroManager() interstitialGroManager = InterstitialGroManager()
// interstitialGroManager?.loadInsertScreenAd(activity, false) interstitialGroManager?.loadInsertScreenAd(activity, isMain)
// } }
/** /**
* 全屏 * 全屏
...@@ -84,65 +114,37 @@ class WifiAdManager private constructor() { ...@@ -84,65 +114,37 @@ class WifiAdManager private constructor() {
fullGroManager?.loadFullAd(activity, isMain) fullGroManager?.loadFullAd(activity, isMain)
} }
/**
* 展示广告
*/
fun showInterstitial() {
// when (currentAdType) {
//// Constant.GROMORE_INSERTSCREEN_AD -> {
//// interstitialGroManager?.setWifiAdStatusListener(object : WifiAdStatusListener {
//// override fun adSuccess() {
////
//// }
////
//// override fun adFail() {
////
//// }
////
//// override fun adClose() {
//// wifiAdStatusListener?.adClose()
//// }
//// })
//// interstitialGroManager?.showInteractionAd()
//// }
// Constant.GROMORE_FULL_AD -> {
fullGroManager?.setWifiAdStatusListener(wifiAdStatusListener)
fullGroManager?.showFullAd()
// }
// }
}
/** /**
* 展示广告 * 展示广告
*/ */
fun showInterstitial(_activity: Activity) { fun showInterstitial(_activity: Activity) {
// when (currentAdType) { when (currentAdType) {
// Constant.GROMORE_INSERTSCREEN_AD -> { Constant.GROMORE_INSERTSCREEN_AD -> {
// interstitialGroManager?.setWifiAdStatusListener(object : WifiAdStatusListener { interstitialGroManager?.setWifiAdStatusListener(object : WifiAdStatusListener {
// override fun adSuccess() { override fun adSuccess() {
// wifiAdStatusListener?.adSuccess()
// } }
//
// override fun adFail() { override fun adFail() {
// wifiAdStatusListener?.adFail()
// } }
//
// override fun adClose() { override fun adClose() {
// wifiAdStatusListener?.adClose() wifiAdStatusListener?.adClose()
// } }
// }) })
// interstitialGroManager?.showInteractionAd(_activity) interstitialGroManager?.showInteractionAd(_activity)
// } }
// Constant.GROMORE_FULL_AD -> { Constant.GROMORE_FULL_AD -> {
fullGroManager?.showFullAd(_activity, wifiAdStatusListener) fullGroManager?.showFullAd(_activity, wifiAdStatusListener)
// } }
// } }
} }
fun onDestroy() { fun onDestroy() {
// interstitialGroManager?.onDestroy() interstitialGroManager?.onDestroy()
// interstitialGroManager?.setWifiAdStatusListener(null) interstitialGroManager?.setWifiAdStatusListener(null)
// interstitialGroManager = null interstitialGroManager = null
fullGroManager?.onDestroy() fullGroManager?.onDestroy()
fullGroManager = null fullGroManager = null
......
...@@ -14,8 +14,8 @@ object CsjGroMoreManager { ...@@ -14,8 +14,8 @@ object CsjGroMoreManager {
* 老用户代码位-- ↓ * 老用户代码位-- ↓
* 应用内: * 应用内:
* 普通: * 普通:
* 新插屏(全屏) -> 946333578 * 新插屏 -> 946333578
* 新插屏(插屏) -> * 插屏 ->
* 信息流 -> 946265897 * 信息流 -> 946265897
* 网赚: * 网赚:
* 激励视频 -> 946265896 * 激励视频 -> 946265896
...@@ -24,8 +24,8 @@ object CsjGroMoreManager { ...@@ -24,8 +24,8 @@ object CsjGroMoreManager {
* 开屏 -> 887506685 * 开屏 -> 887506685
* 应用外: * 应用外:
* 普通: * 普通:
* 新插屏(全屏) -> 946333773 * 新插屏 -> 946333773
* 新插屏(插屏) -> * 插屏 -> 946369728
* 信息流 -> 946333992 * 信息流 -> 946333992
* 锁屏: * 锁屏:
* 信息流 -> 946334023 * 信息流 -> 946334023
...@@ -34,10 +34,10 @@ object CsjGroMoreManager { ...@@ -34,10 +34,10 @@ object CsjGroMoreManager {
var APP_OUT_AD_UNIT_EXPRESS_ID = "946333992" // 应用外普通信息流 var APP_OUT_AD_UNIT_EXPRESS_ID = "946333992" // 应用外普通信息流
var APP_OUT_AD_UNIT_LOCK_EXPRESS_ID = "946334023" // 应用外锁屏信息流 var APP_OUT_AD_UNIT_LOCK_EXPRESS_ID = "946334023" // 应用外锁屏信息流
var APP_OUT_AD_UNIT_FULL_NEW_INTERSTITIAL_ID = "946333773" // 应用外新插屏(全屏) var APP_OUT_AD_UNIT_FULL_NEW_INTERSTITIAL_ID = "946333773" // 应用外新插屏(全屏)
var APP_OUT_AD_UNIT_NEW_INTERSTITIAL_ID = "" // 应用外新插屏(插屏) var APP_OUT_AD_UNIT_NEW_INTERSTITIAL_ID = "946369728" // 应用外插屏
var APP_IN_COMMON_AD_FULL_UNIT_NEW_INTERSTITIAL_ID = "946333578" // 应用内 普通 新插屏(全屏) var APP_IN_COMMON_AD_FULL_UNIT_NEW_INTERSTITIAL_ID = "946333578" // 应用内 普通 新插屏(全屏)
var APP_IN_COMMON_AD_UNIT_NEW_INTERSTITIAL_ID = "" // 应用内 普通 新插屏(插屏) var APP_IN_COMMON_AD_UNIT_NEW_INTERSTITIAL_ID = "946369787" // 应用内 普通 插屏
var APP_IN_COMMON_AD_UNIT_EXPRESS_ID = "946265897" // 应用内 普通 信息流 var APP_IN_COMMON_AD_UNIT_EXPRESS_ID = "946265897" // 应用内 普通 信息流
var APP_IN_MAIN_AD_UNIT_VIDEO_ID = "946265896" // 应用内 网赚 激励视频 var APP_IN_MAIN_AD_UNIT_VIDEO_ID = "946265896" // 应用内 网赚 激励视频
var APP_IN_MAIN_AD_UNIT_EXPRESS_ID = "946334121" // 应用内 网赚 信息流 var APP_IN_MAIN_AD_UNIT_EXPRESS_ID = "946334121" // 应用内 网赚 信息流
...@@ -45,7 +45,7 @@ object CsjGroMoreManager { ...@@ -45,7 +45,7 @@ object CsjGroMoreManager {
var APP_IN_MAIN_AD_UNIT_SPLASH_ID = "887506685" // 应用内 网赚 开屏 var APP_IN_MAIN_AD_UNIT_SPLASH_ID = "887506685" // 应用内 网赚 开屏
var APP_FULL_NEW_INTERSTITIAL_WEIGHT = 2 // 新插屏(全屏)权重 var APP_FULL_NEW_INTERSTITIAL_WEIGHT = 2 // 新插屏(全屏)权重
var APP_NEW_INTERSTITIAL_WEIGHT = 1 // 新插屏(插屏)权重 var APP_NEW_INTERSTITIAL_WEIGHT = 1 // 插屏权重
fun init(application: MintsApplication) { fun init(application: MintsApplication) {
TTGroMoreAdManagerHolder.init(application) TTGroMoreAdManagerHolder.init(application)
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="加载中..." android:text="加载中..."
android:textColor="@color/color_3D5AFE" android:textColor="#1ba0fc"
android:textSize="14sp" /> android:textSize="14sp" />
</LinearLayout> </LinearLayout>
......
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