Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot
-
Upload
droidcon-berlin -
Category
Technology
-
view
106 -
download
0
description
Transcript of Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot
![Page 1: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/1.jpg)
New Android APIs:Gingerbread and Honeycomb
![Page 2: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/2.jpg)
New Android APIs:Gingerbread and Honeycomb
24. März 2011Markus Junginger
![Page 3: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/3.jpg)
New Android APIs:Gingerbread and Honeycomb
Markus Junginger@greenrobot_de
![Page 4: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/4.jpg)
New Android APIs:Gingerbread and Honeycomb
@greenrobot_de
![Page 5: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/5.jpg)
New Android APIs:Gingerbread and Honeycomb
![Page 6: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/6.jpg)
New Android APIs:Gingerbread and Honeycomb
![Page 7: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/7.jpg)
About me
Markus Junginger, founder of greenrobot 2007: First Android app 2001: First mobile project 12 years of Java experience 20 years of development experience Android & Mobile Entwicklung Android Technology Usergroup München
![Page 8: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/8.jpg)
Outline
Some history Technical look at new APIs (plus code) Gingerbread APIs
– AudioFX, SIP, NFC, strict mode, NDK Honeycomb APIs
– Hardware accelerated UIs, Animations, Loaders, Renderscript, …
![Page 9: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/9.jpg)
API Changes History
![Page 10: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/10.jpg)
API Changes History
![Page 11: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/11.jpg)
Releases & TimeAPI Version API
LevelSDK Released
Previews since
- 2007-11
1.0 1 2008-09
1.1 2 2009-02
1.5 3 2009-04
1.6 4 2009-09
2.0 5 2009-10
2.0.1 6 2009-12
2.1 7 2010-01
2.2 8 2010-05
2.3 9 2010-12
2.3.3 10 2011-02
3.0 11 2011-02
Release early & often 11 official releases 29 months Every ~3 months a new
release Android developers:
constant progress isyour chance
![Page 12: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/12.jpg)
Android 2.3 Gingerbread
Performance (Concurrent GC, ext4, …) Audio Effects SIP NFC StrictMode NDK revamped
![Page 13: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/13.jpg)
Audio Effects
MediaPlayer & AudioTrack Available Effects
– Equalizer– Bass boost– Environment reverb– Virtualizer– Visualizer
App: Real Time Audio FX
![Page 14: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/14.jpg)
Audio Effects
MediaPlayer & AudioTrack Available Effects
– Equalizer– Bass boost– Environment reverb– Virtualizer– Visualizer
App: Real Time Audio FX
![Page 15: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/15.jpg)
Audio Effects
aid = getAudioSessionId() // or 0 effect = new BassBoost(0, aid) effect.setStrength(1000) effect.setEnable(true) … effect.release()
![Page 16: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/16.jpg)
Audio Effects: Equalizer
android.media.audiofx.Equalizer Frequency bands
– Available number of bands getNumberOfBands()
– Min/Max Level using getBandLevelRange()– setBandLevel(band, level)
![Page 17: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/17.jpg)
SIP – Session Initiation Protocol
Popular for voice and videocalls over IP
General purposeIM, games, etc.
REGISTER INVITE BYE Media separate
![Page 18: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/18.jpg)
SIP – Android Classes
SipManager: central for SIP functionality SipProfile: user account data SipSession: session SipAudioCall: convenience for voice calls
![Page 19: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/19.jpg)
SIP – Basics steps
Get a SipManager Create a “me” and “you” SipProfile Use SipManager establish a call Once established, start audio
![Page 20: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/20.jpg)
SIP – Code for setup
manager = SipManager.newInstance(ctx) builder = new
SipProfile.Builder(username, domain)me = builder.setPassword(password)me = builder.build()
manager.open(me) you = SipProfile.Builder(uri).build() // URI Example: “[email protected]”
![Page 21: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/21.jpg)
SIP – Code for making a call
call = manager.makeAudioCall(me, you, listener, timeoutInSeconds)
SipAudioCall.Listener– onCallEstablished(SipAudioCall call)– call.startAudio()
call.setSpeakerMode(true)call.toggleMute()
![Page 22: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/22.jpg)
SIP – Availability & permissions
Check if SIP is available on deviceisApiSupported, isVoipSupported
Basic permissions– INTERNET, USE_SIP
Audio call permissions– RECORD_AUDIO, ACCESS_WIFI_STATE,
WAKE_LOCK, MODIFY_AUDIO_SETTINGS
![Page 23: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/23.jpg)
Near Field Communication
NFC: wireless communication within ~4cm 13 – 106 Kbyte/s NFC tags variants (e.g. RFID)
– Low-end: Read-only and powerless (cheap!)– …– High-end: full OS, interactive
Device-to-Device (P2P) Major API additions in Android 2.3.3
![Page 24: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/24.jpg)
NFC: Getting notified by Intent
android.permission.NFC <intent-filter><action android:name =
"android.nfc.action.TAG_DISCOVERED" /></intent-filter
android.nfc.extra.NDEF_MESSAGES:Array of NdefMessage object
Works with API Level 9
![Page 25: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/25.jpg)
NfcAdapter
API Level 9– static getDefaultAdapter() (deprecated in 10)– isEnabled: NFC disabled in system settings?
API Level 10– NfcAdapter.getDefaultAdapter(context)– Methods for foreground tag discovery/push
![Page 26: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/26.jpg)
NFC: Foreground actions
Multiple apps can register for NFC tags Foreground NFC: Activity is running has priority over other NFC apps
enableForegroundDispatch: fires Intent (PendingIntent) when NFC tag is read
enableForegroundNdefPush: makes a NDEF tag available
![Page 27: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/27.jpg)
NFC: Notes
API Level 10: more tag technologies– Mifare, A, B, F, V, ISO-DEP– Filters defined in meta-data XML file
Filtering by MIME type (e.g. text/plain) Working with tags is pretty low level bits & bytes
Nexus S must be really close to tag (<4cm)
![Page 28: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/28.jpg)
Strict mode
Tool for developers (helper classes) Detect performance violations in threads
– Network operations– Disk reads/writes
Detect leaks (VM wide)– Activites– Closeable– SQLite objects
![Page 29: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/29.jpg)
Strict mode
Ways to react to violations (penalties)– Log, drop box, dialog, or crash
Strict mode activated & configured in code android.os.StrictMode and inner classes
– Policies– Builders
![Page 30: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/30.jpg)
Strict mode – thread policy code
p= Builder().detectAll().penaltyLog().build() StrictMode.setThreadPolicy(p) Example log with stack trace
03-19 20:21:44.292: DEBUG/StrictMode(32242): StrictMode policy violation; ~duration=336 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=279 violation=203-19
Note: MapActivity triggers violations
![Page 31: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/31.jpg)
NDK in Gingerbread
GCC 4.4.3, ./configure && make C++ STL (Standard template library) Native Activities Less Java wrappers nessesary
– Input and sensor access– Audio (OpenSL)– Windows management / pixel buffers– Direct access to assets in APK
![Page 32: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/32.jpg)
Android 3.0 Honeycomb
Fragments (conceptual) Hardware accelerated UIs Action Bar Loaders Animations Renderscript And more…
![Page 33: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/33.jpg)
Hardware accelerated UIs
Graphics library Skia: CPU based until 2.3 Software rendering, sometimes slow
GPU based rendering is faster (mostly) Switched off by default Manifest entries for application & activity:
android:hardwareAccelerated=„true“ Control for windows and views in code:
view.setLayerType(View.LAYER_TYPE_SOFTWARE, null)
![Page 34: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/34.jpg)
Hardware accelerated UIs, but...
Hard to test– No Android 3.0 device in Germany yet– Emulator falls back to software rendering
(which is really sloooooooooooooooow) Not all operations are supported Some operations render differently Bitmaps must be uploaded as textures
![Page 35: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/35.jpg)
Loader: Asynchronous loading
Loaders address problems of AsynchTask– Don’t restart after configuration changes– Ability to monitor data changes
AsyncTaskLoader http://code.google.com/p/android/issues/detail?id=14944
CursorLoader for ContentProviders LoaderManager from activity or fragment
![Page 36: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/36.jpg)
Using a CursorLoader
getLoaderManager().initLoader(0, null, l) Implement LoaderCallbacks
– onCreateLoader: create loader here– onLoadFinished: receive the result– onLoaderReset: clear the result
Creating the CursorLoader: like ContentResolver.query(URI, projection, selection, sort order)
![Page 37: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/37.jpg)
Property Animations
ValueAnimator: changes value over time ObjectAnimator: applies value to an object Animation Hello World:View text = findViewById(R.id.text);ObjectAnimator anim = ObjectAnimator .ofFloat(text, "alpha", 0f, 1f);anim.setDuration(2000);anim.start();
Much more: sets, listeners, interpolators,...
![Page 38: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/38.jpg)
Renderscript
Portable high performance (vs. NDK) Intermediate LLVM byte code Written in C (C99 standard) Compiled and cached on the device May use CPU or GPU (or even a DSP) Native Renderscript APIs
– Logging, Graphics, Memory Doesn’t run on emulator, hard to debug
![Page 39: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/39.jpg)
HC: A lot more to explore…
New UI widgets, e.g. StackView Improved home screen widgets System clipboard framework Drag & Drop Media, e.g. HTTP adaptive streaming JSON streaming …
![Page 40: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/40.jpg)
So Honeycomb is cool, but…
(Nevertheless: being among the first may be a good strategy)
![Page 41: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/41.jpg)
Android Compatibility package
Downloadable through SDK Manager Some of 3.0 APIs for Android 1.6+
– Fragments– Loader– Utils
Include as jar/source (~100k) Package android.support.v4 won’t use updated APIs on level 11+
![Page 44: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/44.jpg)
Fragments
Modular approach to arrange the UI Fragments can be (re)used in activities Target multiple device categories
![Page 45: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/45.jpg)
Fragment complexity
Activities are not trivial Lifecycle & process
Fragments have alifecycle, too
Interaction with activities Fragment transactions Android just got more
complicated powerful
![Page 46: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/46.jpg)
Action Bar
Part of Honeycomb’s Holographic theme Quick access to Options Menu items <item android:showAsAction="ifRoom" … No room left: overflow menu
![Page 47: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/47.jpg)
Action Bar
Part of Honeycomb’s Holographic theme Quick access to Options Menu items <item android:showAsAction="ifRoom" … No room left: overflow menu
![Page 48: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/48.jpg)
Action Bar, take me home!
App icon (by default) when onOptionsItemSelected() is called
– Check for android.R.id.home– Go to „home“ activity
(Intent.FLAG_ACTIVITY_CLEAR_TOP)
![Page 49: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/49.jpg)
Action Bar, take me home!
App icon (by default) when onOptionsItemSelected() is called
– Check for android.R.id.home– Go to „home“ activity
(Intent.FLAG_ACTIVITY_CLEAR_TOP)
![Page 50: Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot](https://reader034.fdocuments.us/reader034/viewer/2022051613/54c758f24a795909428b4607/html5/thumbnails/50.jpg)
Action Bar: Views and Tabs
Place custom layouts in the action bar<item android:actionLayout="…" … />
And views (use fully qualified class name)<item android:actionViewClass="…" … />
Tabs use Fragments ActionBar: newTab(), addTab() TabListener adds/removes Fragements