Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
android_goodmoney
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
android
android_goodmoney
Commits
8900563b
Commit
8900563b
authored
May 25, 2021
by
mengcuiguang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
代码优化
parent
4dbd973c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
332 additions
and
3 deletions
+332
-3
MintsApplication.java
...p/src/main/java/com/mints/goodmoney/MintsApplication.java
+4
-0
CsjGroMoreVideoAdManager.java
...om/mints/goodmoney/ad/video/CsjGroMoreVideoAdManager.java
+319
-0
Constant.kt
.../app/src/main/java/com/mints/goodmoney/common/Constant.kt
+1
-0
TTGroMoreAdManagerHolder.java
...com/mints/goodmoney/manager/TTGroMoreAdManagerHolder.java
+8
-3
No files found.
GoodMoney/app/src/main/java/com/mints/goodmoney/MintsApplication.java
View file @
8900563b
...
...
@@ -12,6 +12,7 @@ import androidx.multidex.MultiDexApplication;
import
com.hjq.toast.ToastUtils
;
import
com.mints.goodmoney.common.Constant
;
import
com.mints.goodmoney.manager.CsjGroMoreManager
;
import
com.mints.goodmoney.manager.KsManager
;
import
com.mints.goodmoney.manager.LiebaoManager
;
import
com.mints.goodmoney.manager.MhManager
;
...
...
@@ -128,6 +129,9 @@ public class MintsApplication extends MultiDexApplication {
// 穿山甲
TtCsjAdManager
.
init
(
this
);
// GroMore
CsjGroMoreManager
.
INSTANCE
.
init
();
// 快手
KsManager
.
INSTANCE
.
initKs
(
this
);
...
...
GoodMoney/app/src/main/java/com/mints/goodmoney/ad/video/CsjGroMoreVideoAdManager.java
0 → 100644
View file @
8900563b
package
com
.
mints
.
goodmoney
.
ad
.
video
;
import
android.app.Activity
;
import
android.util.Log
;
import
com.bytedance.msdk.adapter.util.Logger
;
import
com.bytedance.msdk.api.AdError
;
import
com.bytedance.msdk.api.AdSlot
;
import
com.bytedance.msdk.api.TTAdConstant
;
import
com.bytedance.msdk.api.TTMediationAdSdk
;
import
com.bytedance.msdk.api.TTSettingConfigCallback
;
import
com.bytedance.msdk.api.TTVideoOption
;
import
com.bytedance.msdk.api.reward.RewardItem
;
import
com.bytedance.msdk.api.reward.TTRewardAd
;
import
com.bytedance.msdk.api.reward.TTRewardedAdListener
;
import
com.bytedance.msdk.api.reward.TTRewardedAdLoadCallback
;
import
com.bytedance.sdk.openadsdk.TTAdNative
;
import
com.bytedance.sdk.openadsdk.TTAppDownloadListener
;
import
com.bytedance.sdk.openadsdk.TTRewardVideoAd
;
import
com.mints.goodmoney.BuildConfig
;
import
com.mints.goodmoney.ad.video.base.BaseVideoAd
;
import
com.mints.goodmoney.ad.video.base.VideoAdStatusListener
;
import
com.mints.goodmoney.common.AppConfig
;
import
com.mints.goodmoney.common.Constant
;
import
com.mints.goodmoney.manager.TTNativeExpressManager
;
import
com.mints.goodmoney.manager.TrackManager
;
import
com.mints.goodmoney.manager.TtCsjAdManager
;
import
com.mints.goodmoney.manager.UserManager
;
import
com.mints.goodmoney.utils.LogUtil
;
import
com.mints.goodmoney.utils.MD5
;
import
com.mints.library.utils.json.JsonUtil
;
import
net.grandcentrix.tray.AppPreferences
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* 穿山甲激励视频广告
*/
public
class
CsjGroMoreVideoAdManager
extends
BaseVideoAd
{
private
static
final
String
TAG
=
CsjGroMoreVideoAdManager
.
class
.
getSimpleName
();
private
static
CsjGroMoreVideoAdManager
_inst
;
private
AppPreferences
ps
;
private
int
curCoin
;
private
String
extraId
;
private
VideoAdStatusListener
videoAdStatusListener
;
private
TTRewardAd
mttRewardAd
;
Activity
activity
;
private
UserManager
userManager
;
private
String
adUnitId
=
"946018378"
;
private
boolean
isClickScreen
=
true
;
// 是否点击屏幕跳转广告
public
static
CsjGroMoreVideoAdManager
getInstance
(
Activity
activity
)
{
if
(
_inst
==
null
)
{
_inst
=
new
CsjGroMoreVideoAdManager
(
activity
);
}
return
_inst
;
}
private
CsjGroMoreVideoAdManager
(
Activity
activity
)
{
init
(
activity
);
}
private
void
init
(
Activity
activity
)
{
this
.
activity
=
activity
;
ps
=
new
AppPreferences
(
activity
);
userManager
=
UserManager
.
getInstance
();
}
@Override
public
void
onDestroy
()
{
TTMediationAdSdk
.
unregisterConfigCallback
(
mSettingConfigCallback
);
if
(
mttRewardAd
!=
null
)
{
mttRewardAd
.
destroy
();
}
ps
=
null
;
activity
=
null
;
}
/**
* 激励视频
*
* @param carrierType
*/
@Override
public
void
loadAd
(
Activity
activity
,
int
curCoin
,
String
carrierType
,
String
extraId
)
{
this
.
activity
=
activity
;
isClickScreen
=
true
;
this
.
curCoin
=
curCoin
;
this
.
extraId
=
extraId
;
/**
* 判断当前是否存在config 配置 ,如果存在直接加载广告 ,如果不存在则注册config加载回调
*/
if
(
TTMediationAdSdk
.
configLoadSuccess
())
{
loadAd
(
adUnitId
,
TTAdConstant
.
VERTICAL
);
}
else
{
TTMediationAdSdk
.
registerConfigCallback
(
mSettingConfigCallback
);
//不用使用内部类,否则在ondestory中无法移除该回调
}
}
/**
* config回调
*/
private
TTSettingConfigCallback
mSettingConfigCallback
=
new
TTSettingConfigCallback
()
{
@Override
public
void
configLoad
()
{
loadAd
(
adUnitId
,
TTAdConstant
.
VERTICAL
);
}
};
private
void
loadAd
(
final
String
adUnitId
,
int
orientation
)
{
/**
* 注:每次加载激励视频广告的时候需要新建一个TTRewardAd,否则可能会出现广告填充问题
* ( 例如:mttRewardAd = new TTRewardAd(this, adUnitId);)
*/
mttRewardAd
=
new
TTRewardAd
(
activity
,
adUnitId
);
TTVideoOption
videoOption
=
new
TTVideoOption
.
Builder
()
.
setMuted
(
true
)
//对所有SDK的激励广告生效,除需要在平台配置的SDK,如穿山甲SDK
.
setAdmobAppVolume
(
0
f
)
//配合Admob的声音大小设置[0-1]
.
build
();
Map
<
String
,
String
>
customData
=
new
HashMap
<>();
customData
.
put
(
com
.
bytedance
.
msdk
.
api
.
AdSlot
.
CUSTOM_DATA_KEY_PANGLE
,
"pangle media_extra"
);
customData
.
put
(
com
.
bytedance
.
msdk
.
api
.
AdSlot
.
CUSTOM_DATA_KEY_GDT
,
"gdt custom data"
);
customData
.
put
(
com
.
bytedance
.
msdk
.
api
.
AdSlot
.
CUSTOM_DATA_KEY_KS
,
"ks custom data"
);
// 其他需要透传给adn的数据。
//创建广告请求参数AdSlot,具体参数含义参考文档
com
.
bytedance
.
msdk
.
api
.
AdSlot
.
Builder
adSlotBuilder
=
new
com
.
bytedance
.
msdk
.
api
.
AdSlot
.
Builder
()
.
setTTVideoOption
(
videoOption
)
.
setRewardName
(
"金币"
)
//奖励的名称
.
setRewardAmount
(
3
)
//奖励的数量
.
setUserID
(
"user123"
)
//用户id,必传参数
.
setAdStyleType
(
AdSlot
.
TYPE_EXPRESS_AD
)
// 确保该聚合广告位下所有gdt代码位都是同一种类型(模版或非模版)。
.
setCustomData
(
customData
)
// 激励视频开启服务端验证时,透传给adn的自定义数据。
.
setOrientation
(
orientation
);
//必填参数,期望视频的播放方向:TTAdConstant.HORIZONTAL 或 TTAdConstant.VERTICAL
//请求广告
mttRewardAd
.
loadRewardAd
(
adSlotBuilder
.
build
(),
new
TTRewardedAdLoadCallback
()
{
@Override
public
void
onRewardVideoLoadFail
(
AdError
adError
)
{
TrackManager
.
getInstance
().
addCallImp
(
Constant
.
AD_SOURCE_CSJ
,
Constant
.
EVENT_TYPE_ONE
,
String
.
valueOf
(
adError
.
code
),
adError
.
message
);
LogUtil
.
d
(
"vedioAdStatusListener"
,
"onError "
+
String
.
valueOf
(
adError
.
code
)
+
adError
.
message
);
if
(
videoAdStatusListener
!=
null
)
{
videoAdStatusListener
.
adFail
();
}
}
@Override
public
void
onRewardVideoAdLoad
()
{
}
@Override
public
void
onRewardVideoCached
()
{
if
(
mttRewardAd
!=
null
)
{
//在获取到广告后展示,强烈建议在onRewardVideoCached回调后,展示广告,提升播放体验
//该方法直接展示广告
//展示广告,并传入广告展示的场景
mttRewardAd
.
showRewardAd
(
activity
,
mTTRewardedAdListener
);
}
else
{
TrackManager
.
getInstance
().
addCallImp
(
Constant
.
AD_SOURCE_CSJ
,
Constant
.
EVENT_TYPE_ONE
,
"999999"
,
"Cached Fail"
);
if
(
videoAdStatusListener
!=
null
)
{
videoAdStatusListener
.
adFail
();
}
}
}
});
}
/**
* 激励视频交互回调
*/
private
TTRewardedAdListener
mTTRewardedAdListener
=
new
TTRewardedAdListener
()
{
/**
* 广告的展示回调 每个广告仅回调一次
*/
public
void
onRewardedAdShow
()
{
Log
.
d
(
TAG
,
"onRewardedAdShow"
);
TrackManager
.
getInstance
().
addCallImp
(
Constant
.
AD_SOURCE_CSJ
,
Constant
.
EVENT_TYPE_ZERO
,
""
,
""
);
}
/**
* 注意Admob的激励视频不会回调该方法
*/
@Override
public
void
onRewardClick
()
{
Log
.
d
(
TAG
,
"onRewardClick"
);
if
(
AppConfig
.
needReportClickAdEvent
)
{
TrackManager
.
getInstance
().
reportClickAdEvent
();
}
TrackManager
.
getInstance
().
addCallImp
(
Constant
.
AD_SOURCE_CSJ
,
Constant
.
EVENT_TYPE_TWO
,
""
,
""
);
if
(
isClickScreen
)
{
// 防止重复
TrackManager
.
getInstance
().
addCallImp
(
Constant
.
AD_SOURCE_CSJ
,
Constant
.
EVENT_TYPE_FOUR
,
""
,
""
);
isClickScreen
=
false
;
}
if
(
videoAdStatusListener
!=
null
)
{
videoAdStatusListener
.
adDownload
();
}
}
/**
* 广告关闭的回调
*/
public
void
onRewardedAdClosed
()
{
Log
.
d
(
TAG
,
"onRewardedAdClosed"
);
TrackManager
.
getInstance
().
addCallImp
(
Constant
.
AD_SOURCE_CSJ
,
Constant
.
EVENT_TYPE_THREE
,
""
,
""
);
if
(
videoAdStatusListener
!=
null
)
{
videoAdStatusListener
.
adSuccess
();
}
}
/**
* 视频播放完毕的回调 Admob广告不存在该回调
*/
public
void
onVideoComplete
()
{
Log
.
d
(
TAG
,
"onVideoComplete"
);
}
/**
* 视频播放失败的回调 - Mintegral GDT Admob广告不存在该回调
*/
public
void
onVideoError
()
{
Log
.
d
(
TAG
,
"onVideoError"
);
TrackManager
.
getInstance
().
addCallImp
(
Constant
.
AD_SOURCE_CSJ
,
Constant
.
EVENT_TYPE_ONE
,
"999999"
,
"VideoError"
);
if
(
videoAdStatusListener
!=
null
)
{
videoAdStatusListener
.
adFail
();
}
}
/**
* 激励视频播放完毕,验证是否有效发放奖励的回调
*/
public
void
onRewardVerify
(
RewardItem
rewardItem
)
{
Map
<
String
,
Object
>
customData
=
rewardItem
.
getCustomData
();
if
(
customData
!=
null
)
{
String
adnName
=
(
String
)
customData
.
get
(
RewardItem
.
KEY_ADN_NAME
);
switch
(
adnName
)
{
case
RewardItem
.
KEY_GDT
:
Logger
.
d
(
TAG
,
"rewardItem gdt: "
+
customData
.
get
(
RewardItem
.
KEY_GDT_TRANS_ID
));
break
;
}
}
}
/**
* - Mintegral GDT Admob广告不存在该回调
*/
@Override
public
void
onSkippedVideo
()
{
}
};
/**
* 封装广告数据,请求服务器
*
* @param carrierType
* @param tid
* @return
*/
private
HashMap
<
String
,
Object
>
getAdMapVO
(
String
carrierType
,
String
tid
)
{
HashMap
<
String
,
Object
>
vo
=
new
HashMap
<>();
vo
.
put
(
"carrierType"
,
carrierType
);
vo
.
put
(
"adtype"
,
Constant
.
ADTYPE_VEDIO
);
vo
.
put
(
"tid"
,
tid
);
vo
.
put
(
"adsource"
,
Constant
.
AD_SOURCE_CSJ
);
if
(
ps
==
null
)
{
ps
=
new
AppPreferences
(
activity
);
}
vo
.
put
(
"ip"
,
ps
.
getString
(
Constant
.
CSJ_VEDIO_APPIP
,
""
));
switch
(
carrierType
)
{
case
Constant
.
CARRIER_VERSUS_VIDEO
:
// 每日任务-视频
vo
.
put
(
"coin"
,
curCoin
);
break
;
case
Constant
.
CARRIER_HOMEWATER
:
// 首页喝水汽泡
vo
.
put
(
"waterCoin"
,
curCoin
);
break
;
case
Constant
.
CARRIER_OFFLINE_DOUBLE
:
// 离线收益翻倍
vo
.
put
(
"offline_income"
,
curCoin
);
case
Constant
.
CARRIER_CHALLENGE_TURN
:
// 挑战大转盘
case
Constant
.
CARRIER_CHALLENGE_CARD
:
// 挑战刮刮乐
vo
.
put
(
"turntableKey"
,
extraId
);
break
;
}
return
vo
;
}
public
void
setVideoAdStatusListener
(
VideoAdStatusListener
videoAdStatusListener
)
{
this
.
videoAdStatusListener
=
videoAdStatusListener
;
}
}
GoodMoney/app/src/main/java/com/mints/goodmoney/common/Constant.kt
View file @
8900563b
...
...
@@ -148,6 +148,7 @@ object Constant {
const
val
AD_SOURCE_CSJ
=
"CSJ"
const
val
AD_SOURCE_GROMORE
=
"GROMORE"
const
val
AD_SOURCE_YLH
=
"YLH"
const
val
AD_SOURCE_SDHZ
=
"SDHZ"
//闪电盒子
const
val
AD_SOURCE_FL
=
"FL"
//枫岚
...
...
GoodMoney/app/src/main/java/com/mints/goodmoney/manager/TTGroMoreAdManagerHolder.java
View file @
8900563b
...
...
@@ -8,6 +8,8 @@ import com.bytedance.msdk.api.TTAdConfig;
import
com.bytedance.msdk.api.TTAdConstant
;
import
com.bytedance.msdk.api.TTMediationAdSdk
;
import
com.bytedance.msdk.api.UserInfoForSegment
;
import
com.mints.goodmoney.BuildConfig
;
import
com.mints.goodmoney.common.Constant
;
import
java.util.HashMap
;
import
java.util.Map
;
...
...
@@ -18,6 +20,9 @@ import java.util.Map;
*/
public
class
TTGroMoreAdManagerHolder
{
public
static
final
String
TT_AD_APPID
=
"5113521"
;
public
static
final
String
TT_AD_NAME
=
Constant
.
MINTS_APP_NAME
;
private
static
boolean
sInit
;
public
static
void
init
(
Context
context
)
{
...
...
@@ -51,12 +56,12 @@ public class TTGroMoreAdManagerHolder {
customInfos
.
put
(
"bbbb"
,
"test222"
);
userInfo
.
setCustomInfos
(
customInfos
);
return
new
TTAdConfig
.
Builder
()
.
appId
(
"5001121"
)
//必填 ,不能为空
.
appName
(
"APP测试媒体"
)
//必填,不能为空
.
appId
(
TT_AD_APPID
)
//必填 ,不能为空
.
appName
(
TT_AD_NAME
)
//必填,不能为空
.
openAdnTest
(
false
)
//开启第三方ADN测试时需要设置为true,会每次重新拉去最新配置,release 包情况下必须关闭.默认false
.
isPanglePaid
(
false
)
//是否为费用户
.
setPublisherDid
(
getAndroidId
(
context
))
//用户自定义device_id
.
openDebugLog
(
true
)
//测试阶段打开,可以通过日志排查问题,上线时去除该调用
.
openDebugLog
(
BuildConfig
.
DEBUG
)
//测试阶段打开,可以通过日志排查问题,上线时去除该调用
.
usePangleTextureView
(
true
)
//使用TextureView控件播放视频,默认为SurfaceView,当有SurfaceView冲突的场景,可以使用TextureView
.
setPangleTitleBarTheme
(
TTAdConstant
.
TITLE_BAR_THEME_DARK
)
.
allowPangleShowNotify
(
true
)
//是否允许sdk展示通知栏提示
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment