Window.java revision 9678e34521d7eaa38cd93bee32b1e307956b74bd
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.annotation.NonNull;
20import android.annotation.Nullable;
21import android.content.Context;
22import android.content.res.Configuration;
23import android.content.res.TypedArray;
24import android.graphics.PixelFormat;
25import android.graphics.drawable.Drawable;
26import android.media.session.MediaController;
27import android.net.Uri;
28import android.os.Bundle;
29import android.os.IBinder;
30import android.os.SystemProperties;
31import android.transition.Scene;
32import android.transition.Transition;
33import android.transition.TransitionManager;
34import android.view.accessibility.AccessibilityEvent;
35
36/**
37 * Abstract base class for a top-level window look and behavior policy.  An
38 * instance of this class should be used as the top-level view added to the
39 * window manager. It provides standard UI policies such as a background, title
40 * area, default key processing, etc.
41 *
42 * <p>The only existing implementation of this abstract class is
43 * android.policy.PhoneWindow, which you should instantiate when needing a
44 * Window.  Eventually that class will be refactored and a factory method
45 * added for creating Window instances without knowing about a particular
46 * implementation.
47 */
48public abstract class Window {
49    /** Flag for the "options panel" feature.  This is enabled by default. */
50    public static final int FEATURE_OPTIONS_PANEL = 0;
51    /** Flag for the "no title" feature, turning off the title at the top
52     *  of the screen. */
53    public static final int FEATURE_NO_TITLE = 1;
54    /** Flag for the progress indicator feature */
55    public static final int FEATURE_PROGRESS = 2;
56    /** Flag for having an icon on the left side of the title bar */
57    public static final int FEATURE_LEFT_ICON = 3;
58    /** Flag for having an icon on the right side of the title bar */
59    public static final int FEATURE_RIGHT_ICON = 4;
60    /** Flag for indeterminate progress */
61    public static final int FEATURE_INDETERMINATE_PROGRESS = 5;
62    /** Flag for the context menu.  This is enabled by default. */
63    public static final int FEATURE_CONTEXT_MENU = 6;
64    /** Flag for custom title. You cannot combine this feature with other title features. */
65    public static final int FEATURE_CUSTOM_TITLE = 7;
66    /**
67     * Flag for enabling the Action Bar.
68     * This is enabled by default for some devices. The Action Bar
69     * replaces the title bar and provides an alternate location
70     * for an on-screen menu button on some devices.
71     */
72    public static final int FEATURE_ACTION_BAR = 8;
73    /**
74     * Flag for requesting an Action Bar that overlays window content.
75     * Normally an Action Bar will sit in the space above window content, but if this
76     * feature is requested along with {@link #FEATURE_ACTION_BAR} it will be layered over
77     * the window content itself. This is useful if you would like your app to have more control
78     * over how the Action Bar is displayed, such as letting application content scroll beneath
79     * an Action Bar with a transparent background or otherwise displaying a transparent/translucent
80     * Action Bar over application content.
81     *
82     * <p>This mode is especially useful with {@link View#SYSTEM_UI_FLAG_FULLSCREEN
83     * View.SYSTEM_UI_FLAG_FULLSCREEN}, which allows you to seamlessly hide the
84     * action bar in conjunction with other screen decorations.
85     *
86     * <p>As of {@link android.os.Build.VERSION_CODES#JELLY_BEAN}, when an
87     * ActionBar is in this mode it will adjust the insets provided to
88     * {@link View#fitSystemWindows(android.graphics.Rect) View.fitSystemWindows(Rect)}
89     * to include the content covered by the action bar, so you can do layout within
90     * that space.
91     */
92    public static final int FEATURE_ACTION_BAR_OVERLAY = 9;
93    /**
94     * Flag for specifying the behavior of action modes when an Action Bar is not present.
95     * If overlay is enabled, the action mode UI will be allowed to cover existing window content.
96     */
97    public static final int FEATURE_ACTION_MODE_OVERLAY = 10;
98    /**
99     * Flag for requesting a decoration-free window that is dismissed by swiping from the left.
100     */
101    public static final int FEATURE_SWIPE_TO_DISMISS = 11;
102    /**
103     * Flag for requesting that window content changes should be represented
104     * with scenes and transitions.
105     *
106     * TODO Add docs
107     *
108     * @see #setContentView
109     */
110    public static final int FEATURE_CONTENT_TRANSITIONS = 12;
111
112    /**
113     * Enables Activities to run Activity Transitions either through sending or receiving
114     * ActivityOptions bundle created with
115     * {@link android.app.ActivityOptions#makeSceneTransitionAnimation(android.app.Activity,
116     * android.util.Pair[])} or {@link android.app.ActivityOptions#makeSceneTransitionAnimation(
117     * android.app.Activity, View, String)}.
118     */
119    public static final int FEATURE_ACTIVITY_TRANSITIONS = 13;
120
121    /**
122     * Max value used as a feature ID
123     * @hide
124     */
125    public static final int FEATURE_MAX = FEATURE_ACTIVITY_TRANSITIONS;
126
127    /** Flag for setting the progress bar's visibility to VISIBLE */
128    public static final int PROGRESS_VISIBILITY_ON = -1;
129    /** Flag for setting the progress bar's visibility to GONE */
130    public static final int PROGRESS_VISIBILITY_OFF = -2;
131    /** Flag for setting the progress bar's indeterminate mode on */
132    public static final int PROGRESS_INDETERMINATE_ON = -3;
133    /** Flag for setting the progress bar's indeterminate mode off */
134    public static final int PROGRESS_INDETERMINATE_OFF = -4;
135    /** Starting value for the (primary) progress */
136    public static final int PROGRESS_START = 0;
137    /** Ending value for the (primary) progress */
138    public static final int PROGRESS_END = 10000;
139    /** Lowest possible value for the secondary progress */
140    public static final int PROGRESS_SECONDARY_START = 20000;
141    /** Highest possible value for the secondary progress */
142    public static final int PROGRESS_SECONDARY_END = 30000;
143
144    /**
145     * The transitionName for the status bar background View when a custom background is used.
146     * @see android.view.Window#setStatusBarColor(int)
147     */
148    public static final String STATUS_BAR_BACKGROUND_TRANSITION_NAME = "android:status:background";
149
150    /**
151     * The transitionName for the navigation bar background View when a custom background is used.
152     * @see android.view.Window#setNavigationBarColor(int)
153     */
154    public static final String NAVIGATION_BAR_BACKGROUND_TRANSITION_NAME =
155            "android:navigation:background";
156
157    /** The default features enabled */
158    @SuppressWarnings({"PointlessBitwiseExpression"})
159    protected static final int DEFAULT_FEATURES = (1 << FEATURE_OPTIONS_PANEL) |
160            (1 << FEATURE_CONTEXT_MENU);
161
162    /**
163     * The ID that the main layout in the XML layout file should have.
164     */
165    public static final int ID_ANDROID_CONTENT = com.android.internal.R.id.content;
166
167    private static final String PROPERTY_HARDWARE_UI = "persist.sys.ui.hw";
168
169    private final Context mContext;
170
171    private TypedArray mWindowStyle;
172    private Callback mCallback;
173    private OnWindowDismissedCallback mOnWindowDismissedCallback;
174    private WindowManager mWindowManager;
175    private IBinder mAppToken;
176    private String mAppName;
177    private boolean mHardwareAccelerated;
178    private Window mContainer;
179    private Window mActiveChild;
180    private boolean mIsActive = false;
181    private boolean mHasChildren = false;
182    private boolean mCloseOnTouchOutside = false;
183    private boolean mSetCloseOnTouchOutside = false;
184    private int mForcedWindowFlags = 0;
185
186    private int mFeatures = DEFAULT_FEATURES;
187    private int mLocalFeatures = DEFAULT_FEATURES;
188
189    private boolean mHaveWindowFormat = false;
190    private boolean mHaveDimAmount = false;
191    private int mDefaultWindowFormat = PixelFormat.OPAQUE;
192
193    private boolean mHasSoftInputMode = false;
194
195    private boolean mDestroyed;
196
197    // The current window attributes.
198    private final WindowManager.LayoutParams mWindowAttributes =
199        new WindowManager.LayoutParams();
200
201    /**
202     * API from a Window back to its caller.  This allows the client to
203     * intercept key dispatching, panels and menus, etc.
204     */
205    public interface Callback {
206        /**
207         * Called to process key events.  At the very least your
208         * implementation must call
209         * {@link android.view.Window#superDispatchKeyEvent} to do the
210         * standard key processing.
211         *
212         * @param event The key event.
213         *
214         * @return boolean Return true if this event was consumed.
215         */
216        public boolean dispatchKeyEvent(KeyEvent event);
217
218        /**
219         * Called to process a key shortcut event.
220         * At the very least your implementation must call
221         * {@link android.view.Window#superDispatchKeyShortcutEvent} to do the
222         * standard key shortcut processing.
223         *
224         * @param event The key shortcut event.
225         * @return True if this event was consumed.
226         */
227        public boolean dispatchKeyShortcutEvent(KeyEvent event);
228
229        /**
230         * Called to process touch screen events.  At the very least your
231         * implementation must call
232         * {@link android.view.Window#superDispatchTouchEvent} to do the
233         * standard touch screen processing.
234         *
235         * @param event The touch screen event.
236         *
237         * @return boolean Return true if this event was consumed.
238         */
239        public boolean dispatchTouchEvent(MotionEvent event);
240
241        /**
242         * Called to process trackball events.  At the very least your
243         * implementation must call
244         * {@link android.view.Window#superDispatchTrackballEvent} to do the
245         * standard trackball processing.
246         *
247         * @param event The trackball event.
248         *
249         * @return boolean Return true if this event was consumed.
250         */
251        public boolean dispatchTrackballEvent(MotionEvent event);
252
253        /**
254         * Called to process generic motion events.  At the very least your
255         * implementation must call
256         * {@link android.view.Window#superDispatchGenericMotionEvent} to do the
257         * standard processing.
258         *
259         * @param event The generic motion event.
260         *
261         * @return boolean Return true if this event was consumed.
262         */
263        public boolean dispatchGenericMotionEvent(MotionEvent event);
264
265        /**
266         * Called to process population of {@link AccessibilityEvent}s.
267         *
268         * @param event The event.
269         *
270         * @return boolean Return true if event population was completed.
271         */
272        public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event);
273
274        /**
275         * Instantiate the view to display in the panel for 'featureId'.
276         * You can return null, in which case the default content (typically
277         * a menu) will be created for you.
278         *
279         * @param featureId Which panel is being created.
280         *
281         * @return view The top-level view to place in the panel.
282         *
283         * @see #onPreparePanel
284         */
285        @Nullable
286        public View onCreatePanelView(int featureId);
287
288        /**
289         * Initialize the contents of the menu for panel 'featureId'.  This is
290         * called if onCreatePanelView() returns null, giving you a standard
291         * menu in which you can place your items.  It is only called once for
292         * the panel, the first time it is shown.
293         *
294         * <p>You can safely hold on to <var>menu</var> (and any items created
295         * from it), making modifications to it as desired, until the next
296         * time onCreatePanelMenu() is called for this feature.
297         *
298         * @param featureId The panel being created.
299         * @param menu The menu inside the panel.
300         *
301         * @return boolean You must return true for the panel to be displayed;
302         *         if you return false it will not be shown.
303         */
304        public boolean onCreatePanelMenu(int featureId, Menu menu);
305
306        /**
307         * Prepare a panel to be displayed.  This is called right before the
308         * panel window is shown, every time it is shown.
309         *
310         * @param featureId The panel that is being displayed.
311         * @param view The View that was returned by onCreatePanelView().
312         * @param menu If onCreatePanelView() returned null, this is the Menu
313         *             being displayed in the panel.
314         *
315         * @return boolean You must return true for the panel to be displayed;
316         *         if you return false it will not be shown.
317         *
318         * @see #onCreatePanelView
319         */
320        public boolean onPreparePanel(int featureId, View view, Menu menu);
321
322        /**
323         * Called when a panel's menu is opened by the user. This may also be
324         * called when the menu is changing from one type to another (for
325         * example, from the icon menu to the expanded menu).
326         *
327         * @param featureId The panel that the menu is in.
328         * @param menu The menu that is opened.
329         * @return Return true to allow the menu to open, or false to prevent
330         *         the menu from opening.
331         */
332        public boolean onMenuOpened(int featureId, Menu menu);
333
334        /**
335         * Called when a panel's menu item has been selected by the user.
336         *
337         * @param featureId The panel that the menu is in.
338         * @param item The menu item that was selected.
339         *
340         * @return boolean Return true to finish processing of selection, or
341         *         false to perform the normal menu handling (calling its
342         *         Runnable or sending a Message to its target Handler).
343         */
344        public boolean onMenuItemSelected(int featureId, MenuItem item);
345
346        /**
347         * This is called whenever the current window attributes change.
348         *
349         */
350        public void onWindowAttributesChanged(WindowManager.LayoutParams attrs);
351
352        /**
353         * This hook is called whenever the content view of the screen changes
354         * (due to a call to
355         * {@link Window#setContentView(View, android.view.ViewGroup.LayoutParams)
356         * Window.setContentView} or
357         * {@link Window#addContentView(View, android.view.ViewGroup.LayoutParams)
358         * Window.addContentView}).
359         */
360        public void onContentChanged();
361
362        /**
363         * This hook is called whenever the window focus changes.  See
364         * {@link View#onWindowFocusChanged(boolean)
365         * View.onWindowFocusChanged(boolean)} for more information.
366         *
367         * @param hasFocus Whether the window now has focus.
368         */
369        public void onWindowFocusChanged(boolean hasFocus);
370
371        /**
372         * Called when the window has been attached to the window manager.
373         * See {@link View#onAttachedToWindow() View.onAttachedToWindow()}
374         * for more information.
375         */
376        public void onAttachedToWindow();
377
378        /**
379         * Called when the window has been attached to the window manager.
380         * See {@link View#onDetachedFromWindow() View.onDetachedFromWindow()}
381         * for more information.
382         */
383        public void onDetachedFromWindow();
384
385        /**
386         * Called when a panel is being closed.  If another logical subsequent
387         * panel is being opened (and this panel is being closed to make room for the subsequent
388         * panel), this method will NOT be called.
389         *
390         * @param featureId The panel that is being displayed.
391         * @param menu If onCreatePanelView() returned null, this is the Menu
392         *            being displayed in the panel.
393         */
394        public void onPanelClosed(int featureId, Menu menu);
395
396        /**
397         * Called when the user signals the desire to start a search.
398         *
399         * @return true if search launched, false if activity refuses (blocks)
400         *
401         * @see android.app.Activity#onSearchRequested()
402         */
403        public boolean onSearchRequested();
404
405        /**
406         * Called when an action mode is being started for this window. Gives the
407         * callback an opportunity to handle the action mode in its own unique and
408         * beautiful way. If this method returns null the system can choose a way
409         * to present the mode or choose not to start the mode at all.
410         *
411         * @param callback Callback to control the lifecycle of this action mode
412         * @return The ActionMode that was started, or null if the system should present it
413         */
414        @Nullable
415        public ActionMode onWindowStartingActionMode(ActionMode.Callback callback);
416
417        /**
418         * Called when an action mode has been started. The appropriate mode callback
419         * method will have already been invoked.
420         *
421         * @param mode The new mode that has just been started.
422         */
423        public void onActionModeStarted(ActionMode mode);
424
425        /**
426         * Called when an action mode has been finished. The appropriate mode callback
427         * method will have already been invoked.
428         *
429         * @param mode The mode that was just finished.
430         */
431        public void onActionModeFinished(ActionMode mode);
432    }
433
434    /** @hide */
435    public interface OnWindowDismissedCallback {
436        /**
437         * Called when a window is dismissed. This informs the callback that the
438         * window is gone, and it should finish itself.
439         */
440        public void onWindowDismissed();
441    }
442
443    public Window(Context context) {
444        mContext = context;
445    }
446
447    /**
448     * Return the Context this window policy is running in, for retrieving
449     * resources and other information.
450     *
451     * @return Context The Context that was supplied to the constructor.
452     */
453    public final Context getContext() {
454        return mContext;
455    }
456
457    /**
458     * Return the {@link android.R.styleable#Window} attributes from this
459     * window's theme.
460     */
461    public final TypedArray getWindowStyle() {
462        synchronized (this) {
463            if (mWindowStyle == null) {
464                mWindowStyle = mContext.obtainStyledAttributes(
465                        com.android.internal.R.styleable.Window);
466            }
467            return mWindowStyle;
468        }
469    }
470
471    /**
472     * Set the container for this window.  If not set, the DecorWindow
473     * operates as a top-level window; otherwise, it negotiates with the
474     * container to display itself appropriately.
475     *
476     * @param container The desired containing Window.
477     */
478    public void setContainer(Window container) {
479        mContainer = container;
480        if (container != null) {
481            // Embedded screens never have a title.
482            mFeatures |= 1<<FEATURE_NO_TITLE;
483            mLocalFeatures |= 1<<FEATURE_NO_TITLE;
484            container.mHasChildren = true;
485        }
486    }
487
488    /**
489     * Return the container for this Window.
490     *
491     * @return Window The containing window, or null if this is a
492     *         top-level window.
493     */
494    public final Window getContainer() {
495        return mContainer;
496    }
497
498    public final boolean hasChildren() {
499        return mHasChildren;
500    }
501
502    /** @hide */
503    public final void destroy() {
504        mDestroyed = true;
505    }
506
507    /** @hide */
508    public final boolean isDestroyed() {
509        return mDestroyed;
510    }
511
512    /**
513     * Set the window manager for use by this Window to, for example,
514     * display panels.  This is <em>not</em> used for displaying the
515     * Window itself -- that must be done by the client.
516     *
517     * @param wm The window manager for adding new windows.
518     */
519    public void setWindowManager(WindowManager wm, IBinder appToken, String appName) {
520        setWindowManager(wm, appToken, appName, false);
521    }
522
523    /**
524     * Set the window manager for use by this Window to, for example,
525     * display panels.  This is <em>not</em> used for displaying the
526     * Window itself -- that must be done by the client.
527     *
528     * @param wm The window manager for adding new windows.
529     */
530    public void setWindowManager(WindowManager wm, IBinder appToken, String appName,
531            boolean hardwareAccelerated) {
532        mAppToken = appToken;
533        mAppName = appName;
534        mHardwareAccelerated = hardwareAccelerated
535                || SystemProperties.getBoolean(PROPERTY_HARDWARE_UI, false);
536        if (wm == null) {
537            wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
538        }
539        mWindowManager = ((WindowManagerImpl)wm).createLocalWindowManager(this);
540    }
541
542    void adjustLayoutParamsForSubWindow(WindowManager.LayoutParams wp) {
543        CharSequence curTitle = wp.getTitle();
544        if (wp.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW &&
545            wp.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
546            if (wp.token == null) {
547                View decor = peekDecorView();
548                if (decor != null) {
549                    wp.token = decor.getWindowToken();
550                }
551            }
552            if (curTitle == null || curTitle.length() == 0) {
553                String title;
554                if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA) {
555                    title="Media";
556                } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY) {
557                    title="MediaOvr";
558                } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
559                    title="Panel";
560                } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL) {
561                    title="SubPanel";
562                } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG) {
563                    title="AtchDlg";
564                } else {
565                    title=Integer.toString(wp.type);
566                }
567                if (mAppName != null) {
568                    title += ":" + mAppName;
569                }
570                wp.setTitle(title);
571            }
572        } else {
573            if (wp.token == null) {
574                wp.token = mContainer == null ? mAppToken : mContainer.mAppToken;
575            }
576            if ((curTitle == null || curTitle.length() == 0)
577                    && mAppName != null) {
578                wp.setTitle(mAppName);
579            }
580        }
581        if (wp.packageName == null) {
582            wp.packageName = mContext.getPackageName();
583        }
584        if (mHardwareAccelerated) {
585            wp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
586        }
587    }
588
589    /**
590     * Return the window manager allowing this Window to display its own
591     * windows.
592     *
593     * @return WindowManager The ViewManager.
594     */
595    public WindowManager getWindowManager() {
596        return mWindowManager;
597    }
598
599    /**
600     * Set the Callback interface for this window, used to intercept key
601     * events and other dynamic operations in the window.
602     *
603     * @param callback The desired Callback interface.
604     */
605    public void setCallback(Callback callback) {
606        mCallback = callback;
607    }
608
609    /**
610     * Return the current Callback interface for this window.
611     */
612    public final Callback getCallback() {
613        return mCallback;
614    }
615
616    /** @hide */
617    public final void setOnWindowDismissedCallback(OnWindowDismissedCallback dcb) {
618        mOnWindowDismissedCallback = dcb;
619    }
620
621    /** @hide */
622    public final void dispatchOnWindowDismissed() {
623        if (mOnWindowDismissedCallback != null) {
624            mOnWindowDismissedCallback.onWindowDismissed();
625        }
626    }
627
628    /**
629     * Take ownership of this window's surface.  The window's view hierarchy
630     * will no longer draw into the surface, though it will otherwise continue
631     * to operate (such as for receiving input events).  The given SurfaceHolder
632     * callback will be used to tell you about state changes to the surface.
633     */
634    public abstract void takeSurface(SurfaceHolder.Callback2 callback);
635
636    /**
637     * Take ownership of this window's InputQueue.  The window will no
638     * longer read and dispatch input events from the queue; it is your
639     * responsibility to do so.
640     */
641    public abstract void takeInputQueue(InputQueue.Callback callback);
642
643    /**
644     * Return whether this window is being displayed with a floating style
645     * (based on the {@link android.R.attr#windowIsFloating} attribute in
646     * the style/theme).
647     *
648     * @return Returns true if the window is configured to be displayed floating
649     * on top of whatever is behind it.
650     */
651    public abstract boolean isFloating();
652
653    /**
654     * Set the width and height layout parameters of the window.  The default
655     * for both of these is MATCH_PARENT; you can change them to WRAP_CONTENT
656     * or an absolute value to make a window that is not full-screen.
657     *
658     * @param width The desired layout width of the window.
659     * @param height The desired layout height of the window.
660     *
661     * @see ViewGroup.LayoutParams#height
662     * @see ViewGroup.LayoutParams#width
663     */
664    public void setLayout(int width, int height) {
665        final WindowManager.LayoutParams attrs = getAttributes();
666        attrs.width = width;
667        attrs.height = height;
668        dispatchWindowAttributesChanged(attrs);
669    }
670
671    /**
672     * Set the gravity of the window, as per the Gravity constants.  This
673     * controls how the window manager is positioned in the overall window; it
674     * is only useful when using WRAP_CONTENT for the layout width or height.
675     *
676     * @param gravity The desired gravity constant.
677     *
678     * @see Gravity
679     * @see #setLayout
680     */
681    public void setGravity(int gravity)
682    {
683        final WindowManager.LayoutParams attrs = getAttributes();
684        attrs.gravity = gravity;
685        dispatchWindowAttributesChanged(attrs);
686    }
687
688    /**
689     * Set the type of the window, as per the WindowManager.LayoutParams
690     * types.
691     *
692     * @param type The new window type (see WindowManager.LayoutParams).
693     */
694    public void setType(int type) {
695        final WindowManager.LayoutParams attrs = getAttributes();
696        attrs.type = type;
697        dispatchWindowAttributesChanged(attrs);
698    }
699
700    /**
701     * Set the format of window, as per the PixelFormat types.  This overrides
702     * the default format that is selected by the Window based on its
703     * window decorations.
704     *
705     * @param format The new window format (see PixelFormat).  Use
706     *               PixelFormat.UNKNOWN to allow the Window to select
707     *               the format.
708     *
709     * @see PixelFormat
710     */
711    public void setFormat(int format) {
712        final WindowManager.LayoutParams attrs = getAttributes();
713        if (format != PixelFormat.UNKNOWN) {
714            attrs.format = format;
715            mHaveWindowFormat = true;
716        } else {
717            attrs.format = mDefaultWindowFormat;
718            mHaveWindowFormat = false;
719        }
720        dispatchWindowAttributesChanged(attrs);
721    }
722
723    /**
724     * Specify custom animations to use for the window, as per
725     * {@link WindowManager.LayoutParams#windowAnimations
726     * WindowManager.LayoutParams.windowAnimations}.  Providing anything besides
727     * 0 here will override the animations the window would
728     * normally retrieve from its theme.
729     */
730    public void setWindowAnimations(int resId) {
731        final WindowManager.LayoutParams attrs = getAttributes();
732        attrs.windowAnimations = resId;
733        dispatchWindowAttributesChanged(attrs);
734    }
735
736    /**
737     * Specify an explicit soft input mode to use for the window, as per
738     * {@link WindowManager.LayoutParams#softInputMode
739     * WindowManager.LayoutParams.softInputMode}.  Providing anything besides
740     * "unspecified" here will override the input mode the window would
741     * normally retrieve from its theme.
742     */
743    public void setSoftInputMode(int mode) {
744        final WindowManager.LayoutParams attrs = getAttributes();
745        if (mode != WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED) {
746            attrs.softInputMode = mode;
747            mHasSoftInputMode = true;
748        } else {
749            mHasSoftInputMode = false;
750        }
751        dispatchWindowAttributesChanged(attrs);
752    }
753
754    /**
755     * Convenience function to set the flag bits as specified in flags, as
756     * per {@link #setFlags}.
757     * @param flags The flag bits to be set.
758     * @see #setFlags
759     * @see #clearFlags
760     */
761    public void addFlags(int flags) {
762        setFlags(flags, flags);
763    }
764
765    /** @hide */
766    public void addPrivateFlags(int flags) {
767        setPrivateFlags(flags, flags);
768    }
769
770    /**
771     * Convenience function to clear the flag bits as specified in flags, as
772     * per {@link #setFlags}.
773     * @param flags The flag bits to be cleared.
774     * @see #setFlags
775     * @see #addFlags
776     */
777    public void clearFlags(int flags) {
778        setFlags(0, flags);
779    }
780
781    /**
782     * Set the flags of the window, as per the
783     * {@link WindowManager.LayoutParams WindowManager.LayoutParams}
784     * flags.
785     *
786     * <p>Note that some flags must be set before the window decoration is
787     * created (by the first call to
788     * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)} or
789     * {@link #getDecorView()}:
790     * {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN} and
791     * {@link WindowManager.LayoutParams#FLAG_LAYOUT_INSET_DECOR}.  These
792     * will be set for you based on the {@link android.R.attr#windowIsFloating}
793     * attribute.
794     *
795     * @param flags The new window flags (see WindowManager.LayoutParams).
796     * @param mask Which of the window flag bits to modify.
797     * @see #addFlags
798     * @see #clearFlags
799     */
800    public void setFlags(int flags, int mask) {
801        final WindowManager.LayoutParams attrs = getAttributes();
802        attrs.flags = (attrs.flags&~mask) | (flags&mask);
803        mForcedWindowFlags |= mask;
804        dispatchWindowAttributesChanged(attrs);
805    }
806
807    private void setPrivateFlags(int flags, int mask) {
808        final WindowManager.LayoutParams attrs = getAttributes();
809        attrs.privateFlags = (attrs.privateFlags & ~mask) | (flags & mask);
810        dispatchWindowAttributesChanged(attrs);
811    }
812
813    /**
814     * {@hide}
815     */
816    protected void setNeedsMenuKey(int value) {
817        final WindowManager.LayoutParams attrs = getAttributes();
818        attrs.needsMenuKey = value;
819        dispatchWindowAttributesChanged(attrs);
820    }
821
822    /**
823     * {@hide}
824     */
825    protected void dispatchWindowAttributesChanged(WindowManager.LayoutParams attrs) {
826        if (mCallback != null) {
827            mCallback.onWindowAttributesChanged(attrs);
828        }
829    }
830
831    /**
832     * Set the amount of dim behind the window when using
833     * {@link WindowManager.LayoutParams#FLAG_DIM_BEHIND}.  This overrides
834     * the default dim amount of that is selected by the Window based on
835     * its theme.
836     *
837     * @param amount The new dim amount, from 0 for no dim to 1 for full dim.
838     */
839    public void setDimAmount(float amount) {
840        final WindowManager.LayoutParams attrs = getAttributes();
841        attrs.dimAmount = amount;
842        mHaveDimAmount = true;
843        dispatchWindowAttributesChanged(attrs);
844    }
845
846    /**
847     * Specify custom window attributes.  <strong>PLEASE NOTE:</strong> the
848     * layout params you give here should generally be from values previously
849     * retrieved with {@link #getAttributes()}; you probably do not want to
850     * blindly create and apply your own, since this will blow away any values
851     * set by the framework that you are not interested in.
852     *
853     * @param a The new window attributes, which will completely override any
854     *          current values.
855     */
856    public void setAttributes(WindowManager.LayoutParams a) {
857        mWindowAttributes.copyFrom(a);
858        dispatchWindowAttributesChanged(mWindowAttributes);
859    }
860
861    /**
862     * Retrieve the current window attributes associated with this panel.
863     *
864     * @return WindowManager.LayoutParams Either the existing window
865     *         attributes object, or a freshly created one if there is none.
866     */
867    public final WindowManager.LayoutParams getAttributes() {
868        return mWindowAttributes;
869    }
870
871    /**
872     * Return the window flags that have been explicitly set by the client,
873     * so will not be modified by {@link #getDecorView}.
874     */
875    protected final int getForcedWindowFlags() {
876        return mForcedWindowFlags;
877    }
878
879    /**
880     * Has the app specified their own soft input mode?
881     */
882    protected final boolean hasSoftInputMode() {
883        return mHasSoftInputMode;
884    }
885
886    /** @hide */
887    public void setCloseOnTouchOutside(boolean close) {
888        mCloseOnTouchOutside = close;
889        mSetCloseOnTouchOutside = true;
890    }
891
892    /** @hide */
893    public void setCloseOnTouchOutsideIfNotSet(boolean close) {
894        if (!mSetCloseOnTouchOutside) {
895            mCloseOnTouchOutside = close;
896            mSetCloseOnTouchOutside = true;
897        }
898    }
899
900    /** @hide */
901    public abstract void alwaysReadCloseOnTouchAttr();
902
903    /** @hide */
904    public boolean shouldCloseOnTouch(Context context, MotionEvent event) {
905        if (mCloseOnTouchOutside && event.getAction() == MotionEvent.ACTION_DOWN
906                && isOutOfBounds(context, event) && peekDecorView() != null) {
907            return true;
908        }
909        return false;
910    }
911
912    private boolean isOutOfBounds(Context context, MotionEvent event) {
913        final int x = (int) event.getX();
914        final int y = (int) event.getY();
915        final int slop = ViewConfiguration.get(context).getScaledWindowTouchSlop();
916        final View decorView = getDecorView();
917        return (x < -slop) || (y < -slop)
918                || (x > (decorView.getWidth()+slop))
919                || (y > (decorView.getHeight()+slop));
920    }
921
922    /**
923     * Enable extended screen features.  This must be called before
924     * setContentView().  May be called as many times as desired as long as it
925     * is before setContentView().  If not called, no extended features
926     * will be available.  You can not turn off a feature once it is requested.
927     * You canot use other title features with {@link #FEATURE_CUSTOM_TITLE}.
928     *
929     * @param featureId The desired features, defined as constants by Window.
930     * @return The features that are now set.
931     */
932    public boolean requestFeature(int featureId) {
933        final int flag = 1<<featureId;
934        mFeatures |= flag;
935        mLocalFeatures |= mContainer != null ? (flag&~mContainer.mFeatures) : flag;
936        return (mFeatures&flag) != 0;
937    }
938
939    /**
940     * @hide Used internally to help resolve conflicting features.
941     */
942    protected void removeFeature(int featureId) {
943        final int flag = 1<<featureId;
944        mFeatures &= ~flag;
945        mLocalFeatures &= ~(mContainer != null ? (flag&~mContainer.mFeatures) : flag);
946    }
947
948    public final void makeActive() {
949        if (mContainer != null) {
950            if (mContainer.mActiveChild != null) {
951                mContainer.mActiveChild.mIsActive = false;
952            }
953            mContainer.mActiveChild = this;
954        }
955        mIsActive = true;
956        onActive();
957    }
958
959    public final boolean isActive()
960    {
961        return mIsActive;
962    }
963
964    /**
965     * Finds a view that was identified by the id attribute from the XML that
966     * was processed in {@link android.app.Activity#onCreate}.  This will
967     * implicitly call {@link #getDecorView} for you, with all of the
968     * associated side-effects.
969     *
970     * @return The view if found or null otherwise.
971     */
972    public View findViewById(int id) {
973        return getDecorView().findViewById(id);
974    }
975
976    /**
977     * Convenience for
978     * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}
979     * to set the screen content from a layout resource.  The resource will be
980     * inflated, adding all top-level views to the screen.
981     *
982     * @param layoutResID Resource ID to be inflated.
983     * @see #setContentView(View, android.view.ViewGroup.LayoutParams)
984     */
985    public abstract void setContentView(int layoutResID);
986
987    /**
988     * Convenience for
989     * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}
990     * set the screen content to an explicit view.  This view is placed
991     * directly into the screen's view hierarchy.  It can itself be a complex
992     * view hierarhcy.
993     *
994     * @param view The desired content to display.
995     * @see #setContentView(View, android.view.ViewGroup.LayoutParams)
996     */
997    public abstract void setContentView(View view);
998
999    /**
1000     * Set the screen content to an explicit view.  This view is placed
1001     * directly into the screen's view hierarchy.  It can itself be a complex
1002     * view hierarchy.
1003     *
1004     * <p>Note that calling this function "locks in" various characteristics
1005     * of the window that can not, from this point forward, be changed: the
1006     * features that have been requested with {@link #requestFeature(int)},
1007     * and certain window flags as described in {@link #setFlags(int, int)}.
1008     *
1009     * @param view The desired content to display.
1010     * @param params Layout parameters for the view.
1011     */
1012    public abstract void setContentView(View view, ViewGroup.LayoutParams params);
1013
1014    /**
1015     * Variation on
1016     * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}
1017     * to add an additional content view to the screen.  Added after any existing
1018     * ones in the screen -- existing views are NOT removed.
1019     *
1020     * @param view The desired content to display.
1021     * @param params Layout parameters for the view.
1022     */
1023    public abstract void addContentView(View view, ViewGroup.LayoutParams params);
1024
1025    /**
1026     * Return the view in this Window that currently has focus, or null if
1027     * there are none.  Note that this does not look in any containing
1028     * Window.
1029     *
1030     * @return View The current View with focus or null.
1031     */
1032    @Nullable
1033    public abstract View getCurrentFocus();
1034
1035    /**
1036     * Quick access to the {@link LayoutInflater} instance that this Window
1037     * retrieved from its Context.
1038     *
1039     * @return LayoutInflater The shared LayoutInflater.
1040     */
1041    @NonNull
1042    public abstract LayoutInflater getLayoutInflater();
1043
1044    public abstract void setTitle(CharSequence title);
1045
1046    @Deprecated
1047    public abstract void setTitleColor(int textColor);
1048
1049    public abstract void openPanel(int featureId, KeyEvent event);
1050
1051    public abstract void closePanel(int featureId);
1052
1053    public abstract void togglePanel(int featureId, KeyEvent event);
1054
1055    public abstract void invalidatePanelMenu(int featureId);
1056
1057    public abstract boolean performPanelShortcut(int featureId,
1058                                                 int keyCode,
1059                                                 KeyEvent event,
1060                                                 int flags);
1061    public abstract boolean performPanelIdentifierAction(int featureId,
1062                                                 int id,
1063                                                 int flags);
1064
1065    public abstract void closeAllPanels();
1066
1067    public abstract boolean performContextMenuIdentifierAction(int id, int flags);
1068
1069    /**
1070     * Should be called when the configuration is changed.
1071     *
1072     * @param newConfig The new configuration.
1073     */
1074    public abstract void onConfigurationChanged(Configuration newConfig);
1075
1076    /**
1077     * Change the background of this window to a Drawable resource. Setting the
1078     * background to null will make the window be opaque. To make the window
1079     * transparent, you can use an empty drawable (for instance a ColorDrawable
1080     * with the color 0 or the system drawable android:drawable/empty.)
1081     *
1082     * @param resid The resource identifier of a drawable resource which will be
1083     *              installed as the new background.
1084     */
1085    public void setBackgroundDrawableResource(int resid)
1086    {
1087        setBackgroundDrawable(mContext.getDrawable(resid));
1088    }
1089
1090    /**
1091     * Change the background of this window to a custom Drawable. Setting the
1092     * background to null will make the window be opaque. To make the window
1093     * transparent, you can use an empty drawable (for instance a ColorDrawable
1094     * with the color 0 or the system drawable android:drawable/empty.)
1095     *
1096     * @param drawable The new Drawable to use for this window's background.
1097     */
1098    public abstract void setBackgroundDrawable(Drawable drawable);
1099
1100    /**
1101     * Set the value for a drawable feature of this window, from a resource
1102     * identifier.  You must have called requestFeauture(featureId) before
1103     * calling this function.
1104     *
1105     * @see android.content.res.Resources#getDrawable(int)
1106     *
1107     * @param featureId The desired drawable feature to change, defined as a
1108     * constant by Window.
1109     * @param resId Resource identifier of the desired image.
1110     */
1111    public abstract void setFeatureDrawableResource(int featureId, int resId);
1112
1113    /**
1114     * Set the value for a drawable feature of this window, from a URI. You
1115     * must have called requestFeature(featureId) before calling this
1116     * function.
1117     *
1118     * <p>The only URI currently supported is "content:", specifying an image
1119     * in a content provider.
1120     *
1121     * @see android.widget.ImageView#setImageURI
1122     *
1123     * @param featureId The desired drawable feature to change. Features are
1124     * constants defined by Window.
1125     * @param uri The desired URI.
1126     */
1127    public abstract void setFeatureDrawableUri(int featureId, Uri uri);
1128
1129    /**
1130     * Set an explicit Drawable value for feature of this window. You must
1131     * have called requestFeature(featureId) before calling this function.
1132     *
1133     * @param featureId The desired drawable feature to change. Features are
1134     *                  constants defined by Window.
1135     * @param drawable A Drawable object to display.
1136     */
1137    public abstract void setFeatureDrawable(int featureId, Drawable drawable);
1138
1139    /**
1140     * Set a custom alpha value for the given drawable feature, controlling how
1141     * much the background is visible through it.
1142     *
1143     * @param featureId The desired drawable feature to change. Features are
1144     *                  constants defined by Window.
1145     * @param alpha The alpha amount, 0 is completely transparent and 255 is
1146     *              completely opaque.
1147     */
1148    public abstract void setFeatureDrawableAlpha(int featureId, int alpha);
1149
1150    /**
1151     * Set the integer value for a feature. The range of the value depends on
1152     * the feature being set. For {@link #FEATURE_PROGRESS}, it should go from
1153     * 0 to 10000. At 10000 the progress is complete and the indicator hidden.
1154     *
1155     * @param featureId The desired feature to change. Features are constants
1156     *                  defined by Window.
1157     * @param value The value for the feature. The interpretation of this
1158     *              value is feature-specific.
1159     */
1160    public abstract void setFeatureInt(int featureId, int value);
1161
1162    /**
1163     * Request that key events come to this activity. Use this if your
1164     * activity has no views with focus, but the activity still wants
1165     * a chance to process key events.
1166     */
1167    public abstract void takeKeyEvents(boolean get);
1168
1169    /**
1170     * Used by custom windows, such as Dialog, to pass the key press event
1171     * further down the view hierarchy. Application developers should
1172     * not need to implement or call this.
1173     *
1174     */
1175    public abstract boolean superDispatchKeyEvent(KeyEvent event);
1176
1177    /**
1178     * Used by custom windows, such as Dialog, to pass the key shortcut press event
1179     * further down the view hierarchy. Application developers should
1180     * not need to implement or call this.
1181     *
1182     */
1183    public abstract boolean superDispatchKeyShortcutEvent(KeyEvent event);
1184
1185    /**
1186     * Used by custom windows, such as Dialog, to pass the touch screen event
1187     * further down the view hierarchy. Application developers should
1188     * not need to implement or call this.
1189     *
1190     */
1191    public abstract boolean superDispatchTouchEvent(MotionEvent event);
1192
1193    /**
1194     * Used by custom windows, such as Dialog, to pass the trackball event
1195     * further down the view hierarchy. Application developers should
1196     * not need to implement or call this.
1197     *
1198     */
1199    public abstract boolean superDispatchTrackballEvent(MotionEvent event);
1200
1201    /**
1202     * Used by custom windows, such as Dialog, to pass the generic motion event
1203     * further down the view hierarchy. Application developers should
1204     * not need to implement or call this.
1205     *
1206     */
1207    public abstract boolean superDispatchGenericMotionEvent(MotionEvent event);
1208
1209    /**
1210     * Retrieve the top-level window decor view (containing the standard
1211     * window frame/decorations and the client's content inside of that), which
1212     * can be added as a window to the window manager.
1213     *
1214     * <p><em>Note that calling this function for the first time "locks in"
1215     * various window characteristics as described in
1216     * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}.</em></p>
1217     *
1218     * @return Returns the top-level window decor view.
1219     */
1220    public abstract View getDecorView();
1221
1222    /**
1223     * Retrieve the current decor view, but only if it has already been created;
1224     * otherwise returns null.
1225     *
1226     * @return Returns the top-level window decor or null.
1227     * @see #getDecorView
1228     */
1229    public abstract View peekDecorView();
1230
1231    public abstract Bundle saveHierarchyState();
1232
1233    public abstract void restoreHierarchyState(Bundle savedInstanceState);
1234
1235    protected abstract void onActive();
1236
1237    /**
1238     * Return the feature bits that are enabled.  This is the set of features
1239     * that were given to requestFeature(), and are being handled by this
1240     * Window itself or its container.  That is, it is the set of
1241     * requested features that you can actually use.
1242     *
1243     * <p>To do: add a public version of this API that allows you to check for
1244     * features by their feature ID.
1245     *
1246     * @return int The feature bits.
1247     */
1248    protected final int getFeatures()
1249    {
1250        return mFeatures;
1251    }
1252
1253    /**
1254     * Query for the availability of a certain feature.
1255     *
1256     * @param feature The feature ID to check
1257     * @return true if the feature is enabled, false otherwise.
1258     */
1259    public boolean hasFeature(int feature) {
1260        return (getFeatures() & (1 << feature)) != 0;
1261    }
1262
1263    /**
1264     * Return the feature bits that are being implemented by this Window.
1265     * This is the set of features that were given to requestFeature(), and are
1266     * being handled by only this Window itself, not by its containers.
1267     *
1268     * @return int The feature bits.
1269     */
1270    protected final int getLocalFeatures()
1271    {
1272        return mLocalFeatures;
1273    }
1274
1275    /**
1276     * Set the default format of window, as per the PixelFormat types.  This
1277     * is the format that will be used unless the client specifies in explicit
1278     * format with setFormat();
1279     *
1280     * @param format The new window format (see PixelFormat).
1281     *
1282     * @see #setFormat
1283     * @see PixelFormat
1284     */
1285    protected void setDefaultWindowFormat(int format) {
1286        mDefaultWindowFormat = format;
1287        if (!mHaveWindowFormat) {
1288            final WindowManager.LayoutParams attrs = getAttributes();
1289            attrs.format = format;
1290            dispatchWindowAttributesChanged(attrs);
1291        }
1292    }
1293
1294    /** @hide */
1295    protected boolean haveDimAmount() {
1296        return mHaveDimAmount;
1297    }
1298
1299    public abstract void setChildDrawable(int featureId, Drawable drawable);
1300
1301    public abstract void setChildInt(int featureId, int value);
1302
1303    /**
1304     * Is a keypress one of the defined shortcut keys for this window.
1305     * @param keyCode the key code from {@link android.view.KeyEvent} to check.
1306     * @param event the {@link android.view.KeyEvent} to use to help check.
1307     */
1308    public abstract boolean isShortcutKey(int keyCode, KeyEvent event);
1309
1310    /**
1311     * @see android.app.Activity#setVolumeControlStream(int)
1312     */
1313    public abstract void setVolumeControlStream(int streamType);
1314
1315    /**
1316     * @see android.app.Activity#getVolumeControlStream()
1317     */
1318    public abstract int getVolumeControlStream();
1319
1320    /**
1321     * Sets a {@link MediaController} to send media keys and volume changes to.
1322     * If set, this should be preferred for all media keys and volume requests
1323     * sent to this window.
1324     *
1325     * @param controller The controller for the session which should receive
1326     *            media keys and volume changes.
1327     * @see android.app.Activity#setMediaController(android.media.session.MediaController)
1328     */
1329    public void setMediaController(MediaController controller) {
1330    }
1331
1332    /**
1333     * Gets the {@link MediaController} that was previously set.
1334     *
1335     * @return The controller which should receive events.
1336     * @see #setMediaController(android.media.session.MediaController)
1337     * @see android.app.Activity#getMediaController()
1338     */
1339    public MediaController getMediaController() {
1340        return null;
1341    }
1342
1343    /**
1344     * Set extra options that will influence the UI for this window.
1345     * @param uiOptions Flags specifying extra options for this window.
1346     */
1347    public void setUiOptions(int uiOptions) { }
1348
1349    /**
1350     * Set extra options that will influence the UI for this window.
1351     * Only the bits filtered by mask will be modified.
1352     * @param uiOptions Flags specifying extra options for this window.
1353     * @param mask Flags specifying which options should be modified. Others will remain unchanged.
1354     */
1355    public void setUiOptions(int uiOptions, int mask) { }
1356
1357    /**
1358     * Set the primary icon for this window.
1359     *
1360     * @param resId resource ID of a drawable to set
1361     */
1362    public void setIcon(int resId) { }
1363
1364    /**
1365     * Set the default icon for this window.
1366     * This will be overridden by any other icon set operation which could come from the
1367     * theme or another explicit set.
1368     *
1369     * @hide
1370     */
1371    public void setDefaultIcon(int resId) { }
1372
1373    /**
1374     * Set the logo for this window. A logo is often shown in place of an
1375     * {@link #setIcon(int) icon} but is generally wider and communicates window title information
1376     * as well.
1377     *
1378     * @param resId resource ID of a drawable to set
1379     */
1380    public void setLogo(int resId) { }
1381
1382    /**
1383     * Set the default logo for this window.
1384     * This will be overridden by any other logo set operation which could come from the
1385     * theme or another explicit set.
1386     *
1387     * @hide
1388     */
1389    public void setDefaultLogo(int resId) { }
1390
1391    /**
1392     * Set focus locally. The window should have the
1393     * {@link WindowManager.LayoutParams#FLAG_LOCAL_FOCUS_MODE} flag set already.
1394     * @param hasFocus Whether this window has focus or not.
1395     * @param inTouchMode Whether this window is in touch mode or not.
1396     */
1397    public void setLocalFocus(boolean hasFocus, boolean inTouchMode) { }
1398
1399    /**
1400     * Inject an event to window locally.
1401     * @param event A key or touch event to inject to this window.
1402     */
1403    public void injectInputEvent(InputEvent event) { }
1404
1405    /**
1406     * Retrieve the {@link TransitionManager} responsible for  for default transitions
1407     * in this window. Requires {@link #FEATURE_CONTENT_TRANSITIONS}.
1408     *
1409     * <p>This method will return non-null after content has been initialized (e.g. by using
1410     * {@link #setContentView}) if {@link #FEATURE_CONTENT_TRANSITIONS} has been granted.</p>
1411     *
1412     * @return This window's content TransitionManager or null if none is set.
1413     */
1414    public TransitionManager getTransitionManager() {
1415        return null;
1416    }
1417
1418    /**
1419     * Set the {@link TransitionManager} to use for default transitions in this window.
1420     * Requires {@link #FEATURE_CONTENT_TRANSITIONS}.
1421     *
1422     * @param tm The TransitionManager to use for scene changes.
1423     */
1424    public void setTransitionManager(TransitionManager tm) {
1425        throw new UnsupportedOperationException();
1426    }
1427
1428    /**
1429     * Retrieve the {@link Scene} representing this window's current content.
1430     * Requires {@link #FEATURE_CONTENT_TRANSITIONS}.
1431     *
1432     * <p>This method will return null if the current content is not represented by a Scene.</p>
1433     *
1434     * @return Current Scene being shown or null
1435     */
1436    public Scene getContentScene() {
1437        return null;
1438    }
1439
1440    /**
1441     * Sets the Transition that will be used to move Views into the initial scene. The entering
1442     * Views will be those that are regular Views or ViewGroups that have
1443     * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
1444     * {@link android.transition.Visibility} as entering is governed by changing visibility from
1445     * {@link View#INVISIBLE} to {@link View#VISIBLE}. If <code>transition</code> is null,
1446     * entering Views will remain unaffected.
1447     *
1448     * @param transition The Transition to use to move Views into the initial Scene.
1449     * @attr ref android.R.styleable#Window_windowEnterTransition
1450     */
1451    public void setEnterTransition(Transition transition) {}
1452
1453    /**
1454     * Sets the Transition that will be used to move Views out of the scene when the Window is
1455     * preparing to close, for example after a call to
1456     * {@link android.app.Activity#finishAfterTransition()}. The exiting
1457     * Views will be those that are regular Views or ViewGroups that have
1458     * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
1459     * {@link android.transition.Visibility} as entering is governed by changing visibility from
1460     * {@link View#VISIBLE} to {@link View#INVISIBLE}. If <code>transition</code> is null,
1461     * entering Views will remain unaffected. If nothing is set, the default will be to
1462     * use the same value as set in {@link #setEnterTransition(android.transition.Transition)}.
1463     *
1464     * @param transition The Transition to use to move Views out of the Scene when the Window
1465     *                   is preparing to close.
1466     * @attr ref android.R.styleable#Window_windowReturnTransition
1467     */
1468    public void setReturnTransition(Transition transition) {}
1469
1470    /**
1471     * Sets the Transition that will be used to move Views out of the scene when starting a
1472     * new Activity. The exiting Views will be those that are regular Views or ViewGroups that
1473     * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
1474     * {@link android.transition.Visibility} as exiting is governed by changing visibility
1475     * from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, the views will
1476     * remain unaffected. Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1477     *
1478     * @param transition The Transition to use to move Views out of the scene when calling a
1479     *                   new Activity.
1480     * @attr ref android.R.styleable#Window_windowExitTransition
1481     */
1482    public void setExitTransition(Transition transition) {}
1483
1484    /**
1485     * Sets the Transition that will be used to move Views in to the scene when returning from
1486     * a previously-started Activity. The entering Views will be those that are regular Views
1487     * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions
1488     * will extend {@link android.transition.Visibility} as exiting is governed by changing
1489     * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null,
1490     * the views will remain unaffected. If nothing is set, the default will be to use the same
1491     * transition as {@link #setExitTransition(android.transition.Transition)}.
1492     * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1493     *
1494     * @param transition The Transition to use to move Views into the scene when reentering from a
1495     *                   previously-started Activity.
1496     * @attr ref android.R.styleable#Window_windowReenterTransition
1497     */
1498    public void setReenterTransition(Transition transition) {}
1499
1500    /**
1501     * Returns the transition used to move Views into the initial scene. The entering
1502     * Views will be those that are regular Views or ViewGroups that have
1503     * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
1504     * {@link android.transition.Visibility} as entering is governed by changing visibility from
1505     * {@link View#INVISIBLE} to {@link View#VISIBLE}. If <code>transition</code> is null,
1506     * entering Views will remain unaffected.  Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1507     *
1508     * @return the Transition to use to move Views into the initial Scene.
1509     * @attr ref android.R.styleable#Window_windowEnterTransition
1510     */
1511    public Transition getEnterTransition() { return null; }
1512
1513    /**
1514     * Returns he Transition that will be used to move Views out of the scene when the Window is
1515     * preparing to close, for example after a call to
1516     * {@link android.app.Activity#finishAfterTransition()}. The exiting
1517     * Views will be those that are regular Views or ViewGroups that have
1518     * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
1519     * {@link android.transition.Visibility} as entering is governed by changing visibility from
1520     * {@link View#VISIBLE} to {@link View#INVISIBLE}.
1521     *
1522     * @return The Transition to use to move Views out of the Scene when the Window
1523     *         is preparing to close.
1524     * @attr ref android.R.styleable#Window_windowReturnTransition
1525     */
1526    public Transition getReturnTransition() { return null; }
1527
1528    /**
1529     * Returns the Transition that will be used to move Views out of the scene when starting a
1530     * new Activity. The exiting Views will be those that are regular Views or ViewGroups that
1531     * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
1532     * {@link android.transition.Visibility} as exiting is governed by changing visibility
1533     * from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, the views will
1534     * remain unaffected. Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1535     *
1536     * @return the Transition to use to move Views out of the scene when calling a
1537     * new Activity.
1538     * @attr ref android.R.styleable#Window_windowExitTransition
1539     */
1540    public Transition getExitTransition() { return null; }
1541
1542    /**
1543     * Returns the Transition that will be used to move Views in to the scene when returning from
1544     * a previously-started Activity. The entering Views will be those that are regular Views
1545     * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions
1546     * will extend {@link android.transition.Visibility} as exiting is governed by changing
1547     * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}.
1548     * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1549     *
1550     * @return The Transition to use to move Views into the scene when reentering from a
1551     *         previously-started Activity.
1552     * @attr ref android.R.styleable#Window_windowReenterTransition
1553     */
1554    public Transition getReenterTransition() { return null; }
1555
1556    /**
1557     * Sets the Transition that will be used for shared elements transferred into the content
1558     * Scene. Typical Transitions will affect size and location, such as
1559     * {@link android.transition.ChangeBounds}. A null
1560     * value will cause transferred shared elements to blink to the final position.
1561     * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1562     *
1563     * @param transition The Transition to use for shared elements transferred into the content
1564     *                   Scene.
1565     * @attr ref android.R.styleable#Window_windowSharedElementEnterTransition
1566     */
1567    public void setSharedElementEnterTransition(Transition transition) {}
1568
1569    /**
1570     * Sets the Transition that will be used for shared elements transferred back to a
1571     * calling Activity. Typical Transitions will affect size and location, such as
1572     * {@link android.transition.ChangeBounds}. A null
1573     * value will cause transferred shared elements to blink to the final position.
1574     * If no value is set, the default will be to use the same value as
1575     * {@link #setSharedElementEnterTransition(android.transition.Transition)}.
1576     * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1577     *
1578     * @param transition The Transition to use for shared elements transferred out of the content
1579     *                   Scene.
1580     * @attr ref android.R.styleable#Window_windowSharedElementReturnTransition
1581     */
1582    public void setSharedElementReturnTransition(Transition transition) {}
1583
1584    /**
1585     * Returns the Transition that will be used for shared elements transferred into the content
1586     * Scene. Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1587     *
1588     * @return Transition to use for sharend elements transferred into the content Scene.
1589     * @attr ref android.R.styleable#Window_windowSharedElementEnterTransition
1590     */
1591    public Transition getSharedElementEnterTransition() { return null; }
1592
1593    /**
1594     * Returns the Transition that will be used for shared elements transferred back to a
1595     * calling Activity. Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1596     *
1597     * @return Transition to use for sharend elements transferred into the content Scene.
1598     * @attr ref android.R.styleable#Window_windowSharedElementReturnTransition
1599     */
1600    public Transition getSharedElementReturnTransition() { return null; }
1601
1602    /**
1603     * Sets the Transition that will be used for shared elements after starting a new Activity
1604     * before the shared elements are transferred to the called Activity. If the shared elements
1605     * must animate during the exit transition, this Transition should be used. Upon completion,
1606     * the shared elements may be transferred to the started Activity.
1607     * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1608     *
1609     * @param transition The Transition to use for shared elements in the launching Window
1610     *                   prior to transferring to the launched Activity's Window.
1611     * @attr ref android.R.styleable#Window_windowSharedElementExitTransition
1612     */
1613    public void setSharedElementExitTransition(Transition transition) {}
1614
1615    /**
1616     * Sets the Transition that will be used for shared elements reentering from a started
1617     * Activity after it has returned the shared element to it start location. If no value
1618     * is set, this will default to
1619     * {@link #setSharedElementExitTransition(android.transition.Transition)}.
1620     * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1621     *
1622     * @param transition The Transition to use for shared elements in the launching Window
1623     *                   after the shared element has returned to the Window.
1624     * @attr ref android.R.styleable#Window_windowSharedElementReenterTransition
1625     */
1626    public void setSharedElementReenterTransition(Transition transition) {}
1627
1628    /**
1629     * Returns the Transition to use for shared elements in the launching Window prior
1630     * to transferring to the launched Activity's Window.
1631     * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1632     *
1633     * @return the Transition to use for shared elements in the launching Window prior
1634     * to transferring to the launched Activity's Window.
1635     * @attr ref android.R.styleable#Window_windowSharedElementExitTransition
1636     */
1637    public Transition getSharedElementExitTransition() { return null; }
1638
1639    /**
1640     * Returns the Transition that will be used for shared elements reentering from a started
1641     * Activity after it has returned the shared element to it start location.
1642     * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1643     *
1644     * @return the Transition that will be used for shared elements reentering from a started
1645     * Activity after it has returned the shared element to it start location.
1646     * @attr ref android.R.styleable#Window_windowSharedElementReenterTransition
1647     */
1648    public Transition getSharedElementReenterTransition() { return null; }
1649
1650    /**
1651     * Controls how the transition set in
1652     * {@link #setEnterTransition(android.transition.Transition)} overlaps with the exit
1653     * transition of the calling Activity. When true, the transition will start as soon as possible.
1654     * When false, the transition will wait until the remote exiting transition completes before
1655     * starting.
1656     *
1657     * @param allow true to start the enter transition when possible or false to
1658     *              wait until the exiting transition completes.
1659     * @attr ref android.R.styleable#Window_windowAllowEnterTransitionOverlap
1660     */
1661    public void setAllowEnterTransitionOverlap(boolean allow) {}
1662
1663    /**
1664     * Returns how the transition set in
1665     * {@link #setEnterTransition(android.transition.Transition)} overlaps with the exit
1666     * transition of the calling Activity. When true, the transition will start as soon as possible.
1667     * When false, the transition will wait until the remote exiting transition completes before
1668     * starting.
1669     *
1670     * @return true when the enter transition should start as soon as possible or false to
1671     * when it should wait until the exiting transition completes.
1672     * @attr ref android.R.styleable#Window_windowAllowEnterTransitionOverlap
1673     */
1674    public boolean getAllowEnterTransitionOverlap() { return true; }
1675
1676    /**
1677     * Controls how the transition set in
1678     * {@link #setExitTransition(android.transition.Transition)} overlaps with the exit
1679     * transition of the called Activity when reentering after if finishes. When true,
1680     * the transition will start as soon as possible. When false, the transition will wait
1681     * until the called Activity's exiting transition completes before starting.
1682     *
1683     * @param allow true to start the transition when possible or false to wait until the
1684     *              called Activity's exiting transition completes.
1685     * @attr ref android.R.styleable#Window_windowAllowReturnTransitionOverlap
1686     */
1687    public void setAllowReturnTransitionOverlap(boolean allow) {}
1688
1689    /**
1690     * TODO: remove this.
1691     * @hide
1692     */
1693    public void setAllowExitTransitionOverlap(boolean allow) {
1694        setAllowReturnTransitionOverlap(allow);
1695    }
1696
1697    /**
1698     * Returns how the transition set in
1699     * {@link #setExitTransition(android.transition.Transition)} overlaps with the exit
1700     * transition of the called Activity when reentering after if finishes. When true,
1701     * the transition will start as soon as possible. When false, the transition will wait
1702     * until the called Activity's exiting transition completes before starting.
1703     *
1704     * @return true when the transition should start when possible or false when it should wait
1705     * until the called Activity's exiting transition completes.
1706     * @attr ref android.R.styleable#Window_windowAllowReturnTransitionOverlap
1707     */
1708    public boolean getAllowReturnTransitionOverlap() { return true; }
1709
1710    /**
1711     * TODO: remove this.
1712     * @hide
1713     */
1714    public boolean getAllowExitTransitionOverlap() { return getAllowReturnTransitionOverlap(); }
1715
1716    /**
1717     * Returns the duration, in milliseconds, of the window background fade
1718     * when transitioning into or away from an Activity when called with an Activity Transition.
1719     * <p>When executing the enter transition, the background starts transparent
1720     * and fades in. This requires {@link #FEATURE_ACTIVITY_TRANSITIONS}. The default is
1721     * 300 milliseconds.</p>
1722     *
1723     * @return The duration of the window background fade to opaque during enter transition.
1724     * @see #getEnterTransition()
1725     * @attr ref android.R.styleable#Window_windowTransitionBackgroundFadeDuration
1726     */
1727    public long getTransitionBackgroundFadeDuration() { return 0; }
1728
1729    /**
1730     * Sets the duration, in milliseconds, of the window background fade
1731     * when transitioning into or away from an Activity when called with an Activity Transition.
1732     * <p>When executing the enter transition, the background starts transparent
1733     * and fades in. This requires {@link #FEATURE_ACTIVITY_TRANSITIONS}. The default is
1734     * 300 milliseconds.</p>
1735     *
1736     * @param fadeDurationMillis The duration of the window background fade to or from opaque
1737     *                           during enter transition.
1738     * @see #setEnterTransition(android.transition.Transition)
1739     * @attr ref android.R.styleable#Window_windowTransitionBackgroundFadeDuration
1740     */
1741    public void setTransitionBackgroundFadeDuration(long fadeDurationMillis) { }
1742
1743    /**
1744     * Returns <code>true</code> when shared elements should use an Overlay during
1745     * shared element transitions or <code>false</code> when they should animate as
1746     * part of the normal View hierarchy. The default value is true.
1747     *
1748     * @return <code>true</code> when shared elements should use an Overlay during
1749     * shared element transitions or <code>false</code> when they should animate as
1750     * part of the normal View hierarchy.
1751     * @attr ref android.R.styleable#Window_windowSharedElementsUseOverlay
1752     */
1753    public boolean getSharedElementsUseOverlay() { return true; }
1754
1755    /**
1756     * Sets whether or not shared elements should use an Overlay during shared element transitions.
1757     * The default value is true.
1758     *
1759     * @param sharedElementsUseOverlay <code>true</code> indicates that shared elements should
1760     *                                 be transitioned with an Overlay or <code>false</code>
1761     *                                 to transition within the normal View hierarchy.
1762     * @attr ref android.R.styleable#Window_windowSharedElementsUseOverlay
1763     */
1764    public void setSharedElementsUseOverlay(boolean sharedElementsUseOverlay) { }
1765
1766    /**
1767     * @return the color of the status bar.
1768     */
1769    public abstract int getStatusBarColor();
1770
1771    /**
1772     * Sets the color of the status bar to {@param color}.
1773     *
1774     * For this to take effect,
1775     * the window must be drawing the system bar backgrounds with
1776     * {@link android.view.WindowManager.LayoutParams#FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS} and
1777     * {@link android.view.WindowManager.LayoutParams#FLAG_TRANSLUCENT_STATUS} must not be set.
1778     *
1779     * If {@param color} is not opaque, consider setting
1780     * {@link android.view.View#SYSTEM_UI_FLAG_LAYOUT_STABLE} and
1781     * {@link android.view.View#SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}.
1782     * <p>
1783     * The transitionName for the view background will be "android:status:background".
1784     * </p>
1785     */
1786    public abstract void setStatusBarColor(int color);
1787
1788    /**
1789     * @return the color of the navigation bar.
1790     */
1791    public abstract int getNavigationBarColor();
1792
1793    /**
1794     * Sets the color of the navigation bar to {@param color}.
1795     *
1796     * For this to take effect,
1797     * the window must be drawing the system bar backgrounds with
1798     * {@link android.view.WindowManager.LayoutParams#FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS} and
1799     * {@link android.view.WindowManager.LayoutParams#FLAG_TRANSLUCENT_NAVIGATION} must not be set.
1800     *
1801     * If {@param color} is not opaque, consider setting
1802     * {@link android.view.View#SYSTEM_UI_FLAG_LAYOUT_STABLE} and
1803     * {@link android.view.View#SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION}.
1804     * <p>
1805     * The transitionName for the view background will be "android:navigation:background".
1806     * </p>
1807     */
1808    public abstract void setNavigationBarColor(int color);
1809
1810
1811}
1812