interstitial.monkey2 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 interstitial 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( "interstitial","top",AdUnitId )
  23. _adView.Loading+=Lambda()
  24. Print "AdView Loading"
  25. End
  26. _adView.Ready+=Lambda()
  27. Print "AdView Ready"
  28. End
  29. _adView.Error+=Lambda( error:Int )
  30. Print "AdView Error: error="+error
  31. End
  32. 'Add some buttons to hide/show the ad.
  33. '
  34. Local tools:=New ToolBar
  35. tools.AddAction( "Show ad" ).Triggered=Lambda()
  36. If _adView.State=AdState.Ready
  37. _adView.Visible=True 'Actually shows interstitial. App will suspend until user closes it. If State<>AdState.Ready, has no effect.
  38. Endif
  39. End
  40. tools.AddAction( "Reload ad" ).Triggered=Lambda()
  41. If _adView.State=AdState.Error
  42. _adView.Reload() 'Tries to load another ad. If State<>AdState.Error, this has no effect.
  43. Endif
  44. End
  45. ContentView=tools
  46. End
  47. Method OnRender( canvas:Canvas ) Override
  48. RequestRender()
  49. ' Print "OnRender"
  50. Local state:="?????"
  51. Select _adView.State
  52. Case AdState.Initial 'ad is starting up
  53. state="Initial"
  54. Case AdState.Loading 'ad is loading
  55. state="Loading"
  56. Case AdState.Ready 'ad is ready to be made visible
  57. state="Ready"
  58. Case AdState.Error 'ad error.
  59. state="Error"
  60. End
  61. canvas.DrawText( state+"...",Width/2,Height/2,.5,.5 )
  62. End
  63. End
  64. Function Main()
  65. New AppInstance
  66. New MyWindow
  67. App.Run()
  68. End