blob: 39e2e73f6fa8c59e08f7cbd27198dbdf3ab20092 [file] [log] [blame]
Jorim Jaggib6030952018-10-23 18:31:52 +02001/*
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
17package android.view;
18
Jorim Jaggi2ae39132019-01-24 13:02:50 +010019import static android.view.WindowInsets.Type.ime;
20
Jorim Jaggib7848b72018-12-28 14:38:21 +010021import android.annotation.IntDef;
Jorim Jaggi5bb571d2018-11-06 14:42:04 +010022import android.annotation.NonNull;
Jorim Jaggib7848b72018-12-28 14:38:21 +010023import android.graphics.Insets;
Tiger Huang332793b2019-10-29 23:21:27 +080024import android.view.WindowInsets.Type.InsetsType;
Jorim Jaggib6030952018-10-23 18:31:52 +020025
Jorim Jaggib7848b72018-12-28 14:38:21 +010026import java.lang.annotation.Retention;
27import java.lang.annotation.RetentionPolicy;
28
Jorim Jaggib6030952018-10-23 18:31:52 +020029/**
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 */
35public interface WindowInsetsController {
36
37 /**
Tiger Huang332793b2019-10-29 23:21:27 +080038 * Makes status bars become opaque with solid dark background and light foreground.
Jorim Jaggib7848b72018-12-28 14:38:21 +010039 * @hide
40 */
Tiger Huang332793b2019-10-29 23:21:27 +080041 int APPEARANCE_OPAQUE_STATUS_BARS = 1;
Jorim Jaggi956ca412019-01-07 14:49:14 +010042
43 /**
Tiger Huang332793b2019-10-29 23:21:27 +080044 * Makes navigation bars become opaque with solid dark background and light foreground.
Jorim Jaggi956ca412019-01-07 14:49:14 +010045 * @hide
46 */
Tiger Huang332793b2019-10-29 23:21:27 +080047 int APPEARANCE_OPAQUE_NAVIGATION_BARS = 1 << 1;
Jorim Jaggib7848b72018-12-28 14:38:21 +010048
49 /**
50 * Makes items on system bars become less noticeable without changing the layout of the bars.
51 * @hide
52 */
Jorim Jaggi956ca412019-01-07 14:49:14 +010053 int APPEARANCE_LOW_PROFILE_BARS = 1 << 2;
Jorim Jaggib7848b72018-12-28 14:38:21 +010054
55 /**
Tiger Huang332793b2019-10-29 23:21:27 +080056 * Changes the foreground color for light status bars so that the items on the bar can be read
Jorim Jaggib7848b72018-12-28 14:38:21 +010057 * clearly.
58 */
Tiger Huang332793b2019-10-29 23:21:27 +080059 int APPEARANCE_LIGHT_STATUS_BARS = 1 << 3;
Jorim Jaggib7848b72018-12-28 14:38:21 +010060
61 /**
Tiger Huang332793b2019-10-29 23:21:27 +080062 * Changes the foreground color for light navigation bars so that the items on the bar can be
63 * read clearly.
Jorim Jaggib7848b72018-12-28 14:38:21 +010064 */
Tiger Huang332793b2019-10-29 23:21:27 +080065 int APPEARANCE_LIGHT_NAVIGATION_BARS = 1 << 4;
Jorim Jaggib7848b72018-12-28 14:38:21 +010066
67 /** Determines the appearance of system bars. */
68 @Retention(RetentionPolicy.SOURCE)
Tiger Huang332793b2019-10-29 23:21:27 +080069 @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 Jaggib7848b72018-12-28 14:38:21 +010072 @interface Appearance {
73 }
74
75 /**
Tiger Huang332793b2019-10-29 23:21:27 +080076 * 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 Jaggib7848b72018-12-28 14:38:21 +010079 */
Tiger Huang332793b2019-10-29 23:21:27 +080080 int BEHAVIOR_SHOW_BARS_BY_TOUCH = 0;
Jorim Jaggib7848b72018-12-28 14:38:21 +010081
82 /**
83 * Option for {@link #setSystemBarsBehavior(int)}: Window would like to remain interactive when
Tiger Huang332793b2019-10-29 23:21:27 +080084 * hiding navigation bars by calling {@link #hide(int)} or
Jorim Jaggib7848b72018-12-28 14:38:21 +010085 * {@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 Huang332793b2019-10-29 23:21:27 +080094 * hiding navigation bars by calling {@link #hide(int)} or
Jorim Jaggib7848b72018-12-28 14:38:21 +010095 * {@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 Huang332793b2019-10-29 23:21:27 +0800106 @IntDef(value = {BEHAVIOR_SHOW_BARS_BY_TOUCH, BEHAVIOR_SHOW_BARS_BY_SWIPE,
Jorim Jaggib7848b72018-12-28 14:38:21 +0100107 BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE})
108 @interface Behavior {
109 }
110
111 /**
Jorim Jaggib6030952018-10-23 18:31:52 +0200112 * 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 Jaggi2ae39132019-01-24 13:02:50 +0100116 * {@link View#onApplyWindowInsets} and checking visibility with {@link WindowInsets#isVisible}.
Jorim Jaggib6030952018-10-23 18:31:52 +0200117 *
Tiger Huang332793b2019-10-29 23:21:27 +0800118 * @param types A bitmask of {@link InsetsType} specifying what windows the app
Jorim Jaggib6030952018-10-23 18:31:52 +0200119 * would like to make appear on screen.
Jorim Jaggi2ae39132019-01-24 13:02:50 +0100120 * @hide
Jorim Jaggib6030952018-10-23 18:31:52 +0200121 */
Tiger Huang332793b2019-10-29 23:21:27 +0800122 void show(@InsetsType int types);
Jorim Jaggib6030952018-10-23 18:31:52 +0200123
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 Jaggi2ae39132019-01-24 13:02:50 +0100129 * {@link View#onApplyWindowInsets} and checking visibility with {@link WindowInsets#isVisible}.
Jorim Jaggib6030952018-10-23 18:31:52 +0200130 *
Tiger Huang332793b2019-10-29 23:21:27 +0800131 * @param types A bitmask of {@link InsetsType} specifying what windows the app
Jorim Jaggib6030952018-10-23 18:31:52 +0200132 * would like to make disappear.
Jorim Jaggi2ae39132019-01-24 13:02:50 +0100133 * @hide
Jorim Jaggib6030952018-10-23 18:31:52 +0200134 */
Tiger Huang332793b2019-10-29 23:21:27 +0800135 void hide(@InsetsType int types);
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100136
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 Huang332793b2019-10-29 23:21:27 +0800141 * @param types The {@link InsetsType}s the application has requested to control.
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100142 * @param listener The {@link WindowInsetsAnimationControlListener} that gets called when the
143 * windows are ready to be controlled, among other callbacks.
Jorim Jaggi2ae39132019-01-24 13:02:50 +0100144 * @hide
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100145 */
Tiger Huang332793b2019-10-29 23:21:27 +0800146 void controlWindowInsetsAnimation(@InsetsType int types,
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100147 @NonNull WindowInsetsAnimationControlListener listener);
Jorim Jaggi2ae39132019-01-24 13:02:50 +0100148
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 Jaggib7848b72018-12-28 14:38:21 +0100190
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 Jaggib6030952018-10-23 18:31:52 +0200206}