Android Live Wallpaper Touch Event Hierarchy

I have live wallpapers that use different screens to trigger certain events. At the moment it works, but I seem to get all touch events. For example, when the user touches the icon to launch the application, I seem to get this event too.

Is it possible to determine whether the user has touched the background screen (i.e. the spaces between the icons) so that I can only perform my actions at this time and ignore the rest.

Otherwise (and suppose - perhaps by mistake) that if I am the first in the queue than there is no other application on top of me on the screen), I can determine where I am in the touch event queue so that I can only take action when am i first in line?
Or any other suggestions please. thanks Richard

+3
source share
1 answer

Turning around the same problem, I ended up looking at the source for Nexus wallpapers to see how it is implemented there.

I don’t think it can be determined if the actual home screen consumes touch. However, the main Android screen by default sends a command to the wallpaper when you click on an 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;
}
+10

Source: https://habr.com/ru/post/1777331/


All Articles