当前位置: 首页>>代码示例>>Java>>正文


Java AdSize.getWidthInPixels方法代码示例

本文整理汇总了Java中com.google.android.gms.ads.AdSize.getWidthInPixels方法的典型用法代码示例。如果您正苦于以下问题:Java AdSize.getWidthInPixels方法的具体用法?Java AdSize.getWidthInPixels怎么用?Java AdSize.getWidthInPixels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.android.gms.ads.AdSize的用法示例。


在下文中一共展示了AdSize.getWidthInPixels方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onMeasure

import com.google.android.gms.ads.AdSize; //导入方法依赖的package包/类
protected final void onMeasure(int paramInt1, int paramInt2)
{
  View localView = getChildAt(0);
  int j;
  int i;
  if ((localView != null) && (localView.getVisibility() != 8))
  {
    measureChild(localView, paramInt1, paramInt2);
    j = localView.getMeasuredWidth();
    i = localView.getMeasuredHeight();
  }
  for (;;)
  {
    int k = Math.max(j, getSuggestedMinimumWidth());
    int m = Math.max(i, getSuggestedMinimumHeight());
    setMeasuredDimension(View.resolveSize(k, paramInt1), View.resolveSize(m, paramInt2));
    return;
    AdSize localAdSize = getAdSize();
    if (localAdSize != null)
    {
      Context localContext = getContext();
      j = localAdSize.getWidthInPixels(localContext);
      i = localAdSize.getHeightInPixels(localContext);
    }
    else
    {
      i = 0;
      j = 0;
    }
  }
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:32,代码来源:PublisherAdView.java

示例2: requestBannerAd

import com.google.android.gms.ads.AdSize; //导入方法依赖的package包/类
@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();
}
 
开发者ID:googleads,项目名称:googleads-mobile-android-mediation,代码行数:39,代码来源:FacebookAdapter.java

示例3: onMeasure

import com.google.android.gms.ads.AdSize; //导入方法依赖的package包/类
protected final void onMeasure(int paramInt1, int paramInt2)
{
  View localView = getChildAt(0);
  AdSize localAdSize = getAdSize();
  int i;
  int j;
  if ((localView != null) && (localView.getVisibility() != 8))
  {
    measureChild(localView, paramInt1, paramInt2);
    i = localView.getMeasuredWidth();
    j = localView.getMeasuredHeight();
  }
  else
  {
    i = 0;
    j = 0;
    if (localAdSize != null)
    {
      Context localContext = getContext();
      i = localAdSize.getWidthInPixels(localContext);
      j = localAdSize.getHeightInPixels(localContext);
    }
  }
  int k = Math.max(i, getSuggestedMinimumWidth());
  int m = Math.max(j, getSuggestedMinimumHeight());
  setMeasuredDimension(View.resolveSize(k, paramInt1), View.resolveSize(m, paramInt2));
}
 
开发者ID:mmmsplay10,项目名称:QuizUpWinner,代码行数:28,代码来源:PublisherAdView.java

示例4: requestBannerAd

import com.google.android.gms.ads.AdSize; //导入方法依赖的package包/类
/**
 * This method will only ever be called once per adapter instance.
 */
