Chet Haase, Android Framework engineer (Graphics & animations)
Romain Guy, ex-Android Framework engineer
&

Chet Haase

Romain Guy

Chet Haase, Android Framework engineer (Graphics & animations)
Romain Guy, ex-Android Framework...
A few weeks ago, Google announced the release of Android 4.4 KitKat.
What’s New
Today we’re going to talk about what’s new in Android. We won’t be able to cover
everything but we’d like to hi...
Today we’re going to talk about what’s new in Android. We won’t be able to cover
everything but we’d like to highlight som...
The first device to run with Android 4.4 KitKat is the newly released Google Nexus 5.
It’s not the focus of our talk but he...
In September 2013, we announced a total of 1 billion activated Android devices.
One year ago, in September 2012, there wer...
1,000,000,000
devices activated

In September 2013, we announced a total of 1 billion activated Android devices.
One year ...
Device activations

Here is a brief recap of the total number of activated Android devices since mid-2011.
Device activations
1,000

750

500
400
190

250

300

100
May 11

Oct 11

Jan 12

Feb 12

Jun 12

Sep 12

Mar 13

Here is ...
JellyBean is now on >50% of Android devices and ICS 20%. Honeycomb barely registers at 0.1%.
Froyo < 2%

JB 52%

GB 26%

HC
ICS 20%
JellyBean is now on >50% of Android devices and ICS 20%. Honeycomb barely registers...
API 15-18
72%

This means 72% of devices run API level 15 (ICS) or higher.

API 8-13
28%
1

