Search in sources :

Example 1 with VisibilityTrackerOption

use of org.prebid.mobile.rendering.models.internal.VisibilityTrackerOption in project prebid-mobile-android by prebid.

the class HTMLCreative method startViewabilityTracker.

@Override
public void startViewabilityTracker() {
    VisibilityTrackerOption visibilityTrackerOption = new VisibilityTrackerOption(NativeEventTracker.EventType.IMPRESSION);
    mCreativeVisibilityTracker = new CreativeVisibilityTracker(getCreativeView().getWebView(), visibilityTrackerOption, ((PrebidWebViewBase) getCreativeView()).getWebView().isMRAID());
    mCreativeVisibilityTracker.setVisibilityTrackerListener(this::onVisibilityEvent);
    mCreativeVisibilityTracker.startVisibilityCheck(mContextReference.get());
}
Also used : VisibilityTrackerOption(org.prebid.mobile.rendering.models.internal.VisibilityTrackerOption)

Example 2 with VisibilityTrackerOption

use of org.prebid.mobile.rendering.models.internal.VisibilityTrackerOption in project prebid-mobile-android by prebid.

the class AdMobBannerMediationUtils method canPerformRefresh.

@Override
public boolean canPerformRefresh() {
    AdView view = adView.get();
    if (view == null) {
        LogUtil.e(TAG, "AdView is null, it can be destroyed as WeakReference");
        return false;
    }
    final VisibilityTrackerOption visibilityTrackerOption = new VisibilityTrackerOption(NativeEventTracker.EventType.IMPRESSION);
    final VisibilityChecker checker = new VisibilityChecker(visibilityTrackerOption);
    boolean isVisible = checker.isVisibleForRefresh(view);
    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) AdView(com.google.android.gms.ads.AdView) VisibilityTrackerOption(org.prebid.mobile.rendering.models.internal.VisibilityTrackerOption)

Example 3 with VisibilityTrackerOption

use of org.prebid.mobile.rendering.models.internal.VisibilityTrackerOption 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 4 with VisibilityTrackerOption

use of org.prebid.mobile.rendering.models.internal.VisibilityTrackerOption in project prebid-mobile-android by prebid.

the class CreativeVisibilityTrackerTest method visibilityRunnable_runWithViewVisibleForAtLeastMinDuration_CallOnVisibilityChanged_ImpTrackerFiredTrue_IsVisibilityScheduledFalse.

// VisibilityRunnable Tests
@Test
public void visibilityRunnable_runWithViewVisibleForAtLeastMinDuration_CallOnVisibilityChanged_ImpTrackerFiredTrue_IsVisibilityScheduledFalse() throws Exception {
    ViewExposure viewExposure = new ViewExposure(100, new Rect(0, 0, 100, 100), null);
    when(mSpyVisibilityChecker.isVisible(any(View.class))).thenReturn(true);
    when(mSpyVisibilityChecker.checkViewExposure(any(View.class))).thenReturn(viewExposure);
    when(mSpyVisibilityChecker.hasBeenVisible()).thenReturn(true);
    when(mSpyVisibilityChecker.hasRequiredTimeElapsed()).thenReturn(true);
    mCreativeVisibilityTracker.mVisibilityRunnable.run();
    VisibilityTrackerResult result = new VisibilityTrackerResult(NativeEventTracker.EventType.IMPRESSION, viewExposure, true, true);
    verify(mMockVisibilityTrackerListener).onVisibilityChanged(result);
    final VisibilityTrackerOption visibilityTrackerOption = mSpyVisibilityChecker.getVisibilityTrackerOption();
    assertTrue(visibilityTrackerOption.isImpressionTracked());
    assertFalse((Boolean) getFieldValue("mIsVisibilityScheduled"));
}
Also used : Rect(android.graphics.Rect) VisibilityTrackerResult(org.prebid.mobile.rendering.models.internal.VisibilityTrackerResult) ViewExposure(org.prebid.mobile.rendering.utils.exposure.ViewExposure) View(android.view.View) VisibilityTrackerOption(org.prebid.mobile.rendering.models.internal.VisibilityTrackerOption) Test(org.junit.Test)

Example 5 with VisibilityTrackerOption

use of org.prebid.mobile.rendering.models.internal.VisibilityTrackerOption in project prebid-mobile-android by prebid.

the class CreativeVisibilityTrackerTest method visibilityRunnable_runWithMultipleTrackingOptions_CallOnVisibilityChangedIndependently_NoTrackForVideo.

