Search in sources :

Example 41 with ResultCode

use of org.prebid.mobile.ResultCode in project prebid-mobile-android by prebid.

the class ExtraTests method testPostDataWithContext.

@Test
public void testPostDataWithContext() throws Exception {
    server.setDispatcher(new Dispatcher() {

        @Override
        public MockResponse dispatch(RecordedRequest request) {
            if (request.getPath().equals("/testPostData")) {
                String postDataString = request.getBody().readUtf8();
                try {
                    JSONObject postData = new JSONObject(postDataString);
                    JSONObject device = postData.getJSONObject("device");
                    String ifa = device.getString("ifa");
                    assertTrue(ifa != null && !ifa.isEmpty());
                    String ua = device.getString("ua");
                    assertTrue(ua != null && !ua.isEmpty());
                } catch (JSONException e) {
                    fail("error:" + e);
                }
                return getAppNexusDemand(postDataString);
            }
            return new MockResponse().setResponseCode(404);
        }
    });
    PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
    PrebidMobile.setPrebidServerAccountId("1001");
    PrebidMobile.setPrebidServerHost(Host.CUSTOM);
    Host.CUSTOM.setHostUrl(server.url("testPostData").toString());
    mHandler.post(new Runnable() {

        @Override
        public void run() {
            BannerAdUnit adUnit = new BannerAdUnit("1001-1", 300, 250);
            final MoPubView adObject = new MoPubView(m.getActivity());
            adUnit.fetchDemand(adObject, new OnCompleteListener() {

                @Override
                public void onComplete(ResultCode resultCode) {
                }
            });
        }
    });
    Thread.sleep(5_000);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) OnCompleteListener(org.prebid.mobile.OnCompleteListener) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) Matchers.containsString(org.hamcrest.Matchers.containsString) Dispatcher(okhttp3.mockwebserver.Dispatcher) ResultCode(org.prebid.mobile.ResultCode) BannerAdUnit(org.prebid.mobile.BannerAdUnit) MoPubView(com.mopub.mobileads.MoPubView) Test(org.junit.Test)

Example 42 with ResultCode

use of org.prebid.mobile.ResultCode in project prebid-mobile-android by prebid.

the class XandrNativeInBannerMoPubDemoActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_demo);
    PrebidMobile.setPrebidServerHost(Host.APPNEXUS);
    PrebidMobile.setPrebidServerAccountId(Constants.PBS_ACCOUNT_ID_APPNEXUS);
    adUnit = new NativeAdUnit(Constants.PBS_CONFIG_ID_NATIVE_APPNEXUS);
    final FrameLayout adFrame = (FrameLayout) findViewById(R.id.adFrame);
    adFrame.removeAllViews();
    final MoPubView adView = new MoPubView(this);
    adView.setAdUnitId(Constants.MOPUB_IN_BANNER_NATIVE_ADUNIT_ID_APPNEXUS);
    adView.setBannerAdListener(new MoPubView.BannerAdListener() {

        @Override
        public void onBannerLoaded(final MoPubView banner) {
            adFrame.addView(banner);
        }

        @Override
        public void onBannerFailed(MoPubView banner, MoPubErrorCode errorCode) {
            LogUtil.d("Banner failed " + errorCode);
        }

        @Override
        public void onBannerClicked(MoPubView banner) {
        }

        @Override
        public void onBannerExpanded(MoPubView banner) {
        }

        @Override
        public void onBannerCollapsed(MoPubView banner) {
        }
    });
    adView.setAutorefreshEnabled(false);
    NativeAdUnit nativeAdUnit = (NativeAdUnit) adUnit;
    nativeAdUnit.setContextType(NativeAdUnit.CONTEXT_TYPE.SOCIAL_CENTRIC);
    nativeAdUnit.setPlacementType(NativeAdUnit.PLACEMENTTYPE.CONTENT_FEED);
    nativeAdUnit.setContextSubType(NativeAdUnit.CONTEXTSUBTYPE.GENERAL_SOCIAL);
    ArrayList<NativeEventTracker.EVENT_TRACKING_METHOD> methods = new ArrayList<>();
    methods.add(NativeEventTracker.EVENT_TRACKING_METHOD.IMAGE);
    methods.add(NativeEventTracker.EVENT_TRACKING_METHOD.JS);
    try {
        NativeEventTracker tracker = new NativeEventTracker(NativeEventTracker.EVENT_TYPE.IMPRESSION, methods);
        nativeAdUnit.addEventTracker(tracker);
    } catch (Exception e) {
        e.printStackTrace();
    }
    NativeTitleAsset title = new NativeTitleAsset();
    title.setLength(90);
    title.setRequired(true);
    nativeAdUnit.addAsset(title);
    NativeImageAsset icon = new NativeImageAsset();
    icon.setImageType(NativeImageAsset.IMAGE_TYPE.ICON);
    icon.setWMin(20);
    icon.setHMin(20);
    icon.setRequired(true);
    nativeAdUnit.addAsset(icon);
    NativeImageAsset image = new NativeImageAsset();
    image.setImageType(NativeImageAsset.IMAGE_TYPE.MAIN);
    image.setHMin(200);
    image.setWMin(200);
    image.setRequired(true);
    nativeAdUnit.addAsset(image);
    NativeDataAsset data = new NativeDataAsset();
    data.setLen(90);
    data.setDataType(NativeDataAsset.DATA_TYPE.SPONSORED);
    data.setRequired(true);
    nativeAdUnit.addAsset(data);
    NativeDataAsset body = new NativeDataAsset();
    body.setRequired(true);
    body.setDataType(NativeDataAsset.DATA_TYPE.DESC);
    nativeAdUnit.addAsset(body);
    NativeDataAsset cta = new NativeDataAsset();
    cta.setRequired(true);
    cta.setDataType(NativeDataAsset.DATA_TYPE.CTATEXT);
    nativeAdUnit.addAsset(cta);
    int millis = getIntent().getIntExtra(Constants.AUTO_REFRESH_NAME, 0);
    nativeAdUnit.setAutoRefreshPeriodMillis(millis);
    nativeAdUnit.fetchDemand(adView, new OnCompleteListener() {

        @Override
        public void onComplete(ResultCode resultCode) {
            adView.loadAd(MoPubView.MoPubAdSize.MATCH_VIEW);
        }
    });
}
Also used : MoPubErrorCode(com.mopub.mobileads.MoPubErrorCode) ArrayList(java.util.ArrayList) NativeTitleAsset(org.prebid.mobile.NativeTitleAsset) NativeDataAsset(org.prebid.mobile.NativeDataAsset) NativeAdUnit(org.prebid.mobile.NativeAdUnit) OnCompleteListener(org.prebid.mobile.OnCompleteListener) NativeImageAsset(org.prebid.mobile.NativeImageAsset) FrameLayout(android.widget.FrameLayout) NativeEventTracker(org.prebid.mobile.NativeEventTracker) ResultCode(org.prebid.mobile.ResultCode) MoPubView(com.mopub.mobileads.MoPubView)

Aggregations

ResultCode (org.prebid.mobile.ResultCode)42 OnCompleteListener (org.prebid.mobile.OnCompleteListener)41 BannerAdUnit (org.prebid.mobile.BannerAdUnit)29 FrameLayout (android.widget.FrameLayout)27 Test (org.junit.Test)25 MoPubView (com.mopub.mobileads.MoPubView)23 AdManagerAdRequest (com.google.android.gms.ads.admanager.AdManagerAdRequest)14 MockResponse (okhttp3.mockwebserver.MockResponse)9 NonNull (androidx.annotation.NonNull)7 ArrayList (java.util.ArrayList)7 Matchers.containsString (org.hamcrest.Matchers.containsString)7 AdUnit (org.prebid.mobile.AdUnit)7 InterstitialAdUnit (org.prebid.mobile.InterstitialAdUnit)7 AdManagerAdView (com.google.android.gms.ads.admanager.AdManagerAdView)6 Dispatcher (okhttp3.mockwebserver.Dispatcher)6 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)6 AdListener (com.google.android.gms.ads.AdListener)5 LoadAdError (com.google.android.gms.ads.LoadAdError)5 VideoBaseAdUnit (org.prebid.mobile.VideoBaseAdUnit)5 AdSize (com.google.android.gms.ads.AdSize)4