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