Skip to content

Commit

Permalink
Pull request #714: Release branch v8.7
Browse files Browse the repository at this point in the history
Merge in MOBILE-SDK/app_mobile-sdk-android from release_branch_v8.7 to master

* commit '1997a2fa5b209a52ea95bd40a7a02361864433e0':
  release version 8.7
  Pull request #712: PR comments fix
  update mvp.js
  Added unit tests
  Move logic from AdWebview to BannerAdView
  Reverted SimpleBanner changes
  Changes for video orientation
  Pull request #710: Retrieve AAID only if permitted
  Added log message
  Added inline comment
  Added debug logs for onAdResponseReceived
  updated test cases
  fix_recyclerview_scrolling_issue
  • Loading branch information
Ritesh Zaveri committed Jul 6, 2023
2 parents 334c821 + 1997a2f commit 5a3f691
Show file tree
Hide file tree
Showing 18 changed files with 277 additions and 33 deletions.
9 changes: 9 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 8.7

### New Features
+ MS-5206 Added support for setting player size and getting video creative width and height for BannerVideo. New API introduced in BannerAdView setPortraitBannerVideoPlayerSize(AdSize), setLandscapeBannerVideoPlayerSize(AdSize), setSquareBannerVideoPlayerSize(AdSize), getBannerVideoCreativeWidth(), getBannerVideoCreativeHeight()

### Improvement/Bug Fixes
+ MS-5295 Fixed ad rendering issue on scrolling/recyclerview
+ MS-5332 Update to AAID fetch logic

## 8.6.1

### Improvement/Bug Fixes
Expand Down
4 changes: 2 additions & 2 deletions instreamvideo/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Project Properties
version = "1.45" // Instream SDK version
version = "1.46" // Instream SDK version

apply plugin: 'com.android.library'

Expand All @@ -10,7 +10,7 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 32
versionCode 44 // An integer value that represents the version of the code, relative to other versions. Increase for each release.
versionCode 45 // An integer value that represents the version of the code, relative to other versions. Increase for each release.
versionName version
consumerProguardFiles 'proguard-project.txt'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,11 @@ public void onAdClicked(String clickUrl) {
public void onAdImpression() {
Clog.d(Clog.videoLogTag, "onAdImpression");
}

@Override
public void onAdResponseReceived() {
Clog.d(Clog.videoLogTag, "onAdResponseReceived");
}
}

