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