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 | |
John Spurlock | 1bbd49d | 2012-10-19 11:09:32 -0400 | [diff] [blame] | 19 | import android.animation.LayoutTransition; |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 20 | import android.animation.LayoutTransition.TransitionListener; |
| 21 | import android.animation.ObjectAnimator; |
| 22 | import android.animation.TimeInterpolator; |
| 23 | import android.animation.ValueAnimator; |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 24 | import android.annotation.DrawableRes; |
Jason Monk | 00659ba | 2017-03-03 10:28:45 -0500 | [diff] [blame] | 25 | import android.app.ActivityManager; |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 26 | import android.app.StatusBarManager; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 27 | import android.content.Context; |
Selim Cinek | 17a327a | 2014-08-25 15:03:48 +0200 | [diff] [blame] | 28 | import android.content.res.Configuration; |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 29 | import android.graphics.Canvas; |
Jeff Brown | a8b9def | 2012-07-23 14:22:49 -0700 | [diff] [blame] | 30 | import android.graphics.Point; |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 31 | import android.graphics.Rect; |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 32 | import android.os.Handler; |
| 33 | import android.os.Message; |
Jason Monk | 17488b9 | 2014-11-06 11:26:14 -0500 | [diff] [blame] | 34 | import android.os.RemoteException; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 35 | import android.support.annotation.ColorInt; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 36 | import android.util.AttributeSet; |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 37 | import android.util.Log; |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 38 | import android.util.SparseArray; |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 39 | import android.view.ContextThemeWrapper; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 40 | import android.view.Display; |
Daniel Sandler | 1d4d30a | 2011-04-28 12:35:29 -0400 | [diff] [blame] | 41 | import android.view.MotionEvent; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 42 | import android.view.Surface; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 43 | import android.view.View; |
John Spurlock | 1bbd49d | 2012-10-19 11:09:32 -0400 | [diff] [blame] | 44 | import android.view.ViewGroup; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 45 | import android.view.WindowManager; |
Jason Monk | f1ff209 | 2014-04-29 16:50:53 -0400 | [diff] [blame] | 46 | import android.view.inputmethod.InputMethodManager; |
Jason Monk | 86bc331 | 2016-08-16 13:17:56 -0400 | [diff] [blame] | 47 | import android.widget.FrameLayout; |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 48 | |
Jason Monk | 9a376bc | 2017-05-10 09:52:10 -0400 | [diff] [blame] | 49 | import com.android.settingslib.Utils; |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 50 | import com.android.systemui.Dependency; |
Jason Monk | f85fc96 | 2017-04-19 17:13:41 -0400 | [diff] [blame] | 51 | import com.android.systemui.DockedStackExistsListener; |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 52 | import com.android.systemui.OverviewProxyService; |
| 53 | import com.android.systemui.OverviewProxyService.OverviewProxyListener; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 54 | import com.android.systemui.R; |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 55 | import com.android.systemui.RecentsComponent; |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 56 | import com.android.systemui.plugins.PluginListener; |
| 57 | import com.android.systemui.plugins.PluginManager; |
| 58 | import com.android.systemui.plugins.statusbar.phone.NavGesture; |
| 59 | import com.android.systemui.plugins.statusbar.phone.NavGesture.GestureHelper; |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 60 | import com.android.systemui.stackdivider.Divider; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 61 | import com.android.systemui.statusbar.policy.TintedKeyButtonDrawable; |
Daniel Sandler | c26185b | 2012-08-29 15:49:53 -0400 | [diff] [blame] | 62 | import com.android.systemui.statusbar.policy.DeadZone; |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 63 | import com.android.systemui.statusbar.policy.KeyButtonDrawable; |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 64 | |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 65 | import java.io.FileDescriptor; |
| 66 | import java.io.PrintWriter; |
Jason Monk | 32e3bb5 | 2017-07-27 12:35:41 -0400 | [diff] [blame] | 67 | import java.util.function.Consumer; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 68 | |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 69 | public class NavigationBarView extends FrameLayout implements PluginListener<NavGesture> { |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 70 | final static boolean DEBUG = false; |
Adrian Roos | a98b32c | 2016-08-11 10:41:08 -0700 | [diff] [blame] | 71 | final static String TAG = "StatusBar/NavBarView"; |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 72 | |
Daniel Sandler | c3fc322 | 2012-10-25 13:28:33 -0400 | [diff] [blame] | 73 | // slippery nav bar when everything is disabled, e.g. during setup |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 74 | final static boolean SLIPPERY_WHEN_DISABLED = true; |
Daniel Sandler | c3fc322 | 2012-10-25 13:28:33 -0400 | [diff] [blame] | 75 | |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 76 | final static boolean ALTERNATE_CAR_MODE_UI = false; |
| 77 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 78 | final Display mDisplay; |
Daniel Sandler | 5c8da94 | 2011-06-28 00:29:04 -0400 | [diff] [blame] | 79 | View mCurrentView = null; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 80 | View[] mRotatedViews = new View[4]; |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 81 | |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 82 | boolean mVertical; |
Adrian Roos | 090b7d8 | 2016-08-02 18:36:12 -0700 | [diff] [blame] | 83 | private int mCurrentRotation = -1; |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 84 | |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 85 | boolean mShowMenu; |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 86 | boolean mShowAccessibilityButton; |
| 87 | boolean mLongClickableAccessibilityButton; |
Daniel Sandler | 6da2b76 | 2011-09-14 16:04:59 -0400 | [diff] [blame] | 88 | int mDisabledFlags = 0; |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 89 | int mNavigationIconHints = 0; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 90 | |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 91 | private KeyButtonDrawable mBackIcon, mBackLandIcon, mBackAltIcon, mBackAltLandIcon; |
| 92 | private KeyButtonDrawable mBackCarModeIcon, mBackLandCarModeIcon; |
| 93 | private KeyButtonDrawable mBackAltCarModeIcon, mBackAltLandCarModeIcon; |
| 94 | private KeyButtonDrawable mHomeDefaultIcon, mHomeCarModeIcon; |
| 95 | private KeyButtonDrawable mRecentIcon; |
| 96 | private KeyButtonDrawable mDockedIcon; |
| 97 | private KeyButtonDrawable mImeIcon; |
| 98 | private KeyButtonDrawable mMenuIcon; |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 99 | private KeyButtonDrawable mAccessibilityIcon; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 100 | private KeyButtonDrawable mRotateSuggestionIcon; |
Fabrice Di Meglio | 18d9824 | 2013-01-17 10:57:40 -0800 | [diff] [blame] | 101 | |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 102 | private GestureHelper mGestureHelper; |
Daniel Sandler | c26185b | 2012-08-29 15:49:53 -0400 | [diff] [blame] | 103 | private DeadZone mDeadZone; |
John Spurlock | 89835dd | 2013-08-16 15:06:51 -0400 | [diff] [blame] | 104 | private final NavigationBarTransitions mBarTransitions; |
Matthew Ng | dc79e5c | 2017-12-14 17:37:35 -0800 | [diff] [blame] | 105 | private final OverviewProxyService mOverviewProxyService; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 106 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 107 | // workaround for LayoutTransitions leaving the nav buttons in a weird state (bug 5549288) |
| 108 | final static boolean WORKAROUND_INVALID_LAYOUT = true; |
| 109 | final static int MSG_CHECK_INVALID_LAYOUT = 8686; |
| 110 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 111 | // performs manual animation in sync with layout transitions |
| 112 | private final NavTransitionListener mTransitionListener = new NavTransitionListener(); |
| 113 | |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 114 | private OnVerticalChangedListener mOnVerticalChangedListener; |
Jorim Jaggi | 37c1180 | 2015-08-18 20:27:54 -0700 | [diff] [blame] | 115 | private boolean mLayoutTransitionsEnabled = true; |
| 116 | private boolean mWakeAndUnlocking; |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 117 | private boolean mUseCarModeUi = false; |
| 118 | private boolean mInCarMode = false; |
Jorim Jaggi | d30d95d | 2016-02-17 20:27:22 -0800 | [diff] [blame] | 119 | private boolean mDockedStackExists; |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 120 | |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 121 | private final SparseArray<ButtonDispatcher> mButtonDispatchers = new SparseArray<>(); |
Winson | fde2e6a | 2016-03-22 16:03:10 -0700 | [diff] [blame] | 122 | private Configuration mConfiguration; |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 123 | |
Adrian Roos | db12b15 | 2016-07-12 15:38:55 -0700 | [diff] [blame] | 124 | private NavigationBarInflaterView mNavigationInflaterView; |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 125 | private RecentsComponent mRecentsComponent; |
| 126 | private Divider mDivider; |
Adrian Roos | db12b15 | 2016-07-12 15:38:55 -0700 | [diff] [blame] | 127 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 128 | private class NavTransitionListener implements TransitionListener { |
| 129 | private boolean mBackTransitioning; |
| 130 | private boolean mHomeAppearing; |
| 131 | private long mStartDelay; |
| 132 | private long mDuration; |
| 133 | private TimeInterpolator mInterpolator; |
| 134 | |
| 135 | @Override |
| 136 | public void startTransition(LayoutTransition transition, ViewGroup container, |
| 137 | View view, int transitionType) { |
| 138 | if (view.getId() == R.id.back) { |
| 139 | mBackTransitioning = true; |
| 140 | } else if (view.getId() == R.id.home && transitionType == LayoutTransition.APPEARING) { |
| 141 | mHomeAppearing = true; |
| 142 | mStartDelay = transition.getStartDelay(transitionType); |
| 143 | mDuration = transition.getDuration(transitionType); |
| 144 | mInterpolator = transition.getInterpolator(transitionType); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | @Override |
| 149 | public void endTransition(LayoutTransition transition, ViewGroup container, |
| 150 | View view, int transitionType) { |
| 151 | if (view.getId() == R.id.back) { |
| 152 | mBackTransitioning = false; |
| 153 | } else if (view.getId() == R.id.home && transitionType == LayoutTransition.APPEARING) { |
| 154 | mHomeAppearing = false; |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | public void onBackAltCleared() { |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 159 | ButtonDispatcher backButton = getBackButton(); |
Anthony Chen | ada1304 | 2016-01-19 16:57:20 -0800 | [diff] [blame] | 160 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 161 | // When dismissing ime during unlock, force the back button to run the same appearance |
| 162 | // animation as home (if we catch this condition early enough). |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 163 | if (!mBackTransitioning && backButton.getVisibility() == VISIBLE |
| 164 | && mHomeAppearing && getHomeButton().getAlpha() == 0) { |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 165 | getBackButton().setAlpha(0); |
Anthony Chen | ada1304 | 2016-01-19 16:57:20 -0800 | [diff] [blame] | 166 | ValueAnimator a = ObjectAnimator.ofFloat(backButton, "alpha", 0, 1); |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 167 | a.setStartDelay(mStartDelay); |
| 168 | a.setDuration(mDuration); |
| 169 | a.setInterpolator(mInterpolator); |
| 170 | a.start(); |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | |
Jason Monk | f1ff209 | 2014-04-29 16:50:53 -0400 | [diff] [blame] | 175 | private final OnClickListener mImeSwitcherClickListener = new OnClickListener() { |
| 176 | @Override |
| 177 | public void onClick(View view) { |
Yohei Yukawa | 777ef95 | 2015-11-25 20:32:24 -0800 | [diff] [blame] | 178 | mContext.getSystemService(InputMethodManager.class) |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 179 | .showInputMethodPicker(true /* showAuxiliarySubtypes */); |
Jason Monk | f1ff209 | 2014-04-29 16:50:53 -0400 | [diff] [blame] | 180 | } |
| 181 | }; |
| 182 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 183 | private class H extends Handler { |
| 184 | public void handleMessage(Message m) { |
| 185 | switch (m.what) { |
| 186 | case MSG_CHECK_INVALID_LAYOUT: |
| 187 | final String how = "" + m.obj; |
| 188 | final int w = getWidth(); |
| 189 | final int h = getHeight(); |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 190 | final int vw = getCurrentView().getWidth(); |
| 191 | final int vh = getCurrentView().getHeight(); |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 192 | |
| 193 | if (h != vh || w != vw) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 194 | Log.w(TAG, String.format( |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 195 | "*** Invalid layout in navigation bar (%s this=%dx%d cur=%dx%d)", |
| 196 | how, w, h, vw, vh)); |
| 197 | if (WORKAROUND_INVALID_LAYOUT) { |
| 198 | requestLayout(); |
| 199 | } |
| 200 | } |
| 201 | break; |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | |
Matthew Ng | 3c6f2f2 | 2018-01-08 14:26:40 -0800 | [diff] [blame] | 206 | private final OverviewProxyListener mOverviewProxyListener = isConnected -> { |
| 207 | setSlippery(!isConnected); |
| 208 | setDisabledFlags(mDisabledFlags, true); |
| 209 | }; |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 210 | |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 211 | public NavigationBarView(Context context, AttributeSet attrs) { |
| 212 | super(context, attrs); |
| 213 | |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 214 | mDisplay = ((WindowManager) context.getSystemService( |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 215 | Context.WINDOW_SERVICE)).getDefaultDisplay(); |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 216 | |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 217 | mVertical = false; |
| 218 | mShowMenu = false; |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 219 | |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 220 | mShowAccessibilityButton = false; |
| 221 | mLongClickableAccessibilityButton = false; |
| 222 | |
Winson | fde2e6a | 2016-03-22 16:03:10 -0700 | [diff] [blame] | 223 | mConfiguration = new Configuration(); |
| 224 | mConfiguration.updateFrom(context.getResources().getConfiguration()); |
| 225 | updateIcons(context, Configuration.EMPTY, mConfiguration); |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 226 | |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 227 | mBarTransitions = new NavigationBarTransitions(this); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 228 | |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 229 | mButtonDispatchers.put(R.id.back, new ButtonDispatcher(R.id.back)); |
| 230 | mButtonDispatchers.put(R.id.home, new ButtonDispatcher(R.id.home)); |
| 231 | mButtonDispatchers.put(R.id.recent_apps, new ButtonDispatcher(R.id.recent_apps)); |
| 232 | mButtonDispatchers.put(R.id.menu, new ButtonDispatcher(R.id.menu)); |
| 233 | mButtonDispatchers.put(R.id.ime_switcher, new ButtonDispatcher(R.id.ime_switcher)); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 234 | mButtonDispatchers.put(R.id.accessibility_button, |
| 235 | new ButtonDispatcher(R.id.accessibility_button)); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 236 | mButtonDispatchers.put(R.id.rotate_suggestion, |
| 237 | new ButtonDispatcher(R.id.rotate_suggestion)); |
| 238 | |
Matthew Ng | dc79e5c | 2017-12-14 17:37:35 -0800 | [diff] [blame] | 239 | mOverviewProxyService = Dependency.get(OverviewProxyService.class); |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | public BarTransitions getBarTransitions() { |
| 243 | return mBarTransitions; |
| 244 | } |
| 245 | |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 246 | public LightBarTransitionsController getLightTransitionsController() { |
| 247 | return mBarTransitions.getLightTransitionsController(); |
| 248 | } |
| 249 | |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 250 | public void setComponents(RecentsComponent recentsComponent, Divider divider) { |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 251 | mRecentsComponent = recentsComponent; |
| 252 | mDivider = divider; |
| 253 | if (mGestureHelper instanceof NavigationBarGestureHelper) { |
| 254 | ((NavigationBarGestureHelper) mGestureHelper).setComponents( |
| 255 | recentsComponent, divider, this); |
| 256 | } |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 259 | public void setOnVerticalChangedListener(OnVerticalChangedListener onVerticalChangedListener) { |
| 260 | mOnVerticalChangedListener = onVerticalChangedListener; |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 261 | notifyVerticalChangedListener(mVertical); |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 262 | } |
| 263 | |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 264 | @Override |
Jim Miller | 960892c | 2012-05-23 15:50:04 -0700 | [diff] [blame] | 265 | public boolean onTouchEvent(MotionEvent event) { |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 266 | if (mGestureHelper.onTouchEvent(event)) { |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 267 | return true; |
| 268 | } |
Daniel Sandler | c26185b | 2012-08-29 15:49:53 -0400 | [diff] [blame] | 269 | return super.onTouchEvent(event); |
Jim Miller | 960892c | 2012-05-23 15:50:04 -0700 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | @Override |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 273 | public boolean onInterceptTouchEvent(MotionEvent event) { |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 274 | return mGestureHelper.onInterceptTouchEvent(event); |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Xiyuan Xia | ee7dd05 | 2015-05-15 09:46:27 -0700 | [diff] [blame] | 277 | public void abortCurrentGesture() { |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 278 | getHomeButton().abortCurrentGesture(); |
Xiyuan Xia | ee7dd05 | 2015-05-15 09:46:27 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 281 | private H mHandler = new H(); |
| 282 | |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 283 | public View getCurrentView() { |
| 284 | return mCurrentView; |
| 285 | } |
| 286 | |
Xiaohui Chen | 1094230 | 2015-12-16 16:38:13 -0800 | [diff] [blame] | 287 | public View[] getAllViews() { |
| 288 | return mRotatedViews; |
| 289 | } |
| 290 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 291 | public ButtonDispatcher getRecentsButton() { |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 292 | return mButtonDispatchers.get(R.id.recent_apps); |
Daniel Sandler | 5c8da94 | 2011-06-28 00:29:04 -0400 | [diff] [blame] | 293 | } |
| 294 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 295 | public ButtonDispatcher getMenuButton() { |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 296 | return mButtonDispatchers.get(R.id.menu); |
Daniel Sandler | 5c8da94 | 2011-06-28 00:29:04 -0400 | [diff] [blame] | 297 | } |
| 298 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 299 | public ButtonDispatcher getBackButton() { |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 300 | return mButtonDispatchers.get(R.id.back); |
Mike Lockwood | e3646dd | 2011-09-01 12:46:28 -0400 | [diff] [blame] | 301 | } |
| 302 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 303 | public ButtonDispatcher getHomeButton() { |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 304 | return mButtonDispatchers.get(R.id.home); |
Mike Lockwood | e3646dd | 2011-09-01 12:46:28 -0400 | [diff] [blame] | 305 | } |
| 306 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 307 | public ButtonDispatcher getImeSwitchButton() { |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 308 | return mButtonDispatchers.get(R.id.ime_switcher); |
Jason Monk | f1ff209 | 2014-04-29 16:50:53 -0400 | [diff] [blame] | 309 | } |
| 310 | |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 311 | public ButtonDispatcher getAccessibilityButton() { |
| 312 | return mButtonDispatchers.get(R.id.accessibility_button); |
| 313 | } |
| 314 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 315 | public ButtonDispatcher getRotateSuggestionButton() { |
| 316 | return mButtonDispatchers.get(R.id.rotate_suggestion); |
| 317 | } |
| 318 | |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 319 | public SparseArray<ButtonDispatcher> getButtonDispatchers() { |
| 320 | return mButtonDispatchers; |
| 321 | } |
| 322 | |
Winson | fde2e6a | 2016-03-22 16:03:10 -0700 | [diff] [blame] | 323 | private void updateCarModeIcons(Context ctx) { |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 324 | mBackCarModeIcon = getDrawable(ctx, |
| 325 | R.drawable.ic_sysbar_back_carmode, R.drawable.ic_sysbar_back_carmode); |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 326 | mBackLandCarModeIcon = mBackCarModeIcon; |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 327 | mBackAltCarModeIcon = getDrawable(ctx, |
| 328 | 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] | 329 | mBackAltLandCarModeIcon = mBackAltCarModeIcon; |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 330 | mHomeCarModeIcon = getDrawable(ctx, |
| 331 | R.drawable.ic_sysbar_home_carmode, R.drawable.ic_sysbar_home_carmode); |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 332 | } |
| 333 | |
Winson | fde2e6a | 2016-03-22 16:03:10 -0700 | [diff] [blame] | 334 | private void updateIcons(Context ctx, Configuration oldConfig, Configuration newConfig) { |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 335 | if (oldConfig.orientation != newConfig.orientation |
| 336 | || oldConfig.densityDpi != newConfig.densityDpi) { |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 337 | mDockedIcon = getDrawable(ctx, |
| 338 | R.drawable.ic_sysbar_docked, R.drawable.ic_sysbar_docked_dark); |
Winson | fde2e6a | 2016-03-22 16:03:10 -0700 | [diff] [blame] | 339 | } |
Jason Monk | 1f785d4 | 2017-07-25 15:46:33 -0400 | [diff] [blame] | 340 | if (oldConfig.densityDpi != newConfig.densityDpi |
| 341 | || oldConfig.getLayoutDirection() != newConfig.getLayoutDirection()) { |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 342 | mBackIcon = getDrawable(ctx, R.drawable.ic_sysbar_back, R.drawable.ic_sysbar_back_dark); |
Winson | fde2e6a | 2016-03-22 16:03:10 -0700 | [diff] [blame] | 343 | mBackLandIcon = mBackIcon; |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 344 | mBackAltIcon = getDrawable(ctx, |
| 345 | R.drawable.ic_sysbar_back_ime, R.drawable.ic_sysbar_back_ime_dark); |
Winson | fde2e6a | 2016-03-22 16:03:10 -0700 | [diff] [blame] | 346 | mBackAltLandIcon = mBackAltIcon; |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 347 | |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 348 | mHomeDefaultIcon = getDrawable(ctx, |
| 349 | R.drawable.ic_sysbar_home, R.drawable.ic_sysbar_home_dark); |
| 350 | mRecentIcon = getDrawable(ctx, |
| 351 | R.drawable.ic_sysbar_recent, R.drawable.ic_sysbar_recent_dark); |
| 352 | 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] | 353 | mAccessibilityIcon = getDrawable(ctx, R.drawable.ic_sysbar_accessibility_button, |
| 354 | R.drawable.ic_sysbar_accessibility_button_dark); |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 355 | |
Jason Monk | 9a376bc | 2017-05-10 09:52:10 -0400 | [diff] [blame] | 356 | int dualToneDarkTheme = Utils.getThemeAttr(ctx, R.attr.darkIconTheme); |
| 357 | int dualToneLightTheme = Utils.getThemeAttr(ctx, R.attr.lightIconTheme); |
| 358 | Context darkContext = new ContextThemeWrapper(ctx, dualToneDarkTheme); |
| 359 | Context lightContext = new ContextThemeWrapper(ctx, dualToneLightTheme); |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 360 | mImeIcon = getDrawable(darkContext, lightContext, |
| 361 | R.drawable.ic_ime_switcher_default, R.drawable.ic_ime_switcher_default); |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 362 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 363 | int lightColor = Utils.getColorAttr(lightContext, R.attr.singleToneColor); |
| 364 | int darkColor = Utils.getColorAttr(darkContext, R.attr.singleToneColor); |
| 365 | mRotateSuggestionIcon = getDrawable(ctx, R.drawable.ic_sysbar_rotate_button, |
| 366 | lightColor, darkColor); |
| 367 | |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 368 | if (ALTERNATE_CAR_MODE_UI) { |
| 369 | updateCarModeIcons(ctx); |
| 370 | } |
Winson | fde2e6a | 2016-03-22 16:03:10 -0700 | [diff] [blame] | 371 | } |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 372 | } |
| 373 | |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 374 | private KeyButtonDrawable getDrawable(Context ctx, @DrawableRes int lightIcon, |
| 375 | @DrawableRes int darkIcon) { |
| 376 | return getDrawable(ctx, ctx, lightIcon, darkIcon); |
| 377 | } |
| 378 | |
| 379 | private KeyButtonDrawable getDrawable(Context darkContext, Context lightContext, |
| 380 | @DrawableRes int lightIcon, @DrawableRes int darkIcon) { |
| 381 | return KeyButtonDrawable.create(lightContext.getDrawable(lightIcon), |
| 382 | darkContext.getDrawable(darkIcon)); |
| 383 | } |
| 384 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 385 | private KeyButtonDrawable getDrawable(Context ctx, @DrawableRes int icon, |
| 386 | @ColorInt int lightColor, @ColorInt int darkColor) { |
| 387 | return TintedKeyButtonDrawable.create(ctx.getDrawable(icon), lightColor, darkColor); |
| 388 | } |
| 389 | |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 390 | @Override |
| 391 | public void setLayoutDirection(int layoutDirection) { |
Winson | fde2e6a | 2016-03-22 16:03:10 -0700 | [diff] [blame] | 392 | // Reload all the icons |
| 393 | updateIcons(getContext(), Configuration.EMPTY, mConfiguration); |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 394 | |
| 395 | super.setLayoutDirection(layoutDirection); |
Daniel Sandler | 1d4d30a | 2011-04-28 12:35:29 -0400 | [diff] [blame] | 396 | } |
| 397 | |
Siarhei Vishniakou | d002a0a | 2017-06-05 22:44:37 +0100 | [diff] [blame] | 398 | public void notifyScreenOn() { |
John Spurlock | 1bbd49d | 2012-10-19 11:09:32 -0400 | [diff] [blame] | 399 | setDisabledFlags(mDisabledFlags, true); |
| 400 | } |
| 401 | |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 402 | public void setNavigationIconHints(int hints) { |
| 403 | setNavigationIconHints(hints, false); |
| 404 | } |
| 405 | |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 406 | private KeyButtonDrawable getBackIconWithAlt(boolean carMode, boolean landscape) { |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 407 | return landscape |
| 408 | ? carMode ? mBackAltLandCarModeIcon : mBackAltLandIcon |
| 409 | : carMode ? mBackAltCarModeIcon : mBackAltIcon; |
| 410 | } |
| 411 | |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 412 | private KeyButtonDrawable getBackIcon(boolean carMode, boolean landscape) { |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 413 | return landscape |
| 414 | ? carMode ? mBackLandCarModeIcon : mBackLandIcon |
| 415 | : carMode ? mBackCarModeIcon : mBackIcon; |
| 416 | } |
| 417 | |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 418 | public void setNavigationIconHints(int hints, boolean force) { |
| 419 | if (!force && hints == mNavigationIconHints) return; |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 420 | final boolean backAlt = (hints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) != 0; |
| 421 | if ((mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) != 0 && !backAlt) { |
| 422 | mTransitionListener.onBackAltCleared(); |
| 423 | } |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 424 | if (DEBUG) { |
John Spurlock | 0153478 | 2014-01-13 11:59:22 -0500 | [diff] [blame] | 425 | android.widget.Toast.makeText(getContext(), |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 426 | "Navigation icon hints = " + hints, |
| 427 | 500).show(); |
| 428 | } |
| 429 | |
| 430 | mNavigationIconHints = hints; |
| 431 | |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 432 | // We have to replace or restore the back and home button icons when exiting or entering |
| 433 | // carmode, respectively. Recents are not available in CarMode in nav bar so change |
| 434 | // to recent icon is not required. |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 435 | KeyButtonDrawable backIcon = (backAlt) |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 436 | ? getBackIconWithAlt(mUseCarModeUi, mVertical) |
| 437 | : getBackIcon(mUseCarModeUi, mVertical); |
John Spurlock | a9b4682 | 2012-11-02 10:42:39 -0400 | [diff] [blame] | 438 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 439 | getBackButton().setImageDrawable(backIcon); |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 440 | |
Jorim Jaggi | d30d95d | 2016-02-17 20:27:22 -0800 | [diff] [blame] | 441 | updateRecentsIcon(); |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 442 | |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 443 | if (mUseCarModeUi) { |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 444 | getHomeButton().setImageDrawable(mHomeCarModeIcon); |
| 445 | } else { |
| 446 | getHomeButton().setImageDrawable(mHomeDefaultIcon); |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 447 | } |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 448 | |
Casey Burkhardt | 2464dc9 | 2017-03-28 15:52:12 -0700 | [diff] [blame] | 449 | // The Accessibility button always overrides the appearance of the IME switcher |
| 450 | final boolean showImeButton = |
| 451 | !mShowAccessibilityButton && ((hints & StatusBarManager.NAVIGATION_HINT_IME_SHOWN) |
| 452 | != 0); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 453 | getImeSwitchButton().setVisibility(showImeButton ? View.VISIBLE : View.INVISIBLE); |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 454 | getImeSwitchButton().setImageDrawable(mImeIcon); |
Anthony Chen | ada1304 | 2016-01-19 16:57:20 -0800 | [diff] [blame] | 455 | |
Jason Monk | f1ff209 | 2014-04-29 16:50:53 -0400 | [diff] [blame] | 456 | // Update menu button in case the IME state has changed. |
| 457 | setMenuVisibility(mShowMenu, true); |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 458 | getMenuButton().setImageDrawable(mMenuIcon); |
Jason Monk | f1ff209 | 2014-04-29 16:50:53 -0400 | [diff] [blame] | 459 | |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 460 | setAccessibilityButtonState(mShowAccessibilityButton, mLongClickableAccessibilityButton); |
| 461 | getAccessibilityButton().setImageDrawable(mAccessibilityIcon); |
| 462 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 463 | getRotateSuggestionButton().setImageDrawable(mRotateSuggestionIcon); |
| 464 | |
John Spurlock | a9b4682 | 2012-11-02 10:42:39 -0400 | [diff] [blame] | 465 | setDisabledFlags(mDisabledFlags, true); |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 466 | |
| 467 | mBarTransitions.reapplyDarkIntensity(); |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 468 | } |
| 469 | |
Daniel Sandler | 6da2b76 | 2011-09-14 16:04:59 -0400 | [diff] [blame] | 470 | public void setDisabledFlags(int disabledFlags) { |
Daniel Sandler | 6da2b76 | 2011-09-14 16:04:59 -0400 | [diff] [blame] | 471 | setDisabledFlags(disabledFlags, false); |
| 472 | } |
| 473 | |
| 474 | public void setDisabledFlags(int disabledFlags, boolean force) { |
| 475 | if (!force && mDisabledFlags == disabledFlags) return; |
| 476 | |
| 477 | mDisabledFlags = disabledFlags; |
| 478 | |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 479 | final boolean disableHome = ((disabledFlags & View.STATUS_BAR_DISABLE_HOME) != 0); |
Sriram Viswanathan | 469caae | 2016-03-22 13:11:50 -0700 | [diff] [blame] | 480 | |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 481 | // Always disable recents when alternate car mode UI is active. |
| 482 | boolean disableRecent = mUseCarModeUi |
Charles He | e57ff81 | 2017-10-26 10:01:35 +0100 | [diff] [blame] | 483 | || ((disabledFlags & View.STATUS_BAR_DISABLE_RECENT) != 0); |
| 484 | |
| 485 | boolean disableBack = ((disabledFlags & View.STATUS_BAR_DISABLE_BACK) != 0) |
John Spurlock | a9b4682 | 2012-11-02 10:42:39 -0400 | [diff] [blame] | 486 | && ((mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) == 0); |
Daniel Sandler | 029d587 | 2011-09-12 00:58:58 -0400 | [diff] [blame] | 487 | |
Charles He | e57ff81 | 2017-10-26 10:01:35 +0100 | [diff] [blame] | 488 | if ((disableRecent || disableBack) && inScreenPinning()) { |
| 489 | // Don't hide back and recents buttons when in screen pinning mode, as they are used for |
| 490 | // exiting. |
| 491 | disableBack = false; |
| 492 | disableRecent = false; |
| 493 | } |
Matthew Ng | dc79e5c | 2017-12-14 17:37:35 -0800 | [diff] [blame] | 494 | if (mOverviewProxyService.getProxy() != null) { |
| 495 | // When overview is connected to the launcher service, disable the recents button |
| 496 | disableRecent = true; |
| 497 | } |
Charles He | e57ff81 | 2017-10-26 10:01:35 +0100 | [diff] [blame] | 498 | |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 499 | ViewGroup navButtons = (ViewGroup) getCurrentView().findViewById(R.id.nav_buttons); |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 500 | if (navButtons != null) { |
| 501 | LayoutTransition lt = navButtons.getLayoutTransition(); |
John Spurlock | 1bbd49d | 2012-10-19 11:09:32 -0400 | [diff] [blame] | 502 | if (lt != null) { |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 503 | if (!lt.getTransitionListeners().contains(mTransitionListener)) { |
| 504 | lt.addTransitionListener(mTransitionListener); |
| 505 | } |
John Spurlock | 1bbd49d | 2012-10-19 11:09:32 -0400 | [diff] [blame] | 506 | } |
| 507 | } |
| 508 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 509 | getBackButton().setVisibility(disableBack ? View.INVISIBLE : View.VISIBLE); |
Jason Monk | 188908f | 2016-01-22 10:23:51 -0500 | [diff] [blame] | 510 | getHomeButton().setVisibility(disableHome ? View.INVISIBLE : View.VISIBLE); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 511 | getRecentsButton().setVisibility(disableRecent ? View.INVISIBLE : View.VISIBLE); |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 512 | } |
| 513 | |
Charles He | e57ff81 | 2017-10-26 10:01:35 +0100 | [diff] [blame] | 514 | private boolean inScreenPinning() { |
Jason Monk | 17488b9 | 2014-11-06 11:26:14 -0500 | [diff] [blame] | 515 | try { |
Charles He | e57ff81 | 2017-10-26 10:01:35 +0100 | [diff] [blame] | 516 | return ActivityManager.getService().getLockTaskModeState() |
| 517 | == ActivityManager.LOCK_TASK_MODE_PINNED; |
Jason Monk | 17488b9 | 2014-11-06 11:26:14 -0500 | [diff] [blame] | 518 | } catch (RemoteException e) { |
| 519 | return false; |
| 520 | } |
| 521 | } |
| 522 | |
Jorim Jaggi | 37c1180 | 2015-08-18 20:27:54 -0700 | [diff] [blame] | 523 | public void setLayoutTransitionsEnabled(boolean enabled) { |
| 524 | mLayoutTransitionsEnabled = enabled; |
| 525 | updateLayoutTransitionsEnabled(); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 526 | } |
| 527 | |
Jorim Jaggi | 37c1180 | 2015-08-18 20:27:54 -0700 | [diff] [blame] | 528 | public void setWakeAndUnlocking(boolean wakeAndUnlocking) { |
| 529 | setUseFadingAnimations(wakeAndUnlocking); |
| 530 | mWakeAndUnlocking = wakeAndUnlocking; |
| 531 | updateLayoutTransitionsEnabled(); |
| 532 | } |
| 533 | |
| 534 | private void updateLayoutTransitionsEnabled() { |
| 535 | boolean enabled = !mWakeAndUnlocking && mLayoutTransitionsEnabled; |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 536 | ViewGroup navButtons = (ViewGroup) getCurrentView().findViewById(R.id.nav_buttons); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 537 | LayoutTransition lt = navButtons.getLayoutTransition(); |
Julia Reynolds | 8478aba | 2015-07-31 09:17:20 -0400 | [diff] [blame] | 538 | if (lt != null) { |
| 539 | if (enabled) { |
| 540 | lt.enableTransitionType(LayoutTransition.APPEARING); |
| 541 | lt.enableTransitionType(LayoutTransition.DISAPPEARING); |
| 542 | lt.enableTransitionType(LayoutTransition.CHANGE_APPEARING); |
| 543 | lt.enableTransitionType(LayoutTransition.CHANGE_DISAPPEARING); |
| 544 | } else { |
| 545 | lt.disableTransitionType(LayoutTransition.APPEARING); |
| 546 | lt.disableTransitionType(LayoutTransition.DISAPPEARING); |
| 547 | lt.disableTransitionType(LayoutTransition.CHANGE_APPEARING); |
| 548 | lt.disableTransitionType(LayoutTransition.CHANGE_DISAPPEARING); |
| 549 | } |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 550 | } |
| 551 | } |
| 552 | |
| 553 | private void setUseFadingAnimations(boolean useFadingAnimations) { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 554 | WindowManager.LayoutParams lp = (WindowManager.LayoutParams) ((ViewGroup) getParent()) |
| 555 | .getLayoutParams(); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 556 | if (lp != null) { |
| 557 | boolean old = lp.windowAnimations != 0; |
| 558 | if (!old && useFadingAnimations) { |
| 559 | lp.windowAnimations = R.style.Animation_NavigationBarFadeIn; |
| 560 | } else if (old && !useFadingAnimations) { |
| 561 | lp.windowAnimations = 0; |
| 562 | } else { |
| 563 | return; |
| 564 | } |
| 565 | WindowManager wm = (WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 566 | wm.updateViewLayout((View) getParent(), lp); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 567 | } |
| 568 | } |
| 569 | |
Matthew Ng | 7d05e77 | 2017-11-09 14:41:07 -0800 | [diff] [blame] | 570 | private void setSlippery(boolean slippery) { |
| 571 | boolean changed = false; |
| 572 | final ViewGroup navbarView = ((ViewGroup) getParent()); |
| 573 | final WindowManager.LayoutParams lp = (WindowManager.LayoutParams) navbarView |
| 574 | .getLayoutParams(); |
| 575 | if (slippery && (lp.flags & WindowManager.LayoutParams.FLAG_SLIPPERY) == 0) { |
| 576 | lp.flags |= WindowManager.LayoutParams.FLAG_SLIPPERY; |
| 577 | changed = true; |
| 578 | } else if (!slippery && (lp.flags & WindowManager.LayoutParams.FLAG_SLIPPERY) != 0) { |
| 579 | lp.flags &= ~WindowManager.LayoutParams.FLAG_SLIPPERY; |
| 580 | changed = true; |
| 581 | } |
| 582 | if (changed) { |
| 583 | WindowManager wm = (WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE); |
| 584 | wm.updateViewLayout(navbarView, lp); |
| 585 | } |
| 586 | } |
| 587 | |
Daniel Sandler | 56598cd | 2011-09-15 16:02:56 -0400 | [diff] [blame] | 588 | public void setMenuVisibility(final boolean show) { |
| 589 | setMenuVisibility(show, false); |
| 590 | } |
| 591 | |
| 592 | public void setMenuVisibility(final boolean show, final boolean force) { |
| 593 | if (!force && mShowMenu == show) return; |
| 594 | |
| 595 | mShowMenu = show; |
| 596 | |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 597 | // Only show Menu if IME switcher and Accessibility button not shown. |
| 598 | final boolean shouldShow = mShowMenu && !mShowAccessibilityButton && |
Jason Monk | f1ff209 | 2014-04-29 16:50:53 -0400 | [diff] [blame] | 599 | ((mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_IME_SHOWN) == 0); |
Anthony Chen | ada1304 | 2016-01-19 16:57:20 -0800 | [diff] [blame] | 600 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 601 | getMenuButton().setVisibility(shouldShow ? View.VISIBLE : View.INVISIBLE); |
Daniel Sandler | 029d587 | 2011-09-12 00:58:58 -0400 | [diff] [blame] | 602 | } |
| 603 | |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 604 | public void setAccessibilityButtonState(final boolean visible, final boolean longClickable) { |
| 605 | mShowAccessibilityButton = visible; |
| 606 | mLongClickableAccessibilityButton = longClickable; |
| 607 | if (visible) { |
Casey Burkhardt | 2464dc9 | 2017-03-28 15:52:12 -0700 | [diff] [blame] | 608 | // Accessibility button overrides Menu and IME switcher buttons. |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 609 | setMenuVisibility(false, true); |
Casey Burkhardt | 2464dc9 | 2017-03-28 15:52:12 -0700 | [diff] [blame] | 610 | getImeSwitchButton().setVisibility(View.INVISIBLE); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | getAccessibilityButton().setVisibility(visible ? View.VISIBLE : View.INVISIBLE); |
| 614 | getAccessibilityButton().setLongClickable(longClickable); |
| 615 | } |
| 616 | |
Jim Miller | 960892c | 2012-05-23 15:50:04 -0700 | [diff] [blame] | 617 | @Override |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 618 | public void onFinishInflate() { |
Adrian Roos | db12b15 | 2016-07-12 15:38:55 -0700 | [diff] [blame] | 619 | mNavigationInflaterView = (NavigationBarInflaterView) findViewById( |
| 620 | R.id.navigation_inflater); |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 621 | mNavigationInflaterView.setButtonDispatchers(mButtonDispatchers); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 622 | |
| 623 | getImeSwitchButton().setOnClickListener(mImeSwitcherClickListener); |
Selim Cinek | 17a327a | 2014-08-25 15:03:48 +0200 | [diff] [blame] | 624 | |
Jason Monk | 32e3bb5 | 2017-07-27 12:35:41 -0400 | [diff] [blame] | 625 | DockedStackExistsListener.register(mDockedListener); |
Siarhei Vishniakou | fdb4277 | 2017-06-29 10:32:11 -0700 | [diff] [blame] | 626 | updateRotatedViews(); |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 627 | } |
| 628 | |
Matthew Ng | a8f2426 | 2017-12-19 11:54:24 -0800 | [diff] [blame] | 629 | public void onDarkIntensityChange(float intensity) { |
| 630 | if (mGestureHelper != null) { |
| 631 | mGestureHelper.onDarkIntensityChange(intensity); |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | @Override |
| 636 | protected void onDraw(Canvas canvas) { |
| 637 | mGestureHelper.onDraw(canvas); |
| 638 | super.onDraw(canvas); |
| 639 | } |
| 640 | |
| 641 | @Override |
| 642 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 643 | super.onLayout(changed, left, top, right, bottom); |
| 644 | mGestureHelper.onLayout(changed, left, top, right, bottom); |
| 645 | } |
| 646 | |
Siarhei Vishniakou | fdb4277 | 2017-06-29 10:32:11 -0700 | [diff] [blame] | 647 | private void updateRotatedViews() { |
Jason Monk | 9a6552d | 2016-05-20 11:21:59 -0400 | [diff] [blame] | 648 | mRotatedViews[Surface.ROTATION_0] = |
| 649 | mRotatedViews[Surface.ROTATION_180] = findViewById(R.id.rot0); |
| 650 | mRotatedViews[Surface.ROTATION_270] = |
| 651 | mRotatedViews[Surface.ROTATION_90] = findViewById(R.id.rot90); |
| 652 | |
Jason Monk | 199a2d0 | 2017-07-28 11:08:27 -0400 | [diff] [blame] | 653 | updateCurrentView(); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 654 | } |
| 655 | |
Adrian Roos | a98b32c | 2016-08-11 10:41:08 -0700 | [diff] [blame] | 656 | public boolean needsReorient(int rotation) { |
| 657 | return mCurrentRotation != rotation; |
Adrian Roos | 090b7d8 | 2016-08-02 18:36:12 -0700 | [diff] [blame] | 658 | } |
| 659 | |
Jason Monk | 199a2d0 | 2017-07-28 11:08:27 -0400 | [diff] [blame] | 660 | private void updateCurrentView() { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 661 | final int rot = mDisplay.getRotation(); |
| 662 | for (int i=0; i<4; i++) { |
| 663 | mRotatedViews[i].setVisibility(View.GONE); |
| 664 | } |
Daniel Sandler | 5c8da94 | 2011-06-28 00:29:04 -0400 | [diff] [blame] | 665 | mCurrentView = mRotatedViews[rot]; |
| 666 | mCurrentView.setVisibility(View.VISIBLE); |
Adrian Roos | db12b15 | 2016-07-12 15:38:55 -0700 | [diff] [blame] | 667 | mNavigationInflaterView.setAlternativeOrder(rot == Surface.ROTATION_90); |
Felipe Leme | 15f915c | 2016-10-31 12:47:15 -0700 | [diff] [blame] | 668 | for (int i = 0; i < mButtonDispatchers.size(); i++) { |
| 669 | mButtonDispatchers.valueAt(i).setCurrentView(mCurrentView); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 670 | } |
Jorim Jaggi | 37c1180 | 2015-08-18 20:27:54 -0700 | [diff] [blame] | 671 | updateLayoutTransitionsEnabled(); |
Adrian Roos | 090b7d8 | 2016-08-02 18:36:12 -0700 | [diff] [blame] | 672 | mCurrentRotation = rot; |
Jason Monk | 9a6552d | 2016-05-20 11:21:59 -0400 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | private void updateRecentsIcon() { |
| 676 | getRecentsButton().setImageDrawable(mDockedStackExists ? mDockedIcon : mRecentIcon); |
Jorim Jaggi | 40db029 | 2016-06-27 17:58:03 -0700 | [diff] [blame] | 677 | mBarTransitions.reapplyDarkIntensity(); |
Jason Monk | 9a6552d | 2016-05-20 11:21:59 -0400 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | public boolean isVertical() { |
| 681 | return mVertical; |
| 682 | } |
| 683 | |
| 684 | public void reorient() { |
Jason Monk | 199a2d0 | 2017-07-28 11:08:27 -0400 | [diff] [blame] | 685 | updateCurrentView(); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 686 | |
Daniel Sandler | c26185b | 2012-08-29 15:49:53 -0400 | [diff] [blame] | 687 | mDeadZone = (DeadZone) mCurrentView.findViewById(R.id.deadzone); |
Siarhei Vishniakou | fdb4277 | 2017-06-29 10:32:11 -0700 | [diff] [blame] | 688 | |
| 689 | ((NavigationBarFrame) getRootView()).setDeadZone(mDeadZone); |
Jorim Jaggi | 7aaa3d7 | 2016-11-28 14:03:11 +0100 | [diff] [blame] | 690 | mDeadZone.setDisplayRotation(mCurrentRotation); |
Daniel Sandler | c26185b | 2012-08-29 15:49:53 -0400 | [diff] [blame] | 691 | |
Daniel Sandler | 6da2b76 | 2011-09-14 16:04:59 -0400 | [diff] [blame] | 692 | // force the low profile & disabled states into compliance |
Adrian Roos | 8a8ffd4 | 2015-05-26 18:30:37 -0700 | [diff] [blame] | 693 | mBarTransitions.init(); |
Daniel Sandler | 6da2b76 | 2011-09-14 16:04:59 -0400 | [diff] [blame] | 694 | setDisabledFlags(mDisabledFlags, true /* force */); |
Daniel Sandler | 56598cd | 2011-09-15 16:02:56 -0400 | [diff] [blame] | 695 | setMenuVisibility(mShowMenu, true /* force */); |
Daniel Sandler | 6da2b76 | 2011-09-14 16:04:59 -0400 | [diff] [blame] | 696 | |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 697 | if (DEBUG) { |
Adrian Roos | a98b32c | 2016-08-11 10:41:08 -0700 | [diff] [blame] | 698 | Log.d(TAG, "reorient(): rot=" + mCurrentRotation); |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 699 | } |
Michael Jurka | a5d0ddb | 2012-03-09 17:41:41 -0800 | [diff] [blame] | 700 | |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 701 | updateTaskSwitchHelper(); |
Michael Jurka | a5d0ddb | 2012-03-09 17:41:41 -0800 | [diff] [blame] | 702 | setNavigationIconHints(mNavigationIconHints, true); |
Xiaohui Chen | 9efa5de | 2016-11-22 10:34:38 -0800 | [diff] [blame] | 703 | |
Xiaohui Chen | 40e978e | 2016-11-29 15:10:04 -0800 | [diff] [blame] | 704 | getHomeButton().setVertical(mVertical); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 705 | } |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 706 | |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 707 | private void updateTaskSwitchHelper() { |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 708 | if (mGestureHelper == null) return; |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 709 | boolean isRtl = (getLayoutDirection() == View.LAYOUT_DIRECTION_RTL); |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 710 | mGestureHelper.setBarState(mVertical, isRtl); |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 711 | } |
| 712 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 713 | @Override |
| 714 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 715 | if (DEBUG) Log.d(TAG, String.format( |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 716 | "onSizeChanged: (%dx%d) old: (%dx%d)", w, h, oldw, oldh)); |
Daniel Sandler | e03bc95 | 2012-04-27 16:11:22 -0400 | [diff] [blame] | 717 | |
| 718 | final boolean newVertical = w > 0 && h > w; |
| 719 | if (newVertical != mVertical) { |
| 720 | mVertical = newVertical; |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 721 | //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] | 722 | reorient(); |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 723 | notifyVerticalChangedListener(newVertical); |
Daniel Sandler | e03bc95 | 2012-04-27 16:11:22 -0400 | [diff] [blame] | 724 | } |
| 725 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 726 | postCheckForInvalidLayout("sizeChanged"); |
| 727 | super.onSizeChanged(w, h, oldw, oldh); |
| 728 | } |
| 729 | |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 730 | private void notifyVerticalChangedListener(boolean newVertical) { |
| 731 | if (mOnVerticalChangedListener != null) { |
| 732 | mOnVerticalChangedListener.onVerticalChanged(newVertical); |
| 733 | } |
| 734 | } |
| 735 | |
Selim Cinek | 17a327a | 2014-08-25 15:03:48 +0200 | [diff] [blame] | 736 | @Override |
| 737 | protected void onConfigurationChanged(Configuration newConfig) { |
| 738 | super.onConfigurationChanged(newConfig); |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 739 | boolean uiCarModeChanged = updateCarMode(newConfig); |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 740 | updateTaskSwitchHelper(); |
Winson | fde2e6a | 2016-03-22 16:03:10 -0700 | [diff] [blame] | 741 | updateIcons(getContext(), mConfiguration, newConfig); |
| 742 | updateRecentsIcon(); |
Jason Monk | 1f785d4 | 2017-07-25 15:46:33 -0400 | [diff] [blame] | 743 | if (uiCarModeChanged || mConfiguration.densityDpi != newConfig.densityDpi |
| 744 | || mConfiguration.getLayoutDirection() != newConfig.getLayoutDirection()) { |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 745 | // If car mode or density changes, we need to reset the icons. |
| 746 | setNavigationIconHints(mNavigationIconHints, true); |
| 747 | } |
Winson | fde2e6a | 2016-03-22 16:03:10 -0700 | [diff] [blame] | 748 | mConfiguration.updateFrom(newConfig); |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | /** |
| 752 | * If the configuration changed, update the carmode and return that it was updated. |
| 753 | */ |
| 754 | private boolean updateCarMode(Configuration newConfig) { |
| 755 | boolean uiCarModeChanged = false; |
| 756 | if (newConfig != null) { |
| 757 | int uiMode = newConfig.uiMode & Configuration.UI_MODE_TYPE_MASK; |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 758 | final boolean isCarMode = (uiMode == Configuration.UI_MODE_TYPE_CAR); |
| 759 | |
| 760 | if (isCarMode != mInCarMode) { |
| 761 | mInCarMode = isCarMode; |
Justin Paupore | 01915a1 | 2016-09-28 17:41:26 -0700 | [diff] [blame] | 762 | if (ALTERNATE_CAR_MODE_UI) { |
| 763 | mUseCarModeUi = isCarMode; |
| 764 | uiCarModeChanged = true; |
| 765 | } else { |
| 766 | // Don't use car mode behavior if ALTERNATE_CAR_MODE_UI not set. |
| 767 | mUseCarModeUi = false; |
| 768 | } |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 769 | } |
| 770 | } |
| 771 | return uiCarModeChanged; |
Selim Cinek | 17a327a | 2014-08-25 15:03:48 +0200 | [diff] [blame] | 772 | } |
| 773 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 774 | /* |
| 775 | @Override |
| 776 | 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] | 777 | if (DEBUG) Log.d(TAG, String.format( |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 778 | "onLayout: %s (%d,%d,%d,%d)", |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 779 | changed?"changed":"notchanged", left, top, right, bottom)); |
| 780 | super.onLayout(changed, left, top, right, bottom); |
| 781 | } |
| 782 | |
| 783 | // uncomment this for extra defensiveness in WORKAROUND_INVALID_LAYOUT situations: if all else |
| 784 | // fails, any touch on the display will fix the layout. |
| 785 | @Override |
| 786 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 787 | if (DEBUG) Log.d(TAG, "onInterceptTouchEvent: " + ev.toString()); |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 788 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
| 789 | postCheckForInvalidLayout("touch"); |
| 790 | } |
| 791 | return super.onInterceptTouchEvent(ev); |
| 792 | } |
| 793 | */ |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 794 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 795 | |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 796 | private String getResourceName(int resId) { |
| 797 | if (resId != 0) { |
John Spurlock | 0153478 | 2014-01-13 11:59:22 -0500 | [diff] [blame] | 798 | final android.content.res.Resources res = getContext().getResources(); |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 799 | try { |
| 800 | return res.getResourceName(resId); |
| 801 | } catch (android.content.res.Resources.NotFoundException ex) { |
| 802 | return "(unknown)"; |
| 803 | } |
| 804 | } else { |
| 805 | return "(null)"; |
| 806 | } |
| 807 | } |
| 808 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 809 | private void postCheckForInvalidLayout(final String how) { |
| 810 | mHandler.obtainMessage(MSG_CHECK_INVALID_LAYOUT, 0, 0, how).sendToTarget(); |
| 811 | } |
| 812 | |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 813 | private static String visibilityToString(int vis) { |
| 814 | switch (vis) { |
| 815 | case View.INVISIBLE: |
| 816 | return "INVISIBLE"; |
| 817 | case View.GONE: |
| 818 | return "GONE"; |
| 819 | default: |
| 820 | return "VISIBLE"; |
| 821 | } |
| 822 | } |
| 823 | |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 824 | @Override |
| 825 | protected void onAttachedToWindow() { |
| 826 | super.onAttachedToWindow(); |
Siarhei Vishniakou | fdb4277 | 2017-06-29 10:32:11 -0700 | [diff] [blame] | 827 | reorient(); |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 828 | onPluginDisconnected(null); // Create default gesture helper |
Jason Monk | 5bec68f | 2017-02-08 20:45:10 -0800 | [diff] [blame] | 829 | Dependency.get(PluginManager.class).addPluginListener(this, |
| 830 | NavGesture.class, false /* Only one */); |
Matthew Ng | dc79e5c | 2017-12-14 17:37:35 -0800 | [diff] [blame] | 831 | mOverviewProxyService.addCallback(mOverviewProxyListener); |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | @Override |
| 835 | protected void onDetachedFromWindow() { |
| 836 | super.onDetachedFromWindow(); |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 837 | Dependency.get(PluginManager.class).removePluginListener(this); |
| 838 | if (mGestureHelper != null) { |
| 839 | mGestureHelper.destroy(); |
| 840 | } |
Matthew Ng | dc79e5c | 2017-12-14 17:37:35 -0800 | [diff] [blame] | 841 | mOverviewProxyService.removeCallback(mOverviewProxyListener); |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | @Override |
Jason Monk | 20ff3f9 | 2017-01-09 15:13:23 -0500 | [diff] [blame] | 845 | public void onPluginConnected(NavGesture plugin, Context context) { |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 846 | mGestureHelper = plugin.getGestureHelper(); |
| 847 | updateTaskSwitchHelper(); |
| 848 | } |
| 849 | |
| 850 | @Override |
| 851 | public void onPluginDisconnected(NavGesture plugin) { |
| 852 | NavigationBarGestureHelper defaultHelper = new NavigationBarGestureHelper(getContext()); |
| 853 | defaultHelper.setComponents(mRecentsComponent, mDivider, this); |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 854 | if (mGestureHelper != null) { |
| 855 | mGestureHelper.destroy(); |
| 856 | } |
Jason Monk | 67e6c80 | 2016-08-30 14:09:21 -0400 | [diff] [blame] | 857 | mGestureHelper = defaultHelper; |
| 858 | updateTaskSwitchHelper(); |
| 859 | } |
| 860 | |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 861 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 862 | pw.println("NavigationBarView {"); |
| 863 | final Rect r = new Rect(); |
Jeff Brown | a8b9def | 2012-07-23 14:22:49 -0700 | [diff] [blame] | 864 | final Point size = new Point(); |
| 865 | mDisplay.getRealSize(size); |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 866 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 867 | pw.println(String.format(" this: " + StatusBar.viewInfo(this) |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 868 | + " " + visibilityToString(getVisibility()))); |
| 869 | |
| 870 | getWindowVisibleDisplayFrame(r); |
Jeff Brown | a8b9def | 2012-07-23 14:22:49 -0700 | [diff] [blame] | 871 | final boolean offscreen = r.right > size.x || r.bottom > size.y; |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 872 | pw.println(" window: " |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 873 | + r.toShortString() |
| 874 | + " " + visibilityToString(getWindowVisibility()) |
| 875 | + (offscreen ? " OFFSCREEN!" : "")); |
| 876 | |
| 877 | pw.println(String.format(" mCurrentView: id=%s (%dx%d) %s", |
Rakesh Iyer | f51fe4e | 2016-02-09 10:51:50 -0800 | [diff] [blame] | 878 | getResourceName(getCurrentView().getId()), |
| 879 | getCurrentView().getWidth(), getCurrentView().getHeight(), |
| 880 | visibilityToString(getCurrentView().getVisibility()))); |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 881 | |
John Spurlock | 41c1e35 | 2013-09-16 13:57:13 -0400 | [diff] [blame] | 882 | pw.println(String.format(" disabled=0x%08x vertical=%s menu=%s", |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 883 | mDisabledFlags, |
| 884 | mVertical ? "true" : "false", |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 885 | mShowMenu ? "true" : "false")); |
| 886 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 887 | dumpButton(pw, "back", getBackButton()); |
| 888 | dumpButton(pw, "home", getHomeButton()); |
| 889 | dumpButton(pw, "rcnt", getRecentsButton()); |
| 890 | dumpButton(pw, "menu", getMenuButton()); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 891 | dumpButton(pw, "a11y", getAccessibilityButton()); |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 892 | |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 893 | pw.println(" }"); |
| 894 | } |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 895 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 896 | private static void dumpButton(PrintWriter pw, String caption, ButtonDispatcher button) { |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 897 | pw.print(" " + caption + ": "); |
| 898 | if (button == null) { |
| 899 | pw.print("null"); |
| 900 | } else { |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 901 | pw.print(visibilityToString(button.getVisibility()) |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 902 | + " alpha=" + button.getAlpha() |
| 903 | ); |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 904 | } |
| 905 | pw.println(); |
| 906 | } |
| 907 | |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 908 | public interface OnVerticalChangedListener { |
| 909 | void onVerticalChanged(boolean isVertical); |
| 910 | } |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 911 | |
Jason Monk | 32e3bb5 | 2017-07-27 12:35:41 -0400 | [diff] [blame] | 912 | private final Consumer<Boolean> mDockedListener = exists -> mHandler.post(() -> { |
| 913 | mDockedStackExists = exists; |
| 914 | updateRecentsIcon(); |
| 915 | }); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 916 | } |