1 /*
2  * Copyright (C) 2018 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 
17 package android.view;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.view.WindowInsets.Type.InsetsType;
22 import android.view.inputmethod.EditorInfo;
23 
24 /**
25  * Listener that encapsulates a request to
26  * {@link WindowInsetsController#controlWindowInsetsAnimation}.
27  *
28  * <p>
29  * Insets can be controlled with the supplied {@link WindowInsetsAnimationController} from
30  * {@link #onReady} until either {@link #onFinished} or {@link #onCancelled}.
31  *
32  * <p>
33  * Once the control over insets is finished or cancelled, it will not be regained until a new
34  * request to {@link WindowInsetsController#controlWindowInsetsAnimation} is made.
35  *
36  * <p>
37  * The request to control insets can fail immediately. In that case {@link #onCancelled} will be
38  * invoked without a preceding {@link #onReady}.
39  *
40  * @see WindowInsetsController#controlWindowInsetsAnimation
41  */
42 public interface WindowInsetsAnimationControlListener {
43 
44     /**
45      * Called when the animation is ready to be controlled. This may be delayed when the IME needs
46      * to redraw because of an {@link EditorInfo} change, or when the window is starting up.
47      *
48      * @param controller The controller to control the inset animation.
49      * @param types The {@link WindowInsets.Type}s it was able to gain control over. Note that this
50      *              may be different than the types passed into
51      *              {@link WindowInsetsController#controlWindowInsetsAnimation} in case the window
52      *              wasn't able to gain the controls because it wasn't the IME target or not
53      *              currently the window that's controlling the system bars.
54      * @see WindowInsetsAnimationController#isReady
55      */
onReady(@onNull WindowInsetsAnimationController controller, @InsetsType int types)56     void onReady(@NonNull WindowInsetsAnimationController controller, @InsetsType int types);
57 
58     /**
59      * Called when the request for control over the insets has
60      * {@link WindowInsetsAnimationController#finish finished}.
61      *
62      * Once this callback is invoked, the supplied {@link WindowInsetsAnimationController}
63      * is no longer {@link WindowInsetsAnimationController#isReady() ready}.
64      *
65      * Control will not be regained until a new request
66      * to {@link WindowInsetsController#controlWindowInsetsAnimation} is made.
67      *
68      * @param controller the controller which has finished.
69      * @see WindowInsetsAnimationController#isFinished
70      */
onFinished(@onNull WindowInsetsAnimationController controller)71     void onFinished(@NonNull WindowInsetsAnimationController controller);
72 
73     /**
74      * Called when the request for control over the insets has been cancelled, either
75      * because the {@link android.os.CancellationSignal} associated with the
76      * {@link WindowInsetsController#controlWindowInsetsAnimation request} has been invoked, or
77      * the window has lost control over the insets (e.g. because it lost focus).
78      *
79      * Once this callback is invoked, the supplied {@link WindowInsetsAnimationController}
80      * is no longer {@link WindowInsetsAnimationController#isReady() ready}.
81      *
82      * Control will not be regained until a new request
83      * to {@link WindowInsetsController#controlWindowInsetsAnimation} is made.
84      *
85      * @param controller the controller which has been cancelled, or null if the request
86      *                   was cancelled before {@link #onReady} was invoked.
87      * @see WindowInsetsAnimationController#isCancelled
88      */
onCancelled(@ullable WindowInsetsAnimationController controller)89     void onCancelled(@Nullable WindowInsetsAnimationController controller);
90 }
91