The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1 | /* |
Jeff Brown | 37df39a9 | 2015-02-25 15:42:31 -0800 | [diff] [blame] | 2 | * Copyright (C) 2006 The Android Open Source Project |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Adam Powell | 6711f3b | 2015-05-06 15:57:09 -0700 | [diff] [blame] | 17 | package com.android.internal.policy; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 18 | |
Jaewan Kim | d98dcab | 2016-05-03 02:52:18 +0900 | [diff] [blame] | 19 | import static android.provider.Settings.Global.DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES; |
Romain Guy | cc6828c | 2010-01-08 15:06:37 -0800 | [diff] [blame] | 20 | import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; |
svetoslavganov | 491293e | 2009-04-28 19:17:02 -0700 | [diff] [blame] | 21 | import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 22 | import static android.view.WindowManager.LayoutParams.*; |
svetoslavganov | 491293e | 2009-04-28 19:17:02 -0700 | [diff] [blame] | 23 | |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 24 | import android.app.ActivityManager; |
Dianne Hackborn | fdf5b35 | 2014-10-08 17:43:48 -0700 | [diff] [blame] | 25 | import android.app.SearchManager; |
| 26 | import android.os.UserHandle; |
Clara Bayarri | ed2a54c | 2015-02-05 16:58:00 +0000 | [diff] [blame] | 27 | |
Phil Weaver | 396d549 | 2016-03-22 17:53:50 -0700 | [diff] [blame] | 28 | import android.text.TextUtils; |
Adam Powell | 6711f3b | 2015-05-06 15:57:09 -0700 | [diff] [blame] | 29 | import android.view.ContextThemeWrapper; |
Adam Powell | 6711f3b | 2015-05-06 15:57:09 -0700 | [diff] [blame] | 30 | import android.view.Gravity; |
| 31 | import android.view.IRotationWatcher.Stub; |
| 32 | import android.view.IWindowManager; |
| 33 | import android.view.InputDevice; |
| 34 | import android.view.InputEvent; |
| 35 | import android.view.InputQueue; |
| 36 | import android.view.KeyCharacterMap; |
| 37 | import android.view.KeyEvent; |
| 38 | import android.view.LayoutInflater; |
| 39 | import android.view.Menu; |
| 40 | import android.view.MenuItem; |
| 41 | import android.view.MotionEvent; |
| 42 | import android.view.SearchEvent; |
| 43 | import android.view.SurfaceHolder.Callback2; |
| 44 | import android.view.View; |
| 45 | import android.view.ViewConfiguration; |
| 46 | import android.view.ViewGroup; |
| 47 | import android.view.ViewManager; |
| 48 | import android.view.ViewParent; |
| 49 | import android.view.ViewRootImpl; |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 50 | import android.view.ViewRootImpl.ActivityConfigCallback; |
Adam Powell | 6711f3b | 2015-05-06 15:57:09 -0700 | [diff] [blame] | 51 | import android.view.Window; |
Adam Powell | 6711f3b | 2015-05-06 15:57:09 -0700 | [diff] [blame] | 52 | import android.view.WindowManager; |
John Spurlock | ae3349e | 2013-10-18 17:34:42 -0400 | [diff] [blame] | 53 | import com.android.internal.R; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 54 | import com.android.internal.view.menu.ContextMenuBuilder; |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 55 | import com.android.internal.view.menu.IconMenuPresenter; |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 56 | import com.android.internal.view.menu.ListMenuPresenter; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 57 | import com.android.internal.view.menu.MenuBuilder; |
| 58 | import com.android.internal.view.menu.MenuDialogHelper; |
Alan Viverette | 021627e | 2015-11-25 14:22:00 -0500 | [diff] [blame] | 59 | import com.android.internal.view.menu.MenuHelper; |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 60 | import com.android.internal.view.menu.MenuPresenter; |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 61 | import com.android.internal.view.menu.MenuView; |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 62 | import com.android.internal.widget.DecorContentParent; |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 63 | import com.android.internal.widget.SwipeDismissLayout; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 64 | |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 65 | import android.app.ActivityManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 66 | import android.app.KeyguardManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 67 | import android.content.Context; |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 68 | import android.content.Intent; |
Aaron Whyte | 1fb617f | 2014-05-12 22:08:53 -0700 | [diff] [blame] | 69 | import android.content.pm.PackageManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 70 | import android.content.res.Configuration; |
Alan Viverette | 4b002d3 | 2014-06-03 17:32:19 -0700 | [diff] [blame] | 71 | import android.content.res.Resources.Theme; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 72 | import android.content.res.TypedArray; |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 73 | import android.graphics.Color; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 74 | import android.graphics.drawable.Drawable; |
| 75 | import android.media.AudioManager; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 76 | import android.media.session.MediaController; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 77 | import android.media.session.MediaSessionLegacyHelper; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 78 | import android.net.Uri; |
| 79 | import android.os.Bundle; |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 80 | import android.os.Handler; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 81 | import android.os.Parcel; |
| 82 | import android.os.Parcelable; |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 83 | import android.os.RemoteException; |
| 84 | import android.os.ServiceManager; |
Jaewan Kim | d98dcab | 2016-05-03 02:52:18 +0900 | [diff] [blame] | 85 | import android.provider.Settings; |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 86 | import android.transition.Scene; |
| 87 | import android.transition.Transition; |
| 88 | import android.transition.TransitionInflater; |
| 89 | import android.transition.TransitionManager; |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 90 | import android.transition.TransitionSet; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 91 | import android.util.AndroidRuntimeException; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 92 | import android.util.EventLog; |
| 93 | import android.util.Log; |
| 94 | import android.util.SparseArray; |
Adam Powell | 85446e9 | 2010-10-22 17:43:56 -0700 | [diff] [blame] | 95 | import android.util.TypedValue; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 96 | import android.view.animation.Animation; |
| 97 | import android.view.animation.AnimationUtils; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 98 | import android.widget.FrameLayout; |
| 99 | import android.widget.ImageView; |
| 100 | import android.widget.ProgressBar; |
| 101 | import android.widget.TextView; |
| 102 | |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 103 | import java.lang.ref.WeakReference; |
| 104 | import java.util.ArrayList; |
| 105 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 106 | /** |
| 107 | * Android-specific Window. |
| 108 | * <p> |
| 109 | * todo: need to pull the generic functionality out into a base class |
| 110 | * in android.widget. |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 111 | * |
| 112 | * @hide |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 113 | */ |
| 114 | public class PhoneWindow extends Window implements MenuBuilder.Callback { |
svetoslavganov | 491293e | 2009-04-28 19:17:02 -0700 | [diff] [blame] | 115 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 116 | private final static String TAG = "PhoneWindow"; |
| 117 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 118 | private static final boolean DEBUG = false; |
| 119 | |
George Mount | ed1e01d | 2014-06-05 13:49:12 -0700 | [diff] [blame] | 120 | private final static int DEFAULT_BACKGROUND_FADE_DURATION_MS = 300; |
| 121 | |
Adam Powell | 166c8e3 | 2014-07-01 17:37:48 -0700 | [diff] [blame] | 122 | private static final int CUSTOM_TITLE_COMPATIBLE_FEATURES = DEFAULT_FEATURES | |
| 123 | (1 << FEATURE_CUSTOM_TITLE) | |
| 124 | (1 << FEATURE_CONTENT_TRANSITIONS) | |
George Mount | 9826f63 | 2014-09-11 08:50:09 -0700 | [diff] [blame] | 125 | (1 << FEATURE_ACTIVITY_TRANSITIONS) | |
Adam Powell | 166c8e3 | 2014-07-01 17:37:48 -0700 | [diff] [blame] | 126 | (1 << FEATURE_ACTION_MODE_OVERLAY); |
| 127 | |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 128 | private static final Transition USE_DEFAULT_TRANSITION = new TransitionSet(); |
| 129 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 130 | /** |
| 131 | * Simple callback used by the context menu and its submenus. The options |
| 132 | * menu submenus do not use this (their behavior is more complex). |
| 133 | */ |
Alan Viverette | 77fb85e | 2015-12-14 11:42:44 -0500 | [diff] [blame] | 134 | final PhoneWindowMenuCallback mContextMenuCallback = new PhoneWindowMenuCallback(this); |
Dianne Hackborn | 6014527 | 2011-01-11 23:45:09 -0800 | [diff] [blame] | 135 | |
| 136 | final TypedValue mMinWidthMajor = new TypedValue(); |
| 137 | final TypedValue mMinWidthMinor = new TypedValue(); |
Adam Powell | 40eec4c | 2012-02-15 17:10:58 -0800 | [diff] [blame] | 138 | TypedValue mFixedWidthMajor; |
| 139 | TypedValue mFixedWidthMinor; |
| 140 | TypedValue mFixedHeightMajor; |
| 141 | TypedValue mFixedHeightMinor; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 142 | |
| 143 | // This is the top-level view of the window, containing the window decor. |
| 144 | private DecorView mDecor; |
| 145 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 146 | // When we reuse decor views, we need to recreate the content root. This happens when the decor |
| 147 | // view is requested, so we need to force the recreating without introducing an infinite loop. |
| 148 | private boolean mForceDecorInstall = false; |
| 149 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 150 | // This is the view in which the window contents are placed. It is either |
| 151 | // mDecor itself, or a child of mDecor where the contents go. |
Wale Ogunwale | 8804af2 | 2015-11-17 09:18:15 -0800 | [diff] [blame] | 152 | ViewGroup mContentParent; |
Filip Gruszczynski | f4bdaeb | 2016-01-06 14:34:00 -0800 | [diff] [blame] | 153 | // Whether the client has explicitly set the content view. If false and mContentParent is not |
| 154 | // null, then the content parent was set due to window preservation. |
| 155 | private boolean mContentParentExplicitlySet = false; |
Adrian Roos | f5e9b5c | 2014-09-10 15:27:41 +0200 | [diff] [blame] | 156 | |
Adam Powell | 6711f3b | 2015-05-06 15:57:09 -0700 | [diff] [blame] | 157 | Callback2 mTakeSurfaceCallback; |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 158 | |
Dianne Hackborn | 1e4b9f3 | 2010-06-23 14:10:57 -0700 | [diff] [blame] | 159 | InputQueue.Callback mTakeInputQueueCallback; |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 160 | |
Wale Ogunwale | 8804af2 | 2015-11-17 09:18:15 -0800 | [diff] [blame] | 161 | boolean mIsFloating; |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 162 | private boolean mIsTranslucent; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 163 | |
| 164 | private LayoutInflater mLayoutInflater; |
| 165 | |
| 166 | private TextView mTitleView; |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 167 | |
Wale Ogunwale | 8804af2 | 2015-11-17 09:18:15 -0800 | [diff] [blame] | 168 | DecorContentParent mDecorContentParent; |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 169 | private ActionMenuPresenterCallback mActionMenuPresenterCallback; |
| 170 | private PanelMenuPresenterCallback mPanelMenuPresenterCallback; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 171 | |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 172 | private TransitionManager mTransitionManager; |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 173 | private Scene mContentScene; |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 174 | |
Adam Powell | 0a317e9 | 2013-06-13 13:15:43 -0700 | [diff] [blame] | 175 | // The icon resource has been explicitly set elsewhere |
| 176 | // and should not be overwritten with a default. |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 177 | static final int FLAG_RESOURCE_SET_ICON = 1 << 0; |
Adam Powell | 0a317e9 | 2013-06-13 13:15:43 -0700 | [diff] [blame] | 178 | |
| 179 | // The logo resource has been explicitly set elsewhere |
| 180 | // and should not be overwritten with a default. |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 181 | static final int FLAG_RESOURCE_SET_LOGO = 1 << 1; |
Adam Powell | 0a317e9 | 2013-06-13 13:15:43 -0700 | [diff] [blame] | 182 | |
| 183 | // The icon resource is currently configured to use the system fallback |
| 184 | // as no default was previously specified. Anything can override this. |
| 185 | static final int FLAG_RESOURCE_SET_ICON_FALLBACK = 1 << 2; |
| 186 | |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 187 | int mResourcesSetFlags; |
| 188 | int mIconRes; |
| 189 | int mLogoRes; |
| 190 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 191 | private DrawableFeatureState[] mDrawables; |
| 192 | |
| 193 | private PanelFeatureState[] mPanels; |
| 194 | |
| 195 | /** |
| 196 | * The panel that is prepared or opened (the most recent one if there are |
| 197 | * multiple panels). Shortcuts will go to this panel. It gets set in |
| 198 | * {@link #preparePanel} and cleared in {@link #closePanel}. |
| 199 | */ |
Wale Ogunwale | 8804af2 | 2015-11-17 09:18:15 -0800 | [diff] [blame] | 200 | PanelFeatureState mPreparedPanel; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 201 | |
| 202 | /** |
| 203 | * The keycode that is currently held down (as a modifier) for chording. If |
| 204 | * this is 0, there is no key held down. |
| 205 | */ |
Wale Ogunwale | 8804af2 | 2015-11-17 09:18:15 -0800 | [diff] [blame] | 206 | int mPanelChordingKey; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 207 | |
Jaewan Kim | d98dcab | 2016-05-03 02:52:18 +0900 | [diff] [blame] | 208 | // This stores if the system supports Picture-in-Picture |
| 209 | // to see if KEYCODE_WINDOW should be handled here or not. |
| 210 | private boolean mSupportsPictureInPicture; |
| 211 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 212 | private ImageView mLeftIconView; |
| 213 | |
| 214 | private ImageView mRightIconView; |
| 215 | |
| 216 | private ProgressBar mCircularProgressBar; |
| 217 | |
| 218 | private ProgressBar mHorizontalProgressBar; |
| 219 | |
Wale Ogunwale | 0d7e912 | 2015-11-17 10:45:06 -0800 | [diff] [blame] | 220 | int mBackgroundResource = 0; |
| 221 | int mBackgroundFallbackResource = 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 222 | |
| 223 | private Drawable mBackgroundDrawable; |
| 224 | |
Wale Ogunwale | 0d7e912 | 2015-11-17 10:45:06 -0800 | [diff] [blame] | 225 | private boolean mLoadElevation = true; |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 226 | private float mElevation; |
| 227 | |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 228 | /** Whether window content should be clipped to the background outline. */ |
| 229 | private boolean mClipToOutline; |
| 230 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 231 | private int mFrameResource = 0; |
| 232 | |
| 233 | private int mTextColor = 0; |
Wale Ogunwale | 8804af2 | 2015-11-17 09:18:15 -0800 | [diff] [blame] | 234 | int mStatusBarColor = 0; |
| 235 | int mNavigationBarColor = 0; |
Jason Monk | a750e99 | 2017-09-01 12:40:06 -0400 | [diff] [blame] | 236 | int mNavigationBarDividerColor = 0; |
Adrian Roos | 34e6544 | 2014-05-17 02:35:33 +0200 | [diff] [blame] | 237 | private boolean mForcedStatusBarColor = false; |
| 238 | private boolean mForcedNavigationBarColor = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 239 | |
| 240 | private CharSequence mTitle = null; |
| 241 | |
| 242 | private int mTitleColor = 0; |
| 243 | |
Dianne Hackborn | cfaf887 | 2011-01-18 13:57:54 -0800 | [diff] [blame] | 244 | private boolean mAlwaysReadCloseOnTouchAttr = false; |
Alan Viverette | eb1d379 | 2014-06-03 18:36:03 -0700 | [diff] [blame] | 245 | |
Wale Ogunwale | 8804af2 | 2015-11-17 09:18:15 -0800 | [diff] [blame] | 246 | ContextMenuBuilder mContextMenu; |
Alan Viverette | 021627e | 2015-11-25 14:22:00 -0500 | [diff] [blame] | 247 | MenuHelper mContextMenuHelper; |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 248 | private boolean mClosingActionMenu; |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 249 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 250 | private int mVolumeControlStreamType = AudioManager.USE_DEFAULT_STREAM_TYPE; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 251 | private MediaController mMediaController; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 252 | |
Joe Onorato | 86f6786 | 2010-11-05 18:57:34 -0700 | [diff] [blame] | 253 | private AudioManager mAudioManager; |
| 254 | private KeyguardManager mKeyguardManager; |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 255 | |
Adam Powell | 269248d | 2011-08-02 10:26:54 -0700 | [diff] [blame] | 256 | private int mUiOptions = 0; |
| 257 | |
Adam Powell | 4b6d93f | 2012-09-18 18:34:08 -0700 | [diff] [blame] | 258 | private boolean mInvalidatePanelMenuPosted; |
| 259 | private int mInvalidatePanelMenuFeatures; |
| 260 | private final Runnable mInvalidatePanelMenuRunnable = new Runnable() { |
| 261 | @Override public void run() { |
| 262 | for (int i = 0; i <= FEATURE_MAX; i++) { |
| 263 | if ((mInvalidatePanelMenuFeatures & 1 << i) != 0) { |
| 264 | doInvalidatePanelMenu(i); |
| 265 | } |
| 266 | } |
| 267 | mInvalidatePanelMenuPosted = false; |
| 268 | mInvalidatePanelMenuFeatures = 0; |
| 269 | } |
| 270 | }; |
| 271 | |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 272 | private Transition mEnterTransition = null; |
| 273 | private Transition mReturnTransition = USE_DEFAULT_TRANSITION; |
| 274 | private Transition mExitTransition = null; |
| 275 | private Transition mReenterTransition = USE_DEFAULT_TRANSITION; |
| 276 | private Transition mSharedElementEnterTransition = null; |
| 277 | private Transition mSharedElementReturnTransition = USE_DEFAULT_TRANSITION; |
| 278 | private Transition mSharedElementExitTransition = null; |
| 279 | private Transition mSharedElementReenterTransition = USE_DEFAULT_TRANSITION; |
George Mount | c03da0e | 2014-08-22 17:04:02 -0700 | [diff] [blame] | 280 | private Boolean mAllowReturnTransitionOverlap; |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 281 | private Boolean mAllowEnterTransitionOverlap; |
George Mount | ed1e01d | 2014-06-05 13:49:12 -0700 | [diff] [blame] | 282 | private long mBackgroundFadeDurationMillis = -1; |
George Mount | b89d5cc | 2014-08-18 16:50:50 -0700 | [diff] [blame] | 283 | private Boolean mSharedElementsUseOverlay; |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 284 | |
Jorim Jaggi | a16cc15 | 2015-06-01 16:55:05 -0700 | [diff] [blame] | 285 | private boolean mIsStartingWindow; |
Filip Gruszczynski | 0daf210 | 2015-09-29 08:39:07 -0700 | [diff] [blame] | 286 | private int mTheme = -1; |
Jorim Jaggi | a16cc15 | 2015-06-01 16:55:05 -0700 | [diff] [blame] | 287 | |
Filip Gruszczynski | 3dec081 | 2015-12-09 08:42:41 -0800 | [diff] [blame] | 288 | private int mDecorCaptionShade = DECOR_CAPTION_SHADE_AUTO; |
| 289 | |
Filip Gruszczynski | 796b8c1 | 2015-12-22 14:46:21 -0800 | [diff] [blame] | 290 | private boolean mUseDecorContext = false; |
| 291 | |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 292 | /** @see ViewRootImpl#mActivityConfigCallback */ |
| 293 | private ActivityConfigCallback mActivityConfigCallback; |
| 294 | |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 295 | static class WindowManagerHolder { |
| 296 | static final IWindowManager sWindowManager = IWindowManager.Stub.asInterface( |
| 297 | ServiceManager.getService("window")); |
| 298 | } |
| 299 | |
| 300 | static final RotationWatcher sRotationWatcher = new RotationWatcher(); |
| 301 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 302 | public PhoneWindow(Context context) { |
| 303 | super(context); |
| 304 | mLayoutInflater = LayoutInflater.from(context); |
| 305 | } |
| 306 | |
Filip Gruszczynski | 796b8c1 | 2015-12-22 14:46:21 -0800 | [diff] [blame] | 307 | /** |
| 308 | * Constructor for main window of an activity. |
| 309 | */ |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 310 | public PhoneWindow(Context context, Window preservedWindow, |
| 311 | ActivityConfigCallback activityConfigCallback) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 312 | this(context); |
Filip Gruszczynski | 796b8c1 | 2015-12-22 14:46:21 -0800 | [diff] [blame] | 313 | // Only main activity windows use decor context, all the other windows depend on whatever |
| 314 | // context that was given to them. |
| 315 | mUseDecorContext = true; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 316 | if (preservedWindow != null) { |
| 317 | mDecor = (DecorView) preservedWindow.getDecorView(); |
| 318 | mElevation = preservedWindow.getElevation(); |
Wale Ogunwale | 0d7e912 | 2015-11-17 10:45:06 -0800 | [diff] [blame] | 319 | mLoadElevation = false; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 320 | mForceDecorInstall = true; |
Chong Zhang | a8be1b9 | 2015-09-29 13:54:44 -0700 | [diff] [blame] | 321 | // If we're preserving window, carry over the app token from the preserved |
| 322 | // window, as we'll be skipping the addView in handleResumeActivity(), and |
| 323 | // the token will not be updated as for a new window. |
| 324 | getAttributes().token = preservedWindow.getAttributes().token; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 325 | } |
Jaewan Kim | d98dcab | 2016-05-03 02:52:18 +0900 | [diff] [blame] | 326 | // Even though the device doesn't support picture-in-picture mode, |
| 327 | // an user can force using it through developer options. |
| 328 | boolean forceResizable = Settings.Global.getInt(context.getContentResolver(), |
| 329 | DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES, 0) != 0; |
| 330 | mSupportsPictureInPicture = forceResizable || context.getPackageManager().hasSystemFeature( |
| 331 | PackageManager.FEATURE_PICTURE_IN_PICTURE); |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 332 | mActivityConfigCallback = activityConfigCallback; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 333 | } |
| 334 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 335 | @Override |
| 336 | public final void setContainer(Window container) { |
| 337 | super.setContainer(container); |
| 338 | } |
| 339 | |
| 340 | @Override |
| 341 | public boolean requestFeature(int featureId) { |
Filip Gruszczynski | f4bdaeb | 2016-01-06 14:34:00 -0800 | [diff] [blame] | 342 | if (mContentParentExplicitlySet) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 343 | throw new AndroidRuntimeException("requestFeature() must be called before adding content"); |
| 344 | } |
| 345 | final int features = getFeatures(); |
Adam Powell | 166c8e3 | 2014-07-01 17:37:48 -0700 | [diff] [blame] | 346 | final int newFeatures = features | (1 << featureId); |
| 347 | if ((newFeatures & (1 << FEATURE_CUSTOM_TITLE)) != 0 && |
| 348 | (newFeatures & ~CUSTOM_TITLE_COMPATIBLE_FEATURES) != 0) { |
| 349 | // Another feature is enabled and the user is trying to enable the custom title feature |
| 350 | // or custom title feature is enabled and the user is trying to enable another feature |
| 351 | throw new AndroidRuntimeException( |
| 352 | "You cannot combine custom titles with other title features"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 353 | } |
Adam Powell | f4a6ec4 | 2010-08-24 14:18:10 -0700 | [diff] [blame] | 354 | if ((features & (1 << FEATURE_NO_TITLE)) != 0 && featureId == FEATURE_ACTION_BAR) { |
| 355 | return false; // Ignore. No title dominates. |
| 356 | } |
| 357 | if ((features & (1 << FEATURE_ACTION_BAR)) != 0 && featureId == FEATURE_NO_TITLE) { |
| 358 | // Remove the action bar feature if we have no title. No title dominates. |
| 359 | removeFeature(FEATURE_ACTION_BAR); |
| 360 | } |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 361 | |
| 362 | if ((features & (1 << FEATURE_ACTION_BAR)) != 0 && featureId == FEATURE_SWIPE_TO_DISMISS) { |
| 363 | throw new AndroidRuntimeException( |
| 364 | "You cannot combine swipe dismissal and the action bar."); |
| 365 | } |
| 366 | if ((features & (1 << FEATURE_SWIPE_TO_DISMISS)) != 0 && featureId == FEATURE_ACTION_BAR) { |
| 367 | throw new AndroidRuntimeException( |
| 368 | "You cannot combine swipe dismissal and the action bar."); |
| 369 | } |
Aaron Whyte | 1fb617f | 2014-05-12 22:08:53 -0700 | [diff] [blame] | 370 | |
| 371 | if (featureId == FEATURE_INDETERMINATE_PROGRESS && |
| 372 | getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH)) { |
| 373 | throw new AndroidRuntimeException("You cannot use indeterminate progress on a watch."); |
| 374 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 375 | return super.requestFeature(featureId); |
| 376 | } |
| 377 | |
| 378 | @Override |
Adam Powell | 269248d | 2011-08-02 10:26:54 -0700 | [diff] [blame] | 379 | public void setUiOptions(int uiOptions) { |
| 380 | mUiOptions = uiOptions; |
| 381 | } |
| 382 | |
| 383 | @Override |
Adam Powell | e43fca9 | 2011-08-16 12:57:01 -0700 | [diff] [blame] | 384 | public void setUiOptions(int uiOptions, int mask) { |
| 385 | mUiOptions = (mUiOptions & ~mask) | (uiOptions & mask); |
| 386 | } |
| 387 | |
| 388 | @Override |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 389 | public TransitionManager getTransitionManager() { |
| 390 | return mTransitionManager; |
| 391 | } |
| 392 | |
| 393 | @Override |
| 394 | public void setTransitionManager(TransitionManager tm) { |
| 395 | mTransitionManager = tm; |
| 396 | } |
| 397 | |
| 398 | @Override |
| 399 | public Scene getContentScene() { |
| 400 | return mContentScene; |
| 401 | } |
| 402 | |
| 403 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 404 | public void setContentView(int layoutResID) { |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 405 | // Note: FEATURE_CONTENT_TRANSITIONS may be set in the process of installing the window |
| 406 | // decor, when theme attributes and the like are crystalized. Do not check the feature |
| 407 | // before this happens. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 408 | if (mContentParent == null) { |
| 409 | installDecor(); |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 410 | } else if (!hasFeature(FEATURE_CONTENT_TRANSITIONS)) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 411 | mContentParent.removeAllViews(); |
| 412 | } |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 413 | |
| 414 | if (hasFeature(FEATURE_CONTENT_TRANSITIONS)) { |
| 415 | final Scene newScene = Scene.getSceneForLayout(mContentParent, layoutResID, |
| 416 | getContext()); |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 417 | transitionTo(newScene); |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 418 | } else { |
| 419 | mLayoutInflater.inflate(layoutResID, mContentParent); |
| 420 | } |
Adam Powell | 41607d5 | 2015-06-17 13:37:06 -0700 | [diff] [blame] | 421 | mContentParent.requestApplyInsets(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 422 | final Callback cb = getCallback(); |
Dianne Hackborn | b66ad57 | 2011-03-01 17:10:30 -0800 | [diff] [blame] | 423 | if (cb != null && !isDestroyed()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 424 | cb.onContentChanged(); |
| 425 | } |
Filip Gruszczynski | f4bdaeb | 2016-01-06 14:34:00 -0800 | [diff] [blame] | 426 | mContentParentExplicitlySet = true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | @Override |
| 430 | public void setContentView(View view) { |
Romain Guy | cc6828c | 2010-01-08 15:06:37 -0800 | [diff] [blame] | 431 | setContentView(view, new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | @Override |
| 435 | public void setContentView(View view, ViewGroup.LayoutParams params) { |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 436 | // Note: FEATURE_CONTENT_TRANSITIONS may be set in the process of installing the window |
| 437 | // decor, when theme attributes and the like are crystalized. Do not check the feature |
| 438 | // before this happens. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 439 | if (mContentParent == null) { |
| 440 | installDecor(); |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 441 | } else if (!hasFeature(FEATURE_CONTENT_TRANSITIONS)) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 442 | mContentParent.removeAllViews(); |
| 443 | } |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 444 | |
| 445 | if (hasFeature(FEATURE_CONTENT_TRANSITIONS)) { |
| 446 | view.setLayoutParams(params); |
| 447 | final Scene newScene = new Scene(mContentParent, view); |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 448 | transitionTo(newScene); |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 449 | } else { |
| 450 | mContentParent.addView(view, params); |
| 451 | } |
Adam Powell | 41607d5 | 2015-06-17 13:37:06 -0700 | [diff] [blame] | 452 | mContentParent.requestApplyInsets(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 453 | final Callback cb = getCallback(); |
Dianne Hackborn | b66ad57 | 2011-03-01 17:10:30 -0800 | [diff] [blame] | 454 | if (cb != null && !isDestroyed()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 455 | cb.onContentChanged(); |
| 456 | } |
Filip Gruszczynski | f4bdaeb | 2016-01-06 14:34:00 -0800 | [diff] [blame] | 457 | mContentParentExplicitlySet = true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | @Override |
| 461 | public void addContentView(View view, ViewGroup.LayoutParams params) { |
| 462 | if (mContentParent == null) { |
| 463 | installDecor(); |
| 464 | } |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 465 | if (hasFeature(FEATURE_CONTENT_TRANSITIONS)) { |
| 466 | // TODO Augment the scenes/transitions API to support this. |
George Mount | 7e20884 | 2014-07-02 07:22:43 -0700 | [diff] [blame] | 467 | Log.v(TAG, "addContentView does not support content transitions"); |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 468 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 469 | mContentParent.addView(view, params); |
Adam Powell | 41607d5 | 2015-06-17 13:37:06 -0700 | [diff] [blame] | 470 | mContentParent.requestApplyInsets(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 471 | final Callback cb = getCallback(); |
Dianne Hackborn | b66ad57 | 2011-03-01 17:10:30 -0800 | [diff] [blame] | 472 | if (cb != null && !isDestroyed()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 473 | cb.onContentChanged(); |
| 474 | } |
| 475 | } |
| 476 | |
Wale Ogunwale | 0d7e912 | 2015-11-17 10:45:06 -0800 | [diff] [blame] | 477 | @Override |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 478 | public void clearContentView() { |
Wale Ogunwale | 0d7e912 | 2015-11-17 10:45:06 -0800 | [diff] [blame] | 479 | if (mDecor != null) { |
| 480 | mDecor.clearContentView(); |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 481 | } |
| 482 | } |
| 483 | |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 484 | private void transitionTo(Scene scene) { |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 485 | if (mContentScene == null) { |
| 486 | scene.enter(); |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 487 | } else { |
| 488 | mTransitionManager.transitionTo(scene); |
| 489 | } |
| 490 | mContentScene = scene; |
| 491 | } |
| 492 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 493 | @Override |
| 494 | public View getCurrentFocus() { |
| 495 | return mDecor != null ? mDecor.findFocus() : null; |
| 496 | } |
| 497 | |
| 498 | @Override |
Adam Powell | 6711f3b | 2015-05-06 15:57:09 -0700 | [diff] [blame] | 499 | public void takeSurface(Callback2 callback) { |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 500 | mTakeSurfaceCallback = callback; |
| 501 | } |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 502 | |
Dianne Hackborn | 1e4b9f3 | 2010-06-23 14:10:57 -0700 | [diff] [blame] | 503 | public void takeInputQueue(InputQueue.Callback callback) { |
| 504 | mTakeInputQueueCallback = callback; |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 505 | } |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 506 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 507 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 508 | public boolean isFloating() { |
| 509 | return mIsFloating; |
| 510 | } |
| 511 | |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 512 | public boolean isTranslucent() { |
| 513 | return mIsTranslucent; |
| 514 | } |
| 515 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 516 | /** |
Jorim Jaggi | 8e879f1 | 2016-05-25 16:41:49 -0700 | [diff] [blame] | 517 | * @return Whether the window is currently showing the wallpaper. |
| 518 | */ |
| 519 | boolean isShowingWallpaper() { |
| 520 | return (getAttributes().flags & FLAG_SHOW_WALLPAPER) != 0; |
| 521 | } |
| 522 | |
| 523 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 524 | * Return a LayoutInflater instance that can be used to inflate XML view layout |
| 525 | * resources for use in this Window. |
| 526 | * |
| 527 | * @return LayoutInflater The shared LayoutInflater. |
| 528 | */ |
| 529 | @Override |
| 530 | public LayoutInflater getLayoutInflater() { |
| 531 | return mLayoutInflater; |
| 532 | } |
| 533 | |
| 534 | @Override |
| 535 | public void setTitle(CharSequence title) { |
Phil Weaver | 155edc6 | 2016-06-09 10:24:53 -0700 | [diff] [blame] | 536 | setTitle(title, true); |
| 537 | } |
| 538 | |
| 539 | public void setTitle(CharSequence title, boolean updateAccessibilityTitle) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 540 | if (mTitleView != null) { |
| 541 | mTitleView.setText(title); |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 542 | } else if (mDecorContentParent != null) { |
| 543 | mDecorContentParent.setWindowTitle(title); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 544 | } |
| 545 | mTitle = title; |
Phil Weaver | 155edc6 | 2016-06-09 10:24:53 -0700 | [diff] [blame] | 546 | if (updateAccessibilityTitle) { |
| 547 | WindowManager.LayoutParams params = getAttributes(); |
| 548 | if (!TextUtils.equals(title, params.accessibilityTitle)) { |
| 549 | params.accessibilityTitle = TextUtils.stringOrSpannedString(title); |
Phil Weaver | 964c68e | 2016-10-27 16:22:05 -0700 | [diff] [blame] | 550 | if (mDecor != null) { |
| 551 | // ViewRootImpl will make sure the change propagates to WindowManagerService |
| 552 | ViewRootImpl vr = mDecor.getViewRootImpl(); |
| 553 | if (vr != null) { |
| 554 | vr.onWindowTitleChanged(); |
| 555 | } |
| 556 | } |
Phil Weaver | 155edc6 | 2016-06-09 10:24:53 -0700 | [diff] [blame] | 557 | dispatchWindowAttributesChanged(getAttributes()); |
| 558 | } |
Phil Weaver | 396d549 | 2016-03-22 17:53:50 -0700 | [diff] [blame] | 559 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | @Override |
Alan Viverette | 2525d9c | 2013-11-15 14:42:19 -0800 | [diff] [blame] | 563 | @Deprecated |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 564 | public void setTitleColor(int textColor) { |
| 565 | if (mTitleView != null) { |
| 566 | mTitleView.setTextColor(textColor); |
| 567 | } |
| 568 | mTitleColor = textColor; |
| 569 | } |
| 570 | |
| 571 | /** |
| 572 | * Prepares the panel to either be opened or chorded. This creates the Menu |
| 573 | * instance for the panel and populates it via the Activity callbacks. |
| 574 | * |
| 575 | * @param st The panel state to prepare. |
| 576 | * @param event The event that triggered the preparing of the panel. |
| 577 | * @return Whether the panel was prepared. If the panel should not be shown, |
| 578 | * returns false. |
| 579 | */ |
| 580 | public final boolean preparePanel(PanelFeatureState st, KeyEvent event) { |
Dianne Hackborn | b66ad57 | 2011-03-01 17:10:30 -0800 | [diff] [blame] | 581 | if (isDestroyed()) { |
| 582 | return false; |
| 583 | } |
| 584 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 585 | // Already prepared (isPrepared will be reset to false later) |
Adam Powell | c6d5188 | 2011-10-13 11:33:24 -0700 | [diff] [blame] | 586 | if (st.isPrepared) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 587 | return true; |
Adam Powell | c6d5188 | 2011-10-13 11:33:24 -0700 | [diff] [blame] | 588 | } |
Alan Viverette | eb1d379 | 2014-06-03 18:36:03 -0700 | [diff] [blame] | 589 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 590 | if ((mPreparedPanel != null) && (mPreparedPanel != st)) { |
| 591 | // Another Panel is prepared and possibly open, so close it |
| 592 | closePanel(mPreparedPanel, false); |
| 593 | } |
| 594 | |
| 595 | final Callback cb = getCallback(); |
| 596 | |
| 597 | if (cb != null) { |
| 598 | st.createdPanelView = cb.onCreatePanelView(st.featureId); |
| 599 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 600 | |
Adam Powell | 8c16aa9 | 2013-04-04 10:47:52 -0700 | [diff] [blame] | 601 | final boolean isActionBarMenu = |
| 602 | (st.featureId == FEATURE_OPTIONS_PANEL || st.featureId == FEATURE_ACTION_BAR); |
| 603 | |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 604 | if (isActionBarMenu && mDecorContentParent != null) { |
Adam Powell | 8c16aa9 | 2013-04-04 10:47:52 -0700 | [diff] [blame] | 605 | // Enforce ordering guarantees around events so that the action bar never |
| 606 | // dispatches menu-related events before the panel is prepared. |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 607 | mDecorContentParent.setMenuPrepared(); |
Adam Powell | 8c16aa9 | 2013-04-04 10:47:52 -0700 | [diff] [blame] | 608 | } |
| 609 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 610 | if (st.createdPanelView == null) { |
| 611 | // Init the panel state's menu--return false if init failed |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 612 | if (st.menu == null || st.refreshMenuContent) { |
| 613 | if (st.menu == null) { |
| 614 | if (!initializePanelMenu(st) || (st.menu == null)) { |
| 615 | return false; |
| 616 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 617 | } |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 618 | |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 619 | if (isActionBarMenu && mDecorContentParent != null) { |
Adam Powell | ccdd4ee | 2011-07-27 20:05:14 -0700 | [diff] [blame] | 620 | if (mActionMenuPresenterCallback == null) { |
| 621 | mActionMenuPresenterCallback = new ActionMenuPresenterCallback(); |
| 622 | } |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 623 | mDecorContentParent.setMenu(st.menu, mActionMenuPresenterCallback); |
Adam Powell | ccdd4ee | 2011-07-27 20:05:14 -0700 | [diff] [blame] | 624 | } |
| 625 | |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 626 | // Call callback, and return if it doesn't want to display menu. |
| 627 | |
| 628 | // Creating the panel menu will involve a lot of manipulation; |
| 629 | // don't dispatch change events to presenters until we're done. |
| 630 | st.menu.stopDispatchingItemsChanged(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 631 | if ((cb == null) || !cb.onCreatePanelMenu(st.featureId, st.menu)) { |
| 632 | // Ditch the menu created above |
Adam Powell | 1d07e16 | 2011-09-07 20:46:24 -0700 | [diff] [blame] | 633 | st.setMenu(null); |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 634 | |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 635 | if (isActionBarMenu && mDecorContentParent != null) { |
Adam Powell | 84f4936 | 2011-08-18 11:09:57 -0700 | [diff] [blame] | 636 | // Don't show it in the action bar either |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 637 | mDecorContentParent.setMenu(null, mActionMenuPresenterCallback); |
Adam Powell | 84f4936 | 2011-08-18 11:09:57 -0700 | [diff] [blame] | 638 | } |
Adam Powell | f35d049 | 2011-08-17 13:56:47 -0700 | [diff] [blame] | 639 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 640 | return false; |
| 641 | } |
Alan Viverette | eb1d379 | 2014-06-03 18:36:03 -0700 | [diff] [blame] | 642 | |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 643 | st.refreshMenuContent = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 644 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 645 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 646 | // Callback and return if the callback does not want to show the menu |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 647 | |
| 648 | // Preparing the panel menu can involve a lot of manipulation; |
| 649 | // don't dispatch change events to presenters until we're done. |
| 650 | st.menu.stopDispatchingItemsChanged(); |
Adam Powell | 97a3001 | 2011-08-09 17:15:48 -0700 | [diff] [blame] | 651 | |
| 652 | // Restore action view state before we prepare. This gives apps |
| 653 | // an opportunity to override frozen/restored state in onPrepare. |
| 654 | if (st.frozenActionViewState != null) { |
| 655 | st.menu.restoreActionViewStates(st.frozenActionViewState); |
| 656 | st.frozenActionViewState = null; |
| 657 | } |
| 658 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 659 | if (!cb.onPreparePanel(st.featureId, st.createdPanelView, st.menu)) { |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 660 | if (isActionBarMenu && mDecorContentParent != null) { |
Adam Powell | 84f4936 | 2011-08-18 11:09:57 -0700 | [diff] [blame] | 661 | // The app didn't want to show the menu for now but it still exists. |
| 662 | // Clear it out of the action bar. |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 663 | mDecorContentParent.setMenu(null, mActionMenuPresenterCallback); |
Adam Powell | 84f4936 | 2011-08-18 11:09:57 -0700 | [diff] [blame] | 664 | } |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 665 | st.menu.startDispatchingItemsChanged(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 666 | return false; |
| 667 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 668 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 669 | // Set the proper keymap |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 670 | KeyCharacterMap kmap = KeyCharacterMap.load( |
| 671 | event != null ? event.getDeviceId() : KeyCharacterMap.VIRTUAL_KEYBOARD); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 672 | st.qwertyMode = kmap.getKeyboardType() != KeyCharacterMap.NUMERIC; |
| 673 | st.menu.setQwertyMode(st.qwertyMode); |
Adam Powell | 89b09da | 2011-07-27 11:55:29 -0700 | [diff] [blame] | 674 | st.menu.startDispatchingItemsChanged(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | // Set other state |
| 678 | st.isPrepared = true; |
| 679 | st.isHandled = false; |
| 680 | mPreparedPanel = st; |
| 681 | |
| 682 | return true; |
| 683 | } |
| 684 | |
| 685 | @Override |
| 686 | public void onConfigurationChanged(Configuration newConfig) { |
Adam Powell | 6c6f575 | 2010-08-20 18:34:46 -0700 | [diff] [blame] | 687 | // Action bars handle their own menu state |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 688 | if (mDecorContentParent == null) { |
Adam Powell | 6c6f575 | 2010-08-20 18:34:46 -0700 | [diff] [blame] | 689 | PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, false); |
| 690 | if ((st != null) && (st.menu != null)) { |
Adam Powell | 6c6f575 | 2010-08-20 18:34:46 -0700 | [diff] [blame] | 691 | if (st.isOpen) { |
| 692 | // Freeze state |
| 693 | final Bundle state = new Bundle(); |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 694 | if (st.iconMenuPresenter != null) { |
| 695 | st.iconMenuPresenter.saveHierarchyState(state); |
| 696 | } |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 697 | if (st.listMenuPresenter != null) { |
| 698 | st.listMenuPresenter.saveHierarchyState(state); |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 699 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 700 | |
Adam Powell | 6c6f575 | 2010-08-20 18:34:46 -0700 | [diff] [blame] | 701 | // Remove the menu views since they need to be recreated |
| 702 | // according to the new configuration |
| 703 | clearMenuViews(st); |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 704 | |
Adam Powell | 6c6f575 | 2010-08-20 18:34:46 -0700 | [diff] [blame] | 705 | // Re-open the same menu |
| 706 | reopenMenu(false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 707 | |
Adam Powell | 6c6f575 | 2010-08-20 18:34:46 -0700 | [diff] [blame] | 708 | // Restore state |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 709 | if (st.iconMenuPresenter != null) { |
| 710 | st.iconMenuPresenter.restoreHierarchyState(state); |
| 711 | } |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 712 | if (st.listMenuPresenter != null) { |
| 713 | st.listMenuPresenter.restoreHierarchyState(state); |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 714 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 715 | |
Adam Powell | 6c6f575 | 2010-08-20 18:34:46 -0700 | [diff] [blame] | 716 | } else { |
| 717 | // Clear menu views so on next menu opening, it will use |
| 718 | // the proper layout |
| 719 | clearMenuViews(st); |
| 720 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 721 | } |
| 722 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 723 | } |
| 724 | |
Wale Ogunwale | eb6722c | 2015-12-08 11:43:43 -0800 | [diff] [blame] | 725 | @Override |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 726 | public void onMultiWindowModeChanged() { |
Wale Ogunwale | eb6722c | 2015-12-08 11:43:43 -0800 | [diff] [blame] | 727 | if (mDecor != null) { |
Filip Gruszczynski | 1937a4c | 2016-01-19 16:17:13 -0800 | [diff] [blame] | 728 | mDecor.onConfigurationChanged(getContext().getResources().getConfiguration()); |
Wale Ogunwale | eb6722c | 2015-12-08 11:43:43 -0800 | [diff] [blame] | 729 | } |
| 730 | } |
| 731 | |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 732 | @Override |
Winson Chung | 4d8681f | 2017-05-23 16:22:08 -0700 | [diff] [blame] | 733 | public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) { |
| 734 | if (mDecor != null) { |
| 735 | mDecor.updatePictureInPictureOutlineProvider(isInPictureInPictureMode); |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | @Override |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 740 | public void reportActivityRelaunched() { |
| 741 | if (mDecor != null && mDecor.getViewRootImpl() != null) { |
| 742 | mDecor.getViewRootImpl().reportActivityRelaunched(); |
| 743 | } |
| 744 | } |
| 745 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 746 | private static void clearMenuViews(PanelFeatureState st) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 747 | // This can be called on config changes, so we should make sure |
| 748 | // the views will be reconstructed based on the new orientation, etc. |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 749 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 750 | // Allow the callback to create a new panel view |
| 751 | st.createdPanelView = null; |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 752 | |
| 753 | // Causes the decor view to be recreated |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 754 | st.refreshDecorView = true; |
Alan Viverette | eb1d379 | 2014-06-03 18:36:03 -0700 | [diff] [blame] | 755 | |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 756 | st.clearMenuPresenters(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 757 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 758 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 759 | @Override |
| 760 | public final void openPanel(int featureId, KeyEvent event) { |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 761 | if (featureId == FEATURE_OPTIONS_PANEL && mDecorContentParent != null && |
| 762 | mDecorContentParent.canShowOverflowMenu() && |
Adam Powell | 5fcf5b9 | 2013-09-11 08:45:36 -0700 | [diff] [blame] | 763 | !ViewConfiguration.get(getContext()).hasPermanentMenuKey()) { |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 764 | mDecorContentParent.showOverflowMenu(); |
Adam Powell | f75eeb2 | 2010-08-10 15:59:40 -0700 | [diff] [blame] | 765 | } else { |
| 766 | openPanel(getPanelState(featureId, true), event); |
| 767 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 768 | } |
| 769 | |
Adam Powell | 5fcf5b9 | 2013-09-11 08:45:36 -0700 | [diff] [blame] | 770 | private void openPanel(final PanelFeatureState st, KeyEvent event) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 771 | // System.out.println("Open panel: isOpen=" + st.isOpen); |
| 772 | |
| 773 | // Already open, return |
Dianne Hackborn | b66ad57 | 2011-03-01 17:10:30 -0800 | [diff] [blame] | 774 | if (st.isOpen || isDestroyed()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 775 | return; |
| 776 | } |
| 777 | |
Adam Powell | 0d69fae | 2011-01-08 15:07:08 -0800 | [diff] [blame] | 778 | // Don't open an options panel for honeycomb apps on xlarge devices. |
| 779 | // (The app should be using an action bar for menu items.) |
| 780 | if (st.featureId == FEATURE_OPTIONS_PANEL) { |
| 781 | Context context = getContext(); |
| 782 | Configuration config = context.getResources().getConfiguration(); |
| 783 | boolean isXLarge = (config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == |
| 784 | Configuration.SCREENLAYOUT_SIZE_XLARGE; |
| 785 | boolean isHoneycombApp = context.getApplicationInfo().targetSdkVersion >= |
| 786 | android.os.Build.VERSION_CODES.HONEYCOMB; |
| 787 | |
| 788 | if (isXLarge && isHoneycombApp) { |
| 789 | return; |
| 790 | } |
| 791 | } |
| 792 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 793 | Callback cb = getCallback(); |
| 794 | if ((cb != null) && (!cb.onMenuOpened(st.featureId, st.menu))) { |
| 795 | // Callback doesn't want the menu to open, reset any state |
| 796 | closePanel(st, true); |
| 797 | return; |
| 798 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 799 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 800 | final WindowManager wm = getWindowManager(); |
| 801 | if (wm == null) { |
| 802 | return; |
| 803 | } |
| 804 | |
| 805 | // Prepare panel (should have been done before, but just in case) |
| 806 | if (!preparePanel(st, event)) { |
| 807 | return; |
| 808 | } |
| 809 | |
Adam Powell | a3e3c53 | 2011-06-22 11:21:54 -0700 | [diff] [blame] | 810 | int width = WRAP_CONTENT; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 811 | if (st.decorView == null || st.refreshDecorView) { |
| 812 | if (st.decorView == null) { |
| 813 | // Initialize the panel decor, this will populate st.decorView |
| 814 | if (!initializePanelDecor(st) || (st.decorView == null)) |
| 815 | return; |
| 816 | } else if (st.refreshDecorView && (st.decorView.getChildCount() > 0)) { |
| 817 | // Decor needs refreshing, so remove its views |
| 818 | st.decorView.removeAllViews(); |
| 819 | } |
| 820 | |
| 821 | // This will populate st.shownPanelView |
Adam Powell | 526b931 | 2011-04-22 15:42:05 -0700 | [diff] [blame] | 822 | if (!initializePanelContent(st) || !st.hasPanelItems()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 823 | return; |
| 824 | } |
| 825 | |
| 826 | ViewGroup.LayoutParams lp = st.shownPanelView.getLayoutParams(); |
| 827 | if (lp == null) { |
| 828 | lp = new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT); |
| 829 | } |
| 830 | |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 831 | int backgroundResId; |
Romain Guy | cc6828c | 2010-01-08 15:06:37 -0800 | [diff] [blame] | 832 | if (lp.width == ViewGroup.LayoutParams.MATCH_PARENT) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 833 | // If the contents is fill parent for the width, set the |
| 834 | // corresponding background |
| 835 | backgroundResId = st.fullBackground; |
Adam Powell | a3e3c53 | 2011-06-22 11:21:54 -0700 | [diff] [blame] | 836 | width = MATCH_PARENT; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 837 | } else { |
| 838 | // Otherwise, set the normal panel background |
| 839 | backgroundResId = st.background; |
| 840 | } |
Alan Viverette | 8eea3ea | 2014-02-03 18:40:20 -0800 | [diff] [blame] | 841 | st.decorView.setWindowBackground(getContext().getDrawable( |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 842 | backgroundResId)); |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 843 | |
Adam Powell | a60314c | 2012-05-15 14:33:13 -0700 | [diff] [blame] | 844 | ViewParent shownPanelParent = st.shownPanelView.getParent(); |
| 845 | if (shownPanelParent != null && shownPanelParent instanceof ViewGroup) { |
| 846 | ((ViewGroup) shownPanelParent).removeView(st.shownPanelView); |
| 847 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 848 | st.decorView.addView(st.shownPanelView, lp); |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 849 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 850 | /* |
| 851 | * Give focus to the view, if it or one of its children does not |
| 852 | * already have it. |
| 853 | */ |
| 854 | if (!st.shownPanelView.hasFocus()) { |
| 855 | st.shownPanelView.requestFocus(); |
| 856 | } |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 857 | } else if (!st.isInListMode()) { |
Adam Powell | dc5facd | 2011-08-03 16:45:45 -0700 | [diff] [blame] | 858 | width = MATCH_PARENT; |
Adam Powell | 3429ff5 | 2011-08-18 18:32:48 -0700 | [diff] [blame] | 859 | } else if (st.createdPanelView != null) { |
| 860 | // If we already had a panel view, carry width=MATCH_PARENT through |
| 861 | // as we did above when it was created. |
| 862 | ViewGroup.LayoutParams lp = st.createdPanelView.getLayoutParams(); |
| 863 | if (lp != null && lp.width == ViewGroup.LayoutParams.MATCH_PARENT) { |
| 864 | width = MATCH_PARENT; |
| 865 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 866 | } |
| 867 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 868 | st.isHandled = false; |
| 869 | |
| 870 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
Adam Powell | a3e3c53 | 2011-06-22 11:21:54 -0700 | [diff] [blame] | 871 | width, WRAP_CONTENT, |
Dianne Hackborn | d371510 | 2009-09-15 19:28:03 -0700 | [diff] [blame] | 872 | st.x, st.y, WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG, |
Jeff Brown | 3cc321e | 2012-07-16 16:04:23 -0700 | [diff] [blame] | 873 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
Jeff Brown | 46e7529 | 2010-11-10 16:53:45 -0800 | [diff] [blame] | 874 | | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 875 | st.decorView.mDefaultOpacity); |
| 876 | |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 877 | if (st.isCompact) { |
| 878 | lp.gravity = getOptionsPanelGravity(); |
| 879 | sRotationWatcher.addWindow(this); |
| 880 | } else { |
| 881 | lp.gravity = st.gravity; |
| 882 | } |
| 883 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 884 | lp.windowAnimations = st.windowAnimations; |
Craig Mautner | 9b40728 | 2013-07-01 12:57:51 -0700 | [diff] [blame] | 885 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 886 | wm.addView(st.decorView, lp); |
Craig Mautner | 9b40728 | 2013-07-01 12:57:51 -0700 | [diff] [blame] | 887 | st.isOpen = true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 888 | // Log.v(TAG, "Adding main menu to window manager."); |
| 889 | } |
| 890 | |
| 891 | @Override |
| 892 | public final void closePanel(int featureId) { |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 893 | if (featureId == FEATURE_OPTIONS_PANEL && mDecorContentParent != null && |
| 894 | mDecorContentParent.canShowOverflowMenu() && |
Adam Powell | 5fcf5b9 | 2013-09-11 08:45:36 -0700 | [diff] [blame] | 895 | !ViewConfiguration.get(getContext()).hasPermanentMenuKey()) { |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 896 | mDecorContentParent.hideOverflowMenu(); |
Adam Powell | f75eeb2 | 2010-08-10 15:59:40 -0700 | [diff] [blame] | 897 | } else if (featureId == FEATURE_CONTEXT_MENU) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 898 | closeContextMenu(); |
| 899 | } else { |
| 900 | closePanel(getPanelState(featureId, true), true); |
| 901 | } |
| 902 | } |
| 903 | |
| 904 | /** |
| 905 | * Closes the given panel. |
| 906 | * |
| 907 | * @param st The panel to be closed. |
| 908 | * @param doCallback Whether to notify the callback that the panel was |
| 909 | * closed. If the panel is in the process of re-opening or |
| 910 | * opening another panel (e.g., menu opening a sub menu), the |
| 911 | * callback should not happen and this variable should be false. |
| 912 | * In addition, this method internally will only perform the |
| 913 | * callback if the panel is open. |
| 914 | */ |
| 915 | public final void closePanel(PanelFeatureState st, boolean doCallback) { |
| 916 | // System.out.println("Close panel: isOpen=" + st.isOpen); |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 917 | if (doCallback && st.featureId == FEATURE_OPTIONS_PANEL && |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 918 | mDecorContentParent != null && mDecorContentParent.isOverflowMenuShowing()) { |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 919 | checkCloseActionMenu(st.menu); |
| 920 | return; |
| 921 | } |
| 922 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 923 | final ViewManager wm = getWindowManager(); |
| 924 | if ((wm != null) && st.isOpen) { |
| 925 | if (st.decorView != null) { |
| 926 | wm.removeView(st.decorView); |
| 927 | // Log.v(TAG, "Removing main menu from window manager."); |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 928 | if (st.isCompact) { |
| 929 | sRotationWatcher.removeWindow(this); |
| 930 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | if (doCallback) { |
| 934 | callOnPanelClosed(st.featureId, st, null); |
| 935 | } |
| 936 | } |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 937 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 938 | st.isPrepared = false; |
| 939 | st.isHandled = false; |
| 940 | st.isOpen = false; |
| 941 | |
| 942 | // This view is no longer shown, so null it out |
| 943 | st.shownPanelView = null; |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 944 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 945 | if (st.isInExpandedMode) { |
| 946 | // Next time the menu opens, it should not be in expanded mode, so |
| 947 | // force a refresh of the decor |
| 948 | st.refreshDecorView = true; |
| 949 | st.isInExpandedMode = false; |
| 950 | } |
| 951 | |
| 952 | if (mPreparedPanel == st) { |
| 953 | mPreparedPanel = null; |
| 954 | mPanelChordingKey = 0; |
| 955 | } |
| 956 | } |
| 957 | |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 958 | void checkCloseActionMenu(Menu menu) { |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 959 | if (mClosingActionMenu) { |
| 960 | return; |
| 961 | } |
| 962 | |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 963 | mClosingActionMenu = true; |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 964 | mDecorContentParent.dismissPopups(); |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 965 | Callback cb = getCallback(); |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 966 | if (cb != null && !isDestroyed()) { |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 967 | cb.onPanelClosed(FEATURE_ACTION_BAR, menu); |
| 968 | } |
| 969 | mClosingActionMenu = false; |
| 970 | } |
| 971 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 972 | @Override |
| 973 | public final void togglePanel(int featureId, KeyEvent event) { |
| 974 | PanelFeatureState st = getPanelState(featureId, true); |
| 975 | if (st.isOpen) { |
| 976 | closePanel(st, true); |
| 977 | } else { |
| 978 | openPanel(st, event); |
| 979 | } |
| 980 | } |
| 981 | |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 982 | @Override |
| 983 | public void invalidatePanelMenu(int featureId) { |
Adam Powell | 4b6d93f | 2012-09-18 18:34:08 -0700 | [diff] [blame] | 984 | mInvalidatePanelMenuFeatures |= 1 << featureId; |
| 985 | |
| 986 | if (!mInvalidatePanelMenuPosted && mDecor != null) { |
| 987 | mDecor.postOnAnimation(mInvalidatePanelMenuRunnable); |
| 988 | mInvalidatePanelMenuPosted = true; |
| 989 | } |
| 990 | } |
| 991 | |
Adam Powell | 31c91c8 | 2014-08-22 17:20:00 -0700 | [diff] [blame] | 992 | void doPendingInvalidatePanelMenu() { |
| 993 | if (mInvalidatePanelMenuPosted) { |
| 994 | mDecor.removeCallbacks(mInvalidatePanelMenuRunnable); |
| 995 | mInvalidatePanelMenuRunnable.run(); |
| 996 | } |
| 997 | } |
| 998 | |
Adam Powell | 4b6d93f | 2012-09-18 18:34:08 -0700 | [diff] [blame] | 999 | void doInvalidatePanelMenu(int featureId) { |
Jose Lima | 7a22fc6 | 2015-01-23 17:24:22 -0800 | [diff] [blame] | 1000 | PanelFeatureState st = getPanelState(featureId, false); |
| 1001 | if (st == null) { |
| 1002 | return; |
| 1003 | } |
Adam Powell | 038f1c8 | 2011-07-21 14:28:10 -0700 | [diff] [blame] | 1004 | Bundle savedActionViewStates = null; |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 1005 | if (st.menu != null) { |
Adam Powell | 038f1c8 | 2011-07-21 14:28:10 -0700 | [diff] [blame] | 1006 | savedActionViewStates = new Bundle(); |
| 1007 | st.menu.saveActionViewStates(savedActionViewStates); |
| 1008 | if (savedActionViewStates.size() > 0) { |
| 1009 | st.frozenActionViewState = savedActionViewStates; |
| 1010 | } |
Adam Powell | 89b09da | 2011-07-27 11:55:29 -0700 | [diff] [blame] | 1011 | // This will be started again when the panel is prepared. |
| 1012 | st.menu.stopDispatchingItemsChanged(); |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 1013 | st.menu.clear(); |
| 1014 | } |
| 1015 | st.refreshMenuContent = true; |
| 1016 | st.refreshDecorView = true; |
Alan Viverette | eb1d379 | 2014-06-03 18:36:03 -0700 | [diff] [blame] | 1017 | |
Adam Powell | 96675b1 | 2010-06-10 18:58:59 -0700 | [diff] [blame] | 1018 | // Prepare the options panel if we have an action bar |
| 1019 | if ((featureId == FEATURE_ACTION_BAR || featureId == FEATURE_OPTIONS_PANEL) |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 1020 | && mDecorContentParent != null) { |
Adam Powell | 96675b1 | 2010-06-10 18:58:59 -0700 | [diff] [blame] | 1021 | st = getPanelState(Window.FEATURE_OPTIONS_PANEL, false); |
| 1022 | if (st != null) { |
| 1023 | st.isPrepared = false; |
| 1024 | preparePanel(st, null); |
| 1025 | } |
| 1026 | } |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 1027 | } |
Alan Viverette | eb1d379 | 2014-06-03 18:36:03 -0700 | [diff] [blame] | 1028 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1029 | /** |
| 1030 | * Called when the panel key is pushed down. |
| 1031 | * @param featureId The feature ID of the relevant panel (defaults to FEATURE_OPTIONS_PANEL}. |
| 1032 | * @param event The key event. |
| 1033 | * @return Whether the key was handled. |
| 1034 | */ |
| 1035 | public final boolean onKeyDownPanel(int featureId, KeyEvent event) { |
Dianne Hackborn | a207baa | 2009-09-13 16:14:44 -0700 | [diff] [blame] | 1036 | final int keyCode = event.getKeyCode(); |
Alan Viverette | eb1d379 | 2014-06-03 18:36:03 -0700 | [diff] [blame] | 1037 | |
Dianne Hackborn | a207baa | 2009-09-13 16:14:44 -0700 | [diff] [blame] | 1038 | if (event.getRepeatCount() == 0) { |
| 1039 | // The panel key was pushed, so set the chording key |
| 1040 | mPanelChordingKey = keyCode; |
Adam Powell | f6148c5 | 2010-08-11 21:10:16 -0700 | [diff] [blame] | 1041 | |
Jose Lima | 7a22fc6 | 2015-01-23 17:24:22 -0800 | [diff] [blame] | 1042 | PanelFeatureState st = getPanelState(featureId, false); |
| 1043 | if (st != null && !st.isOpen) { |
Dianne Hackborn | a207baa | 2009-09-13 16:14:44 -0700 | [diff] [blame] | 1044 | return preparePanel(st, event); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1045 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | return false; |
| 1049 | } |
| 1050 | |
| 1051 | /** |
| 1052 | * Called when the panel key is released. |
| 1053 | * @param featureId The feature ID of the relevant panel (defaults to FEATURE_OPTIONS_PANEL}. |
| 1054 | * @param event The key event. |
| 1055 | */ |
| 1056 | public final void onKeyUpPanel(int featureId, KeyEvent event) { |
| 1057 | // The panel key was released, so clear the chording key |
| 1058 | if (mPanelChordingKey != 0) { |
| 1059 | mPanelChordingKey = 0; |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 1060 | |
Jose Lima | 7a22fc6 | 2015-01-23 17:24:22 -0800 | [diff] [blame] | 1061 | final PanelFeatureState st = getPanelState(featureId, false); |
| 1062 | |
Clara Bayarri | 80c3856 | 2015-03-04 17:10:57 +0000 | [diff] [blame] | 1063 | if (event.isCanceled() || (mDecor != null && mDecor.mPrimaryActionMode != null) || |
Jose Lima | 7a22fc6 | 2015-01-23 17:24:22 -0800 | [diff] [blame] | 1064 | (st == null)) { |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 1065 | return; |
| 1066 | } |
Alan Viverette | eb1d379 | 2014-06-03 18:36:03 -0700 | [diff] [blame] | 1067 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1068 | boolean playSoundEffect = false; |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 1069 | if (featureId == FEATURE_OPTIONS_PANEL && mDecorContentParent != null && |
| 1070 | mDecorContentParent.canShowOverflowMenu() && |
Adam Powell | 5fcf5b9 | 2013-09-11 08:45:36 -0700 | [diff] [blame] | 1071 | !ViewConfiguration.get(getContext()).hasPermanentMenuKey()) { |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 1072 | if (!mDecorContentParent.isOverflowMenuShowing()) { |
| 1073 | if (!isDestroyed() && preparePanel(st, event)) { |
| 1074 | playSoundEffect = mDecorContentParent.showOverflowMenu(); |
Adam Powell | f6148c5 | 2010-08-11 21:10:16 -0700 | [diff] [blame] | 1075 | } |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 1076 | } else { |
| 1077 | playSoundEffect = mDecorContentParent.hideOverflowMenu(); |
Adam Powell | f6148c5 | 2010-08-11 21:10:16 -0700 | [diff] [blame] | 1078 | } |
| 1079 | } else { |
| 1080 | if (st.isOpen || st.isHandled) { |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 1081 | |
Adam Powell | f6148c5 | 2010-08-11 21:10:16 -0700 | [diff] [blame] | 1082 | // Play the sound effect if the user closed an open menu (and not if |
| 1083 | // they just released a menu shortcut) |
| 1084 | playSoundEffect = st.isOpen; |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 1085 | |
Adam Powell | f6148c5 | 2010-08-11 21:10:16 -0700 | [diff] [blame] | 1086 | // Close menu |
| 1087 | closePanel(st, true); |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 1088 | |
Adam Powell | f6148c5 | 2010-08-11 21:10:16 -0700 | [diff] [blame] | 1089 | } else if (st.isPrepared) { |
Adam Powell | c6d5188 | 2011-10-13 11:33:24 -0700 | [diff] [blame] | 1090 | boolean show = true; |
| 1091 | if (st.refreshMenuContent) { |
| 1092 | // Something may have invalidated the menu since we prepared it. |
| 1093 | // Re-prepare it to refresh. |
| 1094 | st.isPrepared = false; |
| 1095 | show = preparePanel(st, event); |
| 1096 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 1097 | |
Adam Powell | c6d5188 | 2011-10-13 11:33:24 -0700 | [diff] [blame] | 1098 | if (show) { |
| 1099 | // Write 'menu opened' to event log |
| 1100 | EventLog.writeEvent(50001, 0); |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 1101 | |
Adam Powell | c6d5188 | 2011-10-13 11:33:24 -0700 | [diff] [blame] | 1102 | // Show menu |
| 1103 | openPanel(st, event); |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 1104 | |
Adam Powell | c6d5188 | 2011-10-13 11:33:24 -0700 | [diff] [blame] | 1105 | playSoundEffect = true; |
| 1106 | } |
Adam Powell | f6148c5 | 2010-08-11 21:10:16 -0700 | [diff] [blame] | 1107 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1108 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 1109 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1110 | if (playSoundEffect) { |
| 1111 | AudioManager audioManager = (AudioManager) getContext().getSystemService( |
| 1112 | Context.AUDIO_SERVICE); |
| 1113 | if (audioManager != null) { |
| 1114 | audioManager.playSoundEffect(AudioManager.FX_KEY_CLICK); |
| 1115 | } else { |
| 1116 | Log.w(TAG, "Couldn't get audio manager"); |
| 1117 | } |
| 1118 | } |
| 1119 | } |
| 1120 | } |
| 1121 | |
| 1122 | @Override |
| 1123 | public final void closeAllPanels() { |
| 1124 | final ViewManager wm = getWindowManager(); |
| 1125 | if (wm == null) { |
| 1126 | return; |
| 1127 | } |
| 1128 | |
| 1129 | final PanelFeatureState[] panels = mPanels; |
| 1130 | final int N = panels != null ? panels.length : 0; |
| 1131 | for (int i = 0; i < N; i++) { |
| 1132 | final PanelFeatureState panel = panels[i]; |
| 1133 | if (panel != null) { |
| 1134 | closePanel(panel, true); |
| 1135 | } |
| 1136 | } |
| 1137 | |
| 1138 | closeContextMenu(); |
| 1139 | } |
| 1140 | |
| 1141 | /** |
| 1142 | * Closes the context menu. This notifies the menu logic of the close, along |
| 1143 | * with dismissing it from the UI. |
| 1144 | */ |
| 1145 | private synchronized void closeContextMenu() { |
| 1146 | if (mContextMenu != null) { |
| 1147 | mContextMenu.close(); |
| 1148 | dismissContextMenu(); |
| 1149 | } |
| 1150 | } |
| 1151 | |
| 1152 | /** |
| 1153 | * Dismisses just the context menu UI. To close the context menu, use |
| 1154 | * {@link #closeContextMenu()}. |
| 1155 | */ |
| 1156 | private synchronized void dismissContextMenu() { |
| 1157 | mContextMenu = null; |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 1158 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1159 | if (mContextMenuHelper != null) { |
| 1160 | mContextMenuHelper.dismiss(); |
| 1161 | mContextMenuHelper = null; |
| 1162 | } |
| 1163 | } |
| 1164 | |
| 1165 | @Override |
| 1166 | public boolean performPanelShortcut(int featureId, int keyCode, KeyEvent event, int flags) { |
Jose Lima | 7a22fc6 | 2015-01-23 17:24:22 -0800 | [diff] [blame] | 1167 | return performPanelShortcut(getPanelState(featureId, false), keyCode, event, flags); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1168 | } |
| 1169 | |
Wale Ogunwale | 8804af2 | 2015-11-17 09:18:15 -0800 | [diff] [blame] | 1170 | boolean performPanelShortcut(PanelFeatureState st, int keyCode, KeyEvent event, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1171 | int flags) { |
| 1172 | if (event.isSystem() || (st == null)) { |
| 1173 | return false; |
| 1174 | } |
| 1175 | |
| 1176 | boolean handled = false; |
| 1177 | |
| 1178 | // Only try to perform menu shortcuts if preparePanel returned true (possible false |
| 1179 | // return value from application not wanting to show the menu). |
| 1180 | if ((st.isPrepared || preparePanel(st, event)) && st.menu != null) { |
| 1181 | // The menu is prepared now, perform the shortcut on it |
| 1182 | handled = st.menu.performShortcut(keyCode, event, flags); |
| 1183 | } |
| 1184 | |
| 1185 | if (handled) { |
| 1186 | // Mark as handled |
| 1187 | st.isHandled = true; |
| 1188 | |
Adam Powell | 6055f3e | 2011-08-28 14:20:24 -0700 | [diff] [blame] | 1189 | // Only close down the menu if we don't have an action bar keeping it open. |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 1190 | if ((flags & Menu.FLAG_PERFORM_NO_CLOSE) == 0 && mDecorContentParent == null) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1191 | closePanel(st, true); |
| 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | return handled; |
| 1196 | } |
| 1197 | |
| 1198 | @Override |
| 1199 | public boolean performPanelIdentifierAction(int featureId, int id, int flags) { |
| 1200 | |
| 1201 | PanelFeatureState st = getPanelState(featureId, true); |
| 1202 | if (!preparePanel(st, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MENU))) { |
| 1203 | return false; |
| 1204 | } |
| 1205 | if (st.menu == null) { |
| 1206 | return false; |
| 1207 | } |
| 1208 | |
| 1209 | boolean res = st.menu.performIdentifierAction(id, flags); |
| 1210 | |
Adam Powell | 6055f3e | 2011-08-28 14:20:24 -0700 | [diff] [blame] | 1211 | // Only close down the menu if we don't have an action bar keeping it open. |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 1212 | if (mDecorContentParent == null) { |
Adam Powell | 6055f3e | 2011-08-28 14:20:24 -0700 | [diff] [blame] | 1213 | closePanel(st, true); |
| 1214 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1215 | |
| 1216 | return res; |
| 1217 | } |
| 1218 | |
| 1219 | public PanelFeatureState findMenuPanel(Menu menu) { |
| 1220 | final PanelFeatureState[] panels = mPanels; |
| 1221 | final int N = panels != null ? panels.length : 0; |
| 1222 | for (int i = 0; i < N; i++) { |
| 1223 | final PanelFeatureState panel = panels[i]; |
| 1224 | if (panel != null && panel.menu == menu) { |
| 1225 | return panel; |
| 1226 | } |
| 1227 | } |
| 1228 | return null; |
| 1229 | } |
| 1230 | |
| 1231 | public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) { |
| 1232 | final Callback cb = getCallback(); |
Dianne Hackborn | b66ad57 | 2011-03-01 17:10:30 -0800 | [diff] [blame] | 1233 | if (cb != null && !isDestroyed()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1234 | final PanelFeatureState panel = findMenuPanel(menu.getRootMenu()); |
| 1235 | if (panel != null) { |
| 1236 | return cb.onMenuItemSelected(panel.featureId, item); |
| 1237 | } |
| 1238 | } |
| 1239 | return false; |
| 1240 | } |
| 1241 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1242 | public void onMenuModeChange(MenuBuilder menu) { |
| 1243 | reopenMenu(true); |
| 1244 | } |
| 1245 | |
| 1246 | private void reopenMenu(boolean toggleMenuMode) { |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 1247 | if (mDecorContentParent != null && mDecorContentParent.canShowOverflowMenu() && |
Adam Powell | 5fcf5b9 | 2013-09-11 08:45:36 -0700 | [diff] [blame] | 1248 | (!ViewConfiguration.get(getContext()).hasPermanentMenuKey() || |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 1249 | mDecorContentParent.isOverflowMenuShowPending())) { |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 1250 | final Callback cb = getCallback(); |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 1251 | if (!mDecorContentParent.isOverflowMenuShowing() || !toggleMenuMode) { |
| 1252 | if (cb != null && !isDestroyed()) { |
Adam Powell | 5c8f9b5 | 2013-03-27 12:22:27 -0700 | [diff] [blame] | 1253 | // If we have a menu invalidation pending, do it now. |
| 1254 | if (mInvalidatePanelMenuPosted && |
| 1255 | (mInvalidatePanelMenuFeatures & (1 << FEATURE_OPTIONS_PANEL)) != 0) { |
| 1256 | mDecor.removeCallbacks(mInvalidatePanelMenuRunnable); |
| 1257 | mInvalidatePanelMenuRunnable.run(); |
| 1258 | } |
| 1259 | |
Jose Lima | 7a22fc6 | 2015-01-23 17:24:22 -0800 | [diff] [blame] | 1260 | final PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, false); |
Adam Powell | 6a5b0a3 | 2012-09-28 14:24:48 -0700 | [diff] [blame] | 1261 | |
| 1262 | // If we don't have a menu or we're waiting for a full content refresh, |
| 1263 | // forget it. This is a lingering event that no longer matters. |
Jose Lima | 7a22fc6 | 2015-01-23 17:24:22 -0800 | [diff] [blame] | 1264 | if (st != null && st.menu != null && !st.refreshMenuContent && |
Adam Powell | 6a5b0a3 | 2012-09-28 14:24:48 -0700 | [diff] [blame] | 1265 | cb.onPreparePanel(FEATURE_OPTIONS_PANEL, st.createdPanelView, st.menu)) { |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 1266 | cb.onMenuOpened(FEATURE_ACTION_BAR, st.menu); |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 1267 | mDecorContentParent.showOverflowMenu(); |
Adam Powell | f6148c5 | 2010-08-11 21:10:16 -0700 | [diff] [blame] | 1268 | } |
| 1269 | } |
| 1270 | } else { |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 1271 | mDecorContentParent.hideOverflowMenu(); |
Jose Lima | 7a22fc6 | 2015-01-23 17:24:22 -0800 | [diff] [blame] | 1272 | final PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, false); |
| 1273 | if (st != null && cb != null && !isDestroyed()) { |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 1274 | cb.onPanelClosed(FEATURE_ACTION_BAR, st.menu); |
| 1275 | } |
Adam Powell | f6148c5 | 2010-08-11 21:10:16 -0700 | [diff] [blame] | 1276 | } |
| 1277 | return; |
| 1278 | } |
| 1279 | |
Jose Lima | 7a22fc6 | 2015-01-23 17:24:22 -0800 | [diff] [blame] | 1280 | PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, false); |
| 1281 | |
| 1282 | if (st == null) { |
| 1283 | return; |
| 1284 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1285 | |
| 1286 | // Save the future expanded mode state since closePanel will reset it |
| 1287 | boolean newExpandedMode = toggleMenuMode ? !st.isInExpandedMode : st.isInExpandedMode; |
| 1288 | |
| 1289 | st.refreshDecorView = true; |
| 1290 | closePanel(st, false); |
| 1291 | |
| 1292 | // Set the expanded mode state |
| 1293 | st.isInExpandedMode = newExpandedMode; |
| 1294 | |
| 1295 | openPanel(st, null); |
| 1296 | } |
| 1297 | |
| 1298 | /** |
| 1299 | * Initializes the menu associated with the given panel feature state. You |
| 1300 | * must at the very least set PanelFeatureState.menu to the Menu to be |
| 1301 | * associated with the given panel state. The default implementation creates |
| 1302 | * a new menu for the panel state. |
| 1303 | * |
| 1304 | * @param st The panel whose menu is being initialized. |
| 1305 | * @return Whether the initialization was successful. |
| 1306 | */ |
| 1307 | protected boolean initializePanelMenu(final PanelFeatureState st) { |
Adam Powell | d65b3b9 | 2011-09-22 16:38:11 -0700 | [diff] [blame] | 1308 | Context context = getContext(); |
| 1309 | |
Alan Viverette | eb1d379 | 2014-06-03 18:36:03 -0700 | [diff] [blame] | 1310 | // If we have an action bar, initialize the menu with the right theme. |
Adam Powell | d65b3b9 | 2011-09-22 16:38:11 -0700 | [diff] [blame] | 1311 | if ((st.featureId == FEATURE_OPTIONS_PANEL || st.featureId == FEATURE_ACTION_BAR) && |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 1312 | mDecorContentParent != null) { |
Alan Viverette | 4b002d3 | 2014-06-03 17:32:19 -0700 | [diff] [blame] | 1313 | final TypedValue outValue = new TypedValue(); |
| 1314 | final Theme baseTheme = context.getTheme(); |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 1315 | baseTheme.resolveAttribute(R.attr.actionBarTheme, outValue, true); |
Adam Powell | d65b3b9 | 2011-09-22 16:38:11 -0700 | [diff] [blame] | 1316 | |
Alan Viverette | 4b002d3 | 2014-06-03 17:32:19 -0700 | [diff] [blame] | 1317 | Theme widgetTheme = null; |
| 1318 | if (outValue.resourceId != 0) { |
| 1319 | widgetTheme = context.getResources().newTheme(); |
| 1320 | widgetTheme.setTo(baseTheme); |
| 1321 | widgetTheme.applyStyle(outValue.resourceId, true); |
| 1322 | widgetTheme.resolveAttribute( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 1323 | R.attr.actionBarWidgetTheme, outValue, true); |
Alan Viverette | 4b002d3 | 2014-06-03 17:32:19 -0700 | [diff] [blame] | 1324 | } else { |
| 1325 | baseTheme.resolveAttribute( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 1326 | R.attr.actionBarWidgetTheme, outValue, true); |
Alan Viverette | 4b002d3 | 2014-06-03 17:32:19 -0700 | [diff] [blame] | 1327 | } |
| 1328 | |
| 1329 | if (outValue.resourceId != 0) { |
| 1330 | if (widgetTheme == null) { |
| 1331 | widgetTheme = context.getResources().newTheme(); |
| 1332 | widgetTheme.setTo(baseTheme); |
| 1333 | } |
| 1334 | widgetTheme.applyStyle(outValue.resourceId, true); |
| 1335 | } |
| 1336 | |
| 1337 | if (widgetTheme != null) { |
| 1338 | context = new ContextThemeWrapper(context, 0); |
| 1339 | context.getTheme().setTo(widgetTheme); |
Adam Powell | d65b3b9 | 2011-09-22 16:38:11 -0700 | [diff] [blame] | 1340 | } |
| 1341 | } |
| 1342 | |
| 1343 | final MenuBuilder menu = new MenuBuilder(context); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1344 | menu.setCallback(this); |
| 1345 | st.setMenu(menu); |
| 1346 | |
| 1347 | return true; |
| 1348 | } |
| 1349 | |
| 1350 | /** |
| 1351 | * Perform initial setup of a panel. This should at the very least set the |
| 1352 | * style information in the PanelFeatureState and must set |
| 1353 | * PanelFeatureState.decor to the panel's window decor view. |
| 1354 | * |
| 1355 | * @param st The panel being initialized. |
| 1356 | */ |
| 1357 | protected boolean initializePanelDecor(PanelFeatureState st) { |
Stefan Kuhne | 61b47bb | 2015-07-28 14:04:25 -0700 | [diff] [blame] | 1358 | st.decorView = generateDecor(st.featureId); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1359 | st.gravity = Gravity.CENTER | Gravity.BOTTOM; |
| 1360 | st.setStyle(getContext()); |
Adam Powell | 594558d | 2014-09-18 18:22:29 -0700 | [diff] [blame] | 1361 | TypedArray a = getContext().obtainStyledAttributes(null, |
| 1362 | R.styleable.Window, 0, st.listPresenterTheme); |
| 1363 | final float elevation = a.getDimension(R.styleable.Window_windowElevation, 0); |
| 1364 | if (elevation != 0) { |
| 1365 | st.decorView.setElevation(elevation); |
| 1366 | } |
| 1367 | a.recycle(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1368 | |
| 1369 | return true; |
| 1370 | } |
| 1371 | |
| 1372 | /** |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 1373 | * Determine the gravity value for the options panel. This can |
| 1374 | * differ in compact mode. |
| 1375 | * |
| 1376 | * @return gravity value to use for the panel window |
| 1377 | */ |
| 1378 | private int getOptionsPanelGravity() { |
| 1379 | try { |
| 1380 | return WindowManagerHolder.sWindowManager.getPreferredOptionsPanelGravity(); |
| 1381 | } catch (RemoteException ex) { |
| 1382 | Log.e(TAG, "Couldn't getOptionsPanelGravity; using default", ex); |
| 1383 | return Gravity.CENTER | Gravity.BOTTOM; |
| 1384 | } |
| 1385 | } |
| 1386 | |
| 1387 | void onOptionsPanelRotationChanged() { |
| 1388 | final PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, false); |
| 1389 | if (st == null) return; |
| 1390 | |
| 1391 | final WindowManager.LayoutParams lp = st.decorView != null ? |
| 1392 | (WindowManager.LayoutParams) st.decorView.getLayoutParams() : null; |
| 1393 | if (lp != null) { |
| 1394 | lp.gravity = getOptionsPanelGravity(); |
| 1395 | final ViewManager wm = getWindowManager(); |
| 1396 | if (wm != null) { |
| 1397 | wm.updateViewLayout(st.decorView, lp); |
| 1398 | } |
| 1399 | } |
| 1400 | } |
| 1401 | |
| 1402 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1403 | * Initializes the panel associated with the panel feature state. You must |
| 1404 | * at the very least set PanelFeatureState.panel to the View implementing |
| 1405 | * its contents. The default implementation gets the panel from the menu. |
| 1406 | * |
| 1407 | * @param st The panel state being initialized. |
| 1408 | * @return Whether the initialization was successful. |
| 1409 | */ |
| 1410 | protected boolean initializePanelContent(PanelFeatureState st) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1411 | if (st.createdPanelView != null) { |
| 1412 | st.shownPanelView = st.createdPanelView; |
| 1413 | return true; |
| 1414 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 1415 | |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 1416 | if (st.menu == null) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1417 | return false; |
| 1418 | } |
| 1419 | |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 1420 | if (mPanelMenuPresenterCallback == null) { |
| 1421 | mPanelMenuPresenterCallback = new PanelMenuPresenterCallback(); |
| 1422 | } |
| 1423 | |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 1424 | MenuView menuView = st.isInListMode() |
Adam Powell | 538e565 | 2011-10-11 13:47:08 -0700 | [diff] [blame] | 1425 | ? st.getListMenuView(getContext(), mPanelMenuPresenterCallback) |
| 1426 | : st.getIconMenuView(getContext(), mPanelMenuPresenterCallback); |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 1427 | |
| 1428 | st.shownPanelView = (View) menuView; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1429 | |
| 1430 | if (st.shownPanelView != null) { |
| 1431 | // Use the menu View's default animations if it has any |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 1432 | final int defaultAnimations = menuView.getWindowAnimations(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1433 | if (defaultAnimations != 0) { |
| 1434 | st.windowAnimations = defaultAnimations; |
| 1435 | } |
| 1436 | return true; |
| 1437 | } else { |
| 1438 | return false; |
| 1439 | } |
| 1440 | } |
| 1441 | |
| 1442 | @Override |
| 1443 | public boolean performContextMenuIdentifierAction(int id, int flags) { |
| 1444 | return (mContextMenu != null) ? mContextMenu.performIdentifierAction(id, flags) : false; |
| 1445 | } |
| 1446 | |
| 1447 | @Override |
Alan Viverette | 79c067c5 | 2014-10-29 14:27:47 -0700 | [diff] [blame] | 1448 | public final void setElevation(float elevation) { |
| 1449 | mElevation = elevation; |
Wale Ogunwale | 246c209 | 2016-04-07 14:12:44 -0700 | [diff] [blame] | 1450 | final WindowManager.LayoutParams attrs = getAttributes(); |
Alan Viverette | 79c067c5 | 2014-10-29 14:27:47 -0700 | [diff] [blame] | 1451 | if (mDecor != null) { |
| 1452 | mDecor.setElevation(elevation); |
Wale Ogunwale | 246c209 | 2016-04-07 14:12:44 -0700 | [diff] [blame] | 1453 | attrs.setSurfaceInsets(mDecor, true /*manual*/, false /*preservePrevious*/); |
Alan Viverette | 79c067c5 | 2014-10-29 14:27:47 -0700 | [diff] [blame] | 1454 | } |
Wale Ogunwale | 246c209 | 2016-04-07 14:12:44 -0700 | [diff] [blame] | 1455 | dispatchWindowAttributesChanged(attrs); |
Alan Viverette | 79c067c5 | 2014-10-29 14:27:47 -0700 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | @Override |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 1459 | public float getElevation() { |
| 1460 | return mElevation; |
| 1461 | } |
| 1462 | |
| 1463 | @Override |
Alan Viverette | 79c067c5 | 2014-10-29 14:27:47 -0700 | [diff] [blame] | 1464 | public final void setClipToOutline(boolean clipToOutline) { |
| 1465 | mClipToOutline = clipToOutline; |
| 1466 | if (mDecor != null) { |
| 1467 | mDecor.setClipToOutline(clipToOutline); |
| 1468 | } |
| 1469 | } |
| 1470 | |
| 1471 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1472 | public final void setBackgroundDrawable(Drawable drawable) { |
Dianne Hackborn | a7c176c | 2009-06-22 20:56:57 -0700 | [diff] [blame] | 1473 | if (drawable != mBackgroundDrawable || mBackgroundResource != 0) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1474 | mBackgroundResource = 0; |
| 1475 | mBackgroundDrawable = drawable; |
| 1476 | if (mDecor != null) { |
| 1477 | mDecor.setWindowBackground(drawable); |
| 1478 | } |
Adam Powell | f849a5e | 2014-09-11 15:09:36 -0700 | [diff] [blame] | 1479 | if (mBackgroundFallbackResource != 0) { |
| 1480 | mDecor.setBackgroundFallback(drawable != null ? 0 : mBackgroundFallbackResource); |
| 1481 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1482 | } |
| 1483 | } |
| 1484 | |
| 1485 | @Override |
| 1486 | public final void setFeatureDrawableResource(int featureId, int resId) { |
| 1487 | if (resId != 0) { |
| 1488 | DrawableFeatureState st = getDrawableState(featureId, true); |
| 1489 | if (st.resid != resId) { |
| 1490 | st.resid = resId; |
| 1491 | st.uri = null; |
Alan Viverette | 8eea3ea | 2014-02-03 18:40:20 -0800 | [diff] [blame] | 1492 | st.local = getContext().getDrawable(resId); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1493 | updateDrawable(featureId, st, false); |
| 1494 | } |
| 1495 | } else { |
| 1496 | setFeatureDrawable(featureId, null); |
| 1497 | } |
| 1498 | } |
| 1499 | |
| 1500 | @Override |
| 1501 | public final void setFeatureDrawableUri(int featureId, Uri uri) { |
| 1502 | if (uri != null) { |
| 1503 | DrawableFeatureState st = getDrawableState(featureId, true); |
| 1504 | if (st.uri == null || !st.uri.equals(uri)) { |
| 1505 | st.resid = 0; |
| 1506 | st.uri = uri; |
| 1507 | st.local = loadImageURI(uri); |
| 1508 | updateDrawable(featureId, st, false); |
| 1509 | } |
| 1510 | } else { |
| 1511 | setFeatureDrawable(featureId, null); |
| 1512 | } |
| 1513 | } |
| 1514 | |
| 1515 | @Override |
| 1516 | public final void setFeatureDrawable(int featureId, Drawable drawable) { |
| 1517 | DrawableFeatureState st = getDrawableState(featureId, true); |
| 1518 | st.resid = 0; |
| 1519 | st.uri = null; |
| 1520 | if (st.local != drawable) { |
| 1521 | st.local = drawable; |
| 1522 | updateDrawable(featureId, st, false); |
| 1523 | } |
| 1524 | } |
| 1525 | |
| 1526 | @Override |
| 1527 | public void setFeatureDrawableAlpha(int featureId, int alpha) { |
| 1528 | DrawableFeatureState st = getDrawableState(featureId, true); |
| 1529 | if (st.alpha != alpha) { |
| 1530 | st.alpha = alpha; |
| 1531 | updateDrawable(featureId, st, false); |
| 1532 | } |
| 1533 | } |
| 1534 | |
| 1535 | protected final void setFeatureDefaultDrawable(int featureId, Drawable drawable) { |
| 1536 | DrawableFeatureState st = getDrawableState(featureId, true); |
| 1537 | if (st.def != drawable) { |
| 1538 | st.def = drawable; |
| 1539 | updateDrawable(featureId, st, false); |
| 1540 | } |
| 1541 | } |
| 1542 | |
| 1543 | @Override |
| 1544 | public final void setFeatureInt(int featureId, int value) { |
| 1545 | // XXX Should do more management (as with drawable features) to |
| 1546 | // deal with interactions between multiple window policies. |
| 1547 | updateInt(featureId, value, false); |
| 1548 | } |
| 1549 | |
| 1550 | /** |
| 1551 | * Update the state of a drawable feature. This should be called, for every |
| 1552 | * drawable feature supported, as part of onActive(), to make sure that the |
| 1553 | * contents of a containing window is properly updated. |
| 1554 | * |
| 1555 | * @see #onActive |
| 1556 | * @param featureId The desired drawable feature to change. |
| 1557 | * @param fromActive Always true when called from onActive(). |
| 1558 | */ |
| 1559 | protected final void updateDrawable(int featureId, boolean fromActive) { |
| 1560 | final DrawableFeatureState st = getDrawableState(featureId, false); |
| 1561 | if (st != null) { |
| 1562 | updateDrawable(featureId, st, fromActive); |
| 1563 | } |
| 1564 | } |
| 1565 | |
| 1566 | /** |
| 1567 | * Called when a Drawable feature changes, for the window to update its |
| 1568 | * graphics. |
| 1569 | * |
| 1570 | * @param featureId The feature being changed. |
| 1571 | * @param drawable The new Drawable to show, or null if none. |
| 1572 | * @param alpha The new alpha blending of the Drawable. |
| 1573 | */ |
| 1574 | protected void onDrawableChanged(int featureId, Drawable drawable, int alpha) { |
| 1575 | ImageView view; |
| 1576 | if (featureId == FEATURE_LEFT_ICON) { |
| 1577 | view = getLeftIconView(); |
| 1578 | } else if (featureId == FEATURE_RIGHT_ICON) { |
| 1579 | view = getRightIconView(); |
| 1580 | } else { |
| 1581 | return; |
| 1582 | } |
| 1583 | |
| 1584 | if (drawable != null) { |
| 1585 | drawable.setAlpha(alpha); |
| 1586 | view.setImageDrawable(drawable); |
| 1587 | view.setVisibility(View.VISIBLE); |
| 1588 | } else { |
| 1589 | view.setVisibility(View.GONE); |
| 1590 | } |
| 1591 | } |
| 1592 | |
| 1593 | /** |
| 1594 | * Called when an int feature changes, for the window to update its |
| 1595 | * graphics. |
| 1596 | * |
| 1597 | * @param featureId The feature being changed. |
| 1598 | * @param value The new integer value. |
| 1599 | */ |
| 1600 | protected void onIntChanged(int featureId, int value) { |
| 1601 | if (featureId == FEATURE_PROGRESS || featureId == FEATURE_INDETERMINATE_PROGRESS) { |
| 1602 | updateProgressBars(value); |
| 1603 | } else if (featureId == FEATURE_CUSTOM_TITLE) { |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 1604 | FrameLayout titleContainer = findViewById(R.id.title_container); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1605 | if (titleContainer != null) { |
| 1606 | mLayoutInflater.inflate(value, titleContainer); |
| 1607 | } |
| 1608 | } |
| 1609 | } |
| 1610 | |
| 1611 | /** |
| 1612 | * Updates the progress bars that are shown in the title bar. |
| 1613 | * |
| 1614 | * @param value Can be one of {@link Window#PROGRESS_VISIBILITY_ON}, |
| 1615 | * {@link Window#PROGRESS_VISIBILITY_OFF}, |
| 1616 | * {@link Window#PROGRESS_INDETERMINATE_ON}, |
| 1617 | * {@link Window#PROGRESS_INDETERMINATE_OFF}, or a value |
| 1618 | * starting at {@link Window#PROGRESS_START} through |
| 1619 | * {@link Window#PROGRESS_END} for setting the default |
| 1620 | * progress (if {@link Window#PROGRESS_END} is given, |
| 1621 | * the progress bar widgets in the title will be hidden after an |
| 1622 | * animation), a value between |
| 1623 | * {@link Window#PROGRESS_SECONDARY_START} - |
| 1624 | * {@link Window#PROGRESS_SECONDARY_END} for the |
| 1625 | * secondary progress (if |
| 1626 | * {@link Window#PROGRESS_SECONDARY_END} is given, the |
| 1627 | * progress bar widgets will still be shown with the secondary |
| 1628 | * progress bar will be completely filled in.) |
| 1629 | */ |
| 1630 | private void updateProgressBars(int value) { |
| 1631 | ProgressBar circularProgressBar = getCircularProgressBar(true); |
| 1632 | ProgressBar horizontalProgressBar = getHorizontalProgressBar(true); |
| 1633 | |
| 1634 | final int features = getLocalFeatures(); |
| 1635 | if (value == PROGRESS_VISIBILITY_ON) { |
| 1636 | if ((features & (1 << FEATURE_PROGRESS)) != 0) { |
Adam Powell | eec8f0c | 2014-05-30 11:00:00 -0700 | [diff] [blame] | 1637 | if (horizontalProgressBar != null) { |
| 1638 | int level = horizontalProgressBar.getProgress(); |
| 1639 | int visibility = (horizontalProgressBar.isIndeterminate() || level < 10000) ? |
| 1640 | View.VISIBLE : View.INVISIBLE; |
| 1641 | horizontalProgressBar.setVisibility(visibility); |
| 1642 | } else { |
| 1643 | Log.e(TAG, "Horizontal progress bar not located in current window decor"); |
| 1644 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1645 | } |
| 1646 | if ((features & (1 << FEATURE_INDETERMINATE_PROGRESS)) != 0) { |
Adam Powell | eec8f0c | 2014-05-30 11:00:00 -0700 | [diff] [blame] | 1647 | if (circularProgressBar != null) { |
| 1648 | circularProgressBar.setVisibility(View.VISIBLE); |
| 1649 | } else { |
| 1650 | Log.e(TAG, "Circular progress bar not located in current window decor"); |
| 1651 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1652 | } |
| 1653 | } else if (value == PROGRESS_VISIBILITY_OFF) { |
| 1654 | if ((features & (1 << FEATURE_PROGRESS)) != 0) { |
Adam Powell | eec8f0c | 2014-05-30 11:00:00 -0700 | [diff] [blame] | 1655 | if (horizontalProgressBar != null) { |
| 1656 | horizontalProgressBar.setVisibility(View.GONE); |
| 1657 | } else { |
| 1658 | Log.e(TAG, "Horizontal progress bar not located in current window decor"); |
| 1659 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1660 | } |
| 1661 | if ((features & (1 << FEATURE_INDETERMINATE_PROGRESS)) != 0) { |
Adam Powell | eec8f0c | 2014-05-30 11:00:00 -0700 | [diff] [blame] | 1662 | if (circularProgressBar != null) { |
| 1663 | circularProgressBar.setVisibility(View.GONE); |
| 1664 | } else { |
| 1665 | Log.e(TAG, "Circular progress bar not located in current window decor"); |
| 1666 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1667 | } |
| 1668 | } else if (value == PROGRESS_INDETERMINATE_ON) { |
Adam Powell | eec8f0c | 2014-05-30 11:00:00 -0700 | [diff] [blame] | 1669 | if (horizontalProgressBar != null) { |
| 1670 | horizontalProgressBar.setIndeterminate(true); |
| 1671 | } else { |
| 1672 | Log.e(TAG, "Horizontal progress bar not located in current window decor"); |
| 1673 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1674 | } else if (value == PROGRESS_INDETERMINATE_OFF) { |
Adam Powell | eec8f0c | 2014-05-30 11:00:00 -0700 | [diff] [blame] | 1675 | if (horizontalProgressBar != null) { |
| 1676 | horizontalProgressBar.setIndeterminate(false); |
| 1677 | } else { |
| 1678 | Log.e(TAG, "Horizontal progress bar not located in current window decor"); |
| 1679 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1680 | } else if (PROGRESS_START <= value && value <= PROGRESS_END) { |
| 1681 | // We want to set the progress value before testing for visibility |
| 1682 | // so that when the progress bar becomes visible again, it has the |
| 1683 | // correct level. |
Adam Powell | eec8f0c | 2014-05-30 11:00:00 -0700 | [diff] [blame] | 1684 | if (horizontalProgressBar != null) { |
| 1685 | horizontalProgressBar.setProgress(value - PROGRESS_START); |
| 1686 | } else { |
| 1687 | Log.e(TAG, "Horizontal progress bar not located in current window decor"); |
| 1688 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1689 | |
| 1690 | if (value < PROGRESS_END) { |
| 1691 | showProgressBars(horizontalProgressBar, circularProgressBar); |
| 1692 | } else { |
| 1693 | hideProgressBars(horizontalProgressBar, circularProgressBar); |
| 1694 | } |
| 1695 | } else if (PROGRESS_SECONDARY_START <= value && value <= PROGRESS_SECONDARY_END) { |
Adam Powell | eec8f0c | 2014-05-30 11:00:00 -0700 | [diff] [blame] | 1696 | if (horizontalProgressBar != null) { |
| 1697 | horizontalProgressBar.setSecondaryProgress(value - PROGRESS_SECONDARY_START); |
| 1698 | } else { |
| 1699 | Log.e(TAG, "Horizontal progress bar not located in current window decor"); |
| 1700 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1701 | |
| 1702 | showProgressBars(horizontalProgressBar, circularProgressBar); |
| 1703 | } |
| 1704 | |
| 1705 | } |
| 1706 | |
| 1707 | private void showProgressBars(ProgressBar horizontalProgressBar, ProgressBar spinnyProgressBar) { |
| 1708 | final int features = getLocalFeatures(); |
| 1709 | if ((features & (1 << FEATURE_INDETERMINATE_PROGRESS)) != 0 && |
Adam Powell | eec8f0c | 2014-05-30 11:00:00 -0700 | [diff] [blame] | 1710 | spinnyProgressBar != null && spinnyProgressBar.getVisibility() == View.INVISIBLE) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1711 | spinnyProgressBar.setVisibility(View.VISIBLE); |
| 1712 | } |
| 1713 | // Only show the progress bars if the primary progress is not complete |
Adam Powell | eec8f0c | 2014-05-30 11:00:00 -0700 | [diff] [blame] | 1714 | if ((features & (1 << FEATURE_PROGRESS)) != 0 && horizontalProgressBar != null && |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1715 | horizontalProgressBar.getProgress() < 10000) { |
| 1716 | horizontalProgressBar.setVisibility(View.VISIBLE); |
| 1717 | } |
| 1718 | } |
| 1719 | |
| 1720 | private void hideProgressBars(ProgressBar horizontalProgressBar, ProgressBar spinnyProgressBar) { |
| 1721 | final int features = getLocalFeatures(); |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 1722 | Animation anim = AnimationUtils.loadAnimation(getContext(), R.anim.fade_out); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1723 | anim.setDuration(1000); |
| 1724 | if ((features & (1 << FEATURE_INDETERMINATE_PROGRESS)) != 0 && |
Adam Powell | eec8f0c | 2014-05-30 11:00:00 -0700 | [diff] [blame] | 1725 | spinnyProgressBar != null && |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1726 | spinnyProgressBar.getVisibility() == View.VISIBLE) { |
| 1727 | spinnyProgressBar.startAnimation(anim); |
| 1728 | spinnyProgressBar.setVisibility(View.INVISIBLE); |
| 1729 | } |
Adam Powell | eec8f0c | 2014-05-30 11:00:00 -0700 | [diff] [blame] | 1730 | if ((features & (1 << FEATURE_PROGRESS)) != 0 && horizontalProgressBar != null && |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1731 | horizontalProgressBar.getVisibility() == View.VISIBLE) { |
| 1732 | horizontalProgressBar.startAnimation(anim); |
| 1733 | horizontalProgressBar.setVisibility(View.INVISIBLE); |
| 1734 | } |
| 1735 | } |
| 1736 | |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 1737 | @Override |
| 1738 | public void setIcon(int resId) { |
| 1739 | mIconRes = resId; |
| 1740 | mResourcesSetFlags |= FLAG_RESOURCE_SET_ICON; |
Adam Powell | 0a317e9 | 2013-06-13 13:15:43 -0700 | [diff] [blame] | 1741 | mResourcesSetFlags &= ~FLAG_RESOURCE_SET_ICON_FALLBACK; |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 1742 | if (mDecorContentParent != null) { |
| 1743 | mDecorContentParent.setIcon(resId); |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 1744 | } |
| 1745 | } |
| 1746 | |
| 1747 | @Override |
| 1748 | public void setDefaultIcon(int resId) { |
| 1749 | if ((mResourcesSetFlags & FLAG_RESOURCE_SET_ICON) != 0) { |
| 1750 | return; |
| 1751 | } |
| 1752 | mIconRes = resId; |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 1753 | if (mDecorContentParent != null && (!mDecorContentParent.hasIcon() || |
Adam Powell | 0a317e9 | 2013-06-13 13:15:43 -0700 | [diff] [blame] | 1754 | (mResourcesSetFlags & FLAG_RESOURCE_SET_ICON_FALLBACK) != 0)) { |
| 1755 | if (resId != 0) { |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 1756 | mDecorContentParent.setIcon(resId); |
Adam Powell | 0a317e9 | 2013-06-13 13:15:43 -0700 | [diff] [blame] | 1757 | mResourcesSetFlags &= ~FLAG_RESOURCE_SET_ICON_FALLBACK; |
| 1758 | } else { |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 1759 | mDecorContentParent.setIcon( |
| 1760 | getContext().getPackageManager().getDefaultActivityIcon()); |
Adam Powell | 0a317e9 | 2013-06-13 13:15:43 -0700 | [diff] [blame] | 1761 | mResourcesSetFlags |= FLAG_RESOURCE_SET_ICON_FALLBACK; |
| 1762 | } |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 1763 | } |
| 1764 | } |
| 1765 | |
| 1766 | @Override |
| 1767 | public void setLogo(int resId) { |
| 1768 | mLogoRes = resId; |
| 1769 | mResourcesSetFlags |= FLAG_RESOURCE_SET_LOGO; |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 1770 | if (mDecorContentParent != null) { |
| 1771 | mDecorContentParent.setLogo(resId); |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 1772 | } |
| 1773 | } |
| 1774 | |
| 1775 | @Override |
| 1776 | public void setDefaultLogo(int resId) { |
| 1777 | if ((mResourcesSetFlags & FLAG_RESOURCE_SET_LOGO) != 0) { |
| 1778 | return; |
| 1779 | } |
| 1780 | mLogoRes = resId; |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 1781 | if (mDecorContentParent != null && !mDecorContentParent.hasLogo()) { |
| 1782 | mDecorContentParent.setLogo(resId); |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 1783 | } |
| 1784 | } |
| 1785 | |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 1786 | @Override |
| 1787 | public void setLocalFocus(boolean hasFocus, boolean inTouchMode) { |
| 1788 | getViewRootImpl().windowFocusChanged(hasFocus, inTouchMode); |
| 1789 | |
| 1790 | } |
| 1791 | |
| 1792 | @Override |
| 1793 | public void injectInputEvent(InputEvent event) { |
| 1794 | getViewRootImpl().dispatchInputEvent(event); |
| 1795 | } |
| 1796 | |
| 1797 | private ViewRootImpl getViewRootImpl() { |
| 1798 | if (mDecor != null) { |
| 1799 | ViewRootImpl viewRootImpl = mDecor.getViewRootImpl(); |
| 1800 | if (viewRootImpl != null) { |
| 1801 | return viewRootImpl; |
| 1802 | } |
| 1803 | } |
| 1804 | throw new IllegalStateException("view not added"); |
| 1805 | } |
| 1806 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1807 | /** |
| 1808 | * Request that key events come to this activity. Use this if your activity |
| 1809 | * has no views with focus, but the activity still wants a chance to process |
| 1810 | * key events. |
| 1811 | */ |
| 1812 | @Override |
| 1813 | public void takeKeyEvents(boolean get) { |
| 1814 | mDecor.setFocusable(get); |
| 1815 | } |
| 1816 | |
| 1817 | @Override |
| 1818 | public boolean superDispatchKeyEvent(KeyEvent event) { |
| 1819 | return mDecor.superDispatchKeyEvent(event); |
| 1820 | } |
| 1821 | |
| 1822 | @Override |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 1823 | public boolean superDispatchKeyShortcutEvent(KeyEvent event) { |
| 1824 | return mDecor.superDispatchKeyShortcutEvent(event); |
| 1825 | } |
| 1826 | |
| 1827 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1828 | public boolean superDispatchTouchEvent(MotionEvent event) { |
| 1829 | return mDecor.superDispatchTouchEvent(event); |
| 1830 | } |
| 1831 | |
| 1832 | @Override |
| 1833 | public boolean superDispatchTrackballEvent(MotionEvent event) { |
| 1834 | return mDecor.superDispatchTrackballEvent(event); |
| 1835 | } |
| 1836 | |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 1837 | @Override |
| 1838 | public boolean superDispatchGenericMotionEvent(MotionEvent event) { |
| 1839 | return mDecor.superDispatchGenericMotionEvent(event); |
| 1840 | } |
| 1841 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1842 | /** |
| 1843 | * A key was pressed down and not handled by anything else in the window. |
| 1844 | * |
| 1845 | * @see #onKeyUp |
| 1846 | * @see android.view.KeyEvent |
| 1847 | */ |
| 1848 | protected boolean onKeyDown(int featureId, int keyCode, KeyEvent event) { |
Joe Onorato | 86f6786 | 2010-11-05 18:57:34 -0700 | [diff] [blame] | 1849 | /* **************************************************************************** |
| 1850 | * HOW TO DECIDE WHERE YOUR KEY HANDLING GOES. |
| 1851 | * |
| 1852 | * If your key handling must happen before the app gets a crack at the event, |
| 1853 | * it goes in PhoneWindowManager. |
| 1854 | * |
| 1855 | * If your key handling should happen in all windows, and does not depend on |
| 1856 | * the state of the current application, other than that the current |
| 1857 | * application can override the behavior by handling the event itself, it |
| 1858 | * should go in PhoneFallbackEventHandler. |
| 1859 | * |
| 1860 | * Only if your handling depends on the window, and the fact that it has |
| 1861 | * a DecorView, should it go here. |
| 1862 | * ****************************************************************************/ |
| 1863 | |
Dianne Hackborn | a207baa | 2009-09-13 16:14:44 -0700 | [diff] [blame] | 1864 | final KeyEvent.DispatcherState dispatcher = |
| 1865 | mDecor != null ? mDecor.getKeyDispatcherState() : null; |
| 1866 | //Log.i(TAG, "Key down: repeat=" + event.getRepeatCount() |
| 1867 | // + " flags=0x" + Integer.toHexString(event.getFlags())); |
Alan Viverette | eb1d379 | 2014-06-03 18:36:03 -0700 | [diff] [blame] | 1868 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1869 | switch (keyCode) { |
| 1870 | case KeyEvent.KEYCODE_VOLUME_UP: |
RoboErik | 5452e25 | 2015-02-06 15:33:53 -0800 | [diff] [blame] | 1871 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 1872 | case KeyEvent.KEYCODE_VOLUME_MUTE: { |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1873 | // If we have a session send it the volume command, otherwise |
| 1874 | // use the suggested stream. |
| 1875 | if (mMediaController != null) { |
Jaewan Kim | 5026936 | 2016-12-23 11:22:02 +0900 | [diff] [blame] | 1876 | int direction = 0; |
| 1877 | switch (keyCode) { |
| 1878 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 1879 | direction = AudioManager.ADJUST_RAISE; |
| 1880 | break; |
| 1881 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 1882 | direction = AudioManager.ADJUST_LOWER; |
| 1883 | break; |
| 1884 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 1885 | direction = AudioManager.ADJUST_TOGGLE_MUTE; |
| 1886 | break; |
| 1887 | } |
RoboErik | 1ff5b16 | 2014-07-15 17:23:18 -0700 | [diff] [blame] | 1888 | mMediaController.adjustVolume(direction, AudioManager.FLAG_SHOW_UI); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1889 | } else { |
Jaewan Kim | 5026936 | 2016-12-23 11:22:02 +0900 | [diff] [blame] | 1890 | MediaSessionLegacyHelper.getHelper(getContext()).sendVolumeKeyEvent( |
| 1891 | event, mVolumeControlStreamType, false); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1892 | } |
| 1893 | return true; |
| 1894 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1895 | // These are all the recognized media key codes in |
| 1896 | // KeyEvent.isMediaKey() |
| 1897 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 1898 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 1899 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 1900 | case KeyEvent.KEYCODE_MUTE: |
| 1901 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 1902 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 1903 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 1904 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 1905 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 1906 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
| 1907 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: { |
| 1908 | if (mMediaController != null) { |
| 1909 | if (mMediaController.dispatchMediaButtonEvent(event)) { |
| 1910 | return true; |
| 1911 | } |
| 1912 | } |
RoboErik | 28204a7 | 2014-07-17 12:17:27 -0700 | [diff] [blame] | 1913 | return false; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1914 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1915 | |
| 1916 | case KeyEvent.KEYCODE_MENU: { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1917 | onKeyDownPanel((featureId < 0) ? FEATURE_OPTIONS_PANEL : featureId, event); |
| 1918 | return true; |
| 1919 | } |
| 1920 | |
| 1921 | case KeyEvent.KEYCODE_BACK: { |
| 1922 | if (event.getRepeatCount() > 0) break; |
| 1923 | if (featureId < 0) break; |
Dianne Hackborn | fed9cb5 | 2009-09-14 21:23:11 -0700 | [diff] [blame] | 1924 | // Currently don't do anything with long press. |
Winson Chung | 45d378b | 2011-09-08 19:02:06 -0700 | [diff] [blame] | 1925 | if (dispatcher != null) { |
| 1926 | dispatcher.startTracking(event, this); |
| 1927 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1928 | return true; |
| 1929 | } |
| 1930 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1931 | } |
| 1932 | |
| 1933 | return false; |
| 1934 | } |
| 1935 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1936 | private KeyguardManager getKeyguardManager() { |
| 1937 | if (mKeyguardManager == null) { |
Joe Onorato | 86f6786 | 2010-11-05 18:57:34 -0700 | [diff] [blame] | 1938 | mKeyguardManager = (KeyguardManager) getContext().getSystemService( |
| 1939 | Context.KEYGUARD_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1940 | } |
| 1941 | return mKeyguardManager; |
| 1942 | } |
Joe Onorato | 86f6786 | 2010-11-05 18:57:34 -0700 | [diff] [blame] | 1943 | |
| 1944 | AudioManager getAudioManager() { |
| 1945 | if (mAudioManager == null) { |
| 1946 | mAudioManager = (AudioManager)getContext().getSystemService(Context.AUDIO_SERVICE); |
Mike LeBeau | bfd25ca | 2010-03-22 17:40:35 -0700 | [diff] [blame] | 1947 | } |
Joe Onorato | 86f6786 | 2010-11-05 18:57:34 -0700 | [diff] [blame] | 1948 | return mAudioManager; |
Mike LeBeau | bfd25ca | 2010-03-22 17:40:35 -0700 | [diff] [blame] | 1949 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1950 | |
| 1951 | /** |
| 1952 | * A key was released and not handled by anything else in the window. |
| 1953 | * |
| 1954 | * @see #onKeyDown |
| 1955 | * @see android.view.KeyEvent |
| 1956 | */ |
| 1957 | protected boolean onKeyUp(int featureId, int keyCode, KeyEvent event) { |
Dianne Hackborn | a207baa | 2009-09-13 16:14:44 -0700 | [diff] [blame] | 1958 | final KeyEvent.DispatcherState dispatcher = |
| 1959 | mDecor != null ? mDecor.getKeyDispatcherState() : null; |
| 1960 | if (dispatcher != null) { |
| 1961 | dispatcher.handleUpEvent(event); |
| 1962 | } |
| 1963 | //Log.i(TAG, "Key up: repeat=" + event.getRepeatCount() |
| 1964 | // + " flags=0x" + Integer.toHexString(event.getFlags())); |
Alan Viverette | eb1d379 | 2014-06-03 18:36:03 -0700 | [diff] [blame] | 1965 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1966 | switch (keyCode) { |
| 1967 | case KeyEvent.KEYCODE_VOLUME_UP: |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1968 | case KeyEvent.KEYCODE_VOLUME_DOWN: { |
| 1969 | // If we have a session send it the volume command, otherwise |
| 1970 | // use the suggested stream. |
| 1971 | if (mMediaController != null) { |
Jaewan Kim | 5026936 | 2016-12-23 11:22:02 +0900 | [diff] [blame] | 1972 | final int flags = AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_VIBRATE |
| 1973 | | AudioManager.FLAG_FROM_KEY; |
John Spurlock | b94f2d6 | 2015-03-17 14:11:57 -0400 | [diff] [blame] | 1974 | mMediaController.adjustVolume(0, flags); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1975 | } else { |
Jaewan Kim | 5026936 | 2016-12-23 11:22:02 +0900 | [diff] [blame] | 1976 | MediaSessionLegacyHelper.getHelper(getContext()).sendVolumeKeyEvent( |
| 1977 | event, mVolumeControlStreamType, false); |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1978 | } |
| 1979 | return true; |
| 1980 | } |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 1981 | case KeyEvent.KEYCODE_VOLUME_MUTE: { |
Joe Onorato | 86f6786 | 2010-11-05 18:57:34 -0700 | [diff] [blame] | 1982 | // Similar code is in PhoneFallbackEventHandler in case the window |
| 1983 | // doesn't have one of these. In this case, we execute it here and |
| 1984 | // eat the event instead, because we have mVolumeControlStreamType |
| 1985 | // and they don't. |
Jaewan Kim | 5026936 | 2016-12-23 11:22:02 +0900 | [diff] [blame] | 1986 | MediaSessionLegacyHelper.getHelper(getContext()).sendVolumeKeyEvent( |
| 1987 | event, AudioManager.USE_DEFAULT_STREAM_TYPE, false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1988 | return true; |
| 1989 | } |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 1990 | // These are all the recognized media key codes in |
| 1991 | // KeyEvent.isMediaKey() |
| 1992 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 1993 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 1994 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 1995 | case KeyEvent.KEYCODE_MUTE: |
| 1996 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 1997 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 1998 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 1999 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 2000 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 2001 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
| 2002 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: { |
| 2003 | if (mMediaController != null) { |
| 2004 | if (mMediaController.dispatchMediaButtonEvent(event)) { |
| 2005 | return true; |
| 2006 | } |
| 2007 | } |
RoboErik | 28204a7 | 2014-07-17 12:17:27 -0700 | [diff] [blame] | 2008 | return false; |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 2009 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2010 | |
| 2011 | case KeyEvent.KEYCODE_MENU: { |
Adam Powell | f6148c5 | 2010-08-11 21:10:16 -0700 | [diff] [blame] | 2012 | onKeyUpPanel(featureId < 0 ? FEATURE_OPTIONS_PANEL : featureId, |
| 2013 | event); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2014 | return true; |
| 2015 | } |
| 2016 | |
Dianne Hackborn | a207baa | 2009-09-13 16:14:44 -0700 | [diff] [blame] | 2017 | case KeyEvent.KEYCODE_BACK: { |
| 2018 | if (featureId < 0) break; |
Dianne Hackborn | fed9cb5 | 2009-09-14 21:23:11 -0700 | [diff] [blame] | 2019 | if (event.isTracking() && !event.isCanceled()) { |
| 2020 | if (featureId == FEATURE_OPTIONS_PANEL) { |
| 2021 | PanelFeatureState st = getPanelState(featureId, false); |
| 2022 | if (st != null && st.isInExpandedMode) { |
| 2023 | // If the user is in an expanded menu and hits back, it |
| 2024 | // should go back to the icon menu |
| 2025 | reopenMenu(true); |
| 2026 | return true; |
| 2027 | } |
Dianne Hackborn | a207baa | 2009-09-13 16:14:44 -0700 | [diff] [blame] | 2028 | } |
Dianne Hackborn | fed9cb5 | 2009-09-14 21:23:11 -0700 | [diff] [blame] | 2029 | closePanel(featureId); |
| 2030 | return true; |
Dianne Hackborn | a207baa | 2009-09-13 16:14:44 -0700 | [diff] [blame] | 2031 | } |
Dianne Hackborn | fed9cb5 | 2009-09-14 21:23:11 -0700 | [diff] [blame] | 2032 | break; |
Dianne Hackborn | a207baa | 2009-09-13 16:14:44 -0700 | [diff] [blame] | 2033 | } |
| 2034 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2035 | case KeyEvent.KEYCODE_SEARCH: { |
| 2036 | /* |
| 2037 | * Do this in onKeyUp since the Search key is also used for |
| 2038 | * chording quick launch shortcuts. |
| 2039 | */ |
Dianne Hackborn | a207baa | 2009-09-13 16:14:44 -0700 | [diff] [blame] | 2040 | if (getKeyguardManager().inKeyguardRestrictedInputMode()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2041 | break; |
| 2042 | } |
Erik Wolsheimer | ac5cecd | 2017-12-05 13:11:50 -0800 | [diff] [blame] | 2043 | if ((getContext().getResources().getConfiguration().uiMode |
| 2044 | & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_WATCH) { |
| 2045 | break; |
| 2046 | } |
Dianne Hackborn | a207baa | 2009-09-13 16:14:44 -0700 | [diff] [blame] | 2047 | if (event.isTracking() && !event.isCanceled()) { |
Tim Kilbourn | 6a975b3 | 2015-04-09 17:14:34 -0700 | [diff] [blame] | 2048 | launchDefaultSearch(event); |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 2049 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2050 | return true; |
| 2051 | } |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 2052 | |
| 2053 | case KeyEvent.KEYCODE_WINDOW: { |
Jaewan Kim | d98dcab | 2016-05-03 02:52:18 +0900 | [diff] [blame] | 2054 | if (mSupportsPictureInPicture && !event.isCanceled()) { |
| 2055 | getWindowControllerCallback().enterPictureInPictureModeIfPossible(); |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 2056 | } |
| 2057 | return true; |
| 2058 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2059 | } |
| 2060 | |
| 2061 | return false; |
| 2062 | } |
| 2063 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2064 | @Override |
| 2065 | protected void onActive() { |
| 2066 | } |
| 2067 | |
| 2068 | @Override |
| 2069 | public final View getDecorView() { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 2070 | if (mDecor == null || mForceDecorInstall) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2071 | installDecor(); |
| 2072 | } |
| 2073 | return mDecor; |
| 2074 | } |
| 2075 | |
| 2076 | @Override |
| 2077 | public final View peekDecorView() { |
| 2078 | return mDecor; |
| 2079 | } |
| 2080 | |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 2081 | /** Notify when decor view is attached to window and {@link ViewRootImpl} is available. */ |
| 2082 | void onViewRootImplSet(ViewRootImpl viewRoot) { |
| 2083 | viewRoot.setActivityConfigCallback(mActivityConfigCallback); |
| 2084 | } |
| 2085 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2086 | static private final String FOCUSED_ID_TAG = "android:focusedViewId"; |
| 2087 | static private final String VIEWS_TAG = "android:views"; |
| 2088 | static private final String PANELS_TAG = "android:Panels"; |
Adam Powell | 6c6f575 | 2010-08-20 18:34:46 -0700 | [diff] [blame] | 2089 | static private final String ACTION_BAR_TAG = "android:ActionBar"; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2090 | |
Alan Viverette | eae66cd | 2015-08-13 20:05:35 +0000 | [diff] [blame] | 2091 | /** {@inheritDoc} */ |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2092 | @Override |
| 2093 | public Bundle saveHierarchyState() { |
Alan Viverette | eae66cd | 2015-08-13 20:05:35 +0000 | [diff] [blame] | 2094 | Bundle outState = new Bundle(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2095 | if (mContentParent == null) { |
| 2096 | return outState; |
| 2097 | } |
| 2098 | |
Alan Viverette | eae66cd | 2015-08-13 20:05:35 +0000 | [diff] [blame] | 2099 | SparseArray<Parcelable> states = new SparseArray<Parcelable>(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2100 | mContentParent.saveHierarchyState(states); |
| 2101 | outState.putSparseParcelableArray(VIEWS_TAG, states); |
| 2102 | |
Alan Viverette | ec6cf18 | 2015-08-13 15:31:57 -0400 | [diff] [blame] | 2103 | // Save the focused view ID. |
| 2104 | final View focusedView = mContentParent.findFocus(); |
| 2105 | if (focusedView != null && focusedView.getId() != View.NO_ID) { |
| 2106 | outState.putInt(FOCUSED_ID_TAG, focusedView.getId()); |
| 2107 | } |
| 2108 | |
Alan Viverette | eae66cd | 2015-08-13 20:05:35 +0000 | [diff] [blame] | 2109 | // save the panels |
| 2110 | SparseArray<Parcelable> panelStates = new SparseArray<Parcelable>(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2111 | savePanelState(panelStates); |
| 2112 | if (panelStates.size() > 0) { |
| 2113 | outState.putSparseParcelableArray(PANELS_TAG, panelStates); |
| 2114 | } |
| 2115 | |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 2116 | if (mDecorContentParent != null) { |
Alan Viverette | eae66cd | 2015-08-13 20:05:35 +0000 | [diff] [blame] | 2117 | SparseArray<Parcelable> actionBarStates = new SparseArray<Parcelable>(); |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 2118 | mDecorContentParent.saveToolbarHierarchyState(actionBarStates); |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 2119 | outState.putSparseParcelableArray(ACTION_BAR_TAG, actionBarStates); |
Adam Powell | 6c6f575 | 2010-08-20 18:34:46 -0700 | [diff] [blame] | 2120 | } |
| 2121 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2122 | return outState; |
| 2123 | } |
| 2124 | |
Alan Viverette | eae66cd | 2015-08-13 20:05:35 +0000 | [diff] [blame] | 2125 | /** {@inheritDoc} */ |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2126 | @Override |
| 2127 | public void restoreHierarchyState(Bundle savedInstanceState) { |
| 2128 | if (mContentParent == null) { |
| 2129 | return; |
| 2130 | } |
| 2131 | |
Alan Viverette | eae66cd | 2015-08-13 20:05:35 +0000 | [diff] [blame] | 2132 | SparseArray<Parcelable> savedStates |
| 2133 | = savedInstanceState.getSparseParcelableArray(VIEWS_TAG); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2134 | if (savedStates != null) { |
| 2135 | mContentParent.restoreHierarchyState(savedStates); |
| 2136 | } |
| 2137 | |
Alan Viverette | eae66cd | 2015-08-13 20:05:35 +0000 | [diff] [blame] | 2138 | // restore the focused view |
| 2139 | int focusedViewId = savedInstanceState.getInt(FOCUSED_ID_TAG, View.NO_ID); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2140 | if (focusedViewId != View.NO_ID) { |
Alan Viverette | eae66cd | 2015-08-13 20:05:35 +0000 | [diff] [blame] | 2141 | View needsFocus = mContentParent.findViewById(focusedViewId); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2142 | if (needsFocus != null) { |
| 2143 | needsFocus.requestFocus(); |
| 2144 | } else { |
Alan Viverette | eae66cd | 2015-08-13 20:05:35 +0000 | [diff] [blame] | 2145 | Log.w(TAG, |
| 2146 | "Previously focused view reported id " + focusedViewId |
| 2147 | + " during save, but can't be found during restore."); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2148 | } |
| 2149 | } |
| 2150 | |
Alan Viverette | ec6cf18 | 2015-08-13 15:31:57 -0400 | [diff] [blame] | 2151 | // Restore the panels. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2152 | SparseArray<Parcelable> panelStates = savedInstanceState.getSparseParcelableArray(PANELS_TAG); |
| 2153 | if (panelStates != null) { |
| 2154 | restorePanelState(panelStates); |
| 2155 | } |
Adam Powell | 6c6f575 | 2010-08-20 18:34:46 -0700 | [diff] [blame] | 2156 | |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 2157 | if (mDecorContentParent != null) { |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 2158 | SparseArray<Parcelable> actionBarStates = |
| 2159 | savedInstanceState.getSparseParcelableArray(ACTION_BAR_TAG); |
Adam Powell | fb5f1bc | 2012-05-17 19:30:35 -0700 | [diff] [blame] | 2160 | if (actionBarStates != null) { |
Adam Powell | 31c91c8 | 2014-08-22 17:20:00 -0700 | [diff] [blame] | 2161 | doPendingInvalidatePanelMenu(); |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 2162 | mDecorContentParent.restoreToolbarHierarchyState(actionBarStates); |
Adam Powell | fb5f1bc | 2012-05-17 19:30:35 -0700 | [diff] [blame] | 2163 | } else { |
| 2164 | Log.w(TAG, "Missing saved instance states for action bar views! " + |
| 2165 | "State will not be restored."); |
| 2166 | } |
Adam Powell | 6c6f575 | 2010-08-20 18:34:46 -0700 | [diff] [blame] | 2167 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2168 | } |
| 2169 | |
| 2170 | /** |
| 2171 | * Invoked when the panels should freeze their state. |
| 2172 | * |
| 2173 | * @param icicles Save state into this. This is usually indexed by the |
| 2174 | * featureId. This will be given to {@link #restorePanelState} in the |
| 2175 | * future. |
| 2176 | */ |
| 2177 | private void savePanelState(SparseArray<Parcelable> icicles) { |
| 2178 | PanelFeatureState[] panels = mPanels; |
| 2179 | if (panels == null) { |
| 2180 | return; |
| 2181 | } |
| 2182 | |
| 2183 | for (int curFeatureId = panels.length - 1; curFeatureId >= 0; curFeatureId--) { |
| 2184 | if (panels[curFeatureId] != null) { |
| 2185 | icicles.put(curFeatureId, panels[curFeatureId].onSaveInstanceState()); |
| 2186 | } |
| 2187 | } |
| 2188 | } |
| 2189 | |
| 2190 | /** |
| 2191 | * Invoked when the panels should thaw their state from a previously frozen state. |
| 2192 | * |
| 2193 | * @param icicles The state saved by {@link #savePanelState} that needs to be thawed. |
| 2194 | */ |
| 2195 | private void restorePanelState(SparseArray<Parcelable> icicles) { |
| 2196 | PanelFeatureState st; |
Dmitry Tsyganyuk | 554bb01 | 2012-04-02 13:10:52 -0500 | [diff] [blame] | 2197 | int curFeatureId; |
| 2198 | for (int i = icicles.size() - 1; i >= 0; i--) { |
| 2199 | curFeatureId = icicles.keyAt(i); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2200 | st = getPanelState(curFeatureId, false /* required */); |
| 2201 | if (st == null) { |
| 2202 | // The panel must not have been required, and is currently not around, skip it |
| 2203 | continue; |
| 2204 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 2205 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2206 | st.onRestoreInstanceState(icicles.get(curFeatureId)); |
Adam Powell | 31bb97d | 2011-05-03 20:58:31 -0700 | [diff] [blame] | 2207 | invalidatePanelMenu(curFeatureId); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2208 | } |
| 2209 | |
| 2210 | /* |
| 2211 | * Implementation note: call openPanelsAfterRestore later to actually open the |
| 2212 | * restored panels. |
| 2213 | */ |
| 2214 | } |
| 2215 | |
| 2216 | /** |
| 2217 | * Opens the panels that have had their state restored. This should be |
| 2218 | * called sometime after {@link #restorePanelState} when it is safe to add |
| 2219 | * to the window manager. |
| 2220 | */ |
Wale Ogunwale | 8804af2 | 2015-11-17 09:18:15 -0800 | [diff] [blame] | 2221 | void openPanelsAfterRestore() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2222 | PanelFeatureState[] panels = mPanels; |
| 2223 | |
| 2224 | if (panels == null) { |
| 2225 | return; |
| 2226 | } |
| 2227 | |
| 2228 | PanelFeatureState st; |
| 2229 | for (int i = panels.length - 1; i >= 0; i--) { |
| 2230 | st = panels[i]; |
Dianne Hackborn | d007144 | 2009-09-25 01:35:29 -0700 | [diff] [blame] | 2231 | // We restore the panel if it was last open; we skip it if it |
| 2232 | // now is open, to avoid a race condition if the user immediately |
| 2233 | // opens it when we are resuming. |
Adam Powell | 11ed1d6 | 2011-07-11 21:19:59 -0700 | [diff] [blame] | 2234 | if (st != null) { |
| 2235 | st.applyFrozenState(); |
| 2236 | if (!st.isOpen && st.wasLastOpen) { |
| 2237 | st.isInExpandedMode = st.wasLastExpanded; |
| 2238 | openPanel(st, null); |
| 2239 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2240 | } |
| 2241 | } |
| 2242 | } |
| 2243 | |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 2244 | private class PanelMenuPresenterCallback implements MenuPresenter.Callback { |
| 2245 | @Override |
| 2246 | public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) { |
| 2247 | final Menu parentMenu = menu.getRootMenu(); |
| 2248 | final boolean isSubMenu = parentMenu != menu; |
| 2249 | final PanelFeatureState panel = findMenuPanel(isSubMenu ? parentMenu : menu); |
| 2250 | if (panel != null) { |
| 2251 | if (isSubMenu) { |
| 2252 | callOnPanelClosed(panel.featureId, panel, parentMenu); |
| 2253 | closePanel(panel, true); |
| 2254 | } else { |
| 2255 | // Close the panel and only do the callback if the menu is being |
| 2256 | // closed completely, not if opening a sub menu |
| 2257 | closePanel(panel, allMenusAreClosing); |
| 2258 | } |
| 2259 | } |
| 2260 | } |
| 2261 | |
| 2262 | @Override |
| 2263 | public boolean onOpenSubMenu(MenuBuilder subMenu) { |
| 2264 | if (subMenu == null && hasFeature(FEATURE_ACTION_BAR)) { |
| 2265 | Callback cb = getCallback(); |
| 2266 | if (cb != null && !isDestroyed()) { |
| 2267 | cb.onMenuOpened(FEATURE_ACTION_BAR, subMenu); |
| 2268 | } |
| 2269 | } |
| 2270 | |
| 2271 | return true; |
| 2272 | } |
| 2273 | } |
| 2274 | |
| 2275 | private final class ActionMenuPresenterCallback implements MenuPresenter.Callback { |
| 2276 | @Override |
| 2277 | public boolean onOpenSubMenu(MenuBuilder subMenu) { |
| 2278 | Callback cb = getCallback(); |
| 2279 | if (cb != null) { |
| 2280 | cb.onMenuOpened(FEATURE_ACTION_BAR, subMenu); |
| 2281 | return true; |
| 2282 | } |
| 2283 | return false; |
| 2284 | } |
| 2285 | |
| 2286 | @Override |
| 2287 | public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) { |
| 2288 | checkCloseActionMenu(menu); |
| 2289 | } |
| 2290 | } |
| 2291 | |
Stefan Kuhne | 61b47bb | 2015-07-28 14:04:25 -0700 | [diff] [blame] | 2292 | protected DecorView generateDecor(int featureId) { |
Filip Gruszczynski | 0daf210 | 2015-09-29 08:39:07 -0700 | [diff] [blame] | 2293 | // System process doesn't have application context and in that case we need to directly use |
| 2294 | // the context we have. Otherwise we want the application context, so we don't cling to the |
| 2295 | // activity. |
Filip Gruszczynski | 0daf210 | 2015-09-29 08:39:07 -0700 | [diff] [blame] | 2296 | Context context; |
Filip Gruszczynski | 796b8c1 | 2015-12-22 14:46:21 -0800 | [diff] [blame] | 2297 | if (mUseDecorContext) { |
| 2298 | Context applicationContext = getContext().getApplicationContext(); |
| 2299 | if (applicationContext == null) { |
| 2300 | context = getContext(); |
| 2301 | } else { |
chaviw | a213d30 | 2018-04-23 13:34:36 -0700 | [diff] [blame] | 2302 | context = new DecorContext(applicationContext, getContext()); |
Filip Gruszczynski | 796b8c1 | 2015-12-22 14:46:21 -0800 | [diff] [blame] | 2303 | if (mTheme != -1) { |
| 2304 | context.setTheme(mTheme); |
| 2305 | } |
Filip Gruszczynski | 0daf210 | 2015-09-29 08:39:07 -0700 | [diff] [blame] | 2306 | } |
Filip Gruszczynski | 796b8c1 | 2015-12-22 14:46:21 -0800 | [diff] [blame] | 2307 | } else { |
| 2308 | context = getContext(); |
Filip Gruszczynski | 0daf210 | 2015-09-29 08:39:07 -0700 | [diff] [blame] | 2309 | } |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2310 | return new DecorView(context, featureId, this, getAttributes()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2311 | } |
| 2312 | |
| 2313 | protected ViewGroup generateLayout(DecorView decor) { |
| 2314 | // Apply data from current theme. |
| 2315 | |
| 2316 | TypedArray a = getWindowStyle(); |
| 2317 | |
| 2318 | if (false) { |
| 2319 | System.out.println("From style:"); |
| 2320 | String s = "Attrs:"; |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2321 | for (int i = 0; i < R.styleable.Window.length; i++) { |
| 2322 | s = s + " " + Integer.toHexString(R.styleable.Window[i]) + "=" |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2323 | + a.getString(i); |
| 2324 | } |
| 2325 | System.out.println(s); |
| 2326 | } |
| 2327 | |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2328 | mIsFloating = a.getBoolean(R.styleable.Window_windowIsFloating, false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2329 | int flagsToUpdate = (FLAG_LAYOUT_IN_SCREEN|FLAG_LAYOUT_INSET_DECOR) |
| 2330 | & (~getForcedWindowFlags()); |
| 2331 | if (mIsFloating) { |
| 2332 | setLayout(WRAP_CONTENT, WRAP_CONTENT); |
| 2333 | setFlags(0, flagsToUpdate); |
| 2334 | } else { |
| 2335 | setFlags(FLAG_LAYOUT_IN_SCREEN|FLAG_LAYOUT_INSET_DECOR, flagsToUpdate); |
| 2336 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 2337 | |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2338 | if (a.getBoolean(R.styleable.Window_windowNoTitle, false)) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2339 | requestFeature(FEATURE_NO_TITLE); |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2340 | } else if (a.getBoolean(R.styleable.Window_windowActionBar, false)) { |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 2341 | // Don't allow an action bar if there is no title. |
| 2342 | requestFeature(FEATURE_ACTION_BAR); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2343 | } |
| 2344 | |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2345 | if (a.getBoolean(R.styleable.Window_windowActionBarOverlay, false)) { |
Adam Powell | 6b336f8 | 2010-08-10 20:13:01 -0700 | [diff] [blame] | 2346 | requestFeature(FEATURE_ACTION_BAR_OVERLAY); |
| 2347 | } |
| 2348 | |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2349 | if (a.getBoolean(R.styleable.Window_windowActionModeOverlay, false)) { |
Adam Powell | 5d27977 | 2010-07-27 16:34:07 -0700 | [diff] [blame] | 2350 | requestFeature(FEATURE_ACTION_MODE_OVERLAY); |
| 2351 | } |
| 2352 | |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2353 | if (a.getBoolean(R.styleable.Window_windowSwipeToDismiss, false)) { |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 2354 | requestFeature(FEATURE_SWIPE_TO_DISMISS); |
| 2355 | } |
| 2356 | |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2357 | if (a.getBoolean(R.styleable.Window_windowFullscreen, false)) { |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2358 | setFlags(FLAG_FULLSCREEN, FLAG_FULLSCREEN & (~getForcedWindowFlags())); |
| 2359 | } |
| 2360 | |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2361 | if (a.getBoolean(R.styleable.Window_windowTranslucentStatus, |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 2362 | false)) { |
| 2363 | setFlags(FLAG_TRANSLUCENT_STATUS, FLAG_TRANSLUCENT_STATUS |
| 2364 | & (~getForcedWindowFlags())); |
| 2365 | } |
| 2366 | |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2367 | if (a.getBoolean(R.styleable.Window_windowTranslucentNavigation, |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 2368 | false)) { |
| 2369 | setFlags(FLAG_TRANSLUCENT_NAVIGATION, FLAG_TRANSLUCENT_NAVIGATION |
| 2370 | & (~getForcedWindowFlags())); |
| 2371 | } |
| 2372 | |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2373 | if (a.getBoolean(R.styleable.Window_windowOverscan, false)) { |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2374 | setFlags(FLAG_LAYOUT_IN_OVERSCAN, FLAG_LAYOUT_IN_OVERSCAN&(~getForcedWindowFlags())); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2375 | } |
| 2376 | |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2377 | if (a.getBoolean(R.styleable.Window_windowShowWallpaper, false)) { |
Dianne Hackborn | 4bf7bcf | 2009-08-09 17:23:00 -0700 | [diff] [blame] | 2378 | setFlags(FLAG_SHOW_WALLPAPER, FLAG_SHOW_WALLPAPER&(~getForcedWindowFlags())); |
| 2379 | } |
| 2380 | |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2381 | if (a.getBoolean(R.styleable.Window_windowEnableSplitTouch, |
Jeff Brown | 46e7529 | 2010-11-10 16:53:45 -0800 | [diff] [blame] | 2382 | getContext().getApplicationInfo().targetSdkVersion |
| 2383 | >= android.os.Build.VERSION_CODES.HONEYCOMB)) { |
| 2384 | setFlags(FLAG_SPLIT_TOUCH, FLAG_SPLIT_TOUCH&(~getForcedWindowFlags())); |
| 2385 | } |
| 2386 | |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2387 | a.getValue(R.styleable.Window_windowMinWidthMajor, mMinWidthMajor); |
| 2388 | a.getValue(R.styleable.Window_windowMinWidthMinor, mMinWidthMinor); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2389 | if (DEBUG) Log.d(TAG, "Min width minor: " + mMinWidthMinor.coerceToString() |
| 2390 | + ", major: " + mMinWidthMajor.coerceToString()); |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2391 | if (a.hasValue(R.styleable.Window_windowFixedWidthMajor)) { |
Adam Powell | 40eec4c | 2012-02-15 17:10:58 -0800 | [diff] [blame] | 2392 | if (mFixedWidthMajor == null) mFixedWidthMajor = new TypedValue(); |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2393 | a.getValue(R.styleable.Window_windowFixedWidthMajor, |
Adam Powell | 40eec4c | 2012-02-15 17:10:58 -0800 | [diff] [blame] | 2394 | mFixedWidthMajor); |
| 2395 | } |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2396 | if (a.hasValue(R.styleable.Window_windowFixedWidthMinor)) { |
Adam Powell | 40eec4c | 2012-02-15 17:10:58 -0800 | [diff] [blame] | 2397 | if (mFixedWidthMinor == null) mFixedWidthMinor = new TypedValue(); |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2398 | a.getValue(R.styleable.Window_windowFixedWidthMinor, |
Adam Powell | 40eec4c | 2012-02-15 17:10:58 -0800 | [diff] [blame] | 2399 | mFixedWidthMinor); |
| 2400 | } |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2401 | if (a.hasValue(R.styleable.Window_windowFixedHeightMajor)) { |
Adam Powell | 40eec4c | 2012-02-15 17:10:58 -0800 | [diff] [blame] | 2402 | if (mFixedHeightMajor == null) mFixedHeightMajor = new TypedValue(); |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2403 | a.getValue(R.styleable.Window_windowFixedHeightMajor, |
Adam Powell | 40eec4c | 2012-02-15 17:10:58 -0800 | [diff] [blame] | 2404 | mFixedHeightMajor); |
| 2405 | } |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2406 | if (a.hasValue(R.styleable.Window_windowFixedHeightMinor)) { |
Adam Powell | 40eec4c | 2012-02-15 17:10:58 -0800 | [diff] [blame] | 2407 | if (mFixedHeightMinor == null) mFixedHeightMinor = new TypedValue(); |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2408 | a.getValue(R.styleable.Window_windowFixedHeightMinor, |
Adam Powell | 40eec4c | 2012-02-15 17:10:58 -0800 | [diff] [blame] | 2409 | mFixedHeightMinor); |
| 2410 | } |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2411 | if (a.getBoolean(R.styleable.Window_windowContentTransitions, false)) { |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 2412 | requestFeature(FEATURE_CONTENT_TRANSITIONS); |
Michael Kolb | 4bb047f | 2014-04-01 14:38:57 -0700 | [diff] [blame] | 2413 | } |
George Mount | 9826f63 | 2014-09-11 08:50:09 -0700 | [diff] [blame] | 2414 | if (a.getBoolean(R.styleable.Window_windowActivityTransitions, false)) { |
| 2415 | requestFeature(FEATURE_ACTIVITY_TRANSITIONS); |
| 2416 | } |
Filip Gruszczynski | b57503c | 2014-07-16 16:35:18 -0700 | [diff] [blame] | 2417 | |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 2418 | mIsTranslucent = a.getBoolean(R.styleable.Window_windowIsTranslucent, false); |
| 2419 | |
Adam Powell | 82349c5 | 2011-08-23 13:53:56 -0700 | [diff] [blame] | 2420 | final Context context = getContext(); |
| 2421 | final int targetSdk = context.getApplicationInfo().targetSdkVersion; |
| 2422 | final boolean targetPreHoneycomb = targetSdk < android.os.Build.VERSION_CODES.HONEYCOMB; |
| 2423 | final boolean targetPreIcs = targetSdk < android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH; |
Dianne Hackborn | 955d8d6 | 2014-10-07 20:17:19 -0700 | [diff] [blame] | 2424 | final boolean targetPreL = targetSdk < android.os.Build.VERSION_CODES.LOLLIPOP; |
Adam Powell | 82349c5 | 2011-08-23 13:53:56 -0700 | [diff] [blame] | 2425 | final boolean targetHcNeedsOptions = context.getResources().getBoolean( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2426 | R.bool.target_honeycomb_needs_options_menu); |
Adam Powell | 82349c5 | 2011-08-23 13:53:56 -0700 | [diff] [blame] | 2427 | final boolean noActionBar = !hasFeature(FEATURE_ACTION_BAR) || hasFeature(FEATURE_NO_TITLE); |
| 2428 | |
| 2429 | if (targetPreHoneycomb || (targetPreIcs && targetHcNeedsOptions && noActionBar)) { |
Wale Ogunwale | 393b1c1 | 2014-10-18 16:22:01 -0700 | [diff] [blame] | 2430 | setNeedsMenuKey(WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE); |
Dianne Hackborn | 73ab6a4 | 2011-12-13 11:16:23 -0800 | [diff] [blame] | 2431 | } else { |
Wale Ogunwale | 393b1c1 | 2014-10-18 16:22:01 -0700 | [diff] [blame] | 2432 | setNeedsMenuKey(WindowManager.LayoutParams.NEEDS_MENU_SET_FALSE); |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 2433 | } |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2434 | |
Jorim Jaggi | 6e0ce28 | 2015-12-01 15:19:49 -0800 | [diff] [blame] | 2435 | if (!mForcedStatusBarColor) { |
| 2436 | mStatusBarColor = a.getColor(R.styleable.Window_statusBarColor, 0xFF000000); |
| 2437 | } |
| 2438 | if (!mForcedNavigationBarColor) { |
| 2439 | mNavigationBarColor = a.getColor(R.styleable.Window_navigationBarColor, 0xFF000000); |
Jason Monk | a750e99 | 2017-09-01 12:40:06 -0400 | [diff] [blame] | 2440 | mNavigationBarDividerColor = a.getColor(R.styleable.Window_navigationBarDividerColor, |
| 2441 | 0x00000000); |
Jorim Jaggi | 6e0ce28 | 2015-12-01 15:19:49 -0800 | [diff] [blame] | 2442 | } |
| 2443 | |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 2444 | WindowManager.LayoutParams params = getAttributes(); |
| 2445 | |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2446 | // Non-floating windows on high end devices must put up decor beneath the system bars and |
| 2447 | // therefore must know about visibility changes of those. |
Matthew Ng | e6b393b | 2017-09-01 12:45:04 -0700 | [diff] [blame] | 2448 | if (!mIsFloating) { |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2449 | if (!targetPreL && a.getBoolean( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2450 | R.styleable.Window_windowDrawsSystemBarBackgrounds, |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2451 | false)) { |
| 2452 | setFlags(FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS, |
| 2453 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS & ~getForcedWindowFlags()); |
| 2454 | } |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 2455 | if (mDecor.mForceWindowDrawsStatusBarBackground) { |
| 2456 | params.privateFlags |= PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND; |
| 2457 | } |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2458 | } |
Adrian Roos | f4f84c9 | 2015-04-28 13:44:43 -0700 | [diff] [blame] | 2459 | if (a.getBoolean(R.styleable.Window_windowLightStatusBar, false)) { |
Adrian Roos | 75fa385 | 2015-01-27 20:21:44 +0100 | [diff] [blame] | 2460 | decor.setSystemUiVisibility( |
| 2461 | decor.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); |
| 2462 | } |
Jason Monk | d7acd16 | 2017-09-11 08:54:12 -0700 | [diff] [blame] | 2463 | if (a.getBoolean(R.styleable.Window_windowLightNavigationBar, false)) { |
| 2464 | decor.setSystemUiVisibility( |
| 2465 | decor.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); |
| 2466 | } |
Adrian Roos | 2292031 | 2018-02-23 14:33:42 +0100 | [diff] [blame] | 2467 | if (a.hasValue(R.styleable.Window_windowLayoutInDisplayCutoutMode)) { |
| 2468 | int mode = a.getInt(R.styleable.Window_windowLayoutInDisplayCutoutMode, -1); |
| 2469 | if (mode < LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT |
| 2470 | || mode > LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER) { |
| 2471 | throw new UnsupportedOperationException("Unknown windowLayoutInDisplayCutoutMode: " |
| 2472 | + a.getString(R.styleable.Window_windowLayoutInDisplayCutoutMode)); |
| 2473 | } |
| 2474 | params.layoutInDisplayCutoutMode = mode; |
| 2475 | } |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2476 | |
Dianne Hackborn | cfaf887 | 2011-01-18 13:57:54 -0800 | [diff] [blame] | 2477 | if (mAlwaysReadCloseOnTouchAttr || getContext().getApplicationInfo().targetSdkVersion |
| 2478 | >= android.os.Build.VERSION_CODES.HONEYCOMB) { |
Dianne Hackborn | ef57575 | 2011-01-18 17:35:17 -0800 | [diff] [blame] | 2479 | if (a.getBoolean( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2480 | R.styleable.Window_windowCloseOnTouchOutside, |
Dianne Hackborn | ef57575 | 2011-01-18 17:35:17 -0800 | [diff] [blame] | 2481 | false)) { |
| 2482 | setCloseOnTouchOutsideIfNotSet(true); |
Dianne Hackborn | cfaf887 | 2011-01-18 13:57:54 -0800 | [diff] [blame] | 2483 | } |
| 2484 | } |
Alan Viverette | eb1d379 | 2014-06-03 18:36:03 -0700 | [diff] [blame] | 2485 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2486 | if (!hasSoftInputMode()) { |
| 2487 | params.softInputMode = a.getInt( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2488 | R.styleable.Window_windowSoftInputMode, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2489 | params.softInputMode); |
| 2490 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 2491 | |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2492 | if (a.getBoolean(R.styleable.Window_backgroundDimEnabled, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2493 | mIsFloating)) { |
| 2494 | /* All dialogs should have the window dimmed */ |
| 2495 | if ((getForcedWindowFlags()&WindowManager.LayoutParams.FLAG_DIM_BEHIND) == 0) { |
| 2496 | params.flags |= WindowManager.LayoutParams.FLAG_DIM_BEHIND; |
| 2497 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2498 | if (!haveDimAmount()) { |
| 2499 | params.dimAmount = a.getFloat( |
| 2500 | android.R.styleable.Window_backgroundDimAmount, 0.5f); |
| 2501 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2502 | } |
| 2503 | |
| 2504 | if (params.windowAnimations == 0) { |
| 2505 | params.windowAnimations = a.getResourceId( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2506 | R.styleable.Window_windowAnimationStyle, 0); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2507 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 2508 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2509 | // The rest are only done if this window is not embedded; otherwise, |
| 2510 | // the values are inherited from our container. |
| 2511 | if (getContainer() == null) { |
| 2512 | if (mBackgroundDrawable == null) { |
| 2513 | if (mBackgroundResource == 0) { |
| 2514 | mBackgroundResource = a.getResourceId( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2515 | R.styleable.Window_windowBackground, 0); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2516 | } |
| 2517 | if (mFrameResource == 0) { |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2518 | mFrameResource = a.getResourceId(R.styleable.Window_windowFrame, 0); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2519 | } |
Adam Powell | f849a5e | 2014-09-11 15:09:36 -0700 | [diff] [blame] | 2520 | mBackgroundFallbackResource = a.getResourceId( |
| 2521 | R.styleable.Window_windowBackgroundFallback, 0); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2522 | if (false) { |
| 2523 | System.out.println("Background: " |
| 2524 | + Integer.toHexString(mBackgroundResource) + " Frame: " |
| 2525 | + Integer.toHexString(mFrameResource)); |
| 2526 | } |
| 2527 | } |
Wale Ogunwale | 0d7e912 | 2015-11-17 10:45:06 -0800 | [diff] [blame] | 2528 | if (mLoadElevation) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 2529 | mElevation = a.getDimension(R.styleable.Window_windowElevation, 0); |
| 2530 | } |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2531 | mClipToOutline = a.getBoolean(R.styleable.Window_windowClipToOutline, false); |
| 2532 | mTextColor = a.getColor(R.styleable.Window_textColor, Color.TRANSPARENT); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2533 | } |
| 2534 | |
| 2535 | // Inflate the window decor. |
| 2536 | |
| 2537 | int layoutResource; |
| 2538 | int features = getLocalFeatures(); |
| 2539 | // System.out.println("Features: 0x" + Integer.toHexString(features)); |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 2540 | if ((features & (1 << FEATURE_SWIPE_TO_DISMISS)) != 0) { |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2541 | layoutResource = R.layout.screen_swipe_dismiss; |
Michael Kwan | f7964be | 2016-11-30 16:44:33 -0800 | [diff] [blame] | 2542 | setCloseOnSwipeEnabled(true); |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 2543 | } else if ((features & ((1 << FEATURE_LEFT_ICON) | (1 << FEATURE_RIGHT_ICON))) != 0) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2544 | if (mIsFloating) { |
Adam Powell | 32aa2c9 | 2011-01-11 15:37:04 -0800 | [diff] [blame] | 2545 | TypedValue res = new TypedValue(); |
| 2546 | getContext().getTheme().resolveAttribute( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2547 | R.attr.dialogTitleIconsDecorLayout, res, true); |
Adam Powell | 32aa2c9 | 2011-01-11 15:37:04 -0800 | [diff] [blame] | 2548 | layoutResource = res.resourceId; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2549 | } else { |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2550 | layoutResource = R.layout.screen_title_icons; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2551 | } |
Adam Powell | f4a6ec4 | 2010-08-24 14:18:10 -0700 | [diff] [blame] | 2552 | // XXX Remove this once action bar supports these features. |
| 2553 | removeFeature(FEATURE_ACTION_BAR); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2554 | // System.out.println("Title Icons!"); |
Adam Powell | 6af97e1 | 2010-11-11 21:11:53 -0800 | [diff] [blame] | 2555 | } else if ((features & ((1 << FEATURE_PROGRESS) | (1 << FEATURE_INDETERMINATE_PROGRESS))) != 0 |
| 2556 | && (features & (1 << FEATURE_ACTION_BAR)) == 0) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2557 | // Special case for a window with only a progress bar (and title). |
| 2558 | // XXX Need to have a no-title version of embedded windows. |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2559 | layoutResource = R.layout.screen_progress; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2560 | // System.out.println("Progress!"); |
| 2561 | } else if ((features & (1 << FEATURE_CUSTOM_TITLE)) != 0) { |
| 2562 | // Special case for a window with a custom title. |
| 2563 | // If the window is floating, we need a dialog layout |
| 2564 | if (mIsFloating) { |
Adam Powell | 32aa2c9 | 2011-01-11 15:37:04 -0800 | [diff] [blame] | 2565 | TypedValue res = new TypedValue(); |
| 2566 | getContext().getTheme().resolveAttribute( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2567 | R.attr.dialogCustomTitleDecorLayout, res, true); |
Adam Powell | 32aa2c9 | 2011-01-11 15:37:04 -0800 | [diff] [blame] | 2568 | layoutResource = res.resourceId; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2569 | } else { |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2570 | layoutResource = R.layout.screen_custom_title; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2571 | } |
Adam Powell | f4a6ec4 | 2010-08-24 14:18:10 -0700 | [diff] [blame] | 2572 | // XXX Remove this once action bar supports these features. |
| 2573 | removeFeature(FEATURE_ACTION_BAR); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2574 | } else if ((features & (1 << FEATURE_NO_TITLE)) == 0) { |
| 2575 | // If no other features and not embedded, only need a title. |
| 2576 | // If the window is floating, we need a dialog layout |
| 2577 | if (mIsFloating) { |
Adam Powell | 32aa2c9 | 2011-01-11 15:37:04 -0800 | [diff] [blame] | 2578 | TypedValue res = new TypedValue(); |
| 2579 | getContext().getTheme().resolveAttribute( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2580 | R.attr.dialogTitleDecorLayout, res, true); |
Adam Powell | 32aa2c9 | 2011-01-11 15:37:04 -0800 | [diff] [blame] | 2581 | layoutResource = res.resourceId; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 2582 | } else if ((features & (1 << FEATURE_ACTION_BAR)) != 0) { |
Adam Powell | e021e6e | 2014-05-23 17:27:24 -0700 | [diff] [blame] | 2583 | layoutResource = a.getResourceId( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2584 | R.styleable.Window_windowActionBarFullscreenDecorLayout, |
| 2585 | R.layout.screen_action_bar); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2586 | } else { |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2587 | layoutResource = R.layout.screen_title; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2588 | } |
| 2589 | // System.out.println("Title!"); |
Adam Powell | f8419a0 | 2011-10-03 12:08:54 -0700 | [diff] [blame] | 2590 | } else if ((features & (1 << FEATURE_ACTION_MODE_OVERLAY)) != 0) { |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2591 | layoutResource = R.layout.screen_simple_overlay_action_mode; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2592 | } else { |
| 2593 | // Embedded, so no decoration is needed. |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2594 | layoutResource = R.layout.screen_simple; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2595 | // System.out.println("Simple!"); |
| 2596 | } |
| 2597 | |
| 2598 | mDecor.startChanging(); |
Filip Gruszczynski | 3dec081 | 2015-12-09 08:42:41 -0800 | [diff] [blame] | 2599 | mDecor.onResourcesLoaded(mLayoutInflater, layoutResource); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2600 | |
| 2601 | ViewGroup contentParent = (ViewGroup)findViewById(ID_ANDROID_CONTENT); |
| 2602 | if (contentParent == null) { |
| 2603 | throw new RuntimeException("Window couldn't find content container view"); |
| 2604 | } |
| 2605 | |
| 2606 | if ((features & (1 << FEATURE_INDETERMINATE_PROGRESS)) != 0) { |
| 2607 | ProgressBar progress = getCircularProgressBar(false); |
| 2608 | if (progress != null) { |
| 2609 | progress.setIndeterminate(true); |
| 2610 | } |
| 2611 | } |
| 2612 | |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 2613 | if ((features & (1 << FEATURE_SWIPE_TO_DISMISS)) != 0) { |
Michael Kwan | f7964be | 2016-11-30 16:44:33 -0800 | [diff] [blame] | 2614 | registerSwipeCallbacks(contentParent); |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 2615 | } |
| 2616 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2617 | // Remaining setup -- of background and title -- that only applies |
| 2618 | // to top-level windows. |
| 2619 | if (getContainer() == null) { |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 2620 | final Drawable background; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2621 | if (mBackgroundResource != 0) { |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 2622 | background = getContext().getDrawable(mBackgroundResource); |
| 2623 | } else { |
| 2624 | background = mBackgroundDrawable; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2625 | } |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 2626 | mDecor.setWindowBackground(background); |
| 2627 | |
| 2628 | final Drawable frame; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2629 | if (mFrameResource != 0) { |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 2630 | frame = getContext().getDrawable(mFrameResource); |
| 2631 | } else { |
| 2632 | frame = null; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2633 | } |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 2634 | mDecor.setWindowFrame(frame); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2635 | |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 2636 | mDecor.setElevation(mElevation); |
Alan Viverette | 2c18333 | 2014-08-07 13:43:05 -0700 | [diff] [blame] | 2637 | mDecor.setClipToOutline(mClipToOutline); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2638 | |
| 2639 | if (mTitle != null) { |
| 2640 | setTitle(mTitle); |
| 2641 | } |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 2642 | |
| 2643 | if (mTitleColor == 0) { |
| 2644 | mTitleColor = mTextColor; |
| 2645 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2646 | setTitleColor(mTitleColor); |
| 2647 | } |
| 2648 | |
| 2649 | mDecor.finishChanging(); |
| 2650 | |
| 2651 | return contentParent; |
| 2652 | } |
| 2653 | |
Dianne Hackborn | cfaf887 | 2011-01-18 13:57:54 -0800 | [diff] [blame] | 2654 | /** @hide */ |
| 2655 | public void alwaysReadCloseOnTouchAttr() { |
| 2656 | mAlwaysReadCloseOnTouchAttr = true; |
| 2657 | } |
| 2658 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2659 | private void installDecor() { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 2660 | mForceDecorInstall = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2661 | if (mDecor == null) { |
Stefan Kuhne | 61b47bb | 2015-07-28 14:04:25 -0700 | [diff] [blame] | 2662 | mDecor = generateDecor(-1); |
Adam Powell | 00f4d98 | 2010-03-24 11:17:03 -0700 | [diff] [blame] | 2663 | mDecor.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2664 | mDecor.setIsRootNamespace(true); |
Adam Powell | 4b6d93f | 2012-09-18 18:34:08 -0700 | [diff] [blame] | 2665 | if (!mInvalidatePanelMenuPosted && mInvalidatePanelMenuFeatures != 0) { |
| 2666 | mDecor.postOnAnimation(mInvalidatePanelMenuRunnable); |
| 2667 | } |
Filip Gruszczynski | 0daf210 | 2015-09-29 08:39:07 -0700 | [diff] [blame] | 2668 | } else { |
| 2669 | mDecor.setWindow(this); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2670 | } |
| 2671 | if (mContentParent == null) { |
| 2672 | mContentParent = generateLayout(mDecor); |
| 2673 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2674 | // Set up decor part of UI to ignore fitsSystemWindows if appropriate. |
| 2675 | mDecor.makeOptionalFitsSystemWindows(); |
| 2676 | |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 2677 | final DecorContentParent decorContentParent = (DecorContentParent) mDecor.findViewById( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2678 | R.id.decor_content_parent); |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 2679 | |
| 2680 | if (decorContentParent != null) { |
| 2681 | mDecorContentParent = decorContentParent; |
| 2682 | mDecorContentParent.setWindowCallback(getCallback()); |
| 2683 | if (mDecorContentParent.getTitle() == null) { |
| 2684 | mDecorContentParent.setWindowTitle(mTitle); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2685 | } |
Adam Powell | 9b4bee0 | 2011-04-27 19:24:47 -0700 | [diff] [blame] | 2686 | |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 2687 | final int localFeatures = getLocalFeatures(); |
| 2688 | for (int i = 0; i < FEATURE_MAX; i++) { |
| 2689 | if ((localFeatures & (1 << i)) != 0) { |
| 2690 | mDecorContentParent.initFeature(i); |
Adam Powell | 9b0dc28 | 2013-07-31 13:58:43 -0700 | [diff] [blame] | 2691 | } |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 2692 | } |
Adam Powell | 9b0dc28 | 2013-07-31 13:58:43 -0700 | [diff] [blame] | 2693 | |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 2694 | mDecorContentParent.setUiOptions(mUiOptions); |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 2695 | |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 2696 | if ((mResourcesSetFlags & FLAG_RESOURCE_SET_ICON) != 0 || |
| 2697 | (mIconRes != 0 && !mDecorContentParent.hasIcon())) { |
| 2698 | mDecorContentParent.setIcon(mIconRes); |
| 2699 | } else if ((mResourcesSetFlags & FLAG_RESOURCE_SET_ICON) == 0 && |
| 2700 | mIconRes == 0 && !mDecorContentParent.hasIcon()) { |
| 2701 | mDecorContentParent.setIcon( |
| 2702 | getContext().getPackageManager().getDefaultActivityIcon()); |
| 2703 | mResourcesSetFlags |= FLAG_RESOURCE_SET_ICON_FALLBACK; |
| 2704 | } |
| 2705 | if ((mResourcesSetFlags & FLAG_RESOURCE_SET_LOGO) != 0 || |
| 2706 | (mLogoRes != 0 && !mDecorContentParent.hasLogo())) { |
| 2707 | mDecorContentParent.setLogo(mLogoRes); |
| 2708 | } |
Adam Powell | 9b4bee0 | 2011-04-27 19:24:47 -0700 | [diff] [blame] | 2709 | |
Adam Powell | 31c91c8 | 2014-08-22 17:20:00 -0700 | [diff] [blame] | 2710 | // Invalidate if the panel menu hasn't been created before this. |
| 2711 | // Panel menu invalidation is deferred avoiding application onCreateOptionsMenu |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 2712 | // being called in the middle of onCreate or similar. |
Adam Powell | 31c91c8 | 2014-08-22 17:20:00 -0700 | [diff] [blame] | 2713 | // A pending invalidation will typically be resolved before the posted message |
| 2714 | // would run normally in order to satisfy instance state restoration. |
| 2715 | PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, false); |
Jorim Jaggi | a16cc15 | 2015-06-01 16:55:05 -0700 | [diff] [blame] | 2716 | if (!isDestroyed() && (st == null || st.menu == null) && !mIsStartingWindow) { |
Adam Powell | 31c91c8 | 2014-08-22 17:20:00 -0700 | [diff] [blame] | 2717 | invalidatePanelMenu(FEATURE_ACTION_BAR); |
| 2718 | } |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 2719 | } else { |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 2720 | mTitleView = findViewById(R.id.title); |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 2721 | if (mTitleView != null) { |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 2722 | if ((getLocalFeatures() & (1 << FEATURE_NO_TITLE)) != 0) { |
Alan Viverette | 891c9ee | 2016-01-08 13:43:15 -0500 | [diff] [blame] | 2723 | final View titleContainer = findViewById(R.id.title_container); |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 2724 | if (titleContainer != null) { |
| 2725 | titleContainer.setVisibility(View.GONE); |
| 2726 | } else { |
| 2727 | mTitleView.setVisibility(View.GONE); |
| 2728 | } |
Alan Viverette | 891c9ee | 2016-01-08 13:43:15 -0500 | [diff] [blame] | 2729 | mContentParent.setForeground(null); |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 2730 | } else { |
| 2731 | mTitleView.setText(mTitle); |
| 2732 | } |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 2733 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2734 | } |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 2735 | |
Adam Powell | f849a5e | 2014-09-11 15:09:36 -0700 | [diff] [blame] | 2736 | if (mDecor.getBackground() == null && mBackgroundFallbackResource != 0) { |
| 2737 | mDecor.setBackgroundFallback(mBackgroundFallbackResource); |
| 2738 | } |
| 2739 | |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 2740 | // Only inflate or create a new TransitionManager if the caller hasn't |
| 2741 | // already set a custom one. |
George Mount | 9826f63 | 2014-09-11 08:50:09 -0700 | [diff] [blame] | 2742 | if (hasFeature(FEATURE_ACTIVITY_TRANSITIONS)) { |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 2743 | if (mTransitionManager == null) { |
| 2744 | final int transitionRes = getWindowStyle().getResourceId( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2745 | R.styleable.Window_windowContentTransitionManager, |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 2746 | 0); |
| 2747 | if (transitionRes != 0) { |
| 2748 | final TransitionInflater inflater = TransitionInflater.from(getContext()); |
| 2749 | mTransitionManager = inflater.inflateTransitionManager(transitionRes, |
| 2750 | mContentParent); |
| 2751 | } else { |
| 2752 | mTransitionManager = new TransitionManager(); |
| 2753 | } |
| 2754 | } |
| 2755 | |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 2756 | mEnterTransition = getTransition(mEnterTransition, null, |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2757 | R.styleable.Window_windowEnterTransition); |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 2758 | mReturnTransition = getTransition(mReturnTransition, USE_DEFAULT_TRANSITION, |
| 2759 | R.styleable.Window_windowReturnTransition); |
| 2760 | mExitTransition = getTransition(mExitTransition, null, |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2761 | R.styleable.Window_windowExitTransition); |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 2762 | mReenterTransition = getTransition(mReenterTransition, USE_DEFAULT_TRANSITION, |
| 2763 | R.styleable.Window_windowReenterTransition); |
| 2764 | mSharedElementEnterTransition = getTransition(mSharedElementEnterTransition, null, |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2765 | R.styleable.Window_windowSharedElementEnterTransition); |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 2766 | mSharedElementReturnTransition = getTransition(mSharedElementReturnTransition, |
| 2767 | USE_DEFAULT_TRANSITION, |
| 2768 | R.styleable.Window_windowSharedElementReturnTransition); |
| 2769 | mSharedElementExitTransition = getTransition(mSharedElementExitTransition, null, |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2770 | R.styleable.Window_windowSharedElementExitTransition); |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 2771 | mSharedElementReenterTransition = getTransition(mSharedElementReenterTransition, |
| 2772 | USE_DEFAULT_TRANSITION, |
| 2773 | R.styleable.Window_windowSharedElementReenterTransition); |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 2774 | if (mAllowEnterTransitionOverlap == null) { |
| 2775 | mAllowEnterTransitionOverlap = getWindowStyle().getBoolean( |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 2776 | R.styleable.Window_windowAllowEnterTransitionOverlap, true); |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 2777 | } |
George Mount | c03da0e | 2014-08-22 17:04:02 -0700 | [diff] [blame] | 2778 | if (mAllowReturnTransitionOverlap == null) { |
| 2779 | mAllowReturnTransitionOverlap = getWindowStyle().getBoolean( |
| 2780 | R.styleable.Window_windowAllowReturnTransitionOverlap, true); |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 2781 | } |
George Mount | ed1e01d | 2014-06-05 13:49:12 -0700 | [diff] [blame] | 2782 | if (mBackgroundFadeDurationMillis < 0) { |
| 2783 | mBackgroundFadeDurationMillis = getWindowStyle().getInteger( |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 2784 | R.styleable.Window_windowTransitionBackgroundFadeDuration, |
George Mount | ed1e01d | 2014-06-05 13:49:12 -0700 | [diff] [blame] | 2785 | DEFAULT_BACKGROUND_FADE_DURATION_MS); |
| 2786 | } |
George Mount | b89d5cc | 2014-08-18 16:50:50 -0700 | [diff] [blame] | 2787 | if (mSharedElementsUseOverlay == null) { |
| 2788 | mSharedElementsUseOverlay = getWindowStyle().getBoolean( |
| 2789 | R.styleable.Window_windowSharedElementsUseOverlay, true); |
| 2790 | } |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 2791 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2792 | } |
| 2793 | } |
| 2794 | |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 2795 | private Transition getTransition(Transition currentValue, Transition defaultValue, int id) { |
| 2796 | if (currentValue != defaultValue) { |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 2797 | return currentValue; |
| 2798 | } |
| 2799 | int transitionId = getWindowStyle().getResourceId(id, -1); |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 2800 | Transition transition = defaultValue; |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2801 | if (transitionId != -1 && transitionId != R.transition.no_transition) { |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 2802 | TransitionInflater inflater = TransitionInflater.from(getContext()); |
| 2803 | transition = inflater.inflateTransition(transitionId); |
George Mount | 7f15164 | 2014-08-18 16:24:21 -0700 | [diff] [blame] | 2804 | if (transition instanceof TransitionSet && |
| 2805 | ((TransitionSet)transition).getTransitionCount() == 0) { |
| 2806 | transition = null; |
| 2807 | } |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 2808 | } |
| 2809 | return transition; |
| 2810 | } |
| 2811 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2812 | private Drawable loadImageURI(Uri uri) { |
| 2813 | try { |
Alan Viverette | ad3c4a1 | 2014-06-02 17:12:58 -0700 | [diff] [blame] | 2814 | return Drawable.createFromStream( |
| 2815 | getContext().getContentResolver().openInputStream(uri), null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2816 | } catch (Exception e) { |
| 2817 | Log.w(TAG, "Unable to open content: " + uri); |
| 2818 | } |
| 2819 | return null; |
| 2820 | } |
| 2821 | |
| 2822 | private DrawableFeatureState getDrawableState(int featureId, boolean required) { |
| 2823 | if ((getFeatures() & (1 << featureId)) == 0) { |
| 2824 | if (!required) { |
| 2825 | return null; |
| 2826 | } |
| 2827 | throw new RuntimeException("The feature has not been requested"); |
| 2828 | } |
| 2829 | |
| 2830 | DrawableFeatureState[] ar; |
| 2831 | if ((ar = mDrawables) == null || ar.length <= featureId) { |
| 2832 | DrawableFeatureState[] nar = new DrawableFeatureState[featureId + 1]; |
| 2833 | if (ar != null) { |
| 2834 | System.arraycopy(ar, 0, nar, 0, ar.length); |
| 2835 | } |
| 2836 | mDrawables = ar = nar; |
| 2837 | } |
| 2838 | |
| 2839 | DrawableFeatureState st = ar[featureId]; |
| 2840 | if (st == null) { |
| 2841 | ar[featureId] = st = new DrawableFeatureState(featureId); |
| 2842 | } |
| 2843 | return st; |
| 2844 | } |
| 2845 | |
| 2846 | /** |
| 2847 | * Gets a panel's state based on its feature ID. |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 2848 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2849 | * @param featureId The feature ID of the panel. |
| 2850 | * @param required Whether the panel is required (if it is required and it |
| 2851 | * isn't in our features, this throws an exception). |
| 2852 | * @return The panel state. |
| 2853 | */ |
Wale Ogunwale | 8804af2 | 2015-11-17 09:18:15 -0800 | [diff] [blame] | 2854 | PanelFeatureState getPanelState(int featureId, boolean required) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2855 | return getPanelState(featureId, required, null); |
| 2856 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 2857 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2858 | /** |
| 2859 | * Gets a panel's state based on its feature ID. |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 2860 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2861 | * @param featureId The feature ID of the panel. |
| 2862 | * @param required Whether the panel is required (if it is required and it |
| 2863 | * isn't in our features, this throws an exception). |
| 2864 | * @param convertPanelState Optional: If the panel state does not exist, use |
| 2865 | * this as the panel state. |
| 2866 | * @return The panel state. |
| 2867 | */ |
| 2868 | private PanelFeatureState getPanelState(int featureId, boolean required, |
| 2869 | PanelFeatureState convertPanelState) { |
| 2870 | if ((getFeatures() & (1 << featureId)) == 0) { |
| 2871 | if (!required) { |
| 2872 | return null; |
| 2873 | } |
| 2874 | throw new RuntimeException("The feature has not been requested"); |
| 2875 | } |
| 2876 | |
| 2877 | PanelFeatureState[] ar; |
| 2878 | if ((ar = mPanels) == null || ar.length <= featureId) { |
| 2879 | PanelFeatureState[] nar = new PanelFeatureState[featureId + 1]; |
| 2880 | if (ar != null) { |
| 2881 | System.arraycopy(ar, 0, nar, 0, ar.length); |
| 2882 | } |
| 2883 | mPanels = ar = nar; |
| 2884 | } |
| 2885 | |
| 2886 | PanelFeatureState st = ar[featureId]; |
| 2887 | if (st == null) { |
| 2888 | ar[featureId] = st = (convertPanelState != null) |
| 2889 | ? convertPanelState |
| 2890 | : new PanelFeatureState(featureId); |
| 2891 | } |
| 2892 | return st; |
| 2893 | } |
| 2894 | |
| 2895 | @Override |
| 2896 | public final void setChildDrawable(int featureId, Drawable drawable) { |
| 2897 | DrawableFeatureState st = getDrawableState(featureId, true); |
| 2898 | st.child = drawable; |
| 2899 | updateDrawable(featureId, st, false); |
| 2900 | } |
| 2901 | |
| 2902 | @Override |
| 2903 | public final void setChildInt(int featureId, int value) { |
| 2904 | updateInt(featureId, value, false); |
| 2905 | } |
| 2906 | |
| 2907 | @Override |
| 2908 | public boolean isShortcutKey(int keyCode, KeyEvent event) { |
Jose Lima | 7a22fc6 | 2015-01-23 17:24:22 -0800 | [diff] [blame] | 2909 | PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, false); |
| 2910 | return st != null && st.menu != null && st.menu.isShortcutKey(keyCode, event); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2911 | } |
| 2912 | |
| 2913 | private void updateDrawable(int featureId, DrawableFeatureState st, boolean fromResume) { |
| 2914 | // Do nothing if the decor is not yet installed... an update will |
| 2915 | // need to be forced when we eventually become active. |
| 2916 | if (mContentParent == null) { |
| 2917 | return; |
| 2918 | } |
| 2919 | |
| 2920 | final int featureMask = 1 << featureId; |
| 2921 | |
| 2922 | if ((getFeatures() & featureMask) == 0 && !fromResume) { |
| 2923 | return; |
| 2924 | } |
| 2925 | |
| 2926 | Drawable drawable = null; |
| 2927 | if (st != null) { |
| 2928 | drawable = st.child; |
| 2929 | if (drawable == null) |
| 2930 | drawable = st.local; |
| 2931 | if (drawable == null) |
| 2932 | drawable = st.def; |
| 2933 | } |
| 2934 | if ((getLocalFeatures() & featureMask) == 0) { |
| 2935 | if (getContainer() != null) { |
| 2936 | if (isActive() || fromResume) { |
| 2937 | getContainer().setChildDrawable(featureId, drawable); |
| 2938 | } |
| 2939 | } |
| 2940 | } else if (st != null && (st.cur != drawable || st.curAlpha != st.alpha)) { |
| 2941 | // System.out.println("Drawable changed: old=" + st.cur |
| 2942 | // + ", new=" + drawable); |
| 2943 | st.cur = drawable; |
| 2944 | st.curAlpha = st.alpha; |
| 2945 | onDrawableChanged(featureId, drawable, st.alpha); |
| 2946 | } |
| 2947 | } |
| 2948 | |
| 2949 | private void updateInt(int featureId, int value, boolean fromResume) { |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 2950 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2951 | // Do nothing if the decor is not yet installed... an update will |
| 2952 | // need to be forced when we eventually become active. |
| 2953 | if (mContentParent == null) { |
| 2954 | return; |
| 2955 | } |
| 2956 | |
| 2957 | final int featureMask = 1 << featureId; |
| 2958 | |
| 2959 | if ((getFeatures() & featureMask) == 0 && !fromResume) { |
| 2960 | return; |
| 2961 | } |
| 2962 | |
| 2963 | if ((getLocalFeatures() & featureMask) == 0) { |
| 2964 | if (getContainer() != null) { |
| 2965 | getContainer().setChildInt(featureId, value); |
| 2966 | } |
| 2967 | } else { |
| 2968 | onIntChanged(featureId, value); |
| 2969 | } |
| 2970 | } |
| 2971 | |
| 2972 | private ImageView getLeftIconView() { |
| 2973 | if (mLeftIconView != null) { |
| 2974 | return mLeftIconView; |
| 2975 | } |
| 2976 | if (mContentParent == null) { |
| 2977 | installDecor(); |
| 2978 | } |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2979 | return (mLeftIconView = (ImageView)findViewById(R.id.left_icon)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2980 | } |
| 2981 | |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2982 | @Override |
| 2983 | protected void dispatchWindowAttributesChanged(WindowManager.LayoutParams attrs) { |
| 2984 | super.dispatchWindowAttributesChanged(attrs); |
| 2985 | if (mDecor != null) { |
Adrian Roos | 05054bd | 2014-10-27 17:04:10 +0100 | [diff] [blame] | 2986 | mDecor.updateColorViews(null /* insets */, true /* animate */); |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2987 | } |
| 2988 | } |
| 2989 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2990 | private ProgressBar getCircularProgressBar(boolean shouldInstallDecor) { |
| 2991 | if (mCircularProgressBar != null) { |
| 2992 | return mCircularProgressBar; |
| 2993 | } |
| 2994 | if (mContentParent == null && shouldInstallDecor) { |
| 2995 | installDecor(); |
| 2996 | } |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 2997 | mCircularProgressBar = findViewById(R.id.progress_circular); |
Adam Powell | 6af97e1 | 2010-11-11 21:11:53 -0800 | [diff] [blame] | 2998 | if (mCircularProgressBar != null) { |
| 2999 | mCircularProgressBar.setVisibility(View.INVISIBLE); |
| 3000 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3001 | return mCircularProgressBar; |
| 3002 | } |
| 3003 | |
| 3004 | private ProgressBar getHorizontalProgressBar(boolean shouldInstallDecor) { |
| 3005 | if (mHorizontalProgressBar != null) { |
| 3006 | return mHorizontalProgressBar; |
| 3007 | } |
| 3008 | if (mContentParent == null && shouldInstallDecor) { |
| 3009 | installDecor(); |
| 3010 | } |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 3011 | mHorizontalProgressBar = findViewById(R.id.progress_horizontal); |
Adam Powell | 6af97e1 | 2010-11-11 21:11:53 -0800 | [diff] [blame] | 3012 | if (mHorizontalProgressBar != null) { |
| 3013 | mHorizontalProgressBar.setVisibility(View.INVISIBLE); |
| 3014 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3015 | return mHorizontalProgressBar; |
| 3016 | } |
| 3017 | |
| 3018 | private ImageView getRightIconView() { |
| 3019 | if (mRightIconView != null) { |
| 3020 | return mRightIconView; |
| 3021 | } |
| 3022 | if (mContentParent == null) { |
| 3023 | installDecor(); |
| 3024 | } |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 3025 | return (mRightIconView = (ImageView)findViewById(R.id.right_icon)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3026 | } |
| 3027 | |
Michael Kwan | f7964be | 2016-11-30 16:44:33 -0800 | [diff] [blame] | 3028 | private void registerSwipeCallbacks(ViewGroup contentParent) { |
| 3029 | if (!(contentParent instanceof SwipeDismissLayout)) { |
| 3030 | Log.w(TAG, "contentParent is not a SwipeDismissLayout: " + contentParent); |
| 3031 | return; |
| 3032 | } |
| 3033 | SwipeDismissLayout swipeDismiss = (SwipeDismissLayout) contentParent; |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 3034 | swipeDismiss.setOnDismissedListener(new SwipeDismissLayout.OnDismissedListener() { |
| 3035 | @Override |
| 3036 | public void onDismissed(SwipeDismissLayout layout) { |
Michael Kwan | 67639a5 | 2016-12-16 12:38:10 -0800 | [diff] [blame] | 3037 | dispatchOnWindowSwipeDismissed(); |
Ned Burns | 7d6cb91 | 2016-12-02 17:25:33 -0500 | [diff] [blame] | 3038 | dispatchOnWindowDismissed(false /*finishTask*/, true /*suppressWindowTransition*/); |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 3039 | } |
| 3040 | }); |
| 3041 | swipeDismiss.setOnSwipeProgressChangedListener( |
| 3042 | new SwipeDismissLayout.OnSwipeProgressChangedListener() { |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 3043 | @Override |
| 3044 | public void onSwipeProgressChanged( |
Ned Burns | 7d6cb91 | 2016-12-02 17:25:33 -0500 | [diff] [blame] | 3045 | SwipeDismissLayout layout, float alpha, float translate) { |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 3046 | WindowManager.LayoutParams newParams = getAttributes(); |
| 3047 | newParams.x = (int) translate; |
Ned Burns | 7d6cb91 | 2016-12-02 17:25:33 -0500 | [diff] [blame] | 3048 | newParams.alpha = alpha; |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 3049 | setAttributes(newParams); |
| 3050 | |
| 3051 | int flags = 0; |
| 3052 | if (newParams.x == 0) { |
| 3053 | flags = FLAG_FULLSCREEN; |
| 3054 | } else { |
| 3055 | flags = FLAG_LAYOUT_NO_LIMITS; |
| 3056 | } |
| 3057 | setFlags(flags, FLAG_FULLSCREEN | FLAG_LAYOUT_NO_LIMITS); |
| 3058 | } |
| 3059 | |
| 3060 | @Override |
| 3061 | public void onSwipeCancelled(SwipeDismissLayout layout) { |
| 3062 | WindowManager.LayoutParams newParams = getAttributes(); |
Michael Kwan | 134ad6e | 2017-02-10 18:38:34 -0800 | [diff] [blame] | 3063 | // Swipe changes only affect the x-translation and alpha, check to see if |
| 3064 | // those values have changed first before resetting them. |
| 3065 | if (newParams.x != 0 || newParams.alpha != 1) { |
| 3066 | newParams.x = 0; |
| 3067 | newParams.alpha = 1; |
| 3068 | setAttributes(newParams); |
| 3069 | setFlags(FLAG_FULLSCREEN, FLAG_FULLSCREEN | FLAG_LAYOUT_NO_LIMITS); |
| 3070 | } |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 3071 | } |
| 3072 | }); |
| 3073 | } |
| 3074 | |
Michael Kwan | f7964be | 2016-11-30 16:44:33 -0800 | [diff] [blame] | 3075 | /** @hide */ |
| 3076 | @Override |
| 3077 | public void setCloseOnSwipeEnabled(boolean closeOnSwipeEnabled) { |
| 3078 | if (hasFeature(Window.FEATURE_SWIPE_TO_DISMISS) // swipe-to-dismiss feature is requested |
| 3079 | && mContentParent instanceof SwipeDismissLayout) { // check casting mContentParent |
| 3080 | ((SwipeDismissLayout) mContentParent).setDismissable(closeOnSwipeEnabled); |
| 3081 | } |
| 3082 | super.setCloseOnSwipeEnabled(closeOnSwipeEnabled); |
| 3083 | } |
| 3084 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3085 | /** |
| 3086 | * Helper method for calling the {@link Callback#onPanelClosed(int, Menu)} |
| 3087 | * callback. This method will grab whatever extra state is needed for the |
| 3088 | * callback that isn't given in the parameters. If the panel is not open, |
| 3089 | * this will not perform the callback. |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3090 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3091 | * @param featureId Feature ID of the panel that was closed. Must be given. |
| 3092 | * @param panel Panel that was closed. Optional but useful if there is no |
| 3093 | * menu given. |
| 3094 | * @param menu The menu that was closed. Optional, but give if you have. |
| 3095 | */ |
| 3096 | private void callOnPanelClosed(int featureId, PanelFeatureState panel, Menu menu) { |
| 3097 | final Callback cb = getCallback(); |
| 3098 | if (cb == null) |
| 3099 | return; |
| 3100 | |
| 3101 | // Try to get a menu |
| 3102 | if (menu == null) { |
| 3103 | // Need a panel to grab the menu, so try to get that |
| 3104 | if (panel == null) { |
| 3105 | if ((featureId >= 0) && (featureId < mPanels.length)) { |
| 3106 | panel = mPanels[featureId]; |
| 3107 | } |
| 3108 | } |
| 3109 | |
| 3110 | if (panel != null) { |
| 3111 | // menu still may be null, which is okay--we tried our best |
| 3112 | menu = panel.menu; |
| 3113 | } |
| 3114 | } |
| 3115 | |
| 3116 | // If the panel is not open, do not callback |
| 3117 | if ((panel != null) && (!panel.isOpen)) |
| 3118 | return; |
| 3119 | |
Dianne Hackborn | b66ad57 | 2011-03-01 17:10:30 -0800 | [diff] [blame] | 3120 | if (!isDestroyed()) { |
| 3121 | cb.onPanelClosed(featureId, menu); |
| 3122 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3123 | } |
| 3124 | |
| 3125 | /** |
Sujith Ramakrishnan | 0390fff | 2017-06-08 18:18:12 -0700 | [diff] [blame] | 3126 | * Check if Setup or Post-Setup update is completed on TV |
| 3127 | * @return true if completed |
| 3128 | */ |
| 3129 | private boolean isTvUserSetupComplete() { |
| 3130 | boolean isTvSetupComplete = Settings.Secure.getInt(getContext().getContentResolver(), |
| 3131 | Settings.Secure.USER_SETUP_COMPLETE, 0) != 0; |
| 3132 | isTvSetupComplete &= Settings.Secure.getInt(getContext().getContentResolver(), |
| 3133 | Settings.Secure.TV_USER_SETUP_COMPLETE, 0) != 0; |
| 3134 | return isTvSetupComplete; |
| 3135 | } |
| 3136 | |
| 3137 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3138 | * Helper method for adding launch-search to most applications. Opens the |
| 3139 | * search window using default settings. |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3140 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3141 | * @return true if search window opened |
| 3142 | */ |
Tim Kilbourn | 6a975b3 | 2015-04-09 17:14:34 -0700 | [diff] [blame] | 3143 | private boolean launchDefaultSearch(KeyEvent event) { |
Sujith Ramakrishnan | 0390fff | 2017-06-08 18:18:12 -0700 | [diff] [blame] | 3144 | if (getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK) |
| 3145 | && !isTvUserSetupComplete()) { |
| 3146 | // If we are in Setup or Post-Setup update mode on TV, consume the search key |
| 3147 | return false; |
| 3148 | } |
Dianne Hackborn | fdf5b35 | 2014-10-08 17:43:48 -0700 | [diff] [blame] | 3149 | boolean result; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3150 | final Callback cb = getCallback(); |
Dianne Hackborn | b66ad57 | 2011-03-01 17:10:30 -0800 | [diff] [blame] | 3151 | if (cb == null || isDestroyed()) { |
Dianne Hackborn | fdf5b35 | 2014-10-08 17:43:48 -0700 | [diff] [blame] | 3152 | result = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3153 | } else { |
Karl Rosaen | 323216b | 2009-07-20 14:00:29 -0700 | [diff] [blame] | 3154 | sendCloseSystemWindows("search"); |
Tim Kilbourn | 6a975b3 | 2015-04-09 17:14:34 -0700 | [diff] [blame] | 3155 | int deviceId = event.getDeviceId(); |
| 3156 | SearchEvent searchEvent = null; |
| 3157 | if (deviceId != 0) { |
| 3158 | searchEvent = new SearchEvent(InputDevice.getDevice(deviceId)); |
| 3159 | } |
Adam Powell | 9790034 | 2015-04-15 13:12:52 -0700 | [diff] [blame] | 3160 | try { |
| 3161 | result = cb.onSearchRequested(searchEvent); |
| 3162 | } catch (AbstractMethodError e) { |
| 3163 | Log.e(TAG, "WindowCallback " + cb.getClass().getName() + " does not implement" |
| 3164 | + " method onSearchRequested(SearchEvent); fa", e); |
| 3165 | result = cb.onSearchRequested(); |
| 3166 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3167 | } |
Dianne Hackborn | fdf5b35 | 2014-10-08 17:43:48 -0700 | [diff] [blame] | 3168 | if (!result && (getContext().getResources().getConfiguration().uiMode |
| 3169 | & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) { |
| 3170 | // On TVs, if the app doesn't implement search, we want to launch assist. |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 3171 | Bundle args = new Bundle(); |
| 3172 | args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, event.getDeviceId()); |
Dianne Hackborn | fdf5b35 | 2014-10-08 17:43:48 -0700 | [diff] [blame] | 3173 | return ((SearchManager)getContext().getSystemService(Context.SEARCH_SERVICE)) |
Jeff Sharkey | ad357d1 | 2018-02-02 13:25:31 -0700 | [diff] [blame] | 3174 | .launchLegacyAssist(null, getContext().getUserId(), args); |
Dianne Hackborn | fdf5b35 | 2014-10-08 17:43:48 -0700 | [diff] [blame] | 3175 | } |
| 3176 | return result; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3177 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3178 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3179 | @Override |
| 3180 | public void setVolumeControlStream(int streamType) { |
| 3181 | mVolumeControlStreamType = streamType; |
| 3182 | } |
| 3183 | |
| 3184 | @Override |
| 3185 | public int getVolumeControlStream() { |
| 3186 | return mVolumeControlStreamType; |
| 3187 | } |
| 3188 | |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3189 | @Override |
| 3190 | public void setMediaController(MediaController controller) { |
| 3191 | mMediaController = controller; |
| 3192 | } |
| 3193 | |
| 3194 | @Override |
| 3195 | public MediaController getMediaController() { |
| 3196 | return mMediaController; |
| 3197 | } |
| 3198 | |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 3199 | @Override |
| 3200 | public void setEnterTransition(Transition enterTransition) { |
| 3201 | mEnterTransition = enterTransition; |
| 3202 | } |
| 3203 | |
| 3204 | @Override |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 3205 | public void setReturnTransition(Transition transition) { |
| 3206 | mReturnTransition = transition; |
| 3207 | } |
| 3208 | |
| 3209 | @Override |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 3210 | public void setExitTransition(Transition exitTransition) { |
| 3211 | mExitTransition = exitTransition; |
| 3212 | } |
| 3213 | |
| 3214 | @Override |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 3215 | public void setReenterTransition(Transition transition) { |
| 3216 | mReenterTransition = transition; |
| 3217 | } |
| 3218 | |
| 3219 | @Override |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 3220 | public void setSharedElementEnterTransition(Transition sharedElementEnterTransition) { |
| 3221 | mSharedElementEnterTransition = sharedElementEnterTransition; |
| 3222 | } |
| 3223 | |
| 3224 | @Override |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 3225 | public void setSharedElementReturnTransition(Transition transition) { |
| 3226 | mSharedElementReturnTransition = transition; |
| 3227 | } |
| 3228 | |
| 3229 | @Override |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 3230 | public void setSharedElementExitTransition(Transition sharedElementExitTransition) { |
| 3231 | mSharedElementExitTransition = sharedElementExitTransition; |
| 3232 | } |
| 3233 | |
| 3234 | @Override |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 3235 | public void setSharedElementReenterTransition(Transition transition) { |
| 3236 | mSharedElementReenterTransition = transition; |
| 3237 | } |
| 3238 | |
| 3239 | @Override |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 3240 | public Transition getEnterTransition() { |
| 3241 | return mEnterTransition; |
| 3242 | } |
| 3243 | |
| 3244 | @Override |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 3245 | public Transition getReturnTransition() { |
| 3246 | return mReturnTransition == USE_DEFAULT_TRANSITION ? getEnterTransition() |
| 3247 | : mReturnTransition; |
| 3248 | } |
| 3249 | |
| 3250 | @Override |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 3251 | public Transition getExitTransition() { |
| 3252 | return mExitTransition; |
| 3253 | } |
| 3254 | |
| 3255 | @Override |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 3256 | public Transition getReenterTransition() { |
| 3257 | return mReenterTransition == USE_DEFAULT_TRANSITION ? getExitTransition() |
| 3258 | : mReenterTransition; |
| 3259 | } |
| 3260 | |
| 3261 | @Override |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 3262 | public Transition getSharedElementEnterTransition() { |
| 3263 | return mSharedElementEnterTransition; |
| 3264 | } |
| 3265 | |
| 3266 | @Override |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 3267 | public Transition getSharedElementReturnTransition() { |
| 3268 | return mSharedElementReturnTransition == USE_DEFAULT_TRANSITION |
| 3269 | ? getSharedElementEnterTransition() : mSharedElementReturnTransition; |
| 3270 | } |
| 3271 | |
| 3272 | @Override |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 3273 | public Transition getSharedElementExitTransition() { |
| 3274 | return mSharedElementExitTransition; |
| 3275 | } |
| 3276 | |
| 3277 | @Override |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 3278 | public Transition getSharedElementReenterTransition() { |
| 3279 | return mSharedElementReenterTransition == USE_DEFAULT_TRANSITION |
| 3280 | ? getSharedElementExitTransition() : mSharedElementReenterTransition; |
| 3281 | } |
| 3282 | |
| 3283 | @Override |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 3284 | public void setAllowEnterTransitionOverlap(boolean allow) { |
| 3285 | mAllowEnterTransitionOverlap = allow; |
| 3286 | } |
| 3287 | |
| 3288 | @Override |
| 3289 | public boolean getAllowEnterTransitionOverlap() { |
| 3290 | return (mAllowEnterTransitionOverlap == null) ? true : mAllowEnterTransitionOverlap; |
| 3291 | } |
| 3292 | |
| 3293 | @Override |
George Mount | c03da0e | 2014-08-22 17:04:02 -0700 | [diff] [blame] | 3294 | public void setAllowReturnTransitionOverlap(boolean allowExitTransitionOverlap) { |
| 3295 | mAllowReturnTransitionOverlap = allowExitTransitionOverlap; |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 3296 | } |
| 3297 | |
| 3298 | @Override |
George Mount | c03da0e | 2014-08-22 17:04:02 -0700 | [diff] [blame] | 3299 | public boolean getAllowReturnTransitionOverlap() { |
| 3300 | return (mAllowReturnTransitionOverlap == null) ? true : mAllowReturnTransitionOverlap; |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 3301 | } |
| 3302 | |
George Mount | ed1e01d | 2014-06-05 13:49:12 -0700 | [diff] [blame] | 3303 | @Override |
| 3304 | public long getTransitionBackgroundFadeDuration() { |
| 3305 | return (mBackgroundFadeDurationMillis < 0) ? DEFAULT_BACKGROUND_FADE_DURATION_MS |
| 3306 | : mBackgroundFadeDurationMillis; |
| 3307 | } |
| 3308 | |
| 3309 | @Override |
| 3310 | public void setTransitionBackgroundFadeDuration(long fadeDurationMillis) { |
| 3311 | if (fadeDurationMillis < 0) { |
| 3312 | throw new IllegalArgumentException("negative durations are not allowed"); |
| 3313 | } |
| 3314 | mBackgroundFadeDurationMillis = fadeDurationMillis; |
| 3315 | } |
| 3316 | |
George Mount | b89d5cc | 2014-08-18 16:50:50 -0700 | [diff] [blame] | 3317 | @Override |
| 3318 | public void setSharedElementsUseOverlay(boolean sharedElementsUseOverlay) { |
| 3319 | mSharedElementsUseOverlay = sharedElementsUseOverlay; |
| 3320 | } |
| 3321 | |
| 3322 | @Override |
| 3323 | public boolean getSharedElementsUseOverlay() { |
| 3324 | return (mSharedElementsUseOverlay == null) ? true : mSharedElementsUseOverlay; |
| 3325 | } |
| 3326 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3327 | private static final class DrawableFeatureState { |
| 3328 | DrawableFeatureState(int _featureId) { |
| 3329 | featureId = _featureId; |
| 3330 | } |
| 3331 | |
| 3332 | final int featureId; |
| 3333 | |
| 3334 | int resid; |
| 3335 | |
| 3336 | Uri uri; |
| 3337 | |
| 3338 | Drawable local; |
| 3339 | |
| 3340 | Drawable child; |
| 3341 | |
| 3342 | Drawable def; |
| 3343 | |
| 3344 | Drawable cur; |
| 3345 | |
| 3346 | int alpha = 255; |
| 3347 | |
| 3348 | int curAlpha = 255; |
| 3349 | } |
| 3350 | |
Wale Ogunwale | 8804af2 | 2015-11-17 09:18:15 -0800 | [diff] [blame] | 3351 | static final class PanelFeatureState { |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3352 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3353 | /** Feature ID for this panel. */ |
| 3354 | int featureId; |
| 3355 | |
| 3356 | // Information pulled from the style for this panel. |
| 3357 | |
| 3358 | int background; |
| 3359 | |
| 3360 | /** The background when the panel spans the entire available width. */ |
| 3361 | int fullBackground; |
| 3362 | |
| 3363 | int gravity; |
| 3364 | |
| 3365 | int x; |
| 3366 | |
| 3367 | int y; |
| 3368 | |
| 3369 | int windowAnimations; |
| 3370 | |
| 3371 | /** Dynamic state of the panel. */ |
| 3372 | DecorView decorView; |
| 3373 | |
| 3374 | /** The panel that was returned by onCreatePanelView(). */ |
| 3375 | View createdPanelView; |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3376 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3377 | /** The panel that we are actually showing. */ |
| 3378 | View shownPanelView; |
| 3379 | |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3380 | /** Use {@link #setMenu} to set this. */ |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 3381 | MenuBuilder menu; |
| 3382 | |
| 3383 | IconMenuPresenter iconMenuPresenter; |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 3384 | ListMenuPresenter listMenuPresenter; |
| 3385 | |
| 3386 | /** true if this menu will show in single-list compact mode */ |
| 3387 | boolean isCompact; |
| 3388 | |
| 3389 | /** Theme resource ID for list elements of the panel menu */ |
| 3390 | int listPresenterTheme; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3391 | |
| 3392 | /** |
| 3393 | * Whether the panel has been prepared (see |
| 3394 | * {@link PhoneWindow#preparePanel}). |
| 3395 | */ |
| 3396 | boolean isPrepared; |
| 3397 | |
| 3398 | /** |
| 3399 | * Whether an item's action has been performed. This happens in obvious |
| 3400 | * scenarios (user clicks on menu item), but can also happen with |
| 3401 | * chording menu+(shortcut key). |
| 3402 | */ |
| 3403 | boolean isHandled; |
| 3404 | |
| 3405 | boolean isOpen; |
| 3406 | |
| 3407 | /** |
| 3408 | * True if the menu is in expanded mode, false if the menu is in icon |
| 3409 | * mode |
| 3410 | */ |
| 3411 | boolean isInExpandedMode; |
| 3412 | |
| 3413 | public boolean qwertyMode; |
| 3414 | |
| 3415 | boolean refreshDecorView; |
| 3416 | |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 3417 | boolean refreshMenuContent; |
Alan Viverette | eb1d379 | 2014-06-03 18:36:03 -0700 | [diff] [blame] | 3418 | |
Dianne Hackborn | d007144 | 2009-09-25 01:35:29 -0700 | [diff] [blame] | 3419 | boolean wasLastOpen; |
Alan Viverette | eb1d379 | 2014-06-03 18:36:03 -0700 | [diff] [blame] | 3420 | |
Dianne Hackborn | d007144 | 2009-09-25 01:35:29 -0700 | [diff] [blame] | 3421 | boolean wasLastExpanded; |
Alan Viverette | eb1d379 | 2014-06-03 18:36:03 -0700 | [diff] [blame] | 3422 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3423 | /** |
| 3424 | * Contains the state of the menu when told to freeze. |
| 3425 | */ |
| 3426 | Bundle frozenMenuState; |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3427 | |
Adam Powell | 038f1c8 | 2011-07-21 14:28:10 -0700 | [diff] [blame] | 3428 | /** |
| 3429 | * Contains the state of associated action views when told to freeze. |
| 3430 | * These are saved across invalidations. |
| 3431 | */ |
| 3432 | Bundle frozenActionViewState; |
| 3433 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3434 | PanelFeatureState(int featureId) { |
| 3435 | this.featureId = featureId; |
| 3436 | |
| 3437 | refreshDecorView = false; |
| 3438 | } |
| 3439 | |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 3440 | public boolean isInListMode() { |
| 3441 | return isInExpandedMode || isCompact; |
| 3442 | } |
| 3443 | |
Adam Powell | 526b931 | 2011-04-22 15:42:05 -0700 | [diff] [blame] | 3444 | public boolean hasPanelItems() { |
| 3445 | if (shownPanelView == null) return false; |
Adam Powell | 4fd8d533 | 2011-08-17 14:54:41 -0700 | [diff] [blame] | 3446 | if (createdPanelView != null) return true; |
Adam Powell | 526b931 | 2011-04-22 15:42:05 -0700 | [diff] [blame] | 3447 | |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 3448 | if (isCompact || isInExpandedMode) { |
| 3449 | return listMenuPresenter.getAdapter().getCount() > 0; |
Adam Powell | 526b931 | 2011-04-22 15:42:05 -0700 | [diff] [blame] | 3450 | } else { |
| 3451 | return ((ViewGroup) shownPanelView).getChildCount() > 0; |
| 3452 | } |
| 3453 | } |
| 3454 | |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 3455 | /** |
| 3456 | * Unregister and free attached MenuPresenters. They will be recreated as needed. |
| 3457 | */ |
| 3458 | public void clearMenuPresenters() { |
| 3459 | if (menu != null) { |
| 3460 | menu.removeMenuPresenter(iconMenuPresenter); |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 3461 | menu.removeMenuPresenter(listMenuPresenter); |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 3462 | } |
| 3463 | iconMenuPresenter = null; |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 3464 | listMenuPresenter = null; |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 3465 | } |
| 3466 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3467 | void setStyle(Context context) { |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 3468 | TypedArray a = context.obtainStyledAttributes(R.styleable.Theme); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3469 | background = a.getResourceId( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 3470 | R.styleable.Theme_panelBackground, 0); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3471 | fullBackground = a.getResourceId( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 3472 | R.styleable.Theme_panelFullBackground, 0); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3473 | windowAnimations = a.getResourceId( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 3474 | R.styleable.Theme_windowAnimationStyle, 0); |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 3475 | isCompact = a.getBoolean( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 3476 | R.styleable.Theme_panelMenuIsCompact, false); |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 3477 | listPresenterTheme = a.getResourceId( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 3478 | R.styleable.Theme_panelMenuListTheme, |
| 3479 | R.style.Theme_ExpandedMenu); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3480 | a.recycle(); |
| 3481 | } |
| 3482 | |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 3483 | void setMenu(MenuBuilder menu) { |
Adam Powell | 1d07e16 | 2011-09-07 20:46:24 -0700 | [diff] [blame] | 3484 | if (menu == this.menu) return; |
| 3485 | |
| 3486 | if (this.menu != null) { |
| 3487 | this.menu.removeMenuPresenter(iconMenuPresenter); |
| 3488 | this.menu.removeMenuPresenter(listMenuPresenter); |
| 3489 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3490 | this.menu = menu; |
Adam Powell | 1d07e16 | 2011-09-07 20:46:24 -0700 | [diff] [blame] | 3491 | if (menu != null) { |
| 3492 | if (iconMenuPresenter != null) menu.addMenuPresenter(iconMenuPresenter); |
| 3493 | if (listMenuPresenter != null) menu.addMenuPresenter(listMenuPresenter); |
| 3494 | } |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 3495 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3496 | |
Adam Powell | 538e565 | 2011-10-11 13:47:08 -0700 | [diff] [blame] | 3497 | MenuView getListMenuView(Context context, MenuPresenter.Callback cb) { |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 3498 | if (menu == null) return null; |
| 3499 | |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 3500 | if (!isCompact) { |
Adam Powell | 538e565 | 2011-10-11 13:47:08 -0700 | [diff] [blame] | 3501 | getIconMenuView(context, cb); // Need this initialized to know where our offset goes |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 3502 | } |
| 3503 | |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 3504 | if (listMenuPresenter == null) { |
| 3505 | listMenuPresenter = new ListMenuPresenter( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 3506 | R.layout.list_menu_item_layout, listPresenterTheme); |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 3507 | listMenuPresenter.setCallback(cb); |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 3508 | listMenuPresenter.setId(R.id.list_menu_presenter); |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 3509 | menu.addMenuPresenter(listMenuPresenter); |
| 3510 | } |
| 3511 | |
| 3512 | if (iconMenuPresenter != null) { |
| 3513 | listMenuPresenter.setItemIndexOffset( |
| 3514 | iconMenuPresenter.getNumActualItemsShown()); |
| 3515 | } |
| 3516 | MenuView result = listMenuPresenter.getMenuView(decorView); |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 3517 | |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 3518 | return result; |
| 3519 | } |
| 3520 | |
Adam Powell | 538e565 | 2011-10-11 13:47:08 -0700 | [diff] [blame] | 3521 | MenuView getIconMenuView(Context context, MenuPresenter.Callback cb) { |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 3522 | if (menu == null) return null; |
| 3523 | |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 3524 | if (iconMenuPresenter == null) { |
Adam Powell | 538e565 | 2011-10-11 13:47:08 -0700 | [diff] [blame] | 3525 | iconMenuPresenter = new IconMenuPresenter(context); |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 3526 | iconMenuPresenter.setCallback(cb); |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 3527 | iconMenuPresenter.setId(R.id.icon_menu_presenter); |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 3528 | menu.addMenuPresenter(iconMenuPresenter); |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 3529 | } |
| 3530 | |
| 3531 | MenuView result = iconMenuPresenter.getMenuView(decorView); |
| 3532 | |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 3533 | return result; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3534 | } |
| 3535 | |
| 3536 | Parcelable onSaveInstanceState() { |
| 3537 | SavedState savedState = new SavedState(); |
| 3538 | savedState.featureId = featureId; |
| 3539 | savedState.isOpen = isOpen; |
| 3540 | savedState.isInExpandedMode = isInExpandedMode; |
| 3541 | |
| 3542 | if (menu != null) { |
| 3543 | savedState.menuState = new Bundle(); |
Adam Powell | 11ed1d6 | 2011-07-11 21:19:59 -0700 | [diff] [blame] | 3544 | menu.savePresenterStates(savedState.menuState); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3545 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3546 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3547 | return savedState; |
| 3548 | } |
| 3549 | |
| 3550 | void onRestoreInstanceState(Parcelable state) { |
| 3551 | SavedState savedState = (SavedState) state; |
| 3552 | featureId = savedState.featureId; |
Dianne Hackborn | d007144 | 2009-09-25 01:35:29 -0700 | [diff] [blame] | 3553 | wasLastOpen = savedState.isOpen; |
| 3554 | wasLastExpanded = savedState.isInExpandedMode; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3555 | frozenMenuState = savedState.menuState; |
| 3556 | |
| 3557 | /* |
| 3558 | * A LocalActivityManager keeps the same instance of this class around. |
| 3559 | * The first time the menu is being shown after restoring, the |
| 3560 | * Activity.onCreateOptionsMenu should be called. But, if it is the |
| 3561 | * same instance then menu != null and we won't call that method. |
Adam Powell | 31bb97d | 2011-05-03 20:58:31 -0700 | [diff] [blame] | 3562 | * We clear any cached views here. The caller should invalidatePanelMenu. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3563 | */ |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3564 | createdPanelView = null; |
| 3565 | shownPanelView = null; |
| 3566 | decorView = null; |
| 3567 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3568 | |
Adam Powell | 11ed1d6 | 2011-07-11 21:19:59 -0700 | [diff] [blame] | 3569 | void applyFrozenState() { |
| 3570 | if (menu != null && frozenMenuState != null) { |
| 3571 | menu.restorePresenterStates(frozenMenuState); |
| 3572 | frozenMenuState = null; |
| 3573 | } |
| 3574 | } |
| 3575 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3576 | private static class SavedState implements Parcelable { |
| 3577 | int featureId; |
| 3578 | boolean isOpen; |
| 3579 | boolean isInExpandedMode; |
| 3580 | Bundle menuState; |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3581 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3582 | public int describeContents() { |
| 3583 | return 0; |
| 3584 | } |
| 3585 | |
| 3586 | public void writeToParcel(Parcel dest, int flags) { |
| 3587 | dest.writeInt(featureId); |
| 3588 | dest.writeInt(isOpen ? 1 : 0); |
| 3589 | dest.writeInt(isInExpandedMode ? 1 : 0); |
| 3590 | |
| 3591 | if (isOpen) { |
| 3592 | dest.writeBundle(menuState); |
| 3593 | } |
| 3594 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3595 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3596 | private static SavedState readFromParcel(Parcel source) { |
| 3597 | SavedState savedState = new SavedState(); |
| 3598 | savedState.featureId = source.readInt(); |
| 3599 | savedState.isOpen = source.readInt() == 1; |
| 3600 | savedState.isInExpandedMode = source.readInt() == 1; |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3601 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3602 | if (savedState.isOpen) { |
| 3603 | savedState.menuState = source.readBundle(); |
| 3604 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3605 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3606 | return savedState; |
| 3607 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3608 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3609 | public static final Parcelable.Creator<SavedState> CREATOR |
| 3610 | = new Parcelable.Creator<SavedState>() { |
| 3611 | public SavedState createFromParcel(Parcel in) { |
| 3612 | return readFromParcel(in); |
| 3613 | } |
| 3614 | |
| 3615 | public SavedState[] newArray(int size) { |
| 3616 | return new SavedState[size]; |
| 3617 | } |
| 3618 | }; |
| 3619 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3620 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3621 | } |
| 3622 | |
Adam Powell | 6711f3b | 2015-05-06 15:57:09 -0700 | [diff] [blame] | 3623 | static class RotationWatcher extends Stub { |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 3624 | private Handler mHandler; |
| 3625 | private final Runnable mRotationChanged = new Runnable() { |
| 3626 | public void run() { |
| 3627 | dispatchRotationChanged(); |
| 3628 | } |
| 3629 | }; |
| 3630 | private final ArrayList<WeakReference<PhoneWindow>> mWindows = |
| 3631 | new ArrayList<WeakReference<PhoneWindow>>(); |
| 3632 | private boolean mIsWatching; |
| 3633 | |
| 3634 | @Override |
| 3635 | public void onRotationChanged(int rotation) throws RemoteException { |
| 3636 | mHandler.post(mRotationChanged); |
| 3637 | } |
| 3638 | |
| 3639 | public void addWindow(PhoneWindow phoneWindow) { |
| 3640 | synchronized (mWindows) { |
| 3641 | if (!mIsWatching) { |
| 3642 | try { |
Andrii Kulian | 35fa3c2 | 2017-03-11 09:37:28 -0800 | [diff] [blame] | 3643 | WindowManagerHolder.sWindowManager.watchRotation(this, |
| 3644 | phoneWindow.getContext().getDisplay().getDisplayId()); |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 3645 | mHandler = new Handler(); |
| 3646 | mIsWatching = true; |
| 3647 | } catch (RemoteException ex) { |
| 3648 | Log.e(TAG, "Couldn't start watching for device rotation", ex); |
| 3649 | } |
| 3650 | } |
| 3651 | mWindows.add(new WeakReference<PhoneWindow>(phoneWindow)); |
| 3652 | } |
| 3653 | } |
| 3654 | |
| 3655 | public void removeWindow(PhoneWindow phoneWindow) { |
| 3656 | synchronized (mWindows) { |
| 3657 | int i = 0; |
| 3658 | while (i < mWindows.size()) { |
| 3659 | final WeakReference<PhoneWindow> ref = mWindows.get(i); |
| 3660 | final PhoneWindow win = ref.get(); |
| 3661 | if (win == null || win == phoneWindow) { |
| 3662 | mWindows.remove(i); |
| 3663 | } else { |
| 3664 | i++; |
| 3665 | } |
| 3666 | } |
| 3667 | } |
| 3668 | } |
| 3669 | |
| 3670 | void dispatchRotationChanged() { |
| 3671 | synchronized (mWindows) { |
| 3672 | int i = 0; |
| 3673 | while (i < mWindows.size()) { |
| 3674 | final WeakReference<PhoneWindow> ref = mWindows.get(i); |
| 3675 | final PhoneWindow win = ref.get(); |
| 3676 | if (win != null) { |
| 3677 | win.onOptionsPanelRotationChanged(); |
| 3678 | i++; |
| 3679 | } else { |
| 3680 | mWindows.remove(i); |
| 3681 | } |
| 3682 | } |
| 3683 | } |
| 3684 | } |
| 3685 | } |
| 3686 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3687 | /** |
| 3688 | * Simple implementation of MenuBuilder.Callback that: |
| 3689 | * <li> Opens a submenu when selected. |
| 3690 | * <li> Calls back to the callback's onMenuItemSelected when an item is |
| 3691 | * selected. |
| 3692 | */ |
Alan Viverette | 77fb85e | 2015-12-14 11:42:44 -0500 | [diff] [blame] | 3693 | public static final class PhoneWindowMenuCallback |
| 3694 | implements MenuBuilder.Callback, MenuPresenter.Callback { |
| 3695 | private static final int FEATURE_ID = FEATURE_CONTEXT_MENU; |
| 3696 | |
| 3697 | private final PhoneWindow mWindow; |
| 3698 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3699 | private MenuDialogHelper mSubMenuHelper; |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3700 | |
Alan Viverette | 77fb85e | 2015-12-14 11:42:44 -0500 | [diff] [blame] | 3701 | private boolean mShowDialogForSubmenu; |
| 3702 | |
| 3703 | public PhoneWindowMenuCallback(PhoneWindow window) { |
| 3704 | mWindow = window; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3705 | } |
| 3706 | |
Alan Viverette | 77fb85e | 2015-12-14 11:42:44 -0500 | [diff] [blame] | 3707 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3708 | public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) { |
Adam Powell | d1f4207 | 2011-05-03 17:20:14 -0700 | [diff] [blame] | 3709 | if (menu.getRootMenu() != menu) { |
| 3710 | onCloseSubMenu(menu); |
| 3711 | } |
| 3712 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3713 | if (allMenusAreClosing) { |
Alan Viverette | 77fb85e | 2015-12-14 11:42:44 -0500 | [diff] [blame] | 3714 | final Callback callback = mWindow.getCallback(); |
| 3715 | if (callback != null && !mWindow.isDestroyed()) { |
| 3716 | callback.onPanelClosed(FEATURE_ID, menu); |
Dianne Hackborn | b66ad57 | 2011-03-01 17:10:30 -0800 | [diff] [blame] | 3717 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3718 | |
Alan Viverette | 77fb85e | 2015-12-14 11:42:44 -0500 | [diff] [blame] | 3719 | if (menu == mWindow.mContextMenu) { |
| 3720 | mWindow.dismissContextMenu(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3721 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3722 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3723 | // Dismiss the submenu, if it is showing |
| 3724 | if (mSubMenuHelper != null) { |
| 3725 | mSubMenuHelper.dismiss(); |
| 3726 | mSubMenuHelper = null; |
| 3727 | } |
| 3728 | } |
| 3729 | } |
| 3730 | |
Alan Viverette | 77fb85e | 2015-12-14 11:42:44 -0500 | [diff] [blame] | 3731 | private void onCloseSubMenu(MenuBuilder menu) { |
| 3732 | final Callback callback = mWindow.getCallback(); |
| 3733 | if (callback != null && !mWindow.isDestroyed()) { |
| 3734 | callback.onPanelClosed(FEATURE_ID, menu.getRootMenu()); |
Dianne Hackborn | b66ad57 | 2011-03-01 17:10:30 -0800 | [diff] [blame] | 3735 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3736 | } |
| 3737 | |
Alan Viverette | 77fb85e | 2015-12-14 11:42:44 -0500 | [diff] [blame] | 3738 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3739 | public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) { |
Alan Viverette | 77fb85e | 2015-12-14 11:42:44 -0500 | [diff] [blame] | 3740 | final Callback callback = mWindow.getCallback(); |
| 3741 | return callback != null && !mWindow.isDestroyed() |
| 3742 | && callback.onMenuItemSelected(FEATURE_ID, item); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3743 | } |
| 3744 | |
Alan Viverette | 77fb85e | 2015-12-14 11:42:44 -0500 | [diff] [blame] | 3745 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3746 | public void onMenuModeChange(MenuBuilder menu) { |
| 3747 | } |
| 3748 | |
Alan Viverette | 77fb85e | 2015-12-14 11:42:44 -0500 | [diff] [blame] | 3749 | @Override |
Adam Powell | d1f4207 | 2011-05-03 17:20:14 -0700 | [diff] [blame] | 3750 | public boolean onOpenSubMenu(MenuBuilder subMenu) { |
Alan Viverette | 77fb85e | 2015-12-14 11:42:44 -0500 | [diff] [blame] | 3751 | if (subMenu == null) { |
| 3752 | return false; |
| 3753 | } |
Adam Powell | 823f074 | 2011-09-21 17:17:01 -0700 | [diff] [blame] | 3754 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3755 | // Set a simple callback for the submenu |
| 3756 | subMenu.setCallback(this); |
| 3757 | |
Alan Viverette | 77fb85e | 2015-12-14 11:42:44 -0500 | [diff] [blame] | 3758 | if (mShowDialogForSubmenu) { |
| 3759 | // The window manager will give us a valid window token |
| 3760 | mSubMenuHelper = new MenuDialogHelper(subMenu); |
| 3761 | mSubMenuHelper.show(null); |
| 3762 | return true; |
| 3763 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3764 | |
Alan Viverette | 77fb85e | 2015-12-14 11:42:44 -0500 | [diff] [blame] | 3765 | return false; |
| 3766 | } |
| 3767 | |
| 3768 | public void setShowDialogForSubmenu(boolean enabled) { |
| 3769 | mShowDialogForSubmenu = enabled; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3770 | } |
| 3771 | } |
| 3772 | |
Wale Ogunwale | 8804af2 | 2015-11-17 09:18:15 -0800 | [diff] [blame] | 3773 | int getLocalFeaturesPrivate() { |
| 3774 | return super.getLocalFeatures(); |
| 3775 | } |
Adrian Roos | 05054bd | 2014-10-27 17:04:10 +0100 | [diff] [blame] | 3776 | |
Wale Ogunwale | 8804af2 | 2015-11-17 09:18:15 -0800 | [diff] [blame] | 3777 | protected void setDefaultWindowFormat(int format) { |
| 3778 | super.setDefaultWindowFormat(format); |
Adrian Roos | 05054bd | 2014-10-27 17:04:10 +0100 | [diff] [blame] | 3779 | } |
| 3780 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3781 | void sendCloseSystemWindows() { |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 3782 | sendCloseSystemWindows(getContext(), null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3783 | } |
| 3784 | |
| 3785 | void sendCloseSystemWindows(String reason) { |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 3786 | sendCloseSystemWindows(getContext(), reason); |
| 3787 | } |
| 3788 | |
| 3789 | public static void sendCloseSystemWindows(Context context, String reason) { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3790 | if (ActivityManager.isSystemReady()) { |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 3791 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3792 | ActivityManager.getService().closeSystemDialogs(reason); |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 3793 | } catch (RemoteException e) { |
| 3794 | } |
| 3795 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3796 | } |
Adrian Roos | 217ccd2 | 2014-05-09 14:29:04 +0200 | [diff] [blame] | 3797 | |
| 3798 | @Override |
| 3799 | public int getStatusBarColor() { |
Adrian Roos | 34e6544 | 2014-05-17 02:35:33 +0200 | [diff] [blame] | 3800 | return mStatusBarColor; |
Adrian Roos | 217ccd2 | 2014-05-09 14:29:04 +0200 | [diff] [blame] | 3801 | } |
| 3802 | |
| 3803 | @Override |
| 3804 | public void setStatusBarColor(int color) { |
Adrian Roos | 34e6544 | 2014-05-17 02:35:33 +0200 | [diff] [blame] | 3805 | mStatusBarColor = color; |
| 3806 | mForcedStatusBarColor = true; |
| 3807 | if (mDecor != null) { |
Adrian Roos | 05054bd | 2014-10-27 17:04:10 +0100 | [diff] [blame] | 3808 | mDecor.updateColorViews(null, false /* animate */); |
Adrian Roos | 34e6544 | 2014-05-17 02:35:33 +0200 | [diff] [blame] | 3809 | } |
Adrian Roos | 217ccd2 | 2014-05-09 14:29:04 +0200 | [diff] [blame] | 3810 | } |
| 3811 | |
| 3812 | @Override |
| 3813 | public int getNavigationBarColor() { |
Adrian Roos | 34e6544 | 2014-05-17 02:35:33 +0200 | [diff] [blame] | 3814 | return mNavigationBarColor; |
Adrian Roos | 217ccd2 | 2014-05-09 14:29:04 +0200 | [diff] [blame] | 3815 | } |
| 3816 | |
| 3817 | @Override |
| 3818 | public void setNavigationBarColor(int color) { |
Adrian Roos | 34e6544 | 2014-05-17 02:35:33 +0200 | [diff] [blame] | 3819 | mNavigationBarColor = color; |
| 3820 | mForcedNavigationBarColor = true; |
| 3821 | if (mDecor != null) { |
Adrian Roos | 05054bd | 2014-10-27 17:04:10 +0100 | [diff] [blame] | 3822 | mDecor.updateColorViews(null, false /* animate */); |
Adrian Roos | 34e6544 | 2014-05-17 02:35:33 +0200 | [diff] [blame] | 3823 | } |
Adrian Roos | 217ccd2 | 2014-05-09 14:29:04 +0200 | [diff] [blame] | 3824 | } |
Jorim Jaggi | a16cc15 | 2015-06-01 16:55:05 -0700 | [diff] [blame] | 3825 | |
Jorim Jaggi | a0b78d5 | 2018-01-22 19:01:42 +0100 | [diff] [blame] | 3826 | @Override |
| 3827 | public void setNavigationBarDividerColor(int navigationBarDividerColor) { |
| 3828 | mNavigationBarDividerColor = navigationBarDividerColor; |
| 3829 | if (mDecor != null) { |
| 3830 | mDecor.updateColorViews(null, false /* animate */); |
| 3831 | } |
| 3832 | } |
| 3833 | |
| 3834 | @Override |
| 3835 | public int getNavigationBarDividerColor() { |
| 3836 | return mNavigationBarDividerColor; |
| 3837 | } |
| 3838 | |
Jorim Jaggi | a16cc15 | 2015-06-01 16:55:05 -0700 | [diff] [blame] | 3839 | public void setIsStartingWindow(boolean isStartingWindow) { |
| 3840 | mIsStartingWindow = isStartingWindow; |
| 3841 | } |
Stefan Kuhne | f4dd71a | 2015-08-07 09:28:52 -0700 | [diff] [blame] | 3842 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3843 | @Override |
Filip Gruszczynski | 0daf210 | 2015-09-29 08:39:07 -0700 | [diff] [blame] | 3844 | public void setTheme(int resid) { |
| 3845 | mTheme = resid; |
| 3846 | if (mDecor != null) { |
| 3847 | Context context = mDecor.getContext(); |
| 3848 | if (context instanceof DecorContext) { |
| 3849 | context.setTheme(resid); |
| 3850 | } |
| 3851 | } |
| 3852 | } |
Filip Gruszczynski | 3dec081 | 2015-12-09 08:42:41 -0800 | [diff] [blame] | 3853 | |
| 3854 | @Override |
| 3855 | public void setResizingCaptionDrawable(Drawable drawable) { |
| 3856 | mDecor.setUserCaptionBackgroundDrawable(drawable); |
| 3857 | } |
| 3858 | |
| 3859 | @Override |
| 3860 | public void setDecorCaptionShade(int decorCaptionShade) { |
| 3861 | mDecorCaptionShade = decorCaptionShade; |
| 3862 | if (mDecor != null) { |
| 3863 | mDecor.updateDecorCaptionShade(); |
| 3864 | } |
| 3865 | } |
| 3866 | |
| 3867 | int getDecorCaptionShade() { |
| 3868 | return mDecorCaptionShade; |
| 3869 | } |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3870 | |
| 3871 | @Override |
| 3872 | public void setAttributes(WindowManager.LayoutParams params) { |
| 3873 | super.setAttributes(params); |
| 3874 | if (mDecor != null) { |
| 3875 | mDecor.updateLogTag(params); |
| 3876 | } |
| 3877 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3878 | } |