Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 1 | /* |
Brad Stenning | 8d1a51c | 2018-11-20 17:34:16 -0800 | [diff] [blame] | 2 | * Copyright (C) 2018 The Android Open Source Project |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.statusbar.car; |
| 18 | |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 19 | import android.animation.Animator; |
| 20 | import android.animation.AnimatorListenerAdapter; |
| 21 | import android.animation.ValueAnimator; |
Matthew Ng | 9438065 | 2019-04-08 13:43:07 -0700 | [diff] [blame] | 22 | import android.annotation.Nullable; |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 23 | import android.app.ActivityManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 24 | import android.app.ActivityTaskManager; |
Brad Stenning | d3ede64 | 2019-04-23 21:19:27 -0700 | [diff] [blame] | 25 | import android.car.Car; |
jovanak | edba98c | 2018-09-14 15:46:24 -0700 | [diff] [blame] | 26 | import android.car.drivingstate.CarDrivingStateEvent; |
Brad Stenning | d3ede64 | 2019-04-23 21:19:27 -0700 | [diff] [blame] | 27 | import android.car.drivingstate.CarUxRestrictionsManager; |
Jonathan Koo | 007ff07 | 2019-05-10 09:24:08 -0700 | [diff] [blame] | 28 | import android.car.hardware.power.CarPowerManager.CarPowerStateListener; |
Brad Stenning | 2ccc2a4 | 2019-04-15 10:17:01 -0700 | [diff] [blame] | 29 | import android.content.Context; |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 30 | import android.graphics.PixelFormat; |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 31 | import android.graphics.Rect; |
Anthony Chen | e658cc2 | 2017-04-27 11:17:35 -0700 | [diff] [blame] | 32 | import android.graphics.drawable.Drawable; |
Heemin Seog | 28097c4 | 2019-08-15 13:18:41 -0700 | [diff] [blame] | 33 | import android.inputmethodservice.InputMethodService; |
| 34 | import android.os.IBinder; |
Rakesh Iyer | 74ebabe | 2016-03-11 10:10:43 -0800 | [diff] [blame] | 35 | import android.util.Log; |
Heemin Seog | 28097c4 | 2019-08-15 13:18:41 -0700 | [diff] [blame] | 36 | import android.view.Display; |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 37 | import android.view.GestureDetector; |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 38 | import android.view.Gravity; |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 39 | import android.view.MotionEvent; |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 40 | import android.view.View; |
Anthony Chen | 0801a5c | 2017-03-22 09:54:37 -0700 | [diff] [blame] | 41 | import android.view.ViewGroup; |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 42 | import android.view.ViewGroup.LayoutParams; |
Priyank Singh | b9ab052 | 2019-05-03 15:36:25 -0700 | [diff] [blame] | 43 | import android.view.ViewTreeObserver; |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 44 | import android.view.WindowManager; |
Anthony Chen | e658cc2 | 2017-04-27 11:17:35 -0700 | [diff] [blame] | 45 | |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 46 | import androidx.annotation.NonNull; |
| 47 | import androidx.recyclerview.widget.RecyclerView; |
| 48 | |
Brad Stenning | 2ccc2a4 | 2019-04-15 10:17:01 -0700 | [diff] [blame] | 49 | import com.android.car.notification.CarHeadsUpNotificationManager; |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 50 | import com.android.car.notification.CarNotificationListener; |
| 51 | import com.android.car.notification.CarNotificationView; |
| 52 | import com.android.car.notification.CarUxRestrictionManagerWrapper; |
Brad Stenning | 2ccc2a4 | 2019-04-15 10:17:01 -0700 | [diff] [blame] | 53 | import com.android.car.notification.HeadsUpEntry; |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 54 | import com.android.car.notification.NotificationClickHandlerFactory; |
Brad Stenning | 2ccc2a4 | 2019-04-15 10:17:01 -0700 | [diff] [blame] | 55 | import com.android.car.notification.NotificationDataManager; |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 56 | import com.android.car.notification.NotificationViewController; |
| 57 | import com.android.car.notification.PreprocessingManager; |
Matthew Ng | 9438065 | 2019-04-08 13:43:07 -0700 | [diff] [blame] | 58 | import com.android.internal.statusbar.RegisterStatusBarResult; |
Winson Chung | 2db3557 | 2017-10-09 15:08:30 -0700 | [diff] [blame] | 59 | import com.android.keyguard.KeyguardUpdateMonitor; |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 60 | import com.android.systemui.BatteryMeterView; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 61 | import com.android.systemui.CarSystemUIFactory; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 62 | import com.android.systemui.Dependency; |
Winson Chung | 2db3557 | 2017-10-09 15:08:30 -0700 | [diff] [blame] | 63 | import com.android.systemui.Prefs; |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 64 | import com.android.systemui.R; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 65 | import com.android.systemui.SystemUIFactory; |
Winson Chung | 2db3557 | 2017-10-09 15:08:30 -0700 | [diff] [blame] | 66 | import com.android.systemui.classifier.FalsingLog; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 67 | import com.android.systemui.fragments.FragmentHostManager; |
jovanak | 622def2 | 2019-06-11 11:51:54 -0700 | [diff] [blame] | 68 | import com.android.systemui.keyguard.ScreenLifecycle; |
Dave Mankoff | 781ef7e | 2019-06-28 16:33:25 -0400 | [diff] [blame] | 69 | import com.android.systemui.plugins.FalsingManager; |
Brad Stenning | 8d1a51c | 2018-11-20 17:34:16 -0800 | [diff] [blame] | 70 | import com.android.systemui.plugins.qs.QS; |
| 71 | import com.android.systemui.qs.car.CarQSFragment; |
Winson Chung | b05b398 | 2017-11-01 18:02:43 -0700 | [diff] [blame] | 72 | import com.android.systemui.shared.system.ActivityManagerWrapper; |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 73 | import com.android.systemui.shared.system.TaskStackChangeListener; |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 74 | import com.android.systemui.statusbar.FlingAnimationUtils; |
Rakesh Iyer | 2790a37 | 2016-01-22 15:33:39 -0800 | [diff] [blame] | 75 | import com.android.systemui.statusbar.StatusBarState; |
Brad Stenning | 38b46f8 | 2018-03-27 13:57:29 -0700 | [diff] [blame] | 76 | import com.android.systemui.statusbar.car.hvac.HvacController; |
Brad Stenning | f084d88 | 2018-08-08 13:34:21 -0700 | [diff] [blame] | 77 | import com.android.systemui.statusbar.car.hvac.TemperatureView; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 78 | import com.android.systemui.statusbar.phone.CollapsedStatusBarFragment; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 79 | import com.android.systemui.statusbar.phone.StatusBar; |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 80 | import com.android.systemui.statusbar.policy.BatteryController; |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 81 | import com.android.systemui.statusbar.policy.DeviceProvisionedController; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 82 | import com.android.systemui.statusbar.policy.UserSwitcherController; |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 83 | |
Qiming Shi | b9dfb92 | 2017-04-13 16:23:18 +0800 | [diff] [blame] | 84 | import java.io.FileDescriptor; |
| 85 | import java.io.PrintWriter; |
| 86 | import java.util.Map; |
davidln | 5473915 | 2018-07-02 13:25:44 -0700 | [diff] [blame] | 87 | |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 88 | /** |
| 89 | * A status bar (and navigation bar) tailored for the automotive use case. |
| 90 | */ |
Heemin Seog | 28097c4 | 2019-08-15 13:18:41 -0700 | [diff] [blame] | 91 | public class CarStatusBar extends StatusBar implements CarBatteryController.BatteryViewHandler { |
Rakesh Iyer | 74ebabe | 2016-03-11 10:10:43 -0800 | [diff] [blame] | 92 | private static final String TAG = "CarStatusBar"; |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 93 | // used to calculate how fast to open or close the window |
| 94 | private static final float DEFAULT_FLING_VELOCITY = 0; |
| 95 | // max time a fling animation takes |
| 96 | private static final float FLING_ANIMATION_MAX_TIME = 0.5f; |
| 97 | // acceleration rate for the fling animation |
| 98 | private static final float FLING_SPEED_UP_FACTOR = 0.6f; |
| 99 | |
| 100 | private float mOpeningVelocity = DEFAULT_FLING_VELOCITY; |
| 101 | private float mClosingVelocity = DEFAULT_FLING_VELOCITY; |
Rakesh Iyer | 74ebabe | 2016-03-11 10:10:43 -0800 | [diff] [blame] | 102 | |
JianYang Liu | b923d1e | 2019-10-24 17:19:44 -0700 | [diff] [blame] | 103 | private float mBackgroundAlphaDiff; |
| 104 | private float mInitialBackgroundAlpha; |
| 105 | |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 106 | private TaskStackListenerImpl mTaskStackListener; |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 107 | |
Rakesh Iyer | 2790a37 | 2016-01-22 15:33:39 -0800 | [diff] [blame] | 108 | private FullscreenUserSwitcher mFullscreenUserSwitcher; |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 109 | |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 110 | private CarBatteryController mCarBatteryController; |
| 111 | private BatteryMeterView mBatteryMeterView; |
Anthony Chen | e658cc2 | 2017-04-27 11:17:35 -0700 | [diff] [blame] | 112 | private Drawable mNotificationPanelBackground; |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 113 | |
Heemin Seog | 1a13af5 | 2019-10-03 16:15:50 -0700 | [diff] [blame] | 114 | private ViewGroup mTopNavigationBarContainer; |
Scott Randolph | f408582 | 2017-06-27 15:23:01 -0700 | [diff] [blame] | 115 | private ViewGroup mNavigationBarWindow; |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 116 | private ViewGroup mLeftNavigationBarWindow; |
| 117 | private ViewGroup mRightNavigationBarWindow; |
Heemin Seog | 1a13af5 | 2019-10-03 16:15:50 -0700 | [diff] [blame] | 118 | private CarNavigationBarView mTopNavigationBarView; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 119 | private CarNavigationBarView mNavigationBarView; |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 120 | private CarNavigationBarView mLeftNavigationBarView; |
| 121 | private CarNavigationBarView mRightNavigationBarView; |
Anthony Chen | 1c59e9f | 2016-04-11 11:05:48 -0700 | [diff] [blame] | 122 | |
Qiming Shi | b9dfb92 | 2017-04-13 16:23:18 +0800 | [diff] [blame] | 123 | private final Object mQueueLock = new Object(); |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 124 | private boolean mShowLeft; |
| 125 | private boolean mShowRight; |
| 126 | private boolean mShowBottom; |
| 127 | private CarFacetButtonController mCarFacetButtonController; |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 128 | private ActivityManagerWrapper mActivityManagerWrapper; |
| 129 | private DeviceProvisionedController mDeviceProvisionedController; |
Heemin Seog | 1a13af5 | 2019-10-03 16:15:50 -0700 | [diff] [blame] | 130 | private boolean mDeviceIsSetUpForUser = true; |
Brad Stenning | f084d88 | 2018-08-08 13:34:21 -0700 | [diff] [blame] | 131 | private HvacController mHvacController; |
jovanak | edba98c | 2018-09-14 15:46:24 -0700 | [diff] [blame] | 132 | private DrivingStateHelper mDrivingStateHelper; |
Jonathan Koo | 007ff07 | 2019-05-10 09:24:08 -0700 | [diff] [blame] | 133 | private PowerManagerHelper mPowerManagerHelper; |
| 134 | private FlingAnimationUtils mFlingAnimationUtils; |
jovanak | edba98c | 2018-09-14 15:46:24 -0700 | [diff] [blame] | 135 | private SwitchToGuestTimer mSwitchToGuestTimer; |
Jonathan Koo | 007ff07 | 2019-05-10 09:24:08 -0700 | [diff] [blame] | 136 | private NotificationDataManager mNotificationDataManager; |
| 137 | private NotificationClickHandlerFactory mNotificationClickHandlerFactory; |
jovanak | 622def2 | 2019-06-11 11:51:54 -0700 | [diff] [blame] | 138 | private ScreenLifecycle mScreenLifecycle; |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 139 | |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 140 | // The container for the notifications. |
| 141 | private CarNotificationView mNotificationView; |
| 142 | private RecyclerView mNotificationList; |
Priyank Singh | 647f9e6 | 2019-05-16 15:19:53 -0700 | [diff] [blame] | 143 | // The handler bar view at the bottom of notification shade. |
| 144 | private View mHandleBar; |
Adora Zhang | daea911 | 2019-04-11 17:47:40 -0700 | [diff] [blame] | 145 | // The controller for the notification view. |
| 146 | private NotificationViewController mNotificationViewController; |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 147 | // The state of if the notification list is currently showing the bottom. |
| 148 | private boolean mNotificationListAtBottom; |
| 149 | // Was the notification list at the bottom when the user first touched the screen |
| 150 | private boolean mNotificationListAtBottomAtTimeOfTouch; |
Heemin Seog | 1a13af5 | 2019-10-03 16:15:50 -0700 | [diff] [blame] | 151 | // To be attached to the top navigation bar (i.e. status bar) to pull down the notification |
| 152 | // panel. |
| 153 | private View.OnTouchListener mTopNavBarNotificationTouchListener; |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 154 | // To be attached to the navigation bars such that they can close the notification panel if |
| 155 | // it's open. |
| 156 | private View.OnTouchListener mNavBarNotificationTouchListener; |
| 157 | |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 158 | // Percentage from top of the screen after which the notification shade will open. This value |
| 159 | // will be used while opening the notification shade. |
| 160 | private int mSettleOpenPercentage; |
| 161 | // Percentage from top of the screen below which the notification shade will close. This |
| 162 | // value will be used while closing the notification shade. |
| 163 | private int mSettleClosePercentage; |
| 164 | // Percentage of notification shade open from top of the screen. |
| 165 | private int mPercentageFromBottom; |
| 166 | // If notification shade is animation to close or to open. |
| 167 | private boolean mIsNotificationAnimating; |
| 168 | |
| 169 | // Tracks when the notification shade is being scrolled. This refers to the glass pane being |
| 170 | // scrolled not the recycler view. |
| 171 | private boolean mIsTracking; |
| 172 | private float mFirstTouchDownOnGlassPane; |
| 173 | |
| 174 | // If the notification card inside the recycler view is being swiped. |
| 175 | private boolean mIsNotificationCardSwiping; |
| 176 | // If notification shade is being swiped vertically to close. |
| 177 | private boolean mIsSwipingVerticallyToClose; |
Priyank Singh | 8bd920f | 2019-06-04 15:21:46 -0700 | [diff] [blame] | 178 | // Whether heads-up notifications should be shown when shade is open. |
| 179 | private boolean mEnableHeadsUpNotificationWhenNotificationShadeOpen; |
Heemin Seog | 28097c4 | 2019-08-15 13:18:41 -0700 | [diff] [blame] | 180 | // If the nav bar should be hidden when the soft keyboard is visible. |
| 181 | private boolean mHideNavBarForKeyboard; |
| 182 | private boolean mBottomNavBarVisible; |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 183 | |
Keun young Park | 9e395bb | 2019-10-11 20:00:22 -0700 | [diff] [blame] | 184 | private CarUxRestrictionManagerWrapper mCarUxRestrictionManagerWrapper; |
| 185 | |
Jonathan Koo | 007ff07 | 2019-05-10 09:24:08 -0700 | [diff] [blame] | 186 | private final CarPowerStateListener mCarPowerStateListener = |
| 187 | (int state) -> { |
| 188 | // When the car powers on, clear all notifications and mute/unread states. |
| 189 | Log.d(TAG, "New car power state: " + state); |
| 190 | if (state == CarPowerStateListener.ON) { |
| 191 | if (mNotificationClickHandlerFactory != null) { |
| 192 | mNotificationClickHandlerFactory.clearAllNotifications(); |
| 193 | } |
| 194 | if (mNotificationDataManager != null) { |
| 195 | mNotificationDataManager.clearAll(); |
| 196 | } |
| 197 | } |
| 198 | }; |
| 199 | |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 200 | @Override |
| 201 | public void start() { |
Brad Stenning | eb6051c | 2019-02-27 13:46:11 -0800 | [diff] [blame] | 202 | // get the provisioned state before calling the parent class since it's that flow that |
| 203 | // builds the nav bar |
| 204 | mDeviceProvisionedController = Dependency.get(DeviceProvisionedController.class); |
Heemin Seog | 1a13af5 | 2019-10-03 16:15:50 -0700 | [diff] [blame] | 205 | mDeviceIsSetUpForUser = mDeviceProvisionedController.isCurrentUserSetup(); |
Heemin Seog | 28097c4 | 2019-08-15 13:18:41 -0700 | [diff] [blame] | 206 | |
| 207 | // Keyboard related setup, before nav bars are created. |
| 208 | mHideNavBarForKeyboard = mContext.getResources().getBoolean( |
| 209 | com.android.internal.R.bool.config_automotiveHideNavBarForKeyboard); |
| 210 | mBottomNavBarVisible = false; |
| 211 | |
jovanak | 504e753 | 2019-08-19 16:32:50 -0700 | [diff] [blame] | 212 | // Need to initialize screen lifecycle before calling super.start - before switcher is |
| 213 | // created. |
| 214 | mScreenLifecycle = Dependency.get(ScreenLifecycle.class); |
| 215 | mScreenLifecycle.addObserver(mScreenObserver); |
| 216 | |
Heemin Seog | 1a13af5 | 2019-10-03 16:15:50 -0700 | [diff] [blame] | 217 | // Need to initialize HVAC controller before calling super.start - before system bars are |
| 218 | // created. |
| 219 | mHvacController = new HvacController(mContext); |
| 220 | |
JianYang Liu | b923d1e | 2019-10-24 17:19:44 -0700 | [diff] [blame] | 221 | // Notification bar related setup. |
| 222 | mInitialBackgroundAlpha = (float) mContext.getResources().getInteger( |
| 223 | R.integer.config_initialNotificationBackgroundAlpha) / 100; |
| 224 | if (mInitialBackgroundAlpha < 0 || mInitialBackgroundAlpha > 100) { |
| 225 | throw new RuntimeException( |
| 226 | "Unable to setup notification bar due to incorrect initial background alpha" |
| 227 | + " percentage"); |
| 228 | } |
| 229 | float finalBackgroundAlpha = Math.max( |
| 230 | mInitialBackgroundAlpha, |
| 231 | (float) mContext.getResources().getInteger( |
| 232 | R.integer.config_finalNotificationBackgroundAlpha) / 100); |
| 233 | if (finalBackgroundAlpha < 0 || finalBackgroundAlpha > 100) { |
| 234 | throw new RuntimeException( |
| 235 | "Unable to setup notification bar due to incorrect final background alpha" |
| 236 | + " percentage"); |
| 237 | } |
| 238 | mBackgroundAlphaDiff = finalBackgroundAlpha - mInitialBackgroundAlpha; |
| 239 | |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 240 | super.start(); |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 241 | mTaskStackListener = new TaskStackListenerImpl(); |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 242 | mActivityManagerWrapper = ActivityManagerWrapper.getInstance(); |
| 243 | mActivityManagerWrapper.registerTaskStackListener(mTaskStackListener); |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 244 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 245 | mNotificationPanel.setScrollingEnabled(true); |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 246 | mSettleOpenPercentage = mContext.getResources().getInteger( |
| 247 | R.integer.notification_settle_open_percentage); |
| 248 | mSettleClosePercentage = mContext.getResources().getInteger( |
| 249 | R.integer.notification_settle_close_percentage); |
Jonathan Koo | 007ff07 | 2019-05-10 09:24:08 -0700 | [diff] [blame] | 250 | mFlingAnimationUtils = new FlingAnimationUtils(mContext, |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 251 | FLING_ANIMATION_MAX_TIME, FLING_SPEED_UP_FACTOR); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 252 | |
Rakesh Iyer | 545e47d | 2017-01-23 18:10:21 -0800 | [diff] [blame] | 253 | createBatteryController(); |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 254 | mCarBatteryController.startListening(); |
Brad Stenning | 38b46f8 | 2018-03-27 13:57:29 -0700 | [diff] [blame] | 255 | |
Brad Stenning | f084d88 | 2018-08-08 13:34:21 -0700 | [diff] [blame] | 256 | mHvacController.connectToCarService(); |
davidln | 5473915 | 2018-07-02 13:25:44 -0700 | [diff] [blame] | 257 | |
Heemin Seog | 1a13af5 | 2019-10-03 16:15:50 -0700 | [diff] [blame] | 258 | mDeviceProvisionedController.addCallback( |
| 259 | new DeviceProvisionedController.DeviceProvisionedListener() { |
| 260 | @Override |
| 261 | public void onUserSetupChanged() { |
| 262 | mHandler.post(() -> restartNavBarsIfNecessary()); |
| 263 | } |
| 264 | |
| 265 | @Override |
| 266 | public void onUserSwitched() { |
| 267 | mHandler.post(() -> restartNavBarsIfNecessary()); |
| 268 | } |
| 269 | }); |
jovanak | edba98c | 2018-09-14 15:46:24 -0700 | [diff] [blame] | 270 | |
Keun young Park | 9e395bb | 2019-10-11 20:00:22 -0700 | [diff] [blame] | 271 | // Used by onDrivingStateChanged and it can be called inside |
| 272 | // DrivingStateHelper.connectToCarService() |
| 273 | mSwitchToGuestTimer = new SwitchToGuestTimer(mContext); |
| 274 | |
jovanak | edba98c | 2018-09-14 15:46:24 -0700 | [diff] [blame] | 275 | // Register a listener for driving state changes. |
| 276 | mDrivingStateHelper = new DrivingStateHelper(mContext, this::onDrivingStateChanged); |
| 277 | mDrivingStateHelper.connectToCarService(); |
| 278 | |
Jonathan Koo | 007ff07 | 2019-05-10 09:24:08 -0700 | [diff] [blame] | 279 | mPowerManagerHelper = new PowerManagerHelper(mContext, mCarPowerStateListener); |
| 280 | mPowerManagerHelper.connectToCarService(); |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Heemin Seog | 1a13af5 | 2019-10-03 16:15:50 -0700 | [diff] [blame] | 283 | private void restartNavBarsIfNecessary() { |
| 284 | boolean currentUserSetup = mDeviceProvisionedController.isCurrentUserSetup(); |
| 285 | if (mDeviceIsSetUpForUser != currentUserSetup) { |
| 286 | mDeviceIsSetUpForUser = currentUserSetup; |
| 287 | restartNavBars(); |
| 288 | } |
| 289 | } |
| 290 | |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 291 | /** |
| 292 | * Remove all content from navbars and rebuild them. Used to allow for different nav bars |
Guobin Zhang | eef0e0c | 2019-02-01 11:54:24 -0800 | [diff] [blame] | 293 | * before and after the device is provisioned. . Also for change of density and font size. |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 294 | */ |
| 295 | private void restartNavBars() { |
Brad Stenning | f084d88 | 2018-08-08 13:34:21 -0700 | [diff] [blame] | 296 | // remove and reattach all hvac components such that we don't keep a reference to unused |
| 297 | // ui elements |
| 298 | mHvacController.removeAllComponents(); |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 299 | mCarFacetButtonController.removeAll(); |
Heemin Seog | 1a13af5 | 2019-10-03 16:15:50 -0700 | [diff] [blame] | 300 | |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 301 | if (mNavigationBarWindow != null) { |
| 302 | mNavigationBarWindow.removeAllViews(); |
| 303 | mNavigationBarView = null; |
| 304 | } |
| 305 | |
| 306 | if (mLeftNavigationBarWindow != null) { |
| 307 | mLeftNavigationBarWindow.removeAllViews(); |
| 308 | mLeftNavigationBarView = null; |
| 309 | } |
| 310 | |
| 311 | if (mRightNavigationBarWindow != null) { |
| 312 | mRightNavigationBarWindow.removeAllViews(); |
| 313 | mRightNavigationBarView = null; |
| 314 | } |
Brad Stenning | f084d88 | 2018-08-08 13:34:21 -0700 | [diff] [blame] | 315 | |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 316 | buildNavBarContent(); |
Brad Stenning | 7522164 | 2019-03-13 07:33:24 -0700 | [diff] [blame] | 317 | // If the UI was rebuilt (day/night change) while the keyguard was up we need to |
| 318 | // correctly respect that state. |
| 319 | if (mIsKeyguard) { |
| 320 | updateNavBarForKeyguardContent(); |
| 321 | } |
Brad Stenning | 4534f44 | 2019-04-01 21:43:32 -0700 | [diff] [blame] | 322 | // CarFacetButtonController was reset therefore we need to re-add the status bar elements |
| 323 | // to the controller. |
| 324 | mCarFacetButtonController.addAllFacetButtons(mStatusBarWindow); |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 325 | } |
| 326 | |
Brad Stenning | f084d88 | 2018-08-08 13:34:21 -0700 | [diff] [blame] | 327 | private void addTemperatureViewToController(View v) { |
| 328 | if (v instanceof TemperatureView) { |
Brad Stenning | f084d88 | 2018-08-08 13:34:21 -0700 | [diff] [blame] | 329 | mHvacController.addHvacTextView((TemperatureView) v); |
| 330 | } else if (v instanceof ViewGroup) { |
| 331 | ViewGroup viewGroup = (ViewGroup) v; |
| 332 | for (int i = 0; i < viewGroup.getChildCount(); i++) { |
| 333 | addTemperatureViewToController(viewGroup.getChildAt(i)); |
| 334 | } |
| 335 | } |
| 336 | } |
| 337 | |
Brad Stenning | 7e41181 | 2018-04-13 22:52:39 -0700 | [diff] [blame] | 338 | /** |
| 339 | * Allows for showing or hiding just the navigation bars. This is indented to be used when |
| 340 | * the full screen user selector is shown. |
| 341 | */ |
davidln | 5473915 | 2018-07-02 13:25:44 -0700 | [diff] [blame] | 342 | void setNavBarVisibility(@View.Visibility int visibility) { |
Brad Stenning | 7e41181 | 2018-04-13 22:52:39 -0700 | [diff] [blame] | 343 | if (mNavigationBarWindow != null) { |
| 344 | mNavigationBarWindow.setVisibility(visibility); |
| 345 | } |
| 346 | if (mLeftNavigationBarWindow != null) { |
| 347 | mLeftNavigationBarWindow.setVisibility(visibility); |
| 348 | } |
| 349 | if (mRightNavigationBarWindow != null) { |
| 350 | mRightNavigationBarWindow.setVisibility(visibility); |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | |
| 355 | @Override |
| 356 | public boolean hideKeyguard() { |
| 357 | boolean result = super.hideKeyguard(); |
| 358 | if (mNavigationBarView != null) { |
| 359 | mNavigationBarView.hideKeyguardButtons(); |
| 360 | } |
| 361 | if (mLeftNavigationBarView != null) { |
| 362 | mLeftNavigationBarView.hideKeyguardButtons(); |
| 363 | } |
| 364 | if (mRightNavigationBarView != null) { |
| 365 | mRightNavigationBarView.hideKeyguardButtons(); |
| 366 | } |
| 367 | return result; |
| 368 | } |
| 369 | |
Brad Stenning | 7e41181 | 2018-04-13 22:52:39 -0700 | [diff] [blame] | 370 | @Override |
| 371 | public void showKeyguard() { |
| 372 | super.showKeyguard(); |
Brad Stenning | 7522164 | 2019-03-13 07:33:24 -0700 | [diff] [blame] | 373 | updateNavBarForKeyguardContent(); |
| 374 | } |
| 375 | |
| 376 | /** |
| 377 | * Switch to the keyguard applicable content contained in the nav bars |
| 378 | */ |
| 379 | private void updateNavBarForKeyguardContent() { |
Brad Stenning | 7e41181 | 2018-04-13 22:52:39 -0700 | [diff] [blame] | 380 | if (mNavigationBarView != null) { |
| 381 | mNavigationBarView.showKeyguardButtons(); |
| 382 | } |
| 383 | if (mLeftNavigationBarView != null) { |
| 384 | mLeftNavigationBarView.showKeyguardButtons(); |
| 385 | } |
| 386 | if (mRightNavigationBarView != null) { |
| 387 | mRightNavigationBarView.showKeyguardButtons(); |
| 388 | } |
| 389 | } |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 390 | |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 391 | @Override |
Matthew Ng | 9438065 | 2019-04-08 13:43:07 -0700 | [diff] [blame] | 392 | protected void makeStatusBarView(@Nullable RegisterStatusBarResult result) { |
| 393 | super.makeStatusBarView(result); |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 394 | |
Guobin Zhang | eef0e0c | 2019-02-01 11:54:24 -0800 | [diff] [blame] | 395 | CarSystemUIFactory factory = SystemUIFactory.getInstance(); |
| 396 | mCarFacetButtonController = factory.getCarDependencyComponent() |
davidln | 1ceedb5 | 2019-05-30 14:25:01 -0700 | [diff] [blame] | 397 | .getCarFacetButtonController(); |
Anthony Chen | e658cc2 | 2017-04-27 11:17:35 -0700 | [diff] [blame] | 398 | mNotificationPanelBackground = getDefaultWallpaper(); |
| 399 | mScrimController.setScrimBehindDrawable(mNotificationPanelBackground); |
| 400 | |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 401 | FragmentHostManager manager = FragmentHostManager.get(mStatusBarWindow); |
| 402 | manager.addTagListener(CollapsedStatusBarFragment.TAG, (tag, fragment) -> { |
Anthony Chen | e658cc2 | 2017-04-27 11:17:35 -0700 | [diff] [blame] | 403 | mBatteryMeterView = fragment.getView().findViewById(R.id.battery); |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 404 | |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 405 | // By default, the BatteryMeterView should not be visible. It will be toggled |
| 406 | // when a device has connected by bluetooth. |
| 407 | mBatteryMeterView.setVisibility(View.GONE); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 408 | }); |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 409 | |
| 410 | connectNotificationsUI(); |
| 411 | } |
| 412 | |
| 413 | /** |
| 414 | * Attach the notification listeners and controllers to the UI as well as build all the |
| 415 | * touch listeners needed for opening and closing the notification panel |
| 416 | */ |
| 417 | private void connectNotificationsUI() { |
Heemin Seog | 1a13af5 | 2019-10-03 16:15:50 -0700 | [diff] [blame] | 418 | // Attached to the top navigation bar (i.e. status bar) to detect pull down of the |
| 419 | // notification shade. |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 420 | GestureDetector openGestureDetector = new GestureDetector(mContext, |
| 421 | new OpenNotificationGestureListener() { |
| 422 | @Override |
| 423 | protected void openNotification() { |
| 424 | animateExpandNotificationsPanel(); |
| 425 | } |
| 426 | }); |
| 427 | // Attached to the notification ui to detect close request of the notification shade. |
| 428 | GestureDetector closeGestureDetector = new GestureDetector(mContext, |
| 429 | new CloseNotificationGestureListener() { |
| 430 | @Override |
| 431 | protected void close() { |
Brad Stenning | 44d3907 | 2019-04-20 11:53:17 -0700 | [diff] [blame] | 432 | if (mPanelExpanded) { |
| 433 | animateCollapsePanels(); |
| 434 | } |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 435 | } |
| 436 | }); |
| 437 | // Attached to the NavBars to close the notification shade |
| 438 | GestureDetector navBarCloseNotificationGestureDetector = new GestureDetector(mContext, |
| 439 | new NavBarCloseNotificationGestureListener() { |
| 440 | @Override |
| 441 | protected void close() { |
Brad Stenning | 44d3907 | 2019-04-20 11:53:17 -0700 | [diff] [blame] | 442 | if (mPanelExpanded) { |
| 443 | animateCollapsePanels(); |
| 444 | } |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 445 | } |
| 446 | }); |
Priyank Singh | a47b6f7 | 2019-05-28 13:02:47 -0700 | [diff] [blame] | 447 | |
| 448 | // Attached to the Handle bar to close the notification shade |
| 449 | GestureDetector handleBarCloseNotificationGestureDetector = new GestureDetector(mContext, |
| 450 | new HandleBarCloseNotificationGestureListener()); |
| 451 | |
Heemin Seog | 1a13af5 | 2019-10-03 16:15:50 -0700 | [diff] [blame] | 452 | mTopNavBarNotificationTouchListener = (v, event) -> { |
| 453 | if (!mDeviceIsSetUpForUser) { |
| 454 | return true; |
| 455 | } |
| 456 | boolean consumed = openGestureDetector.onTouchEvent(event); |
| 457 | if (consumed) { |
| 458 | return true; |
| 459 | } |
| 460 | maybeCompleteAnimation(event); |
| 461 | return true; |
| 462 | }; |
| 463 | |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 464 | mNavBarNotificationTouchListener = |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 465 | (v, event) -> { |
| 466 | boolean consumed = navBarCloseNotificationGestureDetector.onTouchEvent(event); |
| 467 | if (consumed) { |
| 468 | return true; |
| 469 | } |
Priyank Singh | a47b6f7 | 2019-05-28 13:02:47 -0700 | [diff] [blame] | 470 | maybeCompleteAnimation(event); |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 471 | return true; |
| 472 | }; |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 473 | |
Jonathan Koo | 007ff07 | 2019-05-10 09:24:08 -0700 | [diff] [blame] | 474 | mNotificationClickHandlerFactory = new NotificationClickHandlerFactory( |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 475 | mBarService, |
| 476 | launchResult -> { |
| 477 | if (launchResult == ActivityManager.START_TASK_TO_FRONT |
| 478 | || launchResult == ActivityManager.START_SUCCESS) { |
| 479 | animateCollapsePanels(); |
| 480 | } |
| 481 | }); |
Keun young Park | 9e395bb | 2019-10-11 20:00:22 -0700 | [diff] [blame] | 482 | |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 483 | CarNotificationListener carNotificationListener = new CarNotificationListener(); |
Keun young Park | 9e395bb | 2019-10-11 20:00:22 -0700 | [diff] [blame] | 484 | mCarUxRestrictionManagerWrapper = new CarUxRestrictionManagerWrapper(); |
| 485 | // This can take time if car service is not ready up to this time. |
| 486 | // TODO(b/142808072) Refactor CarUxRestrictionManagerWrapper to allow setting |
| 487 | // CarUxRestrictionsManager later and switch to Car.CAR_WAIT_TIMEOUT_DO_NOT_WAIT. |
| 488 | Car.createCar(mContext, /* handler= */ null, Car.CAR_WAIT_TIMEOUT_WAIT_FOREVER, |
| 489 | (car, ready) -> { |
| 490 | if (!ready) { |
| 491 | return; |
| 492 | } |
| 493 | CarUxRestrictionsManager carUxRestrictionsManager = |
| 494 | (CarUxRestrictionsManager) |
| 495 | car.getCarManager(Car.CAR_UX_RESTRICTION_SERVICE); |
| 496 | mCarUxRestrictionManagerWrapper.setCarUxRestrictionsManager( |
| 497 | carUxRestrictionsManager); |
| 498 | }); |
Jonathan Koo | c9f71aa | 2019-05-06 08:20:14 -0700 | [diff] [blame] | 499 | |
Jonathan Koo | 007ff07 | 2019-05-10 09:24:08 -0700 | [diff] [blame] | 500 | mNotificationDataManager = new NotificationDataManager(); |
| 501 | mNotificationDataManager.setOnUnseenCountUpdateListener( |
Jonathan Koo | c9f71aa | 2019-05-06 08:20:14 -0700 | [diff] [blame] | 502 | () -> { |
Jonathan Koo | 307bda9 | 2019-05-14 16:53:48 -0700 | [diff] [blame] | 503 | if (mNavigationBarView != null && mNotificationDataManager != null) { |
| 504 | Boolean hasUnseen = |
| 505 | mNotificationDataManager.getUnseenNotificationCount() > 0; |
| 506 | if (mNavigationBarView != null) { |
| 507 | mNavigationBarView.toggleNotificationUnseenIndicator(hasUnseen); |
| 508 | } |
| 509 | |
| 510 | if (mLeftNavigationBarView != null) { |
| 511 | mLeftNavigationBarView.toggleNotificationUnseenIndicator(hasUnseen); |
| 512 | } |
| 513 | |
| 514 | if (mRightNavigationBarView != null) { |
| 515 | mRightNavigationBarView.toggleNotificationUnseenIndicator(hasUnseen); |
| 516 | } |
| 517 | } |
Jonathan Koo | c9f71aa | 2019-05-06 08:20:14 -0700 | [diff] [blame] | 518 | }); |
| 519 | |
Priyank Singh | 8bd920f | 2019-06-04 15:21:46 -0700 | [diff] [blame] | 520 | mEnableHeadsUpNotificationWhenNotificationShadeOpen = mContext.getResources().getBoolean( |
| 521 | R.bool.config_enableHeadsUpNotificationWhenNotificationShadeOpen); |
Brad Stenning | 2ccc2a4 | 2019-04-15 10:17:01 -0700 | [diff] [blame] | 522 | CarHeadsUpNotificationManager carHeadsUpNotificationManager = |
Jonathan Koo | 007ff07 | 2019-05-10 09:24:08 -0700 | [diff] [blame] | 523 | new CarSystemUIHeadsUpNotificationManager(mContext, |
| 524 | mNotificationClickHandlerFactory, mNotificationDataManager); |
| 525 | mNotificationClickHandlerFactory.setNotificationDataManager(mNotificationDataManager); |
Brad Stenning | 2ccc2a4 | 2019-04-15 10:17:01 -0700 | [diff] [blame] | 526 | |
Keun young Park | 9e395bb | 2019-10-11 20:00:22 -0700 | [diff] [blame] | 527 | carNotificationListener.registerAsSystemService(mContext, mCarUxRestrictionManagerWrapper, |
Jonathan Koo | 007ff07 | 2019-05-10 09:24:08 -0700 | [diff] [blame] | 528 | carHeadsUpNotificationManager, mNotificationDataManager); |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 529 | |
| 530 | mNotificationView = mStatusBarWindow.findViewById(R.id.notification_view); |
| 531 | View glassPane = mStatusBarWindow.findViewById(R.id.glass_pane); |
Priyank Singh | 647f9e6 | 2019-05-16 15:19:53 -0700 | [diff] [blame] | 532 | mHandleBar = mStatusBarWindow.findViewById(R.id.handle_bar); |
Jonathan Koo | 007ff07 | 2019-05-10 09:24:08 -0700 | [diff] [blame] | 533 | mNotificationView.setClickHandlerFactory(mNotificationClickHandlerFactory); |
| 534 | mNotificationView.setNotificationDataManager(mNotificationDataManager); |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 535 | |
| 536 | // The glass pane is used to view touch events before passed to the notification list. |
| 537 | // This allows us to initialize gesture listeners and detect when to close the notifications |
| 538 | glassPane.setOnTouchListener((v, event) -> { |
| 539 | if (event.getActionMasked() == MotionEvent.ACTION_UP) { |
| 540 | mNotificationListAtBottomAtTimeOfTouch = false; |
| 541 | } |
| 542 | if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 543 | mFirstTouchDownOnGlassPane = event.getRawX(); |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 544 | mNotificationListAtBottomAtTimeOfTouch = mNotificationListAtBottom; |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 545 | // Reset the tracker when there is a touch down on the glass pane. |
| 546 | mIsTracking = false; |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 547 | // Pass the down event to gesture detector so that it knows where the touch event |
| 548 | // started. |
| 549 | closeGestureDetector.onTouchEvent(event); |
| 550 | } |
| 551 | return false; |
| 552 | }); |
Priyank Singh | a47b6f7 | 2019-05-28 13:02:47 -0700 | [diff] [blame] | 553 | |
| 554 | mHandleBar.setOnTouchListener((v, event) -> { |
| 555 | handleBarCloseNotificationGestureDetector.onTouchEvent(event); |
| 556 | maybeCompleteAnimation(event); |
| 557 | return true; |
| 558 | }); |
| 559 | |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 560 | mNotificationList = mNotificationView.findViewById(R.id.notifications); |
| 561 | mNotificationList.addOnScrollListener(new RecyclerView.OnScrollListener() { |
| 562 | @Override |
| 563 | public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { |
| 564 | super.onScrolled(recyclerView, dx, dy); |
| 565 | if (!mNotificationList.canScrollVertically(1)) { |
| 566 | mNotificationListAtBottom = true; |
| 567 | return; |
| 568 | } |
| 569 | mNotificationListAtBottom = false; |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 570 | mIsSwipingVerticallyToClose = false; |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 571 | mNotificationListAtBottomAtTimeOfTouch = false; |
| 572 | } |
| 573 | }); |
| 574 | mNotificationList.setOnTouchListener(new View.OnTouchListener() { |
| 575 | @Override |
| 576 | public boolean onTouch(View v, MotionEvent event) { |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 577 | mIsNotificationCardSwiping = Math.abs(mFirstTouchDownOnGlassPane - event.getRawX()) |
| 578 | > SWIPE_MAX_OFF_PATH; |
| 579 | if (mNotificationListAtBottomAtTimeOfTouch && mNotificationListAtBottom) { |
| 580 | // We need to save the state here as if notification card is swiping we will |
| 581 | // change the mNotificationListAtBottomAtTimeOfTouch. This is to protect |
| 582 | // closing the notification shade while the notification card is being swiped. |
| 583 | mIsSwipingVerticallyToClose = true; |
| 584 | } |
| 585 | |
| 586 | // If the card is swiping we should not allow the notification shade to close. |
| 587 | // Hence setting mNotificationListAtBottomAtTimeOfTouch to false will stop that |
| 588 | // for us. We are also checking for mIsTracking because while swiping the |
| 589 | // notification shade to close if the user goes a bit horizontal while swiping |
| 590 | // upwards then also this should close. |
| 591 | if (mIsNotificationCardSwiping && !mIsTracking) { |
| 592 | mNotificationListAtBottomAtTimeOfTouch = false; |
| 593 | } |
| 594 | |
Priyank Singh | bae09ae | 2019-04-25 18:17:02 -0700 | [diff] [blame] | 595 | boolean handled = closeGestureDetector.onTouchEvent(event); |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 596 | boolean isTracking = mIsTracking; |
Priyank Singh | 647f9e6 | 2019-05-16 15:19:53 -0700 | [diff] [blame] | 597 | Rect rect = mNotificationView.getClipBounds(); |
Priyank Singh | f391286 | 2019-04-22 10:41:58 -0700 | [diff] [blame] | 598 | float clippedHeight = 0; |
| 599 | if (rect != null) { |
| 600 | clippedHeight = rect.bottom; |
| 601 | } |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 602 | if (!handled && event.getActionMasked() == MotionEvent.ACTION_UP |
| 603 | && mIsSwipingVerticallyToClose) { |
| 604 | if (mSettleClosePercentage < mPercentageFromBottom && isTracking) { |
| 605 | animateNotificationPanel(DEFAULT_FLING_VELOCITY, false); |
| 606 | } else if (clippedHeight != mNotificationView.getHeight() && isTracking) { |
| 607 | // this can be caused when user is at the end of the list and trying to |
| 608 | // fling to top of the list by scrolling down. |
| 609 | animateNotificationPanel(DEFAULT_FLING_VELOCITY, true); |
| 610 | } |
| 611 | } |
| 612 | |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 613 | // Updating the mNotificationListAtBottomAtTimeOfTouch state has to be done after |
| 614 | // the event has been passed to the closeGestureDetector above, such that the |
| 615 | // closeGestureDetector sees the up event before the state has changed. |
| 616 | if (event.getActionMasked() == MotionEvent.ACTION_UP) { |
| 617 | mNotificationListAtBottomAtTimeOfTouch = false; |
| 618 | } |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 619 | return handled || isTracking; |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 620 | } |
| 621 | }); |
| 622 | |
Adora Zhang | daea911 | 2019-04-11 17:47:40 -0700 | [diff] [blame] | 623 | mNotificationViewController = new NotificationViewController( |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 624 | mNotificationView, |
| 625 | PreprocessingManager.getInstance(mContext), |
| 626 | carNotificationListener, |
Keun young Park | 9e395bb | 2019-10-11 20:00:22 -0700 | [diff] [blame] | 627 | mCarUxRestrictionManagerWrapper, |
Jonathan Koo | 007ff07 | 2019-05-10 09:24:08 -0700 | [diff] [blame] | 628 | mNotificationDataManager); |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 629 | mNotificationViewController.enable(); |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 630 | } |
| 631 | |
Brad Stenning | 44d3907 | 2019-04-20 11:53:17 -0700 | [diff] [blame] | 632 | /** |
| 633 | * @return true if the notification panel is currently visible |
| 634 | */ |
| 635 | boolean isNotificationPanelOpen() { |
| 636 | return mPanelExpanded; |
| 637 | } |
| 638 | |
Brad Stenning | 8d1a51c | 2018-11-20 17:34:16 -0800 | [diff] [blame] | 639 | @Override |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 640 | public void animateExpandNotificationsPanel() { |
| 641 | if (!mCommandQueue.panelsEnabled() || !mUserSetup) { |
| 642 | return; |
| 643 | } |
| 644 | // scroll to top |
| 645 | mNotificationList.scrollToPosition(0); |
| 646 | mStatusBarWindowController.setPanelVisible(true); |
| 647 | mNotificationView.setVisibility(View.VISIBLE); |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 648 | animateNotificationPanel(mOpeningVelocity, false); |
| 649 | |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 650 | setPanelExpanded(true); |
| 651 | } |
| 652 | |
| 653 | @Override |
| 654 | public void animateCollapsePanels(int flags, boolean force, boolean delayed, |
| 655 | float speedUpFactor) { |
| 656 | super.animateCollapsePanels(flags, force, delayed, speedUpFactor); |
| 657 | if (!mPanelExpanded || mNotificationView.getVisibility() == View.INVISIBLE) { |
| 658 | return; |
| 659 | } |
| 660 | mStatusBarWindowController.setStatusBarFocusable(false); |
| 661 | mStatusBarWindow.cancelExpandHelper(); |
| 662 | mStatusBarView.collapsePanel(true /* animate */, delayed, speedUpFactor); |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 663 | |
| 664 | animateNotificationPanel(mClosingVelocity, true); |
| 665 | |
| 666 | if (!mIsTracking) { |
| 667 | mStatusBarWindowController.setPanelVisible(false); |
| 668 | mNotificationView.setVisibility(View.INVISIBLE); |
| 669 | } |
| 670 | |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 671 | setPanelExpanded(false); |
| 672 | } |
| 673 | |
Priyank Singh | a47b6f7 | 2019-05-28 13:02:47 -0700 | [diff] [blame] | 674 | private void maybeCompleteAnimation(MotionEvent event) { |
| 675 | if (event.getActionMasked() == MotionEvent.ACTION_UP |
| 676 | && mNotificationView.getVisibility() == View.VISIBLE) { |
| 677 | if (mSettleClosePercentage < mPercentageFromBottom) { |
| 678 | animateNotificationPanel(DEFAULT_FLING_VELOCITY, false); |
| 679 | } else { |
| 680 | animateNotificationPanel(DEFAULT_FLING_VELOCITY, true); |
| 681 | } |
| 682 | } |
| 683 | } |
| 684 | |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 685 | /** |
| 686 | * Animates the notification shade from one position to other. This is used to either open or |
Priyank Singh | 245bd12 | 2019-04-21 15:42:44 -0700 | [diff] [blame] | 687 | * close the notification shade completely with a velocity. If the animation is to close the |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 688 | * notification shade this method also makes the view invisible after animation ends. |
| 689 | */ |
| 690 | private void animateNotificationPanel(float velocity, boolean isClosing) { |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 691 | float to = 0; |
| 692 | if (!isClosing) { |
| 693 | to = mNotificationView.getHeight(); |
| 694 | } |
Priyank Singh | b9ab052 | 2019-05-03 15:36:25 -0700 | [diff] [blame] | 695 | |
Priyank Singh | 647f9e6 | 2019-05-16 15:19:53 -0700 | [diff] [blame] | 696 | Rect rect = mNotificationView.getClipBounds(); |
Priyank Singh | b9ab052 | 2019-05-03 15:36:25 -0700 | [diff] [blame] | 697 | if (rect != null) { |
| 698 | float from = rect.bottom; |
| 699 | animate(from, to, velocity, isClosing); |
| 700 | return; |
| 701 | } |
| 702 | |
| 703 | // We will only be here if the shade is being opened programmatically. |
| 704 | ViewTreeObserver notificationTreeObserver = mNotificationView.getViewTreeObserver(); |
| 705 | notificationTreeObserver.addOnGlobalLayoutListener( |
| 706 | new ViewTreeObserver.OnGlobalLayoutListener() { |
| 707 | @Override |
| 708 | public void onGlobalLayout() { |
| 709 | ViewTreeObserver obs = mNotificationView.getViewTreeObserver(); |
| 710 | obs.removeOnGlobalLayoutListener(this); |
| 711 | float to = mNotificationView.getHeight(); |
| 712 | animate(/* from= */ 0, to, velocity, isClosing); |
| 713 | } |
| 714 | }); |
| 715 | } |
| 716 | |
| 717 | private void animate(float from, float to, float velocity, boolean isClosing) { |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 718 | if (mIsNotificationAnimating) { |
| 719 | return; |
| 720 | } |
| 721 | mIsNotificationAnimating = true; |
| 722 | mIsTracking = true; |
| 723 | ValueAnimator animator = ValueAnimator.ofFloat(from, to); |
| 724 | animator.addUpdateListener( |
| 725 | animation -> { |
| 726 | float animatedValue = (Float) animation.getAnimatedValue(); |
| 727 | setNotificationViewClipBounds((int) animatedValue); |
| 728 | }); |
| 729 | animator.addListener(new AnimatorListenerAdapter() { |
| 730 | @Override |
| 731 | public void onAnimationEnd(Animator animation) { |
| 732 | super.onAnimationEnd(animation); |
| 733 | mIsNotificationAnimating = false; |
| 734 | mIsTracking = false; |
| 735 | mOpeningVelocity = DEFAULT_FLING_VELOCITY; |
| 736 | mClosingVelocity = DEFAULT_FLING_VELOCITY; |
| 737 | if (isClosing) { |
| 738 | mStatusBarWindowController.setPanelVisible(false); |
| 739 | mNotificationView.setVisibility(View.INVISIBLE); |
Priyank Singh | 647f9e6 | 2019-05-16 15:19:53 -0700 | [diff] [blame] | 740 | mNotificationView.setClipBounds(null); |
Adora Zhang | daea911 | 2019-04-11 17:47:40 -0700 | [diff] [blame] | 741 | mNotificationViewController.setIsInForeground(false); |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 742 | // let the status bar know that the panel is closed |
| 743 | setPanelExpanded(false); |
| 744 | } else { |
Adora Zhang | daea911 | 2019-04-11 17:47:40 -0700 | [diff] [blame] | 745 | mNotificationViewController.setIsInForeground(true); |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 746 | // let the status bar know that the panel is open |
Jonathan Koo | c9f71aa | 2019-05-06 08:20:14 -0700 | [diff] [blame] | 747 | mNotificationView.setVisibleNotificationsAsSeen(); |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 748 | setPanelExpanded(true); |
| 749 | } |
| 750 | } |
| 751 | }); |
Jonathan Koo | 007ff07 | 2019-05-10 09:24:08 -0700 | [diff] [blame] | 752 | mFlingAnimationUtils.apply(animator, from, to, Math.abs(velocity)); |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 753 | animator.start(); |
| 754 | } |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 755 | |
| 756 | @Override |
Brad Stenning | 8d1a51c | 2018-11-20 17:34:16 -0800 | [diff] [blame] | 757 | protected QS createDefaultQSFragment() { |
| 758 | return new CarQSFragment(); |
| 759 | } |
| 760 | |
Rakesh Iyer | 545e47d | 2017-01-23 18:10:21 -0800 | [diff] [blame] | 761 | private BatteryController createBatteryController() { |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 762 | mCarBatteryController = new CarBatteryController(mContext); |
| 763 | mCarBatteryController.addBatteryViewHandler(this); |
| 764 | return mCarBatteryController; |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 765 | } |
| 766 | |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 767 | @Override |
Matthew Ng | 9438065 | 2019-04-08 13:43:07 -0700 | [diff] [blame] | 768 | protected void createNavigationBar(@Nullable RegisterStatusBarResult result) { |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 769 | mShowBottom = mContext.getResources().getBoolean(R.bool.config_enableBottomNavigationBar); |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 770 | mShowLeft = mContext.getResources().getBoolean(R.bool.config_enableLeftNavigationBar); |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 771 | mShowRight = mContext.getResources().getBoolean(R.bool.config_enableRightNavigationBar); |
| 772 | |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 773 | buildNavBarWindows(); |
| 774 | buildNavBarContent(); |
| 775 | attachNavBarWindows(); |
Andrii Kulian | 3ddd7de | 2018-10-10 00:33:19 -0700 | [diff] [blame] | 776 | |
Heemin Seog | 28097c4 | 2019-08-15 13:18:41 -0700 | [diff] [blame] | 777 | // Try setting up the initial state of the nav bar if applicable. |
| 778 | if (result != null) { |
| 779 | setImeWindowStatus(Display.DEFAULT_DISPLAY, result.mImeToken, |
| 780 | result.mImeWindowVis, result.mImeBackDisposition, |
| 781 | result.mShowImeSwitcher); |
| 782 | } |
| 783 | |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 784 | // There has been a car customized nav bar on the default display, so just create nav bars |
| 785 | // on external displays. |
Matthew Ng | 9438065 | 2019-04-08 13:43:07 -0700 | [diff] [blame] | 786 | mNavigationBarController.createNavigationBars(false /* includeDefaultDisplay */, result); |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | private void buildNavBarContent() { |
Heemin Seog | 1a13af5 | 2019-10-03 16:15:50 -0700 | [diff] [blame] | 790 | // Always build top bar. |
| 791 | buildTopBar((mDeviceIsSetUpForUser) ? R.layout.car_top_navigation_bar : |
| 792 | R.layout.car_top_navigation_bar_unprovisioned); |
| 793 | |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 794 | if (mShowBottom) { |
Heemin Seog | 1a13af5 | 2019-10-03 16:15:50 -0700 | [diff] [blame] | 795 | buildBottomBar((mDeviceIsSetUpForUser) ? R.layout.car_navigation_bar : |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 796 | R.layout.car_navigation_bar_unprovisioned); |
| 797 | } |
| 798 | |
| 799 | if (mShowLeft) { |
Heemin Seog | 1a13af5 | 2019-10-03 16:15:50 -0700 | [diff] [blame] | 800 | buildLeft((mDeviceIsSetUpForUser) ? R.layout.car_left_navigation_bar : |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 801 | R.layout.car_left_navigation_bar_unprovisioned); |
| 802 | } |
| 803 | |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 804 | if (mShowRight) { |
Heemin Seog | 1a13af5 | 2019-10-03 16:15:50 -0700 | [diff] [blame] | 805 | buildRight((mDeviceIsSetUpForUser) ? R.layout.car_right_navigation_bar : |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 806 | R.layout.car_right_navigation_bar_unprovisioned); |
| 807 | } |
| 808 | } |
| 809 | |
| 810 | private void buildNavBarWindows() { |
Heemin Seog | 1a13af5 | 2019-10-03 16:15:50 -0700 | [diff] [blame] | 811 | mTopNavigationBarContainer = mStatusBarWindow |
| 812 | .findViewById(R.id.car_top_navigation_bar_container); |
| 813 | |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 814 | if (mShowBottom) { |
davidln | 5473915 | 2018-07-02 13:25:44 -0700 | [diff] [blame] | 815 | mNavigationBarWindow = (ViewGroup) View.inflate(mContext, |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 816 | R.layout.navigation_bar_window, null); |
| 817 | } |
| 818 | if (mShowLeft) { |
| 819 | mLeftNavigationBarWindow = (ViewGroup) View.inflate(mContext, |
davidln | 5473915 | 2018-07-02 13:25:44 -0700 | [diff] [blame] | 820 | R.layout.navigation_bar_window, null); |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 821 | } |
| 822 | if (mShowRight) { |
| 823 | mRightNavigationBarWindow = (ViewGroup) View.inflate(mContext, |
| 824 | R.layout.navigation_bar_window, null); |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | } |
| 828 | |
Heemin Seog | 28097c4 | 2019-08-15 13:18:41 -0700 | [diff] [blame] | 829 | /** |
| 830 | * We register for soft keyboard visibility events such that we can hide the navigation bar |
| 831 | * giving more screen space to the IME. Note: this is optional and controlled by |
| 832 | * {@code com.android.internal.R.bool.config_automotiveHideNavBarForKeyboard}. |
| 833 | */ |
| 834 | @Override |
| 835 | public void setImeWindowStatus(int displayId, IBinder token, int vis, int backDisposition, |
| 836 | boolean showImeSwitcher) { |
| 837 | if (!mHideNavBarForKeyboard) { |
| 838 | return; |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 839 | } |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 840 | |
Heemin Seog | 28097c4 | 2019-08-15 13:18:41 -0700 | [diff] [blame] | 841 | if (mContext.getDisplay().getDisplayId() != displayId) { |
| 842 | return; |
| 843 | } |
| 844 | |
| 845 | boolean isKeyboardVisible = (vis & InputMethodService.IME_VISIBLE) != 0; |
JianYang Liu | 2c00fcf | 2019-10-10 15:37:29 -0700 | [diff] [blame] | 846 | showBottomNavBarWindow(isKeyboardVisible); |
Heemin Seog | 28097c4 | 2019-08-15 13:18:41 -0700 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | private void attachNavBarWindows() { |
JianYang Liu | 2c00fcf | 2019-10-10 15:37:29 -0700 | [diff] [blame] | 850 | if (mShowBottom && !mBottomNavBarVisible) { |
| 851 | mBottomNavBarVisible = true; |
| 852 | |
| 853 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 854 | LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, |
| 855 | WindowManager.LayoutParams.TYPE_NAVIGATION_BAR, |
| 856 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 857 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
| 858 | | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
| 859 | | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH, |
| 860 | PixelFormat.TRANSLUCENT); |
| 861 | lp.setTitle("CarNavigationBar"); |
| 862 | lp.windowAnimations = 0; |
| 863 | mWindowManager.addView(mNavigationBarWindow, lp); |
| 864 | } |
Heemin Seog | 28097c4 | 2019-08-15 13:18:41 -0700 | [diff] [blame] | 865 | |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 866 | if (mShowLeft) { |
| 867 | int width = mContext.getResources().getDimensionPixelSize( |
| 868 | R.dimen.car_left_navigation_bar_width); |
| 869 | WindowManager.LayoutParams leftlp = new WindowManager.LayoutParams( |
| 870 | width, LayoutParams.MATCH_PARENT, |
| 871 | WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL, |
| 872 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 873 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
| 874 | | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
| 875 | | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH, |
| 876 | PixelFormat.TRANSLUCENT); |
| 877 | leftlp.setTitle("LeftCarNavigationBar"); |
| 878 | leftlp.windowAnimations = 0; |
| 879 | leftlp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_IS_SCREEN_DECOR; |
| 880 | leftlp.gravity = Gravity.LEFT; |
| 881 | mWindowManager.addView(mLeftNavigationBarWindow, leftlp); |
| 882 | } |
| 883 | if (mShowRight) { |
| 884 | int width = mContext.getResources().getDimensionPixelSize( |
| 885 | R.dimen.car_right_navigation_bar_width); |
| 886 | WindowManager.LayoutParams rightlp = new WindowManager.LayoutParams( |
| 887 | width, LayoutParams.MATCH_PARENT, |
| 888 | WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL, |
| 889 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 890 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
| 891 | | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
| 892 | | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH, |
| 893 | PixelFormat.TRANSLUCENT); |
| 894 | rightlp.setTitle("RightCarNavigationBar"); |
| 895 | rightlp.windowAnimations = 0; |
| 896 | rightlp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_IS_SCREEN_DECOR; |
| 897 | rightlp.gravity = Gravity.RIGHT; |
| 898 | mWindowManager.addView(mRightNavigationBarWindow, rightlp); |
| 899 | } |
Heemin Seog | 28097c4 | 2019-08-15 13:18:41 -0700 | [diff] [blame] | 900 | } |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 901 | |
JianYang Liu | 2c00fcf | 2019-10-10 15:37:29 -0700 | [diff] [blame] | 902 | private void showBottomNavBarWindow(boolean isKeyboardVisible) { |
Heemin Seog | 28097c4 | 2019-08-15 13:18:41 -0700 | [diff] [blame] | 903 | if (!mShowBottom) { |
| 904 | return; |
| 905 | } |
| 906 | |
JianYang Liu | 2c00fcf | 2019-10-10 15:37:29 -0700 | [diff] [blame] | 907 | // If keyboard is visible and bottom nav bar not visible, this is the correct state, so do |
| 908 | // nothing. Same with if keyboard is not visible and bottom nav bar is visible. |
| 909 | if (isKeyboardVisible ^ mBottomNavBarVisible) { |
Heemin Seog | 28097c4 | 2019-08-15 13:18:41 -0700 | [diff] [blame] | 910 | return; |
| 911 | } |
| 912 | |
JianYang Liu | 2c00fcf | 2019-10-10 15:37:29 -0700 | [diff] [blame] | 913 | mNavigationBarWindow.setVisibility(isKeyboardVisible ? View.GONE : View.VISIBLE); |
| 914 | mBottomNavBarVisible = !isKeyboardVisible; |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 915 | } |
| 916 | |
Heemin Seog | 1a13af5 | 2019-10-03 16:15:50 -0700 | [diff] [blame] | 917 | private void buildTopBar(int layout) { |
| 918 | mTopNavigationBarContainer.removeAllViews(); |
| 919 | View.inflate(mContext, layout, mTopNavigationBarContainer); |
| 920 | mTopNavigationBarView = (CarNavigationBarView) mTopNavigationBarContainer.getChildAt(0); |
| 921 | if (mTopNavigationBarView == null) { |
| 922 | Log.e(TAG, "CarStatusBar failed inflate for R.layout.car_top_navigation_bar"); |
| 923 | throw new RuntimeException("Unable to build top nav bar due to missing layout"); |
| 924 | } |
| 925 | mTopNavigationBarView.setStatusBar(this); |
| 926 | addTemperatureViewToController(mTopNavigationBarView); |
| 927 | mTopNavigationBarView.setStatusBarWindowTouchListener(mTopNavBarNotificationTouchListener); |
| 928 | } |
| 929 | |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 930 | private void buildBottomBar(int layout) { |
Anthony Chen | 0801a5c | 2017-03-22 09:54:37 -0700 | [diff] [blame] | 931 | // SystemUI requires that the navigation bar view have a parent. Since the regular |
| 932 | // StatusBar inflates navigation_bar_window as this parent view, use the same view for the |
| 933 | // CarNavigationBarView. |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 934 | View.inflate(mContext, layout, mNavigationBarWindow); |
Scott Randolph | f408582 | 2017-06-27 15:23:01 -0700 | [diff] [blame] | 935 | mNavigationBarView = (CarNavigationBarView) mNavigationBarWindow.getChildAt(0); |
| 936 | if (mNavigationBarView == null) { |
| 937 | Log.e(TAG, "CarStatusBar failed inflate for R.layout.car_navigation_bar"); |
Heemin Seog | 1a13af5 | 2019-10-03 16:15:50 -0700 | [diff] [blame] | 938 | throw new RuntimeException("Unable to build bottom nav bar due to missing layout"); |
Scott Randolph | f408582 | 2017-06-27 15:23:01 -0700 | [diff] [blame] | 939 | } |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 940 | mNavigationBarView.setStatusBar(this); |
Brad Stenning | f084d88 | 2018-08-08 13:34:21 -0700 | [diff] [blame] | 941 | addTemperatureViewToController(mNavigationBarView); |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 942 | mNavigationBarView.setStatusBarWindowTouchListener(mNavBarNotificationTouchListener); |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 943 | } |
| 944 | |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 945 | private void buildLeft(int layout) { |
| 946 | View.inflate(mContext, layout, mLeftNavigationBarWindow); |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 947 | mLeftNavigationBarView = (CarNavigationBarView) mLeftNavigationBarWindow.getChildAt(0); |
| 948 | if (mLeftNavigationBarView == null) { |
Heemin Seog | 1a13af5 | 2019-10-03 16:15:50 -0700 | [diff] [blame] | 949 | Log.e(TAG, "CarStatusBar failed inflate for R.layout.car_left_navigation_bar"); |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 950 | throw new RuntimeException("Unable to build left nav bar due to missing layout"); |
| 951 | } |
| 952 | mLeftNavigationBarView.setStatusBar(this); |
Brad Stenning | f084d88 | 2018-08-08 13:34:21 -0700 | [diff] [blame] | 953 | addTemperatureViewToController(mLeftNavigationBarView); |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 954 | mLeftNavigationBarView.setStatusBarWindowTouchListener(mNavBarNotificationTouchListener); |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 958 | private void buildRight(int layout) { |
| 959 | View.inflate(mContext, layout, mRightNavigationBarWindow); |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 960 | mRightNavigationBarView = (CarNavigationBarView) mRightNavigationBarWindow.getChildAt(0); |
| 961 | if (mRightNavigationBarView == null) { |
Heemin Seog | 1a13af5 | 2019-10-03 16:15:50 -0700 | [diff] [blame] | 962 | Log.e(TAG, "CarStatusBar failed inflate for R.layout.car_right_navigation_bar"); |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 963 | throw new RuntimeException("Unable to build right nav bar due to missing layout"); |
| 964 | } |
Brad Stenning | f084d88 | 2018-08-08 13:34:21 -0700 | [diff] [blame] | 965 | mRightNavigationBarView.setStatusBar(this); |
| 966 | addTemperatureViewToController(mRightNavigationBarView); |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 967 | mRightNavigationBarView.setStatusBarWindowTouchListener(mNavBarNotificationTouchListener); |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 968 | } |
| 969 | |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 970 | @Override |
Qiming Shi | b9dfb92 | 2017-04-13 16:23:18 +0800 | [diff] [blame] | 971 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 972 | //When executing dump() function simultaneously, we need to serialize them |
Qiming Shi | b9dfb92 | 2017-04-13 16:23:18 +0800 | [diff] [blame] | 973 | //to get mStackScroller's position correctly. |
| 974 | synchronized (mQueueLock) { |
| 975 | pw.println(" mStackScroller: " + viewInfo(mStackScroller)); |
| 976 | pw.println(" mStackScroller: " + viewInfo(mStackScroller) |
| 977 | + " scroll " + mStackScroller.getScrollX() |
| 978 | + "," + mStackScroller.getScrollY()); |
| 979 | } |
| 980 | |
davidln | 5473915 | 2018-07-02 13:25:44 -0700 | [diff] [blame] | 981 | pw.print(" mTaskStackListener="); |
| 982 | pw.println(mTaskStackListener); |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 983 | pw.print(" mCarFacetButtonController="); |
| 984 | pw.println(mCarFacetButtonController); |
davidln | 5473915 | 2018-07-02 13:25:44 -0700 | [diff] [blame] | 985 | pw.print(" mFullscreenUserSwitcher="); |
| 986 | pw.println(mFullscreenUserSwitcher); |
Qiming Shi | b9dfb92 | 2017-04-13 16:23:18 +0800 | [diff] [blame] | 987 | pw.print(" mCarBatteryController="); |
| 988 | pw.println(mCarBatteryController); |
| 989 | pw.print(" mBatteryMeterView="); |
| 990 | pw.println(mBatteryMeterView); |
Qiming Shi | b9dfb92 | 2017-04-13 16:23:18 +0800 | [diff] [blame] | 991 | pw.print(" mNavigationBarView="); |
| 992 | pw.println(mNavigationBarView); |
| 993 | |
| 994 | if (KeyguardUpdateMonitor.getInstance(mContext) != null) { |
| 995 | KeyguardUpdateMonitor.getInstance(mContext).dump(fd, pw, args); |
| 996 | } |
| 997 | |
Dave Mankoff | 781ef7e | 2019-06-28 16:33:25 -0400 | [diff] [blame] | 998 | Dependency.get(FalsingManager.class).dump(pw); |
Qiming Shi | b9dfb92 | 2017-04-13 16:23:18 +0800 | [diff] [blame] | 999 | FalsingLog.dump(pw); |
| 1000 | |
| 1001 | pw.println("SharedPreferences:"); |
| 1002 | for (Map.Entry<String, ?> entry : Prefs.getAll(mContext).entrySet()) { |
davidln | 5473915 | 2018-07-02 13:25:44 -0700 | [diff] [blame] | 1003 | pw.print(" "); |
| 1004 | pw.print(entry.getKey()); |
| 1005 | pw.print("="); |
| 1006 | pw.println(entry.getValue()); |
Qiming Shi | b9dfb92 | 2017-04-13 16:23:18 +0800 | [diff] [blame] | 1007 | } |
| 1008 | } |
| 1009 | |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 1010 | @Override |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 1011 | public void showBatteryView() { |
| 1012 | if (Log.isLoggable(TAG, Log.DEBUG)) { |
| 1013 | Log.d(TAG, "showBatteryView(). mBatteryMeterView: " + mBatteryMeterView); |
| 1014 | } |
| 1015 | |
| 1016 | if (mBatteryMeterView != null) { |
| 1017 | mBatteryMeterView.setVisibility(View.VISIBLE); |
| 1018 | } |
| 1019 | } |
| 1020 | |
| 1021 | @Override |
| 1022 | public void hideBatteryView() { |
| 1023 | if (Log.isLoggable(TAG, Log.DEBUG)) { |
| 1024 | Log.d(TAG, "hideBatteryView(). mBatteryMeterView: " + mBatteryMeterView); |
| 1025 | } |
| 1026 | |
| 1027 | if (mBatteryMeterView != null) { |
| 1028 | mBatteryMeterView.setVisibility(View.GONE); |
| 1029 | } |
| 1030 | } |
| 1031 | |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 1032 | /** |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 1033 | * An implementation of TaskStackChangeListener, that listens for changes in the system |
davidln | 5473915 | 2018-07-02 13:25:44 -0700 | [diff] [blame] | 1034 | * task stack and notifies the navigation bar. |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 1035 | */ |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 1036 | private class TaskStackListenerImpl extends TaskStackChangeListener { |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 1037 | @Override |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 1038 | public void onTaskStackChanged() { |
Brad Stenning | a5e714c | 2018-04-12 19:23:39 -0700 | [diff] [blame] | 1039 | try { |
| 1040 | mCarFacetButtonController.taskChanged( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 1041 | ActivityTaskManager.getService().getAllStackInfos()); |
Brad Stenning | a5e714c | 2018-04-12 19:23:39 -0700 | [diff] [blame] | 1042 | } catch (Exception e) { |
| 1043 | Log.e(TAG, "Getting StackInfo from activity manager failed", e); |
| 1044 | } |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 1045 | } |
davidln | 1ceedb5 | 2019-05-30 14:25:01 -0700 | [diff] [blame] | 1046 | |
| 1047 | @Override |
| 1048 | public void onTaskDisplayChanged(int taskId, int newDisplayId) { |
| 1049 | try { |
| 1050 | mCarFacetButtonController.taskChanged( |
| 1051 | ActivityTaskManager.getService().getAllStackInfos()); |
| 1052 | } catch (Exception e) { |
| 1053 | Log.e(TAG, "Getting StackInfo from activity manager failed", e); |
| 1054 | } |
| 1055 | } |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 1056 | } |
Rakesh Iyer | 2790a37 | 2016-01-22 15:33:39 -0800 | [diff] [blame] | 1057 | |
jovanak | edba98c | 2018-09-14 15:46:24 -0700 | [diff] [blame] | 1058 | private void onDrivingStateChanged(CarDrivingStateEvent notUsed) { |
| 1059 | // Check if we need to start the timer every time driving state changes. |
| 1060 | startSwitchToGuestTimerIfDrivingOnKeyguard(); |
| 1061 | } |
| 1062 | |
| 1063 | private void startSwitchToGuestTimerIfDrivingOnKeyguard() { |
| 1064 | if (mDrivingStateHelper.isCurrentlyDriving() && mState != StatusBarState.SHADE) { |
| 1065 | // We're driving while keyguard is up. |
| 1066 | mSwitchToGuestTimer.start(); |
| 1067 | } else { |
| 1068 | mSwitchToGuestTimer.cancel(); |
| 1069 | } |
| 1070 | } |
| 1071 | |
Rakesh Iyer | 2790a37 | 2016-01-22 15:33:39 -0800 | [diff] [blame] | 1072 | @Override |
| 1073 | protected void createUserSwitcher() { |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 1074 | UserSwitcherController userSwitcherController = |
| 1075 | Dependency.get(UserSwitcherController.class); |
| 1076 | if (userSwitcherController.useFullscreenUserSwitcher()) { |
| 1077 | mFullscreenUserSwitcher = new FullscreenUserSwitcher(this, |
Keun young Park | 9e395bb | 2019-10-11 20:00:22 -0700 | [diff] [blame] | 1078 | mStatusBarWindow.findViewById(R.id.fullscreen_user_switcher_stub), mContext); |
Rakesh Iyer | 2790a37 | 2016-01-22 15:33:39 -0800 | [diff] [blame] | 1079 | } else { |
| 1080 | super.createUserSwitcher(); |
| 1081 | } |
| 1082 | } |
| 1083 | |
| 1084 | @Override |
jovanak | 168dbdb | 2019-02-18 01:00:43 -0800 | [diff] [blame] | 1085 | public void setLockscreenUser(int newUserId) { |
| 1086 | super.setLockscreenUser(newUserId); |
| 1087 | // Try to dismiss the keyguard after every user switch. |
| 1088 | dismissKeyguardWhenUserSwitcherNotDisplayed(); |
| 1089 | } |
| 1090 | |
| 1091 | @Override |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 1092 | public void onStateChanged(int newState) { |
| 1093 | super.onStateChanged(newState); |
jovanak | edba98c | 2018-09-14 15:46:24 -0700 | [diff] [blame] | 1094 | |
| 1095 | startSwitchToGuestTimerIfDrivingOnKeyguard(); |
| 1096 | |
jovanak | 168dbdb | 2019-02-18 01:00:43 -0800 | [diff] [blame] | 1097 | if (newState != StatusBarState.FULLSCREEN_USER_SWITCHER) { |
| 1098 | hideUserSwitcher(); |
jovanak | 604ad51 | 2018-08-14 18:41:27 -0700 | [diff] [blame] | 1099 | } else { |
jovanak | 168dbdb | 2019-02-18 01:00:43 -0800 | [diff] [blame] | 1100 | dismissKeyguardWhenUserSwitcherNotDisplayed(); |
| 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | /** Makes the full screen user switcher visible, if applicable. */ |
| 1105 | public void showUserSwitcher() { |
| 1106 | if (mFullscreenUserSwitcher != null && mState == StatusBarState.FULLSCREEN_USER_SWITCHER) { |
| 1107 | mFullscreenUserSwitcher.show(); // Makes the switcher visible. |
| 1108 | } |
| 1109 | } |
| 1110 | |
| 1111 | private void hideUserSwitcher() { |
| 1112 | if (mFullscreenUserSwitcher != null) { |
jovanak | 604ad51 | 2018-08-14 18:41:27 -0700 | [diff] [blame] | 1113 | mFullscreenUserSwitcher.hide(); |
Aarthi Balachander | 0a427ef | 2018-07-13 15:00:58 -0700 | [diff] [blame] | 1114 | } |
| 1115 | } |
| 1116 | |
jovanak | 622def2 | 2019-06-11 11:51:54 -0700 | [diff] [blame] | 1117 | final ScreenLifecycle.Observer mScreenObserver = new ScreenLifecycle.Observer() { |
| 1118 | @Override |
| 1119 | public void onScreenTurnedOn() { |
| 1120 | dismissKeyguardWhenUserSwitcherNotDisplayed(); |
| 1121 | } |
| 1122 | }; |
| 1123 | |
jovanak | 168dbdb | 2019-02-18 01:00:43 -0800 | [diff] [blame] | 1124 | // We automatically dismiss keyguard unless user switcher is being shown on the keyguard. |
| 1125 | private void dismissKeyguardWhenUserSwitcherNotDisplayed() { |
| 1126 | if (mFullscreenUserSwitcher == null) { |
| 1127 | return; // Not using the full screen user switcher. |
| 1128 | } |
| 1129 | |
| 1130 | if (mState == StatusBarState.FULLSCREEN_USER_SWITCHER |
| 1131 | && !mFullscreenUserSwitcher.isVisible()) { |
| 1132 | // Current execution path continues to set state after this, thus we deffer the |
| 1133 | // dismissal to the next execution cycle. |
| 1134 | postDismissKeyguard(); // Dismiss the keyguard if switcher is not visible. |
Rakesh Iyer | 2790a37 | 2016-01-22 15:33:39 -0800 | [diff] [blame] | 1135 | } |
| 1136 | } |
Rakesh Iyer | 74ebabe | 2016-03-11 10:10:43 -0800 | [diff] [blame] | 1137 | |
jovanak | 604ad51 | 2018-08-14 18:41:27 -0700 | [diff] [blame] | 1138 | public void postDismissKeyguard() { |
| 1139 | mHandler.post(this::dismissKeyguard); |
| 1140 | } |
| 1141 | |
| 1142 | /** |
| 1143 | * Dismisses the keyguard and shows bouncer if authentication is necessary. |
| 1144 | */ |
| 1145 | public void dismissKeyguard() { |
jovanak | 622def2 | 2019-06-11 11:51:54 -0700 | [diff] [blame] | 1146 | // Don't dismiss keyguard when the screen is off. |
| 1147 | if (mScreenLifecycle.getScreenState() == ScreenLifecycle.SCREEN_OFF) { |
| 1148 | return; |
| 1149 | } |
jovanak | 604ad51 | 2018-08-14 18:41:27 -0700 | [diff] [blame] | 1150 | executeRunnableDismissingKeyguard(null/* runnable */, null /* cancelAction */, |
Brad Stenning | 8d1a51c | 2018-11-20 17:34:16 -0800 | [diff] [blame] | 1151 | true /* dismissShade */, true /* afterKeyguardGone */, true /* deferred */); |
jovanak | 604ad51 | 2018-08-14 18:41:27 -0700 | [diff] [blame] | 1152 | } |
| 1153 | |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 1154 | /** |
| 1155 | * Ensures that relevant child views are appropriately recreated when the device's density |
| 1156 | * changes. |
| 1157 | */ |
| 1158 | @Override |
Jason Monk | 9cac5ff | 2017-06-02 11:35:50 -0400 | [diff] [blame] | 1159 | public void onDensityOrFontScaleChanged() { |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 1160 | super.onDensityOrFontScaleChanged(); |
Guobin Zhang | eef0e0c | 2019-02-01 11:54:24 -0800 | [diff] [blame] | 1161 | restartNavBars(); |
Anthony Chen | e658cc2 | 2017-04-27 11:17:35 -0700 | [diff] [blame] | 1162 | // Need to update the background on density changed in case the change was due to night |
| 1163 | // mode. |
| 1164 | mNotificationPanelBackground = getDefaultWallpaper(); |
| 1165 | mScrimController.setScrimBehindDrawable(mNotificationPanelBackground); |
| 1166 | } |
| 1167 | |
| 1168 | /** |
| 1169 | * Returns the {@link Drawable} that represents the wallpaper that the user has currently set. |
| 1170 | */ |
| 1171 | private Drawable getDefaultWallpaper() { |
| 1172 | return mContext.getDrawable(com.android.internal.R.drawable.default_wallpaper); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 1173 | } |
Brad Stenning | 19f236a | 2018-12-11 14:12:30 -0800 | [diff] [blame] | 1174 | |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1175 | private void setNotificationViewClipBounds(int height) { |
Priyank Singh | ea4af13 | 2019-05-01 17:57:06 -0700 | [diff] [blame] | 1176 | if (height > mNotificationView.getHeight()) { |
| 1177 | height = mNotificationView.getHeight(); |
| 1178 | } |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1179 | Rect clipBounds = new Rect(); |
| 1180 | clipBounds.set(0, 0, mNotificationView.getWidth(), height); |
Priyank Singh | 245bd12 | 2019-04-21 15:42:44 -0700 | [diff] [blame] | 1181 | // Sets the clip region on the notification list view. |
Priyank Singh | 647f9e6 | 2019-05-16 15:19:53 -0700 | [diff] [blame] | 1182 | mNotificationView.setClipBounds(clipBounds); |
| 1183 | if (mHandleBar != null) { |
| 1184 | ViewGroup.MarginLayoutParams lp = |
| 1185 | (ViewGroup.MarginLayoutParams) mHandleBar.getLayoutParams(); |
| 1186 | mHandleBar.setTranslationY(height - mHandleBar.getHeight() - lp.bottomMargin); |
| 1187 | } |
Priyank Singh | 245bd12 | 2019-04-21 15:42:44 -0700 | [diff] [blame] | 1188 | if (mNotificationView.getHeight() > 0) { |
Brad Stenning | 8650f41 | 2019-07-16 16:46:28 -0700 | [diff] [blame] | 1189 | Drawable background = mNotificationView.getBackground().mutate(); |
JianYang Liu | b923d1e | 2019-10-24 17:19:44 -0700 | [diff] [blame] | 1190 | background.setAlpha((int) (getBackgroundAlpha(height) * 255)); |
Brad Stenning | 8650f41 | 2019-07-16 16:46:28 -0700 | [diff] [blame] | 1191 | mNotificationView.setBackground(background); |
Priyank Singh | 245bd12 | 2019-04-21 15:42:44 -0700 | [diff] [blame] | 1192 | } |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1193 | } |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 1194 | |
JianYang Liu | b923d1e | 2019-10-24 17:19:44 -0700 | [diff] [blame] | 1195 | /** |
| 1196 | * Calculates the alpha value for the background based on how much of the notification |
| 1197 | * shade is visible to the user. When the notification shade is completely open then |
| 1198 | * alpha value will be 1. |
| 1199 | */ |
| 1200 | private float getBackgroundAlpha(int height) { |
| 1201 | return mInitialBackgroundAlpha + |
| 1202 | ((float) height / mNotificationView.getHeight() * mBackgroundAlphaDiff); |
| 1203 | } |
| 1204 | |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1205 | private void calculatePercentageFromBottom(float height) { |
| 1206 | if (mNotificationView.getHeight() > 0) { |
| 1207 | mPercentageFromBottom = (int) Math.abs( |
| 1208 | height / mNotificationView.getHeight() * 100); |
| 1209 | } |
| 1210 | } |
| 1211 | |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 1212 | private static final int SWIPE_DOWN_MIN_DISTANCE = 25; |
| 1213 | private static final int SWIPE_MAX_OFF_PATH = 75; |
| 1214 | private static final int SWIPE_THRESHOLD_VELOCITY = 200; |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1215 | |
Priyank Singh | a47b6f7 | 2019-05-28 13:02:47 -0700 | [diff] [blame] | 1216 | /** |
| 1217 | * Only responsible for open hooks. Since once the panel opens it covers all elements |
| 1218 | * there is no need to merge with close. |
| 1219 | */ |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 1220 | private abstract class OpenNotificationGestureListener extends |
| 1221 | GestureDetector.SimpleOnGestureListener { |
| 1222 | |
| 1223 | @Override |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1224 | public boolean onScroll(MotionEvent event1, MotionEvent event2, float distanceX, |
| 1225 | float distanceY) { |
| 1226 | |
| 1227 | if (mNotificationView.getVisibility() == View.INVISIBLE) { |
| 1228 | // when the on-scroll is called for the first time to open. |
| 1229 | mNotificationList.scrollToPosition(0); |
| 1230 | } |
| 1231 | mStatusBarWindowController.setPanelVisible(true); |
| 1232 | mNotificationView.setVisibility(View.VISIBLE); |
| 1233 | |
| 1234 | // clips the view for the notification shade when the user scrolls to open. |
| 1235 | setNotificationViewClipBounds((int) event2.getRawY()); |
| 1236 | |
| 1237 | // Initially the scroll starts with height being zero. This checks protects from divide |
| 1238 | // by zero error. |
| 1239 | calculatePercentageFromBottom(event2.getRawY()); |
| 1240 | |
| 1241 | mIsTracking = true; |
| 1242 | return true; |
| 1243 | } |
| 1244 | |
| 1245 | |
| 1246 | @Override |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 1247 | public boolean onFling(MotionEvent event1, MotionEvent event2, |
| 1248 | float velocityX, float velocityY) { |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1249 | if (velocityY > SWIPE_THRESHOLD_VELOCITY) { |
| 1250 | mOpeningVelocity = velocityY; |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 1251 | openNotification(); |
| 1252 | return true; |
| 1253 | } |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1254 | animateNotificationPanel(DEFAULT_FLING_VELOCITY, true); |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 1255 | |
| 1256 | return false; |
| 1257 | } |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1258 | |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 1259 | protected abstract void openNotification(); |
Brad Stenning | 19f236a | 2018-12-11 14:12:30 -0800 | [diff] [blame] | 1260 | } |
| 1261 | |
Priyank Singh | a47b6f7 | 2019-05-28 13:02:47 -0700 | [diff] [blame] | 1262 | /** |
| 1263 | * To be installed on the open panel notification panel |
| 1264 | */ |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 1265 | private abstract class CloseNotificationGestureListener extends |
| 1266 | GestureDetector.SimpleOnGestureListener { |
| 1267 | |
| 1268 | @Override |
Priyank Singh | bae09ae | 2019-04-25 18:17:02 -0700 | [diff] [blame] | 1269 | public boolean onSingleTapUp(MotionEvent motionEvent) { |
Priyank Singh | b9ab052 | 2019-05-03 15:36:25 -0700 | [diff] [blame] | 1270 | if (mPanelExpanded) { |
| 1271 | animateNotificationPanel(DEFAULT_FLING_VELOCITY, true); |
| 1272 | } |
| 1273 | return true; |
Priyank Singh | bae09ae | 2019-04-25 18:17:02 -0700 | [diff] [blame] | 1274 | } |
| 1275 | |
| 1276 | @Override |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1277 | public boolean onScroll(MotionEvent event1, MotionEvent event2, float distanceX, |
| 1278 | float distanceY) { |
Priyank Singh | bae09ae | 2019-04-25 18:17:02 -0700 | [diff] [blame] | 1279 | // should not clip while scroll to the bottom of the list. |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1280 | if (!mNotificationListAtBottomAtTimeOfTouch) { |
| 1281 | return false; |
| 1282 | } |
| 1283 | float actualNotificationHeight = |
| 1284 | mNotificationView.getHeight() - (event1.getRawY() - event2.getRawY()); |
| 1285 | if (actualNotificationHeight > mNotificationView.getHeight()) { |
| 1286 | actualNotificationHeight = mNotificationView.getHeight(); |
| 1287 | } |
| 1288 | if (mNotificationView.getHeight() > 0) { |
| 1289 | mPercentageFromBottom = (int) Math.abs( |
| 1290 | actualNotificationHeight / mNotificationView.getHeight() * 100); |
| 1291 | boolean isUp = distanceY > 0; |
| 1292 | |
| 1293 | // This check is to figure out if onScroll was called while swiping the card at |
| 1294 | // bottom of the list. At that time we should not allow notification shade to |
| 1295 | // close. We are also checking for the upwards swipe gesture here because it is |
| 1296 | // possible if a user is closing the notification shade and while swiping starts |
| 1297 | // to open again but does not fling. At that time we should allow the |
| 1298 | // notification shade to close fully or else it would stuck in between. |
| 1299 | if (Math.abs(mNotificationView.getHeight() - actualNotificationHeight) |
| 1300 | > SWIPE_DOWN_MIN_DISTANCE && isUp) { |
| 1301 | setNotificationViewClipBounds((int) actualNotificationHeight); |
| 1302 | mIsTracking = true; |
| 1303 | } else if (!isUp) { |
| 1304 | setNotificationViewClipBounds((int) actualNotificationHeight); |
| 1305 | } |
| 1306 | } |
| 1307 | // if we return true the the items in RV won't be scrollable. |
| 1308 | return false; |
| 1309 | } |
| 1310 | |
| 1311 | |
| 1312 | @Override |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 1313 | public boolean onFling(MotionEvent event1, MotionEvent event2, |
| 1314 | float velocityX, float velocityY) { |
Priyank Singh | a01f243 | 2019-05-17 16:33:57 -0700 | [diff] [blame] | 1315 | // should not fling if the touch does not start when view is at the bottom of the list. |
| 1316 | if (!mNotificationListAtBottomAtTimeOfTouch) { |
Priyank Singh | bae09ae | 2019-04-25 18:17:02 -0700 | [diff] [blame] | 1317 | return false; |
| 1318 | } |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 1319 | if (Math.abs(event1.getX() - event2.getX()) > SWIPE_MAX_OFF_PATH |
| 1320 | || Math.abs(velocityY) < SWIPE_THRESHOLD_VELOCITY) { |
| 1321 | // swipe was not vertical or was not fast enough |
| 1322 | return false; |
| 1323 | } |
| 1324 | boolean isUp = velocityY < 0; |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1325 | if (isUp) { |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 1326 | close(); |
| 1327 | return true; |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1328 | } else { |
| 1329 | // we should close the shade |
| 1330 | animateNotificationPanel(velocityY, false); |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 1331 | } |
| 1332 | return false; |
| 1333 | } |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1334 | |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 1335 | protected abstract void close(); |
| 1336 | } |
| 1337 | |
Priyank Singh | a47b6f7 | 2019-05-28 13:02:47 -0700 | [diff] [blame] | 1338 | /** |
| 1339 | * To be installed on the nav bars. |
| 1340 | */ |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 1341 | private abstract class NavBarCloseNotificationGestureListener extends |
| 1342 | CloseNotificationGestureListener { |
| 1343 | @Override |
| 1344 | public boolean onSingleTapUp(MotionEvent e) { |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1345 | mClosingVelocity = DEFAULT_FLING_VELOCITY; |
Priyank Singh | b9ab052 | 2019-05-03 15:36:25 -0700 | [diff] [blame] | 1346 | if (mPanelExpanded) { |
| 1347 | close(); |
| 1348 | } |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 1349 | return super.onSingleTapUp(e); |
| 1350 | } |
| 1351 | |
| 1352 | @Override |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1353 | public boolean onScroll(MotionEvent event1, MotionEvent event2, float distanceX, |
| 1354 | float distanceY) { |
| 1355 | calculatePercentageFromBottom(event2.getRawY()); |
| 1356 | setNotificationViewClipBounds((int) event2.getRawY()); |
| 1357 | return true; |
| 1358 | } |
| 1359 | |
| 1360 | @Override |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 1361 | public void onLongPress(MotionEvent e) { |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1362 | mClosingVelocity = DEFAULT_FLING_VELOCITY; |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 1363 | close(); |
| 1364 | super.onLongPress(e); |
| 1365 | } |
Adora Zhang | 0237b9c | 2019-03-08 12:27:09 -0800 | [diff] [blame] | 1366 | } |
Brad Stenning | 2ccc2a4 | 2019-04-15 10:17:01 -0700 | [diff] [blame] | 1367 | |
| 1368 | /** |
Priyank Singh | a47b6f7 | 2019-05-28 13:02:47 -0700 | [diff] [blame] | 1369 | * To be installed on the handle bar. |
| 1370 | */ |
| 1371 | private class HandleBarCloseNotificationGestureListener extends |
| 1372 | GestureDetector.SimpleOnGestureListener { |
| 1373 | |
| 1374 | @Override |
| 1375 | public boolean onScroll(MotionEvent event1, MotionEvent event2, float distanceX, |
| 1376 | float distanceY) { |
| 1377 | calculatePercentageFromBottom(event2.getRawY()); |
| 1378 | // To prevent the jump in the clip bounds while closing the notification shade using |
| 1379 | // the handle bar we should calculate the height using the diff of event1 and event2. |
| 1380 | // This will help the notification shade to clip smoothly as the event2 value changes |
| 1381 | // as event1 value will be fixed. |
| 1382 | int clipHeight = |
| 1383 | mNotificationView.getHeight() - (int) (event1.getRawY() - event2.getRawY()); |
| 1384 | setNotificationViewClipBounds(clipHeight); |
| 1385 | return true; |
| 1386 | } |
| 1387 | } |
| 1388 | |
| 1389 | /** |
| 1390 | * SystemUi version of the notification manager that overrides methods such that the |
Brad Stenning | 2ccc2a4 | 2019-04-15 10:17:01 -0700 | [diff] [blame] | 1391 | * notifications end up in the status bar layouts instead of a standalone window. |
| 1392 | */ |
| 1393 | private class CarSystemUIHeadsUpNotificationManager extends CarHeadsUpNotificationManager { |
| 1394 | |
| 1395 | CarSystemUIHeadsUpNotificationManager(Context context, |
| 1396 | NotificationClickHandlerFactory clickHandlerFactory, |
| 1397 | NotificationDataManager notificationDataManager) { |
| 1398 | super(context, clickHandlerFactory, notificationDataManager); |
| 1399 | } |
| 1400 | |
| 1401 | @Override |
| 1402 | protected View createHeadsUpPanel() { |
| 1403 | // In SystemUi the view is already in the window so just return a reference. |
| 1404 | return mStatusBarWindow.findViewById(R.id.notification_headsup); |
| 1405 | } |
| 1406 | |
| 1407 | @Override |
| 1408 | protected void addHeadsUpPanelToDisplay() { |
| 1409 | // Set the panel initial state to invisible |
| 1410 | mHeadsUpPanel.setVisibility(View.INVISIBLE); |
| 1411 | } |
| 1412 | |
| 1413 | @Override |
Priyank Singh | 8bd920f | 2019-06-04 15:21:46 -0700 | [diff] [blame] | 1414 | protected void setInternalInsetsInfo(ViewTreeObserver.InternalInsetsInfo info, |
| 1415 | HeadsUpEntry currentNotification, boolean panelExpanded) { |
| 1416 | super.setInternalInsetsInfo(info, currentNotification, mPanelExpanded); |
| 1417 | } |
| 1418 | |
| 1419 | @Override |
Brad Stenning | 2ccc2a4 | 2019-04-15 10:17:01 -0700 | [diff] [blame] | 1420 | protected void setHeadsUpVisible() { |
Priyank Singh | 7e9344f | 2019-05-07 14:30:13 -0700 | [diff] [blame] | 1421 | // if the Notifications panel is showing don't show the Heads up |
Priyank Singh | 8bd920f | 2019-06-04 15:21:46 -0700 | [diff] [blame] | 1422 | if (!mEnableHeadsUpNotificationWhenNotificationShadeOpen && mPanelExpanded) { |
Priyank Singh | 7e9344f | 2019-05-07 14:30:13 -0700 | [diff] [blame] | 1423 | return; |
| 1424 | } |
Priyank Singh | 8bd920f | 2019-06-04 15:21:46 -0700 | [diff] [blame] | 1425 | |
Brad Stenning | 2ccc2a4 | 2019-04-15 10:17:01 -0700 | [diff] [blame] | 1426 | super.setHeadsUpVisible(); |
| 1427 | if (mHeadsUpPanel.getVisibility() == View.VISIBLE) { |
| 1428 | mStatusBarWindowController.setHeadsUpShowing(true); |
| 1429 | mStatusBarWindowController.setForceStatusBarVisible(true); |
| 1430 | } |
| 1431 | } |
| 1432 | |
| 1433 | @Override |
| 1434 | protected void removeNotificationFromPanel(HeadsUpEntry currentHeadsUpNotification) { |
| 1435 | super.removeNotificationFromPanel(currentHeadsUpNotification); |
| 1436 | // If the panel ended up empty and hidden we can remove it from SystemUi |
| 1437 | if (mHeadsUpPanel.getVisibility() != View.VISIBLE) { |
| 1438 | mStatusBarWindowController.setHeadsUpShowing(false); |
| 1439 | mStatusBarWindowController.setForceStatusBarVisible(false); |
| 1440 | } |
| 1441 | } |
| 1442 | } |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 1443 | } |