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/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 new file mode 100644 index 00000000..15467151 --- /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) +} 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..acb071ad --- /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) + } +} 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 diff --git a/hms-sdk-unity/HuaweiMobileServices/Ads/AdListenerWrapper.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/AdListenerWrapper.cs new file mode 100644 index 00000000..d72ff572 --- /dev/null +++ b/hms-sdk-unity/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/hms-sdk-unity/HuaweiMobileServices/Ads/AdParam.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/AdParam.cs new file mode 100644 index 00000000..fc87b80b --- /dev/null +++ b/hms-sdk-unity/HuaweiMobileServices/Ads/AdParam.cs @@ -0,0 +1,117 @@ +using System.Collections.Generic; + +namespace HuaweiMobileServices.Ads +{ + using HuaweiMobileServices.Utils; + using UnityEngine; + + // 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(); + + // 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) + { + JavaObject = Call("addKeyword", param1String); + return this; + } + + public AdParam Build() => CallAsWrapper("build"); + + public Builder SetTargetingContentUrl(string param1String) + { + JavaObject = Call("setTargetingContentUrl", param1String); + return this; + } + + public Builder SetGender(int param1Int) + { + JavaObject = Call("setGender", param1Int); + return this; + } + + public Builder SetRequestOrigin(string param1String) + { + JavaObject = Call("setRequestOrigin", param1String); + return this; + } + + public Builder SetBelongCountryCode(string param1String) + { + JavaObject = Call("setBelongCountryCode", param1String); + return this; + } + + public Builder SetTagForChildProtection(int? param1Integer) + { + JavaObject = Call("setTagForChildProtection", param1Integer); + return this; + } + + public Builder SetNonPersonalizedAd(int? param1Integer) + { + JavaObject = Call("setNonPersonalizedAd", param1Integer); + return this; + } + + public Builder SetAppLang(string param1String) + { + JavaObject = Call("setAppLang", param1String); + return this; + } + + public Builder SetAppCountry(string param1String) + { + JavaObject = Call("setAppCountry", param1String); + return this; + } + + public Builder SetTagForUnderAgeOfPromise(int? param1Integer) + { + JavaObject = Call("setTagForUnderAgeOfPromise", param1Integer); + return this; + } + + public Builder SetAdContentClassification(string param1String) + { + JavaObject = Call("setAdContentClassification", param1String); + return this; + } + } + + public static class 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/hms-sdk-unity/HuaweiMobileServices/Ads/BannerAdSize.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/BannerAdSize.cs new file mode 100644 index 00000000..ce6fe891 --- /dev/null +++ b/hms-sdk-unity/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/hms-sdk-unity/HuaweiMobileServices/Ads/BannerView.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/BannerView.cs new file mode 100644 index 00000000..08706035 --- /dev/null +++ b/hms-sdk-unity/HuaweiMobileServices/Ads/BannerView.cs @@ -0,0 +1,47 @@ +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) => Call("loadAd", 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/hms-sdk-unity/HuaweiMobileServices/Ads/HwAds.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/HwAds.cs new file mode 100644 index 00000000..e1e225cb --- /dev/null +++ b/hms-sdk-unity/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/hms-sdk-unity/HuaweiMobileServices/Ads/IAdListener.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/IAdListener.cs new file mode 100644 index 00000000..70e7b750 --- /dev/null +++ b/hms-sdk-unity/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/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/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/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/IRewardAdStatusListener.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/IRewardAdStatusListener.cs new file mode 100644 index 00000000..25d5261e --- /dev/null +++ b/hms-sdk-unity/HuaweiMobileServices/Ads/IRewardAdStatusListener.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace HuaweiMobileServices.Ads +{ + public interface IRewardAdStatusListener + { + void OnRewardAdClosed(); + void OnRewardAdFailedToShow(int errorCode); + void OnRewardAdOpened(); + void OnRewarded(Reward reward); + } +} diff --git a/hms-sdk-unity/HuaweiMobileServices/Ads/OnMetadataChangedListener.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/OnMetadataChangedListener.cs new file mode 100644 index 00000000..ebb15391 --- /dev/null +++ b/hms-sdk-unity/HuaweiMobileServices/Ads/OnMetadataChangedListener.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 OnMetadataChangedListener : 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 OnMetadataChangedListener(IOnMetadataChangedListener listener) + : base("org.m0skit0.android.hms.unity.ads.OnMetadataChangedListenerWrapper", new OnMetadataChangedListenerInterfaceWrapper(listener)) { } + } +} 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..ceadd540 --- /dev/null +++ b/hms-sdk-unity/HuaweiMobileServices/Ads/RewardAd.cs @@ -0,0 +1,69 @@ +namespace HuaweiMobileServices.Ads +{ + using HuaweiMobileServices.Utils; + using UnityEngine; + + // 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 RewardAdLoadListener(paramRewardAdLoadListener)); + + public virtual IOnMetadataChangedListener OnMetadataChangedListener + { + set + { + Call("setOnMetadataChangedListener", new OnMetadataChangedListener(value)); + } + } + + public virtual void Show(IRewardAdStatusListener paramRewardAdStatusListener, bool paramBoolean) => + Call("show", AndroidContext.GetActivityContext(), new RewardAdStausListener(paramRewardAdStatusListener), paramBoolean); + + public virtual void Show(IRewardAdStatusListener paramRewardAdStatusListener) => + Call("show", AndroidContext.GetActivityContext(), new RewardAdStausListener(paramRewardAdStatusListener)); + + public virtual RewardVerifyConfig RewardVerifyConfig => CallAsWrapper("getRewardVerifyConfig"); + + public virtual void Destroy() => Call("destroy", AndroidContext.GetActivityContext()); + + public virtual IRewardAdListener RewardAdListener + { + set + { + Call("setRewardAdListener", new RewardAdListenerWrapper(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/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/RewardAdLoadListener.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/RewardAdLoadListener.cs new file mode 100644 index 00000000..e792d1e2 --- /dev/null +++ b/hms-sdk-unity/HuaweiMobileServices/Ads/RewardAdLoadListener.cs @@ -0,0 +1,37 @@ +namespace HuaweiMobileServices.Ads +{ + using UnityEngine; + using HuaweiMobileServices.Utils; + + // Wrapper for com.huawei.hms.ads.reward.RewardAdLoadListener + public class RewardAdLoadListener : 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 RewardAdLoadListener(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/Ads/RewardAdStausListener.cs b/hms-sdk-unity/HuaweiMobileServices/Ads/RewardAdStausListener.cs new file mode 100644 index 00000000..6e3e30d4 --- /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 IRewardAdStatusListener mListener; + + public RewardAdStausListenerInterfaceWrapper(IRewardAdStatusListener 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(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 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) 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)