From 155f2c9dab5d6adbd11444c1c48babc129b58bd2 Mon Sep 17 00:00:00 2001 From: Yassine Diouri Date: Tue, 14 Apr 2020 12:47:38 +0200 Subject: [PATCH 1/7] Ads work in progress --- HuaweiMobileServices/Ads/AdListenerWrapper.cs | 51 ++++++ HuaweiMobileServices/Ads/AdParam.cs | 154 ++++++++++++++++++ HuaweiMobileServices/Ads/BannerAdSize.cs | 53 ++++++ HuaweiMobileServices/Ads/BannerView.cs | 50 ++++++ HuaweiMobileServices/Ads/HwAds.cs | 19 +++ HuaweiMobileServices/Ads/IAdListener.cs | 17 ++ .../Utils/AndroidJavaClassExtensions.cs | 3 + .../Utils/AndroidJavaObjectExtensions.cs | 6 + 8 files changed, 353 insertions(+) create mode 100644 HuaweiMobileServices/Ads/AdListenerWrapper.cs create mode 100644 HuaweiMobileServices/Ads/AdParam.cs create mode 100644 HuaweiMobileServices/Ads/BannerAdSize.cs create mode 100644 HuaweiMobileServices/Ads/BannerView.cs create mode 100644 HuaweiMobileServices/Ads/HwAds.cs create mode 100644 HuaweiMobileServices/Ads/IAdListener.cs diff --git a/HuaweiMobileServices/Ads/AdListenerWrapper.cs b/HuaweiMobileServices/Ads/AdListenerWrapper.cs new file mode 100644 index 00000000..d72ff572 --- /dev/null +++ b/HuaweiMobileServices/Ads/AdListenerWrapper.cs @@ -0,0 +1,51 @@ +namespace HuaweiMobileServices.Ads +{ + using UnityEngine; + + internal class AdListenerWrapper : AndroidJavaProxy + { + + private readonly IAdListener mListener; + + public AdListenerWrapper(IAdListener listener) : base("com.huawei.hms.ads.AdListener") + { + mListener = listener; + } + + public void onAdClosed() + { + mListener.OnAdClosed(); + } + + public void onAdFailed(int paramInt) + { + mListener.OnAdFailed(paramInt); + } + + public void onAdLeave() + { + mListener.OnAdLeave(); + } + + public void onAdOpened() + { + mListener.OnAdOpened(); + } + + public void onAdLoaded() + { + mListener.OnAdLoaded(); + } + + public void onAdClicked() + { + mListener.OnAdClicked(); + } + + public void onAdImpression() + { + mListener.OnAdImpression(); + } + + } +} diff --git a/HuaweiMobileServices/Ads/AdParam.cs b/HuaweiMobileServices/Ads/AdParam.cs new file mode 100644 index 00000000..69961f98 --- /dev/null +++ b/HuaweiMobileServices/Ads/AdParam.cs @@ -0,0 +1,154 @@ +using System.Collections.Generic; + +namespace HuaweiMobileServices.Ads +{ + using UnityEngine; + using HuaweiMobileServices.Utils; + + // Wrapper for com.huawei.hms.ads.AdParam + public class AdParam : JavaObjectWrapper + { + + public AdParam(AndroidJavaObject javaObject) : base(javaObject) { } + + public virtual string TargetingContentUrl => CallAsString("getTargetingContentUrl"); + + public int Gender => Call("getGender"); + + public ISet Keywords => Call("getKeywords").AsStringSet(); + + public Location Code() + { + return this.Code_Conflict.B(); + } + + public RequestOptions V() + { + return this.Code_Conflict.C(); + } + + // Wrapper for com.huawei.hms.ads.AdParam.Builder + public class Builder : JavaObjectWrapper + { + + public Builder(AndroidJavaObject javaObject) : base(javaObject) { } + + + + public Builder AddKeyword(string param1String) + { + this.Code.Code(Param1String); + return this; + } + + //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: + //ORIGINAL LINE: @GlobalApi public final AdParam build() + public AdParam Build() + { + return new AdParam(this, (sbyte)0); + } + + //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: + //ORIGINAL LINE: @GlobalApi public final Builder setTargetingContentUrl(String param1String) + public Builder setTargetingContentUrl(string Param1String) + { + this.Code.V(Param1String); + return this; + } + + //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: + //ORIGINAL LINE: @GlobalApi public final Builder setGender(int param1Int) + public Builder setGender(int Param1Int) + { + this.Code.Code(Param1Int); + return this; + } + + //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: + //ORIGINAL LINE: @GlobalApi public final Builder setRequestOrigin(String param1String) + public Builder setRequestOrigin(string Param1String) + { + this.Code.I(Param1String); + return this; + } + + //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: + //ORIGINAL LINE: @GlobalApi public final Builder setBelongCountryCode(String param1String) + public Builder setBelongCountryCode(string Param1String) + { + this.Code.S(Param1String); + return this; + } + + //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: + //ORIGINAL LINE: @GlobalApi public final Builder setTagForChildProtection(System.Nullable param1Integer) + public Builder setTagForChildProtection(int? Param1Integer) + { + this.Code.Code(Param1Integer.Value); + return this; + } + + //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: + //ORIGINAL LINE: @GlobalApi public final Builder setNonPersonalizedAd(System.Nullable param1Integer) + public Builder setNonPersonalizedAd(int? Param1Integer) + { + this.Code.V(Param1Integer); + return this; + } + + //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: + //ORIGINAL LINE: @GlobalApi public final Builder setAppLang(String param1String) + public Builder setAppLang(string Param1String) + { + this.Code.Z(Param1String); + return this; + } + + //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: + //ORIGINAL LINE: @GlobalApi public final Builder setAppCountry(String param1String) + public Builder setAppCountry(string Param1String) + { + this.Code.B(Param1String); + return this; + } + + //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: + //ORIGINAL LINE: @GlobalApi public final Builder setTagForUnderAgeOfPromise(System.Nullable param1Integer) + public Builder setTagForUnderAgeOfPromise(int? Param1Integer) + { + this.Code.I(Param1Integer); + return this; + } + + //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: + //ORIGINAL LINE: @GlobalApi public final Builder setAdContentClassification(String param1String) + public Builder setAdContentClassification(string Param1String) + { + this.Code.C(Param1String); + return this; + } + } + + //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: + //ORIGINAL LINE: @GlobalApi public static interface ErrorCode + public interface ErrorCode + { + public static int INNER = 0; + + public static int INVALID_REQUEST = 1; + + public static int NETWORK_ERROR = 2; + + public static int NO_AD = 3; + + public static int AD_LOADING = 4; + + public static int LOW_API = 5; + + public static int BANNER_AD_EXPIRE = 6; + + public static int BANNER_AD_CANCEL = 7; + } + } + +} \ No newline at end of file diff --git a/HuaweiMobileServices/Ads/BannerAdSize.cs b/HuaweiMobileServices/Ads/BannerAdSize.cs new file mode 100644 index 00000000..ce6fe891 --- /dev/null +++ b/HuaweiMobileServices/Ads/BannerAdSize.cs @@ -0,0 +1,53 @@ +namespace HuaweiMobileServices.Ads +{ + using HuaweiMobileServices.Utils; + using UnityEngine; + + // Wrapper for com.huawei.hms.ads.BannerAdSize + public class BannerAdSize : JavaObjectWrapper + { + + private const string CLASS_NAME = "com.huawei.hms.ads.BannerAdSize"; + + private static readonly AndroidJavaClass sJavaClass = new AndroidJavaClass(CLASS_NAME); + + public static BannerAdSize BANNER_SIZE_360_57 => sJavaClass.GetStaticAsWrapper("BANNER_SIZE_360_57"); + public static BannerAdSize BANNER_SIZE_360_144 => sJavaClass.GetStaticAsWrapper("BANNER_SIZE_360_144"); + public static BannerAdSize BANNER_SIZE_320_50 => sJavaClass.GetStaticAsWrapper("BANNER_SIZE_320_50"); + public static BannerAdSize BANNER_SIZE_DYNAMIC => sJavaClass.GetStaticAsWrapper("BANNER_SIZE_DYNAMIC"); + public static BannerAdSize BANNER_SIZE_468_60 => sJavaClass.GetStaticAsWrapper("BANNER_SIZE_468_60"); + public static BannerAdSize BANNER_SIZE_INVALID => sJavaClass.GetStaticAsWrapper("BANNER_SIZE_INVALID"); + public static BannerAdSize BANNER_SIZE_320_100 => sJavaClass.GetStaticAsWrapper("BANNER_SIZE_320_100"); + public static BannerAdSize BANNER_SIZE_728_90 => sJavaClass.GetStaticAsWrapper("BANNER_SIZE_728_90"); + public static BannerAdSize BANNER_SIZE_300_250 => sJavaClass.GetStaticAsWrapper("BANNER_SIZE_300_250"); + public static BannerAdSize BANNER_SIZE_SMART => sJavaClass.GetStaticAsWrapper("BANNER_SIZE_SMART"); + public static BannerAdSize BANNER_SIZE_160_600 => sJavaClass.GetStaticAsWrapper("BANNER_SIZE_160_600"); + + public static BannerAdSize GetCurrentDirectionBannerSize(int paramInt) => + sJavaClass.CallStaticAsWrapper("getCurrentDirectionBannerSize", AndroidContext.GetActivityContext(), paramInt); + + public static BannerAdSize GetLandscapeBannerSize(int paramInt) => + sJavaClass.CallStaticAsWrapper("getLandscapeBannerSize", AndroidContext.GetActivityContext(), paramInt); + + public static BannerAdSize GetPortraitBannerSize(int paramInt) => + sJavaClass.CallStaticAsWrapper("getPortraitBannerSize", AndroidContext.GetActivityContext(), paramInt); + + public BannerAdSize(int paramInt1, int paramInt2) : base(CLASS_NAME, paramInt1, paramInt2) { } + + public BannerAdSize(AndroidJavaObject javaObject) : base(javaObject) { } + + public int Height => Call("getHeight"); + + public int Width => Call("getWidth"); + + public int HeightPx => Call("getHeightPx", AndroidContext.GetActivityContext()); + + public int WidthPx => Call("getWidthPx", AndroidContext.GetActivityContext()); + + public bool AutoHeightSize => Call("isAutoHeightSize"); + + public bool DynamicSize => Call("isDynamicSize"); + + public bool FullWidthSize => Call("isFullWidthSize"); + } +} diff --git a/HuaweiMobileServices/Ads/BannerView.cs b/HuaweiMobileServices/Ads/BannerView.cs new file mode 100644 index 00000000..640810c3 --- /dev/null +++ b/HuaweiMobileServices/Ads/BannerView.cs @@ -0,0 +1,50 @@ +using System; + +namespace HuaweiMobileServices.Ads +{ + using HuaweiMobileServices.Utils; + using UnityEngine; + + // Wrapper for com.huawei.hms.ads.banner.BannerView + public class BannerView : JavaObjectWrapper + { + + public BannerView(AndroidJavaObject javaObject) : base(javaObject) { } + + public virtual void Destroy() => Call("destroy"); + + public virtual IAdListener AdListener + { + set => Call("setAdListener", new AdListenerWrapper(value)); + } + + public virtual BannerAdSize BannerAdSize + { + get => CallAsWrapper("getBannerAdSize"); + set => Call("setBannerAdSize", value); + } + + public virtual string AdId => CallAsString("getAdId"); + + public virtual bool Loading => Call("isLoading"); + + public virtual void LoadAd(AdParam ParamAdParam) + { + this.I.Code(ParamAdParam); + } + + public virtual void Pause() => Call("pause"); + + public virtual void Resume() => Call("resume"); + + public virtual long BannerRefresh + { + set + { + Call("setBannerRefresh", value); + } + } + + } + +} \ No newline at end of file diff --git a/HuaweiMobileServices/Ads/HwAds.cs b/HuaweiMobileServices/Ads/HwAds.cs new file mode 100644 index 00000000..e1e225cb --- /dev/null +++ b/HuaweiMobileServices/Ads/HwAds.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace HuaweiMobileServices.Ads +{ + using UnityEngine; + using HuaweiMobileServices.Utils; + + // Wrapper for com.huawei.hms.ads.HwAds + public static class HwAds + { + + private static readonly AndroidJavaClass sJavaClass = new AndroidJavaClass("com.huawei.hms.ads.HwAds"); + + public static void Init() => sJavaClass.CallStatic("init", AndroidContext.GetActivityContext()); + + } +} diff --git a/HuaweiMobileServices/Ads/IAdListener.cs b/HuaweiMobileServices/Ads/IAdListener.cs new file mode 100644 index 00000000..70e7b750 --- /dev/null +++ b/HuaweiMobileServices/Ads/IAdListener.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace HuaweiMobileServices.Ads +{ + public interface IAdListener + { + void OnAdClosed(); + void OnAdFailed(int reason); + void OnAdLeave(); + void OnAdOpened(); + void OnAdLoaded(); + void OnAdClicked(); + void OnAdImpression(); + } +} diff --git a/hms-sdk-unity/HuaweiMobileServices/Utils/AndroidJavaClassExtensions.cs b/hms-sdk-unity/HuaweiMobileServices/Utils/AndroidJavaClassExtensions.cs index 5d417b46..b778a414 100644 --- a/hms-sdk-unity/HuaweiMobileServices/Utils/AndroidJavaClassExtensions.cs +++ b/hms-sdk-unity/HuaweiMobileServices/Utils/AndroidJavaClassExtensions.cs @@ -9,5 +9,8 @@ public static T CallStaticAsWrapper(this AndroidJavaClass javaClass, string m public static string CallStaticAsString(this AndroidJavaClass javaClass, string methodName, params object[] args) => javaClass.CallStatic(methodName, args).AsString(); + + public static T GetStaticAsWrapper(this AndroidJavaClass javaClass, string fieldName) where T : JavaObjectWrapper => + javaClass.GetStatic(fieldName).AsWrapper(); } } diff --git a/hms-sdk-unity/HuaweiMobileServices/Utils/AndroidJavaObjectExtensions.cs b/hms-sdk-unity/HuaweiMobileServices/Utils/AndroidJavaObjectExtensions.cs index 4349aed7..534f8a4c 100644 --- a/hms-sdk-unity/HuaweiMobileServices/Utils/AndroidJavaObjectExtensions.cs +++ b/hms-sdk-unity/HuaweiMobileServices/Utils/AndroidJavaObjectExtensions.cs @@ -74,6 +74,12 @@ public static ISet AsSet(this AndroidJavaObject javaSet) return new HashSet(list); } + public static ISet AsStringSet(this AndroidJavaObject javaSet) + { + var list = new AndroidJavaObject("java.util.ArrayList", javaSet).AsStringList(); + return new HashSet(list); + } + public static AndroidJavaObject AsJavaArray(this T[] array, Func converter) => new List(array) .Map(converter) From af59285a80c7373f97fc2db0908a8372ac299699 Mon Sep 17 00:00:00 2001 From: Yassine Diouri Date: Tue, 14 Apr 2020 16:59:24 +0200 Subject: [PATCH 2/7] Finished AdParams --- HuaweiMobileServices/Ads/AdParam.cs | 94 +++++++++-------------------- 1 file changed, 29 insertions(+), 65 deletions(-) diff --git a/HuaweiMobileServices/Ads/AdParam.cs b/HuaweiMobileServices/Ads/AdParam.cs index 69961f98..9809c5c3 100644 --- a/HuaweiMobileServices/Ads/AdParam.cs +++ b/HuaweiMobileServices/Ads/AdParam.cs @@ -4,12 +4,13 @@ namespace HuaweiMobileServices.Ads { using UnityEngine; using HuaweiMobileServices.Utils; + using HuaweiMobileServices.Base; - // Wrapper for com.huawei.hms.ads.AdParam - public class AdParam : JavaObjectWrapper + // Wrapper for com.huawei.hms.ads.Adparam + public class Adparam : JavaObjectWrapper { - public AdParam(AndroidJavaObject javaObject) : base(javaObject) { } + public Adparam(AndroidJavaObject javaObject) : base(javaObject) { } public virtual string TargetingContentUrl => CallAsString("getTargetingContentUrl"); @@ -17,121 +18,84 @@ public AdParam(AndroidJavaObject javaObject) : base(javaObject) { } public ISet Keywords => Call("getKeywords").AsStringSet(); - public Location Code() - { - return this.Code_Conflict.B(); - } - - public RequestOptions V() - { - return this.Code_Conflict.C(); - } - - // Wrapper for com.huawei.hms.ads.AdParam.Builder + // Wrapper for com.huawei.hms.ads.Adparam.Builder public class Builder : JavaObjectWrapper { public Builder(AndroidJavaObject javaObject) : base(javaObject) { } - + public Builder() : base("com.huawei.hms.ads.Adparam.Builder") { } public Builder AddKeyword(string param1String) { - this.Code.Code(Param1String); + JavaObject = Call("addKeyword", param1String); return this; } - //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: - //ORIGINAL LINE: @GlobalApi public final AdParam build() - public AdParam Build() - { - return new AdParam(this, (sbyte)0); - } + public Adparam Build() => CallAsWrapper("build"); - //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: - //ORIGINAL LINE: @GlobalApi public final Builder setTargetingContentUrl(String param1String) - public Builder setTargetingContentUrl(string Param1String) + public Builder SetTargetingContentUrl(string param1String) { - this.Code.V(Param1String); + JavaObject = Call("setTargetingContentUrl", param1String); return this; } - //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: - //ORIGINAL LINE: @GlobalApi public final Builder setGender(int param1Int) - public Builder setGender(int Param1Int) + public Builder SetGender(int param1Int) { - this.Code.Code(Param1Int); + JavaObject = Call("setGender", param1Int); return this; } - //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: - //ORIGINAL LINE: @GlobalApi public final Builder setRequestOrigin(String param1String) - public Builder setRequestOrigin(string Param1String) + public Builder SetRequestOrigin(string param1String) { - this.Code.I(Param1String); + JavaObject = Call("setRequestOrigin", param1String); return this; } - //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: - //ORIGINAL LINE: @GlobalApi public final Builder setBelongCountryCode(String param1String) - public Builder setBelongCountryCode(string Param1String) + public Builder SetBelongCountryCode(string param1String) { - this.Code.S(Param1String); + JavaObject = Call("setBelongCountryCode", param1String); return this; } - //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: - //ORIGINAL LINE: @GlobalApi public final Builder setTagForChildProtection(System.Nullable param1Integer) - public Builder setTagForChildProtection(int? Param1Integer) + public Builder SetTagForChildProtection(int? param1Integer) { - this.Code.Code(Param1Integer.Value); + JavaObject = Call("setTagForChildProtection", param1Integer); return this; } - //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: - //ORIGINAL LINE: @GlobalApi public final Builder setNonPersonalizedAd(System.Nullable param1Integer) - public Builder setNonPersonalizedAd(int? Param1Integer) + public Builder SetNonPersonalizedAd(int? param1Integer) { - this.Code.V(Param1Integer); + JavaObject = Call("setNonPersonalizedAd", param1Integer); return this; } - //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: - //ORIGINAL LINE: @GlobalApi public final Builder setAppLang(String param1String) - public Builder setAppLang(string Param1String) + public Builder SetAppLang(string param1String) { - this.Code.Z(Param1String); + JavaObject = Call("setAppLang", param1String); return this; } - //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: - //ORIGINAL LINE: @GlobalApi public final Builder setAppCountry(String param1String) - public Builder setAppCountry(string Param1String) + public Builder SetAppCountry(string param1String) { - this.Code.B(Param1String); + JavaObject = Call("setAppCountry", param1String); return this; } - //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: - //ORIGINAL LINE: @GlobalApi public final Builder setTagForUnderAgeOfPromise(System.Nullable param1Integer) - public Builder setTagForUnderAgeOfPromise(int? Param1Integer) + public Builder SetTagForUnderAgeOfPromise(int? param1Integer) { - this.Code.I(Param1Integer); + JavaObject = Call("setTagForUnderAgeOfPromise", param1Integer); return this; } - //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: - //ORIGINAL LINE: @GlobalApi public final Builder setAdContentClassification(String param1String) - public Builder setAdContentClassification(string Param1String) + public Builder SetAdContentClassification(string param1String) { - this.Code.C(Param1String); + JavaObject = Call("setAdContentClassification", param1String); return this; } } - //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: - //ORIGINAL LINE: @GlobalApi public static interface ErrorCode - public interface ErrorCode + public static class ErrorCode { public static int INNER = 0; From 801a21f7e9262c5853b920848efcd796aaceab68 Mon Sep 17 00:00:00 2001 From: Yassine Diouri Date: Thu, 16 Apr 2020 09:59:05 +0200 Subject: [PATCH 3/7] Refactored Ads into new folder structure --- .../HuaweiMobileServices}/Ads/AdListenerWrapper.cs | 0 .../HuaweiMobileServices}/Ads/AdParam.cs | 0 .../HuaweiMobileServices}/Ads/BannerAdSize.cs | 0 .../HuaweiMobileServices}/Ads/BannerView.cs | 0 .../HuaweiMobileServices}/Ads/HwAds.cs | 0 .../HuaweiMobileServices}/Ads/IAdListener.cs | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename {HuaweiMobileServices => hms-sdk-unity/HuaweiMobileServices}/Ads/AdListenerWrapper.cs (100%) rename {HuaweiMobileServices => hms-sdk-unity/HuaweiMobileServices}/Ads/AdParam.cs (100%) rename {HuaweiMobileServices => hms-sdk-unity/HuaweiMobileServices}/Ads/BannerAdSize.cs (100%) rename {HuaweiMobileServices => hms-sdk-unity/HuaweiMobileServices}/Ads/BannerView.cs (100%) rename {HuaweiMobileServices => hms-sdk-unity/HuaweiMobileServices}/Ads/HwAds.cs (100%) rename {HuaweiMobileServices => hms-sdk-unity/HuaweiMobileServices}/Ads/IAdListener.cs (100%) diff --git a/HuaweiMobileServices/Ads/AdListenerWrapper.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/AdListenerWrapper.cs similarity index 100% rename from HuaweiMobileServices/Ads/AdListenerWrapper.cs rename to hms-sdk-unity/HuaweiMobileServices/Ads/AdListenerWrapper.cs diff --git a/HuaweiMobileServices/Ads/AdParam.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/AdParam.cs similarity index 100% rename from HuaweiMobileServices/Ads/AdParam.cs rename to hms-sdk-unity/HuaweiMobileServices/Ads/AdParam.cs diff --git a/HuaweiMobileServices/Ads/BannerAdSize.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/BannerAdSize.cs similarity index 100% rename from HuaweiMobileServices/Ads/BannerAdSize.cs rename to hms-sdk-unity/HuaweiMobileServices/Ads/BannerAdSize.cs diff --git a/HuaweiMobileServices/Ads/BannerView.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/BannerView.cs similarity index 100% rename from HuaweiMobileServices/Ads/BannerView.cs rename to hms-sdk-unity/HuaweiMobileServices/Ads/BannerView.cs diff --git a/HuaweiMobileServices/Ads/HwAds.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/HwAds.cs similarity index 100% rename from HuaweiMobileServices/Ads/HwAds.cs rename to hms-sdk-unity/HuaweiMobileServices/Ads/HwAds.cs diff --git a/HuaweiMobileServices/Ads/IAdListener.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/IAdListener.cs similarity index 100% rename from HuaweiMobileServices/Ads/IAdListener.cs rename to hms-sdk-unity/HuaweiMobileServices/Ads/IAdListener.cs From 0795719f77a947ef3452fdb7ba4af66781ca9c75 Mon Sep 17 00:00:00 2001 From: Yassine Diouri Date: Thu, 16 Apr 2020 13:10:41 +0200 Subject: [PATCH 4/7] Bridge for RewardAdLoadListener Bridge for RewardAdLoadListener --- android-wrapper/app/build.gradle | 1 + .../hms/unity/GenericBridgeCallback.kt | 2 +- .../hms/unity/ads/RewardAdLoadListener.kt | 6 ++ .../unity/ads/RewardAdLoadListenerWrapper.kt | 12 +++ .../HuaweiMobileServices/Ads/AdParam.cs | 9 +- .../HuaweiMobileServices/Ads/BannerView.cs | 5 +- .../Ads/IRewardAdLoadListener.cs | 12 +++ .../HuaweiMobileServices/Ads/Reward.cs | 21 +++++ .../HuaweiMobileServices/Ads/RewardAd.cs | 94 +++++++++++++++++++ .../Ads/RewardAdLoadListenerWrapper.cs | 37 ++++++++ .../Utils/JavaObjectWrapper.cs | 2 +- 11 files changed, 190 insertions(+), 11 deletions(-) create mode 100644 android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/RewardAdLoadListener.kt create mode 100644 android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/RewardAdLoadListenerWrapper.kt create mode 100644 hms-sdk-unity/HuaweiMobileServices/Ads/IRewardAdLoadListener.cs create mode 100644 hms-sdk-unity/HuaweiMobileServices/Ads/Reward.cs create mode 100644 hms-sdk-unity/HuaweiMobileServices/Ads/RewardAd.cs create mode 100644 hms-sdk-unity/HuaweiMobileServices/Ads/RewardAdLoadListenerWrapper.cs diff --git a/android-wrapper/app/build.gradle b/android-wrapper/app/build.gradle index ec24b54f..347c8d9f 100644 --- a/android-wrapper/app/build.gradle +++ b/android-wrapper/app/build.gradle @@ -24,4 +24,5 @@ dependencies { // HMS compileOnly 'com.huawei.hms:iap:4.0.2.300' + compileOnly 'com.huawei.hms:ads-lite:13.4.28.305' } diff --git a/android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/GenericBridgeCallback.kt b/android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/GenericBridgeCallback.kt index f04a70b7..4bd48def 100644 --- a/android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/GenericBridgeCallback.kt +++ b/android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/GenericBridgeCallback.kt @@ -5,4 +5,4 @@ import android.content.Intent interface GenericBridgeCallback { fun onSuccess(data: Intent) fun onFailure(error: Exception) -} \ No newline at end of file +} diff --git a/android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/RewardAdLoadListener.kt b/android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/RewardAdLoadListener.kt new file mode 100644 index 00000000..990f9273 --- /dev/null +++ b/android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/RewardAdLoadListener.kt @@ -0,0 +1,6 @@ +package org.m0skit0.android.hms.unity.ads + +interface RewardAdLoadListener { + fun onRewardedLoaded() + fun onRewardAdFailedToLoad(errorCode: Int) +} \ No newline at end of file diff --git a/android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/RewardAdLoadListenerWrapper.kt b/android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/RewardAdLoadListenerWrapper.kt new file mode 100644 index 00000000..81d373d1 --- /dev/null +++ b/android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/RewardAdLoadListenerWrapper.kt @@ -0,0 +1,12 @@ +package org.m0skit0.android.hms.unity.ads + +class RewardAdLoadListenerWrapper(private val listener: RewardAdLoadListener) : com.huawei.hms.ads.reward.RewardAdLoadListener() { + + override fun onRewardedLoaded() { + listener.onRewardedLoaded() + } + + override fun onRewardAdFailedToLoad(errorCode: Int) { + listener.onRewardAdFailedToLoad(errorCode) + } +} \ No newline at end of file diff --git a/hms-sdk-unity/HuaweiMobileServices/Ads/AdParam.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/AdParam.cs index 9809c5c3..fc87b80b 100644 --- a/hms-sdk-unity/HuaweiMobileServices/Ads/AdParam.cs +++ b/hms-sdk-unity/HuaweiMobileServices/Ads/AdParam.cs @@ -2,15 +2,14 @@ namespace HuaweiMobileServices.Ads { - using UnityEngine; using HuaweiMobileServices.Utils; - using HuaweiMobileServices.Base; + using UnityEngine; // Wrapper for com.huawei.hms.ads.Adparam - public class Adparam : JavaObjectWrapper + public class AdParam : JavaObjectWrapper { - public Adparam(AndroidJavaObject javaObject) : base(javaObject) { } + public AdParam(AndroidJavaObject javaObject) : base(javaObject) { } public virtual string TargetingContentUrl => CallAsString("getTargetingContentUrl"); @@ -32,7 +31,7 @@ public Builder AddKeyword(string param1String) return this; } - public Adparam Build() => CallAsWrapper("build"); + public AdParam Build() => CallAsWrapper("build"); public Builder SetTargetingContentUrl(string param1String) { diff --git a/hms-sdk-unity/HuaweiMobileServices/Ads/BannerView.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/BannerView.cs index 640810c3..08706035 100644 --- a/hms-sdk-unity/HuaweiMobileServices/Ads/BannerView.cs +++ b/hms-sdk-unity/HuaweiMobileServices/Ads/BannerView.cs @@ -28,10 +28,7 @@ public virtual BannerAdSize BannerAdSize public virtual bool Loading => Call("isLoading"); - public virtual void LoadAd(AdParam ParamAdParam) - { - this.I.Code(ParamAdParam); - } + public virtual void LoadAd(AdParam paramAdParam) => Call("loadAd", paramAdParam); public virtual void Pause() => Call("pause"); diff --git a/hms-sdk-unity/HuaweiMobileServices/Ads/IRewardAdLoadListener.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/IRewardAdLoadListener.cs new file mode 100644 index 00000000..c70d3ed4 --- /dev/null +++ b/hms-sdk-unity/HuaweiMobileServices/Ads/IRewardAdLoadListener.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace HuaweiMobileServices.Ads +{ + public interface IRewardAdLoadListener + { + void OnRewardAdFailedToLoad(int errorCode); + void OnRewardedLoaded(); + } +} diff --git a/hms-sdk-unity/HuaweiMobileServices/Ads/Reward.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/Reward.cs new file mode 100644 index 00000000..6eaaba62 --- /dev/null +++ b/hms-sdk-unity/HuaweiMobileServices/Ads/Reward.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace HuaweiMobileServices.Ads +{ + using UnityEngine; + using HuaweiMobileServices.Utils; + + // Wrapper for com.huawei.hms.ads.reward.Reward + public class Reward : JavaObjectWrapper + { + + public Reward(AndroidJavaObject javaObject) : base(javaObject) { } + + public string Name => CallAsString("getName"); + + public int Amount => Call("getAmount"); + + } +} diff --git a/hms-sdk-unity/HuaweiMobileServices/Ads/RewardAd.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/RewardAd.cs new file mode 100644 index 00000000..35a46af1 --- /dev/null +++ b/hms-sdk-unity/HuaweiMobileServices/Ads/RewardAd.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; + +namespace HuaweiMobileServices.Ads +{ + using UnityEngine; + using HuaweiMobileServices.Utils; + + // Wrapper for com.huawei.hms.ads.reward.RewardAd + public class RewardAd : JavaObjectWrapper + { + private const string CLASS_NAME = "com.huawei.hms.ads.reward.RewardAd"; + + private static readonly AndroidJavaClass sJavaClass = new AndroidJavaClass(CLASS_NAME); + + public static RewardAd CreateRewardAdInstance() => + sJavaClass.CallStaticAsWrapper("createRewardAdInstance", AndroidContext.GetActivityContext()); + + public RewardAd(AndroidJavaObject javaObject) : base(javaObject) { } + + public RewardAd(string paramString) : base("com.huawei.hms.ads.reward.RewardAd", AndroidContext.GetActivityContext(), paramString) { } + + public virtual Reward Reward => CallAsWrapper("getReward"); + + public virtual bool Loaded => Call("isLoaded"); + + public virtual void LoadAd(AdParam paramAdParam, IRewardAdLoadListener paramRewardAdLoadListener) => + Call("loadAd", paramAdParam, new RewardAdLoadListenerWrapper(paramRewardAdLoadListener)); + + public virtual OnMetadataChangedListener OnMetadataChangedListener + { + set + { + this.Code_Conflict = value; + } + } + + public virtual void Show(Activity ParamActivity, RewardAdStatusListener ParamRewardAdStatusListener, bool ParamBoolean) + { + + } + + public virtual void Show(Activity ParamActivity, RewardAdStatusListener ParamRewardAdStatusListener) + { + Show(ParamActivity, ParamRewardAdStatusListener, true); + } + + public virtual RewardVerifyConfig RewardVerifyConfig + { + set + { + this.C = value; + } + } + + public virtual void Destroy() => Call("destroy", AndroidContext.GetActivityContext()); + + public virtual Bundle Metadata + { + get + { + return this.D; + } + } + + public virtual RewardAdListener RewardAdListener + { + get + { + return this.L; + } + set + { + this.L = value; + } + } + + public virtual string Data => CallAsString("getData"); + + public virtual string UserId => CallAsString("getUserId"); + + public virtual void LoadAd(string paramString, AdParam paramAdParam) => Call("loadAd", paramString, paramAdParam); + + public virtual void Pause() => Call("pause", AndroidContext.GetActivityContext()); + + public virtual void Resume() => Call("resume", AndroidContext.GetActivityContext()); + + public virtual bool Immersive => Call("isImmersive"); + + public virtual void Show() => Call("show"); + + } + +} \ No newline at end of file diff --git a/hms-sdk-unity/HuaweiMobileServices/Ads/RewardAdLoadListenerWrapper.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/RewardAdLoadListenerWrapper.cs new file mode 100644 index 00000000..736b9907 --- /dev/null +++ b/hms-sdk-unity/HuaweiMobileServices/Ads/RewardAdLoadListenerWrapper.cs @@ -0,0 +1,37 @@ +namespace HuaweiMobileServices.Ads +{ + using UnityEngine; + using HuaweiMobileServices.Utils; + + // Wrapper for com.huawei.hms.ads.reward.RewardAdLoadListener + public class RewardAdLoadListenerWrapper : JavaObjectWrapper + { + + internal class RewardAdLoadListenerInterfaceWrapper : AndroidJavaProxy + { + + private readonly IRewardAdLoadListener mListener; + + public RewardAdLoadListenerInterfaceWrapper(IRewardAdLoadListener listener) : base("org.m0skit0.android.hms.unity.ads.RewardAdLoadListener") + { + mListener = listener; + } + + public void onRewardedLoaded() + { + mListener.OnRewardedLoaded(); + } + + public void onRewardAdFailedToLoad(int errorCode) + { + mListener.OnRewardAdFailedToLoad(errorCode); + } + + } + + public RewardAdLoadListenerWrapper(IRewardAdLoadListener listener) + : base("org.m0skit0.android.hms.unity.ads.RewardAdLoadListenerWrapper", new RewardAdLoadListenerInterfaceWrapper(listener)) { } + + } + +} \ No newline at end of file diff --git a/hms-sdk-unity/HuaweiMobileServices/Utils/JavaObjectWrapper.cs b/hms-sdk-unity/HuaweiMobileServices/Utils/JavaObjectWrapper.cs index 32629908..dae7f02b 100644 --- a/hms-sdk-unity/HuaweiMobileServices/Utils/JavaObjectWrapper.cs +++ b/hms-sdk-unity/HuaweiMobileServices/Utils/JavaObjectWrapper.cs @@ -3,7 +3,7 @@ namespace HuaweiMobileServices.Utils using System.Collections.Generic; using UnityEngine; - public abstract class JavaObjectWrapper : MonoBehaviour + public abstract class JavaObjectWrapper { private static object[] AsAutoParams(object[] args) From 94de448415aca3b513d241dc82740c7437bcd9e1 Mon Sep 17 00:00:00 2001 From: Yassine Diouri Date: Thu, 16 Apr 2020 14:05:53 +0200 Subject: [PATCH 5/7] More bridges for ads because whoever made this API doesn't know what an interface is --- .../unity/ads/OnMetadataChangedListener.kt | 5 +++++ .../ads/OnMetadataChangedListenerWrapper.kt | 8 +++++++ .../hms/unity/ads/RewardAdLoadListener.kt | 2 +- .../unity/ads/RewardAdLoadListenerWrapper.kt | 2 +- .../hms/unity/ads/RewardAdStatusListener.kt | 10 +++++++++ .../ads/RewardAdStatusListenerWrapper.kt | 22 +++++++++++++++++++ 6 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/OnMetadataChangedListener.kt create mode 100644 android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/OnMetadataChangedListenerWrapper.kt create mode 100644 android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/RewardAdStatusListener.kt create mode 100644 android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/RewardAdStatusListenerWrapper.kt diff --git a/android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/OnMetadataChangedListener.kt b/android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/OnMetadataChangedListener.kt new file mode 100644 index 00000000..cb6e6e3d --- /dev/null +++ b/android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/OnMetadataChangedListener.kt @@ -0,0 +1,5 @@ +package org.m0skit0.android.hms.unity.ads + +interface OnMetadataChangedListener { + fun onMetadataChanged() +} diff --git a/android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/OnMetadataChangedListenerWrapper.kt b/android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/OnMetadataChangedListenerWrapper.kt new file mode 100644 index 00000000..61b41259 --- /dev/null +++ b/android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/OnMetadataChangedListenerWrapper.kt @@ -0,0 +1,8 @@ +package org.m0skit0.android.hms.unity.ads + +class OnMetadataChangedListenerWrapper(private val listener: OnMetadataChangedListener) : com.huawei.hms.ads.reward.OnMetadataChangedListener() { + + override fun onMetadataChanged() { + listener.onMetadataChanged() + } +} diff --git a/android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/RewardAdLoadListener.kt b/android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/RewardAdLoadListener.kt index 990f9273..15467151 100644 --- a/android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/RewardAdLoadListener.kt +++ b/android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/RewardAdLoadListener.kt @@ -3,4 +3,4 @@ package org.m0skit0.android.hms.unity.ads interface RewardAdLoadListener { fun onRewardedLoaded() fun onRewardAdFailedToLoad(errorCode: Int) -} \ No newline at end of file +} diff --git a/android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/RewardAdLoadListenerWrapper.kt b/android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/RewardAdLoadListenerWrapper.kt index 81d373d1..acb071ad 100644 --- a/android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/RewardAdLoadListenerWrapper.kt +++ b/android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/RewardAdLoadListenerWrapper.kt @@ -9,4 +9,4 @@ class RewardAdLoadListenerWrapper(private val listener: RewardAdLoadListener) : override fun onRewardAdFailedToLoad(errorCode: Int) { listener.onRewardAdFailedToLoad(errorCode) } -} \ No newline at end of file +} diff --git a/android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/RewardAdStatusListener.kt b/android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/RewardAdStatusListener.kt new file mode 100644 index 00000000..3a18839d --- /dev/null +++ b/android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/RewardAdStatusListener.kt @@ -0,0 +1,10 @@ +package org.m0skit0.android.hms.unity.ads + +import com.huawei.hms.ads.reward.Reward + +interface RewardAdStatusListener { + fun onRewardAdClosed() + fun onRewardAdFailedToShow(errorCode: Int) + fun onRewardAdOpened() + fun onRewarded(reward: Reward) +} \ No newline at end of file diff --git a/android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/RewardAdStatusListenerWrapper.kt b/android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/RewardAdStatusListenerWrapper.kt new file mode 100644 index 00000000..2d711a2f --- /dev/null +++ b/android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/RewardAdStatusListenerWrapper.kt @@ -0,0 +1,22 @@ +package org.m0skit0.android.hms.unity.ads + +import com.huawei.hms.ads.reward.Reward + +class RewardAdStatusListenerWrapper(private val listener: RewardAdStatusListener) : com.huawei.hms.ads.reward.RewardAdStatusListener() { + + override fun onRewardAdClosed() { + listener.onRewardAdClosed() + } + + override fun onRewardAdFailedToShow(errorCode: Int) { + listener.onRewardAdFailedToShow(errorCode) + } + + override fun onRewardAdOpened() { + listener.onRewardAdOpened() + } + + override fun onRewarded(reward: Reward) { + listener.onRewarded(reward) + } +} \ No newline at end of file From 27be6193fd3d363953f91d43f69779555593fc8d Mon Sep 17 00:00:00 2001 From: Yassine Diouri Date: Thu, 16 Apr 2020 14:14:08 +0200 Subject: [PATCH 6/7] More ads bridges :( --- .../Ads/IOnMetadataChangedListener.cs | 11 +++++ .../Ads/IRewardAdStausListener.cs | 14 ++++++ .../Ads/OnMetadataChangedListenerWrapper.cs | 32 +++++++++++++ .../HuaweiMobileServices/Ads/RewardAd.cs | 4 +- .../Ads/RewardAdStausListener.cs | 46 +++++++++++++++++++ 5 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 hms-sdk-unity/HuaweiMobileServices/Ads/IOnMetadataChangedListener.cs create mode 100644 hms-sdk-unity/HuaweiMobileServices/Ads/IRewardAdStausListener.cs create mode 100644 hms-sdk-unity/HuaweiMobileServices/Ads/OnMetadataChangedListenerWrapper.cs create mode 100644 hms-sdk-unity/HuaweiMobileServices/Ads/RewardAdStausListener.cs diff --git a/hms-sdk-unity/HuaweiMobileServices/Ads/IOnMetadataChangedListener.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/IOnMetadataChangedListener.cs new file mode 100644 index 00000000..0236ee02 --- /dev/null +++ b/hms-sdk-unity/HuaweiMobileServices/Ads/IOnMetadataChangedListener.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace HuaweiMobileServices.Ads +{ + public interface IOnMetadataChangedListener + { + void OnMetadataChanged(); + } +} diff --git a/hms-sdk-unity/HuaweiMobileServices/Ads/IRewardAdStausListener.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/IRewardAdStausListener.cs new file mode 100644 index 00000000..d28f34d0 --- /dev/null +++ b/hms-sdk-unity/HuaweiMobileServices/Ads/IRewardAdStausListener.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace HuaweiMobileServices.Ads +{ + public interface IRewardAdStausListener + { + void OnRewardAdClosed(); + void OnRewardAdFailedToShow(int errorCode); + void OnRewardAdOpened(); + void OnRewarded(Reward reward); + } +} diff --git a/hms-sdk-unity/HuaweiMobileServices/Ads/OnMetadataChangedListenerWrapper.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/OnMetadataChangedListenerWrapper.cs new file mode 100644 index 00000000..323d169d --- /dev/null +++ b/hms-sdk-unity/HuaweiMobileServices/Ads/OnMetadataChangedListenerWrapper.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace HuaweiMobileServices.Ads +{ + using UnityEngine; + using HuaweiMobileServices.Utils; + + // Wrapper for com.huawei.hms.ads.reward.OnMetadataChangedListener + public class OnMetadataChangedListenerWrapper : JavaObjectWrapper + { + internal class OnMetadataChangedListenerInterfaceWrapper : AndroidJavaProxy + { + + private readonly IOnMetadataChangedListener mListener; + + public OnMetadataChangedListenerInterfaceWrapper(IOnMetadataChangedListener listener) : base("org.m0skit0.android.hms.unity.ads.OnMetadataChangedListener") + { + mListener = listener; + } + + public void onMetadataChanged() + { + mListener.OnMetadataChanged(); + } + } + + public OnMetadataChangedListenerWrapper(IOnMetadataChangedListener listener) + : base("org.m0skit0.android.hms.unity.ads.OnMetadataChangedListenerWrapper", new OnMetadataChangedListenerInterfaceWrapper(listener)) { } + } +} diff --git a/hms-sdk-unity/HuaweiMobileServices/Ads/RewardAd.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/RewardAd.cs index 35a46af1..057d5e87 100644 --- a/hms-sdk-unity/HuaweiMobileServices/Ads/RewardAd.cs +++ b/hms-sdk-unity/HuaweiMobileServices/Ads/RewardAd.cs @@ -27,11 +27,11 @@ public RewardAd(string paramString) : base("com.huawei.hms.ads.reward.RewardAd", public virtual void LoadAd(AdParam paramAdParam, IRewardAdLoadListener paramRewardAdLoadListener) => Call("loadAd", paramAdParam, new RewardAdLoadListenerWrapper(paramRewardAdLoadListener)); - public virtual OnMetadataChangedListener OnMetadataChangedListener + public virtual IOnMetadataChangedListener OnMetadataChangedListener { set { - this.Code_Conflict = value; + Call("setOnMetadataChangedListener", new OnMetadataChangedListenerWrapper(value)); } } diff --git a/hms-sdk-unity/HuaweiMobileServices/Ads/RewardAdStausListener.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/RewardAdStausListener.cs new file mode 100644 index 00000000..7d3eeea5 --- /dev/null +++ b/hms-sdk-unity/HuaweiMobileServices/Ads/RewardAdStausListener.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace HuaweiMobileServices.Ads +{ + using UnityEngine; + using HuaweiMobileServices.Utils; + + public class RewardAdStausListener : JavaObjectWrapper + { + internal class RewardAdStausListenerInterfaceWrapper : AndroidJavaProxy + { + + private readonly IRewardAdStausListener mListener; + + public RewardAdStausListenerInterfaceWrapper(IRewardAdStausListener listener) : base("org.m0skit0.android.hms.unity.ads.RewardAdStausListener") + { + mListener = listener; + } + + public void onRewardAdClosed() + { + mListener.OnRewardAdClosed(); + } + + public void onRewardAdFailedToShow(int errorCode) + { + mListener.OnRewardAdFailedToShow(errorCode); + } + + public void onRewardAdOpened() + { + mListener.OnRewardAdOpened(); + } + + public void onRewarded(AndroidJavaObject reward) + { + mListener.OnRewarded(new Reward(reward)); + } + } + + public RewardAdStausListener(IRewardAdStausListener listener) + : base("org.m0skit0.android.hms.unity.ads.RewardAdStausListenerWrapper", new RewardAdStausListenerInterfaceWrapper(listener)) { } + } +} From 830c9ea31a85965f027978e1f19e39786b2f3755 Mon Sep 17 00:00:00 2001 From: Yassine Diouri Date: Thu, 16 Apr 2020 14:47:28 +0200 Subject: [PATCH 7/7] Finished RewardAd and its dependencies --- .../Ads/IRewardAdListener.cs | 24 ++++++++ ...Listener.cs => IRewardAdStatusListener.cs} | 2 +- ...rapper.cs => OnMetadataChangedListener.cs} | 4 +- .../HuaweiMobileServices/Ads/RewardAd.cs | 49 ++++----------- .../Ads/RewardAdListenerWrapper.cs | 60 +++++++++++++++++++ ...enerWrapper.cs => RewardAdLoadListener.cs} | 4 +- .../Ads/RewardAdStausListener.cs | 6 +- .../Ads/RewardVerifyConfig.cs | 18 ++++++ 8 files changed, 122 insertions(+), 45 deletions(-) create mode 100644 hms-sdk-unity/HuaweiMobileServices/Ads/IRewardAdListener.cs rename hms-sdk-unity/HuaweiMobileServices/Ads/{IRewardAdStausListener.cs => IRewardAdStatusListener.cs} (86%) rename hms-sdk-unity/HuaweiMobileServices/Ads/{OnMetadataChangedListenerWrapper.cs => OnMetadataChangedListener.cs} (85%) create mode 100644 hms-sdk-unity/HuaweiMobileServices/Ads/RewardAdListenerWrapper.cs rename hms-sdk-unity/HuaweiMobileServices/Ads/{RewardAdLoadListenerWrapper.cs => RewardAdLoadListener.cs} (87%) create mode 100644 hms-sdk-unity/HuaweiMobileServices/Ads/RewardVerifyConfig.cs diff --git a/hms-sdk-unity/HuaweiMobileServices/Ads/IRewardAdListener.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/IRewardAdListener.cs new file mode 100644 index 00000000..7cf014de --- /dev/null +++ b/hms-sdk-unity/HuaweiMobileServices/Ads/IRewardAdListener.cs @@ -0,0 +1,24 @@ +namespace HuaweiMobileServices.Ads +{ + + // Wrapper for com.huawei.hms.ads.reward.RewardAdListener + public interface IRewardAdListener + { + void OnRewarded(Reward reward); + + void OnRewardAdClosed(); + + void OnRewardAdFailedToLoad(int errorCode); + + void OnRewardAdLeftApp(); + + void OnRewardAdLoaded(); + + void OnRewardAdOpened(); + + void OnRewardAdCompleted(); + + void OnRewardAdStarted(); + } + +} \ No newline at end of file diff --git a/hms-sdk-unity/HuaweiMobileServices/Ads/IRewardAdStausListener.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/IRewardAdStatusListener.cs similarity index 86% rename from hms-sdk-unity/HuaweiMobileServices/Ads/IRewardAdStausListener.cs rename to hms-sdk-unity/HuaweiMobileServices/Ads/IRewardAdStatusListener.cs index d28f34d0..25d5261e 100644 --- a/hms-sdk-unity/HuaweiMobileServices/Ads/IRewardAdStausListener.cs +++ b/hms-sdk-unity/HuaweiMobileServices/Ads/IRewardAdStatusListener.cs @@ -4,7 +4,7 @@ namespace HuaweiMobileServices.Ads { - public interface IRewardAdStausListener + public interface IRewardAdStatusListener { void OnRewardAdClosed(); void OnRewardAdFailedToShow(int errorCode); diff --git a/hms-sdk-unity/HuaweiMobileServices/Ads/OnMetadataChangedListenerWrapper.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/OnMetadataChangedListener.cs similarity index 85% rename from hms-sdk-unity/HuaweiMobileServices/Ads/OnMetadataChangedListenerWrapper.cs rename to hms-sdk-unity/HuaweiMobileServices/Ads/OnMetadataChangedListener.cs index 323d169d..ebb15391 100644 --- a/hms-sdk-unity/HuaweiMobileServices/Ads/OnMetadataChangedListenerWrapper.cs +++ b/hms-sdk-unity/HuaweiMobileServices/Ads/OnMetadataChangedListener.cs @@ -8,7 +8,7 @@ namespace HuaweiMobileServices.Ads using HuaweiMobileServices.Utils; // Wrapper for com.huawei.hms.ads.reward.OnMetadataChangedListener - public class OnMetadataChangedListenerWrapper : JavaObjectWrapper + public class OnMetadataChangedListener : JavaObjectWrapper { internal class OnMetadataChangedListenerInterfaceWrapper : AndroidJavaProxy { @@ -26,7 +26,7 @@ public void onMetadataChanged() } } - public OnMetadataChangedListenerWrapper(IOnMetadataChangedListener listener) + public OnMetadataChangedListener(IOnMetadataChangedListener listener) : base("org.m0skit0.android.hms.unity.ads.OnMetadataChangedListenerWrapper", new OnMetadataChangedListenerInterfaceWrapper(listener)) { } } } diff --git a/hms-sdk-unity/HuaweiMobileServices/Ads/RewardAd.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/RewardAd.cs index 057d5e87..ceadd540 100644 --- a/hms-sdk-unity/HuaweiMobileServices/Ads/RewardAd.cs +++ b/hms-sdk-unity/HuaweiMobileServices/Ads/RewardAd.cs @@ -1,10 +1,7 @@ -using System; -using System.Collections.Generic; - -namespace HuaweiMobileServices.Ads +namespace HuaweiMobileServices.Ads { - using UnityEngine; using HuaweiMobileServices.Utils; + using UnityEngine; // Wrapper for com.huawei.hms.ads.reward.RewardAd public class RewardAd : JavaObjectWrapper @@ -13,7 +10,7 @@ public class RewardAd : JavaObjectWrapper private static readonly AndroidJavaClass sJavaClass = new AndroidJavaClass(CLASS_NAME); - public static RewardAd CreateRewardAdInstance() => + public static RewardAd CreateRewardAdInstance() => sJavaClass.CallStaticAsWrapper("createRewardAdInstance", AndroidContext.GetActivityContext()); public RewardAd(AndroidJavaObject javaObject) : base(javaObject) { } @@ -25,53 +22,31 @@ public RewardAd(string paramString) : base("com.huawei.hms.ads.reward.RewardAd", public virtual bool Loaded => Call("isLoaded"); public virtual void LoadAd(AdParam paramAdParam, IRewardAdLoadListener paramRewardAdLoadListener) => - Call("loadAd", paramAdParam, new RewardAdLoadListenerWrapper(paramRewardAdLoadListener)); + Call("loadAd", paramAdParam, new RewardAdLoadListener(paramRewardAdLoadListener)); public virtual IOnMetadataChangedListener OnMetadataChangedListener { set { - Call("setOnMetadataChangedListener", new OnMetadataChangedListenerWrapper(value)); + Call("setOnMetadataChangedListener", new OnMetadataChangedListener(value)); } } - public virtual void Show(Activity ParamActivity, RewardAdStatusListener ParamRewardAdStatusListener, bool ParamBoolean) - { - - } + public virtual void Show(IRewardAdStatusListener paramRewardAdStatusListener, bool paramBoolean) => + Call("show", AndroidContext.GetActivityContext(), new RewardAdStausListener(paramRewardAdStatusListener), paramBoolean); - public virtual void Show(Activity ParamActivity, RewardAdStatusListener ParamRewardAdStatusListener) - { - Show(ParamActivity, ParamRewardAdStatusListener, true); - } + public virtual void Show(IRewardAdStatusListener paramRewardAdStatusListener) => + Call("show", AndroidContext.GetActivityContext(), new RewardAdStausListener(paramRewardAdStatusListener)); - public virtual RewardVerifyConfig RewardVerifyConfig - { - set - { - this.C = value; - } - } + public virtual RewardVerifyConfig RewardVerifyConfig => CallAsWrapper("getRewardVerifyConfig"); public virtual void Destroy() => Call("destroy", AndroidContext.GetActivityContext()); - public virtual Bundle Metadata + public virtual IRewardAdListener RewardAdListener { - get - { - return this.D; - } - } - - public virtual RewardAdListener RewardAdListener - { - get - { - return this.L; - } set { - this.L = value; + Call("setRewardAdListener", new RewardAdListenerWrapper(value)); } } diff --git a/hms-sdk-unity/HuaweiMobileServices/Ads/RewardAdListenerWrapper.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/RewardAdListenerWrapper.cs new file mode 100644 index 00000000..bf054887 --- /dev/null +++ b/hms-sdk-unity/HuaweiMobileServices/Ads/RewardAdListenerWrapper.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace HuaweiMobileServices.Ads +{ + using UnityEngine; + using HuaweiMobileServices.Utils; + + // Wrapper for com.huawei.hms.ads.reward.RewardAdListener + internal class RewardAdListenerWrapper : AndroidJavaProxy + { + private readonly IRewardAdListener mListener; + + public RewardAdListenerWrapper(IRewardAdListener listener) : base("com.huawei.hms.ads.reward.RewardAdListener") + { + mListener = listener; + } + + public void onRewarded(AndroidJavaObject reward) + { + mListener.OnRewarded(reward.AsWrapper()); + } + + public void onRewardAdClosed() + { + mListener.OnRewardAdClosed(); + } + + public void onRewardAdFailedToLoad(int errorCode) + { + mListener.OnRewardAdFailedToLoad(errorCode); + } + + public void onRewardAdLeftApp() + { + mListener.OnRewardAdLeftApp(); + } + + public void onRewardAdLoaded() + { + mListener.OnRewardAdLoaded(); + } + + public void onRewardAdOpened() + { + mListener.OnRewardAdOpened(); + } + + public void onRewardAdCompleted() + { + mListener.OnRewardAdCompleted(); + } + + public void onRewardAdStarted() + { + mListener.OnRewardAdStarted(); + } + } +} diff --git a/hms-sdk-unity/HuaweiMobileServices/Ads/RewardAdLoadListenerWrapper.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/RewardAdLoadListener.cs similarity index 87% rename from hms-sdk-unity/HuaweiMobileServices/Ads/RewardAdLoadListenerWrapper.cs rename to hms-sdk-unity/HuaweiMobileServices/Ads/RewardAdLoadListener.cs index 736b9907..e792d1e2 100644 --- a/hms-sdk-unity/HuaweiMobileServices/Ads/RewardAdLoadListenerWrapper.cs +++ b/hms-sdk-unity/HuaweiMobileServices/Ads/RewardAdLoadListener.cs @@ -4,7 +4,7 @@ using HuaweiMobileServices.Utils; // Wrapper for com.huawei.hms.ads.reward.RewardAdLoadListener - public class RewardAdLoadListenerWrapper : JavaObjectWrapper + public class RewardAdLoadListener : JavaObjectWrapper { internal class RewardAdLoadListenerInterfaceWrapper : AndroidJavaProxy @@ -29,7 +29,7 @@ public void onRewardAdFailedToLoad(int errorCode) } - public RewardAdLoadListenerWrapper(IRewardAdLoadListener listener) + public RewardAdLoadListener(IRewardAdLoadListener listener) : base("org.m0skit0.android.hms.unity.ads.RewardAdLoadListenerWrapper", new RewardAdLoadListenerInterfaceWrapper(listener)) { } } diff --git a/hms-sdk-unity/HuaweiMobileServices/Ads/RewardAdStausListener.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/RewardAdStausListener.cs index 7d3eeea5..6e3e30d4 100644 --- a/hms-sdk-unity/HuaweiMobileServices/Ads/RewardAdStausListener.cs +++ b/hms-sdk-unity/HuaweiMobileServices/Ads/RewardAdStausListener.cs @@ -12,9 +12,9 @@ public class RewardAdStausListener : JavaObjectWrapper internal class RewardAdStausListenerInterfaceWrapper : AndroidJavaProxy { - private readonly IRewardAdStausListener mListener; + private readonly IRewardAdStatusListener mListener; - public RewardAdStausListenerInterfaceWrapper(IRewardAdStausListener listener) : base("org.m0skit0.android.hms.unity.ads.RewardAdStausListener") + public RewardAdStausListenerInterfaceWrapper(IRewardAdStatusListener listener) : base("org.m0skit0.android.hms.unity.ads.RewardAdStausListener") { mListener = listener; } @@ -40,7 +40,7 @@ public void onRewarded(AndroidJavaObject reward) } } - public RewardAdStausListener(IRewardAdStausListener listener) + public RewardAdStausListener(IRewardAdStatusListener listener) : base("org.m0skit0.android.hms.unity.ads.RewardAdStausListenerWrapper", new RewardAdStausListenerInterfaceWrapper(listener)) { } } } diff --git a/hms-sdk-unity/HuaweiMobileServices/Ads/RewardVerifyConfig.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/RewardVerifyConfig.cs new file mode 100644 index 00000000..0e07f88e --- /dev/null +++ b/hms-sdk-unity/HuaweiMobileServices/Ads/RewardVerifyConfig.cs @@ -0,0 +1,18 @@ +namespace HuaweiMobileServices.Ads +{ + using HuaweiMobileServices.Utils; + using UnityEngine; + + // Wrapper for com.huawei.hms.ads.reward.RewardVerifyConfig + public class RewardVerifyConfig : JavaObjectWrapper + { + + public RewardVerifyConfig(AndroidJavaObject javaObject) : base(javaObject) { } + + public virtual string Data => CallAsString("getData"); + + public virtual string UserId => CallAsString("getUserId"); + + } + +} \ No newline at end of file