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