How Do I Code Thee? Let Me Count The Ways
-
Upload
best-tech-videos -
Category
Documents
-
view
217 -
download
0
Transcript of How Do I Code Thee? Let Me Count The Ways
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 1/56
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 2/56
How Do I Code Thee?
Let Me Count The Ways.Dan MorrillGoogle Developer Relations
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 3/56
What is Android?
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 4/56
The Layer Cake
4
Linux Kernel
Libraries Android Runtime
Application Framework
Applications
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 5/56
What is Android?
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 6/56
A chunk of code for making phone calls
6 Image by Evi Christodoulou; http://www.flickr.com/search/?q=startac&l=comm&ct=0Licensed under Creative Commons Attribution-Share Alike
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 7/56
A robust network stack and Internet client
7
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 8/56
A Platform for Running Code
8 Image by sludgegulper; http://www.flickr.com/photos/sludgeulper/3441498831/Licensed under Creative Commons Attribution-Share Alike
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 9/56
A Platform for Running Code
• Android has an application platform, true
• But we didn’t create Android in an attempt to “own mobile”
• Android is a framework for interacting components – Apps can pull in pieces of other apps, the web, or even native
9 Image by genvessel; http://www.flickr.com/photos/genvessel/177133869/Licensed under Creative Commons Attribution
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 10/56
"Give me your compiled, your ARM, your huddledbytecodes yearning to run free, the wretched refuse of
your teeming store. Send these, the threadless, scriptedstuff to me, I lift my lamp beside the coder’s door."
10
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 11/56
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 12/56
Anti-Agenda
• I will not...
– Teach you how to write apps – Rehash stuff that’s covered elsewhere
– Pass judgment
12
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 13/56
Three Delicious Flavors
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 14/56
The (current) Three Kinds of Android Code
• Managed Code
• Ajax
• Native Code
14 Images by Sharon Mollerus (http://www.flickr.com/photos/clairity/3229586543/) and Gemma Vittoria (http://www.flickr.com/photos/ggvic/3255129747/)Licensed under Creative Commons Attribution
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 15/56
Dalvik Code
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 16/56
Wait Wait, Hold Up
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 17/56
I Need a Victim
• Interesting but computationally significant
• Efficiently externalizable
• Must make for an interesting visualization
17
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 18/56
How about.... k-means clustering?
• Used to identify clusters in sets of points
• We’ll use a simple 2D version – 500 randomly-generated points
– 6 clusters (ROYGBV)
• Easy to visualize on screen
• 3 implementations – “Pure” Dalvik app (i.e. 100% Java source code)
– Same visualization code with C algorithm implementation
– JavaScript
18
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 19/56
K-Means Clustering in 2,000 Words
19
Source: http://en.wikipedia.org/wiki/K-means_clustering
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 20/56
Dalvik Code
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 21/56
Dalvik - Overview
• Dalvik is a virtual machine, similar to the JVM or .Net CLR
• Memory-protected, garbage-collected, & lifecycle-managed
• Optimized for embedded machines – Built to reduce much of the need for a JITC
• Custom bytecode format; included translator from Java bytecode
21 Image by damon brunson; http://www.flickr.com/photos/blackdudemedia/2495758057/Licensed under Creative Commons Attribution
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 22/56
Dalvik - Writing Apps
• Apps run on Dalvik, which provides core framework APIs
• APIs are backed by system infrastructure in native code – e.g. OpenGL, Binder IPC, media, etc.
• Popular tools are supported, and an Eclipse plugin is available
22
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 23/56
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 24/56
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 25/56
Dalvik - Demo
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 26/56
Dalvik - Examples
• Core system apps
• Currently (nearly) all apps on the Android Market
26
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 27/56
Dalvik - Future
• Improved (faster, better) garbage collection
• Just-In-Time compilation• Optimizations in core libraries
• Additional APIs -- Bluetooth, P2P, and more
27 Image by the Seattle Municipal Archives; http://www.flickr.com/photos/seattlemunicipalarchives/2680241972/Licensed under Creative Commons Attribution
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 28/56
Ajax (Web) Apps
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 29/56
Ajax - Overview
• Apps are broken up into convenient declarative layouts & code
• JavaScript code mutates the DOM to create UI effects• Network access is available via XMLHttpRequest
• Recently, <canvas> allows JavaScript to do direct painting
29 Image by henrybloomfield; http://www.flickr.com/photos/henrybloomfield/2929756532/Licensed under Creative Commons Attribution-No Derivative Works
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 30/56
Ajax on Android - Overview
• Android’s Browser is based on WebKit + SquirrelFish
• WebKit v528.5, equivalent to Safari 4 beta – Reports as 3.1.2 in the user-agent string -- oops!
• Includes Gears 0.5.17.0 (including location)
• Includes support for the <canvas> tag
30
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 31/56
Ajax - What Can You Do?
• Old sk00l
– You can, of course, just build static web page apps
31 Image by Jason Rogers; http://www.flickr.com/photos/restlessglobetrotter/434218278/Licensed under Creative Commons Attribution
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 32/56
Ajax - What Can You Do?
• But you can also build dynamic UIs, via DOM or <canvas>
• You can fetch & store data on your origin server • With HTML5, you can also: – Access location
– Run code outside the main thread
– Store data & pages locally
32
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 33/56
Ajax on Android - What Can’t You Do?
• Android doesn’t currently support HTML5, but does have Gears
• Background processing – Code only runs when Browser is open and your page is loaded
• Access system & framework APIs [1]
33
[1] - Hold that thought, though.
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 34/56
Ajax - Demo
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 35/56
Ajax - Examples
• Google Reader for mobile
• Gmail (web version)• Many mobile web apps (of various fruit flavors)
35
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 36/56
Ajax - Future
• HTML5 will keep getting better
• Android will continue to include a world-class browser – Gears today, HTML5 in the future
– Plans to upgrade to an even faster JSVM
• Who knows what else? I hear the future is a crazy place
36
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 37/56
• Augmented Ajax
D a
l v i k
Ajax - What Else Can You Do?
37
JavaObject
JavaObject
JavaObject
WebView
addJavaScriptInterface
Image by Luis Villa del Campo; http://www.flickr.com/photos/maguisso/271623867/Licensed under Creative Commons Attribution
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 38/56
Augmented Ajax
• Inject functionality into JavaScript
38 Image by Andres Lueda Lopez; http://www.flickr.com/photos/andresrueda/2983149263/Licensed under Creative Commons Attribution-No Derivative Works
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 39/56
Native Code
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 40/56
Native - Overview
• Launched as a Dalvik application
• Loads a dynamic library (.so, ARM ELF, linked against Bionic)• Makes calls into native code via JNI for heavy lifting
• .so files are created using the NDK complement to the SDK
• Work-in-progress NDK added to donut branch in git
40 Image by Thomas; http://www.flickr.com/photos/tomsaint/2678120228/Licensed under Creative Commons Attribution
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 41/56
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 42/56
Native - What Can’t You Do?
• Current set of APIs is limited to libm and libc
• More will be added over time• h@x0r the system -- sandboxing still applies
42
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 43/56
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 44/56
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 45/56
Native - Future
• Add additional libraries, but which? TBD.
– Let us know!• No plans to make native code a fully-independent app model
– ...but there’s no reason to prevent developers from doing stuff
45
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 46/56
Bonus Demo
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 47/56
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 48/56
Some Data
48
Modality Total RenderingTime PercentRendering
Dalvik 614 16 2.6%
JavaScript 936 303 32.4%
Native 127 15 11.2%
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 49/56
Some Data
49
Modality Total RenderingTime PercentRendering
Dalvik 614 16 2.6%
JavaScript 936 303 32.4%
Native 127 15 11.2%
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 50/56
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 51/56
What’s that mean?
• Dalvik is very competitive with other pure-interpreted VMs
• Dalvik, as a front-end for native code, usually beats JavaScript – But clearly, there are use cases where that doesn’t matter
• And of course, custom native code will always win the speed test
51
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 52/56
Groundbreaking, Dynamo-Interactive Flowchart
52
RESTService
Do you
have anexisting website?
Is itAjax?
Doyou need
a website?
Why not?
You shouldgo make itAjaxy.
Doesyour app
need to be reallyfast?
Seriously,now. Really
REALLY
fast?
Yeah, that’swhat I
thought.
DalvikAjax
Okayfine,
Native
Hmm,hold on. Do
you need tightintegration with
system?
AugmentedAjax
Hey,what
languages doyou even
know?
C/C++Java
JavaScriptHaven’t we been
here before?
Ugh, Ihave a
headache.
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 53/56
The Bottom Line
• There’s more than one way to do it
• We aren’t out to shove a paradigm down your throat (ouch?)
53 Image by i_yudai; http://www.flickr.com/photos/y_i/2330044065/Licensed under Creative Commons Attribution
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 54/56
The Bottom Line
• The “centroid” of your app can be anywhere
– Dalvik apps can embed the web; web apps can call to Dalvik – Apps can include native code pieces for better performance
• Understand your app, & decide based on your app’s needs – If you’re doing lots of drawing, use Dalvik
– If you have a web presence already, use (Dalvik-enhanced?) Ajax – If you have large, slow algorithms, use Dalvik + native code
– Your skills do mean something: go with what you know!
54
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 55/56
8/14/2019 How Do I Code Thee? Let Me Count The Ways
http://slidepdf.com/reader/full/how-do-i-code-thee-let-me-count-the-ways 56/56