31. Introducing the L Developer Preview

At Google I/O 2014, the Android team released the L Developer Preview, or Android L (API Level 20). In the past, if you wanted to get your application working on the latest version of Android, you had to wait until the official release was generally available. The new L Developer Preview releases the upcoming version of Android to early adopter developers and testers, allowing them to get a head start porting their applications to the newest version of Android. Not only are you able to get an early look at the latest APIs and features with the preview, you may even be able to influence the direction of Android by providing feedback to the Android team. This chapter introduces you to the L Developer Preview release of the Android SDK and many of the preview’s newest features.


Image Tip

To get started using the L Developer Preview, you first need to set up the SDK. The Android documentation provides an article titled “Setting Up the Preview SDK,” found at http://d.android.com/preview/setup-sdk.html, which walks you through the steps of downloading the preview SDK, setting up your development environment, and creating your first project.


Exploring the L Developer Preview

The Android L Developer Preview comes with many enhancements to previous features and many new capabilities. Over 5000 new APIs have been added to the L Developer Preview; it probably would require multiple books to cover all of them, so we will narrow our focus in this chapter to some of the most compelling additions to this preview release.


Image Tip

For a more complete overview of the APIs that can be found in the L Developer Preview, see the “API Overview” Android documentation found here: http://d.android.com/preview/api-overview.html.



Image Warning

Because this is a preview release of the Android SDK, the APIs are subject to change, as the preview is still a work in progress. You must download a zip file to access the preliminary reference documentation and learn how the APIs are implemented. You can download the zip file here: http://storage.googleapis.com/androiddevelopers/preview/l-developer-preview-reference.zip.


Improving Performance

One of the goals of the Android team for the L Developer Preview was to improve performance. This preview release is packed with performance enhancements, features, and tools that make creating performant applications much easier than in the past. In this section, we discuss some of those additions.

ART Runtime

The L Developer Preview replaced the Dalvik runtime with a new runtime called ART (Android Runtime), which was originally released in the 4.4 release as an optional and experimental feature. Some of the benefits of ART are:

Image It supports ahead-of-time (AOT) compilation in addition to just-in-time (JIT) compilation, many times resulting in a 2X performance improvement over the Dalvik runtime without requiring a single change to application code for most applications.

Image Garbage collection (GC) pauses have been reduced from two to one, while running parallel processes during the pause, many times reducing garbage collection times from 10 milliseconds to 2 to 4 milliseconds.

Image There are debug tracing improvements during application execution with a dedicated sampling profiler without causing significant performance degradation, including many new debugging options and more information detailing exceptions and crash reports.


Image Warning

You should always test your applications before release to ensure that they work with ART. Most developers will not have to make any changes to their code, but if you are using JNI bindings and native code, or use nonstandard code obfuscation, you may run into issues that require code modification. If you are using JNI bindings and you run into bugs, you should look into using the CheckJNI tool. There is a great blog post about debugging with CheckJNI here: http://android-developers.blogspot.com/2011/07/debugging-android-jni-with-checkjni.html.


Graphics

Support for OpenGL ES 3.1 has been added to the L Developer Preview with both native and Java support, in addition to the Android Extension pack, which brings advanced OpenGL ES 3.1 graphics capabilities. To add support for OpenGL ES 3.1, you need to add the following line of code to your manifest file:

<uses-feature android:glEsVersion="0x00030001" />

These OpenGL ES 3.1 Java interfaces are included with GLES31 and GLES31Ext.

Project Volta

The L Developer Preview introduced an initiative called Project Volta, which aims to provide the necessary tools to help developers optimize battery performance. Some of these features include the following:

Image A new JobScheduler API allows you to implement jobs to be performed upon certain conditions occurring, such as when charging or when connected to Wi-Fi, and even allows you to schedule jobs to execute as a batch to increase efficiency.

Image The dumpsys batterystats developer tool can be run from the ADB shell command line and is useful for generating statistics about usage of the battery on the device.

Image The Battery Historian (historian.par) developer tool can be run from the command line and used for generating an HTML visualization of the device’s power consumption.

