Skip to content

Commit

Permalink
Merge pull request #25 from AGulev/issue-24
Browse files Browse the repository at this point in the history
Fix issue when banner cut by navigation bar
  • Loading branch information
AGulev authored Jan 2, 2022
2 parents 249954c + 27844c6 commit 47b9ff1
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 8 deletions.
16 changes: 9 additions & 7 deletions defunityads/src/java/com/agulev/defunityads/DefUnityAdsJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -293,18 +293,18 @@ public void requestIDFA() {

private boolean isShown = false;

private void ApplyBannerPosition() {

}

public void setBannerPosition(String position) {
m_bannerPosition = BannerPosition.fromString(position);
public void applyBannerPosition() {
if (isShown) {
_hideBanner();
showBanner();
}
}

public void setBannerPosition(String position) {
m_bannerPosition = BannerPosition.fromString(position);
applyBannerPosition();
}

public void loadBanner(String placementId, int width, int height) {
if (bannerView == null) {
BannerView banner = new BannerView(activity, placementId, new UnityBannerSize(width, height));
Expand All @@ -315,7 +315,8 @@ public void onBannerLoaded(BannerView bannerAdView) {

layout = new LinearLayout(activity);
layout.setOrientation(LinearLayout.VERTICAL);

layout.setSystemUiVisibility(activity.getWindow().getDecorView().getSystemUiVisibility());

MarginLayoutParams params = new MarginLayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
params.setMargins(0, 0, 0, 0);

Expand Down Expand Up @@ -417,6 +418,7 @@ public void showBanner() {
@Override
public void run() {
WindowManager wm = activity.getWindowManager();
layout.setSystemUiVisibility(activity.getWindow().getDecorView().getSystemUiVisibility());
windowParams.gravity = m_bannerPosition.getGravity();
wm.addView(layout, windowParams);
}
Expand Down
16 changes: 15 additions & 1 deletion defunityads/src/unityads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,16 @@ static dmExtension::Result UpdateUnityAds(dmExtension::Params* params)
return dmExtension::RESULT_OK;
}

static void OnEventUnityAds(dmExtension::Params* params, const dmExtension::Event* event)
{
switch(event->m_Event)
{
case dmExtension::EVENT_ID_ACTIVATEAPP:
dmUnityAds::ActivateApp();
break;
}
}

#else // unsupported platforms

static dmExtension::Result AppInitializeUnityAds(dmExtension::AppParams* params)
Expand Down Expand Up @@ -277,7 +287,11 @@ static dmExtension::Result UpdateUnityAds(dmExtension::Params* params)
return dmExtension::RESULT_OK;
}

static void OnEventUnityAds(dmExtension::Params* params, const dmExtension::Event* event)
{
}

#endif // platforms


DM_DECLARE_EXTENSION(EXTENSION_NAME, LIB_NAME, AppInitializeUnityAds, AppFinalizeUnityAds, InitializeUnityAds, UpdateUnityAds, 0, FinalizeUnityAds)
DM_DECLARE_EXTENSION(EXTENSION_NAME, LIB_NAME, AppInitializeUnityAds, AppFinalizeUnityAds, InitializeUnityAds, UpdateUnityAds, OnEventUnityAds, FinalizeUnityAds)
7 changes: 7 additions & 0 deletions defunityads/src/unityads_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ struct DefUnityAdsClass
jmethodID m_showBanner;
jmethodID m_hideBanner;
jmethodID m_requestIDFA;
jmethodID m_applyBannerPosition;
};

DefUnityAdsClass g_duads;
Expand All @@ -96,6 +97,7 @@ void Initialize_Ext()
g_duads.m_showBanner = env->GetMethodID(cls, "showBanner", "()V");
g_duads.m_hideBanner = env->GetMethodID(cls, "hideBanner", "()V");
g_duads.m_requestIDFA = env->GetMethodID(cls, "requestIDFA", "()V");
g_duads.m_applyBannerPosition = env->GetMethodID(cls, "applyBannerPosition", "()V");

jmethodID jni_constructor = env->GetMethodID(cls, "<init>", "(Landroid/app/Activity;)V");
g_duads.m_DUADS_JNI = env->NewGlobalRef(env->NewObject(cls, jni_constructor, threadAttacher.GetActivity()->clazz));
Expand Down Expand Up @@ -205,6 +207,11 @@ void RequestIDFA()
CallVoidMethod(g_duads.m_DUADS_JNI, g_duads.m_requestIDFA);
}

void ActivateApp()
{
CallVoidMethod(g_duads.m_DUADS_JNI, g_duads.m_applyBannerPosition);
}

} //namespaces

#endif
4 changes: 4 additions & 0 deletions defunityads/src/unityads_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ void HideBanner() {
}
}

void ActivateApp()
{
}

void SetBannerPosition(DefUnityBannerPosition bannerPosition) {
currentPosition = bannerPosition;
if (isBannerVisible) {
Expand Down
1 change: 1 addition & 0 deletions defunityads/src/unityads_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ void UnloadBanner();
void ShowBanner();
void HideBanner();
void RequestIDFA();
void ActivateApp();

bool IsSupported();
bool IsInitialized();
Expand Down
1 change: 1 addition & 0 deletions game.project
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ game_binding = /input/game.input_bindingc
[display]
width = 1280
height = 720
dynamic_orientation = 1

[physics]
scale = 0.02
Expand Down

0 comments on commit 47b9ff1

Please sign in to comment.