forked from xamarin/GoogleApisForiOSComponents
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Extensions.cs
313 lines (256 loc) · 9.7 KB
/
Extensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
using System;
using System.Runtime.InteropServices;
using ObjCRuntime;
using Foundation;
using CoreGraphics;
using UIKit;
namespace Google.MobileAds
{
public partial class AdLoader : NSObject
{
public AdLoader (string adUnitId, UIViewController rootViewController, AdLoaderAdType [] adTypes, AdLoaderOptions [] options) : this (adUnitId, rootViewController, CastAdTypes (adTypes), options)
{
}
static NSString [] CastAdTypes (AdLoaderAdType [] adTypes)
{
if (adTypes == null)
return null;
var adLoaderAdTypes = new NSString [adTypes.Length];
for (int i = 0; i < adTypes.Length; i++)
adLoaderAdTypes [i] = adTypes [i].GetConstant ();
return adLoaderAdTypes;
}
}
public partial class NativeCustomTemplateAd
{
public static string MediaViewKey { get; } = _MediaViewKey.ToString ();
}
public partial class Request
{
public static readonly string GADGoogleAdMobNetworkName = "GoogleAdMobAds";
}
public partial class RequestError : NSError
{
public RequestError (NSString appDomain, nint code) : this (appDomain, code, null)
{
}
}
[Preserve (AllMembers = true)]
public partial class AdSizeCons
{
// Deprecated Macros
[Obsolete ("Use GADAdSizeCons.Banner Instead")]
public static readonly CGSize GAD_SIZE_320x50 = AdSizeCons.Banner.Size;
[Obsolete ("Use GADAdSizeCons.MediumRectangle Instead")]
public static readonly CGSize GAD_SIZE_300x250 = AdSizeCons.MediumRectangle.Size;
[Obsolete ("Use ADAdSizeCons.FullBanner Instead")]
public static readonly CGSize GAD_SIZE_468x60 = AdSizeCons.FullBanner.Size;
[Obsolete ("Use AdSizeCons.Leaderboard Instead")]
public static readonly CGSize GAD_SIZE_728x90 = AdSizeCons.Leaderboard.Size;
[Obsolete ("Use ADAdSizeCons.Skyscraper Instead")]
public static readonly CGSize GAD_SIZE_120x600 = AdSizeCons.Skyscraper.Size;
//GAD_EXTERN GADAdSize GADPortraitAnchoredAdaptiveBannerAdSizeWithWidth (CGFloat width);
[DllImport ("__Internal", EntryPoint = "GADPortraitAnchoredAdaptiveBannerAdSizeWithWidth")]
public static extern AdSize GetPortraitAnchoredAdaptiveBannerAdSize (CGSize size);
//GAD_EXTERN GADAdSize GADLandscapeAnchoredAdaptiveBannerAdSizeWithWidth (CGFloat width);
[DllImport ("__Internal", EntryPoint = "GADLandscapeAnchoredAdaptiveBannerAdSizeWithWidth")]
public static extern AdSize GetLandscapeAnchoredAdaptiveBannerAdSize (CGSize size);
//GAD_EXTERN GADAdSize GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth (CGFloat width);
[DllImport ("__Internal", EntryPoint = "GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth")]
public static extern AdSize GetCurrentOrientationAnchoredAdaptiveBannerAdSize (CGSize size);
// GADAdSize GADAdSizeFromCGSize(CGSize size);
[DllImport ("__Internal", EntryPoint = "GADAdSizeFromCGSize")]
public static extern AdSize GetFromCGSize (CGSize size);
// GADAdSize GADAdSizeFullWidthPortraitWithHeight(CGFloat height);
[DllImport ("__Internal", EntryPoint = "GADAdSizeFullWidthPortraitWithHeight")]
public static extern AdSize GetFullWidthPortrait (nfloat height);
// GADAdSize GADAdSizeFullWidthLandscapeWithHeight (CGFloat height);
[DllImport ("__Internal", EntryPoint = "GADAdSizeFullWidthLandscapeWithHeight")]
public static extern AdSize GetFullWidthLandscape (nfloat height);
// BOOL GADAdSizeEqualToSize(GADAdSize size1, GADAdSize size2);
[DllImport ("__Internal", EntryPoint = "GADAdSizeEqualToSize")]
public static extern bool Equals (AdSize size, AdSize toSize);
// CGSize CGSizeFromGADAdSize(GADAdSize size);
[DllImport ("__Internal", EntryPoint = "CGSizeFromGADAdSize")]
public static extern CGSize GetCGSize (AdSize size);
// BOOL IsGADAdSizeValid(GADAdSize size);
[DllImport ("__Internal", EntryPoint = "IsGADAdSizeValid")]
public static extern bool IsAdSizeValid (AdSize size);
// GAD_EXTERN BOOL GADAdSizeIsFluid(GADAdSize size);
[DllImport ("__Internal", EntryPoint = "GADAdSizeIsFluid")]
public static extern bool AdSizeIsFluid (AdSize size);
// NSString *NSStringFromGADAdSize(GADAdSize size);
[DllImport ("__Internal", EntryPoint = "NSStringFromGADAdSize")]
static extern IntPtr _GetNSString (AdSize size);
// NSValue *NSValueFromGADAdSize(GADAdSize size);
[DllImport ("__Internal", EntryPoint = "NSValueFromGADAdSize")]
static extern IntPtr _GetNSValue (AdSize size);
// GADAdSize GADAdSizeFromNSValue(NSValue *value);
[DllImport ("__Internal", EntryPoint = "GADAdSizeFromNSValue")]
public static extern AdSize _GetFromNSValue (IntPtr value);
public static NSString GetNSString (AdSize size)
{
return Runtime.GetNSObject<NSString> (_GetNSString (size));
}
public static NSValue GetNSValue (AdSize size)
{
return Runtime.GetNSObject<NSValue> (_GetNSValue (size));
}
public static AdSize GetFromNSValue (NSValue value)
{
return _GetFromNSValue (value.Handle);
}
static AdSize? banner;
public static AdSize Banner {
get {
if (banner == null) {
IntPtr RTLD_MAIN_ONLY = Dlfcn.dlopen (null, 0);
IntPtr ptr = Dlfcn.dlsym (RTLD_MAIN_ONLY, "kGADAdSizeBanner");
banner = (AdSize)Marshal.PtrToStructure (ptr, typeof (AdSize));
Dlfcn.dlclose (RTLD_MAIN_ONLY);
}
return banner.Value;
}
}
static AdSize? largeBanner;
public static AdSize LargeBanner {
get {
if (largeBanner == null) {
IntPtr RTLD_MAIN_ONLY = Dlfcn.dlopen (null, 0);
IntPtr ptr = Dlfcn.dlsym (RTLD_MAIN_ONLY, "kGADAdSizeLargeBanner");
largeBanner = (AdSize)Marshal.PtrToStructure (ptr, typeof (AdSize));
Dlfcn.dlclose (RTLD_MAIN_ONLY);
}
return largeBanner.Value;
}
}
static AdSize? mediumRectangle;
public static AdSize MediumRectangle {
get {
if (mediumRectangle == null) {
IntPtr RTLD_MAIN_ONLY = Dlfcn.dlopen (null, 0);
IntPtr ptr = Dlfcn.dlsym (RTLD_MAIN_ONLY, "kGADAdSizeMediumRectangle");
mediumRectangle = (AdSize)Marshal.PtrToStructure (ptr, typeof (AdSize));
Dlfcn.dlclose (RTLD_MAIN_ONLY);
}
return mediumRectangle.Value;
}
}
static AdSize? fullBanner;
public static AdSize FullBanner {
get {
if (fullBanner == null) {
IntPtr RTLD_MAIN_ONLY = Dlfcn.dlopen (null, 0);
IntPtr ptr = Dlfcn.dlsym (RTLD_MAIN_ONLY, "kGADAdSizeFullBanner");
fullBanner = (AdSize)Marshal.PtrToStructure (ptr, typeof (AdSize));
Dlfcn.dlclose (RTLD_MAIN_ONLY);
}
return fullBanner.Value;
}
}
static AdSize? leaderboard;
public static AdSize Leaderboard {
get {
if (leaderboard == null) {
IntPtr RTLD_MAIN_ONLY = Dlfcn.dlopen (null, 0);
IntPtr ptr = Dlfcn.dlsym (RTLD_MAIN_ONLY, "kGADAdSizeLeaderboard");
leaderboard = (AdSize)Marshal.PtrToStructure (ptr, typeof (AdSize));
Dlfcn.dlclose (RTLD_MAIN_ONLY);
}
return leaderboard.Value;
}
}
static AdSize? skyscraper;
public static AdSize Skyscraper {
get {
if (skyscraper == null) {
IntPtr RTLD_MAIN_ONLY = Dlfcn.dlopen (null, 0);
IntPtr ptr = Dlfcn.dlsym (RTLD_MAIN_ONLY, "kGADAdSizeSkyscraper");
skyscraper = (AdSize)Marshal.PtrToStructure (ptr, typeof (AdSize));
Dlfcn.dlclose (RTLD_MAIN_ONLY);
}
return skyscraper.Value;
}
}
static AdSize? smartBannerPortrait;
public static AdSize SmartBannerPortrait {
get {
if (smartBannerPortrait == null) {
IntPtr RTLD_MAIN_ONLY = Dlfcn.dlopen (null, 0);
IntPtr ptr = Dlfcn.dlsym (RTLD_MAIN_ONLY, "kGADAdSizeSmartBannerPortrait");
smartBannerPortrait = (AdSize)Marshal.PtrToStructure (ptr, typeof (AdSize));
Dlfcn.dlclose (RTLD_MAIN_ONLY);
}
return smartBannerPortrait.Value;
}
}
static AdSize? smartBannerLandscape;
public static AdSize SmartBannerLandscape {
get {
if (smartBannerLandscape == null) {
IntPtr RTLD_MAIN_ONLY = Dlfcn.dlopen (null, 0);
IntPtr ptr = Dlfcn.dlsym (RTLD_MAIN_ONLY, "kGADAdSizeSmartBannerLandscape");
smartBannerLandscape = (AdSize)Marshal.PtrToStructure (ptr, typeof (AdSize));
Dlfcn.dlclose (RTLD_MAIN_ONLY);
}
return smartBannerLandscape.Value;
}
}
static AdSize? fluid;
public static AdSize Fluid {
get {
if (fluid == null) {
IntPtr RTLD_MAIN_ONLY = Dlfcn.dlopen (null, 0);
IntPtr ptr = Dlfcn.dlsym (RTLD_MAIN_ONLY, "kGADAdSizeFluid");
fluid = (AdSize)Marshal.PtrToStructure (ptr, typeof (AdSize));
Dlfcn.dlclose (RTLD_MAIN_ONLY);
}
return fluid.Value;
}
}
static AdSize? invalid;
public static AdSize Invalid {
get {
if (invalid == null) {
IntPtr RTLD_MAIN_ONLY = Dlfcn.dlopen (null, 0);
IntPtr ptr = Dlfcn.dlsym (RTLD_MAIN_ONLY, "kGADAdSizeInvalid");
invalid = (AdSize)Marshal.PtrToStructure (ptr, typeof (AdSize));
Dlfcn.dlclose (RTLD_MAIN_ONLY);
}
return invalid.Value;
}
}
public static string GetString (AdSize size)
{
return GetNSString (size);
}
}
public partial class RewardBasedVideoAd
{
[Obsolete ("Use IsReady property instead, this will be removed in future versions")]
public bool Ready { get { return IsReady; } }
}
}
namespace Google.MobileAds.DoubleClick
{
public partial class BannerView : Google.MobileAds.BannerView
{
[Obsolete ("Use ValidAdSizes property.")]
public void SetValidAdSizes (params AdSize [] sizes)
{
if (sizes == null)
throw new ArgumentNullException ("sizes");
var pNativeArr = Marshal.AllocHGlobal (sizes.Length * IntPtr.Size);
for (int i = 1; i < sizes.Length; ++i) {
IntPtr sizePtr = Marshal.AllocHGlobal (Marshal.SizeOf (sizes [i]));
Marshal.StructureToPtr (sizes [i], sizePtr, false);
Marshal.WriteIntPtr (pNativeArr, (i - 1) * IntPtr.Size, sizePtr);
Marshal.FreeHGlobal (sizePtr);
}
// null termination
Marshal.WriteIntPtr (pNativeArr, (sizes.Length - 1) * IntPtr.Size, IntPtr.Zero);
SetValidAdSizes (sizes [0], pNativeArr);
Marshal.FreeHGlobal (pNativeArr);
}
}
}