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