Advertisement Plugin - Android


The following document describes the Applicaster API for pluggable advertisement

The diagrams below show the Banner and the interstitial loading flows. The blue part is called by the SDK, the green by plugin.











Ad View - implemented in the Applicaster SDK

BannerComponent on generic app level implements the AdView interface. It contains 3 callback methods:

fun adLoaded(sender: AdViewPresenter, view: View)
fun stateChanged(sender: AdViewPresenter, adViewState: AdViewState)
fun adLoadFailed(sender: AdViewPresenter, exc: Exception)

Method adLoaded is called whenever the presenter loads an Ad. As a parameter it takesView and sender which is an implementation of AdViewPresenter.

Parameters Type Description
sender AdViewPresenter AdViewPresenter implementation instance - caller
view View AdView returned by the advertisement provider
Parameters Type Description
sender AdViewPresenter AdViewPresenter implementation instance - caller
adViewState AdViewState Current state of the advert. States are listed below

The method stateChanged is called every time the state was changed. For this plugin we have defined states: Uninitialized - whenever the ad hasn't been initialized yet, Loading - whenever the ad is loading, Loaded - whenever the ad has been loaded, Impressed - whenever the ad has been shown on screen with at least 50% visibility, Failed - whenever ad view has failed to load, Clicked - whenever the user opened the ad, Closed - whenever the ad view has been closed


The method adLoadFailed is called whenever the presenter failed to load an Ad. As a parameter it has an instance ofException.

Parameters Type Description
sender AdViewPresenter AdViewPresenter implementation instance - caller
exc Exception Reason of advertisement failure

Ad View Presenter

AdViewPresenter should be implemented on the plugin level. The following methods from the interface should be implemented:

fun init(component: AdView)
fun loadAd(adConfig: AdConfig)
fun getSize(withContainer:Boolean): Size
fun getProviderName(): String
fun reloadAdWithSize(adSize: String)
fun showInterstitial()
fun getConfig() : AdConfig

The method init is called whenever the presenter is initialised. It creates an intance of Ad Provider views.

fun init(component: AdView)
Parameters Type Description
component AdView Imprementation of the AdView interface on the Applicaster SDK level

The method loadAd is called whenever the ad configuration needs to be set and the ad is supposed to start loading its content. As a parameter it takes AdConfig which defines everything what Ad view needs so as to present content.

Parameters Type Description
adConfig AdConfig Configuration of a specific advert (size, type, unit id)

Method get advertisement size in dp

Return type Description
com.applicaster.plugins.advertisement.view.Size Return Size class specified below
class Size(var width: Int, var height: Int){
    override fun toString(): String {
        return "(${width}x${height})"

The method reloadAdWithSize is called whenever the presenter should reload the size of the Ad.

Parameters Type Description
adSize String Key name of the ad size eg. "BOX_BANNER", "SMART_BANNER"

Returns a human friendly name of the advertisement provider

Return type Description
String A human friendly name of the advertisement provider

Fire show interstitial on presenter class.


The method returns the advert configuration

Return type Description
AdConfig Returns the AdConfig class specified below
class AdConfig (var adUnitId : String,
                var component : AdView) {

    var customizedLayout = false


Ad Plugin

The AdPlugin interface should be implemented at the plugin level so as to provide a single layer of Model-View-Presenter. So for every single Model(AdConfig) and View there should exist a Presenter. The class implemets 2 methods:

fun createAd(context: Context, component: AdView): AdViewPresenter
fun setPluginModel(Plugin plugin)

The method createAd is called whenever the plugin needs to crete a presenter for the ad and initialize it

Parameters Type Description
context Context Context in which the advert will be presented
component AdView Imprementation of AdView interface
Return type Description
AdViewPresenter Returns an instance of AdViewPresenter

The method setPluginModel is called from the inherited interface GenericPlugin and provides configuration of the plugin - not used in this implementation.

results matching ""

    No results matching ""