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