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