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