Monday, December 7, 2009

Dealing with orientation change in Android Widgets

As you know, i had some issues with the MineSweeper Widget in G1 devices (and, indeed, in all Android mobiles with physical keyboards).

This issue was related to switching between portrait and landscape modes.

First, i trusted in Android auto-resize, and it resulted in an acore crash when people switched to landscape mode (for example, putting out the physical keyboard), although it didn't crash in the Android emulator (it did a weird resize though).

In this particular case, it was no point on supporting landscape mode (too small buttons = unplayable), so i decided to show an error advice when landscape mode was activated. And this wasn't as easy as expected.

First of all, i realised that i needed buttons references in both portrait and landscape layouts, why? Because the user could add the widget while being in landscape mode, and MineSweeper's data and buttons needed to be assigned to their PendingIntents, otherwise it'll result in an unexpected behaviour, and user would see how widget didn't response when switching to portrait! So i left the buttons part of the layout in the "error layout" setting visibility to "gone".

Then, next problem appeared. Each time the layout changes from portrait to landscape, the view is re-inflated, so you need to re-assign PendingIntents to all layout elements before each updateAppWidget call (and reassign all viewResources too!).

And that's it!

And remember, don't trust Android Emulator and test your app in all devices as posible.

I suppose there are better ways to solve this issue, you can share them with us in the comments!

Saturday, December 5, 2009

Mine Sweeper Widget

NEWCOMER! Mine Sweeper Widget!

A couple of weeks ago we released a new app in the Android Market: Mine Sweeper Widget. We've been really busy these days so we couldn't post it here!

I was really interested in experimenting with widgets and seeing how far this concept could go. So i decided to start developing some game widgets (yes, more are coming :P).

With this widget, you can play the classic game "MineSweeper" right in your homescreen, since we believe this is a "fast-play" game, we don't want you to open an app each time you want some quick fun :)

There're still some problems with this app while running in landscape mode (crashes in G1 when opening phisical keyboard while being on homescreen), but we're working hard to solve this issue. Fixed!

So let's show you how it looks!


Can you see any Halo reference? :P

Enjoy!