public void activityOnDestroy() {
Expand Down
6 changes: 3 additions & 3 deletions sdk/assets/mobilevastplayer.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions sdk/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Project properties
version = "8.6.1"
version = "8.7"
group='com.appnexus.opensdk'

// Android build
Expand All @@ -10,7 +10,7 @@ android {
buildToolsVersion '32.0.0'

defaultConfig {
versionCode 103 // An integer value that represents the version of the code, relative to other versions. Increase for each release.
versionCode 104 // An integer value that represents the version of the code, relative to other versions. Increase for each release.
versionName version
consumerProguardFiles 'proguard-project.txt'
minSdkVersion 14
Expand Down
9 changes: 9 additions & 0 deletions sdk/src/com/appnexus/opensdk/AdFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,15 @@ synchronized public void handleMessage(Message msg) {
Clog.e(Clog.lazyLoadLogTag, "Lazy Load Fetching");
((AdView)fetcher.owner).deactivateWebviewForNextCall();
}

// Checks if the AdResponseReceived is enabled (isAdResponseReceived - boolean in the AdView)
if (fetcher.owner != null && fetcher.owner instanceof AdView) {
if(((AdView)fetcher.owner).isAdResponseReceived) {
((AdView)fetcher.owner).isAdResponseReceived = false;
Clog.d(Clog.baseLogTag, "Resetting isAdResponseReceived for Banner / Interstitial");
}
}

fetcher.lastFetchTime = System.currentTimeMillis();

// Spawn an AdRequest
Expand Down
11 changes: 11 additions & 0 deletions sdk/src/com/appnexus/opensdk/AdView.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ public abstract class AdView extends FrameLayout implements Ad, MultiAd, Visibil
// Client suggested change for memory leak in VisibilityDetector
private boolean isDestroyed = false;

/**
* This variable keeps track if the AdRequest has been completed and the AdResponse is received or not
* This does not ascertain that the received response is valid or not
*/
protected boolean isAdResponseReceived = false;

/**
* Begin Construction
Expand Down Expand Up @@ -1181,6 +1186,12 @@ public void run() {
});
}

@Override
public void onAdResponseReceived() {
Clog.d(Clog.baseLogTag, "onAdResponseReceived");
isAdResponseReceived = true;
}

private void handleNativeAd(AdResponse ad) {
setAdType(AdType.NATIVE);

Expand Down
4 changes: 4 additions & 0 deletions sdk/src/com/appnexus/opensdk/AdViewRequestManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ public void onReceiveAd(AdResponse ad) {
public void onReceiveUTResponse(UTAdResponse response) {
super.onReceiveUTResponse(response);
Clog.d(Clog.baseLogTag, "onReceiveUTResponse");
Ad ownerAd = owner.get();
if(ownerAd != null && ownerAd.getAdDispatcher() != null) {
ownerAd.getAdDispatcher().onAdResponseReceived();
}
processUTResponse(response);
}

Expand Down
30 changes: 30 additions & 0 deletions sdk/src/com/appnexus/opensdk/AdWebView.java
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,36 @@ boolean getUserInteraction() {
return userInteracted;
}

public void resizeWebViewBasedOnVideoOrientation() {
//Resize only for BannerVideo
if (adView == null || !(adView instanceof BannerAdView)) {
return;
}
AdSize videoPlayerSize = ((BannerAdView) adView).getBannerVideoPlayerSize();

final float scale = adView.getContext().getResources()
.getDisplayMetrics().density;

int rheight, rwidth;

//Resize only if publisher app has set a value greater than 1x1 other wise by default BannerVideo is sized to the primary adSize
if (videoPlayerSize.height() > 1 && videoPlayerSize.width() > 1) {
adResponseData.setHeight(videoPlayerSize.height());
adResponseData.setWidth(videoPlayerSize.width());

setCreativeHeight(videoPlayerSize.height());
setCreativeWidth(videoPlayerSize.width());

rheight = (int) (videoPlayerSize.height() * scale + 0.5f);
rwidth = (int) (videoPlayerSize.width() * scale + 0.5f);
AdView.LayoutParams resize = new AdView.LayoutParams(rwidth, rheight,
Gravity.CENTER);
this.setLayoutParams(resize);
this.requestLayout();
}

}

/**
* AdWebViewClient for the webview
*/
Expand Down
102 changes: 100 additions & 2 deletions sdk/src/com/appnexus/opensdk/BannerAdView.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Point;
import android.os.Build;
import android.util.AttributeSet;
import android.view.Display;
import android.view.Gravity;
Expand Down Expand Up @@ -104,6 +103,14 @@ public class BannerAdView extends AdView implements ScreenEventListener {
private Animator animator;
private boolean autoRefreshOffInXML;
private VideoOrientation videoOrientation = UNKNOWN;
private int bannerVideoCreativeWidth;
private int bannerVideoCreativeHeight;

private AdSize landscapeBannerVideoPlayerSize = new AdSize(1,1);

private AdSize portraitBannerVideoPlayerSize = new AdSize(1,1);

private AdSize squareBannerVideoPlayerSize = new AdSize(1,1);

private void setDefaultsBeforeXML() {
loadAdHasBeenCalled = false;
Expand Down Expand Up @@ -906,7 +913,8 @@ protected void onWindowVisibilityChanged(int visibility) {
//The only time we want to request on visibility changes is if an ad hasn't been loaded yet (loadAdHasBeenCalled)
// shouldReloadOnResume is true
// OR auto_refresh is enabled
if (loadAdHasBeenCalled && (shouldReloadOnResume || (period > 0))) {
// OR isAdResponseReceived is false
if (loadAdHasBeenCalled && (shouldReloadOnResume || (period > 0) || !isAdResponseReceived)) {

//If we're MRAID mraid_is_closing or expanding, don't load.
if (!mraid_is_closing && !mraid_changing_size_or_visibility
Expand Down Expand Up @@ -1326,4 +1334,94 @@ public boolean loadLazyAd() {
return super.loadLazyAd();
}

/**
* Get the Creative Width of the Banner Video
*/
public int getBannerVideoCreativeWidth() {
return bannerVideoCreativeWidth;
}

/**
* Set the Creative Width of the Banner Video
*/
void setBannerVideoCreativeWidth(int bannerVideoCreativeWidth) {
this.bannerVideoCreativeWidth = bannerVideoCreativeWidth;
}

/**
* Get the Creative Height of the Banner Video
*/
public int getBannerVideoCreativeHeight() {
return bannerVideoCreativeHeight;
}

/**
* Set the Creative Height of the Banner Video
*/
void setBannerVideoCreativeHeight(int bannerVideoCreativeHeight) {
this.bannerVideoCreativeHeight = bannerVideoCreativeHeight;
}

/**
* Get Player Size for Landscape Banner Video
*/
public AdSize getLandscapeBannerVideoPlayerSize() {
return landscapeBannerVideoPlayerSize;
}

/**
* Set Player Size for Landscape Banner Video
*/
public void setLandscapeBannerVideoPlayerSize(AdSize landscapeBannerVideoPlayerSize) {
this.landscapeBannerVideoPlayerSize = landscapeBannerVideoPlayerSize;
}

/**
* Get Player Size for Portrait Banner Video
*/
public AdSize getPortraitBannerVideoPlayerSize() {
return portraitBannerVideoPlayerSize;
}

/**
* Set Player Size for Portrait Banner Video
*/
public void setPortraitBannerVideoPlayerSize(AdSize portraitBannerVideoPlayerSize) {
this.portraitBannerVideoPlayerSize = portraitBannerVideoPlayerSize;
}

/**
* Get Player Size for Landscape Square Video
*/
public AdSize getSquareBannerVideoPlayerSize() {
return squareBannerVideoPlayerSize;
}

/**
* Set Player Size for Landscape Square Video
*/
public void setSquareBannerVideoPlayerSize(AdSize squareBannerVideoPlayerSize) {
this.squareBannerVideoPlayerSize = squareBannerVideoPlayerSize;
}

//Internal API to be used by AdWebview to determine its size for resizing based on VideoOrientation
protected AdSize getBannerVideoPlayerSize(){
AdSize videoPlayerSize;

switch (videoOrientation){
case PORTRAIT:
videoPlayerSize = getPortraitBannerVideoPlayerSize();
break;
case SQUARE:
videoPlayerSize = getSquareBannerVideoPlayerSize();
break;
default:
// Use Landscape size by default for Landscape and Unknown,
videoPlayerSize = getLandscapeBannerVideoPlayerSize();

}
return videoPlayerSize;
}


}
6 changes: 6 additions & 0 deletions sdk/src/com/appnexus/opensdk/BaseAdDispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,10 @@ public interface BaseAdDispatcher {
* Called on ad impression
*/
public void onAdImpression();

/**
* Called when an ad request is completed
* and successful ad response is received
*/
public void onAdResponseReceived();
}
5 changes: 5 additions & 0 deletions sdk/src/com/appnexus/opensdk/NativeAdRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,11 @@ public void onAdClicked(String clickUrl) {
public void onAdImpression() {
Clog.d(Clog.nativeLogTag, "onAdImpression");
}

@Override
public void onAdResponseReceived() {
Clog.d(Clog.nativeLogTag, "onAdResponseReceived");
}
}

@Override
Expand Down
16 changes: 15 additions & 1 deletion sdk/src/com/appnexus/opensdk/VideoImplementation.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ protected void dispatchNativeCallback(String url) {
if (paramsDictionary.has("aspectRatio")) {
processAspectRatio(paramsDictionary.getString("aspectRatio"));
}
if (paramsDictionary.has("width") &&
paramsDictionary.has("height")) {

try {
((BannerAdView) adWebView.adView).setBannerVideoCreativeWidth(Integer.parseInt(paramsDictionary.getString("width")));
((BannerAdView) adWebView.adView).setBannerVideoCreativeHeight(Integer.parseInt(paramsDictionary.getString("height")));
} catch (NumberFormatException nfe) {
Clog.d(Clog.videoLogTag, "Could not parse int value" + nfe);
}

}
adWebView.success();
adReady = true;
} else if (eventName.equals("videoStart")) {
Expand All @@ -84,7 +95,10 @@ protected void dispatchNativeCallback(String url) {

private void processAspectRatio(String fetchedAspectRatio) {
if(adWebView.adView instanceof BannerAdView) {
((BannerAdView)adWebView.adView).setVideoOrientation(ViewUtil.getVideoOrientation(fetchedAspectRatio));
VideoOrientation orientation = ViewUtil.getVideoOrientation(fetchedAspectRatio);
((BannerAdView)adWebView.adView).setVideoOrientation(orientation);
adWebView.resizeWebViewBasedOnVideoOrientation();

}
}

Expand Down
41 changes: 21 additions & 20 deletions sdk/src/com/appnexus/opensdk/utils/AdvertisingIDUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,31 @@ private static Pair<String, Boolean> getAAID(Context context) {
Boolean limited = false;

// attempt to retrieve AAID from GooglePlayServices via reflection
if (Settings.getSettings().deviceAccessAllowed && !SDKSettings.isAAIDUsageDisabled() && !Settings.getSettings().doNotTrack) {
try {
if (context != null) {
// NPE catches null objects
Class<?> cInfo = Class.forName(cAdvertisingIdClientInfoName);
Class<?> cClient = Class.forName(cAdvertisingIdClientName);

try {
if (context != null) {
// NPE catches null objects
Class<?> cInfo = Class.forName(cAdvertisingIdClientInfoName);
Class<?> cClient = Class.forName(cAdvertisingIdClientName);

Method mGetAdvertisingIdInfo = cClient.getMethod("getAdvertisingIdInfo", Context.class);
Method mGetId = cInfo.getMethod("getId");
Method mIsLimitAdTrackingEnabled = cInfo.getMethod("isLimitAdTrackingEnabled");
Method mGetAdvertisingIdInfo = cClient.getMethod("getAdvertisingIdInfo", Context.class);
Method mGetId = cInfo.getMethod("getId");
Method mIsLimitAdTrackingEnabled = cInfo.getMethod("isLimitAdTrackingEnabled");

Object adInfoObject = cInfo.cast(mGetAdvertisingIdInfo.invoke(null, context));
Object adInfoObject = cInfo.cast(mGetAdvertisingIdInfo.invoke(null, context));

aaid = (String) mGetId.invoke(adInfoObject);
limited = (Boolean) mIsLimitAdTrackingEnabled.invoke(adInfoObject);
aaid = (String) mGetId.invoke(adInfoObject);
limited = (Boolean) mIsLimitAdTrackingEnabled.invoke(adInfoObject);
}
} catch (ClassNotFoundException ignored) {
} catch (InvocationTargetException ignored) {
} catch (NoSuchMethodException ignored) {
} catch (IllegalAccessException ignored) {
} catch (ClassCastException ignored) {
} catch (NullPointerException ignored) {
} catch (Exception ignored) {
// catches GooglePlayServicesRepairableException, GooglePlayServicesNotAvailableException
}
} catch (ClassNotFoundException ignored) {
} catch (InvocationTargetException ignored) {
} catch (NoSuchMethodException ignored) {
} catch (IllegalAccessException ignored) {
} catch (ClassCastException ignored) {
} catch (NullPointerException ignored) {
} catch (Exception ignored) {
// catches GooglePlayServicesRepairableException, GooglePlayServicesNotAvailableException
}

// set or clear the AAID depending on success/failure
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/com/appnexus/opensdk/utils/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public enum ImpressionType {
public boolean debug_mode = false; // This should always be false here.
public String ua = null;

public final String sdkVersion = "8.6.1";
public final String sdkVersion = "8.7";
// BuildConfig.VERSION_NAME;


Expand Down
5 changes: 5 additions & 0 deletions sdk/test/com/appnexus/opensdk/MRAIDImplementationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -424,5 +424,10 @@ public void onAdClicked(String clickUrl) {
public void onAdImpression() {
adImpression = true;
}

@Override
public void onAdResponseReceived() {

}
}
}
Loading

0 comments on commit 5a3f691

Please sign in to comment.