1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.android.torus.core.engine 18 19 import android.app.WallpaperManager 20 import com.google.android.torus.core.wallpaper.LiveWallpaper 21 22 /** 23 * Interface that defines a Live Wallpaper Engine and its different states. You need to implement 24 * this class to render using [LiveWallpaper]. 25 */ 26 interface TorusEngine { 27 /** 28 * Called when the engine is created. You should load the assets and initialize the 29 * resources here. 30 * 31 * IMPORTANT: When this function is called, the surface used to render the engine has to be 32 * ready. 33 * 34 * @param isFirstActiveInstance Whether this is the first Engine instance (since the last time 35 * that all instances were destroyed). 36 */ createnull37 fun create(isFirstActiveInstance: Boolean = true) 38 39 /** 40 * Called when the [TorusEngine] resumes. 41 */ 42 fun resume() 43 44 /** 45 * Called when the [TorusEngine] is paused. 46 */ 47 fun pause() 48 49 /** 50 * Called when the surface holding the [TorusEngine] has changed its size. 51 * 52 * @param width The new width of the surface holding the [TorusEngine]. 53 * @param height The new height of the surface holding the [TorusEngine]. 54 */ 55 fun resize(width: Int, height: Int) 56 57 /** 58 * Called when we need to destroy the surface. 59 * 60 * @param isLastActiveInstance Whether this was the last Engine instance in our Service. 61 */ 62 fun destroy(isLastActiveInstance: Boolean = true) 63 64 /** 65 * Called when the engine changes its destination flag. The destination indicates whether 66 * the wallpaper is drawn on home screen, lock screen, or both. It is a combination of 67 * [WallpaperManager.FLAG_LOCK] and/or [WallpaperManager.FLAG_SYSTEM] 68 */ 69 fun onWallpaperFlagsChanged(which: Int) {} 70 } 71