blob: 61c8027eb80030313af63074a6b13823e1f1ce59 [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
22import static com.android.systemui.statusbar.phone.BarTransitions.MODE_SEMI_TRANSPARENT;
Jason Monk2a6ea9c2017-01-26 11:14:51 -050023import static com.android.systemui.statusbar.phone.StatusBar.DEBUG_WINDOW_STATE;
24import static com.android.systemui.statusbar.phone.StatusBar.dumpBarTransitions;
Jason Monk49fa0162017-01-11 09:21:56 -050025
Casey Burkhardt048c2bc2016-12-08 16:09:20 -080026import android.accessibilityservice.AccessibilityServiceInfo;
Mike Digman7d092772018-01-11 12:10:32 -080027import android.animation.Animator;
28import android.animation.AnimatorListenerAdapter;
Mike Digman7d092772018-01-11 12:10:32 -080029import android.animation.ObjectAnimator;
Jason Monk49fa0162017-01-11 09:21:56 -050030import android.annotation.Nullable;
31import android.app.ActivityManager;
32import android.app.ActivityManagerNative;
33import android.app.Fragment;
34import android.app.IActivityManager;
35import android.app.StatusBarManager;
36import android.content.BroadcastReceiver;
Casey Burkhardtb9dcd662017-03-20 15:10:16 -070037import android.content.ContentResolver;
Jason Monk49fa0162017-01-11 09:21:56 -050038import android.content.Context;
39import android.content.Intent;
40import android.content.IntentFilter;
41import android.content.res.Configuration;
Casey Burkhardt74922c62017-02-13 12:43:16 -080042import android.database.ContentObserver;
Jason Monk49fa0162017-01-11 09:21:56 -050043import android.graphics.PixelFormat;
44import android.graphics.Rect;
Mike Digman7d092772018-01-11 12:10:32 -080045import android.graphics.drawable.AnimatedVectorDrawable;
Jason Monk49fa0162017-01-11 09:21:56 -050046import android.inputmethodservice.InputMethodService;
47import android.os.Binder;
48import android.os.Bundle;
49import android.os.Handler;
50import android.os.IBinder;
51import android.os.Message;
Jason Monk49fa0162017-01-11 09:21:56 -050052import android.os.RemoteException;
53import android.os.UserHandle;
Casey Burkhardt74922c62017-02-13 12:43:16 -080054import android.provider.Settings;
Jason Monk865246d2017-01-19 08:27:01 -050055import android.support.annotation.VisibleForTesting;
Jason Monk49fa0162017-01-11 09:21:56 -050056import android.telecom.TelecomManager;
57import android.text.TextUtils;
58import android.util.Log;
59import android.view.IRotationWatcher.Stub;
60import android.view.KeyEvent;
61import android.view.LayoutInflater;
62import android.view.MotionEvent;
Mike Digman85ff7fa2018-01-23 14:59:52 -080063import android.view.Surface;
Jason Monk49fa0162017-01-11 09:21:56 -050064import android.view.View;
65import android.view.ViewGroup;
66import android.view.WindowManager;
67import android.view.WindowManager.LayoutParams;
68import android.view.WindowManagerGlobal;
69import android.view.accessibility.AccessibilityEvent;
70import android.view.accessibility.AccessibilityManager;
Jason Monk91e587e2017-04-13 13:41:23 -040071import android.view.accessibility.AccessibilityManager.AccessibilityServicesStateChangeListener;
Jason Monk49fa0162017-01-11 09:21:56 -050072
73import com.android.internal.logging.MetricsLogger;
74import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Jason Monkea03be12017-12-04 11:08:41 -050075import com.android.internal.util.LatencyTracker;
Jason Monk9c7844c2017-01-18 15:21:53 -050076import com.android.systemui.Dependency;
Matthew Ngdc79e5c2017-12-14 17:37:35 -080077import com.android.systemui.OverviewProxyService;
Mike Digman7d092772018-01-11 12:10:32 -080078import com.android.systemui.Interpolators;
Jason Monk49fa0162017-01-11 09:21:56 -050079import com.android.systemui.R;
Jason Monk9c7844c2017-01-18 15:21:53 -050080import com.android.systemui.SysUiServiceProvider;
Jason Monk49fa0162017-01-11 09:21:56 -050081import com.android.systemui.assist.AssistManager;
82import com.android.systemui.fragments.FragmentHostManager;
83import com.android.systemui.fragments.FragmentHostManager.FragmentListener;
84import com.android.systemui.recents.Recents;
Mike Digman7d092772018-01-11 12:10:32 -080085import com.android.systemui.recents.misc.SysUiTaskStackChangeListener;
86import com.android.systemui.shared.system.ActivityManagerWrapper;
Jason Monk49fa0162017-01-11 09:21:56 -050087import com.android.systemui.stackdivider.Divider;
88import com.android.systemui.statusbar.CommandQueue;
89import com.android.systemui.statusbar.CommandQueue.Callbacks;
Jason Monk91e587e2017-04-13 13:41:23 -040090import com.android.systemui.statusbar.policy.AccessibilityManagerWrapper;
Mike Digman7d092772018-01-11 12:10:32 -080091import com.android.systemui.statusbar.policy.KeyButtonDrawable;
Jason Monk49fa0162017-01-11 09:21:56 -050092import com.android.systemui.statusbar.policy.KeyButtonView;
Mike Digman7d092772018-01-11 12:10:32 -080093import com.android.systemui.statusbar.policy.RotationLockController;
Jason Monk49fa0162017-01-11 09:21:56 -050094import com.android.systemui.statusbar.stack.StackStateAnimator;
95
96import java.io.FileDescriptor;
97import java.io.PrintWriter;
Casey Burkhardt048c2bc2016-12-08 16:09:20 -080098import java.util.List;
Jason Monk49fa0162017-01-11 09:21:56 -050099import java.util.Locale;
100
101/**
102 * Fragment containing the NavigationBarFragment. Contains logic for what happens
103 * on clicks and view states of the nav bar.
104 */
105public class NavigationBarFragment extends Fragment implements Callbacks {
106
Jason Monkd4afe152017-05-01 15:37:43 -0400107 public static final String TAG = "NavigationBar";
Jason Monk49fa0162017-01-11 09:21:56 -0500108 private static final boolean DEBUG = false;
109 private static final String EXTRA_DISABLE_STATE = "disabled_state";
110
111 /** Allow some time inbetween the long press for back and recents. */
112 private static final int LOCK_TO_APP_GESTURE_TOLERENCE = 200;
113
Mike Digman90402952018-01-22 16:05:51 -0800114 private static final int BUTTON_FADE_IN_OUT_DURATION_MS = 100;
Mike Digman7d092772018-01-11 12:10:32 -0800115
Jason Monk49fa0162017-01-11 09:21:56 -0500116 protected NavigationBarView mNavigationBarView = null;
117 protected AssistManager mAssistManager;
118
119 private int mNavigationBarWindowState = WINDOW_STATE_SHOWING;
120
121 private int mNavigationIconHints = 0;
122 private int mNavigationBarMode;
Mike Digman90402952018-01-22 16:05:51 -0800123 private boolean mAccessibilityFeedbackEnabled;
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800124 private AccessibilityManager mAccessibilityManager;
Casey Burkhardt74922c62017-02-13 12:43:16 -0800125 private MagnificationContentObserver mMagnificationObserver;
Casey Burkhardtb9dcd662017-03-20 15:10:16 -0700126 private ContentResolver mContentResolver;
Mike Digmanc94759d2018-01-23 11:01:21 -0800127 private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class);
Jason Monk49fa0162017-01-11 09:21:56 -0500128
129 private int mDisabledFlags1;
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500130 private StatusBar mStatusBar;
Jason Monk49fa0162017-01-11 09:21:56 -0500131 private Recents mRecents;
132 private Divider mDivider;
133 private WindowManager mWindowManager;
134 private CommandQueue mCommandQueue;
135 private long mLastLockToAppLongPress;
136
137 private Locale mLocale;
138 private int mLayoutDirection;
139
140 private int mSystemUiVisibility;
141 private LightBarController mLightBarController;
Jason Monk49fa0162017-01-11 09:21:56 -0500142
Matthew Ngdc79e5c2017-12-14 17:37:35 -0800143 private OverviewProxyService mOverviewProxyService;
144
Jason Monk49fa0162017-01-11 09:21:56 -0500145 public boolean mHomeBlockedThisTouch;
146
Mike Digman7d092772018-01-11 12:10:32 -0800147 private int mLastRotationSuggestion;
Mike Digman90402952018-01-22 16:05:51 -0800148 private boolean mHoveringRotationSuggestion;
Mike Digman7d092772018-01-11 12:10:32 -0800149 private RotationLockController mRotationLockController;
150 private TaskStackListenerImpl mTaskStackListener;
151
152 private final Runnable mRemoveRotationProposal = () -> setRotateSuggestionButtonState(false);
153 private Animator mRotateShowAnimator;
154 private Animator mRotateHideAnimator;
155
156
Jason Monk49fa0162017-01-11 09:21:56 -0500157 // ----- Fragment Lifecycle Callbacks -----
158
159 @Override
160 public void onCreate(@Nullable Bundle savedInstanceState) {
161 super.onCreate(savedInstanceState);
Jason Monk9c7844c2017-01-18 15:21:53 -0500162 mCommandQueue = SysUiServiceProvider.getComponent(getContext(), CommandQueue.class);
Jason Monk49fa0162017-01-11 09:21:56 -0500163 mCommandQueue.addCallbacks(this);
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500164 mStatusBar = SysUiServiceProvider.getComponent(getContext(), StatusBar.class);
Jason Monk9c7844c2017-01-18 15:21:53 -0500165 mRecents = SysUiServiceProvider.getComponent(getContext(), Recents.class);
166 mDivider = SysUiServiceProvider.getComponent(getContext(), Divider.class);
Jason Monk49fa0162017-01-11 09:21:56 -0500167 mWindowManager = getContext().getSystemService(WindowManager.class);
168 mAccessibilityManager = getContext().getSystemService(AccessibilityManager.class);
Jason Monk91e587e2017-04-13 13:41:23 -0400169 Dependency.get(AccessibilityManagerWrapper.class).addCallback(
170 mAccessibilityListener);
Casey Burkhardtb9dcd662017-03-20 15:10:16 -0700171 mContentResolver = getContext().getContentResolver();
Casey Burkhardt74922c62017-02-13 12:43:16 -0800172 mMagnificationObserver = new MagnificationContentObserver(
173 getContext().getMainThreadHandler());
Casey Burkhardtb9dcd662017-03-20 15:10:16 -0700174 mContentResolver.registerContentObserver(Settings.Secure.getUriFor(
Casey Burkhardt74922c62017-02-13 12:43:16 -0800175 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED), false,
Casey Burkhardt5d614402017-04-06 13:46:50 -0700176 mMagnificationObserver, UserHandle.USER_ALL);
Casey Burkhardt74922c62017-02-13 12:43:16 -0800177
Jason Monk49fa0162017-01-11 09:21:56 -0500178 if (savedInstanceState != null) {
179 mDisabledFlags1 = savedInstanceState.getInt(EXTRA_DISABLE_STATE, 0);
180 }
Jason Monk9c7844c2017-01-18 15:21:53 -0500181 mAssistManager = Dependency.get(AssistManager.class);
Matthew Ngdc79e5c2017-12-14 17:37:35 -0800182 mOverviewProxyService = Dependency.get(OverviewProxyService.class);
Jason Monk49fa0162017-01-11 09:21:56 -0500183
184 try {
185 WindowManagerGlobal.getWindowManagerService()
Andrii Kulian35fa3c22017-03-11 09:37:28 -0800186 .watchRotation(mRotationWatcher, getContext().getDisplay().getDisplayId());
Jason Monk49fa0162017-01-11 09:21:56 -0500187 } catch (RemoteException e) {
188 throw e.rethrowFromSystemServer();
189 }
Mike Digman7d092772018-01-11 12:10:32 -0800190
191 mRotationLockController = Dependency.get(RotationLockController.class);
192
193 // Register the task stack listener
194 mTaskStackListener = new TaskStackListenerImpl();
195 ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener);
Jason Monk49fa0162017-01-11 09:21:56 -0500196 }
197
198 @Override
199 public void onDestroy() {
200 super.onDestroy();
201 mCommandQueue.removeCallbacks(this);
Jason Monk91e587e2017-04-13 13:41:23 -0400202 Dependency.get(AccessibilityManagerWrapper.class).removeCallback(
203 mAccessibilityListener);
Casey Burkhardtb9dcd662017-03-20 15:10:16 -0700204 mContentResolver.unregisterContentObserver(mMagnificationObserver);
Jason Monk49fa0162017-01-11 09:21:56 -0500205 try {
206 WindowManagerGlobal.getWindowManagerService()
207 .removeRotationWatcher(mRotationWatcher);
208 } catch (RemoteException e) {
209 throw e.rethrowFromSystemServer();
210 }
Mike Digman7d092772018-01-11 12:10:32 -0800211
212 // Unregister the task stack listener
213 ActivityManagerWrapper.getInstance().unregisterTaskStackListener(mTaskStackListener);
Jason Monk49fa0162017-01-11 09:21:56 -0500214 }
215
216 @Override
217 public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
218 Bundle savedInstanceState) {
219 return inflater.inflate(R.layout.navigation_bar, container, false);
220 }
221
222 @Override
223 public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
224 super.onViewCreated(view, savedInstanceState);
225 mNavigationBarView = (NavigationBarView) view;
226
227 mNavigationBarView.setDisabledFlags(mDisabledFlags1);
Matthew Ng78f88d12018-01-23 12:39:55 -0800228 mNavigationBarView.setComponents(mRecents, mDivider, mStatusBar.getPanel());
Jason Monk49fa0162017-01-11 09:21:56 -0500229 mNavigationBarView.setOnVerticalChangedListener(this::onVerticalChanged);
230 mNavigationBarView.setOnTouchListener(this::onNavigationTouch);
231 if (savedInstanceState != null) {
232 mNavigationBarView.getLightTransitionsController().restoreState(savedInstanceState);
233 }
234
235 prepareNavigationBarView();
236 checkNavBarModes();
237
238 IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
239 filter.addAction(Intent.ACTION_SCREEN_ON);
240 getContext().registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, filter, null, null);
Siarhei Vishniakoud002a0a2017-06-05 22:44:37 +0100241 notifyNavigationBarScreenOn();
Jason Monk49fa0162017-01-11 09:21:56 -0500242 }
243
244 @Override
245 public void onDestroyView() {
246 super.onDestroyView();
Jason Monkaa573e92017-01-27 17:00:29 -0500247 mNavigationBarView.getLightTransitionsController().destroy(getContext());
Jason Monk49fa0162017-01-11 09:21:56 -0500248 getContext().unregisterReceiver(mBroadcastReceiver);
249 }
250
251 @Override
252 public void onSaveInstanceState(Bundle outState) {
253 super.onSaveInstanceState(outState);
254 outState.putInt(EXTRA_DISABLE_STATE, mDisabledFlags1);
255 if (mNavigationBarView != null) {
256 mNavigationBarView.getLightTransitionsController().saveState(outState);
257 }
258 }
259
260 @Override
261 public void onConfigurationChanged(Configuration newConfig) {
262 super.onConfigurationChanged(newConfig);
263 final Locale locale = getContext().getResources().getConfiguration().locale;
264 final int ld = TextUtils.getLayoutDirectionFromLocale(locale);
265 if (!locale.equals(mLocale) || ld != mLayoutDirection) {
266 if (DEBUG) {
267 Log.v(TAG, String.format(
268 "config changed locale/LD: %s (%d) -> %s (%d)", mLocale, mLayoutDirection,
269 locale, ld));
270 }
271 mLocale = locale;
272 mLayoutDirection = ld;
273 refreshLayout(ld);
274 }
275 repositionNavigationBar();
276 }
277
278 @Override
279 public void dump(String prefix, FileDescriptor fd, PrintWriter pw, String[] args) {
280 if (mNavigationBarView != null) {
281 pw.print(" mNavigationBarWindowState=");
282 pw.println(windowStateToString(mNavigationBarWindowState));
283 pw.print(" mNavigationBarMode=");
284 pw.println(BarTransitions.modeToString(mNavigationBarMode));
285 dumpBarTransitions(pw, "mNavigationBarView", mNavigationBarView.getBarTransitions());
286 }
287
288 pw.print(" mNavigationBarView=");
289 if (mNavigationBarView == null) {
290 pw.println("null");
291 } else {
292 mNavigationBarView.dump(fd, pw, args);
293 }
294 }
295
296 // ----- CommandQueue Callbacks -----
297
298 @Override
299 public void setImeWindowStatus(IBinder token, int vis, int backDisposition,
300 boolean showImeSwitcher) {
301 boolean imeShown = (vis & InputMethodService.IME_VISIBLE) != 0;
302 int hints = mNavigationIconHints;
303 if ((backDisposition == InputMethodService.BACK_DISPOSITION_WILL_DISMISS) || imeShown) {
304 hints |= NAVIGATION_HINT_BACK_ALT;
305 } else {
306 hints &= ~NAVIGATION_HINT_BACK_ALT;
307 }
308 if (showImeSwitcher) {
309 hints |= NAVIGATION_HINT_IME_SHOWN;
310 } else {
311 hints &= ~NAVIGATION_HINT_IME_SHOWN;
312 }
313 if (hints == mNavigationIconHints) return;
314
315 mNavigationIconHints = hints;
316
317 if (mNavigationBarView != null) {
318 mNavigationBarView.setNavigationIconHints(hints);
319 }
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500320 mStatusBar.checkBarModes();
Jason Monk49fa0162017-01-11 09:21:56 -0500321 }
322
323 @Override
324 public void topAppWindowChanged(boolean showMenu) {
325 if (mNavigationBarView != null) {
326 mNavigationBarView.setMenuVisibility(showMenu);
327 }
328 }
329
330 @Override
331 public void setWindowState(int window, int state) {
332 if (mNavigationBarView != null
333 && window == StatusBarManager.WINDOW_NAVIGATION_BAR
334 && mNavigationBarWindowState != state) {
335 mNavigationBarWindowState = state;
336 if (DEBUG_WINDOW_STATE) Log.d(TAG, "Navigation bar " + windowStateToString(state));
337 }
338 }
339
Mike Digman7d092772018-01-11 12:10:32 -0800340 @Override
Mike Digmane0777312018-01-19 12:41:51 -0800341 public void onRotationProposal(final int rotation, boolean isValid) {
342 // This method will be called on rotation suggestion changes even if the proposed rotation
343 // is not valid for the top app. Use invalid rotation choices as a signal to remove the
344 // rotate button if shown.
345
346 if (!isValid) {
347 setRotateSuggestionButtonState(false);
348 return;
349 }
350
Mike Digman7d092772018-01-11 12:10:32 -0800351 if (rotation == mWindowManager.getDefaultDisplay().getRotation()) {
352 // Use this as a signal to remove any current suggestions
Mike Digman90402952018-01-22 16:05:51 -0800353 getView().getHandler().removeCallbacks(mRemoveRotationProposal);
Mike Digman7d092772018-01-11 12:10:32 -0800354 setRotateSuggestionButtonState(false);
355 } else {
356 mLastRotationSuggestion = rotation; // Remember rotation for click
357 setRotateSuggestionButtonState(true);
Mike Digman90402952018-01-22 16:05:51 -0800358 rescheduleRotationTimeout(false);
Mike Digmanc94759d2018-01-23 11:01:21 -0800359 mMetricsLogger.visible(MetricsEvent.ROTATION_SUGGESTION_SHOWN);
Mike Digman7d092772018-01-11 12:10:32 -0800360 }
361 }
362
Mike Digman90402952018-01-22 16:05:51 -0800363 private void rescheduleRotationTimeout(final boolean reasonHover) {
364 // May be called due to a new rotation proposal or a change in hover state
365 if (reasonHover) {
366 // Don't reschedule if a hide animator is running
367 if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) {
368 return;
369 }
370 // Don't reschedule if not visible
371 if (mNavigationBarView.getRotateSuggestionButton().getVisibility() != View.VISIBLE) {
372 return;
373 }
374 }
375
376 Handler h = getView().getHandler();
377 h.removeCallbacks(mRemoveRotationProposal); // Stop any pending removal
378 h.postDelayed(mRemoveRotationProposal,
379 computeRotationProposalTimeout()); // Schedule timeout
380 }
381
382 private int computeRotationProposalTimeout() {
383 if (mAccessibilityFeedbackEnabled) return 20000;
384 if (mHoveringRotationSuggestion) return 16000;
385 return 6000;
386 }
387
Mike Digman7d092772018-01-11 12:10:32 -0800388 public void setRotateSuggestionButtonState(final boolean visible) {
389 setRotateSuggestionButtonState(visible, false);
390 }
391
392 public void setRotateSuggestionButtonState(final boolean visible, final boolean skipAnim) {
393 ButtonDispatcher rotBtn = mNavigationBarView.getRotateSuggestionButton();
Mike Digman90402952018-01-22 16:05:51 -0800394 final boolean currentlyVisible = rotBtn.getVisibility() == View.VISIBLE;
Mike Digman7d092772018-01-11 12:10:32 -0800395
396 // Rerun a show animation to indicate change but don't rerun a hide animation
397 if (!visible && !currentlyVisible) return;
398
Mike Digman90402952018-01-22 16:05:51 -0800399 View currentView = rotBtn.getCurrentView();
Mike Digman7d092772018-01-11 12:10:32 -0800400 if (currentView == null) return;
401
Mike Digman90402952018-01-22 16:05:51 -0800402 KeyButtonDrawable kbd = rotBtn.getImageDrawable();
Mike Digman7d092772018-01-11 12:10:32 -0800403 if (kbd == null) return;
404
Mike Digman90402952018-01-22 16:05:51 -0800405 AnimatedVectorDrawable animIcon = null;
406 if (kbd.getDrawable(0) instanceof AnimatedVectorDrawable) {
407 animIcon = (AnimatedVectorDrawable) kbd.getDrawable(0);
408 }
409
Mike Digman7d092772018-01-11 12:10:32 -0800410 if (visible) { // Appear and change
411 rotBtn.setVisibility(View.VISIBLE);
Mike Digman90402952018-01-22 16:05:51 -0800412 mNavigationBarView.notifyAccessibilitySubtreeChanged();
Mike Digman7d092772018-01-11 12:10:32 -0800413
414 if (skipAnim) {
415 currentView.setAlpha(1f);
416 return;
417 }
418
419 // Start a new animation if running
420 if (mRotateShowAnimator != null) mRotateShowAnimator.pause();
421 if (mRotateHideAnimator != null) mRotateHideAnimator.pause();
422
423 ObjectAnimator appearFade = ObjectAnimator.ofFloat(currentView, "alpha",
424 0f, 1f);
Mike Digman90402952018-01-22 16:05:51 -0800425 appearFade.setDuration(BUTTON_FADE_IN_OUT_DURATION_MS);
Mike Digman7d092772018-01-11 12:10:32 -0800426 appearFade.setInterpolator(Interpolators.LINEAR);
427 mRotateShowAnimator = appearFade;
428 appearFade.start();
429
Mike Digman90402952018-01-22 16:05:51 -0800430 // Run the rotate icon's animation if it has one
431 if (animIcon != null) {
432 animIcon.reset();
433 animIcon.start();
434 }
435
Mike Digman7d092772018-01-11 12:10:32 -0800436 } else { // Hide
437
438 if (skipAnim) {
439 rotBtn.setVisibility(View.INVISIBLE);
Mike Digman90402952018-01-22 16:05:51 -0800440 mNavigationBarView.notifyAccessibilitySubtreeChanged();
Mike Digman7d092772018-01-11 12:10:32 -0800441 return;
442 }
443
444 // Don't start any new hide animations if one is running
445 if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) return;
446 // Pause any active show animations but don't reset the AVD to avoid jumps
447 if (mRotateShowAnimator != null) mRotateShowAnimator.pause();
448
449 ObjectAnimator fadeOut = ObjectAnimator.ofFloat(currentView, "alpha",
450 0f);
Mike Digman90402952018-01-22 16:05:51 -0800451 fadeOut.setDuration(BUTTON_FADE_IN_OUT_DURATION_MS);
Mike Digman7d092772018-01-11 12:10:32 -0800452 fadeOut.setInterpolator(Interpolators.LINEAR);
453 fadeOut.addListener(new AnimatorListenerAdapter() {
454 @Override
455 public void onAnimationEnd(Animator animation) {
456 rotBtn.setVisibility(View.INVISIBLE);
Mike Digman90402952018-01-22 16:05:51 -0800457 mNavigationBarView.notifyAccessibilitySubtreeChanged();
Mike Digman7d092772018-01-11 12:10:32 -0800458 }
459 });
460
461 mRotateHideAnimator = fadeOut;
462 fadeOut.start();
463 }
464 }
465
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500466 // Injected from StatusBar at creation.
Jason Monk49fa0162017-01-11 09:21:56 -0500467 public void setCurrentSysuiVisibility(int systemUiVisibility) {
468 mSystemUiVisibility = systemUiVisibility;
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500469 mNavigationBarMode = mStatusBar.computeBarMode(0, mSystemUiVisibility,
Jason Monk49fa0162017-01-11 09:21:56 -0500470 View.NAVIGATION_BAR_TRANSIENT, View.NAVIGATION_BAR_TRANSLUCENT,
471 View.NAVIGATION_BAR_TRANSPARENT);
472 checkNavBarModes();
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500473 mStatusBar.touchAutoHide();
Jason Monk49fa0162017-01-11 09:21:56 -0500474 mLightBarController.onNavigationVisibilityChanged(mSystemUiVisibility, 0 /* mask */,
475 true /* nbModeChanged */, mNavigationBarMode);
476 }
477
478 @Override
479 public void setSystemUiVisibility(int vis, int fullscreenStackVis, int dockedStackVis,
480 int mask, Rect fullscreenStackBounds, Rect dockedStackBounds) {
481 final int oldVal = mSystemUiVisibility;
482 final int newVal = (oldVal & ~mask) | (vis & mask);
483 final int diff = newVal ^ oldVal;
484 boolean nbModeChanged = false;
485 if (diff != 0) {
486 mSystemUiVisibility = newVal;
487
488 // update navigation bar mode
489 final int nbMode = getView() == null
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500490 ? -1 : mStatusBar.computeBarMode(oldVal, newVal,
Jason Monk49fa0162017-01-11 09:21:56 -0500491 View.NAVIGATION_BAR_TRANSIENT, View.NAVIGATION_BAR_TRANSLUCENT,
492 View.NAVIGATION_BAR_TRANSPARENT);
493 nbModeChanged = nbMode != -1;
494 if (nbModeChanged) {
495 if (mNavigationBarMode != nbMode) {
496 mNavigationBarMode = nbMode;
497 checkNavBarModes();
498 }
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500499 mStatusBar.touchAutoHide();
Jason Monk49fa0162017-01-11 09:21:56 -0500500 }
501 }
502
503 mLightBarController.onNavigationVisibilityChanged(vis, mask, nbModeChanged,
504 mNavigationBarMode);
505 }
506
507 @Override
508 public void disable(int state1, int state2, boolean animate) {
509 // All navigation bar flags are in state1.
510 int masked = state1 & (StatusBarManager.DISABLE_HOME
511 | StatusBarManager.DISABLE_RECENT
512 | StatusBarManager.DISABLE_BACK
513 | StatusBarManager.DISABLE_SEARCH);
514 if (masked != mDisabledFlags1) {
515 mDisabledFlags1 = masked;
516 if (mNavigationBarView != null) mNavigationBarView.setDisabledFlags(state1);
517 }
518 }
519
520 // ----- Internal stuffz -----
521
522 private void refreshLayout(int layoutDirection) {
523 if (mNavigationBarView != null) {
524 mNavigationBarView.setLayoutDirection(layoutDirection);
525 }
526 }
527
528 private boolean shouldDisableNavbarGestures() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500529 return !mStatusBar.isDeviceProvisioned()
Matthew Ngdc79e5c2017-12-14 17:37:35 -0800530 || (mDisabledFlags1 & StatusBarManager.DISABLE_SEARCH) != 0
531 || mOverviewProxyService.getProxy() != null;
Jason Monk49fa0162017-01-11 09:21:56 -0500532 }
533
534 private void repositionNavigationBar() {
535 if (mNavigationBarView == null || !mNavigationBarView.isAttachedToWindow()) return;
536
537 prepareNavigationBarView();
538
539 mWindowManager.updateViewLayout((View) mNavigationBarView.getParent(),
540 ((View) mNavigationBarView.getParent()).getLayoutParams());
541 }
542
Siarhei Vishniakoud002a0a2017-06-05 22:44:37 +0100543 private void notifyNavigationBarScreenOn() {
544 mNavigationBarView.notifyScreenOn();
Jason Monk49fa0162017-01-11 09:21:56 -0500545 }
546
547 private void prepareNavigationBarView() {
548 mNavigationBarView.reorient();
549
550 ButtonDispatcher recentsButton = mNavigationBarView.getRecentsButton();
551 recentsButton.setOnClickListener(this::onRecentsClick);
552 recentsButton.setOnTouchListener(this::onRecentsTouch);
553 recentsButton.setLongClickable(true);
554 recentsButton.setOnLongClickListener(this::onLongPressBackRecents);
555
556 ButtonDispatcher backButton = mNavigationBarView.getBackButton();
557 backButton.setLongClickable(true);
558 backButton.setOnLongClickListener(this::onLongPressBackRecents);
559
560 ButtonDispatcher homeButton = mNavigationBarView.getHomeButton();
561 homeButton.setOnTouchListener(this::onHomeTouch);
562 homeButton.setOnLongClickListener(this::onHomeLongClick);
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800563
564 ButtonDispatcher accessibilityButton = mNavigationBarView.getAccessibilityButton();
565 accessibilityButton.setOnClickListener(this::onAccessibilityClick);
566 accessibilityButton.setOnLongClickListener(this::onAccessibilityLongClick);
Phil Weaverdb9a7742017-04-18 08:15:06 -0700567 updateAccessibilityServicesState(mAccessibilityManager);
Mike Digman7d092772018-01-11 12:10:32 -0800568
569 ButtonDispatcher rotateSuggestionButton = mNavigationBarView.getRotateSuggestionButton();
570 rotateSuggestionButton.setOnClickListener(this::onRotateSuggestionClick);
Mike Digman90402952018-01-22 16:05:51 -0800571 rotateSuggestionButton.setOnHoverListener(this::onRotateSuggestionHover);
Jason Monk49fa0162017-01-11 09:21:56 -0500572 }
573
574 private boolean onHomeTouch(View v, MotionEvent event) {
575 if (mHomeBlockedThisTouch && event.getActionMasked() != MotionEvent.ACTION_DOWN) {
576 return true;
577 }
578 // If an incoming call is ringing, HOME is totally disabled.
579 // (The user is already on the InCallUI at this point,
580 // and his ONLY options are to answer or reject the call.)
581 switch (event.getAction()) {
582 case MotionEvent.ACTION_DOWN:
583 mHomeBlockedThisTouch = false;
584 TelecomManager telecomManager =
585 getContext().getSystemService(TelecomManager.class);
586 if (telecomManager != null && telecomManager.isRinging()) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500587 if (mStatusBar.isKeyguardShowing()) {
Jason Monk49fa0162017-01-11 09:21:56 -0500588 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call. " +
589 "No heads up");
590 mHomeBlockedThisTouch = true;
591 return true;
592 }
593 }
594 break;
595 case MotionEvent.ACTION_UP:
596 case MotionEvent.ACTION_CANCEL:
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500597 mStatusBar.awakenDreams();
Jason Monk49fa0162017-01-11 09:21:56 -0500598 break;
599 }
600 return false;
601 }
602
603 private void onVerticalChanged(boolean isVertical) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500604 mStatusBar.setQsScrimEnabled(!isVertical);
Jason Monk49fa0162017-01-11 09:21:56 -0500605 }
606
607 private boolean onNavigationTouch(View v, MotionEvent event) {
Eliot Courtneycb5d3162017-08-09 16:53:15 +0900608 mStatusBar.checkUserAutohide(event);
Jason Monk49fa0162017-01-11 09:21:56 -0500609 return false;
610 }
611
Jason Monk865246d2017-01-19 08:27:01 -0500612 @VisibleForTesting
613 boolean onHomeLongClick(View v) {
Jason Monk49fa0162017-01-11 09:21:56 -0500614 if (shouldDisableNavbarGestures()) {
615 return false;
616 }
Mike Digmanc94759d2018-01-23 11:01:21 -0800617 mMetricsLogger.action(MetricsEvent.ACTION_ASSIST_LONG_PRESS);
Jason Monk49fa0162017-01-11 09:21:56 -0500618 mAssistManager.startAssist(new Bundle() /* args */);
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500619 mStatusBar.awakenDreams();
Matthew Ngdc79e5c2017-12-14 17:37:35 -0800620
Jason Monk49fa0162017-01-11 09:21:56 -0500621 if (mNavigationBarView != null) {
622 mNavigationBarView.abortCurrentGesture();
623 }
624 return true;
625 }
626
627 // additional optimization when we have software system buttons - start loading the recent
628 // tasks on touch down
629 private boolean onRecentsTouch(View v, MotionEvent event) {
630 int action = event.getAction() & MotionEvent.ACTION_MASK;
631 if (action == MotionEvent.ACTION_DOWN) {
632 mCommandQueue.preloadRecentApps();
633 } else if (action == MotionEvent.ACTION_CANCEL) {
634 mCommandQueue.cancelPreloadRecentApps();
635 } else if (action == MotionEvent.ACTION_UP) {
636 if (!v.isPressed()) {
637 mCommandQueue.cancelPreloadRecentApps();
638 }
639 }
640 return false;
641 }
642
643 private void onRecentsClick(View v) {
644 if (LatencyTracker.isEnabled(getContext())) {
645 LatencyTracker.getInstance(getContext()).onActionStart(
646 LatencyTracker.ACTION_TOGGLE_RECENTS);
647 }
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500648 mStatusBar.awakenDreams();
Jason Monk49fa0162017-01-11 09:21:56 -0500649 mCommandQueue.toggleRecentApps();
650 }
651
652 /**
653 * This handles long-press of both back and recents. They are
654 * handled together to capture them both being long-pressed
655 * at the same time to exit screen pinning (lock task).
656 *
657 * When accessibility mode is on, only a long-press from recents
658 * is required to exit.
659 *
660 * In all other circumstances we try to pass through long-press events
661 * for Back, so that apps can still use it. Which can be from two things.
662 * 1) Not currently in screen pinning (lock task).
663 * 2) Back is long-pressed without recents.
664 */
665 private boolean onLongPressBackRecents(View v) {
666 try {
667 boolean sendBackLongPress = false;
668 IActivityManager activityManager = ActivityManagerNative.getDefault();
669 boolean touchExplorationEnabled = mAccessibilityManager.isTouchExplorationEnabled();
670 boolean inLockTaskMode = activityManager.isInLockTaskMode();
671 if (inLockTaskMode && !touchExplorationEnabled) {
672 long time = System.currentTimeMillis();
673 // If we recently long-pressed the other button then they were
674 // long-pressed 'together'
675 if ((time - mLastLockToAppLongPress) < LOCK_TO_APP_GESTURE_TOLERENCE) {
Benjamin Franza83859f2017-07-03 16:34:14 +0100676 activityManager.stopSystemLockTaskMode();
Jason Monk49fa0162017-01-11 09:21:56 -0500677 // When exiting refresh disabled flags.
678 mNavigationBarView.setDisabledFlags(mDisabledFlags1, true);
679 return true;
680 } else if ((v.getId() == R.id.back)
681 && !mNavigationBarView.getRecentsButton().getCurrentView().isPressed()) {
682 // If we aren't pressing recents right now then they presses
683 // won't be together, so send the standard long-press action.
684 sendBackLongPress = true;
685 }
686 mLastLockToAppLongPress = time;
687 } else {
688 // If this is back still need to handle sending the long-press event.
689 if (v.getId() == R.id.back) {
690 sendBackLongPress = true;
691 } else if (touchExplorationEnabled && inLockTaskMode) {
692 // When in accessibility mode a long press that is recents (not back)
693 // should stop lock task.
Benjamin Franza83859f2017-07-03 16:34:14 +0100694 activityManager.stopSystemLockTaskMode();
Jason Monk49fa0162017-01-11 09:21:56 -0500695 // When exiting refresh disabled flags.
696 mNavigationBarView.setDisabledFlags(mDisabledFlags1, true);
697 return true;
698 } else if (v.getId() == R.id.recent_apps) {
699 return onLongPressRecents();
700 }
701 }
702 if (sendBackLongPress) {
703 KeyButtonView keyButtonView = (KeyButtonView) v;
704 keyButtonView.sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.FLAG_LONG_PRESS);
705 keyButtonView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED);
706 return true;
707 }
708 } catch (RemoteException e) {
709 Log.d(TAG, "Unable to reach activity manager", e);
710 }
711 return false;
712 }
713
714 private boolean onLongPressRecents() {
Erik Wolsheimer9be3a062017-05-31 14:59:57 -0700715 if (mRecents == null || !ActivityManager.supportsMultiWindow(getContext())
Matthew Ng43db6d22017-06-27 15:29:39 -0700716 || !mDivider.getView().getSnapAlgorithm().isSplitScreenFeasible()
717 || Recents.getConfiguration().isLowRamDevice) {
Jason Monk49fa0162017-01-11 09:21:56 -0500718 return false;
719 }
720
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500721 return mStatusBar.toggleSplitScreenMode(MetricsEvent.ACTION_WINDOW_DOCK_LONGPRESS,
Jason Monk49fa0162017-01-11 09:21:56 -0500722 MetricsEvent.ACTION_WINDOW_UNDOCK_LONGPRESS);
723 }
724
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800725 private void onAccessibilityClick(View v) {
726 mAccessibilityManager.notifyAccessibilityButtonClicked();
727 }
728
729 private boolean onAccessibilityLongClick(View v) {
Casey Burkhardt5e8b9802017-03-24 10:07:20 -0700730 Intent intent = new Intent(AccessibilityManager.ACTION_CHOOSE_ACCESSIBILITY_BUTTON);
731 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
Casey Burkhardt5d614402017-04-06 13:46:50 -0700732 v.getContext().startActivityAsUser(intent, UserHandle.CURRENT);
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800733 return true;
734 }
735
Phil Weaverdb9a7742017-04-18 08:15:06 -0700736 private void updateAccessibilityServicesState(AccessibilityManager accessibilityManager) {
Casey Burkhardt74922c62017-02-13 12:43:16 -0800737 int requestingServices = 0;
738 try {
Casey Burkhardt5d614402017-04-06 13:46:50 -0700739 if (Settings.Secure.getIntForUser(mContentResolver,
740 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED,
741 UserHandle.USER_CURRENT) == 1) {
Casey Burkhardt74922c62017-02-13 12:43:16 -0800742 requestingServices++;
743 }
744 } catch (Settings.SettingNotFoundException e) {
745 }
746
Mike Digman90402952018-01-22 16:05:51 -0800747 boolean feedbackEnabled = false;
Casey Burkhardt5d614402017-04-06 13:46:50 -0700748 // AccessibilityManagerService resolves services for the current user since the local
749 // AccessibilityManager is created from a Context with the INTERACT_ACROSS_USERS permission
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800750 final List<AccessibilityServiceInfo> services =
Phil Weaverdb9a7742017-04-18 08:15:06 -0700751 accessibilityManager.getEnabledAccessibilityServiceList(
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800752 AccessibilityServiceInfo.FEEDBACK_ALL_MASK);
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800753 for (int i = services.size() - 1; i >= 0; --i) {
754 AccessibilityServiceInfo info = services.get(i);
755 if ((info.flags & AccessibilityServiceInfo.FLAG_REQUEST_ACCESSIBILITY_BUTTON) != 0) {
756 requestingServices++;
757 }
Mike Digman90402952018-01-22 16:05:51 -0800758
759 if (info.feedbackType != 0 && info.feedbackType !=
760 AccessibilityServiceInfo.FEEDBACK_GENERIC) {
761 feedbackEnabled = true;
762 }
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800763 }
764
Mike Digman90402952018-01-22 16:05:51 -0800765 mAccessibilityFeedbackEnabled = feedbackEnabled;
766
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800767 final boolean showAccessibilityButton = requestingServices >= 1;
768 final boolean targetSelection = requestingServices >= 2;
769 mNavigationBarView.setAccessibilityButtonState(showAccessibilityButton, targetSelection);
770 }
771
Mike Digman7d092772018-01-11 12:10:32 -0800772 private void onRotateSuggestionClick(View v) {
Mike Digmanc94759d2018-01-23 11:01:21 -0800773 mMetricsLogger.action(MetricsEvent.ACTION_ROTATION_SUGGESTION_ACCEPTED);
Mike Digman7d092772018-01-11 12:10:32 -0800774 mRotationLockController.setRotationLockedAtAngle(true, mLastRotationSuggestion);
775 }
776
Mike Digman90402952018-01-22 16:05:51 -0800777 private boolean onRotateSuggestionHover(View v, MotionEvent event) {
778 final int action = event.getActionMasked();
779 mHoveringRotationSuggestion = (action == MotionEvent.ACTION_HOVER_ENTER)
780 || (action == MotionEvent.ACTION_HOVER_MOVE);
781 rescheduleRotationTimeout(true);
782 return false; // Must return false so a11y hover events are dispatched correctly.
783 }
784
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500785 // ----- Methods that StatusBar talks to (should be minimized) -----
Jason Monk49fa0162017-01-11 09:21:56 -0500786
Jason Monk49fa0162017-01-11 09:21:56 -0500787 public void setLightBarController(LightBarController lightBarController) {
788 mLightBarController = lightBarController;
789 mLightBarController.setNavigationBar(mNavigationBarView.getLightTransitionsController());
790 }
791
792 public boolean isSemiTransparent() {
793 return mNavigationBarMode == MODE_SEMI_TRANSPARENT;
794 }
795
Jason Monk49fa0162017-01-11 09:21:56 -0500796 public void disableAnimationsDuringHide(long delay) {
797 mNavigationBarView.setLayoutTransitionsEnabled(false);
798 mNavigationBarView.postDelayed(() -> mNavigationBarView.setLayoutTransitionsEnabled(true),
799 delay + StackStateAnimator.ANIMATION_DURATION_GO_TO_FULL_SHADE);
800 }
801
Jason Monk49fa0162017-01-11 09:21:56 -0500802 public BarTransitions getBarTransitions() {
803 return mNavigationBarView.getBarTransitions();
804 }
805
806 public void checkNavBarModes() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500807 mStatusBar.checkBarMode(mNavigationBarMode,
Jason Monk49fa0162017-01-11 09:21:56 -0500808 mNavigationBarWindowState, mNavigationBarView.getBarTransitions());
809 }
810
811 public void finishBarAnimations() {
812 mNavigationBarView.getBarTransitions().finishAnimations();
813 }
814
Jason Monk91e587e2017-04-13 13:41:23 -0400815 private final AccessibilityServicesStateChangeListener mAccessibilityListener =
816 this::updateAccessibilityServicesState;
817
Casey Burkhardt74922c62017-02-13 12:43:16 -0800818 private class MagnificationContentObserver extends ContentObserver {
819
820 public MagnificationContentObserver(Handler handler) {
821 super(handler);
822 }
823
824 @Override
825 public void onChange(boolean selfChange) {
Phil Weaverdb9a7742017-04-18 08:15:06 -0700826 NavigationBarFragment.this.updateAccessibilityServicesState(mAccessibilityManager);
Casey Burkhardt74922c62017-02-13 12:43:16 -0800827 }
828 }
829
Jason Monk49fa0162017-01-11 09:21:56 -0500830 private final Stub mRotationWatcher = new Stub() {
831 @Override
Mike Digman90402952018-01-22 16:05:51 -0800832 public void onRotationChanged(final int rotation) throws RemoteException {
Jason Monk49fa0162017-01-11 09:21:56 -0500833 // We need this to be scheduled as early as possible to beat the redrawing of
834 // window in response to the orientation change.
835 Handler h = getView().getHandler();
836 Message msg = Message.obtain(h, () -> {
Mike Digman85ff7fa2018-01-23 14:59:52 -0800837
838 // If the screen rotation changes while locked, potentially update lock to flow with
Mike Digman90402952018-01-22 16:05:51 -0800839 // new screen rotation and hide any showing suggestions.
840 if (mRotationLockController.isRotationLocked()) {
Mike Digman85ff7fa2018-01-23 14:59:52 -0800841 if (shouldOverrideUserLockPrefs(rotation)) {
842 mRotationLockController.setRotationLockedAtAngle(true, rotation);
843 }
Mike Digman90402952018-01-22 16:05:51 -0800844 setRotateSuggestionButtonState(false, true);
845 }
846
Jason Monk49fa0162017-01-11 09:21:56 -0500847 if (mNavigationBarView != null
848 && mNavigationBarView.needsReorient(rotation)) {
849 repositionNavigationBar();
850 }
851 });
852 msg.setAsynchronous(true);
853 h.sendMessageAtFrontOfQueue(msg);
854 }
Mike Digman85ff7fa2018-01-23 14:59:52 -0800855
856 private boolean shouldOverrideUserLockPrefs(final int rotation) {
857 // Only override user prefs when returning to portrait.
858 // Don't let apps that force landscape or 180 alter user lock.
859 return rotation == Surface.ROTATION_0;
860 }
Jason Monk49fa0162017-01-11 09:21:56 -0500861 };
862
863 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
864 @Override
865 public void onReceive(Context context, Intent intent) {
866 String action = intent.getAction();
Siarhei Vishniakoud002a0a2017-06-05 22:44:37 +0100867 if (Intent.ACTION_SCREEN_OFF.equals(action)
868 || Intent.ACTION_SCREEN_ON.equals(action)) {
869 notifyNavigationBarScreenOn();
Jason Monk49fa0162017-01-11 09:21:56 -0500870 }
871 }
872 };
873
Mike Digman7d092772018-01-11 12:10:32 -0800874 class TaskStackListenerImpl extends SysUiTaskStackChangeListener {
875 // Invalidate any rotation suggestion on task change or activity orientation change
876 // Note: all callbacks happen on main thread
877
878 @Override
879 public void onTaskStackChanged() {
880 setRotateSuggestionButtonState(false);
881 }
882
883 @Override
884 public void onTaskRemoved(int taskId) {
885 setRotateSuggestionButtonState(false);
886 }
887
888 @Override
889 public void onTaskMovedToFront(int taskId) {
890 setRotateSuggestionButtonState(false);
891 }
892
893 @Override
894 public void onActivityRequestedOrientationChanged(int taskId, int requestedOrientation) {
895 setRotateSuggestionButtonState(false);
896 }
897 }
898
Jason Monk49fa0162017-01-11 09:21:56 -0500899 public static View create(Context context, FragmentListener listener) {
900 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
901 LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
902 WindowManager.LayoutParams.TYPE_NAVIGATION_BAR,
903 WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
904 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
905 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
906 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
907 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
908 | WindowManager.LayoutParams.FLAG_SLIPPERY,
909 PixelFormat.TRANSLUCENT);
910 lp.token = new Binder();
Jason Monk49fa0162017-01-11 09:21:56 -0500911 lp.setTitle("NavigationBar");
912 lp.windowAnimations = 0;
913
914 View navigationBarView = LayoutInflater.from(context).inflate(
915 R.layout.navigation_bar_window, null);
916
917 if (DEBUG) Log.v(TAG, "addNavigationBar: about to add " + navigationBarView);
918 if (navigationBarView == null) return null;
919
920 context.getSystemService(WindowManager.class).addView(navigationBarView, lp);
921 FragmentHostManager fragmentHost = FragmentHostManager.get(navigationBarView);
922 NavigationBarFragment fragment = new NavigationBarFragment();
923 fragmentHost.getFragmentManager().beginTransaction()
924 .replace(R.id.navigation_bar_frame, fragment, TAG)
925 .commit();
926 fragmentHost.addTagListener(TAG, listener);
927 return navigationBarView;
928 }
929}