Thursday, January 31, 2013

Jumpgate Live Wallpaper v1.25

  - New Feature: Daydream support on 4.2+ devices
  - New Feature: Simulated scrolling on some devices
  - Update: Misc stability improvements
  - Update: Holo-themed settings screen
  - Google Play Link

It's been a while since Jumpgate got an update, apparently long enough that it was still using the old-style settings screen.  This update brings it up to date on our current framework, which brings with it some good perks like Daydream support, simulated scrolling if you have a device that doesn't scroll the wallpaper on its own, and various other small fixes.

This also updates the SDK version so you get a nicer looking settings screen!

Friendly Bugs Live Wallpaper v2.15

  - New Feature: Daydream support on 4.2+ devices!
  - New Feature: Simulated scrolling in some devices.
  - Bug Fix: Gap at edges of background on some devices
  - Google Play Link

Nothing earth shaking here, this is primarily a maintenance update that also fixes a camera issue on a few devices (notably the Nexus 7).  Daydream support is now in and working as well, so break out your dock and have butterflies hang out while charging.

Tuesday, January 29, 2013

Space Battle Live Wallpaper v1.25

  - New Feature: High scores!
  - New Feature: Lives!
  - New Feature: Daydream support on 4.2+ devices
  - Update: Explosions reflect hero/enemy weapon colors
  - Update: Better list selections on settings screen
  - Update: Better handling of top/bottom placement
  - Google Play Link

It's been a while since Space Battle got an update, and we've been discussing it on and off for a while.  Since we're simulating a game here, we've gone ahead and added both lives and real score tracking -- complete with high score counter.  You can adjust the positions of these up or down to make them line up nicely for your particular device.  :)

In addition, some other minor stuff happened.  Enemy and player explosions now reflect the color of their weapons, Daydream support is in and working, the list selections on the Settings screen look nicer now, and so on.

We flirted all too long with making an online scoreboard and turning this into some sort of retro ProgressQuest...  Maybe next update.

Thursday, January 24, 2013

Integrating Picasa into Android Apps

In our most recent update of the Gallery Live Wallpaper, we added Picasa support.  We were a little more ambitious this time, so we decided to experiment with letting users access their personal Picasa accounts, which are tied to their Google accounts.  What followed was an adventure through older, soon to be deprecated Google APIs, and upcoming, not quite out of beta APIs.

Google has some pretty good documentation on the Picasa web interface:

We were actually able to use this pretty easily to run searches of publicly available Picasa photos that we could then download for use in the Gallery Live Wallpaper.

In order to use users' private accounts, though, we need to authenticate them with Google using OAuth2.

Google makes it a point through all of this to encourage people to use their client APIs rather than hand coding all of the access to various web connections.  In looking up these libraries, though, there seem to be two editions:

Google Data Java Client Library

Google APIs Client Library for Java

Primary Picasa support is in the GData library, but this library is specifically noted to not support Android.  The new Google APIs has references to it, but it's mostly in a generalized area, Google Data APIs.

It's slightly concerning that the new Google APIs libraries are still in beta, but they largely seem to work.

There are a couple incomplete examples of Picasa support immediately available from the Google Data APIs links, but we wanted to see if we could find something more substantial, especially something that included logging in with OAuth2.

Within the Google Data APIs section, there's a sample command line Picasa implementation that makes reference to a namespace,  Some Google searching revealed this source project:

This provided a good base for creating our authenticated Picasa interface, along with the command line sample.

Library Dependencies

There are two main sets of libraries we need for Picasa and authentication: the Google APIs Client Library for Java and the Google Play Services library, obtained from the Android SDK manager in the Extras section.  The latter is not very clearly spelled out.  We didn't find it for a while, and encountered some mysterious java.lang.VerifyError exceptions.  It's referenced in the Android Task-sample project setup instructions.

As a quick note, the Google documentation talks a lot about getting client IDs and secrets to register apps for proper access to the various Google APIs.  This blog post notes that for Android, you can bypass the entire system by listing your app's package name and SHA1 signing key, which the Google client libraries will pick up and use to perform the same function automatically.  You can do this at the Google APIs Console, which is the same place you set up your client ID.

