Window.java revision fe568359340e58492e2ca1ebdab0f234b91e328a
15f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)/*
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Copyright (C) 2006 The Android Open Source Project
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Licensed under the Apache License, Version 2.0 (the "License");
55f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) * you may not use this file except in compliance with the License.
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * You may obtain a copy of the License at
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *      http://www.apache.org/licenses/LICENSE-2.0
9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) *
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * Unless required by applicable law or agreed to in writing, software
11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * distributed under the License is distributed on an "AS IS" BASIS,
12868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch * See the License for the specific language governing permissions and
145f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) * limitations under the License.
15116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch */
16116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccipackage android.view;
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import android.annotation.NonNull;
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import android.annotation.Nullable;
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import android.annotation.SystemApi;
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import android.content.Context;
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import android.content.res.Configuration;
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import android.content.res.Resources;
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import android.content.res.TypedArray;
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import android.graphics.PixelFormat;
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import android.graphics.drawable.Drawable;
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import android.media.session.MediaController;
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import android.net.Uri;
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import android.os.Bundle;
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import android.os.IBinder;
325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)import android.os.SystemProperties;
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import android.transition.Scene;
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import android.transition.Transition;
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import android.transition.TransitionManager;
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import android.view.accessibility.AccessibilityEvent;
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/**
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Abstract base class for a top-level window look and behavior policy.  An
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * instance of this class should be used as the top-level view added to the
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * window manager. It provides standard UI policies such as a background, title
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * area, default key processing, etc.
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
44c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch * <p>The only existing implementation of this abstract class is
451320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci * android.policy.PhoneWindow, which you should instantiate when needing a
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Window.  Eventually that class will be refactored and a factory method
4790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) * added for creating Window instances without knowing about a particular
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * implementation.
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public abstract class Window {
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /** Flag for the "options panel" feature.  This is enabled by default. */
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    public static final int FEATURE_OPTIONS_PANEL = 0;
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /** Flag for the "no title" feature, turning off the title at the top
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     *  of the screen. */
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    public static final int FEATURE_NO_TITLE = 1;
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /** Flag for the progress indicator feature */
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    public static final int FEATURE_PROGRESS = 2;
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /** Flag for having an icon on the left side of the title bar */
59c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch    public static final int FEATURE_LEFT_ICON = 3;
601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    /** Flag for having an icon on the right side of the title bar */
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    public static final int FEATURE_RIGHT_ICON = 4;
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /** Flag for indeterminate progress */
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    public static final int FEATURE_INDETERMINATE_PROGRESS = 5;
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /** Flag for the context menu.  This is enabled by default. */
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    public static final int FEATURE_CONTEXT_MENU = 6;
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /** Flag for custom title. You cannot combine this feature with other title features. */
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    public static final int FEATURE_CUSTOM_TITLE = 7;
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /**
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * Flag for enabling the Action Bar.
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * This is enabled by default for some devices. The Action Bar
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * replaces the title bar and provides an alternate location
72ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch     * for an on-screen menu button on some devices.
73c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch     */
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    public static final int FEATURE_ACTION_BAR = 8;
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /**
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * Flag for requesting an Action Bar that overlays window content.
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * Normally an Action Bar will sit in the space above window content, but if this
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * feature is requested along with {@link #FEATURE_ACTION_BAR} it will be layered over
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * the window content itself. This is useful if you would like your app to have more control
80cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)     * over how the Action Bar is displayed, such as letting application content scroll beneath
81cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)     * an Action Bar with a transparent background or otherwise displaying a transparent/translucent
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * Action Bar over application content.
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     *
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * <p>This mode is especially useful with {@link View#SYSTEM_UI_FLAG_FULLSCREEN
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * View.SYSTEM_UI_FLAG_FULLSCREEN}, which allows you to seamlessly hide the
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * action bar in conjunction with other screen decorations.
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     *
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * <p>As of {@link android.os.Build.VERSION_CODES#JELLY_BEAN}, when an
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * ActionBar is in this mode it will adjust the insets provided to
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * {@link View#fitSystemWindows(android.graphics.Rect) View.fitSystemWindows(Rect)}
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * to include the content covered by the action bar, so you can do layout within
92a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)     * that space.
93a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)     */
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    public static final int FEATURE_ACTION_BAR_OVERLAY = 9;
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /**
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * Flag for specifying the behavior of action modes when an Action Bar is not present.
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * If overlay is enabled, the action mode UI will be allowed to cover existing window content.
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     */
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    public static final int FEATURE_ACTION_MODE_OVERLAY = 10;
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /**
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * Flag for requesting a decoration-free window that is dismissed by swiping from the left.
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     */
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    public static final int FEATURE_SWIPE_TO_DISMISS = 11;
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /**
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * Flag for requesting that window content changes should be represented
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * with scenes and transitions.
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     *
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * TODO Add docs
109ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch     *
110c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch     * @see #setContentView
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     */
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    public static final int FEATURE_CONTENT_TRANSITIONS = 12;
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /**
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * Enables Activities to run Activity Transitions either through sending or receiving
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * ActivityOptions bundle created with
117cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)     * {@link android.app.ActivityOptions#makeSceneTransitionAnimation(android.app.Activity,
118cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)     * android.util.Pair[])} or {@link android.app.ActivityOptions#makeSceneTransitionAnimation(
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * android.app.Activity, View, String)}.
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     */
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    public static final int FEATURE_ACTIVITY_TRANSITIONS = 13;
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /**
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * Max value used as a feature ID
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * @hide
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     */
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    public static final int FEATURE_MAX = FEATURE_ACTIVITY_TRANSITIONS;
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
129a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    /** Flag for setting the progress bar's visibility to VISIBLE */
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    public static final int PROGRESS_VISIBILITY_ON = -1;
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /** Flag for setting the progress bar's visibility to GONE */
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    public static final int PROGRESS_VISIBILITY_OFF = -2;
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /** Flag for setting the progress bar's indeterminate mode on */
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    public static final int PROGRESS_INDETERMINATE_ON = -3;
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /** Flag for setting the progress bar's indeterminate mode off */
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    public static final int PROGRESS_INDETERMINATE_OFF = -4;
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /** Starting value for the (primary) progress */
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    public static final int PROGRESS_START = 0;
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /** Ending value for the (primary) progress */
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    public static final int PROGRESS_END = 10000;
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /** Lowest possible value for the secondary progress */
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    public static final int PROGRESS_SECONDARY_START = 20000;
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /** Highest possible value for the secondary progress */
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    public static final int PROGRESS_SECONDARY_END = 30000;
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    /**
1475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * The transitionName for the status bar background View when a custom background is used.
1485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * @see android.view.Window#setStatusBarColor(int)
1495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     */
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    public static final String STATUS_BAR_BACKGROUND_TRANSITION_NAME = "android:status:background";
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /**
153010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)     * The transitionName for the navigation bar background View when a custom background is used.
154f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)     * @see android.view.Window#setNavigationBarColor(int)
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     */
15690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    public static final String NAVIGATION_BAR_BACKGROUND_TRANSITION_NAME =
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            "android:navigation:background";
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /** The default features enabled */
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    @Deprecated
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    @SuppressWarnings({"PointlessBitwiseExpression"})
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    protected static final int DEFAULT_FEATURES = (1 << FEATURE_OPTIONS_PANEL) |
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            (1 << FEATURE_CONTEXT_MENU);
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /**
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * The ID that the main layout in the XML layout file should have.
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     */
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    public static final int ID_ANDROID_CONTENT = com.android.internal.R.id.content;
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    private static final String PROPERTY_HARDWARE_UI = "persist.sys.ui.hw";
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    private final Context mContext;
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    private TypedArray mWindowStyle;
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    private Callback mCallback;
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    private OnWindowDismissedCallback mOnWindowDismissedCallback;
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    private WindowManager mWindowManager;
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    private IBinder mAppToken;
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    private String mAppName;
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    private boolean mHardwareAccelerated;
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    private Window mContainer;
182a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    private Window mActiveChild;
183a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    private boolean mIsActive = false;
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    private boolean mHasChildren = false;
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    private boolean mCloseOnTouchOutside = false;
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    private boolean mSetCloseOnTouchOutside = false;
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    private int mForcedWindowFlags = 0;
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    private int mFeatures;
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    private int mLocalFeatures;
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    private boolean mHaveWindowFormat = false;
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    private boolean mHaveDimAmount = false;
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    private int mDefaultWindowFormat = PixelFormat.OPAQUE;
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    private boolean mHasSoftInputMode = false;
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    private boolean mDestroyed;
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // The current window attributes.
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    private final WindowManager.LayoutParams mWindowAttributes =
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        new WindowManager.LayoutParams();
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /**
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * API from a Window back to its caller.  This allows the client to
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * intercept key dispatching, panels and menus, etc.
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     */
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    public interface Callback {
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        /**
210a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)         * Called to process key events.  At the very least your
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * implementation must call
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * {@link android.view.Window#superDispatchKeyEvent} to do the
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * standard key processing.
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         *
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * @param event The key event.
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         *
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * @return boolean Return true if this event was consumed.
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         */
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        public boolean dispatchKeyEvent(KeyEvent event);
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        /**
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * Called to process a key shortcut event.
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * At the very least your implementation must call
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * {@link android.view.Window#superDispatchKeyShortcutEvent} to do the
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * standard key shortcut processing.
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         *
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * @param event The key shortcut event.
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * @return True if this event was consumed.
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         */
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        public boolean dispatchKeyShortcutEvent(KeyEvent event);
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        /**
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * Called to process touch screen events.  At the very least your
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * implementation must call
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * {@link android.view.Window#superDispatchTouchEvent} to do the
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * standard touch screen processing.
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         *
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * @param event The touch screen event.
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         *
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * @return boolean Return true if this event was consumed.
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         */
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        public boolean dispatchTouchEvent(MotionEvent event);
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        /**
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * Called to process trackball events.  At the very least your
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * implementation must call
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * {@link android.view.Window#superDispatchTrackballEvent} to do the
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * standard trackball processing.
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         *
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * @param event The trackball event.
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         *
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * @return boolean Return true if this event was consumed.
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         */
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        public boolean dispatchTrackballEvent(MotionEvent event);
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        /**
2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * Called to process generic motion events.  At the very least your
2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * implementation must call
2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * {@link android.view.Window#superDispatchGenericMotionEvent} to do the
2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * standard processing.
2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         *
2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * @param event The generic motion event.
2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         *
2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * @return boolean Return true if this event was consumed.
2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         */
2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        public boolean dispatchGenericMotionEvent(MotionEvent event);
2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        /**
2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * Called to process population of {@link AccessibilityEvent}s.
2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         *
2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * @param event The event.
2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         *
2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * @return boolean Return true if event population was completed.
2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         */
2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event);
2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        /**
2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * Instantiate the view to display in the panel for 'featureId'.
2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * You can return null, in which case the default content (typically
2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * a menu) will be created for you.
2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         *
2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * @param featureId Which panel is being created.
2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         *
2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * @return view The top-level view to place in the panel.
2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         *
2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * @see #onPreparePanel
2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         */
2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        @Nullable
2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        public View onCreatePanelView(int featureId);
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        /**
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * Initialize the contents of the menu for panel 'featureId'.  This is
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * called if onCreatePanelView() returns null, giving you a standard
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * menu in which you can place your items.  It is only called once for
2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * the panel, the first time it is shown.
2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         *
2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * <p>You can safely hold on to <var>menu</var> (and any items created
2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * from it), making modifications to it as desired, until the next
2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * time onCreatePanelMenu() is called for this feature.
3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         *
3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * @param featureId The panel being created.
3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * @param menu The menu inside the panel.
3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         *
3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * @return boolean You must return true for the panel to be displayed;
3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         *         if you return false it will not be shown.
306a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)         */
3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        public boolean onCreatePanelMenu(int featureId, Menu menu);
3082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
309a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)        /**
310a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)         * Prepare a panel to be displayed.  This is called right before the
311a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)         * panel window is shown, every time it is shown.
3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         *
3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * @param featureId The panel that is being displayed.
3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * @param view The View that was returned by onCreatePanelView().
3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * @param menu If onCreatePanelView() returned null, this is the Menu
3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         *             being displayed in the panel.
31790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)         *
31890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)         * @return boolean You must return true for the panel to be displayed;
31990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)         *         if you return false it will not be shown.
320effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch         *
321effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch         * @see #onCreatePanelView
322effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch         */
323effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch        public boolean onPreparePanel(int featureId, View view, Menu menu);
324effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
325effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch        /**
326effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch         * Called when a panel's menu is opened by the user. This may also be
327a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)         * called when the menu is changing from one type to another (for
328a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)         * example, from the icon menu to the expanded menu).
329f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)         *
330f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)         * @param featureId The panel that the menu is in.
3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * @param menu The menu that is opened.
3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * @return Return true to allow the menu to open, or false to prevent
333116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         *         the menu from opening.
334116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         */
335116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        public boolean onMenuOpened(int featureId, Menu menu);
336116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
337116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        /**
338116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         * Called when a panel's menu item has been selected by the user.
339116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         *
340116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         * @param featureId The panel that the menu is in.
341116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         * @param item The menu item that was selected.
342116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         *
343116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         * @return boolean Return true to finish processing of selection, or
344116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         *         false to perform the normal menu handling (calling its
345116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         *         Runnable or sending a Message to its target Handler).
346116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         */
347116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        public boolean onMenuItemSelected(int featureId, MenuItem item);
348116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
349116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        /**
350116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         * This is called whenever the current window attributes change.
351116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         *
352116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         */
353116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        public void onWindowAttributesChanged(WindowManager.LayoutParams attrs);
354116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        /**
3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * This hook is called whenever the content view of the screen changes
3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * (due to a call to
3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * {@link Window#setContentView(View, android.view.ViewGroup.LayoutParams)
3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * Window.setContentView} or
3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * {@link Window#addContentView(View, android.view.ViewGroup.LayoutParams)
361116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         * Window.addContentView}).
362116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         */
363f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)        public void onContentChanged();
364116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
365116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        /**
366a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)         * This hook is called whenever the window focus changes.  See
367116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         * {@link View#onWindowFocusChanged(boolean)
368116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         * View.onWindowFocusChangedNotLocked(boolean)} for more information.
369116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         *
370116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         * @param hasFocus Whether the window now has focus.
3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         */
3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        public void onWindowFocusChanged(boolean hasFocus);
373f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
374116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        /**
3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * Called when the window has been attached to the window manager.
3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * See {@link View#onAttachedToWindow() View.onAttachedToWindow()}
3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * for more information.
3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         */
3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        public void onAttachedToWindow();
3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        /**
3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * Called when the window has been attached to the window manager.
3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * See {@link View#onDetachedFromWindow() View.onDetachedFromWindow()}
3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * for more information.
3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         */
3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        public void onDetachedFromWindow();
3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        /**
3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * Called when a panel is being closed.  If another logical subsequent
3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * panel is being opened (and this panel is being closed to make room for the subsequent
3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * panel), this method will NOT be called.
3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         *
3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * @param featureId The panel that is being displayed.
3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * @param menu If onCreatePanelView() returned null, this is the Menu
3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         *            being displayed in the panel.
396010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)         */
397010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        public void onPanelClosed(int featureId, Menu menu);
398010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        /**
4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * Called when the user signals the desire to start a search.
4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         *
4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * @return true if search launched, false if activity refuses (blocks)
4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         *
4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * @see android.app.Activity#onSearchRequested()
405116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         */
406116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        public boolean onSearchRequested();
407116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
408116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        /**
409116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         * Called when an action mode is being started for this window. Gives the
410116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         * callback an opportunity to handle the action mode in its own unique and
411116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         * beautiful way. If this method returns null the system can choose a way
4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * to present the mode or choose not to start the mode at all.
4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         *
414116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         * @param callback Callback to control the lifecycle of this action mode
415116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         * @return The ActionMode that was started, or null if the system should present it
416116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         */
417116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        @Nullable
418116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        public ActionMode onWindowStartingActionMode(ActionMode.Callback callback);
419116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
420116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        /**
421116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         * Called when an action mode has been started. The appropriate mode callback
422116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         * method will have already been invoked.
423116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         *
424116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         * @param mode The new mode that has just been started.
425116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         */
426116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        public void onActionModeStarted(ActionMode mode);
427116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
428116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        /**
429116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         * Called when an action mode has been finished. The appropriate mode callback
430116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         * method will have already been invoked.
4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         *
4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)         * @param mode The mode that was just finished.
433116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         */
4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        public void onActionModeFinished(ActionMode mode);
4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
436a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
437116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    /** @hide */
4381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    public interface OnWindowDismissedCallback {
439116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        /**
440a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)         * Called when a window is dismissed. This informs the callback that the
441116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         * window is gone, and it should finish itself.
442116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         */
443116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        public void onWindowDismissed();
444f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    }
445116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
446116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    public Window(Context context) {
447f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)        mContext = context;
4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        mFeatures = mLocalFeatures = getDefaultFeatures(context);
4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
451116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    /**
452116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch     * Return the Context this window policy is running in, for retrieving
453116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch     * resources and other information.
454116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch     *
455116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch     * @return Context The Context that was supplied to the constructor.
456116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch     */
4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    public final Context getContext() {
4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        return mContext;
4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
461eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    /**
462eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch     * Return the {@link android.R.styleable#Window} attributes from this
4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * window's theme.
4645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     */
4655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    public final TypedArray getWindowStyle() {
4665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        synchronized (this) {
4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            if (mWindowStyle == null) {
468eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                mWindowStyle = mContext.obtainStyledAttributes(
4695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                        com.android.internal.R.styleable.Window);
4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            }
4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            return mWindowStyle;
4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        }
4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
4745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
4755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    /**
4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * Set the container for this window.  If not set, the DecorWindow
4775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * operates as a top-level window; otherwise, it negotiates with the
478eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch     * container to display itself appropriately.
479eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch     *
480eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch     * @param container The desired containing Window.
481eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch     */
482eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    public void setContainer(Window container) {
483eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch        mContainer = container;
4842385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch        if (container != null) {
4852385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch            // Embedded screens never have a title.
4862385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch            mFeatures |= 1<<FEATURE_NO_TITLE;
4872385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch            mLocalFeatures |= 1<<FEATURE_NO_TITLE;
4882385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch            container.mHasChildren = true;
4892385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch        }
4902385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch    }
4912385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch
4922385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch    /**
4932385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch     * Return the container for this Window.
494a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)     *
495a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)     * @return Window The containing window, or null if this is a
496a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)     *         top-level window.
497a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)     */
498a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    public final Window getContainer() {
499a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        return mContainer;
500a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    }
501a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
502a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    public final boolean hasChildren() {
503a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        return mHasChildren;
504a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    }
505a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
5065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /** @hide */
5075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    public final void destroy() {
5085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        mDestroyed = true;
5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /** @hide */
5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    public final boolean isDestroyed() {
513a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)        return mDestroyed;
5145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
5155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /**
5175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * Set the window manager for use by this Window to, for example,
5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * display panels.  This is <em>not</em> used for displaying the
5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * Window itself -- that must be done by the client.
5205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     *
5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * @param wm The window manager for adding new windows.
5225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     */
5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    public void setWindowManager(WindowManager wm, IBinder appToken, String appName) {
5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        setWindowManager(wm, appToken, appName, false);
5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /**
5285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * Set the window manager for use by this Window to, for example,
5295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * display panels.  This is <em>not</em> used for displaying the
5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * Window itself -- that must be done by the client.
5315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     *
5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * @param wm The window manager for adding new windows.
5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     */
5345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    public void setWindowManager(WindowManager wm, IBinder appToken, String appName,
5355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            boolean hardwareAccelerated) {
5365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        mAppToken = appToken;
5375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        mAppName = appName;
5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        mHardwareAccelerated = hardwareAccelerated
5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                || SystemProperties.getBoolean(PROPERTY_HARDWARE_UI, false);
5405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        if (wm == null) {
5415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
5425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        }
5435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        mWindowManager = ((WindowManagerImpl)wm).createLocalWindowManager(this);
544    }
545
546    void adjustLayoutParamsForSubWindow(WindowManager.LayoutParams wp) {
547        CharSequence curTitle = wp.getTitle();
548        if (wp.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW &&
549            wp.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
550            if (wp.token == null) {
551                View decor = peekDecorView();
552                if (decor != null) {
553                    wp.token = decor.getWindowToken();
554                }
555            }
556            if (curTitle == null || curTitle.length() == 0) {
557                String title;
558                if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA) {
559                    title="Media";
560                } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY) {
561                    title="MediaOvr";
562                } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
563                    title="Panel";
564                } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL) {
565                    title="SubPanel";
566                } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG) {
567                    title="AtchDlg";
568                } else {
569                    title=Integer.toString(wp.type);
570                }
571                if (mAppName != null) {
572                    title += ":" + mAppName;
573                }
574                wp.setTitle(title);
575            }
576        } else {
577            if (wp.token == null) {
578                wp.token = mContainer == null ? mAppToken : mContainer.mAppToken;
579            }
580            if ((curTitle == null || curTitle.length() == 0)
581                    && mAppName != null) {
582                wp.setTitle(mAppName);
583            }
584        }
585        if (wp.packageName == null) {
586            wp.packageName = mContext.getPackageName();
587        }
588        if (mHardwareAccelerated) {
589            wp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
590        }
591    }
592
593    /**
594     * Return the window manager allowing this Window to display its own
595     * windows.
596     *
597     * @return WindowManager The ViewManager.
598     */
599    public WindowManager getWindowManager() {
600        return mWindowManager;
601    }
602
603    /**
604     * Set the Callback interface for this window, used to intercept key
605     * events and other dynamic operations in the window.
606     *
607     * @param callback The desired Callback interface.
608     */
609    public void setCallback(Callback callback) {
610        mCallback = callback;
611    }
612
613    /**
614     * Return the current Callback interface for this window.
615     */
616    public final Callback getCallback() {
617        return mCallback;
618    }
619
620    /** @hide */
621    public final void setOnWindowDismissedCallback(OnWindowDismissedCallback dcb) {
622        mOnWindowDismissedCallback = dcb;
623    }
624
625    /** @hide */
626    public final void dispatchOnWindowDismissed() {
627        if (mOnWindowDismissedCallback != null) {
628            mOnWindowDismissedCallback.onWindowDismissed();
629        }
630    }
631
632    /**
633     * Take ownership of this window's surface.  The window's view hierarchy
634     * will no longer draw into the surface, though it will otherwise continue
635     * to operate (such as for receiving input events).  The given SurfaceHolder
636     * callback will be used to tell you about state changes to the surface.
637     */
638    public abstract void takeSurface(SurfaceHolder.Callback2 callback);
639
640    /**
641     * Take ownership of this window's InputQueue.  The window will no
642     * longer read and dispatch input events from the queue; it is your
643     * responsibility to do so.
644     */
645    public abstract void takeInputQueue(InputQueue.Callback callback);
646
647    /**
648     * Return whether this window is being displayed with a floating style
649     * (based on the {@link android.R.attr#windowIsFloating} attribute in
650     * the style/theme).
651     *
652     * @return Returns true if the window is configured to be displayed floating
653     * on top of whatever is behind it.
654     */
655    public abstract boolean isFloating();
656
657    /**
658     * Set the width and height layout parameters of the window.  The default
659     * for both of these is MATCH_PARENT; you can change them to WRAP_CONTENT
660     * or an absolute value to make a window that is not full-screen.
661     *
662     * @param width The desired layout width of the window.
663     * @param height The desired layout height of the window.
664     *
665     * @see ViewGroup.LayoutParams#height
666     * @see ViewGroup.LayoutParams#width
667     */
668    public void setLayout(int width, int height) {
669        final WindowManager.LayoutParams attrs = getAttributes();
670        attrs.width = width;
671        attrs.height = height;
672        dispatchWindowAttributesChanged(attrs);
673    }
674
675    /**
676     * Set the gravity of the window, as per the Gravity constants.  This
677     * controls how the window manager is positioned in the overall window; it
678     * is only useful when using WRAP_CONTENT for the layout width or height.
679     *
680     * @param gravity The desired gravity constant.
681     *
682     * @see Gravity
683     * @see #setLayout
684     */
685    public void setGravity(int gravity)
686    {
687        final WindowManager.LayoutParams attrs = getAttributes();
688        attrs.gravity = gravity;
689        dispatchWindowAttributesChanged(attrs);
690    }
691
692    /**
693     * Set the type of the window, as per the WindowManager.LayoutParams
694     * types.
695     *
696     * @param type The new window type (see WindowManager.LayoutParams).
697     */
698    public void setType(int type) {
699        final WindowManager.LayoutParams attrs = getAttributes();
700        attrs.type = type;
701        dispatchWindowAttributesChanged(attrs);
702    }
703
704    /**
705     * Set the format of window, as per the PixelFormat types.  This overrides
706     * the default format that is selected by the Window based on its
707     * window decorations.
708     *
709     * @param format The new window format (see PixelFormat).  Use
710     *               PixelFormat.UNKNOWN to allow the Window to select
711     *               the format.
712     *
713     * @see PixelFormat
714     */
715    public void setFormat(int format) {
716        final WindowManager.LayoutParams attrs = getAttributes();
717        if (format != PixelFormat.UNKNOWN) {
718            attrs.format = format;
719            mHaveWindowFormat = true;
720        } else {
721            attrs.format = mDefaultWindowFormat;
722            mHaveWindowFormat = false;
723        }
724        dispatchWindowAttributesChanged(attrs);
725    }
726
727    /**
728     * Specify custom animations to use for the window, as per
729     * {@link WindowManager.LayoutParams#windowAnimations
730     * WindowManager.LayoutParams.windowAnimations}.  Providing anything besides
731     * 0 here will override the animations the window would
732     * normally retrieve from its theme.
733     */
734    public void setWindowAnimations(int resId) {
735        final WindowManager.LayoutParams attrs = getAttributes();
736        attrs.windowAnimations = resId;
737        dispatchWindowAttributesChanged(attrs);
738    }
739
740    /**
741     * Specify an explicit soft input mode to use for the window, as per
742     * {@link WindowManager.LayoutParams#softInputMode
743     * WindowManager.LayoutParams.softInputMode}.  Providing anything besides
744     * "unspecified" here will override the input mode the window would
745     * normally retrieve from its theme.
746     */
747    public void setSoftInputMode(int mode) {
748        final WindowManager.LayoutParams attrs = getAttributes();
749        if (mode != WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED) {
750            attrs.softInputMode = mode;
751            mHasSoftInputMode = true;
752        } else {
753            mHasSoftInputMode = false;
754        }
755        dispatchWindowAttributesChanged(attrs);
756    }
757
758    /**
759     * Convenience function to set the flag bits as specified in flags, as
760     * per {@link #setFlags}.
761     * @param flags The flag bits to be set.
762     * @see #setFlags
763     * @see #clearFlags
764     */
765    public void addFlags(int flags) {
766        setFlags(flags, flags);
767    }
768
769    /** @hide */
770    public void addPrivateFlags(int flags) {
771        setPrivateFlags(flags, flags);
772    }
773
774    /**
775     * Convenience function to clear the flag bits as specified in flags, as
776     * per {@link #setFlags}.
777     * @param flags The flag bits to be cleared.
778     * @see #setFlags
779     * @see #addFlags
780     */
781    public void clearFlags(int flags) {
782        setFlags(0, flags);
783    }
784
785    /**
786     * Set the flags of the window, as per the
787     * {@link WindowManager.LayoutParams WindowManager.LayoutParams}
788     * flags.
789     *
790     * <p>Note that some flags must be set before the window decoration is
791     * created (by the first call to
792     * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)} or
793     * {@link #getDecorView()}:
794     * {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN} and
795     * {@link WindowManager.LayoutParams#FLAG_LAYOUT_INSET_DECOR}.  These
796     * will be set for you based on the {@link android.R.attr#windowIsFloating}
797     * attribute.
798     *
799     * @param flags The new window flags (see WindowManager.LayoutParams).
800     * @param mask Which of the window flag bits to modify.
801     * @see #addFlags
802     * @see #clearFlags
803     */
804    public void setFlags(int flags, int mask) {
805        final WindowManager.LayoutParams attrs = getAttributes();
806        attrs.flags = (attrs.flags&~mask) | (flags&mask);
807        mForcedWindowFlags |= mask;
808        dispatchWindowAttributesChanged(attrs);
809    }
810
811    private void setPrivateFlags(int flags, int mask) {
812        final WindowManager.LayoutParams attrs = getAttributes();
813        attrs.privateFlags = (attrs.privateFlags & ~mask) | (flags & mask);
814        dispatchWindowAttributesChanged(attrs);
815    }
816
817    /**
818     * {@hide}
819     */
820    protected void setNeedsMenuKey(int value) {
821        final WindowManager.LayoutParams attrs = getAttributes();
822        attrs.needsMenuKey = value;
823        dispatchWindowAttributesChanged(attrs);
824    }
825
826    /**
827     * {@hide}
828     */
829    protected void dispatchWindowAttributesChanged(WindowManager.LayoutParams attrs) {
830        if (mCallback != null) {
831            mCallback.onWindowAttributesChanged(attrs);
832        }
833    }
834
835    /**
836     * Set the amount of dim behind the window when using
837     * {@link WindowManager.LayoutParams#FLAG_DIM_BEHIND}.  This overrides
838     * the default dim amount of that is selected by the Window based on
839     * its theme.
840     *
841     * @param amount The new dim amount, from 0 for no dim to 1 for full dim.
842     */
843    public void setDimAmount(float amount) {
844        final WindowManager.LayoutParams attrs = getAttributes();
845        attrs.dimAmount = amount;
846        mHaveDimAmount = true;
847        dispatchWindowAttributesChanged(attrs);
848    }
849
850    /**
851     * Specify custom window attributes.  <strong>PLEASE NOTE:</strong> the
852     * layout params you give here should generally be from values previously
853     * retrieved with {@link #getAttributes()}; you probably do not want to
854     * blindly create and apply your own, since this will blow away any values
855     * set by the framework that you are not interested in.
856     *
857     * @param a The new window attributes, which will completely override any
858     *          current values.
859     */
860    public void setAttributes(WindowManager.LayoutParams a) {
861        mWindowAttributes.copyFrom(a);
862        dispatchWindowAttributesChanged(mWindowAttributes);
863    }
864
865    /**
866     * Retrieve the current window attributes associated with this panel.
867     *
868     * @return WindowManager.LayoutParams Either the existing window
869     *         attributes object, or a freshly created one if there is none.
870     */
871    public final WindowManager.LayoutParams getAttributes() {
872        return mWindowAttributes;
873    }
874
875    /**
876     * Return the window flags that have been explicitly set by the client,
877     * so will not be modified by {@link #getDecorView}.
878     */
879    protected final int getForcedWindowFlags() {
880        return mForcedWindowFlags;
881    }
882
883    /**
884     * Has the app specified their own soft input mode?
885     */
886    protected final boolean hasSoftInputMode() {
887        return mHasSoftInputMode;
888    }
889
890    /** @hide */
891    public void setCloseOnTouchOutside(boolean close) {
892        mCloseOnTouchOutside = close;
893        mSetCloseOnTouchOutside = true;
894    }
895
896    /** @hide */
897    public void setCloseOnTouchOutsideIfNotSet(boolean close) {
898        if (!mSetCloseOnTouchOutside) {
899            mCloseOnTouchOutside = close;
900            mSetCloseOnTouchOutside = true;
901        }
902    }
903
904    /** @hide */
905    @SystemApi
906    public void setDisableWallpaperTouchEvents(boolean disable) {
907        setPrivateFlags(disable
908                ? WindowManager.LayoutParams.PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS : 0,
909                WindowManager.LayoutParams.PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS);
910    }
911
912    /** @hide */
913    public abstract void alwaysReadCloseOnTouchAttr();
914
915    /** @hide */
916    public boolean shouldCloseOnTouch(Context context, MotionEvent event) {
917        if (mCloseOnTouchOutside && event.getAction() == MotionEvent.ACTION_DOWN
918                && isOutOfBounds(context, event) && peekDecorView() != null) {
919            return true;
920        }
921        return false;
922    }
923
924    private boolean isOutOfBounds(Context context, MotionEvent event) {
925        final int x = (int) event.getX();
926        final int y = (int) event.getY();
927        final int slop = ViewConfiguration.get(context).getScaledWindowTouchSlop();
928        final View decorView = getDecorView();
929        return (x < -slop) || (y < -slop)
930                || (x > (decorView.getWidth()+slop))
931                || (y > (decorView.getHeight()+slop));
932    }
933
934    /**
935     * Enable extended screen features.  This must be called before
936     * setContentView().  May be called as many times as desired as long as it
937     * is before setContentView().  If not called, no extended features
938     * will be available.  You can not turn off a feature once it is requested.
939     * You canot use other title features with {@link #FEATURE_CUSTOM_TITLE}.
940     *
941     * @param featureId The desired features, defined as constants by Window.
942     * @return The features that are now set.
943     */
944    public boolean requestFeature(int featureId) {
945        final int flag = 1<<featureId;
946        mFeatures |= flag;
947        mLocalFeatures |= mContainer != null ? (flag&~mContainer.mFeatures) : flag;
948        return (mFeatures&flag) != 0;
949    }
950
951    /**
952     * @hide Used internally to help resolve conflicting features.
953     */
954    protected void removeFeature(int featureId) {
955        final int flag = 1<<featureId;
956        mFeatures &= ~flag;
957        mLocalFeatures &= ~(mContainer != null ? (flag&~mContainer.mFeatures) : flag);
958    }
959
960    public final void makeActive() {
961        if (mContainer != null) {
962            if (mContainer.mActiveChild != null) {
963                mContainer.mActiveChild.mIsActive = false;
964            }
965            mContainer.mActiveChild = this;
966        }
967        mIsActive = true;
968        onActive();
969    }
970
971    public final boolean isActive()
972    {
973        return mIsActive;
974    }
975
976    /**
977     * Finds a view that was identified by the id attribute from the XML that
978     * was processed in {@link android.app.Activity#onCreate}.  This will
979     * implicitly call {@link #getDecorView} for you, with all of the
980     * associated side-effects.
981     *
982     * @return The view if found or null otherwise.
983     */
984    public View findViewById(int id) {
985        return getDecorView().findViewById(id);
986    }
987
988    /**
989     * Convenience for
990     * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}
991     * to set the screen content from a layout resource.  The resource will be
992     * inflated, adding all top-level views to the screen.
993     *
994     * @param layoutResID Resource ID to be inflated.
995     * @see #setContentView(View, android.view.ViewGroup.LayoutParams)
996     */
997    public abstract void setContentView(int layoutResID);
998
999    /**
1000     * Convenience for
1001     * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}
1002     * set the screen content to an explicit view.  This view is placed
1003     * directly into the screen's view hierarchy.  It can itself be a complex
1004     * view hierarhcy.
1005     *
1006     * @param view The desired content to display.
1007     * @see #setContentView(View, android.view.ViewGroup.LayoutParams)
1008     */
1009    public abstract void setContentView(View view);
1010
1011    /**
1012     * Set the screen content to an explicit view.  This view is placed
1013     * directly into the screen's view hierarchy.  It can itself be a complex
1014     * view hierarchy.
1015     *
1016     * <p>Note that calling this function "locks in" various characteristics
1017     * of the window that can not, from this point forward, be changed: the
1018     * features that have been requested with {@link #requestFeature(int)},
1019     * and certain window flags as described in {@link #setFlags(int, int)}.
1020     *
1021     * @param view The desired content to display.
1022     * @param params Layout parameters for the view.
1023     */
1024    public abstract void setContentView(View view, ViewGroup.LayoutParams params);
1025
1026    /**
1027     * Variation on
1028     * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}
1029     * to add an additional content view to the screen.  Added after any existing
1030     * ones in the screen -- existing views are NOT removed.
1031     *
1032     * @param view The desired content to display.
1033     * @param params Layout parameters for the view.
1034     */
1035    public abstract void addContentView(View view, ViewGroup.LayoutParams params);
1036
1037    /**
1038     * Return the view in this Window that currently has focus, or null if
1039     * there are none.  Note that this does not look in any containing
1040     * Window.
1041     *
1042     * @return View The current View with focus or null.
1043     */
1044    @Nullable
1045    public abstract View getCurrentFocus();
1046
1047    /**
1048     * Quick access to the {@link LayoutInflater} instance that this Window
1049     * retrieved from its Context.
1050     *
1051     * @return LayoutInflater The shared LayoutInflater.
1052     */
1053    @NonNull
1054    public abstract LayoutInflater getLayoutInflater();
1055
1056    public abstract void setTitle(CharSequence title);
1057
1058    @Deprecated
1059    public abstract void setTitleColor(int textColor);
1060
1061    public abstract void openPanel(int featureId, KeyEvent event);
1062
1063    public abstract void closePanel(int featureId);
1064
1065    public abstract void togglePanel(int featureId, KeyEvent event);
1066
1067    public abstract void invalidatePanelMenu(int featureId);
1068
1069    public abstract boolean performPanelShortcut(int featureId,
1070                                                 int keyCode,
1071                                                 KeyEvent event,
1072                                                 int flags);
1073    public abstract boolean performPanelIdentifierAction(int featureId,
1074                                                 int id,
1075                                                 int flags);
1076
1077    public abstract void closeAllPanels();
1078
1079    public abstract boolean performContextMenuIdentifierAction(int id, int flags);
1080
1081    /**
1082     * Should be called when the configuration is changed.
1083     *
1084     * @param newConfig The new configuration.
1085     */
1086    public abstract void onConfigurationChanged(Configuration newConfig);
1087
1088    /**
1089     * Sets the window elevation.
1090     *
1091     * @param elevation The window elevation.
1092     * @see View#setElevation(float)
1093     * @see android.R.styleable#Window_windowElevation
1094     */
1095    public void setElevation(float elevation) {}
1096
1097    /**
1098     * Sets whether window content should be clipped to the outline of the
1099     * window background.
1100     *
1101     * @param clipToOutline Whether window content should be clipped to the
1102     *                      outline of the window background.
1103     * @see View#setClipToOutline(boolean)
1104     * @see android.R.styleable#Window_windowClipToOutline
1105     */
1106    public void setClipToOutline(boolean clipToOutline) {}
1107
1108    /**
1109     * Change the background of this window to a Drawable resource. Setting the
1110     * background to null will make the window be opaque. To make the window
1111     * transparent, you can use an empty drawable (for instance a ColorDrawable
1112     * with the color 0 or the system drawable android:drawable/empty.)
1113     *
1114     * @param resId The resource identifier of a drawable resource which will
1115     *              be installed as the new background.
1116     */
1117    public void setBackgroundDrawableResource(int resId) {
1118        setBackgroundDrawable(mContext.getDrawable(resId));
1119    }
1120
1121    /**
1122     * Change the background of this window to a custom Drawable. Setting the
1123     * background to null will make the window be opaque. To make the window
1124     * transparent, you can use an empty drawable (for instance a ColorDrawable
1125     * with the color 0 or the system drawable android:drawable/empty.)
1126     *
1127     * @param drawable The new Drawable to use for this window's background.
1128     */
1129    public abstract void setBackgroundDrawable(Drawable drawable);
1130
1131    /**
1132     * Set the value for a drawable feature of this window, from a resource
1133     * identifier.  You must have called requestFeauture(featureId) before
1134     * calling this function.
1135     *
1136     * @see android.content.res.Resources#getDrawable(int)
1137     *
1138     * @param featureId The desired drawable feature to change, defined as a
1139     * constant by Window.
1140     * @param resId Resource identifier of the desired image.
1141     */
1142    public abstract void setFeatureDrawableResource(int featureId, int resId);
1143
1144    /**
1145     * Set the value for a drawable feature of this window, from a URI. You
1146     * must have called requestFeature(featureId) before calling this
1147     * function.
1148     *
1149     * <p>The only URI currently supported is "content:", specifying an image
1150     * in a content provider.
1151     *
1152     * @see android.widget.ImageView#setImageURI
1153     *
1154     * @param featureId The desired drawable feature to change. Features are
1155     * constants defined by Window.
1156     * @param uri The desired URI.
1157     */
1158    public abstract void setFeatureDrawableUri(int featureId, Uri uri);
1159
1160    /**
1161     * Set an explicit Drawable value for feature of this window. You must
1162     * have called requestFeature(featureId) before calling this function.
1163     *
1164     * @param featureId The desired drawable feature to change. Features are
1165     *                  constants defined by Window.
1166     * @param drawable A Drawable object to display.
1167     */
1168    public abstract void setFeatureDrawable(int featureId, Drawable drawable);
1169
1170    /**
1171     * Set a custom alpha value for the given drawable feature, controlling how
1172     * much the background is visible through it.
1173     *
1174     * @param featureId The desired drawable feature to change. Features are
1175     *                  constants defined by Window.
1176     * @param alpha The alpha amount, 0 is completely transparent and 255 is
1177     *              completely opaque.
1178     */
1179    public abstract void setFeatureDrawableAlpha(int featureId, int alpha);
1180
1181    /**
1182     * Set the integer value for a feature. The range of the value depends on
1183     * the feature being set. For {@link #FEATURE_PROGRESS}, it should go from
1184     * 0 to 10000. At 10000 the progress is complete and the indicator hidden.
1185     *
1186     * @param featureId The desired feature to change. Features are constants
1187     *                  defined by Window.
1188     * @param value The value for the feature. The interpretation of this
1189     *              value is feature-specific.
1190     */
1191    public abstract void setFeatureInt(int featureId, int value);
1192
1193    /**
1194     * Request that key events come to this activity. Use this if your
1195     * activity has no views with focus, but the activity still wants
1196     * a chance to process key events.
1197     */
1198    public abstract void takeKeyEvents(boolean get);
1199
1200    /**
1201     * Used by custom windows, such as Dialog, to pass the key press event
1202     * further down the view hierarchy. Application developers should
1203     * not need to implement or call this.
1204     *
1205     */
1206    public abstract boolean superDispatchKeyEvent(KeyEvent event);
1207
1208    /**
1209     * Used by custom windows, such as Dialog, to pass the key shortcut press event
1210     * further down the view hierarchy. Application developers should
1211     * not need to implement or call this.
1212     *
1213     */
1214    public abstract boolean superDispatchKeyShortcutEvent(KeyEvent event);
1215
1216    /**
1217     * Used by custom windows, such as Dialog, to pass the touch screen event
1218     * further down the view hierarchy. Application developers should
1219     * not need to implement or call this.
1220     *
1221     */
1222    public abstract boolean superDispatchTouchEvent(MotionEvent event);
1223
1224    /**
1225     * Used by custom windows, such as Dialog, to pass the trackball event
1226     * further down the view hierarchy. Application developers should
1227     * not need to implement or call this.
1228     *
1229     */
1230    public abstract boolean superDispatchTrackballEvent(MotionEvent event);
1231
1232    /**
1233     * Used by custom windows, such as Dialog, to pass the generic motion event
1234     * further down the view hierarchy. Application developers should
1235     * not need to implement or call this.
1236     *
1237     */
1238    public abstract boolean superDispatchGenericMotionEvent(MotionEvent event);
1239
1240    /**
1241     * Retrieve the top-level window decor view (containing the standard
1242     * window frame/decorations and the client's content inside of that), which
1243     * can be added as a window to the window manager.
1244     *
1245     * <p><em>Note that calling this function for the first time "locks in"
1246     * various window characteristics as described in
1247     * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}.</em></p>
1248     *
1249     * @return Returns the top-level window decor view.
1250     */
1251    public abstract View getDecorView();
1252
1253    /**
1254     * Retrieve the current decor view, but only if it has already been created;
1255     * otherwise returns null.
1256     *
1257     * @return Returns the top-level window decor or null.
1258     * @see #getDecorView
1259     */
1260    public abstract View peekDecorView();
1261
1262    public abstract Bundle saveHierarchyState();
1263
1264    public abstract void restoreHierarchyState(Bundle savedInstanceState);
1265
1266    protected abstract void onActive();
1267
1268    /**
1269     * Return the feature bits that are enabled.  This is the set of features
1270     * that were given to requestFeature(), and are being handled by this
1271     * Window itself or its container.  That is, it is the set of
1272     * requested features that you can actually use.
1273     *
1274     * <p>To do: add a public version of this API that allows you to check for
1275     * features by their feature ID.
1276     *
1277     * @return int The feature bits.
1278     */
1279    protected final int getFeatures()
1280    {
1281        return mFeatures;
1282    }
1283
1284    /**
1285     * Return the feature bits set by default on a window.
1286     * @param context The context used to access resources
1287     */
1288    public static int getDefaultFeatures(Context context) {
1289        int features = 0;
1290
1291        final Resources res = context.getResources();
1292        if (res.getBoolean(com.android.internal.R.bool.config_defaultWindowFeatureOptionsPanel)) {
1293            features |= 1 << FEATURE_OPTIONS_PANEL;
1294        }
1295
1296        if (res.getBoolean(com.android.internal.R.bool.config_defaultWindowFeatureContextMenu)) {
1297            features |= 1 << FEATURE_CONTEXT_MENU;
1298        }
1299
1300        return features;
1301    }
1302
1303    /**
1304     * Query for the availability of a certain feature.
1305     *
1306     * @param feature The feature ID to check
1307     * @return true if the feature is enabled, false otherwise.
1308     */
1309    public boolean hasFeature(int feature) {
1310        return (getFeatures() & (1 << feature)) != 0;
1311    }
1312
1313    /**
1314     * Return the feature bits that are being implemented by this Window.
1315     * This is the set of features that were given to requestFeature(), and are
1316     * being handled by only this Window itself, not by its containers.
1317     *
1318     * @return int The feature bits.
1319     */
1320    protected final int getLocalFeatures()
1321    {
1322        return mLocalFeatures;
1323    }
1324
1325    /**
1326     * Set the default format of window, as per the PixelFormat types.  This
1327     * is the format that will be used unless the client specifies in explicit
1328     * format with setFormat();
1329     *
1330     * @param format The new window format (see PixelFormat).
1331     *
1332     * @see #setFormat
1333     * @see PixelFormat
1334     */
1335    protected void setDefaultWindowFormat(int format) {
1336        mDefaultWindowFormat = format;
1337        if (!mHaveWindowFormat) {
1338            final WindowManager.LayoutParams attrs = getAttributes();
1339            attrs.format = format;
1340            dispatchWindowAttributesChanged(attrs);
1341        }
1342    }
1343
1344    /** @hide */
1345    protected boolean haveDimAmount() {
1346        return mHaveDimAmount;
1347    }
1348
1349    public abstract void setChildDrawable(int featureId, Drawable drawable);
1350
1351    public abstract void setChildInt(int featureId, int value);
1352
1353    /**
1354     * Is a keypress one of the defined shortcut keys for this window.
1355     * @param keyCode the key code from {@link android.view.KeyEvent} to check.
1356     * @param event the {@link android.view.KeyEvent} to use to help check.
1357     */
1358    public abstract boolean isShortcutKey(int keyCode, KeyEvent event);
1359
1360    /**
1361     * @see android.app.Activity#setVolumeControlStream(int)
1362     */
1363    public abstract void setVolumeControlStream(int streamType);
1364
1365    /**
1366     * @see android.app.Activity#getVolumeControlStream()
1367     */
1368    public abstract int getVolumeControlStream();
1369
1370    /**
1371     * Sets a {@link MediaController} to send media keys and volume changes to.
1372     * If set, this should be preferred for all media keys and volume requests
1373     * sent to this window.
1374     *
1375     * @param controller The controller for the session which should receive
1376     *            media keys and volume changes.
1377     * @see android.app.Activity#setMediaController(android.media.session.MediaController)
1378     */
1379    public void setMediaController(MediaController controller) {
1380    }
1381
1382    /**
1383     * Gets the {@link MediaController} that was previously set.
1384     *
1385     * @return The controller which should receive events.
1386     * @see #setMediaController(android.media.session.MediaController)
1387     * @see android.app.Activity#getMediaController()
1388     */
1389    public MediaController getMediaController() {
1390        return null;
1391    }
1392
1393    /**
1394     * Set extra options that will influence the UI for this window.
1395     * @param uiOptions Flags specifying extra options for this window.
1396     */
1397    public void setUiOptions(int uiOptions) { }
1398
1399    /**
1400     * Set extra options that will influence the UI for this window.
1401     * Only the bits filtered by mask will be modified.
1402     * @param uiOptions Flags specifying extra options for this window.
1403     * @param mask Flags specifying which options should be modified. Others will remain unchanged.
1404     */
1405    public void setUiOptions(int uiOptions, int mask) { }
1406
1407    /**
1408     * Set the primary icon for this window.
1409     *
1410     * @param resId resource ID of a drawable to set
1411     */
1412    public void setIcon(int resId) { }
1413
1414    /**
1415     * Set the default icon for this window.
1416     * This will be overridden by any other icon set operation which could come from the
1417     * theme or another explicit set.
1418     *
1419     * @hide
1420     */
1421    public void setDefaultIcon(int resId) { }
1422
1423    /**
1424     * Set the logo for this window. A logo is often shown in place of an
1425     * {@link #setIcon(int) icon} but is generally wider and communicates window title information
1426     * as well.
1427     *
1428     * @param resId resource ID of a drawable to set
1429     */
1430    public void setLogo(int resId) { }
1431
1432    /**
1433     * Set the default logo for this window.
1434     * This will be overridden by any other logo set operation which could come from the
1435     * theme or another explicit set.
1436     *
1437     * @hide
1438     */
1439    public void setDefaultLogo(int resId) { }
1440
1441    /**
1442     * Set focus locally. The window should have the
1443     * {@link WindowManager.LayoutParams#FLAG_LOCAL_FOCUS_MODE} flag set already.
1444     * @param hasFocus Whether this window has focus or not.
1445     * @param inTouchMode Whether this window is in touch mode or not.
1446     */
1447    public void setLocalFocus(boolean hasFocus, boolean inTouchMode) { }
1448
1449    /**
1450     * Inject an event to window locally.
1451     * @param event A key or touch event to inject to this window.
1452     */
1453    public void injectInputEvent(InputEvent event) { }
1454
1455    /**
1456     * Retrieve the {@link TransitionManager} responsible for  for default transitions
1457     * in this window. Requires {@link #FEATURE_CONTENT_TRANSITIONS}.
1458     *
1459     * <p>This method will return non-null after content has been initialized (e.g. by using
1460     * {@link #setContentView}) if {@link #FEATURE_CONTENT_TRANSITIONS} has been granted.</p>
1461     *
1462     * @return This window's content TransitionManager or null if none is set.
1463     */
1464    public TransitionManager getTransitionManager() {
1465        return null;
1466    }
1467
1468    /**
1469     * Set the {@link TransitionManager} to use for default transitions in this window.
1470     * Requires {@link #FEATURE_CONTENT_TRANSITIONS}.
1471     *
1472     * @param tm The TransitionManager to use for scene changes.
1473     */
1474    public void setTransitionManager(TransitionManager tm) {
1475        throw new UnsupportedOperationException();
1476    }
1477
1478    /**
1479     * Retrieve the {@link Scene} representing this window's current content.
1480     * Requires {@link #FEATURE_CONTENT_TRANSITIONS}.
1481     *
1482     * <p>This method will return null if the current content is not represented by a Scene.</p>
1483     *
1484     * @return Current Scene being shown or null
1485     */
1486    public Scene getContentScene() {
1487        return null;
1488    }
1489
1490    /**
1491     * Sets the Transition that will be used to move Views into the initial scene. The entering
1492     * Views will be those that are regular Views or ViewGroups that have
1493     * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
1494     * {@link android.transition.Visibility} as entering is governed by changing visibility from
1495     * {@link View#INVISIBLE} to {@link View#VISIBLE}. If <code>transition</code> is null,
1496     * entering Views will remain unaffected.
1497     *
1498     * @param transition The Transition to use to move Views into the initial Scene.
1499     * @attr ref android.R.styleable#Window_windowEnterTransition
1500     */
1501    public void setEnterTransition(Transition transition) {}
1502
1503    /**
1504     * Sets the Transition that will be used to move Views out of the scene when the Window is
1505     * preparing to close, for example after a call to
1506     * {@link android.app.Activity#finishAfterTransition()}. The exiting
1507     * Views will be those that are regular Views or ViewGroups that have
1508     * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
1509     * {@link android.transition.Visibility} as entering is governed by changing visibility from
1510     * {@link View#VISIBLE} to {@link View#INVISIBLE}. If <code>transition</code> is null,
1511     * entering Views will remain unaffected. If nothing is set, the default will be to
1512     * use the same value as set in {@link #setEnterTransition(android.transition.Transition)}.
1513     *
1514     * @param transition The Transition to use to move Views out of the Scene when the Window
1515     *                   is preparing to close.
1516     * @attr ref android.R.styleable#Window_windowReturnTransition
1517     */
1518    public void setReturnTransition(Transition transition) {}
1519
1520    /**
1521     * Sets the Transition that will be used to move Views out of the scene when starting a
1522     * new Activity. The exiting Views will be those that are regular Views or ViewGroups that
1523     * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
1524     * {@link android.transition.Visibility} as exiting is governed by changing visibility
1525     * from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, the views will
1526     * remain unaffected. Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1527     *
1528     * @param transition The Transition to use to move Views out of the scene when calling a
1529     *                   new Activity.
1530     * @attr ref android.R.styleable#Window_windowExitTransition
1531     */
1532    public void setExitTransition(Transition transition) {}
1533
1534    /**
1535     * Sets the Transition that will be used to move Views in to the scene when returning from
1536     * a previously-started Activity. The entering Views will be those that are regular Views
1537     * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions
1538     * will extend {@link android.transition.Visibility} as exiting is governed by changing
1539     * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null,
1540     * the views will remain unaffected. If nothing is set, the default will be to use the same
1541     * transition as {@link #setExitTransition(android.transition.Transition)}.
1542     * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1543     *
1544     * @param transition The Transition to use to move Views into the scene when reentering from a
1545     *                   previously-started Activity.
1546     * @attr ref android.R.styleable#Window_windowReenterTransition
1547     */
1548    public void setReenterTransition(Transition transition) {}
1549
1550    /**
1551     * Returns the transition used to move Views into the initial scene. The entering
1552     * Views will be those that are regular Views or ViewGroups that have
1553     * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
1554     * {@link android.transition.Visibility} as entering is governed by changing visibility from
1555     * {@link View#INVISIBLE} to {@link View#VISIBLE}. If <code>transition</code> is null,
1556     * entering Views will remain unaffected.  Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1557     *
1558     * @return the Transition to use to move Views into the initial Scene.
1559     * @attr ref android.R.styleable#Window_windowEnterTransition
1560     */
1561    public Transition getEnterTransition() { return null; }
1562
1563    /**
1564     * Returns he Transition that will be used to move Views out of the scene when the Window is
1565     * preparing to close, for example after a call to
1566     * {@link android.app.Activity#finishAfterTransition()}. The exiting
1567     * Views will be those that are regular Views or ViewGroups that have
1568     * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
1569     * {@link android.transition.Visibility} as entering is governed by changing visibility from
1570     * {@link View#VISIBLE} to {@link View#INVISIBLE}.
1571     *
1572     * @return The Transition to use to move Views out of the Scene when the Window
1573     *         is preparing to close.
1574     * @attr ref android.R.styleable#Window_windowReturnTransition
1575     */
1576    public Transition getReturnTransition() { return null; }
1577
1578    /**
1579     * Returns the Transition that will be used to move Views out of the scene when starting a
1580     * new Activity. The exiting Views will be those that are regular Views or ViewGroups that
1581     * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
1582     * {@link android.transition.Visibility} as exiting is governed by changing visibility
1583     * from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, the views will
1584     * remain unaffected. Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1585     *
1586     * @return the Transition to use to move Views out of the scene when calling a
1587     * new Activity.
1588     * @attr ref android.R.styleable#Window_windowExitTransition
1589     */
1590    public Transition getExitTransition() { return null; }
1591
1592    /**
1593     * Returns the Transition that will be used to move Views in to the scene when returning from
1594     * a previously-started Activity. The entering Views will be those that are regular Views
1595     * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions
1596     * will extend {@link android.transition.Visibility} as exiting is governed by changing
1597     * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}.
1598     * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1599     *
1600     * @return The Transition to use to move Views into the scene when reentering from a
1601     *         previously-started Activity.
1602     * @attr ref android.R.styleable#Window_windowReenterTransition
1603     */
1604    public Transition getReenterTransition() { return null; }
1605
1606    /**
1607     * Sets the Transition that will be used for shared elements transferred into the content
1608     * Scene. Typical Transitions will affect size and location, such as
1609     * {@link android.transition.ChangeBounds}. A null
1610     * value will cause transferred shared elements to blink to the final position.
1611     * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1612     *
1613     * @param transition The Transition to use for shared elements transferred into the content
1614     *                   Scene.
1615     * @attr ref android.R.styleable#Window_windowSharedElementEnterTransition
1616     */
1617    public void setSharedElementEnterTransition(Transition transition) {}
1618
1619    /**
1620     * Sets the Transition that will be used for shared elements transferred back to a
1621     * calling Activity. Typical Transitions will affect size and location, such as
1622     * {@link android.transition.ChangeBounds}. A null
1623     * value will cause transferred shared elements to blink to the final position.
1624     * If no value is set, the default will be to use the same value as
1625     * {@link #setSharedElementEnterTransition(android.transition.Transition)}.
1626     * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1627     *
1628     * @param transition The Transition to use for shared elements transferred out of the content
1629     *                   Scene.
1630     * @attr ref android.R.styleable#Window_windowSharedElementReturnTransition
1631     */
1632    public void setSharedElementReturnTransition(Transition transition) {}
1633
1634    /**
1635     * Returns the Transition that will be used for shared elements transferred into the content
1636     * Scene. Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1637     *
1638     * @return Transition to use for sharend elements transferred into the content Scene.
1639     * @attr ref android.R.styleable#Window_windowSharedElementEnterTransition
1640     */
1641    public Transition getSharedElementEnterTransition() { return null; }
1642
1643    /**
1644     * Returns the Transition that will be used for shared elements transferred back to a
1645     * calling Activity. Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1646     *
1647     * @return Transition to use for sharend elements transferred into the content Scene.
1648     * @attr ref android.R.styleable#Window_windowSharedElementReturnTransition
1649     */
1650    public Transition getSharedElementReturnTransition() { return null; }
1651
1652    /**
1653     * Sets the Transition that will be used for shared elements after starting a new Activity
1654     * before the shared elements are transferred to the called Activity. If the shared elements
1655     * must animate during the exit transition, this Transition should be used. Upon completion,
1656     * the shared elements may be transferred to the started Activity.
1657     * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1658     *
1659     * @param transition The Transition to use for shared elements in the launching Window
1660     *                   prior to transferring to the launched Activity's Window.
1661     * @attr ref android.R.styleable#Window_windowSharedElementExitTransition
1662     */
1663    public void setSharedElementExitTransition(Transition transition) {}
1664
1665    /**
1666     * Sets the Transition that will be used for shared elements reentering from a started
1667     * Activity after it has returned the shared element to it start location. If no value
1668     * is set, this will default to
1669     * {@link #setSharedElementExitTransition(android.transition.Transition)}.
1670     * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1671     *
1672     * @param transition The Transition to use for shared elements in the launching Window
1673     *                   after the shared element has returned to the Window.
1674     * @attr ref android.R.styleable#Window_windowSharedElementReenterTransition
1675     */
1676    public void setSharedElementReenterTransition(Transition transition) {}
1677
1678    /**
1679     * Returns the Transition to use for shared elements in the launching Window prior
1680     * to transferring to the launched Activity's Window.
1681     * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1682     *
1683     * @return the Transition to use for shared elements in the launching Window prior
1684     * to transferring to the launched Activity's Window.
1685     * @attr ref android.R.styleable#Window_windowSharedElementExitTransition
1686     */
1687    public Transition getSharedElementExitTransition() { return null; }
1688
1689    /**
1690     * Returns the Transition that will be used for shared elements reentering from a started
1691     * Activity after it has returned the shared element to it start location.
1692     * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
1693     *
1694     * @return the Transition that will be used for shared elements reentering from a started
1695     * Activity after it has returned the shared element to it start location.
1696     * @attr ref android.R.styleable#Window_windowSharedElementReenterTransition
1697     */
1698    public Transition getSharedElementReenterTransition() { return null; }
1699
1700    /**
1701     * Controls how the transition set in
1702     * {@link #setEnterTransition(android.transition.Transition)} overlaps with the exit
1703     * transition of the calling Activity. When true, the transition will start as soon as possible.
1704     * When false, the transition will wait until the remote exiting transition completes before
1705     * starting.
1706     *
1707     * @param allow true to start the enter transition when possible or false to
1708     *              wait until the exiting transition completes.
1709     * @attr ref android.R.styleable#Window_windowAllowEnterTransitionOverlap
1710     */
1711    public void setAllowEnterTransitionOverlap(boolean allow) {}
1712
1713    /**
1714     * Returns how the transition set in
1715     * {@link #setEnterTransition(android.transition.Transition)} overlaps with the exit
1716     * transition of the calling Activity. When true, the transition will start as soon as possible.
1717     * When false, the transition will wait until the remote exiting transition completes before
1718     * starting.
1719     *
1720     * @return true when the enter transition should start as soon as possible or false to
1721     * when it should wait until the exiting transition completes.
1722     * @attr ref android.R.styleable#Window_windowAllowEnterTransitionOverlap
1723     */
1724    public boolean getAllowEnterTransitionOverlap() { return true; }
1725
1726    /**
1727     * Controls how the transition set in
1728     * {@link #setExitTransition(android.transition.Transition)} overlaps with the exit
1729     * transition of the called Activity when reentering after if finishes. When true,
1730     * the transition will start as soon as possible. When false, the transition will wait
1731     * until the called Activity's exiting transition completes before starting.
1732     *
1733     * @param allow true to start the transition when possible or false to wait until the
1734     *              called Activity's exiting transition completes.
1735     * @attr ref android.R.styleable#Window_windowAllowReturnTransitionOverlap
1736     */
1737    public void setAllowReturnTransitionOverlap(boolean allow) {}
1738
1739    /**
1740     * TODO: remove this.
1741     * @hide
1742     */
1743    public void setAllowExitTransitionOverlap(boolean allow) {
1744        setAllowReturnTransitionOverlap(allow);
1745    }
1746
1747    /**
1748     * Returns how the transition set in
1749     * {@link #setExitTransition(android.transition.Transition)} overlaps with the exit
1750     * transition of the called Activity when reentering after if finishes. When true,
1751     * the transition will start as soon as possible. When false, the transition will wait
1752     * until the called Activity's exiting transition completes before starting.
1753     *
1754     * @return true when the transition should start when possible or false when it should wait
1755     * until the called Activity's exiting transition completes.
1756     * @attr ref android.R.styleable#Window_windowAllowReturnTransitionOverlap
1757     */
1758    public boolean getAllowReturnTransitionOverlap() { return true; }
1759
1760    /**
1761     * TODO: remove this.
1762     * @hide
1763     */
1764    public boolean getAllowExitTransitionOverlap() { return getAllowReturnTransitionOverlap(); }
1765
1766    /**
1767     * Returns the duration, in milliseconds, of the window background fade
1768     * when transitioning into or away from an Activity when called with an Activity Transition.
1769     * <p>When executing the enter transition, the background starts transparent
1770     * and fades in. This requires {@link #FEATURE_ACTIVITY_TRANSITIONS}. The default is
1771     * 300 milliseconds.</p>
1772     *
1773     * @return The duration of the window background fade to opaque during enter transition.
1774     * @see #getEnterTransition()
1775     * @attr ref android.R.styleable#Window_windowTransitionBackgroundFadeDuration
1776     */
1777    public long getTransitionBackgroundFadeDuration() { return 0; }
1778
1779    /**
1780     * Sets the duration, in milliseconds, of the window background fade
1781     * when transitioning into or away from an Activity when called with an Activity Transition.
1782     * <p>When executing the enter transition, the background starts transparent
1783     * and fades in. This requires {@link #FEATURE_ACTIVITY_TRANSITIONS}. The default is
1784     * 300 milliseconds.</p>
1785     *
1786     * @param fadeDurationMillis The duration of the window background fade to or from opaque
1787     *                           during enter transition.
1788     * @see #setEnterTransition(android.transition.Transition)
1789     * @attr ref android.R.styleable#Window_windowTransitionBackgroundFadeDuration
1790     */
1791    public void setTransitionBackgroundFadeDuration(long fadeDurationMillis) { }
1792
1793    /**
1794     * Returns <code>true</code> when shared elements should use an Overlay during
1795     * shared element transitions or <code>false</code> when they should animate as
1796     * part of the normal View hierarchy. The default value is true.
1797     *
1798     * @return <code>true</code> when shared elements should use an Overlay during
1799     * shared element transitions or <code>false</code> when they should animate as
1800     * part of the normal View hierarchy.
1801     * @attr ref android.R.styleable#Window_windowSharedElementsUseOverlay
1802     */
1803    public boolean getSharedElementsUseOverlay() { return true; }
1804
1805    /**
1806     * Sets whether or not shared elements should use an Overlay during shared element transitions.
1807     * The default value is true.
1808     *
1809     * @param sharedElementsUseOverlay <code>true</code> indicates that shared elements should
1810     *                                 be transitioned with an Overlay or <code>false</code>
1811     *                                 to transition within the normal View hierarchy.
1812     * @attr ref android.R.styleable#Window_windowSharedElementsUseOverlay
1813     */
1814    public void setSharedElementsUseOverlay(boolean sharedElementsUseOverlay) { }
1815
1816    /**
1817     * @return the color of the status bar.
1818     */
1819    public abstract int getStatusBarColor();
1820
1821    /**
1822     * Sets the color of the status bar to {@param color}.
1823     *
1824     * For this to take effect,
1825     * the window must be drawing the system bar backgrounds with
1826     * {@link android.view.WindowManager.LayoutParams#FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS} and
1827     * {@link android.view.WindowManager.LayoutParams#FLAG_TRANSLUCENT_STATUS} must not be set.
1828     *
1829     * If {@param color} is not opaque, consider setting
1830     * {@link android.view.View#SYSTEM_UI_FLAG_LAYOUT_STABLE} and
1831     * {@link android.view.View#SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}.
1832     * <p>
1833     * The transitionName for the view background will be "android:status:background".
1834     * </p>
1835     */
1836    public abstract void setStatusBarColor(int color);
1837
1838    /**
1839     * @return the color of the navigation bar.
1840     */
1841    public abstract int getNavigationBarColor();
1842
1843    /**
1844     * Sets the color of the navigation bar to {@param color}.
1845     *
1846     * For this to take effect,
1847     * the window must be drawing the system bar backgrounds with
1848     * {@link android.view.WindowManager.LayoutParams#FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS} and
1849     * {@link android.view.WindowManager.LayoutParams#FLAG_TRANSLUCENT_NAVIGATION} must not be set.
1850     *
1851     * If {@param color} is not opaque, consider setting
1852     * {@link android.view.View#SYSTEM_UI_FLAG_LAYOUT_STABLE} and
1853     * {@link android.view.View#SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION}.
1854     * <p>
1855     * The transitionName for the view background will be "android:navigation:background".
1856     * </p>
1857     */
1858    public abstract void setNavigationBarColor(int color);
1859
1860
1861}
1862