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 android.app.wallpaper.WallpaperDescription 21 import android.service.wallpaper.WallpaperService.Engine 22 import com.google.android.torus.core.wallpaper.LiveWallpaper 23 24 /** 25 * Interface that defines a Live Wallpaper Engine and its different states. You need to implement 26 * this class to render using [LiveWallpaper]. 27 */ 28 interface TorusEngine { 29 /** 30 * Called when the engine is created. You should load the assets and initialize the resources 31 * here. 32 * 33 * IMPORTANT: When this function is called, the surface used to render the engine has to be 34 * ready. 35 * 36 * @param isFirstActiveInstance Whether this is the first Engine instance (since the last time 37 * that all instances were destroyed). 38 */ createnull39 fun create(isFirstActiveInstance: Boolean = true) 40 41 /** 42 * Called when the event [Engine.onApplyWallpaper] is called. 43 * 44 * @see Engine.onApplyWallpaper 45 */ 46 fun applyWallpaper(which: Int): WallpaperDescription? { 47 return null 48 } 49 50 /** Called when the [TorusEngine] resumes. */ resumenull51 fun resume() 52 53 /** Called when the [TorusEngine] is paused. */ 54 fun pause() 55 56 /** 57 * Called when the surface holding the [TorusEngine] has changed its size. 58 * 59 * @param width The new width of the surface holding the [TorusEngine]. 60 * @param height The new height of the surface holding the [TorusEngine]. 61 */ 62 fun resize(width: Int, height: Int) 63 64 /** 65 * Called when we need to destroy the surface. 66 * 67 * @param isLastActiveInstance Whether this was the last Engine instance in our Service. 68 */ 69 fun destroy(isLastActiveInstance: Boolean = true) 70 71 /** 72 * Called when the engine changes its destination flag. The destination indicates whether the 73 * wallpaper is drawn on home screen, lock screen, or both. It is a combination of 74 * [WallpaperManager.FLAG_LOCK] and/or [WallpaperManager.FLAG_SYSTEM] 75 */ 76 fun onWallpaperFlagsChanged(which: Int) {} 77 } 78