blob: c69c28154c2d7c5ba4ad831b6a8374b94f014a4f [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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;
Mitsuru Oshima3d914922009-05-13 22:29:15 -070021import android.graphics.Rect;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.os.IBinder;
23import android.os.Parcel;
24import android.os.Parcelable;
25import android.text.TextUtils;
26import android.util.Log;
27
28
29/**
30 * The interface that apps use to talk to the window manager.
31 * <p>
32 * Use <code>Context.getSystemService(Context.WINDOW_SERVICE)</code> to get one of these.
33 *
34 * @see android.content.Context#getSystemService
35 * @see android.content.Context#WINDOW_SERVICE
36 */
37public interface WindowManager extends ViewManager {
38 /**
39 * Exception that is thrown when trying to add view whose
40 * {@link WindowManager.LayoutParams} {@link WindowManager.LayoutParams#token}
41 * is invalid.
42 */
43 public static class BadTokenException extends RuntimeException {
44 public BadTokenException() {
45 }
46
47 public BadTokenException(String name) {
48 super(name);
49 }
50 }
51
52 /**
53 * Use this method to get the default Display object.
54 *
55 * @return default Display object
56 */
57 public Display getDefaultDisplay();
58
59 /**
60 * Special variation of {@link #removeView} that immediately invokes
61 * the given view hierarchy's {@link View#onDetachedFromWindow()
62 * View.onDetachedFromWindow()} methods before returning. This is not
63 * for normal applications; using it correctly requires great care.
64 *
65 * @param view The view to be removed.
66 */
67 public void removeViewImmediate(View view);
68
69 public static class LayoutParams extends ViewGroup.LayoutParams
70 implements Parcelable {
71 /**
72 * X position for this window. With the default gravity it is ignored.
73 * When using {@link Gravity#LEFT} or {@link Gravity#RIGHT} it provides
74 * an offset from the given edge.
75 */
76 public int x;
77
78 /**
79 * Y position for this window. With the default gravity it is ignored.
80 * When using {@link Gravity#TOP} or {@link Gravity#BOTTOM} it provides
81 * an offset from the given edge.
82 */
83 public int y;
84
85 /**
86 * Indicates how much of the extra space will be allocated horizontally
87 * to the view associated with these LayoutParams. Specify 0 if the view
88 * should not be stretched. Otherwise the extra pixels will be pro-rated
89 * among all views whose weight is greater than 0.
90 */
91 public float horizontalWeight;
92
93 /**
94 * Indicates how much of the extra space will be allocated vertically
95 * to the view associated with these LayoutParams. Specify 0 if the view
96 * should not be stretched. Otherwise the extra pixels will be pro-rated
97 * among all views whose weight is greater than 0.
98 */
99 public float verticalWeight;
100
101 /**
102 * The general type of window. There are three main classes of
103 * window types:
104 * <ul>
105 * <li> <strong>Application windows</strong> (ranging from
106 * {@link #FIRST_APPLICATION_WINDOW} to
107 * {@link #LAST_APPLICATION_WINDOW}) are normal top-level application
108 * windows. For these types of windows, the {@link #token} must be
109 * set to the token of the activity they are a part of (this will
110 * normally be done for you if {@link #token} is null).
111 * <li> <strong>Sub-windows</strong> (ranging from
112 * {@link #FIRST_SUB_WINDOW} to
113 * {@link #LAST_SUB_WINDOW}) are associated with another top-level
114 * window. For these types of windows, the {@link #token} must be
115 * the token of the window it is attached to.
116 * <li> <strong>System windows</strong> (ranging from
117 * {@link #FIRST_SYSTEM_WINDOW} to
118 * {@link #LAST_SYSTEM_WINDOW}) are special types of windows for
119 * use by the system for specific purposes. They should not normally
120 * be used by applications, and a special permission is required
121 * to use them.
122 * </ul>
123 *
124 * @see #TYPE_BASE_APPLICATION
125 * @see #TYPE_APPLICATION
126 * @see #TYPE_APPLICATION_STARTING
127 * @see #TYPE_APPLICATION_PANEL
128 * @see #TYPE_APPLICATION_MEDIA
129 * @see #TYPE_APPLICATION_SUB_PANEL
130 * @see #TYPE_APPLICATION_ATTACHED_DIALOG
131 * @see #TYPE_STATUS_BAR
132 * @see #TYPE_SEARCH_BAR
133 * @see #TYPE_PHONE
134 * @see #TYPE_SYSTEM_ALERT
135 * @see #TYPE_KEYGUARD
136 * @see #TYPE_TOAST
137 * @see #TYPE_SYSTEM_OVERLAY
138 * @see #TYPE_PRIORITY_PHONE
139 * @see #TYPE_STATUS_BAR_PANEL
140 * @see #TYPE_SYSTEM_DIALOG
141 * @see #TYPE_KEYGUARD_DIALOG
142 * @see #TYPE_SYSTEM_ERROR
143 * @see #TYPE_INPUT_METHOD
144 * @see #TYPE_INPUT_METHOD_DIALOG
145 */
146 public int type;
147
148 /**
149 * Start of window types that represent normal application windows.
150 */
151 public static final int FIRST_APPLICATION_WINDOW = 1;
152
153 /**
154 * Window type: an application window that serves as the "base" window
155 * of the overall application; all other application windows will
156 * appear on top of it.
157 */
158 public static final int TYPE_BASE_APPLICATION = 1;
159
160 /**
161 * Window type: a normal application window. The {@link #token} must be
162 * an Activity token identifying who the window belongs to.
163 */
164 public static final int TYPE_APPLICATION = 2;
165
166 /**
167 * Window type: special application window that is displayed while the
168 * application is starting. Not for use by applications themselves;
169 * this is used by the system to display something until the
170 * application can show its own windows.
171 */
172 public static final int TYPE_APPLICATION_STARTING = 3;
173
174 /**
175 * End of types of application windows.
176 */
177 public static final int LAST_APPLICATION_WINDOW = 99;
178
179 /**
180 * Start of types of sub-windows. The {@link #token} of these windows
181 * must be set to the window they are attached to. These types of
182 * windows are kept next to their attached window in Z-order, and their
183 * coordinate space is relative to their attached window.
184 */
185 public static final int FIRST_SUB_WINDOW = 1000;
186
187 /**
188 * Window type: a panel on top of an application window. These windows
189 * appear on top of their attached window.
190 */
191 public static final int TYPE_APPLICATION_PANEL = FIRST_SUB_WINDOW;
192
193 /**
194 * Window type: window for showing media (e.g. video). These windows
195 * are displayed behind their attached window.
196 */
197 public static final int TYPE_APPLICATION_MEDIA = FIRST_SUB_WINDOW+1;
198
199 /**
200 * Window type: a sub-panel on top of an application window. These
201 * windows are displayed on top their attached window and any
202 * {@link #TYPE_APPLICATION_PANEL} panels.
203 */
204 public static final int TYPE_APPLICATION_SUB_PANEL = FIRST_SUB_WINDOW+2;
205
206 /** Window type: like {@link #TYPE_APPLICATION_PANEL}, but layout
207 * of the window happens as that of a top-level window, <em>not</em>
208 * as a child of its container.
209 */
210 public static final int TYPE_APPLICATION_ATTACHED_DIALOG = FIRST_SUB_WINDOW+3;
211
212 /**
213 * 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
469 /** Window flag: a special option intended for system dialogs. When
470 * this flag is set, the window will demand focus unconditionally when
471 * it is created.
472 * {@hide} */
473 public static final int FLAG_SYSTEM_ERROR = 0x40000000;
474
475 /**
476 * Given a particular set of window manager flags, determine whether
477 * such a window may be a target for an input method when it has
478 * focus. In particular, this checks the
479 * {@link #FLAG_NOT_FOCUSABLE} and {@link #FLAG_ALT_FOCUSABLE_IM}
480 * flags and returns true if the combination of the two corresponds
481 * to a window that needs to be behind the input method so that the
482 * user can type into it.
483 *
484 * @param flags The current window manager flags.
485 *
486 * @return Returns true if such a window should be behind/interact
487 * with an input method, false if not.
488 */
489 public static boolean mayUseInputMethod(int flags) {
490 switch (flags&(FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
491 case 0:
492 case FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM:
493 return true;
494 }
495 return false;
496 }
497
498 /**
499 * Mask for {@link #softInputMode} of the bits that determine the
500 * desired visibility state of the soft input area for this window.
501 */
502 public static final int SOFT_INPUT_MASK_STATE = 0x0f;
503
504 /**
505 * Visibility state for {@link #softInputMode}: no state has been specified.
506 */
507 public static final int SOFT_INPUT_STATE_UNSPECIFIED = 0;
508
509 /**
510 * Visibility state for {@link #softInputMode}: please don't change the state of
511 * the soft input area.
512 */
513 public static final int SOFT_INPUT_STATE_UNCHANGED = 1;
514
515 /**
516 * Visibility state for {@link #softInputMode}: please hide any soft input
517 * area when normally appropriate (when the user is navigating
518 * forward to your window).
519 */
520 public static final int SOFT_INPUT_STATE_HIDDEN = 2;
521
522 /**
523 * Visibility state for {@link #softInputMode}: please always hide any
524 * soft input area when this window receives focus.
525 */
526 public static final int SOFT_INPUT_STATE_ALWAYS_HIDDEN = 3;
527
528 /**
529 * Visibility state for {@link #softInputMode}: please show the soft
530 * input area when normally appropriate (when the user is navigating
531 * forward to your window).
532 */
533 public static final int SOFT_INPUT_STATE_VISIBLE = 4;
534
535 /**
536 * Visibility state for {@link #softInputMode}: please always make the
537 * soft input area visible when this window receives input focus.
538 */
539 public static final int SOFT_INPUT_STATE_ALWAYS_VISIBLE = 5;
540
541 /**
542 * Mask for {@link #softInputMode} of the bits that determine the
543 * way that the window should be adjusted to accommodate the soft
544 * input window.
545 */
546 public static final int SOFT_INPUT_MASK_ADJUST = 0xf0;
547
548 /** Adjustment option for {@link #softInputMode}: nothing specified.
549 * The system will try to pick one or
550 * the other depending on the contents of the window.
551 */
552 public static final int SOFT_INPUT_ADJUST_UNSPECIFIED = 0x00;
553
554 /** Adjustment option for {@link #softInputMode}: set to allow the
555 * window to be resized when an input
556 * method is shown, so that its contents are not covered by the input
557 * method. This can <em>not<em> be combined with
558 * {@link #SOFT_INPUT_ADJUST_PAN}; if
559 * neither of these are set, then the system will try to pick one or
560 * the other depending on the contents of the window.
561 */
562 public static final int SOFT_INPUT_ADJUST_RESIZE = 0x10;
563
564 /** Adjustment option for {@link #softInputMode}: set to have a window
565 * pan when an input method is
566 * shown, so it doesn't need to deal with resizing but just panned
567 * by the framework to ensure the current input focus is visible. This
568 * can <em>not<em> be combined with {@link #SOFT_INPUT_ADJUST_RESIZE}; if
569 * neither of these are set, then the system will try to pick one or
570 * the other depending on the contents of the window.
571 */
572 public static final int SOFT_INPUT_ADJUST_PAN = 0x20;
573
574 /**
575 * Bit for {@link #softInputMode}: set when the user has navigated
576 * forward to the window. This is normally set automatically for
577 * you by the system, though you may want to set it in certain cases
578 * when you are displaying a window yourself. This flag will always
579 * be cleared automatically after the window is displayed.
580 */
581 public static final int SOFT_INPUT_IS_FORWARD_NAVIGATION = 0x100;
582
583 /**
584 * Desired operating mode for any soft input area. May any combination
585 * of:
586 *
587 * <ul>
588 * <li> One of the visibility states
589 * {@link #SOFT_INPUT_STATE_UNSPECIFIED}, {@link #SOFT_INPUT_STATE_UNCHANGED},
590 * {@link #SOFT_INPUT_STATE_HIDDEN}, {@link #SOFT_INPUT_STATE_ALWAYS_VISIBLE}, or
591 * {@link #SOFT_INPUT_STATE_VISIBLE}.
592 * <li> One of the adjustment options
593 * {@link #SOFT_INPUT_ADJUST_UNSPECIFIED},
594 * {@link #SOFT_INPUT_ADJUST_RESIZE}, or
595 * {@link #SOFT_INPUT_ADJUST_PAN}.
596 */
597 public int softInputMode;
598
599 /**
600 * Placement of window within the screen as per {@link Gravity}
601 *
602 * @see Gravity
603 */
604 public int gravity;
605
606 /**
607 * The horizontal margin, as a percentage of the container's width,
608 * between the container and the widget.
609 */
610 public float horizontalMargin;
611
612 /**
613 * The vertical margin, as a percentage of the container's height,
614 * between the container and the widget.
615 */
616 public float verticalMargin;
617
618 /**
619 * The desired bitmap format. May be one of the constants in
620 * {@link android.graphics.PixelFormat}. Default is OPAQUE.
621 */
622 public int format;
623
624 /**
625 * A style resource defining the animations to use for this window.
626 * This must be a system resource; it can not be an application resource
627 * because the window manager does not have access to applications.
628 */
629 public int windowAnimations;
630
631 /**
632 * An alpha value to apply to this entire window.
633 * An alpha of 1.0 means fully opaque and 0.0 means fully transparent
634 */
635 public float alpha = 1.0f;
636
637 /**
638 * When {@link #FLAG_DIM_BEHIND} is set, this is the amount of dimming
639 * to apply. Range is from 1.0 for completely opaque to 0.0 for no
640 * dim.
641 */
642 public float dimAmount = 1.0f;
643
644 /**
645 * This can be used to override the user's preferred brightness of
646 * the screen. A value of less than 0, the default, means to use the
647 * preferred screen brightness. 0 to 1 adjusts the brightness from
648 * dark to full bright.
649 */
650 public float screenBrightness = -1.0f;
651
652 /**
653 * Identifier for this window. This will usually be filled in for
654 * you.
655 */
656 public IBinder token = null;
657
658 /**
659 * Name of the package owning this window.
660 */
661 public String packageName = null;
662
663 /**
664 * Specific orientation value for a window.
665 * May be any of the same values allowed
666 * for {@link android.content.pm.ActivityInfo#screenOrientation}.
667 * If not set, a default value of
668 * {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSPECIFIED}
669 * will be used.
670 */
671 public int screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
672
673
674 public LayoutParams() {
675 super(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
676 type = TYPE_APPLICATION;
677 format = PixelFormat.OPAQUE;
678 }
679
680 public LayoutParams(int _type) {
681 super(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
682 type = _type;
683 format = PixelFormat.OPAQUE;
684 }
685
686 public LayoutParams(int _type, int _flags) {
687 super(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
688 type = _type;
689 flags = _flags;
690 format = PixelFormat.OPAQUE;
691 }
692
693 public LayoutParams(int _type, int _flags, int _format) {
694 super(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
695 type = _type;
696 flags = _flags;
697 format = _format;
698 }
699
700 public LayoutParams(int w, int h, int _type, int _flags, int _format) {
701 super(w, h);
702 type = _type;
703 flags = _flags;
704 format = _format;
705 }
706
707 public LayoutParams(int w, int h, int xpos, int ypos, int _type,
708 int _flags, int _format) {
709 super(w, h);
710 x = xpos;
711 y = ypos;
712 type = _type;
713 flags = _flags;
714 format = _format;
715 }
716
717 public final void setTitle(CharSequence title) {
718 if (null == title)
719 title = "";
720
721 mTitle = TextUtils.stringOrSpannedString(title);
722 }
723
724 public final CharSequence getTitle() {
725 return mTitle;
726 }
727
728 public int describeContents() {
729 return 0;
730 }
731
732 public void writeToParcel(Parcel out, int parcelableFlags) {
733 out.writeInt(width);
734 out.writeInt(height);
735 out.writeInt(x);
736 out.writeInt(y);
737 out.writeInt(type);
738 out.writeInt(memoryType);
739 out.writeInt(flags);
740 out.writeInt(softInputMode);
741 out.writeInt(gravity);
742 out.writeFloat(horizontalMargin);
743 out.writeFloat(verticalMargin);
744 out.writeInt(format);
745 out.writeInt(windowAnimations);
746 out.writeFloat(alpha);
747 out.writeFloat(dimAmount);
748 out.writeFloat(screenBrightness);
749 out.writeStrongBinder(token);
750 out.writeString(packageName);
751 TextUtils.writeToParcel(mTitle, out, parcelableFlags);
752 out.writeInt(screenOrientation);
753 }
754
755 public static final Parcelable.Creator<LayoutParams> CREATOR
756 = new Parcelable.Creator<LayoutParams>() {
757 public LayoutParams createFromParcel(Parcel in) {
758 return new LayoutParams(in);
759 }
760
761 public LayoutParams[] newArray(int size) {
762 return new LayoutParams[size];
763 }
764 };
765
766
767 public LayoutParams(Parcel in) {
768 width = in.readInt();
769 height = in.readInt();
770 x = in.readInt();
771 y = in.readInt();
772 type = in.readInt();
773 memoryType = in.readInt();
774 flags = in.readInt();
775 softInputMode = in.readInt();
776 gravity = in.readInt();
777 horizontalMargin = in.readFloat();
778 verticalMargin = in.readFloat();
779 format = in.readInt();
780 windowAnimations = in.readInt();
781 alpha = in.readFloat();
782 dimAmount = in.readFloat();
783 screenBrightness = in.readFloat();
784 token = in.readStrongBinder();
785 packageName = in.readString();
786 mTitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
787 screenOrientation = in.readInt();
788 }
789
790 public static final int LAYOUT_CHANGED = 1<<0;
791 public static final int TYPE_CHANGED = 1<<1;
792 public static final int FLAGS_CHANGED = 1<<2;
793 public static final int FORMAT_CHANGED = 1<<3;
794 public static final int ANIMATION_CHANGED = 1<<4;
795 public static final int DIM_AMOUNT_CHANGED = 1<<5;
796 public static final int TITLE_CHANGED = 1<<6;
797 public static final int ALPHA_CHANGED = 1<<7;
798 public static final int MEMORY_TYPE_CHANGED = 1<<8;
799 public static final int SOFT_INPUT_MODE_CHANGED = 1<<9;
800 public static final int SCREEN_ORIENTATION_CHANGED = 1<<10;
801 public static final int SCREEN_BRIGHTNESS_CHANGED = 1<<11;
802
803 public final int copyFrom(LayoutParams o) {
804 int changes = 0;
805
806 if (width != o.width) {
807 width = o.width;
808 changes |= LAYOUT_CHANGED;
809 }
810 if (height != o.height) {
811 height = o.height;
812 changes |= LAYOUT_CHANGED;
813 }
814 if (x != o.x) {
815 x = o.x;
816 changes |= LAYOUT_CHANGED;
817 }
818 if (y != o.y) {
819 y = o.y;
820 changes |= LAYOUT_CHANGED;
821 }
822 if (horizontalWeight != o.horizontalWeight) {
823 horizontalWeight = o.horizontalWeight;
824 changes |= LAYOUT_CHANGED;
825 }
826 if (verticalWeight != o.verticalWeight) {
827 verticalWeight = o.verticalWeight;
828 changes |= LAYOUT_CHANGED;
829 }
830 if (horizontalMargin != o.horizontalMargin) {
831 horizontalMargin = o.horizontalMargin;
832 changes |= LAYOUT_CHANGED;
833 }
834 if (verticalMargin != o.verticalMargin) {
835 verticalMargin = o.verticalMargin;
836 changes |= LAYOUT_CHANGED;
837 }
838 if (type != o.type) {
839 type = o.type;
840 changes |= TYPE_CHANGED;
841 }
842 if (memoryType != o.memoryType) {
843 memoryType = o.memoryType;
844 changes |= MEMORY_TYPE_CHANGED;
845 }
846 if (flags != o.flags) {
847 flags = o.flags;
848 changes |= FLAGS_CHANGED;
849 }
850 if (softInputMode != o.softInputMode) {
851 softInputMode = o.softInputMode;
852 changes |= SOFT_INPUT_MODE_CHANGED;
853 }
854 if (gravity != o.gravity) {
855 gravity = o.gravity;
856 changes |= LAYOUT_CHANGED;
857 }
858 if (horizontalMargin != o.horizontalMargin) {
859 horizontalMargin = o.horizontalMargin;
860 changes |= LAYOUT_CHANGED;
861 }
862 if (verticalMargin != o.verticalMargin) {
863 verticalMargin = o.verticalMargin;
864 changes |= LAYOUT_CHANGED;
865 }
866 if (format != o.format) {
867 format = o.format;
868 changes |= FORMAT_CHANGED;
869 }
870 if (windowAnimations != o.windowAnimations) {
871 windowAnimations = o.windowAnimations;
872 changes |= ANIMATION_CHANGED;
873 }
874 if (token == null) {
875 // NOTE: token only copied if the recipient doesn't
876 // already have one.
877 token = o.token;
878 }
879 if (packageName == null) {
880 // NOTE: packageName only copied if the recipient doesn't
881 // already have one.
882 packageName = o.packageName;
883 }
884 if (!mTitle.equals(o.mTitle)) {
885 mTitle = o.mTitle;
886 changes |= TITLE_CHANGED;
887 }
888 if (alpha != o.alpha) {
889 alpha = o.alpha;
890 changes |= ALPHA_CHANGED;
891 }
892 if (dimAmount != o.dimAmount) {
893 dimAmount = o.dimAmount;
894 changes |= DIM_AMOUNT_CHANGED;
895 }
896 if (screenBrightness != o.screenBrightness) {
897 screenBrightness = o.screenBrightness;
898 changes |= SCREEN_BRIGHTNESS_CHANGED;
899 }
900
901 if (screenOrientation != o.screenOrientation) {
902 screenOrientation = o.screenOrientation;
903 changes |= SCREEN_ORIENTATION_CHANGED;
904 }
905 return changes;
906 }
907
908 @Override
909 public String debug(String output) {
910 output += "Contents of " + this + ":";
911 Log.d("Debug", output);
912 output = super.debug("");
913 Log.d("Debug", output);
914 Log.d("Debug", "");
915 Log.d("Debug", "WindowManager.LayoutParams={title=" + mTitle + "}");
916 return "";
917 }
918
919 @Override
920 public String toString() {
921 StringBuilder sb = new StringBuilder(256);
922 sb.append("WM.LayoutParams{");
923 sb.append("(");
924 sb.append(x);
925 sb.append(',');
926 sb.append(y);
927 sb.append(")(");
928 sb.append((width==FILL_PARENT?"fill":(width==WRAP_CONTENT?"wrap":width)));
929 sb.append('x');
930 sb.append((height==FILL_PARENT?"fill":(height==WRAP_CONTENT?"wrap":height)));
931 sb.append(")");
932 if (softInputMode != 0) {
933 sb.append(" sim=#");
934 sb.append(Integer.toHexString(softInputMode));
935 }
936 if (gravity != 0) {
937 sb.append(" gr=#");
938 sb.append(Integer.toHexString(gravity));
939 }
940 sb.append(" ty=");
941 sb.append(type);
942 sb.append(" fl=#");
943 sb.append(Integer.toHexString(flags));
944 sb.append(" fmt=");
945 sb.append(format);
946 if (windowAnimations != 0) {
947 sb.append(" wanim=0x");
948 sb.append(Integer.toHexString(windowAnimations));
949 }
950 if (screenOrientation != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
951 sb.append(" or=");
952 sb.append(screenOrientation);
953 }
954 sb.append('}');
955 return sb.toString();
956 }
Mitsuru Oshima8d112672009-04-27 12:01:23 -0700957
Mitsuru Oshima3d914922009-05-13 22:29:15 -0700958 /**
959 * Scale the layout params' coordinates and size.
960 * Returns the original info as a backup so that the caller can
961 * restore the layout params;
962 */
963 void scale(float scale, int[] backup) {
Mitsuru Oshima8d112672009-04-27 12:01:23 -0700964 if (scale != 1.0f) {
Mitsuru Oshima3d914922009-05-13 22:29:15 -0700965 backup[0] = x;
966 backup[1] = y;
Mitsuru Oshima8d112672009-04-27 12:01:23 -0700967 x *= scale;
968 y *= scale;
969 if (width > 0) {
Mitsuru Oshima3d914922009-05-13 22:29:15 -0700970 backup[2] = width;
Mitsuru Oshima8d112672009-04-27 12:01:23 -0700971 width *= scale;
972 }
973 if (height > 0) {
Mitsuru Oshima3d914922009-05-13 22:29:15 -0700974 backup[3] = height;
Mitsuru Oshima8d112672009-04-27 12:01:23 -0700975 height *= scale;
976 }
977 }
978 }
979
Mitsuru Oshima3d914922009-05-13 22:29:15 -0700980 /**
981 * Restore the layout params' coordinates and size.
982 */
983 void restore(int[] backup) {
984 x = backup[0];
985 y = backup[1];
986 if (width > 0) {
987 width = backup[2];
988 }
989 if (height > 0) {
990 height = backup[3];
991 }
992 }
993
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800994 private CharSequence mTitle = "";
995 }
996}