Search in sources :

Example 1 with AdSize

use of com.google.android.gms.ads.AdSize in project mopub-android-mediation by mopub.

the class GooglePlayServicesBanner method loadBanner.

@Override
protected void loadBanner(final Context context, final CustomEventBannerListener customEventBannerListener, final Map<String, Object> localExtras, final Map<String, String> serverExtras) {
    mBannerListener = customEventBannerListener;
    final String adUnitId;
    final int adWidth;
    final int adHeight;
    if (extrasAreValid(serverExtras)) {
        adUnitId = serverExtras.get(AD_UNIT_ID_KEY);
        adWidth = Integer.parseInt(serverExtras.get(AD_WIDTH_KEY));
        adHeight = Integer.parseInt(serverExtras.get(AD_HEIGHT_KEY));
    } else {
        mBannerListener.onBannerFailed(MoPubErrorCode.ADAPTER_CONFIGURATION_ERROR);
        return;
    }
    mGoogleAdView = new AdView(context);
    mGoogleAdView.setAdListener(new AdViewListener());
    mGoogleAdView.setAdUnitId(adUnitId);
    final AdSize adSize = calculateAdSize(adWidth, adHeight);
    if (adSize == null) {
        mBannerListener.onBannerFailed(MoPubErrorCode.ADAPTER_CONFIGURATION_ERROR);
        return;
    }
    mGoogleAdView.setAdSize(adSize);
    final AdRequest adRequest = new AdRequest.Builder().setRequestAgent("MoPub").build();
    try {
        mGoogleAdView.loadAd(adRequest);
    } catch (NoClassDefFoundError e) {
        // This can be thrown by Play Services on Honeycomb.
        mBannerListener.onBannerFailed(MoPubErrorCode.NETWORK_NO_FILL);
    }
}
Also used : AdRequest(com.google.android.gms.ads.AdRequest) AdSize(com.google.android.gms.ads.AdSize) AdView(com.google.android.gms.ads.AdView)

Example 2 with AdSize

use of com.google.android.gms.ads.AdSize in project UltimateRecyclerView by cymcsg.

the class TestAdvancedAdmobActivity method createadmob.

