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