# SurfaceCallback

Artifact: [androidx.car.app:app](https://developer.android.com/jetpack/androidx/releases/car-app) [View Source](https://cs.android.com/search?q=file:androidx/car/app/SurfaceCallback.java+class:androidx.car.app.SurfaceCallback) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

*** ** * ** ***


```
interface SurfaceCallback
```

<br />

*** ** * ** ***

A callback for changes on the `https://developer.android.com/reference/kotlin/androidx/car/app/SurfaceContainer` and its attributes.

## Summary

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/car/app/annotations/RequiresCarApi(value = 5) https://developer.android.com/reference/kotlin/androidx/car/app/SurfaceCallback#onClick(float,float)(x: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, y: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Provides information about a click event on the car screen. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/car/app/annotations/RequiresCarApi(value = 2) https://developer.android.com/reference/kotlin/androidx/car/app/SurfaceCallback#onFling(float,float)(velocityX: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, velocityY: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Provides information about a fling touch event on the car screen. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/car/app/annotations/RequiresCarApi(value = 2) https://developer.android.com/reference/kotlin/androidx/car/app/SurfaceCallback#onScale(float,float,float)(focusX: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, focusY: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, scaleFactor: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Provides information about a scale touch event on the car screen. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/car/app/annotations/RequiresCarApi(value = 2) https://developer.android.com/reference/kotlin/androidx/car/app/SurfaceCallback#onScroll(float,float)(distanceX: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, distanceY: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Provides information about a scroll touch event on the car screen. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/SurfaceCallback#onStableAreaChanged(android.graphics.Rect)(stableArea: https://developer.android.com/reference/android/graphics/Rect.html)` Indicates that the stable area provided by the host has changed. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/SurfaceCallback#onSurfaceAvailable(androidx.car.app.SurfaceContainer)(surfaceContainer: https://developer.android.com/reference/kotlin/androidx/car/app/SurfaceContainer)` Provides a `https://developer.android.com/reference/kotlin/androidx/car/app/SurfaceContainer` from the host which is ready for drawing. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/SurfaceCallback#onSurfaceDestroyed(androidx.car.app.SurfaceContainer)(surfaceContainer: https://developer.android.com/reference/kotlin/androidx/car/app/SurfaceContainer)` Indicates that the `https://developer.android.com/reference/kotlin/androidx/car/app/SurfaceContainer` provided by the host will be destroyed after this callback. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/SurfaceCallback#onVisibleAreaChanged(android.graphics.Rect)(visibleArea: https://developer.android.com/reference/android/graphics/Rect.html)` Indicates that the visible area provided by the host has changed. |

## Public functions

### onClick

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.2.0)

```
@RequiresCarApi(value = 5)
fun onClick(x: Float, y: Float): Unit
```

Provides information about a click event on the car screen.

See `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/model/NavigationTemplate` class description for more details on how to receive this callback.

This method may not be called in some car systems.

| Parameters |
|---|---|
| `x: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | x coordinate of the click in pixels |
| `y: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | y coordinate of the click in pixels |

### onFling

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.1.0)

```
@RequiresCarApi(value = 2)
fun onFling(velocityX: Float, velocityY: Float): Unit
```

Provides information about a fling touch event on the car screen.

See `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/model/NavigationTemplate` class description for more details on how to receive this callback.

This method may not be called in some car systems.

| Parameters |
|---|---|
| `velocityX: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | the velocity of this fling measured in pixels per second along the x axis |
| `velocityY: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | the velocity of this fling measured in pixels per second along the y axis |

### onScale

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.1.0)

```
@RequiresCarApi(value = 2)
fun onScale(focusX: Float, focusY: Float, scaleFactor: Float): Unit
```

Provides information about a scale touch event on the car screen.

See `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/model/NavigationTemplate` class description for more details on how to receive this callback.

This method may not be called in some car systems.

| Parameters |
|---|---|
| `focusX: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | x coordinate of the focal point in pixels. A negative value indicates that the focal point is unavailable. |
| `focusY: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | y coordinate of the focal point in pixels. A negative value indicates that the focal point is unavailable. |
| `scaleFactor: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | the scaling factor from the previous state to the current state during the scale event. This value is defined as (current state) / (previous state) |

### onScroll

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.1.0)

```
@RequiresCarApi(value = 2)
fun onScroll(distanceX: Float, distanceY: Float): Unit
```

Provides information about a scroll touch event on the car screen.

See `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/model/NavigationTemplate` class description for more details on how to receive this callback.

| Parameters |
|---|---|
| `distanceX: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | the distance in pixels along the X axis that has been scrolled since the last touch position during the scroll event |
| `distanceY: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | the distance in pixels along the Y axis that has been scrolled since the last touch position during the scroll event |

### onStableAreaChanged

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
fun onStableAreaChanged(stableArea: Rect): Unit
```

Indicates that the stable area provided by the host has changed.

The surface may be occluded for several reasons including status bar changes, overlays from other apps or dynamic UI within the template (also see `https://developer.android.com/reference/kotlin/androidx/car/app/SurfaceCallback#onVisibleAreaChanged(android.graphics.Rect)`). The stable area is the visual area that accounts for these occlusions as if they were always present. If the app needs to show more persistent data that do not necessarily adjust based on these dynamic content changes, it should be bounded by this area.

| Parameters |
|---|---|
| `stableArea: https://developer.android.com/reference/android/graphics/Rect.html` | inset rectangle of the surface space designated as stable. If `https://developer.android.com/reference/android/graphics/Rect.html#isEmpty()` returns `true` for the stable area, then it is currently unknown |

### onSurfaceAvailable

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
fun onSurfaceAvailable(surfaceContainer: SurfaceContainer): Unit
```

Provides a `https://developer.android.com/reference/kotlin/androidx/car/app/SurfaceContainer` from the host which is ready for drawing.

This method may be called multiple times if the surface changes characteristics. For instance, the size or DPI may change without the underlying surface being destroyed.

This method is guaranteed to be called before any other methods on this listener.

**Important:** every instance of `https://developer.android.com/reference/android/view/Surface.html` received through this method must be released by calling `https://developer.android.com/reference/android/view/Surface.html#release()`.

| Parameters |
|---|---|
| `surfaceContainer: https://developer.android.com/reference/kotlin/androidx/car/app/SurfaceContainer` | the `https://developer.android.com/reference/kotlin/androidx/car/app/SurfaceContainer` that is ready for drawing |

### onSurfaceDestroyed

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
fun onSurfaceDestroyed(surfaceContainer: SurfaceContainer): Unit
```

Indicates that the `https://developer.android.com/reference/kotlin/androidx/car/app/SurfaceContainer` provided by the host will be destroyed after this callback.

| Parameters |
|---|---|
| `surfaceContainer: https://developer.android.com/reference/kotlin/androidx/car/app/SurfaceContainer` | the `https://developer.android.com/reference/kotlin/androidx/car/app/SurfaceContainer` being destroyed |

### onVisibleAreaChanged

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
fun onVisibleAreaChanged(visibleArea: Rect): Unit
```

Indicates that the visible area provided by the host has changed.

The surface may be occluded for several reasons including status bar changes, overlays from other apps or dynamic UI within a template. `visibleArea` is the area currently guaranteed to not be occluded by any other UI. If the app needs to show critical data, it should be bounded by this area.

| Parameters |
|---|---|
| `visibleArea: https://developer.android.com/reference/android/graphics/Rect.html` | the rectangle set to the surface area guaranteed to be visible. If `https://developer.android.com/reference/android/graphics/Rect.html#isEmpty()` returns `true` for the visible area, then it is currently unknown |