Search in sources :

Example 1 with VisibilityChecker

use of org.prebid.mobile.rendering.utils.helpers.VisibilityChecker 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 2 with VisibilityChecker

use of org.prebid.mobile.rendering.utils.helpers.VisibilityChecker 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 3 with VisibilityChecker

use of org.prebid.mobile.rendering.utils.helpers.VisibilityChecker in project prebid-mobile-android by prebid.

the class CreativeVisibilityTrackerTest method hasRequiredTimeElapsedWithStartTimeSet_And_ElapsedTimeLessThanMinTimeViewed_ReturnFalse.

@Test
public void hasRequiredTimeElapsedWithStartTimeSet_And_ElapsedTimeLessThanMinTimeViewed_ReturnFalse() {
    mSpyVisibilityChecker = new VisibilityChecker(new VisibilityTrackerOption(NativeEventTracker.EventType.VIEWABLE_MRC50));
    mSpyVisibilityChecker.setStartTimeMillis();
    // minVisibleMillis is 1 sec, should return false since we are checking immediately before 1 sec elapses
    assertFalse(mSpyVisibilityChecker.hasRequiredTimeElapsed());
}
Also used : VisibilityChecker(org.prebid.mobile.rendering.utils.helpers.VisibilityChecker) VisibilityTrackerOption(org.prebid.mobile.rendering.models.internal.VisibilityTrackerOption) Test(org.junit.Test)

Example 4 with VisibilityChecker

use of org.prebid.mobile.rendering.utils.helpers.VisibilityChecker in project prebid-mobile-android by prebid.

the class CreativeVisibilityTrackerTest method mockVisibilityChecker.

private void mockVisibilityChecker(CreativeVisibilityTracker visibilityTracker, ViewExposure desiredViewExposure, Set<VisibilityTrackerOption> optionSet) {
    List<VisibilityChecker> visibilityCheckerList = new ArrayList<>();
    for (VisibilityTrackerOption trackerOption : optionSet) {
        VisibilityChecker visibilityChecker = spy(new VisibilityChecker(trackerOption));
        when(visibilityChecker.checkViewExposure(any(View.class))).thenReturn(desiredViewExposure);
        visibilityCheckerList.add(visibilityChecker);
    }
    WhiteBox.setInternalState(visibilityTracker, "mVisibilityCheckerList", visibilityCheckerList);
}
Also used : VisibilityChecker(org.prebid.mobile.rendering.utils.helpers.VisibilityChecker) ArrayList(java.util.ArrayList) VisibilityTrackerOption(org.prebid.mobile.rendering.models.internal.VisibilityTrackerOption) View(android.view.View)

Example 5 with VisibilityChecker

use of org.prebid.mobile.rendering.utils.helpers.VisibilityChecker in project prebid-mobile-android by prebid.

the class BannerView method initBidLoader.

private void initBidLoader() {
    mBidLoader = new BidLoader(getContext(), mAdUnitConfig, mBidRequesterListener);
    final VisibilityTrackerOption visibilityTrackerOption = new VisibilityTrackerOption(NativeEventTracker.EventType.IMPRESSION);
    final VisibilityChecker visibilityChecker = new VisibilityChecker(visibilityTrackerOption);
    mBidLoader.setBidRefreshListener(() -> {
        if (mAdFailed) {
            mAdFailed = false;
            return true;
        }
        final boolean isWindowVisibleToUser = mScreenStateReceiver.isScreenOn();
        return visibilityChecker.isVisibleForRefresh(this) && isWindowVisibleToUser;
    });
}
Also used : VisibilityChecker(org.prebid.mobile.rendering.utils.helpers.VisibilityChecker) BidLoader(org.prebid.mobile.rendering.bidding.loader.BidLoader) VisibilityTrackerOption(org.prebid.mobile.rendering.models.internal.VisibilityTrackerOption)

Aggregations

VisibilityChecker (org.prebid.mobile.rendering.utils.helpers.VisibilityChecker)6 VisibilityTrackerOption (org.prebid.mobile.rendering.models.internal.VisibilityTrackerOption)5 Test (org.junit.Test)2 View (android.view.View)1 AdView (com.google.android.gms.ads.AdView)1 MoPubView (com.mopub.mobileads.MoPubView)1 ArrayList (java.util.ArrayList)1 BidLoader (org.prebid.mobile.rendering.bidding.loader.BidLoader)1