+ All Categories
Home > Technology > 20130409 1 developing apps for android with kivy

20130409 1 developing apps for android with kivy

Date post: 12-May-2015
Category:
Upload: droidcon-berlin
View: 2,999 times
Download: 4 times
Share this document with a friend
Popular Tags:
40
Developing Apps for Android and Other Platforms with Kivy and Python Andreas Schreiber <[email protected]> droidcon 2013, Berlin, 09. April 2013 www.DLR.de Chart 1 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013
Transcript
Page 1: 20130409 1 developing apps for android with kivy

Developing Apps for Android and Other Platforms with Kivy and Python Andreas Schreiber <[email protected]> droidcon 2013, Berlin, 09. April 2013

www.DLR.de • Chart 1 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

Page 2: 20130409 1 developing apps for android with kivy

Outline

• Introduction • Python • Kivy • Demos • Limitations • Credits

www.DLR.de • Chart 2 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

Page 3: 20130409 1 developing apps for android with kivy

Me

www.DLR.de • Chart 3 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

Scientist, Head of department

Founder, CEO

Enthusiastic about Python

Page 4: 20130409 1 developing apps for android with kivy

DLR German Aerospace Center

− Research Institution − Space Agency − Project Management Agency

www.DLR.de • Chart 4 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

Page 5: 20130409 1 developing apps for android with kivy

Locations and employees

7400 employees across 32 institutes and facilities at 16 sites.

Offices in Brussels, Paris, Tokyo and Washington. ~1400 employees develop software

Cologne

Oberpfaffenhofen

Braunschweig

Goettingen

Berlin

Bonn

Neustrelitz

Weilheim

Bremen Trauen

Lampoldshausen

Stuttgart

Stade

Augsburg

Hamburg

Juelich

www.DLR.de • Chart 5 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

Page 6: 20130409 1 developing apps for android with kivy

Python

www.DLR.de • Chart 6 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

Page 7: 20130409 1 developing apps for android with kivy

Python

• General-purpose, high-level programming language • Object-oriented, aspect-oriented, functional • Dynamic type system • Easy-to-learn with clear and expressive syntax

def faculty(x): if x > 1: return x * faculty(x - 1) else: return 1

Page 8: 20130409 1 developing apps for android with kivy

Python on Mobile Devices

Early Mobile Development with Python • PyS60 for Symbian • Python CE for Windows Mobile

Current Mobile Development with Python • Scripting Layer for Android (SL4A) • Python for Android (Py4A) • PySide / Qt for Android • WinRT / IronPython for Windows 8 • Kivy…

www.DLR.de • Chart 8 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

Page 9: 20130409 1 developing apps for android with kivy

Kivy

www.DLR.de • Chart 9 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

Page 10: 20130409 1 developing apps for android with kivy

Kivy

• Platform-independent Python-Framework

• Available for • Android • iOS • Meego • Windows • Linux • OSX • (Raspberry Pi)

• Development in Python on all platforms

• Not emulated!

www.DLR.de • Chart 10 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

kivy.org

Page 11: 20130409 1 developing apps for android with kivy

Kivy Basics

• Framework for Natural User Interfaces (NUI) • Touchscreens / Multi-Touch

• GPU accelerated graphics

• Based on OpenGL ES 2.0

• Suitable for prototypes as well as products • Porting to new platforms is easy

www.DLR.de • Chart 11 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

Page 12: 20130409 1 developing apps for android with kivy

Kivy Software

• Open Source (LGPL), 7 Core developer

• Source code: https://github.com/kivy

• Documentation: http://kivy.org/docs

• Kivy on Google Play: https://play.google.com/store/apps/details?id=org.kivy.pygame

www.DLR.de • Chart 12 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

Page 13: 20130409 1 developing apps for android with kivy

Kivy says Hello!

www.DLR.de • Chart 13 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

from kivy.app import App from kivy.uix.button import Button class HelloApp(App): def build(self): return Button(text='Hello Berlin') HelloApp().run()

Page 14: 20130409 1 developing apps for android with kivy

www.DLR.de • Chart 14 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

Page 15: 20130409 1 developing apps for android with kivy

Development with Kivy

• Python for widgets, input, program logic

• Language KV for layout und graphics

• Cython for low-level access to graphic routines

www.DLR.de • Chart 15 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

Page 16: 20130409 1 developing apps for android with kivy

“Hello Berlin” with KV

www.DLR.de • Chart 16 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

from kivy.app import App class HelloApp(App): pass HelloApp().run()

#:kivy 1.0 Button: text: ‘Hello Berlin’

File hello.kv defines root widget

Page 17: 20130409 1 developing apps for android with kivy

Example: Pong

www.DLR.de • Chart 17 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

import kivy from kivy.app import App from kivy.uix.widget import Widget class PongGame(Widget): pass class PongApp(App): def build(self): return PongGame() if __name__ == '__main__': PongApp().run()

Page 18: 20130409 1 developing apps for android with kivy

Pong Graphics

www.DLR.de • Chart 18 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

