Java Code Examples for com.google.android.gms.ads.AdView#setAdSize()

The following examples show how to use com.google.android.gms.ads.AdView#setAdSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AdViewHelper.java    From admobadapter with Apache License 2.0 6 votes vote down vote up
public static AdView getBannerAdView(Context context, BannerAdPreset bannerAdPreset) {
    AdView adView = new AdView(context);
    AdSize adSize = bannerAdPreset.getAdSize();
    adView.setAdSize(adSize);
    adView.setAdUnitId(bannerAdPreset.getAdUnitId());
    adView.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT,
            adSize.getHeightInPixels(context)));

    //Banners do not have video options
    /*
    if(bannerAdPreset.getVideoOptions() != null)
    adView.setVideoOptions(bannerAdPreset.getVideoOptions());
    */

    return adView;
}
 
Example 2
Source File: TvShowsFragment.java    From Android with MIT License 6 votes vote down vote up
private void Ads(View v) {
    View adContainer1 = v.findViewById(R.id.adView_tvshow_fragment);

    AdView mAdView = new AdView(mContext);
    mAdView.setAdSize(AdSize.MEDIUM_RECTANGLE);
    mAdView.setAdUnitId(ADMOB_PLEX_BANNER_2);
    ((RelativeLayout)adContainer1).addView(mAdView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);


    View adContainer2 = v.findViewById(R.id.adView_tvshow_fragment2);
    AdView mAdVie2 = new AdView(mContext);
    mAdVie2.setAdSize(AdSize.SMART_BANNER);
    mAdVie2.setAdUnitId(ADMOB_PLEX_BANNER_2);
    ((RelativeLayout)adContainer2).addView(mAdVie2);
    AdRequest adReques2 = new AdRequest.Builder().build();
    mAdVie2.loadAd(adReques2);
}
 
Example 3
Source File: HomeFragment.java    From Android with MIT License 6 votes vote down vote up
private void Ads(View v) {
    //adView = view.findViewById(R.id.adView);
    View adContainer = v.findViewById(R.id.adMobView);
   // Log.e("TAG :BANNERhomefragment",ADMOB_PLEX_BANNER_1);

    AdView mAdView = new AdView(mContext);
    mAdView.setAdSize(AdSize.SMART_BANNER);
    mAdView.setAdUnitId(ADMOB_PLEX_BANNER_1);
    ((RelativeLayout)adContainer).addView(mAdView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);
    mInterstitialAd = new InterstitialAd(getActivity());
    mInterstitialAd.setAdUnitId(ADMOB_PLEX_INTERSTITIAL_1);
    mInterstitialAd.loadAd(new AdRequest.Builder().build());
    mInterstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {

        }
    });

}
 
Example 4
Source File: MainActivity.java    From android-ads with Apache License 2.0 5 votes vote down vote up
/**
 * Adds banner ads to the items list.
 */
private void addBannerAds() {
    // Loop through the items array and place a new banner ad in every ith position in
    // the items List.
    for (int i = 0; i <= recyclerViewItems.size(); i += ITEMS_PER_AD) {
        final AdView adView = new AdView(MainActivity.this);
        adView.setAdSize(AdSize.BANNER);
        adView.setAdUnitId(AD_UNIT_ID);
        recyclerViewItems.add(i, adView);
    }
}
 
Example 5
Source File: AdMobComboProvider.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void displayBanner() {

    adView = new AdView(Game.instance());
    adView.setAdSize(AdSize.SMART_BANNER);
    adView.setAdUnitId(Game.getVar(R.string.easyModeAdUnitId));
    adView.setBackgroundColor(Color.TRANSPARENT);
    adView.setAdListener(new AdmobBannerListener());

    adView.loadAd(AdMob.makeAdRequest());
}
 
