WindowManager.java revision 29d8d267dd97f66d829478778de5e0c56b965a47
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#START} or {@link Gravity#RIGHT} or 73 * {@link Gravity#END} it provides an offset from the given edge. 74 */ 75 @ViewDebug.ExportedProperty 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 @ViewDebug.ExportedProperty 84 public int y; 85 86 /** 87 * Indicates how much of the extra space will be allocated horizontally 88 * to the view associated with these LayoutParams. Specify 0 if the view 89 * should not be stretched. Otherwise the extra pixels will be pro-rated 90 * among all views whose weight is greater than 0. 91 */ 92 @ViewDebug.ExportedProperty 93 public float horizontalWeight; 94 95 /** 96 * Indicates how much of the extra space will be allocated vertically 97 * to the view associated with these LayoutParams. Specify 0 if the view 98 * should not be stretched. Otherwise the extra pixels will be pro-rated 99 * among all views whose weight is greater than 0. 100 */ 101 @ViewDebug.ExportedProperty 102 public float verticalWeight; 103 104 /** 105 * The general type of window. There are three main classes of 106 * window types: 107 * <ul> 108 * <li> <strong>Application windows</strong> (ranging from 109 * {@link #FIRST_APPLICATION_WINDOW} to 110 * {@link #LAST_APPLICATION_WINDOW}) are normal top-level application 111 * windows. For these types of windows, the {@link #token} must be 112 * set to the token of the activity they are a part of (this will 113 * normally be done for you if {@link #token} is null). 114 * <li> <strong>Sub-windows</strong> (ranging from 115 * {@link #FIRST_SUB_WINDOW} to 116 * {@link #LAST_SUB_WINDOW}) are associated with another top-level 117 * window. For these types of windows, the {@link #token} must be 118 * the token of the window it is attached to. 119 * <li> <strong>System windows</strong> (ranging from 120 * {@link #FIRST_SYSTEM_WINDOW} to 121 * {@link #LAST_SYSTEM_WINDOW}) are special types of windows for 122 * use by the system for specific purposes. They should not normally 123 * be used by applications, and a special permission is required 124 * to use them. 125 * </ul> 126 * 127 * @see #TYPE_BASE_APPLICATION 128 * @see #TYPE_APPLICATION 129 * @see #TYPE_APPLICATION_STARTING 130 * @see #TYPE_APPLICATION_PANEL 131 * @see #TYPE_APPLICATION_MEDIA 132 * @see #TYPE_APPLICATION_SUB_PANEL 133 * @see #TYPE_APPLICATION_ATTACHED_DIALOG 134 * @see #TYPE_STATUS_BAR 135 * @see #TYPE_SEARCH_BAR 136 * @see #TYPE_PHONE 137 * @see #TYPE_SYSTEM_ALERT 138 * @see #TYPE_KEYGUARD 139 * @see #TYPE_TOAST 140 * @see #TYPE_SYSTEM_OVERLAY 141 * @see #TYPE_PRIORITY_PHONE 142 * @see #TYPE_STATUS_BAR_PANEL 143 * @see #TYPE_SYSTEM_DIALOG 144 * @see #TYPE_KEYGUARD_DIALOG 145 * @see #TYPE_SYSTEM_ERROR 146 * @see #TYPE_INPUT_METHOD 147 * @see #TYPE_INPUT_METHOD_DIALOG 148 */ 149 @ViewDebug.ExportedProperty(mapping = { 150 @ViewDebug.IntToString(from = TYPE_BASE_APPLICATION, to = "TYPE_BASE_APPLICATION"), 151 @ViewDebug.IntToString(from = TYPE_APPLICATION, to = "TYPE_APPLICATION"), 152 @ViewDebug.IntToString(from = TYPE_APPLICATION_STARTING, to = "TYPE_APPLICATION_STARTING"), 153 @ViewDebug.IntToString(from = TYPE_APPLICATION_PANEL, to = "TYPE_APPLICATION_PANEL"), 154 @ViewDebug.IntToString(from = TYPE_APPLICATION_MEDIA, to = "TYPE_APPLICATION_MEDIA"), 155 @ViewDebug.IntToString(from = TYPE_APPLICATION_SUB_PANEL, to = "TYPE_APPLICATION_SUB_PANEL"), 156 @ViewDebug.IntToString(from = TYPE_APPLICATION_ATTACHED_DIALOG, to = "TYPE_APPLICATION_ATTACHED_DIALOG"), 157 @ViewDebug.IntToString(from = TYPE_APPLICATION_MEDIA_OVERLAY, to = "TYPE_APPLICATION_MEDIA_OVERLAY"), 158 @ViewDebug.IntToString(from = TYPE_STATUS_BAR, to = "TYPE_STATUS_BAR"), 159 @ViewDebug.IntToString(from = TYPE_SEARCH_BAR, to = "TYPE_SEARCH_BAR"), 160 @ViewDebug.IntToString(from = TYPE_PHONE, to = "TYPE_PHONE"), 161 @ViewDebug.IntToString(from = TYPE_SYSTEM_ALERT, to = "TYPE_SYSTEM_ALERT"), 162 @ViewDebug.IntToString(from = TYPE_KEYGUARD, to = "TYPE_KEYGUARD"), 163 @ViewDebug.IntToString(from = TYPE_TOAST, to = "TYPE_TOAST"), 164 @ViewDebug.IntToString(from = TYPE_SYSTEM_OVERLAY, to = "TYPE_SYSTEM_OVERLAY"), 165 @ViewDebug.IntToString(from = TYPE_PRIORITY_PHONE, to = "TYPE_PRIORITY_PHONE"), 166 @ViewDebug.IntToString(from = TYPE_SYSTEM_DIALOG, to = "TYPE_SYSTEM_DIALOG"), 167 @ViewDebug.IntToString(from = TYPE_KEYGUARD_DIALOG, to = "TYPE_KEYGUARD_DIALOG"), 168 @ViewDebug.IntToString(from = TYPE_SYSTEM_ERROR, to = "TYPE_SYSTEM_ERROR"), 169 @ViewDebug.IntToString(from = TYPE_INPUT_METHOD, to = "TYPE_INPUT_METHOD"), 170 @ViewDebug.IntToString(from = TYPE_INPUT_METHOD_DIALOG, to = "TYPE_INPUT_METHOD_DIALOG"), 171 @ViewDebug.IntToString(from = TYPE_WALLPAPER, to = "TYPE_WALLPAPER"), 172 @ViewDebug.IntToString(from = TYPE_STATUS_BAR_PANEL, to = "TYPE_STATUS_BAR_PANEL"), 173 @ViewDebug.IntToString(from = TYPE_SECURE_SYSTEM_OVERLAY, to = "TYPE_SECURE_SYSTEM_OVERLAY"), 174 @ViewDebug.IntToString(from = TYPE_DRAG, to = "TYPE_DRAG"), 175 @ViewDebug.IntToString(from = TYPE_STATUS_BAR_SUB_PANEL, to = "TYPE_STATUS_BAR_SUB_PANEL"), 176 @ViewDebug.IntToString(from = TYPE_POINTER, to = "TYPE_POINTER"), 177 @ViewDebug.IntToString(from = TYPE_NAVIGATION_BAR, to = "TYPE_NAVIGATION_BAR"), 178 @ViewDebug.IntToString(from = TYPE_VOLUME_OVERLAY, to = "TYPE_VOLUME_OVERLAY"), 179 @ViewDebug.IntToString(from = TYPE_BOOT_PROGRESS, to = "TYPE_BOOT_PROGRESS"), 180 @ViewDebug.IntToString(from = TYPE_HIDDEN_NAV_CONSUMER, to = "TYPE_HIDDEN_NAV_CONSUMER"), 181 @ViewDebug.IntToString(from = TYPE_DREAM, to = "TYPE_DREAM"), 182 @ViewDebug.IntToString(from = TYPE_NAVIGATION_BAR_PANEL, to = "TYPE_NAVIGATION_BAR_PANEL"), 183 @ViewDebug.IntToString(from = TYPE_DISPLAY_OVERLAY, to = "TYPE_DISPLAY_OVERLAY") 184 }) 185 public int type; 186 187 /** 188 * Start of window types that represent normal application windows. 189 */ 190 public static final int FIRST_APPLICATION_WINDOW = 1; 191 192 /** 193 * Window type: an application window that serves as the "base" window 194 * of the overall application; all other application windows will 195 * appear on top of it. 196 */ 197 public static final int TYPE_BASE_APPLICATION = 1; 198 199 /** 200 * Window type: a normal application window. The {@link #token} must be 201 * an Activity token identifying who the window belongs to. 202 */ 203 public static final int TYPE_APPLICATION = 2; 204 205 /** 206 * Window type: special application window that is displayed while the 207 * application is starting. Not for use by applications themselves; 208 * this is used by the system to display something until the 209 * application can show its own windows. 210 */ 211 public static final int TYPE_APPLICATION_STARTING = 3; 212 213 /** 214 * End of types of application windows. 215 */ 216 public static final int LAST_APPLICATION_WINDOW = 99; 217 218 /** 219 * Start of types of sub-windows. The {@link #token} of these windows 220 * must be set to the window they are attached to. These types of 221 * windows are kept next to their attached window in Z-order, and their 222 * coordinate space is relative to their attached window. 223 */ 224 public static final int FIRST_SUB_WINDOW = 1000; 225 226 /** 227 * Window type: a panel on top of an application window. These windows 228 * appear on top of their attached window. 229 */ 230 public static final int TYPE_APPLICATION_PANEL = FIRST_SUB_WINDOW; 231 232 /** 233 * Window type: window for showing media (e.g. video). These windows 234 * are displayed behind their attached window. 235 */ 236 public static final int TYPE_APPLICATION_MEDIA = FIRST_SUB_WINDOW+1; 237 238 /** 239 * Window type: a sub-panel on top of an application window. These 240 * windows are displayed on top their attached window and any 241 * {@link #TYPE_APPLICATION_PANEL} panels. 242 */ 243 public static final int TYPE_APPLICATION_SUB_PANEL = FIRST_SUB_WINDOW+2; 244 245 /** Window type: like {@link #TYPE_APPLICATION_PANEL}, but layout 246 * of the window happens as that of a top-level window, <em>not</em> 247 * as a child of its container. 248 */ 249 public static final int TYPE_APPLICATION_ATTACHED_DIALOG = FIRST_SUB_WINDOW+3; 250 251 /** 252 * Window type: window for showing overlays on top of media windows. 253 * These windows are displayed between TYPE_APPLICATION_MEDIA and the 254 * application window. They should be translucent to be useful. This 255 * is a big ugly hack so: 256 * @hide 257 */ 258 public static final int TYPE_APPLICATION_MEDIA_OVERLAY = FIRST_SUB_WINDOW+4; 259 260 /** 261 * End of types of sub-windows. 262 */ 263 public static final int LAST_SUB_WINDOW = 1999; 264 265 /** 266 * Start of system-specific window types. These are not normally 267 * created by applications. 268 */ 269 public static final int FIRST_SYSTEM_WINDOW = 2000; 270 271 /** 272 * Window type: the status bar. There can be only one status bar 273 * window; it is placed at the top of the screen, and all other 274 * windows are shifted down so they are below it. 275 */ 276 public static final int TYPE_STATUS_BAR = FIRST_SYSTEM_WINDOW; 277 278 /** 279 * Window type: the search bar. There can be only one search bar 280 * window; it is placed at the top of the screen. 281 */ 282 public static final int TYPE_SEARCH_BAR = FIRST_SYSTEM_WINDOW+1; 283 284 /** 285 * Window type: phone. These are non-application windows providing 286 * user interaction with the phone (in particular incoming calls). 287 * These windows are normally placed above all applications, but behind 288 * the status bar. 289 */ 290 public static final int TYPE_PHONE = FIRST_SYSTEM_WINDOW+2; 291 292 /** 293 * Window type: system window, such as low power alert. These windows 294 * are always on top of application windows. 295 */ 296 public static final int TYPE_SYSTEM_ALERT = FIRST_SYSTEM_WINDOW+3; 297 298 /** 299 * Window type: keyguard window. 300 */ 301 public static final int TYPE_KEYGUARD = FIRST_SYSTEM_WINDOW+4; 302 303 /** 304 * Window type: transient notifications. 305 */ 306 public static final int TYPE_TOAST = FIRST_SYSTEM_WINDOW+5; 307 308 /** 309 * Window type: system overlay windows, which need to be displayed 310 * on top of everything else. These windows must not take input 311 * focus, or they will interfere with the keyguard. 312 */ 313 public static final int TYPE_SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW+6; 314 315 /** 316 * Window type: priority phone UI, which needs to be displayed even if 317 * the keyguard is active. These windows must not take input 318 * focus, or they will interfere with the keyguard. 319 */ 320 public static final int TYPE_PRIORITY_PHONE = FIRST_SYSTEM_WINDOW+7; 321 322 /** 323 * Window type: panel that slides out from the status bar 324 */ 325 public static final int TYPE_SYSTEM_DIALOG = FIRST_SYSTEM_WINDOW+8; 326 327 /** 328 * Window type: dialogs that the keyguard shows 329 */ 330 public static final int TYPE_KEYGUARD_DIALOG = FIRST_SYSTEM_WINDOW+9; 331 332 /** 333 * Window type: internal system error windows, appear on top of 334 * everything they can. 335 */ 336 public static final int TYPE_SYSTEM_ERROR = FIRST_SYSTEM_WINDOW+10; 337 338 /** 339 * Window type: internal input methods windows, which appear above 340 * the normal UI. Application windows may be resized or panned to keep 341 * the input focus visible while this window is displayed. 342 */ 343 public static final int TYPE_INPUT_METHOD = FIRST_SYSTEM_WINDOW+11; 344 345 /** 346 * Window type: internal input methods dialog windows, which appear above 347 * the current input method window. 348 */ 349 public static final int TYPE_INPUT_METHOD_DIALOG= FIRST_SYSTEM_WINDOW+12; 350 351 /** 352 * Window type: wallpaper window, placed behind any window that wants 353 * to sit on top of the wallpaper. 354 */ 355 public static final int TYPE_WALLPAPER = FIRST_SYSTEM_WINDOW+13; 356 357 /** 358 * Window type: panel that slides out from over the status bar 359 */ 360 public static final int TYPE_STATUS_BAR_PANEL = FIRST_SYSTEM_WINDOW+14; 361 362 /** 363 * Window type: secure system overlay windows, which need to be displayed 364 * on top of everything else. These windows must not take input 365 * focus, or they will interfere with the keyguard. 366 * 367 * This is exactly like {@link #TYPE_SYSTEM_OVERLAY} except that only the 368 * system itself is allowed to create these overlays. Applications cannot 369 * obtain permission to create secure system overlays. 370 * @hide 371 */ 372 public static final int TYPE_SECURE_SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW+15; 373 374 /** 375 * Window type: the drag-and-drop pseudowindow. There is only one 376 * drag layer (at most), and it is placed on top of all other windows. 377 * @hide 378 */ 379 public static final int TYPE_DRAG = FIRST_SYSTEM_WINDOW+16; 380 381 /** 382 * Window type: panel that slides out from under the status bar 383 * @hide 384 */ 385 public static final int TYPE_STATUS_BAR_SUB_PANEL = FIRST_SYSTEM_WINDOW+17; 386 387 /** 388 * Window type: (mouse) pointer 389 * @hide 390 */ 391 public static final int TYPE_POINTER = FIRST_SYSTEM_WINDOW+18; 392 393 /** 394 * Window type: Navigation bar (when distinct from status bar) 395 * @hide 396 */ 397 public static final int TYPE_NAVIGATION_BAR = FIRST_SYSTEM_WINDOW+19; 398 399 /** 400 * Window type: The volume level overlay/dialog shown when the user 401 * changes the system volume. 402 * @hide 403 */ 404 public static final int TYPE_VOLUME_OVERLAY = FIRST_SYSTEM_WINDOW+20; 405 406 /** 407 * Window type: The boot progress dialog, goes on top of everything 408 * in the world. 409 * @hide 410 */ 411 public static final int TYPE_BOOT_PROGRESS = FIRST_SYSTEM_WINDOW+21; 412 413 /** 414 * Window type: Fake window to consume touch events when the navigation 415 * bar is hidden. 416 * @hide 417 */ 418 public static final int TYPE_HIDDEN_NAV_CONSUMER = FIRST_SYSTEM_WINDOW+22; 419 420 /** 421 * Window type: Dreams (screen saver) window, just above keyguard. 422 * @hide 423 */ 424 public static final int TYPE_DREAM = FIRST_SYSTEM_WINDOW+23; 425 426 /** 427 * Window type: Navigation bar panel (when navigation bar is distinct from status bar) 428 * @hide 429 */ 430 public static final int TYPE_NAVIGATION_BAR_PANEL = FIRST_SYSTEM_WINDOW+24; 431 432 /** 433 * Window type: Behind the universe of the real windows. 434 * @hide 435 */ 436 public static final int TYPE_UNIVERSE_BACKGROUND = FIRST_SYSTEM_WINDOW+25; 437 438 /** 439 * Window type: Display overlay window. Used to simulate secondary display devices. 440 * @hide 441 */ 442 public static final int TYPE_DISPLAY_OVERLAY = FIRST_SYSTEM_WINDOW+26; 443 444 /** 445 * End of types of system windows. 446 */ 447 public static final int LAST_SYSTEM_WINDOW = 2999; 448 449 /** @deprecated this is ignored, this value is set automatically when needed. */ 450 @Deprecated 451 public static final int MEMORY_TYPE_NORMAL = 0; 452 /** @deprecated this is ignored, this value is set automatically when needed. */ 453 @Deprecated 454 public static final int MEMORY_TYPE_HARDWARE = 1; 455 /** @deprecated this is ignored, this value is set automatically when needed. */ 456 @Deprecated 457 public static final int MEMORY_TYPE_GPU = 2; 458 /** @deprecated this is ignored, this value is set automatically when needed. */ 459 @Deprecated 460 public static final int MEMORY_TYPE_PUSH_BUFFERS = 3; 461 462 /** 463 * @deprecated this is ignored 464 */ 465 @Deprecated 466 public int memoryType; 467 468 /** Window flag: as long as this window is visible to the user, allow 469 * the lock screen to activate while the screen is on. 470 * This can be used independently, or in combination with 471 * {@link #FLAG_KEEP_SCREEN_ON} and/or {@link #FLAG_SHOW_WHEN_LOCKED} */ 472 public static final int FLAG_ALLOW_LOCK_WHILE_SCREEN_ON = 0x00000001; 473 474 /** Window flag: everything behind this window will be dimmed. 475 * Use {@link #dimAmount} to control the amount of dim. */ 476 public static final int FLAG_DIM_BEHIND = 0x00000002; 477 478 /** Window flag: blur everything behind this window. 479 * @deprecated Blurring is no longer supported. */ 480 @Deprecated 481 public static final int FLAG_BLUR_BEHIND = 0x00000004; 482 483 /** Window flag: this window won't ever get key input focus, so the 484 * user can not send key or other button events to it. Those will 485 * instead go to whatever focusable window is behind it. This flag 486 * will also enable {@link #FLAG_NOT_TOUCH_MODAL} whether or not that 487 * is explicitly set. 488 * 489 * <p>Setting this flag also implies that the window will not need to 490 * interact with 491 * a soft input method, so it will be Z-ordered and positioned 492 * independently of any active input method (typically this means it 493 * gets Z-ordered on top of the input method, so it can use the full 494 * screen for its content and cover the input method if needed. You 495 * can use {@link #FLAG_ALT_FOCUSABLE_IM} to modify this behavior. */ 496 public static final int FLAG_NOT_FOCUSABLE = 0x00000008; 497 498 /** Window flag: this window can never receive touch events. */ 499 public static final int FLAG_NOT_TOUCHABLE = 0x00000010; 500 501 /** Window flag: Even when this window is focusable (its 502 * {@link #FLAG_NOT_FOCUSABLE is not set), allow any pointer events 503 * outside of the window to be sent to the windows behind it. Otherwise 504 * it will consume all pointer events itself, regardless of whether they 505 * are inside of the window. */ 506 public static final int FLAG_NOT_TOUCH_MODAL = 0x00000020; 507 508 /** Window flag: When set, if the device is asleep when the touch 509 * screen is pressed, you will receive this first touch event. Usually 510 * the first touch event is consumed by the system since the user can 511 * not see what they are pressing on. 512 */ 513 public static final int FLAG_TOUCHABLE_WHEN_WAKING = 0x00000040; 514 515 /** Window flag: as long as this window is visible to the user, keep 516 * the device's screen turned on and bright. */ 517 public static final int FLAG_KEEP_SCREEN_ON = 0x00000080; 518 519 /** Window flag: place the window within the entire screen, ignoring 520 * decorations around the border (a.k.a. the status bar). The 521 * window must correctly position its contents to take the screen 522 * decoration into account. This flag is normally set for you 523 * by Window as described in {@link Window#setFlags}. */ 524 public static final int FLAG_LAYOUT_IN_SCREEN = 0x00000100; 525 526 /** Window flag: allow window to extend outside of the screen. */ 527 public static final int FLAG_LAYOUT_NO_LIMITS = 0x00000200; 528 529 /** Window flag: Hide all screen decorations (e.g. status bar) while 530 * this window is displayed. This allows the window to use the entire 531 * display space for itself -- the status bar will be hidden when 532 * an app window with this flag set is on the top layer. */ 533 public static final int FLAG_FULLSCREEN = 0x00000400; 534 535 /** Window flag: Override {@link #FLAG_FULLSCREEN and force the 536 * screen decorations (such as status bar) to be shown. */ 537 public static final int FLAG_FORCE_NOT_FULLSCREEN = 0x00000800; 538 539 /** Window flag: turn on dithering when compositing this window to 540 * the screen. 541 * @deprecated This flag is no longer used. */ 542 @Deprecated 543 public static final int FLAG_DITHER = 0x00001000; 544 545 /** Window flag: don't allow screen shots while this window is 546 * displayed. Maps to Surface.SECURE. */ 547 public static final int FLAG_SECURE = 0x00002000; 548 549 /** Window flag: a special mode where the layout parameters are used 550 * to perform scaling of the surface when it is composited to the 551 * screen. */ 552 public static final int FLAG_SCALED = 0x00004000; 553 554 /** Window flag: intended for windows that will often be used when the user is 555 * holding the screen against their face, it will aggressively filter the event 556 * stream to prevent unintended presses in this situation that may not be 557 * desired for a particular window, when such an event stream is detected, the 558 * application will receive a CANCEL motion event to indicate this so applications 559 * can handle this accordingly by taking no action on the event 560 * until the finger is released. */ 561 public static final int FLAG_IGNORE_CHEEK_PRESSES = 0x00008000; 562 563 /** Window flag: a special option only for use in combination with 564 * {@link #FLAG_LAYOUT_IN_SCREEN}. When requesting layout in the 565 * screen your window may appear on top of or behind screen decorations 566 * such as the status bar. By also including this flag, the window 567 * manager will report the inset rectangle needed to ensure your 568 * content is not covered by screen decorations. This flag is normally 569 * set for you by Window as described in {@link Window#setFlags}.*/ 570 public static final int FLAG_LAYOUT_INSET_DECOR = 0x00010000; 571 572 /** Window flag: invert the state of {@link #FLAG_NOT_FOCUSABLE} with 573 * respect to how this window interacts with the current method. That 574 * is, if FLAG_NOT_FOCUSABLE is set and this flag is set, then the 575 * window will behave as if it needs to interact with the input method 576 * and thus be placed behind/away from it; if FLAG_NOT_FOCUSABLE is 577 * not set and this flag is set, then the window will behave as if it 578 * doesn't need to interact with the input method and can be placed 579 * to use more space and cover the input method. 580 */ 581 public static final int FLAG_ALT_FOCUSABLE_IM = 0x00020000; 582 583 /** Window flag: if you have set {@link #FLAG_NOT_TOUCH_MODAL}, you 584 * can set this flag to receive a single special MotionEvent with 585 * the action 586 * {@link MotionEvent#ACTION_OUTSIDE MotionEvent.ACTION_OUTSIDE} for 587 * touches that occur outside of your window. Note that you will not 588 * receive the full down/move/up gesture, only the location of the 589 * first down as an ACTION_OUTSIDE. 590 */ 591 public static final int FLAG_WATCH_OUTSIDE_TOUCH = 0x00040000; 592 593 /** Window flag: special flag to let windows be shown when the screen 594 * is locked. This will let application windows take precedence over 595 * key guard or any other lock screens. Can be used with 596 * {@link #FLAG_KEEP_SCREEN_ON} to turn screen on and display windows 597 * directly before showing the key guard window. Can be used with 598 * {@link #FLAG_DISMISS_KEYGUARD} to automatically fully dismisss 599 * non-secure keyguards. This flag only applies to the top-most 600 * full-screen window. 601 */ 602 public static final int FLAG_SHOW_WHEN_LOCKED = 0x00080000; 603 604 /** Window flag: ask that the system wallpaper be shown behind 605 * your window. The window surface must be translucent to be able 606 * to actually see the wallpaper behind it; this flag just ensures 607 * that the wallpaper surface will be there if this window actually 608 * has translucent regions. 609 */ 610 public static final int FLAG_SHOW_WALLPAPER = 0x00100000; 611 612 /** Window flag: when set as a window is being added or made 613 * visible, once the window has been shown then the system will 614 * poke the power manager's user activity (as if the user had woken 615 * up the device) to turn the screen on. */ 616 public static final int FLAG_TURN_SCREEN_ON = 0x00200000; 617 618 /** Window flag: when set the window will cause the keyguard to 619 * be dismissed, only if it is not a secure lock keyguard. Because such 620 * a keyguard is not needed for security, it will never re-appear if 621 * the user navigates to another window (in contrast to 622 * {@link #FLAG_SHOW_WHEN_LOCKED}, which will only temporarily 623 * hide both secure and non-secure keyguards but ensure they reappear 624 * when the user moves to another UI that doesn't hide them). 625 * If the keyguard is currently active and is secure (requires an 626 * unlock pattern) than the user will still need to confirm it before 627 * seeing this window, unless {@link #FLAG_SHOW_WHEN_LOCKED} has 628 * also been set. 629 */ 630 public static final int FLAG_DISMISS_KEYGUARD = 0x00400000; 631 632 /** Window flag: when set the window will accept for touch events 633 * outside of its bounds to be sent to other windows that also 634 * support split touch. When this flag is not set, the first pointer 635 * that goes down determines the window to which all subsequent touches 636 * go until all pointers go up. When this flag is set, each pointer 637 * (not necessarily the first) that goes down determines the window 638 * to which all subsequent touches of that pointer will go until that 639 * pointer goes up thereby enabling touches with multiple pointers 640 * to be split across multiple windows. 641 */ 642 public static final int FLAG_SPLIT_TOUCH = 0x00800000; 643 644 /** 645 * <p>Indicates whether this window should be hardware accelerated. 646 * Requesting hardware acceleration does not guarantee it will happen.</p> 647 * 648 * <p>This flag can be controlled programmatically <em>only</em> to enable 649 * hardware acceleration. To enable hardware acceleration for a given 650 * window programmatically, do the following:</p> 651 * 652 * <pre> 653 * Window w = activity.getWindow(); // in Activity's onCreate() for instance 654 * w.setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, 655 * WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED); 656 * </pre> 657 * 658 * <p>It is important to remember that this flag <strong>must</strong> 659 * be set before setting the content view of your activity or dialog.</p> 660 * 661 * <p>This flag cannot be used to disable hardware acceleration after it 662 * was enabled in your manifest using 663 * {@link android.R.attr#hardwareAccelerated}. If you need to selectively 664 * and programmatically disable hardware acceleration (for automated testing 665 * for instance), make sure it is turned off in your manifest and enable it 666 * on your activity or dialog when you need it instead, using the method 667 * described above.</p> 668 * 669 * <p>This flag is automatically set by the system if the 670 * {@link android.R.attr#hardwareAccelerated android:hardwareAccelerated} 671 * XML attribute is set to true on an activity or on the application.</p> 672 */ 673 public static final int FLAG_HARDWARE_ACCELERATED = 0x01000000; 674 675 // ----- HIDDEN FLAGS. 676 // These start at the high bit and go down. 677 678 /** Window flag: Enable touches to slide out of a window into neighboring 679 * windows in mid-gesture instead of being captured for the duration of 680 * the gesture. 681 * 682 * This flag changes the behavior of touch focus for this window only. 683 * Touches can slide out of the window but they cannot necessarily slide 684 * back in (unless the other window with touch focus permits it). 685 * 686 * {@hide} 687 */ 688 public static final int FLAG_SLIPPERY = 0x04000000; 689 690 /** 691 * Flag for a window belonging to an activity that responds to {@link KeyEvent#KEYCODE_MENU} 692 * and therefore needs a Menu key. For devices where Menu is a physical button this flag is 693 * ignored, but on devices where the Menu key is drawn in software it may be hidden unless 694 * this flag is set. 695 * 696 * (Note that Action Bars, when available, are the preferred way to offer additional 697 * functions otherwise accessed via an options menu.) 698 * 699 * {@hide} 700 */ 701 public static final int FLAG_NEEDS_MENU_KEY = 0x08000000; 702 703 /** Window flag: special flag to limit the size of the window to be 704 * original size ([320x480] x density). Used to create window for applications 705 * running under compatibility mode. 706 * 707 * {@hide} */ 708 public static final int FLAG_COMPATIBLE_WINDOW = 0x20000000; 709 710 /** Window flag: a special option intended for system dialogs. When 711 * this flag is set, the window will demand focus unconditionally when 712 * it is created. 713 * {@hide} */ 714 public static final int FLAG_SYSTEM_ERROR = 0x40000000; 715 716 /** 717 * Various behavioral options/flags. Default is none. 718 * 719 * @see #FLAG_ALLOW_LOCK_WHILE_SCREEN_ON 720 * @see #FLAG_DIM_BEHIND 721 * @see #FLAG_NOT_FOCUSABLE 722 * @see #FLAG_NOT_TOUCHABLE 723 * @see #FLAG_NOT_TOUCH_MODAL 724 * @see #FLAG_TOUCHABLE_WHEN_WAKING 725 * @see #FLAG_KEEP_SCREEN_ON 726 * @see #FLAG_LAYOUT_IN_SCREEN 727 * @see #FLAG_LAYOUT_NO_LIMITS 728 * @see #FLAG_FULLSCREEN 729 * @see #FLAG_FORCE_NOT_FULLSCREEN 730 * @see #FLAG_SECURE 731 * @see #FLAG_SCALED 732 * @see #FLAG_IGNORE_CHEEK_PRESSES 733 * @see #FLAG_LAYOUT_INSET_DECOR 734 * @see #FLAG_ALT_FOCUSABLE_IM 735 * @see #FLAG_WATCH_OUTSIDE_TOUCH 736 * @see #FLAG_SHOW_WHEN_LOCKED 737 * @see #FLAG_SHOW_WALLPAPER 738 * @see #FLAG_TURN_SCREEN_ON 739 * @see #FLAG_DISMISS_KEYGUARD 740 * @see #FLAG_SPLIT_TOUCH 741 * @see #FLAG_HARDWARE_ACCELERATED 742 */ 743 @ViewDebug.ExportedProperty(flagMapping = { 744 @ViewDebug.FlagToString(mask = FLAG_ALLOW_LOCK_WHILE_SCREEN_ON, equals = FLAG_ALLOW_LOCK_WHILE_SCREEN_ON, 745 name = "FLAG_ALLOW_LOCK_WHILE_SCREEN_ON"), 746 @ViewDebug.FlagToString(mask = FLAG_DIM_BEHIND, equals = FLAG_DIM_BEHIND, 747 name = "FLAG_DIM_BEHIND"), 748 @ViewDebug.FlagToString(mask = FLAG_BLUR_BEHIND, equals = FLAG_BLUR_BEHIND, 749 name = "FLAG_BLUR_BEHIND"), 750 @ViewDebug.FlagToString(mask = FLAG_NOT_FOCUSABLE, equals = FLAG_NOT_FOCUSABLE, 751 name = "FLAG_NOT_FOCUSABLE"), 752 @ViewDebug.FlagToString(mask = FLAG_NOT_TOUCHABLE, equals = FLAG_NOT_TOUCHABLE, 753 name = "FLAG_NOT_TOUCHABLE"), 754 @ViewDebug.FlagToString(mask = FLAG_NOT_TOUCH_MODAL, equals = FLAG_NOT_TOUCH_MODAL, 755 name = "FLAG_NOT_TOUCH_MODAL"), 756 @ViewDebug.FlagToString(mask = FLAG_TOUCHABLE_WHEN_WAKING, equals = FLAG_TOUCHABLE_WHEN_WAKING, 757 name = "FLAG_TOUCHABLE_WHEN_WAKING"), 758 @ViewDebug.FlagToString(mask = FLAG_KEEP_SCREEN_ON, equals = FLAG_KEEP_SCREEN_ON, 759 name = "FLAG_KEEP_SCREEN_ON"), 760 @ViewDebug.FlagToString(mask = FLAG_LAYOUT_IN_SCREEN, equals = FLAG_LAYOUT_IN_SCREEN, 761 name = "FLAG_LAYOUT_IN_SCREEN"), 762 @ViewDebug.FlagToString(mask = FLAG_LAYOUT_NO_LIMITS, equals = FLAG_LAYOUT_NO_LIMITS, 763 name = "FLAG_LAYOUT_NO_LIMITS"), 764 @ViewDebug.FlagToString(mask = FLAG_FULLSCREEN, equals = FLAG_FULLSCREEN, 765 name = "FLAG_FULLSCREEN"), 766 @ViewDebug.FlagToString(mask = FLAG_FORCE_NOT_FULLSCREEN, equals = FLAG_FORCE_NOT_FULLSCREEN, 767 name = "FLAG_FORCE_NOT_FULLSCREEN"), 768 @ViewDebug.FlagToString(mask = FLAG_DITHER, equals = FLAG_DITHER, 769 name = "FLAG_DITHER"), 770 @ViewDebug.FlagToString(mask = FLAG_SECURE, equals = FLAG_SECURE, 771 name = "FLAG_SECURE"), 772 @ViewDebug.FlagToString(mask = FLAG_SCALED, equals = FLAG_SCALED, 773 name = "FLAG_SCALED"), 774 @ViewDebug.FlagToString(mask = FLAG_IGNORE_CHEEK_PRESSES, equals = FLAG_IGNORE_CHEEK_PRESSES, 775 name = "FLAG_IGNORE_CHEEK_PRESSES"), 776 @ViewDebug.FlagToString(mask = FLAG_LAYOUT_INSET_DECOR, equals = FLAG_LAYOUT_INSET_DECOR, 777 name = "FLAG_LAYOUT_INSET_DECOR"), 778 @ViewDebug.FlagToString(mask = FLAG_ALT_FOCUSABLE_IM, equals = FLAG_ALT_FOCUSABLE_IM, 779 name = "FLAG_ALT_FOCUSABLE_IM"), 780 @ViewDebug.FlagToString(mask = FLAG_WATCH_OUTSIDE_TOUCH, equals = FLAG_WATCH_OUTSIDE_TOUCH, 781 name = "FLAG_WATCH_OUTSIDE_TOUCH"), 782 @ViewDebug.FlagToString(mask = FLAG_SHOW_WHEN_LOCKED, equals = FLAG_SHOW_WHEN_LOCKED, 783 name = "FLAG_SHOW_WHEN_LOCKED"), 784 @ViewDebug.FlagToString(mask = FLAG_SHOW_WALLPAPER, equals = FLAG_SHOW_WALLPAPER, 785 name = "FLAG_SHOW_WALLPAPER"), 786 @ViewDebug.FlagToString(mask = FLAG_TURN_SCREEN_ON, equals = FLAG_TURN_SCREEN_ON, 787 name = "FLAG_TURN_SCREEN_ON"), 788 @ViewDebug.FlagToString(mask = FLAG_DISMISS_KEYGUARD, equals = FLAG_DISMISS_KEYGUARD, 789 name = "FLAG_DISMISS_KEYGUARD"), 790 @ViewDebug.FlagToString(mask = FLAG_SPLIT_TOUCH, equals = FLAG_SPLIT_TOUCH, 791 name = "FLAG_SPLIT_TOUCH"), 792 @ViewDebug.FlagToString(mask = FLAG_HARDWARE_ACCELERATED, equals = FLAG_HARDWARE_ACCELERATED, 793 name = "FLAG_HARDWARE_ACCELERATED") 794 }) 795 public int flags; 796 797 /** 798 * If the window has requested hardware acceleration, but this is not 799 * allowed in the process it is in, then still render it as if it is 800 * hardware accelerated. This is used for the starting preview windows 801 * in the system process, which don't need to have the overhead of 802 * hardware acceleration (they are just a static rendering), but should 803 * be rendered as such to match the actual window of the app even if it 804 * is hardware accelerated. 805 * Even if the window isn't hardware accelerated, still do its rendering 806 * as if it was. 807 * Like {@link #FLAG_HARDWARE_ACCELERATED} except for trusted system windows 808 * that need hardware acceleration (e.g. LockScreen), where hardware acceleration 809 * is generally disabled. This flag must be specified in addition to 810 * {@link #FLAG_HARDWARE_ACCELERATED} to enable hardware acceleration for system 811 * windows. 812 * 813 * @hide 814 */ 815 public static final int PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED = 0x00000001; 816 817 /** 818 * In the system process, we globally do not use hardware acceleration 819 * because there are many threads doing UI there and they conflict. 820 * If certain parts of the UI that really do want to use hardware 821 * acceleration, this flag can be set to force it. This is basically 822 * for the lock screen. Anyone else using it, you are probably wrong. 823 * 824 * @hide 825 */ 826 public static final int PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED = 0x00000002; 827 828 /** 829 * By default, wallpapers are sent new offsets when the wallpaper is scrolled. Wallpapers 830 * may elect to skip these notifications if they are not doing anything productive with 831 * them (they do not affect the wallpaper scrolling operation) by calling 832 * {@link 833 * android.service.wallpaper.WallpaperService.Engine#setOffsetNotificationsEnabled(boolean)}. 834 * 835 * @hide 836 */ 837 public static final int PRIVATE_FLAG_WANTS_OFFSET_NOTIFICATIONS = 0x00000004; 838 839 /** 840 * This is set for a window that has explicitly specified its 841 * FLAG_NEEDS_MENU_KEY, so we know the value on this window is the 842 * appropriate one to use. If this is not set, we should look at 843 * windows behind it to determine the appropriate value. 844 * 845 * @hide 846 */ 847 public static final int PRIVATE_FLAG_SET_NEEDS_MENU_KEY = 0x00000008; 848 849 /** 850 * Control flags that are private to the platform. 851 * @hide 852 */ 853 public int privateFlags; 854 855 /** 856 * Given a particular set of window manager flags, determine whether 857 * such a window may be a target for an input method when it has 858 * focus. In particular, this checks the 859 * {@link #FLAG_NOT_FOCUSABLE} and {@link #FLAG_ALT_FOCUSABLE_IM} 860 * flags and returns true if the combination of the two corresponds 861 * to a window that needs to be behind the input method so that the 862 * user can type into it. 863 * 864 * @param flags The current window manager flags. 865 * 866 * @return Returns true if such a window should be behind/interact 867 * with an input method, false if not. 868 */ 869 public static boolean mayUseInputMethod(int flags) { 870 switch (flags&(FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) { 871 case 0: 872 case FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM: 873 return true; 874 } 875 return false; 876 } 877 878 /** 879 * Mask for {@link #softInputMode} of the bits that determine the 880 * desired visibility state of the soft input area for this window. 881 */ 882 public static final int SOFT_INPUT_MASK_STATE = 0x0f; 883 884 /** 885 * Visibility state for {@link #softInputMode}: no state has been specified. 886 */ 887 public static final int SOFT_INPUT_STATE_UNSPECIFIED = 0; 888 889 /** 890 * Visibility state for {@link #softInputMode}: please don't change the state of 891 * the soft input area. 892 */ 893 public static final int SOFT_INPUT_STATE_UNCHANGED = 1; 894 895 /** 896 * Visibility state for {@link #softInputMode}: please hide any soft input 897 * area when normally appropriate (when the user is navigating 898 * forward to your window). 899 */ 900 public static final int SOFT_INPUT_STATE_HIDDEN = 2; 901 902 /** 903 * Visibility state for {@link #softInputMode}: please always hide any 904 * soft input area when this window receives focus. 905 */ 906 public static final int SOFT_INPUT_STATE_ALWAYS_HIDDEN = 3; 907 908 /** 909 * Visibility state for {@link #softInputMode}: please show the soft 910 * input area when normally appropriate (when the user is navigating 911 * forward to your window). 912 */ 913 public static final int SOFT_INPUT_STATE_VISIBLE = 4; 914 915 /** 916 * Visibility state for {@link #softInputMode}: please always make the 917 * soft input area visible when this window receives input focus. 918 */ 919 public static final int SOFT_INPUT_STATE_ALWAYS_VISIBLE = 5; 920 921 /** 922 * Mask for {@link #softInputMode} of the bits that determine the 923 * way that the window should be adjusted to accommodate the soft 924 * input window. 925 */ 926 public static final int SOFT_INPUT_MASK_ADJUST = 0xf0; 927 928 /** Adjustment option for {@link #softInputMode}: nothing specified. 929 * The system will try to pick one or 930 * the other depending on the contents of the window. 931 */ 932 public static final int SOFT_INPUT_ADJUST_UNSPECIFIED = 0x00; 933 934 /** Adjustment option for {@link #softInputMode}: set to allow the 935 * window to be resized when an input 936 * method is shown, so that its contents are not covered by the input 937 * method. This can <em>not</em> be combined with 938 * {@link #SOFT_INPUT_ADJUST_PAN}; if 939 * neither of these are set, then the system will try to pick one or 940 * the other depending on the contents of the window. 941 */ 942 public static final int SOFT_INPUT_ADJUST_RESIZE = 0x10; 943 944 /** Adjustment option for {@link #softInputMode}: set to have a window 945 * pan when an input method is 946 * shown, so it doesn't need to deal with resizing but just panned 947 * by the framework to ensure the current input focus is visible. This 948 * can <em>not</em> be combined with {@link #SOFT_INPUT_ADJUST_RESIZE}; if 949 * neither of these are set, then the system will try to pick one or 950 * the other depending on the contents of the window. 951 */ 952 public static final int SOFT_INPUT_ADJUST_PAN = 0x20; 953 954 /** Adjustment option for {@link #softInputMode}: set to have a window 955 * not adjust for a shown input method. The window will not be resized, 956 * and it will not be panned to make its focus visible. 957 */ 958 public static final int SOFT_INPUT_ADJUST_NOTHING = 0x30; 959 960 /** 961 * Bit for {@link #softInputMode}: set when the user has navigated 962 * forward to the window. This is normally set automatically for 963 * you by the system, though you may want to set it in certain cases 964 * when you are displaying a window yourself. This flag will always 965 * be cleared automatically after the window is displayed. 966 */ 967 public static final int SOFT_INPUT_IS_FORWARD_NAVIGATION = 0x100; 968 969 /** 970 * Desired operating mode for any soft input area. May be any combination 971 * of: 972 * 973 * <ul> 974 * <li> One of the visibility states 975 * {@link #SOFT_INPUT_STATE_UNSPECIFIED}, {@link #SOFT_INPUT_STATE_UNCHANGED}, 976 * {@link #SOFT_INPUT_STATE_HIDDEN}, {@link #SOFT_INPUT_STATE_ALWAYS_VISIBLE}, or 977 * {@link #SOFT_INPUT_STATE_VISIBLE}. 978 * <li> One of the adjustment options 979 * {@link #SOFT_INPUT_ADJUST_UNSPECIFIED}, 980 * {@link #SOFT_INPUT_ADJUST_RESIZE}, or 981 * {@link #SOFT_INPUT_ADJUST_PAN}. 982 */ 983 public int softInputMode; 984 985 /** 986 * Placement of window within the screen as per {@link Gravity}. Both 987 * {@link Gravity#apply(int, int, int, android.graphics.Rect, int, int, 988 * android.graphics.Rect) Gravity.apply} and 989 * {@link Gravity#applyDisplay(int, android.graphics.Rect, android.graphics.Rect) 990 * Gravity.applyDisplay} are used during window layout, with this value 991 * given as the desired gravity. For example you can specify 992 * {@link Gravity#DISPLAY_CLIP_HORIZONTAL Gravity.DISPLAY_CLIP_HORIZONTAL} and 993 * {@link Gravity#DISPLAY_CLIP_VERTICAL Gravity.DISPLAY_CLIP_VERTICAL} here 994 * to control the behavior of 995 * {@link Gravity#applyDisplay(int, android.graphics.Rect, android.graphics.Rect) 996 * Gravity.applyDisplay}. 997 * 998 * @see Gravity 999 */ 1000 public int gravity; 1001 1002 /** 1003 * The horizontal margin, as a percentage of the container's width, 1004 * between the container and the widget. See 1005 * {@link Gravity#apply(int, int, int, android.graphics.Rect, int, int, 1006 * android.graphics.Rect) Gravity.apply} for how this is used. This 1007 * field is added with {@link #x} to supply the <var>xAdj</var> parameter. 1008 */ 1009 public float horizontalMargin; 1010 1011 /** 1012 * The vertical margin, as a percentage of the container's height, 1013 * between the container and the widget. See 1014 * {@link Gravity#apply(int, int, int, android.graphics.Rect, int, int, 1015 * android.graphics.Rect) Gravity.apply} for how this is used. This 1016 * field is added with {@link #y} to supply the <var>yAdj</var> parameter. 1017 */ 1018 public float verticalMargin; 1019 1020 /** 1021 * The desired bitmap format. May be one of the constants in 1022 * {@link android.graphics.PixelFormat}. Default is OPAQUE. 1023 */ 1024 public int format; 1025 1026 /** 1027 * A style resource defining the animations to use for this window. 1028 * This must be a system resource; it can not be an application resource 1029 * because the window manager does not have access to applications. 1030 */ 1031 public int windowAnimations; 1032 1033 /** 1034 * An alpha value to apply to this entire window. 1035 * An alpha of 1.0 means fully opaque and 0.0 means fully transparent 1036 */ 1037 public float alpha = 1.0f; 1038 1039 /** 1040 * When {@link #FLAG_DIM_BEHIND} is set, this is the amount of dimming 1041 * to apply. Range is from 1.0 for completely opaque to 0.0 for no 1042 * dim. 1043 */ 1044 public float dimAmount = 1.0f; 1045 1046 /** 1047 * Default value for {@link #screenBrightness} and {@link #buttonBrightness} 1048 * indicating that the brightness value is not overridden for this window 1049 * and normal brightness policy should be used. 1050 */ 1051 public static final float BRIGHTNESS_OVERRIDE_NONE = -1.0f; 1052 1053 /** 1054 * Value for {@link #screenBrightness} and {@link #buttonBrightness} 1055 * indicating that the screen or button backlight brightness should be set 1056 * to the lowest value when this window is in front. 1057 */ 1058 public static final float BRIGHTNESS_OVERRIDE_OFF = 0.0f; 1059 1060 /** 1061 * Value for {@link #screenBrightness} and {@link #buttonBrightness} 1062 * indicating that the screen or button backlight brightness should be set 1063 * to the hightest value when this window is in front. 1064 */ 1065 public static final float BRIGHTNESS_OVERRIDE_FULL = 1.0f; 1066 1067 /** 1068 * This can be used to override the user's preferred brightness of 1069 * the screen. A value of less than 0, the default, means to use the 1070 * preferred screen brightness. 0 to 1 adjusts the brightness from 1071 * dark to full bright. 1072 */ 1073 public float screenBrightness = BRIGHTNESS_OVERRIDE_NONE; 1074 1075 /** 1076 * This can be used to override the standard behavior of the button and 1077 * keyboard backlights. A value of less than 0, the default, means to 1078 * use the standard backlight behavior. 0 to 1 adjusts the brightness 1079 * from dark to full bright. 1080 */ 1081 public float buttonBrightness = BRIGHTNESS_OVERRIDE_NONE; 1082 1083 /** 1084 * Identifier for this window. This will usually be filled in for 1085 * you. 1086 */ 1087 public IBinder token = null; 1088 1089 /** 1090 * Name of the package owning this window. 1091 */ 1092 public String packageName = null; 1093 1094 /** 1095 * Specific orientation value for a window. 1096 * May be any of the same values allowed 1097 * for {@link android.content.pm.ActivityInfo#screenOrientation}. 1098 * If not set, a default value of 1099 * {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSPECIFIED} 1100 * will be used. 1101 */ 1102 public int screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; 1103 1104 /** 1105 * Control the visibility of the status bar. 1106 * 1107 * @see View#STATUS_BAR_VISIBLE 1108 * @see View#STATUS_BAR_HIDDEN 1109 */ 1110 public int systemUiVisibility; 1111 1112 /** 1113 * @hide 1114 * The ui visibility as requested by the views in this hierarchy. 1115 * the combined value should be systemUiVisibility | subtreeSystemUiVisibility. 1116 */ 1117 public int subtreeSystemUiVisibility; 1118 1119 /** 1120 * Get callbacks about the system ui visibility changing. 1121 * 1122 * TODO: Maybe there should be a bitfield of optional callbacks that we need. 1123 * 1124 * @hide 1125 */ 1126 public boolean hasSystemUiListeners; 1127 1128 /** 1129 * When this window has focus, disable touch pad pointer gesture processing. 1130 * The window will receive raw position updates from the touch pad instead 1131 * of pointer movements and synthetic touch events. 1132 * 1133 * @hide 1134 */ 1135 public static final int INPUT_FEATURE_DISABLE_POINTER_GESTURES = 0x00000001; 1136 1137 /** 1138 * Does not construct an input channel for this window. The channel will therefore 1139 * be incapable of receiving input. 1140 * 1141 * @hide 1142 */ 1143 public static final int INPUT_FEATURE_NO_INPUT_CHANNEL = 0x00000002; 1144 1145 /** 1146 * Control special features of the input subsystem. 1147 * 1148 * @see #INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES 1149 * @see #INPUT_FEATURE_NO_INPUT_CHANNEL 1150 * @hide 1151 */ 1152 public int inputFeatures; 1153 1154 public LayoutParams() { 1155 super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); 1156 type = TYPE_APPLICATION; 1157 format = PixelFormat.OPAQUE; 1158 } 1159 1160 public LayoutParams(int _type) { 1161 super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); 1162 type = _type; 1163 format = PixelFormat.OPAQUE; 1164 } 1165 1166 public LayoutParams(int _type, int _flags) { 1167 super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); 1168 type = _type; 1169 flags = _flags; 1170 format = PixelFormat.OPAQUE; 1171 } 1172 1173 public LayoutParams(int _type, int _flags, int _format) { 1174 super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); 1175 type = _type; 1176 flags = _flags; 1177 format = _format; 1178 } 1179 1180 public LayoutParams(int w, int h, int _type, int _flags, int _format) { 1181 super(w, h); 1182 type = _type; 1183 flags = _flags; 1184 format = _format; 1185 } 1186 1187 public LayoutParams(int w, int h, int xpos, int ypos, int _type, 1188 int _flags, int _format) { 1189 super(w, h); 1190 x = xpos; 1191 y = ypos; 1192 type = _type; 1193 flags = _flags; 1194 format = _format; 1195 } 1196 1197 public final void setTitle(CharSequence title) { 1198 if (null == title) 1199 title = ""; 1200 1201 mTitle = TextUtils.stringOrSpannedString(title); 1202 } 1203 1204 public final CharSequence getTitle() { 1205 return mTitle; 1206 } 1207 1208 public int describeContents() { 1209 return 0; 1210 } 1211 1212 public void writeToParcel(Parcel out, int parcelableFlags) { 1213 out.writeInt(width); 1214 out.writeInt(height); 1215 out.writeInt(x); 1216 out.writeInt(y); 1217 out.writeInt(type); 1218 out.writeInt(flags); 1219 out.writeInt(privateFlags); 1220 out.writeInt(softInputMode); 1221 out.writeInt(gravity); 1222 out.writeFloat(horizontalMargin); 1223 out.writeFloat(verticalMargin); 1224 out.writeInt(format); 1225 out.writeInt(windowAnimations); 1226 out.writeFloat(alpha); 1227 out.writeFloat(dimAmount); 1228 out.writeFloat(screenBrightness); 1229 out.writeFloat(buttonBrightness); 1230 out.writeStrongBinder(token); 1231 out.writeString(packageName); 1232 TextUtils.writeToParcel(mTitle, out, parcelableFlags); 1233 out.writeInt(screenOrientation); 1234 out.writeInt(systemUiVisibility); 1235 out.writeInt(subtreeSystemUiVisibility); 1236 out.writeInt(hasSystemUiListeners ? 1 : 0); 1237 out.writeInt(inputFeatures); 1238 } 1239 1240 public static final Parcelable.Creator<LayoutParams> CREATOR 1241 = new Parcelable.Creator<LayoutParams>() { 1242 public LayoutParams createFromParcel(Parcel in) { 1243 return new LayoutParams(in); 1244 } 1245 1246 public LayoutParams[] newArray(int size) { 1247 return new LayoutParams[size]; 1248 } 1249 }; 1250 1251 1252 public LayoutParams(Parcel in) { 1253 width = in.readInt(); 1254 height = in.readInt(); 1255 x = in.readInt(); 1256 y = in.readInt(); 1257 type = in.readInt(); 1258 flags = in.readInt(); 1259 privateFlags = in.readInt(); 1260 softInputMode = in.readInt(); 1261 gravity = in.readInt(); 1262 horizontalMargin = in.readFloat(); 1263 verticalMargin = in.readFloat(); 1264 format = in.readInt(); 1265 windowAnimations = in.readInt(); 1266 alpha = in.readFloat(); 1267 dimAmount = in.readFloat(); 1268 screenBrightness = in.readFloat(); 1269 buttonBrightness = in.readFloat(); 1270 token = in.readStrongBinder(); 1271 packageName = in.readString(); 1272 mTitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); 1273 screenOrientation = in.readInt(); 1274 systemUiVisibility = in.readInt(); 1275 subtreeSystemUiVisibility = in.readInt(); 1276 hasSystemUiListeners = in.readInt() != 0; 1277 inputFeatures = in.readInt(); 1278 } 1279 1280 @SuppressWarnings({"PointlessBitwiseExpression"}) 1281 public static final int LAYOUT_CHANGED = 1<<0; 1282 public static final int TYPE_CHANGED = 1<<1; 1283 public static final int FLAGS_CHANGED = 1<<2; 1284 public static final int FORMAT_CHANGED = 1<<3; 1285 public static final int ANIMATION_CHANGED = 1<<4; 1286 public static final int DIM_AMOUNT_CHANGED = 1<<5; 1287 public static final int TITLE_CHANGED = 1<<6; 1288 public static final int ALPHA_CHANGED = 1<<7; 1289 public static final int MEMORY_TYPE_CHANGED = 1<<8; 1290 public static final int SOFT_INPUT_MODE_CHANGED = 1<<9; 1291 public static final int SCREEN_ORIENTATION_CHANGED = 1<<10; 1292 public static final int SCREEN_BRIGHTNESS_CHANGED = 1<<11; 1293 /** {@hide} */ 1294 public static final int BUTTON_BRIGHTNESS_CHANGED = 1<<12; 1295 /** {@hide} */ 1296 public static final int SYSTEM_UI_VISIBILITY_CHANGED = 1<<13; 1297 /** {@hide} */ 1298 public static final int SYSTEM_UI_LISTENER_CHANGED = 1<<14; 1299 /** {@hide} */ 1300 public static final int INPUT_FEATURES_CHANGED = 1<<15; 1301 /** {@hide} */ 1302 public static final int PRIVATE_FLAGS_CHANGED = 1<<16; 1303 /** {@hide} */ 1304 public static final int EVERYTHING_CHANGED = 0xffffffff; 1305 1306 // internal buffer to backup/restore parameters under compatibility mode. 1307 private int[] mCompatibilityParamsBackup = null; 1308 1309 public final int copyFrom(LayoutParams o) { 1310 int changes = 0; 1311 1312 if (width != o.width) { 1313 width = o.width; 1314 changes |= LAYOUT_CHANGED; 1315 } 1316 if (height != o.height) { 1317 height = o.height; 1318 changes |= LAYOUT_CHANGED; 1319 } 1320 if (x != o.x) { 1321 x = o.x; 1322 changes |= LAYOUT_CHANGED; 1323 } 1324 if (y != o.y) { 1325 y = o.y; 1326 changes |= LAYOUT_CHANGED; 1327 } 1328 if (horizontalWeight != o.horizontalWeight) { 1329 horizontalWeight = o.horizontalWeight; 1330 changes |= LAYOUT_CHANGED; 1331 } 1332 if (verticalWeight != o.verticalWeight) { 1333 verticalWeight = o.verticalWeight; 1334 changes |= LAYOUT_CHANGED; 1335 } 1336 if (horizontalMargin != o.horizontalMargin) { 1337 horizontalMargin = o.horizontalMargin; 1338 changes |= LAYOUT_CHANGED; 1339 } 1340 if (verticalMargin != o.verticalMargin) { 1341 verticalMargin = o.verticalMargin; 1342 changes |= LAYOUT_CHANGED; 1343 } 1344 if (type != o.type) { 1345 type = o.type; 1346 changes |= TYPE_CHANGED; 1347 } 1348 if (flags != o.flags) { 1349 flags = o.flags; 1350 changes |= FLAGS_CHANGED; 1351 } 1352 if (privateFlags != o.privateFlags) { 1353 privateFlags = o.privateFlags; 1354 changes |= PRIVATE_FLAGS_CHANGED; 1355 } 1356 if (softInputMode != o.softInputMode) { 1357 softInputMode = o.softInputMode; 1358 changes |= SOFT_INPUT_MODE_CHANGED; 1359 } 1360 if (gravity != o.gravity) { 1361 gravity = o.gravity; 1362 changes |= LAYOUT_CHANGED; 1363 } 1364 if (format != o.format) { 1365 format = o.format; 1366 changes |= FORMAT_CHANGED; 1367 } 1368 if (windowAnimations != o.windowAnimations) { 1369 windowAnimations = o.windowAnimations; 1370 changes |= ANIMATION_CHANGED; 1371 } 1372 if (token == null) { 1373 // NOTE: token only copied if the recipient doesn't 1374 // already have one. 1375 token = o.token; 1376 } 1377 if (packageName == null) { 1378 // NOTE: packageName only copied if the recipient doesn't 1379 // already have one. 1380 packageName = o.packageName; 1381 } 1382 if (!mTitle.equals(o.mTitle)) { 1383 mTitle = o.mTitle; 1384 changes |= TITLE_CHANGED; 1385 } 1386 if (alpha != o.alpha) { 1387 alpha = o.alpha; 1388 changes |= ALPHA_CHANGED; 1389 } 1390 if (dimAmount != o.dimAmount) { 1391 dimAmount = o.dimAmount; 1392 changes |= DIM_AMOUNT_CHANGED; 1393 } 1394 if (screenBrightness != o.screenBrightness) { 1395 screenBrightness = o.screenBrightness; 1396 changes |= SCREEN_BRIGHTNESS_CHANGED; 1397 } 1398 if (buttonBrightness != o.buttonBrightness) { 1399 buttonBrightness = o.buttonBrightness; 1400 changes |= BUTTON_BRIGHTNESS_CHANGED; 1401 } 1402 1403 if (screenOrientation != o.screenOrientation) { 1404 screenOrientation = o.screenOrientation; 1405 changes |= SCREEN_ORIENTATION_CHANGED; 1406 } 1407 1408 if (systemUiVisibility != o.systemUiVisibility 1409 || subtreeSystemUiVisibility != o.subtreeSystemUiVisibility) { 1410 systemUiVisibility = o.systemUiVisibility; 1411 subtreeSystemUiVisibility = o.subtreeSystemUiVisibility; 1412 changes |= SYSTEM_UI_VISIBILITY_CHANGED; 1413 } 1414 1415 if (hasSystemUiListeners != o.hasSystemUiListeners) { 1416 hasSystemUiListeners = o.hasSystemUiListeners; 1417 changes |= SYSTEM_UI_LISTENER_CHANGED; 1418 } 1419 1420 if (inputFeatures != o.inputFeatures) { 1421 inputFeatures = o.inputFeatures; 1422 changes |= INPUT_FEATURES_CHANGED; 1423 } 1424 1425 return changes; 1426 } 1427 1428 @Override 1429 public String debug(String output) { 1430 output += "Contents of " + this + ":"; 1431 Log.d("Debug", output); 1432 output = super.debug(""); 1433 Log.d("Debug", output); 1434 Log.d("Debug", ""); 1435 Log.d("Debug", "WindowManager.LayoutParams={title=" + mTitle + "}"); 1436 return ""; 1437 } 1438 1439 @Override 1440 public String toString() { 1441 StringBuilder sb = new StringBuilder(256); 1442 sb.append("WM.LayoutParams{"); 1443 sb.append("("); 1444 sb.append(x); 1445 sb.append(','); 1446 sb.append(y); 1447 sb.append(")("); 1448 sb.append((width== MATCH_PARENT ?"fill":(width==WRAP_CONTENT?"wrap":width))); 1449 sb.append('x'); 1450 sb.append((height== MATCH_PARENT ?"fill":(height==WRAP_CONTENT?"wrap":height))); 1451 sb.append(")"); 1452 if (horizontalMargin != 0) { 1453 sb.append(" hm="); 1454 sb.append(horizontalMargin); 1455 } 1456 if (verticalMargin != 0) { 1457 sb.append(" vm="); 1458 sb.append(verticalMargin); 1459 } 1460 if (gravity != 0) { 1461 sb.append(" gr=#"); 1462 sb.append(Integer.toHexString(gravity)); 1463 } 1464 if (softInputMode != 0) { 1465 sb.append(" sim=#"); 1466 sb.append(Integer.toHexString(softInputMode)); 1467 } 1468 sb.append(" ty="); 1469 sb.append(type); 1470 sb.append(" fl=#"); 1471 sb.append(Integer.toHexString(flags)); 1472 if (privateFlags != 0) { 1473 sb.append(" pfl=0x").append(Integer.toHexString(privateFlags)); 1474 } 1475 if (format != PixelFormat.OPAQUE) { 1476 sb.append(" fmt="); 1477 sb.append(format); 1478 } 1479 if (windowAnimations != 0) { 1480 sb.append(" wanim=0x"); 1481 sb.append(Integer.toHexString(windowAnimations)); 1482 } 1483 if (screenOrientation != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { 1484 sb.append(" or="); 1485 sb.append(screenOrientation); 1486 } 1487 if (alpha != 1.0f) { 1488 sb.append(" alpha="); 1489 sb.append(alpha); 1490 } 1491 if (screenBrightness != BRIGHTNESS_OVERRIDE_NONE) { 1492 sb.append(" sbrt="); 1493 sb.append(screenBrightness); 1494 } 1495 if (buttonBrightness != BRIGHTNESS_OVERRIDE_NONE) { 1496 sb.append(" bbrt="); 1497 sb.append(buttonBrightness); 1498 } 1499 if ((flags & FLAG_COMPATIBLE_WINDOW) != 0) { 1500 sb.append(" compatible=true"); 1501 } 1502 if (systemUiVisibility != 0) { 1503 sb.append(" sysui=0x"); 1504 sb.append(Integer.toHexString(systemUiVisibility)); 1505 } 1506 if (subtreeSystemUiVisibility != 0) { 1507 sb.append(" vsysui=0x"); 1508 sb.append(Integer.toHexString(subtreeSystemUiVisibility)); 1509 } 1510 if (hasSystemUiListeners) { 1511 sb.append(" sysuil="); 1512 sb.append(hasSystemUiListeners); 1513 } 1514 if (inputFeatures != 0) { 1515 sb.append(" if=0x").append(Integer.toHexString(inputFeatures)); 1516 } 1517 sb.append('}'); 1518 return sb.toString(); 1519 } 1520 1521 /** 1522 * Scale the layout params' coordinates and size. 1523 * @hide 1524 */ 1525 public void scale(float scale) { 1526 x = (int) (x * scale + 0.5f); 1527 y = (int) (y * scale + 0.5f); 1528 if (width > 0) { 1529 width = (int) (width * scale + 0.5f); 1530 } 1531 if (height > 0) { 1532 height = (int) (height * scale + 0.5f); 1533 } 1534 } 1535 1536 /** 1537 * Backup the layout parameters used in compatibility mode. 1538 * @see LayoutParams#restore() 1539 */ 1540 void backup() { 1541 int[] backup = mCompatibilityParamsBackup; 1542 if (backup == null) { 1543 // we backup 4 elements, x, y, width, height 1544 backup = mCompatibilityParamsBackup = new int[4]; 1545 } 1546 backup[0] = x; 1547 backup[1] = y; 1548 backup[2] = width; 1549 backup[3] = height; 1550 } 1551 1552 /** 1553 * Restore the layout params' coordinates, size and gravity 1554 * @see LayoutParams#backup() 1555 */ 1556 void restore() { 1557 int[] backup = mCompatibilityParamsBackup; 1558 if (backup != null) { 1559 x = backup[0]; 1560 y = backup[1]; 1561 width = backup[2]; 1562 height = backup[3]; 1563 } 1564 } 1565 1566 private CharSequence mTitle = ""; 1567 } 1568} 1569