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