Android的动态壁纸触摸事件层次 [英] Android Live Wallpaper Touch Event Hierarchy

查看:368
本文介绍了Android的动态壁纸触摸事件层次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用不同的屏幕动态壁纸触及触发某些事件。目前,它是工作,但我似乎得到所有的触摸事件。例如,当用户触摸一个图标来启动一个应用程序,我似乎得到该事件了。

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

推荐答案

遇到同样的问题,并最终在看源的Nexus壁纸,看看它是如何实现的存在。

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

我不认为这是可能的,以确定实际主屏幕是否已经消耗的联系。但是,默认的Andr​​oid主屏幕确实发送命令时,你点击空白区域的壁纸。因此,在你的引擎,你可以这样写:

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;
}

这篇关于Android的动态壁纸触摸事件层次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