@Test
public void visibilityRunnable_runWithMultipleTrackingOptions_CallOnVisibilityChangedIndependently_NoTrackForVideo() {
    mockView();
    VisibilityTrackerOption trackerOptionImpression = new VisibilityTrackerOption(NativeEventTracker.EventType.IMPRESSION);
    VisibilityTrackerOption trackerOptionMrc50 = new VisibilityTrackerOption(NativeEventTracker.EventType.VIEWABLE_MRC50);
    VisibilityTrackerOption trackerOptionMrc100 = new VisibilityTrackerOption(NativeEventTracker.EventType.VIEWABLE_MRC100);
    VisibilityTrackerOption trackerOptionViewableVideo50 = new VisibilityTrackerOption(NativeEventTracker.EventType.VIEWABLE_VIDEO50);
    final ViewExposure viewExposure = new ViewExposure(1.0f, new Rect(), new ArrayList<>());
    Set<VisibilityTrackerOption> visibilityTrackerOptionSet = new HashSet<>();
    visibilityTrackerOptionSet.add(trackerOptionImpression);
    visibilityTrackerOptionSet.add(trackerOptionMrc50);
    visibilityTrackerOptionSet.add(trackerOptionMrc100);
    visibilityTrackerOptionSet.add(trackerOptionViewableVideo50);
    CreativeVisibilityTracker creativeVisibilityTracker = new CreativeVisibilityTracker(mMockView, visibilityTrackerOptionSet);
    creativeVisibilityTracker.setVisibilityTrackerListener(mMockVisibilityTrackerListener);
    mockVisibilityChecker(creativeVisibilityTracker, viewExposure, visibilityTrackerOptionSet);
    creativeVisibilityTracker.mVisibilityRunnable.run();
    // 0 sec visibility duration
    assertTrue(trackerOptionImpression.isImpressionTracked());
    ShadowSystemClock.advanceBy(Duration.ofMillis(1000));
    // 1 sec visibility duration
    assertTrue(trackerOptionMrc50.isImpressionTracked());
    assertTrue(trackerOptionMrc100.isImpressionTracked());
    // 2 sec visibility duration
    assertFalse(trackerOptionViewableVideo50.isImpressionTracked());
    VisibilityTrackerResult impressionResult = new VisibilityTrackerResult(NativeEventTracker.EventType.IMPRESSION, viewExposure, true, true);
    VisibilityTrackerResult mrc50Result = new VisibilityTrackerResult(NativeEventTracker.EventType.VIEWABLE_MRC50, viewExposure, true, true);
    VisibilityTrackerResult mrc100Result = new VisibilityTrackerResult(NativeEventTracker.EventType.VIEWABLE_MRC100, viewExposure, true, true);
    VisibilityTrackerResult videoResult = new VisibilityTrackerResult(NativeEventTracker.EventType.VIEWABLE_VIDEO50, viewExposure, true, true);
    verify(mMockVisibilityTrackerListener, times(1)).onVisibilityChanged(eq(impressionResult));
    verify(mMockVisibilityTrackerListener, times(1)).onVisibilityChanged(eq(mrc50Result));
    verify(mMockVisibilityTrackerListener, times(1)).onVisibilityChanged(eq(mrc100Result));
    verify(mMockVisibilityTrackerListener, times(0)).onVisibilityChanged(eq(videoResult));
}
Also used : Rect(android.graphics.Rect) VisibilityTrackerResult(org.prebid.mobile.rendering.models.internal.VisibilityTrackerResult) VisibilityTrackerOption(org.prebid.mobile.rendering.models.internal.VisibilityTrackerOption) ViewExposure(org.prebid.mobile.rendering.utils.exposure.ViewExposure) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

VisibilityTrackerOption (org.prebid.mobile.rendering.models.internal.VisibilityTrackerOption)12 Test (org.junit.Test)5 VisibilityChecker (org.prebid.mobile.rendering.utils.helpers.VisibilityChecker)5 View (android.view.View)4 VisibilityTrackerResult (org.prebid.mobile.rendering.models.internal.VisibilityTrackerResult)4 ViewExposure (org.prebid.mobile.rendering.utils.exposure.ViewExposure)3 Rect (android.graphics.Rect)2 CreativeVisibilityTracker (org.prebid.mobile.rendering.models.CreativeVisibilityTracker)2 AdView (com.google.android.gms.ads.AdView)1 MoPubView (com.mopub.mobileads.MoPubView)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 BidLoader (org.prebid.mobile.rendering.bidding.loader.BidLoader)1