Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.statusbar.phone; |
| 18 | |
Winson Chung | 1aa24b9 | 2019-04-24 15:17:33 -0700 | [diff] [blame] | 19 | import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 20 | |
Winson Chung | a706700 | 2019-05-07 11:50:42 -0700 | [diff] [blame] | 21 | import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_HOME_DISABLED; |
Winson Chung | a313298 | 2019-04-08 13:27:47 -0700 | [diff] [blame] | 22 | import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_NOTIFICATION_PANEL_EXPANDED; |
Winson Chung | a706700 | 2019-05-07 11:50:42 -0700 | [diff] [blame] | 23 | import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_OVERVIEW_DISABLED; |
Winson Chung | 5b6a1fe | 2019-07-26 16:38:08 -0700 | [diff] [blame] | 24 | import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_QUICK_SETTINGS_EXPANDED; |
Winson Chung | a706700 | 2019-05-07 11:50:42 -0700 | [diff] [blame] | 25 | import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_SCREEN_PINNING; |
Winson Chung | cb6454e | 2019-07-23 09:58:47 -0700 | [diff] [blame] | 26 | import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_SEARCH_DISABLED; |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 27 | import static com.android.systemui.shared.system.QuickStepContract.isGesturalMode; |
Winson Chung | 775d287 | 2019-03-27 14:14:01 -0700 | [diff] [blame] | 28 | import static com.android.systemui.statusbar.phone.BarTransitions.MODE_OPAQUE; |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 29 | |
John Spurlock | 1bbd49d | 2012-10-19 11:09:32 -0400 | [diff] [blame] | 30 | import android.animation.LayoutTransition; |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 31 | import android.animation.LayoutTransition.TransitionListener; |
| 32 | import android.animation.ObjectAnimator; |
Matthew Ng | ca4592b | 2018-08-06 14:12:37 -0700 | [diff] [blame] | 33 | import android.animation.PropertyValuesHolder; |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 34 | import android.animation.TimeInterpolator; |
| 35 | import android.animation.ValueAnimator; |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 36 | import android.annotation.DrawableRes; |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 37 | import android.app.StatusBarManager; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 38 | import android.content.Context; |
Selim Cinek | 17a327a | 2014-08-25 15:03:48 +0200 | [diff] [blame] | 39 | import android.content.res.Configuration; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 40 | import android.graphics.Canvas; |
Jeff Brown | a8b9def | 2012-07-23 14:22:49 -0700 | [diff] [blame] | 41 | import android.graphics.Point; |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 42 | import android.graphics.Rect; |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 43 | import android.graphics.Region; |
| 44 | import android.graphics.Region.Op; |
Matthew Ng | 44b1450 | 2018-05-04 11:10:14 -0700 | [diff] [blame] | 45 | import android.os.Bundle; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 46 | import android.util.AttributeSet; |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 47 | import android.util.Log; |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 48 | import android.util.SparseArray; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 49 | import android.view.Display; |
Daniel Sandler | 1d4d30a | 2011-04-28 12:35:29 -0400 | [diff] [blame] | 50 | import android.view.MotionEvent; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 51 | import android.view.Surface; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 52 | import android.view.View; |
John Spurlock | 1bbd49d | 2012-10-19 11:09:32 -0400 | [diff] [blame] | 53 | import android.view.ViewGroup; |
Tracy Zhou | efc3466 | 2019-04-22 13:37:12 -0700 | [diff] [blame] | 54 | import android.view.ViewTreeObserver.InternalInsetsInfo; |
| 55 | import android.view.ViewTreeObserver.OnComputeInternalInsetsListener; |
Adrian Roos | 7e58a08 | 2018-03-09 16:40:56 +0100 | [diff] [blame] | 56 | import android.view.WindowInsets; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 57 | import android.view.WindowManager; |
Matthew Ng | 44b1450 | 2018-05-04 11:10:14 -0700 | [diff] [blame] | 58 | import android.view.accessibility.AccessibilityNodeInfo; |
| 59 | import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction; |
Jason Monk | f1ff209 | 2014-04-29 16:50:53 -0400 | [diff] [blame] | 60 | import android.view.inputmethod.InputMethodManager; |
Jason Monk | 86bc331 | 2016-08-16 13:17:56 -0400 | [diff] [blame] | 61 | import android.widget.FrameLayout; |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 62 | |
Jeff Chang | 2aaa91a | 2018-11-08 18:04:16 +0800 | [diff] [blame] | 63 | import com.android.internal.annotations.VisibleForTesting; |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 64 | import com.android.systemui.Dependency; |
Jason Monk | f85fc96 | 2017-04-19 17:13:41 -0400 | [diff] [blame] | 65 | import com.android.systemui.DockedStackExistsListener; |
Matthew Ng | ca4592b | 2018-08-06 14:12:37 -0700 | [diff] [blame] | 66 | import com.android.systemui.Interpolators; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 67 | import com.android.systemui.R; |
Matthew Ng | 44b1450 | 2018-05-04 11:10:14 -0700 | [diff] [blame] | 68 | import com.android.systemui.SysUiServiceProvider; |
Matthew Ng | 0548fbc | 2019-01-11 12:24:13 -0800 | [diff] [blame] | 69 | import com.android.systemui.assist.AssistManager; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 70 | import com.android.systemui.recents.OverviewProxyService; |
Matthew Ng | 44b1450 | 2018-05-04 11:10:14 -0700 | [diff] [blame] | 71 | import com.android.systemui.recents.Recents; |
Tony Wickham | 05c1f85 | 2018-02-06 12:32:54 -0800 | [diff] [blame] | 72 | import com.android.systemui.recents.RecentsOnboarding; |
Matthew Ng | 87cbf34 | 2018-02-15 12:21:18 -0800 | [diff] [blame] | 73 | import com.android.systemui.shared.system.ActivityManagerWrapper; |
Winson Chung | e108b67 | 2019-03-06 16:11:28 -0800 | [diff] [blame] | 74 | import com.android.systemui.shared.system.QuickStepContract; |
Matthew Ng | 84db161 | 2018-04-17 16:48:21 -0700 | [diff] [blame] | 75 | import com.android.systemui.shared.system.WindowManagerWrapper; |
Daniel Sandler | c26185b | 2012-08-29 15:49:53 -0400 | [diff] [blame] | 76 | import com.android.systemui.statusbar.policy.DeadZone; |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 77 | import com.android.systemui.statusbar.policy.KeyButtonDrawable; |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 78 | |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 79 | import java.io.FileDescriptor; |
| 80 | import java.io.PrintWriter; |
Jason Monk | 32e3bb5 | 2017-07-27 12:35:41 -0400 | [diff] [blame] | 81 | import java.util.function.Consumer; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 82 | |
Matthew Ng | e0d5ccd3 | 2019-05-08 15:13:22 -0700 | [diff] [blame] | 83 | public class NavigationBarView extends FrameLayout implements |
Winson Chung | 1aa24b9 | 2019-04-24 15:17:33 -0700 | [diff] [blame] | 84 | NavigationModeController.ModeChangedListener { |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 85 | final static boolean DEBUG = false; |
Adrian Roos | a98b32c | 2016-08-11 10:41:08 -0700 | [diff] [blame] | 86 | final static String TAG = "StatusBar/NavBarView"; |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 87 | |
Daniel Sandler | c3fc322 | 2012-10-25 13:28:33 -0400 | [diff] [blame] | 88 | // slippery nav bar when everything is disabled, e.g. during setup |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 89 | final static boolean SLIPPERY_WHEN_DISABLED = true; |
Daniel Sandler | c3fc322 | 2012-10-25 13:28:33 -0400 | [diff] [blame] | 90 | |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 91 | final static boolean ALTERNATE_CAR_MODE_UI = false; |
| 92 | |
Daniel Sandler | 5c8da94 | 2011-06-28 00:29:04 -0400 | [diff] [blame] | 93 | View mCurrentView = null; |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 94 | private View mVertical; |
| 95 | private View mHorizontal; |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 96 | |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 97 | /** Indicates that navigation bar is vertical. */ |
| 98 | private boolean mIsVertical; |
Adrian Roos | 090b7d8 | 2016-08-02 18:36:12 -0700 | [diff] [blame] | 99 | private int mCurrentRotation = -1; |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 100 | |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 101 | boolean mLongClickableAccessibilityButton; |
Daniel Sandler | 6da2b76 | 2011-09-14 16:04:59 -0400 | [diff] [blame] | 102 | int mDisabledFlags = 0; |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 103 | int mNavigationIconHints = 0; |
Winson Chung | 1aa24b9 | 2019-04-24 15:17:33 -0700 | [diff] [blame] | 104 | private int mNavBarMode = NAV_BAR_MODE_3BUTTON; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 105 | |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 106 | private Rect mHomeButtonBounds = new Rect(); |
| 107 | private Rect mBackButtonBounds = new Rect(); |
Matthew Ng | 8a8c89c | 2018-03-01 13:21:43 -0800 | [diff] [blame] | 108 | private Rect mRecentsButtonBounds = new Rect(); |
Winson Chung | 8079af7 | 2018-05-10 11:12:55 -0700 | [diff] [blame] | 109 | private Rect mRotationButtonBounds = new Rect(); |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 110 | private final Region mActiveRegion = new Region(); |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 111 | private int[] mTmpPosition = new int[2]; |
| 112 | |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 113 | private KeyButtonDrawable mBackIcon; |
Matthew Ng | ec5b841 | 2018-08-22 10:45:08 -0700 | [diff] [blame] | 114 | private KeyButtonDrawable mHomeDefaultIcon; |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 115 | private KeyButtonDrawable mRecentIcon; |
| 116 | private KeyButtonDrawable mDockedIcon; |
Fabrice Di Meglio | 18d9824 | 2013-01-17 10:57:40 -0800 | [diff] [blame] | 117 | |
Sunny Goyal | a6a5812 | 2019-04-02 10:20:29 -0700 | [diff] [blame] | 118 | private final EdgeBackGestureHandler mEdgeBackGestureHandler; |
Matthew Ng | 603b329 | 2018-03-30 17:15:39 -0700 | [diff] [blame] | 119 | private final DeadZone mDeadZone; |
Matthew Ng | 1e14e96 | 2018-05-03 12:51:43 -0700 | [diff] [blame] | 120 | private boolean mDeadZoneConsuming = false; |
John Spurlock | 89835dd | 2013-08-16 15:06:51 -0400 | [diff] [blame] | 121 | private final NavigationBarTransitions mBarTransitions; |
Matthew Ng | dc79e5c | 2017-12-14 17:37:35 -0800 | [diff] [blame] | 122 | private final OverviewProxyService mOverviewProxyService; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 123 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 124 | // performs manual animation in sync with layout transitions |
| 125 | private final NavTransitionListener mTransitionListener = new NavTransitionListener(); |
| 126 | |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 127 | private OnVerticalChangedListener mOnVerticalChangedListener; |
Jorim Jaggi | 37c1180 | 2015-08-18 20:27:54 -0700 | [diff] [blame] | 128 | private boolean mLayoutTransitionsEnabled = true; |
| 129 | private boolean mWakeAndUnlocking; |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 130 | private boolean mUseCarModeUi = false; |
| 131 | private boolean mInCarMode = false; |
Jorim Jaggi | d30d95d | 2016-02-17 20:27:22 -0800 | [diff] [blame] | 132 | private boolean mDockedStackExists; |
Matthew Ng | f03c3a6 | 2019-04-03 13:52:57 -0700 | [diff] [blame] | 133 | private boolean mImeVisible; |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 134 | |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 135 | private final SparseArray<ButtonDispatcher> mButtonDispatchers = new SparseArray<>(); |
Matthew Ng | 25593cc | 2018-09-12 16:05:41 -0700 | [diff] [blame] | 136 | private final ContextualButtonGroup mContextualButtonGroup; |
Winson | fde2e6a | 2016-03-22 16:03:10 -0700 | [diff] [blame] | 137 | private Configuration mConfiguration; |
Matthew Ng | 8c056c1 | 2018-10-15 15:16:46 -0700 | [diff] [blame] | 138 | private Configuration mTmpLastConfiguration; |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 139 | |
Adrian Roos | db12b15 | 2016-07-12 15:38:55 -0700 | [diff] [blame] | 140 | private NavigationBarInflaterView mNavigationInflaterView; |
Tony Wickham | 05c1f85 | 2018-02-06 12:32:54 -0800 | [diff] [blame] | 141 | private RecentsOnboarding mRecentsOnboarding; |
Matthew Ng | 78f88d1 | 2018-01-23 12:39:55 -0800 | [diff] [blame] | 142 | private NotificationPanelView mPanelView; |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 143 | private FloatingRotationButton mFloatingRotationButton; |
| 144 | private RotationButtonController mRotationButtonController; |
Adrian Roos | db12b15 | 2016-07-12 15:38:55 -0700 | [diff] [blame] | 145 | |
Winson Chung | 775d287 | 2019-03-27 14:14:01 -0700 | [diff] [blame] | 146 | private NavBarTintController mTintController; |
Matthew Ng | b831fb4 | 2019-01-30 11:20:48 -0800 | [diff] [blame] | 147 | |
Matthew Ng | 20136e6 | 2018-05-30 12:20:31 -0700 | [diff] [blame] | 148 | /** |
| 149 | * Helper that is responsible for showing the right toast when a disallowed activity operation |
| 150 | * occurred. In pinned mode, we show instructions on how to break out of this mode, whilst in |
| 151 | * fully locked mode we only show that unlocking is blocked. |
| 152 | */ |
| 153 | private ScreenPinningNotify mScreenPinningNotify; |
| 154 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 155 | private class NavTransitionListener implements TransitionListener { |
| 156 | private boolean mBackTransitioning; |
| 157 | private boolean mHomeAppearing; |
| 158 | private long mStartDelay; |
| 159 | private long mDuration; |
| 160 | private TimeInterpolator mInterpolator; |
| 161 | |
| 162 | @Override |
| 163 | public void startTransition(LayoutTransition transition, ViewGroup container, |
| 164 | View view, int transitionType) { |
| 165 | if (view.getId() == R.id.back) { |
| 166 | mBackTransitioning = true; |
| 167 | } else if (view.getId() == R.id.home && transitionType == LayoutTransition.APPEARING) { |
| 168 | mHomeAppearing = true; |
| 169 | mStartDelay = transition.getStartDelay(transitionType); |
| 170 | mDuration = transition.getDuration(transitionType); |
| 171 | mInterpolator = transition.getInterpolator(transitionType); |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | @Override |
| 176 | public void endTransition(LayoutTransition transition, ViewGroup container, |
| 177 | View view, int transitionType) { |
| 178 | if (view.getId() == R.id.back) { |
| 179 | mBackTransitioning = false; |
| 180 | } else if (view.getId() == R.id.home && transitionType == LayoutTransition.APPEARING) { |
| 181 | mHomeAppearing = false; |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | public void onBackAltCleared() { |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 186 | ButtonDispatcher backButton = getBackButton(); |
Anthony Chen | ada1304 | 2016-01-19 16:57:20 -0800 | [diff] [blame] | 187 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 188 | // When dismissing ime during unlock, force the back button to run the same appearance |
| 189 | // animation as home (if we catch this condition early enough). |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 190 | if (!mBackTransitioning && backButton.getVisibility() == VISIBLE |
| 191 | && mHomeAppearing && getHomeButton().getAlpha() == 0) { |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 192 | getBackButton().setAlpha(0); |
Anthony Chen | ada1304 | 2016-01-19 16:57:20 -0800 | [diff] [blame] | 193 | ValueAnimator a = ObjectAnimator.ofFloat(backButton, "alpha", 0, 1); |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 194 | a.setStartDelay(mStartDelay); |
| 195 | a.setDuration(mDuration); |
| 196 | a.setInterpolator(mInterpolator); |
| 197 | a.start(); |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | |
Jason Monk | f1ff209 | 2014-04-29 16:50:53 -0400 | [diff] [blame] | 202 | private final OnClickListener mImeSwitcherClickListener = new OnClickListener() { |
| 203 | @Override |
| 204 | public void onClick(View view) { |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 205 | mContext.getSystemService(InputMethodManager.class).showInputMethodPickerFromSystem( |
| 206 | true /* showAuxiliarySubtypes */, getContext().getDisplayId()); |
Jason Monk | f1ff209 | 2014-04-29 16:50:53 -0400 | [diff] [blame] | 207 | } |
| 208 | }; |
| 209 | |
Matthew Ng | 44b1450 | 2018-05-04 11:10:14 -0700 | [diff] [blame] | 210 | private final AccessibilityDelegate mQuickStepAccessibilityDelegate |
| 211 | = new AccessibilityDelegate() { |
| 212 | private AccessibilityAction mToggleOverviewAction; |
| 213 | |
| 214 | @Override |
| 215 | public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) { |
| 216 | super.onInitializeAccessibilityNodeInfo(host, info); |
| 217 | if (mToggleOverviewAction == null) { |
| 218 | mToggleOverviewAction = new AccessibilityAction(R.id.action_toggle_overview, |
| 219 | getContext().getString(R.string.quick_step_accessibility_toggle_overview)); |
| 220 | } |
| 221 | info.addAction(mToggleOverviewAction); |
| 222 | } |
| 223 | |
| 224 | @Override |
| 225 | public boolean performAccessibilityAction(View host, int action, Bundle args) { |
Jason Monk | 05dd567 | 2018-08-09 09:38:21 -0400 | [diff] [blame] | 226 | if (action == R.id.action_toggle_overview) { |
| 227 | SysUiServiceProvider.getComponent(getContext(), Recents.class) |
| 228 | .toggleRecentApps(); |
| 229 | } else { |
| 230 | return super.performAccessibilityAction(host, action, args); |
Matthew Ng | 44b1450 | 2018-05-04 11:10:14 -0700 | [diff] [blame] | 231 | } |
| 232 | return true; |
| 233 | } |
| 234 | }; |
| 235 | |
Tracy Zhou | efc3466 | 2019-04-22 13:37:12 -0700 | [diff] [blame] | 236 | private final OnComputeInternalInsetsListener mOnComputeInternalInsetsListener = info -> { |
| 237 | // When the nav bar is in 2-button or 3-button mode, or when IME is visible in fully |
| 238 | // gestural mode, the entire nav bar should be touchable. |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 239 | if (!isGesturalMode(mNavBarMode) || mImeVisible) { |
Tracy Zhou | efc3466 | 2019-04-22 13:37:12 -0700 | [diff] [blame] | 240 | info.setTouchableInsets(InternalInsetsInfo.TOUCHABLE_INSETS_FRAME); |
| 241 | return; |
| 242 | } |
Winson Chung | d882ce1 | 2019-06-05 09:57:01 -0700 | [diff] [blame] | 243 | |
Tracy Zhou | efc3466 | 2019-04-22 13:37:12 -0700 | [diff] [blame] | 244 | info.setTouchableInsets(InternalInsetsInfo.TOUCHABLE_INSETS_REGION); |
Winson Chung | d882ce1 | 2019-06-05 09:57:01 -0700 | [diff] [blame] | 245 | ButtonDispatcher imeSwitchButton = getImeSwitchButton(); |
| 246 | if (imeSwitchButton.getVisibility() == VISIBLE) { |
| 247 | // If the IME is not up, but the ime switch button is visible, then make sure that |
| 248 | // button is touchable |
| 249 | int[] loc = new int[2]; |
| 250 | View buttonView = imeSwitchButton.getCurrentView(); |
| 251 | buttonView.getLocationInWindow(loc); |
| 252 | info.touchableRegion.set(loc[0], loc[1], loc[0] + buttonView.getWidth(), |
| 253 | loc[1] + buttonView.getHeight()); |
| 254 | return; |
| 255 | } |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 256 | info.touchableRegion.setEmpty(); |
Tracy Zhou | efc3466 | 2019-04-22 13:37:12 -0700 | [diff] [blame] | 257 | }; |
| 258 | |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 259 | public NavigationBarView(Context context, AttributeSet attrs) { |
| 260 | super(context, attrs); |
| 261 | |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 262 | mIsVertical = false; |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 263 | mLongClickableAccessibilityButton = false; |
Tracy Zhou | efc3466 | 2019-04-22 13:37:12 -0700 | [diff] [blame] | 264 | mNavBarMode = Dependency.get(NavigationModeController.class).addListener(this); |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 265 | boolean isGesturalMode = isGesturalMode(mNavBarMode); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 266 | |
Matthew Ng | 25593cc | 2018-09-12 16:05:41 -0700 | [diff] [blame] | 267 | // Set up the context group of buttons |
| 268 | mContextualButtonGroup = new ContextualButtonGroup(R.id.menu_container); |
Matthew Ng | 25593cc | 2018-09-12 16:05:41 -0700 | [diff] [blame] | 269 | final ContextualButton imeSwitcherButton = new ContextualButton(R.id.ime_switcher, |
| 270 | R.drawable.ic_ime_switcher_default); |
| 271 | final RotationContextButton rotateSuggestionButton = new RotationContextButton( |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 272 | R.id.rotate_suggestion, R.drawable.ic_sysbar_rotate_button); |
Matthew Ng | 25593cc | 2018-09-12 16:05:41 -0700 | [diff] [blame] | 273 | final ContextualButton accessibilityButton = |
| 274 | new ContextualButton(R.id.accessibility_button, |
| 275 | R.drawable.ic_sysbar_accessibility_button); |
Matthew Ng | 25593cc | 2018-09-12 16:05:41 -0700 | [diff] [blame] | 276 | mContextualButtonGroup.addButton(imeSwitcherButton); |
Tracy Zhou | efc3466 | 2019-04-22 13:37:12 -0700 | [diff] [blame] | 277 | if (!isGesturalMode) { |
| 278 | mContextualButtonGroup.addButton(rotateSuggestionButton); |
| 279 | } |
Matthew Ng | 25593cc | 2018-09-12 16:05:41 -0700 | [diff] [blame] | 280 | mContextualButtonGroup.addButton(accessibilityButton); |
| 281 | |
Matthew Ng | f294654 | 2018-02-12 14:13:18 -0800 | [diff] [blame] | 282 | mOverviewProxyService = Dependency.get(OverviewProxyService.class); |
| 283 | mRecentsOnboarding = new RecentsOnboarding(context, mOverviewProxyService); |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 284 | mFloatingRotationButton = new FloatingRotationButton(context); |
| 285 | mRotationButtonController = new RotationButtonController(context, |
| 286 | R.style.RotateButtonCCWStart90, |
| 287 | isGesturalMode ? mFloatingRotationButton : rotateSuggestionButton); |
Matthew Ng | f294654 | 2018-02-12 14:13:18 -0800 | [diff] [blame] | 288 | |
Tracy Zhou | efc3466 | 2019-04-22 13:37:12 -0700 | [diff] [blame] | 289 | final ContextualButton backButton = new ContextualButton(R.id.back, 0); |
Tracy Zhou | efc3466 | 2019-04-22 13:37:12 -0700 | [diff] [blame] | 290 | |
Winson | fde2e6a | 2016-03-22 16:03:10 -0700 | [diff] [blame] | 291 | mConfiguration = new Configuration(); |
Matthew Ng | 8c056c1 | 2018-10-15 15:16:46 -0700 | [diff] [blame] | 292 | mTmpLastConfiguration = new Configuration(); |
Winson | fde2e6a | 2016-03-22 16:03:10 -0700 | [diff] [blame] | 293 | mConfiguration.updateFrom(context.getResources().getConfiguration()); |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 294 | |
Matthew Ng | 20136e6 | 2018-05-30 12:20:31 -0700 | [diff] [blame] | 295 | mScreenPinningNotify = new ScreenPinningNotify(mContext); |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 296 | mBarTransitions = new NavigationBarTransitions(this); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 297 | |
Tracy Zhou | efc3466 | 2019-04-22 13:37:12 -0700 | [diff] [blame] | 298 | mButtonDispatchers.put(R.id.back, backButton); |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 299 | mButtonDispatchers.put(R.id.home, new ButtonDispatcher(R.id.home)); |
Matthew Ng | b55c02c | 2019-02-15 16:20:31 -0800 | [diff] [blame] | 300 | mButtonDispatchers.put(R.id.home_handle, new ButtonDispatcher(R.id.home_handle)); |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 301 | mButtonDispatchers.put(R.id.recent_apps, new ButtonDispatcher(R.id.recent_apps)); |
Matthew Ng | 25593cc | 2018-09-12 16:05:41 -0700 | [diff] [blame] | 302 | mButtonDispatchers.put(R.id.ime_switcher, imeSwitcherButton); |
| 303 | mButtonDispatchers.put(R.id.accessibility_button, accessibilityButton); |
| 304 | mButtonDispatchers.put(R.id.rotate_suggestion, rotateSuggestionButton); |
| 305 | mButtonDispatchers.put(R.id.menu_container, mContextualButtonGroup); |
Matthew Ng | 603b329 | 2018-03-30 17:15:39 -0700 | [diff] [blame] | 306 | mDeadZone = new DeadZone(this); |
Matthew Ng | 86a436e | 2018-10-26 16:00:53 -0700 | [diff] [blame] | 307 | |
Winson Chung | 04ff8bda | 2019-04-02 15:08:59 -0700 | [diff] [blame] | 308 | mEdgeBackGestureHandler = new EdgeBackGestureHandler(context, mOverviewProxyService); |
Winson Chung | 775d287 | 2019-03-27 14:14:01 -0700 | [diff] [blame] | 309 | mTintController = new NavBarTintController(this, getLightTransitionsController()); |
Matthew Ng | 355fe21 | 2018-12-14 17:42:38 -0800 | [diff] [blame] | 310 | } |
| 311 | |
Winson Chung | 775d287 | 2019-03-27 14:14:01 -0700 | [diff] [blame] | 312 | public NavBarTintController getTintController() { |
| 313 | return mTintController; |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 314 | } |
| 315 | |
James O'Leary | 4335c70 | 2019-05-29 12:38:51 -0400 | [diff] [blame] | 316 | public NavigationBarTransitions getBarTransitions() { |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 317 | return mBarTransitions; |
| 318 | } |
| 319 | |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 320 | public LightBarTransitionsController getLightTransitionsController() { |
| 321 | return mBarTransitions.getLightTransitionsController(); |
| 322 | } |
| 323 | |
Matthew Ng | 0548fbc | 2019-01-11 12:24:13 -0800 | [diff] [blame] | 324 | public void setComponents(NotificationPanelView panel, AssistManager assistManager) { |
Matthew Ng | 78f88d1 | 2018-01-23 12:39:55 -0800 | [diff] [blame] | 325 | mPanelView = panel; |
Winson Chung | 56a667b | 2019-07-30 13:51:27 -0700 | [diff] [blame] | 326 | updatePanelSystemUiStateFlags(); |
Matthew Ng | 1cf6eac | 2018-11-27 15:06:55 -0800 | [diff] [blame] | 327 | } |
| 328 | |
Winson Chung | 600c186 | 2019-03-07 15:14:49 -0800 | [diff] [blame] | 329 | @Override |
| 330 | protected void dispatchDraw(Canvas canvas) { |
| 331 | super.dispatchDraw(canvas); |
Winson Chung | 775d287 | 2019-03-27 14:14:01 -0700 | [diff] [blame] | 332 | mTintController.onDraw(); |
Winson Chung | 600c186 | 2019-03-07 15:14:49 -0800 | [diff] [blame] | 333 | } |
| 334 | |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 335 | public void setOnVerticalChangedListener(OnVerticalChangedListener onVerticalChangedListener) { |
| 336 | mOnVerticalChangedListener = onVerticalChangedListener; |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 337 | notifyVerticalChangedListener(mIsVertical); |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 338 | } |
| 339 | |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 340 | @Override |
| 341 | public boolean onInterceptTouchEvent(MotionEvent event) { |
Sunny Goyal | a6a5812 | 2019-04-02 10:20:29 -0700 | [diff] [blame] | 342 | return shouldDeadZoneConsumeTouchEvents(event) || super.onInterceptTouchEvent(event); |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 343 | } |
| 344 | |
Winson Chung | 4faf38a | 2018-02-06 08:53:37 -0800 | [diff] [blame] | 345 | @Override |
| 346 | public boolean onTouchEvent(MotionEvent event) { |
Matthew Ng | 472d3e4 | 2018-06-14 15:16:55 -0700 | [diff] [blame] | 347 | shouldDeadZoneConsumeTouchEvents(event); |
Winson Chung | 4965884 | 2018-02-08 12:52:21 -0800 | [diff] [blame] | 348 | return super.onTouchEvent(event); |
Winson Chung | 4faf38a | 2018-02-06 08:53:37 -0800 | [diff] [blame] | 349 | } |
| 350 | |
Winson Chung | 3d6c080 | 2019-10-04 10:37:12 -0700 | [diff] [blame] | 351 | void onSystemUiVisibilityChanged(int systemUiVisibility) { |
| 352 | mEdgeBackGestureHandler.onSystemUiVisibilityChanged(systemUiVisibility); |
| 353 | } |
| 354 | |
Winson Chung | 775d287 | 2019-03-27 14:14:01 -0700 | [diff] [blame] | 355 | void onBarTransition(int newMode) { |
| 356 | if (newMode == MODE_OPAQUE) { |
| 357 | // If the nav bar background is opaque, stop auto tinting since we know the icons are |
| 358 | // showing over a dark background |
| 359 | mTintController.stop(); |
| 360 | getLightTransitionsController().setIconsDark(false /* dark */, true /* animate */); |
| 361 | } else { |
| 362 | mTintController.start(); |
| 363 | } |
| 364 | } |
| 365 | |
Matthew Ng | 1e14e96 | 2018-05-03 12:51:43 -0700 | [diff] [blame] | 366 | private boolean shouldDeadZoneConsumeTouchEvents(MotionEvent event) { |
Sunny Goyal | a6a5812 | 2019-04-02 10:20:29 -0700 | [diff] [blame] | 367 | int action = event.getActionMasked(); |
| 368 | if (action == MotionEvent.ACTION_DOWN) { |
| 369 | mDeadZoneConsuming = false; |
| 370 | } |
Matthew Ng | 1e14e96 | 2018-05-03 12:51:43 -0700 | [diff] [blame] | 371 | if (mDeadZone.onTouchEvent(event) || mDeadZoneConsuming) { |
Sunny Goyal | a6a5812 | 2019-04-02 10:20:29 -0700 | [diff] [blame] | 372 | switch (action) { |
Matthew Ng | 1e14e96 | 2018-05-03 12:51:43 -0700 | [diff] [blame] | 373 | case MotionEvent.ACTION_DOWN: |
| 374 | // Allow gestures starting in the deadzone to be slippery |
| 375 | setSlippery(true); |
| 376 | mDeadZoneConsuming = true; |
| 377 | break; |
| 378 | case MotionEvent.ACTION_CANCEL: |
| 379 | case MotionEvent.ACTION_UP: |
| 380 | // When a gesture started in the deadzone is finished, restore slippery state |
| 381 | updateSlippery(); |
| 382 | mDeadZoneConsuming = false; |
| 383 | break; |
| 384 | } |
| 385 | return true; |
| 386 | } |
| 387 | return false; |
| 388 | } |
| 389 | |
Xiyuan Xia | ee7dd05 | 2015-05-15 09:46:27 -0700 | [diff] [blame] | 390 | public void abortCurrentGesture() { |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 391 | getHomeButton().abortCurrentGesture(); |
Xiyuan Xia | ee7dd05 | 2015-05-15 09:46:27 -0700 | [diff] [blame] | 392 | } |
| 393 | |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 394 | public View getCurrentView() { |
| 395 | return mCurrentView; |
| 396 | } |
| 397 | |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 398 | public RotationButtonController getRotationButtonController() { |
| 399 | return mRotationButtonController; |
| 400 | } |
| 401 | |
| 402 | public FloatingRotationButton getFloatingRotationButton() { |
| 403 | return mFloatingRotationButton; |
| 404 | } |
| 405 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 406 | public ButtonDispatcher getRecentsButton() { |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 407 | return mButtonDispatchers.get(R.id.recent_apps); |
Daniel Sandler | 5c8da94 | 2011-06-28 00:29:04 -0400 | [diff] [blame] | 408 | } |
| 409 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 410 | public ButtonDispatcher getBackButton() { |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 411 | return mButtonDispatchers.get(R.id.back); |
Mike Lockwood | e3646dd | 2011-09-01 12:46:28 -0400 | [diff] [blame] | 412 | } |
| 413 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 414 | public ButtonDispatcher getHomeButton() { |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 415 | return mButtonDispatchers.get(R.id.home); |
Mike Lockwood | e3646dd | 2011-09-01 12:46:28 -0400 | [diff] [blame] | 416 | } |
| 417 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 418 | public ButtonDispatcher getImeSwitchButton() { |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 419 | return mButtonDispatchers.get(R.id.ime_switcher); |
Jason Monk | f1ff209 | 2014-04-29 16:50:53 -0400 | [diff] [blame] | 420 | } |
| 421 | |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 422 | public ButtonDispatcher getAccessibilityButton() { |
| 423 | return mButtonDispatchers.get(R.id.accessibility_button); |
| 424 | } |
| 425 | |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 426 | public RotationContextButton getRotateSuggestionButton() { |
Tracy Zhou | efc3466 | 2019-04-22 13:37:12 -0700 | [diff] [blame] | 427 | return (RotationContextButton) mButtonDispatchers.get(R.id.rotate_suggestion); |
| 428 | } |
| 429 | |
Matthew Ng | b55c02c | 2019-02-15 16:20:31 -0800 | [diff] [blame] | 430 | public ButtonDispatcher getHomeHandle() { |
| 431 | return mButtonDispatchers.get(R.id.home_handle); |
| 432 | } |
| 433 | |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 434 | public SparseArray<ButtonDispatcher> getButtonDispatchers() { |
| 435 | return mButtonDispatchers; |
| 436 | } |
| 437 | |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 438 | public boolean isRecentsButtonVisible() { |
| 439 | return getRecentsButton().getVisibility() == View.VISIBLE; |
| 440 | } |
| 441 | |
Matthew Ng | 6ff33b7 | 2018-02-27 13:47:38 -0800 | [diff] [blame] | 442 | public boolean isOverviewEnabled() { |
| 443 | return (mDisabledFlags & View.STATUS_BAR_DISABLE_RECENT) == 0; |
| 444 | } |
| 445 | |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 446 | public boolean isQuickStepSwipeUpEnabled() { |
Matthew Ng | c1a97b1 | 2018-03-28 14:02:00 -0700 | [diff] [blame] | 447 | return mOverviewProxyService.shouldShowSwipeUpUI() && isOverviewEnabled(); |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 448 | } |
| 449 | |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 450 | private void reloadNavIcons() { |
Matthew Ng | 8c056c1 | 2018-10-15 15:16:46 -0700 | [diff] [blame] | 451 | updateIcons(Configuration.EMPTY); |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 452 | } |
| 453 | |
Matthew Ng | 8c056c1 | 2018-10-15 15:16:46 -0700 | [diff] [blame] | 454 | private void updateIcons(Configuration oldConfig) { |
| 455 | final boolean orientationChange = oldConfig.orientation != mConfiguration.orientation; |
| 456 | final boolean densityChange = oldConfig.densityDpi != mConfiguration.densityDpi; |
| 457 | final boolean dirChange = oldConfig.getLayoutDirection() != mConfiguration.getLayoutDirection(); |
Matthew Ng | ca4592b | 2018-08-06 14:12:37 -0700 | [diff] [blame] | 458 | |
| 459 | if (orientationChange || densityChange) { |
Matthew Ng | d6865ba | 2018-08-27 17:58:41 -0700 | [diff] [blame] | 460 | mDockedIcon = getDrawable(R.drawable.ic_sysbar_docked); |
| 461 | mHomeDefaultIcon = getHomeDrawable(); |
Winson | fde2e6a | 2016-03-22 16:03:10 -0700 | [diff] [blame] | 462 | } |
Matthew Ng | ca4592b | 2018-08-06 14:12:37 -0700 | [diff] [blame] | 463 | if (densityChange || dirChange) { |
Matthew Ng | d6865ba | 2018-08-27 17:58:41 -0700 | [diff] [blame] | 464 | mRecentIcon = getDrawable(R.drawable.ic_sysbar_recent); |
Matthew Ng | 25593cc | 2018-09-12 16:05:41 -0700 | [diff] [blame] | 465 | mContextualButtonGroup.updateIcons(); |
Winson | fde2e6a | 2016-03-22 16:03:10 -0700 | [diff] [blame] | 466 | } |
Matthew Ng | ca4592b | 2018-08-06 14:12:37 -0700 | [diff] [blame] | 467 | if (orientationChange || densityChange || dirChange) { |
Matthew Ng | d6865ba | 2018-08-27 17:58:41 -0700 | [diff] [blame] | 468 | mBackIcon = getBackDrawable(); |
Matthew Ng | ca4592b | 2018-08-06 14:12:37 -0700 | [diff] [blame] | 469 | } |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 470 | } |
| 471 | |
Matthew Ng | d6865ba | 2018-08-27 17:58:41 -0700 | [diff] [blame] | 472 | public KeyButtonDrawable getBackDrawable() { |
Tracy Zhou | efc3466 | 2019-04-22 13:37:12 -0700 | [diff] [blame] | 473 | KeyButtonDrawable drawable = getDrawable(getBackDrawableRes()); |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 474 | orientBackButton(drawable); |
| 475 | return drawable; |
Matthew Ng | 87cbf34 | 2018-02-15 12:21:18 -0800 | [diff] [blame] | 476 | } |
| 477 | |
Tracy Zhou | efc3466 | 2019-04-22 13:37:12 -0700 | [diff] [blame] | 478 | public @DrawableRes int getBackDrawableRes() { |
| 479 | return chooseNavigationIconDrawableRes(R.drawable.ic_sysbar_back, |
| 480 | R.drawable.ic_sysbar_back_quick_step); |
| 481 | } |
| 482 | |
Matthew Ng | d6865ba | 2018-08-27 17:58:41 -0700 | [diff] [blame] | 483 | public KeyButtonDrawable getHomeDrawable() { |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 484 | final boolean quickStepEnabled = mOverviewProxyService.shouldShowSwipeUpUI(); |
| 485 | KeyButtonDrawable drawable = quickStepEnabled |
Matthew Ng | d6865ba | 2018-08-27 17:58:41 -0700 | [diff] [blame] | 486 | ? getDrawable(R.drawable.ic_sysbar_home_quick_step) |
| 487 | : getDrawable(R.drawable.ic_sysbar_home); |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 488 | orientHomeButton(drawable); |
| 489 | return drawable; |
Matthew Ng | 87cbf34 | 2018-02-15 12:21:18 -0800 | [diff] [blame] | 490 | } |
| 491 | |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 492 | private void orientBackButton(KeyButtonDrawable drawable) { |
| 493 | final boolean useAltBack = |
Matthew Ng | ca4592b | 2018-08-06 14:12:37 -0700 | [diff] [blame] | 494 | (mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) != 0; |
Matthew Ng | 8c056c1 | 2018-10-15 15:16:46 -0700 | [diff] [blame] | 495 | final boolean isRtl = mConfiguration.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; |
Matthew Ng | d04bd0f | 2019-04-08 17:29:45 -0700 | [diff] [blame] | 496 | float degrees = useAltBack ? (isRtl ? 90 : -90) : 0; |
Matthew Ng | ca4592b | 2018-08-06 14:12:37 -0700 | [diff] [blame] | 497 | if (drawable.getRotation() == degrees) { |
| 498 | return; |
| 499 | } |
| 500 | |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 501 | if (isGesturalMode(mNavBarMode)) { |
Matthew Ng | f03c3a6 | 2019-04-03 13:52:57 -0700 | [diff] [blame] | 502 | drawable.setRotation(degrees); |
| 503 | return; |
| 504 | } |
| 505 | |
Matthew Ng | ca4592b | 2018-08-06 14:12:37 -0700 | [diff] [blame] | 506 | // Animate the back button's rotation to the new degrees and only in portrait move up the |
| 507 | // back button to line up with the other buttons |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 508 | float targetY = !mOverviewProxyService.shouldShowSwipeUpUI() && !mIsVertical && useAltBack |
Matthew Ng | ca4592b | 2018-08-06 14:12:37 -0700 | [diff] [blame] | 509 | ? - getResources().getDimension(R.dimen.navbar_back_button_ime_offset) |
| 510 | : 0; |
| 511 | ObjectAnimator navBarAnimator = ObjectAnimator.ofPropertyValuesHolder(drawable, |
| 512 | PropertyValuesHolder.ofFloat(KeyButtonDrawable.KEY_DRAWABLE_ROTATE, degrees), |
| 513 | PropertyValuesHolder.ofFloat(KeyButtonDrawable.KEY_DRAWABLE_TRANSLATE_Y, targetY)); |
| 514 | navBarAnimator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN); |
| 515 | navBarAnimator.setDuration(200); |
| 516 | navBarAnimator.start(); |
Matthew Ng | 87cbf34 | 2018-02-15 12:21:18 -0800 | [diff] [blame] | 517 | } |
| 518 | |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 519 | private void orientHomeButton(KeyButtonDrawable drawable) { |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 520 | drawable.setRotation(mIsVertical ? 90 : 0); |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 521 | } |
| 522 | |
Matthew Ng | d6865ba | 2018-08-27 17:58:41 -0700 | [diff] [blame] | 523 | private KeyButtonDrawable chooseNavigationIconDrawable(@DrawableRes int icon, |
| 524 | @DrawableRes int quickStepIcon) { |
Tracy Zhou | efc3466 | 2019-04-22 13:37:12 -0700 | [diff] [blame] | 525 | return getDrawable(chooseNavigationIconDrawableRes(icon, quickStepIcon)); |
| 526 | } |
| 527 | |
| 528 | private @DrawableRes int chooseNavigationIconDrawableRes(@DrawableRes int icon, |
| 529 | @DrawableRes int quickStepIcon) { |
Matthew Ng | c1a97b1 | 2018-03-28 14:02:00 -0700 | [diff] [blame] | 530 | final boolean quickStepEnabled = mOverviewProxyService.shouldShowSwipeUpUI(); |
Tracy Zhou | efc3466 | 2019-04-22 13:37:12 -0700 | [diff] [blame] | 531 | return quickStepEnabled ? quickStepIcon : icon; |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 532 | } |
| 533 | |
Matthew Ng | d6865ba | 2018-08-27 17:58:41 -0700 | [diff] [blame] | 534 | private KeyButtonDrawable getDrawable(@DrawableRes int icon) { |
Matthew Ng | 25593cc | 2018-09-12 16:05:41 -0700 | [diff] [blame] | 535 | return KeyButtonDrawable.create(mContext, icon, true /* hasShadow */); |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 536 | } |
| 537 | |
Matthew Ng | d6865ba | 2018-08-27 17:58:41 -0700 | [diff] [blame] | 538 | private KeyButtonDrawable getDrawable(@DrawableRes int icon, boolean hasShadow) { |
Matthew Ng | 25593cc | 2018-09-12 16:05:41 -0700 | [diff] [blame] | 539 | return KeyButtonDrawable.create(mContext, icon, hasShadow); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 540 | } |
| 541 | |
Winson Chung | 2102ae8 | 2019-06-19 13:15:24 -0700 | [diff] [blame] | 542 | public void setWindowVisible(boolean visible) { |
| 543 | mTintController.setWindowVisible(visible); |
| 544 | mRotationButtonController.onNavigationBarWindowVisibilityChange(visible); |
| 545 | } |
| 546 | |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 547 | @Override |
| 548 | public void setLayoutDirection(int layoutDirection) { |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 549 | reloadNavIcons(); |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 550 | |
| 551 | super.setLayoutDirection(layoutDirection); |
Daniel Sandler | 1d4d30a | 2011-04-28 12:35:29 -0400 | [diff] [blame] | 552 | } |
| 553 | |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 554 | public void setNavigationIconHints(int hints) { |
| 555 | if (hints == mNavigationIconHints) return; |
Matthew Ng | 691d558 | 2019-04-04 14:59:17 -0700 | [diff] [blame] | 556 | final boolean newBackAlt = (hints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) != 0; |
| 557 | final boolean oldBackAlt = |
| 558 | (mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) != 0; |
| 559 | if (newBackAlt != oldBackAlt) { |
| 560 | onImeVisibilityChanged(newBackAlt); |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 561 | } |
Matthew Ng | 691d558 | 2019-04-04 14:59:17 -0700 | [diff] [blame] | 562 | |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 563 | if (DEBUG) { |
John Spurlock | 0153478 | 2014-01-13 11:59:22 -0500 | [diff] [blame] | 564 | android.widget.Toast.makeText(getContext(), |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 565 | "Navigation icon hints = " + hints, |
| 566 | 500).show(); |
| 567 | } |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 568 | mNavigationIconHints = hints; |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 569 | updateNavButtonIcons(); |
| 570 | } |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 571 | |
Matthew Ng | 691d558 | 2019-04-04 14:59:17 -0700 | [diff] [blame] | 572 | private void onImeVisibilityChanged(boolean visible) { |
| 573 | if (!visible) { |
| 574 | mTransitionListener.onBackAltCleared(); |
| 575 | } |
| 576 | mImeVisible = visible; |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 577 | mRotationButtonController.getRotationButton().setCanShowRotationButton(!mImeVisible); |
Matthew Ng | 691d558 | 2019-04-04 14:59:17 -0700 | [diff] [blame] | 578 | } |
| 579 | |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 580 | public void setDisabledFlags(int disabledFlags) { |
| 581 | if (mDisabledFlags == disabledFlags) return; |
| 582 | |
| 583 | final boolean overviewEnabledBefore = isOverviewEnabled(); |
| 584 | mDisabledFlags = disabledFlags; |
| 585 | |
| 586 | // Update icons if overview was just enabled to ensure the correct icons are present |
| 587 | if (!overviewEnabledBefore && isOverviewEnabled()) { |
| 588 | reloadNavIcons(); |
| 589 | } |
| 590 | |
| 591 | updateNavButtonIcons(); |
Winson Chung | 1be4c7e | 2018-05-23 18:24:13 -0700 | [diff] [blame] | 592 | updateSlippery(); |
Tracy Zhou | 9814091 | 2018-06-05 12:09:14 -0700 | [diff] [blame] | 593 | setUpSwipeUpOnboarding(isQuickStepSwipeUpEnabled()); |
Winson Chung | 56a667b | 2019-07-30 13:51:27 -0700 | [diff] [blame] | 594 | updateDisabledSystemUiStateFlags(); |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | public void updateNavButtonIcons() { |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 598 | // We have to replace or restore the back and home button icons when exiting or entering |
| 599 | // carmode, respectively. Recents are not available in CarMode in nav bar so change |
| 600 | // to recent icon is not required. |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 601 | final boolean useAltBack = |
| 602 | (mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) != 0; |
Matthew Ng | d6865ba | 2018-08-27 17:58:41 -0700 | [diff] [blame] | 603 | KeyButtonDrawable backIcon = mBackIcon; |
Matthew Ng | ec5b841 | 2018-08-22 10:45:08 -0700 | [diff] [blame] | 604 | orientBackButton(backIcon); |
Matthew Ng | d6865ba | 2018-08-27 17:58:41 -0700 | [diff] [blame] | 605 | KeyButtonDrawable homeIcon = mHomeDefaultIcon; |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 606 | if (!mUseCarModeUi) { |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 607 | orientHomeButton(homeIcon); |
| 608 | } |
| 609 | getHomeButton().setImageDrawable(homeIcon); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 610 | getBackButton().setImageDrawable(backIcon); |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 611 | |
Jorim Jaggi | d30d95d | 2016-02-17 20:27:22 -0800 | [diff] [blame] | 612 | updateRecentsIcon(); |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 613 | |
Mike Digman | a48cf19 | 2018-02-12 17:52:48 -0800 | [diff] [blame] | 614 | // Update IME button visibility, a11y and rotate button always overrides the appearance |
Tracy Zhou | efc3466 | 2019-04-22 13:37:12 -0700 | [diff] [blame] | 615 | mContextualButtonGroup.setButtonVisibility(R.id.ime_switcher, |
Matthew Ng | 25593cc | 2018-09-12 16:05:41 -0700 | [diff] [blame] | 616 | (mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_IME_SHOWN) != 0); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 617 | |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 618 | mBarTransitions.reapplyDarkIntensity(); |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 619 | |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 620 | boolean disableHome = isGesturalMode(mNavBarMode) |
Winson Chung | e108b67 | 2019-03-06 16:11:28 -0800 | [diff] [blame] | 621 | || ((mDisabledFlags & View.STATUS_BAR_DISABLE_HOME) != 0); |
Sriram Viswanathan | 469caae | 2016-03-22 13:11:50 -0700 | [diff] [blame] | 622 | |
Jeff Chang | 2aaa91a | 2018-11-08 18:04:16 +0800 | [diff] [blame] | 623 | // Always disable recents when alternate car mode UI is active and for secondary displays. |
| 624 | boolean disableRecent = isRecentsButtonDisabled(); |
Charles He | e57ff81 | 2017-10-26 10:01:35 +0100 | [diff] [blame] | 625 | |
Sunny Goyal | be4e054 | 2019-08-08 16:36:14 -0700 | [diff] [blame] | 626 | // Disable the home handle if both hone and recents are disabled |
| 627 | boolean disableHomeHandle = disableRecent |
| 628 | && ((mDisabledFlags & View.STATUS_BAR_DISABLE_HOME) != 0); |
| 629 | |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 630 | boolean disableBack = !useAltBack && (isGesturalMode(mNavBarMode) |
Matthew Ng | f03c3a6 | 2019-04-03 13:52:57 -0700 | [diff] [blame] | 631 | || ((mDisabledFlags & View.STATUS_BAR_DISABLE_BACK) != 0)); |
Daniel Sandler | 029d587 | 2011-09-12 00:58:58 -0400 | [diff] [blame] | 632 | |
Matthew Ng | 87cbf34 | 2018-02-15 12:21:18 -0800 | [diff] [blame] | 633 | // When screen pinning, don't hide back and home when connected service or back and |
| 634 | // recents buttons when disconnected from launcher service in screen pinning mode, |
| 635 | // as they are used for exiting. |
Matthew Ng | 6ff33b7 | 2018-02-27 13:47:38 -0800 | [diff] [blame] | 636 | final boolean pinningActive = ActivityManagerWrapper.getInstance().isScreenPinningActive(); |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 637 | if (mOverviewProxyService.isEnabled()) { |
Winson Chung | 30c6260 | 2019-05-09 13:34:48 -0700 | [diff] [blame] | 638 | // Force disable recents when not in legacy mode |
| 639 | disableRecent |= !QuickStepContract.isLegacyMode(mNavBarMode); |
Tracy Zhou | 63b5047 | 2019-07-01 15:27:02 -0700 | [diff] [blame] | 640 | if (pinningActive && !QuickStepContract.isGesturalMode(mNavBarMode)) { |
Matthew Ng | 87cbf34 | 2018-02-15 12:21:18 -0800 | [diff] [blame] | 641 | disableBack = disableHome = false; |
Matthew Ng | 87cbf34 | 2018-02-15 12:21:18 -0800 | [diff] [blame] | 642 | } |
Matthew Ng | 6ff33b7 | 2018-02-27 13:47:38 -0800 | [diff] [blame] | 643 | } else if (pinningActive) { |
Matthew Ng | 87cbf34 | 2018-02-15 12:21:18 -0800 | [diff] [blame] | 644 | disableBack = disableRecent = false; |
Matthew Ng | dc79e5c | 2017-12-14 17:37:35 -0800 | [diff] [blame] | 645 | } |
Charles He | e57ff81 | 2017-10-26 10:01:35 +0100 | [diff] [blame] | 646 | |
Winson Chung | e108b67 | 2019-03-06 16:11:28 -0800 | [diff] [blame] | 647 | ViewGroup navButtons = getCurrentView().findViewById(R.id.nav_buttons); |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 648 | if (navButtons != null) { |
| 649 | LayoutTransition lt = navButtons.getLayoutTransition(); |
John Spurlock | 1bbd49d | 2012-10-19 11:09:32 -0400 | [diff] [blame] | 650 | if (lt != null) { |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 651 | if (!lt.getTransitionListeners().contains(mTransitionListener)) { |
| 652 | lt.addTransitionListener(mTransitionListener); |
| 653 | } |
John Spurlock | 1bbd49d | 2012-10-19 11:09:32 -0400 | [diff] [blame] | 654 | } |
| 655 | } |
| 656 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 657 | getBackButton().setVisibility(disableBack ? View.INVISIBLE : View.VISIBLE); |
Jason Monk | 188908f | 2016-01-22 10:23:51 -0500 | [diff] [blame] | 658 | getHomeButton().setVisibility(disableHome ? View.INVISIBLE : View.VISIBLE); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 659 | getRecentsButton().setVisibility(disableRecent ? View.INVISIBLE : View.VISIBLE); |
Sunny Goyal | be4e054 | 2019-08-08 16:36:14 -0700 | [diff] [blame] | 660 | getHomeHandle().setVisibility(disableHomeHandle ? View.INVISIBLE : View.VISIBLE); |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 661 | } |
| 662 | |
Jeff Chang | 2aaa91a | 2018-11-08 18:04:16 +0800 | [diff] [blame] | 663 | @VisibleForTesting |
| 664 | boolean isRecentsButtonDisabled() { |
| 665 | return mUseCarModeUi || !isOverviewEnabled() |
| 666 | || getContext().getDisplayId() != Display.DEFAULT_DISPLAY; |
| 667 | } |
| 668 | |
| 669 | private Display getContextDisplay() { |
| 670 | return getContext().getDisplay(); |
| 671 | } |
| 672 | |
Jorim Jaggi | 37c1180 | 2015-08-18 20:27:54 -0700 | [diff] [blame] | 673 | public void setLayoutTransitionsEnabled(boolean enabled) { |
| 674 | mLayoutTransitionsEnabled = enabled; |
| 675 | updateLayoutTransitionsEnabled(); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 676 | } |
| 677 | |
Jorim Jaggi | 37c1180 | 2015-08-18 20:27:54 -0700 | [diff] [blame] | 678 | public void setWakeAndUnlocking(boolean wakeAndUnlocking) { |
| 679 | setUseFadingAnimations(wakeAndUnlocking); |
| 680 | mWakeAndUnlocking = wakeAndUnlocking; |
| 681 | updateLayoutTransitionsEnabled(); |
| 682 | } |
| 683 | |
| 684 | private void updateLayoutTransitionsEnabled() { |
| 685 | boolean enabled = !mWakeAndUnlocking && mLayoutTransitionsEnabled; |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 686 | ViewGroup navButtons = (ViewGroup) getCurrentView().findViewById(R.id.nav_buttons); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 687 | LayoutTransition lt = navButtons.getLayoutTransition(); |
Julia Reynolds | 8478aba | 2015-07-31 09:17:20 -0400 | [diff] [blame] | 688 | if (lt != null) { |
| 689 | if (enabled) { |
| 690 | lt.enableTransitionType(LayoutTransition.APPEARING); |
| 691 | lt.enableTransitionType(LayoutTransition.DISAPPEARING); |
| 692 | lt.enableTransitionType(LayoutTransition.CHANGE_APPEARING); |
| 693 | lt.enableTransitionType(LayoutTransition.CHANGE_DISAPPEARING); |
| 694 | } else { |
| 695 | lt.disableTransitionType(LayoutTransition.APPEARING); |
| 696 | lt.disableTransitionType(LayoutTransition.DISAPPEARING); |
| 697 | lt.disableTransitionType(LayoutTransition.CHANGE_APPEARING); |
| 698 | lt.disableTransitionType(LayoutTransition.CHANGE_DISAPPEARING); |
| 699 | } |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 700 | } |
| 701 | } |
| 702 | |
| 703 | private void setUseFadingAnimations(boolean useFadingAnimations) { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 704 | WindowManager.LayoutParams lp = (WindowManager.LayoutParams) ((ViewGroup) getParent()) |
| 705 | .getLayoutParams(); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 706 | if (lp != null) { |
| 707 | boolean old = lp.windowAnimations != 0; |
| 708 | if (!old && useFadingAnimations) { |
| 709 | lp.windowAnimations = R.style.Animation_NavigationBarFadeIn; |
| 710 | } else if (old && !useFadingAnimations) { |
| 711 | lp.windowAnimations = 0; |
| 712 | } else { |
| 713 | return; |
| 714 | } |
| 715 | WindowManager wm = (WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 716 | wm.updateViewLayout((View) getParent(), lp); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 717 | } |
| 718 | } |
| 719 | |
Winson Chung | 5b6a1fe | 2019-07-26 16:38:08 -0700 | [diff] [blame] | 720 | public void onStatusBarPanelStateChanged() { |
Matthew Ng | 78f88d1 | 2018-01-23 12:39:55 -0800 | [diff] [blame] | 721 | updateSlippery(); |
Winson Chung | 56a667b | 2019-07-30 13:51:27 -0700 | [diff] [blame] | 722 | updatePanelSystemUiStateFlags(); |
Winson Chung | a706700 | 2019-05-07 11:50:42 -0700 | [diff] [blame] | 723 | } |
| 724 | |
Winson Chung | 56a667b | 2019-07-30 13:51:27 -0700 | [diff] [blame] | 725 | public void updateDisabledSystemUiStateFlags() { |
Winson Chung | a706700 | 2019-05-07 11:50:42 -0700 | [diff] [blame] | 726 | int displayId = mContext.getDisplayId(); |
| 727 | mOverviewProxyService.setSystemUiStateFlag(SYSUI_STATE_SCREEN_PINNING, |
| 728 | ActivityManagerWrapper.getInstance().isScreenPinningActive(), displayId); |
| 729 | mOverviewProxyService.setSystemUiStateFlag(SYSUI_STATE_OVERVIEW_DISABLED, |
| 730 | (mDisabledFlags & View.STATUS_BAR_DISABLE_RECENT) != 0, displayId); |
| 731 | mOverviewProxyService.setSystemUiStateFlag(SYSUI_STATE_HOME_DISABLED, |
| 732 | (mDisabledFlags & View.STATUS_BAR_DISABLE_HOME) != 0, displayId); |
Winson Chung | cb6454e | 2019-07-23 09:58:47 -0700 | [diff] [blame] | 733 | mOverviewProxyService.setSystemUiStateFlag(SYSUI_STATE_SEARCH_DISABLED, |
| 734 | (mDisabledFlags & View.STATUS_BAR_DISABLE_SEARCH) != 0, displayId); |
Winson Chung | 56a667b | 2019-07-30 13:51:27 -0700 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | public void updatePanelSystemUiStateFlags() { |
| 738 | int displayId = mContext.getDisplayId(); |
Winson Chung | a706700 | 2019-05-07 11:50:42 -0700 | [diff] [blame] | 739 | if (mPanelView != null) { |
| 740 | mOverviewProxyService.setSystemUiStateFlag(SYSUI_STATE_NOTIFICATION_PANEL_EXPANDED, |
| 741 | mPanelView.isFullyExpanded() && !mPanelView.isInSettings(), displayId); |
Winson Chung | 5b6a1fe | 2019-07-26 16:38:08 -0700 | [diff] [blame] | 742 | mOverviewProxyService.setSystemUiStateFlag(SYSUI_STATE_QUICK_SETTINGS_EXPANDED, |
| 743 | mPanelView.isInSettings(), displayId); |
Winson Chung | a706700 | 2019-05-07 11:50:42 -0700 | [diff] [blame] | 744 | } |
Matthew Ng | 78f88d1 | 2018-01-23 12:39:55 -0800 | [diff] [blame] | 745 | } |
| 746 | |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 747 | public void updateStates() { |
Matthew Ng | 44b1450 | 2018-05-04 11:10:14 -0700 | [diff] [blame] | 748 | final boolean showSwipeUpUI = mOverviewProxyService.shouldShowSwipeUpUI(); |
Mike Digman | f77fb91 | 2018-05-21 11:21:30 -0700 | [diff] [blame] | 749 | |
| 750 | if (mNavigationInflaterView != null) { |
| 751 | // Reinflate the navbar if needed, no-op unless the swipe up state changes |
| 752 | mNavigationInflaterView.onLikelyDefaultLayoutChange(); |
| 753 | } |
| 754 | |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 755 | updateSlippery(); |
Winson Chung | 770d7e9 | 2018-03-20 17:51:39 -0700 | [diff] [blame] | 756 | reloadNavIcons(); |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 757 | updateNavButtonIcons(); |
Winson Chung | f9e3027 | 2018-03-26 17:25:36 -0700 | [diff] [blame] | 758 | setUpSwipeUpOnboarding(isQuickStepSwipeUpEnabled()); |
Matthew Ng | 44b1450 | 2018-05-04 11:10:14 -0700 | [diff] [blame] | 759 | WindowManagerWrapper.getInstance().setNavBarVirtualKeyHapticFeedbackEnabled(!showSwipeUpUI); |
| 760 | getHomeButton().setAccessibilityDelegate( |
| 761 | showSwipeUpUI ? mQuickStepAccessibilityDelegate : null); |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 762 | } |
| 763 | |
Matthew Ng | 90ef063 | 2018-08-15 13:53:15 -0700 | [diff] [blame] | 764 | /** |
| 765 | * Updates the {@link WindowManager.LayoutParams.FLAG_SLIPPERY} state dependent on if swipe up |
| 766 | * is enabled, or the notifications is fully opened without being in an animated state. If |
| 767 | * slippery is enabled, touch events will leave the nav bar window and enter into the fullscreen |
| 768 | * app/home window, if not nav bar will receive a cancelled touch event once gesture leaves bar. |
| 769 | */ |
Matthew Ng | 472d3e4 | 2018-06-14 15:16:55 -0700 | [diff] [blame] | 770 | public void updateSlippery() { |
Matthew Ng | 90ef063 | 2018-08-15 13:53:15 -0700 | [diff] [blame] | 771 | setSlippery(!isQuickStepSwipeUpEnabled() || |
| 772 | (mPanelView.isFullyExpanded() && !mPanelView.isCollapsing())); |
Matthew Ng | 78f88d1 | 2018-01-23 12:39:55 -0800 | [diff] [blame] | 773 | } |
| 774 | |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 775 | private void setSlippery(boolean slippery) { |
Matthew Ng | b831fb4 | 2019-01-30 11:20:48 -0800 | [diff] [blame] | 776 | setWindowFlag(WindowManager.LayoutParams.FLAG_SLIPPERY, slippery); |
| 777 | } |
| 778 | |
Matthew Ng | b831fb4 | 2019-01-30 11:20:48 -0800 | [diff] [blame] | 779 | private void setWindowFlag(int flags, boolean enable) { |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 780 | final ViewGroup navbarView = ((ViewGroup) getParent()); |
Matthew Ng | b55c02c | 2019-02-15 16:20:31 -0800 | [diff] [blame] | 781 | if (navbarView == null) { |
| 782 | return; |
| 783 | } |
Matthew Ng | b831fb4 | 2019-01-30 11:20:48 -0800 | [diff] [blame] | 784 | WindowManager.LayoutParams lp = (WindowManager.LayoutParams) navbarView.getLayoutParams(); |
| 785 | if (lp == null || enable == ((lp.flags & flags) != 0)) { |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 786 | return; |
| 787 | } |
Matthew Ng | b831fb4 | 2019-01-30 11:20:48 -0800 | [diff] [blame] | 788 | if (enable) { |
| 789 | lp.flags |= flags; |
| 790 | } else { |
| 791 | lp.flags &= ~flags; |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 792 | } |
Matthew Ng | b831fb4 | 2019-01-30 11:20:48 -0800 | [diff] [blame] | 793 | WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); |
| 794 | wm.updateViewLayout(navbarView, lp); |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 795 | } |
| 796 | |
Winson Chung | 1aa24b9 | 2019-04-24 15:17:33 -0700 | [diff] [blame] | 797 | @Override |
| 798 | public void onNavigationModeChanged(int mode) { |
Winson Chung | 316f673 | 2019-06-14 09:31:46 -0700 | [diff] [blame] | 799 | Context curUserCtx = Dependency.get(NavigationModeController.class).getCurrentUserContext(); |
Winson Chung | 1aa24b9 | 2019-04-24 15:17:33 -0700 | [diff] [blame] | 800 | mNavBarMode = mode; |
| 801 | mBarTransitions.onNavigationModeChanged(mNavBarMode); |
Winson Chung | 316f673 | 2019-06-14 09:31:46 -0700 | [diff] [blame] | 802 | mEdgeBackGestureHandler.onNavigationModeChanged(mNavBarMode, curUserCtx); |
Winson Chung | 1aa24b9 | 2019-04-24 15:17:33 -0700 | [diff] [blame] | 803 | mRecentsOnboarding.onNavigationModeChanged(mNavBarMode); |
Tracy Zhou | efc3466 | 2019-04-22 13:37:12 -0700 | [diff] [blame] | 804 | getRotateSuggestionButton().onNavigationModeChanged(mNavBarMode); |
Matthew Ng | b55c02c | 2019-02-15 16:20:31 -0800 | [diff] [blame] | 805 | |
| 806 | // Color adaption is tied with showing home handle, only avaliable if visible |
Winson Chung | 1aa24b9 | 2019-04-24 15:17:33 -0700 | [diff] [blame] | 807 | mTintController.onNavigationModeChanged(mNavBarMode); |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 808 | if (isGesturalMode(mNavBarMode)) { |
Winson Chung | 775d287 | 2019-03-27 14:14:01 -0700 | [diff] [blame] | 809 | mTintController.start(); |
Matthew Ng | b55c02c | 2019-02-15 16:20:31 -0800 | [diff] [blame] | 810 | } else { |
Winson Chung | 775d287 | 2019-03-27 14:14:01 -0700 | [diff] [blame] | 811 | mTintController.stop(); |
Matthew Ng | b55c02c | 2019-02-15 16:20:31 -0800 | [diff] [blame] | 812 | } |
| 813 | } |
| 814 | |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 815 | public void setAccessibilityButtonState(final boolean visible, final boolean longClickable) { |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 816 | mLongClickableAccessibilityButton = longClickable; |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 817 | getAccessibilityButton().setLongClickable(longClickable); |
Tracy Zhou | efc3466 | 2019-04-22 13:37:12 -0700 | [diff] [blame] | 818 | mContextualButtonGroup.setButtonVisibility(R.id.accessibility_button, visible); |
Mike Digman | a48cf19 | 2018-02-12 17:52:48 -0800 | [diff] [blame] | 819 | } |
| 820 | |
Tracy Zhou | 1ac592c | 2018-07-25 13:47:37 -0700 | [diff] [blame] | 821 | void hideRecentsOnboarding() { |
| 822 | mRecentsOnboarding.hide(true); |
| 823 | } |
| 824 | |
Jim Miller | 960892c | 2012-05-23 15:50:04 -0700 | [diff] [blame] | 825 | @Override |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 826 | public void onFinishInflate() { |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 827 | mNavigationInflaterView = findViewById(R.id.navigation_inflater); |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 828 | mNavigationInflaterView.setButtonDispatchers(mButtonDispatchers); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 829 | |
| 830 | getImeSwitchButton().setOnClickListener(mImeSwitcherClickListener); |
Selim Cinek | 17a327a | 2014-08-25 15:03:48 +0200 | [diff] [blame] | 831 | |
Jason Monk | 32e3bb5 | 2017-07-27 12:35:41 -0400 | [diff] [blame] | 832 | DockedStackExistsListener.register(mDockedListener); |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 833 | updateOrientationViews(); |
Matthew Ng | 25593cc | 2018-09-12 16:05:41 -0700 | [diff] [blame] | 834 | reloadNavIcons(); |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 835 | } |
| 836 | |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 837 | @Override |
| 838 | protected void onDraw(Canvas canvas) { |
Matthew Ng | 603b329 | 2018-03-30 17:15:39 -0700 | [diff] [blame] | 839 | mDeadZone.onDraw(canvas); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 840 | super.onDraw(canvas); |
| 841 | } |
| 842 | |
| 843 | @Override |
| 844 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 845 | super.onLayout(changed, left, top, right, bottom); |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 846 | |
| 847 | mActiveRegion.setEmpty(); |
| 848 | updateButtonLocation(getBackButton(), mBackButtonBounds, true); |
| 849 | updateButtonLocation(getHomeButton(), mHomeButtonBounds, false); |
| 850 | updateButtonLocation(getRecentsButton(), mRecentsButtonBounds, false); |
| 851 | updateButtonLocation(getRotateSuggestionButton(), mRotationButtonBounds, true); |
| 852 | // TODO: Handle button visibility changes |
| 853 | mOverviewProxyService.onActiveNavBarRegionChanges(mActiveRegion); |
Tracy Zhou | 559d97c | 2018-04-07 23:54:46 -0700 | [diff] [blame] | 854 | mRecentsOnboarding.setNavBarHeight(getMeasuredHeight()); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 855 | } |
| 856 | |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 857 | private void updateButtonLocation(ButtonDispatcher button, Rect buttonBounds, |
| 858 | boolean isActive) { |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 859 | View view = button.getCurrentView(); |
| 860 | if (view == null) { |
| 861 | buttonBounds.setEmpty(); |
| 862 | return; |
| 863 | } |
Matthew Ng | 3b7e390 | 2018-03-22 16:06:09 -0700 | [diff] [blame] | 864 | // Temporarily reset the translation back to origin to get the position in window |
| 865 | final float posX = view.getTranslationX(); |
| 866 | final float posY = view.getTranslationY(); |
| 867 | view.setTranslationX(0); |
| 868 | view.setTranslationY(0); |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 869 | |
| 870 | if (isActive) { |
| 871 | view.getLocationOnScreen(mTmpPosition); |
| 872 | buttonBounds.set(mTmpPosition[0], mTmpPosition[1], |
| 873 | mTmpPosition[0] + view.getMeasuredWidth(), |
| 874 | mTmpPosition[1] + view.getMeasuredHeight()); |
| 875 | mActiveRegion.op(buttonBounds, Op.UNION); |
| 876 | } |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 877 | view.getLocationInWindow(mTmpPosition); |
| 878 | buttonBounds.set(mTmpPosition[0], mTmpPosition[1], |
| 879 | mTmpPosition[0] + view.getMeasuredWidth(), |
| 880 | mTmpPosition[1] + view.getMeasuredHeight()); |
Matthew Ng | 3b7e390 | 2018-03-22 16:06:09 -0700 | [diff] [blame] | 881 | view.setTranslationX(posX); |
| 882 | view.setTranslationY(posY); |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 883 | } |
| 884 | |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 885 | private void updateOrientationViews() { |
| 886 | mHorizontal = findViewById(R.id.horizontal); |
| 887 | mVertical = findViewById(R.id.vertical); |
Jason Monk | 9a6552d | 2016-05-20 11:21:59 -0400 | [diff] [blame] | 888 | |
Jason Monk | 199a2d0 | 2017-07-28 11:08:27 -0400 | [diff] [blame] | 889 | updateCurrentView(); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 890 | } |
| 891 | |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 892 | boolean needsReorient(int rotation) { |
Adrian Roos | a98b32c | 2016-08-11 10:41:08 -0700 | [diff] [blame] | 893 | return mCurrentRotation != rotation; |
Adrian Roos | 090b7d8 | 2016-08-02 18:36:12 -0700 | [diff] [blame] | 894 | } |
| 895 | |
Jason Monk | 199a2d0 | 2017-07-28 11:08:27 -0400 | [diff] [blame] | 896 | private void updateCurrentView() { |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 897 | resetViews(); |
| 898 | mCurrentView = mIsVertical ? mVertical : mHorizontal; |
Daniel Sandler | 5c8da94 | 2011-06-28 00:29:04 -0400 | [diff] [blame] | 899 | mCurrentView.setVisibility(View.VISIBLE); |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 900 | mNavigationInflaterView.setVertical(mIsVertical); |
| 901 | mCurrentRotation = getContextDisplay().getRotation(); |
| 902 | mNavigationInflaterView.setAlternativeOrder(mCurrentRotation == Surface.ROTATION_90); |
Matthew Ng | 1efc9c3 | 2018-04-11 18:13:56 -0700 | [diff] [blame] | 903 | mNavigationInflaterView.updateButtonDispatchersCurrentView(); |
Jorim Jaggi | 37c1180 | 2015-08-18 20:27:54 -0700 | [diff] [blame] | 904 | updateLayoutTransitionsEnabled(); |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 905 | } |
| 906 | |
| 907 | private void resetViews() { |
| 908 | mHorizontal.setVisibility(View.GONE); |
| 909 | mVertical.setVisibility(View.GONE); |
Jason Monk | 9a6552d | 2016-05-20 11:21:59 -0400 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | private void updateRecentsIcon() { |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 913 | mDockedIcon.setRotation(mDockedStackExists && mIsVertical ? 90 : 0); |
Jason Monk | 9a6552d | 2016-05-20 11:21:59 -0400 | [diff] [blame] | 914 | getRecentsButton().setImageDrawable(mDockedStackExists ? mDockedIcon : mRecentIcon); |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 915 | mBarTransitions.reapplyDarkIntensity(); |
Jason Monk | 9a6552d | 2016-05-20 11:21:59 -0400 | [diff] [blame] | 916 | } |
| 917 | |
Matthew Ng | 20136e6 | 2018-05-30 12:20:31 -0700 | [diff] [blame] | 918 | public void showPinningEnterExitToast(boolean entering) { |
| 919 | if (entering) { |
| 920 | mScreenPinningNotify.showPinningStartToast(); |
| 921 | } else { |
| 922 | mScreenPinningNotify.showPinningExitToast(); |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | public void showPinningEscapeToast() { |
| 927 | mScreenPinningNotify.showEscapeToast(isRecentsButtonVisible()); |
| 928 | } |
| 929 | |
Jason Monk | 9a6552d | 2016-05-20 11:21:59 -0400 | [diff] [blame] | 930 | public boolean isVertical() { |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 931 | return mIsVertical; |
Jason Monk | 9a6552d | 2016-05-20 11:21:59 -0400 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | public void reorient() { |
Jason Monk | 199a2d0 | 2017-07-28 11:08:27 -0400 | [diff] [blame] | 935 | updateCurrentView(); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 936 | |
Siarhei Vishniakou | fdb4277 | 2017-06-29 10:32:11 -0700 | [diff] [blame] | 937 | ((NavigationBarFrame) getRootView()).setDeadZone(mDeadZone); |
Matthew Ng | 603b329 | 2018-03-30 17:15:39 -0700 | [diff] [blame] | 938 | mDeadZone.onConfigurationChanged(mCurrentRotation); |
Daniel Sandler | c26185b | 2012-08-29 15:49:53 -0400 | [diff] [blame] | 939 | |
Daniel Sandler | 6da2b76 | 2011-09-14 16:04:59 -0400 | [diff] [blame] | 940 | // force the low profile & disabled states into compliance |
Adrian Roos | 8a8ffd4 | 2015-05-26 18:30:37 -0700 | [diff] [blame] | 941 | mBarTransitions.init(); |
Daniel Sandler | 6da2b76 | 2011-09-14 16:04:59 -0400 | [diff] [blame] | 942 | |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 943 | if (DEBUG) { |
Adrian Roos | a98b32c | 2016-08-11 10:41:08 -0700 | [diff] [blame] | 944 | Log.d(TAG, "reorient(): rot=" + mCurrentRotation); |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 945 | } |
Michael Jurka | a5d0ddb | 2012-03-09 17:41:41 -0800 | [diff] [blame] | 946 | |
Matthew Ng | 5fd8041 | 2018-02-14 14:40:31 -0800 | [diff] [blame] | 947 | // Resolve layout direction if not resolved since components changing layout direction such |
| 948 | // as changing languages will recreate this view and the direction will be resolved later |
| 949 | if (!isLayoutDirectionResolved()) { |
| 950 | resolveLayoutDirection(); |
| 951 | } |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 952 | updateNavButtonIcons(); |
Xiaohui Chen | 9efa5de | 2016-11-22 10:34:38 -0800 | [diff] [blame] | 953 | |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 954 | getHomeButton().setVertical(mIsVertical); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 955 | } |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 956 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 957 | @Override |
Matthew Ng | ff63812 | 2019-03-21 17:17:18 -0700 | [diff] [blame] | 958 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 959 | int w = MeasureSpec.getSize(widthMeasureSpec); |
| 960 | int h = MeasureSpec.getSize(heightMeasureSpec); |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 961 | if (DEBUG) Log.d(TAG, String.format( |
Matthew Ng | ff63812 | 2019-03-21 17:17:18 -0700 | [diff] [blame] | 962 | "onMeasure: (%dx%d) old: (%dx%d)", w, h, getMeasuredWidth(), getMeasuredHeight())); |
Daniel Sandler | e03bc95 | 2012-04-27 16:11:22 -0400 | [diff] [blame] | 963 | |
Winson Chung | 4723b4e | 2019-03-25 16:49:36 -0700 | [diff] [blame] | 964 | final boolean newVertical = w > 0 && h > w |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 965 | && !isGesturalMode(mNavBarMode); |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 966 | if (newVertical != mIsVertical) { |
| 967 | mIsVertical = newVertical; |
| 968 | if (DEBUG) { |
Matthew Ng | ff63812 | 2019-03-21 17:17:18 -0700 | [diff] [blame] | 969 | Log.d(TAG, String.format("onMeasure: h=%d, w=%d, vert=%s", h, w, |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 970 | mIsVertical ? "y" : "n")); |
| 971 | } |
Daniel Sandler | e03bc95 | 2012-04-27 16:11:22 -0400 | [diff] [blame] | 972 | reorient(); |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 973 | notifyVerticalChangedListener(newVertical); |
Daniel Sandler | e03bc95 | 2012-04-27 16:11:22 -0400 | [diff] [blame] | 974 | } |
Winson Chung | 775d287 | 2019-03-27 14:14:01 -0700 | [diff] [blame] | 975 | |
Tracy Zhou | 24fd028 | 2019-05-20 14:40:38 -0700 | [diff] [blame] | 976 | if (isGesturalMode(mNavBarMode)) { |
Winson Chung | 775d287 | 2019-03-27 14:14:01 -0700 | [diff] [blame] | 977 | // Update the nav bar background to match the height of the visible nav bar |
| 978 | int height = mIsVertical |
| 979 | ? getResources().getDimensionPixelSize( |
| 980 | com.android.internal.R.dimen.navigation_bar_height_landscape) |
| 981 | : getResources().getDimensionPixelSize( |
| 982 | com.android.internal.R.dimen.navigation_bar_height); |
| 983 | int frameHeight = getResources().getDimensionPixelSize( |
| 984 | com.android.internal.R.dimen.navigation_bar_frame_height); |
| 985 | mBarTransitions.setBackgroundFrame(new Rect(0, frameHeight - height, w, h)); |
| 986 | } |
| 987 | |
Matthew Ng | ff63812 | 2019-03-21 17:17:18 -0700 | [diff] [blame] | 988 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 989 | } |
| 990 | |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 991 | private void notifyVerticalChangedListener(boolean newVertical) { |
| 992 | if (mOnVerticalChangedListener != null) { |
| 993 | mOnVerticalChangedListener.onVerticalChanged(newVertical); |
| 994 | } |
| 995 | } |
| 996 | |
Selim Cinek | 17a327a | 2014-08-25 15:03:48 +0200 | [diff] [blame] | 997 | @Override |
| 998 | protected void onConfigurationChanged(Configuration newConfig) { |
| 999 | super.onConfigurationChanged(newConfig); |
Matthew Ng | 8c056c1 | 2018-10-15 15:16:46 -0700 | [diff] [blame] | 1000 | mTmpLastConfiguration.updateFrom(mConfiguration); |
| 1001 | mConfiguration.updateFrom(newConfig); |
| 1002 | boolean uiCarModeChanged = updateCarMode(); |
Matthew Ng | 8c056c1 | 2018-10-15 15:16:46 -0700 | [diff] [blame] | 1003 | updateIcons(mTmpLastConfiguration); |
Winson | fde2e6a | 2016-03-22 16:03:10 -0700 | [diff] [blame] | 1004 | updateRecentsIcon(); |
Matthew Ng | 8c056c1 | 2018-10-15 15:16:46 -0700 | [diff] [blame] | 1005 | mRecentsOnboarding.onConfigurationChanged(mConfiguration); |
| 1006 | if (uiCarModeChanged || mTmpLastConfiguration.densityDpi != mConfiguration.densityDpi |
| 1007 | || mTmpLastConfiguration.getLayoutDirection() != mConfiguration.getLayoutDirection()) { |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 1008 | // If car mode or density changes, we need to reset the icons. |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 1009 | updateNavButtonIcons(); |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 1010 | } |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | /** |
| 1014 | * If the configuration changed, update the carmode and return that it was updated. |
| 1015 | */ |
Matthew Ng | 8c056c1 | 2018-10-15 15:16:46 -0700 | [diff] [blame] | 1016 | private boolean updateCarMode() { |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 1017 | boolean uiCarModeChanged = false; |
Matthew Ng | 8c056c1 | 2018-10-15 15:16:46 -0700 | [diff] [blame] | 1018 | if (mConfiguration != null) { |
| 1019 | int uiMode = mConfiguration.uiMode & Configuration.UI_MODE_TYPE_MASK; |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 1020 | final boolean isCarMode = (uiMode == Configuration.UI_MODE_TYPE_CAR); |
| 1021 | |
| 1022 | if (isCarMode != mInCarMode) { |
| 1023 | mInCarMode = isCarMode; |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 1024 | if (ALTERNATE_CAR_MODE_UI) { |
| 1025 | mUseCarModeUi = isCarMode; |
| 1026 | uiCarModeChanged = true; |
| 1027 | } else { |
| 1028 | // Don't use car mode behavior if ALTERNATE_CAR_MODE_UI not set. |
| 1029 | mUseCarModeUi = false; |
| 1030 | } |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 1031 | } |
| 1032 | } |
| 1033 | return uiCarModeChanged; |
Selim Cinek | 17a327a | 2014-08-25 15:03:48 +0200 | [diff] [blame] | 1034 | } |
| 1035 | |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1036 | private String getResourceName(int resId) { |
| 1037 | if (resId != 0) { |
John Spurlock | 0153478 | 2014-01-13 11:59:22 -0500 | [diff] [blame] | 1038 | final android.content.res.Resources res = getContext().getResources(); |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1039 | try { |
| 1040 | return res.getResourceName(resId); |
| 1041 | } catch (android.content.res.Resources.NotFoundException ex) { |
| 1042 | return "(unknown)"; |
| 1043 | } |
| 1044 | } else { |
| 1045 | return "(null)"; |
| 1046 | } |
| 1047 | } |
| 1048 | |
| 1049 | private static String visibilityToString(int vis) { |
| 1050 | switch (vis) { |
| 1051 | case View.INVISIBLE: |
| 1052 | return "INVISIBLE"; |
| 1053 | case View.GONE: |
| 1054 | return "GONE"; |
| 1055 | default: |
| 1056 | return "VISIBLE"; |
| 1057 | } |
| 1058 | } |
| 1059 | |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 1060 | @Override |
| 1061 | protected void onAttachedToWindow() { |
| 1062 | super.onAttachedToWindow(); |
Adrian Roos | 7e58a08 | 2018-03-09 16:40:56 +0100 | [diff] [blame] | 1063 | requestApplyInsets(); |
Siarhei Vishniakou | fdb4277 | 2017-06-29 10:32:11 -0700 | [diff] [blame] | 1064 | reorient(); |
Tracy Zhou | efc3466 | 2019-04-22 13:37:12 -0700 | [diff] [blame] | 1065 | onNavigationModeChanged(mNavBarMode); |
Winson Chung | f9e3027 | 2018-03-26 17:25:36 -0700 | [diff] [blame] | 1066 | setUpSwipeUpOnboarding(isQuickStepSwipeUpEnabled()); |
Tracy Zhou | cb0362a | 2019-06-18 10:59:11 -0700 | [diff] [blame] | 1067 | if (mRotationButtonController != null) { |
| 1068 | mRotationButtonController.registerListeners(); |
| 1069 | } |
Matthew Ng | b831fb4 | 2019-01-30 11:20:48 -0800 | [diff] [blame] | 1070 | |
Sunny Goyal | a6a5812 | 2019-04-02 10:20:29 -0700 | [diff] [blame] | 1071 | mEdgeBackGestureHandler.onNavBarAttached(); |
Tracy Zhou | efc3466 | 2019-04-22 13:37:12 -0700 | [diff] [blame] | 1072 | getViewTreeObserver().addOnComputeInternalInsetsListener(mOnComputeInternalInsetsListener); |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | @Override |
| 1076 | protected void onDetachedFromWindow() { |
| 1077 | super.onDetachedFromWindow(); |
Winson Chung | 1aa24b9 | 2019-04-24 15:17:33 -0700 | [diff] [blame] | 1078 | Dependency.get(NavigationModeController.class).removeListener(this); |
Tony Wickham | fb63fe8 | 2018-01-16 12:14:06 -0800 | [diff] [blame] | 1079 | setUpSwipeUpOnboarding(false); |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 1080 | for (int i = 0; i < mButtonDispatchers.size(); ++i) { |
| 1081 | mButtonDispatchers.valueAt(i).onDestroy(); |
| 1082 | } |
Tracy Zhou | cb0362a | 2019-06-18 10:59:11 -0700 | [diff] [blame] | 1083 | if (mRotationButtonController != null) { |
| 1084 | mRotationButtonController.unregisterListeners(); |
| 1085 | } |
| 1086 | |
Sunny Goyal | a6a5812 | 2019-04-02 10:20:29 -0700 | [diff] [blame] | 1087 | mEdgeBackGestureHandler.onNavBarDetached(); |
Tracy Zhou | efc3466 | 2019-04-22 13:37:12 -0700 | [diff] [blame] | 1088 | getViewTreeObserver().removeOnComputeInternalInsetsListener( |
| 1089 | mOnComputeInternalInsetsListener); |
Tony Wickham | fb63fe8 | 2018-01-16 12:14:06 -0800 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | private void setUpSwipeUpOnboarding(boolean connectedToOverviewProxy) { |
| 1093 | if (connectedToOverviewProxy) { |
Tony Wickham | 05c1f85 | 2018-02-06 12:32:54 -0800 | [diff] [blame] | 1094 | mRecentsOnboarding.onConnectedToLauncher(); |
Tony Wickham | fb63fe8 | 2018-01-16 12:14:06 -0800 | [diff] [blame] | 1095 | } else { |
Tony Wickham | 05c1f85 | 2018-02-06 12:32:54 -0800 | [diff] [blame] | 1096 | mRecentsOnboarding.onDisconnectedFromLauncher(); |
Tony Wickham | fb63fe8 | 2018-01-16 12:14:06 -0800 | [diff] [blame] | 1097 | } |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 1098 | } |
| 1099 | |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1100 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 1101 | pw.println("NavigationBarView {"); |
| 1102 | final Rect r = new Rect(); |
Jeff Brown | a8b9def | 2012-07-23 14:22:49 -0700 | [diff] [blame] | 1103 | final Point size = new Point(); |
Jeff Chang | 2aaa91a | 2018-11-08 18:04:16 +0800 | [diff] [blame] | 1104 | getContextDisplay().getRealSize(size); |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1105 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 1106 | pw.println(String.format(" this: " + StatusBar.viewInfo(this) |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1107 | + " " + visibilityToString(getVisibility()))); |
| 1108 | |
| 1109 | getWindowVisibleDisplayFrame(r); |
Jeff Brown | a8b9def | 2012-07-23 14:22:49 -0700 | [diff] [blame] | 1110 | final boolean offscreen = r.right > size.x || r.bottom > size.y; |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 1111 | pw.println(" window: " |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1112 | + r.toShortString() |
| 1113 | + " " + visibilityToString(getWindowVisibility()) |
| 1114 | + (offscreen ? " OFFSCREEN!" : "")); |
| 1115 | |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 1116 | pw.println(String.format(" mCurrentView: id=%s (%dx%d) %s %f", |
Rakesh Iyer | f51fe4e | 2016-02-09 10:51:50 -0800 | [diff] [blame] | 1117 | getResourceName(getCurrentView().getId()), |
| 1118 | getCurrentView().getWidth(), getCurrentView().getHeight(), |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 1119 | visibilityToString(getCurrentView().getVisibility()), |
| 1120 | getCurrentView().getAlpha())); |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1121 | |
Sunny Goyal | ded62f0 | 2019-05-01 14:35:49 -0700 | [diff] [blame] | 1122 | pw.println(String.format(" disabled=0x%08x vertical=%s darkIntensity=%.2f", |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1123 | mDisabledFlags, |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 1124 | mIsVertical ? "true" : "false", |
Matthew Ng | eb0b094 | 2018-10-12 16:42:11 -0700 | [diff] [blame] | 1125 | getLightTransitionsController().getCurrentDarkIntensity())); |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1126 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 1127 | dumpButton(pw, "back", getBackButton()); |
| 1128 | dumpButton(pw, "home", getHomeButton()); |
| 1129 | dumpButton(pw, "rcnt", getRecentsButton()); |
Matthew Ng | 25593cc | 2018-09-12 16:05:41 -0700 | [diff] [blame] | 1130 | dumpButton(pw, "rota", getRotateSuggestionButton()); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 1131 | dumpButton(pw, "a11y", getAccessibilityButton()); |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1132 | |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1133 | pw.println(" }"); |
Matthew Ng | 25593cc | 2018-09-12 16:05:41 -0700 | [diff] [blame] | 1134 | |
| 1135 | mContextualButtonGroup.dump(pw); |
| 1136 | mRecentsOnboarding.dump(pw); |
Winson Chung | 775d287 | 2019-03-27 14:14:01 -0700 | [diff] [blame] | 1137 | mTintController.dump(pw); |
Winson Chung | 316f673 | 2019-06-14 09:31:46 -0700 | [diff] [blame] | 1138 | mEdgeBackGestureHandler.dump(pw); |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1139 | } |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 1140 | |
Adrian Roos | 7e58a08 | 2018-03-09 16:40:56 +0100 | [diff] [blame] | 1141 | @Override |
| 1142 | public WindowInsets onApplyWindowInsets(WindowInsets insets) { |
Selim Cinek | e50b121 | 2019-06-04 18:40:31 -0700 | [diff] [blame] | 1143 | int leftInset = insets.getSystemWindowInsetLeft(); |
| 1144 | int rightInset = insets.getSystemWindowInsetRight(); |
| 1145 | setPadding(leftInset, insets.getSystemWindowInsetTop(), rightInset, |
| 1146 | insets.getSystemWindowInsetBottom()); |
| 1147 | // we're passing the insets onto the gesture handler since the back arrow is only |
| 1148 | // conditionally added and doesn't always get all the insets. |
| 1149 | mEdgeBackGestureHandler.setInsets(leftInset, rightInset); |
Adrian Roos | 7e58a08 | 2018-03-09 16:40:56 +0100 | [diff] [blame] | 1150 | return super.onApplyWindowInsets(insets); |
| 1151 | } |
| 1152 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 1153 | private static void dumpButton(PrintWriter pw, String caption, ButtonDispatcher button) { |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 1154 | pw.print(" " + caption + ": "); |
| 1155 | if (button == null) { |
| 1156 | pw.print("null"); |
| 1157 | } else { |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 1158 | pw.print(visibilityToString(button.getVisibility()) |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 1159 | + " alpha=" + button.getAlpha() |
| 1160 | ); |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 1161 | } |
| 1162 | pw.println(); |
| 1163 | } |
| 1164 | |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 1165 | public interface OnVerticalChangedListener { |
| 1166 | void onVerticalChanged(boolean isVertical); |
| 1167 | } |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 1168 | |
Matthew Ng | ff63812 | 2019-03-21 17:17:18 -0700 | [diff] [blame] | 1169 | private final Consumer<Boolean> mDockedListener = exists -> post(() -> { |
Jason Monk | 32e3bb5 | 2017-07-27 12:35:41 -0400 | [diff] [blame] | 1170 | mDockedStackExists = exists; |
| 1171 | updateRecentsIcon(); |
| 1172 | }); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1173 | } |