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