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