diff --git a/examples/java/SimpleVideo/app/src/main/java/com/appnexus/example/simplevideo/MainActivity.java b/examples/java/SimpleVideo/app/src/main/java/com/appnexus/example/simplevideo/MainActivity.java index 05689f03..c897b466 100644 --- a/examples/java/SimpleVideo/app/src/main/java/com/appnexus/example/simplevideo/MainActivity.java +++ b/examples/java/SimpleVideo/app/src/main/java/com/appnexus/example/simplevideo/MainActivity.java @@ -225,4 +225,4 @@ public void goBacktoNormal() { baseContainer.setLayoutParams(oldParams); } } -} +} \ No newline at end of file diff --git a/instreamvideo/src/main/java/com/appnexus/opensdk/instreamvideo/InstreamVideoView.java b/instreamvideo/src/main/java/com/appnexus/opensdk/instreamvideo/InstreamVideoView.java index dc5bb406..6ced3ba2 100644 --- a/instreamvideo/src/main/java/com/appnexus/opensdk/instreamvideo/InstreamVideoView.java +++ b/instreamvideo/src/main/java/com/appnexus/opensdk/instreamvideo/InstreamVideoView.java @@ -58,7 +58,7 @@ class InstreamVideoView extends FrameLayout { void setup(Context context) { - SDKSettings.init(context, null); + SDKSettings.init(context, null, true, true, false, false); Clog.d(Clog.publicFunctionsLogTag, Clog.getString(R.string.new_adview)); @@ -253,4 +253,4 @@ private boolean alreadyAddedToFriendlyObstruction(View view) { protected ArrayList> getFriendlyObstructionList() { return friendlyObstructionList; } -} +} \ No newline at end of file diff --git a/sdk/src/com/appnexus/opensdk/AdView.java b/sdk/src/com/appnexus/opensdk/AdView.java index 0e74e452..0f469750 100644 --- a/sdk/src/com/appnexus/opensdk/AdView.java +++ b/sdk/src/com/appnexus/opensdk/AdView.java @@ -1667,4 +1667,4 @@ public Long getFinishTime() { * */ public boolean isEligibleForNativeAssemblyRendering() { return eligibleForNativeAssemblyRendering; } -} +} \ No newline at end of file diff --git a/sdk/src/com/appnexus/opensdk/NativeAdRequest.java b/sdk/src/com/appnexus/opensdk/NativeAdRequest.java index ecd5aa3d..eb57da12 100644 --- a/sdk/src/com/appnexus/opensdk/NativeAdRequest.java +++ b/sdk/src/com/appnexus/opensdk/NativeAdRequest.java @@ -42,7 +42,7 @@ public class NativeAdRequest implements Ad, MultiAd { public NativeAdRequest(Context context, String placementID) { - SDKSettings.init(context, null); + SDKSettings.init(context, null, true, true, false, false); requestParameters = new UTRequestParameters(context); requestParameters.setPlacementID(placementID); @@ -57,7 +57,7 @@ public NativeAdRequest(Context context, String placementID) { public NativeAdRequest(Context context, String inventoryCode, int memberID) { - SDKSettings.init(context, null); + SDKSettings.init(context, null, true, true, false, false); requestParameters = new UTRequestParameters(context); requestParameters.setInventoryCodeAndMemberID(memberID, inventoryCode); @@ -617,4 +617,4 @@ public Long getFinishTime() { return 0L; } -} +} \ No newline at end of file diff --git a/sdk/src/com/appnexus/opensdk/SDKSettings.java b/sdk/src/com/appnexus/opensdk/SDKSettings.java index 225b2324..74292d7a 100644 --- a/sdk/src/com/appnexus/opensdk/SDKSettings.java +++ b/sdk/src/com/appnexus/opensdk/SDKSettings.java @@ -49,14 +49,14 @@ public class SDKSettings { * */ private static Boolean useBackgroundThreads = false; + @Deprecated private static Boolean enableBannerOptimization = true; /** * For internal use only * */ - private static boolean isOmidActivationDone = false, isUserAgentFetched = false, isAAIDFetched = false; + private static boolean isOmidActivationDone = false, isUserAgentFetched = false, isAAIDFetched = false, isWarmupAdCallDone = false, isPrefetchWebViewDone = false; - private static boolean isWarmupAdCallDone = false; // hide the constructor from javadocs private SDKSettings() { @@ -429,21 +429,42 @@ public static void enableBackgroundThreading(boolean enable) { } public static void init(Context context, final InitListener listener) { - init(context, listener, true, true); + init(context, listener, true, true, true, true); } /** - * This is an overloaded init method which provides flexibility to enable/disable booleans for activateOmid, fetcbUserAgent and fetchAAID. + * This is an overloaded init method which provides flexibility to enable/disable booleans for activateOmid, fetchUserAgent and fetchAAID. * @param fetchUserAgent enable / disable fetching of User Agent. * @param fetchAAID enable / disable fetching of AAID. + * Use {@link SDKSettings#init(Context, InitListener, boolean, boolean, boolean, boolean)} signature instead + * To be removed in v9.0 * */ + @Deprecated public static void init(final Context context, final InitListener listener, final boolean fetchUserAgent, final boolean fetchAAID) { - prefetchWebview(context); - warmupAdCall(); + init(context, listener, fetchUserAgent, fetchAAID, true, true); + } + + /** + * This is an overloaded init method which provides flexibility to enable/disable booleans for activateOmid, fetchUserAgent, fetchAAID, enableWarmUpAdCall and preFetchWebView. + * @param fetchUserAgent enable / disable fetching of User Agent. + * @param fetchAAID enable / disable fetching of AAID. + * @param enableWarmUpAdCall enable / disable of the warm up ad call. + * @param preFetchWebView enable / disable pre-fetching of the webview. + * */ + public static void init(final Context context, final InitListener listener, final boolean fetchUserAgent, final boolean fetchAAID, final boolean enableWarmUpAdCall, final boolean preFetchWebView) { // Store the UA in the settings isOmidActivationDone = Omid.isActive(); isUserAgentFetched = !fetchUserAgent || !StringUtil.isEmpty(Settings.getSettings().ua); isAAIDFetched = !fetchAAID || !StringUtil.isEmpty(getAAID()); + // Execute prefetchWebview() if !isPrefetchWebViewDone or prefetchWebView is enabled. + if(!isPrefetchWebViewDone && preFetchWebView){ + isPrefetchWebViewDone = true; + prefetchWebview(context); + } + // Execute warmupAdCall() if !isWarmupAdCallDone or warm up ad call is enabled. + if (!isWarmupAdCallDone && enableWarmUpAdCall) { + warmupAdCall(); + } if (!isOmidActivationDone) { ANOmidViewabilty.getInstance().activateOmidAndCreatePartner(context.getApplicationContext()); isOmidActivationDone = true; @@ -496,9 +517,6 @@ public void onInitFinished(boolean success) { } private static void warmupAdCall() { - if (isWarmupAdCallDone) { - return; - } new HTTPGet() { @Override @@ -514,7 +532,7 @@ protected String getUrl() { } private static void prefetchWebview(Context context) { - if (isBannerOptimizationEnabled()) { + if (enableBannerOptimization) { List cachedAdWebView = Settings.getSettings().getCachedAdWebView(); if (cachedAdWebView.size() == 0) { AdWebView webView = new AdWebView(context); @@ -549,6 +567,8 @@ public void run() { /** * Experimental API, to be used in case of issue with banner optimization * To be removed in v9.0 + * Use {@link SDKSettings#init(Context, InitListener, boolean, boolean, boolean, boolean)} signature instead + * passing preFetchWebView = true/false while calling SDKSettings.init() has the same effect of setting enableBannerOptimization to true/false * */ @Deprecated public static void enableBannerOptimization(boolean enable) { @@ -563,4 +583,4 @@ public static void enableBannerOptimization(boolean enable) { public static Boolean isBannerOptimizationEnabled() { return enableBannerOptimization; } -} +} \ No newline at end of file diff --git a/sdk/src/com/appnexus/opensdk/XandrAd.java b/sdk/src/com/appnexus/opensdk/XandrAd.java index bc893f5d..e5e0f68f 100644 --- a/sdk/src/com/appnexus/opensdk/XandrAd.java +++ b/sdk/src/com/appnexus/opensdk/XandrAd.java @@ -38,8 +38,8 @@ public class XandrAd { /** - * memberId will be set using the {@link XandrAd#init(int, Context, boolean, boolean, InitListener)} - **/ + * memberId will be set using the {@link XandrAd#init(int, Context, boolean, boolean, InitListener)} + **/ private static int memberId = -1; /** * Cached member IDs list diff --git a/sdk/test/com/appnexus/opensdk/AdFetcherTest.java b/sdk/test/com/appnexus/opensdk/AdFetcherTest.java index cf26537e..949b14c4 100644 --- a/sdk/test/com/appnexus/opensdk/AdFetcherTest.java +++ b/sdk/test/com/appnexus/opensdk/AdFetcherTest.java @@ -142,7 +142,7 @@ public void testStartWithRefreshOnWithLazyLoad() { adFetcher.setPeriod(15000); adFetcher.start(); Lock.pause(1000); // added this so jenkins can have enough time to process - // assert 3 here because a AAID async task + // assert 2 here because a AAID async task assertExpectedBGTasksAfterOneAdRequest(2); assertEquals(AdFetcher.STATE.AUTO_REFRESH, adFetcher.getState()); @@ -179,7 +179,7 @@ public void testStartWithRefreshOnWithLazyLoadAndReload() { adFetcher.setPeriod(15000); adFetcher.start(); Lock.pause(1000); // added this so jenkins can have enough time to process - // assert 3 here because a AAID async task + // assert 2 here because a AAID async task assertExpectedBGTasksAfterOneAdRequest(2); assertEquals(AdFetcher.STATE.AUTO_REFRESH, adFetcher.getState()); @@ -207,7 +207,7 @@ public void testStartWithRefreshOnWithLazyLoadAndReload() { owner.loadAd(); Lock.pause(1000); // added this so jenkins can have enough time to process - // assert 3 here because a AAID async task + // assert 4 here because a AAID async task assertExpectedBGTasksAfterOneAdRequest(4); assertEquals(AdFetcher.STATE.AUTO_REFRESH, adFetcher.getState()); diff --git a/sdk/test/com/appnexus/opensdk/SDKSettingsTest.java b/sdk/test/com/appnexus/opensdk/SDKSettingsTest.java index 68b8906c..7e0166ea 100644 --- a/sdk/test/com/appnexus/opensdk/SDKSettingsTest.java +++ b/sdk/test/com/appnexus/opensdk/SDKSettingsTest.java @@ -111,4 +111,4 @@ public void testSDKSettingsInitAboveHONEY_COMB() { assertNotNull(Settings.getSettings().ua); assertNotEquals(Settings.getSettings().ua, (userAgentWebView.getSettings().getUserAgentString().trim().toLowerCase(Locale.ROOT))); } -} +} \ No newline at end of file