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