Bläddra i källkod

[fix]修复广告问题

zk 1 år sedan
förälder
incheckning
7f645994d8

+ 5 - 4
README.md

@@ -4,9 +4,10 @@
 
 ## Getting Started
 
-FlutterAtmobAd 调用初始化、激励视频、插屏、插全屏
-FlutterSplashAdView 调用开屏广告
-FlutterBannerAdView 调用Banner广告
-FlutterNativeAdView 调用原生广告
+FlutterAtmobAd 调用初始化、激励视频、插屏、插全屏 <br>
+FlutterSplashAdView 调用开屏广告 <br>
+FlutterBannerAdView 调用Banner广告 <br>
+FlutterNativeAdView 调用原生广告 <br>
+
 
 

+ 1 - 1
android/src/main/java/com/atmob/flutter_ad/bannerad/BannerAdView.java

@@ -81,7 +81,7 @@ public class BannerAdView implements PlatformView {
         if (args == null) {
             return;
         }
-        adFuncId = FlutterParamsUtils.getInt(args, "adFuncId", 0);
+        adFuncId = FlutterParamsUtils.getInt(args, "adFuncId", -1);
         AtmobLog.d(TAG, "adFuncId:" + adFuncId);
         channel = new MethodChannel(messenger, FlutterViewConfig.bannerAdView + "_" + viewId);
     }

+ 20 - 34
android/src/main/java/com/atmob/flutter_ad/interstitial/InterstitialAdCall.java

