Search in sources :

Example 1 with AdServerSettings

use of org.prebid.mobile.drprebid.model.AdServerSettings in project prebid-mobile-android by prebid.

the class SubmitViewHolder method validateSettings.

private boolean validateSettings() {
    AdServerSettings adServerSettings = SettingsManager.getInstance(itemView.getContext()).getAdServerSettings();
    PrebidServerSettings prebidServerSettings = SettingsManager.getInstance(itemView.getContext()).getPrebidServerSettings();
    boolean valid = true;
    if (TextUtils.isEmpty(adServerSettings.getAdUnitId())) {
        valid = false;
    }
    if (adServerSettings.getBidPrice() <= 0.0) {
        valid = false;
    }
    if (prebidServerSettings.getPrebidServer() == PrebidServer.CUSTOM && TextUtils.isEmpty(prebidServerSettings.getCustomPrebidServerUrl())) {
        valid = false;
    }
    if (TextUtils.isEmpty(prebidServerSettings.getAccountId())) {
        valid = false;
    }
    if (TextUtils.isEmpty(prebidServerSettings.getConfigId())) {
        valid = false;
    }
    return valid;
}
Also used : PrebidServerSettings(org.prebid.mobile.drprebid.model.PrebidServerSettings) AdServerSettings(org.prebid.mobile.drprebid.model.AdServerSettings)

Example 2 with AdServerSettings

use of org.prebid.mobile.drprebid.model.AdServerSettings in project prebid-mobile-android by prebid.

the class SdkTest method startTest.

