Monday, January 30, 2012

Android Developers on Google+

[This post is by Reto Meier, Android Developer Relations Tech Lead. — Tim Bray]

I’ve been fortunate enough to be involved with Android since the 0.9 preview SDK was released to developers back in 2007. A lot has changed since then, but one thing that hasn’t is the rapid pace at which new tools, resources, and information have become available for us Android developers. Just look at the last few months.

In December Android Training launched, with its first set of classes designed to demonstrate the best practices behind building great Android Apps.

Earlier this month, the Android design site went live — offering a place to learn about the principles, building blocks, and patterns you need to make good design decisions when creating your Android app interfaces.

We’ve got a lot more planned in the coming year, so to help you keep abreast of all the latest Android developer news we’re launching the +Android Developers page on Google+!

One of my favourite things about Google+ is the quality of conversation around posts, so +Android Developers will focus on being a place for the people behind the Android developer experience, and Android developers all around the world, to meet and discuss the latest in Android app development.

We’ll be posting development tips, discussing updates to the SDK and developer tools, highlighting new Android training classes, and posting video and pics from Android developer events around the world.

We’ll also be using Google+ Hangouts to help us all interact even more closely. Starting with weekly broadcast office-hours on Hangouts On Air to answer Android development questions. These will happen every Wednesday at 2pm Pacific Time (10pm UTS) in Mountain View—expect to see these hangouts in more time zones as our teams in London, Sydney, and Tokyo get involved. Each hangout will be recorded for YouTube, so if you can’t join us live you won’t miss out.

It turns out that hangouts are a lot of fun, so we’ll be doing more of these that feature interviews with Google engineers and 3rd party Android app developers willing to share their tips and experiences.

We’re looking forward to interacting with you even more closely, so add us to your circles, join the conversation by commenting on posts, and join the hangouts. We can't wait to hear what you have to say.

You have read this article with the title January 2012. You can bookmark this page URL http://azaquery.blogspot.com/2012/01/android-developers-on-google_30.html. Thanks!
Thursday, January 26, 2012

Say Goodbye to the Menu Button

[This post is by Scott Main, lead tech writer for developer.android.com. — Tim Bray]

Before Android 3.0 (Honeycomb), all Android-powered devices included a dedicated Menu button. As a developer, you could use the Menu button to display whatever options were relevant to the user, often using the activity’s built-in options menu. Honeycomb removed the reliance on physical buttons, and introduced the ActionBar class as the standard solution to make actions from the user options immediately visible and quick to invoke. In order to provide the most intuitive and consistent user experience in your apps, you should migrate your designs away from using the Menu button and toward using the action bar. This isn’t a new concept — the action bar pattern has been around on Android even before Honeycomb. As Ice Cream Sandwich rolls out to more devices, it’s important that you begin to migrate your designs to the action bar in order to promote a consistent Android user experience.

You might worry that it’s too much work to begin using the action bar, because you need to support versions of Android older than Honeycomb. However, it’s quite simple for most apps because you can continue to support the Menu button on pre-Honeycomb devices, but also provide the action bar on newer devices with only a few lines of code changes.

If I had to put this whole post into one sentence, it’d be: Set targetSdkVersion to 14 and, if you use the options menu, surface a few actions in the action bar with showAsAction="ifRoom".

Don’t call it a menu

Not only should your apps stop relying on the hardware Menu button, but you should stop thinking about your activities using a “menu button” at all. Your activities should provide buttons for important user actions directly in the action bar (or elsewhere on screen). Those that can’t fit in the action bar end up in the action overflow.

In the screenshot here, you can see an action button for Search and the action overflow on the right side of the action bar.

Even if your app is built to support versions of Android older than 3.0 (in which apps traditionally use the options menu panel to display user options/actions), when it runs on Android 3.0 and beyond, there’s no Menu button. The button that appears in the system/navigation bar represents the action overflow for legacy apps, which reveals actions and user options that have “overflowed off the screen.”

