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