Skip to content

Commit

Permalink
Merge pull request #166 from Astrovic/master
Browse files Browse the repository at this point in the history
  • Loading branch information
cb1kenobi authored May 16, 2023
2 parents ded0459 + 2032e79 commit 51fa87e
Show file tree
Hide file tree
Showing 916 changed files with 48,272 additions and 12,617 deletions.
35 changes: 35 additions & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
tmp
bin
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
*.xcworkspace
!default.xcworkspace
xcuserdata
profile
*.moved-aside
DerivedData
.DS_Store
.project

android/libs
android/build.properties
android/dist
android/java-sources.txt
android/.gradle

ios/metadata.json
ios/ti.admob-iphone-*.zip
ios/dist/
ios/titanium.xcconfig.bak
ios/admob.xcodeproj/project.xcworkspace/xcuserdata/*

node_modules/

TESTS-*.xml
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Titanium AdMob Module
============

Use the Google Admob Module in Appcelerator Titanium.
Use the Google Admob Module in Titanium.

## Contributors

Expand All @@ -12,12 +12,13 @@ Use the Google Admob Module in Appcelerator Titanium.
* Gary Mathews
* Dawson Toth
* Hans Knöchel
* Vittorio Sorbera

Interested in contributing? Read the [contributors/committer's](https://wiki.appcelerator.org/display/community/Home) guide.
Interested in contributing? Fork and submit your PR :)

## Issues

Report issues to [Appcelerator JIRA](https://jira.appcelerator.org).
Report issues to [TiSlack](https://slack.tidev.io/).

## Legal

Expand Down
30 changes: 23 additions & 7 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
repositories {
google()
jcenter()
mavenCentral()
}

dependencies {
implementation 'com.google.android.ads.consent:consent-library:1.0.8'
implementation 'com.facebook.android:audience-network-sdk:5.6.1'
implementation 'com.google.ads.mediation:facebook:5.6.1.0'
implementation 'com.google.android.gms:play-services-base:17.1.0'
implementation 'com.google.android.gms:play-services-ads:18.3.0'
implementation 'com.google.android.gms:play-services-ads-base:18.3.0'
implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
implementation 'com.google.android.gms:play-services-ads-lite:18.3.0'
/* Facebook */
implementation 'androidx.annotation:annotation:1.0.0'
implementation 'com.facebook.android:audience-network-sdk:6.+'
implementation 'com.google.ads.mediation:facebook:6.8.0.0'
/* inMobi */
implementation 'com.inmobi.monetization:inmobi-ads:10.0.1'
implementation 'com.google.ads.mediation:inmobi:10.0.1.0'
//implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
implementation 'com.google.android.gms:play-services-location:18.0.0'//optional dependency for better targeting
/****/
implementation 'com.google.android.gms:play-services-base:17.6.0'
implementation 'com.google.android.gms:play-services-ads:20.5.0'
implementation 'com.google.android.gms:play-services-ads-base:20.5.0'
implementation 'com.google.android.gms:play-services-ads-identifier:17.1.0'
implementation 'com.google.android.gms:play-services-ads-lite:20.5.0'
implementation 'com.google.firebase:firebase-ads:20.5.0'
implementation 'com.google.firebase:firebase-ads-lite:20.5.0'
}
19 changes: 17 additions & 2 deletions android/documentation/changelog.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
# Change Log
v5.0.6 Update Google Mobile Ads SDK 19.8.0
Update Audience Network SDK 6.+
Update Facebook Adapter 6.3.0.1
Support InMobi adapter
Update InMobi SDK 9.1.7
Update InMobiAdapter 9.1.6.0
Admob.setInMobi_updateGDPRConsent()

v5.0.3 Update Google Mobile Ads SDK 19.7.0
Update Audience Network SDK 6.2.0
Update Facebook Adapter 6.2.0.1

v5.0.2 Update Google Mobile Ads SDK 19.2.0
Update Audience Network SDK 5.11.0
Update Facebook Adapter 5.11.0.0

<pre>

v4.5.0 Update APIs to match the Swift version of the iOS part of the module. Set Titanium 8.0.0 as minimum.
v4.5.0 Update APIs to match the Swift version of the iOS part of the module. Set Titanium 8.0.0 as minimum.

v4.4.0 Maintain API parity with iOS module and introduce Interstitial ads support on Android.

v4.3.0 Support the Facebook Audience Network adapter
Android integration guide: https://developers.google.com/admob/android/mediation/facebook

v4.2.1 Fix Kroll annotation for requestConsentInfoUpdateForPublisherIdentifiers.

v4.2.0 Expose getId() and isAdTrackingLimited() from AdvertisingIdClient.Info.
Expand Down
2 changes: 2 additions & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
android.useAndroidX=true
android.enableJetifier=true
2 changes: 1 addition & 1 deletion android/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# during compilation, packaging, distribution, etc.
#

version: 5.0.1
version: 5.1.0
apiversion: 4
architectures: arm64-v8a armeabi-v7a x86 x86_64
description: Titanium Admob module for Android
Expand Down
43 changes: 40 additions & 3 deletions android/src/ti/admob/AdmobModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;

import androidx.annotation.NonNull;

import com.google.ads.consent.AdProvider;
import com.google.ads.consent.ConsentForm;
import com.google.ads.consent.ConsentFormListener;
Expand All @@ -21,6 +24,10 @@
import com.google.ads.consent.ConsentStatus;
import com.google.ads.consent.DebugGeography;
import com.google.ads.mediation.admob.AdMobAdapter;
import com.google.android.gms.ads.initialization.InitializationStatus;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;
import com.inmobi.sdk.InMobiSdk;
import com.google.ads.mediation.inmobi.InMobiConsent;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.identifier.AdvertisingIdClient;
Expand All @@ -44,6 +51,8 @@
import org.appcelerator.titanium.TiBlob;
import org.appcelerator.titanium.io.TiBaseFile;
import org.appcelerator.titanium.util.TiConvert;
import org.json.JSONException;
import org.json.JSONObject;

@Kroll.module(name = "Admob", id = "ti.admob")
public class AdmobModule extends KrollModule
Expand Down Expand Up @@ -152,7 +161,12 @@ public AdmobModule()
@Kroll.method
public void initialize(String appID)
{
MobileAds.initialize(TiApplication.getInstance(), appID);
MobileAds.initialize(TiApplication.getInstance(), new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(@NonNull InitializationStatus initializationStatus) {

}
});
}

@Kroll.method
Expand Down Expand Up @@ -477,6 +491,29 @@ public KrollDict[] getAdProviders()
return result;
}

@Kroll.method
public void setInMobi_updateGDPRConsent(boolean isEnable)
{
JSONObject consentObject = new JSONObject();
try {
if (isEnable){
consentObject.put(InMobiSdk.IM_GDPR_CONSENT_AVAILABLE, true);
consentObject.put("gdpr", "1");
Log.d(TAG, "inMobi GDPR enabled");
} else {
consentObject.put(InMobiSdk.IM_GDPR_CONSENT_AVAILABLE, true);
consentObject.put("gdpr", "0");
Log.d(TAG, "inMobi GDPR disabled");
}
} catch (JSONException exception) {
Log.e(TAG, "inMobi GDPR error");
exception.printStackTrace();
return;
}

InMobiConsent.updateGDPRConsent(consentObject);
}

