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