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