-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathgps.py
39 lines (30 loc) · 1.3 KB
/
gps.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
from jnius import PythonJavaClass, java_method, autoclass
Looper = autoclass('android.os.Looper')
LocationManager = autoclass('android.location.LocationManager')
PythonActivity = autoclass('org.renpy.android.PythonActivity')
Context = autoclass('android.content.Context')
class GpsListener(PythonJavaClass):
__javainterfaces__ = ['android/location/LocationListener']
def __init__(self, callback):
super(GpsListener, self).__init__()
self.callback = callback
self.locationManager = PythonActivity.mActivity.getSystemService(
Context.LOCATION_SERVICE)
def start(self):
self.locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
10000, 10, self, Looper.getMainLooper())
def stop(self):
self.locationManager.removeUpdates(self)
@java_method('()I')
def hashCode(self):
return id(self)
@java_method('(Landroid/location/Location;)V')
def onLocationChanged(self, location):
self.callback(self, 'location', location)
@java_method('(Ljava/lang/String;)V')
def onProviderDisabled(self, status):
self.callback(self, 'provider-disabled', status)
@java_method('(Ljava/lang/Object;)Z')
def equals(self, obj):
return obj.hashCode() == self.hashCode()