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 | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 19 | import static android.view.MotionEvent.ACTION_DOWN; |
Tiger Huang | 44c0455 | 2018-11-29 20:06:45 +0800 | [diff] [blame] | 20 | import static android.view.WindowManagerPolicyConstants.NAV_BAR_INVALID; |
Matthew Ng | b831fb4 | 2019-01-30 11:20:48 -0800 | [diff] [blame] | 21 | import static android.view.WindowManagerPolicyConstants.NAV_BAR_LEFT; |
| 22 | import static android.view.WindowManagerPolicyConstants.NAV_BAR_RIGHT; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 23 | |
| 24 | import static com.android.systemui.shared.system.NavigationBarCompat.FLAG_DISABLE_QUICK_SCRUB; |
| 25 | import static com.android.systemui.shared.system.NavigationBarCompat.FLAG_SHOW_OVERVIEW_BUTTON; |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 26 | import static com.android.systemui.shared.system.NavigationBarCompat.HIT_TARGET_BACK; |
Matthew Ng | 472d3e4 | 2018-06-14 15:16:55 -0700 | [diff] [blame] | 27 | import static com.android.systemui.shared.system.NavigationBarCompat.HIT_TARGET_DEAD_ZONE; |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 28 | import static com.android.systemui.shared.system.NavigationBarCompat.HIT_TARGET_HOME; |
| 29 | import static com.android.systemui.shared.system.NavigationBarCompat.HIT_TARGET_NONE; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 30 | import static com.android.systemui.shared.system.NavigationBarCompat.HIT_TARGET_OVERVIEW; |
| 31 | import static com.android.systemui.shared.system.NavigationBarCompat.HIT_TARGET_ROTATION; |
Matthew Ng | b55c02c | 2019-02-15 16:20:31 -0800 | [diff] [blame] | 32 | import static com.android.systemui.statusbar.phone.NavigationBarInflaterView.NAV_BAR_VIEWS; |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 33 | |
John Spurlock | 1bbd49d | 2012-10-19 11:09:32 -0400 | [diff] [blame] | 34 | import android.animation.LayoutTransition; |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 35 | import android.animation.LayoutTransition.TransitionListener; |
| 36 | import android.animation.ObjectAnimator; |
Matthew Ng | ca4592b | 2018-08-06 14:12:37 -0700 | [diff] [blame] | 37 | import android.animation.PropertyValuesHolder; |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 38 | import android.animation.TimeInterpolator; |
| 39 | import android.animation.ValueAnimator; |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 40 | import android.annotation.DrawableRes; |
Matthew Ng | b831fb4 | 2019-01-30 11:20:48 -0800 | [diff] [blame] | 41 | import android.annotation.IntDef; |
| 42 | import android.annotation.SuppressLint; |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 43 | import android.app.StatusBarManager; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 44 | import android.content.Context; |
Selim Cinek | 17a327a | 2014-08-25 15:03:48 +0200 | [diff] [blame] | 45 | import android.content.res.Configuration; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 46 | import android.graphics.Canvas; |
Jeff Brown | a8b9def | 2012-07-23 14:22:49 -0700 | [diff] [blame] | 47 | import android.graphics.Point; |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 48 | import android.graphics.Rect; |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 49 | import android.graphics.Region; |
| 50 | import android.graphics.Region.Op; |
Matthew Ng | 44b1450 | 2018-05-04 11:10:14 -0700 | [diff] [blame] | 51 | import android.os.Bundle; |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 52 | import android.os.Handler; |
| 53 | import android.os.Message; |
Matthew Ng | 86a436e | 2018-10-26 16:00:53 -0700 | [diff] [blame] | 54 | import android.os.RemoteException; |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 55 | import android.os.SystemProperties; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 56 | import android.util.AttributeSet; |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 57 | import android.util.Log; |
Matthew Ng | 86a436e | 2018-10-26 16:00:53 -0700 | [diff] [blame] | 58 | import android.util.Slog; |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 59 | import android.util.SparseArray; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 60 | import android.view.Display; |
Matthew Ng | b831fb4 | 2019-01-30 11:20:48 -0800 | [diff] [blame] | 61 | import android.view.Gravity; |
Daniel Sandler | 1d4d30a | 2011-04-28 12:35:29 -0400 | [diff] [blame] | 62 | import android.view.MotionEvent; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 63 | import android.view.Surface; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 64 | import android.view.View; |
John Spurlock | 1bbd49d | 2012-10-19 11:09:32 -0400 | [diff] [blame] | 65 | import android.view.ViewGroup; |
Adrian Roos | 7e58a08 | 2018-03-09 16:40:56 +0100 | [diff] [blame] | 66 | import android.view.WindowInsets; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 67 | import android.view.WindowManager; |
Matthew Ng | 86a436e | 2018-10-26 16:00:53 -0700 | [diff] [blame] | 68 | import android.view.WindowManagerGlobal; |
Matthew Ng | 44b1450 | 2018-05-04 11:10:14 -0700 | [diff] [blame] | 69 | import android.view.accessibility.AccessibilityNodeInfo; |
| 70 | import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction; |
Jason Monk | f1ff209 | 2014-04-29 16:50:53 -0400 | [diff] [blame] | 71 | import android.view.inputmethod.InputMethodManager; |
Jason Monk | 86bc331 | 2016-08-16 13:17:56 -0400 | [diff] [blame] | 72 | import android.widget.FrameLayout; |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 73 | |
Jeff Chang | 2aaa91a | 2018-11-08 18:04:16 +0800 | [diff] [blame] | 74 | import com.android.internal.annotations.VisibleForTesting; |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 75 | import com.android.systemui.Dependency; |
Jason Monk | f85fc96 | 2017-04-19 17:13:41 -0400 | [diff] [blame] | 76 | import com.android.systemui.DockedStackExistsListener; |
Matthew Ng | ca4592b | 2018-08-06 14:12:37 -0700 | [diff] [blame] | 77 | import com.android.systemui.Interpolators; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 78 | import com.android.systemui.R; |
Matthew Ng | 44b1450 | 2018-05-04 11:10:14 -0700 | [diff] [blame] | 79 | import com.android.systemui.SysUiServiceProvider; |
Matthew Ng | 0548fbc | 2019-01-11 12:24:13 -0800 | [diff] [blame] | 80 | import com.android.systemui.assist.AssistManager; |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 81 | import com.android.systemui.plugins.PluginListener; |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 82 | import com.android.systemui.plugins.statusbar.phone.NavGesture; |
| 83 | import com.android.systemui.plugins.statusbar.phone.NavGesture.GestureHelper; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 84 | import com.android.systemui.recents.OverviewProxyService; |
Matthew Ng | 44b1450 | 2018-05-04 11:10:14 -0700 | [diff] [blame] | 85 | import com.android.systemui.recents.Recents; |
Tony Wickham | 05c1f85 | 2018-02-06 12:32:54 -0800 | [diff] [blame] | 86 | import com.android.systemui.recents.RecentsOnboarding; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 87 | import com.android.systemui.shared.plugins.PluginManager; |
Matthew Ng | 87cbf34 | 2018-02-15 12:21:18 -0800 | [diff] [blame] | 88 | import com.android.systemui.shared.system.ActivityManagerWrapper; |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 89 | import com.android.systemui.shared.system.NavigationBarCompat; |
Matthew Ng | 84db161 | 2018-04-17 16:48:21 -0700 | [diff] [blame] | 90 | import com.android.systemui.shared.system.WindowManagerWrapper; |
Matthew Ng | 1cf6eac | 2018-11-27 15:06:55 -0800 | [diff] [blame] | 91 | import com.android.systemui.statusbar.phone.NavigationPrototypeController.GestureAction; |
| 92 | import com.android.systemui.statusbar.phone.NavigationPrototypeController.OnPrototypeChangedListener; |
Daniel Sandler | c26185b | 2012-08-29 15:49:53 -0400 | [diff] [blame] | 93 | import com.android.systemui.statusbar.policy.DeadZone; |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 94 | import com.android.systemui.statusbar.policy.KeyButtonDrawable; |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 95 | |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 96 | import java.io.FileDescriptor; |
| 97 | import java.io.PrintWriter; |
Matthew Ng | b831fb4 | 2019-01-30 11:20:48 -0800 | [diff] [blame] | 98 | import java.lang.annotation.Retention; |
| 99 | import java.lang.annotation.RetentionPolicy; |
Jason Monk | 32e3bb5 | 2017-07-27 12:35:41 -0400 | [diff] [blame] | 100 | import java.util.function.Consumer; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 101 | |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 102 | public class NavigationBarView extends FrameLayout implements PluginListener<NavGesture> { |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 103 | final static boolean DEBUG = false; |
Adrian Roos | a98b32c | 2016-08-11 10:41:08 -0700 | [diff] [blame] | 104 | final static String TAG = "StatusBar/NavBarView"; |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 105 | |
Matthew Ng | b831fb4 | 2019-01-30 11:20:48 -0800 | [diff] [blame] | 106 | @Retention(RetentionPolicy.SOURCE) |
| 107 | @IntDef({WINDOW_TARGET_BOTTOM, WINDOW_TARGET_LEFT, WINDOW_TARGET_RIGHT}) |
| 108 | public @interface WindowTarget{} |
| 109 | public static final int WINDOW_TARGET_BOTTOM = 0; |
| 110 | public static final int WINDOW_TARGET_LEFT = 1; |
| 111 | public static final int WINDOW_TARGET_RIGHT = 2; |
| 112 | |
Daniel Sandler | c3fc322 | 2012-10-25 13:28:33 -0400 | [diff] [blame] | 113 | // slippery nav bar when everything is disabled, e.g. during setup |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 114 | final static boolean SLIPPERY_WHEN_DISABLED = true; |
Daniel Sandler | c3fc322 | 2012-10-25 13:28:33 -0400 | [diff] [blame] | 115 | |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 116 | final static boolean ALTERNATE_CAR_MODE_UI = false; |
| 117 | |
Daniel Sandler | 5c8da94 | 2011-06-28 00:29:04 -0400 | [diff] [blame] | 118 | View mCurrentView = null; |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 119 | private View mVertical; |
| 120 | private View mHorizontal; |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 121 | |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 122 | /** Indicates that navigation bar is vertical. */ |
| 123 | private boolean mIsVertical; |
Adrian Roos | 090b7d8 | 2016-08-02 18:36:12 -0700 | [diff] [blame] | 124 | private int mCurrentRotation = -1; |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 125 | |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 126 | boolean mLongClickableAccessibilityButton; |
Daniel Sandler | 6da2b76 | 2011-09-14 16:04:59 -0400 | [diff] [blame] | 127 | int mDisabledFlags = 0; |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 128 | int mNavigationIconHints = 0; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 129 | |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 130 | private @NavigationBarCompat.HitTarget int mDownHitTarget = HIT_TARGET_NONE; |
Matthew Ng | b831fb4 | 2019-01-30 11:20:48 -0800 | [diff] [blame] | 131 | private @WindowTarget int mWindowHitTarget = WINDOW_TARGET_BOTTOM; |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 132 | private Rect mHomeButtonBounds = new Rect(); |
| 133 | private Rect mBackButtonBounds = new Rect(); |
Matthew Ng | 8a8c89c | 2018-03-01 13:21:43 -0800 | [diff] [blame] | 134 | private Rect mRecentsButtonBounds = new Rect(); |
Winson Chung | 8079af7 | 2018-05-10 11:12:55 -0700 | [diff] [blame] | 135 | private Rect mRotationButtonBounds = new Rect(); |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 136 | private final Region mActiveRegion = new Region(); |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 137 | private int[] mTmpPosition = new int[2]; |
| 138 | |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 139 | private KeyButtonDrawable mBackIcon; |
Matthew Ng | ec5b841 | 2018-08-22 10:45:08 -0700 | [diff] [blame] | 140 | private KeyButtonDrawable mHomeDefaultIcon; |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 141 | private KeyButtonDrawable mRecentIcon; |
| 142 | private KeyButtonDrawable mDockedIcon; |
Fabrice Di Meglio | 18d9824 | 2013-01-17 10:57:40 -0800 | [diff] [blame] | 143 | |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 144 | private GestureHelper mGestureHelper; |
Matthew Ng | 603b329 | 2018-03-30 17:15:39 -0700 | [diff] [blame] | 145 | private final DeadZone mDeadZone; |
Matthew Ng | 1e14e96 | 2018-05-03 12:51:43 -0700 | [diff] [blame] | 146 | private boolean mDeadZoneConsuming = false; |
John Spurlock | 89835dd | 2013-08-16 15:06:51 -0400 | [diff] [blame] | 147 | private final NavigationBarTransitions mBarTransitions; |
Matthew Ng | dc79e5c | 2017-12-14 17:37:35 -0800 | [diff] [blame] | 148 | private final OverviewProxyService mOverviewProxyService; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 149 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 150 | // workaround for LayoutTransitions leaving the nav buttons in a weird state (bug 5549288) |
| 151 | final static boolean WORKAROUND_INVALID_LAYOUT = true; |
| 152 | final static int MSG_CHECK_INVALID_LAYOUT = 8686; |
| 153 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 154 | // performs manual animation in sync with layout transitions |
| 155 | private final NavTransitionListener mTransitionListener = new NavTransitionListener(); |
| 156 | |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 157 | private OnVerticalChangedListener mOnVerticalChangedListener; |
Jorim Jaggi | 37c1180 | 2015-08-18 20:27:54 -0700 | [diff] [blame] | 158 | private boolean mLayoutTransitionsEnabled = true; |
| 159 | private boolean mWakeAndUnlocking; |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 160 | private boolean mUseCarModeUi = false; |
| 161 | private boolean mInCarMode = false; |
Jorim Jaggi | d30d95d | 2016-02-17 20:27:22 -0800 | [diff] [blame] | 162 | private boolean mDockedStackExists; |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 163 | |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 164 | private final SparseArray<ButtonDispatcher> mButtonDispatchers = new SparseArray<>(); |
Matthew Ng | 25593cc | 2018-09-12 16:05:41 -0700 | [diff] [blame] | 165 | private final ContextualButtonGroup mContextualButtonGroup; |
Winson | fde2e6a | 2016-03-22 16:03:10 -0700 | [diff] [blame] | 166 | private Configuration mConfiguration; |
Matthew Ng | 8c056c1 | 2018-10-15 15:16:46 -0700 | [diff] [blame] | 167 | private Configuration mTmpLastConfiguration; |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 168 | |
Adrian Roos | db12b15 | 2016-07-12 15:38:55 -0700 | [diff] [blame] | 169 | private NavigationBarInflaterView mNavigationInflaterView; |
Tony Wickham | 05c1f85 | 2018-02-06 12:32:54 -0800 | [diff] [blame] | 170 | private RecentsOnboarding mRecentsOnboarding; |
Matthew Ng | 78f88d1 | 2018-01-23 12:39:55 -0800 | [diff] [blame] | 171 | private NotificationPanelView mPanelView; |
Adrian Roos | db12b15 | 2016-07-12 15:38:55 -0700 | [diff] [blame] | 172 | |
Matthew Ng | 355fe21 | 2018-12-14 17:42:38 -0800 | [diff] [blame] | 173 | private NavBarTintController mColorAdaptionController; |
Matthew Ng | 1cf6eac | 2018-11-27 15:06:55 -0800 | [diff] [blame] | 174 | private NavigationPrototypeController mPrototypeController; |
| 175 | private NavigationGestureAction[] mDefaultGestureMap; |
Matthew Ng | 86a436e | 2018-10-26 16:00:53 -0700 | [diff] [blame] | 176 | private QuickScrubAction mQuickScrubAction; |
| 177 | private QuickStepAction mQuickStepAction; |
| 178 | private NavigationBackAction mBackAction; |
Matthew Ng | b9c8428 | 2018-12-06 17:15:27 -0800 | [diff] [blame] | 179 | private QuickSwitchAction mQuickSwitchAction; |
Matthew Ng | 0548fbc | 2019-01-11 12:24:13 -0800 | [diff] [blame] | 180 | private NavigationAssistantAction mAssistantAction; |
Matthew Ng | f886946 | 2019-01-18 13:31:47 -0800 | [diff] [blame] | 181 | private NavigationNotificationPanelAction mNotificationPanelAction; |
Matthew Ng | 86a436e | 2018-10-26 16:00:53 -0700 | [diff] [blame] | 182 | |
Matthew Ng | b831fb4 | 2019-01-30 11:20:48 -0800 | [diff] [blame] | 183 | private NavigationBarEdgePanel mLeftEdgePanel; |
| 184 | private NavigationBarEdgePanel mRightEdgePanel; |
| 185 | |
Matthew Ng | 20136e6 | 2018-05-30 12:20:31 -0700 | [diff] [blame] | 186 | /** |
| 187 | * Helper that is responsible for showing the right toast when a disallowed activity operation |
| 188 | * occurred. In pinned mode, we show instructions on how to break out of this mode, whilst in |
| 189 | * fully locked mode we only show that unlocking is blocked. |
| 190 | */ |
| 191 | private ScreenPinningNotify mScreenPinningNotify; |
| 192 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 193 | private class NavTransitionListener implements TransitionListener { |
| 194 | private boolean mBackTransitioning; |
| 195 | private boolean mHomeAppearing; |
| 196 | private long mStartDelay; |
| 197 | private long mDuration; |
| 198 | private TimeInterpolator mInterpolator; |
| 199 | |
| 200 | @Override |
| 201 | public void startTransition(LayoutTransition transition, ViewGroup container, |
| 202 | View view, int transitionType) { |
| 203 | if (view.getId() == R.id.back) { |
| 204 | mBackTransitioning = true; |
| 205 | } else if (view.getId() == R.id.home && transitionType == LayoutTransition.APPEARING) { |
| 206 | mHomeAppearing = true; |
| 207 | mStartDelay = transition.getStartDelay(transitionType); |
| 208 | mDuration = transition.getDuration(transitionType); |
| 209 | mInterpolator = transition.getInterpolator(transitionType); |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | @Override |
| 214 | public void endTransition(LayoutTransition transition, ViewGroup container, |
| 215 | View view, int transitionType) { |
| 216 | if (view.getId() == R.id.back) { |
| 217 | mBackTransitioning = false; |
| 218 | } else if (view.getId() == R.id.home && transitionType == LayoutTransition.APPEARING) { |
| 219 | mHomeAppearing = false; |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | public void onBackAltCleared() { |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 224 | ButtonDispatcher backButton = getBackButton(); |
Anthony Chen | ada1304 | 2016-01-19 16:57:20 -0800 | [diff] [blame] | 225 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 226 | // When dismissing ime during unlock, force the back button to run the same appearance |
| 227 | // animation as home (if we catch this condition early enough). |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 228 | if (!mBackTransitioning && backButton.getVisibility() == VISIBLE |
| 229 | && mHomeAppearing && getHomeButton().getAlpha() == 0) { |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 230 | getBackButton().setAlpha(0); |
Anthony Chen | ada1304 | 2016-01-19 16:57:20 -0800 | [diff] [blame] | 231 | ValueAnimator a = ObjectAnimator.ofFloat(backButton, "alpha", 0, 1); |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 232 | a.setStartDelay(mStartDelay); |
| 233 | a.setDuration(mDuration); |
| 234 | a.setInterpolator(mInterpolator); |
| 235 | a.start(); |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | |
Jason Monk | f1ff209 | 2014-04-29 16:50:53 -0400 | [diff] [blame] | 240 | private final OnClickListener mImeSwitcherClickListener = new OnClickListener() { |
| 241 | @Override |
| 242 | public void onClick(View view) { |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 243 | mContext.getSystemService(InputMethodManager.class).showInputMethodPickerFromSystem( |
| 244 | true /* showAuxiliarySubtypes */, getContext().getDisplayId()); |
Jason Monk | f1ff209 | 2014-04-29 16:50:53 -0400 | [diff] [blame] | 245 | } |
| 246 | }; |
| 247 | |
Matthew Ng | b831fb4 | 2019-01-30 11:20:48 -0800 | [diff] [blame] | 248 | private final OnTouchListener mEdgePanelTouchListener = new OnTouchListener() { |
| 249 | @SuppressLint("ClickableViewAccessibility") |
| 250 | @Override |
| 251 | public boolean onTouch(View v, MotionEvent event) { |
| 252 | if (event.getActionMasked() == ACTION_DOWN) { |
| 253 | mWindowHitTarget = v == mLeftEdgePanel ? WINDOW_TARGET_LEFT : WINDOW_TARGET_RIGHT; |
| 254 | mDownHitTarget = HIT_TARGET_NONE; |
| 255 | } |
| 256 | return mGestureHelper.onTouchEvent(event); |
| 257 | } |
| 258 | }; |
| 259 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 260 | private class H extends Handler { |
| 261 | public void handleMessage(Message m) { |
| 262 | switch (m.what) { |
| 263 | case MSG_CHECK_INVALID_LAYOUT: |
| 264 | final String how = "" + m.obj; |
| 265 | final int w = getWidth(); |
| 266 | final int h = getHeight(); |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 267 | final int vw = getCurrentView().getWidth(); |
| 268 | final int vh = getCurrentView().getHeight(); |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 269 | |
| 270 | if (h != vh || w != vw) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 271 | Log.w(TAG, String.format( |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 272 | "*** Invalid layout in navigation bar (%s this=%dx%d cur=%dx%d)", |
| 273 | how, w, h, vw, vh)); |
| 274 | if (WORKAROUND_INVALID_LAYOUT) { |
| 275 | requestLayout(); |
| 276 | } |
| 277 | } |
| 278 | break; |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | |
Matthew Ng | 44b1450 | 2018-05-04 11:10:14 -0700 | [diff] [blame] | 283 | private final AccessibilityDelegate mQuickStepAccessibilityDelegate |
| 284 | = new AccessibilityDelegate() { |
| 285 | private AccessibilityAction mToggleOverviewAction; |
| 286 | |
| 287 | @Override |
| 288 | public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) { |
| 289 | super.onInitializeAccessibilityNodeInfo(host, info); |
| 290 | if (mToggleOverviewAction == null) { |
| 291 | mToggleOverviewAction = new AccessibilityAction(R.id.action_toggle_overview, |
| 292 | getContext().getString(R.string.quick_step_accessibility_toggle_overview)); |
| 293 | } |
| 294 | info.addAction(mToggleOverviewAction); |
| 295 | } |
| 296 | |
| 297 | @Override |
| 298 | public boolean performAccessibilityAction(View host, int action, Bundle args) { |
Jason Monk | 05dd567 | 2018-08-09 09:38:21 -0400 | [diff] [blame] | 299 | if (action == R.id.action_toggle_overview) { |
| 300 | SysUiServiceProvider.getComponent(getContext(), Recents.class) |
| 301 | .toggleRecentApps(); |
| 302 | } else { |
| 303 | return super.performAccessibilityAction(host, action, args); |
Matthew Ng | 44b1450 | 2018-05-04 11:10:14 -0700 | [diff] [blame] | 304 | } |
| 305 | return true; |
| 306 | } |
| 307 | }; |
| 308 | |
Matthew Ng | 1cf6eac | 2018-11-27 15:06:55 -0800 | [diff] [blame] | 309 | private OnPrototypeChangedListener mPrototypeListener = new OnPrototypeChangedListener() { |
| 310 | @Override |
| 311 | public void onGestureRemap(int[] actions) { |
| 312 | updateNavigationGestures(); |
| 313 | } |
| 314 | |
| 315 | @Override |
| 316 | public void onBackButtonVisibilityChanged(boolean visible) { |
Matthew Ng | 8a10fb5 | 2018-12-20 16:43:56 -0800 | [diff] [blame] | 317 | if (!inScreenPinning()) { |
| 318 | getBackButton().setVisibility(visible ? VISIBLE : GONE); |
| 319 | } |
Matthew Ng | 1cf6eac | 2018-11-27 15:06:55 -0800 | [diff] [blame] | 320 | } |
Matthew Ng | 355fe21 | 2018-12-14 17:42:38 -0800 | [diff] [blame] | 321 | |
| 322 | @Override |
Matthew Ng | b8c30bb | 2018-12-21 15:25:48 -0800 | [diff] [blame] | 323 | public void onHomeButtonVisibilityChanged(boolean visible) { |
| 324 | getHomeButton().setVisibility(visible ? VISIBLE : GONE); |
| 325 | } |
| 326 | |
| 327 | @Override |
Matthew Ng | 355fe21 | 2018-12-14 17:42:38 -0800 | [diff] [blame] | 328 | public void onColorAdaptChanged(boolean enabled) { |
| 329 | if (enabled) { |
| 330 | mColorAdaptionController.start(); |
| 331 | } else { |
| 332 | mColorAdaptionController.end(); |
| 333 | } |
| 334 | } |
Matthew Ng | b831fb4 | 2019-01-30 11:20:48 -0800 | [diff] [blame] | 335 | |
| 336 | @Override |
| 337 | public void onEdgeSensitivityChanged(int width, int height) { |
| 338 | if (mLeftEdgePanel != null) { |
| 339 | mLeftEdgePanel.setDimensions(width, height); |
| 340 | } |
| 341 | if (mRightEdgePanel != null) { |
| 342 | mRightEdgePanel.setDimensions(width, height); |
| 343 | } |
| 344 | } |
Matthew Ng | b55c02c | 2019-02-15 16:20:31 -0800 | [diff] [blame] | 345 | |
| 346 | @Override |
| 347 | public void onHomeHandleVisiblilityChanged(boolean visible) { |
| 348 | showHomeHandle(visible); |
| 349 | } |
Matthew Ng | 1cf6eac | 2018-11-27 15:06:55 -0800 | [diff] [blame] | 350 | }; |
| 351 | |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 352 | public NavigationBarView(Context context, AttributeSet attrs) { |
| 353 | super(context, attrs); |
| 354 | |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 355 | mIsVertical = false; |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 356 | mLongClickableAccessibilityButton = false; |
| 357 | |
Matthew Ng | 25593cc | 2018-09-12 16:05:41 -0700 | [diff] [blame] | 358 | // Set up the context group of buttons |
| 359 | mContextualButtonGroup = new ContextualButtonGroup(R.id.menu_container); |
| 360 | final ContextualButton menuButton = new ContextualButton(R.id.menu, |
| 361 | R.drawable.ic_sysbar_menu); |
| 362 | final ContextualButton imeSwitcherButton = new ContextualButton(R.id.ime_switcher, |
| 363 | R.drawable.ic_ime_switcher_default); |
| 364 | final RotationContextButton rotateSuggestionButton = new RotationContextButton( |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 365 | R.id.rotate_suggestion, R.drawable.ic_sysbar_rotate_button, getContext(), |
Matthew Ng | 25593cc | 2018-09-12 16:05:41 -0700 | [diff] [blame] | 366 | R.style.RotateButtonCCWStart90); |
| 367 | final ContextualButton accessibilityButton = |
| 368 | new ContextualButton(R.id.accessibility_button, |
| 369 | R.drawable.ic_sysbar_accessibility_button); |
| 370 | mContextualButtonGroup.addButton(menuButton); |
| 371 | mContextualButtonGroup.addButton(imeSwitcherButton); |
| 372 | mContextualButtonGroup.addButton(rotateSuggestionButton); |
| 373 | mContextualButtonGroup.addButton(accessibilityButton); |
| 374 | |
Matthew Ng | f294654 | 2018-02-12 14:13:18 -0800 | [diff] [blame] | 375 | mOverviewProxyService = Dependency.get(OverviewProxyService.class); |
| 376 | mRecentsOnboarding = new RecentsOnboarding(context, mOverviewProxyService); |
| 377 | |
Winson | fde2e6a | 2016-03-22 16:03:10 -0700 | [diff] [blame] | 378 | mConfiguration = new Configuration(); |
Matthew Ng | 8c056c1 | 2018-10-15 15:16:46 -0700 | [diff] [blame] | 379 | mTmpLastConfiguration = new Configuration(); |
Winson | fde2e6a | 2016-03-22 16:03:10 -0700 | [diff] [blame] | 380 | mConfiguration.updateFrom(context.getResources().getConfiguration()); |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 381 | |
Matthew Ng | 20136e6 | 2018-05-30 12:20:31 -0700 | [diff] [blame] | 382 | mScreenPinningNotify = new ScreenPinningNotify(mContext); |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 383 | mBarTransitions = new NavigationBarTransitions(this); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 384 | |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 385 | mButtonDispatchers.put(R.id.back, new ButtonDispatcher(R.id.back)); |
| 386 | mButtonDispatchers.put(R.id.home, new ButtonDispatcher(R.id.home)); |
Matthew Ng | b55c02c | 2019-02-15 16:20:31 -0800 | [diff] [blame] | 387 | mButtonDispatchers.put(R.id.home_handle, new ButtonDispatcher(R.id.home_handle)); |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 388 | mButtonDispatchers.put(R.id.recent_apps, new ButtonDispatcher(R.id.recent_apps)); |
Matthew Ng | 25593cc | 2018-09-12 16:05:41 -0700 | [diff] [blame] | 389 | mButtonDispatchers.put(R.id.menu, menuButton); |
| 390 | mButtonDispatchers.put(R.id.ime_switcher, imeSwitcherButton); |
| 391 | mButtonDispatchers.put(R.id.accessibility_button, accessibilityButton); |
| 392 | mButtonDispatchers.put(R.id.rotate_suggestion, rotateSuggestionButton); |
| 393 | mButtonDispatchers.put(R.id.menu_container, mContextualButtonGroup); |
Matthew Ng | 603b329 | 2018-03-30 17:15:39 -0700 | [diff] [blame] | 394 | mDeadZone = new DeadZone(this); |
Matthew Ng | 86a436e | 2018-10-26 16:00:53 -0700 | [diff] [blame] | 395 | |
| 396 | mQuickScrubAction = new QuickScrubAction(this, mOverviewProxyService); |
| 397 | mQuickStepAction = new QuickStepAction(this, mOverviewProxyService); |
| 398 | mBackAction = new NavigationBackAction(this, mOverviewProxyService); |
Matthew Ng | b9c8428 | 2018-12-06 17:15:27 -0800 | [diff] [blame] | 399 | mQuickSwitchAction = new QuickSwitchAction(this, mOverviewProxyService); |
Matthew Ng | 1cf6eac | 2018-11-27 15:06:55 -0800 | [diff] [blame] | 400 | mDefaultGestureMap = new NavigationGestureAction[] { |
| 401 | mQuickStepAction, null /* swipeDownAction*/, null /* swipeLeftAction */, |
Matthew Ng | b9c8428 | 2018-12-06 17:15:27 -0800 | [diff] [blame] | 402 | mQuickScrubAction, null /* swipeLeftEdgeAction */, null /* swipeRightEdgeAction */ |
Matthew Ng | 1cf6eac | 2018-11-27 15:06:55 -0800 | [diff] [blame] | 403 | }; |
| 404 | |
| 405 | mPrototypeController = new NavigationPrototypeController(mHandler, mContext); |
| 406 | mPrototypeController.register(); |
| 407 | mPrototypeController.setOnPrototypeChangedListener(mPrototypeListener); |
Matthew Ng | 355fe21 | 2018-12-14 17:42:38 -0800 | [diff] [blame] | 408 | mColorAdaptionController = new NavBarTintController(this, getLightTransitionsController()); |
| 409 | } |
| 410 | |
| 411 | public NavBarTintController getColorAdaptionController() { |
| 412 | return mColorAdaptionController; |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | public BarTransitions getBarTransitions() { |
| 416 | return mBarTransitions; |
| 417 | } |
| 418 | |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 419 | public LightBarTransitionsController getLightTransitionsController() { |
| 420 | return mBarTransitions.getLightTransitionsController(); |
| 421 | } |
| 422 | |
Matthew Ng | 0548fbc | 2019-01-11 12:24:13 -0800 | [diff] [blame] | 423 | public void setComponents(NotificationPanelView panel, AssistManager assistManager) { |
Matthew Ng | 78f88d1 | 2018-01-23 12:39:55 -0800 | [diff] [blame] | 424 | mPanelView = panel; |
Matthew Ng | 0548fbc | 2019-01-11 12:24:13 -0800 | [diff] [blame] | 425 | if (mAssistantAction == null) { |
| 426 | mAssistantAction = new NavigationAssistantAction(this, mOverviewProxyService, |
| 427 | assistManager); |
| 428 | } |
Matthew Ng | f886946 | 2019-01-18 13:31:47 -0800 | [diff] [blame] | 429 | if (mNotificationPanelAction == null) { |
| 430 | mNotificationPanelAction = new NavigationNotificationPanelAction(this, |
| 431 | mOverviewProxyService, panel); |
| 432 | } |
Winson Chung | 0d3815d | 2018-09-25 18:11:54 -0700 | [diff] [blame] | 433 | if (mGestureHelper instanceof QuickStepController) { |
| 434 | ((QuickStepController) mGestureHelper).setComponents(this); |
Matthew Ng | 1cf6eac | 2018-11-27 15:06:55 -0800 | [diff] [blame] | 435 | updateNavigationGestures(); |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | private void updateNavigationGestures() { |
| 440 | if (mGestureHelper instanceof QuickStepController) { |
| 441 | final int[] assignedMap = mPrototypeController.getGestureActionMap(); |
| 442 | ((QuickStepController) mGestureHelper).setGestureActions( |
| 443 | getNavigationActionFromType(assignedMap[0], mDefaultGestureMap[0]), |
| 444 | getNavigationActionFromType(assignedMap[1], mDefaultGestureMap[1]), |
| 445 | getNavigationActionFromType(assignedMap[2], mDefaultGestureMap[2]), |
Matthew Ng | b9c8428 | 2018-12-06 17:15:27 -0800 | [diff] [blame] | 446 | getNavigationActionFromType(assignedMap[3], mDefaultGestureMap[3]), |
| 447 | getNavigationActionFromType(assignedMap[4], mDefaultGestureMap[4]), |
| 448 | getNavigationActionFromType(assignedMap[5], mDefaultGestureMap[5])); |
Matthew Ng | 1cf6eac | 2018-11-27 15:06:55 -0800 | [diff] [blame] | 449 | } |
| 450 | } |
| 451 | |
| 452 | private NavigationGestureAction getNavigationActionFromType(@GestureAction int actionType, |
| 453 | NavigationGestureAction defaultAction) { |
| 454 | switch(actionType) { |
| 455 | case NavigationPrototypeController.ACTION_QUICKSTEP: |
| 456 | return mQuickStepAction; |
| 457 | case NavigationPrototypeController.ACTION_QUICKSCRUB: |
| 458 | return mQuickScrubAction; |
| 459 | case NavigationPrototypeController.ACTION_BACK: |
| 460 | return mBackAction; |
Matthew Ng | b9c8428 | 2018-12-06 17:15:27 -0800 | [diff] [blame] | 461 | case NavigationPrototypeController.ACTION_QUICKSWITCH: |
| 462 | return mQuickSwitchAction; |
Matthew Ng | 0548fbc | 2019-01-11 12:24:13 -0800 | [diff] [blame] | 463 | case NavigationPrototypeController.ACTION_ASSISTANT: |
| 464 | return mAssistantAction; |
Matthew Ng | f886946 | 2019-01-18 13:31:47 -0800 | [diff] [blame] | 465 | case NavigationPrototypeController.ACTION_EXPAND_NOTIFICATION: |
| 466 | return mNotificationPanelAction; |
Matthew Ng | 0548fbc | 2019-01-11 12:24:13 -0800 | [diff] [blame] | 467 | case NavigationPrototypeController.ACTION_NOTHING: |
| 468 | return null; |
Matthew Ng | 1cf6eac | 2018-11-27 15:06:55 -0800 | [diff] [blame] | 469 | default: |
| 470 | return defaultAction; |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 471 | } |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 474 | public void setOnVerticalChangedListener(OnVerticalChangedListener onVerticalChangedListener) { |
| 475 | mOnVerticalChangedListener = onVerticalChangedListener; |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 476 | notifyVerticalChangedListener(mIsVertical); |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 477 | } |
| 478 | |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 479 | @Override |
| 480 | public boolean onInterceptTouchEvent(MotionEvent event) { |
Matthew Ng | 472d3e4 | 2018-06-14 15:16:55 -0700 | [diff] [blame] | 481 | final boolean deadZoneConsumed = shouldDeadZoneConsumeTouchEvents(event); |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 482 | switch (event.getActionMasked()) { |
| 483 | case ACTION_DOWN: |
| 484 | int x = (int) event.getX(); |
| 485 | int y = (int) event.getY(); |
| 486 | mDownHitTarget = HIT_TARGET_NONE; |
Matthew Ng | b831fb4 | 2019-01-30 11:20:48 -0800 | [diff] [blame] | 487 | mWindowHitTarget = WINDOW_TARGET_BOTTOM; |
Matthew Ng | 472d3e4 | 2018-06-14 15:16:55 -0700 | [diff] [blame] | 488 | if (deadZoneConsumed) { |
| 489 | mDownHitTarget = HIT_TARGET_DEAD_ZONE; |
| 490 | } else if (getBackButton().isVisible() && mBackButtonBounds.contains(x, y)) { |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 491 | mDownHitTarget = HIT_TARGET_BACK; |
Winson Chung | c6c9d40 | 2018-05-25 18:25:52 -0700 | [diff] [blame] | 492 | } else if (getHomeButton().isVisible() && mHomeButtonBounds.contains(x, y)) { |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 493 | mDownHitTarget = HIT_TARGET_HOME; |
Winson Chung | c6c9d40 | 2018-05-25 18:25:52 -0700 | [diff] [blame] | 494 | } else if (getRecentsButton().isVisible() && mRecentsButtonBounds.contains(x, y)) { |
Matthew Ng | 8a8c89c | 2018-03-01 13:21:43 -0800 | [diff] [blame] | 495 | mDownHitTarget = HIT_TARGET_OVERVIEW; |
Winson Chung | c6c9d40 | 2018-05-25 18:25:52 -0700 | [diff] [blame] | 496 | } else if (getRotateSuggestionButton().isVisible() |
| 497 | && mRotationButtonBounds.contains(x, y)) { |
Winson Chung | 8079af7 | 2018-05-10 11:12:55 -0700 | [diff] [blame] | 498 | mDownHitTarget = HIT_TARGET_ROTATION; |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 499 | } |
| 500 | break; |
| 501 | } |
Winson Chung | 4965884 | 2018-02-08 12:52:21 -0800 | [diff] [blame] | 502 | return mGestureHelper.onInterceptTouchEvent(event); |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 503 | } |
| 504 | |
Winson Chung | 4faf38a | 2018-02-06 08:53:37 -0800 | [diff] [blame] | 505 | @Override |
| 506 | public boolean onTouchEvent(MotionEvent event) { |
Matthew Ng | 472d3e4 | 2018-06-14 15:16:55 -0700 | [diff] [blame] | 507 | shouldDeadZoneConsumeTouchEvents(event); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 508 | if (mGestureHelper != null && mGestureHelper.onTouchEvent(event)) { |
Winson Chung | 4faf38a | 2018-02-06 08:53:37 -0800 | [diff] [blame] | 509 | return true; |
| 510 | } |
Winson Chung | 4965884 | 2018-02-08 12:52:21 -0800 | [diff] [blame] | 511 | return super.onTouchEvent(event); |
Winson Chung | 4faf38a | 2018-02-06 08:53:37 -0800 | [diff] [blame] | 512 | } |
| 513 | |
Matthew Ng | 1e14e96 | 2018-05-03 12:51:43 -0700 | [diff] [blame] | 514 | private boolean shouldDeadZoneConsumeTouchEvents(MotionEvent event) { |
| 515 | if (mDeadZone.onTouchEvent(event) || mDeadZoneConsuming) { |
| 516 | switch (event.getActionMasked()) { |
| 517 | case MotionEvent.ACTION_DOWN: |
| 518 | // Allow gestures starting in the deadzone to be slippery |
| 519 | setSlippery(true); |
| 520 | mDeadZoneConsuming = true; |
| 521 | break; |
| 522 | case MotionEvent.ACTION_CANCEL: |
| 523 | case MotionEvent.ACTION_UP: |
| 524 | // When a gesture started in the deadzone is finished, restore slippery state |
| 525 | updateSlippery(); |
| 526 | mDeadZoneConsuming = false; |
| 527 | break; |
| 528 | } |
| 529 | return true; |
| 530 | } |
| 531 | return false; |
| 532 | } |
| 533 | |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 534 | public @NavigationBarCompat.HitTarget int getDownHitTarget() { |
| 535 | return mDownHitTarget; |
| 536 | } |
| 537 | |
Matthew Ng | b831fb4 | 2019-01-30 11:20:48 -0800 | [diff] [blame] | 538 | public @WindowTarget int getWindowTarget() { |
| 539 | return mWindowHitTarget; |
| 540 | } |
| 541 | |
Xiyuan Xia | ee7dd05 | 2015-05-15 09:46:27 -0700 | [diff] [blame] | 542 | public void abortCurrentGesture() { |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 543 | getHomeButton().abortCurrentGesture(); |
Xiyuan Xia | ee7dd05 | 2015-05-15 09:46:27 -0700 | [diff] [blame] | 544 | } |
| 545 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 546 | private H mHandler = new H(); |
| 547 | |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 548 | public View getCurrentView() { |
| 549 | return mCurrentView; |
| 550 | } |
| 551 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 552 | public ButtonDispatcher getRecentsButton() { |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 553 | return mButtonDispatchers.get(R.id.recent_apps); |
Daniel Sandler | 5c8da94 | 2011-06-28 00:29:04 -0400 | [diff] [blame] | 554 | } |
| 555 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 556 | public ButtonDispatcher getMenuButton() { |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 557 | return mButtonDispatchers.get(R.id.menu); |
Daniel Sandler | 5c8da94 | 2011-06-28 00:29:04 -0400 | [diff] [blame] | 558 | } |
| 559 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 560 | public ButtonDispatcher getBackButton() { |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 561 | return mButtonDispatchers.get(R.id.back); |
Mike Lockwood | e3646dd | 2011-09-01 12:46:28 -0400 | [diff] [blame] | 562 | } |
| 563 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 564 | public ButtonDispatcher getHomeButton() { |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 565 | return mButtonDispatchers.get(R.id.home); |
Mike Lockwood | e3646dd | 2011-09-01 12:46:28 -0400 | [diff] [blame] | 566 | } |
| 567 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 568 | public ButtonDispatcher getImeSwitchButton() { |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 569 | return mButtonDispatchers.get(R.id.ime_switcher); |
Jason Monk | f1ff209 | 2014-04-29 16:50:53 -0400 | [diff] [blame] | 570 | } |
| 571 | |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 572 | public ButtonDispatcher getAccessibilityButton() { |
| 573 | return mButtonDispatchers.get(R.id.accessibility_button); |
| 574 | } |
| 575 | |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 576 | public RotationContextButton getRotateSuggestionButton() { |
| 577 | return (RotationContextButton) mContextualButtonGroup |
| 578 | .getContextButton(R.id.rotate_suggestion); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 579 | } |
| 580 | |
Matthew Ng | b55c02c | 2019-02-15 16:20:31 -0800 | [diff] [blame] | 581 | public ButtonDispatcher getHomeHandle() { |
| 582 | return mButtonDispatchers.get(R.id.home_handle); |
| 583 | } |
| 584 | |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 585 | public SparseArray<ButtonDispatcher> getButtonDispatchers() { |
| 586 | return mButtonDispatchers; |
| 587 | } |
| 588 | |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 589 | public boolean isRecentsButtonVisible() { |
| 590 | return getRecentsButton().getVisibility() == View.VISIBLE; |
| 591 | } |
| 592 | |
Matthew Ng | 6ff33b7 | 2018-02-27 13:47:38 -0800 | [diff] [blame] | 593 | public boolean isOverviewEnabled() { |
| 594 | return (mDisabledFlags & View.STATUS_BAR_DISABLE_RECENT) == 0; |
| 595 | } |
| 596 | |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 597 | public boolean isQuickStepSwipeUpEnabled() { |
Matthew Ng | c1a97b1 | 2018-03-28 14:02:00 -0700 | [diff] [blame] | 598 | return mOverviewProxyService.shouldShowSwipeUpUI() && isOverviewEnabled(); |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | public boolean isQuickScrubEnabled() { |
| 602 | return SystemProperties.getBoolean("persist.quickstep.scrub.enabled", true) |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 603 | && mOverviewProxyService.isEnabled() && isOverviewEnabled() |
Matthew Ng | c1a97b1 | 2018-03-28 14:02:00 -0700 | [diff] [blame] | 604 | && ((mOverviewProxyService.getInteractionFlags() & FLAG_DISABLE_QUICK_SCRUB) == 0); |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 605 | } |
| 606 | |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 607 | private void reloadNavIcons() { |
Matthew Ng | 8c056c1 | 2018-10-15 15:16:46 -0700 | [diff] [blame] | 608 | updateIcons(Configuration.EMPTY); |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 609 | } |
| 610 | |
Matthew Ng | 8c056c1 | 2018-10-15 15:16:46 -0700 | [diff] [blame] | 611 | private void updateIcons(Configuration oldConfig) { |
| 612 | final boolean orientationChange = oldConfig.orientation != mConfiguration.orientation; |
| 613 | final boolean densityChange = oldConfig.densityDpi != mConfiguration.densityDpi; |
| 614 | final boolean dirChange = oldConfig.getLayoutDirection() != mConfiguration.getLayoutDirection(); |
Matthew Ng | ca4592b | 2018-08-06 14:12:37 -0700 | [diff] [blame] | 615 | |
| 616 | if (orientationChange || densityChange) { |
Matthew Ng | d6865ba | 2018-08-27 17:58:41 -0700 | [diff] [blame] | 617 | mDockedIcon = getDrawable(R.drawable.ic_sysbar_docked); |
| 618 | mHomeDefaultIcon = getHomeDrawable(); |
Winson | fde2e6a | 2016-03-22 16:03:10 -0700 | [diff] [blame] | 619 | } |
Matthew Ng | ca4592b | 2018-08-06 14:12:37 -0700 | [diff] [blame] | 620 | if (densityChange || dirChange) { |
Matthew Ng | d6865ba | 2018-08-27 17:58:41 -0700 | [diff] [blame] | 621 | mRecentIcon = getDrawable(R.drawable.ic_sysbar_recent); |
Matthew Ng | 25593cc | 2018-09-12 16:05:41 -0700 | [diff] [blame] | 622 | mContextualButtonGroup.updateIcons(); |
Winson | fde2e6a | 2016-03-22 16:03:10 -0700 | [diff] [blame] | 623 | } |
Matthew Ng | ca4592b | 2018-08-06 14:12:37 -0700 | [diff] [blame] | 624 | if (orientationChange || densityChange || dirChange) { |
Matthew Ng | d6865ba | 2018-08-27 17:58:41 -0700 | [diff] [blame] | 625 | mBackIcon = getBackDrawable(); |
Matthew Ng | ca4592b | 2018-08-06 14:12:37 -0700 | [diff] [blame] | 626 | } |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 627 | } |
| 628 | |
Matthew Ng | d6865ba | 2018-08-27 17:58:41 -0700 | [diff] [blame] | 629 | public KeyButtonDrawable getBackDrawable() { |
| 630 | KeyButtonDrawable drawable = chooseNavigationIconDrawable(R.drawable.ic_sysbar_back, |
| 631 | R.drawable.ic_sysbar_back_quick_step); |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 632 | orientBackButton(drawable); |
| 633 | return drawable; |
Matthew Ng | 87cbf34 | 2018-02-15 12:21:18 -0800 | [diff] [blame] | 634 | } |
| 635 | |
Matthew Ng | d6865ba | 2018-08-27 17:58:41 -0700 | [diff] [blame] | 636 | public KeyButtonDrawable getHomeDrawable() { |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 637 | final boolean quickStepEnabled = mOverviewProxyService.shouldShowSwipeUpUI(); |
| 638 | KeyButtonDrawable drawable = quickStepEnabled |
Matthew Ng | d6865ba | 2018-08-27 17:58:41 -0700 | [diff] [blame] | 639 | ? getDrawable(R.drawable.ic_sysbar_home_quick_step) |
| 640 | : getDrawable(R.drawable.ic_sysbar_home); |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 641 | orientHomeButton(drawable); |
| 642 | return drawable; |
Matthew Ng | 87cbf34 | 2018-02-15 12:21:18 -0800 | [diff] [blame] | 643 | } |
| 644 | |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 645 | private void orientBackButton(KeyButtonDrawable drawable) { |
| 646 | final boolean useAltBack = |
Matthew Ng | ca4592b | 2018-08-06 14:12:37 -0700 | [diff] [blame] | 647 | (mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) != 0; |
Matthew Ng | 8c056c1 | 2018-10-15 15:16:46 -0700 | [diff] [blame] | 648 | final boolean isRtl = mConfiguration.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; |
Matthew Ng | ca4592b | 2018-08-06 14:12:37 -0700 | [diff] [blame] | 649 | float degrees = useAltBack |
| 650 | ? (isRtl ? 270 : -90) |
| 651 | : (isRtl ? 180 : 0); |
| 652 | if (drawable.getRotation() == degrees) { |
| 653 | return; |
| 654 | } |
| 655 | |
| 656 | // Animate the back button's rotation to the new degrees and only in portrait move up the |
| 657 | // back button to line up with the other buttons |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 658 | float targetY = !mOverviewProxyService.shouldShowSwipeUpUI() && !mIsVertical && useAltBack |
Matthew Ng | ca4592b | 2018-08-06 14:12:37 -0700 | [diff] [blame] | 659 | ? - getResources().getDimension(R.dimen.navbar_back_button_ime_offset) |
| 660 | : 0; |
| 661 | ObjectAnimator navBarAnimator = ObjectAnimator.ofPropertyValuesHolder(drawable, |
| 662 | PropertyValuesHolder.ofFloat(KeyButtonDrawable.KEY_DRAWABLE_ROTATE, degrees), |
| 663 | PropertyValuesHolder.ofFloat(KeyButtonDrawable.KEY_DRAWABLE_TRANSLATE_Y, targetY)); |
| 664 | navBarAnimator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN); |
| 665 | navBarAnimator.setDuration(200); |
| 666 | navBarAnimator.start(); |
Matthew Ng | 87cbf34 | 2018-02-15 12:21:18 -0800 | [diff] [blame] | 667 | } |
| 668 | |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 669 | private void orientHomeButton(KeyButtonDrawable drawable) { |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 670 | drawable.setRotation(mIsVertical ? 90 : 0); |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 671 | } |
| 672 | |
Matthew Ng | d6865ba | 2018-08-27 17:58:41 -0700 | [diff] [blame] | 673 | private KeyButtonDrawable chooseNavigationIconDrawable(@DrawableRes int icon, |
| 674 | @DrawableRes int quickStepIcon) { |
Matthew Ng | c1a97b1 | 2018-03-28 14:02:00 -0700 | [diff] [blame] | 675 | final boolean quickStepEnabled = mOverviewProxyService.shouldShowSwipeUpUI(); |
Matthew Ng | d6865ba | 2018-08-27 17:58:41 -0700 | [diff] [blame] | 676 | return quickStepEnabled ? getDrawable(quickStepIcon) : getDrawable(icon); |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 677 | } |
| 678 | |
Matthew Ng | d6865ba | 2018-08-27 17:58:41 -0700 | [diff] [blame] | 679 | private KeyButtonDrawable getDrawable(@DrawableRes int icon) { |
Matthew Ng | 25593cc | 2018-09-12 16:05:41 -0700 | [diff] [blame] | 680 | return KeyButtonDrawable.create(mContext, icon, true /* hasShadow */); |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 681 | } |
| 682 | |
Matthew Ng | d6865ba | 2018-08-27 17:58:41 -0700 | [diff] [blame] | 683 | private KeyButtonDrawable getDrawable(@DrawableRes int icon, boolean hasShadow) { |
Matthew Ng | 25593cc | 2018-09-12 16:05:41 -0700 | [diff] [blame] | 684 | return KeyButtonDrawable.create(mContext, icon, hasShadow); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 685 | } |
| 686 | |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 687 | @Override |
| 688 | public void setLayoutDirection(int layoutDirection) { |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 689 | reloadNavIcons(); |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 690 | |
| 691 | super.setLayoutDirection(layoutDirection); |
Daniel Sandler | 1d4d30a | 2011-04-28 12:35:29 -0400 | [diff] [blame] | 692 | } |
| 693 | |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 694 | public void setNavigationIconHints(int hints) { |
| 695 | if (hints == mNavigationIconHints) return; |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 696 | final boolean backAlt = (hints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) != 0; |
| 697 | if ((mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) != 0 && !backAlt) { |
| 698 | mTransitionListener.onBackAltCleared(); |
| 699 | } |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 700 | if (DEBUG) { |
John Spurlock | 0153478 | 2014-01-13 11:59:22 -0500 | [diff] [blame] | 701 | android.widget.Toast.makeText(getContext(), |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 702 | "Navigation icon hints = " + hints, |
| 703 | 500).show(); |
| 704 | } |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 705 | mNavigationIconHints = hints; |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 706 | updateNavButtonIcons(); |
| 707 | } |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 708 | |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 709 | public void setDisabledFlags(int disabledFlags) { |
| 710 | if (mDisabledFlags == disabledFlags) return; |
| 711 | |
| 712 | final boolean overviewEnabledBefore = isOverviewEnabled(); |
| 713 | mDisabledFlags = disabledFlags; |
| 714 | |
| 715 | // Update icons if overview was just enabled to ensure the correct icons are present |
| 716 | if (!overviewEnabledBefore && isOverviewEnabled()) { |
| 717 | reloadNavIcons(); |
| 718 | } |
| 719 | |
| 720 | updateNavButtonIcons(); |
Winson Chung | 1be4c7e | 2018-05-23 18:24:13 -0700 | [diff] [blame] | 721 | updateSlippery(); |
Tracy Zhou | 9814091 | 2018-06-05 12:09:14 -0700 | [diff] [blame] | 722 | setUpSwipeUpOnboarding(isQuickStepSwipeUpEnabled()); |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | public void updateNavButtonIcons() { |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 726 | // We have to replace or restore the back and home button icons when exiting or entering |
| 727 | // carmode, respectively. Recents are not available in CarMode in nav bar so change |
| 728 | // to recent icon is not required. |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 729 | final boolean useAltBack = |
| 730 | (mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) != 0; |
Matthew Ng | d6865ba | 2018-08-27 17:58:41 -0700 | [diff] [blame] | 731 | KeyButtonDrawable backIcon = mBackIcon; |
Matthew Ng | ec5b841 | 2018-08-22 10:45:08 -0700 | [diff] [blame] | 732 | orientBackButton(backIcon); |
Matthew Ng | d6865ba | 2018-08-27 17:58:41 -0700 | [diff] [blame] | 733 | KeyButtonDrawable homeIcon = mHomeDefaultIcon; |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 734 | if (!mUseCarModeUi) { |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 735 | orientHomeButton(homeIcon); |
| 736 | } |
| 737 | getHomeButton().setImageDrawable(homeIcon); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 738 | getBackButton().setImageDrawable(backIcon); |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 739 | |
Jorim Jaggi | d30d95d | 2016-02-17 20:27:22 -0800 | [diff] [blame] | 740 | updateRecentsIcon(); |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 741 | |
Mike Digman | a48cf19 | 2018-02-12 17:52:48 -0800 | [diff] [blame] | 742 | // Update IME button visibility, a11y and rotate button always overrides the appearance |
Matthew Ng | 25593cc | 2018-09-12 16:05:41 -0700 | [diff] [blame] | 743 | mContextualButtonGroup.setButtonVisiblity(R.id.ime_switcher, |
| 744 | (mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_IME_SHOWN) != 0); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 745 | |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 746 | mBarTransitions.reapplyDarkIntensity(); |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 747 | |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 748 | boolean disableHome = ((mDisabledFlags & View.STATUS_BAR_DISABLE_HOME) != 0); |
Sriram Viswanathan | 469caae | 2016-03-22 13:11:50 -0700 | [diff] [blame] | 749 | |
Matthew Ng | 78ba6e2 | 2018-09-24 16:55:36 -0700 | [diff] [blame] | 750 | // TODO(b/113914868): investigation log for disappearing home button |
| 751 | Log.i(TAG, "updateNavButtonIcons (b/113914868): home disabled=" + disableHome |
| 752 | + " mDisabledFlags=" + mDisabledFlags); |
Matthew Ng | b8c30bb | 2018-12-21 15:25:48 -0800 | [diff] [blame] | 753 | disableHome |= mPrototypeController.hideHomeButton(); |
Matthew Ng | 78ba6e2 | 2018-09-24 16:55:36 -0700 | [diff] [blame] | 754 | |
Jeff Chang | 2aaa91a | 2018-11-08 18:04:16 +0800 | [diff] [blame] | 755 | // Always disable recents when alternate car mode UI is active and for secondary displays. |
| 756 | boolean disableRecent = isRecentsButtonDisabled(); |
Charles He | e57ff81 | 2017-10-26 10:01:35 +0100 | [diff] [blame] | 757 | |
Matthew Ng | b687c8a | 2018-10-02 11:31:38 -0700 | [diff] [blame] | 758 | boolean disableBack = QuickStepController.shouldhideBackButton(getContext()) |
Matthew Ng | c83b989 | 2018-08-21 16:31:13 -0700 | [diff] [blame] | 759 | || (((mDisabledFlags & View.STATUS_BAR_DISABLE_BACK) != 0) && !useAltBack); |
Daniel Sandler | 029d587 | 2011-09-12 00:58:58 -0400 | [diff] [blame] | 760 | |
Matthew Ng | 87cbf34 | 2018-02-15 12:21:18 -0800 | [diff] [blame] | 761 | // When screen pinning, don't hide back and home when connected service or back and |
| 762 | // recents buttons when disconnected from launcher service in screen pinning mode, |
| 763 | // as they are used for exiting. |
Matthew Ng | 6ff33b7 | 2018-02-27 13:47:38 -0800 | [diff] [blame] | 764 | final boolean pinningActive = ActivityManagerWrapper.getInstance().isScreenPinningActive(); |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 765 | if (mOverviewProxyService.isEnabled()) { |
Matthew Ng | 87cbf34 | 2018-02-15 12:21:18 -0800 | [diff] [blame] | 766 | // Use interaction flags to show/hide navigation buttons but will be shown if required |
| 767 | // to exit screen pinning. |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 768 | final int flags = mOverviewProxyService.getInteractionFlags(); |
| 769 | disableRecent |= (flags & FLAG_SHOW_OVERVIEW_BUTTON) == 0; |
Matthew Ng | 6ff33b7 | 2018-02-27 13:47:38 -0800 | [diff] [blame] | 770 | if (pinningActive) { |
Matthew Ng | 87cbf34 | 2018-02-15 12:21:18 -0800 | [diff] [blame] | 771 | disableBack = disableHome = false; |
Matthew Ng | 87cbf34 | 2018-02-15 12:21:18 -0800 | [diff] [blame] | 772 | } |
Matthew Ng | 6ff33b7 | 2018-02-27 13:47:38 -0800 | [diff] [blame] | 773 | } else if (pinningActive) { |
Matthew Ng | 87cbf34 | 2018-02-15 12:21:18 -0800 | [diff] [blame] | 774 | disableBack = disableRecent = false; |
Matthew Ng | dc79e5c | 2017-12-14 17:37:35 -0800 | [diff] [blame] | 775 | } |
Charles He | e57ff81 | 2017-10-26 10:01:35 +0100 | [diff] [blame] | 776 | |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 777 | ViewGroup navButtons = (ViewGroup) getCurrentView().findViewById(R.id.nav_buttons); |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 778 | if (navButtons != null) { |
| 779 | LayoutTransition lt = navButtons.getLayoutTransition(); |
John Spurlock | 1bbd49d | 2012-10-19 11:09:32 -0400 | [diff] [blame] | 780 | if (lt != null) { |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 781 | if (!lt.getTransitionListeners().contains(mTransitionListener)) { |
| 782 | lt.addTransitionListener(mTransitionListener); |
| 783 | } |
John Spurlock | 1bbd49d | 2012-10-19 11:09:32 -0400 | [diff] [blame] | 784 | } |
| 785 | } |
| 786 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 787 | getBackButton().setVisibility(disableBack ? View.INVISIBLE : View.VISIBLE); |
Jason Monk | 188908f | 2016-01-22 10:23:51 -0500 | [diff] [blame] | 788 | getHomeButton().setVisibility(disableHome ? View.INVISIBLE : View.VISIBLE); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 789 | getRecentsButton().setVisibility(disableRecent ? View.INVISIBLE : View.VISIBLE); |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 790 | } |
| 791 | |
Jeff Chang | 2aaa91a | 2018-11-08 18:04:16 +0800 | [diff] [blame] | 792 | @VisibleForTesting |
| 793 | boolean isRecentsButtonDisabled() { |
| 794 | return mUseCarModeUi || !isOverviewEnabled() |
| 795 | || getContext().getDisplayId() != Display.DEFAULT_DISPLAY; |
| 796 | } |
| 797 | |
| 798 | private Display getContextDisplay() { |
| 799 | return getContext().getDisplay(); |
| 800 | } |
| 801 | |
Matthew Ng | 87cbf34 | 2018-02-15 12:21:18 -0800 | [diff] [blame] | 802 | public boolean inScreenPinning() { |
Matthew Ng | 6ff33b7 | 2018-02-27 13:47:38 -0800 | [diff] [blame] | 803 | return ActivityManagerWrapper.getInstance().isScreenPinningActive(); |
Jason Monk | 17488b9 | 2014-11-06 11:26:14 -0500 | [diff] [blame] | 804 | } |
| 805 | |
Jorim Jaggi | 37c1180 | 2015-08-18 20:27:54 -0700 | [diff] [blame] | 806 | public void setLayoutTransitionsEnabled(boolean enabled) { |
| 807 | mLayoutTransitionsEnabled = enabled; |
| 808 | updateLayoutTransitionsEnabled(); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 809 | } |
| 810 | |
Jorim Jaggi | 37c1180 | 2015-08-18 20:27:54 -0700 | [diff] [blame] | 811 | public void setWakeAndUnlocking(boolean wakeAndUnlocking) { |
| 812 | setUseFadingAnimations(wakeAndUnlocking); |
| 813 | mWakeAndUnlocking = wakeAndUnlocking; |
| 814 | updateLayoutTransitionsEnabled(); |
| 815 | } |
| 816 | |
| 817 | private void updateLayoutTransitionsEnabled() { |
| 818 | boolean enabled = !mWakeAndUnlocking && mLayoutTransitionsEnabled; |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 819 | ViewGroup navButtons = (ViewGroup) getCurrentView().findViewById(R.id.nav_buttons); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 820 | LayoutTransition lt = navButtons.getLayoutTransition(); |
Julia Reynolds | 8478aba | 2015-07-31 09:17:20 -0400 | [diff] [blame] | 821 | if (lt != null) { |
| 822 | if (enabled) { |
| 823 | lt.enableTransitionType(LayoutTransition.APPEARING); |
| 824 | lt.enableTransitionType(LayoutTransition.DISAPPEARING); |
| 825 | lt.enableTransitionType(LayoutTransition.CHANGE_APPEARING); |
| 826 | lt.enableTransitionType(LayoutTransition.CHANGE_DISAPPEARING); |
| 827 | } else { |
| 828 | lt.disableTransitionType(LayoutTransition.APPEARING); |
| 829 | lt.disableTransitionType(LayoutTransition.DISAPPEARING); |
| 830 | lt.disableTransitionType(LayoutTransition.CHANGE_APPEARING); |
| 831 | lt.disableTransitionType(LayoutTransition.CHANGE_DISAPPEARING); |
| 832 | } |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 833 | } |
| 834 | } |
| 835 | |
| 836 | private void setUseFadingAnimations(boolean useFadingAnimations) { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 837 | WindowManager.LayoutParams lp = (WindowManager.LayoutParams) ((ViewGroup) getParent()) |
| 838 | .getLayoutParams(); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 839 | if (lp != null) { |
| 840 | boolean old = lp.windowAnimations != 0; |
| 841 | if (!old && useFadingAnimations) { |
| 842 | lp.windowAnimations = R.style.Animation_NavigationBarFadeIn; |
| 843 | } else if (old && !useFadingAnimations) { |
| 844 | lp.windowAnimations = 0; |
| 845 | } else { |
| 846 | return; |
| 847 | } |
| 848 | WindowManager wm = (WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 849 | wm.updateViewLayout((View) getParent(), lp); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 850 | } |
| 851 | } |
| 852 | |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 853 | public void onNavigationButtonLongPress(View v) { |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 854 | if (mGestureHelper != null) { |
| 855 | mGestureHelper.onNavigationButtonLongPress(v); |
| 856 | } |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 857 | } |
| 858 | |
Matthew Ng | 78f88d1 | 2018-01-23 12:39:55 -0800 | [diff] [blame] | 859 | public void onPanelExpandedChange(boolean expanded) { |
| 860 | updateSlippery(); |
| 861 | } |
| 862 | |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 863 | public void updateStates() { |
Matthew Ng | 44b1450 | 2018-05-04 11:10:14 -0700 | [diff] [blame] | 864 | final boolean showSwipeUpUI = mOverviewProxyService.shouldShowSwipeUpUI(); |
Mike Digman | f77fb91 | 2018-05-21 11:21:30 -0700 | [diff] [blame] | 865 | |
| 866 | if (mNavigationInflaterView != null) { |
Matthew Ng | b55c02c | 2019-02-15 16:20:31 -0800 | [diff] [blame] | 867 | if (mPrototypeController.showHomeHandle()) { |
| 868 | showHomeHandle(true /* visible */); |
| 869 | } |
| 870 | |
Mike Digman | f77fb91 | 2018-05-21 11:21:30 -0700 | [diff] [blame] | 871 | // Reinflate the navbar if needed, no-op unless the swipe up state changes |
| 872 | mNavigationInflaterView.onLikelyDefaultLayoutChange(); |
| 873 | } |
| 874 | |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 875 | updateSlippery(); |
Winson Chung | 770d7e9 | 2018-03-20 17:51:39 -0700 | [diff] [blame] | 876 | reloadNavIcons(); |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 877 | updateNavButtonIcons(); |
Winson Chung | f9e3027 | 2018-03-26 17:25:36 -0700 | [diff] [blame] | 878 | setUpSwipeUpOnboarding(isQuickStepSwipeUpEnabled()); |
Matthew Ng | 44b1450 | 2018-05-04 11:10:14 -0700 | [diff] [blame] | 879 | WindowManagerWrapper.getInstance().setNavBarVirtualKeyHapticFeedbackEnabled(!showSwipeUpUI); |
| 880 | getHomeButton().setAccessibilityDelegate( |
| 881 | showSwipeUpUI ? mQuickStepAccessibilityDelegate : null); |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 882 | } |
| 883 | |
Matthew Ng | 90ef063 | 2018-08-15 13:53:15 -0700 | [diff] [blame] | 884 | public boolean isNotificationsFullyCollapsed() { |
| 885 | return mPanelView.isFullyCollapsed(); |
| 886 | } |
| 887 | |
| 888 | /** |
| 889 | * Updates the {@link WindowManager.LayoutParams.FLAG_SLIPPERY} state dependent on if swipe up |
| 890 | * is enabled, or the notifications is fully opened without being in an animated state. If |
| 891 | * slippery is enabled, touch events will leave the nav bar window and enter into the fullscreen |
| 892 | * app/home window, if not nav bar will receive a cancelled touch event once gesture leaves bar. |
| 893 | */ |
Matthew Ng | 472d3e4 | 2018-06-14 15:16:55 -0700 | [diff] [blame] | 894 | public void updateSlippery() { |
Matthew Ng | 90ef063 | 2018-08-15 13:53:15 -0700 | [diff] [blame] | 895 | setSlippery(!isQuickStepSwipeUpEnabled() || |
| 896 | (mPanelView.isFullyExpanded() && !mPanelView.isCollapsing())); |
Matthew Ng | 78f88d1 | 2018-01-23 12:39:55 -0800 | [diff] [blame] | 897 | } |
| 898 | |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 899 | private void setSlippery(boolean slippery) { |
Matthew Ng | b831fb4 | 2019-01-30 11:20:48 -0800 | [diff] [blame] | 900 | setWindowFlag(WindowManager.LayoutParams.FLAG_SLIPPERY, slippery); |
| 901 | } |
| 902 | |
| 903 | public void setWindowTouchable(boolean flag) { |
| 904 | setWindowFlag(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, !flag); |
| 905 | if (mLeftEdgePanel != null) { |
| 906 | mLeftEdgePanel.setWindowFlag(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, !flag); |
| 907 | } |
| 908 | if (mRightEdgePanel != null) { |
| 909 | mRightEdgePanel.setWindowFlag(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, !flag); |
| 910 | } |
| 911 | } |
| 912 | |
| 913 | private void setWindowFlag(int flags, boolean enable) { |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 914 | final ViewGroup navbarView = ((ViewGroup) getParent()); |
Matthew Ng | b55c02c | 2019-02-15 16:20:31 -0800 | [diff] [blame] | 915 | if (navbarView == null) { |
| 916 | return; |
| 917 | } |
Matthew Ng | b831fb4 | 2019-01-30 11:20:48 -0800 | [diff] [blame] | 918 | WindowManager.LayoutParams lp = (WindowManager.LayoutParams) navbarView.getLayoutParams(); |
| 919 | if (lp == null || enable == ((lp.flags & flags) != 0)) { |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 920 | return; |
| 921 | } |
Matthew Ng | b831fb4 | 2019-01-30 11:20:48 -0800 | [diff] [blame] | 922 | if (enable) { |
| 923 | lp.flags |= flags; |
| 924 | } else { |
| 925 | lp.flags &= ~flags; |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 926 | } |
Matthew Ng | b831fb4 | 2019-01-30 11:20:48 -0800 | [diff] [blame] | 927 | WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); |
| 928 | wm.updateViewLayout(navbarView, lp); |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 929 | } |
| 930 | |
Matthew Ng | b55c02c | 2019-02-15 16:20:31 -0800 | [diff] [blame] | 931 | private void showHomeHandle(boolean visible) { |
| 932 | mNavigationInflaterView.onTuningChanged(NAV_BAR_VIEWS, |
| 933 | visible ? getContext().getString(R.string.config_navBarLayoutHandle) : null); |
| 934 | |
| 935 | // Color adaption is tied with showing home handle, only avaliable if visible |
| 936 | if (visible) { |
| 937 | mColorAdaptionController.start(); |
| 938 | } else { |
| 939 | mColorAdaptionController.end(); |
| 940 | } |
| 941 | } |
| 942 | |
Daniel Sandler | 56598cd | 2011-09-15 16:02:56 -0400 | [diff] [blame] | 943 | public void setMenuVisibility(final boolean show) { |
Matthew Ng | 25593cc | 2018-09-12 16:05:41 -0700 | [diff] [blame] | 944 | mContextualButtonGroup.setButtonVisiblity(R.id.menu, show); |
Daniel Sandler | 56598cd | 2011-09-15 16:02:56 -0400 | [diff] [blame] | 945 | } |
| 946 | |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 947 | public void setAccessibilityButtonState(final boolean visible, final boolean longClickable) { |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 948 | mLongClickableAccessibilityButton = longClickable; |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 949 | getAccessibilityButton().setLongClickable(longClickable); |
Matthew Ng | 25593cc | 2018-09-12 16:05:41 -0700 | [diff] [blame] | 950 | mContextualButtonGroup.setButtonVisiblity(R.id.accessibility_button, visible); |
Mike Digman | a48cf19 | 2018-02-12 17:52:48 -0800 | [diff] [blame] | 951 | } |
| 952 | |
Tracy Zhou | 1ac592c | 2018-07-25 13:47:37 -0700 | [diff] [blame] | 953 | void hideRecentsOnboarding() { |
| 954 | mRecentsOnboarding.hide(true); |
| 955 | } |
| 956 | |
Jim Miller | 960892c | 2012-05-23 15:50:04 -0700 | [diff] [blame] | 957 | @Override |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 958 | public void onFinishInflate() { |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 959 | mNavigationInflaterView = findViewById(R.id.navigation_inflater); |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 960 | mNavigationInflaterView.setButtonDispatchers(mButtonDispatchers); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 961 | |
| 962 | getImeSwitchButton().setOnClickListener(mImeSwitcherClickListener); |
Selim Cinek | 17a327a | 2014-08-25 15:03:48 +0200 | [diff] [blame] | 963 | |
Jason Monk | 32e3bb5 | 2017-07-27 12:35:41 -0400 | [diff] [blame] | 964 | DockedStackExistsListener.register(mDockedListener); |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 965 | updateOrientationViews(); |
Matthew Ng | 25593cc | 2018-09-12 16:05:41 -0700 | [diff] [blame] | 966 | reloadNavIcons(); |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 967 | } |
| 968 | |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 969 | public void onDarkIntensityChange(float intensity) { |
| 970 | if (mGestureHelper != null) { |
| 971 | mGestureHelper.onDarkIntensityChange(intensity); |
| 972 | } |
| 973 | } |
| 974 | |
| 975 | @Override |
| 976 | protected void onDraw(Canvas canvas) { |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 977 | if (mGestureHelper != null) { |
| 978 | mGestureHelper.onDraw(canvas); |
| 979 | } |
Matthew Ng | 603b329 | 2018-03-30 17:15:39 -0700 | [diff] [blame] | 980 | mDeadZone.onDraw(canvas); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 981 | super.onDraw(canvas); |
| 982 | } |
| 983 | |
| 984 | @Override |
| 985 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 986 | super.onLayout(changed, left, top, right, bottom); |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 987 | |
| 988 | mActiveRegion.setEmpty(); |
| 989 | updateButtonLocation(getBackButton(), mBackButtonBounds, true); |
| 990 | updateButtonLocation(getHomeButton(), mHomeButtonBounds, false); |
| 991 | updateButtonLocation(getRecentsButton(), mRecentsButtonBounds, false); |
| 992 | updateButtonLocation(getRotateSuggestionButton(), mRotationButtonBounds, true); |
| 993 | // TODO: Handle button visibility changes |
| 994 | mOverviewProxyService.onActiveNavBarRegionChanges(mActiveRegion); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 995 | if (mGestureHelper != null) { |
| 996 | mGestureHelper.onLayout(changed, left, top, right, bottom); |
| 997 | } |
Tracy Zhou | 559d97c | 2018-04-07 23:54:46 -0700 | [diff] [blame] | 998 | mRecentsOnboarding.setNavBarHeight(getMeasuredHeight()); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 999 | } |
| 1000 | |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 1001 | private void updateButtonLocation(ButtonDispatcher button, Rect buttonBounds, |
| 1002 | boolean isActive) { |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 1003 | View view = button.getCurrentView(); |
| 1004 | if (view == null) { |
| 1005 | buttonBounds.setEmpty(); |
| 1006 | return; |
| 1007 | } |
Matthew Ng | 3b7e390 | 2018-03-22 16:06:09 -0700 | [diff] [blame] | 1008 | // Temporarily reset the translation back to origin to get the position in window |
| 1009 | final float posX = view.getTranslationX(); |
| 1010 | final float posY = view.getTranslationY(); |
| 1011 | view.setTranslationX(0); |
| 1012 | view.setTranslationY(0); |
Sunny Goyal | aac6c88 | 2019-02-11 11:57:58 -0800 | [diff] [blame] | 1013 | |
| 1014 | if (isActive) { |
| 1015 | view.getLocationOnScreen(mTmpPosition); |
| 1016 | buttonBounds.set(mTmpPosition[0], mTmpPosition[1], |
| 1017 | mTmpPosition[0] + view.getMeasuredWidth(), |
| 1018 | mTmpPosition[1] + view.getMeasuredHeight()); |
| 1019 | mActiveRegion.op(buttonBounds, Op.UNION); |
| 1020 | } |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 1021 | view.getLocationInWindow(mTmpPosition); |
| 1022 | buttonBounds.set(mTmpPosition[0], mTmpPosition[1], |
| 1023 | mTmpPosition[0] + view.getMeasuredWidth(), |
| 1024 | mTmpPosition[1] + view.getMeasuredHeight()); |
Matthew Ng | 3b7e390 | 2018-03-22 16:06:09 -0700 | [diff] [blame] | 1025 | view.setTranslationX(posX); |
| 1026 | view.setTranslationY(posY); |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 1027 | } |
| 1028 | |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 1029 | private void updateOrientationViews() { |
| 1030 | mHorizontal = findViewById(R.id.horizontal); |
| 1031 | mVertical = findViewById(R.id.vertical); |
Jason Monk | 9a6552d | 2016-05-20 11:21:59 -0400 | [diff] [blame] | 1032 | |
Jason Monk | 199a2d0 | 2017-07-28 11:08:27 -0400 | [diff] [blame] | 1033 | updateCurrentView(); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1034 | } |
| 1035 | |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 1036 | boolean needsReorient(int rotation) { |
Adrian Roos | a98b32c | 2016-08-11 10:41:08 -0700 | [diff] [blame] | 1037 | return mCurrentRotation != rotation; |
Adrian Roos | 090b7d8 | 2016-08-02 18:36:12 -0700 | [diff] [blame] | 1038 | } |
| 1039 | |
Jason Monk | 199a2d0 | 2017-07-28 11:08:27 -0400 | [diff] [blame] | 1040 | private void updateCurrentView() { |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 1041 | resetViews(); |
| 1042 | mCurrentView = mIsVertical ? mVertical : mHorizontal; |
Daniel Sandler | 5c8da94 | 2011-06-28 00:29:04 -0400 | [diff] [blame] | 1043 | mCurrentView.setVisibility(View.VISIBLE); |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 1044 | mNavigationInflaterView.setVertical(mIsVertical); |
| 1045 | mCurrentRotation = getContextDisplay().getRotation(); |
| 1046 | mNavigationInflaterView.setAlternativeOrder(mCurrentRotation == Surface.ROTATION_90); |
Matthew Ng | 1efc9c3 | 2018-04-11 18:13:56 -0700 | [diff] [blame] | 1047 | mNavigationInflaterView.updateButtonDispatchersCurrentView(); |
Jorim Jaggi | 37c1180 | 2015-08-18 20:27:54 -0700 | [diff] [blame] | 1048 | updateLayoutTransitionsEnabled(); |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | private void resetViews() { |
| 1052 | mHorizontal.setVisibility(View.GONE); |
| 1053 | mVertical.setVisibility(View.GONE); |
Jason Monk | 9a6552d | 2016-05-20 11:21:59 -0400 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | private void updateRecentsIcon() { |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 1057 | mDockedIcon.setRotation(mDockedStackExists && mIsVertical ? 90 : 0); |
Jason Monk | 9a6552d | 2016-05-20 11:21:59 -0400 | [diff] [blame] | 1058 | getRecentsButton().setImageDrawable(mDockedStackExists ? mDockedIcon : mRecentIcon); |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 1059 | mBarTransitions.reapplyDarkIntensity(); |
Jason Monk | 9a6552d | 2016-05-20 11:21:59 -0400 | [diff] [blame] | 1060 | } |
| 1061 | |
Matthew Ng | 20136e6 | 2018-05-30 12:20:31 -0700 | [diff] [blame] | 1062 | public void showPinningEnterExitToast(boolean entering) { |
| 1063 | if (entering) { |
| 1064 | mScreenPinningNotify.showPinningStartToast(); |
Matthew Ng | 8a10fb5 | 2018-12-20 16:43:56 -0800 | [diff] [blame] | 1065 | |
| 1066 | // TODO(b/112934365): remove after prototype finished, only needed to escape from pin |
| 1067 | getBackButton().setVisibility(VISIBLE); |
Matthew Ng | b8c30bb | 2018-12-21 15:25:48 -0800 | [diff] [blame] | 1068 | getHomeButton().setVisibility(VISIBLE); |
Matthew Ng | 20136e6 | 2018-05-30 12:20:31 -0700 | [diff] [blame] | 1069 | } else { |
| 1070 | mScreenPinningNotify.showPinningExitToast(); |
| 1071 | } |
| 1072 | } |
| 1073 | |
| 1074 | public void showPinningEscapeToast() { |
| 1075 | mScreenPinningNotify.showEscapeToast(isRecentsButtonVisible()); |
| 1076 | } |
| 1077 | |
Jason Monk | 9a6552d | 2016-05-20 11:21:59 -0400 | [diff] [blame] | 1078 | public boolean isVertical() { |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 1079 | return mIsVertical; |
Jason Monk | 9a6552d | 2016-05-20 11:21:59 -0400 | [diff] [blame] | 1080 | } |
| 1081 | |
| 1082 | public void reorient() { |
Jason Monk | 199a2d0 | 2017-07-28 11:08:27 -0400 | [diff] [blame] | 1083 | updateCurrentView(); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1084 | |
Siarhei Vishniakou | fdb4277 | 2017-06-29 10:32:11 -0700 | [diff] [blame] | 1085 | ((NavigationBarFrame) getRootView()).setDeadZone(mDeadZone); |
Matthew Ng | 603b329 | 2018-03-30 17:15:39 -0700 | [diff] [blame] | 1086 | mDeadZone.onConfigurationChanged(mCurrentRotation); |
Daniel Sandler | c26185b | 2012-08-29 15:49:53 -0400 | [diff] [blame] | 1087 | |
Daniel Sandler | 6da2b76 | 2011-09-14 16:04:59 -0400 | [diff] [blame] | 1088 | // force the low profile & disabled states into compliance |
Adrian Roos | 8a8ffd4 | 2015-05-26 18:30:37 -0700 | [diff] [blame] | 1089 | mBarTransitions.init(); |
Daniel Sandler | 6da2b76 | 2011-09-14 16:04:59 -0400 | [diff] [blame] | 1090 | |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 1091 | if (DEBUG) { |
Adrian Roos | a98b32c | 2016-08-11 10:41:08 -0700 | [diff] [blame] | 1092 | Log.d(TAG, "reorient(): rot=" + mCurrentRotation); |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 1093 | } |
Michael Jurka | a5d0ddb | 2012-03-09 17:41:41 -0800 | [diff] [blame] | 1094 | |
Matthew Ng | 5fd8041 | 2018-02-14 14:40:31 -0800 | [diff] [blame] | 1095 | // Resolve layout direction if not resolved since components changing layout direction such |
| 1096 | // as changing languages will recreate this view and the direction will be resolved later |
| 1097 | if (!isLayoutDirectionResolved()) { |
| 1098 | resolveLayoutDirection(); |
| 1099 | } |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 1100 | updateTaskSwitchHelper(); |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 1101 | updateNavButtonIcons(); |
Xiaohui Chen | 9efa5de | 2016-11-22 10:34:38 -0800 | [diff] [blame] | 1102 | |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 1103 | getHomeButton().setVertical(mIsVertical); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1104 | } |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1105 | |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 1106 | private void updateTaskSwitchHelper() { |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 1107 | if (mGestureHelper == null) return; |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 1108 | boolean isRtl = (getLayoutDirection() == View.LAYOUT_DIRECTION_RTL); |
Tiger Huang | 44c0455 | 2018-11-29 20:06:45 +0800 | [diff] [blame] | 1109 | int navBarPos = NAV_BAR_INVALID; |
Matthew Ng | 86a436e | 2018-10-26 16:00:53 -0700 | [diff] [blame] | 1110 | try { |
Tiger Huang | 44c0455 | 2018-11-29 20:06:45 +0800 | [diff] [blame] | 1111 | navBarPos = WindowManagerGlobal.getWindowManagerService().getNavBarPosition( |
Jeff Chang | 2aaa91a | 2018-11-08 18:04:16 +0800 | [diff] [blame] | 1112 | getContext().getDisplayId()); |
Matthew Ng | 86a436e | 2018-10-26 16:00:53 -0700 | [diff] [blame] | 1113 | } catch (RemoteException e) { |
| 1114 | Slog.e(TAG, "Failed to get nav bar position.", e); |
| 1115 | } |
Matthew Ng | b831fb4 | 2019-01-30 11:20:48 -0800 | [diff] [blame] | 1116 | |
| 1117 | // For landscape, hide the panel that would interfere with navigation bar layout |
| 1118 | if (mLeftEdgePanel != null && mRightEdgePanel != null) { |
| 1119 | mLeftEdgePanel.setVisibility(VISIBLE); |
| 1120 | mRightEdgePanel.setVisibility(VISIBLE); |
| 1121 | if (navBarPos == NAV_BAR_LEFT) { |
| 1122 | mLeftEdgePanel.setVisibility(GONE); |
| 1123 | } else if (navBarPos == NAV_BAR_RIGHT) { |
| 1124 | mRightEdgePanel.setVisibility(GONE); |
| 1125 | } |
| 1126 | } |
Matthew Ng | 86a436e | 2018-10-26 16:00:53 -0700 | [diff] [blame] | 1127 | mGestureHelper.setBarState(isRtl, navBarPos); |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 1128 | } |
| 1129 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 1130 | @Override |
| 1131 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 1132 | if (DEBUG) Log.d(TAG, String.format( |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 1133 | "onSizeChanged: (%dx%d) old: (%dx%d)", w, h, oldw, oldh)); |
Daniel Sandler | e03bc95 | 2012-04-27 16:11:22 -0400 | [diff] [blame] | 1134 | |
| 1135 | final boolean newVertical = w > 0 && h > w; |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 1136 | if (newVertical != mIsVertical) { |
| 1137 | mIsVertical = newVertical; |
| 1138 | if (DEBUG) { |
| 1139 | Log.d(TAG, String.format("onSizeChanged: h=%d, w=%d, vert=%s", h, w, |
| 1140 | mIsVertical ? "y" : "n")); |
| 1141 | } |
Daniel Sandler | e03bc95 | 2012-04-27 16:11:22 -0400 | [diff] [blame] | 1142 | reorient(); |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 1143 | notifyVerticalChangedListener(newVertical); |
Daniel Sandler | e03bc95 | 2012-04-27 16:11:22 -0400 | [diff] [blame] | 1144 | } |
| 1145 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 1146 | postCheckForInvalidLayout("sizeChanged"); |
| 1147 | super.onSizeChanged(w, h, oldw, oldh); |
| 1148 | } |
| 1149 | |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 1150 | private void notifyVerticalChangedListener(boolean newVertical) { |
| 1151 | if (mOnVerticalChangedListener != null) { |
| 1152 | mOnVerticalChangedListener.onVerticalChanged(newVertical); |
| 1153 | } |
| 1154 | } |
| 1155 | |
Selim Cinek | 17a327a | 2014-08-25 15:03:48 +0200 | [diff] [blame] | 1156 | @Override |
| 1157 | protected void onConfigurationChanged(Configuration newConfig) { |
| 1158 | super.onConfigurationChanged(newConfig); |
Matthew Ng | 8c056c1 | 2018-10-15 15:16:46 -0700 | [diff] [blame] | 1159 | mTmpLastConfiguration.updateFrom(mConfiguration); |
| 1160 | mConfiguration.updateFrom(newConfig); |
| 1161 | boolean uiCarModeChanged = updateCarMode(); |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 1162 | updateTaskSwitchHelper(); |
Matthew Ng | 8c056c1 | 2018-10-15 15:16:46 -0700 | [diff] [blame] | 1163 | updateIcons(mTmpLastConfiguration); |
Winson | fde2e6a | 2016-03-22 16:03:10 -0700 | [diff] [blame] | 1164 | updateRecentsIcon(); |
Matthew Ng | 8c056c1 | 2018-10-15 15:16:46 -0700 | [diff] [blame] | 1165 | mRecentsOnboarding.onConfigurationChanged(mConfiguration); |
| 1166 | if (uiCarModeChanged || mTmpLastConfiguration.densityDpi != mConfiguration.densityDpi |
| 1167 | || mTmpLastConfiguration.getLayoutDirection() != mConfiguration.getLayoutDirection()) { |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 1168 | // If car mode or density changes, we need to reset the icons. |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 1169 | updateNavButtonIcons(); |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 1170 | } |
Matthew Ng | b55c02c | 2019-02-15 16:20:31 -0800 | [diff] [blame] | 1171 | |
| 1172 | if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) { |
| 1173 | mColorAdaptionController.start(); |
| 1174 | } else { |
| 1175 | mColorAdaptionController.end(); |
| 1176 | } |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 1177 | } |
| 1178 | |
| 1179 | /** |
| 1180 | * If the configuration changed, update the carmode and return that it was updated. |
| 1181 | */ |
Matthew Ng | 8c056c1 | 2018-10-15 15:16:46 -0700 | [diff] [blame] | 1182 | private boolean updateCarMode() { |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 1183 | boolean uiCarModeChanged = false; |
Matthew Ng | 8c056c1 | 2018-10-15 15:16:46 -0700 | [diff] [blame] | 1184 | if (mConfiguration != null) { |
| 1185 | int uiMode = mConfiguration.uiMode & Configuration.UI_MODE_TYPE_MASK; |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 1186 | final boolean isCarMode = (uiMode == Configuration.UI_MODE_TYPE_CAR); |
| 1187 | |
| 1188 | if (isCarMode != mInCarMode) { |
| 1189 | mInCarMode = isCarMode; |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 1190 | if (ALTERNATE_CAR_MODE_UI) { |
| 1191 | mUseCarModeUi = isCarMode; |
| 1192 | uiCarModeChanged = true; |
| 1193 | } else { |
| 1194 | // Don't use car mode behavior if ALTERNATE_CAR_MODE_UI not set. |
| 1195 | mUseCarModeUi = false; |
| 1196 | } |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 1197 | } |
| 1198 | } |
| 1199 | return uiCarModeChanged; |
Selim Cinek | 17a327a | 2014-08-25 15:03:48 +0200 | [diff] [blame] | 1200 | } |
| 1201 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 1202 | /* |
| 1203 | @Override |
| 1204 | protected void onLayout (boolean changed, int left, int top, int right, int bottom) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 1205 | if (DEBUG) Log.d(TAG, String.format( |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 1206 | "onLayout: %s (%d,%d,%d,%d)", |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 1207 | changed?"changed":"notchanged", left, top, right, bottom)); |
| 1208 | super.onLayout(changed, left, top, right, bottom); |
| 1209 | } |
| 1210 | |
| 1211 | // uncomment this for extra defensiveness in WORKAROUND_INVALID_LAYOUT situations: if all else |
| 1212 | // fails, any touch on the display will fix the layout. |
| 1213 | @Override |
| 1214 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 1215 | if (DEBUG) Log.d(TAG, "onInterceptTouchEvent: " + ev.toString()); |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 1216 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
| 1217 | postCheckForInvalidLayout("touch"); |
| 1218 | } |
| 1219 | return super.onInterceptTouchEvent(ev); |
| 1220 | } |
| 1221 | */ |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 1222 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 1223 | |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1224 | private String getResourceName(int resId) { |
| 1225 | if (resId != 0) { |
John Spurlock | 0153478 | 2014-01-13 11:59:22 -0500 | [diff] [blame] | 1226 | final android.content.res.Resources res = getContext().getResources(); |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1227 | try { |
| 1228 | return res.getResourceName(resId); |
| 1229 | } catch (android.content.res.Resources.NotFoundException ex) { |
| 1230 | return "(unknown)"; |
| 1231 | } |
| 1232 | } else { |
| 1233 | return "(null)"; |
| 1234 | } |
| 1235 | } |
| 1236 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 1237 | private void postCheckForInvalidLayout(final String how) { |
| 1238 | mHandler.obtainMessage(MSG_CHECK_INVALID_LAYOUT, 0, 0, how).sendToTarget(); |
| 1239 | } |
| 1240 | |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1241 | private static String visibilityToString(int vis) { |
| 1242 | switch (vis) { |
| 1243 | case View.INVISIBLE: |
| 1244 | return "INVISIBLE"; |
| 1245 | case View.GONE: |
| 1246 | return "GONE"; |
| 1247 | default: |
| 1248 | return "VISIBLE"; |
| 1249 | } |
| 1250 | } |
| 1251 | |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 1252 | @Override |
| 1253 | protected void onAttachedToWindow() { |
| 1254 | super.onAttachedToWindow(); |
Adrian Roos | 7e58a08 | 2018-03-09 16:40:56 +0100 | [diff] [blame] | 1255 | requestApplyInsets(); |
Siarhei Vishniakou | fdb4277 | 2017-06-29 10:32:11 -0700 | [diff] [blame] | 1256 | reorient(); |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 1257 | onPluginDisconnected(null); // Create default gesture helper |
Jason Monk | 5bec68f | 2017-02-08 20:45:10 -0800 | [diff] [blame] | 1258 | Dependency.get(PluginManager.class).addPluginListener(this, |
| 1259 | NavGesture.class, false /* Only one */); |
Winson Chung | f9e3027 | 2018-03-26 17:25:36 -0700 | [diff] [blame] | 1260 | setUpSwipeUpOnboarding(isQuickStepSwipeUpEnabled()); |
Matthew Ng | 355fe21 | 2018-12-14 17:42:38 -0800 | [diff] [blame] | 1261 | mColorAdaptionController.start(); |
Matthew Ng | b831fb4 | 2019-01-30 11:20:48 -0800 | [diff] [blame] | 1262 | |
| 1263 | if (mPrototypeController.isEnabled()) { |
| 1264 | WindowManager wm = (WindowManager) getContext() |
| 1265 | .getSystemService(Context.WINDOW_SERVICE); |
| 1266 | int width = mPrototypeController.getEdgeSensitivityWidth(); |
| 1267 | int height = mPrototypeController.getEdgeSensitivityHeight(); |
Zak Cohen | 8d8d677 | 2019-02-07 16:50:24 -0800 | [diff] [blame] | 1268 | // Explicitly left and right, not start and end as this is device relative. |
Matthew Ng | b831fb4 | 2019-01-30 11:20:48 -0800 | [diff] [blame] | 1269 | mLeftEdgePanel = NavigationBarEdgePanel.create(getContext(), width, height, |
Zak Cohen | 8d8d677 | 2019-02-07 16:50:24 -0800 | [diff] [blame] | 1270 | Gravity.LEFT | Gravity.BOTTOM); |
Matthew Ng | b831fb4 | 2019-01-30 11:20:48 -0800 | [diff] [blame] | 1271 | mRightEdgePanel = NavigationBarEdgePanel.create(getContext(), width, height, |
Zak Cohen | 8d8d677 | 2019-02-07 16:50:24 -0800 | [diff] [blame] | 1272 | Gravity.RIGHT | Gravity.BOTTOM); |
Matthew Ng | b831fb4 | 2019-01-30 11:20:48 -0800 | [diff] [blame] | 1273 | mLeftEdgePanel.setOnTouchListener(mEdgePanelTouchListener); |
| 1274 | mRightEdgePanel.setOnTouchListener(mEdgePanelTouchListener); |
| 1275 | wm.addView(mLeftEdgePanel, mLeftEdgePanel.getLayoutParams()); |
| 1276 | wm.addView(mRightEdgePanel, mRightEdgePanel.getLayoutParams()); |
| 1277 | } |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | @Override |
| 1281 | protected void onDetachedFromWindow() { |
| 1282 | super.onDetachedFromWindow(); |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 1283 | Dependency.get(PluginManager.class).removePluginListener(this); |
| 1284 | if (mGestureHelper != null) { |
| 1285 | mGestureHelper.destroy(); |
| 1286 | } |
Matthew Ng | 1cf6eac | 2018-11-27 15:06:55 -0800 | [diff] [blame] | 1287 | mPrototypeController.unregister(); |
Matthew Ng | 355fe21 | 2018-12-14 17:42:38 -0800 | [diff] [blame] | 1288 | mColorAdaptionController.stop(); |
Tony Wickham | fb63fe8 | 2018-01-16 12:14:06 -0800 | [diff] [blame] | 1289 | setUpSwipeUpOnboarding(false); |
Matthew Ng | 761562d | 2018-09-17 11:13:21 -0700 | [diff] [blame] | 1290 | for (int i = 0; i < mButtonDispatchers.size(); ++i) { |
| 1291 | mButtonDispatchers.valueAt(i).onDestroy(); |
| 1292 | } |
Matthew Ng | b831fb4 | 2019-01-30 11:20:48 -0800 | [diff] [blame] | 1293 | |
Matthew Ng | 33fa275 | 2019-02-14 12:12:50 -0800 | [diff] [blame] | 1294 | WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); |
| 1295 | if (mLeftEdgePanel != null) { |
| 1296 | wm.removeView(mLeftEdgePanel); |
| 1297 | } |
| 1298 | if (mRightEdgePanel != null) { |
| 1299 | wm.removeView(mRightEdgePanel); |
Matthew Ng | b831fb4 | 2019-01-30 11:20:48 -0800 | [diff] [blame] | 1300 | } |
Tony Wickham | fb63fe8 | 2018-01-16 12:14:06 -0800 | [diff] [blame] | 1301 | } |
| 1302 | |
| 1303 | private void setUpSwipeUpOnboarding(boolean connectedToOverviewProxy) { |
| 1304 | if (connectedToOverviewProxy) { |
Tony Wickham | 05c1f85 | 2018-02-06 12:32:54 -0800 | [diff] [blame] | 1305 | mRecentsOnboarding.onConnectedToLauncher(); |
Tony Wickham | fb63fe8 | 2018-01-16 12:14:06 -0800 | [diff] [blame] | 1306 | } else { |
Tony Wickham | 05c1f85 | 2018-02-06 12:32:54 -0800 | [diff] [blame] | 1307 | mRecentsOnboarding.onDisconnectedFromLauncher(); |
Tony Wickham | fb63fe8 | 2018-01-16 12:14:06 -0800 | [diff] [blame] | 1308 | } |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 1309 | } |
| 1310 | |
| 1311 | @Override |
Jason Monk | 20ff3f9 | 2017-01-09 15:13:23 -0500 | [diff] [blame] | 1312 | public void onPluginConnected(NavGesture plugin, Context context) { |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 1313 | mGestureHelper = plugin.getGestureHelper(); |
| 1314 | updateTaskSwitchHelper(); |
| 1315 | } |
| 1316 | |
| 1317 | @Override |
| 1318 | public void onPluginDisconnected(NavGesture plugin) { |
Winson Chung | 0d3815d | 2018-09-25 18:11:54 -0700 | [diff] [blame] | 1319 | QuickStepController defaultHelper = new QuickStepController(getContext()); |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 1320 | defaultHelper.setComponents(this); |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 1321 | if (mGestureHelper != null) { |
| 1322 | mGestureHelper.destroy(); |
| 1323 | } |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 1324 | mGestureHelper = defaultHelper; |
| 1325 | updateTaskSwitchHelper(); |
| 1326 | } |
| 1327 | |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1328 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 1329 | pw.println("NavigationBarView {"); |
| 1330 | final Rect r = new Rect(); |
Jeff Brown | a8b9def | 2012-07-23 14:22:49 -0700 | [diff] [blame] | 1331 | final Point size = new Point(); |
Jeff Chang | 2aaa91a | 2018-11-08 18:04:16 +0800 | [diff] [blame] | 1332 | getContextDisplay().getRealSize(size); |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1333 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 1334 | pw.println(String.format(" this: " + StatusBar.viewInfo(this) |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1335 | + " " + visibilityToString(getVisibility()))); |
| 1336 | |
| 1337 | getWindowVisibleDisplayFrame(r); |
Jeff Brown | a8b9def | 2012-07-23 14:22:49 -0700 | [diff] [blame] | 1338 | final boolean offscreen = r.right > size.x || r.bottom > size.y; |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 1339 | pw.println(" window: " |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1340 | + r.toShortString() |
| 1341 | + " " + visibilityToString(getWindowVisibility()) |
| 1342 | + (offscreen ? " OFFSCREEN!" : "")); |
| 1343 | |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 1344 | pw.println(String.format(" mCurrentView: id=%s (%dx%d) %s %f", |
Rakesh Iyer | f51fe4e | 2016-02-09 10:51:50 -0800 | [diff] [blame] | 1345 | getResourceName(getCurrentView().getId()), |
| 1346 | getCurrentView().getWidth(), getCurrentView().getHeight(), |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 1347 | visibilityToString(getCurrentView().getVisibility()), |
| 1348 | getCurrentView().getAlpha())); |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1349 | |
Matthew Ng | eb0b094 | 2018-10-12 16:42:11 -0700 | [diff] [blame] | 1350 | pw.println(String.format(" disabled=0x%08x vertical=%s menu=%s darkIntensity=%.2f", |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1351 | mDisabledFlags, |
Charles Chen | aa94d95b | 2019-02-19 14:18:19 +0800 | [diff] [blame] | 1352 | mIsVertical ? "true" : "false", |
Matthew Ng | eb0b094 | 2018-10-12 16:42:11 -0700 | [diff] [blame] | 1353 | getMenuButton().isVisible() ? "true" : "false", |
| 1354 | getLightTransitionsController().getCurrentDarkIntensity())); |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1355 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 1356 | dumpButton(pw, "back", getBackButton()); |
| 1357 | dumpButton(pw, "home", getHomeButton()); |
| 1358 | dumpButton(pw, "rcnt", getRecentsButton()); |
| 1359 | dumpButton(pw, "menu", getMenuButton()); |
Matthew Ng | 25593cc | 2018-09-12 16:05:41 -0700 | [diff] [blame] | 1360 | dumpButton(pw, "rota", getRotateSuggestionButton()); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 1361 | dumpButton(pw, "a11y", getAccessibilityButton()); |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1362 | |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1363 | pw.println(" }"); |
Matthew Ng | 25593cc | 2018-09-12 16:05:41 -0700 | [diff] [blame] | 1364 | |
| 1365 | mContextualButtonGroup.dump(pw); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 1366 | if (mGestureHelper != null) { |
Matthew Ng | 86a436e | 2018-10-26 16:00:53 -0700 | [diff] [blame] | 1367 | pw.println("Navigation Gesture Actions {"); |
| 1368 | pw.print(" "); pw.println("QuickScrub Enabled=" + mQuickScrubAction.isEnabled()); |
| 1369 | pw.print(" "); pw.println("QuickScrub Active=" + mQuickScrubAction.isActive()); |
| 1370 | pw.print(" "); pw.println("QuickStep Enabled=" + mQuickStepAction.isEnabled()); |
| 1371 | pw.print(" "); pw.println("QuickStep Active=" + mQuickStepAction.isActive()); |
| 1372 | pw.print(" "); pw.println("Back Gesture Enabled=" + mBackAction.isEnabled()); |
| 1373 | pw.print(" "); pw.println("Back Gesture Active=" + mBackAction.isActive()); |
| 1374 | pw.println("}"); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 1375 | mGestureHelper.dump(pw); |
| 1376 | } |
Matthew Ng | 25593cc | 2018-09-12 16:05:41 -0700 | [diff] [blame] | 1377 | mRecentsOnboarding.dump(pw); |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1378 | } |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 1379 | |
Adrian Roos | 7e58a08 | 2018-03-09 16:40:56 +0100 | [diff] [blame] | 1380 | @Override |
| 1381 | public WindowInsets onApplyWindowInsets(WindowInsets insets) { |
| 1382 | setPadding(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(), |
| 1383 | insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom()); |
| 1384 | return super.onApplyWindowInsets(insets); |
| 1385 | } |
| 1386 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 1387 | private static void dumpButton(PrintWriter pw, String caption, ButtonDispatcher button) { |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 1388 | pw.print(" " + caption + ": "); |
| 1389 | if (button == null) { |
| 1390 | pw.print("null"); |
| 1391 | } else { |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 1392 | pw.print(visibilityToString(button.getVisibility()) |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 1393 | + " alpha=" + button.getAlpha() |
| 1394 | ); |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 1395 | } |
| 1396 | pw.println(); |
| 1397 | } |
| 1398 | |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 1399 | public interface OnVerticalChangedListener { |
| 1400 | void onVerticalChanged(boolean isVertical); |
| 1401 | } |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 1402 | |
Jason Monk | 32e3bb5 | 2017-07-27 12:35:41 -0400 | [diff] [blame] | 1403 | private final Consumer<Boolean> mDockedListener = exists -> mHandler.post(() -> { |
| 1404 | mDockedStackExists = exists; |
| 1405 | updateRecentsIcon(); |
| 1406 | }); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1407 | } |