This might seem like splitting hairs over terminology, but the name action overflow promotes a different way of thinking. Instead of thinking about a menu that serves as a catch-all for various user options, you should think more about which user options you want to display on the screen as actions. Those that don't need to be on the screen can overflow off the screen. Users can reveal the overflow and other options by touching an overflow button that appears alongside the on-screen action buttons.

Action overflow button for legacy apps

If you’ve already developed an app to support Android 2.3 and lower, then you might have noticed that when it runs on a device without a hardware Menu button (such as a Honeycomb tablet or Galaxy Nexus), the system adds the action overflow button beside the system navigation.

This is a compatibility behavior for legacy apps designed to ensure that apps built to expect a Menu button remain functional. However, this button doesn’t provide an ideal user experience. In fact, in apps that don’t use an options menu anyway, this action overflow button does nothing and creates user confusion. So you should update your legacy apps to remove the action overflow from the navigation bar when running on Android 3.0+ and begin using the action bar if necessary. You can do so all while remaining backward compatible with the devices your apps currently support.

If your app runs on a device without a dedicated Menu button, the system decides whether to add the action overflow to the navigation bar based on which API levels you declare to support in the <uses-sdk> manifest element. The logic boils down to:

  • If you set either minSdkVersion or targetSdkVersion to 11 or higher, the system will not add the legacy overflow button.


  • Otherwise, the system will add the legacy overflow button when running on Android 3.0 or higher.


  • The only exception is that if you set minSdkVersion to 10 or lower, set targetSdkVersion to 11, 12, or 13, and you do not use ActionBar, the system will add the legacy overflow button when running your app on a handset with Android 4.0 or higher.


That exception might be a bit confusing, but it’s based on the belief that if you designed your app to support pre-Honeycomb handsets and Honeycomb tablets, it probably expects handset devices to include a Menu button (but it supports tablets that don’t have one).

So, to ensure that the overflow action button never appears beside the system navigation, you should set the targetSdkVersion to 14. (You can leave minSdkVersion at something much lower to continue supporting older devices.)

Migrating to the action bar

If you have activities that use the options menu (they implement onCreateOptionsMenu()), then once the legacy overflow button disappears from the system/navigation bar (because you’ve set targetSdkVersion to 14), you need to provide an alternative means for the user to access the activity’s actions and other options. Fortunately, the system provides such a means by default: the action bar.

Add showAsAction="ifRoom" to the <item> elements representing the activity’s most important actions to show them in the action bar when space is available. For help deciding how to prioritize which actions should appear in the action bar, see Android Design’s Action Bar guide.

To further provide a consistent user experience in the action bar, we suggest that you use action icons designed by the Android UX Team where appropriate. The available icons support common user actions such as Refresh, Delete, Attach, Star, Share and more, and are designed for the light and dark Holo themes; they’re available on the Android Design downloads page.

If these icons don’t accommodate your needs and you need to create your own, you should follow the Iconography design guide.

Removing the action bar

If you don’t need the action bar, you can remove it from your entire app or from individual activities. This is appropriate for apps that never used the options menu or for apps in which the action bar doesn’t meet design needs (such as games). You can remove the action bar using a theme such as Theme.Holo.NoActionBar or Theme.DeviceDefault.NoActionBar.

In order to use such a theme and remain backward compatible, you can use Android’s resource system to define different themes for different platform versions, as described by Adam Powell’s post, Holo Everywhere. All you need is your own theme, which you define to inherit different platform themes depending on the current platform version.

For example, here’s how you can declare a custom theme for your application:

<application android:theme="@style/NoActionBar">

Or you can instead declare the theme for individual <activity> elements.

For pre-Honeycomb devices, include the following theme in res/values/themes.xml that inherits the standard platform theme:

<resources>
<style name="NoActionBar" parent="@android:style/Theme">
<!-- Inherits the default theme for pre-HC (no action bar) -->
</style>
</resources>

