# WallpaperService.Engine

Added in[API level 7](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Ctors](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#pubctors)\|[Methods](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#pubmethods)\|[Protected Methods](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#promethods)\|[Inherited Methods](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#inhmethods)  

# WallpaperService.Engine

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/service/wallpaper/WallpaperService.Engine "View this page in Kotlin")\|Java

`
public


class
WallpaperService.Engine
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|---------------------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.service.wallpaper.WallpaperService.Engine |

<br />

*** ** * ** ***

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()](https://developer.android.com/reference/android/service/wallpaper/WallpaperService#onCreateEngine())to return your concrete Engine implementation.

## Summary

|                                                           ### Public constructors                                                           ||
|------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[Engine](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#Engine())`() ` Default constructor |

|                                                                                                                                                                                                                                                                                                                                                                                        ### Public methods                                                                                                                                                                                                                                                                                                                                                                                        ||
|---------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` int`                                                                                                        | ` `[getDesiredMinimumHeight](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#getDesiredMinimumHeight())`() ` Convenience for[WallpaperManager.getDesiredMinimumHeight()](https://developer.android.com/reference/android/app/WallpaperManager#getDesiredMinimumHeight()), returning the height that the system would like this wallpaper to run in.                                                                                                                                                                                                                                                                                     |
| ` int`                                                                                                        | ` `[getDesiredMinimumWidth](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#getDesiredMinimumWidth())`() ` Convenience for[WallpaperManager.getDesiredMinimumWidth()](https://developer.android.com/reference/android/app/WallpaperManager#getDesiredMinimumWidth()), returning the width that the system would like this wallpaper to run in.                                                                                                                                                                                                                                                                                          |
| ` `[Context](https://developer.android.com/reference/android/content/Context)                                 | ` `[getDisplayContext](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#getDisplayContext())`() ` The[Context](https://developer.android.com/reference/android/content/Context)with resources that match the current display the wallpaper is on.                                                                                                                                                                                                                                                                                                                                                                                        |
| ` `[SurfaceHolder](https://developer.android.com/reference/android/view/SurfaceHolder)                        | ` `[getSurfaceHolder](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#getSurfaceHolder())`() ` Provides access to the surface in which this wallpaper is drawn.                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| ` int`                                                                                                        | ` `[getWallpaperFlags](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#getWallpaperFlags())`() ` Returns the current wallpaper flags indicating which screen this Engine is rendering to.                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| ` boolean`                                                                                                    | ` `[isPreview](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#isPreview())`() ` 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.                                                                                                                                                                                                                                                                                                                                                                                                        |
| ` boolean`                                                                                                    | ` `[isVisible](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#isVisible())`() ` Return whether the wallpaper is currently visible to the user, this is the last value supplied to[onVisibilityChanged(boolean)](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#onVisibilityChanged(boolean)).                                                                                                                                                                                                                                                                                               |
| ` void`                                                                                                       | ` `[notifyColorsChanged](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#notifyColorsChanged())`() ` Notifies the engine that wallpaper colors changed significantly.                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| ` `[WallpaperDescription](https://developer.android.com/reference/android/app/wallpaper/WallpaperDescription) | ` `[onApplyWallpaper](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#onApplyWallpaper(int))`(int which) ` Called when the wallpaper preview rendered by this engine is about to be persisted as a selected wallpaper.                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ` void`                                                                                                       | ` `[onApplyWindowInsets](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#onApplyWindowInsets(android.view.WindowInsets))`(`[WindowInsets](https://developer.android.com/reference/android/view/WindowInsets)` insets) ` Called with the current insets that are in effect for the wallpaper.                                                                                                                                                                                                                                                                                                                                            |
| ` `[Bundle](https://developer.android.com/reference/android/os/Bundle)                                        | ` `[onCommand](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#onCommand(java.lang.String,%20int,%20int,%20int,%20android.os.Bundle,%20boolean))`(`[String](https://developer.android.com/reference/java/lang/String)` action, int x, int y, int z, `[Bundle](https://developer.android.com/reference/android/os/Bundle)` extras, boolean resultRequested) ` Process a command that was sent to the wallpaper with[WallpaperManager.sendWallpaperCommand](https://developer.android.com/reference/android/app/WallpaperManager#sendWallpaperCommand(android.os.IBinder,%20java.lang.String,%20int,%20int,%20int,%20android.os.Bundle)). |
| ` `[WallpaperColors](https://developer.android.com/reference/android/app/WallpaperColors)                     | ` `[onComputeColors](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#onComputeColors())`() ` Called by the system when it needs to know what colors the wallpaper is using.                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ` void`                                                                                                       | ` `[onCreate](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#onCreate(android.view.SurfaceHolder))`(`[SurfaceHolder](https://developer.android.com/reference/android/view/SurfaceHolder)` surfaceHolder) ` Called once to initialize the engine.                                                                                                                                                                                                                                                                                                                                                                                       |
| ` void`                                                                                                       | ` `[onDesiredSizeChanged](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#onDesiredSizeChanged(int,%20int))`(int desiredWidth, int desiredHeight) ` Called when an application has changed the desired virtual size of the wallpaper.                                                                                                                                                                                                                                                                                                                                                                                                   |
| ` void`                                                                                                       | ` `[onDestroy](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#onDestroy())`() ` Called right before the engine is going away.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ` void`                                                                                                       | ` `[onOffsetsChanged](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#onOffsetsChanged(float,%20float,%20float,%20float,%20int,%20int))`(float xOffset, float yOffset, float xOffsetStep, float yOffsetStep, int xPixelOffset, int yPixelOffset) ` Called to inform you of the wallpaper's offsets changing within its contain, corresponding to the container's call to[WallpaperManager.setWallpaperOffsets()](https://developer.android.com/reference/android/app/WallpaperManager#setWallpaperOffsets(android.os.IBinder,%20float,%20float)).                                                                                       |
| ` void`                                                                                                       | ` `[onSurfaceChanged](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#onSurfaceChanged(android.view.SurfaceHolder,%20int,%20int,%20int))`(`[SurfaceHolder](https://developer.android.com/reference/android/view/SurfaceHolder)` holder, int format, int width, int height) ` Convenience for[SurfaceHolder.Callback.surfaceChanged()](https://developer.android.com/reference/android/view/SurfaceHolder.Callback#surfaceChanged(android.view.SurfaceHolder,%20int,%20int,%20int)).                                                                                                                                                     |
| ` void`                                                                                                       | ` `[onSurfaceCreated](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#onSurfaceCreated(android.view.SurfaceHolder))`(`[SurfaceHolder](https://developer.android.com/reference/android/view/SurfaceHolder)` holder) ` Convenience for[SurfaceHolder.Callback.surfaceCreated()](https://developer.android.com/reference/android/view/SurfaceHolder.Callback#surfaceCreated(android.view.SurfaceHolder)).                                                                                                                                                                                                                                  |
| ` void`                                                                                                       | ` `[onSurfaceDestroyed](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#onSurfaceDestroyed(android.view.SurfaceHolder))`(`[SurfaceHolder](https://developer.android.com/reference/android/view/SurfaceHolder)` holder) ` Convenience for[SurfaceHolder.Callback.surfaceDestroyed()](https://developer.android.com/reference/android/view/SurfaceHolder.Callback#surfaceDestroyed(android.view.SurfaceHolder)).                                                                                                                                                                                                                          |
| ` void`                                                                                                       | ` `[onSurfaceRedrawNeeded](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#onSurfaceRedrawNeeded(android.view.SurfaceHolder))`(`[SurfaceHolder](https://developer.android.com/reference/android/view/SurfaceHolder)` holder) ` Convenience for[SurfaceHolder.Callback.surfaceRedrawNeeded()](https://developer.android.com/reference/android/view/SurfaceHolder.Callback2#surfaceRedrawNeeded(android.view.SurfaceHolder)).                                                                                                                                                                                                             |
| ` void`                                                                                                       | ` `[onTouchEvent](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#onTouchEvent(android.view.MotionEvent))`(`[MotionEvent](https://developer.android.com/reference/android/view/MotionEvent)` event) ` Called as the user performs touch-screen interaction with the window that is currently showing this wallpaper.                                                                                                                                                                                                                                                                                                                    |
| ` void`                                                                                                       | ` `[onVisibilityChanged](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#onVisibilityChanged(boolean))`(boolean visible) ` Called to inform you of the wallpaper becoming visible or hidden.                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ` void`                                                                                                       | ` `[onWallpaperFlagsChanged](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#onWallpaperFlagsChanged(int))`(int which) ` Called when the current wallpaper flags change.                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| ` void`                                                                                                       | ` `[onZoomChanged](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#onZoomChanged(float))`(float zoom) ` Called when the zoom level of the wallpaper changed.                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ` void`                                                                                                       | ` `[setOffsetNotificationsEnabled](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#setOffsetNotificationsEnabled(boolean))`(boolean enabled) ` Control whether this wallpaper will receive notifications when the wallpaper has been scrolled.                                                                                                                                                                                                                                                                                                                                                                                          |
| ` void`                                                                                                       | ` `[setTouchEventsEnabled](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#setTouchEventsEnabled(boolean))`(boolean enabled) ` 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                                                                                                                                                                                                                                                               ||
|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` void` | ` `[dump](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#dump(java.lang.String,%20java.io.FileDescriptor,%20java.io.PrintWriter,%20java.lang.String[]))`(`[String](https://developer.android.com/reference/java/lang/String)` prefix, `[FileDescriptor](https://developer.android.com/reference/java/io/FileDescriptor)` fd, `[PrintWriter](https://developer.android.com/reference/java/io/PrintWriter)` out, `[String[]](https://developer.android.com/reference/java/lang/String)` args) ` |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Public constructors

### Engine

Added in[API level 7](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Engine ()
```

