Rahul Ravikumar | 0533600 | 2019-10-14 15:04:32 -0700 | [diff] [blame] | 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 static android.view.WindowInsets.Type.ime; |
| 20 | |
| 21 | import android.annotation.NonNull; |
| 22 | import android.view.WindowInsets.Type.InsetType; |
| 23 | |
| 24 | /** |
| 25 | * Interface to control windows that generate insets. |
| 26 | * |
| 27 | * TODO Needs more information and examples once the API is more baked. |
| 28 | * @hide pending unhide |
| 29 | */ |
| 30 | public interface WindowInsetsController { |
| 31 | |
| 32 | /** |
| 33 | * Makes a set of windows that cause insets appear on screen. |
| 34 | * <p> |
| 35 | * Note that if the window currently doesn't have control over a certain type, it will apply the |
| 36 | * change as soon as the window gains control. The app can listen to the event by observing |
| 37 | * {@link View#onApplyWindowInsets} and checking visibility with {@link WindowInsets#isVisible}. |
| 38 | * |
| 39 | * @param types A bitmask of {@link WindowInsets.Type.InsetType} specifying what windows the app |
| 40 | * would like to make appear on screen. |
| 41 | * @hide |
| 42 | */ |
| 43 | void show(@InsetType int types); |
| 44 | |
| 45 | /** |
| 46 | * Makes a set of windows causing insets disappear. |
| 47 | * <p> |
| 48 | * Note that if the window currently doesn't have control over a certain type, it will apply the |
| 49 | * change as soon as the window gains control. The app can listen to the event by observing |
| 50 | * {@link View#onApplyWindowInsets} and checking visibility with {@link WindowInsets#isVisible}. |
| 51 | * |
| 52 | * @param types A bitmask of {@link WindowInsets.Type.InsetType} specifying what windows the app |
| 53 | * would like to make disappear. |
| 54 | * @hide |
| 55 | */ |
| 56 | void hide(@InsetType int types); |
| 57 | |
| 58 | /** |
| 59 | * Lets the application control window inset animations in a frame-by-frame manner by modifying |
| 60 | * the position of the windows in the system causing insets directly. |
| 61 | * |
| 62 | * @param types The {@link InsetType}s the application has requested to control. |
| 63 | * @param listener The {@link WindowInsetsAnimationControlListener} that gets called when the |
| 64 | * windows are ready to be controlled, among other callbacks. |
| 65 | * @hide |
| 66 | */ |
| 67 | void controlWindowInsetsAnimation(@InsetType int types, |
| 68 | @NonNull WindowInsetsAnimationControlListener listener); |
| 69 | |
| 70 | /** |
| 71 | * Lets the application control the animation for showing the IME in a frame-by-frame manner by |
| 72 | * modifying the position of the IME when it's causing insets. |
| 73 | * |
| 74 | * @param listener The {@link WindowInsetsAnimationControlListener} that gets called when the |
| 75 | * IME are ready to be controlled, among other callbacks. |
| 76 | */ |
| 77 | default void controlInputMethodAnimation( |
| 78 | @NonNull WindowInsetsAnimationControlListener listener) { |
| 79 | controlWindowInsetsAnimation(ime(), listener); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Makes the IME appear on screen. |
| 84 | * <p> |
| 85 | * Note that if the window currently doesn't have control over the IME, because it doesn't have |
| 86 | * focus, it will apply the change as soon as the window gains control. The app can listen to |
| 87 | * the event by observing {@link View#onApplyWindowInsets} and checking visibility with |
| 88 | * {@link WindowInsets#isVisible}. |
| 89 | * |
| 90 | * @see #controlInputMethodAnimation(WindowInsetsAnimationControlListener) |
| 91 | * @see #hideInputMethod() |
| 92 | */ |
| 93 | default void showInputMethod() { |
| 94 | show(ime()); |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Makes the IME disappear on screen. |
| 99 | * <p> |
| 100 | * Note that if the window currently doesn't have control over IME, because it doesn't have |
| 101 | * focus, it will apply the change as soon as the window gains control. The app can listen to |
| 102 | * the event by observing {@link View#onApplyWindowInsets} and checking visibility with |
| 103 | * {@link WindowInsets#isVisible}. |
| 104 | * |
| 105 | * @see #controlInputMethodAnimation(WindowInsetsAnimationControlListener) |
| 106 | * @see #showInputMethod() |
| 107 | */ |
| 108 | default void hideInputMethod() { |
| 109 | hide(ime()); |
| 110 | } |
| 111 | } |