WindowManager.java revision cc4f7db698f88b633a286d8ab1105b28a474cd09
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    /**
69     * Return true if this window manager is configured to request hardware
70     * accelerated windows.  This does <em>not</em> guarantee that they will
71     * actually be accelerated, since that depends on the device supporting them.
72     * @hide
73     */
74    public boolean isHardwareAccelerated();
75
76    public static class LayoutParams extends ViewGroup.LayoutParams
77            implements Parcelable {
78        /**
79         * X position for this window.  With the default gravity it is ignored.
80         * When using {@link Gravity#LEFT} or {@link Gravity#START} or {@link Gravity#RIGHT} or
81         * {@link Gravity#END} it provides an offset from the given edge.
82         */
83        @ViewDebug.ExportedProperty
84        public int x;
85
86        /**
87         * Y position for this window.  With the default gravity it is ignored.
88         * When using {@link Gravity#TOP} or {@link Gravity#BOTTOM} it provides
89         * an offset from the given edge.
90         */
91        @ViewDebug.ExportedProperty
92        public int y;
93
94        /**
95         * Indicates how much of the extra space will be allocated horizontally
96         * to the view associated with these LayoutParams. Specify 0 if the view
97         * should not be stretched. Otherwise the extra pixels will be pro-rated
98         * among all views whose weight is greater than 0.
99         */
100        @ViewDebug.ExportedProperty
101        public float horizontalWeight;
102
103        /**
104         * Indicates how much of the extra space will be allocated vertically
105         * to the view associated with these LayoutParams. Specify 0 if the view
106         * should not be stretched. Otherwise the extra pixels will be pro-rated
107         * among all views whose weight is greater than 0.
108         */
109        @ViewDebug.ExportedProperty
110        public float verticalWeight;
111
112        /**
113         * The general type of window.  There are three main classes of
114         * window types:
115         * <ul>
116         * <li> <strong>Application windows</strong> (ranging from
117         * {@link #FIRST_APPLICATION_WINDOW} to
118         * {@link #LAST_APPLICATION_WINDOW}) are normal top-level application
119         * windows.  For these types of windows, the {@link #token} must be
120         * set to the token of the activity they are a part of (this will
121         * normally be done for you if {@link #token} is null).
122         * <li> <strong>Sub-windows</strong> (ranging from
123         * {@link #FIRST_SUB_WINDOW} to
124         * {@link #LAST_SUB_WINDOW}) are associated with another top-level
125         * window.  For these types of windows, the {@link #token} must be
126         * the token of the window it is attached to.
127         * <li> <strong>System windows</strong> (ranging from
128         * {@link #FIRST_SYSTEM_WINDOW} to
129         * {@link #LAST_SYSTEM_WINDOW}) are special types of windows for
130         * use by the system for specific purposes.  They should not normally
131         * be used by applications, and a special permission is required
132         * to use them.
133         * </ul>
134         *
135         * @see #TYPE_BASE_APPLICATION
136         * @see #TYPE_APPLICATION
137         * @see #TYPE_APPLICATION_STARTING
138         * @see #TYPE_APPLICATION_PANEL
139         * @see #TYPE_APPLICATION_MEDIA
140         * @see #TYPE_APPLICATION_SUB_PANEL
141         * @see #TYPE_APPLICATION_ATTACHED_DIALOG
142         * @see #TYPE_STATUS_BAR
143         * @see #TYPE_SEARCH_BAR
144         * @see #TYPE_PHONE
145         * @see #TYPE_SYSTEM_ALERT
146         * @see #TYPE_KEYGUARD
147         * @see #TYPE_TOAST
148         * @see #TYPE_SYSTEM_OVERLAY
149         * @see #TYPE_PRIORITY_PHONE
150         * @see #TYPE_STATUS_BAR_PANEL
151         * @see #TYPE_SYSTEM_DIALOG
152         * @see #TYPE_KEYGUARD_DIALOG
153         * @see #TYPE_SYSTEM_ERROR
154         * @see #TYPE_INPUT_METHOD
155         * @see #TYPE_INPUT_METHOD_DIALOG
156         */
157        @ViewDebug.ExportedProperty(mapping = {
158            @ViewDebug.IntToString(from = TYPE_BASE_APPLICATION, to = "TYPE_BASE_APPLICATION"),
159            @ViewDebug.IntToString(from = TYPE_APPLICATION, to = "TYPE_APPLICATION"),
160            @ViewDebug.IntToString(from = TYPE_APPLICATION_STARTING, to = "TYPE_APPLICATION_STARTING"),
161            @ViewDebug.IntToString(from = TYPE_APPLICATION_PANEL, to = "TYPE_APPLICATION_PANEL"),
162            @ViewDebug.IntToString(from = TYPE_APPLICATION_MEDIA, to = "TYPE_APPLICATION_MEDIA"),
163            @ViewDebug.IntToString(from = TYPE_APPLICATION_SUB_PANEL, to = "TYPE_APPLICATION_SUB_PANEL"),
164            @ViewDebug.IntToString(from = TYPE_APPLICATION_ATTACHED_DIALOG, to = "TYPE_APPLICATION_ATTACHED_DIALOG"),
165            @ViewDebug.IntToString(from = TYPE_STATUS_BAR, to = "TYPE_STATUS_BAR"),
166            @ViewDebug.IntToString(from = TYPE_SEARCH_BAR, to = "TYPE_SEARCH_BAR"),
167            @ViewDebug.IntToString(from = TYPE_PHONE, to = "TYPE_PHONE"),
168            @ViewDebug.IntToString(from = TYPE_SYSTEM_ALERT, to = "TYPE_SYSTEM_ALERT"),
169            @ViewDebug.IntToString(from = TYPE_KEYGUARD, to = "TYPE_KEYGUARD"),
170            @ViewDebug.IntToString(from = TYPE_TOAST, to = "TYPE_TOAST"),
171            @ViewDebug.IntToString(from = TYPE_SYSTEM_OVERLAY, to = "TYPE_SYSTEM_OVERLAY"),
172            @ViewDebug.IntToString(from = TYPE_PRIORITY_PHONE, to = "TYPE_PRIORITY_PHONE"),
173            @ViewDebug.IntToString(from = TYPE_STATUS_BAR_PANEL, to = "TYPE_STATUS_BAR_PANEL"),
174            @ViewDebug.IntToString(from = TYPE_STATUS_BAR_SUB_PANEL, to = "TYPE_STATUS_BAR_SUB_PANEL"),
175            @ViewDebug.IntToString(from = TYPE_SYSTEM_DIALOG, to = "TYPE_SYSTEM_DIALOG"),
176            @ViewDebug.IntToString(from = TYPE_KEYGUARD_DIALOG, to = "TYPE_KEYGUARD_DIALOG"),
177            @ViewDebug.IntToString(from = TYPE_SYSTEM_ERROR, to = "TYPE_SYSTEM_ERROR"),
178            @ViewDebug.IntToString(from = TYPE_INPUT_METHOD, to = "TYPE_INPUT_METHOD"),
179            @ViewDebug.IntToString(from = TYPE_INPUT_METHOD_DIALOG, to = "TYPE_INPUT_METHOD_DIALOG"),
180            @ViewDebug.IntToString(from = TYPE_SECURE_SYSTEM_OVERLAY, to = "TYPE_SECURE_SYSTEM_OVERLAY"),
181            @ViewDebug.IntToString(from = TYPE_BOOT_PROGRESS, to = "TYPE_BOOT_PROGRESS")
182        })
183        public int type;
184
185        /**
186         * Start of window types that represent normal application windows.
187         */
188        public static final int FIRST_APPLICATION_WINDOW = 1;
189
190        /**
191         * Window type: an application window that serves as the "base" window
192         * of the overall application; all other application windows will
193         * appear on top of it.
194         */
195        public static final int TYPE_BASE_APPLICATION   = 1;
196
197        /**
198         * Window type: a normal application window.  The {@link #token} must be
199         * an Activity token identifying who the window belongs to.
200         */
201        public static final int TYPE_APPLICATION        = 2;
202
203        /**
204         * Window type: special application window that is displayed while the
205         * application is starting.  Not for use by applications themselves;
206         * this is used by the system to display something until the
207         * application can show its own windows.
208         */
209        public static final int TYPE_APPLICATION_STARTING = 3;
210
211        /**
212         * End of types of application windows.
213         */
214        public static final int LAST_APPLICATION_WINDOW = 99;
215
216        /**
217         * Start of types of sub-windows.  The {@link #token} of these windows
218         * must be set to the window they are attached to.  These types of
219         * windows are kept next to their attached window in Z-order, and their
220         * coordinate space is relative to their attached window.
221         */
222        public static final int FIRST_SUB_WINDOW        = 1000;
223
224        /**
225         * Window type: a panel on top of an application window.  These windows
226         * appear on top of their attached window.
227         */
228        public static final int TYPE_APPLICATION_PANEL  = FIRST_SUB_WINDOW;
229
230        /**
231         * Window type: window for showing media (e.g. video).  These windows
232         * are displayed behind their attached window.
233         */
234        public static final int TYPE_APPLICATION_MEDIA  = FIRST_SUB_WINDOW+1;
235
236        /**
237         * Window type: a sub-panel on top of an application window.  These
238         * windows are displayed on top their attached window and any
239         * {@link #TYPE_APPLICATION_PANEL} panels.
240         */
241        public static final int TYPE_APPLICATION_SUB_PANEL = FIRST_SUB_WINDOW+2;
242
243        /** Window type: like {@link #TYPE_APPLICATION_PANEL}, but layout
244         * of the window happens as that of a top-level window, <em>not</em>
245         * as a child of its container.
246         */
247        public static final int TYPE_APPLICATION_ATTACHED_DIALOG = FIRST_SUB_WINDOW+3;
248
249        /**
250         * Window type: window for showing overlays on top of media windows.
251         * These windows are displayed between TYPE_APPLICATION_MEDIA and the
252         * application window.  They should be translucent to be useful.  This
253         * is a big ugly hack so:
254         * @hide
255         */
256        public static final int TYPE_APPLICATION_MEDIA_OVERLAY  = FIRST_SUB_WINDOW+4;
257
258        /**
259         * End of types of sub-windows.
260         */
261        public static final int LAST_SUB_WINDOW         = 1999;
262
263        /**
264         * Start of system-specific window types.  These are not normally
265         * created by applications.
266         */
267        public static final int FIRST_SYSTEM_WINDOW     = 2000;
268
269        /**
270         * Window type: the status bar.  There can be only one status bar
271         * window; it is placed at the top of the screen, and all other
272         * windows are shifted down so they are below it.
273         */
274        public static final int TYPE_STATUS_BAR         = FIRST_SYSTEM_WINDOW;
275
276        /**
277         * Window type: the search bar.  There can be only one search bar
278         * window; it is placed at the top of the screen.
279         */
280        public static final int TYPE_SEARCH_BAR         = FIRST_SYSTEM_WINDOW+1;
281
282        /**
283         * Window type: phone.  These are non-application windows providing
284         * user interaction with the phone (in particular incoming calls).
285         * These windows are normally placed above all applications, but behind
286         * the status bar.
287         */
288        public static final int TYPE_PHONE              = FIRST_SYSTEM_WINDOW+2;
289
290        /**
291         * Window type: system window, such as low power alert. These windows
292         * are always on top of application windows.
293         */
294        public static final int TYPE_SYSTEM_ALERT       = FIRST_SYSTEM_WINDOW+3;
295
296        /**
297         * Window type: keyguard window.
298         */
299        public static final int TYPE_KEYGUARD           = FIRST_SYSTEM_WINDOW+4;
300
301        /**
302         * Window type: transient notifications.
303         */
304        public static final int TYPE_TOAST              = FIRST_SYSTEM_WINDOW+5;
305
306        /**
307         * Window type: system overlay windows, which need to be displayed
308         * on top of everything else.  These windows must not take input
309         * focus, or they will interfere with the keyguard.
310         */
311        public static final int TYPE_SYSTEM_OVERLAY     = FIRST_SYSTEM_WINDOW+6;
312
313        /**
314         * Window type: priority phone UI, which needs to be displayed even if
315         * the keyguard is active.  These windows must not take input
316         * focus, or they will interfere with the keyguard.
317         */
318        public static final int TYPE_PRIORITY_PHONE     = FIRST_SYSTEM_WINDOW+7;
319
320        /**
321         * Window type: panel that slides out from the status bar
322         */
323        public static final int TYPE_SYSTEM_DIALOG      = FIRST_SYSTEM_WINDOW+8;
324
325        /**
326         * Window type: dialogs that the keyguard shows
327         */
328        public static final int TYPE_KEYGUARD_DIALOG    = FIRST_SYSTEM_WINDOW+9;
329
330        /**
331         * Window type: internal system error windows, appear on top of
332         * everything they can.
333         */
334        public static final int TYPE_SYSTEM_ERROR       = FIRST_SYSTEM_WINDOW+10;
335
336        /**
337         * Window type: internal input methods windows, which appear above
338         * the normal UI.  Application windows may be resized or panned to keep
339         * the input focus visible while this window is displayed.
340         */
341        public static final int TYPE_INPUT_METHOD       = FIRST_SYSTEM_WINDOW+11;
342
343        /**
344         * Window type: internal input methods dialog windows, which appear above
345         * the current input method window.
346         */
347        public static final int TYPE_INPUT_METHOD_DIALOG= FIRST_SYSTEM_WINDOW+12;
348
349        /**
350         * Window type: wallpaper window, placed behind any window that wants
351         * to sit on top of the wallpaper.
352         */
353        public static final int TYPE_WALLPAPER          = FIRST_SYSTEM_WINDOW+13;
354
355        /**
356         * Window type: panel that slides out from over the status bar
357         */
358        public static final int TYPE_STATUS_BAR_PANEL   = FIRST_SYSTEM_WINDOW+14;
359
360        /**
361         * Window type: secure system overlay windows, which need to be displayed
362         * on top of everything else.  These windows must not take input
363         * focus, or they will interfere with the keyguard.
364         *
365         * This is exactly like {@link #TYPE_SYSTEM_OVERLAY} except that only the
366         * system itself is allowed to create these overlays.  Applications cannot
367         * obtain permission to create secure system overlays.
368         * @hide
369         */
370        public static final int TYPE_SECURE_SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW+15;
371
372        /**
373         * Window type: the drag-and-drop pseudowindow.  There is only one
374         * drag layer (at most), and it is placed on top of all other windows.
375         * @hide
376         */
377        public static final int TYPE_DRAG               = FIRST_SYSTEM_WINDOW+16;
378
379        /**
380         * Window type: panel that slides out from under the status bar
381         * @hide
382         */
383        public static final int TYPE_STATUS_BAR_SUB_PANEL = FIRST_SYSTEM_WINDOW+17;
384
385        /**
386         * Window type: (mouse) pointer
387         * @hide
388         */
389        public static final int TYPE_POINTER = FIRST_SYSTEM_WINDOW+18;
390
391        /**
392         * Window type: Navigation bar (when distinct from status bar)
393         * @hide
394         */
395        public static final int TYPE_NAVIGATION_BAR = FIRST_SYSTEM_WINDOW+19;
396
397        /**
398         * Window type: The volume level overlay/dialog shown when the user
399         * changes the system volume.
400         * @hide
401         */
402        public static final int TYPE_VOLUME_OVERLAY = FIRST_SYSTEM_WINDOW+20;
403
404        /**
405         * Window type: The boot progress dialog, goes on top of everything
406         * in the world.
407         * @hide
408         */
409        public static final int TYPE_BOOT_PROGRESS = FIRST_SYSTEM_WINDOW+21;
410
411        /**
412         * End of types of system windows.
413         */
414        public static final int LAST_SYSTEM_WINDOW      = 2999;
415
416        /**
417         * @deprecated this is ignored
418         */
419        @Deprecated
420        public int memoryType;
421
422        /** @deprecated this is ignored, this value is set automatically when needed. */
423        @Deprecated
424        public static final int MEMORY_TYPE_NORMAL = 0;
425        /** @deprecated this is ignored, this value is set automatically when needed. */
426        @Deprecated
427        public static final int MEMORY_TYPE_HARDWARE = 1;
428        /** @deprecated this is ignored, this value is set automatically when needed. */
429        @Deprecated
430        public static final int MEMORY_TYPE_GPU = 2;
431        /** @deprecated this is ignored, this value is set automatically when needed. */
432        @Deprecated
433        public static final int MEMORY_TYPE_PUSH_BUFFERS = 3;
434
435        /**
436         * Various behavioral options/flags.  Default is none.
437         *
438         * @see #FLAG_BLUR_BEHIND
439         * @see #FLAG_DIM_BEHIND
440         * @see #FLAG_NOT_FOCUSABLE
441         * @see #FLAG_NOT_TOUCHABLE
442         * @see #FLAG_NOT_TOUCH_MODAL
443         * @see #FLAG_LAYOUT_IN_SCREEN
444         * @see #FLAG_DITHER
445         * @see #FLAG_KEEP_SCREEN_ON
446         * @see #FLAG_FULLSCREEN
447         * @see #FLAG_FORCE_NOT_FULLSCREEN
448         * @see #FLAG_IGNORE_CHEEK_PRESSES
449         * @see #FLAG_HARDWARE_ACCELERATED
450         */
451        @ViewDebug.ExportedProperty(flagMapping = {
452            @ViewDebug.FlagToString(mask = FLAG_BLUR_BEHIND, equals = FLAG_BLUR_BEHIND,
453                    name = "FLAG_BLUR_BEHIND"),
454            @ViewDebug.FlagToString(mask = FLAG_DIM_BEHIND, equals = FLAG_DIM_BEHIND,
455                    name = "FLAG_DIM_BEHIND"),
456            @ViewDebug.FlagToString(mask = FLAG_NOT_FOCUSABLE, equals = FLAG_NOT_FOCUSABLE,
457                    name = "FLAG_NOT_FOCUSABLE"),
458            @ViewDebug.FlagToString(mask = FLAG_NOT_TOUCHABLE, equals = FLAG_NOT_TOUCHABLE,
459                    name = "FLAG_NOT_TOUCHABLE"),
460            @ViewDebug.FlagToString(mask = FLAG_NOT_TOUCH_MODAL, equals = FLAG_NOT_TOUCH_MODAL,
461                    name = "FLAG_NOT_TOUCH_MODAL"),
462            @ViewDebug.FlagToString(mask = FLAG_LAYOUT_IN_SCREEN, equals = FLAG_LAYOUT_IN_SCREEN,
463                    name = "FLAG_LAYOUT_IN_SCREEN"),
464            @ViewDebug.FlagToString(mask = FLAG_DITHER, equals = FLAG_DITHER,
465                    name = "FLAG_DITHER"),
466            @ViewDebug.FlagToString(mask = FLAG_TURN_SCREEN_ON, equals = FLAG_TURN_SCREEN_ON,
467                    name = "FLAG_TURN_SCREEN_ON"),
468            @ViewDebug.FlagToString(mask = FLAG_KEEP_SCREEN_ON, equals = FLAG_KEEP_SCREEN_ON,
469                    name = "FLAG_KEEP_SCREEN_ON"),
470            @ViewDebug.FlagToString(mask = FLAG_SHOW_WHEN_LOCKED, equals = FLAG_SHOW_WHEN_LOCKED,
471                    name = "FLAG_SHOW_WHEN_LOCKED"),
472            @ViewDebug.FlagToString(mask = FLAG_ALLOW_LOCK_WHILE_SCREEN_ON, equals = FLAG_ALLOW_LOCK_WHILE_SCREEN_ON,
473                    name = "FLAG_ALLOW_LOCK_WHILE_SCREEN_ON"),
474            @ViewDebug.FlagToString(mask = FLAG_DISMISS_KEYGUARD, equals = FLAG_DISMISS_KEYGUARD,
475                    name = "FLAG_DISMISS_KEYGUARD"),
476            @ViewDebug.FlagToString(mask = FLAG_FULLSCREEN, equals = FLAG_FULLSCREEN,
477                    name = "FLAG_FULLSCREEN"),
478            @ViewDebug.FlagToString(mask = FLAG_FORCE_NOT_FULLSCREEN,
479                    equals = FLAG_FORCE_NOT_FULLSCREEN, name = "FLAG_FORCE_NOT_FULLSCREEN"),
480            @ViewDebug.FlagToString(mask = FLAG_IGNORE_CHEEK_PRESSES,
481                    equals = FLAG_IGNORE_CHEEK_PRESSES, name = "FLAG_IGNORE_CHEEK_PRESSES"),
482            @ViewDebug.FlagToString(mask = FLAG_HARDWARE_ACCELERATED,
483                    equals = FLAG_HARDWARE_ACCELERATED, name = "FLAG_HARDWARE_ACCELERATED")
484        })
485        public int flags;
486
487        /** Window flag: as long as this window is visible to the user, allow
488         *  the lock screen to activate while the screen is on.
489         *  This can be used independently, or in combination with
490         *  {@link #FLAG_KEEP_SCREEN_ON} and/or {@link #FLAG_SHOW_WHEN_LOCKED} */
491        public static final int FLAG_ALLOW_LOCK_WHILE_SCREEN_ON     = 0x00000001;
492
493        /** Window flag: everything behind this window will be dimmed.
494         *  Use {@link #dimAmount} to control the amount of dim. */
495        public static final int FLAG_DIM_BEHIND        = 0x00000002;
496
497        /** Window flag: blur everything behind this window. */
498        public static final int FLAG_BLUR_BEHIND        = 0x00000004;
499
500        /** Window flag: this window won't ever get key input focus, so the
501         * user can not send key or other button events to it.  Those will
502         * instead go to whatever focusable window is behind it.  This flag
503         * will also enable {@link #FLAG_NOT_TOUCH_MODAL} whether or not that
504         * is explicitly set.
505         *
506         * <p>Setting this flag also implies that the window will not need to
507         * interact with
508         * a soft input method, so it will be Z-ordered and positioned
509         * independently of any active input method (typically this means it
510         * gets Z-ordered on top of the input method, so it can use the full
511         * screen for its content and cover the input method if needed.  You
512         * can use {@link #FLAG_ALT_FOCUSABLE_IM} to modify this behavior. */
513        public static final int FLAG_NOT_FOCUSABLE      = 0x00000008;
514
515        /** Window flag: this window can never receive touch events. */
516        public static final int FLAG_NOT_TOUCHABLE      = 0x00000010;
517
518        /** Window flag: Even when this window is focusable (its
519         * {@link #FLAG_NOT_FOCUSABLE is not set), allow any pointer events
520         * outside of the window to be sent to the windows behind it.  Otherwise
521         * it will consume all pointer events itself, regardless of whether they
522         * are inside of the window. */
523        public static final int FLAG_NOT_TOUCH_MODAL    = 0x00000020;
524
525        /** Window flag: When set, if the device is asleep when the touch
526         * screen is pressed, you will receive this first touch event.  Usually
527         * the first touch event is consumed by the system since the user can
528         * not see what they are pressing on.
529         */
530        public static final int FLAG_TOUCHABLE_WHEN_WAKING = 0x00000040;
531
532        /** Window flag: as long as this window is visible to the user, keep
533         *  the device's screen turned on and bright. */
534        public static final int FLAG_KEEP_SCREEN_ON     = 0x00000080;
535
536        /** Window flag: place the window within the entire screen, ignoring
537         *  decorations around the border (a.k.a. the status bar).  The
538         *  window must correctly position its contents to take the screen
539         *  decoration into account.  This flag is normally set for you
540         *  by Window as described in {@link Window#setFlags}. */
541        public static final int FLAG_LAYOUT_IN_SCREEN   = 0x00000100;
542
543        /** Window flag: allow window to extend outside of the screen. */
544        public static final int FLAG_LAYOUT_NO_LIMITS   = 0x00000200;
545
546        /** Window flag: Hide all screen decorations (e.g. status bar) while
547         * this window is displayed.  This allows the window to use the entire
548         * display space for itself -- the status bar will be hidden when
549         * an app window with this flag set is on the top layer. */
550        public static final int FLAG_FULLSCREEN      = 0x00000400;
551
552        /** Window flag: Override {@link #FLAG_FULLSCREEN and force the
553         *  screen decorations (such as status bar) to be shown. */
554        public static final int FLAG_FORCE_NOT_FULLSCREEN   = 0x00000800;
555
556        /** Window flag: turn on dithering when compositing this window to
557         *  the screen. */
558        public static final int FLAG_DITHER             = 0x00001000;
559
560        /** Window flag: don't allow screen shots while this window is
561         * displayed. Maps to Surface.SECURE. */
562        public static final int FLAG_SECURE             = 0x00002000;
563
564        /** Window flag: a special mode where the layout parameters are used
565         * to perform scaling of the surface when it is composited to the
566         * screen. */
567        public static final int FLAG_SCALED             = 0x00004000;
568
569        /** Window flag: intended for windows that will often be used when the user is
570         * holding the screen against their face, it will aggressively filter the event
571         * stream to prevent unintended presses in this situation that may not be
572         * desired for a particular window, when such an event stream is detected, the
573         * application will receive a CANCEL motion event to indicate this so applications
574         * can handle this accordingly by taking no action on the event
575         * until the finger is released. */
576        public static final int FLAG_IGNORE_CHEEK_PRESSES    = 0x00008000;
577
578        /** Window flag: a special option only for use in combination with
579         * {@link #FLAG_LAYOUT_IN_SCREEN}.  When requesting layout in the
580         * screen your window may appear on top of or behind screen decorations
581         * such as the status bar.  By also including this flag, the window
582         * manager will report the inset rectangle needed to ensure your
583         * content is not covered by screen decorations.  This flag is normally
584         * set for you by Window as described in {@link Window#setFlags}.*/
585        public static final int FLAG_LAYOUT_INSET_DECOR = 0x00010000;
586
587        /** Window flag: invert the state of {@link #FLAG_NOT_FOCUSABLE} with
588         * respect to how this window interacts with the current method.  That
589         * is, if FLAG_NOT_FOCUSABLE is set and this flag is set, then the
590         * window will behave as if it needs to interact with the input method
591         * and thus be placed behind/away from it; if FLAG_NOT_FOCUSABLE is
592         * not set and this flag is set, then the window will behave as if it
593         * doesn't need to interact with the input method and can be placed
594         * to use more space and cover the input method.
595         */
596        public static final int FLAG_ALT_FOCUSABLE_IM = 0x00020000;
597
598        /** Window flag: if you have set {@link #FLAG_NOT_TOUCH_MODAL}, you
599         * can set this flag to receive a single special MotionEvent with
600         * the action
601         * {@link MotionEvent#ACTION_OUTSIDE MotionEvent.ACTION_OUTSIDE} for
602         * touches that occur outside of your window.  Note that you will not
603         * receive the full down/move/up gesture, only the location of the
604         * first down as an ACTION_OUTSIDE.
605         */
606        public static final int FLAG_WATCH_OUTSIDE_TOUCH = 0x00040000;
607
608        /** Window flag: special flag to let windows be shown when the screen
609         * is locked. This will let application windows take precedence over
610         * key guard or any other lock screens. Can be used with
611         * {@link #FLAG_KEEP_SCREEN_ON} to turn screen on and display windows
612         * directly before showing the key guard window.  Can be used with
613         * {@link #FLAG_DISMISS_KEYGUARD} to automatically fully dismisss
614         * non-secure keyguards.  This flag only applies to the top-most
615         * full-screen window.
616         */
617        public static final int FLAG_SHOW_WHEN_LOCKED = 0x00080000;
618
619        /** Window flag: ask that the system wallpaper be shown behind
620         * your window.  The window surface must be translucent to be able
621         * to actually see the wallpaper behind it; this flag just ensures
622         * that the wallpaper surface will be there if this window actually
623         * has translucent regions.
624         */
625        public static final int FLAG_SHOW_WALLPAPER = 0x00100000;
626
627        /** Window flag: when set as a window is being added or made
628         * visible, once the window has been shown then the system will
629         * poke the power manager's user activity (as if the user had woken
630         * up the device) to turn the screen on. */
631        public static final int FLAG_TURN_SCREEN_ON = 0x00200000;
632
633        /** Window flag: when set the window will cause the keyguard to
634         * be dismissed, only if it is not a secure lock keyguard.  Because such
635         * a keyguard is not needed for security, it will never re-appear if
636         * the user navigates to another window (in contrast to
637         * {@link #FLAG_SHOW_WHEN_LOCKED}, which will only temporarily
638         * hide both secure and non-secure keyguards but ensure they reappear
639         * when the user moves to another UI that doesn't hide them).
640         * If the keyguard is currently active and is secure (requires an
641         * unlock pattern) than the user will still need to confirm it before
642         * seeing this window, unless {@link #FLAG_SHOW_WHEN_LOCKED} has
643         * also been set.
644         */
645        public static final int FLAG_DISMISS_KEYGUARD = 0x00400000;
646
647        /** Window flag: when set the window will accept for touch events
648         * outside of its bounds to be sent to other windows that also
649         * support split touch.  When this flag is not set, the first pointer
650         * that goes down determines the window to which all subsequent touches
651         * go until all pointers go up.  When this flag is set, each pointer
652         * (not necessarily the first) that goes down determines the window
653         * to which all subsequent touches of that pointer will go until that
654         * pointer goes up thereby enabling touches with multiple pointers
655         * to be split across multiple windows.
656         */
657        public static final int FLAG_SPLIT_TOUCH = 0x00800000;
658
659        /**
660         * <p>Indicates whether this window should be hardware accelerated.
661         * Requesting hardware acceleration does not guarantee it will happen.</p>
662         *
663         * <p>This flag can be controlled programmatically <em>only</em> to enable
664         * hardware acceleration. To enable hardware acceleration for a given
665         * window programmatically, do the following:</p>
666         *
667         * <pre>
668         * Window w = activity.getWindow(); // in Activity's onCreate() for instance
669         * w.setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
670         *         WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
671         * </pre>
672         *
673         * <p>It is important to remember that this flag <strong>must</strong>
674         * be set before setting the content view of your activity or dialog.</p>
675         *
676         * <p>This flag cannot be used to disable hardware acceleration after it
677         * was enabled in your manifest using
678         * {@link android.R.attr#hardwareAccelerated}. If you need to selectively
679         * and programmatically disable hardware acceleration (for automated testing
680         * for instance), make sure it is turned off in your manifest and enable it
681         * on your activity or dialog when you need it instead, using the method
682         * described above.</p>
683         *
684         * <p>This flag is automatically set by the system if the
685         * {@link android.R.attr#hardwareAccelerated android:hardwareAccelerated}
686         * XML attribute is set to true on an activity or on the application.</p>
687         */
688        public static final int FLAG_HARDWARE_ACCELERATED = 0x01000000;
689
690        /**
691         * Like {@link #FLAG_HARDWARE_ACCELERATED} except for trusted system windows
692         * that need hardware acceleration (e.g. LockScreen), where hardware acceleration
693         * is generally disabled. This flag must be specified in addition to
694         * {@link #FLAG_HARDWARE_ACCELERATED} to enable hardware acceleration for system
695         * windows.
696         *
697         * @hide
698         */
699        public static final int FLAG_HARDWARE_ACCELERATED_SYSTEM = 0x02000000;
700
701        // ----- HIDDEN FLAGS.
702        // These start at the high bit and go down.
703
704        /** Window flag: Enable touches to slide out of a window into neighboring
705         * windows in mid-gesture instead of being captured for the duration of
706         * the gesture.
707         *
708         * This flag changes the behavior of touch focus for this window only.
709         * Touches can slide out of the window but they cannot necessarily slide
710         * back in (unless the other window with touch focus permits it).
711         *
712         * {@hide}
713         */
714        public static final int FLAG_SLIPPERY = 0x04000000;
715
716        /**
717         * Flag for a window belonging to an activity that responds to {@link KeyEvent#KEYCODE_MENU}
718         * and therefore needs a Menu key. For devices where Menu is a physical button this flag is
719         * ignored, but on devices where the Menu key is drawn in software it may be hidden unless
720         * this flag is set.
721         *
722         * (Note that Action Bars, when available, are the preferred way to offer additional
723         * functions otherwise accessed via an options menu.)
724         *
725         * {@hide}
726         */
727        public static final int FLAG_NEEDS_MENU_KEY = 0x08000000;
728
729        /** Window flag: *sigh* The lock screen wants to continue running its
730         * animation while it is fading.  A kind-of hack to allow this.  Maybe
731         * in the future we just make this the default behavior.
732         *
733         * {@hide} */
734        public static final int FLAG_KEEP_SURFACE_WHILE_ANIMATING = 0x10000000;
735
736        /** Window flag: special flag to limit the size of the window to be
737         * original size ([320x480] x density). Used to create window for applications
738         * running under compatibility mode.
739         *
740         * {@hide} */
741        public static final int FLAG_COMPATIBLE_WINDOW = 0x20000000;
742
743        /** Window flag: a special option intended for system dialogs.  When
744         * this flag is set, the window will demand focus unconditionally when
745         * it is created.
746         * {@hide} */
747        public static final int FLAG_SYSTEM_ERROR = 0x40000000;
748
749        /**
750         * Given a particular set of window manager flags, determine whether
751         * such a window may be a target for an input method when it has
752         * focus.  In particular, this checks the
753         * {@link #FLAG_NOT_FOCUSABLE} and {@link #FLAG_ALT_FOCUSABLE_IM}
754         * flags and returns true if the combination of the two corresponds
755         * to a window that needs to be behind the input method so that the
756         * user can type into it.
757         *
758         * @param flags The current window manager flags.
759         *
760         * @return Returns true if such a window should be behind/interact
761         * with an input method, false if not.
762         */
763        public static boolean mayUseInputMethod(int flags) {
764            switch (flags&(FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
765                case 0:
766                case FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM:
767                    return true;
768            }
769            return false;
770        }
771
772        /**
773         * Mask for {@link #softInputMode} of the bits that determine the
774         * desired visibility state of the soft input area for this window.
775         */
776        public static final int SOFT_INPUT_MASK_STATE = 0x0f;
777
778        /**
779         * Visibility state for {@link #softInputMode}: no state has been specified.
780         */
781        public static final int SOFT_INPUT_STATE_UNSPECIFIED = 0;
782
783        /**
784         * Visibility state for {@link #softInputMode}: please don't change the state of
785         * the soft input area.
786         */
787        public static final int SOFT_INPUT_STATE_UNCHANGED = 1;
788
789        /**
790         * Visibility state for {@link #softInputMode}: please hide any soft input
791         * area when normally appropriate (when the user is navigating
792         * forward to your window).
793         */
794        public static final int SOFT_INPUT_STATE_HIDDEN = 2;
795
796        /**
797         * Visibility state for {@link #softInputMode}: please always hide any
798         * soft input area when this window receives focus.
799         */
800        public static final int SOFT_INPUT_STATE_ALWAYS_HIDDEN = 3;
801
802        /**
803         * Visibility state for {@link #softInputMode}: please show the soft
804         * input area when normally appropriate (when the user is navigating
805         * forward to your window).
806         */
807        public static final int SOFT_INPUT_STATE_VISIBLE = 4;
808
809        /**
810         * Visibility state for {@link #softInputMode}: please always make the
811         * soft input area visible when this window receives input focus.
812         */
813        public static final int SOFT_INPUT_STATE_ALWAYS_VISIBLE = 5;
814
815        /**
816         * Mask for {@link #softInputMode} of the bits that determine the
817         * way that the window should be adjusted to accommodate the soft
818         * input window.
819         */
820        public static final int SOFT_INPUT_MASK_ADJUST = 0xf0;
821
822        /** Adjustment option for {@link #softInputMode}: nothing specified.
823         * The system will try to pick one or
824         * the other depending on the contents of the window.
825         */
826        public static final int SOFT_INPUT_ADJUST_UNSPECIFIED = 0x00;
827
828        /** Adjustment option for {@link #softInputMode}: set to allow the
829         * window to be resized when an input
830         * method is shown, so that its contents are not covered by the input
831         * method.  This can <em>not</em> be combined with
832         * {@link #SOFT_INPUT_ADJUST_PAN}; if
833         * neither of these are set, then the system will try to pick one or
834         * the other depending on the contents of the window.
835         */
836        public static final int SOFT_INPUT_ADJUST_RESIZE = 0x10;
837
838        /** Adjustment option for {@link #softInputMode}: set to have a window
839         * pan when an input method is
840         * shown, so it doesn't need to deal with resizing but just panned
841         * by the framework to ensure the current input focus is visible.  This
842         * can <em>not</em> be combined with {@link #SOFT_INPUT_ADJUST_RESIZE}; if
843         * neither of these are set, then the system will try to pick one or
844         * the other depending on the contents of the window.
845         */
846        public static final int SOFT_INPUT_ADJUST_PAN = 0x20;
847
848        /** Adjustment option for {@link #softInputMode}: set to have a window
849         * not adjust for a shown input method.  The window will not be resized,
850         * and it will not be panned to make its focus visible.
851         */
852        public static final int SOFT_INPUT_ADJUST_NOTHING = 0x30;
853
854        /**
855         * Bit for {@link #softInputMode}: set when the user has navigated
856         * forward to the window.  This is normally set automatically for
857         * you by the system, though you may want to set it in certain cases
858         * when you are displaying a window yourself.  This flag will always
859         * be cleared automatically after the window is displayed.
860         */
861        public static final int SOFT_INPUT_IS_FORWARD_NAVIGATION = 0x100;
862
863        /**
864         * Desired operating mode for any soft input area.  May be any combination
865         * of:
866         *
867         * <ul>
868         * <li> One of the visibility states
869         * {@link #SOFT_INPUT_STATE_UNSPECIFIED}, {@link #SOFT_INPUT_STATE_UNCHANGED},
870         * {@link #SOFT_INPUT_STATE_HIDDEN}, {@link #SOFT_INPUT_STATE_ALWAYS_VISIBLE}, or
871         * {@link #SOFT_INPUT_STATE_VISIBLE}.
872         * <li> One of the adjustment options
873         * {@link #SOFT_INPUT_ADJUST_UNSPECIFIED},
874         * {@link #SOFT_INPUT_ADJUST_RESIZE}, or
875         * {@link #SOFT_INPUT_ADJUST_PAN}.
876         */
877        public int softInputMode;
878
879        /**
880         * Placement of window within the screen as per {@link Gravity}.  Both
881         * {@link Gravity#apply(int, int, int, android.graphics.Rect, int, int,
882         * android.graphics.Rect) Gravity.apply} and
883         * {@link Gravity#applyDisplay(int, android.graphics.Rect, android.graphics.Rect)
884         * Gravity.applyDisplay} are used during window layout, with this value
885         * given as the desired gravity.  For example you can specify
886         * {@link Gravity#DISPLAY_CLIP_HORIZONTAL Gravity.DISPLAY_CLIP_HORIZONTAL} and
887         * {@link Gravity#DISPLAY_CLIP_VERTICAL Gravity.DISPLAY_CLIP_VERTICAL} here
888         * to control the behavior of
889         * {@link Gravity#applyDisplay(int, android.graphics.Rect, android.graphics.Rect)
890         * Gravity.applyDisplay}.
891         *
892         * @see Gravity
893         */
894        public int gravity;
895
896        /**
897         * The horizontal margin, as a percentage of the container's width,
898         * between the container and the widget.  See
899         * {@link Gravity#apply(int, int, int, android.graphics.Rect, int, int,
900         * android.graphics.Rect) Gravity.apply} for how this is used.  This
901         * field is added with {@link #x} to supply the <var>xAdj</var> parameter.
902         */
903        public float horizontalMargin;
904
905        /**
906         * The vertical margin, as a percentage of the container's height,
907         * between the container and the widget.  See
908         * {@link Gravity#apply(int, int, int, android.graphics.Rect, int, int,
909         * android.graphics.Rect) Gravity.apply} for how this is used.  This
910         * field is added with {@link #y} to supply the <var>yAdj</var> parameter.
911         */
912        public float verticalMargin;
913
914        /**
915         * The desired bitmap format.  May be one of the constants in
916         * {@link android.graphics.PixelFormat}.  Default is OPAQUE.
917         */
918        public int format;
919
920        /**
921         * A style resource defining the animations to use for this window.
922         * This must be a system resource; it can not be an application resource
923         * because the window manager does not have access to applications.
924         */
925        public int windowAnimations;
926
927        /**
928         * An alpha value to apply to this entire window.
929         * An alpha of 1.0 means fully opaque and 0.0 means fully transparent
930         */
931        public float alpha = 1.0f;
932
933        /**
934         * When {@link #FLAG_DIM_BEHIND} is set, this is the amount of dimming
935         * to apply.  Range is from 1.0 for completely opaque to 0.0 for no
936         * dim.
937         */
938        public float dimAmount = 1.0f;
939
940        /**
941         * Default value for {@link #screenBrightness} and {@link #buttonBrightness}
942         * indicating that the brightness value is not overridden for this window
943         * and normal brightness policy should be used.
944         */
945        public static final float BRIGHTNESS_OVERRIDE_NONE = -1.0f;
946
947        /**
948         * Value for {@link #screenBrightness} and {@link #buttonBrightness}
949         * indicating that the screen or button backlight brightness should be set
950         * to the lowest value when this window is in front.
951         */
952        public static final float BRIGHTNESS_OVERRIDE_OFF = 0.0f;
953
954        /**
955         * Value for {@link #screenBrightness} and {@link #buttonBrightness}
956         * indicating that the screen or button backlight brightness should be set
957         * to the hightest value when this window is in front.
958         */
959        public static final float BRIGHTNESS_OVERRIDE_FULL = 1.0f;
960
961        /**
962         * This can be used to override the user's preferred brightness of
963         * the screen.  A value of less than 0, the default, means to use the
964         * preferred screen brightness.  0 to 1 adjusts the brightness from
965         * dark to full bright.
966         */
967        public float screenBrightness = BRIGHTNESS_OVERRIDE_NONE;
968
969        /**
970         * This can be used to override the standard behavior of the button and
971         * keyboard backlights.  A value of less than 0, the default, means to
972         * use the standard backlight behavior.  0 to 1 adjusts the brightness
973         * from dark to full bright.
974         */
975        public float buttonBrightness = BRIGHTNESS_OVERRIDE_NONE;
976
977        /**
978         * Identifier for this window.  This will usually be filled in for
979         * you.
980         */
981        public IBinder token = null;
982
983        /**
984         * Name of the package owning this window.
985         */
986        public String packageName = null;
987
988        /**
989         * Specific orientation value for a window.
990         * May be any of the same values allowed
991         * for {@link android.content.pm.ActivityInfo#screenOrientation}.
992         * If not set, a default value of
993         * {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSPECIFIED}
994         * will be used.
995         */
996        public int screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
997
998        /**
999         * Control the visibility of the status bar.
1000         *
1001         * @see View#STATUS_BAR_VISIBLE
1002         * @see View#STATUS_BAR_HIDDEN
1003         */
1004        public int systemUiVisibility;
1005
1006        /**
1007         * @hide
1008         * The ui visibility as requested by the views in this hierarchy.
1009         * the combined value should be systemUiVisibility | subtreeSystemUiVisibility.
1010         */
1011        public int subtreeSystemUiVisibility;
1012
1013        /**
1014         * Get callbacks about the system ui visibility changing.
1015         *
1016         * TODO: Maybe there should be a bitfield of optional callbacks that we need.
1017         *
1018         * @hide
1019         */
1020        public boolean hasSystemUiListeners;
1021
1022        /**
1023         * When this window has focus, disable touch pad pointer gesture processing.
1024         * The window will receive raw position updates from the touch pad instead
1025         * of pointer movements and synthetic touch events.
1026         *
1027         * @hide
1028         */
1029        public static final int INPUT_FEATURE_DISABLE_POINTER_GESTURES = 0x00000001;
1030
1031        /**
1032         * Does not construct an input channel for this window.  The channel will therefore
1033         * be incapable of receiving input.
1034         *
1035         * @hide
1036         */
1037        public static final int INPUT_FEATURE_NO_INPUT_CHANNEL = 0x00000002;
1038
1039        /**
1040         * Control special features of the input subsystem.
1041         *
1042         * @see #INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES
1043         * @see #INPUT_FEATURE_NO_INPUT_CHANNEL
1044         * @hide
1045         */
1046        public int inputFeatures;
1047
1048        public LayoutParams() {
1049            super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
1050            type = TYPE_APPLICATION;
1051            format = PixelFormat.OPAQUE;
1052        }
1053
1054        public LayoutParams(int _type) {
1055            super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
1056            type = _type;
1057            format = PixelFormat.OPAQUE;
1058        }
1059
1060        public LayoutParams(int _type, int _flags) {
1061            super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
1062            type = _type;
1063            flags = _flags;
1064            format = PixelFormat.OPAQUE;
1065        }
1066
1067        public LayoutParams(int _type, int _flags, int _format) {
1068            super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
1069            type = _type;
1070            flags = _flags;
1071            format = _format;
1072        }
1073
1074        public LayoutParams(int w, int h, int _type, int _flags, int _format) {
1075            super(w, h);
1076            type = _type;
1077            flags = _flags;
1078            format = _format;
1079        }
1080
1081        public LayoutParams(int w, int h, int xpos, int ypos, int _type,
1082                int _flags, int _format) {
1083            super(w, h);
1084            x = xpos;
1085            y = ypos;
1086            type = _type;
1087            flags = _flags;
1088            format = _format;
1089        }
1090
1091        public final void setTitle(CharSequence title) {
1092            if (null == title)
1093                title = "";
1094
1095            mTitle = TextUtils.stringOrSpannedString(title);
1096        }
1097
1098        public final CharSequence getTitle() {
1099            return mTitle;
1100        }
1101
1102        public int describeContents() {
1103            return 0;
1104        }
1105
1106        public void writeToParcel(Parcel out, int parcelableFlags) {
1107            out.writeInt(width);
1108            out.writeInt(height);
1109            out.writeInt(x);
1110            out.writeInt(y);
1111            out.writeInt(type);
1112            out.writeInt(flags);
1113            out.writeInt(softInputMode);
1114            out.writeInt(gravity);
1115            out.writeFloat(horizontalMargin);
1116            out.writeFloat(verticalMargin);
1117            out.writeInt(format);
1118            out.writeInt(windowAnimations);
1119            out.writeFloat(alpha);
1120            out.writeFloat(dimAmount);
1121            out.writeFloat(screenBrightness);
1122            out.writeFloat(buttonBrightness);
1123            out.writeStrongBinder(token);
1124            out.writeString(packageName);
1125            TextUtils.writeToParcel(mTitle, out, parcelableFlags);
1126            out.writeInt(screenOrientation);
1127            out.writeInt(systemUiVisibility);
1128            out.writeInt(subtreeSystemUiVisibility);
1129            out.writeInt(hasSystemUiListeners ? 1 : 0);
1130            out.writeInt(inputFeatures);
1131        }
1132
1133        public static final Parcelable.Creator<LayoutParams> CREATOR
1134                    = new Parcelable.Creator<LayoutParams>() {
1135            public LayoutParams createFromParcel(Parcel in) {
1136                return new LayoutParams(in);
1137            }
1138
1139            public LayoutParams[] newArray(int size) {
1140                return new LayoutParams[size];
1141            }
1142        };
1143
1144
1145        public LayoutParams(Parcel in) {
1146            width = in.readInt();
1147            height = in.readInt();
1148            x = in.readInt();
1149            y = in.readInt();
1150            type = in.readInt();
1151            flags = in.readInt();
1152            softInputMode = in.readInt();
1153            gravity = in.readInt();
1154            horizontalMargin = in.readFloat();
1155            verticalMargin = in.readFloat();
1156            format = in.readInt();
1157            windowAnimations = in.readInt();
1158            alpha = in.readFloat();
1159            dimAmount = in.readFloat();
1160            screenBrightness = in.readFloat();
1161            buttonBrightness = in.readFloat();
1162            token = in.readStrongBinder();
1163            packageName = in.readString();
1164            mTitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
1165            screenOrientation = in.readInt();
1166            systemUiVisibility = in.readInt();
1167            subtreeSystemUiVisibility = in.readInt();
1168            hasSystemUiListeners = in.readInt() != 0;
1169            inputFeatures = in.readInt();
1170        }
1171
1172        @SuppressWarnings({"PointlessBitwiseExpression"})
1173        public static final int LAYOUT_CHANGED = 1<<0;
1174        public static final int TYPE_CHANGED = 1<<1;
1175        public static final int FLAGS_CHANGED = 1<<2;
1176        public static final int FORMAT_CHANGED = 1<<3;
1177        public static final int ANIMATION_CHANGED = 1<<4;
1178        public static final int DIM_AMOUNT_CHANGED = 1<<5;
1179        public static final int TITLE_CHANGED = 1<<6;
1180        public static final int ALPHA_CHANGED = 1<<7;
1181        public static final int MEMORY_TYPE_CHANGED = 1<<8;
1182        public static final int SOFT_INPUT_MODE_CHANGED = 1<<9;
1183        public static final int SCREEN_ORIENTATION_CHANGED = 1<<10;
1184        public static final int SCREEN_BRIGHTNESS_CHANGED = 1<<11;
1185        /** {@hide} */
1186        public static final int BUTTON_BRIGHTNESS_CHANGED = 1<<12;
1187        /** {@hide} */
1188        public static final int SYSTEM_UI_VISIBILITY_CHANGED = 1<<13;
1189        /** {@hide} */
1190        public static final int SYSTEM_UI_LISTENER_CHANGED = 1<<14;
1191        /** {@hide} */
1192        public static final int INPUT_FEATURES_CHANGED = 1<<15;
1193
1194        // internal buffer to backup/restore parameters under compatibility mode.
1195        private int[] mCompatibilityParamsBackup = null;
1196
1197        public final int copyFrom(LayoutParams o) {
1198            int changes = 0;
1199
1200            if (width != o.width) {
1201                width = o.width;
1202                changes |= LAYOUT_CHANGED;
1203            }
1204            if (height != o.height) {
1205                height = o.height;
1206                changes |= LAYOUT_CHANGED;
1207            }
1208            if (x != o.x) {
1209                x = o.x;
1210                changes |= LAYOUT_CHANGED;
1211            }
1212            if (y != o.y) {
1213                y = o.y;
1214                changes |= LAYOUT_CHANGED;
1215            }
1216            if (horizontalWeight != o.horizontalWeight) {
1217                horizontalWeight = o.horizontalWeight;
1218                changes |= LAYOUT_CHANGED;
1219            }
1220            if (verticalWeight != o.verticalWeight) {
1221                verticalWeight = o.verticalWeight;
1222                changes |= LAYOUT_CHANGED;
1223            }
1224            if (horizontalMargin != o.horizontalMargin) {
1225                horizontalMargin = o.horizontalMargin;
1226                changes |= LAYOUT_CHANGED;
1227            }
1228            if (verticalMargin != o.verticalMargin) {
1229                verticalMargin = o.verticalMargin;
1230                changes |= LAYOUT_CHANGED;
1231            }
1232            if (type != o.type) {
1233                type = o.type;
1234                changes |= TYPE_CHANGED;
1235            }
1236            if (flags != o.flags) {
1237                flags = o.flags;
1238                changes |= FLAGS_CHANGED;
1239            }
1240            if (softInputMode != o.softInputMode) {
1241                softInputMode = o.softInputMode;
1242                changes |= SOFT_INPUT_MODE_CHANGED;
1243            }
1244            if (gravity != o.gravity) {
1245                gravity = o.gravity;
1246                changes |= LAYOUT_CHANGED;
1247            }
1248            if (format != o.format) {
1249                format = o.format;
1250                changes |= FORMAT_CHANGED;
1251            }
1252            if (windowAnimations != o.windowAnimations) {
1253                windowAnimations = o.windowAnimations;
1254                changes |= ANIMATION_CHANGED;
1255            }
1256            if (token == null) {
1257                // NOTE: token only copied if the recipient doesn't
1258                // already have one.
1259                token = o.token;
1260            }
1261            if (packageName == null) {
1262                // NOTE: packageName only copied if the recipient doesn't
1263                // already have one.
1264                packageName = o.packageName;
1265            }
1266            if (!mTitle.equals(o.mTitle)) {
1267                mTitle = o.mTitle;
1268                changes |= TITLE_CHANGED;
1269            }
1270            if (alpha != o.alpha) {
1271                alpha = o.alpha;
1272                changes |= ALPHA_CHANGED;
1273            }
1274            if (dimAmount != o.dimAmount) {
1275                dimAmount = o.dimAmount;
1276                changes |= DIM_AMOUNT_CHANGED;
1277            }
1278            if (screenBrightness != o.screenBrightness) {
1279                screenBrightness = o.screenBrightness;
1280                changes |= SCREEN_BRIGHTNESS_CHANGED;
1281            }
1282            if (buttonBrightness != o.buttonBrightness) {
1283                buttonBrightness = o.buttonBrightness;
1284                changes |= BUTTON_BRIGHTNESS_CHANGED;
1285            }
1286
1287            if (screenOrientation != o.screenOrientation) {
1288                screenOrientation = o.screenOrientation;
1289                changes |= SCREEN_ORIENTATION_CHANGED;
1290            }
1291
1292            if (systemUiVisibility != o.systemUiVisibility
1293                    || subtreeSystemUiVisibility != o.subtreeSystemUiVisibility) {
1294                systemUiVisibility = o.systemUiVisibility;
1295                subtreeSystemUiVisibility = o.subtreeSystemUiVisibility;
1296                changes |= SYSTEM_UI_VISIBILITY_CHANGED;
1297            }
1298
1299            if (hasSystemUiListeners != o.hasSystemUiListeners) {
1300                hasSystemUiListeners = o.hasSystemUiListeners;
1301                changes |= SYSTEM_UI_LISTENER_CHANGED;
1302            }
1303
1304            if (inputFeatures != o.inputFeatures) {
1305                inputFeatures = o.inputFeatures;
1306                changes |= INPUT_FEATURES_CHANGED;
1307            }
1308
1309            return changes;
1310        }
1311
1312        @Override
1313        public String debug(String output) {
1314            output += "Contents of " + this + ":";
1315            Log.d("Debug", output);
1316            output = super.debug("");
1317            Log.d("Debug", output);
1318            Log.d("Debug", "");
1319            Log.d("Debug", "WindowManager.LayoutParams={title=" + mTitle + "}");
1320            return "";
1321        }
1322
1323        @Override
1324        public String toString() {
1325            StringBuilder sb = new StringBuilder(256);
1326            sb.append("WM.LayoutParams{");
1327            sb.append("(");
1328            sb.append(x);
1329            sb.append(',');
1330            sb.append(y);
1331            sb.append(")(");
1332            sb.append((width== MATCH_PARENT ?"fill":(width==WRAP_CONTENT?"wrap":width)));
1333            sb.append('x');
1334            sb.append((height== MATCH_PARENT ?"fill":(height==WRAP_CONTENT?"wrap":height)));
1335            sb.append(")");
1336            if (horizontalMargin != 0) {
1337                sb.append(" hm=");
1338                sb.append(horizontalMargin);
1339            }
1340            if (verticalMargin != 0) {
1341                sb.append(" vm=");
1342                sb.append(verticalMargin);
1343            }
1344            if (gravity != 0) {
1345                sb.append(" gr=#");
1346                sb.append(Integer.toHexString(gravity));
1347            }
1348            if (softInputMode != 0) {
1349                sb.append(" sim=#");
1350                sb.append(Integer.toHexString(softInputMode));
1351            }
1352            sb.append(" ty=");
1353            sb.append(type);
1354            sb.append(" fl=#");
1355            sb.append(Integer.toHexString(flags));
1356            if (format != PixelFormat.OPAQUE) {
1357                sb.append(" fmt=");
1358                sb.append(format);
1359            }
1360            if (windowAnimations != 0) {
1361                sb.append(" wanim=0x");
1362                sb.append(Integer.toHexString(windowAnimations));
1363            }
1364            if (screenOrientation != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
1365                sb.append(" or=");
1366                sb.append(screenOrientation);
1367            }
1368            if (alpha != 1.0f) {
1369                sb.append(" alpha=");
1370                sb.append(alpha);
1371            }
1372            if (screenBrightness != BRIGHTNESS_OVERRIDE_NONE) {
1373                sb.append(" sbrt=");
1374                sb.append(screenBrightness);
1375            }
1376            if (buttonBrightness != BRIGHTNESS_OVERRIDE_NONE) {
1377                sb.append(" bbrt=");
1378                sb.append(buttonBrightness);
1379            }
1380            if ((flags & FLAG_COMPATIBLE_WINDOW) != 0) {
1381                sb.append(" compatible=true");
1382            }
1383            if (systemUiVisibility != 0) {
1384                sb.append(" sysui=0x");
1385                sb.append(Integer.toHexString(systemUiVisibility));
1386            }
1387            if (subtreeSystemUiVisibility != 0) {
1388                sb.append(" vsysui=0x");
1389                sb.append(Integer.toHexString(subtreeSystemUiVisibility));
1390            }
1391            if (hasSystemUiListeners) {
1392                sb.append(" sysuil=");
1393                sb.append(hasSystemUiListeners);
1394            }
1395            if (inputFeatures != 0) {
1396                sb.append(" if=0x").append(Integer.toHexString(inputFeatures));
1397            }
1398            sb.append('}');
1399            return sb.toString();
1400        }
1401
1402        /**
1403         * Scale the layout params' coordinates and size.
1404         * @hide
1405         */
1406        public void scale(float scale) {
1407            x = (int) (x * scale + 0.5f);
1408            y = (int) (y * scale + 0.5f);
1409            if (width > 0) {
1410                width = (int) (width * scale + 0.5f);
1411            }
1412            if (height > 0) {
1413                height = (int) (height * scale + 0.5f);
1414            }
1415        }
1416
1417        /**
1418         * Backup the layout parameters used in compatibility mode.
1419         * @see LayoutParams#restore()
1420         */
1421        void backup() {
1422            int[] backup = mCompatibilityParamsBackup;
1423            if (backup == null) {
1424                // we backup 4 elements, x, y, width, height
1425                backup = mCompatibilityParamsBackup = new int[4];
1426            }
1427            backup[0] = x;
1428            backup[1] = y;
1429            backup[2] = width;
1430            backup[3] = height;
1431        }
1432
1433        /**
1434         * Restore the layout params' coordinates, size and gravity
1435         * @see LayoutParams#backup()
1436         */
1437        void restore() {
1438            int[] backup = mCompatibilityParamsBackup;
1439            if (backup != null) {
1440                x = backup[0];
1441                y = backup[1];
1442                width = backup[2];
1443                height = backup[3];
1444            }
1445        }
1446
1447        private CharSequence mTitle = "";
1448    }
1449}
1450