Skip to content

Commit

Permalink
Added Rewarded Videos. Using Admob version 16.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
luc4smoreira committed Jul 30, 2020
1 parent 2a96a6b commit bf58f7d
Show file tree
Hide file tree
Showing 18 changed files with 458 additions and 137 deletions.
Binary file modified AdMob.ane
Binary file not shown.
Binary file modified AdMob64.ane
Binary file not shown.
Binary file modified air/AdMob/bin/AdMob.swc
Binary file not shown.
40 changes: 40 additions & 0 deletions air/AdMob/bin/catalog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" ?>
<swc xmlns="http://www.adobe.com/flash/swccatalog/9">
<versions>
<swc version="1.2"/>
<compiler name="ActionScript Compiler" version="2.0.0" build="354209"/>
</versions>
<features>
<feature-script-deps/>
</features>
<libraries>
<library path="library.swf">
<script name="com/pozirk/ads/admob/AdEvent" mod="1596130528420">
<def id="com.pozirk.ads.admob:AdEvent"/>
<dep id="String" type="s"/>
<dep id="flash.events:Event" type="i"/>
</script>
<script name="com/pozirk/ads/admob/AdMob" mod="1596130536361">
<def id="com.pozirk.ads.admob:AdMob"/>
<dep id="Error" type="s"/>
<dep id="Function" type="s"/>
<dep id="Number" type="s"/>
<dep id="String" type="s"/>
<dep id="com.pozirk.ads.admob:AdEvent" type="e"/>
<dep id="flash.events:EventDispatcher" type="i"/>
<dep id="flash.events:StatusEvent" type="s"/>
<dep id="flash.external:ExtensionContext" type="s"/>
<dep id="int" type="s"/>
<dep id="trace" type="e"/>
</script>
<script name="com/pozirk/ads/admob/AdParams" mod="1595968159509">
<def id="com.pozirk.ads.admob:AdParams"/>
<dep id="Object" type="i"/>
<dep id="int" type="s"/>
</script>
<digests>
<digest type="SHA-256" signed="false" value="b41360e269c8985ff57b5c800b16985f99e9c3b83df124ed8c3cf532aa375014"/>
</digests>
</library>
</libraries>
</swc>
Binary file added air/AdMob/bin/library.swf
Binary file not shown.
8 changes: 8 additions & 0 deletions air/AdMob/com/pozirk/ads/admob/AdEvent.as
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ package com.pozirk.ads.admob
public static const INTERSTITIAL_CACHE_FAIL:String = "INTERSTITIAL_CACHE_FAIL";
public static const INTERSTITIAL_OPENED:String = "INTERSTITIAL_OPENED";
public static const INTERSTITIAL_CLOSED:String = "INTERSTITIAL_CLOSED";
public static const REWARDED_CACHE_OK:String = "REWARDED_CACHE_OK";
public static const REWARDED_OPENED:String = "REWARDED_OPENED";
public static const REWARDED_CLOSED:String = "REWARDED_CLOSED";
public static const REWARDED_LEFT_APP:String = "REWARDED_LEFT_APP";
public static const REWARDED_CACHE_FAIL:String = "REWARDED_CACHE_FAIL";
public static const REWARDED_STARTED:String = "REWARDED_STARTED";
public static const REWARDED_REWARDED:String = "REWARDED_REWARDED"; //value rewardItem.getType()+"-"+rewardItem.getAmount()
public static const REWARDED_COMPLETED:String = "REWARDED_COMPLETED";

public var _data:String; //extra info about event

Expand Down
77 changes: 77 additions & 0 deletions air/AdMob/com/pozirk/ads/admob/AdMob.as
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,26 @@ package com.pozirk.ads.admob
_ctx.call("showInterstitial");
}


/**
* Cache rewarded ad, listen for AdEvent.REWARDED_CACHE_OK before showing it
* @param adID - Ad unit ID
* @param testDevice - device ID
*/
public function cacheRewarded(adID:String, testDevice:String = null):void
{
_ctx.call("cacheRewarded", adID, testDevice);
}

/**
* Show rewarded ad, if it is not cached yet, nothing will be shown
*/
public function showRewarded():void
{
_ctx.call("showRewarded");
}


/**
* Mute/unmute sound
*/
Expand Down Expand Up @@ -183,11 +203,68 @@ package com.pozirk.ads.admob
break;
}





case "REWARDED_CACHE_OK":
{
e = new AdEvent(AdEvent.REWARDED_CACHE_OK);
break;
}


case "REWARDED_OPENED":
{
e = new AdEvent(AdEvent.INTERSTITIAL_CLOSED);
break;
}

case "INTERSTITIAL_CLOSED":
{
e = new AdEvent(AdEvent.INTERSTITIAL_CLOSED);
break;
}

case "REWARDED_LEFT_APP":
{
e = new AdEvent(AdEvent.REWARDED_LEFT_APP);
break;
}

case "REWARDED_CLOSED":
{
e = new AdEvent(AdEvent.REWARDED_CLOSED);
break;
}

case "REWARDED_CACHE_FAIL":
{
e = new AdEvent(AdEvent.REWARDED_CACHE_FAIL);
break;
}

case "REWARDED_STARTED":
{
e = new AdEvent(AdEvent.REWARDED_STARTED);
break;
}

case "REWARDED_REWARDED":
{
e = new AdEvent(AdEvent.REWARDED_REWARDED, event.level); //rewardItem.getType()+"-"+rewardItem.getAmount()
break;
}

case "REWARDED_COMPLETED":
{
e = new AdEvent(AdEvent.REWARDED_COMPLETED);
break;
}




}

