Android Question Swapping out views

Spright

Active Member
I have ads inside panel that I wish to swap out for some picture when its offline. If possible an image that links go a webpage when clicked.

Shuld i create two views (each with their aligend panel) and swap them out or should i modify the content of hte panel? (admob).
Any ideas how to achive a routine that swaps out or turns/on off different views?

B4X:
#MultiDex: True

#Region Project Attributes
    #FullScreen: True
    #IncludeTitle: False
    #ApplicationLabel: Demo
    #VersionCode: 1
    #VersionName:
    #SupportedOrientations: sensorLandscape
    #CanInstallToExternalStorage: False
#End Region

#Region Activity Attributes
#End Region

Sub Process_Globals
End Sub

Sub Globals
    Type AdSize (Native As Object, Width As Int, Height As Int)
    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 AdView1 As AdView
    Dim tm As Timer
    Dim Camera As lgOrthographicCamera
 End Sub

Sub Activity_Create(FirstTime As Boolean)
    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
    

    ' 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 GetAdaptiveAdSize As AdSize
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    Dim AdSize As JavaObject
    Dim width As Int = 100%x / GetDeviceLayoutValues.Scale
    ' width = Min(width,2560) ' Ad should be in panel
    Dim res As AdSize
    res.Native = AdSize.InitializeStatic("com.google.android.gms.ads.AdSize").RunMethod("getCurrentOrientationAnchoredAdaptiveBannerAdSize", Array(ctxt, width))
    Dim jo As JavaObject = res.Native
    res.Width = jo.RunMethod("getWidthInPixels", Array(ctxt))
    res.Height = jo.RunMethod("getHeightInPixels", Array(ctxt))
    Return res
End Sub
 
Sub Activity_Resume
    Starter.RewardAd.Callback = Me
    If AdView1.IsInitialized Then AdView1.resume
    If lGdx.IsInitialized Then lGdx.Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    If AdView1.IsInitialized Then AdView1.pause
    If lGdx.IsInitialized Then lGdx.Pause
End Sub

Sub Activity_Destroy
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

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 RewardAd_Rewarded (Item As Object)
    Log("GOT REWARD! NOW YOU HAVE COLLECTED THIS MANY COINS:")
End Sub

Sub RewardAd_AdClosed
    Log("ad closed")
End Sub

Sub timer_Tick
    If adwanted = True Then
        If Starter.RewardAd.Ready Then
            Starter.RewardAd.Show
            adwanted = False
            adwanted = True
        Else
            ' No ad is available, handle the error
            HandleAdLoadError
        End If
    End If
    Log("TIMER!")
End Sub

Sub HandleAdLoadError
    ToastMessageShow("Failed to load rewarded ad. Please check your internet connection.", True)
    ' Additional actions here e.g. disabling ad-related functionality or providing alternative content
End Sub
 
Top