@@ -22,214 +22,159 @@ namespace GoogleMobileAds.Android
2222{
2323 public class NextGenRewardedAdClient : AndroidJavaProxy , IRewardedAdClient
2424 {
25- private AndroidJavaObject _androidRewardedAd ;
26-
27- public NextGenRewardedAdClient ( ) : base ( NextGenUtils . UnityRewardedAdCallbackClassName )
28- {
29- AndroidJavaClass playerClass = new AndroidJavaClass ( Utils . UnityActivityClassName ) ;
30- AndroidJavaObject activity =
31- playerClass . GetStatic < AndroidJavaObject > ( "currentActivity" ) ;
32- _androidRewardedAd = new AndroidJavaObject (
33- NextGenUtils . UnityRewardedAdClassName , activity , this ) ;
34- }
25+ internal AndroidJavaObject androidRewardedAd ;
3526
36- #region IRewardedClient implementation
27+ public NextGenRewardedAdClient ( ) : base ( NextGenUtils . UnityRewardedAdCallbackClassName ) {
28+ AndroidJavaClass playerClass = new AndroidJavaClass ( Utils . UnityActivityClassName ) ;
29+ AndroidJavaObject activity = playerClass . GetStatic < AndroidJavaObject > ( "currentActivity" ) ;
30+ androidRewardedAd =
31+ new AndroidJavaObject ( NextGenUtils . UnityRewardedAdClassName , activity , this ) ;
32+ }
3733
38- public event EventHandler < EventArgs > OnAdLoaded ;
34+ #region IRewardedClient implementation
3935
40- public event EventHandler < LoadAdErrorClientEventArgs > OnAdFailedToLoad ;
36+ public event EventHandler < EventArgs > OnAdLoaded ;
4137
42- public event EventHandler < Reward > OnUserEarnedReward ;
38+ public event EventHandler < LoadAdErrorClientEventArgs > OnAdFailedToLoad ;
4339
44- public event Action < AdValue > OnPaidEvent ;
40+ public event EventHandler < Reward > OnUserEarnedReward ;
4541
46- public event EventHandler < AdErrorClientEventArgs > OnAdFailedToPresentFullScreenContent ;
42+ public event Action < AdValue > OnPaidEvent ;
4743
48- public event EventHandler < EventArgs > OnAdDidPresentFullScreenContent ;
44+ public event EventHandler < AdErrorClientEventArgs > OnAdFailedToPresentFullScreenContent ;
4945
50- public event EventHandler < EventArgs > OnAdDidDismissFullScreenContent ;
46+ public event EventHandler < EventArgs > OnAdDidPresentFullScreenContent ;
5147
52- public event EventHandler < EventArgs > OnAdDidRecordImpression ;
48+ public event EventHandler < EventArgs > OnAdDidDismissFullScreenContent ;
5349
54- public event Action OnAdClicked ;
50+ public event EventHandler < EventArgs > OnAdDidRecordImpression ;
5551
56- public void CreateRewardedAd ( )
57- {
58- // No op.
59- }
52+ public event Action OnAdClicked ;
6053
61- public void LoadAd ( string adUnitId , AdRequest request )
62- {
63- _androidRewardedAd . Call ( "load" , NextGenUtils . GetAdRequestJavaObject ( request , adUnitId ) ) ;
64- }
54+ public void CreateRewardedAd ( ) {
55+ // No op.
56+ }
6557
66- public void Show ( )
67- {
68- _androidRewardedAd . Call ( "show" ) ;
69- }
58+ public void LoadAd ( string adUnitId , AdRequest request ) {
59+ androidRewardedAd . Call ( "load" , NextGenUtils . GetAdRequestJavaObject ( request , adUnitId ) ) ;
60+ }
7061
71- public void SetServerSideVerificationOptions (
72- ServerSideVerificationOptions serverSideVerificationOptions )
73- {
74- // TODO(vkini): Implement SetServerSideVerificationOptions for NextGen SDK.
75- }
62+ public void Show ( ) {
63+ androidRewardedAd . Call ( "show" ) ;
64+ }
7665
77- public long PlacementId
78- {
79- get
80- {
81- return _androidRewardedAd . Call < long > ( "getPlacementId" ) ;
82- }
83- set
84- {
85- _androidRewardedAd . Call ( "setPlacementId" , value ) ;
86- }
87- }
66+ public void SetServerSideVerificationOptions (
67+ ServerSideVerificationOptions serverSideVerificationOptions ) {
68+ // TODO(vkini): Implement SetServerSideVerificationOptions for NextGen SDK.
69+ }
8870
89- // Returns the reward item for the loaded rewarded ad.
90- public Reward GetRewardItem ( )
91- {
92- AndroidJavaObject rewardItem =
93- _androidRewardedAd . Call < AndroidJavaObject > ( "getRewardItem" ) ;
94- if ( rewardItem == null )
95- {
96- return null ;
97- }
98- string type = rewardItem . Call < string > ( "getType" ) ;
99- int amount = rewardItem . Call < int > ( "getAmount" ) ;
100- return new Reward ( )
101- {
102- Type = type ,
103- Amount = ( double ) amount
104- } ;
105- }
71+ public long PlacementId {
72+ get { return androidRewardedAd . Call < long > ( "getPlacementId" ) ; }
73+ set { androidRewardedAd . Call ( "setPlacementId" , value ) ; }
74+ }
10675
107- // Returns the ad unit ID .
108- public string GetAdUnitID ( )
109- {
110- // TODO(vkini): Implement GetAdUnitID for NextGen.
111- return "" ;
76+ // Returns the reward item for the loaded rewarded ad .
77+ public Reward GetRewardItem ( ) {
78+ AndroidJavaObject rewardItem = androidRewardedAd . Call < AndroidJavaObject > ( "getRewardItem" ) ;
79+ if ( rewardItem == null ) {
80+ return null ;
11281 }
82+ string type = rewardItem . Call < string > ( "getType" ) ;
83+ int amount = rewardItem . Call < int > ( "getAmount" ) ;
84+ return new Reward ( ) { Type = type , Amount = ( double ) amount } ;
85+ }
11386
114- // Ad Preloading v1 will not be supported in NextGen .
115- public bool IsAdAvailable ( string adUnitId )
116- {
117- return false ;
118- }
87+ // Returns the ad unit ID .
88+ public string GetAdUnitID ( ) {
89+ // TODO(vkini): Implement GetAdUnitID for NextGen.
90+ return "" ;
91+ }
11992
120- public IRewardedAdClient PollAd ( string adUnitId )
121- {
122- return null ;
123- }
93+ // Ad Preloading v1 will not be supported in NextGen.
94+ public bool IsAdAvailable ( string adUnitId ) {
95+ return false ;
96+ }
12497
125- // Returns ad request response info
126- public IResponseInfoClient GetResponseInfoClient ( )
127- {
128- var responseInfoJavaObject = _androidRewardedAd . Call < AndroidJavaObject > (
129- "getResponseInfo" ) ;
130- return new NextGenResponseInfoClient ( responseInfoJavaObject ) ;
131- }
98+ public IRewardedAdClient PollAd ( string adUnitId ) {
99+ return null ;
100+ }
132101
133- // Destroy the rewarded ad.
134- public void DestroyRewardedAd ( )
135- {
136- // Currently we don't have to do anything on destroy.
137- }
102+ // Returns ad request response info
103+ public IResponseInfoClient GetResponseInfoClient ( ) {
104+ var responseInfoJavaObject = androidRewardedAd . Call < AndroidJavaObject > ( "getResponseInfo" ) ;
105+ return new NextGenResponseInfoClient ( responseInfoJavaObject ) ;
106+ }
138107
139- #endregion
108+ // Destroy the rewarded ad.
109+ public void DestroyRewardedAd ( ) {
110+ // Currently we don't have to do anything on destroy.
111+ }
140112
141- #region Callbacks from UnityRewardedAdCallback
142- void onRewardedAdLoaded ( )
143- {
144- if ( this . OnAdLoaded != null )
145- {
146- this . OnAdLoaded ( this , EventArgs . Empty ) ;
147- }
148- }
113+ #endregion
149114
150- void onRewardedAdFailedToLoad ( AndroidJavaObject error )
151- {
152- if ( this . OnAdFailedToLoad != null )
153- {
154- LoadAdErrorClientEventArgs args = new LoadAdErrorClientEventArgs ( )
155- {
156- LoadAdErrorClient = new NextGenLoadAdErrorClient ( error )
157- } ;
158- this . OnAdFailedToLoad ( this , args ) ;
159- }
115+ #region Callbacks from UnityRewardedAdCallback
116+ void onRewardedAdLoaded ( ) {
117+ if ( this . OnAdLoaded != null ) {
118+ this . OnAdLoaded ( this , EventArgs . Empty ) ;
160119 }
120+ }
161121
162- void onAdFailedToShowFullScreenContent ( AndroidJavaObject error )
163- {
164- if ( this . OnAdFailedToPresentFullScreenContent != null )
165- {
166- AdErrorClientEventArgs args = new AdErrorClientEventArgs ( )
167- {
168- AdErrorClient = new NextGenFullScreenContentErrorClient ( error )
169- } ;
170- this . OnAdFailedToPresentFullScreenContent ( this , args ) ;
171- }
122+ void onRewardedAdFailedToLoad ( AndroidJavaObject error ) {
123+ if ( this . OnAdFailedToLoad != null ) {
124+ LoadAdErrorClientEventArgs args =
125+ new LoadAdErrorClientEventArgs ( ) { LoadAdErrorClient =
126+ new NextGenLoadAdErrorClient ( error ) } ;
127+ this . OnAdFailedToLoad ( this , args ) ;
172128 }
129+ }
173130
174- void onAdShowedFullScreenContent ( )
175- {
176- if ( this . OnAdDidPresentFullScreenContent != null )
177- {
178- this . OnAdDidPresentFullScreenContent ( this , EventArgs . Empty ) ;
179- }
131+ void onAdFailedToShowFullScreenContent ( AndroidJavaObject error ) {
132+ if ( this . OnAdFailedToPresentFullScreenContent != null ) {
133+ AdErrorClientEventArgs args =
134+ new AdErrorClientEventArgs ( ) { AdErrorClient =
135+ new NextGenFullScreenContentErrorClient ( error ) } ;
136+ this . OnAdFailedToPresentFullScreenContent ( this , args ) ;
180137 }
138+ }
181139
140+ void onAdShowedFullScreenContent ( ) {
141+ if ( this . OnAdDidPresentFullScreenContent != null ) {
142+ this . OnAdDidPresentFullScreenContent ( this , EventArgs . Empty ) ;
143+ }
144+ }
182145
183- void onAdDismissedFullScreenContent ( )
184- {
185- if ( this . OnAdDidDismissFullScreenContent != null )
186- {
187- this . OnAdDidDismissFullScreenContent ( this , EventArgs . Empty ) ;
188- }
146+ void onAdDismissedFullScreenContent ( ) {
147+ if ( this . OnAdDidDismissFullScreenContent != null ) {
148+ this . OnAdDidDismissFullScreenContent ( this , EventArgs . Empty ) ;
189149 }
150+ }
190151
191- void onAdImpression ( )
192- {
193- if ( this . OnAdDidRecordImpression != null )
194- {
195- this . OnAdDidRecordImpression ( this , EventArgs . Empty ) ;
196- }
152+ void onAdImpression ( ) {
153+ if ( this . OnAdDidRecordImpression != null ) {
154+ this . OnAdDidRecordImpression ( this , EventArgs . Empty ) ;
197155 }
156+ }
198157
199- void onAdClicked ( )
200- {
201- if ( this . OnAdClicked != null )
202- {
203- this . OnAdClicked ( ) ;
204- }
158+ void onAdClicked ( ) {
159+ if ( this . OnAdClicked != null ) {
160+ this . OnAdClicked ( ) ;
205161 }
162+ }
206163
207- void onUserEarnedReward ( string type , float amount )
208- {
209- if ( this . OnUserEarnedReward != null )
210- {
211- Reward args = new Reward ( )
212- {
213- Type = type ,
214- Amount = amount
215- } ;
216- this . OnUserEarnedReward ( this , args ) ;
217- }
164+ void onUserEarnedReward ( string type , float amount ) {
165+ if ( this . OnUserEarnedReward != null ) {
166+ Reward args = new Reward ( ) { Type = type , Amount = amount } ;
167+ this . OnUserEarnedReward ( this , args ) ;
218168 }
169+ }
219170
220- public void onPaidEvent ( int precision , long valueInMicros , string currencyCode )
221- {
222- if ( this . OnPaidEvent != null )
223- {
224- AdValue adValue = new AdValue ( )
225- {
226- Precision = ( AdValue . PrecisionType ) precision ,
227- Value = valueInMicros ,
228- CurrencyCode = currencyCode
229- } ;
230- this . OnPaidEvent ( adValue ) ;
231- }
171+ public void onPaidEvent ( int precision , long valueInMicros , string currencyCode ) {
172+ if ( this . OnPaidEvent != null ) {
173+ AdValue adValue = new AdValue ( ) { Precision = ( AdValue . PrecisionType ) precision ,
174+ Value = valueInMicros , CurrencyCode = currencyCode } ;
175+ this . OnPaidEvent ( adValue ) ;
232176 }
177+ }
233178
234179 #endregion
235180 }
0 commit comments