WindowManager.java revision 613dde4aa651e11dac3db859723cc6faf8fc0a82
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_TURN_SCREEN_ON, equals = FLAG_TURN_SCREEN_ON, 409 name = "FLAG_TURN_SCREEN_ON"), 410 @ViewDebug.FlagToString(mask = FLAG_KEEP_SCREEN_ON, equals = FLAG_KEEP_SCREEN_ON, 411 name = "FLAG_KEEP_SCREEN_ON"), 412 @ViewDebug.FlagToString(mask = FLAG_SHOW_WHEN_LOCKED, equals = FLAG_SHOW_WHEN_LOCKED, 413 name = "FLAG_SHOW_WHEN_LOCKED"), 414 @ViewDebug.FlagToString(mask = FLAG_ALLOW_LOCK_WHILE_SCREEN_ON, equals = FLAG_ALLOW_LOCK_WHILE_SCREEN_ON, 415 name = "FLAG_ALLOW_LOCK_WHILE_SCREEN_ON"), 416 @ViewDebug.FlagToString(mask = FLAG_DISMISS_KEYGUARD, equals = FLAG_DISMISS_KEYGUARD, 417 name = "FLAG_DISMISS_KEYGUARD"), 418 @ViewDebug.FlagToString(mask = FLAG_FULLSCREEN, equals = FLAG_FULLSCREEN, 419 name = "FLAG_FULLSCREEN"), 420 @ViewDebug.FlagToString(mask = FLAG_FORCE_NOT_FULLSCREEN, 421 equals = FLAG_FORCE_NOT_FULLSCREEN, name = "FLAG_FORCE_NOT_FULLSCREEN"), 422 @ViewDebug.FlagToString(mask = FLAG_IGNORE_CHEEK_PRESSES, 423 equals = FLAG_IGNORE_CHEEK_PRESSES, name = "FLAG_IGNORE_CHEEK_PRESSES") 424 }) 425 public int flags; 426 427 /** Window flag: as long as this window is visible to the user, allow 428 * the lock screen to activate while the screen is on. 429 * This can be used independently, or in combination with 430 * {@link #FLAG_KEEP_SCREEN_ON} and/or {@link #FLAG_SHOW_WHEN_LOCKED} */ 431 public static final int FLAG_ALLOW_LOCK_WHILE_SCREEN_ON = 0x00000001; 432 433 /** Window flag: everything behind this window will be dimmed. 434 * Use {@link #dimAmount} to control the amount of dim. */ 435 public static final int FLAG_DIM_BEHIND = 0x00000002; 436 437 /** Window flag: blur everything behind this window. */ 438 public static final int FLAG_BLUR_BEHIND = 0x00000004; 439 440 /** Window flag: this window won't ever get key input focus, so the 441 * user can not send key or other button events to it. Those will 442 * instead go to whatever focusable window is behind it. This flag 443 * will also enable {@link #FLAG_NOT_TOUCH_MODAL} whether or not that 444 * is explicitly set. 445 * 446 * <p>Setting this flag also implies that the window will not need to 447 * interact with 448 * a soft input method, so it will be Z-ordered and positioned 449 * independently of any active input method (typically this means it 450 * gets Z-ordered on top of the input method, so it can use the full 451 * screen for its content and cover the input method if needed. You 452 * can use {@link #FLAG_ALT_FOCUSABLE_IM} to modify this behavior. */ 453 public static final int FLAG_NOT_FOCUSABLE = 0x00000008; 454 455 /** Window flag: this window can never receive touch events. */ 456 public static final int FLAG_NOT_TOUCHABLE = 0x00000010; 457 458 /** Window flag: Even when this window is focusable (its 459 * {@link #FLAG_NOT_FOCUSABLE is not set), allow any pointer events 460 * outside of the window to be sent to the windows behind it. Otherwise 461 * it will consume all pointer events itself, regardless of whether they 462 * are inside of the window. */ 463 public static final int FLAG_NOT_TOUCH_MODAL = 0x00000020; 464 465 /** Window flag: When set, if the device is asleep when the touch 466 * screen is pressed, you will receive this first touch event. Usually 467 * the first touch event is consumed by the system since the user can 468 * not see what they are pressing on. 469 */ 470 public static final int FLAG_TOUCHABLE_WHEN_WAKING = 0x00000040; 471 472 /** Window flag: as long as this window is visible to the user, keep 473 * the device's screen turned on and bright. */ 474 public static final int FLAG_KEEP_SCREEN_ON = 0x00000080; 475 476 /** Window flag: place the window within the entire screen, ignoring 477 * decorations around the border (a.k.a. the status bar). The 478 * window must correctly position its contents to take the screen 479 * decoration into account. This flag is normally set for you 480 * by Window as described in {@link Window#setFlags}. */ 481 public static final int FLAG_LAYOUT_IN_SCREEN = 0x00000100; 482 483 /** Window flag: allow window to extend outside of the screen. */ 484 public static final int FLAG_LAYOUT_NO_LIMITS = 0x00000200; 485 486 /** Window flag: Hide all screen decorations (e.g. status bar) while 487 * this window is displayed. This allows the window to use the entire 488 * display space for itself -- the status bar will be hidden when 489 * an app window with this flag set is on the top layer. */ 490 public static final int FLAG_FULLSCREEN = 0x00000400; 491 492 /** Window flag: Override {@link #FLAG_FULLSCREEN and force the 493 * screen decorations (such as status bar) to be shown. */ 494 public static final int FLAG_FORCE_NOT_FULLSCREEN = 0x00000800; 495 496 /** Window flag: turn on dithering when compositing this window to 497 * the screen. */ 498 public static final int FLAG_DITHER = 0x00001000; 499 500 /** Window flag: don't allow screen shots while this window is 501 * displayed. */ 502 public static final int FLAG_SECURE = 0x00002000; 503 504 /** Window flag: a special mode where the layout parameters are used 505 * to perform scaling of the surface when it is composited to the 506 * screen. */ 507 public static final int FLAG_SCALED = 0x00004000; 508 509 /** Window flag: intended for windows that will often be used when the user is 510 * holding the screen against their face, it will aggressively filter the event 511 * stream to prevent unintended presses in this situation that may not be 512 * desired for a particular window, when such an event stream is detected, the 513 * application will receive a CANCEL motion event to indicate this so applications 514 * can handle this accordingly by taking no action on the event 515 * until the finger is released. */ 516 public static final int FLAG_IGNORE_CHEEK_PRESSES = 0x00008000; 517 518 /** Window flag: a special option only for use in combination with 519 * {@link #FLAG_LAYOUT_IN_SCREEN}. When requesting layout in the 520 * screen your window may appear on top of or behind screen decorations 521 * such as the status bar. By also including this flag, the window 522 * manager will report the inset rectangle needed to ensure your 523 * content is not covered by screen decorations. This flag is normally 524 * set for you by Window as described in {@link Window#setFlags}.*/ 525 public static final int FLAG_LAYOUT_INSET_DECOR = 0x00010000; 526 527 /** Window flag: invert the state of {@link #FLAG_NOT_FOCUSABLE} with 528 * respect to how this window interacts with the current method. That 529 * is, if FLAG_NOT_FOCUSABLE is set and this flag is set, then the 530 * window will behave as if it needs to interact with the input method 531 * and thus be placed behind/away from it; if FLAG_NOT_FOCUSABLE is 532 * not set and this flag is set, then the window will behave as if it 533 * doesn't need to interact with the input method and can be placed 534 * to use more space and cover the input method. 535 */ 536 public static final int FLAG_ALT_FOCUSABLE_IM = 0x00020000; 537 538 /** Window flag: if you have set {@link #FLAG_NOT_TOUCH_MODAL}, you 539 * can set this flag to receive a single special MotionEvent with 540 * the action 541 * {@link MotionEvent#ACTION_OUTSIDE MotionEvent.ACTION_OUTSIDE} for 542 * touches that occur outside of your window. Note that you will not 543 * receive the full down/move/up gesture, only the location of the 544 * first down as an ACTION_OUTSIDE. 545 */ 546 public static final int FLAG_WATCH_OUTSIDE_TOUCH = 0x00040000; 547 548 /** Window flag: special flag to let windows be shown when the screen 549 * is locked. This will let application windows take precedence over 550 * key guard or any other lock screens. Can be used with 551 * {@link #FLAG_KEEP_SCREEN_ON} to turn screen on and display windows 552 * directly before showing the key guard window. Can be used with 553 * {@link #FLAG_DISMISS_KEYGUARD} to automatically fully dismisss 554 * non-secure keyguards. This flag only applies to the top-most 555 * full-screen window. 556 */ 557 public static final int FLAG_SHOW_WHEN_LOCKED = 0x00080000; 558 559 /** Window flag: ask that the system wallpaper be shown behind 560 * your window. The window surface must be translucent to be able 561 * to actually see the wallpaper behind it; this flag just ensures 562 * that the wallpaper surface will be there if this window actually 563 * has translucent regions. 564 */ 565 public static final int FLAG_SHOW_WALLPAPER = 0x00100000; 566 567 /** Window flag: when set as a window is being added or made 568 * visible, once the window has been shown then the system will 569 * poke the power manager's user activity (as if the user had woken 570 * up the device) to turn the screen on. */ 571 public static final int FLAG_TURN_SCREEN_ON = 0x00200000; 572 573 /** Window flag: when set the window will cause the keyguard to 574 * be dismissed, only if it is not a secure lock keyguard. Because such 575 * a keyguard is not needed for security, it will never re-appear if 576 * the user navigates to another window (in contrast to 577 * {@link #FLAG_SHOW_WHEN_LOCKED}, which will only temporarily 578 * hide both secure and non-secure keyguards but ensure they reappear 579 * when the user moves to another UI that doesn't hide them). 580 * If the keyguard is currently active and is secure (requires an 581 * unlock pattern) than the user will still need to confirm it before 582 * seeing this window, unless {@link #FLAG_SHOW_WHEN_LOCKED} has 583 * also been set. 584 */ 585 public static final int FLAG_DISMISS_KEYGUARD = 0x00400000; 586 587 /** Window flag: *sigh* The lock screen wants to continue running its 588 * animation while it is fading. A kind-of hack to allow this. Maybe 589 * in the future we just make this the default behavior. 590 * 591 * {@hide} */ 592 public static final int FLAG_KEEP_SURFACE_WHILE_ANIMATING = 0x10000000; 593 594 /** Window flag: special flag to limit the size of the window to be 595 * original size ([320x480] x density). Used to create window for applications 596 * running under compatibility mode. 597 * 598 * {@hide} */ 599 public static final int FLAG_COMPATIBLE_WINDOW = 0x20000000; 600 601 /** Window flag: a special option intended for system dialogs. When 602 * this flag is set, the window will demand focus unconditionally when 603 * it is created. 604 * {@hide} */ 605 public static final int FLAG_SYSTEM_ERROR = 0x40000000; 606 607 /** 608 * Given a particular set of window manager flags, determine whether 609 * such a window may be a target for an input method when it has 610 * focus. In particular, this checks the 611 * {@link #FLAG_NOT_FOCUSABLE} and {@link #FLAG_ALT_FOCUSABLE_IM} 612 * flags and returns true if the combination of the two corresponds 613 * to a window that needs to be behind the input method so that the 614 * user can type into it. 615 * 616 * @param flags The current window manager flags. 617 * 618 * @return Returns true if such a window should be behind/interact 619 * with an input method, false if not. 620 */ 621 public static boolean mayUseInputMethod(int flags) { 622 switch (flags&(FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) { 623 case 0: 624 case FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM: 625 return true; 626 } 627 return false; 628 } 629 630 /** 631 * Mask for {@link #softInputMode} of the bits that determine the 632 * desired visibility state of the soft input area for this window. 633 */ 634 public static final int SOFT_INPUT_MASK_STATE = 0x0f; 635 636 /** 637 * Visibility state for {@link #softInputMode}: no state has been specified. 638 */ 639 public static final int SOFT_INPUT_STATE_UNSPECIFIED = 0; 640 641 /** 642 * Visibility state for {@link #softInputMode}: please don't change the state of 643 * the soft input area. 644 */ 645 public static final int SOFT_INPUT_STATE_UNCHANGED = 1; 646 647 /** 648 * Visibility state for {@link #softInputMode}: please hide any soft input 649 * area when normally appropriate (when the user is navigating 650 * forward to your window). 651 */ 652 public static final int SOFT_INPUT_STATE_HIDDEN = 2; 653 654 /** 655 * Visibility state for {@link #softInputMode}: please always hide any 656 * soft input area when this window receives focus. 657 */ 658 public static final int SOFT_INPUT_STATE_ALWAYS_HIDDEN = 3; 659 660 /** 661 * Visibility state for {@link #softInputMode}: please show the soft 662 * input area when normally appropriate (when the user is navigating 663 * forward to your window). 664 */ 665 public static final int SOFT_INPUT_STATE_VISIBLE = 4; 666 667 /** 668 * Visibility state for {@link #softInputMode}: please always make the 669 * soft input area visible when this window receives input focus. 670 */ 671 public static final int SOFT_INPUT_STATE_ALWAYS_VISIBLE = 5; 672 673 /** 674 * Mask for {@link #softInputMode} of the bits that determine the 675 * way that the window should be adjusted to accommodate the soft 676 * input window. 677 */ 678 public static final int SOFT_INPUT_MASK_ADJUST = 0xf0; 679 680 /** Adjustment option for {@link #softInputMode}: nothing specified. 681 * The system will try to pick one or 682 * the other depending on the contents of the window. 683 */ 684 public static final int SOFT_INPUT_ADJUST_UNSPECIFIED = 0x00; 685 686 /** Adjustment option for {@link #softInputMode}: set to allow the 687 * window to be resized when an input 688 * method is shown, so that its contents are not covered by the input 689 * method. This can <em>not</em> be combined with 690 * {@link #SOFT_INPUT_ADJUST_PAN}; if 691 * neither of these are set, then the system will try to pick one or 692 * the other depending on the contents of the window. 693 */ 694 public static final int SOFT_INPUT_ADJUST_RESIZE = 0x10; 695 696 /** Adjustment option for {@link #softInputMode}: set to have a window 697 * pan when an input method is 698 * shown, so it doesn't need to deal with resizing but just panned 699 * by the framework to ensure the current input focus is visible. This 700 * can <em>not</em> be combined with {@link #SOFT_INPUT_ADJUST_RESIZE}; if 701 * neither of these are set, then the system will try to pick one or 702 * the other depending on the contents of the window. 703 */ 704 public static final int SOFT_INPUT_ADJUST_PAN = 0x20; 705 706 /** 707 * Bit for {@link #softInputMode}: set when the user has navigated 708 * forward to the window. This is normally set automatically for 709 * you by the system, though you may want to set it in certain cases 710 * when you are displaying a window yourself. This flag will always 711 * be cleared automatically after the window is displayed. 712 */ 713 public static final int SOFT_INPUT_IS_FORWARD_NAVIGATION = 0x100; 714 715 /** 716 * Default value for {@link #screenBrightness} and {@link #buttonBrightness} 717 * indicating that the brightness value is not overridden for this window 718 * and normal brightness policy should be used. 719 */ 720 public static final float BRIGHTNESS_OVERRIDE_NONE = -1.0f; 721 722 /** 723 * Value for {@link #screenBrightness} and {@link #buttonBrightness} 724 * indicating that the screen or button backlight brightness should be set 725 * to the lowest value when this window is in front. 726 */ 727 public static final float BRIGHTNESS_OVERRIDE_OFF = 0.0f; 728 729 /** 730 * Value for {@link #screenBrightness} and {@link #buttonBrightness} 731 * indicating that the screen or button backlight brightness should be set 732 * to the hightest value when this window is in front. 733 */ 734 public static final float BRIGHTNESS_OVERRIDE_FULL = 1.0f; 735 736 /** 737 * Desired operating mode for any soft input area. May any combination 738 * of: 739 * 740 * <ul> 741 * <li> One of the visibility states 742 * {@link #SOFT_INPUT_STATE_UNSPECIFIED}, {@link #SOFT_INPUT_STATE_UNCHANGED}, 743 * {@link #SOFT_INPUT_STATE_HIDDEN}, {@link #SOFT_INPUT_STATE_ALWAYS_VISIBLE}, or 744 * {@link #SOFT_INPUT_STATE_VISIBLE}. 745 * <li> One of the adjustment options 746 * {@link #SOFT_INPUT_ADJUST_UNSPECIFIED}, 747 * {@link #SOFT_INPUT_ADJUST_RESIZE}, or 748 * {@link #SOFT_INPUT_ADJUST_PAN}. 749 */ 750 public int softInputMode; 751 752 /** 753 * Placement of window within the screen as per {@link Gravity} 754 * 755 * @see Gravity 756 */ 757 public int gravity; 758 759 /** 760 * The horizontal margin, as a percentage of the container's width, 761 * between the container and the widget. 762 */ 763 public float horizontalMargin; 764 765 /** 766 * The vertical margin, as a percentage of the container's height, 767 * between the container and the widget. 768 */ 769 public float verticalMargin; 770 771 /** 772 * The desired bitmap format. May be one of the constants in 773 * {@link android.graphics.PixelFormat}. Default is OPAQUE. 774 */ 775 public int format; 776 777 /** 778 * A style resource defining the animations to use for this window. 779 * This must be a system resource; it can not be an application resource 780 * because the window manager does not have access to applications. 781 */ 782 public int windowAnimations; 783 784 /** 785 * An alpha value to apply to this entire window. 786 * An alpha of 1.0 means fully opaque and 0.0 means fully transparent 787 */ 788 public float alpha = 1.0f; 789 790 /** 791 * When {@link #FLAG_DIM_BEHIND} is set, this is the amount of dimming 792 * to apply. Range is from 1.0 for completely opaque to 0.0 for no 793 * dim. 794 */ 795 public float dimAmount = 1.0f; 796 797 /** 798 * This can be used to override the user's preferred brightness of 799 * the screen. A value of less than 0, the default, means to use the 800 * preferred screen brightness. 0 to 1 adjusts the brightness from 801 * dark to full bright. 802 */ 803 public float screenBrightness = BRIGHTNESS_OVERRIDE_NONE; 804 805 /** 806 * This can be used to override the standard behavior of the button and 807 * keyboard backlights. A value of less than 0, the default, means to 808 * use the standard backlight behavior. 0 to 1 adjusts the brightness 809 * from dark to full bright. 810 */ 811 public float buttonBrightness = BRIGHTNESS_OVERRIDE_NONE; 812 813 /** 814 * Identifier for this window. This will usually be filled in for 815 * you. 816 */ 817 public IBinder token = null; 818 819 /** 820 * Name of the package owning this window. 821 */ 822 public String packageName = null; 823 824 /** 825 * Specific orientation value for a window. 826 * May be any of the same values allowed 827 * for {@link android.content.pm.ActivityInfo#screenOrientation}. 828 * If not set, a default value of 829 * {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSPECIFIED} 830 * will be used. 831 */ 832 public int screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; 833 834 835 public LayoutParams() { 836 super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); 837 type = TYPE_APPLICATION; 838 format = PixelFormat.OPAQUE; 839 } 840 841 public LayoutParams(int _type) { 842 super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); 843 type = _type; 844 format = PixelFormat.OPAQUE; 845 } 846 847 public LayoutParams(int _type, int _flags) { 848 super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); 849 type = _type; 850 flags = _flags; 851 format = PixelFormat.OPAQUE; 852 } 853 854 public LayoutParams(int _type, int _flags, int _format) { 855 super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); 856 type = _type; 857 flags = _flags; 858 format = _format; 859 } 860 861 public LayoutParams(int w, int h, int _type, int _flags, int _format) { 862 super(w, h); 863 type = _type; 864 flags = _flags; 865 format = _format; 866 } 867 868 public LayoutParams(int w, int h, int xpos, int ypos, int _type, 869 int _flags, int _format) { 870 super(w, h); 871 x = xpos; 872 y = ypos; 873 type = _type; 874 flags = _flags; 875 format = _format; 876 } 877 878 public final void setTitle(CharSequence title) { 879 if (null == title) 880 title = ""; 881 882 mTitle = TextUtils.stringOrSpannedString(title); 883 } 884 885 public final CharSequence getTitle() { 886 return mTitle; 887 } 888 889 public int describeContents() { 890 return 0; 891 } 892 893 public void writeToParcel(Parcel out, int parcelableFlags) { 894 out.writeInt(width); 895 out.writeInt(height); 896 out.writeInt(x); 897 out.writeInt(y); 898 out.writeInt(type); 899 out.writeInt(memoryType); 900 out.writeInt(flags); 901 out.writeInt(softInputMode); 902 out.writeInt(gravity); 903 out.writeFloat(horizontalMargin); 904 out.writeFloat(verticalMargin); 905 out.writeInt(format); 906 out.writeInt(windowAnimations); 907 out.writeFloat(alpha); 908 out.writeFloat(dimAmount); 909 out.writeFloat(screenBrightness); 910 out.writeFloat(buttonBrightness); 911 out.writeStrongBinder(token); 912 out.writeString(packageName); 913 TextUtils.writeToParcel(mTitle, out, parcelableFlags); 914 out.writeInt(screenOrientation); 915 } 916 917 public static final Parcelable.Creator<LayoutParams> CREATOR 918 = new Parcelable.Creator<LayoutParams>() { 919 public LayoutParams createFromParcel(Parcel in) { 920 return new LayoutParams(in); 921 } 922 923 public LayoutParams[] newArray(int size) { 924 return new LayoutParams[size]; 925 } 926 }; 927 928 929 public LayoutParams(Parcel in) { 930 width = in.readInt(); 931 height = in.readInt(); 932 x = in.readInt(); 933 y = in.readInt(); 934 type = in.readInt(); 935 memoryType = in.readInt(); 936 flags = in.readInt(); 937 softInputMode = in.readInt(); 938 gravity = in.readInt(); 939 horizontalMargin = in.readFloat(); 940 verticalMargin = in.readFloat(); 941 format = in.readInt(); 942 windowAnimations = in.readInt(); 943 alpha = in.readFloat(); 944 dimAmount = in.readFloat(); 945 screenBrightness = in.readFloat(); 946 buttonBrightness = in.readFloat(); 947 token = in.readStrongBinder(); 948 packageName = in.readString(); 949 mTitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); 950 screenOrientation = in.readInt(); 951 } 952 953 @SuppressWarnings({"PointlessBitwiseExpression"}) 954 public static final int LAYOUT_CHANGED = 1<<0; 955 public static final int TYPE_CHANGED = 1<<1; 956 public static final int FLAGS_CHANGED = 1<<2; 957 public static final int FORMAT_CHANGED = 1<<3; 958 public static final int ANIMATION_CHANGED = 1<<4; 959 public static final int DIM_AMOUNT_CHANGED = 1<<5; 960 public static final int TITLE_CHANGED = 1<<6; 961 public static final int ALPHA_CHANGED = 1<<7; 962 public static final int MEMORY_TYPE_CHANGED = 1<<8; 963 public static final int SOFT_INPUT_MODE_CHANGED = 1<<9; 964 public static final int SCREEN_ORIENTATION_CHANGED = 1<<10; 965 public static final int SCREEN_BRIGHTNESS_CHANGED = 1<<11; 966 /** {@hide} */ 967 public static final int BUTTON_BRIGHTNESS_CHANGED = 1<<12; 968 969 // internal buffer to backup/restore parameters under compatibility mode. 970 private int[] mCompatibilityParamsBackup = null; 971 972 public final int copyFrom(LayoutParams o) { 973 int changes = 0; 974 975 if (width != o.width) { 976 width = o.width; 977 changes |= LAYOUT_CHANGED; 978 } 979 if (height != o.height) { 980 height = o.height; 981 changes |= LAYOUT_CHANGED; 982 } 983 if (x != o.x) { 984 x = o.x; 985 changes |= LAYOUT_CHANGED; 986 } 987 if (y != o.y) { 988 y = o.y; 989 changes |= LAYOUT_CHANGED; 990 } 991 if (horizontalWeight != o.horizontalWeight) { 992 horizontalWeight = o.horizontalWeight; 993 changes |= LAYOUT_CHANGED; 994 } 995 if (verticalWeight != o.verticalWeight) { 996 verticalWeight = o.verticalWeight; 997 changes |= LAYOUT_CHANGED; 998 } 999 if (horizontalMargin != o.horizontalMargin) { 1000 horizontalMargin = o.horizontalMargin; 1001 changes |= LAYOUT_CHANGED; 1002 } 1003 if (verticalMargin != o.verticalMargin) { 1004 verticalMargin = o.verticalMargin; 1005 changes |= LAYOUT_CHANGED; 1006 } 1007 if (type != o.type) { 1008 type = o.type; 1009 changes |= TYPE_CHANGED; 1010 } 1011 if (memoryType != o.memoryType) { 1012 memoryType = o.memoryType; 1013 changes |= MEMORY_TYPE_CHANGED; 1014 } 1015 if (flags != o.flags) { 1016 flags = o.flags; 1017 changes |= FLAGS_CHANGED; 1018 } 1019 if (softInputMode != o.softInputMode) { 1020 softInputMode = o.softInputMode; 1021 changes |= SOFT_INPUT_MODE_CHANGED; 1022 } 1023 if (gravity != o.gravity) { 1024 gravity = o.gravity; 1025 changes |= LAYOUT_CHANGED; 1026 } 1027 if (horizontalMargin != o.horizontalMargin) { 1028 horizontalMargin = o.horizontalMargin; 1029 changes |= LAYOUT_CHANGED; 1030 } 1031 if (verticalMargin != o.verticalMargin) { 1032 verticalMargin = o.verticalMargin; 1033 changes |= LAYOUT_CHANGED; 1034 } 1035 if (format != o.format) { 1036 format = o.format; 1037 changes |= FORMAT_CHANGED; 1038 } 1039 if (windowAnimations != o.windowAnimations) { 1040 windowAnimations = o.windowAnimations; 1041 changes |= ANIMATION_CHANGED; 1042 } 1043 if (token == null) { 1044 // NOTE: token only copied if the recipient doesn't 1045 // already have one. 1046 token = o.token; 1047 } 1048 if (packageName == null) { 1049 // NOTE: packageName only copied if the recipient doesn't 1050 // already have one. 1051 packageName = o.packageName; 1052 } 1053 if (!mTitle.equals(o.mTitle)) { 1054 mTitle = o.mTitle; 1055 changes |= TITLE_CHANGED; 1056 } 1057 if (alpha != o.alpha) { 1058 alpha = o.alpha; 1059 changes |= ALPHA_CHANGED; 1060 } 1061 if (dimAmount != o.dimAmount) { 1062 dimAmount = o.dimAmount; 1063 changes |= DIM_AMOUNT_CHANGED; 1064 } 1065 if (screenBrightness != o.screenBrightness) { 1066 screenBrightness = o.screenBrightness; 1067 changes |= SCREEN_BRIGHTNESS_CHANGED; 1068 } 1069 if (buttonBrightness != o.buttonBrightness) { 1070 buttonBrightness = o.buttonBrightness; 1071 changes |= BUTTON_BRIGHTNESS_CHANGED; 1072 } 1073 1074 if (screenOrientation != o.screenOrientation) { 1075 screenOrientation = o.screenOrientation; 1076 changes |= SCREEN_ORIENTATION_CHANGED; 1077 } 1078 return changes; 1079 } 1080 1081 @Override 1082 public String debug(String output) { 1083 output += "Contents of " + this + ":"; 1084 Log.d("Debug", output); 1085 output = super.debug(""); 1086 Log.d("Debug", output); 1087 Log.d("Debug", ""); 1088 Log.d("Debug", "WindowManager.LayoutParams={title=" + mTitle + "}"); 1089 return ""; 1090 } 1091 1092 @Override 1093 public String toString() { 1094 StringBuilder sb = new StringBuilder(256); 1095 sb.append("WM.LayoutParams{"); 1096 sb.append("("); 1097 sb.append(x); 1098 sb.append(','); 1099 sb.append(y); 1100 sb.append(")("); 1101 sb.append((width== MATCH_PARENT ?"fill":(width==WRAP_CONTENT?"wrap":width))); 1102 sb.append('x'); 1103 sb.append((height== MATCH_PARENT ?"fill":(height==WRAP_CONTENT?"wrap":height))); 1104 sb.append(")"); 1105 if (softInputMode != 0) { 1106 sb.append(" sim=#"); 1107 sb.append(Integer.toHexString(softInputMode)); 1108 } 1109 if (gravity != 0) { 1110 sb.append(" gr=#"); 1111 sb.append(Integer.toHexString(gravity)); 1112 } 1113 sb.append(" ty="); 1114 sb.append(type); 1115 sb.append(" fl=#"); 1116 sb.append(Integer.toHexString(flags)); 1117 sb.append(" fmt="); 1118 sb.append(format); 1119 if (windowAnimations != 0) { 1120 sb.append(" wanim=0x"); 1121 sb.append(Integer.toHexString(windowAnimations)); 1122 } 1123 if (screenOrientation != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { 1124 sb.append(" or="); 1125 sb.append(screenOrientation); 1126 } 1127 if ((flags & FLAG_COMPATIBLE_WINDOW) != 0) { 1128 sb.append(" compatible=true"); 1129 } 1130 sb.append('}'); 1131 return sb.toString(); 1132 } 1133 1134 /** 1135 * Scale the layout params' coordinates and size. 1136 * @hide 1137 */ 1138 public void scale(float scale) { 1139 x = (int) (x * scale + 0.5f); 1140 y = (int) (y * scale + 0.5f); 1141 if (width > 0) { 1142 width = (int) (width * scale + 0.5f); 1143 } 1144 if (height > 0) { 1145 height = (int) (height * scale + 0.5f); 1146 } 1147 } 1148 1149 /** 1150 * Backup the layout parameters used in compatibility mode. 1151 * @see LayoutParams#restore() 1152 */ 1153 void backup() { 1154 int[] backup = mCompatibilityParamsBackup; 1155 if (backup == null) { 1156 // we backup 4 elements, x, y, width, height 1157 backup = mCompatibilityParamsBackup = new int[4]; 1158 } 1159 backup[0] = x; 1160 backup[1] = y; 1161 backup[2] = width; 1162 backup[3] = height; 1163 } 1164 1165 /** 1166 * Restore the layout params' coordinates, size and gravity 1167 * @see LayoutParams#backup() 1168 */ 1169 void restore() { 1170 int[] backup = mCompatibilityParamsBackup; 1171 if (backup != null) { 1172 x = backup[0]; 1173 y = backup[1]; 1174 width = backup[2]; 1175 height = backup[3]; 1176 } 1177 } 1178 1179 private CharSequence mTitle = ""; 1180 } 1181} 1182