#Region Service Attributes
#StartAtBoot: False
#End Region
Sub Process_Globals
'GENERAL
Private appId As String = "xxxx"
Private controllerDisplayio As JavaObject
Private ctxt As JavaObject
Private SdkListener As Object
Private retryTime As Int = 30000
Private reloadTime As Int = 2000
'INTER
Private intersticialAd As JavaObject
Private intersticialPlacementId As String = "xxxx"
Private intersticialPlacement As JavaObject
Public isInterstitialReady As Boolean = False
'BANNER
Public bannerView As JavaObject
Private bannerPlacementId As String = "xxxx"
Private bannerPlacement As JavaObject
Private AdRequestBanner As JavaObject
Public isBannerReady As Boolean = False
End Sub
Sub Service_Create
'INITIALIZE CONTEXT
ctxt.InitializeContext
'INITIALIZE SDK
controllerDisplayio = controllerDisplayio.InitializeStatic("com.brandio.ads.Controller").RunMethod("getInstance", Null)
SdkListener = controllerDisplayio.CreateEventFromUI("com.brandio.ads.listeners.SdkInitListener", "SDK", Null)
controllerDisplayio.RunMethod("init", Array(ctxt, Null, appId, SdkListener))
End Sub
Sub Service_Start (StartingIntent As Intent)
Service.StopAutomaticForeground
End Sub
Sub Service_Destroy
End Sub
Sub SDK_Event (MethodName As String, Args() As Object) As Object
Select MethodName
Case "onInit"
LogColor("onInit SDK Displayio", Colors.Yellow)
intersticialPlacement = controllerDisplayio.RunMethod("getPlacement", Array(intersticialPlacementId))
bannerPlacement = controllerDisplayio.RunMethod("getPlacement", Array(bannerPlacementId))
Get_Inter
Get_Banner
Case "onInitError"
LogColor("onInitError SDK Displayio", Colors.Yellow)
End Select
Return Null
End Sub
#Region INTER
Sub Get_Inter
Private AdRequest As JavaObject = intersticialPlacement.RunMethod("newAdRequest", Null)
Dim AdRequestListener As Object = AdRequest.CreateEventFromUI("com.brandio.ads.listeners.AdRequestListener", "adRequestIntersticial", Null)
AdRequest.RunMethod("setAdRequestListener", Array(AdRequestListener))
AdRequest.RunMethod("requestAd", Null)
End Sub
Sub adRequestIntersticial_Event (MethodName As String, Args() As Object) As Object
Select MethodName
Case "onAdReceived"
LogColor("onAdReceived Inter Displayio", Colors.Yellow)
Private AdProvider As JavaObject = Args(0)
Dim AdLoadListener As Object = AdProvider.CreateEventFromUI("com.brandio.ads.listeners.AdLoadListener", "adLoadIntersticial", Null)
AdProvider.RunMethod("setAdLoadListener", Array(AdLoadListener))
Try
AdProvider.RunMethod("loadAd", Null)
Catch
If LastException.IsInitialized Then Log(LastException)
Retry_Inter
End Try
Case "onNoAds"
LogColor("onNoAds Inter Displayio", Colors.Yellow)
isInterstitialReady = False
Retry_Inter
End Select
Return Null
End Sub
Sub adLoadIntersticial_Event (MethodName As String, Args() As Object) As Object
Select MethodName
Case "onLoaded"
LogColor("onLoaded Inter Displayio", Colors.Yellow)
intersticialAd = Args(0)
Dim AdEventListener As Object = intersticialAd.CreateEventFromUI("com.brandio.ads.listeners.AdEventListener", "AdEventIntersticial", Null)
intersticialAd.RunMethod("setEventListener", Array(AdEventListener))
isInterstitialReady = True
Case "onFailedToLoad"
LogColor("onFailedToLoad Inter Displayio", Colors.Yellow)
isInterstitialReady = False
Retry_Inter
End Select
Return Null
End Sub
Sub AdEventIntersticial_Event (MethodName As String, Args() As Object) As Object
Select MethodName
Case "onShown"
LogColor("onShown Inter Displayio", Colors.Yellow)
isInterstitialReady = False
Case "onFailedToShow"
LogColor("onFailedToShow Inter Displayio", Colors.Yellow)
isInterstitialReady = False
Reload_Inter
Case "onClicked"
LogColor("onClicked Inter Displayio", Colors.Yellow)
isInterstitialReady = False
Case "onClosed"
LogColor("onClosed Inter Displayio", Colors.Yellow)
isInterstitialReady = False
Reload_Inter
Case "onAdCompleted"
isInterstitialReady = False
LogColor("onAdCompleted Inter Displayio", Colors.Yellow)
End Select
Return Null
End Sub
Sub Retry_Inter
isInterstitialReady = False
Sleep(retryTime)
Get_Inter
End Sub
Sub Reload_Inter
isInterstitialReady = False
Sleep(reloadTime)
Get_Inter
End Sub
Sub Show_Inter
intersticialAd.RunMethod("showAd", Array(ctxt))
End Sub
#End Region
#Region BANNER
Sub Get_Banner
AdRequestBanner = bannerPlacement.RunMethod("newAdRequest", Null)
Dim AdRequestListener As Object = AdRequestBanner.CreateEventFromUI("com.brandio.ads.listeners.AdRequestListener", "adRequestBanner", Null)
AdRequestBanner.RunMethod("setAdRequestListener", Array(AdRequestListener))
AdRequestBanner.RunMethod("requestAd", Null)
End Sub
Sub adRequestBanner_Event (MethodName As String, Args() As Object) As Object
Select MethodName
Case "onAdReceived"
LogColor("onAdReceived Banner Displayio", Colors.Yellow)
Private AdProvider As JavaObject = Args(0)
Dim AdLoadListener As Object = AdProvider.CreateEventFromUI("com.brandio.ads.listeners.AdLoadListener", "adLoadBanner", Null)
AdProvider.RunMethod("setAdLoadListener", Array(AdLoadListener))
Try
AdProvider.RunMethod("loadAd", Null)
Catch
If LastException.IsInitialized Then Log(LastException)
Retry_Banner
End Try
Case "onNoAds"
LogColor("onNoAds Banner Displayio", Colors.Yellow)
isBannerReady = False
Retry_Banner
End Select
Return Null
End Sub
Sub adLoadBanner_Event (MethodName As String, Args() As Object) As Object
Select MethodName
Case "onLoaded"
LogColor("onLoaded Banner Displayio", Colors.Yellow)
bannerView = bannerPlacement.RunMethod("getBanner", Array(ctxt, AdRequestBanner.RunMethod("getId", Null)))
isBannerReady = True
Case "onFailedToLoad"
LogColor("onFailedToLoad Banner Displayio", Colors.Yellow)
isBannerReady = False
Retry_Banner
End Select
Return Null
End Sub
Sub Retry_Banner
isBannerReady = False
Sleep(retryTime)
Get_Banner
End Sub
#End Region