Skip to content

Instantly share code, notes, and snippets.

@tshirtman
Created Feb 6, 2013
Embed
What would you like to do?
from kivy.app import App
from kivy.lang import Builder
from jnius import autoclass
from kivy.properties import BooleanProperty
Context = autoclass('org.renpy.android.PythonActivity')
context = Context.mActivity
vibrator = context.getSystemService(Context.VIBRATOR_SERVICE)
kv = '''
FloatLayout:
Button:
size_hint: .4, .1
pos_hint: {'center_x': .5, 'top': .1}
on_press: app.feedback()
text: 'touch me'
Button:
size_hint: .3, .3
pos_hint: {'center_x': .5, 'y': .3}
on_touch_down: args[1].ud['inside'] = self.collide_point(*args[1].pos)
on_touch_move: app.limit_feedback(self, args[1])
text: 'enter/leave me'
'''
class HapticApp(App):
inside = BooleanProperty(False)
def build(self):
return Builder.load_string(kv)
def feedback(self):
vibrator.vibrate(10)
print "vibrate?"
def limit_feedback(self, button, touch):
ud = touch.ud
collide = button.collide_point(*touch.pos)
if ud['inside'] != collide:
self.feedback()
ud['inside'] = collide
if __name__ == '__main__':
HapticApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment