|
56 | 56 | import org.prebid.mobile.rendering.views.webview.WebViewBase; |
57 | 57 |
|
58 | 58 | import java.lang.ref.WeakReference; |
| 59 | +import java.util.concurrent.FutureTask; |
| 60 | +import java.util.concurrent.RunnableFuture; |
59 | 61 |
|
60 | 62 | @SuppressLint("NewApi") |
61 | 63 | public class BaseJSInterface implements JSInterface { |
@@ -119,9 +121,11 @@ public String getMaxSize() { |
119 | 121 | JSONObject maxSize = new JSONObject(); |
120 | 122 | try { |
121 | 123 | final Rect currentMaxSizeRect = screenMetrics.getCurrentMaxSizeRect(); |
122 | | - maxSize.put(JSON_WIDTH, currentMaxSizeRect.width()); |
123 | | - maxSize.put(JSON_HEIGHT, currentMaxSizeRect.height()); |
124 | | - return maxSize.toString(); |
| 124 | + if (currentMaxSizeRect != null) { |
| 125 | + maxSize.put(JSON_WIDTH, currentMaxSizeRect.width()); |
| 126 | + maxSize.put(JSON_HEIGHT, currentMaxSizeRect.height()); |
| 127 | + return maxSize.toString(); |
| 128 | + } |
125 | 129 | } |
126 | 130 | catch (Exception e) { |
127 | 131 | LogUtil.error(TAG, "Failed getMaxSize() for MRAID: " + Log.getStackTraceString(e)); |
@@ -171,10 +175,12 @@ public String getDefaultPosition() { |
171 | 175 | public String getCurrentPosition() { |
172 | 176 | JSONObject position = new JSONObject(); |
173 | 177 | Rect rect = new Rect(); |
174 | | - |
175 | | - adBaseView.getGlobalVisibleRect(rect); |
176 | | - |
| 178 | + Handler mainHandler = new Handler(Looper.getMainLooper()); |
| 179 | + Runnable mainThreadRunnable = () -> adBaseView.getGlobalVisibleRect(rect); |
| 180 | + RunnableFuture<Void> task = new FutureTask<>(mainThreadRunnable, null); |
177 | 181 | try { |
| 182 | + mainHandler.post(task); |
| 183 | + task.get(); |
178 | 184 | position.put(JSON_X, (int) (rect.left / Utils.DENSITY)); |
179 | 185 | position.put(JSON_Y, (int) (rect.top / Utils.DENSITY)); |
180 | 186 | position.put(JSON_WIDTH, (int) (rect.right / Utils.DENSITY - rect.left / Utils.DENSITY)); |
|
0 commit comments