cannibalize plyer gps example

This commit is contained in:
rgarcia-herrera 2020-07-16 21:12:36 -05:00
parent 586f1ebcfd
commit 1d04daef0f
4 changed files with 45 additions and 52 deletions

View File

@ -1,7 +1,7 @@
[app]
# (str) Title of your application
title = Flockompass
title = flockompass
# (str) Package name
package.name = flockompass
@ -36,7 +36,7 @@ version = 0.1
# (list) Application requirements
# comma separated e.g. requirements = sqlite3,kivy
requirements = python3,kivy,hostpython3,mapview,plyer,requests,urllib3,chardet,idna
requirements = hostpython3, python3, kivy, plyer, android, mapview, requests, urllib3, chardet, idna
# (str) Custom source folders for requirements
# Sets custom source for any requirements with recipes
@ -85,7 +85,7 @@ fullscreen = 0
#android.presplash_color = #FFFFFF
# (list) Permissions
#android.permissions = INTERNET
android.permissions = INTERNET,ACCESS_FINE_LOCATION,ACCESS_COARSE_LOCATION
# (int) Target Android API, should be as high as possible.
#android.api = 27

View File

@ -62,24 +62,12 @@
root.disable()
disable_button.disabled = not disable_button.disabled
enable_button.disabled = not enable_button.disabled
BoxLayout:
orientation: 'vertical'
Label:
text: "Earth's Magnetic Field"
Label:
text: 'including hard iron calibration'
Label:
text: '(' + str(root.x_calib) + ','
Label:
text: str(root.y_calib) + ','
Label:
text: str(root.z_calib) + ')'
Label:
text: app.gps_location
text: root.gps_location
Label:
text: app.gps_status
text: root.gps_status
BoxLayout:
size_hint_y: None
@ -89,10 +77,11 @@
ToggleButton:
text: 'Start' if self.state == 'normal' else 'Stop'
on_state:
app.start(1000, 0) if self.state == 'down' else \
app.stop()
root.start(1000, 0) if self.state == 'down' else \
root.stop()
FloatLayout:
canvas:

68
main.py
View File

@ -1,12 +1,14 @@
from plyer import gps
from kivy.app import App
from kivy.clock import Clock
from kivy.uix.screenmanager import ScreenManager, Screen, RiseInTransition
from kivy.properties import NumericProperty, StringProperty
from kivy.lang import Builder
from kivy_garden.mapview import MapView
from plyer import gps
from kivy.clock import mainthread
from kivy.utils import platform
from kivy.uix.screenmanager import ScreenManager, Screen, RiseInTransition
from kivy_garden.mapview import MapView
from kivy.vector import Vector
from kivy.animation import Animation
from math import floor
@ -23,12 +25,13 @@ class CompassScreen(Screen):
y_calib = NumericProperty(0)
z_calib = NumericProperty(0)
needle_angle = NumericProperty(0)
needle_angle = NumericProperty(0)
gps_location = StringProperty()
gps_status = StringProperty('Click Start to get GPS location updates')
def enable(self):
self.facade.enable()
Clock.schedule_interval(self.get_field, 1 / 20.)
gps.start(1000, 0)
def disable(self):
self.facade.disable()
@ -57,25 +60,6 @@ class CompassScreen(Screen):
self._anim.start(self)
class FlockompassApp(App):
gps_location = StringProperty()
gps_status = StringProperty('Click Start to get GPS location updates')
def request_android_permissions(self):
from android.permissions import request_permissions, Permission
def callback(permissions, results):
if all([res for res in results]):
print("callback. All permissions granted.")
else:
print("callback. Some permissions refused.")
request_permissions([Permission.ACCESS_COARSE_LOCATION,
Permission.ACCESS_FINE_LOCATION],
callback)
def start(self, minTime, minDistance):
gps.start(minTime, minDistance)
@ -89,22 +73,46 @@ class FlockompassApp(App):
def on_resume(self):
gps.start(1000, 0)
@mainthread
def on_location(self, **kwargs):
print('aguas on location')
print(kwargs)
self.gps_location = '\n'.join([
'{}={}'.format(k, v) for k, v in kwargs.items()])
@mainthread
def on_status(self, stype, status):
print('aguas on status')
self.gps_status = 'type={}\n{}'.format(stype, status)
class FlockompassApp(App):
def request_android_permissions(self):
from android.permissions import request_permissions, Permission
def callback(permissions, results):
if all([res for res in results]):
print("aguas: callback. All permissions granted.")
else:
print("aguas: callback. Some permissions refused.Permission.ACCESS_FINE_LOCATION")
request_permissions([Permission.ACCESS_COARSE_LOCATION,
Permission.ACCESS_FINE_LOCATION],
callback)
def build(self):
root = ScreenManager(transition=RiseInTransition())
root.add_widget(MapScreen(name='map'))
cs = CompassScreen(name='compass')
cs._anim = None
try:
gps.configure(on_location=self.on_location,
on_status=self.on_status)
gps.configure(on_location=cs.on_location,
on_status=cs.on_status)
except NotImplementedError:
import traceback
traceback.print_exc()
@ -114,10 +122,6 @@ class FlockompassApp(App):
print("gps.py: Android detected. Requesting permissions")
self.request_android_permissions()
root = ScreenManager(transition=RiseInTransition())
root.add_widget(MapScreen(name='map'))
cs = CompassScreen(name='compass')
cs._anim = None
root.add_widget(cs)
return root

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB