Honeycomb, Ice Cream Sandwich, and Jelly Bean Features

Android 3.0, nicknamed Honeycomb, introduced the world to the Android tablet. Honeycomb and its subsequent 3.1 and 3.2 releases brought about a number of changes to support this new device class. Android 4.0 Ice Cream Sandwich and 4.1 Jelly Bean refined the ideas introduced in Honeycomb for tablets and brought them to phones, allowing developers to use the same code to support both phones and tablets in a single code base.

The following sections introduce you to some of the features in these three versions (that will be covered throughout this book).

Fragments

Every “page” in an Android application is a separate activity. In older versions of Android, you would place any element that you wanted to display onscreen directly into the activity class. This arrangement worked well when viewed on a phone’s small screen, on which you typically can’t see a lot of information at once. You may be able to see a list of tasks, or a task that you’re editing, but cramming both elements onto the screen at the same time is impossible.

On a tablet, however, you’re swimming in real estate. Not only does it make sense to let users see a list of tasks and edit them on the same page, but it also looks silly not to let them do so. The screen size on a table is simply too big to fill with a single long list of items or lots of empty space.

Android doesn’t allow you to easily put two activities on the screen at the same time. What to do? The answer is the fragment.

Using fragments, a single list fragment can occupy half the screen, and an edit fragment can occupy the other half. You can find out how to use fragments in your phone application in Chapter 9 and how to scale your app to tablets in Chapter 17.

tip.eps You can think of fragments as miniature activities: Because every fragment has its own lifecycle, you know when it’s being created and destroyed, among other information. Fragments go inside activities.

Loaders

A fragment is often used to display data to the user. For example, you might list some tasks by loading the list from the database. However, it’s important to never perform I/O operations on the main user interface thread. If you perform a database operation in the main user interface thread, the user may see the (dreaded) Application Not Responsive dialog box, which is intrusive and confusing and often looks like a crash to many users.

A loader provides an easy way to load data on a background thread so that you don’t delay the user interface (UI) thread and hang your app. You can find out more about loaders in Chapter 10.

Android support library

Fragments and loaders are effective ways to add usefulness to Android 3.x and 4.x applications. However, you may need to support older devices that use Android 1.x and 2.x, which don’t support these new features.

Luckily, Android provides a solution. You can use the Android support library to make fragments and loaders compatible with devices all the way back to the Android Stone Age (circa 2009 A.D.).

In addition to supplying fragments and loaders, the support library adds several other excellent features to old devices, such as:

check.png ViewPager: Swipes pages left and right

check.png GridLayout: A new way to lay out views

check.png ShareCompat: For sharing activities with your friends

tip.eps Visit http://developer.android.com/tools/extras/support-library.html to see the complete list of features in the Android support library.

Action bar

The Menu button is an important element in any application using Android 1.x or 2.x. All Android phones have (unlike another popular type of smartphone) the hardware Menu button, which can be used to access functions that aren’t otherwise shown onscreen.

Or, rather, all Android phones did have this button. Beginning with Android 3.0, Android has dropped the Menu button. It still shows up on a few devices, such as on the Samsung Galaxy S III, but for the most part it’s a relic of the past. Generally speaking, elements placed on the Android menu weren’t easy to find, and users even tended to forget that they were there.

In place of the menu in devices using Android 3.x and later, the action bar is almost always present across the top of the screen — and it’s therefore extremely difficult not to notice. See Figure 1-3 for an example of the action bar from the YouTube application.

Figure 1-3: The YouTube action bar for a funny cat video.




9781118417454-fg0103.tif

Check out these elements on the action bar:

check.png Up Button, app logo: Tap the Up button or the app logo on the action bar to move up one level.

remember.eps Note the subtle distinction between the Up button and the Back button: Pressing the Back button returns the user to the previous activity, regardless of which app is being used; pressing the Up button returns the user to the previous activity in the current application, even if that activity wasn’t an activity the user was just performing.

Suppose that you’re viewing a web page in the Chrome browser and you tap a link to open the YouTube app. Pressing the Back button returns you to Chrome; pressing the Up button takes you to the YouTube app’s home page.

check.png Page: Next to the application icon on the action bar is the title of the current page. If your application lets you filter data on the current page, you can add a drop-down menu there to allow users to change the filter.

check.png Tab: You can put tabs (rather than the page title) on the action bar to let users switch tabs in the current activity.

check.png Action: You can see, on the right end of the action bar, various actions that the user can perform. In the YouTube app shown in Figure 1-3, the user can add the video to a list, share the video, or search for more videos. Actions can take the form of text or icons (as shown in the figure) or both. You can add as many actions as you want. Actions that don’t fit onscreen are placed on an overflow submenu on the right end.

check.png Context action bar: The action bar can change to show what the user is doing. For example, if a user chooses several items from a list, you can replace the standard action bar with a contextual action bar to let users choose actions based on those items. For example, if you want to allow bulk deletions, you can provide a Delete Items button on the contextual action bar.

Visit http://developer.android.com/guide/topics/ui/actionbar.html for more information about the versatility that this element of the user interface can add to your app.

remember.eps The action bar doesn’t exist at all on Android 2.x and earlier! It’s not supported by the support library either. Any action bars you add to your application will not show up in these versions of Android. But don’t dismay, the actions you put in your action bar will still show up under the Menu button for those devices, so users can still find them.

tip.eps If you’re interested in placing the action bar in an app running on an earlier version of Android (on an older phone or on the Kindle Fire, for example), try ActionBarSherlock at http://actionbarsherlock.com .

Holo

Android 3.0 adds three holographic themes to help you create beautiful Android applications:

check.png Holo Dark

check.png Holo Light

check.png Holo Light with dark action bars

These somewhat darker themes may require some getting used to, but they’re much cleaner and more consistent than Android 2.x themes. The Holo themes are also visually less cluttered, which leaves more “real estate” for the important information you want your app to display.

The best quality of Holo is its consistency (at long last) across all Android devices and manufacturers — a manufacturer can’t modify the Holo theme to make its version of Android look different.

Widgets, notifications, performance

The list of new features in Android 3.0, 4.0, and 4.1 seems endless. Here’s a brief description of a few standouts:

check.png Widgets: Widgets are much improved in later versions of Android. They’re easier to find, now that they’ve been moved to the Applications list. You can even add list views to widgets, to handle limited swiping and scrolling, and you can resize widgets to occupy more or less space. In fact, these user-friendly widgets automatically resize as they’re dragged around the screen. These changes make them feel much more lively and responsive than in earlier versions.

check.png Notifications: Android 4.1 brings stylish new options to the formerly staid Android notification system. Because a notification is now expandable and collapsible, a user can see more information about it. For example, if your mother sends you a photo of her new puppy in a text message, you can see it directly in the notification without having to open the app. A notification about a new e-mail message can show a preview of the message text so that it can be read directly.

In addition, a notification now also lets the user take action on it directly from whichever app is being used. To reply to a birthday e-mail from Grandma, for example, simply tap the Reply button on the notification to launch Gmail with an editor so that you can thank her.

check.png Performance: Android 4.1 brings significant performance improvements to the platform. You don’t have to do anything special to benefit from a faster, smoother interface in your app — it will run smoothly on devices running Android 4.1 or later.

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

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