-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
137 lines (111 loc) · 3.89 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
from kivmob import KivMob,TestIds,RewardedListenerInterface
from kivymd.app import MDApp
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
from kivymd.theming import ThemeManager
from kivy.lang import Builder
from kivy.properties import NumericProperty
from kivy.uix.label import Label
from kivymd.toast import toast
Builder.load_string(
'''
#.import MDFloatingActionButton kivymd.uix.button.MDFloatingActionButton
#.import MDRaisedButton kivymd.uix.button.MDRaisedButton
#:import SlideTransition kivy.uix.screenmanager.SlideTransition
<Screenmgr>:
SimpleUI:
InterstitialAdScreen:
Rewarded:
<SimpleUI>:
name:"UI"
Label:
text: "Banner Ads Are shown at bottom"
color:[1,1,1,1]
pos_hint:{"center_x":0.5,"top":1.2}
MDRaisedButton:
text:"Interstitial Ad Screen"
pos_hint:{"center_x":0.5,"top":0.6}
on_release:
app.root.transition = SlideTransition(direction = "left")
app.root.current = "Interstitial"
MDRaisedButton:
text:"Rewarded Video AD Screen"
pos_hint:{"center_x":0.5,"top":0.4}
on_release:
app.root.transition = SlideTransition(direction = "left")
app.root.current = "rewarded"
<InterstitialAdScreen>:
name: "Interstitial"
MDRaisedButton:
text:"Click To see Interstitial"
pos_hint:{"center_x":0.5,"top":0.6}
on_release:
root.Show()
MDRaisedButton:
text:"Back"
pos_hint:{"center_x":0.5,"top":0.8}
on_release:
app.root.transition = SlideTransition(direction = "left")
app.root.current = "UI"
<Rewarded>:
name: "rewarded"
MDLabel:
text:"Points :"+str(app.points)
halign: "center"
MDFloatingActionButton:
icon:"plus"
elevation_normal:2
pos_hint:{"center_x":0.5,"center_y":0.30}
on_release:
app.ads.show_rewarded_ad()
MDRaisedButton:
text:"Leave Screen"
pos_hint:{"center_x":0.5,"top":0.2}
on_release:
app.root.transition = SlideTransition(direction = "left")
app.root.current = "UI"
'''
)
class Screenmgr(ScreenManager):
pass
class SimpleUI(Screen):
pass
class InterstitialAdScreen(Screen):
def on_pre_enter(self, *args):
SimpleApp.ads.request_interstitial() # Intersitial ads is loaded in memory
def on_pre_leave(self, *args):
SimpleApp.ads.request_interstitial() # reloading ad again .
def Show(self):
SimpleApp.ads.show_interstitial()
class Rewarded(Screen):
pass
class SimpleApp(MDApp):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.theme_cls.theme_style="Dark"
self.rewards = Rewards_Handler(self)
ads = KivMob(TestIds.APP) # put your Admob Id in case you want to put your own ads.
points = NumericProperty(0)
def build(self):
self.ads.new_banner(TestIds.BANNER,False)
self.ads.request_banner()
self.ads.show_banner()
self.ads.new_interstitial(TestIds.INTERSTITIAL)
self.ads.load_rewarded_ad(TestIds.REWARDED_VIDEO)
self.ads.set_rewarded_ad_listener(self.rewards)
return Screenmgr()
def load_video(self):
self.ads.load_rewarded_ad(TestIds.REWARDED_VIDEO)
class Rewards_Handler(RewardedListenerInterface):
def __init__(self,other):
self.AppObj = other
def on_rewarded(self, reward_name, reward_amount):
self.AppObj.points += reward_amount # in Sample ad unit default amount is 10
toast("User recieved " +reward_amount+ " points")
def on_rewarded_video_ad_started(self): # Reloading Ad
self.AppObj.load_video()
def on_rewarded_video_ad_completed(self):
self.on_rewarded("Points",10)
def on_rewarded_video_ad_closed(self):
self.AppObj.points += 0
if __name__ == "__main__":
SimpleApp().run()