Window.java revision 529b60a3b16ac3dff24f2403d760ab8ebc9670ff
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.content.Context; 20import android.content.res.Configuration; 21import android.content.res.TypedArray; 22import android.graphics.PixelFormat; 23import android.graphics.drawable.Drawable; 24import android.net.Uri; 25import android.os.Bundle; 26import android.os.IBinder; 27import android.view.accessibility.AccessibilityEvent; 28 29/** 30 * Abstract base class for a top-level window look and behavior policy. An 31 * instance of this class should be used as the top-level view added to the 32 * window manager. It provides standard UI policies such as a background, title 33 * area, default key processing, etc. 34 * 35 * <p>The only existing implementation of this abstract class is 36 * android.policy.PhoneWindow, which you should instantiate when needing a 37 * Window. Eventually that class will be refactored and a factory method 38 * added for creating Window instances without knowing about a particular 39 * implementation. 40 */ 41public abstract class Window { 42 /** Flag for the "options panel" feature. This is enabled by default. */ 43 public static final int FEATURE_OPTIONS_PANEL = 0; 44 /** Flag for the "no title" feature, turning off the title at the top 45 * of the screen. */ 46 public static final int FEATURE_NO_TITLE = 1; 47 /** Flag for the progress indicator feature */ 48 public static final int FEATURE_PROGRESS = 2; 49 /** Flag for having an icon on the left side of the title bar */ 50 public static final int FEATURE_LEFT_ICON = 3; 51 /** Flag for having an icon on the right side of the title bar */ 52 public static final int FEATURE_RIGHT_ICON = 4; 53 /** Flag for indeterminate progress */ 54 public static final int FEATURE_INDETERMINATE_PROGRESS = 5; 55 /** Flag for the context menu. This is enabled by default. */ 56 public static final int FEATURE_CONTEXT_MENU = 6; 57 /** Flag for custom title. You cannot combine this feature with other title features. */ 58 public static final int FEATURE_CUSTOM_TITLE = 7; 59 /** 60 * Flag for enabling the Action Bar. 61 * This is enabled by default for some devices. The Action Bar 62 * replaces the title bar and provides an alternate location 63 * for an on-screen menu button on some devices. 64 */ 65 public static final int FEATURE_ACTION_BAR = 8; 66 /** 67 * Flag for specifying the behavior of action modes when an Action Bar is not present. 68 * If overlay is enabled, the action mode UI will be allowed to cover existing window content. 69 */ 70 public static final int FEATURE_ACTION_MODE_OVERLAY = 9; 71 /** 72 * Flag for requesting this window to be hardware accelerated, if possible. 73 */ 74 public static final int FEATURE_HARDWARE_ACCELERATED = 10; 75 /** Flag for setting the progress bar's visibility to VISIBLE */ 76 public static final int PROGRESS_VISIBILITY_ON = -1; 77 /** Flag for setting the progress bar's visibility to GONE */ 78 public static final int PROGRESS_VISIBILITY_OFF = -2; 79 /** Flag for setting the progress bar's indeterminate mode on */ 80 public static final int PROGRESS_INDETERMINATE_ON = -3; 81 /** Flag for setting the progress bar's indeterminate mode off */ 82 public static final int PROGRESS_INDETERMINATE_OFF = -4; 83 /** Starting value for the (primary) progress */ 84 public static final int PROGRESS_START = 0; 85 /** Ending value for the (primary) progress */ 86 public static final int PROGRESS_END = 10000; 87 /** Lowest possible value for the secondary progress */ 88 public static final int PROGRESS_SECONDARY_START = 20000; 89 /** Highest possible value for the secondary progress */ 90 public static final int PROGRESS_SECONDARY_END = 30000; 91 92 /** The default features enabled */ 93 @SuppressWarnings({"PointlessBitwiseExpression"}) 94 protected static final int DEFAULT_FEATURES = (1 << FEATURE_OPTIONS_PANEL) | 95 (1 << FEATURE_CONTEXT_MENU); 96 97 /** 98 * The ID that the main layout in the XML layout file should have. 99 */ 100 public static final int ID_ANDROID_CONTENT = com.android.internal.R.id.content; 101 102 private final Context mContext; 103 104 private TypedArray mWindowStyle; 105 private Callback mCallback; 106 private WindowManager mWindowManager; 107 private IBinder mAppToken; 108 private String mAppName; 109 private Window mContainer; 110 private Window mActiveChild; 111 private boolean mIsActive = false; 112 private boolean mHasChildren = false; 113 private int mForcedWindowFlags = 0; 114 115 private int mFeatures = DEFAULT_FEATURES; 116 private int mLocalFeatures = DEFAULT_FEATURES; 117 118 private boolean mHaveWindowFormat = false; 119 private int mDefaultWindowFormat = PixelFormat.OPAQUE; 120 121 private boolean mHasSoftInputMode = false; 122 123 // The current window attributes. 124 private final WindowManager.LayoutParams mWindowAttributes = 125 new WindowManager.LayoutParams(); 126 127 /** 128 * API from a Window back to its caller. This allows the client to 129 * intercept key dispatching, panels and menus, etc. 130 */ 131 public interface Callback { 132 /** 133 * Called to process key events. At the very least your 134 * implementation must call 135 * {@link android.view.Window#superDispatchKeyEvent} to do the 136 * standard key processing. 137 * 138 * @param event The key event. 139 * 140 * @return boolean Return true if this event was consumed. 141 */ 142 public boolean dispatchKeyEvent(KeyEvent event); 143 144 /** 145 * Called to process touch screen events. At the very least your 146 * implementation must call 147 * {@link android.view.Window#superDispatchTouchEvent} to do the 148 * standard touch screen processing. 149 * 150 * @param event The touch screen event. 151 * 152 * @return boolean Return true if this event was consumed. 153 */ 154 public boolean dispatchTouchEvent(MotionEvent event); 155 156 /** 157 * Called to process trackball events. At the very least your 158 * implementation must call 159 * {@link android.view.Window#superDispatchTrackballEvent} to do the 160 * standard trackball processing. 161 * 162 * @param event The trackball event. 163 * 164 * @return boolean Return true if this event was consumed. 165 */ 166 public boolean dispatchTrackballEvent(MotionEvent event); 167 168 /** 169 * Called to process population of {@link AccessibilityEvent}s. 170 * 171 * @param event The event. 172 * 173 * @return boolean Return true if event population was completed. 174 */ 175 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event); 176 177 /** 178 * Instantiate the view to display in the panel for 'featureId'. 179 * You can return null, in which case the default content (typically 180 * a menu) will be created for you. 181 * 182 * @param featureId Which panel is being created. 183 * 184 * @return view The top-level view to place in the panel. 185 * 186 * @see #onPreparePanel 187 */ 188 public View onCreatePanelView(int featureId); 189 190 /** 191 * Initialize the contents of the menu for panel 'featureId'. This is 192 * called if onCreatePanelView() returns null, giving you a standard 193 * menu in which you can place your items. It is only called once for 194 * the panel, the first time it is shown. 195 * 196 * <p>You can safely hold on to <var>menu</var> (and any items created 197 * from it), making modifications to it as desired, until the next 198 * time onCreatePanelMenu() is called for this feature. 199 * 200 * @param featureId The panel being created. 201 * @param menu The menu inside the panel. 202 * 203 * @return boolean You must return true for the panel to be displayed; 204 * if you return false it will not be shown. 205 */ 206 public boolean onCreatePanelMenu(int featureId, Menu menu); 207 208 /** 209 * Prepare a panel to be displayed. This is called right before the 210 * panel window is shown, every time it is shown. 211 * 212 * @param featureId The panel that is being displayed. 213 * @param view The View that was returned by onCreatePanelView(). 214 * @param menu If onCreatePanelView() returned null, this is the Menu 215 * being displayed in the panel. 216 * 217 * @return boolean You must return true for the panel to be displayed; 218 * if you return false it will not be shown. 219 * 220 * @see #onCreatePanelView 221 */ 222 public boolean onPreparePanel(int featureId, View view, Menu menu); 223 224 /** 225 * Called when a panel's menu is opened by the user. This may also be 226 * called when the menu is changing from one type to another (for 227 * example, from the icon menu to the expanded menu). 228 * 229 * @param featureId The panel that the menu is in. 230 * @param menu The menu that is opened. 231 * @return Return true to allow the menu to open, or false to prevent 232 * the menu from opening. 233 */ 234 public boolean onMenuOpened(int featureId, Menu menu); 235 236 /** 237 * Called when a panel's menu item has been selected by the user. 238 * 239 * @param featureId The panel that the menu is in. 240 * @param item The menu item that was selected. 241 * 242 * @return boolean Return true to finish processing of selection, or 243 * false to perform the normal menu handling (calling its 244 * Runnable or sending a Message to its target Handler). 245 */ 246 public boolean onMenuItemSelected(int featureId, MenuItem item); 247 248 /** 249 * This is called whenever the current window attributes change. 250 * 251 */ 252 public void onWindowAttributesChanged(WindowManager.LayoutParams attrs); 253 254 /** 255 * This hook is called whenever the content view of the screen changes 256 * (due to a call to 257 * {@link Window#setContentView(View, android.view.ViewGroup.LayoutParams) 258 * Window.setContentView} or 259 * {@link Window#addContentView(View, android.view.ViewGroup.LayoutParams) 260 * Window.addContentView}). 261 */ 262 public void onContentChanged(); 263 264 /** 265 * This hook is called whenever the window focus changes. See 266 * {@link View#onWindowFocusChanged(boolean) 267 * View.onWindowFocusChanged(boolean)} for more information. 268 * 269 * @param hasFocus Whether the window now has focus. 270 */ 271 public void onWindowFocusChanged(boolean hasFocus); 272 273 /** 274 * Called when the window has been attached to the window manager. 275 * See {@link View#onAttachedToWindow() View.onAttachedToWindow()} 276 * for more information. 277 */ 278 public void onAttachedToWindow(); 279 280 /** 281 * Called when the window has been attached to the window manager. 282 * See {@link View#onDetachedFromWindow() View.onDetachedFromWindow()} 283 * for more information. 284 */ 285 public void onDetachedFromWindow(); 286 287 /** 288 * Called when a panel is being closed. If another logical subsequent 289 * panel is being opened (and this panel is being closed to make room for the subsequent 290 * panel), this method will NOT be called. 291 * 292 * @param featureId The panel that is being displayed. 293 * @param menu If onCreatePanelView() returned null, this is the Menu 294 * being displayed in the panel. 295 */ 296 public void onPanelClosed(int featureId, Menu menu); 297 298 /** 299 * Called when the user signals the desire to start a search. 300 * 301 * @return true if search launched, false if activity refuses (blocks) 302 * 303 * @see android.app.Activity#onSearchRequested() 304 */ 305 public boolean onSearchRequested(); 306 307 /** 308 * Called when an action mode is being started. 309 * 310 * @param callback Callback to control the lifecycle of this action mode 311 * @return The ActionMode that was started, or null if it was canceled 312 */ 313 public ActionMode onStartActionMode(ActionMode.Callback callback); 314 } 315 316 public Window(Context context) { 317 mContext = context; 318 } 319 320 /** 321 * Return the Context this window policy is running in, for retrieving 322 * resources and other information. 323 * 324 * @return Context The Context that was supplied to the constructor. 325 */ 326 public final Context getContext() { 327 return mContext; 328 } 329 330 /** 331 * Return the {@link android.R.styleable#Window} attributes from this 332 * window's theme. 333 */ 334 public final TypedArray getWindowStyle() { 335 synchronized (this) { 336 if (mWindowStyle == null) { 337 mWindowStyle = mContext.obtainStyledAttributes( 338 com.android.internal.R.styleable.Window); 339 } 340 return mWindowStyle; 341 } 342 } 343 344 /** 345 * Set the container for this window. If not set, the DecorWindow 346 * operates as a top-level window; otherwise, it negotiates with the 347 * container to display itself appropriately. 348 * 349 * @param container The desired containing Window. 350 */ 351 public void setContainer(Window container) { 352 mContainer = container; 353 if (container != null) { 354 // Embedded screens never have a title. 355 mFeatures |= 1<<FEATURE_NO_TITLE; 356 mLocalFeatures |= 1<<FEATURE_NO_TITLE; 357 container.mHasChildren = true; 358 } 359 } 360 361 /** 362 * Return the container for this Window. 363 * 364 * @return Window The containing window, or null if this is a 365 * top-level window. 366 */ 367 public final Window getContainer() { 368 return mContainer; 369 } 370 371 public final boolean hasChildren() { 372 return mHasChildren; 373 } 374 375 /** 376 * Set the window manager for use by this Window to, for example, 377 * display panels. This is <em>not</em> used for displaying the 378 * Window itself -- that must be done by the client. 379 * 380 * @param wm The ViewManager for adding new windows. 381 */ 382 public void setWindowManager(WindowManager wm, IBinder appToken, String appName) { 383 setWindowManager(wm, appToken, appName, false); 384 } 385 386 /** 387 * Set the window manager for use by this Window to, for example, 388 * display panels. This is <em>not</em> used for displaying the 389 * Window itself -- that must be done by the client. 390 * 391 * @param wm The ViewManager for adding new windows. 392 */ 393 public void setWindowManager(WindowManager wm, IBinder appToken, String appName, 394 boolean hardwareAccelerated) { 395 mAppToken = appToken; 396 mAppName = appName; 397 if (wm == null) { 398 wm = WindowManagerImpl.getDefault(); 399 } 400 mWindowManager = new LocalWindowManager(wm, hardwareAccelerated); 401 } 402 403 private class LocalWindowManager implements WindowManager { 404 private boolean mHardwareAccelerated; 405 406 LocalWindowManager(WindowManager wm, boolean hardwareAccelerated) { 407 mWindowManager = wm; 408 mDefaultDisplay = mContext.getResources().getDefaultDisplay( 409 mWindowManager.getDefaultDisplay()); 410 mHardwareAccelerated = hardwareAccelerated; 411 } 412 413 public final void addView(View view, ViewGroup.LayoutParams params) { 414 // Let this throw an exception on a bad params. 415 WindowManager.LayoutParams wp = (WindowManager.LayoutParams)params; 416 CharSequence curTitle = wp.getTitle(); 417 if (wp.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW && 418 wp.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { 419 if (wp.token == null) { 420 View decor = peekDecorView(); 421 if (decor != null) { 422 wp.token = decor.getWindowToken(); 423 } 424 } 425 if (curTitle == null || curTitle.length() == 0) { 426 String title; 427 if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA) { 428 title="Media"; 429 } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY) { 430 title="MediaOvr"; 431 } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { 432 title="Panel"; 433 } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL) { 434 title="SubPanel"; 435 } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG) { 436 title="AtchDlg"; 437 } else { 438 title=Integer.toString(wp.type); 439 } 440 if (mAppName != null) { 441 title += ":" + mAppName; 442 } 443 wp.setTitle(title); 444 } 445 } else { 446 if (wp.token == null) { 447 wp.token = mContainer == null ? mAppToken : mContainer.mAppToken; 448 } 449 if ((curTitle == null || curTitle.length() == 0) 450 && mAppName != null) { 451 wp.setTitle(mAppName); 452 } 453 } 454 if (wp.packageName == null) { 455 wp.packageName = mContext.getPackageName(); 456 } 457 if (mHardwareAccelerated) { 458 wp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; 459 } 460 mWindowManager.addView(view, params); 461 } 462 463 public void updateViewLayout(View view, ViewGroup.LayoutParams params) { 464 mWindowManager.updateViewLayout(view, params); 465 } 466 467 public final void removeView(View view) { 468 mWindowManager.removeView(view); 469 } 470 471 public final void removeViewImmediate(View view) { 472 mWindowManager.removeViewImmediate(view); 473 } 474 475 public Display getDefaultDisplay() { 476 return mDefaultDisplay; 477 } 478 479 private final WindowManager mWindowManager; 480 481 private final Display mDefaultDisplay; 482 } 483 484 /** 485 * Return the window manager allowing this Window to display its own 486 * windows. 487 * 488 * @return WindowManager The ViewManager. 489 */ 490 public WindowManager getWindowManager() { 491 return mWindowManager; 492 } 493 494 /** 495 * Set the Callback interface for this window, used to intercept key 496 * events and other dynamic operations in the window. 497 * 498 * @param callback The desired Callback interface. 499 */ 500 public void setCallback(Callback callback) { 501 mCallback = callback; 502 } 503 504 /** 505 * Return the current Callback interface for this window. 506 */ 507 public final Callback getCallback() { 508 return mCallback; 509 } 510 511 /** 512 * Take ownership of this window's surface. The window's view hierarchy 513 * will no longer draw into the surface, though it will otherwise continue 514 * to operate (such as for receiving input events). The given SurfaceHolder 515 * callback will be used to tell you about state changes to the surface. 516 */ 517 public abstract void takeSurface(SurfaceHolder.Callback2 callback); 518 519 /** 520 * Take ownership of this window's InputQueue. The window will no 521 * longer read and dispatch input events from the queue; it is your 522 * responsibility to do so. 523 */ 524 public abstract void takeInputQueue(InputQueue.Callback callback); 525 526 /** 527 * Return whether this window is being displayed with a floating style 528 * (based on the {@link android.R.attr#windowIsFloating} attribute in 529 * the style/theme). 530 * 531 * @return Returns true if the window is configured to be displayed floating 532 * on top of whatever is behind it. 533 */ 534 public abstract boolean isFloating(); 535 536 /** 537 * Set the width and height layout parameters of the window. The default 538 * for both of these is MATCH_PARENT; you can change them to WRAP_CONTENT to 539 * make a window that is not full-screen. 540 * 541 * @param width The desired layout width of the window. 542 * @param height The desired layout height of the window. 543 */ 544 public void setLayout(int width, int height) 545 { 546 final WindowManager.LayoutParams attrs = getAttributes(); 547 attrs.width = width; 548 attrs.height = height; 549 if (mCallback != null) { 550 mCallback.onWindowAttributesChanged(attrs); 551 } 552 } 553 554 /** 555 * Set the gravity of the window, as per the Gravity constants. This 556 * controls how the window manager is positioned in the overall window; it 557 * is only useful when using WRAP_CONTENT for the layout width or height. 558 * 559 * @param gravity The desired gravity constant. 560 * 561 * @see Gravity 562 * @see #setLayout 563 */ 564 public void setGravity(int gravity) 565 { 566 final WindowManager.LayoutParams attrs = getAttributes(); 567 attrs.gravity = gravity; 568 if (mCallback != null) { 569 mCallback.onWindowAttributesChanged(attrs); 570 } 571 } 572 573 /** 574 * Set the type of the window, as per the WindowManager.LayoutParams 575 * types. 576 * 577 * @param type The new window type (see WindowManager.LayoutParams). 578 */ 579 public void setType(int type) { 580 final WindowManager.LayoutParams attrs = getAttributes(); 581 attrs.type = type; 582 if (mCallback != null) { 583 mCallback.onWindowAttributesChanged(attrs); 584 } 585 } 586 587 /** 588 * Set the format of window, as per the PixelFormat types. This overrides 589 * the default format that is selected by the Window based on its 590 * window decorations. 591 * 592 * @param format The new window format (see PixelFormat). Use 593 * PixelFormat.UNKNOWN to allow the Window to select 594 * the format. 595 * 596 * @see PixelFormat 597 */ 598 public void setFormat(int format) { 599 final WindowManager.LayoutParams attrs = getAttributes(); 600 if (format != PixelFormat.UNKNOWN) { 601 attrs.format = format; 602 mHaveWindowFormat = true; 603 } else { 604 attrs.format = mDefaultWindowFormat; 605 mHaveWindowFormat = false; 606 } 607 if (mCallback != null) { 608 mCallback.onWindowAttributesChanged(attrs); 609 } 610 } 611 612 /** 613 * Specify custom animations to use for the window, as per 614 * {@link WindowManager.LayoutParams#windowAnimations 615 * WindowManager.LayoutParams.windowAnimations}. Providing anything besides 616 * 0 here will override the animations the window would 617 * normally retrieve from its theme. 618 */ 619 public void setWindowAnimations(int resId) { 620 final WindowManager.LayoutParams attrs = getAttributes(); 621 attrs.windowAnimations = resId; 622 if (mCallback != null) { 623 mCallback.onWindowAttributesChanged(attrs); 624 } 625 } 626 627 /** 628 * Specify an explicit soft input mode to use for the window, as per 629 * {@link WindowManager.LayoutParams#softInputMode 630 * WindowManager.LayoutParams.softInputMode}. Providing anything besides 631 * "unspecified" here will override the input mode the window would 632 * normally retrieve from its theme. 633 */ 634 public void setSoftInputMode(int mode) { 635 final WindowManager.LayoutParams attrs = getAttributes(); 636 if (mode != WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED) { 637 attrs.softInputMode = mode; 638 mHasSoftInputMode = true; 639 } else { 640 mHasSoftInputMode = false; 641 } 642 if (mCallback != null) { 643 mCallback.onWindowAttributesChanged(attrs); 644 } 645 } 646 647 /** 648 * Convenience function to set the flag bits as specified in flags, as 649 * per {@link #setFlags}. 650 * @param flags The flag bits to be set. 651 * @see #setFlags 652 */ 653 public void addFlags(int flags) { 654 setFlags(flags, flags); 655 } 656 657 /** 658 * Convenience function to clear the flag bits as specified in flags, as 659 * per {@link #setFlags}. 660 * @param flags The flag bits to be cleared. 661 * @see #setFlags 662 */ 663 public void clearFlags(int flags) { 664 setFlags(0, flags); 665 } 666 667 /** 668 * Set the flags of the window, as per the 669 * {@link WindowManager.LayoutParams WindowManager.LayoutParams} 670 * flags. 671 * 672 * <p>Note that some flags must be set before the window decoration is 673 * created (by the first call to 674 * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)} or 675 * {@link #getDecorView()}: 676 * {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN} and 677 * {@link WindowManager.LayoutParams#FLAG_LAYOUT_INSET_DECOR}. These 678 * will be set for you based on the {@link android.R.attr#windowIsFloating} 679 * attribute. 680 * 681 * @param flags The new window flags (see WindowManager.LayoutParams). 682 * @param mask Which of the window flag bits to modify. 683 */ 684 public void setFlags(int flags, int mask) { 685 final WindowManager.LayoutParams attrs = getAttributes(); 686 attrs.flags = (attrs.flags&~mask) | (flags&mask); 687 mForcedWindowFlags |= mask; 688 if (mCallback != null) { 689 mCallback.onWindowAttributesChanged(attrs); 690 } 691 } 692 693 /** 694 * Specify custom window attributes. <strong>PLEASE NOTE:</strong> the 695 * layout params you give here should generally be from values previously 696 * retrieved with {@link #getAttributes()}; you probably do not want to 697 * blindly create and apply your own, since this will blow away any values 698 * set by the framework that you are not interested in. 699 * 700 * @param a The new window attributes, which will completely override any 701 * current values. 702 */ 703 public void setAttributes(WindowManager.LayoutParams a) { 704 mWindowAttributes.copyFrom(a); 705 if (mCallback != null) { 706 mCallback.onWindowAttributesChanged(mWindowAttributes); 707 } 708 } 709 710 /** 711 * Retrieve the current window attributes associated with this panel. 712 * 713 * @return WindowManager.LayoutParams Either the existing window 714 * attributes object, or a freshly created one if there is none. 715 */ 716 public final WindowManager.LayoutParams getAttributes() { 717 return mWindowAttributes; 718 } 719 720 /** 721 * Return the window flags that have been explicitly set by the client, 722 * so will not be modified by {@link #getDecorView}. 723 */ 724 protected final int getForcedWindowFlags() { 725 return mForcedWindowFlags; 726 } 727 728 /** 729 * Has the app specified their own soft input mode? 730 */ 731 protected final boolean hasSoftInputMode() { 732 return mHasSoftInputMode; 733 } 734 735 /** 736 * Enable extended screen features. This must be called before 737 * setContentView(). May be called as many times as desired as long as it 738 * is before setContentView(). If not called, no extended features 739 * will be available. You can not turn off a feature once it is requested. 740 * You canot use other title features with {@link #FEATURE_CUSTOM_TITLE}. 741 * 742 * @param featureId The desired features, defined as constants by Window. 743 * @return The features that are now set. 744 */ 745 public boolean requestFeature(int featureId) { 746 final int flag = 1<<featureId; 747 mFeatures |= flag; 748 mLocalFeatures |= mContainer != null ? (flag&~mContainer.mFeatures) : flag; 749 return (mFeatures&flag) != 0; 750 } 751 752 public final void makeActive() { 753 if (mContainer != null) { 754 if (mContainer.mActiveChild != null) { 755 mContainer.mActiveChild.mIsActive = false; 756 } 757 mContainer.mActiveChild = this; 758 } 759 mIsActive = true; 760 onActive(); 761 } 762 763 public final boolean isActive() 764 { 765 return mIsActive; 766 } 767 768 /** 769 * Finds a view that was identified by the id attribute from the XML that 770 * was processed in {@link android.app.Activity#onCreate}. This will 771 * implicitly call {@link #getDecorView} for you, with all of the 772 * associated side-effects. 773 * 774 * @return The view if found or null otherwise. 775 */ 776 public View findViewById(int id) { 777 return getDecorView().findViewById(id); 778 } 779 780 /** 781 * Convenience for 782 * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)} 783 * to set the screen content from a layout resource. The resource will be 784 * inflated, adding all top-level views to the screen. 785 * 786 * @param layoutResID Resource ID to be inflated. 787 * @see #setContentView(View, android.view.ViewGroup.LayoutParams) 788 */ 789 public abstract void setContentView(int layoutResID); 790 791 /** 792 * Convenience for 793 * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)} 794 * set the screen content to an explicit view. This view is placed 795 * directly into the screen's view hierarchy. It can itself be a complex 796 * view hierarhcy. 797 * 798 * @param view The desired content to display. 799 * @see #setContentView(View, android.view.ViewGroup.LayoutParams) 800 */ 801 public abstract void setContentView(View view); 802 803 /** 804 * Set the screen content to an explicit view. This view is placed 805 * directly into the screen's view hierarchy. It can itself be a complex 806 * view hierarchy. 807 * 808 * <p>Note that calling this function "locks in" various characteristics 809 * of the window that can not, from this point forward, be changed: the 810 * features that have been requested with {@link #requestFeature(int)}, 811 * and certain window flags as described in {@link #setFlags(int, int)}. 812 * 813 * @param view The desired content to display. 814 * @param params Layout parameters for the view. 815 */ 816 public abstract void setContentView(View view, ViewGroup.LayoutParams params); 817 818 /** 819 * Variation on 820 * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)} 821 * to add an additional content view to the screen. Added after any existing 822 * ones in the screen -- existing views are NOT removed. 823 * 824 * @param view The desired content to display. 825 * @param params Layout parameters for the view. 826 */ 827 public abstract void addContentView(View view, ViewGroup.LayoutParams params); 828 829 /** 830 * Return the view in this Window that currently has focus, or null if 831 * there are none. Note that this does not look in any containing 832 * Window. 833 * 834 * @return View The current View with focus or null. 835 */ 836 public abstract View getCurrentFocus(); 837 838 /** 839 * Quick access to the {@link LayoutInflater} instance that this Window 840 * retrieved from its Context. 841 * 842 * @return LayoutInflater The shared LayoutInflater. 843 */ 844 public abstract LayoutInflater getLayoutInflater(); 845 846 public abstract void setTitle(CharSequence title); 847 848 public abstract void setTitleColor(int textColor); 849 850 public abstract void openPanel(int featureId, KeyEvent event); 851 852 public abstract void closePanel(int featureId); 853 854 public abstract void togglePanel(int featureId, KeyEvent event); 855 856 public abstract void invalidatePanelMenu(int featureId); 857 858 public abstract boolean performPanelShortcut(int featureId, 859 int keyCode, 860 KeyEvent event, 861 int flags); 862 public abstract boolean performPanelIdentifierAction(int featureId, 863 int id, 864 int flags); 865 866 public abstract void closeAllPanels(); 867 868 public abstract boolean performContextMenuIdentifierAction(int id, int flags); 869 870 /** 871 * Should be called when the configuration is changed. 872 * 873 * @param newConfig The new configuration. 874 */ 875 public abstract void onConfigurationChanged(Configuration newConfig); 876 877 /** 878 * Change the background of this window to a Drawable resource. Setting the 879 * background to null will make the window be opaque. To make the window 880 * transparent, you can use an empty drawable (for instance a ColorDrawable 881 * with the color 0 or the system drawable android:drawable/empty.) 882 * 883 * @param resid The resource identifier of a drawable resource which will be 884 * installed as the new background. 885 */ 886 public void setBackgroundDrawableResource(int resid) 887 { 888 setBackgroundDrawable(mContext.getResources().getDrawable(resid)); 889 } 890 891 /** 892 * Change the background of this window to a custom Drawable. Setting the 893 * background to null will make the window be opaque. To make the window 894 * transparent, you can use an empty drawable (for instance a ColorDrawable 895 * with the color 0 or the system drawable android:drawable/empty.) 896 * 897 * @param drawable The new Drawable to use for this window's background. 898 */ 899 public abstract void setBackgroundDrawable(Drawable drawable); 900 901 /** 902 * Set the value for a drawable feature of this window, from a resource 903 * identifier. You must have called requestFeauture(featureId) before 904 * calling this function. 905 * 906 * @see android.content.res.Resources#getDrawable(int) 907 * 908 * @param featureId The desired drawable feature to change, defined as a 909 * constant by Window. 910 * @param resId Resource identifier of the desired image. 911 */ 912 public abstract void setFeatureDrawableResource(int featureId, int resId); 913 914 /** 915 * Set the value for a drawable feature of this window, from a URI. You 916 * must have called requestFeature(featureId) before calling this 917 * function. 918 * 919 * <p>The only URI currently supported is "content:", specifying an image 920 * in a content provider. 921 * 922 * @see android.widget.ImageView#setImageURI 923 * 924 * @param featureId The desired drawable feature to change. Features are 925 * constants defined by Window. 926 * @param uri The desired URI. 927 */ 928 public abstract void setFeatureDrawableUri(int featureId, Uri uri); 929 930 /** 931 * Set an explicit Drawable value for feature of this window. You must 932 * have called requestFeature(featureId) before calling this function. 933 * 934 * @param featureId The desired drawable feature to change. 935 * Features are constants defined by Window. 936 * @param drawable A Drawable object to display. 937 */ 938 public abstract void setFeatureDrawable(int featureId, Drawable drawable); 939 940 /** 941 * Set a custom alpha value for the given drawale feature, controlling how 942 * much the background is visible through it. 943 * 944 * @param featureId The desired drawable feature to change. 945 * Features are constants defined by Window. 946 * @param alpha The alpha amount, 0 is completely transparent and 255 is 947 * completely opaque. 948 */ 949 public abstract void setFeatureDrawableAlpha(int featureId, int alpha); 950 951 /** 952 * Set the integer value for a feature. The range of the value depends on 953 * the feature being set. For FEATURE_PROGRESSS, it should go from 0 to 954 * 10000. At 10000 the progress is complete and the indicator hidden. 955 * 956 * @param featureId The desired feature to change. 957 * Features are constants defined by Window. 958 * @param value The value for the feature. The interpretation of this 959 * value is feature-specific. 960 */ 961 public abstract void setFeatureInt(int featureId, int value); 962 963 /** 964 * Request that key events come to this activity. Use this if your 965 * activity has no views with focus, but the activity still wants 966 * a chance to process key events. 967 */ 968 public abstract void takeKeyEvents(boolean get); 969 970 /** 971 * Used by custom windows, such as Dialog, to pass the key press event 972 * further down the view hierarchy. Application developers should 973 * not need to implement or call this. 974 * 975 */ 976 public abstract boolean superDispatchKeyEvent(KeyEvent event); 977 978 /** 979 * Used by custom windows, such as Dialog, to pass the touch screen event 980 * further down the view hierarchy. Application developers should 981 * not need to implement or call this. 982 * 983 */ 984 public abstract boolean superDispatchTouchEvent(MotionEvent event); 985 986 /** 987 * Used by custom windows, such as Dialog, to pass the trackball event 988 * further down the view hierarchy. Application developers should 989 * not need to implement or call this. 990 * 991 */ 992 public abstract boolean superDispatchTrackballEvent(MotionEvent event); 993 994 /** 995 * Retrieve the top-level window decor view (containing the standard 996 * window frame/decorations and the client's content inside of that), which 997 * can be added as a window to the window manager. 998 * 999 * <p><em>Note that calling this function for the first time "locks in" 1000 * various window characteristics as described in 1001 * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}.</em></p> 1002 * 1003 * @return Returns the top-level window decor view. 1004 */ 1005 public abstract View getDecorView(); 1006 1007 /** 1008 * Retrieve the current decor view, but only if it has already been created; 1009 * otherwise returns null. 1010 * 1011 * @return Returns the top-level window decor or null. 1012 * @see #getDecorView 1013 */ 1014 public abstract View peekDecorView(); 1015 1016 public abstract Bundle saveHierarchyState(); 1017 1018 public abstract void restoreHierarchyState(Bundle savedInstanceState); 1019 1020 protected abstract void onActive(); 1021 1022 /** 1023 * Return the feature bits that are enabled. This is the set of features 1024 * that were given to requestFeature(), and are being handled by this 1025 * Window itself or its container. That is, it is the set of 1026 * requested features that you can actually use. 1027 * 1028 * <p>To do: add a public version of this API that allows you to check for 1029 * features by their feature ID. 1030 * 1031 * @return int The feature bits. 1032 */ 1033 protected final int getFeatures() 1034 { 1035 return mFeatures; 1036 } 1037 1038 /** 1039 * Query for the availability of a certain feature. 1040 * 1041 * @param feature The feature ID to check 1042 * @return true if the feature is enabled, false otherwise. 1043 */ 1044 public boolean hasFeature(int feature) { 1045 return (getFeatures() & (1 << feature)) != 0; 1046 } 1047 1048 /** 1049 * Return the feature bits that are being implemented by this Window. 1050 * This is the set of features that were given to requestFeature(), and are 1051 * being handled by only this Window itself, not by its containers. 1052 * 1053 * @return int The feature bits. 1054 */ 1055 protected final int getLocalFeatures() 1056 { 1057 return mLocalFeatures; 1058 } 1059 1060 /** 1061 * Set the default format of window, as per the PixelFormat types. This 1062 * is the format that will be used unless the client specifies in explicit 1063 * format with setFormat(); 1064 * 1065 * @param format The new window format (see PixelFormat). 1066 * 1067 * @see #setFormat 1068 * @see PixelFormat 1069 */ 1070 protected void setDefaultWindowFormat(int format) { 1071 mDefaultWindowFormat = format; 1072 if (!mHaveWindowFormat) { 1073 final WindowManager.LayoutParams attrs = getAttributes(); 1074 attrs.format = format; 1075 if (mCallback != null) { 1076 mCallback.onWindowAttributesChanged(attrs); 1077 } 1078 } 1079 } 1080 1081 public abstract void setChildDrawable(int featureId, Drawable drawable); 1082 1083 public abstract void setChildInt(int featureId, int value); 1084 1085 /** 1086 * Is a keypress one of the defined shortcut keys for this window. 1087 * @param keyCode the key code from {@link android.view.KeyEvent} to check. 1088 * @param event the {@link android.view.KeyEvent} to use to help check. 1089 */ 1090 public abstract boolean isShortcutKey(int keyCode, KeyEvent event); 1091 1092 /** 1093 * @see android.app.Activity#setVolumeControlStream(int) 1094 */ 1095 public abstract void setVolumeControlStream(int streamType); 1096 1097 /** 1098 * @see android.app.Activity#getVolumeControlStream() 1099 */ 1100 public abstract int getVolumeControlStream(); 1101 1102} 1103