本文整理匯總了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;
}
}
}
示例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();
}
示例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));
}
示例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);
}
示例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));
}