Skip to content

Commit

Permalink
Merge pull request #4 from nyancodeid/v1.2.0
Browse files Browse the repository at this point in the history
v1.2.0 - Update for latest SDK version 4.1.0
  • Loading branch information
lreiner authored Sep 3, 2019
2 parents 13c288d + 3171c0f commit ec49ffc
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 10 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ document.addEventListener('startappads.interstitial.load_fail', () => {
//do something here
});
```
#### IMPORTANT:
```
Do not call `showInterstitial()` from within `load_fail` event. The SDK will automatically try to reload an ad upon a failure.
```

### 5. Show Rewarded Video Ads
Show a Rewarded Video Ad:
Expand All @@ -127,6 +131,16 @@ document.addEventListener('startappads.reward_video.load', () => {
//do something here
});

document.addEventListener('startappads.reward_video.closed', () => {
//user closed video reward
//do something here
});

document.addEventListener('startappads.reward_video.clicked', () => {
//user click on video reward
//do something here
});

document.addEventListener('startappads.reward_video.load_fail', () => {
//reward video failed to load. Probably no Ads available at the moment
//do something here
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@
</feature>
</config-file>
<source-file src="src/android/StartAppAdsPlugin.java" target-dir="src/startapp/ads/" />
<source-file src="src/android/StartAppInApp-4.0.2.jar" target-dir="libs" />
<source-file src="src/android/StartAppInApp-4.1.0.jar" target-dir="libs" />
</platform>
</plugin>
62 changes: 55 additions & 7 deletions src/android/StartAppAdsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class StartAppAdsPlugin extends CordovaPlugin {
private CordovaWebView cWebView;
private ViewGroup parentView;
private Banner startAppBanner;
private StartAppAd rewardedVideo = null;

public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
Expand All @@ -49,7 +50,11 @@ public boolean execute(String action, JSONArray args, final CallbackContext call
if (action.equals("initStartApp")) {
cordova.getActivity().runOnUiThread(new Runnable() {
public void run() {
initStartApp(PUBLIC_CALLBACKS, args.optString(0));
String appId = args.optString(0);
boolean disableReturnAd = args.optBoolean(1);
boolean disableSplashAd = args.optBoolean(2);

initStartApp(appId, disableReturnAd, disableSplashAd, PUBLIC_CALLBACKS);
}
});
return true;
Expand Down Expand Up @@ -78,6 +83,15 @@ public void run() {
});
return true;
}
else if(action.equals("loadRewardVideo")) {
cordova.getActivity().runOnUiThread(new Runnable() {
public void run() {
boolean autoShow = args.optBoolean(0);
loadRewardVideo(autoShow, PUBLIC_CALLBACKS);
}
});
return true;
}
else if(action.equals("showRewardVideo")) {
cordova.getActivity().runOnUiThread(new Runnable() {
public void run() {
Expand All @@ -89,11 +103,15 @@ public void run() {
return false;
}

public void initStartApp(CallbackContext callbackContext, String appID) {
Log.d(TAG, "Initializing StartApp SDK with ID: " + appID);
public void initStartApp(String appID, Boolean disableReturnAd, Boolean disableSplashAd, CallbackContext callbackContext) {
Log.d(TAG, "Initializing StartApp SDK with ID: " + appID + " ReturnAd: " + disableReturnAd + " SplashAd: " + disableSplashAd);
startAppAd = new StartAppAd(cordova.getActivity());
StartAppSDK.init(cordova.getActivity(), appID, true);
StartAppSDK.init(cordova.getActivity(), appID, disableReturnAd);
StartAppSDK.setUserConsent(cordova.getActivity(), "pas", System.currentTimeMillis(), false);

if (disableSplashAd) {
StartAppAd.disableSplash();
}
}

public void showBanner(CallbackContext callbackContext) {
Expand Down Expand Up @@ -188,8 +206,8 @@ public void onFailedToReceiveAd(Ad ad) {
});
}

public void showRewardVideo(CallbackContext callbackContext) {
final StartAppAd rewardedVideo = new StartAppAd(cordova.getActivity());
public void loadRewardVideo(Boolean autoShow, CallbackContext callbackContext) {
rewardedVideo = new StartAppAd(cordova.getActivity());

rewardedVideo.setVideoListener(new VideoListener() {
@Override
Expand All @@ -204,7 +222,11 @@ public void onVideoCompleted() {
public void onReceiveAd(Ad arg0) {
Log.d(TAG, "Reward Video loaded!");
cWebView.loadUrl("javascript:cordova.fireDocumentEvent('startappads.reward_video.load');");
rewardedVideo.showAd();

if (autoShow) {
Log.d(TAG, "Video Reward auto show!");
rewardedVideo.showAd();
}
}

@Override
Expand All @@ -214,4 +236,30 @@ public void onFailedToReceiveAd(Ad arg0) {
}
});
}

public void showRewardVideo(CallbackContext callbackContext) {
if (rewardedVideo != null) {
Log.d(TAG, "Reward Video show now!");
rewardedVideo.showAd(new AdDisplayListener() {
@Override
public void adHidden(Ad ad) {
Log.d(TAG, "Rewarded Video closed!");
cWebView.loadUrl("javascript:cordova.fireDocumentEvent('startappads.reward_video.closed');");
}
@Override
public void adClicked(Ad ad) {
Log.d(TAG, "Rewarded Video clicked!");
cWebView.loadUrl("javascript:cordova.fireDocumentEvent('startappads.reward_video.clicked');");
}
@Override
public void adDisplayed(Ad ad) {
}
@Override
public void adNotDisplayed(Ad ad) {
}
});
} else {
Log.d(TAG, "Video Reward need to load before call it!");
}
}
}
Binary file removed src/android/StartAppInApp-4.0.2.jar
Binary file not shown.
Binary file added src/android/StartAppInApp-4.1.0.jar
Binary file not shown.
13 changes: 11 additions & 2 deletions www/startappads.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ var cordova = require('cordova');
var exec = require('cordova/exec');

var StartAppAds = {
init: function(appid) {
exec(function(){}, function(){}, "StartAppAdsPlugin", "initStartApp", [appid]);
init: function(appid, options) {
var DEFAULT_OPTIONS = { returnAd: true, splashAd: true };

if (typeof options !== "object") { options = DEFAULT_OPTIONS; }
options = Object.assign(DEFAULT_OPTIONS, options);

exec(function(){}, function(){}, "StartAppAdsPlugin", "initStartApp", [appid, !options.returnAd, !options.splashAd]);
},
showBanner: function() {
exec(function(){}, function(){}, "StartAppAdsPlugin", "showBanner", []);
Expand All @@ -14,6 +19,10 @@ var StartAppAds = {
showInterstitial: function() {
exec(function(){}, function(){}, "StartAppAdsPlugin", "showInterstitial", []);
},
loadRewardVideo: function(autoShow) {
autoShow = (typeof autoShow === "boolean") ? autoShow : true;
exec(function(){}, function(){}, "StartAppAdsPlugin", "loadRewardVideo", [ autoShow ]);
},
showRewardVideo: function() {
exec(function(){}, function(){}, "StartAppAdsPlugin", "showRewardVideo", []);
}
Expand Down

0 comments on commit ec49ffc

Please sign in to comment.