ThirdPartyAdapters/inmobi/inmobi/src/main/java/com/google/ads/mediation/inmobi/InMobiAppInstallNativeAdMapper.java
// Map InMobi Native Ad to AdMob App Install Ad.
Map InMobi Native Ad to AdMob App Install Ad.
Map InMobi Native Ad to AdMob App Install Ad .
void mapAppInstallAd(final Context context) {
    JSONObject payLoad;
    HashMap<String, URL> map;
    final Uri iconUri;
    final Double iconScale;
    try {
      if (mInMobiNative.getCustomAdContent() != null) {
        payLoad = mInMobiNative.getCustomAdContent();
      } else {
        mMediationNativeListener.onAdFailedToLoad(mInMobiAdapter, AdRequest.ERROR_CODE_NO_FILL);
        return;
      }
      setHeadline(
          InMobiAdapterUtils.mandatoryChecking(
              mInMobiNative.getAdTitle(), InMobiNetworkValues.TITLE));
      setBody(
          InMobiAdapterUtils.mandatoryChecking(
              mInMobiNative.getAdDescription(), InMobiNetworkValues.DESCRIPTION));
      setCallToAction(
          InMobiAdapterUtils.mandatoryChecking(
              mInMobiNative.getAdCtaText(), InMobiNetworkValues.CTA));
      String landingURL =
          InMobiAdapterUtils.mandatoryChecking(
              mInMobiNative.getAdLandingPageUrl(), InMobiNetworkValues.LANDING_URL);
      Bundle paramMap = new Bundle();
      paramMap.putString(InMobiNetworkValues.LANDING_URL, landingURL);
      setExtras(paramMap);
      map = new HashMap<>();
      URL iconURL = new URL(mInMobiNative.getAdIconUrl());
      iconUri = Uri.parse(iconURL.toURI().toString());
      iconScale = 1.0;
      if (!this.mIsOnlyURL) {
        map.put(ImageDownloaderAsyncTask.KEY_ICON, iconURL);
      } else {
        setIcon(new InMobiNativeMappedImage(null, iconUri, iconScale));
        List<NativeAd.Image> imagesList = new ArrayList<>();
        imagesList.add(
            new InMobiNativeMappedImage(new ColorDrawable(Color.TRANSPARENT), null, 1.0));
        setImages(imagesList);
      }
    } catch (MandatoryParamException | MalformedURLException | URISyntaxException e) {
      e.printStackTrace();
      mMediationNativeListener.onAdFailedToLoad(mInMobiAdapter, AdRequest.ERROR_CODE_NO_FILL);
      return;
    }
    try {
      if (payLoad.has(InMobiNetworkValues.RATING)) {
        setStarRating(Double.parseDouble(payLoad.getString(InMobiNetworkValues.RATING)));
      }
      if (payLoad.has(InMobiNetworkValues.PACKAGE_NAME)) {
        setStore("Google Play");
      } else {
        setStore("Others");
      }
      if (payLoad.has(InMobiNetworkValues.PRICE)) {
        setPrice(payLoad.getString(InMobiNetworkValues.PRICE));
      }
    } catch (JSONException e) {
      e.printStackTrace();
    }
    final RelativeLayout placeHolderView = new RelativeLayout(context);
    placeHolderView.setLayoutParams(
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT));
    placeHolderView.setGravity(Gravity.CENTER);
    placeHolderView.post(
        new Runnable() {
          @Override
          public void run() {
            final View primaryView =
                mInMobiNative.getPrimaryViewOfWidth(
                    context, null, placeHolderView, placeHolderView.getWidth());
            if (primaryView == null) {
              return;
            }
            placeHolderView.addView(primaryView);
          }
        });
    setMediaView(placeHolderView);
    boolean hasVideo = (mInMobiNative.isVideo() == null) ? false : mInMobiNative.isVideo();
    setHasVideoContent(hasVideo);
    setOverrideClickHandling(false);
    if (!this.mIsOnlyURL) {
      new ImageDownloaderAsyncTask(
              new ImageDownloaderAsyncTask.DrawableDownloadListener() {
                @Override
                public void onDownloadSuccess(HashMap<String, Drawable> drawableMap) {
                  Drawable iconDrawable = drawableMap.get(ImageDownloaderAsyncTask.KEY_ICON);
                  setIcon(new InMobiNativeMappedImage(iconDrawable, iconUri, iconScale));
                  List<NativeAd.Image> imagesList = new ArrayList<>();
                  imagesList.add(
                      new InMobiNativeMappedImage(new ColorDrawable(Color.TRANSPARENT), null, 1.0));
                  setImages(imagesList);
                  if ((null != iconDrawable)) {
                    mMediationNativeListener.onAdLoaded(
                        mInMobiAdapter, InMobiAppInstallNativeAdMapper.this);
                  } else {
                    mMediationNativeListener.onAdFailedToLoad(
                        mInMobiAdapter, AdRequest.ERROR_CODE_NETWORK_ERROR);
                  }
                }
                @Override
                public void onDownloadFailure() {
                  mMediationNativeListener.onAdFailedToLoad(
                      mInMobiAdapter, AdRequest.ERROR_CODE_NO_FILL);
                }
              })
          .execute(map);
    } else {
      mMediationNativeListener.onAdLoaded(mInMobiAdapter, InMobiAppInstallNativeAdMapper.this);
    }
  }
