blob: 66486cedcfb59c96d8ee3f4767426b3b1caa3d31 [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;
52import android.inputmethodservice.InputMethodService;
53import android.os.Binder;
54import android.os.Bundle;
55import android.os.Handler;
56import android.os.IBinder;
57import android.os.Message;
Jason Monk49fa0162017-01-11 09:21:56 -050058import android.os.RemoteException;
59import android.os.UserHandle;
Casey Burkhardt74922c62017-02-13 12:43:16 -080060import android.provider.Settings;
Aurimas Liutikasfd52c142018-04-17 09:50:46 -070061import androidx.annotation.VisibleForTesting;
Jason Monk49fa0162017-01-11 09:21:56 -050062import android.telecom.TelecomManager;
63import android.text.TextUtils;
64import android.util.Log;
65import android.view.IRotationWatcher.Stub;
66import android.view.KeyEvent;
67import android.view.LayoutInflater;
68import android.view.MotionEvent;
Mike Digman85ff7fa2018-01-23 14:59:52 -080069import android.view.Surface;
Jason Monk49fa0162017-01-11 09:21:56 -050070import android.view.View;
71import android.view.ViewGroup;
72import android.view.WindowManager;
73import android.view.WindowManager.LayoutParams;
74import android.view.WindowManagerGlobal;
75import android.view.accessibility.AccessibilityEvent;
76import android.view.accessibility.AccessibilityManager;
Jason Monk91e587e2017-04-13 13:41:23 -040077import android.view.accessibility.AccessibilityManager.AccessibilityServicesStateChangeListener;
Jason Monk49fa0162017-01-11 09:21:56 -050078
79import com.android.internal.logging.MetricsLogger;
80import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Jason Monkea03be12017-12-04 11:08:41 -050081import com.android.internal.util.LatencyTracker;
Jason Monk9c7844c2017-01-18 15:21:53 -050082import com.android.systemui.Dependency;
Mike Digman7d092772018-01-11 12:10:32 -080083import com.android.systemui.Interpolators;
Mike Digman1e28a5a2018-02-14 10:49:19 -080084import com.android.systemui.OverviewProxyService;
Jason Monk49fa0162017-01-11 09:21:56 -050085import com.android.systemui.R;
Jason Monk9c7844c2017-01-18 15:21:53 -050086import com.android.systemui.SysUiServiceProvider;
Jason Monk49fa0162017-01-11 09:21:56 -050087import com.android.systemui.assist.AssistManager;
88import com.android.systemui.fragments.FragmentHostManager;
89import com.android.systemui.fragments.FragmentHostManager.FragmentListener;
90import com.android.systemui.recents.Recents;
Mike Digman7d092772018-01-11 12:10:32 -080091import com.android.systemui.recents.misc.SysUiTaskStackChangeListener;
92import com.android.systemui.shared.system.ActivityManagerWrapper;
Jason Monk49fa0162017-01-11 09:21:56 -050093import com.android.systemui.stackdivider.Divider;
94import com.android.systemui.statusbar.CommandQueue;
95import com.android.systemui.statusbar.CommandQueue.Callbacks;
Jason Monk91e587e2017-04-13 13:41:23 -040096import com.android.systemui.statusbar.policy.AccessibilityManagerWrapper;
Mike Digman7d092772018-01-11 12:10:32 -080097import com.android.systemui.statusbar.policy.KeyButtonDrawable;
Jason Monk49fa0162017-01-11 09:21:56 -050098import com.android.systemui.statusbar.policy.KeyButtonView;
Mike Digman7d092772018-01-11 12:10:32 -080099import com.android.systemui.statusbar.policy.RotationLockController;
Rohan Shah20790b82018-07-02 17:21:04 -0700100import com.android.systemui.statusbar.notification.stack.StackStateAnimator;
Jason Monk49fa0162017-01-11 09:21:56 -0500101
102import java.io.FileDescriptor;
103import java.io.PrintWriter;
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800104import java.util.List;
Jason Monk49fa0162017-01-11 09:21:56 -0500105import java.util.Locale;
Mike Digman121b11f2018-04-04 12:45:24 -0700106import java.util.Optional;
Jason Monk49fa0162017-01-11 09:21:56 -0500107
108/**
109 * Fragment containing the NavigationBarFragment. Contains logic for what happens
110 * on clicks and view states of the nav bar.
111 */
112public class NavigationBarFragment extends Fragment implements Callbacks {
113
Jason Monkd4afe152017-05-01 15:37:43 -0400114 public static final String TAG = "NavigationBar";
Jason Monk49fa0162017-01-11 09:21:56 -0500115 private static final boolean DEBUG = false;
Mike Digman3e33da62018-03-14 16:25:11 -0700116 private static final boolean DEBUG_ROTATION = true;
Jason Monk49fa0162017-01-11 09:21:56 -0500117 private static final String EXTRA_DISABLE_STATE = "disabled_state";
Mike Digmandd2f49e2018-03-16 10:54:22 -0700118 private static final String EXTRA_DISABLE2_STATE = "disabled2_state";
Jason Monk49fa0162017-01-11 09:21:56 -0500119
Mike Digman1e28a5a2018-02-14 10:49:19 -0800120 private final static int BUTTON_FADE_IN_OUT_DURATION_MS = 100;
Mike Digman5aeca792018-03-05 11:14:39 -0800121 private final static int NAVBAR_HIDDEN_PENDING_ICON_TIMEOUT_MS = 20000;
Mike Digman1e28a5a2018-02-14 10:49:19 -0800122
Mike Digman50752642018-02-15 13:36:09 -0800123 private static final int NUM_ACCEPTED_ROTATION_SUGGESTIONS_FOR_INTRODUCTION = 3;
124
Jason Monk49fa0162017-01-11 09:21:56 -0500125 /** Allow some time inbetween the long press for back and recents. */
126 private static final int LOCK_TO_APP_GESTURE_TOLERENCE = 200;
127
128 protected NavigationBarView mNavigationBarView = null;
129 protected AssistManager mAssistManager;
130
131 private int mNavigationBarWindowState = WINDOW_STATE_SHOWING;
132
133 private int mNavigationIconHints = 0;
134 private int mNavigationBarMode;
Mike Digman90402952018-01-22 16:05:51 -0800135 private boolean mAccessibilityFeedbackEnabled;
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800136 private AccessibilityManager mAccessibilityManager;
Casey Burkhardt74922c62017-02-13 12:43:16 -0800137 private MagnificationContentObserver mMagnificationObserver;
Casey Burkhardtb9dcd662017-03-20 15:10:16 -0700138 private ContentResolver mContentResolver;
Mike Digmanc94759d2018-01-23 11:01:21 -0800139 private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class);
Jason Monk49fa0162017-01-11 09:21:56 -0500140
141 private int mDisabledFlags1;
Mike Digmandd2f49e2018-03-16 10:54:22 -0700142 private int mDisabledFlags2;
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500143 private StatusBar mStatusBar;
Jason Monk49fa0162017-01-11 09:21:56 -0500144 private Recents mRecents;
145 private Divider mDivider;
146 private WindowManager mWindowManager;
147 private CommandQueue mCommandQueue;
148 private long mLastLockToAppLongPress;
149
150 private Locale mLocale;
151 private int mLayoutDirection;
152
153 private int mSystemUiVisibility;
154 private LightBarController mLightBarController;
Jason Monk49fa0162017-01-11 09:21:56 -0500155
Matthew Ngdc79e5c2017-12-14 17:37:35 -0800156 private OverviewProxyService mOverviewProxyService;
157
Jason Monk49fa0162017-01-11 09:21:56 -0500158 public boolean mHomeBlockedThisTouch;
159
Mike Digman7d092772018-01-11 12:10:32 -0800160 private int mLastRotationSuggestion;
Mike Digman5aeca792018-03-05 11:14:39 -0800161 private boolean mPendingRotationSuggestion;
Mike Digman90402952018-01-22 16:05:51 -0800162 private boolean mHoveringRotationSuggestion;
Mike Digman7d092772018-01-11 12:10:32 -0800163 private RotationLockController mRotationLockController;
164 private TaskStackListenerImpl mTaskStackListener;
165
Mike Digman1e28a5a2018-02-14 10:49:19 -0800166 private final Runnable mRemoveRotationProposal = () -> setRotateSuggestionButtonState(false);
Mike Digman5aeca792018-03-05 11:14:39 -0800167 private final Runnable mCancelPendingRotationProposal =
168 () -> mPendingRotationSuggestion = false;
Mike Digman7d092772018-01-11 12:10:32 -0800169 private Animator mRotateHideAnimator;
Mike Digman50752642018-02-15 13:36:09 -0800170 private ViewRippler mViewRippler = new ViewRippler();
Mike Digman7d092772018-01-11 12:10:32 -0800171
Matthew Ng9c3bce52018-02-01 22:00:31 +0000172 private final OverviewProxyListener mOverviewProxyListener = new OverviewProxyListener() {
173 @Override
174 public void onConnectionChanged(boolean isConnected) {
Winson Chungf9e30272018-03-26 17:25:36 -0700175 mNavigationBarView.updateStates();
Matthew Ng9c3bce52018-02-01 22:00:31 +0000176 updateScreenPinningGestures();
177 }
178
179 @Override
Matthew Ng2ea93b72018-03-14 19:43:18 +0000180 public void onQuickStepStarted() {
Mike Digman85a9bea2018-02-23 15:08:53 -0800181 // Use navbar dragging as a signal to hide the rotate button
182 setRotateSuggestionButtonState(false);
Matthew Ng90ef0632018-08-15 13:53:15 -0700183
184 // Hide the notifications panel when quick step starts
185 mStatusBar.collapsePanel(true /* animate */);
Matthew Ng9c3bce52018-02-01 22:00:31 +0000186 }
Matthew Ng8f25fb962018-01-16 17:17:24 -0800187
188 @Override
189 public void onInteractionFlagsChanged(@InteractionType int flags) {
190 mNavigationBarView.updateStates();
Winson Chungf9e30272018-03-26 17:25:36 -0700191 updateScreenPinningGestures();
Matthew Ng8f25fb962018-01-16 17:17:24 -0800192 }
Matthew Ng96985e72018-05-08 15:46:13 -0700193
194 @Override
195 public void onBackButtonAlphaChanged(float alpha, boolean animate) {
196 final ButtonDispatcher backButton = mNavigationBarView.getBackButton();
Matthew Ngc83b9892018-08-21 16:31:13 -0700197 if (QuickStepController.shouldhideBackButton()) {
198 // If property was changed to hide/show back button, going home will trigger
199 // launcher to to change the back button alpha to reflect property change
200 backButton.setVisibility(View.GONE);
201 } else {
202 backButton.setVisibility(alpha > 0 ? View.VISIBLE : View.INVISIBLE);
203 backButton.setAlpha(alpha, animate);
204 }
Matthew Ng96985e72018-05-08 15:46:13 -0700205 }
Matthew Ng9c3bce52018-02-01 22:00:31 +0000206 };
Mike Digman7d092772018-01-11 12:10:32 -0800207
Jason Monk49fa0162017-01-11 09:21:56 -0500208 // ----- Fragment Lifecycle Callbacks -----
209
210 @Override
211 public void onCreate(@Nullable Bundle savedInstanceState) {
212 super.onCreate(savedInstanceState);
Jason Monk9c7844c2017-01-18 15:21:53 -0500213 mCommandQueue = SysUiServiceProvider.getComponent(getContext(), CommandQueue.class);
Jason Monk49fa0162017-01-11 09:21:56 -0500214 mCommandQueue.addCallbacks(this);
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500215 mStatusBar = SysUiServiceProvider.getComponent(getContext(), StatusBar.class);
Jason Monk9c7844c2017-01-18 15:21:53 -0500216 mRecents = SysUiServiceProvider.getComponent(getContext(), Recents.class);
217 mDivider = SysUiServiceProvider.getComponent(getContext(), Divider.class);
Jason Monk49fa0162017-01-11 09:21:56 -0500218 mWindowManager = getContext().getSystemService(WindowManager.class);
219 mAccessibilityManager = getContext().getSystemService(AccessibilityManager.class);
Jason Monk91e587e2017-04-13 13:41:23 -0400220 Dependency.get(AccessibilityManagerWrapper.class).addCallback(
221 mAccessibilityListener);
Casey Burkhardtb9dcd662017-03-20 15:10:16 -0700222 mContentResolver = getContext().getContentResolver();
Casey Burkhardt74922c62017-02-13 12:43:16 -0800223 mMagnificationObserver = new MagnificationContentObserver(
224 getContext().getMainThreadHandler());
Casey Burkhardtb9dcd662017-03-20 15:10:16 -0700225 mContentResolver.registerContentObserver(Settings.Secure.getUriFor(
Casey Burkhardt74922c62017-02-13 12:43:16 -0800226 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED), false,
Casey Burkhardt5d614402017-04-06 13:46:50 -0700227 mMagnificationObserver, UserHandle.USER_ALL);
Casey Burkhardt74922c62017-02-13 12:43:16 -0800228
Jason Monk49fa0162017-01-11 09:21:56 -0500229 if (savedInstanceState != null) {
230 mDisabledFlags1 = savedInstanceState.getInt(EXTRA_DISABLE_STATE, 0);
Mike Digmandd2f49e2018-03-16 10:54:22 -0700231 mDisabledFlags2 = savedInstanceState.getInt(EXTRA_DISABLE2_STATE, 0);
Jason Monk49fa0162017-01-11 09:21:56 -0500232 }
Jason Monk9c7844c2017-01-18 15:21:53 -0500233 mAssistManager = Dependency.get(AssistManager.class);
Matthew Ngdc79e5c2017-12-14 17:37:35 -0800234 mOverviewProxyService = Dependency.get(OverviewProxyService.class);
Jason Monk49fa0162017-01-11 09:21:56 -0500235
236 try {
237 WindowManagerGlobal.getWindowManagerService()
Andrii Kulian35fa3c22017-03-11 09:37:28 -0800238 .watchRotation(mRotationWatcher, getContext().getDisplay().getDisplayId());
Jason Monk49fa0162017-01-11 09:21:56 -0500239 } catch (RemoteException e) {
240 throw e.rethrowFromSystemServer();
241 }
Mike Digman7d092772018-01-11 12:10:32 -0800242
243 mRotationLockController = Dependency.get(RotationLockController.class);
244
Mike Digmanab650252018-03-06 11:01:41 -0800245 // Reset user rotation pref to match that of the WindowManager if starting in locked mode
246 // This will automatically happen when switching from auto-rotate to locked mode
247 if (mRotationLockController.isRotationLocked()) {
248 final int winRotation = mWindowManager.getDefaultDisplay().getRotation();
249 mRotationLockController.setRotationLockedAtAngle(true, winRotation);
250 }
251
Mike Digman7d092772018-01-11 12:10:32 -0800252 // Register the task stack listener
253 mTaskStackListener = new TaskStackListenerImpl();
254 ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener);
Jason Monk49fa0162017-01-11 09:21:56 -0500255 }
256
257 @Override
258 public void onDestroy() {
259 super.onDestroy();
260 mCommandQueue.removeCallbacks(this);
Jason Monk91e587e2017-04-13 13:41:23 -0400261 Dependency.get(AccessibilityManagerWrapper.class).removeCallback(
262 mAccessibilityListener);
Casey Burkhardtb9dcd662017-03-20 15:10:16 -0700263 mContentResolver.unregisterContentObserver(mMagnificationObserver);
Jason Monk49fa0162017-01-11 09:21:56 -0500264 try {
265 WindowManagerGlobal.getWindowManagerService()
266 .removeRotationWatcher(mRotationWatcher);
267 } catch (RemoteException e) {
268 throw e.rethrowFromSystemServer();
269 }
Mike Digman7d092772018-01-11 12:10:32 -0800270
271 // Unregister the task stack listener
272 ActivityManagerWrapper.getInstance().unregisterTaskStackListener(mTaskStackListener);
Jason Monk49fa0162017-01-11 09:21:56 -0500273 }
274
275 @Override
276 public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
277 Bundle savedInstanceState) {
278 return inflater.inflate(R.layout.navigation_bar, container, false);
279 }
280
281 @Override
282 public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
283 super.onViewCreated(view, savedInstanceState);
284 mNavigationBarView = (NavigationBarView) view;
285
286 mNavigationBarView.setDisabledFlags(mDisabledFlags1);
Matthew Ng78f88d12018-01-23 12:39:55 -0800287 mNavigationBarView.setComponents(mRecents, mDivider, mStatusBar.getPanel());
Jason Monk49fa0162017-01-11 09:21:56 -0500288 mNavigationBarView.setOnVerticalChangedListener(this::onVerticalChanged);
289 mNavigationBarView.setOnTouchListener(this::onNavigationTouch);
290 if (savedInstanceState != null) {
291 mNavigationBarView.getLightTransitionsController().restoreState(savedInstanceState);
292 }
293
294 prepareNavigationBarView();
295 checkNavBarModes();
296
Mike Digmandd2f49e2018-03-16 10:54:22 -0700297 setDisabled2Flags(mDisabledFlags2);
298
Jason Monk49fa0162017-01-11 09:21:56 -0500299 IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
300 filter.addAction(Intent.ACTION_SCREEN_ON);
Phil Weavera858c5f2018-04-26 13:27:30 -0700301 filter.addAction(Intent.ACTION_USER_SWITCHED);
Jason Monk49fa0162017-01-11 09:21:56 -0500302 getContext().registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, filter, null, null);
Siarhei Vishniakoud002a0a2017-06-05 22:44:37 +0100303 notifyNavigationBarScreenOn();
Matthew Ng9c3bce52018-02-01 22:00:31 +0000304 mOverviewProxyService.addCallback(mOverviewProxyListener);
Jason Monk49fa0162017-01-11 09:21:56 -0500305 }
306
307 @Override
308 public void onDestroyView() {
309 super.onDestroyView();
Winson Chungb03d44d2018-09-18 12:42:45 -0700310 if (mNavigationBarView != null) {
311 mNavigationBarView.getBarTransitions().destroy();
312 mNavigationBarView.getLightTransitionsController().destroy(getContext());
313 }
Matthew Ng9c3bce52018-02-01 22:00:31 +0000314 mOverviewProxyService.removeCallback(mOverviewProxyListener);
Jason Monk49fa0162017-01-11 09:21:56 -0500315 getContext().unregisterReceiver(mBroadcastReceiver);
316 }
317
318 @Override
319 public void onSaveInstanceState(Bundle outState) {
320 super.onSaveInstanceState(outState);
321 outState.putInt(EXTRA_DISABLE_STATE, mDisabledFlags1);
Mike Digmandd2f49e2018-03-16 10:54:22 -0700322 outState.putInt(EXTRA_DISABLE2_STATE, mDisabledFlags2);
Jason Monk49fa0162017-01-11 09:21:56 -0500323 if (mNavigationBarView != null) {
324 mNavigationBarView.getLightTransitionsController().saveState(outState);
325 }
326 }
327
328 @Override
329 public void onConfigurationChanged(Configuration newConfig) {
330 super.onConfigurationChanged(newConfig);
331 final Locale locale = getContext().getResources().getConfiguration().locale;
332 final int ld = TextUtils.getLayoutDirectionFromLocale(locale);
333 if (!locale.equals(mLocale) || ld != mLayoutDirection) {
334 if (DEBUG) {
335 Log.v(TAG, String.format(
336 "config changed locale/LD: %s (%d) -> %s (%d)", mLocale, mLayoutDirection,
337 locale, ld));
338 }
339 mLocale = locale;
340 mLayoutDirection = ld;
341 refreshLayout(ld);
342 }
343 repositionNavigationBar();
344 }
345
346 @Override
347 public void dump(String prefix, FileDescriptor fd, PrintWriter pw, String[] args) {
348 if (mNavigationBarView != null) {
349 pw.print(" mNavigationBarWindowState=");
350 pw.println(windowStateToString(mNavigationBarWindowState));
351 pw.print(" mNavigationBarMode=");
352 pw.println(BarTransitions.modeToString(mNavigationBarMode));
353 dumpBarTransitions(pw, "mNavigationBarView", mNavigationBarView.getBarTransitions());
354 }
355
356 pw.print(" mNavigationBarView=");
357 if (mNavigationBarView == null) {
358 pw.println("null");
359 } else {
360 mNavigationBarView.dump(fd, pw, args);
361 }
362 }
363
364 // ----- CommandQueue Callbacks -----
365
366 @Override
367 public void setImeWindowStatus(IBinder token, int vis, int backDisposition,
368 boolean showImeSwitcher) {
369 boolean imeShown = (vis & InputMethodService.IME_VISIBLE) != 0;
370 int hints = mNavigationIconHints;
Yohei Yukawa386f50e2018-03-14 13:03:42 -0700371 switch (backDisposition) {
372 case InputMethodService.BACK_DISPOSITION_DEFAULT:
373 case InputMethodService.BACK_DISPOSITION_WILL_NOT_DISMISS:
374 case InputMethodService.BACK_DISPOSITION_WILL_DISMISS:
375 if (imeShown) {
376 hints |= NAVIGATION_HINT_BACK_ALT;
377 } else {
378 hints &= ~NAVIGATION_HINT_BACK_ALT;
379 }
380 break;
381 case InputMethodService.BACK_DISPOSITION_ADJUST_NOTHING:
382 hints &= ~NAVIGATION_HINT_BACK_ALT;
383 break;
Jason Monk49fa0162017-01-11 09:21:56 -0500384 }
385 if (showImeSwitcher) {
386 hints |= NAVIGATION_HINT_IME_SHOWN;
387 } else {
388 hints &= ~NAVIGATION_HINT_IME_SHOWN;
389 }
390 if (hints == mNavigationIconHints) return;
391
392 mNavigationIconHints = hints;
393
394 if (mNavigationBarView != null) {
395 mNavigationBarView.setNavigationIconHints(hints);
396 }
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500397 mStatusBar.checkBarModes();
Jason Monk49fa0162017-01-11 09:21:56 -0500398 }
399
400 @Override
401 public void topAppWindowChanged(boolean showMenu) {
402 if (mNavigationBarView != null) {
403 mNavigationBarView.setMenuVisibility(showMenu);
404 }
405 }
406
407 @Override
408 public void setWindowState(int window, int state) {
409 if (mNavigationBarView != null
410 && window == StatusBarManager.WINDOW_NAVIGATION_BAR
411 && mNavigationBarWindowState != state) {
412 mNavigationBarWindowState = state;
413 if (DEBUG_WINDOW_STATE) Log.d(TAG, "Navigation bar " + windowStateToString(state));
Mike Digman5aeca792018-03-05 11:14:39 -0800414
415 // If the navbar is visible, show the rotate button if there's a pending suggestion
416 if (state == WINDOW_STATE_SHOWING && mPendingRotationSuggestion) {
417 showAndLogRotationSuggestion();
418 }
Jason Monk49fa0162017-01-11 09:21:56 -0500419 }
420 }
421
Mike Digman7d092772018-01-11 12:10:32 -0800422 @Override
Mike Digmane0777312018-01-19 12:41:51 -0800423 public void onRotationProposal(final int rotation, boolean isValid) {
Mike Digman3e33da62018-03-14 16:25:11 -0700424 final int winRotation = mWindowManager.getDefaultDisplay().getRotation();
Mike Digmandd2f49e2018-03-16 10:54:22 -0700425 final boolean rotateSuggestionsDisabled = hasDisable2RotateSuggestionFlag(mDisabledFlags2);
Mike Digman3e33da62018-03-14 16:25:11 -0700426 if (DEBUG_ROTATION) {
427 Log.v(TAG, "onRotationProposal proposedRotation=" + Surface.rotationToString(rotation)
428 + ", winRotation=" + Surface.rotationToString(winRotation)
429 + ", isValid=" + isValid + ", mNavBarWindowState="
430 + StatusBarManager.windowStateToString(mNavigationBarWindowState)
Mike Digmandd2f49e2018-03-16 10:54:22 -0700431 + ", rotateSuggestionsDisabled=" + rotateSuggestionsDisabled
Mike Digman3e33da62018-03-14 16:25:11 -0700432 + ", isRotateButtonVisible=" + (mNavigationBarView == null ? "null" :
433 mNavigationBarView.isRotateButtonVisible()));
434 }
435
Mike Digmandd2f49e2018-03-16 10:54:22 -0700436 // Respect the disabled flag, no need for action as flag change callback will handle hiding
437 if (rotateSuggestionsDisabled) return;
438
Mike Digmane0777312018-01-19 12:41:51 -0800439 // This method will be called on rotation suggestion changes even if the proposed rotation
440 // is not valid for the top app. Use invalid rotation choices as a signal to remove the
441 // rotate button if shown.
Mike Digmane0777312018-01-19 12:41:51 -0800442 if (!isValid) {
Mike Digman1e28a5a2018-02-14 10:49:19 -0800443 setRotateSuggestionButtonState(false);
Mike Digmane0777312018-01-19 12:41:51 -0800444 return;
445 }
446
Mike Digman5aeca792018-03-05 11:14:39 -0800447 // If window rotation matches suggested rotation, remove any current suggestions
Mike Digman1e28a5a2018-02-14 10:49:19 -0800448 if (rotation == winRotation) {
Mike Digman5aeca792018-03-05 11:14:39 -0800449 getView().removeCallbacks(mRemoveRotationProposal);
Mike Digman1e28a5a2018-02-14 10:49:19 -0800450 setRotateSuggestionButtonState(false);
Mike Digman5aeca792018-03-05 11:14:39 -0800451 return;
Mike Digman7d092772018-01-11 12:10:32 -0800452 }
Mike Digman5aeca792018-03-05 11:14:39 -0800453
454 // Prepare to show the navbar icon by updating the icon style to change anim params
455 mLastRotationSuggestion = rotation; // Remember rotation for click
456 if (mNavigationBarView != null) {
457 final boolean rotationCCW = isRotationAnimationCCW(winRotation, rotation);
458 int style;
459 if (winRotation == Surface.ROTATION_0 || winRotation == Surface.ROTATION_180) {
460 style = rotationCCW ? R.style.RotateButtonCCWStart90 :
461 R.style.RotateButtonCWStart90;
462 } else { // 90 or 270
463 style = rotationCCW ? R.style.RotateButtonCCWStart0 :
464 R.style.RotateButtonCWStart0;
465 }
466 mNavigationBarView.updateRotateSuggestionButtonStyle(style, true);
467 }
468
469 if (mNavigationBarWindowState != WINDOW_STATE_SHOWING) {
470 // If the navbar isn't shown, flag the rotate icon to be shown should the navbar become
471 // visible given some time limit.
472 mPendingRotationSuggestion = true;
473 getView().removeCallbacks(mCancelPendingRotationProposal);
474 getView().postDelayed(mCancelPendingRotationProposal,
475 NAVBAR_HIDDEN_PENDING_ICON_TIMEOUT_MS);
476
477 } else { // The navbar is visible so show the icon right away
478 showAndLogRotationSuggestion();
479 }
480 }
481
Mike Digmandd2f49e2018-03-16 10:54:22 -0700482 private void onRotationSuggestionsDisabled() {
483 // Immediately hide the rotate button and clear any planned removal
484 setRotateSuggestionButtonState(false, true);
Mike Digmane14c4752018-03-20 12:14:54 -0700485
486 // This method can be called before view setup is done, ensure getView isn't null
487 final View v = getView();
488 if (v != null) v.removeCallbacks(mRemoveRotationProposal);
Mike Digmandd2f49e2018-03-16 10:54:22 -0700489 }
490
Mike Digman5aeca792018-03-05 11:14:39 -0800491 private void showAndLogRotationSuggestion() {
492 setRotateSuggestionButtonState(true);
493 rescheduleRotationTimeout(false);
494 mMetricsLogger.visible(MetricsEvent.ROTATION_SUGGESTION_SHOWN);
Mike Digman7d092772018-01-11 12:10:32 -0800495 }
496
Mike Digman1e28a5a2018-02-14 10:49:19 -0800497 private boolean isRotationAnimationCCW(int from, int to) {
498 // All 180deg WM rotation animations are CCW, match that
499 if (from == Surface.ROTATION_0 && to == Surface.ROTATION_90) return false;
500 if (from == Surface.ROTATION_0 && to == Surface.ROTATION_180) return true; //180d so CCW
501 if (from == Surface.ROTATION_0 && to == Surface.ROTATION_270) return true;
502 if (from == Surface.ROTATION_90 && to == Surface.ROTATION_0) return true;
503 if (from == Surface.ROTATION_90 && to == Surface.ROTATION_180) return false;
504 if (from == Surface.ROTATION_90 && to == Surface.ROTATION_270) return true; //180d so CCW
505 if (from == Surface.ROTATION_180 && to == Surface.ROTATION_0) return true; //180d so CCW
506 if (from == Surface.ROTATION_180 && to == Surface.ROTATION_90) return true;
507 if (from == Surface.ROTATION_180 && to == Surface.ROTATION_270) return false;
508 if (from == Surface.ROTATION_270 && to == Surface.ROTATION_0) return false;
509 if (from == Surface.ROTATION_270 && to == Surface.ROTATION_90) return true; //180d so CCW
510 if (from == Surface.ROTATION_270 && to == Surface.ROTATION_180) return true;
511 return false; // Default
Mike Digmana48cf192018-02-12 17:52:48 -0800512 }
513
Mike Digman1e28a5a2018-02-14 10:49:19 -0800514 public void setRotateSuggestionButtonState(final boolean visible) {
515 setRotateSuggestionButtonState(visible, false);
516 }
517
518 public void setRotateSuggestionButtonState(final boolean visible, final boolean force) {
519 if (mNavigationBarView == null) return;
520
521 // At any point the the button can become invisible because an a11y service became active.
522 // Similarly, a call to make the button visible may be rejected because an a11y service is
523 // active. Must account for this.
524
525 ButtonDispatcher rotBtn = mNavigationBarView.getRotateSuggestionButton();
526 final boolean currentlyVisible = mNavigationBarView.isRotateButtonVisible();
527
528 // Rerun a show animation to indicate change but don't rerun a hide animation
529 if (!visible && !currentlyVisible) return;
530
531 View view = rotBtn.getCurrentView();
532 if (view == null) return;
533
534 KeyButtonDrawable kbd = rotBtn.getImageDrawable();
535 if (kbd == null) return;
536
Mike Digman5aeca792018-03-05 11:14:39 -0800537 // Clear any pending suggestion flag as it has either been nullified or is being shown
538 mPendingRotationSuggestion = false;
Mike Digmanf4c98992018-04-25 11:25:59 -0700539 if (getView() != null) getView().removeCallbacks(mCancelPendingRotationProposal);
Mike Digman5aeca792018-03-05 11:14:39 -0800540
541 // Handle the visibility change and animation
Mike Digman1e28a5a2018-02-14 10:49:19 -0800542 if (visible) { // Appear and change (cannot force)
Mike Digman85a9bea2018-02-23 15:08:53 -0800543 // Stop and clear any currently running hide animations
Mike Digman1e28a5a2018-02-14 10:49:19 -0800544 if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) {
Mike Digman85a9bea2018-02-23 15:08:53 -0800545 mRotateHideAnimator.cancel();
Mike Digman1e28a5a2018-02-14 10:49:19 -0800546 }
Mike Digman85a9bea2018-02-23 15:08:53 -0800547 mRotateHideAnimator = null;
Mike Digman1e28a5a2018-02-14 10:49:19 -0800548
549 // Reset the alpha if any has changed due to hide animation
550 view.setAlpha(1f);
551
552 // Run the rotate icon's animation if it has one
Matthew Ngd6865ba2018-08-27 17:58:41 -0700553 if (kbd.canAnimate()) {
554 kbd.resetAnimation();
555 kbd.startAnimation();
Mike Digman1e28a5a2018-02-14 10:49:19 -0800556 }
557
Mike Digman50752642018-02-15 13:36:09 -0800558 if (!isRotateSuggestionIntroduced()) mViewRippler.start(view);
559
Mike Digman1e28a5a2018-02-14 10:49:19 -0800560 // Set visibility, may fail if a11y service is active.
561 // If invisible, call will stop animation.
Mike Digman9b50b762018-04-19 10:50:35 -0700562 int appliedVisibility = mNavigationBarView.setRotateButtonVisibility(true);
563 if (appliedVisibility == View.VISIBLE) {
564 // If the button will actually become visible and the navbar is about to hide,
565 // tell the statusbar to keep it around for longer
566 mStatusBar.touchAutoHide();
567 }
Mike Digman1e28a5a2018-02-14 10:49:19 -0800568
569 } else { // Hide
570
Mike Digman50752642018-02-15 13:36:09 -0800571 mViewRippler.stop(); // Prevent any pending ripples, force hide or not
572
Mike Digman1e28a5a2018-02-14 10:49:19 -0800573 if (force) {
574 // If a hide animator is running stop it and make invisible
575 if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) {
576 mRotateHideAnimator.pause();
577 }
578 mNavigationBarView.setRotateButtonVisibility(false);
579 return;
580 }
581
582 // Don't start any new hide animations if one is running
583 if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) return;
584
585 ObjectAnimator fadeOut = ObjectAnimator.ofFloat(view, "alpha",
586 0f);
587 fadeOut.setDuration(BUTTON_FADE_IN_OUT_DURATION_MS);
588 fadeOut.setInterpolator(Interpolators.LINEAR);
589 fadeOut.addListener(new AnimatorListenerAdapter() {
590 @Override
591 public void onAnimationEnd(Animator animation) {
592 mNavigationBarView.setRotateButtonVisibility(false);
593 }
594 });
595
596 mRotateHideAnimator = fadeOut;
597 fadeOut.start();
Mike Digmana48cf192018-02-12 17:52:48 -0800598 }
599 }
600
Mike Digman90402952018-01-22 16:05:51 -0800601 private void rescheduleRotationTimeout(final boolean reasonHover) {
602 // May be called due to a new rotation proposal or a change in hover state
603 if (reasonHover) {
604 // Don't reschedule if a hide animator is running
Mike Digman1e28a5a2018-02-14 10:49:19 -0800605 if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) return;
Mike Digman90402952018-01-22 16:05:51 -0800606 // Don't reschedule if not visible
Mike Digman1e28a5a2018-02-14 10:49:19 -0800607 if (!mNavigationBarView.isRotateButtonVisible()) return;
Mike Digman90402952018-01-22 16:05:51 -0800608 }
609
Mike Digman5aeca792018-03-05 11:14:39 -0800610 getView().removeCallbacks(mRemoveRotationProposal); // Stop any pending removal
611 getView().postDelayed(mRemoveRotationProposal,
Mike Digman90402952018-01-22 16:05:51 -0800612 computeRotationProposalTimeout()); // Schedule timeout
613 }
614
615 private int computeRotationProposalTimeout() {
616 if (mAccessibilityFeedbackEnabled) return 20000;
617 if (mHoveringRotationSuggestion) return 16000;
Mike Digmand13e43b2018-05-21 11:23:56 -0700618 return 10000;
Mike Digman90402952018-01-22 16:05:51 -0800619 }
620
Mike Digman50752642018-02-15 13:36:09 -0800621 private boolean isRotateSuggestionIntroduced() {
622 ContentResolver cr = getContext().getContentResolver();
623 return Settings.Secure.getInt(cr, Settings.Secure.NUM_ROTATION_SUGGESTIONS_ACCEPTED, 0)
624 >= NUM_ACCEPTED_ROTATION_SUGGESTIONS_FOR_INTRODUCTION;
625 }
626
627 private void incrementNumAcceptedRotationSuggestionsIfNeeded() {
628 // Get the number of accepted suggestions
629 ContentResolver cr = getContext().getContentResolver();
630 final int numSuggestions = Settings.Secure.getInt(cr,
631 Settings.Secure.NUM_ROTATION_SUGGESTIONS_ACCEPTED, 0);
632
633 // Increment the number of accepted suggestions only if it would change intro mode
634 if (numSuggestions < NUM_ACCEPTED_ROTATION_SUGGESTIONS_FOR_INTRODUCTION) {
635 Settings.Secure.putInt(cr, Settings.Secure.NUM_ROTATION_SUGGESTIONS_ACCEPTED,
636 numSuggestions + 1);
637 }
638 }
639
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500640 // Injected from StatusBar at creation.
Jason Monk49fa0162017-01-11 09:21:56 -0500641 public void setCurrentSysuiVisibility(int systemUiVisibility) {
642 mSystemUiVisibility = systemUiVisibility;
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500643 mNavigationBarMode = mStatusBar.computeBarMode(0, mSystemUiVisibility,
Jason Monk49fa0162017-01-11 09:21:56 -0500644 View.NAVIGATION_BAR_TRANSIENT, View.NAVIGATION_BAR_TRANSLUCENT,
645 View.NAVIGATION_BAR_TRANSPARENT);
646 checkNavBarModes();
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500647 mStatusBar.touchAutoHide();
Jason Monk49fa0162017-01-11 09:21:56 -0500648 mLightBarController.onNavigationVisibilityChanged(mSystemUiVisibility, 0 /* mask */,
649 true /* nbModeChanged */, mNavigationBarMode);
650 }
651
652 @Override
653 public void setSystemUiVisibility(int vis, int fullscreenStackVis, int dockedStackVis,
654 int mask, Rect fullscreenStackBounds, Rect dockedStackBounds) {
655 final int oldVal = mSystemUiVisibility;
656 final int newVal = (oldVal & ~mask) | (vis & mask);
657 final int diff = newVal ^ oldVal;
658 boolean nbModeChanged = false;
659 if (diff != 0) {
660 mSystemUiVisibility = newVal;
661
662 // update navigation bar mode
663 final int nbMode = getView() == null
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500664 ? -1 : mStatusBar.computeBarMode(oldVal, newVal,
Jason Monk49fa0162017-01-11 09:21:56 -0500665 View.NAVIGATION_BAR_TRANSIENT, View.NAVIGATION_BAR_TRANSLUCENT,
666 View.NAVIGATION_BAR_TRANSPARENT);
667 nbModeChanged = nbMode != -1;
668 if (nbModeChanged) {
669 if (mNavigationBarMode != nbMode) {
Tracy Zhou1ac592c2018-07-25 13:47:37 -0700670 if (mNavigationBarMode == MODE_TRANSPARENT
671 || mNavigationBarMode == MODE_LIGHTS_OUT_TRANSPARENT) {
672 mNavigationBarView.hideRecentsOnboarding();
673 }
Jason Monk49fa0162017-01-11 09:21:56 -0500674 mNavigationBarMode = nbMode;
675 checkNavBarModes();
676 }
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500677 mStatusBar.touchAutoHide();
Jason Monk49fa0162017-01-11 09:21:56 -0500678 }
679 }
680
681 mLightBarController.onNavigationVisibilityChanged(vis, mask, nbModeChanged,
682 mNavigationBarMode);
683 }
684
685 @Override
686 public void disable(int state1, int state2, boolean animate) {
Mike Digmandd2f49e2018-03-16 10:54:22 -0700687 // Navigation bar flags are in both state1 and state2.
688 final int masked = state1 & (StatusBarManager.DISABLE_HOME
Jason Monk49fa0162017-01-11 09:21:56 -0500689 | StatusBarManager.DISABLE_RECENT
690 | StatusBarManager.DISABLE_BACK
691 | StatusBarManager.DISABLE_SEARCH);
692 if (masked != mDisabledFlags1) {
693 mDisabledFlags1 = masked;
694 if (mNavigationBarView != null) mNavigationBarView.setDisabledFlags(state1);
Matthew Ng9c3bce52018-02-01 22:00:31 +0000695 updateScreenPinningGestures();
Jason Monk49fa0162017-01-11 09:21:56 -0500696 }
Mike Digmandd2f49e2018-03-16 10:54:22 -0700697
698 final int masked2 = state2 & (StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS);
699 if (masked2 != mDisabledFlags2) {
700 mDisabledFlags2 = masked2;
701 setDisabled2Flags(masked2);
702 }
703 }
704
705 private void setDisabled2Flags(int state2) {
706 // Method only called on change of disable2 flags
707 final boolean rotateSuggestionsDisabled = hasDisable2RotateSuggestionFlag(state2);
708 if (rotateSuggestionsDisabled) onRotationSuggestionsDisabled();
709 }
710
711 private boolean hasDisable2RotateSuggestionFlag(int disable2Flags) {
712 return (disable2Flags & StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS) != 0;
Jason Monk49fa0162017-01-11 09:21:56 -0500713 }
714
715 // ----- Internal stuffz -----
716
717 private void refreshLayout(int layoutDirection) {
718 if (mNavigationBarView != null) {
719 mNavigationBarView.setLayoutDirection(layoutDirection);
720 }
721 }
722
723 private boolean shouldDisableNavbarGestures() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500724 return !mStatusBar.isDeviceProvisioned()
Matthew Ngfee0b5b2018-02-21 15:38:21 -0800725 || (mDisabledFlags1 & StatusBarManager.DISABLE_SEARCH) != 0;
Jason Monk49fa0162017-01-11 09:21:56 -0500726 }
727
728 private void repositionNavigationBar() {
729 if (mNavigationBarView == null || !mNavigationBarView.isAttachedToWindow()) return;
730
731 prepareNavigationBarView();
732
733 mWindowManager.updateViewLayout((View) mNavigationBarView.getParent(),
734 ((View) mNavigationBarView.getParent()).getLayoutParams());
735 }
736
Matthew Ng9c3bce52018-02-01 22:00:31 +0000737 private void updateScreenPinningGestures() {
738 if (mNavigationBarView == null) {
739 return;
740 }
741
742 // Change the cancel pin gesture to home and back if recents button is invisible
743 boolean recentsVisible = mNavigationBarView.isRecentsButtonVisible();
Matthew Ng9c3bce52018-02-01 22:00:31 +0000744 ButtonDispatcher backButton = mNavigationBarView.getBackButton();
745 if (recentsVisible) {
Matthew Ng9c3bce52018-02-01 22:00:31 +0000746 backButton.setOnLongClickListener(this::onLongPressBackRecents);
747 } else {
Matthew Ng9c3bce52018-02-01 22:00:31 +0000748 backButton.setOnLongClickListener(this::onLongPressBackHome);
749 }
750 }
751
Siarhei Vishniakoud002a0a2017-06-05 22:44:37 +0100752 private void notifyNavigationBarScreenOn() {
Matthew Ngd0a73e72018-03-02 15:16:03 -0800753 mNavigationBarView.updateNavButtonIcons();
Jason Monk49fa0162017-01-11 09:21:56 -0500754 }
755
756 private void prepareNavigationBarView() {
757 mNavigationBarView.reorient();
758
759 ButtonDispatcher recentsButton = mNavigationBarView.getRecentsButton();
760 recentsButton.setOnClickListener(this::onRecentsClick);
761 recentsButton.setOnTouchListener(this::onRecentsTouch);
762 recentsButton.setLongClickable(true);
763 recentsButton.setOnLongClickListener(this::onLongPressBackRecents);
764
765 ButtonDispatcher backButton = mNavigationBarView.getBackButton();
766 backButton.setLongClickable(true);
Jason Monk49fa0162017-01-11 09:21:56 -0500767
768 ButtonDispatcher homeButton = mNavigationBarView.getHomeButton();
769 homeButton.setOnTouchListener(this::onHomeTouch);
Matthew Ngfee0b5b2018-02-21 15:38:21 -0800770 homeButton.setOnLongClickListener(this::onHomeLongClick);
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800771
772 ButtonDispatcher accessibilityButton = mNavigationBarView.getAccessibilityButton();
773 accessibilityButton.setOnClickListener(this::onAccessibilityClick);
774 accessibilityButton.setOnLongClickListener(this::onAccessibilityLongClick);
Phil Weaverdb9a7742017-04-18 08:15:06 -0700775 updateAccessibilityServicesState(mAccessibilityManager);
Mike Digman7d092772018-01-11 12:10:32 -0800776
777 ButtonDispatcher rotateSuggestionButton = mNavigationBarView.getRotateSuggestionButton();
778 rotateSuggestionButton.setOnClickListener(this::onRotateSuggestionClick);
Mike Digman90402952018-01-22 16:05:51 -0800779 rotateSuggestionButton.setOnHoverListener(this::onRotateSuggestionHover);
Matthew Ng9c3bce52018-02-01 22:00:31 +0000780 updateScreenPinningGestures();
Jason Monk49fa0162017-01-11 09:21:56 -0500781 }
782
783 private boolean onHomeTouch(View v, MotionEvent event) {
784 if (mHomeBlockedThisTouch && event.getActionMasked() != MotionEvent.ACTION_DOWN) {
785 return true;
786 }
787 // If an incoming call is ringing, HOME is totally disabled.
788 // (The user is already on the InCallUI at this point,
789 // and his ONLY options are to answer or reject the call.)
790 switch (event.getAction()) {
791 case MotionEvent.ACTION_DOWN:
792 mHomeBlockedThisTouch = false;
793 TelecomManager telecomManager =
794 getContext().getSystemService(TelecomManager.class);
795 if (telecomManager != null && telecomManager.isRinging()) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500796 if (mStatusBar.isKeyguardShowing()) {
Jason Monk49fa0162017-01-11 09:21:56 -0500797 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call. " +
798 "No heads up");
799 mHomeBlockedThisTouch = true;
800 return true;
801 }
802 }
803 break;
804 case MotionEvent.ACTION_UP:
805 case MotionEvent.ACTION_CANCEL:
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500806 mStatusBar.awakenDreams();
Jason Monk49fa0162017-01-11 09:21:56 -0500807 break;
808 }
809 return false;
810 }
811
812 private void onVerticalChanged(boolean isVertical) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500813 mStatusBar.setQsScrimEnabled(!isVertical);
Jason Monk49fa0162017-01-11 09:21:56 -0500814 }
815
816 private boolean onNavigationTouch(View v, MotionEvent event) {
Eliot Courtneycb5d3162017-08-09 16:53:15 +0900817 mStatusBar.checkUserAutohide(event);
Jason Monk49fa0162017-01-11 09:21:56 -0500818 return false;
819 }
820
Jason Monk865246d2017-01-19 08:27:01 -0500821 @VisibleForTesting
822 boolean onHomeLongClick(View v) {
Matthew Ng6ff33b72018-02-27 13:47:38 -0800823 if (!mNavigationBarView.isRecentsButtonVisible()
824 && ActivityManagerWrapper.getInstance().isScreenPinningActive()) {
Matthew Ngfee0b5b2018-02-21 15:38:21 -0800825 return onLongPressBackHome(v);
826 }
Jason Monk49fa0162017-01-11 09:21:56 -0500827 if (shouldDisableNavbarGestures()) {
828 return false;
829 }
Matthew Ng2ea93b72018-03-14 19:43:18 +0000830 mNavigationBarView.onNavigationButtonLongPress(v);
Mike Digmanc94759d2018-01-23 11:01:21 -0800831 mMetricsLogger.action(MetricsEvent.ACTION_ASSIST_LONG_PRESS);
Jason Monk49fa0162017-01-11 09:21:56 -0500832 mAssistManager.startAssist(new Bundle() /* args */);
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500833 mStatusBar.awakenDreams();
Matthew Ngdc79e5c2017-12-14 17:37:35 -0800834
Jason Monk49fa0162017-01-11 09:21:56 -0500835 if (mNavigationBarView != null) {
836 mNavigationBarView.abortCurrentGesture();
837 }
838 return true;
839 }
840
841 // additional optimization when we have software system buttons - start loading the recent
842 // tasks on touch down
843 private boolean onRecentsTouch(View v, MotionEvent event) {
844 int action = event.getAction() & MotionEvent.ACTION_MASK;
845 if (action == MotionEvent.ACTION_DOWN) {
846 mCommandQueue.preloadRecentApps();
847 } else if (action == MotionEvent.ACTION_CANCEL) {
848 mCommandQueue.cancelPreloadRecentApps();
849 } else if (action == MotionEvent.ACTION_UP) {
850 if (!v.isPressed()) {
851 mCommandQueue.cancelPreloadRecentApps();
852 }
853 }
854 return false;
855 }
856
857 private void onRecentsClick(View v) {
858 if (LatencyTracker.isEnabled(getContext())) {
859 LatencyTracker.getInstance(getContext()).onActionStart(
860 LatencyTracker.ACTION_TOGGLE_RECENTS);
861 }
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500862 mStatusBar.awakenDreams();
Jason Monk49fa0162017-01-11 09:21:56 -0500863 mCommandQueue.toggleRecentApps();
864 }
865
Matthew Ng9c3bce52018-02-01 22:00:31 +0000866 private boolean onLongPressBackHome(View v) {
Matthew Ng2ea93b72018-03-14 19:43:18 +0000867 mNavigationBarView.onNavigationButtonLongPress(v);
Matthew Ng9c3bce52018-02-01 22:00:31 +0000868 return onLongPressNavigationButtons(v, R.id.back, R.id.home);
869 }
870
871 private boolean onLongPressBackRecents(View v) {
Matthew Ng2ea93b72018-03-14 19:43:18 +0000872 mNavigationBarView.onNavigationButtonLongPress(v);
Matthew Ng9c3bce52018-02-01 22:00:31 +0000873 return onLongPressNavigationButtons(v, R.id.back, R.id.recent_apps);
874 }
875
Jason Monk49fa0162017-01-11 09:21:56 -0500876 /**
Matthew Ng9c3bce52018-02-01 22:00:31 +0000877 * This handles long-press of both back and recents/home. Back is the common button with
878 * combination of recents if it is visible or home if recents is invisible.
879 * They are handled together to capture them both being long-pressed
Jason Monk49fa0162017-01-11 09:21:56 -0500880 * at the same time to exit screen pinning (lock task).
881 *
Matthew Ng9c3bce52018-02-01 22:00:31 +0000882 * When accessibility mode is on, only a long-press from recents/home
Jason Monk49fa0162017-01-11 09:21:56 -0500883 * is required to exit.
884 *
885 * In all other circumstances we try to pass through long-press events
886 * for Back, so that apps can still use it. Which can be from two things.
887 * 1) Not currently in screen pinning (lock task).
Matthew Ng9c3bce52018-02-01 22:00:31 +0000888 * 2) Back is long-pressed without recents/home.
Jason Monk49fa0162017-01-11 09:21:56 -0500889 */
Matthew Ng9c3bce52018-02-01 22:00:31 +0000890 private boolean onLongPressNavigationButtons(View v, @IdRes int btnId1, @IdRes int btnId2) {
Jason Monk49fa0162017-01-11 09:21:56 -0500891 try {
892 boolean sendBackLongPress = false;
Wale Ogunwale04d9cb52018-04-30 13:55:07 -0700893 IActivityTaskManager activityManager = ActivityTaskManager.getService();
Jason Monk49fa0162017-01-11 09:21:56 -0500894 boolean touchExplorationEnabled = mAccessibilityManager.isTouchExplorationEnabled();
895 boolean inLockTaskMode = activityManager.isInLockTaskMode();
896 if (inLockTaskMode && !touchExplorationEnabled) {
897 long time = System.currentTimeMillis();
Matthew Ng9c3bce52018-02-01 22:00:31 +0000898
Jason Monk49fa0162017-01-11 09:21:56 -0500899 // If we recently long-pressed the other button then they were
900 // long-pressed 'together'
901 if ((time - mLastLockToAppLongPress) < LOCK_TO_APP_GESTURE_TOLERENCE) {
Benjamin Franza83859f2017-07-03 16:34:14 +0100902 activityManager.stopSystemLockTaskMode();
Jason Monk49fa0162017-01-11 09:21:56 -0500903 // When exiting refresh disabled flags.
Matthew Ngd0a73e72018-03-02 15:16:03 -0800904 mNavigationBarView.updateNavButtonIcons();
Jason Monk49fa0162017-01-11 09:21:56 -0500905 return true;
Matthew Ng9c3bce52018-02-01 22:00:31 +0000906 } else if (v.getId() == btnId1) {
907 ButtonDispatcher button = btnId2 == R.id.recent_apps
908 ? mNavigationBarView.getRecentsButton()
909 : mNavigationBarView.getHomeButton();
910 if (!button.getCurrentView().isPressed()) {
911 // If we aren't pressing recents/home right now then they presses
912 // won't be together, so send the standard long-press action.
913 sendBackLongPress = true;
914 }
Jason Monk49fa0162017-01-11 09:21:56 -0500915 }
916 mLastLockToAppLongPress = time;
917 } else {
918 // If this is back still need to handle sending the long-press event.
Matthew Ng9c3bce52018-02-01 22:00:31 +0000919 if (v.getId() == btnId1) {
Jason Monk49fa0162017-01-11 09:21:56 -0500920 sendBackLongPress = true;
921 } else if (touchExplorationEnabled && inLockTaskMode) {
Matthew Ng9c3bce52018-02-01 22:00:31 +0000922 // When in accessibility mode a long press that is recents/home (not back)
Jason Monk49fa0162017-01-11 09:21:56 -0500923 // should stop lock task.
Benjamin Franza83859f2017-07-03 16:34:14 +0100924 activityManager.stopSystemLockTaskMode();
Jason Monk49fa0162017-01-11 09:21:56 -0500925 // When exiting refresh disabled flags.
Matthew Ngd0a73e72018-03-02 15:16:03 -0800926 mNavigationBarView.updateNavButtonIcons();
Jason Monk49fa0162017-01-11 09:21:56 -0500927 return true;
Matthew Ng9c3bce52018-02-01 22:00:31 +0000928 } else if (v.getId() == btnId2) {
929 return btnId2 == R.id.recent_apps
930 ? onLongPressRecents()
931 : onHomeLongClick(mNavigationBarView.getHomeButton().getCurrentView());
Jason Monk49fa0162017-01-11 09:21:56 -0500932 }
933 }
934 if (sendBackLongPress) {
935 KeyButtonView keyButtonView = (KeyButtonView) v;
936 keyButtonView.sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.FLAG_LONG_PRESS);
937 keyButtonView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED);
938 return true;
939 }
940 } catch (RemoteException e) {
941 Log.d(TAG, "Unable to reach activity manager", e);
942 }
943 return false;
944 }
945
946 private boolean onLongPressRecents() {
Wale Ogunwale65ebd952018-04-25 15:41:44 -0700947 if (mRecents == null || !ActivityTaskManager.supportsMultiWindow(getContext())
Matthew Ng43db6d22017-06-27 15:29:39 -0700948 || !mDivider.getView().getSnapAlgorithm().isSplitScreenFeasible()
Winson Chung074c4342018-03-26 17:27:19 -0700949 || Recents.getConfiguration().isLowRamDevice
950 // If we are connected to the overview service, then disable the recents button
951 || mOverviewProxyService.getProxy() != null) {
Jason Monk49fa0162017-01-11 09:21:56 -0500952 return false;
953 }
954
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500955 return mStatusBar.toggleSplitScreenMode(MetricsEvent.ACTION_WINDOW_DOCK_LONGPRESS,
Jason Monk49fa0162017-01-11 09:21:56 -0500956 MetricsEvent.ACTION_WINDOW_UNDOCK_LONGPRESS);
957 }
958
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800959 private void onAccessibilityClick(View v) {
960 mAccessibilityManager.notifyAccessibilityButtonClicked();
961 }
962
963 private boolean onAccessibilityLongClick(View v) {
Casey Burkhardt5e8b9802017-03-24 10:07:20 -0700964 Intent intent = new Intent(AccessibilityManager.ACTION_CHOOSE_ACCESSIBILITY_BUTTON);
965 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
Casey Burkhardt5d614402017-04-06 13:46:50 -0700966 v.getContext().startActivityAsUser(intent, UserHandle.CURRENT);
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800967 return true;
968 }
969
Phil Weaverdb9a7742017-04-18 08:15:06 -0700970 private void updateAccessibilityServicesState(AccessibilityManager accessibilityManager) {
Casey Burkhardt74922c62017-02-13 12:43:16 -0800971 int requestingServices = 0;
972 try {
Casey Burkhardt5d614402017-04-06 13:46:50 -0700973 if (Settings.Secure.getIntForUser(mContentResolver,
974 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED,
975 UserHandle.USER_CURRENT) == 1) {
Casey Burkhardt74922c62017-02-13 12:43:16 -0800976 requestingServices++;
977 }
978 } catch (Settings.SettingNotFoundException e) {
979 }
980
Mike Digman90402952018-01-22 16:05:51 -0800981 boolean feedbackEnabled = false;
Casey Burkhardt5d614402017-04-06 13:46:50 -0700982 // AccessibilityManagerService resolves services for the current user since the local
983 // AccessibilityManager is created from a Context with the INTERACT_ACROSS_USERS permission
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800984 final List<AccessibilityServiceInfo> services =
Phil Weaverdb9a7742017-04-18 08:15:06 -0700985 accessibilityManager.getEnabledAccessibilityServiceList(
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800986 AccessibilityServiceInfo.FEEDBACK_ALL_MASK);
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800987 for (int i = services.size() - 1; i >= 0; --i) {
988 AccessibilityServiceInfo info = services.get(i);
989 if ((info.flags & AccessibilityServiceInfo.FLAG_REQUEST_ACCESSIBILITY_BUTTON) != 0) {
990 requestingServices++;
991 }
Mike Digman90402952018-01-22 16:05:51 -0800992
993 if (info.feedbackType != 0 && info.feedbackType !=
994 AccessibilityServiceInfo.FEEDBACK_GENERIC) {
995 feedbackEnabled = true;
996 }
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800997 }
998
Mike Digman90402952018-01-22 16:05:51 -0800999 mAccessibilityFeedbackEnabled = feedbackEnabled;
1000
Casey Burkhardt048c2bc2016-12-08 16:09:20 -08001001 final boolean showAccessibilityButton = requestingServices >= 1;
1002 final boolean targetSelection = requestingServices >= 2;
1003 mNavigationBarView.setAccessibilityButtonState(showAccessibilityButton, targetSelection);
1004 }
1005
Mike Digman7d092772018-01-11 12:10:32 -08001006 private void onRotateSuggestionClick(View v) {
Mike Digmanc94759d2018-01-23 11:01:21 -08001007 mMetricsLogger.action(MetricsEvent.ACTION_ROTATION_SUGGESTION_ACCEPTED);
Mike Digman50752642018-02-15 13:36:09 -08001008 incrementNumAcceptedRotationSuggestionsIfNeeded();
Mike Digman7d092772018-01-11 12:10:32 -08001009 mRotationLockController.setRotationLockedAtAngle(true, mLastRotationSuggestion);
1010 }
1011
Mike Digman90402952018-01-22 16:05:51 -08001012 private boolean onRotateSuggestionHover(View v, MotionEvent event) {
1013 final int action = event.getActionMasked();
1014 mHoveringRotationSuggestion = (action == MotionEvent.ACTION_HOVER_ENTER)
1015 || (action == MotionEvent.ACTION_HOVER_MOVE);
1016 rescheduleRotationTimeout(true);
1017 return false; // Must return false so a11y hover events are dispatched correctly.
1018 }
1019
Jason Monk2a6ea9c2017-01-26 11:14:51 -05001020 // ----- Methods that StatusBar talks to (should be minimized) -----
Jason Monk49fa0162017-01-11 09:21:56 -05001021
Jason Monk49fa0162017-01-11 09:21:56 -05001022 public void setLightBarController(LightBarController lightBarController) {
1023 mLightBarController = lightBarController;
1024 mLightBarController.setNavigationBar(mNavigationBarView.getLightTransitionsController());
1025 }
1026
1027 public boolean isSemiTransparent() {
1028 return mNavigationBarMode == MODE_SEMI_TRANSPARENT;
1029 }
1030
Jason Monk49fa0162017-01-11 09:21:56 -05001031 public void disableAnimationsDuringHide(long delay) {
1032 mNavigationBarView.setLayoutTransitionsEnabled(false);
1033 mNavigationBarView.postDelayed(() -> mNavigationBarView.setLayoutTransitionsEnabled(true),
1034 delay + StackStateAnimator.ANIMATION_DURATION_GO_TO_FULL_SHADE);
1035 }
1036
Jason Monk49fa0162017-01-11 09:21:56 -05001037 public BarTransitions getBarTransitions() {
1038 return mNavigationBarView.getBarTransitions();
1039 }
1040
1041 public void checkNavBarModes() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -05001042 mStatusBar.checkBarMode(mNavigationBarMode,
Jason Monk49fa0162017-01-11 09:21:56 -05001043 mNavigationBarWindowState, mNavigationBarView.getBarTransitions());
1044 }
1045
1046 public void finishBarAnimations() {
1047 mNavigationBarView.getBarTransitions().finishAnimations();
1048 }
1049
Jason Monk91e587e2017-04-13 13:41:23 -04001050 private final AccessibilityServicesStateChangeListener mAccessibilityListener =
1051 this::updateAccessibilityServicesState;
1052
Casey Burkhardt74922c62017-02-13 12:43:16 -08001053 private class MagnificationContentObserver extends ContentObserver {
1054
1055 public MagnificationContentObserver(Handler handler) {
1056 super(handler);
1057 }
1058
1059 @Override
1060 public void onChange(boolean selfChange) {
Phil Weaverdb9a7742017-04-18 08:15:06 -07001061 NavigationBarFragment.this.updateAccessibilityServicesState(mAccessibilityManager);
Casey Burkhardt74922c62017-02-13 12:43:16 -08001062 }
1063 }
1064
Jason Monk49fa0162017-01-11 09:21:56 -05001065 private final Stub mRotationWatcher = new Stub() {
1066 @Override
Mike Digman90402952018-01-22 16:05:51 -08001067 public void onRotationChanged(final int rotation) throws RemoteException {
Jason Monk49fa0162017-01-11 09:21:56 -05001068 // We need this to be scheduled as early as possible to beat the redrawing of
1069 // window in response to the orientation change.
1070 Handler h = getView().getHandler();
1071 Message msg = Message.obtain(h, () -> {
Mike Digman85ff7fa2018-01-23 14:59:52 -08001072
1073 // If the screen rotation changes while locked, potentially update lock to flow with
Mike Digman90402952018-01-22 16:05:51 -08001074 // new screen rotation and hide any showing suggestions.
1075 if (mRotationLockController.isRotationLocked()) {
Mike Digman85ff7fa2018-01-23 14:59:52 -08001076 if (shouldOverrideUserLockPrefs(rotation)) {
1077 mRotationLockController.setRotationLockedAtAngle(true, rotation);
1078 }
Mike Digman1e28a5a2018-02-14 10:49:19 -08001079 setRotateSuggestionButtonState(false, true);
Mike Digman90402952018-01-22 16:05:51 -08001080 }
1081
Jason Monk49fa0162017-01-11 09:21:56 -05001082 if (mNavigationBarView != null
1083 && mNavigationBarView.needsReorient(rotation)) {
1084 repositionNavigationBar();
1085 }
1086 });
1087 msg.setAsynchronous(true);
1088 h.sendMessageAtFrontOfQueue(msg);
1089 }
Mike Digman85ff7fa2018-01-23 14:59:52 -08001090
1091 private boolean shouldOverrideUserLockPrefs(final int rotation) {
Mike Digmanab650252018-03-06 11:01:41 -08001092 // Only override user prefs when returning to the natural rotation (normally portrait).
Mike Digman85ff7fa2018-01-23 14:59:52 -08001093 // Don't let apps that force landscape or 180 alter user lock.
Mike Digmanab650252018-03-06 11:01:41 -08001094 return rotation == NATURAL_ROTATION;
Mike Digman85ff7fa2018-01-23 14:59:52 -08001095 }
Jason Monk49fa0162017-01-11 09:21:56 -05001096 };
1097
1098 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1099 @Override
1100 public void onReceive(Context context, Intent intent) {
1101 String action = intent.getAction();
Siarhei Vishniakoud002a0a2017-06-05 22:44:37 +01001102 if (Intent.ACTION_SCREEN_OFF.equals(action)
1103 || Intent.ACTION_SCREEN_ON.equals(action)) {
1104 notifyNavigationBarScreenOn();
Jason Monk49fa0162017-01-11 09:21:56 -05001105 }
Phil Weavera858c5f2018-04-26 13:27:30 -07001106 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
1107 // The accessibility settings may be different for the new user
1108 updateAccessibilityServicesState(mAccessibilityManager);
1109 };
Jason Monk49fa0162017-01-11 09:21:56 -05001110 }
1111 };
1112
Mike Digman7d092772018-01-11 12:10:32 -08001113 class TaskStackListenerImpl extends SysUiTaskStackChangeListener {
1114 // Invalidate any rotation suggestion on task change or activity orientation change
1115 // Note: all callbacks happen on main thread
1116
1117 @Override
1118 public void onTaskStackChanged() {
Mike Digman1e28a5a2018-02-14 10:49:19 -08001119 setRotateSuggestionButtonState(false);
Mike Digman7d092772018-01-11 12:10:32 -08001120 }
1121
1122 @Override
1123 public void onTaskRemoved(int taskId) {
Mike Digman1e28a5a2018-02-14 10:49:19 -08001124 setRotateSuggestionButtonState(false);
Mike Digman7d092772018-01-11 12:10:32 -08001125 }
1126
1127 @Override
1128 public void onTaskMovedToFront(int taskId) {
Mike Digman1e28a5a2018-02-14 10:49:19 -08001129 setRotateSuggestionButtonState(false);
Mike Digman7d092772018-01-11 12:10:32 -08001130 }
1131
1132 @Override
1133 public void onActivityRequestedOrientationChanged(int taskId, int requestedOrientation) {
Mike Digman85a9bea2018-02-23 15:08:53 -08001134 // Only hide the icon if the top task changes its requestedOrientation
1135 // Launcher can alter its requestedOrientation while it's not on top, don't hide on this
Mike Digman121b11f2018-04-04 12:45:24 -07001136 Optional.ofNullable(ActivityManagerWrapper.getInstance())
1137 .map(ActivityManagerWrapper::getRunningTask)
1138 .ifPresent(a -> {
1139 if (a.id == taskId) setRotateSuggestionButtonState(false);
1140 });
Mike Digman7d092772018-01-11 12:10:32 -08001141 }
1142 }
1143
Mike Digman50752642018-02-15 13:36:09 -08001144 private class ViewRippler {
1145 private static final int RIPPLE_OFFSET_MS = 50;
1146 private static final int RIPPLE_INTERVAL_MS = 2000;
1147 private View mRoot;
1148
1149 public void start(View root) {
1150 stop(); // Stop any pending ripple animations
1151
1152 mRoot = root;
1153
1154 // Schedule pending ripples, offset the 1st to avoid problems with visibility change
1155 mRoot.postOnAnimationDelayed(mRipple, RIPPLE_OFFSET_MS);
1156 mRoot.postOnAnimationDelayed(mRipple, RIPPLE_INTERVAL_MS);
1157 mRoot.postOnAnimationDelayed(mRipple, 2*RIPPLE_INTERVAL_MS);
Mike Digmanc038c322018-05-24 11:06:05 -07001158 mRoot.postOnAnimationDelayed(mRipple, 3*RIPPLE_INTERVAL_MS);
1159 mRoot.postOnAnimationDelayed(mRipple, 4*RIPPLE_INTERVAL_MS);
Mike Digman50752642018-02-15 13:36:09 -08001160 }
1161
1162 public void stop() {
1163 if (mRoot != null) mRoot.removeCallbacks(mRipple);
1164 }
1165
1166 private final Runnable mRipple = new Runnable() {
1167 @Override
1168 public void run() { // Cause the ripple to fire via false presses
Mike Digmanf4c98992018-04-25 11:25:59 -07001169 if (!mRoot.isAttachedToWindow()) return;
Mike Digman50752642018-02-15 13:36:09 -08001170 mRoot.setPressed(true);
1171 mRoot.setPressed(false);
1172 }
1173 };
1174 }
1175
Jason Monk49fa0162017-01-11 09:21:56 -05001176 public static View create(Context context, FragmentListener listener) {
1177 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1178 LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
1179 WindowManager.LayoutParams.TYPE_NAVIGATION_BAR,
1180 WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
1181 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1182 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
1183 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
1184 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
1185 | WindowManager.LayoutParams.FLAG_SLIPPERY,
1186 PixelFormat.TRANSLUCENT);
1187 lp.token = new Binder();
Jason Monk49fa0162017-01-11 09:21:56 -05001188 lp.setTitle("NavigationBar");
Phil Weaver8583ae82018-02-13 11:01:24 -08001189 lp.accessibilityTitle = context.getString(R.string.nav_bar);
Jason Monk49fa0162017-01-11 09:21:56 -05001190 lp.windowAnimations = 0;
1191
1192 View navigationBarView = LayoutInflater.from(context).inflate(
1193 R.layout.navigation_bar_window, null);
1194
1195 if (DEBUG) Log.v(TAG, "addNavigationBar: about to add " + navigationBarView);
1196 if (navigationBarView == null) return null;
1197
1198 context.getSystemService(WindowManager.class).addView(navigationBarView, lp);
1199 FragmentHostManager fragmentHost = FragmentHostManager.get(navigationBarView);
1200 NavigationBarFragment fragment = new NavigationBarFragment();
1201 fragmentHost.getFragmentManager().beginTransaction()
1202 .replace(R.id.navigation_bar_frame, fragment, TAG)
1203 .commit();
1204 fragmentHost.addTagListener(TAG, listener);
1205 return navigationBarView;
1206 }
1207}