use of com.mopub.mobileads.MoPubView in project frostwire by frostwire.
the class PreviewPlayerActivity method initMopubView.
private void initMopubView() {
if (Offers.disabledAds()) {
hideHorizontalAdContainer();
return;
}
if (!UIUtils.diceRollPassesThreshold(ConfigurationManager.instance(), Constants.PREF_KEY_GUI_MOPUB_PREVIEW_BANNER_THRESHOLD)) {
return;
}
mopubView = findViewById(R.id.activity_preview_player_mopubview);
advertisementHeaderLayout = findViewById(R.id.activity_preview_advertisement_header_layout);
fallbackImageView = findView(R.id.activity_preview_fallback_imageview);
final ImageButton dismissButton = findViewById(R.id.audio_player_dismiss_mopubview_button);
if (mopubView == null || advertisementHeaderLayout == null || dismissButton == null) {
return;
}
fallbackImageView.setVisibility(View.GONE);
dismissButton.setOnClickListener(view -> {
destroyMopubView();
fallbackImageView.setVisibility(View.GONE);
});
mopubView.setTesting(false);
mopubView.setAutorefreshEnabled(true);
isVertical = getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
mopubView.setAdUnitId(isVertical ? "a8be0cad4ad0419dbb19601aef3a18d2" : "2fd0fafe3d3c4d668385a620caaa694e");
mopubView.setKeywords("music,audio,ringtone,video,music video");
mopubView.setBannerAdListener(new MoPubView.BannerAdListener() {
@Override
public void onBannerLoaded(MoPubView banner) {
mopubLoaded = true;
if (!isFullScreen) {
setViewsVisibility(View.VISIBLE, advertisementHeaderLayout, mopubView);
fallbackImageView.setVisibility(View.GONE);
PrebidManager.getInstance(getApplicationContext()).onBannerLoaded(PreviewPlayerActivity.this, banner, isVertical ? PrebidManager.Placement.PREVIEW_BANNER_PORTRAIT_320_50 : PrebidManager.Placement.PREVIEW_BANNER_LANDSCAPE_300_250);
}
}
@Override
public void onBannerFailed(MoPubView banner, MoPubErrorCode errorCode) {
PrebidManager.getInstance(getApplicationContext()).onBannerFailed(PreviewPlayerActivity.this, banner, isVertical ? PrebidManager.Placement.PREVIEW_BANNER_PORTRAIT_320_50 : PrebidManager.Placement.PREVIEW_BANNER_LANDSCAPE_300_250, errorCode);
// mopubLoaded = false, also hides the ad-header view ("advertisement")
destroyMopubView();
if (!Offers.disabledAds()) {
loadFallbackBanner();
} else {
hideHorizontalAdContainer();
}
}
@Override
public void onBannerClicked(MoPubView banner) {
}
@Override
public void onBannerExpanded(MoPubView banner) {
}
@Override
public void onBannerCollapsed(MoPubView banner) {
}
});
try {
mopubView.loadAd();
} catch (Throwable e) {
LOG.warn("AudioPlayer Mopub banner could not be loaded", e);
mopubLoaded = false;
loadFallbackBanner();
}
}
use of com.mopub.mobileads.MoPubView in project prebid-mobile-android by prebid.
the class MoPubBannerFragment method setupBannerWithWait.
private void setupBannerWithWait(final int waitTime) {
FrameLayout adFrame = (FrameLayout) root.findViewById(R.id.adFrame2);
adFrame.removeAllViews();
adView2 = new MoPubView(this.getActivity());
adView2.setAdUnitId(Constants.MOPUB_BANNER_ADUNIT_ID_300x250);
adView2.setBannerAdListener(this);
adView2.setAutorefreshEnabled(true);
adView2.setMinimumWidth(300);
adView2.setMinimumHeight(250);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lp.gravity = Gravity.CENTER;
adView2.setLayoutParams(lp);
adFrame.addView(adView2);
// region Prebid API usage
Prebid.attachBidsWhenReady(adView2, Constants.BANNER_300x250, this, waitTime, this.getActivity());
// endregion
}
use of com.mopub.mobileads.MoPubView in project prebid-mobile-android by prebid.
the class MoPubBannerMediationUtils method setResponseToLocalExtras.
@Override
public void setResponseToLocalExtras(@Nullable BidResponse response) {
setResponseToLocalExtras(response, localExtras -> {
MoPubView adView = adViewReference.get();
if (isAdViewNull(adView)) {
return;
}
adView.setLocalExtras(localExtras);
});
}
use of com.mopub.mobileads.MoPubView in project prebid-mobile-android by prebid.
the class MoPubBannerMediationUtils method canPerformRefresh.
@Override
public boolean canPerformRefresh() {
MoPubView adView = adViewReference.get();
if (isAdViewNull(adView)) {
return false;
}
final VisibilityTrackerOption visibilityTrackerOption = new VisibilityTrackerOption(NativeEventTracker.EventType.IMPRESSION);
final VisibilityChecker checker = new VisibilityChecker(visibilityTrackerOption);
boolean isVisible = checker.isVisibleForRefresh(adView);
if (isVisible) {
Log.d(TAG, "Visibility checker result: " + true);
} else {
Log.e(TAG, "Can't perform refresh. Ad view is not visible.");
}
return isVisible;
}
use of com.mopub.mobileads.MoPubView in project prebid-mobile-android by prebid.
the class KeywordsSetupTest method handleMoPubKeywordsUpdateWithBanner_KeyWordsShouldMatchExpected.
@Test
public void handleMoPubKeywordsUpdateWithBanner_KeyWordsShouldMatchExpected() {
MoPubView adView = new MoPubView(mActivity);
MoPubBannerMediationUtils mediationUtils = new MoPubBannerMediationUtils(adView);
adView.setKeywords("key1:value1,key2:value2");
HashMap<String, String> bids = new HashMap<>();
bids.put("hb_pb", "0.50");
bids.put("hb_cache_id", "123456");
mediationUtils.handleKeywordsUpdate(bids);
String adViewKeywords = adView.getKeywords();
assertEquals("hb_pb:0.50,hb_cache_id:123456,key1:value1,key2:value2", adViewKeywords);
mediationUtils.handleKeywordsUpdate(null);
assertEquals("key1:value1,key2:value2", adView.getKeywords());
}
Aggregations