private RelativeLayout createadmob() {
    AdSize adSize = AdSize.SMART_BANNER;
    DisplayMetrics dm = getResources().getDisplayMetrics();
    double density = dm.density * 160;
    double x = Math.pow(dm.widthPixels / density, 2);
    double y = Math.pow(dm.heightPixels / density, 2);
    double screenInches = Math.sqrt(x + y);
    if (screenInches > 8) {
        // > 728 X 90
        adSize = AdSize.LEADERBOARD;
    } else if (screenInches > 6) {
        // > 468 X 60
        adSize = AdSize.MEDIUM_RECTANGLE;
    } else {
        // > 320 X 50
        adSize = AdSize.BANNER;
    }
    adSize = AdSize.MEDIUM_RECTANGLE;
    final AdView mAdView = new AdView(this);
    mAdView.setAdSize(adSize);
    mAdView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
    // Create an ad request.
    AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
    if (admob_test_mode)
        // Optionally populate the ad request builder.
        adRequestBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
    // Start loading the ad.
    mAdView.loadAd(adRequestBuilder.build());
    DisplayMetrics displaymetrics = new DisplayMetrics();
    final RelativeLayout layout = AdGoogleDisplaySupport.initialSupport(this, displaymetrics);
    final double ratio = AdGoogleDisplaySupport.ratioMatching(displaymetrics);
    final int ad_height = AdGoogleDisplaySupport.defaultHeight(displaymetrics);
    AdGoogleDisplaySupport.panelAdjust(mAdView, (int) (ad_height * ratio));
    // get display info
    /*  G.display_w = displayMetrics.widthPixels;
        G.display_h = displayMetrics.heightPixels;
        G.scale = Math.max(G.display_w/1280.0f, G.display_h/800.0f);*/
    mAdView.setAdListener(new AdListener() {

        @Override
        public void onAdLoaded() {
            super.onAdLoaded();
            int h = mAdView.getLayoutParams().height;
            AdGoogleDisplaySupport.scale(mAdView, ratio);
            AdGoogleDisplaySupport.panelAdjust(mAdView, (int) (h * ratio));
        // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        }
    });
    layout.addView(mAdView);
    return layout;
}
Also used : AdRequest(com.google.android.gms.ads.AdRequest) AdSize(com.google.android.gms.ads.AdSize) RelativeLayout(android.widget.RelativeLayout) AdView(com.google.android.gms.ads.AdView) DisplayMetrics(android.util.DisplayMetrics) AdListener(com.google.android.gms.ads.AdListener)

Example 3 with AdSize

use of com.google.android.gms.ads.AdSize in project MTweaks-KernelAdiutorMOD by morogoku.

the class AdNativeExpress method loadNativeAd.

private void loadNativeAd(int width, float deviceDensity) {
    float adWidth = width / deviceDensity;
    if (adWidth > MAX_WIDTH)
        adWidth = MAX_WIDTH;
    mNativeExpressAdView.setAdSize(new AdSize((int) adWidth, MIN_HEIGHT));
    mNativeLoading = true;
    mNativeExpressAdView.loadAd(new AdRequest.Builder().build());
}
Also used : AdSize(com.google.android.gms.ads.AdSize)

Example 4 with AdSize

use of com.google.android.gms.ads.AdSize in project prebid-mobile-android by prebid.

the class DFPBannerFragment method setupBannerWithoutWait.

private void setupBannerWithoutWait() {
    FrameLayout adFrame = (FrameLayout) root.findViewById(R.id.adFrame);
    adFrame.removeAllViews();
    adView1 = new PublisherAdView(getActivity());
    adView1.setAdUnitId(Constants.DFP_BANNER_ADUNIT_ID_320x50);
    adView1.setAdSizes(new AdSize(320, 50));
    adView1.setAdListener(adListener);
    adFrame.addView(adView1);
    // region PriceCheckForDFP API usage
    PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder();
    PublisherAdRequest request = builder.build();
    Prebid.attachBids(request, Constants.BANNER_320x50, this.getActivity());
    // endregion
    adView1.loadAd(request);
}
Also used : PublisherAdView(com.google.android.gms.ads.doubleclick.PublisherAdView) FrameLayout(android.widget.FrameLayout) AdSize(com.google.android.gms.ads.AdSize) PublisherAdRequest(com.google.android.gms.ads.doubleclick.PublisherAdRequest)

Example 5 with AdSize

use of com.google.android.gms.ads.AdSize in project prebid-mobile-android by prebid.

the class DFPBannerFragment method setupBannerWithWait.

private void setupBannerWithWait(final int waitTime) {
    FrameLayout adFrame = (FrameLayout) root.findViewById(R.id.adFrame2);
    adFrame.removeAllViews();
    adView2 = new PublisherAdView(getActivity());
    adView2.setAdUnitId(Constants.DFP_BANNER_ADUNIT_ID_300x250);
    adView2.setAdSizes(new AdSize(300, 250));
    adView2.setAdListener(adListener);
    adFrame.addView(adView2);
    // region PriceCheckForDFP API usage
    PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder();
    PublisherAdRequest request = builder.build();
    Prebid.attachBidsWhenReady(request, Constants.BANNER_300x250, this, waitTime, this.getActivity());
// endregion
}
Also used : PublisherAdView(com.google.android.gms.ads.doubleclick.PublisherAdView) FrameLayout(android.widget.FrameLayout) AdSize(com.google.android.gms.ads.AdSize) PublisherAdRequest(com.google.android.gms.ads.doubleclick.PublisherAdRequest)

Aggregations

AdSize (com.google.android.gms.ads.AdSize)7 FrameLayout (android.widget.FrameLayout)3 AdListener (com.google.android.gms.ads.AdListener)3 AdRequest (com.google.android.gms.ads.AdRequest)3 AdView (com.google.android.gms.ads.AdView)2 PublisherAdRequest (com.google.android.gms.ads.doubleclick.PublisherAdRequest)2 PublisherAdView (com.google.android.gms.ads.doubleclick.PublisherAdView)2 DisplayMetrics (android.util.DisplayMetrics)1 Button (android.widget.Button)1 RelativeLayout (android.widget.RelativeLayout)1 NativeExpressAdView (com.google.android.gms.ads.NativeExpressAdView)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1