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