3

I have a Live Wallpaper that uses various screen touches to trigger certain events. At the moment it is working but I seem to get all touch events. For example, when the user touches an icon to launch an app, I seem to get that event too.

Is it possible to determine whether the user has touched the background screen (i.e. the inter-icon gaps.) so that I can only take my actions at that time and ignore the others.

Failing that, (and assuming – possibly erroneously – that if I am first in the queue than there is no other application on top of me on the screen) can I determine where I am in the touch event queue so that I can only take actions when I am the first one in the queue?
Or any other suggestions please. Thanks Richard

Josh Lee
  • 171,072
  • 38
  • 269
  • 275
Richard
  • 135
  • 1
  • 7

1 Answers1

10

Ran into the same problem and ended up looking at the source for the Nexus wallpaper to see how it's implemented there.

I don't think it's possible to determine whether the actual home screen has consumed the touch. However, the default Android home screen does send a command to the wallpaper when you tap on empty space. So in your Engine, you can write:

@Override
public Bundle onCommand(String action, int x, int y, int z, Bundle extras, boolean resultRequested) {
    if (action.equals(WallpaperManager.COMMAND_TAP)) {
        // do whatever you would have done on ACTION_UP
    }
    return null;
}
Tim
  • 116
  • 1
  • 2
  • Perfect :) - Does exactly what I want - Thank you - Can you let me know where you found the Nexus code please - Richard – Richard Dec 28 '10 at 22:48
  • http://android.git.kernel.org/?p=platform/packages/wallpapers/Basic.git;a=tree;f=src/com/android/wallpaper;hb=HEAD – Tim Jan 04 '11 at 22:59
  • Thank you - I'll start educating myself :) – Richard Jan 10 '11 at 14:41
  • This doesn't work for the Samsung Galaxy S II - the event is still received by the wallpaper. Works fine on other devices. – Kenton Price Jan 19 '12 at 11:30