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