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