Added in API level 7

Engine

open class Engine
kotlin.Any
   ↳ android.service.wallpaper.WallpaperService.Engine

The actual implementation of a wallpaper. A wallpaper service may have multiple instances running (for example as a real wallpaper and as a preview), each of which is represented by its own Engine instance. You must implement WallpaperService#onCreateEngine() to return your concrete Engine implementation.

Summary

Public constructors

Default constructor

Public methods
open Int

Convenience for WallpaperManager.getDesiredMinimumHeight(), returning the height that the system would like this wallpaper to run in.

open Int

Convenience for WallpaperManager.getDesiredMinimumWidth(), returning the width that the system would like this wallpaper to run in.

open Context?

The Context with resources that match the current display the wallpaper is on.

open SurfaceHolder!

Provides access to the surface in which this wallpaper is drawn.

open Int

Returns the current wallpaper flags indicating which screen this Engine is rendering to.

open Boolean

Returns true if this engine is running in preview mode -- that is, it is being shown to the user before they select it as the actual wallpaper.

open Boolean

Return whether the wallpaper is currently visible to the user, this is the last value supplied to onVisibilityChanged(boolean).

open Unit

Notifies the engine that wallpaper colors changed significantly.

open Unit

Called with the current insets that are in effect for the wallpaper.

open Bundle!
onCommand(action: String!, x: Int, y: Int, z: Int, extras: Bundle!, resultRequested: Boolean)

Process a command that was sent to the wallpaper with WallpaperManager#sendWallpaperCommand.

open WallpaperColors?

Called by the system when it needs to know what colors the wallpaper is using.

open Unit
onCreate(surfaceHolder: SurfaceHolder!)

Called once to initialize the engine.

open Unit
onDesiredSizeChanged(desiredWidth: Int, desiredHeight: Int)

Called when an application has changed the desired virtual size of the wallpaper.

open Unit

Called right before the engine is going away.

open Unit
onOffsetsChanged(xOffset: Float, yOffset: Float, xOffsetStep: Float, yOffsetStep: Float, xPixelOffset: Int, yPixelOffset: Int)

Called to inform you of the wallpaper's offsets changing within its contain, corresponding to the container's call to WallpaperManager.setWallpaperOffsets().

open Unit
onSurfaceChanged(holder: SurfaceHolder!, format: Int, width: Int, height: Int)

Convenience for SurfaceHolder.Callback.surfaceChanged().

open Unit

Convenience for SurfaceHolder.Callback.surfaceCreated().

open Unit

Convenience for SurfaceHolder.Callback.surfaceDestroyed().

open Unit

Convenience for SurfaceHolder.Callback.surfaceRedrawNeeded().

open Unit

Called as the user performs touch-screen interaction with the window that is currently showing this wallpaper.

open Unit

Called to inform you of the wallpaper becoming visible or hidden.

open Unit

Called when the current wallpaper flags change.

open Unit

Called when the zoom level of the wallpaper changed.

open Unit

Control whether this wallpaper will receive notifications when the wallpaper has been scrolled.

open Unit

Control whether this wallpaper will receive raw touch events from the window manager as the user interacts with the window that is currently displaying the wallpaper.

Protected methods
open Unit
dump(prefix: String!, fd: FileDescriptor!, out: PrintWriter!, args: Array<String!>!)

Public constructors

Engine

Added in API level 7
Engine()

Default constructor

Public methods

getDesiredMinimumHeight

Added in API level 7
open fun getDesiredMinimumHeight(): Int

Convenience for WallpaperManager.getDesiredMinimumHeight(), returning the height that the system would like this wallpaper to run in.

getDesiredMinimumWidth

Added in API level 7
open fun getDesiredMinimumWidth(): Int

Convenience for WallpaperManager.getDesiredMinimumWidth(), returning the width that the system would like this wallpaper to run in.

getDisplayContext

Added in API level 29
open fun getDisplayContext(): Context?

The Context with resources that match the current display the wallpaper is on. For multiple display environment, multiple engines can be created to render on each display, but these displays may have different densities. Use this context to get the corresponding resources for currently display, avoiding the context of the service.

The display context will never be null after Engine#onCreate(SurfaceHolder) has been called.

Return
Context? A Context for current display.

getSurfaceHolder

Added in API level 7
open fun getSurfaceHolder(): SurfaceHolder!

Provides access to the surface in which this wallpaper is drawn.

getWallpaperFlags

Added in API level 34
open fun getWallpaperFlags(): Int

Returns the current wallpaper flags indicating which screen this Engine is rendering to.

Return
Int Value is either 0 or a combination of android.app.WallpaperManager#FLAG_SYSTEM, and android.app.WallpaperManager#FLAG_LOCK

isPreview

Added in API level 7
open fun isPreview(): Boolean

Returns true if this engine is running in preview mode -- that is, it is being shown to the user before they select it as the actual wallpaper.

isVisible

Added in API level 7
open fun isVisible(): Boolean

Return whether the wallpaper is currently visible to the user, this is the last value supplied to onVisibilityChanged(boolean).

notifyColorsChanged

Added in API level 27
open fun notifyColorsChanged(): Unit

Notifies the engine that wallpaper colors changed significantly. This will trigger a onComputeColors() call.

onApplyWindowInsets

Added in API level 21
open fun onApplyWindowInsets(insets: WindowInsets!): Unit

Called with the current insets that are in effect for the wallpaper. This gives you the part of the overall wallpaper surface that will generally be visible to the user (ignoring position offsets applied to it).
This method must be called from the main thread of your app.

Parameters
insets WindowInsets!: Insets to apply.

onCommand

Added in API level 7
open fun onCommand(
    action: String!,
    x: Int,
    y: Int,
    z: Int,
    extras: Bundle!,
    resultRequested: Boolean
): Bundle!