For Honeycomb and beyond, include the following theme in res/values-v11/themes.xml that inherits a NoActionBar theme:

<resources>
<style name="NoActionBar" parent="@android:style/Theme.Holo.NoActionBar">
<!-- Inherits the Holo theme with no action bar; no other styles needed. -->
</style>
</resources>

At runtime, the system applies the appropriate version of the NoActionBar theme based on the system’s API version.

Summary

  • Android no longer requires a dedicated Menu button, some devices don’t have one, and you should migrate away from using it.


  • Set targetSdkVersion to 14, then test your app on Android 4.0.


  • Add showAsAction="ifRoom" to menu items you’d like to surface in the action bar.



  • If the ActionBar doesn’t work for your app, you can remove it with Theme.Holo.NoActionBar or Theme.DeviceDefault.NoActionBar.

For information about how you should design your action bar, see Android Design’s Action Bar guide. More information about implementing the action bar is also available in the Action Bar developer guide.

You have read this article Best Practices / User Interface with the title January 2012. You can bookmark this page URL http://azaquery.blogspot.com/2012/01/say-goodbye-to-menu-button_26.html. Thanks!
Monday, January 16, 2012

Southern-hemisphere Developer Labs

We’ve just scheduled Android Developer Labs for Melbourne (January 31), Sydney (February 3), and Auckland (February 8). The material is not introductory; it’s aimed at people with existing apps who want to make them better in the era of Ice Cream Sandwich and tablets. You’ll want to show up with the SDK installed, and a couple of devices.

If this describes you, drop by the ADL page and sign up. You should hurry, because these are not large-scale events and there are more qualified people than there are seats.

You have read this article with the title January 2012. You can bookmark this page URL http://azaquery.blogspot.com/2012/01/southern-hemisphere-developer-labs_16.html. Thanks!
Thursday, January 12, 2012

Introducing the Android Design site

[This post is by Christian Robertson, who leads the Android visual design group. He is also the designer of the Roboto font family. —Tim Bray]

Ice Cream Sandwich (Android 4.0) is our biggest redesign yet — both for users and developers. We’ve enhanced the UI framework with new interactions and styles that will let you create Android apps that are simpler and more beautiful than ever before.



To help you use great UI in your apps, we’re introducing Android Design: the place to learn about principles, building blocks, and patterns for creating world-class Android user interfaces.
Whether you’re a UI professional or a developer playing that role, these docs show you how to make good design decisions, big and small.

The Android User Experience Team is committed to helping you design amazing apps that people love, and this is just the beginning. In the coming months, we’ll expand Android Design with more in-depth content. And watch this blog for a series of posts about design, and invitations to Google+ hangouts on the topics you care about most.

So head on over to Android Design, and make something amazing!

You have read this article User Interface with the title January 2012. You can bookmark this page URL http://azaquery.blogspot.com/2012/01/introducing-android-design-site_12.html. Thanks!
Tuesday, January 10, 2012

Levels in Renderscript

[This post is by R. Jason Sams, an Android Framework engineer who specializes in graphics, performance tuning, and software architecture. —Tim Bray]

For ICS, Renderscript (RS) has been updated with several new features to simplify adding compute acceleration to your application. RS is interesting for compute acceleration when you have large buffers of data on which you need to do significant processing. In this example we will look at applying a levels/saturation operation on a bitmap.

In this case, saturation is implemented by multiplying every pixel by a color matrix Levels are typically implemented with several operations.

  1. Input levels are adjusted.

  2. Gamma correction.

  3. Output levels are adjusted.

  4. Clamp to the valid range.

A simple implementation of this might look like:

