Skip to content

Commit

Permalink
Merge pull request #775 from shinwan2/fix/banner-adsize
Browse files Browse the repository at this point in the history
fix: Set video dimensions based on banner configuration if not set
  • Loading branch information
jsligh authored Jun 25, 2024
2 parents 45e2f28 + 37ea4c7 commit e02e455
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import android.text.TextUtils;
import android.util.Pair;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import org.json.JSONArray;
import org.json.JSONObject;
import org.prebid.mobile.AdSize;
Expand Down Expand Up @@ -301,27 +304,32 @@ private void setVideoImpValues(Imp imp) {
}
}

setVideoDimensions(video);
video.delivery = new int[]{VIDEO_DELIVERY_DOWNLOAD};

imp.video = video;
}

private void setVideoDimensions(@NonNull Video video) {
VideoParameters videoParams = adConfiguration.getVideoParameters();
if (videoParams != null) {
AdSize adSize = videoParams.getAdSize();
if (adSize != null) {
video.w = adSize.getWidth();
video.h = adSize.getHeight();
}
@Nullable AdSize adSize = null;
if (videoParams != null && videoParams.getAdSize() != null) {
adSize = videoParams.getAdSize();
} else if (!adConfiguration.getSizes().isEmpty()) {
for (AdSize size : adConfiguration.getSizes()) {
video.w = size.getWidth();
video.h = size.getHeight();
adSize = size;
break;
}
}

if (adSize != null) {
video.w = adSize.getWidth();
video.h = adSize.getHeight();
} else if (resources != null) {
Configuration deviceConfiguration = resources.getConfiguration();
video.w = deviceConfiguration.screenWidthDp;
video.h = deviceConfiguration.screenHeightDp;
}
video.delivery = new int[]{VIDEO_DELIVERY_DOWNLOAD};

imp.video = video;
}

private void setBannerImpValues(Imp imp) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.prebid.mobile.AdSize;
import org.prebid.mobile.BannerAdUnit;
import org.prebid.mobile.BannerParameters;
import org.prebid.mobile.DataObject;
import org.prebid.mobile.ExternalUserId;
Expand Down Expand Up @@ -136,6 +137,30 @@ public void cleanup() throws Exception {
PrebidMobile.unregisterPluginRenderer(otherPlugin);
}

@Test
public void banner_videoDimensionsNotSet_allImpsHaveDimensions() throws JSONException {
final BannerAdUnit adUnit = new BannerAdUnit(
"unitId",
300,
250,
EnumSet.of(AdUnitFormat.BANNER, AdUnitFormat.VIDEO)
);
final VideoParameters videoParameters = new VideoParameters(Lists.newArrayList("video/mp4"));
adUnit.setVideoParameters(videoParameters);

final BidRequest bidRequest = configIntoBidRequest(adUnit.getConfiguration());

Imp imp = bidRequest.getImp().get(0);
assertNotNull(imp);
Banner banner = imp.banner;
assertNotNull(banner);
assertEquals("{\"format\":[{\"w\":300,\"h\":250}]}", banner.getJsonObject().toString());

Video video = imp.video;
assertNotNull(video);
assertEquals("{\"delivery\":[3],\"w\":300,\"h\":250,\"mimes\":[\"video\\/mp4\"]}", video.getJsonObject().toString());
}

@Test
public void multiformat_setAllParameterTypes_allTypesInRequestObject() throws JSONException {
AdUnitConfiguration config = new AdUnitConfiguration();
Expand Down

0 comments on commit e02e455

Please sign in to comment.