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