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