blob: 40c8fde3f845e9c768cbbe3c3d4f23e8d74501df [file] [log] [blame]
Jason Monk49fa0162017-01-11 09:21:56 -05001/*
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
15package com.android.systemui.statusbar.phone;
16
17import static android.app.StatusBarManager.NAVIGATION_HINT_BACK_ALT;
18import static android.app.StatusBarManager.NAVIGATION_HINT_IME_SHOWN;
19import static android.app.StatusBarManager.WINDOW_STATE_SHOWING;
20import static android.app.StatusBarManager.windowStateToString;
21
Mike Digmanab650252018-03-06 11:01:41 -080022import static com.android.internal.view.RotationPolicy.NATURAL_ROTATION;
23
Matthew Ng8f25fb962018-01-16 17:17:24 -080024import static com.android.systemui.shared.system.NavigationBarCompat.InteractionType;
Tracy Zhou1ac592c2018-07-25 13:47:37 -070025import static com.android.systemui.statusbar.phone.BarTransitions.MODE_LIGHTS_OUT_TRANSPARENT;
Jason Monk49fa0162017-01-11 09:21:56 -050026import static com.android.systemui.statusbar.phone.BarTransitions.MODE_SEMI_TRANSPARENT;
Tracy Zhou1ac592c2018-07-25 13:47:37 -070027import static com.android.systemui.statusbar.phone.BarTransitions.MODE_TRANSPARENT;
Jason Monk2a6ea9c2017-01-26 11:14:51 -050028import static com.android.systemui.statusbar.phone.StatusBar.DEBUG_WINDOW_STATE;
29import static com.android.systemui.statusbar.phone.StatusBar.dumpBarTransitions;
Matthew Ng9c3bce52018-02-01 22:00:31 +000030import static com.android.systemui.OverviewProxyService.OverviewProxyListener;
Jason Monk49fa0162017-01-11 09:21:56 -050031
Casey Burkhardt048c2bc2016-12-08 16:09:20 -080032import android.accessibilityservice.AccessibilityServiceInfo;
Mike Digman7d092772018-01-11 12:10:32 -080033import android.animation.Animator;
34import android.animation.AnimatorListenerAdapter;
Mike Digman7d092772018-01-11 12:10:32 -080035import android.animation.ObjectAnimator;
Matthew Ng9c3bce52018-02-01 22:00:31 +000036import android.annotation.IdRes;
Jason Monk49fa0162017-01-11 09:21:56 -050037import android.annotation.Nullable;
Wale Ogunwale65ebd952018-04-25 15:41:44 -070038import android.app.ActivityTaskManager;
Jason Monk49fa0162017-01-11 09:21:56 -050039import android.app.Fragment;
40import android.app.IActivityManager;
Wale Ogunwale04d9cb52018-04-30 13:55:07 -070041import android.app.IActivityTaskManager;
Jason Monk49fa0162017-01-11 09:21:56 -050042import android.app.StatusBarManager;
43import android.content.BroadcastReceiver;
Casey Burkhardtb9dcd662017-03-20 15:10:16 -070044import android.content.ContentResolver;
Jason Monk49fa0162017-01-11 09:21:56 -050045import android.content.Context;
46import android.content.Intent;
47import android.content.IntentFilter;
48import android.content.res.Configuration;
Casey Burkhardt74922c62017-02-13 12:43:16 -080049import android.database.ContentObserver;
Jason Monk49fa0162017-01-11 09:21:56 -050050import android.graphics.PixelFormat;
51import android.graphics.Rect;
Mike Digman7d092772018-01-11 12:10:32 -080052import android.graphics.drawable.AnimatedVectorDrawable;
Jason Monk49fa0162017-01-11 09:21:56 -050053import android.inputmethodservice.InputMethodService;
54import android.os.Binder;
55import android.os.Bundle;
56import android.os.Handler;
57import android.os.IBinder;
58import android.os.Message;
Jason Monk49fa0162017-01-11 09:21:56 -050059import android.os.RemoteException;
60import android.os.UserHandle;
Casey Burkhardt74922c62017-02-13 12:43:16 -080061import android.provider.Settings;
Aurimas Liutikasfd52c142018-04-17 09:50:46 -070062import androidx.annotation.VisibleForTesting;
Jason Monk49fa0162017-01-11 09:21:56 -050063import android.telecom.TelecomManager;
64import android.text.TextUtils;
65import android.util.Log;
66import android.view.IRotationWatcher.Stub;
67import android.view.KeyEvent;
68import android.view.LayoutInflater;
69import android.view.MotionEvent;
Mike Digman85ff7fa2018-01-23 14:59:52 -080070import android.view.Surface;
Jason Monk49fa0162017-01-11 09:21:56 -050071import android.view.View;
72import android.view.ViewGroup;
73import android.view.WindowManager;
74import android.view.WindowManager.LayoutParams;
75import android.view.WindowManagerGlobal;
76import android.view.accessibility.AccessibilityEvent;
77import android.view.accessibility.AccessibilityManager;
Jason Monk91e587e2017-04-13 13:41:23 -040078import android.view.accessibility.AccessibilityManager.AccessibilityServicesStateChangeListener;
Jason Monk49fa0162017-01-11 09:21:56 -050079
80import com.android.internal.logging.MetricsLogger;
81import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Jason Monkea03be12017-12-04 11:08:41 -050082import com.android.internal.util.LatencyTracker;
Jason Monk9c7844c2017-01-18 15:21:53 -050083import com.android.systemui.Dependency;
Mike Digman7d092772018-01-11 12:10:32 -080084import com.android.systemui.Interpolators;
Mike Digman1e28a5a2018-02-14 10:49:19 -080085import com.android.systemui.OverviewProxyService;
Jason Monk49fa0162017-01-11 09:21:56 -050086import com.android.systemui.R;
Jason Monk9c7844c2017-01-18 15:21:53 -050087import com.android.systemui.SysUiServiceProvider;
Jason Monk49fa0162017-01-11 09:21:56 -050088import com.android.systemui.assist.AssistManager;
89import com.android.systemui.fragments.FragmentHostManager;
90import com.android.systemui.fragments.FragmentHostManager.FragmentListener;
91import com.android.systemui.recents.Recents;
Mike Digman7d092772018-01-11 12:10:32 -080092import com.android.systemui.recents.misc.SysUiTaskStackChangeListener;
93import com.android.systemui.shared.system.ActivityManagerWrapper;
Jason Monk49fa0162017-01-11 09:21:56 -050094import com.android.systemui.stackdivider.Divider;
95import com.android.systemui.statusbar.CommandQueue;
96import com.android.systemui.statusbar.CommandQueue.Callbacks;
Jason Monk91e587e2017-04-13 13:41:23 -040097import com.android.systemui.statusbar.policy.AccessibilityManagerWrapper;
Mike Digman7d092772018-01-11 12:10:32 -080098import com.android.systemui.statusbar.policy.KeyButtonDrawable;
Jason Monk49fa0162017-01-11 09:21:56 -050099import com.android.systemui.statusbar.policy.KeyButtonView;
Mike Digman7d092772018-01-11 12:10:32 -0800100import com.android.systemui.statusbar.policy.RotationLockController;
Rohan Shah20790b82018-07-02 17:21:04 -0700101import com.android.systemui.statusbar.notification.stack.StackStateAnimator;
Jason Monk49fa0162017-01-11 09:21:56 -0500102
103import java.io.FileDescriptor;
104import java.io.PrintWriter;
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800105import java.util.List;
Jason Monk49fa0162017-01-11 09:21:56 -0500106import java.util.Locale;
Mike Digman121b11f2018-04-04 12:45:24 -0700107import java.util.Optional;
Jason Monk49fa0162017-01-11 09:21:56 -0500108
109/**
110 * Fragment containing the NavigationBarFragment. Contains logic for what happens
111 * on clicks and view states of the nav bar.
112 */
113public class NavigationBarFragment extends Fragment implements Callbacks {
114
Jason Monkd4afe152017-05-01 15:37:43 -0400115 public static final String TAG = "NavigationBar";
Jason Monk49fa0162017-01-11 09:21:56 -0500116 private static final boolean DEBUG = false;
Mike Digman3e33da62018-03-14 16:25:11 -0700117 private static final boolean DEBUG_ROTATION = true;
Jason Monk49fa0162017-01-11 09:21:56 -0500118 private static final String EXTRA_DISABLE_STATE = "disabled_state";
Mike Digmandd2f49e2018-03-16 10:54:22 -0700119 private static final String EXTRA_DISABLE2_STATE = "disabled2_state";
Jason Monk49fa0162017-01-11 09:21:56 -0500120
Mike Digman1e28a5a2018-02-14 10:49:19 -0800121 private final static int BUTTON_FADE_IN_OUT_DURATION_MS = 100;
Mike Digman5aeca792018-03-05 11:14:39 -0800122 private final static int NAVBAR_HIDDEN_PENDING_ICON_TIMEOUT_MS = 20000;
Mike Digman1e28a5a2018-02-14 10:49:19 -0800123
Mike Digman50752642018-02-15 13:36:09 -0800124 private static final int NUM_ACCEPTED_ROTATION_SUGGESTIONS_FOR_INTRODUCTION = 3;
125
Jason Monk49fa0162017-01-11 09:21:56 -0500126 /** Allow some time inbetween the long press for back and recents. */
127 private static final int LOCK_TO_APP_GESTURE_TOLERENCE = 200;
128
129 protected NavigationBarView mNavigationBarView = null;
130 protected AssistManager mAssistManager;
131
132 private int mNavigationBarWindowState = WINDOW_STATE_SHOWING;
133
134 private int mNavigationIconHints = 0;
135 private int mNavigationBarMode;
Mike Digman90402952018-01-22 16:05:51 -0800136 private boolean mAccessibilityFeedbackEnabled;
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800137 private AccessibilityManager mAccessibilityManager;
Casey Burkhardt74922c62017-02-13 12:43:16 -0800138 private MagnificationContentObserver mMagnificationObserver;
Casey Burkhardtb9dcd662017-03-20 15:10:16 -0700139 private ContentResolver mContentResolver;
Mike Digmanc94759d2018-01-23 11:01:21 -0800140 private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class);
Jason Monk49fa0162017-01-11 09:21:56 -0500141
142 private int mDisabledFlags1;
Mike Digmandd2f49e2018-03-16 10:54:22 -0700143 private int mDisabledFlags2;
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500144 private StatusBar mStatusBar;
Jason Monk49fa0162017-01-11 09:21:56 -0500145 private Recents mRecents;
146 private Divider mDivider;
147 private WindowManager mWindowManager;
148 private CommandQueue mCommandQueue;
149 private long mLastLockToAppLongPress;
150
151 private Locale mLocale;
152 private int mLayoutDirection;
153
154 private int mSystemUiVisibility;
155 private LightBarController mLightBarController;
Jason Monk49fa0162017-01-11 09:21:56 -0500156
Matthew Ngdc79e5c2017-12-14 17:37:35 -0800157 private OverviewProxyService mOverviewProxyService;
158
Jason Monk49fa0162017-01-11 09:21:56 -0500159 public boolean mHomeBlockedThisTouch;
160
Mike Digman7d092772018-01-11 12:10:32 -0800161 private int mLastRotationSuggestion;
Mike Digman5aeca792018-03-05 11:14:39 -0800162 private boolean mPendingRotationSuggestion;
Mike Digman90402952018-01-22 16:05:51 -0800163 private boolean mHoveringRotationSuggestion;
Mike Digman7d092772018-01-11 12:10:32 -0800164 private RotationLockController mRotationLockController;
165 private TaskStackListenerImpl mTaskStackListener;
166
Mike Digman1e28a5a2018-02-14 10:49:19 -0800167 private final Runnable mRemoveRotationProposal = () -> setRotateSuggestionButtonState(false);
Mike Digman5aeca792018-03-05 11:14:39 -0800168 private final Runnable mCancelPendingRotationProposal =
169 () -> mPendingRotationSuggestion = false;
Mike Digman7d092772018-01-11 12:10:32 -0800170 private Animator mRotateHideAnimator;
Mike Digman50752642018-02-15 13:36:09 -0800171 private ViewRippler mViewRippler = new ViewRippler();
Mike Digman7d092772018-01-11 12:10:32 -0800172
Matthew Ng9c3bce52018-02-01 22:00:31 +0000173 private final OverviewProxyListener mOverviewProxyListener = new OverviewProxyListener() {
174 @Override
175 public void onConnectionChanged(boolean isConnected) {
Winson Chungf9e30272018-03-26 17:25:36 -0700176 mNavigationBarView.updateStates();
Matthew Ng9c3bce52018-02-01 22:00:31 +0000177 updateScreenPinningGestures();
178 }
179
180 @Override
Matthew Ng2ea93b72018-03-14 19:43:18 +0000181 public void onQuickStepStarted() {
Mike Digman85a9bea2018-02-23 15:08:53 -0800182 // Use navbar dragging as a signal to hide the rotate button
183 setRotateSuggestionButtonState(false);
Matthew Ng90ef0632018-08-15 13:53:15 -0700184
185 // Hide the notifications panel when quick step starts
186 mStatusBar.collapsePanel(true /* animate */);
Matthew Ng9c3bce52018-02-01 22:00:31 +0000187 }
Matthew Ng8f25fb962018-01-16 17:17:24 -0800188
189 @Override
190 public void onInteractionFlagsChanged(@InteractionType int flags) {
191 mNavigationBarView.updateStates();
Winson Chungf9e30272018-03-26 17:25:36 -0700192 updateScreenPinningGestures();
Matthew Ng8f25fb962018-01-16 17:17:24 -0800193 }
Matthew Ng96985e72018-05-08 15:46:13 -0700194
195 @Override
196 public void onBackButtonAlphaChanged(float alpha, boolean animate) {
197 final ButtonDispatcher backButton = mNavigationBarView.getBackButton();
198 backButton.setVisibility(alpha > 0 ? View.VISIBLE : View.INVISIBLE);
199 backButton.setAlpha(alpha, animate);
200 }
Matthew Ng9c3bce52018-02-01 22:00:31 +0000201 };
Mike Digman7d092772018-01-11 12:10:32 -0800202
Jason Monk49fa0162017-01-11 09:21:56 -0500203 // ----- Fragment Lifecycle Callbacks -----
204
205 @Override
206 public void onCreate(@Nullable Bundle savedInstanceState) {
207 super.onCreate(savedInstanceState);
Jason Monk9c7844c2017-01-18 15:21:53 -0500208 mCommandQueue = SysUiServiceProvider.getComponent(getContext(), CommandQueue.class);
Jason Monk49fa0162017-01-11 09:21:56 -0500209 mCommandQueue.addCallbacks(this);
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500210 mStatusBar = SysUiServiceProvider.getComponent(getContext(), StatusBar.class);
Jason Monk9c7844c2017-01-18 15:21:53 -0500211 mRecents = SysUiServiceProvider.getComponent(getContext(), Recents.class);
212 mDivider = SysUiServiceProvider.getComponent(getContext(), Divider.class);
Jason Monk49fa0162017-01-11 09:21:56 -0500213 mWindowManager = getContext().getSystemService(WindowManager.class);
214 mAccessibilityManager = getContext().getSystemService(AccessibilityManager.class);
Jason Monk91e587e2017-04-13 13:41:23 -0400215 Dependency.get(AccessibilityManagerWrapper.class).addCallback(
216 mAccessibilityListener);
Casey Burkhardtb9dcd662017-03-20 15:10:16 -0700217 mContentResolver = getContext().getContentResolver();
Casey Burkhardt74922c62017-02-13 12:43:16 -0800218 mMagnificationObserver = new MagnificationContentObserver(
219 getContext().getMainThreadHandler());
Casey Burkhardtb9dcd662017-03-20 15:10:16 -0700220 mContentResolver.registerContentObserver(Settings.Secure.getUriFor(
Casey Burkhardt74922c62017-02-13 12:43:16 -0800221 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED), false,
Casey Burkhardt5d614402017-04-06 13:46:50 -0700222 mMagnificationObserver, UserHandle.USER_ALL);
Casey Burkhardt74922c62017-02-13 12:43:16 -0800223
Jason Monk49fa0162017-01-11 09:21:56 -0500224 if (savedInstanceState != null) {
225 mDisabledFlags1 = savedInstanceState.getInt(EXTRA_DISABLE_STATE, 0);
Mike Digmandd2f49e2018-03-16 10:54:22 -0700226 mDisabledFlags2 = savedInstanceState.getInt(EXTRA_DISABLE2_STATE, 0);
Jason Monk49fa0162017-01-11 09:21:56 -0500227 }
Jason Monk9c7844c2017-01-18 15:21:53 -0500228 mAssistManager = Dependency.get(AssistManager.class);
Matthew Ngdc79e5c2017-12-14 17:37:35 -0800229 mOverviewProxyService = Dependency.get(OverviewProxyService.class);
Jason Monk49fa0162017-01-11 09:21:56 -0500230
231 try {
232 WindowManagerGlobal.getWindowManagerService()
Andrii Kulian35fa3c22017-03-11 09:37:28 -0800233 .watchRotation(mRotationWatcher, getContext().getDisplay().getDisplayId());
Jason Monk49fa0162017-01-11 09:21:56 -0500234 } catch (RemoteException e) {
235 throw e.rethrowFromSystemServer();
236 }
Mike Digman7d092772018-01-11 12:10:32 -0800237
238 mRotationLockController = Dependency.get(RotationLockController.class);
239
Mike Digmanab650252018-03-06 11:01:41 -0800240 // Reset user rotation pref to match that of the WindowManager if starting in locked mode
241 // This will automatically happen when switching from auto-rotate to locked mode
242 if (mRotationLockController.isRotationLocked()) {
243 final int winRotation = mWindowManager.getDefaultDisplay().getRotation();
244 mRotationLockController.setRotationLockedAtAngle(true, winRotation);
245 }
246
Mike Digman7d092772018-01-11 12:10:32 -0800247 // Register the task stack listener
248 mTaskStackListener = new TaskStackListenerImpl();
249 ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener);
Jason Monk49fa0162017-01-11 09:21:56 -0500250 }
251
252 @Override
253 public void onDestroy() {
254 super.onDestroy();
255 mCommandQueue.removeCallbacks(this);
Jason Monk91e587e2017-04-13 13:41:23 -0400256 Dependency.get(AccessibilityManagerWrapper.class).removeCallback(
257 mAccessibilityListener);
Casey Burkhardtb9dcd662017-03-20 15:10:16 -0700258 mContentResolver.unregisterContentObserver(mMagnificationObserver);
Jason Monk49fa0162017-01-11 09:21:56 -0500259 try {
260 WindowManagerGlobal.getWindowManagerService()
261 .removeRotationWatcher(mRotationWatcher);
262 } catch (RemoteException e) {
263 throw e.rethrowFromSystemServer();
264 }
Mike Digman7d092772018-01-11 12:10:32 -0800265
266 // Unregister the task stack listener
267 ActivityManagerWrapper.getInstance().unregisterTaskStackListener(mTaskStackListener);
Jason Monk49fa0162017-01-11 09:21:56 -0500268 }
269
270 @Override
271 public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
272 Bundle savedInstanceState) {
273 return inflater.inflate(R.layout.navigation_bar, container, false);
274 }
275
276 @Override
277 public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
278 super.onViewCreated(view, savedInstanceState);
279 mNavigationBarView = (NavigationBarView) view;
280
281 mNavigationBarView.setDisabledFlags(mDisabledFlags1);
Matthew Ng78f88d12018-01-23 12:39:55 -0800282 mNavigationBarView.setComponents(mRecents, mDivider, mStatusBar.getPanel());
Jason Monk49fa0162017-01-11 09:21:56 -0500283 mNavigationBarView.setOnVerticalChangedListener(this::onVerticalChanged);
284 mNavigationBarView.setOnTouchListener(this::onNavigationTouch);
285 if (savedInstanceState != null) {
286 mNavigationBarView.getLightTransitionsController().restoreState(savedInstanceState);
287 }
288
289 prepareNavigationBarView();
290 checkNavBarModes();
291
Mike Digmandd2f49e2018-03-16 10:54:22 -0700292 setDisabled2Flags(mDisabledFlags2);
293
Jason Monk49fa0162017-01-11 09:21:56 -0500294 IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
295 filter.addAction(Intent.ACTION_SCREEN_ON);
Phil Weavera858c5f2018-04-26 13:27:30 -0700296 filter.addAction(Intent.ACTION_USER_SWITCHED);
Jason Monk49fa0162017-01-11 09:21:56 -0500297 getContext().registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, filter, null, null);
Siarhei Vishniakoud002a0a2017-06-05 22:44:37 +0100298 notifyNavigationBarScreenOn();
Matthew Ng9c3bce52018-02-01 22:00:31 +0000299 mOverviewProxyService.addCallback(mOverviewProxyListener);
Jason Monk49fa0162017-01-11 09:21:56 -0500300 }
301
302 @Override
303 public void onDestroyView() {
304 super.onDestroyView();
Jason Monkaa573e92017-01-27 17:00:29 -0500305 mNavigationBarView.getLightTransitionsController().destroy(getContext());
Matthew Ng9c3bce52018-02-01 22:00:31 +0000306 mOverviewProxyService.removeCallback(mOverviewProxyListener);
Jason Monk49fa0162017-01-11 09:21:56 -0500307 getContext().unregisterReceiver(mBroadcastReceiver);
308 }
309
310 @Override
311 public void onSaveInstanceState(Bundle outState) {
312 super.onSaveInstanceState(outState);
313 outState.putInt(EXTRA_DISABLE_STATE, mDisabledFlags1);
Mike Digmandd2f49e2018-03-16 10:54:22 -0700314 outState.putInt(EXTRA_DISABLE2_STATE, mDisabledFlags2);
Jason Monk49fa0162017-01-11 09:21:56 -0500315 if (mNavigationBarView != null) {
316 mNavigationBarView.getLightTransitionsController().saveState(outState);
317 }
318 }
319
320 @Override
321 public void onConfigurationChanged(Configuration newConfig) {
322 super.onConfigurationChanged(newConfig);
323 final Locale locale = getContext().getResources().getConfiguration().locale;
324 final int ld = TextUtils.getLayoutDirectionFromLocale(locale);
325 if (!locale.equals(mLocale) || ld != mLayoutDirection) {
326 if (DEBUG) {
327 Log.v(TAG, String.format(
328 "config changed locale/LD: %s (%d) -> %s (%d)", mLocale, mLayoutDirection,
329 locale, ld));
330 }
331 mLocale = locale;
332 mLayoutDirection = ld;
333 refreshLayout(ld);
334 }
335 repositionNavigationBar();
336 }
337
338 @Override
339 public void dump(String prefix, FileDescriptor fd, PrintWriter pw, String[] args) {
340 if (mNavigationBarView != null) {
341 pw.print(" mNavigationBarWindowState=");
342 pw.println(windowStateToString(mNavigationBarWindowState));
343 pw.print(" mNavigationBarMode=");
344 pw.println(BarTransitions.modeToString(mNavigationBarMode));
345 dumpBarTransitions(pw, "mNavigationBarView", mNavigationBarView.getBarTransitions());
346 }
347
348 pw.print(" mNavigationBarView=");
349 if (mNavigationBarView == null) {
350 pw.println("null");
351 } else {
352 mNavigationBarView.dump(fd, pw, args);
353 }
354 }
355
356 // ----- CommandQueue Callbacks -----
357
358 @Override
359 public void setImeWindowStatus(IBinder token, int vis, int backDisposition,
360 boolean showImeSwitcher) {
361 boolean imeShown = (vis & InputMethodService.IME_VISIBLE) != 0;
362 int hints = mNavigationIconHints;
Yohei Yukawa386f50e2018-03-14 13:03:42 -0700363 switch (backDisposition) {
364 case InputMethodService.BACK_DISPOSITION_DEFAULT:
365 case InputMethodService.BACK_DISPOSITION_WILL_NOT_DISMISS:
366 case InputMethodService.BACK_DISPOSITION_WILL_DISMISS:
367 if (imeShown) {
368 hints |= NAVIGATION_HINT_BACK_ALT;
369 } else {
370 hints &= ~NAVIGATION_HINT_BACK_ALT;
371 }
372 break;
373 case InputMethodService.BACK_DISPOSITION_ADJUST_NOTHING:
374 hints &= ~NAVIGATION_HINT_BACK_ALT;
375 break;
Jason Monk49fa0162017-01-11 09:21:56 -0500376 }
377 if (showImeSwitcher) {
378 hints |= NAVIGATION_HINT_IME_SHOWN;
379 } else {
380 hints &= ~NAVIGATION_HINT_IME_SHOWN;
381 }
382 if (hints == mNavigationIconHints) return;
383
384 mNavigationIconHints = hints;
385
386 if (mNavigationBarView != null) {
387 mNavigationBarView.setNavigationIconHints(hints);
388 }
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500389 mStatusBar.checkBarModes();
Jason Monk49fa0162017-01-11 09:21:56 -0500390 }
391
392 @Override
393 public void topAppWindowChanged(boolean showMenu) {
394 if (mNavigationBarView != null) {
395 mNavigationBarView.setMenuVisibility(showMenu);
396 }
397 }
398
399 @Override
400 public void setWindowState(int window, int state) {
401 if (mNavigationBarView != null
402 && window == StatusBarManager.WINDOW_NAVIGATION_BAR
403 && mNavigationBarWindowState != state) {
404 mNavigationBarWindowState = state;
405 if (DEBUG_WINDOW_STATE) Log.d(TAG, "Navigation bar " + windowStateToString(state));
Mike Digman5aeca792018-03-05 11:14:39 -0800406
407 // If the navbar is visible, show the rotate button if there's a pending suggestion
408 if (state == WINDOW_STATE_SHOWING && mPendingRotationSuggestion) {
409 showAndLogRotationSuggestion();
410 }
Jason Monk49fa0162017-01-11 09:21:56 -0500411 }
412 }
413
Mike Digman7d092772018-01-11 12:10:32 -0800414 @Override
Mike Digmane0777312018-01-19 12:41:51 -0800415 public void onRotationProposal(final int rotation, boolean isValid) {
Mike Digman3e33da62018-03-14 16:25:11 -0700416 final int winRotation = mWindowManager.getDefaultDisplay().getRotation();
Mike Digmandd2f49e2018-03-16 10:54:22 -0700417 final boolean rotateSuggestionsDisabled = hasDisable2RotateSuggestionFlag(mDisabledFlags2);
Mike Digman3e33da62018-03-14 16:25:11 -0700418 if (DEBUG_ROTATION) {
419 Log.v(TAG, "onRotationProposal proposedRotation=" + Surface.rotationToString(rotation)
420 + ", winRotation=" + Surface.rotationToString(winRotation)
421 + ", isValid=" + isValid + ", mNavBarWindowState="
422 + StatusBarManager.windowStateToString(mNavigationBarWindowState)
Mike Digmandd2f49e2018-03-16 10:54:22 -0700423 + ", rotateSuggestionsDisabled=" + rotateSuggestionsDisabled
Mike Digman3e33da62018-03-14 16:25:11 -0700424 + ", isRotateButtonVisible=" + (mNavigationBarView == null ? "null" :
425 mNavigationBarView.isRotateButtonVisible()));
426 }
427
Mike Digmandd2f49e2018-03-16 10:54:22 -0700428 // Respect the disabled flag, no need for action as flag change callback will handle hiding
429 if (rotateSuggestionsDisabled) return;
430
Mike Digmane0777312018-01-19 12:41:51 -0800431 // This method will be called on rotation suggestion changes even if the proposed rotation
432 // is not valid for the top app. Use invalid rotation choices as a signal to remove the
433 // rotate button if shown.
Mike Digmane0777312018-01-19 12:41:51 -0800434 if (!isValid) {
Mike Digman1e28a5a2018-02-14 10:49:19 -0800435 setRotateSuggestionButtonState(false);
Mike Digmane0777312018-01-19 12:41:51 -0800436 return;
437 }
438
Mike Digman5aeca792018-03-05 11:14:39 -0800439 // If window rotation matches suggested rotation, remove any current suggestions
Mike Digman1e28a5a2018-02-14 10:49:19 -0800440 if (rotation == winRotation) {
Mike Digman5aeca792018-03-05 11:14:39 -0800441 getView().removeCallbacks(mRemoveRotationProposal);
Mike Digman1e28a5a2018-02-14 10:49:19 -0800442 setRotateSuggestionButtonState(false);
Mike Digman5aeca792018-03-05 11:14:39 -0800443 return;
Mike Digman7d092772018-01-11 12:10:32 -0800444 }
Mike Digman5aeca792018-03-05 11:14:39 -0800445
446 // Prepare to show the navbar icon by updating the icon style to change anim params
447 mLastRotationSuggestion = rotation; // Remember rotation for click
448 if (mNavigationBarView != null) {
449 final boolean rotationCCW = isRotationAnimationCCW(winRotation, rotation);
450 int style;
451 if (winRotation == Surface.ROTATION_0 || winRotation == Surface.ROTATION_180) {
452 style = rotationCCW ? R.style.RotateButtonCCWStart90 :
453 R.style.RotateButtonCWStart90;
454 } else { // 90 or 270
455 style = rotationCCW ? R.style.RotateButtonCCWStart0 :
456 R.style.RotateButtonCWStart0;
457 }
458 mNavigationBarView.updateRotateSuggestionButtonStyle(style, true);
459 }
460
461 if (mNavigationBarWindowState != WINDOW_STATE_SHOWING) {
462 // If the navbar isn't shown, flag the rotate icon to be shown should the navbar become
463 // visible given some time limit.
464 mPendingRotationSuggestion = true;
465 getView().removeCallbacks(mCancelPendingRotationProposal);
466 getView().postDelayed(mCancelPendingRotationProposal,
467 NAVBAR_HIDDEN_PENDING_ICON_TIMEOUT_MS);
468
469 } else { // The navbar is visible so show the icon right away
470 showAndLogRotationSuggestion();
471 }
472 }
473
Mike Digmandd2f49e2018-03-16 10:54:22 -0700474 private void onRotationSuggestionsDisabled() {
475 // Immediately hide the rotate button and clear any planned removal
476 setRotateSuggestionButtonState(false, true);
Mike Digmane14c4752018-03-20 12:14:54 -0700477
478 // This method can be called before view setup is done, ensure getView isn't null
479 final View v = getView();
480 if (v != null) v.removeCallbacks(mRemoveRotationProposal);
Mike Digmandd2f49e2018-03-16 10:54:22 -0700481 }
482
Mike Digman5aeca792018-03-05 11:14:39 -0800483 private void showAndLogRotationSuggestion() {
484 setRotateSuggestionButtonState(true);
485 rescheduleRotationTimeout(false);
486 mMetricsLogger.visible(MetricsEvent.ROTATION_SUGGESTION_SHOWN);
Mike Digman7d092772018-01-11 12:10:32 -0800487 }
488
Mike Digman1e28a5a2018-02-14 10:49:19 -0800489 private boolean isRotationAnimationCCW(int from, int to) {
490 // All 180deg WM rotation animations are CCW, match that
491 if (from == Surface.ROTATION_0 && to == Surface.ROTATION_90) return false;
492 if (from == Surface.ROTATION_0 && to == Surface.ROTATION_180) return true; //180d so CCW
493 if (from == Surface.ROTATION_0 && to == Surface.ROTATION_270) return true;
494 if (from == Surface.ROTATION_90 && to == Surface.ROTATION_0) return true;
495 if (from == Surface.ROTATION_90 && to == Surface.ROTATION_180) return false;
496 if (from == Surface.ROTATION_90 && to == Surface.ROTATION_270) return true; //180d so CCW
497 if (from == Surface.ROTATION_180 && to == Surface.ROTATION_0) return true; //180d so CCW
498 if (from == Surface.ROTATION_180 && to == Surface.ROTATION_90) return true;
499 if (from == Surface.ROTATION_180 && to == Surface.ROTATION_270) return false;
500 if (from == Surface.ROTATION_270 && to == Surface.ROTATION_0) return false;
501 if (from == Surface.ROTATION_270 && to == Surface.ROTATION_90) return true; //180d so CCW
502 if (from == Surface.ROTATION_270 && to == Surface.ROTATION_180) return true;
503 return false; // Default
Mike Digmana48cf192018-02-12 17:52:48 -0800504 }
505
Mike Digman1e28a5a2018-02-14 10:49:19 -0800506 public void setRotateSuggestionButtonState(final boolean visible) {
507 setRotateSuggestionButtonState(visible, false);
508 }
509
510 public void setRotateSuggestionButtonState(final boolean visible, final boolean force) {
511 if (mNavigationBarView == null) return;
512
513 // At any point the the button can become invisible because an a11y service became active.
514 // Similarly, a call to make the button visible may be rejected because an a11y service is
515 // active. Must account for this.
516
517 ButtonDispatcher rotBtn = mNavigationBarView.getRotateSuggestionButton();
518 final boolean currentlyVisible = mNavigationBarView.isRotateButtonVisible();
519
520 // Rerun a show animation to indicate change but don't rerun a hide animation
521 if (!visible && !currentlyVisible) return;
522
523 View view = rotBtn.getCurrentView();
524 if (view == null) return;
525
526 KeyButtonDrawable kbd = rotBtn.getImageDrawable();
527 if (kbd == null) return;
528
529 // The KBD and AVD is recreated every new valid suggestion because of style changes.
530 AnimatedVectorDrawable animIcon = null;
531 if (kbd.getDrawable(0) instanceof AnimatedVectorDrawable) {
532 animIcon = (AnimatedVectorDrawable) kbd.getDrawable(0);
533 }
534
Mike Digman5aeca792018-03-05 11:14:39 -0800535 // Clear any pending suggestion flag as it has either been nullified or is being shown
536 mPendingRotationSuggestion = false;
Mike Digmanf4c98992018-04-25 11:25:59 -0700537 if (getView() != null) getView().removeCallbacks(mCancelPendingRotationProposal);
Mike Digman5aeca792018-03-05 11:14:39 -0800538
539 // Handle the visibility change and animation
Mike Digman1e28a5a2018-02-14 10:49:19 -0800540 if (visible) { // Appear and change (cannot force)
Mike Digman85a9bea2018-02-23 15:08:53 -0800541 // Stop and clear any currently running hide animations
Mike Digman1e28a5a2018-02-14 10:49:19 -0800542 if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) {
Mike Digman85a9bea2018-02-23 15:08:53 -0800543 mRotateHideAnimator.cancel();
Mike Digman1e28a5a2018-02-14 10:49:19 -0800544 }
Mike Digman85a9bea2018-02-23 15:08:53 -0800545 mRotateHideAnimator = null;
Mike Digman1e28a5a2018-02-14 10:49:19 -0800546
547 // Reset the alpha if any has changed due to hide animation
548 view.setAlpha(1f);
549
550 // Run the rotate icon's animation if it has one
551 if (animIcon != null) {
552 animIcon.reset();
553 animIcon.start();
554 }
555
Mike Digman50752642018-02-15 13:36:09 -0800556 if (!isRotateSuggestionIntroduced()) mViewRippler.start(view);
557
Mike Digman1e28a5a2018-02-14 10:49:19 -0800558 // Set visibility, may fail if a11y service is active.
559 // If invisible, call will stop animation.
Mike Digman9b50b762018-04-19 10:50:35 -0700560 int appliedVisibility = mNavigationBarView.setRotateButtonVisibility(true);
561 if (appliedVisibility == View.VISIBLE) {
562 // If the button will actually become visible and the navbar is about to hide,
563 // tell the statusbar to keep it around for longer
564 mStatusBar.touchAutoHide();
565 }
Mike Digman1e28a5a2018-02-14 10:49:19 -0800566
567 } else { // Hide
568
Mike Digman50752642018-02-15 13:36:09 -0800569 mViewRippler.stop(); // Prevent any pending ripples, force hide or not
570
Mike Digman1e28a5a2018-02-14 10:49:19 -0800571 if (force) {
572 // If a hide animator is running stop it and make invisible
573 if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) {
574 mRotateHideAnimator.pause();
575 }
576 mNavigationBarView.setRotateButtonVisibility(false);
577 return;
578 }
579
580 // Don't start any new hide animations if one is running
581 if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) return;
582
583 ObjectAnimator fadeOut = ObjectAnimator.ofFloat(view, "alpha",
584 0f);
585 fadeOut.setDuration(BUTTON_FADE_IN_OUT_DURATION_MS);
586 fadeOut.setInterpolator(Interpolators.LINEAR);
587 fadeOut.addListener(new AnimatorListenerAdapter() {
588 @Override
589 public void onAnimationEnd(Animator animation) {
590 mNavigationBarView.setRotateButtonVisibility(false);
591 }
592 });
593
594 mRotateHideAnimator = fadeOut;
595 fadeOut.start();
Mike Digmana48cf192018-02-12 17:52:48 -0800596 }
597 }
598
Mike Digman90402952018-01-22 16:05:51 -0800599 private void rescheduleRotationTimeout(final boolean reasonHover) {
600 // May be called due to a new rotation proposal or a change in hover state
601 if (reasonHover) {
602 // Don't reschedule if a hide animator is running
Mike Digman1e28a5a2018-02-14 10:49:19 -0800603 if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) return;
Mike Digman90402952018-01-22 16:05:51 -0800604 // Don't reschedule if not visible
Mike Digman1e28a5a2018-02-14 10:49:19 -0800605 if (!mNavigationBarView.isRotateButtonVisible()) return;
Mike Digman90402952018-01-22 16:05:51 -0800606 }
607
Mike Digman5aeca792018-03-05 11:14:39 -0800608 getView().removeCallbacks(mRemoveRotationProposal); // Stop any pending removal
609 getView().postDelayed(mRemoveRotationProposal,
Mike Digman90402952018-01-22 16:05:51 -0800610 computeRotationProposalTimeout()); // Schedule timeout
611 }
612
613 private int computeRotationProposalTimeout() {
614 if (mAccessibilityFeedbackEnabled) return 20000;
615 if (mHoveringRotationSuggestion) return 16000;
Mike Digmand13e43b2018-05-21 11:23:56 -0700616 return 10000;
Mike Digman90402952018-01-22 16:05:51 -0800617 }
618
Mike Digman50752642018-02-15 13:36:09 -0800619 private boolean isRotateSuggestionIntroduced() {
620 ContentResolver cr = getContext().getContentResolver();
621 return Settings.Secure.getInt(cr, Settings.Secure.NUM_ROTATION_SUGGESTIONS_ACCEPTED, 0)
622 >= NUM_ACCEPTED_ROTATION_SUGGESTIONS_FOR_INTRODUCTION;
623 }
624
625 private void incrementNumAcceptedRotationSuggestionsIfNeeded() {
626 // Get the number of accepted suggestions
627 ContentResolver cr = getContext().getContentResolver();
628 final int numSuggestions = Settings.Secure.getInt(cr,
629 Settings.Secure.NUM_ROTATION_SUGGESTIONS_ACCEPTED, 0);
630
631 // Increment the number of accepted suggestions only if it would change intro mode
632 if (numSuggestions < NUM_ACCEPTED_ROTATION_SUGGESTIONS_FOR_INTRODUCTION) {
633 Settings.Secure.putInt(cr, Settings.Secure.NUM_ROTATION_SUGGESTIONS_ACCEPTED,
634 numSuggestions + 1);
635 }
636 }
637
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500638 // Injected from StatusBar at creation.
Jason Monk49fa0162017-01-11 09:21:56 -0500639 public void setCurrentSysuiVisibility(int systemUiVisibility) {
640 mSystemUiVisibility = systemUiVisibility;
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500641 mNavigationBarMode = mStatusBar.computeBarMode(0, mSystemUiVisibility,
Jason Monk49fa0162017-01-11 09:21:56 -0500642 View.NAVIGATION_BAR_TRANSIENT, View.NAVIGATION_BAR_TRANSLUCENT,
643 View.NAVIGATION_BAR_TRANSPARENT);
644 checkNavBarModes();
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500645 mStatusBar.touchAutoHide();
Jason Monk49fa0162017-01-11 09:21:56 -0500646 mLightBarController.onNavigationVisibilityChanged(mSystemUiVisibility, 0 /* mask */,
647 true /* nbModeChanged */, mNavigationBarMode);
648 }
649
650 @Override
651 public void setSystemUiVisibility(int vis, int fullscreenStackVis, int dockedStackVis,
652 int mask, Rect fullscreenStackBounds, Rect dockedStackBounds) {
653 final int oldVal = mSystemUiVisibility;
654 final int newVal = (oldVal & ~mask) | (vis & mask);
655 final int diff = newVal ^ oldVal;
656 boolean nbModeChanged = false;
657 if (diff != 0) {
658 mSystemUiVisibility = newVal;
659
660 // update navigation bar mode
661 final int nbMode = getView() == null
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500662 ? -1 : mStatusBar.computeBarMode(oldVal, newVal,
Jason Monk49fa0162017-01-11 09:21:56 -0500663 View.NAVIGATION_BAR_TRANSIENT, View.NAVIGATION_BAR_TRANSLUCENT,
664 View.NAVIGATION_BAR_TRANSPARENT);
665 nbModeChanged = nbMode != -1;
666 if (nbModeChanged) {
667 if (mNavigationBarMode != nbMode) {
Tracy Zhou1ac592c2018-07-25 13:47:37 -0700668 if (mNavigationBarMode == MODE_TRANSPARENT
669 || mNavigationBarMode == MODE_LIGHTS_OUT_TRANSPARENT) {
670 mNavigationBarView.hideRecentsOnboarding();
671 }
Jason Monk49fa0162017-01-11 09:21:56 -0500672 mNavigationBarMode = nbMode;
673 checkNavBarModes();
674 }
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500675 mStatusBar.touchAutoHide();
Jason Monk49fa0162017-01-11 09:21:56 -0500676 }
677 }
678
679 mLightBarController.onNavigationVisibilityChanged(vis, mask, nbModeChanged,
680 mNavigationBarMode);
681 }
682
683 @Override
684 public void disable(int state1, int state2, boolean animate) {
Mike Digmandd2f49e2018-03-16 10:54:22 -0700685 // Navigation bar flags are in both state1 and state2.
686 final int masked = state1 & (StatusBarManager.DISABLE_HOME
Jason Monk49fa0162017-01-11 09:21:56 -0500687 | StatusBarManager.DISABLE_RECENT
688 | StatusBarManager.DISABLE_BACK
689 | StatusBarManager.DISABLE_SEARCH);
690 if (masked != mDisabledFlags1) {
691 mDisabledFlags1 = masked;
692 if (mNavigationBarView != null) mNavigationBarView.setDisabledFlags(state1);
Matthew Ng9c3bce52018-02-01 22:00:31 +0000693 updateScreenPinningGestures();
Jason Monk49fa0162017-01-11 09:21:56 -0500694 }
Mike Digmandd2f49e2018-03-16 10:54:22 -0700695
696 final int masked2 = state2 & (StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS);
697 if (masked2 != mDisabledFlags2) {
698 mDisabledFlags2 = masked2;
699 setDisabled2Flags(masked2);
700 }
701 }
702
703 private void setDisabled2Flags(int state2) {
704 // Method only called on change of disable2 flags
705 final boolean rotateSuggestionsDisabled = hasDisable2RotateSuggestionFlag(state2);
706 if (rotateSuggestionsDisabled) onRotationSuggestionsDisabled();
707 }
708
709 private boolean hasDisable2RotateSuggestionFlag(int disable2Flags) {
710 return (disable2Flags & StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS) != 0;
Jason Monk49fa0162017-01-11 09:21:56 -0500711 }
712
713 // ----- Internal stuffz -----
714
715 private void refreshLayout(int layoutDirection) {
716 if (mNavigationBarView != null) {
717 mNavigationBarView.setLayoutDirection(layoutDirection);
718 }
719 }
720
721 private boolean shouldDisableNavbarGestures() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500722 return !mStatusBar.isDeviceProvisioned()
Matthew Ngfee0b5b2018-02-21 15:38:21 -0800723 || (mDisabledFlags1 & StatusBarManager.DISABLE_SEARCH) != 0;
Jason Monk49fa0162017-01-11 09:21:56 -0500724 }
725
726 private void repositionNavigationBar() {
727 if (mNavigationBarView == null || !mNavigationBarView.isAttachedToWindow()) return;
728
729 prepareNavigationBarView();
730
731 mWindowManager.updateViewLayout((View) mNavigationBarView.getParent(),
732 ((View) mNavigationBarView.getParent()).getLayoutParams());
733 }
734
Matthew Ng9c3bce52018-02-01 22:00:31 +0000735 private void updateScreenPinningGestures() {
736 if (mNavigationBarView == null) {
737 return;
738 }
739
740 // Change the cancel pin gesture to home and back if recents button is invisible
741 boolean recentsVisible = mNavigationBarView.isRecentsButtonVisible();
Matthew Ng9c3bce52018-02-01 22:00:31 +0000742 ButtonDispatcher backButton = mNavigationBarView.getBackButton();
743 if (recentsVisible) {
Matthew Ng9c3bce52018-02-01 22:00:31 +0000744 backButton.setOnLongClickListener(this::onLongPressBackRecents);
745 } else {
Matthew Ng9c3bce52018-02-01 22:00:31 +0000746 backButton.setOnLongClickListener(this::onLongPressBackHome);
747 }
748 }
749
Siarhei Vishniakoud002a0a2017-06-05 22:44:37 +0100750 private void notifyNavigationBarScreenOn() {
Matthew Ngd0a73e72018-03-02 15:16:03 -0800751 mNavigationBarView.updateNavButtonIcons();
Jason Monk49fa0162017-01-11 09:21:56 -0500752 }
753
754 private void prepareNavigationBarView() {
755 mNavigationBarView.reorient();
756
757 ButtonDispatcher recentsButton = mNavigationBarView.getRecentsButton();
758 recentsButton.setOnClickListener(this::onRecentsClick);
759 recentsButton.setOnTouchListener(this::onRecentsTouch);
760 recentsButton.setLongClickable(true);
761 recentsButton.setOnLongClickListener(this::onLongPressBackRecents);
762
763 ButtonDispatcher backButton = mNavigationBarView.getBackButton();
764 backButton.setLongClickable(true);
Jason Monk49fa0162017-01-11 09:21:56 -0500765
766 ButtonDispatcher homeButton = mNavigationBarView.getHomeButton();
767 homeButton.setOnTouchListener(this::onHomeTouch);
Matthew Ngfee0b5b2018-02-21 15:38:21 -0800768 homeButton.setOnLongClickListener(this::onHomeLongClick);
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800769
770 ButtonDispatcher accessibilityButton = mNavigationBarView.getAccessibilityButton();
771 accessibilityButton.setOnClickListener(this::onAccessibilityClick);
772 accessibilityButton.setOnLongClickListener(this::onAccessibilityLongClick);
Phil Weaverdb9a7742017-04-18 08:15:06 -0700773 updateAccessibilityServicesState(mAccessibilityManager);
Mike Digman7d092772018-01-11 12:10:32 -0800774
775 ButtonDispatcher rotateSuggestionButton = mNavigationBarView.getRotateSuggestionButton();
776 rotateSuggestionButton.setOnClickListener(this::onRotateSuggestionClick);
Mike Digman90402952018-01-22 16:05:51 -0800777 rotateSuggestionButton.setOnHoverListener(this::onRotateSuggestionHover);
Matthew Ng9c3bce52018-02-01 22:00:31 +0000778 updateScreenPinningGestures();
Jason Monk49fa0162017-01-11 09:21:56 -0500779 }
780
781 private boolean onHomeTouch(View v, MotionEvent event) {
782 if (mHomeBlockedThisTouch && event.getActionMasked() != MotionEvent.ACTION_DOWN) {
783 return true;
784 }
785 // If an incoming call is ringing, HOME is totally disabled.
786 // (The user is already on the InCallUI at this point,
787 // and his ONLY options are to answer or reject the call.)
788 switch (event.getAction()) {
789 case MotionEvent.ACTION_DOWN:
790 mHomeBlockedThisTouch = false;
791 TelecomManager telecomManager =
792 getContext().getSystemService(TelecomManager.class);
793 if (telecomManager != null && telecomManager.isRinging()) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500794 if (mStatusBar.isKeyguardShowing()) {
Jason Monk49fa0162017-01-11 09:21:56 -0500795 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call. " +
796 "No heads up");
797 mHomeBlockedThisTouch = true;
798 return true;
799 }
800 }
801 break;
802 case MotionEvent.ACTION_UP:
803 case MotionEvent.ACTION_CANCEL:
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500804 mStatusBar.awakenDreams();
Jason Monk49fa0162017-01-11 09:21:56 -0500805 break;
806 }
807 return false;
808 }
809
810 private void onVerticalChanged(boolean isVertical) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500811 mStatusBar.setQsScrimEnabled(!isVertical);
Jason Monk49fa0162017-01-11 09:21:56 -0500812 }
813
814 private boolean onNavigationTouch(View v, MotionEvent event) {
Eliot Courtneycb5d3162017-08-09 16:53:15 +0900815 mStatusBar.checkUserAutohide(event);
Jason Monk49fa0162017-01-11 09:21:56 -0500816 return false;
817 }
818
Jason Monk865246d2017-01-19 08:27:01 -0500819 @VisibleForTesting
820 boolean onHomeLongClick(View v) {
Matthew Ng6ff33b72018-02-27 13:47:38 -0800821 if (!mNavigationBarView.isRecentsButtonVisible()
822 && ActivityManagerWrapper.getInstance().isScreenPinningActive()) {
Matthew Ngfee0b5b2018-02-21 15:38:21 -0800823 return onLongPressBackHome(v);
824 }
Jason Monk49fa0162017-01-11 09:21:56 -0500825 if (shouldDisableNavbarGestures()) {
826 return false;
827 }
Matthew Ng2ea93b72018-03-14 19:43:18 +0000828 mNavigationBarView.onNavigationButtonLongPress(v);
Mike Digmanc94759d2018-01-23 11:01:21 -0800829 mMetricsLogger.action(MetricsEvent.ACTION_ASSIST_LONG_PRESS);
Jason Monk49fa0162017-01-11 09:21:56 -0500830 mAssistManager.startAssist(new Bundle() /* args */);
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500831 mStatusBar.awakenDreams();
Matthew Ngdc79e5c2017-12-14 17:37:35 -0800832
Jason Monk49fa0162017-01-11 09:21:56 -0500833 if (mNavigationBarView != null) {
834 mNavigationBarView.abortCurrentGesture();
835 }
836 return true;
837 }
838
839 // additional optimization when we have software system buttons - start loading the recent
840 // tasks on touch down
841 private boolean onRecentsTouch(View v, MotionEvent event) {
842 int action = event.getAction() & MotionEvent.ACTION_MASK;
843 if (action == MotionEvent.ACTION_DOWN) {
844 mCommandQueue.preloadRecentApps();
845 } else if (action == MotionEvent.ACTION_CANCEL) {
846 mCommandQueue.cancelPreloadRecentApps();
847 } else if (action == MotionEvent.ACTION_UP) {
848 if (!v.isPressed()) {
849 mCommandQueue.cancelPreloadRecentApps();
850 }
851 }
852 return false;
853 }
854
855 private void onRecentsClick(View v) {
856 if (LatencyTracker.isEnabled(getContext())) {
857 LatencyTracker.getInstance(getContext()).onActionStart(
858 LatencyTracker.ACTION_TOGGLE_RECENTS);
859 }
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500860 mStatusBar.awakenDreams();
Jason Monk49fa0162017-01-11 09:21:56 -0500861 mCommandQueue.toggleRecentApps();
862 }
863
Matthew Ng9c3bce52018-02-01 22:00:31 +0000864 private boolean onLongPressBackHome(View v) {
Matthew Ng2ea93b72018-03-14 19:43:18 +0000865 mNavigationBarView.onNavigationButtonLongPress(v);
Matthew Ng9c3bce52018-02-01 22:00:31 +0000866 return onLongPressNavigationButtons(v, R.id.back, R.id.home);
867 }
868
869 private boolean onLongPressBackRecents(View v) {
Matthew Ng2ea93b72018-03-14 19:43:18 +0000870 mNavigationBarView.onNavigationButtonLongPress(v);
Matthew Ng9c3bce52018-02-01 22:00:31 +0000871 return onLongPressNavigationButtons(v, R.id.back, R.id.recent_apps);
872 }
873
Jason Monk49fa0162017-01-11 09:21:56 -0500874 /**
Matthew Ng9c3bce52018-02-01 22:00:31 +0000875 * This handles long-press of both back and recents/home. Back is the common button with
876 * combination of recents if it is visible or home if recents is invisible.
877 * They are handled together to capture them both being long-pressed
Jason Monk49fa0162017-01-11 09:21:56 -0500878 * at the same time to exit screen pinning (lock task).
879 *
Matthew Ng9c3bce52018-02-01 22:00:31 +0000880 * When accessibility mode is on, only a long-press from recents/home
Jason Monk49fa0162017-01-11 09:21:56 -0500881 * is required to exit.
882 *
883 * In all other circumstances we try to pass through long-press events
884 * for Back, so that apps can still use it. Which can be from two things.
885 * 1) Not currently in screen pinning (lock task).
Matthew Ng9c3bce52018-02-01 22:00:31 +0000886 * 2) Back is long-pressed without recents/home.
Jason Monk49fa0162017-01-11 09:21:56 -0500887 */
Matthew Ng9c3bce52018-02-01 22:00:31 +0000888 private boolean onLongPressNavigationButtons(View v, @IdRes int btnId1, @IdRes int btnId2) {
Jason Monk49fa0162017-01-11 09:21:56 -0500889 try {
890 boolean sendBackLongPress = false;
Wale Ogunwale04d9cb52018-04-30 13:55:07 -0700891 IActivityTaskManager activityManager = ActivityTaskManager.getService();
Jason Monk49fa0162017-01-11 09:21:56 -0500892 boolean touchExplorationEnabled = mAccessibilityManager.isTouchExplorationEnabled();
893 boolean inLockTaskMode = activityManager.isInLockTaskMode();
894 if (inLockTaskMode && !touchExplorationEnabled) {
895 long time = System.currentTimeMillis();
Matthew Ng9c3bce52018-02-01 22:00:31 +0000896
Jason Monk49fa0162017-01-11 09:21:56 -0500897 // If we recently long-pressed the other button then they were
898 // long-pressed 'together'
899 if ((time - mLastLockToAppLongPress) < LOCK_TO_APP_GESTURE_TOLERENCE) {
Benjamin Franza83859f2017-07-03 16:34:14 +0100900 activityManager.stopSystemLockTaskMode();
Jason Monk49fa0162017-01-11 09:21:56 -0500901 // When exiting refresh disabled flags.
Matthew Ngd0a73e72018-03-02 15:16:03 -0800902 mNavigationBarView.updateNavButtonIcons();
Jason Monk49fa0162017-01-11 09:21:56 -0500903 return true;
Matthew Ng9c3bce52018-02-01 22:00:31 +0000904 } else if (v.getId() == btnId1) {
905 ButtonDispatcher button = btnId2 == R.id.recent_apps
906 ? mNavigationBarView.getRecentsButton()
907 : mNavigationBarView.getHomeButton();
908 if (!button.getCurrentView().isPressed()) {
909 // If we aren't pressing recents/home right now then they presses
910 // won't be together, so send the standard long-press action.
911 sendBackLongPress = true;
912 }
Jason Monk49fa0162017-01-11 09:21:56 -0500913 }
914 mLastLockToAppLongPress = time;
915 } else {
916 // If this is back still need to handle sending the long-press event.
Matthew Ng9c3bce52018-02-01 22:00:31 +0000917 if (v.getId() == btnId1) {
Jason Monk49fa0162017-01-11 09:21:56 -0500918 sendBackLongPress = true;
919 } else if (touchExplorationEnabled && inLockTaskMode) {
Matthew Ng9c3bce52018-02-01 22:00:31 +0000920 // When in accessibility mode a long press that is recents/home (not back)
Jason Monk49fa0162017-01-11 09:21:56 -0500921 // should stop lock task.
Benjamin Franza83859f2017-07-03 16:34:14 +0100922 activityManager.stopSystemLockTaskMode();
Jason Monk49fa0162017-01-11 09:21:56 -0500923 // When exiting refresh disabled flags.
Matthew Ngd0a73e72018-03-02 15:16:03 -0800924 mNavigationBarView.updateNavButtonIcons();
Jason Monk49fa0162017-01-11 09:21:56 -0500925 return true;
Matthew Ng9c3bce52018-02-01 22:00:31 +0000926 } else if (v.getId() == btnId2) {
927 return btnId2 == R.id.recent_apps
928 ? onLongPressRecents()
929 : onHomeLongClick(mNavigationBarView.getHomeButton().getCurrentView());
Jason Monk49fa0162017-01-11 09:21:56 -0500930 }
931 }
932 if (sendBackLongPress) {
933 KeyButtonView keyButtonView = (KeyButtonView) v;
934 keyButtonView.sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.FLAG_LONG_PRESS);
935 keyButtonView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED);
936 return true;
937 }
938 } catch (RemoteException e) {
939 Log.d(TAG, "Unable to reach activity manager", e);
940 }
941 return false;
942 }
943
944 private boolean onLongPressRecents() {
Wale Ogunwale65ebd952018-04-25 15:41:44 -0700945 if (mRecents == null || !ActivityTaskManager.supportsMultiWindow(getContext())
Matthew Ng43db6d22017-06-27 15:29:39 -0700946 || !mDivider.getView().getSnapAlgorithm().isSplitScreenFeasible()
Winson Chung074c4342018-03-26 17:27:19 -0700947 || Recents.getConfiguration().isLowRamDevice
948 // If we are connected to the overview service, then disable the recents button
949 || mOverviewProxyService.getProxy() != null) {
Jason Monk49fa0162017-01-11 09:21:56 -0500950 return false;
951 }
952
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500953 return mStatusBar.toggleSplitScreenMode(MetricsEvent.ACTION_WINDOW_DOCK_LONGPRESS,
Jason Monk49fa0162017-01-11 09:21:56 -0500954 MetricsEvent.ACTION_WINDOW_UNDOCK_LONGPRESS);
955 }
956
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800957 private void onAccessibilityClick(View v) {
958 mAccessibilityManager.notifyAccessibilityButtonClicked();
959 }
960
961 private boolean onAccessibilityLongClick(View v) {
Casey Burkhardt5e8b9802017-03-24 10:07:20 -0700962 Intent intent = new Intent(AccessibilityManager.ACTION_CHOOSE_ACCESSIBILITY_BUTTON);
963 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
Casey Burkhardt5d614402017-04-06 13:46:50 -0700964 v.getContext().startActivityAsUser(intent, UserHandle.CURRENT);
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800965 return true;
966 }
967
Phil Weaverdb9a7742017-04-18 08:15:06 -0700968 private void updateAccessibilityServicesState(AccessibilityManager accessibilityManager) {
Casey Burkhardt74922c62017-02-13 12:43:16 -0800969 int requestingServices = 0;
970 try {
Casey Burkhardt5d614402017-04-06 13:46:50 -0700971 if (Settings.Secure.getIntForUser(mContentResolver,
972 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED,
973 UserHandle.USER_CURRENT) == 1) {
Casey Burkhardt74922c62017-02-13 12:43:16 -0800974 requestingServices++;
975 }
976 } catch (Settings.SettingNotFoundException e) {
977 }
978
Mike Digman90402952018-01-22 16:05:51 -0800979 boolean feedbackEnabled = false;
Casey Burkhardt5d614402017-04-06 13:46:50 -0700980 // AccessibilityManagerService resolves services for the current user since the local
981 // AccessibilityManager is created from a Context with the INTERACT_ACROSS_USERS permission
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800982 final List<AccessibilityServiceInfo> services =
Phil Weaverdb9a7742017-04-18 08:15:06 -0700983 accessibilityManager.getEnabledAccessibilityServiceList(
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800984 AccessibilityServiceInfo.FEEDBACK_ALL_MASK);
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800985 for (int i = services.size() - 1; i >= 0; --i) {
986 AccessibilityServiceInfo info = services.get(i);
987 if ((info.flags & AccessibilityServiceInfo.FLAG_REQUEST_ACCESSIBILITY_BUTTON) != 0) {
988 requestingServices++;
989 }
Mike Digman90402952018-01-22 16:05:51 -0800990
991 if (info.feedbackType != 0 && info.feedbackType !=
992 AccessibilityServiceInfo.FEEDBACK_GENERIC) {
993 feedbackEnabled = true;
994 }
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800995 }
996
Mike Digman90402952018-01-22 16:05:51 -0800997 mAccessibilityFeedbackEnabled = feedbackEnabled;
998
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800999 final boolean showAccessibilityButton = requestingServices >= 1;
1000 final boolean targetSelection = requestingServices >= 2;
1001 mNavigationBarView.setAccessibilityButtonState(showAccessibilityButton, targetSelection);
1002 }
1003
Mike Digman7d092772018-01-11 12:10:32 -08001004 private void onRotateSuggestionClick(View v) {
Mike Digmanc94759d2018-01-23 11:01:21 -08001005 mMetricsLogger.action(MetricsEvent.ACTION_ROTATION_SUGGESTION_ACCEPTED);
Mike Digman50752642018-02-15 13:36:09 -08001006 incrementNumAcceptedRotationSuggestionsIfNeeded();
Mike Digman7d092772018-01-11 12:10:32 -08001007 mRotationLockController.setRotationLockedAtAngle(true, mLastRotationSuggestion);
1008 }
1009
Mike Digman90402952018-01-22 16:05:51 -08001010 private boolean onRotateSuggestionHover(View v, MotionEvent event) {
1011 final int action = event.getActionMasked();
1012 mHoveringRotationSuggestion = (action == MotionEvent.ACTION_HOVER_ENTER)
1013 || (action == MotionEvent.ACTION_HOVER_MOVE);
1014 rescheduleRotationTimeout(true);
1015 return false; // Must return false so a11y hover events are dispatched correctly.
1016 }
1017
Jason Monk2a6ea9c2017-01-26 11:14:51 -05001018 // ----- Methods that StatusBar talks to (should be minimized) -----
Jason Monk49fa0162017-01-11 09:21:56 -05001019
Jason Monk49fa0162017-01-11 09:21:56 -05001020 public void setLightBarController(LightBarController lightBarController) {
1021 mLightBarController = lightBarController;
1022 mLightBarController.setNavigationBar(mNavigationBarView.getLightTransitionsController());
1023 }
1024
1025 public boolean isSemiTransparent() {
1026 return mNavigationBarMode == MODE_SEMI_TRANSPARENT;
1027 }
1028
Jason Monk49fa0162017-01-11 09:21:56 -05001029 public void disableAnimationsDuringHide(long delay) {
1030 mNavigationBarView.setLayoutTransitionsEnabled(false);
1031 mNavigationBarView.postDelayed(() -> mNavigationBarView.setLayoutTransitionsEnabled(true),
1032 delay + StackStateAnimator.ANIMATION_DURATION_GO_TO_FULL_SHADE);
1033 }
1034
Jason Monk49fa0162017-01-11 09:21:56 -05001035 public BarTransitions getBarTransitions() {
1036 return mNavigationBarView.getBarTransitions();
1037 }
1038
1039 public void checkNavBarModes() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -05001040 mStatusBar.checkBarMode(mNavigationBarMode,
Jason Monk49fa0162017-01-11 09:21:56 -05001041 mNavigationBarWindowState, mNavigationBarView.getBarTransitions());
1042 }
1043
1044 public void finishBarAnimations() {
1045 mNavigationBarView.getBarTransitions().finishAnimations();
1046 }
1047
Jason Monk91e587e2017-04-13 13:41:23 -04001048 private final AccessibilityServicesStateChangeListener mAccessibilityListener =
1049 this::updateAccessibilityServicesState;
1050
Casey Burkhardt74922c62017-02-13 12:43:16 -08001051 private class MagnificationContentObserver extends ContentObserver {
1052
1053 public MagnificationContentObserver(Handler handler) {
1054 super(handler);
1055 }
1056
1057 @Override
1058 public void onChange(boolean selfChange) {
Phil Weaverdb9a7742017-04-18 08:15:06 -07001059 NavigationBarFragment.this.updateAccessibilityServicesState(mAccessibilityManager);
Casey Burkhardt74922c62017-02-13 12:43:16 -08001060 }
1061 }
1062
Jason Monk49fa0162017-01-11 09:21:56 -05001063 private final Stub mRotationWatcher = new Stub() {
1064 @Override
Mike Digman90402952018-01-22 16:05:51 -08001065 public void onRotationChanged(final int rotation) throws RemoteException {
Jason Monk49fa0162017-01-11 09:21:56 -05001066 // We need this to be scheduled as early as possible to beat the redrawing of
1067 // window in response to the orientation change.
1068 Handler h = getView().getHandler();
1069 Message msg = Message.obtain(h, () -> {
Mike Digman85ff7fa2018-01-23 14:59:52 -08001070
1071 // If the screen rotation changes while locked, potentially update lock to flow with
Mike Digman90402952018-01-22 16:05:51 -08001072 // new screen rotation and hide any showing suggestions.
1073 if (mRotationLockController.isRotationLocked()) {
Mike Digman85ff7fa2018-01-23 14:59:52 -08001074 if (shouldOverrideUserLockPrefs(rotation)) {
1075 mRotationLockController.setRotationLockedAtAngle(true, rotation);
1076 }
Mike Digman1e28a5a2018-02-14 10:49:19 -08001077 setRotateSuggestionButtonState(false, true);
Mike Digman90402952018-01-22 16:05:51 -08001078 }
1079
Jason Monk49fa0162017-01-11 09:21:56 -05001080 if (mNavigationBarView != null
1081 && mNavigationBarView.needsReorient(rotation)) {
1082 repositionNavigationBar();
1083 }
1084 });
1085 msg.setAsynchronous(true);
1086 h.sendMessageAtFrontOfQueue(msg);
1087 }
Mike Digman85ff7fa2018-01-23 14:59:52 -08001088
1089 private boolean shouldOverrideUserLockPrefs(final int rotation) {
Mike Digmanab650252018-03-06 11:01:41 -08001090 // Only override user prefs when returning to the natural rotation (normally portrait).
Mike Digman85ff7fa2018-01-23 14:59:52 -08001091 // Don't let apps that force landscape or 180 alter user lock.
Mike Digmanab650252018-03-06 11:01:41 -08001092 return rotation == NATURAL_ROTATION;
Mike Digman85ff7fa2018-01-23 14:59:52 -08001093 }
Jason Monk49fa0162017-01-11 09:21:56 -05001094 };
1095
1096 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1097 @Override
1098 public void onReceive(Context context, Intent intent) {
1099 String action = intent.getAction();
Siarhei Vishniakoud002a0a2017-06-05 22:44:37 +01001100 if (Intent.ACTION_SCREEN_OFF.equals(action)
1101 || Intent.ACTION_SCREEN_ON.equals(action)) {
1102 notifyNavigationBarScreenOn();
Jason Monk49fa0162017-01-11 09:21:56 -05001103 }
Phil Weavera858c5f2018-04-26 13:27:30 -07001104 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
1105 // The accessibility settings may be different for the new user
1106 updateAccessibilityServicesState(mAccessibilityManager);
1107 };
Jason Monk49fa0162017-01-11 09:21:56 -05001108 }
1109 };
1110
Mike Digman7d092772018-01-11 12:10:32 -08001111 class TaskStackListenerImpl extends SysUiTaskStackChangeListener {
1112 // Invalidate any rotation suggestion on task change or activity orientation change
1113 // Note: all callbacks happen on main thread
1114
1115 @Override
1116 public void onTaskStackChanged() {
Mike Digman1e28a5a2018-02-14 10:49:19 -08001117 setRotateSuggestionButtonState(false);
Mike Digman7d092772018-01-11 12:10:32 -08001118 }
1119
1120 @Override
1121 public void onTaskRemoved(int taskId) {
Mike Digman1e28a5a2018-02-14 10:49:19 -08001122 setRotateSuggestionButtonState(false);
Mike Digman7d092772018-01-11 12:10:32 -08001123 }
1124
1125 @Override
1126 public void onTaskMovedToFront(int taskId) {
Mike Digman1e28a5a2018-02-14 10:49:19 -08001127 setRotateSuggestionButtonState(false);
Mike Digman7d092772018-01-11 12:10:32 -08001128 }
1129
1130 @Override
1131 public void onActivityRequestedOrientationChanged(int taskId, int requestedOrientation) {
Mike Digman85a9bea2018-02-23 15:08:53 -08001132 // Only hide the icon if the top task changes its requestedOrientation
1133 // Launcher can alter its requestedOrientation while it's not on top, don't hide on this
Mike Digman121b11f2018-04-04 12:45:24 -07001134 Optional.ofNullable(ActivityManagerWrapper.getInstance())
1135 .map(ActivityManagerWrapper::getRunningTask)
1136 .ifPresent(a -> {
1137 if (a.id == taskId) setRotateSuggestionButtonState(false);
1138 });
Mike Digman7d092772018-01-11 12:10:32 -08001139 }
1140 }
1141
Mike Digman50752642018-02-15 13:36:09 -08001142 private class ViewRippler {
1143 private static final int RIPPLE_OFFSET_MS = 50;
1144 private static final int RIPPLE_INTERVAL_MS = 2000;
1145 private View mRoot;
1146
1147 public void start(View root) {
1148 stop(); // Stop any pending ripple animations
1149
1150 mRoot = root;
1151
1152 // Schedule pending ripples, offset the 1st to avoid problems with visibility change
1153 mRoot.postOnAnimationDelayed(mRipple, RIPPLE_OFFSET_MS);
1154 mRoot.postOnAnimationDelayed(mRipple, RIPPLE_INTERVAL_MS);
1155 mRoot.postOnAnimationDelayed(mRipple, 2*RIPPLE_INTERVAL_MS);
Mike Digmanc038c322018-05-24 11:06:05 -07001156 mRoot.postOnAnimationDelayed(mRipple, 3*RIPPLE_INTERVAL_MS);
1157 mRoot.postOnAnimationDelayed(mRipple, 4*RIPPLE_INTERVAL_MS);
Mike Digman50752642018-02-15 13:36:09 -08001158 }
1159
1160 public void stop() {
1161 if (mRoot != null) mRoot.removeCallbacks(mRipple);
1162 }
1163
1164 private final Runnable mRipple = new Runnable() {
1165 @Override
1166 public void run() { // Cause the ripple to fire via false presses
Mike Digmanf4c98992018-04-25 11:25:59 -07001167 if (!mRoot.isAttachedToWindow()) return;
Mike Digman50752642018-02-15 13:36:09 -08001168 mRoot.setPressed(true);
1169 mRoot.setPressed(false);
1170 }
1171 };
1172 }
1173
Jason Monk49fa0162017-01-11 09:21:56 -05001174 public static View create(Context context, FragmentListener listener) {
1175 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1176 LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
1177 WindowManager.LayoutParams.TYPE_NAVIGATION_BAR,
1178 WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
1179 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1180 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
1181 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
1182 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
1183 | WindowManager.LayoutParams.FLAG_SLIPPERY,
1184 PixelFormat.TRANSLUCENT);
1185 lp.token = new Binder();
Jason Monk49fa0162017-01-11 09:21:56 -05001186 lp.setTitle("NavigationBar");
Phil Weaver8583ae82018-02-13 11:01:24 -08001187 lp.accessibilityTitle = context.getString(R.string.nav_bar);
Jason Monk49fa0162017-01-11 09:21:56 -05001188 lp.windowAnimations = 0;
1189
1190 View navigationBarView = LayoutInflater.from(context).inflate(
1191 R.layout.navigation_bar_window, null);
1192
1193 if (DEBUG) Log.v(TAG, "addNavigationBar: about to add " + navigationBarView);
1194 if (navigationBarView == null) return null;
1195
1196 context.getSystemService(WindowManager.class).addView(navigationBarView, lp);
1197 FragmentHostManager fragmentHost = FragmentHostManager.get(navigationBarView);
1198 NavigationBarFragment fragment = new NavigationBarFragment();
1199 fragmentHost.getFragmentManager().beginTransaction()
1200 .replace(R.id.navigation_bar_frame, fragment, TAG)
1201 .commit();
1202 fragmentHost.addTagListener(TAG, listener);
1203 return navigationBarView;
1204 }
1205}