com.google.ads.AdSize Java Examples

The following examples show how to use com.google.ads.AdSize. 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: GodotAdMob.java    From godot_modules with MIT License 5 votes vote down vote up
public void InitializeUIThread(String p_key) {
	
	// Create the interstitial
	interstitial = new InterstitialAd(activity, p_key);
	
	// Create banner
	adView = new AdView(activity, AdSize.SMART_BANNER, p_key);

	RelativeLayout layout = ((Godot)activity).layout;
	RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
        LayoutParams.WRAP_CONTENT);

	layoutParams.addRule(layoutRule1);
	layoutParams.addRule(layoutRule2);
	layout.addView(adView, layoutParams);
	layout.invalidate();

	adView.setVisibility(View.VISIBLE);        
	
	initialized = true;
	
    	adReceived = false;
    	screenDismissed = false;
    	failedToReceiveAd = false;
    	applicationLeaved = false;
    	presentScreen = false;        

	Log.d("godot", "AdMob: Initialized");
}
 
Example #2
Source File: AdMobMediationBanner.java    From mobile-sdk-android with Apache License 2.0 5 votes vote down vote up
@Override
public void requestBannerAd(CustomEventBannerListener listener, final Activity activity,
                            String label, String serverParameter, AdSize adSize, MediationAdRequest mediationAdRequest,
                            Object extra) {
    Clog.d(Clog.mediationLogTag, "Initializing ANBanner via AdMob SDK");
    this.listener = listener;

    BannerAdView appNexusAdView = new BannerAdView(activity);
    appNexusAdView.setPlacementID(serverParameter);
    appNexusAdView.setAdSize(adSize.getWidth(), adSize.getHeight());
    appNexusAdView.setShouldServePSAs(false);
    appNexusAdView.setAdListener(this);

    switch (mediationAdRequest.getGender()) {
        case MALE:
            appNexusAdView.setGender(AdView.GENDER.MALE);
            break;
        case FEMALE:
            appNexusAdView.setGender(AdView.GENDER.FEMALE);
            break;
        default:
            // unknown case passes nothing
            break;
    }

    if (mediationAdRequest.getAgeInYears() != null) {
        appNexusAdView.setAge(String.valueOf(mediationAdRequest.getAgeInYears()));
    }
    SDKSettings.setLocation(mediationAdRequest.getLocation());

    Clog.d(Clog.mediationLogTag, "Load ANBanner");
    appNexusAdView.loadAdOffscreen();
}
 
Example #3
Source File: LegacyAdMobBanner.java    From mobile-sdk-android with Apache License 2.0 5 votes vote down vote up
/**
 * Interface called by the AN SDK to request an ad from the mediating SDK.
 *
 * @param mBC       the object which will be called with events from the 3d party SDK
 * @param activity  the activity from which this is launched
 * @param parameter String parameter received from the server for instantiation of this object
 * @param adUnitID  The 3rd party placement , in adMob this is the adUnitID
 * @param width     Width of the ad
 * @param height    Height of the ad
 */
@Override
public View requestAd(MediatedBannerAdViewController mBC, Activity activity, String parameter, String adUnitID,
                      int width, int height, TargetingParameters targetingParameters) {
    adListener = new AdMobAdListener(mBC, super.getClass().getSimpleName());
    adListener.printToClog(String.format(" - requesting an ad: [%s, %s, %dx%d]",
            parameter, adUnitID, width, height));

    admobAV = new AdView(activity, new AdSize(width, height), adUnitID);
    admobAV.setAdListener(adListener);
    AdRequest ar = new AdRequest();

    switch (targetingParameters.getGender()) {
        case UNKNOWN:
            break;
        case FEMALE:
            ar.setGender(AdRequest.Gender.FEMALE);
            break;
        case MALE:
            ar.setGender(AdRequest.Gender.MALE);
            break;
    }
    AdMobAdapterExtras extras = new AdMobAdapterExtras();
    if (targetingParameters.getAge() != null) {
        extras.addExtra("Age", targetingParameters.getAge());
    }

    for (Pair<String, String> p : targetingParameters.getCustomKeywords()) {
        extras.addExtra(p.first, p.second);
    }
    if (targetingParameters.getLocation() != null) {
        ar.setLocation(targetingParameters.getLocation());
    }
    ar.setNetworkExtras(extras);

    admobAV.loadAd(ar);
    return admobAV;
}
 
Example #4
Source File: LegacyDFPBanner.java    From mobile-sdk-android with Apache License 2.0 4 votes vote down vote up
/**
 * Interface called by the AN SDK to request an ad from the mediating SDK.
 *
 * @param mBC       the object which will be called with events from the 3d party SDK
 * @param activity  the activity from which this is launched
 * @param parameter String parameter received from the server for instantiation of this object
 * @param adUnitID  The 3rd party placement , in DFP this is the adUnitID
 * @param width     Width of the ad
 * @param height    Height of the ad
 */
@Override
public View requestAd(MediatedBannerAdViewController mBC, Activity activity, String parameter, String adUnitID,
                      int width, int height, TargetingParameters targetingParameters) {
    adListener = new AdMobAdListener(mBC, super.getClass().getSimpleName());
    adListener.printToClog(String.format("requesting an ad: [%s, %s, %dx%d]", parameter, adUnitID, width, height));

    DFBBannerSSParameters ssparm = new DFBBannerSSParameters(parameter);
    AdSize adSize = ssparm.isSmartBanner ? AdSize.SMART_BANNER : new AdSize(width, height);

    if (ssparm.isSwipeable) {
        dfpView = new SwipeableDfpAdView(activity, adSize, adUnitID);
    } else {
        dfpView = new DfpAdView(activity, adSize, adUnitID);
    }

    dfpView.setAdListener(adListener);
    AdRequest ar = new AdRequest();

    if (ssparm.test_device != null && ssparm.test_device.length() > 0) {
        adListener.printToClog("requestAd called with test device " + ssparm.test_device);
        ar.addTestDevice(ssparm.test_device);
    }

    switch (targetingParameters.getGender()) {
        case UNKNOWN:
            break;
        case FEMALE:
            ar.setGender(AdRequest.Gender.FEMALE);
            break;
        case MALE:
            ar.setGender(AdRequest.Gender.MALE);
            break;
    }
    DfpExtras extras = new DfpExtras();
    if (targetingParameters.getAge() != null) {
        extras.addExtra("Age", targetingParameters.getAge());
    }
    if (targetingParameters.getLocation() != null) {
        ar.setLocation(targetingParameters.getLocation());
    }
    for (Pair<String, String> p : targetingParameters.getCustomKeywords()) {
        extras.addExtra(p.first, p.second);
    }
    ar.setNetworkExtras(extras);

    dfpView.loadAd(ar);

    return dfpView;
}