Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

159 rindas
4.7 KiB

  1. // Copyright (C) 2015 Google, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. using System;
  15. using System.Reflection;
  16. using GoogleMobileAds.Common;
  17. namespace GoogleMobileAds.Api
  18. {
  19. public class RewardBasedVideoAd
  20. {
  21. private IRewardBasedVideoAdClient client;
  22. private static readonly RewardBasedVideoAd instance = new RewardBasedVideoAd();
  23. public static RewardBasedVideoAd Instance
  24. {
  25. get
  26. {
  27. return instance;
  28. }
  29. }
  30. // Creates a Singleton RewardBasedVideoAd.
  31. private RewardBasedVideoAd()
  32. {
  33. Type googleMobileAdsClientFactory = Type.GetType(
  34. "GoogleMobileAds.GoogleMobileAdsClientFactory,Assembly-CSharp");
  35. MethodInfo method = googleMobileAdsClientFactory.GetMethod(
  36. "BuildRewardBasedVideoAdClient",
  37. BindingFlags.Static | BindingFlags.Public);
  38. this.client = (IRewardBasedVideoAdClient)method.Invoke(null, null);
  39. client.CreateRewardBasedVideoAd();
  40. this.client.OnAdLoaded += (sender, args) =>
  41. {
  42. if (this.OnAdLoaded != null)
  43. {
  44. this.OnAdLoaded(this, args);
  45. }
  46. };
  47. this.client.OnAdFailedToLoad += (sender, args) =>
  48. {
  49. if (this.OnAdFailedToLoad != null)
  50. {
  51. this.OnAdFailedToLoad(this, args);
  52. }
  53. };
  54. this.client.OnAdOpening += (sender, args) =>
  55. {
  56. if (this.OnAdOpening != null)
  57. {
  58. this.OnAdOpening(this, args);
  59. }
  60. };
  61. this.client.OnAdStarted += (sender, args) =>
  62. {
  63. if (this.OnAdStarted != null)
  64. {
  65. this.OnAdStarted(this, args);
  66. }
  67. };
  68. this.client.OnAdClosed += (sender, args) =>
  69. {
  70. if (this.OnAdClosed != null)
  71. {
  72. this.OnAdClosed(this, args);
  73. }
  74. };
  75. this.client.OnAdLeavingApplication += (sender, args) =>
  76. {
  77. if (this.OnAdLeavingApplication != null)
  78. {
  79. this.OnAdLeavingApplication(this, args);
  80. }
  81. };
  82. this.client.OnAdRewarded += (sender, args) =>
  83. {
  84. if (this.OnAdRewarded != null)
  85. {
  86. this.OnAdRewarded(this, args);
  87. }
  88. };
  89. this.client.OnAdCompleted += (sender, args) =>
  90. {
  91. if (this.OnAdCompleted != null)
  92. {
  93. this.OnAdCompleted(this, args);
  94. }
  95. };
  96. }
  97. // These are the ad callback events that can be hooked into.
  98. public event EventHandler<EventArgs> OnAdLoaded;
  99. public event EventHandler<AdFailedToLoadEventArgs> OnAdFailedToLoad;
  100. public event EventHandler<EventArgs> OnAdOpening;
  101. public event EventHandler<EventArgs> OnAdStarted;
  102. public event EventHandler<EventArgs> OnAdClosed;
  103. public event EventHandler<Reward> OnAdRewarded;
  104. public event EventHandler<EventArgs> OnAdLeavingApplication;
  105. public event EventHandler<EventArgs> OnAdCompleted;
  106. // Loads a new reward based video ad request
  107. public void LoadAd(AdRequest request, string adUnitId)
  108. {
  109. client.LoadAd(request, adUnitId);
  110. }
  111. // Determines whether the reward based video has loaded.
  112. public bool IsLoaded()
  113. {
  114. return client.IsLoaded();
  115. }
  116. // Shows the reward based video.
  117. public void Show()
  118. {
  119. client.ShowRewardBasedVideoAd();
  120. }
  121. // Sets the user id of current user.
  122. public void SetUserId(string userId)
  123. {
  124. client.SetUserId(userId);
  125. }
  126. // Returns the mediation adapter class name.
  127. public string MediationAdapterClassName()
  128. {
  129. return this.client.MediationAdapterClassName();
  130. }
  131. }
  132. }