Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [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 | |
Jorim Jaggi | 2ae3913 | 2019-01-24 13:02:50 +0100 | [diff] [blame] | 19 | import static android.view.WindowInsets.Type.ime; |
| 20 | |
Jorim Jaggi | b7848b7 | 2018-12-28 14:38:21 +0100 | [diff] [blame] | 21 | import android.annotation.IntDef; |
Jorim Jaggi | 5bb571d | 2018-11-06 14:42:04 +0100 | [diff] [blame] | 22 | import android.annotation.NonNull; |
Jorim Jaggi | b7848b7 | 2018-12-28 14:38:21 +0100 | [diff] [blame] | 23 | import android.graphics.Insets; |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 24 | import android.view.WindowInsets.Type.InsetType; |
| 25 | |
Jorim Jaggi | b7848b7 | 2018-12-28 14:38:21 +0100 | [diff] [blame] | 26 | import java.lang.annotation.Retention; |
| 27 | import java.lang.annotation.RetentionPolicy; |
| 28 | |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 29 | /** |
| 30 | * Interface to control windows that generate insets. |
| 31 | * |
| 32 | * TODO Needs more information and examples once the API is more baked. |
| 33 | * @hide pending unhide |
| 34 | */ |
| 35 | public interface WindowInsetsController { |
| 36 | |
| 37 | /** |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 38 | * Makes the top bars become opaque with solid dark background and light foreground. |
Jorim Jaggi | b7848b7 | 2018-12-28 14:38:21 +0100 | [diff] [blame] | 39 | * @hide |
| 40 | */ |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 41 | int APPEARANCE_OPAQUE_TOP_BAR = 1; |
| 42 | |
| 43 | /** |
| 44 | * Makes the side bars become opaque with solid dark background and light foreground. |
| 45 | * @hide |
| 46 | */ |
| 47 | int APPEARANCE_OPAQUE_SIDE_BARS = 1 << 1; |
Jorim Jaggi | b7848b7 | 2018-12-28 14:38:21 +0100 | [diff] [blame] | 48 | |
| 49 | /** |
| 50 | * Makes items on system bars become less noticeable without changing the layout of the bars. |
| 51 | * @hide |
| 52 | */ |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 53 | int APPEARANCE_LOW_PROFILE_BARS = 1 << 2; |
Jorim Jaggi | b7848b7 | 2018-12-28 14:38:21 +0100 | [diff] [blame] | 54 | |
| 55 | /** |
| 56 | * Changes the foreground color for the light top bar so that the items on the bar can be read |
| 57 | * clearly. |
| 58 | */ |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 59 | int APPEARANCE_LIGHT_TOP_BAR = 1 << 3; |
Jorim Jaggi | b7848b7 | 2018-12-28 14:38:21 +0100 | [diff] [blame] | 60 | |
| 61 | /** |
| 62 | * Changes the foreground color for the light side bars so that the items on the bar can be read |
| 63 | * clearly. |
| 64 | */ |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 65 | int APPEARANCE_LIGHT_SIDE_BARS = 1 << 4; |
Jorim Jaggi | b7848b7 | 2018-12-28 14:38:21 +0100 | [diff] [blame] | 66 | |
| 67 | /** Determines the appearance of system bars. */ |
| 68 | @Retention(RetentionPolicy.SOURCE) |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 69 | @IntDef(flag = true, value = {APPEARANCE_OPAQUE_TOP_BAR, APPEARANCE_OPAQUE_SIDE_BARS, |
| 70 | APPEARANCE_LOW_PROFILE_BARS, APPEARANCE_LIGHT_TOP_BAR, APPEARANCE_LIGHT_SIDE_BARS}) |
Jorim Jaggi | b7848b7 | 2018-12-28 14:38:21 +0100 | [diff] [blame] | 71 | @interface Appearance { |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * The default option for {@link #setSystemBarsBehavior(int)}. The side bars will be forcibly |
| 76 | * shown by the system on any user interaction on the corresponding display if the side bars are |
| 77 | * hidden by {@link #hide(int)} or {@link WindowInsetsAnimationController#changeInsets(Insets)}. |
| 78 | */ |
| 79 | int BEHAVIOR_SHOW_SIDE_BARS_BY_TOUCH = 0; |
| 80 | |
| 81 | /** |
| 82 | * Option for {@link #setSystemBarsBehavior(int)}: Window would like to remain interactive when |
| 83 | * hiding the side bars by calling {@link #hide(int)} or |
| 84 | * {@link WindowInsetsAnimationController#changeInsets(Insets)}. |
| 85 | * |
| 86 | * <p>When system bars are hidden in this mode, they can be revealed with system gestures, such |
| 87 | * as swiping from the edge of the screen where the bar is hidden from.</p> |
| 88 | */ |
| 89 | int BEHAVIOR_SHOW_BARS_BY_SWIPE = 1; |
| 90 | |
| 91 | /** |
| 92 | * Option for {@link #setSystemBarsBehavior(int)}: Window would like to remain interactive when |
| 93 | * hiding the side bars by calling {@link #hide(int)} or |
| 94 | * {@link WindowInsetsAnimationController#changeInsets(Insets)}. |
| 95 | * |
| 96 | * <p>When system bars are hidden in this mode, they can be revealed temporarily with system |
| 97 | * gestures, such as swiping from the edge of the screen where the bar is hidden from. These |
| 98 | * transient system bars will overlay app’s content, may have some degree of transparency, and |
| 99 | * will automatically hide after a short timeout.</p> |
| 100 | */ |
| 101 | int BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE = 2; |
| 102 | |
| 103 | /** Determines the behavior of system bars when hiding them by calling {@link #hide}. */ |
| 104 | @Retention(RetentionPolicy.SOURCE) |
| 105 | @IntDef(value = {BEHAVIOR_SHOW_SIDE_BARS_BY_TOUCH, BEHAVIOR_SHOW_BARS_BY_SWIPE, |
| 106 | BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE}) |
| 107 | @interface Behavior { |
| 108 | } |
| 109 | |
| 110 | /** |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 111 | * Makes a set of windows that cause insets appear on screen. |
| 112 | * <p> |
| 113 | * Note that if the window currently doesn't have control over a certain type, it will apply the |
| 114 | * change as soon as the window gains control. The app can listen to the event by observing |
Jorim Jaggi | 2ae3913 | 2019-01-24 13:02:50 +0100 | [diff] [blame] | 115 | * {@link View#onApplyWindowInsets} and checking visibility with {@link WindowInsets#isVisible}. |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 116 | * |
| 117 | * @param types A bitmask of {@link WindowInsets.Type.InsetType} specifying what windows the app |
| 118 | * would like to make appear on screen. |
Jorim Jaggi | 2ae3913 | 2019-01-24 13:02:50 +0100 | [diff] [blame] | 119 | * @hide |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 120 | */ |
| 121 | void show(@InsetType int types); |
| 122 | |
| 123 | /** |
| 124 | * Makes a set of windows causing insets disappear. |
| 125 | * <p> |
| 126 | * Note that if the window currently doesn't have control over a certain type, it will apply the |
| 127 | * change as soon as the window gains control. The app can listen to the event by observing |
Jorim Jaggi | 2ae3913 | 2019-01-24 13:02:50 +0100 | [diff] [blame] | 128 | * {@link View#onApplyWindowInsets} and checking visibility with {@link WindowInsets#isVisible}. |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 129 | * |
| 130 | * @param types A bitmask of {@link WindowInsets.Type.InsetType} specifying what windows the app |
| 131 | * would like to make disappear. |
Jorim Jaggi | 2ae3913 | 2019-01-24 13:02:50 +0100 | [diff] [blame] | 132 | * @hide |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 133 | */ |
| 134 | void hide(@InsetType int types); |
Jorim Jaggi | 5bb571d | 2018-11-06 14:42:04 +0100 | [diff] [blame] | 135 | |
| 136 | /** |
| 137 | * Lets the application control window inset animations in a frame-by-frame manner by modifying |
| 138 | * the position of the windows in the system causing insets directly. |
| 139 | * |
| 140 | * @param types The {@link InsetType}s the application has requested to control. |
| 141 | * @param listener The {@link WindowInsetsAnimationControlListener} that gets called when the |
| 142 | * windows are ready to be controlled, among other callbacks. |
Jorim Jaggi | 2ae3913 | 2019-01-24 13:02:50 +0100 | [diff] [blame] | 143 | * @hide |
Jorim Jaggi | 5bb571d | 2018-11-06 14:42:04 +0100 | [diff] [blame] | 144 | */ |
| 145 | void controlWindowInsetsAnimation(@InsetType int types, |
| 146 | @NonNull WindowInsetsAnimationControlListener listener); |
Jorim Jaggi | 2ae3913 | 2019-01-24 13:02:50 +0100 | [diff] [blame] | 147 | |
| 148 | /** |
| 149 | * Lets the application control the animation for showing the IME in a frame-by-frame manner by |
| 150 | * modifying the position of the IME when it's causing insets. |
| 151 | * |
| 152 | * @param listener The {@link WindowInsetsAnimationControlListener} that gets called when the |
| 153 | * IME are ready to be controlled, among other callbacks. |
| 154 | */ |
| 155 | default void controlInputMethodAnimation( |
| 156 | @NonNull WindowInsetsAnimationControlListener listener) { |
| 157 | controlWindowInsetsAnimation(ime(), listener); |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Makes the IME appear on screen. |
| 162 | * <p> |
| 163 | * Note that if the window currently doesn't have control over the IME, because it doesn't have |
| 164 | * focus, it will apply the change as soon as the window gains control. The app can listen to |
| 165 | * the event by observing {@link View#onApplyWindowInsets} and checking visibility with |
| 166 | * {@link WindowInsets#isVisible}. |
| 167 | * |
| 168 | * @see #controlInputMethodAnimation(WindowInsetsAnimationControlListener) |
| 169 | * @see #hideInputMethod() |
| 170 | */ |
| 171 | default void showInputMethod() { |
| 172 | show(ime()); |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Makes the IME disappear on screen. |
| 177 | * <p> |
| 178 | * Note that if the window currently doesn't have control over IME, because it doesn't have |
| 179 | * focus, it will apply the change as soon as the window gains control. The app can listen to |
| 180 | * the event by observing {@link View#onApplyWindowInsets} and checking visibility with |
| 181 | * {@link WindowInsets#isVisible}. |
| 182 | * |
| 183 | * @see #controlInputMethodAnimation(WindowInsetsAnimationControlListener) |
| 184 | * @see #showInputMethod() |
| 185 | */ |
| 186 | default void hideInputMethod() { |
| 187 | hide(ime()); |
| 188 | } |
Jorim Jaggi | b7848b7 | 2018-12-28 14:38:21 +0100 | [diff] [blame] | 189 | |
| 190 | /** |
| 191 | * Controls the appearance of system bars. |
| 192 | * |
| 193 | * @param appearance Bitmask of {@link Appearance} flags. |
| 194 | * @see Appearance |
| 195 | */ |
| 196 | void setSystemBarsAppearance(@Appearance int appearance); |
| 197 | |
| 198 | /** |
| 199 | * Controls the behavior of system bars. |
| 200 | * |
| 201 | * @param behavior Determines how the bars behave when being hidden by the application. |
| 202 | * @see Behavior |
| 203 | */ |
| 204 | void setSystemBarsBehavior(@Behavior int behavior); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 205 | } |