Documents
Storage Access
Framework
The new storage API makes it easy for users to browse and open local & cloud-based documents.
An ...
private static final int READ_REQUEST_CODE = 1;
public void performFileSearch() {
Intent intent =
new Intent(Intent.ACTION...
public class MyDocsProvider extends DocumentsProvider {
@Override
public Cursor queryRoots(String[] projection);
@Override...
<provider
android:name="com.example.mycloud.MyCloudProvider"
android:authorities="com.example.mycloud.provider"
android:gr...
Printing

New printing APIs can be used to add printing capabilities to almost any kind of content.
In particular, you can...
PdfDocument document = new PdfDocument();
PageInfo pageInfo = new PageInfo.Builder(
new Rect(0, 0, 100, 100), 1).create();...
PrintHelper bitmapPrinter =
new PrintHelper(getActivity());
bitmapPrinter.setScaleMode(PrintHelper.SCALE_MODE_FIT);
Bitmap...
2

User interface
Translucent system UI

Android 4.4 allows applications to draw behind the status bar and the navigation bar.
Theme.Holo.NoActionBar.TranslucentDecor
Theme.Holo.Light.NoActionBar.TranslucentDecor

There are two new themes you can us...
<LinearLayout
android:fitsSystemWindows="true"
android:orientation="vertical"
android:layout_width="match_parent"
android:...
Immersive mode

We have a new immersive full-screen mode that hides the system UI even while the user interacts
with the a...
private void hideSystemUI() {
mDecorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LA...
private void showSystemUI() {
mDecorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LA...
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
mDeco...
Fullscreen & hide navigation
Here are a few guidelines to help you choose the most appropriate mode.
If your app needs a “...
Immersive, fullscreen & hide
navigation
If your app is a content reader (books, magazines, articles, etc…)
use the IMMERSI...
Immersive sticky, fullscreen &
hide navigation
If your app is a game or a drawing app – an app that requires a lot of inte...
New WebView

Android 4.4 introduces a completely new backend for WebView, based on the
Chromium Open Source project that p...
Android 4.4 introduces a completely new backend for WebView, based on the
Chromium Open Source project that powers Chrome....
WebView webView = (WebView) findViewById(R.id.html_content);
// Enable remote debugging
webView.setWebContentsDebuggingEna...
Connect your device over USB to a computer running Chrome and visit
chrome://inspect to start debugging your WebView.
chrome://inspect

Connect your device over USB to a computer running Chrome and visit
chrome://inspect to start debugging ...
Connect your device over USB to a computer running Chrome and visit
chrome://inspect to start debugging your WebView.
Scenes & transitions
// 1. From scratch
Scene(ViewGroup);
Scene.setEnterAction(Runnable);

Scenes
// 2. From a layout resource
Scene.getSceneForLayout(sceneRoot,
R.layout.someId, context);

Scenes
// 3. From existing ViewGroup
Scene(ViewGroup, ViewGroup);

Scenes
// 1. Individual transitions
new ChangeBounds();
new Fade();

Transitions
// 2. Transition groups
TransitionSet set = new TransitionSet();
set.addTransition(new ChangeBounds())
.addTransition(new ...
// 3. From XML
<transitionSet>
<changeBounds/>
<fade/>
</transitionSet>

Transitions
void captureStartValues(TransitionValues);
void captureEndValues(TransitionValues);
Animator createAnimator(ViewGroup,
Tra...
// Inflate from XML
tm = TransitionInflater.inflateTransitionManager(
R.transition.mgr, root);
<transitionManager>
<transi...
// Build transition sequences manually
TransitionManager tm = TransitionManager();
tm.setTransition(Scene, Transition);
tm...
// Different ways to trigger transitions
Scene.enter();
TransitionManager.go(Scene);
TransitionManager.go(Scene, Transitio...
TransitionManager.beginDelayedTransition(ViewGroup);

The easy way
3

Accessibility & I18N
Closed captioning are now controlled by system-wide settings, found under Accessibility.
Apps can access and adjust these ...
// Add local source for English subtitles
mVideoView.addSubtitleSource(
getResources().openRawResource(R.raw.subs_en_vtt),...
CaptioningManager manager = (CaptioningManager)
context.getSystemService(Context.CAPTIONING_SERVICE);
manager.addCaptionin...
Drawables auto-mirroring
In RTL mode drawables sometimes have to be mirrored (arrows for instance.) Until now
it required ...
<nine-patch
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/spinner_ab_default_holo_ligh...
Drawable d = resources.getDrawable(R.drawable.spinner);
d.setAutoMirrored(true);

You can also of course set the auto-mirr...
Supporting RTL locales is important to reach out as many users as possible but it can be
difficult to test your applicatio...
4

Performance
Re-usable bitmaps
// Create a 1 MB bitmap, 1 px high, 8 bits per pixel
Bitmap b = Bitmap.createBitmap(1024 * 1024, 1,
Bitmap.Config.ALPHA_8)...
// Create a 1 MB bitmap, 1 px high, 8 bits per pixel
Bitmap b = Bitmap.createBitmap(1024 * 1024, 1,
Bitmap.Config.ALPHA_8)...
Shared
assets texture
Android 4.4 now generates a single texture containing all the framework assets, shared by
all proces...
Re-ordering & merging
This is an example of re-ordering & merging with Android 4.4 on Nexus 7 (2013).
Note how checked and...
Software v-sync
SurfaceFlinger in OpenGL ES 2.0
Asynchronous texture uploads

Other notable graphics improvements. Softwar...
RenderScript
RenderScript is now part of the NDK.
There is also a support library.
mRs = new RSC::RS();
mRs->init(RSC::RS_INIT_LOW_LATENCY | RSC::RS_INIT_SYNCHRONOUS);
mRsElement = RSC::Element::A_8(mRs);
...
performTraversals
draw
getDL

drawDisplayList
flush drawing commands

systrace
systrace got even more useful in Android 4....
Android 4.4 introduces a new overdraw debugging tool that shows you the amount of
overdraw per window.
Project Svelte
Project Svelte was an effort in Android 4.4 to reduce memory usage across the board
(system & apps) to ensu...
Procstats
$ adb shell dumpsys procstats com.google.android.apps.maps
COMMITTED STATS FROM 2013-11-05-18-04-58:
* com.google.android....
ActivityManager activityManager =
(ActivityManager) getSystemService(ACTIVITY_SERVICE);
if (activityManager.isLowRamDevice...
Connectivity &
media

5
Bluetooth HID over GATT (HOGP)
IR blasters
NFC host card emulation
Low-power sensors
Step detection and counting sensors
Adaptive playback
Support for adaptive video playback is now available with the MediaCodec APIs, enabling seamless change ...
Loudness enhancer
The LoudnessEnhancer is a new subclass of AudioEffect that allows you to increase the audible volume of ...
private void setupImageReader() {
mReader = ImageReader.newInstance(width, height, 2);
mReader.setOnImageAvailableListener...
android:sdk $ adb shell screenrecord
/sdcard/my_app.mp4
android:sdk $ adb pull /sdcard/my_app.mp4

Android 4.4 adds a long...
You can also invoke the screen recording command from Android Studio.
The record button can be found in the “Android DDMS”...
You can also invoke the screen recording command from Android Studio.
The record button can be found in the “Android DDMS”...
And more!

6
SELinux set to “enforcing”
Improved cryptographic algorithms
Per-user VPN on multi-user devices
Map<String, List<Drawable>> drawables = new HashMap<>();

Android 4.4 supports new language features such as the diamond o...
String command = getCommand();
switch (command) {
case "start":
start();
break;
case "stop":
stop();
break;
}

It is not p...
try (PrintWriter out = new PrintWriter("data.out")) {
for (String line : getData()) {
out.println(line);
}
} catch (IOExce...
try {
readFile();
} catch (FileNotFoundException | IOException e) {
// Do something useful

}

If several exceptions are t...
New runtime

Android 4.4 offers the option to switch to a new runtime, called ART, for development
purposes only. ART is i...
To enable ART, go to Developer options, and click the “Select runtime” entry.
After selecting ART you will need to reboot ...
Android 4.4 DevBytes
goo.gl/2bpmDA
DevBytes is a series of videos that dive deeper in some of the features presented here....
developer.android.com/about/versions/kitkat.html
developer.android.com/about/versions/android-4.4.html

More info
Chet’s Tips & Tricks
graphics-geek.blogspot.com
Romain’s Tips & Tricks
www.curious-creature.org

More info
Chet Haase
google.com/+ChetHaase

Romain Guy
google.com/+RomainGuy
What's new in android 4.4 - Romain Guy & Chet Haase
What's new in android 4.4 - Romain Guy & Chet Haase
Upcoming SlideShare
Loading in …5
×

What's new in android 4.4 - Romain Guy & Chet Haase

7,272 views

Published on

http://www.paug.fr

Published in: Technology
0 Comments
7 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
7,272
On SlideShare
0
From Embeds
0
Number of Embeds
349
Actions
Shares
0
Downloads
68
Comments
0
Likes
7
Embeds 0
No embeds

No notes for slide

What's new in android 4.4 - Romain Guy & Chet Haase

  1. 1. Chet Haase, Android Framework engineer (Graphics & animations) Romain Guy, ex-Android Framework engineer
  2. 2. & Chet Haase Romain Guy Chet Haase, Android Framework engineer (Graphics & animations) Romain Guy, ex-Android Framework engineer
  3. 3. A few weeks ago, Google announced the release of Android 4.4 KitKat.
  4. 4. What’s New Today we’re going to talk about what’s new in Android. We won’t be able to cover everything but we’d like to highlight some of the most exciting new features for developers and users alike.
  5. 5. Today we’re going to talk about what’s new in Android. We won’t be able to cover everything but we’d like to highlight some of the most exciting new features for developers and users alike.
  6. 6. The first device to run with Android 4.4 KitKat is the newly released Google Nexus 5. It’s not the focus of our talk but here is some info about the specs: 1080p display, 2 GB of RAM, 4-core 2.3 Ghz Snapdragon 800, Adreno 330 GPU, optical image stabilization…
  7. 7. In September 2013, we announced a total of 1 billion activated Android devices. One year ago, in September 2012, there were 500 million Android devices.
  8. 8. 1,000,000,000 devices activated In September 2013, we announced a total of 1 billion activated Android devices. One year ago, in September 2012, there were 500 million Android devices.
  9. 9. Device activations Here is a brief recap of the total number of activated Android devices since mid-2011.
  10. 10. Device activations 1,000 750 500 400 190 250 300 100 May 11 Oct 11 Jan 12 Feb 12 Jun 12 Sep 12 Mar 13 Here is a brief recap of the total number of activated Android devices since mid-2011. Sep 13
  11. 11. JellyBean is now on >50% of Android devices and ICS 20%. Honeycomb barely registers at 0.1%.
  12. 12. Froyo < 2% JB 52% GB 26% HC ICS 20% JellyBean is now on >50% of Android devices and ICS 20%. Honeycomb barely registers at 0.1%.
  13. 13. API 15-18 72% This means 72% of devices run API level 15 (ICS) or higher. API 8-13 28%
  14. 14. 1 Documents
  15. 15. Storage Access Framework The new storage API makes it easy for users to browse and open local & cloud-based documents. An advanced setting even allows to browse the entire file system.
  16. 16. private static final int READ_REQUEST_CODE = 1; public void performFileSearch() { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("image/*"); startActivityForResult(intent, READ_REQUEST_CODE); } You can display the standard UI by using the OPEN_DOCUMENT or CREATE_DOCUMENT intents. The standard UI will show content from all registered document providers.
  17. 17. public class MyDocsProvider extends DocumentsProvider { @Override public Cursor queryRoots(String[] projection); @Override public Cursor queryChildDocuments(String parentDocId, String[] projection, String sortOrder); @Override public Cursor queryDocument(String documentId, String[] projection); @Override public ParcelFileDescriptor openDocument( String documentId, String mode, CancellationSignal signal); } To implement a new document provider you only need to implement these 4 methods. They let you manage the browsing, reading and writing of any local or remote data that can be represented as files/documents.
  18. 18. <provider android:name="com.example.mycloud.MyCloudProvider" android:authorities="com.example.mycloud.provider" android:grantUriPermissions="true" android:exported="true" android:permission="android.permission.MANAGE_DOCUMENTS"> <intent-filter> <action android:name= "android.content.action.DOCUMENTS_PROVIDER" /> </intent-filter> </provider> You need to register your document provider by using the DOCUMENTS_PROVIDER intent filter and requesting the MANAGE_DOCUMENTS permission.
  19. 19. Printing New printing APIs can be used to add printing capabilities to almost any kind of content. In particular, you can print anything you can render to a Canvas.
  20. 20. PdfDocument document = new PdfDocument(); PageInfo pageInfo = new PageInfo.Builder( new Rect(0, 0, 100, 100), 1).create(); Page page = document.startPage(pageInfo); View content = getContentView(); content.draw(page.getCanvas()); document.finishPage(page); document.writeTo(getOutputStream()); document.close(); Android uses PDF as its native printing format, this means you can generate PDF documents from any app that can draw onto a Canvas.
  21. 21. PrintHelper bitmapPrinter = new PrintHelper(getActivity()); bitmapPrinter.setScaleMode(PrintHelper.SCALE_MODE_FIT); Bitmap bitmap = BitmapFactory.decodeResource( getResources(), R.drawable.my_bitmap); bitmapPrinter.printBitmap("Untitled Image", bitmap); The PDF API is powerful but if you want to print properly paginated bitmaps, it is recommended you use helper classes.
  22. 22. 2 User interface
  23. 23. Translucent system UI Android 4.4 allows applications to draw behind the status bar and the navigation bar.
  24. 24. Theme.Holo.NoActionBar.TranslucentDecor Theme.Holo.Light.NoActionBar.TranslucentDecor There are two new themes you can use to request the new translucent system UI.
  25. 25. <LinearLayout android:fitsSystemWindows="true" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" </LinearLayout> If you request translucent sys bars, make sure to use fitsSystemWindows for the portion of your layout that should not be covered by the system UI.
  26. 26. Immersive mode We have a new immersive full-screen mode that hides the system UI even while the user interacts with the application. This was previously only possible for passive content such as videos. This is a great new API for content-rich applications that many of you have been asking for. To bring back the system UI, swipe from the top or bottom edges.
  27. 27. private void hideSystemUI() { mDecorView.setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE); } Hiding the system UI is easy with the new SYSTEM_UI_FLAG_IMMERSIVE flag.
  28. 28. private void showSystemUI() { mDecorView.setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); } To show the UI again, no new flag is necessary. These two methods can be used to toggle the system UI dynamically.
  29. 29. @Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); if (hasFocus) { mDecorView.setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); } } Alternatively you can create a persistent immersive experience that will automatically re-hide the system UI after a short delay or if the user interacts with the middle of the screen.
  30. 30. Fullscreen & hide navigation Here are a few guidelines to help you choose the most appropriate mode. If your app needs a “lean back” experience – often found in video players – use the FULLSCREEN and HIDE_NAVIGATION flags
  31. 31. Immersive, fullscreen & hide navigation If your app is a content reader (books, magazines, articles, etc…) use the IMMERSIVE, FULLSCREEN and HIDE_NAVIGATION flags
  32. 32. Immersive sticky, fullscreen & hide navigation If your app is a game or a drawing app – an app that requires a lot of interaction – use the IMMERSIVE_STICKY, FULLSCREEN and HIDE_NAVIGATION flags
  33. 33. New WebView Android 4.4 introduces a completely new backend for WebView, based on the Chromium Open Source project that powers Chrome. This new WebView improved HTML 5 support, remote debugging, etc.
  34. 34. Android 4.4 introduces a completely new backend for WebView, based on the Chromium Open Source project that powers Chrome. This new WebView improved HTML 5 support, remote debugging, etc.
  35. 35. WebView webView = (WebView) findViewById(R.id.html_content); // Enable remote debugging webView.setWebContentsDebuggingEnabled(BuildConfig.DEBUG); Remote debugging is one of the best new features of the new WebView. First, you must enable debugging on the WebView instance you want to inspect.
  36. 36. Connect your device over USB to a computer running Chrome and visit chrome://inspect to start debugging your WebView.
  37. 37. chrome://inspect Connect your device over USB to a computer running Chrome and visit chrome://inspect to start debugging your WebView.
  38. 38. Connect your device over USB to a computer running Chrome and visit chrome://inspect to start debugging your WebView.
  39. 39. Scenes & transitions
  40. 40. // 1. From scratch Scene(ViewGroup); Scene.setEnterAction(Runnable); Scenes
  41. 41. // 2. From a layout resource Scene.getSceneForLayout(sceneRoot, R.layout.someId, context); Scenes
  42. 42. // 3. From existing ViewGroup Scene(ViewGroup, ViewGroup); Scenes
  43. 43. // 1. Individual transitions new ChangeBounds(); new Fade(); Transitions
  44. 44. // 2. Transition groups TransitionSet set = new TransitionSet(); set.addTransition(new ChangeBounds()) .addTransition(new Fade()); Transitions
  45. 45. // 3. From XML <transitionSet> <changeBounds/> <fade/> </transitionSet> Transitions
  46. 46. void captureStartValues(TransitionValues); void captureEndValues(TransitionValues); Animator createAnimator(ViewGroup, TransitionValues, TransitionValues); Custom transitions
  47. 47. // Inflate from XML tm = TransitionInflater.inflateTransitionManager( R.transition.mgr, root); <transitionManager> <transition android:fromScene="@layout/scene1" android:toScene="@layout/scene2" android:transition="@transition/changebounds" /> <transition android:fromScene="@layout/scene1" android:toScene="@layout/scene3" android:transition="@transition/faderesize" /> </transitionManager> TransitionManager
  48. 48. // Build transition sequences manually TransitionManager tm = TransitionManager(); tm.setTransition(Scene, Transition); tm.setTransition(Scene, Transition, Transition); TransitionManager
  49. 49. // Different ways to trigger transitions Scene.enter(); TransitionManager.go(Scene); TransitionManager.go(Scene, Transition); tm.transitionTo(Scene, Transition); TransitionManager
  50. 50. TransitionManager.beginDelayedTransition(ViewGroup); The easy way
  51. 51. 3 Accessibility & I18N
  52. 52. Closed captioning are now controlled by system-wide settings, found under Accessibility. Apps can access and adjust these settings using the new CaptioningManager.
  53. 53. // Add local source for English subtitles mVideoView.addSubtitleSource( getResources().openRawResource(R.raw.subs_en_vtt), MediaFormat.createSubtitleFormat("text/vtt", Locale.ENGLISH.getLanguage())); // Add local source for French subtitles. mVideoView.addSubtitleSource( getResources().openRawResource(R.raw.subs_fr_vtt), MediaFormat.createSubtitleFormat("text/vtt", Locale.FRENCH.getLanguage())); When you use a VideoView you can now simply pass the captions in WebVTT format. VideoView will take care of rendering the captions according to the user’s preferences.
  54. 54. CaptioningManager manager = (CaptioningManager) context.getSystemService(Context.CAPTIONING_SERVICE); manager.addCaptioningChangeListener(this); CaptioningManager.CaptionStyle style = manager.getUserStyle(); Typeface t = style.getTypeface(); The captioning manager lets you listen to preferences changes and access the style chosen by the user, including the typeface, background color, etc.
  55. 55. Drawables auto-mirroring In RTL mode drawables sometimes have to be mirrored (arrows for instance.) Until now it required the app to embed two versions of each asset, one going in the drawable-rtl/ resource directory. Mirroring is now handled automatically.
  56. 56. <nine-patch xmlns:android="http://schemas.android.com/apk/res/android" android:src="@drawable/spinner_ab_default_holo_light_am" android:autoMirrored="true"> </nine-patch> Here is an example of auto-mirroring taken from Android’s framework resources.
  57. 57. Drawable d = resources.getDrawable(R.drawable.spinner); d.setAutoMirrored(true); You can also of course set the auto-mirror property from code.
  58. 58. Supporting RTL locales is important to reach out as many users as possible but it can be difficult to test your application – and use the system – in Arabic or Hebrew. A new developer option lets you force RTL mode with your favorite locale to test your apps.
  59. 59. 4 Performance
  60. 60. Re-usable bitmaps
  61. 61. // Create a 1 MB bitmap, 1 px high, 8 bits per pixel Bitmap b = Bitmap.createBitmap(1024 * 1024, 1, Bitmap.Config.ALPHA_8); // Use it as a 256x256 32 bits per pixel bitmap b.reconfigure(256, 256, Bitmap.Config.ARGB_8888); // Returns 256x256x4 = ~262 kB int size = b.getByteCount(); // Returns 1024x1024x1 = 1 MB int realSize = b.getAllocatedByteCount(); There is now a distinction between a bitmap’s backing store and its configuration. You can for instance allocate a bitmap that’s larger than what you need. As long as it can hold enough data, you can reconfigure it however you please by changing the width, height and configuration.
  62. 62. // Create a 1 MB bitmap, 1 px high, 8 bits per pixel Bitmap b = Bitmap.createBitmap(1024 * 1024, 1, Bitmap.Config.ALPHA_8); // Re-use our scratch bitmap for decoding BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inBitmap = b; // Resizing is now supported when re-using bitmaps opts.inSampleSize = 2; // Decode an input stream into our bitmap BitmapFactory.decodeStream(in, null, opts); This is of course particularly useful when decoding bitmaps from external resources. You can pre-allocate bitmaps large enough to hold your incoming data and never allocate new bitmaps.
  63. 63. Shared assets texture Android 4.4 now generates a single texture containing all the framework assets, shared by all processes. This saves a bit of memory in every process but it also helps batching and merging drawing operations to optimize applications automatically.
  64. 64. Re-ordering & merging This is an example of re-ordering & merging with Android 4.4 on Nexus 7 (2013). Note how checked and unchecked boxes are drawn together.
  65. 65. Software v-sync SurfaceFlinger in OpenGL ES 2.0 Asynchronous texture uploads Other notable graphics improvements. Software v-sync triggers redraws a little ahead of the hardware v-sync to reduce latency. Async texture uploads improve apps that uses a large number of glyphs (CJK, emojis, etc…)
  66. 66. RenderScript RenderScript is now part of the NDK. There is also a support library.
  67. 67. mRs = new RSC::RS(); mRs->init(RSC::RS_INIT_LOW_LATENCY | RSC::RS_INIT_SYNCHRONOUS); mRsElement = RSC::Element::A_8(mRs); mRsScript = RSC::ScriptIntrinsicBlur::create(mRs, mRsElement); RSC::sp<const RSC::Type> t = RSC::Type::create(mRs, mRsElement, width, height, 0); RSC::sp<RSC::Allocation> ain = RSC::Allocation::createTyped(mRs, t, RS_ALLOCATION_MIPMAP_NONE, RS_ALLOCATION_USAGE_SCRIPT | RS_ALLOCATION_USAGE_SHARED, inImage); RSC::sp<RSC::Allocation> aout = RSC::Allocation::createTyped(mRs, t, RS_ALLOCATION_MIPMAP_NONE, RS_ALLOCATION_USAGE_SCRIPT | RS_ALLOCATION_USAGE_SHARED, outImage); mRsScript->setRadius(radius); mRsScript->setInput(ain); mRsScript->forEach(aout); This is how Android’s hardware renderer uses RenderScript intrinsics. This gives the renderer a 2-3x boost over native code when applying blurs to textures.
  68. 68. performTraversals draw getDL drawDisplayList flush drawing commands systrace systrace got even more useful in Android 4.4, with new tags (animations, inflation, etc.) and the ability to use it from monitor (DDMS). Let’s look at a demo, using Launcher.
  69. 69. Android 4.4 introduces a new overdraw debugging tool that shows you the amount of overdraw per window.
  70. 70. Project Svelte Project Svelte was an effort in Android 4.4 to reduce memory usage across the board (system & apps) to ensure KitKat can run well on devices with 512 MB of physical RAM.
  71. 71. Procstats
  72. 72. $ adb shell dumpsys procstats com.google.android.apps.maps COMMITTED STATS FROM 2013-11-05-18-04-58: * com.google.android.apps.maps / u0a60: TOTAL: 1.1% Service: 1.1% (Cached): 99% (98MB-98MB-99MB/96MB-97MB-97MB over 7) Run time Stats: Screen Off / Norm / +1h19m25s22ms Screen On / Norm / +10m43s963ms TOTAL: +1h30m8s985ms Start time: 2013-11-05 18:04:58 Total elapsed time: +5h9m53s44ms (complete) libdvm.so chromeview
  73. 73. ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); if (activityManager.isLowRamDevice()) { // Modify memory use behavior }
  74. 74. Connectivity & media 5
  75. 75. Bluetooth HID over GATT (HOGP) IR blasters NFC host card emulation Low-power sensors Step detection and counting sensors
  76. 76. Adaptive playback Support for adaptive video playback is now available with the MediaCodec APIs, enabling seamless change in resolution during playback onto a Surface. You can feed the decoder input frames of a new resolution and the resolution of the output buffers change without a significant gap.
  77. 77. Loudness enhancer The LoudnessEnhancer is a new subclass of AudioEffect that allows you to increase the audible volume of your MediaPlayer or AudioTrack. This can be especially useful in conjunction to increase the volume of spoken audio tracks while other media is currently playing.
  78. 78. private void setupImageReader() { mReader = ImageReader.newInstance(width, height, 2); mReader.setOnImageAvailableListener(this, mHandler); playVideo(mReader.getSurface()); } @Override public void onImageAvailable(ImageReader reader) { Image image = reader.acquireLatestImage(); for (Image.Plane plane : image.getPlanes()) { processImageData(plane.getBuffer(), image.getWidth(), image.getHeight()); } } The new ImageReader API provides you direct access to image buffers as they are rendered into a Surface. The Image object provides direct access to the image's timestamp, format, dimensions, and pixel data.
  79. 79. android:sdk $ adb shell screenrecord /sdcard/my_app.mp4 android:sdk $ adb pull /sdcard/my_app.mp4 Android 4.4 adds a long awaited feature: screen recording. The screenrecord command can record a video of your device for a duration of up to 3 minutes.
  80. 80. You can also invoke the screen recording command from Android Studio. The record button can be found in the “Android DDMS” panel (Alt-6).
  81. 81. You can also invoke the screen recording command from Android Studio. The record button can be found in the “Android DDMS” panel (Alt-6).
  82. 82. And more! 6
  83. 83. SELinux set to “enforcing” Improved cryptographic algorithms Per-user VPN on multi-user devices
  84. 84. Map<String, List<Drawable>> drawables = new HashMap<>(); Android 4.4 supports new language features such as the diamond operator. The compiler can infer the type of the right-hand side expression for us. This feature is retro-compatible.
  85. 85. String command = getCommand(); switch (command) { case "start": start(); break; case "stop": stop(); break; } It is not possible to use String types in switch statements. This makes the code a lot more readable than a series of if (mystring.equals(“astring”)). This feature is retro-compatible.
  86. 86. try (PrintWriter out = new PrintWriter("data.out")) { for (String line : getData()) { out.println(line); } } catch (IOException e) { // Do something smart } Automatic resource management will take care of calling close() for you. No more try/catch for IOException around close() calls in your finally statement! Auto resource management works on classes that implement AutoCloseable, present in API level 19 only.
  87. 87. try { readFile(); } catch (FileNotFoundException | IOException e) { // Do something useful } If several exceptions are thrown in a block of code and needs to be handled the same way, you can now catch them all with a single catch without catching a base class. This feature is retro-compatible.
  88. 88. New runtime Android 4.4 offers the option to switch to a new runtime, called ART, for development purposes only. ART is included so you can test your application but Dalvik should remain the default runtime for normal use.
  89. 89. To enable ART, go to Developer options, and click the “Select runtime” entry. After selecting ART you will need to reboot the device.
  90. 90. Android 4.4 DevBytes goo.gl/2bpmDA DevBytes is a series of videos that dive deeper in some of the features presented here. They are a great resource and highly recommended if you want to learn more about the new Android 4.4 APIs.
  91. 91. developer.android.com/about/versions/kitkat.html developer.android.com/about/versions/android-4.4.html More info
  92. 92. Chet’s Tips & Tricks graphics-geek.blogspot.com Romain’s Tips & Tricks www.curious-creature.org More info
  93. 93. Chet Haase google.com/+ChetHaase Romain Guy google.com/+RomainGuy

×