-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from m0skit0/ads
Wrapper for Ads kit enhancement
- Loading branch information
Showing
28 changed files
with
723 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/OnMetadataChangedListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.m0skit0.android.hms.unity.ads | ||
|
||
interface OnMetadataChangedListener { | ||
fun onMetadataChanged() | ||
} |
8 changes: 8 additions & 0 deletions
8
...r/app/src/main/java/org/m0skit0/android/hms/unity/ads/OnMetadataChangedListenerWrapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
android-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/RewardAdLoadListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.m0skit0.android.hms.unity.ads | ||
|
||
interface RewardAdLoadListener { | ||
fun onRewardedLoaded() | ||
fun onRewardAdFailedToLoad(errorCode: Int) | ||
} |
12 changes: 12 additions & 0 deletions
12
...rapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/RewardAdLoadListenerWrapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...oid-wrapper/app/src/main/java/org/m0skit0/android/hms/unity/ads/RewardAdStatusListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
22 changes: 22 additions & 0 deletions
22
...pper/app/src/main/java/org/m0skit0/android/hms/unity/ads/RewardAdStatusListenerWrapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
hms-sdk-unity/HuaweiMobileServices/Ads/AdListenerWrapper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<int>("getGender"); | ||
|
||
public ISet<string> Keywords => Call<AndroidJavaObject>("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<AndroidJavaObject>("addKeyword", param1String); | ||
return this; | ||
} | ||
|
||
public AdParam Build() => CallAsWrapper<AdParam>("build"); | ||
|
||
public Builder SetTargetingContentUrl(string param1String) | ||
{ | ||
JavaObject = Call<AndroidJavaObject>("setTargetingContentUrl", param1String); | ||
return this; | ||
} | ||
|
||
public Builder SetGender(int param1Int) | ||
{ | ||
JavaObject = Call<AndroidJavaObject>("setGender", param1Int); | ||
return this; | ||
} | ||
|
||
public Builder SetRequestOrigin(string param1String) | ||
{ | ||
JavaObject = Call<AndroidJavaObject>("setRequestOrigin", param1String); | ||
return this; | ||
} | ||
|
||
public Builder SetBelongCountryCode(string param1String) | ||
{ | ||
JavaObject = Call<AndroidJavaObject>("setBelongCountryCode", param1String); | ||
return this; | ||
} | ||
|
||
public Builder SetTagForChildProtection(int? param1Integer) | ||
{ | ||
JavaObject = Call<AndroidJavaObject>("setTagForChildProtection", param1Integer); | ||
return this; | ||
} | ||
|
||
public Builder SetNonPersonalizedAd(int? param1Integer) | ||
{ | ||
JavaObject = Call<AndroidJavaObject>("setNonPersonalizedAd", param1Integer); | ||
return this; | ||
} | ||
|
||
public Builder SetAppLang(string param1String) | ||
{ | ||
JavaObject = Call<AndroidJavaObject>("setAppLang", param1String); | ||
return this; | ||
} | ||
|
||
public Builder SetAppCountry(string param1String) | ||
{ | ||
JavaObject = Call<AndroidJavaObject>("setAppCountry", param1String); | ||
return this; | ||
} | ||
|
||
public Builder SetTagForUnderAgeOfPromise(int? param1Integer) | ||
{ | ||
JavaObject = Call<AndroidJavaObject>("setTagForUnderAgeOfPromise", param1Integer); | ||
return this; | ||
} | ||
|
||
public Builder SetAdContentClassification(string param1String) | ||
{ | ||
JavaObject = Call<AndroidJavaObject>("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; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<BannerAdSize>("BANNER_SIZE_360_57"); | ||
public static BannerAdSize BANNER_SIZE_360_144 => sJavaClass.GetStaticAsWrapper<BannerAdSize>("BANNER_SIZE_360_144"); | ||
public static BannerAdSize BANNER_SIZE_320_50 => sJavaClass.GetStaticAsWrapper<BannerAdSize>("BANNER_SIZE_320_50"); | ||
public static BannerAdSize BANNER_SIZE_DYNAMIC => sJavaClass.GetStaticAsWrapper<BannerAdSize>("BANNER_SIZE_DYNAMIC"); | ||
public static BannerAdSize BANNER_SIZE_468_60 => sJavaClass.GetStaticAsWrapper<BannerAdSize>("BANNER_SIZE_468_60"); | ||
public static BannerAdSize BANNER_SIZE_INVALID => sJavaClass.GetStaticAsWrapper<BannerAdSize>("BANNER_SIZE_INVALID"); | ||
public static BannerAdSize BANNER_SIZE_320_100 => sJavaClass.GetStaticAsWrapper<BannerAdSize>("BANNER_SIZE_320_100"); | ||
public static BannerAdSize BANNER_SIZE_728_90 => sJavaClass.GetStaticAsWrapper<BannerAdSize>("BANNER_SIZE_728_90"); | ||
public static BannerAdSize BANNER_SIZE_300_250 => sJavaClass.GetStaticAsWrapper<BannerAdSize>("BANNER_SIZE_300_250"); | ||
public static BannerAdSize BANNER_SIZE_SMART => sJavaClass.GetStaticAsWrapper<BannerAdSize>("BANNER_SIZE_SMART"); | ||
public static BannerAdSize BANNER_SIZE_160_600 => sJavaClass.GetStaticAsWrapper<BannerAdSize>("BANNER_SIZE_160_600"); | ||
|
||
public static BannerAdSize GetCurrentDirectionBannerSize(int paramInt) => | ||
sJavaClass.CallStaticAsWrapper<BannerAdSize>("getCurrentDirectionBannerSize", AndroidContext.GetActivityContext(), paramInt); | ||
|
||
public static BannerAdSize GetLandscapeBannerSize(int paramInt) => | ||
sJavaClass.CallStaticAsWrapper<BannerAdSize>("getLandscapeBannerSize", AndroidContext.GetActivityContext(), paramInt); | ||
|
||
public static BannerAdSize GetPortraitBannerSize(int paramInt) => | ||
sJavaClass.CallStaticAsWrapper<BannerAdSize>("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<int>("getHeight"); | ||
|
||
public int Width => Call<int>("getWidth"); | ||
|
||
public int HeightPx => Call<int>("getHeightPx", AndroidContext.GetActivityContext()); | ||
|
||
public int WidthPx => Call<int>("getWidthPx", AndroidContext.GetActivityContext()); | ||
|
||
public bool AutoHeightSize => Call<bool>("isAutoHeightSize"); | ||
|
||
public bool DynamicSize => Call<bool>("isDynamicSize"); | ||
|
||
public bool FullWidthSize => Call<bool>("isFullWidthSize"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<BannerAdSize>("getBannerAdSize"); | ||
set => Call("setBannerAdSize", value); | ||
} | ||
|
||
public virtual string AdId => CallAsString("getAdId"); | ||
|
||
public virtual bool Loading => Call<bool>("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); | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
Oops, something went wrong.