预览模式下的动态壁纸

发布于 2024-10-27 12:44:47 字数 62 浏览 4 评论 0原文

我需要我的壁纸在预览模式下(屏幕上有“设置”和“设置..”)时有不同的行为。我怎么知道它什么时候被绘制在那里?

I need my wallpaper to act differently when in preview mode (the screen with "Settings" and "Set .. "). How do i know when it's drawn there?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小女人ら 2024-11-03 12:44:47

onCreateEngine() 中,您可以使用 isPreview() 方法。

请注意,onCreateEngine()“通常”会调用两次:一次是为了创建预览实例,另一次是在您实际设置壁纸时调用。

详细信息请参见:http://developer.android.com/reference/ android/service/wallpaper/WallpaperService.Engine.html

Within onCreateEngine() you can use the isPreview() method.

Note that onCreateEngine() is "normally" called twice: once to create an instance for preview, and then again when you actually set the wallpaper.

Details here: http://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine.html

空名 2024-11-03 12:44:47

isPreview() 方法可以在已实现的 Engine 的 onCreate(SurfaceHolderholder) 方法中调用。不在 onCreateEngine 方法中作为先前的答案,因为该方法尚未准备好。

The isPreview() method can be called in the onCreate(SurfaceHolder holder) method of the implemented Engine. Not in the onCreateEngine method as the prior answer because the method is not ready.

我为君王 2024-11-03 12:44:47

除了代表的答案之外,我还会写。
由于预览和非预览引擎实例可以同时存在,您可以在您的 WallpaperService 类中添加引擎的两个静态实例和一个局部变量(Kotlin 中的示例):

    private var engine: OpenGLEngine? = null
    private set
    //...

    companion object {
       private var engineInstance: OpenGLEngine? = null
       private var previewEngineInstance: OpenGLEngine? = null
       //...
    }

并在重写函数中使用它们

     override fun onCreate(surfaceHolder: SurfaceHolder?) {
        super.onCreate(surfaceHolder)
        if (isPreview) {
            previewEngineInstance = this@OpenGLEngine
            engine = previewEngineInstance
        } else {
            engineInstance = this@OpenGLEngine
            engine = engineInstance
        }
        //...
    }

    override fun onDestroy() {
        if (isPreview) {
            engine = engineInstance
            previewEngineInstance = null
        } else {
            engine = previewEngineInstance
            engineInstance = null
        }
        //...
        super.onDestroy()
    }

这样您就可以始终获取当前您的壁纸服务中的引擎实例并调用其isPreview

I'll write in addition to represented answers.
As the preview and non-preview engine instances could exist simultaneously, you can add two static instances and one local variable of your engine inside your WallpaperService class (sample in Kotlin):

    private var engine: OpenGLEngine? = null
    private set
    //...

    companion object {
       private var engineInstance: OpenGLEngine? = null
       private var previewEngineInstance: OpenGLEngine? = null
       //...
    }

and use them in overriding functions

     override fun onCreate(surfaceHolder: SurfaceHolder?) {
        super.onCreate(surfaceHolder)
        if (isPreview) {
            previewEngineInstance = this@OpenGLEngine
            engine = previewEngineInstance
        } else {
            engineInstance = this@OpenGLEngine
            engine = engineInstance
        }
        //...
    }

    override fun onDestroy() {
        if (isPreview) {
            engine = engineInstance
            previewEngineInstance = null
        } else {
            engine = previewEngineInstance
            engineInstance = null
        }
        //...
        super.onDestroy()
    }

This way you can always get the current engine instance in your WallpaperService and call its isPreview.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文