#:kivy 1.6.0 <PongGame>: canvas: Rectangle: pos: self.center_x - 5, 0 size: 10, self.height Label: font_size: 70 center_x: root.width / 4 top: root.top - 50 text: "0" Label: font_size: 70 center_x: root.width * 3 / 4 top: root.top - 50 text: "0"

Page 19: 20130409 1 developing apps for android with kivy

Pong

www.DLR.de • Chart 19 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

Full example: http://kivy.org/docs/tutorials/pong.html

Page 20: 20130409 1 developing apps for android with kivy

Accessing Java Classes from Python • Smartphones have many APIs

• Camera, Compass, Contacts, Location, …

• Access from Python via PyJNIus • https://github.com/kivy/pyjnius • Implemented with JNI and Java reflection

Example

www.DLR.de • Chart 20 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

from jnius import autoclass Hardware = autoclass('org.renpy.android.Hardware') print 'DPI is', Hardware.getDPI()

Page 21: 20130409 1 developing apps for android with kivy

Packaging

• Creating packages for Windows, OSX, Android und iOS: http://kivy.org/docs/guide/packaging.html

www.DLR.de • Chart 21 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

Page 22: 20130409 1 developing apps for android with kivy

Build Tools

Tool chain • Python-for-android • Cross compiler for ARM • Android SDK & NDK • Python and some Python packages

Buildozer • Hides the complexity: Downloads, compiles, packages Kivy source code • https://github.com/kivy/buildozer

www.DLR.de • Chart 22 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

% buildozer android debug deploy run

Page 23: 20130409 1 developing apps for android with kivy

Demos

www.DLR.de • Chart 23 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

Page 24: 20130409 1 developing apps for android with kivy

Kivy Showcase

www.DLR.de • Chart 24 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

Page 25: 20130409 1 developing apps for android with kivy

Kivy Pictures

www.DLR.de • Chart 25 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

Page 26: 20130409 1 developing apps for android with kivy

Small Dragon Luki Speech therapy game for kids

www.DLR.de • Chart 26 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

Page 27: 20130409 1 developing apps for android with kivy

Small Dragon Luki

www.DLR.de • Chart 27 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

Page 28: 20130409 1 developing apps for android with kivy

MQTT Client

www.DLR.de • Chart 28 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

Page 29: 20130409 1 developing apps for android with kivy

Steering Plant Growth • Webcam takes picture of plants

• Computer detects plant

• Computer generates an image for

lighting

• Light source (e.g., a projector) illuminates the plant using the generated image

mobile.cologne > Andreas Schreiber • Plattformübergreifende Apps entwickeln mit Kivy und Python > 08.11.2012 www.DLR.de • Folie 29

Page 30: 20130409 1 developing apps for android with kivy

www.DLR.de • Chart 30 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

Page 31: 20130409 1 developing apps for android with kivy

www.DLR.de • Chart 31 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

Page 32: 20130409 1 developing apps for android with kivy

www.DLR.de • Chart 32 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

Page 33: 20130409 1 developing apps for android with kivy

www.DLR.de • Chart 33 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

Page 34: 20130409 1 developing apps for android with kivy

Other Examples…

www.DLR.de • Chart 34 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

Page 35: 20130409 1 developing apps for android with kivy

iOS-App Deflectouch

https://itunes.apple.com/de/app/deflectouch/id505729681

Page 36: 20130409 1 developing apps for android with kivy

iOS/Android-App ProcessCraft

https://itunes.apple.com/gb/app/processcraft/id526377075 http://showgen.com

Page 37: 20130409 1 developing apps for android with kivy

Limitations

www.DLR.de • Chart 37 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

Page 38: 20130409 1 developing apps for android with kivy

Missing, but Planned (or In Progress)

User Interface Designer • Design tool for Kivy Language KV • Planned for GSoC

Abstraction of mobile APIs • Platform-independent Python wrapper for platform APIs (Android, iOS,

Linux/Mac/Windows) • Project Plyer will start as GSoC project maybe Porting to Raspberry Pi • Useful for small/cheap standalone systems • Founded via Crowdsourcing (bountysource.com)

www.DLR.de • Chart 38 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

Page 39: 20130409 1 developing apps for android with kivy

Credits

Thanks to the Kivy developers

• Mathieu Virbel (@mathieuvirbel)

• Thomas Hansen (@hansent)

• Gabriel Pettier (@tshirtman)

• and many others

www.DLR.de • Chart 39 > droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

Page 40: 20130409 1 developing apps for android with kivy

> droidcon 2013 > A. Schreiber • Developing Apps for Android and Other Platforms with Kivy and Python > 09.04.2013

www.DLR.de • Chart 40

Questions?

Andreas Schreiber Twitter: @onyame http:/ /www.dlr.de/sc

Summary • Kivy allows platform-independent development of

apps for Android, iOS, Meego, Windows, OSX and Linux

• Suitable for multi-touch and graphics applications, such as kiosk systems, exhibits, games, …


Recommended