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