@ShortName("AdView")
@Events(values={"ReceiveAd", "FailedToReceiveAd (ErrorCode As String)",
"AdScreenDismissed", "PresentScreen"})
@ActivityObject
@DontInheritEvents
@Permissions(values={"android.permission.INTERNET", "android.permission.ACCESS_NETWORK_STATE"})
@DependsOn(values={"GoogleAdMobAdsSdk"})
public class AdViewWrapper extends ViewWrapper<AdView> {
/**
* 320dip x 50dip (default size)
*/
public static Object SIZE_BANNER = AdSize.BANNER;
/**
* 468dip x 60dip - tablet only
*/
public static Object SIZE_IAB_BANNER = AdSize.IAB_BANNER;
/**
* 728dip x 90dip - tablet only
*/
public static Object SIZE_IAB_LEADERBOARD = AdSize.IAB_LEADERBOARD;
/**
* 300dip x 250dip - tablet only
*/
public static Object SIZE_IAB_MRECT = AdSize.IAB_MRECT;
/**
* Initializes the AdView using the default 320dip x 50dip size.
*EventName - Name of Subs that will handle the events.
*PublisherId - The publisher id you received from AdMob.
*/
public void Initialize(final BA ba, String EventName, String PublisherId) {
Initialize2(ba, EventName, PublisherId, AdSize.BANNER);
}
/**
* Initializes the AdView.
*EventName - Name of Subs that will handle the events.
*PublisherId - The publisher id you received from AdMob.
*Size - One of the SIZE constants.
*/
public void Initialize2(final BA ba, String EventName, String PublisherId, Object Size) {
setObject(new AdView(ba.activity, (AdSize)Size, PublisherId));
super.Initialize(ba, EventName);
final String eventName = EventName.toLowerCase(BA.cul);
getObject().setAdListener(new AdListener() {
@Override
public void onFailedToReceiveAd(Ad ad, AdRequest.ErrorCode e){
ba.raiseEvent(getObject(), eventName + "_failedtoreceivead", e.toString());
}
@Override
public void onReceiveAd(Ad ad) {
ba.raiseEvent(getObject(), eventName + "_receivead");
}
@Override
public void onDismissScreen(Ad arg0) {
ba.raiseEventFromDifferentThread(getObject(), null, 0, eventName + "_adscreendismissed", false, null);
}
@Override
public void onLeaveApplication(Ad arg0) {
//
}
@Override
public void onPresentScreen(Ad arg0) {
ba.raiseEventFromDifferentThread(getObject(), null, 0, eventName + "_presentscreen", false, null);
}
});
}
/**
* Sends a request to AdMob, requesting an ad.
*/
public void LoadAd() {
AdRequest req = new AdRequest();
req.setTesting(true);
getObject().loadAd(req);
}
}