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