From 9b86997b5d878a7e348f18e2df5a18ce06021099 Mon Sep 17 00:00:00 2001 From: Rich Loveland Date: Fri, 22 Nov 2013 14:49:28 -0500 Subject: [PATCH 01/34] Revise and add to docs everywhere except mediation. I had to import `android.view.ViewGroup' into the interstitial ad view file to get the Javadocs to build. --- sdk/src/com/appnexus/opensdk/AdActivity.java | 6 +- sdk/src/com/appnexus/opensdk/AdListener.java | 34 ++-- sdk/src/com/appnexus/opensdk/AdView.java | 152 ++++++++------ .../com/appnexus/opensdk/BannerAdView.java | 186 +++++++++++------- .../com/appnexus/opensdk/BrowserActivity.java | 9 +- .../appnexus/opensdk/InterstitialAdView.java | 131 +++++++----- .../com/appnexus/opensdk/package-info.java | 34 ++-- 7 files changed, 337 insertions(+), 215 deletions(-) diff --git a/sdk/src/com/appnexus/opensdk/AdActivity.java b/sdk/src/com/appnexus/opensdk/AdActivity.java index 7c03f609c..af716a94c 100644 --- a/sdk/src/com/appnexus/opensdk/AdActivity.java +++ b/sdk/src/com/appnexus/opensdk/AdActivity.java @@ -35,12 +35,12 @@ import java.util.Locale; /** - * This is the main ad activity. You must add a reference to in your app's AndroidManifest.xml - * file. {@link BrowserActivity} Also needs to be added allow the in-app browser functionality, + * This is the main ad activity. You must add a reference to this to + * your app's AndroidManifest.xml file. {@link BrowserActivity} also + * needs to be added allow the in-app browser functionality: *
  * {@code
  * 
- *   ....
  *   
  *   
  * 
diff --git a/sdk/src/com/appnexus/opensdk/AdListener.java b/sdk/src/com/appnexus/opensdk/AdListener.java
index 507aaa78d..e6dd1a95e 100644
--- a/sdk/src/com/appnexus/opensdk/AdListener.java
+++ b/sdk/src/com/appnexus/opensdk/AdListener.java
@@ -17,8 +17,9 @@
 package com.appnexus.opensdk;
 
 /**
- * Implement this interface and pass it to your {@link BannerAdView} and {@link  InterstitialAdView}
- * objects to receive events on the status of the ad.
+ * Implement this interface and pass it to your {@link BannerAdView}
+ * and {@link InterstitialAdView} objects to receive events on the
+ * status of the ad.
  */
 public interface AdListener {
     /**
@@ -29,37 +30,40 @@ public interface AdListener {
     public void onAdLoaded(AdView adView);
 
     /**
-     * Called when an ad request has failed.
-     * Ad request failures may include no ad available, or networking errors
+     * Called when an ad request has failed.  Ad requests can fail
+     * because no ad is available, or because of networking errors.
      *
      * @param adView The {@link AdView} that loaded the ad.
      */
     public void onAdRequestFailed(AdView adView);
 
     /**
-     * Called when an ad expands due to user interaction. MRAID ads that expand
-     * the screen generate these events. This event may fire from both Banner and Interstitial ads.
-     * This would be a good time to stop or pause your application due 
-     * to the user interacting with the ad. 
+     * Called when an ad expands due to user interaction.  MRAID ads
+     * that expand the screen generate these events, for example.
+     * This event may fire from both banner and interstitial ads.
+     * This would be a good time to stop or pause your application due
+     * to the user interacting with the ad.  This is the inverse of
+     * onAdCollapsed.
      *
      * @param adView The {@link AdView} that loaded the ad.
      */
     public void onAdExpanded(AdView adView);
 
     /**
-     * Called when an ad is closed/unexpanded. The user has stopped interacting 
-     * with the ad. This is the corollary of onAdExpanded.
+     * Called when an ad is closed/unexpanded, for example if the user
+     * has stopped interacting with the ad.  This is the inverse of
+     * onAdExpanded.
      *
      * @param adView The {@link AdView} that loaded the ad.
      */
     public void onAdCollapsed(AdView adView);
 
     /**
-     * Called when an ad is clicked. The current activity will be paused 
-     * as the user switches activities to the activity launched from 
-     * the ad interaction. For example the user clicked a link that 
-     * opened a web browser, or the user touched a click to call link 
-     * which launched the phone dialer. 
+     * Called when an ad is clicked.  The current activity will be
+     * paused as the user switches to the activity launched from the
+     * ad interaction.  For example, the user may click a link that
+     * opens a web browser, or touch a click-to-call link which
+     * launches the phone dialer.
      *
      * @param adView The {@link AdView} that loaded the ad.
      */
diff --git a/sdk/src/com/appnexus/opensdk/AdView.java b/sdk/src/com/appnexus/opensdk/AdView.java
index 1cd2455f5..e72e7474a 100644
--- a/sdk/src/com/appnexus/opensdk/AdView.java
+++ b/sdk/src/com/appnexus/opensdk/AdView.java
@@ -38,8 +38,9 @@
 import java.util.LinkedList;
 
 /**
- * The parent class of InterstitialAdView and BannerAdView. This may not be
- * instantiated directly. It public methods are accessed through one of its sub classes.
+ * The parent class of {@link InterstitialAdView} and {@link
+ * BannerAdView}.  This may not be instantiated directly.  Its public
+ * methods are accessed through one of its sub classes.
  *
  *
  */
@@ -194,10 +195,10 @@ boolean isReadyToStart() {
 	}
 
 	/**
-	 * Loads a new ad, if the ad space is visible. You should have called
-	 * setPlacementID() before invoking this method.
+	 * Loads a new ad, if the ad space is visible.  You should
+	 * have called setPlacementID before invoking this method.
 	 *
-	 * @return true is ad will begin loading, false otherwise.
+	 * @return true means the ad will begin loading; false otherwise.
 	 *
 	 */
 	protected boolean loadAd() {
@@ -214,12 +215,12 @@ protected boolean loadAd() {
 	}
 
 	/**
-	 * Loads a new ad, if the ad space is visible, and sets the placement id
-	 * attribute of the AdView to the supplied parameter.
+	 * Loads a new ad, if the ad space is visible, and sets the
+	 * AdView's placement ID.
 	 *
-	 * @param placementID   The new placement id to use.
+	 * @param placementID The new placement ID to use.
 	 *
-	 * @return true is ad will begin loading, false otherwise
+	 * @return true means the ad will begin loading; false otherwise.
 	 */
 	public boolean loadAd(String placementID) {
 		this.setPlacementID(placementID);
@@ -296,12 +297,13 @@ public String getPlacementID() {
 	}
 
 	/**
-	 * Sets the placement id of the AdView. The placement ID identifies a
-	 * location in your application. You must have a valid active placement ID
-	 * to monetize your application.
+	 * Sets the placement id of the AdView.  The placement ID
+	 * identifies the location in your application where ads will
+	 * be shown.  You must have a valid, active placement ID to
+	 * monetize your application.
 	 *
 	 * @param placementID
-	 *            The placement id to use
+	 *            The placement ID to use.
 	 */
 	public void setPlacementID(String placementID) {
 		Clog.d(Clog.publicFunctionsLogTag,
@@ -378,18 +380,18 @@ public void onClick(View v) {
 
 	/**
 	 *
-	 * @return true if the AdView is a BannerAdView
+	 * @return true if the AdView is a {@link BannerAdView}.
 	 */
 	abstract boolean isBanner();
 
 	/**
 	 *
-	 * @return true if the AdView is an InterstitialAdView
+	 * @return true if the AdView is an {@link InterstitialAdView}.
 	 */
 	abstract boolean isInterstitial();
 
 	/**
-	 * Sets the currently installed listener that the SDK will send events on.
+	 * Sets the currently installed listener that the SDK will send events to.
 	 *
 	 * @param listener
 	 *            The {@link AdListener} object to use.
@@ -401,7 +403,7 @@ public void setAdListener(AdListener listener) {
 	}
 
 	/**
-	 * Gets the currently installed listener that the SDK will send events on.
+	 * Gets the currently installed listener that the SDK will send events to.
 	 *
 	 * @return The {@link AdListener} object in use.
 	 */
@@ -416,10 +418,11 @@ void fail() {
 	}
 
 	/**
-	 * Retrieve the inapp or native browser setting.
+	 * Retrieve the setting that determines whether or not the
+	 * device's native browser is used instead of the in-app
+	 * browser when the user clicks an ad.
 	 *
-	 * @return whether or not the devices native browser is used instead of the
-	 *         in-app browser.
+	 * @return true if the device's native browser will be used; false otherwise. 
 	 */
 	public boolean getOpensNativeBrowser() {
 		Clog.d(Clog.publicFunctionsLogTag, Clog.getString(
@@ -428,12 +431,12 @@ public boolean getOpensNativeBrowser() {
 	}
 
 	/**
-	 * Set this to true to disable the in-app browser. That will cause url's to
-	 * open in the device's native browser e.g. Chrome. If set to true when a
-	 * user clicks on an ad your app will be paused and the native browser will
-	 * open. Set this to false to enabled the in-app browser. Which is a
-	 * lightweight browser that runs within your app. The default value is
-	 * false.
+	 * Set this to true to disable the in-app browser.  This will
+	 * cause URLs to open in a native browser such as Chrome so
+	 * that when the user clicks on an ad, your app will be paused
+	 * and the native browser will open.  Set this to false to
+	 * enable the in-app browser instead (a lightweight browser
+	 * that runs within your app).  The default value is false.
 	 *
 	 * @param opensNativeBrowser
 	 */
@@ -452,7 +455,11 @@ protected void setBrowserStyle(BrowserStyle browserStyle) {
 	}
 
 	/**
-	 * Retrieve the current PSA setting
+	 * Retrieve the current PSA setting.  PSAs (Public Service
+	 * Announcements) are ads for various causes or nonprofit
+	 * organizations that can be served if there are no ads
+	 * available.  You can turn this on and off with
+	 * setShouldServePSAs.
 	 *
 	 * @return Whether this placement accepts PSAs if no ad is served.
 	 */
@@ -461,55 +468,63 @@ public boolean getShouldServePSAs() {
 	}
 
 	/**
-	 * Allows overriding the platform behavior in the case there is no ad
-	 * currently available. If set to true the platform will retrieve and
-	 * displaya PSA (Public Service Announcement) . Set the value to false it
-	 * will return no ad.
+	 * Set the current PSA setting.  If set to true, the SDK will
+	 * retrieve and display a Public Service Announcement if no
+	 * other ad is available.  PSAs are ads for various causes or
+	 * nonprofit organizations.  If set to false, no ad is
+	 * returned.
 	 *
 	 * @param shouldServePSAs
-	 *            Whether this placement is willing to accept PSA if no ad is
-	 *            served.
+	 *            Whether this placement is willing to accept a PSA if no other ad is available.
 	 */
 	public void setShouldServePSAs(boolean shouldServePSAs) {
 		this.shouldServePSAs = shouldServePSAs;
 	}
 
 	/**
-	 * Retrieve the minimum price. A value of zero indicates no minimum.
+	 * Retrieve the reserve price.  The reserve price is the
+	 * minimum price you will accept in order to show an ad.  A
+	 * value of 0 indicates that there is no minimum.
 	 *
-	 * @return The minimum price zero indicates none.
+	 * @return The reserve price.  A value of 0 indicates that no reserve is set.
 	 */
 	public float getReserve() {
 		return reserve;
 	}
 
 	/**
-	 * Set a minimum price. Note that setting a minimum may negatively affect
-	 * monetization. Setting this value to zero disables the minimum price.
-	 * Default value is zero.
+	 * Set a reserve price.  The reserve price is the minimum
+	 * price you will accept in order to show an ad.  Note that
+	 * setting a reserve price may negatively affect monetization,
+	 * since there may not be any buyers willing to pay more than
+	 * your reserve.  Setting this value to zero disables the
+	 * reserve price.  The default value is zero.
 	 *
-	 * @param reserve The reserve in CPM.
+	 * @param reserve The reserve price expressed in CPM, e.g., 0.50f.
 	 */
 	public void setReserve(float reserve) {
 		this.reserve = reserve;
 	}
 
 	/**
-	 * Retrieve the current users Age. Note this is a string as it may be an
-	 * age, birth year or age range. The default value is an empty string.
+	 * Retrieve the current user's age.  Note that this is a
+	 * string as it may come in one of several formats: age, birth
+	 * year, or age range.  The default value is an empty string.
 	 *
-	 * @return The age
+	 * @return The current user's age.
 	 */
 	public String getAge() {
 		return age;
 	}
 
 	/**
-	 * Set's the user's age. should be used if age or age range is known.
+	 * Set the current user's age.  This should be set if the
+	 * user's age or age range is known, as it can help make
+	 * buying the ad space more attractive to advertisers.
 	 *
-	 * @param age
-	 *            should be a numerical age, birth year, or hyphenated age
-	 *            range. For example: "56", "1974", or "25-35"
+	 * @param age A string containing a numeric age, birth year,
+	 *            or hyphenated age range.  For example: "56",
+	 *            "1974", or "25-35".
 	 */
 	public void setAge(String age) {
 		this.age = age;
@@ -517,7 +532,7 @@ public void setAge(String age) {
 
 	/**
 	 *
-	 * Users gender enumeration
+	 * The user's gender.
 	 *
 	 */
 	public enum GENDER {
@@ -528,33 +543,39 @@ public enum GENDER {
 	}
 
 	/**
-	 * Get the current user's gender if available
+	 * Get the current user's gender, if it's available.  The
+	 * default value is UNKNOWN.
 	 *
-	 * @return The gender
+	 * @return The user's gender.
 	 */
 	public GENDER getGender() {
 		return gender;
 	}
 
 	/**
-	 * Set the users gender if it is known. Default value is UNKNOWN
+	 * Set the user's gender.  This should be set if the user's
+	 * gender is known, as it can help make buying the ad space
+	 * more attractive to advertisers.  The default value is
+	 * UNKNOWN.
 	 *
 	 * @param gender
-	 *            One of UNKNOWN,MALE,FEMALE
+	 *            The user's gender.
 	 */
 	public void setGender(GENDER gender) {
 		this.gender = gender;
 	}
 
 	/**
-	 * Add a custom keyword to the request url for the ad. This will be used to
-	 * allow custom targeting parameters within the AppNexus platform. You will
-	 * be given the names and to use by App Nexus account representative.
+	 * Add a custom keyword to the request URL for the ad.  This
+	 * is used to set custom targeting parameters within the
+	 * AppNexus platform.  You will be given the keys and values
+	 * to use by your AppNexus account representative or your ad
+	 * network.
 	 *
 	 * @param key
-	 *            keyword name to add, cannot be null or empty
+	 *            The key to add; this cannot be null or empty.
 	 * @param value
-	 *            keyword value, cannot be null
+	 *            The value to add; this cannot be null or empty.
 	 */
 	public void addCustomKeywords(String key, String value) {
 		if (StringUtil.isEmpty(key) || (value == null)) {
@@ -564,11 +585,13 @@ public void addCustomKeywords(String key, String value) {
 	}
 
 	/**
-	 * Remove a custom keyword from the request url for the ad. Use this to
-	 * remove a keyword previously set using addCustomKeywords.
+	 *
+	 * Remove a custom keyword from the request URL for the ad.
+	 * Use this to remove a keyword previously set using
+	 * addCustomKeywords.
 	 *
 	 * @param key
-	 *            keyword name to remove, cannot be null or empty
+	 *            The key to remove; this cannot be null or empty.
 	 */
 	public void removeCustomKeyword(String key) {
 		if (StringUtil.isEmpty(key))
@@ -584,10 +607,11 @@ public void removeCustomKeyword(String key) {
 	}
 
 	/**
-	 * Retrieve the array of currently configured Custom Keywords in the current
-	 * AdView.
+	 * Retrieve the array of custom keywords associated with the
+	 * current AdView.
 	 *
-	 * @return The current list of key value pairs of custom keywords.
+	 * @return The current list of key-value pairs of custom
+	 * keywords.
 	 */
 	public ArrayList> getCustomKeywords() {
 		return customKeywords;
@@ -610,8 +634,8 @@ public BrowserStyle(Drawable forwardButton, Drawable backButton,
 	}
 
 	/**
-	 * Private class to bridge events from mediation to the user AdListener
-	 * class
+	 * Private class to bridge events from mediation to the user
+	 * AdListener class.
 	 *
 	 */
 	private class AdListenerDispatch implements AdViewListener {
diff --git a/sdk/src/com/appnexus/opensdk/BannerAdView.java b/sdk/src/com/appnexus/opensdk/BannerAdView.java
index f4f6a6373..d5a2a8473 100644
--- a/sdk/src/com/appnexus/opensdk/BannerAdView.java
+++ b/sdk/src/com/appnexus/opensdk/BannerAdView.java
@@ -36,10 +36,16 @@
 import com.appnexus.opensdk.utils.WebviewUtil;
 
 /**
- * This view is added to an existing layout in order to display banner ads.
- * It may be added via XML or via code
+ * This view is added to an existing layout in order to display banner
+ * ads.  It may be added via XML or code.
+ *
+ * 

+ * Note that you need a placement ID in order to show ads. If you + * don't have a placement ID, you'll need to get one from your + * AppNexus representative or your ad network. + *

+ * Using XML, you might add it like this: * - * Note that you must insert your Placement ID. *
  * {@code
  *
@@ -56,17 +62,25 @@
  *           android:should_reload_on_resume=true
  *           android:opens_native_browser=true
  *           android:expands_to_fit_screen_width=false
- *           />
+ *           />;
  * }
  * 
* - * In code you do the following + * In code you can do the following: + * + *
  * {@code
- *   blah
- *   blah
- *   blah
+ * RelativeLayout rl = (RelativeLayout)(findViewById(R.id.mainview));
+ * AdView av = new BannerAdView(this);
+ * LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, 100);
+ * av.setAdHeight(50);
+ * av.setAdWidth(320);
+ * av.setLayoutParams(lp);
+ * av.setPlacementID("12345");
+ * rl.addView(av);
+ * av.loadAd();
  * }
- *
+ * 
* * */ @@ -91,10 +105,10 @@ private void setDefaultsBeforeXML() { } /** - * Creates a new BannerAdView + * Create a new BannerAdView in which to load and show ads. * - * @param context The context of the ViewGroup to which the BannerAdView is - * being added. + * @param context The context of the {@link ViewGroup} to which + * the BannerAdView is being added. */ public BannerAdView(Context context) { super(context); @@ -102,11 +116,13 @@ public BannerAdView(Context context) { } /** - * Creates a new BannerAdView + * Create a new BannerAdView in which to load and show ads. * - * @param context The context of the ViewGroup to which the BannerAdView is - * being added. - * @param attrs The AttributeSet to use when creating the BannerAdView. + * @param context The context of the {@link ViewGroup} to which + * the BannerAdView is being added. + * + * @param attrs The {@link AttributeSet} to use when creating the + * BannerAdView. */ public BannerAdView(Context context, AttributeSet attrs) { super(context, attrs); @@ -114,15 +130,20 @@ public BannerAdView(Context context, AttributeSet attrs) { } /** - * Creates a new BannerAdView + * Create a new BannerAdView in which to load and show ads. + * + * @param context The context of the {@link ViewGroup} to which + * the BannerAdView is being added. * - * @param context The context of the ViewGroup to which the BannerAdView is - * being added. - * @param attrs The AttributeSet to use when creating the BannerAdView. - * @param defStyle The default style to apply to this view. If 0, no style will - * be applied (beyond what is included in the theme). This may - * either be an attribute resource, whose value will be retrieved - * from the current theme, or an explicit style resource. + * @param attrs The {@link AttributeSet} to use when creating the + * BannerAdView. + + * @param defStyle The default style to apply to this view. If 0, + * no style will be applied (beyond what is + * included in the theme). This may be either an + * attribute resource, whose value will be + * retrieved from the current theme, or an + * explicit style resource. */ public BannerAdView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); @@ -130,12 +151,15 @@ public BannerAdView(Context context, AttributeSet attrs, int defStyle) { } /** - * Creates a new BannerAdView + * Creates a new BannerAdView in which to load and show ads. + * + * @param context The context of the {@link ViewGroup} to which + * the BannerAdView is being added. * - * @param context The context of the ViewGroup to which the BannerAdView is - * being added. - * @param refresh_interval The desired refresh rate, in milliseconds. By default, 30 - * seconds. Minimum is 15 seconds. 0 turns auto-refresh off. + * @param refresh_interval The desired refresh rate, in + * milliseconds. The default value is 30 + * seconds; minimum is 15. A value of 0 + * turns auto-refreshing off. */ public BannerAdView(Context context, int refresh_interval) { super(context); @@ -211,11 +235,14 @@ private void onFirstLayout() { } /** - * Call this method to start loading an ad into this view. - * Ad loading is asynchronous, that is calling this method will request - * an ad from the server. If you wish to know whether the ad failed to load or was successfully loaded - * use the AdListener object to receive the corresponding events. - * @return true if the ad load was successfully dispatched, false otherwise + * Call this method to start loading an ad into this view + * asynchronously. This will request an ad from the server. If + * you wish to know whether the ad succeeded or failed to load, + * use the {@link AdListener} object to receive the corresponding + * events. + * + * @return true if the ad load was successfully + * dispatched, false otherwise. */ @Override public boolean loadAd() { @@ -224,17 +251,18 @@ public boolean loadAd() { } /** - * Loads a new ad, if the ad space is visible, and sets the placement id, ad - * width, and ad height attribute of the AdView to the supplied parameters. + * Loads a new ad, if the ad space is visible, and sets the + * placement ID, ad width, and ad height attributes of the AdView. * * @param placementID - * The new placement id to use. + * The placement ID to use in this view. * @param width - * The new width to use. + * The width of the ad. * @param height - * The new height to use. + * The height of the ad. * - * @return true is ad will begin loading, false otherwise + * @return true if the ad will begin loading, + * false otherwise. */ public boolean loadAd(String placementID, int width, int height) { setAdSize(width, height); @@ -314,9 +342,11 @@ protected void loadVariablesFromXML(Context context, AttributeSet attrs) { } /** - * Retrieve the current set auto refresh interval. - * @return The interval, in milliseconds, at which the BannerAdView will - * request new ads, if autorefresh is enabled. + * Retrieve the currently set auto-refresh interval. + * + * @return The interval, in milliseconds, at which the + * BannerAdView will request new ads, if auto-refresh is + * enabled. */ public int getAutoRefreshInterval() { Clog.d(Clog.publicFunctionsLogTag, @@ -325,7 +355,7 @@ public int getAutoRefreshInterval() { } /** - * Sets the height of the ad to request. + * Set the height of the ad to request. * * @deprecated Favor setAdSize(int w, int h) * @param h The height, in pixels, to use. @@ -337,7 +367,7 @@ public void setAdHeight(int h) { } /** - * Sets the width of the ad to request. + * Set the width of the ad to request. * * @deprecated Favor setAdSize(int w, int h) * @param w The width, in pixels, to use. @@ -349,10 +379,10 @@ public void setAdWidth(int w) { } /** - * Sets the size of the ad to request. + * Set the size of the ad to request. * - * @param w The width, in pixels, to use. - * @param h The height, in pixels, to use. + * @param w The width of the ad, in pixels. + * @param h The height of the ad, in pixels. */ public void setAdSize(int w, int h){ Clog.d(Clog.baseLogTag, Clog.getString(R.string.set_size, w, h)); @@ -361,7 +391,9 @@ public void setAdSize(int w, int h){ } /** - * @return The height of the ad to be requested. + * Check the height of the ad to be requested for this view. + * + * @return The height of the ad to request. */ public int getAdHeight() { Clog.d(Clog.baseLogTag, Clog.getString(R.string.get_height, height)); @@ -369,7 +401,9 @@ public int getAdHeight() { } /** - * @return The width of the ad to be requested. + * Check the width of the ad to be requested for this view. + * + * @return The width of the ad to request. */ public int getAdWidth() { Clog.d(Clog.baseLogTag, Clog.getString(R.string.get_width, width)); @@ -377,9 +411,13 @@ public int getAdWidth() { } /** - * @param period The interval, in milliseconds, at which the BannerAdView will - * request new ads, if autorefresh is enabled. The minimum period - * is 15 seconds. The default period is 30 seconds. + * Set the auto-refresh interval. This is the interval, in + * milliseconds, at which the BannerAdView will request new ads, + * if auto-refresh is enabled. The default period is 30 seconds; + * the minimum is 15. You can enable or disable auto-refresh + * using the setAutoRefresh method. + * + * @param period The auto-refresh interval, in milliseconds. */ public void setAutoRefreshInterval(int period) { this.period = Math.max(Settings.getSettings().MIN_REFRESH_MILLISECONDS, @@ -396,7 +434,10 @@ public void setAutoRefreshInterval(int period) { } /** - * @return Whether this view should periodically request new ads. + * Check whether auto-refresh is currently enabled for this ad + * view. + * + * @return If true, this view will periodically request new ads. */ private boolean getAutoRefresh() { Clog.d(Clog.publicFunctionsLogTag, @@ -405,7 +446,10 @@ private boolean getAutoRefresh() { } /** - * @param auto_refresh Whether this view should periodically request new ads. + * Turn the auto-refresh setting for this ad view on or off. + * + * @param auto_refresh If set to true, this view will periodically + * request new ads. */ private void setAutoRefresh(boolean auto_refresh) { Clog.d(Clog.publicFunctionsLogTag, @@ -421,8 +465,10 @@ private void setAutoRefresh(boolean auto_refresh) { } /** - * Retrieves the current shouldAutoReload on resume value - * @return True add will reload on resume, false otherwise. + * Check whether the ad view will load a new ad if the user + * resumes use of the app from a screenlock or multitask. + * + * @return If true, the ad will reload on resume. */ public boolean getShouldReloadOnResume() { Clog.d(Clog.publicFunctionsLogTag, Clog.getString( @@ -431,9 +477,11 @@ public boolean getShouldReloadOnResume() { } /** - * Whether or not this view should load a new ad if the user - * resumes use of the app from a screenlock or multitask. - * @param shouldReloadOnResume True to reload on resume, false otherwise + * Set whether or not this view should load a new ad if the user + * resumes use of the app from a screenlock or multitask. + * + * @param shouldReloadOnResume Set this to true to reload the ad + * on resume. */ void setShouldReloadOnResume(boolean shouldReloadOnResume) { Clog.d(Clog.publicFunctionsLogTag, Clog.getString( @@ -507,20 +555,24 @@ boolean isInterstitial() { } /** - * Retrieves the current expandsToFitWindowWidth setting. + * Check whether the ad will expand to fit the screen width. This + * feature is disabled by default. * - * @return true ad expands to fit screen width, false otherwise + * @return If true, the ad will expand to fit screen width. */ public boolean getExpandsToFitScreenWidth() { return expandsToFitScreenWidth; } /** - * Enable the expand ad to fit screen width. This feature will cause ad creatives - * that are smaller than the view size to 'stretch' to the current size. This may cause - * image quality degradation for the benefit of having an ad occupy the entire adview. - * By default his feature is disabled - * @param expandsToFitScreenWidth true to enable the automatic expansion, false otherwise + * Set whether ads will expand to fit the screen width. This + * feature will cause ad creatives that are smaller than the view + * size to 'stretch' to the current size. This may cause image + * quality degradation for the benefit of having an ad occupy the + * entire ad view. This feature is disabled by default. + * + * @param expandsToFitScreenWidth If true, automatic expansion is + * enabled. */ public void setExpandsToFitScreenWidth(boolean expandsToFitScreenWidth) { this.expandsToFitScreenWidth = expandsToFitScreenWidth; diff --git a/sdk/src/com/appnexus/opensdk/BrowserActivity.java b/sdk/src/com/appnexus/opensdk/BrowserActivity.java index f7267f68e..55714a0c0 100644 --- a/sdk/src/com/appnexus/opensdk/BrowserActivity.java +++ b/sdk/src/com/appnexus/opensdk/BrowserActivity.java @@ -41,13 +41,16 @@ import com.appnexus.opensdk.AdView.BrowserStyle; import com.appnexus.opensdk.utils.Clog; + /** - * This is the in-app browser activity. You must add a reference to in your app's AndroidManifest.xml - * file. {@link AdActivity} Also needs to be added allow the in-app browser functionality, + * This is the in-app browser activity. You must add a reference to + * this activity in your app's AndroidManifest.xml + * file. {@link AdActivity} also needs to be added allow the in-app + * browser functionality, + * *
  * {@code
  * 
- *   ....
  *   
  *   
  * 
diff --git a/sdk/src/com/appnexus/opensdk/InterstitialAdView.java b/sdk/src/com/appnexus/opensdk/InterstitialAdView.java
index fa376d334..a37b4ab25 100644
--- a/sdk/src/com/appnexus/opensdk/InterstitialAdView.java
+++ b/sdk/src/com/appnexus/opensdk/InterstitialAdView.java
@@ -28,6 +28,7 @@
 import android.util.Pair;
 import android.view.Gravity;
 import android.view.View;
+import android.view.ViewGroup;
 import android.view.Window;
 import android.view.WindowManager;
 import android.widget.FrameLayout;
@@ -40,9 +41,10 @@
 import java.util.Queue;
 
 /**
- * This class controls the loading and displaying of interstitial ads.
- * Interstitial ads are modal and take up the entire screen. The Interstitial Ad is tied
- * to an {@link AdActivity} which is lauched to show the ad.
+ * This class controls the loading and display of interstitial ads.
+ * These ads are modal and take up the entire screen.  Each
+ * interstitial ad is tied to a {@link AdActivity} which is launched
+ * to show the ad.
  *
  */
 public class InterstitialAdView extends AdView {
@@ -63,38 +65,46 @@ public class InterstitialAdView extends AdView {
     private AdActivity adActivity = null;
 
     /**
-     * Creates a new InterstitialAdView
+     * Creates a new interstitial ad view in which to load and show
+     * interstitial ads.
      *
-     * @param context The context of the ViewGroup to which the InterstitialAdView
-     *                is being added.
+     * @param context The context of the {@link ViewGroup} to which
+     *                the interstitial ad view is being added.
      */
     public InterstitialAdView(Context context) {
         super(context);
     }
 
     /**
-     * Creates a new InterstitialAdView
+     * Creates a new interstitial ad view in which to load and show
+     * interstitial ads.
      *
-     * @param context The context of the ViewGroup to which the InterstitialAdView
-     *                is being added.
-     * @param attrs   The {@link AttributeSet} to use when creating the
-     *                InterstitialAdView.
+     * @param context The context of the {@link ViewGroup} to which
+     *                the interstitial ad view is being added.
+     *
+     * @param attrs The {@link AttributeSet} to use when creating the
+     *              interstitial ad view.
      */
     public InterstitialAdView(Context context, AttributeSet attrs) {
         super(context, attrs);
     }
 
     /**
-     * Creates a new InterstitialAdView
+     * Creates a new interstitial ad view in which to load and show
+     * interstitial ads.
+     *
+     * @param context The context of the {@link ViewGroup} to which
+     *                the interstitial ad view is being added.
+     *
+     * @param attrs The {@link AttributeSet} to use when creating the
+     *              interstitial ad view.
      *
-     * @param context  The context of the ViewGroup to which the InterstitialAdView
-     *                 is being added.
-     * @param attrs    The AttributeSet to use when creating the
-     *                 InterstitialAdView.rs
-     * @param defStyle The default style to apply to this view. If 0, no style will
-     *                 be applied (beyond what is included in the theme). This may
-     *                 either be an attribute resource, whose value will be retrieved
-     *                 from the current theme, or an explicit style resource.
+     * @param defStyle The default style to apply to this view. If 0,
+     *                 no style will be applied (beyond what is
+     *                 included in the theme). This may be either an
+     *                 attribute resource, whose value will be
+     *                 retrieved from the current theme, or an
+     *                 explicit style resource.
      */
     public InterstitialAdView(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
@@ -170,10 +180,14 @@ protected void loadVariablesFromXML(Context context, AttributeSet attrs) {
     }
 
     /**
-     * Requests a new interstitial ad from the server and stores it in a local
-     * queue. Please note, that interstitials have a timeout of 60 seconds. You
-     * must show the interstitial (call 'show()') within 60 seconds of getting a
-     * response, otherwise, the ad will not show.
+     * Requests a new interstitial ad from the server and stores it in
+     * a local queue.  Note that interstitials have a timeout of 60
+     * seconds; you must show the interstitial (by calling
+     * show()) within 60 seconds of getting a response;
+     * otherwise, the ad will not show.
+     *
+     * @return true if the ad load was successfully
+     *         dispatched; false otherwise.
      */
     @Override
     public boolean loadAd() {
@@ -234,9 +248,11 @@ private boolean removeStaleAds(long now) {
     }
 
     /**
-     * Checks the queue to see if there are any valid ads available.
+     * Checks the queue to see if there is a valid (i.e., fresher than
+     * 60 seconds) interstitial ad available.
      *
-     * @return whether there is a valid ad available in the queue
+     * @return true if there is a valid ad available in
+     *         the queue, false otherwise.
      */
     public boolean isReady() {
         long now = System.currentTimeMillis();
@@ -252,12 +268,13 @@ public boolean isReady() {
     }
 
     /**
-     * Pops ads from the queue until it finds one that has not exceeded the
-     * timeout of 60 seconds, and displays it in a new activity. All ads in the
-     * queue which have exceeded the timeout are removed.
+     * Pops interstitial ads from the queue until it finds one that
+     * has not exceeded the 60 second timeout, and displays it in a
+     * new activity.  All ads in the queue which have exceeded the
+     * timeout are removed.
      *
-     * @return The number of remaining ads in the queue that do not exceed the
-     *         timeout.
+     * @return The number of remaining ads in the queue that do not
+     *         exceed the timeout.
      */
     public int show() {
         Clog.d(Clog.publicFunctionsLogTag, Clog.getString(R.string.show_int));
@@ -297,9 +314,11 @@ public int show() {
     }
 
     /**
-     * Returns an ArrayList of {@link Size}s which are allowed to be displayed.
+     * Get a list of ad {@link Size}s which are allowed to be
+     * displayed.
      *
-     * @return The ArrayList of {@link Size}s which are allowed to be displayed.
+     * @return The {@link ArrayList} of {@link Size}s which are
+     *         allowed to be displayed.
      */
     public ArrayList getAllowedSizes() {
         Clog.d(Clog.publicFunctionsLogTag,
@@ -308,12 +327,13 @@ public ArrayList getAllowedSizes() {
     }
 
     /**
-     * Sets the ArrayList of {@link Size}s which are allowed to be displayed.
-     * The allowed sizes is the list of the platform ad sizes which may be inserted into
-     * an interstitial view. The default list is sufficient for most implementations. Custom
-     * sizes may be added here.
-     * @param allowed_sizes The ArrayList of {@link Size}s which are allowed to be
-     *                      displayed.
+     * Set the ad {@link Size}s which are allowed to be displayed.
+     * This is a list of the platform ad sizes that may be inserted
+     * into an interstitial ad view.  The default list is sufficient
+     * for most implementations.  Custom sizes may also be added here.
+     *
+     * @param allowed_sizes The {@link ArrayList} of {@link Size}s
+     *                      which are allowed to be displayed.
      */
     public void setAllowedSizes(ArrayList allowed_sizes) {
         Clog.d(Clog.publicFunctionsLogTag,
@@ -322,8 +342,8 @@ public void setAllowedSizes(ArrayList allowed_sizes) {
     }
 
     /**
-     * Sets the background Color to use behind the interstitial ad.
-     * If left unspecified the default background is Black.
+     * Sets the background color to use behind the interstitial ad.
+     * If left unspecified, the default is black.
      */
     public void setBackgroundColor(int color) {
         Clog.d(Clog.publicFunctionsLogTag, Clog.getString(R.string.set_bg));
@@ -331,9 +351,10 @@ public void setBackgroundColor(int color) {
     }
 
     /**
-     * Gets the background Color to use behind the interstitial ad.
+     * Get the current background color which will appear behind the
+     * interstitial ad.
      *
-     * @return The background Color to use behind the interstitial ad.
+     * @return The background color to use behind the interstitial ad.
      */
     public int getBackgroundColor() {
         Clog.d(Clog.publicFunctionsLogTag, Clog.getString(R.string.get_bg));
@@ -341,7 +362,7 @@ public int getBackgroundColor() {
     }
 
     /**
-     * Destroys this InterstitialAdView object.
+     * Destroy this InterstitialAdView object.
      */
     public void destroy() {
         Clog.d(Clog.publicFunctionsLogTag, Clog.getString(R.string.destroy_int));
@@ -352,19 +373,25 @@ public void destroy() {
     }
 
     /**
-     * @return the time in milliseconds after an interstitial is displayed until
-     *         the close button appears. Default is 10 seconds. 0 is disabled
+     * Get the delay between when an interstitial ad is displayed and
+     * when the close button appears to the user.  10 seconds is the
+     * default; 0 means that the close button will appear immediately.
+     *
+     * @return the time in milliseconds between when an interstitial
+     *         ad is displayed and when the close button appears.
      */
     public int getCloseButtonDelay() {
         return closeButtonDelay;
     }
 
     /**
-     * Interstitial Ad's have a close button. The close button does not appear until the ad
-     * has been view for 10 seconds by default. This method allows you to override the timeout. Settting
-     * the value to 0 shows the close button with the ad. The maximum time allowed is 10 seconds. Any value
-     * larger than that will cause 10 seconds to be used.
-     * @param closeButtonDelay The time in milliseconds to wait before showing the close button.
+     * Set the delay between when an interstitial ad is displayed and
+     * when the close button appears to the user.  10 seconds is the
+     * default; it is also the maximum.  Setting the value to 0 allows
+     * the close button to appear immediately.
+     * 
+     * @param closeButtonDelay The time in milliseconds before the
+     *                         close button is displayed to the user.
      */
     public void setCloseButtonDelay(int closeButtonDelay) {
         this.closeButtonDelay = Math.min(closeButtonDelay, Settings.getSettings().DEFAULT_INTERSTITIAL_CLOSE_BUTTON_DELAY);
@@ -467,4 +494,4 @@ public void onClick(View v) {
             }
         }
     }
-}
\ No newline at end of file
+}
diff --git a/sdk/src/com/appnexus/opensdk/package-info.java b/sdk/src/com/appnexus/opensdk/package-info.java
index 7c99c33f4..1dc7ce8aa 100644
--- a/sdk/src/com/appnexus/opensdk/package-info.java
+++ b/sdk/src/com/appnexus/opensdk/package-info.java
@@ -1,15 +1,27 @@
 /**
- * The AppNexus Mobile Advertising SDK
- * The source code is available for download from https://github.com/appnexus
- * You can find more information about AppNexus and this SDK at http://www.appnexus.com
- * 
- * To monetize a free app you may choose to include advertising. Where, how, when and why are all up to you. 
- * This SDK gives you the application developer the ability to do so. 
- * There are two general kinds of advertisements, banners and interstitials. 
- * Banners are ads that occupy some part of the screen you choose and within whichever views you choose.  
- * Interstitials are ads that take the whole screen they are modal, they typically generate larger revenue
- * and are used for example between game levels, or when the application starts, it is your choice to decide where ad's will be visible.  
- *
+ * The AppNexus Mobile Advertising SDK
+ * 

+ * The source code is available for download from + * https://github.com/appnexus + *

+ *

+ * You can find more information about AppNexus at + * http://www.appnexus.com + *

+ *

+ * To monetize a free app you may choose to include advertising. + * Where, how, when and why are all up to you. This SDK gives you, + * the application developer, the ability to show ads. It also gives + * you complete control over where and when they will appear. + *

+ *

+ * There are two basic types of advertisements: banners and + * interstitials. Banner ads occupy some part of the screen you + * choose and within whichever views you choose. Interstitial ads + * take the whole screen: they are modal, they typically generate + * larger revenue. For example, they are typically used between game + * levels, or when the application starts. + *

*/ package com.appnexus.opensdk; From 4a71799bedb533bf0d7e378dd055fbd097628cda Mon Sep 17 00:00:00 2001 From: Ron Lissack Date: Mon, 25 Nov 2013 15:38:34 -0500 Subject: [PATCH 02/34] Cleanup xml description Documentation change --- sdk/src/com/appnexus/opensdk/BannerAdView.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/sdk/src/com/appnexus/opensdk/BannerAdView.java b/sdk/src/com/appnexus/opensdk/BannerAdView.java index d5a2a8473..1fdc26fb6 100644 --- a/sdk/src/com/appnexus/opensdk/BannerAdView.java +++ b/sdk/src/com/appnexus/opensdk/BannerAdView.java @@ -54,15 +54,15 @@ * android:layout_width="wrap_content" * android:layout_height="wrap_content" * android:placement_id="YOUR PLACEMENT ID" - * android:auto_refresh=true - * android:auto_refresh_interval=30 - * android:opens_native_browser=true - * android:adWidth=320 - * android:adHeight=50 - * android:should_reload_on_resume=true - * android:opens_native_browser=true - * android:expands_to_fit_screen_width=false - * />; + * android:auto_refresh="true" + * android:auto_refresh_interval="30" + * android:opens_native_browser="true" + * android:adWidth="320" + * android:adHeight="50" + * android:should_reload_on_resume="true" + * android:opens_native_browser="true" + * android:expands_to_fit_screen_width="false" + * /> * } *
* From b1d0c9984dffd36f44b175244ddbae128862ec73 Mon Sep 17 00:00:00 2001 From: Rich Loveland Date: Mon, 25 Nov 2013 17:33:21 -0500 Subject: [PATCH 03/34] Revised & updated docs in mediation-related files. --- .../opensdk/MediatedAdViewController.java | 85 +++++++++++++------ .../opensdk/MediatedBannerAdView.java | 73 +++++++++++----- .../MediatedBannerAdViewController.java | 14 +-- .../opensdk/MediatedInterstitialAdView.java | 62 +++++++++----- .../MediatedInterstitialAdViewController.java | 24 ++++-- 5 files changed, 177 insertions(+), 81 deletions(-) diff --git a/sdk/src/com/appnexus/opensdk/MediatedAdViewController.java b/sdk/src/com/appnexus/opensdk/MediatedAdViewController.java index bbbecbd08..2291e82d7 100644 --- a/sdk/src/com/appnexus/opensdk/MediatedAdViewController.java +++ b/sdk/src/com/appnexus/opensdk/MediatedAdViewController.java @@ -28,42 +28,51 @@ import com.appnexus.opensdk.utils.StringUtil; /** - * This class is the base of the Mediation controllers. It is used to implement external or 3rd party - * SDK mediation. Where the AppNexus SDK calls into other SDK's when commanded to do so via the - * AppNexus Network Manager. - * The mediation adaptors receives an object of this class and uses it to inform the AppNexus - * SDK of events from the 3rd party SDK. + *

+ * This is the base class for the AppNexus SDK's mediation + * controllers. It's used to implement external or third party SDK + * mediation. It determines where the AppNexus SDK calls into other + * SDKs when commanded to do so via the AppNexus Network Manager. + *

+ *

+ * The mediation adaptor receives an object of this class and uses it + * to inform the AppNexus SDK of events from the third party SDK. + *

*/ + public abstract class MediatedAdViewController implements Displayable { /** - * The results from mediation calls sent back to the AppNexusSDK in the onAdFailed method. - * + * This enum contains the results from mediation calls sent + * back to the AppNexus SDK in the onAdFailed + * method. */ public static enum RESULT { /** - * Return this if the ad successfully loaded + * Return this if the ad loaded successfully. */ SUCCESS, /** - * Return this if the ad request parameters or id were invalid + * Return this if the ad request parameters or placement ID + * were invalid. */ INVALID_REQUEST, /** - * Return this if the mediated network did not return an ad in this call. + * Return this if the mediated network did not return an ad in + * this call. */ UNABLE_TO_FILL, - /** - * Return if the underlying SDK is not available. + * Return this if the third-party SDK is not available. */ MEDIATED_SDK_UNAVAILABLE, /** - * A Network error caused no ad to be returned. + * Return this if a network error caused no ad to be returned. */ NETWORK_ERROR, /** - * Internal error detected in the underlying SDK. + * Return this if an Internal error is detected in the + * third-party SDK. */ INTERNAL_ERROR } @@ -102,10 +111,14 @@ public static enum RESULT { */ /** - * Validates all fields necessary for controller to function properly + * Validates all the fields necessary for the controller to + * function properly. + * + * @param callerClass The calling class that mAV (the + * MediatedAdView) should be an instance of. * - * @param callerClass the calling class that mAV should be an instance of - * @return true if the controller is valid, false if not. + * @return true if the controller is valid, + * false otherwise. */ @SuppressWarnings("rawtypes") boolean isValid(Class callerClass) { @@ -127,9 +140,10 @@ boolean isValid(Class callerClass) { } /** - * Attempts to instantiate currentAd + * Attempts to instantiate the currentAd. * - * @return true if instantiation was successful, false if not. + * @return true if instantiation was successful, + * false otherwise. */ private boolean instantiateNewMediatedAd() { Clog.d(Clog.mediationLogTag, Clog.getString( @@ -161,8 +175,13 @@ private void finishController() { } /** - * Call this method to inform that AppNexus SDK that an Ad from the 3rd party SDK - * has successfully loaded. This method should only be called once per requestAd call. + * Call this method to inform the AppNexus SDK that an ad from the + * third-party SDK has successfully loaded. This method should + * only be called once per requestAd call (see the + * implementations of requestAd for banners and + * interstitials in {@link MediatedBannerAdView} and {@link + * MediatedInterstitialAdView}). + * */ public void onAdLoaded() { if (hasSucceeded || hasFailed) return; @@ -175,9 +194,15 @@ public void onAdLoaded() { } /** - * Call this method to inform the AppNexus SDK than an ad call from the 3rd party SDK - * has failed to load an ad.This method should only be called once per requestedAd call. - * @param reason The reason for the failure. + * Call this method to inform the AppNexus SDK than an ad call + * from the third-party SDK has failed to load an ad. This method + * should only be called once per requestAd call (see + * the implementations of requestAd for banners and + * interstitials in {@link MediatedBannerAdView} and {@link + * MediatedInterstitialAdView}). + * + * @param reason The reason why the ad call from the third-party + * SDK failed. */ public void onAdFailed(MediatedAdViewController.RESULT reason) { if (hasSucceeded || hasFailed) return; @@ -191,8 +216,10 @@ public void onAdFailed(MediatedAdViewController.RESULT reason) { } /** - * Call this method to inform the AppNexus SDK that the ad has expanded its size. - * This is usually due to the user interacting with an expanding MRAID ad. + * Call this method to inform the AppNexus SDK that the ad has + * expanded from its original size. This is usually due to the + * user interacting with an expanding + * MRAID ad. */ public void onAdExpanded() { if (hasFailed) return; @@ -201,7 +228,8 @@ public void onAdExpanded() { } /** - * Call this method to inform the AppNexus SDK that the previous expansion has completed. + * Call this method to inform the AppNexus SDK that a previously + * expanded ad has now collapsed to its original size. */ public void onAdCollapsed() { if (hasFailed) return; @@ -210,7 +238,8 @@ public void onAdCollapsed() { } /** - * Call this method to inform the the AppNexus SDK that the user is interacting with the ad. + * Call this method to inform the the AppNexus SDK that the user + * is interacting with the ad (i.e., has clicked on it). */ public void onAdClicked() { if (hasFailed) return; diff --git a/sdk/src/com/appnexus/opensdk/MediatedBannerAdView.java b/sdk/src/com/appnexus/opensdk/MediatedBannerAdView.java index bdd065837..7f3f0be66 100644 --- a/sdk/src/com/appnexus/opensdk/MediatedBannerAdView.java +++ b/sdk/src/com/appnexus/opensdk/MediatedBannerAdView.java @@ -19,33 +19,60 @@ import android.view.View; /** - * The interface a mediation adaptor must implement for requesting banners. - * The mediation interface allows 3rd party SDK's to be called via the - * AppNexus SDK. To integrate a 3rd party SDK create a class that implements - * MediatedBannerAdView. Implement the required method and configure it within - * the AppNexus Network Manager to be called whenever the network targeting - * matches the conditions that are defined in Network Manager. - * - * + * This is the interface a mediation adaptor must implement for + * requesting banner ads. The mediation interface allows third-party + * SDKs to be called by the AppNexus SDK. To integrate a third-party + * SDK, create a class that implements + * MediatedBannerAdView. Implement the required method + * and configure it within the AppNexus Ad Network Manager to be + * called whenever the targeting matches the conditions defined in the + * Ad Network Manager. (The Ad Network Manager is a web application + * that AppNexus platform members can use to work with ad networks + * that are not on the platform.) */ + public interface MediatedBannerAdView extends MediatedAdView { + /** - * The AppNexus SDK will call this method to ask the 3rd party SDK to request an Ad - * from its network. The AppNexus SDK expects to be notified of events through the - * {@link MediatedBannerAdViewController} Note that once a requestAd call has been made - * the AppNexus SDK expects a onAdLoaded or onAdFailed called through the MediatedBannerAdViewController - * within 15 seconds or the mediation call is considered failed. + * The AppNexus SDK will call this method to ask the + * third-party SDK to request an ad from its network. The + * AppNexus SDK expects to be notified of events through the + * {@link MediatedBannerAdViewController}. Note that once a + * requestAd call has been made, the AppNexus SDK expects + * onAdLoaded or onAdFailed to be called through the {@link + * MediatedBannerAdViewController} within 15 seconds or the + * mediation call is considered to have failed. * - * @param mBC The controller to notify on load, failure etc. - * @param activity The activity from which this call was made. - * @param parameter An optional opaque string passed from Network Manager , this can be used to defined - * SDK specific parameters such as additional targeting information. The encoding of the contents of this - * string are entirely up to the implementation of the 3rd party SDK adaptor. - * @param uid The network ID for this ad call. This ID is opaque to the AppNexus SDK and its contents and their encoding - * are up to the implementation of the 3rd party SDK. - * @param width The width of the advertisement as defined in the {@link BannerAdView} object that initiated this call. - * @param height The height of the advertisement as defined in the {@link BannerAdView} object that initiated this call. - * @return A view that will be inserted into the BannerAdView that will hold the ad from the 3rd party SDK + * @param mBC The controller to notify on load, failure, etc. + * + * @param activity The activity from which this method was + * called. + * + * @param parameter An optional opaque string passed from the + * Ad Network Manager, this can be used to + * defined SDK-specific parameters such as + * additional targeting information. The + * encoding of the contents of this string + * are entirely up to the implementation of + * the third-party SDK adaptor. + * + * @param uid The network ID for this ad call. This ID is + * opaque to the AppNexus SDK and its contents and + * their encoding are up to the implementation of + * the third-party SDK. + * + * @param width The width of the advertisement in pixels as + * defined in the {@link BannerAdView} object + * that initiated this call. + * + * @param height The height of the advertisement in pixels as + * defined in the {@link BannerAdView} object + * that initiated this call. + * + * @return A view that will be inserted into the {@link + * BannerAdView} that will hold the ad from the + * third-party SDK. */ + public View requestAd(MediatedBannerAdViewController mBC, Activity activity, String parameter, String uid, int width, int height); } diff --git a/sdk/src/com/appnexus/opensdk/MediatedBannerAdViewController.java b/sdk/src/com/appnexus/opensdk/MediatedBannerAdViewController.java index 096e5bde6..47cb76a4f 100644 --- a/sdk/src/com/appnexus/opensdk/MediatedBannerAdViewController.java +++ b/sdk/src/com/appnexus/opensdk/MediatedBannerAdViewController.java @@ -20,11 +20,12 @@ import com.appnexus.opensdk.utils.Clog; /** - * An object of this type is sent to the 3rd party SDK's MediatedBannerAdView object. The 3rd party - * SDK uses this object from within its banner view implementation to send events back to the AppNexus - * SDK - * + * An object of this type is sent to the third-party SDK's {@link + * MediatedBannerAdView} object. The third-party SDK uses this object + * from within its banner view implementation to send events back to + * the AppNexus SDK. */ + public class MediatedBannerAdViewController extends MediatedAdViewController implements Displayable { private View placeableView; @@ -77,8 +78,9 @@ private MediatedBannerAdViewController( } /** - * Returns the Banner view of the underlying SDK. - * @return the mediated SDK's view. + * Get the banner ad view of the underlying third-party SDK. + * + * @return the third-party SDK's banner ad view. */ @Override public View getView() { diff --git a/sdk/src/com/appnexus/opensdk/MediatedInterstitialAdView.java b/sdk/src/com/appnexus/opensdk/MediatedInterstitialAdView.java index 6bbac7f5c..c55c12b8f 100644 --- a/sdk/src/com/appnexus/opensdk/MediatedInterstitialAdView.java +++ b/sdk/src/com/appnexus/opensdk/MediatedInterstitialAdView.java @@ -3,34 +3,58 @@ import android.app.Activity; /** - * This interface must be implemented by 3rd Party SDK's that which to have Interstitial views that are - * mediated by the AppNexus SDK. To integrate a 3rd party SDK create a class that implements - * MediatedInterstitialAdView. Implement the required methods and configure it within - * the AppNexus Network Manager to be called whenever the network targeting - * matches the conditions that are defined in Network Manager. - * + * This interface must be implemented by third-party SDKs whose + * interstitial views will be mediated by the AppNexus SDK. Implement + * the required methods and configure them within the AppNexus Ad + * Network Manager to be called whenever the targeting matches the + * conditions defined in the Ad Network Manager. (The Ad Network + * Manager is a web application that AppNexus platform members can use + * to work with ad networks that are not on the platform.) */ + public interface MediatedInterstitialAdView extends MediatedAdView { - /** - * The AppNexus SDK will call this method in your class when directed to do so from Network Manager. - * Where an application has instantiated an InterstitialAdView. - * @param mIC A controller through which the adapter must send events to the AppNexus SDK - * @param parameter An optional opaque string passed from Network Manager , this can be used to defined - * SDK specific parameters such as additional targeting information. The encoding of the contents of this - * string are entirely up to the implementation of the 3rd party SDK adaptor. - * @param uid The network ID for this ad call. This ID is opaque to the AppNexus SDK and its contents and their encoding - * are up to the implementation of the 3rd party SDK. */ + + /** + * The AppNexus SDK will call this method in your class when + * directed to do so from the Ad Network Manager, where an + * application has instantiated an {@link InterstitialAdView}. + * + * @param mIC A controller through which the adaptor must send + * events to the AppNexus SDK. + * + * @param parameter An optional opaque string passed from the Ad + * Network Manager, this can be used to define + * SDK-specific parameters such as additional + * targeting information. The encoding of the + * contents of this string are entirely up to the + * implementation of the third-party SDK adaptor. + * + * @param uid The network ID for this ad call. This ID is opaque + * to the AppNexus SDK; the ID's contents and their + * encoding are up to the implementation of the + * third-party SDK. + */ + public void requestAd(MediatedInterstitialAdViewController mIC, Activity activity, String parameter, String uid); /** - * The AppNexus SDK will call this method to show the interstitial view when the user has call - * InterstitialAdView.show() {@link InterstitialAdView} + * The AppNexus SDK will call this method to show the interstitial + * view when the user has called + * InterstitialAdView.show(). (See {@link + * InterstitialAdView}.) */ + public void show(); /** - * The AppNexus SDK will call this method to check if the interstitial view is ready when the user - * calls InterstitialAdView.isReady() {@link InterstitialAdView} + * The AppNexus SDK will call this method to check if the + * interstitial view is ready when the user calls + * InterstitialAdView.isReady(). (See {@link + * InterstitialAdView}.) + * + * @return true if the interstitial ad is ready to + * show, false otherwise. */ + public boolean isReady(); } diff --git a/sdk/src/com/appnexus/opensdk/MediatedInterstitialAdViewController.java b/sdk/src/com/appnexus/opensdk/MediatedInterstitialAdViewController.java index 75cfd2351..0ec8f9b99 100644 --- a/sdk/src/com/appnexus/opensdk/MediatedInterstitialAdViewController.java +++ b/sdk/src/com/appnexus/opensdk/MediatedInterstitialAdViewController.java @@ -20,11 +20,13 @@ import com.appnexus.opensdk.utils.Clog; /** -* An object of this type is sent to the 3rd party SDK's MediatedInterstitialAdView object. The 3rd party -* SDK uses this object from within its interstitial view implementation to send events back to the AppNexus -* SDK -* -*/public class MediatedInterstitialAdViewController extends MediatedAdViewController implements Displayable { +* An object of this type is sent to the third-party SDK's {@link +* MediatedInterstitialAdView} object. The third-party SDK uses this +* object from within its interstitial view implementation to send +* events back to the AppNexus SDK. +*/ + +public class MediatedInterstitialAdViewController extends MediatedAdViewController implements Displayable { private Activity activity; @@ -52,6 +54,18 @@ void show() { } } + /** + * Gets the interstitial ad view of the underlying third-party SDK + * and begins the process of fetching an interstitial ad in the + * background. Note that the ad will expire 60 seconds after + * being delivered from the server. In other words, if the user + * views or clicks the ad 60 seconds after it was initially + * fetched from the server, you will not get credit for that + * impression or click. + * + * @return the third-party SDK's view. + */ + @Override public View getView() { // if controller is valid, request an ad. From d8386fc479c41175ccae965841d69fd81e4c6964 Mon Sep 17 00:00:00 2001 From: Mark Ha Date: Wed, 4 Dec 2013 15:10:55 -0500 Subject: [PATCH 04/34] MS-124 remove retrying requests from SDK --- sdk/res/values/errors.xml | 3 +- sdk/src/com/appnexus/opensdk/AdFetcher.java | 5 - sdk/src/com/appnexus/opensdk/AdRequest.java | 147 ++++-------------- sdk/src/com/appnexus/opensdk/AdRequester.java | 7 - sdk/src/com/appnexus/opensdk/AdResponse.java | 14 +- .../com/appnexus/opensdk/utils/Settings.java | 4 - .../opensdk/stdtests/TestRetryAdRequest.java | 119 -------------- 7 files changed, 34 insertions(+), 265 deletions(-) delete mode 100644 tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestRetryAdRequest.java diff --git a/sdk/res/values/errors.xml b/sdk/res/values/errors.xml index 7b85259cd..68db442be 100644 --- a/sdk/res/values/errors.xml +++ b/sdk/res/values/errors.xml @@ -23,7 +23,7 @@ Request received no response from the server. Response body: %s Header: %s Value: %s - The server returned a blank 200 OK HTTP response. Unless the maximum retries have been reached, this request will be retried shortly. + The server returned a blank 200 OK HTTP response. E301: The server replied with an error: %s The server responded, but didn\'t return any ads. E300: There was an error parsing the JSON response: %s @@ -111,7 +111,6 @@ result cb returned a bad response firing result cb with null resultCB Cancelling scheduled request - Tried to execute a retry request that was cancelled MRAID resize() called with w:%d, h:%d, offset_x:%d, offset_y:%d, cust_close_position:%s, allow_offscreen:%b MRAID setOrientationProperties called with allow_orientation_change=%b, orientation=%d MRAID createCalendarEvent() called diff --git a/sdk/src/com/appnexus/opensdk/AdFetcher.java b/sdk/src/com/appnexus/opensdk/AdFetcher.java index 2b4afbe33..5bb45bf52 100644 --- a/sdk/src/com/appnexus/opensdk/AdFetcher.java +++ b/sdk/src/com/appnexus/opensdk/AdFetcher.java @@ -280,11 +280,6 @@ public AdView getOwner() { return owner; } - @Override - public void setAdRequest(AdRequest adRequest) { - this.adRequest = adRequest; - } - public void clearDurations() { lastFetchTime = -1; timePausedAt = -1; diff --git a/sdk/src/com/appnexus/opensdk/AdRequest.java b/sdk/src/com/appnexus/opensdk/AdRequest.java index 39ce3dcaf..0e130f738 100644 --- a/sdk/src/com/appnexus/opensdk/AdRequest.java +++ b/sdk/src/com/appnexus/opensdk/AdRequest.java @@ -35,6 +35,7 @@ import com.appnexus.opensdk.utils.Clog; import com.appnexus.opensdk.utils.HashingFunctions; import com.appnexus.opensdk.utils.Settings; +import com.appnexus.opensdk.utils.StringUtil; import org.apache.http.HttpResponse; import org.apache.http.StatusLine; import org.apache.http.client.ClientProtocolException; @@ -82,24 +83,13 @@ class AdRequest extends AsyncTask { private int height = -1; private int maxWidth = -1; private int maxHeight = -1; - private boolean shouldRetry = true; // true by default private float reserve = 0.00f; private String age; private String gender; private ArrayList> customKeywords; - - private final Handler retryHandler = new Handler(); - - private int httpRetriesLeft = 0; - private int blankRetriesLeft = 0; - private static final AdResponse HTTP_ERROR - = new AdResponse(true, false, false); - private static final AdResponse CONNECTIVITY_RETRY - = new AdResponse(false, true, false); - private static final AdResponse BLANK_RETRY - = new AdResponse(false, false, true); + = new AdResponse(true); /** * Creates a new AdRequest with the given parameters @@ -131,8 +121,6 @@ public AdRequest(AdRequester requester, String aid, String lat, String lon, AdListener adListener, boolean shouldServePSAs, boolean shouldRetry) { this.adListener = adListener; this.requester = requester; - this.httpRetriesLeft = Settings.getSettings().MAX_CONNECTIVITY_RETRIES; - this.blankRetriesLeft = Settings.getSettings().MAX_BLANK_RETRIES; if (aid != null) { hidmd5 = HashingFunctions.md5(aid); hidsha1 = HashingFunctions.sha1(aid); @@ -168,19 +156,11 @@ public AdRequest(AdRequester requester, String aid, String lat, String lon, this.psa = shouldServePSAs ? "1" : "0"; this.nativeBrowser = isNativeBrowser ? "1" : "0"; - - this.shouldRetry = shouldRetry; } public AdRequest(AdRequester adRequester) { - this(adRequester, Settings.getSettings().MAX_CONNECTIVITY_RETRIES, Settings.getSettings().MAX_BLANK_RETRIES); - } - - private AdRequest(AdRequester adRequester, int httpRetriesLeft, int blankRetriesLeft) { owner = adRequester.getOwner(); this.requester = adRequester; - this.httpRetriesLeft = httpRetriesLeft; - this.blankRetriesLeft = blankRetriesLeft; this.placementId = owner.getPlacementID(); context = owner.getContext(); String aid = android.provider.Settings.Secure.getString( @@ -334,24 +314,24 @@ String getRequestUrl() { } else { sb.append("NO-PLACEMENT-ID"); } - if (!isEmpty(hidmd5)) sb.append("&md5udid=").append(Uri.encode(hidmd5)); - if (!isEmpty(hidsha1)) sb.append("&sha1udid=").append(Uri.encode(hidsha1)); - if (!isEmpty(devMake)) sb.append("&devmake=").append(Uri.encode(devMake)); - if (!isEmpty(devModel)) sb.append("&devmodel=").append(Uri.encode(devModel)); - if (!isEmpty(carrier)) sb.append( "&carrier=").append(Uri.encode(carrier)); + if (!StringUtil.isEmpty(hidmd5)) sb.append("&md5udid=").append(Uri.encode(hidmd5)); + if (!StringUtil.isEmpty(hidsha1)) sb.append("&sha1udid=").append(Uri.encode(hidsha1)); + if (!StringUtil.isEmpty(devMake)) sb.append("&devmake=").append(Uri.encode(devMake)); + if (!StringUtil.isEmpty(devModel)) sb.append("&devmodel=").append(Uri.encode(devModel)); + if (!StringUtil.isEmpty(carrier)) sb.append( "&carrier=").append(Uri.encode(carrier)); sb.append("&appid="); - if (!isEmpty(Settings.getSettings().app_id)) { + if (!StringUtil.isEmpty(Settings.getSettings().app_id)) { sb.append(Uri.encode(Settings.getSettings().app_id)); } else { sb.append("NO-APP-ID"); } if (firstlaunch) sb.append("&firstlaunch=true"); - if (!isEmpty(lat) && !isEmpty(lon)) sb.append("&loc=").append(lat).append(",").append(lon); - if (!isEmpty(locDataAge)) sb.append("&loc_age=").append(locDataAge); - if (!isEmpty(locDataPrecision)) sb.append("&loc_prec=").append(locDataPrecision); + if (!StringUtil.isEmpty(lat) && !StringUtil.isEmpty(lon)) sb.append("&loc=").append(lat).append(",").append(lon); + if (!StringUtil.isEmpty(locDataAge)) sb.append("&loc_age=").append(locDataAge); + if (!StringUtil.isEmpty(locDataPrecision)) sb.append("&loc_prec=").append(locDataPrecision); if (Settings.getSettings().test_mode) sb.append("&istest=true"); - if (!isEmpty(ua)) sb.append("&ua=").append(Uri.encode(ua)); - if (!isEmpty(orientation)) sb.append("&orientation=").append(orientation); + if (!StringUtil.isEmpty(ua)) sb.append("&ua=").append(Uri.encode(ua)); + if (!StringUtil.isEmpty(orientation)) sb.append("&orientation=").append(orientation); if (width > 0 && height > 0) sb.append("&size=").append(width).append("x").append(height); // complicated, don't change if (owner != null) { @@ -364,18 +344,18 @@ String getRequestUrl() { } } } - if (!isEmpty(allowedSizes)) sb.append("&promo_sizes=").append(allowedSizes); - if (!isEmpty(mcc)) sb.append("&mcc=").append(Uri.encode(mcc)); - if (!isEmpty(mnc)) sb.append("&mnc=").append(Uri.encode(mnc)); - if (!isEmpty(language)) sb.append("&language=").append(Uri.encode(language)); - if (!isEmpty(dev_timezone)) sb.append("&devtz=").append(Uri.encode(dev_timezone)); - if (!isEmpty(dev_time)) sb.append("&devtime=").append(Uri.encode(dev_time)); - if (!isEmpty(connection_type)) sb.append("&connection_type=").append( Uri.encode(connection_type)); - if (!isEmpty(nativeBrowser)) sb.append("&native_browser=").append(nativeBrowser); - if (!isEmpty(psa)) sb.append( "&psa=").append(psa); + if (!StringUtil.isEmpty(allowedSizes)) sb.append("&promo_sizes=").append(allowedSizes); + if (!StringUtil.isEmpty(mcc)) sb.append("&mcc=").append(Uri.encode(mcc)); + if (!StringUtil.isEmpty(mnc)) sb.append("&mnc=").append(Uri.encode(mnc)); + if (!StringUtil.isEmpty(language)) sb.append("&language=").append(Uri.encode(language)); + if (!StringUtil.isEmpty(dev_timezone)) sb.append("&devtz=").append(Uri.encode(dev_timezone)); + if (!StringUtil.isEmpty(dev_time)) sb.append("&devtime=").append(Uri.encode(dev_time)); + if (!StringUtil.isEmpty(connection_type)) sb.append("&connection_type=").append( Uri.encode(connection_type)); + if (!StringUtil.isEmpty(nativeBrowser)) sb.append("&native_browser=").append(nativeBrowser); + if (!StringUtil.isEmpty(psa)) sb.append( "&psa=").append(psa); if (reserve>0) sb.append("&reserve=").append(reserve); - if (!isEmpty(age)) sb.append("&age=").append(Uri.encode(age)); - if (!isEmpty(gender)) sb.append("&gender=").append(Uri.encode(gender)); + if (!StringUtil.isEmpty(age)) sb.append("&age=").append(Uri.encode(age)); + if (!StringUtil.isEmpty(gender)) sb.append("&gender=").append(Uri.encode(gender)); sb.append("&format=json"); sb.append("&st=mobile_app"); sb.append("&sdkver=").append(Uri.encode(Settings.getSettings().sdkVersion)); @@ -383,7 +363,7 @@ String getRequestUrl() { // add custom parameters if there are any if (customKeywords != null) { for (Pair pair : customKeywords) { - if (!isEmpty(pair.first) && (pair.second != null)) { + if (!StringUtil.isEmpty(pair.first) && (pair.second != null)) { sb.append("&") .append(pair.first) .append("=") @@ -400,9 +380,6 @@ protected AdResponse doInBackground(Void... params) { if (!hasNetwork(context)) { Clog.e(Clog.httpReqLogTag, Clog.getString(R.string.no_connectivity)); - if (!shouldRetry) - return doRequest(); - return AdRequest.CONNECTIVITY_RETRY; } return doRequest(); @@ -434,18 +411,18 @@ private AdResponse doRequest() { out = EntityUtils.toString(r.getEntity()); } catch (ClientProtocolException e) { Clog.e(Clog.httpReqLogTag, Clog.getString(R.string.http_unknown)); - return AdRequest.CONNECTIVITY_RETRY; + return null; } catch (ConnectTimeoutException e) { Clog.e(Clog.httpReqLogTag, Clog.getString(R.string.http_timeout)); - return AdRequest.CONNECTIVITY_RETRY; + return null; } catch (HttpHostConnectException he) { Clog.e(Clog.httpReqLogTag, Clog.getString( R.string.http_unreachable, he.getHost().getHostName(), he .getHost().getPort())); - return AdRequest.CONNECTIVITY_RETRY; + return null; } catch (IOException e) { Clog.e(Clog.httpReqLogTag, Clog.getString(R.string.http_io)); - return AdRequest.CONNECTIVITY_RETRY; + return null; } catch (SecurityException se) { Clog.e(Clog.baseLogTag, Clog.getString(R.string.permissions_internet)); @@ -453,11 +430,11 @@ private AdResponse doRequest() { } catch (Exception e) { e.printStackTrace(); Clog.e(Clog.baseLogTag, Clog.getString(R.string.unknown_exception)); - return AdRequest.CONNECTIVITY_RETRY; + return null; } if (out.equals("")) { Clog.e(Clog.httpRespLogTag, Clog.getString(R.string.response_blank)); - return AdRequest.BLANK_RETRY; + return null; } return new AdResponse(out, r.getAllHeaders()); } @@ -493,12 +470,10 @@ private boolean httpShouldContinue(StatusLine statusLine) { @Override protected void onPostExecute(AdResponse result) { - if (requester != null) - requester.setAdRequest(null); + // check for invalid responses if (result == null) { Clog.v(Clog.httpRespLogTag, Clog.getString(R.string.no_response)); fail(); - // Don't call fail again! return; // http request failed } if (result.isHttpError()) { @@ -506,33 +481,6 @@ protected void onPostExecute(AdResponse result) { return; } - if (shouldRetry) { - if ((httpRetriesLeft < 1) || (blankRetriesLeft < 1)) { - // return if we have exceeded the max number of tries - fail(); - return; - } - boolean resultIsRetry = false; - - if (result.isConnectivityRetry()) { - httpRetriesLeft--; - resultIsRetry = true; - } else if (result.isBlankRetry()) { - blankRetriesLeft--; - resultIsRetry = true; - } - - if (resultIsRetry) { - // don't fail, but clear the last response - Clog.clearLastResponse(); - final AdRequest retry = new AdRequest(requester, httpRetriesLeft, blankRetriesLeft); - if (requester != null) - requester.setAdRequest(retry); - retry.retryHandler.postDelayed(new RetryRunnable(retry), Settings.getSettings().HTTP_RETRY_INTERVAL); - return; // The request failed and should be retried. - } - // else let it continue to process the valid result - } if (requester != null) requester.onReceiveResponse(result); // for unit testing @@ -544,37 +492,6 @@ protected void onPostExecute(AdResponse result) { protected void onCancelled(AdResponse adResponse) { super.onCancelled(adResponse); Clog.w(Clog.httpRespLogTag, Clog.getString(R.string.cancel_request)); - if (requester != null) - requester.setAdRequest(null); - // remove pending retry requests if the requester cancels the ad request - retryHandler.removeCallbacksAndMessages(null); - } - - private static boolean isEmpty(String str) { - return (str == null) || str.equals(""); - } - - class RetryRunnable implements Runnable { - final AdRequest retry; - - RetryRunnable(AdRequest retry) { - this.retry = retry; - } - - @Override - public void run() { - if (retry.isCancelled()) { - Clog.w(Clog.httpRespLogTag, Clog.getString(R.string.retry_already_cancelled)); - return; - } - - // Spawn an AdRequest - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { - retry.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } else { - retry.execute(); - } - } } // // Uncomment for unit tests diff --git a/sdk/src/com/appnexus/opensdk/AdRequester.java b/sdk/src/com/appnexus/opensdk/AdRequester.java index 57cf82314..65bbe1994 100644 --- a/sdk/src/com/appnexus/opensdk/AdRequester.java +++ b/sdk/src/com/appnexus/opensdk/AdRequester.java @@ -35,11 +35,4 @@ interface AdRequester { * Used to get the owner adview of the request */ public AdView getOwner(); - - /** - * Used to set inform the AdRequester which AdRequest is currently being run or pending - * - * @param adRequest the current ad request - */ - public void setAdRequest(AdRequest adRequest); } diff --git a/sdk/src/com/appnexus/opensdk/AdResponse.java b/sdk/src/com/appnexus/opensdk/AdResponse.java index 9978063a1..8c0935c0b 100644 --- a/sdk/src/com/appnexus/opensdk/AdResponse.java +++ b/sdk/src/com/appnexus/opensdk/AdResponse.java @@ -41,8 +41,6 @@ class AdResponse { private boolean containsAds = false; private boolean isHttpError = false; - private boolean isConnectivityRetry = false; - private boolean isBlankRetry = false; private static final String MRAID_JS_FILENAME = "mraid.js"; private static final String RESPONSE_KEY_STATUS = "status"; @@ -82,10 +80,8 @@ public AdResponse(HTTPResponse httpResponse) { parseResponse(httpResponse.getResponseBody()); } - public AdResponse(boolean isHttpError, boolean isConnectivityRetry, boolean isBlankRetry) { + public AdResponse(boolean isHttpError) { this.isHttpError = isHttpError; - this.isConnectivityRetry = isConnectivityRetry; - this.isBlankRetry = isBlankRetry; } private void printHeaders(Header[] headers) { @@ -233,14 +229,6 @@ public boolean isMraid() { return isMraid; } - public boolean isConnectivityRetry() { - return isConnectivityRetry; - } - - public boolean isBlankRetry() { - return isBlankRetry; - } - public boolean isHttpError() { return isHttpError; } diff --git a/sdk/src/com/appnexus/opensdk/utils/Settings.java b/sdk/src/com/appnexus/opensdk/utils/Settings.java index 9cc54b242..a1107fc7c 100644 --- a/sdk/src/com/appnexus/opensdk/utils/Settings.java +++ b/sdk/src/com/appnexus/opensdk/utils/Settings.java @@ -47,13 +47,9 @@ public class Settings { public final int MIN_REFRESH_MILLISECONDS = 15000; public final int DEFAULT_INTERSTITIAL_CLOSE_BUTTON_DELAY = 10000; - public /*final*/ long HTTP_RETRY_INTERVAL = 10000; public final long MEDIATED_NETWORK_TIMEOUT = 15000; - public final int MAX_BLANK_RETRIES = 1; - public final int MAX_CONNECTIVITY_RETRIES = 1; - public /*final*/ String BASE_URL = "http://mediation.adnxs.com/mob?"; public final String INSTALL_BASE_URL = "http://mediation.adnxs.com/install?"; diff --git a/tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestRetryAdRequest.java b/tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestRetryAdRequest.java deleted file mode 100644 index c2d111219..000000000 --- a/tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestRetryAdRequest.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright 2013 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.stdtests; - -import android.test.AndroidTestCase; -import com.appnexus.opensdk.*; -import com.appnexus.opensdk.utils.Clog; -import com.appnexus.opensdk.utils.Settings; -import com.appnexus.opensdk.util.InstanceLock; -import com.appnexus.opensdk.util.TestUtil; - -public class TestRetryAdRequest extends AndroidTestCase implements AdRequester { - /** - * Make sure permissions are set up in test_app's AndroidManifest.xml file for wifi+data access and change - * - * Also make sure AdRequest has setContext() uncommented, and uncomment the code here - */ - - String settingsURL; - long settingsInterval; - AdRequest request; - boolean didFail = false; - boolean didSucceed = false; - InstanceLock lock; - int timesRetried = 0; - AdView adView; - - String placementId = "17"; - - protected void setUp() throws Exception { - super.setUp(); - Clog.w(TestUtil.testLogTag, "Testing Retries"); - settingsURL = Settings.getSettings().BASE_URL; - settingsInterval = Settings.getSettings().HTTP_RETRY_INTERVAL; - Settings.getSettings().HTTP_RETRY_INTERVAL = TestUtil.SHORT_RETRY_INTERVAL; - request = new AdRequest(this, "123456", null, null, placementId, "portrait", "AT&T", - 320, 50, 320, 50, null, null, "wifi", false, null, true, true); - lock = new InstanceLock(); - timesRetried = 0; - adView = new BannerAdView(getContext()); - adView.setPlacementID(placementId); - -// request.setContext(getContext()); - TestUtil.setWifi(true, getContext()); - TestUtil.setData(true, getContext()); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - TestUtil.setWifi(true, getContext()); - TestUtil.setData(true, getContext()); - } - - public void testBlankRetries() { - request.execute(); - long retryTime = Settings.getSettings().HTTP_RETRY_INTERVAL * Settings.getSettings().MAX_BLANK_RETRIES; - lock.pause(10000 + retryTime); - request.cancel(true); - - assertFalse(didSucceed); - assertTrue(didFail); - assertEquals(Settings.getSettings().MAX_BLANK_RETRIES, timesRetried); - } - - public void testConnectivityRetries() { - TestUtil.setWifi(false, getContext()); - TestUtil.setData(false, getContext()); - - request.execute(); - long retryTime = Settings.getSettings().HTTP_RETRY_INTERVAL * Settings.getSettings().MAX_CONNECTIVITY_RETRIES; - lock.pause(10000 + retryTime); - request.cancel(true); - - assertFalse(didSucceed); - assertTrue(didFail); - assertEquals(Settings.getSettings().MAX_CONNECTIVITY_RETRIES, timesRetried); - } - - @Override - public void onReceiveResponse(AdResponse response) { - didSucceed = true; - if (lock != null) - lock.unpause(); - } - - @Override - public AdView getOwner() { - return adView; - } - - @Override - public void setAdRequest(AdRequest adRequest) { - // ignore deallocation calls - if (adRequest != null) - timesRetried++; - } - - @Override - public void failed(AdRequest request) { - didFail = true; - if (lock != null) - lock.unpause(); - } -} From 7b687867dfe7ba7167f3ba7bcd9abb04d2937392 Mon Sep 17 00:00:00 2001 From: Mark Ha Date: Wed, 4 Dec 2013 15:34:41 -0500 Subject: [PATCH 05/34] MS-124 unit tests updates, move package --- .../opensdk/{mediationtests => }/Test404Error.java | 9 +++------ .../{mediationtests => }/TestActivity404Error.java | 2 +- .../TestActivityMediationCallbacks.java | 2 +- .../TestActivityMediationWaterfall.java | 2 +- .../TestActivityRefreshStdThenMediated.java | 2 +- .../opensdk/{stdtests => }/TestClogListener.java | 2 +- .../opensdk/{stdtests => }/TestFailingAdRequest.java | 6 +----- .../opensdk/{stdtests => }/TestHashingFunctions.java | 2 +- .../opensdk/{mediationtests => }/TestMediationBasic.java | 8 ++------ .../TestMediationSuccessThenStd.java | 8 ++------ .../{stdtests => }/TestShortestSuccessfulAdRequest.java | 6 +----- .../opensdk/{stdtests => }/TestSuccessfulAdRequest.java | 6 +----- .../appnexus/opensdk/{stdtests => }/TestVisibility.java | 2 +- 13 files changed, 17 insertions(+), 40 deletions(-) rename tests/test_sdk/src/com/appnexus/opensdk/{mediationtests => }/Test404Error.java (95%) rename tests/test_sdk/src/com/appnexus/opensdk/{mediationtests => }/TestActivity404Error.java (98%) rename tests/test_sdk/src/com/appnexus/opensdk/{mediationtests => }/TestActivityMediationCallbacks.java (99%) rename tests/test_sdk/src/com/appnexus/opensdk/{mediationtests => }/TestActivityMediationWaterfall.java (99%) rename tests/test_sdk/src/com/appnexus/opensdk/{mediationtests => }/TestActivityRefreshStdThenMediated.java (98%) rename tests/test_sdk/src/com/appnexus/opensdk/{stdtests => }/TestClogListener.java (99%) rename tests/test_sdk/src/com/appnexus/opensdk/{stdtests => }/TestFailingAdRequest.java (96%) rename tests/test_sdk/src/com/appnexus/opensdk/{stdtests => }/TestHashingFunctions.java (97%) rename tests/test_sdk/src/com/appnexus/opensdk/{mediationtests => }/TestMediationBasic.java (96%) rename tests/test_sdk/src/com/appnexus/opensdk/{mediationtests => }/TestMediationSuccessThenStd.java (96%) rename tests/test_sdk/src/com/appnexus/opensdk/{stdtests => }/TestShortestSuccessfulAdRequest.java (96%) rename tests/test_sdk/src/com/appnexus/opensdk/{stdtests => }/TestSuccessfulAdRequest.java (96%) rename tests/test_sdk/src/com/appnexus/opensdk/{stdtests => }/TestVisibility.java (98%) diff --git a/tests/test_sdk/src/com/appnexus/opensdk/mediationtests/Test404Error.java b/tests/test_sdk/src/com/appnexus/opensdk/Test404Error.java similarity index 95% rename from tests/test_sdk/src/com/appnexus/opensdk/mediationtests/Test404Error.java rename to tests/test_sdk/src/com/appnexus/opensdk/Test404Error.java index 7f8603efe..83a05b619 100644 --- a/tests/test_sdk/src/com/appnexus/opensdk/mediationtests/Test404Error.java +++ b/tests/test_sdk/src/com/appnexus/opensdk/Test404Error.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.appnexus.opensdk.mediationtests; +package com.appnexus.opensdk; import android.test.AndroidTestCase; import com.appnexus.opensdk.*; @@ -70,7 +70,7 @@ public void testSuccessWithResult404() { assertTrue(receivedResponse); assertEquals(true, SuccessfulMediationView.didPass); - assertTrue(responseWasNull); + // responses from a successful result_cb no longer get passed back up, so can't check } public void testFailWithResult404() { @@ -97,7 +97,7 @@ public void failed(AdRequest request) { @Override public void onReceiveResponse(AdResponse response) { - // response should be a regular valid mediatied ad + // response should be a regular valid mediated ad Clog.d(TestUtil.testLogTag, "received response: " + response); if (response != null && response.getMediatedAds() != null) { MediatedBannerAdViewController output = MediatedBannerAdViewController.create( @@ -116,7 +116,4 @@ public AdView getOwner() { return null; } - @Override - public void setAdRequest(AdRequest adRequest) { - } } diff --git a/tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestActivity404Error.java b/tests/test_sdk/src/com/appnexus/opensdk/TestActivity404Error.java similarity index 98% rename from tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestActivity404Error.java rename to tests/test_sdk/src/com/appnexus/opensdk/TestActivity404Error.java index be6313dcb..57440a4a0 100644 --- a/tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestActivity404Error.java +++ b/tests/test_sdk/src/com/appnexus/opensdk/TestActivity404Error.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.appnexus.opensdk.mediationtests; +package com.appnexus.opensdk; import android.test.ActivityInstrumentationTestCase2; import com.appnexus.opensdk.AdListener; diff --git a/tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestActivityMediationCallbacks.java b/tests/test_sdk/src/com/appnexus/opensdk/TestActivityMediationCallbacks.java similarity index 99% rename from tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestActivityMediationCallbacks.java rename to tests/test_sdk/src/com/appnexus/opensdk/TestActivityMediationCallbacks.java index 723592804..d878d27c5 100644 --- a/tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestActivityMediationCallbacks.java +++ b/tests/test_sdk/src/com/appnexus/opensdk/TestActivityMediationCallbacks.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.appnexus.opensdk.mediationtests; +package com.appnexus.opensdk; import android.test.ActivityInstrumentationTestCase2; import com.appnexus.opensdk.AdListener; diff --git a/tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestActivityMediationWaterfall.java b/tests/test_sdk/src/com/appnexus/opensdk/TestActivityMediationWaterfall.java similarity index 99% rename from tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestActivityMediationWaterfall.java rename to tests/test_sdk/src/com/appnexus/opensdk/TestActivityMediationWaterfall.java index dcbdcc0fe..7589e5476 100644 --- a/tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestActivityMediationWaterfall.java +++ b/tests/test_sdk/src/com/appnexus/opensdk/TestActivityMediationWaterfall.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.appnexus.opensdk.mediationtests; +package com.appnexus.opensdk; import android.test.ActivityInstrumentationTestCase2; import com.appnexus.opensdk.AdListener; diff --git a/tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestActivityRefreshStdThenMediated.java b/tests/test_sdk/src/com/appnexus/opensdk/TestActivityRefreshStdThenMediated.java similarity index 98% rename from tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestActivityRefreshStdThenMediated.java rename to tests/test_sdk/src/com/appnexus/opensdk/TestActivityRefreshStdThenMediated.java index 8930a6c9c..74397e21f 100644 --- a/tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestActivityRefreshStdThenMediated.java +++ b/tests/test_sdk/src/com/appnexus/opensdk/TestActivityRefreshStdThenMediated.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.appnexus.opensdk.mediationtests; +package com.appnexus.opensdk; import android.test.ActivityInstrumentationTestCase2; import android.view.View; diff --git a/tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestClogListener.java b/tests/test_sdk/src/com/appnexus/opensdk/TestClogListener.java similarity index 99% rename from tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestClogListener.java rename to tests/test_sdk/src/com/appnexus/opensdk/TestClogListener.java index eaaa8f5a8..1ee296122 100644 --- a/tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestClogListener.java +++ b/tests/test_sdk/src/com/appnexus/opensdk/TestClogListener.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.appnexus.opensdk.stdtests; +package com.appnexus.opensdk; import android.util.Log; import com.appnexus.opensdk.utils.Clog; diff --git a/tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestFailingAdRequest.java b/tests/test_sdk/src/com/appnexus/opensdk/TestFailingAdRequest.java similarity index 96% rename from tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestFailingAdRequest.java rename to tests/test_sdk/src/com/appnexus/opensdk/TestFailingAdRequest.java index 9f3dde9be..56cc9637d 100644 --- a/tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestFailingAdRequest.java +++ b/tests/test_sdk/src/com/appnexus/opensdk/TestFailingAdRequest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.appnexus.opensdk.stdtests; +package com.appnexus.opensdk; import com.appnexus.opensdk.*; import junit.framework.TestCase; @@ -70,10 +70,6 @@ public AdView getOwner() { return null; } - @Override - public void setAdRequest(AdRequest adRequest) { - } - @Override synchronized public void failed(AdRequest request) { shouldPass = true; diff --git a/tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestHashingFunctions.java b/tests/test_sdk/src/com/appnexus/opensdk/TestHashingFunctions.java similarity index 97% rename from tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestHashingFunctions.java rename to tests/test_sdk/src/com/appnexus/opensdk/TestHashingFunctions.java index 16a257f7b..8292138f2 100644 --- a/tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestHashingFunctions.java +++ b/tests/test_sdk/src/com/appnexus/opensdk/TestHashingFunctions.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.appnexus.opensdk.stdtests; +package com.appnexus.opensdk; import com.appnexus.opensdk.utils.HashingFunctions; import junit.framework.TestCase; diff --git a/tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestMediationBasic.java b/tests/test_sdk/src/com/appnexus/opensdk/TestMediationBasic.java similarity index 96% rename from tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestMediationBasic.java rename to tests/test_sdk/src/com/appnexus/opensdk/TestMediationBasic.java index 6b5ba9cab..8f4988398 100644 --- a/tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestMediationBasic.java +++ b/tests/test_sdk/src/com/appnexus/opensdk/TestMediationBasic.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.appnexus.opensdk.mediationtests; +package com.appnexus.opensdk; import android.test.AndroidTestCase; import com.appnexus.opensdk.*; @@ -53,7 +53,7 @@ protected void setUp() throws Exception { synchronized protected void tearDown() throws Exception { wait(1000); if ((SuccessfulMediationView.didPass && SecondSuccessfulMediationView.didPass && ThirdSuccessfulMediationView.didPass) - || (NoSDK.didPass && ThirdSuccessfulMediationView.didPass)) + || (NoSDK.didPass && ThirdSuccessfulMediationView.didPass)) Clog.w(TestUtil.testLogTag, "TEST PASSED #" + placementId); Settings.getSettings().BASE_URL = oldUrl; super.tearDown(); @@ -157,8 +157,4 @@ public void onReceiveResponse(AdResponse response) { public AdView getOwner() { return null; } - - @Override - public void setAdRequest(AdRequest adRequest) { - } } \ No newline at end of file diff --git a/tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestMediationSuccessThenStd.java b/tests/test_sdk/src/com/appnexus/opensdk/TestMediationSuccessThenStd.java similarity index 96% rename from tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestMediationSuccessThenStd.java rename to tests/test_sdk/src/com/appnexus/opensdk/TestMediationSuccessThenStd.java index 0416c2e4e..ece88167f 100644 --- a/tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestMediationSuccessThenStd.java +++ b/tests/test_sdk/src/com/appnexus/opensdk/TestMediationSuccessThenStd.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.appnexus.opensdk.mediationtests; +package com.appnexus.opensdk; import android.test.AndroidTestCase; import com.appnexus.opensdk.*; @@ -89,14 +89,10 @@ public AdView getOwner() { return null; } - @Override - public void setAdRequest(AdRequest adRequest) { - } - synchronized private void pause() { Clog.d(TestUtil.testLogTag, "pausing"); try { - wait(); + wait(10000); } catch (InterruptedException e) { e.printStackTrace(); shouldWork.cancel(true); diff --git a/tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestShortestSuccessfulAdRequest.java b/tests/test_sdk/src/com/appnexus/opensdk/TestShortestSuccessfulAdRequest.java similarity index 96% rename from tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestShortestSuccessfulAdRequest.java rename to tests/test_sdk/src/com/appnexus/opensdk/TestShortestSuccessfulAdRequest.java index 709e49686..b466ff8c8 100644 --- a/tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestShortestSuccessfulAdRequest.java +++ b/tests/test_sdk/src/com/appnexus/opensdk/TestShortestSuccessfulAdRequest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.appnexus.opensdk.stdtests; +package com.appnexus.opensdk; import com.appnexus.opensdk.*; import junit.framework.TestCase; @@ -58,10 +58,6 @@ public AdView getOwner() { return null; } - @Override - public void setAdRequest(AdRequest adRequest) { - } - @Override synchronized public void failed(AdRequest request) { shouldWorkDidWork = false; diff --git a/tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestSuccessfulAdRequest.java b/tests/test_sdk/src/com/appnexus/opensdk/TestSuccessfulAdRequest.java similarity index 96% rename from tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestSuccessfulAdRequest.java rename to tests/test_sdk/src/com/appnexus/opensdk/TestSuccessfulAdRequest.java index a679c10fd..bef85c964 100644 --- a/tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestSuccessfulAdRequest.java +++ b/tests/test_sdk/src/com/appnexus/opensdk/TestSuccessfulAdRequest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.appnexus.opensdk.stdtests; +package com.appnexus.opensdk; import com.appnexus.opensdk.*; import junit.framework.TestCase; @@ -58,10 +58,6 @@ public AdView getOwner() { return null; } - @Override - public void setAdRequest(AdRequest adRequest) { - } - @Override synchronized public void failed(AdRequest request) { shouldWorkDidWork = false; diff --git a/tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestVisibility.java b/tests/test_sdk/src/com/appnexus/opensdk/TestVisibility.java similarity index 98% rename from tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestVisibility.java rename to tests/test_sdk/src/com/appnexus/opensdk/TestVisibility.java index 684b9542c..9a8367912 100644 --- a/tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestVisibility.java +++ b/tests/test_sdk/src/com/appnexus/opensdk/TestVisibility.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.appnexus.opensdk.stdtests; +package com.appnexus.opensdk; import android.test.ActivityInstrumentationTestCase2; import android.view.View; From cabdf78a2ddf7a0d67a9d35a05f07b466f5328c0 Mon Sep 17 00:00:00 2001 From: Mark Ha Date: Fri, 6 Dec 2013 12:45:48 -0500 Subject: [PATCH 06/34] MS-397 updating debug auction in app to show device info. --- .../src/com/appnexus/opensdkapp/DebugFragment.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/anx_sdk_app/src/com/appnexus/opensdkapp/DebugFragment.java b/examples/anx_sdk_app/src/com/appnexus/opensdkapp/DebugFragment.java index 76432a018..4ca404fc3 100644 --- a/examples/anx_sdk_app/src/com/appnexus/opensdkapp/DebugFragment.java +++ b/examples/anx_sdk_app/src/com/appnexus/opensdkapp/DebugFragment.java @@ -19,6 +19,7 @@ import android.app.AlertDialog; import android.content.ActivityNotFoundException; import android.content.Intent; +import android.net.Uri; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; @@ -40,6 +41,8 @@ import org.json.JSONException; import org.json.JSONObject; +import java.net.URI; + public class DebugFragment extends Fragment { TextView txtRequest, txtResponse; @@ -235,13 +238,14 @@ public String getUrl() { params.append("&debug_member=").append(Prefs.getMemberId(getActivity())); params.append("&dongle=").append(Prefs.getDongle(getActivity())); params.append("&size=").append(Prefs.getSize(getActivity())); + params.append("&psa=").append(Prefs.getAllowPSAs(getActivity()) ? "1" : "0"); + params.append("&ua=").append(Uri.encode(webView.getSettings().getUserAgentString())); return Constants.DEBUG_AUCTION_URL + params.toString(); } public void runAuction() { final String debugAuctionUrl = getUrl(); Clog.d(Constants.BASE_LOG_TAG, "Running a Debug Auction: " + debugAuctionUrl); -// loadUrl(debugAuctionUrl); final HTTPGet auctionGet = new HTTPGet() { @Override From 8b74028cebb59bf5c6a4813fa27fde0d33396290 Mon Sep 17 00:00:00 2001 From: Mark Ha Date: Mon, 9 Dec 2013 14:55:40 -0500 Subject: [PATCH 07/34] MS-124 return null for no network or context case. --- sdk/src/com/appnexus/opensdk/AdRequest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/src/com/appnexus/opensdk/AdRequest.java b/sdk/src/com/appnexus/opensdk/AdRequest.java index 0e130f738..084e85cd0 100644 --- a/sdk/src/com/appnexus/opensdk/AdRequest.java +++ b/sdk/src/com/appnexus/opensdk/AdRequest.java @@ -380,6 +380,7 @@ protected AdResponse doInBackground(Void... params) { if (!hasNetwork(context)) { Clog.e(Clog.httpReqLogTag, Clog.getString(R.string.no_connectivity)); + return null; } return doRequest(); From 55063b79505e19a3d519369177deb92c43425251 Mon Sep 17 00:00:00 2001 From: Mark Ha Date: Mon, 9 Dec 2013 16:25:11 -0500 Subject: [PATCH 08/34] MS-385 make display protected in InterstitialAdView to hide from javadoc --- sdk/src/com/appnexus/opensdk/AdView.java | 2 +- sdk/src/com/appnexus/opensdk/InterstitialAdView.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/src/com/appnexus/opensdk/AdView.java b/sdk/src/com/appnexus/opensdk/AdView.java index 1cd2455f5..324ddcfd3 100644 --- a/sdk/src/com/appnexus/opensdk/AdView.java +++ b/sdk/src/com/appnexus/opensdk/AdView.java @@ -463,7 +463,7 @@ public boolean getShouldServePSAs() { /** * Allows overriding the platform behavior in the case there is no ad * currently available. If set to true the platform will retrieve and - * displaya PSA (Public Service Announcement) . Set the value to false it + * display a PSA (Public Service Announcement) . Set the value to false it * will return no ad. * * @param shouldServePSAs diff --git a/sdk/src/com/appnexus/opensdk/InterstitialAdView.java b/sdk/src/com/appnexus/opensdk/InterstitialAdView.java index fa376d334..f4a20cf3c 100644 --- a/sdk/src/com/appnexus/opensdk/InterstitialAdView.java +++ b/sdk/src/com/appnexus/opensdk/InterstitialAdView.java @@ -190,7 +190,7 @@ public boolean loadAd() { } @Override - public void display(Displayable d) { + void display(Displayable d) { if (d == null) { fail(); return; From f4da24828504b648edb9ef49bb324c885494cb7b Mon Sep 17 00:00:00 2001 From: Mark Ha Date: Mon, 9 Dec 2013 18:19:35 -0500 Subject: [PATCH 09/34] MS-386 refactored mediation to create private displayable object, hide inner classes from javadoc --- sdk/src/com/appnexus/opensdk/AdFetcher.java | 4 +- .../opensdk/MediatedAdViewController.java | 25 +++-------- .../MediatedBannerAdViewController.java | 19 ++------ .../appnexus/opensdk/MediatedDisplayable.java | 43 +++++++++++++++++++ .../MediatedInterstitialAdViewController.java | 24 +++-------- 5 files changed, 61 insertions(+), 54 deletions(-) create mode 100644 sdk/src/com/appnexus/opensdk/MediatedDisplayable.java diff --git a/sdk/src/com/appnexus/opensdk/AdFetcher.java b/sdk/src/com/appnexus/opensdk/AdFetcher.java index 5bb45bf52..5e6c6d960 100644 --- a/sdk/src/com/appnexus/opensdk/AdFetcher.java +++ b/sdk/src/com/appnexus/opensdk/AdFetcher.java @@ -245,13 +245,11 @@ public void run() { owner.popMediatedAd(), owner.getAdDispatcher()); } else if (owner.isInterstitial()) { - MediatedInterstitialAdViewController output = MediatedInterstitialAdViewController.create( + MediatedInterstitialAdViewController.create( (Activity) owner.getContext(), owner.mAdFetcher, owner.popMediatedAd(), owner.getAdDispatcher()); - if (output != null) - output.getView(); } } else if ((response != null) && response.isMraid()) { diff --git a/sdk/src/com/appnexus/opensdk/MediatedAdViewController.java b/sdk/src/com/appnexus/opensdk/MediatedAdViewController.java index bbbecbd08..15b98b174 100644 --- a/sdk/src/com/appnexus/opensdk/MediatedAdViewController.java +++ b/sdk/src/com/appnexus/opensdk/MediatedAdViewController.java @@ -34,7 +34,7 @@ * The mediation adaptors receives an object of this class and uses it to inform the AppNexus * SDK of events from the 3rd party SDK. */ -public abstract class MediatedAdViewController implements Displayable { +public abstract class MediatedAdViewController { /** * The results from mediation calls sent back to the AppNexusSDK in the onAdFailed method. @@ -73,9 +73,10 @@ public static enum RESULT { private AdRequester requester; protected MediatedAd currentAd; private AdViewListener listener; + protected MediatedDisplayable mediatedDisplayable = new MediatedDisplayable(this); - private boolean hasFailed = false; - private boolean hasSucceeded = false; + boolean hasFailed = false; + boolean hasSucceeded = false; MediatedAdViewController(AdRequester requester, MediatedAd currentAd, AdViewListener listener) { this.requester = requester; @@ -152,7 +153,7 @@ private boolean instantiateNewMediatedAd() { return false; } - private void finishController() { + void finishController() { mAV = null; requester = null; currentAd = null; @@ -170,7 +171,7 @@ public void onAdLoaded() { hasSucceeded = true; if (listener != null) - listener.onAdLoaded(this); + listener.onAdLoaded(mediatedDisplayable); fireResultCB(RESULT.SUCCESS); } @@ -218,20 +219,6 @@ public void onAdClicked() { listener.onAdClicked(); } - /* - Overridden Displayable methods - */ - - @Override - public boolean failed() { - return hasFailed; - } - - @Override - public void destroy() { - finishController(); - } - /* Result CB Code */ diff --git a/sdk/src/com/appnexus/opensdk/MediatedBannerAdViewController.java b/sdk/src/com/appnexus/opensdk/MediatedBannerAdViewController.java index 096e5bde6..c4889ceb3 100644 --- a/sdk/src/com/appnexus/opensdk/MediatedBannerAdViewController.java +++ b/sdk/src/com/appnexus/opensdk/MediatedBannerAdViewController.java @@ -25,15 +25,13 @@ * SDK * */ -public class MediatedBannerAdViewController extends MediatedAdViewController implements Displayable { - - private View placeableView; +public class MediatedBannerAdViewController extends MediatedAdViewController { static MediatedBannerAdViewController create( Activity activity, AdRequester requester, MediatedAd mediatedAd, AdViewListener listener) { MediatedBannerAdViewController out = new MediatedBannerAdViewController(activity, requester, mediatedAd, listener); - return out.failed() ? null : out; + return out.hasFailed ? null : out; } private MediatedBannerAdViewController( @@ -51,7 +49,7 @@ private MediatedBannerAdViewController( startTimeout(); try { - placeableView = ((MediatedBannerAdView) mAV).requestAd(this, + mediatedDisplayable.view = ((MediatedBannerAdView) mAV).requestAd(this, activity, currentAd.getParam(), currentAd.getId(), @@ -66,7 +64,7 @@ private MediatedBannerAdViewController( errorCode = RESULT.MEDIATED_SDK_UNAVAILABLE; } - if (placeableView == null) { + if (mediatedDisplayable.view == null) { Clog.e(Clog.mediationLogTag, Clog.getString(R.string.mediated_view_null)); errorCode = RESULT.UNABLE_TO_FILL; } @@ -75,13 +73,4 @@ private MediatedBannerAdViewController( onAdFailed(errorCode); } } - - /** - * Returns the Banner view of the underlying SDK. - * @return the mediated SDK's view. - */ - @Override - public View getView() { - return placeableView; - } } diff --git a/sdk/src/com/appnexus/opensdk/MediatedDisplayable.java b/sdk/src/com/appnexus/opensdk/MediatedDisplayable.java new file mode 100644 index 000000000..84970e090 --- /dev/null +++ b/sdk/src/com/appnexus/opensdk/MediatedDisplayable.java @@ -0,0 +1,43 @@ +/* + * Copyright 2013 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; + +import android.view.View; + +class MediatedDisplayable implements Displayable { + View view; + MediatedAdViewController mAVC; + + MediatedDisplayable(MediatedAdViewController mAVC) { + this.mAVC = mAVC; + } + + @Override + public View getView() { + return view; + } + + @Override + public boolean failed() { + return mAVC.hasFailed; + } + + @Override + public void destroy() { + mAVC.finishController(); + } +} diff --git a/sdk/src/com/appnexus/opensdk/MediatedInterstitialAdViewController.java b/sdk/src/com/appnexus/opensdk/MediatedInterstitialAdViewController.java index 75cfd2351..64ed9e6ac 100644 --- a/sdk/src/com/appnexus/opensdk/MediatedInterstitialAdViewController.java +++ b/sdk/src/com/appnexus/opensdk/MediatedInterstitialAdViewController.java @@ -24,15 +24,13 @@ * SDK uses this object from within its interstitial view implementation to send events back to the AppNexus * SDK * -*/public class MediatedInterstitialAdViewController extends MediatedAdViewController implements Displayable { - - private Activity activity; +*/public class MediatedInterstitialAdViewController extends MediatedAdViewController { static MediatedInterstitialAdViewController create( Activity activity, AdRequester requester, MediatedAd mediatedAd, AdViewListener listener) { MediatedInterstitialAdViewController out = new MediatedInterstitialAdViewController(activity, requester, mediatedAd, listener); - return out.failed() ? null : out; + return out.hasFailed ? null : out; } private MediatedInterstitialAdViewController( @@ -43,19 +41,7 @@ private MediatedInterstitialAdViewController( if (!isValid(MediatedInterstitialAdView.class)) return; - this.activity = activity; - } - - void show() { - if (mAV != null) { - ((MediatedInterstitialAdView) mAV).show(); - } - } - - @Override - public View getView() { // if controller is valid, request an ad. - // create() will never return a non-null, invalid controller Clog.d(Clog.mediationLogTag, Clog.getString(R.string.mediated_request)); RESULT errorCode = null; @@ -77,8 +63,12 @@ public View getView() { if (errorCode != null) onAdFailed(errorCode); + } - return null; + void show() { + if (mAV != null) { + ((MediatedInterstitialAdView) mAV).show(); + } } boolean isReady() { From f1846ff22a3bd3042cda6ecb2c68b983aa228f3d Mon Sep 17 00:00:00 2001 From: Mark Ha Date: Mon, 9 Dec 2013 18:28:39 -0500 Subject: [PATCH 10/34] MS-386 update interstitials for new MediatedDisplayable --- .../appnexus/opensdk/InterstitialAdView.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/sdk/src/com/appnexus/opensdk/InterstitialAdView.java b/sdk/src/com/appnexus/opensdk/InterstitialAdView.java index f4a20cf3c..9c440571d 100644 --- a/sdk/src/com/appnexus/opensdk/InterstitialAdView.java +++ b/sdk/src/com/appnexus/opensdk/InterstitialAdView.java @@ -242,9 +242,12 @@ public boolean isReady() { long now = System.currentTimeMillis(); if (removeStaleAds(now)) { Pair top = InterstitialAdView.q.peek(); - if (top != null && top.second instanceof MediatedInterstitialAdViewController) { - MediatedInterstitialAdViewController mAVC = (MediatedInterstitialAdViewController) top.second; - return mAVC.isReady(); + if (top != null && top.second instanceof MediatedDisplayable) { + MediatedDisplayable mediatedDisplayable = (MediatedDisplayable) top.second; + if (mediatedDisplayable.mAVC instanceof MediatedInterstitialAdViewController) { + MediatedInterstitialAdViewController mAVC = (MediatedInterstitialAdViewController) mediatedDisplayable.mAVC; + return mAVC.isReady(); + } } return true; } @@ -267,13 +270,16 @@ public int show() { //If the head of the queue is interstitial mediation, show that instead of our adactivity Pair top = InterstitialAdView.q.peek(); - if (top != null && top.second instanceof MediatedInterstitialAdViewController) { - MediatedInterstitialAdViewController mAVC = (MediatedInterstitialAdViewController) top.second; - mAVC.show(); - - //Pop the mediated view; - InterstitialAdView.q.poll(); - return InterstitialAdView.q.size(); + if (top != null && top.second instanceof MediatedDisplayable) { + MediatedDisplayable mediatedDisplayable = (MediatedDisplayable) top.second; + if (mediatedDisplayable.mAVC instanceof MediatedInterstitialAdViewController) { + MediatedInterstitialAdViewController mAVC = (MediatedInterstitialAdViewController) mediatedDisplayable.mAVC; + mAVC.show(); + + //Pop the mediated view; + InterstitialAdView.q.poll(); + return InterstitialAdView.q.size(); + } } // otherwise, launch our adActivity From 8d9708c40a71a283bb03dd437f7257bc3d347749 Mon Sep 17 00:00:00 2001 From: Mark Ha Date: Tue, 10 Dec 2013 11:27:15 -0500 Subject: [PATCH 11/34] MS-386 CR-159 use private variables --- .../com/appnexus/opensdk/InterstitialAdView.java | 8 ++++---- .../opensdk/MediatedBannerAdViewController.java | 5 +++-- .../appnexus/opensdk/MediatedDisplayable.java | 16 ++++++++++++++-- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/sdk/src/com/appnexus/opensdk/InterstitialAdView.java b/sdk/src/com/appnexus/opensdk/InterstitialAdView.java index 9c440571d..406df268b 100644 --- a/sdk/src/com/appnexus/opensdk/InterstitialAdView.java +++ b/sdk/src/com/appnexus/opensdk/InterstitialAdView.java @@ -244,8 +244,8 @@ public boolean isReady() { Pair top = InterstitialAdView.q.peek(); if (top != null && top.second instanceof MediatedDisplayable) { MediatedDisplayable mediatedDisplayable = (MediatedDisplayable) top.second; - if (mediatedDisplayable.mAVC instanceof MediatedInterstitialAdViewController) { - MediatedInterstitialAdViewController mAVC = (MediatedInterstitialAdViewController) mediatedDisplayable.mAVC; + if (mediatedDisplayable.getMAVC() instanceof MediatedInterstitialAdViewController) { + MediatedInterstitialAdViewController mAVC = (MediatedInterstitialAdViewController) mediatedDisplayable.getMAVC(); return mAVC.isReady(); } } @@ -272,8 +272,8 @@ public int show() { Pair top = InterstitialAdView.q.peek(); if (top != null && top.second instanceof MediatedDisplayable) { MediatedDisplayable mediatedDisplayable = (MediatedDisplayable) top.second; - if (mediatedDisplayable.mAVC instanceof MediatedInterstitialAdViewController) { - MediatedInterstitialAdViewController mAVC = (MediatedInterstitialAdViewController) mediatedDisplayable.mAVC; + if (mediatedDisplayable.getMAVC() instanceof MediatedInterstitialAdViewController) { + MediatedInterstitialAdViewController mAVC = (MediatedInterstitialAdViewController) mediatedDisplayable.getMAVC(); mAVC.show(); //Pop the mediated view; diff --git a/sdk/src/com/appnexus/opensdk/MediatedBannerAdViewController.java b/sdk/src/com/appnexus/opensdk/MediatedBannerAdViewController.java index c4889ceb3..92d54cf03 100644 --- a/sdk/src/com/appnexus/opensdk/MediatedBannerAdViewController.java +++ b/sdk/src/com/appnexus/opensdk/MediatedBannerAdViewController.java @@ -49,12 +49,13 @@ private MediatedBannerAdViewController( startTimeout(); try { - mediatedDisplayable.view = ((MediatedBannerAdView) mAV).requestAd(this, + View viewFromMediatedAdaptor = ((MediatedBannerAdView) mAV).requestAd(this, activity, currentAd.getParam(), currentAd.getId(), currentAd.getWidth(), currentAd.getHeight()); + mediatedDisplayable.setView(viewFromMediatedAdaptor); } catch (Exception e) { Clog.e(Clog.mediationLogTag, Clog.getString(R.string.mediated_request_exception), e); errorCode = RESULT.INVALID_REQUEST; @@ -64,7 +65,7 @@ private MediatedBannerAdViewController( errorCode = RESULT.MEDIATED_SDK_UNAVAILABLE; } - if (mediatedDisplayable.view == null) { + if (mediatedDisplayable.getView() == null) { Clog.e(Clog.mediationLogTag, Clog.getString(R.string.mediated_view_null)); errorCode = RESULT.UNABLE_TO_FILL; } diff --git a/sdk/src/com/appnexus/opensdk/MediatedDisplayable.java b/sdk/src/com/appnexus/opensdk/MediatedDisplayable.java index 84970e090..38363fe59 100644 --- a/sdk/src/com/appnexus/opensdk/MediatedDisplayable.java +++ b/sdk/src/com/appnexus/opensdk/MediatedDisplayable.java @@ -19,8 +19,8 @@ import android.view.View; class MediatedDisplayable implements Displayable { - View view; - MediatedAdViewController mAVC; + private View view; + private MediatedAdViewController mAVC; MediatedDisplayable(MediatedAdViewController mAVC) { this.mAVC = mAVC; @@ -40,4 +40,16 @@ public boolean failed() { public void destroy() { mAVC.finishController(); } + + void setView(View view) { + this.view = view; + } + + MediatedAdViewController getMAVC() { + return mAVC; + } + + void setMAVC(MediatedAdViewController mAVC) { + this.mAVC = mAVC; + } } From a9c61e6e27be8483f1f4179cfdfa05b27c417f09 Mon Sep 17 00:00:00 2001 From: Mark Ha Date: Tue, 10 Dec 2013 14:28:08 -0500 Subject: [PATCH 12/34] MS-398 use last request as base url for debug auction --- .../src/com/appnexus/opensdkapp/Constants.java | 1 - .../src/com/appnexus/opensdkapp/DebugFragment.java | 14 +++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/examples/anx_sdk_app/src/com/appnexus/opensdkapp/Constants.java b/examples/anx_sdk_app/src/com/appnexus/opensdkapp/Constants.java index 35df13caf..a6fb313e7 100644 --- a/examples/anx_sdk_app/src/com/appnexus/opensdkapp/Constants.java +++ b/examples/anx_sdk_app/src/com/appnexus/opensdkapp/Constants.java @@ -19,7 +19,6 @@ public class Constants { public final static String BASE_LOG_TAG = "OPENSDK-APP"; public final static String PREFS_TAG = "OPENSDK-APP-PREFS"; - public final static String DEBUG_AUCTION_URL = "http://mediation.adnxs.com/mob?"; public final static String PREFERENCES = "AppNexus SDK App"; public final static String LOG_FILENAME = "AN_LOG_FILE"; diff --git a/examples/anx_sdk_app/src/com/appnexus/opensdkapp/DebugFragment.java b/examples/anx_sdk_app/src/com/appnexus/opensdkapp/DebugFragment.java index 4ca404fc3..a50fc71e5 100644 --- a/examples/anx_sdk_app/src/com/appnexus/opensdkapp/DebugFragment.java +++ b/examples/anx_sdk_app/src/com/appnexus/opensdkapp/DebugFragment.java @@ -195,7 +195,7 @@ public void onClick(View view) { }; private class DebugAuctionWebViewClient extends WebViewClient { - WebView webView; + private WebView webView; private DebugAuctionWebViewClient(WebView view) { this.webView = view; @@ -233,14 +233,10 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) { String result; public String getUrl() { - StringBuilder params = new StringBuilder(); - params.append("&id=").append(Prefs.getPlacementId(getActivity())); - params.append("&debug_member=").append(Prefs.getMemberId(getActivity())); - params.append("&dongle=").append(Prefs.getDongle(getActivity())); - params.append("&size=").append(Prefs.getSize(getActivity())); - params.append("&psa=").append(Prefs.getAllowPSAs(getActivity()) ? "1" : "0"); - params.append("&ua=").append(Uri.encode(webView.getSettings().getUserAgentString())); - return Constants.DEBUG_AUCTION_URL + params.toString(); + StringBuilder auctionURL = new StringBuilder(Clog.getLastRequest()); + auctionURL.append("&debug_member=").append(Prefs.getMemberId(getActivity())); + auctionURL.append("&dongle=").append(Prefs.getDongle(getActivity())); + return auctionURL.toString(); } public void runAuction() { From daaf05ac3a239a3888ebe67c991f5e2c71ad738f Mon Sep 17 00:00:00 2001 From: Mark Ha Date: Wed, 27 Nov 2013 13:31:47 -0500 Subject: [PATCH 13/34] Update gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 027c79aeb..1e959df45 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,8 @@ bin/ *.idea *local.properties .DS_Store +**/out/ +**/gen/ examples/.DS_Store examples/anx_sdk_app/gen/ examples/libs/pulltorefresh/gen/ @@ -15,3 +17,4 @@ mediation/mediating/.DS_Store sdk/.DS_Store sdk/doc/ sdk/gen/ + From 42940e94849c731e3ca278710739bbca4e7afdd1 Mon Sep 17 00:00:00 2001 From: Ron Lissack Date: Mon, 2 Dec 2013 15:17:58 -0500 Subject: [PATCH 14/34] MS-390 Application crash on invalid API setScaleX requires API 11 setLayoutDirection requires API 17 Changed play button rendering to use Matrix rotation --- .../com/appnexus/opensdk/BrowserActivity.java | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/sdk/src/com/appnexus/opensdk/BrowserActivity.java b/sdk/src/com/appnexus/opensdk/BrowserActivity.java index 55714a0c0..173c417ca 100644 --- a/sdk/src/com/appnexus/opensdk/BrowserActivity.java +++ b/sdk/src/com/appnexus/opensdk/BrowserActivity.java @@ -20,6 +20,9 @@ import android.app.Activity; import android.content.ActivityNotFoundException; import android.content.Intent; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Matrix; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; @@ -36,6 +39,7 @@ import android.webkit.WebViewClient; import android.widget.FrameLayout; import android.widget.ImageButton; +import android.widget.ImageView.ScaleType; import android.widget.ProgressBar; import android.widget.VideoView; @@ -75,10 +79,28 @@ protected void onCreate(Bundle savedInstance) { ImageButton openBrowser = (ImageButton) findViewById(R.id.open_browser); back.setEnabled(false); forward.setEnabled(false); - Drawable play = getResources().getDrawable(android.R.drawable.ic_media_play).mutate(); - back.setScaleX(-1); - back.setLayoutDirection(ImageButton.LAYOUT_DIRECTION_RTL); - back.setImageDrawable(play); + + int sdk = android.os.Build.VERSION.SDK_INT; + if (sdk >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { + Drawable play = getResources().getDrawable(android.R.drawable.ic_media_play).mutate(); + back.setScaleX(-1); + back.setLayoutDirection(ImageButton.LAYOUT_DIRECTION_RTL); + back.setImageDrawable(play); + } else { + back.post(new Runnable() { + public void run() { + Bitmap pbmp = BitmapFactory.decodeResource(getResources(), + android.R.drawable.ic_media_play); + Matrix x = new Matrix(); + back.setScaleType(ScaleType.MATRIX); + x.postRotate((float) 180.0f); + + Bitmap rotated = Bitmap.createBitmap(pbmp, 0, 0, + pbmp.getWidth(), pbmp.getHeight(), x, true); + back.setImageBitmap(rotated); + } + }); + } ImageButton refresh = (ImageButton) findViewById(R.id.browser_refresh); progressBar = (ProgressBar) findViewById(R.id.progress_bar); @@ -211,7 +233,6 @@ public void onProgressChanged(WebView view, int progress) { } } if (style != null) { - int sdk = android.os.Build.VERSION.SDK_INT; if (sdk >= android.os.Build.VERSION_CODES.JELLY_BEAN) { back.setBackground(style.backButton); forward.setBackground(style.forwardButton); From 6f7ad46381f4b9fe04bb73bf3b7cb663691f355c Mon Sep 17 00:00:00 2001 From: Jacob Shufro Date: Tue, 3 Dec 2013 15:35:18 -0500 Subject: [PATCH 15/34] Tweaks for crash fix from Ron --- sdk/res/layout/activity_in_app_browser.xml | 4 ++-- sdk/src/com/appnexus/opensdk/BrowserActivity.java | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/sdk/res/layout/activity_in_app_browser.xml b/sdk/res/layout/activity_in_app_browser.xml index f56805768..77d3d9ddc 100644 --- a/sdk/res/layout/activity_in_app_browser.xml +++ b/sdk/res/layout/activity_in_app_browser.xml @@ -50,13 +50,13 @@ diff --git a/sdk/src/com/appnexus/opensdk/BrowserActivity.java b/sdk/src/com/appnexus/opensdk/BrowserActivity.java index 173c417ca..9df15d2b5 100644 --- a/sdk/src/com/appnexus/opensdk/BrowserActivity.java +++ b/sdk/src/com/appnexus/opensdk/BrowserActivity.java @@ -23,6 +23,7 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Matrix; +import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; @@ -79,7 +80,7 @@ protected void onCreate(Bundle savedInstance) { ImageButton openBrowser = (ImageButton) findViewById(R.id.open_browser); back.setEnabled(false); forward.setEnabled(false); - + int sdk = android.os.Build.VERSION.SDK_INT; if (sdk >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { Drawable play = getResources().getDrawable(android.R.drawable.ic_media_play).mutate(); @@ -91,12 +92,15 @@ protected void onCreate(Bundle savedInstance) { public void run() { Bitmap pbmp = BitmapFactory.decodeResource(getResources(), android.R.drawable.ic_media_play); + forward.setImageBitmap(pbmp); Matrix x = new Matrix(); back.setScaleType(ScaleType.MATRIX); x.postRotate((float) 180.0f); Bitmap rotated = Bitmap.createBitmap(pbmp, 0, 0, pbmp.getWidth(), pbmp.getHeight(), x, true); + back.setScaleType(ScaleType.CENTER_INSIDE); + forward.setScaleType(ScaleType.CENTER_INSIDE); back.setImageBitmap(rotated); } }); From 4f69e24a6196b3bf945e9cddb6d9909ee955482d Mon Sep 17 00:00:00 2001 From: Mark Ha Date: Wed, 4 Dec 2013 15:10:55 -0500 Subject: [PATCH 16/34] MS-124 remove retrying requests from SDK --- sdk/res/values/errors.xml | 3 +- sdk/src/com/appnexus/opensdk/AdFetcher.java | 5 - sdk/src/com/appnexus/opensdk/AdRequest.java | 147 ++++-------------- sdk/src/com/appnexus/opensdk/AdRequester.java | 7 - sdk/src/com/appnexus/opensdk/AdResponse.java | 14 +- .../com/appnexus/opensdk/utils/Settings.java | 4 - .../opensdk/stdtests/TestRetryAdRequest.java | 119 -------------- 7 files changed, 34 insertions(+), 265 deletions(-) delete mode 100644 tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestRetryAdRequest.java diff --git a/sdk/res/values/errors.xml b/sdk/res/values/errors.xml index 7b85259cd..68db442be 100644 --- a/sdk/res/values/errors.xml +++ b/sdk/res/values/errors.xml @@ -23,7 +23,7 @@ Request received no response from the server. Response body: %s Header: %s Value: %s - The server returned a blank 200 OK HTTP response. Unless the maximum retries have been reached, this request will be retried shortly. + The server returned a blank 200 OK HTTP response. E301: The server replied with an error: %s The server responded, but didn\'t return any ads. E300: There was an error parsing the JSON response: %s @@ -111,7 +111,6 @@ result cb returned a bad response firing result cb with null resultCB Cancelling scheduled request - Tried to execute a retry request that was cancelled MRAID resize() called with w:%d, h:%d, offset_x:%d, offset_y:%d, cust_close_position:%s, allow_offscreen:%b MRAID setOrientationProperties called with allow_orientation_change=%b, orientation=%d MRAID createCalendarEvent() called diff --git a/sdk/src/com/appnexus/opensdk/AdFetcher.java b/sdk/src/com/appnexus/opensdk/AdFetcher.java index 2b4afbe33..5bb45bf52 100644 --- a/sdk/src/com/appnexus/opensdk/AdFetcher.java +++ b/sdk/src/com/appnexus/opensdk/AdFetcher.java @@ -280,11 +280,6 @@ public AdView getOwner() { return owner; } - @Override - public void setAdRequest(AdRequest adRequest) { - this.adRequest = adRequest; - } - public void clearDurations() { lastFetchTime = -1; timePausedAt = -1; diff --git a/sdk/src/com/appnexus/opensdk/AdRequest.java b/sdk/src/com/appnexus/opensdk/AdRequest.java index 39ce3dcaf..0e130f738 100644 --- a/sdk/src/com/appnexus/opensdk/AdRequest.java +++ b/sdk/src/com/appnexus/opensdk/AdRequest.java @@ -35,6 +35,7 @@ import com.appnexus.opensdk.utils.Clog; import com.appnexus.opensdk.utils.HashingFunctions; import com.appnexus.opensdk.utils.Settings; +import com.appnexus.opensdk.utils.StringUtil; import org.apache.http.HttpResponse; import org.apache.http.StatusLine; import org.apache.http.client.ClientProtocolException; @@ -82,24 +83,13 @@ class AdRequest extends AsyncTask { private int height = -1; private int maxWidth = -1; private int maxHeight = -1; - private boolean shouldRetry = true; // true by default private float reserve = 0.00f; private String age; private String gender; private ArrayList> customKeywords; - - private final Handler retryHandler = new Handler(); - - private int httpRetriesLeft = 0; - private int blankRetriesLeft = 0; - private static final AdResponse HTTP_ERROR - = new AdResponse(true, false, false); - private static final AdResponse CONNECTIVITY_RETRY - = new AdResponse(false, true, false); - private static final AdResponse BLANK_RETRY - = new AdResponse(false, false, true); + = new AdResponse(true); /** * Creates a new AdRequest with the given parameters @@ -131,8 +121,6 @@ public AdRequest(AdRequester requester, String aid, String lat, String lon, AdListener adListener, boolean shouldServePSAs, boolean shouldRetry) { this.adListener = adListener; this.requester = requester; - this.httpRetriesLeft = Settings.getSettings().MAX_CONNECTIVITY_RETRIES; - this.blankRetriesLeft = Settings.getSettings().MAX_BLANK_RETRIES; if (aid != null) { hidmd5 = HashingFunctions.md5(aid); hidsha1 = HashingFunctions.sha1(aid); @@ -168,19 +156,11 @@ public AdRequest(AdRequester requester, String aid, String lat, String lon, this.psa = shouldServePSAs ? "1" : "0"; this.nativeBrowser = isNativeBrowser ? "1" : "0"; - - this.shouldRetry = shouldRetry; } public AdRequest(AdRequester adRequester) { - this(adRequester, Settings.getSettings().MAX_CONNECTIVITY_RETRIES, Settings.getSettings().MAX_BLANK_RETRIES); - } - - private AdRequest(AdRequester adRequester, int httpRetriesLeft, int blankRetriesLeft) { owner = adRequester.getOwner(); this.requester = adRequester; - this.httpRetriesLeft = httpRetriesLeft; - this.blankRetriesLeft = blankRetriesLeft; this.placementId = owner.getPlacementID(); context = owner.getContext(); String aid = android.provider.Settings.Secure.getString( @@ -334,24 +314,24 @@ String getRequestUrl() { } else { sb.append("NO-PLACEMENT-ID"); } - if (!isEmpty(hidmd5)) sb.append("&md5udid=").append(Uri.encode(hidmd5)); - if (!isEmpty(hidsha1)) sb.append("&sha1udid=").append(Uri.encode(hidsha1)); - if (!isEmpty(devMake)) sb.append("&devmake=").append(Uri.encode(devMake)); - if (!isEmpty(devModel)) sb.append("&devmodel=").append(Uri.encode(devModel)); - if (!isEmpty(carrier)) sb.append( "&carrier=").append(Uri.encode(carrier)); + if (!StringUtil.isEmpty(hidmd5)) sb.append("&md5udid=").append(Uri.encode(hidmd5)); + if (!StringUtil.isEmpty(hidsha1)) sb.append("&sha1udid=").append(Uri.encode(hidsha1)); + if (!StringUtil.isEmpty(devMake)) sb.append("&devmake=").append(Uri.encode(devMake)); + if (!StringUtil.isEmpty(devModel)) sb.append("&devmodel=").append(Uri.encode(devModel)); + if (!StringUtil.isEmpty(carrier)) sb.append( "&carrier=").append(Uri.encode(carrier)); sb.append("&appid="); - if (!isEmpty(Settings.getSettings().app_id)) { + if (!StringUtil.isEmpty(Settings.getSettings().app_id)) { sb.append(Uri.encode(Settings.getSettings().app_id)); } else { sb.append("NO-APP-ID"); } if (firstlaunch) sb.append("&firstlaunch=true"); - if (!isEmpty(lat) && !isEmpty(lon)) sb.append("&loc=").append(lat).append(",").append(lon); - if (!isEmpty(locDataAge)) sb.append("&loc_age=").append(locDataAge); - if (!isEmpty(locDataPrecision)) sb.append("&loc_prec=").append(locDataPrecision); + if (!StringUtil.isEmpty(lat) && !StringUtil.isEmpty(lon)) sb.append("&loc=").append(lat).append(",").append(lon); + if (!StringUtil.isEmpty(locDataAge)) sb.append("&loc_age=").append(locDataAge); + if (!StringUtil.isEmpty(locDataPrecision)) sb.append("&loc_prec=").append(locDataPrecision); if (Settings.getSettings().test_mode) sb.append("&istest=true"); - if (!isEmpty(ua)) sb.append("&ua=").append(Uri.encode(ua)); - if (!isEmpty(orientation)) sb.append("&orientation=").append(orientation); + if (!StringUtil.isEmpty(ua)) sb.append("&ua=").append(Uri.encode(ua)); + if (!StringUtil.isEmpty(orientation)) sb.append("&orientation=").append(orientation); if (width > 0 && height > 0) sb.append("&size=").append(width).append("x").append(height); // complicated, don't change if (owner != null) { @@ -364,18 +344,18 @@ String getRequestUrl() { } } } - if (!isEmpty(allowedSizes)) sb.append("&promo_sizes=").append(allowedSizes); - if (!isEmpty(mcc)) sb.append("&mcc=").append(Uri.encode(mcc)); - if (!isEmpty(mnc)) sb.append("&mnc=").append(Uri.encode(mnc)); - if (!isEmpty(language)) sb.append("&language=").append(Uri.encode(language)); - if (!isEmpty(dev_timezone)) sb.append("&devtz=").append(Uri.encode(dev_timezone)); - if (!isEmpty(dev_time)) sb.append("&devtime=").append(Uri.encode(dev_time)); - if (!isEmpty(connection_type)) sb.append("&connection_type=").append( Uri.encode(connection_type)); - if (!isEmpty(nativeBrowser)) sb.append("&native_browser=").append(nativeBrowser); - if (!isEmpty(psa)) sb.append( "&psa=").append(psa); + if (!StringUtil.isEmpty(allowedSizes)) sb.append("&promo_sizes=").append(allowedSizes); + if (!StringUtil.isEmpty(mcc)) sb.append("&mcc=").append(Uri.encode(mcc)); + if (!StringUtil.isEmpty(mnc)) sb.append("&mnc=").append(Uri.encode(mnc)); + if (!StringUtil.isEmpty(language)) sb.append("&language=").append(Uri.encode(language)); + if (!StringUtil.isEmpty(dev_timezone)) sb.append("&devtz=").append(Uri.encode(dev_timezone)); + if (!StringUtil.isEmpty(dev_time)) sb.append("&devtime=").append(Uri.encode(dev_time)); + if (!StringUtil.isEmpty(connection_type)) sb.append("&connection_type=").append( Uri.encode(connection_type)); + if (!StringUtil.isEmpty(nativeBrowser)) sb.append("&native_browser=").append(nativeBrowser); + if (!StringUtil.isEmpty(psa)) sb.append( "&psa=").append(psa); if (reserve>0) sb.append("&reserve=").append(reserve); - if (!isEmpty(age)) sb.append("&age=").append(Uri.encode(age)); - if (!isEmpty(gender)) sb.append("&gender=").append(Uri.encode(gender)); + if (!StringUtil.isEmpty(age)) sb.append("&age=").append(Uri.encode(age)); + if (!StringUtil.isEmpty(gender)) sb.append("&gender=").append(Uri.encode(gender)); sb.append("&format=json"); sb.append("&st=mobile_app"); sb.append("&sdkver=").append(Uri.encode(Settings.getSettings().sdkVersion)); @@ -383,7 +363,7 @@ String getRequestUrl() { // add custom parameters if there are any if (customKeywords != null) { for (Pair pair : customKeywords) { - if (!isEmpty(pair.first) && (pair.second != null)) { + if (!StringUtil.isEmpty(pair.first) && (pair.second != null)) { sb.append("&") .append(pair.first) .append("=") @@ -400,9 +380,6 @@ protected AdResponse doInBackground(Void... params) { if (!hasNetwork(context)) { Clog.e(Clog.httpReqLogTag, Clog.getString(R.string.no_connectivity)); - if (!shouldRetry) - return doRequest(); - return AdRequest.CONNECTIVITY_RETRY; } return doRequest(); @@ -434,18 +411,18 @@ private AdResponse doRequest() { out = EntityUtils.toString(r.getEntity()); } catch (ClientProtocolException e) { Clog.e(Clog.httpReqLogTag, Clog.getString(R.string.http_unknown)); - return AdRequest.CONNECTIVITY_RETRY; + return null; } catch (ConnectTimeoutException e) { Clog.e(Clog.httpReqLogTag, Clog.getString(R.string.http_timeout)); - return AdRequest.CONNECTIVITY_RETRY; + return null; } catch (HttpHostConnectException he) { Clog.e(Clog.httpReqLogTag, Clog.getString( R.string.http_unreachable, he.getHost().getHostName(), he .getHost().getPort())); - return AdRequest.CONNECTIVITY_RETRY; + return null; } catch (IOException e) { Clog.e(Clog.httpReqLogTag, Clog.getString(R.string.http_io)); - return AdRequest.CONNECTIVITY_RETRY; + return null; } catch (SecurityException se) { Clog.e(Clog.baseLogTag, Clog.getString(R.string.permissions_internet)); @@ -453,11 +430,11 @@ private AdResponse doRequest() { } catch (Exception e) { e.printStackTrace(); Clog.e(Clog.baseLogTag, Clog.getString(R.string.unknown_exception)); - return AdRequest.CONNECTIVITY_RETRY; + return null; } if (out.equals("")) { Clog.e(Clog.httpRespLogTag, Clog.getString(R.string.response_blank)); - return AdRequest.BLANK_RETRY; + return null; } return new AdResponse(out, r.getAllHeaders()); } @@ -493,12 +470,10 @@ private boolean httpShouldContinue(StatusLine statusLine) { @Override protected void onPostExecute(AdResponse result) { - if (requester != null) - requester.setAdRequest(null); + // check for invalid responses if (result == null) { Clog.v(Clog.httpRespLogTag, Clog.getString(R.string.no_response)); fail(); - // Don't call fail again! return; // http request failed } if (result.isHttpError()) { @@ -506,33 +481,6 @@ protected void onPostExecute(AdResponse result) { return; } - if (shouldRetry) { - if ((httpRetriesLeft < 1) || (blankRetriesLeft < 1)) { - // return if we have exceeded the max number of tries - fail(); - return; - } - boolean resultIsRetry = false; - - if (result.isConnectivityRetry()) { - httpRetriesLeft--; - resultIsRetry = true; - } else if (result.isBlankRetry()) { - blankRetriesLeft--; - resultIsRetry = true; - } - - if (resultIsRetry) { - // don't fail, but clear the last response - Clog.clearLastResponse(); - final AdRequest retry = new AdRequest(requester, httpRetriesLeft, blankRetriesLeft); - if (requester != null) - requester.setAdRequest(retry); - retry.retryHandler.postDelayed(new RetryRunnable(retry), Settings.getSettings().HTTP_RETRY_INTERVAL); - return; // The request failed and should be retried. - } - // else let it continue to process the valid result - } if (requester != null) requester.onReceiveResponse(result); // for unit testing @@ -544,37 +492,6 @@ protected void onPostExecute(AdResponse result) { protected void onCancelled(AdResponse adResponse) { super.onCancelled(adResponse); Clog.w(Clog.httpRespLogTag, Clog.getString(R.string.cancel_request)); - if (requester != null) - requester.setAdRequest(null); - // remove pending retry requests if the requester cancels the ad request - retryHandler.removeCallbacksAndMessages(null); - } - - private static boolean isEmpty(String str) { - return (str == null) || str.equals(""); - } - - class RetryRunnable implements Runnable { - final AdRequest retry; - - RetryRunnable(AdRequest retry) { - this.retry = retry; - } - - @Override - public void run() { - if (retry.isCancelled()) { - Clog.w(Clog.httpRespLogTag, Clog.getString(R.string.retry_already_cancelled)); - return; - } - - // Spawn an AdRequest - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { - retry.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } else { - retry.execute(); - } - } } // // Uncomment for unit tests diff --git a/sdk/src/com/appnexus/opensdk/AdRequester.java b/sdk/src/com/appnexus/opensdk/AdRequester.java index 57cf82314..65bbe1994 100644 --- a/sdk/src/com/appnexus/opensdk/AdRequester.java +++ b/sdk/src/com/appnexus/opensdk/AdRequester.java @@ -35,11 +35,4 @@ interface AdRequester { * Used to get the owner adview of the request */ public AdView getOwner(); - - /** - * Used to set inform the AdRequester which AdRequest is currently being run or pending - * - * @param adRequest the current ad request - */ - public void setAdRequest(AdRequest adRequest); } diff --git a/sdk/src/com/appnexus/opensdk/AdResponse.java b/sdk/src/com/appnexus/opensdk/AdResponse.java index 9978063a1..8c0935c0b 100644 --- a/sdk/src/com/appnexus/opensdk/AdResponse.java +++ b/sdk/src/com/appnexus/opensdk/AdResponse.java @@ -41,8 +41,6 @@ class AdResponse { private boolean containsAds = false; private boolean isHttpError = false; - private boolean isConnectivityRetry = false; - private boolean isBlankRetry = false; private static final String MRAID_JS_FILENAME = "mraid.js"; private static final String RESPONSE_KEY_STATUS = "status"; @@ -82,10 +80,8 @@ public AdResponse(HTTPResponse httpResponse) { parseResponse(httpResponse.getResponseBody()); } - public AdResponse(boolean isHttpError, boolean isConnectivityRetry, boolean isBlankRetry) { + public AdResponse(boolean isHttpError) { this.isHttpError = isHttpError; - this.isConnectivityRetry = isConnectivityRetry; - this.isBlankRetry = isBlankRetry; } private void printHeaders(Header[] headers) { @@ -233,14 +229,6 @@ public boolean isMraid() { return isMraid; } - public boolean isConnectivityRetry() { - return isConnectivityRetry; - } - - public boolean isBlankRetry() { - return isBlankRetry; - } - public boolean isHttpError() { return isHttpError; } diff --git a/sdk/src/com/appnexus/opensdk/utils/Settings.java b/sdk/src/com/appnexus/opensdk/utils/Settings.java index 9cc54b242..a1107fc7c 100644 --- a/sdk/src/com/appnexus/opensdk/utils/Settings.java +++ b/sdk/src/com/appnexus/opensdk/utils/Settings.java @@ -47,13 +47,9 @@ public class Settings { public final int MIN_REFRESH_MILLISECONDS = 15000; public final int DEFAULT_INTERSTITIAL_CLOSE_BUTTON_DELAY = 10000; - public /*final*/ long HTTP_RETRY_INTERVAL = 10000; public final long MEDIATED_NETWORK_TIMEOUT = 15000; - public final int MAX_BLANK_RETRIES = 1; - public final int MAX_CONNECTIVITY_RETRIES = 1; - public /*final*/ String BASE_URL = "http://mediation.adnxs.com/mob?"; public final String INSTALL_BASE_URL = "http://mediation.adnxs.com/install?"; diff --git a/tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestRetryAdRequest.java b/tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestRetryAdRequest.java deleted file mode 100644 index c2d111219..000000000 --- a/tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestRetryAdRequest.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright 2013 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.stdtests; - -import android.test.AndroidTestCase; -import com.appnexus.opensdk.*; -import com.appnexus.opensdk.utils.Clog; -import com.appnexus.opensdk.utils.Settings; -import com.appnexus.opensdk.util.InstanceLock; -import com.appnexus.opensdk.util.TestUtil; - -public class TestRetryAdRequest extends AndroidTestCase implements AdRequester { - /** - * Make sure permissions are set up in test_app's AndroidManifest.xml file for wifi+data access and change - * - * Also make sure AdRequest has setContext() uncommented, and uncomment the code here - */ - - String settingsURL; - long settingsInterval; - AdRequest request; - boolean didFail = false; - boolean didSucceed = false; - InstanceLock lock; - int timesRetried = 0; - AdView adView; - - String placementId = "17"; - - protected void setUp() throws Exception { - super.setUp(); - Clog.w(TestUtil.testLogTag, "Testing Retries"); - settingsURL = Settings.getSettings().BASE_URL; - settingsInterval = Settings.getSettings().HTTP_RETRY_INTERVAL; - Settings.getSettings().HTTP_RETRY_INTERVAL = TestUtil.SHORT_RETRY_INTERVAL; - request = new AdRequest(this, "123456", null, null, placementId, "portrait", "AT&T", - 320, 50, 320, 50, null, null, "wifi", false, null, true, true); - lock = new InstanceLock(); - timesRetried = 0; - adView = new BannerAdView(getContext()); - adView.setPlacementID(placementId); - -// request.setContext(getContext()); - TestUtil.setWifi(true, getContext()); - TestUtil.setData(true, getContext()); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - TestUtil.setWifi(true, getContext()); - TestUtil.setData(true, getContext()); - } - - public void testBlankRetries() { - request.execute(); - long retryTime = Settings.getSettings().HTTP_RETRY_INTERVAL * Settings.getSettings().MAX_BLANK_RETRIES; - lock.pause(10000 + retryTime); - request.cancel(true); - - assertFalse(didSucceed); - assertTrue(didFail); - assertEquals(Settings.getSettings().MAX_BLANK_RETRIES, timesRetried); - } - - public void testConnectivityRetries() { - TestUtil.setWifi(false, getContext()); - TestUtil.setData(false, getContext()); - - request.execute(); - long retryTime = Settings.getSettings().HTTP_RETRY_INTERVAL * Settings.getSettings().MAX_CONNECTIVITY_RETRIES; - lock.pause(10000 + retryTime); - request.cancel(true); - - assertFalse(didSucceed); - assertTrue(didFail); - assertEquals(Settings.getSettings().MAX_CONNECTIVITY_RETRIES, timesRetried); - } - - @Override - public void onReceiveResponse(AdResponse response) { - didSucceed = true; - if (lock != null) - lock.unpause(); - } - - @Override - public AdView getOwner() { - return adView; - } - - @Override - public void setAdRequest(AdRequest adRequest) { - // ignore deallocation calls - if (adRequest != null) - timesRetried++; - } - - @Override - public void failed(AdRequest request) { - didFail = true; - if (lock != null) - lock.unpause(); - } -} From 538b362da0967fb7d81ae962c5f5d97b250918d4 Mon Sep 17 00:00:00 2001 From: Mark Ha Date: Wed, 4 Dec 2013 15:34:41 -0500 Subject: [PATCH 17/34] MS-124 unit tests updates, move package --- .../opensdk/{mediationtests => }/Test404Error.java | 9 +++------ .../{mediationtests => }/TestActivity404Error.java | 2 +- .../TestActivityMediationCallbacks.java | 2 +- .../TestActivityMediationWaterfall.java | 2 +- .../TestActivityRefreshStdThenMediated.java | 2 +- .../opensdk/{stdtests => }/TestClogListener.java | 2 +- .../opensdk/{stdtests => }/TestFailingAdRequest.java | 6 +----- .../opensdk/{stdtests => }/TestHashingFunctions.java | 2 +- .../opensdk/{mediationtests => }/TestMediationBasic.java | 8 ++------ .../TestMediationSuccessThenStd.java | 8 ++------ .../{stdtests => }/TestShortestSuccessfulAdRequest.java | 6 +----- .../opensdk/{stdtests => }/TestSuccessfulAdRequest.java | 6 +----- .../appnexus/opensdk/{stdtests => }/TestVisibility.java | 2 +- 13 files changed, 17 insertions(+), 40 deletions(-) rename tests/test_sdk/src/com/appnexus/opensdk/{mediationtests => }/Test404Error.java (95%) rename tests/test_sdk/src/com/appnexus/opensdk/{mediationtests => }/TestActivity404Error.java (98%) rename tests/test_sdk/src/com/appnexus/opensdk/{mediationtests => }/TestActivityMediationCallbacks.java (99%) rename tests/test_sdk/src/com/appnexus/opensdk/{mediationtests => }/TestActivityMediationWaterfall.java (99%) rename tests/test_sdk/src/com/appnexus/opensdk/{mediationtests => }/TestActivityRefreshStdThenMediated.java (98%) rename tests/test_sdk/src/com/appnexus/opensdk/{stdtests => }/TestClogListener.java (99%) rename tests/test_sdk/src/com/appnexus/opensdk/{stdtests => }/TestFailingAdRequest.java (96%) rename tests/test_sdk/src/com/appnexus/opensdk/{stdtests => }/TestHashingFunctions.java (97%) rename tests/test_sdk/src/com/appnexus/opensdk/{mediationtests => }/TestMediationBasic.java (96%) rename tests/test_sdk/src/com/appnexus/opensdk/{mediationtests => }/TestMediationSuccessThenStd.java (96%) rename tests/test_sdk/src/com/appnexus/opensdk/{stdtests => }/TestShortestSuccessfulAdRequest.java (96%) rename tests/test_sdk/src/com/appnexus/opensdk/{stdtests => }/TestSuccessfulAdRequest.java (96%) rename tests/test_sdk/src/com/appnexus/opensdk/{stdtests => }/TestVisibility.java (98%) diff --git a/tests/test_sdk/src/com/appnexus/opensdk/mediationtests/Test404Error.java b/tests/test_sdk/src/com/appnexus/opensdk/Test404Error.java similarity index 95% rename from tests/test_sdk/src/com/appnexus/opensdk/mediationtests/Test404Error.java rename to tests/test_sdk/src/com/appnexus/opensdk/Test404Error.java index 7f8603efe..83a05b619 100644 --- a/tests/test_sdk/src/com/appnexus/opensdk/mediationtests/Test404Error.java +++ b/tests/test_sdk/src/com/appnexus/opensdk/Test404Error.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.appnexus.opensdk.mediationtests; +package com.appnexus.opensdk; import android.test.AndroidTestCase; import com.appnexus.opensdk.*; @@ -70,7 +70,7 @@ public void testSuccessWithResult404() { assertTrue(receivedResponse); assertEquals(true, SuccessfulMediationView.didPass); - assertTrue(responseWasNull); + // responses from a successful result_cb no longer get passed back up, so can't check } public void testFailWithResult404() { @@ -97,7 +97,7 @@ public void failed(AdRequest request) { @Override public void onReceiveResponse(AdResponse response) { - // response should be a regular valid mediatied ad + // response should be a regular valid mediated ad Clog.d(TestUtil.testLogTag, "received response: " + response); if (response != null && response.getMediatedAds() != null) { MediatedBannerAdViewController output = MediatedBannerAdViewController.create( @@ -116,7 +116,4 @@ public AdView getOwner() { return null; } - @Override - public void setAdRequest(AdRequest adRequest) { - } } diff --git a/tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestActivity404Error.java b/tests/test_sdk/src/com/appnexus/opensdk/TestActivity404Error.java similarity index 98% rename from tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestActivity404Error.java rename to tests/test_sdk/src/com/appnexus/opensdk/TestActivity404Error.java index be6313dcb..57440a4a0 100644 --- a/tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestActivity404Error.java +++ b/tests/test_sdk/src/com/appnexus/opensdk/TestActivity404Error.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.appnexus.opensdk.mediationtests; +package com.appnexus.opensdk; import android.test.ActivityInstrumentationTestCase2; import com.appnexus.opensdk.AdListener; diff --git a/tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestActivityMediationCallbacks.java b/tests/test_sdk/src/com/appnexus/opensdk/TestActivityMediationCallbacks.java similarity index 99% rename from tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestActivityMediationCallbacks.java rename to tests/test_sdk/src/com/appnexus/opensdk/TestActivityMediationCallbacks.java index 723592804..d878d27c5 100644 --- a/tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestActivityMediationCallbacks.java +++ b/tests/test_sdk/src/com/appnexus/opensdk/TestActivityMediationCallbacks.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.appnexus.opensdk.mediationtests; +package com.appnexus.opensdk; import android.test.ActivityInstrumentationTestCase2; import com.appnexus.opensdk.AdListener; diff --git a/tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestActivityMediationWaterfall.java b/tests/test_sdk/src/com/appnexus/opensdk/TestActivityMediationWaterfall.java similarity index 99% rename from tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestActivityMediationWaterfall.java rename to tests/test_sdk/src/com/appnexus/opensdk/TestActivityMediationWaterfall.java index dcbdcc0fe..7589e5476 100644 --- a/tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestActivityMediationWaterfall.java +++ b/tests/test_sdk/src/com/appnexus/opensdk/TestActivityMediationWaterfall.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.appnexus.opensdk.mediationtests; +package com.appnexus.opensdk; import android.test.ActivityInstrumentationTestCase2; import com.appnexus.opensdk.AdListener; diff --git a/tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestActivityRefreshStdThenMediated.java b/tests/test_sdk/src/com/appnexus/opensdk/TestActivityRefreshStdThenMediated.java similarity index 98% rename from tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestActivityRefreshStdThenMediated.java rename to tests/test_sdk/src/com/appnexus/opensdk/TestActivityRefreshStdThenMediated.java index 8930a6c9c..74397e21f 100644 --- a/tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestActivityRefreshStdThenMediated.java +++ b/tests/test_sdk/src/com/appnexus/opensdk/TestActivityRefreshStdThenMediated.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.appnexus.opensdk.mediationtests; +package com.appnexus.opensdk; import android.test.ActivityInstrumentationTestCase2; import android.view.View; diff --git a/tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestClogListener.java b/tests/test_sdk/src/com/appnexus/opensdk/TestClogListener.java similarity index 99% rename from tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestClogListener.java rename to tests/test_sdk/src/com/appnexus/opensdk/TestClogListener.java index eaaa8f5a8..1ee296122 100644 --- a/tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestClogListener.java +++ b/tests/test_sdk/src/com/appnexus/opensdk/TestClogListener.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.appnexus.opensdk.stdtests; +package com.appnexus.opensdk; import android.util.Log; import com.appnexus.opensdk.utils.Clog; diff --git a/tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestFailingAdRequest.java b/tests/test_sdk/src/com/appnexus/opensdk/TestFailingAdRequest.java similarity index 96% rename from tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestFailingAdRequest.java rename to tests/test_sdk/src/com/appnexus/opensdk/TestFailingAdRequest.java index 9f3dde9be..56cc9637d 100644 --- a/tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestFailingAdRequest.java +++ b/tests/test_sdk/src/com/appnexus/opensdk/TestFailingAdRequest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.appnexus.opensdk.stdtests; +package com.appnexus.opensdk; import com.appnexus.opensdk.*; import junit.framework.TestCase; @@ -70,10 +70,6 @@ public AdView getOwner() { return null; } - @Override - public void setAdRequest(AdRequest adRequest) { - } - @Override synchronized public void failed(AdRequest request) { shouldPass = true; diff --git a/tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestHashingFunctions.java b/tests/test_sdk/src/com/appnexus/opensdk/TestHashingFunctions.java similarity index 97% rename from tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestHashingFunctions.java rename to tests/test_sdk/src/com/appnexus/opensdk/TestHashingFunctions.java index 16a257f7b..8292138f2 100644 --- a/tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestHashingFunctions.java +++ b/tests/test_sdk/src/com/appnexus/opensdk/TestHashingFunctions.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.appnexus.opensdk.stdtests; +package com.appnexus.opensdk; import com.appnexus.opensdk.utils.HashingFunctions; import junit.framework.TestCase; diff --git a/tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestMediationBasic.java b/tests/test_sdk/src/com/appnexus/opensdk/TestMediationBasic.java similarity index 96% rename from tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestMediationBasic.java rename to tests/test_sdk/src/com/appnexus/opensdk/TestMediationBasic.java index 6b5ba9cab..8f4988398 100644 --- a/tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestMediationBasic.java +++ b/tests/test_sdk/src/com/appnexus/opensdk/TestMediationBasic.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.appnexus.opensdk.mediationtests; +package com.appnexus.opensdk; import android.test.AndroidTestCase; import com.appnexus.opensdk.*; @@ -53,7 +53,7 @@ protected void setUp() throws Exception { synchronized protected void tearDown() throws Exception { wait(1000); if ((SuccessfulMediationView.didPass && SecondSuccessfulMediationView.didPass && ThirdSuccessfulMediationView.didPass) - || (NoSDK.didPass && ThirdSuccessfulMediationView.didPass)) + || (NoSDK.didPass && ThirdSuccessfulMediationView.didPass)) Clog.w(TestUtil.testLogTag, "TEST PASSED #" + placementId); Settings.getSettings().BASE_URL = oldUrl; super.tearDown(); @@ -157,8 +157,4 @@ public void onReceiveResponse(AdResponse response) { public AdView getOwner() { return null; } - - @Override - public void setAdRequest(AdRequest adRequest) { - } } \ No newline at end of file diff --git a/tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestMediationSuccessThenStd.java b/tests/test_sdk/src/com/appnexus/opensdk/TestMediationSuccessThenStd.java similarity index 96% rename from tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestMediationSuccessThenStd.java rename to tests/test_sdk/src/com/appnexus/opensdk/TestMediationSuccessThenStd.java index 0416c2e4e..ece88167f 100644 --- a/tests/test_sdk/src/com/appnexus/opensdk/mediationtests/TestMediationSuccessThenStd.java +++ b/tests/test_sdk/src/com/appnexus/opensdk/TestMediationSuccessThenStd.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.appnexus.opensdk.mediationtests; +package com.appnexus.opensdk; import android.test.AndroidTestCase; import com.appnexus.opensdk.*; @@ -89,14 +89,10 @@ public AdView getOwner() { return null; } - @Override - public void setAdRequest(AdRequest adRequest) { - } - synchronized private void pause() { Clog.d(TestUtil.testLogTag, "pausing"); try { - wait(); + wait(10000); } catch (InterruptedException e) { e.printStackTrace(); shouldWork.cancel(true); diff --git a/tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestShortestSuccessfulAdRequest.java b/tests/test_sdk/src/com/appnexus/opensdk/TestShortestSuccessfulAdRequest.java similarity index 96% rename from tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestShortestSuccessfulAdRequest.java rename to tests/test_sdk/src/com/appnexus/opensdk/TestShortestSuccessfulAdRequest.java index 709e49686..b466ff8c8 100644 --- a/tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestShortestSuccessfulAdRequest.java +++ b/tests/test_sdk/src/com/appnexus/opensdk/TestShortestSuccessfulAdRequest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.appnexus.opensdk.stdtests; +package com.appnexus.opensdk; import com.appnexus.opensdk.*; import junit.framework.TestCase; @@ -58,10 +58,6 @@ public AdView getOwner() { return null; } - @Override - public void setAdRequest(AdRequest adRequest) { - } - @Override synchronized public void failed(AdRequest request) { shouldWorkDidWork = false; diff --git a/tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestSuccessfulAdRequest.java b/tests/test_sdk/src/com/appnexus/opensdk/TestSuccessfulAdRequest.java similarity index 96% rename from tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestSuccessfulAdRequest.java rename to tests/test_sdk/src/com/appnexus/opensdk/TestSuccessfulAdRequest.java index a679c10fd..bef85c964 100644 --- a/tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestSuccessfulAdRequest.java +++ b/tests/test_sdk/src/com/appnexus/opensdk/TestSuccessfulAdRequest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.appnexus.opensdk.stdtests; +package com.appnexus.opensdk; import com.appnexus.opensdk.*; import junit.framework.TestCase; @@ -58,10 +58,6 @@ public AdView getOwner() { return null; } - @Override - public void setAdRequest(AdRequest adRequest) { - } - @Override synchronized public void failed(AdRequest request) { shouldWorkDidWork = false; diff --git a/tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestVisibility.java b/tests/test_sdk/src/com/appnexus/opensdk/TestVisibility.java similarity index 98% rename from tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestVisibility.java rename to tests/test_sdk/src/com/appnexus/opensdk/TestVisibility.java index 684b9542c..9a8367912 100644 --- a/tests/test_sdk/src/com/appnexus/opensdk/stdtests/TestVisibility.java +++ b/tests/test_sdk/src/com/appnexus/opensdk/TestVisibility.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.appnexus.opensdk.stdtests; +package com.appnexus.opensdk; import android.test.ActivityInstrumentationTestCase2; import android.view.View; From 8df48c791958eb6fe5a54607ca9d6a92fa90ffdc Mon Sep 17 00:00:00 2001 From: Mark Ha Date: Fri, 6 Dec 2013 12:45:48 -0500 Subject: [PATCH 18/34] MS-397 updating debug auction in app to show device info. --- .../src/com/appnexus/opensdkapp/DebugFragment.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/anx_sdk_app/src/com/appnexus/opensdkapp/DebugFragment.java b/examples/anx_sdk_app/src/com/appnexus/opensdkapp/DebugFragment.java index 76432a018..4ca404fc3 100644 --- a/examples/anx_sdk_app/src/com/appnexus/opensdkapp/DebugFragment.java +++ b/examples/anx_sdk_app/src/com/appnexus/opensdkapp/DebugFragment.java @@ -19,6 +19,7 @@ import android.app.AlertDialog; import android.content.ActivityNotFoundException; import android.content.Intent; +import android.net.Uri; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; @@ -40,6 +41,8 @@ import org.json.JSONException; import org.json.JSONObject; +import java.net.URI; + public class DebugFragment extends Fragment { TextView txtRequest, txtResponse; @@ -235,13 +238,14 @@ public String getUrl() { params.append("&debug_member=").append(Prefs.getMemberId(getActivity())); params.append("&dongle=").append(Prefs.getDongle(getActivity())); params.append("&size=").append(Prefs.getSize(getActivity())); + params.append("&psa=").append(Prefs.getAllowPSAs(getActivity()) ? "1" : "0"); + params.append("&ua=").append(Uri.encode(webView.getSettings().getUserAgentString())); return Constants.DEBUG_AUCTION_URL + params.toString(); } public void runAuction() { final String debugAuctionUrl = getUrl(); Clog.d(Constants.BASE_LOG_TAG, "Running a Debug Auction: " + debugAuctionUrl); -// loadUrl(debugAuctionUrl); final HTTPGet auctionGet = new HTTPGet() { @Override From eb383a4d3693c7f950b019334ba850f074446ac1 Mon Sep 17 00:00:00 2001 From: Mark Ha Date: Mon, 9 Dec 2013 14:55:40 -0500 Subject: [PATCH 19/34] MS-124 return null for no network or context case. --- sdk/src/com/appnexus/opensdk/AdRequest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/src/com/appnexus/opensdk/AdRequest.java b/sdk/src/com/appnexus/opensdk/AdRequest.java index 0e130f738..084e85cd0 100644 --- a/sdk/src/com/appnexus/opensdk/AdRequest.java +++ b/sdk/src/com/appnexus/opensdk/AdRequest.java @@ -380,6 +380,7 @@ protected AdResponse doInBackground(Void... params) { if (!hasNetwork(context)) { Clog.e(Clog.httpReqLogTag, Clog.getString(R.string.no_connectivity)); + return null; } return doRequest(); From b03e9a564170b0e4968c49da0d6edc93567915d4 Mon Sep 17 00:00:00 2001 From: Mark Ha Date: Mon, 9 Dec 2013 16:25:11 -0500 Subject: [PATCH 20/34] MS-385 make display protected in InterstitialAdView to hide from javadoc --- sdk/src/com/appnexus/opensdk/AdView.java | 9 ++++----- sdk/src/com/appnexus/opensdk/InterstitialAdView.java | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/sdk/src/com/appnexus/opensdk/AdView.java b/sdk/src/com/appnexus/opensdk/AdView.java index e72e7474a..5d2b0e4da 100644 --- a/sdk/src/com/appnexus/opensdk/AdView.java +++ b/sdk/src/com/appnexus/opensdk/AdView.java @@ -468,11 +468,10 @@ public boolean getShouldServePSAs() { } /** - * Set the current PSA setting. If set to true, the SDK will - * retrieve and display a Public Service Announcement if no - * other ad is available. PSAs are ads for various causes or - * nonprofit organizations. If set to false, no ad is - * returned. + * Allows overriding the platform behavior in the case there is no ad + * currently available. If set to true the platform will retrieve and + * display a PSA (Public Service Announcement) . Set the value to false it + * will return no ad. * * @param shouldServePSAs * Whether this placement is willing to accept a PSA if no other ad is available. diff --git a/sdk/src/com/appnexus/opensdk/InterstitialAdView.java b/sdk/src/com/appnexus/opensdk/InterstitialAdView.java index a37b4ab25..235b2be9d 100644 --- a/sdk/src/com/appnexus/opensdk/InterstitialAdView.java +++ b/sdk/src/com/appnexus/opensdk/InterstitialAdView.java @@ -204,7 +204,7 @@ public boolean loadAd() { } @Override - public void display(Displayable d) { + void display(Displayable d) { if (d == null) { fail(); return; From a5f44911efc4a972e0a9a8111a3b777a98495357 Mon Sep 17 00:00:00 2001 From: Mark Ha Date: Mon, 9 Dec 2013 18:19:35 -0500 Subject: [PATCH 21/34] MS-386 refactored mediation to create private displayable object, hide inner classes from javadoc --- sdk/src/com/appnexus/opensdk/AdFetcher.java | 4 +- .../opensdk/MediatedAdViewController.java | 25 +++-------- .../MediatedBannerAdViewController.java | 10 ++--- .../appnexus/opensdk/MediatedDisplayable.java | 43 +++++++++++++++++++ 4 files changed, 54 insertions(+), 28 deletions(-) create mode 100644 sdk/src/com/appnexus/opensdk/MediatedDisplayable.java diff --git a/sdk/src/com/appnexus/opensdk/AdFetcher.java b/sdk/src/com/appnexus/opensdk/AdFetcher.java index 5bb45bf52..5e6c6d960 100644 --- a/sdk/src/com/appnexus/opensdk/AdFetcher.java +++ b/sdk/src/com/appnexus/opensdk/AdFetcher.java @@ -245,13 +245,11 @@ public void run() { owner.popMediatedAd(), owner.getAdDispatcher()); } else if (owner.isInterstitial()) { - MediatedInterstitialAdViewController output = MediatedInterstitialAdViewController.create( + MediatedInterstitialAdViewController.create( (Activity) owner.getContext(), owner.mAdFetcher, owner.popMediatedAd(), owner.getAdDispatcher()); - if (output != null) - output.getView(); } } else if ((response != null) && response.isMraid()) { diff --git a/sdk/src/com/appnexus/opensdk/MediatedAdViewController.java b/sdk/src/com/appnexus/opensdk/MediatedAdViewController.java index 2291e82d7..f1d15450f 100644 --- a/sdk/src/com/appnexus/opensdk/MediatedAdViewController.java +++ b/sdk/src/com/appnexus/opensdk/MediatedAdViewController.java @@ -40,7 +40,7 @@ *

*/ -public abstract class MediatedAdViewController implements Displayable { +public abstract class MediatedAdViewController { /** * This enum contains the results from mediation calls sent @@ -82,9 +82,10 @@ public static enum RESULT { private AdRequester requester; protected MediatedAd currentAd; private AdViewListener listener; + protected MediatedDisplayable mediatedDisplayable = new MediatedDisplayable(this); - private boolean hasFailed = false; - private boolean hasSucceeded = false; + boolean hasFailed = false; + boolean hasSucceeded = false; MediatedAdViewController(AdRequester requester, MediatedAd currentAd, AdViewListener listener) { this.requester = requester; @@ -166,7 +167,7 @@ private boolean instantiateNewMediatedAd() { return false; } - private void finishController() { + void finishController() { mAV = null; requester = null; currentAd = null; @@ -189,7 +190,7 @@ public void onAdLoaded() { hasSucceeded = true; if (listener != null) - listener.onAdLoaded(this); + listener.onAdLoaded(mediatedDisplayable); fireResultCB(RESULT.SUCCESS); } @@ -247,20 +248,6 @@ public void onAdClicked() { listener.onAdClicked(); } - /* - Overridden Displayable methods - */ - - @Override - public boolean failed() { - return hasFailed; - } - - @Override - public void destroy() { - finishController(); - } - /* Result CB Code */ diff --git a/sdk/src/com/appnexus/opensdk/MediatedBannerAdViewController.java b/sdk/src/com/appnexus/opensdk/MediatedBannerAdViewController.java index 47cb76a4f..a640f0970 100644 --- a/sdk/src/com/appnexus/opensdk/MediatedBannerAdViewController.java +++ b/sdk/src/com/appnexus/opensdk/MediatedBannerAdViewController.java @@ -26,15 +26,13 @@ * the AppNexus SDK. */ -public class MediatedBannerAdViewController extends MediatedAdViewController implements Displayable { - - private View placeableView; +public class MediatedBannerAdViewController extends MediatedAdViewController { static MediatedBannerAdViewController create( Activity activity, AdRequester requester, MediatedAd mediatedAd, AdViewListener listener) { MediatedBannerAdViewController out = new MediatedBannerAdViewController(activity, requester, mediatedAd, listener); - return out.failed() ? null : out; + return out.hasFailed ? null : out; } private MediatedBannerAdViewController( @@ -52,7 +50,7 @@ private MediatedBannerAdViewController( startTimeout(); try { - placeableView = ((MediatedBannerAdView) mAV).requestAd(this, + mediatedDisplayable.view = ((MediatedBannerAdView) mAV).requestAd(this, activity, currentAd.getParam(), currentAd.getId(), @@ -67,7 +65,7 @@ private MediatedBannerAdViewController( errorCode = RESULT.MEDIATED_SDK_UNAVAILABLE; } - if (placeableView == null) { + if (mediatedDisplayable.view == null) { Clog.e(Clog.mediationLogTag, Clog.getString(R.string.mediated_view_null)); errorCode = RESULT.UNABLE_TO_FILL; } diff --git a/sdk/src/com/appnexus/opensdk/MediatedDisplayable.java b/sdk/src/com/appnexus/opensdk/MediatedDisplayable.java new file mode 100644 index 000000000..84970e090 --- /dev/null +++ b/sdk/src/com/appnexus/opensdk/MediatedDisplayable.java @@ -0,0 +1,43 @@ +/* + * Copyright 2013 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; + +import android.view.View; + +class MediatedDisplayable implements Displayable { + View view; + MediatedAdViewController mAVC; + + MediatedDisplayable(MediatedAdViewController mAVC) { + this.mAVC = mAVC; + } + + @Override + public View getView() { + return view; + } + + @Override + public boolean failed() { + return mAVC.hasFailed; + } + + @Override + public void destroy() { + mAVC.finishController(); + } +} From 25adfe9f1145bde46fffffcd704e4e59b6396911 Mon Sep 17 00:00:00 2001 From: Mark Ha Date: Mon, 9 Dec 2013 18:28:39 -0500 Subject: [PATCH 22/34] MS-386 update interstitials for new MediatedDisplayable --- .../appnexus/opensdk/InterstitialAdView.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/sdk/src/com/appnexus/opensdk/InterstitialAdView.java b/sdk/src/com/appnexus/opensdk/InterstitialAdView.java index 235b2be9d..c676bc114 100644 --- a/sdk/src/com/appnexus/opensdk/InterstitialAdView.java +++ b/sdk/src/com/appnexus/opensdk/InterstitialAdView.java @@ -258,9 +258,12 @@ public boolean isReady() { long now = System.currentTimeMillis(); if (removeStaleAds(now)) { Pair top = InterstitialAdView.q.peek(); - if (top != null && top.second instanceof MediatedInterstitialAdViewController) { - MediatedInterstitialAdViewController mAVC = (MediatedInterstitialAdViewController) top.second; - return mAVC.isReady(); + if (top != null && top.second instanceof MediatedDisplayable) { + MediatedDisplayable mediatedDisplayable = (MediatedDisplayable) top.second; + if (mediatedDisplayable.mAVC instanceof MediatedInterstitialAdViewController) { + MediatedInterstitialAdViewController mAVC = (MediatedInterstitialAdViewController) mediatedDisplayable.mAVC; + return mAVC.isReady(); + } } return true; } @@ -284,13 +287,16 @@ public int show() { //If the head of the queue is interstitial mediation, show that instead of our adactivity Pair top = InterstitialAdView.q.peek(); - if (top != null && top.second instanceof MediatedInterstitialAdViewController) { - MediatedInterstitialAdViewController mAVC = (MediatedInterstitialAdViewController) top.second; - mAVC.show(); - - //Pop the mediated view; - InterstitialAdView.q.poll(); - return InterstitialAdView.q.size(); + if (top != null && top.second instanceof MediatedDisplayable) { + MediatedDisplayable mediatedDisplayable = (MediatedDisplayable) top.second; + if (mediatedDisplayable.mAVC instanceof MediatedInterstitialAdViewController) { + MediatedInterstitialAdViewController mAVC = (MediatedInterstitialAdViewController) mediatedDisplayable.mAVC; + mAVC.show(); + + //Pop the mediated view; + InterstitialAdView.q.poll(); + return InterstitialAdView.q.size(); + } } // otherwise, launch our adActivity From 0487ad9dde06a6126dac945a895852103427f560 Mon Sep 17 00:00:00 2001 From: Mark Ha Date: Tue, 10 Dec 2013 11:27:15 -0500 Subject: [PATCH 23/34] MS-386 CR-159 use private variables --- .../com/appnexus/opensdk/InterstitialAdView.java | 8 ++++---- .../opensdk/MediatedBannerAdViewController.java | 5 +++-- .../appnexus/opensdk/MediatedDisplayable.java | 16 ++++++++++++++-- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/sdk/src/com/appnexus/opensdk/InterstitialAdView.java b/sdk/src/com/appnexus/opensdk/InterstitialAdView.java index c676bc114..9d48840bd 100644 --- a/sdk/src/com/appnexus/opensdk/InterstitialAdView.java +++ b/sdk/src/com/appnexus/opensdk/InterstitialAdView.java @@ -260,8 +260,8 @@ public boolean isReady() { Pair top = InterstitialAdView.q.peek(); if (top != null && top.second instanceof MediatedDisplayable) { MediatedDisplayable mediatedDisplayable = (MediatedDisplayable) top.second; - if (mediatedDisplayable.mAVC instanceof MediatedInterstitialAdViewController) { - MediatedInterstitialAdViewController mAVC = (MediatedInterstitialAdViewController) mediatedDisplayable.mAVC; + if (mediatedDisplayable.getMAVC() instanceof MediatedInterstitialAdViewController) { + MediatedInterstitialAdViewController mAVC = (MediatedInterstitialAdViewController) mediatedDisplayable.getMAVC(); return mAVC.isReady(); } } @@ -289,8 +289,8 @@ public int show() { Pair top = InterstitialAdView.q.peek(); if (top != null && top.second instanceof MediatedDisplayable) { MediatedDisplayable mediatedDisplayable = (MediatedDisplayable) top.second; - if (mediatedDisplayable.mAVC instanceof MediatedInterstitialAdViewController) { - MediatedInterstitialAdViewController mAVC = (MediatedInterstitialAdViewController) mediatedDisplayable.mAVC; + if (mediatedDisplayable.getMAVC() instanceof MediatedInterstitialAdViewController) { + MediatedInterstitialAdViewController mAVC = (MediatedInterstitialAdViewController) mediatedDisplayable.getMAVC(); mAVC.show(); //Pop the mediated view; diff --git a/sdk/src/com/appnexus/opensdk/MediatedBannerAdViewController.java b/sdk/src/com/appnexus/opensdk/MediatedBannerAdViewController.java index a640f0970..037941da8 100644 --- a/sdk/src/com/appnexus/opensdk/MediatedBannerAdViewController.java +++ b/sdk/src/com/appnexus/opensdk/MediatedBannerAdViewController.java @@ -50,12 +50,13 @@ private MediatedBannerAdViewController( startTimeout(); try { - mediatedDisplayable.view = ((MediatedBannerAdView) mAV).requestAd(this, + View viewFromMediatedAdaptor = ((MediatedBannerAdView) mAV).requestAd(this, activity, currentAd.getParam(), currentAd.getId(), currentAd.getWidth(), currentAd.getHeight()); + mediatedDisplayable.setView(viewFromMediatedAdaptor); } catch (Exception e) { Clog.e(Clog.mediationLogTag, Clog.getString(R.string.mediated_request_exception), e); errorCode = RESULT.INVALID_REQUEST; @@ -65,7 +66,7 @@ private MediatedBannerAdViewController( errorCode = RESULT.MEDIATED_SDK_UNAVAILABLE; } - if (mediatedDisplayable.view == null) { + if (mediatedDisplayable.getView() == null) { Clog.e(Clog.mediationLogTag, Clog.getString(R.string.mediated_view_null)); errorCode = RESULT.UNABLE_TO_FILL; } diff --git a/sdk/src/com/appnexus/opensdk/MediatedDisplayable.java b/sdk/src/com/appnexus/opensdk/MediatedDisplayable.java index 84970e090..38363fe59 100644 --- a/sdk/src/com/appnexus/opensdk/MediatedDisplayable.java +++ b/sdk/src/com/appnexus/opensdk/MediatedDisplayable.java @@ -19,8 +19,8 @@ import android.view.View; class MediatedDisplayable implements Displayable { - View view; - MediatedAdViewController mAVC; + private View view; + private MediatedAdViewController mAVC; MediatedDisplayable(MediatedAdViewController mAVC) { this.mAVC = mAVC; @@ -40,4 +40,16 @@ public boolean failed() { public void destroy() { mAVC.finishController(); } + + void setView(View view) { + this.view = view; + } + + MediatedAdViewController getMAVC() { + return mAVC; + } + + void setMAVC(MediatedAdViewController mAVC) { + this.mAVC = mAVC; + } } From 47bb508ac4053c2e49eff998782795430d893608 Mon Sep 17 00:00:00 2001 From: Mark Ha Date: Tue, 10 Dec 2013 14:28:08 -0500 Subject: [PATCH 24/34] MS-398 use last request as base url for debug auction --- .../src/com/appnexus/opensdkapp/Constants.java | 1 - .../src/com/appnexus/opensdkapp/DebugFragment.java | 14 +++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/examples/anx_sdk_app/src/com/appnexus/opensdkapp/Constants.java b/examples/anx_sdk_app/src/com/appnexus/opensdkapp/Constants.java index 35df13caf..a6fb313e7 100644 --- a/examples/anx_sdk_app/src/com/appnexus/opensdkapp/Constants.java +++ b/examples/anx_sdk_app/src/com/appnexus/opensdkapp/Constants.java @@ -19,7 +19,6 @@ public class Constants { public final static String BASE_LOG_TAG = "OPENSDK-APP"; public final static String PREFS_TAG = "OPENSDK-APP-PREFS"; - public final static String DEBUG_AUCTION_URL = "http://mediation.adnxs.com/mob?"; public final static String PREFERENCES = "AppNexus SDK App"; public final static String LOG_FILENAME = "AN_LOG_FILE"; diff --git a/examples/anx_sdk_app/src/com/appnexus/opensdkapp/DebugFragment.java b/examples/anx_sdk_app/src/com/appnexus/opensdkapp/DebugFragment.java index 4ca404fc3..a50fc71e5 100644 --- a/examples/anx_sdk_app/src/com/appnexus/opensdkapp/DebugFragment.java +++ b/examples/anx_sdk_app/src/com/appnexus/opensdkapp/DebugFragment.java @@ -195,7 +195,7 @@ public void onClick(View view) { }; private class DebugAuctionWebViewClient extends WebViewClient { - WebView webView; + private WebView webView; private DebugAuctionWebViewClient(WebView view) { this.webView = view; @@ -233,14 +233,10 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) { String result; public String getUrl() { - StringBuilder params = new StringBuilder(); - params.append("&id=").append(Prefs.getPlacementId(getActivity())); - params.append("&debug_member=").append(Prefs.getMemberId(getActivity())); - params.append("&dongle=").append(Prefs.getDongle(getActivity())); - params.append("&size=").append(Prefs.getSize(getActivity())); - params.append("&psa=").append(Prefs.getAllowPSAs(getActivity()) ? "1" : "0"); - params.append("&ua=").append(Uri.encode(webView.getSettings().getUserAgentString())); - return Constants.DEBUG_AUCTION_URL + params.toString(); + StringBuilder auctionURL = new StringBuilder(Clog.getLastRequest()); + auctionURL.append("&debug_member=").append(Prefs.getMemberId(getActivity())); + auctionURL.append("&dongle=").append(Prefs.getDongle(getActivity())); + return auctionURL.toString(); } public void runAuction() { From 5169d3f6e6b434d25f4a0223b0ba98634d969b8b Mon Sep 17 00:00:00 2001 From: Rich Loveland Date: Mon, 25 Nov 2013 17:33:21 -0500 Subject: [PATCH 25/34] Revised & updated docs in mediation-related files. --- .../appnexus/opensdk/MediatedInterstitialAdViewController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/com/appnexus/opensdk/MediatedInterstitialAdViewController.java b/sdk/src/com/appnexus/opensdk/MediatedInterstitialAdViewController.java index 0ec8f9b99..61e4a602b 100644 --- a/sdk/src/com/appnexus/opensdk/MediatedInterstitialAdViewController.java +++ b/sdk/src/com/appnexus/opensdk/MediatedInterstitialAdViewController.java @@ -26,7 +26,7 @@ * events back to the AppNexus SDK. */ -public class MediatedInterstitialAdViewController extends MediatedAdViewController implements Displayable { +public class MediatedInterstitialAdViewController extends MediatedAdViewController { private Activity activity; From 6a61848f17e76ccbb77ba417f37a5e7b45b07755 Mon Sep 17 00:00:00 2001 From: Jacob Shufro Date: Mon, 16 Dec 2013 14:33:07 -0500 Subject: [PATCH 26/34] Location bug fix --- sdk/src/com/appnexus/opensdk/AdRequest.java | 29 +++++++++++++++------ 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/sdk/src/com/appnexus/opensdk/AdRequest.java b/sdk/src/com/appnexus/opensdk/AdRequest.java index 084e85cd0..6dd03435a 100644 --- a/sdk/src/com/appnexus/opensdk/AdRequest.java +++ b/sdk/src/com/appnexus/opensdk/AdRequest.java @@ -175,14 +175,27 @@ public AdRequest(AdRequester adRequester) { // available LocationManager lm = (LocationManager) context .getSystemService(Context.LOCATION_SERVICE); - Location lastLocation = lm.getLastKnownLocation(lm.getBestProvider( - new Criteria(), false)); - if (lastLocation != null) { - lat = "" + lastLocation.getLatitude(); - lon = "" + lastLocation.getLongitude(); - locDataAge = "" - + (System.currentTimeMillis() - lastLocation.getTime()); - locDataPrecision = "" + lastLocation.getAccuracy(); + Location lastLocation = null; + for (String provider_name : lm.getProviders(true)) { + Location l = lm.getLastKnownLocation(provider_name); + if (l == null) { + continue; + } + + if (lastLocation == null) { + lastLocation = l; + } else { + if ( l.getTime() > 0 && lastLocation.getTime()>0) { + if (l.getTime() > lastLocation.getTime()) { + lastLocation = l; + } + } + } + } + if(lastLocation!=null){ + lat = ""+lastLocation.getLatitude(); + lon = ""+lastLocation.getLongitude(); + locDataPrecision = ""+lastLocation.getAccuracy(); } } else { Clog.w(Clog.baseLogTag, From 11176008559bdd591f06da0601fd0d8b9f6435cd Mon Sep 17 00:00:00 2001 From: Mark Ha Date: Thu, 19 Dec 2013 17:10:42 -0500 Subject: [PATCH 27/34] MS-408 MoPub adaptor no loading ads enable sdk to load ads offscreen, update gitignore --- .gitignore | 1 + .../opensdk/mopubmediation/BuildConfig.java | 4 ++-- .../appnexus/opensdk/mopubmediation/Manifest.java | 2 +- .../com/appnexus/opensdk/mopubmediation/R.java | 2 +- .../appnexus/opensdk/MoPubMediationBanner.java | 6 ++---- sdk/src/com/appnexus/opensdk/AdView.java | 15 ++++++++++++++- 6 files changed, 21 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 1e959df45..ba6ffe135 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ mediation/mediatedviews/.DS_Store mediation/mediatedviews/doc/ mediation/mediatedviews/gen/ mediation/mediating/.DS_Store +mediation/mediating/*/gen/ sdk/.DS_Store sdk/doc/ sdk/gen/ diff --git a/mediation/mediating/mopub/gen/com/appnexus/opensdk/mopubmediation/BuildConfig.java b/mediation/mediating/mopub/gen/com/appnexus/opensdk/mopubmediation/BuildConfig.java index f74ef4c25..55581c577 100644 --- a/mediation/mediating/mopub/gen/com/appnexus/opensdk/mopubmediation/BuildConfig.java +++ b/mediation/mediating/mopub/gen/com/appnexus/opensdk/mopubmediation/BuildConfig.java @@ -1,8 +1,8 @@ /*___Generated_by_IDEA___*/ -/** Automatically generated file. DO NOT MODIFY */ package com.appnexus.opensdk.mopubmediation; +/* This stub is only used by the IDE. It is NOT the BuildConfig class actually packed into the APK */ public final class BuildConfig { - public final static boolean DEBUG = true; + public final static boolean DEBUG = Boolean.parseBoolean(null); } \ No newline at end of file diff --git a/mediation/mediating/mopub/gen/com/appnexus/opensdk/mopubmediation/Manifest.java b/mediation/mediating/mopub/gen/com/appnexus/opensdk/mopubmediation/Manifest.java index 19d249db8..69fb318e5 100644 --- a/mediation/mediating/mopub/gen/com/appnexus/opensdk/mopubmediation/Manifest.java +++ b/mediation/mediating/mopub/gen/com/appnexus/opensdk/mopubmediation/Manifest.java @@ -2,6 +2,6 @@ package com.appnexus.opensdk.mopubmediation; -/* This stub is for using by IDE only. It is NOT the Manifest class actually packed into APK */ +/* This stub is only used by the IDE. It is NOT the Manifest class actually packed into the APK */ public final class Manifest { } \ No newline at end of file diff --git a/mediation/mediating/mopub/gen/com/appnexus/opensdk/mopubmediation/R.java b/mediation/mediating/mopub/gen/com/appnexus/opensdk/mopubmediation/R.java index 576e310d6..b2ce96513 100644 --- a/mediation/mediating/mopub/gen/com/appnexus/opensdk/mopubmediation/R.java +++ b/mediation/mediating/mopub/gen/com/appnexus/opensdk/mopubmediation/R.java @@ -2,6 +2,6 @@ package com.appnexus.opensdk.mopubmediation; -/* This stub is for using by IDE only. It is NOT the R class actually packed into APK */ +/* This stub is only used by the IDE. It is NOT the R class actually packed into the APK */ public final class R { } \ No newline at end of file diff --git a/mediation/mediating/mopub/src/com/appnexus/opensdk/MoPubMediationBanner.java b/mediation/mediating/mopub/src/com/appnexus/opensdk/MoPubMediationBanner.java index d308cebd8..142d4013f 100644 --- a/mediation/mediating/mopub/src/com/appnexus/opensdk/MoPubMediationBanner.java +++ b/mediation/mediating/mopub/src/com/appnexus/opensdk/MoPubMediationBanner.java @@ -47,12 +47,10 @@ protected void loadBanner(Context context, CustomEventBannerListener customEvent bav = new BannerAdView(context); bav.setPlacementID(apid); - bav.setAdHeight(height); - bav.setAdWidth(width); + bav.setAdSize(width, height); bav.setAdListener(this); - bav.loadAd(); - + bav.loadAdOffscreen(); } private boolean extrasAreValid(Map serverExtras) { diff --git a/sdk/src/com/appnexus/opensdk/AdView.java b/sdk/src/com/appnexus/opensdk/AdView.java index 5d2b0e4da..9056b2e04 100644 --- a/sdk/src/com/appnexus/opensdk/AdView.java +++ b/sdk/src/com/appnexus/opensdk/AdView.java @@ -66,6 +66,7 @@ public abstract class AdView extends FrameLayout { final Handler handler = new Handler(Looper.getMainLooper()); private Displayable lastDisplayable; private AdListenerDispatch dispatcher; + boolean loadedOffscreen = false; /** * Begin Construction @@ -164,7 +165,7 @@ protected void onLayout(boolean changed, int left, int top, int right, } // Hide the adview - if (!measured) { + if (!measured && !loadedOffscreen) { hide(); } @@ -214,6 +215,18 @@ protected boolean loadAd() { return false; } + protected void loadAdOffscreen() { + if (!isReadyToStart()) + return; + if (mAdFetcher != null) { + // Reload Ad Fetcher to get new ad at user's request + mAdFetcher.stop(); + mAdFetcher.clearDurations(); + mAdFetcher.start(); + loadedOffscreen = true; + } + } + /** * Loads a new ad, if the ad space is visible, and sets the * AdView's placement ID. From a6ae3e6e2cea812a78b98d18f1032e14453885d1 Mon Sep 17 00:00:00 2001 From: Mark Ha Date: Thu, 19 Dec 2013 17:14:36 -0500 Subject: [PATCH 28/34] MS-408 MoPub adaptor no loading ads delete gen files --- .../com/appnexus/opensdk/mopubmediation/BuildConfig.java | 8 -------- .../gen/com/appnexus/opensdk/mopubmediation/Manifest.java | 7 ------- .../mopub/gen/com/appnexus/opensdk/mopubmediation/R.java | 7 ------- 3 files changed, 22 deletions(-) delete mode 100644 mediation/mediating/mopub/gen/com/appnexus/opensdk/mopubmediation/BuildConfig.java delete mode 100644 mediation/mediating/mopub/gen/com/appnexus/opensdk/mopubmediation/Manifest.java delete mode 100644 mediation/mediating/mopub/gen/com/appnexus/opensdk/mopubmediation/R.java diff --git a/mediation/mediating/mopub/gen/com/appnexus/opensdk/mopubmediation/BuildConfig.java b/mediation/mediating/mopub/gen/com/appnexus/opensdk/mopubmediation/BuildConfig.java deleted file mode 100644 index 55581c577..000000000 --- a/mediation/mediating/mopub/gen/com/appnexus/opensdk/mopubmediation/BuildConfig.java +++ /dev/null @@ -1,8 +0,0 @@ -/*___Generated_by_IDEA___*/ - -package com.appnexus.opensdk.mopubmediation; - -/* This stub is only used by the IDE. It is NOT the BuildConfig class actually packed into the APK */ -public final class BuildConfig { - public final static boolean DEBUG = Boolean.parseBoolean(null); -} \ No newline at end of file diff --git a/mediation/mediating/mopub/gen/com/appnexus/opensdk/mopubmediation/Manifest.java b/mediation/mediating/mopub/gen/com/appnexus/opensdk/mopubmediation/Manifest.java deleted file mode 100644 index 69fb318e5..000000000 --- a/mediation/mediating/mopub/gen/com/appnexus/opensdk/mopubmediation/Manifest.java +++ /dev/null @@ -1,7 +0,0 @@ -/*___Generated_by_IDEA___*/ - -package com.appnexus.opensdk.mopubmediation; - -/* This stub is only used by the IDE. It is NOT the Manifest class actually packed into the APK */ -public final class Manifest { -} \ No newline at end of file diff --git a/mediation/mediating/mopub/gen/com/appnexus/opensdk/mopubmediation/R.java b/mediation/mediating/mopub/gen/com/appnexus/opensdk/mopubmediation/R.java deleted file mode 100644 index b2ce96513..000000000 --- a/mediation/mediating/mopub/gen/com/appnexus/opensdk/mopubmediation/R.java +++ /dev/null @@ -1,7 +0,0 @@ -/*___Generated_by_IDEA___*/ - -package com.appnexus.opensdk.mopubmediation; - -/* This stub is only used by the IDE. It is NOT the R class actually packed into the APK */ -public final class R { -} \ No newline at end of file From 13c2185845c1dbf9fa7f1be9ff7be3a13811556d Mon Sep 17 00:00:00 2001 From: Mark Ha Date: Thu, 19 Dec 2013 17:44:03 -0500 Subject: [PATCH 29/34] MS-408: MoPub adaptor not loading ads Add log statements in MoPub adaptors --- .../opensdk/MoPubMediationBanner.java | 14 ++++++++++--- .../opensdk/MoPubMediationInterstitial.java | 20 +++++++++++++++---- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/mediation/mediating/mopub/src/com/appnexus/opensdk/MoPubMediationBanner.java b/mediation/mediating/mopub/src/com/appnexus/opensdk/MoPubMediationBanner.java index 142d4013f..dc7295ab1 100644 --- a/mediation/mediating/mopub/src/com/appnexus/opensdk/MoPubMediationBanner.java +++ b/mediation/mediating/mopub/src/com/appnexus/opensdk/MoPubMediationBanner.java @@ -17,6 +17,7 @@ package com.appnexus.opensdk; import android.content.Context; +import com.appnexus.opensdk.utils.Clog; import com.mopub.mobileads.CustomEventBanner; import com.mopub.mobileads.MoPubErrorCode; @@ -31,25 +32,30 @@ public class MoPubMediationBanner extends CustomEventBanner implements AdListene @Override protected void loadBanner(Context context, CustomEventBannerListener customEventBannerListener, Map localExtras, Map serverExtras) { + Clog.d(Clog.mediationLogTag, "Initializing ANBanner via MoPub SDK"); this.listener = customEventBannerListener; - String apid; + String placementID; int width; int height; + if (extrasAreValid(serverExtras)) { - apid = serverExtras.get(PLACEMENTID_KEY); + placementID = serverExtras.get(PLACEMENTID_KEY); width = Integer.parseInt(serverExtras.get(AD_WIDTH_KEY)); height = Integer.parseInt(serverExtras.get(AD_HEIGHT_KEY)); + Clog.d(Clog.mediationLogTag, String.format("Server extras were valid: placementID: %s, width: %s, height: %s", placementID, width, height)); } else { listener.onBannerFailed(MoPubErrorCode.ADAPTER_CONFIGURATION_ERROR); + Clog.e(Clog.mediationLogTag, "Failed to parse server extras. Check setup of placement in MoPub."); return; } bav = new BannerAdView(context); - bav.setPlacementID(apid); + bav.setPlacementID(placementID); bav.setAdSize(width, height); bav.setAdListener(this); + Clog.d(Clog.mediationLogTag, "Load ANBanner"); bav.loadAdOffscreen(); } @@ -73,11 +79,13 @@ protected void onInvalidate() { @Override public void onAdLoaded(AdView adView) { + Clog.d(Clog.mediationLogTag, "ANBanner loaded successfully"); if (listener != null) listener.onBannerLoaded(bav); } @Override public void onAdRequestFailed(AdView adView) { + Clog.d(Clog.mediationLogTag, "ANBanner failed to load"); if (listener != null) listener.onBannerFailed(MoPubErrorCode.UNSPECIFIED); } diff --git a/mediation/mediating/mopub/src/com/appnexus/opensdk/MoPubMediationInterstitial.java b/mediation/mediating/mopub/src/com/appnexus/opensdk/MoPubMediationInterstitial.java index cc790563f..340373070 100644 --- a/mediation/mediating/mopub/src/com/appnexus/opensdk/MoPubMediationInterstitial.java +++ b/mediation/mediating/mopub/src/com/appnexus/opensdk/MoPubMediationInterstitial.java @@ -17,6 +17,7 @@ package com.appnexus.opensdk; import android.content.Context; +import com.appnexus.opensdk.utils.Clog; import com.mopub.mobileads.CustomEventInterstitial; import com.mopub.mobileads.MoPubErrorCode; @@ -29,18 +30,23 @@ public class MoPubMediationInterstitial extends CustomEventInterstitial implemen @Override protected void loadInterstitial(Context context, CustomEventInterstitialListener customEventInterstitialListener, Map localExtras, Map serverExtras) { + Clog.d(Clog.mediationLogTag, "Initializing ANInterstitial via MoPub SDK"); listener = customEventInterstitialListener; - String apid; + String placementID; if (extrasAreValid(serverExtras)) { - apid = serverExtras.get(PLACEMENTID_KEY); + placementID = serverExtras.get(PLACEMENTID_KEY); + Clog.d(Clog.mediationLogTag, String.format("Server extras were valid: placementID: %s", placementID)); } else { listener.onInterstitialFailed(MoPubErrorCode.ADAPTER_CONFIGURATION_ERROR); + Clog.e(Clog.mediationLogTag, "Failed to parse server extras. Check setup of placement in MoPub."); return; } iad = new InterstitialAdView(context); - iad.setPlacementID(apid); + iad.setPlacementID(placementID); iad.setAdListener(this); + + Clog.d(Clog.mediationLogTag, "Fetch ANInterstitial"); iad.loadAd(); } @@ -50,8 +56,12 @@ private boolean extrasAreValid(Map serverExtras) { @Override protected void showInterstitial() { - if (iad != null) + if (iad != null) { + Clog.d(Clog.mediationLogTag, "Show ANInterstitial"); iad.show(); + } else { + Clog.d(Clog.mediationLogTag, "Failed to show ANInterstitial; null object"); + } } @Override @@ -63,11 +73,13 @@ protected void onInvalidate() { @Override public void onAdLoaded(AdView adView) { + Clog.d(Clog.mediationLogTag, "ANInterstitial loaded successfully"); if (listener != null) listener.onInterstitialLoaded(); } @Override public void onAdRequestFailed(AdView adView) { + Clog.d(Clog.mediationLogTag, "ANInterstitial failed to load"); if (listener != null) listener.onInterstitialFailed(MoPubErrorCode.UNSPECIFIED); } From 127a41c5b55a4c8b9bbfa5db88e393833e40eaf4 Mon Sep 17 00:00:00 2001 From: Mark Ha Date: Thu, 19 Dec 2013 17:53:36 -0500 Subject: [PATCH 30/34] MS-408: MoPub adaptor not loading ads Disable PSAs in MoPub adaptors --- .../src/com/appnexus/opensdk/MoPubMediationBanner.java | 1 + .../com/appnexus/opensdk/MoPubMediationInterstitial.java | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/mediation/mediating/mopub/src/com/appnexus/opensdk/MoPubMediationBanner.java b/mediation/mediating/mopub/src/com/appnexus/opensdk/MoPubMediationBanner.java index dc7295ab1..891a7c3a0 100644 --- a/mediation/mediating/mopub/src/com/appnexus/opensdk/MoPubMediationBanner.java +++ b/mediation/mediating/mopub/src/com/appnexus/opensdk/MoPubMediationBanner.java @@ -53,6 +53,7 @@ protected void loadBanner(Context context, CustomEventBannerListener customEvent bav = new BannerAdView(context); bav.setPlacementID(placementID); bav.setAdSize(width, height); + bav.setShouldServePSAs(false); bav.setAdListener(this); Clog.d(Clog.mediationLogTag, "Load ANBanner"); diff --git a/mediation/mediating/mopub/src/com/appnexus/opensdk/MoPubMediationInterstitial.java b/mediation/mediating/mopub/src/com/appnexus/opensdk/MoPubMediationInterstitial.java index 340373070..d127a54a5 100644 --- a/mediation/mediating/mopub/src/com/appnexus/opensdk/MoPubMediationInterstitial.java +++ b/mediation/mediating/mopub/src/com/appnexus/opensdk/MoPubMediationInterstitial.java @@ -44,6 +44,7 @@ protected void loadInterstitial(Context context, CustomEventInterstitialListener iad = new InterstitialAdView(context); iad.setPlacementID(placementID); + iad.setShouldServePSAs(false); iad.setAdListener(this); Clog.d(Clog.mediationLogTag, "Fetch ANInterstitial"); @@ -56,11 +57,15 @@ private boolean extrasAreValid(Map serverExtras) { @Override protected void showInterstitial() { - if (iad != null) { + if (iad != null && iad.isReady()) { Clog.d(Clog.mediationLogTag, "Show ANInterstitial"); iad.show(); } else { - Clog.d(Clog.mediationLogTag, "Failed to show ANInterstitial; null object"); + if (iad == null) { + Clog.e(Clog.mediationLogTag, "Failed to show ANInterstitial; null object"); + } else if (!iad.isReady()) { + Clog.e(Clog.mediationLogTag, "Failed to show ANInterstitial; ad unavailable"); + } } } From 0a931b648712f0a4d5bfbf030b8679bb76663d74 Mon Sep 17 00:00:00 2001 From: Mark Ha Date: Thu, 19 Dec 2013 18:37:36 -0500 Subject: [PATCH 31/34] MS-408: MoPub adaptor not loading ads additional logging --- .../mopub/src/com/appnexus/opensdk/MoPubMediationBanner.java | 3 +++ .../src/com/appnexus/opensdk/MoPubMediationInterstitial.java | 3 +++ 2 files changed, 6 insertions(+) diff --git a/mediation/mediating/mopub/src/com/appnexus/opensdk/MoPubMediationBanner.java b/mediation/mediating/mopub/src/com/appnexus/opensdk/MoPubMediationBanner.java index 891a7c3a0..ae5b32344 100644 --- a/mediation/mediating/mopub/src/com/appnexus/opensdk/MoPubMediationBanner.java +++ b/mediation/mediating/mopub/src/com/appnexus/opensdk/MoPubMediationBanner.java @@ -92,16 +92,19 @@ public void onAdRequestFailed(AdView adView) { @Override public void onAdExpanded(AdView adView) { + Clog.d(Clog.mediationLogTag, "ANBanner expanded"); if (listener != null) listener.onBannerExpanded(); } @Override public void onAdCollapsed(AdView adView) { + Clog.d(Clog.mediationLogTag, "ANBanner collapsed"); if (listener != null) listener.onBannerCollapsed(); } @Override public void onAdClicked(AdView adView) { + Clog.d(Clog.mediationLogTag, "ANBanner was clicked"); if (listener != null) listener.onBannerClicked(); } } diff --git a/mediation/mediating/mopub/src/com/appnexus/opensdk/MoPubMediationInterstitial.java b/mediation/mediating/mopub/src/com/appnexus/opensdk/MoPubMediationInterstitial.java index d127a54a5..2b98413b1 100644 --- a/mediation/mediating/mopub/src/com/appnexus/opensdk/MoPubMediationInterstitial.java +++ b/mediation/mediating/mopub/src/com/appnexus/opensdk/MoPubMediationInterstitial.java @@ -90,16 +90,19 @@ public void onAdRequestFailed(AdView adView) { @Override public void onAdExpanded(AdView adView) { + Clog.d(Clog.mediationLogTag, "ANInterstitial expanded"); if (listener != null) listener.onInterstitialShown(); } @Override public void onAdCollapsed(AdView adView) { + Clog.d(Clog.mediationLogTag, "ANInterstitial collapsed"); if (listener != null) listener.onInterstitialDismissed(); } @Override public void onAdClicked(AdView adView) { + Clog.d(Clog.mediationLogTag, "ANInterstitial was clicked"); if (listener != null) listener.onInterstitialClicked(); } } From 67fae4d3f0f0b1889659a8c636026183ad3e44fd Mon Sep 17 00:00:00 2001 From: Mark Ha Date: Thu, 19 Dec 2013 18:52:26 -0500 Subject: [PATCH 32/34] MS-410 Update SDK Version number --- sdk/src/com/appnexus/opensdk/utils/Settings.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/com/appnexus/opensdk/utils/Settings.java b/sdk/src/com/appnexus/opensdk/utils/Settings.java index a1107fc7c..d483eb667 100644 --- a/sdk/src/com/appnexus/opensdk/utils/Settings.java +++ b/sdk/src/com/appnexus/opensdk/utils/Settings.java @@ -33,7 +33,7 @@ public class Settings { public boolean test_mode = false; public String ua = null; public boolean first_launch; - public final String sdkVersion = "1.0"; + public final String sdkVersion = "1.6"; public String mcc; public String mnc; From 49ec631a0b178f8ea6aacd7b419e0b5fe5e4a0ba Mon Sep 17 00:00:00 2001 From: Mark Ha Date: Fri, 20 Dec 2013 11:20:31 -0500 Subject: [PATCH 33/34] MS-406 onCancelled in AsyncTask requires min API 11 add TargetApi annotations --- sdk/src/com/appnexus/opensdk/AdRequest.java | 4 ++-- sdk/src/com/appnexus/opensdk/utils/HTTPGet.java | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/sdk/src/com/appnexus/opensdk/AdRequest.java b/sdk/src/com/appnexus/opensdk/AdRequest.java index 6dd03435a..31cacd33f 100644 --- a/sdk/src/com/appnexus/opensdk/AdRequest.java +++ b/sdk/src/com/appnexus/opensdk/AdRequest.java @@ -16,10 +16,10 @@ package com.appnexus.opensdk; +import android.annotation.TargetApi; import android.content.Context; import android.content.pm.PackageManager; import android.content.res.Configuration; -import android.location.Criteria; import android.location.Location; import android.location.LocationManager; import android.net.ConnectivityManager; @@ -27,7 +27,6 @@ import android.net.Uri; import android.os.AsyncTask; import android.os.Build; -import android.os.Handler; import android.provider.Settings.Secure; import android.telephony.TelephonyManager; import android.util.Pair; @@ -502,6 +501,7 @@ protected void onPostExecute(AdResponse result) { adListener.onAdLoaded(owner); } + @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override protected void onCancelled(AdResponse adResponse) { super.onCancelled(adResponse); diff --git a/sdk/src/com/appnexus/opensdk/utils/HTTPGet.java b/sdk/src/com/appnexus/opensdk/utils/HTTPGet.java index 05ca32a6d..3f40015f0 100644 --- a/sdk/src/com/appnexus/opensdk/utils/HTTPGet.java +++ b/sdk/src/com/appnexus/opensdk/utils/HTTPGet.java @@ -16,7 +16,9 @@ package com.appnexus.opensdk.utils; +import android.annotation.TargetApi; import android.os.AsyncTask; +import android.os.Build; import org.apache.http.HttpResponse; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; @@ -70,6 +72,7 @@ protected HTTPResponse doInBackground(Void... params) { @Override abstract protected void onPostExecute(HTTPResponse response); + @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override protected void onCancelled(HTTPResponse response) { super.onCancelled(null); From da14ad5ac9bbd50211be50bc044e474b24275525 Mon Sep 17 00:00:00 2001 From: Mark Ha Date: Fri, 20 Dec 2013 11:22:09 -0500 Subject: [PATCH 34/34] MS-405 Location not reporting add location age --- sdk/src/com/appnexus/opensdk/AdRequest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/src/com/appnexus/opensdk/AdRequest.java b/sdk/src/com/appnexus/opensdk/AdRequest.java index 31cacd33f..f6c9ff931 100644 --- a/sdk/src/com/appnexus/opensdk/AdRequest.java +++ b/sdk/src/com/appnexus/opensdk/AdRequest.java @@ -194,6 +194,7 @@ public AdRequest(AdRequester adRequester) { if(lastLocation!=null){ lat = ""+lastLocation.getLatitude(); lon = ""+lastLocation.getLongitude(); + locDataAge = "" + (System.currentTimeMillis() - lastLocation.getTime()); locDataPrecision = ""+lastLocation.getAccuracy(); } } else {