WindowManager.java revision 9266c558bf1d21ff647525ff99f7dadbca417309
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.graphics.PixelFormat; 20import android.os.IBinder; 21import android.os.Parcel; 22import android.os.Parcelable; 23import android.text.TextUtils; 24import android.util.Log; 25 26 27/** 28 * The interface that apps use to talk to the window manager. 29 * <p> 30 * Use <code>Context.getSystemService(Context.WINDOW_SERVICE)</code> to get one of these. 31 * 32 * @see android.content.Context#getSystemService 33 * @see android.content.Context#WINDOW_SERVICE 34 */ 35public interface WindowManager extends ViewManager { 36 /** 37 * Exception that is thrown when trying to add view whose 38 * {@link WindowManager.LayoutParams} {@link WindowManager.LayoutParams#token} 39 * is invalid. 40 */ 41 public static class BadTokenException extends RuntimeException { 42 public BadTokenException() { 43 } 44 45 public BadTokenException(String name) { 46 super(name); 47 } 48 } 49 50 /** 51 * Use this method to get the default Display object. 52 * 53 * @return default Display object 54 */ 55 public Display getDefaultDisplay(); 56 57 /** 58 * Special variation of {@link #removeView} that immediately invokes 59 * the given view hierarchy's {@link View#onDetachedFromWindow() 60 * View.onDetachedFromWindow()} methods before returning. This is not 61 * for normal applications; using it correctly requires great care. 62 * 63 * @param view The view to be removed. 64 */ 65 public void removeViewImmediate(View view); 66 67 public static class LayoutParams extends ViewGroup.LayoutParams 68 implements Parcelable { 69 /** 70 * X position for this window. With the default gravity it is ignored. 71 * When using {@link Gravity#LEFT} or {@link Gravity#RIGHT} it provides 72 * an offset from the given edge. 73 */ 74 public int x; 75 76 /** 77 * Y position for this window. With the default gravity it is ignored. 78 * When using {@link Gravity#TOP} or {@link Gravity#BOTTOM} it provides 79 * an offset from the given edge. 80 */ 81 public int y; 82 83 /** 84 * Indicates how much of the extra space will be allocated horizontally 85 * to the view associated with these LayoutParams. Specify 0 if the view 86 * should not be stretched. Otherwise the extra pixels will be pro-rated 87 * among all views whose weight is greater than 0. 88 */ 89 public float horizontalWeight; 90 91 /** 92 * Indicates how much of the extra space will be allocated vertically 93 * to the view associated with these LayoutParams. Specify 0 if the view 94 * should not be stretched. Otherwise the extra pixels will be pro-rated 95 * among all views whose weight is greater than 0. 96 */ 97 public float verticalWeight; 98 99 /** 100 * The general type of window. There are three main classes of 101 * window types: 102 * <ul> 103 * <li> <strong>Application windows</strong> (ranging from 104 * {@link #FIRST_APPLICATION_WINDOW} to 105 * {@link #LAST_APPLICATION_WINDOW}) are normal top-level application 106 * windows. For these types of windows, the {@link #token} must be 107 * set to the token of the activity they are a part of (this will 108 * normally be done for you if {@link #token} is null). 109 * <li> <strong>Sub-windows</strong> (ranging from 110 * {@link #FIRST_SUB_WINDOW} to 111 * {@link #LAST_SUB_WINDOW}) are associated with another top-level 112 * window. For these types of windows, the {@link #token} must be 113 * the token of the window it is attached to. 114 * <li> <strong>System windows</strong> (ranging from 115 * {@link #FIRST_SYSTEM_WINDOW} to 116 * {@link #LAST_SYSTEM_WINDOW}) are special types of windows for 117 * use by the system for specific purposes. They should not normally 118 * be used by applications, and a special permission is required 119 * to use them. 120 * </ul> 121 * 122 * @see #TYPE_BASE_APPLICATION 123 * @see #TYPE_APPLICATION 124 * @see #TYPE_APPLICATION_STARTING 125 * @see #TYPE_APPLICATION_PANEL 126 * @see #TYPE_APPLICATION_MEDIA 127 * @see #TYPE_APPLICATION_SUB_PANEL 128 * @see #TYPE_APPLICATION_ATTACHED_DIALOG 129 * @see #TYPE_INPUT_METHOD 130 * @see #TYPE_INPUT_METHOD_DIALOG 131 * @see #TYPE_STATUS_BAR 132 * @see #TYPE_SEARCH_BAR 133 * @see #TYPE_PHONE 134 * @see #TYPE_SYSTEM_ALERT 135 * @see #TYPE_KEYGUARD 136 * @see #TYPE_TOAST 137 * @see #TYPE_SYSTEM_OVERLAY 138 * @see #TYPE_PRIORITY_PHONE 139 * @see #TYPE_STATUS_BAR_PANEL 140 * @see #TYPE_SYSTEM_DIALOG 141 * @see #TYPE_KEYGUARD_DIALOG 142 * @see #TYPE_SYSTEM_ERROR 143 * @see #TYPE_INPUT_METHOD 144 * @see #TYPE_INPUT_METHOD_DIALOG 145 */ 146 public int type; 147 148 /** 149 * Start of window types that represent normal application windows. 150 */ 151 public static final int FIRST_APPLICATION_WINDOW = 1; 152 153 /** 154 * Window type: an application window that serves as the "base" window 155 * of the overall application; all other application windows will 156 * appear on top of it. 157 */ 158 public static final int TYPE_BASE_APPLICATION = 1; 159 160 /** 161 * Window type: a normal application window. The {@link #token} must be 162 * an Activity token identifying who the window belongs to. 163 */ 164 public static final int TYPE_APPLICATION = 2; 165 166 /** 167 * Window type: special application window that is displayed while the 168 * application is starting. Not for use by applications themselves; 169 * this is used by the system to display something until the 170 * application can show its own windows. 171 */ 172 public static final int TYPE_APPLICATION_STARTING = 3; 173 174 /** 175 * End of types of application windows. 176 */ 177 public static final int LAST_APPLICATION_WINDOW = 99; 178 179 /** 180 * Start of types of sub-windows. The {@link #token} of these windows 181 * must be set to the window they are attached to. These types of 182 * windows are kept next to their attached window in Z-order, and their 183 * coordinate space is relative to their attached window. 184 */ 185 public static final int FIRST_SUB_WINDOW = 1000; 186 187 /** 188 * Window type: a panel on top of an application window. These windows 189 * appear on top of their attached window. 190 */ 191 public static final int TYPE_APPLICATION_PANEL = FIRST_SUB_WINDOW; 192 193 /** 194 * Window type: window for showing media (e.g. video). These windows 195 * are displayed behind their attached window. 196 */ 197 public static final int TYPE_APPLICATION_MEDIA = FIRST_SUB_WINDOW+1; 198 199 /** 200 * Window type: a sub-panel on top of an application window. These 201 * windows are displayed on top their attached window and any 202 * {@link #TYPE_APPLICATION_PANEL} panels. 203 */ 204 public static final int TYPE_APPLICATION_SUB_PANEL = FIRST_SUB_WINDOW+2; 205 206 /** Window type: like {@link #TYPE_APPLICATION_PANEL}, but layout 207 * of the window happens as that of a top-level window, <em>not</em> 208 * as a child of its container. 209 */ 210 public static final int TYPE_APPLICATION_ATTACHED_DIALOG = FIRST_SUB_WINDOW+3; 211 212 /** 213 * End of types of sub-windows. 214 */ 215 public static final int LAST_SUB_WINDOW = 1999; 216 217 /** 218 * Start of system-specific window types. These are not normally 219 * created by applications. 220 */ 221 public static final int FIRST_SYSTEM_WINDOW = 2000; 222 223 /** 224 * Window type: the status bar. There can be only one status bar 225 * window; it is placed at the top of the screen, and all other 226 * windows are shifted down so they are below it. 227 */ 228 public static final int TYPE_STATUS_BAR = FIRST_SYSTEM_WINDOW; 229 230 /** 231 * Window type: the search bar. There can be only one search bar 232 * window; it is placed at the top of the screen. 233 */ 234 public static final int TYPE_SEARCH_BAR = FIRST_SYSTEM_WINDOW+1; 235 236 /** 237 * Window type: phone. These are non-application windows providing 238 * user interaction with the phone (in particular incoming calls). 239 * These windows are normally placed above all applications, but behind 240 * the status bar. 241 */ 242 public static final int TYPE_PHONE = FIRST_SYSTEM_WINDOW+2; 243 244 /** 245 * Window type: system window, such as low power alert. These windows 246 * are always on top of application windows. 247 */ 248 public static final int TYPE_SYSTEM_ALERT = FIRST_SYSTEM_WINDOW+3; 249 250 /** 251 * Window type: keyguard window. 252 */ 253 public static final int TYPE_KEYGUARD = FIRST_SYSTEM_WINDOW+4; 254 255 /** 256 * Window type: transient notifications. 257 */ 258 public static final int TYPE_TOAST = FIRST_SYSTEM_WINDOW+5; 259 260 /** 261 * Window type: system overlay windows, which need to be displayed 262 * on top of everything else. These windows must not take input 263 * focus, or they will interfere with the keyguard. 264 */ 265 public static final int TYPE_SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW+6; 266 267 /** 268 * Window type: priority phone UI, which needs to be displayed even if 269 * the keyguard is active. These windows must not take input 270 * focus, or they will interfere with the keyguard. 271 */ 272 public static final int TYPE_PRIORITY_PHONE = FIRST_SYSTEM_WINDOW+7; 273 274 /** 275 * Window type: panel that slides out from the status bar 276 */ 277 public static final int TYPE_STATUS_BAR_PANEL = FIRST_SYSTEM_WINDOW+8; 278 279 /** 280 * Window type: panel that slides out from the status bar 281 */ 282 public static final int TYPE_SYSTEM_DIALOG = FIRST_SYSTEM_WINDOW+8; 283 284 /** 285 * Window type: dialogs that the keyguard shows 286 */ 287 public static final int TYPE_KEYGUARD_DIALOG = FIRST_SYSTEM_WINDOW+9; 288 289 /** 290 * Window type: internal system error windows, appear on top of 291 * everything they can. 292 */ 293 public static final int TYPE_SYSTEM_ERROR = FIRST_SYSTEM_WINDOW+10; 294 295 /** 296 * Window type: internal input methods windows, which appear above 297 * the normal UI. Application windows may be resized or panned to keep 298 * the input focus visible while this window is displayed. 299 */ 300 public static final int TYPE_INPUT_METHOD = FIRST_SYSTEM_WINDOW+11; 301 302 /** 303 * Window type: internal input methods dialog windows, which appear above 304 * the current input method window. 305 */ 306 public static final int TYPE_INPUT_METHOD_DIALOG= FIRST_SYSTEM_WINDOW+12; 307 308 /** 309 * End of types of system windows. 310 */ 311 public static final int LAST_SYSTEM_WINDOW = 2999; 312 313 /** 314 * Specifies what type of memory buffers should be used by this window. 315 * Default is normal. 316 * 317 * @see #MEMORY_TYPE_NORMAL 318 * @see #MEMORY_TYPE_HARDWARE 319 * @see #MEMORY_TYPE_GPU 320 * @see #MEMORY_TYPE_PUSH_BUFFERS 321 */ 322 public int memoryType; 323 324 /** Memory type: The window's surface is allocated in main memory. */ 325 public static final int MEMORY_TYPE_NORMAL = 0; 326 /** Memory type: The window's surface is configured to be accessible 327 * by DMA engines and hardware accelerators. */ 328 public static final int MEMORY_TYPE_HARDWARE = 1; 329 /** Memory type: The window's surface is configured to be accessible 330 * by graphics accelerators. */ 331 public static final int MEMORY_TYPE_GPU = 2; 332 /** Memory type: The window's surface doesn't own its buffers and 333 * therefore cannot be locked. Instead the buffers are pushed to 334 * it through native binder calls. */ 335 public static final int MEMORY_TYPE_PUSH_BUFFERS = 3; 336 337 /** 338 * Various behavioral options/flags. Default is none. 339 * 340 * @see #FLAG_BLUR_BEHIND 341 * @see #FLAG_DIM_BEHIND 342 * @see #FLAG_NOT_FOCUSABLE 343 * @see #FLAG_NOT_TOUCHABLE 344 * @see #FLAG_NOT_TOUCH_MODAL 345 * @see #FLAG_LAYOUT_IN_SCREEN 346 * @see #FLAG_DITHER 347 * @see #FLAG_KEEP_SCREEN_ON 348 * @see #FLAG_FULLSCREEN 349 * @see #FLAG_FORCE_NOT_FULLSCREEN 350 * @see #FLAG_IGNORE_CHEEK_PRESSES 351 */ 352 public int flags; 353 354 /** Window flag: everything behind this window will be dimmed. 355 * Use {@link #dimAmount} to control the amount of dim. */ 356 public static final int FLAG_DIM_BEHIND = 0x00000002; 357 358 /** Window flag: blur everything behind this window. */ 359 public static final int FLAG_BLUR_BEHIND = 0x00000004; 360 361 /** Window flag: this window won't ever get key input focus, so the 362 * user can not send key or other button events to it. Those will 363 * instead go to whatever focusable window is behind it. This flag 364 * will also enable {@link #FLAG_NOT_TOUCH_MODAL} whether or not that 365 * is explicitly set. 366 * 367 * <p>Setting this flag also implies that the window will not need to 368 * interact with 369 * a soft input method, so it will be Z-ordered and positioned 370 * independently of any active input method (typically this means it 371 * gets Z-ordered on top of the input method, so it can use the full 372 * screen for its content and cover the input method if needed. You 373 * can use {@link #FLAG_ALT_FOCUSABLE_IM} to modify this behavior. */ 374 public static final int FLAG_NOT_FOCUSABLE = 0x00000008; 375 376 /** Window flag: this window can never receive touch events. */ 377 public static final int FLAG_NOT_TOUCHABLE = 0x00000010; 378 379 /** Window flag: Even when this window is focusable (its 380 * {@link #FLAG_NOT_FOCUSABLE is not set), allow any pointer events 381 * outside of the window to be sent to the windows behind it. Otherwise 382 * it will consume all pointer events itself, regardless of whether they 383 * are inside of the window. */ 384 public static final int FLAG_NOT_TOUCH_MODAL = 0x00000020; 385 386 /** Window flag: When set, if the device is asleep when the touch 387 * screen is pressed, you will receive this first touch event. Usually 388 * the first touch event is consumed by the system since the user can 389 * not see what they are pressing on. 390 */ 391 public static final int FLAG_TOUCHABLE_WHEN_WAKING = 0x00000040; 392 393 /** Window flag: as long as this window is visible to the user, keep 394 * the device's screen turned on and bright. */ 395 public static final int FLAG_KEEP_SCREEN_ON = 0x00000080; 396 397 /** Window flag: place the window within the entire screen, ignoring 398 * decorations around the border (a.k.a. the status bar). The 399 * window must correctly position its contents to take the screen 400 * decoration into account. This flag is normally set for you 401 * by Window as described in {@link Window#setFlags}. */ 402 public static final int FLAG_LAYOUT_IN_SCREEN = 0x00000100; 403 404 /** Window flag: allow window to extend outside of the screen. */ 405 public static final int FLAG_LAYOUT_NO_LIMITS = 0x00000200; 406 407 /** Window flag: Hide all screen decorations (e.g. status bar) while 408 * this window is displayed. This allows the window to use the entire 409 * display space for itself -- the status bar will be hidden when 410 * an app window with this flag set is on the top layer. */ 411 public static final int FLAG_FULLSCREEN = 0x00000400; 412 413 /** Window flag: Override {@link #FLAG_FULLSCREEN and force the 414 * screen decorations (such as status bar) to be shown. */ 415 public static final int FLAG_FORCE_NOT_FULLSCREEN = 0x00000800; 416 417 /** Window flag: turn on dithering when compositing this window to 418 * the screen. */ 419 public static final int FLAG_DITHER = 0x00001000; 420 421 /** Window flag: don't allow screen shots while this window is 422 * displayed. */ 423 public static final int FLAG_SECURE = 0x00002000; 424 425 /** Window flag: a special mode where the layout parameters are used 426 * to perform scaling of the surface when it is composited to the 427 * screen. */ 428 public static final int FLAG_SCALED = 0x00004000; 429 430 /** Window flag: intended for windows that will often be used when the user is 431 * holding the screen against their face, it will aggressively filter the event 432 * stream to prevent unintended presses in this situation that may not be 433 * desired for a particular window, when such an event stream is detected, the 434 * application will receive a CANCEL motion event to indicate this so applications 435 * can handle this accordingly by taking no action on the event 436 * until the finger is released. */ 437 public static final int FLAG_IGNORE_CHEEK_PRESSES = 0x00008000; 438 439 /** Window flag: a special option only for use in combination with 440 * {@link #FLAG_LAYOUT_IN_SCREEN}. When requesting layout in the 441 * screen your window may appear on top of or behind screen decorations 442 * such as the status bar. By also including this flag, the window 443 * manager will report the inset rectangle needed to ensure your 444 * content is not covered by screen decorations. This flag is normally 445 * set for you by Window as described in {@link Window#setFlags}.*/ 446 public static final int FLAG_LAYOUT_INSET_DECOR = 0x00010000; 447 448 /** Window flag: invert the state of {@link #FLAG_NOT_FOCUSABLE} with 449 * respect to how this window interacts with the current method. That 450 * is, if FLAG_NOT_FOCUSABLE is set and this flag is set, then the 451 * window will behave as if it needs to interact with the input method 452 * and thus be placed behind/away from it; if FLAG_NOT_FOCUSABLE is 453 * not set and this flag is set, then the window will behave as if it 454 * doesn't need to interact with the input method and can be placed 455 * to use more space and cover the input method. 456 */ 457 public static final int FLAG_ALT_FOCUSABLE_IM = 0x00020000; 458 459 /** Window flag: if you have set {@link #FLAG_NOT_TOUCH_MODAL}, you 460 * can set this flag to receive a single special MotionEvent with 461 * the action 462 * {@link MotionEvent#ACTION_OUTSIDE MotionEvent.ACTION_OUTSIDE} for 463 * touches that occur outside of your window. Note that you will not 464 * receive the full down/move/up gesture, only the location of the 465 * first down as an ACTION_OUTSIDE. 466 */ 467 public static final int FLAG_WATCH_OUTSIDE_TOUCH = 0x00040000; 468 469 /** Window flag: a special option intended for system dialogs. When 470 * this flag is set, the window will demand focus unconditionally when 471 * it is created. 472 * {@hide} */ 473 public static final int FLAG_SYSTEM_ERROR = 0x40000000; 474 475 /** 476 * Given a particular set of window manager flags, determine whether 477 * such a window may be a target for an input method when it has 478 * focus. In particular, this checks the 479 * {@link #FLAG_NOT_FOCUSABLE} and {@link #FLAG_ALT_FOCUSABLE_IM} 480 * flags and returns true if the combination of the two corresponds 481 * to a window that needs to be behind the input method so that the 482 * user can type into it. 483 * 484 * @param flags The current window manager flags. 485 * 486 * @return Returns true if such a window should be behind/interact 487 * with an input method, false if not. 488 */ 489 public static boolean mayUseInputMethod(int flags) { 490 switch (flags&(FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) { 491 case 0: 492 case FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM: 493 return true; 494 } 495 return false; 496 } 497 498 /** 499 * Mask for {@link #softInputMode} of the bits that determine the 500 * desired visibility state of the soft input area for this window. 501 */ 502 public static final int SOFT_INPUT_MASK_STATE = 0x0f; 503 504 /** 505 * Visibility state for {@link #softInputMode}: no state has been specified. 506 */ 507 public static final int SOFT_INPUT_STATE_UNSPECIFIED = 0; 508 509 /** 510 * Visibility state for {@link #softInputMode}: please don't change the state of 511 * the soft input area. 512 */ 513 public static final int SOFT_INPUT_STATE_UNCHANGED = 1; 514 515 /** 516 * Visibility state for {@link #softInputMode}: please hide any soft input 517 * area. 518 */ 519 public static final int SOFT_INPUT_STATE_HIDDEN = 2; 520 521 /** 522 * Visibility state for {@link #softInputMode}: please show the soft 523 * input area when normally appropriate (when the user is navigating 524 * forward to your window). 525 */ 526 public static final int SOFT_INPUT_STATE_VISIBLE = 3; 527 528 /** 529 * Visibility state for {@link #softInputMode}: please always make the 530 * soft input area visible when this window receives input focus. 531 */ 532 public static final int SOFT_INPUT_STATE_ALWAYS_VISIBLE = 4; 533 534 /** 535 * Mask for {@link #softInputMode} of the bits that determine the 536 * way that the window should be adjusted to accomodate the soft 537 * input window. 538 */ 539 public static final int SOFT_INPUT_MASK_ADJUST = 0xf0; 540 541 /** Adjustment option for {@link #softInputMode}: nothing specified. 542 * The system will try to pick one or 543 * the other depending on the contents of the window. 544 */ 545 public static final int SOFT_INPUT_ADJUST_UNSPECIFIED = 0x00; 546 547 /** Adjustment option for {@link #softInputMode}: set to allow the 548 * window to be resized when an input 549 * method is shown, so that its contents are not covered by the input 550 * method. This can <em>not<em> be combined with 551 * {@link #SOFT_INPUT_ADJUST_PAN}; if 552 * neither of these are set, then the system will try to pick one or 553 * the other depending on the contents of the window. 554 */ 555 public static final int SOFT_INPUT_ADJUST_RESIZE = 0x10; 556 557 /** Adjustment option for {@link #softInputMode}: set to have a window 558 * pan when an input method is 559 * shown, so it doesn't need to deal with resizing but just panned 560 * by the framework to ensure the current input focus is visible. This 561 * can <em>not<em> be combined with {@link #SOFT_INPUT_ADJUST_RESIZE}; if 562 * neither of these are set, then the system will try to pick one or 563 * the other depending on the contents of the window. 564 */ 565 public static final int SOFT_INPUT_ADJUST_PAN = 0x20; 566 567 /** 568 * Bit for {@link #softInputMode}: set when the user has navigated 569 * forward to the window. This is normally set automatically for 570 * you by the system, though you may want to set it in certain cases 571 * when you are displaying a window yourself. This flag will always 572 * be cleared automatically after the window is displayed. 573 */ 574 public static final int SOFT_INPUT_IS_FORWARD_NAVIGATION = 0x100; 575 576 /** 577 * Desired operating mode for any soft input area. May any combination 578 * of: 579 * 580 * <ul> 581 * <li> One of the visibility states 582 * {@link #SOFT_INPUT_STATE_UNSPECIFIED}, {@link #SOFT_INPUT_STATE_UNCHANGED}, 583 * {@link #SOFT_INPUT_STATE_HIDDEN}, {@link #SOFT_INPUT_STATE_ALWAYS_VISIBLE}, or 584 * {@link #SOFT_INPUT_STATE_VISIBLE}. 585 * <li> One of the adjustment options 586 * {@link #SOFT_INPUT_ADJUST_UNSPECIFIED}, 587 * {@link #SOFT_INPUT_ADJUST_RESIZE}, or 588 * {@link #SOFT_INPUT_ADJUST_PAN}. 589 */ 590 public int softInputMode; 591 592 /** 593 * Placement of window within the screen as per {@link Gravity} 594 * 595 * @see Gravity 596 */ 597 public int gravity; 598 599 /** 600 * The horizontal margin, as a percentage of the container's width, 601 * between the container and the widget. 602 */ 603 public float horizontalMargin; 604 605 /** 606 * The vertical margin, as a percentage of the container's height, 607 * between the container and the widget. 608 */ 609 public float verticalMargin; 610 611 /** 612 * The desired bitmap format. May be one of the constants in 613 * {@link android.graphics.PixelFormat}. Default is OPAQUE. 614 */ 615 public int format; 616 617 /** 618 * A style resource defining the animations to use for this window. 619 * This must be a system resource; it can not be an application resource 620 * because the window manager does not have access to applications. 621 */ 622 public int windowAnimations; 623 624 /** 625 * An alpha value to apply to this entire window. 626 * An alpha of 1.0 means fully opaque and 0.0 means fully transparent 627 */ 628 public float alpha = 1.0f; 629 630 /** 631 * When {@link #FLAG_DIM_BEHIND} is set, this is the amount of dimming 632 * to apply. Range is from 1.0 for completely opaque to 0.0 for no 633 * dim. 634 */ 635 public float dimAmount = 1.0f; 636 637 /** 638 * Identifier for this window. This will usually be filled in for 639 * you. 640 */ 641 public IBinder token = null; 642 643 /** 644 * Name of the package owning this window. 645 */ 646 public String packageName = null; 647 648 public LayoutParams() { 649 super(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); 650 type = TYPE_APPLICATION; 651 format = PixelFormat.OPAQUE; 652 } 653 654 public LayoutParams(int _type) { 655 super(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); 656 type = _type; 657 format = PixelFormat.OPAQUE; 658 } 659 660 public LayoutParams(int _type, int _flags) { 661 super(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); 662 type = _type; 663 flags = _flags; 664 format = PixelFormat.OPAQUE; 665 } 666 667 public LayoutParams(int _type, int _flags, int _format) { 668 super(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); 669 type = _type; 670 flags = _flags; 671 format = _format; 672 } 673 674 public LayoutParams(int w, int h, int _type, int _flags, int _format) { 675 super(w, h); 676 type = _type; 677 flags = _flags; 678 format = _format; 679 } 680 681 public LayoutParams(int w, int h, int xpos, int ypos, int _type, 682 int _flags, int _format) { 683 super(w, h); 684 x = xpos; 685 y = ypos; 686 type = _type; 687 flags = _flags; 688 format = _format; 689 } 690 691 public final void setTitle(CharSequence title) { 692 if (null == title) 693 title = ""; 694 695 mTitle = TextUtils.stringOrSpannedString(title); 696 } 697 698 public final CharSequence getTitle() { 699 return mTitle; 700 } 701 702 public int describeContents() { 703 return 0; 704 } 705 706 public void writeToParcel(Parcel out, int parcelableFlags) { 707 out.writeInt(width); 708 out.writeInt(height); 709 out.writeInt(x); 710 out.writeInt(y); 711 out.writeInt(type); 712 out.writeInt(memoryType); 713 out.writeInt(flags); 714 out.writeInt(softInputMode); 715 out.writeInt(gravity); 716 out.writeFloat(horizontalMargin); 717 out.writeFloat(verticalMargin); 718 out.writeInt(format); 719 out.writeInt(windowAnimations); 720 out.writeFloat(alpha); 721 out.writeFloat(dimAmount); 722 out.writeStrongBinder(token); 723 out.writeString(packageName); 724 TextUtils.writeToParcel(mTitle, out, parcelableFlags); 725 } 726 727 public static final Parcelable.Creator<LayoutParams> CREATOR 728 = new Parcelable.Creator<LayoutParams>() { 729 public LayoutParams createFromParcel(Parcel in) { 730 return new LayoutParams(in); 731 } 732 733 public LayoutParams[] newArray(int size) { 734 return new LayoutParams[size]; 735 } 736 }; 737 738 739 public LayoutParams(Parcel in) { 740 width = in.readInt(); 741 height = in.readInt(); 742 x = in.readInt(); 743 y = in.readInt(); 744 type = in.readInt(); 745 memoryType = in.readInt(); 746 flags = in.readInt(); 747 softInputMode = in.readInt(); 748 gravity = in.readInt(); 749 horizontalMargin = in.readFloat(); 750 verticalMargin = in.readFloat(); 751 format = in.readInt(); 752 windowAnimations = in.readInt(); 753 alpha = in.readFloat(); 754 dimAmount = in.readFloat(); 755 token = in.readStrongBinder(); 756 packageName = in.readString(); 757 mTitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); 758 } 759 760 public static final int LAYOUT_CHANGED = 1<<0; 761 public static final int TYPE_CHANGED = 1<<1; 762 public static final int FLAGS_CHANGED = 1<<2; 763 public static final int FORMAT_CHANGED = 1<<3; 764 public static final int ANIMATION_CHANGED = 1<<4; 765 public static final int DIM_AMOUNT_CHANGED = 1<<5; 766 public static final int TITLE_CHANGED = 1<<6; 767 public static final int ALPHA_CHANGED = 1<<7; 768 public static final int MEMORY_TYPE_CHANGED = 1<<8; 769 public static final int SOFT_INPUT_MODE_CHANGED = 1<<9; 770 771 public final int copyFrom(LayoutParams o) { 772 int changes = 0; 773 774 if (width != o.width) { 775 width = o.width; 776 changes |= LAYOUT_CHANGED; 777 } 778 if (height != o.height) { 779 height = o.height; 780 changes |= LAYOUT_CHANGED; 781 } 782 if (x != o.x) { 783 x = o.x; 784 changes |= LAYOUT_CHANGED; 785 } 786 if (y != o.y) { 787 y = o.y; 788 changes |= LAYOUT_CHANGED; 789 } 790 if (horizontalWeight != o.horizontalWeight) { 791 horizontalWeight = o.horizontalWeight; 792 changes |= LAYOUT_CHANGED; 793 } 794 if (verticalWeight != o.verticalWeight) { 795 verticalWeight = o.verticalWeight; 796 changes |= LAYOUT_CHANGED; 797 } 798 if (horizontalMargin != o.horizontalMargin) { 799 horizontalMargin = o.horizontalMargin; 800 changes |= LAYOUT_CHANGED; 801 } 802 if (verticalMargin != o.verticalMargin) { 803 verticalMargin = o.verticalMargin; 804 changes |= LAYOUT_CHANGED; 805 } 806 if (type != o.type) { 807 type = o.type; 808 changes |= TYPE_CHANGED; 809 } 810 if (memoryType != o.memoryType) { 811 memoryType = o.memoryType; 812 changes |= MEMORY_TYPE_CHANGED; 813 } 814 if (flags != o.flags) { 815 flags = o.flags; 816 changes |= FLAGS_CHANGED; 817 } 818 if (softInputMode != o.softInputMode) { 819 softInputMode = o.softInputMode; 820 changes |= SOFT_INPUT_MODE_CHANGED; 821 } 822 if (gravity != o.gravity) { 823 gravity = o.gravity; 824 changes |= LAYOUT_CHANGED; 825 } 826 if (horizontalMargin != o.horizontalMargin) { 827 horizontalMargin = o.horizontalMargin; 828 changes |= LAYOUT_CHANGED; 829 } 830 if (verticalMargin != o.verticalMargin) { 831 verticalMargin = o.verticalMargin; 832 changes |= LAYOUT_CHANGED; 833 } 834 if (format != o.format) { 835 format = o.format; 836 changes |= FORMAT_CHANGED; 837 } 838 if (windowAnimations != o.windowAnimations) { 839 windowAnimations = o.windowAnimations; 840 changes |= ANIMATION_CHANGED; 841 } 842 if (token == null) { 843 // NOTE: token only copied if the recipient doesn't 844 // already have one. 845 token = o.token; 846 } 847 if (packageName == null) { 848 // NOTE: packageName only copied if the recipient doesn't 849 // already have one. 850 packageName = o.packageName; 851 } 852 if (!mTitle.equals(o.mTitle)) { 853 mTitle = o.mTitle; 854 changes |= TITLE_CHANGED; 855 } 856 if (alpha != o.alpha) { 857 alpha = o.alpha; 858 changes |= ALPHA_CHANGED; 859 } 860 if (dimAmount != o.dimAmount) { 861 dimAmount = o.dimAmount; 862 changes |= DIM_AMOUNT_CHANGED; 863 } 864 865 return changes; 866 } 867 868 @Override 869 public String debug(String output) { 870 output += "Contents of " + this + ":"; 871 Log.d("Debug", output); 872 output = super.debug(""); 873 Log.d("Debug", output); 874 Log.d("Debug", ""); 875 Log.d("Debug", "WindowManager.LayoutParams={title=" + mTitle + "}"); 876 return ""; 877 } 878 879 @Override 880 public String toString() { 881 StringBuilder sb = new StringBuilder(256); 882 sb.append("WM.LayoutParams{"); 883 sb.append("("); 884 sb.append(x); 885 sb.append(','); 886 sb.append(y); 887 sb.append(")("); 888 sb.append((width==FILL_PARENT?"fill":(width==WRAP_CONTENT?"wrap":width))); 889 sb.append('x'); 890 sb.append((height==FILL_PARENT?"fill":(height==WRAP_CONTENT?"wrap":height))); 891 sb.append(")"); 892 if (softInputMode != 0) { 893 sb.append(" sim=#"); 894 sb.append(Integer.toHexString(softInputMode)); 895 } 896 if (gravity != 0) { 897 sb.append(" gr=#"); 898 sb.append(Integer.toHexString(gravity)); 899 } 900 sb.append(" ty="); 901 sb.append(type); 902 sb.append(" fl=#"); 903 sb.append(Integer.toHexString(flags)); 904 sb.append(" fmt="); 905 sb.append(format); 906 if (windowAnimations != 0) { 907 sb.append(" wanim=0x"); 908 sb.append(Integer.toHexString(windowAnimations)); 909 } 910 sb.append('}'); 911 return sb.toString(); 912 } 913 914 private CharSequence mTitle = ""; 915 } 916} 917