com.mopub.nativeads.StaticNativeAd Java Examples
The following examples show how to use
com.mopub.nativeads.StaticNativeAd.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TwitterStaticNativeAdRenderer.java From twitter-kit-android with Apache License 2.0 | 6 votes |
private void update(final TwitterStaticNativeAd staticNativeView, final StaticNativeAd staticNativeAd) { NativeRendererHelper.addTextView(staticNativeView.adTitleView, staticNativeAd.getTitle()); NativeRendererHelper.addTextView(staticNativeView.adTextView, staticNativeAd.getText()); NativeRendererHelper.addTextView(staticNativeView.callToActionView, staticNativeAd.getCallToAction()); NativeImageHelper.loadImageView(staticNativeAd.getMainImageUrl(), staticNativeView.mainImageView); NativeImageHelper.loadImageView(staticNativeAd.getIconImageUrl(), staticNativeView.adIconView); NativeRendererHelper.addPrivacyInformationIcon( staticNativeView.privacyInfoView, staticNativeAd.getPrivacyInformationIconImageUrl(), staticNativeAd.getPrivacyInformationIconClickThroughUrl()); }
Example #2
Source File: TwitterStaticNativeAdRendererTest.java From twitter-kit-android with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); Networking.setImageLoaderForTesting(mockImageLoader); doReturn(mockBitmap).when(mockImageContainer).getBitmap(); doAnswer(invocation -> { final Object[] args = invocation.getArguments(); ((ImageLoader.ImageListener) args[1]).onResponse(mockImageContainer, true); return null; }).when(mockImageLoader).get(anyString(), any(ImageLoader.ImageListener.class)); twitterStaticNativeAdRenderer = new TwitterStaticNativeAdRenderer(); twitterStaticNativeAd = new TwitterStaticNativeAd(RuntimeEnvironment.application); twitterStaticNativeAd.adTextView = mock(TextView.class); twitterStaticNativeAd.adTitleView = mock(TextView.class); twitterStaticNativeAd.callToActionView = mock(TextView.class); twitterStaticNativeAd.mainImageView = mock(RoundedImageView.class); twitterStaticNativeAd.adIconView = mock(ImageView.class); twitterStaticNativeAd.privacyInfoView = mock(ImageView.class); staticNativeAd = new StaticNativeAd() { }; staticNativeAd.setTitle(TEST_TITLE); staticNativeAd.setText(TEST_TEXT); staticNativeAd.setCallToAction(TEST_CTA); staticNativeAd.setClickDestinationUrl(TEST_URL); staticNativeAd.setMainImageUrl(TEST_URL); staticNativeAd.setIconImageUrl(TEST_URL); staticNativeAd.setPrivacyInformationIconClickThroughUrl(TEST_URL); staticNativeAd.setPrivacyInformationIconImageUrl(TEST_URL); }
Example #3
Source File: MoPubNativeAppInstallAdMapper.java From googleads-mobile-android-mediation with Apache License 2.0 | 5 votes |
public MoPubNativeAppInstallAdMapper(@NonNull Context context, @NonNull StaticNativeAd ad, @Nullable Drawable icon, @Nullable Drawable nativeAdMainImage, int privacyIconPlacementParam, int privacyIconSize) { mMoPubNativeAdData = ad; setHeadline(mMoPubNativeAdData.getTitle()); setBody(mMoPubNativeAdData.getText()); setCallToAction(mMoPubNativeAdData.getCallToAction()); privacyIconPlacement = privacyIconPlacementParam; mPrivacyIconSize = privacyIconSize; MoPubNativeMappedImage iconImage = new MoPubNativeMappedImage(icon, mMoPubNativeAdData.getIconImageUrl(), MoPubAdapter.DEFAULT_MOPUB_IMAGE_SCALE); setIcon(iconImage); MoPubNativeMappedImage mainImage = new MoPubNativeMappedImage( nativeAdMainImage, mMoPubNativeAdData.getMainImageUrl(), MoPubAdapter.DEFAULT_MOPUB_IMAGE_SCALE); List<NativeAd.Image> imagesList = new ArrayList<NativeAd.Image>(); imagesList.add(mainImage); setImages(imagesList); ImageView mediaView = new ImageView(context); mediaView.setImageDrawable(nativeAdMainImage); setMediaView(mediaView); setOverrideClickHandling(true); setOverrideImpressionRecording(true); }
Example #4
Source File: MoPubNativeAdResponse.java From mobile-sdk-android with Apache License 2.0 | 5 votes |
boolean setResources(NativeAd response) { if (response != null) { this.mopubNativeAd = response; BaseNativeAd baseNativeAd = response.getBaseNativeAd(); if (!(baseNativeAd instanceof StaticNativeAd)) { return false; } final StaticNativeAd staticNativeAd = (StaticNativeAd) baseNativeAd; this.title = staticNativeAd.getTitle(); this.description = staticNativeAd.getText(); this.imageUrl = staticNativeAd.getMainImageUrl(); this.iconUrl = staticNativeAd.getIconImageUrl(); this.callToAction = staticNativeAd.getCallToAction(); if (staticNativeAd.getStarRating() != null) { this.rating = new Rating(staticNativeAd.getStarRating(), 5.0); } if (!staticNativeAd.getExtras().isEmpty()) { // put extras in native response, MoPub returns String as Object for (Map.Entry<String, Object> entry : staticNativeAd.getExtras().entrySet()) { nativeElements.put(entry.getKey(), entry.getValue()); } } nativeElements.put(NATIVE_ELEMENT_OBJECT, response); if (staticNativeAd.getPrivacyInformationIconImageUrl() != null) { nativeElements.put(MoPubNativeSettings.KEY_PRIVACYINFO_ICONURL, staticNativeAd.getPrivacyInformationIconImageUrl()); } if (staticNativeAd.getPrivacyInformationIconClickThroughUrl() != null) { nativeElements.put(MoPubNativeSettings.KEY_PRIVACYINFO_LINKURL, staticNativeAd.getPrivacyInformationIconClickThroughUrl()); } return true; } return false; }
Example #5
Source File: TwitterStaticNativeAdRenderer.java From twitter-kit-android with Apache License 2.0 | 4 votes |
@Override public void renderAdView(final View view, final StaticNativeAd staticNativeAd) { update((TwitterStaticNativeAd) view, staticNativeAd); }
Example #6
Source File: TwitterStaticNativeAdRenderer.java From twitter-kit-android with Apache License 2.0 | 4 votes |
@Override public boolean supports(final BaseNativeAd nativeAd) { return nativeAd instanceof StaticNativeAd; }
Example #7
Source File: TwitterStaticNativeAdRendererTest.java From twitter-kit-android with Apache License 2.0 | 4 votes |
@Test public void testSupports_withCorrectInstanceOfBaseNativeAd_shouldReturnTrue() throws Exception { assertTrue(twitterStaticNativeAdRenderer.supports(new StaticNativeAd() {})); assertFalse(twitterStaticNativeAdRenderer.supports(mock(BaseNativeAd.class))); }
Example #8
Source File: MoPubUnifiedNativeAdMapper.java From googleads-mobile-android-mediation with Apache License 2.0 | 4 votes |
public MoPubUnifiedNativeAdMapper(@NonNull Context context, @NonNull StaticNativeAd ad, @Nullable Drawable icon, @Nullable Drawable nativeAdMainImage, int privacyIconPlacementParam, int privacyIconSize) { mMoPubNativeAdData = ad; setHeadline(mMoPubNativeAdData.getTitle()); setBody(mMoPubNativeAdData.getText()); setCallToAction(mMoPubNativeAdData.getCallToAction()); privacyIconPlacement = privacyIconPlacementParam; mPrivacyIconSize = privacyIconSize; MoPubNativeMappedImage iconImage = new MoPubNativeMappedImage(icon, mMoPubNativeAdData.getIconImageUrl(), MoPubAdapter.DEFAULT_MOPUB_IMAGE_SCALE); setIcon(iconImage); MoPubNativeMappedImage mainImage = new MoPubNativeMappedImage( nativeAdMainImage, mMoPubNativeAdData.getMainImageUrl(), MoPubAdapter.DEFAULT_MOPUB_IMAGE_SCALE); List<NativeAd.Image> imagesList = new ArrayList<NativeAd.Image>(); imagesList.add(mainImage); setImages(imagesList); int height = mainImage.getHeight(); int width = mainImage.getWidth(); float aspectRatio = 0.0f; if (height > 0) { aspectRatio = (float) (width / height); } setMediaContentAspectRatio(aspectRatio); ImageView mediaView = new ImageView(context); mediaView.setImageDrawable(nativeAdMainImage); setMediaView(mediaView); setOverrideClickHandling(true); setOverrideImpressionRecording(true); }