Improving the User Experience

Another goal of the Android team for the L Developer Preview was to improve the user experience. This preview release is full of capabilities that make it simple to create visually appealing applications while providing a high-quality user experience. We will be talking about two of the most profound additions to the L Developer Preview: the new material design and enhanced notifications.

Material Design

The first user experience improvement is a new design guideline referred to as material design. The material design guidelines are an attempt to create a seamless experience across all devices, regardless of the form factor or platform, with a mobile-first focus—Android to the Web. These guidelines are founded on a set of principles for improving motion, visual, and interaction design. In addition, the L Developer Preview has also introduced many APIs for implementing these newfound best practices.


Image Tip

Google provides a fantastic resource for learning about the material design guidelines that will most likely evolve over time, so be sure to check these documents frequently for the latest updates and information. You can learn more here: http://www.google.com/design/spec/material-design/introduction.html.


Material Theme

A new material theme has been added to the L Developer Preview which provides an easy way to apply these new styles to your application. Both a light material theme and a dark material theme have been provided. In addition, new color attributes have been defined, the colorPrimary and colorPrimaryDark style attributes. These are useful for defining a light and dark primary color for an application. For example, if you wanted to apply the new material light theme with a dark action bar and two primary colors, you would define the following style and items in your /res/values-v21/styles.xml file:

<style name="Theme.AdvancedAndroid"
    parent="@android:style/Theme.Material.Light/DarkActionBar">
    <item name="android:colorPrimary">
        @color/advanced
    </item>
    <item name="android:colorPrimaryDark">
        @color/advanced_dark
    </item>
</style>


Image Tip

You are now able to recolor drawable resources at runtime either by specifying a tint using the setTint() method in your application code or by defining the android:tint attribute of a <bitmap> tag within a layout.


Complex Views, Animations, and Shadows

Two new View widgets have been added to the L Developer Preview: the RecyclerView and CardView. The RecyclerView is a new type of widget that you should consider using in place of a GridView or a ListView. This View allows for more layout flexibility when displaying items in a list, is better performing, and is much easier to use. When using the RecyclerView, you need to define both a LayoutManager and an Adapter. In addition, RecyclerView animations are provided for adding and removing items, which definitely makes this new widget worth using.

The CardView is a way to present information in a widget that has the appearance of a card. You are able to define attributes such as the card’s corner radius or the card’s background color. You are even able to define a new z axis value by defining an elevation and translationZ value, and when these two values—added together—equal 0 under an orthographic projection, the card will have the appearance of rising above other views on the z axis.

