banner.monkey2 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. Namespace myapp
  2. #Import "<std>"
  3. #Import "<mojo>"
  4. #Import "<mojox>"
  5. #Import "<admob>"
  6. Using std..
  7. Using mojo..
  8. Using mojox..
  9. Using admob..
  10. 'Replace this with your AdMobID for banner ads, eg: "ca-app-pub-XXXXXXXXXXXXXXXX/YYYYYYYYYY"
  11. '
  12. Const AdUnitId:=""
  13. Class MyWindow Extends Window
  14. Field _adView:AdView
  15. Method New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=Null )
  16. Super.New( title,width,height,flags )
  17. 'Scale up GUI a bit on mobile!
  18. '
  19. App.Theme.Scale=New Vec2f( 3,3 )
  20. 'Create AdView instance
  21. '
  22. _adView=New AdView( "banner","bottom",AdUnitId )
  23. _adView.Loading+=Lambda()
  24. Print "AdView Loading"
  25. End
  26. _adView.Ready+=Lambda()
  27. Print "AdView Ready"
  28. End
  29. 'Add some buttons to hide/show the ad.
  30. '
  31. Local tools:=New ToolBar
  32. tools.AddAction( "Show Ad" ).Triggered=Lambda()
  33. _adView.Visible=True
  34. End
  35. tools.AddAction( "Hide Ad" ).Triggered=Lambda()
  36. _adView.Visible=False
  37. End
  38. tools.AddAction( "Reload Ad" ).Triggered=Lambda()
  39. If _adView.State=AdState.Error
  40. _adView.Reload() 'Tries to load another ad. If State<>AdState.Error, this has no effect.
  41. Endif
  42. End
  43. ContentView=tools
  44. End
  45. Method OnRender( canvas:Canvas ) Override
  46. RequestRender()
  47. Local state:="?????"
  48. Select _adView.State
  49. Case AdState.Initial 'ad is starting up
  50. state="Initial"
  51. Case AdState.Loading 'ad is loading
  52. state="Loading"
  53. Case AdState.Ready 'ad is ready to be made visible
  54. state="Ready"
  55. Case AdState.Error 'ad error.
  56. state="Error"
  57. End
  58. canvas.DrawText( state+"...",Width/2,Height/2,.5,.5 )
  59. End
  60. End
  61. Function Main()
  62. New AppInstance
  63. New MyWindow
  64. App.Run()
  65. End