Skip to content

Commit

Permalink
Merge pull request #367 in MOBILE-SDK/app_mobile-sdk-android from ANA…
Browse files Browse the repository at this point in the history
…dResponseInfo_Implementation to develop

Squashed commit of the following:

commit 90524f530ac20305abfc087b393633528909228d
Author: Abhas Vohra <[email protected]>
Date:   Sat Feb 29 01:18:45 2020 +0530

    Handled NO BID case for VideoAd

commit ce17bbe7090ce9417d5d0b77852c2314aca3272c
Author: Abhas Vohra <[email protected]>
Date:   Sat Feb 29 01:17:53 2020 +0530

    Handled NO BID case

commit f11f486598888388007a06f37d43323e7f9afd74
Author: Abhas Vohra <[email protected]>
Date:   Sat Feb 29 01:03:14 2020 +0530

    Removed AdResponseInfo APIs from BaseAdDispatcher and consequent uses

commit 13636e5250b5682185ddb7e665f79f94d9b440e8
Author: Abhas Vohra <[email protected]>
Date:   Fri Feb 28 21:58:25 2020 +0530

    Updated Sample Apps

commit d58805f9ea279db889dd06b8a5a14fedac52da39
Author: Abhas Vohra <[email protected]>
Date:   Fri Feb 28 20:56:14 2020 +0530

    Moved the common implementation to the BaseNativeAdResponse

commit 099318021b00a572fdd65f05485a1f46ecaf53f1
Author: Abhas Vohra <[email protected]>
Date:   Fri Feb 28 20:45:41 2020 +0530

    Overridden AdResponseInfo methods in the BaseNativeAdResponse

commit a071eb84cd32a9502cc1f64477abd899f5c6e1ea
Author: Abhas Vohra <[email protected]>
Date:   Fri Feb 28 20:17:39 2020 +0530

    Fixed Unit Tests

commit 4ee0d449de4918c54e6beb7a4e5ba2e8a5d38d9c
Author: Abhas Vohra <[email protected]>
Date:   Fri Feb 28 19:24:19 2020 +0530

    Fixed broken CSR Unit Tests

commit 3fdae39579e05fbfd8627f8a849b27c7034836f5
Merge: f1d92a2 7f7c349
Author: Abhas Vohra <[email protected]>
Date:   Fri Feb 28 14:16:04 2020 +0530

    Merge with develop

commit f1d92a29c682af12af3ddae5fade972dfaa5e950
Author: Abhas Vohra <[email protected]>
Date:   Fri Feb 28 14:09:26 2020 +0530

    Removed ANAdResponseInfo form AdListener's and VideoAdListener's onAdRequestFailed, set the AdResponse to the AdUnit (except Native)

commit afca02e0320be2f2a13cc730d95c64db3ad8a8ed
Merge: 19bb156 1e51ae1
Author: Abhas Vohra <[email protected]>
Date:   Thu Feb 27 15:27:08 2020 +0530

    Merge: latest develop

commit 19bb156ff444cbf87847a8904bda9f003f1711b1
Author: Abhas Vohra <[email protected]>
Date:   Thu Feb 27 00:08:26 2020 +0530

    PR comments

commit 8a9b7084d1ac0de656d21e36b7256fba46d1c3d9
Author: Abhas Vohra <[email protected]>
Date:   Mon Feb 24 20:56:27 2020 +0530

    BannerAdView returns null for Banner Native AdResponseInfo, fixed Unit tests, Added Unit tests

commit ee6823011f172932c9e967639cf2dfd197c65c19
Author: Abhas Vohra <[email protected]>
Date:   Thu Feb 20 20:44:24 2020 +0530

    Refined Unit Test

commit 2e5043d3f378aecf47b5f399b8d4031ef722b977
Author: Abhas Vohra <[email protected]>
Date:   Thu Feb 20 18:09:51 2020 +0530

    Changed the Native Ad implementation as per iOS

