Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The MobileFusePullTabAd class provided by the MobileFuse SDK will handle the loading, display, and interactivity of the pull-tab creative. It is similar in implementation to MobileFuse interstitial ads.

Info

Note: Ensure that critical sections of your app, for example buttons or text, do not sit within the left margin of the screen when displaying a pull-tab ad.

...

Next, add a listener - the listener will allow you to receive events from the ad unit. The pull-tab ad has some additional callbacks for pull-tab specific events.

Code Block
languagejava
pullTabAdpullTab.setListener(new MobileFusePullTabAd.Listener() {
    @Override
    public void onAdClosed() {
        // The pull-tab ad has been dismissed and closed
    }

    @Override
    public void onAdPulled() {
        // The pull-tab ad has been pulled and expanded into a full-screen interstitial style view
    }

    @Override
    public void onAdLoaded() {
         // Called when the pull tab ad has been loaded and is ready to be displayed
    }

    @Override
    public void onAdNotFilled() {
        // The server responded with no fill (no ad available)
    }

    @Override
    public void onAdRendered() {
        // The pull-tab ad has been rendered and is displaying to the user
    }

    @Override
    public void onAdClicked() {
        // Called when the user clicks the pull-tab ad
    }

    @Override
    public void onAdExpired() {
        // This ad has expired and can no longer be displayed to the user - load a new ad
    }

    @Override
    public void onAdError(AdError adError) {
        // An error occurred, examine the adError argument to determine the problem
    }
});

...

Note

Note: The pull-tab will render a tab in the left 10% of screen space. Be sure that when a pull-tab ad is displayed that you don’t place important UI components or buttons within this area. You may want to add padding to the left side of your activity to shift your UI away from the ad slightly. See the sample code for an example.

Code Block
languagejava
pullTabAd.showAd();

...

Code Block
languagejava
if (pullTabAd.isLoaded()) {
   // The ad is ready to be displayed!
}

Sample Code

LUKE TODO: Update sample

The following sample shows an activity that will initialize and then immediately display the pull-tab ad:

...

Java

Expand
titleMainActivity.java
Code Block
import android.app.Activity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Display;
import android.widget.Toast;

import com.mobilefuse.sdk.AdError;
import com.mobilefuse.sdk.
PullTabAd
MobileFuse;
import com.mobilefuse.sdk.
PullTabAdListener
MobileFusePullTabAd;
import com.mobilefuse.sdk.
MobileFuse
MobileFuseSettings;
import com.mobilefuse.sdk.SdkInitListener;
import com.mobilefuse.sdk.privacy.
PrivacyPreferences
MobileFusePrivacyPreferences;

public class MainActivity extends Activity {
    final int publisherId = 0;
    final int appId = 0;
    final String pullTabPlacementId = "000000";
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        // Set up the user's privacy preferences before init:
    
PrivacyPreferences.Builder privacyPrefs =
    MobileFuse.setPrivacyPreferences(
                new 
PrivacyPreferences
MobileFusePrivacyPreferences.Builder()
;

                        
privacyPrefs
.
setIabConsentString("...");
setSubjectToCoppa(false)
                        
MobileFuse
.
setPrivacyPreferences(privacyPrefs.build());
setUsPrivacyConsentString("1YNN")
                  
String
 
appId
 
=
 
"0000_00000";
   .build()
     
String
 
pullTabAdPlacement
 
=
 
"000000"
);
        
