admob native - help with lib

Monkey Forums/Monkey Programming/admob native - help with lib

Lugato(Posted 2013) [#1]
Hi for all,

I'm using the monkey v70e with native admob, I create a lib to abstract lib to make some compatibility with other plataforms (html, flash, etc).. But the banner don't appear.. Anyoune can give a little help to find the problem ???

Thanks for the Mark .. the code are fixed now ;)

here's the codes:

LIB libBanner.monkey
Import mojo

#If TARGET="android" Or TARGET="ios"
	Import brl.admob
#End

Class Banner
	#If TARGET="android" Or TARGET="ios"
		Field admob:Admob
	#End
	Field bannerCalled:Bool = False
	Field bannerSize:Int
	Field bannerLayout:Int

	Method New (bannerSize:Int=1 , bannerLayout:Int=2)
		Self.bannerSize		= bannerSize
		Self.bannerLayout	= bannerLayout

		#If TARGET="android" Or TARGET="ios"
			Self.admob = Admob.GetAdmob()
			Self.admob.ShowAdView Self.bannerSize, Self.bannerLayout
		#End
		
		Self.bannerCalled = True
	End    

	Method SetType(bannerSize:Int=1 , bannerLayout:Int=2)
		Self.bannerSize		= bannerSize
		Self.bannerLayout	= bannerLayout
'		Print (Self.bannerSize +"|"+ Self.bannerLayout)

	End

	Method Show()
		If Not Self.bannerCalled Then 
			#If TARGET="android" Or TARGET="ios"
				Self.admob.ShowAdView Self.bannerSize, Self.bannerLayout
			#End
'			Print (Self.bannerSize +"|"+ Self.bannerLayout)
			Self.bannerCalled = True
		End
	End

	Method Disable()
		#If TARGET="android" Or TARGET="ios"
			Self.admob.HideAdView()
		#End
		Self.bannerCalled = False
	End
End



Example how to use:
banner.monkey
#ADMOB_PUBLISHER_ID="abcdabcdabcdabc"                           'from your admod account
#ADMOB_ANDROID_TEST_DEVICE1="TEST_EMULATOR"
#ADMOB_ANDROID_TEST_DEVICE2="ABCDABCDABCDABCDABCDABCDABCDABCD"  'your device's admob ID for test mode
Import mojo
Import libBanner

Class MyApp Extends App

	Const BANNER_TOP_CENTER		= 2
	Const BANNER_TOP_LEFT		= 1
	Const BANNER_TOP_RIGHT		= 3
	
	Const BANNER_BOTTON_CENTER	= 5 
	Const BANNER_BOTTON_LEFT	= 4
	Const BANNER_BOTTON_RIGHT	= 6
	
	Const BANNER_SIZE_320X50	= 1

    Global banner:Banner = New Banner 

	Field enabled:Bool = True
    
    Method OnCreate()
		banner = New Banner()
        SetUpdateRate 60
    End
    
    Method OnUpdate()
        If MouseHit( 0 )
            If Self.enabled
                banner.Disable()
                Self.enabled=False
            Else
				banner.Show()
        		Self.enabled=True
            Endif
        End
    End
    
    Method OnRender()
        Cls
        DrawText "Click to toggle ads!",DeviceWidth/2,DeviceHeight/2,.5,.5
    End
    
End

Function Main()
    New MyApp
End



marksibly(Posted 2013) [#2]
> #If TARGET="android" And TARGET="ios"

Try 'Or' instead of 'And'...


Lugato(Posted 2013) [#3]
Hi Mark,

Some times you need verify what are you coping and pasting hahahah

After the fixes the banner worked perfectly in the app ;)

Thanks for the help ;)


Nobuyuki(Posted 2013) [#4]
I've made some changes to your lib thingy to suit my needs. The consts now live in the class, some typos have been corrected, and Disable() was changed to Hide() to provide more consistency with the underlying classes. In addition, there is a DebugRender() method to show what the ad banner might look like, which can be called on any platform, and respects the enabled state of the ad.