简体   繁体   English

实施动态壁纸

[英]Implementing a live wallpaper

I'm making a custom home screen, and I would like to give the user the ability to use live wallpapers in my launcher/home screen. 我正在制作自定义主屏幕,我希望使用户能够在启动器/主屏幕中使用动态壁纸。 Settings android:Theme.Holo.Wallpaper.NoTitleBar as my AppTheme kind of what I want, but not exactly. 设置android:Theme.Holo.Wallpaper.NoTitleBar作为我AppTheme 那种我想要的,但不完全是。

There are 2 possible solutions (but please tell me if you can think of another good one); 有两种可能的解决方案(但是请告诉我您是否可以想到另一个好的解决方案);

  • Use android:Theme.Holo.Wallpaper.NoTitleBar as my AppTheme 使用android:Theme.Holo.Wallpaper.NoTitleBar作为我的AppTheme
    • Live wallpapers are shown, but the user can't interact with them. 显示了动态壁纸,但用户无法与它们互动。 It's not great, but I'm fine with this. 不好,但是我很好。
  • Implement it in the "proper" way, so that users can interact with it. “适当”的方式实施它,以便用户可以与其进行交互。
    • The big problem is that I can't find how to do this anywhere. 最大的问题是我在任何地方都找不到怎么做。 All the documentation I can find tells me how to create a live wallpaper, but not how to implement support for it in my custom home screen. 我能找到的所有文档都告诉我如何创建动态壁纸,但没有告诉我如何在自定义主屏幕中实现对此的支持。

Whichever approach I take, these are 2 problems I'd incur either way and would also like a solution to; 无论我采用哪种方法,这都是我将要遇到的两个问题,并且也希望找到解决方案;

  • I need to calculate the "average colour" of the wallpaper (something similar is also fine). 我需要计算墙纸的“平均颜色”(类似的东西也可以)。 How do I do this with a live wallpaper, if at all possible? 如果有可能,我该如何使用动态壁纸呢?
  • I need to blur the wallpaper at some point. 我需要在某个时候模糊墙纸。 An acceptable solution here is to just overlay it with something that has a black transparent background instead of blurring it, but ideally I'd be able to blur it (even if I could just take kind of a static screenshot of the current state of the live wallpaper so I can blur that). 此处可接受的解决方案是,将其覆盖有透明的黑色背景而不是使其模糊,但理想情况下,我将能够对其进行模糊处理(即使我只能拍摄静态图片的当前状态)动态壁纸,这样我就可以模糊它)。 If I can get a static snapshot from the current state of the live wallpaper that would also solve my previous problem. 如果我可以从动态壁纸的当前状态获得静态快照,那也可以解决我以前的问题。

Here's what I ended up doing; 这就是我最终要做的事情;

  • Set android:Theme.Holo.Wallpaper.NoTitleBar as the AppTheme . android:Theme.Holo.Wallpaper.NoTitleBar设置为AppTheme
  • Disable colour calculation when a live wallpaper is set and default to a transparent black. 设置动态壁纸并默认为透明黑色时,禁用颜色计算。
    • Use WallpaperManager.getInstance (this.context).getWallpaperInfo () != null to detect whether a live wallpaper is set. 使用WallpaperManager.getInstance (this.context).getWallpaperInfo () != null来检测是否设置了动态壁纸。
  • While you can get a screenshot of your root view, the area where the live wallpaper is shown will be transparent. 虽然可以获取根视图的屏幕截图,但显示动态壁纸的区域将是透明的。 So that's no good. 那就不好了 I ended up overlaying it with a transparent black overlay so that the white text that is displayed on it is still readable. 我最后用透明的黑色覆盖层覆盖它,因此仍可以读取显示在其上的白色文本。

Apparently using android:Theme.Holo.Wallpaper.NoTitleBar does not stop the user from interacting with the live wallpaper. 显然,使用android:Theme.Holo.Wallpaper.NoTitleBar 停止从与动态壁纸交互的用户。 The live wallpapers I tested with (the default ones that come with Android) just didn't allow any kind of interaction, which I didn't realise. 我测试过的动态壁纸(Android附带的默认壁纸)只是不允许进行任何互动,而我却没有意识到。

I hope this information is able to save someone else some time. 我希望这些信息能够节省一些时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM