|
|
@@ -0,0 +1,73 @@
|
|
|
+package com.atmob.flutter_ad.adevent;
|
|
|
+
|
|
|
+import com.atmob.ad.callback.OnAdEventCallback;
|
|
|
+import com.atmob.flutter_ad.constants.FlutterAdMethod;
|
|
|
+import com.atmob.flutter_ad.constants.FlutterNameConfig;
|
|
|
+import com.atmob.flutter_ad.utils.FlutterParamsUtils;
|
|
|
+import com.atmob.logging.AtmobLog;
|
|
|
+import com.atmob.sdk.AtmobAdSdk;
|
|
|
+
|
|
|
+import io.flutter.embedding.engine.plugins.FlutterPlugin;
|
|
|
+import io.flutter.plugin.common.MethodChannel;
|
|
|
+
|
|
|
+public class AtmobAdEventHelper {
|
|
|
+
|
|
|
+ private static final String TAG = "AtmobAdEventHelper";
|
|
|
+ private static volatile MethodChannel eventChannel;
|
|
|
+
|
|
|
+ private AtmobAdEventHelper() {
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static void setAdEventCallback(FlutterPlugin.FlutterPluginBinding flutterPluginBinding, MethodChannel.Result result) {
|
|
|
+ try {
|
|
|
+ if (eventChannel == null) {
|
|
|
+ synchronized (AtmobAdEventHelper.class) {
|
|
|
+ if (eventChannel == null) {
|
|
|
+ eventChannel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), FlutterNameConfig.adEvent);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ AtmobAdSdk.getInstance().setAdEventCallback(new OnAdEventCallback() {
|
|
|
+ @Override
|
|
|
+ public void onAdLoad(String adUnionType, String adPlacementId, String adSourceId, String adType, String adnType) {
|
|
|
+ AtmobLog.d(TAG, "onAdLoad: adUnionType = " + adUnionType + ", adPlacementId = " + adPlacementId + ", adSourceId = " + adSourceId + ", adType = " + adType + ", adnType = " + adnType);
|
|
|
+ if (eventChannel != null)
|
|
|
+ eventChannel.invokeMethod(FlutterAdMethod.onAdLoadEvent, FlutterParamsUtils.createAdEventParams(adUnionType, adPlacementId, adSourceId, adType, adnType));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onAdShow(String adUnionType, String adPlacementId, String adSourceId, String adType, String adnType, float ecpm) {
|
|
|
+ AtmobLog.d(TAG, "onAdShow: adUnionType = " + adUnionType + ", adPlacementId = " + adPlacementId + ", adSourceId = " + adSourceId + ", adType = " + adType + ", adnType = " + adnType + ", ecpm = " + ecpm);
|
|
|
+ if (eventChannel != null)
|
|
|
+ eventChannel.invokeMethod(FlutterAdMethod.onAdShowEvent, FlutterParamsUtils.createAdEventParams(adUnionType, adPlacementId, adSourceId, adType, adnType, ecpm));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onAdClick(String adUnionType, String adPlacementId, String adSourceId, String adType, String adnType, float ecpm) {
|
|
|
+ AtmobLog.d(TAG, "onAdClick: adUnionType = " + adUnionType + ", adPlacementId = " + adPlacementId + ", adSourceId = " + adSourceId + ", adType = " + adType + ", adnType = " + adnType + ", ecpm = " + ecpm);
|
|
|
+ if (eventChannel != null)
|
|
|
+ eventChannel.invokeMethod(FlutterAdMethod.onAdClickEvent, FlutterParamsUtils.createAdEventParams(adUnionType, adPlacementId, adSourceId, adType, adnType, ecpm));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onAdPlayStart(String adUnionType, String adPlacementId, String adSourceId, String adType, String adnType, float ecpm) {
|
|
|
+ AtmobLog.d(TAG, "onAdPlayStart: adUnionType = " + adUnionType + ", adPlacementId = " + adPlacementId + ", adSourceId = " + adSourceId + ", adType = " + adType + ", adnType = " + adnType + ", ecpm = " + ecpm);
|
|
|
+ if (eventChannel != null)
|
|
|
+ eventChannel.invokeMethod(FlutterAdMethod.onAdPlayStartEvent, FlutterParamsUtils.createAdEventParams(adUnionType, adPlacementId, adSourceId, adType, adnType, ecpm));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onAdPlayEnd(String adUnionType, String adPlacementId, String adSourceId, String adType, String adnType, float ecpm, int duration, boolean isPlayOver) {
|
|
|
+ AtmobLog.d(TAG, "onAdPlayEnd: adUnionType = " + adUnionType + ", adPlacementId = " + adPlacementId + ", adSourceId = " + adSourceId + ", adType = " + adType + ", adnType = " + adnType + ", ecpm = " + ecpm + ", duration = " + duration + ", isPlayOver = " + isPlayOver);
|
|
|
+ if (eventChannel != null)
|
|
|
+ eventChannel.invokeMethod(FlutterAdMethod.onAdPlayEndEvent, FlutterParamsUtils.createAdEventParams(adUnionType, adPlacementId, adSourceId, adType, adnType, ecpm, duration, isPlayOver));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ result.success(null);
|
|
|
+ } catch (Exception e) {
|
|
|
+ result.error("setAdEventCallback error", e.getMessage(), null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|