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