@Override
public void requestBannerAd(
        Context context,
        MediationBannerListener listener,
        Bundle serverParameters,
        AdSize adSize,
        MediationAdRequest mediationAdRequest,
        Bundle mediationExtras) {
    /*
     * In this method, you should:
     *
     * 1. Create your banner view.
     * 2. Set your ad network's listener.
     * 3. Make an ad request.
     */

    // Create the SampleAdView.
    mSampleAdView = new SampleAdView(context);

    if (serverParameters.containsKey(SAMPLE_AD_UNIT_KEY)) {
        mSampleAdView.setAdUnit(serverParameters.getString(SAMPLE_AD_UNIT_KEY));
    } else {
        listener.onAdFailedToLoad(this, AdRequest.ERROR_CODE_INVALID_REQUEST);
    }

    // Internally, smart banners use constants to represent their ad size, which means a call to
    // AdSize.getHeight could return a negative value. You can accommodate this by using
    // AdSize.getHeightInPixels and AdSize.getWidthInPixels instead, and then adjusting to match
    // the device's display metrics.
    int widthInPixels = adSize.getWidthInPixels(context);
    int heightInPixels = adSize.getHeightInPixels(context);
    DisplayMetrics displayMetrics = Resources.getSystem().getDisplayMetrics();
    int widthInDp = Math.round(widthInPixels / displayMetrics.density);
    int heightInDp = Math.round(heightInPixels / displayMetrics.density);

    mSampleAdView.setSize(new SampleAdSize(widthInDp, heightInDp));

    /**
     * Implement a SampleAdListener and forward callbacks to mediation. The callback forwarding
     * is handled by {@link SampleMediationBannerEventForwarder}.
     */
    mSampleAdView.setAdListener(new SampleMediationBannerEventForwarder(listener, this));

    SampleAdRequest request = createSampleRequest(mediationAdRequest);

    /**
     * If your network supports additional request parameters, the publisher can send these
     * additional parameters to the adapter using the {@link mediationExtras} bundle.
     * Creating a bundle builder class makes it easier for the publisher to create this bundle.
     */
    if (mediationExtras != null) {
        if (mediationExtras.containsKey(MediationExtrasBundleBuilder.KEY_AWESOME_SAUCE)) {
            request.setShouldAddAwesomeSauce(
                    mediationExtras.getBoolean(MediationExtrasBundleBuilder.KEY_AWESOME_SAUCE));
        }

        if (mediationExtras.containsKey(MediationExtrasBundleBuilder.KEY_INCOME)) {
            request.setIncome(mediationExtras.getInt(MediationExtrasBundleBuilder.KEY_INCOME));
        }
    }

    // Make an ad request.
    mSampleAdView.fetchAd(request);
}
 
开发者ID:googleads,项目名称:googleads-mobile-android-mediation,代码行数:68,代码来源:SampleAdapter.java

示例5: requestBannerAd

import com.google.android.gms.ads.AdSize; //导入方法依赖的package包/类
@Override
public void requestBannerAd(Context context,
                            CustomEventBannerListener listener,
                            String serverParameter,
                            AdSize size,
                            MediationAdRequest mediationAdRequest,
                            Bundle customEventExtras) {
    /*
     * In this method, you should:
     *
     * 1. Create your banner view.
     * 2. Set your ad network's listener.
     * 3. Make an ad request.
     *
     * When setting your ad network's listener, don't forget to send the following callbacks:
     *
     * listener.onAdLoaded(this);
     * listener.onAdFailedToLoad(this, AdRequest.ERROR_CODE_*);
     * listener.onAdClicked(this);
     * listener.onAdOpened(this);
     * listener.onAdLeftApplication(this);
     * listener.onAdClosed(this);
     */

    mSampleAdView = new SampleAdView(context);

    // Assumes that the serverParameter is the AdUnit for the Sample Network.
    mSampleAdView.setAdUnit(serverParameter);

    // Internally, smart banners use constants to represent their ad size, which means a call to
    // AdSize.getHeight could return a negative value. You can accommodate this by using
    // AdSize.getHeightInPixels and AdSize.getWidthInPixels instead, and then adjusting to match
    // the device's display metrics.
    int widthInPixels = size.getWidthInPixels(context);
    int heightInPixels = size.getHeightInPixels(context);
    DisplayMetrics displayMetrics = Resources.getSystem().getDisplayMetrics();
    int widthInDp = Math.round(widthInPixels / displayMetrics.density);
    int heightInDp = Math.round(heightInPixels / displayMetrics.density);

    mSampleAdView.setSize(new SampleAdSize(widthInDp, heightInDp));

    // Implement a SampleAdListener and forward callbacks to mediation. The callback forwarding
    // is handled by SampleBannerEventFowarder.
    mSampleAdView.setAdListener(new SampleCustomBannerEventForwarder(listener, mSampleAdView));

    // Make an ad request.
    mSampleAdView.fetchAd(createSampleRequest(mediationAdRequest));
}
 
开发者ID:googleads,项目名称:googleads-mobile-android-mediation,代码行数:49,代码来源:SampleCustomEvent.java


注:本文中的com.google.android.gms.ads.AdSize.getWidthInPixels方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。