Skip to content

Commit

Permalink
大概复制一份
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangruiyu committed Jan 14, 2025
1 parent e922725 commit 04a7bec
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 102 deletions.
1 change: 1 addition & 0 deletions lib/flutter_unionad.dart
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ class FlutterUnionad {
return await _channel.invokeMethod("loadFullScreenVideoAdInteraction", {
"androidCodeId": androidCodeId,
"iosCodeId": iosCodeId,
"ohosCodeId": ohosCodeId,
"orientation": orientation ?? FlutterUnionadOrientation.VERTICAL,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
} from '@csj/openadsdk';
import { UIAbility } from '@kit.AbilityKit';
import FlutterUnionadEventPlugin from './FlutterUnionadEventPlugin';
import FullScreenVideoAdInteraction from 'flutter_unionad/src/main/ets/components/plugin/FullScreenVideoAdInteraction';
import FullScreenVideoAdInteraction from './FullScreenVideoAdInteraction';

/** FlutterUnionadPlugin **/
export default class FlutterUnionadPlugin implements FlutterPlugin, MethodCallHandler, AbilityAware {
Expand Down
199 changes: 98 additions & 101 deletions ohos/src/main/ets/components/plugin/FullScreenVideoAdInteraction.ets
Original file line number Diff line number Diff line change
Expand Up @@ -15,115 +15,112 @@ import { window } from '@kit.ArkUI';
* @Author: gstory0404@gmail
* @CreateDate: 2020/8/21 15:48
*/
export default class FullScreenVideoAdInteraction {
private static TAG = "FullScreenVideoExpressAd"
static mContext: Context|null = null
static mActivity: window.WindowStage|null = null
private static mttFullVideoAd: CSJFullAd|null = null
export default class FullScreenVideoAdInteraction {
private static TAG = "FullScreenVideoExpressAd"
static mContext: Context | null = null
static mActivity: window.WindowStage | null = null
private static mttFullVideoAd: CSJFullAd | null = null
//广告所需参数
private static mCodeId: string | null = null
private static orientation: number = 1
private static mAdCreator: CSJAdCreator | null

//广告所需参数
private static mCodeId: string|null = null
private static orientation : number= 1
private static mAdCreator : CSJAdCreator|null
static init(
context: Context,
mActivity: window.WindowStage | null,
mCodeId: string | null,
orientation: number | null,
): void {
FullScreenVideoAdInteraction.mContext = context
FullScreenVideoAdInteraction.mActivity = mActivity
FullScreenVideoAdInteraction.mCodeId = mCodeId
FullScreenVideoAdInteraction.orientation = orientation!!
FullScreenVideoAdInteraction.loadFullScreenVideoAd()
}


static init(
context: Context,
mActivity: window.WindowStage|null,
mCodeId: string|null,
orientation: number|null,
) :void{
FullScreenVideoAdInteraction.mContext = context
FullScreenVideoAdInteraction.mActivity = mActivity
FullScreenVideoAdInteraction.mCodeId = mCodeId
FullScreenVideoAdInteraction.orientation = orientation!!
FullScreenVideoAdInteraction.loadFullScreenVideoAd()
private static loadFullScreenVideoAd() {
Log.e(FullScreenVideoAdInteraction.TAG, "广告位id $mCodeId")
FullScreenVideoAdInteraction.mAdCreator = CSJAdSdk.getAdCreator()
//设置广告参数
let adSlot = new AdSlotBuilder().setCodeId(FullScreenVideoAdInteraction.mCodeId)//广告位id
.setOrientation(FullScreenVideoAdInteraction.orientation).build()
let mLoadListener: FullAdLoadListener = {
onAdLoaded: (fullAd: CSJFullAd) => {
// 广告基础信息加载完成
Log.e(FullScreenVideoAdInteraction.TAG, "fullScreenVideoAdInteraction loaded")
FullScreenVideoAdInteraction.mttFullVideoAd = fullAd
let map: Record<string, Any> = {
"adType": "fullScreenVideoAdInteraction", "onAdMethod": "onReady"
}
FlutterUnionadEventPlugin.sendContent(map)
},
onAdCached: (fullAd: CSJFullAd) => {
// 广告基础信息与素材缓存完成
Log.e(FullScreenVideoAdInteraction.TAG, "fullScreenVideoAdInteraction video cached2")
},
onError: (code: number, message: string) => {
Log.e(FullScreenVideoAdInteraction.TAG, "fullScreenVideoAd加载失败 $code === > $message")
let map: Record<string, Any> = {
"adType": "fullScreenVideoAdInteraction",
"onAdMethod": "onFail",
"error": code + message
}
FlutterUnionadEventPlugin.sendContent(map)
}
}
//加载全屏视频
FullScreenVideoAdInteraction.mAdCreator.loadFullAd(adSlot, mLoadListener)

private static loadFullScreenVideoAd() {
Log.e(FullScreenVideoAdInteraction.TAG, "广告位id $mCodeId")
FullScreenVideoAdInteraction.mAdCreator = CSJAdSdk.getAdCreator()
//设置广告参数
let adSlot = new AdSlotBuilder().setCodeId(FullScreenVideoAdInteraction.mCodeId) //广告位id
.setOrientation(FullScreenVideoAdInteraction.orientation).build()
let mLoadListener: FullAdLoadListener = {
onAdLoaded: (fullAd: CSJFullAd) => {
// 广告基础信息加载完成
Log.e(FullScreenVideoAdInteraction.TAG, "fullScreenVideoAdInteraction loaded")
FullScreenVideoAdInteraction.mttFullVideoAd = fullAd
let map: Record<string, Any> = {
"adType" : "fullScreenVideoAdInteraction", "onAdMethod" : "onReady"
}
FlutterUnionadEventPlugin.sendContent(map)
},
onAdCached: (fullAd: CSJFullAd) => {
// 广告基础信息与素材缓存完成
Log.e(FullScreenVideoAdInteraction.TAG, "fullScreenVideoAdInteraction video cached2")
},
onError: (code: number, message: string) => {
Log.e(FullScreenVideoAdInteraction.TAG, "fullScreenVideoAd加载失败 $code === > $message")
let map: Record<string, Any> = {
"adType": "fullScreenVideoAdInteraction",
"onAdMethod": "onFail",
"error": code + message
}
FlutterUnionadEventPlugin.sendContent(map)
}
}
//加载全屏视频
FullScreenVideoAdInteraction.mAdCreator.loadFullAd(adSlot, mLoadListener)
}

static showAd() {
if (FullScreenVideoAdInteraction.mttFullVideoAd == null) {
let map: Record<string, Any> = {
"adType": "fullScreenVideoAdInteraction",
"onAdMethod": "onUnReady",
"error": "广告预加载未完成"
}
FlutterUnionadEventPlugin.sendContent(map)
return
}

static showAd() {
if (FullScreenVideoAdInteraction.mttFullVideoAd == null) {
let map: Record<string, Any> = {
"adType": "fullScreenVideoAdInteraction",
"onAdMethod": "onUnReady",
"error": "广告预加载未完成"
}
FlutterUnionadEventPlugin.sendContent(map)
return
let adInteractionListener: FullAdInteractionListener = {
onShow: () => {
Log.e(FullScreenVideoAdInteraction.TAG, "fullScreenVideoAdInteraction show")
let map: Record<string, Any> = {
"adType": "fullScreenVideoAdInteraction", "onAdMethod": "onShow"
}
FlutterUnionadEventPlugin.sendContent(map)
},
onSkip: () => {
Log.e(FullScreenVideoAdInteraction.TAG, "fullScreenVideoAd skipped")
let map: Record<string, Any> = {
"adType": "fullScreenVideoAdInteraction", "onAdMethod": "onSkip"
}
FlutterUnionadEventPlugin.sendContent(map)
},
onClick: () => {
Log.e(FullScreenVideoAdInteraction.TAG, "fullScreenVideoAd click")
let map: Record<string, Any> = {
"adType": "fullScreenVideoAdInteraction", "onAdMethod": "onClick"
}
let adInteractionListener: FullAdInteractionListener = {
onShow: () => {
Log.e(FullScreenVideoAdInteraction.TAG, "fullScreenVideoAdInteraction show")
let map: Record<string, Any> = {
"adType" : "fullScreenVideoAdInteraction", "onAdMethod" : "onShow"
}
FlutterUnionadEventPlugin.sendContent(map)
},
onSkip: () => {
Log.e(FullScreenVideoAdInteraction.TAG, "fullScreenVideoAd skipped")
let map: Record<string, Any> = {
"adType": "fullScreenVideoAdInteraction", "onAdMethod": "onSkip"
}
FlutterUnionadEventPlugin.sendContent(map)
},
onClick: () => {
Log.e(FullScreenVideoAdInteraction.TAG, "fullScreenVideoAd click")
let map: Record<string, Any> = {
"adType": "fullScreenVideoAdInteraction", "onAdMethod": "onClick"
}
FlutterUnionadEventPlugin.sendContent(map)
},
onClose: () => {
Log.e(FullScreenVideoAdInteraction.TAG, "fullScreenVideoAd close")
let map: Record<string, Any> = {
"adType": "fullScreenVideoAdInteraction", "onAdMethod": "onClose"
}
FlutterUnionadEventPlugin.sendContent(map)
},
onComplete: () => {
Log.e(FullScreenVideoAdInteraction.TAG, "fullScreenVideoAd complete")
let map: Record<string, Any> = {
"adType": "fullScreenVideoAdInteraction", "onAdMethod": "onFinish"
}
FlutterUnionadEventPlugin.sendContent(map)
FlutterUnionadEventPlugin.sendContent(map)
},
onClose: () => {
Log.e(FullScreenVideoAdInteraction.TAG, "fullScreenVideoAd close")
let map: Record<string, Any> = {
"adType": "fullScreenVideoAdInteraction", "onAdMethod": "onClose"
}
FlutterUnionadEventPlugin.sendContent(map)
},
onComplete: () => {
Log.e(FullScreenVideoAdInteraction.TAG, "fullScreenVideoAd complete")
let map: Record<string, Any> = {
"adType": "fullScreenVideoAdInteraction", "onAdMethod": "onFinish"
}
FlutterUnionadEventPlugin.sendContent(map)
}
FullScreenVideoAdInteraction.mttFullVideoAd?.setInteractionListener(adInteractionListener)
FullScreenVideoAdInteraction.mttFullVideoAd?.showFullAd(FullScreenVideoAdInteraction.mActivity)
}

FullScreenVideoAdInteraction.mttFullVideoAd?.setInteractionListener(adInteractionListener)
FullScreenVideoAdInteraction.mttFullVideoAd?.showFullAd(FullScreenVideoAdInteraction.mActivity)
}
}

0 comments on commit 04a7bec

Please sign in to comment.