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…
Sep 12 Mar 13 Sep 13 100 190 250 300 400 500 750 1,000 Device activations Here is a brief recap of the total number of activated Android devices since mid-2011.
{ 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.
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.
/> </intent-filter> </provider> You need to register your document provider by using the DOCUMENTS_PROVIDER intent filter and requesting the MANAGE_DOCUMENTS permission.
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.
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.
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.
| 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.
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.
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
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.
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.
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.
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.
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.
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.
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.
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…)
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.
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.
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.
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.
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.
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.
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.
: 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.
// 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.
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.
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.