commit d2d05469fbf2adb0a15d2e0b5eca7cba9d6ff46a
Author: Abhas Vohra <[email protected]>
Date:   Thu Feb 20 03:18:04 2020 +0530

    Updated as per the comments

commit 820bb8796c75e8d6bb0fc734e6686dc96a634f09
Author: Abhas Vohra <[email protected]>
Date:   Wed Feb 19 22:27:43 2020 +0530

    Added public facing APIs for getting the Member Id and Publisher Id

commit 132698450bbef7a0958291288a13efa21dc3c4d4
Author: Abhas Vohra <[email protected]>
Date:   Wed Feb 19 21:29:27 2020 +0530

    Code Refactor

commit 7eef54b6b5068cdc6619cccfb5ce2d9a837e977f
Merge: bd33061 eaacc30
Author: Abhas Vohra <[email protected]>
Date:   Wed Feb 19 21:18:56 2020 +0530

    Merged Publisher ID changes

commit eaacc30798d06213396cc10df85683641784da63
Author: Abhas Vohra <[email protected]>
Date:   Wed Feb 19 19:55:00 2020 +0530

    Added Publisher ID to the UTRequest Parameters, Added Unit Tests

... and 5 more commits
  • Loading branch information
Kowshickkarthick Subramanian committed Feb 28, 2020
1 parent 7f7c349 commit 1c62f24
Show file tree
Hide file tree
Showing 66 changed files with 1,264 additions and 181 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.os.Handler;
import android.widget.RelativeLayout;

import com.appnexus.opensdk.ANAdResponseInfo;
import com.appnexus.opensdk.ANClickThroughAction;
import com.appnexus.opensdk.AdListener;
import com.appnexus.opensdk.AdView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import androidx.test.espresso.idling.CountingIdlingResource;