for (int i=0; i < mInPixels.length; i++) {
float r = (float)(mInPixels[i] & 0xff);
float g = (float)((mInPixels[i] >> 8) & 0xff);
float b = (float)((mInPixels[i] >> 16) & 0xff);

float tr = r * m[0] + g * m[3] + b * m[6];
float tg = r * m[1] + g * m[4] + b * m[7];
float tb = r * m[2] + g * m[5] + b * m[8];
r = tr;
g = tg;
b = tb;

if (r < 0.f) r = 0.f;
if (r > 255.f) r = 255.f;
if (g < 0.f) g = 0.f;
if (g > 255.f) g = 255.f;
if (b < 0.f) b = 0.f;
if (b > 255.f) b = 255.f;

r = (r - mInBlack) * mOverInWMinInB;
g = (g - mInBlack) * mOverInWMinInB;
b = (b - mInBlack) * mOverInWMinInB;

if (mGamma != 1.0f) {
r = (float)java.lang.Math.pow(r, mGamma);
g = (float)java.lang.Math.pow(g, mGamma);
b = (float)java.lang.Math.pow(b, mGamma);
}

r = (r * mOutWMinOutB) + mOutBlack;
g = (g * mOutWMinOutB) + mOutBlack;
b = (b * mOutWMinOutB) + mOutBlack;

if (r < 0.f) r = 0.f;
if (r > 255.f) r = 255.f;
if (g < 0.f) g = 0.f;
if (g > 255.f) g = 255.f;
if (b < 0.f) b = 0.f;
if (b > 255.f) b = 255.f;

mOutPixels[i] = ((int)r) + (((int)g) << 8) + (((int)b) << 16)
+ (mInPixels[i] & 0xff000000);
}

This code assumes a bitmap has been loaded and transferred to an integer array for processing. Assuming the bitmaps are already loaded, this is simple.

        mInPixels = new int[mBitmapIn.getHeight() * mBitmapIn.getWidth()];
mOutPixels = new int[mBitmapOut.getHeight() * mBitmapOut.getWidth()];
mBitmapIn.getPixels(mInPixels, 0, mBitmapIn.getWidth(), 0, 0,
mBitmapIn.getWidth(), mBitmapIn.getHeight());

Once the data is processed with the loop, putting it back into the bitmap to draw is simple.

        mBitmapOut.setPixels(mOutPixels, 0, mBitmapOut.getWidth(), 0, 0,
mBitmapOut.getWidth(), mBitmapOut.getHeight());

The full code of the application is around 232 lines when you include code to compute the constants for the filter kernel, manage the controls, and display the image. On the devices I have laying around this takes about 140-180ms to process an 800x423 image.

What if that is not fast enough?

Porting the kernel of this image processing to RS (available at android-renderscript-samples) is quite simple. The pixel processing kernel above, reimplemented for RS looks like:

void root(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) {
float3 pixel = convert_float4(in[0]).rgb;
pixel = rsMatrixMultiply(&colorMat, pixel);
pixel = clamp(pixel, 0.f, 255.f);
pixel = (pixel - inBlack) * overInWMinInB;
if (gamma != 1.0f)
pixel = pow(pixel, (float3)gamma);
pixel = pixel * outWMinOutB + outBlack;
pixel = clamp(pixel, 0.f, 255.f);
out->xyz = convert_uchar3(pixel);
}

It takes far fewer lines of code because of the built-in support for vectors of floats, matrix operations, and format conversions. Also note that there is no loop present.

The setup code is slightly more complex because you also need to load the script.

        mRS = RenderScript.create(this);
