mirror of
https://github.com/QuasarApp/QtAndroidTools.git
synced 2025-04-28 05:54:32 +00:00
Changed the way AdMobBanner is positioned
This commit is contained in:
parent
d894b8bef9
commit
48d2ce7254
@ -53,9 +53,8 @@ QAndroidAdMobBanner::QAndroidAdMobBanner(QQuickItem *parent) : QQuickItem(parent
|
||||
}
|
||||
connect(qGuiApp, &QGuiApplication::applicationStateChanged, this, &QAndroidAdMobBanner::ApplicationStateChanged);
|
||||
connect(qGuiApp->primaryScreen(), &QScreen::geometryChanged, this, &QAndroidAdMobBanner::ScreenGeometryChanged);
|
||||
connect(this, &QQuickItem::xChanged, this, &QAndroidAdMobBanner::ItemPosChanged);
|
||||
connect(this, &QQuickItem::yChanged, this, &QAndroidAdMobBanner::ItemPosChanged);
|
||||
SetNewAppState(APP_STATE_CREATE);
|
||||
|
||||
}
|
||||
|
||||
QAndroidAdMobBanner::~QAndroidAdMobBanner()
|
||||
@ -73,7 +72,7 @@ bool QAndroidAdMobBanner::show()
|
||||
{
|
||||
if(m_JavaAdMobBanner.isValid() && m_BannerType != TYPE_NO_BANNER && m_UnitId.isEmpty() == false)
|
||||
{
|
||||
ItemPosChanged();
|
||||
UpdatePosition();
|
||||
m_JavaAdMobBanner.callMethod<void>("show");
|
||||
m_BannerShowed = true;
|
||||
return true;
|
||||
@ -193,20 +192,17 @@ void QAndroidAdMobBanner::ScreenGeometryChanged(const QRect &Geometry)
|
||||
}
|
||||
}
|
||||
|
||||
void QAndroidAdMobBanner::ItemPosChanged()
|
||||
void QAndroidAdMobBanner::UpdatePosition()
|
||||
{
|
||||
if(m_JavaAdMobBanner.isValid())
|
||||
{
|
||||
QAndroidJniObject BannerPosObj("com/falsinsoft/qtandroidtools/AndroidAdMobBanner$BannerPos");
|
||||
const qreal PixelRatio = qApp->primaryScreen()->devicePixelRatio();
|
||||
const QPointF ScreenPos = mapToGlobal(QPointF(0,0));
|
||||
|
||||
BannerPosObj.setField<jint>("x", static_cast<int>(ScreenPos.x() * PixelRatio));
|
||||
BannerPosObj.setField<jint>("y", static_cast<int>(ScreenPos.y() * PixelRatio));
|
||||
|
||||
m_JavaAdMobBanner.callMethod<void>("setPos",
|
||||
"(Lcom/falsinsoft/qtandroidtools/AndroidAdMobBanner$BannerPos;)V",
|
||||
BannerPosObj.object()
|
||||
"(II)V",
|
||||
static_cast<int>(ScreenPos.x() * PixelRatio),
|
||||
static_cast<int>(ScreenPos.y() * PixelRatio)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -81,7 +81,6 @@ signals:
|
||||
private slots:
|
||||
void ApplicationStateChanged(Qt::ApplicationState State);
|
||||
void ScreenGeometryChanged(const QRect &Geometry);
|
||||
void ItemPosChanged();
|
||||
|
||||
private:
|
||||
const QAndroidJniObject m_JavaAdMobBanner;
|
||||
@ -112,4 +111,5 @@ private:
|
||||
APP_STATE_DESTROY
|
||||
};
|
||||
void SetNewAppState(APP_STATE NewState);
|
||||
void UpdatePosition();
|
||||
};
|
||||
|
@ -52,7 +52,7 @@ public class AndroidAdMobBanner
|
||||
|
||||
public AndroidAdMobBanner(Activity ActivityInstance)
|
||||
{
|
||||
mViewGroup = (ViewGroup)ActivityInstance.getWindow().getDecorView().getRootView();
|
||||
mViewGroup = (ViewGroup)ActivityInstance.getWindow().getDecorView().findViewById(android.R.id.content);
|
||||
mBannerListener = new BannerListener();
|
||||
mActivityInstance = ActivityInstance;
|
||||
}
|
||||
@ -110,7 +110,7 @@ public class AndroidAdMobBanner
|
||||
UiThread.exec();
|
||||
}
|
||||
|
||||
public void setPos(final BannerPos pos)
|
||||
public void setPos(final int posX, final int posY)
|
||||
{
|
||||
if(mBannerView == null)
|
||||
{
|
||||
@ -121,12 +121,8 @@ public class AndroidAdMobBanner
|
||||
{
|
||||
public void runOnUIThread()
|
||||
{
|
||||
Rect VisibleFrame = new Rect();
|
||||
|
||||
mActivityInstance.getWindow().getDecorView().getWindowVisibleDisplayFrame(VisibleFrame);
|
||||
|
||||
mBannerView.setX(pos.x);
|
||||
mBannerView.setY(VisibleFrame.top + pos.y); // Add the height of the system status bar on top
|
||||
mBannerView.setX(posX);
|
||||
mBannerView.setY(posY);
|
||||
}
|
||||
});
|
||||
UiThread.exec();
|
||||
@ -329,12 +325,6 @@ public class AndroidAdMobBanner
|
||||
}
|
||||
}
|
||||
|
||||
public static class BannerPos
|
||||
{
|
||||
public int x = 0;
|
||||
public int y = 0;
|
||||
}
|
||||
|
||||
public static class BannerSize
|
||||
{
|
||||
public int width = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user