forked from niavlys/admob4kivy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
152 lines (122 loc) · 4.42 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
__version__ = '0.0.5'
"""
Basic POC of admob integration into Kivy.
starting point is the screenmanager example from kivy, on where is added admob features:
- intersticial ad between screens (see on_pre_enter() for details).
- banner on screen, with a button to toogle its visibility.
"""
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.properties import NumericProperty,ObjectProperty
from kivy.lang import Builder
from kivy.clock import Clock
from admob import Admob
from random import random
ad_inst = Admob()
Builder.load_string('''
#:import random random.random
#:import SlideTransition kivy.uix.screenmanager.SlideTransition
#:import SwapTransition kivy.uix.screenmanager.SwapTransition
#:import WipeTransition kivy.uix.screenmanager.WipeTransition
#:import FadeTransition kivy.uix.screenmanager.FadeTransition
#:import RiseInTransition kivy.uix.screenmanager.RiseInTransition
#:import FallOutTransition kivy.uix.screenmanager.FallOutTransition
#:import NoTransition kivy.uix.screenmanager.NoTransition
<CustomScreen>:
hue: random()
canvas:
Color:
hsv: self.hue, .5, .3
Rectangle:
size: self.size
Label:
font_size: 42
text: root.name
Button:
text: 'Next screen'
size_hint: None, None
pos_hint: {'right': 1}
size: 150, 50
on_release: root.manager.current = root.manager.next()
Button:
text: 'Previous screen'
size_hint: None, None
size: 150, 50
on_release: root.manager.current = root.manager.previous()
BoxLayout:
size_hint: .5, None
height: 250
pos_hint: {'center_x': .5}
orientation: 'vertical'
Button:
id: toggleButton
text: 'Show Ad Banner'
on_press: root.toggleBanner()
Button:
text: 'Use SlideTransition with "up" direction'
on_release: root.manager.transition = \
SlideTransition(direction="up")
Button:
text: 'Use SlideTransition with "down" direction'
on_release: root.manager.transition = \
SlideTransition(direction="down")
Button:
text: 'Use SlideTransition with "left" direction'
on_release: root.manager.transition = \
SlideTransition(direction="left")
Button:
text: 'Use SlideTransition with "right" direction'
on_release: root.manager.transition = \
SlideTransition(direction="right")
Button:
text: 'Use SwapTransition'
on_release: root.manager.transition = SwapTransition()
Button:
text: 'Use WipeTransition'
on_release: root.manager.transition = WipeTransition()
Button:
text: 'Use FadeTransition'
on_release: root.manager.transition = FadeTransition()
Button:
text: 'Use FallOutTransition'
on_release: root.manager.transition = FallOutTransition()
Button:
text: 'Use RiseInTransition'
on_release: root.manager.transition = RiseInTransition()
Button:
text: 'Use NoTransition'
on_release: root.manager.transition = NoTransition(duration=0)
''')
class CustomScreen(Screen):
hue = NumericProperty(0)
def _showBanner(self,*args):
ad_inst.request_Banner()
def on_pre_enter(self,*args):
if ad_inst.is_Banner_Visible():
self.ids['toggleButton'].text="Hide Ad Banner"
else:
self.ids['toggleButton'].text="Show Ad Banner"
ad_inst.show_Interstitial()
def toggleBanner(self,*args):
if ad_inst.is_Banner_Visible():
ad_inst.hide_Banner()
self.ids['toggleButton'].text="Show Ad Banner"
else:
ad_inst.request_Banner()
self.ids['toggleButton'].text="Hide Ad Banner"
class ScreenManagerApp(App):
def build(self):
#initial request
ad_inst.request_Interstitial()
ad_inst.request_Banner()
root = ScreenManager()
for x in range(4):
root.add_widget(CustomScreen(name='Screen %d' % x))
return root
def on_pause(self):
return True
def on_resume(self):
#request new interstitial if needed
ad_inst.request_Interstitial()
if __name__ == '__main__':
ScreenManagerApp().run()