blob: 019874132c856e46a5be606badc3b2ef8bba18c4 [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 Ngb687c8a2018-10-02 11:31:38 -0700198 if (QuickStepController.shouldhideBackButton(getContext())) {
Matthew Ngc83b9892018-08-21 16:31:13 -0700199 // 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
Winson Chung67f5c8b2018-09-24 12:09:19 -0700287 mNavigationBarView.setComponents(mStatusBar.getPanel());
Matthew Ngf0f84542018-10-15 11:53:22 -0700288 mNavigationBarView.setDisabledFlags(mDisabledFlags1);
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;
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500644 mNavigationBarMode = 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);
647 checkNavBarModes();
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500648 mStatusBar.touchAutoHide();
Jason Monk49fa0162017-01-11 09:21:56 -0500649 mLightBarController.onNavigationVisibilityChanged(mSystemUiVisibility, 0 /* mask */,
650 true /* nbModeChanged */, mNavigationBarMode);
651 }
652
653 @Override
654 public void setSystemUiVisibility(int vis, int fullscreenStackVis, int dockedStackVis,
655 int mask, Rect fullscreenStackBounds, Rect dockedStackBounds) {
656 final int oldVal = mSystemUiVisibility;
657 final int newVal = (oldVal & ~mask) | (vis & mask);
658 final int diff = newVal ^ oldVal;
659 boolean nbModeChanged = false;
660 if (diff != 0) {
661 mSystemUiVisibility = newVal;
662
663 // update navigation bar mode
664 final int nbMode = getView() == null
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500665 ? -1 : mStatusBar.computeBarMode(oldVal, newVal,
Jason Monk49fa0162017-01-11 09:21:56 -0500666 View.NAVIGATION_BAR_TRANSIENT, View.NAVIGATION_BAR_TRANSLUCENT,
667 View.NAVIGATION_BAR_TRANSPARENT);
668 nbModeChanged = nbMode != -1;
669 if (nbModeChanged) {
670 if (mNavigationBarMode != nbMode) {
Tracy Zhou1ac592c2018-07-25 13:47:37 -0700671 if (mNavigationBarMode == MODE_TRANSPARENT
672 || mNavigationBarMode == MODE_LIGHTS_OUT_TRANSPARENT) {
673 mNavigationBarView.hideRecentsOnboarding();
674 }
Jason Monk49fa0162017-01-11 09:21:56 -0500675 mNavigationBarMode = nbMode;
676 checkNavBarModes();
677 }
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500678 mStatusBar.touchAutoHide();
Jason Monk49fa0162017-01-11 09:21:56 -0500679 }
680 }
681
682 mLightBarController.onNavigationVisibilityChanged(vis, mask, nbModeChanged,
683 mNavigationBarMode);
684 }
685
686 @Override
687 public void disable(int state1, int state2, boolean animate) {
Mike Digmandd2f49e2018-03-16 10:54:22 -0700688 // Navigation bar flags are in both state1 and state2.
689 final int masked = state1 & (StatusBarManager.DISABLE_HOME
Jason Monk49fa0162017-01-11 09:21:56 -0500690 | StatusBarManager.DISABLE_RECENT
691 | StatusBarManager.DISABLE_BACK
692 | StatusBarManager.DISABLE_SEARCH);
693 if (masked != mDisabledFlags1) {
694 mDisabledFlags1 = masked;
695 if (mNavigationBarView != null) mNavigationBarView.setDisabledFlags(state1);
Matthew Ng9c3bce52018-02-01 22:00:31 +0000696 updateScreenPinningGestures();
Jason Monk49fa0162017-01-11 09:21:56 -0500697 }
Mike Digmandd2f49e2018-03-16 10:54:22 -0700698
699 final int masked2 = state2 & (StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS);
700 if (masked2 != mDisabledFlags2) {
701 mDisabledFlags2 = masked2;
702 setDisabled2Flags(masked2);
703 }
704 }
705
706 private void setDisabled2Flags(int state2) {
707 // Method only called on change of disable2 flags
708 final boolean rotateSuggestionsDisabled = hasDisable2RotateSuggestionFlag(state2);
709 if (rotateSuggestionsDisabled) onRotationSuggestionsDisabled();
710 }
711
712 private boolean hasDisable2RotateSuggestionFlag(int disable2Flags) {
713 return (disable2Flags & StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS) != 0;
Jason Monk49fa0162017-01-11 09:21:56 -0500714 }
715
716 // ----- Internal stuffz -----
717
718 private void refreshLayout(int layoutDirection) {
719 if (mNavigationBarView != null) {
720 mNavigationBarView.setLayoutDirection(layoutDirection);
721 }
722 }
723
724 private boolean shouldDisableNavbarGestures() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500725 return !mStatusBar.isDeviceProvisioned()
Matthew Ngfee0b5b2018-02-21 15:38:21 -0800726 || (mDisabledFlags1 & StatusBarManager.DISABLE_SEARCH) != 0;
Jason Monk49fa0162017-01-11 09:21:56 -0500727 }
728
729 private void repositionNavigationBar() {
730 if (mNavigationBarView == null || !mNavigationBarView.isAttachedToWindow()) return;
731
732 prepareNavigationBarView();
733
734 mWindowManager.updateViewLayout((View) mNavigationBarView.getParent(),
735 ((View) mNavigationBarView.getParent()).getLayoutParams());
736 }
737
Matthew Ng9c3bce52018-02-01 22:00:31 +0000738 private void updateScreenPinningGestures() {
739 if (mNavigationBarView == null) {
740 return;
741 }
742
743 // Change the cancel pin gesture to home and back if recents button is invisible
744 boolean recentsVisible = mNavigationBarView.isRecentsButtonVisible();
Matthew Ng9c3bce52018-02-01 22:00:31 +0000745 ButtonDispatcher backButton = mNavigationBarView.getBackButton();
746 if (recentsVisible) {
Matthew Ng9c3bce52018-02-01 22:00:31 +0000747 backButton.setOnLongClickListener(this::onLongPressBackRecents);
748 } else {
Matthew Ng9c3bce52018-02-01 22:00:31 +0000749 backButton.setOnLongClickListener(this::onLongPressBackHome);
750 }
751 }
752
Siarhei Vishniakoud002a0a2017-06-05 22:44:37 +0100753 private void notifyNavigationBarScreenOn() {
Matthew Ngd0a73e72018-03-02 15:16:03 -0800754 mNavigationBarView.updateNavButtonIcons();
Jason Monk49fa0162017-01-11 09:21:56 -0500755 }
756
757 private void prepareNavigationBarView() {
758 mNavigationBarView.reorient();
759
760 ButtonDispatcher recentsButton = mNavigationBarView.getRecentsButton();
761 recentsButton.setOnClickListener(this::onRecentsClick);
762 recentsButton.setOnTouchListener(this::onRecentsTouch);
763 recentsButton.setLongClickable(true);
764 recentsButton.setOnLongClickListener(this::onLongPressBackRecents);
765
766 ButtonDispatcher backButton = mNavigationBarView.getBackButton();
767 backButton.setLongClickable(true);
Jason Monk49fa0162017-01-11 09:21:56 -0500768
769 ButtonDispatcher homeButton = mNavigationBarView.getHomeButton();
770 homeButton.setOnTouchListener(this::onHomeTouch);
Matthew Ngfee0b5b2018-02-21 15:38:21 -0800771 homeButton.setOnLongClickListener(this::onHomeLongClick);
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800772
773 ButtonDispatcher accessibilityButton = mNavigationBarView.getAccessibilityButton();
774 accessibilityButton.setOnClickListener(this::onAccessibilityClick);
775 accessibilityButton.setOnLongClickListener(this::onAccessibilityLongClick);
Phil Weaverdb9a7742017-04-18 08:15:06 -0700776 updateAccessibilityServicesState(mAccessibilityManager);
Mike Digman7d092772018-01-11 12:10:32 -0800777
778 ButtonDispatcher rotateSuggestionButton = mNavigationBarView.getRotateSuggestionButton();
779 rotateSuggestionButton.setOnClickListener(this::onRotateSuggestionClick);
Mike Digman90402952018-01-22 16:05:51 -0800780 rotateSuggestionButton.setOnHoverListener(this::onRotateSuggestionHover);
Matthew Ng9c3bce52018-02-01 22:00:31 +0000781 updateScreenPinningGestures();
Jason Monk49fa0162017-01-11 09:21:56 -0500782 }
783
784 private boolean onHomeTouch(View v, MotionEvent event) {
785 if (mHomeBlockedThisTouch && event.getActionMasked() != MotionEvent.ACTION_DOWN) {
786 return true;
787 }
788 // If an incoming call is ringing, HOME is totally disabled.
789 // (The user is already on the InCallUI at this point,
790 // and his ONLY options are to answer or reject the call.)
791 switch (event.getAction()) {
792 case MotionEvent.ACTION_DOWN:
793 mHomeBlockedThisTouch = false;
794 TelecomManager telecomManager =
795 getContext().getSystemService(TelecomManager.class);
796 if (telecomManager != null && telecomManager.isRinging()) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500797 if (mStatusBar.isKeyguardShowing()) {
Jason Monk49fa0162017-01-11 09:21:56 -0500798 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call. " +
799 "No heads up");
800 mHomeBlockedThisTouch = true;
801 return true;
802 }
803 }
804 break;
805 case MotionEvent.ACTION_UP:
806 case MotionEvent.ACTION_CANCEL:
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500807 mStatusBar.awakenDreams();
Jason Monk49fa0162017-01-11 09:21:56 -0500808 break;
809 }
810 return false;
811 }
812
813 private void onVerticalChanged(boolean isVertical) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500814 mStatusBar.setQsScrimEnabled(!isVertical);
Jason Monk49fa0162017-01-11 09:21:56 -0500815 }
816
817 private boolean onNavigationTouch(View v, MotionEvent event) {
Eliot Courtneycb5d3162017-08-09 16:53:15 +0900818 mStatusBar.checkUserAutohide(event);
Jason Monk49fa0162017-01-11 09:21:56 -0500819 return false;
820 }
821
Jason Monk865246d2017-01-19 08:27:01 -0500822 @VisibleForTesting
823 boolean onHomeLongClick(View v) {
Matthew Ng6ff33b72018-02-27 13:47:38 -0800824 if (!mNavigationBarView.isRecentsButtonVisible()
825 && ActivityManagerWrapper.getInstance().isScreenPinningActive()) {
Matthew Ngfee0b5b2018-02-21 15:38:21 -0800826 return onLongPressBackHome(v);
827 }
Jason Monk49fa0162017-01-11 09:21:56 -0500828 if (shouldDisableNavbarGestures()) {
829 return false;
830 }
Matthew Ng2ea93b72018-03-14 19:43:18 +0000831 mNavigationBarView.onNavigationButtonLongPress(v);
Mike Digmanc94759d2018-01-23 11:01:21 -0800832 mMetricsLogger.action(MetricsEvent.ACTION_ASSIST_LONG_PRESS);
Jason Monk49fa0162017-01-11 09:21:56 -0500833 mAssistManager.startAssist(new Bundle() /* args */);
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500834 mStatusBar.awakenDreams();
Matthew Ngdc79e5c2017-12-14 17:37:35 -0800835
Jason Monk49fa0162017-01-11 09:21:56 -0500836 if (mNavigationBarView != null) {
837 mNavigationBarView.abortCurrentGesture();
838 }
839 return true;
840 }
841
842 // additional optimization when we have software system buttons - start loading the recent
843 // tasks on touch down
844 private boolean onRecentsTouch(View v, MotionEvent event) {
845 int action = event.getAction() & MotionEvent.ACTION_MASK;
846 if (action == MotionEvent.ACTION_DOWN) {
847 mCommandQueue.preloadRecentApps();
848 } else if (action == MotionEvent.ACTION_CANCEL) {
849 mCommandQueue.cancelPreloadRecentApps();
850 } else if (action == MotionEvent.ACTION_UP) {
851 if (!v.isPressed()) {
852 mCommandQueue.cancelPreloadRecentApps();
853 }
854 }
855 return false;
856 }
857
858 private void onRecentsClick(View v) {
859 if (LatencyTracker.isEnabled(getContext())) {
860 LatencyTracker.getInstance(getContext()).onActionStart(
861 LatencyTracker.ACTION_TOGGLE_RECENTS);
862 }
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500863 mStatusBar.awakenDreams();
Jason Monk49fa0162017-01-11 09:21:56 -0500864 mCommandQueue.toggleRecentApps();
865 }
866
Matthew Ng9c3bce52018-02-01 22:00:31 +0000867 private boolean onLongPressBackHome(View v) {
Matthew Ng2ea93b72018-03-14 19:43:18 +0000868 mNavigationBarView.onNavigationButtonLongPress(v);
Matthew Ng9c3bce52018-02-01 22:00:31 +0000869 return onLongPressNavigationButtons(v, R.id.back, R.id.home);
870 }
871
872 private boolean onLongPressBackRecents(View v) {
Matthew Ng2ea93b72018-03-14 19:43:18 +0000873 mNavigationBarView.onNavigationButtonLongPress(v);
Matthew Ng9c3bce52018-02-01 22:00:31 +0000874 return onLongPressNavigationButtons(v, R.id.back, R.id.recent_apps);
875 }
876
Jason Monk49fa0162017-01-11 09:21:56 -0500877 /**
Matthew Ng9c3bce52018-02-01 22:00:31 +0000878 * This handles long-press of both back and recents/home. Back is the common button with
879 * combination of recents if it is visible or home if recents is invisible.
880 * They are handled together to capture them both being long-pressed
Jason Monk49fa0162017-01-11 09:21:56 -0500881 * at the same time to exit screen pinning (lock task).
882 *
Matthew Ng9c3bce52018-02-01 22:00:31 +0000883 * When accessibility mode is on, only a long-press from recents/home
Jason Monk49fa0162017-01-11 09:21:56 -0500884 * is required to exit.
885 *
886 * In all other circumstances we try to pass through long-press events
887 * for Back, so that apps can still use it. Which can be from two things.
888 * 1) Not currently in screen pinning (lock task).
Matthew Ng9c3bce52018-02-01 22:00:31 +0000889 * 2) Back is long-pressed without recents/home.
Jason Monk49fa0162017-01-11 09:21:56 -0500890 */
Matthew Ng9c3bce52018-02-01 22:00:31 +0000891 private boolean onLongPressNavigationButtons(View v, @IdRes int btnId1, @IdRes int btnId2) {
Jason Monk49fa0162017-01-11 09:21:56 -0500892 try {
893 boolean sendBackLongPress = false;
Wale Ogunwale04d9cb52018-04-30 13:55:07 -0700894 IActivityTaskManager activityManager = ActivityTaskManager.getService();
Jason Monk49fa0162017-01-11 09:21:56 -0500895 boolean touchExplorationEnabled = mAccessibilityManager.isTouchExplorationEnabled();
896 boolean inLockTaskMode = activityManager.isInLockTaskMode();
897 if (inLockTaskMode && !touchExplorationEnabled) {
898 long time = System.currentTimeMillis();
Matthew Ng9c3bce52018-02-01 22:00:31 +0000899
Jason Monk49fa0162017-01-11 09:21:56 -0500900 // If we recently long-pressed the other button then they were
901 // long-pressed 'together'
902 if ((time - mLastLockToAppLongPress) < LOCK_TO_APP_GESTURE_TOLERENCE) {
Benjamin Franza83859f2017-07-03 16:34:14 +0100903 activityManager.stopSystemLockTaskMode();
Jason Monk49fa0162017-01-11 09:21:56 -0500904 // When exiting refresh disabled flags.
Matthew Ngd0a73e72018-03-02 15:16:03 -0800905 mNavigationBarView.updateNavButtonIcons();
Jason Monk49fa0162017-01-11 09:21:56 -0500906 return true;
Matthew Ng9c3bce52018-02-01 22:00:31 +0000907 } else if (v.getId() == btnId1) {
908 ButtonDispatcher button = btnId2 == R.id.recent_apps
909 ? mNavigationBarView.getRecentsButton()
910 : mNavigationBarView.getHomeButton();
911 if (!button.getCurrentView().isPressed()) {
912 // If we aren't pressing recents/home right now then they presses
913 // won't be together, so send the standard long-press action.
914 sendBackLongPress = true;
915 }
Jason Monk49fa0162017-01-11 09:21:56 -0500916 }
917 mLastLockToAppLongPress = time;
918 } else {
919 // If this is back still need to handle sending the long-press event.
Matthew Ng9c3bce52018-02-01 22:00:31 +0000920 if (v.getId() == btnId1) {
Jason Monk49fa0162017-01-11 09:21:56 -0500921 sendBackLongPress = true;
922 } else if (touchExplorationEnabled && inLockTaskMode) {
Matthew Ng9c3bce52018-02-01 22:00:31 +0000923 // When in accessibility mode a long press that is recents/home (not back)
Jason Monk49fa0162017-01-11 09:21:56 -0500924 // should stop lock task.
Benjamin Franza83859f2017-07-03 16:34:14 +0100925 activityManager.stopSystemLockTaskMode();
Jason Monk49fa0162017-01-11 09:21:56 -0500926 // When exiting refresh disabled flags.
Matthew Ngd0a73e72018-03-02 15:16:03 -0800927 mNavigationBarView.updateNavButtonIcons();
Jason Monk49fa0162017-01-11 09:21:56 -0500928 return true;
Matthew Ng9c3bce52018-02-01 22:00:31 +0000929 } else if (v.getId() == btnId2) {
930 return btnId2 == R.id.recent_apps
931 ? onLongPressRecents()
932 : onHomeLongClick(mNavigationBarView.getHomeButton().getCurrentView());
Jason Monk49fa0162017-01-11 09:21:56 -0500933 }
934 }
935 if (sendBackLongPress) {
936 KeyButtonView keyButtonView = (KeyButtonView) v;
937 keyButtonView.sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.FLAG_LONG_PRESS);
938 keyButtonView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED);
939 return true;
940 }
941 } catch (RemoteException e) {
942 Log.d(TAG, "Unable to reach activity manager", e);
943 }
944 return false;
945 }
946
947 private boolean onLongPressRecents() {
Wale Ogunwale65ebd952018-04-25 15:41:44 -0700948 if (mRecents == null || !ActivityTaskManager.supportsMultiWindow(getContext())
Matthew Ng43db6d22017-06-27 15:29:39 -0700949 || !mDivider.getView().getSnapAlgorithm().isSplitScreenFeasible()
Winson Chung67f5c8b2018-09-24 12:09:19 -0700950 || ActivityManager.isLowRamDeviceStatic()
Winson Chung074c4342018-03-26 17:27:19 -0700951 // If we are connected to the overview service, then disable the recents button
952 || mOverviewProxyService.getProxy() != null) {
Jason Monk49fa0162017-01-11 09:21:56 -0500953 return false;
954 }
955
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500956 return mStatusBar.toggleSplitScreenMode(MetricsEvent.ACTION_WINDOW_DOCK_LONGPRESS,
Jason Monk49fa0162017-01-11 09:21:56 -0500957 MetricsEvent.ACTION_WINDOW_UNDOCK_LONGPRESS);
958 }
959
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800960 private void onAccessibilityClick(View v) {
961 mAccessibilityManager.notifyAccessibilityButtonClicked();
962 }
963
964 private boolean onAccessibilityLongClick(View v) {
Casey Burkhardt5e8b9802017-03-24 10:07:20 -0700965 Intent intent = new Intent(AccessibilityManager.ACTION_CHOOSE_ACCESSIBILITY_BUTTON);
966 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
Casey Burkhardt5d614402017-04-06 13:46:50 -0700967 v.getContext().startActivityAsUser(intent, UserHandle.CURRENT);
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800968 return true;
969 }
970
Phil Weaverdb9a7742017-04-18 08:15:06 -0700971 private void updateAccessibilityServicesState(AccessibilityManager accessibilityManager) {
Casey Burkhardt74922c62017-02-13 12:43:16 -0800972 int requestingServices = 0;
973 try {
Casey Burkhardt5d614402017-04-06 13:46:50 -0700974 if (Settings.Secure.getIntForUser(mContentResolver,
975 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED,
976 UserHandle.USER_CURRENT) == 1) {
Casey Burkhardt74922c62017-02-13 12:43:16 -0800977 requestingServices++;
978 }
979 } catch (Settings.SettingNotFoundException e) {
980 }
981
Mike Digman90402952018-01-22 16:05:51 -0800982 boolean feedbackEnabled = false;
Casey Burkhardt5d614402017-04-06 13:46:50 -0700983 // AccessibilityManagerService resolves services for the current user since the local
984 // AccessibilityManager is created from a Context with the INTERACT_ACROSS_USERS permission
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800985 final List<AccessibilityServiceInfo> services =
Phil Weaverdb9a7742017-04-18 08:15:06 -0700986 accessibilityManager.getEnabledAccessibilityServiceList(
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800987 AccessibilityServiceInfo.FEEDBACK_ALL_MASK);
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800988 for (int i = services.size() - 1; i >= 0; --i) {
989 AccessibilityServiceInfo info = services.get(i);
990 if ((info.flags & AccessibilityServiceInfo.FLAG_REQUEST_ACCESSIBILITY_BUTTON) != 0) {
991 requestingServices++;
992 }
Mike Digman90402952018-01-22 16:05:51 -0800993
994 if (info.feedbackType != 0 && info.feedbackType !=
995 AccessibilityServiceInfo.FEEDBACK_GENERIC) {
996 feedbackEnabled = true;
997 }
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800998 }
999
Mike Digman90402952018-01-22 16:05:51 -08001000 mAccessibilityFeedbackEnabled = feedbackEnabled;
1001
Casey Burkhardt048c2bc2016-12-08 16:09:20 -08001002 final boolean showAccessibilityButton = requestingServices >= 1;
1003 final boolean targetSelection = requestingServices >= 2;
1004 mNavigationBarView.setAccessibilityButtonState(showAccessibilityButton, targetSelection);
1005 }
1006
Mike Digman7d092772018-01-11 12:10:32 -08001007 private void onRotateSuggestionClick(View v) {
Mike Digmanc94759d2018-01-23 11:01:21 -08001008 mMetricsLogger.action(MetricsEvent.ACTION_ROTATION_SUGGESTION_ACCEPTED);
Mike Digman50752642018-02-15 13:36:09 -08001009 incrementNumAcceptedRotationSuggestionsIfNeeded();
Mike Digman7d092772018-01-11 12:10:32 -08001010 mRotationLockController.setRotationLockedAtAngle(true, mLastRotationSuggestion);
1011 }
1012
Mike Digman90402952018-01-22 16:05:51 -08001013 private boolean onRotateSuggestionHover(View v, MotionEvent event) {
1014 final int action = event.getActionMasked();
1015 mHoveringRotationSuggestion = (action == MotionEvent.ACTION_HOVER_ENTER)
1016 || (action == MotionEvent.ACTION_HOVER_MOVE);
1017 rescheduleRotationTimeout(true);
1018 return false; // Must return false so a11y hover events are dispatched correctly.
1019 }
1020
Jason Monk2a6ea9c2017-01-26 11:14:51 -05001021 // ----- Methods that StatusBar talks to (should be minimized) -----
Jason Monk49fa0162017-01-11 09:21:56 -05001022
Jason Monk49fa0162017-01-11 09:21:56 -05001023 public void setLightBarController(LightBarController lightBarController) {
1024 mLightBarController = lightBarController;
1025 mLightBarController.setNavigationBar(mNavigationBarView.getLightTransitionsController());
1026 }
1027
1028 public boolean isSemiTransparent() {
1029 return mNavigationBarMode == MODE_SEMI_TRANSPARENT;
1030 }
1031
Jason Monk49fa0162017-01-11 09:21:56 -05001032 public void disableAnimationsDuringHide(long delay) {
1033 mNavigationBarView.setLayoutTransitionsEnabled(false);
1034 mNavigationBarView.postDelayed(() -> mNavigationBarView.setLayoutTransitionsEnabled(true),
1035 delay + StackStateAnimator.ANIMATION_DURATION_GO_TO_FULL_SHADE);
1036 }
1037
Jason Monk49fa0162017-01-11 09:21:56 -05001038 public BarTransitions getBarTransitions() {
1039 return mNavigationBarView.getBarTransitions();
1040 }
1041
1042 public void checkNavBarModes() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -05001043 mStatusBar.checkBarMode(mNavigationBarMode,
Jason Monk49fa0162017-01-11 09:21:56 -05001044 mNavigationBarWindowState, mNavigationBarView.getBarTransitions());
1045 }
1046
1047 public void finishBarAnimations() {
1048 mNavigationBarView.getBarTransitions().finishAnimations();
1049 }
1050
Jason Monk91e587e2017-04-13 13:41:23 -04001051 private final AccessibilityServicesStateChangeListener mAccessibilityListener =
1052 this::updateAccessibilityServicesState;
1053
Casey Burkhardt74922c62017-02-13 12:43:16 -08001054 private class MagnificationContentObserver extends ContentObserver {
1055
1056 public MagnificationContentObserver(Handler handler) {
1057 super(handler);
1058 }
1059
1060 @Override
1061 public void onChange(boolean selfChange) {
Phil Weaverdb9a7742017-04-18 08:15:06 -07001062 NavigationBarFragment.this.updateAccessibilityServicesState(mAccessibilityManager);
Casey Burkhardt74922c62017-02-13 12:43:16 -08001063 }
1064 }
1065
Jason Monk49fa0162017-01-11 09:21:56 -05001066 private final Stub mRotationWatcher = new Stub() {
1067 @Override
Mike Digman90402952018-01-22 16:05:51 -08001068 public void onRotationChanged(final int rotation) throws RemoteException {
Jason Monk49fa0162017-01-11 09:21:56 -05001069 // We need this to be scheduled as early as possible to beat the redrawing of
1070 // window in response to the orientation change.
1071 Handler h = getView().getHandler();
1072 Message msg = Message.obtain(h, () -> {
Mike Digman85ff7fa2018-01-23 14:59:52 -08001073
1074 // If the screen rotation changes while locked, potentially update lock to flow with
Mike Digman90402952018-01-22 16:05:51 -08001075 // new screen rotation and hide any showing suggestions.
1076 if (mRotationLockController.isRotationLocked()) {
Mike Digman85ff7fa2018-01-23 14:59:52 -08001077 if (shouldOverrideUserLockPrefs(rotation)) {
1078 mRotationLockController.setRotationLockedAtAngle(true, rotation);
1079 }
Mike Digman1e28a5a2018-02-14 10:49:19 -08001080 setRotateSuggestionButtonState(false, true);
Mike Digman90402952018-01-22 16:05:51 -08001081 }
1082
Jason Monk49fa0162017-01-11 09:21:56 -05001083 if (mNavigationBarView != null
1084 && mNavigationBarView.needsReorient(rotation)) {
1085 repositionNavigationBar();
1086 }
1087 });
1088 msg.setAsynchronous(true);
1089 h.sendMessageAtFrontOfQueue(msg);
1090 }
Mike Digman85ff7fa2018-01-23 14:59:52 -08001091
1092 private boolean shouldOverrideUserLockPrefs(final int rotation) {
Mike Digmanab650252018-03-06 11:01:41 -08001093 // Only override user prefs when returning to the natural rotation (normally portrait).
Mike Digman85ff7fa2018-01-23 14:59:52 -08001094 // Don't let apps that force landscape or 180 alter user lock.
Mike Digmanab650252018-03-06 11:01:41 -08001095 return rotation == NATURAL_ROTATION;
Mike Digman85ff7fa2018-01-23 14:59:52 -08001096 }
Jason Monk49fa0162017-01-11 09:21:56 -05001097 };
1098
1099 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1100 @Override
1101 public void onReceive(Context context, Intent intent) {
1102 String action = intent.getAction();
Siarhei Vishniakoud002a0a2017-06-05 22:44:37 +01001103 if (Intent.ACTION_SCREEN_OFF.equals(action)
1104 || Intent.ACTION_SCREEN_ON.equals(action)) {
1105 notifyNavigationBarScreenOn();
Jason Monk49fa0162017-01-11 09:21:56 -05001106 }
Phil Weavera858c5f2018-04-26 13:27:30 -07001107 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
1108 // The accessibility settings may be different for the new user
1109 updateAccessibilityServicesState(mAccessibilityManager);
1110 };
Jason Monk49fa0162017-01-11 09:21:56 -05001111 }
1112 };
1113
Winson Chung67f5c8b2018-09-24 12:09:19 -07001114 class TaskStackListenerImpl extends TaskStackChangeListener {
Mike Digman7d092772018-01-11 12:10:32 -08001115 // Invalidate any rotation suggestion on task change or activity orientation change
1116 // Note: all callbacks happen on main thread
1117
1118 @Override
1119 public void onTaskStackChanged() {
Mike Digman1e28a5a2018-02-14 10:49:19 -08001120 setRotateSuggestionButtonState(false);
Mike Digman7d092772018-01-11 12:10:32 -08001121 }
1122
1123 @Override
1124 public void onTaskRemoved(int taskId) {
Mike Digman1e28a5a2018-02-14 10:49:19 -08001125 setRotateSuggestionButtonState(false);
Mike Digman7d092772018-01-11 12:10:32 -08001126 }
1127
1128 @Override
1129 public void onTaskMovedToFront(int taskId) {
Mike Digman1e28a5a2018-02-14 10:49:19 -08001130 setRotateSuggestionButtonState(false);
Mike Digman7d092772018-01-11 12:10:32 -08001131 }
1132
1133 @Override
1134 public void onActivityRequestedOrientationChanged(int taskId, int requestedOrientation) {
Mike Digman85a9bea2018-02-23 15:08:53 -08001135 // Only hide the icon if the top task changes its requestedOrientation
1136 // Launcher can alter its requestedOrientation while it's not on top, don't hide on this
Mike Digman121b11f2018-04-04 12:45:24 -07001137 Optional.ofNullable(ActivityManagerWrapper.getInstance())
1138 .map(ActivityManagerWrapper::getRunningTask)
1139 .ifPresent(a -> {
1140 if (a.id == taskId) setRotateSuggestionButtonState(false);
1141 });
Mike Digman7d092772018-01-11 12:10:32 -08001142 }
1143 }
1144
Mike Digman50752642018-02-15 13:36:09 -08001145 private class ViewRippler {
1146 private static final int RIPPLE_OFFSET_MS = 50;
1147 private static final int RIPPLE_INTERVAL_MS = 2000;
1148 private View mRoot;
1149
1150 public void start(View root) {
1151 stop(); // Stop any pending ripple animations
1152
1153 mRoot = root;
1154
1155 // Schedule pending ripples, offset the 1st to avoid problems with visibility change
1156 mRoot.postOnAnimationDelayed(mRipple, RIPPLE_OFFSET_MS);
1157 mRoot.postOnAnimationDelayed(mRipple, RIPPLE_INTERVAL_MS);
1158 mRoot.postOnAnimationDelayed(mRipple, 2*RIPPLE_INTERVAL_MS);
Mike Digmanc038c322018-05-24 11:06:05 -07001159 mRoot.postOnAnimationDelayed(mRipple, 3*RIPPLE_INTERVAL_MS);
1160 mRoot.postOnAnimationDelayed(mRipple, 4*RIPPLE_INTERVAL_MS);
Mike Digman50752642018-02-15 13:36:09 -08001161 }
1162
1163 public void stop() {
1164 if (mRoot != null) mRoot.removeCallbacks(mRipple);
1165 }
1166
1167 private final Runnable mRipple = new Runnable() {
1168 @Override
1169 public void run() { // Cause the ripple to fire via false presses
Mike Digmanf4c98992018-04-25 11:25:59 -07001170 if (!mRoot.isAttachedToWindow()) return;
Mike Digman50752642018-02-15 13:36:09 -08001171 mRoot.setPressed(true);
1172 mRoot.setPressed(false);
1173 }
1174 };
1175 }
1176
Jason Monk49fa0162017-01-11 09:21:56 -05001177 public static View create(Context context, FragmentListener listener) {
1178 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1179 LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
1180 WindowManager.LayoutParams.TYPE_NAVIGATION_BAR,
1181 WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
1182 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1183 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
1184 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
1185 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
1186 | WindowManager.LayoutParams.FLAG_SLIPPERY,
1187 PixelFormat.TRANSLUCENT);
1188 lp.token = new Binder();
Jason Monk49fa0162017-01-11 09:21:56 -05001189 lp.setTitle("NavigationBar");
Phil Weaver8583ae82018-02-13 11:01:24 -08001190 lp.accessibilityTitle = context.getString(R.string.nav_bar);
Jason Monk49fa0162017-01-11 09:21:56 -05001191 lp.windowAnimations = 0;
1192
1193 View navigationBarView = LayoutInflater.from(context).inflate(
1194 R.layout.navigation_bar_window, null);
1195
1196 if (DEBUG) Log.v(TAG, "addNavigationBar: about to add " + navigationBarView);
1197 if (navigationBarView == null) return null;
1198
1199 context.getSystemService(WindowManager.class).addView(navigationBarView, lp);
1200 FragmentHostManager fragmentHost = FragmentHostManager.get(navigationBarView);
1201 NavigationBarFragment fragment = new NavigationBarFragment();
1202 fragmentHost.getFragmentManager().beginTransaction()
1203 .replace(R.id.navigation_bar_frame, fragment, TAG)
1204 .commit();
1205 fragmentHost.addTagListener(TAG, listener);
1206 return navigationBarView;
1207 }
1208}