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