Defining the elevation attribute will also add a shadow to the card, and the higher the elevation, the larger the shadow. As a matter of fact, you are able to define the elevation and translationZ values on all views within Android. Figure 31.1 shows the Google-provided ElevationBasic L Developer Preview sample application (https://github.com/googlesamples/android-ElevationBasic), which implements a z axis for a circle and a square, and when the square is touched, its z axis value changes in relation to the circle.

Image

Figure 31.1 The ElevationBasic sample application with a changing z axis value for the square, before touch (left) and after touch (right).

Enhanced Notifications

Since notifications are such an important part of the Android experience, it’s no wonder that the L Developer Preview introduces many improvements to notifications. Here is a list of the changes made to notifications:

Image Material design improvements have been added to notifications to enhance their visual appearance. If you have already created notifications using the Notification.Builder class, there are really no changes you need to make as Android handles the style differences automatically.

Image Heads-up notifications are a new type of notification introduced for delivering high-priority messages to users while they are performing other tasks on the device.

Image The Lock screen is a new integration point for displaying notifications. You can define visibility levels for these notifications to ensure that sensitive information is protected. Figure 31.2 shows a Lock screen notification created from the CustomNotifications sample application included with the Android SDK.

Image

Figure 31.2 A notification created from the CustomNotifications sample application included with the Android SDK, displayed in the expanded system bar (left) and displayed in collapsed mode on the Lock screen (right).

Image You can sync your notifications across devices through the cloud, and when you dismiss a notification on one device, that notification will be dismissed on all your devices.

Introducing Android TV

In Chapter 10, “Development Best Practices for Tablets, TVs, and Wearables,” we discussed Google TV, which has been around since 2010. Although Google TV is based on Android, the L Developer Preview released a new version of Android for TVs—Android TV.

Included in the L Developer Preview is the v17 leanback library, which is an Android TV support library. This support library is optional for including in your application, but it contains many APIs designed specifically for TVs. In order to include the v17 leanback library, you must also include the v4 support library—v17 depends on v4. The v17 leanback library has special fragments that have been created for TV: the SearchFragment, BrowseFragment, and DetailsFragment.


Image Tip

To learn more about Android TV for the L Developer Preview, visit the following URL: http://d.android.com/preview/tv/index.html.


Understanding Android TV Development Requirements

Included with the L Developer Preview are two Android TV system images. These system images are all you need to get started developing for Android TV. You should always test your applications on real hardware. In order to do so, you need to have access to the ADT-1 Developer Kit, which at the time of this writing is available only upon approved request from Google. This is currently a limitation, as not everyone who requests access will be approved. To apply for access to the ADT-1 Developer Kit, visit https://support.google.com/googleplay/android-developer/contact/adt_request and submit the requested information.

Understanding TV Application Hardware Limitations

TVs do not typically have access to certain hardware that would be included in a phone or tablet. You need to keep this in mind when developing your applications for Android TV, and if for some reason your application uses such hardware when running on other device form factors, you need to make sure that you check for the availability of a particular feature and handle cases where it is not supported. Hardware that is usually not present on a TV includes:

Image Telephony

Image GPS

Image Touchscreen

Image Camera

Image NFC

Image Microphone

Summary

The L Developer Preview is a new version of Android that has been released so that application developers can have a head start on getting their applications working on the newest version of Android before its official release. You have learned about the performance and user experience improvements included in the preview. In addition, you have also learned that APIs for the new Android TV are included in this exciting new preview.

Quiz Questions

1. True or false: There are over 5000 new APIs included with the L Developer Preview.

2. What does ART stand for?

3. What feature should you add to your manifest to begin working with OpenGL ES 3.1?

4. True or false: The JobScheduler API currently does not support executing jobs in batches.

5. What attribute should you define on a View to have a shadow added?

Exercises

1. Use the reference found below—“Setting Up the Preview SDK”—and set up the SDK.

2. Use the Android documentation to determine how to include a CardView in your layout.

References and More Information

Android L Developer Preview: “Setting Up the Preview SDK”:

http://d.android.com/preview/setup-sdk.html

Android L Developer Preview: “API Overview”:

http://d.android.com/preview/api-overview.html

YouTube Google Developers Channel: “Google I/O 2014—The ART Runtime”:

https://www.youtube.com/watch?v=EBlTzQsUoOw

YouTube Google Developers Channel: “Using the Android Job Scheduler”:

https://www.youtube.com/watch?v=QdINLG5QrJc

YouTube Google Developers Channel: “Google I/O 2014—Introduction to Project Volta”:

https://www.youtube.com/watch?v=KzSKIpJepUw

Android L Developer Preview: “Material Design”:

http://d.android.com/preview/material/index.html

Google Design Spec: “Material Design”:

http://www.google.com/design/spec/material-design/introduction.html

YouTube Google Developers Channel: “Google I/O 2014—Material Science: Developing Android Applications with Material Design”:

https://www.youtube.com/watch?v=lSH9aKXjgt8

Android L Developer Preview: “Design for Notifications”:

http://d.android.com/preview/notifications.html

Android L Developer Preview: “Samples”:

http://d.android.com/preview/samples.html

Android L Developer Preview: “Reference”:

http://d.android.com/preview/reference.html

Android L Developer Preview: “Support”:

http://d.android.com/preview/support.html

Android L Developer Preview: “License Agreement”:

http://d.android.com/preview/license.html

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.146.61