|
18 | 18 | import android.app.Activity;
|
19 | 19 | import android.graphics.Color;
|
20 | 20 | import android.graphics.Point;
|
| 21 | +import android.os.Build; |
21 | 22 | import android.util.Log;
|
22 | 23 | import android.view.View;
|
23 | 24 | import android.view.ViewGroup;
|
24 | 25 | import android.view.ViewParent;
|
| 26 | +import android.view.ViewTreeObserver; |
25 | 27 | import android.view.WindowManager;
|
26 | 28 | import android.widget.PopupWindow;
|
27 | 29 |
|
@@ -90,6 +92,12 @@ public class Banner {
|
90 | 92 | */
|
91 | 93 | private View.OnLayoutChangeListener mLayoutChangeListener;
|
92 | 94 |
|
| 95 | + /** |
| 96 | + * A {@code ViewTreeObserver.OnGlobalLayoutListener} used to detect if a full screen ad was |
| 97 | + * shown while a banner ad was on screen. |
| 98 | + */ |
| 99 | + private ViewTreeObserver.OnGlobalLayoutListener mViewTreeLayoutChangeListener; |
| 100 | + |
93 | 101 |
|
94 | 102 | /**
|
95 | 103 | * Creates an instance of {@code Banner}.
|
@@ -204,6 +212,16 @@ public void onLayoutChange(View v, int left, int top, int right, int bottom,
|
204 | 212 | };
|
205 | 213 | mUnityPlayerActivity.getWindow().getDecorView().getRootView()
|
206 | 214 | .addOnLayoutChangeListener(mLayoutChangeListener);
|
| 215 | + |
| 216 | + // Workaround for issue where ad view will be repositioned to the top of the screen after |
| 217 | + // a full screen ad is shown on some devices. |
| 218 | + mViewTreeLayoutChangeListener = new ViewTreeObserver.OnGlobalLayoutListener() { |
| 219 | + @Override |
| 220 | + public void onGlobalLayout() { |
| 221 | + updatePosition(); |
| 222 | + } |
| 223 | + }; |
| 224 | + mAdView.getViewTreeObserver().addOnGlobalLayoutListener(mViewTreeLayoutChangeListener); |
207 | 225 | }
|
208 | 226 |
|
209 | 227 | private void createPopupWindow() {
|
@@ -305,6 +323,13 @@ public void run() {
|
305 | 323 |
|
306 | 324 | mUnityPlayerActivity.getWindow().getDecorView().getRootView()
|
307 | 325 | .removeOnLayoutChangeListener(mLayoutChangeListener);
|
| 326 | + |
| 327 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { |
| 328 | + mAdView.getViewTreeObserver() |
| 329 | + .removeOnGlobalLayoutListener(mViewTreeLayoutChangeListener); |
| 330 | + } else { |
| 331 | + mAdView.getViewTreeObserver().removeGlobalOnLayoutListener(mViewTreeLayoutChangeListener); |
| 332 | + } |
308 | 333 | }
|
309 | 334 |
|
310 | 335 | /**
|
|
0 commit comments