using System;
using UnityEngine;
namespace AdUnion
{
/*
* 4399广告联盟Banner
*/
public class AdUnionBanner
{
private static int MATCH_PARENT = -1;
private static int WRAP_CONTENT = -2;
private static int GRAVITY_TOP = 48;
private static int GRAVITY_BOTTOM = 80;
//广告位ID
private string posId;
public AdUnionBanner(string posId)
{
this.posId = posId;
}
/*
* 加载banner广告
*/
public void loadBanner()
{
Debug.Log("loadBanner---");
AndroidJavaObject banner = new AndroidJavaObject("com.mob4399.adunion.AdUnionBanner");
OnAuBannerAdListenerProxy listener
= new OnAuBannerAdListenerProxy(AdUnionContext.GetInstance().GetRootLayout());
//加载广告
banner.Call("loadBanner",
AdUnionContext.GetInstance().GetActivity(), posId, listener);
}
/*
* Banner广告回调方法
*/
class OnAuBannerAdListenerProxy : AndroidJavaProxy
{
private AndroidJavaObject parentContainer;
public OnAuBannerAdListenerProxy(AndroidJavaObject parent) : base("com.mob4399.adunion.listener.OnAuBannerAdListener")
{
this.parentContainer = parent;
}
/*
* 加载成功,返回广告view
*/
void onBannerLoaded(AndroidJavaObject mBannerView)
{
Debug.Log("Banner loaded");
AdUnionContext.GetInstance().RunOnUIThread(new AndroidJavaRunnable(() =>
{
//广告添加到容器中
AndroidJavaObject layoutParams = null;
layoutParams = new AndroidJavaObject("android.widget.FrameLayout$LayoutParams",
MATCH_PARENT, WRAP_CONTENT, GRAVITY_BOTTOM);
//add banner to parent container
parentContainer.Call("addView", mBannerView, layoutParams);
if (ADSMgr.Inst.curView != null)
{
ADSMgr.Inst.curView.Call("setVisibility", 8);
parentContainer.Call("removeView", ADSMgr.Inst.curView);
}
ADSMgr.Inst.curView = mBannerView;
//mBannerView.Call("setVisibility",8);
}));
}
/**
* 加载失败
* @param message
*/
void onBannerFailed()
{
Debug.Log("Banner onInterstitialLoadFailed");
}
/**
*广告被点击
*/
void onBannerClicked()
{
}
/**
* 广告关闭
*/
void onBannerClosed()
{
Debug.Log("close Banner");
}
}
}
}