@@ -23,13 +23,55 @@ namespace GoogleMobileAds.Api.AdManager
2323 /// Banner view that works with Google Ad Manager. Banner views occupy a spot within an app's
2424 /// layout. They stay on screen while users are interacting with the app.
2525 /// </summary>
26- public class AdManagerBannerView : BannerView
26+ public class AdManagerBannerView
2727 {
28+ /// <summary>
29+ /// Raised when an ad is loaded into the banner view.
30+ /// </summary>
31+ public event Action OnBannerAdLoaded ;
32+
33+ /// <summary>
34+ /// Raised when an ad fails to load into the banner view.
35+ /// </summary>
36+ public event Action < LoadAdError > OnBannerAdLoadFailed ;
37+
38+ /// <summary>
39+ /// Raised when the ad is estimated to have earned money.
40+ /// </summary>
41+ public event Action < AdValue > OnAdPaid ;
42+
43+ /// <summary>
44+ /// Raised when an ad is clicked.
45+ /// </summary>
46+ public event Action OnAdClicked ;
47+
48+ /// <summary>
49+ /// Raised when an impression is recorded for an ad.
50+ /// </summary>
51+ public event Action OnAdImpressionRecorded ;
52+
53+ /// <summary>
54+ /// Raised when an ad opened full-screen content.
55+ /// </summary>
56+ public event Action OnAdFullScreenContentOpened ;
57+
58+ /// <summary>
59+ /// Raised when the ad closed full-screen content.
60+ /// On iOS, this event is only raised when an ad opens an overlay, not when opening a new
61+ /// application such as Safari or the App Store.
62+ /// </summary>
63+ public event Action OnAdFullScreenContentClosed ;
64+
2865 /// <summary>
2966 /// Raised when the app receives an event from the banner ad.
3067 /// </summary>
3168 public event Action < AppEvent > OnAppEventReceived ;
3269
70+ /// <summary>
71+ /// Returns true if Destroy() has been called.
72+ /// </summary>
73+ public bool IsDestroyed { get { return _client == null ; } }
74+
3375 /// <summary>
3476 /// Sets the supported sizes of the banner ad. In most cases, only one ad size will be
3577 /// specified. Use one of the predefined standard ad sizes (such as AdSize.MediumRectangle),
@@ -50,10 +92,12 @@ public class AdManagerBannerView : BannerView
5092 /// </summary>
5193 public List < AdSize > ValidAdSizes
5294 {
53- get { return ( ( IAdManagerBannerClient ) _client ) . ValidAdSizes ; }
54- set { ( ( IAdManagerBannerClient ) _client ) . ValidAdSizes = value ; }
95+ get { return _client . ValidAdSizes ; }
96+ set { _client . ValidAdSizes = value ; }
5597 }
5698
99+ internal IAdManagerBannerClient _client ;
100+
57101 /// <summary>
58102 /// Creates an Ad Manager banner view with a standard position.
59103 /// </summary>
@@ -74,11 +118,195 @@ public AdManagerBannerView(string adUnitId, AdSize adSize, int x, int y)
74118 ConfigureBannerEvents ( ) ;
75119 }
76120
77- protected internal override void ConfigureBannerEvents ( )
121+ /// <summary>
122+ /// Destroys the banner view.
123+ /// </summary>
124+ public void Destroy ( )
125+ {
126+ if ( _client != null )
127+ {
128+ _client . DestroyBannerView ( ) ;
129+ _client = null ;
130+ }
131+ }
132+
133+ /// <summary>
134+ /// Returns the ad unit ID.
135+ /// </summary>
136+ public string GetAdUnitID ( )
137+ {
138+ return _client != null ? _client . GetAdUnitID ( ) : null ;
139+ }
140+
141+ /// <summary>
142+ /// Returns the ad request response info or null if the ad is not loaded.
143+ /// </summary>
144+ public ResponseInfo GetResponseInfo ( )
145+ {
146+ return _client != null ? new ResponseInfo ( _client . GetResponseInfoClient ( ) ) : null ;
147+ }
148+
149+ /// <summary>
150+ /// Returns the height of the banner view in pixels.
151+ /// </summary>
152+ public float GetHeightInPixels ( )
153+ {
154+ return _client != null ? _client . GetHeightInPixels ( ) : 0 ;
155+ }
156+
157+ /// <summary>
158+ /// Returns the width of the banner view in pixels.
159+ /// </summary>
160+ public float GetWidthInPixels ( )
161+ {
162+ return _client != null ? _client . GetWidthInPixels ( ) : 0 ;
163+ }
164+
165+ /// <summary>
166+ /// Loads an ad into the banner view.
167+ /// </summary>
168+ public void LoadAd ( AdRequest request )
169+ {
170+ if ( _client != null )
171+ {
172+ _client . LoadAd ( request ) ;
173+ }
174+ }
175+
176+ /// <summary>
177+ /// Shows the banner view.
178+ /// </summary>
179+ public void Show ( )
180+ {
181+ if ( _client != null )
182+ {
183+ _client . ShowBannerView ( ) ;
184+ }
185+ }
186+
187+ /// <summary>
188+ /// Hides the banner view.
189+ /// </summary>
190+ public void Hide ( )
191+ {
192+ if ( _client != null )
193+ {
194+ _client . HideBannerView ( ) ;
195+ }
196+ }
197+
198+ /// <summary>
199+ /// Sets the position of the banner view using standard position.
200+ /// </summary>
201+ public void SetPosition ( AdPosition adPosition )
78202 {
79- base . ConfigureBannerEvents ( ) ;
203+ if ( _client != null )
204+ {
205+ _client . SetPosition ( adPosition ) ;
206+ }
207+ }
208+
209+ /// <summary>
210+ /// Sets the position of the banner view using custom position.
211+ /// </summary>
212+ public void SetPosition ( int x , int y )
213+ {
214+ if ( _client != null )
215+ {
216+ _client . SetPosition ( x , y ) ;
217+ }
218+ }
219+
220+ /// <summary>
221+ /// Indicates whether the last loaded ad is a collapsible banner.
222+ /// </summary>
223+ public bool IsCollapsible ( )
224+ {
225+ return _client == null ? false : _client . IsCollapsible ( ) ;
226+ }
227+
228+ private void ConfigureBannerEvents ( )
229+ {
230+
231+ _client . OnAdLoaded += ( sender , args ) =>
232+ {
233+ MobileAds . RaiseAction ( ( ) =>
234+ {
235+ if ( OnBannerAdLoaded != null )
236+ {
237+ OnBannerAdLoaded ( ) ;
238+ }
239+ } ) ;
240+ } ;
241+
242+ _client . OnAdFailedToLoad += ( sender , args ) =>
243+ {
244+ LoadAdError loadAdError = new LoadAdError ( args . LoadAdErrorClient ) ;
245+ MobileAds . RaiseAction ( ( ) =>
246+ {
247+ if ( OnBannerAdLoadFailed != null )
248+ {
249+ OnBannerAdLoadFailed ( loadAdError ) ;
250+ }
251+ } ) ;
252+ } ;
253+
254+ _client . OnAdOpening += ( sender , args ) =>
255+ {
256+ MobileAds . RaiseAction ( ( ) =>
257+ {
258+ if ( OnAdFullScreenContentOpened != null )
259+ {
260+ OnAdFullScreenContentOpened ( ) ;
261+ }
262+ } ) ;
263+ } ;
264+
265+ _client . OnAdClosed += ( sender , args ) =>
266+ {
267+ MobileAds . RaiseAction ( ( ) =>
268+ {
269+ if ( OnAdFullScreenContentClosed != null )
270+ {
271+ OnAdFullScreenContentClosed ( ) ;
272+ }
273+ } ) ;
274+ } ;
275+
276+ _client . OnPaidEvent += ( adValue ) =>
277+ {
278+ MobileAds . RaiseAction ( ( ) =>
279+ {
280+ if ( OnAdPaid != null )
281+ {
282+ OnAdPaid ( adValue ) ;
283+ }
284+ } ) ;
285+ } ;
286+
287+ _client . OnAdClicked += ( ) =>
288+ {
289+ MobileAds . RaiseAction ( ( ) =>
290+ {
291+ if ( OnAdClicked != null )
292+ {
293+ OnAdClicked ( ) ;
294+ }
295+ } ) ;
296+ } ;
297+
298+ _client . OnAdImpressionRecorded += ( ) =>
299+ {
300+ MobileAds . RaiseAction ( ( ) =>
301+ {
302+ if ( OnAdImpressionRecorded != null )
303+ {
304+ OnAdImpressionRecorded ( ) ;
305+ }
306+ } ) ;
307+ } ;
80308
81- ( ( IAdManagerBannerClient ) _client ) . OnAppEvent += ( appEvent ) =>
309+ _client . OnAppEvent += ( appEvent ) =>
82310 {
83311 MobileAds . RaiseAction ( ( ) =>
84312 {
0 commit comments