Search in sources :

Example 1 with StaticNativeAd

use of com.mopub.nativeads.StaticNativeAd in project prebid-mobile-android by prebid.

the class XandrNativeInAppMoPubDemoActivity method inflateMoPubNativeAd.

private void inflateMoPubNativeAd(NativeAd nativeAd) {
    Log.d("Prebid", "came here");
    final StaticNativeAd ad = (StaticNativeAd) nativeAd.getBaseNativeAd();
    Log.d("Prebid", "" + ad.getExtras().toString());
    LinearLayout nativeContainer = new LinearLayout(XandrNativeInAppMoPubDemoActivity.this);
    nativeContainer.setOrientation(LinearLayout.VERTICAL);
    LinearLayout iconAndTitle = new LinearLayout(XandrNativeInAppMoPubDemoActivity.this);
    iconAndTitle.setOrientation(LinearLayout.HORIZONTAL);
    ImageView icon = new ImageView(XandrNativeInAppMoPubDemoActivity.this);
    icon.setLayoutParams(new LinearLayout.LayoutParams(160, 160));
    Util.loadImage(icon, ad.getIconImageUrl());
    iconAndTitle.addView(icon);
    TextView title = new TextView(XandrNativeInAppMoPubDemoActivity.this);
    title.setTextSize(20);
    title.setText(ad.getTitle());
    iconAndTitle.addView(title);
    nativeContainer.addView(iconAndTitle);
    ImageView image = new ImageView(XandrNativeInAppMoPubDemoActivity.this);
    image.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    Util.loadImage(image, ad.getMainImageUrl());
    nativeContainer.addView(image);
    TextView description = new TextView(XandrNativeInAppMoPubDemoActivity.this);
    description.setTextSize(18);
    description.setText(ad.getText());
    nativeContainer.addView(description);
    Button cta = new Button(XandrNativeInAppMoPubDemoActivity.this);
    cta.setText(ad.getCallToAction());
    cta.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(ad.getClickDestinationUrl()));
            startActivity(browserIntent);
        }
    });
    nativeContainer.addView(cta);
    ((FrameLayout) XandrNativeInAppMoPubDemoActivity.this.findViewById(R.id.adFrame)).addView(nativeContainer);
}
Also used : Button(android.widget.Button) FrameLayout(android.widget.FrameLayout) TextView(android.widget.TextView) Intent(android.content.Intent) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout) StaticNativeAd(com.mopub.nativeads.StaticNativeAd)

Aggregations

Intent (android.content.Intent)1 View (android.view.View)1 Button (android.widget.Button)1 FrameLayout (android.widget.FrameLayout)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 StaticNativeAd (com.mopub.nativeads.StaticNativeAd)1