import com.appnexus.opensdk.ANAdResponseInfo;
import com.appnexus.opensdk.ANClickThroughAction;
import com.appnexus.opensdk.ANMultiAdRequest;
import com.appnexus.opensdk.AdListener;
Expand Down Expand Up @@ -164,7 +165,7 @@ public void onAdClicked(AdView adView, String clickUrl) {
// adUnitList.add(adRequest);
// adUnitList.add(videoAd);

anMultiAdRequest2 = new ANMultiAdRequest(this, 0, new MultiAdRequestListener() {
anMultiAdRequest2 = new ANMultiAdRequest(this, 0, 0, new MultiAdRequestListener() {
@Override
public void onMultiAdRequestCompleted() {
msg += "MAR 2 Load Completed";
Expand All @@ -188,7 +189,7 @@ public void onMultiAdRequestFailed(ResultCode code) {
// anMultiAdRequest2.load();


anMultiAdRequest = new ANMultiAdRequest(this, 0,
anMultiAdRequest = new ANMultiAdRequest(this, 0, 0,
new MultiAdRequestListener() {
@Override
public void onMultiAdRequestCompleted() {
Expand All @@ -208,14 +209,14 @@ public void onMultiAdRequestFailed(ResultCode code) {
});
anMultiAdRequest.addAdUnit(bav);
anMultiAdRequest.addAdUnit(iav);
// anMultiAdRequest.addAdUnit(adRequest);
// anMultiAdRequest.addAdUnit(videoAd);
anMultiAdRequest.addAdUnit(adRequest);
anMultiAdRequest.addAdUnit(videoAd);
// anMultiAdRequest.addAdUnit(setupVideoAd());
// bav = null;
// System.gc();
// iav = null;
// adRequest = null;
// load();
load();
// bav.loadAd();

tv.setOnClickListener(new View.OnClickListener() {
Expand Down Expand Up @@ -293,7 +294,7 @@ public void onAdLoaded(NativeAdResponse response) {
}

@Override
public void onAdFailed(ResultCode errorcode) {
public void onAdFailed(ResultCode errorcode, ANAdResponseInfo adResponseInfo) {
msg += "Native Ad Failed:" + errorcode + "\n";
toast();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import android.widget.Toast;
import android.widget.VideoView;

import com.appnexus.opensdk.ANAdResponseInfo;
import com.appnexus.opensdk.ResultCode;
import com.appnexus.opensdk.SDKSettings;
import com.appnexus.opensdk.instreamvideo.ResultCallback;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class NativeActivity : AppCompatActivity(),NativeAdRequestListener,NativeAdEvent
NativeAdSDK.registerTracking(nativeAdResponse, nativeContainer, mutableListOf(clickThrough) as List<View>?,this)
}

override fun onAdFailed(errorcode: ResultCode) {
override fun onAdFailed(errorcode: ResultCode, adResponseinfo:ANAdResponseInfo) {
log("Native Ad Failed: " + errorcode.name)
}
// NativeAdRequestListener - End
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.util.Log
import android.view.View
import android.widget.*
import androidx.appcompat.app.AppCompatActivity
import com.appnexus.opensdk.ANAdResponseInfo
import com.appnexus.opensdk.ResultCode
import com.appnexus.opensdk.instreamvideo.*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,6 @@ public int getVideoAdDuration () {
return 0;
}



public String getCreativeId () {
if(this.videoWebView != null){
return this.videoWebView.getCreativeId();
}
return "";
}

public String getVastXML () {
if(this.videoWebView != null){
return this.videoWebView.getVastXML();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@


import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.Pair;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;

import com.appnexus.opensdk.ANAdResponseInfo;
import com.appnexus.opensdk.ANClickThroughAction;
import com.appnexus.opensdk.ANMultiAdRequest;
import com.appnexus.opensdk.Ad;
Expand All @@ -30,8 +29,8 @@
import com.appnexus.opensdk.AdType;
import com.appnexus.opensdk.AdView;
import com.appnexus.opensdk.AdViewRequestManager;
import com.appnexus.opensdk.MultiAd;
import com.appnexus.opensdk.MediaType;
import com.appnexus.opensdk.MultiAd;
import com.appnexus.opensdk.ResultCode;
import com.appnexus.opensdk.VideoOrientation;
import com.appnexus.opensdk.ut.UTAdRequester;
Expand Down Expand Up @@ -61,6 +60,7 @@ public class VideoAd implements Ad, MultiAd {
private InstreamVideoView videoAdView;
boolean doesLoadingInBackground = true;
private boolean showLoadingIndicator = true;
private ANAdResponseInfo adResponseInfo;

public VideoAd(Context context, String placementID) {
weakContext = new WeakReference<Context>(context);
Expand Down Expand Up @@ -177,6 +177,24 @@ public int getMemberID() {
return requestParameters.getMemberID();
}

/**
* Retrieve the Publisher ID.
*
* @return the Publisher id that this NativeAdRequest belongs to.
*/
public int getPublisherId() {
return requestParameters.getPublisherId();
}

/**
* Retrieve the Publisher ID.
*
* @@param publisherId the Publisher id that this NativeAdRequest belongs to.
*/
public void setPublisherId(int publisherId) {
requestParameters.setPublisherId(publisherId);
}

/**
* Retrieve the inventory code.
*
Expand Down Expand Up @@ -399,7 +417,7 @@ public boolean loadAd() {
protected void loadAdFromVAST(String VASTXML,int width,int height) {
// load an ad directly from VASTXML
VideoWebView output = new VideoWebView(this.getContext(),this, null);
RTBVASTAdResponse response = new RTBVASTAdResponse(width,height, AdType.VIDEO.toString(), null,null,"1");
RTBVASTAdResponse response = new RTBVASTAdResponse(width,height, AdType.VIDEO.toString(), null,null, getAdResponseInfo());
response.setAdContent(VASTXML);
response.setContentSource(UTConstants.RTB);
response.addToExtras(UTConstants.EXTRAS_KEY_MRAID, true);
Expand Down Expand Up @@ -498,9 +516,10 @@ public void onAdLoaded() {
}

@Override
public void onAdFailed(ResultCode errorCode) {
public void onAdFailed(ResultCode errorCode, ANAdResponseInfo adResponseInfo) {
isLoading = false;
validAdExists = false;
setAdResponseInfo(adResponseInfo);
if (adLoadListener != null) {
adLoadListener.onAdRequestFailed(VideoAd.this, errorCode);
}
Expand Down Expand Up @@ -730,15 +749,16 @@ public int getVideoAdDuration() {
return 0;
}

@Deprecated
/**
* Retrieve the Creative Id of the creative .
*
* @return the creativeId
* @deprecated use ({@link ANAdResponseInfo}.getCreativeId)
*/

public String getCreativeId() {
if (videoAdView != null) {
return videoAdView.getCreativeId();
if (getAdResponseInfo() != null) {
return getAdResponseInfo().getCreativeId();
}
return "";
}
Expand Down Expand Up @@ -778,6 +798,7 @@ public void getAdPlayElapsedTime(ResultCallback resultCallback) {
@Override
public void initiateVastAdView(BaseAdResponse response, AdViewRequestManager adViewRequestManager) {
Clog.d(Clog.videoLogTag, "Creating WebView for::" + response.getContentSource());
setAdResponseInfo(response.getAdResponseInfo());
VideoWebView adVideoView = new VideoWebView(getContext(), this, adViewRequestManager);
getVideoAdView().setVideoWebView(adVideoView);
adVideoView.loadAd(response);
Expand All @@ -792,4 +813,13 @@ public void setRequestManager(UTAdRequester requester) {
public MultiAd getMultiAd() {
return this;
}

public ANAdResponseInfo getAdResponseInfo() {
return adResponseInfo;
}

private void setAdResponseInfo(ANAdResponseInfo adResponseInfo) {
this.adResponseInfo = adResponseInfo;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
*/
package com.appnexus.opensdk.instreamvideo;

import com.appnexus.opensdk.ANClickThroughAction;
import com.appnexus.opensdk.BaseAdDispatcher;
import com.appnexus.opensdk.ResultCode;

/**
* This interface is used by internal classes of SDK to send callbacks to the VideoAd class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public interface VideoAdLoadListener {
/**
* Called when an ad request has failed. Ad requests can fail
* because no ad is available, or because of networking errors.
*
* @param videoAd The {@link VideoAd} that loaded the ad.
* @param videoAd The {@link VideoAd} that loaded the ad.
* @param errorCode the ResultCode describing the failure.
*/
public void onAdRequestFailed(VideoAd videoAd, ResultCode errorCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ class VideoWebView extends WebView {
private static final int WAIT_INTERVAL_MILLES = 300;

private int adDuration = 0;
private String creativeId = "";
private String creativeUrl = "";
private String vastURLContent = "";
private String vastXMLContent = "";
Expand Down Expand Up @@ -530,7 +529,6 @@ protected void loadAd(BaseAdResponse baseAdResponse) {
return;
}
this.baseAdResponse = baseAdResponse;
this.creativeId = baseAdResponse.getCreativeId();
this.loadUrl(Settings.getVideoHtmlPage());
}

Expand All @@ -554,11 +552,6 @@ protected VideoOrientation getVideoOrientation() {
return ViewUtil.getVideoOrientation(aspectRatio);
}

protected String getCreativeId() {
return this.creativeId;
}


private class RedirectWebView extends WebView {

@SuppressLint("SetJavaScriptEnabled")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* Copyright 2018 APPNEXUS INC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.appnexus.opensdk.instreamvideo;

import com.appnexus.opensdk.ANAdResponseInfo;
import com.appnexus.opensdk.AdType;
import com.appnexus.opensdk.ResultCode;
import com.appnexus.opensdk.instreamvideo.shadows.ShadowAsyncTaskNoExecutor;
import com.appnexus.opensdk.instreamvideo.shadows.ShadowCustomWebView;
import com.appnexus.opensdk.instreamvideo.shadows.ShadowSettings;
import com.appnexus.opensdk.instreamvideo.shadows.ShadowWebSettings;
import com.appnexus.opensdk.ut.UTConstants;
import com.squareup.okhttp.mockwebserver.MockResponse;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowLog;

import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

@Config(sdk = 21,
shadows = {ShadowAsyncTaskNoExecutor.class,
ShadowCustomWebView.class, ShadowWebSettings.class, ShadowSettings.class, ShadowLog.class})
@RunWith(RobolectricTestRunner.class)
public class ANAdResponseInfoVideoTests extends BaseRoboTest implements VideoAdLoadListener {

VideoAd videoAd;
ANAdResponseInfo adResponseInfo;

@Override
public void setup() {
super.setup();
videoAd = new VideoAd(activity,"12345");
videoAd.setAdLoadListener(this);
}

@Override
public void tearDown() {
super.tearDown();
videoAd = null;
adResponseInfo = null;
}

@Test
public void testAdResponseInfoRTBVideo() {
server.enqueue(new MockResponse().setResponseCode(200).setBody(TestUTResponses.video())); // First queue a regular HTML banner response
assertNull(videoAd.getAdResponseInfo());
executeVideoRequest();
assertNotNull(videoAd.getAdResponseInfo());
assertEquals(videoAd.getAdResponseInfo().getAdType(), AdType.VIDEO);
assertEquals(videoAd.getAdResponseInfo().getCreativeId(), "6332753");
assertEquals(videoAd.getAdResponseInfo().getTagId(), "123456");
assertEquals(videoAd.getAdResponseInfo().getBuyMemberId(), 123);
assertEquals(videoAd.getAdResponseInfo().getContentSource(), UTConstants.RTB);
assertEquals(videoAd.getAdResponseInfo().getNetworkName(), "");
}

@Test
public void testAdResponseInfoRTBVideoNoBid() {
server.enqueue(new MockResponse().setResponseCode(200).setBody(TestUTResponses.NO_BID));
assertNull(videoAd.getAdResponseInfo());
executeVideoRequest();
assertNotNull(videoAd.getAdResponseInfo());
assertEquals(videoAd.getAdResponseInfo().getAdType(), null);
assertEquals(videoAd.getAdResponseInfo().getCreativeId(), "");
assertEquals(videoAd.getAdResponseInfo().getTagId(), "123456789");
assertEquals(videoAd.getAdResponseInfo().getBuyMemberId(), 0);
assertEquals(videoAd.getAdResponseInfo().getContentSource(), "");
assertEquals(videoAd.getAdResponseInfo().getNetworkName(), "");
}

@Test
public void testAdResponseInfoRTBVideoBlank() {
server.enqueue(new MockResponse().setResponseCode(200).setBody(TestUTResponses.blank()));
assertNull(videoAd.getAdResponseInfo());
executeVideoRequest();
assertNull(videoAd.getAdResponseInfo());
}

private void executeVideoRequest() {
videoAd.loadAd();

waitForTasks();
Robolectric.flushBackgroundThreadScheduler();
Robolectric.flushForegroundThreadScheduler();

waitForTasks();
Robolectric.flushBackgroundThreadScheduler();
Robolectric.flushForegroundThreadScheduler();
}

@Override
public void onAdLoaded(VideoAd videoAd) {

}

@Override
public void onAdRequestFailed(VideoAd videoAd, ResultCode errorCode) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.Activity;


import com.appnexus.opensdk.ANAdResponseInfo;
import com.appnexus.opensdk.instreamvideo.shadows.ShadowSettings;
import com.appnexus.opensdk.instreamvideo.util.Lock;
import com.appnexus.opensdk.ut.UTConstants;
Expand Down
Loading

0 comments on commit 1c62f24

Please sign in to comment.