com.facebook.ads.AdIconView Java Examples

The following examples show how to use com.facebook.ads.AdIconView. 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: FBNativeAdResponse.java    From mobile-sdk-android with Apache License 2.0 6 votes vote down vote up
private boolean getMediaViewsForRegisterView(View view) {

        if(view instanceof ViewGroup){
            ViewGroup subViews =  (ViewGroup)view;
            for (int i = 0; i < subViews.getChildCount(); i++) {
                final View subview = subViews.getChildAt(i);
                if (subview instanceof AdIconView) {
                    adIconView = (AdIconView )subview;
                }else if (subview instanceof MediaView) {
                    adMediaView = (MediaView )subview;
                }else if(subview instanceof ViewGroup){
                    getMediaViewsForRegisterView(subview);
                }
                if(adMediaView != null && adIconView != null){
                    break;
                }
            }
        }
        if(adMediaView != null){
            return true;
        }
        return false;
    }
 
Example #2
Source File: StoryFragment.java    From Instagram-Profile-Downloader with MIT License 4 votes vote down vote up
private void inflateAd(NativeAd nativeAd){


        try {


        nativeAd.unregisterView();

        // Add the Ad view into the ad container.
        nativeAdLayout = view.findViewById(R.id.native_ad_container);
        LayoutInflater inflater = LayoutInflater.from(getActivity());
        // Inflate the Ad view.  The layout referenced should be the one you created in the last step.
        adView = (LinearLayout) inflater.inflate(R.layout.layout_native_ad_view, nativeAdLayout, false);
        nativeAdLayout.addView(adView);

        // Add the AdOptionsView
        LinearLayout adChoicesContainer = view.findViewById(R.id.ad_choices_container);
        AdOptionsView adOptionsView = new AdOptionsView(getActivity(), nativeAd, nativeAdLayout);
        adChoicesContainer.removeAllViews();
        adChoicesContainer.addView(adOptionsView, 0);

        // Create native UI using the ad metadata.
        AdIconView nativeAdIcon = adView.findViewById(R.id.native_ad_icon);
        TextView nativeAdTitle = adView.findViewById(R.id.native_ad_title);
        MediaView nativeAdMedia = adView.findViewById(R.id.native_ad_media);
        TextView nativeAdSocialContext = adView.findViewById(R.id.native_ad_social_context);
        TextView nativeAdBody = adView.findViewById(R.id.native_ad_body);
        TextView sponsoredLabel = adView.findViewById(R.id.native_ad_sponsored_label);
        Button nativeAdCallToAction = adView.findViewById(R.id.native_ad_call_to_action);

        // Set the Text.
        nativeAdTitle.setText(nativeAd.getAdvertiserName());
        nativeAdBody.setText(nativeAd.getAdBodyText());
        nativeAdSocialContext.setText(nativeAd.getAdSocialContext());
        nativeAdCallToAction.setVisibility(nativeAd.hasCallToAction() ? View.VISIBLE : View.INVISIBLE);
        nativeAdCallToAction.setText(nativeAd.getAdCallToAction());
        sponsoredLabel.setText(nativeAd.getSponsoredTranslation());

        // Create a list of clickable views
        List<View> clickableViews = new ArrayList<>();
        clickableViews.add(nativeAdTitle);
        clickableViews.add(nativeAdCallToAction);

        // Register the Title and CTA button to listen for clicks.
        nativeAd.registerViewForInteraction(
                adView,
                nativeAdMedia,
                nativeAdIcon,
                clickableViews);
        }catch (Exception e){
            Log.e(TAG, "inflateAd: "+e );
        }
    }
 
Example #3
Source File: AdIconViewManager.java    From react-native-fbads with MIT License 4 votes vote down vote up
@Override
protected AdIconView createViewInstance(ThemedReactContext reactContext) {
  return new AdIconView(reactContext);
}
 
Example #4
Source File: NativeAdView.java    From react-native-fbads with MIT License 4 votes vote down vote up
public void registerViewsForInteraction(MediaView mediaView, AdIconView adIconView, List<View> clickableViews) {
  mNativeAd.registerViewForInteraction(this, mediaView, adIconView, clickableViews);
}