Default constructor

<br />

## Public methods

### getDesiredMinimumHeight

Added in[API level 7](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int getDesiredMinimumHeight ()
```

Convenience for[WallpaperManager.getDesiredMinimumHeight()](https://developer.android.com/reference/android/app/WallpaperManager#getDesiredMinimumHeight()), returning the height that the system would like this wallpaper to run in.

<br />

|    Returns    ||
|-------|--------|
| `int` | <br /> |

### getDesiredMinimumWidth

Added in[API level 7](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int getDesiredMinimumWidth ()
```

Convenience for[WallpaperManager.getDesiredMinimumWidth()](https://developer.android.com/reference/android/app/WallpaperManager#getDesiredMinimumWidth()), returning the width that the system would like this wallpaper to run in.

<br />

|    Returns    ||
|-------|--------|
| `int` | <br /> |

### getDisplayContext

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Context getDisplayContext ()
```

The[Context](https://developer.android.com/reference/android/content/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)](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#onCreate(android.view.SurfaceHolder))has been called.

<br />

|                                                                                      Returns                                                                                       ||
|----------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------|
| [Context](https://developer.android.com/reference/android/content/Context) | A[Context](https://developer.android.com/reference/android/content/Context)for current display. <br /> |

### getSurfaceHolder

Added in[API level 7](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public SurfaceHolder getSurfaceHolder ()
```

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

<br />

|                                           Returns                                           ||
|-------------------------------------------------------------------------------------|--------|
| [SurfaceHolder](https://developer.android.com/reference/android/view/SurfaceHolder) | <br /> |

### getWallpaperFlags

Added in[API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int getWallpaperFlags ()
```

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

<br />

|                                                                                                                                       Returns                                                                                                                                        ||
|-------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | Value is either`0`or a combination of[WallpaperManager.FLAG_SYSTEM](https://developer.android.com/reference/android/app/WallpaperManager#FLAG_SYSTEM), and[WallpaperManager.FLAG_LOCK](https://developer.android.com/reference/android/app/WallpaperManager#FLAG_LOCK) <br /> |

### isPreview

Added in[API level 7](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean isPreview ()
```

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.

<br />

|      Returns      ||
|-----------|--------|
| `boolean` | <br /> |

### isVisible

Added in[API level 7](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean isVisible ()
```

Return whether the wallpaper is currently visible to the user, this is the last value supplied to[onVisibilityChanged(boolean)](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#onVisibilityChanged(boolean)).

<br />

|      Returns      ||
|-----------|--------|
| `boolean` | <br /> |

### notifyColorsChanged

Added in[API level 27](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void notifyColorsChanged ()
```

Notifies the engine that wallpaper colors changed significantly. This will trigger a[onComputeColors()](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#onComputeColors())call.

<br />

### onApplyWallpaper

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public WallpaperDescription onApplyWallpaper (int which)
```

Called when the wallpaper preview rendered by this engine is about to be persisted as a selected wallpaper. The returned WallpaperDescription (if any) will be persisted by the system and passed into subsequent calls to[WallpaperService.onCreateEngine(WallpaperDescription)](https://developer.android.com/reference/android/service/wallpaper/WallpaperService#onCreateEngine(android.app.wallpaper.WallpaperDescription)). This allows the Engine to perform any necessary bookkeeping before a wallpaper being previewed is set on the device, and update the description if necessary.

<br />

|                                                                                                                                                                     Parameters                                                                                                                                                                     ||
|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `which` | `int`: Specifies wallpaper destination: home, lock, or both Value is either`0`or a combination of[WallpaperManager.FLAG_SYSTEM](https://developer.android.com/reference/android/app/WallpaperManager#FLAG_SYSTEM), and[WallpaperManager.FLAG_LOCK](https://developer.android.com/reference/android/app/WallpaperManager#FLAG_LOCK) <br /> |

|                                                                                             Returns                                                                                              ||
|------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------|
| [WallpaperDescription](https://developer.android.com/reference/android/app/wallpaper/WallpaperDescription) | the description of the applied wallpaper, or`null`if description is unchanged <br /> |

### onApplyWindowInsets

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void onApplyWindowInsets (WindowInsets insets)
```

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.

<br />

|                    Parameters                     ||
|----------|-----------------------------------------|
| `insets` | `WindowInsets`: Insets to apply. <br /> |

### onCommand

Added in[API level 7](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Bundle onCommand (String action, 
                int x, 
                int y, 
                int z, 
                Bundle extras, 
                boolean resultRequested)
```

Process a command that was sent to the wallpaper with[WallpaperManager.sendWallpaperCommand](https://developer.android.com/reference/android/app/WallpaperManager#sendWallpaperCommand(android.os.IBinder,%20java.lang.String,%20int,%20int,%20int,%20android.os.Bundle)). The default implementation does nothing, and always returns null as the result.  
This method must be called from the main thread of your app.

<br />

|                                                                    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. <br /> |
| `x`               | `int`: Generic integer parameter. <br />                                                                                       |
| `y`               | `int`: Generic integer parameter. <br />                                                                                       |
| `z`               | `int`: Generic integer parameter. <br />                                                                                       |
| `extras`          | `Bundle`: Any additional parameters. <br />                                                                                    |
| `resultRequested` | `boolean`: If true, the caller is requesting that a result, appropriate for the command, be returned back. <br />              |

|                                                                                    Returns                                                                                    ||
|---------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------|
| [Bundle](https://developer.android.com/reference/android/os/Bundle) | If returning a result, create a Bundle and place the result data in to it. Otherwise return null. <br /> |

### onComputeColors

Added in[API level 27](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public WallpaperColors onComputeColors ()
```

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()](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#notifyColorsChanged())when color information becomes available.

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

<br />

|                                                     Returns                                                      ||
|----------------------------------------------------------------------------------------|--------------------------|
| [WallpaperColors](https://developer.android.com/reference/android/app/WallpaperColors) | Wallpaper colors. <br /> |

### onCreate

Added in[API level 7](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void onCreate (SurfaceHolder surfaceHolder)
```

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.

<br />

|               Parameters                ||
|-----------------|------------------------|
| `surfaceHolder` | `SurfaceHolder` <br /> |

### onDesiredSizeChanged

Added in[API level 7](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void onDesiredSizeChanged (int desiredWidth, 
                int desiredHeight)
```

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.

<br />

|          Parameters           ||
|-----------------|--------------|
| `desiredWidth`  | `int` <br /> |
| `desiredHeight` | `int` <br /> |

### onDestroy

Added in[API level 7](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void onDestroy ()
```

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.

<br />

### onOffsetsChanged

Added in[API level 7](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void onOffsetsChanged (float xOffset, 
                float yOffset, 
                float xOffsetStep, 
                float yOffsetStep, 
                int xPixelOffset, 
                int yPixelOffset)
```

Called to inform you of the wallpaper's offsets changing within its contain, corresponding to the container's call to[WallpaperManager.setWallpaperOffsets()](https://developer.android.com/reference/android/app/WallpaperManager#setWallpaperOffsets(android.os.IBinder,%20float,%20float)).  
This method must be called from the main thread of your app.

<br />

|           Parameters           ||
|----------------|----------------|
| `xOffset`      | `float` <br /> |
| `yOffset`      | `float` <br /> |
| `xOffsetStep`  | `float` <br /> |
| `yOffsetStep`  | `float` <br /> |
| `xPixelOffset` | `int` <br />   |
| `yPixelOffset` | `int` <br />   |

### onSurfaceChanged

Added in[API level 7](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void onSurfaceChanged (SurfaceHolder holder, 
                int format, 
                int width, 
                int height)
```

Convenience for[SurfaceHolder.Callback.surfaceChanged()](https://developer.android.com/reference/android/view/SurfaceHolder.Callback#surfaceChanged(android.view.SurfaceHolder,%20int,%20int,%20int)).  
This method must be called from the main thread of your app.

<br />

|            Parameters            ||
|----------|------------------------|
| `holder` | `SurfaceHolder` <br /> |
| `format` | `int` <br />           |
| `width`  | `int` <br />           |
| `height` | `int` <br />           |

### onSurfaceCreated

Added in[API level 7](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void onSurfaceCreated (SurfaceHolder holder)
```

Convenience for[SurfaceHolder.Callback.surfaceCreated()](https://developer.android.com/reference/android/view/SurfaceHolder.Callback#surfaceCreated(android.view.SurfaceHolder)).  
This method must be called from the main thread of your app.

<br />

|            Parameters            ||
|----------|------------------------|
| `holder` | `SurfaceHolder` <br /> |

### onSurfaceDestroyed

Added in[API level 7](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void onSurfaceDestroyed (SurfaceHolder holder)
```

Convenience for[SurfaceHolder.Callback.surfaceDestroyed()](https://developer.android.com/reference/android/view/SurfaceHolder.Callback#surfaceDestroyed(android.view.SurfaceHolder)).  
This method must be called from the main thread of your app.

<br />

|            Parameters            ||
|----------|------------------------|
| `holder` | `SurfaceHolder` <br /> |

### onSurfaceRedrawNeeded

Added in[API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void onSurfaceRedrawNeeded (SurfaceHolder holder)
```

Convenience for[SurfaceHolder.Callback.surfaceRedrawNeeded()](https://developer.android.com/reference/android/view/SurfaceHolder.Callback2#surfaceRedrawNeeded(android.view.SurfaceHolder)).  
This method must be called from the main thread of your app.

<br />

|            Parameters            ||
|----------|------------------------|
| `holder` | `SurfaceHolder` <br /> |

### onTouchEvent

Added in[API level 7](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void onTouchEvent (MotionEvent event)
```

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.

<br />

|          Parameters           ||
|---------|----------------------|
| `event` | `MotionEvent` <br /> |

### onVisibilityChanged

Added in[API level 7](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void onVisibilityChanged (boolean visible)
```

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.

<br />

|         Parameters          ||
|-----------|------------------|
| `visible` | `boolean` <br /> |

### onWallpaperFlagsChanged

Added in[API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void onWallpaperFlagsChanged (int which)
```

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

<br />

|                                                                                                                                                    Parameters                                                                                                                                                    ||
|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `which` | `int`: The new flag value Value is either`0`or a combination of[WallpaperManager.FLAG_SYSTEM](https://developer.android.com/reference/android/app/WallpaperManager#FLAG_SYSTEM), and[WallpaperManager.FLAG_LOCK](https://developer.android.com/reference/android/app/WallpaperManager#FLAG_LOCK) <br /> |

**See also:**

- [getWallpaperFlags()](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#getWallpaperFlags())  

### onZoomChanged

Added in[API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void onZoomChanged (float zoom)
```

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.

<br />

|                                                                        Parameters                                                                        ||
|--------|--------------------------------------------------------------------------------------------------------------------------------------------------|
| `zoom` | `float`: the zoom level, between 0 indicating fully zoomed in and 1 indicating fully zoomed out. Value is between 0.0f and 1.0f inclusive <br /> |

### setOffsetNotificationsEnabled

Added in[API level 15](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setOffsetNotificationsEnabled (boolean enabled)
```

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.

<br />

|                                        Parameters                                        ||
|-----------|-------------------------------------------------------------------------------|
| `enabled` | `boolean`: whether the wallpaper wants to receive offset notifications <br /> |

### setTouchEventsEnabled

Added in[API level 7](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setTouchEventsEnabled (boolean enabled)
```

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)](https://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine#onTouchEvent(android.view.MotionEvent)).

<br />

|         Parameters          ||
|-----------|------------------|
| `enabled` | `boolean` <br /> |

## Protected methods

### dump

Added in[API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
protected void dump (String prefix, 
                FileDescriptor fd, 
                PrintWriter out, 
                String[] args)
```

<br />

<br />

|            Parameters             ||
|----------|-------------------------|
| `prefix` | `String` <br />         |
| `fd`     | `FileDescriptor` <br /> |
| `out`    | `PrintWriter` <br />    |
| `args`   | `String` <br />         |