From 08602b2f22ffc5697e641ef268fb5cd16f8d461f Mon Sep 17 00:00:00 2001 From: Ram Parameswaran Date: Fri, 13 Apr 2018 16:58:33 -0700 Subject: [PATCH] Version 3.13.1 of the Google Mobile Ads Unity plugin --- ChangeLog.txt | 13 ++++++++++ .../java/com/google/unity/ads/Banner.java | 25 +++++++++++++++++++ .../Assets/GoogleMobileAds/Api/AdRequest.cs | 2 +- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 49d3270aa..d0bfbd87f 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,5 +1,18 @@ Google Mobile Ads Unity Plugin Change Log +************** +Version 3.13.1 +************** + +Plugin: +- Fixed issue where banner ads reposition to top of screen after a full +screen ad is displayed. + +Built and tested with: +- Google Play services 12.0.1 +- Google Mobile Ads iOS SDK 7.30.0 +- Unity Jar Resolver 1.2.64.0 + ************** Version 3.13.0 ************** diff --git a/source/android-library/app/src/main/java/com/google/unity/ads/Banner.java b/source/android-library/app/src/main/java/com/google/unity/ads/Banner.java index a63ce7f8c..a16f2d22c 100644 --- a/source/android-library/app/src/main/java/com/google/unity/ads/Banner.java +++ b/source/android-library/app/src/main/java/com/google/unity/ads/Banner.java @@ -18,10 +18,12 @@ import android.app.Activity; import android.graphics.Color; import android.graphics.Point; +import android.os.Build; import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.view.ViewParent; +import android.view.ViewTreeObserver; import android.view.WindowManager; import android.widget.PopupWindow; @@ -90,6 +92,12 @@ public class Banner { */ private View.OnLayoutChangeListener mLayoutChangeListener; + /** + * A {@code ViewTreeObserver.OnGlobalLayoutListener} used to detect if a full screen ad was + * shown while a banner ad was on screen. + */ + private ViewTreeObserver.OnGlobalLayoutListener mViewTreeLayoutChangeListener; + /** * Creates an instance of {@code Banner}. @@ -204,6 +212,16 @@ public void onLayoutChange(View v, int left, int top, int right, int bottom, }; mUnityPlayerActivity.getWindow().getDecorView().getRootView() .addOnLayoutChangeListener(mLayoutChangeListener); + + // Workaround for issue where ad view will be repositioned to the top of the screen after + // a full screen ad is shown on some devices. + mViewTreeLayoutChangeListener = new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + updatePosition(); + } + }; + mAdView.getViewTreeObserver().addOnGlobalLayoutListener(mViewTreeLayoutChangeListener); } private void createPopupWindow() { @@ -305,6 +323,13 @@ public void run() { mUnityPlayerActivity.getWindow().getDecorView().getRootView() .removeOnLayoutChangeListener(mLayoutChangeListener); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + mAdView.getViewTreeObserver() + .removeOnGlobalLayoutListener(mViewTreeLayoutChangeListener); + } else { + mAdView.getViewTreeObserver().removeGlobalOnLayoutListener(mViewTreeLayoutChangeListener); + } } /** diff --git a/source/plugin/Assets/GoogleMobileAds/Api/AdRequest.cs b/source/plugin/Assets/GoogleMobileAds/Api/AdRequest.cs index 394d6b83d..23f38dd75 100644 --- a/source/plugin/Assets/GoogleMobileAds/Api/AdRequest.cs +++ b/source/plugin/Assets/GoogleMobileAds/Api/AdRequest.cs @@ -21,7 +21,7 @@ namespace GoogleMobileAds.Api { public class AdRequest { - public const string Version = "3.13.0"; + public const string Version = "3.13.1"; public const string TestDeviceSimulator = "SIMULATOR"; private AdRequest(Builder builder)