#MultiDex: True
#Region Project Attributes
#FullScreen: True
#IncludeTitle: False
#ApplicationLabel: Demo
#VersionCode: 1
#VersionName:
#SupportedOrientations: Portrait
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#End Region
#AdditionalJar: com.google.android.ump:user-messaging-platform
Sub Process_Globals
Private xui As XUI
End Sub
Sub Globals
Dim GL As lgGL
Dim lGdx As LibGDX
Dim IP As lgInputProcessor
Dim Batch As lgSpriteBatch
Dim texsheet As lgTexture
Dim adwanted As Boolean = True
Dim Surface As View
Dim tm As Timer
Dim Camera As lgOrthographicCamera
Private Ads As AdsHelper
Private BannerAd As AdView
Private BannerAdFixedSize As AdView
Private iAd As InterstitialAd
Private Ads As AdsHelper
Private AppOpenAdUnit As String = "ca-app-pub-3940256099942544/3419835294"
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.Color=Colors.Black
If FirstTime = True Then
Dim Config As lgConfiguration
Config.useAccelerometer = False
Config.useCompass = False
Config.useWakelock = True
Config.hideStatusBar = True
Config.useImmersiveMode = True
Config.r = 8
Config.g = 8
Config.b = 8
Config.a = 8
Config.numSamples = 0
Config.maxSimultaneousSounds = 8
Surface = lGdx.InitializeView2(Config, "LG")
Activity.AddView(Surface, 0, 0, 100%x, 100%y)
tm.Initialize("timer",4000*4)
tm.Enabled = True
End If
Dim ButtonPanel As Panel
ButtonPanel.Initialize("")
Activity.AddView(ButtonPanel, 0, 250dip, 100%x, 150dip)
ButtonPanel.LoadLayout("MainPage")
Ads.Initialize
CheckConsentAndAddAds
' OLD ADS
' Create the panel view and add it to the activity
' Dim panel As Panel
' panel.Initialize("")
' panel.Color = Colors.White
' panel.SetLayout(0, 0, 100%x, 90dip)
' Activity.AddView(panel, 0, 0, 100%x, 90dip)
' ' Initialize and load the adaptive ad inside the panel
' Dim size As AdSize = GetAdaptiveAdSize
' Dim adHeight As Int = size.Height
' Dim adView As AdView
' adView.Initialize2("ad", "ca-app-pub-3940256099942544/6300978111", size.Native)
' panel.Color = Colors.Transparent
' panel.AddView(adView, 0, 0, size.Width, adHeight)
' adView.LoadAd
End Sub
Sub Activity_Resume
Ads.ShowOpenAdIfAvailable(1)
If lGdx.IsInitialized Then lGdx.Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
If UserClosed Then Ads.Background
If lGdx.IsInitialized Then lGdx.Pause
End Sub
Sub LG_Create
Batch.Initialize
IP.Initialize("IP")
texsheet.Initialize("sprite.png")
Camera.Initialize
Camera.SetToOrtho(False)
End Sub
Sub LG_Render
GL.glClearColor(0, 0, 1, 1)
GL.glClear(GL.GL10_COLOR_BUFFER_BIT)
Camera.Update
Batch.ProjectionMatrix = Camera.Combined
Batch.Begin
Dim X, Y As Int
For i = 1 To 99
X = Rnd(0,999)
Y = Rnd(0,499)
Batch.DrawTex2(texsheet, X, Y, 100dip, 100dip)
Next
Batch.End
End Sub
Sub LG_Resume
End Sub
Sub LG_Pause
End Sub
' ADD LG RESIZE
Sub LG_Dispose
If texsheet.IsInitialized Then texsheet.dispose
If Batch.IsInitialized Then Batch.dispose
End Sub
Sub IP_TouchDown(ScreenX As Int, ScreenY As Int, Pointer As Int) As Boolean
Return True
End Sub
Sub ToastMsg_Show(Text As Object)
ToastMessageShow(Text, True)
End Sub
Sub timer_Tick
Log("TIMER!")
End Sub
Private Sub CheckConsentAndAddAds
Dim m As MobileAds
Wait For (m.Initialize) MobileAds_Ready
LogColor("After MobileAds_Ready", Colors.Magenta)
' m.SetConfigutation(m.CreateRequestConfigurationBuilder(Array("77A04EE40B2AFED2AFC67701365187EC"))) 'optional. Array with test device ids. See unfiltered logs to find correct id.
' Ads.ResetConsentStatus
' Ads.SetConsentDebugParameters("77A04EE40B2AFED2AFC67701365187EC", True) 'same id as above
If Ads.GetConsentStatus = "UNKNOWN" Or Ads.GetConsentStatus = "REQUIRED" Then
Wait For (Ads.RequestConsentInformation(False)) Complete (Success As Boolean)
End If
If Ads.GetConsentStatus = "REQUIRED" And Ads.GetConsentFormAvailable Then
Wait For (Ads.ShowConsentForm) Complete (Success As Boolean)
End If
Log("Consent: " & Ads.GetConsentStatus)
LoadAds
End Sub
Sub LoadAds
Dim AdaptiveSize As Map = Ads.GetAdaptiveAdSize
' AdaptiveSize.Get("native")
' load a fixed size banner ad
BannerAdFixedSize.Initialize2("BannerAdFixedSize", "ca-app-pub-3940256099942544/6300978111", BannerAd.SIZE_IAB_MRECT)
Activity.AddView(BannerAdFixedSize, (100%x-300dip)/2, 0, 300dip, 250dip)
BannerAdFixedSize.LoadAd
BannerAd.Initialize2("BannerAd", "ca-app-pub-3940256099942544/6300978111", AdaptiveSize.Get("native"))
Activity.AddView(BannerAd, 0, 100%y-AdaptiveSize.Get("height"), AdaptiveSize.Get("width"), AdaptiveSize.Get("height"))
BannerAd.LoadAd
iAd.Initialize("iad", "ca-app-pub-3940256099942544/1033173712")
iAd.LoadAd
Ads.FetchRewardedInterstitialAd("ca-app-pub-3940256099942544/5354046379", Me, "RewardedInterstitialAd")
Ads.FetchRewardedVideoAd("ca-app-pub-3940256099942544/5224354917", Me, "RewardAd")
Ads.FetchOpenAd(AppOpenAdUnit, Me, "OpenAd")
End Sub
#Region Button Click Events
Private Sub Button1_Click
If iAd.Ready Then
iAd.Show
Else
Log("no Iad is available")
End If
iAd.LoadAd
End Sub
Private Sub Button2_Click
If Ads.isAvailableRewardedInterstitialAd Then
Ads.ShowRewardedInterstitialAd
Else
Log("wait... loading reward ad")
Ads.FetchRewardedInterstitialAd("ca-app-pub-3940256099942544/5354046379", Me, "RewardedInterstitialAd")
End If
End Sub
Private Sub Button_Native_Click
' B4XPages.ShowPage("B4XNative2")
StartActivity(NativeActivity)
End Sub
Private Sub Button_RewardedVideo_Click
If Ads.isAvailableRewardedVideoAd Then
Ads.ShowRewardedVideoAd
Else
Log("wait... loading reward ad")
Ads.FetchRewardedVideoAd("ca-app-pub-3940256099942544/5224354917", Me, "RewardAd")
End If
End Sub
#End Region
#Region Ad Events
Sub BannerAd_ReceiveAd
Log("BannerAd_ReceiveAd")
End Sub
Sub BannerAd_FailedToReceiveAd (ErrorCode As String)
Log("BannerAd_FailedToReceiveAd ErrorCode=" & ErrorCode)
End Sub
Sub BannerAd_AdClosed
Log("BannerAd_AdClosed")
End Sub
Sub BannerAd_AdOpened
Log("BannerAd_AdOpened")
End Sub
Sub BannerAdFixedSize_ReceiveAd
Log("BannerAdFixedSize_ReceiveAd")
End Sub
Sub BannerAdFixedSize_FailedToReceiveAd (ErrorCode As String)
Log("BannerAdFixedSize_FailedToReceiveAd ErrorCode=" & ErrorCode)
End Sub
Sub BannerAdFixedSize_AdClosed
Log("BannerAdFixedSize_AdClosed")
End Sub
Sub BannerAdFixedSize_AdOpened
Log("BannerAdFixedSize_AdOpened")
End Sub
Sub iAd_ReceiveAd
Log("IAd received. Now wait for the right moment to show the ad.")
End Sub
Sub iAd_FailedToReceiveAd (ErrorCode As String)
Log("Failed: " & ErrorCode)
End Sub
Sub iAd_AdClosed
Log("Closed")
End Sub
Sub iAd_AdOpened
Log("Opened")
End Sub
' Open Ad Events
Sub OpenAd_ReceiveAd
LogColor($"OpenAd_ReceiveAd"$, Colors.Green)
End Sub
Sub OpenAd_FailedToReceiveAd (ErrorCode As String)
LogColor($"OpenAd_FailedToReceiveAd ErrorCode=${ErrorCode}"$, Colors.Green)
End Sub
' Rewarded video ad events
Sub RewardAd_ReceiveAd
LogColor($"RewardAd_ReceiveAd"$, Colors.Green)
End Sub
Sub RewardAd_FailedToReceiveAd (ErrorCode As String)
LogColor($"RewardAd_FailedToReceiveAd ErrorCode=${ErrorCode}"$, Colors.Green)
End Sub
Sub RewardAd_Rewarded (Item As Object)
LogColor("RewardAd_Rewarded",Colors.Green)
Dim Reward As JavaObject = Item
Dim Amount As Int = Reward.RunMethod("getAmount", Null)
Dim RewardType As String = Reward.RunMethod("getType", Null)
Log("Rewarded: " & Amount & " -> " & RewardType)
End Sub
' Rewarded interstitial events
Sub RewardedInterstitialAd_ReceiveAd
LogColor($"RewardInterstitialAd_ReceiveAd"$, Colors.Green)
End Sub
Sub RewardedInterstitialAd_FailedToReceiveAd (ErrorCode As String)
LogColor($"RewardedInterstitialAd_FailedToReceiveAd ErrorCode=${ErrorCode}"$, Colors.Green)
End Sub
Sub RewardedInterstitialAd_Rewarded (Item As Object)
LogColor("RewardedInterstitialAd_Rewarded",Colors.Green)
Dim Reward As JavaObject = Item
Dim Amount As Int = Reward.RunMethod("getAmount", Null)
Dim RewardType As String = Reward.RunMethod("getType", Null)
Log("Rewarded: " & Amount & " -> " & RewardType)
End Sub
#End Region