Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0ab07b7e authored by Shan Huang's avatar Shan Huang Committed by Android (Google) Code Review
Browse files

Merge "Setup TorusEngine with WallpaperDescription" into main

parents 89fb0138 118954ee
Loading
Loading
Loading
Loading
+16 −3
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.google.android.torus.core.wallpaper

import android.app.WallpaperColors
import android.app.wallpaper.WallpaperDescription
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
@@ -133,7 +134,11 @@ abstract class LiveWallpaper : WallpaperService() {
     * well). You can track the lifecycle when *any* Engine is active using the
     * is{First/Last}ActiveInstance parameters of the create/destroy methods.
     */
    abstract fun getWallpaperEngine(context: Context, surfaceHolder: SurfaceHolder): TorusEngine
    abstract fun getWallpaperEngine(
        context: Context,
        surfaceHolder: SurfaceHolder,
        wallpaperDescription: WallpaperDescription? = null,
    ): TorusEngine

    /**
     * returns a new instance of [LiveWallpaperEngineWrapper]. Caution: This function should not be
@@ -145,6 +150,12 @@ abstract class LiveWallpaper : WallpaperService() {
        return wrapper
    }

    override fun onCreateEngine(description: WallpaperDescription): Engine? {
        val wrapper = LiveWallpaperEngineWrapper(description)
        wakeStateChangeListeners.add(WeakReference(wrapper))
        return wrapper
    }

    override fun onConfigurationChanged(newConfig: Configuration) {
        super.onConfigurationChanged(newConfig)

@@ -242,7 +253,9 @@ abstract class LiveWallpaper : WallpaperService() {
     * engine is created. Also, wrapping our [TorusEngine] inside [WallpaperService.Engine] allow us
     * to reuse [TorusEngine] in other places, like Activities.
     */
    private inner class LiveWallpaperEngineWrapper : WallpaperService.Engine() {
    private inner class LiveWallpaperEngineWrapper(
        private val wallpaperDescription: WallpaperDescription? = null
    ) : WallpaperService.Engine() {
        private lateinit var wallpaperEngine: TorusEngine

        override fun onCreate(surfaceHolder: SurfaceHolder) {
@@ -261,7 +274,7 @@ abstract class LiveWallpaper : WallpaperService() {
                    this@LiveWallpaper
                }

            wallpaperEngine = getWallpaperEngine(context, surfaceHolder)
            wallpaperEngine = getWallpaperEngine(context, surfaceHolder, wallpaperDescription)
            numEngines++

            /*
+7 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.google.android.wallpaper.weathereffects

import android.app.wallpaper.WallpaperDescription
import android.content.Context
import android.view.SurfaceHolder
import com.google.android.torus.core.engine.TorusEngine
@@ -35,7 +36,11 @@ class WeatherWallpaperService @Inject constructor(): LiveWallpaper() {
        WallpaperEffectsDebugApplication.graph.inject(this)
    }

    override fun getWallpaperEngine(context: Context, surfaceHolder: SurfaceHolder): TorusEngine {
    override fun getWallpaperEngine(
        context: Context,
        surfaceHolder: SurfaceHolder,
        wallpaperDescription: WallpaperDescription?,
    ): TorusEngine {
        return WeatherEngine(surfaceHolder, applicationScope, interactor, context)
    }
}