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.wallpaper.listener 18 19 import android.app.WallpaperColors 20 import android.os.Bundle 21 22 /** 23 * Interface that is used to implement specific wallpaper callbacks like offset change (user swipes 24 * between home pages), when the preview state has changed or when the zoom state has changed. 25 */ 26 interface LiveWallpaperEventListener { 27 companion object { 28 const val WAKE_ACTION_LOCATION_X: String = "WAKE_ACTION_LOCATION_X" 29 const val WAKE_ACTION_LOCATION_Y: String = "WAKE_ACTION_LOCATION_Y" 30 const val SLEEP_ACTION_LOCATION_X: String = "SLEEP_ACTION_LOCATION_X" 31 const val SLEEP_ACTION_LOCATION_Y: String = "SLEEP_ACTION_LOCATION_Y" 32 } 33 34 /** 35 * Called when the wallpaper has been scrolled (usually when the user scroll between pages in 36 * the home of the launcher). This only tracts the horizontal scroll. 37 * 38 * @param xOffset The current offset of the scroll. The value is normalize between [0,1]. 39 * @param xOffsetStep How is stepped the scroll. If you invert [xOffsetStep] you get the 40 * number of pages in the scrolling area. 41 */ onOffsetChangednull42 fun onOffsetChanged(xOffset: Float, xOffsetStep: Float) 43 44 /** 45 * Called when the zoom level of the wallpaper is changing. 46 * 47 * @param zoomLevel A value between 0 and 1 that tells how much the wallpaper should be zoomed 48 * out: if 0, the wallpaper should be in normal state; if 1 the wallpaper should be zoomed out. 49 */ 50 fun onZoomChanged(zoomLevel: Float) 51 52 /** 53 * Call when the wallpaper was set, and then is reapplied. This means that the wallpaper was 54 * set and is being set again. This is useful to know if the wallpaper settings have to be 55 * reapplied again (i.e. if the user enters the wallpaper picker and picks the same wallpaper, 56 * changes the settings and sets the wallpaper again). 57 */ 58 fun onWallpaperReapplied() 59 60 /** 61 * Called when the Wallpaper colors need to be computed you can create a [WallpaperColors] 62 * instance using the [WallpaperColors.fromBitmap] function and passing a bitmap that 63 * represents the wallpaper (i.e. the gallery thumbnail) or use the [WallpaperColors] 64 * constructor and pass the primary, secondary and tertiary colors. This method is specially 65 * important since the UI will change their colors based on what is returned here. 66 * 67 * @return The colors that represent the wallpaper; null if you want the System to take 68 * care of the colors. 69 */ 70 fun computeWallpaperColors(): WallpaperColors? 71 72 /** 73 * Called when the wallpaper receives the preview information (asynchronous call). 74 * 75 * @param extras the bundle of the preview information. The key "which_preview" can be used to 76 * retrieve a string value (ex. main_preview_home) that specifies which preview the engine 77 * is referring to. 78 */ 79 fun onPreviewInfoReceived(extras: Bundle?) {} 80 81 /** 82 * Called when the device is activated from a sleep/AOD state. 83 * 84 * @param extras contains the location of the action that caused the wake event: 85 * - [LiveWallpaperEventListener.WAKE_ACTION_LOCATION_X]: the X screen location (in Pixels). if 86 * the value is not included or is -1, the X screen location is unknown. 87 * - [LiveWallpaperEventListener.WAKE_ACTION_LOCATION_Y]: the Y screen location (in Pixels). if 88 * the value is not included or is -1, the Y screen location is unknown. 89 */ onWakenull90 fun onWake(extras: Bundle) 91 92 /** 93 * Called when the device enters a sleep/AOD state. 94 * 95 * @param extras contains the location of the action that caused the sleep event: 96 * - [LiveWallpaperEventListener.SLEEP_ACTION_LOCATION_X]: the X screen location (in Pixels). if 97 * the value is not included or is -1, the X screen location is unknown. 98 * - [LiveWallpaperEventListener.SLEEP_ACTION_LOCATION_Y]: the Y screen location (in Pixels). if 99 * the value is not included or is -1, the Y screen location is unknown. 100 */ 101 fun onSleep(extras: Bundle) 102 103 /** 104 * Indicates whether the zoom animation should be handled in WindowManager. Preferred to be set 105 * to true to avoid pressuring GPU. 106 * 107 * See [WallpaperService.shouldZoomOutWallpaper]. 108 */ 109 fun shouldZoomOutWallpaper() = false 110 } 111