-
-
Save danzel/e8ebd4ca442a6b19746f to your computer and use it in GitHub Desktop.
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
namespace LibIronshodSharp | |
{ | |
public enum BannerAdPosition | |
{ | |
None, | |
TopCenter | |
} | |
} | |
using System; | |
using Android.App; | |
using Android.Gms.Ads; | |
using Android.Views; | |
using Android.Widget; | |
// ReSharper disable once CheckNamespace | |
namespace LibIronshodSharp | |
{ | |
public static class AdManager | |
{ | |
private static AdView _adView; | |
private static BannerAdPosition _currentBannerAdPosition = BannerAdPosition.None; | |
public static void CreateAndSetContentView(Activity activity, Android.Views.View view, string adUnitId, string[] testDeviceIds) | |
{ | |
var frameLayout = new FrameLayout(activity); | |
var linearLayout = new LinearLayout(activity); | |
linearLayout.Orientation = Orientation.Horizontal; | |
linearLayout.SetGravity(GravityFlags.CenterHorizontal | GravityFlags.Top); | |
frameLayout.AddView(view); | |
_adView = new AdView(activity); | |
_adView.AdUnitId = adUnitId; | |
_adView.AdSize = AdSize.Banner; | |
linearLayout.AddView(_adView); | |
frameLayout.AddView(linearLayout); | |
activity.SetContentView(frameLayout); | |
// Initiate a generic request. | |
var adRequest = new AdRequest.Builder() | |
.AddTestDevice(AdRequest.DeviceIdEmulator); | |
foreach (var id in testDeviceIds) | |
adRequest.AddTestDevice(id); | |
// Load the adView with the ad request. | |
_adView.LoadAd(adRequest.Build()); | |
_adView.Visibility = ViewStates.Gone; | |
} | |
internal static void Update(BannerAdPosition bannerAdPosition, float dt) | |
{ | |
if (bannerAdPosition == _currentBannerAdPosition) | |
return; | |
switch (bannerAdPosition) | |
{ | |
case BannerAdPosition.None: | |
_adView.Visibility = ViewStates.Gone; | |
break; | |
case BannerAdPosition.TopCenter: | |
_adView.Visibility = ViewStates.Visible; | |
break; | |
default: | |
throw new Exception(); | |
} | |
_currentBannerAdPosition = bannerAdPosition; | |
} | |
internal static void Draw(BannerAdPosition bannerAdPosition) | |
{ | |
//Do nothing | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment