Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1 | /* |
| 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 | |
| 15 | package com.android.systemui.statusbar.phone; |
| 16 | |
| 17 | import static android.app.StatusBarManager.NAVIGATION_HINT_BACK_ALT; |
| 18 | import static android.app.StatusBarManager.NAVIGATION_HINT_IME_SHOWN; |
| 19 | import static android.app.StatusBarManager.WINDOW_STATE_SHOWING; |
| 20 | import static android.app.StatusBarManager.windowStateToString; |
| 21 | |
Mike Digman | ab65025 | 2018-03-06 11:01:41 -0800 | [diff] [blame] | 22 | import static com.android.internal.view.RotationPolicy.NATURAL_ROTATION; |
| 23 | |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 24 | import static com.android.systemui.shared.system.NavigationBarCompat.InteractionType; |
Tracy Zhou | 1ac592c | 2018-07-25 13:47:37 -0700 | [diff] [blame] | 25 | import static com.android.systemui.statusbar.phone.BarTransitions.MODE_LIGHTS_OUT_TRANSPARENT; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 26 | import static com.android.systemui.statusbar.phone.BarTransitions.MODE_SEMI_TRANSPARENT; |
Tracy Zhou | 1ac592c | 2018-07-25 13:47:37 -0700 | [diff] [blame] | 27 | import static com.android.systemui.statusbar.phone.BarTransitions.MODE_TRANSPARENT; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 28 | import static com.android.systemui.statusbar.phone.StatusBar.DEBUG_WINDOW_STATE; |
| 29 | import static com.android.systemui.statusbar.phone.StatusBar.dumpBarTransitions; |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 30 | import static com.android.systemui.OverviewProxyService.OverviewProxyListener; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 31 | |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 32 | import android.accessibilityservice.AccessibilityServiceInfo; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 33 | import android.animation.Animator; |
| 34 | import android.animation.AnimatorListenerAdapter; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 35 | import android.animation.ObjectAnimator; |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 36 | import android.annotation.IdRes; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 37 | import android.annotation.Nullable; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 38 | import android.app.ActivityTaskManager; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 39 | import android.app.Fragment; |
| 40 | import android.app.IActivityManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 41 | import android.app.IActivityTaskManager; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 42 | import android.app.StatusBarManager; |
| 43 | import android.content.BroadcastReceiver; |
Casey Burkhardt | b9dcd66 | 2017-03-20 15:10:16 -0700 | [diff] [blame] | 44 | import android.content.ContentResolver; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 45 | import android.content.Context; |
| 46 | import android.content.Intent; |
| 47 | import android.content.IntentFilter; |
| 48 | import android.content.res.Configuration; |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 49 | import android.database.ContentObserver; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 50 | import android.graphics.PixelFormat; |
| 51 | import android.graphics.Rect; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 52 | import android.graphics.drawable.AnimatedVectorDrawable; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 53 | import android.inputmethodservice.InputMethodService; |
| 54 | import android.os.Binder; |
| 55 | import android.os.Bundle; |
| 56 | import android.os.Handler; |
| 57 | import android.os.IBinder; |
| 58 | import android.os.Message; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 59 | import android.os.RemoteException; |
| 60 | import android.os.UserHandle; |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 61 | import android.provider.Settings; |
Aurimas Liutikas | fd52c14 | 2018-04-17 09:50:46 -0700 | [diff] [blame] | 62 | import androidx.annotation.VisibleForTesting; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 63 | import android.telecom.TelecomManager; |
| 64 | import android.text.TextUtils; |
| 65 | import android.util.Log; |
| 66 | import android.view.IRotationWatcher.Stub; |
| 67 | import android.view.KeyEvent; |
| 68 | import android.view.LayoutInflater; |
| 69 | import android.view.MotionEvent; |
Mike Digman | 85ff7fa | 2018-01-23 14:59:52 -0800 | [diff] [blame] | 70 | import android.view.Surface; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 71 | import android.view.View; |
| 72 | import android.view.ViewGroup; |
| 73 | import android.view.WindowManager; |
| 74 | import android.view.WindowManager.LayoutParams; |
| 75 | import android.view.WindowManagerGlobal; |
| 76 | import android.view.accessibility.AccessibilityEvent; |
| 77 | import android.view.accessibility.AccessibilityManager; |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 78 | import android.view.accessibility.AccessibilityManager.AccessibilityServicesStateChangeListener; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 79 | |
| 80 | import com.android.internal.logging.MetricsLogger; |
| 81 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Jason Monk | ea03be1 | 2017-12-04 11:08:41 -0500 | [diff] [blame] | 82 | import com.android.internal.util.LatencyTracker; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 83 | import com.android.systemui.Dependency; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 84 | import com.android.systemui.Interpolators; |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 85 | import com.android.systemui.OverviewProxyService; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 86 | import com.android.systemui.R; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 87 | import com.android.systemui.SysUiServiceProvider; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 88 | import com.android.systemui.assist.AssistManager; |
| 89 | import com.android.systemui.fragments.FragmentHostManager; |
| 90 | import com.android.systemui.fragments.FragmentHostManager.FragmentListener; |
| 91 | import com.android.systemui.recents.Recents; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 92 | import com.android.systemui.recents.misc.SysUiTaskStackChangeListener; |
| 93 | import com.android.systemui.shared.system.ActivityManagerWrapper; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 94 | import com.android.systemui.stackdivider.Divider; |
| 95 | import com.android.systemui.statusbar.CommandQueue; |
| 96 | import com.android.systemui.statusbar.CommandQueue.Callbacks; |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 97 | import com.android.systemui.statusbar.policy.AccessibilityManagerWrapper; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 98 | import com.android.systemui.statusbar.policy.KeyButtonDrawable; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 99 | import com.android.systemui.statusbar.policy.KeyButtonView; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 100 | import com.android.systemui.statusbar.policy.RotationLockController; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 101 | import com.android.systemui.statusbar.notification.stack.StackStateAnimator; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 102 | |
| 103 | import java.io.FileDescriptor; |
| 104 | import java.io.PrintWriter; |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 105 | import java.util.List; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 106 | import java.util.Locale; |
Mike Digman | 121b11f | 2018-04-04 12:45:24 -0700 | [diff] [blame] | 107 | import java.util.Optional; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 108 | |
| 109 | /** |
| 110 | * Fragment containing the NavigationBarFragment. Contains logic for what happens |
| 111 | * on clicks and view states of the nav bar. |
| 112 | */ |
| 113 | public class NavigationBarFragment extends Fragment implements Callbacks { |
| 114 | |
Jason Monk | d4afe15 | 2017-05-01 15:37:43 -0400 | [diff] [blame] | 115 | public static final String TAG = "NavigationBar"; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 116 | private static final boolean DEBUG = false; |
Mike Digman | 3e33da6 | 2018-03-14 16:25:11 -0700 | [diff] [blame] | 117 | private static final boolean DEBUG_ROTATION = true; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 118 | private static final String EXTRA_DISABLE_STATE = "disabled_state"; |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 119 | private static final String EXTRA_DISABLE2_STATE = "disabled2_state"; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 120 | |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 121 | private final static int BUTTON_FADE_IN_OUT_DURATION_MS = 100; |
Mike Digman | 5aeca79 | 2018-03-05 11:14:39 -0800 | [diff] [blame] | 122 | private final static int NAVBAR_HIDDEN_PENDING_ICON_TIMEOUT_MS = 20000; |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 123 | |
Mike Digman | 5075264 | 2018-02-15 13:36:09 -0800 | [diff] [blame] | 124 | private static final int NUM_ACCEPTED_ROTATION_SUGGESTIONS_FOR_INTRODUCTION = 3; |
| 125 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 126 | /** 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 Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 136 | private boolean mAccessibilityFeedbackEnabled; |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 137 | private AccessibilityManager mAccessibilityManager; |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 138 | private MagnificationContentObserver mMagnificationObserver; |
Casey Burkhardt | b9dcd66 | 2017-03-20 15:10:16 -0700 | [diff] [blame] | 139 | private ContentResolver mContentResolver; |
Mike Digman | c94759d | 2018-01-23 11:01:21 -0800 | [diff] [blame] | 140 | private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 141 | |
| 142 | private int mDisabledFlags1; |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 143 | private int mDisabledFlags2; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 144 | private StatusBar mStatusBar; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 145 | 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 Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 156 | |
Matthew Ng | dc79e5c | 2017-12-14 17:37:35 -0800 | [diff] [blame] | 157 | private OverviewProxyService mOverviewProxyService; |
| 158 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 159 | public boolean mHomeBlockedThisTouch; |
| 160 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 161 | private int mLastRotationSuggestion; |
Mike Digman | 5aeca79 | 2018-03-05 11:14:39 -0800 | [diff] [blame] | 162 | private boolean mPendingRotationSuggestion; |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 163 | private boolean mHoveringRotationSuggestion; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 164 | private RotationLockController mRotationLockController; |
| 165 | private TaskStackListenerImpl mTaskStackListener; |
| 166 | |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 167 | private final Runnable mRemoveRotationProposal = () -> setRotateSuggestionButtonState(false); |
Mike Digman | 5aeca79 | 2018-03-05 11:14:39 -0800 | [diff] [blame] | 168 | private final Runnable mCancelPendingRotationProposal = |
| 169 | () -> mPendingRotationSuggestion = false; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 170 | private Animator mRotateHideAnimator; |
Mike Digman | 5075264 | 2018-02-15 13:36:09 -0800 | [diff] [blame] | 171 | private ViewRippler mViewRippler = new ViewRippler(); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 172 | |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 173 | private final OverviewProxyListener mOverviewProxyListener = new OverviewProxyListener() { |
| 174 | @Override |
| 175 | public void onConnectionChanged(boolean isConnected) { |
Winson Chung | f9e3027 | 2018-03-26 17:25:36 -0700 | [diff] [blame] | 176 | mNavigationBarView.updateStates(); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 177 | updateScreenPinningGestures(); |
| 178 | } |
| 179 | |
| 180 | @Override |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 181 | public void onQuickStepStarted() { |
Mike Digman | 85a9bea | 2018-02-23 15:08:53 -0800 | [diff] [blame] | 182 | // Use navbar dragging as a signal to hide the rotate button |
| 183 | setRotateSuggestionButtonState(false); |
Matthew Ng | 90ef063 | 2018-08-15 13:53:15 -0700 | [diff] [blame^] | 184 | |
| 185 | // Hide the notifications panel when quick step starts |
| 186 | mStatusBar.collapsePanel(true /* animate */); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 187 | } |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 188 | |
| 189 | @Override |
| 190 | public void onInteractionFlagsChanged(@InteractionType int flags) { |
| 191 | mNavigationBarView.updateStates(); |
Winson Chung | f9e3027 | 2018-03-26 17:25:36 -0700 | [diff] [blame] | 192 | updateScreenPinningGestures(); |
Matthew Ng | 8f25fb96 | 2018-01-16 17:17:24 -0800 | [diff] [blame] | 193 | } |
Matthew Ng | 96985e7 | 2018-05-08 15:46:13 -0700 | [diff] [blame] | 194 | |
| 195 | @Override |
| 196 | public void onBackButtonAlphaChanged(float alpha, boolean animate) { |
| 197 | final ButtonDispatcher backButton = mNavigationBarView.getBackButton(); |
| 198 | backButton.setVisibility(alpha > 0 ? View.VISIBLE : View.INVISIBLE); |
| 199 | backButton.setAlpha(alpha, animate); |
| 200 | } |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 201 | }; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 202 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 203 | // ----- Fragment Lifecycle Callbacks ----- |
| 204 | |
| 205 | @Override |
| 206 | public void onCreate(@Nullable Bundle savedInstanceState) { |
| 207 | super.onCreate(savedInstanceState); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 208 | mCommandQueue = SysUiServiceProvider.getComponent(getContext(), CommandQueue.class); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 209 | mCommandQueue.addCallbacks(this); |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 210 | mStatusBar = SysUiServiceProvider.getComponent(getContext(), StatusBar.class); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 211 | mRecents = SysUiServiceProvider.getComponent(getContext(), Recents.class); |
| 212 | mDivider = SysUiServiceProvider.getComponent(getContext(), Divider.class); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 213 | mWindowManager = getContext().getSystemService(WindowManager.class); |
| 214 | mAccessibilityManager = getContext().getSystemService(AccessibilityManager.class); |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 215 | Dependency.get(AccessibilityManagerWrapper.class).addCallback( |
| 216 | mAccessibilityListener); |
Casey Burkhardt | b9dcd66 | 2017-03-20 15:10:16 -0700 | [diff] [blame] | 217 | mContentResolver = getContext().getContentResolver(); |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 218 | mMagnificationObserver = new MagnificationContentObserver( |
| 219 | getContext().getMainThreadHandler()); |
Casey Burkhardt | b9dcd66 | 2017-03-20 15:10:16 -0700 | [diff] [blame] | 220 | mContentResolver.registerContentObserver(Settings.Secure.getUriFor( |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 221 | Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED), false, |
Casey Burkhardt | 5d61440 | 2017-04-06 13:46:50 -0700 | [diff] [blame] | 222 | mMagnificationObserver, UserHandle.USER_ALL); |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 223 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 224 | if (savedInstanceState != null) { |
| 225 | mDisabledFlags1 = savedInstanceState.getInt(EXTRA_DISABLE_STATE, 0); |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 226 | mDisabledFlags2 = savedInstanceState.getInt(EXTRA_DISABLE2_STATE, 0); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 227 | } |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 228 | mAssistManager = Dependency.get(AssistManager.class); |
Matthew Ng | dc79e5c | 2017-12-14 17:37:35 -0800 | [diff] [blame] | 229 | mOverviewProxyService = Dependency.get(OverviewProxyService.class); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 230 | |
| 231 | try { |
| 232 | WindowManagerGlobal.getWindowManagerService() |
Andrii Kulian | 35fa3c2 | 2017-03-11 09:37:28 -0800 | [diff] [blame] | 233 | .watchRotation(mRotationWatcher, getContext().getDisplay().getDisplayId()); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 234 | } catch (RemoteException e) { |
| 235 | throw e.rethrowFromSystemServer(); |
| 236 | } |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 237 | |
| 238 | mRotationLockController = Dependency.get(RotationLockController.class); |
| 239 | |
Mike Digman | ab65025 | 2018-03-06 11:01:41 -0800 | [diff] [blame] | 240 | // Reset user rotation pref to match that of the WindowManager if starting in locked mode |
| 241 | // This will automatically happen when switching from auto-rotate to locked mode |
| 242 | if (mRotationLockController.isRotationLocked()) { |
| 243 | final int winRotation = mWindowManager.getDefaultDisplay().getRotation(); |
| 244 | mRotationLockController.setRotationLockedAtAngle(true, winRotation); |
| 245 | } |
| 246 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 247 | // Register the task stack listener |
| 248 | mTaskStackListener = new TaskStackListenerImpl(); |
| 249 | ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | @Override |
| 253 | public void onDestroy() { |
| 254 | super.onDestroy(); |
| 255 | mCommandQueue.removeCallbacks(this); |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 256 | Dependency.get(AccessibilityManagerWrapper.class).removeCallback( |
| 257 | mAccessibilityListener); |
Casey Burkhardt | b9dcd66 | 2017-03-20 15:10:16 -0700 | [diff] [blame] | 258 | mContentResolver.unregisterContentObserver(mMagnificationObserver); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 259 | try { |
| 260 | WindowManagerGlobal.getWindowManagerService() |
| 261 | .removeRotationWatcher(mRotationWatcher); |
| 262 | } catch (RemoteException e) { |
| 263 | throw e.rethrowFromSystemServer(); |
| 264 | } |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 265 | |
| 266 | // Unregister the task stack listener |
| 267 | ActivityManagerWrapper.getInstance().unregisterTaskStackListener(mTaskStackListener); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | @Override |
| 271 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, |
| 272 | Bundle savedInstanceState) { |
| 273 | return inflater.inflate(R.layout.navigation_bar, container, false); |
| 274 | } |
| 275 | |
| 276 | @Override |
| 277 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { |
| 278 | super.onViewCreated(view, savedInstanceState); |
| 279 | mNavigationBarView = (NavigationBarView) view; |
| 280 | |
| 281 | mNavigationBarView.setDisabledFlags(mDisabledFlags1); |
Matthew Ng | 78f88d1 | 2018-01-23 12:39:55 -0800 | [diff] [blame] | 282 | mNavigationBarView.setComponents(mRecents, mDivider, mStatusBar.getPanel()); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 283 | mNavigationBarView.setOnVerticalChangedListener(this::onVerticalChanged); |
| 284 | mNavigationBarView.setOnTouchListener(this::onNavigationTouch); |
| 285 | if (savedInstanceState != null) { |
| 286 | mNavigationBarView.getLightTransitionsController().restoreState(savedInstanceState); |
| 287 | } |
| 288 | |
| 289 | prepareNavigationBarView(); |
| 290 | checkNavBarModes(); |
| 291 | |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 292 | setDisabled2Flags(mDisabledFlags2); |
| 293 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 294 | IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF); |
| 295 | filter.addAction(Intent.ACTION_SCREEN_ON); |
Phil Weaver | a858c5f | 2018-04-26 13:27:30 -0700 | [diff] [blame] | 296 | filter.addAction(Intent.ACTION_USER_SWITCHED); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 297 | getContext().registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, filter, null, null); |
Siarhei Vishniakou | d002a0a | 2017-06-05 22:44:37 +0100 | [diff] [blame] | 298 | notifyNavigationBarScreenOn(); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 299 | mOverviewProxyService.addCallback(mOverviewProxyListener); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | @Override |
| 303 | public void onDestroyView() { |
| 304 | super.onDestroyView(); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 305 | mNavigationBarView.getLightTransitionsController().destroy(getContext()); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 306 | mOverviewProxyService.removeCallback(mOverviewProxyListener); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 307 | getContext().unregisterReceiver(mBroadcastReceiver); |
| 308 | } |
| 309 | |
| 310 | @Override |
| 311 | public void onSaveInstanceState(Bundle outState) { |
| 312 | super.onSaveInstanceState(outState); |
| 313 | outState.putInt(EXTRA_DISABLE_STATE, mDisabledFlags1); |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 314 | outState.putInt(EXTRA_DISABLE2_STATE, mDisabledFlags2); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 315 | if (mNavigationBarView != null) { |
| 316 | mNavigationBarView.getLightTransitionsController().saveState(outState); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | @Override |
| 321 | public void onConfigurationChanged(Configuration newConfig) { |
| 322 | super.onConfigurationChanged(newConfig); |
| 323 | final Locale locale = getContext().getResources().getConfiguration().locale; |
| 324 | final int ld = TextUtils.getLayoutDirectionFromLocale(locale); |
| 325 | if (!locale.equals(mLocale) || ld != mLayoutDirection) { |
| 326 | if (DEBUG) { |
| 327 | Log.v(TAG, String.format( |
| 328 | "config changed locale/LD: %s (%d) -> %s (%d)", mLocale, mLayoutDirection, |
| 329 | locale, ld)); |
| 330 | } |
| 331 | mLocale = locale; |
| 332 | mLayoutDirection = ld; |
| 333 | refreshLayout(ld); |
| 334 | } |
| 335 | repositionNavigationBar(); |
| 336 | } |
| 337 | |
| 338 | @Override |
| 339 | public void dump(String prefix, FileDescriptor fd, PrintWriter pw, String[] args) { |
| 340 | if (mNavigationBarView != null) { |
| 341 | pw.print(" mNavigationBarWindowState="); |
| 342 | pw.println(windowStateToString(mNavigationBarWindowState)); |
| 343 | pw.print(" mNavigationBarMode="); |
| 344 | pw.println(BarTransitions.modeToString(mNavigationBarMode)); |
| 345 | dumpBarTransitions(pw, "mNavigationBarView", mNavigationBarView.getBarTransitions()); |
| 346 | } |
| 347 | |
| 348 | pw.print(" mNavigationBarView="); |
| 349 | if (mNavigationBarView == null) { |
| 350 | pw.println("null"); |
| 351 | } else { |
| 352 | mNavigationBarView.dump(fd, pw, args); |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | // ----- CommandQueue Callbacks ----- |
| 357 | |
| 358 | @Override |
| 359 | public void setImeWindowStatus(IBinder token, int vis, int backDisposition, |
| 360 | boolean showImeSwitcher) { |
| 361 | boolean imeShown = (vis & InputMethodService.IME_VISIBLE) != 0; |
| 362 | int hints = mNavigationIconHints; |
Yohei Yukawa | 386f50e | 2018-03-14 13:03:42 -0700 | [diff] [blame] | 363 | switch (backDisposition) { |
| 364 | case InputMethodService.BACK_DISPOSITION_DEFAULT: |
| 365 | case InputMethodService.BACK_DISPOSITION_WILL_NOT_DISMISS: |
| 366 | case InputMethodService.BACK_DISPOSITION_WILL_DISMISS: |
| 367 | if (imeShown) { |
| 368 | hints |= NAVIGATION_HINT_BACK_ALT; |
| 369 | } else { |
| 370 | hints &= ~NAVIGATION_HINT_BACK_ALT; |
| 371 | } |
| 372 | break; |
| 373 | case InputMethodService.BACK_DISPOSITION_ADJUST_NOTHING: |
| 374 | hints &= ~NAVIGATION_HINT_BACK_ALT; |
| 375 | break; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 376 | } |
| 377 | if (showImeSwitcher) { |
| 378 | hints |= NAVIGATION_HINT_IME_SHOWN; |
| 379 | } else { |
| 380 | hints &= ~NAVIGATION_HINT_IME_SHOWN; |
| 381 | } |
| 382 | if (hints == mNavigationIconHints) return; |
| 383 | |
| 384 | mNavigationIconHints = hints; |
| 385 | |
| 386 | if (mNavigationBarView != null) { |
| 387 | mNavigationBarView.setNavigationIconHints(hints); |
| 388 | } |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 389 | mStatusBar.checkBarModes(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | @Override |
| 393 | public void topAppWindowChanged(boolean showMenu) { |
| 394 | if (mNavigationBarView != null) { |
| 395 | mNavigationBarView.setMenuVisibility(showMenu); |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | @Override |
| 400 | public void setWindowState(int window, int state) { |
| 401 | if (mNavigationBarView != null |
| 402 | && window == StatusBarManager.WINDOW_NAVIGATION_BAR |
| 403 | && mNavigationBarWindowState != state) { |
| 404 | mNavigationBarWindowState = state; |
| 405 | if (DEBUG_WINDOW_STATE) Log.d(TAG, "Navigation bar " + windowStateToString(state)); |
Mike Digman | 5aeca79 | 2018-03-05 11:14:39 -0800 | [diff] [blame] | 406 | |
| 407 | // If the navbar is visible, show the rotate button if there's a pending suggestion |
| 408 | if (state == WINDOW_STATE_SHOWING && mPendingRotationSuggestion) { |
| 409 | showAndLogRotationSuggestion(); |
| 410 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 411 | } |
| 412 | } |
| 413 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 414 | @Override |
Mike Digman | e077731 | 2018-01-19 12:41:51 -0800 | [diff] [blame] | 415 | public void onRotationProposal(final int rotation, boolean isValid) { |
Mike Digman | 3e33da6 | 2018-03-14 16:25:11 -0700 | [diff] [blame] | 416 | final int winRotation = mWindowManager.getDefaultDisplay().getRotation(); |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 417 | final boolean rotateSuggestionsDisabled = hasDisable2RotateSuggestionFlag(mDisabledFlags2); |
Mike Digman | 3e33da6 | 2018-03-14 16:25:11 -0700 | [diff] [blame] | 418 | if (DEBUG_ROTATION) { |
| 419 | Log.v(TAG, "onRotationProposal proposedRotation=" + Surface.rotationToString(rotation) |
| 420 | + ", winRotation=" + Surface.rotationToString(winRotation) |
| 421 | + ", isValid=" + isValid + ", mNavBarWindowState=" |
| 422 | + StatusBarManager.windowStateToString(mNavigationBarWindowState) |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 423 | + ", rotateSuggestionsDisabled=" + rotateSuggestionsDisabled |
Mike Digman | 3e33da6 | 2018-03-14 16:25:11 -0700 | [diff] [blame] | 424 | + ", isRotateButtonVisible=" + (mNavigationBarView == null ? "null" : |
| 425 | mNavigationBarView.isRotateButtonVisible())); |
| 426 | } |
| 427 | |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 428 | // Respect the disabled flag, no need for action as flag change callback will handle hiding |
| 429 | if (rotateSuggestionsDisabled) return; |
| 430 | |
Mike Digman | e077731 | 2018-01-19 12:41:51 -0800 | [diff] [blame] | 431 | // This method will be called on rotation suggestion changes even if the proposed rotation |
| 432 | // is not valid for the top app. Use invalid rotation choices as a signal to remove the |
| 433 | // rotate button if shown. |
Mike Digman | e077731 | 2018-01-19 12:41:51 -0800 | [diff] [blame] | 434 | if (!isValid) { |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 435 | setRotateSuggestionButtonState(false); |
Mike Digman | e077731 | 2018-01-19 12:41:51 -0800 | [diff] [blame] | 436 | return; |
| 437 | } |
| 438 | |
Mike Digman | 5aeca79 | 2018-03-05 11:14:39 -0800 | [diff] [blame] | 439 | // If window rotation matches suggested rotation, remove any current suggestions |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 440 | if (rotation == winRotation) { |
Mike Digman | 5aeca79 | 2018-03-05 11:14:39 -0800 | [diff] [blame] | 441 | getView().removeCallbacks(mRemoveRotationProposal); |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 442 | setRotateSuggestionButtonState(false); |
Mike Digman | 5aeca79 | 2018-03-05 11:14:39 -0800 | [diff] [blame] | 443 | return; |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 444 | } |
Mike Digman | 5aeca79 | 2018-03-05 11:14:39 -0800 | [diff] [blame] | 445 | |
| 446 | // Prepare to show the navbar icon by updating the icon style to change anim params |
| 447 | mLastRotationSuggestion = rotation; // Remember rotation for click |
| 448 | if (mNavigationBarView != null) { |
| 449 | final boolean rotationCCW = isRotationAnimationCCW(winRotation, rotation); |
| 450 | int style; |
| 451 | if (winRotation == Surface.ROTATION_0 || winRotation == Surface.ROTATION_180) { |
| 452 | style = rotationCCW ? R.style.RotateButtonCCWStart90 : |
| 453 | R.style.RotateButtonCWStart90; |
| 454 | } else { // 90 or 270 |
| 455 | style = rotationCCW ? R.style.RotateButtonCCWStart0 : |
| 456 | R.style.RotateButtonCWStart0; |
| 457 | } |
| 458 | mNavigationBarView.updateRotateSuggestionButtonStyle(style, true); |
| 459 | } |
| 460 | |
| 461 | if (mNavigationBarWindowState != WINDOW_STATE_SHOWING) { |
| 462 | // If the navbar isn't shown, flag the rotate icon to be shown should the navbar become |
| 463 | // visible given some time limit. |
| 464 | mPendingRotationSuggestion = true; |
| 465 | getView().removeCallbacks(mCancelPendingRotationProposal); |
| 466 | getView().postDelayed(mCancelPendingRotationProposal, |
| 467 | NAVBAR_HIDDEN_PENDING_ICON_TIMEOUT_MS); |
| 468 | |
| 469 | } else { // The navbar is visible so show the icon right away |
| 470 | showAndLogRotationSuggestion(); |
| 471 | } |
| 472 | } |
| 473 | |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 474 | private void onRotationSuggestionsDisabled() { |
| 475 | // Immediately hide the rotate button and clear any planned removal |
| 476 | setRotateSuggestionButtonState(false, true); |
Mike Digman | e14c475 | 2018-03-20 12:14:54 -0700 | [diff] [blame] | 477 | |
| 478 | // This method can be called before view setup is done, ensure getView isn't null |
| 479 | final View v = getView(); |
| 480 | if (v != null) v.removeCallbacks(mRemoveRotationProposal); |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 481 | } |
| 482 | |
Mike Digman | 5aeca79 | 2018-03-05 11:14:39 -0800 | [diff] [blame] | 483 | private void showAndLogRotationSuggestion() { |
| 484 | setRotateSuggestionButtonState(true); |
| 485 | rescheduleRotationTimeout(false); |
| 486 | mMetricsLogger.visible(MetricsEvent.ROTATION_SUGGESTION_SHOWN); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 487 | } |
| 488 | |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 489 | private boolean isRotationAnimationCCW(int from, int to) { |
| 490 | // All 180deg WM rotation animations are CCW, match that |
| 491 | if (from == Surface.ROTATION_0 && to == Surface.ROTATION_90) return false; |
| 492 | if (from == Surface.ROTATION_0 && to == Surface.ROTATION_180) return true; //180d so CCW |
| 493 | if (from == Surface.ROTATION_0 && to == Surface.ROTATION_270) return true; |
| 494 | if (from == Surface.ROTATION_90 && to == Surface.ROTATION_0) return true; |
| 495 | if (from == Surface.ROTATION_90 && to == Surface.ROTATION_180) return false; |
| 496 | if (from == Surface.ROTATION_90 && to == Surface.ROTATION_270) return true; //180d so CCW |
| 497 | if (from == Surface.ROTATION_180 && to == Surface.ROTATION_0) return true; //180d so CCW |
| 498 | if (from == Surface.ROTATION_180 && to == Surface.ROTATION_90) return true; |
| 499 | if (from == Surface.ROTATION_180 && to == Surface.ROTATION_270) return false; |
| 500 | if (from == Surface.ROTATION_270 && to == Surface.ROTATION_0) return false; |
| 501 | if (from == Surface.ROTATION_270 && to == Surface.ROTATION_90) return true; //180d so CCW |
| 502 | if (from == Surface.ROTATION_270 && to == Surface.ROTATION_180) return true; |
| 503 | return false; // Default |
Mike Digman | a48cf19 | 2018-02-12 17:52:48 -0800 | [diff] [blame] | 504 | } |
| 505 | |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 506 | public void setRotateSuggestionButtonState(final boolean visible) { |
| 507 | setRotateSuggestionButtonState(visible, false); |
| 508 | } |
| 509 | |
| 510 | public void setRotateSuggestionButtonState(final boolean visible, final boolean force) { |
| 511 | if (mNavigationBarView == null) return; |
| 512 | |
| 513 | // At any point the the button can become invisible because an a11y service became active. |
| 514 | // Similarly, a call to make the button visible may be rejected because an a11y service is |
| 515 | // active. Must account for this. |
| 516 | |
| 517 | ButtonDispatcher rotBtn = mNavigationBarView.getRotateSuggestionButton(); |
| 518 | final boolean currentlyVisible = mNavigationBarView.isRotateButtonVisible(); |
| 519 | |
| 520 | // Rerun a show animation to indicate change but don't rerun a hide animation |
| 521 | if (!visible && !currentlyVisible) return; |
| 522 | |
| 523 | View view = rotBtn.getCurrentView(); |
| 524 | if (view == null) return; |
| 525 | |
| 526 | KeyButtonDrawable kbd = rotBtn.getImageDrawable(); |
| 527 | if (kbd == null) return; |
| 528 | |
| 529 | // The KBD and AVD is recreated every new valid suggestion because of style changes. |
| 530 | AnimatedVectorDrawable animIcon = null; |
| 531 | if (kbd.getDrawable(0) instanceof AnimatedVectorDrawable) { |
| 532 | animIcon = (AnimatedVectorDrawable) kbd.getDrawable(0); |
| 533 | } |
| 534 | |
Mike Digman | 5aeca79 | 2018-03-05 11:14:39 -0800 | [diff] [blame] | 535 | // Clear any pending suggestion flag as it has either been nullified or is being shown |
| 536 | mPendingRotationSuggestion = false; |
Mike Digman | f4c9899 | 2018-04-25 11:25:59 -0700 | [diff] [blame] | 537 | if (getView() != null) getView().removeCallbacks(mCancelPendingRotationProposal); |
Mike Digman | 5aeca79 | 2018-03-05 11:14:39 -0800 | [diff] [blame] | 538 | |
| 539 | // Handle the visibility change and animation |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 540 | if (visible) { // Appear and change (cannot force) |
Mike Digman | 85a9bea | 2018-02-23 15:08:53 -0800 | [diff] [blame] | 541 | // Stop and clear any currently running hide animations |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 542 | if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) { |
Mike Digman | 85a9bea | 2018-02-23 15:08:53 -0800 | [diff] [blame] | 543 | mRotateHideAnimator.cancel(); |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 544 | } |
Mike Digman | 85a9bea | 2018-02-23 15:08:53 -0800 | [diff] [blame] | 545 | mRotateHideAnimator = null; |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 546 | |
| 547 | // Reset the alpha if any has changed due to hide animation |
| 548 | view.setAlpha(1f); |
| 549 | |
| 550 | // Run the rotate icon's animation if it has one |
| 551 | if (animIcon != null) { |
| 552 | animIcon.reset(); |
| 553 | animIcon.start(); |
| 554 | } |
| 555 | |
Mike Digman | 5075264 | 2018-02-15 13:36:09 -0800 | [diff] [blame] | 556 | if (!isRotateSuggestionIntroduced()) mViewRippler.start(view); |
| 557 | |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 558 | // Set visibility, may fail if a11y service is active. |
| 559 | // If invisible, call will stop animation. |
Mike Digman | 9b50b76 | 2018-04-19 10:50:35 -0700 | [diff] [blame] | 560 | int appliedVisibility = mNavigationBarView.setRotateButtonVisibility(true); |
| 561 | if (appliedVisibility == View.VISIBLE) { |
| 562 | // If the button will actually become visible and the navbar is about to hide, |
| 563 | // tell the statusbar to keep it around for longer |
| 564 | mStatusBar.touchAutoHide(); |
| 565 | } |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 566 | |
| 567 | } else { // Hide |
| 568 | |
Mike Digman | 5075264 | 2018-02-15 13:36:09 -0800 | [diff] [blame] | 569 | mViewRippler.stop(); // Prevent any pending ripples, force hide or not |
| 570 | |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 571 | if (force) { |
| 572 | // If a hide animator is running stop it and make invisible |
| 573 | if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) { |
| 574 | mRotateHideAnimator.pause(); |
| 575 | } |
| 576 | mNavigationBarView.setRotateButtonVisibility(false); |
| 577 | return; |
| 578 | } |
| 579 | |
| 580 | // Don't start any new hide animations if one is running |
| 581 | if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) return; |
| 582 | |
| 583 | ObjectAnimator fadeOut = ObjectAnimator.ofFloat(view, "alpha", |
| 584 | 0f); |
| 585 | fadeOut.setDuration(BUTTON_FADE_IN_OUT_DURATION_MS); |
| 586 | fadeOut.setInterpolator(Interpolators.LINEAR); |
| 587 | fadeOut.addListener(new AnimatorListenerAdapter() { |
| 588 | @Override |
| 589 | public void onAnimationEnd(Animator animation) { |
| 590 | mNavigationBarView.setRotateButtonVisibility(false); |
| 591 | } |
| 592 | }); |
| 593 | |
| 594 | mRotateHideAnimator = fadeOut; |
| 595 | fadeOut.start(); |
Mike Digman | a48cf19 | 2018-02-12 17:52:48 -0800 | [diff] [blame] | 596 | } |
| 597 | } |
| 598 | |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 599 | private void rescheduleRotationTimeout(final boolean reasonHover) { |
| 600 | // May be called due to a new rotation proposal or a change in hover state |
| 601 | if (reasonHover) { |
| 602 | // Don't reschedule if a hide animator is running |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 603 | if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) return; |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 604 | // Don't reschedule if not visible |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 605 | if (!mNavigationBarView.isRotateButtonVisible()) return; |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 606 | } |
| 607 | |
Mike Digman | 5aeca79 | 2018-03-05 11:14:39 -0800 | [diff] [blame] | 608 | getView().removeCallbacks(mRemoveRotationProposal); // Stop any pending removal |
| 609 | getView().postDelayed(mRemoveRotationProposal, |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 610 | computeRotationProposalTimeout()); // Schedule timeout |
| 611 | } |
| 612 | |
| 613 | private int computeRotationProposalTimeout() { |
| 614 | if (mAccessibilityFeedbackEnabled) return 20000; |
| 615 | if (mHoveringRotationSuggestion) return 16000; |
Mike Digman | d13e43b | 2018-05-21 11:23:56 -0700 | [diff] [blame] | 616 | return 10000; |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 617 | } |
| 618 | |
Mike Digman | 5075264 | 2018-02-15 13:36:09 -0800 | [diff] [blame] | 619 | private boolean isRotateSuggestionIntroduced() { |
| 620 | ContentResolver cr = getContext().getContentResolver(); |
| 621 | return Settings.Secure.getInt(cr, Settings.Secure.NUM_ROTATION_SUGGESTIONS_ACCEPTED, 0) |
| 622 | >= NUM_ACCEPTED_ROTATION_SUGGESTIONS_FOR_INTRODUCTION; |
| 623 | } |
| 624 | |
| 625 | private void incrementNumAcceptedRotationSuggestionsIfNeeded() { |
| 626 | // Get the number of accepted suggestions |
| 627 | ContentResolver cr = getContext().getContentResolver(); |
| 628 | final int numSuggestions = Settings.Secure.getInt(cr, |
| 629 | Settings.Secure.NUM_ROTATION_SUGGESTIONS_ACCEPTED, 0); |
| 630 | |
| 631 | // Increment the number of accepted suggestions only if it would change intro mode |
| 632 | if (numSuggestions < NUM_ACCEPTED_ROTATION_SUGGESTIONS_FOR_INTRODUCTION) { |
| 633 | Settings.Secure.putInt(cr, Settings.Secure.NUM_ROTATION_SUGGESTIONS_ACCEPTED, |
| 634 | numSuggestions + 1); |
| 635 | } |
| 636 | } |
| 637 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 638 | // Injected from StatusBar at creation. |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 639 | public void setCurrentSysuiVisibility(int systemUiVisibility) { |
| 640 | mSystemUiVisibility = systemUiVisibility; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 641 | mNavigationBarMode = mStatusBar.computeBarMode(0, mSystemUiVisibility, |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 642 | View.NAVIGATION_BAR_TRANSIENT, View.NAVIGATION_BAR_TRANSLUCENT, |
| 643 | View.NAVIGATION_BAR_TRANSPARENT); |
| 644 | checkNavBarModes(); |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 645 | mStatusBar.touchAutoHide(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 646 | mLightBarController.onNavigationVisibilityChanged(mSystemUiVisibility, 0 /* mask */, |
| 647 | true /* nbModeChanged */, mNavigationBarMode); |
| 648 | } |
| 649 | |
| 650 | @Override |
| 651 | public void setSystemUiVisibility(int vis, int fullscreenStackVis, int dockedStackVis, |
| 652 | int mask, Rect fullscreenStackBounds, Rect dockedStackBounds) { |
| 653 | final int oldVal = mSystemUiVisibility; |
| 654 | final int newVal = (oldVal & ~mask) | (vis & mask); |
| 655 | final int diff = newVal ^ oldVal; |
| 656 | boolean nbModeChanged = false; |
| 657 | if (diff != 0) { |
| 658 | mSystemUiVisibility = newVal; |
| 659 | |
| 660 | // update navigation bar mode |
| 661 | final int nbMode = getView() == null |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 662 | ? -1 : mStatusBar.computeBarMode(oldVal, newVal, |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 663 | View.NAVIGATION_BAR_TRANSIENT, View.NAVIGATION_BAR_TRANSLUCENT, |
| 664 | View.NAVIGATION_BAR_TRANSPARENT); |
| 665 | nbModeChanged = nbMode != -1; |
| 666 | if (nbModeChanged) { |
| 667 | if (mNavigationBarMode != nbMode) { |
Tracy Zhou | 1ac592c | 2018-07-25 13:47:37 -0700 | [diff] [blame] | 668 | if (mNavigationBarMode == MODE_TRANSPARENT |
| 669 | || mNavigationBarMode == MODE_LIGHTS_OUT_TRANSPARENT) { |
| 670 | mNavigationBarView.hideRecentsOnboarding(); |
| 671 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 672 | mNavigationBarMode = nbMode; |
| 673 | checkNavBarModes(); |
| 674 | } |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 675 | mStatusBar.touchAutoHide(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 676 | } |
| 677 | } |
| 678 | |
| 679 | mLightBarController.onNavigationVisibilityChanged(vis, mask, nbModeChanged, |
| 680 | mNavigationBarMode); |
| 681 | } |
| 682 | |
| 683 | @Override |
| 684 | public void disable(int state1, int state2, boolean animate) { |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 685 | // Navigation bar flags are in both state1 and state2. |
| 686 | final int masked = state1 & (StatusBarManager.DISABLE_HOME |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 687 | | StatusBarManager.DISABLE_RECENT |
| 688 | | StatusBarManager.DISABLE_BACK |
| 689 | | StatusBarManager.DISABLE_SEARCH); |
| 690 | if (masked != mDisabledFlags1) { |
| 691 | mDisabledFlags1 = masked; |
| 692 | if (mNavigationBarView != null) mNavigationBarView.setDisabledFlags(state1); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 693 | updateScreenPinningGestures(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 694 | } |
Mike Digman | dd2f49e | 2018-03-16 10:54:22 -0700 | [diff] [blame] | 695 | |
| 696 | final int masked2 = state2 & (StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS); |
| 697 | if (masked2 != mDisabledFlags2) { |
| 698 | mDisabledFlags2 = masked2; |
| 699 | setDisabled2Flags(masked2); |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | private void setDisabled2Flags(int state2) { |
| 704 | // Method only called on change of disable2 flags |
| 705 | final boolean rotateSuggestionsDisabled = hasDisable2RotateSuggestionFlag(state2); |
| 706 | if (rotateSuggestionsDisabled) onRotationSuggestionsDisabled(); |
| 707 | } |
| 708 | |
| 709 | private boolean hasDisable2RotateSuggestionFlag(int disable2Flags) { |
| 710 | return (disable2Flags & StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS) != 0; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | // ----- Internal stuffz ----- |
| 714 | |
| 715 | private void refreshLayout(int layoutDirection) { |
| 716 | if (mNavigationBarView != null) { |
| 717 | mNavigationBarView.setLayoutDirection(layoutDirection); |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | private boolean shouldDisableNavbarGestures() { |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 722 | return !mStatusBar.isDeviceProvisioned() |
Matthew Ng | fee0b5b | 2018-02-21 15:38:21 -0800 | [diff] [blame] | 723 | || (mDisabledFlags1 & StatusBarManager.DISABLE_SEARCH) != 0; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | private void repositionNavigationBar() { |
| 727 | if (mNavigationBarView == null || !mNavigationBarView.isAttachedToWindow()) return; |
| 728 | |
| 729 | prepareNavigationBarView(); |
| 730 | |
| 731 | mWindowManager.updateViewLayout((View) mNavigationBarView.getParent(), |
| 732 | ((View) mNavigationBarView.getParent()).getLayoutParams()); |
| 733 | } |
| 734 | |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 735 | private void updateScreenPinningGestures() { |
| 736 | if (mNavigationBarView == null) { |
| 737 | return; |
| 738 | } |
| 739 | |
| 740 | // Change the cancel pin gesture to home and back if recents button is invisible |
| 741 | boolean recentsVisible = mNavigationBarView.isRecentsButtonVisible(); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 742 | ButtonDispatcher backButton = mNavigationBarView.getBackButton(); |
| 743 | if (recentsVisible) { |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 744 | backButton.setOnLongClickListener(this::onLongPressBackRecents); |
| 745 | } else { |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 746 | backButton.setOnLongClickListener(this::onLongPressBackHome); |
| 747 | } |
| 748 | } |
| 749 | |
Siarhei Vishniakou | d002a0a | 2017-06-05 22:44:37 +0100 | [diff] [blame] | 750 | private void notifyNavigationBarScreenOn() { |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 751 | mNavigationBarView.updateNavButtonIcons(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | private void prepareNavigationBarView() { |
| 755 | mNavigationBarView.reorient(); |
| 756 | |
| 757 | ButtonDispatcher recentsButton = mNavigationBarView.getRecentsButton(); |
| 758 | recentsButton.setOnClickListener(this::onRecentsClick); |
| 759 | recentsButton.setOnTouchListener(this::onRecentsTouch); |
| 760 | recentsButton.setLongClickable(true); |
| 761 | recentsButton.setOnLongClickListener(this::onLongPressBackRecents); |
| 762 | |
| 763 | ButtonDispatcher backButton = mNavigationBarView.getBackButton(); |
| 764 | backButton.setLongClickable(true); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 765 | |
| 766 | ButtonDispatcher homeButton = mNavigationBarView.getHomeButton(); |
| 767 | homeButton.setOnTouchListener(this::onHomeTouch); |
Matthew Ng | fee0b5b | 2018-02-21 15:38:21 -0800 | [diff] [blame] | 768 | homeButton.setOnLongClickListener(this::onHomeLongClick); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 769 | |
| 770 | ButtonDispatcher accessibilityButton = mNavigationBarView.getAccessibilityButton(); |
| 771 | accessibilityButton.setOnClickListener(this::onAccessibilityClick); |
| 772 | accessibilityButton.setOnLongClickListener(this::onAccessibilityLongClick); |
Phil Weaver | db9a774 | 2017-04-18 08:15:06 -0700 | [diff] [blame] | 773 | updateAccessibilityServicesState(mAccessibilityManager); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 774 | |
| 775 | ButtonDispatcher rotateSuggestionButton = mNavigationBarView.getRotateSuggestionButton(); |
| 776 | rotateSuggestionButton.setOnClickListener(this::onRotateSuggestionClick); |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 777 | rotateSuggestionButton.setOnHoverListener(this::onRotateSuggestionHover); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 778 | updateScreenPinningGestures(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | private boolean onHomeTouch(View v, MotionEvent event) { |
| 782 | if (mHomeBlockedThisTouch && event.getActionMasked() != MotionEvent.ACTION_DOWN) { |
| 783 | return true; |
| 784 | } |
| 785 | // If an incoming call is ringing, HOME is totally disabled. |
| 786 | // (The user is already on the InCallUI at this point, |
| 787 | // and his ONLY options are to answer or reject the call.) |
| 788 | switch (event.getAction()) { |
| 789 | case MotionEvent.ACTION_DOWN: |
| 790 | mHomeBlockedThisTouch = false; |
| 791 | TelecomManager telecomManager = |
| 792 | getContext().getSystemService(TelecomManager.class); |
| 793 | if (telecomManager != null && telecomManager.isRinging()) { |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 794 | if (mStatusBar.isKeyguardShowing()) { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 795 | Log.i(TAG, "Ignoring HOME; there's a ringing incoming call. " + |
| 796 | "No heads up"); |
| 797 | mHomeBlockedThisTouch = true; |
| 798 | return true; |
| 799 | } |
| 800 | } |
| 801 | break; |
| 802 | case MotionEvent.ACTION_UP: |
| 803 | case MotionEvent.ACTION_CANCEL: |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 804 | mStatusBar.awakenDreams(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 805 | break; |
| 806 | } |
| 807 | return false; |
| 808 | } |
| 809 | |
| 810 | private void onVerticalChanged(boolean isVertical) { |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 811 | mStatusBar.setQsScrimEnabled(!isVertical); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | private boolean onNavigationTouch(View v, MotionEvent event) { |
Eliot Courtney | cb5d316 | 2017-08-09 16:53:15 +0900 | [diff] [blame] | 815 | mStatusBar.checkUserAutohide(event); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 816 | return false; |
| 817 | } |
| 818 | |
Jason Monk | 865246d | 2017-01-19 08:27:01 -0500 | [diff] [blame] | 819 | @VisibleForTesting |
| 820 | boolean onHomeLongClick(View v) { |
Matthew Ng | 6ff33b7 | 2018-02-27 13:47:38 -0800 | [diff] [blame] | 821 | if (!mNavigationBarView.isRecentsButtonVisible() |
| 822 | && ActivityManagerWrapper.getInstance().isScreenPinningActive()) { |
Matthew Ng | fee0b5b | 2018-02-21 15:38:21 -0800 | [diff] [blame] | 823 | return onLongPressBackHome(v); |
| 824 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 825 | if (shouldDisableNavbarGestures()) { |
| 826 | return false; |
| 827 | } |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 828 | mNavigationBarView.onNavigationButtonLongPress(v); |
Mike Digman | c94759d | 2018-01-23 11:01:21 -0800 | [diff] [blame] | 829 | mMetricsLogger.action(MetricsEvent.ACTION_ASSIST_LONG_PRESS); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 830 | mAssistManager.startAssist(new Bundle() /* args */); |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 831 | mStatusBar.awakenDreams(); |
Matthew Ng | dc79e5c | 2017-12-14 17:37:35 -0800 | [diff] [blame] | 832 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 833 | if (mNavigationBarView != null) { |
| 834 | mNavigationBarView.abortCurrentGesture(); |
| 835 | } |
| 836 | return true; |
| 837 | } |
| 838 | |
| 839 | // additional optimization when we have software system buttons - start loading the recent |
| 840 | // tasks on touch down |
| 841 | private boolean onRecentsTouch(View v, MotionEvent event) { |
| 842 | int action = event.getAction() & MotionEvent.ACTION_MASK; |
| 843 | if (action == MotionEvent.ACTION_DOWN) { |
| 844 | mCommandQueue.preloadRecentApps(); |
| 845 | } else if (action == MotionEvent.ACTION_CANCEL) { |
| 846 | mCommandQueue.cancelPreloadRecentApps(); |
| 847 | } else if (action == MotionEvent.ACTION_UP) { |
| 848 | if (!v.isPressed()) { |
| 849 | mCommandQueue.cancelPreloadRecentApps(); |
| 850 | } |
| 851 | } |
| 852 | return false; |
| 853 | } |
| 854 | |
| 855 | private void onRecentsClick(View v) { |
| 856 | if (LatencyTracker.isEnabled(getContext())) { |
| 857 | LatencyTracker.getInstance(getContext()).onActionStart( |
| 858 | LatencyTracker.ACTION_TOGGLE_RECENTS); |
| 859 | } |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 860 | mStatusBar.awakenDreams(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 861 | mCommandQueue.toggleRecentApps(); |
| 862 | } |
| 863 | |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 864 | private boolean onLongPressBackHome(View v) { |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 865 | mNavigationBarView.onNavigationButtonLongPress(v); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 866 | return onLongPressNavigationButtons(v, R.id.back, R.id.home); |
| 867 | } |
| 868 | |
| 869 | private boolean onLongPressBackRecents(View v) { |
Matthew Ng | 2ea93b7 | 2018-03-14 19:43:18 +0000 | [diff] [blame] | 870 | mNavigationBarView.onNavigationButtonLongPress(v); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 871 | return onLongPressNavigationButtons(v, R.id.back, R.id.recent_apps); |
| 872 | } |
| 873 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 874 | /** |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 875 | * This handles long-press of both back and recents/home. Back is the common button with |
| 876 | * combination of recents if it is visible or home if recents is invisible. |
| 877 | * They are handled together to capture them both being long-pressed |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 878 | * at the same time to exit screen pinning (lock task). |
| 879 | * |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 880 | * When accessibility mode is on, only a long-press from recents/home |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 881 | * is required to exit. |
| 882 | * |
| 883 | * In all other circumstances we try to pass through long-press events |
| 884 | * for Back, so that apps can still use it. Which can be from two things. |
| 885 | * 1) Not currently in screen pinning (lock task). |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 886 | * 2) Back is long-pressed without recents/home. |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 887 | */ |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 888 | private boolean onLongPressNavigationButtons(View v, @IdRes int btnId1, @IdRes int btnId2) { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 889 | try { |
| 890 | boolean sendBackLongPress = false; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 891 | IActivityTaskManager activityManager = ActivityTaskManager.getService(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 892 | boolean touchExplorationEnabled = mAccessibilityManager.isTouchExplorationEnabled(); |
| 893 | boolean inLockTaskMode = activityManager.isInLockTaskMode(); |
| 894 | if (inLockTaskMode && !touchExplorationEnabled) { |
| 895 | long time = System.currentTimeMillis(); |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 896 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 897 | // If we recently long-pressed the other button then they were |
| 898 | // long-pressed 'together' |
| 899 | if ((time - mLastLockToAppLongPress) < LOCK_TO_APP_GESTURE_TOLERENCE) { |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 900 | activityManager.stopSystemLockTaskMode(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 901 | // When exiting refresh disabled flags. |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 902 | mNavigationBarView.updateNavButtonIcons(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 903 | return true; |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 904 | } else if (v.getId() == btnId1) { |
| 905 | ButtonDispatcher button = btnId2 == R.id.recent_apps |
| 906 | ? mNavigationBarView.getRecentsButton() |
| 907 | : mNavigationBarView.getHomeButton(); |
| 908 | if (!button.getCurrentView().isPressed()) { |
| 909 | // If we aren't pressing recents/home right now then they presses |
| 910 | // won't be together, so send the standard long-press action. |
| 911 | sendBackLongPress = true; |
| 912 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 913 | } |
| 914 | mLastLockToAppLongPress = time; |
| 915 | } else { |
| 916 | // If this is back still need to handle sending the long-press event. |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 917 | if (v.getId() == btnId1) { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 918 | sendBackLongPress = true; |
| 919 | } else if (touchExplorationEnabled && inLockTaskMode) { |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 920 | // When in accessibility mode a long press that is recents/home (not back) |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 921 | // should stop lock task. |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 922 | activityManager.stopSystemLockTaskMode(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 923 | // When exiting refresh disabled flags. |
Matthew Ng | d0a73e7 | 2018-03-02 15:16:03 -0800 | [diff] [blame] | 924 | mNavigationBarView.updateNavButtonIcons(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 925 | return true; |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 926 | } else if (v.getId() == btnId2) { |
| 927 | return btnId2 == R.id.recent_apps |
| 928 | ? onLongPressRecents() |
| 929 | : onHomeLongClick(mNavigationBarView.getHomeButton().getCurrentView()); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 930 | } |
| 931 | } |
| 932 | if (sendBackLongPress) { |
| 933 | KeyButtonView keyButtonView = (KeyButtonView) v; |
| 934 | keyButtonView.sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.FLAG_LONG_PRESS); |
| 935 | keyButtonView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED); |
| 936 | return true; |
| 937 | } |
| 938 | } catch (RemoteException e) { |
| 939 | Log.d(TAG, "Unable to reach activity manager", e); |
| 940 | } |
| 941 | return false; |
| 942 | } |
| 943 | |
| 944 | private boolean onLongPressRecents() { |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 945 | if (mRecents == null || !ActivityTaskManager.supportsMultiWindow(getContext()) |
Matthew Ng | 43db6d2 | 2017-06-27 15:29:39 -0700 | [diff] [blame] | 946 | || !mDivider.getView().getSnapAlgorithm().isSplitScreenFeasible() |
Winson Chung | 074c434 | 2018-03-26 17:27:19 -0700 | [diff] [blame] | 947 | || Recents.getConfiguration().isLowRamDevice |
| 948 | // If we are connected to the overview service, then disable the recents button |
| 949 | || mOverviewProxyService.getProxy() != null) { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 950 | return false; |
| 951 | } |
| 952 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 953 | return mStatusBar.toggleSplitScreenMode(MetricsEvent.ACTION_WINDOW_DOCK_LONGPRESS, |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 954 | MetricsEvent.ACTION_WINDOW_UNDOCK_LONGPRESS); |
| 955 | } |
| 956 | |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 957 | private void onAccessibilityClick(View v) { |
| 958 | mAccessibilityManager.notifyAccessibilityButtonClicked(); |
| 959 | } |
| 960 | |
| 961 | private boolean onAccessibilityLongClick(View v) { |
Casey Burkhardt | 5e8b980 | 2017-03-24 10:07:20 -0700 | [diff] [blame] | 962 | Intent intent = new Intent(AccessibilityManager.ACTION_CHOOSE_ACCESSIBILITY_BUTTON); |
| 963 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); |
Casey Burkhardt | 5d61440 | 2017-04-06 13:46:50 -0700 | [diff] [blame] | 964 | v.getContext().startActivityAsUser(intent, UserHandle.CURRENT); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 965 | return true; |
| 966 | } |
| 967 | |
Phil Weaver | db9a774 | 2017-04-18 08:15:06 -0700 | [diff] [blame] | 968 | private void updateAccessibilityServicesState(AccessibilityManager accessibilityManager) { |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 969 | int requestingServices = 0; |
| 970 | try { |
Casey Burkhardt | 5d61440 | 2017-04-06 13:46:50 -0700 | [diff] [blame] | 971 | if (Settings.Secure.getIntForUser(mContentResolver, |
| 972 | Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, |
| 973 | UserHandle.USER_CURRENT) == 1) { |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 974 | requestingServices++; |
| 975 | } |
| 976 | } catch (Settings.SettingNotFoundException e) { |
| 977 | } |
| 978 | |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 979 | boolean feedbackEnabled = false; |
Casey Burkhardt | 5d61440 | 2017-04-06 13:46:50 -0700 | [diff] [blame] | 980 | // AccessibilityManagerService resolves services for the current user since the local |
| 981 | // AccessibilityManager is created from a Context with the INTERACT_ACROSS_USERS permission |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 982 | final List<AccessibilityServiceInfo> services = |
Phil Weaver | db9a774 | 2017-04-18 08:15:06 -0700 | [diff] [blame] | 983 | accessibilityManager.getEnabledAccessibilityServiceList( |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 984 | AccessibilityServiceInfo.FEEDBACK_ALL_MASK); |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 985 | for (int i = services.size() - 1; i >= 0; --i) { |
| 986 | AccessibilityServiceInfo info = services.get(i); |
| 987 | if ((info.flags & AccessibilityServiceInfo.FLAG_REQUEST_ACCESSIBILITY_BUTTON) != 0) { |
| 988 | requestingServices++; |
| 989 | } |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 990 | |
| 991 | if (info.feedbackType != 0 && info.feedbackType != |
| 992 | AccessibilityServiceInfo.FEEDBACK_GENERIC) { |
| 993 | feedbackEnabled = true; |
| 994 | } |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 995 | } |
| 996 | |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 997 | mAccessibilityFeedbackEnabled = feedbackEnabled; |
| 998 | |
Casey Burkhardt | 048c2bc | 2016-12-08 16:09:20 -0800 | [diff] [blame] | 999 | final boolean showAccessibilityButton = requestingServices >= 1; |
| 1000 | final boolean targetSelection = requestingServices >= 2; |
| 1001 | mNavigationBarView.setAccessibilityButtonState(showAccessibilityButton, targetSelection); |
| 1002 | } |
| 1003 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 1004 | private void onRotateSuggestionClick(View v) { |
Mike Digman | c94759d | 2018-01-23 11:01:21 -0800 | [diff] [blame] | 1005 | mMetricsLogger.action(MetricsEvent.ACTION_ROTATION_SUGGESTION_ACCEPTED); |
Mike Digman | 5075264 | 2018-02-15 13:36:09 -0800 | [diff] [blame] | 1006 | incrementNumAcceptedRotationSuggestionsIfNeeded(); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 1007 | mRotationLockController.setRotationLockedAtAngle(true, mLastRotationSuggestion); |
| 1008 | } |
| 1009 | |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 1010 | private boolean onRotateSuggestionHover(View v, MotionEvent event) { |
| 1011 | final int action = event.getActionMasked(); |
| 1012 | mHoveringRotationSuggestion = (action == MotionEvent.ACTION_HOVER_ENTER) |
| 1013 | || (action == MotionEvent.ACTION_HOVER_MOVE); |
| 1014 | rescheduleRotationTimeout(true); |
| 1015 | return false; // Must return false so a11y hover events are dispatched correctly. |
| 1016 | } |
| 1017 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 1018 | // ----- Methods that StatusBar talks to (should be minimized) ----- |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1019 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1020 | public void setLightBarController(LightBarController lightBarController) { |
| 1021 | mLightBarController = lightBarController; |
| 1022 | mLightBarController.setNavigationBar(mNavigationBarView.getLightTransitionsController()); |
| 1023 | } |
| 1024 | |
| 1025 | public boolean isSemiTransparent() { |
| 1026 | return mNavigationBarMode == MODE_SEMI_TRANSPARENT; |
| 1027 | } |
| 1028 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1029 | public void disableAnimationsDuringHide(long delay) { |
| 1030 | mNavigationBarView.setLayoutTransitionsEnabled(false); |
| 1031 | mNavigationBarView.postDelayed(() -> mNavigationBarView.setLayoutTransitionsEnabled(true), |
| 1032 | delay + StackStateAnimator.ANIMATION_DURATION_GO_TO_FULL_SHADE); |
| 1033 | } |
| 1034 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1035 | public BarTransitions getBarTransitions() { |
| 1036 | return mNavigationBarView.getBarTransitions(); |
| 1037 | } |
| 1038 | |
| 1039 | public void checkNavBarModes() { |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 1040 | mStatusBar.checkBarMode(mNavigationBarMode, |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1041 | mNavigationBarWindowState, mNavigationBarView.getBarTransitions()); |
| 1042 | } |
| 1043 | |
| 1044 | public void finishBarAnimations() { |
| 1045 | mNavigationBarView.getBarTransitions().finishAnimations(); |
| 1046 | } |
| 1047 | |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 1048 | private final AccessibilityServicesStateChangeListener mAccessibilityListener = |
| 1049 | this::updateAccessibilityServicesState; |
| 1050 | |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 1051 | private class MagnificationContentObserver extends ContentObserver { |
| 1052 | |
| 1053 | public MagnificationContentObserver(Handler handler) { |
| 1054 | super(handler); |
| 1055 | } |
| 1056 | |
| 1057 | @Override |
| 1058 | public void onChange(boolean selfChange) { |
Phil Weaver | db9a774 | 2017-04-18 08:15:06 -0700 | [diff] [blame] | 1059 | NavigationBarFragment.this.updateAccessibilityServicesState(mAccessibilityManager); |
Casey Burkhardt | 74922c6 | 2017-02-13 12:43:16 -0800 | [diff] [blame] | 1060 | } |
| 1061 | } |
| 1062 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1063 | private final Stub mRotationWatcher = new Stub() { |
| 1064 | @Override |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 1065 | public void onRotationChanged(final int rotation) throws RemoteException { |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1066 | // We need this to be scheduled as early as possible to beat the redrawing of |
| 1067 | // window in response to the orientation change. |
| 1068 | Handler h = getView().getHandler(); |
| 1069 | Message msg = Message.obtain(h, () -> { |
Mike Digman | 85ff7fa | 2018-01-23 14:59:52 -0800 | [diff] [blame] | 1070 | |
| 1071 | // If the screen rotation changes while locked, potentially update lock to flow with |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 1072 | // new screen rotation and hide any showing suggestions. |
| 1073 | if (mRotationLockController.isRotationLocked()) { |
Mike Digman | 85ff7fa | 2018-01-23 14:59:52 -0800 | [diff] [blame] | 1074 | if (shouldOverrideUserLockPrefs(rotation)) { |
| 1075 | mRotationLockController.setRotationLockedAtAngle(true, rotation); |
| 1076 | } |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 1077 | setRotateSuggestionButtonState(false, true); |
Mike Digman | 9040295 | 2018-01-22 16:05:51 -0800 | [diff] [blame] | 1078 | } |
| 1079 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1080 | if (mNavigationBarView != null |
| 1081 | && mNavigationBarView.needsReorient(rotation)) { |
| 1082 | repositionNavigationBar(); |
| 1083 | } |
| 1084 | }); |
| 1085 | msg.setAsynchronous(true); |
| 1086 | h.sendMessageAtFrontOfQueue(msg); |
| 1087 | } |
Mike Digman | 85ff7fa | 2018-01-23 14:59:52 -0800 | [diff] [blame] | 1088 | |
| 1089 | private boolean shouldOverrideUserLockPrefs(final int rotation) { |
Mike Digman | ab65025 | 2018-03-06 11:01:41 -0800 | [diff] [blame] | 1090 | // Only override user prefs when returning to the natural rotation (normally portrait). |
Mike Digman | 85ff7fa | 2018-01-23 14:59:52 -0800 | [diff] [blame] | 1091 | // Don't let apps that force landscape or 180 alter user lock. |
Mike Digman | ab65025 | 2018-03-06 11:01:41 -0800 | [diff] [blame] | 1092 | return rotation == NATURAL_ROTATION; |
Mike Digman | 85ff7fa | 2018-01-23 14:59:52 -0800 | [diff] [blame] | 1093 | } |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1094 | }; |
| 1095 | |
| 1096 | private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 1097 | @Override |
| 1098 | public void onReceive(Context context, Intent intent) { |
| 1099 | String action = intent.getAction(); |
Siarhei Vishniakou | d002a0a | 2017-06-05 22:44:37 +0100 | [diff] [blame] | 1100 | if (Intent.ACTION_SCREEN_OFF.equals(action) |
| 1101 | || Intent.ACTION_SCREEN_ON.equals(action)) { |
| 1102 | notifyNavigationBarScreenOn(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1103 | } |
Phil Weaver | a858c5f | 2018-04-26 13:27:30 -0700 | [diff] [blame] | 1104 | if (Intent.ACTION_USER_SWITCHED.equals(action)) { |
| 1105 | // The accessibility settings may be different for the new user |
| 1106 | updateAccessibilityServicesState(mAccessibilityManager); |
| 1107 | }; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1108 | } |
| 1109 | }; |
| 1110 | |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 1111 | class TaskStackListenerImpl extends SysUiTaskStackChangeListener { |
| 1112 | // Invalidate any rotation suggestion on task change or activity orientation change |
| 1113 | // Note: all callbacks happen on main thread |
| 1114 | |
| 1115 | @Override |
| 1116 | public void onTaskStackChanged() { |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 1117 | setRotateSuggestionButtonState(false); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | @Override |
| 1121 | public void onTaskRemoved(int taskId) { |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 1122 | setRotateSuggestionButtonState(false); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 1123 | } |
| 1124 | |
| 1125 | @Override |
| 1126 | public void onTaskMovedToFront(int taskId) { |
Mike Digman | 1e28a5a | 2018-02-14 10:49:19 -0800 | [diff] [blame] | 1127 | setRotateSuggestionButtonState(false); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | @Override |
| 1131 | public void onActivityRequestedOrientationChanged(int taskId, int requestedOrientation) { |
Mike Digman | 85a9bea | 2018-02-23 15:08:53 -0800 | [diff] [blame] | 1132 | // Only hide the icon if the top task changes its requestedOrientation |
| 1133 | // Launcher can alter its requestedOrientation while it's not on top, don't hide on this |
Mike Digman | 121b11f | 2018-04-04 12:45:24 -0700 | [diff] [blame] | 1134 | Optional.ofNullable(ActivityManagerWrapper.getInstance()) |
| 1135 | .map(ActivityManagerWrapper::getRunningTask) |
| 1136 | .ifPresent(a -> { |
| 1137 | if (a.id == taskId) setRotateSuggestionButtonState(false); |
| 1138 | }); |
Mike Digman | 7d09277 | 2018-01-11 12:10:32 -0800 | [diff] [blame] | 1139 | } |
| 1140 | } |
| 1141 | |
Mike Digman | 5075264 | 2018-02-15 13:36:09 -0800 | [diff] [blame] | 1142 | private class ViewRippler { |
| 1143 | private static final int RIPPLE_OFFSET_MS = 50; |
| 1144 | private static final int RIPPLE_INTERVAL_MS = 2000; |
| 1145 | private View mRoot; |
| 1146 | |
| 1147 | public void start(View root) { |
| 1148 | stop(); // Stop any pending ripple animations |
| 1149 | |
| 1150 | mRoot = root; |
| 1151 | |
| 1152 | // Schedule pending ripples, offset the 1st to avoid problems with visibility change |
| 1153 | mRoot.postOnAnimationDelayed(mRipple, RIPPLE_OFFSET_MS); |
| 1154 | mRoot.postOnAnimationDelayed(mRipple, RIPPLE_INTERVAL_MS); |
| 1155 | mRoot.postOnAnimationDelayed(mRipple, 2*RIPPLE_INTERVAL_MS); |
Mike Digman | c038c32 | 2018-05-24 11:06:05 -0700 | [diff] [blame] | 1156 | mRoot.postOnAnimationDelayed(mRipple, 3*RIPPLE_INTERVAL_MS); |
| 1157 | mRoot.postOnAnimationDelayed(mRipple, 4*RIPPLE_INTERVAL_MS); |
Mike Digman | 5075264 | 2018-02-15 13:36:09 -0800 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | public void stop() { |
| 1161 | if (mRoot != null) mRoot.removeCallbacks(mRipple); |
| 1162 | } |
| 1163 | |
| 1164 | private final Runnable mRipple = new Runnable() { |
| 1165 | @Override |
| 1166 | public void run() { // Cause the ripple to fire via false presses |
Mike Digman | f4c9899 | 2018-04-25 11:25:59 -0700 | [diff] [blame] | 1167 | if (!mRoot.isAttachedToWindow()) return; |
Mike Digman | 5075264 | 2018-02-15 13:36:09 -0800 | [diff] [blame] | 1168 | mRoot.setPressed(true); |
| 1169 | mRoot.setPressed(false); |
| 1170 | } |
| 1171 | }; |
| 1172 | } |
| 1173 | |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1174 | public static View create(Context context, FragmentListener listener) { |
| 1175 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 1176 | LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, |
| 1177 | WindowManager.LayoutParams.TYPE_NAVIGATION_BAR, |
| 1178 | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING |
| 1179 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1180 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
| 1181 | | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
| 1182 | | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH |
| 1183 | | WindowManager.LayoutParams.FLAG_SLIPPERY, |
| 1184 | PixelFormat.TRANSLUCENT); |
| 1185 | lp.token = new Binder(); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1186 | lp.setTitle("NavigationBar"); |
Phil Weaver | 8583ae8 | 2018-02-13 11:01:24 -0800 | [diff] [blame] | 1187 | lp.accessibilityTitle = context.getString(R.string.nav_bar); |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 1188 | lp.windowAnimations = 0; |
| 1189 | |
| 1190 | View navigationBarView = LayoutInflater.from(context).inflate( |
| 1191 | R.layout.navigation_bar_window, null); |
| 1192 | |
| 1193 | if (DEBUG) Log.v(TAG, "addNavigationBar: about to add " + navigationBarView); |
| 1194 | if (navigationBarView == null) return null; |
| 1195 | |
| 1196 | context.getSystemService(WindowManager.class).addView(navigationBarView, lp); |
| 1197 | FragmentHostManager fragmentHost = FragmentHostManager.get(navigationBarView); |
| 1198 | NavigationBarFragment fragment = new NavigationBarFragment(); |
| 1199 | fragmentHost.getFragmentManager().beginTransaction() |
| 1200 | .replace(R.id.navigation_bar_frame, fragment, TAG) |
| 1201 | .commit(); |
| 1202 | fragmentHost.addTagListener(TAG, listener); |
| 1203 | return navigationBarView; |
| 1204 | } |
| 1205 | } |