Skip to content

Commit

Permalink
add android AppLovin getBannerViewport
Browse files Browse the repository at this point in the history
improve Stream logging
  • Loading branch information
irov committed May 21, 2024
1 parent 9d8b03c commit 7fa2981
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.Mengine.Plugin.AppLovin;

import android.graphics.Rect;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
Expand Down Expand Up @@ -97,6 +98,21 @@ public void destroy() {
}
}

public Rect getViewport() {
if (m_adView == null) {
m_plugin.logError("getViewport: adView is null");

return null;
}

int left = m_adView.getLeft();
int right = m_adView.getRight();
int top = m_adView.getTop();
int bottom = m_adView.getBottom();

return new Rect(left, top, right, bottom);
}

public void loadAd() {
if (m_adView == null) {
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package org.Mengine.Plugin.AppLovin;

import android.content.Context;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Bundle;

import androidx.preference.Preference;
import androidx.preference.PreferenceManager;

import com.applovin.mediation.MaxAd;
import com.applovin.mediation.MaxAdFormat;
import com.applovin.mediation.MaxMediatedNetworkInfo;
Expand Down Expand Up @@ -315,6 +312,20 @@ public boolean bannerVisible(String adUnitId, boolean show) {
return true;
}

public Rect getBannerViewport(String adUnitId) {
MengineAppLovinBanner banner = m_banners.get(adUnitId);

if (banner == null) {
this.assertionError("not found banner: %s", adUnitId);

return null;
}

Rect rect = banner.getViewport();

return rect;
}

public boolean initInterstitial(String adUnitId) {
if (m_interstitials.containsKey(adUnitId) == true) {
this.assertionError("already exist interstitial: %s", adUnitId);
Expand Down
22 changes: 22 additions & 0 deletions src/Environment/Android/AndroidHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,28 @@ namespace Mengine
_jenv->DeleteLocalRef( jclass_List );
}
//////////////////////////////////////////////////////////////////////////
void AndroidGetJavaRect( JNIEnv * _jenv, jobject _jrect, Viewport * const _viewport )
{
jclass jclass_Rect = _jenv->FindClass( "android/graphics/Rect" );

jfieldID jfieldID_Rect_left = _jenv->GetFieldID( jclass_Rect, "left", "I" );
jfieldID jfieldID_Rect_top = _jenv->GetFieldID( jclass_Rect, "top", "I" );
jfieldID jfieldID_Rect_right = _jenv->GetFieldID( jclass_Rect, "right", "I" );
jfieldID jfieldID_Rect_bottom = _jenv->GetFieldID( jclass_Rect, "bottom", "I" );

jint left = _jenv->GetIntField( _jrect, jfieldID_Rect_left );
jint top = _jenv->GetIntField( _jrect, jfieldID_Rect_top );
jint right = _jenv->GetIntField( _jrect, jfieldID_Rect_right );
jint bottom = _jenv->GetIntField( _jrect, jfieldID_Rect_bottom );

_viewport->begin.x = (float)left;
_viewport->begin.y = (float)top;
_viewport->end.x = (float)right;
_viewport->end.y = (float)bottom;

_jenv->DeleteLocalRef( jclass_Rect );
}
//////////////////////////////////////////////////////////////////////////
void AndroidWriteMemory( JNIEnv * _jenv, const Mengine::MemoryInterfacePtr & _memory, jobject _writer )
{
jclass jclass_Writer = _jenv->GetObjectClass( _writer );
Expand Down
3 changes: 3 additions & 0 deletions src/Environment/Android/AndroidHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "Kernel/String.h"
#include "Kernel/ArrayString.h"
#include "Kernel/StaticString.h"
#include "Kernel/Viewport.h"

#include "Config/Lambda.h"

Expand Down Expand Up @@ -52,6 +53,8 @@ namespace Mengine
uint32_t AndroidGetJavaListSize( JNIEnv * _jenv, jobject _jlist );
void AndroidForeachJavaList( JNIEnv * _jenv, jobject _jlist, const LambdaJavaListForeach & _lambda );
//////////////////////////////////////////////////////////////////////////
void AndroidGetJavaRect( JNIEnv * _jenv, jobject _jrect, Viewport * const _viewport );
//////////////////////////////////////////////////////////////////////////
void AndroidWriteMemory( JNIEnv * _jenv, const MemoryInterfacePtr & _memory, jobject _writer );
//////////////////////////////////////////////////////////////////////////
void AndroidEnvExceptionCheck( JNIEnv * _jenv );
Expand Down

0 comments on commit 7fa2981

Please sign in to comment.