if(e != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.pozirk.ads.admob.function.CacheRewardedFunction;
import com.pozirk.ads.admob.function.ShowRewardedFunction;
import com.pozirk.ads.admob.manager.AdMobManager;
import com.pozirk.ads.admob.function.CacheInterstitialFunction;
import com.pozirk.ads.admob.function.DisposeFunction;
Expand Down Expand Up @@ -49,6 +51,9 @@ public Map<String, FREFunction> getFunctions()
functionMap.put("hide", new HideFunction());
functionMap.put("cacheInterstitial", new CacheInterstitialFunction());
functionMap.put("showInterstitial", new ShowInterstitialFunction());
functionMap.put("cacheRewarded", new CacheRewardedFunction());
functionMap.put("showRewarded", new ShowRewardedFunction());

functionMap.put("dispose", new DisposeFunction());
functionMap.put("setVolume", new SetVolumeFunction());

Expand All @@ -57,13 +62,7 @@ public Map<String, FREFunction> getFunctions()

public AdMobManager getAdMobMan() {
if(_adMobMan==null) {

// try {
_adMobMan = new AdMobManager(getActivity(), this);
// }
// catch(Exception e) {
// dispatchStatusEventAsync("INIT_FAIL", e.getMessage());
// }
_adMobMan = new AdMobManager(this);
}
return _adMobMan;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
import com.adobe.fre.FREObject;
import com.pozirk.ads.admob.context.ExtensionContext;

public class CacheInterstitialFunction
implements FREFunction
public class CacheInterstitialFunction implements FREFunction
{
public FREObject call(FREContext frectx, FREObject[] args)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* Copyright (c) 2014 Pozirk Games
* http://www.pozirk.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.pozirk.ads.admob.function;

import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.adobe.fre.FREObject;
import com.pozirk.ads.admob.context.ExtensionContext;

public class CacheRewardedFunction implements FREFunction
{
public FREObject call(FREContext frectx, FREObject[] args)
{
ExtensionContext ctx = (ExtensionContext)frectx;

try
{
FREObject adID = args[0];
FREObject testDevice = args[1];
ctx.getAdMobMan().cacheRewarded(adID.getAsString(), (testDevice != null ? testDevice.getAsString() : null));
}
catch(Exception e)
{
e.printStackTrace();
ctx.dispatchStatusEventAsync("REWARDED_CACHE_FAIL", e.getMessage());
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* Copyright (c) 2014 Pozirk Games
* http://www.pozirk.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.pozirk.ads.admob.function;

import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.adobe.fre.FREObject;
import com.pozirk.ads.admob.context.ExtensionContext;

public class ShowRewardedFunction
implements FREFunction
{
public FREObject call(FREContext frectx, FREObject[] args)
{
ExtensionContext ctx = (ExtensionContext)frectx;

ctx.getAdMobMan().showRewarded();

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,33 @@

import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.pozirk.ads.admob.manager.AdTypesSupportedEnum;
import com.pozirk.ads.admob.context.ExtensionContext;

public class AdMobListener extends AdListener
{
protected ExtensionContext _ctx = null;
protected String _who = null;
protected ExtensionContext _ctx ;
protected AdTypesSupportedEnum _who;

public AdMobListener(ExtensionContext ctx, String who)
public AdMobListener(ExtensionContext ctx, AdTypesSupportedEnum type)
{
_ctx = ctx;
_who = who;
_who = type;
}

@Override
public void onAdLoaded()
{
if(_who == "BANNER")
{
_ctx.getAdMobMan().bannerOnTop();
_ctx.dispatchStatusEventAsync(_who+"_SHOW_OK", "");
}
else
_ctx.dispatchStatusEventAsync(_who+"_CACHE_OK", "");
}
@Override
public void onAdLoaded()
{
if(_who == AdTypesSupportedEnum.BANNER)
{
_ctx.getAdMobMan().bannerOnTop();
_ctx.dispatchStatusEventAsync(_who.getType()+"_SHOW_OK", "");
}
else {
_ctx.dispatchStatusEventAsync(_who.getType()+"_CACHE_OK", "");
}

}

@Override
public void onAdFailedToLoad(int errorCode)
Expand All @@ -63,27 +66,29 @@ public void onAdFailedToLoad(int errorCode)
break;
}

if(_who == "BANNER")
_ctx.dispatchStatusEventAsync(_who+"_SHOW_FAIL", errorReason);
else
_ctx.dispatchStatusEventAsync(_who+"_CACHE_FAIL", errorReason);
if(_who == AdTypesSupportedEnum.BANNER) {
_ctx.dispatchStatusEventAsync(_who.getType() + "_SHOW_FAIL", errorReason);
}
else {
_ctx.dispatchStatusEventAsync(_who.getType() + "_CACHE_FAIL", errorReason);
}
}

@Override
public void onAdOpened()
{
_ctx.dispatchStatusEventAsync(_who+"_OPENED", "So, you've just earned some money, huh?");
_ctx.dispatchStatusEventAsync(_who.getType()+"_OPENED", "So, you've just earned some money, huh?");
}

@Override
public void onAdClosed()
{
_ctx.dispatchStatusEventAsync(_who+"_CLOSED", "");
_ctx.dispatchStatusEventAsync(_who.getType()+"_CLOSED", "");
}

@Override
public void onAdLeftApplication()
{
_ctx.dispatchStatusEventAsync(_who+"_LEFT_APP", "");
_ctx.dispatchStatusEventAsync(_who.getType()+"_LEFT_APP", "");
}
}
Loading

0 comments on commit bf58f7d

Please sign in to comment.