mInPixelsAllocation = Allocation.createFromBitmap(mRS, mBitmapIn,
Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
mOutPixelsAllocation = Allocation.createFromBitmap(mRS, mBitmapOut,
Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
mScript = new ScriptC_levels(mRS, getResources(), R.raw.levels);

This code creates the RS context. It then uses this context to create two memory allocations to hold the RS copy of the bitmap data. Last, it loads the script to process the data.

Also in the source there are a few small blocks of code to copy the computed constants to the script when they change. Because we reflect the globals from the script this is easy.

        mScript.set_inBlack(mInBlack);
mScript.set_outBlack(mOutBlack);
mScript.set_inWMinInB(mInWMinInB);
mScript.set_outWMinOutB(mOutWMinOutB);
mScript.set_overInWMinInB(mOverInWMinInB);

Earlier we noted that there was no loop to process all the pixels. The RS code that processes the bitmap data and copies the result back looks like this:

        mScript.forEach_root(mInPixelsAllocation, mOutPixelsAllocation);
mOutPixelsAllocation.copyTo(mBitmapOut);

The first line takes the script and processes the input allocation and places the result in the output allocation. It does this by calling the natively compiled version of the script above once for each pixel in the allocation. However, unlike the dalvik implementation, the primitives will automatically launch extra threads to do the work. This, combined with the performance of native code can produce large performance gains. I’ll show the results with and without the gamma function working because it adds a lot of cost.

800x423 image

DeviceDalvikRSGain
Xoom174ms39ms4.5x
Galaxy Nexus139ms30ms4.6x
Tegra 30 device136ms19ms7.2x

800x423 image with gamma correction

DeviceDalvikRSGain
Xoom994ms259ms3.8x
Galaxy Nexus787ms213ms3.7x
Tegra 30 device783ms104ms7.5x

These large gains represent a large return on the simple coding investment shown above.

You have read this article with the title January 2012. You can bookmark this page URL http://azaquery.blogspot.com/2012/01/levels-in-renderscript_10.html. Thanks!
Thursday, January 5, 2012

Moving from Symbian to Android: Where Am I (GPS Navigation)?

One redeeming feature of the Nokia ecosystem is the turn-by-turn, spoken street name, FREE navigation. Later Nokia Maps versions running on Symbian 3 continue to offer class-leading navigation, that give some dedicated GPS devices a run for their money. Nokia's venture into Windows Phone is showing those users what Symbian users have been enjoying for years now.

Let me say from the outset, you will not find a free app like Nokia Maps in the Android ecosystem.

Android uses Google Maps (not even going to hyperlink this) by default. And that's great, if you have a consistent 3G connection, and a fat data allowance. Yes, you can download "offline" map data now, but it is only for a 10 mile (16 km) radius. What happens if you want to do an interstate road trip and not get slammed for data? Not good enough as a Nokia Maps replacement.

Waze is an interesting free solution that relies on other Waze users to provide mapping telemetry. If you live in the US or Europe with lot of other Waze users, you will likely love this app. If you live in Australia, you're probably not going to like it. Not good enough as a reliable mapping solution.


Android Solution:  Sygic


The closest I've come to decent mapping for Android users is Sygic. Sygic provides accurate, offline maps for Australia and New Zealand.

Turn-by-turn, spoken street name navigation is also provided.

Sygic's interface is lovely. Simple, but also incredibly powerful when you need it. Add Points of Interest (POI) from within the application. Or import POI from any compatible source as an overlay to the offline maps.

The only downside of Sygic is the maps for Australia and New Zealand cost about $30. Once you buy the maps, you continue to receive updates forever (perpetual license). That's a lot cheaper than purchasing a dedicated GPS and having to update maps every three years. From what I can tell, if you change or upgrade your Android device, the licence is transferable as well.

But you need to plan ahead and check that points of interest (POI) are present on the map. If not, you can add them, and they are persistent in subsequent searches. You'll probably find that some other Sygic users have uploaded photos of POIs in the area you need, so if you have been there before and know the basic map geography, the photographs help you pick the right location to navigate to with or without a POI entry.

The 7 Day trial of this app is not really long enough: it needs to be a full month. If Sygic offered a month trial on this product, I would not have installed a cracked version because I could test it over multiple trips in the month and see how incredibly worth the $30 it is. Hope you read this Sygic (and I will be making a purchase shortly for the record).

You also have to pay extra for live traffic alerts, per year (ouch). But as one of my colleagues suggested, just fire up google maps when you hit a traffic jam and take a look at the way ahead on the free traffic alert system built-in to Google Maps.


Dishonourable Mention:  Navigon

I only stumbled across this solution by accident, after heading to the SGS2 product site and glancing at the Australia product features of the SGS2. It listed Navigon as being offered as the navigation solution, but the app was nowhere to be found on the device. You would think it should have been at least already installed when you set up the phone or something?

Turns out that you can get completely free Australian and New Zealand Navigon maps for being a Samsung customer. The paid version of Navigon for non-Samsung customers costs upwards of $60, so I see this as a real advantage of being a Samsung customer.

At least that is what I thought...

It all started when I attempted to download the maps initially.

WARNING: When you are downloading the maps initially, do not navigate away from the download screen. Your download will be abandoned, because Navigon in their wisdom do not allow the download to continue in the background, or provide any "WARNING: You are about to stop your download" PEBKAC prevention.

So I managed to download the maps the second time, and start the app. The GPS lock took ages, in direct line of sight of the cloudless blue sky. After 5 minutes, I just closed the app. When I opened the map view, it was like something from GPS units of 4 years ago. Blocky maps, with horrible map panning that would re-draw as you drag the map around.

Navigon and the maps are free. The add-ons are not. There are three to choose from, which give you the same turn by turn guidance and dashboard stuff as Sygic does, and one for Traffic (which is an extra, yearly subscription service in Sygic). The real sour point here is that to purchase all four will cost you more than purchasing an Australian/New Zealand license of Sygic (at current exchange rates).

T O T A L   F A I L

If you need offline maps for Australia and New Zealand, and own a Samsung device, do not even bother with Navigon. Utter rubbish. I'm removing it as I write this blog.
You have read this article android / GPS Navigation / Symbian S3 with the title January 2012. You can bookmark this page URL http://azaquery.blogspot.com/2012/01/moving-from-symbian-to-android-where-am.html. Thanks!

Moving from Symbian to Android: Let the music play

With Symbian 3, there were not many choices for music player software. You really only had the default "Music" software. And even if you could find an alternative music player that offered a similar feature set, you were likely not able to set it as the default player due to Symbian's frustrating "our default apps are better than yours, nyaaaah" attitude.

There was nothing wrong with that Symbian 3 music player. While it was basic, it did have a lovely cover-flow feature (quite iPod like, actually), and good support for many proprietary CODECs.

As soon as I started the Samsung Music Player on the Galaxy S2, I thought to myself "well, I'll be looking for another music player very quickly". The default player is a steaming pile of excrement. I can't really put it any other way, without using stronger language.

In my quest to find an immediate replacement for the player, I chose WinAmp. It is free, it is not that shiny, but it does the job much better than the dookie that is the Samsung Music Player. If you like to use WinAmp on your PC, you'll likely love the fact that you will be able to wirelessly sync your music to your Android phone.

For a really excellent summary of players you can use on Android, check out Joshua Goldman's CNET post: Best Android Music Players. I'm not going to repeat them all here because Joshua has said it all really. For those who want the tl:dr version, choose PlayerPro, PowerAMP, or Audiogalaxy.


You have read this article android / Pros and Cons / Symbian S3 with the title January 2012. You can bookmark this page URL http://azaquery.blogspot.com/2012/01/moving-from-symbian-to-android-let.html. Thanks!
Wednesday, January 4, 2012

Moving from Symbian to Android: O Sleeping Screen, where art thou


I still do miss Sleeping Screen, the impressive free app that turns your Nokia AMOLED phone screen into a minimalistic notification system for your sleeping phone (when your phone is on stand-by).

I followed this app when it was just a promising Nokia Beta Labs offering, until it's maturity into the Nokia Store. The great thing about Sleeping Screen is you get an overview of missed calls, texts, and calendar alarms on your standby screen.

The killer feature offered by this app was that you could use the provided converter to make any photo or image to a reduced-pixel image. Because AMOLED can turn on individual pixels, and requires no LED light source, the pictures consume very little battery, while still offering quite amazing resolution. This gives you ultimate flexibility as to what pictures you want refreshing on your standby screen. You can see some results on my post about Sleeping Screen.

Many Android handsets feature a multi-coloured LED that gives you a basic indication of what notification type you have waiting for you on your handset. In my case, the Samsung Galaxy S2 does not have a LED.

Solution: NoLED.

While NoLED does not give you screensaver images, it gives you everything else.

It will notify you of missed calls, SMS, email, and other apps with small coloured dots. The dots move around the screen (configurable).

You can expand the dots to icons (similar to sleeping screen), app thumbnails (where available). It will even tell you how much charge is left on your phone when a notification is received, so you can do away with the battery widget on your home screen. You can even go so far as to instruct NoLED to sleep between a time range so it doesn't wake you up at night.

In short, NoLED is ultra-configurable. And it is free. You can opt to donate a small amount to the developers for their excellent work. I likely will.

This app is the best solution I've found to solve the gap between Sleeping Screen and the default lock screen on the Samsung Galaxy S2. If you have found another app that is better, please comment so other readers can benefit from your experience.
You have read this article android / Pros and Cons / Symbian S3 with the title January 2012. You can bookmark this page URL http://azaquery.blogspot.com/2012/01/moving-from-symbian-to-android-o.html. Thanks!
Tuesday, January 3, 2012

Holo Everywhere

[This post is by Adam Powell, an Android Framework engineer who cares about style. —Tim Bray]

Android 4.0 showcases the Holo theme family, further refined since its debut in Android 3.0. But as most developers know, a new system theme for some Android devices isn’t a new or uncommon event. For developers new system themes mean more design targets for their apps. Using system themes means developers can take advantage of a user’s existing expectations and it can save a lot of production time, but only if an app designer can reliably predict the results. Before Android 4.0 the variance in system themes from device to device could make it difficult to design an app with a single predictable look and feel. We set out to improve this situation for the developer community in Ice Cream Sandwich and beyond.



Theme.Holo
If you’re not already familiar with Android’s style and theme system, you should read Styles and Themes before continuing.

Compatibility Standard

In Android 4.0, Holo is different. We’ve made the inclusion of the unmodified Holo theme family a compatibility requirement for devices running Android 4.0 and forward. If the device has Android Market it will have the Holo themes as they were originally designed.

This standardization goes for all of the public Holo widget styles as well. The Widget.Holo styles will be stable from device to device, safe for use as parent styles for incremental customizations within your app.

The Holo theme family in Android 4.0 consists of the themes Theme.Holo, Theme.Holo.Light, and Theme.Holo.Light.DarkActionBar. Examples of these themes in action are shown in the screenshots lining this post.

To use a Holo theme, explicitly request one from your manifest on your activity or application element, e.g. android:theme="@android:style/Theme.Holo". Your app will be displayed using the unmodified theme on all compatible Android 4.0 devices. The Holo themes may also be used as stable parent themes for app-level theme customizations.

What about device themes?

We have no desire to restrict manufacturers from building their own themed experience across their devices. In fact we’ve gone further to make this even easier. In Android 4.0’s API (level 14) we’ve added a new public theme family to complement the Holo family introduced in Android 3.0: DeviceDefault. DeviceDefault themes are aliases for the device’s native look and feel. The DeviceDefault theme family and widget style family offer ways for developers to target the device’s native theme with all customizations intact.



Theme.Holo.Light
Formally separating these theme families will also make future merges easier for manufacturers updating to a new platform version, helping more devices update more quickly. Google’s Nexus devices alias DeviceDefault to the unmodified Holo themes.

Making use of your chosen theme

We’ve added a number of theme attributes to report common metrics and color palette info to apps that want to fit in with a theme. These include highlight colors, default padding and margins for common UI elements such as list items, and more. Apps that wish to integrate with their chosen theme (both Holo and DeviceDefault included) can refer to these theme attributes as in the examples below:

Sample button with system-supplied touch highlight:

<ImageButton android:id="@+id/my_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/button_icon"
android:background="?android:attr/selectableItemBackground" />
Sample widget with a custom pressedHighlightColor attribute, value retrieved from the system theme:

<MyWidget android:layout_width="wrap_content"
android:layout_height="wrap_content"
myapp:pressedHighlightColor="?android:attr/colorPressedHighlight" />
Sample list item layout using system-supplied metrics and text appearance:

<LinearLayout android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
android:paddingRight="?android:attr/listPreferredItemPaddingRight">
<TextView android:id="@+id/text"
android:textAppearance="?android:attr/textAppearanceListItem" />
<!-- Other views here -->
</LinearLayout>


Theme.Holo.Light.DarkActionBar

(Available in API level 14 and above)

Defaults for Older Apps

If an app does not explicitly request a theme in its manifest, Android 4.0 will determine the default theme based on the app’s targetSdkVersion to maintain the app’s original expectations: For values less than 11, @android:style/Theme; between 11 and 13 @android:style/Theme.Holo; and for 14 and higher @android:style/Theme.DeviceDefault.

Using Holo while supporting Android 2.x

Most Android developers will still want to support 2.x devices for a while as updates and new devices continue to roll out. This doesn’t stop you from taking advantage of newer themes on devices that support them though. Using Android’s resource system you can define themes for your app that are selected automatically based on the platform version of the device it’s running on.

Theme.Holo and Theme.Holo.Light have been available since API level 11, but Theme.Holo.Light.DarkActionBar is new in API level 14.

res/values/themes.xml:

<resources>
<style name="MyTheme" parent="@android:style/Theme">
<!-- Any customizations for your app running on pre-3.0 devices here -->
</style>
</resources>
res/values-v11/themes.xml:

<resources>
<style name="MyTheme" parent="@android:style/Theme.Holo">
<!-- Any customizations for your app running on devices with Theme.Holo here -->
</style>
</resources>
Finally, in AndroidManifest.xml:

<!-- [...] -->
<application android:name="MyApplication"
android:label="@string/application_label"
android:icon="@drawable/app_icon"
android:hardwareAccelerated="true"
android:theme="@style/MyTheme">
<!-- [...] -->
You can go as far with this idea as you like, up to and including defining your own theme attributes with different values across configurations for use in your other resources. To learn more about Android’s resource system, see Application Resources.

Final Thoughts

Android apps running on 4.0 and forward can use the Holo themes and be assured that their look and feel will not change when running on a device with a custom skin. Apps that wish to use the device’s default styling can do so using the DeviceDefault themes that are now in the public API. These changes let you spend more time on your design and less time worrying about what will be different from one device to another. Finally, Android’s resource system allows you to support features from the latest platform version while offering graceful fallback on older devices.
You have read this article App Resources / User Interface with the title January 2012. You can bookmark this page URL http://azaquery.blogspot.com/2012/01/holo-everywhere_3.html. Thanks!
Monday, January 2, 2012

Moving from Symbian to Android

I'm tired of Symbian, but I also love things like Sleeping Screen and Nokia Maps. What do I choose to make the transition as friendly as possible?

Don't worry: I was there about two weeks ago. I upgraded from a Nokia N8 to a Samsung Galaxy S2 (SGS2), and have spent the last few weeks tweaking and researching apps and services that give me the functionality I was used to on Symbian, and in many cases offer functionality better than Symbian.  If you're considering the jump, read my posts in the coming days about my findings so far.

Topics I'll be covering are:



You have read this article android / Pros and Cons / Symbian S3 with the title January 2012. You can bookmark this page URL http://azaquery.blogspot.com/2012/01/moving-from-symbian-to-android.html. Thanks!