Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
import org.prebid.mobile.rendering.views.webview.WebViewBase;

import java.lang.ref.WeakReference;
import java.util.concurrent.FutureTask;
import java.util.concurrent.RunnableFuture;

@SuppressLint("NewApi")
public class BaseJSInterface implements JSInterface {
Expand Down Expand Up @@ -119,9 +121,11 @@ public String getMaxSize() {
JSONObject maxSize = new JSONObject();
try {
final Rect currentMaxSizeRect = screenMetrics.getCurrentMaxSizeRect();
maxSize.put(JSON_WIDTH, currentMaxSizeRect.width());
maxSize.put(JSON_HEIGHT, currentMaxSizeRect.height());
return maxSize.toString();
if (currentMaxSizeRect != null) {
maxSize.put(JSON_WIDTH, currentMaxSizeRect.width());
maxSize.put(JSON_HEIGHT, currentMaxSizeRect.height());
return maxSize.toString();
}
}
catch (Exception e) {
LogUtil.error(TAG, "Failed getMaxSize() for MRAID: " + Log.getStackTraceString(e));
Expand Down Expand Up @@ -171,10 +175,12 @@ public String getDefaultPosition() {
public String getCurrentPosition() {
JSONObject position = new JSONObject();
Rect rect = new Rect();

adBaseView.getGlobalVisibleRect(rect);

Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable mainThreadRunnable = () -> adBaseView.getGlobalVisibleRect(rect);
RunnableFuture<Void> task = new FutureTask<>(mainThreadRunnable, null);
try {
mainHandler.post(task);
task.get();
position.put(JSON_X, (int) (rect.left / Utils.DENSITY));
position.put(JSON_Y, (int) (rect.top / Utils.DENSITY));
position.put(JSON_WIDTH, (int) (rect.right / Utils.DENSITY - rect.left / Utils.DENSITY));
Expand Down