Window.java revision ac670c0433d19397d4e36ced2110475b6f54fe26
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.Context;
20import android.content.res.Configuration;
21import android.content.res.TypedArray;
22import android.graphics.PixelFormat;
23import android.graphics.drawable.Drawable;
24import android.net.Uri;
25import android.os.Bundle;
26import android.os.IBinder;
27import android.view.accessibility.AccessibilityEvent;
28
29/**
30 * Abstract base class for a top-level window look and behavior policy.  An
31 * instance of this class should be used as the top-level view added to the
32 * window manager. It provides standard UI policies such as a background, title
33 * area, default key processing, etc.
34 *
35 * <p>The only existing implementation of this abstract class is
36 * android.policy.PhoneWindow, which you should instantiate when needing a
37 * Window.  Eventually that class will be refactored and a factory method
38 * added for creating Window instances without knowing about a particular
39 * implementation.
40 */
41public abstract class Window {
42    /** Flag for the "options panel" feature.  This is enabled by default. */
43    public static final int FEATURE_OPTIONS_PANEL = 0;
44    /** Flag for the "no title" feature, turning off the title at the top
45     *  of the screen. */
46    public static final int FEATURE_NO_TITLE = 1;
47    /** Flag for the progress indicator feature */
48    public static final int FEATURE_PROGRESS = 2;
49    /** Flag for having an icon on the left side of the title bar */
50    public static final int FEATURE_LEFT_ICON = 3;
51    /** Flag for having an icon on the right side of the title bar */
52    public static final int FEATURE_RIGHT_ICON = 4;
53    /** Flag for indeterminate progress */
54    public static final int FEATURE_INDETERMINATE_PROGRESS = 5;
55    /** Flag for the context menu.  This is enabled by default. */
56    public static final int FEATURE_CONTEXT_MENU = 6;
57    /** Flag for custom title. You cannot combine this feature with other title features. */
58    public static final int FEATURE_CUSTOM_TITLE = 7;
59    /**
60     * Flag for enabling the Action Bar.
61     * This is enabled by default for some devices. The Action Bar
62     * replaces the title bar and provides an alternate location
63     * for an on-screen menu button on some devices.
64     */
65    public static final int FEATURE_ACTION_BAR = 9;
66    /** Flag for setting the progress bar's visibility to VISIBLE */
67    public static final int PROGRESS_VISIBILITY_ON = -1;
68    /** Flag for setting the progress bar's visibility to GONE */
69    public static final int PROGRESS_VISIBILITY_OFF = -2;
70    /** Flag for setting the progress bar's indeterminate mode on */
71    public static final int PROGRESS_INDETERMINATE_ON = -3;
72    /** Flag for setting the progress bar's indeterminate mode off */
73    public static final int PROGRESS_INDETERMINATE_OFF = -4;
74    /** Starting value for the (primary) progress */
75    public static final int PROGRESS_START = 0;
76    /** Ending value for the (primary) progress */
77    public static final int PROGRESS_END = 10000;
78    /** Lowest possible value for the secondary progress */
79    public static final int PROGRESS_SECONDARY_START = 20000;
80    /** Highest possible value for the secondary progress */
81    public static final int PROGRESS_SECONDARY_END = 30000;
82
83    /** The default features enabled */
84    @SuppressWarnings({"PointlessBitwiseExpression"})
85    protected static final int DEFAULT_FEATURES = (1 << FEATURE_OPTIONS_PANEL) |
86            (1 << FEATURE_CONTEXT_MENU);
87
88    /**
89     * The ID that the main layout in the XML layout file should have.
90     */
91    public static final int ID_ANDROID_CONTENT = com.android.internal.R.id.content;
92
93    private final Context mContext;
94
95    private TypedArray mWindowStyle;
96    private Callback mCallback;
97    private WindowManager mWindowManager;
98    private IBinder mAppToken;
99    private String mAppName;
100    private Window mContainer;
101    private Window mActiveChild;
102    private boolean mIsActive = false;
103    private boolean mHasChildren = false;
104    private int mForcedWindowFlags = 0;
105
106    private int mFeatures = DEFAULT_FEATURES;
107    private int mLocalFeatures = DEFAULT_FEATURES;
108
109    private boolean mHaveWindowFormat = false;
110    private int mDefaultWindowFormat = PixelFormat.OPAQUE;
111
112    private boolean mHasSoftInputMode = false;
113
114    // The current window attributes.
115    private final WindowManager.LayoutParams mWindowAttributes =
116        new WindowManager.LayoutParams();
117
118    /**
119     * API from a Window back to its caller.  This allows the client to
120     * intercept key dispatching, panels and menus, etc.
121     */
122    public interface Callback {
123        /**
124         * Called to process key events.  At the very least your
125         * implementation must call
126         * {@link android.view.Window#superDispatchKeyEvent} to do the
127         * standard key processing.
128         *
129         * @param event The key event.
130         *
131         * @return boolean Return true if this event was consumed.
132         */
133        public boolean dispatchKeyEvent(KeyEvent event);
134
135        /**
136         * Called to process touch screen events.  At the very least your
137         * implementation must call
138         * {@link android.view.Window#superDispatchTouchEvent} to do the
139         * standard touch screen processing.
140         *
141         * @param event The touch screen event.
142         *
143         * @return boolean Return true if this event was consumed.
144         */
145        public boolean dispatchTouchEvent(MotionEvent event);
146
147        /**
148         * Called to process trackball events.  At the very least your
149         * implementation must call
150         * {@link android.view.Window#superDispatchTrackballEvent} to do the
151         * standard trackball processing.
152         *
153         * @param event The trackball event.
154         *
155         * @return boolean Return true if this event was consumed.
156         */
157        public boolean dispatchTrackballEvent(MotionEvent event);
158
159        /**
160         * Called to process population of {@link AccessibilityEvent}s.
161         *
162         * @param event The event.
163         *
164         * @return boolean Return true if event population was completed.
165         */
166        public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event);
167
168        /**
169         * Instantiate the view to display in the panel for 'featureId'.
170         * You can return null, in which case the default content (typically
171         * a menu) will be created for you.
172         *
173         * @param featureId Which panel is being created.
174         *
175         * @return view The top-level view to place in the panel.
176         *
177         * @see #onPreparePanel
178         */
179        public View onCreatePanelView(int featureId);
180
181        /**
182         * Initialize the contents of the menu for panel 'featureId'.  This is
183         * called if onCreatePanelView() returns null, giving you a standard
184         * menu in which you can place your items.  It is only called once for
185         * the panel, the first time it is shown.
186         *
187         * <p>You can safely hold on to <var>menu</var> (and any items created
188         * from it), making modifications to it as desired, until the next
189         * time onCreatePanelMenu() is called for this feature.
190         *
191         * @param featureId The panel being created.
192         * @param menu The menu inside the panel.
193         *
194         * @return boolean You must return true for the panel to be displayed;
195         *         if you return false it will not be shown.
196         */
197        public boolean onCreatePanelMenu(int featureId, Menu menu);
198
199        /**
200         * Prepare a panel to be displayed.  This is called right before the
201         * panel window is shown, every time it is shown.
202         *
203         * @param featureId The panel that is being displayed.
204         * @param view The View that was returned by onCreatePanelView().
205         * @param menu If onCreatePanelView() returned null, this is the Menu
206         *             being displayed in the panel.
207         *
208         * @return boolean You must return true for the panel to be displayed;
209         *         if you return false it will not be shown.
210         *
211         * @see #onCreatePanelView
212         */
213        public boolean onPreparePanel(int featureId, View view, Menu menu);
214
215        /**
216         * Called when a panel's menu is opened by the user. This may also be
217         * called when the menu is changing from one type to another (for
218         * example, from the icon menu to the expanded menu).
219         *
220         * @param featureId The panel that the menu is in.
221         * @param menu The menu that is opened.
222         * @return Return true to allow the menu to open, or false to prevent
223         *         the menu from opening.
224         */
225        public boolean onMenuOpened(int featureId, Menu menu);
226
227        /**
228         * Called when a panel's menu item has been selected by the user.
229         *
230         * @param featureId The panel that the menu is in.
231         * @param item The menu item that was selected.
232         *
233         * @return boolean Return true to finish processing of selection, or
234         *         false to perform the normal menu handling (calling its
235         *         Runnable or sending a Message to its target Handler).
236         */
237        public boolean onMenuItemSelected(int featureId, MenuItem item);
238
239        /**
240         * This is called whenever the current window attributes change.
241         *
242         */
243        public void onWindowAttributesChanged(WindowManager.LayoutParams attrs);
244
245        /**
246         * This hook is called whenever the content view of the screen changes
247         * (due to a call to
248         * {@link Window#setContentView(View, android.view.ViewGroup.LayoutParams)
249         * Window.setContentView} or
250         * {@link Window#addContentView(View, android.view.ViewGroup.LayoutParams)
251         * Window.addContentView}).
252         */
253        public void onContentChanged();
254
255        /**
256         * This hook is called whenever the window focus changes.  See
257         * {@link View#onWindowFocusChanged(boolean)
258         * View.onWindowFocusChanged(boolean)} for more information.
259         *
260         * @param hasFocus Whether the window now has focus.
261         */
262        public void onWindowFocusChanged(boolean hasFocus);
263
264        /**
265         * Called when the window has been attached to the window manager.
266         * See {@link View#onAttachedToWindow() View.onAttachedToWindow()}
267         * for more information.
268         */
269        public void onAttachedToWindow();
270
271        /**
272         * Called when the window has been attached to the window manager.
273         * See {@link View#onDetachedFromWindow() View.onDetachedFromWindow()}
274         * for more information.
275         */
276        public void onDetachedFromWindow();
277
278        /**
279         * Called when a panel is being closed.  If another logical subsequent
280         * panel is being opened (and this panel is being closed to make room for the subsequent
281         * panel), this method will NOT be called.
282         *
283         * @param featureId The panel that is being displayed.
284         * @param menu If onCreatePanelView() returned null, this is the Menu
285         *            being displayed in the panel.
286         */
287        public void onPanelClosed(int featureId, Menu menu);
288
289        /**
290         * Called when the user signals the desire to start a search.
291         *
292         * @return true if search launched, false if activity refuses (blocks)
293         *
294         * @see android.app.Activity#onSearchRequested()
295         */
296        public boolean onSearchRequested();
297
298        /**
299         * Called when an action mode is being started.
300         *
301         * @param callback Callback to control the lifecycle of this action mode
302         * @return The ActionMode that was started, or null if it was canceled
303         */
304        public ActionMode onStartActionMode(ActionMode.Callback callback);
305    }
306
307    public Window(Context context) {
308        mContext = context;
309    }
310
311    /**
312     * Return the Context this window policy is running in, for retrieving
313     * resources and other information.
314     *
315     * @return Context The Context that was supplied to the constructor.
316     */
317    public final Context getContext() {
318        return mContext;
319    }
320
321    /**
322     * Return the {@link android.R.styleable#Window} attributes from this
323     * window's theme.
324     */
325    public final TypedArray getWindowStyle() {
326        synchronized (this) {
327            if (mWindowStyle == null) {
328                mWindowStyle = mContext.obtainStyledAttributes(
329                        com.android.internal.R.styleable.Window);
330            }
331            return mWindowStyle;
332        }
333    }
334
335    /**
336     * Set the container for this window.  If not set, the DecorWindow
337     * operates as a top-level window; otherwise, it negotiates with the
338     * container to display itself appropriately.
339     *
340     * @param container The desired containing Window.
341     */
342    public void setContainer(Window container) {
343        mContainer = container;
344        if (container != null) {
345            // Embedded screens never have a title.
346            mFeatures |= 1<<FEATURE_NO_TITLE;
347            mLocalFeatures |= 1<<FEATURE_NO_TITLE;
348            container.mHasChildren = true;
349        }
350    }
351
352    /**
353     * Return the container for this Window.
354     *
355     * @return Window The containing window, or null if this is a
356     *         top-level window.
357     */
358    public final Window getContainer() {
359        return mContainer;
360    }
361
362    public final boolean hasChildren() {
363        return mHasChildren;
364    }
365
366    /**
367     * Set the window manager for use by this Window to, for example,
368     * display panels.  This is <em>not</em> used for displaying the
369     * Window itself -- that must be done by the client.
370     *
371     * @param wm The ViewManager for adding new windows.
372     */
373    public void setWindowManager(WindowManager wm,
374            IBinder appToken, String appName) {
375        mAppToken = appToken;
376        mAppName = appName;
377        if (wm == null) {
378            wm = WindowManagerImpl.getDefault();
379        }
380        mWindowManager = new LocalWindowManager(wm);
381    }
382
383    private class LocalWindowManager implements WindowManager {
384        LocalWindowManager(WindowManager wm) {
385            mWindowManager = wm;
386            mDefaultDisplay = mContext.getResources().getDefaultDisplay(
387                    mWindowManager.getDefaultDisplay());
388        }
389
390        public final void addView(View view, ViewGroup.LayoutParams params) {
391            // Let this throw an exception on a bad params.
392            WindowManager.LayoutParams wp = (WindowManager.LayoutParams)params;
393            CharSequence curTitle = wp.getTitle();
394            if (wp.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW &&
395                wp.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
396                if (wp.token == null) {
397                    View decor = peekDecorView();
398                    if (decor != null) {
399                        wp.token = decor.getWindowToken();
400                    }
401                }
402                if (curTitle == null || curTitle.length() == 0) {
403                    String title;
404                    if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA) {
405                        title="Media";
406                    } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY) {
407                        title="MediaOvr";
408                    } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
409                        title="Panel";
410                    } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL) {
411                        title="SubPanel";
412                    } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG) {
413                        title="AtchDlg";
414                    } else {
415                        title=Integer.toString(wp.type);
416                    }
417                    if (mAppName != null) {
418                        title += ":" + mAppName;
419                    }
420                    wp.setTitle(title);
421                }
422            } else {
423                if (wp.token == null) {
424                    wp.token = mContainer == null ? mAppToken : mContainer.mAppToken;
425                }
426                if ((curTitle == null || curTitle.length() == 0)
427                        && mAppName != null) {
428                    wp.setTitle(mAppName);
429                }
430           }
431            if (wp.packageName == null) {
432                wp.packageName = mContext.getPackageName();
433            }
434            mWindowManager.addView(view, params);
435        }
436
437        public void updateViewLayout(View view, ViewGroup.LayoutParams params) {
438            mWindowManager.updateViewLayout(view, params);
439        }
440
441        public final void removeView(View view) {
442            mWindowManager.removeView(view);
443        }
444
445        public final void removeViewImmediate(View view) {
446            mWindowManager.removeViewImmediate(view);
447        }
448
449        public Display getDefaultDisplay() {
450            return mDefaultDisplay;
451        }
452
453        private final WindowManager mWindowManager;
454
455        private final Display mDefaultDisplay;
456    }
457
458    /**
459     * Return the window manager allowing this Window to display its own
460     * windows.
461     *
462     * @return WindowManager The ViewManager.
463     */
464    public WindowManager getWindowManager() {
465        return mWindowManager;
466    }
467
468    /**
469     * Set the Callback interface for this window, used to intercept key
470     * events and other dynamic operations in the window.
471     *
472     * @param callback The desired Callback interface.
473     */
474    public void setCallback(Callback callback) {
475        mCallback = callback;
476    }
477
478    /**
479     * Return the current Callback interface for this window.
480     */
481    public final Callback getCallback() {
482        return mCallback;
483    }
484
485    /**
486     * Take ownership of this window's surface.  The window's view hierarchy
487     * will no longer draw into the surface, though it will otherwise continue
488     * to operate (such as for receiving input events).  The given SurfaceHolder
489     * callback will be used to tell you about state changes to the surface.
490     */
491    public abstract void takeSurface(SurfaceHolder.Callback2 callback);
492
493    /**
494     * Take ownership of this window's InputQueue.  The window will no
495     * longer read and dispatch input events from the queue; it is your
496     * responsibility to do so.
497     */
498    public abstract void takeInputQueue(InputQueue.Callback callback);
499
500    /**
501     * Return whether this window is being displayed with a floating style
502     * (based on the {@link android.R.attr#windowIsFloating} attribute in
503     * the style/theme).
504     *
505     * @return Returns true if the window is configured to be displayed floating
506     * on top of whatever is behind it.
507     */
508    public abstract boolean isFloating();
509
510    /**
511     * Set the width and height layout parameters of the window.  The default
512     * for both of these is MATCH_PARENT; you can change them to WRAP_CONTENT to
513     * make a window that is not full-screen.
514     *
515     * @param width The desired layout width of the window.
516     * @param height The desired layout height of the window.
517     */
518    public void setLayout(int width, int height)
519    {
520        final WindowManager.LayoutParams attrs = getAttributes();
521        attrs.width = width;
522        attrs.height = height;
523        if (mCallback != null) {
524            mCallback.onWindowAttributesChanged(attrs);
525        }
526    }
527
528    /**
529     * Set the gravity of the window, as per the Gravity constants.  This
530     * controls how the window manager is positioned in the overall window; it
531     * is only useful when using WRAP_CONTENT for the layout width or height.
532     *
533     * @param gravity The desired gravity constant.
534     *
535     * @see Gravity
536     * @see #setLayout
537     */
538    public void setGravity(int gravity)
539    {
540        final WindowManager.LayoutParams attrs = getAttributes();
541        attrs.gravity = gravity;
542        if (mCallback != null) {
543            mCallback.onWindowAttributesChanged(attrs);
544        }
545    }
546
547    /**
548     * Set the type of the window, as per the WindowManager.LayoutParams
549     * types.
550     *
551     * @param type The new window type (see WindowManager.LayoutParams).
552     */
553    public void setType(int type) {
554        final WindowManager.LayoutParams attrs = getAttributes();
555        attrs.type = type;
556        if (mCallback != null) {
557            mCallback.onWindowAttributesChanged(attrs);
558        }
559    }
560
561    /**
562     * Set the format of window, as per the PixelFormat types.  This overrides
563     * the default format that is selected by the Window based on its
564     * window decorations.
565     *
566     * @param format The new window format (see PixelFormat).  Use
567     *               PixelFormat.UNKNOWN to allow the Window to select
568     *               the format.
569     *
570     * @see PixelFormat
571     */
572    public void setFormat(int format) {
573        final WindowManager.LayoutParams attrs = getAttributes();
574        if (format != PixelFormat.UNKNOWN) {
575            attrs.format = format;
576            mHaveWindowFormat = true;
577        } else {
578            attrs.format = mDefaultWindowFormat;
579            mHaveWindowFormat = false;
580        }
581        if (mCallback != null) {
582            mCallback.onWindowAttributesChanged(attrs);
583        }
584    }
585
586    /**
587     * Specify custom animations to use for the window, as per
588     * {@link WindowManager.LayoutParams#windowAnimations
589     * WindowManager.LayoutParams.windowAnimations}.  Providing anything besides
590     * 0 here will override the animations the window would
591     * normally retrieve from its theme.
592     */
593    public void setWindowAnimations(int resId) {
594        final WindowManager.LayoutParams attrs = getAttributes();
595        attrs.windowAnimations = resId;
596        if (mCallback != null) {
597            mCallback.onWindowAttributesChanged(attrs);
598        }
599    }
600
601    /**
602     * Specify an explicit soft input mode to use for the window, as per
603     * {@link WindowManager.LayoutParams#softInputMode
604     * WindowManager.LayoutParams.softInputMode}.  Providing anything besides
605     * "unspecified" here will override the input mode the window would
606     * normally retrieve from its theme.
607     */
608    public void setSoftInputMode(int mode) {
609        final WindowManager.LayoutParams attrs = getAttributes();
610        if (mode != WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED) {
611            attrs.softInputMode = mode;
612            mHasSoftInputMode = true;
613        } else {
614            mHasSoftInputMode = false;
615        }
616        if (mCallback != null) {
617            mCallback.onWindowAttributesChanged(attrs);
618        }
619    }
620
621    /**
622     * Convenience function to set the flag bits as specified in flags, as
623     * per {@link #setFlags}.
624     * @param flags The flag bits to be set.
625     * @see #setFlags
626     */
627    public void addFlags(int flags) {
628        setFlags(flags, flags);
629    }
630
631    /**
632     * Convenience function to clear the flag bits as specified in flags, as
633     * per {@link #setFlags}.
634     * @param flags The flag bits to be cleared.
635     * @see #setFlags
636     */
637    public void clearFlags(int flags) {
638        setFlags(0, flags);
639    }
640
641    /**
642     * Set the flags of the window, as per the
643     * {@link WindowManager.LayoutParams WindowManager.LayoutParams}
644     * flags.
645     *
646     * <p>Note that some flags must be set before the window decoration is
647     * created (by the first call to
648     * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)} or
649     * {@link #getDecorView()}:
650     * {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN} and
651     * {@link WindowManager.LayoutParams#FLAG_LAYOUT_INSET_DECOR}.  These
652     * will be set for you based on the {@link android.R.attr#windowIsFloating}
653     * attribute.
654     *
655     * @param flags The new window flags (see WindowManager.LayoutParams).
656     * @param mask Which of the window flag bits to modify.
657     */
658    public void setFlags(int flags, int mask) {
659        final WindowManager.LayoutParams attrs = getAttributes();
660        attrs.flags = (attrs.flags&~mask) | (flags&mask);
661        mForcedWindowFlags |= mask;
662        if (mCallback != null) {
663            mCallback.onWindowAttributesChanged(attrs);
664        }
665    }
666
667    /**
668     * Specify custom window attributes.  <strong>PLEASE NOTE:</strong> the
669     * layout params you give here should generally be from values previously
670     * retrieved with {@link #getAttributes()}; you probably do not want to
671     * blindly create and apply your own, since this will blow away any values
672     * set by the framework that you are not interested in.
673     *
674     * @param a The new window attributes, which will completely override any
675     *          current values.
676     */
677    public void setAttributes(WindowManager.LayoutParams a) {
678        mWindowAttributes.copyFrom(a);
679        if (mCallback != null) {
680            mCallback.onWindowAttributesChanged(mWindowAttributes);
681        }
682    }
683
684    /**
685     * Retrieve the current window attributes associated with this panel.
686     *
687     * @return WindowManager.LayoutParams Either the existing window
688     *         attributes object, or a freshly created one if there is none.
689     */
690    public final WindowManager.LayoutParams getAttributes() {
691        return mWindowAttributes;
692    }
693
694    /**
695     * Return the window flags that have been explicitly set by the client,
696     * so will not be modified by {@link #getDecorView}.
697     */
698    protected final int getForcedWindowFlags() {
699        return mForcedWindowFlags;
700    }
701
702    /**
703     * Has the app specified their own soft input mode?
704     */
705    protected final boolean hasSoftInputMode() {
706        return mHasSoftInputMode;
707    }
708
709    /**
710     * Enable extended screen features.  This must be called before
711     * setContentView().  May be called as many times as desired as long as it
712     * is before setContentView().  If not called, no extended features
713     * will be available.  You can not turn off a feature once it is requested.
714     * You canot use other title features with {@link #FEATURE_CUSTOM_TITLE}.
715     *
716     * @param featureId The desired features, defined as constants by Window.
717     * @return The features that are now set.
718     */
719    public boolean requestFeature(int featureId) {
720        final int flag = 1<<featureId;
721        mFeatures |= flag;
722        mLocalFeatures |= mContainer != null ? (flag&~mContainer.mFeatures) : flag;
723        return (mFeatures&flag) != 0;
724    }
725
726    public final void makeActive() {
727        if (mContainer != null) {
728            if (mContainer.mActiveChild != null) {
729                mContainer.mActiveChild.mIsActive = false;
730            }
731            mContainer.mActiveChild = this;
732        }
733        mIsActive = true;
734        onActive();
735    }
736
737    public final boolean isActive()
738    {
739        return mIsActive;
740    }
741
742    /**
743     * Finds a view that was identified by the id attribute from the XML that
744     * was processed in {@link android.app.Activity#onCreate}.  This will
745     * implicitly call {@link #getDecorView} for you, with all of the
746     * associated side-effects.
747     *
748     * @return The view if found or null otherwise.
749     */
750    public View findViewById(int id) {
751        return getDecorView().findViewById(id);
752    }
753
754    /**
755     * Convenience for
756     * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}
757     * to set the screen content from a layout resource.  The resource will be
758     * inflated, adding all top-level views to the screen.
759     *
760     * @param layoutResID Resource ID to be inflated.
761     * @see #setContentView(View, android.view.ViewGroup.LayoutParams)
762     */
763    public abstract void setContentView(int layoutResID);
764
765    /**
766     * Convenience for
767     * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}
768     * set the screen content to an explicit view.  This view is placed
769     * directly into the screen's view hierarchy.  It can itself be a complex
770     * view hierarhcy.
771     *
772     * @param view The desired content to display.
773     * @see #setContentView(View, android.view.ViewGroup.LayoutParams)
774     */
775    public abstract void setContentView(View view);
776
777    /**
778     * Set the screen content to an explicit view.  This view is placed
779     * directly into the screen's view hierarchy.  It can itself be a complex
780     * view hierarchy.
781     *
782     * <p>Note that calling this function "locks in" various characteristics
783     * of the window that can not, from this point forward, be changed: the
784     * features that have been requested with {@link #requestFeature(int)},
785     * and certain window flags as described in {@link #setFlags(int, int)}.
786     *
787     * @param view The desired content to display.
788     * @param params Layout parameters for the view.
789     */
790    public abstract void setContentView(View view, ViewGroup.LayoutParams params);
791
792    /**
793     * Variation on
794     * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}
795     * to add an additional content view to the screen.  Added after any existing
796     * ones in the screen -- existing views are NOT removed.
797     *
798     * @param view The desired content to display.
799     * @param params Layout parameters for the view.
800     */
801    public abstract void addContentView(View view, ViewGroup.LayoutParams params);
802
803    /**
804     * Return the view in this Window that currently has focus, or null if
805     * there are none.  Note that this does not look in any containing
806     * Window.
807     *
808     * @return View The current View with focus or null.
809     */
810    public abstract View getCurrentFocus();
811
812    /**
813     * Quick access to the {@link LayoutInflater} instance that this Window
814     * retrieved from its Context.
815     *
816     * @return LayoutInflater The shared LayoutInflater.
817     */
818    public abstract LayoutInflater getLayoutInflater();
819
820    public abstract void setTitle(CharSequence title);
821
822    public abstract void setTitleColor(int textColor);
823
824    public abstract void openPanel(int featureId, KeyEvent event);
825
826    public abstract void closePanel(int featureId);
827
828    public abstract void togglePanel(int featureId, KeyEvent event);
829
830    public abstract void invalidatePanelMenu(int featureId);
831
832    public abstract boolean performPanelShortcut(int featureId,
833                                                 int keyCode,
834                                                 KeyEvent event,
835                                                 int flags);
836    public abstract boolean performPanelIdentifierAction(int featureId,
837                                                 int id,
838                                                 int flags);
839
840    public abstract void closeAllPanels();
841
842    public abstract boolean performContextMenuIdentifierAction(int id, int flags);
843
844    /**
845     * Should be called when the configuration is changed.
846     *
847     * @param newConfig The new configuration.
848     */
849    public abstract void onConfigurationChanged(Configuration newConfig);
850
851    /**
852     * Change the background of this window to a Drawable resource. Setting the
853     * background to null will make the window be opaque. To make the window
854     * transparent, you can use an empty drawable (for instance a ColorDrawable
855     * with the color 0 or the system drawable android:drawable/empty.)
856     *
857     * @param resid The resource identifier of a drawable resource which will be
858     *              installed as the new background.
859     */
860    public void setBackgroundDrawableResource(int resid)
861    {
862        setBackgroundDrawable(mContext.getResources().getDrawable(resid));
863    }
864
865    /**
866     * Change the background of this window to a custom Drawable. Setting the
867     * background to null will make the window be opaque. To make the window
868     * transparent, you can use an empty drawable (for instance a ColorDrawable
869     * with the color 0 or the system drawable android:drawable/empty.)
870     *
871     * @param drawable The new Drawable to use for this window's background.
872     */
873    public abstract void setBackgroundDrawable(Drawable drawable);
874
875    /**
876     * Set the value for a drawable feature of this window, from a resource
877     * identifier.  You must have called requestFeauture(featureId) before
878     * calling this function.
879     *
880     * @see android.content.res.Resources#getDrawable(int)
881     *
882     * @param featureId The desired drawable feature to change, defined as a
883     * constant by Window.
884     * @param resId Resource identifier of the desired image.
885     */
886    public abstract void setFeatureDrawableResource(int featureId, int resId);
887
888    /**
889     * Set the value for a drawable feature of this window, from a URI. You
890     * must have called requestFeature(featureId) before calling this
891     * function.
892     *
893     * <p>The only URI currently supported is "content:", specifying an image
894     * in a content provider.
895     *
896     * @see android.widget.ImageView#setImageURI
897     *
898     * @param featureId The desired drawable feature to change. Features are
899     * constants defined by Window.
900     * @param uri The desired URI.
901     */
902    public abstract void setFeatureDrawableUri(int featureId, Uri uri);
903
904    /**
905     * Set an explicit Drawable value for feature of this window. You must
906     * have called requestFeature(featureId) before calling this function.
907     *
908     * @param featureId The desired drawable feature to change.
909     * Features are constants defined by Window.
910     * @param drawable A Drawable object to display.
911     */
912    public abstract void setFeatureDrawable(int featureId, Drawable drawable);
913
914    /**
915     * Set a custom alpha value for the given drawale feature, controlling how
916     * much the background is visible through it.
917     *
918     * @param featureId The desired drawable feature to change.
919     * Features are constants defined by Window.
920     * @param alpha The alpha amount, 0 is completely transparent and 255 is
921     *              completely opaque.
922     */
923    public abstract void setFeatureDrawableAlpha(int featureId, int alpha);
924
925    /**
926     * Set the integer value for a feature.  The range of the value depends on
927     * the feature being set.  For FEATURE_PROGRESSS, it should go from 0 to
928     * 10000. At 10000 the progress is complete and the indicator hidden.
929     *
930     * @param featureId The desired feature to change.
931     * Features are constants defined by Window.
932     * @param value The value for the feature.  The interpretation of this
933     *              value is feature-specific.
934     */
935    public abstract void setFeatureInt(int featureId, int value);
936
937    /**
938     * Request that key events come to this activity. Use this if your
939     * activity has no views with focus, but the activity still wants
940     * a chance to process key events.
941     */
942    public abstract void takeKeyEvents(boolean get);
943
944    /**
945     * Used by custom windows, such as Dialog, to pass the key press event
946     * further down the view hierarchy. Application developers should
947     * not need to implement or call this.
948     *
949     */
950    public abstract boolean superDispatchKeyEvent(KeyEvent event);
951
952    /**
953     * Used by custom windows, such as Dialog, to pass the touch screen event
954     * further down the view hierarchy. Application developers should
955     * not need to implement or call this.
956     *
957     */
958    public abstract boolean superDispatchTouchEvent(MotionEvent event);
959
960    /**
961     * Used by custom windows, such as Dialog, to pass the trackball event
962     * further down the view hierarchy. Application developers should
963     * not need to implement or call this.
964     *
965     */
966    public abstract boolean superDispatchTrackballEvent(MotionEvent event);
967
968    /**
969     * Retrieve the top-level window decor view (containing the standard
970     * window frame/decorations and the client's content inside of that), which
971     * can be added as a window to the window manager.
972     *
973     * <p><em>Note that calling this function for the first time "locks in"
974     * various window characteristics as described in
975     * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}.</em></p>
976     *
977     * @return Returns the top-level window decor view.
978     */
979    public abstract View getDecorView();
980
981    /**
982     * Retrieve the current decor view, but only if it has already been created;
983     * otherwise returns null.
984     *
985     * @return Returns the top-level window decor or null.
986     * @see #getDecorView
987     */
988    public abstract View peekDecorView();
989
990    public abstract Bundle saveHierarchyState();
991
992    public abstract void restoreHierarchyState(Bundle savedInstanceState);
993
994    protected abstract void onActive();
995
996    /**
997     * Return the feature bits that are enabled.  This is the set of features
998     * that were given to requestFeature(), and are being handled by this
999     * Window itself or its container.  That is, it is the set of
1000     * requested features that you can actually use.
1001     *
1002     * <p>To do: add a public version of this API that allows you to check for
1003     * features by their feature ID.
1004     *
1005     * @return int The feature bits.
1006     */
1007    protected final int getFeatures()
1008    {
1009        return mFeatures;
1010    }
1011
1012    /**
1013     * Query for the availability of a certain feature.
1014     *
1015     * @param feature The feature ID to check
1016     * @return true if the feature is enabled, false otherwise.
1017     */
1018    public boolean hasFeature(int feature) {
1019        return (getFeatures() & (1 << feature)) != 0;
1020    }
1021
1022    /**
1023     * Return the feature bits that are being implemented by this Window.
1024     * This is the set of features that were given to requestFeature(), and are
1025     * being handled by only this Window itself, not by its containers.
1026     *
1027     * @return int The feature bits.
1028     */
1029    protected final int getLocalFeatures()
1030    {
1031        return mLocalFeatures;
1032    }
1033
1034    /**
1035     * Set the default format of window, as per the PixelFormat types.  This
1036     * is the format that will be used unless the client specifies in explicit
1037     * format with setFormat();
1038     *
1039     * @param format The new window format (see PixelFormat).
1040     *
1041     * @see #setFormat
1042     * @see PixelFormat
1043     */
1044    protected void setDefaultWindowFormat(int format) {
1045        mDefaultWindowFormat = format;
1046        if (!mHaveWindowFormat) {
1047            final WindowManager.LayoutParams attrs = getAttributes();
1048            attrs.format = format;
1049            if (mCallback != null) {
1050                mCallback.onWindowAttributesChanged(attrs);
1051            }
1052        }
1053    }
1054
1055    public abstract void setChildDrawable(int featureId, Drawable drawable);
1056
1057    public abstract void setChildInt(int featureId, int value);
1058
1059    /**
1060     * Is a keypress one of the defined shortcut keys for this window.
1061     * @param keyCode the key code from {@link android.view.KeyEvent} to check.
1062     * @param event the {@link android.view.KeyEvent} to use to help check.
1063     */
1064    public abstract boolean isShortcutKey(int keyCode, KeyEvent event);
1065
1066    /**
1067     * @see android.app.Activity#setVolumeControlStream(int)
1068     */
1069    public abstract void setVolumeControlStream(int streamType);
1070
1071    /**
1072     * @see android.app.Activity#getVolumeControlStream()
1073     */
1074    public abstract int getVolumeControlStream();
1075
1076}
1077