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