@@ -24,49 +24,42 @@ public class InterstitialAdCall {
 
     public static void loadInterstitial(Context context, MethodChannel channel, MethodCall call, MethodChannel.Result result) {
         Map<String, Object> params = call.arguments();
-        String adFuncId = null;
-        if (params != null && params.containsKey(CommonParams.AdFuncId)) {
-            adFuncId = (String) params.get(CommonParams.AdFuncId);
-        }
-        if (TextUtils.isEmpty(adFuncId)) {
-            result.error("AdFuncId is empty", "AdFuncId is empty", null);
+        if (params == null) {
+            result.error("params is empty", "params is empty", null);
             return;
         }
-        int intAdFuncId;
-        try {
-            intAdFuncId = Integer.parseInt(adFuncId);
-        } catch (NumberFormatException e) {
-            result.error("AdFuncId is not a number", "AdFuncId is not a number", null);
+        if (!params.containsKey(CommonParams.AdFuncId)) {
+            result.error("AdFuncId is empty", "AdFuncId is empty", null);
             return;
         }
+        int adFuncId = FlutterParamsUtils.getInt(params, CommonParams.AdFuncId, -1);
         AtmobLog.d(TAG, "loadInterstitial: adFuncId = " + adFuncId);
         AtmobAdNative adNative = AtmobAdSdk.getInstance().createAdNative(context);
-        String finalAdFuncId = adFuncId;
-        adNative.loadInterstitial(intAdFuncId, new InterstitialListener() {
+        adNative.loadInterstitial(adFuncId, new InterstitialListener() {
             @Override
             public void onShow() {
                 AtmobLog.d(TAG, "loadInterstitial..onShow");
-                channel.invokeMethod(FlutterAdMethod.flutterAdMethod, FlutterParamsUtils.createCommonParams(finalAdFuncId, FlutterListenerMethod.onShow));
+                channel.invokeMethod(FlutterAdMethod.flutterAdMethod, FlutterParamsUtils.createCommonParams(String.valueOf(adFuncId), FlutterListenerMethod.onShow));
             }
 
             @Override
             public void onClose() {
                 AtmobLog.d(TAG, "loadInterstitial..onClose");
-                channel.invokeMethod(FlutterAdMethod.flutterAdMethod, FlutterParamsUtils.createCommonParams(finalAdFuncId, FlutterListenerMethod.onClose));
+                channel.invokeMethod(FlutterAdMethod.flutterAdMethod, FlutterParamsUtils.createCommonParams(String.valueOf(adFuncId), FlutterListenerMethod.onClose));
 
             }
 
             @Override
             public void onFail(String s) {
                 AtmobLog.d(TAG, "loadInterstitial..onFail: " + s);
-                channel.invokeMethod(FlutterAdMethod.flutterAdMethod, FlutterParamsUtils.createCommonParams(finalAdFuncId, FlutterListenerMethod.onFail, s));
+                channel.invokeMethod(FlutterAdMethod.flutterAdMethod, FlutterParamsUtils.createCommonParams(String.valueOf(adFuncId), FlutterListenerMethod.onFail, s));
 
             }
 
             @Override
             public void onClick() {
                 AtmobLog.d(TAG, "loadInterstitial..onClick");
-                channel.invokeMethod(FlutterAdMethod.flutterAdMethod, FlutterParamsUtils.createCommonParams(finalAdFuncId, FlutterListenerMethod.onClick));
+                channel.invokeMethod(FlutterAdMethod.flutterAdMethod, FlutterParamsUtils.createCommonParams(String.valueOf(adFuncId), FlutterListenerMethod.onClick));
 
             }
         });
@@ -74,49 +67,42 @@ public class InterstitialAdCall {
 
     public static void loadInterstitialFull(Context context, MethodChannel channel, MethodCall call, MethodChannel.Result result) {
         Map<String, Object> params = call.arguments();
-        String adFuncId = null;
-        if (params != null && params.containsKey(CommonParams.AdFuncId)) {
-            adFuncId = (String) params.get(CommonParams.AdFuncId);
-        }
-        if (TextUtils.isEmpty(adFuncId)) {
-            result.error("AdFuncId is empty", "AdFuncId is empty", null);
+        if (params == null) {
+            result.error("params is empty", "params is empty", null);
             return;
         }
-        int intAdFuncId;
-        try {
-            intAdFuncId = Integer.parseInt(adFuncId);
-        } catch (NumberFormatException e) {
-            result.error("AdFuncId is not a number", "AdFuncId is not a number", null);
+        if (!params.containsKey(CommonParams.AdFuncId)) {
+            result.error("AdFuncId is empty", "AdFuncId is empty", null);
             return;
         }
+        int adFuncId = FlutterParamsUtils.getInt(params, CommonParams.AdFuncId, -1);
         AtmobLog.d(TAG, "loadInterstitialFull: adFuncId = " + adFuncId);
         AtmobAdNative adNative = AtmobAdSdk.getInstance().createAdNative(context);
-        String finalAdFuncId = adFuncId;
-        adNative.loadInterstitialFull(intAdFuncId, new InterstitialFullListener() {
+        adNative.loadInterstitialFull(adFuncId, new InterstitialFullListener() {
             @Override
             public void onShow() {
                 AtmobLog.d(TAG, "loadInterstitialFull..onShow");
-                channel.invokeMethod(FlutterAdMethod.flutterAdMethod, FlutterParamsUtils.createCommonParams(finalAdFuncId, FlutterListenerMethod.onShow));
+                channel.invokeMethod(FlutterAdMethod.flutterAdMethod, FlutterParamsUtils.createCommonParams(String.valueOf(adFuncId), FlutterListenerMethod.onShow));
             }
 
             @Override
             public void onClose() {
                 AtmobLog.d(TAG, "loadInterstitialFull..onClose");
-                channel.invokeMethod(FlutterAdMethod.flutterAdMethod, FlutterParamsUtils.createCommonParams(finalAdFuncId, FlutterListenerMethod.onClose));
+                channel.invokeMethod(FlutterAdMethod.flutterAdMethod, FlutterParamsUtils.createCommonParams(String.valueOf(adFuncId), FlutterListenerMethod.onClose));
 
             }
 
             @Override
             public void onFail(String s) {
                 AtmobLog.d(TAG, "loadInterstitialFull..onFail: " + s);
-                channel.invokeMethod(FlutterAdMethod.flutterAdMethod, FlutterParamsUtils.createCommonParams(finalAdFuncId, FlutterListenerMethod.onFail, s));
+                channel.invokeMethod(FlutterAdMethod.flutterAdMethod, FlutterParamsUtils.createCommonParams(String.valueOf(adFuncId), FlutterListenerMethod.onFail, s));
 
             }
 
             @Override
             public void onClick() {
                 AtmobLog.d(TAG, "loadInterstitialFull..onClick");
-                channel.invokeMethod(FlutterAdMethod.flutterAdMethod, FlutterParamsUtils.createCommonParams(finalAdFuncId, FlutterListenerMethod.onClick));
+                channel.invokeMethod(FlutterAdMethod.flutterAdMethod, FlutterParamsUtils.createCommonParams(String.valueOf(adFuncId), FlutterListenerMethod.onClick));
             }
         });
     }

+ 1 - 1
android/src/main/java/com/atmob/flutter_ad/nativead/NativeAdView.java

@@ -81,7 +81,7 @@ public class NativeAdView implements PlatformView {
         if (args == null) {
             return;
         }
-        adFuncId = FlutterParamsUtils.getInt(args, "adFuncId", 0);
+        adFuncId = FlutterParamsUtils.getInt(args, "adFuncId", -1);
         AtmobLog.d(TAG, "adFuncId:" + adFuncId);
         channel = new MethodChannel(messenger, FlutterViewConfig.nativeAdView + "_" + viewId);
     }

+ 17 - 5
android/src/main/java/com/atmob/flutter_ad/splash/SplashAdView.java

@@ -2,8 +2,10 @@ package com.atmob.flutter_ad.splash;
 
 import android.app.Activity;
 import android.content.Context;
+import android.view.Gravity;
 import android.view.View;
 import android.widget.FrameLayout;
+import android.widget.LinearLayout;
 
 import androidx.annotation.Nullable;
 
@@ -11,6 +13,7 @@ import com.atmob.ad.listener.SplashListener;
 import com.atmob.flutter_ad.constants.FlutterListenerMethod;
 import com.atmob.flutter_ad.constants.FlutterViewConfig;
 import com.atmob.flutter_ad.utils.FlutterParamsUtils;
+import com.atmob.flutter_ad.utils.ViewUtils;
 import com.atmob.logging.AtmobLog;
 import com.atmob.sdk.AtmobAdNative;
 import com.atmob.sdk.AtmobAdSdk;
@@ -20,6 +23,7 @@ import java.util.Map;
 import io.flutter.plugin.common.BinaryMessenger;
 import io.flutter.plugin.common.MethodChannel;
 import io.flutter.plugin.platform.PlatformView;
+import io.flutter.plugin.platform.PlatformViewWrapper;
 
 public class SplashAdView implements PlatformView {
 
@@ -35,7 +39,7 @@ public class SplashAdView implements PlatformView {
 
     Map<String, Object> args;
 
-    private FrameLayout mContainer = null;
+    private LinearLayout mContainer = null;
 
     private MethodChannel channel;
 
@@ -54,8 +58,10 @@ public class SplashAdView implements PlatformView {
 
 
     void initView() {
-        mContainer = new FrameLayout(context);
-        mContainer.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
+        mContainer = new LinearLayout(context);
+        mContainer.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
+        mContainer.setGravity(Gravity.BOTTOM);
+        mContainer.setOrientation(LinearLayout.VERTICAL);
         channel = new MethodChannel(messenger, FlutterViewConfig.splashAdView + "_" + viewId);
     }
 
@@ -64,7 +70,7 @@ public class SplashAdView implements PlatformView {
         if (args == null) {
             return;
         }
-        adFuncId = FlutterParamsUtils.getInt(args, "adFuncId", 0);
+        adFuncId = FlutterParamsUtils.getInt(args, "adFuncId", -1);
         AtmobLog.d(TAG, "adFuncId:" + adFuncId);
     }
 
@@ -115,7 +121,13 @@ public class SplashAdView implements PlatformView {
     @Nullable
     @Override
     public View getView() {
-        return mContainer;
+        if (mContainer.getChildCount() == 0) {
+            return mContainer;
+        } else if (!(mContainer.getParent() instanceof PlatformViewWrapper)) {
+            return (View) mContainer.getParent();
+        } else {
+            return mContainer;
+        }
     }
 
     @Override

+ 11 - 18
android/src/main/java/com/atmob/flutter_ad/video/RewardVideoAdCall.java

@@ -24,55 +24,48 @@ public class RewardVideoAdCall {
 
     public static void loadRewardVideo(Context context, MethodChannel channel, MethodCall call, MethodChannel.Result result) {
         Map<String, Object> params = call.arguments();
-        String adFuncId = null;
-        if (params != null && params.containsKey(CommonParams.AdFuncId)) {
-            adFuncId = (String) params.get(CommonParams.AdFuncId);
-        }
-        if (TextUtils.isEmpty(adFuncId)) {
-            result.error("AdFuncId is empty", "AdFuncId is empty", null);
+        if (params == null) {
+            result.error("params is empty", "params is empty", null);
             return;
         }
-        int intAdFuncId;
-        try {
-            intAdFuncId = Integer.parseInt(adFuncId);
-        } catch (NumberFormatException e) {
-            result.error("AdFuncId is not a number", "AdFuncId is not a number", null);
+        if (!params.containsKey(CommonParams.AdFuncId)) {
+            result.error("AdFuncId is empty", "AdFuncId is empty", null);
             return;
         }
+        int adFuncId = FlutterParamsUtils.getInt(params, CommonParams.AdFuncId, -1);
         AtmobLog.d(TAG, "loadRewardVideo: adFuncId = " + adFuncId);
         AtmobAdNative adNative = AtmobAdSdk.getInstance().createAdNative(context);
-        String finalAdFuncId = adFuncId;
-        adNative.loadRewardVideo(intAdFuncId, new RewardVideoListener() {
+        adNative.loadRewardVideo(adFuncId, new RewardVideoListener() {
             @Override
             public void onRewarded() {
                 AtmobLog.d(TAG, "loadRewardVideo..onRewarded");
-                channel.invokeMethod(FlutterAdMethod.flutterAdMethod, FlutterParamsUtils.createCommonParams(finalAdFuncId, FlutterListenerMethod.onRewarded));
+                channel.invokeMethod(FlutterAdMethod.flutterAdMethod, FlutterParamsUtils.createCommonParams(String.valueOf(adFuncId), FlutterListenerMethod.onRewarded));
             }
 
             @Override
             public void onShow() {
                 AtmobLog.d(TAG, "loadRewardVideo..onShow");
-                channel.invokeMethod(FlutterAdMethod.flutterAdMethod, FlutterParamsUtils.createCommonParams(finalAdFuncId, FlutterListenerMethod.onShow));
+                channel.invokeMethod(FlutterAdMethod.flutterAdMethod, FlutterParamsUtils.createCommonParams(String.valueOf(adFuncId), FlutterListenerMethod.onShow));
             }
 
             @Override
             public void onClose() {
                 AtmobLog.d(TAG, "loadRewardVideo..onClose");
-                channel.invokeMethod(FlutterAdMethod.flutterAdMethod, FlutterParamsUtils.createCommonParams(finalAdFuncId, FlutterListenerMethod.onClose));
+                channel.invokeMethod(FlutterAdMethod.flutterAdMethod, FlutterParamsUtils.createCommonParams(String.valueOf(adFuncId), FlutterListenerMethod.onClose));
 
             }
 
             @Override
             public void onFail(String s) {
                 AtmobLog.d(TAG, "loadRewardVideo..onFail: " + s);
-                channel.invokeMethod(FlutterAdMethod.flutterAdMethod, FlutterParamsUtils.createCommonParams(finalAdFuncId, FlutterListenerMethod.onFail, s));
+                channel.invokeMethod(FlutterAdMethod.flutterAdMethod, FlutterParamsUtils.createCommonParams(String.valueOf(adFuncId), FlutterListenerMethod.onFail, s));
 
             }
 
             @Override
             public void onClick() {
                 AtmobLog.d(TAG, "loadRewardVideo..onClick");
-                channel.invokeMethod(FlutterAdMethod.flutterAdMethod, FlutterParamsUtils.createCommonParams(finalAdFuncId, FlutterListenerMethod.onClick));
+                channel.invokeMethod(FlutterAdMethod.flutterAdMethod, FlutterParamsUtils.createCommonParams(String.valueOf(adFuncId), FlutterListenerMethod.onClick));
 
             }
         });