com.facebook.ads.AdView Java Examples

The following examples show how to use com.facebook.ads.AdView. 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: BannerFragment.java    From kognitivo with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Initialize status label
    statusLabel = getString(R.string.loading_status);

    // Create a banner's ad view with a unique placement ID (generate your own on the Facebook app settings).
    // Use different ID for each ad placement in your app.
    boolean isTablet = getResources().getBoolean(R.bool.is_tablet);
    adViewBanner = new AdView(this.getActivity(), "YOUR_PLACEMENT_ID",
            isTablet ? AdSize.BANNER_HEIGHT_90 : AdSize.BANNER_HEIGHT_50);

    // Set a listener to get notified on changes or when the user interact with the ad.
    adViewBanner.setAdListener(this);

    // Initiate a request to load an ad.
    adViewBanner.loadAd();
}
 
Example #2
Source File: FacebookBanner.java    From mobile-sdk-android with Apache License 2.0 6 votes vote down vote up
@Override
public View requestAd(MediatedBannerAdViewController mBC, Activity activity, String parameter, String uid, int width, int height, TargetingParameters tp) {
    FacebookListener fbListener = new FacebookListener(mBC, this.getClass().getSimpleName());
    AdSize adSize;
    if (width == 320 && height == 50) {
        adSize = AdSize.BANNER_320_50;
    } else if (height == 50) {
        adSize = AdSize.BANNER_HEIGHT_50;
    } else if (height == 90) {
        adSize = AdSize.BANNER_HEIGHT_90;
    } else if (height == 250) {
        adSize = AdSize.RECTANGLE_HEIGHT_250;
    } else {
        Clog.e(Clog.mediationLogTag, "Facebook - Attempted to instantiate with size other than the allowed size of 320x50, -1x50, -1x90, -1x250");
        mBC.onAdFailed(ResultCode.UNABLE_TO_FILL);
        return null;
    }
    adView = new AdView(activity, uid, adSize);
    adView.setAdListener(fbListener);
    adView.loadAd();
    return adView;
}
 
Example #3
Source File: RectangleFragment.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Initialize status label
    statusLabel = getString(R.string.loading_status);

    adViewRectangle = new AdView(this.getActivity(), "YOUR_PLACEMENT_ID", AdSize.RECTANGLE_HEIGHT_250);

    // Set a listener to get notified on changes or when the user interact with the ad.
    adViewRectangle.setAdListener(this);

    // Initiate a request to load an ad.
    adViewRectangle.loadAd();
}
 
Example #4
Source File: FacebookAdapter.java    From googleads-mobile-android-mediation with Apache License 2.0 4 votes vote down vote up
@Override
public void requestBannerAd(final Context context,
    MediationBannerListener listener,
    Bundle serverParameters,
    final AdSize adSize,
    final MediationAdRequest adRequest,
    Bundle mediationExtras) {
  mBannerListener = listener;

  final String placementID = getPlacementID(serverParameters);
  if (TextUtils.isEmpty(placementID)) {
    Log.e(TAG, createAdapterError(ERROR_INVALID_SERVER_PARAMETERS,
        "Failed to request ad: placementID is null or empty."));
    mBannerListener.onAdFailedToLoad(this, ERROR_INVALID_SERVER_PARAMETERS);
    return;
  }

  final com.facebook.ads.AdSize facebookAdSize = getAdSize(context, adSize);
  if (facebookAdSize == null) {
    Log.w(TAG, createAdapterError(ERROR_BANNER_SIZE_MISMATCH,
        "There is no matching Facebook ad size for Google ad size: " + adSize.toString()));
    mBannerListener.onAdFailedToLoad(this, ERROR_BANNER_SIZE_MISMATCH);
    return;
  }

  FacebookInitializer.getInstance()
      .initialize(
          context,
          placementID,
          new FacebookInitializer.Listener() {
            @Override
            public void onInitializeSuccess() {
              mAdView = new AdView(context, placementID, facebookAdSize);
              buildAdRequest(adRequest);

              FrameLayout.LayoutParams adViewLayoutParams = new FrameLayout.LayoutParams(
                  adSize.getWidthInPixels(context), LayoutParams.WRAP_CONTENT);
              mWrappedAdView = new FrameLayout(context);
              mAdView.setLayoutParams(adViewLayoutParams);
              mWrappedAdView.addView(mAdView);
              mAdView.loadAd(
                  mAdView.buildLoadAdConfig()
                      .withAdListener(new BannerListener())
                      .build()
              );
            }

            @Override
            public void onInitializeError(String message) {
              Log.w(TAG, createAdapterError(ERROR_FACEBOOK_INITIALIZATION, message));
              if (mBannerListener != null) {
                mBannerListener.onAdFailedToLoad(FacebookAdapter.this,
                    ERROR_FACEBOOK_INITIALIZATION);
              }
            }
          });
}