Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file |
| 5 | * except in compliance with the License. You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software distributed under the |
| 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 11 | * KIND, either express or implied. See the License for the specific language governing |
| 12 | * permissions and limitations under the License. |
| 13 | */ |
| 14 | |
| 15 | package com.android.systemui.statusbar.phone; |
| 16 | |
| 17 | import static android.app.StatusBarManager.NAVIGATION_HINT_BACK_ALT; |
| 18 | import static android.app.StatusBarManager.NAVIGATION_HINT_IME_SHOWN; |
| 19 | import static android.app.StatusBarManager.WINDOW_STATE_SHOWING; |
| 20 | import static android.app.StatusBarManager.windowStateToString; |
| 21 | |
| 22 | import static com.android.systemui.statusbar.phone.BarTransitions.MODE_SEMI_TRANSPARENT; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 23 | import static com.android.systemui.statusbar.phone.StatusBar.DEBUG_WINDOW_STATE; |
| 24 | import static com.android.systemui.statusbar.phone.StatusBar.dumpBarTransitions; |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame^] | 25 | import static com.android.systemui.OverviewProxyService.OverviewProxyListener; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 26 | |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 27 | import android.accessibilityservice.AccessibilityServiceInfo; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 28 | import android.animation.Animator; |
| 29 | import android.animation.AnimatorListenerAdapter; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 30 | import android.animation.ObjectAnimator; |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame^] | 31 | import android.annotation.IdRes; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 32 | import android.annotation.Nullable; |
| 33 | import android.app.ActivityManager; |
| 34 | import android.app.ActivityManagerNative; |
| 35 | import android.app.Fragment; |
| 36 | import android.app.IActivityManager; |
| 37 | import android.app.StatusBarManager; |
| 38 | import android.content.BroadcastReceiver; |
Casey Burkhardt | b9dcd66 | 2017-03-20 15:10:16 -0700 | [diff] [blame] | 39 | import android.content.ContentResolver; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 40 | import android.content.Context; |
| 41 | import android.content.Intent; |
| 42 | import android.content.IntentFilter; |
| 43 | import android.content.res.Configuration; |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 44 | import android.database.ContentObserver; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 45 | import android.graphics.PixelFormat; |
| 46 | import android.graphics.Rect; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 47 | import android.graphics.drawable.AnimatedVectorDrawable; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 48 | import android.inputmethodservice.InputMethodService; |
| 49 | import android.os.Binder; |
| 50 | import android.os.Bundle; |
| 51 | import android.os.Handler; |
| 52 | import android.os.IBinder; |
| 53 | import android.os.Message; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 54 | import android.os.RemoteException; |
| 55 | import android.os.UserHandle; |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 56 | import android.provider.Settings; |
Jason Monk | 865246d | 2017-01-19 08:27:01 -0500 | [diff] [blame] | 57 | import android.support.annotation.VisibleForTesting; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 58 | import android.telecom.TelecomManager; |
| 59 | import android.text.TextUtils; |
| 60 | import android.util.Log; |
| 61 | import android.view.IRotationWatcher.Stub; |
| 62 | import android.view.KeyEvent; |
| 63 | import android.view.LayoutInflater; |
| 64 | import android.view.MotionEvent; |
Mike Digman | 85ff7fa | 2018-01-23 14:59:52 -0800 | [diff] [blame] | 65 | import android.view.Surface; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 66 | import android.view.View; |
| 67 | import android.view.ViewGroup; |
| 68 | import android.view.WindowManager; |
| 69 | import android.view.WindowManager.LayoutParams; |
| 70 | import android.view.WindowManagerGlobal; |
| 71 | import android.view.accessibility.AccessibilityEvent; |
| 72 | import android.view.accessibility.AccessibilityManager; |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 73 | import android.view.accessibility.AccessibilityManager.AccessibilityServicesStateChangeListener; |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame^] | 74 | import android.widget.Button; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 75 | |
| 76 | import com.android.internal.logging.MetricsLogger; |
| 77 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Jason Monk | ea03be1 | 2017-12-04 11:08:41 -0500 | [diff] [blame] | 78 | import com.android.internal.util.LatencyTracker; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 79 | import com.android.systemui.Dependency; |
Matthew Ng | dc79e5c | 2017-12-14 17:37:35 -0800 | [diff] [blame] | 80 | import com.android.systemui.OverviewProxyService; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 81 | import com.android.systemui.Interpolators; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 82 | import com.android.systemui.R; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 83 | import com.android.systemui.SysUiServiceProvider; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 84 | import com.android.systemui.assist.AssistManager; |
| 85 | import com.android.systemui.fragments.FragmentHostManager; |
| 86 | import com.android.systemui.fragments.FragmentHostManager.FragmentListener; |
| 87 | import com.android.systemui.recents.Recents; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 88 | import com.android.systemui.recents.misc.SysUiTaskStackChangeListener; |
| 89 | import com.android.systemui.shared.system.ActivityManagerWrapper; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 90 | import com.android.systemui.stackdivider.Divider; |
| 91 | import com.android.systemui.statusbar.CommandQueue; |
| 92 | import com.android.systemui.statusbar.CommandQueue.Callbacks; |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 93 | import com.android.systemui.statusbar.policy.AccessibilityManagerWrapper; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 94 | import com.android.systemui.statusbar.policy.KeyButtonDrawable; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 95 | import com.android.systemui.statusbar.policy.KeyButtonView; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 96 | import com.android.systemui.statusbar.policy.RotationLockController; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 97 | import com.android.systemui.statusbar.stack.StackStateAnimator; |
| 98 | |
| 99 | import java.io.FileDescriptor; |
| 100 | import java.io.PrintWriter; |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 101 | import java.util.List; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 102 | import java.util.Locale; |
| 103 | |
| 104 | /** |
| 105 | * Fragment containing the NavigationBarFragment. Contains logic for what happens |
| 106 | * on clicks and view states of the nav bar. |
| 107 | */ |
| 108 | public class NavigationBarFragment extends Fragment implements Callbacks { |
| 109 | |
Jason Monk | d4afe15 | 2017-05-01 15:37:43 -0400 | [diff] [blame] | 110 | public static final String TAG = "NavigationBar"; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 111 | private static final boolean DEBUG = false; |
| 112 | private static final String EXTRA_DISABLE_STATE = "disabled_state"; |
| 113 | |
| 114 | /** Allow some time inbetween the long press for back and recents. */ |
| 115 | private static final int LOCK_TO_APP_GESTURE_TOLERENCE = 200; |
| 116 | |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 117 | private static final int BUTTON_FADE_IN_OUT_DURATION_MS = 100; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 118 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 119 | protected NavigationBarView mNavigationBarView = null; |
| 120 | protected AssistManager mAssistManager; |
| 121 | |
| 122 | private int mNavigationBarWindowState = WINDOW_STATE_SHOWING; |
| 123 | |
| 124 | private int mNavigationIconHints = 0; |
| 125 | private int mNavigationBarMode; |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 126 | private boolean mAccessibilityFeedbackEnabled; |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 127 | private AccessibilityManager mAccessibilityManager; |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 128 | private MagnificationContentObserver mMagnificationObserver; |
Casey Burkhardt | b9dcd66 | 2017-03-20 15:10:16 -0700 | [diff] [blame] | 129 | private ContentResolver mContentResolver; |
Mike Digman | c94759d | 2018-01-23 11:01:21 -0800 | [diff] [blame] | 130 | private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 131 | |
| 132 | private int mDisabledFlags1; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 133 | private StatusBar mStatusBar; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 134 | private Recents mRecents; |
| 135 | private Divider mDivider; |
| 136 | private WindowManager mWindowManager; |
| 137 | private CommandQueue mCommandQueue; |
| 138 | private long mLastLockToAppLongPress; |
| 139 | |
| 140 | private Locale mLocale; |
| 141 | private int mLayoutDirection; |
| 142 | |
| 143 | private int mSystemUiVisibility; |
| 144 | private LightBarController mLightBarController; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 145 | |
Matthew Ng | dc79e5c | 2017-12-14 17:37:35 -0800 | [diff] [blame] | 146 | private OverviewProxyService mOverviewProxyService; |
| 147 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 148 | public boolean mHomeBlockedThisTouch; |
| 149 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 150 | private int mLastRotationSuggestion; |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 151 | private boolean mHoveringRotationSuggestion; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 152 | private RotationLockController mRotationLockController; |
| 153 | private TaskStackListenerImpl mTaskStackListener; |
| 154 | |
| 155 | private final Runnable mRemoveRotationProposal = () -> setRotateSuggestionButtonState(false); |
| 156 | private Animator mRotateShowAnimator; |
| 157 | private Animator mRotateHideAnimator; |
| 158 | |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame^] | 159 | private final OverviewProxyListener mOverviewProxyListener = new OverviewProxyListener() { |
| 160 | @Override |
| 161 | public void onConnectionChanged(boolean isConnected) { |
| 162 | mNavigationBarView.onOverviewProxyConnectionChanged(isConnected); |
| 163 | updateScreenPinningGestures(); |
| 164 | } |
| 165 | |
| 166 | @Override |
| 167 | public void onRecentsAnimationStarted() { |
| 168 | mNavigationBarView.setRecentsAnimationStarted(true); |
| 169 | } |
| 170 | }; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 171 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 172 | // ----- Fragment Lifecycle Callbacks ----- |
| 173 | |
| 174 | @Override |
| 175 | public void onCreate(@Nullable Bundle savedInstanceState) { |
| 176 | super.onCreate(savedInstanceState); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 177 | mCommandQueue = SysUiServiceProvider.getComponent(getContext(), CommandQueue.class); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 178 | mCommandQueue.addCallbacks(this); |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 179 | mStatusBar = SysUiServiceProvider.getComponent(getContext(), StatusBar.class); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 180 | mRecents = SysUiServiceProvider.getComponent(getContext(), Recents.class); |
| 181 | mDivider = SysUiServiceProvider.getComponent(getContext(), Divider.class); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 182 | mWindowManager = getContext().getSystemService(WindowManager.class); |
| 183 | mAccessibilityManager = getContext().getSystemService(AccessibilityManager.class); |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 184 | Dependency.get(AccessibilityManagerWrapper.class).addCallback( |
| 185 | mAccessibilityListener); |
Casey Burkhardt | b9dcd66 | 2017-03-20 15:10:16 -0700 | [diff] [blame] | 186 | mContentResolver = getContext().getContentResolver(); |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 187 | mMagnificationObserver = new MagnificationContentObserver( |
| 188 | getContext().getMainThreadHandler()); |
Casey Burkhardt | b9dcd66 | 2017-03-20 15:10:16 -0700 | [diff] [blame] | 189 | mContentResolver.registerContentObserver(Settings.Secure.getUriFor( |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 190 | Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED), false, |
Casey Burkhardt | 5d61440 | 2017-04-06 13:46:50 -0700 | [diff] [blame] | 191 | mMagnificationObserver, UserHandle.USER_ALL); |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 192 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 193 | if (savedInstanceState != null) { |
| 194 | mDisabledFlags1 = savedInstanceState.getInt(EXTRA_DISABLE_STATE, 0); |
| 195 | } |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 196 | mAssistManager = Dependency.get(AssistManager.class); |
Matthew Ng | dc79e5c | 2017-12-14 17:37:35 -0800 | [diff] [blame] | 197 | mOverviewProxyService = Dependency.get(OverviewProxyService.class); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 198 | |
| 199 | try { |
| 200 | WindowManagerGlobal.getWindowManagerService() |
Andrii Kulian | 35fa3c2 | 2017-03-11 09:37:28 -0800 | [diff] [blame] | 201 | .watchRotation(mRotationWatcher, getContext().getDisplay().getDisplayId()); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 202 | } catch (RemoteException e) { |
| 203 | throw e.rethrowFromSystemServer(); |
| 204 | } |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 205 | |
| 206 | mRotationLockController = Dependency.get(RotationLockController.class); |
| 207 | |
| 208 | // Register the task stack listener |
| 209 | mTaskStackListener = new TaskStackListenerImpl(); |
| 210 | ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | @Override |
| 214 | public void onDestroy() { |
| 215 | super.onDestroy(); |
| 216 | mCommandQueue.removeCallbacks(this); |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 217 | Dependency.get(AccessibilityManagerWrapper.class).removeCallback( |
| 218 | mAccessibilityListener); |
Casey Burkhardt | b9dcd66 | 2017-03-20 15:10:16 -0700 | [diff] [blame] | 219 | mContentResolver.unregisterContentObserver(mMagnificationObserver); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 220 | try { |
| 221 | WindowManagerGlobal.getWindowManagerService() |
| 222 | .removeRotationWatcher(mRotationWatcher); |
| 223 | } catch (RemoteException e) { |
| 224 | throw e.rethrowFromSystemServer(); |
| 225 | } |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 226 | |
| 227 | // Unregister the task stack listener |
| 228 | ActivityManagerWrapper.getInstance().unregisterTaskStackListener(mTaskStackListener); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | @Override |
| 232 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, |
| 233 | Bundle savedInstanceState) { |
| 234 | return inflater.inflate(R.layout.navigation_bar, container, false); |
| 235 | } |
| 236 | |
| 237 | @Override |
| 238 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { |
| 239 | super.onViewCreated(view, savedInstanceState); |
| 240 | mNavigationBarView = (NavigationBarView) view; |
| 241 | |
| 242 | mNavigationBarView.setDisabledFlags(mDisabledFlags1); |
Matthew Ng | 78f88d1 | 2018-01-23 12:39:55 -0800 | [diff] [blame] | 243 | mNavigationBarView.setComponents(mRecents, mDivider, mStatusBar.getPanel()); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 244 | mNavigationBarView.setOnVerticalChangedListener(this::onVerticalChanged); |
| 245 | mNavigationBarView.setOnTouchListener(this::onNavigationTouch); |
| 246 | if (savedInstanceState != null) { |
| 247 | mNavigationBarView.getLightTransitionsController().restoreState(savedInstanceState); |
| 248 | } |
| 249 | |
| 250 | prepareNavigationBarView(); |
| 251 | checkNavBarModes(); |
| 252 | |
| 253 | IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF); |
| 254 | filter.addAction(Intent.ACTION_SCREEN_ON); |
| 255 | getContext().registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, filter, null, null); |
Siarhei Vishniakou | d002a0a | 2017-06-05 22:44:37 +0100 | [diff] [blame] | 256 | notifyNavigationBarScreenOn(); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame^] | 257 | mOverviewProxyService.addCallback(mOverviewProxyListener); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | @Override |
| 261 | public void onDestroyView() { |
| 262 | super.onDestroyView(); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 263 | mNavigationBarView.getLightTransitionsController().destroy(getContext()); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame^] | 264 | mOverviewProxyService.removeCallback(mOverviewProxyListener); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 265 | getContext().unregisterReceiver(mBroadcastReceiver); |
| 266 | } |
| 267 | |
| 268 | @Override |
| 269 | public void onSaveInstanceState(Bundle outState) { |
| 270 | super.onSaveInstanceState(outState); |
| 271 | outState.putInt(EXTRA_DISABLE_STATE, mDisabledFlags1); |
| 272 | if (mNavigationBarView != null) { |
| 273 | mNavigationBarView.getLightTransitionsController().saveState(outState); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | @Override |
| 278 | public void onConfigurationChanged(Configuration newConfig) { |
| 279 | super.onConfigurationChanged(newConfig); |
| 280 | final Locale locale = getContext().getResources().getConfiguration().locale; |
| 281 | final int ld = TextUtils.getLayoutDirectionFromLocale(locale); |
| 282 | if (!locale.equals(mLocale) || ld != mLayoutDirection) { |
| 283 | if (DEBUG) { |
| 284 | Log.v(TAG, String.format( |
| 285 | "config changed locale/LD: %s (%d) -> %s (%d)", mLocale, mLayoutDirection, |
| 286 | locale, ld)); |
| 287 | } |
| 288 | mLocale = locale; |
| 289 | mLayoutDirection = ld; |
| 290 | refreshLayout(ld); |
| 291 | } |
| 292 | repositionNavigationBar(); |
| 293 | } |
| 294 | |
| 295 | @Override |
| 296 | public void dump(String prefix, FileDescriptor fd, PrintWriter pw, String[] args) { |
| 297 | if (mNavigationBarView != null) { |
| 298 | pw.print(" mNavigationBarWindowState="); |
| 299 | pw.println(windowStateToString(mNavigationBarWindowState)); |
| 300 | pw.print(" mNavigationBarMode="); |
| 301 | pw.println(BarTransitions.modeToString(mNavigationBarMode)); |
| 302 | dumpBarTransitions(pw, "mNavigationBarView", mNavigationBarView.getBarTransitions()); |
| 303 | } |
| 304 | |
| 305 | pw.print(" mNavigationBarView="); |
| 306 | if (mNavigationBarView == null) { |
| 307 | pw.println("null"); |
| 308 | } else { |
| 309 | mNavigationBarView.dump(fd, pw, args); |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | // ----- CommandQueue Callbacks ----- |
| 314 | |
| 315 | @Override |
| 316 | public void setImeWindowStatus(IBinder token, int vis, int backDisposition, |
| 317 | boolean showImeSwitcher) { |
| 318 | boolean imeShown = (vis & InputMethodService.IME_VISIBLE) != 0; |
| 319 | int hints = mNavigationIconHints; |
Tarandeep Singh | 3fecef1 | 2018-01-22 14:33:33 -0800 | [diff] [blame] | 320 | if (imeShown && backDisposition != InputMethodService.BACK_DISPOSITION_WILL_NOT_DISMISS) { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 321 | hints |= NAVIGATION_HINT_BACK_ALT; |
| 322 | } else { |
| 323 | hints &= ~NAVIGATION_HINT_BACK_ALT; |
| 324 | } |
| 325 | if (showImeSwitcher) { |
| 326 | hints |= NAVIGATION_HINT_IME_SHOWN; |
| 327 | } else { |
| 328 | hints &= ~NAVIGATION_HINT_IME_SHOWN; |
| 329 | } |
| 330 | if (hints == mNavigationIconHints) return; |
| 331 | |
| 332 | mNavigationIconHints = hints; |
| 333 | |
| 334 | if (mNavigationBarView != null) { |
| 335 | mNavigationBarView.setNavigationIconHints(hints); |
| 336 | } |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 337 | mStatusBar.checkBarModes(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | @Override |
| 341 | public void topAppWindowChanged(boolean showMenu) { |
| 342 | if (mNavigationBarView != null) { |
| 343 | mNavigationBarView.setMenuVisibility(showMenu); |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | @Override |
| 348 | public void setWindowState(int window, int state) { |
| 349 | if (mNavigationBarView != null |
| 350 | && window == StatusBarManager.WINDOW_NAVIGATION_BAR |
| 351 | && mNavigationBarWindowState != state) { |
| 352 | mNavigationBarWindowState = state; |
| 353 | if (DEBUG_WINDOW_STATE) Log.d(TAG, "Navigation bar " + windowStateToString(state)); |
| 354 | } |
| 355 | } |
| 356 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 357 | @Override |
Mike Digman | e077731 | 2018-01-19 12:41:51 -0800 | [diff] [blame] | 358 | public void onRotationProposal(final int rotation, boolean isValid) { |
| 359 | // This method will be called on rotation suggestion changes even if the proposed rotation |
| 360 | // is not valid for the top app. Use invalid rotation choices as a signal to remove the |
| 361 | // rotate button if shown. |
| 362 | |
| 363 | if (!isValid) { |
| 364 | setRotateSuggestionButtonState(false); |
| 365 | return; |
| 366 | } |
| 367 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 368 | if (rotation == mWindowManager.getDefaultDisplay().getRotation()) { |
| 369 | // Use this as a signal to remove any current suggestions |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 370 | getView().getHandler().removeCallbacks(mRemoveRotationProposal); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 371 | setRotateSuggestionButtonState(false); |
| 372 | } else { |
| 373 | mLastRotationSuggestion = rotation; // Remember rotation for click |
| 374 | setRotateSuggestionButtonState(true); |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 375 | rescheduleRotationTimeout(false); |
Mike Digman | c94759d | 2018-01-23 11:01:21 -0800 | [diff] [blame] | 376 | mMetricsLogger.visible(MetricsEvent.ROTATION_SUGGESTION_SHOWN); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 377 | } |
| 378 | } |
| 379 | |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 380 | private void rescheduleRotationTimeout(final boolean reasonHover) { |
| 381 | // May be called due to a new rotation proposal or a change in hover state |
| 382 | if (reasonHover) { |
| 383 | // Don't reschedule if a hide animator is running |
| 384 | if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) { |
| 385 | return; |
| 386 | } |
| 387 | // Don't reschedule if not visible |
| 388 | if (mNavigationBarView.getRotateSuggestionButton().getVisibility() != View.VISIBLE) { |
| 389 | return; |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | Handler h = getView().getHandler(); |
| 394 | h.removeCallbacks(mRemoveRotationProposal); // Stop any pending removal |
| 395 | h.postDelayed(mRemoveRotationProposal, |
| 396 | computeRotationProposalTimeout()); // Schedule timeout |
| 397 | } |
| 398 | |
| 399 | private int computeRotationProposalTimeout() { |
| 400 | if (mAccessibilityFeedbackEnabled) return 20000; |
| 401 | if (mHoveringRotationSuggestion) return 16000; |
| 402 | return 6000; |
| 403 | } |
| 404 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 405 | public void setRotateSuggestionButtonState(final boolean visible) { |
| 406 | setRotateSuggestionButtonState(visible, false); |
| 407 | } |
| 408 | |
| 409 | public void setRotateSuggestionButtonState(final boolean visible, final boolean skipAnim) { |
| 410 | ButtonDispatcher rotBtn = mNavigationBarView.getRotateSuggestionButton(); |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 411 | final boolean currentlyVisible = rotBtn.getVisibility() == View.VISIBLE; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 412 | |
| 413 | // Rerun a show animation to indicate change but don't rerun a hide animation |
| 414 | if (!visible && !currentlyVisible) return; |
| 415 | |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 416 | View currentView = rotBtn.getCurrentView(); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 417 | if (currentView == null) return; |
| 418 | |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 419 | KeyButtonDrawable kbd = rotBtn.getImageDrawable(); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 420 | if (kbd == null) return; |
| 421 | |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 422 | AnimatedVectorDrawable animIcon = null; |
| 423 | if (kbd.getDrawable(0) instanceof AnimatedVectorDrawable) { |
| 424 | animIcon = (AnimatedVectorDrawable) kbd.getDrawable(0); |
| 425 | } |
| 426 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 427 | if (visible) { // Appear and change |
| 428 | rotBtn.setVisibility(View.VISIBLE); |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 429 | mNavigationBarView.notifySubtreeAccessibilityStateChangedIfNeeded(); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 430 | |
| 431 | if (skipAnim) { |
| 432 | currentView.setAlpha(1f); |
| 433 | return; |
| 434 | } |
| 435 | |
| 436 | // Start a new animation if running |
| 437 | if (mRotateShowAnimator != null) mRotateShowAnimator.pause(); |
| 438 | if (mRotateHideAnimator != null) mRotateHideAnimator.pause(); |
| 439 | |
| 440 | ObjectAnimator appearFade = ObjectAnimator.ofFloat(currentView, "alpha", |
| 441 | 0f, 1f); |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 442 | appearFade.setDuration(BUTTON_FADE_IN_OUT_DURATION_MS); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 443 | appearFade.setInterpolator(Interpolators.LINEAR); |
| 444 | mRotateShowAnimator = appearFade; |
| 445 | appearFade.start(); |
| 446 | |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 447 | // Run the rotate icon's animation if it has one |
| 448 | if (animIcon != null) { |
| 449 | animIcon.reset(); |
| 450 | animIcon.start(); |
| 451 | } |
| 452 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 453 | } else { // Hide |
| 454 | |
| 455 | if (skipAnim) { |
| 456 | rotBtn.setVisibility(View.INVISIBLE); |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 457 | mNavigationBarView.notifySubtreeAccessibilityStateChangedIfNeeded(); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 458 | return; |
| 459 | } |
| 460 | |
| 461 | // Don't start any new hide animations if one is running |
| 462 | if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) return; |
| 463 | // Pause any active show animations but don't reset the AVD to avoid jumps |
| 464 | if (mRotateShowAnimator != null) mRotateShowAnimator.pause(); |
| 465 | |
| 466 | ObjectAnimator fadeOut = ObjectAnimator.ofFloat(currentView, "alpha", |
| 467 | 0f); |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 468 | fadeOut.setDuration(BUTTON_FADE_IN_OUT_DURATION_MS); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 469 | fadeOut.setInterpolator(Interpolators.LINEAR); |
| 470 | fadeOut.addListener(new AnimatorListenerAdapter() { |
| 471 | @Override |
| 472 | public void onAnimationEnd(Animator animation) { |
| 473 | rotBtn.setVisibility(View.INVISIBLE); |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 474 | mNavigationBarView.notifySubtreeAccessibilityStateChangedIfNeeded(); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 475 | } |
| 476 | }); |
| 477 | |
| 478 | mRotateHideAnimator = fadeOut; |
| 479 | fadeOut.start(); |
| 480 | } |
| 481 | } |
| 482 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 483 | // Injected from StatusBar at creation. |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 484 | public void setCurrentSysuiVisibility(int systemUiVisibility) { |
| 485 | mSystemUiVisibility = systemUiVisibility; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 486 | mNavigationBarMode = mStatusBar.computeBarMode(0, mSystemUiVisibility, |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 487 | View.NAVIGATION_BAR_TRANSIENT, View.NAVIGATION_BAR_TRANSLUCENT, |
| 488 | View.NAVIGATION_BAR_TRANSPARENT); |
| 489 | checkNavBarModes(); |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 490 | mStatusBar.touchAutoHide(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 491 | mLightBarController.onNavigationVisibilityChanged(mSystemUiVisibility, 0 /* mask */, |
| 492 | true /* nbModeChanged */, mNavigationBarMode); |
| 493 | } |
| 494 | |
| 495 | @Override |
| 496 | public void setSystemUiVisibility(int vis, int fullscreenStackVis, int dockedStackVis, |
| 497 | int mask, Rect fullscreenStackBounds, Rect dockedStackBounds) { |
| 498 | final int oldVal = mSystemUiVisibility; |
| 499 | final int newVal = (oldVal & ~mask) | (vis & mask); |
| 500 | final int diff = newVal ^ oldVal; |
| 501 | boolean nbModeChanged = false; |
| 502 | if (diff != 0) { |
| 503 | mSystemUiVisibility = newVal; |
| 504 | |
| 505 | // update navigation bar mode |
| 506 | final int nbMode = getView() == null |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 507 | ? -1 : mStatusBar.computeBarMode(oldVal, newVal, |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 508 | View.NAVIGATION_BAR_TRANSIENT, View.NAVIGATION_BAR_TRANSLUCENT, |
| 509 | View.NAVIGATION_BAR_TRANSPARENT); |
| 510 | nbModeChanged = nbMode != -1; |
| 511 | if (nbModeChanged) { |
| 512 | if (mNavigationBarMode != nbMode) { |
| 513 | mNavigationBarMode = nbMode; |
| 514 | checkNavBarModes(); |
| 515 | } |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 516 | mStatusBar.touchAutoHide(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 517 | } |
| 518 | } |
| 519 | |
| 520 | mLightBarController.onNavigationVisibilityChanged(vis, mask, nbModeChanged, |
| 521 | mNavigationBarMode); |
| 522 | } |
| 523 | |
| 524 | @Override |
| 525 | public void disable(int state1, int state2, boolean animate) { |
| 526 | // All navigation bar flags are in state1. |
| 527 | int masked = state1 & (StatusBarManager.DISABLE_HOME |
| 528 | | StatusBarManager.DISABLE_RECENT |
| 529 | | StatusBarManager.DISABLE_BACK |
| 530 | | StatusBarManager.DISABLE_SEARCH); |
| 531 | if (masked != mDisabledFlags1) { |
| 532 | mDisabledFlags1 = masked; |
| 533 | if (mNavigationBarView != null) mNavigationBarView.setDisabledFlags(state1); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame^] | 534 | updateScreenPinningGestures(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 535 | } |
| 536 | } |
| 537 | |
| 538 | // ----- Internal stuffz ----- |
| 539 | |
| 540 | private void refreshLayout(int layoutDirection) { |
| 541 | if (mNavigationBarView != null) { |
| 542 | mNavigationBarView.setLayoutDirection(layoutDirection); |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | private boolean shouldDisableNavbarGestures() { |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 547 | return !mStatusBar.isDeviceProvisioned() |
Matthew Ng | dc79e5c | 2017-12-14 17:37:35 -0800 | [diff] [blame] | 548 | || (mDisabledFlags1 & StatusBarManager.DISABLE_SEARCH) != 0 |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame^] | 549 | || mNavigationBarView.getRecentsButton().getVisibility() != View.VISIBLE; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | private void repositionNavigationBar() { |
| 553 | if (mNavigationBarView == null || !mNavigationBarView.isAttachedToWindow()) return; |
| 554 | |
| 555 | prepareNavigationBarView(); |
| 556 | |
| 557 | mWindowManager.updateViewLayout((View) mNavigationBarView.getParent(), |
| 558 | ((View) mNavigationBarView.getParent()).getLayoutParams()); |
| 559 | } |
| 560 | |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame^] | 561 | private void updateScreenPinningGestures() { |
| 562 | if (mNavigationBarView == null) { |
| 563 | return; |
| 564 | } |
| 565 | |
| 566 | // Change the cancel pin gesture to home and back if recents button is invisible |
| 567 | boolean recentsVisible = mNavigationBarView.isRecentsButtonVisible(); |
| 568 | ButtonDispatcher homeButton = mNavigationBarView.getHomeButton(); |
| 569 | ButtonDispatcher backButton = mNavigationBarView.getBackButton(); |
| 570 | if (recentsVisible) { |
| 571 | homeButton.setOnLongClickListener(this::onHomeLongClick); |
| 572 | backButton.setOnLongClickListener(this::onLongPressBackRecents); |
| 573 | } else { |
| 574 | homeButton.setOnLongClickListener(this::onLongPressBackHome); |
| 575 | backButton.setOnLongClickListener(this::onLongPressBackHome); |
| 576 | } |
| 577 | } |
| 578 | |
Siarhei Vishniakou | d002a0a | 2017-06-05 22:44:37 +0100 | [diff] [blame] | 579 | private void notifyNavigationBarScreenOn() { |
| 580 | mNavigationBarView.notifyScreenOn(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | private void prepareNavigationBarView() { |
| 584 | mNavigationBarView.reorient(); |
| 585 | |
| 586 | ButtonDispatcher recentsButton = mNavigationBarView.getRecentsButton(); |
| 587 | recentsButton.setOnClickListener(this::onRecentsClick); |
| 588 | recentsButton.setOnTouchListener(this::onRecentsTouch); |
| 589 | recentsButton.setLongClickable(true); |
| 590 | recentsButton.setOnLongClickListener(this::onLongPressBackRecents); |
| 591 | |
| 592 | ButtonDispatcher backButton = mNavigationBarView.getBackButton(); |
| 593 | backButton.setLongClickable(true); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 594 | |
| 595 | ButtonDispatcher homeButton = mNavigationBarView.getHomeButton(); |
| 596 | homeButton.setOnTouchListener(this::onHomeTouch); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 597 | |
| 598 | ButtonDispatcher accessibilityButton = mNavigationBarView.getAccessibilityButton(); |
| 599 | accessibilityButton.setOnClickListener(this::onAccessibilityClick); |
| 600 | accessibilityButton.setOnLongClickListener(this::onAccessibilityLongClick); |
Phil Weaver | db9a774 | 2017-04-18 08:15:06 -0700 | [diff] [blame] | 601 | updateAccessibilityServicesState(mAccessibilityManager); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 602 | |
| 603 | ButtonDispatcher rotateSuggestionButton = mNavigationBarView.getRotateSuggestionButton(); |
| 604 | rotateSuggestionButton.setOnClickListener(this::onRotateSuggestionClick); |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 605 | rotateSuggestionButton.setOnHoverListener(this::onRotateSuggestionHover); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame^] | 606 | updateScreenPinningGestures(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | private boolean onHomeTouch(View v, MotionEvent event) { |
| 610 | if (mHomeBlockedThisTouch && event.getActionMasked() != MotionEvent.ACTION_DOWN) { |
| 611 | return true; |
| 612 | } |
| 613 | // If an incoming call is ringing, HOME is totally disabled. |
| 614 | // (The user is already on the InCallUI at this point, |
| 615 | // and his ONLY options are to answer or reject the call.) |
| 616 | switch (event.getAction()) { |
| 617 | case MotionEvent.ACTION_DOWN: |
| 618 | mHomeBlockedThisTouch = false; |
| 619 | TelecomManager telecomManager = |
| 620 | getContext().getSystemService(TelecomManager.class); |
| 621 | if (telecomManager != null && telecomManager.isRinging()) { |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 622 | if (mStatusBar.isKeyguardShowing()) { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 623 | Log.i(TAG, "Ignoring HOME; there's a ringing incoming call. " + |
| 624 | "No heads up"); |
| 625 | mHomeBlockedThisTouch = true; |
| 626 | return true; |
| 627 | } |
| 628 | } |
| 629 | break; |
| 630 | case MotionEvent.ACTION_UP: |
| 631 | case MotionEvent.ACTION_CANCEL: |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 632 | mStatusBar.awakenDreams(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 633 | break; |
| 634 | } |
| 635 | return false; |
| 636 | } |
| 637 | |
| 638 | private void onVerticalChanged(boolean isVertical) { |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 639 | mStatusBar.setQsScrimEnabled(!isVertical); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | private boolean onNavigationTouch(View v, MotionEvent event) { |
Eliot Courtney | cb5d316 | 2017-08-09 16:53:15 +0900 | [diff] [blame] | 643 | mStatusBar.checkUserAutohide(event); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 644 | return false; |
| 645 | } |
| 646 | |
Jason Monk | 865246d | 2017-01-19 08:27:01 -0500 | [diff] [blame] | 647 | @VisibleForTesting |
| 648 | boolean onHomeLongClick(View v) { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 649 | if (shouldDisableNavbarGestures()) { |
| 650 | return false; |
| 651 | } |
Mike Digman | c94759d | 2018-01-23 11:01:21 -0800 | [diff] [blame] | 652 | mMetricsLogger.action(MetricsEvent.ACTION_ASSIST_LONG_PRESS); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 653 | mAssistManager.startAssist(new Bundle() /* args */); |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 654 | mStatusBar.awakenDreams(); |
Matthew Ng | dc79e5c | 2017-12-14 17:37:35 -0800 | [diff] [blame] | 655 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 656 | if (mNavigationBarView != null) { |
| 657 | mNavigationBarView.abortCurrentGesture(); |
| 658 | } |
| 659 | return true; |
| 660 | } |
| 661 | |
| 662 | // additional optimization when we have software system buttons - start loading the recent |
| 663 | // tasks on touch down |
| 664 | private boolean onRecentsTouch(View v, MotionEvent event) { |
| 665 | int action = event.getAction() & MotionEvent.ACTION_MASK; |
| 666 | if (action == MotionEvent.ACTION_DOWN) { |
| 667 | mCommandQueue.preloadRecentApps(); |
| 668 | } else if (action == MotionEvent.ACTION_CANCEL) { |
| 669 | mCommandQueue.cancelPreloadRecentApps(); |
| 670 | } else if (action == MotionEvent.ACTION_UP) { |
| 671 | if (!v.isPressed()) { |
| 672 | mCommandQueue.cancelPreloadRecentApps(); |
| 673 | } |
| 674 | } |
| 675 | return false; |
| 676 | } |
| 677 | |
| 678 | private void onRecentsClick(View v) { |
| 679 | if (LatencyTracker.isEnabled(getContext())) { |
| 680 | LatencyTracker.getInstance(getContext()).onActionStart( |
| 681 | LatencyTracker.ACTION_TOGGLE_RECENTS); |
| 682 | } |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 683 | mStatusBar.awakenDreams(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 684 | mCommandQueue.toggleRecentApps(); |
| 685 | } |
| 686 | |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame^] | 687 | private boolean onLongPressBackHome(View v) { |
| 688 | return onLongPressNavigationButtons(v, R.id.back, R.id.home); |
| 689 | } |
| 690 | |
| 691 | private boolean onLongPressBackRecents(View v) { |
| 692 | return onLongPressNavigationButtons(v, R.id.back, R.id.recent_apps); |
| 693 | } |
| 694 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 695 | /** |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame^] | 696 | * This handles long-press of both back and recents/home. Back is the common button with |
| 697 | * combination of recents if it is visible or home if recents is invisible. |
| 698 | * They are handled together to capture them both being long-pressed |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 699 | * at the same time to exit screen pinning (lock task). |
| 700 | * |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame^] | 701 | * When accessibility mode is on, only a long-press from recents/home |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 702 | * is required to exit. |
| 703 | * |
| 704 | * In all other circumstances we try to pass through long-press events |
| 705 | * for Back, so that apps can still use it. Which can be from two things. |
| 706 | * 1) Not currently in screen pinning (lock task). |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame^] | 707 | * 2) Back is long-pressed without recents/home. |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 708 | */ |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame^] | 709 | private boolean onLongPressNavigationButtons(View v, @IdRes int btnId1, @IdRes int btnId2) { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 710 | try { |
| 711 | boolean sendBackLongPress = false; |
| 712 | IActivityManager activityManager = ActivityManagerNative.getDefault(); |
| 713 | boolean touchExplorationEnabled = mAccessibilityManager.isTouchExplorationEnabled(); |
| 714 | boolean inLockTaskMode = activityManager.isInLockTaskMode(); |
| 715 | if (inLockTaskMode && !touchExplorationEnabled) { |
| 716 | long time = System.currentTimeMillis(); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame^] | 717 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 718 | // If we recently long-pressed the other button then they were |
| 719 | // long-pressed 'together' |
| 720 | if ((time - mLastLockToAppLongPress) < LOCK_TO_APP_GESTURE_TOLERENCE) { |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 721 | activityManager.stopSystemLockTaskMode(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 722 | // When exiting refresh disabled flags. |
| 723 | mNavigationBarView.setDisabledFlags(mDisabledFlags1, true); |
| 724 | return true; |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame^] | 725 | } else if (v.getId() == btnId1) { |
| 726 | ButtonDispatcher button = btnId2 == R.id.recent_apps |
| 727 | ? mNavigationBarView.getRecentsButton() |
| 728 | : mNavigationBarView.getHomeButton(); |
| 729 | if (!button.getCurrentView().isPressed()) { |
| 730 | // If we aren't pressing recents/home right now then they presses |
| 731 | // won't be together, so send the standard long-press action. |
| 732 | sendBackLongPress = true; |
| 733 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 734 | } |
| 735 | mLastLockToAppLongPress = time; |
| 736 | } else { |
| 737 | // If this is back still need to handle sending the long-press event. |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame^] | 738 | if (v.getId() == btnId1) { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 739 | sendBackLongPress = true; |
| 740 | } else if (touchExplorationEnabled && inLockTaskMode) { |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame^] | 741 | // When in accessibility mode a long press that is recents/home (not back) |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 742 | // should stop lock task. |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 743 | activityManager.stopSystemLockTaskMode(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 744 | // When exiting refresh disabled flags. |
| 745 | mNavigationBarView.setDisabledFlags(mDisabledFlags1, true); |
| 746 | return true; |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame^] | 747 | } else if (v.getId() == btnId2) { |
| 748 | return btnId2 == R.id.recent_apps |
| 749 | ? onLongPressRecents() |
| 750 | : onHomeLongClick(mNavigationBarView.getHomeButton().getCurrentView()); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 751 | } |
| 752 | } |
| 753 | if (sendBackLongPress) { |
| 754 | KeyButtonView keyButtonView = (KeyButtonView) v; |
| 755 | keyButtonView.sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.FLAG_LONG_PRESS); |
| 756 | keyButtonView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED); |
| 757 | return true; |
| 758 | } |
| 759 | } catch (RemoteException e) { |
| 760 | Log.d(TAG, "Unable to reach activity manager", e); |
| 761 | } |
| 762 | return false; |
| 763 | } |
| 764 | |
| 765 | private boolean onLongPressRecents() { |
Erik Wolsheimer | 9be3a06 | 2017-05-31 14:59:57 -0700 | [diff] [blame] | 766 | if (mRecents == null || !ActivityManager.supportsMultiWindow(getContext()) |
Matthew Ng | 43db6d2 | 2017-06-27 15:29:39 -0700 | [diff] [blame] | 767 | || !mDivider.getView().getSnapAlgorithm().isSplitScreenFeasible() |
| 768 | || Recents.getConfiguration().isLowRamDevice) { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 769 | return false; |
| 770 | } |
| 771 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 772 | return mStatusBar.toggleSplitScreenMode(MetricsEvent.ACTION_WINDOW_DOCK_LONGPRESS, |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 773 | MetricsEvent.ACTION_WINDOW_UNDOCK_LONGPRESS); |
| 774 | } |
| 775 | |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 776 | private void onAccessibilityClick(View v) { |
| 777 | mAccessibilityManager.notifyAccessibilityButtonClicked(); |
| 778 | } |
| 779 | |
| 780 | private boolean onAccessibilityLongClick(View v) { |
Casey Burkhardt | 5e8b980 | 2017-03-24 10:07:20 -0700 | [diff] [blame] | 781 | Intent intent = new Intent(AccessibilityManager.ACTION_CHOOSE_ACCESSIBILITY_BUTTON); |
| 782 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); |
Casey Burkhardt | 5d61440 | 2017-04-06 13:46:50 -0700 | [diff] [blame] | 783 | v.getContext().startActivityAsUser(intent, UserHandle.CURRENT); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 784 | return true; |
| 785 | } |
| 786 | |
Phil Weaver | db9a774 | 2017-04-18 08:15:06 -0700 | [diff] [blame] | 787 | private void updateAccessibilityServicesState(AccessibilityManager accessibilityManager) { |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 788 | int requestingServices = 0; |
| 789 | try { |
Casey Burkhardt | 5d61440 | 2017-04-06 13:46:50 -0700 | [diff] [blame] | 790 | if (Settings.Secure.getIntForUser(mContentResolver, |
| 791 | Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, |
| 792 | UserHandle.USER_CURRENT) == 1) { |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 793 | requestingServices++; |
| 794 | } |
| 795 | } catch (Settings.SettingNotFoundException e) { |
| 796 | } |
| 797 | |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 798 | boolean feedbackEnabled = false; |
Casey Burkhardt | 5d61440 | 2017-04-06 13:46:50 -0700 | [diff] [blame] | 799 | // AccessibilityManagerService resolves services for the current user since the local |
| 800 | // AccessibilityManager is created from a Context with the INTERACT_ACROSS_USERS permission |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 801 | final List<AccessibilityServiceInfo> services = |
Phil Weaver | db9a774 | 2017-04-18 08:15:06 -0700 | [diff] [blame] | 802 | accessibilityManager.getEnabledAccessibilityServiceList( |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 803 | AccessibilityServiceInfo.FEEDBACK_ALL_MASK); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 804 | for (int i = services.size() - 1; i >= 0; --i) { |
| 805 | AccessibilityServiceInfo info = services.get(i); |
| 806 | if ((info.flags & AccessibilityServiceInfo.FLAG_REQUEST_ACCESSIBILITY_BUTTON) != 0) { |
| 807 | requestingServices++; |
| 808 | } |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 809 | |
| 810 | if (info.feedbackType != 0 && info.feedbackType != |
| 811 | AccessibilityServiceInfo.FEEDBACK_GENERIC) { |
| 812 | feedbackEnabled = true; |
| 813 | } |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 814 | } |
| 815 | |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 816 | mAccessibilityFeedbackEnabled = feedbackEnabled; |
| 817 | |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 818 | final boolean showAccessibilityButton = requestingServices >= 1; |
| 819 | final boolean targetSelection = requestingServices >= 2; |
| 820 | mNavigationBarView.setAccessibilityButtonState(showAccessibilityButton, targetSelection); |
| 821 | } |
| 822 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 823 | private void onRotateSuggestionClick(View v) { |
Mike Digman | c94759d | 2018-01-23 11:01:21 -0800 | [diff] [blame] | 824 | mMetricsLogger.action(MetricsEvent.ACTION_ROTATION_SUGGESTION_ACCEPTED); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 825 | mRotationLockController.setRotationLockedAtAngle(true, mLastRotationSuggestion); |
| 826 | } |
| 827 | |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 828 | private boolean onRotateSuggestionHover(View v, MotionEvent event) { |
| 829 | final int action = event.getActionMasked(); |
| 830 | mHoveringRotationSuggestion = (action == MotionEvent.ACTION_HOVER_ENTER) |
| 831 | || (action == MotionEvent.ACTION_HOVER_MOVE); |
| 832 | rescheduleRotationTimeout(true); |
| 833 | return false; // Must return false so a11y hover events are dispatched correctly. |
| 834 | } |
| 835 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 836 | // ----- Methods that StatusBar talks to (should be minimized) ----- |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 837 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 838 | public void setLightBarController(LightBarController lightBarController) { |
| 839 | mLightBarController = lightBarController; |
| 840 | mLightBarController.setNavigationBar(mNavigationBarView.getLightTransitionsController()); |
| 841 | } |
| 842 | |
| 843 | public boolean isSemiTransparent() { |
| 844 | return mNavigationBarMode == MODE_SEMI_TRANSPARENT; |
| 845 | } |
| 846 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 847 | public void disableAnimationsDuringHide(long delay) { |
| 848 | mNavigationBarView.setLayoutTransitionsEnabled(false); |
| 849 | mNavigationBarView.postDelayed(() -> mNavigationBarView.setLayoutTransitionsEnabled(true), |
| 850 | delay + StackStateAnimator.ANIMATION_DURATION_GO_TO_FULL_SHADE); |
| 851 | } |
| 852 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 853 | public BarTransitions getBarTransitions() { |
| 854 | return mNavigationBarView.getBarTransitions(); |
| 855 | } |
| 856 | |
| 857 | public void checkNavBarModes() { |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 858 | mStatusBar.checkBarMode(mNavigationBarMode, |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 859 | mNavigationBarWindowState, mNavigationBarView.getBarTransitions()); |
| 860 | } |
| 861 | |
| 862 | public void finishBarAnimations() { |
| 863 | mNavigationBarView.getBarTransitions().finishAnimations(); |
| 864 | } |
| 865 | |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 866 | private final AccessibilityServicesStateChangeListener mAccessibilityListener = |
| 867 | this::updateAccessibilityServicesState; |
| 868 | |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 869 | private class MagnificationContentObserver extends ContentObserver { |
| 870 | |
| 871 | public MagnificationContentObserver(Handler handler) { |
| 872 | super(handler); |
| 873 | } |
| 874 | |
| 875 | @Override |
| 876 | public void onChange(boolean selfChange) { |
Phil Weaver | db9a774 | 2017-04-18 08:15:06 -0700 | [diff] [blame] | 877 | NavigationBarFragment.this.updateAccessibilityServicesState(mAccessibilityManager); |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 878 | } |
| 879 | } |
| 880 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 881 | private final Stub mRotationWatcher = new Stub() { |
| 882 | @Override |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 883 | public void onRotationChanged(final int rotation) throws RemoteException { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 884 | // We need this to be scheduled as early as possible to beat the redrawing of |
| 885 | // window in response to the orientation change. |
| 886 | Handler h = getView().getHandler(); |
| 887 | Message msg = Message.obtain(h, () -> { |
Mike Digman | 85ff7fa | 2018-01-23 14:59:52 -0800 | [diff] [blame] | 888 | |
| 889 | // If the screen rotation changes while locked, potentially update lock to flow with |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 890 | // new screen rotation and hide any showing suggestions. |
| 891 | if (mRotationLockController.isRotationLocked()) { |
Mike Digman | 85ff7fa | 2018-01-23 14:59:52 -0800 | [diff] [blame] | 892 | if (shouldOverrideUserLockPrefs(rotation)) { |
| 893 | mRotationLockController.setRotationLockedAtAngle(true, rotation); |
| 894 | } |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 895 | setRotateSuggestionButtonState(false, true); |
| 896 | } |
| 897 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 898 | if (mNavigationBarView != null |
| 899 | && mNavigationBarView.needsReorient(rotation)) { |
| 900 | repositionNavigationBar(); |
| 901 | } |
| 902 | }); |
| 903 | msg.setAsynchronous(true); |
| 904 | h.sendMessageAtFrontOfQueue(msg); |
| 905 | } |
Mike Digman | 85ff7fa | 2018-01-23 14:59:52 -0800 | [diff] [blame] | 906 | |
| 907 | private boolean shouldOverrideUserLockPrefs(final int rotation) { |
| 908 | // Only override user prefs when returning to portrait. |
| 909 | // Don't let apps that force landscape or 180 alter user lock. |
| 910 | return rotation == Surface.ROTATION_0; |
| 911 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 912 | }; |
| 913 | |
| 914 | private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 915 | @Override |
| 916 | public void onReceive(Context context, Intent intent) { |
| 917 | String action = intent.getAction(); |
Siarhei Vishniakou | d002a0a | 2017-06-05 22:44:37 +0100 | [diff] [blame] | 918 | if (Intent.ACTION_SCREEN_OFF.equals(action) |
| 919 | || Intent.ACTION_SCREEN_ON.equals(action)) { |
| 920 | notifyNavigationBarScreenOn(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 921 | } |
| 922 | } |
| 923 | }; |
| 924 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 925 | class TaskStackListenerImpl extends SysUiTaskStackChangeListener { |
| 926 | // Invalidate any rotation suggestion on task change or activity orientation change |
| 927 | // Note: all callbacks happen on main thread |
| 928 | |
| 929 | @Override |
| 930 | public void onTaskStackChanged() { |
| 931 | setRotateSuggestionButtonState(false); |
| 932 | } |
| 933 | |
| 934 | @Override |
| 935 | public void onTaskRemoved(int taskId) { |
| 936 | setRotateSuggestionButtonState(false); |
| 937 | } |
| 938 | |
| 939 | @Override |
| 940 | public void onTaskMovedToFront(int taskId) { |
| 941 | setRotateSuggestionButtonState(false); |
| 942 | } |
| 943 | |
| 944 | @Override |
| 945 | public void onActivityRequestedOrientationChanged(int taskId, int requestedOrientation) { |
| 946 | setRotateSuggestionButtonState(false); |
| 947 | } |
| 948 | } |
| 949 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 950 | public static View create(Context context, FragmentListener listener) { |
| 951 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 952 | LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, |
| 953 | WindowManager.LayoutParams.TYPE_NAVIGATION_BAR, |
| 954 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING |
| 955 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 956 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
| 957 | | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
| 958 | | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH |
| 959 | | WindowManager.LayoutParams.FLAG_SLIPPERY, |
| 960 | PixelFormat.TRANSLUCENT); |
| 961 | lp.token = new Binder(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 962 | lp.setTitle("NavigationBar"); |
| 963 | lp.windowAnimations = 0; |
| 964 | |
| 965 | View navigationBarView = LayoutInflater.from(context).inflate( |
| 966 | R.layout.navigation_bar_window, null); |
| 967 | |
| 968 | if (DEBUG) Log.v(TAG, "addNavigationBar: about to add " + navigationBarView); |
| 969 | if (navigationBarView == null) return null; |
| 970 | |
| 971 | context.getSystemService(WindowManager.class).addView(navigationBarView, lp); |
| 972 | FragmentHostManager fragmentHost = FragmentHostManager.get(navigationBarView); |
| 973 | NavigationBarFragment fragment = new NavigationBarFragment(); |
| 974 | fragmentHost.getFragmentManager().beginTransaction() |
| 975 | .replace(R.id.navigation_bar_frame, fragment, TAG) |
| 976 | .commit(); |
| 977 | fragmentHost.addTagListener(TAG, listener); |
| 978 | return navigationBarView; |
| 979 | } |
| 980 | } |