-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
226 lines (180 loc) · 5.59 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# -*- coding: utf-8 -*-
# Kivy imports
import kivy
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.tabbedpanel import TabbedPanel
from kivy.uix.slider import Slider
from kivy.clock import Clock
from kivy.utils import platform
from kivy.lib import osc
from kivy.base import EventLoop
# pyjnius imports
from jnius import autoclass
# Android-specific actions
if platform=="android":
PythonActivity=autoclass("org.renpy.android.PythonActivity")
Build=autoclass("android.os.Build$VERSION")
ANDROID_VERSION=Build.RELEASE
# Check Kivy required version
kivy.require("1.8.0")
class BestVibratorAppVibratorController(object):
SERVICE_PORT=3000
def __init__(self, **kwargs):
super(BestVibratorAppVibratorController, self).__init__(**kwargs)
if platform=="android":
from plyer import vibrator
self.vibrator=vibrator
self.check_vibrator()
else:
self.HAS_VIBRATOR=False
def custom_vibrations_time(self, period):
if period <=59:
return str(int(period))+"s"
elif period >=60 and period <=3599:
return str(int(period/60))+"min"
elif period >=3600:
return str(int(period/3600))+"h"
def check_vibrator(self):
if platform=="android":
if not ANDROID_VERSION.startswith("2"):
if self.vibrator.exists():
return "Your device supports vibrations!"
else:
return "Your device doesn't support vibrations!"
else:
return "Your device should support vibrations!"
else:
return "It is not a mobile device!"
def run_vibrator(self, period):
path="/run_vibrator"
osc.sendMsg(path, [period, ], port=self.SERVICE_PORT)
def run_vibrator_schema(self, period, gap):
path="/run_vibrator_schema"
osc.sendMsg(path, [period, gap, ], port=self.SERVICE_PORT)
def stop_vibrator(self):
path="/stop_vibrator"
stop=1
osc.sendMsg(path, [stop, ], port=self.SERVICE_PORT)
class BestVibratorAppServiceController(object):
def __init__(self, **kwargs):
super(BestVibratorAppServiceController, self).__init__(**kwargs)
self.SERVICE_ACTIVE=False
if platform=="android":
from android import AndroidService
self.service=AndroidService("Best Vibrator Service", "running")
self.service.start("Best Vibrator Service started")
self.SERVICE_ACTIVE=True
osc.init()
def service_stop(self):
self.service.stop()
self.SERVICE_ACTIVE=False
class BestVibratorAppWebController(object):
def __init__(self, **kwargs):
super(BestVibratorAppWebController, self).__init__(**kwargs)
import webbrowser
self.webbrowser=webbrowser
if platform=="android":
from plyer import email
self.email=email
def open_website(self, text):
self.webbrowser.open(text)
def send_email_to_dev(self):
if platform=="android":
recipient="rafal.kaczor.1993@gmail.com"
subject="BEST VIBRATOR QUESTION"
text=""
create_chooser=False
self.email.send(recipient,subject,text,create_chooser)
class BestVibratorAppAdsController(object):
def __init__(self, **kwargs):
super(BestVibratorAppAdsController, self).__init__(**kwargs)
if platform=="android":
import random
self.random=random
self.AdBuddiz=autoclass("com.purplebrain.adbuddiz.sdk.AdBuddiz")
#~ self.AdBuddizLogLevel=autoclass("com.purplebrain.adbuddiz.sdk.AdBuddizLogLevel")
self.AdBuddiz.setPublisherKey("XXX")
#~ self.AdBuddiz.setTestModeActive()
#~ self.AdBuddiz.setLogLevel(self.AdBuddizLogLevel.Error)
self.AdBuddiz.cacheAds(PythonActivity.mActivity)
self.WAS_AD_SHOWN=False
self.WAS_EXIT_AD_SHOWN=False
def is_ready(self):
if platform=="android":
if self.AdBuddiz.isReadyToShowAd(PythonActivity.mActivity):
return True
else:
return False
else:
return False
def show_ads(self):
if platform=="android":
if not self.WAS_AD_SHOWN:
if self.is_ready():
tick=self.random.randint(1, 3)
if tick==1:
self.AdBuddiz.showAd(PythonActivity.mActivity)
self.WAS_AD_SHOWN=True
else:
self.WAS_AD_SHOWN=True
def show_exit_ad(self):
if platform=="android":
self.AdBuddiz.showAd(PythonActivity.mActivity)
self.WAS_EXIT_AD_SHOWN=True
else:
self.WAS_EXIT_AD_SHOWN=True
class BestVibratorApp(App):
def __init__(self, **kwargs):
super(BestVibratorApp, self).__init__(**kwargs)
self.serviceController=BestVibratorAppServiceController()
self.vibratorController=BestVibratorAppVibratorController()
self.webController=BestVibratorAppWebController()
self.adsController=BestVibratorAppAdsController()
def on_start(self):
use_kivy_settings=False
EventLoop.window.bind(on_keyboard=self.hook_keyboard)
def open_settings(self, *largs):
pass
def hook_keyboard(self, window, key, *largs):
if key in [27, 1001]:
if self.adsController.WAS_EXIT_AD_SHOWN:
self.close_app()
else:
if self.adsController.is_ready():
self.adsController.show_exit_ad()
else:
self.close_app()
return True
return False
def on_pause(self):
return True
def close_app(self):
if self.serviceController.SERVICE_ACTIVE:
self.vibratorController.stop_vibrator()
self.serviceController.service_stop()
self.stop()
class BestVibratorAppMain(BoxLayout):
pass
class BestVibratorButton(Button):
pass
class BestVibratorLabel(Label):
pass
class BestVibratorSlider(Slider):
pass
class BestVibratorAppMainView(TabbedPanel):
pass
class BestVibratorAppBottomBar(BoxLayout):
pass
class BestVibratorAppTimeView(BoxLayout):
pass
class BestVibratorAppCustomTimeView(BoxLayout):
pass
class BestVibratorAppSchemaView(BoxLayout):
pass
class BestVibratorAppAboutView(BoxLayout):
pass
if __name__=="__main__":
BestVibratorApp().run()