mirror of
https://github.com/QuasarApp/QtAndroidTools.git
synced 2025-04-29 14:34:32 +00:00
Added reload() function for AdMob banner
This commit is contained in:
parent
2465a59717
commit
46c9cb6ddd
Documentation
QtAndroidTools
QtAndroidToolsDemo/tools
@ -277,9 +277,10 @@ onClicked</pre>
|
|||||||
ERROR_NETWORK
|
ERROR_NETWORK
|
||||||
ERROR_INVALID_REQUEST
|
ERROR_INVALID_REQUEST
|
||||||
ERROR_NO_FILL</pre>
|
ERROR_NO_FILL</pre>
|
||||||
<p>When you want to load and show the banner you have to call the <i>show()</i> function and for hide the <i>hide()</i> functions as follow (banner is the id name of the item in the example above):</p>
|
<p>When you want to load and show the banner you have to call the <i>show()</i> function and for hide the <i>hide()</i> functions (banner is the id name of the item in the example above). Function <i>reload()</i> force reload of a new banner.</p>
|
||||||
<pre class="prettyprint">banner.show()
|
<pre class="prettyprint">banner.show()
|
||||||
banner.hide()</pre>
|
banner.hide()
|
||||||
|
banner.reload()</pre>
|
||||||
<p>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.</p>
|
<p>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.</p>
|
||||||
<img src="images/admobbanner1.png">
|
<img src="images/admobbanner1.png">
|
||||||
</div>
|
</div>
|
||||||
|
@ -33,7 +33,8 @@ QAndroidAdMobBanner::QAndroidAdMobBanner(QQuickItem *parent) : QQuickItem(parent
|
|||||||
"(Landroid/app/Activity;)V",
|
"(Landroid/app/Activity;)V",
|
||||||
QtAndroid::androidActivity().object<jobject>()),
|
QtAndroid::androidActivity().object<jobject>()),
|
||||||
m_InstanceIndex(m_InstancesCounter++),
|
m_InstanceIndex(m_InstancesCounter++),
|
||||||
m_BannerType(TYPE_NO_BANNER)
|
m_BannerType(TYPE_NO_BANNER),
|
||||||
|
m_BannerShowed(false)
|
||||||
{
|
{
|
||||||
m_pInstancesMap[m_InstanceIndex] = this;
|
m_pInstancesMap[m_InstanceIndex] = this;
|
||||||
|
|
||||||
@ -74,6 +75,7 @@ bool QAndroidAdMobBanner::show()
|
|||||||
{
|
{
|
||||||
ItemPosChanged();
|
ItemPosChanged();
|
||||||
m_JavaAdMobBanner.callMethod<void>("show");
|
m_JavaAdMobBanner.callMethod<void>("show");
|
||||||
|
m_BannerShowed = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,6 +87,25 @@ bool QAndroidAdMobBanner::hide()
|
|||||||
if(m_JavaAdMobBanner.isValid())
|
if(m_JavaAdMobBanner.isValid())
|
||||||
{
|
{
|
||||||
m_JavaAdMobBanner.callMethod<void>("hide");
|
m_JavaAdMobBanner.callMethod<void>("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<void>("reload");
|
||||||
|
setType(m_BannerType);
|
||||||
|
setUnitId(m_UnitId);
|
||||||
|
if(BannerShowed) show();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,13 +159,9 @@ void QAndroidAdMobBanner::ScreenGeometryChanged(const QRect &Geometry)
|
|||||||
{
|
{
|
||||||
Q_UNUSED(Geometry)
|
Q_UNUSED(Geometry)
|
||||||
|
|
||||||
if(m_JavaAdMobBanner.isValid() && m_BannerType != TYPE_NO_BANNER && m_UnitId.isEmpty() == false)
|
if(m_BannerShowed == true)
|
||||||
{
|
{
|
||||||
hide();
|
reload();
|
||||||
m_JavaAdMobBanner.callMethod<void>("reload");
|
|
||||||
setType(m_BannerType);
|
|
||||||
setUnitId(m_UnitId);
|
|
||||||
show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +59,7 @@ public:
|
|||||||
|
|
||||||
Q_INVOKABLE bool show();
|
Q_INVOKABLE bool show();
|
||||||
Q_INVOKABLE bool hide();
|
Q_INVOKABLE bool hide();
|
||||||
|
Q_INVOKABLE bool reload();
|
||||||
|
|
||||||
const QString& getUnitId() const;
|
const QString& getUnitId() const;
|
||||||
void setUnitId(const QString &UnitId);
|
void setUnitId(const QString &UnitId);
|
||||||
@ -85,6 +86,7 @@ private:
|
|||||||
static int m_InstancesCounter;
|
static int m_InstancesCounter;
|
||||||
const int m_InstanceIndex;
|
const int m_InstanceIndex;
|
||||||
BANNER_TYPE m_BannerType;
|
BANNER_TYPE m_BannerType;
|
||||||
|
bool m_BannerShowed;
|
||||||
QString m_UnitId;
|
QString m_UnitId;
|
||||||
|
|
||||||
enum EVENT_TYPE
|
enum EVENT_TYPE
|
||||||
|
@ -10,7 +10,7 @@ Page {
|
|||||||
|
|
||||||
Column {
|
Column {
|
||||||
width: parent.wdith
|
width: parent.wdith
|
||||||
height: parent.height * 0.8
|
height: parent.height * 0.9
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
spacing: 20
|
spacing: 20
|
||||||
|
|
||||||
@ -88,5 +88,13 @@ Page {
|
|||||||
banner2.hide();
|
banner2.hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Button {
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
text: "Reload banners"
|
||||||
|
onClicked: {
|
||||||
|
banner1.reload();
|
||||||
|
banner2.reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user