Java 类com.facebook.ads.AdView 实例源码

项目:kognitivo    文件:BannerFragment.java   
@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();
}
项目:mobile-sdk-android    文件:FacebookBanner.java   
@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;
}
项目:kognitivo    文件:RectangleFragment.java   
@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();
}
项目:googleads-mobile-android-mediation    文件:FacebookAdapter.java   
@Override
public void requestBannerAd(Context context,
                            MediationBannerListener listener,
                            Bundle serverParameters,
                            AdSize adSize,
                            MediationAdRequest adRequest,
                            Bundle mediationExtras) {
    mBannerListener = listener;
    if (!isValidRequestParameters(context, serverParameters)) {
        mBannerListener.onAdFailedToLoad(
                FacebookAdapter.this, AdRequest.ERROR_CODE_INVALID_REQUEST);
        return;
    }
    if (adSize == null) {
        Log.w(TAG, "Fail to request banner ad, adSize is null");
        mBannerListener.onAdFailedToLoad(this, AdRequest.ERROR_CODE_INVALID_REQUEST);
        return;
    }

    String placementId = serverParameters.getString(PLACEMENT_PARAMETER);

    com.facebook.ads.AdSize facebookAdSize = getAdSize(context, adSize);
    if (facebookAdSize == null) {
        Log.w(TAG,
                "The input ad size " + adSize.toString() + " is not supported at this moment.");
        mBannerListener.onAdFailedToLoad(this, AdRequest.ERROR_CODE_NO_FILL);
        return;
    }
    mAdView = new AdView(context, placementId, facebookAdSize);
    mAdView.setAdListener(new BannerListener());
    buildAdRequest(adRequest);
    RelativeLayout.LayoutParams adViewLayoutParams = new RelativeLayout.LayoutParams(
            adSize.getWidthInPixels(context), adSize.getHeightInPixels(context));
    mWrappedAdView = new RelativeLayout(context);
    mAdView.setLayoutParams(adViewLayoutParams);
    mWrappedAdView.addView(mAdView);
    mAdView.loadAd();
}