Example 6
Source File: AdLayout.java    From KernelAdiutor with GNU General Public License v3.0 5 votes vote down vote up
public AdLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    setOrientation(VERTICAL);

    LayoutInflater.from(context).inflate(R.layout.ad_layout_view, this);
    FrameLayout mAdLayout = findViewById(R.id.ad_layout);
    mProgress = findViewById(R.id.progress);
    mAdText = findViewById(R.id.ad_text);
    mGHImage = findViewById(R.id.gh_image);

    findViewById(R.id.remove_ad).setOnClickListener(v
            -> ViewUtils.dialogDonate(v.getContext()).show());

    mAdView = new AdView(context);
    mAdView.setAdSize(AdSize.SMART_BANNER);
    mAdView.setAdUnitId("ca-app-pub-1851546461606210/7537613480");
    mAdView.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            super.onAdLoaded();
            mAdFailedLoading = false;
            mProgress.setVisibility(GONE);
            if (mAdView.getParent() == null) {
                mAdLayout.addView(mAdView);
            }
        }

        @Override
        public void onAdFailedToLoad(int i) {
            super.onAdFailedToLoad(i);
            mAdFailedLoading = true;
            loadGHAd();
        }
    });
    mAdView.loadAd(new AdRequest.Builder().build());
}
 
Example 7
Source File: AndroidLauncher.java    From martianrun with Apache License 2.0 5 votes vote down vote up
private AdView createAdView() {
    AdView adView = new AdView(this);

    adView.setAdSize(AdSize.SMART_BANNER);
    adView.setAdUnitId(getAdMobUnitId());

    return adView;
}
 
Example 8
Source File: MainActivity.java    From googleads-mobile-android-examples with Apache License 2.0 5 votes vote down vote up
/**
 * Adds banner ads to the items list.
 */
private void addBannerAds() {
    // Loop through the items array and place a new banner ad in every ith position in
    // the items List.
    for (int i = 0; i <= recyclerViewItems.size(); i += ITEMS_PER_AD) {
        final AdView adView = new AdView(MainActivity.this);
        adView.setAdSize(AdSize.BANNER);
        adView.setAdUnitId(AD_UNIT_ID);
        recyclerViewItems.add(i, adView);
    }
}
 
Example 9
Source File: DetailsMovie_Fragment.java    From Android with MIT License 5 votes vote down vote up
private void Ads(View v) {
    View adContainer = v.findViewById(R.id.adView_details_fragment);
    AdView mAdView = new AdView(mContext);
    mAdView.setAdSize(AdSize.SMART_BANNER);
    mAdView.setAdUnitId(ADMOB_PLEX_BANNER_2);
    ((RelativeLayout)adContainer).addView(mAdView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);
}
 
Example 10
Source File: DownloadProfileImageActivity.java    From Instagram-Profile-Downloader with MIT License 4 votes vote down vote up
private void showBannerAd() {
    try {
        adView = new AdView(this);
        adView.setAdSize(AdSize.MEDIUM_RECTANGLE);
        adView.setAdUnitId(getString(R.string.banner_home_footer));
        adContainer.addView(adView);
        AdRequest adRequest = new AdRequest.Builder()
                .build();
        adView.loadAd(adRequest);
        adView.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                adContainer.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAdFailedToLoad(int errorCode) {
                showFbBannerAd();
            }

            @Override
            public void onAdOpened() {
                // Code to be executed when an ad opens an overlay that
                // covers the screen.
            }

            @Override
            public void onAdLeftApplication() {
                // Code to be executed when the user has left the app.
            }

            @Override
            public void onAdClosed() {
                // Code to be executed when the user is about to return
                // to the app after tapping on an ad.
            }
        });
    } catch (Exception e) {
        Log.e(TAG, "showBannerAd: " + e);
    }
}
 
Example 11
Source File: TestAdvancedAdmobActivity.java    From UltimateRecyclerView with Apache License 2.0 4 votes vote down vote up
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;
    }
 
