本文整理汇总了Java中com.facebook.ads.NativeAd类的典型用法代码示例。如果您正苦于以下问题:Java NativeAd类的具体用法?Java NativeAd怎么用?Java NativeAd使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NativeAd类属于com.facebook.ads包,在下文中一共展示了NativeAd类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addNativeAd
import com.facebook.ads.NativeAd; //导入依赖的package包/类
public synchronized void addNativeAd(NativeAd ad, Context context, ArrayList<TimelineListAPKsJson.UserApk> list) {
if (ad == null) {
Log.d("pois", "addNativeAd , was null");
return;
}
if (this.ad != null) {
Log.d("pois","addNativeAd , was old");
// Clean up the old ad before inserting the new one
this.ad.unregisterView();
list.remove(AD_INDEX);
this.ad = null;
this.notifyDataSetChanged();
}
Log.d("pois","addNativeAd , adding native ad");
this.ad = ad;
adView = mInflater.inflate(R.layout.row_timeline_ad_unit, null);
TimelineListAPKsJson.UserApk ret = new UserAPKAd(ad);
inflateAd(ad, adView, context);
list.add(AD_INDEX, ret);
Log.d("pois","addNativeAd , position on "+AD_INDEX);
this.notifyDataSetChanged();
}
示例2: onCreate
import com.facebook.ads.NativeAd; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.hscroll);
manager = new NativeAdsManager(this, "YOUR_PLACEMENT_ID", 5);
manager.setListener(this);
manager.loadAds(NativeAd.MediaCacheFlag.ALL);
inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
reloadButton = (Button)findViewById(R.id.reloadHscroll);
reloadButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
manager.loadAds();
}
});
}
示例3: request
import com.facebook.ads.NativeAd; //导入依赖的package包/类
@Override
protected void request(Context context, Map<String, String> networkData) {
if (context == null || networkData == null) {
invokeLoadFail(PNException.ADAPTER_MISSING_DATA);
} else {
mContext = context;
String placementId = networkData.get(Facebook.KEY_PLACEMENT_ID);
if (TextUtils.isEmpty(placementId)) {
invokeLoadFail(PNException.ADAPTER_ILLEGAL_ARGUMENTS);
} else {
mAdView = null;
mWrapper = null;
Facebook.init(context);
mNativeAd = new NativeAd(context, placementId);
mNativeAd.setAdListener(this);
mNativeAd.loadAd();
}
}
}
示例4: request
import com.facebook.ads.NativeAd; //导入依赖的package包/类
@Override
protected void request(Context context, Map<String, String> networkData) {
if (context == null || networkData == null) {
invokeLoadFail(PNException.ADAPTER_MISSING_DATA);
} else {
mContext = context;
String placementId = networkData.get(Facebook.KEY_PLACEMENT_ID);
if (TextUtils.isEmpty(placementId)) {
invokeLoadFail(PNException.ADAPTER_ILLEGAL_ARGUMENTS);
} else {
Facebook.init(context);
mAdView = null;
mWrapper = null;
mNativeAd = new NativeAd(context, placementId);
mNativeAd.setAdListener(this);
mNativeAd.loadAd();
}
}
}
示例5: addNativeAd
import com.facebook.ads.NativeAd; //导入依赖的package包/类
public synchronized void addNativeAd(NativeAd ad) {
if (ad == null) {
return;
}
if (this.ad != null) {
// Clean up the old ad before inserting the new one
this.ad.unregisterView();
this.datas.remove(AD_INDEX);
this.ad = null;
this.notifyDataSetChanged();
}
this.ad = ad;
View adView = inflater.inflate(R.layout.ad_list, null);
inflateAd(ad, adView);
datas.add(AD_INDEX, adView);
this.notifyDataSetChanged();
}
示例6: addNativeAd
import com.facebook.ads.NativeAd; //导入依赖的package包/类
public synchronized void addNativeAd(NativeAd ad) {
if (ad == null) {
return;
}
if (this.ad != null) {
// Clean up the old ad before inserting the new one
this.ad.unregisterView();
this.list.remove(AD_INDEX);
this.ad = null;
this.notifyDataSetChanged();
}
this.ad = ad;
View adView = inflater.inflate(R.layout.ad_unit, null);
NativeAdSampleActivity.inflateAd(ad, adView, NativeAdListActivity.this);
list.add(AD_INDEX, adView);
this.notifyDataSetChanged();
}
示例7: onAdLoaded
import com.facebook.ads.NativeAd; //导入依赖的package包/类
@Override
public void onAdLoaded(Ad ad) {
Logger.d("FragmentSocialTimeline","onAdLoaded , ad: "+ad.toString());
if(getActivity() != null){
adapter.addNativeAd((NativeAd) ad,getActivity(),apks);
}
}
示例8: onAdLoaded
import com.facebook.ads.NativeAd; //导入依赖的package包/类
@Override
public void onAdLoaded(final Ad ad) {
// This identity check is from Facebook's Native API sample code:
// https://developers.facebook.com/docs/audience-network/android/native-api
if (!this.nativeAd.equals(ad) || !this.nativeAd.isAdLoaded()) {
this.getCustomEventNativeListener().onNativeAdFailed(NativeErrorCode.NETWORK_INVALID_STATE);
return;
}
this.setTitle(this.nativeAd.getAdTitle());
this.setText(this.nativeAd.getAdBody());
final NativeAd.Image coverImage = this.nativeAd.getAdCoverImage();
if (coverImage != null) this.setMainImageUrl(coverImage.getUrl());
final NativeAd.Image icon = this.nativeAd.getAdIcon();
if (icon != null) this.setIconImageUrl(icon.getUrl());
this.setCallToAction(this.nativeAd.getAdCallToAction());
this.setStarRating(FacebookNativeAd.getStarRatingValue(this.nativeAd.getAdStarRating()));
this.addExtra(FacebookNativeAd.SOCIAL_CONTEXT_FOR_AD, this.nativeAd.getAdSocialContext());
final NativeAd.Image adChoicesIconImage = this.nativeAd.getAdChoicesIcon();
if (adChoicesIconImage != null) {
this.setPrivacyInformationIconImageUrl(adChoicesIconImage.getUrl());
this.setPrivacyInformationIconClickThroughUrl(this.nativeAd.getAdChoicesLinkUrl());
}
this.preCacheImages(this.getImageUrls());
this.setImpressionMinTimeViewed(BaseStaticNativeAd.IMPRESSION_MIN_TIME);
}
示例9: FacebookNativeAdModel
import com.facebook.ads.NativeAd; //导入依赖的package包/类
public FacebookNativeAdModel(Context context, NativeAd nativeAd) {
super(context);
if (nativeAd != null) {
mNativeAd = nativeAd;
mNativeAd.setAdListener(this);
}
}
示例10: getStarRating
import com.facebook.ads.NativeAd; //导入依赖的package包/类
@Override
public float getStarRating() {
float starRating = 0;
if (mNativeAd != null) {
NativeAd.Rating rating = mNativeAd.getAdStarRating();
if (rating != null) {
double ratingScale = rating.getScale();
double ratingValue = rating.getValue();
starRating = (float) ((ratingValue / ratingScale) * 5);
}
}
return starRating;
}
示例11: onAdLoaded
import com.facebook.ads.NativeAd; //导入依赖的package包/类
@Override
public void onAdLoaded(Ad ad) {
if (ad == mNativeAd) {
FacebookNativeAdModel wrapModel = new FacebookNativeAdModel(mContext, (NativeAd) ad);
wrapModel.setInsightModel(mInsight);
invokeLoadFinish(wrapModel);
}
}
示例12: setNativeAd
import com.facebook.ads.NativeAd; //导入依赖的package包/类
/**
* Called by the view manager when adsManager prop is set. Sends serialised
* version of a native ad back to Javascript.
*
* Automatically registers current view for interactions on an ad so that
* it becomes clickable.
*
* @param nativeAd
*/
public void setNativeAd(NativeAd nativeAd) {
mNativeAd = nativeAd;
if (nativeAd == null) {
mEventEmitter.receiveEvent(getId(), "onAdLoaded", null);
return;
}
NativeAd.Image coverImage = nativeAd.getAdCoverImage();
NativeAd.Image iconImage = nativeAd.getAdIcon();
WritableMap event = Arguments.createMap();
event.putString("title", nativeAd.getAdTitle());
event.putString("subtitle", nativeAd.getAdSubtitle());
event.putString("description", nativeAd.getAdBody());
event.putString("callToActionText", nativeAd.getAdCallToAction());
// Check as they might be null because of memory issues on low-end devices
if (coverImage != null) {
event.putString("coverImage", coverImage.getUrl());
}
if (iconImage != null) {
event.putString("icon", iconImage.getUrl());
}
mEventEmitter.receiveEvent(getId(), "onAdLoaded", event);
mNativeAd.registerViewForInteraction(this);
}
示例13: FacebookNativeAd
import com.facebook.ads.NativeAd; //导入依赖的package包/类
FacebookNativeAd(final Context context,
final NativeAd nativeAd,
final CustomEventListener customEventListener) {
mContext = context.getApplicationContext();
mFbNativeAd = nativeAd;
mCustomEventListener = customEventListener;
}
示例14: requestNativeAd
import com.facebook.ads.NativeAd; //导入依赖的package包/类
@Override
public void requestNativeAd(Context context,
MediationNativeListener listener,
Bundle serverParameters,
NativeMediationAdRequest mediationAdRequest,
Bundle mediationExtras) {
mNativeListener = listener;
if (!isValidRequestParameters(context, serverParameters)) {
mNativeListener.onAdFailedToLoad(this, AdRequest.ERROR_CODE_INVALID_REQUEST);
return;
}
// Verify that the request is for both app install and content ads.
if (!(mediationAdRequest.isAppInstallAdRequested()
&& mediationAdRequest.isContentAdRequested())) {
Log.w(TAG, "Failed to request native ad. Both app install and content ad should be "
+ "requested");
mNativeListener.onAdFailedToLoad(this, AdRequest.ERROR_CODE_INVALID_REQUEST);
return;
}
String placementId = serverParameters.getString(PLACEMENT_PARAMETER);
// Get the optional extras if set by the publisher.
if (mediationExtras != null) {
mIsAdChoicesIconExpandable = mediationExtras.getBoolean(
FacebookExtrasBundleBuilder.KEY_EXPANDABLE_ICON, true);
}
mMediaView = new MediaView(context);
mNativeAd = new NativeAd(context, placementId);
mNativeAd.setAdListener(new NativeListener(mNativeAd, mediationAdRequest));
buildAdRequest(mediationAdRequest);
mNativeAd.loadAd();
}
示例15: getRating
import com.facebook.ads.NativeAd; //导入依赖的package包/类
/**
* Convert rating to a scale of 1 to 5.
*/
private Double getRating(NativeAd.Rating rating) {
if (rating == null) {
return null;
}
return (MAX_STAR_RATING * rating.getValue()) / rating.getScale();
}