-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Interstitial ads as a new proxy.
Remove some duplications.
- Loading branch information
Showing
6 changed files
with
287 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* Copyright (c) 2011 by Studio Classics. All Rights Reserved. | ||
* Copyright (c) 2017-present by Axway Appcelerator. All Rights Reserved. | ||
* Licensed under the terms of the Apache Public License | ||
* Please see the LICENSE included with this distribution for details. | ||
*/ | ||
|
||
package ti.admob; | ||
|
||
import com.google.android.gms.ads.AdListener; | ||
|
||
import org.appcelerator.kroll.KrollDict; | ||
import org.appcelerator.kroll.KrollProxy; | ||
import org.appcelerator.kroll.common.Log; | ||
|
||
public class CommonAdListener extends AdListener { | ||
|
||
private KrollProxy sourceProxy; | ||
private String sourceTag; | ||
|
||
public CommonAdListener(KrollProxy sourceProxy, String tag) { | ||
this.sourceProxy = sourceProxy; | ||
this.sourceTag = tag; | ||
} | ||
|
||
@Override | ||
public void onAdLoaded() { | ||
Log.d(this.sourceTag, "onAdLoaded()"); | ||
this.sourceProxy.fireEvent(AdmobModule.AD_RECEIVED, new KrollDict()); | ||
} | ||
|
||
@Override | ||
public void onAdFailedToLoad(int errorCode) | ||
{ | ||
super.onAdFailedToLoad(errorCode); | ||
Log.d(this.sourceTag, "onAdFailedToLoad(): " + errorCode); | ||
KrollDict eventData = new KrollDict(); | ||
eventData.put("errorCode", String.valueOf(errorCode)); | ||
this.sourceProxy.fireEvent(AdmobModule.AD_NOT_RECEIVED, eventData); | ||
} | ||
|
||
@Override | ||
public void onAdClosed() { | ||
super.onAdClosed(); | ||
this.sourceProxy.fireEvent(AdmobModule.AD_CLOSED, new KrollDict()); | ||
} | ||
|
||
@Override | ||
public void onAdOpened() { | ||
super.onAdOpened(); | ||
this.sourceProxy.fireEvent(AdmobModule.AD_OPENED, new KrollDict()); | ||
} | ||
|
||
@Override | ||
public void onAdLeftApplication() { | ||
super.onAdLeftApplication(); | ||
this.sourceProxy.fireEvent(AdmobModule.AD_LEFT_APPLICATION, new KrollDict()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* Copyright (c) 2011 by Studio Classics. All Rights Reserved. | ||
* Copyright (c) 2017-present by Axway Appcelerator. All Rights Reserved. | ||
* Licensed under the terms of the Apache Public License | ||
* Please see the LICENSE included with this distribution for details. | ||
*/ | ||
|
||
package ti.admob; | ||
|
||
import com.google.android.gms.ads.AdRequest; | ||
import com.google.android.gms.ads.InterstitialAd; | ||
|
||
import org.appcelerator.kroll.KrollDict; | ||
import org.appcelerator.kroll.KrollProxy; | ||
import org.appcelerator.kroll.annotations.Kroll; | ||
import org.appcelerator.kroll.common.Log; | ||
|
||
@Kroll.proxy(creatableInModule = AdmobModule.class) | ||
public class InterstitialAdProxy extends KrollProxy { | ||
|
||
private final String TAG = "InterstitialAd"; | ||
private InterstitialAd interstitialAd; | ||
|
||
public InterstitialAdProxy() { | ||
this.interstitialAd = new InterstitialAd(getActivity()); | ||
this.interstitialAd.setAdListener(new CommonAdListener(this, TAG)); | ||
} | ||
|
||
@Override | ||
public void handleCreationDict(KrollDict dict) { | ||
super.handleCreationDict(dict); | ||
if (dict.containsKeyAndNotNull(AdmobModule.PROPERTY_AD_UNIT_ID)) { | ||
this.interstitialAd.setAdUnitId(dict.getString(AdmobModule.PROPERTY_AD_UNIT_ID)); | ||
} | ||
} | ||
|
||
// clang format off | ||
@Kroll.method | ||
@Kroll.setProperty | ||
public void setAdUnitId(String adUnitId) | ||
// clang format on | ||
{ | ||
// Validate the parameter | ||
if (adUnitId != null && adUnitId instanceof String) { | ||
this.interstitialAd.setAdUnitId(adUnitId); | ||
} | ||
} | ||
|
||
// clang format off | ||
@Kroll.method | ||
@Kroll.getProperty | ||
public String getAdUnitId() | ||
// clang format on | ||
{ | ||
return this.interstitialAd.getAdUnitId(); | ||
} | ||
|
||
@Kroll.method | ||
public void load() | ||
{ | ||
this.interstitialAd.loadAd(new AdRequest.Builder().build()); | ||
} | ||
|
||
@Kroll.method | ||
public void show() | ||
{ | ||
if (this.interstitialAd.isLoaded()) { | ||
this.interstitialAd.show(); | ||
} else { | ||
Log.w(TAG, "Trying to show an ad that has not been loaded."); | ||
} | ||
} | ||
} |
Oops, something went wrong.