        Activity 
ctx
activity = this;
        MobileFuse.init(
ctx
activity, publisherId, appId, new SdkInitListener() {
            @Override
            public void onInitSuccess() {
                Toast.makeText(
ctx
activity, "SDK Init 
success
Success", Toast.LENGTH_SHORT).show();
                
PullTabAd ad

                // Create a new interstitial ad and display it immediately
                MobileFusePullTabAd pullTab = new 
PullTabAd
MobileFusePullTabAd(
ctx
activity, 
pullTabAdPlacement
pullTabPlacementId);
                
ad
pullTab.setListener(new 
PullTabAdListener
MobileFusePullTabAd.Listener() {
                    @Override public void onAdLoaded() {
                        // Show the ad as soon as it has loaded:
                        pullTab.showAd();
                    }
                    @Override public void 
onAdLoaded
onAdRendered() {
                        //
Show the ad as soon as it has loaded
 Set our left margin to 10% of the width
                        setAppLeftMarginFraction(0.1f);
                    }
                    @Override public void onAdClosed() {
                        // Reset our margin:
                        
ad.showAd
setAppLeftMarginFraction(0f);
                    }
                    @Override public void 
onAdUnavailable
onAdPulled() { }
                    @Override public void 
onAdComplete
onAdNotFilled() { }
                    @Override public void 
onAdShowing
onAdClicked() { }
                    @Override public void 
onAdClicked
onAdExpired() { }
                    @Override public void onAdError(AdError adError) { }
                });
                // Send the 
Request
ad 
loading
request 
of
to the 
ad
server:
                
ad
pullTab.loadAd();
            }
            
            @Override
            public void onInitError() {
                Toast.makeText(
ctx
activity, "SDK Init 
failed
Failed", Toast.LENGTH_SHORT).show();
            }
        });
    }
    
    private void setAppLeftMarginFraction(float fraction) {
        // Example: Calculating the left margin as a fraction of the entire screen width:
        Display display = getWindowManager().getDefaultDisplay();
        DisplayMetrics outMetrics = new DisplayMetrics ();
        display.getMetrics(outMetrics);
        
        float density  = getResources().getDisplayMetrics().density;
        float dpWidth  = outMetrics.widthPixels / density;
    
        findViewById(R.id.main_view_container).setPadding((int)(dpWidth * fraction), 0, 0, 0);
    }
}

Kotlin

Expand
titleMainActivity.kt
Code Block
import android.app.Activity
import android.os.Bundle
import android.util.DisplayMetrics
import android.view.Display
import android.view.View
import android.widget.Toast
import com.mobilefuse.sdk.AdError
import com.mobilefuse.sdk.MobileFuse
import com.mobilefuse.sdk.MobileFusePullTabAd
import com.mobilefuse.sdk.SdkInitListener
import com.mobilefuse.sdk.privacy.MobileFusePrivacyPreferences


class MainActivity : Activity() {
    private val publisherId = 0
    private val appId = 0
    private val pullTabPlacementId = "000000"

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // Set up the user's privacy preferences before init:
        MobileFuse.setPrivacyPreferences(
            MobileFusePrivacyPreferences.Builder()
                .setSubjectToCoppa(false)
                .setUsPrivacyConsentString("1YNN")
                .build()
        )
        val activity: Activity = this
        MobileFuse.init(activity, publisherId, appId, object : SdkInitListener {
            override fun onInitSuccess() {
                Toast.makeText(activity, "SDK Init Success", Toast.LENGTH_SHORT).show()

                // Create a new interstitial ad and display it immediately
                val pullTab = MobileFusePullTabAd(activity, pullTabPlacementId)
                pullTab.setListener(object : MobileFusePullTabAd.Listener {
                    override fun onAdLoaded() {
                        // Show the ad as soon as it has loaded:
                        pullTab.showAd()
                    }

                    override fun onAdRendered() {
                        // Set our left margin to 10% of the width
                        setAppLeftMarginFraction(0.1f)
                    }

                    override fun onAdClosed() {
                        // Reset our margin:
                        setAppLeftMarginFraction(0f)
                    }

                    override fun onAdPulled() {}
                    override fun onAdNotFilled() {}
                    override fun onAdClicked() {}
                    override fun onAdExpired() {}
                    override fun onAdError(adError: AdError?) {}
                })
                // Send the ad request to the server:
                pullTab.loadAd()
            }

            override fun onInitError() {
                Toast.makeText(activity, "SDK Init Failed", Toast.LENGTH_SHORT).show()
            }
        })
    }

    private fun setAppLeftMarginFraction(fraction: Float) {
        // Example: Calculating the left margin as a fraction of the entire screen width:
        val display: Display = windowManager.defaultDisplay
        val outMetrics = DisplayMetrics()
        display.getMetrics(outMetrics)
        val density = resources.displayMetrics.density
        val dpWidth = outMetrics.widthPixels / density
        findViewById<View>(R.id.main_view_container).setPadding((dpWidth * fraction).toInt(), 0, 0, 0)
    }
}