Skip to content

Commit

Permalink
add ShowAdInspector API
Browse files Browse the repository at this point in the history
  • Loading branch information
AGulev committed May 16, 2021
1 parent af30bc6 commit 57e23ab
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 0 deletions.
8 changes: 8 additions & 0 deletions extension-admob/src/admob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ static int Lua_RequestIDFA(lua_State* L)
return 0;
}

static int Lua_ShowAdInspector(lua_State* L)
{
DM_LUA_STACK_CHECK(L, 0);
ShowAdInspector();
return 0;
}

static const luaL_reg Module_methods[] =
{
{"initialize", Lua_Initialize},
Expand All @@ -168,6 +175,7 @@ static const luaL_reg Module_methods[] =
{"is_banner_loaded", Lua_IsBannerLoaded},
{"set_privacy_settings", Lua_SetPrivacySettings},
{"request_idfa", Lua_RequestIDFA},
{"show_ad_inspector", Lua_ShowAdInspector},
{0, 0}
};

Expand Down
7 changes: 7 additions & 0 deletions extension-admob/src/admob_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct Admob
jmethodID m_IsBannerLoaded;
jmethodID m_SetPrivacySettings;
jmethodID m_RequestIDFA;
jmethodID m_ShowAdInspector;

};

Expand Down Expand Up @@ -105,6 +106,7 @@ static void InitJNIMethods(JNIEnv* env, jclass cls)
g_admob.m_HideBanner = env->GetMethodID(cls, "hideBanner", "()V");
g_admob.m_SetPrivacySettings = env->GetMethodID(cls, "setPrivacySettings", "(Z)V");
g_admob.m_RequestIDFA = env->GetMethodID(cls, "requestIDFA", "()V");
g_admob.m_ShowAdInspector = env->GetMethodID(cls, "showAdInspector", "()V");

g_admob.m_IsRewardedLoaded = env->GetMethodID(cls, "isRewardedLoaded", "()Z");
g_admob.m_IsInterstitialLoaded = env->GetMethodID(cls, "isInterstitialLoaded", "()Z");
Expand Down Expand Up @@ -195,6 +197,11 @@ void RequestIDFA()
CallVoidMethod(g_admob.m_AdmobJNI, g_admob.m_RequestIDFA);
}

void ShowAdInspector()
{
CallVoidMethod(g_admob.m_AdmobJNI, g_admob.m_ShowAdInspector);
}

}//namespace dmAdmob

#endif
9 changes: 9 additions & 0 deletions extension-admob/src/admob_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,15 @@ void RequestIDFA() {
}
}

void ShowAdInspector() {
[GADMobileAds.sharedInstance presentAdInspectorFromViewController:uiViewController completionHandler:^(NSError *error) {
// error will be non-nil if there was an issue and the inspector was not displayed.
if (error) {
dmLogInfo("AdInspector Error: %s", error);
}
}];
}

} //namespace

@implementation AdmobExtInterstitialAdDelegate
Expand Down
1 change: 1 addition & 0 deletions extension-admob/src/admob_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ void ShowBanner(BannerPosition bannerPos);
void HideBanner();
void SetPrivacySettings(bool enable_rdp);
void RequestIDFA();
void ShowAdInspector();

bool IsInterstitialLoaded();
bool IsRewardedLoaded();
Expand Down
13 changes: 13 additions & 0 deletions extension-admob/src/java/com/defold/admob/AdmobJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import com.google.android.gms.ads.FullScreenContentCallback;
import com.google.android.gms.ads.LoadAdError;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.AdInspectorError;
import com.google.android.gms.ads.OnAdInspectorClosedListener;
import com.google.android.gms.ads.initialization.InitializationStatus;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;

Expand Down Expand Up @@ -114,6 +116,17 @@ public void requestIDFA() {
sendSimpleMessage(MSG_IDFA, EVENT_NOT_SUPPORTED);
}

public void showAdInspector() {
MobileAds.openAdInspector(activity, new OnAdInspectorClosedListener() {
public void onAdInspectorClosed(AdInspectorError error) {
// Error will be non-null if ad inspector closed due to an error.
if (error != null) {
Log.d(TAG, error.toString());
}
}
});
}

// https://www.baeldung.com/java-json-escaping
private String getJsonConversionErrorMessage(String messageText) {
String message = null;
Expand Down
162 changes: 162 additions & 0 deletions main/ads.gui
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,168 @@ nodes {
text_leading: 1.0
text_tracking: 0.0
}
nodes {
position {
x: 46.0
y: 617.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 200.0
y: 100.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_TEMPLATE
id: "show_ad_inspector"
parent: "inited"
layer: ""
inherit_alpha: true
alpha: 1.0
template: "/dirtylarry/button.gui"
template_node_child: false
}
nodes {
position {
x: 160.0
y: 233.85786
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 340.0
y: 88.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_BOX
blend_mode: BLEND_MODE_ALPHA
texture: "button/button_normal"
id: "show_ad_inspector/larrybutton"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
adjust_mode: ADJUST_MODE_FIT
parent: "show_ad_inspector"
layer: ""
inherit_alpha: true
slice9 {
x: 32.0
y: 32.0
z: 32.0
w: 32.0
}
clipping_mode: CLIPPING_MODE_NONE
clipping_visible: true
clipping_inverted: false
alpha: 1.0
overridden_fields: 1
overridden_fields: 4
template_node_child: true
size_mode: SIZE_MODE_MANUAL
}
nodes {
position {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 200.0
y: 100.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_TEXT
blend_mode: BLEND_MODE_ALPHA
text: "Show Ad Inspector"
font: "larryfont"
id: "show_ad_inspector/larrylabel"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
outline {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
shadow {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
adjust_mode: ADJUST_MODE_FIT
line_break: false
parent: "show_ad_inspector/larrybutton"
layer: ""
inherit_alpha: true
alpha: 1.0
outline_alpha: 1.0
shadow_alpha: 1.0
overridden_fields: 1
overridden_fields: 8
template_node_child: true
text_leading: 1.0
text_tracking: 0.0
}
nodes {
position {
x: 0.0
Expand Down
7 changes: 7 additions & 0 deletions main/ads.gui_script
Original file line number Diff line number Diff line change
Expand Up @@ -275,5 +275,12 @@ function on_input(self, action_id, action)
end)
end

if gui.is_enabled(gui.get_node("show_ad_inspector/larrybutton")) then
dirtylarry:button("show_ad_inspector", action_id, action, function ()
print("admob.show_ad_inspector()")
admob.show_ad_inspector()
end)
end

end

0 comments on commit 57e23ab

Please sign in to comment.