Home | History | Annotate | Download | only in view
      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 
     17 package android.view;
     18 
     19 import static android.view.WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
     20 
     21 import android.annotation.ColorInt;
     22 import android.annotation.DrawableRes;
     23 import android.annotation.IdRes;
     24 import android.annotation.LayoutRes;
     25 import android.annotation.NonNull;
     26 import android.annotation.Nullable;
     27 import android.annotation.StyleRes;
     28 import android.annotation.SystemApi;
     29 import android.content.Context;
     30 import android.content.pm.ActivityInfo;
     31 import android.content.res.Configuration;
     32 import android.content.res.Resources;
     33 import android.content.res.TypedArray;
     34 import android.graphics.PixelFormat;
     35 import android.graphics.Rect;
     36 import android.graphics.drawable.Drawable;
     37 import android.media.session.MediaController;
     38 import android.net.Uri;
     39 import android.os.Bundle;
     40 import android.os.Handler;
     41 import android.os.IBinder;
     42 import android.os.RemoteException;
     43 import android.os.SystemProperties;
     44 import android.transition.Scene;
     45 import android.transition.Transition;
     46 import android.transition.TransitionManager;
     47 import android.view.accessibility.AccessibilityEvent;
     48 
     49 import java.util.List;
     50 
     51 /**
     52  * Abstract base class for a top-level window look and behavior policy.  An
     53  * instance of this class should be used as the top-level view added to the
     54  * window manager. It provides standard UI policies such as a background, title
     55  * area, default key processing, etc.
     56  *
     57  * <p>The only existing implementation of this abstract class is
     58  * android.view.PhoneWindow, which you should instantiate when needing a
     59  * Window.
     60  */
     61 public abstract class Window {
     62     /** Flag for the "options panel" feature.  This is enabled by default. */
     63     public static final int FEATURE_OPTIONS_PANEL = 0;
     64     /** Flag for the "no title" feature, turning off the title at the top
     65      *  of the screen. */
     66     public static final int FEATURE_NO_TITLE = 1;
     67 
     68     /**
     69      * Flag for the progress indicator feature.
     70      *
     71      * @deprecated No longer supported starting in API 21.
     72      */
     73     @Deprecated
     74     public static final int FEATURE_PROGRESS = 2;
     75 
     76     /** Flag for having an icon on the left side of the title bar */
     77     public static final int FEATURE_LEFT_ICON = 3;
     78     /** Flag for having an icon on the right side of the title bar */
     79     public static final int FEATURE_RIGHT_ICON = 4;
     80 
     81     /**
     82      * Flag for indeterminate progress.
     83      *
     84      * @deprecated No longer supported starting in API 21.
     85      */
     86     @Deprecated
     87     public static final int FEATURE_INDETERMINATE_PROGRESS = 5;
     88 
     89     /** Flag for the context menu.  This is enabled by default. */
     90     public static final int FEATURE_CONTEXT_MENU = 6;
     91     /** Flag for custom title. You cannot combine this feature with other title features. */
     92     public static final int FEATURE_CUSTOM_TITLE = 7;
     93     /**
     94      * Flag for enabling the Action Bar.
     95      * This is enabled by default for some devices. The Action Bar
     96      * replaces the title bar and provides an alternate location
     97      * for an on-screen menu button on some devices.
     98      */
     99     public static final int FEATURE_ACTION_BAR = 8;
    100     /**
    101      * Flag for requesting an Action Bar that overlays window content.
    102      * Normally an Action Bar will sit in the space above window content, but if this
    103      * feature is requested along with {@link #FEATURE_ACTION_BAR} it will be layered over
    104      * the window content itself. This is useful if you would like your app to have more control
    105      * over how the Action Bar is displayed, such as letting application content scroll beneath
    106      * an Action Bar with a transparent background or otherwise displaying a transparent/translucent
    107      * Action Bar over application content.
    108      *
    109      * <p>This mode is especially useful with {@link View#SYSTEM_UI_FLAG_FULLSCREEN
    110      * View.SYSTEM_UI_FLAG_FULLSCREEN}, which allows you to seamlessly hide the
    111      * action bar in conjunction with other screen decorations.
    112      *
    113      * <p>As of {@link android.os.Build.VERSION_CODES#JELLY_BEAN}, when an
    114      * ActionBar is in this mode it will adjust the insets provided to
    115      * {@link View#fitSystemWindows(android.graphics.Rect) View.fitSystemWindows(Rect)}
    116      * to include the content covered by the action bar, so you can do layout within
    117      * that space.
    118      */
    119     public static final int FEATURE_ACTION_BAR_OVERLAY = 9;
    120     /**
    121      * Flag for specifying the behavior of action modes when an Action Bar is not present.
    122      * If overlay is enabled, the action mode UI will be allowed to cover existing window content.
    123      */
    124     public static final int FEATURE_ACTION_MODE_OVERLAY = 10;
    125     /**
    126      * Flag for requesting a decoration-free window that is dismissed by swiping from the left.
    127      */
    128     public static final int FEATURE_SWIPE_TO_DISMISS = 11;
    129     /**
    130      * Flag for requesting that window content changes should be animated using a
    131      * TransitionManager.
    132      *
    133      * <p>The TransitionManager is set using
    134      * {@link #setTransitionManager(android.transition.TransitionManager)}. If none is set,
    135      * a default TransitionManager will be used.</p>
    136      *
    137      * @see #setContentView
    138      */
    139     public static final int FEATURE_CONTENT_TRANSITIONS = 12;
    140 
    141     /**
    142      * Enables Activities to run Activity Transitions either through sending or receiving
    143      * ActivityOptions bundle created with
    144      * {@link android.app.ActivityOptions#makeSceneTransitionAnimation(android.app.Activity,
    145      * android.util.Pair[])} or {@link android.app.ActivityOptions#makeSceneTransitionAnimation(
    146      * android.app.Activity, View, String)}.
    147      */
    148     public static final int FEATURE_ACTIVITY_TRANSITIONS = 13;
    149 
    150     /**
    151      * Max value used as a feature ID
    152      * @hide
    153      */
    154     public static final int FEATURE_MAX = FEATURE_ACTIVITY_TRANSITIONS;
    155 
    156     /**
    157      * Flag for setting the progress bar's visibility to VISIBLE.
    158      *
    159      * @deprecated {@link #FEATURE_PROGRESS} and related methods are no longer
    160      *             supported starting in API 21.
    161      */
    162     @Deprecated
    163     public static final int PROGRESS_VISIBILITY_ON = -1;
    164 
    165     /**
    166      * Flag for setting the progress bar's visibility to GONE.
    167      *
    168      * @deprecated {@link #FEATURE_PROGRESS} and related methods are no longer
    169      *             supported starting in API 21.
    170      */
    171     @Deprecated
    172     public static final int PROGRESS_VISIBILITY_OFF = -2;
    173 
    174     /**
    175      * Flag for setting the progress bar's indeterminate mode on.
    176      *
    177      * @deprecated {@link #FEATURE_INDETERMINATE_PROGRESS} and related methods
    178      *             are no longer supported starting in API 21.
    179      */
    180     @Deprecated
    181     public static final int PROGRESS_INDETERMINATE_ON = -3;
    182 
    183     /**
    184      * Flag for setting the progress bar's indeterminate mode off.
    185      *
    186      * @deprecated {@link #FEATURE_INDETERMINATE_PROGRESS} and related methods
    187      *             are no longer supported starting in API 21.
    188      */
    189     @Deprecated
    190     public static final int PROGRESS_INDETERMINATE_OFF = -4;
    191 
    192     /**
    193      * Starting value for the (primary) progress.
    194      *
    195      * @deprecated {@link #FEATURE_PROGRESS} and related methods are no longer
    196      *             supported starting in API 21.
    197      */
    198     @Deprecated
    199     public static final int PROGRESS_START = 0;
    200 
    201     /**
    202      * Ending value for the (primary) progress.
    203      *
    204      * @deprecated {@link #FEATURE_PROGRESS} and related methods are no longer
    205      *             supported starting in API 21.
    206      */
    207     @Deprecated
    208     public static final int PROGRESS_END = 10000;
    209 
    210     /**
    211      * Lowest possible value for the secondary progress.
    212      *
    213      * @deprecated {@link #FEATURE_PROGRESS} and related methods are no longer
    214      *             supported starting in API 21.
    215      */
    216     @Deprecated
    217     public static final int PROGRESS_SECONDARY_START = 20000;
    218 
    219     /**
    220      * Highest possible value for the secondary progress.
    221      *
    222      * @deprecated {@link #FEATURE_PROGRESS} and related methods are no longer
    223      *             supported starting in API 21.
    224      */
    225     @Deprecated
    226     public static final int PROGRESS_SECONDARY_END = 30000;
    227 
    228     /**
    229      * The transitionName for the status bar background View when a custom background is used.
    230      * @see android.view.Window#setStatusBarColor(int)
    231      */
    232     public static final String STATUS_BAR_BACKGROUND_TRANSITION_NAME = "android:status:background";
    233 
    234     /**
    235      * The transitionName for the navigation bar background View when a custom background is used.
    236      * @see android.view.Window#setNavigationBarColor(int)
    237      */
    238     public static final String NAVIGATION_BAR_BACKGROUND_TRANSITION_NAME =
    239             "android:navigation:background";
    240 
    241     /**
    242      * The default features enabled.
    243      * @deprecated use {@link #getDefaultFeatures(android.content.Context)} instead.
    244      */
    245     @Deprecated
    246     @SuppressWarnings({"PointlessBitwiseExpression"})
    247     protected static final int DEFAULT_FEATURES = (1 << FEATURE_OPTIONS_PANEL) |
    248             (1 << FEATURE_CONTEXT_MENU);
    249 
    250     /**
    251      * The ID that the main layout in the XML layout file should have.
    252      */
    253     public static final int ID_ANDROID_CONTENT = com.android.internal.R.id.content;
    254 
    255     private static final String PROPERTY_HARDWARE_UI = "persist.sys.ui.hw";
    256 
    257     /**
    258      * Flag for letting the theme drive the color of the window caption controls. Use with
    259      * {@link #setDecorCaptionShade(int)}. This is the default value.
    260      */
    261     public static final int DECOR_CAPTION_SHADE_AUTO = 0;
    262     /**
    263      * Flag for setting light-color controls on the window caption. Use with
    264      * {@link #setDecorCaptionShade(int)}.
    265      */
    266     public static final int DECOR_CAPTION_SHADE_LIGHT = 1;
    267     /**
    268      * Flag for setting dark-color controls on the window caption. Use with
    269      * {@link #setDecorCaptionShade(int)}.
    270      */
    271     public static final int DECOR_CAPTION_SHADE_DARK = 2;
    272 
    273     private final Context mContext;
    274 
    275     private TypedArray mWindowStyle;
    276     private Callback mCallback;
    277     private OnWindowDismissedCallback mOnWindowDismissedCallback;
    278     private OnWindowSwipeDismissedCallback mOnWindowSwipeDismissedCallback;
    279     private WindowControllerCallback mWindowControllerCallback;
    280     private OnRestrictedCaptionAreaChangedListener mOnRestrictedCaptionAreaChangedListener;
    281     private Rect mRestrictedCaptionAreaRect;
    282     private WindowManager mWindowManager;
    283     private IBinder mAppToken;
    284     private String mAppName;
    285     private boolean mHardwareAccelerated;
    286     private Window mContainer;
    287     private Window mActiveChild;
    288     private boolean mIsActive = false;
    289     private boolean mHasChildren = false;
    290     private boolean mCloseOnTouchOutside = false;
    291     private boolean mSetCloseOnTouchOutside = false;
    292     private int mForcedWindowFlags = 0;
    293 
    294     private int mFeatures;
    295     private int mLocalFeatures;
    296 
    297     private boolean mHaveWindowFormat = false;
    298     private boolean mHaveDimAmount = false;
    299     private int mDefaultWindowFormat = PixelFormat.OPAQUE;
    300 
    301     private boolean mHasSoftInputMode = false;
    302 
    303     private boolean mDestroyed;
    304 
    305     private boolean mOverlayWithDecorCaptionEnabled = false;
    306     private boolean mCloseOnSwipeEnabled = false;
    307 
    308     // The current window attributes.
    309     private final WindowManager.LayoutParams mWindowAttributes =
    310         new WindowManager.LayoutParams();
    311 
    312     /**
    313      * API from a Window back to its caller.  This allows the client to
    314      * intercept key dispatching, panels and menus, etc.
    315      */
    316     public interface Callback {
    317         /**
    318          * Called to process key events.  At the very least your
    319          * implementation must call
    320          * {@link android.view.Window#superDispatchKeyEvent} to do the
    321          * standard key processing.
    322          *
    323          * @param event The key event.
    324          *
    325          * @return boolean Return true if this event was consumed.
    326          */
    327         public boolean dispatchKeyEvent(KeyEvent event);
    328 
    329         /**
    330          * Called to process a key shortcut event.
    331          * At the very least your implementation must call
    332          * {@link android.view.Window#superDispatchKeyShortcutEvent} to do the
    333          * standard key shortcut processing.
    334          *
    335          * @param event The key shortcut event.
    336          * @return True if this event was consumed.
    337          */
    338         public boolean dispatchKeyShortcutEvent(KeyEvent event);
    339 
    340         /**
    341          * Called to process touch screen events.  At the very least your
    342          * implementation must call
    343          * {@link android.view.Window#superDispatchTouchEvent} to do the
    344          * standard touch screen processing.
    345          *
    346          * @param event The touch screen event.
    347          *
    348          * @return boolean Return true if this event was consumed.
    349          */
    350         public boolean dispatchTouchEvent(MotionEvent event);
    351 
    352         /**
    353          * Called to process trackball events.  At the very least your
    354          * implementation must call
    355          * {@link android.view.Window#superDispatchTrackballEvent} to do the
    356          * standard trackball processing.
    357          *
    358          * @param event The trackball event.
    359          *
    360          * @return boolean Return true if this event was consumed.
    361          */
    362         public boolean dispatchTrackballEvent(MotionEvent event);
    363 
    364         /**
    365          * Called to process generic motion events.  At the very least your
    366          * implementation must call
    367          * {@link android.view.Window#superDispatchGenericMotionEvent} to do the
    368          * standard processing.
    369          *
    370          * @param event The generic motion event.
    371          *
    372          * @return boolean Return true if this event was consumed.
    373          */
    374         public boolean dispatchGenericMotionEvent(MotionEvent event);
    375 
    376         /**
    377          * Called to process population of {@link AccessibilityEvent}s.
    378          *
    379          * @param event The event.
    380          *
    381          * @return boolean Return true if event population was completed.
    382          */
    383         public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event);
    384 
    385         /**
    386          * Instantiate the view to display in the panel for 'featureId'.
    387          * You can return null, in which case the default content (typically
    388          * a menu) will be created for you.
    389          *
    390          * @param featureId Which panel is being created.
    391          *
    392          * @return view The top-level view to place in the panel.
    393          *
    394          * @see #onPreparePanel
    395          */
    396         @Nullable
    397         public View onCreatePanelView(int featureId);
    398 
    399         /**
    400          * Initialize the contents of the menu for panel 'featureId'.  This is
    401          * called if onCreatePanelView() returns null, giving you a standard
    402          * menu in which you can place your items.  It is only called once for
    403          * the panel, the first time it is shown.
    404          *
    405          * <p>You can safely hold on to <var>menu</var> (and any items created
    406          * from it), making modifications to it as desired, until the next
    407          * time onCreatePanelMenu() is called for this feature.
    408          *
    409          * @param featureId The panel being created.
    410          * @param menu The menu inside the panel.
    411          *
    412          * @return boolean You must return true for the panel to be displayed;
    413          *         if you return false it will not be shown.
    414          */
    415         public boolean onCreatePanelMenu(int featureId, Menu menu);
    416 
    417         /**
    418          * Prepare a panel to be displayed.  This is called right before the
    419          * panel window is shown, every time it is shown.
    420          *
    421          * @param featureId The panel that is being displayed.
    422          * @param view The View that was returned by onCreatePanelView().
    423          * @param menu If onCreatePanelView() returned null, this is the Menu
    424          *             being displayed in the panel.
    425          *
    426          * @return boolean You must return true for the panel to be displayed;
    427          *         if you return false it will not be shown.
    428          *
    429          * @see #onCreatePanelView
    430          */
    431         public boolean onPreparePanel(int featureId, View view, Menu menu);
    432 
    433         /**
    434          * Called when a panel's menu is opened by the user. This may also be
    435          * called when the menu is changing from one type to another (for
    436          * example, from the icon menu to the expanded menu).
    437          *
    438          * @param featureId The panel that the menu is in.
    439          * @param menu The menu that is opened.
    440          * @return Return true to allow the menu to open, or false to prevent
    441          *         the menu from opening.
    442          */
    443         public boolean onMenuOpened(int featureId, Menu menu);
    444 
    445         /**
    446          * Called when a panel's menu item has been selected by the user.
    447          *
    448          * @param featureId The panel that the menu is in.
    449          * @param item The menu item that was selected.
    450          *
    451          * @return boolean Return true to finish processing of selection, or
    452          *         false to perform the normal menu handling (calling its
    453          *         Runnable or sending a Message to its target Handler).
    454          */
    455         public boolean onMenuItemSelected(int featureId, MenuItem item);
    456 
    457         /**
    458          * This is called whenever the current window attributes change.
    459          *
    460          */
    461         public void onWindowAttributesChanged(WindowManager.LayoutParams attrs);
    462 
    463         /**
    464          * This hook is called whenever the content view of the screen changes
    465          * (due to a call to
    466          * {@link Window#setContentView(View, android.view.ViewGroup.LayoutParams)
    467          * Window.setContentView} or
    468          * {@link Window#addContentView(View, android.view.ViewGroup.LayoutParams)
    469          * Window.addContentView}).
    470          */
    471         public void onContentChanged();
    472 
    473         /**
    474          * This hook is called whenever the window focus changes.  See
    475          * {@link View#onWindowFocusChanged(boolean)
    476          * View.onWindowFocusChangedNotLocked(boolean)} for more information.
    477          *
    478          * @param hasFocus Whether the window now has focus.
    479          */
    480         public void onWindowFocusChanged(boolean hasFocus);
    481 
    482         /**
    483          * Called when the window has been attached to the window manager.
    484          * See {@link View#onAttachedToWindow() View.onAttachedToWindow()}
    485          * for more information.
    486          */
    487         public void onAttachedToWindow();
    488 
    489         /**
    490          * Called when the window has been attached to the window manager.
    491          * See {@link View#onDetachedFromWindow() View.onDetachedFromWindow()}
    492          * for more information.
    493          */
    494         public void onDetachedFromWindow();
    495 
    496         /**
    497          * Called when a panel is being closed.  If another logical subsequent
    498          * panel is being opened (and this panel is being closed to make room for the subsequent
    499          * panel), this method will NOT be called.
    500          *
    501          * @param featureId The panel that is being displayed.
    502          * @param menu If onCreatePanelView() returned null, this is the Menu
    503          *            being displayed in the panel.
    504          */
    505         public void onPanelClosed(int featureId, Menu menu);
    506 
    507         /**
    508          * Called when the user signals the desire to start a search.
    509          *
    510          * @return true if search launched, false if activity refuses (blocks)
    511          *
    512          * @see android.app.Activity#onSearchRequested()
    513          */
    514         public boolean onSearchRequested();
    515 
    516         /**
    517          * Called when the user signals the desire to start a search.
    518          *
    519          * @param searchEvent A {@link SearchEvent} describing the signal to
    520          *                   start a search.
    521          * @return true if search launched, false if activity refuses (blocks)
    522          */
    523         public boolean onSearchRequested(SearchEvent searchEvent);
    524 
    525         /**
    526          * Called when an action mode is being started for this window. Gives the
    527          * callback an opportunity to handle the action mode in its own unique and
    528          * beautiful way. If this method returns null the system can choose a way
    529          * to present the mode or choose not to start the mode at all. This is equivalent
    530          * to {@link #onWindowStartingActionMode(android.view.ActionMode.Callback, int)}
    531          * with type {@link ActionMode#TYPE_PRIMARY}.
    532          *
    533          * @param callback Callback to control the lifecycle of this action mode
    534          * @return The ActionMode that was started, or null if the system should present it
    535          */
    536         @Nullable
    537         public ActionMode onWindowStartingActionMode(ActionMode.Callback callback);
    538 
    539         /**
    540          * Called when an action mode is being started for this window. Gives the
    541          * callback an opportunity to handle the action mode in its own unique and
    542          * beautiful way. If this method returns null the system can choose a way
    543          * to present the mode or choose not to start the mode at all.
    544          *
    545          * @param callback Callback to control the lifecycle of this action mode
    546          * @param type One of {@link ActionMode#TYPE_PRIMARY} or {@link ActionMode#TYPE_FLOATING}.
    547          * @return The ActionMode that was started, or null if the system should present it
    548          */
    549         @Nullable
    550         public ActionMode onWindowStartingActionMode(ActionMode.Callback callback, int type);
    551 
    552         /**
    553          * Called when an action mode has been started. The appropriate mode callback
    554          * method will have already been invoked.
    555          *
    556          * @param mode The new mode that has just been started.
    557          */
    558         public void onActionModeStarted(ActionMode mode);
    559 
    560         /**
    561          * Called when an action mode has been finished. The appropriate mode callback
    562          * method will have already been invoked.
    563          *
    564          * @param mode The mode that was just finished.
    565          */
    566         public void onActionModeFinished(ActionMode mode);
    567 
    568         /**
    569          * Called when Keyboard Shortcuts are requested for the current window.
    570          *
    571          * @param data The data list to populate with shortcuts.
    572          * @param menu The current menu, which may be null.
    573          * @param deviceId The id for the connected device the shortcuts should be provided for.
    574          */
    575         default public void onProvideKeyboardShortcuts(
    576                 List<KeyboardShortcutGroup> data, @Nullable Menu menu, int deviceId) { };
    577 
    578         /**
    579          * Called when pointer capture is enabled or disabled for the current window.
    580          *
    581          * @param hasCapture True if the window has pointer capture.
    582          */
    583         default public void onPointerCaptureChanged(boolean hasCapture) { };
    584     }
    585 
    586     /** @hide */
    587     public interface OnWindowDismissedCallback {
    588         /**
    589          * Called when a window is dismissed. This informs the callback that the
    590          * window is gone, and it should finish itself.
    591          * @param finishTask True if the task should also be finished.
    592          * @param suppressWindowTransition True if the resulting exit and enter window transition
    593          * animations should be suppressed.
    594          */
    595         void onWindowDismissed(boolean finishTask, boolean suppressWindowTransition);
    596     }
    597 
    598     /** @hide */
    599     public interface OnWindowSwipeDismissedCallback {
    600         /**
    601          * Called when a window is swipe dismissed. This informs the callback that the
    602          * window is gone, and it should finish itself.
    603          * @param finishTask True if the task should also be finished.
    604          * @param suppressWindowTransition True if the resulting exit and enter window transition
    605          * animations should be suppressed.
    606          */
    607         void onWindowSwipeDismissed();
    608     }
    609 
    610     /** @hide */
    611     public interface WindowControllerCallback {
    612         /**
    613          * Moves the activity from
    614          * {@link android.app.ActivityManager.StackId#FREEFORM_WORKSPACE_STACK_ID} to
    615          * {@link android.app.ActivityManager.StackId#FULLSCREEN_WORKSPACE_STACK_ID} stack.
    616          */
    617         void exitFreeformMode() throws RemoteException;
    618 
    619         /**
    620          * Puts the activity in picture-in-picture mode if the activity supports.
    621          * @see android.R.attr#supportsPictureInPicture
    622          */
    623         void enterPictureInPictureModeIfPossible();
    624 
    625         /** Returns the current stack Id for the window. */
    626         int getWindowStackId() throws RemoteException;
    627 
    628         /** Returns whether the window belongs to the task root. */
    629         boolean isTaskRoot();
    630     }
    631 
    632     /**
    633      * Callback for clients that want to be aware of where caption draws content.
    634      */
    635     public interface OnRestrictedCaptionAreaChangedListener {
    636         /**
    637          * Called when the area where caption draws content changes.
    638          *
    639          * @param rect The area where caption content is positioned, relative to the top view.
    640          */
    641         void onRestrictedCaptionAreaChanged(Rect rect);
    642     }
    643 
    644     /**
    645      * Callback for clients that want frame timing information for each
    646      * frame rendered by the Window.
    647      */
    648     public interface OnFrameMetricsAvailableListener {
    649         /**
    650          * Called when information is available for the previously rendered frame.
    651          *
    652          * Reports can be dropped if this callback takes too
    653          * long to execute, as the report producer cannot wait for the consumer to
    654          * complete.
    655          *
    656          * It is highly recommended that clients copy the passed in FrameMetrics
    657          * via {@link FrameMetrics#FrameMetrics(FrameMetrics)} within this method and defer
    658          * additional computation or storage to another thread to avoid unnecessarily
    659          * dropping reports.
    660          *
    661          * @param window The {@link Window} on which the frame was displayed.
    662          * @param frameMetrics the available metrics. This object is reused on every call
    663          * and thus <strong>this reference is not valid outside the scope of this method</strong>.
    664          * @param dropCountSinceLastInvocation the number of reports dropped since the last time
    665          * this callback was invoked.
    666          */
    667         void onFrameMetricsAvailable(Window window, FrameMetrics frameMetrics,
    668                 int dropCountSinceLastInvocation);
    669     }
    670 
    671 
    672     public Window(Context context) {
    673         mContext = context;
    674         mFeatures = mLocalFeatures = getDefaultFeatures(context);
    675     }
    676 
    677     /**
    678      * Return the Context this window policy is running in, for retrieving
    679      * resources and other information.
    680      *
    681      * @return Context The Context that was supplied to the constructor.
    682      */
    683     public final Context getContext() {
    684         return mContext;
    685     }
    686 
    687     /**
    688      * Return the {@link android.R.styleable#Window} attributes from this
    689      * window's theme.
    690      */
    691     public final TypedArray getWindowStyle() {
    692         synchronized (this) {
    693             if (mWindowStyle == null) {
    694                 mWindowStyle = mContext.obtainStyledAttributes(
    695                         com.android.internal.R.styleable.Window);
    696             }
    697             return mWindowStyle;
    698         }
    699     }
    700 
    701     /**
    702      * Set the container for this window.  If not set, the DecorWindow
    703      * operates as a top-level window; otherwise, it negotiates with the
    704      * container to display itself appropriately.
    705      *
    706      * @param container The desired containing Window.
    707      */
    708     public void setContainer(Window container) {
    709         mContainer = container;
    710         if (container != null) {
    711             // Embedded screens never have a title.
    712             mFeatures |= 1<<FEATURE_NO_TITLE;
    713             mLocalFeatures |= 1<<FEATURE_NO_TITLE;
    714             container.mHasChildren = true;
    715         }
    716     }
    717 
    718     /**
    719      * Return the container for this Window.
    720      *
    721      * @return Window The containing window, or null if this is a
    722      *         top-level window.
    723      */
    724     public final Window getContainer() {
    725         return mContainer;
    726     }
    727 
    728     public final boolean hasChildren() {
    729         return mHasChildren;
    730     }
    731 
    732     /** @hide */
    733     public final void destroy() {
    734         mDestroyed = true;
    735     }
    736 
    737     /** @hide */
    738     public final boolean isDestroyed() {
    739         return mDestroyed;
    740     }
    741 
    742     /**
    743      * Set the window manager for use by this Window to, for example,
    744      * display panels.  This is <em>not</em> used for displaying the
    745      * Window itself -- that must be done by the client.
    746      *
    747      * @param wm The window manager for adding new windows.
    748      */
    749     public void setWindowManager(WindowManager wm, IBinder appToken, String appName) {
    750         setWindowManager(wm, appToken, appName, false);
    751     }
    752 
    753     /**
    754      * Set the window manager for use by this Window to, for example,
    755      * display panels.  This is <em>not</em> used for displaying the
    756      * Window itself -- that must be done by the client.
    757      *
    758      * @param wm The window manager for adding new windows.
    759      */
    760     public void setWindowManager(WindowManager wm, IBinder appToken, String appName,
    761             boolean hardwareAccelerated) {
    762         mAppToken = appToken;
    763         mAppName = appName;
    764         mHardwareAccelerated = hardwareAccelerated
    765                 || SystemProperties.getBoolean(PROPERTY_HARDWARE_UI, false);
    766         if (wm == null) {
    767             wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
    768         }
    769         mWindowManager = ((WindowManagerImpl)wm).createLocalWindowManager(this);
    770     }
    771 
    772     void adjustLayoutParamsForSubWindow(WindowManager.LayoutParams wp) {
    773         CharSequence curTitle = wp.getTitle();
    774         if (wp.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW &&
    775                 wp.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
    776             if (wp.token == null) {
    777                 View decor = peekDecorView();
    778                 if (decor != null) {
    779                     wp.token = decor.getWindowToken();
    780                 }
    781             }
    782             if (curTitle == null || curTitle.length() == 0) {
    783                 final StringBuilder title = new StringBuilder(32);
    784                 if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA) {
    785                     title.append("Media");
    786                 } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY) {
    787                     title.append("MediaOvr");
    788                 } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
    789                     title.append("Panel");
    790                 } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL) {
    791                     title.append("SubPanel");
    792                 } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_ABOVE_SUB_PANEL) {
    793                     title.append("AboveSubPanel");
    794                 } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG) {
    795                     title.append("AtchDlg");
    796                 } else {
    797                     title.append(wp.type);
    798                 }
    799                 if (mAppName != null) {
    800                     title.append(":").append(mAppName);
    801                 }
    802                 wp.setTitle(title);
    803             }
    804         } else if (wp.type >= WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW &&
    805                 wp.type <= WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) {
    806             // We don't set the app token to this system window because the life cycles should be
    807             // independent. If an app creates a system window and then the app goes to the stopped
    808             // state, the system window should not be affected (can still show and receive input
    809             // events).
    810             if (curTitle == null || curTitle.length() == 0) {
    811                 final StringBuilder title = new StringBuilder(32);
    812                 title.append("Sys").append(wp.type);
    813                 if (mAppName != null) {
    814                     title.append(":").append(mAppName);
    815                 }
    816                 wp.setTitle(title);
    817             }
    818         } else {
    819             if (wp.token == null) {
    820                 wp.token = mContainer == null ? mAppToken : mContainer.mAppToken;
    821             }
    822             if ((curTitle == null || curTitle.length() == 0)
    823                     && mAppName != null) {
    824                 wp.setTitle(mAppName);
    825             }
    826         }
    827         if (wp.packageName == null) {
    828             wp.packageName = mContext.getPackageName();
    829         }
    830         if (mHardwareAccelerated ||
    831                 (mWindowAttributes.flags & FLAG_HARDWARE_ACCELERATED) != 0) {
    832             wp.flags |= FLAG_HARDWARE_ACCELERATED;
    833         }
    834     }
    835 
    836     /**
    837      * Return the window manager allowing this Window to display its own
    838      * windows.
    839      *
    840      * @return WindowManager The ViewManager.
    841      */
    842     public WindowManager getWindowManager() {
    843         return mWindowManager;
    844     }
    845 
    846     /**
    847      * Set the Callback interface for this window, used to intercept key
    848      * events and other dynamic operations in the window.
    849      *
    850      * @param callback The desired Callback interface.
    851      */
    852     public void setCallback(Callback callback) {
    853         mCallback = callback;
    854     }
    855 
    856     /**
    857      * Return the current Callback interface for this window.
    858      */
    859     public final Callback getCallback() {
    860         return mCallback;
    861     }
    862 
    863     /**
    864      * Set an observer to collect frame stats for each frame rendererd in this window.
    865      *
    866      * Must be in hardware rendering mode.
    867      */
    868     public final void addOnFrameMetricsAvailableListener(
    869             @NonNull OnFrameMetricsAvailableListener listener,
    870             Handler handler) {
    871         final View decorView = getDecorView();
    872         if (decorView == null) {
    873             throw new IllegalStateException("can't observe a Window without an attached view");
    874         }
    875 
    876         if (listener == null) {
    877             throw new NullPointerException("listener cannot be null");
    878         }
    879 
    880         decorView.addFrameMetricsListener(this, listener, handler);
    881     }
    882 
    883     /**
    884      * Remove observer and stop listening to frame stats for this window.
    885      */
    886     public final void removeOnFrameMetricsAvailableListener(OnFrameMetricsAvailableListener listener) {
    887         final View decorView = getDecorView();
    888         if (decorView != null) {
    889             getDecorView().removeFrameMetricsListener(listener);
    890         }
    891     }
    892 
    893     /** @hide */
    894     public final void setOnWindowDismissedCallback(OnWindowDismissedCallback dcb) {
    895         mOnWindowDismissedCallback = dcb;
    896     }
    897 
    898     /** @hide */
    899     public final void dispatchOnWindowDismissed(
    900             boolean finishTask, boolean suppressWindowTransition) {
    901         if (mOnWindowDismissedCallback != null) {
    902             mOnWindowDismissedCallback.onWindowDismissed(finishTask, suppressWindowTransition);
    903         }
    904     }
    905 
    906     /** @hide */
    907     public final void setOnWindowSwipeDismissedCallback(OnWindowSwipeDismissedCallback sdcb) {
    908         mOnWindowSwipeDismissedCallback = sdcb;
    909     }
    910 
    911     /** @hide */
    912     public final void dispatchOnWindowSwipeDismissed() {
    913         if (mOnWindowSwipeDismissedCallback != null) {
    914             mOnWindowSwipeDismissedCallback.onWindowSwipeDismissed();
    915         }
    916     }
    917 
    918     /** @hide */
    919     public final void setWindowControllerCallback(WindowControllerCallback wccb) {
    920         mWindowControllerCallback = wccb;
    921     }
    922 
    923     /** @hide */
    924     public final WindowControllerCallback getWindowControllerCallback() {
    925         return mWindowControllerCallback;
    926     }
    927 
    928     /**
    929      * Set a callback for changes of area where caption will draw its content.
    930      *
    931      * @param listener Callback that will be called when the area changes.
    932      */
    933     public final void setRestrictedCaptionAreaListener(OnRestrictedCaptionAreaChangedListener listener) {
    934         mOnRestrictedCaptionAreaChangedListener = listener;
    935         mRestrictedCaptionAreaRect = listener != null ? new Rect() : null;
    936     }
    937 
    938     /**
    939      * Take ownership of this window's surface.  The window's view hierarchy
    940      * will no longer draw into the surface, though it will otherwise continue
    941      * to operate (such as for receiving input events).  The given SurfaceHolder
    942      * callback will be used to tell you about state changes to the surface.
    943      */
    944     public abstract void takeSurface(SurfaceHolder.Callback2 callback);
    945 
    946     /**
    947      * Take ownership of this window's InputQueue.  The window will no
    948      * longer read and dispatch input events from the queue; it is your
    949      * responsibility to do so.
    950      */
    951     public abstract void takeInputQueue(InputQueue.Callback callback);
    952 
    953     /**
    954      * Return whether this window is being displayed with a floating style
    955      * (based on the {@link android.R.attr#windowIsFloating} attribute in
    956      * the style/theme).
    957      *
    958      * @return Returns true if the window is configured to be displayed floating
    959      * on top of whatever is behind it.
    960      */
    961     public abstract boolean isFloating();
    962 
    963     /**
    964      * Set the width and height layout parameters of the window.  The default
    965      * for both of these is MATCH_PARENT; you can change them to WRAP_CONTENT
    966      * or an absolute value to make a window that is not full-screen.
    967      *
    968      * @param width The desired layout width of the window.
    969      * @param height The desired layout height of the window.
    970      *
    971      * @see ViewGroup.LayoutParams#height
    972      * @see ViewGroup.LayoutParams#width
    973      */
    974     public void setLayout(int width, int height) {
    975         final WindowManager.LayoutParams attrs = getAttributes();
    976         attrs.width = width;
    977         attrs.height = height;
    978         dispatchWindowAttributesChanged(attrs);
    979     }
    980 
    981     /**
    982      * Set the gravity of the window, as per the Gravity constants.  This
    983      * controls how the window manager is positioned in the overall window; it
    984      * is only useful when using WRAP_CONTENT for the layout width or height.
    985      *
    986      * @param gravity The desired gravity constant.
    987      *
    988      * @see Gravity
    989      * @see #setLayout
    990      */
    991     public void setGravity(int gravity)
    992     {
    993         final WindowManager.LayoutParams attrs = getAttributes();
    994         attrs.gravity = gravity;
    995         dispatchWindowAttributesChanged(attrs);
    996     }
    997 
    998     /**
    999      * Set the type of the window, as per the WindowManager.LayoutParams
   1000      * types.
   1001      *
   1002      * @param type The new window type (see WindowManager.LayoutParams).
   1003      */
   1004     public void setType(int type) {
   1005         final WindowManager.LayoutParams attrs = getAttributes();
   1006         attrs.type = type;
   1007         dispatchWindowAttributesChanged(attrs);
   1008     }
   1009 
   1010     /**
   1011      * Set the format of window, as per the PixelFormat types.  This overrides
   1012      * the default format that is selected by the Window based on its
   1013      * window decorations.
   1014      *
   1015      * @param format The new window format (see PixelFormat).  Use
   1016      *               PixelFormat.UNKNOWN to allow the Window to select
   1017      *               the format.
   1018      *
   1019      * @see PixelFormat
   1020      */
   1021     public void setFormat(int format) {
   1022         final WindowManager.LayoutParams attrs = getAttributes();
   1023         if (format != PixelFormat.UNKNOWN) {
   1024             attrs.format = format;
   1025             mHaveWindowFormat = true;
   1026         } else {
   1027             attrs.format = mDefaultWindowFormat;
   1028             mHaveWindowFormat = false;
   1029         }
   1030         dispatchWindowAttributesChanged(attrs);
   1031     }
   1032 
   1033     /**
   1034      * Specify custom animations to use for the window, as per
   1035      * {@link WindowManager.LayoutParams#windowAnimations
   1036      * WindowManager.LayoutParams.windowAnimations}.  Providing anything besides
   1037      * 0 here will override the animations the window would
   1038      * normally retrieve from its theme.
   1039      */
   1040     public void setWindowAnimations(@StyleRes int resId) {
   1041         final WindowManager.LayoutParams attrs = getAttributes();
   1042         attrs.windowAnimations = resId;
   1043         dispatchWindowAttributesChanged(attrs);
   1044     }
   1045 
   1046     /**
   1047      * Specify an explicit soft input mode to use for the window, as per
   1048      * {@link WindowManager.LayoutParams#softInputMode
   1049      * WindowManager.LayoutParams.softInputMode}.  Providing anything besides
   1050      * "unspecified" here will override the input mode the window would
   1051      * normally retrieve from its theme.
   1052      */
   1053     public void setSoftInputMode(int mode) {
   1054         final WindowManager.LayoutParams attrs = getAttributes();
   1055         if (mode != WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED) {
   1056             attrs.softInputMode = mode;
   1057             mHasSoftInputMode = true;
   1058         } else {
   1059             mHasSoftInputMode = false;
   1060         }
   1061         dispatchWindowAttributesChanged(attrs);
   1062     }
   1063 
   1064     /**
   1065      * Convenience function to set the flag bits as specified in flags, as
   1066      * per {@link #setFlags}.
   1067      * @param flags The flag bits to be set.
   1068      * @see #setFlags
   1069      * @see #clearFlags
   1070      */
   1071     public void addFlags(int flags) {
   1072         setFlags(flags, flags);
   1073     }
   1074 
   1075     /** @hide */
   1076     public void addPrivateFlags(int flags) {
   1077         setPrivateFlags(flags, flags);
   1078     }
   1079 
   1080     /**
   1081      * Convenience function to clear the flag bits as specified in flags, as
   1082      * per {@link #setFlags}.
   1083      * @param flags The flag bits to be cleared.
   1084      * @see #setFlags
   1085      * @see #addFlags
   1086      */
   1087     public void clearFlags(int flags) {
   1088         setFlags(0, flags);
   1089     }
   1090 
   1091     /**
   1092      * Set the flags of the window, as per the
   1093      * {@link WindowManager.LayoutParams WindowManager.LayoutParams}
   1094      * flags.
   1095      *
   1096      * <p>Note that some flags must be set before the window decoration is
   1097      * created (by the first call to
   1098      * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)} or
   1099      * {@link #getDecorView()}:
   1100      * {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN} and
   1101      * {@link WindowManager.LayoutParams#FLAG_LAYOUT_INSET_DECOR}.  These
   1102      * will be set for you based on the {@link android.R.attr#windowIsFloating}
   1103      * attribute.
   1104      *
   1105      * @param flags The new window flags (see WindowManager.LayoutParams).
   1106      * @param mask Which of the window flag bits to modify.
   1107      * @see #addFlags
   1108      * @see #clearFlags
   1109      */
   1110     public void setFlags(int flags, int mask) {
   1111         final WindowManager.LayoutParams attrs = getAttributes();
   1112         attrs.flags = (attrs.flags&~mask) | (flags&mask);
   1113         mForcedWindowFlags |= mask;
   1114         dispatchWindowAttributesChanged(attrs);
   1115     }
   1116 
   1117     private void setPrivateFlags(int flags, int mask) {
   1118         final WindowManager.LayoutParams attrs = getAttributes();
   1119         attrs.privateFlags = (attrs.privateFlags & ~mask) | (flags & mask);
   1120         dispatchWindowAttributesChanged(attrs);
   1121     }
   1122 
   1123     /**
   1124      * {@hide}
   1125      */
   1126     protected void setNeedsMenuKey(int value) {
   1127         final WindowManager.LayoutParams attrs = getAttributes();
   1128         attrs.needsMenuKey = value;
   1129         dispatchWindowAttributesChanged(attrs);
   1130     }
   1131 
   1132     /**
   1133      * {@hide}
   1134      */
   1135     protected void dispatchWindowAttributesChanged(WindowManager.LayoutParams attrs) {
   1136         if (mCallback != null) {
   1137             mCallback.onWindowAttributesChanged(attrs);
   1138         }
   1139     }
   1140 
   1141     /**
   1142      * <p>Set the color mode of the window. Setting the color mode might
   1143      * override the window's pixel {@link WindowManager.LayoutParams#format format}.</p>
   1144      *
   1145      * <p>The color mode must be one of {@link ActivityInfo#COLOR_MODE_DEFAULT},
   1146      * {@link ActivityInfo#COLOR_MODE_WIDE_COLOR_GAMUT} or {@link ActivityInfo#COLOR_MODE_HDR}.</p>
   1147      */
   1148     public void setColorMode(@ActivityInfo.ColorMode int colorMode) {
   1149         final WindowManager.LayoutParams attrs = getAttributes();
   1150         attrs.setColorMode(colorMode);
   1151         dispatchWindowAttributesChanged(attrs);
   1152     }
   1153 
   1154     /**
   1155      * Returns the color mode of the window, one of {@link ActivityInfo#COLOR_MODE_DEFAULT},
   1156      * {@link ActivityInfo#COLOR_MODE_WIDE_COLOR_GAMUT} or {@link ActivityInfo#COLOR_MODE_HDR}.
   1157      */
   1158     @ActivityInfo.ColorMode
   1159     public int getColorMode() {
   1160         return getAttributes().getColorMode();
   1161     }
   1162 
   1163     /**
   1164      * Set the amount of dim behind the window when using
   1165      * {@link WindowManager.LayoutParams#FLAG_DIM_BEHIND}.  This overrides
   1166      * the default dim amount of that is selected by the Window based on
   1167      * its theme.
   1168      *
   1169      * @param amount The new dim amount, from 0 for no dim to 1 for full dim.
   1170      */
   1171     public void setDimAmount(float amount) {
   1172         final WindowManager.LayoutParams attrs = getAttributes();
   1173         attrs.dimAmount = amount;
   1174         mHaveDimAmount = true;
   1175         dispatchWindowAttributesChanged(attrs);
   1176     }
   1177 
   1178     /**
   1179      * Specify custom window attributes.  <strong>PLEASE NOTE:</strong> the
   1180      * layout params you give here should generally be from values previously
   1181      * retrieved with {@link #getAttributes()}; you probably do not want to
   1182      * blindly create and apply your own, since this will blow away any values
   1183      * set by the framework that you are not interested in.
   1184      *
   1185      * @param a The new window attributes, which will completely override any
   1186      *          current values.
   1187      */
   1188     public void setAttributes(WindowManager.LayoutParams a) {
   1189         mWindowAttributes.copyFrom(a);
   1190         dispatchWindowAttributesChanged(mWindowAttributes);
   1191     }
   1192 
   1193     /**
   1194      * Retrieve the current window attributes associated with this panel.
   1195      *
   1196      * @return WindowManager.LayoutParams Either the existing window
   1197      *         attributes object, or a freshly created one if there is none.
   1198      */
   1199     public final WindowManager.LayoutParams getAttributes() {
   1200         return mWindowAttributes;
   1201     }
   1202 
   1203     /**
   1204      * Return the window flags that have been explicitly set by the client,
   1205      * so will not be modified by {@link #getDecorView}.
   1206      */
   1207     protected final int getForcedWindowFlags() {
   1208         return mForcedWindowFlags;
   1209     }
   1210 
   1211     /**
   1212      * Has the app specified their own soft input mode?
   1213      */
   1214     protected final boolean hasSoftInputMode() {
   1215         return mHasSoftInputMode;
   1216     }
   1217 
   1218     /** @hide */
   1219     public void setCloseOnTouchOutside(boolean close) {
   1220         mCloseOnTouchOutside = close;
   1221         mSetCloseOnTouchOutside = true;
   1222     }
   1223 
   1224     /** @hide */
   1225     public void setCloseOnTouchOutsideIfNotSet(boolean close) {
   1226         if (!mSetCloseOnTouchOutside) {
   1227             mCloseOnTouchOutside = close;
   1228             mSetCloseOnTouchOutside = true;
   1229         }
   1230     }
   1231 
   1232     /** @hide */
   1233     @SystemApi
   1234     public void setDisableWallpaperTouchEvents(boolean disable) {
   1235         setPrivateFlags(disable
   1236                 ? WindowManager.LayoutParams.PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS : 0,
   1237                 WindowManager.LayoutParams.PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS);
   1238     }
   1239 
   1240     /** @hide */
   1241     public abstract void alwaysReadCloseOnTouchAttr();
   1242 
   1243     /** @hide */
   1244     public boolean shouldCloseOnTouch(Context context, MotionEvent event) {
   1245         if (mCloseOnTouchOutside && event.getAction() == MotionEvent.ACTION_DOWN
   1246                 && isOutOfBounds(context, event) && peekDecorView() != null) {
   1247             return true;
   1248         }
   1249         return false;
   1250     }
   1251 
   1252     /* Sets the Sustained Performance requirement for the calling window.
   1253      * @param enable disables or enables the mode.
   1254      */
   1255     public void setSustainedPerformanceMode(boolean enable) {
   1256         setPrivateFlags(enable
   1257                 ? WindowManager.LayoutParams.PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE : 0,
   1258                 WindowManager.LayoutParams.PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE);
   1259     }
   1260 
   1261     private boolean isOutOfBounds(Context context, MotionEvent event) {
   1262         final int x = (int) event.getX();
   1263         final int y = (int) event.getY();
   1264         final int slop = ViewConfiguration.get(context).getScaledWindowTouchSlop();
   1265         final View decorView = getDecorView();
   1266         return (x < -slop) || (y < -slop)
   1267                 || (x > (decorView.getWidth()+slop))
   1268                 || (y > (decorView.getHeight()+slop));
   1269     }
   1270 
   1271     /**
   1272      * Enable extended screen features.  This must be called before
   1273      * setContentView().  May be called as many times as desired as long as it
   1274      * is before setContentView().  If not called, no extended features
   1275      * will be available.  You can not turn off a feature once it is requested.
   1276      * You canot use other title features with {@link #FEATURE_CUSTOM_TITLE}.
   1277      *
   1278      * @param featureId The desired features, defined as constants by Window.
   1279      * @return The features that are now set.
   1280      */
   1281     public boolean requestFeature(int featureId) {
   1282         final int flag = 1<<featureId;
   1283         mFeatures |= flag;
   1284         mLocalFeatures |= mContainer != null ? (flag&~mContainer.mFeatures) : flag;
   1285         return (mFeatures&flag) != 0;
   1286     }
   1287 
   1288     /**
   1289      * @hide Used internally to help resolve conflicting features.
   1290      */
   1291     protected void removeFeature(int featureId) {
   1292         final int flag = 1<<featureId;
   1293         mFeatures &= ~flag;
   1294         mLocalFeatures &= ~(mContainer != null ? (flag&~mContainer.mFeatures) : flag);
   1295     }
   1296 
   1297     public final void makeActive() {
   1298         if (mContainer != null) {
   1299             if (mContainer.mActiveChild != null) {
   1300                 mContainer.mActiveChild.mIsActive = false;
   1301             }
   1302             mContainer.mActiveChild = this;
   1303         }
   1304         mIsActive = true;
   1305         onActive();
   1306     }
   1307 
   1308     public final boolean isActive()
   1309     {
   1310         return mIsActive;
   1311     }
   1312 
   1313     /**
   1314      * Finds a view that was identified by the {@code android:id} XML attribute
   1315      * that was processed in {@link android.app.Activity#onCreate}. This will
   1316      * implicitly call {@link #getDecorView} with all of the associated
   1317      * side-effects.
   1318      * <p>
   1319      * <strong>Note:</strong> In most cases -- depending on compiler support --
   1320      * the resulting view is automatically cast to the target class type. If
   1321      * the target class type is unconstrained, an explicit cast may be
   1322      * necessary.
   1323      *
   1324      * @param id the ID to search for
   1325      * @return a view with given ID if found, or {@code null} otherwise
   1326      * @see View#findViewById(int)
   1327      */
   1328     @Nullable
   1329     public <T extends View> T findViewById(@IdRes int id) {
   1330         return getDecorView().findViewById(id);
   1331     }
   1332 
   1333     /**
   1334      * Convenience for
   1335      * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}
   1336      * to set the screen content from a layout resource.  The resource will be
   1337      * inflated, adding all top-level views to the screen.
   1338      *
   1339      * @param layoutResID Resource ID to be inflated.
   1340      * @see #setContentView(View, android.view.ViewGroup.LayoutParams)
   1341      */
   1342     public abstract void setContentView(@LayoutRes int layoutResID);
   1343 
   1344     /**
   1345      * Convenience for
   1346      * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}
   1347      * set the screen content to an explicit view.  This view is placed
   1348      * directly into the screen's view hierarchy.  It can itself be a complex
   1349      * view hierarhcy.
   1350      *
   1351      * @param view The desired content to display.
   1352      * @see #setContentView(View, android.view.ViewGroup.LayoutParams)
   1353      */
   1354     public abstract void setContentView(View view);
   1355 
   1356     /**
   1357      * Set the screen content to an explicit view.  This view is placed
   1358      * directly into the screen's view hierarchy.  It can itself be a complex
   1359      * view hierarchy.
   1360      *
   1361      * <p>Note that calling this function "locks in" various characteristics
   1362      * of the window that can not, from this point forward, be changed: the
   1363      * features that have been requested with {@link #requestFeature(int)},
   1364      * and certain window flags as described in {@link #setFlags(int, int)}.</p>
   1365      *
   1366      * <p>If {@link #FEATURE_CONTENT_TRANSITIONS} is set, the window's
   1367      * TransitionManager will be used to animate content from the current
   1368      * content View to view.</p>
   1369      *
   1370      * @param view The desired content to display.
   1371      * @param params Layout parameters for the view.
   1372      * @see #getTransitionManager()
   1373      * @see #setTransitionManager(android.transition.TransitionManager)
   1374      */
   1375     public abstract void setContentView(View view, ViewGroup.LayoutParams params);
   1376 
   1377     /**
   1378      * Variation on
   1379      * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}
   1380      * to add an additional content view to the screen.  Added after any existing
   1381      * ones in the screen -- existing views are NOT removed.
   1382      *
   1383      * @param view The desired content to display.
   1384      * @param params Layout parameters for the view.
   1385      */
   1386     public abstract void addContentView(View view, ViewGroup.LayoutParams params);
   1387 
   1388     /**
   1389      * Remove the view that was used as the screen content.
   1390      *
   1391      * @hide
   1392      */
   1393     public abstract void clearContentView();
   1394 
   1395     /**
   1396      * Return the view in this Window that currently has focus, or null if
   1397      * there are none.  Note that this does not look in any containing
   1398      * Window.
   1399      *
   1400      * @return View The current View with focus or null.
   1401      */
   1402     @Nullable
   1403     public abstract View getCurrentFocus();
   1404 
   1405     /**
   1406      * Quick access to the {@link LayoutInflater} instance that this Window
   1407      * retrieved from its Context.
   1408      *
   1409      * @return LayoutInflater The shared LayoutInflater.
   1410      */
   1411     @NonNull
   1412     public abstract LayoutInflater getLayoutInflater();
   1413 
   1414     public abstract void setTitle(CharSequence title);
   1415 
   1416     @Deprecated
   1417     public abstract void setTitleColor(@ColorInt int textColor);
   1418 
   1419     public abstract void openPanel(int featureId, KeyEvent event);
   1420 
   1421     public abstract void closePanel(int featureId);
   1422 
   1423     public abstract void togglePanel(int featureId, KeyEvent event);
   1424 
   1425     public abstract void invalidatePanelMenu(int featureId);
   1426 
   1427     public abstract boolean performPanelShortcut(int featureId,
   1428                                                  int keyCode,
   1429                                                  KeyEvent event,
   1430                                                  int flags);
   1431     public abstract boolean performPanelIdentifierAction(int featureId,
   1432                                                  int id,
   1433                                                  int flags);
   1434 
   1435     public abstract void closeAllPanels();
   1436 
   1437     public abstract boolean performContextMenuIdentifierAction(int id, int flags);
   1438 
   1439     /**
   1440      * Should be called when the configuration is changed.
   1441      *
   1442      * @param newConfig The new configuration.
   1443      */
   1444     public abstract void onConfigurationChanged(Configuration newConfig);
   1445 
   1446     /**
   1447      * Sets the window elevation.
   1448      * <p>
   1449      * Changes to this property take effect immediately and will cause the
   1450      * window surface to be recreated. This is an expensive operation and as a
   1451      * result, this property should not be animated.
   1452      *
   1453      * @param elevation The window elevation.
   1454      * @see View#setElevation(float)
   1455      * @see android.R.styleable#Window_windowElevation
   1456      */
   1457     public void setElevation(float elevation) {}
   1458 
   1459     /**
   1460      * Gets the window elevation.
   1461      *
   1462      * @hide
   1463      */
   1464     public float getElevation() {
   1465         return 0.0f;
   1466     }
   1467 
   1468     /**
   1469      * Sets whether window content should be clipped to the outline of the
   1470      * window background.
   1471      *
   1472      * @param clipToOutline Whether window content should be clipped to the
   1473      *                      outline of the window background.
   1474      * @see View#setClipToOutline(boolean)
   1475      * @see android.R.styleable#Window_windowClipToOutline
   1476      */
   1477     public void setClipToOutline(boolean clipToOutline) {}
   1478 
   1479     /**
   1480      * Change the background of this window to a Drawable resource. Setting the
   1481      * background to null will make the window be opaque. To make the window
   1482      * transparent, you can use an empty drawable (for instance a ColorDrawable
   1483      * with the color 0 or the system drawable android:drawable/empty.)
   1484      *
   1485      * @param resId The resource identifier of a drawable resource which will
   1486      *              be installed as the new background.
   1487      */
   1488     public void setBackgroundDrawableResource(@DrawableRes int resId) {
   1489         setBackgroundDrawable(mContext.getDrawable(resId));
   1490     }
   1491 
   1492     /**
   1493      * Change the background of this window to a custom Drawable. Setting the
   1494      * background to null will make the window be opaque. To make the window
   1495      * transparent, you can use an empty drawable (for instance a ColorDrawable
   1496      * with the color 0 or the system drawable android:drawable/empty.)
   1497      *
   1498      * @param drawable The new Drawable to use for this window's background.
   1499      */
   1500     public abstract void setBackgroundDrawable(Drawable drawable);
   1501 
   1502     /**
   1503      * Set the value for a drawable feature of this window, from a resource
   1504      * identifier.  You must have called requestFeature(featureId) before
   1505      * calling this function.
   1506      *
   1507      * @see android.content.res.Resources#getDrawable(int)
   1508      *
   1509      * @param featureId The desired drawable feature to change, defined as a
   1510      * constant by Window.
   1511      * @param resId Resource identifier of the desired image.
   1512      */
   1513     public abstract void setFeatureDrawableResource(int featureId, @DrawableRes int resId);
   1514 
   1515     /**
   1516      * Set the value for a drawable feature of this window, from a URI. You
   1517      * must have called requestFeature(featureId) before calling this
   1518      * function.
   1519      *
   1520      * <p>The only URI currently supported is "content:", specifying an image
   1521      * in a content provider.
   1522      *
   1523      * @see android.widget.ImageView#setImageURI
   1524      *
   1525      * @param featureId The desired drawable feature to change. Features are
   1526      * constants defined by Window.
   1527      * @param uri The desired URI.
   1528      */
   1529     public abstract void setFeatureDrawableUri(int featureId, Uri uri);
   1530 
   1531     /**
   1532      * Set an explicit Drawable value for feature of this window. You must
   1533      * have called requestFeature(featureId) before calling this function.
   1534      *
   1535      * @param featureId The desired drawable feature to change. Features are
   1536      *                  constants defined by Window.
   1537      * @param drawable A Drawable object to display.
   1538      */
   1539     public abstract void setFeatureDrawable(int featureId, Drawable drawable);
   1540 
   1541     /**
   1542      * Set a custom alpha value for the given drawable feature, controlling how
   1543      * much the background is visible through it.
   1544      *
   1545      * @param featureId The desired drawable feature to change. Features are
   1546      *                  constants defined by Window.
   1547      * @param alpha The alpha amount, 0 is completely transparent and 255 is
   1548      *              completely opaque.
   1549      */
   1550     public abstract void setFeatureDrawableAlpha(int featureId, int alpha);
   1551 
   1552     /**
   1553      * Set the integer value for a feature. The range of the value depends on
   1554      * the feature being set. For {@link #FEATURE_PROGRESS}, it should go from
   1555      * 0 to 10000. At 10000 the progress is complete and the indicator hidden.
   1556      *
   1557      * @param featureId The desired feature to change. Features are constants
   1558      *                  defined by Window.
   1559      * @param value The value for the feature. The interpretation of this
   1560      *              value is feature-specific.
   1561      */
   1562     public abstract void setFeatureInt(int featureId, int value);
   1563 
   1564     /**
   1565      * Request that key events come to this activity. Use this if your
   1566      * activity has no views with focus, but the activity still wants
   1567      * a chance to process key events.
   1568      */
   1569     public abstract void takeKeyEvents(boolean get);
   1570 
   1571     /**
   1572      * Used by custom windows, such as Dialog, to pass the key press event
   1573      * further down the view hierarchy. Application developers should
   1574      * not need to implement or call this.
   1575      *
   1576      */
   1577     public abstract boolean superDispatchKeyEvent(KeyEvent event);
   1578 
   1579     /**
   1580      * Used by custom windows, such as Dialog, to pass the key shortcut press event
   1581      * further down the view hierarchy. Application developers should
   1582      * not need to implement or call this.
   1583      *
   1584      */
   1585     public abstract boolean superDispatchKeyShortcutEvent(KeyEvent event);
   1586 
   1587     /**
   1588      * Used by custom windows, such as Dialog, to pass the touch screen event
   1589      * further down the view hierarchy. Application developers should
   1590      * not need to implement or call this.
   1591      *
   1592      */
   1593     public abstract boolean superDispatchTouchEvent(MotionEvent event);
   1594 
   1595     /**
   1596      * Used by custom windows, such as Dialog, to pass the trackball event
   1597      * further down the view hierarchy. Application developers should
   1598      * not need to implement or call this.
   1599      *
   1600      */
   1601     public abstract boolean superDispatchTrackballEvent(MotionEvent event);
   1602 
   1603     /**
   1604      * Used by custom windows, such as Dialog, to pass the generic motion event
   1605      * further down the view hierarchy. Application developers should
   1606      * not need to implement or call this.
   1607      *
   1608      */
   1609     public abstract boolean superDispatchGenericMotionEvent(MotionEvent event);
   1610 
   1611     /**
   1612      * Retrieve the top-level window decor view (containing the standard
   1613      * window frame/decorations and the client's content inside of that), which
   1614      * can be added as a window to the window manager.
   1615      *
   1616      * <p><em>Note that calling this function for the first time "locks in"
   1617      * various window characteristics as described in
   1618      * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}.</em></p>
   1619      *
   1620      * @return Returns the top-level window decor view.
   1621      */
   1622     public abstract View getDecorView();
   1623 
   1624     /**
   1625      * Retrieve the current decor view, but only if it has already been created;
   1626      * otherwise returns null.
   1627      *
   1628      * @return Returns the top-level window decor or null.
   1629      * @see #getDecorView
   1630      */
   1631     public abstract View peekDecorView();
   1632 
   1633     public abstract Bundle saveHierarchyState();
   1634 
   1635     public abstract void restoreHierarchyState(Bundle savedInstanceState);
   1636 
   1637     protected abstract void onActive();
   1638 
   1639     /**
   1640      * Return the feature bits that are enabled.  This is the set of features
   1641      * that were given to requestFeature(), and are being handled by this
   1642      * Window itself or its container.  That is, it is the set of
   1643      * requested features that you can actually use.
   1644      *
   1645      * <p>To do: add a public version of this API that allows you to check for
   1646      * features by their feature ID.
   1647      *
   1648      * @return int The feature bits.
   1649      */
   1650     protected final int getFeatures()
   1651     {
   1652         return mFeatures;
   1653     }
   1654 
   1655     /**
   1656      * Return the feature bits set by default on a window.
   1657      * @param context The context used to access resources
   1658      */
   1659     public static int getDefaultFeatures(Context context) {
   1660         int features = 0;
   1661 
   1662         final Resources res = context.getResources();
   1663         if (res.getBoolean(com.android.internal.R.bool.config_defaultWindowFeatureOptionsPanel)) {
   1664             features |= 1 << FEATURE_OPTIONS_PANEL;
   1665         }
   1666 
   1667         if (res.getBoolean(com.android.internal.R.bool.config_defaultWindowFeatureContextMenu)) {
   1668             features |= 1 << FEATURE_CONTEXT_MENU;
   1669         }
   1670 
   1671         return features;
   1672     }
   1673 
   1674     /**
   1675      * Query for the availability of a certain feature.
   1676      *
   1677      * @param feature The feature ID to check
   1678      * @return true if the feature is enabled, false otherwise.
   1679      */
   1680     public boolean hasFeature(int feature) {
   1681         return (getFeatures() & (1 << feature)) != 0;
   1682     }
   1683 
   1684     /**
   1685      * Return the feature bits that are being implemented by this Window.
   1686      * This is the set of features that were given to requestFeature(), and are
   1687      * being handled by only this Window itself, not by its containers.
   1688      *
   1689      * @return int The feature bits.
   1690      */
   1691     protected final int getLocalFeatures()
   1692     {
   1693         return mLocalFeatures;
   1694     }
   1695 
   1696     /**
   1697      * Set the default format of window, as per the PixelFormat types.  This
   1698      * is the format that will be used unless the client specifies in explicit
   1699      * format with setFormat();
   1700      *
   1701      * @param format The new window format (see PixelFormat).
   1702      *
   1703      * @see #setFormat
   1704      * @see PixelFormat
   1705      */
   1706     protected void setDefaultWindowFormat(int format) {
   1707         mDefaultWindowFormat = format;
   1708         if (!mHaveWindowFormat) {
   1709             final WindowManager.LayoutParams attrs = getAttributes();
   1710             attrs.format = format;
   1711             dispatchWindowAttributesChanged(attrs);
   1712         }
   1713     }
   1714 
   1715     /** @hide */
   1716     protected boolean haveDimAmount() {
   1717         return mHaveDimAmount;
   1718     }
   1719 
   1720     public abstract void setChildDrawable(int featureId, Drawable drawable);
   1721 
   1722     public abstract void setChildInt(int featureId, int value);
   1723 
   1724     /**
   1725      * Is a keypress one of the defined shortcut keys for this window.
   1726      * @param keyCode the key code from {@link android.view.KeyEvent} to check.
   1727      * @param event the {@link android.view.KeyEvent} to use to help check.
   1728      */
   1729     public abstract boolean isShortcutKey(int keyCode, KeyEvent event);
   1730 
   1731     /**
   1732      * @see android.app.Activity#setVolumeControlStream(int)
   1733      */
   1734     public abstract void setVolumeControlStream(int streamType);
   1735 
   1736     /**
   1737      * @see android.app.Activity#getVolumeControlStream()
   1738      */
   1739     public abstract int getVolumeControlStream();
   1740 
   1741     /**
   1742      * Sets a {@link MediaController} to send media keys and volume changes to.
   1743      * If set, this should be preferred for all media keys and volume requests
   1744      * sent to this window.
   1745      *
   1746      * @param controller The controller for the session which should receive
   1747      *            media keys and volume changes.
   1748      * @see android.app.Activity#setMediaController(android.media.session.MediaController)
   1749      */
   1750     public void setMediaController(MediaController controller) {
   1751     }
   1752 
   1753     /**
   1754      * Gets the {@link MediaController} that was previously set.
   1755      *
   1756      * @return The controller which should receive events.
   1757      * @see #setMediaController(android.media.session.MediaController)
   1758      * @see android.app.Activity#getMediaController()
   1759      */
   1760     public MediaController getMediaController() {
   1761         return null;
   1762     }
   1763 
   1764     /**
   1765      * Set extra options that will influence the UI for this window.
   1766      * @param uiOptions Flags specifying extra options for this window.
   1767      */
   1768     public void setUiOptions(int uiOptions) { }
   1769 
   1770     /**
   1771      * Set extra options that will influence the UI for this window.
   1772      * Only the bits filtered by mask will be modified.
   1773      * @param uiOptions Flags specifying extra options for this window.
   1774      * @param mask Flags specifying which options should be modified. Others will remain unchanged.
   1775      */
   1776     public void setUiOptions(int uiOptions, int mask) { }
   1777 
   1778     /**
   1779      * Set the primary icon for this window.
   1780      *
   1781      * @param resId resource ID of a drawable to set
   1782      */
   1783     public void setIcon(@DrawableRes int resId) { }
   1784 
   1785     /**
   1786      * Set the default icon for this window.
   1787      * This will be overridden by any other icon set operation which could come from the
   1788      * theme or another explicit set.
   1789      *
   1790      * @hide
   1791      */
   1792     public void setDefaultIcon(@DrawableRes int resId) { }
   1793 
   1794     /**
   1795      * Set the logo for this window. A logo is often shown in place of an
   1796      * {@link #setIcon(int) icon} but is generally wider and communicates window title information
   1797      * as well.
   1798      *
   1799      * @param resId resource ID of a drawable to set
   1800      */
   1801     public void setLogo(@DrawableRes int resId) { }
   1802 
   1803     /**
   1804      * Set the default logo for this window.
   1805      * This will be overridden by any other logo set operation which could come from the
   1806      * theme or another explicit set.
   1807      *
   1808      * @hide
   1809      */
   1810     public void setDefaultLogo(@DrawableRes int resId) { }
   1811 
   1812     /**
   1813      * Set focus locally. The window should have the
   1814      * {@link WindowManager.LayoutParams#FLAG_LOCAL_FOCUS_MODE} flag set already.
   1815      * @param hasFocus Whether this window has focus or not.
   1816      * @param inTouchMode Whether this window is in touch mode or not.
   1817      */
   1818     public void setLocalFocus(boolean hasFocus, boolean inTouchMode) { }
   1819 
   1820     /**
   1821      * Inject an event to window locally.
   1822      * @param event A key or touch event to inject to this window.
   1823      */
   1824     public void injectInputEvent(InputEvent event) { }
   1825 
   1826     /**
   1827      * Retrieve the {@link TransitionManager} responsible for  for default transitions
   1828      * in this window. Requires {@link #FEATURE_CONTENT_TRANSITIONS}.
   1829      *
   1830      * <p>This method will return non-null after content has been initialized (e.g. by using
   1831      * {@link #setContentView}) if {@link #FEATURE_CONTENT_TRANSITIONS} has been granted.</p>
   1832      *
   1833      * @return This window's content TransitionManager or null if none is set.
   1834      * @attr ref android.R.styleable#Window_windowContentTransitionManager
   1835      */
   1836     public TransitionManager getTransitionManager() {
   1837         return null;
   1838     }
   1839 
   1840     /**
   1841      * Set the {@link TransitionManager} to use for default transitions in this window.
   1842      * Requires {@link #FEATURE_CONTENT_TRANSITIONS}.
   1843      *
   1844      * @param tm The TransitionManager to use for scene changes.
   1845      * @attr ref android.R.styleable#Window_windowContentTransitionManager
   1846      */
   1847     public void setTransitionManager(TransitionManager tm) {
   1848         throw new UnsupportedOperationException();
   1849     }
   1850 
   1851     /**
   1852      * Retrieve the {@link Scene} representing this window's current content.
   1853      * Requires {@link #FEATURE_CONTENT_TRANSITIONS}.
   1854      *
   1855      * <p>This method will return null if the current content is not represented by a Scene.</p>
   1856      *
   1857      * @return Current Scene being shown or null
   1858      */
   1859     public Scene getContentScene() {
   1860         return null;
   1861     }
   1862 
   1863     /**
   1864      * Sets the Transition that will be used to move Views into the initial scene. The entering
   1865      * Views will be those that are regular Views or ViewGroups that have
   1866      * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
   1867      * {@link android.transition.Visibility} as entering is governed by changing visibility from
   1868      * {@link View#INVISIBLE} to {@link View#VISIBLE}. If <code>transition</code> is null,
   1869      * entering Views will remain unaffected.
   1870      *
   1871      * @param transition The Transition to use to move Views into the initial Scene.
   1872      * @attr ref android.R.styleable#Window_windowEnterTransition
   1873      */
   1874     public void setEnterTransition(Transition transition) {}
   1875 
   1876     /**
   1877      * Sets the Transition that will be used to move Views out of the scene when the Window is
   1878      * preparing to close, for example after a call to
   1879      * {@link android.app.Activity#finishAfterTransition()}. The exiting
   1880      * Views will be those that are regular Views or ViewGroups that have
   1881      * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
   1882      * {@link android.transition.Visibility} as entering is governed by changing visibility from
   1883      * {@link View#VISIBLE} to {@link View#INVISIBLE}. If <code>transition</code> is null,
   1884      * entering Views will remain unaffected. If nothing is set, the default will be to
   1885      * use the same value as set in {@link #setEnterTransition(android.transition.Transition)}.
   1886      *
   1887      * @param transition The Transition to use to move Views out of the Scene when the Window
   1888      *                   is preparing to close.
   1889      * @attr ref android.R.styleable#Window_windowReturnTransition
   1890      */
   1891     public void setReturnTransition(Transition transition) {}
   1892 
   1893     /**
   1894      * Sets the Transition that will be used to move Views out of the scene when starting a
   1895      * new Activity. The exiting Views will be those that are regular Views or ViewGroups that
   1896      * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
   1897      * {@link android.transition.Visibility} as exiting is governed by changing visibility
   1898      * from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, the views will
   1899      * remain unaffected. Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
   1900      *
   1901      * @param transition The Transition to use to move Views out of the scene when calling a
   1902      *                   new Activity.
   1903      * @attr ref android.R.styleable#Window_windowExitTransition
   1904      */
   1905     public void setExitTransition(Transition transition) {}
   1906 
   1907     /**
   1908      * Sets the Transition that will be used to move Views in to the scene when returning from
   1909      * a previously-started Activity. The entering Views will be those that are regular Views
   1910      * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions
   1911      * will extend {@link android.transition.Visibility} as exiting is governed by changing
   1912      * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null,
   1913      * the views will remain unaffected. If nothing is set, the default will be to use the same
   1914      * transition as {@link #setExitTransition(android.transition.Transition)}.
   1915      * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
   1916      *
   1917      * @param transition The Transition to use to move Views into the scene when reentering from a
   1918      *                   previously-started Activity.
   1919      * @attr ref android.R.styleable#Window_windowReenterTransition
   1920      */
   1921     public void setReenterTransition(Transition transition) {}
   1922 
   1923     /**
   1924      * Returns the transition used to move Views into the initial scene. The entering
   1925      * Views will be those that are regular Views or ViewGroups that have
   1926      * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
   1927      * {@link android.transition.Visibility} as entering is governed by changing visibility from
   1928      * {@link View#INVISIBLE} to {@link View#VISIBLE}. If <code>transition</code> is null,
   1929      * entering Views will remain unaffected.  Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
   1930      *
   1931      * @return the Transition to use to move Views into the initial Scene.
   1932      * @attr ref android.R.styleable#Window_windowEnterTransition
   1933      */
   1934     public Transition getEnterTransition() { return null; }
   1935 
   1936     /**
   1937      * Returns the Transition that will be used to move Views out of the scene when the Window is
   1938      * preparing to close, for example after a call to
   1939      * {@link android.app.Activity#finishAfterTransition()}. The exiting
   1940      * Views will be those that are regular Views or ViewGroups that have
   1941      * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
   1942      * {@link android.transition.Visibility} as entering is governed by changing visibility from
   1943      * {@link View#VISIBLE} to {@link View#INVISIBLE}.
   1944      *
   1945      * @return The Transition to use to move Views out of the Scene when the Window
   1946      *         is preparing to close.
   1947      * @attr ref android.R.styleable#Window_windowReturnTransition
   1948      */
   1949     public Transition getReturnTransition() { return null; }
   1950 
   1951     /**
   1952      * Returns the Transition that will be used to move Views out of the scene when starting a
   1953      * new Activity. The exiting Views will be those that are regular Views or ViewGroups that
   1954      * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
   1955      * {@link android.transition.Visibility} as exiting is governed by changing visibility
   1956      * from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, the views will
   1957      * remain unaffected. Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
   1958      *
   1959      * @return the Transition to use to move Views out of the scene when calling a
   1960      * new Activity.
   1961      * @attr ref android.R.styleable#Window_windowExitTransition
   1962      */
   1963     public Transition getExitTransition() { return null; }
   1964 
   1965     /**
   1966      * Returns the Transition that will be used to move Views in to the scene when returning from
   1967      * a previously-started Activity. The entering Views will be those that are regular Views
   1968      * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions
   1969      * will extend {@link android.transition.Visibility} as exiting is governed by changing
   1970      * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}.
   1971      * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
   1972      *
   1973      * @return The Transition to use to move Views into the scene when reentering from a
   1974      *         previously-started Activity.
   1975      * @attr ref android.R.styleable#Window_windowReenterTransition
   1976      */
   1977     public Transition getReenterTransition() { return null; }
   1978 
   1979     /**
   1980      * Sets the Transition that will be used for shared elements transferred into the content
   1981      * Scene. Typical Transitions will affect size and location, such as
   1982      * {@link android.transition.ChangeBounds}. A null
   1983      * value will cause transferred shared elements to blink to the final position.
   1984      * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
   1985      *
   1986      * @param transition The Transition to use for shared elements transferred into the content
   1987      *                   Scene.
   1988      * @attr ref android.R.styleable#Window_windowSharedElementEnterTransition
   1989      */
   1990     public void setSharedElementEnterTransition(Transition transition) {}
   1991 
   1992     /**
   1993      * Sets the Transition that will be used for shared elements transferred back to a
   1994      * calling Activity. Typical Transitions will affect size and location, such as
   1995      * {@link android.transition.ChangeBounds}. A null
   1996      * value will cause transferred shared elements to blink to the final position.
   1997      * If no value is set, the default will be to use the same value as
   1998      * {@link #setSharedElementEnterTransition(android.transition.Transition)}.
   1999      * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
   2000      *
   2001      * @param transition The Transition to use for shared elements transferred out of the content
   2002      *                   Scene.
   2003      * @attr ref android.R.styleable#Window_windowSharedElementReturnTransition
   2004      */
   2005     public void setSharedElementReturnTransition(Transition transition) {}
   2006 
   2007     /**
   2008      * Returns the Transition that will be used for shared elements transferred into the content
   2009      * Scene. Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
   2010      *
   2011      * @return Transition to use for sharend elements transferred into the content Scene.
   2012      * @attr ref android.R.styleable#Window_windowSharedElementEnterTransition
   2013      */
   2014     public Transition getSharedElementEnterTransition() { return null; }
   2015 
   2016     /**
   2017      * Returns the Transition that will be used for shared elements transferred back to a
   2018      * calling Activity. Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
   2019      *
   2020      * @return Transition to use for sharend elements transferred into the content Scene.
   2021      * @attr ref android.R.styleable#Window_windowSharedElementReturnTransition
   2022      */
   2023     public Transition getSharedElementReturnTransition() { return null; }
   2024 
   2025     /**
   2026      * Sets the Transition that will be used for shared elements after starting a new Activity
   2027      * before the shared elements are transferred to the called Activity. If the shared elements
   2028      * must animate during the exit transition, this Transition should be used. Upon completion,
   2029      * the shared elements may be transferred to the started Activity.
   2030      * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
   2031      *
   2032      * @param transition The Transition to use for shared elements in the launching Window
   2033      *                   prior to transferring to the launched Activity's Window.
   2034      * @attr ref android.R.styleable#Window_windowSharedElementExitTransition
   2035      */
   2036     public void setSharedElementExitTransition(Transition transition) {}
   2037 
   2038     /**
   2039      * Sets the Transition that will be used for shared elements reentering from a started
   2040      * Activity after it has returned the shared element to it start location. If no value
   2041      * is set, this will default to
   2042      * {@link #setSharedElementExitTransition(android.transition.Transition)}.
   2043      * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
   2044      *
   2045      * @param transition The Transition to use for shared elements in the launching Window
   2046      *                   after the shared element has returned to the Window.
   2047      * @attr ref android.R.styleable#Window_windowSharedElementReenterTransition
   2048      */
   2049     public void setSharedElementReenterTransition(Transition transition) {}
   2050 
   2051     /**
   2052      * Returns the Transition to use for shared elements in the launching Window prior
   2053      * to transferring to the launched Activity's Window.
   2054      * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
   2055      *
   2056      * @return the Transition to use for shared elements in the launching Window prior
   2057      * to transferring to the launched Activity's Window.
   2058      * @attr ref android.R.styleable#Window_windowSharedElementExitTransition
   2059      */
   2060     public Transition getSharedElementExitTransition() { return null; }
   2061 
   2062     /**
   2063      * Returns the Transition that will be used for shared elements reentering from a started
   2064      * Activity after it has returned the shared element to it start location.
   2065      * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
   2066      *
   2067      * @return the Transition that will be used for shared elements reentering from a started
   2068      * Activity after it has returned the shared element to it start location.
   2069      * @attr ref android.R.styleable#Window_windowSharedElementReenterTransition
   2070      */
   2071     public Transition getSharedElementReenterTransition() { return null; }
   2072 
   2073     /**
   2074      * Controls how the transition set in
   2075      * {@link #setEnterTransition(android.transition.Transition)} overlaps with the exit
   2076      * transition of the calling Activity. When true, the transition will start as soon as possible.
   2077      * When false, the transition will wait until the remote exiting transition completes before
   2078      * starting. The default value is true.
   2079      *
   2080      * @param allow true to start the enter transition when possible or false to
   2081      *              wait until the exiting transition completes.
   2082      * @attr ref android.R.styleable#Window_windowAllowEnterTransitionOverlap
   2083      */
   2084     public void setAllowEnterTransitionOverlap(boolean allow) {}
   2085 
   2086     /**
   2087      * Returns how the transition set in
   2088      * {@link #setEnterTransition(android.transition.Transition)} overlaps with the exit
   2089      * transition of the calling Activity. When true, the transition will start as soon as possible.
   2090      * When false, the transition will wait until the remote exiting transition completes before
   2091      * starting. The default value is true.
   2092      *
   2093      * @return true when the enter transition should start as soon as possible or false to
   2094      * when it should wait until the exiting transition completes.
   2095      * @attr ref android.R.styleable#Window_windowAllowEnterTransitionOverlap
   2096      */
   2097     public boolean getAllowEnterTransitionOverlap() { return true; }
   2098 
   2099     /**
   2100      * Controls how the transition set in
   2101      * {@link #setExitTransition(android.transition.Transition)} overlaps with the exit
   2102      * transition of the called Activity when reentering after if finishes. When true,
   2103      * the transition will start as soon as possible. When false, the transition will wait
   2104      * until the called Activity's exiting transition completes before starting.
   2105      * The default value is true.
   2106      *
   2107      * @param allow true to start the transition when possible or false to wait until the
   2108      *              called Activity's exiting transition completes.
   2109      * @attr ref android.R.styleable#Window_windowAllowReturnTransitionOverlap
   2110      */
   2111     public void setAllowReturnTransitionOverlap(boolean allow) {}
   2112 
   2113     /**
   2114      * Returns how the transition set in
   2115      * {@link #setExitTransition(android.transition.Transition)} overlaps with the exit
   2116      * transition of the called Activity when reentering after if finishes. When true,
   2117      * the transition will start as soon as possible. When false, the transition will wait
   2118      * until the called Activity's exiting transition completes before starting.
   2119      * The default value is true.
   2120      *
   2121      * @return true when the transition should start when possible or false when it should wait
   2122      * until the called Activity's exiting transition completes.
   2123      * @attr ref android.R.styleable#Window_windowAllowReturnTransitionOverlap
   2124      */
   2125     public boolean getAllowReturnTransitionOverlap() { return true; }
   2126 
   2127     /**
   2128      * Returns the duration, in milliseconds, of the window background fade
   2129      * when transitioning into or away from an Activity when called with an Activity Transition.
   2130      * <p>When executing the enter transition, the background starts transparent
   2131      * and fades in. This requires {@link #FEATURE_ACTIVITY_TRANSITIONS}. The default is
   2132      * 300 milliseconds.</p>
   2133      *
   2134      * @return The duration of the window background fade to opaque during enter transition.
   2135      * @see #getEnterTransition()
   2136      * @attr ref android.R.styleable#Window_windowTransitionBackgroundFadeDuration
   2137      */
   2138     public long getTransitionBackgroundFadeDuration() { return 0; }
   2139 
   2140     /**
   2141      * Sets the duration, in milliseconds, of the window background fade
   2142      * when transitioning into or away from an Activity when called with an Activity Transition.
   2143      * <p>When executing the enter transition, the background starts transparent
   2144      * and fades in. This requires {@link #FEATURE_ACTIVITY_TRANSITIONS}. The default is
   2145      * 300 milliseconds.</p>
   2146      *
   2147      * @param fadeDurationMillis The duration of the window background fade to or from opaque
   2148      *                           during enter transition.
   2149      * @see #setEnterTransition(android.transition.Transition)
   2150      * @attr ref android.R.styleable#Window_windowTransitionBackgroundFadeDuration
   2151      */
   2152     public void setTransitionBackgroundFadeDuration(long fadeDurationMillis) { }
   2153 
   2154     /**
   2155      * Returns <code>true</code> when shared elements should use an Overlay during
   2156      * shared element transitions or <code>false</code> when they should animate as
   2157      * part of the normal View hierarchy. The default value is true.
   2158      *
   2159      * @return <code>true</code> when shared elements should use an Overlay during
   2160      * shared element transitions or <code>false</code> when they should animate as
   2161      * part of the normal View hierarchy.
   2162      * @attr ref android.R.styleable#Window_windowSharedElementsUseOverlay
   2163      */
   2164     public boolean getSharedElementsUseOverlay() { return true; }
   2165 
   2166     /**
   2167      * Sets whether or not shared elements should use an Overlay during shared element transitions.
   2168      * The default value is true.
   2169      *
   2170      * @param sharedElementsUseOverlay <code>true</code> indicates that shared elements should
   2171      *                                 be transitioned with an Overlay or <code>false</code>
   2172      *                                 to transition within the normal View hierarchy.
   2173      * @attr ref android.R.styleable#Window_windowSharedElementsUseOverlay
   2174      */
   2175     public void setSharedElementsUseOverlay(boolean sharedElementsUseOverlay) { }
   2176 
   2177     /**
   2178      * @return the color of the status bar.
   2179      */
   2180     @ColorInt
   2181     public abstract int getStatusBarColor();
   2182 
   2183     /**
   2184      * Sets the color of the status bar to {@code color}.
   2185      *
   2186      * For this to take effect,
   2187      * the window must be drawing the system bar backgrounds with
   2188      * {@link android.view.WindowManager.LayoutParams#FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS} and
   2189      * {@link android.view.WindowManager.LayoutParams#FLAG_TRANSLUCENT_STATUS} must not be set.
   2190      *
   2191      * If {@code color} is not opaque, consider setting
   2192      * {@link android.view.View#SYSTEM_UI_FLAG_LAYOUT_STABLE} and
   2193      * {@link android.view.View#SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}.
   2194      * <p>
   2195      * The transitionName for the view background will be "android:status:background".
   2196      * </p>
   2197      */
   2198     public abstract void setStatusBarColor(@ColorInt int color);
   2199 
   2200     /**
   2201      * @return the color of the navigation bar.
   2202      */
   2203     @ColorInt
   2204     public abstract int getNavigationBarColor();
   2205 
   2206     /**
   2207      * Sets the color of the navigation bar to {@param color}.
   2208      *
   2209      * For this to take effect,
   2210      * the window must be drawing the system bar backgrounds with
   2211      * {@link android.view.WindowManager.LayoutParams#FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS} and
   2212      * {@link android.view.WindowManager.LayoutParams#FLAG_TRANSLUCENT_NAVIGATION} must not be set.
   2213      *
   2214      * If {@param color} is not opaque, consider setting
   2215      * {@link android.view.View#SYSTEM_UI_FLAG_LAYOUT_STABLE} and
   2216      * {@link android.view.View#SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION}.
   2217      * <p>
   2218      * The transitionName for the view background will be "android:navigation:background".
   2219      * </p>
   2220      */
   2221     public abstract void setNavigationBarColor(@ColorInt int color);
   2222 
   2223     /** @hide */
   2224     public void setTheme(int resId) {
   2225     }
   2226 
   2227     /**
   2228      * Whether the caption should be displayed directly on the content rather than push the content
   2229      * down. This affects only freeform windows since they display the caption.
   2230      * @hide
   2231      */
   2232     public void setOverlayWithDecorCaptionEnabled(boolean enabled) {
   2233         mOverlayWithDecorCaptionEnabled = enabled;
   2234     }
   2235 
   2236     /** @hide */
   2237     public boolean isOverlayWithDecorCaptionEnabled() {
   2238         return mOverlayWithDecorCaptionEnabled;
   2239     }
   2240 
   2241     /** @hide */
   2242     public void notifyRestrictedCaptionAreaCallback(int left, int top, int right, int bottom) {
   2243         if (mOnRestrictedCaptionAreaChangedListener != null) {
   2244             mRestrictedCaptionAreaRect.set(left, top, right, bottom);
   2245             mOnRestrictedCaptionAreaChangedListener.onRestrictedCaptionAreaChanged(
   2246                     mRestrictedCaptionAreaRect);
   2247         }
   2248     }
   2249 
   2250     /**
   2251      * Set what color should the caption controls be. By default the system will try to determine
   2252      * the color from the theme. You can overwrite this by using {@link #DECOR_CAPTION_SHADE_DARK},
   2253      * {@link #DECOR_CAPTION_SHADE_LIGHT}, or {@link #DECOR_CAPTION_SHADE_AUTO}.
   2254      * @see #DECOR_CAPTION_SHADE_DARK
   2255      * @see #DECOR_CAPTION_SHADE_LIGHT
   2256      * @see #DECOR_CAPTION_SHADE_AUTO
   2257      */
   2258     public abstract void setDecorCaptionShade(int decorCaptionShade);
   2259 
   2260     /**
   2261      * Set the drawable that is drawn underneath the caption during the resizing.
   2262      *
   2263      * During the resizing the caption might not be drawn fast enough to match the new dimensions.
   2264      * There is a second caption drawn underneath it that will be fast enough. By default the
   2265      * caption is constructed from the theme. You can provide a drawable, that will be drawn instead
   2266      * to better match your application.
   2267      */
   2268     public abstract void setResizingCaptionDrawable(Drawable drawable);
   2269 
   2270     /**
   2271      * Called when the activity changes from fullscreen mode to multi-window mode and visa-versa.
   2272      * @hide
   2273      */
   2274     public abstract void onMultiWindowModeChanged();
   2275 
   2276     /**
   2277      * Called when the activity changes to/from picture-in-picture mode.
   2278      * @hide
   2279      */
   2280     public abstract void onPictureInPictureModeChanged(boolean isInPictureInPictureMode);
   2281 
   2282     /**
   2283      * Called when the activity just relaunched.
   2284      * @hide
   2285      */
   2286     public abstract void reportActivityRelaunched();
   2287 
   2288     /**
   2289      * Called to set flag to check if the close on swipe is enabled. This will only function if
   2290      * FEATURE_SWIPE_TO_DISMISS has been set.
   2291      * @hide
   2292      */
   2293     public void setCloseOnSwipeEnabled(boolean closeOnSwipeEnabled) {
   2294         mCloseOnSwipeEnabled = closeOnSwipeEnabled;
   2295     }
   2296 
   2297     /**
   2298      * @return {@code true} if the close on swipe is enabled.
   2299      * @hide
   2300      */
   2301     public boolean isCloseOnSwipeEnabled() {
   2302         return mCloseOnSwipeEnabled;
   2303     }
   2304 }
   2305