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