package anywheresoftware.b4a.objects;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.BA.Events;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import com.adiquity.android.AdIquityAdListener;
import com.adiquity.android.AdIquityAdView;
@Version(1.0f)
@DependsOn(values={"AdiquityAndroidSDK"})
@ShortName("AdiquityAdView")
@Permissions(values={"android.permission.INTERNET"})
@Events(values={"AdRequestCompleted", "AdRequestCompletedNoAd", "AdRequestFailed"})
@ActivityObject
public class AdWrapper extends ViewWrapper<AdIquityAdView>{
public static final String ADSIZE_300x50 = AdIquityAdView.ADIQUITY_AD_UNIT_300_50;
public static final String ADSIZE_320x48 = AdIquityAdView.ADIQUITY_AD_UNIT_320_48;
public void Initialize(final BA ba, String EventName, String SiteId, String AdSize) {
AdIquityAdView ad = new AdIquityAdView(ba.context);
ad.init(SiteId, ba.activity, AdSize);
setObject(ad);
final String eventName = EventName.toLowerCase(BA.cul);
ad.setAdListener(new AdIquityAdListener() {
@Override
public void adRequestCompleted(AdIquityAdView arg0) {
ba.raiseEvent(getObject(), eventName + "_adrequestcompleted");
}
@Override
public void adRequestCompletedNoAd(AdIquityAdView arg0) {
ba.raiseEvent(getObject(), eventName + "_adrequestcompletednoad");
}
@Override
public void adRequestFailed(AdIquityAdView arg0) {
ba.raiseEvent(getObject(), eventName + "_adrequestfailed");
}
});
}
/**
* A test ad will be shown instead of a real ad.
*/
public void SetTestMode(){
getObject().setTestMode();
}
/**
* Sets the refresh rate (in seconds). The default value is 30. Set to -1 to disable automatic refreshing.
*/
public void setRefreshRate(long value) {
getObject().setRefreshTime(value);
}
/**
* Starts showing ads.
*/
public void StartAds() {
getObject().startAds();
}
/**
* Pauses the ad requests. Should be called from Activity_Pause.
*/
public void PauseAds() {
getObject().onPause();
}
/**
* Resumes ad requests. Should be called from Activity_Resume.
*/
public void ResumeAds() {
getObject().onResume();
}
}