Authentication Process Overview

In order to authenticate properly, the process needs to launch Google Play to let the user allow the application to access their Picasa account.  This is done through Activity.startActivityForResult(), which means that the actual initial authorization has to run through our wallpaper settings activity, rather than the backend service we use to help downloading images asynchronously.  So we launch the authentication process when the user chooses the setting to use their personal Picasa account, and we don't allow that setting to actually be set until the full authentication process completes successfully.

In addition to needing to wait for the external Google Play activity to return, we also need to account for the authentication token expiring or being invalidated.  In that case, we need to forcibly invalidate the token we're using locally, so that the next time we make an authorization request, OAuth2 correctly requests a new token.

Most of this should be invisible to the user, but because the requests and retries take a while, our "authenticating Picasa account" dialog can stay up for 30 seconds or more.  The user should just be presented with the authorization activity from Google Play the first time, and then authentication should proceed more quickly afterwards.

Also, useful for both users and developers, we can revoke access through Google at any time.  Log in to your Google account, go to your account settings, select Security, and go to Connected applications and sites.  Clicking Manage Access here will bring up a page with all your authorized apps, where you can manually revoke any authorization you choose.

Authentication Code Sample

 Using the Android Tasks sample as a base, we can use Google's classes to do the vast majority of the authentication work.

import android.accounts.Account;


// ......

final HttpTransport transport =

final GoogleAccountCredential credential =
          "" );

final Account[] accounts = credential.getAllAccounts();

credential.setSelectedAccountName( accounts[0].name );

PicasaClient client = new PicasaClient(
     transport.createRequestFactory( credential ) );

client.setApplicationName( "KF-GalleryLiveWallpaper" );

PicasaUrl url = PicasaUrl.relativeToRoot(
     "feed/api/user/default" );

     UserFeed feed = client.executeGetUserFeed( url );
catch ( Exception e )
     /* Error handling for launching Google Play authentication, old token invalidation, etc. */


The scope required for GoogleAccountCredential.usingOAuth2() is noted in the Picasa Web API protocol documentation.

We also found that none of the actual requests out to Google services happen until we actually execute the Picasa request.  This is why the executeGetUserFeed() line is caught, but none of the preceding setup is.

The other big thing is that we cannot run any of this on the main activity thread or UI thread.  The system specifically throws a runtime exception about this, because the OAuth2 process can block while waiting on network responses, potentially creating a deadlock.

Final Notes

There are a lot of topics only touched on here, including more detail about handling errors in the authentication process.  There's also more study to be done on the Google Atom XML parser used for the Picasa data model classes.  And while our purpose for the Gallery Live Wallpaper is simply to search and display photos, the Picasa Web API also allows uploading and editing photos.

Picasa is quite accessible within an Android application.  The trick has been to pull together all the documentation necessary to do so.

Monday, January 21, 2013

Gallery Live Wallpaper v2.0

  - New Feature: Added Picasa support, including personal accounts  - New Feature: Simulated scrolling on some devices
  - New Feature: Help and introductory text
  - Update: Separated retriever service from wallpaper service
  - Google Play link

This update has been brewing for a long time, and is using a framework we created (that at this point is well tested on a number of products) to handle background downloads from a content source.  It shouldn't look much different to you on the surface, but should be better behaved overall.

In addition, we've added support for Picasa.  By default this is public images only, but if you allow us to use your credentials it can include your personal images as well.  Clear the search terms and it'll just show your personal images.

In addition, we've added some help functionality and intro text that should help get new users going.

Friday, January 4, 2013

Koi Live Wallpaper v1.65

  - New Feature: Disable shadows checkbox
  - Update: Rearranged some items on prefs screen
  - Google Play Link

Not a world changing update, but some folks didn't care for the fish shadows.  It's been a few days now, but if they still feel that way there's now an easy way to disable it.