Process a command that was sent to the wallpaper with WallpaperManager#sendWallpaperCommand. The default implementation does nothing, and always returns null as the result.
This method must be called from the main thread of your app.

Parameters
action String!: The name of the command to perform. This tells you what to do and how to interpret the rest of the arguments.
x Int: Generic integer parameter.
y Int: Generic integer parameter.
z Int: Generic integer parameter.
extras Bundle!: Any additional parameters.
resultRequested Boolean: If true, the caller is requesting that a result, appropriate for the command, be returned back.
Return
Bundle! If returning a result, create a Bundle and place the result data in to it. Otherwise return null.

onComputeColors

Added in API level 27
open fun onComputeColors(): WallpaperColors?

Called by the system when it needs to know what colors the wallpaper is using. You might return null if no color information is available at the moment. In that case you might want to call notifyColorsChanged() when color information becomes available.

The simplest way of creating a android.app.WallpaperColors object is by using android.app.WallpaperColors#fromBitmap(Bitmap) or android.app.WallpaperColors#fromDrawable(Drawable), but you can also specify your main colors by constructing a android.app.WallpaperColors object manually.
This method must be called from the main thread of your app.

Return
WallpaperColors? Wallpaper colors.

onCreate

Added in API level 7
open fun onCreate(surfaceHolder: SurfaceHolder!): Unit

Called once to initialize the engine. After returning, the engine's surface will be created by the framework.
This method must be called from the main thread of your app.

onDesiredSizeChanged

Added in API level 7
open fun onDesiredSizeChanged(
    desiredWidth: Int,
    desiredHeight: Int
): Unit

Called when an application has changed the desired virtual size of the wallpaper.
This method must be called from the main thread of your app.

onDestroy

Added in API level 7
open fun onDestroy(): Unit

Called right before the engine is going away. After this the surface will be destroyed and this Engine object is no longer valid.
This method must be called from the main thread of your app.

onOffsetsChanged

Added in API level 7
open fun onOffsetsChanged(
    xOffset: Float,
    yOffset: Float,
    xOffsetStep: Float,
    yOffsetStep: Float,
    xPixelOffset: Int,
    yPixelOffset: Int
): Unit

Called to inform you of the wallpaper's offsets changing within its contain, corresponding to the container's call to WallpaperManager.setWallpaperOffsets().
This method must be called from the main thread of your app.

onSurfaceChanged

Added in API level 7
open fun onSurfaceChanged(
    holder: SurfaceHolder!,
    format: Int,
    width: Int,
    height: Int
): Unit

Convenience for SurfaceHolder.Callback.surfaceChanged().
This method must be called from the main thread of your app.

onSurfaceCreated

Added in API level 7
open fun onSurfaceCreated(holder: SurfaceHolder!): Unit

Convenience for SurfaceHolder.Callback.surfaceCreated().
This method must be called from the main thread of your app.

onSurfaceDestroyed

Added in API level 7
open fun onSurfaceDestroyed(holder: SurfaceHolder!): Unit

Convenience for SurfaceHolder.Callback.surfaceDestroyed().
This method must be called from the main thread of your app.

onSurfaceRedrawNeeded

Added in API level 9
open fun onSurfaceRedrawNeeded(holder: SurfaceHolder!): Unit

Convenience for SurfaceHolder.Callback.surfaceRedrawNeeded().
This method must be called from the main thread of your app.

onTouchEvent

Added in API level 7
open fun onTouchEvent(event: MotionEvent!): Unit

Called as the user performs touch-screen interaction with the window that is currently showing this wallpaper. Note that the events you receive here are driven by the actual application the user is interacting with, so if it is slow you will get fewer move events.
This method must be called from the main thread of your app.

onVisibilityChanged

Added in API level 7
open fun onVisibilityChanged(visible: Boolean): Unit

Called to inform you of the wallpaper becoming visible or hidden. It is very important that a wallpaper only use CPU while it is visible..
This method must be called from the main thread of your app.

onWallpaperFlagsChanged

Added in API level 34
open fun onWallpaperFlagsChanged(which: Int): Unit

Called when the current wallpaper flags change.
This method must be called from the main thread of your app.

Parameters
which Int: The new flag value Value is either 0 or a combination of android.app.WallpaperManager#FLAG_SYSTEM, and android.app.WallpaperManager#FLAG_LOCK

onZoomChanged

Added in API level 30
open fun onZoomChanged(zoom: Float): Unit

Called when the zoom level of the wallpaper changed. This method will be called with the initial zoom level when the surface is created.
This method must be called from the main thread of your app.

Parameters
zoom Float: the zoom level, between 0 indicating fully zoomed in and 1 indicating fully zoomed out. Value is between 0f and 1f inclusive

setOffsetNotificationsEnabled

Added in API level 15
open fun setOffsetNotificationsEnabled(enabled: Boolean): Unit

Control whether this wallpaper will receive notifications when the wallpaper has been scrolled. By default, wallpapers will receive notifications, although the default static image wallpapers do not. It is a performance optimization to set this to false.

Parameters
enabled Boolean: whether the wallpaper wants to receive offset notifications

setTouchEventsEnabled

Added in API level 7
open fun setTouchEventsEnabled(enabled: Boolean): Unit

Control whether this wallpaper will receive raw touch events from the window manager as the user interacts with the window that is currently displaying the wallpaper. By default they are turned off. If enabled, the events will be received in onTouchEvent(android.view.MotionEvent).

Protected methods

dump

Added in API level 14
protected open fun dump(
    prefix: String!,
    fd: FileDescriptor!,
    out: PrintWriter!,
    args: Array<String!>!
): Unit