Pro Android Python with SL4A [Ferrill 2011-06-26].pdf
(
5412 KB
)
Pobierz
Build Android Apps
with Python
Android Python
with
SL4A
Paul Ferrill
Pro
For your convenience Apress has placed some of the front
matter material after the index. Please use the Bookmarks
and Contents at a Glance links to access them.
Contents at a Glance
About the Author ....................................................................................................... xi
About the Technical Reviewer .................................................................................. xii
Acknowledgments ...................................................................................................xiii
Preface .................................................................................................................... xiv
■Chapter
1: Introduction ........................................................................................... 1
■Chapter
2: Getting Started ..................................................................................... 27
■Chapter
3: Navigating the Android SDK ................................................................. 57
■Chapter
4: Developing with Eclipse ....................................................................... 83
■Chapter
5: Exploring the Android API .................................................................. 113
■Chapter
6: Background Scripting with Python .................................................... 139
■Chapter
7: Python Scripting Utilities ................................................................... 165
■Chapter
8: Python Dialog Box–based GUIs .......................................................... 195
■Chapter
9: Python GUIs with HTML ...................................................................... 221
■Chapter
10: Packaging and Distributing.............................................................. 249
Index ....................................................................................................................... 2
73
iv
CHAPTER 1
Introduction
This book is about writing real-world applications for the Android platform primarily using the Python
language and a little bit of JavaScript. While there is nothing wrong with Java, it really is overkill when all
you need to do is turn on or off a handful of settings on your Android device. The Scripting Layer for
Android (SL4A) project was started to meet that specific need. This book will introduce you to SL4A and
give you the power to automate your Android device in ways you never thought possible.
Why SL4A?
One of the first questions you probably have about this book is, “Why would I want to use SL4A instead
of Java?” There are several answers to that question. One is that not everyone is a fan of Java. The Java
language is too heavyweight for some and is not entirely open source. It also requires the use of an edit /
compile / run design loop that can be tedious for simple applications. An equally legitimate answer is
simply “I want to use X”, where X could be any number of popular languages.
Google provides a comprehensive software development kit (SDK) aimed specifically at Java
developers, and most applications available from the Android market are probably written in Java. I’ll
address the Android SDK in Chapter 3 and use a number of the tools that come with it throughout the
book.
■
Note
SL4A currently supports Beanshell, JRuby, Lua, Perl, PHP, Python, and Rhino.
SL4A is really targeted at anyone looking for a way to write simple scripts to automate tasks on an
Android device using any of the supported languages, including Java through Beanshell. It provides an
interactive console in which you can type in a line of code and immediately see the result. It even makes
it possible, in many cases, to reuse code you’ve written for a desktop environment. The bottom line is
that SL4A makes it possible both to write code for Android-based devices in languages other than Java
and to do it in a more interactive way.
1
CHAPTER 1
■
INTRODUCTION
The World of Android
Google jumped into the world of mobile operating systems in a big way when it bought Android, Inc. in
2005. It’s really pretty amazing how far it has come in such a short time. The Android community is huge
and has spawned a wide range of conferences, books, and support materials that are easily available
over the Internet.
This is a good point to define a few terms that you’ll see throughout the rest of this book. Android
applications are typically packaged into
.apk
files. These are really just
.zip
files containing everything
needed by the application. In fact, if you rename an
.apk
file to
.zip,
you can open it with any archive
tool and examine the contents.
Most Android devices come from the manufacturer with the systems files protected to prevent any
inadvertent or malicious manipulation. The Android operating system (OS) is essentially Linux at the
core and provides much of the same functionality you would find on any Linux desktop. There are ways
to unlock the system areas and provide
root,
or unrestricted, access to the entire filesystem on an
Android device. This process is appropriately called
rooting
your device, and once complete, the device
is described as
rooted.
SL4A does not require a rooted device, but will work on one if you have chosen
this path.
Android Application Anatomy
Android is based on the Linux operating system (at the time of writing, version 2.6 of the Linux kernel).
Linux provides all the core plumbing such as device drivers, memory and process management, network
stack, and security. The kernel also adds a layer of abstraction between the hardware and applications.
To use an anatomical analogy, you might think of Linux as the skeleton, muscles, and organs of the
Android body.
The next layer up the Android stack is the Dalvik Virtual Machine (DVM). This piece provides the
core Java language support and most of the functionality of the Java programming language. The DVM is
the brains in which the majority of all processing takes place. Every Android application runs in its own
process space in a private instance of the DVM. The application framework provides all the necessary
components needed by an Android application. From the Google Android documentation:
“Developers have full access to the same framework APIs used by the core applications.
The a pplication ar chitecture is des igned to sim plify the r euse o f com ponents. Any
application can publi sh it s ca pabilities, and any other a pplication may th en make
use o f tho se capabilities (s ubject to security con straints enf orced by the fr amework).
This same mechanism allows components to be replaced by the user.
Underlying all applications is a set of services and systems, including:
•
A rich and e xtensible s et of Views th at can be used to build an ap plication,
including lis ts, grids, tex t boxes, butt ons, and ev en an emb eddable w eb
browser
Content Pr oviders that enable a pplications to a ccess dat a f rom other
applications (such as Contacts) or to share their own data
A Resource Manager, pr oviding access to non-code resources such as localiz ed
strings, graphics, and layout files
•
•
2
Plik z chomika:
musli_com
Inne pliki z tego folderu:
100 Questions and Answers to Help You Land Your Dream Android Job_ or to Hire the Right Candidate! [López-Mañas 2015-07-19](1).pdf
(742 KB)
20 Recipes for Programming PhoneGap_ Cross-Platform Mobile Development for Android and iPhone [Munro 2012-04-06](1).pdf
(6551 KB)
50 Android Hacks [Sessa 2013-06-13](2).pdf
(10631 KB)
A Guide to Android for Seniors_ Introduction to Android Phones and Tablets [Hollinder 2015-04-02](1).pdf
(336 KB)
Advanced Android 4 Games [Silva 2011-12-19](1).pdf
(7341 KB)
Inne foldery tego chomika:
3D Design - Programming
ActionScript
Actionscript - Flash - Flex - Air
Ada
ADO
Zgłoś jeśli
naruszono regulamin