|
|
@@ -1,11 +1,13 @@
|
|
|
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 com.atmob.mediation.api.AdConstants;
|
|
|
+import com.atmob.mediation.api.EcpmInfo;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
|
|
|
import io.flutter.embedding.engine.plugins.FlutterPlugin;
|
|
|
import io.flutter.plugin.common.MethodChannel;
|
|
|
@@ -28,46 +30,140 @@ public class AtmobAdEventHelper {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- 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));
|
|
|
- }
|
|
|
+ result.success(null);
|
|
|
+ } catch (Exception e) {
|
|
|
+ result.error("setAdEventCallback error", e.getMessage(), null);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- @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));
|
|
|
- }
|
|
|
+ public static void onAdLoaded(int adType, EcpmInfo ecpmInfo) {
|
|
|
+ String adUnionType = getAdUnionType(ecpmInfo);
|
|
|
+ String adPlacementId = ecpmInfo.getPositionId();
|
|
|
+ String adSourceId = ecpmInfo.getShowPositionId();
|
|
|
+ String adnType = getAdnType(ecpmInfo);
|
|
|
+ if (eventChannel != null) {
|
|
|
+ eventChannel.invokeMethod(FlutterAdMethod.onAdLoadEvent,
|
|
|
+ FlutterParamsUtils.createAdEventParams(adUnionType, adPlacementId, adSourceId, getAdType(adType), adnType));
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- @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));
|
|
|
- }
|
|
|
+ public static void onAdShow(int adType, EcpmInfo ecpmInfo) {
|
|
|
+ String adUnionType = getAdUnionType(ecpmInfo);
|
|
|
+ String adPlacementId = ecpmInfo.getPositionId();
|
|
|
+ String adSourceId = ecpmInfo.getShowPositionId();
|
|
|
+ String adnType = getAdnType(ecpmInfo);
|
|
|
+ float ecpm = getEcpm(ecpmInfo);
|
|
|
+ if (eventChannel != null) {
|
|
|
+ eventChannel.invokeMethod(FlutterAdMethod.onAdShowEvent,
|
|
|
+ FlutterParamsUtils.createAdEventParams(adUnionType, adPlacementId, adSourceId, getAdType(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));
|
|
|
- }
|
|
|
+ public static void onAdClick(int adType, EcpmInfo ecpmInfo) {
|
|
|
+ String adUnionType = getAdUnionType(ecpmInfo);
|
|
|
+ String adPlacementId = ecpmInfo.getPositionId();
|
|
|
+ String adSourceId = ecpmInfo.getShowPositionId();
|
|
|
+ String adnType = getAdnType(ecpmInfo);
|
|
|
+ float ecpm = getEcpm(ecpmInfo);
|
|
|
+ if (eventChannel != null) {
|
|
|
+ eventChannel.invokeMethod(FlutterAdMethod.onAdClickEvent,
|
|
|
+ FlutterParamsUtils.createAdEventParams(adUnionType, adPlacementId, adSourceId, getAdType(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);
|
|
|
+ public static void onAdPlayStart(EcpmInfo ecpmInfo) {
|
|
|
+ String adUnionType = getAdUnionType(ecpmInfo);
|
|
|
+ String adPlacementId = ecpmInfo.getPositionId();
|
|
|
+ String adSourceId = ecpmInfo.getShowPositionId();
|
|
|
+ String adnType = getAdnType(ecpmInfo);
|
|
|
+ float ecpm = getEcpm(ecpmInfo);
|
|
|
+ String adType = getAdType(AdConstants.RewardVideo);
|
|
|
+ if (eventChannel != null) {
|
|
|
+ eventChannel.invokeMethod(FlutterAdMethod.onAdPlayStartEvent,
|
|
|
+ FlutterParamsUtils.createAdEventParams(adUnionType, adPlacementId, adSourceId, adType, adnType, ecpm));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void onAdPlayEnd(EcpmInfo ecpmInfo, int duration, boolean isPlayOver) {
|
|
|
+ String adUnionType = getAdUnionType(ecpmInfo);
|
|
|
+ String adPlacementId = ecpmInfo.getPositionId();
|
|
|
+ String adSourceId = ecpmInfo.getShowPositionId();
|
|
|
+ String adnType = getAdnType(ecpmInfo);
|
|
|
+ float ecpm = getEcpm(ecpmInfo);
|
|
|
+ String adType = getAdType(AdConstants.RewardVideo);
|
|
|
+ if (eventChannel != null) {
|
|
|
+ eventChannel.invokeMethod(FlutterAdMethod.onAdPlayEndEvent,
|
|
|
+ FlutterParamsUtils.createAdEventParams(adUnionType, adPlacementId, adSourceId, adType, adnType, ecpm, duration, isPlayOver));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //reward、banner、 native 、interstitial、 splash
|
|
|
+ public static String getAdType(int adType) {
|
|
|
+ switch (adType) {
|
|
|
+ case AdConstants.Splash:
|
|
|
+ return "splash";
|
|
|
+ case AdConstants.NativeExpress:
|
|
|
+ case AdConstants.NativeUnified:
|
|
|
+ return "native";
|
|
|
+ case AdConstants.Interstitial:
|
|
|
+ case AdConstants.InterstitialFull:
|
|
|
+ return "interstitial";
|
|
|
+ case AdConstants.RewardVideo:
|
|
|
+ return "reward";
|
|
|
+ case AdConstants.BannerExpress:
|
|
|
+ return "banner";
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String getAdUnionType(EcpmInfo ecpmInfo) {
|
|
|
+ if (ecpmInfo == null) {
|
|
|
+ return "self";
|
|
|
+ }
|
|
|
+ int platformId = ecpmInfo.getPlatformId();
|
|
|
+ switch (platformId) {
|
|
|
+ case AdConstants.Gromore:
|
|
|
+ return "gromore";
|
|
|
+ case AdConstants.Taku:
|
|
|
+ case AdConstants.TopOn:
|
|
|
+ return "topon";
|
|
|
+ case AdConstants.Max:
|
|
|
+ return "max";
|
|
|
+ case AdConstants.ToBid:
|
|
|
+ return "tobid";
|
|
|
}
|
|
|
+ return "self";
|
|
|
}
|
|
|
|
|
|
+ public static String getAdnType(EcpmInfo ecpmInfo) {
|
|
|
+ if (ecpmInfo == null) {
|
|
|
+ return "other";
|
|
|
+ }
|
|
|
+ int showPlatformId = ecpmInfo.getShowPlatformId();
|
|
|
+ switch (showPlatformId) {
|
|
|
+ case AdConstants.CSJ:
|
|
|
+ return "csj";
|
|
|
+ case AdConstants.Tencent:
|
|
|
+ return "gdt";
|
|
|
+ case AdConstants.Kuaishou:
|
|
|
+ return "ks";
|
|
|
+ case AdConstants.Mintegral:
|
|
|
+ return "mint";
|
|
|
+ case AdConstants.Baidu:
|
|
|
+ return "baidu";
|
|
|
+ }
|
|
|
+ return "other";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return 单位元
|
|
|
+ */
|
|
|
+ public static float getEcpm(EcpmInfo ecpmInfo) {
|
|
|
+ if (ecpmInfo == null) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ double ecpmCent = ecpmInfo.getEcpmCent();
|
|
|
+ BigDecimal bigDecimal = new BigDecimal(ecpmCent);
|
|
|
+ return bigDecimal.divide(new BigDecimal(100), 2, RoundingMode.HALF_DOWN).floatValue();
|
|
|
+ }
|
|
|
}
|