void mapAppInstallAd ( final Context context ) { JSONObject payLoad ; HashMap < String , URL > map ; final Uri iconUri ; final Double iconScale ; try { if ( mInMobiNative . getCustomAdContent ( ) != null ) { payLoad = mInMobiNative . getCustomAdContent ( ) ; } else { mMediationNativeListener . onAdFailedToLoad ( mInMobiAdapter , AdRequest . ERROR_CODE_NO_FILL ) ; return ; } setHeadline ( InMobiAdapterUtils . mandatoryChecking ( mInMobiNative . getAdTitle ( ) , InMobiNetworkValues . TITLE ) ) ; setBody ( InMobiAdapterUtils . mandatoryChecking ( mInMobiNative . getAdDescription ( ) , InMobiNetworkValues . DESCRIPTION ) ) ; setCallToAction ( InMobiAdapterUtils . mandatoryChecking ( mInMobiNative . getAdCtaText ( ) , InMobiNetworkValues . CTA ) ) ; String landingURL = InMobiAdapterUtils . mandatoryChecking ( mInMobiNative . getAdLandingPageUrl ( ) , InMobiNetworkValues . LANDING_URL ) ; Bundle paramMap = new Bundle ( ) ; paramMap . putString ( InMobiNetworkValues . LANDING_URL , landingURL ) ; setExtras ( paramMap ) ; map = new HashMap < > ( ) ; URL iconURL = new URL ( mInMobiNative . getAdIconUrl ( ) ) ; iconUri = Uri . parse ( iconURL . toURI ( ) . toString ( ) ) ; iconScale = 1.0 ; if ( ! this . mIsOnlyURL ) { map . put ( ImageDownloaderAsyncTask . KEY_ICON , iconURL ) ; } else { setIcon ( new InMobiNativeMappedImage ( null , iconUri , iconScale ) ) ; List < NativeAd . Image > imagesList = new ArrayList < > ( ) ; imagesList . add ( new InMobiNativeMappedImage ( new ColorDrawable ( Color . TRANSPARENT ) , null , 1.0 ) ) ; setImages ( imagesList ) ; } } catch ( MandatoryParamException | MalformedURLException | URISyntaxException e ) { e . printStackTrace ( ) ; mMediationNativeListener . onAdFailedToLoad ( mInMobiAdapter , AdRequest . ERROR_CODE_NO_FILL ) ; return ; } try { if ( payLoad . has ( InMobiNetworkValues . RATING ) ) { setStarRating ( Double . parseDouble ( payLoad . getString ( InMobiNetworkValues . RATING ) ) ) ; } if ( payLoad . has ( InMobiNetworkValues . PACKAGE_NAME ) ) { setStore ( "Google Play" ) ; } else { setStore ( "Others" ) ; } if ( payLoad . has ( InMobiNetworkValues . PRICE ) ) { setPrice ( payLoad . getString ( InMobiNetworkValues . PRICE ) ) ; } } catch ( JSONException e ) { e . printStackTrace ( ) ; } final RelativeLayout placeHolderView = new RelativeLayout ( context ) ; placeHolderView . setLayoutParams ( new RelativeLayout . LayoutParams ( RelativeLayout . LayoutParams . MATCH_PARENT , RelativeLayout . LayoutParams . MATCH_PARENT ) ) ; placeHolderView . setGravity ( Gravity . CENTER ) ; placeHolderView . post ( new Runnable ( ) { @ Override public void run ( ) { final View primaryView = mInMobiNative . getPrimaryViewOfWidth ( context , null , placeHolderView , placeHolderView . getWidth ( ) ) ; if ( primaryView == null ) { return ; } placeHolderView . addView ( primaryView ) ; } } ) ; setMediaView ( placeHolderView ) ; boolean hasVideo = ( mInMobiNative . isVideo ( ) == null ) ? false : mInMobiNative . isVideo ( ) ; setHasVideoContent ( hasVideo ) ; setOverrideClickHandling ( false ) ; if ( ! this . mIsOnlyURL ) { new ImageDownloaderAsyncTask ( new ImageDownloaderAsyncTask . DrawableDownloadListener ( ) { @ Override public void onDownloadSuccess ( HashMap < String , Drawable > drawableMap ) { Drawable iconDrawable = drawableMap . get ( ImageDownloaderAsyncTask . KEY_ICON ) ; setIcon ( new InMobiNativeMappedImage ( iconDrawable , iconUri , iconScale ) ) ; List < NativeAd . Image > imagesList = new ArrayList < > ( ) ; imagesList . add ( new InMobiNativeMappedImage ( new ColorDrawable ( Color . TRANSPARENT ) , null , 1.0 ) ) ; setImages ( imagesList ) ; if ( ( null != iconDrawable ) ) { mMediationNativeListener . onAdLoaded ( mInMobiAdapter , InMobiAppInstallNativeAdMapper . this ) ; } else { mMediationNativeListener . onAdFailedToLoad ( mInMobiAdapter , AdRequest . ERROR_CODE_NETWORK_ERROR ) ; } } @ Override public void onDownloadFailure ( ) { mMediationNativeListener . onAdFailedToLoad ( mInMobiAdapter , AdRequest . ERROR_CODE_NO_FILL ) ; } } ) . execute ( map ) ; } else { mMediationNativeListener . onAdLoaded ( mInMobiAdapter , InMobiAppInstallNativeAdMapper . this ) ; } }
Map InMobi Native Ad to AdMob App Install Ad.
Map InMobi Native Ad to AdMob App Install Ad .
// App icon. // Add primary view as media view // Download drawables.