public void startTest() {
    GeneralSettings generalSettings = SettingsManager.getInstance(mContext).getGeneralSettings();
    AdServerSettings adServerSettings = SettingsManager.getInstance(mContext).getAdServerSettings();
    if (adServerSettings.getAdServer() == AdServer.MOPUB) {
        if (generalSettings.getAdFormat() == AdFormat.BANNER) {
            AdSize adSize = generalSettings.getAdSize();
            FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(DimenUtil.convertPxToDp(mContext, adSize.getWidth()), DimenUtil.convertPxToDp(mContext, adSize.getHeight()));
            mMoPubBanner = new MoPubView(mContext);
            mMoPubBanner.setLayoutParams(layoutParams);
            mMoPubBanner.setAutorefreshEnabled(false);
            mMoPubBanner.setBannerAdListener(this);
            mMoPubBanner.setAdUnitId(adServerSettings.getAdUnitId());
            if (mAdUnit != null) {
                Networking.getRequestQueue(mContext).addRequestFinishedListener(mMoPubRequestFinishedListener);
                mAdUnit.fetchDemand(mMoPubBanner, resultCode -> {
                    checkPrebidLog();
                    mMoPubBanner.loadAd();
                });
                if (mListener != null) {
                    mListener.requestToPrebidServerSent(true);
                }
            }
        } else if (generalSettings.getAdFormat() == AdFormat.INTERSTITIAL) {
            mMoPubInterstitial = new MoPubInterstitial(mContext, adServerSettings.getAdUnitId());
            mMoPubInterstitial.setInterstitialAdListener(this);
            if (mAdUnit != null) {
                Networking.getRequestQueue(mContext).addRequestFinishedListener(mMoPubRequestFinishedListener);
                mAdUnit.fetchDemand(mMoPubInterstitial, resultCode -> {
                    checkPrebidLog();
                    mMoPubInterstitial.load();
                });
                if (mListener != null) {
                    mListener.requestToPrebidServerSent(true);
                }
            }
        }
    } else if (adServerSettings.getAdServer() == AdServer.GOOGLE_AD_MANAGER) {
        if (generalSettings.getAdFormat() == AdFormat.BANNER) {
            mGoogleBanner = new PublisherAdView(mContext);
            AdSize adSize = generalSettings.getAdSize();
            mGoogleBanner.setAdSizes(new com.google.android.gms.ads.AdSize(adSize.getWidth(), adSize.getHeight()));
            mGoogleBanner.setAdUnitId(adServerSettings.getAdUnitId());
            mGoogleBanner.setAdListener(mGoogleBannerListener);
        } else if (generalSettings.getAdFormat() == AdFormat.INTERSTITIAL) {
            mGoogleInterstitial = new PublisherInterstitialAd(mContext);
            mGoogleInterstitial.setAdUnitId(adServerSettings.getAdUnitId());
            mGoogleInterstitial.setAdListener(mGoogleInterstitialListener);
        }
        if (mAdUnit != null) {
            final Map<String, String> keywordsMap = new HashMap<>();
            mAdUnit.fetchDemand(keywordsMap, resultCode -> {
                boolean responseSuccess = false;
                if (resultCode == SUCCESS) {
                    responseSuccess = true;
                }
                boolean topBid = false;
                if (keywordsMap.containsKey("hb_cache_id")) {
                    topBid = true;
                }
                PublisherAdRequest.Builder adRequestBuilder = new PublisherAdRequest.Builder();
                for (Map.Entry<String, String> entry : keywordsMap.entrySet()) {
                    adRequestBuilder.addCustomTargeting(entry.getKey(), entry.getValue());
                }
                if (generalSettings.getAdFormat() == AdFormat.BANNER) {
                    mGoogleBanner.loadAd(adRequestBuilder.build());
                } else if (generalSettings.getAdFormat() == AdFormat.INTERSTITIAL) {
                    mGoogleInterstitial.loadAd(adRequestBuilder.build());
                }
                if (mListener != null) {
                    mListener.responseFromPrebidServerReceived(responseSuccess);
                    mListener.bidReceivedAndCached(topBid);
                    mListener.requestSentToAdServer("", "");
                }
            });
            if (mListener != null) {
                mListener.requestToPrebidServerSent(true);
            }
        }
    }
}
Also used : Networking(com.mopub.network.Networking) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) AdListener(com.google.android.gms.ads.AdListener) BannerAdUnit(org.prebid.mobile.BannerAdUnit) HashMap(java.util.HashMap) RequestBody(okhttp3.RequestBody) AdUnit(org.prebid.mobile.AdUnit) InterstitialAdUnit(org.prebid.mobile.InterstitialAdUnit) BidLog(org.prebid.mobile.BidLog) TargetingParams(org.prebid.mobile.TargetingParams) ByteArrayInputStream(java.io.ByteArrayInputStream) PublisherAdRequest(com.google.android.gms.ads.doubleclick.PublisherAdRequest) GeneralSettings(org.prebid.mobile.drprebid.model.GeneralSettings) Map(java.util.Map) AdServer(org.prebid.mobile.drprebid.model.AdServer) Response(okhttp3.Response) MoPubView(com.mopub.mobileads.MoPubView) Call(okhttp3.Call) Callback(okhttp3.Callback) IOUtil(org.prebid.mobile.drprebid.util.IOUtil) MoPubRequestQueue(com.mopub.network.MoPubRequestQueue) AdServerSettings(org.prebid.mobile.drprebid.model.AdServerSettings) Log(android.util.Log) DimenUtil(org.prebid.mobile.drprebid.util.DimenUtil) MediaType(okhttp3.MediaType) PublisherInterstitialAd(com.google.android.gms.ads.doubleclick.PublisherInterstitialAd) PublisherAdView(com.google.android.gms.ads.doubleclick.PublisherAdView) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) SettingsManager(org.prebid.mobile.drprebid.managers.SettingsManager) PrebidServerSettings(org.prebid.mobile.drprebid.model.PrebidServerSettings) SUCCESS(org.prebid.mobile.ResultCode.SUCCESS) TextUtils(android.text.TextUtils) IOException(java.io.IOException) AdSize(org.prebid.mobile.drprebid.model.AdSize) RequestQueue(com.mopub.volley.RequestQueue) Nullable(androidx.annotation.Nullable) OkHttpClient(okhttp3.OkHttpClient) AdFormat(org.prebid.mobile.drprebid.model.AdFormat) MoPubErrorCode(com.mopub.mobileads.MoPubErrorCode) MoPubInterstitial(com.mopub.mobileads.MoPubInterstitial) Activity(android.app.Activity) Host(org.prebid.mobile.Host) Request(com.mopub.volley.Request) PrebidMobile(org.prebid.mobile.PrebidMobile) InputStream(java.io.InputStream) MoPubInterstitial(com.mopub.mobileads.MoPubInterstitial) AdServerSettings(org.prebid.mobile.drprebid.model.AdServerSettings) GeneralSettings(org.prebid.mobile.drprebid.model.GeneralSettings) PublisherAdView(com.google.android.gms.ads.doubleclick.PublisherAdView) AdSize(org.prebid.mobile.drprebid.model.AdSize) FrameLayout(android.widget.FrameLayout) PublisherAdRequest(com.google.android.gms.ads.doubleclick.PublisherAdRequest) PublisherInterstitialAd(com.google.android.gms.ads.doubleclick.PublisherInterstitialAd) HashMap(java.util.HashMap) Map(java.util.Map) MoPubView(com.mopub.mobileads.MoPubView)

Example 3 with AdServerSettings

use of org.prebid.mobile.drprebid.model.AdServerSettings in project prebid-mobile-android by prebid.

