SurfaceCallback

public interface SurfaceCallback

androidx.car.app.SurfaceCallback


A callback for changes on the SurfaceContainer and its attributes.

Summary

Public methods

default void onFling(float velocityX, float velocityY)

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

default void onScale(float focusX, float focusY, float scaleFactor)

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

default void onScroll(float distanceX, float distanceY)

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

default void onStableAreaChanged(Rect stableArea)

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

default void onSurfaceAvailable(SurfaceContainer surfaceContainer)

Provides a SurfaceContainer from the host which is ready for drawing.

default void onSurfaceDestroyed(SurfaceContainer surfaceContainer)

Indicates that the SurfaceContainer provided by the host will be destroyed after this callback.

default void onVisibleAreaChanged(Rect visibleArea)

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

Public methods

onFling

public void onFling (float velocityX, 
                float velocityY)

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

See NavigationTemplate class description for more details on how to receive this callback.

This method may not be called in some car systems.

Parameters
velocityX float: the velocity of this fling measured in pixels per second along the x axis

velocityY float: the velocity of this fling measured in pixels per second along the y axis

onScale

public void onScale (float focusX, 
                float focusY, 
                float scaleFactor)

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

See NavigationTemplate class description for more details on how to receive this callback.

This method may not be called in some car systems.

Parameters
focusX float: x coordinate of the focal point in pixels. A negative value indicates that the focal point is unavailable.

focusY float: y coordinate of the focal point in pixels. A negative value indicates that the focal point is unavailable.

scaleFactor float: 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

public void onScroll (float distanceX, 
                float distanceY)

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

See NavigationTemplate class description for more details on how to receive this callback.

Parameters
distanceX float: the distance in pixels along the X axis that has been scrolled since the last touch position during the scroll event

distanceY float: the distance in pixels along the Y axis that has been scrolled since the last touch position during the scroll event

onStableAreaChanged

public void onStableAreaChanged (Rect stableArea)

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 onVisibleAreaChanged(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 Rect: inset rectangle of the surface space designated as stable. If Rect.isEmpty() returns true for the stable area, then it is currently unknown

onSurfaceAvailable

public void onSurfaceAvailable (SurfaceContainer surfaceContainer)

Provides a 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.

Parameters
surfaceContainer SurfaceContainer: the SurfaceContainer that is ready for drawing

onSurfaceDestroyed

public void onSurfaceDestroyed (SurfaceContainer surfaceContainer)

Indicates that the SurfaceContainer provided by the host will be destroyed after this callback.

Parameters
surfaceContainer SurfaceContainer: the SurfaceContainer being destroyed

onVisibleAreaChanged

public void onVisibleAreaChanged (Rect visibleArea)

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 Rect: the rectangle set to the surface area guaranteed to be visible. If Rect.isEmpty() returns true for the visible area, then it is currently unknown