blob: b415319885189106855dfeca196e7e3ea56f860b [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;
Jorim Jaggib6030952018-10-23 18:31:52 +020024import android.view.WindowInsets.Type.InsetType;
25
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 /**
Jorim Jaggi956ca412019-01-07 14:49:14 +010038 * Makes the top bars become opaque with solid dark background and light foreground.
Jorim Jaggib7848b72018-12-28 14:38:21 +010039 * @hide
40 */
Jorim Jaggi956ca412019-01-07 14:49:14 +010041 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 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 /**
56 * Changes the foreground color for the light top bar so that the items on the bar can be read
57 * clearly.
58 */
Jorim Jaggi956ca412019-01-07 14:49:14 +010059 int APPEARANCE_LIGHT_TOP_BAR = 1 << 3;
Jorim Jaggib7848b72018-12-28 14:38:21 +010060
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 Jaggi956ca412019-01-07 14:49:14 +010065 int APPEARANCE_LIGHT_SIDE_BARS = 1 << 4;
Jorim Jaggib7848b72018-12-28 14:38:21 +010066
67 /** Determines the appearance of system bars. */
68 @Retention(RetentionPolicy.SOURCE)
Jorim Jaggi956ca412019-01-07 14:49:14 +010069 @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 Jaggib7848b72018-12-28 14:38:21 +010071 @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 Jaggib6030952018-10-23 18:31:52 +0200111 * 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 Jaggi2ae39132019-01-24 13:02:50 +0100115 * {@link View#onApplyWindowInsets} and checking visibility with {@link WindowInsets#isVisible}.
Jorim Jaggib6030952018-10-23 18:31:52 +0200116 *
117 * @param types A bitmask of {@link WindowInsets.Type.InsetType} specifying what windows the app
118 * would like to make appear on screen.
Jorim Jaggi2ae39132019-01-24 13:02:50 +0100119 * @hide
Jorim Jaggib6030952018-10-23 18:31:52 +0200120 */
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 Jaggi2ae39132019-01-24 13:02:50 +0100128 * {@link View#onApplyWindowInsets} and checking visibility with {@link WindowInsets#isVisible}.
Jorim Jaggib6030952018-10-23 18:31:52 +0200129 *
130 * @param types A bitmask of {@link WindowInsets.Type.InsetType} specifying what windows the app
131 * would like to make disappear.
Jorim Jaggi2ae39132019-01-24 13:02:50 +0100132 * @hide
Jorim Jaggib6030952018-10-23 18:31:52 +0200133 */
134 void hide(@InsetType int types);
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100135
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 Jaggi2ae39132019-01-24 13:02:50 +0100143 * @hide
Jorim Jaggi5bb571d2018-11-06 14:42:04 +0100144 */
145 void controlWindowInsetsAnimation(@InsetType int types,
146 @NonNull WindowInsetsAnimationControlListener listener);
Jorim Jaggi2ae39132019-01-24 13:02:50 +0100147
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 Jaggib7848b72018-12-28 14:38:21 +0100189
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 Jaggib6030952018-10-23 18:31:52 +0200205}