Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS Proximity Sensor #362

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ Supported APIs
Platform Android iOS Windows OS X Linux
================================== ======= === ======= ==== =====
Accelerometer X X X X
Barometer X X
Audio recording X
Barometer X X
Battery X X X X X
Bluetooth
Brightness X X X
Expand All @@ -47,13 +47,13 @@ Flash X X
GPS X X
Gravity X
Gyroscope X X
Humidity X
IR Blaster X
Light X
Native file chooser X X X
Notifications X X X X
Orientation X
Proximity X
Humidity X
Proximity X X
Sms (send messages) X X
Spatial Orientation X
Storage Path X X X X
Expand Down
6 changes: 3 additions & 3 deletions examples/proximity/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from kivy.app import App
from kivy.clock import Clock
from kivy.lang import Builder
from kivy.properties import BooleanProperty
from kivy.properties import StringProperty
from kivy.properties import ObjectProperty
from kivy.uix.boxlayout import BoxLayout

Expand Down Expand Up @@ -37,7 +37,7 @@
Label:
text: 'Does Proximity Sensor detect something?'
Label:
text: 'Yes' if root.is_near else 'No'
text: root.is_near
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tshirtman I was trying to remove this condition statement from here. That's why String Property.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's a good idea to change the api to simplify a particular example, especially since a lot of other usages would change from:

if obj.is_near:
    do_something()

to

if obj.is_near == 'True':
     do_something()

which is really un-pythonic, the api is better when a boolean value is represented as a boolean.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, you could just change the example to this, to achieve the same effect as your previous solution.

text: str(root.is_near)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"text: str(root.is_near)"
👍


Widget:
Label:
Expand All @@ -51,7 +51,7 @@ class ProximityInterface(BoxLayout):
'''Root Widget.'''

proximity = ObjectProperty()
is_near = BooleanProperty(False)
is_near = StringProperty()

def enable(self):
self.proximity.enable()
Expand Down
7 changes: 6 additions & 1 deletion plyer/platforms/android/proximity.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
'''
Android Proximity
-----------------
'''

from jnius import autoclass
from jnius import cast
from jnius import java_method
Expand Down Expand Up @@ -62,7 +67,7 @@ def _get_proximity(self):
# value is 0.0 when proxime sensor is covered. In other case
# value is 5.0 because in smartphone, optical proximity sensors
# are used.
return value < 5.0
return str(value < 5.0)


def instance():
Expand Down
37 changes: 37 additions & 0 deletions plyer/platforms/ios/proximity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'''
iOS Proximity
-------------
'''

from pyobjus import autoclass
from pyobjus.dylib_manager import load_framework
from plyer.facades import Proximity

load_framework('/System/Library/Frameworks/UIKit.framework')
UIDevice = autoclass('UIDevice')


class iOSProximity(Proximity):

def __init__(self):
super(iOSProximity, self).__init__()
self.device = UIDevice.currentDevice()

def _enable(self):
self.device.setProximityMonitoringEnabled_(True)

def _disable(self):
self.device.setProximityMonitoringEnabled_(False)

def _get_proximity(self):
if self.device.proximityMonitoringEnabled:
if self.device.proximityState:
return str(True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why now returning a string of a boolean, both platforms are coded to return a boolean value anyway?

else:
return str(False)
else:
return 'Proximity Sensor in present in your device.'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"is not present" ?



def instance():
return iOSProximity()