public static Bundle mapToBundle(Map<String, Object> map)
{
if (map == null) {
Expand Down Expand Up @@ -530,7 +567,7 @@ public static AdRequest.Builder createRequestBuilderWithOptions(KrollDict option
}
// Handle tagForChildDirectedTreatment
if (options.containsKeyAndNotNull("tagForChildDirectedTreatment")) {
adRequestBuilder.tagForChildDirectedTreatment(options.getBoolean("tagForChildDirectedTreatment"));
//adRequestBuilder.tagForChildDirectedTreatment(options.getBoolean("tagForChildDirectedTreatment"));
}
// Handle requestAgent
if (options.containsKeyAndNotNull("requestAgent")) {
Expand All @@ -540,7 +577,7 @@ public static AdRequest.Builder createRequestBuilderWithOptions(KrollDict option
if (options.containsKeyAndNotNull("testDevices")) {
String[] testDevices = options.getStringArray("testDevices");
for (int i = 0; i < testDevices.length; i++) {
adRequestBuilder.addTestDevice(testDevices[i]);
//adRequestBuilder.addTestDevice(testDevices[i]);
}
}
return adRequestBuilder;
Expand Down
4 changes: 2 additions & 2 deletions android/src/ti/admob/AdmobView.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class AdmobView extends TiUIView

AdmobSizeProxy prop_adSize = AdmobSizeEnum.BANNER.getAdmobSizeProxy();
String prop_adUnitId;
// Put these in extras bundle of laod
// Put these in extras bundle of load
Boolean prop_debugEnabled = false;
int prop_top;
int prop_left;
Expand Down Expand Up @@ -72,7 +72,7 @@ public void run()
final AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
Log.d(TAG, "requestAd(Boolean testing) -- testing:" + testing);
if (testing) {
adRequestBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
//adRequestBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
}
Bundle bundle = createAdRequestProperties();
if (bundle.size() > 0) {
Expand Down
20 changes: 10 additions & 10 deletions android/src/ti/admob/CommonAdListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@

package ti.admob;

import androidx.annotation.NonNull;

import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.LoadAdError;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.common.Log;
Expand Down Expand Up @@ -36,12 +40,11 @@ public void onAdLoaded()
}

@Override
public void onAdFailedToLoad(int errorCode)
{
super.onAdFailedToLoad(errorCode);
Log.d(this.sourceTag, "onAdFailedToLoad(): " + errorCode);
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
super.onAdFailedToLoad(loadAdError);
Log.d(this.sourceTag, "onAdFailedToLoad(): " + loadAdError);
KrollDict eventData = new KrollDict();
eventData.put("errorCode", String.valueOf(errorCode));
eventData.put("errorCode", loadAdError);
warnForDeprecatedConstant(AdmobModule.AD_NOT_RECEIVED, AdmobModule.EVENT_AD_FAIL);
this.sourceProxy.fireEvent(AdmobModule.AD_NOT_RECEIVED, eventData);
this.sourceProxy.fireEvent(AdmobModule.EVENT_AD_FAIL, eventData);
Expand All @@ -66,11 +69,8 @@ public void onAdOpened()
}

@Override
public void onAdLeftApplication()
{
super.onAdLeftApplication();
warnForDeprecatedConstant(AdmobModule.AD_LEFT_APPLICATION, AdmobModule.EVENT_AD_LEFT_APP);
this.sourceProxy.fireEvent(AdmobModule.AD_LEFT_APPLICATION, new KrollDict());
public void onAdClicked() {
super.onAdClicked();
this.sourceProxy.fireEvent(AdmobModule.EVENT_AD_LEFT_APP, new KrollDict());
}

Expand Down
44 changes: 34 additions & 10 deletions android/src/ti/admob/InterstitialAdProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@
package ti.admob;

import android.os.Bundle;

import androidx.annotation.NonNull;

import com.google.ads.mediation.admob.AdMobAdapter;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.LoadAdError;
import com.google.android.gms.ads.interstitial.InterstitialAd;
import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.annotations.Kroll;
Expand All @@ -21,20 +27,22 @@ public class InterstitialAdProxy extends KrollProxy
{

private final String TAG = "InterstitialAd";
private InterstitialAd interstitialAd;
private InterstitialAd mInterstitialAd;
String adId = "";

public InterstitialAdProxy()
{
this.interstitialAd = new InterstitialAd(getActivity());
this.interstitialAd.setAdListener(new CommonAdListener(this, TAG));
//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));
//this.interstitialAd.setAdUnitId(dict.getString(AdmobModule.PROPERTY_AD_UNIT_ID));
adId = dict.getString(AdmobModule.PROPERTY_AD_UNIT_ID);
}
}

Expand All @@ -46,7 +54,7 @@ public void setAdUnitId(String adUnitId)
{
// Validate the parameter
if (adUnitId != null && adUnitId instanceof String) {
this.interstitialAd.setAdUnitId(adUnitId);
//
}
}

Expand All @@ -56,21 +64,37 @@ public void setAdUnitId(String adUnitId)
public String getAdUnitId()
// clang format on
{
return this.interstitialAd.getAdUnitId();
return mInterstitialAd.getAdUnitId();
}

@Kroll.method
public void load(@Kroll.argument(optional = true) KrollDict options)
{
AdRequest.Builder adRequestBuilder = AdmobModule.createRequestBuilderWithOptions(options);
interstitialAd.loadAd(adRequestBuilder.build());
mInterstitialAd.load(getActivity(), adId, adRequestBuilder.build(), new InterstitialAdLoadCallback() {
@Override
public void onAdLoaded(@NonNull InterstitialAd interstitialAd) {
super.onAdLoaded(interstitialAd);
mInterstitialAd = interstitialAd;
fireEvent(AdmobModule.EVENT_AD_LOAD, new KrollDict());
}

@Override
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
super.onAdFailedToLoad(loadAdError);
mInterstitialAd = null;
KrollDict eventData = new KrollDict();
eventData.put("errorCode", loadAdError);
fireEvent(AdmobModule.EVENT_AD_FAIL, eventData);
}
});
}

@Kroll.method
public void show()
{
if (this.interstitialAd.isLoaded()) {
this.interstitialAd.show();
if (this.mInterstitialAd != null) {
this.mInterstitialAd.show(getActivity());
} else {
Log.w(TAG, "Trying to show an ad that has not been loaded.");
}
Expand Down
Loading

0 comments on commit 51fa87e

Please sign in to comment.