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; |
| 20 | import static com.android.systemui.shared.system.NavigationBarCompat.HIT_TARGET_BACK; |
| 21 | import static com.android.systemui.shared.system.NavigationBarCompat.HIT_TARGET_HOME; |
| 22 | import static com.android.systemui.shared.system.NavigationBarCompat.HIT_TARGET_NONE; |
| 23 | |
John Spurlock | 1bbd49d | 2012-10-19 11:09:32 -0400 | [diff] [blame] | 24 | import android.animation.LayoutTransition; |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 25 | import android.animation.LayoutTransition.TransitionListener; |
| 26 | import android.animation.ObjectAnimator; |
| 27 | import android.animation.TimeInterpolator; |
| 28 | import android.animation.ValueAnimator; |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 29 | import android.annotation.DrawableRes; |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 30 | import android.annotation.StyleRes; |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 31 | import android.app.StatusBarManager; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 32 | import android.content.Context; |
Selim Cinek | 17a327a | 2014-08-25 15:03:48 +0200 | [diff] [blame] | 33 | import android.content.res.Configuration; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 34 | import android.graphics.Canvas; |
Jeff Brown | a8b9def | 2012-07-23 14:22:49 -0700 | [diff] [blame] | 35 | import android.graphics.Point; |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 36 | import android.graphics.Rect; |
Mike Digman | a48cf19 | 2018-02-12 17:52:48 -0800 | [diff] [blame] | 37 | import android.graphics.drawable.AnimatedVectorDrawable; |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 38 | import android.graphics.drawable.Drawable; |
Matthew Ng | 44b1450 | 2018-05-04 11:10:14 -0700 | [diff] [blame] | 39 | import android.os.Bundle; |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 40 | import android.os.Handler; |
| 41 | import android.os.Message; |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 42 | import android.os.SystemProperties; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 43 | import android.support.annotation.ColorInt; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 44 | import android.util.AttributeSet; |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 45 | import android.util.Log; |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 46 | import android.util.SparseArray; |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 47 | import android.view.ContextThemeWrapper; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 48 | import android.view.Display; |
Daniel Sandler | 1d4d30a | 2011-04-28 12:35:29 -0400 | [diff] [blame] | 49 | import android.view.MotionEvent; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 50 | import android.view.Surface; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 51 | import android.view.View; |
John Spurlock | 1bbd49d | 2012-10-19 11:09:32 -0400 | [diff] [blame] | 52 | import android.view.ViewGroup; |
Adrian Roos | 7e58a08 | 2018-03-09 16:40:56 +0100 | [diff] [blame] | 53 | import android.view.WindowInsets; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 54 | import android.view.WindowManager; |
Matthew Ng | 44b1450 | 2018-05-04 11:10:14 -0700 | [diff] [blame] | 55 | import android.view.accessibility.AccessibilityNodeInfo; |
| 56 | import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction; |
Jason Monk | f1ff209 | 2014-04-29 16:50:53 -0400 | [diff] [blame] | 57 | import android.view.inputmethod.InputMethodManager; |
Jason Monk | 86bc331 | 2016-08-16 13:17:56 -0400 | [diff] [blame] | 58 | import android.widget.FrameLayout; |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 59 | |
Jason Monk | 9a376bc | 2017-05-10 09:52:10 -0400 | [diff] [blame] | 60 | import com.android.settingslib.Utils; |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 61 | import com.android.systemui.Dependency; |
Jason Monk | f85fc96 | 2017-04-19 17:13:41 -0400 | [diff] [blame] | 62 | import com.android.systemui.DockedStackExistsListener; |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 63 | import com.android.systemui.OverviewProxyService; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 64 | import com.android.systemui.R; |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 65 | import com.android.systemui.RecentsComponent; |
Matthew Ng | 44b1450 | 2018-05-04 11:10:14 -0700 | [diff] [blame] | 66 | import com.android.systemui.SysUiServiceProvider; |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 67 | import com.android.systemui.plugins.PluginListener; |
| 68 | import com.android.systemui.plugins.PluginManager; |
| 69 | import com.android.systemui.plugins.statusbar.phone.NavGesture; |
| 70 | import com.android.systemui.plugins.statusbar.phone.NavGesture.GestureHelper; |
Matthew Ng | 44b1450 | 2018-05-04 11:10:14 -0700 | [diff] [blame] | 71 | import com.android.systemui.recents.Recents; |
Tony Wickham | 05c1f85 | 2018-02-06 12:32:54 -0800 | [diff] [blame] | 72 | import com.android.systemui.recents.RecentsOnboarding; |
Matthew Ng | 44b1450 | 2018-05-04 11:10:14 -0700 | [diff] [blame] | 73 | import com.android.systemui.shared.recents.IOverviewProxy; |
Matthew Ng | 87cbf34 | 2018-02-15 12:21:18 -0800 | [diff] [blame] | 74 | import com.android.systemui.shared.system.ActivityManagerWrapper; |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 75 | import com.android.systemui.shared.system.NavigationBarCompat; |
Matthew Ng | 84db161 | 2018-04-17 16:48:21 -0700 | [diff] [blame] | 76 | import com.android.systemui.shared.system.WindowManagerWrapper; |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 77 | import com.android.systemui.stackdivider.Divider; |
Daniel Sandler | c26185b | 2012-08-29 15:49:53 -0400 | [diff] [blame] | 78 | import com.android.systemui.statusbar.policy.DeadZone; |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 79 | import com.android.systemui.statusbar.policy.KeyButtonDrawable; |
Tony Wickham | fb63fe8 | 2018-01-16 12:14:06 -0800 | [diff] [blame] | 80 | import com.android.systemui.statusbar.policy.TintedKeyButtonDrawable; |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 81 | |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 82 | import java.io.FileDescriptor; |
| 83 | import java.io.PrintWriter; |
Jason Monk | 32e3bb5 | 2017-07-27 12:35:41 -0400 | [diff] [blame] | 84 | import java.util.function.Consumer; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 85 | |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 86 | import static com.android.systemui.shared.system.NavigationBarCompat.FLAG_DISABLE_QUICK_SCRUB; |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 87 | import static com.android.systemui.shared.system.NavigationBarCompat.FLAG_SHOW_OVERVIEW_BUTTON; |
Matthew Ng | 8a8c89c | 2018-03-01 13:21:43 -0800 | [diff] [blame] | 88 | import static com.android.systemui.shared.system.NavigationBarCompat.HIT_TARGET_OVERVIEW; |
Winson Chung | 8079af7 | 2018-05-10 11:12:55 -0700 | [diff] [blame] | 89 | import static com.android.systemui.shared.system.NavigationBarCompat.HIT_TARGET_ROTATION; |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 90 | |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 91 | public class NavigationBarView extends FrameLayout implements PluginListener<NavGesture> { |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 92 | final static boolean DEBUG = false; |
Adrian Roos | a98b32c | 2016-08-11 10:41:08 -0700 | [diff] [blame] | 93 | final static String TAG = "StatusBar/NavBarView"; |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 94 | |
Daniel Sandler | c3fc322 | 2012-10-25 13:28:33 -0400 | [diff] [blame] | 95 | // slippery nav bar when everything is disabled, e.g. during setup |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 96 | final static boolean SLIPPERY_WHEN_DISABLED = true; |
Daniel Sandler | c3fc322 | 2012-10-25 13:28:33 -0400 | [diff] [blame] | 97 | |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 98 | final static boolean ALTERNATE_CAR_MODE_UI = false; |
| 99 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 100 | final Display mDisplay; |
Daniel Sandler | 5c8da94 | 2011-06-28 00:29:04 -0400 | [diff] [blame] | 101 | View mCurrentView = null; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 102 | View[] mRotatedViews = new View[4]; |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 103 | |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 104 | boolean mVertical; |
Adrian Roos | 090b7d8 | 2016-08-02 18:36:12 -0700 | [diff] [blame] | 105 | private int mCurrentRotation = -1; |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 106 | |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 107 | boolean mShowMenu; |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 108 | boolean mShowAccessibilityButton; |
| 109 | boolean mLongClickableAccessibilityButton; |
Mike Digman | a48cf19 | 2018-02-12 17:52:48 -0800 | [diff] [blame] | 110 | boolean mShowRotateButton; |
Daniel Sandler | 6da2b76 | 2011-09-14 16:04:59 -0400 | [diff] [blame] | 111 | int mDisabledFlags = 0; |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 112 | int mNavigationIconHints = 0; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 113 | |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 114 | private @NavigationBarCompat.HitTarget int mDownHitTarget = HIT_TARGET_NONE; |
| 115 | private Rect mHomeButtonBounds = new Rect(); |
| 116 | private Rect mBackButtonBounds = new Rect(); |
Matthew Ng | 8a8c89c | 2018-03-01 13:21:43 -0800 | [diff] [blame] | 117 | private Rect mRecentsButtonBounds = new Rect(); |
Winson Chung | 8079af7 | 2018-05-10 11:12:55 -0700 | [diff] [blame] | 118 | private Rect mRotationButtonBounds = new Rect(); |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 119 | private int[] mTmpPosition = new int[2]; |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 120 | private Rect mTmpRect = new Rect(); |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 121 | |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 122 | private KeyButtonDrawable mBackIcon; |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 123 | private KeyButtonDrawable mBackCarModeIcon, mBackLandCarModeIcon; |
| 124 | private KeyButtonDrawable mBackAltCarModeIcon, mBackAltLandCarModeIcon; |
| 125 | private KeyButtonDrawable mHomeDefaultIcon, mHomeCarModeIcon; |
| 126 | private KeyButtonDrawable mRecentIcon; |
| 127 | private KeyButtonDrawable mDockedIcon; |
| 128 | private KeyButtonDrawable mImeIcon; |
| 129 | private KeyButtonDrawable mMenuIcon; |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 130 | private KeyButtonDrawable mAccessibilityIcon; |
Mike Digman | c821758 | 2018-03-06 13:08:33 -0800 | [diff] [blame] | 131 | private TintedKeyButtonDrawable mRotateSuggestionIcon; |
Fabrice Di Meglio | 18d9824 | 2013-01-17 10:57:40 -0800 | [diff] [blame] | 132 | |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 133 | private GestureHelper mGestureHelper; |
Matthew Ng | 603b329 | 2018-03-30 17:15:39 -0700 | [diff] [blame] | 134 | private final DeadZone mDeadZone; |
Matthew Ng | 1e14e96 | 2018-05-03 12:51:43 -0700 | [diff] [blame] | 135 | private boolean mDeadZoneConsuming = false; |
John Spurlock | 89835dd | 2013-08-16 15:06:51 -0400 | [diff] [blame] | 136 | private final NavigationBarTransitions mBarTransitions; |
Matthew Ng | dc79e5c | 2017-12-14 17:37:35 -0800 | [diff] [blame] | 137 | private final OverviewProxyService mOverviewProxyService; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 138 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 139 | // workaround for LayoutTransitions leaving the nav buttons in a weird state (bug 5549288) |
| 140 | final static boolean WORKAROUND_INVALID_LAYOUT = true; |
| 141 | final static int MSG_CHECK_INVALID_LAYOUT = 8686; |
| 142 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 143 | // performs manual animation in sync with layout transitions |
| 144 | private final NavTransitionListener mTransitionListener = new NavTransitionListener(); |
| 145 | |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 146 | private OnVerticalChangedListener mOnVerticalChangedListener; |
Jorim Jaggi | 37c1180 | 2015-08-18 20:27:54 -0700 | [diff] [blame] | 147 | private boolean mLayoutTransitionsEnabled = true; |
| 148 | private boolean mWakeAndUnlocking; |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 149 | private boolean mUseCarModeUi = false; |
| 150 | private boolean mInCarMode = false; |
Jorim Jaggi | d30d95d | 2016-02-17 20:27:22 -0800 | [diff] [blame] | 151 | private boolean mDockedStackExists; |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 152 | |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 153 | private final SparseArray<ButtonDispatcher> mButtonDispatchers = new SparseArray<>(); |
Winson | fde2e6a | 2016-03-22 16:03:10 -0700 | [diff] [blame] | 154 | private Configuration mConfiguration; |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 155 | |
Adrian Roos | db12b15 | 2016-07-12 15:38:55 -0700 | [diff] [blame] | 156 | private NavigationBarInflaterView mNavigationInflaterView; |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 157 | private RecentsComponent mRecentsComponent; |
| 158 | private Divider mDivider; |
Tony Wickham | 05c1f85 | 2018-02-06 12:32:54 -0800 | [diff] [blame] | 159 | private RecentsOnboarding mRecentsOnboarding; |
Matthew Ng | 78f88d1 | 2018-01-23 12:39:55 -0800 | [diff] [blame] | 160 | private NotificationPanelView mPanelView; |
Adrian Roos | db12b15 | 2016-07-12 15:38:55 -0700 | [diff] [blame] | 161 | |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 162 | private int mRotateBtnStyle = R.style.RotateButtonCCWStart90; |
Mike Digman | a48cf19 | 2018-02-12 17:52:48 -0800 | [diff] [blame] | 163 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 164 | private class NavTransitionListener implements TransitionListener { |
| 165 | private boolean mBackTransitioning; |
| 166 | private boolean mHomeAppearing; |
| 167 | private long mStartDelay; |
| 168 | private long mDuration; |
| 169 | private TimeInterpolator mInterpolator; |
| 170 | |
| 171 | @Override |
| 172 | public void startTransition(LayoutTransition transition, ViewGroup container, |
| 173 | View view, int transitionType) { |
| 174 | if (view.getId() == R.id.back) { |
| 175 | mBackTransitioning = true; |
| 176 | } else if (view.getId() == R.id.home && transitionType == LayoutTransition.APPEARING) { |
| 177 | mHomeAppearing = true; |
| 178 | mStartDelay = transition.getStartDelay(transitionType); |
| 179 | mDuration = transition.getDuration(transitionType); |
| 180 | mInterpolator = transition.getInterpolator(transitionType); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | @Override |
| 185 | public void endTransition(LayoutTransition transition, ViewGroup container, |
| 186 | View view, int transitionType) { |
| 187 | if (view.getId() == R.id.back) { |
| 188 | mBackTransitioning = false; |
| 189 | } else if (view.getId() == R.id.home && transitionType == LayoutTransition.APPEARING) { |
| 190 | mHomeAppearing = false; |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | public void onBackAltCleared() { |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 195 | ButtonDispatcher backButton = getBackButton(); |
Anthony Chen | ada1304 | 2016-01-19 16:57:20 -0800 | [diff] [blame] | 196 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 197 | // When dismissing ime during unlock, force the back button to run the same appearance |
| 198 | // animation as home (if we catch this condition early enough). |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 199 | if (!mBackTransitioning && backButton.getVisibility() == VISIBLE |
| 200 | && mHomeAppearing && getHomeButton().getAlpha() == 0) { |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 201 | getBackButton().setAlpha(0); |
Anthony Chen | ada1304 | 2016-01-19 16:57:20 -0800 | [diff] [blame] | 202 | ValueAnimator a = ObjectAnimator.ofFloat(backButton, "alpha", 0, 1); |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 203 | a.setStartDelay(mStartDelay); |
| 204 | a.setDuration(mDuration); |
| 205 | a.setInterpolator(mInterpolator); |
| 206 | a.start(); |
| 207 | } |
| 208 | } |
| 209 | } |
| 210 | |
Jason Monk | f1ff209 | 2014-04-29 16:50:53 -0400 | [diff] [blame] | 211 | private final OnClickListener mImeSwitcherClickListener = new OnClickListener() { |
| 212 | @Override |
| 213 | public void onClick(View view) { |
Yohei Yukawa | 777ef95 | 2015-11-25 20:32:24 -0800 | [diff] [blame] | 214 | mContext.getSystemService(InputMethodManager.class) |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 215 | .showInputMethodPicker(true /* showAuxiliarySubtypes */); |
Jason Monk | f1ff209 | 2014-04-29 16:50:53 -0400 | [diff] [blame] | 216 | } |
| 217 | }; |
| 218 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 219 | private class H extends Handler { |
| 220 | public void handleMessage(Message m) { |
| 221 | switch (m.what) { |
| 222 | case MSG_CHECK_INVALID_LAYOUT: |
| 223 | final String how = "" + m.obj; |
| 224 | final int w = getWidth(); |
| 225 | final int h = getHeight(); |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 226 | final int vw = getCurrentView().getWidth(); |
| 227 | final int vh = getCurrentView().getHeight(); |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 228 | |
| 229 | if (h != vh || w != vw) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 230 | Log.w(TAG, String.format( |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 231 | "*** Invalid layout in navigation bar (%s this=%dx%d cur=%dx%d)", |
| 232 | how, w, h, vw, vh)); |
| 233 | if (WORKAROUND_INVALID_LAYOUT) { |
| 234 | requestLayout(); |
| 235 | } |
| 236 | } |
| 237 | break; |
| 238 | } |
| 239 | } |
| 240 | } |
| 241 | |
Matthew Ng | 44b1450 | 2018-05-04 11:10:14 -0700 | [diff] [blame] | 242 | private final AccessibilityDelegate mQuickStepAccessibilityDelegate |
| 243 | = new AccessibilityDelegate() { |
| 244 | private AccessibilityAction mToggleOverviewAction; |
| 245 | |
| 246 | @Override |
| 247 | public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) { |
| 248 | super.onInitializeAccessibilityNodeInfo(host, info); |
| 249 | if (mToggleOverviewAction == null) { |
| 250 | mToggleOverviewAction = new AccessibilityAction(R.id.action_toggle_overview, |
| 251 | getContext().getString(R.string.quick_step_accessibility_toggle_overview)); |
| 252 | } |
| 253 | info.addAction(mToggleOverviewAction); |
| 254 | } |
| 255 | |
| 256 | @Override |
| 257 | public boolean performAccessibilityAction(View host, int action, Bundle args) { |
| 258 | switch (action) { |
| 259 | case R.id.action_toggle_overview: |
| 260 | SysUiServiceProvider.getComponent(getContext(), Recents.class) |
| 261 | .toggleRecentApps(); |
| 262 | break; |
| 263 | default: |
| 264 | return super.performAccessibilityAction(host, action, args); |
| 265 | } |
| 266 | return true; |
| 267 | } |
| 268 | }; |
| 269 | |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 270 | public NavigationBarView(Context context, AttributeSet attrs) { |
| 271 | super(context, attrs); |
| 272 | |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 273 | mDisplay = ((WindowManager) context.getSystemService( |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 274 | Context.WINDOW_SERVICE)).getDefaultDisplay(); |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 275 | |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 276 | mVertical = false; |
| 277 | mShowMenu = false; |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 278 | |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 279 | mShowAccessibilityButton = false; |
| 280 | mLongClickableAccessibilityButton = false; |
| 281 | |
Matthew Ng | f294654 | 2018-02-12 14:13:18 -0800 | [diff] [blame] | 282 | mOverviewProxyService = Dependency.get(OverviewProxyService.class); |
| 283 | mRecentsOnboarding = new RecentsOnboarding(context, mOverviewProxyService); |
| 284 | |
Winson | fde2e6a | 2016-03-22 16:03:10 -0700 | [diff] [blame] | 285 | mConfiguration = new Configuration(); |
| 286 | mConfiguration.updateFrom(context.getResources().getConfiguration()); |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 287 | reloadNavIcons(); |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 288 | |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 289 | mBarTransitions = new NavigationBarTransitions(this); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 290 | |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 291 | mButtonDispatchers.put(R.id.back, new ButtonDispatcher(R.id.back)); |
| 292 | mButtonDispatchers.put(R.id.home, new ButtonDispatcher(R.id.home)); |
| 293 | mButtonDispatchers.put(R.id.recent_apps, new ButtonDispatcher(R.id.recent_apps)); |
| 294 | mButtonDispatchers.put(R.id.menu, new ButtonDispatcher(R.id.menu)); |
| 295 | mButtonDispatchers.put(R.id.ime_switcher, new ButtonDispatcher(R.id.ime_switcher)); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 296 | mButtonDispatchers.put(R.id.accessibility_button, |
| 297 | new ButtonDispatcher(R.id.accessibility_button)); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 298 | mButtonDispatchers.put(R.id.rotate_suggestion, |
| 299 | new ButtonDispatcher(R.id.rotate_suggestion)); |
Matthew Ng | 6607c3d | 2018-04-26 15:23:27 -0700 | [diff] [blame] | 300 | mButtonDispatchers.put(R.id.menu_container, |
| 301 | new ButtonDispatcher(R.id.menu_container)); |
Matthew Ng | 603b329 | 2018-03-30 17:15:39 -0700 | [diff] [blame] | 302 | mDeadZone = new DeadZone(this); |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | public BarTransitions getBarTransitions() { |
| 306 | return mBarTransitions; |
| 307 | } |
| 308 | |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 309 | public LightBarTransitionsController getLightTransitionsController() { |
| 310 | return mBarTransitions.getLightTransitionsController(); |
| 311 | } |
| 312 | |
Matthew Ng | 78f88d1 | 2018-01-23 12:39:55 -0800 | [diff] [blame] | 313 | public void setComponents(RecentsComponent recentsComponent, Divider divider, |
| 314 | NotificationPanelView panel) { |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 315 | mRecentsComponent = recentsComponent; |
| 316 | mDivider = divider; |
Matthew Ng | 78f88d1 | 2018-01-23 12:39:55 -0800 | [diff] [blame] | 317 | mPanelView = panel; |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 318 | if (mGestureHelper instanceof NavigationBarGestureHelper) { |
| 319 | ((NavigationBarGestureHelper) mGestureHelper).setComponents( |
| 320 | recentsComponent, divider, this); |
| 321 | } |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 322 | } |
| 323 | |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 324 | public void setOnVerticalChangedListener(OnVerticalChangedListener onVerticalChangedListener) { |
| 325 | mOnVerticalChangedListener = onVerticalChangedListener; |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 326 | notifyVerticalChangedListener(mVertical); |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 327 | } |
| 328 | |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 329 | @Override |
| 330 | public boolean onInterceptTouchEvent(MotionEvent event) { |
Matthew Ng | 1e14e96 | 2018-05-03 12:51:43 -0700 | [diff] [blame] | 331 | if (shouldDeadZoneConsumeTouchEvents(event)) { |
Matthew Ng | 603b329 | 2018-03-30 17:15:39 -0700 | [diff] [blame] | 332 | return true; |
| 333 | } |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 334 | switch (event.getActionMasked()) { |
| 335 | case ACTION_DOWN: |
| 336 | int x = (int) event.getX(); |
| 337 | int y = (int) event.getY(); |
| 338 | mDownHitTarget = HIT_TARGET_NONE; |
Winson Chung | c6c9d40 | 2018-05-25 18:25:52 -0700 | [diff] [blame] | 339 | if (getBackButton().isVisible() && mBackButtonBounds.contains(x, y)) { |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 340 | mDownHitTarget = HIT_TARGET_BACK; |
Winson Chung | c6c9d40 | 2018-05-25 18:25:52 -0700 | [diff] [blame] | 341 | } else if (getHomeButton().isVisible() && mHomeButtonBounds.contains(x, y)) { |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 342 | mDownHitTarget = HIT_TARGET_HOME; |
Winson Chung | c6c9d40 | 2018-05-25 18:25:52 -0700 | [diff] [blame] | 343 | } else if (getRecentsButton().isVisible() && mRecentsButtonBounds.contains(x, y)) { |
Matthew Ng | 8a8c89c | 2018-03-01 13:21:43 -0800 | [diff] [blame] | 344 | mDownHitTarget = HIT_TARGET_OVERVIEW; |
Winson Chung | c6c9d40 | 2018-05-25 18:25:52 -0700 | [diff] [blame] | 345 | } else if (getRotateSuggestionButton().isVisible() |
| 346 | && mRotationButtonBounds.contains(x, y)) { |
Winson Chung | 8079af7 | 2018-05-10 11:12:55 -0700 | [diff] [blame] | 347 | mDownHitTarget = HIT_TARGET_ROTATION; |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 348 | } |
| 349 | break; |
| 350 | } |
Winson Chung | 4965884 | 2018-02-08 12:52:21 -0800 | [diff] [blame] | 351 | return mGestureHelper.onInterceptTouchEvent(event); |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Winson Chung | 4faf38a | 2018-02-06 08:53:37 -0800 | [diff] [blame] | 354 | @Override |
| 355 | public boolean onTouchEvent(MotionEvent event) { |
Matthew Ng | 1e14e96 | 2018-05-03 12:51:43 -0700 | [diff] [blame] | 356 | if (shouldDeadZoneConsumeTouchEvents(event)) { |
Matthew Ng | 603b329 | 2018-03-30 17:15:39 -0700 | [diff] [blame] | 357 | return true; |
| 358 | } |
Winson Chung | 4faf38a | 2018-02-06 08:53:37 -0800 | [diff] [blame] | 359 | if (mGestureHelper.onTouchEvent(event)) { |
| 360 | return true; |
| 361 | } |
Winson Chung | 4965884 | 2018-02-08 12:52:21 -0800 | [diff] [blame] | 362 | return super.onTouchEvent(event); |
Winson Chung | 4faf38a | 2018-02-06 08:53:37 -0800 | [diff] [blame] | 363 | } |
| 364 | |
Matthew Ng | 1e14e96 | 2018-05-03 12:51:43 -0700 | [diff] [blame] | 365 | private boolean shouldDeadZoneConsumeTouchEvents(MotionEvent event) { |
| 366 | if (mDeadZone.onTouchEvent(event) || mDeadZoneConsuming) { |
| 367 | switch (event.getActionMasked()) { |
| 368 | case MotionEvent.ACTION_DOWN: |
| 369 | // Allow gestures starting in the deadzone to be slippery |
| 370 | setSlippery(true); |
| 371 | mDeadZoneConsuming = true; |
| 372 | break; |
| 373 | case MotionEvent.ACTION_CANCEL: |
| 374 | case MotionEvent.ACTION_UP: |
| 375 | // When a gesture started in the deadzone is finished, restore slippery state |
| 376 | updateSlippery(); |
| 377 | mDeadZoneConsuming = false; |
| 378 | break; |
| 379 | } |
| 380 | return true; |
| 381 | } |
| 382 | return false; |
| 383 | } |
| 384 | |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 385 | public @NavigationBarCompat.HitTarget int getDownHitTarget() { |
| 386 | return mDownHitTarget; |
| 387 | } |
| 388 | |
Xiyuan Xia | ee7dd05 | 2015-05-15 09:46:27 -0700 | [diff] [blame] | 389 | public void abortCurrentGesture() { |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 390 | getHomeButton().abortCurrentGesture(); |
Xiyuan Xia | ee7dd05 | 2015-05-15 09:46:27 -0700 | [diff] [blame] | 391 | } |
| 392 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 393 | private H mHandler = new H(); |
| 394 | |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 395 | public View getCurrentView() { |
| 396 | return mCurrentView; |
| 397 | } |
| 398 | |
Xiaohui Chen | 1094230 | 2015-12-16 16:38:13 -0800 | [diff] [blame] | 399 | public View[] getAllViews() { |
| 400 | return mRotatedViews; |
| 401 | } |
| 402 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 403 | public ButtonDispatcher getRecentsButton() { |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 404 | return mButtonDispatchers.get(R.id.recent_apps); |
Daniel Sandler | 5c8da94 | 2011-06-28 00:29:04 -0400 | [diff] [blame] | 405 | } |
| 406 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 407 | public ButtonDispatcher getMenuButton() { |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 408 | return mButtonDispatchers.get(R.id.menu); |
Daniel Sandler | 5c8da94 | 2011-06-28 00:29:04 -0400 | [diff] [blame] | 409 | } |
| 410 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 411 | public ButtonDispatcher getBackButton() { |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 412 | return mButtonDispatchers.get(R.id.back); |
Mike Lockwood | e3646dd | 2011-09-01 12:46:28 -0400 | [diff] [blame] | 413 | } |
| 414 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 415 | public ButtonDispatcher getHomeButton() { |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 416 | return mButtonDispatchers.get(R.id.home); |
Mike Lockwood | e3646dd | 2011-09-01 12:46:28 -0400 | [diff] [blame] | 417 | } |
| 418 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 419 | public ButtonDispatcher getImeSwitchButton() { |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 420 | return mButtonDispatchers.get(R.id.ime_switcher); |
Jason Monk | f1ff209 | 2014-04-29 16:50:53 -0400 | [diff] [blame] | 421 | } |
| 422 | |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 423 | public ButtonDispatcher getAccessibilityButton() { |
| 424 | return mButtonDispatchers.get(R.id.accessibility_button); |
| 425 | } |
| 426 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 427 | public ButtonDispatcher getRotateSuggestionButton() { |
| 428 | return mButtonDispatchers.get(R.id.rotate_suggestion); |
| 429 | } |
| 430 | |
Matthew Ng | 6607c3d | 2018-04-26 15:23:27 -0700 | [diff] [blame] | 431 | public ButtonDispatcher getMenuContainer() { |
| 432 | return mButtonDispatchers.get(R.id.menu_container); |
| 433 | } |
| 434 | |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 435 | public SparseArray<ButtonDispatcher> getButtonDispatchers() { |
| 436 | return mButtonDispatchers; |
| 437 | } |
| 438 | |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 439 | public boolean isRecentsButtonVisible() { |
| 440 | return getRecentsButton().getVisibility() == View.VISIBLE; |
| 441 | } |
| 442 | |
Matthew Ng | 6ff33b7 | 2018-02-27 13:47:38 -0800 | [diff] [blame] | 443 | public boolean isOverviewEnabled() { |
| 444 | return (mDisabledFlags & View.STATUS_BAR_DISABLE_RECENT) == 0; |
| 445 | } |
| 446 | |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 447 | public boolean isQuickStepSwipeUpEnabled() { |
Matthew Ng | c1a97b1 | 2018-03-28 14:02:00 -0700 | [diff] [blame] | 448 | return mOverviewProxyService.shouldShowSwipeUpUI() && isOverviewEnabled(); |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | public boolean isQuickScrubEnabled() { |
| 452 | return SystemProperties.getBoolean("persist.quickstep.scrub.enabled", true) |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 453 | && mOverviewProxyService.isEnabled() && isOverviewEnabled() |
Matthew Ng | c1a97b1 | 2018-03-28 14:02:00 -0700 | [diff] [blame] | 454 | && ((mOverviewProxyService.getInteractionFlags() & FLAG_DISABLE_QUICK_SCRUB) == 0); |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 455 | } |
| 456 | |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 457 | // TODO(b/80003212): change car mode icons to vector icons. |
Winson | fde2e6a | 2016-03-22 16:03:10 -0700 | [diff] [blame] | 458 | private void updateCarModeIcons(Context ctx) { |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 459 | mBackCarModeIcon = getDrawable(ctx, |
| 460 | R.drawable.ic_sysbar_back_carmode, R.drawable.ic_sysbar_back_carmode); |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 461 | mBackLandCarModeIcon = mBackCarModeIcon; |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 462 | mBackAltCarModeIcon = getDrawable(ctx, |
| 463 | R.drawable.ic_sysbar_back_ime_carmode, R.drawable.ic_sysbar_back_ime_carmode); |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 464 | mBackAltLandCarModeIcon = mBackAltCarModeIcon; |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 465 | mHomeCarModeIcon = getDrawable(ctx, |
| 466 | R.drawable.ic_sysbar_home_carmode, R.drawable.ic_sysbar_home_carmode); |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 467 | } |
| 468 | |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 469 | private void reloadNavIcons() { |
| 470 | updateIcons(mContext, Configuration.EMPTY, mConfiguration); |
| 471 | } |
| 472 | |
Winson | fde2e6a | 2016-03-22 16:03:10 -0700 | [diff] [blame] | 473 | private void updateIcons(Context ctx, Configuration oldConfig, Configuration newConfig) { |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 474 | int dualToneDarkTheme = Utils.getThemeAttr(ctx, R.attr.darkIconTheme); |
| 475 | int dualToneLightTheme = Utils.getThemeAttr(ctx, R.attr.lightIconTheme); |
| 476 | Context lightContext = new ContextThemeWrapper(ctx, dualToneLightTheme); |
| 477 | Context darkContext = new ContextThemeWrapper(ctx, dualToneDarkTheme); |
| 478 | |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 479 | if (oldConfig.orientation != newConfig.orientation |
| 480 | || oldConfig.densityDpi != newConfig.densityDpi) { |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 481 | mDockedIcon = getDrawable(lightContext, darkContext, R.drawable.ic_sysbar_docked); |
| 482 | mHomeDefaultIcon = getHomeDrawable(lightContext, darkContext); |
Winson | fde2e6a | 2016-03-22 16:03:10 -0700 | [diff] [blame] | 483 | } |
Jason Monk | 1f785d4 | 2017-07-25 15:46:33 -0400 | [diff] [blame] | 484 | if (oldConfig.densityDpi != newConfig.densityDpi |
| 485 | || oldConfig.getLayoutDirection() != newConfig.getLayoutDirection()) { |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 486 | mBackIcon = getBackDrawable(lightContext, darkContext); |
| 487 | mRecentIcon = getDrawable(lightContext, darkContext, R.drawable.ic_sysbar_recent); |
| 488 | mMenuIcon = getDrawable(lightContext, darkContext, R.drawable.ic_sysbar_menu); |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 489 | |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 490 | mAccessibilityIcon = getDrawable(lightContext, darkContext, |
| 491 | R.drawable.ic_sysbar_accessibility_button, false /* hasShadow */); |
Mike Digman | e3909de | 2018-03-30 11:22:05 -0700 | [diff] [blame] | 492 | |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 493 | mImeIcon = getDrawable(lightContext, darkContext, R.drawable.ic_ime_switcher_default, |
| 494 | false /* hasShadow */); |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 495 | |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 496 | updateRotateSuggestionButtonStyle(mRotateBtnStyle, false); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 497 | |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 498 | if (ALTERNATE_CAR_MODE_UI) { |
| 499 | updateCarModeIcons(ctx); |
| 500 | } |
Winson | fde2e6a | 2016-03-22 16:03:10 -0700 | [diff] [blame] | 501 | } |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 502 | } |
| 503 | |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 504 | public KeyButtonDrawable getBackDrawable(Context lightContext, Context darkContext) { |
| 505 | KeyButtonDrawable drawable = chooseNavigationIconDrawable(lightContext, darkContext, |
| 506 | R.drawable.ic_sysbar_back, R.drawable.ic_sysbar_back_quick_step); |
| 507 | orientBackButton(drawable); |
| 508 | return drawable; |
Matthew Ng | 87cbf34 | 2018-02-15 12:21:18 -0800 | [diff] [blame] | 509 | } |
| 510 | |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 511 | public KeyButtonDrawable getHomeDrawable(Context lightContext, Context darkContext) { |
| 512 | final boolean quickStepEnabled = mOverviewProxyService.shouldShowSwipeUpUI(); |
| 513 | KeyButtonDrawable drawable = quickStepEnabled |
| 514 | ? getDrawable(lightContext, darkContext, R.drawable.ic_sysbar_home_quick_step) |
| 515 | : getDrawable(lightContext, darkContext, R.drawable.ic_sysbar_home, |
| 516 | false /* hasShadow */); |
| 517 | orientHomeButton(drawable); |
| 518 | return drawable; |
Matthew Ng | 87cbf34 | 2018-02-15 12:21:18 -0800 | [diff] [blame] | 519 | } |
| 520 | |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 521 | private void orientBackButton(KeyButtonDrawable drawable) { |
| 522 | final boolean useAltBack = |
| 523 | (mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) != 0; |
| 524 | drawable.setRotation(useAltBack |
| 525 | ? -90 : (getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) ? 180 : 0); |
Matthew Ng | 87cbf34 | 2018-02-15 12:21:18 -0800 | [diff] [blame] | 526 | } |
| 527 | |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 528 | private void orientHomeButton(KeyButtonDrawable drawable) { |
| 529 | drawable.setRotation(mVertical ? 90 : 0); |
| 530 | } |
| 531 | |
| 532 | private KeyButtonDrawable chooseNavigationIconDrawable(Context lightContext, |
| 533 | Context darkContext, @DrawableRes int icon, @DrawableRes int quickStepIcon) { |
Matthew Ng | c1a97b1 | 2018-03-28 14:02:00 -0700 | [diff] [blame] | 534 | final boolean quickStepEnabled = mOverviewProxyService.shouldShowSwipeUpUI(); |
Matthew Ng | 87cbf34 | 2018-02-15 12:21:18 -0800 | [diff] [blame] | 535 | return quickStepEnabled |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 536 | ? getDrawable(lightContext, darkContext, quickStepIcon) |
| 537 | : getDrawable(lightContext, darkContext, icon); |
| 538 | } |
| 539 | |
| 540 | private KeyButtonDrawable getDrawable(Context lightContext, Context darkContext, |
| 541 | @DrawableRes int icon) { |
| 542 | return getDrawable(lightContext, darkContext, icon, true /* hasShadow */); |
| 543 | } |
| 544 | |
| 545 | private KeyButtonDrawable getDrawable(Context lightContext, Context darkContext, |
| 546 | @DrawableRes int icon, boolean hasShadow) { |
| 547 | return KeyButtonDrawable.create(lightContext, lightContext.getDrawable(icon), |
| 548 | darkContext.getDrawable(icon), hasShadow); |
Matthew Ng | 87cbf34 | 2018-02-15 12:21:18 -0800 | [diff] [blame] | 549 | } |
| 550 | |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 551 | private KeyButtonDrawable getDrawable(Context ctx, @DrawableRes int lightIcon, |
| 552 | @DrawableRes int darkIcon) { |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 553 | // Legacy image icons using separate light and dark images will not support shadows |
| 554 | return KeyButtonDrawable.create(ctx, ctx.getDrawable(lightIcon), |
| 555 | ctx.getDrawable(darkIcon), false /* hasShadow */); |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 556 | } |
| 557 | |
Mike Digman | c821758 | 2018-03-06 13:08:33 -0800 | [diff] [blame] | 558 | private TintedKeyButtonDrawable getDrawable(Context ctx, @DrawableRes int icon, |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 559 | @ColorInt int lightColor, @ColorInt int darkColor) { |
| 560 | return TintedKeyButtonDrawable.create(ctx.getDrawable(icon), lightColor, darkColor); |
| 561 | } |
| 562 | |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 563 | @Override |
| 564 | public void setLayoutDirection(int layoutDirection) { |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 565 | reloadNavIcons(); |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 566 | |
| 567 | super.setLayoutDirection(layoutDirection); |
Daniel Sandler | 1d4d30a | 2011-04-28 12:35:29 -0400 | [diff] [blame] | 568 | } |
| 569 | |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 570 | private KeyButtonDrawable getBackIconWithAlt(boolean carMode, boolean landscape) { |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 571 | return landscape |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 572 | ? carMode ? mBackAltLandCarModeIcon : mBackIcon |
| 573 | : carMode ? mBackAltCarModeIcon : mBackIcon; |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 574 | } |
| 575 | |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 576 | private KeyButtonDrawable getBackIcon(boolean carMode, boolean landscape) { |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 577 | return landscape |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 578 | ? carMode ? mBackLandCarModeIcon : mBackIcon |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 579 | : carMode ? mBackCarModeIcon : mBackIcon; |
| 580 | } |
| 581 | |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 582 | public void setNavigationIconHints(int hints) { |
| 583 | if (hints == mNavigationIconHints) return; |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 584 | final boolean backAlt = (hints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) != 0; |
| 585 | if ((mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) != 0 && !backAlt) { |
| 586 | mTransitionListener.onBackAltCleared(); |
| 587 | } |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 588 | if (DEBUG) { |
John Spurlock | 0153478 | 2014-01-13 11:59:22 -0500 | [diff] [blame] | 589 | android.widget.Toast.makeText(getContext(), |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 590 | "Navigation icon hints = " + hints, |
| 591 | 500).show(); |
| 592 | } |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 593 | mNavigationIconHints = hints; |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 594 | updateNavButtonIcons(); |
| 595 | } |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 596 | |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 597 | public void setDisabledFlags(int disabledFlags) { |
| 598 | if (mDisabledFlags == disabledFlags) return; |
| 599 | |
| 600 | final boolean overviewEnabledBefore = isOverviewEnabled(); |
| 601 | mDisabledFlags = disabledFlags; |
| 602 | |
| 603 | // Update icons if overview was just enabled to ensure the correct icons are present |
| 604 | if (!overviewEnabledBefore && isOverviewEnabled()) { |
| 605 | reloadNavIcons(); |
| 606 | } |
| 607 | |
| 608 | updateNavButtonIcons(); |
Winson Chung | 1be4c7e | 2018-05-23 18:24:13 -0700 | [diff] [blame] | 609 | updateSlippery(); |
Tracy Zhou | 9814091 | 2018-06-05 12:09:14 -0700 | [diff] [blame] | 610 | setUpSwipeUpOnboarding(isQuickStepSwipeUpEnabled()); |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | public void updateNavButtonIcons() { |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 614 | // We have to replace or restore the back and home button icons when exiting or entering |
| 615 | // carmode, respectively. Recents are not available in CarMode in nav bar so change |
| 616 | // to recent icon is not required. |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 617 | final boolean useAltBack = |
| 618 | (mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) != 0; |
| 619 | KeyButtonDrawable backIcon = useAltBack |
| 620 | ? getBackIconWithAlt(mUseCarModeUi, mVertical) |
| 621 | : getBackIcon(mUseCarModeUi, mVertical); |
| 622 | KeyButtonDrawable homeIcon = mUseCarModeUi ? mHomeCarModeIcon : mHomeDefaultIcon; |
| 623 | if (!mUseCarModeUi) { |
| 624 | orientBackButton(backIcon); |
| 625 | orientHomeButton(homeIcon); |
| 626 | } |
| 627 | getHomeButton().setImageDrawable(homeIcon); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 628 | getBackButton().setImageDrawable(backIcon); |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 629 | |
Jorim Jaggi | d30d95d | 2016-02-17 20:27:22 -0800 | [diff] [blame] | 630 | updateRecentsIcon(); |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 631 | |
Mike Digman | a48cf19 | 2018-02-12 17:52:48 -0800 | [diff] [blame] | 632 | // Update IME button visibility, a11y and rotate button always overrides the appearance |
Casey Burkhardt | 2464dc9 | 2017-03-28 15:52:12 -0700 | [diff] [blame] | 633 | final boolean showImeButton = |
Mike Digman | a48cf19 | 2018-02-12 17:52:48 -0800 | [diff] [blame] | 634 | !mShowAccessibilityButton && |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 635 | !mShowRotateButton && |
| 636 | ((mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_IME_SHOWN) != 0); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 637 | getImeSwitchButton().setVisibility(showImeButton ? View.VISIBLE : View.INVISIBLE); |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 638 | getImeSwitchButton().setImageDrawable(mImeIcon); |
Anthony Chen | ada1304 | 2016-01-19 16:57:20 -0800 | [diff] [blame] | 639 | |
Mike Digman | a48cf19 | 2018-02-12 17:52:48 -0800 | [diff] [blame] | 640 | // Update menu button, visibility logic in method |
Jason Monk | f1ff209 | 2014-04-29 16:50:53 -0400 | [diff] [blame] | 641 | setMenuVisibility(mShowMenu, true); |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 642 | getMenuButton().setImageDrawable(mMenuIcon); |
Jason Monk | f1ff209 | 2014-04-29 16:50:53 -0400 | [diff] [blame] | 643 | |
Mike Digman | a48cf19 | 2018-02-12 17:52:48 -0800 | [diff] [blame] | 644 | // Update rotate button, visibility altered by a11y button logic |
| 645 | getRotateSuggestionButton().setImageDrawable(mRotateSuggestionIcon); |
| 646 | |
| 647 | // Update a11y button, visibility logic in state method |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 648 | setAccessibilityButtonState(mShowAccessibilityButton, mLongClickableAccessibilityButton); |
| 649 | getAccessibilityButton().setImageDrawable(mAccessibilityIcon); |
| 650 | |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 651 | mBarTransitions.reapplyDarkIntensity(); |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 652 | |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 653 | boolean disableHome = ((mDisabledFlags & View.STATUS_BAR_DISABLE_HOME) != 0); |
Sriram Viswanathan | 469caae | 2016-03-22 13:11:50 -0700 | [diff] [blame] | 654 | |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 655 | // Always disable recents when alternate car mode UI is active. |
Matthew Ng | 6ff33b7 | 2018-02-27 13:47:38 -0800 | [diff] [blame] | 656 | boolean disableRecent = mUseCarModeUi || !isOverviewEnabled(); |
Charles He | e57ff81 | 2017-10-26 10:01:35 +0100 | [diff] [blame] | 657 | |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 658 | boolean disableBack = ((mDisabledFlags & View.STATUS_BAR_DISABLE_BACK) != 0) && !useAltBack; |
Daniel Sandler | 029d587 | 2011-09-12 00:58:58 -0400 | [diff] [blame] | 659 | |
Matthew Ng | 87cbf34 | 2018-02-15 12:21:18 -0800 | [diff] [blame] | 660 | // When screen pinning, don't hide back and home when connected service or back and |
| 661 | // recents buttons when disconnected from launcher service in screen pinning mode, |
| 662 | // as they are used for exiting. |
Matthew Ng | 6ff33b7 | 2018-02-27 13:47:38 -0800 | [diff] [blame] | 663 | final boolean pinningActive = ActivityManagerWrapper.getInstance().isScreenPinningActive(); |
Winson Chung | d95a225 | 2018-04-04 17:02:29 +0000 | [diff] [blame] | 664 | if (mOverviewProxyService.isEnabled()) { |
Matthew Ng | 87cbf34 | 2018-02-15 12:21:18 -0800 | [diff] [blame] | 665 | // Use interaction flags to show/hide navigation buttons but will be shown if required |
| 666 | // to exit screen pinning. |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 667 | final int flags = mOverviewProxyService.getInteractionFlags(); |
| 668 | disableRecent |= (flags & FLAG_SHOW_OVERVIEW_BUTTON) == 0; |
Matthew Ng | 6ff33b7 | 2018-02-27 13:47:38 -0800 | [diff] [blame] | 669 | if (pinningActive) { |
Matthew Ng | 87cbf34 | 2018-02-15 12:21:18 -0800 | [diff] [blame] | 670 | disableBack = disableHome = false; |
Matthew Ng | 87cbf34 | 2018-02-15 12:21:18 -0800 | [diff] [blame] | 671 | } |
Matthew Ng | 6ff33b7 | 2018-02-27 13:47:38 -0800 | [diff] [blame] | 672 | } else if (pinningActive) { |
Matthew Ng | 87cbf34 | 2018-02-15 12:21:18 -0800 | [diff] [blame] | 673 | disableBack = disableRecent = false; |
Matthew Ng | dc79e5c | 2017-12-14 17:37:35 -0800 | [diff] [blame] | 674 | } |
Charles He | e57ff81 | 2017-10-26 10:01:35 +0100 | [diff] [blame] | 675 | |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 676 | ViewGroup navButtons = (ViewGroup) getCurrentView().findViewById(R.id.nav_buttons); |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 677 | if (navButtons != null) { |
| 678 | LayoutTransition lt = navButtons.getLayoutTransition(); |
John Spurlock | 1bbd49d | 2012-10-19 11:09:32 -0400 | [diff] [blame] | 679 | if (lt != null) { |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 680 | if (!lt.getTransitionListeners().contains(mTransitionListener)) { |
| 681 | lt.addTransitionListener(mTransitionListener); |
| 682 | } |
John Spurlock | 1bbd49d | 2012-10-19 11:09:32 -0400 | [diff] [blame] | 683 | } |
| 684 | } |
| 685 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 686 | getBackButton().setVisibility(disableBack ? View.INVISIBLE : View.VISIBLE); |
Jason Monk | 188908f | 2016-01-22 10:23:51 -0500 | [diff] [blame] | 687 | getHomeButton().setVisibility(disableHome ? View.INVISIBLE : View.VISIBLE); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 688 | getRecentsButton().setVisibility(disableRecent ? View.INVISIBLE : View.VISIBLE); |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 689 | } |
| 690 | |
Matthew Ng | 87cbf34 | 2018-02-15 12:21:18 -0800 | [diff] [blame] | 691 | public boolean inScreenPinning() { |
Matthew Ng | 6ff33b7 | 2018-02-27 13:47:38 -0800 | [diff] [blame] | 692 | return ActivityManagerWrapper.getInstance().isScreenPinningActive(); |
Jason Monk | 17488b9 | 2014-11-06 11:26:14 -0500 | [diff] [blame] | 693 | } |
| 694 | |
Jorim Jaggi | 37c1180 | 2015-08-18 20:27:54 -0700 | [diff] [blame] | 695 | public void setLayoutTransitionsEnabled(boolean enabled) { |
| 696 | mLayoutTransitionsEnabled = enabled; |
| 697 | updateLayoutTransitionsEnabled(); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 698 | } |
| 699 | |
Jorim Jaggi | 37c1180 | 2015-08-18 20:27:54 -0700 | [diff] [blame] | 700 | public void setWakeAndUnlocking(boolean wakeAndUnlocking) { |
| 701 | setUseFadingAnimations(wakeAndUnlocking); |
| 702 | mWakeAndUnlocking = wakeAndUnlocking; |
| 703 | updateLayoutTransitionsEnabled(); |
| 704 | } |
| 705 | |
| 706 | private void updateLayoutTransitionsEnabled() { |
| 707 | boolean enabled = !mWakeAndUnlocking && mLayoutTransitionsEnabled; |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 708 | ViewGroup navButtons = (ViewGroup) getCurrentView().findViewById(R.id.nav_buttons); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 709 | LayoutTransition lt = navButtons.getLayoutTransition(); |
Julia Reynolds | 8478aba | 2015-07-31 09:17:20 -0400 | [diff] [blame] | 710 | if (lt != null) { |
| 711 | if (enabled) { |
| 712 | lt.enableTransitionType(LayoutTransition.APPEARING); |
| 713 | lt.enableTransitionType(LayoutTransition.DISAPPEARING); |
| 714 | lt.enableTransitionType(LayoutTransition.CHANGE_APPEARING); |
| 715 | lt.enableTransitionType(LayoutTransition.CHANGE_DISAPPEARING); |
| 716 | } else { |
| 717 | lt.disableTransitionType(LayoutTransition.APPEARING); |
| 718 | lt.disableTransitionType(LayoutTransition.DISAPPEARING); |
| 719 | lt.disableTransitionType(LayoutTransition.CHANGE_APPEARING); |
| 720 | lt.disableTransitionType(LayoutTransition.CHANGE_DISAPPEARING); |
| 721 | } |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 722 | } |
| 723 | } |
| 724 | |
| 725 | private void setUseFadingAnimations(boolean useFadingAnimations) { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 726 | WindowManager.LayoutParams lp = (WindowManager.LayoutParams) ((ViewGroup) getParent()) |
| 727 | .getLayoutParams(); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 728 | if (lp != null) { |
| 729 | boolean old = lp.windowAnimations != 0; |
| 730 | if (!old && useFadingAnimations) { |
| 731 | lp.windowAnimations = R.style.Animation_NavigationBarFadeIn; |
| 732 | } else if (old && !useFadingAnimations) { |
| 733 | lp.windowAnimations = 0; |
| 734 | } else { |
| 735 | return; |
| 736 | } |
| 737 | WindowManager wm = (WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 738 | wm.updateViewLayout((View) getParent(), lp); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 739 | } |
| 740 | } |
| 741 | |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 742 | public void onNavigationButtonLongPress(View v) { |
| 743 | mGestureHelper.onNavigationButtonLongPress(v); |
| 744 | } |
| 745 | |
Matthew Ng | 78f88d1 | 2018-01-23 12:39:55 -0800 | [diff] [blame] | 746 | public void onPanelExpandedChange(boolean expanded) { |
| 747 | updateSlippery(); |
| 748 | } |
| 749 | |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 750 | public void updateStates() { |
Matthew Ng | 44b1450 | 2018-05-04 11:10:14 -0700 | [diff] [blame] | 751 | final boolean showSwipeUpUI = mOverviewProxyService.shouldShowSwipeUpUI(); |
Mike Digman | f77fb91 | 2018-05-21 11:21:30 -0700 | [diff] [blame] | 752 | |
| 753 | if (mNavigationInflaterView != null) { |
| 754 | // Reinflate the navbar if needed, no-op unless the swipe up state changes |
| 755 | mNavigationInflaterView.onLikelyDefaultLayoutChange(); |
| 756 | } |
| 757 | |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 758 | updateSlippery(); |
Winson Chung | 770d7e9 | 2018-03-20 17:51:39 -0700 | [diff] [blame] | 759 | reloadNavIcons(); |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 760 | updateNavButtonIcons(); |
Winson Chung | f9e3027 | 2018-03-26 17:25:36 -0700 | [diff] [blame] | 761 | setUpSwipeUpOnboarding(isQuickStepSwipeUpEnabled()); |
Matthew Ng | 44b1450 | 2018-05-04 11:10:14 -0700 | [diff] [blame] | 762 | WindowManagerWrapper.getInstance().setNavBarVirtualKeyHapticFeedbackEnabled(!showSwipeUpUI); |
| 763 | getHomeButton().setAccessibilityDelegate( |
| 764 | showSwipeUpUI ? mQuickStepAccessibilityDelegate : null); |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 765 | } |
| 766 | |
Matthew Ng | 78f88d1 | 2018-01-23 12:39:55 -0800 | [diff] [blame] | 767 | private void updateSlippery() { |
Winson Chung | 770d7e9 | 2018-03-20 17:51:39 -0700 | [diff] [blame] | 768 | setSlippery(!isQuickStepSwipeUpEnabled() || mPanelView.isFullyExpanded()); |
Matthew Ng | 78f88d1 | 2018-01-23 12:39:55 -0800 | [diff] [blame] | 769 | } |
| 770 | |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 771 | private void setSlippery(boolean slippery) { |
| 772 | boolean changed = false; |
| 773 | final ViewGroup navbarView = ((ViewGroup) getParent()); |
| 774 | final WindowManager.LayoutParams lp = (WindowManager.LayoutParams) navbarView |
| 775 | .getLayoutParams(); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 776 | if (lp == null) { |
| 777 | return; |
| 778 | } |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 779 | if (slippery && (lp.flags & WindowManager.LayoutParams.FLAG_SLIPPERY) == 0) { |
| 780 | lp.flags |= WindowManager.LayoutParams.FLAG_SLIPPERY; |
| 781 | changed = true; |
| 782 | } else if (!slippery && (lp.flags & WindowManager.LayoutParams.FLAG_SLIPPERY) != 0) { |
| 783 | lp.flags &= ~WindowManager.LayoutParams.FLAG_SLIPPERY; |
| 784 | changed = true; |
| 785 | } |
| 786 | if (changed) { |
| 787 | WindowManager wm = (WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE); |
| 788 | wm.updateViewLayout(navbarView, lp); |
| 789 | } |
| 790 | } |
| 791 | |
Daniel Sandler | 56598cd | 2011-09-15 16:02:56 -0400 | [diff] [blame] | 792 | public void setMenuVisibility(final boolean show) { |
| 793 | setMenuVisibility(show, false); |
| 794 | } |
| 795 | |
| 796 | public void setMenuVisibility(final boolean show, final boolean force) { |
| 797 | if (!force && mShowMenu == show) return; |
| 798 | |
| 799 | mShowMenu = show; |
| 800 | |
Mike Digman | a48cf19 | 2018-02-12 17:52:48 -0800 | [diff] [blame] | 801 | // Only show Menu if IME switcher, rotate and Accessibility buttons are not shown. |
| 802 | final boolean shouldShow = mShowMenu && |
| 803 | !mShowAccessibilityButton && |
| 804 | !mShowRotateButton && |
Jason Monk | f1ff209 | 2014-04-29 16:50:53 -0400 | [diff] [blame] | 805 | ((mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_IME_SHOWN) == 0); |
Anthony Chen | ada1304 | 2016-01-19 16:57:20 -0800 | [diff] [blame] | 806 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 807 | getMenuButton().setVisibility(shouldShow ? View.VISIBLE : View.INVISIBLE); |
Daniel Sandler | 029d587 | 2011-09-12 00:58:58 -0400 | [diff] [blame] | 808 | } |
| 809 | |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 810 | public void setAccessibilityButtonState(final boolean visible, final boolean longClickable) { |
| 811 | mShowAccessibilityButton = visible; |
| 812 | mLongClickableAccessibilityButton = longClickable; |
| 813 | if (visible) { |
Mike Digman | a48cf19 | 2018-02-12 17:52:48 -0800 | [diff] [blame] | 814 | // Accessibility button overrides Menu, IME switcher and rotate buttons. |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 815 | setMenuVisibility(false, true); |
Casey Burkhardt | 2464dc9 | 2017-03-28 15:52:12 -0700 | [diff] [blame] | 816 | getImeSwitchButton().setVisibility(View.INVISIBLE); |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 817 | setRotateButtonVisibility(false); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | getAccessibilityButton().setVisibility(visible ? View.VISIBLE : View.INVISIBLE); |
| 821 | getAccessibilityButton().setLongClickable(longClickable); |
| 822 | } |
| 823 | |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 824 | public void updateRotateSuggestionButtonStyle(@StyleRes int style, boolean setIcon) { |
| 825 | mRotateBtnStyle = style; |
| 826 | final Context ctx = getContext(); |
| 827 | |
| 828 | // Extract the dark and light tints |
| 829 | final int dualToneDarkTheme = Utils.getThemeAttr(ctx, R.attr.darkIconTheme); |
| 830 | final int dualToneLightTheme = Utils.getThemeAttr(ctx, R.attr.lightIconTheme); |
| 831 | Context darkContext = new ContextThemeWrapper(ctx, dualToneDarkTheme); |
| 832 | Context lightContext = new ContextThemeWrapper(ctx, dualToneLightTheme); |
| 833 | final int lightColor = Utils.getColorAttr(lightContext, R.attr.singleToneColor); |
| 834 | final int darkColor = Utils.getColorAttr(darkContext, R.attr.singleToneColor); |
| 835 | |
| 836 | // Use the supplied style to set the icon's rotation parameters |
| 837 | Context rotateContext = new ContextThemeWrapper(ctx, style); |
| 838 | |
| 839 | // Recreate the icon and set it if needed |
Mike Digman | c821758 | 2018-03-06 13:08:33 -0800 | [diff] [blame] | 840 | TintedKeyButtonDrawable priorIcon = mRotateSuggestionIcon; |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 841 | mRotateSuggestionIcon = getDrawable(rotateContext, R.drawable.ic_sysbar_rotate_button, |
| 842 | lightColor, darkColor); |
Mike Digman | c821758 | 2018-03-06 13:08:33 -0800 | [diff] [blame] | 843 | |
| 844 | // Apply any prior set dark intensity |
| 845 | if (priorIcon != null && priorIcon.isDarkIntensitySet()) { |
| 846 | mRotateSuggestionIcon.setDarkIntensity(priorIcon.getDarkIntensity()); |
| 847 | } |
| 848 | |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 849 | if (setIcon) getRotateSuggestionButton().setImageDrawable(mRotateSuggestionIcon); |
Mike Digman | a48cf19 | 2018-02-12 17:52:48 -0800 | [diff] [blame] | 850 | } |
| 851 | |
Mike Digman | 9b50b76 | 2018-04-19 10:50:35 -0700 | [diff] [blame] | 852 | public int setRotateButtonVisibility(final boolean visible) { |
Mike Digman | a48cf19 | 2018-02-12 17:52:48 -0800 | [diff] [blame] | 853 | // Never show if a11y is visible |
| 854 | final boolean adjVisible = visible && !mShowAccessibilityButton; |
| 855 | final int vis = adjVisible ? View.VISIBLE : View.INVISIBLE; |
| 856 | |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 857 | // No need to do anything if the request matches the current state |
Mike Digman | 9b50b76 | 2018-04-19 10:50:35 -0700 | [diff] [blame] | 858 | if (vis == getRotateSuggestionButton().getVisibility()) return vis; |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 859 | |
Mike Digman | a48cf19 | 2018-02-12 17:52:48 -0800 | [diff] [blame] | 860 | getRotateSuggestionButton().setVisibility(vis); |
| 861 | mShowRotateButton = visible; |
| 862 | |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 863 | // Stop any active animations if hidden |
| 864 | if (!visible) { |
| 865 | Drawable d = mRotateSuggestionIcon.getDrawable(0); |
| 866 | if (d instanceof AnimatedVectorDrawable) { |
| 867 | AnimatedVectorDrawable avd = (AnimatedVectorDrawable) d; |
| 868 | avd.clearAnimationCallbacks(); |
| 869 | avd.reset(); |
| 870 | } |
| 871 | } |
| 872 | |
Mike Digman | a48cf19 | 2018-02-12 17:52:48 -0800 | [diff] [blame] | 873 | // Hide/restore other button visibility, if necessary |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 874 | updateNavButtonIcons(); |
Mike Digman | 9b50b76 | 2018-04-19 10:50:35 -0700 | [diff] [blame] | 875 | |
| 876 | // Return applied visibility |
| 877 | return vis; |
Mike Digman | a48cf19 | 2018-02-12 17:52:48 -0800 | [diff] [blame] | 878 | } |
| 879 | |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 880 | public boolean isRotateButtonVisible() { return mShowRotateButton; } |
| 881 | |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 882 | /** |
| 883 | * @return the button at the given {@param x} and {@param y}. |
| 884 | */ |
| 885 | ButtonDispatcher getButtonAtPosition(int x, int y) { |
| 886 | for (int i = 0; i < mButtonDispatchers.size(); i++) { |
| 887 | ButtonDispatcher button = mButtonDispatchers.valueAt(i); |
| 888 | View buttonView = button.getCurrentView(); |
| 889 | if (buttonView != null) { |
| 890 | buttonView.getHitRect(mTmpRect); |
| 891 | offsetDescendantRectToMyCoords(buttonView, mTmpRect); |
| 892 | if (mTmpRect.contains(x, y)) { |
| 893 | return button; |
| 894 | } |
| 895 | } |
| 896 | } |
| 897 | return null; |
Matthew Ng | 6607c3d | 2018-04-26 15:23:27 -0700 | [diff] [blame] | 898 | } |
| 899 | |
Jim Miller | 960892c | 2012-05-23 15:50:04 -0700 | [diff] [blame] | 900 | @Override |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 901 | public void onFinishInflate() { |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 902 | mNavigationInflaterView = findViewById(R.id.navigation_inflater); |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 903 | mNavigationInflaterView.setButtonDispatchers(mButtonDispatchers); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 904 | |
| 905 | getImeSwitchButton().setOnClickListener(mImeSwitcherClickListener); |
Selim Cinek | 17a327a | 2014-08-25 15:03:48 +0200 | [diff] [blame] | 906 | |
Jason Monk | 32e3bb5 | 2017-07-27 12:35:41 -0400 | [diff] [blame] | 907 | DockedStackExistsListener.register(mDockedListener); |
Siarhei Vishniakou | fdb4277 | 2017-06-29 10:32:11 -0700 | [diff] [blame] | 908 | updateRotatedViews(); |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 909 | } |
| 910 | |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 911 | public void onDarkIntensityChange(float intensity) { |
| 912 | if (mGestureHelper != null) { |
| 913 | mGestureHelper.onDarkIntensityChange(intensity); |
| 914 | } |
| 915 | } |
| 916 | |
| 917 | @Override |
| 918 | protected void onDraw(Canvas canvas) { |
| 919 | mGestureHelper.onDraw(canvas); |
Matthew Ng | 603b329 | 2018-03-30 17:15:39 -0700 | [diff] [blame] | 920 | mDeadZone.onDraw(canvas); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 921 | super.onDraw(canvas); |
| 922 | } |
| 923 | |
| 924 | @Override |
| 925 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 926 | super.onLayout(changed, left, top, right, bottom); |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 927 | updateButtonLocationOnScreen(getBackButton(), mBackButtonBounds); |
| 928 | updateButtonLocationOnScreen(getHomeButton(), mHomeButtonBounds); |
Matthew Ng | 8a8c89c | 2018-03-01 13:21:43 -0800 | [diff] [blame] | 929 | updateButtonLocationOnScreen(getRecentsButton(), mRecentsButtonBounds); |
Winson Chung | 8079af7 | 2018-05-10 11:12:55 -0700 | [diff] [blame] | 930 | updateButtonLocationOnScreen(getRotateSuggestionButton(), mRotationButtonBounds); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 931 | mGestureHelper.onLayout(changed, left, top, right, bottom); |
Tracy Zhou | 559d97c | 2018-04-07 23:54:46 -0700 | [diff] [blame] | 932 | mRecentsOnboarding.setNavBarHeight(getMeasuredHeight()); |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 933 | } |
| 934 | |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 935 | private void updateButtonLocationOnScreen(ButtonDispatcher button, Rect buttonBounds) { |
| 936 | View view = button.getCurrentView(); |
| 937 | if (view == null) { |
| 938 | buttonBounds.setEmpty(); |
| 939 | return; |
| 940 | } |
Matthew Ng | 3b7e390 | 2018-03-22 16:06:09 -0700 | [diff] [blame] | 941 | // Temporarily reset the translation back to origin to get the position in window |
| 942 | final float posX = view.getTranslationX(); |
| 943 | final float posY = view.getTranslationY(); |
| 944 | view.setTranslationX(0); |
| 945 | view.setTranslationY(0); |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 946 | view.getLocationInWindow(mTmpPosition); |
| 947 | buttonBounds.set(mTmpPosition[0], mTmpPosition[1], |
| 948 | mTmpPosition[0] + view.getMeasuredWidth(), |
| 949 | mTmpPosition[1] + view.getMeasuredHeight()); |
Matthew Ng | 3b7e390 | 2018-03-22 16:06:09 -0700 | [diff] [blame] | 950 | view.setTranslationX(posX); |
| 951 | view.setTranslationY(posY); |
Winson Chung | c4e0620 | 2018-02-13 10:37:35 -0800 | [diff] [blame] | 952 | } |
| 953 | |
Siarhei Vishniakou | fdb4277 | 2017-06-29 10:32:11 -0700 | [diff] [blame] | 954 | private void updateRotatedViews() { |
Jason Monk | 9a6552d | 2016-05-20 11:21:59 -0400 | [diff] [blame] | 955 | mRotatedViews[Surface.ROTATION_0] = |
| 956 | mRotatedViews[Surface.ROTATION_180] = findViewById(R.id.rot0); |
| 957 | mRotatedViews[Surface.ROTATION_270] = |
| 958 | mRotatedViews[Surface.ROTATION_90] = findViewById(R.id.rot90); |
| 959 | |
Jason Monk | 199a2d0 | 2017-07-28 11:08:27 -0400 | [diff] [blame] | 960 | updateCurrentView(); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 961 | } |
| 962 | |
Adrian Roos | a98b32c | 2016-08-11 10:41:08 -0700 | [diff] [blame] | 963 | public boolean needsReorient(int rotation) { |
| 964 | return mCurrentRotation != rotation; |
Adrian Roos | 090b7d8 | 2016-08-02 18:36:12 -0700 | [diff] [blame] | 965 | } |
| 966 | |
Jason Monk | 199a2d0 | 2017-07-28 11:08:27 -0400 | [diff] [blame] | 967 | private void updateCurrentView() { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 968 | final int rot = mDisplay.getRotation(); |
| 969 | for (int i=0; i<4; i++) { |
| 970 | mRotatedViews[i].setVisibility(View.GONE); |
| 971 | } |
Daniel Sandler | 5c8da94 | 2011-06-28 00:29:04 -0400 | [diff] [blame] | 972 | mCurrentView = mRotatedViews[rot]; |
| 973 | mCurrentView.setVisibility(View.VISIBLE); |
Adrian Roos | db12b15 | 2016-07-12 15:38:55 -0700 | [diff] [blame] | 974 | mNavigationInflaterView.setAlternativeOrder(rot == Surface.ROTATION_90); |
Matthew Ng | 1efc9c3 | 2018-04-11 18:13:56 -0700 | [diff] [blame] | 975 | mNavigationInflaterView.updateButtonDispatchersCurrentView(); |
Jorim Jaggi | 37c1180 | 2015-08-18 20:27:54 -0700 | [diff] [blame] | 976 | updateLayoutTransitionsEnabled(); |
Adrian Roos | 090b7d8 | 2016-08-02 18:36:12 -0700 | [diff] [blame] | 977 | mCurrentRotation = rot; |
Jason Monk | 9a6552d | 2016-05-20 11:21:59 -0400 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | private void updateRecentsIcon() { |
Matthew Ng | eb5ce83 | 2018-05-15 17:50:37 -0700 | [diff] [blame] | 981 | mDockedIcon.setRotation(mDockedStackExists && mVertical ? 90 : 0); |
Jason Monk | 9a6552d | 2016-05-20 11:21:59 -0400 | [diff] [blame] | 982 | getRecentsButton().setImageDrawable(mDockedStackExists ? mDockedIcon : mRecentIcon); |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 983 | mBarTransitions.reapplyDarkIntensity(); |
Jason Monk | 9a6552d | 2016-05-20 11:21:59 -0400 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | public boolean isVertical() { |
| 987 | return mVertical; |
| 988 | } |
| 989 | |
| 990 | public void reorient() { |
Jason Monk | 199a2d0 | 2017-07-28 11:08:27 -0400 | [diff] [blame] | 991 | updateCurrentView(); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 992 | |
Siarhei Vishniakou | fdb4277 | 2017-06-29 10:32:11 -0700 | [diff] [blame] | 993 | ((NavigationBarFrame) getRootView()).setDeadZone(mDeadZone); |
Matthew Ng | 603b329 | 2018-03-30 17:15:39 -0700 | [diff] [blame] | 994 | mDeadZone.onConfigurationChanged(mCurrentRotation); |
Daniel Sandler | c26185b | 2012-08-29 15:49:53 -0400 | [diff] [blame] | 995 | |
Daniel Sandler | 6da2b76 | 2011-09-14 16:04:59 -0400 | [diff] [blame] | 996 | // force the low profile & disabled states into compliance |
Adrian Roos | 8a8ffd4 | 2015-05-26 18:30:37 -0700 | [diff] [blame] | 997 | mBarTransitions.init(); |
Daniel Sandler | 56598cd | 2011-09-15 16:02:56 -0400 | [diff] [blame] | 998 | setMenuVisibility(mShowMenu, true /* force */); |
Daniel Sandler | 6da2b76 | 2011-09-14 16:04:59 -0400 | [diff] [blame] | 999 | |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 1000 | if (DEBUG) { |
Adrian Roos | a98b32c | 2016-08-11 10:41:08 -0700 | [diff] [blame] | 1001 | Log.d(TAG, "reorient(): rot=" + mCurrentRotation); |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 1002 | } |
Michael Jurka | a5d0ddb | 2012-03-09 17:41:41 -0800 | [diff] [blame] | 1003 | |
Matthew Ng | 5fd8041 | 2018-02-14 14:40:31 -0800 | [diff] [blame] | 1004 | // Resolve layout direction if not resolved since components changing layout direction such |
| 1005 | // as changing languages will recreate this view and the direction will be resolved later |
| 1006 | if (!isLayoutDirectionResolved()) { |
| 1007 | resolveLayoutDirection(); |
| 1008 | } |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 1009 | updateTaskSwitchHelper(); |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 1010 | updateNavButtonIcons(); |
Xiaohui Chen | 9efa5de | 2016-11-22 10:34:38 -0800 | [diff] [blame] | 1011 | |
Xiaohui Chen | 40e978e | 2016-11-29 15:10:04 -0800 | [diff] [blame] | 1012 | getHomeButton().setVertical(mVertical); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1013 | } |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1014 | |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 1015 | private void updateTaskSwitchHelper() { |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 1016 | if (mGestureHelper == null) return; |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 1017 | boolean isRtl = (getLayoutDirection() == View.LAYOUT_DIRECTION_RTL); |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 1018 | mGestureHelper.setBarState(mVertical, isRtl); |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 1019 | } |
| 1020 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 1021 | @Override |
| 1022 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 1023 | if (DEBUG) Log.d(TAG, String.format( |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 1024 | "onSizeChanged: (%dx%d) old: (%dx%d)", w, h, oldw, oldh)); |
Daniel Sandler | e03bc95 | 2012-04-27 16:11:22 -0400 | [diff] [blame] | 1025 | |
| 1026 | final boolean newVertical = w > 0 && h > w; |
| 1027 | if (newVertical != mVertical) { |
| 1028 | mVertical = newVertical; |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 1029 | //Log.v(TAG, String.format("onSizeChanged: h=%d, w=%d, vert=%s", h, w, mVertical?"y":"n")); |
Daniel Sandler | e03bc95 | 2012-04-27 16:11:22 -0400 | [diff] [blame] | 1030 | reorient(); |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 1031 | notifyVerticalChangedListener(newVertical); |
Daniel Sandler | e03bc95 | 2012-04-27 16:11:22 -0400 | [diff] [blame] | 1032 | } |
| 1033 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 1034 | postCheckForInvalidLayout("sizeChanged"); |
| 1035 | super.onSizeChanged(w, h, oldw, oldh); |
| 1036 | } |
| 1037 | |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 1038 | private void notifyVerticalChangedListener(boolean newVertical) { |
| 1039 | if (mOnVerticalChangedListener != null) { |
| 1040 | mOnVerticalChangedListener.onVerticalChanged(newVertical); |
| 1041 | } |
| 1042 | } |
| 1043 | |
Selim Cinek | 17a327a | 2014-08-25 15:03:48 +0200 | [diff] [blame] | 1044 | @Override |
| 1045 | protected void onConfigurationChanged(Configuration newConfig) { |
| 1046 | super.onConfigurationChanged(newConfig); |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 1047 | boolean uiCarModeChanged = updateCarMode(newConfig); |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 1048 | updateTaskSwitchHelper(); |
Winson | fde2e6a | 2016-03-22 16:03:10 -0700 | [diff] [blame] | 1049 | updateIcons(getContext(), mConfiguration, newConfig); |
| 1050 | updateRecentsIcon(); |
Tony Wickham | 05c1f85 | 2018-02-06 12:32:54 -0800 | [diff] [blame] | 1051 | mRecentsOnboarding.onConfigurationChanged(newConfig); |
Jason Monk | 1f785d4 | 2017-07-25 15:46:33 -0400 | [diff] [blame] | 1052 | if (uiCarModeChanged || mConfiguration.densityDpi != newConfig.densityDpi |
| 1053 | || mConfiguration.getLayoutDirection() != newConfig.getLayoutDirection()) { |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 1054 | // If car mode or density changes, we need to reset the icons. |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 1055 | updateNavButtonIcons(); |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 1056 | } |
Winson | fde2e6a | 2016-03-22 16:03:10 -0700 | [diff] [blame] | 1057 | mConfiguration.updateFrom(newConfig); |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | /** |
| 1061 | * If the configuration changed, update the carmode and return that it was updated. |
| 1062 | */ |
| 1063 | private boolean updateCarMode(Configuration newConfig) { |
| 1064 | boolean uiCarModeChanged = false; |
| 1065 | if (newConfig != null) { |
| 1066 | int uiMode = newConfig.uiMode & Configuration.UI_MODE_TYPE_MASK; |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 1067 | final boolean isCarMode = (uiMode == Configuration.UI_MODE_TYPE_CAR); |
| 1068 | |
| 1069 | if (isCarMode != mInCarMode) { |
| 1070 | mInCarMode = isCarMode; |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 1071 | if (ALTERNATE_CAR_MODE_UI) { |
| 1072 | mUseCarModeUi = isCarMode; |
| 1073 | uiCarModeChanged = true; |
| 1074 | } else { |
| 1075 | // Don't use car mode behavior if ALTERNATE_CAR_MODE_UI not set. |
| 1076 | mUseCarModeUi = false; |
| 1077 | } |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 1078 | } |
| 1079 | } |
| 1080 | return uiCarModeChanged; |
Selim Cinek | 17a327a | 2014-08-25 15:03:48 +0200 | [diff] [blame] | 1081 | } |
| 1082 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 1083 | /* |
| 1084 | @Override |
| 1085 | 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] | 1086 | if (DEBUG) Log.d(TAG, String.format( |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 1087 | "onLayout: %s (%d,%d,%d,%d)", |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 1088 | changed?"changed":"notchanged", left, top, right, bottom)); |
| 1089 | super.onLayout(changed, left, top, right, bottom); |
| 1090 | } |
| 1091 | |
| 1092 | // uncomment this for extra defensiveness in WORKAROUND_INVALID_LAYOUT situations: if all else |
| 1093 | // fails, any touch on the display will fix the layout. |
| 1094 | @Override |
| 1095 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 1096 | if (DEBUG) Log.d(TAG, "onInterceptTouchEvent: " + ev.toString()); |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 1097 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
| 1098 | postCheckForInvalidLayout("touch"); |
| 1099 | } |
| 1100 | return super.onInterceptTouchEvent(ev); |
| 1101 | } |
| 1102 | */ |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 1103 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 1104 | |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1105 | private String getResourceName(int resId) { |
| 1106 | if (resId != 0) { |
John Spurlock | 0153478 | 2014-01-13 11:59:22 -0500 | [diff] [blame] | 1107 | final android.content.res.Resources res = getContext().getResources(); |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1108 | try { |
| 1109 | return res.getResourceName(resId); |
| 1110 | } catch (android.content.res.Resources.NotFoundException ex) { |
| 1111 | return "(unknown)"; |
| 1112 | } |
| 1113 | } else { |
| 1114 | return "(null)"; |
| 1115 | } |
| 1116 | } |
| 1117 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 1118 | private void postCheckForInvalidLayout(final String how) { |
| 1119 | mHandler.obtainMessage(MSG_CHECK_INVALID_LAYOUT, 0, 0, how).sendToTarget(); |
| 1120 | } |
| 1121 | |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1122 | private static String visibilityToString(int vis) { |
| 1123 | switch (vis) { |
| 1124 | case View.INVISIBLE: |
| 1125 | return "INVISIBLE"; |
| 1126 | case View.GONE: |
| 1127 | return "GONE"; |
| 1128 | default: |
| 1129 | return "VISIBLE"; |
| 1130 | } |
| 1131 | } |
| 1132 | |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 1133 | @Override |
| 1134 | protected void onAttachedToWindow() { |
| 1135 | super.onAttachedToWindow(); |
Adrian Roos | 7e58a08 | 2018-03-09 16:40:56 +0100 | [diff] [blame] | 1136 | requestApplyInsets(); |
Siarhei Vishniakou | fdb4277 | 2017-06-29 10:32:11 -0700 | [diff] [blame] | 1137 | reorient(); |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 1138 | onPluginDisconnected(null); // Create default gesture helper |
Jason Monk | 5bec68f | 2017-02-08 20:45:10 -0800 | [diff] [blame] | 1139 | Dependency.get(PluginManager.class).addPluginListener(this, |
| 1140 | NavGesture.class, false /* Only one */); |
Winson Chung | f9e3027 | 2018-03-26 17:25:36 -0700 | [diff] [blame] | 1141 | setUpSwipeUpOnboarding(isQuickStepSwipeUpEnabled()); |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | @Override |
| 1145 | protected void onDetachedFromWindow() { |
| 1146 | super.onDetachedFromWindow(); |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 1147 | Dependency.get(PluginManager.class).removePluginListener(this); |
| 1148 | if (mGestureHelper != null) { |
| 1149 | mGestureHelper.destroy(); |
| 1150 | } |
Tony Wickham | fb63fe8 | 2018-01-16 12:14:06 -0800 | [diff] [blame] | 1151 | setUpSwipeUpOnboarding(false); |
| 1152 | } |
| 1153 | |
| 1154 | private void setUpSwipeUpOnboarding(boolean connectedToOverviewProxy) { |
| 1155 | if (connectedToOverviewProxy) { |
Tony Wickham | 05c1f85 | 2018-02-06 12:32:54 -0800 | [diff] [blame] | 1156 | mRecentsOnboarding.onConnectedToLauncher(); |
Tony Wickham | fb63fe8 | 2018-01-16 12:14:06 -0800 | [diff] [blame] | 1157 | } else { |
Tony Wickham | 05c1f85 | 2018-02-06 12:32:54 -0800 | [diff] [blame] | 1158 | mRecentsOnboarding.onDisconnectedFromLauncher(); |
Tony Wickham | fb63fe8 | 2018-01-16 12:14:06 -0800 | [diff] [blame] | 1159 | } |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | @Override |
Jason Monk | 20ff3f9 | 2017-01-09 15:13:23 -0500 | [diff] [blame] | 1163 | public void onPluginConnected(NavGesture plugin, Context context) { |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 1164 | mGestureHelper = plugin.getGestureHelper(); |
| 1165 | updateTaskSwitchHelper(); |
| 1166 | } |
| 1167 | |
| 1168 | @Override |
| 1169 | public void onPluginDisconnected(NavGesture plugin) { |
| 1170 | NavigationBarGestureHelper defaultHelper = new NavigationBarGestureHelper(getContext()); |
| 1171 | defaultHelper.setComponents(mRecentsComponent, mDivider, this); |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 1172 | if (mGestureHelper != null) { |
| 1173 | mGestureHelper.destroy(); |
| 1174 | } |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 1175 | mGestureHelper = defaultHelper; |
| 1176 | updateTaskSwitchHelper(); |
| 1177 | } |
| 1178 | |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1179 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 1180 | pw.println("NavigationBarView {"); |
| 1181 | final Rect r = new Rect(); |
Jeff Brown | a8b9def | 2012-07-23 14:22:49 -0700 | [diff] [blame] | 1182 | final Point size = new Point(); |
| 1183 | mDisplay.getRealSize(size); |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1184 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 1185 | pw.println(String.format(" this: " + StatusBar.viewInfo(this) |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1186 | + " " + visibilityToString(getVisibility()))); |
| 1187 | |
| 1188 | getWindowVisibleDisplayFrame(r); |
Jeff Brown | a8b9def | 2012-07-23 14:22:49 -0700 | [diff] [blame] | 1189 | final boolean offscreen = r.right > size.x || r.bottom > size.y; |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 1190 | pw.println(" window: " |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1191 | + r.toShortString() |
| 1192 | + " " + visibilityToString(getWindowVisibility()) |
| 1193 | + (offscreen ? " OFFSCREEN!" : "")); |
| 1194 | |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 1195 | pw.println(String.format(" mCurrentView: id=%s (%dx%d) %s %f", |
Rakesh Iyer | f51fe4e | 2016-02-09 10:51:50 -0800 | [diff] [blame] | 1196 | getResourceName(getCurrentView().getId()), |
| 1197 | getCurrentView().getWidth(), getCurrentView().getHeight(), |
Winson Chung | 661d5f9 | 2018-05-21 18:41:39 -0700 | [diff] [blame] | 1198 | visibilityToString(getCurrentView().getVisibility()), |
| 1199 | getCurrentView().getAlpha())); |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1200 | |
John Spurlock | 41c1e35 | 2013-09-16 13:57:13 -0400 | [diff] [blame] | 1201 | pw.println(String.format(" disabled=0x%08x vertical=%s menu=%s", |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1202 | mDisabledFlags, |
| 1203 | mVertical ? "true" : "false", |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1204 | mShowMenu ? "true" : "false")); |
| 1205 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 1206 | dumpButton(pw, "back", getBackButton()); |
| 1207 | dumpButton(pw, "home", getHomeButton()); |
| 1208 | dumpButton(pw, "rcnt", getRecentsButton()); |
| 1209 | dumpButton(pw, "menu", getMenuButton()); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 1210 | dumpButton(pw, "a11y", getAccessibilityButton()); |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1211 | |
Tracy Zhou | 66efefd | 2018-05-16 15:03:09 -0700 | [diff] [blame] | 1212 | mRecentsOnboarding.dump(pw); |
| 1213 | |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 1214 | pw.println(" }"); |
| 1215 | } |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 1216 | |
Adrian Roos | 7e58a08 | 2018-03-09 16:40:56 +0100 | [diff] [blame] | 1217 | @Override |
| 1218 | public WindowInsets onApplyWindowInsets(WindowInsets insets) { |
| 1219 | setPadding(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(), |
| 1220 | insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom()); |
| 1221 | return super.onApplyWindowInsets(insets); |
| 1222 | } |
| 1223 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 1224 | private static void dumpButton(PrintWriter pw, String caption, ButtonDispatcher button) { |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 1225 | pw.print(" " + caption + ": "); |
| 1226 | if (button == null) { |
| 1227 | pw.print("null"); |
| 1228 | } else { |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 1229 | pw.print(visibilityToString(button.getVisibility()) |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 1230 | + " alpha=" + button.getAlpha() |
| 1231 | ); |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 1232 | } |
| 1233 | pw.println(); |
| 1234 | } |
| 1235 | |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 1236 | public interface OnVerticalChangedListener { |
| 1237 | void onVerticalChanged(boolean isVertical); |
| 1238 | } |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 1239 | |
Jason Monk | 32e3bb5 | 2017-07-27 12:35:41 -0400 | [diff] [blame] | 1240 | private final Consumer<Boolean> mDockedListener = exists -> mHandler.post(() -> { |
| 1241 | mDockedStackExists = exists; |
| 1242 | updateRecentsIcon(); |
| 1243 | }); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1244 | } |