Example 12
Source File: MainActivity.java    From HeartbeatFixerForGCM with Apache License 2.0 4 votes vote down vote up
private void showAd() {
    Log.v(TAG, "showAd");
    if (!mShowAd) {
        mShowAd = true;
        mAdView = new AdView(this);
        mAdView.setAdSize(AdSize.SMART_BANNER);
        mAdView.setAdUnitId("ca-app-pub-5964196502067291/5460955376");
        mAdView.setAdListener(new AdListener() {
            @Override
            public void onAdClosed() {
                Log.v(TAG, "onAdClosed");
            }

            @Override
            public void onAdFailedToLoad(int errorCode) {
                Log.v(TAG, "onAdFailedToLoad, errorCode: " + errorCode);
            }

            @Override
            public void onAdLeftApplication() {
                Log.v(TAG, "onAdLeftApplication");
            }

            @Override
            public void onAdOpened() {
                Log.v(TAG, "onAdOpened");
            }

            @Override
            public void onAdLoaded() {
                Log.v(TAG, "onAdLoaded");
            }

            @Override
            public void onAdClicked() {
                Log.v(TAG, "onAdClicked");
            }

            @Override
            public void onAdImpression() {
                Log.v(TAG, "onAdImpression");
            }
        });
        getRootViewGroup().addView(mAdView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        mAdView.loadAd(new AdRequest.Builder().build());
    }
}
 
Example 13
Source File: AdMobManager.java    From commcare-android with Apache License 2.0 4 votes vote down vote up
private static AdView buildBannerAdView(Context context, AdLocation adLocation) {
    AdView adView = new AdView(context);
    adView.setAdSize(AdSize.BANNER);
    adView.setAdUnitId(getBannerAdUnitIdForCurrentConsumerApp(adLocation));
    return adView;
}
 
Example 14
Source File: StoriesFragment.java    From Instagram-Profile-Downloader with MIT License 4 votes vote down vote up
private void showBannerAd() {
    try {
        adView = new AdView(getActivity());
        adView.setAdSize(AdSize.BANNER);
        adView.setAdUnitId(getString(R.string.banner_home_footer));
        adContainer.addView(adView);
        AdRequest adRequest = new AdRequest.Builder()
                .build();
        adView.loadAd(adRequest);
        adView.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                adContainer.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAdFailedToLoad(int errorCode) {
                showFbBannerAd();
            }

            @Override
            public void onAdOpened() {
                // Code to be executed when an ad opens an overlay that
                // covers the screen.
            }

            @Override
            public void onAdLeftApplication() {
                // Code to be executed when the user has left the app.
            }

            @Override
            public void onAdClosed() {
                // Code to be executed when the user is about to return
                // to the app after tapping on an ad.
            }
        });
    } catch (Exception e) {
        Log.e(TAG, "showBannerAd: " + e);
    }
}
 
Example 15
Source File: HowToUseActivity.java    From Instagram-Profile-Downloader with MIT License 4 votes vote down vote up
private void showBannerAd() {
    try {
        adView = new AdView(this);
        adView.setAdSize(AdSize.BANNER);
        adView.setAdUnitId(getString(R.string.banner_home_footer));
        adContainer.addView(adView);
        AdRequest adRequest = new AdRequest.Builder()
                .build();
        adView.loadAd(adRequest);
        adView.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                adContainer.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAdFailedToLoad(int errorCode) {
                showFbBannerAd();
            }

            @Override
            public void onAdOpened() {
                // Code to be executed when an ad opens an overlay that
                // covers the screen.
            }

            @Override
            public void onAdLeftApplication() {
                // Code to be executed when the user has left the app.
            }

            @Override
            public void onAdClosed() {
                // Code to be executed when the user is about to return
                // to the app after tapping on an ad.
            }
        });
    }catch (Exception e){
        Log.e(TAG, "showBannerAd: "+e );
    }
}
 
Example 16
Source File: ViewProfileActivity.java    From Instagram-Profile-Downloader with MIT License 4 votes vote down vote up
private void showBannerAd() {
    try {
        adView = new AdView(this);
        adView.setAdSize(AdSize.BANNER);
        adView.setAdUnitId(getString(R.string.banner_home_footer));
        adContainer.addView(adView);
        AdRequest adRequest = new AdRequest.Builder()
                .build();
        adView.loadAd(adRequest);
        adView.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                adContainer.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAdFailedToLoad(int errorCode) {
                showFbBannerAd();
            }

            @Override
            public void onAdOpened() {
                // Code to be executed when an ad opens an overlay that
                // covers the screen.
            }

            @Override
            public void onAdLeftApplication() {
                // Code to be executed when the user has left the app.
            }

            @Override
            public void onAdClosed() {
                // Code to be executed when the user is about to return
                // to the app after tapping on an ad.
            }
        });
    }catch (Exception e){
        Log.e(TAG, "showBannerAd: "+e );
    }
}
 
