1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package android.window;
17 import android.annotation.NonNull;
18 import android.app.Activity;
19 import android.app.Dialog;
20 import android.view.View;
21 import android.view.Window;
22 
23 /**
24  * Interface for applications to register back animation callbacks along their custom back
25  * handling.
26  * <p>
27  * This allows the client to customize various back behaviors by overriding the corresponding
28  * callback methods.
29  * <p>
30  * Callback instances can be added to and removed from {@link OnBackInvokedDispatcher}, which
31  * is held at window level and accessible through {@link Activity#getOnBackInvokedDispatcher()},
32  * {@link Dialog#getOnBackInvokedDispatcher()}, {@link Window#getOnBackInvokedDispatcher()}
33  * and {@link View#findOnBackInvokedDispatcher()}.
34  * <p>
35  * When back is triggered, callbacks on the in-focus window are invoked in reverse order in which
36  * they are added within the same priority. Between different priorities, callbacks with higher
37  * priority are invoked first.
38  * <p>
39  * @see OnBackInvokedCallback
40  */
41 public interface OnBackAnimationCallback extends OnBackInvokedCallback {
42     /**
43      * Called when a back gesture has been started, or back button has been pressed down.
44      *
45      * @param backEvent The {@link BackEvent} containing information about the touch or
46      *                  button press.
47      * @see BackEvent
48      */
onBackStarted(@onNull BackEvent backEvent)49     default void onBackStarted(@NonNull BackEvent backEvent) {}
50 
51     /**
52      * Called when a back gesture progresses.
53      *
54      * @param backEvent An {@link BackEvent} object describing the progress event.
55      *
56      * @see BackEvent
57      */
onBackProgressed(@onNull BackEvent backEvent)58     default void onBackProgressed(@NonNull BackEvent backEvent) { }
59     /**
60      * Called when a back gesture or back button press has been cancelled.
61      */
onBackCancelled()62     default void onBackCancelled() { }
63 }
64