blob: 1003833f003a41f9a7028f5bfa02c914baedff69 [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;
Jason Monk49fa0162017-01-11 09:21:56 -050025import static com.android.systemui.statusbar.phone.BarTransitions.MODE_SEMI_TRANSPARENT;
Jason Monk2a6ea9c2017-01-26 11:14:51 -050026import static com.android.systemui.statusbar.phone.StatusBar.DEBUG_WINDOW_STATE;
27import static com.android.systemui.statusbar.phone.StatusBar.dumpBarTransitions;
Matthew Ng9c3bce52018-02-01 22:00:31 +000028import static com.android.systemui.OverviewProxyService.OverviewProxyListener;
Jason Monk49fa0162017-01-11 09:21:56 -050029
Casey Burkhardt048c2bc2016-12-08 16:09:20 -080030import android.accessibilityservice.AccessibilityServiceInfo;
Mike Digman7d092772018-01-11 12:10:32 -080031import android.animation.Animator;
32import android.animation.AnimatorListenerAdapter;
Mike Digman7d092772018-01-11 12:10:32 -080033import android.animation.ObjectAnimator;
Matthew Ng9c3bce52018-02-01 22:00:31 +000034import android.annotation.IdRes;
Jason Monk49fa0162017-01-11 09:21:56 -050035import android.annotation.Nullable;
36import android.app.ActivityManager;
37import android.app.ActivityManagerNative;
Wale Ogunwale65ebd952018-04-25 15:41:44 -070038import android.app.ActivityTaskManager;
Jason Monk49fa0162017-01-11 09:21:56 -050039import android.app.Fragment;
40import android.app.IActivityManager;
Wale Ogunwale04d9cb52018-04-30 13:55:07 -070041import android.app.IActivityTaskManager;
Jason Monk49fa0162017-01-11 09:21:56 -050042import android.app.StatusBarManager;
43import android.content.BroadcastReceiver;
Casey Burkhardtb9dcd662017-03-20 15:10:16 -070044import android.content.ContentResolver;
Jason Monk49fa0162017-01-11 09:21:56 -050045import android.content.Context;
46import android.content.Intent;
47import android.content.IntentFilter;
48import android.content.res.Configuration;
Casey Burkhardt74922c62017-02-13 12:43:16 -080049import android.database.ContentObserver;
Jason Monk49fa0162017-01-11 09:21:56 -050050import android.graphics.PixelFormat;
51import android.graphics.Rect;
Mike Digman7d092772018-01-11 12:10:32 -080052import android.graphics.drawable.AnimatedVectorDrawable;
Jason Monk49fa0162017-01-11 09:21:56 -050053import android.inputmethodservice.InputMethodService;
54import android.os.Binder;
55import android.os.Bundle;
56import android.os.Handler;
57import android.os.IBinder;
58import android.os.Message;
Jason Monk49fa0162017-01-11 09:21:56 -050059import android.os.RemoteException;
60import android.os.UserHandle;
Casey Burkhardt74922c62017-02-13 12:43:16 -080061import android.provider.Settings;
Aurimas Liutikasfd52c142018-04-17 09:50:46 -070062import androidx.annotation.VisibleForTesting;
Jason Monk49fa0162017-01-11 09:21:56 -050063import android.telecom.TelecomManager;
64import android.text.TextUtils;
65import android.util.Log;
66import android.view.IRotationWatcher.Stub;
67import android.view.KeyEvent;
68import android.view.LayoutInflater;
69import android.view.MotionEvent;
Mike Digman85ff7fa2018-01-23 14:59:52 -080070import android.view.Surface;
Jason Monk49fa0162017-01-11 09:21:56 -050071import android.view.View;
72import android.view.ViewGroup;
73import android.view.WindowManager;
74import android.view.WindowManager.LayoutParams;
75import android.view.WindowManagerGlobal;
76import android.view.accessibility.AccessibilityEvent;
77import android.view.accessibility.AccessibilityManager;
Jason Monk91e587e2017-04-13 13:41:23 -040078import android.view.accessibility.AccessibilityManager.AccessibilityServicesStateChangeListener;
Jason Monk49fa0162017-01-11 09:21:56 -050079
80import com.android.internal.logging.MetricsLogger;
81import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Jason Monkea03be12017-12-04 11:08:41 -050082import com.android.internal.util.LatencyTracker;
Jason Monk9c7844c2017-01-18 15:21:53 -050083import com.android.systemui.Dependency;
Mike Digman7d092772018-01-11 12:10:32 -080084import com.android.systemui.Interpolators;
Mike Digman1e28a5a2018-02-14 10:49:19 -080085import com.android.systemui.OverviewProxyService;
Jason Monk49fa0162017-01-11 09:21:56 -050086import com.android.systemui.R;
Jason Monk9c7844c2017-01-18 15:21:53 -050087import com.android.systemui.SysUiServiceProvider;
Jason Monk49fa0162017-01-11 09:21:56 -050088import com.android.systemui.assist.AssistManager;
89import com.android.systemui.fragments.FragmentHostManager;
90import com.android.systemui.fragments.FragmentHostManager.FragmentListener;
91import com.android.systemui.recents.Recents;
Mike Digman7d092772018-01-11 12:10:32 -080092import com.android.systemui.recents.misc.SysUiTaskStackChangeListener;
93import com.android.systemui.shared.system.ActivityManagerWrapper;
Jason Monk49fa0162017-01-11 09:21:56 -050094import com.android.systemui.stackdivider.Divider;
95import com.android.systemui.statusbar.CommandQueue;
96import com.android.systemui.statusbar.CommandQueue.Callbacks;
Jason Monk91e587e2017-04-13 13:41:23 -040097import com.android.systemui.statusbar.policy.AccessibilityManagerWrapper;
Mike Digman7d092772018-01-11 12:10:32 -080098import com.android.systemui.statusbar.policy.KeyButtonDrawable;
Jason Monk49fa0162017-01-11 09:21:56 -050099import com.android.systemui.statusbar.policy.KeyButtonView;
Mike Digman7d092772018-01-11 12:10:32 -0800100import com.android.systemui.statusbar.policy.RotationLockController;
Jason Monk49fa0162017-01-11 09:21:56 -0500101import com.android.systemui.statusbar.stack.StackStateAnimator;
102
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 Ng9c3bce52018-02-01 22:00:31 +0000184 }
Matthew Ng8f25fb962018-01-16 17:17:24 -0800185
186 @Override
187 public void onInteractionFlagsChanged(@InteractionType int flags) {
188 mNavigationBarView.updateStates();
Winson Chungf9e30272018-03-26 17:25:36 -0700189 updateScreenPinningGestures();
Matthew Ng8f25fb962018-01-16 17:17:24 -0800190 }
Matthew Ng96985e72018-05-08 15:46:13 -0700191
192 @Override
193 public void onBackButtonAlphaChanged(float alpha, boolean animate) {
194 final ButtonDispatcher backButton = mNavigationBarView.getBackButton();
195 backButton.setVisibility(alpha > 0 ? View.VISIBLE : View.INVISIBLE);
196 backButton.setAlpha(alpha, animate);
197 }
Matthew Ng9c3bce52018-02-01 22:00:31 +0000198 };
Mike Digman7d092772018-01-11 12:10:32 -0800199
Jason Monk49fa0162017-01-11 09:21:56 -0500200 // ----- Fragment Lifecycle Callbacks -----
201
202 @Override
203 public void onCreate(@Nullable Bundle savedInstanceState) {
204 super.onCreate(savedInstanceState);
Jason Monk9c7844c2017-01-18 15:21:53 -0500205 mCommandQueue = SysUiServiceProvider.getComponent(getContext(), CommandQueue.class);
Jason Monk49fa0162017-01-11 09:21:56 -0500206 mCommandQueue.addCallbacks(this);
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500207 mStatusBar = SysUiServiceProvider.getComponent(getContext(), StatusBar.class);
Jason Monk9c7844c2017-01-18 15:21:53 -0500208 mRecents = SysUiServiceProvider.getComponent(getContext(), Recents.class);
209 mDivider = SysUiServiceProvider.getComponent(getContext(), Divider.class);
Jason Monk49fa0162017-01-11 09:21:56 -0500210 mWindowManager = getContext().getSystemService(WindowManager.class);
211 mAccessibilityManager = getContext().getSystemService(AccessibilityManager.class);
Jason Monk91e587e2017-04-13 13:41:23 -0400212 Dependency.get(AccessibilityManagerWrapper.class).addCallback(
213 mAccessibilityListener);
Casey Burkhardtb9dcd662017-03-20 15:10:16 -0700214 mContentResolver = getContext().getContentResolver();
Casey Burkhardt74922c62017-02-13 12:43:16 -0800215 mMagnificationObserver = new MagnificationContentObserver(
216 getContext().getMainThreadHandler());
Casey Burkhardtb9dcd662017-03-20 15:10:16 -0700217 mContentResolver.registerContentObserver(Settings.Secure.getUriFor(
Casey Burkhardt74922c62017-02-13 12:43:16 -0800218 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED), false,
Casey Burkhardt5d614402017-04-06 13:46:50 -0700219 mMagnificationObserver, UserHandle.USER_ALL);
Casey Burkhardt74922c62017-02-13 12:43:16 -0800220
Jason Monk49fa0162017-01-11 09:21:56 -0500221 if (savedInstanceState != null) {
222 mDisabledFlags1 = savedInstanceState.getInt(EXTRA_DISABLE_STATE, 0);
Mike Digmandd2f49e2018-03-16 10:54:22 -0700223 mDisabledFlags2 = savedInstanceState.getInt(EXTRA_DISABLE2_STATE, 0);
Jason Monk49fa0162017-01-11 09:21:56 -0500224 }
Jason Monk9c7844c2017-01-18 15:21:53 -0500225 mAssistManager = Dependency.get(AssistManager.class);
Matthew Ngdc79e5c2017-12-14 17:37:35 -0800226 mOverviewProxyService = Dependency.get(OverviewProxyService.class);
Jason Monk49fa0162017-01-11 09:21:56 -0500227
228 try {
229 WindowManagerGlobal.getWindowManagerService()
Andrii Kulian35fa3c22017-03-11 09:37:28 -0800230 .watchRotation(mRotationWatcher, getContext().getDisplay().getDisplayId());
Jason Monk49fa0162017-01-11 09:21:56 -0500231 } catch (RemoteException e) {
232 throw e.rethrowFromSystemServer();
233 }
Mike Digman7d092772018-01-11 12:10:32 -0800234
235 mRotationLockController = Dependency.get(RotationLockController.class);
236
Mike Digmanab650252018-03-06 11:01:41 -0800237 // Reset user rotation pref to match that of the WindowManager if starting in locked mode
238 // This will automatically happen when switching from auto-rotate to locked mode
239 if (mRotationLockController.isRotationLocked()) {
240 final int winRotation = mWindowManager.getDefaultDisplay().getRotation();
241 mRotationLockController.setRotationLockedAtAngle(true, winRotation);
242 }
243
Mike Digman7d092772018-01-11 12:10:32 -0800244 // Register the task stack listener
245 mTaskStackListener = new TaskStackListenerImpl();
246 ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener);
Jason Monk49fa0162017-01-11 09:21:56 -0500247 }
248
249 @Override
250 public void onDestroy() {
251 super.onDestroy();
252 mCommandQueue.removeCallbacks(this);
Jason Monk91e587e2017-04-13 13:41:23 -0400253 Dependency.get(AccessibilityManagerWrapper.class).removeCallback(
254 mAccessibilityListener);
Casey Burkhardtb9dcd662017-03-20 15:10:16 -0700255 mContentResolver.unregisterContentObserver(mMagnificationObserver);
Jason Monk49fa0162017-01-11 09:21:56 -0500256 try {
257 WindowManagerGlobal.getWindowManagerService()
258 .removeRotationWatcher(mRotationWatcher);
259 } catch (RemoteException e) {
260 throw e.rethrowFromSystemServer();
261 }
Mike Digman7d092772018-01-11 12:10:32 -0800262
263 // Unregister the task stack listener
264 ActivityManagerWrapper.getInstance().unregisterTaskStackListener(mTaskStackListener);
Jason Monk49fa0162017-01-11 09:21:56 -0500265 }
266
267 @Override
268 public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
269 Bundle savedInstanceState) {
270 return inflater.inflate(R.layout.navigation_bar, container, false);
271 }
272
273 @Override
274 public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
275 super.onViewCreated(view, savedInstanceState);
276 mNavigationBarView = (NavigationBarView) view;
277
278 mNavigationBarView.setDisabledFlags(mDisabledFlags1);
Matthew Ng78f88d12018-01-23 12:39:55 -0800279 mNavigationBarView.setComponents(mRecents, mDivider, mStatusBar.getPanel());
Jason Monk49fa0162017-01-11 09:21:56 -0500280 mNavigationBarView.setOnVerticalChangedListener(this::onVerticalChanged);
281 mNavigationBarView.setOnTouchListener(this::onNavigationTouch);
282 if (savedInstanceState != null) {
283 mNavigationBarView.getLightTransitionsController().restoreState(savedInstanceState);
284 }
285
286 prepareNavigationBarView();
287 checkNavBarModes();
288
Mike Digmandd2f49e2018-03-16 10:54:22 -0700289 setDisabled2Flags(mDisabledFlags2);
290
Jason Monk49fa0162017-01-11 09:21:56 -0500291 IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
292 filter.addAction(Intent.ACTION_SCREEN_ON);
Phil Weavera858c5f2018-04-26 13:27:30 -0700293 filter.addAction(Intent.ACTION_USER_SWITCHED);
Jason Monk49fa0162017-01-11 09:21:56 -0500294 getContext().registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, filter, null, null);
Siarhei Vishniakoud002a0a2017-06-05 22:44:37 +0100295 notifyNavigationBarScreenOn();
Matthew Ng9c3bce52018-02-01 22:00:31 +0000296 mOverviewProxyService.addCallback(mOverviewProxyListener);
Jason Monk49fa0162017-01-11 09:21:56 -0500297 }
298
299 @Override
300 public void onDestroyView() {
301 super.onDestroyView();
Jason Monkaa573e92017-01-27 17:00:29 -0500302 mNavigationBarView.getLightTransitionsController().destroy(getContext());
Matthew Ng9c3bce52018-02-01 22:00:31 +0000303 mOverviewProxyService.removeCallback(mOverviewProxyListener);
Jason Monk49fa0162017-01-11 09:21:56 -0500304 getContext().unregisterReceiver(mBroadcastReceiver);
305 }
306
307 @Override
308 public void onSaveInstanceState(Bundle outState) {
309 super.onSaveInstanceState(outState);
310 outState.putInt(EXTRA_DISABLE_STATE, mDisabledFlags1);
Mike Digmandd2f49e2018-03-16 10:54:22 -0700311 outState.putInt(EXTRA_DISABLE2_STATE, mDisabledFlags2);
Jason Monk49fa0162017-01-11 09:21:56 -0500312 if (mNavigationBarView != null) {
313 mNavigationBarView.getLightTransitionsController().saveState(outState);
314 }
315 }
316
317 @Override
318 public void onConfigurationChanged(Configuration newConfig) {
319 super.onConfigurationChanged(newConfig);
320 final Locale locale = getContext().getResources().getConfiguration().locale;
321 final int ld = TextUtils.getLayoutDirectionFromLocale(locale);
322 if (!locale.equals(mLocale) || ld != mLayoutDirection) {
323 if (DEBUG) {
324 Log.v(TAG, String.format(
325 "config changed locale/LD: %s (%d) -> %s (%d)", mLocale, mLayoutDirection,
326 locale, ld));
327 }
328 mLocale = locale;
329 mLayoutDirection = ld;
330 refreshLayout(ld);
331 }
332 repositionNavigationBar();
333 }
334
335 @Override
336 public void dump(String prefix, FileDescriptor fd, PrintWriter pw, String[] args) {
337 if (mNavigationBarView != null) {
338 pw.print(" mNavigationBarWindowState=");
339 pw.println(windowStateToString(mNavigationBarWindowState));
340 pw.print(" mNavigationBarMode=");
341 pw.println(BarTransitions.modeToString(mNavigationBarMode));
342 dumpBarTransitions(pw, "mNavigationBarView", mNavigationBarView.getBarTransitions());
343 }
344
345 pw.print(" mNavigationBarView=");
346 if (mNavigationBarView == null) {
347 pw.println("null");
348 } else {
349 mNavigationBarView.dump(fd, pw, args);
350 }
351 }
352
353 // ----- CommandQueue Callbacks -----
354
355 @Override
356 public void setImeWindowStatus(IBinder token, int vis, int backDisposition,
357 boolean showImeSwitcher) {
358 boolean imeShown = (vis & InputMethodService.IME_VISIBLE) != 0;
359 int hints = mNavigationIconHints;
Yohei Yukawa386f50e2018-03-14 13:03:42 -0700360 switch (backDisposition) {
361 case InputMethodService.BACK_DISPOSITION_DEFAULT:
362 case InputMethodService.BACK_DISPOSITION_WILL_NOT_DISMISS:
363 case InputMethodService.BACK_DISPOSITION_WILL_DISMISS:
364 if (imeShown) {
365 hints |= NAVIGATION_HINT_BACK_ALT;
366 } else {
367 hints &= ~NAVIGATION_HINT_BACK_ALT;
368 }
369 break;
370 case InputMethodService.BACK_DISPOSITION_ADJUST_NOTHING:
371 hints &= ~NAVIGATION_HINT_BACK_ALT;
372 break;
Jason Monk49fa0162017-01-11 09:21:56 -0500373 }
374 if (showImeSwitcher) {
375 hints |= NAVIGATION_HINT_IME_SHOWN;
376 } else {
377 hints &= ~NAVIGATION_HINT_IME_SHOWN;
378 }
379 if (hints == mNavigationIconHints) return;
380
381 mNavigationIconHints = hints;
382
383 if (mNavigationBarView != null) {
384 mNavigationBarView.setNavigationIconHints(hints);
385 }
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500386 mStatusBar.checkBarModes();
Jason Monk49fa0162017-01-11 09:21:56 -0500387 }
388
389 @Override
390 public void topAppWindowChanged(boolean showMenu) {
391 if (mNavigationBarView != null) {
392 mNavigationBarView.setMenuVisibility(showMenu);
393 }
394 }
395
396 @Override
397 public void setWindowState(int window, int state) {
398 if (mNavigationBarView != null
399 && window == StatusBarManager.WINDOW_NAVIGATION_BAR
400 && mNavigationBarWindowState != state) {
401 mNavigationBarWindowState = state;
402 if (DEBUG_WINDOW_STATE) Log.d(TAG, "Navigation bar " + windowStateToString(state));
Mike Digman5aeca792018-03-05 11:14:39 -0800403
404 // If the navbar is visible, show the rotate button if there's a pending suggestion
405 if (state == WINDOW_STATE_SHOWING && mPendingRotationSuggestion) {
406 showAndLogRotationSuggestion();
407 }
Jason Monk49fa0162017-01-11 09:21:56 -0500408 }
409 }
410
Mike Digman7d092772018-01-11 12:10:32 -0800411 @Override
Mike Digmane0777312018-01-19 12:41:51 -0800412 public void onRotationProposal(final int rotation, boolean isValid) {
Mike Digman3e33da62018-03-14 16:25:11 -0700413 final int winRotation = mWindowManager.getDefaultDisplay().getRotation();
Mike Digmandd2f49e2018-03-16 10:54:22 -0700414 final boolean rotateSuggestionsDisabled = hasDisable2RotateSuggestionFlag(mDisabledFlags2);
Mike Digman3e33da62018-03-14 16:25:11 -0700415 if (DEBUG_ROTATION) {
416 Log.v(TAG, "onRotationProposal proposedRotation=" + Surface.rotationToString(rotation)
417 + ", winRotation=" + Surface.rotationToString(winRotation)
418 + ", isValid=" + isValid + ", mNavBarWindowState="
419 + StatusBarManager.windowStateToString(mNavigationBarWindowState)
Mike Digmandd2f49e2018-03-16 10:54:22 -0700420 + ", rotateSuggestionsDisabled=" + rotateSuggestionsDisabled
Mike Digman3e33da62018-03-14 16:25:11 -0700421 + ", isRotateButtonVisible=" + (mNavigationBarView == null ? "null" :
422 mNavigationBarView.isRotateButtonVisible()));
423 }
424
Mike Digmandd2f49e2018-03-16 10:54:22 -0700425 // Respect the disabled flag, no need for action as flag change callback will handle hiding
426 if (rotateSuggestionsDisabled) return;
427
Mike Digmane0777312018-01-19 12:41:51 -0800428 // This method will be called on rotation suggestion changes even if the proposed rotation
429 // is not valid for the top app. Use invalid rotation choices as a signal to remove the
430 // rotate button if shown.
Mike Digmane0777312018-01-19 12:41:51 -0800431 if (!isValid) {
Mike Digman1e28a5a2018-02-14 10:49:19 -0800432 setRotateSuggestionButtonState(false);
Mike Digmane0777312018-01-19 12:41:51 -0800433 return;
434 }
435
Mike Digman5aeca792018-03-05 11:14:39 -0800436 // If window rotation matches suggested rotation, remove any current suggestions
Mike Digman1e28a5a2018-02-14 10:49:19 -0800437 if (rotation == winRotation) {
Mike Digman5aeca792018-03-05 11:14:39 -0800438 getView().removeCallbacks(mRemoveRotationProposal);
Mike Digman1e28a5a2018-02-14 10:49:19 -0800439 setRotateSuggestionButtonState(false);
Mike Digman5aeca792018-03-05 11:14:39 -0800440 return;
Mike Digman7d092772018-01-11 12:10:32 -0800441 }
Mike Digman5aeca792018-03-05 11:14:39 -0800442
443 // Prepare to show the navbar icon by updating the icon style to change anim params
444 mLastRotationSuggestion = rotation; // Remember rotation for click
445 if (mNavigationBarView != null) {
446 final boolean rotationCCW = isRotationAnimationCCW(winRotation, rotation);
447 int style;
448 if (winRotation == Surface.ROTATION_0 || winRotation == Surface.ROTATION_180) {
449 style = rotationCCW ? R.style.RotateButtonCCWStart90 :
450 R.style.RotateButtonCWStart90;
451 } else { // 90 or 270
452 style = rotationCCW ? R.style.RotateButtonCCWStart0 :
453 R.style.RotateButtonCWStart0;
454 }
455 mNavigationBarView.updateRotateSuggestionButtonStyle(style, true);
456 }
457
458 if (mNavigationBarWindowState != WINDOW_STATE_SHOWING) {
459 // If the navbar isn't shown, flag the rotate icon to be shown should the navbar become
460 // visible given some time limit.
461 mPendingRotationSuggestion = true;
462 getView().removeCallbacks(mCancelPendingRotationProposal);
463 getView().postDelayed(mCancelPendingRotationProposal,
464 NAVBAR_HIDDEN_PENDING_ICON_TIMEOUT_MS);
465
466 } else { // The navbar is visible so show the icon right away
467 showAndLogRotationSuggestion();
468 }
469 }
470
Mike Digmandd2f49e2018-03-16 10:54:22 -0700471 private void onRotationSuggestionsDisabled() {
472 // Immediately hide the rotate button and clear any planned removal
473 setRotateSuggestionButtonState(false, true);
Mike Digmane14c4752018-03-20 12:14:54 -0700474
475 // This method can be called before view setup is done, ensure getView isn't null
476 final View v = getView();
477 if (v != null) v.removeCallbacks(mRemoveRotationProposal);
Mike Digmandd2f49e2018-03-16 10:54:22 -0700478 }
479
Mike Digman5aeca792018-03-05 11:14:39 -0800480 private void showAndLogRotationSuggestion() {
481 setRotateSuggestionButtonState(true);
482 rescheduleRotationTimeout(false);
483 mMetricsLogger.visible(MetricsEvent.ROTATION_SUGGESTION_SHOWN);
Mike Digman7d092772018-01-11 12:10:32 -0800484 }
485
Mike Digman1e28a5a2018-02-14 10:49:19 -0800486 private boolean isRotationAnimationCCW(int from, int to) {
487 // All 180deg WM rotation animations are CCW, match that
488 if (from == Surface.ROTATION_0 && to == Surface.ROTATION_90) return false;
489 if (from == Surface.ROTATION_0 && to == Surface.ROTATION_180) return true; //180d so CCW
490 if (from == Surface.ROTATION_0 && to == Surface.ROTATION_270) return true;
491 if (from == Surface.ROTATION_90 && to == Surface.ROTATION_0) return true;
492 if (from == Surface.ROTATION_90 && to == Surface.ROTATION_180) return false;
493 if (from == Surface.ROTATION_90 && to == Surface.ROTATION_270) return true; //180d so CCW
494 if (from == Surface.ROTATION_180 && to == Surface.ROTATION_0) return true; //180d so CCW
495 if (from == Surface.ROTATION_180 && to == Surface.ROTATION_90) return true;
496 if (from == Surface.ROTATION_180 && to == Surface.ROTATION_270) return false;
497 if (from == Surface.ROTATION_270 && to == Surface.ROTATION_0) return false;
498 if (from == Surface.ROTATION_270 && to == Surface.ROTATION_90) return true; //180d so CCW
499 if (from == Surface.ROTATION_270 && to == Surface.ROTATION_180) return true;
500 return false; // Default
Mike Digmana48cf192018-02-12 17:52:48 -0800501 }
502
Mike Digman1e28a5a2018-02-14 10:49:19 -0800503 public void setRotateSuggestionButtonState(final boolean visible) {
504 setRotateSuggestionButtonState(visible, false);
505 }
506
507 public void setRotateSuggestionButtonState(final boolean visible, final boolean force) {
508 if (mNavigationBarView == null) return;
509
510 // At any point the the button can become invisible because an a11y service became active.
511 // Similarly, a call to make the button visible may be rejected because an a11y service is
512 // active. Must account for this.
513
514 ButtonDispatcher rotBtn = mNavigationBarView.getRotateSuggestionButton();
515 final boolean currentlyVisible = mNavigationBarView.isRotateButtonVisible();
516
517 // Rerun a show animation to indicate change but don't rerun a hide animation
518 if (!visible && !currentlyVisible) return;
519
520 View view = rotBtn.getCurrentView();
521 if (view == null) return;
522
523 KeyButtonDrawable kbd = rotBtn.getImageDrawable();
524 if (kbd == null) return;
525
526 // The KBD and AVD is recreated every new valid suggestion because of style changes.
527 AnimatedVectorDrawable animIcon = null;
528 if (kbd.getDrawable(0) instanceof AnimatedVectorDrawable) {
529 animIcon = (AnimatedVectorDrawable) kbd.getDrawable(0);
530 }
531
Mike Digman5aeca792018-03-05 11:14:39 -0800532 // Clear any pending suggestion flag as it has either been nullified or is being shown
533 mPendingRotationSuggestion = false;
Mike Digmanf4c98992018-04-25 11:25:59 -0700534 if (getView() != null) getView().removeCallbacks(mCancelPendingRotationProposal);
Mike Digman5aeca792018-03-05 11:14:39 -0800535
536 // Handle the visibility change and animation
Mike Digman1e28a5a2018-02-14 10:49:19 -0800537 if (visible) { // Appear and change (cannot force)
Mike Digman85a9bea2018-02-23 15:08:53 -0800538 // Stop and clear any currently running hide animations
Mike Digman1e28a5a2018-02-14 10:49:19 -0800539 if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) {
Mike Digman85a9bea2018-02-23 15:08:53 -0800540 mRotateHideAnimator.cancel();
Mike Digman1e28a5a2018-02-14 10:49:19 -0800541 }
Mike Digman85a9bea2018-02-23 15:08:53 -0800542 mRotateHideAnimator = null;
Mike Digman1e28a5a2018-02-14 10:49:19 -0800543
544 // Reset the alpha if any has changed due to hide animation
545 view.setAlpha(1f);
546
547 // Run the rotate icon's animation if it has one
548 if (animIcon != null) {
549 animIcon.reset();
550 animIcon.start();
551 }
552
Mike Digman50752642018-02-15 13:36:09 -0800553 if (!isRotateSuggestionIntroduced()) mViewRippler.start(view);
554
Mike Digman1e28a5a2018-02-14 10:49:19 -0800555 // Set visibility, may fail if a11y service is active.
556 // If invisible, call will stop animation.
Mike Digman9b50b762018-04-19 10:50:35 -0700557 int appliedVisibility = mNavigationBarView.setRotateButtonVisibility(true);
558 if (appliedVisibility == View.VISIBLE) {
559 // If the button will actually become visible and the navbar is about to hide,
560 // tell the statusbar to keep it around for longer
561 mStatusBar.touchAutoHide();
562 }
Mike Digman1e28a5a2018-02-14 10:49:19 -0800563
564 } else { // Hide
565
Mike Digman50752642018-02-15 13:36:09 -0800566 mViewRippler.stop(); // Prevent any pending ripples, force hide or not
567
Mike Digman1e28a5a2018-02-14 10:49:19 -0800568 if (force) {
569 // If a hide animator is running stop it and make invisible
570 if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) {
571 mRotateHideAnimator.pause();
572 }
573 mNavigationBarView.setRotateButtonVisibility(false);
574 return;
575 }
576
577 // Don't start any new hide animations if one is running
578 if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) return;
579
580 ObjectAnimator fadeOut = ObjectAnimator.ofFloat(view, "alpha",
581 0f);
582 fadeOut.setDuration(BUTTON_FADE_IN_OUT_DURATION_MS);
583 fadeOut.setInterpolator(Interpolators.LINEAR);
584 fadeOut.addListener(new AnimatorListenerAdapter() {
585 @Override
586 public void onAnimationEnd(Animator animation) {
587 mNavigationBarView.setRotateButtonVisibility(false);
588 }
589 });
590
591 mRotateHideAnimator = fadeOut;
592 fadeOut.start();
Mike Digmana48cf192018-02-12 17:52:48 -0800593 }
594 }
595
Mike Digman90402952018-01-22 16:05:51 -0800596 private void rescheduleRotationTimeout(final boolean reasonHover) {
597 // May be called due to a new rotation proposal or a change in hover state
598 if (reasonHover) {
599 // Don't reschedule if a hide animator is running
Mike Digman1e28a5a2018-02-14 10:49:19 -0800600 if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) return;
Mike Digman90402952018-01-22 16:05:51 -0800601 // Don't reschedule if not visible
Mike Digman1e28a5a2018-02-14 10:49:19 -0800602 if (!mNavigationBarView.isRotateButtonVisible()) return;
Mike Digman90402952018-01-22 16:05:51 -0800603 }
604
Mike Digman5aeca792018-03-05 11:14:39 -0800605 getView().removeCallbacks(mRemoveRotationProposal); // Stop any pending removal
606 getView().postDelayed(mRemoveRotationProposal,
Mike Digman90402952018-01-22 16:05:51 -0800607 computeRotationProposalTimeout()); // Schedule timeout
608 }
609
610 private int computeRotationProposalTimeout() {
611 if (mAccessibilityFeedbackEnabled) return 20000;
612 if (mHoveringRotationSuggestion) return 16000;
Mike Digmand13e43b2018-05-21 11:23:56 -0700613 return 10000;
Mike Digman90402952018-01-22 16:05:51 -0800614 }
615
Mike Digman50752642018-02-15 13:36:09 -0800616 private boolean isRotateSuggestionIntroduced() {
617 ContentResolver cr = getContext().getContentResolver();
618 return Settings.Secure.getInt(cr, Settings.Secure.NUM_ROTATION_SUGGESTIONS_ACCEPTED, 0)
619 >= NUM_ACCEPTED_ROTATION_SUGGESTIONS_FOR_INTRODUCTION;
620 }
621
622 private void incrementNumAcceptedRotationSuggestionsIfNeeded() {
623 // Get the number of accepted suggestions
624 ContentResolver cr = getContext().getContentResolver();
625 final int numSuggestions = Settings.Secure.getInt(cr,
626 Settings.Secure.NUM_ROTATION_SUGGESTIONS_ACCEPTED, 0);
627
628 // Increment the number of accepted suggestions only if it would change intro mode
629 if (numSuggestions < NUM_ACCEPTED_ROTATION_SUGGESTIONS_FOR_INTRODUCTION) {
630 Settings.Secure.putInt(cr, Settings.Secure.NUM_ROTATION_SUGGESTIONS_ACCEPTED,
631 numSuggestions + 1);
632 }
633 }
634
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500635 // Injected from StatusBar at creation.
Jason Monk49fa0162017-01-11 09:21:56 -0500636 public void setCurrentSysuiVisibility(int systemUiVisibility) {
637 mSystemUiVisibility = systemUiVisibility;
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500638 mNavigationBarMode = mStatusBar.computeBarMode(0, mSystemUiVisibility,
Jason Monk49fa0162017-01-11 09:21:56 -0500639 View.NAVIGATION_BAR_TRANSIENT, View.NAVIGATION_BAR_TRANSLUCENT,
640 View.NAVIGATION_BAR_TRANSPARENT);
641 checkNavBarModes();
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500642 mStatusBar.touchAutoHide();
Jason Monk49fa0162017-01-11 09:21:56 -0500643 mLightBarController.onNavigationVisibilityChanged(mSystemUiVisibility, 0 /* mask */,
644 true /* nbModeChanged */, mNavigationBarMode);
645 }
646
647 @Override
648 public void setSystemUiVisibility(int vis, int fullscreenStackVis, int dockedStackVis,
649 int mask, Rect fullscreenStackBounds, Rect dockedStackBounds) {
650 final int oldVal = mSystemUiVisibility;
651 final int newVal = (oldVal & ~mask) | (vis & mask);
652 final int diff = newVal ^ oldVal;
653 boolean nbModeChanged = false;
654 if (diff != 0) {
655 mSystemUiVisibility = newVal;
656
657 // update navigation bar mode
658 final int nbMode = getView() == null
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500659 ? -1 : mStatusBar.computeBarMode(oldVal, newVal,
Jason Monk49fa0162017-01-11 09:21:56 -0500660 View.NAVIGATION_BAR_TRANSIENT, View.NAVIGATION_BAR_TRANSLUCENT,
661 View.NAVIGATION_BAR_TRANSPARENT);
662 nbModeChanged = nbMode != -1;
663 if (nbModeChanged) {
664 if (mNavigationBarMode != nbMode) {
665 mNavigationBarMode = nbMode;
666 checkNavBarModes();
667 }
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500668 mStatusBar.touchAutoHide();
Jason Monk49fa0162017-01-11 09:21:56 -0500669 }
670 }
671
672 mLightBarController.onNavigationVisibilityChanged(vis, mask, nbModeChanged,
673 mNavigationBarMode);
674 }
675
676 @Override
677 public void disable(int state1, int state2, boolean animate) {
Mike Digmandd2f49e2018-03-16 10:54:22 -0700678 // Navigation bar flags are in both state1 and state2.
679 final int masked = state1 & (StatusBarManager.DISABLE_HOME
Jason Monk49fa0162017-01-11 09:21:56 -0500680 | StatusBarManager.DISABLE_RECENT
681 | StatusBarManager.DISABLE_BACK
682 | StatusBarManager.DISABLE_SEARCH);
683 if (masked != mDisabledFlags1) {
684 mDisabledFlags1 = masked;
685 if (mNavigationBarView != null) mNavigationBarView.setDisabledFlags(state1);
Matthew Ng9c3bce52018-02-01 22:00:31 +0000686 updateScreenPinningGestures();
Jason Monk49fa0162017-01-11 09:21:56 -0500687 }
Mike Digmandd2f49e2018-03-16 10:54:22 -0700688
689 final int masked2 = state2 & (StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS);
690 if (masked2 != mDisabledFlags2) {
691 mDisabledFlags2 = masked2;
692 setDisabled2Flags(masked2);
693 }
694 }
695
696 private void setDisabled2Flags(int state2) {
697 // Method only called on change of disable2 flags
698 final boolean rotateSuggestionsDisabled = hasDisable2RotateSuggestionFlag(state2);
699 if (rotateSuggestionsDisabled) onRotationSuggestionsDisabled();
700 }
701
702 private boolean hasDisable2RotateSuggestionFlag(int disable2Flags) {
703 return (disable2Flags & StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS) != 0;
Jason Monk49fa0162017-01-11 09:21:56 -0500704 }
705
706 // ----- Internal stuffz -----
707
708 private void refreshLayout(int layoutDirection) {
709 if (mNavigationBarView != null) {
710 mNavigationBarView.setLayoutDirection(layoutDirection);
711 }
712 }
713
714 private boolean shouldDisableNavbarGestures() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500715 return !mStatusBar.isDeviceProvisioned()
Matthew Ngfee0b5b2018-02-21 15:38:21 -0800716 || (mDisabledFlags1 & StatusBarManager.DISABLE_SEARCH) != 0;
Jason Monk49fa0162017-01-11 09:21:56 -0500717 }
718
719 private void repositionNavigationBar() {
720 if (mNavigationBarView == null || !mNavigationBarView.isAttachedToWindow()) return;
721
722 prepareNavigationBarView();
723
724 mWindowManager.updateViewLayout((View) mNavigationBarView.getParent(),
725 ((View) mNavigationBarView.getParent()).getLayoutParams());
726 }
727
Matthew Ng9c3bce52018-02-01 22:00:31 +0000728 private void updateScreenPinningGestures() {
729 if (mNavigationBarView == null) {
730 return;
731 }
732
733 // Change the cancel pin gesture to home and back if recents button is invisible
734 boolean recentsVisible = mNavigationBarView.isRecentsButtonVisible();
Matthew Ng9c3bce52018-02-01 22:00:31 +0000735 ButtonDispatcher backButton = mNavigationBarView.getBackButton();
736 if (recentsVisible) {
Matthew Ng9c3bce52018-02-01 22:00:31 +0000737 backButton.setOnLongClickListener(this::onLongPressBackRecents);
738 } else {
Matthew Ng9c3bce52018-02-01 22:00:31 +0000739 backButton.setOnLongClickListener(this::onLongPressBackHome);
740 }
741 }
742
Siarhei Vishniakoud002a0a2017-06-05 22:44:37 +0100743 private void notifyNavigationBarScreenOn() {
Matthew Ngd0a73e72018-03-02 15:16:03 -0800744 mNavigationBarView.updateNavButtonIcons();
Jason Monk49fa0162017-01-11 09:21:56 -0500745 }
746
747 private void prepareNavigationBarView() {
748 mNavigationBarView.reorient();
749
750 ButtonDispatcher recentsButton = mNavigationBarView.getRecentsButton();
751 recentsButton.setOnClickListener(this::onRecentsClick);
752 recentsButton.setOnTouchListener(this::onRecentsTouch);
753 recentsButton.setLongClickable(true);
754 recentsButton.setOnLongClickListener(this::onLongPressBackRecents);
755
756 ButtonDispatcher backButton = mNavigationBarView.getBackButton();
757 backButton.setLongClickable(true);
Jason Monk49fa0162017-01-11 09:21:56 -0500758
759 ButtonDispatcher homeButton = mNavigationBarView.getHomeButton();
760 homeButton.setOnTouchListener(this::onHomeTouch);
Matthew Ngfee0b5b2018-02-21 15:38:21 -0800761 homeButton.setOnLongClickListener(this::onHomeLongClick);
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800762
763 ButtonDispatcher accessibilityButton = mNavigationBarView.getAccessibilityButton();
764 accessibilityButton.setOnClickListener(this::onAccessibilityClick);
765 accessibilityButton.setOnLongClickListener(this::onAccessibilityLongClick);
Phil Weaverdb9a7742017-04-18 08:15:06 -0700766 updateAccessibilityServicesState(mAccessibilityManager);
Mike Digman7d092772018-01-11 12:10:32 -0800767
768 ButtonDispatcher rotateSuggestionButton = mNavigationBarView.getRotateSuggestionButton();
769 rotateSuggestionButton.setOnClickListener(this::onRotateSuggestionClick);
Mike Digman90402952018-01-22 16:05:51 -0800770 rotateSuggestionButton.setOnHoverListener(this::onRotateSuggestionHover);
Matthew Ng9c3bce52018-02-01 22:00:31 +0000771 updateScreenPinningGestures();
Jason Monk49fa0162017-01-11 09:21:56 -0500772 }
773
774 private boolean onHomeTouch(View v, MotionEvent event) {
775 if (mHomeBlockedThisTouch && event.getActionMasked() != MotionEvent.ACTION_DOWN) {
776 return true;
777 }
778 // If an incoming call is ringing, HOME is totally disabled.
779 // (The user is already on the InCallUI at this point,
780 // and his ONLY options are to answer or reject the call.)
781 switch (event.getAction()) {
782 case MotionEvent.ACTION_DOWN:
783 mHomeBlockedThisTouch = false;
784 TelecomManager telecomManager =
785 getContext().getSystemService(TelecomManager.class);
786 if (telecomManager != null && telecomManager.isRinging()) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500787 if (mStatusBar.isKeyguardShowing()) {
Jason Monk49fa0162017-01-11 09:21:56 -0500788 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call. " +
789 "No heads up");
790 mHomeBlockedThisTouch = true;
791 return true;
792 }
793 }
794 break;
795 case MotionEvent.ACTION_UP:
796 case MotionEvent.ACTION_CANCEL:
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500797 mStatusBar.awakenDreams();
Jason Monk49fa0162017-01-11 09:21:56 -0500798 break;
799 }
800 return false;
801 }
802
803 private void onVerticalChanged(boolean isVertical) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500804 mStatusBar.setQsScrimEnabled(!isVertical);
Jason Monk49fa0162017-01-11 09:21:56 -0500805 }
806
807 private boolean onNavigationTouch(View v, MotionEvent event) {
Eliot Courtneycb5d3162017-08-09 16:53:15 +0900808 mStatusBar.checkUserAutohide(event);
Jason Monk49fa0162017-01-11 09:21:56 -0500809 return false;
810 }
811
Jason Monk865246d2017-01-19 08:27:01 -0500812 @VisibleForTesting
813 boolean onHomeLongClick(View v) {
Matthew Ng6ff33b72018-02-27 13:47:38 -0800814 if (!mNavigationBarView.isRecentsButtonVisible()
815 && ActivityManagerWrapper.getInstance().isScreenPinningActive()) {
Matthew Ngfee0b5b2018-02-21 15:38:21 -0800816 return onLongPressBackHome(v);
817 }
Jason Monk49fa0162017-01-11 09:21:56 -0500818 if (shouldDisableNavbarGestures()) {
819 return false;
820 }
Matthew Ng2ea93b72018-03-14 19:43:18 +0000821 mNavigationBarView.onNavigationButtonLongPress(v);
Mike Digmanc94759d2018-01-23 11:01:21 -0800822 mMetricsLogger.action(MetricsEvent.ACTION_ASSIST_LONG_PRESS);
Jason Monk49fa0162017-01-11 09:21:56 -0500823 mAssistManager.startAssist(new Bundle() /* args */);
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500824 mStatusBar.awakenDreams();
Matthew Ngdc79e5c2017-12-14 17:37:35 -0800825
Jason Monk49fa0162017-01-11 09:21:56 -0500826 if (mNavigationBarView != null) {
827 mNavigationBarView.abortCurrentGesture();
828 }
829 return true;
830 }
831
832 // additional optimization when we have software system buttons - start loading the recent
833 // tasks on touch down
834 private boolean onRecentsTouch(View v, MotionEvent event) {
835 int action = event.getAction() & MotionEvent.ACTION_MASK;
836 if (action == MotionEvent.ACTION_DOWN) {
837 mCommandQueue.preloadRecentApps();
838 } else if (action == MotionEvent.ACTION_CANCEL) {
839 mCommandQueue.cancelPreloadRecentApps();
840 } else if (action == MotionEvent.ACTION_UP) {
841 if (!v.isPressed()) {
842 mCommandQueue.cancelPreloadRecentApps();
843 }
844 }
845 return false;
846 }
847
848 private void onRecentsClick(View v) {
849 if (LatencyTracker.isEnabled(getContext())) {
850 LatencyTracker.getInstance(getContext()).onActionStart(
851 LatencyTracker.ACTION_TOGGLE_RECENTS);
852 }
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500853 mStatusBar.awakenDreams();
Jason Monk49fa0162017-01-11 09:21:56 -0500854 mCommandQueue.toggleRecentApps();
855 }
856
Matthew Ng9c3bce52018-02-01 22:00:31 +0000857 private boolean onLongPressBackHome(View v) {
Matthew Ng2ea93b72018-03-14 19:43:18 +0000858 mNavigationBarView.onNavigationButtonLongPress(v);
Matthew Ng9c3bce52018-02-01 22:00:31 +0000859 return onLongPressNavigationButtons(v, R.id.back, R.id.home);
860 }
861
862 private boolean onLongPressBackRecents(View v) {
Matthew Ng2ea93b72018-03-14 19:43:18 +0000863 mNavigationBarView.onNavigationButtonLongPress(v);
Matthew Ng9c3bce52018-02-01 22:00:31 +0000864 return onLongPressNavigationButtons(v, R.id.back, R.id.recent_apps);
865 }
866
Jason Monk49fa0162017-01-11 09:21:56 -0500867 /**
Matthew Ng9c3bce52018-02-01 22:00:31 +0000868 * This handles long-press of both back and recents/home. Back is the common button with
869 * combination of recents if it is visible or home if recents is invisible.
870 * They are handled together to capture them both being long-pressed
Jason Monk49fa0162017-01-11 09:21:56 -0500871 * at the same time to exit screen pinning (lock task).
872 *
Matthew Ng9c3bce52018-02-01 22:00:31 +0000873 * When accessibility mode is on, only a long-press from recents/home
Jason Monk49fa0162017-01-11 09:21:56 -0500874 * is required to exit.
875 *
876 * In all other circumstances we try to pass through long-press events
877 * for Back, so that apps can still use it. Which can be from two things.
878 * 1) Not currently in screen pinning (lock task).
Matthew Ng9c3bce52018-02-01 22:00:31 +0000879 * 2) Back is long-pressed without recents/home.
Jason Monk49fa0162017-01-11 09:21:56 -0500880 */
Matthew Ng9c3bce52018-02-01 22:00:31 +0000881 private boolean onLongPressNavigationButtons(View v, @IdRes int btnId1, @IdRes int btnId2) {
Jason Monk49fa0162017-01-11 09:21:56 -0500882 try {
883 boolean sendBackLongPress = false;
Wale Ogunwale04d9cb52018-04-30 13:55:07 -0700884 IActivityTaskManager activityManager = ActivityTaskManager.getService();
Jason Monk49fa0162017-01-11 09:21:56 -0500885 boolean touchExplorationEnabled = mAccessibilityManager.isTouchExplorationEnabled();
886 boolean inLockTaskMode = activityManager.isInLockTaskMode();
887 if (inLockTaskMode && !touchExplorationEnabled) {
888 long time = System.currentTimeMillis();
Matthew Ng9c3bce52018-02-01 22:00:31 +0000889
Jason Monk49fa0162017-01-11 09:21:56 -0500890 // If we recently long-pressed the other button then they were
891 // long-pressed 'together'
892 if ((time - mLastLockToAppLongPress) < LOCK_TO_APP_GESTURE_TOLERENCE) {
Benjamin Franza83859f2017-07-03 16:34:14 +0100893 activityManager.stopSystemLockTaskMode();
Jason Monk49fa0162017-01-11 09:21:56 -0500894 // When exiting refresh disabled flags.
Matthew Ngd0a73e72018-03-02 15:16:03 -0800895 mNavigationBarView.updateNavButtonIcons();
Jason Monk49fa0162017-01-11 09:21:56 -0500896 return true;
Matthew Ng9c3bce52018-02-01 22:00:31 +0000897 } else if (v.getId() == btnId1) {
898 ButtonDispatcher button = btnId2 == R.id.recent_apps
899 ? mNavigationBarView.getRecentsButton()
900 : mNavigationBarView.getHomeButton();
901 if (!button.getCurrentView().isPressed()) {
902 // If we aren't pressing recents/home right now then they presses
903 // won't be together, so send the standard long-press action.
904 sendBackLongPress = true;
905 }
Jason Monk49fa0162017-01-11 09:21:56 -0500906 }
907 mLastLockToAppLongPress = time;
908 } else {
909 // If this is back still need to handle sending the long-press event.
Matthew Ng9c3bce52018-02-01 22:00:31 +0000910 if (v.getId() == btnId1) {
Jason Monk49fa0162017-01-11 09:21:56 -0500911 sendBackLongPress = true;
912 } else if (touchExplorationEnabled && inLockTaskMode) {
Matthew Ng9c3bce52018-02-01 22:00:31 +0000913 // When in accessibility mode a long press that is recents/home (not back)
Jason Monk49fa0162017-01-11 09:21:56 -0500914 // should stop lock task.
Benjamin Franza83859f2017-07-03 16:34:14 +0100915 activityManager.stopSystemLockTaskMode();
Jason Monk49fa0162017-01-11 09:21:56 -0500916 // When exiting refresh disabled flags.
Matthew Ngd0a73e72018-03-02 15:16:03 -0800917 mNavigationBarView.updateNavButtonIcons();
Jason Monk49fa0162017-01-11 09:21:56 -0500918 return true;
Matthew Ng9c3bce52018-02-01 22:00:31 +0000919 } else if (v.getId() == btnId2) {
920 return btnId2 == R.id.recent_apps
921 ? onLongPressRecents()
922 : onHomeLongClick(mNavigationBarView.getHomeButton().getCurrentView());
Jason Monk49fa0162017-01-11 09:21:56 -0500923 }
924 }
925 if (sendBackLongPress) {
926 KeyButtonView keyButtonView = (KeyButtonView) v;
927 keyButtonView.sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.FLAG_LONG_PRESS);
928 keyButtonView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED);
929 return true;
930 }
931 } catch (RemoteException e) {
932 Log.d(TAG, "Unable to reach activity manager", e);
933 }
934 return false;
935 }
936
937 private boolean onLongPressRecents() {
Wale Ogunwale65ebd952018-04-25 15:41:44 -0700938 if (mRecents == null || !ActivityTaskManager.supportsMultiWindow(getContext())
Matthew Ng43db6d22017-06-27 15:29:39 -0700939 || !mDivider.getView().getSnapAlgorithm().isSplitScreenFeasible()
Winson Chung074c4342018-03-26 17:27:19 -0700940 || Recents.getConfiguration().isLowRamDevice
941 // If we are connected to the overview service, then disable the recents button
942 || mOverviewProxyService.getProxy() != null) {
Jason Monk49fa0162017-01-11 09:21:56 -0500943 return false;
944 }
945
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500946 return mStatusBar.toggleSplitScreenMode(MetricsEvent.ACTION_WINDOW_DOCK_LONGPRESS,
Jason Monk49fa0162017-01-11 09:21:56 -0500947 MetricsEvent.ACTION_WINDOW_UNDOCK_LONGPRESS);
948 }
949
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800950 private void onAccessibilityClick(View v) {
951 mAccessibilityManager.notifyAccessibilityButtonClicked();
952 }
953
954 private boolean onAccessibilityLongClick(View v) {
Casey Burkhardt5e8b9802017-03-24 10:07:20 -0700955 Intent intent = new Intent(AccessibilityManager.ACTION_CHOOSE_ACCESSIBILITY_BUTTON);
956 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
Casey Burkhardt5d614402017-04-06 13:46:50 -0700957 v.getContext().startActivityAsUser(intent, UserHandle.CURRENT);
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800958 return true;
959 }
960
Phil Weaverdb9a7742017-04-18 08:15:06 -0700961 private void updateAccessibilityServicesState(AccessibilityManager accessibilityManager) {
Casey Burkhardt74922c62017-02-13 12:43:16 -0800962 int requestingServices = 0;
963 try {
Casey Burkhardt5d614402017-04-06 13:46:50 -0700964 if (Settings.Secure.getIntForUser(mContentResolver,
965 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED,
966 UserHandle.USER_CURRENT) == 1) {
Casey Burkhardt74922c62017-02-13 12:43:16 -0800967 requestingServices++;
968 }
969 } catch (Settings.SettingNotFoundException e) {
970 }
971
Mike Digman90402952018-01-22 16:05:51 -0800972 boolean feedbackEnabled = false;
Casey Burkhardt5d614402017-04-06 13:46:50 -0700973 // AccessibilityManagerService resolves services for the current user since the local
974 // AccessibilityManager is created from a Context with the INTERACT_ACROSS_USERS permission
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800975 final List<AccessibilityServiceInfo> services =
Phil Weaverdb9a7742017-04-18 08:15:06 -0700976 accessibilityManager.getEnabledAccessibilityServiceList(
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800977 AccessibilityServiceInfo.FEEDBACK_ALL_MASK);
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800978 for (int i = services.size() - 1; i >= 0; --i) {
979 AccessibilityServiceInfo info = services.get(i);
980 if ((info.flags & AccessibilityServiceInfo.FLAG_REQUEST_ACCESSIBILITY_BUTTON) != 0) {
981 requestingServices++;
982 }
Mike Digman90402952018-01-22 16:05:51 -0800983
984 if (info.feedbackType != 0 && info.feedbackType !=
985 AccessibilityServiceInfo.FEEDBACK_GENERIC) {
986 feedbackEnabled = true;
987 }
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800988 }
989
Mike Digman90402952018-01-22 16:05:51 -0800990 mAccessibilityFeedbackEnabled = feedbackEnabled;
991
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800992 final boolean showAccessibilityButton = requestingServices >= 1;
993 final boolean targetSelection = requestingServices >= 2;
994 mNavigationBarView.setAccessibilityButtonState(showAccessibilityButton, targetSelection);
995 }
996
Mike Digman7d092772018-01-11 12:10:32 -0800997 private void onRotateSuggestionClick(View v) {
Mike Digmanc94759d2018-01-23 11:01:21 -0800998 mMetricsLogger.action(MetricsEvent.ACTION_ROTATION_SUGGESTION_ACCEPTED);
Mike Digman50752642018-02-15 13:36:09 -0800999 incrementNumAcceptedRotationSuggestionsIfNeeded();
Mike Digman7d092772018-01-11 12:10:32 -08001000 mRotationLockController.setRotationLockedAtAngle(true, mLastRotationSuggestion);
1001 }
1002
Mike Digman90402952018-01-22 16:05:51 -08001003 private boolean onRotateSuggestionHover(View v, MotionEvent event) {
1004 final int action = event.getActionMasked();
1005 mHoveringRotationSuggestion = (action == MotionEvent.ACTION_HOVER_ENTER)
1006 || (action == MotionEvent.ACTION_HOVER_MOVE);
1007 rescheduleRotationTimeout(true);
1008 return false; // Must return false so a11y hover events are dispatched correctly.
1009 }
1010
Jason Monk2a6ea9c2017-01-26 11:14:51 -05001011 // ----- Methods that StatusBar talks to (should be minimized) -----
Jason Monk49fa0162017-01-11 09:21:56 -05001012
Jason Monk49fa0162017-01-11 09:21:56 -05001013 public void setLightBarController(LightBarController lightBarController) {
1014 mLightBarController = lightBarController;
1015 mLightBarController.setNavigationBar(mNavigationBarView.getLightTransitionsController());
1016 }
1017
1018 public boolean isSemiTransparent() {
1019 return mNavigationBarMode == MODE_SEMI_TRANSPARENT;
1020 }
1021
Jason Monk49fa0162017-01-11 09:21:56 -05001022 public void disableAnimationsDuringHide(long delay) {
1023 mNavigationBarView.setLayoutTransitionsEnabled(false);
1024 mNavigationBarView.postDelayed(() -> mNavigationBarView.setLayoutTransitionsEnabled(true),
1025 delay + StackStateAnimator.ANIMATION_DURATION_GO_TO_FULL_SHADE);
1026 }
1027
Jason Monk49fa0162017-01-11 09:21:56 -05001028 public BarTransitions getBarTransitions() {
1029 return mNavigationBarView.getBarTransitions();
1030 }
1031
1032 public void checkNavBarModes() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -05001033 mStatusBar.checkBarMode(mNavigationBarMode,
Jason Monk49fa0162017-01-11 09:21:56 -05001034 mNavigationBarWindowState, mNavigationBarView.getBarTransitions());
1035 }
1036
1037 public void finishBarAnimations() {
1038 mNavigationBarView.getBarTransitions().finishAnimations();
1039 }
1040
Jason Monk91e587e2017-04-13 13:41:23 -04001041 private final AccessibilityServicesStateChangeListener mAccessibilityListener =
1042 this::updateAccessibilityServicesState;
1043
Casey Burkhardt74922c62017-02-13 12:43:16 -08001044 private class MagnificationContentObserver extends ContentObserver {
1045
1046 public MagnificationContentObserver(Handler handler) {
1047 super(handler);
1048 }
1049
1050 @Override
1051 public void onChange(boolean selfChange) {
Phil Weaverdb9a7742017-04-18 08:15:06 -07001052 NavigationBarFragment.this.updateAccessibilityServicesState(mAccessibilityManager);
Casey Burkhardt74922c62017-02-13 12:43:16 -08001053 }
1054 }
1055
Jason Monk49fa0162017-01-11 09:21:56 -05001056 private final Stub mRotationWatcher = new Stub() {
1057 @Override
Mike Digman90402952018-01-22 16:05:51 -08001058 public void onRotationChanged(final int rotation) throws RemoteException {
Jason Monk49fa0162017-01-11 09:21:56 -05001059 // We need this to be scheduled as early as possible to beat the redrawing of
1060 // window in response to the orientation change.
1061 Handler h = getView().getHandler();
1062 Message msg = Message.obtain(h, () -> {
Mike Digman85ff7fa2018-01-23 14:59:52 -08001063
1064 // If the screen rotation changes while locked, potentially update lock to flow with
Mike Digman90402952018-01-22 16:05:51 -08001065 // new screen rotation and hide any showing suggestions.
1066 if (mRotationLockController.isRotationLocked()) {
Mike Digman85ff7fa2018-01-23 14:59:52 -08001067 if (shouldOverrideUserLockPrefs(rotation)) {
1068 mRotationLockController.setRotationLockedAtAngle(true, rotation);
1069 }
Mike Digman1e28a5a2018-02-14 10:49:19 -08001070 setRotateSuggestionButtonState(false, true);
Mike Digman90402952018-01-22 16:05:51 -08001071 }
1072
Jason Monk49fa0162017-01-11 09:21:56 -05001073 if (mNavigationBarView != null
1074 && mNavigationBarView.needsReorient(rotation)) {
1075 repositionNavigationBar();
1076 }
1077 });
1078 msg.setAsynchronous(true);
1079 h.sendMessageAtFrontOfQueue(msg);
1080 }
Mike Digman85ff7fa2018-01-23 14:59:52 -08001081
1082 private boolean shouldOverrideUserLockPrefs(final int rotation) {
Mike Digmanab650252018-03-06 11:01:41 -08001083 // Only override user prefs when returning to the natural rotation (normally portrait).
Mike Digman85ff7fa2018-01-23 14:59:52 -08001084 // Don't let apps that force landscape or 180 alter user lock.
Mike Digmanab650252018-03-06 11:01:41 -08001085 return rotation == NATURAL_ROTATION;
Mike Digman85ff7fa2018-01-23 14:59:52 -08001086 }
Jason Monk49fa0162017-01-11 09:21:56 -05001087 };
1088
1089 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1090 @Override
1091 public void onReceive(Context context, Intent intent) {
1092 String action = intent.getAction();
Siarhei Vishniakoud002a0a2017-06-05 22:44:37 +01001093 if (Intent.ACTION_SCREEN_OFF.equals(action)
1094 || Intent.ACTION_SCREEN_ON.equals(action)) {
1095 notifyNavigationBarScreenOn();
Jason Monk49fa0162017-01-11 09:21:56 -05001096 }
Phil Weavera858c5f2018-04-26 13:27:30 -07001097 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
1098 // The accessibility settings may be different for the new user
1099 updateAccessibilityServicesState(mAccessibilityManager);
1100 };
Jason Monk49fa0162017-01-11 09:21:56 -05001101 }
1102 };
1103
Mike Digman7d092772018-01-11 12:10:32 -08001104 class TaskStackListenerImpl extends SysUiTaskStackChangeListener {
1105 // Invalidate any rotation suggestion on task change or activity orientation change
1106 // Note: all callbacks happen on main thread
1107
1108 @Override
1109 public void onTaskStackChanged() {
Mike Digman1e28a5a2018-02-14 10:49:19 -08001110 setRotateSuggestionButtonState(false);
Mike Digman7d092772018-01-11 12:10:32 -08001111 }
1112
1113 @Override
1114 public void onTaskRemoved(int taskId) {
Mike Digman1e28a5a2018-02-14 10:49:19 -08001115 setRotateSuggestionButtonState(false);
Mike Digman7d092772018-01-11 12:10:32 -08001116 }
1117
1118 @Override
1119 public void onTaskMovedToFront(int taskId) {
Mike Digman1e28a5a2018-02-14 10:49:19 -08001120 setRotateSuggestionButtonState(false);
Mike Digman7d092772018-01-11 12:10:32 -08001121 }
1122
1123 @Override
1124 public void onActivityRequestedOrientationChanged(int taskId, int requestedOrientation) {
Mike Digman85a9bea2018-02-23 15:08:53 -08001125 // Only hide the icon if the top task changes its requestedOrientation
1126 // Launcher can alter its requestedOrientation while it's not on top, don't hide on this
Mike Digman121b11f2018-04-04 12:45:24 -07001127 Optional.ofNullable(ActivityManagerWrapper.getInstance())
1128 .map(ActivityManagerWrapper::getRunningTask)
1129 .ifPresent(a -> {
1130 if (a.id == taskId) setRotateSuggestionButtonState(false);
1131 });
Mike Digman7d092772018-01-11 12:10:32 -08001132 }
1133 }
1134
Mike Digman50752642018-02-15 13:36:09 -08001135 private class ViewRippler {
1136 private static final int RIPPLE_OFFSET_MS = 50;
1137 private static final int RIPPLE_INTERVAL_MS = 2000;
1138 private View mRoot;
1139
1140 public void start(View root) {
1141 stop(); // Stop any pending ripple animations
1142
1143 mRoot = root;
1144
1145 // Schedule pending ripples, offset the 1st to avoid problems with visibility change
1146 mRoot.postOnAnimationDelayed(mRipple, RIPPLE_OFFSET_MS);
1147 mRoot.postOnAnimationDelayed(mRipple, RIPPLE_INTERVAL_MS);
1148 mRoot.postOnAnimationDelayed(mRipple, 2*RIPPLE_INTERVAL_MS);
Mike Digmanc038c322018-05-24 11:06:05 -07001149 mRoot.postOnAnimationDelayed(mRipple, 3*RIPPLE_INTERVAL_MS);
1150 mRoot.postOnAnimationDelayed(mRipple, 4*RIPPLE_INTERVAL_MS);
Mike Digman50752642018-02-15 13:36:09 -08001151 }
1152
1153 public void stop() {
1154 if (mRoot != null) mRoot.removeCallbacks(mRipple);
1155 }
1156
1157 private final Runnable mRipple = new Runnable() {
1158 @Override
1159 public void run() { // Cause the ripple to fire via false presses
Mike Digmanf4c98992018-04-25 11:25:59 -07001160 if (!mRoot.isAttachedToWindow()) return;
Mike Digman50752642018-02-15 13:36:09 -08001161 mRoot.setPressed(true);
1162 mRoot.setPressed(false);
1163 }
1164 };
1165 }
1166
Jason Monk49fa0162017-01-11 09:21:56 -05001167 public static View create(Context context, FragmentListener listener) {
1168 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1169 LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
1170 WindowManager.LayoutParams.TYPE_NAVIGATION_BAR,
1171 WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
1172 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1173 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
1174 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
1175 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
1176 | WindowManager.LayoutParams.FLAG_SLIPPERY,
1177 PixelFormat.TRANSLUCENT);
1178 lp.token = new Binder();
Jason Monk49fa0162017-01-11 09:21:56 -05001179 lp.setTitle("NavigationBar");
Phil Weaver8583ae82018-02-13 11:01:24 -08001180 lp.accessibilityTitle = context.getString(R.string.nav_bar);
Jason Monk49fa0162017-01-11 09:21:56 -05001181 lp.windowAnimations = 0;
1182
1183 View navigationBarView = LayoutInflater.from(context).inflate(
1184 R.layout.navigation_bar_window, null);
1185
1186 if (DEBUG) Log.v(TAG, "addNavigationBar: about to add " + navigationBarView);
1187 if (navigationBarView == null) return null;
1188
1189 context.getSystemService(WindowManager.class).addView(navigationBarView, lp);
1190 FragmentHostManager fragmentHost = FragmentHostManager.get(navigationBarView);
1191 NavigationBarFragment fragment = new NavigationBarFragment();
1192 fragmentHost.getFragmentManager().beginTransaction()
1193 .replace(R.id.navigation_bar_frame, fragment, TAG)
1194 .commit();
1195 fragmentHost.addTagListener(TAG, listener);
1196 return navigationBarView;
1197 }
1198}