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