Example 17
Source File: DownloadHistoryActivity.java    From Instagram-Profile-Downloader with MIT License 4 votes vote down vote up
private void showBannerAd() {
    try {
        adView = new AdView(this);
        adView.setAdSize(AdSize.BANNER);
        adView.setAdUnitId(getString(R.string.banner_home_footer));
        adContainer.addView(adView);
        AdRequest adRequest = new AdRequest.Builder()
                .build();
        adView.loadAd(adRequest);
        adView.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                adContainer.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAdFailedToLoad(int errorCode) {

                showFbBannerAd();
            }

            @Override
            public void onAdOpened() {
                // Code to be executed when an ad opens an overlay that
                // covers the screen.
            }

            @Override
            public void onAdLeftApplication() {
                // Code to be executed when the user has left the app.
            }

            @Override
            public void onAdClosed() {
                // Code to be executed when the user is about to return
                // to the app after tapping on an ad.
            }
        });
    } catch (Exception e) {
        Log.e(TAG, "showBannerAd: " + e);
    }
}
 
Example 18
Source File: DownloadIGTVFragment.java    From Instagram-Profile-Downloader with MIT License 4 votes vote down vote up
private void showBannerAd() {
    try {

        adView = new AdView(getActivity());
        adView.setAdSize(AdSize.MEDIUM_RECTANGLE);
        adView.setAdUnitId(getString(R.string.banner_home_footer));
        adContainer.addView(adView);
        AdRequest adRequest = new AdRequest.Builder()
                .build();
        adView.loadAd(adRequest);
        adView.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                adContainer.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAdFailedToLoad(int errorCode) {
                showFbBannerAd();
            }

            @Override
            public void onAdOpened() {
                // Code to be executed when an ad opens an overlay that
                // covers the screen.
            }

            @Override
            public void onAdLeftApplication() {
                // Code to be executed when the user has left the app.
            }

            @Override
            public void onAdClosed() {
                // Code to be executed when the user is about to return
                // to the app after tapping on an ad.
            }
        });
    } catch (Exception e) {
        Log.e(TAG, "showBannerAd: " + e);
    }
}
 
Example 19
Source File: FavouriteFragment.java    From Instagram-Profile-Downloader with MIT License 4 votes vote down vote up
private void showBannerAd() {
    try {
        adView = new AdView(getActivity());
        adView.setAdSize(AdSize.BANNER);
        adView.setAdUnitId(getString(R.string.banner_home_footer));
        adContainer.addView(adView);
        AdRequest adRequest = new AdRequest.Builder()
                .build();
        adView.loadAd(adRequest);
        adView.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                adContainer.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAdFailedToLoad(int errorCode) {
                showFbBannerAd();
            }

            @Override
            public void onAdOpened() {
                // Code to be executed when an ad opens an overlay that
                // covers the screen.
            }

            @Override
            public void onAdLeftApplication() {
                // Code to be executed when the user has left the app.
            }

            @Override
            public void onAdClosed() {
                // Code to be executed when the user is about to return
                // to the app after tapping on an ad.
            }
        });
    }catch (Exception e){
        Log.e(TAG, "showBannerAd: "+e );
    }
}
 
Example 20
Source File: DownloadPostFragment.java    From Instagram-Profile-Downloader with MIT License 4 votes vote down vote up
private void showBannerAd() {
    try {
        adView = new AdView(getActivity());
        adView.setAdSize(AdSize.MEDIUM_RECTANGLE);
        adView.setAdUnitId(getString(R.string.banner_home_footer));
        adContainer.addView(adView);
        AdRequest adRequest = new AdRequest.Builder()
                .build();
        adView.loadAd(adRequest);
        adView.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                adContainer.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAdFailedToLoad(int errorCode) {
                showFbBannerAd();
            }

            @Override
            public void onAdOpened() {
                // Code to be executed when an ad opens an overlay that
                // covers the screen.
            }

            @Override
            public void onAdLeftApplication() {
                // Code to be executed when the user has left the app.
            }

            @Override
            public void onAdClosed() {
                // Code to be executed when the user is about to return
                // to the app after tapping on an ad.
            }
        });
    } catch (Exception e) {
        Log.e(TAG, "showBannerAd: " + e);
    }
}