Commit 171b3485 authored by 张释方's avatar 张释方

添加小满科技

parent 09e6c4c2
......@@ -251,13 +251,8 @@
<activity
android:name=".call.detail.DetailApplyActivity"
android:screenOrientation="portrait" />
<activity android:name=".ui.activitys.ZaActivity"
android:screenOrientation="portrait"/>
<activity android:name=".ui.activitys.XiaomanActivity"
android:screenOrientation="portrait"/>
<activity android:name=".ui.activitys.XiaomanActivity2"
android:screenOrientation="portrait"/>
<service
android:name=".service.UpdateService"
......
......@@ -13,6 +13,7 @@ import com.bytedance.sdk.openadsdk.TTAdSdk
import com.fendasz.moku.planet.exception.MokuException
import com.fendasz.moku.planet.helper.MokuHelper
import com.mints.goodmoney.MintsApplication
import com.mints.goodmoney.utils.LogUtil
import com.qq.e.comm.managers.GDTADManager
import kotlinx.android.synthetic.main.activity_layout_xiaoman.*
......@@ -23,12 +24,9 @@ object XmManager {
private var placeMateId = ""
private var materialId = ""
private var userId=""
private const val ACCESSKEY = "hzq-az_rvkvdy"
private const val SECRETKEY = "22FvHjUzvQ516214"
fun initXm(application: Application) {
// //打开日志,上线之前记得关闭
try {
......@@ -36,8 +34,6 @@ object XmManager {
AdSdk.setDebug(true);
//初始化 需要在Applicaiton 中
AdSdk.init(application, ACCESSKEY, SECRETKEY)
userId = UserManager.getInstance().userID
Log.d("MyFragment","*****************$userId*********************")
} catch (e: Exception) {//这里应该是小满的异常
e.printStackTrace()
}
......@@ -46,21 +42,22 @@ object XmManager {
fun loadMater(placeid: String) {
if (placeMateId.equals("")) {
val tm: MaterialTm by lazy { MaterialTm() }
tm!!.loadMaterialData(userId, placeid, object : MaterialTm.Callback {
tm!!.loadMaterialData(UserManager.getInstance().userID, placeid, object : MaterialTm.Callback {
//对应PlaceID会有对应的素材
override fun onSuccess(imgUrl: String, placeMateId2: String, materialId2: String) {
placeMateId = placeMateId2
materialId = materialId2
AdSdk.exposure(userId, placeid, placeMateId, materialId);
Log.d("loadMater", "******exposure*********$userId******$placeMateId********$materialId****************$placeid**")
AdSdk.exposure(UserManager.getInstance().userID, placeid, placeMateId, materialId);
LogUtil.d("******exposure*********${UserManager.getInstance().userID}******$placeMateId********$materialId****************$placeid**")
}
override fun onFailure(code: String, errmsg: String) {
Log.d("onFailure", "$code$errmsg")
LogUtil.d("$code$errmsg")
}
})
} else {
AdSdk.exposure(UserManager.getInstance().userID, placeid, placeMateId, materialId);
}
}
......@@ -69,8 +66,8 @@ object XmManager {
* @param view
*/
fun exprotClick(placeid: String) {
AdSdk.click(userId, placeid, materialId, materialId);
Log.d("loadMater", "******exprotClick*******$userId*******$placeMateId********$materialId******$placeid")
AdSdk.click(UserManager.getInstance().userID, placeid, materialId, materialId);
Log.d("loadMater", "******exprotClick*******${UserManager.getInstance().userID}*******$placeMateId********$materialId******$placeid")
}
}
\ No newline at end of file
package com.mints.goodmoney.ui.activitys
import android.content.Intent
import android.graphics.Point
import android.os.Bundle
import android.text.TextUtils
import android.util.Log
import android.view.View
import com.bumptech.glide.Glide
import com.bx.adsdk.AdSdk
import com.bx.adsdk.util.MaterialTm
import com.mints.goodmoney.BuildConfig
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.Toast
import androidx.fragment.app.FragmentTransaction
import com.bx.adsdk.CampaignCallback
import com.bx.adsdk.CampaignFragment
import com.bytedance.sdk.openadsdk.AdSlot
import com.bytedance.sdk.openadsdk.TTAdConstant
import com.bytedance.sdk.openadsdk.TTAdDislike
import com.bytedance.sdk.openadsdk.TTAdNative
import com.bytedance.sdk.openadsdk.TTAdSdk
import com.bytedance.sdk.openadsdk.TTNativeExpressAd
import com.bytedance.sdk.openadsdk.TTRewardVideoAd
import com.google.gson.Gson
import com.mints.goodmoney.R
import com.mints.goodmoney.common.Constant
import com.mints.goodmoney.mvp.model.JsBridgeBean
import com.mints.goodmoney.ui.activitys.base.BaseActivity
import kotlinx.android.synthetic.main.activity_layout_xiaoman.*
import com.qq.e.ads.banner2.UnifiedBannerADListener
import com.qq.e.ads.banner2.UnifiedBannerView
import com.qq.e.ads.nativ.express2.AdEventListener
import com.qq.e.ads.nativ.express2.NativeExpressAD2
import com.qq.e.ads.nativ.express2.NativeExpressADData2
import com.qq.e.ads.rewardvideo.RewardVideoAD
import com.qq.e.ads.rewardvideo.RewardVideoADListener
import com.qq.e.comm.util.AdError
import kotlinx.android.synthetic.main.activity_layout_xiaoman2.*
class XiaomanActivity : BaseActivity(), View.OnClickListener {
private var carrierType = ""//传入载体
private var isPlaySuccess = false
private var rewardVideoAD: RewardVideoAD? = null
private var unifiedBannerView: UnifiedBannerView? = null
private val TAG = "XiaomanActivity2"
private val campaignFragment: CampaignFragment? = null
private var mttRewardVideoAd: TTRewardVideoAd? = null
private var mTTAd: TTNativeExpressAd? = null
private var mNativeExpressADData2: NativeExpressADData2? = null
private var mNativeExpressAD2: NativeExpressAD2? = null
private val bannerContainer: ViewGroup? = null
class XiaomanActivity : BaseActivity() {
private val TAG = "XiaomanActivity"
private val PLACE_ID: String = "3497"
private var tm: MaterialTm? = null
override fun getContentViewLayoutID(): Int {
//显示layout布局
return R.layout.activity_layout_xiaoman
return R.layout.activity_layout_xiaoman2
}
override fun getBundleExtras(extras: Bundle?) {
super.getBundleExtras(extras)
extras?.let {
carrierType = it.getString(Constant.MAIN_CARRIER_TYPE, "")
}
}
override fun initViewsAndEvents() {
//onCreate
tm = MaterialTm()
initListener()
/**
* CampaignFragment.newInstance("这里为userId")
* 为方便测试,demo中采用时间戳来标识用户唯一id
* 媒体对接时注意替换
*/
val fragment = CampaignFragment.newInstance(System.currentTimeMillis().toString() + "")
// fragment.setPlaceId(intent.getStringExtra("placeId"))
fragment.setPlaceId(carrierType)
// fragment.setPlaceId("3497")
fragment.setCallback(object : CampaignCallback() {
override fun showAd(s: String) {//2.2.9.1//调用激励视频
super.showAd(s)
/**
* 这里需要根据adType来判断展示广告的平台 1-穿山甲 2-广点通 3-快手
* pid: 对应平台的代码位
*
* 这里采用广点通的例子,媒体注意替换
*/
val bean: JsBridgeBean = Gson().fromJson(s, JsBridgeBean::class.java)
if (bean.adType.equals("1")) {
loadBytedanceAd(fragment, bean)
} else if (bean.adType.equals("2")) {
loadGDTRewardVideo(fragment, bean)
}
}
/**
* Banner广告
* @param params
*/
override fun showBanner(params: String) {
//2.2.9.3 展示Banner类型广告
Log.d(TAG, "showBanner: $params")
Toast.makeText(this@XiaomanActivity, params, Toast.LENGTH_LONG).show()
val bean: JsBridgeBean = Gson().fromJson(params, JsBridgeBean::class.java)
if (TextUtils.isEmpty(bean.pid)) {
return
}
when (bean.adType) {
"4" -> loadCSJBannerAd(fragment, bean)//穿山甲激励视频
"5" -> loadGDTBannerAd(fragment, bean)//广点通激励视频
"13" -> loadCSJBannerAd(fragment, bean)//穿山甲横幅
"14" -> loadGDTNativeExpressAd(fragment, bean)//广点通横幅
}
}
override fun hideBanner(params: String) {
super.hideBanner(params)
bannerContainer?.removeAllViews()
if (unifiedBannerView != null) {
unifiedBannerView?.destroy()
unifiedBannerView = null
}
}
})
val transaction: FragmentTransaction = supportFragmentManager.beginTransaction()
transaction.add(R.id.frame_layout, fragment)
transaction.commitAllowingStateLoss()
}
private fun initListener() {
ivXiaomanBack.setOnClickListener(this)
}
/**
* banner2.0规定banner宽高比应该为6.4:1 , 开发者可自行设置符合规定宽高比的具体宽度和高度值
*
* @return
*/
private fun getUnifiedBannerLayoutParams(): FrameLayout.LayoutParams? {
val screenSize = Point()
windowManager.defaultDisplay.getSize(screenSize)
return FrameLayout.LayoutParams(screenSize.x, Math.round(screenSize.x / 6.4f))
}
override fun onDestroy() {
super.onDestroy()
if (unifiedBannerView != null) {
unifiedBannerView?.destroy()
}
if (mTTAd != null) {
//调用destroy()方法释放
mTTAd!!.destroy()
}
destroyAd()
}
/**
* 加载广点通横幅广告
* @param fragment
* @param bean
*/
private fun loadGDTNativeExpressAd(fragment: CampaignFragment, bean: JsBridgeBean) {
// 创建广告
mNativeExpressAD2 = NativeExpressAD2(applicationContext, "3081971852112087", object : NativeExpressAD2.AdLoadListener {
override fun onLoadSuccess(list: List<NativeExpressADData2>) {
fragment.setBannerLoad(bean.requestId)
gdtBannerRenderAd(fragment, bean, list)
}
override fun onNoAD(adError: AdError) {
fragment.setBannerError(bean.requestId)
}
})
mNativeExpressAD2?.setAdSize(390, 0) // 单位dp
mNativeExpressAD2?.loadAd(1)
destroyAd()
bannerContainer?.removeAllViews()
}
/**
* 渲染广告
* @param adDataList
*/
private fun gdtBannerRenderAd(fragment: CampaignFragment, bean: JsBridgeBean, adDataList: List<NativeExpressADData2>) {
if (adDataList.size > 0) {
bannerContainer?.removeAllViews()
mNativeExpressADData2 = adDataList[0]
mNativeExpressADData2?.setAdEventListener(object : AdEventListener {
override fun onClick() {
Log.i(TAG, "onClick: $mNativeExpressADData2")
fragment.setBannerClick(bean.requestId)
}
override fun onExposed() {
Log.i(TAG, "onImpression: $mNativeExpressADData2")
fragment.setBannerExpose(bean.requestId)
}
override fun onRenderSuccess() {
Log.i(TAG, "onRenderSuccess: $mNativeExpressADData2")
bannerContainer?.removeAllViews()
if (mNativeExpressADData2?.getAdView() != null) {
bannerContainer?.addView(mNativeExpressADData2?.getAdView())
}
}
override fun onRenderFail() {
Log.i(TAG, "onRenderFail: $mNativeExpressADData2")
fragment.setBannerError(bean.requestId)
}
override fun onAdClosed() {
Log.i(TAG, "onAdClosed: $mNativeExpressADData2")
fragment.setBannerClose(bean.requestId)
bannerContainer?.removeAllViews()
mNativeExpressADData2?.destroy()
}
})
mNativeExpressADData2!!.render()
}
}
/**
* 加载广点通
* @param fragment
* @param bean
*/
private fun loadGDTRewardVideo(fragment: CampaignFragment, bean: JsBridgeBean) {
var pid = bean.pid
// TODO: 2021/1/8 demo中代码位写死, 媒体注意替换
pid = "3081971852112087"
val appId = "1111046903"
rewardVideoAD = RewardVideoAD(applicationContext, appId, pid, object : RewardVideoADListener {
override fun onADLoad() {
Log.e(TAG, "onADLoad")
rewardVideoAD?.showAD()
isPlaySuccess = false
fragment.setVideoLoad(bean.requestId)
}
override fun onVideoCached() {
Log.e(TAG, "onVideoCached")
}
override fun onADShow() {
Log.e(TAG, "onADShow")
}
override fun onADExpose() {
Log.e(TAG, "onADExpose")
fragment.setVideoExposeComplete(bean.requestId)
}
override fun onReward() {
Log.e(TAG, "onReward")
isPlaySuccess = true
}
override fun onADClick() {
Log.e(TAG, "onADClick")
fragment.setVideoClickComplete(bean.requestId)
}
override fun onVideoComplete() {
Log.e(TAG, "onVideoComplete")
}
override fun onADClose() {
Log.e(TAG, "onADClose")
if (isPlaySuccess) {
fragment.setVideoClose(bean.requestId)
} else {
fragment.setVideoSkip(bean.requestId)
}
}
override fun onError(adError: AdError) {
Log.e(TAG, "onError:--->" + adError.errorMsg)
fragment.setVideoError(bean.requestId)
}
})
rewardVideoAD?.loadAD()
}
/**
* 打开活动
* @param view
* 加载广点通banner广告
* @param fragment
* @param bean
*/
fun openPage(view: View?) {
val intent = Intent(this, XiaomanActivity2::class.java)
intent.putExtra("placeId", PLACE_ID)
// intent.putExtra("placeId", BuildConfig.PLACE_ID)
startActivity(intent)
private fun loadGDTBannerAd(fragment: CampaignFragment?, bean: JsBridgeBean) {
var pid = bean.pid
// TODO: 2021/1/8 demo中代码位写死, 媒体注意替换
pid = "3081971852112087"
//广点通底部Banner
unifiedBannerView = UnifiedBannerView(this@XiaomanActivity, pid, object : UnifiedBannerADListener {
override fun onNoAD(adError: AdError) {
Log.e(TAG, "广告加载失败: onNoAD")
fragment?.setBannerError(bean.requestId)
}
override fun onADReceive() {
Log.e(TAG, "广告加载成功回调: onADReceive")
fragment?.setBannerLoad(bean.requestId)
}
override fun onADExposure() {
Log.e(TAG, "广告曝光: onADExposure")//2.2.7.1 曝光上报,在活动入口渲染完成后必须调用
fragment?.setBannerExpose(bean.requestId)
}
override fun onADClosed() {
Log.e(TAG, "广告关闭: onADClosed")
fragment?.setBannerClose(bean.requestId)
}
override fun onADClicked() {
Log.e(TAG, "广告点击: onADClicked")//2.2.7.2 点击上报,活动入口点击时进行调用必须调用
fragment?.setBannerClick(bean.requestId)
}
override fun onADLeftApplication() {
Log.e(TAG, "广告点击离开 APP : onADLeftApplication")
}
override fun onADOpenOverlay() {
Log.e(TAG, "广告打开浮层: onADOpenOverlay")
}
override fun onADCloseOverlay() {
Log.e(TAG, "广告浮层关闭: onADCloseOverlay")
}
})
bannerContainer?.addView(unifiedBannerView, getUnifiedBannerLayoutParams())
unifiedBannerView!!.loadAD()
}
/**
* 加载入口素材
* @param view
* 加载穿山甲视频广告
* @param fragment
* @param bean
*/
open fun loadMater(view: View?) {
tm!!.loadMaterialData("2233", PLACE_ID, object : MaterialTm.Callback {
//对应PlaceID会有对应的素材
override fun onSuccess(s: String, s1: String, s2: String) {
Glide.with(this@XiaomanActivity).load(s).into(imageView)
private fun loadBytedanceAd(fragment: CampaignFragment, bean: JsBridgeBean) {//2.2.9.2 广告数据上报//底部穿山甲banner
var pid = bean.pid
// TODO: 2021/1/8 demo中代码位写死, 媒体注意替换
pid = "946012845"
val adSlot = AdSlot.Builder()
.setCodeId(pid) // 这里要替换成 bean.pid
.setAdCount(1) //个性化模板广告需要设置期望个性化模板广告的大小,单位dp,激励视频场景,只要设置的值大于0即可
.setExpressViewAcceptedSize(500f, 500f)
.setImageAcceptedSize(1080, 1920) //非必传参数,仅奖励发放服务端回调时需要使用
.setUserID("user123") //非必传参数,仅奖励发放服务端回调时需要使用
.setMediaExtra("media_extra")
.build()
val mTTAdNative = TTAdSdk.getAdManager().createAdNative(applicationContext)
mTTAdNative.loadRewardVideoAd(adSlot, object : TTAdNative.RewardVideoAdListener {
override fun onError(code: Int, message: String) {
Log.d(TAG, "穿山甲-加载失败$code====$message")
fragment.setVideoError(bean.requestId)
}
override fun onFailure(s: String, s1: String) {
Log.d(TAG, """$s$s1""".trimIndent())
//视频广告加载后的视频文件资源缓存到本地的回调
override fun onRewardVideoCached() {}
//视频广告素材加载到,如title,视频url等,不包括视频文件
override fun onRewardVideoAdLoad(ad: TTRewardVideoAd) {
fragment.setVideoLoad(bean.requestId)
Log.d(TAG, "穿山甲-加载成功")
isPlaySuccess = false
mttRewardVideoAd = ad
bindBytedanceVideoAdListener(fragment, bean, mttRewardVideoAd!!)
mttRewardVideoAd?.showRewardVideoAd(this@XiaomanActivity)
}
})
AdSdk.exposure("2233", PLACE_ID, "", "");
}
/**
* 入口点击上报
* @param view
* 穿山甲激励视频绑定监听事件
* @param fragment
* @param bean
*/
fun exprotClick(view: View?) {
AdSdk.click("2233", PLACE_ID, "", "");
Log.d(TAG,"**********************????*****exprotClick****************")
private fun bindBytedanceVideoAdListener(fragment: CampaignFragment, bean: JsBridgeBean, ad: TTRewardVideoAd) {
ad.setRewardAdInteractionListener(object : TTRewardVideoAd.RewardAdInteractionListener {
override fun onAdShow() {
Log.d(TAG, "穿山甲-曝光")
fragment.setVideoExposeComplete(bean.requestId)
}
override fun onAdVideoBarClick() {
Log.d(TAG, "穿山甲-点击")
fragment.setVideoClickComplete(bean.requestId)
}
override fun onAdClose() {
if (isPlaySuccess) {
fragment.setVideoClose(bean.requestId)
} else {
fragment.setVideoSkip(bean.requestId)
}
}
override fun onVideoComplete() {}
override fun onVideoError() {
Log.d(TAG, "穿山甲-视频失败")
fragment.setVideoError(bean.requestId)
}
override fun onRewardVerify(rewardVerify: Boolean, rewardAmount: Int, rewardName: String, errorCode: Int, errorMsg: String) {
Log.d(TAG, "穿山甲-验证")
isPlaySuccess = rewardVerify
}
override fun onSkippedVideo() {}
})
}
private class initWeb
/**
* 加载穿山甲banner广告,穿山甲激励视频
* @param fragment
* @param bean
*/
private fun loadCSJBannerAd(fragment: CampaignFragment, bean: JsBridgeBean) {
val mTTAdNative = TTAdSdk.getAdManager().createAdNative(applicationContext)//2.2.9.3穿山甲底部banner
var pid = bean.pid
// 在demo中,为了方便测试,写死.媒体在实际应用中注意替换
pid = "946012845"
val adSlot = AdSlot.Builder()
.setCodeId(pid) //广告位id
.setSupportDeepLink(true)
.setAdCount(1) //请求广告数量为1到3条
.setExpressViewAcceptedSize(600f, 0f) //期望模板广告view的size,单位dp
.build()
mTTAdNative.loadBannerExpressAd(adSlot, object : TTAdNative.NativeExpressAdListener {
//请求失败回调
override fun onError(code: Int, message: String) {
fragment.setBannerError(bean.requestId)
}
//请求成功回调
override fun onNativeExpressAdLoad(ads: List<TTNativeExpressAd>) {
if (ads == null || ads.size == 0) {
return
}
fragment.setBannerLoad(bean.requestId)
mTTAd = ads[0]
mTTAd?.setSlideIntervalTime(30 * 1000) //设置轮播间隔 ms,不调用则不进行轮播展示
bindBytedanceBannerAdListener(fragment, bean, mTTAd!!)
mTTAd?.render() //调用render开始渲染广告
}
})
}
/**
* 绑定穿山甲banner类型监听
* @param fragment
* @param bean
* @param ad
*/
private fun bindBytedanceBannerAdListener(fragment: CampaignFragment, bean: JsBridgeBean, ad: TTNativeExpressAd) {//绑定穿山甲banner监听
ad.setExpressInteractionListener(object : TTNativeExpressAd.ExpressAdInteractionListener {
override fun onAdClicked(view: View, type: Int) {
fragment.setBannerClick(bean.requestId)
}
override fun onAdShow(view: View, type: Int) {}
override fun onRenderFail(view: View, msg: String, code: Int) {
fragment.setBannerError(bean.requestId)
}
override fun onRenderSuccess(view: View, width: Float, height: Float) {
fragment.setBannerExpose(bean.requestId)
//在渲染成功回调时展示广告,提升体验
bannerContainer?.removeAllViews()
bannerContainer?.addView(view)
}
})
//dislike设置
bindDislike(fragment, bean, ad)
if (ad.interactionType != TTAdConstant.INTERACTION_TYPE_DOWNLOAD) {
return
}
}
/**
* 穿山甲banner广告关闭事件绑定
* @param fragment
* @param bean
* @param ad
*/
private fun bindDislike(fragment: CampaignFragment, bean: JsBridgeBean, ad: TTNativeExpressAd) {
//使用默认个性化模板中默认dislike弹出样式
ad.setDislikeCallback(this@XiaomanActivity, object : TTAdDislike.DislikeInteractionCallback {
override fun onSelected(position: Int, value: String) {
//用户选择不喜欢原因后,移除广告展示
fragment.setBannerClose(bean.requestId)
bannerContainer?.removeAllViews()
}
override fun onCancel() {}
override fun onRefuse() {}
})
}
override fun onBackPressed() {
finish()
// Toast.makeText(this@XiaomanActivity2, "按下返回键onBackPressed", Toast.LENGTH_LONG).show()
/* if (campaignFragment != null) {
campaignFragment.backButtonClick(new CampaignFragment.CallBack() {//返回当前界面必须回调
@Override
public void onSuccess(String jsonData) {
Main2Activity.super.onBackPressed();
}
@Override
public void onFailure(String code, String errmsg) {
}
});
} else {
super.onBackPressed();
}*/
}
/**
* 释放前一个 NativeExpressADData2 的资源
*/
private fun destroyAd() {
if (mNativeExpressADData2 != null) {
Log.d(TAG, "destroyAD")
mNativeExpressADData2?.destroy()
}
}
override fun isApplyKitKatTranslucency(): Boolean {
return false
}
override fun onClick(v: View) {
when (v.id) {
R.id.ivXiaomanBack -> {
finish()
}
}
}
}
\ No newline at end of file
package com.mints.goodmoney.ui.activitys
import android.graphics.Point
import android.os.Bundle
import android.text.TextUtils
import android.util.Log
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.Toast
import androidx.fragment.app.FragmentTransaction
import com.bx.adsdk.AdSdk
import com.bx.adsdk.CampaignCallback
import com.bx.adsdk.CampaignFragment
import com.bytedance.sdk.openadsdk.AdSlot
import com.bytedance.sdk.openadsdk.FilterWord
import com.bytedance.sdk.openadsdk.PersonalizationPrompt
import com.bytedance.sdk.openadsdk.TTAdConstant
import com.bytedance.sdk.openadsdk.TTAdDislike
import com.bytedance.sdk.openadsdk.TTAdManager
import com.bytedance.sdk.openadsdk.TTAdNative
import com.bytedance.sdk.openadsdk.TTAdSdk
import com.bytedance.sdk.openadsdk.TTAppDownloadListener
import com.bytedance.sdk.openadsdk.TTNativeExpressAd
import com.bytedance.sdk.openadsdk.TTRewardVideoAd
import com.google.gson.Gson
import com.mints.goodmoney.R
import com.mints.goodmoney.mvp.model.JsBridgeBean
import com.mints.goodmoney.ui.activitys.base.BaseActivity
import com.qq.e.ads.banner2.UnifiedBannerADListener
import com.qq.e.ads.banner2.UnifiedBannerView
import com.qq.e.ads.nativ.express2.AdEventListener
import com.qq.e.ads.nativ.express2.NativeExpressAD2
import com.qq.e.ads.nativ.express2.NativeExpressADData2
import com.qq.e.ads.rewardvideo.RewardVideoAD
import com.qq.e.ads.rewardvideo.RewardVideoADListener
import com.qq.e.comm.util.AdError
import com.ss.android.ttmd5.FileRandomAccess
import java.util.logging.Logger
import kotlinx.android.synthetic.main.activity_layout_xiaoman2.*
class XiaomanActivity2 : BaseActivity(), View.OnClickListener {
private val PLACE_ID: String = "3497"
private var isPlaySuccess = false
private var rewardVideoAD: RewardVideoAD? = null
private var unifiedBannerView: UnifiedBannerView? = null
private val TAG = "XiaomanActivity2"
private val campaignFragment: CampaignFragment? = null
private var mttRewardVideoAd: TTRewardVideoAd? = null
private var mTTAd: TTNativeExpressAd? = null
private var mNativeExpressADData2: NativeExpressADData2? = null
private var mNativeExpressAD2: NativeExpressAD2? = null
private val bannerContainer: ViewGroup? = null
override fun getContentViewLayoutID(): Int {
return R.layout.activity_layout_xiaoman2
}
override fun initViewsAndEvents() {
initListener()
/**
* CampaignFragment.newInstance("这里为userId")
* 为方便测试,demo中采用时间戳来标识用户唯一id
* 媒体对接时注意替换
*/
val fragment = CampaignFragment.newInstance(System.currentTimeMillis().toString() + "")
// fragment.setPlaceId(intent.getStringExtra("placeId"))
fragment.setPlaceId(PLACE_ID)
// fragment.setPlaceId("3497")
fragment.setCallback(object : CampaignCallback() {
override fun showAd(s: String) {//2.2.9.1//调用激励视频
super.showAd(s)
/**
* 这里需要根据adType来判断展示广告的平台 1-穿山甲 2-广点通 3-快手
* pid: 对应平台的代码位
*
* 这里采用广点通的例子,媒体注意替换
*/
val bean: JsBridgeBean = Gson().fromJson(s, JsBridgeBean::class.java)
if (bean.adType.equals("1")) {
loadBytedanceAd(fragment, bean)
} else if (bean.adType.equals("2")) {
loadGDTRewardVideo(fragment, bean)
}
}
/**
* Banner广告
* @param params
*/
override fun showBanner(params: String) {
//2.2.9.3 展示Banner类型广告
Log.d(TAG, "showBanner: $params")
Toast.makeText(this@XiaomanActivity2, params, Toast.LENGTH_LONG).show()
val bean: JsBridgeBean = Gson().fromJson(params, JsBridgeBean::class.java)
if (TextUtils.isEmpty(bean.pid)) {
return
}
when (bean.adType) {
"4" -> loadCSJBannerAd(fragment, bean)//穿山甲激励视频
"5" -> loadGDTBannerAd(fragment, bean)//广点通激励视频
"13" -> loadCSJBannerAd(fragment, bean)//穿山甲横幅
"14" -> loadGDTNativeExpressAd(fragment, bean)//广点通横幅
}
}
override fun hideBanner(params: String) {
super.hideBanner(params)
bannerContainer?.removeAllViews()
if (unifiedBannerView != null) {
unifiedBannerView?.destroy()
unifiedBannerView = null
}
}
})
val transaction: FragmentTransaction = supportFragmentManager.beginTransaction()
transaction.add(R.id.frame_layout, fragment)
transaction.commitAllowingStateLoss()
}
private fun initListener() {
ivXiaomanBack.setOnClickListener(this)
}
/**
* banner2.0规定banner宽高比应该为6.4:1 , 开发者可自行设置符合规定宽高比的具体宽度和高度值
*
* @return
*/
private fun getUnifiedBannerLayoutParams(): FrameLayout.LayoutParams? {
val screenSize = Point()
windowManager.defaultDisplay.getSize(screenSize)
return FrameLayout.LayoutParams(screenSize.x, Math.round(screenSize.x / 6.4f))
}
override fun onDestroy() {
super.onDestroy()
if (unifiedBannerView != null) {
unifiedBannerView?.destroy()
}
if (mTTAd != null) {
//调用destroy()方法释放
mTTAd!!.destroy()
}
destroyAd()
}
/**
* 加载广点通横幅广告
* @param fragment
* @param bean
*/
private fun loadGDTNativeExpressAd(fragment: CampaignFragment, bean: JsBridgeBean) {
// 创建广告
mNativeExpressAD2 = NativeExpressAD2(applicationContext, "3081971852112087", object : NativeExpressAD2.AdLoadListener {
override fun onLoadSuccess(list: List<NativeExpressADData2>) {
fragment.setBannerLoad(bean.requestId)
gdtBannerRenderAd(fragment, bean, list)
}
override fun onNoAD(adError: AdError) {
fragment.setBannerError(bean.requestId)
}
})
mNativeExpressAD2?.setAdSize(390, 0) // 单位dp
mNativeExpressAD2?.loadAd(1)
destroyAd()
bannerContainer?.removeAllViews()
}
/**
* 渲染广告
* @param adDataList
*/
private fun gdtBannerRenderAd(fragment: CampaignFragment, bean: JsBridgeBean, adDataList: List<NativeExpressADData2>) {
if (adDataList.size > 0) {
bannerContainer?.removeAllViews()
mNativeExpressADData2 = adDataList[0]
mNativeExpressADData2?.setAdEventListener(object : AdEventListener {
override fun onClick() {
Log.i(TAG, "onClick: $mNativeExpressADData2")
fragment.setBannerClick(bean.requestId)
}
override fun onExposed() {
Log.i(TAG, "onImpression: $mNativeExpressADData2")
fragment.setBannerExpose(bean.requestId)
}
override fun onRenderSuccess() {
Log.i(TAG, "onRenderSuccess: $mNativeExpressADData2")
bannerContainer?.removeAllViews()
if (mNativeExpressADData2?.getAdView() != null) {
bannerContainer?.addView(mNativeExpressADData2?.getAdView())
}
}
override fun onRenderFail() {
Log.i(TAG, "onRenderFail: $mNativeExpressADData2")
fragment.setBannerError(bean.requestId)
}
override fun onAdClosed() {
Log.i(TAG, "onAdClosed: $mNativeExpressADData2")
fragment.setBannerClose(bean.requestId)
bannerContainer?.removeAllViews()
mNativeExpressADData2?.destroy()
}
})
mNativeExpressADData2!!.render()
}
}
/**
* 加载广点通
* @param fragment
* @param bean
*/
private fun loadGDTRewardVideo(fragment: CampaignFragment, bean: JsBridgeBean) {
var pid = bean.pid
// TODO: 2021/1/8 demo中代码位写死, 媒体注意替换
pid = "3081971852112087"
val appId = "1111046903"
rewardVideoAD = RewardVideoAD(applicationContext, appId, pid, object : RewardVideoADListener {
override fun onADLoad() {
Log.e(TAG, "onADLoad")
rewardVideoAD?.showAD()
isPlaySuccess = false
fragment.setVideoLoad(bean.requestId)
}
override fun onVideoCached() {
Log.e(TAG, "onVideoCached")
}
override fun onADShow() {
Log.e(TAG, "onADShow")
}
override fun onADExpose() {
Log.e(TAG, "onADExpose")
fragment.setVideoExposeComplete(bean.requestId)
}
override fun onReward() {
Log.e(TAG, "onReward")
isPlaySuccess = true
}
override fun onADClick() {
Log.e(TAG, "onADClick")
fragment.setVideoClickComplete(bean.requestId)
}
override fun onVideoComplete() {
Log.e(TAG, "onVideoComplete")
}
override fun onADClose() {
Log.e(TAG, "onADClose")
if (isPlaySuccess) {
fragment.setVideoClose(bean.requestId)
} else {
fragment.setVideoSkip(bean.requestId)
}
}
override fun onError(adError: AdError) {
Log.e(TAG, "onError:--->" + adError.errorMsg)
fragment.setVideoError(bean.requestId)
}
})
rewardVideoAD?.loadAD()
}
/**
* 加载广点通banner广告
* @param fragment
* @param bean
*/
private fun loadGDTBannerAd(fragment: CampaignFragment?, bean: JsBridgeBean) {
var pid = bean.pid
// TODO: 2021/1/8 demo中代码位写死, 媒体注意替换
pid = "3081971852112087"
//广点通底部Banner
unifiedBannerView = UnifiedBannerView(this@XiaomanActivity2, pid, object : UnifiedBannerADListener {
override fun onNoAD(adError: AdError) {
Log.e(TAG, "广告加载失败: onNoAD")
fragment?.setBannerError(bean.requestId)
}
override fun onADReceive() {
Log.e(TAG, "广告加载成功回调: onADReceive")
fragment?.setBannerLoad(bean.requestId)
}
override fun onADExposure() {
Log.e(TAG, "广告曝光: onADExposure")//2.2.7.1 曝光上报,在活动入口渲染完成后必须调用
fragment?.setBannerExpose(bean.requestId)
}
override fun onADClosed() {
Log.e(TAG, "广告关闭: onADClosed")
fragment?.setBannerClose(bean.requestId)
}
override fun onADClicked() {
Log.e(TAG, "广告点击: onADClicked")//2.2.7.2 点击上报,活动入口点击时进行调用必须调用
fragment?.setBannerClick(bean.requestId)
}
override fun onADLeftApplication() {
Log.e(TAG, "广告点击离开 APP : onADLeftApplication")
}
override fun onADOpenOverlay() {
Log.e(TAG, "广告打开浮层: onADOpenOverlay")
}
override fun onADCloseOverlay() {
Log.e(TAG, "广告浮层关闭: onADCloseOverlay")
}
})
bannerContainer?.addView(unifiedBannerView, getUnifiedBannerLayoutParams())
unifiedBannerView!!.loadAD()
}
/**
* 加载穿山甲视频广告
* @param fragment
* @param bean
*/
private fun loadBytedanceAd(fragment: CampaignFragment, bean: JsBridgeBean) {//2.2.9.2 广告数据上报//底部穿山甲banner
var pid = bean.pid
// TODO: 2021/1/8 demo中代码位写死, 媒体注意替换
pid = "946012845"
val adSlot = AdSlot.Builder()
.setCodeId(pid) // 这里要替换成 bean.pid
.setAdCount(1) //个性化模板广告需要设置期望个性化模板广告的大小,单位dp,激励视频场景,只要设置的值大于0即可
.setExpressViewAcceptedSize(500f, 500f)
.setImageAcceptedSize(1080, 1920) //非必传参数,仅奖励发放服务端回调时需要使用
.setUserID("user123") //非必传参数,仅奖励发放服务端回调时需要使用
.setMediaExtra("media_extra")
.build()
val mTTAdNative = TTAdSdk.getAdManager().createAdNative(applicationContext)
mTTAdNative.loadRewardVideoAd(adSlot, object : TTAdNative.RewardVideoAdListener {
override fun onError(code: Int, message: String) {
Log.d(TAG, "穿山甲-加载失败$code====$message")
fragment.setVideoError(bean.requestId)
}
//视频广告加载后的视频文件资源缓存到本地的回调
override fun onRewardVideoCached() {}
//视频广告素材加载到,如title,视频url等,不包括视频文件
override fun onRewardVideoAdLoad(ad: TTRewardVideoAd) {
fragment.setVideoLoad(bean.requestId)
Log.d(TAG, "穿山甲-加载成功")
isPlaySuccess = false
mttRewardVideoAd = ad
bindBytedanceVideoAdListener(fragment, bean, mttRewardVideoAd!!)
mttRewardVideoAd?.showRewardVideoAd(this@XiaomanActivity2)
}
})
}
/**
* 穿山甲激励视频绑定监听事件
* @param fragment
* @param bean
*/
private fun bindBytedanceVideoAdListener(fragment: CampaignFragment, bean: JsBridgeBean, ad: TTRewardVideoAd) {
ad.setRewardAdInteractionListener(object : TTRewardVideoAd.RewardAdInteractionListener {
override fun onAdShow() {
Log.d(TAG, "穿山甲-曝光")
fragment.setVideoExposeComplete(bean.requestId)
}
override fun onAdVideoBarClick() {
Log.d(TAG, "穿山甲-点击")
fragment.setVideoClickComplete(bean.requestId)
}
override fun onAdClose() {
if (isPlaySuccess) {
fragment.setVideoClose(bean.requestId)
} else {
fragment.setVideoSkip(bean.requestId)
}
}
override fun onVideoComplete() {}
override fun onVideoError() {
Log.d(TAG, "穿山甲-视频失败")
fragment.setVideoError(bean.requestId)
}
override fun onRewardVerify(rewardVerify: Boolean, rewardAmount: Int, rewardName: String, errorCode: Int, errorMsg: String) {
Log.d(TAG, "穿山甲-验证")
isPlaySuccess = rewardVerify
}
override fun onSkippedVideo() {}
})
}
/**
* 加载穿山甲banner广告,穿山甲激励视频
* @param fragment
* @param bean
*/
private fun loadCSJBannerAd(fragment: CampaignFragment, bean: JsBridgeBean) {
val mTTAdNative = TTAdSdk.getAdManager().createAdNative(applicationContext)//2.2.9.3穿山甲底部banner
var pid = bean.pid
// 在demo中,为了方便测试,写死.媒体在实际应用中注意替换
pid = "946012845"
val adSlot = AdSlot.Builder()
.setCodeId(pid) //广告位id
.setSupportDeepLink(true)
.setAdCount(1) //请求广告数量为1到3条
.setExpressViewAcceptedSize(600f, 0f) //期望模板广告view的size,单位dp
.build()
mTTAdNative.loadBannerExpressAd(adSlot, object : TTAdNative.NativeExpressAdListener {
//请求失败回调
override fun onError(code: Int, message: String) {
fragment.setBannerError(bean.requestId)
}
//请求成功回调
override fun onNativeExpressAdLoad(ads: List<TTNativeExpressAd>) {
if (ads == null || ads.size == 0) {
return
}
fragment.setBannerLoad(bean.requestId)
mTTAd = ads[0]
mTTAd?.setSlideIntervalTime(30 * 1000) //设置轮播间隔 ms,不调用则不进行轮播展示
bindBytedanceBannerAdListener(fragment, bean, mTTAd!!)
mTTAd?.render() //调用render开始渲染广告
}
})
}
/**
* 绑定穿山甲banner类型监听
* @param fragment
* @param bean
* @param ad
*/
private fun bindBytedanceBannerAdListener(fragment: CampaignFragment, bean: JsBridgeBean, ad: TTNativeExpressAd) {//绑定穿山甲banner监听
ad.setExpressInteractionListener(object : TTNativeExpressAd.ExpressAdInteractionListener {
override fun onAdClicked(view: View, type: Int) {
fragment.setBannerClick(bean.requestId)
}
override fun onAdShow(view: View, type: Int) {}
override fun onRenderFail(view: View, msg: String, code: Int) {
fragment.setBannerError(bean.requestId)
}
override fun onRenderSuccess(view: View, width: Float, height: Float) {
fragment.setBannerExpose(bean.requestId)
//在渲染成功回调时展示广告,提升体验
bannerContainer?.removeAllViews()
bannerContainer?.addView(view)
}
})
//dislike设置
bindDislike(fragment, bean, ad)
if (ad.interactionType != TTAdConstant.INTERACTION_TYPE_DOWNLOAD) {
return
}
}
/**
* 穿山甲banner广告关闭事件绑定
* @param fragment
* @param bean
* @param ad
*/
private fun bindDislike(fragment: CampaignFragment, bean: JsBridgeBean, ad: TTNativeExpressAd) {
//使用默认个性化模板中默认dislike弹出样式
ad.setDislikeCallback(this@XiaomanActivity2, object : TTAdDislike.DislikeInteractionCallback {
override fun onSelected(position: Int, value: String) {
//用户选择不喜欢原因后,移除广告展示
fragment.setBannerClose(bean.requestId)
bannerContainer?.removeAllViews()
}
override fun onCancel() {}
override fun onRefuse() {}
})
}
override fun onBackPressed() {
finish()
// Toast.makeText(this@XiaomanActivity2, "按下返回键onBackPressed", Toast.LENGTH_LONG).show()
/* if (campaignFragment != null) {
campaignFragment.backButtonClick(new CampaignFragment.CallBack() {//返回当前界面必须回调
@Override
public void onSuccess(String jsonData) {
Main2Activity.super.onBackPressed();
}
@Override
public void onFailure(String code, String errmsg) {
}
});
} else {
super.onBackPressed();
}*/
}
/**
* 释放前一个 NativeExpressADData2 的资源
*/
private fun destroyAd() {
if (mNativeExpressADData2 != null) {
Log.d(TAG, "destroyAD")
mNativeExpressADData2?.destroy()
}
}
override fun isApplyKitKatTranslucency(): Boolean {
return false
}
override fun onClick(v: View) {
when (v.id) {
R.id.ivXiaomanBack -> {
finish()
}
}
}
}
\ No newline at end of file
package com.mints.goodmoney.ui.activitys
import android.text.TextUtils
import android.view.View
import com.mints.goodmoney.MintsApplication
import com.mints.goodmoney.R
import com.mints.goodmoney.common.Constant
import com.mints.goodmoney.mvp.model.*
import com.mints.goodmoney.mvp.presenters.MyPresenter
import com.mints.goodmoney.mvp.views.MyView
import com.mints.goodmoney.ui.activitys.base.BaseActivity
import com.mints.library.utils.CommonUtils
import com.mints.library.utils.nodoubleclick.AntiShake
import kotlinx.android.synthetic.main.activity_zmain.*
//当使用第三方登录的时候需要继承OnLoginListener
class ZaActivity : BaseActivity(), MyView, View.OnClickListener {
private val myPresenter by lazy { MyPresenter() }
private var channel: String = ""//获取渠道,类比oppo,vivo等应用商店,方便统计使用人数
override fun toggleOverridePendingTransition() = true
override fun getOverridePendingTransitionMode() = TransitionMode.BOTTOM
override fun initViewsAndEvents() {
myPresenter.attachView(this)
channel = CommonUtils.getAppMetaData(MintsApplication.getContext(), "CHANNEL_NAME")
initListener()
}
private fun initListener() {
back_z.setOnClickListener(this)
Login_z.setOnClickListener(this)
}
override fun getContentViewLayoutID() = R.layout.activity_zmain
override fun isApplyKitKatTranslucency() = false
override fun onDestroy() {
super.onDestroy()
myPresenter.detachView()
}
override fun onClick(v: View?) {
if (AntiShake.check(v?.id)) return
when (v?.id) {
R.id.back_z->{
if (!TextUtils.equals(channel, Constant.CHANNEL_SHARE)) {
finish()
}
}
R.id.Login_z -> {
readyGo(XiaomanActivity::class.java)
}
}
}
override fun getUserTaskMsgSuc(data: MyInfo?) {
//
}
override fun getUserTaskMsgFail() {
}
override fun getMyHotActivitySuc(data: BannerBean?) {
}
override fun getSignInHomePageMsgSuc(signBean: SignCardBean?) {
}
override fun signInHomePageSuc() {
}
override fun userLoginSuc() {
}
override fun getHallBaseMsgSuc(data: UserTaskMsgBean) {
}
override fun getMyRotationChartSuc(data: RotationChartBean) {
showToast("登录成功")
}
}
......@@ -9,7 +9,6 @@ import android.content.Intent
import android.content.IntentFilter
import android.os.Bundle
import android.text.TextUtils
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.widget.AdapterView
......@@ -17,7 +16,6 @@ import android.widget.GridView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.viewpager.widget.ViewPager
import com.chineseall.reader17ksdk.binds.bindRecycleViewLayoutManager
import com.component.dly.xzzq_ywsdk.YwSDK_WebActivity.Companion.open
import com.fly.scenemodule.SceneUtil
import com.mints.goodmoney.BuildConfig
......@@ -247,10 +245,9 @@ class MyFragment : BaseFragment(),
// 生成热门活动数据
private fun generateGridData(data: List<BannerBean.ListBean>) {
val inflater = LayoutInflater.from(mContext)
for (i in 0 until data.size){
if (data.get(i).toUrl.equals(Constant.HOT_ACTIVITY_SHEEP)){
for (i in 0 until data.size) {
if (data.get(i).toUrl.equals(Constant.HOT_ACTIVITY_SHEEP)) {
XmManager.loadMater(data.get(i).xmPlaceId)
Log.d("MyFragment","*****************MYFragment*********************")
break
}
}
......@@ -951,12 +948,13 @@ class MyFragment : BaseFragment(),
when (hotBean.toUrl) {
Constant.HOT_ACTIVITY_SHEEP -> {
XmManager.exprotClick(hotBean.xmPlaceId)
readyGo(XiaomanActivity2::class.java)
val bundle = Bundle()
bundle.putString(Constant.MAIN_CARRIER_TYPE, hotBean.xmPlaceId)
readyGo(XiaomanActivity::class.java, bundle)
}
Constant.HOT_ACTIVITY_WATER -> {
TTPreLoadCarrierExpressManager.getInstance().loadTtFrameLayout(TtCsjAdManager.TT_AD_NATIVEEXPRESS_WATER)
readyGo(WaterActivity::class.java)
}
Constant.HOT_ACTIVITY_WALK -> {
TTPreLoadCarrierExpressManager.getInstance().loadTtFrameLayout(TtCsjAdManager.TT_AD_NATIVEEXPRESS_WALK)
......
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