blob: f3e100d18eba3c725abc9c3c2b6d1369fdae60cb [file] [log] [blame]
Jason Monk49fa0162017-01-11 09:21:56 -05001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the
10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11 * KIND, either express or implied. See the License for the specific language governing
12 * permissions and limitations under the License.
13 */
14
15package com.android.systemui.statusbar.phone;
16
17import static android.app.StatusBarManager.NAVIGATION_HINT_BACK_ALT;
18import static android.app.StatusBarManager.NAVIGATION_HINT_IME_SHOWN;
19import static android.app.StatusBarManager.WINDOW_STATE_SHOWING;
20import static android.app.StatusBarManager.windowStateToString;
21
Mike Digmanab650252018-03-06 11:01:41 -080022import static com.android.internal.view.RotationPolicy.NATURAL_ROTATION;
23
Matthew Ng8f25fb962018-01-16 17:17:24 -080024import static com.android.systemui.shared.system.NavigationBarCompat.InteractionType;
Tracy Zhou1ac592c2018-07-25 13:47:37 -070025import static com.android.systemui.statusbar.phone.BarTransitions.MODE_LIGHTS_OUT_TRANSPARENT;
Jason Monk49fa0162017-01-11 09:21:56 -050026import static com.android.systemui.statusbar.phone.BarTransitions.MODE_SEMI_TRANSPARENT;
Tracy Zhou1ac592c2018-07-25 13:47:37 -070027import static com.android.systemui.statusbar.phone.BarTransitions.MODE_TRANSPARENT;
Jason Monk2a6ea9c2017-01-26 11:14:51 -050028import static com.android.systemui.statusbar.phone.StatusBar.DEBUG_WINDOW_STATE;
29import static com.android.systemui.statusbar.phone.StatusBar.dumpBarTransitions;
Matthew Ng9c3bce52018-02-01 22:00:31 +000030import static com.android.systemui.OverviewProxyService.OverviewProxyListener;
Jason Monk49fa0162017-01-11 09:21:56 -050031
Casey Burkhardt048c2bc2016-12-08 16:09:20 -080032import android.accessibilityservice.AccessibilityServiceInfo;
Mike Digman7d092772018-01-11 12:10:32 -080033import android.animation.Animator;
34import android.animation.AnimatorListenerAdapter;
Mike Digman7d092772018-01-11 12:10:32 -080035import android.animation.ObjectAnimator;
Matthew Ng9c3bce52018-02-01 22:00:31 +000036import android.annotation.IdRes;
Jason Monk49fa0162017-01-11 09:21:56 -050037import android.annotation.Nullable;
Wale Ogunwale65ebd952018-04-25 15:41:44 -070038import android.app.ActivityTaskManager;
Jason Monk49fa0162017-01-11 09:21:56 -050039import android.app.Fragment;
40import android.app.IActivityManager;
Wale Ogunwale04d9cb52018-04-30 13:55:07 -070041import android.app.IActivityTaskManager;
Jason Monk49fa0162017-01-11 09:21:56 -050042import android.app.StatusBarManager;
43import android.content.BroadcastReceiver;
Casey Burkhardtb9dcd662017-03-20 15:10:16 -070044import android.content.ContentResolver;
Jason Monk49fa0162017-01-11 09:21:56 -050045import android.content.Context;
46import android.content.Intent;
47import android.content.IntentFilter;
48import android.content.res.Configuration;
Casey Burkhardt74922c62017-02-13 12:43:16 -080049import android.database.ContentObserver;
Jason Monk49fa0162017-01-11 09:21:56 -050050import android.graphics.PixelFormat;
51import android.graphics.Rect;
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;
Rohan Shah20790b82018-07-02 17:21:04 -0700101import com.android.systemui.statusbar.notification.stack.StackStateAnimator;
Jason Monk49fa0162017-01-11 09:21:56 -0500102
103import java.io.FileDescriptor;
104import java.io.PrintWriter;
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800105import java.util.List;
Jason Monk49fa0162017-01-11 09:21:56 -0500106import java.util.Locale;
Mike Digman121b11f2018-04-04 12:45:24 -0700107import java.util.Optional;
Jason Monk49fa0162017-01-11 09:21:56 -0500108
109/**
110 * Fragment containing the NavigationBarFragment. Contains logic for what happens
111 * on clicks and view states of the nav bar.
112 */
113public class NavigationBarFragment extends Fragment implements Callbacks {
114
Jason Monkd4afe152017-05-01 15:37:43 -0400115 public static final String TAG = "NavigationBar";
Jason Monk49fa0162017-01-11 09:21:56 -0500116 private static final boolean DEBUG = false;
Mike Digman3e33da62018-03-14 16:25:11 -0700117 private static final boolean DEBUG_ROTATION = true;
Jason Monk49fa0162017-01-11 09:21:56 -0500118 private static final String EXTRA_DISABLE_STATE = "disabled_state";
Mike Digmandd2f49e2018-03-16 10:54:22 -0700119 private static final String EXTRA_DISABLE2_STATE = "disabled2_state";
Jason Monk49fa0162017-01-11 09:21:56 -0500120
Mike Digman1e28a5a2018-02-14 10:49:19 -0800121 private final static int BUTTON_FADE_IN_OUT_DURATION_MS = 100;
Mike Digman5aeca792018-03-05 11:14:39 -0800122 private final static int NAVBAR_HIDDEN_PENDING_ICON_TIMEOUT_MS = 20000;
Mike Digman1e28a5a2018-02-14 10:49:19 -0800123
Mike Digman50752642018-02-15 13:36:09 -0800124 private static final int NUM_ACCEPTED_ROTATION_SUGGESTIONS_FOR_INTRODUCTION = 3;
125
Jason Monk49fa0162017-01-11 09:21:56 -0500126 /** Allow some time inbetween the long press for back and recents. */
127 private static final int LOCK_TO_APP_GESTURE_TOLERENCE = 200;
128
129 protected NavigationBarView mNavigationBarView = null;
130 protected AssistManager mAssistManager;
131
132 private int mNavigationBarWindowState = WINDOW_STATE_SHOWING;
133
134 private int mNavigationIconHints = 0;
135 private int mNavigationBarMode;
Mike Digman90402952018-01-22 16:05:51 -0800136 private boolean mAccessibilityFeedbackEnabled;
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800137 private AccessibilityManager mAccessibilityManager;
Casey Burkhardt74922c62017-02-13 12:43:16 -0800138 private MagnificationContentObserver mMagnificationObserver;
Casey Burkhardtb9dcd662017-03-20 15:10:16 -0700139 private ContentResolver mContentResolver;
Mike Digmanc94759d2018-01-23 11:01:21 -0800140 private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class);
Jason Monk49fa0162017-01-11 09:21:56 -0500141
142 private int mDisabledFlags1;
Mike Digmandd2f49e2018-03-16 10:54:22 -0700143 private int mDisabledFlags2;
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500144 private StatusBar mStatusBar;
Jason Monk49fa0162017-01-11 09:21:56 -0500145 private Recents mRecents;
146 private Divider mDivider;
147 private WindowManager mWindowManager;
148 private CommandQueue mCommandQueue;
149 private long mLastLockToAppLongPress;
150
151 private Locale mLocale;
152 private int mLayoutDirection;
153
154 private int mSystemUiVisibility;
155 private LightBarController mLightBarController;
Jason Monk49fa0162017-01-11 09:21:56 -0500156
Matthew Ngdc79e5c2017-12-14 17:37:35 -0800157 private OverviewProxyService mOverviewProxyService;
158
Jason Monk49fa0162017-01-11 09:21:56 -0500159 public boolean mHomeBlockedThisTouch;
160
Mike Digman7d092772018-01-11 12:10:32 -0800161 private int mLastRotationSuggestion;
Mike Digman5aeca792018-03-05 11:14:39 -0800162 private boolean mPendingRotationSuggestion;
Mike Digman90402952018-01-22 16:05:51 -0800163 private boolean mHoveringRotationSuggestion;
Mike Digman7d092772018-01-11 12:10:32 -0800164 private RotationLockController mRotationLockController;
165 private TaskStackListenerImpl mTaskStackListener;
166
Mike Digman1e28a5a2018-02-14 10:49:19 -0800167 private final Runnable mRemoveRotationProposal = () -> setRotateSuggestionButtonState(false);
Mike Digman5aeca792018-03-05 11:14:39 -0800168 private final Runnable mCancelPendingRotationProposal =
169 () -> mPendingRotationSuggestion = false;
Mike Digman7d092772018-01-11 12:10:32 -0800170 private Animator mRotateHideAnimator;
Mike Digman50752642018-02-15 13:36:09 -0800171 private ViewRippler mViewRippler = new ViewRippler();
Mike Digman7d092772018-01-11 12:10:32 -0800172
Matthew Ng9c3bce52018-02-01 22:00:31 +0000173 private final OverviewProxyListener mOverviewProxyListener = new OverviewProxyListener() {
174 @Override
175 public void onConnectionChanged(boolean isConnected) {
Winson Chungf9e30272018-03-26 17:25:36 -0700176 mNavigationBarView.updateStates();
Matthew Ng9c3bce52018-02-01 22:00:31 +0000177 updateScreenPinningGestures();
178 }
179
180 @Override
Matthew Ng2ea93b72018-03-14 19:43:18 +0000181 public void onQuickStepStarted() {
Mike Digman85a9bea2018-02-23 15:08:53 -0800182 // Use navbar dragging as a signal to hide the rotate button
183 setRotateSuggestionButtonState(false);
Matthew 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) {
Tracy Zhou1ac592c2018-07-25 13:47:37 -0700665 if (mNavigationBarMode == MODE_TRANSPARENT
666 || mNavigationBarMode == MODE_LIGHTS_OUT_TRANSPARENT) {
667 mNavigationBarView.hideRecentsOnboarding();
668 }
Jason Monk49fa0162017-01-11 09:21:56 -0500669 mNavigationBarMode = nbMode;
670 checkNavBarModes();
671 }
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500672 mStatusBar.touchAutoHide();
Jason Monk49fa0162017-01-11 09:21:56 -0500673 }
674 }
675
676 mLightBarController.onNavigationVisibilityChanged(vis, mask, nbModeChanged,
677 mNavigationBarMode);
678 }
679
680 @Override
681 public void disable(int state1, int state2, boolean animate) {
Mike Digmandd2f49e2018-03-16 10:54:22 -0700682 // Navigation bar flags are in both state1 and state2.
683 final int masked = state1 & (StatusBarManager.DISABLE_HOME
Jason Monk49fa0162017-01-11 09:21:56 -0500684 | StatusBarManager.DISABLE_RECENT
685 | StatusBarManager.DISABLE_BACK
686 | StatusBarManager.DISABLE_SEARCH);
687 if (masked != mDisabledFlags1) {
688 mDisabledFlags1 = masked;
689 if (mNavigationBarView != null) mNavigationBarView.setDisabledFlags(state1);
Matthew Ng9c3bce52018-02-01 22:00:31 +0000690 updateScreenPinningGestures();
Jason Monk49fa0162017-01-11 09:21:56 -0500691 }
Mike Digmandd2f49e2018-03-16 10:54:22 -0700692
693 final int masked2 = state2 & (StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS);
694 if (masked2 != mDisabledFlags2) {
695 mDisabledFlags2 = masked2;
696 setDisabled2Flags(masked2);
697 }
698 }
699
700 private void setDisabled2Flags(int state2) {
701 // Method only called on change of disable2 flags
702 final boolean rotateSuggestionsDisabled = hasDisable2RotateSuggestionFlag(state2);
703 if (rotateSuggestionsDisabled) onRotationSuggestionsDisabled();
704 }
705
706 private boolean hasDisable2RotateSuggestionFlag(int disable2Flags) {
707 return (disable2Flags & StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS) != 0;
Jason Monk49fa0162017-01-11 09:21:56 -0500708 }
709
710 // ----- Internal stuffz -----
711
712 private void refreshLayout(int layoutDirection) {
713 if (mNavigationBarView != null) {
714 mNavigationBarView.setLayoutDirection(layoutDirection);
715 }
716 }
717
718 private boolean shouldDisableNavbarGestures() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500719 return !mStatusBar.isDeviceProvisioned()
Matthew Ngfee0b5b2018-02-21 15:38:21 -0800720 || (mDisabledFlags1 & StatusBarManager.DISABLE_SEARCH) != 0;
Jason Monk49fa0162017-01-11 09:21:56 -0500721 }
722
723 private void repositionNavigationBar() {
724 if (mNavigationBarView == null || !mNavigationBarView.isAttachedToWindow()) return;
725
726 prepareNavigationBarView();
727
728 mWindowManager.updateViewLayout((View) mNavigationBarView.getParent(),
729 ((View) mNavigationBarView.getParent()).getLayoutParams());
730 }
731
Matthew Ng9c3bce52018-02-01 22:00:31 +0000732 private void updateScreenPinningGestures() {
733 if (mNavigationBarView == null) {
734 return;
735 }
736
737 // Change the cancel pin gesture to home and back if recents button is invisible
738 boolean recentsVisible = mNavigationBarView.isRecentsButtonVisible();
Matthew Ng9c3bce52018-02-01 22:00:31 +0000739 ButtonDispatcher backButton = mNavigationBarView.getBackButton();
740 if (recentsVisible) {
Matthew Ng9c3bce52018-02-01 22:00:31 +0000741 backButton.setOnLongClickListener(this::onLongPressBackRecents);
742 } else {
Matthew Ng9c3bce52018-02-01 22:00:31 +0000743 backButton.setOnLongClickListener(this::onLongPressBackHome);
744 }
745 }
746
Siarhei Vishniakoud002a0a2017-06-05 22:44:37 +0100747 private void notifyNavigationBarScreenOn() {
Matthew Ngd0a73e72018-03-02 15:16:03 -0800748 mNavigationBarView.updateNavButtonIcons();
Jason Monk49fa0162017-01-11 09:21:56 -0500749 }
750
751 private void prepareNavigationBarView() {
752 mNavigationBarView.reorient();
753
754 ButtonDispatcher recentsButton = mNavigationBarView.getRecentsButton();
755 recentsButton.setOnClickListener(this::onRecentsClick);
756 recentsButton.setOnTouchListener(this::onRecentsTouch);
757 recentsButton.setLongClickable(true);
758 recentsButton.setOnLongClickListener(this::onLongPressBackRecents);
759
760 ButtonDispatcher backButton = mNavigationBarView.getBackButton();
761 backButton.setLongClickable(true);
Jason Monk49fa0162017-01-11 09:21:56 -0500762
763 ButtonDispatcher homeButton = mNavigationBarView.getHomeButton();
764 homeButton.setOnTouchListener(this::onHomeTouch);
Matthew Ngfee0b5b2018-02-21 15:38:21 -0800765 homeButton.setOnLongClickListener(this::onHomeLongClick);
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800766
767 ButtonDispatcher accessibilityButton = mNavigationBarView.getAccessibilityButton();
768 accessibilityButton.setOnClickListener(this::onAccessibilityClick);
769 accessibilityButton.setOnLongClickListener(this::onAccessibilityLongClick);
Phil Weaverdb9a7742017-04-18 08:15:06 -0700770 updateAccessibilityServicesState(mAccessibilityManager);
Mike Digman7d092772018-01-11 12:10:32 -0800771
772 ButtonDispatcher rotateSuggestionButton = mNavigationBarView.getRotateSuggestionButton();
773 rotateSuggestionButton.setOnClickListener(this::onRotateSuggestionClick);
Mike Digman90402952018-01-22 16:05:51 -0800774 rotateSuggestionButton.setOnHoverListener(this::onRotateSuggestionHover);
Matthew Ng9c3bce52018-02-01 22:00:31 +0000775 updateScreenPinningGestures();
Jason Monk49fa0162017-01-11 09:21:56 -0500776 }
777
778 private boolean onHomeTouch(View v, MotionEvent event) {
779 if (mHomeBlockedThisTouch && event.getActionMasked() != MotionEvent.ACTION_DOWN) {
780 return true;
781 }
782 // If an incoming call is ringing, HOME is totally disabled.
783 // (The user is already on the InCallUI at this point,
784 // and his ONLY options are to answer or reject the call.)
785 switch (event.getAction()) {
786 case MotionEvent.ACTION_DOWN:
787 mHomeBlockedThisTouch = false;
788 TelecomManager telecomManager =
789 getContext().getSystemService(TelecomManager.class);
790 if (telecomManager != null && telecomManager.isRinging()) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500791 if (mStatusBar.isKeyguardShowing()) {
Jason Monk49fa0162017-01-11 09:21:56 -0500792 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call. " +
793 "No heads up");
794 mHomeBlockedThisTouch = true;
795 return true;
796 }
797 }
798 break;
799 case MotionEvent.ACTION_UP:
800 case MotionEvent.ACTION_CANCEL:
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500801 mStatusBar.awakenDreams();
Jason Monk49fa0162017-01-11 09:21:56 -0500802 break;
803 }
804 return false;
805 }
806
807 private void onVerticalChanged(boolean isVertical) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500808 mStatusBar.setQsScrimEnabled(!isVertical);
Jason Monk49fa0162017-01-11 09:21:56 -0500809 }
810
811 private boolean onNavigationTouch(View v, MotionEvent event) {
Eliot Courtneycb5d3162017-08-09 16:53:15 +0900812 mStatusBar.checkUserAutohide(event);
Jason Monk49fa0162017-01-11 09:21:56 -0500813 return false;
814 }
815
Jason Monk865246d2017-01-19 08:27:01 -0500816 @VisibleForTesting
817 boolean onHomeLongClick(View v) {
Matthew Ng6ff33b72018-02-27 13:47:38 -0800818 if (!mNavigationBarView.isRecentsButtonVisible()
819 && ActivityManagerWrapper.getInstance().isScreenPinningActive()) {
Matthew Ngfee0b5b2018-02-21 15:38:21 -0800820 return onLongPressBackHome(v);
821 }
Jason Monk49fa0162017-01-11 09:21:56 -0500822 if (shouldDisableNavbarGestures()) {
823 return false;
824 }
Matthew Ng2ea93b72018-03-14 19:43:18 +0000825 mNavigationBarView.onNavigationButtonLongPress(v);
Mike Digmanc94759d2018-01-23 11:01:21 -0800826 mMetricsLogger.action(MetricsEvent.ACTION_ASSIST_LONG_PRESS);
Jason Monk49fa0162017-01-11 09:21:56 -0500827 mAssistManager.startAssist(new Bundle() /* args */);
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500828 mStatusBar.awakenDreams();
Matthew Ngdc79e5c2017-12-14 17:37:35 -0800829
Jason Monk49fa0162017-01-11 09:21:56 -0500830 if (mNavigationBarView != null) {
831 mNavigationBarView.abortCurrentGesture();
832 }
833 return true;
834 }
835
836 // additional optimization when we have software system buttons - start loading the recent
837 // tasks on touch down
838 private boolean onRecentsTouch(View v, MotionEvent event) {
839 int action = event.getAction() & MotionEvent.ACTION_MASK;
840 if (action == MotionEvent.ACTION_DOWN) {
841 mCommandQueue.preloadRecentApps();
842 } else if (action == MotionEvent.ACTION_CANCEL) {
843 mCommandQueue.cancelPreloadRecentApps();
844 } else if (action == MotionEvent.ACTION_UP) {
845 if (!v.isPressed()) {
846 mCommandQueue.cancelPreloadRecentApps();
847 }
848 }
849 return false;
850 }
851
852 private void onRecentsClick(View v) {
853 if (LatencyTracker.isEnabled(getContext())) {
854 LatencyTracker.getInstance(getContext()).onActionStart(
855 LatencyTracker.ACTION_TOGGLE_RECENTS);
856 }
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500857 mStatusBar.awakenDreams();
Jason Monk49fa0162017-01-11 09:21:56 -0500858 mCommandQueue.toggleRecentApps();
859 }
860
Matthew Ng9c3bce52018-02-01 22:00:31 +0000861 private boolean onLongPressBackHome(View v) {
Matthew Ng2ea93b72018-03-14 19:43:18 +0000862 mNavigationBarView.onNavigationButtonLongPress(v);
Matthew Ng9c3bce52018-02-01 22:00:31 +0000863 return onLongPressNavigationButtons(v, R.id.back, R.id.home);
864 }
865
866 private boolean onLongPressBackRecents(View v) {
Matthew Ng2ea93b72018-03-14 19:43:18 +0000867 mNavigationBarView.onNavigationButtonLongPress(v);
Matthew Ng9c3bce52018-02-01 22:00:31 +0000868 return onLongPressNavigationButtons(v, R.id.back, R.id.recent_apps);
869 }
870
Jason Monk49fa0162017-01-11 09:21:56 -0500871 /**
Matthew Ng9c3bce52018-02-01 22:00:31 +0000872 * This handles long-press of both back and recents/home. Back is the common button with
873 * combination of recents if it is visible or home if recents is invisible.
874 * They are handled together to capture them both being long-pressed
Jason Monk49fa0162017-01-11 09:21:56 -0500875 * at the same time to exit screen pinning (lock task).
876 *
Matthew Ng9c3bce52018-02-01 22:00:31 +0000877 * When accessibility mode is on, only a long-press from recents/home
Jason Monk49fa0162017-01-11 09:21:56 -0500878 * is required to exit.
879 *
880 * In all other circumstances we try to pass through long-press events
881 * for Back, so that apps can still use it. Which can be from two things.
882 * 1) Not currently in screen pinning (lock task).
Matthew Ng9c3bce52018-02-01 22:00:31 +0000883 * 2) Back is long-pressed without recents/home.
Jason Monk49fa0162017-01-11 09:21:56 -0500884 */
Matthew Ng9c3bce52018-02-01 22:00:31 +0000885 private boolean onLongPressNavigationButtons(View v, @IdRes int btnId1, @IdRes int btnId2) {
Jason Monk49fa0162017-01-11 09:21:56 -0500886 try {
887 boolean sendBackLongPress = false;
Wale Ogunwale04d9cb52018-04-30 13:55:07 -0700888 IActivityTaskManager activityManager = ActivityTaskManager.getService();
Jason Monk49fa0162017-01-11 09:21:56 -0500889 boolean touchExplorationEnabled = mAccessibilityManager.isTouchExplorationEnabled();
890 boolean inLockTaskMode = activityManager.isInLockTaskMode();
891 if (inLockTaskMode && !touchExplorationEnabled) {
892 long time = System.currentTimeMillis();
Matthew Ng9c3bce52018-02-01 22:00:31 +0000893
Jason Monk49fa0162017-01-11 09:21:56 -0500894 // If we recently long-pressed the other button then they were
895 // long-pressed 'together'
896 if ((time - mLastLockToAppLongPress) < LOCK_TO_APP_GESTURE_TOLERENCE) {
Benjamin Franza83859f2017-07-03 16:34:14 +0100897 activityManager.stopSystemLockTaskMode();
Jason Monk49fa0162017-01-11 09:21:56 -0500898 // When exiting refresh disabled flags.
Matthew Ngd0a73e72018-03-02 15:16:03 -0800899 mNavigationBarView.updateNavButtonIcons();
Jason Monk49fa0162017-01-11 09:21:56 -0500900 return true;
Matthew Ng9c3bce52018-02-01 22:00:31 +0000901 } else if (v.getId() == btnId1) {
902 ButtonDispatcher button = btnId2 == R.id.recent_apps
903 ? mNavigationBarView.getRecentsButton()
904 : mNavigationBarView.getHomeButton();
905 if (!button.getCurrentView().isPressed()) {
906 // If we aren't pressing recents/home right now then they presses
907 // won't be together, so send the standard long-press action.
908 sendBackLongPress = true;
909 }
Jason Monk49fa0162017-01-11 09:21:56 -0500910 }
911 mLastLockToAppLongPress = time;
912 } else {
913 // If this is back still need to handle sending the long-press event.
Matthew Ng9c3bce52018-02-01 22:00:31 +0000914 if (v.getId() == btnId1) {
Jason Monk49fa0162017-01-11 09:21:56 -0500915 sendBackLongPress = true;
916 } else if (touchExplorationEnabled && inLockTaskMode) {
Matthew Ng9c3bce52018-02-01 22:00:31 +0000917 // When in accessibility mode a long press that is recents/home (not back)
Jason Monk49fa0162017-01-11 09:21:56 -0500918 // should stop lock task.
Benjamin Franza83859f2017-07-03 16:34:14 +0100919 activityManager.stopSystemLockTaskMode();
Jason Monk49fa0162017-01-11 09:21:56 -0500920 // When exiting refresh disabled flags.
Matthew Ngd0a73e72018-03-02 15:16:03 -0800921 mNavigationBarView.updateNavButtonIcons();
Jason Monk49fa0162017-01-11 09:21:56 -0500922 return true;
Matthew Ng9c3bce52018-02-01 22:00:31 +0000923 } else if (v.getId() == btnId2) {
924 return btnId2 == R.id.recent_apps
925 ? onLongPressRecents()
926 : onHomeLongClick(mNavigationBarView.getHomeButton().getCurrentView());
Jason Monk49fa0162017-01-11 09:21:56 -0500927 }
928 }
929 if (sendBackLongPress) {
930 KeyButtonView keyButtonView = (KeyButtonView) v;
931 keyButtonView.sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.FLAG_LONG_PRESS);
932 keyButtonView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED);
933 return true;
934 }
935 } catch (RemoteException e) {
936 Log.d(TAG, "Unable to reach activity manager", e);
937 }
938 return false;
939 }
940
941 private boolean onLongPressRecents() {
Wale Ogunwale65ebd952018-04-25 15:41:44 -0700942 if (mRecents == null || !ActivityTaskManager.supportsMultiWindow(getContext())
Matthew Ng43db6d22017-06-27 15:29:39 -0700943 || !mDivider.getView().getSnapAlgorithm().isSplitScreenFeasible()
Winson Chung074c4342018-03-26 17:27:19 -0700944 || Recents.getConfiguration().isLowRamDevice
945 // If we are connected to the overview service, then disable the recents button
946 || mOverviewProxyService.getProxy() != null) {
Jason Monk49fa0162017-01-11 09:21:56 -0500947 return false;
948 }
949
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500950 return mStatusBar.toggleSplitScreenMode(MetricsEvent.ACTION_WINDOW_DOCK_LONGPRESS,
Jason Monk49fa0162017-01-11 09:21:56 -0500951 MetricsEvent.ACTION_WINDOW_UNDOCK_LONGPRESS);
952 }
953
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800954 private void onAccessibilityClick(View v) {
955 mAccessibilityManager.notifyAccessibilityButtonClicked();
956 }
957
958 private boolean onAccessibilityLongClick(View v) {
Casey Burkhardt5e8b9802017-03-24 10:07:20 -0700959 Intent intent = new Intent(AccessibilityManager.ACTION_CHOOSE_ACCESSIBILITY_BUTTON);
960 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
Casey Burkhardt5d614402017-04-06 13:46:50 -0700961 v.getContext().startActivityAsUser(intent, UserHandle.CURRENT);
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800962 return true;
963 }
964
Phil Weaverdb9a7742017-04-18 08:15:06 -0700965 private void updateAccessibilityServicesState(AccessibilityManager accessibilityManager) {
Casey Burkhardt74922c62017-02-13 12:43:16 -0800966 int requestingServices = 0;
967 try {
Casey Burkhardt5d614402017-04-06 13:46:50 -0700968 if (Settings.Secure.getIntForUser(mContentResolver,
969 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED,
970 UserHandle.USER_CURRENT) == 1) {
Casey Burkhardt74922c62017-02-13 12:43:16 -0800971 requestingServices++;
972 }
973 } catch (Settings.SettingNotFoundException e) {
974 }
975
Mike Digman90402952018-01-22 16:05:51 -0800976 boolean feedbackEnabled = false;
Casey Burkhardt5d614402017-04-06 13:46:50 -0700977 // AccessibilityManagerService resolves services for the current user since the local
978 // AccessibilityManager is created from a Context with the INTERACT_ACROSS_USERS permission
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800979 final List<AccessibilityServiceInfo> services =
Phil Weaverdb9a7742017-04-18 08:15:06 -0700980 accessibilityManager.getEnabledAccessibilityServiceList(
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800981 AccessibilityServiceInfo.FEEDBACK_ALL_MASK);
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800982 for (int i = services.size() - 1; i >= 0; --i) {
983 AccessibilityServiceInfo info = services.get(i);
984 if ((info.flags & AccessibilityServiceInfo.FLAG_REQUEST_ACCESSIBILITY_BUTTON) != 0) {
985 requestingServices++;
986 }
Mike Digman90402952018-01-22 16:05:51 -0800987
988 if (info.feedbackType != 0 && info.feedbackType !=
989 AccessibilityServiceInfo.FEEDBACK_GENERIC) {
990 feedbackEnabled = true;
991 }
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800992 }
993
Mike Digman90402952018-01-22 16:05:51 -0800994 mAccessibilityFeedbackEnabled = feedbackEnabled;
995
Casey Burkhardt048c2bc2016-12-08 16:09:20 -0800996 final boolean showAccessibilityButton = requestingServices >= 1;
997 final boolean targetSelection = requestingServices >= 2;
998 mNavigationBarView.setAccessibilityButtonState(showAccessibilityButton, targetSelection);
999 }
1000
Mike Digman7d092772018-01-11 12:10:32 -08001001 private void onRotateSuggestionClick(View v) {
Mike Digmanc94759d2018-01-23 11:01:21 -08001002 mMetricsLogger.action(MetricsEvent.ACTION_ROTATION_SUGGESTION_ACCEPTED);
Mike Digman50752642018-02-15 13:36:09 -08001003 incrementNumAcceptedRotationSuggestionsIfNeeded();
Mike Digman7d092772018-01-11 12:10:32 -08001004 mRotationLockController.setRotationLockedAtAngle(true, mLastRotationSuggestion);
1005 }
1006
Mike Digman90402952018-01-22 16:05:51 -08001007 private boolean onRotateSuggestionHover(View v, MotionEvent event) {
1008 final int action = event.getActionMasked();
1009 mHoveringRotationSuggestion = (action == MotionEvent.ACTION_HOVER_ENTER)
1010 || (action == MotionEvent.ACTION_HOVER_MOVE);
1011 rescheduleRotationTimeout(true);
1012 return false; // Must return false so a11y hover events are dispatched correctly.
1013 }
1014
Jason Monk2a6ea9c2017-01-26 11:14:51 -05001015 // ----- Methods that StatusBar talks to (should be minimized) -----
Jason Monk49fa0162017-01-11 09:21:56 -05001016
Jason Monk49fa0162017-01-11 09:21:56 -05001017 public void setLightBarController(LightBarController lightBarController) {
1018 mLightBarController = lightBarController;
1019 mLightBarController.setNavigationBar(mNavigationBarView.getLightTransitionsController());
1020 }
1021
1022 public boolean isSemiTransparent() {
1023 return mNavigationBarMode == MODE_SEMI_TRANSPARENT;
1024 }
1025
Jason Monk49fa0162017-01-11 09:21:56 -05001026 public void disableAnimationsDuringHide(long delay) {
1027 mNavigationBarView.setLayoutTransitionsEnabled(false);
1028 mNavigationBarView.postDelayed(() -> mNavigationBarView.setLayoutTransitionsEnabled(true),
1029 delay + StackStateAnimator.ANIMATION_DURATION_GO_TO_FULL_SHADE);
1030 }
1031
Jason Monk49fa0162017-01-11 09:21:56 -05001032 public BarTransitions getBarTransitions() {
1033 return mNavigationBarView.getBarTransitions();
1034 }
1035
1036 public void checkNavBarModes() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -05001037 mStatusBar.checkBarMode(mNavigationBarMode,
Jason Monk49fa0162017-01-11 09:21:56 -05001038 mNavigationBarWindowState, mNavigationBarView.getBarTransitions());
1039 }
1040
1041 public void finishBarAnimations() {
1042 mNavigationBarView.getBarTransitions().finishAnimations();
1043 }
1044
Jason Monk91e587e2017-04-13 13:41:23 -04001045 private final AccessibilityServicesStateChangeListener mAccessibilityListener =
1046 this::updateAccessibilityServicesState;
1047
Casey Burkhardt74922c62017-02-13 12:43:16 -08001048 private class MagnificationContentObserver extends ContentObserver {
1049
1050 public MagnificationContentObserver(Handler handler) {
1051 super(handler);
1052 }
1053
1054 @Override
1055 public void onChange(boolean selfChange) {
Phil Weaverdb9a7742017-04-18 08:15:06 -07001056 NavigationBarFragment.this.updateAccessibilityServicesState(mAccessibilityManager);
Casey Burkhardt74922c62017-02-13 12:43:16 -08001057 }
1058 }
1059
Jason Monk49fa0162017-01-11 09:21:56 -05001060 private final Stub mRotationWatcher = new Stub() {
1061 @Override
Mike Digman90402952018-01-22 16:05:51 -08001062 public void onRotationChanged(final int rotation) throws RemoteException {
Jason Monk49fa0162017-01-11 09:21:56 -05001063 // We need this to be scheduled as early as possible to beat the redrawing of
1064 // window in response to the orientation change.
1065 Handler h = getView().getHandler();
1066 Message msg = Message.obtain(h, () -> {
Mike Digman85ff7fa2018-01-23 14:59:52 -08001067
1068 // If the screen rotation changes while locked, potentially update lock to flow with
Mike Digman90402952018-01-22 16:05:51 -08001069 // new screen rotation and hide any showing suggestions.
1070 if (mRotationLockController.isRotationLocked()) {
Mike Digman85ff7fa2018-01-23 14:59:52 -08001071 if (shouldOverrideUserLockPrefs(rotation)) {
1072 mRotationLockController.setRotationLockedAtAngle(true, rotation);
1073 }
Mike Digman1e28a5a2018-02-14 10:49:19 -08001074 setRotateSuggestionButtonState(false, true);
Mike Digman90402952018-01-22 16:05:51 -08001075 }
1076
Jason Monk49fa0162017-01-11 09:21:56 -05001077 if (mNavigationBarView != null
1078 && mNavigationBarView.needsReorient(rotation)) {
1079 repositionNavigationBar();
1080 }
1081 });
1082 msg.setAsynchronous(true);
1083 h.sendMessageAtFrontOfQueue(msg);
1084 }
Mike Digman85ff7fa2018-01-23 14:59:52 -08001085
1086 private boolean shouldOverrideUserLockPrefs(final int rotation) {
Mike Digmanab650252018-03-06 11:01:41 -08001087 // Only override user prefs when returning to the natural rotation (normally portrait).
Mike Digman85ff7fa2018-01-23 14:59:52 -08001088 // Don't let apps that force landscape or 180 alter user lock.
Mike Digmanab650252018-03-06 11:01:41 -08001089 return rotation == NATURAL_ROTATION;
Mike Digman85ff7fa2018-01-23 14:59:52 -08001090 }
Jason Monk49fa0162017-01-11 09:21:56 -05001091 };
1092
1093 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1094 @Override
1095 public void onReceive(Context context, Intent intent) {
1096 String action = intent.getAction();
Siarhei Vishniakoud002a0a2017-06-05 22:44:37 +01001097 if (Intent.ACTION_SCREEN_OFF.equals(action)
1098 || Intent.ACTION_SCREEN_ON.equals(action)) {
1099 notifyNavigationBarScreenOn();
Jason Monk49fa0162017-01-11 09:21:56 -05001100 }
Phil Weavera858c5f2018-04-26 13:27:30 -07001101 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
1102 // The accessibility settings may be different for the new user
1103 updateAccessibilityServicesState(mAccessibilityManager);
1104 };
Jason Monk49fa0162017-01-11 09:21:56 -05001105 }
1106 };
1107
Mike Digman7d092772018-01-11 12:10:32 -08001108 class TaskStackListenerImpl extends SysUiTaskStackChangeListener {
1109 // Invalidate any rotation suggestion on task change or activity orientation change
1110 // Note: all callbacks happen on main thread
1111
1112 @Override
1113 public void onTaskStackChanged() {
Mike Digman1e28a5a2018-02-14 10:49:19 -08001114 setRotateSuggestionButtonState(false);
Mike Digman7d092772018-01-11 12:10:32 -08001115 }
1116
1117 @Override
1118 public void onTaskRemoved(int taskId) {
Mike Digman1e28a5a2018-02-14 10:49:19 -08001119 setRotateSuggestionButtonState(false);
Mike Digman7d092772018-01-11 12:10:32 -08001120 }
1121
1122 @Override
1123 public void onTaskMovedToFront(int taskId) {
Mike Digman1e28a5a2018-02-14 10:49:19 -08001124 setRotateSuggestionButtonState(false);
Mike Digman7d092772018-01-11 12:10:32 -08001125 }
1126
1127 @Override
1128 public void onActivityRequestedOrientationChanged(int taskId, int requestedOrientation) {
Mike Digman85a9bea2018-02-23 15:08:53 -08001129 // Only hide the icon if the top task changes its requestedOrientation
1130 // Launcher can alter its requestedOrientation while it's not on top, don't hide on this
Mike Digman121b11f2018-04-04 12:45:24 -07001131 Optional.ofNullable(ActivityManagerWrapper.getInstance())
1132 .map(ActivityManagerWrapper::getRunningTask)
1133 .ifPresent(a -> {
1134 if (a.id == taskId) setRotateSuggestionButtonState(false);
1135 });
Mike Digman7d092772018-01-11 12:10:32 -08001136 }
1137 }
1138
Mike Digman50752642018-02-15 13:36:09 -08001139 private class ViewRippler {
1140 private static final int RIPPLE_OFFSET_MS = 50;
1141 private static final int RIPPLE_INTERVAL_MS = 2000;
1142 private View mRoot;
1143
1144 public void start(View root) {
1145 stop(); // Stop any pending ripple animations
1146
1147 mRoot = root;
1148
1149 // Schedule pending ripples, offset the 1st to avoid problems with visibility change
1150 mRoot.postOnAnimationDelayed(mRipple, RIPPLE_OFFSET_MS);
1151 mRoot.postOnAnimationDelayed(mRipple, RIPPLE_INTERVAL_MS);
1152 mRoot.postOnAnimationDelayed(mRipple, 2*RIPPLE_INTERVAL_MS);
Mike Digmanc038c322018-05-24 11:06:05 -07001153 mRoot.postOnAnimationDelayed(mRipple, 3*RIPPLE_INTERVAL_MS);
1154 mRoot.postOnAnimationDelayed(mRipple, 4*RIPPLE_INTERVAL_MS);
Mike Digman50752642018-02-15 13:36:09 -08001155 }
1156
1157 public void stop() {
1158 if (mRoot != null) mRoot.removeCallbacks(mRipple);
1159 }
1160
1161 private final Runnable mRipple = new Runnable() {
1162 @Override
1163 public void run() { // Cause the ripple to fire via false presses
Mike Digmanf4c98992018-04-25 11:25:59 -07001164 if (!mRoot.isAttachedToWindow()) return;
Mike Digman50752642018-02-15 13:36:09 -08001165 mRoot.setPressed(true);
1166 mRoot.setPressed(false);
1167 }
1168 };
1169 }
1170
Jason Monk49fa0162017-01-11 09:21:56 -05001171 public static View create(Context context, FragmentListener listener) {
1172 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1173 LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
1174 WindowManager.LayoutParams.TYPE_NAVIGATION_BAR,
1175 WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
1176 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1177 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
1178 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
1179 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
1180 | WindowManager.LayoutParams.FLAG_SLIPPERY,
1181 PixelFormat.TRANSLUCENT);
1182 lp.token = new Binder();
Jason Monk49fa0162017-01-11 09:21:56 -05001183 lp.setTitle("NavigationBar");
Phil Weaver8583ae82018-02-13 11:01:24 -08001184 lp.accessibilityTitle = context.getString(R.string.nav_bar);
Jason Monk49fa0162017-01-11 09:21:56 -05001185 lp.windowAnimations = 0;
1186
1187 View navigationBarView = LayoutInflater.from(context).inflate(
1188 R.layout.navigation_bar_window, null);
1189
1190 if (DEBUG) Log.v(TAG, "addNavigationBar: about to add " + navigationBarView);
1191 if (navigationBarView == null) return null;
1192
1193 context.getSystemService(WindowManager.class).addView(navigationBarView, lp);
1194 FragmentHostManager fragmentHost = FragmentHostManager.get(navigationBarView);
1195 NavigationBarFragment fragment = new NavigationBarFragment();
1196 fragmentHost.getFragmentManager().beginTransaction()
1197 .replace(R.id.navigation_bar_frame, fragment, TAG)
1198 .commit();
1199 fragmentHost.addTagListener(TAG, listener);
1200 return navigationBarView;
1201 }
1202}