public interface

SurfaceCallback

 androidx.car.app.SurfaceCallback

Gradle dependencies

compile group: 'androidx.car.app', name: 'app', version: '1.2.0-rc01'

  • groupId: androidx.car.app
  • artifactId: app
  • version: 1.2.0-rc01

Artifact androidx.car.app:app:1.2.0-rc01 it located at Google repository (https://maven.google.com/)

Overview

A callback for changes on the SurfaceContainer and its attributes.

Summary

Methods
public voidonClick(float x, float y)

Provides information about a click event on the car screen.

public voidonFling(float velocityX, float velocityY)

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

public voidonScale(float focusX, float focusY, float scaleFactor)

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

public voidonScroll(float distanceX, float distanceY)

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

public voidonStableAreaChanged(Rect stableArea)

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

public voidonSurfaceAvailable(SurfaceContainer surfaceContainer)

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

public voidonSurfaceDestroyed(SurfaceContainer surfaceContainer)

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

public voidonVisibleAreaChanged(Rect visibleArea)

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

Methods

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.

Important: every instance of received through this method must be released by calling .

Parameters:

surfaceContainer: the SurfaceContainer that is ready for drawing

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

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

public void onSurfaceDestroyed(SurfaceContainer surfaceContainer)

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

Parameters:

surfaceContainer: the SurfaceContainer being destroyed

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: the distance in pixels along the X axis that has been scrolled since the last touch position during the scroll event
distanceY: the distance in pixels along the Y axis that has been scrolled since the last touch position during the scroll event

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: the velocity of this fling measured in pixels per second along the x axis
velocityY: the velocity of this fling measured in pixels per second along the y axis

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: x coordinate of the focal point in pixels. A negative value indicates that the focal point is unavailable.
focusY: y coordinate of the focal point in pixels. A negative value indicates that the focal point is unavailable.
scaleFactor: the scaling factor from the previous state to the current state during the scale event. This value is defined as (current state) / (previous state)

public void onClick(float x, float y)

Provides information about a click 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:

x: x coordinate of the click in pixels
y: y coordinate of the click in pixels

Source

/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.car.app;

import android.graphics.Rect;
import android.view.Surface;

import androidx.annotation.NonNull;
import androidx.car.app.annotations.ExperimentalCarApi;
import androidx.car.app.annotations.RequiresCarApi;

/** A callback for changes on the {@link SurfaceContainer} and its attributes. */
public interface SurfaceCallback {
    /**
     * Provides a {@link SurfaceContainer} from the host which is ready for drawing.
     *
     * <p>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.
     *
     * <p>This method is guaranteed to be called before any other methods on this listener.
     *
     * <p><b>Important:</b> every instance of {@link android.view.Surface} received through this
     * method must be released by calling {@link Surface#release()}.
     *
     * @param surfaceContainer the {@link SurfaceContainer} that is ready for drawing
     */
    default void onSurfaceAvailable(@NonNull SurfaceContainer surfaceContainer) {
    }

    /**
     * Indicates that the visible area provided by the host has changed.
     *
     * <p>The surface may be occluded for several reasons including status bar changes, overlays
     * from other apps or dynamic UI within a template. {@code 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.
     *
     * @param visibleArea the rectangle set to the surface area guaranteed to be visible. If {@link
     *                    Rect#isEmpty()} returns {@code true} for the visible area, then it is
     *                    currently unknown
     */
    default void onVisibleAreaChanged(@NonNull Rect visibleArea) {
    }

    /**
     * Indicates that the stable area provided by the host has changed.
     *
     * <p>The surface may be occluded for several reasons including status bar changes, overlays
     * from other apps or dynamic UI within the template (also see {@link #onVisibleAreaChanged}).
     * 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.
     *
     * @param stableArea inset rectangle of the surface space designated as stable. If {@link
     *                   Rect#isEmpty()} returns {@code true} for the stable area, then it is
     *                   currently unknown
     */
    default void onStableAreaChanged(@NonNull Rect stableArea) {
    }

    /**
     * Indicates that the {@link SurfaceContainer} provided by the host will be destroyed after this
     * callback.
     *
     * @param surfaceContainer the {@link SurfaceContainer} being destroyed
     */
    default void onSurfaceDestroyed(@NonNull SurfaceContainer surfaceContainer) {
    }

    /**
     * Provides information about a scroll touch event on the car screen.
     *
     * <p>See {@link androidx.car.app.navigation.model.NavigationTemplate} class description for
     * more details on how to receive this callback.
     *
     * @param distanceX the distance in pixels along the X axis that has been scrolled since the
     *                  last touch position during the scroll event
     * @param distanceY the distance in pixels along the Y axis that has been scrolled since the
     *                  last touch position during the scroll event
     */
    @RequiresCarApi(2)
    default void onScroll(float distanceX, float distanceY) {
    }

    /**
     * Provides information about a fling touch event on the car screen.
     *
     * <p>See {@link androidx.car.app.navigation.model.NavigationTemplate} class description for
     * more details on how to receive this callback.
     *
     * <p>This method may not be called in some car systems.
     *
     * @param velocityX the velocity of this fling measured in pixels per second along the x axis
     * @param velocityY the velocity of this fling measured in pixels per second along the y axis
     */
    @RequiresCarApi(2)
    default void onFling(float velocityX, float velocityY) {
    }

    /**
     * Provides information about a scale touch event on the car screen.
     *
     * <p>See {@link androidx.car.app.navigation.model.NavigationTemplate} class description for
     * more details on how to receive this callback.
     *
     * <p>This method may not be called in some car systems.
     *
     * @param focusX x coordinate of the focal point in pixels. A negative value indicates that
     *               the focal point is unavailable.
     * @param focusY y coordinate of the focal point in pixels. A negative value indicates that
     *               the focal point is unavailable.
     * @param scaleFactor the scaling factor from the previous state to the current
     *                    state during the scale event. This value is defined as (current state)
     *                    / (previous state)
     */
    @RequiresCarApi(2)
    default void onScale(float focusX, float focusY, float scaleFactor) {
    }

    /**
     * Provides information about a click event on the car screen.
     *
     * <p>See {@link androidx.car.app.navigation.model.NavigationTemplate} class description for
     * more details on how to receive this callback.
     *
     * <p>This method may not be called in some car systems.
     *
     * @param x x coordinate of the click in pixels
     * @param y y coordinate of the click in pixels
     */
    @RequiresCarApi(5)
    @ExperimentalCarApi
    default void onClick(float x, float y) {
    }
}