Search in sources :

Example 1 with MoPubView

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();
    }
}
Also used : MoPubErrorCode(com.mopub.mobileads.MoPubErrorCode) ImageButton(android.widget.ImageButton) MoPubView(com.mopub.mobileads.MoPubView)

Example 2 with MoPubView

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
}
Also used : FrameLayout(android.widget.FrameLayout) MoPubView(com.mopub.mobileads.MoPubView)

Example 3 with MoPubView

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);
    });
}
Also used : MoPubView(com.mopub.mobileads.MoPubView)

Example 4 with MoPubView

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;
}
Also used : VisibilityChecker(org.prebid.mobile.rendering.utils.helpers.VisibilityChecker) VisibilityTrackerOption(org.prebid.mobile.rendering.models.internal.VisibilityTrackerOption) MoPubView(com.mopub.mobileads.MoPubView)

Example 5 with MoPubView

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());
}
Also used : HashMap(java.util.HashMap) MoPubBannerMediationUtils(com.mopub.mediation.MoPubBannerMediationUtils) MoPubView(com.mopub.mobileads.MoPubView) Test(org.junit.Test)

Aggregations

MoPubView (com.mopub.mobileads.MoPubView)48 Test (org.junit.Test)38 FrameLayout (android.widget.FrameLayout)26 BannerAdUnit (org.prebid.mobile.BannerAdUnit)23 OnCompleteListener (org.prebid.mobile.OnCompleteListener)23 ResultCode (org.prebid.mobile.ResultCode)23 MockResponse (okhttp3.mockwebserver.MockResponse)15 HttpUrl (okhttp3.HttpUrl)8 Dispatcher (okhttp3.mockwebserver.Dispatcher)8 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)8 Matchers.containsString (org.hamcrest.Matchers.containsString)7 BackgroundThreadExecutor (org.prebid.mobile.tasksmanager.BackgroundThreadExecutor)7 ShadowLooper (org.robolectric.shadows.ShadowLooper)7 MoPubInterstitial (com.mopub.mobileads.MoPubInterstitial)5 JSONException (org.json.JSONException)5 ArrayList (java.util.ArrayList)4 JSONObject (org.json.JSONObject)4 AdUnit (org.prebid.mobile.AdUnit)4 InterstitialAdUnit (org.prebid.mobile.InterstitialAdUnit)4 MoPubErrorCode (com.mopub.mobileads.MoPubErrorCode)3