/* * Copyright (C) 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 android.view; import android.annotation.NonNull; import android.annotation.UiThread; import android.graphics.Rect; import java.util.function.Consumer; /** * A ScrollCaptureCallback is responsible for providing rendered snapshots of scrolling content for * the scroll capture system. A single callback is responsible for providing support to a single * scrolling UI element. At request time, the system will select the best candidate from among all * callbacks registered within the window. *
* A callback is assigned to a View using {@link View#setScrollCaptureCallback}, or to the window as * {@link Window#addScrollCaptureCallback}. The point where the callback is registered defines the * frame of reference for the bounds measurements used. *
* Terminology *
* Implementations should inset {@code containingViewBounds} to cover only the area within the * containing view where scrolling content may be positioned. This should cover only the content * which tracks with scrolling movement. *
* Return the updated rectangle to {@code resultConsumer}. If for any reason the scrolling * content is not available to capture, a {@code null} rectangle may be returned, and this view * will be excluded as the target for this request. *
* Responses received after XXXms will be discarded. *
* TODO: finalize timeout
*
* @param onReady consumer for the updated rectangle
*/
void onScrollCaptureSearch(@NonNull Consumer
* The onReady signal should be called when ready to begin handling image requests.
*/
void onScrollCaptureStart(@NonNull ScrollCaptureSession session, @NonNull Runnable onReady);
/**
* An image capture has been requested from the scrolling content.
*
*
* A series of requests will step by a constant vertical amount relative to {@code
* scrollBounds}, moving through the scrolling range of content, above and below the current
* visible area. The rectangle's vertical position will not account for any scrolling movement
* since capture started. Implementations therefore must track any scroll position changes and
* subtract this distance from requests.
*
* To handle a request, the content should be scrolled to maximize the visible area of the
* requested rectangle. Offset {@code captureArea} again to account for any further scrolling.
*
* Finally, clip this rectangle against scrollBounds to determine what portion, if any is
* visible content to capture. If the rectangle is completely clipped, set it to {@link
* Rect#setEmpty() empty} and skip the next step.
*
* Make a copy of {@code captureArea}, transform to window coordinates and draw the window,
* clipped to this rectangle, into the {@link ScrollCaptureSession#getSurface() surface} at
* offset (0,0).
*
* Finally, return the resulting {@code captureArea} using
* {@link ScrollCaptureSession#notifyBufferSent}.
*
* If the response is not supplied within XXXms, the session will end with a call to {@link
* #onScrollCaptureEnd}, after which {@code session} is invalid and should be discarded.
*
* TODO: finalize timeout
*
*
* @param captureArea the area to capture, a rectangle within {@code scrollBounds}
*/
void onScrollCaptureImageRequest(
@NonNull ScrollCaptureSession session, @NonNull Rect captureArea);
/**
* Signals that capture has ended. Implementations should release any temporary resources or
* references to objects in use during the capture. Any resources obtained from the session are
* now invalid and attempts to use them after this point may throw an exception.
*
* The window should be returned as much as possible to its original state when capture started.
* At a minimum, the content should be scrolled to its original position.
*
*
* TODO: finalize timeout
*
* @param onReady a callback to inform the system that the application has completed any
* cleanup and is ready to become visible
*/
void onScrollCaptureEnd(@NonNull Runnable onReady);
}
captureArea contains the bounds of the image requested, relative to the
* rectangle provided by {@link ScrollCaptureCallback#onScrollCaptureSearch}, referred to as
* {@code scrollBounds}.
* here.
* onReady should be called when the window should be made visible and
* interactive. The system will wait up to XXXms for this call before proceeding.
*