diff --git a/Documentation/index.html b/Documentation/index.html index 2441671..c01caad 100644 --- a/Documentation/index.html +++ b/Documentation/index.html @@ -277,9 +277,10 @@ onClicked ERROR_NETWORK ERROR_INVALID_REQUEST ERROR_NO_FILL -

When you want to load and show the banner you have to call the show() function and for hide the hide() functions as follow (banner is the id name of the item in the example above):

+

When you want to load and show the banner you have to call the show() function and for hide the hide() functions (banner is the id name of the item in the example above). Function reload() force reload of a new banner.

banner.show()
-banner.hide()
+banner.hide() +banner.reload()

Please note the banner is a native android view over the QML window, that's mean will stay over anything painted into in and you can not place nothing over the banner.

diff --git a/QtAndroidTools/QAndroidAdMobBanner.cpp b/QtAndroidTools/QAndroidAdMobBanner.cpp index 5a14c06..c46af73 100644 --- a/QtAndroidTools/QAndroidAdMobBanner.cpp +++ b/QtAndroidTools/QAndroidAdMobBanner.cpp @@ -33,7 +33,8 @@ QAndroidAdMobBanner::QAndroidAdMobBanner(QQuickItem *parent) : QQuickItem(parent "(Landroid/app/Activity;)V", QtAndroid::androidActivity().object()), m_InstanceIndex(m_InstancesCounter++), - m_BannerType(TYPE_NO_BANNER) + m_BannerType(TYPE_NO_BANNER), + m_BannerShowed(false) { m_pInstancesMap[m_InstanceIndex] = this; @@ -74,6 +75,7 @@ bool QAndroidAdMobBanner::show() { ItemPosChanged(); m_JavaAdMobBanner.callMethod("show"); + m_BannerShowed = true; return true; } @@ -85,6 +87,25 @@ bool QAndroidAdMobBanner::hide() if(m_JavaAdMobBanner.isValid()) { m_JavaAdMobBanner.callMethod("hide"); + m_BannerShowed = false; + return true; + } + + return false; +} + +bool QAndroidAdMobBanner::reload() +{ + if(m_JavaAdMobBanner.isValid() && m_BannerType != TYPE_NO_BANNER && m_UnitId.isEmpty() == false) + { + const bool BannerShowed = m_BannerShowed; + + if(BannerShowed) hide(); + m_JavaAdMobBanner.callMethod("reload"); + setType(m_BannerType); + setUnitId(m_UnitId); + if(BannerShowed) show(); + return true; } @@ -138,13 +159,9 @@ void QAndroidAdMobBanner::ScreenGeometryChanged(const QRect &Geometry) { Q_UNUSED(Geometry) - if(m_JavaAdMobBanner.isValid() && m_BannerType != TYPE_NO_BANNER && m_UnitId.isEmpty() == false) + if(m_BannerShowed == true) { - hide(); - m_JavaAdMobBanner.callMethod("reload"); - setType(m_BannerType); - setUnitId(m_UnitId); - show(); + reload(); } } diff --git a/QtAndroidTools/QAndroidAdMobBanner.h b/QtAndroidTools/QAndroidAdMobBanner.h index 3f221f7..0dd088a 100644 --- a/QtAndroidTools/QAndroidAdMobBanner.h +++ b/QtAndroidTools/QAndroidAdMobBanner.h @@ -59,6 +59,7 @@ public: Q_INVOKABLE bool show(); Q_INVOKABLE bool hide(); + Q_INVOKABLE bool reload(); const QString& getUnitId() const; void setUnitId(const QString &UnitId); @@ -85,6 +86,7 @@ private: static int m_InstancesCounter; const int m_InstanceIndex; BANNER_TYPE m_BannerType; + bool m_BannerShowed; QString m_UnitId; enum EVENT_TYPE diff --git a/QtAndroidToolsDemo/tools/AndroidAdMobBanner.qml b/QtAndroidToolsDemo/tools/AndroidAdMobBanner.qml index 78b4a51..4f36d88 100644 --- a/QtAndroidToolsDemo/tools/AndroidAdMobBanner.qml +++ b/QtAndroidToolsDemo/tools/AndroidAdMobBanner.qml @@ -10,7 +10,7 @@ Page { Column { width: parent.wdith - height: parent.height * 0.8 + height: parent.height * 0.9 anchors.centerIn: parent spacing: 20 @@ -88,5 +88,13 @@ Page { banner2.hide(); } } + Button { + anchors.horizontalCenter: parent.horizontalCenter + text: "Reload banners" + onClicked: { + banner1.reload(); + banner2.reload(); + } + } } }