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