-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ba9efb
commit fec4ce7
Showing
9 changed files
with
223 additions
and
22 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
android/src/main/kotlin/com/gstory/flutter_tencentad/interstitialad/InterstitialAd.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package com.gstory.flutter_tencentad.interstitialad | ||
|
||
import android.app.Activity | ||
import android.content.Context | ||
import com.gstory.flutter_tencentad.LogUtil | ||
import com.gstory.flutter_tencentad.rewardvideoad.RewardVideoAd | ||
import com.qq.e.ads.interstitial2.UnifiedInterstitialAD | ||
import com.qq.e.ads.interstitial2.UnifiedInterstitialADListener | ||
import com.qq.e.ads.rewardvideo.RewardVideoAD | ||
import com.qq.e.comm.util.AdError | ||
|
||
object InterstitialAd { | ||
private val TAG = "InterstitialAd" | ||
|
||
private lateinit var context: Activity | ||
private var unifiedInterstitialAD: UnifiedInterstitialAD? = null | ||
|
||
private var codeId: String? = null | ||
private var isFullScreen: Boolean? = false | ||
|
||
fun init(context: Activity, params: Map<*, *>) { | ||
this.context = context | ||
this.codeId = params["codeId"] as String | ||
this.isFullScreen = params["isFullScreen"] as Boolean | ||
loadInterstitialAD() | ||
} | ||
|
||
private fun loadInterstitialAD() { | ||
unifiedInterstitialAD = UnifiedInterstitialAD( | ||
context, | ||
codeId, | ||
interstitialADListener | ||
) | ||
if(isFullScreen!!){ | ||
unifiedInterstitialAD?.loadFullScreenAD() | ||
}else{ | ||
unifiedInterstitialAD?.loadAD() | ||
} | ||
} | ||
|
||
fun showAd(){ | ||
if(unifiedInterstitialAD == null){ | ||
return | ||
} | ||
if(isFullScreen!!){ | ||
unifiedInterstitialAD?.showFullScreenAD(context) | ||
}else{ | ||
unifiedInterstitialAD?.showAsPopupWindow() | ||
} | ||
} | ||
|
||
private var interstitialADListener = object : UnifiedInterstitialADListener{ | ||
//插屏全屏视频广告加载完毕,此回调后才可以调用 show 方法 | ||
override fun onADReceive() { | ||
LogUtil.e("$TAG 插屏全屏视频广告加载完毕") | ||
} | ||
|
||
//插屏全屏视频视频广告,视频素材下载完成 | ||
override fun onVideoCached() { | ||
LogUtil.e("$TAG 插屏全屏视频视频广告,视频素材下载完成") | ||
} | ||
|
||
//广告加载失败,error 对象包含了错误码和错误信息 | ||
override fun onNoAD(p0: AdError?) { | ||
LogUtil.e("$TAG 插屏全屏视频视频广告,加载失败 ${p0?.errorCode} ${p0?.errorMsg}") | ||
} | ||
|
||
//插屏全屏视频广告展开时回调 | ||
override fun onADOpened() { | ||
LogUtil.e("$TAG 插屏全屏视频广告展开时回调") | ||
} | ||
|
||
//插屏全屏视频广告曝光时回调 | ||
override fun onADExposure() { | ||
LogUtil.e("$TAG 插屏全屏视频广告曝光时回调") | ||
} | ||
|
||
//插屏全屏视频广告点击时回调 | ||
override fun onADClicked() { | ||
LogUtil.e("$TAG 插屏全屏视频广告点击时回调") | ||
} | ||
|
||
override fun onADLeftApplication() { | ||
LogUtil.e("$TAG 插屏全屏视频视频广告,渲染成功") | ||
} | ||
|
||
//插屏全屏视频广告关闭时回调 | ||
override fun onADClosed() { | ||
LogUtil.e("$TAG 插屏全屏视频广告关闭时回调") | ||
unifiedInterstitialAD?.close() | ||
unifiedInterstitialAD?.destroy() | ||
unifiedInterstitialAD = null | ||
} | ||
|
||
// 插屏全屏视频视频广告,渲染成功 | ||
override fun onRenderSuccess() { | ||
LogUtil.e("$TAG 插屏全屏视频视频广告,渲染成功") | ||
} | ||
|
||
//插屏全屏视频视频广告,渲染失败 | ||
override fun onRenderFail() { | ||
LogUtil.e("$TAG 插屏全屏视频视频广告,渲染失败") | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters