Debian Codegraph @

core/java/android/view/Window.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2006 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.Manifest.permission.HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
20 import static android.Manifest.permission.HIDE_OVERLAY_WINDOWS;
21 import static android.content.pm.PackageManager.PERMISSION_GRANTED;
22 import static android.view.WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
23 import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
24
25 import android.annotation.ColorInt;
26 import android.annotation.DrawableRes;
27 import android.annotation.IdRes;
28 import android.annotation.LayoutRes;
29 import android.annotation.NonNull;
30 import android.annotation.Nullable;
31 import android.annotation.RequiresPermission;
32 import android.annotation.StyleRes;
33 import android.annotation.SystemApi;
34 import android.annotation.TestApi;
35 import android.annotation.UiContext;
36 import android.app.WindowConfiguration;
37 import android.compat.annotation.UnsupportedAppUsage;
38 import android.content.Context;
39 import android.content.pm.ActivityInfo;
40 import android.content.res.Configuration;
41 import android.content.res.Resources;
42 import android.content.res.TypedArray;
43 import android.graphics.Insets;
44 import android.graphics.PixelFormat;
45 import android.graphics.Rect;
46 import android.graphics.drawable.Drawable;
47 import android.media.session.MediaController;
48 import android.net.Uri;
49 import android.os.Build;
50 import android.os.Bundle;
51 import android.os.Handler;
52 import android.os.IBinder;
53 import android.transition.Scene;
54 import android.transition.Transition;
55 import android.transition.TransitionManager;
56 import android.util.Pair;
57 import android.view.View.OnApplyWindowInsetsListener;
58 import android.view.accessibility.AccessibilityEvent;
59 import android.window.OnBackInvokedDispatcher;
60
61 import java.util.Collections;
62 import java.util.List;
63
64 /**
65 * Abstract base class for a top-level window look and behavior policy. An
66 * instance of this class should be used as the top-level view added to the
67 * window manager. It provides standard UI policies such as a background, title
68 * area, default key processing, etc.
69 *
70 * <p>The framework will instantiate an implementation of this class on behalf of the application.
71 */
72 public abstract class Window {
73 /** Flag for the "options panel" feature. This is enabled by default. */
74 public static final int FEATURE_OPTIONS_PANEL = 0;
75 /** Flag for the "no title" feature, turning off the title at the top
76 * of the screen. */
77 public static final int FEATURE_NO_TITLE = 1;
78
79 /**
80 * Flag for the progress indicator feature.
81 *
82 * @deprecated No longer supported starting in API 21.
83 */
84 @Deprecated
85 public static final int FEATURE_PROGRESS = 2;
86
87 /** Flag for having an icon on the left side of the title bar */
88 public static final int FEATURE_LEFT_ICON = 3;
89 /** Flag for having an icon on the right side of the title bar */
90 public static final int FEATURE_RIGHT_ICON = 4;
91
92 /**
93 * Flag for indeterminate progress.
94 *
95 * @deprecated No longer supported starting in API 21.
96 */
97 @Deprecated
98 public static final int FEATURE_INDETERMINATE_PROGRESS = 5;
99
100 /** Flag for the context menu. This is enabled by default. */
101 public static final int FEATURE_CONTEXT_MENU = 6;
102 /** Flag for custom title. You cannot combine this feature with other title features. */
103 public static final int FEATURE_CUSTOM_TITLE = 7;
104 /**
105 * Flag for enabling the Action Bar.
106 * This is enabled by default for some devices. The Action Bar
107 * replaces the title bar and provides an alternate location
108 * for an on-screen menu button on some devices.
109 */
110 public static final int FEATURE_ACTION_BAR = 8;
111 /**
112 * Flag for requesting an Action Bar that overlays window content.
113 * Normally an Action Bar will sit in the space above window content, but if this
114 * feature is requested along with {@link #FEATURE_ACTION_BAR} it will be layered over
115 * the window content itself. This is useful if you would like your app to have more control
116 * over how the Action Bar is displayed, such as letting application content scroll beneath
117 * an Action Bar with a transparent background or otherwise displaying a transparent/translucent
118 * Action Bar over application content.
119 *
120 * <p>This mode is especially useful with {@link View#SYSTEM_UI_FLAG_FULLSCREEN
121 * View.SYSTEM_UI_FLAG_FULLSCREEN}, which allows you to seamlessly hide the
122 * action bar in conjunction with other screen decorations.
123 *
124 * <p>As of {@link android.os.Build.VERSION_CODES#JELLY_BEAN}, when an
125 * ActionBar is in this mode it will adjust the insets provided to
126 * {@link View#fitSystemWindows(android.graphics.Rect) View.fitSystemWindows(Rect)}
127 * to include the content covered by the action bar, so you can do layout within
128 * that space.
129 */
130 public static final int FEATURE_ACTION_BAR_OVERLAY = 9;
131 /**
132 * Flag for specifying the behavior of action modes when an Action Bar is not present.
133 * If overlay is enabled, the action mode UI will be allowed to cover existing window content.
134 */
135 public static final int FEATURE_ACTION_MODE_OVERLAY = 10;
136 /**
137 * Flag for requesting a decoration-free window that is dismissed by swiping from the left.
138 *
139 * @deprecated Swipe-to-dismiss isn't functional anymore.
140 */
141 @Deprecated
142 public static final int FEATURE_SWIPE_TO_DISMISS = 11;
143 /**
144 * Flag for requesting that window content changes should be animated using a
145 * TransitionManager.
146 *
147 * <p>The TransitionManager is set using
148 * {@link #setTransitionManager(android.transition.TransitionManager)}. If none is set,
149 * a default TransitionManager will be used.</p>
150 *
151 * @see #setContentView
152 */
153 public static final int FEATURE_CONTENT_TRANSITIONS = 12;
154
155 /**
156 * Enables Activities to run Activity Transitions either through sending or receiving
157 * ActivityOptions bundle created with
158 * {@link android.app.ActivityOptions#makeSceneTransitionAnimation(android.app.Activity,
159 * android.util.Pair[])} or {@link android.app.ActivityOptions#makeSceneTransitionAnimation(
160 * android.app.Activity, View, String)}.
161 */
162 public static final int FEATURE_ACTIVITY_TRANSITIONS = 13;
163
164 /**
165 * Max value used as a feature ID
166 * @hide
167 */
168 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
169 public static final int FEATURE_MAX = FEATURE_ACTIVITY_TRANSITIONS;
170
171 /**
172 * Flag for setting the progress bar's visibility to VISIBLE.
173 *
174 * @deprecated {@link #FEATURE_PROGRESS} and related methods are no longer
175 * supported starting in API 21.
176 */
177 @Deprecated
178 public static final int PROGRESS_VISIBILITY_ON = -1;
179
180 /**
181 * Flag for setting the progress bar's visibility to GONE.
182 *
183 * @deprecated {@link #FEATURE_PROGRESS} and related methods are no longer
184 * supported starting in API 21.
185 */
186 @Deprecated
187 public static final int PROGRESS_VISIBILITY_OFF = -2;
188
189 /**
190 * Flag for setting the progress bar's indeterminate mode on.
191 *
192 * @deprecated {@link #FEATURE_INDETERMINATE_PROGRESS} and related methods
193 * are no longer supported starting in API 21.
194 */
195 @Deprecated
196 public static final int PROGRESS_INDETERMINATE_ON = -3;
197
198 /**
199 * Flag for setting the progress bar's indeterminate mode off.
200 *
201 * @deprecated {@link #FEATURE_INDETERMINATE_PROGRESS} and related methods
202 * are no longer supported starting in API 21.
203 */
204 @Deprecated
205 public static final int PROGRESS_INDETERMINATE_OFF = -4;
206
207 /**
208 * Starting value for the (primary) progress.
209 *
210 * @deprecated {@link #FEATURE_PROGRESS} and related methods are no longer
211 * supported starting in API 21.
212 */
213 @Deprecated
214 public static final int PROGRESS_START = 0;
215
216 /**
217 * Ending value for the (primary) progress.
218 *
219 * @deprecated {@link #FEATURE_PROGRESS} and related methods are no longer
220 * supported starting in API 21.
221 */
222 @Deprecated
223 public static final int PROGRESS_END = 10000;
224
225 /**
226 * Lowest possible value for the secondary progress.
227 *
228 * @deprecated {@link #FEATURE_PROGRESS} and related methods are no longer
229 * supported starting in API 21.
230 */
231 @Deprecated
232 public static final int PROGRESS_SECONDARY_START = 20000;
233
234 /**
235 * Highest possible value for the secondary progress.
236 *
237 * @deprecated {@link #FEATURE_PROGRESS} and related methods are no longer
238 * supported starting in API 21.
239 */
240 @Deprecated
241 public static final int PROGRESS_SECONDARY_END = 30000;
242
243 /**
244 * The transitionName for the status bar background View when a custom background is used.
245 * @see android.view.Window#setStatusBarColor(int)
246 */
247 public static final String STATUS_BAR_BACKGROUND_TRANSITION_NAME = "android:status:background";
248
249 /**
250 * The transitionName for the navigation bar background View when a custom background is used.
251 * @see android.view.Window#setNavigationBarColor(int)
252 */
253 public static final String NAVIGATION_BAR_BACKGROUND_TRANSITION_NAME =
254 "android:navigation:background";
255
256 /**
257 * The default features enabled.
258 * @deprecated use {@link #getDefaultFeatures(android.content.Context)} instead.
259 */
260 @Deprecated
261 @SuppressWarnings({"PointlessBitwiseExpression"})
262 protected static final int DEFAULT_FEATURES = (1 << FEATURE_OPTIONS_PANEL) |
263 (1 << FEATURE_CONTEXT_MENU);
264
265 /**
266 * The ID that the main layout in the XML layout file should have.
267 */
268 public static final int ID_ANDROID_CONTENT = com.android.internal.R.id.content;
269
270 /**
271 * Flag for letting the theme drive the color of the window caption controls. Use with
272 * {@link #setDecorCaptionShade(int)}. This is the default value.
273 */
274 public static final int DECOR_CAPTION_SHADE_AUTO = 0;
275 /**
276 * Flag for setting light-color controls on the window caption. Use with
277 * {@link #setDecorCaptionShade(int)}.
278 */
279 public static final int DECOR_CAPTION_SHADE_LIGHT = 1;
280 /**
281 * Flag for setting dark-color controls on the window caption. Use with
282 * {@link #setDecorCaptionShade(int)}.
283 */
284 public static final int DECOR_CAPTION_SHADE_DARK = 2;
285
286 @UnsupportedAppUsage
287 @UiContext
288 private final Context mContext;
289
290 @UnsupportedAppUsage
291 private TypedArray mWindowStyle;
292 @UnsupportedAppUsage
293 private Callback mCallback;
294 private OnWindowDismissedCallback mOnWindowDismissedCallback;
295 private OnWindowSwipeDismissedCallback mOnWindowSwipeDismissedCallback;
296 private WindowControllerCallback mWindowControllerCallback;
297 @WindowInsetsController.Appearance
298 private int mSystemBarAppearance;
299 private DecorCallback mDecorCallback;
300 private OnRestrictedCaptionAreaChangedListener mOnRestrictedCaptionAreaChangedListener;
301 private Rect mRestrictedCaptionAreaRect;
302 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
303 private WindowManager mWindowManager;
304 @UnsupportedAppUsage
305 private IBinder mAppToken;
306 @UnsupportedAppUsage
307 private String mAppName;
308 @UnsupportedAppUsage
309 private boolean mHardwareAccelerated;
310 private Window mContainer;
311 private Window mActiveChild;
312 private boolean mIsActive = false;
313 private boolean mHasChildren = false;
314 private boolean mCloseOnTouchOutside = false;
315 private boolean mSetCloseOnTouchOutside = false;
316 private int mForcedWindowFlags = 0;
317
318 @UnsupportedAppUsage
319 private int mFeatures;
320 @UnsupportedAppUsage
321 private int mLocalFeatures;
322
323 private boolean mHaveWindowFormat = false;
324 private boolean mHaveDimAmount = false;
325 private int mDefaultWindowFormat = PixelFormat.OPAQUE;
326
327 private boolean mHasSoftInputMode = false;
328
329 @UnsupportedAppUsage
330 private boolean mDestroyed;
331
332 private boolean mOverlayWithDecorCaptionEnabled = true;
333 private boolean mCloseOnSwipeEnabled = false;
334
335 // The current window attributes.
336 @UnsupportedAppUsage
337 private final WindowManager.LayoutParams mWindowAttributes =
338 new WindowManager.LayoutParams();
339
340 /**
341 * API from a Window back to its caller. This allows the client to
342 * intercept key dispatching, panels and menus, etc.
343 */
344 public interface Callback {
345 /**
346 * Called to process key events. At the very least your
347 * implementation must call
348 * {@link android.view.Window#superDispatchKeyEvent} to do the
349 * standard key processing.
350 *
351 * @param event The key event.
352 *
353 * @return boolean Return true if this event was consumed.
354 */
355 public boolean dispatchKeyEvent(KeyEvent event);
356
357 /**
358 * Called to process a key shortcut event.
359 * At the very least your implementation must call
360 * {@link android.view.Window#superDispatchKeyShortcutEvent} to do the
361 * standard key shortcut processing.
362 *
363 * @param event The key shortcut event.
364 * @return True if this event was consumed.
365 */
366 public boolean dispatchKeyShortcutEvent(KeyEvent event);
367
368 /**
369 * Called to process touch screen events. At the very least your
370 * implementation must call
371 * {@link android.view.Window#superDispatchTouchEvent} to do the
372 * standard touch screen processing.
373 *
374 * @param event The touch screen event.
375 *
376 * @return boolean Return true if this event was consumed.
377 */
378 public boolean dispatchTouchEvent(MotionEvent event);
379
380 /**
381 * Called to process trackball events. At the very least your
382 * implementation must call
383 * {@link android.view.Window#superDispatchTrackballEvent} to do the
384 * standard trackball processing.
385 *
386 * @param event The trackball event.
387 *
388 * @return boolean Return true if this event was consumed.
389 */
390 public boolean dispatchTrackballEvent(MotionEvent event);
391
392 /**
393 * Called to process generic motion events. At the very least your
394 * implementation must call
395 * {@link android.view.Window#superDispatchGenericMotionEvent} to do the
396 * standard processing.
397 *
398 * @param event The generic motion event.
399 *
400 * @return boolean Return true if this event was consumed.
401 */
402 public boolean dispatchGenericMotionEvent(MotionEvent event);
403
404 /**
405 * Called to process population of {@link AccessibilityEvent}s.
406 *
407 * @param event The event.
408 *
409 * @return boolean Return true if event population was completed.
410 */
411 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event);
412
413 /**
414 * Instantiate the view to display in the panel for 'featureId'.
415 * You can return null, in which case the default content (typically
416 * a menu) will be created for you.
417 *
418 * @param featureId Which panel is being created.
419 *
420 * @return view The top-level view to place in the panel.
421 *
422 * @see #onPreparePanel
423 */
424 @Nullable
425 public View onCreatePanelView(int featureId);
426
427 /**
428 * Initialize the contents of the menu for panel 'featureId'. This is
429 * called if onCreatePanelView() returns null, giving you a standard
430 * menu in which you can place your items. It is only called once for
431 * the panel, the first time it is shown.
432 *
433 * <p>You can safely hold on to <var>menu</var> (and any items created
434 * from it), making modifications to it as desired, until the next
435 * time onCreatePanelMenu() is called for this feature.
436 *
437 * @param featureId The panel being created.
438 * @param menu The menu inside the panel.
439 *
440 * @return boolean You must return true for the panel to be displayed;
441 * if you return false it will not be shown.
442 */
443 boolean onCreatePanelMenu(int featureId, @NonNull Menu menu);
444
445 /**
446 * Prepare a panel to be displayed. This is called right before the
447 * panel window is shown, every time it is shown.
448 *
449 * @param featureId The panel that is being displayed.
450 * @param view The View that was returned by onCreatePanelView().
451 * @param menu If onCreatePanelView() returned null, this is the Menu
452 * being displayed in the panel.
453 *
454 * @return boolean You must return true for the panel to be displayed;
455 * if you return false it will not be shown.
456 *
457 * @see #onCreatePanelView
458 */
459 boolean onPreparePanel(int featureId, @Nullable View view, @NonNull Menu menu);
460
461 /**
462 * Called when a panel's menu is opened by the user. This may also be
463 * called when the menu is changing from one type to another (for
464 * example, from the icon menu to the expanded menu).
465 *
466 * @param featureId The panel that the menu is in.
467 * @param menu The menu that is opened.
468 * @return Return true to allow the menu to open, or false to prevent
469 * the menu from opening.
470 */
471 boolean onMenuOpened(int featureId, @NonNull Menu menu);
472
473 /**
474 * Called when a panel's menu item has been selected by the user.
475 *
476 * @param featureId The panel that the menu is in.
477 * @param item The menu item that was selected.
478 *
479 * @return boolean Return true to finish processing of selection, or
480 * false to perform the normal menu handling (calling its
481 * Runnable or sending a Message to its target Handler).
482 */
483 boolean onMenuItemSelected(int featureId, @NonNull MenuItem item);
484
485 /**
486 * This is called whenever the current window attributes change.
487 *
488 */
489 public void onWindowAttributesChanged(WindowManager.LayoutParams attrs);
490
491 /**
492 * This hook is called whenever the content view of the screen changes
493 * (due to a call to
494 * {@link Window#setContentView(View, android.view.ViewGroup.LayoutParams)
495 * Window.setContentView} or
496 * {@link Window#addContentView(View, android.view.ViewGroup.LayoutParams)
497 * Window.addContentView}).
498 */
499 public void onContentChanged();
500
501 /**
502 * This hook is called whenever the window focus changes. See
503 * {@link View#onWindowFocusChanged(boolean)
504 * View.onWindowFocusChangedNotLocked(boolean)} for more information.
505 *
506 * @param hasFocus Whether the window now has focus.
507 */
508 public void onWindowFocusChanged(boolean hasFocus);
509
510 /**
511 * Called when the window has been attached to the window manager.
512 * See {@link View#onAttachedToWindow() View.onAttachedToWindow()}
513 * for more information.
514 */
515 public void onAttachedToWindow();
516
517 /**
518 * Called when the window has been detached from the window manager.
519 * See {@link View#onDetachedFromWindow() View.onDetachedFromWindow()}
520 * for more information.
521 */
522 public void onDetachedFromWindow();
523
524 /**
525 * Called when a panel is being closed. If another logical subsequent
526 * panel is being opened (and this panel is being closed to make room for the subsequent
527 * panel), this method will NOT be called.
528 *
529 * @param featureId The panel that is being displayed.
530 * @param menu If onCreatePanelView() returned null, this is the Menu
531 * being displayed in the panel.
532 */
533 void onPanelClosed(int featureId, @NonNull Menu menu);
534
535 /**
536 * Called when the user signals the desire to start a search.
537 *
538 * @return true if search launched, false if activity refuses (blocks)
539 *
540 * @see android.app.Activity#onSearchRequested()
541 */
542 public boolean onSearchRequested();
543
544 /**
545 * Called when the user signals the desire to start a search.
546 *
547 * @param searchEvent A {@link SearchEvent} describing the signal to
548 * start a search.
549 * @return true if search launched, false if activity refuses (blocks)
550 */
551 public boolean onSearchRequested(SearchEvent searchEvent);
552
553 /**
554 * Called when an action mode is being started for this window. Gives the
555 * callback an opportunity to handle the action mode in its own unique and
556 * beautiful way. If this method returns null the system can choose a way
557 * to present the mode or choose not to start the mode at all. This is equivalent
558 * to {@link #onWindowStartingActionMode(android.view.ActionMode.Callback, int)}
559 * with type {@link ActionMode#TYPE_PRIMARY}.
560 *
561 * @param callback Callback to control the lifecycle of this action mode
562 * @return The ActionMode that was started, or null if the system should present it
563 */
564 @Nullable
565 public ActionMode onWindowStartingActionMode(ActionMode.Callback callback);
566
567 /**
568 * Called when an action mode is being started for this window. Gives the
569 * callback an opportunity to handle the action mode in its own unique and
570 * beautiful way. If this method returns null the system can choose a way
571 * to present the mode or choose not to start the mode at all.
572 *
573 * @param callback Callback to control the lifecycle of this action mode
574 * @param type One of {@link ActionMode#TYPE_PRIMARY} or {@link ActionMode#TYPE_FLOATING}.
575 * @return The ActionMode that was started, or null if the system should present it
576 */
577 @Nullable
578 public ActionMode onWindowStartingActionMode(ActionMode.Callback callback, int type);
579
580 /**
581 * Called when an action mode has been started. The appropriate mode callback
582 * method will have already been invoked.
583 *
584 * @param mode The new mode that has just been started.
585 */
586 public void onActionModeStarted(ActionMode mode);
587
588 /**
589 * Called when an action mode has been finished. The appropriate mode callback
590 * method will have already been invoked.
591 *
592 * @param mode The mode that was just finished.
593 */
594 public void onActionModeFinished(ActionMode mode);
595
596 /**
597 * Called when Keyboard Shortcuts are requested for the current window.
598 *
599 * @param data The data list to populate with shortcuts.
600 * @param menu The current menu, which may be null.
601 * @param deviceId The id for the connected device the shortcuts should be provided for.
602 */
603 default public void onProvideKeyboardShortcuts(
604 List<KeyboardShortcutGroup> data, @Nullable Menu menu, int deviceId) { };
605
606 /**
607 * Called when pointer capture is enabled or disabled for the current window.
608 *
609 * @param hasCapture True if the window has pointer capture.
610 */
611 default public void onPointerCaptureChanged(boolean hasCapture) { };
612 }
613
614 /** @hide */
615 public interface OnWindowDismissedCallback {
616 /**
617 * Called when a window is dismissed. This informs the callback that the
618 * window is gone, and it should finish itself.
619 * @param finishTask True if the task should also be finished.
620 * @param suppressWindowTransition True if the resulting exit and enter window transition
621 * animations should be suppressed.
622 */
623 void onWindowDismissed(boolean finishTask, boolean suppressWindowTransition);
624 }
625
626 /** @hide */
627 public interface OnWindowSwipeDismissedCallback {
628 /**
629 * Called when a window is swipe dismissed. This informs the callback that the
630 * window is gone, and it should finish itself.
631 * @param finishTask True if the task should also be finished.
632 * @param suppressWindowTransition True if the resulting exit and enter window transition
633 * animations should be suppressed.
634 */
635 void onWindowSwipeDismissed();
636 }
637
638 /** @hide */
639 public interface WindowControllerCallback {
640 /**
641 * Moves the activity between {@link WindowConfiguration#WINDOWING_MODE_FREEFORM} windowing
642 * mode and {@link WindowConfiguration#WINDOWING_MODE_FULLSCREEN}.
643 */
644 void toggleFreeformWindowingMode();
645
646 /**
647 * Puts the activity in picture-in-picture mode if the activity supports.
648 * @see android.R.attr#supportsPictureInPicture
649 */
650 void enterPictureInPictureModeIfPossible();
651
652 /** Returns whether the window belongs to the task root. */
653 boolean isTaskRoot();
654
655 /**
656 * Update the status bar color to a forced one.
657 */
658 void updateStatusBarColor(int color);
659
660 /**
661 * Update the navigation bar color to a forced one.
662 */
663 void updateNavigationBarColor(int color);
664 }
665
666 /** @hide */
667 public interface DecorCallback {
668 /**
669 * Called from
670 * {@link com.android.internal.policy.DecorView#onSystemBarAppearanceChanged(int)}.
671 *
672 * @param appearance The newly applied appearance.
673 */
674 void onSystemBarAppearanceChanged(@WindowInsetsController.Appearance int appearance);
675
676 /**
677 * Called from
678 * {@link com.android.internal.policy.DecorView#updateColorViews(WindowInsets, boolean)}
679 * when {@link com.android.internal.policy.DecorView#mDrawLegacyNavigationBarBackground} is
680 * being updated.
681 *
682 * @param drawLegacyNavigationBarBackground the new value that is being set to
683 * {@link com.android.internal.policy.DecorView#mDrawLegacyNavigationBarBackground}.
684 * @return The value to be set to
685 * {@link com.android.internal.policy.DecorView#mDrawLegacyNavigationBarBackgroundHandled}
686 * on behalf of the {@link com.android.internal.policy.DecorView}.
687 * {@code true} to tell that the Window can render the legacy navigation bar
688 * background on behalf of the {@link com.android.internal.policy.DecorView}.
689 * {@code false} to let {@link com.android.internal.policy.DecorView} handle it.
690 */
691 boolean onDrawLegacyNavigationBarBackgroundChanged(
692 boolean drawLegacyNavigationBarBackground);
693 }
694
695 /**
696 * Callback for clients that want to be aware of where caption draws content.
697 */
698 public interface OnRestrictedCaptionAreaChangedListener {
699 /**
700 * Called when the area where caption draws content changes.
701 *
702 * @param rect The area where caption content is positioned, relative to the top view.
703 */
704 void onRestrictedCaptionAreaChanged(Rect rect);
705 }
706
707 /**
708 * Callback for clients that want frame timing information for each
709 * frame rendered by the Window.
710 */
711 public interface OnFrameMetricsAvailableListener {
712 /**
713 * Called when information is available for the previously rendered frame.
714 *
715 * Reports can be dropped if this callback takes too
716 * long to execute, as the report producer cannot wait for the consumer to
717 * complete.
718 *
719 * It is highly recommended that clients copy the passed in FrameMetrics
720 * via {@link FrameMetrics#FrameMetrics(FrameMetrics)} within this method and defer
721 * additional computation or storage to another thread to avoid unnecessarily
722 * dropping reports.
723 *
724 * @param window The {@link Window} on which the frame was displayed.
725 * @param frameMetrics the available metrics. This object is reused on every call
726 * and thus <strong>this reference is not valid outside the scope of this method</strong>.
727 * @param dropCountSinceLastInvocation the number of reports dropped since the last time
728 * this callback was invoked.
729 */
730 void onFrameMetricsAvailable(Window window, FrameMetrics frameMetrics,
731 int dropCountSinceLastInvocation);
732 }
733
734 /**
735 * Listener for applying window insets on the content of a window. Used only by the framework to
736 * fit content according to legacy SystemUI flags.
737 *
738 * @hide
739 */
740 public interface OnContentApplyWindowInsetsListener {
741
742 /**
743 * Called when the window needs to apply insets on the container of its content view which
744 * are set by calling {@link #setContentView}. The method should determine what insets to
745 * apply on the container of the root level content view and what should be dispatched to
746 * the content view's
747 * {@link View#setOnApplyWindowInsetsListener(OnApplyWindowInsetsListener)} through the view
748 * hierarchy.
749 *
750 * @param view The view for which to apply insets. Must not be directly modified.
751 * @param insets The root level insets that are about to be dispatched
752 * @return A pair, with the first element containing the insets to apply as margin to the
753 * root-level content views, and the second element determining what should be
754 * dispatched to the content view.
755 */
756 @NonNull
757 Pair<Insets, WindowInsets> onContentApplyWindowInsets(@NonNull View view,
758 @NonNull WindowInsets insets);
759 }
760
761
762 public Window(@UiContext Context context) {
763 mContext = context;
764 mFeatures = mLocalFeatures = getDefaultFeatures(context);
765 }
766
767 /**
768 * Return the Context this window policy is running in, for retrieving
769 * resources and other information.
770 *
771 * @return Context The Context that was supplied to the constructor.
772 */
773 @UiContext
774 public final Context getContext() {
775 return mContext;
776 }
777
778 /**
779 * Return the {@link android.R.styleable#Window} attributes from this
780 * window's theme.
781 */
782 public final TypedArray getWindowStyle() {
783 synchronized (this) {
784 if (mWindowStyle == null) {
785 mWindowStyle = mContext.obtainStyledAttributes(
786 com.android.internal.R.styleable.Window);
787 }
788 return mWindowStyle;
789 }
790 }
791
792 /**
793 * Set the container for this window. If not set, the DecorWindow
794 * operates as a top-level window; otherwise, it negotiates with the
795 * container to display itself appropriately.
796 *
797 * @param container The desired containing Window.
798 */
799 public void setContainer(Window container) {
800 mContainer = container;
801 if (container != null) {
802 // Embedded screens never have a title.
803 mFeatures |= 1<<FEATURE_NO_TITLE;
804 mLocalFeatures |= 1<<FEATURE_NO_TITLE;
805 container.mHasChildren = true;
806 }
807 }
808
809 /**
810 * Return the container for this Window.
811 *
812 * @return Window The containing window, or null if this is a
813 * top-level window.
814 */
815 public final Window getContainer() {
816 return mContainer;
817 }
818
819 public final boolean hasChildren() {
820 return mHasChildren;
821 }
822
823 /** @hide */
824 public final void destroy() {
825 mDestroyed = true;
826 }
827
828 /** @hide */
829 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
830 public final boolean isDestroyed() {
831 return mDestroyed;
832 }
833
834 /**
835 * Set the window manager for use by this Window to, for example,
836 * display panels. This is <em>not</em> used for displaying the
837 * Window itself -- that must be done by the client.
838 *
839 * @param wm The window manager for adding new windows.
840 */
841 public void setWindowManager(WindowManager wm, IBinder appToken, String appName) {
842 setWindowManager(wm, appToken, appName, false);
843 }
844
845 /**
846 * Set the window manager for use by this Window to, for example,
847 * display panels. This is <em>not</em> used for displaying the
848 * Window itself -- that must be done by the client.
849 *
850 * @param wm The window manager for adding new windows.
851 */
852 public void setWindowManager(WindowManager wm, IBinder appToken, String appName,
853 boolean hardwareAccelerated) {
854 mAppToken = appToken;
855 mAppName = appName;
856 mHardwareAccelerated = hardwareAccelerated;
857 if (wm == null) {
858 wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
859 }
860 mWindowManager = ((WindowManagerImpl)wm).createLocalWindowManager(this);
861 }
862
863 void adjustLayoutParamsForSubWindow(WindowManager.LayoutParams wp) {
864 CharSequence curTitle = wp.getTitle();
865 if (wp.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW &&
866 wp.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
867 if (wp.token == null) {
868 View decor = peekDecorView();
869 if (decor != null) {
870 wp.token = decor.getWindowToken();
871 }
872 }
873 if (curTitle == null || curTitle.length() == 0) {
874 final StringBuilder title = new StringBuilder(32);
875 if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA) {
876 title.append("Media");
877 } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY) {
878 title.append("MediaOvr");
879 } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
880 title.append("Panel");
881 } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL) {
882 title.append("SubPanel");
883 } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_ABOVE_SUB_PANEL) {
884 title.append("AboveSubPanel");
885 } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG) {
886 title.append("AtchDlg");
887 } else {
888 title.append(wp.type);
889 }
890 if (mAppName != null) {
891 title.append(":").append(mAppName);
892 }
893 wp.setTitle(title);
894 }
895 } else if (wp.type >= WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW &&
896 wp.type <= WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) {
897 // We don't set the app token to this system window because the life cycles should be
898 // independent. If an app creates a system window and then the app goes to the stopped
899 // state, the system window should not be affected (can still show and receive input
900 // events).
901 if (curTitle == null || curTitle.length() == 0) {
902 final StringBuilder title = new StringBuilder(32);
903 title.append("Sys").append(wp.type);
904 if (mAppName != null) {
905 title.append(":").append(mAppName);
906 }
907 wp.setTitle(title);
908 }
909 } else {
910 if (wp.token == null) {
911 wp.token = mContainer == null ? mAppToken : mContainer.mAppToken;
912 }
913 if ((curTitle == null || curTitle.length() == 0)
914 && mAppName != null) {
915 wp.setTitle(mAppName);
916 }
917 }
918 if (wp.packageName == null) {
919 wp.packageName = mContext.getPackageName();
920 }
921 if (mHardwareAccelerated ||
922 (mWindowAttributes.flags & FLAG_HARDWARE_ACCELERATED) != 0) {
923 wp.flags |= FLAG_HARDWARE_ACCELERATED;
924 }
925 }
926
927 /**
928 * Return the window manager allowing this Window to display its own
929 * windows.
930 *
931 * @return WindowManager The ViewManager.
932 */
933 public WindowManager getWindowManager() {
934 return mWindowManager;
935 }
936
937 /**
938 * Set the Callback interface for this window, used to intercept key
939 * events and other dynamic operations in the window.
940 *
941 * @param callback The desired Callback interface.
942 */
943 public void setCallback(Callback callback) {
944 mCallback = callback;
945 }
946
947 /**
948 * Return the current Callback interface for this window.
949 */
950 public final Callback getCallback() {
951 return mCallback;
952 }
953
954 /**
955 * Set an observer to collect frame stats for each frame rendered in this window.
956 *
957 * Must be in hardware rendering mode.
958 */
959 public final void addOnFrameMetricsAvailableListener(
960 @NonNull OnFrameMetricsAvailableListener listener,
961 Handler handler) {
962 final View decorView = getDecorView();
963 if (decorView == null) {
964 throw new IllegalStateException("can't observe a Window without an attached view");
965 }
966
967 if (listener == null) {
968 throw new NullPointerException("listener cannot be null");
969 }
970
971 decorView.addFrameMetricsListener(this, listener, handler);
972 }
973
974 /**
975 * Remove observer and stop listening to frame stats for this window.
976 */
977 public final void removeOnFrameMetricsAvailableListener(OnFrameMetricsAvailableListener listener) {
978 final View decorView = getDecorView();
979 if (decorView != null) {
980 getDecorView().removeFrameMetricsListener(listener);
981 }
982 }
983
984 /** @hide */
985 public final void setOnWindowDismissedCallback(OnWindowDismissedCallback dcb) {
986 mOnWindowDismissedCallback = dcb;
987 }
988
989 /** @hide */
990 public final void dispatchOnWindowDismissed(
991 boolean finishTask, boolean suppressWindowTransition) {
992 if (mOnWindowDismissedCallback != null) {
993 mOnWindowDismissedCallback.onWindowDismissed(finishTask, suppressWindowTransition);
994 }
995 }
996
997 /** @hide */
998 public final void setOnWindowSwipeDismissedCallback(OnWindowSwipeDismissedCallback sdcb) {
999 mOnWindowSwipeDismissedCallback = sdcb;
1000 }
1001
1002 /** @hide */
1003 public final void dispatchOnWindowSwipeDismissed() {
1004 if (mOnWindowSwipeDismissedCallback != null) {
1005 mOnWindowSwipeDismissedCallback.onWindowSwipeDismissed();
1006 }
1007 }
1008
1009 /** @hide */
1010 public final void setWindowControllerCallback(WindowControllerCallback wccb) {
1011 mWindowControllerCallback = wccb;
1012 }
1013
1014 /** @hide */
1015 public final WindowControllerCallback getWindowControllerCallback() {
1016 return mWindowControllerCallback;
1017 }
1018
1019 /** @hide */
1020 public final void setDecorCallback(DecorCallback decorCallback) {
1021 mDecorCallback = decorCallback;
1022 }
1023
1024 /** @hide */
1025 @WindowInsetsController.Appearance
1026 public final int getSystemBarAppearance() {
1027 return mSystemBarAppearance;
1028 }
1029
1030 /** @hide */
1031 public final void dispatchOnSystemBarAppearanceChanged(
1032 @WindowInsetsController.Appearance int appearance) {
1033 mSystemBarAppearance = appearance;
1034 if (mDecorCallback != null) {
1035 mDecorCallback.onSystemBarAppearanceChanged(appearance);
1036 }
1037 }
1038
1039 /** @hide */
1040 public final boolean onDrawLegacyNavigationBarBackgroundChanged(
1041 boolean drawLegacyNavigationBarBackground) {
1042 if (mDecorCallback == null) {
1043 return false;
1044 }
1045 return mDecorCallback.onDrawLegacyNavigationBarBackgroundChanged(
1046 drawLegacyNavigationBarBackground);
1047 }
1048
1049 /**
1050 * Set a callback for changes of area where caption will draw its content.
1051 *
1052 * @param listener Callback that will be called when the area changes.
1053 */
1054 public final void setRestrictedCaptionAreaListener(OnRestrictedCaptionAreaChangedListener listener) {
1055 mOnRestrictedCaptionAreaChangedListener = listener;
1056 mRestrictedCaptionAreaRect = listener != null ? new Rect() : null;
1057 }
1058
1059 /**
1060 * Prevent non-system overlay windows from being drawn on top of this window.
1061 *
1062 * @param hide whether non-system overlay windows should be hidden.
1063 */
1064 @RequiresPermission(HIDE_OVERLAY_WINDOWS)
1065 public final void setHideOverlayWindows(boolean hide) {
1066 // This permission check is here to throw early and let the developer know that they need
1067 // to hold HIDE_OVERLAY_WINDOWS for the flag to have any effect. The WM verifies that the
1068 // owner of the window has the permission before applying the flag, but this is done
1069 // asynchronously.
1070 if (mContext.checkSelfPermission(HIDE_NON_SYSTEM_OVERLAY_WINDOWS) != PERMISSION_GRANTED
1071 && mContext.checkSelfPermission(HIDE_OVERLAY_WINDOWS) != PERMISSION_GRANTED) {
1072 throw new SecurityException(
1073 "Permission denial: setHideOverlayWindows: HIDE_OVERLAY_WINDOWS");
1074 }
1075 setPrivateFlags(hide ? SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS : 0,
1076 SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
1077 }
1078
1079 /**
1080 * Take ownership of this window's surface. The window's view hierarchy
1081 * will no longer draw into the surface, though it will otherwise continue
1082 * to operate (such as for receiving input events). The given SurfaceHolder
1083 * callback will be used to tell you about state changes to the surface.
1084 */
1085 public abstract void takeSurface(SurfaceHolder.Callback2 callback);
1086
1087 /**
1088 * Take ownership of this window's InputQueue. The window will no
1089 * longer read and dispatch input events from the queue; it is your
1090 * responsibility to do so.
1091 */
1092 public abstract void takeInputQueue(InputQueue.Callback callback);
1093
1094 /**
1095 * Return whether this window is being displayed with a floating style
1096 * (based on the {@link android.R.attr#windowIsFloating} attribute in
1097 * the style/theme).
1098 *
1099 * @return Returns true if the window is configured to be displayed floating
1100 * on top of whatever is behind it.
1101 */
1102 public abstract boolean isFloating();
1103
1104 /**
1105 * Set the width and height layout parameters of the window. The default
1106 * for both of these is MATCH_PARENT; you can change them to WRAP_CONTENT
1107 * or an absolute value to make a window that is not full-screen.
1108 *
1109 * @param width The desired layout width of the window.
1110 * @param height The desired layout height of the window.
1111 *
1112 * @see ViewGroup.LayoutParams#height
1113 * @see ViewGroup.LayoutParams#width
1114 */
1115 public void setLayout(int width, int height) {
1116 final WindowManager.LayoutParams attrs = getAttributes();
1117 attrs.width = width;
1118 attrs.height = height;
1119 dispatchWindowAttributesChanged(attrs);
1120 }
1121
1122 /**
1123 * Set the gravity of the window, as per the Gravity constants. This
1124 * controls how the window manager is positioned in the overall window; it
1125 * is only useful when using WRAP_CONTENT for the layout width or height.
1126 *
1127 * @param gravity The desired gravity constant.
1128 *
1129 * @see Gravity
1130 * @see #setLayout
1131 */
1132 public void setGravity(int gravity)
1133 {
1134 final WindowManager.LayoutParams attrs = getAttributes();
1135 attrs.gravity = gravity;
1136 dispatchWindowAttributesChanged(attrs);
1137 }
1138
1139 /**
1140 * Set the type of the window, as per the WindowManager.LayoutParams
1141 * types.
1142 *
1143 * @param type The new window type (see WindowManager.LayoutParams).
1144 */
1145 public void setType(int type) {
1146 final WindowManager.LayoutParams attrs = getAttributes();
1147 attrs.type = type;
1148 dispatchWindowAttributesChanged(attrs);
1149 }
1150
1151 /**
1152 * Set the format of window, as per the PixelFormat types. This overrides
1153 * the default format that is selected by the Window based on its
1154 * window decorations.
1155 *
1156 * @param format The new window format (see PixelFormat). Use
1157 * PixelFormat.UNKNOWN to allow the Window to select
1158 * the format.
1159 *
1160 * @see PixelFormat
1161 */
1162 public void setFormat(int format) {
1163 final WindowManager.LayoutParams attrs = getAttributes();
1164 if (format != PixelFormat.UNKNOWN) {
1165 attrs.format = format;
1166 mHaveWindowFormat = true;
1167 } else {
1168 attrs.format = mDefaultWindowFormat;
1169 mHaveWindowFormat = false;
1170 }
1171 dispatchWindowAttributesChanged(attrs);
1172 }
1173
1174 /**
1175 * Specify custom animations to use for the window, as per
1176 * {@link WindowManager.LayoutParams#windowAnimations
1177 * WindowManager.LayoutParams.windowAnimations}. Providing anything besides
1178 * 0 here will override the animations the window would
1179 * normally retrieve from its theme.
1180 */
1181 public void setWindowAnimations(@StyleRes int resId) {
1182 final WindowManager.LayoutParams attrs = getAttributes();
1183 attrs.windowAnimations = resId;
1184 dispatchWindowAttributesChanged(attrs);
1185 }
1186
1187 /**
1188 * Specify an explicit soft input mode to use for the window, as per
1189 * {@link WindowManager.LayoutParams#softInputMode
1190 * WindowManager.LayoutParams.softInputMode}. Providing anything besides
1191 * "unspecified" here will override the input mode the window would
1192 * normally retrieve from its theme.
1193 */
1194 public void setSoftInputMode(int mode) {
1195 final WindowManager.LayoutParams attrs = getAttributes();
1196 if (mode != WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED) {
1197 attrs.softInputMode = mode;
1198 mHasSoftInputMode = true;
1199 } else {
1200 mHasSoftInputMode = false;
1201 }
1202 dispatchWindowAttributesChanged(attrs);
1203 }
1204
1205 /**
1206 * Convenience function to set the flag bits as specified in flags, as
1207 * per {@link #setFlags}.
1208 * @param flags The flag bits to be set.
1209 * @see #setFlags
1210 * @see #clearFlags
1211 */
1212 public void addFlags(int flags) {
1213 setFlags(flags, flags);
1214 }
1215
1216 /**
1217 * Add private flag bits.
1218 *
1219 * <p>Refer to the individual flags for the permissions needed.
1220 *
1221 * @param flags The flag bits to add.
1222 *
1223 * @hide
1224 */
1225 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
1226 public void addPrivateFlags(int flags) {
1227 setPrivateFlags(flags, flags);
1228 }
1229
1230 /**
1231 * Add system flag bits.
1232 *
1233 * <p>Refer to the individual flags for the permissions needed.
1234 *
1235 * <p>Note: Only for updateable system components (aka. mainline modules)
1236 *
1237 * @param flags The flag bits to add.
1238 *
1239 * @hide
1240 */
1241 @SystemApi
1242 public void addSystemFlags(@WindowManager.LayoutParams.SystemFlags int flags) {
1243 addPrivateFlags(flags);
1244 }
1245
1246 /**
1247 * Convenience function to clear the flag bits as specified in flags, as
1248 * per {@link #setFlags}.
1249 * @param flags The flag bits to be cleared.
1250 * @see #setFlags
1251 * @see #addFlags
1252 */
1253 public void clearFlags(int flags) {
1254 setFlags(0, flags);
1255 }
1256
1257 /**
1258 * Set the flags of the window, as per the
1259 * {@link WindowManager.LayoutParams WindowManager.LayoutParams}
1260 * flags.
1261 *
1262 * <p>Note that some flags must be set before the window decoration is
1263 * created (by the first call to
1264 * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)} or
1265 * {@link #getDecorView()}:
1266 * {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN} and
1267 * {@link WindowManager.LayoutParams#FLAG_LAYOUT_INSET_DECOR}. These
1268 * will be set for you based on the {@link android.R.attr#windowIsFloating}
1269 * attribute.
1270 *
1271 * @param flags The new window flags (see WindowManager.LayoutParams).
1272 * @param mask Which of the window flag bits to modify.
1273 * @see #addFlags
1274 * @see #clearFlags
1275 */
1276 public void setFlags(int flags, int mask) {
1277 final WindowManager.LayoutParams attrs = getAttributes();
1278 attrs.flags = (attrs.flags&~mask) | (flags&mask);
1279 mForcedWindowFlags |= mask;
1280 dispatchWindowAttributesChanged(attrs);
1281 }
1282
1283 private void setPrivateFlags(int flags, int mask) {
1284 final WindowManager.LayoutParams attrs = getAttributes();
1285 attrs.privateFlags = (attrs.privateFlags & ~mask) | (flags & mask);
1286 dispatchWindowAttributesChanged(attrs);
1287 }
1288
1289 /**
1290 * {@hide}
1291 */
1292 protected void dispatchWindowAttributesChanged(WindowManager.LayoutParams attrs) {
1293 if (mCallback != null) {
1294 mCallback.onWindowAttributesChanged(attrs);
1295 }
1296 }
1297
1298 /**
1299 * <p>Sets the requested color mode of the window. The requested the color mode might
1300 * override the window's pixel {@link WindowManager.LayoutParams#format format}.</p>
1301 *
1302 * <p>The requested color mode must be one of {@link ActivityInfo#COLOR_MODE_DEFAULT},
1303 * {@link ActivityInfo#COLOR_MODE_WIDE_COLOR_GAMUT} or {@link ActivityInfo#COLOR_MODE_HDR}.</p>
1304 *
1305 * <p>The requested color mode is not guaranteed to be honored. Please refer to
1306 * {@link #getColorMode()} for more information.</p>
1307 *
1308 * @see #getColorMode()
1309 * @see Display#isWideColorGamut()
1310 * @see Configuration#isScreenWideColorGamut()
1311 */
1312 public void setColorMode(@ActivityInfo.ColorMode int colorMode) {
1313 final WindowManager.LayoutParams attrs = getAttributes();
1314 attrs.setColorMode(colorMode);
1315 dispatchWindowAttributesChanged(attrs);
1316 }
1317
1318 /**
1319 * If {@code isPreferred} is true, this method requests that the connected display does minimal
1320 * post processing when this window is visible on the screen. Otherwise, it requests that the
1321 * display switches back to standard image processing.
1322 *
1323 * <p> By default, the display does not do minimal post processing and if this is desired, this
1324 * method should not be used. It should be used with {@code isPreferred=true} when low
1325 * latency has a higher priority than image enhancement processing (e.g. for games or video
1326 * conferencing). The display will automatically go back into standard image processing mode
1327 * when no window requesting minimal posst processing is visible on screen anymore.
1328 * {@code setPreferMinimalPostProcessing(false)} can be used if
1329 * {@code setPreferMinimalPostProcessing(true)} was previously called for this window and
1330 * minimal post processing is no longer required.
1331 *
1332 * <p>If the Display sink is connected via HDMI, the device will begin to send infoframes with
1333 * Auto Low Latency Mode enabled and Game Content Type. This will switch the connected display
1334 * to a minimal image processing mode (if available), which reduces latency, improving the user
1335 * experience for gaming or video conferencing applications. For more information, see HDMI 2.1
1336 * specification.
1337 *
1338 * <p>If the Display sink has an internal connection or uses some other protocol than HDMI,
1339 * effects may be similar but implementation-defined.
1340 *
1341 * <p>The ability to switch to a mode with minimal post proessing may be disabled by a user
1342 * setting in the system settings menu. In that case, this method does nothing.
1343 *
1344 * @see android.content.pm.ActivityInfo#FLAG_PREFER_MINIMAL_POST_PROCESSING
1345 * @see android.view.Display#isMinimalPostProcessingSupported
1346 * @see android.view.WindowManager.LayoutParams#preferMinimalPostProcessing
1347 *
1348 * @param isPreferred Indicates whether minimal post processing is preferred for this window
1349 * ({@code isPreferred=true}) or not ({@code isPreferred=false}).
1350 */
1351 public void setPreferMinimalPostProcessing(boolean isPreferred) {
1352 mWindowAttributes.preferMinimalPostProcessing = isPreferred;
1353 dispatchWindowAttributesChanged(mWindowAttributes);
1354 }
1355
1356 /**
1357 * Returns the requested color mode of the window, one of
1358 * {@link ActivityInfo#COLOR_MODE_DEFAULT}, {@link ActivityInfo#COLOR_MODE_WIDE_COLOR_GAMUT}
1359 * or {@link ActivityInfo#COLOR_MODE_HDR}. If {@link ActivityInfo#COLOR_MODE_WIDE_COLOR_GAMUT}
1360 * was requested it is possible the window will not be put in wide color gamut mode depending
1361 * on device and display support for that mode. Use {@link #isWideColorGamut} to determine
1362 * if the window is currently in wide color gamut mode.
1363 *
1364 * @see #setColorMode(int)
1365 * @see Display#isWideColorGamut()
1366 * @see Configuration#isScreenWideColorGamut()
1367 */
1368 @ActivityInfo.ColorMode
1369 public int getColorMode() {
1370 return getAttributes().getColorMode();
1371 }
1372
1373 /**
1374 * Returns true if this window's color mode is {@link ActivityInfo#COLOR_MODE_WIDE_COLOR_GAMUT},
1375 * the display has a wide color gamut and this device supports wide color gamut rendering.
1376 *
1377 * @see Display#isWideColorGamut()
1378 * @see Configuration#isScreenWideColorGamut()
1379 */
1380 public boolean isWideColorGamut() {
1381 return getColorMode() == ActivityInfo.COLOR_MODE_WIDE_COLOR_GAMUT
1382 && getContext().getResources().getConfiguration().isScreenWideColorGamut();
1383 }
1384
1385 /**
1386 * Set the amount of dim behind the window when using
1387 * {@link WindowManager.LayoutParams#FLAG_DIM_BEHIND}. This overrides
1388 * the default dim amount of that is selected by the Window based on
1389 * its theme.
1390 *
1391 * @param amount The new dim amount, from 0 for no dim to 1 for full dim.
1392 */
1393 public void setDimAmount(float amount) {
1394 final WindowManager.LayoutParams attrs = getAttributes();
1395 attrs.dimAmount = amount;
1396 mHaveDimAmount = true;
1397 dispatchWindowAttributesChanged(attrs);
1398 }
1399
1400 /**
1401 * Sets whether the decor view should fit root-level content views for {@link WindowInsets}.
1402 * <p>
1403 * If set to {@code true}, the framework will inspect the now deprecated
1404 * {@link View#SYSTEM_UI_LAYOUT_FLAGS} as well the
1405 * {@link WindowManager.LayoutParams#SOFT_INPUT_ADJUST_RESIZE} flag and fits content according
1406 * to these flags.
1407 * </p>
1408 * <p>
1409 * If set to {@code false}, the framework will not fit the content view to the insets and will
1410 * just pass through the {@link WindowInsets} to the content view.
1411 * </p>
1412 * @param decorFitsSystemWindows Whether the decor view should fit root-level content views for
1413 * insets.
1414 */
1415 public void setDecorFitsSystemWindows(boolean decorFitsSystemWindows) {
1416 }
1417
1418 /** @hide */
1419 public boolean decorFitsSystemWindows() {
1420 return false;
1421 }
1422
1423 /**
1424 * Specify custom window attributes. <strong>PLEASE NOTE:</strong> the
1425 * layout params you give here should generally be from values previously
1426 * retrieved with {@link #getAttributes()}; you probably do not want to
1427 * blindly create and apply your own, since this will blow away any values
1428 * set by the framework that you are not interested in.
1429 *
1430 * @param a The new window attributes, which will completely override any
1431 * current values.
1432 */
1433 public void setAttributes(WindowManager.LayoutParams a) {
1434 mWindowAttributes.copyFrom(a);
1435 dispatchWindowAttributesChanged(mWindowAttributes);
1436 }
1437
1438 /**
1439 * Retrieve the current window attributes associated with this panel.
1440 *
1441 * @return WindowManager.LayoutParams Either the existing window
1442 * attributes object, or a freshly created one if there is none.
1443 */
1444 public final WindowManager.LayoutParams getAttributes() {
1445 return mWindowAttributes;
1446 }
1447
1448 /**
1449 * Return the window flags that have been explicitly set by the client,
1450 * so will not be modified by {@link #getDecorView}.
1451 */
1452 protected final int getForcedWindowFlags() {
1453 return mForcedWindowFlags;
1454 }
1455
1456 /**
1457 * Has the app specified their own soft input mode?
1458 */
1459 protected final boolean hasSoftInputMode() {
1460 return mHasSoftInputMode;
1461 }
1462
1463 /** @hide */
1464 @UnsupportedAppUsage
1465 public void setCloseOnTouchOutside(boolean close) {
1466 mCloseOnTouchOutside = close;
1467 mSetCloseOnTouchOutside = true;
1468 }
1469
1470 /** @hide */
1471 @UnsupportedAppUsage
1472 public void setCloseOnTouchOutsideIfNotSet(boolean close) {
1473 if (!mSetCloseOnTouchOutside) {
1474 mCloseOnTouchOutside = close;
1475 mSetCloseOnTouchOutside = true;
1476 }
1477 }
1478
1479 /** @hide */
1480 @SuppressWarnings("HiddenAbstractMethod")
1481 @UnsupportedAppUsage
1482 public abstract void alwaysReadCloseOnTouchAttr();
1483
1484 /** @hide */
1485 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
1486 public boolean shouldCloseOnTouch(Context context, MotionEvent event) {
1487 final boolean isOutside =
1488 event.getAction() == MotionEvent.ACTION_UP && isOutOfBounds(context, event)
1489 || event.getAction() == MotionEvent.ACTION_OUTSIDE;
1490 if (mCloseOnTouchOutside && peekDecorView() != null && isOutside) {
1491 return true;
1492 }
1493 return false;
1494 }
1495
1496 /* Sets the Sustained Performance requirement for the calling window.
1497 * @param enable disables or enables the mode.
1498 */
1499 public void setSustainedPerformanceMode(boolean enable) {
1500 setPrivateFlags(enable
1501 ? WindowManager.LayoutParams.PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE : 0,
1502 WindowManager.LayoutParams.PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE);
1503 }
1504
1505 private boolean isOutOfBounds(Context context, MotionEvent event) {
1506 final int x = (int) event.getX();
1507 final int y = (int) event.getY();
1508 final int slop = ViewConfiguration.get(context).getScaledWindowTouchSlop();
1509 final View decorView = getDecorView();
1510 return (x < -slop) || (y < -slop)
1511 || (x > (decorView.getWidth()+slop))
1512 || (y > (decorView.getHeight()+slop));
1513 }
1514
1515 /**
1516 * Enable extended screen features. This must be called before
1517 * setContentView(). May be called as many times as desired as long as it
1518 * is before setContentView(). If not called, no extended features
1519 * will be available. You can not turn off a feature once it is requested.
1520 * You canot use other title features with {@link #FEATURE_CUSTOM_TITLE}.
1521 *
1522 * @param featureId The desired features, defined as constants by Window.
1523 * @return The features that are now set.
1524 */
1525 public boolean requestFeature(int featureId) {
1526 final int flag = 1<<featureId;
1527 mFeatures |= flag;
1528 mLocalFeatures |= mContainer != null ? (flag&~mContainer.mFeatures) : flag;
1529 return (mFeatures&flag) != 0;
1530 }
1531
1532 /**
1533 * @hide Used internally to help resolve conflicting features.
1534 */
1535 protected void removeFeature(int featureId) {
1536 final int flag = 1<<featureId;
1537 mFeatures &= ~flag;
1538 mLocalFeatures &= ~(mContainer != null ? (flag&~mContainer.mFeatures) : flag);
1539 }
1540
1541 public final void makeActive() {
1542 if (mContainer != null) {
1543 if (mContainer.mActiveChild != null) {
1544 mContainer.mActiveChild.mIsActive = false;
1545 }
1546 mContainer.mActiveChild = this;
1547 }
1548 mIsActive = true;
1549 onActive();
1550 }
1551
1552 public final boolean isActive()
1553 {
1554 return mIsActive;
1555 }
1556
1557 /**
1558 * Finds a view that was identified by the {@code android:id} XML attribute
1559 * that was processed in {@link android.app.Activity#onCreate}.
1560 * <p>
1561 * This will implicitly call {@link #getDecorView} with all of the associated side-effects.
1562 * <p>
1563 * <strong>Note:</strong> In most cases -- depending on compiler support --
1564 * the resulting view is automatically cast to the target class type. If
1565 * the target class type is unconstrained, an explicit cast may be
1566 * necessary.
1567 *
1568 * @param id the ID to search for
1569 * @return a view with given ID if found, or {@code null} otherwise
1570 * @see View#findViewById(int)
1571 * @see Window#requireViewById(int)
1572 */
1573 @Nullable
1574 public <T extends View> T findViewById(@IdRes int id) {
1575 return getDecorView().findViewById(id);
1576 }
1577 /**
1578 * Finds a view that was identified by the {@code android:id} XML attribute
1579 * that was processed in {@link android.app.Activity#onCreate}, or throws an
1580 * IllegalArgumentException if the ID is invalid, or there is no matching view in the hierarchy.
1581 * <p>
1582 * <strong>Note:</strong> In most cases -- depending on compiler support --
1583 * the resulting view is automatically cast to the target class type. If
1584 * the target class type is unconstrained, an explicit cast may be
1585 * necessary.
1586 *
1587 * @param id the ID to search for
1588 * @return a view with given ID
1589 * @see View#requireViewById(int)
1590 * @see Window#findViewById(int)
1591 */
1592 @NonNull
1593 public final <T extends View> T requireViewById(@IdRes int id) {
1594 T view = findViewById(id);
1595 if (view == null) {
1596 throw new IllegalArgumentException("ID does not reference a View inside this Window");
1597 }
1598 return view;
1599 }
1600
1601 /**
1602 * Convenience for
1603 * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}
1604 * to set the screen content from a layout resource. The resource will be
1605 * inflated, adding all top-level views to the screen.
1606 *
1607 * @param layoutResID Resource ID to be inflated.
1608 * @see #setContentView(View, android.view.ViewGroup.LayoutParams)
1609 */
1610 public abstract void setContentView(@LayoutRes int layoutResID);
1611
1612 /**
1613 * Convenience for
1614 * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}
1615 * set the screen content to an explicit view. This view is placed
1616 * directly into the screen's view hierarchy. It can itself be a complex
1617 * view hierarhcy.
1618 *
1619 * @param view The desired content to display.
1620 * @see #setContentView(View, android.view.ViewGroup.LayoutParams)
1621 */
1622 public abstract void setContentView(View view);
1623
1624 /**
1625 * Set the screen content to an explicit view. This view is placed
1626 * directly into the screen's view hierarchy. It can itself be a complex
1627 * view hierarchy.
1628 *
1629 * <p>Note that calling this function "locks in" various characteristics
1630 * of the window that can not, from this point forward, be changed: the
1631 * features that have been requested with {@link #requestFeature(int)},
1632 * and certain window flags as described in {@link #setFlags(int, int)}.</p>
1633 *
1634 * <p>If {@link #FEATURE_CONTENT_TRANSITIONS} is set, the window's
1635 * TransitionManager will be used to animate content from the current
1636 * content View to view.</p>
1637 *
1638 * @param view The desired content to display.
1639 * @param params Layout parameters for the view.
1640 * @see #getTransitionManager()
1641 * @see #setTransitionManager(android.transition.TransitionManager)
1642 */
1643 public abstract void setContentView(View view, ViewGroup.LayoutParams params);
1644
1645 /**
1646 * Variation on
1647 * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}
1648 * to add an additional content view to the screen. Added after any existing
1649 * ones in the screen -- existing views are NOT removed.
1650 *
1651 * @param view The desired content to display.
1652 * @param params Layout parameters for the view.
1653 */
1654 public abstract void addContentView(View view, ViewGroup.LayoutParams params);
1655
1656 /**
1657 * Remove the view that was used as the screen content.
1658 *
1659 * @hide
1660 */
1661 @SuppressWarnings("HiddenAbstractMethod")
1662 public abstract void clearContentView();
1663
1664 /**
1665 * Return the view in this Window that currently has focus, or null if
1666 * there are none. Note that this does not look in any containing
1667 * Window.
1668 *
1669 * @return View The current View with focus or null.
1670 */
1671 @Nullable
1672 public abstract View getCurrentFocus();
1673
1674 /**
1675 * Quick access to the {@link LayoutInflater} instance that this Window
1676 * retrieved from its Context.
1677 *
1678 * @return LayoutInflater The shared LayoutInflater.
1679 */
1680 @NonNull
1681 public abstract LayoutInflater getLayoutInflater();
1682
1683 public abstract void setTitle(CharSequence title);
1684
1685 @Deprecated
1686 public abstract void setTitleColor(@ColorInt int textColor);
1687
1688 public abstract void openPanel(int featureId, KeyEvent event);
1689
1690 public abstract void closePanel(int featureId);
1691
1692 public abstract void togglePanel(int featureId, KeyEvent event);
1693
1694 public abstract void invalidatePanelMenu(int featureId);
1695
1696 public abstract boolean performPanelShortcut(int featureId,
1697 int keyCode,
1698 KeyEvent event,
1699 int flags);
1700 public abstract boolean performPanelIdentifierAction(int featureId,
1701 int id,
1702 int flags);
1703
1704 public abstract void closeAllPanels();
1705
1706 public abstract boolean performContextMenuIdentifierAction(int id, int flags);
1707
1708 /**
1709 * Should be called when the configuration is changed.
1710 *
1711 * @param newConfig The new configuration.
1712 */
1713 public abstract void onConfigurationChanged(Configuration newConfig);
1714
1715 /**
1716 * Sets the window elevation.
1717 * <p>
1718 * Changes to this property take effect immediately and will cause the
1719 * window surface to be recreated. This is an expensive operation and as a
1720 * result, this property should not be animated.
1721 *
1722 * @param elevation The window elevation.
1723 * @see View#setElevation(float)
1724 * @see android.R.styleable#Window_windowElevation
1725 */
1726 public void setElevation(float elevation) {}
1727
1728 /**
1729 * Gets the window elevation.
1730 *
1731 * @hide
1732 */
1733 public float getElevation() {
1734 return 0.0f;
1735 }
1736
1737 /**
1738 * Sets whether window content should be clipped to the outline of the
1739 * window background.
1740 *
1741 * @param clipToOutline Whether window content should be clipped to the
1742 * outline of the window background.
1743 * @see View#setClipToOutline(boolean)
1744 * @see android.R.styleable#Window_windowClipToOutline
1745 */
1746 public void setClipToOutline(boolean clipToOutline) {}
1747
1748 /**
1749 * Change the background of this window to a Drawable resource. Setting the
1750 * background to null will make the window be opaque. To make the window
1751 * transparent, you can use an empty drawable (for instance a ColorDrawable
1752 * with the color 0 or the system drawable android:drawable/empty.)
1753 *
1754 * @param resId The resource identifier of a drawable resource which will
1755 * be installed as the new background.
1756 */
1757 public void setBackgroundDrawableResource(@DrawableRes int resId) {
1758 setBackgroundDrawable(mContext.getDrawable(resId));
1759 }
1760
1761 /**
1762 * Change the background of this window to a custom Drawable. Setting the
1763 * background to null will make the window be opaque. To make the window
1764 * transparent, you can use an empty drawable (for instance a ColorDrawable
1765 * with the color 0 or the system drawable android:drawable/empty.)
1766 *
1767 * @param drawable The new Drawable to use for this window's background.
1768 */
1769 public abstract void setBackgroundDrawable(Drawable drawable);
1770
1771 /**
1772 * <p>
1773 * Blurs the screen behind the window within the bounds of the window.
1774 * </p><p>
1775 * The density of the blur is set by the blur radius. The radius defines the size
1776 * of the neighbouring area, from which pixels will be averaged to form the final
1777 * color for each pixel. The operation approximates a Gaussian blur.
1778 * A radius of 0 means no blur. The higher the radius, the denser the blur.
1779 * </p><p>
1780 * The window background drawable is drawn on top of the blurred region. The blur
1781 * region bounds and rounded corners will mimic those of the background drawable.
1782 * </p><p>
1783 * For the blur region to be visible, the window has to be translucent
1784 * (see {@link android.R.attr#windowIsTranslucent}) and floating
1785 * (see {@link android.R.attr#windowIsFloating}).
1786 * </p><p>
1787 * Note the difference with {@link WindowManager.LayoutParams#setBlurBehindRadius},
1788 * which blurs the whole screen behind the window. Background blur blurs the screen behind
1789 * only within the bounds of the window.
1790 * </p><p>
1791 * Some devices might not support cross-window blur due to GPU limitations. It can also be
1792 * disabled at runtime, e.g. during battery saving mode, when multimedia tunneling is used or
1793 * when minimal post processing is requested. In such situations, no blur will be computed or
1794 * drawn, resulting in a transparent window background. To avoid this, the app might want to
1795 * change its theme to one that does not use blurs. To listen for cross-window blur
1796 * enabled/disabled events, use {@link WindowManager#addCrossWindowBlurEnabledListener}.
1797 * </p>
1798 *
1799 * @param blurRadius The blur radius to use for window background blur in pixels
1800 *
1801 * @see android.R.styleable#Window_windowBackgroundBlurRadius
1802 * @see WindowManager.LayoutParams#setBlurBehindRadius
1803 * @see WindowManager#addCrossWindowBlurEnabledListener
1804 */
1805 public void setBackgroundBlurRadius(int blurRadius) {}
1806
1807 /**
1808 * Set the value for a drawable feature of this window, from a resource
1809 * identifier. You must have called requestFeature(featureId) before
1810 * calling this function.
1811 *
1812 * @see android.content.res.Resources#getDrawable(int)
1813 *
1814 * @param featureId The desired drawable feature to change, defined as a
1815 * constant by Window.
1816 * @param resId Resource identifier of the desired image.
1817 */
1818 public abstract void setFeatureDrawableResource(int featureId, @DrawableRes int resId);
1819
1820 /**
1821 * Set the value for a drawable feature of this window, from a URI. You
1822 * must have called requestFeature(featureId) before calling this
1823 * function.
1824 *
1825 * <p>The only URI currently supported is "content:", specifying an image
1826 * in a content provider.
1827 *
1828 * @see android.widget.ImageView#setImageURI
1829 *
1830 * @param featureId The desired drawable feature to change. Features are
1831 * constants defined by Window.
1832 * @param uri The desired URI.
1833 */
1834 public abstract void setFeatureDrawableUri(int featureId, Uri uri);
1835
1836 /**
1837 * Set an explicit Drawable value for feature of this window. You must
1838 * have called requestFeature(featureId) before calling this function.
1839 *
1840 * @param featureId The desired drawable feature to change. Features are
1841 * constants defined by Window.
1842 * @param drawable A Drawable object to display.
1843 */
1844 public abstract void setFeatureDrawable(int featureId, Drawable drawable);
1845
1846 /**
1847 * Set a custom alpha value for the given drawable feature, controlling how
1848 * much the background is visible through it.
1849 *
1850 * @param featureId The desired drawable feature to change. Features are
1851 * constants defined by Window.
1852 * @param alpha The alpha amount, 0 is completely transparent and 255 is
1853 * completely opaque.
1854 */
1855 public abstract void setFeatureDrawableAlpha(int featureId, int alpha);
1856
1857 /**
1858 * Set the integer value for a feature. The range of the value depends on
1859 * the feature being set. For {@link #FEATURE_PROGRESS}, it should go from
1860 * 0 to 10000. At 10000 the progress is complete and the indicator hidden.
1861 *
1862 * @param featureId The desired feature to change. Features are constants
1863 * defined by Window.
1864 * @param value The value for the feature. The interpretation of this
1865 * value is feature-specific.
1866 */
1867 public abstract void setFeatureInt(int featureId, int value);
1868
1869 /**
1870 * Request that key events come to this activity. Use this if your
1871 * activity has no views with focus, but the activity still wants
1872 * a chance to process key events.
1873 */
1874 public abstract void takeKeyEvents(boolean get);
1875
1876 /**
1877 * Used by custom windows, such as Dialog, to pass the key press event
1878 * further down the view hierarchy. Application developers should
1879 * not need to implement or call this.
1880 *
1881 */
1882 public abstract boolean superDispatchKeyEvent(KeyEvent event);
1883
1884 /**
1885 * Used by custom windows, such as Dialog, to pass the key shortcut press event
1886 * further down the view hierarchy. Application developers should
1887 * not need to implement or call this.
1888 *
1889 */
1890 public abstract boolean superDispatchKeyShortcutEvent(KeyEvent event);
1891
1892 /**
1893 * Used by custom windows, such as Dialog, to pass the touch screen event
1894 * further down the view hierarchy. Application developers should
1895 * not need to implement or call this.
1896 *
1897 */
1898 public abstract boolean superDispatchTouchEvent(MotionEvent event);
1899
1900 /**
1901 * Used by custom windows, such as Dialog, to pass the trackball event
1902 * further down the view hierarchy. Application developers should
1903 * not need to implement or call this.
1904 *
1905 */
1906 public abstract boolean superDispatchTrackballEvent(MotionEvent event);
1907
1908 /**
1909 * Used by custom windows, such as Dialog, to pass the generic motion event
1910 * further down the view hierarchy. Application developers should
1911 * not need to implement or call this.
1912 *
1913 */
1914 public abstract boolean superDispatchGenericMotionEvent(MotionEvent event);
1915
1916 /**
1917 * Retrieve the top-level window decor view (containing the standard
1918 * window frame/decorations and the client's content inside of that), which
1919 * can be added as a window to the window manager.
1920 *
1921 * <p><em>Note that calling this function for the first time "locks in"
1922 * various window characteristics as described in
1923 * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}.</em></p>
1924 *
1925 * @return Returns the top-level window decor view.
1926 */
1927 public abstract @NonNull View getDecorView();
1928
1929 /**
1930 * @return the status bar background view or null.
1931 * @hide
1932 */
1933 @TestApi
1934 public @Nullable View getStatusBarBackgroundView() {
1935 return null;
1936 }
1937
1938 /**
1939 * @return the navigation bar background view or null.
1940 * @hide
1941 */
1942 @TestApi
1943 public @Nullable View getNavigationBarBackgroundView() {
1944 return null;
1945 }
1946
1947 /**
1948 * Retrieve the current decor view, but only if it has already been created;
1949 * otherwise returns null.
1950 *
1951 * @return Returns the top-level window decor or null.
1952 * @see #getDecorView
1953 */
1954 public abstract View peekDecorView();
1955
1956 public abstract Bundle saveHierarchyState();
1957
1958 public abstract void restoreHierarchyState(Bundle savedInstanceState);
1959
1960 protected abstract void onActive();
1961
1962 /**
1963 * Return the feature bits that are enabled. This is the set of features
1964 * that were given to requestFeature(), and are being handled by this
1965 * Window itself or its container. That is, it is the set of
1966 * requested features that you can actually use.
1967 *
1968 * <p>To do: add a public version of this API that allows you to check for
1969 * features by their feature ID.
1970 *
1971 * @return int The feature bits.
1972 */
1973 protected final int getFeatures()
1974 {
1975 return mFeatures;
1976 }
1977
1978 /**
1979 * Return the feature bits set by default on a window.
1980 * @param context The context used to access resources
1981 */
1982 public static int getDefaultFeatures(Context context) {
1983 int features = 0;
1984
1985 final Resources res = context.getResources();
1986 if (res.getBoolean(com.android.internal.R.bool.config_defaultWindowFeatureOptionsPanel)) {
1987 features |= 1 << FEATURE_OPTIONS_PANEL;
1988 }
1989
1990 if (res.getBoolean(com.android.internal.R.bool.config_defaultWindowFeatureContextMenu)) {
1991 features |= 1 << FEATURE_CONTEXT_MENU;
1992 }
1993
1994 return features;
1995 }
1996
1997 /**
1998 * Query for the availability of a certain feature.
1999 *
2000 * @param feature The feature ID to check
2001 * @return true if the feature is enabled, false otherwise.
2002 */
2003 public boolean hasFeature(int feature) {
2004 return (getFeatures() & (1 << feature)) != 0;
2005 }
2006
2007 /**
2008 * Return the feature bits that are being implemented by this Window.
2009 * This is the set of features that were given to requestFeature(), and are
2010 * being handled by only this Window itself, not by its containers.
2011 *
2012 * @return int The feature bits.
2013 */
2014 protected final int getLocalFeatures()
2015 {
2016 return mLocalFeatures;
2017 }
2018
2019 /**
2020 * Set the default format of window, as per the PixelFormat types. This
2021 * is the format that will be used unless the client specifies in explicit
2022 * format with setFormat();
2023 *
2024 * @param format The new window format (see PixelFormat).
2025 *
2026 * @see #setFormat
2027 * @see PixelFormat
2028 */
2029 protected void setDefaultWindowFormat(int format) {
2030 mDefaultWindowFormat = format;
2031 if (!mHaveWindowFormat) {
2032 final WindowManager.LayoutParams attrs = getAttributes();
2033 attrs.format = format;
2034 dispatchWindowAttributesChanged(attrs);
2035 }
2036 }
2037
2038 /** @hide */
2039 protected boolean haveDimAmount() {
2040 return mHaveDimAmount;
2041 }
2042
2043 public abstract void setChildDrawable(int featureId, Drawable drawable);
2044
2045 public abstract void setChildInt(int featureId, int value);
2046
2047 /**
2048 * Is a keypress one of the defined shortcut keys for this window.
2049 * @param keyCode the key code from {@link android.view.KeyEvent} to check.
2050 * @param event the {@link android.view.KeyEvent} to use to help check.
2051 */
2052 public abstract boolean isShortcutKey(int keyCode, KeyEvent event);
2053
2054 /**
2055 * @see android.app.Activity#setVolumeControlStream(int)
2056 */
2057 public abstract void setVolumeControlStream(int streamType);
2058
2059 /**
2060 * @see android.app.Activity#getVolumeControlStream()
2061 */
2062 public abstract int getVolumeControlStream();
2063
2064 /**
2065 * Sets a {@link MediaController} to send media keys and volume changes to.
2066 * If set, this should be preferred for all media keys and volume requests
2067 * sent to this window.
2068 *
2069 * @param controller The controller for the session which should receive
2070 * media keys and volume changes.
2071 * @see android.app.Activity#setMediaController(android.media.session.MediaController)
2072 */
2073 public void setMediaController(MediaController controller) {
2074 }
2075
2076 /**
2077 * Gets the {@link MediaController} that was previously set.
2078 *
2079 * @return The controller which should receive events.
2080 * @see #setMediaController(android.media.session.MediaController)
2081 * @see android.app.Activity#getMediaController()
2082 */
2083 public MediaController getMediaController() {
2084 return null;
2085 }
2086
2087 /**
2088 * Set extra options that will influence the UI for this window.
2089 * @param uiOptions Flags specifying extra options for this window.
2090 */
2091 public void setUiOptions(int uiOptions) { }
2092
2093 /**
2094 * Set extra options that will influence the UI for this window.
2095 * Only the bits filtered by mask will be modified.
2096 * @param uiOptions Flags specifying extra options for this window.
2097 * @param mask Flags specifying which options should be modified. Others will remain unchanged.
2098 */
2099 public void setUiOptions(int uiOptions, int mask) { }
2100
2101 /**
2102 * Set the primary icon for this window.
2103 *
2104 * @param resId resource ID of a drawable to set
2105 */
2106 public void setIcon(@DrawableRes int resId) { }
2107
2108 /**
2109 * Set the default icon for this window.
2110 * This will be overridden by any other icon set operation which could come from the
2111 * theme or another explicit set.
2112 *
2113 * @hide
2114 */
2115 public void setDefaultIcon(@DrawableRes int resId) { }
2116
2117 /**
2118 * Set the logo for this window. A logo is often shown in place of an
2119 * {@link #setIcon(int) icon} but is generally wider and communicates window title information
2120 * as well.
2121 *
2122 * @param resId resource ID of a drawable to set
2123 */
2124 public void setLogo(@DrawableRes int resId) { }
2125
2126 /**
2127 * Set the default logo for this window.
2128 * This will be overridden by any other logo set operation which could come from the
2129 * theme or another explicit set.
2130 *
2131 * @hide
2132 */
2133 public void setDefaultLogo(@DrawableRes int resId) { }
2134
2135 /**
2136 * Set focus locally. The window should have the
2137 * {@link WindowManager.LayoutParams#FLAG_LOCAL_FOCUS_MODE} flag set already.
2138 * @param hasFocus Whether this window has focus or not.
2139 * @param inTouchMode Whether this window is in touch mode or not.
2140 */
2141 public void setLocalFocus(boolean hasFocus, boolean inTouchMode) { }
2142
2143 /**
2144 * Inject an event to window locally.
2145 * @param event A key or touch event to inject to this window.
2146 */
2147 public void injectInputEvent(InputEvent event) { }
2148
2149 /**
2150 * Retrieve the {@link TransitionManager} responsible for for default transitions
2151 * in this window. Requires {@link #FEATURE_CONTENT_TRANSITIONS}.
2152 *
2153 * <p>This method will return non-null after content has been initialized (e.g. by using
2154 * {@link #setContentView}) if {@link #FEATURE_CONTENT_TRANSITIONS} has been granted.</p>
2155 *
2156 * @return This window's content TransitionManager or null if none is set.
2157 * @attr ref android.R.styleable#Window_windowContentTransitionManager
2158 */
2159 public TransitionManager getTransitionManager() {
2160 return null;
2161 }
2162
2163 /**
2164 * Set the {@link TransitionManager} to use for default transitions in this window.
2165 * Requires {@link #FEATURE_CONTENT_TRANSITIONS}.
2166 *
2167 * @param tm The TransitionManager to use for scene changes.
2168 * @attr ref android.R.styleable#Window_windowContentTransitionManager
2169 */
2170 public void setTransitionManager(TransitionManager tm) {
2171 throw new UnsupportedOperationException();
2172 }
2173
2174 /**
2175 * Retrieve the {@link Scene} representing this window's current content.
2176 * Requires {@link #FEATURE_CONTENT_TRANSITIONS}.
2177 *
2178 * <p>This method will return null if the current content is not represented by a Scene.</p>
2179 *
2180 * @return Current Scene being shown or null
2181 */
2182 public Scene getContentScene() {
2183 return null;
2184 }
2185
2186 /**
2187 * Sets the Transition that will be used to move Views into the initial scene. The entering
2188 * Views will be those that are regular Views or ViewGroups that have
2189 * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
2190 * {@link android.transition.Visibility} as entering is governed by changing visibility from
2191 * {@link View#INVISIBLE} to {@link View#VISIBLE}. If <code>transition</code> is null,
2192 * entering Views will remain unaffected.
2193 *
2194 * @param transition The Transition to use to move Views into the initial Scene.
2195 * @attr ref android.R.styleable#Window_windowEnterTransition
2196 */
2197 public void setEnterTransition(Transition transition) {}
2198
2199 /**
2200 * Sets the Transition that will be used to move Views out of the scene when the Window is
2201 * preparing to close, for example after a call to
2202 * {@link android.app.Activity#finishAfterTransition()}. The exiting
2203 * Views will be those that are regular Views or ViewGroups that have
2204 * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
2205 * {@link android.transition.Visibility} as entering is governed by changing visibility from
2206 * {@link View#VISIBLE} to {@link View#INVISIBLE}. If <code>transition</code> is null,
2207 * entering Views will remain unaffected. If nothing is set, the default will be to
2208 * use the same value as set in {@link #setEnterTransition(android.transition.Transition)}.
2209 *
2210 * @param transition The Transition to use to move Views out of the Scene when the Window
2211 * is preparing to close.
2212 * @attr ref android.R.styleable#Window_windowReturnTransition
2213 */
2214 public void setReturnTransition(Transition transition) {}
2215
2216 /**
2217 * Sets the Transition that will be used to move Views out of the scene when starting a
2218 * new Activity. The exiting Views will be those that are regular Views or ViewGroups that
2219 * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
2220 * {@link android.transition.Visibility} as exiting is governed by changing visibility
2221 * from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, the views will
2222 * remain unaffected. Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
2223 *
2224 * @param transition The Transition to use to move Views out of the scene when calling a
2225 * new Activity.
2226 * @attr ref android.R.styleable#Window_windowExitTransition
2227 */
2228 public void setExitTransition(Transition transition) {}
2229
2230 /**
2231 * Sets the Transition that will be used to move Views in to the scene when returning from
2232 * a previously-started Activity. The entering Views will be those that are regular Views
2233 * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions
2234 * will extend {@link android.transition.Visibility} as exiting is governed by changing
2235 * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null,
2236 * the views will remain unaffected. If nothing is set, the default will be to use the same
2237 * transition as {@link #setExitTransition(android.transition.Transition)}.
2238 * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
2239 *
2240 * @param transition The Transition to use to move Views into the scene when reentering from a
2241 * previously-started Activity.
2242 * @attr ref android.R.styleable#Window_windowReenterTransition
2243 */
2244 public void setReenterTransition(Transition transition) {}
2245
2246 /**
2247 * Returns the transition used to move Views into the initial scene. The entering
2248 * Views will be those that are regular Views or ViewGroups that have
2249 * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
2250 * {@link android.transition.Visibility} as entering is governed by changing visibility from
2251 * {@link View#INVISIBLE} to {@link View#VISIBLE}. If <code>transition</code> is null,
2252 * entering Views will remain unaffected. Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
2253 *
2254 * @return the Transition to use to move Views into the initial Scene.
2255 * @attr ref android.R.styleable#Window_windowEnterTransition
2256 */
2257 public Transition getEnterTransition() { return null; }
2258
2259 /**
2260 * Returns the Transition that will be used to move Views out of the scene when the Window is
2261 * preparing to close, for example after a call to
2262 * {@link android.app.Activity#finishAfterTransition()}. The exiting
2263 * Views will be those that are regular Views or ViewGroups that have
2264 * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
2265 * {@link android.transition.Visibility} as entering is governed by changing visibility from
2266 * {@link View#VISIBLE} to {@link View#INVISIBLE}.
2267 *
2268 * @return The Transition to use to move Views out of the Scene when the Window
2269 * is preparing to close.
2270 * @attr ref android.R.styleable#Window_windowReturnTransition
2271 */
2272 public Transition getReturnTransition() { return null; }
2273
2274 /**
2275 * Returns the Transition that will be used to move Views out of the scene when starting a
2276 * new Activity. The exiting Views will be those that are regular Views or ViewGroups that
2277 * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
2278 * {@link android.transition.Visibility} as exiting is governed by changing visibility
2279 * from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, the views will
2280 * remain unaffected. Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
2281 *
2282 * @return the Transition to use to move Views out of the scene when calling a
2283 * new Activity.
2284 * @attr ref android.R.styleable#Window_windowExitTransition
2285 */
2286 public Transition getExitTransition() { return null; }
2287
2288 /**
2289 * Returns the Transition that will be used to move Views in to the scene when returning from
2290 * a previously-started Activity. The entering Views will be those that are regular Views
2291 * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions
2292 * will extend {@link android.transition.Visibility} as exiting is governed by changing
2293 * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}.
2294 * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
2295 *
2296 * @return The Transition to use to move Views into the scene when reentering from a
2297 * previously-started Activity.
2298 * @attr ref android.R.styleable#Window_windowReenterTransition
2299 */
2300 public Transition getReenterTransition() { return null; }
2301
2302 /**
2303 * Sets the Transition that will be used for shared elements transferred into the content
2304 * Scene. Typical Transitions will affect size and location, such as
2305 * {@link android.transition.ChangeBounds}. A null
2306 * value will cause transferred shared elements to blink to the final position.
2307 * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
2308 *
2309 * @param transition The Transition to use for shared elements transferred into the content
2310 * Scene.
2311 * @attr ref android.R.styleable#Window_windowSharedElementEnterTransition
2312 */
2313 public void setSharedElementEnterTransition(Transition transition) {}
2314
2315 /**
2316 * Sets the Transition that will be used for shared elements transferred back to a
2317 * calling Activity. Typical Transitions will affect size and location, such as
2318 * {@link android.transition.ChangeBounds}. A null
2319 * value will cause transferred shared elements to blink to the final position.
2320 * If no value is set, the default will be to use the same value as
2321 * {@link #setSharedElementEnterTransition(android.transition.Transition)}.
2322 * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
2323 *
2324 * @param transition The Transition to use for shared elements transferred out of the content
2325 * Scene.
2326 * @attr ref android.R.styleable#Window_windowSharedElementReturnTransition
2327 */
2328 public void setSharedElementReturnTransition(Transition transition) {}
2329
2330 /**
2331 * Returns the Transition that will be used for shared elements transferred into the content
2332 * Scene. Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
2333 *
2334 * @return Transition to use for sharend elements transferred into the content Scene.
2335 * @attr ref android.R.styleable#Window_windowSharedElementEnterTransition
2336 */
2337 public Transition getSharedElementEnterTransition() { return null; }
2338
2339 /**
2340 * Returns the Transition that will be used for shared elements transferred back to a
2341 * calling Activity. Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
2342 *
2343 * @return Transition to use for sharend elements transferred into the content Scene.
2344 * @attr ref android.R.styleable#Window_windowSharedElementReturnTransition
2345 */
2346 public Transition getSharedElementReturnTransition() { return null; }
2347
2348 /**
2349 * Sets the Transition that will be used for shared elements after starting a new Activity
2350 * before the shared elements are transferred to the called Activity. If the shared elements
2351 * must animate during the exit transition, this Transition should be used. Upon completion,
2352 * the shared elements may be transferred to the started Activity.
2353 * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
2354 *
2355 * @param transition The Transition to use for shared elements in the launching Window
2356 * prior to transferring to the launched Activity's Window.
2357 * @attr ref android.R.styleable#Window_windowSharedElementExitTransition
2358 */
2359 public void setSharedElementExitTransition(Transition transition) {}
2360
2361 /**
2362 * Sets the Transition that will be used for shared elements reentering from a started
2363 * Activity after it has returned the shared element to it start location. If no value
2364 * is set, this will default to
2365 * {@link #setSharedElementExitTransition(android.transition.Transition)}.
2366 * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
2367 *
2368 * @param transition The Transition to use for shared elements in the launching Window
2369 * after the shared element has returned to the Window.
2370 * @attr ref android.R.styleable#Window_windowSharedElementReenterTransition
2371 */
2372 public void setSharedElementReenterTransition(Transition transition) {}
2373
2374 /**
2375 * Returns the Transition to use for shared elements in the launching Window prior
2376 * to transferring to the launched Activity's Window.
2377 * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
2378 *
2379 * @return the Transition to use for shared elements in the launching Window prior
2380 * to transferring to the launched Activity's Window.
2381 * @attr ref android.R.styleable#Window_windowSharedElementExitTransition
2382 */
2383 public Transition getSharedElementExitTransition() { return null; }
2384
2385 /**
2386 * Returns the Transition that will be used for shared elements reentering from a started
2387 * Activity after it has returned the shared element to it start location.
2388 * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
2389 *
2390 * @return the Transition that will be used for shared elements reentering from a started
2391 * Activity after it has returned the shared element to it start location.
2392 * @attr ref android.R.styleable#Window_windowSharedElementReenterTransition
2393 */
2394 public Transition getSharedElementReenterTransition() { return null; }
2395
2396 /**
2397 * Controls how the transition set in
2398 * {@link #setEnterTransition(android.transition.Transition)} overlaps with the exit
2399 * transition of the calling Activity. When true, the transition will start as soon as possible.
2400 * When false, the transition will wait until the remote exiting transition completes before
2401 * starting. The default value is true.
2402 *
2403 * @param allow true to start the enter transition when possible or false to
2404 * wait until the exiting transition completes.
2405 * @attr ref android.R.styleable#Window_windowAllowEnterTransitionOverlap
2406 */
2407 public void setAllowEnterTransitionOverlap(boolean allow) {}
2408
2409 /**
2410 * Returns how the transition set in
2411 * {@link #setEnterTransition(android.transition.Transition)} overlaps with the exit
2412 * transition of the calling Activity. When true, the transition will start as soon as possible.
2413 * When false, the transition will wait until the remote exiting transition completes before
2414 * starting. The default value is true.
2415 *
2416 * @return true when the enter transition should start as soon as possible or false to
2417 * when it should wait until the exiting transition completes.
2418 * @attr ref android.R.styleable#Window_windowAllowEnterTransitionOverlap
2419 */
2420 public boolean getAllowEnterTransitionOverlap() { return true; }
2421
2422 /**
2423 * Controls how the transition set in
2424 * {@link #setExitTransition(android.transition.Transition)} overlaps with the exit
2425 * transition of the called Activity when reentering after if finishes. When true,
2426 * the transition will start as soon as possible. When false, the transition will wait
2427 * until the called Activity's exiting transition completes before starting.
2428 * The default value is true.
2429 *
2430 * @param allow true to start the transition when possible or false to wait until the
2431 * called Activity's exiting transition completes.
2432 * @attr ref android.R.styleable#Window_windowAllowReturnTransitionOverlap
2433 */
2434 public void setAllowReturnTransitionOverlap(boolean allow) {}
2435
2436 /**
2437 * Returns how the transition set in
2438 * {@link #setExitTransition(android.transition.Transition)} overlaps with the exit
2439 * transition of the called Activity when reentering after if finishes. When true,
2440 * the transition will start as soon as possible. When false, the transition will wait
2441 * until the called Activity's exiting transition completes before starting.
2442 * The default value is true.
2443 *
2444 * @return true when the transition should start when possible or false when it should wait
2445 * until the called Activity's exiting transition completes.
2446 * @attr ref android.R.styleable#Window_windowAllowReturnTransitionOverlap
2447 */
2448 public boolean getAllowReturnTransitionOverlap() { return true; }
2449
2450 /**
2451 * Returns the duration, in milliseconds, of the window background fade
2452 * when transitioning into or away from an Activity when called with an Activity Transition.
2453 * <p>When executing the enter transition, the background starts transparent
2454 * and fades in. This requires {@link #FEATURE_ACTIVITY_TRANSITIONS}. The default is
2455 * 300 milliseconds.</p>
2456 *
2457 * @return The duration of the window background fade to opaque during enter transition.
2458 * @see #getEnterTransition()
2459 * @attr ref android.R.styleable#Window_windowTransitionBackgroundFadeDuration
2460 */
2461 public long getTransitionBackgroundFadeDuration() { return 0; }
2462
2463 /**
2464 * Sets the duration, in milliseconds, of the window background fade
2465 * when transitioning into or away from an Activity when called with an Activity Transition.
2466 * <p>When executing the enter transition, the background starts transparent
2467 * and fades in. This requires {@link #FEATURE_ACTIVITY_TRANSITIONS}. The default is
2468 * 300 milliseconds.</p>
2469 *
2470 * @param fadeDurationMillis The duration of the window background fade to or from opaque
2471 * during enter transition.
2472 * @see #setEnterTransition(android.transition.Transition)
2473 * @attr ref android.R.styleable#Window_windowTransitionBackgroundFadeDuration
2474 */
2475 public void setTransitionBackgroundFadeDuration(long fadeDurationMillis) { }
2476
2477 /**
2478 * Returns <code>true</code> when shared elements should use an Overlay during
2479 * shared element transitions or <code>false</code> when they should animate as
2480 * part of the normal View hierarchy. The default value is true.
2481 *
2482 * @return <code>true</code> when shared elements should use an Overlay during
2483 * shared element transitions or <code>false</code> when they should animate as
2484 * part of the normal View hierarchy.
2485 * @attr ref android.R.styleable#Window_windowSharedElementsUseOverlay
2486 */
2487 public boolean getSharedElementsUseOverlay() { return true; }
2488
2489 /**
2490 * Sets whether or not shared elements should use an Overlay during shared element transitions.
2491 * The default value is true.
2492 *
2493 * @param sharedElementsUseOverlay <code>true</code> indicates that shared elements should
2494 * be transitioned with an Overlay or <code>false</code>
2495 * to transition within the normal View hierarchy.
2496 * @attr ref android.R.styleable#Window_windowSharedElementsUseOverlay
2497 */
2498 public void setSharedElementsUseOverlay(boolean sharedElementsUseOverlay) { }
2499
2500 /**
2501 * @return the color of the status bar.
2502 */
2503 @ColorInt
2504 public abstract int getStatusBarColor();
2505
2506 /**
2507 * Sets the color of the status bar to {@code color}.
2508 *
2509 * For this to take effect,
2510 * the window must be drawing the system bar backgrounds with
2511 * {@link android.view.WindowManager.LayoutParams#FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS} and
2512 * {@link android.view.WindowManager.LayoutParams#FLAG_TRANSLUCENT_STATUS} must not be set.
2513 *
2514 * If {@code color} is not opaque, consider setting
2515 * {@link android.view.View#SYSTEM_UI_FLAG_LAYOUT_STABLE} and
2516 * {@link android.view.View#SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}.
2517 * <p>
2518 * The transitionName for the view background will be "android:status:background".
2519 * </p>
2520 */
2521 public abstract void setStatusBarColor(@ColorInt int color);
2522
2523 /**
2524 * @return the color of the navigation bar.
2525 */
2526 @ColorInt
2527 public abstract int getNavigationBarColor();
2528
2529 /**
2530 * Sets the color of the navigation bar to {@param color}.
2531 *
2532 * For this to take effect,
2533 * the window must be drawing the system bar backgrounds with
2534 * {@link android.view.WindowManager.LayoutParams#FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS} and
2535 * {@link android.view.WindowManager.LayoutParams#FLAG_TRANSLUCENT_NAVIGATION} must not be set.
2536 *
2537 * If {@param color} is not opaque, consider setting
2538 * {@link android.view.View#SYSTEM_UI_FLAG_LAYOUT_STABLE} and
2539 * {@link android.view.View#SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION}.
2540 * <p>
2541 * The transitionName for the view background will be "android:navigation:background".
2542 * </p>
2543 * @attr ref android.R.styleable#Window_navigationBarColor
2544 */
2545 public abstract void setNavigationBarColor(@ColorInt int color);
2546
2547 /**
2548 * Shows a thin line of the specified color between the navigation bar and the app
2549 * content.
2550 * <p>
2551 * For this to take effect,
2552 * the window must be drawing the system bar backgrounds with
2553 * {@link android.view.WindowManager.LayoutParams#FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS} and
2554 * {@link android.view.WindowManager.LayoutParams#FLAG_TRANSLUCENT_NAVIGATION} must not be set.
2555 *
2556 * @param dividerColor The color of the thin line.
2557 * @attr ref android.R.styleable#Window_navigationBarDividerColor
2558 */
2559 public void setNavigationBarDividerColor(@ColorInt int dividerColor) {
2560 }
2561
2562 /**
2563 * Retrieves the color of the navigation bar divider.
2564 *
2565 * @return The color of the navigation bar divider color.
2566 * @see #setNavigationBarColor(int)
2567 * @attr ref android.R.styleable#Window_navigationBarDividerColor
2568 */
2569 public @ColorInt int getNavigationBarDividerColor() {
2570 return 0;
2571 }
2572
2573 /**
2574 * Sets whether the system should ensure that the status bar has enough
2575 * contrast when a fully transparent background is requested.
2576 *
2577 * <p>If set to this value, the system will determine whether a scrim is necessary
2578 * to ensure that the status bar has enough contrast with the contents of
2579 * this app, and set an appropriate effective bar background color accordingly.
2580 *
2581 * <p>When the status bar color has a non-zero alpha value, the value of this
2582 * property has no effect.
2583 *
2584 * @see android.R.attr#enforceStatusBarContrast
2585 * @see #isStatusBarContrastEnforced
2586 * @see #setStatusBarColor
2587 */
2588 public void setStatusBarContrastEnforced(boolean ensureContrast) {
2589 }
2590
2591 /**
2592 * Returns whether the system is ensuring that the status bar has enough contrast when a
2593 * fully transparent background is requested.
2594 *
2595 * <p>When the status bar color has a non-zero alpha value, the value of this
2596 * property has no effect.
2597 *
2598 * @return true, if the system is ensuring contrast, false otherwise.
2599 * @see android.R.attr#enforceStatusBarContrast
2600 * @see #setStatusBarContrastEnforced
2601 * @see #setStatusBarColor
2602 */
2603 public boolean isStatusBarContrastEnforced() {
2604 return false;
2605 }
2606
2607 /**
2608 * Sets whether the system should ensure that the navigation bar has enough
2609 * contrast when a fully transparent background is requested.
2610 *
2611 * <p>If set to this value, the system will determine whether a scrim is necessary
2612 * to ensure that the navigation bar has enough contrast with the contents of
2613 * this app, and set an appropriate effective bar background color accordingly.
2614 *
2615 * <p>When the navigation bar color has a non-zero alpha value, the value of this
2616 * property has no effect.
2617 *
2618 * @see android.R.attr#enforceNavigationBarContrast
2619 * @see #isNavigationBarContrastEnforced
2620 * @see #setNavigationBarColor
2621 */
2622 public void setNavigationBarContrastEnforced(boolean enforceContrast) {
2623 }
2624
2625 /**
2626 * Returns whether the system is ensuring that the navigation bar has enough contrast when a
2627 * fully transparent background is requested.
2628 *
2629 * <p>When the navigation bar color has a non-zero alpha value, the value of this
2630 * property has no effect.
2631 *
2632 * @return true, if the system is ensuring contrast, false otherwise.
2633 * @see android.R.attr#enforceNavigationBarContrast
2634 * @see #setNavigationBarContrastEnforced
2635 * @see #setNavigationBarColor
2636 */
2637 public boolean isNavigationBarContrastEnforced() {
2638 return false;
2639 }
2640
2641 /**
2642 * Sets a list of areas within this window's coordinate space where the system should not
2643 * intercept touch or other pointing device gestures.
2644 *
2645 * <p>This method should be used by apps that make use of
2646 * {@link #takeSurface(SurfaceHolder.Callback2)} and do not have a view hierarchy available.
2647 * Apps that do have a view hierarchy should use
2648 * {@link View#setSystemGestureExclusionRects(List)} instead. This method does not modify or
2649 * replace the gesture exclusion rects populated by individual views in this window's view
2650 * hierarchy using {@link View#setSystemGestureExclusionRects(List)}.</p>
2651 *
2652 * <p>Use this to tell the system which specific sub-areas of a view need to receive gesture
2653 * input in order to function correctly in the presence of global system gestures that may
2654 * conflict. For example, if the system wishes to capture swipe-in-from-screen-edge gestures
2655 * to provide system-level navigation functionality, a view such as a navigation drawer
2656 * container can mark the left (or starting) edge of itself as requiring gesture capture
2657 * priority using this API. The system may then choose to relax its own gesture recognition
2658 * to allow the app to consume the user's gesture. It is not necessary for an app to register
2659 * exclusion rects for broadly spanning regions such as the entirety of a
2660 * <code>ScrollView</code> or for simple press and release click targets such as
2661 * <code>Button</code>. Mark an exclusion rect when interacting with a view requires
2662 * a precision touch gesture in a small area in either the X or Y dimension, such as
2663 * an edge swipe or dragging a <code>SeekBar</code> thumb.</p>
2664 *
2665 * <p>Do not modify the provided list after this method is called.</p>
2666 *
2667 * @param rects A list of precision gesture regions that this window needs to function correctly
2668 */
2669 @SuppressWarnings("unused")
2670 public void setSystemGestureExclusionRects(@NonNull List<Rect> rects) {
2671 throw new UnsupportedOperationException("window does not support gesture exclusion rects");
2672 }
2673
2674 /**
2675 * Retrieve the list of areas within this window's coordinate space where the system should not
2676 * intercept touch or other pointing device gestures. This is the list as set by
2677 * {@link #setSystemGestureExclusionRects(List)} or an empty list if
2678 * {@link #setSystemGestureExclusionRects(List)} has not been called. It does not include
2679 * exclusion rects set by this window's view hierarchy.
2680 *
2681 * @return a list of system gesture exclusion rects specific to this window
2682 */
2683 @NonNull
2684 public List<Rect> getSystemGestureExclusionRects() {
2685 return Collections.emptyList();
2686 }
2687
2688 /**
2689 * System request to begin scroll capture.
2690 *
2691 * @param listener to receive the response
2692 * @hide
2693 */
2694 public void requestScrollCapture(IScrollCaptureResponseListener listener) {
2695 }
2696
2697 /**
2698 * Used to provide scroll capture support for an arbitrary window. This registeres the given
2699 * callback with the root view of the window.
2700 *
2701 * @param callback the callback to add
2702 */
2703 public void registerScrollCaptureCallback(@NonNull ScrollCaptureCallback callback) {
2704 }
2705
2706 /**
2707 * Unregisters a {@link ScrollCaptureCallback} previously registered with this window.
2708 *
2709 * @param callback the callback to remove
2710 */
2711 public void unregisterScrollCaptureCallback(@NonNull ScrollCaptureCallback callback) {
2712 }
2713
2714 /** @hide */
2715 public void setTheme(int resId) {
2716 }
2717
2718 /**
2719 * Whether the caption should be displayed directly on the content rather than push the content
2720 * down. This affects only freeform windows since they display the caption.
2721 * @hide
2722 */
2723 public void setOverlayWithDecorCaptionEnabled(boolean enabled) {
2724 mOverlayWithDecorCaptionEnabled = enabled;
2725 }
2726
2727 /** @hide */
2728 public boolean isOverlayWithDecorCaptionEnabled() {
2729 return mOverlayWithDecorCaptionEnabled;
2730 }
2731
2732 /** @hide */
2733 public void notifyRestrictedCaptionAreaCallback(int left, int top, int right, int bottom) {
2734 if (mOnRestrictedCaptionAreaChangedListener != null) {
2735 mRestrictedCaptionAreaRect.set(left, top, right, bottom);
2736 mOnRestrictedCaptionAreaChangedListener.onRestrictedCaptionAreaChanged(
2737 mRestrictedCaptionAreaRect);
2738 }
2739 }
2740
2741 /**
2742 * Set what color should the caption controls be. By default the system will try to determine
2743 * the color from the theme. You can overwrite this by using {@link #DECOR_CAPTION_SHADE_DARK},
2744 * {@link #DECOR_CAPTION_SHADE_LIGHT}, or {@link #DECOR_CAPTION_SHADE_AUTO}.
2745 * @see #DECOR_CAPTION_SHADE_DARK
2746 * @see #DECOR_CAPTION_SHADE_LIGHT
2747 * @see #DECOR_CAPTION_SHADE_AUTO
2748 */
2749 public abstract void setDecorCaptionShade(int decorCaptionShade);
2750
2751 /**
2752 * Set the drawable that is drawn underneath the caption during the resizing.
2753 *
2754 * During the resizing the caption might not be drawn fast enough to match the new dimensions.
2755 * There is a second caption drawn underneath it that will be fast enough. By default the
2756 * caption is constructed from the theme. You can provide a drawable, that will be drawn instead
2757 * to better match your application.
2758 */
2759 public abstract void setResizingCaptionDrawable(Drawable drawable);
2760
2761 /**
2762 * Called when the activity changes from fullscreen mode to multi-window mode and visa-versa.
2763 * @hide
2764 */
2765 @SuppressWarnings("HiddenAbstractMethod")
2766 public abstract void onMultiWindowModeChanged();
2767
2768 /**
2769 * Called when the activity changes to/from picture-in-picture mode.
2770 * @hide
2771 */
2772 @SuppressWarnings("HiddenAbstractMethod")
2773 public abstract void onPictureInPictureModeChanged(boolean isInPictureInPictureMode);
2774
2775 /**
2776 * Called when the activity just relaunched.
2777 * @hide
2778 */
2779 @SuppressWarnings("HiddenAbstractMethod")
2780 public abstract void reportActivityRelaunched();
2781
2782 /**
2783 * @return The {@link WindowInsetsController} associated with this window
2784 * @see View#getWindowInsetsController()
2785 */
2786 public @Nullable WindowInsetsController getInsetsController() {
2787 return null;
2788 }
2789
2790 /**
2791 * This will be null before a content view is added, e.g. via
2792 * {@link #setContentView} or {@link #addContentView}. See
2793 * {@link android.view.View#getRootSurfaceControl}.
2794 *
2795 * @return The {@link android.view.AttachedSurfaceControl} interface for this Window
2796 */
2797 public @Nullable AttachedSurfaceControl getRootSurfaceControl() {
2798 return null;
2799 }
2800
2801 /**
2802 * Returns the {@link OnBackInvokedDispatcher} instance associated with this window.
2803 */
2804 @NonNull
2805 public OnBackInvokedDispatcher getOnBackInvokedDispatcher() {
2806 throw new RuntimeException("Not implemented. Must override in a subclass.");
2807 }
2808 }