/** * Set the size of the ad to request. * Use only one out of setMaxSize(maxW,maxH) or setAdSize(w,h) or setAdSizes(ArrayList<AdSizes>). Using one will override the value set by other. * * @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)); ArrayList<AdSize> adSizeArrayList = new ArrayList(); adSizeArrayList.add(new AdSize(w, h)); setAdSizes(adSizeArrayList); }
private void warnIfRequestSizesDoesNotFitContainerSize(int containerWidth, int containerHeight) { if (containerWidth > 0 && containerHeight > 0 && requestParameters.getSizes() != null) { for (AdSize adsize : requestParameters.getSizes()) { if (containerHeight < adsize.height() || containerWidth < adsize.width()) { Clog.w(Clog.baseLogTag, Clog.getString(R.string.adsize_too_big, containerWidth, containerHeight, adsize.width(), adsize.height())); } } } }
allowedSizes.add(new AdSize(1, 1)); AdSize containerSize = new AdSize(containerWidth, containerHeight); allowedSizes.add(containerSize); if (new AdSize(300, 250).fitsIn(containerWidth, containerHeight)) allowedSizes.add(new AdSize(300, 250)); if (new AdSize(320, 480).fitsIn(containerWidth, containerHeight)) allowedSizes.add(new AdSize(320, 480)); if (new AdSize(900, 500).fitsIn(containerWidth, containerHeight)) allowedSizes.add(new AdSize(900, 500)); if (new AdSize(1024, 1024).fitsIn(containerWidth, containerHeight)) allowedSizes.add(new AdSize(1024, 1024));
/** * Check the maximum height of the ad to be requested. Previously set using setMaxSize(). * * @return The maximum height of the ad to be requested or * -1 if max height is not set or has been overridden by setAdSize/setAdSizes */ public int getMaxHeight() { Clog.d(Clog.baseLogTag, Clog.getString(R.string.get_max_height, requestParameters.getAllowSmallerSizes() ? requestParameters.getPrimarySize().height() : -1)); return requestParameters.getAllowSmallerSizes() ? requestParameters.getPrimarySize().height() : -1; }
/** * Check the maximum width of the ad to be requested. Previously set using setMaxSize(). * * @return The maximum width of the ad to be requested or * -1 if max width is not set or has been overridden by setAdSize()/setAdSizes() */ public int getMaxWidth() { Clog.d(Clog.baseLogTag, Clog.getString(R.string.get_max_width, requestParameters.getAllowSmallerSizes() ? requestParameters.getPrimarySize().width() : -1)); return requestParameters.getAllowSmallerSizes() ? requestParameters.getPrimarySize().width() : -1; }
/** * Check the height of the ad to be requested for this view. * * @return The height of the ad to request or * -1 if max height is used in the request. */ public int getAdHeight() { Clog.d(Clog.baseLogTag, Clog.getString(R.string.get_height, requestParameters.getAllowSmallerSizes() ? -1 : requestParameters.getPrimarySize().height())); return requestParameters.getAllowSmallerSizes() ? -1 : requestParameters.getPrimarySize().height(); }
/** * Check the width of the ad to be requested for this view. * * @return The width of the ad to request or * -1 if max width is used in the request. */ public int getAdWidth() { Clog.d(Clog.baseLogTag, Clog.getString(R.string.get_width, requestParameters.getAllowSmallerSizes() ? -1 : requestParameters.getPrimarySize().width())); return requestParameters.getAllowSmallerSizes() ? -1 : requestParameters.getPrimarySize().width(); }
/** * -------------------------- Helper methods -------------------------------- */ private void inspectSizes(ArrayList<AdSize> allowedSizes, JSONObject tag) throws JSONException { System.out.println("Checking sizes validity..."); assertTrue(tag.has("sizes")); JSONArray sizes = tag.getJSONArray("sizes"); assertEquals(allowedSizes.size(), sizes.length()); for (int i = 0; i < sizes.length(); i++) { JSONObject size = sizes.getJSONObject(i); assertNotNull(size); System.out.println("Validating size: (" + allowedSizes.get(i).width() + " , " + allowedSizes.get(i).height() + ")"); assertTrue(size.has("width")); assertEquals(allowedSizes.get(i).width(), size.getInt("width")); assertTrue(size.has("height")); assertEquals(allowedSizes.get(i).height(), size.getInt("height")); System.out.println("Size is valid!"); } System.out.println("Sizes validity passed!"); }
/** * Check if required parameters are set for a certain media type * * @return true if ready for request */ public boolean isReadyForRequest() { if ((StringUtil.isEmpty(invCode) || memberID <= 0) && StringUtil.isEmpty(placementID)) { Clog.e(Clog.baseLogTag, Clog.getString(R.string.no_identification)); return false; } if ((primarySize == null || (primarySize.width() <= 0 || primarySize.height() <= 0))) { Clog.e(Clog.baseLogTag, Clog.getString(R.string.no_size_info)); return false; } return true; }
/** * Set the ad {@link AdSize}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 AdSize}s * which are allowed to be displayed. */ public void setAllowedSizes(ArrayList<AdSize> allowed_sizes) { Clog.d(Clog.publicFunctionsLogTag, Clog.getString(R.string.set_allowed_sizes)); //append a 1x1 to this allowedSizes list AdSize oneByOne = new AdSize(1, 1); if (!allowed_sizes.contains(oneByOne)) allowed_sizes.add(oneByOne); //append container size for Interstitial AdSize containerSize = new AdSize(containerWidth, containerHeight); if (!allowed_sizes.contains(containerSize)) allowed_sizes.add(containerSize); requestParameters.setPrimarySize(containerSize); requestParameters.setSizes(allowed_sizes); requestParameters.setAllowSmallerSizes(false); }
private void assertSetAdSizesArray(){ assertTrue(bannerAdView.getAdWidth() == 10); assertTrue(bannerAdView.getAdHeight() == 10); assertTrue(bannerAdView.getAdSizes().size() == 3); assertTrue(bannerAdView.getAdSizes().get(0).width() == 10); assertTrue(bannerAdView.getAdSizes().get(0).height() == 10); assertTrue(bannerAdView.getAdSizes().get(1).width() == 320); assertTrue(bannerAdView.getAdSizes().get(1).height() == 50); assertTrue(bannerAdView.getAdSizes().get(2).width() == 300); assertTrue(bannerAdView.getAdSizes().get(2).height() == 250); assertTrue(bannerAdView.getMaxWidth() == -1); assertTrue(bannerAdView.getMaxHeight() == -1); }
@Test public void testSetAllowedSizes(){ ArrayList<AdSize> adSizeArrayList = new ArrayList<AdSize>(); adSizeArrayList.add(new AdSize(10,10)); adSizeArrayList.add(new AdSize(320,50)); adSizeArrayList.add(new AdSize(300,250)); adSizeArrayList.add(new AdSize(1024,768)); interstitialAdView.setAllowedSizes(adSizeArrayList); String postData = getRequestParametersPostData(); assertTrue(postData.contains("\"primary_size\":{\"width\":320,\"height\":496},")); assertTrue(postData.contains("\"sizes\":[{\"width\":10,\"height\":10},{\"width\":320,\"height\":50},{\"width\":300,\"height\":250},{\"width\":1024,\"height\":768},{\"width\":1,\"height\":1},{\"width\":320,\"height\":496}],")); assertTrue(postData.contains("\"allow_smaller_sizes\":false,")); }
private void assertSetAdSize(){ assertTrue(bannerAdView.getAdWidth() == 720); assertTrue(bannerAdView.getAdHeight() == 90); assertTrue(bannerAdView.getAdSizes().size() == 1); assertTrue(bannerAdView.getAdSizes().get(0).width() == 720); assertTrue(bannerAdView.getAdSizes().get(0).height() == 90); assertTrue(bannerAdView.getMaxWidth() == -1); assertTrue(bannerAdView.getMaxHeight() == -1); }
protected void setAllowedSizes() { Clog.d(Clog.nativeLogTag, Clog.getString(R.string.set_allowed_sizes)); AdSize oneByOneSize = new AdSize(1,1); ArrayList<AdSize> allowed_sizes = new ArrayList<AdSize>(); allowed_sizes.add(oneByOneSize); requestParameters.setSizes(allowed_sizes); requestParameters.setPrimarySize(oneByOneSize); requestParameters.setAllowSmallerSizes(false); }
/** * Set the maximum size of the desired ad. * Use only one out of setMaxSize(maxW,maxh) or setAdSize(w,h) or setAdSizes(ArrayList<AdSizes>). Using one will override the value set by other. * * @param maxW The maximum width in pixels. * @param maxH The maximum height in pixels. */ public void setMaxSize(int maxW, int maxH) { Clog.d(Clog.baseLogTag, Clog.getString(R.string.set_max_size, maxW, maxH)); AdSize maxAdSize = new AdSize(maxW, maxH); ArrayList<AdSize> adSizeArrayList = new ArrayList(); adSizeArrayList.add(maxAdSize); requestParameters.setPrimarySize(adSizeArrayList.get(0)); requestParameters.setSizes(adSizeArrayList); requestParameters.setAllowSmallerSizes(true); }
protected void setAllowedSizes() { Clog.d(Clog.videoLogTag, Clog.getString(com.appnexus.opensdk.R.string.set_allowed_sizes)); AdSize oneByOneSize = new AdSize(1, 1); ArrayList<AdSize> allowed_sizes = new ArrayList<AdSize>(); allowed_sizes.add(oneByOneSize); requestParameters.setSizes(allowed_sizes); requestParameters.setPrimarySize(oneByOneSize); requestParameters.setAllowSmallerSizes(false); }
public void setInterstitialRequestParams() { requestParameters.setPlacementID("0"); ArrayList<AdSize> allowedSizes = new ArrayList<AdSize>(); allowedSizes.add(new AdSize(300, 250)); requestParameters.setSizes(allowedSizes); requestParameters.setPrimarySize(new AdSize(1,1)); requestParameters.setMediaType(MediaType.INTERSTITIAL); }