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 | } |
Dianne Hackborn | a207baa | 2009-09-13 16:14:44 -0700 | [diff] [blame] | 2043 | if (event.isTracking() && !event.isCanceled()) { |
Tim Kilbourn | 6a975b3 | 2015-04-09 17:14:34 -0700 | [diff] [blame] | 2044 | launchDefaultSearch(event); |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 2045 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2046 | return true; |
| 2047 | } |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 2048 | |
| 2049 | case KeyEvent.KEYCODE_WINDOW: { |
Jaewan Kim | d98dcab | 2016-05-03 02:52:18 +0900 | [diff] [blame] | 2050 | if (mSupportsPictureInPicture && !event.isCanceled()) { |
| 2051 | getWindowControllerCallback().enterPictureInPictureModeIfPossible(); |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 2052 | } |
| 2053 | return true; |
| 2054 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2055 | } |
| 2056 | |
| 2057 | return false; |
| 2058 | } |
| 2059 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2060 | @Override |
| 2061 | protected void onActive() { |
| 2062 | } |
| 2063 | |
| 2064 | @Override |
| 2065 | public final View getDecorView() { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 2066 | if (mDecor == null || mForceDecorInstall) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2067 | installDecor(); |
| 2068 | } |
| 2069 | return mDecor; |
| 2070 | } |
| 2071 | |
| 2072 | @Override |
| 2073 | public final View peekDecorView() { |
| 2074 | return mDecor; |
| 2075 | } |
| 2076 | |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 2077 | /** Notify when decor view is attached to window and {@link ViewRootImpl} is available. */ |
| 2078 | void onViewRootImplSet(ViewRootImpl viewRoot) { |
| 2079 | viewRoot.setActivityConfigCallback(mActivityConfigCallback); |
| 2080 | } |
| 2081 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2082 | static private final String FOCUSED_ID_TAG = "android:focusedViewId"; |
| 2083 | static private final String VIEWS_TAG = "android:views"; |
| 2084 | static private final String PANELS_TAG = "android:Panels"; |
Adam Powell | 6c6f575 | 2010-08-20 18:34:46 -0700 | [diff] [blame] | 2085 | static private final String ACTION_BAR_TAG = "android:ActionBar"; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2086 | |
Alan Viverette | eae66cd | 2015-08-13 20:05:35 +0000 | [diff] [blame] | 2087 | /** {@inheritDoc} */ |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2088 | @Override |
| 2089 | public Bundle saveHierarchyState() { |
Alan Viverette | eae66cd | 2015-08-13 20:05:35 +0000 | [diff] [blame] | 2090 | Bundle outState = new Bundle(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2091 | if (mContentParent == null) { |
| 2092 | return outState; |
| 2093 | } |
| 2094 | |
Alan Viverette | eae66cd | 2015-08-13 20:05:35 +0000 | [diff] [blame] | 2095 | SparseArray<Parcelable> states = new SparseArray<Parcelable>(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2096 | mContentParent.saveHierarchyState(states); |
| 2097 | outState.putSparseParcelableArray(VIEWS_TAG, states); |
| 2098 | |
Alan Viverette | ec6cf18 | 2015-08-13 15:31:57 -0400 | [diff] [blame] | 2099 | // Save the focused view ID. |
| 2100 | final View focusedView = mContentParent.findFocus(); |
| 2101 | if (focusedView != null && focusedView.getId() != View.NO_ID) { |
| 2102 | outState.putInt(FOCUSED_ID_TAG, focusedView.getId()); |
| 2103 | } |
| 2104 | |
Alan Viverette | eae66cd | 2015-08-13 20:05:35 +0000 | [diff] [blame] | 2105 | // save the panels |
| 2106 | SparseArray<Parcelable> panelStates = new SparseArray<Parcelable>(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2107 | savePanelState(panelStates); |
| 2108 | if (panelStates.size() > 0) { |
| 2109 | outState.putSparseParcelableArray(PANELS_TAG, panelStates); |
| 2110 | } |
| 2111 | |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 2112 | if (mDecorContentParent != null) { |
Alan Viverette | eae66cd | 2015-08-13 20:05:35 +0000 | [diff] [blame] | 2113 | SparseArray<Parcelable> actionBarStates = new SparseArray<Parcelable>(); |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 2114 | mDecorContentParent.saveToolbarHierarchyState(actionBarStates); |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 2115 | outState.putSparseParcelableArray(ACTION_BAR_TAG, actionBarStates); |
Adam Powell | 6c6f575 | 2010-08-20 18:34:46 -0700 | [diff] [blame] | 2116 | } |
| 2117 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2118 | return outState; |
| 2119 | } |
| 2120 | |
Alan Viverette | eae66cd | 2015-08-13 20:05:35 +0000 | [diff] [blame] | 2121 | /** {@inheritDoc} */ |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2122 | @Override |
| 2123 | public void restoreHierarchyState(Bundle savedInstanceState) { |
| 2124 | if (mContentParent == null) { |
| 2125 | return; |
| 2126 | } |
| 2127 | |
Alan Viverette | eae66cd | 2015-08-13 20:05:35 +0000 | [diff] [blame] | 2128 | SparseArray<Parcelable> savedStates |
| 2129 | = savedInstanceState.getSparseParcelableArray(VIEWS_TAG); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2130 | if (savedStates != null) { |
| 2131 | mContentParent.restoreHierarchyState(savedStates); |
| 2132 | } |
| 2133 | |
Alan Viverette | eae66cd | 2015-08-13 20:05:35 +0000 | [diff] [blame] | 2134 | // restore the focused view |
| 2135 | 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] | 2136 | if (focusedViewId != View.NO_ID) { |
Alan Viverette | eae66cd | 2015-08-13 20:05:35 +0000 | [diff] [blame] | 2137 | View needsFocus = mContentParent.findViewById(focusedViewId); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2138 | if (needsFocus != null) { |
| 2139 | needsFocus.requestFocus(); |
| 2140 | } else { |
Alan Viverette | eae66cd | 2015-08-13 20:05:35 +0000 | [diff] [blame] | 2141 | Log.w(TAG, |
| 2142 | "Previously focused view reported id " + focusedViewId |
| 2143 | + " during save, but can't be found during restore."); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2144 | } |
| 2145 | } |
| 2146 | |
Alan Viverette | ec6cf18 | 2015-08-13 15:31:57 -0400 | [diff] [blame] | 2147 | // Restore the panels. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2148 | SparseArray<Parcelable> panelStates = savedInstanceState.getSparseParcelableArray(PANELS_TAG); |
| 2149 | if (panelStates != null) { |
| 2150 | restorePanelState(panelStates); |
| 2151 | } |
Adam Powell | 6c6f575 | 2010-08-20 18:34:46 -0700 | [diff] [blame] | 2152 | |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 2153 | if (mDecorContentParent != null) { |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 2154 | SparseArray<Parcelable> actionBarStates = |
| 2155 | savedInstanceState.getSparseParcelableArray(ACTION_BAR_TAG); |
Adam Powell | fb5f1bc | 2012-05-17 19:30:35 -0700 | [diff] [blame] | 2156 | if (actionBarStates != null) { |
Adam Powell | 31c91c8 | 2014-08-22 17:20:00 -0700 | [diff] [blame] | 2157 | doPendingInvalidatePanelMenu(); |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 2158 | mDecorContentParent.restoreToolbarHierarchyState(actionBarStates); |
Adam Powell | fb5f1bc | 2012-05-17 19:30:35 -0700 | [diff] [blame] | 2159 | } else { |
| 2160 | Log.w(TAG, "Missing saved instance states for action bar views! " + |
| 2161 | "State will not be restored."); |
| 2162 | } |
Adam Powell | 6c6f575 | 2010-08-20 18:34:46 -0700 | [diff] [blame] | 2163 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2164 | } |
| 2165 | |
| 2166 | /** |
| 2167 | * Invoked when the panels should freeze their state. |
| 2168 | * |
| 2169 | * @param icicles Save state into this. This is usually indexed by the |
| 2170 | * featureId. This will be given to {@link #restorePanelState} in the |
| 2171 | * future. |
| 2172 | */ |
| 2173 | private void savePanelState(SparseArray<Parcelable> icicles) { |
| 2174 | PanelFeatureState[] panels = mPanels; |
| 2175 | if (panels == null) { |
| 2176 | return; |
| 2177 | } |
| 2178 | |
| 2179 | for (int curFeatureId = panels.length - 1; curFeatureId >= 0; curFeatureId--) { |
| 2180 | if (panels[curFeatureId] != null) { |
| 2181 | icicles.put(curFeatureId, panels[curFeatureId].onSaveInstanceState()); |
| 2182 | } |
| 2183 | } |
| 2184 | } |
| 2185 | |
| 2186 | /** |
| 2187 | * Invoked when the panels should thaw their state from a previously frozen state. |
| 2188 | * |
| 2189 | * @param icicles The state saved by {@link #savePanelState} that needs to be thawed. |
| 2190 | */ |
| 2191 | private void restorePanelState(SparseArray<Parcelable> icicles) { |
| 2192 | PanelFeatureState st; |
Dmitry Tsyganyuk | 554bb01 | 2012-04-02 13:10:52 -0500 | [diff] [blame] | 2193 | int curFeatureId; |
| 2194 | for (int i = icicles.size() - 1; i >= 0; i--) { |
| 2195 | curFeatureId = icicles.keyAt(i); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2196 | st = getPanelState(curFeatureId, false /* required */); |
| 2197 | if (st == null) { |
| 2198 | // The panel must not have been required, and is currently not around, skip it |
| 2199 | continue; |
| 2200 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 2201 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2202 | st.onRestoreInstanceState(icicles.get(curFeatureId)); |
Adam Powell | 31bb97d | 2011-05-03 20:58:31 -0700 | [diff] [blame] | 2203 | invalidatePanelMenu(curFeatureId); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2204 | } |
| 2205 | |
| 2206 | /* |
| 2207 | * Implementation note: call openPanelsAfterRestore later to actually open the |
| 2208 | * restored panels. |
| 2209 | */ |
| 2210 | } |
| 2211 | |
| 2212 | /** |
| 2213 | * Opens the panels that have had their state restored. This should be |
| 2214 | * called sometime after {@link #restorePanelState} when it is safe to add |
| 2215 | * to the window manager. |
| 2216 | */ |
Wale Ogunwale | 8804af2 | 2015-11-17 09:18:15 -0800 | [diff] [blame] | 2217 | void openPanelsAfterRestore() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2218 | PanelFeatureState[] panels = mPanels; |
| 2219 | |
| 2220 | if (panels == null) { |
| 2221 | return; |
| 2222 | } |
| 2223 | |
| 2224 | PanelFeatureState st; |
| 2225 | for (int i = panels.length - 1; i >= 0; i--) { |
| 2226 | st = panels[i]; |
Dianne Hackborn | d007144 | 2009-09-25 01:35:29 -0700 | [diff] [blame] | 2227 | // We restore the panel if it was last open; we skip it if it |
| 2228 | // now is open, to avoid a race condition if the user immediately |
| 2229 | // opens it when we are resuming. |
Adam Powell | 11ed1d6 | 2011-07-11 21:19:59 -0700 | [diff] [blame] | 2230 | if (st != null) { |
| 2231 | st.applyFrozenState(); |
| 2232 | if (!st.isOpen && st.wasLastOpen) { |
| 2233 | st.isInExpandedMode = st.wasLastExpanded; |
| 2234 | openPanel(st, null); |
| 2235 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2236 | } |
| 2237 | } |
| 2238 | } |
| 2239 | |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 2240 | private class PanelMenuPresenterCallback implements MenuPresenter.Callback { |
| 2241 | @Override |
| 2242 | public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) { |
| 2243 | final Menu parentMenu = menu.getRootMenu(); |
| 2244 | final boolean isSubMenu = parentMenu != menu; |
| 2245 | final PanelFeatureState panel = findMenuPanel(isSubMenu ? parentMenu : menu); |
| 2246 | if (panel != null) { |
| 2247 | if (isSubMenu) { |
| 2248 | callOnPanelClosed(panel.featureId, panel, parentMenu); |
| 2249 | closePanel(panel, true); |
| 2250 | } else { |
| 2251 | // Close the panel and only do the callback if the menu is being |
| 2252 | // closed completely, not if opening a sub menu |
| 2253 | closePanel(panel, allMenusAreClosing); |
| 2254 | } |
| 2255 | } |
| 2256 | } |
| 2257 | |
| 2258 | @Override |
| 2259 | public boolean onOpenSubMenu(MenuBuilder subMenu) { |
| 2260 | if (subMenu == null && hasFeature(FEATURE_ACTION_BAR)) { |
| 2261 | Callback cb = getCallback(); |
| 2262 | if (cb != null && !isDestroyed()) { |
| 2263 | cb.onMenuOpened(FEATURE_ACTION_BAR, subMenu); |
| 2264 | } |
| 2265 | } |
| 2266 | |
| 2267 | return true; |
| 2268 | } |
| 2269 | } |
| 2270 | |
| 2271 | private final class ActionMenuPresenterCallback implements MenuPresenter.Callback { |
| 2272 | @Override |
| 2273 | public boolean onOpenSubMenu(MenuBuilder subMenu) { |
| 2274 | Callback cb = getCallback(); |
| 2275 | if (cb != null) { |
| 2276 | cb.onMenuOpened(FEATURE_ACTION_BAR, subMenu); |
| 2277 | return true; |
| 2278 | } |
| 2279 | return false; |
| 2280 | } |
| 2281 | |
| 2282 | @Override |
| 2283 | public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) { |
| 2284 | checkCloseActionMenu(menu); |
| 2285 | } |
| 2286 | } |
| 2287 | |
Stefan Kuhne | 61b47bb | 2015-07-28 14:04:25 -0700 | [diff] [blame] | 2288 | protected DecorView generateDecor(int featureId) { |
Filip Gruszczynski | 0daf210 | 2015-09-29 08:39:07 -0700 | [diff] [blame] | 2289 | // System process doesn't have application context and in that case we need to directly use |
| 2290 | // the context we have. Otherwise we want the application context, so we don't cling to the |
| 2291 | // activity. |
Filip Gruszczynski | 0daf210 | 2015-09-29 08:39:07 -0700 | [diff] [blame] | 2292 | Context context; |
Filip Gruszczynski | 796b8c1 | 2015-12-22 14:46:21 -0800 | [diff] [blame] | 2293 | if (mUseDecorContext) { |
| 2294 | Context applicationContext = getContext().getApplicationContext(); |
| 2295 | if (applicationContext == null) { |
| 2296 | context = getContext(); |
| 2297 | } else { |
Adam Lesinski | ff22a56 | 2016-04-18 12:14:12 -0700 | [diff] [blame] | 2298 | context = new DecorContext(applicationContext, getContext().getResources()); |
Filip Gruszczynski | 796b8c1 | 2015-12-22 14:46:21 -0800 | [diff] [blame] | 2299 | if (mTheme != -1) { |
| 2300 | context.setTheme(mTheme); |
| 2301 | } |
Filip Gruszczynski | 0daf210 | 2015-09-29 08:39:07 -0700 | [diff] [blame] | 2302 | } |
Filip Gruszczynski | 796b8c1 | 2015-12-22 14:46:21 -0800 | [diff] [blame] | 2303 | } else { |
| 2304 | context = getContext(); |
Filip Gruszczynski | 0daf210 | 2015-09-29 08:39:07 -0700 | [diff] [blame] | 2305 | } |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2306 | return new DecorView(context, featureId, this, getAttributes()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2307 | } |
| 2308 | |
| 2309 | protected ViewGroup generateLayout(DecorView decor) { |
| 2310 | // Apply data from current theme. |
| 2311 | |
| 2312 | TypedArray a = getWindowStyle(); |
| 2313 | |
| 2314 | if (false) { |
| 2315 | System.out.println("From style:"); |
| 2316 | String s = "Attrs:"; |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2317 | for (int i = 0; i < R.styleable.Window.length; i++) { |
| 2318 | s = s + " " + Integer.toHexString(R.styleable.Window[i]) + "=" |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2319 | + a.getString(i); |
| 2320 | } |
| 2321 | System.out.println(s); |
| 2322 | } |
| 2323 | |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2324 | mIsFloating = a.getBoolean(R.styleable.Window_windowIsFloating, false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2325 | int flagsToUpdate = (FLAG_LAYOUT_IN_SCREEN|FLAG_LAYOUT_INSET_DECOR) |
| 2326 | & (~getForcedWindowFlags()); |
| 2327 | if (mIsFloating) { |
| 2328 | setLayout(WRAP_CONTENT, WRAP_CONTENT); |
| 2329 | setFlags(0, flagsToUpdate); |
| 2330 | } else { |
| 2331 | setFlags(FLAG_LAYOUT_IN_SCREEN|FLAG_LAYOUT_INSET_DECOR, flagsToUpdate); |
| 2332 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 2333 | |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2334 | if (a.getBoolean(R.styleable.Window_windowNoTitle, false)) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2335 | requestFeature(FEATURE_NO_TITLE); |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2336 | } else if (a.getBoolean(R.styleable.Window_windowActionBar, false)) { |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 2337 | // Don't allow an action bar if there is no title. |
| 2338 | requestFeature(FEATURE_ACTION_BAR); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2339 | } |
| 2340 | |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2341 | if (a.getBoolean(R.styleable.Window_windowActionBarOverlay, false)) { |
Adam Powell | 6b336f8 | 2010-08-10 20:13:01 -0700 | [diff] [blame] | 2342 | requestFeature(FEATURE_ACTION_BAR_OVERLAY); |
| 2343 | } |
| 2344 | |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2345 | if (a.getBoolean(R.styleable.Window_windowActionModeOverlay, false)) { |
Adam Powell | 5d27977 | 2010-07-27 16:34:07 -0700 | [diff] [blame] | 2346 | requestFeature(FEATURE_ACTION_MODE_OVERLAY); |
| 2347 | } |
| 2348 | |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2349 | if (a.getBoolean(R.styleable.Window_windowSwipeToDismiss, false)) { |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 2350 | requestFeature(FEATURE_SWIPE_TO_DISMISS); |
| 2351 | } |
| 2352 | |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2353 | if (a.getBoolean(R.styleable.Window_windowFullscreen, false)) { |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2354 | setFlags(FLAG_FULLSCREEN, FLAG_FULLSCREEN & (~getForcedWindowFlags())); |
| 2355 | } |
| 2356 | |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2357 | if (a.getBoolean(R.styleable.Window_windowTranslucentStatus, |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 2358 | false)) { |
| 2359 | setFlags(FLAG_TRANSLUCENT_STATUS, FLAG_TRANSLUCENT_STATUS |
| 2360 | & (~getForcedWindowFlags())); |
| 2361 | } |
| 2362 | |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2363 | if (a.getBoolean(R.styleable.Window_windowTranslucentNavigation, |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 2364 | false)) { |
| 2365 | setFlags(FLAG_TRANSLUCENT_NAVIGATION, FLAG_TRANSLUCENT_NAVIGATION |
| 2366 | & (~getForcedWindowFlags())); |
| 2367 | } |
| 2368 | |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2369 | if (a.getBoolean(R.styleable.Window_windowOverscan, false)) { |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2370 | 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] | 2371 | } |
| 2372 | |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2373 | if (a.getBoolean(R.styleable.Window_windowShowWallpaper, false)) { |
Dianne Hackborn | 4bf7bcf | 2009-08-09 17:23:00 -0700 | [diff] [blame] | 2374 | setFlags(FLAG_SHOW_WALLPAPER, FLAG_SHOW_WALLPAPER&(~getForcedWindowFlags())); |
| 2375 | } |
| 2376 | |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2377 | if (a.getBoolean(R.styleable.Window_windowEnableSplitTouch, |
Jeff Brown | 46e7529 | 2010-11-10 16:53:45 -0800 | [diff] [blame] | 2378 | getContext().getApplicationInfo().targetSdkVersion |
| 2379 | >= android.os.Build.VERSION_CODES.HONEYCOMB)) { |
| 2380 | setFlags(FLAG_SPLIT_TOUCH, FLAG_SPLIT_TOUCH&(~getForcedWindowFlags())); |
| 2381 | } |
| 2382 | |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2383 | a.getValue(R.styleable.Window_windowMinWidthMajor, mMinWidthMajor); |
| 2384 | a.getValue(R.styleable.Window_windowMinWidthMinor, mMinWidthMinor); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2385 | if (DEBUG) Log.d(TAG, "Min width minor: " + mMinWidthMinor.coerceToString() |
| 2386 | + ", major: " + mMinWidthMajor.coerceToString()); |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2387 | if (a.hasValue(R.styleable.Window_windowFixedWidthMajor)) { |
Adam Powell | 40eec4c | 2012-02-15 17:10:58 -0800 | [diff] [blame] | 2388 | if (mFixedWidthMajor == null) mFixedWidthMajor = new TypedValue(); |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2389 | a.getValue(R.styleable.Window_windowFixedWidthMajor, |
Adam Powell | 40eec4c | 2012-02-15 17:10:58 -0800 | [diff] [blame] | 2390 | mFixedWidthMajor); |
| 2391 | } |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2392 | if (a.hasValue(R.styleable.Window_windowFixedWidthMinor)) { |
Adam Powell | 40eec4c | 2012-02-15 17:10:58 -0800 | [diff] [blame] | 2393 | if (mFixedWidthMinor == null) mFixedWidthMinor = new TypedValue(); |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2394 | a.getValue(R.styleable.Window_windowFixedWidthMinor, |
Adam Powell | 40eec4c | 2012-02-15 17:10:58 -0800 | [diff] [blame] | 2395 | mFixedWidthMinor); |
| 2396 | } |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2397 | if (a.hasValue(R.styleable.Window_windowFixedHeightMajor)) { |
Adam Powell | 40eec4c | 2012-02-15 17:10:58 -0800 | [diff] [blame] | 2398 | if (mFixedHeightMajor == null) mFixedHeightMajor = new TypedValue(); |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2399 | a.getValue(R.styleable.Window_windowFixedHeightMajor, |
Adam Powell | 40eec4c | 2012-02-15 17:10:58 -0800 | [diff] [blame] | 2400 | mFixedHeightMajor); |
| 2401 | } |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2402 | if (a.hasValue(R.styleable.Window_windowFixedHeightMinor)) { |
Adam Powell | 40eec4c | 2012-02-15 17:10:58 -0800 | [diff] [blame] | 2403 | if (mFixedHeightMinor == null) mFixedHeightMinor = new TypedValue(); |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2404 | a.getValue(R.styleable.Window_windowFixedHeightMinor, |
Adam Powell | 40eec4c | 2012-02-15 17:10:58 -0800 | [diff] [blame] | 2405 | mFixedHeightMinor); |
| 2406 | } |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2407 | if (a.getBoolean(R.styleable.Window_windowContentTransitions, false)) { |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 2408 | requestFeature(FEATURE_CONTENT_TRANSITIONS); |
Michael Kolb | 4bb047f | 2014-04-01 14:38:57 -0700 | [diff] [blame] | 2409 | } |
George Mount | 9826f63 | 2014-09-11 08:50:09 -0700 | [diff] [blame] | 2410 | if (a.getBoolean(R.styleable.Window_windowActivityTransitions, false)) { |
| 2411 | requestFeature(FEATURE_ACTIVITY_TRANSITIONS); |
| 2412 | } |
Filip Gruszczynski | b57503c | 2014-07-16 16:35:18 -0700 | [diff] [blame] | 2413 | |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 2414 | mIsTranslucent = a.getBoolean(R.styleable.Window_windowIsTranslucent, false); |
| 2415 | |
Adam Powell | 82349c5 | 2011-08-23 13:53:56 -0700 | [diff] [blame] | 2416 | final Context context = getContext(); |
| 2417 | final int targetSdk = context.getApplicationInfo().targetSdkVersion; |
| 2418 | final boolean targetPreHoneycomb = targetSdk < android.os.Build.VERSION_CODES.HONEYCOMB; |
| 2419 | final boolean targetPreIcs = targetSdk < android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH; |
Dianne Hackborn | 955d8d6 | 2014-10-07 20:17:19 -0700 | [diff] [blame] | 2420 | final boolean targetPreL = targetSdk < android.os.Build.VERSION_CODES.LOLLIPOP; |
Adam Powell | 82349c5 | 2011-08-23 13:53:56 -0700 | [diff] [blame] | 2421 | final boolean targetHcNeedsOptions = context.getResources().getBoolean( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2422 | R.bool.target_honeycomb_needs_options_menu); |
Adam Powell | 82349c5 | 2011-08-23 13:53:56 -0700 | [diff] [blame] | 2423 | final boolean noActionBar = !hasFeature(FEATURE_ACTION_BAR) || hasFeature(FEATURE_NO_TITLE); |
| 2424 | |
| 2425 | if (targetPreHoneycomb || (targetPreIcs && targetHcNeedsOptions && noActionBar)) { |
Wale Ogunwale | 393b1c1 | 2014-10-18 16:22:01 -0700 | [diff] [blame] | 2426 | setNeedsMenuKey(WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE); |
Dianne Hackborn | 73ab6a4 | 2011-12-13 11:16:23 -0800 | [diff] [blame] | 2427 | } else { |
Wale Ogunwale | 393b1c1 | 2014-10-18 16:22:01 -0700 | [diff] [blame] | 2428 | setNeedsMenuKey(WindowManager.LayoutParams.NEEDS_MENU_SET_FALSE); |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 2429 | } |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2430 | |
Jorim Jaggi | 6e0ce28 | 2015-12-01 15:19:49 -0800 | [diff] [blame] | 2431 | if (!mForcedStatusBarColor) { |
| 2432 | mStatusBarColor = a.getColor(R.styleable.Window_statusBarColor, 0xFF000000); |
| 2433 | } |
| 2434 | if (!mForcedNavigationBarColor) { |
| 2435 | mNavigationBarColor = a.getColor(R.styleable.Window_navigationBarColor, 0xFF000000); |
Jason Monk | a750e99 | 2017-09-01 12:40:06 -0400 | [diff] [blame^] | 2436 | mNavigationBarDividerColor = a.getColor(R.styleable.Window_navigationBarDividerColor, |
| 2437 | 0x00000000); |
Jorim Jaggi | 6e0ce28 | 2015-12-01 15:19:49 -0800 | [diff] [blame] | 2438 | } |
| 2439 | |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 2440 | WindowManager.LayoutParams params = getAttributes(); |
| 2441 | |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2442 | // Non-floating windows on high end devices must put up decor beneath the system bars and |
| 2443 | // therefore must know about visibility changes of those. |
Matthew Ng | e6b393b | 2017-09-01 12:45:04 -0700 | [diff] [blame] | 2444 | if (!mIsFloating) { |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2445 | if (!targetPreL && a.getBoolean( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2446 | R.styleable.Window_windowDrawsSystemBarBackgrounds, |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2447 | false)) { |
| 2448 | setFlags(FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS, |
| 2449 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS & ~getForcedWindowFlags()); |
| 2450 | } |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 2451 | if (mDecor.mForceWindowDrawsStatusBarBackground) { |
| 2452 | params.privateFlags |= PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND; |
| 2453 | } |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2454 | } |
Adrian Roos | f4f84c9 | 2015-04-28 13:44:43 -0700 | [diff] [blame] | 2455 | if (a.getBoolean(R.styleable.Window_windowLightStatusBar, false)) { |
Adrian Roos | 75fa385 | 2015-01-27 20:21:44 +0100 | [diff] [blame] | 2456 | decor.setSystemUiVisibility( |
| 2457 | decor.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); |
| 2458 | } |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2459 | |
Dianne Hackborn | cfaf887 | 2011-01-18 13:57:54 -0800 | [diff] [blame] | 2460 | if (mAlwaysReadCloseOnTouchAttr || getContext().getApplicationInfo().targetSdkVersion |
| 2461 | >= android.os.Build.VERSION_CODES.HONEYCOMB) { |
Dianne Hackborn | ef57575 | 2011-01-18 17:35:17 -0800 | [diff] [blame] | 2462 | if (a.getBoolean( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2463 | R.styleable.Window_windowCloseOnTouchOutside, |
Dianne Hackborn | ef57575 | 2011-01-18 17:35:17 -0800 | [diff] [blame] | 2464 | false)) { |
| 2465 | setCloseOnTouchOutsideIfNotSet(true); |
Dianne Hackborn | cfaf887 | 2011-01-18 13:57:54 -0800 | [diff] [blame] | 2466 | } |
| 2467 | } |
Alan Viverette | eb1d379 | 2014-06-03 18:36:03 -0700 | [diff] [blame] | 2468 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2469 | if (!hasSoftInputMode()) { |
| 2470 | params.softInputMode = a.getInt( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2471 | R.styleable.Window_windowSoftInputMode, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2472 | params.softInputMode); |
| 2473 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 2474 | |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2475 | if (a.getBoolean(R.styleable.Window_backgroundDimEnabled, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2476 | mIsFloating)) { |
| 2477 | /* All dialogs should have the window dimmed */ |
| 2478 | if ((getForcedWindowFlags()&WindowManager.LayoutParams.FLAG_DIM_BEHIND) == 0) { |
| 2479 | params.flags |= WindowManager.LayoutParams.FLAG_DIM_BEHIND; |
| 2480 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2481 | if (!haveDimAmount()) { |
| 2482 | params.dimAmount = a.getFloat( |
| 2483 | android.R.styleable.Window_backgroundDimAmount, 0.5f); |
| 2484 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2485 | } |
| 2486 | |
| 2487 | if (params.windowAnimations == 0) { |
| 2488 | params.windowAnimations = a.getResourceId( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2489 | R.styleable.Window_windowAnimationStyle, 0); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2490 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 2491 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2492 | // The rest are only done if this window is not embedded; otherwise, |
| 2493 | // the values are inherited from our container. |
| 2494 | if (getContainer() == null) { |
| 2495 | if (mBackgroundDrawable == null) { |
| 2496 | if (mBackgroundResource == 0) { |
| 2497 | mBackgroundResource = a.getResourceId( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2498 | R.styleable.Window_windowBackground, 0); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2499 | } |
| 2500 | if (mFrameResource == 0) { |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2501 | mFrameResource = a.getResourceId(R.styleable.Window_windowFrame, 0); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2502 | } |
Adam Powell | f849a5e | 2014-09-11 15:09:36 -0700 | [diff] [blame] | 2503 | mBackgroundFallbackResource = a.getResourceId( |
| 2504 | R.styleable.Window_windowBackgroundFallback, 0); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2505 | if (false) { |
| 2506 | System.out.println("Background: " |
| 2507 | + Integer.toHexString(mBackgroundResource) + " Frame: " |
| 2508 | + Integer.toHexString(mFrameResource)); |
| 2509 | } |
| 2510 | } |
Wale Ogunwale | 0d7e912 | 2015-11-17 10:45:06 -0800 | [diff] [blame] | 2511 | if (mLoadElevation) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 2512 | mElevation = a.getDimension(R.styleable.Window_windowElevation, 0); |
| 2513 | } |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2514 | mClipToOutline = a.getBoolean(R.styleable.Window_windowClipToOutline, false); |
| 2515 | mTextColor = a.getColor(R.styleable.Window_textColor, Color.TRANSPARENT); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2516 | } |
| 2517 | |
| 2518 | // Inflate the window decor. |
| 2519 | |
| 2520 | int layoutResource; |
| 2521 | int features = getLocalFeatures(); |
| 2522 | // System.out.println("Features: 0x" + Integer.toHexString(features)); |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 2523 | if ((features & (1 << FEATURE_SWIPE_TO_DISMISS)) != 0) { |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2524 | layoutResource = R.layout.screen_swipe_dismiss; |
Michael Kwan | f7964be | 2016-11-30 16:44:33 -0800 | [diff] [blame] | 2525 | setCloseOnSwipeEnabled(true); |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 2526 | } 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] | 2527 | if (mIsFloating) { |
Adam Powell | 32aa2c9 | 2011-01-11 15:37:04 -0800 | [diff] [blame] | 2528 | TypedValue res = new TypedValue(); |
| 2529 | getContext().getTheme().resolveAttribute( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2530 | R.attr.dialogTitleIconsDecorLayout, res, true); |
Adam Powell | 32aa2c9 | 2011-01-11 15:37:04 -0800 | [diff] [blame] | 2531 | layoutResource = res.resourceId; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2532 | } else { |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2533 | layoutResource = R.layout.screen_title_icons; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2534 | } |
Adam Powell | f4a6ec4 | 2010-08-24 14:18:10 -0700 | [diff] [blame] | 2535 | // XXX Remove this once action bar supports these features. |
| 2536 | removeFeature(FEATURE_ACTION_BAR); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2537 | // System.out.println("Title Icons!"); |
Adam Powell | 6af97e1 | 2010-11-11 21:11:53 -0800 | [diff] [blame] | 2538 | } else if ((features & ((1 << FEATURE_PROGRESS) | (1 << FEATURE_INDETERMINATE_PROGRESS))) != 0 |
| 2539 | && (features & (1 << FEATURE_ACTION_BAR)) == 0) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2540 | // Special case for a window with only a progress bar (and title). |
| 2541 | // XXX Need to have a no-title version of embedded windows. |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2542 | layoutResource = R.layout.screen_progress; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2543 | // System.out.println("Progress!"); |
| 2544 | } else if ((features & (1 << FEATURE_CUSTOM_TITLE)) != 0) { |
| 2545 | // Special case for a window with a custom title. |
| 2546 | // If the window is floating, we need a dialog layout |
| 2547 | if (mIsFloating) { |
Adam Powell | 32aa2c9 | 2011-01-11 15:37:04 -0800 | [diff] [blame] | 2548 | TypedValue res = new TypedValue(); |
| 2549 | getContext().getTheme().resolveAttribute( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2550 | R.attr.dialogCustomTitleDecorLayout, res, true); |
Adam Powell | 32aa2c9 | 2011-01-11 15:37:04 -0800 | [diff] [blame] | 2551 | layoutResource = res.resourceId; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2552 | } else { |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2553 | layoutResource = R.layout.screen_custom_title; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2554 | } |
Adam Powell | f4a6ec4 | 2010-08-24 14:18:10 -0700 | [diff] [blame] | 2555 | // XXX Remove this once action bar supports these features. |
| 2556 | removeFeature(FEATURE_ACTION_BAR); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2557 | } else if ((features & (1 << FEATURE_NO_TITLE)) == 0) { |
| 2558 | // If no other features and not embedded, only need a title. |
| 2559 | // If the window is floating, we need a dialog layout |
| 2560 | if (mIsFloating) { |
Adam Powell | 32aa2c9 | 2011-01-11 15:37:04 -0800 | [diff] [blame] | 2561 | TypedValue res = new TypedValue(); |
| 2562 | getContext().getTheme().resolveAttribute( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2563 | R.attr.dialogTitleDecorLayout, res, true); |
Adam Powell | 32aa2c9 | 2011-01-11 15:37:04 -0800 | [diff] [blame] | 2564 | layoutResource = res.resourceId; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 2565 | } else if ((features & (1 << FEATURE_ACTION_BAR)) != 0) { |
Adam Powell | e021e6e | 2014-05-23 17:27:24 -0700 | [diff] [blame] | 2566 | layoutResource = a.getResourceId( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2567 | R.styleable.Window_windowActionBarFullscreenDecorLayout, |
| 2568 | R.layout.screen_action_bar); |
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_title; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2571 | } |
| 2572 | // System.out.println("Title!"); |
Adam Powell | f8419a0 | 2011-10-03 12:08:54 -0700 | [diff] [blame] | 2573 | } else if ((features & (1 << FEATURE_ACTION_MODE_OVERLAY)) != 0) { |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2574 | layoutResource = R.layout.screen_simple_overlay_action_mode; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2575 | } else { |
| 2576 | // Embedded, so no decoration is needed. |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2577 | layoutResource = R.layout.screen_simple; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2578 | // System.out.println("Simple!"); |
| 2579 | } |
| 2580 | |
| 2581 | mDecor.startChanging(); |
Filip Gruszczynski | 3dec081 | 2015-12-09 08:42:41 -0800 | [diff] [blame] | 2582 | mDecor.onResourcesLoaded(mLayoutInflater, layoutResource); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2583 | |
| 2584 | ViewGroup contentParent = (ViewGroup)findViewById(ID_ANDROID_CONTENT); |
| 2585 | if (contentParent == null) { |
| 2586 | throw new RuntimeException("Window couldn't find content container view"); |
| 2587 | } |
| 2588 | |
| 2589 | if ((features & (1 << FEATURE_INDETERMINATE_PROGRESS)) != 0) { |
| 2590 | ProgressBar progress = getCircularProgressBar(false); |
| 2591 | if (progress != null) { |
| 2592 | progress.setIndeterminate(true); |
| 2593 | } |
| 2594 | } |
| 2595 | |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 2596 | if ((features & (1 << FEATURE_SWIPE_TO_DISMISS)) != 0) { |
Michael Kwan | f7964be | 2016-11-30 16:44:33 -0800 | [diff] [blame] | 2597 | registerSwipeCallbacks(contentParent); |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 2598 | } |
| 2599 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2600 | // Remaining setup -- of background and title -- that only applies |
| 2601 | // to top-level windows. |
| 2602 | if (getContainer() == null) { |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 2603 | final Drawable background; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2604 | if (mBackgroundResource != 0) { |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 2605 | background = getContext().getDrawable(mBackgroundResource); |
| 2606 | } else { |
| 2607 | background = mBackgroundDrawable; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2608 | } |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 2609 | mDecor.setWindowBackground(background); |
| 2610 | |
| 2611 | final Drawable frame; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2612 | if (mFrameResource != 0) { |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 2613 | frame = getContext().getDrawable(mFrameResource); |
| 2614 | } else { |
| 2615 | frame = null; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2616 | } |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 2617 | mDecor.setWindowFrame(frame); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2618 | |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 2619 | mDecor.setElevation(mElevation); |
Alan Viverette | 2c18333 | 2014-08-07 13:43:05 -0700 | [diff] [blame] | 2620 | mDecor.setClipToOutline(mClipToOutline); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2621 | |
| 2622 | if (mTitle != null) { |
| 2623 | setTitle(mTitle); |
| 2624 | } |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 2625 | |
| 2626 | if (mTitleColor == 0) { |
| 2627 | mTitleColor = mTextColor; |
| 2628 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2629 | setTitleColor(mTitleColor); |
| 2630 | } |
| 2631 | |
| 2632 | mDecor.finishChanging(); |
| 2633 | |
| 2634 | return contentParent; |
| 2635 | } |
| 2636 | |
Dianne Hackborn | cfaf887 | 2011-01-18 13:57:54 -0800 | [diff] [blame] | 2637 | /** @hide */ |
| 2638 | public void alwaysReadCloseOnTouchAttr() { |
| 2639 | mAlwaysReadCloseOnTouchAttr = true; |
| 2640 | } |
| 2641 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2642 | private void installDecor() { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 2643 | mForceDecorInstall = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2644 | if (mDecor == null) { |
Stefan Kuhne | 61b47bb | 2015-07-28 14:04:25 -0700 | [diff] [blame] | 2645 | mDecor = generateDecor(-1); |
Adam Powell | 00f4d98 | 2010-03-24 11:17:03 -0700 | [diff] [blame] | 2646 | mDecor.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2647 | mDecor.setIsRootNamespace(true); |
Adam Powell | 4b6d93f | 2012-09-18 18:34:08 -0700 | [diff] [blame] | 2648 | if (!mInvalidatePanelMenuPosted && mInvalidatePanelMenuFeatures != 0) { |
| 2649 | mDecor.postOnAnimation(mInvalidatePanelMenuRunnable); |
| 2650 | } |
Filip Gruszczynski | 0daf210 | 2015-09-29 08:39:07 -0700 | [diff] [blame] | 2651 | } else { |
| 2652 | mDecor.setWindow(this); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2653 | } |
| 2654 | if (mContentParent == null) { |
| 2655 | mContentParent = generateLayout(mDecor); |
| 2656 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2657 | // Set up decor part of UI to ignore fitsSystemWindows if appropriate. |
| 2658 | mDecor.makeOptionalFitsSystemWindows(); |
| 2659 | |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 2660 | final DecorContentParent decorContentParent = (DecorContentParent) mDecor.findViewById( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2661 | R.id.decor_content_parent); |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 2662 | |
| 2663 | if (decorContentParent != null) { |
| 2664 | mDecorContentParent = decorContentParent; |
| 2665 | mDecorContentParent.setWindowCallback(getCallback()); |
| 2666 | if (mDecorContentParent.getTitle() == null) { |
| 2667 | mDecorContentParent.setWindowTitle(mTitle); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2668 | } |
Adam Powell | 9b4bee0 | 2011-04-27 19:24:47 -0700 | [diff] [blame] | 2669 | |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 2670 | final int localFeatures = getLocalFeatures(); |
| 2671 | for (int i = 0; i < FEATURE_MAX; i++) { |
| 2672 | if ((localFeatures & (1 << i)) != 0) { |
| 2673 | mDecorContentParent.initFeature(i); |
Adam Powell | 9b0dc28 | 2013-07-31 13:58:43 -0700 | [diff] [blame] | 2674 | } |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 2675 | } |
Adam Powell | 9b0dc28 | 2013-07-31 13:58:43 -0700 | [diff] [blame] | 2676 | |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 2677 | mDecorContentParent.setUiOptions(mUiOptions); |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 2678 | |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 2679 | if ((mResourcesSetFlags & FLAG_RESOURCE_SET_ICON) != 0 || |
| 2680 | (mIconRes != 0 && !mDecorContentParent.hasIcon())) { |
| 2681 | mDecorContentParent.setIcon(mIconRes); |
| 2682 | } else if ((mResourcesSetFlags & FLAG_RESOURCE_SET_ICON) == 0 && |
| 2683 | mIconRes == 0 && !mDecorContentParent.hasIcon()) { |
| 2684 | mDecorContentParent.setIcon( |
| 2685 | getContext().getPackageManager().getDefaultActivityIcon()); |
| 2686 | mResourcesSetFlags |= FLAG_RESOURCE_SET_ICON_FALLBACK; |
| 2687 | } |
| 2688 | if ((mResourcesSetFlags & FLAG_RESOURCE_SET_LOGO) != 0 || |
| 2689 | (mLogoRes != 0 && !mDecorContentParent.hasLogo())) { |
| 2690 | mDecorContentParent.setLogo(mLogoRes); |
| 2691 | } |
Adam Powell | 9b4bee0 | 2011-04-27 19:24:47 -0700 | [diff] [blame] | 2692 | |
Adam Powell | 31c91c8 | 2014-08-22 17:20:00 -0700 | [diff] [blame] | 2693 | // Invalidate if the panel menu hasn't been created before this. |
| 2694 | // Panel menu invalidation is deferred avoiding application onCreateOptionsMenu |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 2695 | // being called in the middle of onCreate or similar. |
Adam Powell | 31c91c8 | 2014-08-22 17:20:00 -0700 | [diff] [blame] | 2696 | // A pending invalidation will typically be resolved before the posted message |
| 2697 | // would run normally in order to satisfy instance state restoration. |
| 2698 | PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, false); |
Jorim Jaggi | a16cc15 | 2015-06-01 16:55:05 -0700 | [diff] [blame] | 2699 | if (!isDestroyed() && (st == null || st.menu == null) && !mIsStartingWindow) { |
Adam Powell | 31c91c8 | 2014-08-22 17:20:00 -0700 | [diff] [blame] | 2700 | invalidatePanelMenu(FEATURE_ACTION_BAR); |
| 2701 | } |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 2702 | } else { |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 2703 | mTitleView = findViewById(R.id.title); |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 2704 | if (mTitleView != null) { |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 2705 | if ((getLocalFeatures() & (1 << FEATURE_NO_TITLE)) != 0) { |
Alan Viverette | 891c9ee | 2016-01-08 13:43:15 -0500 | [diff] [blame] | 2706 | final View titleContainer = findViewById(R.id.title_container); |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 2707 | if (titleContainer != null) { |
| 2708 | titleContainer.setVisibility(View.GONE); |
| 2709 | } else { |
| 2710 | mTitleView.setVisibility(View.GONE); |
| 2711 | } |
Alan Viverette | 891c9ee | 2016-01-08 13:43:15 -0500 | [diff] [blame] | 2712 | mContentParent.setForeground(null); |
Adam Powell | 4369e7d | 2014-05-17 14:16:08 -0700 | [diff] [blame] | 2713 | } else { |
| 2714 | mTitleView.setText(mTitle); |
| 2715 | } |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 2716 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2717 | } |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 2718 | |
Adam Powell | f849a5e | 2014-09-11 15:09:36 -0700 | [diff] [blame] | 2719 | if (mDecor.getBackground() == null && mBackgroundFallbackResource != 0) { |
| 2720 | mDecor.setBackgroundFallback(mBackgroundFallbackResource); |
| 2721 | } |
| 2722 | |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 2723 | // Only inflate or create a new TransitionManager if the caller hasn't |
| 2724 | // already set a custom one. |
George Mount | 9826f63 | 2014-09-11 08:50:09 -0700 | [diff] [blame] | 2725 | if (hasFeature(FEATURE_ACTIVITY_TRANSITIONS)) { |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 2726 | if (mTransitionManager == null) { |
| 2727 | final int transitionRes = getWindowStyle().getResourceId( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2728 | R.styleable.Window_windowContentTransitionManager, |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 2729 | 0); |
| 2730 | if (transitionRes != 0) { |
| 2731 | final TransitionInflater inflater = TransitionInflater.from(getContext()); |
| 2732 | mTransitionManager = inflater.inflateTransitionManager(transitionRes, |
| 2733 | mContentParent); |
| 2734 | } else { |
| 2735 | mTransitionManager = new TransitionManager(); |
| 2736 | } |
| 2737 | } |
| 2738 | |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 2739 | mEnterTransition = getTransition(mEnterTransition, null, |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2740 | R.styleable.Window_windowEnterTransition); |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 2741 | mReturnTransition = getTransition(mReturnTransition, USE_DEFAULT_TRANSITION, |
| 2742 | R.styleable.Window_windowReturnTransition); |
| 2743 | mExitTransition = getTransition(mExitTransition, null, |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2744 | R.styleable.Window_windowExitTransition); |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 2745 | mReenterTransition = getTransition(mReenterTransition, USE_DEFAULT_TRANSITION, |
| 2746 | R.styleable.Window_windowReenterTransition); |
| 2747 | mSharedElementEnterTransition = getTransition(mSharedElementEnterTransition, null, |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2748 | R.styleable.Window_windowSharedElementEnterTransition); |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 2749 | mSharedElementReturnTransition = getTransition(mSharedElementReturnTransition, |
| 2750 | USE_DEFAULT_TRANSITION, |
| 2751 | R.styleable.Window_windowSharedElementReturnTransition); |
| 2752 | mSharedElementExitTransition = getTransition(mSharedElementExitTransition, null, |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2753 | R.styleable.Window_windowSharedElementExitTransition); |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 2754 | mSharedElementReenterTransition = getTransition(mSharedElementReenterTransition, |
| 2755 | USE_DEFAULT_TRANSITION, |
| 2756 | R.styleable.Window_windowSharedElementReenterTransition); |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 2757 | if (mAllowEnterTransitionOverlap == null) { |
| 2758 | mAllowEnterTransitionOverlap = getWindowStyle().getBoolean( |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 2759 | R.styleable.Window_windowAllowEnterTransitionOverlap, true); |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 2760 | } |
George Mount | c03da0e | 2014-08-22 17:04:02 -0700 | [diff] [blame] | 2761 | if (mAllowReturnTransitionOverlap == null) { |
| 2762 | mAllowReturnTransitionOverlap = getWindowStyle().getBoolean( |
| 2763 | R.styleable.Window_windowAllowReturnTransitionOverlap, true); |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 2764 | } |
George Mount | ed1e01d | 2014-06-05 13:49:12 -0700 | [diff] [blame] | 2765 | if (mBackgroundFadeDurationMillis < 0) { |
| 2766 | mBackgroundFadeDurationMillis = getWindowStyle().getInteger( |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 2767 | R.styleable.Window_windowTransitionBackgroundFadeDuration, |
George Mount | ed1e01d | 2014-06-05 13:49:12 -0700 | [diff] [blame] | 2768 | DEFAULT_BACKGROUND_FADE_DURATION_MS); |
| 2769 | } |
George Mount | b89d5cc | 2014-08-18 16:50:50 -0700 | [diff] [blame] | 2770 | if (mSharedElementsUseOverlay == null) { |
| 2771 | mSharedElementsUseOverlay = getWindowStyle().getBoolean( |
| 2772 | R.styleable.Window_windowSharedElementsUseOverlay, true); |
| 2773 | } |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 2774 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2775 | } |
| 2776 | } |
| 2777 | |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 2778 | private Transition getTransition(Transition currentValue, Transition defaultValue, int id) { |
| 2779 | if (currentValue != defaultValue) { |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 2780 | return currentValue; |
| 2781 | } |
| 2782 | int transitionId = getWindowStyle().getResourceId(id, -1); |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 2783 | Transition transition = defaultValue; |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2784 | if (transitionId != -1 && transitionId != R.transition.no_transition) { |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 2785 | TransitionInflater inflater = TransitionInflater.from(getContext()); |
| 2786 | transition = inflater.inflateTransition(transitionId); |
George Mount | 7f15164 | 2014-08-18 16:24:21 -0700 | [diff] [blame] | 2787 | if (transition instanceof TransitionSet && |
| 2788 | ((TransitionSet)transition).getTransitionCount() == 0) { |
| 2789 | transition = null; |
| 2790 | } |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 2791 | } |
| 2792 | return transition; |
| 2793 | } |
| 2794 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2795 | private Drawable loadImageURI(Uri uri) { |
| 2796 | try { |
Alan Viverette | ad3c4a1 | 2014-06-02 17:12:58 -0700 | [diff] [blame] | 2797 | return Drawable.createFromStream( |
| 2798 | getContext().getContentResolver().openInputStream(uri), null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2799 | } catch (Exception e) { |
| 2800 | Log.w(TAG, "Unable to open content: " + uri); |
| 2801 | } |
| 2802 | return null; |
| 2803 | } |
| 2804 | |
| 2805 | private DrawableFeatureState getDrawableState(int featureId, boolean required) { |
| 2806 | if ((getFeatures() & (1 << featureId)) == 0) { |
| 2807 | if (!required) { |
| 2808 | return null; |
| 2809 | } |
| 2810 | throw new RuntimeException("The feature has not been requested"); |
| 2811 | } |
| 2812 | |
| 2813 | DrawableFeatureState[] ar; |
| 2814 | if ((ar = mDrawables) == null || ar.length <= featureId) { |
| 2815 | DrawableFeatureState[] nar = new DrawableFeatureState[featureId + 1]; |
| 2816 | if (ar != null) { |
| 2817 | System.arraycopy(ar, 0, nar, 0, ar.length); |
| 2818 | } |
| 2819 | mDrawables = ar = nar; |
| 2820 | } |
| 2821 | |
| 2822 | DrawableFeatureState st = ar[featureId]; |
| 2823 | if (st == null) { |
| 2824 | ar[featureId] = st = new DrawableFeatureState(featureId); |
| 2825 | } |
| 2826 | return st; |
| 2827 | } |
| 2828 | |
| 2829 | /** |
| 2830 | * 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] | 2831 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2832 | * @param featureId The feature ID of the panel. |
| 2833 | * @param required Whether the panel is required (if it is required and it |
| 2834 | * isn't in our features, this throws an exception). |
| 2835 | * @return The panel state. |
| 2836 | */ |
Wale Ogunwale | 8804af2 | 2015-11-17 09:18:15 -0800 | [diff] [blame] | 2837 | PanelFeatureState getPanelState(int featureId, boolean required) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2838 | return getPanelState(featureId, required, null); |
| 2839 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 2840 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2841 | /** |
| 2842 | * 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] | 2843 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2844 | * @param featureId The feature ID of the panel. |
| 2845 | * @param required Whether the panel is required (if it is required and it |
| 2846 | * isn't in our features, this throws an exception). |
| 2847 | * @param convertPanelState Optional: If the panel state does not exist, use |
| 2848 | * this as the panel state. |
| 2849 | * @return The panel state. |
| 2850 | */ |
| 2851 | private PanelFeatureState getPanelState(int featureId, boolean required, |
| 2852 | PanelFeatureState convertPanelState) { |
| 2853 | if ((getFeatures() & (1 << featureId)) == 0) { |
| 2854 | if (!required) { |
| 2855 | return null; |
| 2856 | } |
| 2857 | throw new RuntimeException("The feature has not been requested"); |
| 2858 | } |
| 2859 | |
| 2860 | PanelFeatureState[] ar; |
| 2861 | if ((ar = mPanels) == null || ar.length <= featureId) { |
| 2862 | PanelFeatureState[] nar = new PanelFeatureState[featureId + 1]; |
| 2863 | if (ar != null) { |
| 2864 | System.arraycopy(ar, 0, nar, 0, ar.length); |
| 2865 | } |
| 2866 | mPanels = ar = nar; |
| 2867 | } |
| 2868 | |
| 2869 | PanelFeatureState st = ar[featureId]; |
| 2870 | if (st == null) { |
| 2871 | ar[featureId] = st = (convertPanelState != null) |
| 2872 | ? convertPanelState |
| 2873 | : new PanelFeatureState(featureId); |
| 2874 | } |
| 2875 | return st; |
| 2876 | } |
| 2877 | |
| 2878 | @Override |
| 2879 | public final void setChildDrawable(int featureId, Drawable drawable) { |
| 2880 | DrawableFeatureState st = getDrawableState(featureId, true); |
| 2881 | st.child = drawable; |
| 2882 | updateDrawable(featureId, st, false); |
| 2883 | } |
| 2884 | |
| 2885 | @Override |
| 2886 | public final void setChildInt(int featureId, int value) { |
| 2887 | updateInt(featureId, value, false); |
| 2888 | } |
| 2889 | |
| 2890 | @Override |
| 2891 | public boolean isShortcutKey(int keyCode, KeyEvent event) { |
Jose Lima | 7a22fc6 | 2015-01-23 17:24:22 -0800 | [diff] [blame] | 2892 | PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, false); |
| 2893 | 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] | 2894 | } |
| 2895 | |
| 2896 | private void updateDrawable(int featureId, DrawableFeatureState st, boolean fromResume) { |
| 2897 | // Do nothing if the decor is not yet installed... an update will |
| 2898 | // need to be forced when we eventually become active. |
| 2899 | if (mContentParent == null) { |
| 2900 | return; |
| 2901 | } |
| 2902 | |
| 2903 | final int featureMask = 1 << featureId; |
| 2904 | |
| 2905 | if ((getFeatures() & featureMask) == 0 && !fromResume) { |
| 2906 | return; |
| 2907 | } |
| 2908 | |
| 2909 | Drawable drawable = null; |
| 2910 | if (st != null) { |
| 2911 | drawable = st.child; |
| 2912 | if (drawable == null) |
| 2913 | drawable = st.local; |
| 2914 | if (drawable == null) |
| 2915 | drawable = st.def; |
| 2916 | } |
| 2917 | if ((getLocalFeatures() & featureMask) == 0) { |
| 2918 | if (getContainer() != null) { |
| 2919 | if (isActive() || fromResume) { |
| 2920 | getContainer().setChildDrawable(featureId, drawable); |
| 2921 | } |
| 2922 | } |
| 2923 | } else if (st != null && (st.cur != drawable || st.curAlpha != st.alpha)) { |
| 2924 | // System.out.println("Drawable changed: old=" + st.cur |
| 2925 | // + ", new=" + drawable); |
| 2926 | st.cur = drawable; |
| 2927 | st.curAlpha = st.alpha; |
| 2928 | onDrawableChanged(featureId, drawable, st.alpha); |
| 2929 | } |
| 2930 | } |
| 2931 | |
| 2932 | private void updateInt(int featureId, int value, boolean fromResume) { |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 2933 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2934 | // Do nothing if the decor is not yet installed... an update will |
| 2935 | // need to be forced when we eventually become active. |
| 2936 | if (mContentParent == null) { |
| 2937 | return; |
| 2938 | } |
| 2939 | |
| 2940 | final int featureMask = 1 << featureId; |
| 2941 | |
| 2942 | if ((getFeatures() & featureMask) == 0 && !fromResume) { |
| 2943 | return; |
| 2944 | } |
| 2945 | |
| 2946 | if ((getLocalFeatures() & featureMask) == 0) { |
| 2947 | if (getContainer() != null) { |
| 2948 | getContainer().setChildInt(featureId, value); |
| 2949 | } |
| 2950 | } else { |
| 2951 | onIntChanged(featureId, value); |
| 2952 | } |
| 2953 | } |
| 2954 | |
| 2955 | private ImageView getLeftIconView() { |
| 2956 | if (mLeftIconView != null) { |
| 2957 | return mLeftIconView; |
| 2958 | } |
| 2959 | if (mContentParent == null) { |
| 2960 | installDecor(); |
| 2961 | } |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 2962 | return (mLeftIconView = (ImageView)findViewById(R.id.left_icon)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2963 | } |
| 2964 | |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2965 | @Override |
| 2966 | protected void dispatchWindowAttributesChanged(WindowManager.LayoutParams attrs) { |
| 2967 | super.dispatchWindowAttributesChanged(attrs); |
| 2968 | if (mDecor != null) { |
Adrian Roos | 05054bd | 2014-10-27 17:04:10 +0100 | [diff] [blame] | 2969 | mDecor.updateColorViews(null /* insets */, true /* animate */); |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2970 | } |
| 2971 | } |
| 2972 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2973 | private ProgressBar getCircularProgressBar(boolean shouldInstallDecor) { |
| 2974 | if (mCircularProgressBar != null) { |
| 2975 | return mCircularProgressBar; |
| 2976 | } |
| 2977 | if (mContentParent == null && shouldInstallDecor) { |
| 2978 | installDecor(); |
| 2979 | } |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 2980 | mCircularProgressBar = findViewById(R.id.progress_circular); |
Adam Powell | 6af97e1 | 2010-11-11 21:11:53 -0800 | [diff] [blame] | 2981 | if (mCircularProgressBar != null) { |
| 2982 | mCircularProgressBar.setVisibility(View.INVISIBLE); |
| 2983 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2984 | return mCircularProgressBar; |
| 2985 | } |
| 2986 | |
| 2987 | private ProgressBar getHorizontalProgressBar(boolean shouldInstallDecor) { |
| 2988 | if (mHorizontalProgressBar != null) { |
| 2989 | return mHorizontalProgressBar; |
| 2990 | } |
| 2991 | if (mContentParent == null && shouldInstallDecor) { |
| 2992 | installDecor(); |
| 2993 | } |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 2994 | mHorizontalProgressBar = findViewById(R.id.progress_horizontal); |
Adam Powell | 6af97e1 | 2010-11-11 21:11:53 -0800 | [diff] [blame] | 2995 | if (mHorizontalProgressBar != null) { |
| 2996 | mHorizontalProgressBar.setVisibility(View.INVISIBLE); |
| 2997 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2998 | return mHorizontalProgressBar; |
| 2999 | } |
| 3000 | |
| 3001 | private ImageView getRightIconView() { |
| 3002 | if (mRightIconView != null) { |
| 3003 | return mRightIconView; |
| 3004 | } |
| 3005 | if (mContentParent == null) { |
| 3006 | installDecor(); |
| 3007 | } |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 3008 | return (mRightIconView = (ImageView)findViewById(R.id.right_icon)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3009 | } |
| 3010 | |
Michael Kwan | f7964be | 2016-11-30 16:44:33 -0800 | [diff] [blame] | 3011 | private void registerSwipeCallbacks(ViewGroup contentParent) { |
| 3012 | if (!(contentParent instanceof SwipeDismissLayout)) { |
| 3013 | Log.w(TAG, "contentParent is not a SwipeDismissLayout: " + contentParent); |
| 3014 | return; |
| 3015 | } |
| 3016 | SwipeDismissLayout swipeDismiss = (SwipeDismissLayout) contentParent; |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 3017 | swipeDismiss.setOnDismissedListener(new SwipeDismissLayout.OnDismissedListener() { |
| 3018 | @Override |
| 3019 | public void onDismissed(SwipeDismissLayout layout) { |
Michael Kwan | 67639a5 | 2016-12-16 12:38:10 -0800 | [diff] [blame] | 3020 | dispatchOnWindowSwipeDismissed(); |
Ned Burns | 7d6cb91 | 2016-12-02 17:25:33 -0500 | [diff] [blame] | 3021 | dispatchOnWindowDismissed(false /*finishTask*/, true /*suppressWindowTransition*/); |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 3022 | } |
| 3023 | }); |
| 3024 | swipeDismiss.setOnSwipeProgressChangedListener( |
| 3025 | new SwipeDismissLayout.OnSwipeProgressChangedListener() { |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 3026 | @Override |
| 3027 | public void onSwipeProgressChanged( |
Ned Burns | 7d6cb91 | 2016-12-02 17:25:33 -0500 | [diff] [blame] | 3028 | SwipeDismissLayout layout, float alpha, float translate) { |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 3029 | WindowManager.LayoutParams newParams = getAttributes(); |
| 3030 | newParams.x = (int) translate; |
Ned Burns | 7d6cb91 | 2016-12-02 17:25:33 -0500 | [diff] [blame] | 3031 | newParams.alpha = alpha; |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 3032 | setAttributes(newParams); |
| 3033 | |
| 3034 | int flags = 0; |
| 3035 | if (newParams.x == 0) { |
| 3036 | flags = FLAG_FULLSCREEN; |
| 3037 | } else { |
| 3038 | flags = FLAG_LAYOUT_NO_LIMITS; |
| 3039 | } |
| 3040 | setFlags(flags, FLAG_FULLSCREEN | FLAG_LAYOUT_NO_LIMITS); |
| 3041 | } |
| 3042 | |
| 3043 | @Override |
| 3044 | public void onSwipeCancelled(SwipeDismissLayout layout) { |
| 3045 | WindowManager.LayoutParams newParams = getAttributes(); |
Michael Kwan | 134ad6e | 2017-02-10 18:38:34 -0800 | [diff] [blame] | 3046 | // Swipe changes only affect the x-translation and alpha, check to see if |
| 3047 | // those values have changed first before resetting them. |
| 3048 | if (newParams.x != 0 || newParams.alpha != 1) { |
| 3049 | newParams.x = 0; |
| 3050 | newParams.alpha = 1; |
| 3051 | setAttributes(newParams); |
| 3052 | setFlags(FLAG_FULLSCREEN, FLAG_FULLSCREEN | FLAG_LAYOUT_NO_LIMITS); |
| 3053 | } |
Will Haldean Brown | ca6234e | 2014-02-12 10:23:41 -0800 | [diff] [blame] | 3054 | } |
| 3055 | }); |
| 3056 | } |
| 3057 | |
Michael Kwan | f7964be | 2016-11-30 16:44:33 -0800 | [diff] [blame] | 3058 | /** @hide */ |
| 3059 | @Override |
| 3060 | public void setCloseOnSwipeEnabled(boolean closeOnSwipeEnabled) { |
| 3061 | if (hasFeature(Window.FEATURE_SWIPE_TO_DISMISS) // swipe-to-dismiss feature is requested |
| 3062 | && mContentParent instanceof SwipeDismissLayout) { // check casting mContentParent |
| 3063 | ((SwipeDismissLayout) mContentParent).setDismissable(closeOnSwipeEnabled); |
| 3064 | } |
| 3065 | super.setCloseOnSwipeEnabled(closeOnSwipeEnabled); |
| 3066 | } |
| 3067 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3068 | /** |
| 3069 | * Helper method for calling the {@link Callback#onPanelClosed(int, Menu)} |
| 3070 | * callback. This method will grab whatever extra state is needed for the |
| 3071 | * callback that isn't given in the parameters. If the panel is not open, |
| 3072 | * this will not perform the callback. |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3073 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3074 | * @param featureId Feature ID of the panel that was closed. Must be given. |
| 3075 | * @param panel Panel that was closed. Optional but useful if there is no |
| 3076 | * menu given. |
| 3077 | * @param menu The menu that was closed. Optional, but give if you have. |
| 3078 | */ |
| 3079 | private void callOnPanelClosed(int featureId, PanelFeatureState panel, Menu menu) { |
| 3080 | final Callback cb = getCallback(); |
| 3081 | if (cb == null) |
| 3082 | return; |
| 3083 | |
| 3084 | // Try to get a menu |
| 3085 | if (menu == null) { |
| 3086 | // Need a panel to grab the menu, so try to get that |
| 3087 | if (panel == null) { |
| 3088 | if ((featureId >= 0) && (featureId < mPanels.length)) { |
| 3089 | panel = mPanels[featureId]; |
| 3090 | } |
| 3091 | } |
| 3092 | |
| 3093 | if (panel != null) { |
| 3094 | // menu still may be null, which is okay--we tried our best |
| 3095 | menu = panel.menu; |
| 3096 | } |
| 3097 | } |
| 3098 | |
| 3099 | // If the panel is not open, do not callback |
| 3100 | if ((panel != null) && (!panel.isOpen)) |
| 3101 | return; |
| 3102 | |
Dianne Hackborn | b66ad57 | 2011-03-01 17:10:30 -0800 | [diff] [blame] | 3103 | if (!isDestroyed()) { |
| 3104 | cb.onPanelClosed(featureId, menu); |
| 3105 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3106 | } |
| 3107 | |
| 3108 | /** |
Sujith Ramakrishnan | 0390fff | 2017-06-08 18:18:12 -0700 | [diff] [blame] | 3109 | * Check if Setup or Post-Setup update is completed on TV |
| 3110 | * @return true if completed |
| 3111 | */ |
| 3112 | private boolean isTvUserSetupComplete() { |
| 3113 | boolean isTvSetupComplete = Settings.Secure.getInt(getContext().getContentResolver(), |
| 3114 | Settings.Secure.USER_SETUP_COMPLETE, 0) != 0; |
| 3115 | isTvSetupComplete &= Settings.Secure.getInt(getContext().getContentResolver(), |
| 3116 | Settings.Secure.TV_USER_SETUP_COMPLETE, 0) != 0; |
| 3117 | return isTvSetupComplete; |
| 3118 | } |
| 3119 | |
| 3120 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3121 | * Helper method for adding launch-search to most applications. Opens the |
| 3122 | * search window using default settings. |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3123 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3124 | * @return true if search window opened |
| 3125 | */ |
Tim Kilbourn | 6a975b3 | 2015-04-09 17:14:34 -0700 | [diff] [blame] | 3126 | private boolean launchDefaultSearch(KeyEvent event) { |
Sujith Ramakrishnan | 0390fff | 2017-06-08 18:18:12 -0700 | [diff] [blame] | 3127 | if (getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK) |
| 3128 | && !isTvUserSetupComplete()) { |
| 3129 | // If we are in Setup or Post-Setup update mode on TV, consume the search key |
| 3130 | return false; |
| 3131 | } |
Dianne Hackborn | fdf5b35 | 2014-10-08 17:43:48 -0700 | [diff] [blame] | 3132 | boolean result; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3133 | final Callback cb = getCallback(); |
Dianne Hackborn | b66ad57 | 2011-03-01 17:10:30 -0800 | [diff] [blame] | 3134 | if (cb == null || isDestroyed()) { |
Dianne Hackborn | fdf5b35 | 2014-10-08 17:43:48 -0700 | [diff] [blame] | 3135 | result = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3136 | } else { |
Karl Rosaen | 323216b | 2009-07-20 14:00:29 -0700 | [diff] [blame] | 3137 | sendCloseSystemWindows("search"); |
Tim Kilbourn | 6a975b3 | 2015-04-09 17:14:34 -0700 | [diff] [blame] | 3138 | int deviceId = event.getDeviceId(); |
| 3139 | SearchEvent searchEvent = null; |
| 3140 | if (deviceId != 0) { |
| 3141 | searchEvent = new SearchEvent(InputDevice.getDevice(deviceId)); |
| 3142 | } |
Adam Powell | 9790034 | 2015-04-15 13:12:52 -0700 | [diff] [blame] | 3143 | try { |
| 3144 | result = cb.onSearchRequested(searchEvent); |
| 3145 | } catch (AbstractMethodError e) { |
| 3146 | Log.e(TAG, "WindowCallback " + cb.getClass().getName() + " does not implement" |
| 3147 | + " method onSearchRequested(SearchEvent); fa", e); |
| 3148 | result = cb.onSearchRequested(); |
| 3149 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3150 | } |
Dianne Hackborn | fdf5b35 | 2014-10-08 17:43:48 -0700 | [diff] [blame] | 3151 | if (!result && (getContext().getResources().getConfiguration().uiMode |
| 3152 | & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) { |
| 3153 | // 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] | 3154 | Bundle args = new Bundle(); |
| 3155 | args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, event.getDeviceId()); |
Dianne Hackborn | fdf5b35 | 2014-10-08 17:43:48 -0700 | [diff] [blame] | 3156 | return ((SearchManager)getContext().getSystemService(Context.SEARCH_SERVICE)) |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 3157 | .launchLegacyAssist(null, UserHandle.myUserId(), args); |
Dianne Hackborn | fdf5b35 | 2014-10-08 17:43:48 -0700 | [diff] [blame] | 3158 | } |
| 3159 | return result; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3160 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3161 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3162 | @Override |
| 3163 | public void setVolumeControlStream(int streamType) { |
| 3164 | mVolumeControlStreamType = streamType; |
| 3165 | } |
| 3166 | |
| 3167 | @Override |
| 3168 | public int getVolumeControlStream() { |
| 3169 | return mVolumeControlStreamType; |
| 3170 | } |
| 3171 | |
RoboErik | 5501165 | 2014-07-09 15:05:53 -0700 | [diff] [blame] | 3172 | @Override |
| 3173 | public void setMediaController(MediaController controller) { |
| 3174 | mMediaController = controller; |
| 3175 | } |
| 3176 | |
| 3177 | @Override |
| 3178 | public MediaController getMediaController() { |
| 3179 | return mMediaController; |
| 3180 | } |
| 3181 | |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 3182 | @Override |
| 3183 | public void setEnterTransition(Transition enterTransition) { |
| 3184 | mEnterTransition = enterTransition; |
| 3185 | } |
| 3186 | |
| 3187 | @Override |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 3188 | public void setReturnTransition(Transition transition) { |
| 3189 | mReturnTransition = transition; |
| 3190 | } |
| 3191 | |
| 3192 | @Override |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 3193 | public void setExitTransition(Transition exitTransition) { |
| 3194 | mExitTransition = exitTransition; |
| 3195 | } |
| 3196 | |
| 3197 | @Override |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 3198 | public void setReenterTransition(Transition transition) { |
| 3199 | mReenterTransition = transition; |
| 3200 | } |
| 3201 | |
| 3202 | @Override |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 3203 | public void setSharedElementEnterTransition(Transition sharedElementEnterTransition) { |
| 3204 | mSharedElementEnterTransition = sharedElementEnterTransition; |
| 3205 | } |
| 3206 | |
| 3207 | @Override |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 3208 | public void setSharedElementReturnTransition(Transition transition) { |
| 3209 | mSharedElementReturnTransition = transition; |
| 3210 | } |
| 3211 | |
| 3212 | @Override |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 3213 | public void setSharedElementExitTransition(Transition sharedElementExitTransition) { |
| 3214 | mSharedElementExitTransition = sharedElementExitTransition; |
| 3215 | } |
| 3216 | |
| 3217 | @Override |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 3218 | public void setSharedElementReenterTransition(Transition transition) { |
| 3219 | mSharedElementReenterTransition = transition; |
| 3220 | } |
| 3221 | |
| 3222 | @Override |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 3223 | public Transition getEnterTransition() { |
| 3224 | return mEnterTransition; |
| 3225 | } |
| 3226 | |
| 3227 | @Override |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 3228 | public Transition getReturnTransition() { |
| 3229 | return mReturnTransition == USE_DEFAULT_TRANSITION ? getEnterTransition() |
| 3230 | : mReturnTransition; |
| 3231 | } |
| 3232 | |
| 3233 | @Override |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 3234 | public Transition getExitTransition() { |
| 3235 | return mExitTransition; |
| 3236 | } |
| 3237 | |
| 3238 | @Override |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 3239 | public Transition getReenterTransition() { |
| 3240 | return mReenterTransition == USE_DEFAULT_TRANSITION ? getExitTransition() |
| 3241 | : mReenterTransition; |
| 3242 | } |
| 3243 | |
| 3244 | @Override |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 3245 | public Transition getSharedElementEnterTransition() { |
| 3246 | return mSharedElementEnterTransition; |
| 3247 | } |
| 3248 | |
| 3249 | @Override |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 3250 | public Transition getSharedElementReturnTransition() { |
| 3251 | return mSharedElementReturnTransition == USE_DEFAULT_TRANSITION |
| 3252 | ? getSharedElementEnterTransition() : mSharedElementReturnTransition; |
| 3253 | } |
| 3254 | |
| 3255 | @Override |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 3256 | public Transition getSharedElementExitTransition() { |
| 3257 | return mSharedElementExitTransition; |
| 3258 | } |
| 3259 | |
| 3260 | @Override |
George Mount | 68f96d8 | 2014-07-31 13:13:10 -0700 | [diff] [blame] | 3261 | public Transition getSharedElementReenterTransition() { |
| 3262 | return mSharedElementReenterTransition == USE_DEFAULT_TRANSITION |
| 3263 | ? getSharedElementExitTransition() : mSharedElementReenterTransition; |
| 3264 | } |
| 3265 | |
| 3266 | @Override |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 3267 | public void setAllowEnterTransitionOverlap(boolean allow) { |
| 3268 | mAllowEnterTransitionOverlap = allow; |
| 3269 | } |
| 3270 | |
| 3271 | @Override |
| 3272 | public boolean getAllowEnterTransitionOverlap() { |
| 3273 | return (mAllowEnterTransitionOverlap == null) ? true : mAllowEnterTransitionOverlap; |
| 3274 | } |
| 3275 | |
| 3276 | @Override |
George Mount | c03da0e | 2014-08-22 17:04:02 -0700 | [diff] [blame] | 3277 | public void setAllowReturnTransitionOverlap(boolean allowExitTransitionOverlap) { |
| 3278 | mAllowReturnTransitionOverlap = allowExitTransitionOverlap; |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 3279 | } |
| 3280 | |
| 3281 | @Override |
George Mount | c03da0e | 2014-08-22 17:04:02 -0700 | [diff] [blame] | 3282 | public boolean getAllowReturnTransitionOverlap() { |
| 3283 | return (mAllowReturnTransitionOverlap == null) ? true : mAllowReturnTransitionOverlap; |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 3284 | } |
| 3285 | |
George Mount | ed1e01d | 2014-06-05 13:49:12 -0700 | [diff] [blame] | 3286 | @Override |
| 3287 | public long getTransitionBackgroundFadeDuration() { |
| 3288 | return (mBackgroundFadeDurationMillis < 0) ? DEFAULT_BACKGROUND_FADE_DURATION_MS |
| 3289 | : mBackgroundFadeDurationMillis; |
| 3290 | } |
| 3291 | |
| 3292 | @Override |
| 3293 | public void setTransitionBackgroundFadeDuration(long fadeDurationMillis) { |
| 3294 | if (fadeDurationMillis < 0) { |
| 3295 | throw new IllegalArgumentException("negative durations are not allowed"); |
| 3296 | } |
| 3297 | mBackgroundFadeDurationMillis = fadeDurationMillis; |
| 3298 | } |
| 3299 | |
George Mount | b89d5cc | 2014-08-18 16:50:50 -0700 | [diff] [blame] | 3300 | @Override |
| 3301 | public void setSharedElementsUseOverlay(boolean sharedElementsUseOverlay) { |
| 3302 | mSharedElementsUseOverlay = sharedElementsUseOverlay; |
| 3303 | } |
| 3304 | |
| 3305 | @Override |
| 3306 | public boolean getSharedElementsUseOverlay() { |
| 3307 | return (mSharedElementsUseOverlay == null) ? true : mSharedElementsUseOverlay; |
| 3308 | } |
| 3309 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3310 | private static final class DrawableFeatureState { |
| 3311 | DrawableFeatureState(int _featureId) { |
| 3312 | featureId = _featureId; |
| 3313 | } |
| 3314 | |
| 3315 | final int featureId; |
| 3316 | |
| 3317 | int resid; |
| 3318 | |
| 3319 | Uri uri; |
| 3320 | |
| 3321 | Drawable local; |
| 3322 | |
| 3323 | Drawable child; |
| 3324 | |
| 3325 | Drawable def; |
| 3326 | |
| 3327 | Drawable cur; |
| 3328 | |
| 3329 | int alpha = 255; |
| 3330 | |
| 3331 | int curAlpha = 255; |
| 3332 | } |
| 3333 | |
Wale Ogunwale | 8804af2 | 2015-11-17 09:18:15 -0800 | [diff] [blame] | 3334 | static final class PanelFeatureState { |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3335 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3336 | /** Feature ID for this panel. */ |
| 3337 | int featureId; |
| 3338 | |
| 3339 | // Information pulled from the style for this panel. |
| 3340 | |
| 3341 | int background; |
| 3342 | |
| 3343 | /** The background when the panel spans the entire available width. */ |
| 3344 | int fullBackground; |
| 3345 | |
| 3346 | int gravity; |
| 3347 | |
| 3348 | int x; |
| 3349 | |
| 3350 | int y; |
| 3351 | |
| 3352 | int windowAnimations; |
| 3353 | |
| 3354 | /** Dynamic state of the panel. */ |
| 3355 | DecorView decorView; |
| 3356 | |
| 3357 | /** The panel that was returned by onCreatePanelView(). */ |
| 3358 | View createdPanelView; |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3359 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3360 | /** The panel that we are actually showing. */ |
| 3361 | View shownPanelView; |
| 3362 | |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3363 | /** Use {@link #setMenu} to set this. */ |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 3364 | MenuBuilder menu; |
| 3365 | |
| 3366 | IconMenuPresenter iconMenuPresenter; |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 3367 | ListMenuPresenter listMenuPresenter; |
| 3368 | |
| 3369 | /** true if this menu will show in single-list compact mode */ |
| 3370 | boolean isCompact; |
| 3371 | |
| 3372 | /** Theme resource ID for list elements of the panel menu */ |
| 3373 | int listPresenterTheme; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3374 | |
| 3375 | /** |
| 3376 | * Whether the panel has been prepared (see |
| 3377 | * {@link PhoneWindow#preparePanel}). |
| 3378 | */ |
| 3379 | boolean isPrepared; |
| 3380 | |
| 3381 | /** |
| 3382 | * Whether an item's action has been performed. This happens in obvious |
| 3383 | * scenarios (user clicks on menu item), but can also happen with |
| 3384 | * chording menu+(shortcut key). |
| 3385 | */ |
| 3386 | boolean isHandled; |
| 3387 | |
| 3388 | boolean isOpen; |
| 3389 | |
| 3390 | /** |
| 3391 | * True if the menu is in expanded mode, false if the menu is in icon |
| 3392 | * mode |
| 3393 | */ |
| 3394 | boolean isInExpandedMode; |
| 3395 | |
| 3396 | public boolean qwertyMode; |
| 3397 | |
| 3398 | boolean refreshDecorView; |
| 3399 | |
Dianne Hackborn | b31e84bc | 2010-06-08 18:04:35 -0700 | [diff] [blame] | 3400 | boolean refreshMenuContent; |
Alan Viverette | eb1d379 | 2014-06-03 18:36:03 -0700 | [diff] [blame] | 3401 | |
Dianne Hackborn | d007144 | 2009-09-25 01:35:29 -0700 | [diff] [blame] | 3402 | boolean wasLastOpen; |
Alan Viverette | eb1d379 | 2014-06-03 18:36:03 -0700 | [diff] [blame] | 3403 | |
Dianne Hackborn | d007144 | 2009-09-25 01:35:29 -0700 | [diff] [blame] | 3404 | boolean wasLastExpanded; |
Alan Viverette | eb1d379 | 2014-06-03 18:36:03 -0700 | [diff] [blame] | 3405 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3406 | /** |
| 3407 | * Contains the state of the menu when told to freeze. |
| 3408 | */ |
| 3409 | Bundle frozenMenuState; |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3410 | |
Adam Powell | 038f1c8 | 2011-07-21 14:28:10 -0700 | [diff] [blame] | 3411 | /** |
| 3412 | * Contains the state of associated action views when told to freeze. |
| 3413 | * These are saved across invalidations. |
| 3414 | */ |
| 3415 | Bundle frozenActionViewState; |
| 3416 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3417 | PanelFeatureState(int featureId) { |
| 3418 | this.featureId = featureId; |
| 3419 | |
| 3420 | refreshDecorView = false; |
| 3421 | } |
| 3422 | |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 3423 | public boolean isInListMode() { |
| 3424 | return isInExpandedMode || isCompact; |
| 3425 | } |
| 3426 | |
Adam Powell | 526b931 | 2011-04-22 15:42:05 -0700 | [diff] [blame] | 3427 | public boolean hasPanelItems() { |
| 3428 | if (shownPanelView == null) return false; |
Adam Powell | 4fd8d533 | 2011-08-17 14:54:41 -0700 | [diff] [blame] | 3429 | if (createdPanelView != null) return true; |
Adam Powell | 526b931 | 2011-04-22 15:42:05 -0700 | [diff] [blame] | 3430 | |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 3431 | if (isCompact || isInExpandedMode) { |
| 3432 | return listMenuPresenter.getAdapter().getCount() > 0; |
Adam Powell | 526b931 | 2011-04-22 15:42:05 -0700 | [diff] [blame] | 3433 | } else { |
| 3434 | return ((ViewGroup) shownPanelView).getChildCount() > 0; |
| 3435 | } |
| 3436 | } |
| 3437 | |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 3438 | /** |
| 3439 | * Unregister and free attached MenuPresenters. They will be recreated as needed. |
| 3440 | */ |
| 3441 | public void clearMenuPresenters() { |
| 3442 | if (menu != null) { |
| 3443 | menu.removeMenuPresenter(iconMenuPresenter); |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 3444 | menu.removeMenuPresenter(listMenuPresenter); |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 3445 | } |
| 3446 | iconMenuPresenter = null; |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 3447 | listMenuPresenter = null; |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 3448 | } |
| 3449 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3450 | void setStyle(Context context) { |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 3451 | TypedArray a = context.obtainStyledAttributes(R.styleable.Theme); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3452 | background = a.getResourceId( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 3453 | R.styleable.Theme_panelBackground, 0); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3454 | fullBackground = a.getResourceId( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 3455 | R.styleable.Theme_panelFullBackground, 0); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3456 | windowAnimations = a.getResourceId( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 3457 | R.styleable.Theme_windowAnimationStyle, 0); |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 3458 | isCompact = a.getBoolean( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 3459 | R.styleable.Theme_panelMenuIsCompact, false); |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 3460 | listPresenterTheme = a.getResourceId( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 3461 | R.styleable.Theme_panelMenuListTheme, |
| 3462 | R.style.Theme_ExpandedMenu); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3463 | a.recycle(); |
| 3464 | } |
| 3465 | |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 3466 | void setMenu(MenuBuilder menu) { |
Adam Powell | 1d07e16 | 2011-09-07 20:46:24 -0700 | [diff] [blame] | 3467 | if (menu == this.menu) return; |
| 3468 | |
| 3469 | if (this.menu != null) { |
| 3470 | this.menu.removeMenuPresenter(iconMenuPresenter); |
| 3471 | this.menu.removeMenuPresenter(listMenuPresenter); |
| 3472 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3473 | this.menu = menu; |
Adam Powell | 1d07e16 | 2011-09-07 20:46:24 -0700 | [diff] [blame] | 3474 | if (menu != null) { |
| 3475 | if (iconMenuPresenter != null) menu.addMenuPresenter(iconMenuPresenter); |
| 3476 | if (listMenuPresenter != null) menu.addMenuPresenter(listMenuPresenter); |
| 3477 | } |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 3478 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3479 | |
Adam Powell | 538e565 | 2011-10-11 13:47:08 -0700 | [diff] [blame] | 3480 | MenuView getListMenuView(Context context, MenuPresenter.Callback cb) { |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 3481 | if (menu == null) return null; |
| 3482 | |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 3483 | if (!isCompact) { |
Adam Powell | 538e565 | 2011-10-11 13:47:08 -0700 | [diff] [blame] | 3484 | getIconMenuView(context, cb); // Need this initialized to know where our offset goes |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 3485 | } |
| 3486 | |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 3487 | if (listMenuPresenter == null) { |
| 3488 | listMenuPresenter = new ListMenuPresenter( |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 3489 | R.layout.list_menu_item_layout, listPresenterTheme); |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 3490 | listMenuPresenter.setCallback(cb); |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 3491 | listMenuPresenter.setId(R.id.list_menu_presenter); |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 3492 | menu.addMenuPresenter(listMenuPresenter); |
| 3493 | } |
| 3494 | |
| 3495 | if (iconMenuPresenter != null) { |
| 3496 | listMenuPresenter.setItemIndexOffset( |
| 3497 | iconMenuPresenter.getNumActualItemsShown()); |
| 3498 | } |
| 3499 | MenuView result = listMenuPresenter.getMenuView(decorView); |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 3500 | |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 3501 | return result; |
| 3502 | } |
| 3503 | |
Adam Powell | 538e565 | 2011-10-11 13:47:08 -0700 | [diff] [blame] | 3504 | MenuView getIconMenuView(Context context, MenuPresenter.Callback cb) { |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 3505 | if (menu == null) return null; |
| 3506 | |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 3507 | if (iconMenuPresenter == null) { |
Adam Powell | 538e565 | 2011-10-11 13:47:08 -0700 | [diff] [blame] | 3508 | iconMenuPresenter = new IconMenuPresenter(context); |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 3509 | iconMenuPresenter.setCallback(cb); |
Alan Viverette | 40982d4 | 2014-07-25 17:48:55 -0700 | [diff] [blame] | 3510 | iconMenuPresenter.setId(R.id.icon_menu_presenter); |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 3511 | menu.addMenuPresenter(iconMenuPresenter); |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 3512 | } |
| 3513 | |
| 3514 | MenuView result = iconMenuPresenter.getMenuView(decorView); |
| 3515 | |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 3516 | return result; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3517 | } |
| 3518 | |
| 3519 | Parcelable onSaveInstanceState() { |
| 3520 | SavedState savedState = new SavedState(); |
| 3521 | savedState.featureId = featureId; |
| 3522 | savedState.isOpen = isOpen; |
| 3523 | savedState.isInExpandedMode = isInExpandedMode; |
| 3524 | |
| 3525 | if (menu != null) { |
| 3526 | savedState.menuState = new Bundle(); |
Adam Powell | 11ed1d6 | 2011-07-11 21:19:59 -0700 | [diff] [blame] | 3527 | menu.savePresenterStates(savedState.menuState); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3528 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3529 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3530 | return savedState; |
| 3531 | } |
| 3532 | |
| 3533 | void onRestoreInstanceState(Parcelable state) { |
| 3534 | SavedState savedState = (SavedState) state; |
| 3535 | featureId = savedState.featureId; |
Dianne Hackborn | d007144 | 2009-09-25 01:35:29 -0700 | [diff] [blame] | 3536 | wasLastOpen = savedState.isOpen; |
| 3537 | wasLastExpanded = savedState.isInExpandedMode; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3538 | frozenMenuState = savedState.menuState; |
| 3539 | |
| 3540 | /* |
| 3541 | * A LocalActivityManager keeps the same instance of this class around. |
| 3542 | * The first time the menu is being shown after restoring, the |
| 3543 | * Activity.onCreateOptionsMenu should be called. But, if it is the |
| 3544 | * same instance then menu != null and we won't call that method. |
Adam Powell | 31bb97d | 2011-05-03 20:58:31 -0700 | [diff] [blame] | 3545 | * 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] | 3546 | */ |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3547 | createdPanelView = null; |
| 3548 | shownPanelView = null; |
| 3549 | decorView = null; |
| 3550 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3551 | |
Adam Powell | 11ed1d6 | 2011-07-11 21:19:59 -0700 | [diff] [blame] | 3552 | void applyFrozenState() { |
| 3553 | if (menu != null && frozenMenuState != null) { |
| 3554 | menu.restorePresenterStates(frozenMenuState); |
| 3555 | frozenMenuState = null; |
| 3556 | } |
| 3557 | } |
| 3558 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3559 | private static class SavedState implements Parcelable { |
| 3560 | int featureId; |
| 3561 | boolean isOpen; |
| 3562 | boolean isInExpandedMode; |
| 3563 | Bundle menuState; |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3564 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3565 | public int describeContents() { |
| 3566 | return 0; |
| 3567 | } |
| 3568 | |
| 3569 | public void writeToParcel(Parcel dest, int flags) { |
| 3570 | dest.writeInt(featureId); |
| 3571 | dest.writeInt(isOpen ? 1 : 0); |
| 3572 | dest.writeInt(isInExpandedMode ? 1 : 0); |
| 3573 | |
| 3574 | if (isOpen) { |
| 3575 | dest.writeBundle(menuState); |
| 3576 | } |
| 3577 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3578 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3579 | private static SavedState readFromParcel(Parcel source) { |
| 3580 | SavedState savedState = new SavedState(); |
| 3581 | savedState.featureId = source.readInt(); |
| 3582 | savedState.isOpen = source.readInt() == 1; |
| 3583 | savedState.isInExpandedMode = source.readInt() == 1; |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3584 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3585 | if (savedState.isOpen) { |
| 3586 | savedState.menuState = source.readBundle(); |
| 3587 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3588 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3589 | return savedState; |
| 3590 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3591 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3592 | public static final Parcelable.Creator<SavedState> CREATOR |
| 3593 | = new Parcelable.Creator<SavedState>() { |
| 3594 | public SavedState createFromParcel(Parcel in) { |
| 3595 | return readFromParcel(in); |
| 3596 | } |
| 3597 | |
| 3598 | public SavedState[] newArray(int size) { |
| 3599 | return new SavedState[size]; |
| 3600 | } |
| 3601 | }; |
| 3602 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3603 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3604 | } |
| 3605 | |
Adam Powell | 6711f3b | 2015-05-06 15:57:09 -0700 | [diff] [blame] | 3606 | static class RotationWatcher extends Stub { |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 3607 | private Handler mHandler; |
| 3608 | private final Runnable mRotationChanged = new Runnable() { |
| 3609 | public void run() { |
| 3610 | dispatchRotationChanged(); |
| 3611 | } |
| 3612 | }; |
| 3613 | private final ArrayList<WeakReference<PhoneWindow>> mWindows = |
| 3614 | new ArrayList<WeakReference<PhoneWindow>>(); |
| 3615 | private boolean mIsWatching; |
| 3616 | |
| 3617 | @Override |
| 3618 | public void onRotationChanged(int rotation) throws RemoteException { |
| 3619 | mHandler.post(mRotationChanged); |
| 3620 | } |
| 3621 | |
| 3622 | public void addWindow(PhoneWindow phoneWindow) { |
| 3623 | synchronized (mWindows) { |
| 3624 | if (!mIsWatching) { |
| 3625 | try { |
Andrii Kulian | 35fa3c2 | 2017-03-11 09:37:28 -0800 | [diff] [blame] | 3626 | WindowManagerHolder.sWindowManager.watchRotation(this, |
| 3627 | phoneWindow.getContext().getDisplay().getDisplayId()); |
Adam Powell | dfee59a | 2011-08-05 20:48:30 -0700 | [diff] [blame] | 3628 | mHandler = new Handler(); |
| 3629 | mIsWatching = true; |
| 3630 | } catch (RemoteException ex) { |
| 3631 | Log.e(TAG, "Couldn't start watching for device rotation", ex); |
| 3632 | } |
| 3633 | } |
| 3634 | mWindows.add(new WeakReference<PhoneWindow>(phoneWindow)); |
| 3635 | } |
| 3636 | } |
| 3637 | |
| 3638 | public void removeWindow(PhoneWindow phoneWindow) { |
| 3639 | synchronized (mWindows) { |
| 3640 | int i = 0; |
| 3641 | while (i < mWindows.size()) { |
| 3642 | final WeakReference<PhoneWindow> ref = mWindows.get(i); |
| 3643 | final PhoneWindow win = ref.get(); |
| 3644 | if (win == null || win == phoneWindow) { |
| 3645 | mWindows.remove(i); |
| 3646 | } else { |
| 3647 | i++; |
| 3648 | } |
| 3649 | } |
| 3650 | } |
| 3651 | } |
| 3652 | |
| 3653 | void dispatchRotationChanged() { |
| 3654 | synchronized (mWindows) { |
| 3655 | int i = 0; |
| 3656 | while (i < mWindows.size()) { |
| 3657 | final WeakReference<PhoneWindow> ref = mWindows.get(i); |
| 3658 | final PhoneWindow win = ref.get(); |
| 3659 | if (win != null) { |
| 3660 | win.onOptionsPanelRotationChanged(); |
| 3661 | i++; |
| 3662 | } else { |
| 3663 | mWindows.remove(i); |
| 3664 | } |
| 3665 | } |
| 3666 | } |
| 3667 | } |
| 3668 | } |
| 3669 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3670 | /** |
| 3671 | * Simple implementation of MenuBuilder.Callback that: |
| 3672 | * <li> Opens a submenu when selected. |
| 3673 | * <li> Calls back to the callback's onMenuItemSelected when an item is |
| 3674 | * selected. |
| 3675 | */ |
Alan Viverette | 77fb85e | 2015-12-14 11:42:44 -0500 | [diff] [blame] | 3676 | public static final class PhoneWindowMenuCallback |
| 3677 | implements MenuBuilder.Callback, MenuPresenter.Callback { |
| 3678 | private static final int FEATURE_ID = FEATURE_CONTEXT_MENU; |
| 3679 | |
| 3680 | private final PhoneWindow mWindow; |
| 3681 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3682 | private MenuDialogHelper mSubMenuHelper; |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3683 | |
Alan Viverette | 77fb85e | 2015-12-14 11:42:44 -0500 | [diff] [blame] | 3684 | private boolean mShowDialogForSubmenu; |
| 3685 | |
| 3686 | public PhoneWindowMenuCallback(PhoneWindow window) { |
| 3687 | mWindow = window; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3688 | } |
| 3689 | |
Alan Viverette | 77fb85e | 2015-12-14 11:42:44 -0500 | [diff] [blame] | 3690 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3691 | public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) { |
Adam Powell | d1f4207 | 2011-05-03 17:20:14 -0700 | [diff] [blame] | 3692 | if (menu.getRootMenu() != menu) { |
| 3693 | onCloseSubMenu(menu); |
| 3694 | } |
| 3695 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3696 | if (allMenusAreClosing) { |
Alan Viverette | 77fb85e | 2015-12-14 11:42:44 -0500 | [diff] [blame] | 3697 | final Callback callback = mWindow.getCallback(); |
| 3698 | if (callback != null && !mWindow.isDestroyed()) { |
| 3699 | callback.onPanelClosed(FEATURE_ID, menu); |
Dianne Hackborn | b66ad57 | 2011-03-01 17:10:30 -0800 | [diff] [blame] | 3700 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3701 | |
Alan Viverette | 77fb85e | 2015-12-14 11:42:44 -0500 | [diff] [blame] | 3702 | if (menu == mWindow.mContextMenu) { |
| 3703 | mWindow.dismissContextMenu(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3704 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3705 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3706 | // Dismiss the submenu, if it is showing |
| 3707 | if (mSubMenuHelper != null) { |
| 3708 | mSubMenuHelper.dismiss(); |
| 3709 | mSubMenuHelper = null; |
| 3710 | } |
| 3711 | } |
| 3712 | } |
| 3713 | |
Alan Viverette | 77fb85e | 2015-12-14 11:42:44 -0500 | [diff] [blame] | 3714 | private void onCloseSubMenu(MenuBuilder menu) { |
| 3715 | final Callback callback = mWindow.getCallback(); |
| 3716 | if (callback != null && !mWindow.isDestroyed()) { |
| 3717 | callback.onPanelClosed(FEATURE_ID, menu.getRootMenu()); |
Dianne Hackborn | b66ad57 | 2011-03-01 17:10:30 -0800 | [diff] [blame] | 3718 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3719 | } |
| 3720 | |
Alan Viverette | 77fb85e | 2015-12-14 11:42:44 -0500 | [diff] [blame] | 3721 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3722 | public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) { |
Alan Viverette | 77fb85e | 2015-12-14 11:42:44 -0500 | [diff] [blame] | 3723 | final Callback callback = mWindow.getCallback(); |
| 3724 | return callback != null && !mWindow.isDestroyed() |
| 3725 | && callback.onMenuItemSelected(FEATURE_ID, item); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3726 | } |
| 3727 | |
Alan Viverette | 77fb85e | 2015-12-14 11:42:44 -0500 | [diff] [blame] | 3728 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3729 | public void onMenuModeChange(MenuBuilder menu) { |
| 3730 | } |
| 3731 | |
Alan Viverette | 77fb85e | 2015-12-14 11:42:44 -0500 | [diff] [blame] | 3732 | @Override |
Adam Powell | d1f4207 | 2011-05-03 17:20:14 -0700 | [diff] [blame] | 3733 | public boolean onOpenSubMenu(MenuBuilder subMenu) { |
Alan Viverette | 77fb85e | 2015-12-14 11:42:44 -0500 | [diff] [blame] | 3734 | if (subMenu == null) { |
| 3735 | return false; |
| 3736 | } |
Adam Powell | 823f074 | 2011-09-21 17:17:01 -0700 | [diff] [blame] | 3737 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3738 | // Set a simple callback for the submenu |
| 3739 | subMenu.setCallback(this); |
| 3740 | |
Alan Viverette | 77fb85e | 2015-12-14 11:42:44 -0500 | [diff] [blame] | 3741 | if (mShowDialogForSubmenu) { |
| 3742 | // The window manager will give us a valid window token |
| 3743 | mSubMenuHelper = new MenuDialogHelper(subMenu); |
| 3744 | mSubMenuHelper.show(null); |
| 3745 | return true; |
| 3746 | } |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 3747 | |
Alan Viverette | 77fb85e | 2015-12-14 11:42:44 -0500 | [diff] [blame] | 3748 | return false; |
| 3749 | } |
| 3750 | |
| 3751 | public void setShowDialogForSubmenu(boolean enabled) { |
| 3752 | mShowDialogForSubmenu = enabled; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3753 | } |
| 3754 | } |
| 3755 | |
Wale Ogunwale | 8804af2 | 2015-11-17 09:18:15 -0800 | [diff] [blame] | 3756 | int getLocalFeaturesPrivate() { |
| 3757 | return super.getLocalFeatures(); |
| 3758 | } |
Adrian Roos | 05054bd | 2014-10-27 17:04:10 +0100 | [diff] [blame] | 3759 | |
Wale Ogunwale | 8804af2 | 2015-11-17 09:18:15 -0800 | [diff] [blame] | 3760 | protected void setDefaultWindowFormat(int format) { |
| 3761 | super.setDefaultWindowFormat(format); |
Adrian Roos | 05054bd | 2014-10-27 17:04:10 +0100 | [diff] [blame] | 3762 | } |
| 3763 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3764 | void sendCloseSystemWindows() { |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 3765 | sendCloseSystemWindows(getContext(), null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3766 | } |
| 3767 | |
| 3768 | void sendCloseSystemWindows(String reason) { |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 3769 | sendCloseSystemWindows(getContext(), reason); |
| 3770 | } |
| 3771 | |
| 3772 | public static void sendCloseSystemWindows(Context context, String reason) { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3773 | if (ActivityManager.isSystemReady()) { |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 3774 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 3775 | ActivityManager.getService().closeSystemDialogs(reason); |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 3776 | } catch (RemoteException e) { |
| 3777 | } |
| 3778 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3779 | } |
Adrian Roos | 217ccd2 | 2014-05-09 14:29:04 +0200 | [diff] [blame] | 3780 | |
| 3781 | @Override |
| 3782 | public int getStatusBarColor() { |
Adrian Roos | 34e6544 | 2014-05-17 02:35:33 +0200 | [diff] [blame] | 3783 | return mStatusBarColor; |
Adrian Roos | 217ccd2 | 2014-05-09 14:29:04 +0200 | [diff] [blame] | 3784 | } |
| 3785 | |
| 3786 | @Override |
| 3787 | public void setStatusBarColor(int color) { |
Adrian Roos | 34e6544 | 2014-05-17 02:35:33 +0200 | [diff] [blame] | 3788 | mStatusBarColor = color; |
| 3789 | mForcedStatusBarColor = true; |
| 3790 | if (mDecor != null) { |
Adrian Roos | 05054bd | 2014-10-27 17:04:10 +0100 | [diff] [blame] | 3791 | mDecor.updateColorViews(null, false /* animate */); |
Adrian Roos | 34e6544 | 2014-05-17 02:35:33 +0200 | [diff] [blame] | 3792 | } |
Adrian Roos | 217ccd2 | 2014-05-09 14:29:04 +0200 | [diff] [blame] | 3793 | } |
| 3794 | |
| 3795 | @Override |
| 3796 | public int getNavigationBarColor() { |
Adrian Roos | 34e6544 | 2014-05-17 02:35:33 +0200 | [diff] [blame] | 3797 | return mNavigationBarColor; |
Adrian Roos | 217ccd2 | 2014-05-09 14:29:04 +0200 | [diff] [blame] | 3798 | } |
| 3799 | |
| 3800 | @Override |
| 3801 | public void setNavigationBarColor(int color) { |
Adrian Roos | 34e6544 | 2014-05-17 02:35:33 +0200 | [diff] [blame] | 3802 | mNavigationBarColor = color; |
| 3803 | mForcedNavigationBarColor = true; |
| 3804 | if (mDecor != null) { |
Adrian Roos | 05054bd | 2014-10-27 17:04:10 +0100 | [diff] [blame] | 3805 | mDecor.updateColorViews(null, false /* animate */); |
Seigo Nonaka | 0a9d1ea | 2015-11-18 22:29:06 +0900 | [diff] [blame] | 3806 | mDecor.updateNavigationGuardColor(); |
Adrian Roos | 34e6544 | 2014-05-17 02:35:33 +0200 | [diff] [blame] | 3807 | } |
Adrian Roos | 217ccd2 | 2014-05-09 14:29:04 +0200 | [diff] [blame] | 3808 | } |
Jorim Jaggi | a16cc15 | 2015-06-01 16:55:05 -0700 | [diff] [blame] | 3809 | |
| 3810 | public void setIsStartingWindow(boolean isStartingWindow) { |
| 3811 | mIsStartingWindow = isStartingWindow; |
| 3812 | } |
Stefan Kuhne | f4dd71a | 2015-08-07 09:28:52 -0700 | [diff] [blame] | 3813 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3814 | @Override |
Filip Gruszczynski | 0daf210 | 2015-09-29 08:39:07 -0700 | [diff] [blame] | 3815 | public void setTheme(int resid) { |
| 3816 | mTheme = resid; |
| 3817 | if (mDecor != null) { |
| 3818 | Context context = mDecor.getContext(); |
| 3819 | if (context instanceof DecorContext) { |
| 3820 | context.setTheme(resid); |
| 3821 | } |
| 3822 | } |
| 3823 | } |
Filip Gruszczynski | 3dec081 | 2015-12-09 08:42:41 -0800 | [diff] [blame] | 3824 | |
| 3825 | @Override |
| 3826 | public void setResizingCaptionDrawable(Drawable drawable) { |
| 3827 | mDecor.setUserCaptionBackgroundDrawable(drawable); |
| 3828 | } |
| 3829 | |
| 3830 | @Override |
| 3831 | public void setDecorCaptionShade(int decorCaptionShade) { |
| 3832 | mDecorCaptionShade = decorCaptionShade; |
| 3833 | if (mDecor != null) { |
| 3834 | mDecor.updateDecorCaptionShade(); |
| 3835 | } |
| 3836 | } |
| 3837 | |
| 3838 | int getDecorCaptionShade() { |
| 3839 | return mDecorCaptionShade; |
| 3840 | } |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3841 | |
| 3842 | @Override |
| 3843 | public void setAttributes(WindowManager.LayoutParams params) { |
| 3844 | super.setAttributes(params); |
| 3845 | if (mDecor != null) { |
| 3846 | mDecor.updateLogTag(params); |
| 3847 | } |
| 3848 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3849 | } |