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