blob: ac2ffccde7452e7ebfc12a258bd79a6d6fb6b648 [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;
Winson Chung67f5c8b2018-09-24 12:09:19 -070038import android.app.ActivityManager;
Wale Ogunwale65ebd952018-04-25 15:41:44 -070039import android.app.ActivityTaskManager;
Jason Monk49fa0162017-01-11 09:21:56 -050040import android.app.Fragment;
41import android.app.IActivityManager;
Wale Ogunwale04d9cb52018-04-30 13:55:07 -070042import android.app.IActivityTaskManager;
Jason Monk49fa0162017-01-11 09:21:56 -050043import android.app.StatusBarManager;
44import android.content.BroadcastReceiver;
Casey Burkhardtb9dcd662017-03-20 15:10:16 -070045import android.content.ContentResolver;
Jason Monk49fa0162017-01-11 09:21:56 -050046import android.content.Context;
47import android.content.Intent;
48import android.content.IntentFilter;
49import android.content.res.Configuration;
Casey Burkhardt74922c62017-02-13 12:43:16 -080050import android.database.ContentObserver;
Jason Monk49fa0162017-01-11 09:21:56 -050051import android.graphics.PixelFormat;
52import android.graphics.Rect;
53import 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.shared.system.ActivityManagerWrapper;
Winson Chung67f5c8b2018-09-24 12:09:19 -070093import com.android.systemui.shared.system.TaskStackChangeListener;
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();
Matthew Ngc83b9892018-08-21 16:31:13 -0700198 if (QuickStepController.shouldhideBackButton()) {
199 // If property was changed to hide/show back button, going home will trigger
200 // launcher to to change the back button alpha to reflect property change
201 backButton.setVisibility(View.GONE);
202 } else {
203 backButton.setVisibility(alpha > 0 ? View.VISIBLE : View.INVISIBLE);
204 backButton.setAlpha(alpha, animate);
205 }
Matthew Ng96985e72018-05-08 15:46:13 -0700206 }
Matthew Ng9c3bce52018-02-01 22:00:31 +0000207 };
Mike Digman7d092772018-01-11 12:10:32 -0800208
Jason Monk49fa0162017-01-11 09:21:56 -0500209 // ----- Fragment Lifecycle Callbacks -----
210
211 @Override
212 public void onCreate(@Nullable Bundle savedInstanceState) {
213 super.onCreate(savedInstanceState);
Jason Monk9c7844c2017-01-18 15:21:53 -0500214 mCommandQueue = SysUiServiceProvider.getComponent(getContext(), CommandQueue.class);
Jason Monk49fa0162017-01-11 09:21:56 -0500215 mCommandQueue.addCallbacks(this);
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500216 mStatusBar = SysUiServiceProvider.getComponent(getContext(), StatusBar.class);
Jason Monk9c7844c2017-01-18 15:21:53 -0500217 mRecents = SysUiServiceProvider.getComponent(getContext(), Recents.class);
218 mDivider = SysUiServiceProvider.getComponent(getContext(), Divider.class);
Jason Monk49fa0162017-01-11 09:21:56 -0500219 mWindowManager = getContext().getSystemService(WindowManager.class);
220 mAccessibilityManager = getContext().getSystemService(AccessibilityManager.class);
Jason Monk91e587e2017-04-13 13:41:23 -0400221 Dependency.get(AccessibilityManagerWrapper.class).addCallback(
222 mAccessibilityListener);
Casey Burkhardtb9dcd662017-03-20 15:10:16 -0700223 mContentResolver = getContext().getContentResolver();
Casey Burkhardt74922c62017-02-13 12:43:16 -0800224 mMagnificationObserver = new MagnificationContentObserver(
225 getContext().getMainThreadHandler());
Casey Burkhardtb9dcd662017-03-20 15:10:16 -0700226 mContentResolver.registerContentObserver(Settings.Secure.getUriFor(
Casey Burkhardt74922c62017-02-13 12:43:16 -0800227 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED), false,
Casey Burkhardt5d614402017-04-06 13:46:50 -0700228 mMagnificationObserver, UserHandle.USER_ALL);
Casey Burkhardt74922c62017-02-13 12:43:16 -0800229
Jason Monk49fa0162017-01-11 09:21:56 -0500230 if (savedInstanceState != null) {
231 mDisabledFlags1 = savedInstanceState.getInt(EXTRA_DISABLE_STATE, 0);
Mike Digmandd2f49e2018-03-16 10:54:22 -0700232 mDisabledFlags2 = savedInstanceState.getInt(EXTRA_DISABLE2_STATE, 0);
Jason Monk49fa0162017-01-11 09:21:56 -0500233 }
Jason Monk9c7844c2017-01-18 15:21:53 -0500234 mAssistManager = Dependency.get(AssistManager.class);
Matthew Ngdc79e5c2017-12-14 17:37:35 -0800235 mOverviewProxyService = Dependency.get(OverviewProxyService.class);
Jason Monk49fa0162017-01-11 09:21:56 -0500236
237 try {
238 WindowManagerGlobal.getWindowManagerService()
Andrii Kulian35fa3c22017-03-11 09:37:28 -0800239 .watchRotation(mRotationWatcher, getContext().getDisplay().getDisplayId());
Jason Monk49fa0162017-01-11 09:21:56 -0500240 } catch (RemoteException e) {
241 throw e.rethrowFromSystemServer();
242 }
Mike Digman7d092772018-01-11 12:10:32 -0800243
244 mRotationLockController = Dependency.get(RotationLockController.class);
245
Mike Digmanab650252018-03-06 11:01:41 -0800246 // Reset user rotation pref to match that of the WindowManager if starting in locked mode
247 // This will automatically happen when switching from auto-rotate to locked mode
248 if (mRotationLockController.isRotationLocked()) {
249 final int winRotation = mWindowManager.getDefaultDisplay().getRotation();
250 mRotationLockController.setRotationLockedAtAngle(true, winRotation);
251 }
252
Mike Digman7d092772018-01-11 12:10:32 -0800253 // Register the task stack listener
254 mTaskStackListener = new TaskStackListenerImpl();
255 ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener);
Jason Monk49fa0162017-01-11 09:21:56 -0500256 }
257
258 @Override
259 public void onDestroy() {
260 super.onDestroy();
261 mCommandQueue.removeCallbacks(this);
Jason Monk91e587e2017-04-13 13:41:23 -0400262 Dependency.get(AccessibilityManagerWrapper.class).removeCallback(
263 mAccessibilityListener);
Casey Burkhardtb9dcd662017-03-20 15:10:16 -0700264 mContentResolver.unregisterContentObserver(mMagnificationObserver);
Jason Monk49fa0162017-01-11 09:21:56 -0500265 try {
266 WindowManagerGlobal.getWindowManagerService()
267 .removeRotationWatcher(mRotationWatcher);
268 } catch (RemoteException e) {
269 throw e.rethrowFromSystemServer();
270 }
Mike Digman7d092772018-01-11 12:10:32 -0800271
272 // Unregister the task stack listener
273 ActivityManagerWrapper.getInstance().unregisterTaskStackListener(mTaskStackListener);
Jason Monk49fa0162017-01-11 09:21:56 -0500274 }
275
276 @Override
277 public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
278 Bundle savedInstanceState) {
279 return inflater.inflate(R.layout.navigation_bar, container, false);
280 }
281
282 @Override
283 public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
284 super.onViewCreated(view, savedInstanceState);
285 mNavigationBarView = (NavigationBarView) view;
286
287 mNavigationBarView.setDisabledFlags(mDisabledFlags1);
Winson Chung67f5c8b2018-09-24 12:09:19 -0700288 mNavigationBarView.setComponents(mStatusBar.getPanel());
Jason Monk49fa0162017-01-11 09:21:56 -0500289 mNavigationBarView.setOnVerticalChangedListener(this::onVerticalChanged);
290 mNavigationBarView.setOnTouchListener(this::onNavigationTouch);
291 if (savedInstanceState != null) {
292 mNavigationBarView.getLightTransitionsController().restoreState(savedInstanceState);
293 }
294
295 prepareNavigationBarView();
296 checkNavBarModes();
297
Mike Digmandd2f49e2018-03-16 10:54:22 -0700298 setDisabled2Flags(mDisabledFlags2);
299
Jason Monk49fa0162017-01-11 09:21:56 -0500300 IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
301 filter.addAction(Intent.ACTION_SCREEN_ON);
Phil Weavera858c5f2018-04-26 13:27:30 -0700302 filter.addAction(Intent.ACTION_USER_SWITCHED);
Jason Monk49fa0162017-01-11 09:21:56 -0500303 getContext().registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, filter, null, null);
Siarhei Vishniakoud002a0a2017-06-05 22:44:37 +0100304 notifyNavigationBarScreenOn();
Matthew Ng9c3bce52018-02-01 22:00:31 +0000305 mOverviewProxyService.addCallback(mOverviewProxyListener);
Jason Monk49fa0162017-01-11 09:21:56 -0500306 }
307
308 @Override
309 public void onDestroyView() {
310 super.onDestroyView();
Winson Chungb03d44d2018-09-18 12:42:45 -0700311 if (mNavigationBarView != null) {
312 mNavigationBarView.getBarTransitions().destroy();
313 mNavigationBarView.getLightTransitionsController().destroy(getContext());
314 }
Matthew Ng9c3bce52018-02-01 22:00:31 +0000315 mOverviewProxyService.removeCallback(mOverviewProxyListener);
Jason Monk49fa0162017-01-11 09:21:56 -0500316 getContext().unregisterReceiver(mBroadcastReceiver);
317 }
318
319 @Override
320 public void onSaveInstanceState(Bundle outState) {
321 super.onSaveInstanceState(outState);
322 outState.putInt(EXTRA_DISABLE_STATE, mDisabledFlags1);
Mike Digmandd2f49e2018-03-16 10:54:22 -0700323 outState.putInt(EXTRA_DISABLE2_STATE, mDisabledFlags2);
Jason Monk49fa0162017-01-11 09:21:56 -0500324 if (mNavigationBarView != null) {
325 mNavigationBarView.getLightTransitionsController().saveState(outState);
326 }
327 }
328
329 @Override
330 public void onConfigurationChanged(Configuration newConfig) {
331 super.onConfigurationChanged(newConfig);
332 final Locale locale = getContext().getResources().getConfiguration().locale;
333 final int ld = TextUtils.getLayoutDirectionFromLocale(locale);
334 if (!locale.equals(mLocale) || ld != mLayoutDirection) {
335 if (DEBUG) {
336 Log.v(TAG, String.format(
337 "config changed locale/LD: %s (%d) -> %s (%d)", mLocale, mLayoutDirection,
338 locale, ld));
339 }
340 mLocale = locale;
341 mLayoutDirection = ld;
342 refreshLayout(ld);
343 }
344 repositionNavigationBar();
345 }
346
347 @Override
348 public void dump(String prefix, FileDescriptor fd, PrintWriter pw, String[] args) {
349 if (mNavigationBarView != null) {
350 pw.print(" mNavigationBarWindowState=");
351 pw.println(windowStateToString(mNavigationBarWindowState));
352 pw.print(" mNavigationBarMode=");
353 pw.println(BarTransitions.modeToString(mNavigationBarMode));
354 dumpBarTransitions(pw, "mNavigationBarView", mNavigationBarView.getBarTransitions());
355 }
356
357 pw.print(" mNavigationBarView=");
358 if (mNavigationBarView == null) {
359 pw.println("null");
360 } else {
361 mNavigationBarView.dump(fd, pw, args);
362 }
363 }
364
365 // ----- CommandQueue Callbacks -----
366
367 @Override
368 public void setImeWindowStatus(IBinder token, int vis, int backDisposition,
369 boolean showImeSwitcher) {
370 boolean imeShown = (vis & InputMethodService.IME_VISIBLE) != 0;
371 int hints = mNavigationIconHints;
Yohei Yukawa386f50e2018-03-14 13:03:42 -0700372 switch (backDisposition) {
373 case InputMethodService.BACK_DISPOSITION_DEFAULT:
374 case InputMethodService.BACK_DISPOSITION_WILL_NOT_DISMISS:
375 case InputMethodService.BACK_DISPOSITION_WILL_DISMISS:
376 if (imeShown) {
377 hints |= NAVIGATION_HINT_BACK_ALT;
378 } else {
379 hints &= ~NAVIGATION_HINT_BACK_ALT;
380 }
381 break;
382 case InputMethodService.BACK_DISPOSITION_ADJUST_NOTHING:
383 hints &= ~NAVIGATION_HINT_BACK_ALT;
384 break;
Jason Monk49fa0162017-01-11 09:21:56 -0500385 }
386 if (showImeSwitcher) {
387 hints |= NAVIGATION_HINT_IME_SHOWN;
388 } else {
389 hints &= ~NAVIGATION_HINT_IME_SHOWN;
390 }
391 if (hints == mNavigationIconHints) return;
392
393 mNavigationIconHints = hints;
394
395 if (mNavigationBarView != null) {
396 mNavigationBarView.setNavigationIconHints(hints);
397 }
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500398 mStatusBar.checkBarModes();
Jason Monk49fa0162017-01-11 09:21:56 -0500399 }
400
401 @Override
402 public void topAppWindowChanged(boolean showMenu) {
403 if (mNavigationBarView != null) {
404 mNavigationBarView.setMenuVisibility(showMenu);
405 }
406 }
407
408 @Override
409 public void setWindowState(int window, int state) {
410 if (mNavigationBarView != null
411 && window == StatusBarManager.WINDOW_NAVIGATION_BAR
412 && mNavigationBarWindowState != state) {
413 mNavigationBarWindowState = state;
414 if (DEBUG_WINDOW_STATE) Log.d(TAG, "Navigation bar " + windowStateToString(state));
Mike Digman5aeca792018-03-05 11:14:39 -0800415
416 // If the navbar is visible, show the rotate button if there's a pending suggestion
417 if (state == WINDOW_STATE_SHOWING && mPendingRotationSuggestion) {
418 showAndLogRotationSuggestion();
419 }
Jason Monk49fa0162017-01-11 09:21:56 -0500420 }
421 }
422
Mike Digman7d092772018-01-11 12:10:32 -0800423 @Override
Mike Digmane0777312018-01-19 12:41:51 -0800424 public void onRotationProposal(final int rotation, boolean isValid) {
Mike Digman3e33da62018-03-14 16:25:11 -0700425 final int winRotation = mWindowManager.getDefaultDisplay().getRotation();
Mike Digmandd2f49e2018-03-16 10:54:22 -0700426 final boolean rotateSuggestionsDisabled = hasDisable2RotateSuggestionFlag(mDisabledFlags2);
Mike Digman3e33da62018-03-14 16:25:11 -0700427 if (DEBUG_ROTATION) {
428 Log.v(TAG, "onRotationProposal proposedRotation=" + Surface.rotationToString(rotation)
429 + ", winRotation=" + Surface.rotationToString(winRotation)
430 + ", isValid=" + isValid + ", mNavBarWindowState="
431 + StatusBarManager.windowStateToString(mNavigationBarWindowState)
Mike Digmandd2f49e2018-03-16 10:54:22 -0700432 + ", rotateSuggestionsDisabled=" + rotateSuggestionsDisabled
Mike Digman3e33da62018-03-14 16:25:11 -0700433 + ", isRotateButtonVisible=" + (mNavigationBarView == null ? "null" :
434 mNavigationBarView.isRotateButtonVisible()));
435 }
436
Mike Digmandd2f49e2018-03-16 10:54:22 -0700437 // Respect the disabled flag, no need for action as flag change callback will handle hiding
438 if (rotateSuggestionsDisabled) return;
439
Mike Digmane0777312018-01-19 12:41:51 -0800440 // This method will be called on rotation suggestion changes even if the proposed rotation
441 // is not valid for the top app. Use invalid rotation choices as a signal to remove the
442 // rotate button if shown.
Mike Digmane0777312018-01-19 12:41:51 -0800443 if (!isValid) {
Mike Digman1e28a5a2018-02-14 10:49:19 -0800444 setRotateSuggestionButtonState(false);
Mike Digmane0777312018-01-19 12:41:51 -0800445 return;
446 }
447
Mike Digman5aeca792018-03-05 11:14:39 -0800448 // If window rotation matches suggested rotation, remove any current suggestions
Mike Digman1e28a5a2018-02-14 10:49:19 -0800449 if (rotation == winRotation) {
Mike Digman5aeca792018-03-05 11:14:39 -0800450 getView().removeCallbacks(mRemoveRotationProposal);
Mike Digman1e28a5a2018-02-14 10:49:19 -0800451 setRotateSuggestionButtonState(false);
Mike Digman5aeca792018-03-05 11:14:39 -0800452 return;
Mike Digman7d092772018-01-11 12:10:32 -0800453 }
Mike Digman5aeca792018-03-05 11:14:39 -0800454
455 // Prepare to show the navbar icon by updating the icon style to change anim params
456 mLastRotationSuggestion = rotation; // Remember rotation for click
457 if (mNavigationBarView != null) {
458 final boolean rotationCCW = isRotationAnimationCCW(winRotation, rotation);
459 int style;
460 if (winRotation == Surface.ROTATION_0 || winRotation == Surface.ROTATION_180) {
461 style = rotationCCW ? R.style.RotateButtonCCWStart90 :
462 R.style.RotateButtonCWStart90;
463 } else { // 90 or 270
464 style = rotationCCW ? R.style.RotateButtonCCWStart0 :
465 R.style.RotateButtonCWStart0;
466 }
Matthew Ng25593cc2018-09-12 16:05:41 -0700467 mNavigationBarView.updateRotateSuggestionButtonStyle(style);
Mike Digman5aeca792018-03-05 11:14:39 -0800468 }
469
470 if (mNavigationBarWindowState != WINDOW_STATE_SHOWING) {
471 // If the navbar isn't shown, flag the rotate icon to be shown should the navbar become
472 // visible given some time limit.
473 mPendingRotationSuggestion = true;
474 getView().removeCallbacks(mCancelPendingRotationProposal);
475 getView().postDelayed(mCancelPendingRotationProposal,
476 NAVBAR_HIDDEN_PENDING_ICON_TIMEOUT_MS);
477
478 } else { // The navbar is visible so show the icon right away
479 showAndLogRotationSuggestion();
480 }
481 }
482
Mike Digmandd2f49e2018-03-16 10:54:22 -0700483 private void onRotationSuggestionsDisabled() {
484 // Immediately hide the rotate button and clear any planned removal
485 setRotateSuggestionButtonState(false, true);
Mike Digmane14c4752018-03-20 12:14:54 -0700486
487 // This method can be called before view setup is done, ensure getView isn't null
488 final View v = getView();
489 if (v != null) v.removeCallbacks(mRemoveRotationProposal);
Mike Digmandd2f49e2018-03-16 10:54:22 -0700490 }
491
Mike Digman5aeca792018-03-05 11:14:39 -0800492 private void showAndLogRotationSuggestion() {
493 setRotateSuggestionButtonState(true);
494 rescheduleRotationTimeout(false);
495 mMetricsLogger.visible(MetricsEvent.ROTATION_SUGGESTION_SHOWN);
Mike Digman7d092772018-01-11 12:10:32 -0800496 }
497
Mike Digman1e28a5a2018-02-14 10:49:19 -0800498 private boolean isRotationAnimationCCW(int from, int to) {
499 // All 180deg WM rotation animations are CCW, match that
500 if (from == Surface.ROTATION_0 && to == Surface.ROTATION_90) return false;
501 if (from == Surface.ROTATION_0 && to == Surface.ROTATION_180) return true; //180d so CCW
502 if (from == Surface.ROTATION_0 && to == Surface.ROTATION_270) return true;
503 if (from == Surface.ROTATION_90 && to == Surface.ROTATION_0) return true;
504 if (from == Surface.ROTATION_90 && to == Surface.ROTATION_180) return false;
505 if (from == Surface.ROTATION_90 && to == Surface.ROTATION_270) return true; //180d so CCW
506 if (from == Surface.ROTATION_180 && to == Surface.ROTATION_0) return true; //180d so CCW
507 if (from == Surface.ROTATION_180 && to == Surface.ROTATION_90) return true;
508 if (from == Surface.ROTATION_180 && to == Surface.ROTATION_270) return false;
509 if (from == Surface.ROTATION_270 && to == Surface.ROTATION_0) return false;
510 if (from == Surface.ROTATION_270 && to == Surface.ROTATION_90) return true; //180d so CCW
511 if (from == Surface.ROTATION_270 && to == Surface.ROTATION_180) return true;
512 return false; // Default
Mike Digmana48cf192018-02-12 17:52:48 -0800513 }
514
Mike Digman1e28a5a2018-02-14 10:49:19 -0800515 public void setRotateSuggestionButtonState(final boolean visible) {
516 setRotateSuggestionButtonState(visible, false);
517 }
518
519 public void setRotateSuggestionButtonState(final boolean visible, final boolean force) {
520 if (mNavigationBarView == null) return;
521
522 // At any point the the button can become invisible because an a11y service became active.
523 // Similarly, a call to make the button visible may be rejected because an a11y service is
524 // active. Must account for this.
525
526 ButtonDispatcher rotBtn = mNavigationBarView.getRotateSuggestionButton();
527 final boolean currentlyVisible = mNavigationBarView.isRotateButtonVisible();
528
529 // Rerun a show animation to indicate change but don't rerun a hide animation
530 if (!visible && !currentlyVisible) return;
531
532 View view = rotBtn.getCurrentView();
533 if (view == null) return;
534
535 KeyButtonDrawable kbd = rotBtn.getImageDrawable();
536 if (kbd == null) return;
537
Mike Digman5aeca792018-03-05 11:14:39 -0800538 // Clear any pending suggestion flag as it has either been nullified or is being shown
539 mPendingRotationSuggestion = false;
Mike Digmanf4c98992018-04-25 11:25:59 -0700540 if (getView() != null) getView().removeCallbacks(mCancelPendingRotationProposal);
Mike Digman5aeca792018-03-05 11:14:39 -0800541
542 // Handle the visibility change and animation
Mike Digman1e28a5a2018-02-14 10:49:19 -0800543 if (visible) { // Appear and change (cannot force)
Mike Digman85a9bea2018-02-23 15:08:53 -0800544 // Stop and clear any currently running hide animations
Mike Digman1e28a5a2018-02-14 10:49:19 -0800545 if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) {
Mike Digman85a9bea2018-02-23 15:08:53 -0800546 mRotateHideAnimator.cancel();
Mike Digman1e28a5a2018-02-14 10:49:19 -0800547 }
Mike Digman85a9bea2018-02-23 15:08:53 -0800548 mRotateHideAnimator = null;
Mike Digman1e28a5a2018-02-14 10:49:19 -0800549
550 // Reset the alpha if any has changed due to hide animation
551 view.setAlpha(1f);
552
553 // Run the rotate icon's animation if it has one
Matthew Ngd6865ba2018-08-27 17:58:41 -0700554 if (kbd.canAnimate()) {
555 kbd.resetAnimation();
556 kbd.startAnimation();
Mike Digman1e28a5a2018-02-14 10:49:19 -0800557 }
558
Mike Digman50752642018-02-15 13:36:09 -0800559 if (!isRotateSuggestionIntroduced()) mViewRippler.start(view);
560
Mike Digman1e28a5a2018-02-14 10:49:19 -0800561 // Set visibility, may fail if a11y service is active.
562 // If invisible, call will stop animation.
Mike Digman9b50b762018-04-19 10:50:35 -0700563 int appliedVisibility = mNavigationBarView.setRotateButtonVisibility(true);
564 if (appliedVisibility == View.VISIBLE) {
565 // If the button will actually become visible and the navbar is about to hide,
566 // tell the statusbar to keep it around for longer
567 mStatusBar.touchAutoHide();
568 }
Mike Digman1e28a5a2018-02-14 10:49:19 -0800569
570 } else { // Hide
571
Mike Digman50752642018-02-15 13:36:09 -0800572 mViewRippler.stop(); // Prevent any pending ripples, force hide or not
573
Mike Digman1e28a5a2018-02-14 10:49:19 -0800574 if (force) {
575 // If a hide animator is running stop it and make invisible
576 if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) {
577 mRotateHideAnimator.pause();
578 }
579 mNavigationBarView.setRotateButtonVisibility(false);
580 return;
581 }
582
583 // Don't start any new hide animations if one is running
584 if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) return;
585
586 ObjectAnimator fadeOut = ObjectAnimator.ofFloat(view, "alpha",
587 0f);
588 fadeOut.setDuration(BUTTON_FADE_IN_OUT_DURATION_MS);
589 fadeOut.setInterpolator(Interpolators.LINEAR);
590 fadeOut.addListener(new AnimatorListenerAdapter() {
591 @Override
592 public void onAnimationEnd(Animator animation) {
593 mNavigationBarView.setRotateButtonVisibility(false);
594 }
595 });
596
597 mRotateHideAnimator = fadeOut;
598 fadeOut.start();
Mike Digmana48cf192018-02-12 17:52:48 -0800599 }
600 }
601
Mike Digman90402952018-01-22 16:05:51 -0800602 private void rescheduleRotationTimeout(final boolean reasonHover) {
603 // May be called due to a new rotation proposal or a change in hover state
604 if (reasonHover) {
605 // Don't reschedule if a hide animator is running
Mike Digman1e28a5a2018-02-14 10:49:19 -0800606 if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) return;
Mike Digman90402952018-01-22 16:05:51 -0800607 // Don't reschedule if not visible
Mike Digman1e28a5a2018-02-14 10:49:19 -0800608 if (!mNavigationBarView.isRotateButtonVisible()) return;
Mike Digman90402952018-01-22 16:05:51 -0800609 }
610
Mike Digman5aeca792018-03-05 11:14:39 -0800611 getView().removeCallbacks(mRemoveRotationProposal); // Stop any pending removal
612 getView().postDelayed(mRemoveRotationProposal,
Mike Digman90402952018-01-22 16:05:51 -0800613 computeRotationProposalTimeout()); // Schedule timeout
614 }
615
616 private int computeRotationProposalTimeout() {
617 if (mAccessibilityFeedbackEnabled) return 20000;
618 if (mHoveringRotationSuggestion) return 16000;
Mike Digmand13e43b2018-05-21 11:23:56 -0700619 return 10000;
Mike Digman90402952018-01-22 16:05:51 -0800620 }
621
Mike Digman50752642018-02-15 13:36:09 -0800622 private boolean isRotateSuggestionIntroduced() {
623 ContentResolver cr = getContext().getContentResolver();
624 return Settings.Secure.getInt(cr, Settings.Secure.NUM_ROTATION_SUGGESTIONS_ACCEPTED, 0)
625 >= NUM_ACCEPTED_ROTATION_SUGGESTIONS_FOR_INTRODUCTION;
626 }
627
628 private void incrementNumAcceptedRotationSuggestionsIfNeeded() {
629 // Get the number of accepted suggestions
630 ContentResolver cr = getContext().getContentResolver();
631 final int numSuggestions = Settings.Secure.getInt(cr,
632 Settings.Secure.NUM_ROTATION_SUGGESTIONS_ACCEPTED, 0);
633
634 // Increment the number of accepted suggestions only if it would change intro mode
635 if (numSuggestions < NUM_ACCEPTED_ROTATION_SUGGESTIONS_FOR_INTRODUCTION) {
636 Settings.Secure.putInt(cr, Settings.Secure.NUM_ROTATION_SUGGESTIONS_ACCEPTED,
637 numSuggestions + 1);
638 }
639 }
640
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500641 // Injected from StatusBar at creation.
Jason Monk49fa0162017-01-11 09:21:56 -0500642 public void setCurrentSysuiVisibility(int systemUiVisibility) {
643 mSystemUiVisibility = systemUiVisibility;
Matthew Ng5a250202018-10-09 16:09:27 -0700644 final int barMode = mStatusBar.computeBarMode(0, mSystemUiVisibility,
Jason Monk49fa0162017-01-11 09:21:56 -0500645 View.NAVIGATION_BAR_TRANSIENT, View.NAVIGATION_BAR_TRANSLUCENT,
646 View.NAVIGATION_BAR_TRANSPARENT);
Matthew Ng5a250202018-10-09 16:09:27 -0700647 if (barMode != -1) {
648 mNavigationBarMode = barMode;
649 }
Jason Monk49fa0162017-01-11 09:21:56 -0500650 checkNavBarModes();
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500651 mStatusBar.touchAutoHide();
Jason Monk49fa0162017-01-11 09:21:56 -0500652 mLightBarController.onNavigationVisibilityChanged(mSystemUiVisibility, 0 /* mask */,
653 true /* nbModeChanged */, mNavigationBarMode);
654 }
655
656 @Override
657 public void setSystemUiVisibility(int vis, int fullscreenStackVis, int dockedStackVis,
658 int mask, Rect fullscreenStackBounds, Rect dockedStackBounds) {
659 final int oldVal = mSystemUiVisibility;
660 final int newVal = (oldVal & ~mask) | (vis & mask);
661 final int diff = newVal ^ oldVal;
662 boolean nbModeChanged = false;
663 if (diff != 0) {
664 mSystemUiVisibility = newVal;
665
666 // update navigation bar mode
667 final int nbMode = getView() == null
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500668 ? -1 : mStatusBar.computeBarMode(oldVal, newVal,
Jason Monk49fa0162017-01-11 09:21:56 -0500669 View.NAVIGATION_BAR_TRANSIENT, View.NAVIGATION_BAR_TRANSLUCENT,
670 View.NAVIGATION_BAR_TRANSPARENT);
671 nbModeChanged = nbMode != -1;
672 if (nbModeChanged) {
673 if (mNavigationBarMode != nbMode) {
Tracy Zhou1ac592c2018-07-25 13:47:37 -0700674 if (mNavigationBarMode == MODE_TRANSPARENT
675 || mNavigationBarMode == MODE_LIGHTS_OUT_TRANSPARENT) {
676 mNavigationBarView.hideRecentsOnboarding();
677 }
Jason Monk49fa0162017-01-11 09:21:56 -0500678 mNavigationBarMode = nbMode;
679 checkNavBarModes();
680 }
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500681 mStatusBar.touchAutoHide();
Jason Monk49fa0162017-01-11 09:21:56 -0500682 }
683 }
684
685 mLightBarController.onNavigationVisibilityChanged(vis, mask, nbModeChanged,
686 mNavigationBarMode);
687 }
688
689 @Override
690 public void disable(int state1, int state2, boolean animate) {
Mike Digmandd2f49e2018-03-16 10:54:22 -0700691 // Navigation bar flags are in both state1 and state2.
692 final int masked = state1 & (StatusBarManager.DISABLE_HOME
Jason Monk49fa0162017-01-11 09:21:56 -0500693 | StatusBarManager.DISABLE_RECENT
694 | StatusBarManager.DISABLE_BACK
695 | StatusBarManager.DISABLE_SEARCH);
696 if (masked != mDisabledFlags1) {
697 mDisabledFlags1 = masked;
698 if (mNavigationBarView != null) mNavigationBarView.setDisabledFlags(state1);
Matthew Ng9c3bce52018-02-01 22:00:31 +0000699 updateScreenPinningGestures();
Jason Monk49fa0162017-01-11 09:21:56 -0500700 }
Mike Digmandd2f49e2018-03-16 10:54:22 -0700701
702 final int masked2 = state2 & (StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS);
703 if (masked2 != mDisabledFlags2) {
704 mDisabledFlags2 = masked2;
705 setDisabled2Flags(masked2);
706 }
707 }
708
709 private void setDisabled2Flags(int state2) {
710 // Method only called on change of disable2 flags
711 final boolean rotateSuggestionsDisabled = hasDisable2RotateSuggestionFlag(state2);
712 if (rotateSuggestionsDisabled) onRotationSuggestionsDisabled();
713 }
714
715 private boolean hasDisable2RotateSuggestionFlag(int disable2Flags) {
716 return (disable2Flags & StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS) != 0;
Jason Monk49fa0162017-01-11 09:21:56 -0500717 }
718
719 // ----- Internal stuffz -----
720
721 private void refreshLayout(int layoutDirection) {
722 if (mNavigationBarView != null) {
723 mNavigationBarView.setLayoutDirection(layoutDirection);
724 }
725 }
726
727 private boolean shouldDisableNavbarGestures() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500728 return !mStatusBar.isDeviceProvisioned()
Matthew Ngfee0b5b2018-02-21 15:38:21 -0800729 || (mDisabledFlags1 & StatusBarManager.DISABLE_SEARCH) != 0;
Jason Monk49fa0162017-01-11 09:21:56 -0500730 }
731
732 private void repositionNavigationBar() {
733 if (mNavigationBarView == null || !mNavigationBarView.isAttachedToWindow()) return;
734
735 prepareNavigationBarView();
736
737 mWindowManager.updateViewLayout((View) mNavigationBarView.getParent(),
738 ((View) mNavigationBarView.getParent()).getLayoutParams());
739 }
740
Matthew Ng9c3bce52018-02-01 22:00:31 +0000741 private void updateScreenPinningGestures() {
742 if (mNavigationBarView == null) {
743 return;
744 }
745
746 // Change the cancel pin gesture to home and back if recents button is invisible
747 boolean recentsVisible = mNavigationBarView.isRecentsButtonVisible();
Matthew Ng9c3bce52018-02-01 22:00:31 +0000748 ButtonDispatcher backButton = mNavigationBarView.getBackButton();
749 if (recentsVisible) {
Matthew Ng9c3bce52018-02-01 22:00:31 +0000750 backButton.setOnLongClickListener(this::onLongPressBackRecents);
751 } else {
Matthew Ng9c3bce52018-02-01 22:00:31 +0000752 backButton.setOnLongClickListener(this::onLongPressBackHome);
753 }
754 }
755
Siarhei Vishniakoud002a0a2017-06-05 22:44:37 +0100756 private void notifyNavigationBarScreenOn() {
Matthew Ngd0a73e72018-03-02 15:16:03 -0800757 mNavigationBarView.updateNavButtonIcons();
Jason Monk49fa0162017-01-11 09:21:56 -0500758 }
759
760 private void prepareNavigationBarView() {
761 mNavigationBarView.reorient();
762
763 ButtonDispatcher recentsButton = mNavigationBarView.getRecentsButton();
764 recentsButton.setOnClickListener(this::onRecentsClick);
765 recentsButton.setOnTouchListener(this::onRecentsTouch);
766 recentsButton.setLongClickable(true);
767 recentsButton.setOnLongClickListener(this::onLongPressBackRecents);
768
769 ButtonDispatcher backButton = mNavigationBarView.getBackButton();
770 backButton.setLongClickable(true);
Jason Monk49fa0162017-01-11 09:21:56 -0500771
772 ButtonDispatcher homeButton = mNavigationBarView.getHomeButton();
773 homeButton.setOnTouchListener(this::onHomeTouch);
Matthew Ngfee0b5b2018-02-21 15:38:21 -0800774 homeButton.setOnLongClickListener(this::onHomeLongClick);
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800775
776 ButtonDispatcher accessibilityButton = mNavigationBarView.getAccessibilityButton();
777 accessibilityButton.setOnClickListener(this::onAccessibilityClick);
778 accessibilityButton.setOnLongClickListener(this::onAccessibilityLongClick);
Phil Weaverdb9a7742017-04-18 08:15:06 -0700779 updateAccessibilityServicesState(mAccessibilityManager);
Mike Digman7d092772018-01-11 12:10:32 -0800780
781 ButtonDispatcher rotateSuggestionButton = mNavigationBarView.getRotateSuggestionButton();
782 rotateSuggestionButton.setOnClickListener(this::onRotateSuggestionClick);
Mike Digman90402952018-01-22 16:05:51 -0800783 rotateSuggestionButton.setOnHoverListener(this::onRotateSuggestionHover);
Matthew Ng9c3bce52018-02-01 22:00:31 +0000784 updateScreenPinningGestures();
Jason Monk49fa0162017-01-11 09:21:56 -0500785 }
786
787 private boolean onHomeTouch(View v, MotionEvent event) {
788 if (mHomeBlockedThisTouch && event.getActionMasked() != MotionEvent.ACTION_DOWN) {
789 return true;
790 }
791 // If an incoming call is ringing, HOME is totally disabled.
792 // (The user is already on the InCallUI at this point,
793 // and his ONLY options are to answer or reject the call.)
794 switch (event.getAction()) {
795 case MotionEvent.ACTION_DOWN:
796 mHomeBlockedThisTouch = false;
797 TelecomManager telecomManager =
798 getContext().getSystemService(TelecomManager.class);
799 if (telecomManager != null && telecomManager.isRinging()) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500800 if (mStatusBar.isKeyguardShowing()) {
Jason Monk49fa0162017-01-11 09:21:56 -0500801 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call. " +
802 "No heads up");
803 mHomeBlockedThisTouch = true;
804 return true;
805 }
806 }
807 break;
808 case MotionEvent.ACTION_UP:
809 case MotionEvent.ACTION_CANCEL:
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500810 mStatusBar.awakenDreams();
Jason Monk49fa0162017-01-11 09:21:56 -0500811 break;
812 }
813 return false;
814 }
815
816 private void onVerticalChanged(boolean isVertical) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500817 mStatusBar.setQsScrimEnabled(!isVertical);
Jason Monk49fa0162017-01-11 09:21:56 -0500818 }
819
820 private boolean onNavigationTouch(View v, MotionEvent event) {
Eliot Courtneycb5d3162017-08-09 16:53:15 +0900821 mStatusBar.checkUserAutohide(event);
Jason Monk49fa0162017-01-11 09:21:56 -0500822 return false;
823 }
824
Jason Monk865246d2017-01-19 08:27:01 -0500825 @VisibleForTesting
826 boolean onHomeLongClick(View v) {
Matthew Ng6ff33b72018-02-27 13:47:38 -0800827 if (!mNavigationBarView.isRecentsButtonVisible()
828 && ActivityManagerWrapper.getInstance().isScreenPinningActive()) {
Matthew Ngfee0b5b2018-02-21 15:38:21 -0800829 return onLongPressBackHome(v);
830 }
Jason Monk49fa0162017-01-11 09:21:56 -0500831 if (shouldDisableNavbarGestures()) {
832 return false;
833 }
Matthew Ng2ea93b72018-03-14 19:43:18 +0000834 mNavigationBarView.onNavigationButtonLongPress(v);
Mike Digmanc94759d2018-01-23 11:01:21 -0800835 mMetricsLogger.action(MetricsEvent.ACTION_ASSIST_LONG_PRESS);
Jason Monk49fa0162017-01-11 09:21:56 -0500836 mAssistManager.startAssist(new Bundle() /* args */);
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500837 mStatusBar.awakenDreams();
Matthew Ngdc79e5c2017-12-14 17:37:35 -0800838
Jason Monk49fa0162017-01-11 09:21:56 -0500839 if (mNavigationBarView != null) {
840 mNavigationBarView.abortCurrentGesture();
841 }
842 return true;
843 }
844
845 // additional optimization when we have software system buttons - start loading the recent
846 // tasks on touch down
847 private boolean onRecentsTouch(View v, MotionEvent event) {
848 int action = event.getAction() & MotionEvent.ACTION_MASK;
849 if (action == MotionEvent.ACTION_DOWN) {
850 mCommandQueue.preloadRecentApps();
851 } else if (action == MotionEvent.ACTION_CANCEL) {
852 mCommandQueue.cancelPreloadRecentApps();
853 } else if (action == MotionEvent.ACTION_UP) {
854 if (!v.isPressed()) {
855 mCommandQueue.cancelPreloadRecentApps();
856 }
857 }
858 return false;
859 }
860
861 private void onRecentsClick(View v) {
862 if (LatencyTracker.isEnabled(getContext())) {
863 LatencyTracker.getInstance(getContext()).onActionStart(
864 LatencyTracker.ACTION_TOGGLE_RECENTS);
865 }
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500866 mStatusBar.awakenDreams();
Jason Monk49fa0162017-01-11 09:21:56 -0500867 mCommandQueue.toggleRecentApps();
868 }
869
Matthew Ng9c3bce52018-02-01 22:00:31 +0000870 private boolean onLongPressBackHome(View v) {
Matthew Ng2ea93b72018-03-14 19:43:18 +0000871 mNavigationBarView.onNavigationButtonLongPress(v);
Matthew Ng9c3bce52018-02-01 22:00:31 +0000872 return onLongPressNavigationButtons(v, R.id.back, R.id.home);
873 }
874
875 private boolean onLongPressBackRecents(View v) {
Matthew Ng2ea93b72018-03-14 19:43:18 +0000876 mNavigationBarView.onNavigationButtonLongPress(v);
Matthew Ng9c3bce52018-02-01 22:00:31 +0000877 return onLongPressNavigationButtons(v, R.id.back, R.id.recent_apps);
878 }
879
Jason Monk49fa0162017-01-11 09:21:56 -0500880 /**
Matthew Ng9c3bce52018-02-01 22:00:31 +0000881 * This handles long-press of both back and recents/home. Back is the common button with
882 * combination of recents if it is visible or home if recents is invisible.
883 * They are handled together to capture them both being long-pressed
Jason Monk49fa0162017-01-11 09:21:56 -0500884 * at the same time to exit screen pinning (lock task).
885 *
Matthew Ng9c3bce52018-02-01 22:00:31 +0000886 * When accessibility mode is on, only a long-press from recents/home
Jason Monk49fa0162017-01-11 09:21:56 -0500887 * is required to exit.
888 *
889 * In all other circumstances we try to pass through long-press events
890 * for Back, so that apps can still use it. Which can be from two things.
891 * 1) Not currently in screen pinning (lock task).
Matthew Ng9c3bce52018-02-01 22:00:31 +0000892 * 2) Back is long-pressed without recents/home.
Jason Monk49fa0162017-01-11 09:21:56 -0500893 */
Matthew Ng9c3bce52018-02-01 22:00:31 +0000894 private boolean onLongPressNavigationButtons(View v, @IdRes int btnId1, @IdRes int btnId2) {
Jason Monk49fa0162017-01-11 09:21:56 -0500895 try {
896 boolean sendBackLongPress = false;
Wale Ogunwale04d9cb52018-04-30 13:55:07 -0700897 IActivityTaskManager activityManager = ActivityTaskManager.getService();
Jason Monk49fa0162017-01-11 09:21:56 -0500898 boolean touchExplorationEnabled = mAccessibilityManager.isTouchExplorationEnabled();
899 boolean inLockTaskMode = activityManager.isInLockTaskMode();
900 if (inLockTaskMode && !touchExplorationEnabled) {
901 long time = System.currentTimeMillis();
Matthew Ng9c3bce52018-02-01 22:00:31 +0000902
Jason Monk49fa0162017-01-11 09:21:56 -0500903 // If we recently long-pressed the other button then they were
904 // long-pressed 'together'
905 if ((time - mLastLockToAppLongPress) < LOCK_TO_APP_GESTURE_TOLERENCE) {
Benjamin Franza83859f2017-07-03 16:34:14 +0100906 activityManager.stopSystemLockTaskMode();
Jason Monk49fa0162017-01-11 09:21:56 -0500907 // When exiting refresh disabled flags.
Matthew Ngd0a73e72018-03-02 15:16:03 -0800908 mNavigationBarView.updateNavButtonIcons();
Jason Monk49fa0162017-01-11 09:21:56 -0500909 return true;
Matthew Ng9c3bce52018-02-01 22:00:31 +0000910 } else if (v.getId() == btnId1) {
911 ButtonDispatcher button = btnId2 == R.id.recent_apps
912 ? mNavigationBarView.getRecentsButton()
913 : mNavigationBarView.getHomeButton();
914 if (!button.getCurrentView().isPressed()) {
915 // If we aren't pressing recents/home right now then they presses
916 // won't be together, so send the standard long-press action.
917 sendBackLongPress = true;
918 }
Jason Monk49fa0162017-01-11 09:21:56 -0500919 }
920 mLastLockToAppLongPress = time;
921 } else {
922 // If this is back still need to handle sending the long-press event.
Matthew Ng9c3bce52018-02-01 22:00:31 +0000923 if (v.getId() == btnId1) {
Jason Monk49fa0162017-01-11 09:21:56 -0500924 sendBackLongPress = true;
925 } else if (touchExplorationEnabled && inLockTaskMode) {
Matthew Ng9c3bce52018-02-01 22:00:31 +0000926 // When in accessibility mode a long press that is recents/home (not back)
Jason Monk49fa0162017-01-11 09:21:56 -0500927 // should stop lock task.
Benjamin Franza83859f2017-07-03 16:34:14 +0100928 activityManager.stopSystemLockTaskMode();
Jason Monk49fa0162017-01-11 09:21:56 -0500929 // When exiting refresh disabled flags.
Matthew Ngd0a73e72018-03-02 15:16:03 -0800930 mNavigationBarView.updateNavButtonIcons();
Jason Monk49fa0162017-01-11 09:21:56 -0500931 return true;
Matthew Ng9c3bce52018-02-01 22:00:31 +0000932 } else if (v.getId() == btnId2) {
933 return btnId2 == R.id.recent_apps
934 ? onLongPressRecents()
935 : onHomeLongClick(mNavigationBarView.getHomeButton().getCurrentView());
Jason Monk49fa0162017-01-11 09:21:56 -0500936 }
937 }
938 if (sendBackLongPress) {
939 KeyButtonView keyButtonView = (KeyButtonView) v;
940 keyButtonView.sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.FLAG_LONG_PRESS);
941 keyButtonView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED);
942 return true;
943 }
944 } catch (RemoteException e) {
945 Log.d(TAG, "Unable to reach activity manager", e);
946 }
947 return false;
948 }
949
950 private boolean onLongPressRecents() {
Wale Ogunwale65ebd952018-04-25 15:41:44 -0700951 if (mRecents == null || !ActivityTaskManager.supportsMultiWindow(getContext())
Matthew Ng43db6d22017-06-27 15:29:39 -0700952 || !mDivider.getView().getSnapAlgorithm().isSplitScreenFeasible()
Winson Chung67f5c8b2018-09-24 12:09:19 -0700953 || ActivityManager.isLowRamDeviceStatic()
Winson Chung074c4342018-03-26 17:27:19 -0700954 // If we are connected to the overview service, then disable the recents button
955 || mOverviewProxyService.getProxy() != null) {
Jason Monk49fa0162017-01-11 09:21:56 -0500956 return false;
957 }
958
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500959 return mStatusBar.toggleSplitScreenMode(MetricsEvent.ACTION_WINDOW_DOCK_LONGPRESS,
Jason Monk49fa0162017-01-11 09:21:56 -0500960 MetricsEvent.ACTION_WINDOW_UNDOCK_LONGPRESS);
961 }
962
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800963 private void onAccessibilityClick(View v) {
964 mAccessibilityManager.notifyAccessibilityButtonClicked();
965 }
966
967 private boolean onAccessibilityLongClick(View v) {
Casey Burkhardt5e8b9802017-03-24 10:07:20 -0700968 Intent intent = new Intent(AccessibilityManager.ACTION_CHOOSE_ACCESSIBILITY_BUTTON);
969 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
Casey Burkhardt5d614402017-04-06 13:46:50 -0700970 v.getContext().startActivityAsUser(intent, UserHandle.CURRENT);
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800971 return true;
972 }
973
Phil Weaverdb9a7742017-04-18 08:15:06 -0700974 private void updateAccessibilityServicesState(AccessibilityManager accessibilityManager) {
Casey Burkhardt74922c62017-02-13 12:43:16 -0800975 int requestingServices = 0;
976 try {
Casey Burkhardt5d614402017-04-06 13:46:50 -0700977 if (Settings.Secure.getIntForUser(mContentResolver,
978 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED,
979 UserHandle.USER_CURRENT) == 1) {
Casey Burkhardt74922c62017-02-13 12:43:16 -0800980 requestingServices++;
981 }
982 } catch (Settings.SettingNotFoundException e) {
983 }
984
Mike Digman90402952018-01-22 16:05:51 -0800985 boolean feedbackEnabled = false;
Casey Burkhardt5d614402017-04-06 13:46:50 -0700986 // AccessibilityManagerService resolves services for the current user since the local
987 // AccessibilityManager is created from a Context with the INTERACT_ACROSS_USERS permission
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800988 final List<AccessibilityServiceInfo> services =
Phil Weaverdb9a7742017-04-18 08:15:06 -0700989 accessibilityManager.getEnabledAccessibilityServiceList(
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800990 AccessibilityServiceInfo.FEEDBACK_ALL_MASK);
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800991 for (int i = services.size() - 1; i >= 0; --i) {
992 AccessibilityServiceInfo info = services.get(i);
993 if ((info.flags & AccessibilityServiceInfo.FLAG_REQUEST_ACCESSIBILITY_BUTTON) != 0) {
994 requestingServices++;
995 }
Mike Digman90402952018-01-22 16:05:51 -0800996
997 if (info.feedbackType != 0 && info.feedbackType !=
998 AccessibilityServiceInfo.FEEDBACK_GENERIC) {
999 feedbackEnabled = true;
1000 }
Casey Burkhardt048c2bc2016-12-08 16:09:20 -08001001 }
1002
Mike Digman90402952018-01-22 16:05:51 -08001003 mAccessibilityFeedbackEnabled = feedbackEnabled;
1004
Casey Burkhardt048c2bc2016-12-08 16:09:20 -08001005 final boolean showAccessibilityButton = requestingServices >= 1;
1006 final boolean targetSelection = requestingServices >= 2;
1007 mNavigationBarView.setAccessibilityButtonState(showAccessibilityButton, targetSelection);
1008 }
1009
Mike Digman7d092772018-01-11 12:10:32 -08001010 private void onRotateSuggestionClick(View v) {
Mike Digmanc94759d2018-01-23 11:01:21 -08001011 mMetricsLogger.action(MetricsEvent.ACTION_ROTATION_SUGGESTION_ACCEPTED);
Mike Digman50752642018-02-15 13:36:09 -08001012 incrementNumAcceptedRotationSuggestionsIfNeeded();
Mike Digman7d092772018-01-11 12:10:32 -08001013 mRotationLockController.setRotationLockedAtAngle(true, mLastRotationSuggestion);
1014 }
1015
Mike Digman90402952018-01-22 16:05:51 -08001016 private boolean onRotateSuggestionHover(View v, MotionEvent event) {
1017 final int action = event.getActionMasked();
1018 mHoveringRotationSuggestion = (action == MotionEvent.ACTION_HOVER_ENTER)
1019 || (action == MotionEvent.ACTION_HOVER_MOVE);
1020 rescheduleRotationTimeout(true);
1021 return false; // Must return false so a11y hover events are dispatched correctly.
1022 }
1023
Jason Monk2a6ea9c2017-01-26 11:14:51 -05001024 // ----- Methods that StatusBar talks to (should be minimized) -----
Jason Monk49fa0162017-01-11 09:21:56 -05001025
Jason Monk49fa0162017-01-11 09:21:56 -05001026 public void setLightBarController(LightBarController lightBarController) {
1027 mLightBarController = lightBarController;
1028 mLightBarController.setNavigationBar(mNavigationBarView.getLightTransitionsController());
1029 }
1030
1031 public boolean isSemiTransparent() {
1032 return mNavigationBarMode == MODE_SEMI_TRANSPARENT;
1033 }
1034
Jason Monk49fa0162017-01-11 09:21:56 -05001035 public void disableAnimationsDuringHide(long delay) {
1036 mNavigationBarView.setLayoutTransitionsEnabled(false);
1037 mNavigationBarView.postDelayed(() -> mNavigationBarView.setLayoutTransitionsEnabled(true),
1038 delay + StackStateAnimator.ANIMATION_DURATION_GO_TO_FULL_SHADE);
1039 }
1040
Jason Monk49fa0162017-01-11 09:21:56 -05001041 public BarTransitions getBarTransitions() {
1042 return mNavigationBarView.getBarTransitions();
1043 }
1044
1045 public void checkNavBarModes() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -05001046 mStatusBar.checkBarMode(mNavigationBarMode,
Jason Monk49fa0162017-01-11 09:21:56 -05001047 mNavigationBarWindowState, mNavigationBarView.getBarTransitions());
1048 }
1049
1050 public void finishBarAnimations() {
1051 mNavigationBarView.getBarTransitions().finishAnimations();
1052 }
1053
Jason Monk91e587e2017-04-13 13:41:23 -04001054 private final AccessibilityServicesStateChangeListener mAccessibilityListener =
1055 this::updateAccessibilityServicesState;
1056
Casey Burkhardt74922c62017-02-13 12:43:16 -08001057 private class MagnificationContentObserver extends ContentObserver {
1058
1059 public MagnificationContentObserver(Handler handler) {
1060 super(handler);
1061 }
1062
1063 @Override
1064 public void onChange(boolean selfChange) {
Phil Weaverdb9a7742017-04-18 08:15:06 -07001065 NavigationBarFragment.this.updateAccessibilityServicesState(mAccessibilityManager);
Casey Burkhardt74922c62017-02-13 12:43:16 -08001066 }
1067 }
1068
Jason Monk49fa0162017-01-11 09:21:56 -05001069 private final Stub mRotationWatcher = new Stub() {
1070 @Override
Mike Digman90402952018-01-22 16:05:51 -08001071 public void onRotationChanged(final int rotation) throws RemoteException {
Jason Monk49fa0162017-01-11 09:21:56 -05001072 // We need this to be scheduled as early as possible to beat the redrawing of
1073 // window in response to the orientation change.
1074 Handler h = getView().getHandler();
1075 Message msg = Message.obtain(h, () -> {
Mike Digman85ff7fa2018-01-23 14:59:52 -08001076
1077 // If the screen rotation changes while locked, potentially update lock to flow with
Mike Digman90402952018-01-22 16:05:51 -08001078 // new screen rotation and hide any showing suggestions.
1079 if (mRotationLockController.isRotationLocked()) {
Mike Digman85ff7fa2018-01-23 14:59:52 -08001080 if (shouldOverrideUserLockPrefs(rotation)) {
1081 mRotationLockController.setRotationLockedAtAngle(true, rotation);
1082 }
Mike Digman1e28a5a2018-02-14 10:49:19 -08001083 setRotateSuggestionButtonState(false, true);
Mike Digman90402952018-01-22 16:05:51 -08001084 }
1085
Jason Monk49fa0162017-01-11 09:21:56 -05001086 if (mNavigationBarView != null
1087 && mNavigationBarView.needsReorient(rotation)) {
1088 repositionNavigationBar();
1089 }
1090 });
1091 msg.setAsynchronous(true);
1092 h.sendMessageAtFrontOfQueue(msg);
1093 }
Mike Digman85ff7fa2018-01-23 14:59:52 -08001094
1095 private boolean shouldOverrideUserLockPrefs(final int rotation) {
Mike Digmanab650252018-03-06 11:01:41 -08001096 // Only override user prefs when returning to the natural rotation (normally portrait).
Mike Digman85ff7fa2018-01-23 14:59:52 -08001097 // Don't let apps that force landscape or 180 alter user lock.
Mike Digmanab650252018-03-06 11:01:41 -08001098 return rotation == NATURAL_ROTATION;
Mike Digman85ff7fa2018-01-23 14:59:52 -08001099 }
Jason Monk49fa0162017-01-11 09:21:56 -05001100 };
1101
1102 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1103 @Override
1104 public void onReceive(Context context, Intent intent) {
1105 String action = intent.getAction();
Siarhei Vishniakoud002a0a2017-06-05 22:44:37 +01001106 if (Intent.ACTION_SCREEN_OFF.equals(action)
1107 || Intent.ACTION_SCREEN_ON.equals(action)) {
1108 notifyNavigationBarScreenOn();
Jason Monk49fa0162017-01-11 09:21:56 -05001109 }
Phil Weavera858c5f2018-04-26 13:27:30 -07001110 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
1111 // The accessibility settings may be different for the new user
1112 updateAccessibilityServicesState(mAccessibilityManager);
1113 };
Jason Monk49fa0162017-01-11 09:21:56 -05001114 }
1115 };
1116
Winson Chung67f5c8b2018-09-24 12:09:19 -07001117 class TaskStackListenerImpl extends TaskStackChangeListener {
Mike Digman7d092772018-01-11 12:10:32 -08001118 // Invalidate any rotation suggestion on task change or activity orientation change
1119 // Note: all callbacks happen on main thread
1120
1121 @Override
1122 public void onTaskStackChanged() {
Mike Digman1e28a5a2018-02-14 10:49:19 -08001123 setRotateSuggestionButtonState(false);
Mike Digman7d092772018-01-11 12:10:32 -08001124 }
1125
1126 @Override
1127 public void onTaskRemoved(int taskId) {
Mike Digman1e28a5a2018-02-14 10:49:19 -08001128 setRotateSuggestionButtonState(false);
Mike Digman7d092772018-01-11 12:10:32 -08001129 }
1130
1131 @Override
1132 public void onTaskMovedToFront(int taskId) {
Mike Digman1e28a5a2018-02-14 10:49:19 -08001133 setRotateSuggestionButtonState(false);
Mike Digman7d092772018-01-11 12:10:32 -08001134 }
1135
1136 @Override
1137 public void onActivityRequestedOrientationChanged(int taskId, int requestedOrientation) {
Mike Digman85a9bea2018-02-23 15:08:53 -08001138 // Only hide the icon if the top task changes its requestedOrientation
1139 // Launcher can alter its requestedOrientation while it's not on top, don't hide on this
Mike Digman121b11f2018-04-04 12:45:24 -07001140 Optional.ofNullable(ActivityManagerWrapper.getInstance())
1141 .map(ActivityManagerWrapper::getRunningTask)
1142 .ifPresent(a -> {
1143 if (a.id == taskId) setRotateSuggestionButtonState(false);
1144 });
Mike Digman7d092772018-01-11 12:10:32 -08001145 }
1146 }
1147
Mike Digman50752642018-02-15 13:36:09 -08001148 private class ViewRippler {
1149 private static final int RIPPLE_OFFSET_MS = 50;
1150 private static final int RIPPLE_INTERVAL_MS = 2000;
1151 private View mRoot;
1152
1153 public void start(View root) {
1154 stop(); // Stop any pending ripple animations
1155
1156 mRoot = root;
1157
1158 // Schedule pending ripples, offset the 1st to avoid problems with visibility change
1159 mRoot.postOnAnimationDelayed(mRipple, RIPPLE_OFFSET_MS);
1160 mRoot.postOnAnimationDelayed(mRipple, RIPPLE_INTERVAL_MS);
1161 mRoot.postOnAnimationDelayed(mRipple, 2*RIPPLE_INTERVAL_MS);
Mike Digmanc038c322018-05-24 11:06:05 -07001162 mRoot.postOnAnimationDelayed(mRipple, 3*RIPPLE_INTERVAL_MS);
1163 mRoot.postOnAnimationDelayed(mRipple, 4*RIPPLE_INTERVAL_MS);
Mike Digman50752642018-02-15 13:36:09 -08001164 }
1165
1166 public void stop() {
1167 if (mRoot != null) mRoot.removeCallbacks(mRipple);
1168 }
1169
1170 private final Runnable mRipple = new Runnable() {
1171 @Override
1172 public void run() { // Cause the ripple to fire via false presses
Mike Digmanf4c98992018-04-25 11:25:59 -07001173 if (!mRoot.isAttachedToWindow()) return;
Mike Digman50752642018-02-15 13:36:09 -08001174 mRoot.setPressed(true);
1175 mRoot.setPressed(false);
1176 }
1177 };
1178 }
1179
Jason Monk49fa0162017-01-11 09:21:56 -05001180 public static View create(Context context, FragmentListener listener) {
1181 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1182 LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
1183 WindowManager.LayoutParams.TYPE_NAVIGATION_BAR,
1184 WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
1185 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1186 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
1187 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
1188 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
1189 | WindowManager.LayoutParams.FLAG_SLIPPERY,
1190 PixelFormat.TRANSLUCENT);
1191 lp.token = new Binder();
Jason Monk49fa0162017-01-11 09:21:56 -05001192 lp.setTitle("NavigationBar");
Phil Weaver8583ae82018-02-13 11:01:24 -08001193 lp.accessibilityTitle = context.getString(R.string.nav_bar);
Jason Monk49fa0162017-01-11 09:21:56 -05001194 lp.windowAnimations = 0;
1195
1196 View navigationBarView = LayoutInflater.from(context).inflate(
1197 R.layout.navigation_bar_window, null);
1198
1199 if (DEBUG) Log.v(TAG, "addNavigationBar: about to add " + navigationBarView);
1200 if (navigationBarView == null) return null;
1201
1202 context.getSystemService(WindowManager.class).addView(navigationBarView, lp);
1203 FragmentHostManager fragmentHost = FragmentHostManager.get(navigationBarView);
1204 NavigationBarFragment fragment = new NavigationBarFragment();
1205 fragmentHost.getFragmentManager().beginTransaction()
1206 .replace(R.id.navigation_bar_frame, fragment, TAG)
1207 .commit();
1208 fragmentHost.addTagListener(TAG, listener);
1209 return navigationBarView;
1210 }
1211}