cordova-admob-tomitank 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -0
- package/README.md +17 -0
- package/esm/admob.d.ts +3 -0
- package/esm/admob.js +22 -0
- package/esm/admob.js.map +1 -0
- package/esm/api.d.ts +61 -0
- package/esm/api.js +232 -0
- package/esm/api.js.map +1 -0
- package/esm/app-open.d.ts +17 -0
- package/esm/app-open.js +83 -0
- package/esm/app-open.js.map +1 -0
- package/esm/banner.d.ts +33 -0
- package/esm/banner.js +143 -0
- package/esm/banner.js.map +1 -0
- package/esm/generated.d.ts +77 -0
- package/esm/generated.js +104 -0
- package/esm/generated.js.map +1 -0
- package/esm/index.d.ts +31 -0
- package/esm/index.js +95 -0
- package/esm/index.js.map +1 -0
- package/esm/interstitial.d.ts +7 -0
- package/esm/interstitial.js +35 -0
- package/esm/interstitial.js.map +1 -0
- package/esm/native.d.ts +19 -0
- package/esm/native.js +134 -0
- package/esm/native.js.map +1 -0
- package/esm/rewarded-interstitial.d.ts +10 -0
- package/esm/rewarded-interstitial.js +35 -0
- package/esm/rewarded-interstitial.js.map +1 -0
- package/esm/rewarded.d.ts +14 -0
- package/esm/rewarded.js +35 -0
- package/esm/rewarded.js.map +1 -0
- package/esm/shared.d.ts +2 -0
- package/esm/shared.js +3 -0
- package/esm/shared.js.map +1 -0
- package/lib/admob.d.ts +3 -0
- package/lib/admob.js +50 -0
- package/lib/admob.js.map +1 -0
- package/lib/api.d.ts +61 -0
- package/lib/api.js +240 -0
- package/lib/api.js.map +1 -0
- package/lib/app-open.d.ts +17 -0
- package/lib/app-open.js +85 -0
- package/lib/app-open.js.map +1 -0
- package/lib/banner.d.ts +33 -0
- package/lib/banner.js +145 -0
- package/lib/banner.js.map +1 -0
- package/lib/generated.d.ts +77 -0
- package/lib/generated.js +110 -0
- package/lib/generated.js.map +1 -0
- package/lib/index.d.ts +31 -0
- package/lib/index.js +120 -0
- package/lib/index.js.map +1 -0
- package/lib/interstitial.d.ts +7 -0
- package/lib/interstitial.js +37 -0
- package/lib/interstitial.js.map +1 -0
- package/lib/native.d.ts +19 -0
- package/lib/native.js +136 -0
- package/lib/native.js.map +1 -0
- package/lib/rewarded-interstitial.d.ts +10 -0
- package/lib/rewarded-interstitial.js +37 -0
- package/lib/rewarded-interstitial.js.map +1 -0
- package/lib/rewarded.d.ts +14 -0
- package/lib/rewarded.js +37 -0
- package/lib/rewarded.js.map +1 -0
- package/lib/shared.d.ts +2 -0
- package/lib/shared.js +19 -0
- package/lib/shared.js.map +1 -0
- package/package.json +73 -0
- package/plugin.xml +333 -0
- package/scripts/iosNSAppTransportSecurity.js +29 -0
- package/scripts/iosNSAppTransportSecurity.ts +33 -0
- package/scripts/tsconfig.json +5 -0
- package/scripts/util.js +34 -0
- package/scripts/util.ts +44 -0
- package/src/android/cordova/AdMob.java +256 -0
- package/src/android/cordova/ExecuteContext.java +174 -0
- package/src/android/cordova/Generated.java +72 -0
- package/src/android/cordova/ads/AdBase.java +54 -0
- package/src/android/cordova/ads/AppOpen.java +98 -0
- package/src/android/cordova/ads/Banner.java +370 -0
- package/src/android/cordova/ads/Interstitial.java +101 -0
- package/src/android/cordova/ads/Native.java +162 -0
- package/src/android/cordova/ads/Rewarded.java +108 -0
- package/src/android/cordova/ads/RewardedInterstitial.java +108 -0
- package/src/android/core/Ad.java +73 -0
- package/src/android/core/Context.java +186 -0
- package/src/android/core/GenericAd.java +22 -0
- package/src/android/core/Helper.java +134 -0
- package/src/browser/AdMobProxy.js +33 -0
- package/src/ios/AMBAdBase.swift +72 -0
- package/src/ios/AMBAppOpenAd.swift +87 -0
- package/src/ios/AMBBanner.swift +294 -0
- package/src/ios/AMBContext.swift +166 -0
- package/src/ios/AMBCore.swift +232 -0
- package/src/ios/AMBGenerated.swift +45 -0
- package/src/ios/AMBInterstitial.swift +69 -0
- package/src/ios/AMBNativeAd.swift +128 -0
- package/src/ios/AMBPlugin.swift +198 -0
- package/src/ios/AMBRewarded.swift +72 -0
- package/src/ios/AMBRewardedInterstitial.swift +72 -0
- package/src/www/admob.ts +26 -0
- package/src/www/api.ts +156 -0
- package/src/www/app-open.ts +27 -0
- package/src/www/banner.ts +102 -0
- package/src/www/cordova.d.ts +9 -0
- package/src/www/generated.ts +125 -0
- package/src/www/index.ts +88 -0
- package/src/www/interstitial.ts +17 -0
- package/src/www/native.ts +54 -0
- package/src/www/rewarded-interstitial.ts +20 -0
- package/src/www/rewarded.ts +26 -0
- package/src/www/shared.ts +2 -0
- package/www/admob.js +675 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
package admob.plus.cordova.ads;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
5
|
+
import com.google.android.gms.ads.AdError;
|
|
6
|
+
import com.google.android.gms.ads.AdRequest;
|
|
7
|
+
import com.google.android.gms.ads.FullScreenContentCallback;
|
|
8
|
+
import com.google.android.gms.ads.LoadAdError;
|
|
9
|
+
import com.google.android.gms.ads.rewarded.RewardedAd;
|
|
10
|
+
import com.google.android.gms.ads.rewarded.RewardedAdLoadCallback;
|
|
11
|
+
import com.google.android.gms.ads.rewarded.ServerSideVerificationOptions;
|
|
12
|
+
|
|
13
|
+
import admob.plus.cordova.ExecuteContext;
|
|
14
|
+
import admob.plus.cordova.Generated.Events;
|
|
15
|
+
import admob.plus.core.Context;
|
|
16
|
+
|
|
17
|
+
public class Rewarded extends AdBase {
|
|
18
|
+
private RewardedAd mAd = null;
|
|
19
|
+
|
|
20
|
+
public Rewarded(ExecuteContext ctx) {
|
|
21
|
+
super(ctx);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@Override
|
|
25
|
+
public void onDestroy() {
|
|
26
|
+
clear();
|
|
27
|
+
|
|
28
|
+
super.onDestroy();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@Override
|
|
32
|
+
public void load(Context ctx) {
|
|
33
|
+
clear();
|
|
34
|
+
|
|
35
|
+
RewardedAd.load(getActivity(), adUnitId, adRequest, new RewardedAdLoadCallback() {
|
|
36
|
+
@Override
|
|
37
|
+
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
|
|
38
|
+
mAd = null;
|
|
39
|
+
emit(Events.AD_LOAD_FAIL, loadAdError);
|
|
40
|
+
emit(Events.REWARDED_LOAD_FAIL, loadAdError);
|
|
41
|
+
ctx.reject(loadAdError.toString());
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@Override
|
|
45
|
+
public void onAdLoaded(@NonNull RewardedAd rewardedAd) {
|
|
46
|
+
mAd = rewardedAd;
|
|
47
|
+
ServerSideVerificationOptions ssv = ctx.optServerSideVerificationOptions();
|
|
48
|
+
if (ssv != null) {
|
|
49
|
+
mAd.setServerSideVerificationOptions(ssv);
|
|
50
|
+
}
|
|
51
|
+
mAd.setFullScreenContentCallback(new FullScreenContentCallback() {
|
|
52
|
+
@Override
|
|
53
|
+
public void onAdDismissedFullScreenContent() {
|
|
54
|
+
emit(Events.AD_DISMISS);
|
|
55
|
+
emit(Events.REWARDED_DISMISS);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@Override
|
|
59
|
+
public void onAdFailedToShowFullScreenContent(AdError adError) {
|
|
60
|
+
emit(Events.AD_SHOW_FAIL, adError);
|
|
61
|
+
emit(Events.REWARDED_SHOW_FAIL, adError);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@Override
|
|
65
|
+
public void onAdShowedFullScreenContent() {
|
|
66
|
+
clear();
|
|
67
|
+
emit(Events.AD_SHOW);
|
|
68
|
+
emit(Events.REWARDED_SHOW);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@Override
|
|
72
|
+
public void onAdImpression() {
|
|
73
|
+
emit(Events.AD_IMPRESSION);
|
|
74
|
+
emit(Events.REWARDED_IMPRESSION);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
emit(Events.AD_LOAD);
|
|
79
|
+
emit(Events.REWARDED_LOAD);
|
|
80
|
+
ctx.resolve();
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@Override
|
|
86
|
+
public boolean isLoaded() {
|
|
87
|
+
return mAd != null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
@Override
|
|
91
|
+
public void show(Context ctx) {
|
|
92
|
+
if (isLoaded()) {
|
|
93
|
+
mAd.show(getActivity(), rewardItem -> {
|
|
94
|
+
emit(Events.AD_REWARD, rewardItem);
|
|
95
|
+
emit(Events.REWARDED_REWARD, rewardItem);
|
|
96
|
+
});
|
|
97
|
+
ctx.resolve();
|
|
98
|
+
} else {
|
|
99
|
+
ctx.reject("Ad is not loaded");
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private void clear() {
|
|
104
|
+
if (mAd != null) {
|
|
105
|
+
mAd = null;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
package admob.plus.cordova.ads;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
5
|
+
import com.google.android.gms.ads.AdError;
|
|
6
|
+
import com.google.android.gms.ads.AdRequest;
|
|
7
|
+
import com.google.android.gms.ads.FullScreenContentCallback;
|
|
8
|
+
import com.google.android.gms.ads.LoadAdError;
|
|
9
|
+
import com.google.android.gms.ads.rewarded.ServerSideVerificationOptions;
|
|
10
|
+
import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAd;
|
|
11
|
+
import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAdLoadCallback;
|
|
12
|
+
|
|
13
|
+
import admob.plus.cordova.ExecuteContext;
|
|
14
|
+
import admob.plus.cordova.Generated.Events;
|
|
15
|
+
import admob.plus.core.Context;
|
|
16
|
+
|
|
17
|
+
public class RewardedInterstitial extends AdBase {
|
|
18
|
+
private RewardedInterstitialAd mAd = null;
|
|
19
|
+
|
|
20
|
+
public RewardedInterstitial(ExecuteContext ctx) {
|
|
21
|
+
super(ctx);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@Override
|
|
25
|
+
public void onDestroy() {
|
|
26
|
+
clear();
|
|
27
|
+
|
|
28
|
+
super.onDestroy();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@Override
|
|
32
|
+
public void load(Context ctx) {
|
|
33
|
+
clear();
|
|
34
|
+
|
|
35
|
+
RewardedInterstitialAd.load(getActivity(), adUnitId, adRequest, new RewardedInterstitialAdLoadCallback() {
|
|
36
|
+
@Override
|
|
37
|
+
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
|
|
38
|
+
mAd = null;
|
|
39
|
+
emit(Events.AD_LOAD_FAIL, loadAdError);
|
|
40
|
+
emit(Events.REWARDED_INTERSTITIAL_LOAD_FAIL, loadAdError);
|
|
41
|
+
ctx.reject(loadAdError.toString());
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@Override
|
|
45
|
+
public void onAdLoaded(@NonNull RewardedInterstitialAd rewardedAd) {
|
|
46
|
+
mAd = rewardedAd;
|
|
47
|
+
ServerSideVerificationOptions ssv = ctx.optServerSideVerificationOptions();
|
|
48
|
+
if (ssv != null) {
|
|
49
|
+
mAd.setServerSideVerificationOptions(ssv);
|
|
50
|
+
}
|
|
51
|
+
mAd.setFullScreenContentCallback(new FullScreenContentCallback() {
|
|
52
|
+
@Override
|
|
53
|
+
public void onAdDismissedFullScreenContent() {
|
|
54
|
+
emit(Events.AD_DISMISS);
|
|
55
|
+
emit(Events.REWARDED_INTERSTITIAL_DISMISS);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@Override
|
|
59
|
+
public void onAdFailedToShowFullScreenContent(AdError adError) {
|
|
60
|
+
emit(Events.AD_SHOW_FAIL, adError);
|
|
61
|
+
emit(Events.REWARDED_INTERSTITIAL_SHOW_FAIL, adError);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@Override
|
|
65
|
+
public void onAdShowedFullScreenContent() {
|
|
66
|
+
mAd = null;
|
|
67
|
+
emit(Events.AD_SHOW);
|
|
68
|
+
emit(Events.REWARDED_INTERSTITIAL_SHOW);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@Override
|
|
72
|
+
public void onAdImpression() {
|
|
73
|
+
emit(Events.AD_IMPRESSION);
|
|
74
|
+
emit(Events.REWARDED_INTERSTITIAL_IMPRESSION);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
emit(Events.AD_LOAD);
|
|
79
|
+
emit(Events.REWARDED_INTERSTITIAL_LOAD);
|
|
80
|
+
ctx.resolve();
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@Override
|
|
86
|
+
public boolean isLoaded() {
|
|
87
|
+
return mAd != null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
@Override
|
|
91
|
+
public void show(Context ctx) {
|
|
92
|
+
if (isLoaded()) {
|
|
93
|
+
mAd.show(getActivity(), rewardItem -> {
|
|
94
|
+
emit(Events.AD_REWARD, rewardItem);
|
|
95
|
+
emit(Events.REWARDED_INTERSTITIAL_REWARD, rewardItem);
|
|
96
|
+
});
|
|
97
|
+
ctx.resolve();
|
|
98
|
+
} else {
|
|
99
|
+
ctx.reject("Ad is not loaded");
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private void clear() {
|
|
104
|
+
if (mAd != null) {
|
|
105
|
+
mAd = null;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
package admob.plus.core;
|
|
2
|
+
|
|
3
|
+
import android.app.Activity;
|
|
4
|
+
import android.view.ViewGroup;
|
|
5
|
+
|
|
6
|
+
import androidx.annotation.NonNull;
|
|
7
|
+
import androidx.annotation.Nullable;
|
|
8
|
+
|
|
9
|
+
import com.google.android.gms.ads.AdError;
|
|
10
|
+
import com.google.android.gms.ads.rewarded.RewardItem;
|
|
11
|
+
|
|
12
|
+
import java.util.HashMap;
|
|
13
|
+
import java.util.Map;
|
|
14
|
+
import java.util.Objects;
|
|
15
|
+
|
|
16
|
+
import static admob.plus.core.Helper.ads;
|
|
17
|
+
|
|
18
|
+
public abstract class Ad {
|
|
19
|
+
public final int id;
|
|
20
|
+
public final String adUnitId;
|
|
21
|
+
|
|
22
|
+
public Ad(int id, @NonNull String adUnitId) {
|
|
23
|
+
this.id = id;
|
|
24
|
+
this.adUnitId = adUnitId;
|
|
25
|
+
ads.put(id, this);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public Ad(Context ctx) {
|
|
29
|
+
this(Objects.requireNonNull(ctx.optId()), Objects.requireNonNull(ctx.optAdUnitID()));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public void destroy() {
|
|
33
|
+
ads.remove(id);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
protected abstract Helper.Adapter getAdapter();
|
|
37
|
+
|
|
38
|
+
public Activity getActivity() {
|
|
39
|
+
return getAdapter().getActivity();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Nullable
|
|
43
|
+
public ViewGroup getContentView() {
|
|
44
|
+
return getActivity().findViewById(android.R.id.content);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
protected void emit(String eventName) {
|
|
48
|
+
this.emit(eventName, new HashMap<String, Object>());
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
protected void emit(String eventName, AdError error) {
|
|
52
|
+
this.emit(eventName, new HashMap<String, Object>() {{
|
|
53
|
+
put("code", error.getCode());
|
|
54
|
+
put("message", error.getMessage());
|
|
55
|
+
put("cause", error.getCause());
|
|
56
|
+
}});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
protected void emit(String eventName, RewardItem rewardItem) {
|
|
60
|
+
this.emit(eventName, new HashMap<String, Object>() {{
|
|
61
|
+
put("reward", new HashMap<String, Object>() {{
|
|
62
|
+
put("amount", rewardItem.getAmount());
|
|
63
|
+
put("type", rewardItem.getType());
|
|
64
|
+
}});
|
|
65
|
+
}});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
protected void emit(String eventName, Map<String, Object> data) {
|
|
69
|
+
getAdapter().emit(eventName, new HashMap<String, Object>(data) {{
|
|
70
|
+
put("adId", id);
|
|
71
|
+
}});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
package admob.plus.core;
|
|
2
|
+
|
|
3
|
+
import android.os.Bundle;
|
|
4
|
+
|
|
5
|
+
import androidx.annotation.NonNull;
|
|
6
|
+
import androidx.annotation.Nullable;
|
|
7
|
+
|
|
8
|
+
import com.google.ads.mediation.admob.AdMobAdapter;
|
|
9
|
+
import com.google.android.gms.ads.AdRequest;
|
|
10
|
+
import com.google.android.gms.ads.LoadAdError;
|
|
11
|
+
import com.google.android.gms.ads.MobileAds;
|
|
12
|
+
import com.google.android.gms.ads.RequestConfiguration;
|
|
13
|
+
import com.google.android.gms.ads.rewarded.ServerSideVerificationOptions;
|
|
14
|
+
|
|
15
|
+
import org.json.JSONObject;
|
|
16
|
+
|
|
17
|
+
import java.util.List;
|
|
18
|
+
import java.util.Objects;
|
|
19
|
+
|
|
20
|
+
public interface Context {
|
|
21
|
+
@Nullable
|
|
22
|
+
static Integer intFromBool(Context ctx, String name, int vNull, int vTrue, int vFalse) {
|
|
23
|
+
if (!ctx.has(name)) return null;
|
|
24
|
+
final Boolean v = ctx.optBoolean(name);
|
|
25
|
+
if (v == null) return vNull;
|
|
26
|
+
return v ? vTrue : vFalse;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
boolean has(@NonNull String name);
|
|
30
|
+
|
|
31
|
+
@Nullable
|
|
32
|
+
Object opt(@NonNull String name);
|
|
33
|
+
|
|
34
|
+
@Nullable
|
|
35
|
+
Boolean optBoolean(@NonNull String name);
|
|
36
|
+
|
|
37
|
+
@Nullable
|
|
38
|
+
Double optDouble(@NonNull String name);
|
|
39
|
+
|
|
40
|
+
default double optDouble(@NonNull String name, double defaultValue) {
|
|
41
|
+
final Double v = optDouble(name);
|
|
42
|
+
if (v == null) return defaultValue;
|
|
43
|
+
return v;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@Nullable
|
|
47
|
+
default Float optFloat(@NonNull String name) {
|
|
48
|
+
final Double v = optDouble(name);
|
|
49
|
+
if (v == null) return null;
|
|
50
|
+
return v.floatValue();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@Nullable
|
|
54
|
+
Integer optInt(@NonNull String name);
|
|
55
|
+
|
|
56
|
+
@Nullable
|
|
57
|
+
String optString(@NonNull String name);
|
|
58
|
+
|
|
59
|
+
@NonNull
|
|
60
|
+
List<String> optStringList(@NonNull String name);
|
|
61
|
+
|
|
62
|
+
@Nullable
|
|
63
|
+
JSONObject optObject(@NonNull String name);
|
|
64
|
+
|
|
65
|
+
void resolve();
|
|
66
|
+
|
|
67
|
+
void resolve(boolean data);
|
|
68
|
+
|
|
69
|
+
void reject(String msg);
|
|
70
|
+
|
|
71
|
+
default void reject() {
|
|
72
|
+
reject("unknown error");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
default void reject(@NonNull LoadAdError loadAdError) {
|
|
76
|
+
reject(loadAdError.getMessage());
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@Nullable
|
|
80
|
+
default Integer optId() {
|
|
81
|
+
return this.optInt("id");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@Nullable
|
|
85
|
+
default Ad optAd() {
|
|
86
|
+
return Helper.getAd(optId());
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@Nullable
|
|
90
|
+
default Ad optAdOrError() {
|
|
91
|
+
Ad ad = optAd();
|
|
92
|
+
if (ad == null) {
|
|
93
|
+
this.reject("Ad not found");
|
|
94
|
+
}
|
|
95
|
+
return ad;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
@Nullable
|
|
99
|
+
default String optAdUnitID() {
|
|
100
|
+
return this.optString("adUnitId");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
@Nullable
|
|
104
|
+
default Boolean optAppMuted() {
|
|
105
|
+
return this.optBoolean("appMuted");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
@Nullable
|
|
109
|
+
default Float optAppVolume() {
|
|
110
|
+
return this.optFloat("appVolume");
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
@Nullable
|
|
114
|
+
default String optPosition() {
|
|
115
|
+
return this.optString("position");
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
@NonNull
|
|
119
|
+
default AdRequest optAdRequest() {
|
|
120
|
+
AdRequest.Builder builder = new AdRequest.Builder();
|
|
121
|
+
if (this.has("contentUrl")) {
|
|
122
|
+
builder.setContentUrl(Objects.requireNonNull(this.optString("contentUrl")));
|
|
123
|
+
}
|
|
124
|
+
Bundle extras = new Bundle();
|
|
125
|
+
if (this.has("npa")) {
|
|
126
|
+
extras.putString("npa", this.optString("npa"));
|
|
127
|
+
}
|
|
128
|
+
return builder.addNetworkExtrasBundle(AdMobAdapter.class, extras).build();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
@NonNull
|
|
132
|
+
default RequestConfiguration optRequestConfiguration() {
|
|
133
|
+
final RequestConfiguration.Builder builder = new RequestConfiguration.Builder();
|
|
134
|
+
if (this.has("maxAdContentRating")) {
|
|
135
|
+
builder.setMaxAdContentRating(this.optString("maxAdContentRating"));
|
|
136
|
+
}
|
|
137
|
+
final Integer tagForChildDirectedTreatment = intFromBool(this, "tagForChildDirectedTreatment",
|
|
138
|
+
RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_UNSPECIFIED,
|
|
139
|
+
RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE,
|
|
140
|
+
RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_FALSE);
|
|
141
|
+
if (tagForChildDirectedTreatment != null) {
|
|
142
|
+
builder.setTagForChildDirectedTreatment(tagForChildDirectedTreatment);
|
|
143
|
+
}
|
|
144
|
+
final Integer tagForUnderAgeOfConsent = intFromBool(this, "tagForUnderAgeOfConsent",
|
|
145
|
+
RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_UNSPECIFIED,
|
|
146
|
+
RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_TRUE,
|
|
147
|
+
RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_FALSE);
|
|
148
|
+
if (tagForUnderAgeOfConsent != null) {
|
|
149
|
+
builder.setTagForUnderAgeOfConsent(tagForUnderAgeOfConsent);
|
|
150
|
+
}
|
|
151
|
+
if (this.has("testDeviceIds")) {
|
|
152
|
+
builder.setTestDeviceIds(this.optStringList("testDeviceIds"));
|
|
153
|
+
}
|
|
154
|
+
return builder.build();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
@Nullable
|
|
158
|
+
default ServerSideVerificationOptions optServerSideVerificationOptions() {
|
|
159
|
+
final String param = "serverSideVerification";
|
|
160
|
+
JSONObject serverSideVerification = this.optObject(param);
|
|
161
|
+
if (serverSideVerification == null) return null;
|
|
162
|
+
|
|
163
|
+
ServerSideVerificationOptions.Builder builder = new ServerSideVerificationOptions.Builder();
|
|
164
|
+
if (serverSideVerification.has("customData")) {
|
|
165
|
+
builder.setCustomData(serverSideVerification.optString("customData"));
|
|
166
|
+
}
|
|
167
|
+
if (serverSideVerification.has("userId")) {
|
|
168
|
+
builder.setUserId(serverSideVerification.optString("userId"));
|
|
169
|
+
}
|
|
170
|
+
return builder.build();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
default void configure(Helper helper) {
|
|
174
|
+
Boolean appMuted = optAppMuted();
|
|
175
|
+
if (appMuted != null) {
|
|
176
|
+
MobileAds.setAppMuted(appMuted);
|
|
177
|
+
}
|
|
178
|
+
Float appVolume = optAppVolume();
|
|
179
|
+
if (appVolume != null) {
|
|
180
|
+
MobileAds.setAppVolume(appVolume);
|
|
181
|
+
}
|
|
182
|
+
MobileAds.setRequestConfiguration(optRequestConfiguration());
|
|
183
|
+
helper.configForTestLab();
|
|
184
|
+
resolve();
|
|
185
|
+
}
|
|
186
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
package admob.plus.core;
|
|
2
|
+
|
|
3
|
+
import static admob.plus.core.Helper.NOT_IMPLEMENTED;
|
|
4
|
+
|
|
5
|
+
public interface GenericAd {
|
|
6
|
+
default boolean isLoaded() {
|
|
7
|
+
NOT_IMPLEMENTED();
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
default void load(Context ctx) {
|
|
12
|
+
NOT_IMPLEMENTED();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
default void show(Context ctx) {
|
|
16
|
+
NOT_IMPLEMENTED();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
default void hide(Context ctx) {
|
|
20
|
+
NOT_IMPLEMENTED();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
package admob.plus.core;
|
|
2
|
+
|
|
3
|
+
import android.annotation.SuppressLint;
|
|
4
|
+
import android.app.Activity;
|
|
5
|
+
import android.content.res.Resources;
|
|
6
|
+
import android.provider.Settings;
|
|
7
|
+
import android.util.DisplayMetrics;
|
|
8
|
+
import android.util.SparseArray;
|
|
9
|
+
import android.view.View;
|
|
10
|
+
import android.view.ViewGroup;
|
|
11
|
+
|
|
12
|
+
import androidx.annotation.NonNull;
|
|
13
|
+
import androidx.annotation.Nullable;
|
|
14
|
+
|
|
15
|
+
import com.google.android.gms.ads.MobileAds;
|
|
16
|
+
import com.google.android.gms.ads.RequestConfiguration;
|
|
17
|
+
|
|
18
|
+
import org.json.JSONArray;
|
|
19
|
+
|
|
20
|
+
import java.math.BigInteger;
|
|
21
|
+
import java.security.MessageDigest;
|
|
22
|
+
import java.security.NoSuchAlgorithmException;
|
|
23
|
+
import java.util.ArrayList;
|
|
24
|
+
import java.util.HashMap;
|
|
25
|
+
import java.util.List;
|
|
26
|
+
import java.util.Map;
|
|
27
|
+
|
|
28
|
+
public class Helper {
|
|
29
|
+
public static final SparseArray<Ad> ads = new SparseArray<Ad>();
|
|
30
|
+
private final Adapter adapter;
|
|
31
|
+
|
|
32
|
+
public Helper(Adapter adapter) {
|
|
33
|
+
this.adapter = adapter;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public static Ad getAd(Integer id) {
|
|
37
|
+
return ads.get(id);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public static double dpToPx(double dp) {
|
|
41
|
+
return dp * Resources.getSystem().getDisplayMetrics().density;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public static int pxToDp(int px) {
|
|
45
|
+
DisplayMetrics displayMetrics = Resources.getSystem().getDisplayMetrics();
|
|
46
|
+
int dp = Math.round(px / (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
|
|
47
|
+
return dp;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public static List<String> jsonArray2stringList(@Nullable JSONArray a) {
|
|
51
|
+
final List<String> result = new ArrayList<String>();
|
|
52
|
+
if (a == null) {
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
for (int i = 0; i < a.length(); i++) {
|
|
56
|
+
String testDeviceId = a.optString(i);
|
|
57
|
+
if (testDeviceId != null) {
|
|
58
|
+
result.add(testDeviceId);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@Nullable
|
|
65
|
+
public static ViewGroup getParentView(@Nullable View view) {
|
|
66
|
+
return view == null ? null : (ViewGroup) view.getParent();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@Nullable
|
|
70
|
+
public static ViewGroup removeFromParentView(@Nullable View view) {
|
|
71
|
+
ViewGroup viewParent = getParentView(view);
|
|
72
|
+
if (viewParent != null) viewParent.removeView(view);
|
|
73
|
+
return viewParent;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public static void NOT_IMPLEMENTED() {
|
|
77
|
+
throw new UnsupportedOperationException("Not implemented.");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private static String md5(String s) {
|
|
81
|
+
try {
|
|
82
|
+
MessageDigest digest = MessageDigest.getInstance("MD5");
|
|
83
|
+
digest.update(s.getBytes());
|
|
84
|
+
BigInteger bigInt = new BigInteger(1, digest.digest());
|
|
85
|
+
return String.format("%32s", bigInt.toString(16)).replace(' ', '0');
|
|
86
|
+
} catch (NoSuchAlgorithmException ignore) {
|
|
87
|
+
}
|
|
88
|
+
return "";
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public Activity getActivity() {
|
|
92
|
+
return adapter.getActivity();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public boolean isRunningInTestLab() {
|
|
96
|
+
String testLabSetting = Settings.System.getString(getActivity().getContentResolver(), "firebase.test.lab");
|
|
97
|
+
return "true".equals(testLabSetting);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public void configForTestLab() {
|
|
101
|
+
if (!isRunningInTestLab()) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
RequestConfiguration config = MobileAds.getRequestConfiguration();
|
|
105
|
+
List<String> testDeviceIds = config.getTestDeviceIds();
|
|
106
|
+
|
|
107
|
+
final String deviceId = getDeviceId();
|
|
108
|
+
if (testDeviceIds.contains(deviceId)) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
testDeviceIds.add(deviceId);
|
|
112
|
+
|
|
113
|
+
RequestConfiguration.Builder builder = config.toBuilder();
|
|
114
|
+
builder.setTestDeviceIds(testDeviceIds);
|
|
115
|
+
MobileAds.setRequestConfiguration(builder.build());
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
@NonNull
|
|
119
|
+
private String getDeviceId() {
|
|
120
|
+
// This will request test ads on the emulator and device by passing this hashed device ID.
|
|
121
|
+
@SuppressLint("HardwareIds") String ANDROID_ID = Settings.Secure.getString(getActivity().getContentResolver(), Settings.Secure.ANDROID_ID);
|
|
122
|
+
return md5(ANDROID_ID).toUpperCase();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
public interface Adapter {
|
|
126
|
+
Activity getActivity();
|
|
127
|
+
|
|
128
|
+
void emit(String eventName, Map<String, Object> data);
|
|
129
|
+
|
|
130
|
+
default void emit(String eventName) {
|
|
131
|
+
emit(eventName, new HashMap<>());
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const AdMob = {
|
|
5
|
+
adCreate() {},
|
|
6
|
+
adHide() {},
|
|
7
|
+
adIsLoaded() {},
|
|
8
|
+
adLoad() {},
|
|
9
|
+
adShow() {},
|
|
10
|
+
bannerConfig() {},
|
|
11
|
+
bannerHide() {},
|
|
12
|
+
bannerLoad() {},
|
|
13
|
+
bannerShow() {},
|
|
14
|
+
configRequest() {},
|
|
15
|
+
configure() {},
|
|
16
|
+
interstitialIsLoaded() {},
|
|
17
|
+
interstitialLoad() {},
|
|
18
|
+
interstitialShow() {},
|
|
19
|
+
ready() {},
|
|
20
|
+
requestTrackingAuthorization() {},
|
|
21
|
+
rewardedInterstitialIsLoaded() {},
|
|
22
|
+
rewardedInterstitialLoad() {},
|
|
23
|
+
rewardedInterstitialShow() {},
|
|
24
|
+
rewardedIsLoaded() {},
|
|
25
|
+
rewardedLoad() {},
|
|
26
|
+
rewardedShow() {},
|
|
27
|
+
setAppMuted() {},
|
|
28
|
+
setAppVolume() {},
|
|
29
|
+
start() {},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// eslint-disable-next-line node/no-missing-require
|
|
33
|
+
require('cordova/exec/proxy').add('AdMob', AdMob);
|