the class SettingsManager method getAdServerSettings.

public AdServerSettings getAdServerSettings() {
    AdServerSettings settings = new AdServerSettings();
    switch(mSharedPreferences.getInt(Constants.Settings.AD_SERVER, Constants.Settings.AdServerCodes.GOOGLE_AD_MANAGER)) {
        case Constants.Settings.AdServerCodes.GOOGLE_AD_MANAGER:
            settings.setAdServer(AdServer.GOOGLE_AD_MANAGER);
            break;
        case Constants.Settings.AdServerCodes.MOPUB:
            settings.setAdServer(AdServer.MOPUB);
            break;
        default:
            settings.setAdServer(AdServer.MOPUB);
    }
    settings.setBidPrice(mSharedPreferences.getFloat(Constants.Settings.BID_PRICE, 0.0f));
    settings.setAdUnitId(mSharedPreferences.getString(Constants.Settings.AD_UNIT_ID, ""));
    return settings;
}
Also used : AdServerSettings(org.prebid.mobile.drprebid.model.AdServerSettings)

Example 4 with AdServerSettings

use of org.prebid.mobile.drprebid.model.AdServerSettings in project prebid-mobile-android by prebid.

the class TestResultsActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test_results);
    mListView = findViewById(R.id.list_results);
    setupResultsList();
    mAdServerValidationViewModel = ViewModelProviders.of(this).get(AdServerValidationViewModel.class);
    mDemandValidationViewModel = ViewModelProviders.of(this).get(PrebidServerValidationViewModel.class);
    mSdkValidationViewModel = ViewModelProviders.of(this).get(SdkValidationViewModel.class);
    AdServerSettings adServerSettings = SettingsManager.getInstance(this).getAdServerSettings();
    if (adServerSettings.getAdServer() == AdServer.MOPUB) {
        initMoPub(adServerSettings.getAdUnitId());
    } else {
        initGoogleAdsManager();
    }
}
Also used : SdkValidationViewModel(org.prebid.mobile.drprebid.ui.viewmodels.SdkValidationViewModel) AdServerSettings(org.prebid.mobile.drprebid.model.AdServerSettings) AdServerValidationViewModel(org.prebid.mobile.drprebid.ui.viewmodels.AdServerValidationViewModel) PrebidServerValidationViewModel(org.prebid.mobile.drprebid.ui.viewmodels.PrebidServerValidationViewModel)

Example 5 with AdServerSettings

use of org.prebid.mobile.drprebid.model.AdServerSettings in project prebid-mobile-android by prebid.

the class AdServerSettingsViewHolder method fillValues.

private void fillValues() {
    AdServerSettings settings = SettingsManager.getInstance(itemView.getContext()).getAdServerSettings();
    switch(settings.getAdServer()) {
        case GOOGLE_AD_MANAGER:
            mAdServerGroup.check(R.id.radio_dfp);
            break;
        case MOPUB:
            mAdServerGroup.check(R.id.radio_mopub);
            break;
    }
    mBidPriceView.setText(String.format(Locale.ENGLISH, "$ %.2f", settings.getBidPrice()));
    if (!TextUtils.isEmpty(settings.getAdUnitId())) {
        mAdUnitIdView.setText(settings.getAdUnitId());
    }
}
Also used : AdServerSettings(org.prebid.mobile.drprebid.model.AdServerSettings)

Aggregations

AdServerSettings (org.prebid.mobile.drprebid.model.AdServerSettings)6 PrebidServerSettings (org.prebid.mobile.drprebid.model.PrebidServerSettings)3 FrameLayout (android.widget.FrameLayout)2 PublisherAdRequest (com.google.android.gms.ads.doubleclick.PublisherAdRequest)2 PublisherAdView (com.google.android.gms.ads.doubleclick.PublisherAdView)2 PublisherInterstitialAd (com.google.android.gms.ads.doubleclick.PublisherInterstitialAd)2 MoPubInterstitial (com.mopub.mobileads.MoPubInterstitial)2 MoPubView (com.mopub.mobileads.MoPubView)2 Activity (android.app.Activity)1 Uri (android.net.Uri)1 TextUtils (android.text.TextUtils)1 Log (android.util.Log)1 Nullable (androidx.annotation.Nullable)1 AdListener (com.google.android.gms.ads.AdListener)1 MoPubErrorCode (com.mopub.mobileads.MoPubErrorCode)1 MoPubRequestQueue (com.mopub.network.MoPubRequestQueue)1 Networking (com.mopub.network.Networking)1 Request (com.mopub.volley.Request)1 RequestQueue (com.mopub.volley.RequestQueue)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1