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