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 | |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 19 | import static com.android.systemui.Dependency.ALLOW_NOTIFICATION_LONG_PRESS_NAME; |
| 20 | |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 21 | import android.animation.Animator; |
| 22 | import android.animation.AnimatorListenerAdapter; |
| 23 | import android.animation.ValueAnimator; |
Matthew Ng | 9438065 | 2019-04-08 13:43:07 -0700 | [diff] [blame] | 24 | import android.annotation.Nullable; |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 25 | import android.app.ActivityManager; |
Brad Stenning | d3ede64 | 2019-04-23 21:19:27 -0700 | [diff] [blame] | 26 | import android.car.Car; |
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; |
Priyank Singh | 956c482 | 2019-07-10 12:28:24 -0700 | [diff] [blame] | 30 | import android.content.res.Configuration; |
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; |
Dave Mankoff | 1193aa4 | 2019-10-28 17:51:26 -0400 | [diff] [blame] | 33 | import android.os.PowerManager; |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 34 | import android.util.DisplayMetrics; |
Rakesh Iyer | 74ebabe | 2016-03-11 10:10:43 -0800 | [diff] [blame] | 35 | import android.util.Log; |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 36 | import android.view.GestureDetector; |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 37 | import android.view.MotionEvent; |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 38 | import android.view.View; |
Anthony Chen | 0801a5c | 2017-03-22 09:54:37 -0700 | [diff] [blame] | 39 | import android.view.ViewGroup; |
Priyank Singh | b9ab052 | 2019-05-03 15:36:25 -0700 | [diff] [blame] | 40 | import android.view.ViewTreeObserver; |
Anthony Chen | e658cc2 | 2017-04-27 11:17:35 -0700 | [diff] [blame] | 41 | |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 42 | import androidx.annotation.NonNull; |
| 43 | import androidx.recyclerview.widget.RecyclerView; |
| 44 | |
Brad Stenning | 2ccc2a4 | 2019-04-15 10:17:01 -0700 | [diff] [blame] | 45 | import com.android.car.notification.CarHeadsUpNotificationManager; |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 46 | import com.android.car.notification.CarNotificationListener; |
| 47 | import com.android.car.notification.CarNotificationView; |
| 48 | import com.android.car.notification.CarUxRestrictionManagerWrapper; |
Brad Stenning | 2ccc2a4 | 2019-04-15 10:17:01 -0700 | [diff] [blame] | 49 | import com.android.car.notification.HeadsUpEntry; |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 50 | import com.android.car.notification.NotificationClickHandlerFactory; |
Brad Stenning | 2ccc2a4 | 2019-04-15 10:17:01 -0700 | [diff] [blame] | 51 | import com.android.car.notification.NotificationDataManager; |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 52 | import com.android.car.notification.NotificationViewController; |
| 53 | import com.android.car.notification.PreprocessingManager; |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 54 | import com.android.internal.logging.MetricsLogger; |
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; |
Heemin Seog | 032075c | 2019-11-06 16:29:12 -0800 | [diff] [blame] | 57 | import com.android.keyguard.ViewMediatorCallback; |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 58 | import com.android.systemui.BatteryMeterView; |
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; |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 62 | import com.android.systemui.UiOffloadThread; |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 63 | import com.android.systemui.assist.AssistManager; |
| 64 | import com.android.systemui.broadcast.BroadcastDispatcher; |
| 65 | import com.android.systemui.bubbles.BubbleController; |
Heemin Seog | eeca9a9 | 2019-11-08 16:16:49 -0800 | [diff] [blame] | 66 | import com.android.systemui.car.CarServiceProvider; |
Winson Chung | 2db3557 | 2017-10-09 15:08:30 -0700 | [diff] [blame] | 67 | import com.android.systemui.classifier.FalsingLog; |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 68 | import com.android.systemui.colorextraction.SysuiColorExtractor; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 69 | import com.android.systemui.fragments.FragmentHostManager; |
Heemin Seog | 032075c | 2019-11-06 16:29:12 -0800 | [diff] [blame] | 70 | import com.android.systemui.keyguard.DismissCallbackRegistry; |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 71 | import com.android.systemui.keyguard.KeyguardViewMediator; |
jovanak | 622def2 | 2019-06-11 11:51:54 -0700 | [diff] [blame] | 72 | import com.android.systemui.keyguard.ScreenLifecycle; |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 73 | import com.android.systemui.keyguard.WakefulnessLifecycle; |
Heemin Seog | fcccab7 | 2019-10-22 08:30:23 -0700 | [diff] [blame] | 74 | import com.android.systemui.navigationbar.car.CarNavigationBarController; |
Dave Mankoff | c195ea8 | 2019-06-28 16:33:25 -0400 | [diff] [blame] | 75 | import com.android.systemui.plugins.FalsingManager; |
Brad Stenning | 8d1a51c | 2018-11-20 17:34:16 -0800 | [diff] [blame] | 76 | import com.android.systemui.plugins.qs.QS; |
| 77 | import com.android.systemui.qs.car.CarQSFragment; |
Dave Mankoff | 6c64d1f | 2019-11-07 17:27:50 -0500 | [diff] [blame] | 78 | import com.android.systemui.recents.Recents; |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 79 | import com.android.systemui.recents.ScreenPinningRequest; |
Dave Mankoff | 2e48492 | 2019-10-31 12:25:08 -0400 | [diff] [blame] | 80 | import com.android.systemui.shared.plugins.PluginManager; |
Dave Mankoff | 613c7c6 | 2019-11-04 11:46:36 -0500 | [diff] [blame] | 81 | import com.android.systemui.stackdivider.Divider; |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 82 | import com.android.systemui.statusbar.CommandQueue; |
Ned Burns | f098dbf | 2019-09-13 19:17:53 -0400 | [diff] [blame] | 83 | import com.android.systemui.statusbar.FeatureFlags; |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 84 | import com.android.systemui.statusbar.FlingAnimationUtils; |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 85 | import com.android.systemui.statusbar.NavigationBarController; |
| 86 | import com.android.systemui.statusbar.NotificationListener; |
| 87 | import com.android.systemui.statusbar.NotificationLockscreenUserManager; |
| 88 | import com.android.systemui.statusbar.NotificationMediaManager; |
| 89 | import com.android.systemui.statusbar.NotificationRemoteInputManager; |
| 90 | import com.android.systemui.statusbar.NotificationViewHierarchyManager; |
| 91 | import com.android.systemui.statusbar.PulseExpansionHandler; |
Rakesh Iyer | 2790a37 | 2016-01-22 15:33:39 -0800 | [diff] [blame] | 92 | import com.android.systemui.statusbar.StatusBarState; |
Heemin Seog | afb3dbc | 2019-11-04 16:05:19 -0800 | [diff] [blame] | 93 | import com.android.systemui.statusbar.SuperStatusBarViewFactory; |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 94 | import com.android.systemui.statusbar.SysuiStatusBarStateController; |
| 95 | import com.android.systemui.statusbar.VibratorHelper; |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 96 | import com.android.systemui.statusbar.notification.BypassHeadsUpNotifier; |
| 97 | import com.android.systemui.statusbar.notification.DynamicPrivacyController; |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 98 | import com.android.systemui.statusbar.notification.NotificationAlertingManager; |
| 99 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
| 100 | import com.android.systemui.statusbar.notification.NotificationInterruptionStateProvider; |
| 101 | import com.android.systemui.statusbar.notification.NotificationWakeUpCoordinator; |
| 102 | import com.android.systemui.statusbar.notification.VisualStabilityManager; |
Ned Burns | 77050aa | 2019-10-17 21:55:24 -0400 | [diff] [blame] | 103 | import com.android.systemui.statusbar.notification.collection.init.NewNotifPipeline; |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 104 | import com.android.systemui.statusbar.notification.logging.NotificationLogger; |
| 105 | import com.android.systemui.statusbar.notification.row.NotificationGutsManager; |
| 106 | import com.android.systemui.statusbar.phone.AutoHideController; |
Dave Mankoff | bbc2f8f | 2019-10-21 12:21:29 -0400 | [diff] [blame] | 107 | import com.android.systemui.statusbar.phone.BiometricUnlockController; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 108 | import com.android.systemui.statusbar.phone.CollapsedStatusBarFragment; |
Dave Mankoff | 2aff6c3 | 2019-10-14 17:40:37 -0400 | [diff] [blame] | 109 | import com.android.systemui.statusbar.phone.DozeParameters; |
Dave Mankoff | 1193aa4 | 2019-10-28 17:51:26 -0400 | [diff] [blame] | 110 | import com.android.systemui.statusbar.phone.DozeScrimController; |
| 111 | import com.android.systemui.statusbar.phone.DozeServiceHost; |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 112 | import com.android.systemui.statusbar.phone.HeadsUpManagerPhone; |
| 113 | import com.android.systemui.statusbar.phone.KeyguardBypassController; |
| 114 | import com.android.systemui.statusbar.phone.LightBarController; |
Beverly | ea2010c | 2019-11-04 09:55:29 -0500 | [diff] [blame] | 115 | import com.android.systemui.statusbar.phone.LightsOutNotifController; |
Heemin Seog | 82b96cd | 2019-11-12 16:40:00 -0800 | [diff] [blame] | 116 | import com.android.systemui.statusbar.phone.LockscreenLockIconController; |
Dave Mankoff | a874996 | 2019-10-18 10:44:07 -0400 | [diff] [blame] | 117 | import com.android.systemui.statusbar.phone.LockscreenWallpaper; |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 118 | import com.android.systemui.statusbar.phone.NotificationGroupAlertTransferHelper; |
| 119 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
Dave Mankoff | a874996 | 2019-10-18 10:44:07 -0400 | [diff] [blame] | 120 | import com.android.systemui.statusbar.phone.ScrimController; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 121 | import com.android.systemui.statusbar.phone.StatusBar; |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 122 | import com.android.systemui.statusbar.phone.StatusBarIconController; |
Heemin Seog | 032075c | 2019-11-06 16:29:12 -0800 | [diff] [blame] | 123 | import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; |
Dave Mankoff | 4c73e65 | 2019-11-14 17:39:08 -0500 | [diff] [blame] | 124 | import com.android.systemui.statusbar.phone.StatusBarNotificationActivityStarter; |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 125 | import com.android.systemui.statusbar.phone.StatusBarWindowController; |
Dave Mankoff | 0cf8dfc | 2019-09-27 12:46:41 -0400 | [diff] [blame] | 126 | import com.android.systemui.statusbar.phone.StatusBarWindowViewController; |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 127 | import com.android.systemui.statusbar.policy.BatteryController; |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 128 | import com.android.systemui.statusbar.policy.ConfigurationController; |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 129 | import com.android.systemui.statusbar.policy.DeviceProvisionedController; |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 130 | import com.android.systemui.statusbar.policy.KeyguardStateController; |
| 131 | import com.android.systemui.statusbar.policy.NetworkController; |
| 132 | import com.android.systemui.statusbar.policy.RemoteInputQuickSettingsDisabler; |
Aran Ink | 979c976 | 2019-10-24 16:09:45 -0400 | [diff] [blame] | 133 | import com.android.systemui.statusbar.policy.RemoteInputUriController; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 134 | import com.android.systemui.statusbar.policy.UserSwitcherController; |
Dave Mankoff | a30b88b | 2019-11-05 20:21:38 -0500 | [diff] [blame] | 135 | import com.android.systemui.volume.VolumeComponent; |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 136 | |
Qiming Shi | b9dfb92 | 2017-04-13 16:23:18 +0800 | [diff] [blame] | 137 | import java.io.FileDescriptor; |
| 138 | import java.io.PrintWriter; |
| 139 | import java.util.Map; |
Dave Mankoff | 613c7c6 | 2019-11-04 11:46:36 -0500 | [diff] [blame] | 140 | import java.util.Optional; |
davidln | 5473915 | 2018-07-02 13:25:44 -0700 | [diff] [blame] | 141 | |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 142 | import javax.inject.Named; |
| 143 | |
Ned Burns | f098dbf | 2019-09-13 19:17:53 -0400 | [diff] [blame] | 144 | import dagger.Lazy; |
| 145 | |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 146 | /** |
Heemin Seog | 1a39dea | 2019-10-16 15:58:21 -0700 | [diff] [blame] | 147 | * A status bar tailored for the automotive use case. |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 148 | */ |
Heemin Seog | 26c830d | 2019-08-15 13:18:41 -0700 | [diff] [blame] | 149 | public class CarStatusBar extends StatusBar implements CarBatteryController.BatteryViewHandler { |
Rakesh Iyer | 74ebabe | 2016-03-11 10:10:43 -0800 | [diff] [blame] | 150 | private static final String TAG = "CarStatusBar"; |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 151 | // used to calculate how fast to open or close the window |
| 152 | private static final float DEFAULT_FLING_VELOCITY = 0; |
| 153 | // max time a fling animation takes |
| 154 | private static final float FLING_ANIMATION_MAX_TIME = 0.5f; |
| 155 | // acceleration rate for the fling animation |
| 156 | private static final float FLING_SPEED_UP_FACTOR = 0.6f; |
Heemin Seog | 82b96cd | 2019-11-12 16:40:00 -0800 | [diff] [blame] | 157 | |
Dave Mankoff | a874996 | 2019-10-18 10:44:07 -0400 | [diff] [blame] | 158 | private final ScrimController mScrimController; |
Heemin Seog | 82b96cd | 2019-11-12 16:40:00 -0800 | [diff] [blame] | 159 | private final StatusBarWindowViewController mStatusBarWindowViewController; |
| 160 | private final LockscreenLockIconController mLockscreenLockIconController; |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 161 | |
| 162 | private float mOpeningVelocity = DEFAULT_FLING_VELOCITY; |
| 163 | private float mClosingVelocity = DEFAULT_FLING_VELOCITY; |
Rakesh Iyer | 74ebabe | 2016-03-11 10:10:43 -0800 | [diff] [blame] | 164 | |
JianYang Liu | cf7b336 | 2019-10-24 17:19:44 -0700 | [diff] [blame] | 165 | private float mBackgroundAlphaDiff; |
| 166 | private float mInitialBackgroundAlpha; |
| 167 | |
Heemin Seog | eeca9a9 | 2019-11-08 16:16:49 -0800 | [diff] [blame] | 168 | private final Lazy<FullscreenUserSwitcher> mFullscreenUserSwitcherLazy; |
Rakesh Iyer | 2790a37 | 2016-01-22 15:33:39 -0800 | [diff] [blame] | 169 | private FullscreenUserSwitcher mFullscreenUserSwitcher; |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 170 | |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 171 | private CarBatteryController mCarBatteryController; |
| 172 | private BatteryMeterView mBatteryMeterView; |
Anthony Chen | e658cc2 | 2017-04-27 11:17:35 -0700 | [diff] [blame] | 173 | private Drawable mNotificationPanelBackground; |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 174 | |
Qiming Shi | b9dfb92 | 2017-04-13 16:23:18 +0800 | [diff] [blame] | 175 | private final Object mQueueLock = new Object(); |
Heemin Seog | fcccab7 | 2019-10-22 08:30:23 -0700 | [diff] [blame] | 176 | private final CarNavigationBarController mCarNavigationBarController; |
Heemin Seog | eeca9a9 | 2019-11-08 16:16:49 -0800 | [diff] [blame] | 177 | private final Lazy<DrivingStateHelper> mDrivingStateHelperLazy; |
| 178 | private final Lazy<PowerManagerHelper> mPowerManagerHelperLazy; |
| 179 | private final CarServiceProvider mCarServiceProvider; |
Heemin Seog | d59786b | 2019-11-08 09:20:26 -0800 | [diff] [blame] | 180 | |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 181 | private DeviceProvisionedController mDeviceProvisionedController; |
Jonathan Koo | 007ff07 | 2019-05-10 09:24:08 -0700 | [diff] [blame] | 182 | private PowerManagerHelper mPowerManagerHelper; |
| 183 | private FlingAnimationUtils mFlingAnimationUtils; |
Jonathan Koo | 007ff07 | 2019-05-10 09:24:08 -0700 | [diff] [blame] | 184 | private NotificationDataManager mNotificationDataManager; |
| 185 | private NotificationClickHandlerFactory mNotificationClickHandlerFactory; |
jovanak | 622def2 | 2019-06-11 11:51:54 -0700 | [diff] [blame] | 186 | private ScreenLifecycle mScreenLifecycle; |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 187 | |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 188 | // The container for the notifications. |
| 189 | private CarNotificationView mNotificationView; |
| 190 | private RecyclerView mNotificationList; |
Priyank Singh | 647f9e6 | 2019-05-16 15:19:53 -0700 | [diff] [blame] | 191 | // The handler bar view at the bottom of notification shade. |
| 192 | private View mHandleBar; |
Adora Zhang | daea911 | 2019-04-11 17:47:40 -0700 | [diff] [blame] | 193 | // The controller for the notification view. |
| 194 | private NotificationViewController mNotificationViewController; |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 195 | // The state of if the notification list is currently showing the bottom. |
| 196 | private boolean mNotificationListAtBottom; |
| 197 | // Was the notification list at the bottom when the user first touched the screen |
| 198 | private boolean mNotificationListAtBottomAtTimeOfTouch; |
Heemin Seog | 956cd51 | 2019-10-03 16:15:50 -0700 | [diff] [blame] | 199 | // To be attached to the top navigation bar (i.e. status bar) to pull down the notification |
| 200 | // panel. |
| 201 | private View.OnTouchListener mTopNavBarNotificationTouchListener; |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 202 | // To be attached to the navigation bars such that they can close the notification panel if |
| 203 | // it's open. |
| 204 | private View.OnTouchListener mNavBarNotificationTouchListener; |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 205 | // Percentage from top of the screen after which the notification shade will open. This value |
| 206 | // will be used while opening the notification shade. |
| 207 | private int mSettleOpenPercentage; |
| 208 | // Percentage from top of the screen below which the notification shade will close. This |
| 209 | // value will be used while closing the notification shade. |
| 210 | private int mSettleClosePercentage; |
| 211 | // Percentage of notification shade open from top of the screen. |
| 212 | private int mPercentageFromBottom; |
| 213 | // If notification shade is animation to close or to open. |
| 214 | private boolean mIsNotificationAnimating; |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 215 | // Tracks when the notification shade is being scrolled. This refers to the glass pane being |
| 216 | // scrolled not the recycler view. |
| 217 | private boolean mIsTracking; |
| 218 | private float mFirstTouchDownOnGlassPane; |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 219 | // If the notification card inside the recycler view is being swiped. |
| 220 | private boolean mIsNotificationCardSwiping; |
| 221 | // If notification shade is being swiped vertically to close. |
| 222 | private boolean mIsSwipingVerticallyToClose; |
Priyank Singh | 8bd920f | 2019-06-04 15:21:46 -0700 | [diff] [blame] | 223 | // Whether heads-up notifications should be shown when shade is open. |
| 224 | private boolean mEnableHeadsUpNotificationWhenNotificationShadeOpen; |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 225 | |
Keun young Park | faae648 | 2019-10-11 20:00:22 -0700 | [diff] [blame] | 226 | private CarUxRestrictionManagerWrapper mCarUxRestrictionManagerWrapper; |
| 227 | |
Jonathan Koo | 007ff07 | 2019-05-10 09:24:08 -0700 | [diff] [blame] | 228 | private final CarPowerStateListener mCarPowerStateListener = |
| 229 | (int state) -> { |
| 230 | // When the car powers on, clear all notifications and mute/unread states. |
| 231 | Log.d(TAG, "New car power state: " + state); |
| 232 | if (state == CarPowerStateListener.ON) { |
| 233 | if (mNotificationClickHandlerFactory != null) { |
| 234 | mNotificationClickHandlerFactory.clearAllNotifications(); |
| 235 | } |
| 236 | if (mNotificationDataManager != null) { |
| 237 | mNotificationDataManager.clearAll(); |
| 238 | } |
| 239 | } |
| 240 | }; |
| 241 | |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 242 | public CarStatusBar( |
Dave Mankoff | a5d8a39 | 2019-10-10 12:21:09 -0400 | [diff] [blame] | 243 | Context context, |
Ned Burns | f098dbf | 2019-09-13 19:17:53 -0400 | [diff] [blame] | 244 | FeatureFlags featureFlags, |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 245 | LightBarController lightBarController, |
| 246 | AutoHideController autoHideController, |
| 247 | KeyguardUpdateMonitor keyguardUpdateMonitor, |
| 248 | StatusBarIconController statusBarIconController, |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 249 | PulseExpansionHandler pulseExpansionHandler, |
| 250 | NotificationWakeUpCoordinator notificationWakeUpCoordinator, |
| 251 | KeyguardBypassController keyguardBypassController, |
| 252 | KeyguardStateController keyguardStateController, |
| 253 | HeadsUpManagerPhone headsUpManagerPhone, |
| 254 | DynamicPrivacyController dynamicPrivacyController, |
| 255 | BypassHeadsUpNotifier bypassHeadsUpNotifier, |
| 256 | @Named(ALLOW_NOTIFICATION_LONG_PRESS_NAME) boolean allowNotificationLongPress, |
Ned Burns | f098dbf | 2019-09-13 19:17:53 -0400 | [diff] [blame] | 257 | Lazy<NewNotifPipeline> newNotifPipeline, |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 258 | FalsingManager falsingManager, |
| 259 | BroadcastDispatcher broadcastDispatcher, |
| 260 | RemoteInputQuickSettingsDisabler remoteInputQuickSettingsDisabler, |
| 261 | NotificationGutsManager notificationGutsManager, |
| 262 | NotificationLogger notificationLogger, |
| 263 | NotificationEntryManager notificationEntryManager, |
| 264 | NotificationInterruptionStateProvider notificationInterruptionStateProvider, |
| 265 | NotificationViewHierarchyManager notificationViewHierarchyManager, |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 266 | KeyguardViewMediator keyguardViewMediator, |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 267 | NotificationAlertingManager notificationAlertingManager, |
| 268 | DisplayMetrics displayMetrics, |
| 269 | MetricsLogger metricsLogger, |
| 270 | UiOffloadThread uiOffloadThread, |
| 271 | NotificationMediaManager notificationMediaManager, |
| 272 | NotificationLockscreenUserManager lockScreenUserManager, |
| 273 | NotificationRemoteInputManager remoteInputManager, |
| 274 | UserSwitcherController userSwitcherController, |
| 275 | NetworkController networkController, |
| 276 | BatteryController batteryController, |
| 277 | SysuiColorExtractor colorExtractor, |
| 278 | ScreenLifecycle screenLifecycle, |
| 279 | WakefulnessLifecycle wakefulnessLifecycle, |
| 280 | SysuiStatusBarStateController statusBarStateController, |
| 281 | VibratorHelper vibratorHelper, |
| 282 | BubbleController bubbleController, |
| 283 | NotificationGroupManager groupManager, |
| 284 | NotificationGroupAlertTransferHelper groupAlertTransferHelper, |
| 285 | VisualStabilityManager visualStabilityManager, |
| 286 | DeviceProvisionedController deviceProvisionedController, |
| 287 | NavigationBarController navigationBarController, |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 288 | Lazy<AssistManager> assistManagerLazy, |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 289 | NotificationListener notificationListener, |
| 290 | ConfigurationController configurationController, |
Dave Mankoff | 0cf8dfc | 2019-09-27 12:46:41 -0400 | [diff] [blame] | 291 | StatusBarWindowController statusBarWindowController, |
Heemin Seog | 82b96cd | 2019-11-12 16:40:00 -0800 | [diff] [blame] | 292 | StatusBarWindowViewController statusBarWindowViewController, |
| 293 | LockscreenLockIconController lockscreenLockIconController, |
Dave Mankoff | a874996 | 2019-10-18 10:44:07 -0400 | [diff] [blame] | 294 | DozeParameters dozeParameters, |
| 295 | ScrimController scrimController, |
Heemin Seog | 1a39dea | 2019-10-16 15:58:21 -0700 | [diff] [blame] | 296 | Lazy<LockscreenWallpaper> lockscreenWallpaperLazy, |
Dave Mankoff | bbc2f8f | 2019-10-21 12:21:29 -0400 | [diff] [blame] | 297 | Lazy<BiometricUnlockController> biometricUnlockControllerLazy, |
Dave Mankoff | 1193aa4 | 2019-10-28 17:51:26 -0400 | [diff] [blame] | 298 | DozeServiceHost dozeServiceHost, |
| 299 | PowerManager powerManager, |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 300 | ScreenPinningRequest screenPinningRequest, |
Dave Mankoff | 1193aa4 | 2019-10-28 17:51:26 -0400 | [diff] [blame] | 301 | DozeScrimController dozeScrimController, |
Dave Mankoff | a30b88b | 2019-11-05 20:21:38 -0500 | [diff] [blame] | 302 | VolumeComponent volumeComponent, |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 303 | CommandQueue commandQueue, |
Dave Mankoff | 6c64d1f | 2019-11-07 17:27:50 -0500 | [diff] [blame] | 304 | Optional<Recents> recents, |
Dave Mankoff | 2e48492 | 2019-10-31 12:25:08 -0400 | [diff] [blame] | 305 | PluginManager pluginManager, |
Aran Ink | 979c976 | 2019-10-24 16:09:45 -0400 | [diff] [blame] | 306 | RemoteInputUriController remoteInputUriController, |
Dave Mankoff | 613c7c6 | 2019-11-04 11:46:36 -0500 | [diff] [blame] | 307 | Optional<Divider> dividerOptional, |
Heemin Seog | afb3dbc | 2019-11-04 16:05:19 -0800 | [diff] [blame] | 308 | SuperStatusBarViewFactory superStatusBarViewFactory, |
Beverly | ea2010c | 2019-11-04 09:55:29 -0500 | [diff] [blame] | 309 | LightsOutNotifController lightsOutNotifController, |
Dave Mankoff | 4c73e65 | 2019-11-14 17:39:08 -0500 | [diff] [blame] | 310 | StatusBarNotificationActivityStarter.Builder |
| 311 | statusBarNotificationActivityStarterBuilder, |
Heemin Seog | 032075c | 2019-11-06 16:29:12 -0800 | [diff] [blame] | 312 | StatusBarKeyguardViewManager statusBarKeyguardViewManager, |
| 313 | ViewMediatorCallback viewMediatorCallback, |
| 314 | DismissCallbackRegistry dismissCallbackRegistry, |
Heemin Seog | 1a39dea | 2019-10-16 15:58:21 -0700 | [diff] [blame] | 315 | /* Car Settings injected components. */ |
Heemin Seog | eeca9a9 | 2019-11-08 16:16:49 -0800 | [diff] [blame] | 316 | CarServiceProvider carServiceProvider, |
| 317 | Lazy<DrivingStateHelper> drivingStateHelperLazy, |
| 318 | Lazy<PowerManagerHelper> powerManagerHelperLazy, |
| 319 | Lazy<FullscreenUserSwitcher> fullscreenUserSwitcherLazy, |
Heemin Seog | fcccab7 | 2019-10-22 08:30:23 -0700 | [diff] [blame] | 320 | CarNavigationBarController carNavigationBarController) { |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 321 | super( |
Dave Mankoff | a5d8a39 | 2019-10-10 12:21:09 -0400 | [diff] [blame] | 322 | context, |
Ned Burns | f098dbf | 2019-09-13 19:17:53 -0400 | [diff] [blame] | 323 | featureFlags, |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 324 | lightBarController, |
| 325 | autoHideController, |
| 326 | keyguardUpdateMonitor, |
| 327 | statusBarIconController, |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 328 | pulseExpansionHandler, |
| 329 | notificationWakeUpCoordinator, |
| 330 | keyguardBypassController, |
| 331 | keyguardStateController, |
| 332 | headsUpManagerPhone, |
| 333 | dynamicPrivacyController, |
| 334 | bypassHeadsUpNotifier, |
| 335 | allowNotificationLongPress, |
Ned Burns | f098dbf | 2019-09-13 19:17:53 -0400 | [diff] [blame] | 336 | newNotifPipeline, |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 337 | falsingManager, |
| 338 | broadcastDispatcher, |
| 339 | remoteInputQuickSettingsDisabler, |
| 340 | notificationGutsManager, |
| 341 | notificationLogger, |
| 342 | notificationEntryManager, |
| 343 | notificationInterruptionStateProvider, |
| 344 | notificationViewHierarchyManager, |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 345 | keyguardViewMediator, |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 346 | notificationAlertingManager, |
| 347 | displayMetrics, |
| 348 | metricsLogger, |
| 349 | uiOffloadThread, |
| 350 | notificationMediaManager, |
| 351 | lockScreenUserManager, |
| 352 | remoteInputManager, |
| 353 | userSwitcherController, |
| 354 | networkController, |
| 355 | batteryController, |
| 356 | colorExtractor, |
| 357 | screenLifecycle, |
| 358 | wakefulnessLifecycle, |
| 359 | statusBarStateController, |
| 360 | vibratorHelper, |
| 361 | bubbleController, |
| 362 | groupManager, |
| 363 | groupAlertTransferHelper, |
| 364 | visualStabilityManager, |
| 365 | deviceProvisionedController, |
| 366 | navigationBarController, |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 367 | assistManagerLazy, |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 368 | notificationListener, |
| 369 | configurationController, |
Dave Mankoff | 0cf8dfc | 2019-09-27 12:46:41 -0400 | [diff] [blame] | 370 | statusBarWindowController, |
Heemin Seog | 82b96cd | 2019-11-12 16:40:00 -0800 | [diff] [blame] | 371 | statusBarWindowViewController, |
| 372 | lockscreenLockIconController, |
Dave Mankoff | a874996 | 2019-10-18 10:44:07 -0400 | [diff] [blame] | 373 | dozeParameters, |
| 374 | scrimController, |
Lucas Dupin | 64171fe | 2019-10-30 14:28:29 -0700 | [diff] [blame] | 375 | null /* keyguardLiftController */, |
Dave Mankoff | bbc2f8f | 2019-10-21 12:21:29 -0400 | [diff] [blame] | 376 | lockscreenWallpaperLazy, |
Dave Mankoff | 1193aa4 | 2019-10-28 17:51:26 -0400 | [diff] [blame] | 377 | biometricUnlockControllerLazy, |
| 378 | dozeServiceHost, |
| 379 | powerManager, |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 380 | screenPinningRequest, |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 381 | dozeScrimController, |
Dave Mankoff | a30b88b | 2019-11-05 20:21:38 -0500 | [diff] [blame] | 382 | volumeComponent, |
Dave Mankoff | 2e48492 | 2019-10-31 12:25:08 -0400 | [diff] [blame] | 383 | commandQueue, |
Dave Mankoff | 6c64d1f | 2019-11-07 17:27:50 -0500 | [diff] [blame] | 384 | recents, |
Aran Ink | 979c976 | 2019-10-24 16:09:45 -0400 | [diff] [blame] | 385 | pluginManager, |
Heemin Seog | afb3dbc | 2019-11-04 16:05:19 -0800 | [diff] [blame] | 386 | remoteInputUriController, |
Dave Mankoff | 613c7c6 | 2019-11-04 11:46:36 -0500 | [diff] [blame] | 387 | dividerOptional, |
Beverly | ea2010c | 2019-11-04 09:55:29 -0500 | [diff] [blame] | 388 | lightsOutNotifController, |
Dave Mankoff | 4c73e65 | 2019-11-14 17:39:08 -0500 | [diff] [blame] | 389 | statusBarNotificationActivityStarterBuilder, |
Heemin Seog | 032075c | 2019-11-06 16:29:12 -0800 | [diff] [blame] | 390 | superStatusBarViewFactory, |
| 391 | statusBarKeyguardViewManager, |
| 392 | viewMediatorCallback, |
| 393 | dismissCallbackRegistry); |
Dave Mankoff | a874996 | 2019-10-18 10:44:07 -0400 | [diff] [blame] | 394 | mScrimController = scrimController; |
Heemin Seog | 82b96cd | 2019-11-12 16:40:00 -0800 | [diff] [blame] | 395 | mStatusBarWindowViewController = statusBarWindowViewController; |
| 396 | mLockscreenLockIconController = lockscreenLockIconController; |
Heemin Seog | d59786b | 2019-11-08 09:20:26 -0800 | [diff] [blame] | 397 | mDeviceProvisionedController = deviceProvisionedController; |
Heemin Seog | eeca9a9 | 2019-11-08 16:16:49 -0800 | [diff] [blame] | 398 | mCarServiceProvider = carServiceProvider; |
| 399 | mDrivingStateHelperLazy = drivingStateHelperLazy; |
| 400 | mPowerManagerHelperLazy = powerManagerHelperLazy; |
| 401 | mFullscreenUserSwitcherLazy = fullscreenUserSwitcherLazy; |
Heemin Seog | fcccab7 | 2019-10-22 08:30:23 -0700 | [diff] [blame] | 402 | mCarNavigationBarController = carNavigationBarController; |
Dave Mankoff | bb9575f | 2019-10-02 12:23:49 -0400 | [diff] [blame] | 403 | } |
| 404 | |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 405 | @Override |
| 406 | public void start() { |
jovanak | 4c4971d | 2019-08-19 16:32:50 -0700 | [diff] [blame] | 407 | // Need to initialize screen lifecycle before calling super.start - before switcher is |
| 408 | // created. |
| 409 | mScreenLifecycle = Dependency.get(ScreenLifecycle.class); |
| 410 | mScreenLifecycle.addObserver(mScreenObserver); |
| 411 | |
Heemin Seog | 82b96cd | 2019-11-12 16:40:00 -0800 | [diff] [blame] | 412 | // Notification bar related setup. |
JianYang Liu | cf7b336 | 2019-10-24 17:19:44 -0700 | [diff] [blame] | 413 | mInitialBackgroundAlpha = (float) mContext.getResources().getInteger( |
Heemin Seog | 82b96cd | 2019-11-12 16:40:00 -0800 | [diff] [blame] | 414 | R.integer.config_initialNotificationBackgroundAlpha) / 100; |
JianYang Liu | cf7b336 | 2019-10-24 17:19:44 -0700 | [diff] [blame] | 415 | if (mInitialBackgroundAlpha < 0 || mInitialBackgroundAlpha > 100) { |
| 416 | throw new RuntimeException( |
Heemin Seog | 82b96cd | 2019-11-12 16:40:00 -0800 | [diff] [blame] | 417 | "Unable to setup notification bar due to incorrect initial background alpha" |
| 418 | + " percentage"); |
JianYang Liu | cf7b336 | 2019-10-24 17:19:44 -0700 | [diff] [blame] | 419 | } |
| 420 | float finalBackgroundAlpha = Math.max( |
Heemin Seog | 82b96cd | 2019-11-12 16:40:00 -0800 | [diff] [blame] | 421 | mInitialBackgroundAlpha, |
| 422 | (float) mContext.getResources().getInteger( |
| 423 | R.integer.config_finalNotificationBackgroundAlpha) / 100); |
JianYang Liu | cf7b336 | 2019-10-24 17:19:44 -0700 | [diff] [blame] | 424 | if (finalBackgroundAlpha < 0 || finalBackgroundAlpha > 100) { |
| 425 | throw new RuntimeException( |
Heemin Seog | 82b96cd | 2019-11-12 16:40:00 -0800 | [diff] [blame] | 426 | "Unable to setup notification bar due to incorrect final background alpha" |
| 427 | + " percentage"); |
JianYang Liu | cf7b336 | 2019-10-24 17:19:44 -0700 | [diff] [blame] | 428 | } |
| 429 | mBackgroundAlphaDiff = finalBackgroundAlpha - mInitialBackgroundAlpha; |
| 430 | |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 431 | super.start(); |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 432 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 433 | mNotificationPanel.setScrollingEnabled(true); |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 434 | mSettleOpenPercentage = mContext.getResources().getInteger( |
| 435 | R.integer.notification_settle_open_percentage); |
| 436 | mSettleClosePercentage = mContext.getResources().getInteger( |
| 437 | R.integer.notification_settle_close_percentage); |
Jonathan Koo | 007ff07 | 2019-05-10 09:24:08 -0700 | [diff] [blame] | 438 | mFlingAnimationUtils = new FlingAnimationUtils(mContext, |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 439 | FLING_ANIMATION_MAX_TIME, FLING_SPEED_UP_FACTOR); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 440 | |
Rakesh Iyer | 545e47d | 2017-01-23 18:10:21 -0800 | [diff] [blame] | 441 | createBatteryController(); |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 442 | mCarBatteryController.startListening(); |
Brad Stenning | 38b46f8 | 2018-03-27 13:57:29 -0700 | [diff] [blame] | 443 | |
Heemin Seog | eeca9a9 | 2019-11-08 16:16:49 -0800 | [diff] [blame] | 444 | mPowerManagerHelper = mPowerManagerHelperLazy.get(); |
| 445 | mPowerManagerHelper.setCarPowerStateListener(mCarPowerStateListener); |
Jonathan Koo | 007ff07 | 2019-05-10 09:24:08 -0700 | [diff] [blame] | 446 | mPowerManagerHelper.connectToCarService(); |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Brad Stenning | 7e41181 | 2018-04-13 22:52:39 -0700 | [diff] [blame] | 449 | /** |
| 450 | * Allows for showing or hiding just the navigation bars. This is indented to be used when |
| 451 | * the full screen user selector is shown. |
| 452 | */ |
davidln | 5473915 | 2018-07-02 13:25:44 -0700 | [diff] [blame] | 453 | void setNavBarVisibility(@View.Visibility int visibility) { |
Heemin Seog | 8d6ec6a7 | 2019-10-25 14:34:11 -0700 | [diff] [blame] | 454 | mCarNavigationBarController.setBottomWindowVisibility(visibility); |
| 455 | mCarNavigationBarController.setLeftWindowVisibility(visibility); |
| 456 | mCarNavigationBarController.setRightWindowVisibility(visibility); |
Brad Stenning | 7e41181 | 2018-04-13 22:52:39 -0700 | [diff] [blame] | 457 | } |
| 458 | |
Brad Stenning | 7e41181 | 2018-04-13 22:52:39 -0700 | [diff] [blame] | 459 | @Override |
| 460 | public boolean hideKeyguard() { |
| 461 | boolean result = super.hideKeyguard(); |
Heemin Seog | d59786b | 2019-11-08 09:20:26 -0800 | [diff] [blame] | 462 | mCarNavigationBarController.hideAllKeyguardButtons( |
| 463 | mDeviceProvisionedController.isCurrentUserSetup()); |
Brad Stenning | 7e41181 | 2018-04-13 22:52:39 -0700 | [diff] [blame] | 464 | return result; |
| 465 | } |
| 466 | |
Brad Stenning | 7e41181 | 2018-04-13 22:52:39 -0700 | [diff] [blame] | 467 | @Override |
| 468 | public void showKeyguard() { |
| 469 | super.showKeyguard(); |
Heemin Seog | d59786b | 2019-11-08 09:20:26 -0800 | [diff] [blame] | 470 | mCarNavigationBarController.showAllKeyguardButtons( |
| 471 | mDeviceProvisionedController.isCurrentUserSetup()); |
Brad Stenning | 7e41181 | 2018-04-13 22:52:39 -0700 | [diff] [blame] | 472 | } |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 473 | |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 474 | @Override |
Matthew Ng | 9438065 | 2019-04-08 13:43:07 -0700 | [diff] [blame] | 475 | protected void makeStatusBarView(@Nullable RegisterStatusBarResult result) { |
| 476 | super.makeStatusBarView(result); |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 477 | |
Anthony Chen | e658cc2 | 2017-04-27 11:17:35 -0700 | [diff] [blame] | 478 | mNotificationPanelBackground = getDefaultWallpaper(); |
| 479 | mScrimController.setScrimBehindDrawable(mNotificationPanelBackground); |
| 480 | |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 481 | FragmentHostManager manager = FragmentHostManager.get(mStatusBarWindow); |
| 482 | manager.addTagListener(CollapsedStatusBarFragment.TAG, (tag, fragment) -> { |
Anthony Chen | e658cc2 | 2017-04-27 11:17:35 -0700 | [diff] [blame] | 483 | mBatteryMeterView = fragment.getView().findViewById(R.id.battery); |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 484 | |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 485 | // By default, the BatteryMeterView should not be visible. It will be toggled |
| 486 | // when a device has connected by bluetooth. |
| 487 | mBatteryMeterView.setVisibility(View.GONE); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 488 | }); |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 489 | |
| 490 | connectNotificationsUI(); |
| 491 | } |
| 492 | |
| 493 | /** |
| 494 | * Attach the notification listeners and controllers to the UI as well as build all the |
| 495 | * touch listeners needed for opening and closing the notification panel |
| 496 | */ |
| 497 | private void connectNotificationsUI() { |
Heemin Seog | 956cd51 | 2019-10-03 16:15:50 -0700 | [diff] [blame] | 498 | // Attached to the top navigation bar (i.e. status bar) to detect pull down of the |
| 499 | // notification shade. |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 500 | GestureDetector openGestureDetector = new GestureDetector(mContext, |
| 501 | new OpenNotificationGestureListener() { |
| 502 | @Override |
| 503 | protected void openNotification() { |
| 504 | animateExpandNotificationsPanel(); |
| 505 | } |
| 506 | }); |
| 507 | // Attached to the notification ui to detect close request of the notification shade. |
| 508 | GestureDetector closeGestureDetector = new GestureDetector(mContext, |
| 509 | new CloseNotificationGestureListener() { |
| 510 | @Override |
| 511 | protected void close() { |
Brad Stenning | 44d3907 | 2019-04-20 11:53:17 -0700 | [diff] [blame] | 512 | if (mPanelExpanded) { |
| 513 | animateCollapsePanels(); |
| 514 | } |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 515 | } |
| 516 | }); |
| 517 | // Attached to the NavBars to close the notification shade |
| 518 | GestureDetector navBarCloseNotificationGestureDetector = new GestureDetector(mContext, |
| 519 | new NavBarCloseNotificationGestureListener() { |
| 520 | @Override |
| 521 | protected void close() { |
Brad Stenning | 44d3907 | 2019-04-20 11:53:17 -0700 | [diff] [blame] | 522 | if (mPanelExpanded) { |
| 523 | animateCollapsePanels(); |
| 524 | } |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 525 | } |
| 526 | }); |
Priyank Singh | a47b6f7 | 2019-05-28 13:02:47 -0700 | [diff] [blame] | 527 | |
| 528 | // Attached to the Handle bar to close the notification shade |
| 529 | GestureDetector handleBarCloseNotificationGestureDetector = new GestureDetector(mContext, |
| 530 | new HandleBarCloseNotificationGestureListener()); |
| 531 | |
Heemin Seog | 956cd51 | 2019-10-03 16:15:50 -0700 | [diff] [blame] | 532 | mTopNavBarNotificationTouchListener = (v, event) -> { |
Heemin Seog | d59786b | 2019-11-08 09:20:26 -0800 | [diff] [blame] | 533 | if (!mDeviceProvisionedController.isCurrentUserSetup()) { |
Heemin Seog | 956cd51 | 2019-10-03 16:15:50 -0700 | [diff] [blame] | 534 | return true; |
| 535 | } |
| 536 | boolean consumed = openGestureDetector.onTouchEvent(event); |
| 537 | if (consumed) { |
| 538 | return true; |
| 539 | } |
| 540 | maybeCompleteAnimation(event); |
| 541 | return true; |
| 542 | }; |
| 543 | |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 544 | mNavBarNotificationTouchListener = |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 545 | (v, event) -> { |
| 546 | boolean consumed = navBarCloseNotificationGestureDetector.onTouchEvent(event); |
| 547 | if (consumed) { |
| 548 | return true; |
| 549 | } |
Priyank Singh | a47b6f7 | 2019-05-28 13:02:47 -0700 | [diff] [blame] | 550 | maybeCompleteAnimation(event); |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 551 | return true; |
| 552 | }; |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 553 | |
kwaky | 15fee3e | 2019-06-17 11:20:47 -0700 | [diff] [blame] | 554 | mNotificationClickHandlerFactory = new NotificationClickHandlerFactory(mBarService); |
| 555 | mNotificationClickHandlerFactory.registerClickListener((launchResult, alertEntry) -> { |
| 556 | if (launchResult == ActivityManager.START_TASK_TO_FRONT |
| 557 | || launchResult == ActivityManager.START_SUCCESS) { |
| 558 | animateCollapsePanels(); |
| 559 | } |
| 560 | }); |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 561 | CarNotificationListener carNotificationListener = new CarNotificationListener(); |
Keun young Park | faae648 | 2019-10-11 20:00:22 -0700 | [diff] [blame] | 562 | mCarUxRestrictionManagerWrapper = new CarUxRestrictionManagerWrapper(); |
Jonathan Koo | c9f71aa | 2019-05-06 08:20:14 -0700 | [diff] [blame] | 563 | |
Jonathan Koo | 007ff07 | 2019-05-10 09:24:08 -0700 | [diff] [blame] | 564 | mNotificationDataManager = new NotificationDataManager(); |
Heemin Seog | ba4cd51 | 2019-11-22 08:35:57 -0800 | [diff] [blame] | 565 | mNotificationDataManager.setOnUnseenCountUpdateListener(this::onUnseenCountUpdate); |
Jonathan Koo | c9f71aa | 2019-05-06 08:20:14 -0700 | [diff] [blame] | 566 | |
Priyank Singh | 8bd920f | 2019-06-04 15:21:46 -0700 | [diff] [blame] | 567 | mEnableHeadsUpNotificationWhenNotificationShadeOpen = mContext.getResources().getBoolean( |
| 568 | R.bool.config_enableHeadsUpNotificationWhenNotificationShadeOpen); |
Brad Stenning | 2ccc2a4 | 2019-04-15 10:17:01 -0700 | [diff] [blame] | 569 | CarHeadsUpNotificationManager carHeadsUpNotificationManager = |
Jonathan Koo | 007ff07 | 2019-05-10 09:24:08 -0700 | [diff] [blame] | 570 | new CarSystemUIHeadsUpNotificationManager(mContext, |
| 571 | mNotificationClickHandlerFactory, mNotificationDataManager); |
| 572 | mNotificationClickHandlerFactory.setNotificationDataManager(mNotificationDataManager); |
Brad Stenning | 2ccc2a4 | 2019-04-15 10:17:01 -0700 | [diff] [blame] | 573 | |
Keun young Park | faae648 | 2019-10-11 20:00:22 -0700 | [diff] [blame] | 574 | carNotificationListener.registerAsSystemService(mContext, mCarUxRestrictionManagerWrapper, |
Jonathan Koo | 007ff07 | 2019-05-10 09:24:08 -0700 | [diff] [blame] | 575 | carHeadsUpNotificationManager, mNotificationDataManager); |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 576 | |
| 577 | mNotificationView = mStatusBarWindow.findViewById(R.id.notification_view); |
| 578 | View glassPane = mStatusBarWindow.findViewById(R.id.glass_pane); |
Priyank Singh | 647f9e6 | 2019-05-16 15:19:53 -0700 | [diff] [blame] | 579 | mHandleBar = mStatusBarWindow.findViewById(R.id.handle_bar); |
Jonathan Koo | 007ff07 | 2019-05-10 09:24:08 -0700 | [diff] [blame] | 580 | mNotificationView.setClickHandlerFactory(mNotificationClickHandlerFactory); |
| 581 | mNotificationView.setNotificationDataManager(mNotificationDataManager); |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 582 | |
| 583 | // The glass pane is used to view touch events before passed to the notification list. |
| 584 | // This allows us to initialize gesture listeners and detect when to close the notifications |
| 585 | glassPane.setOnTouchListener((v, event) -> { |
| 586 | if (event.getActionMasked() == MotionEvent.ACTION_UP) { |
| 587 | mNotificationListAtBottomAtTimeOfTouch = false; |
| 588 | } |
| 589 | if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 590 | mFirstTouchDownOnGlassPane = event.getRawX(); |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 591 | mNotificationListAtBottomAtTimeOfTouch = mNotificationListAtBottom; |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 592 | // Reset the tracker when there is a touch down on the glass pane. |
| 593 | mIsTracking = false; |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 594 | // Pass the down event to gesture detector so that it knows where the touch event |
| 595 | // started. |
| 596 | closeGestureDetector.onTouchEvent(event); |
| 597 | } |
| 598 | return false; |
| 599 | }); |
Priyank Singh | a47b6f7 | 2019-05-28 13:02:47 -0700 | [diff] [blame] | 600 | |
| 601 | mHandleBar.setOnTouchListener((v, event) -> { |
| 602 | handleBarCloseNotificationGestureDetector.onTouchEvent(event); |
| 603 | maybeCompleteAnimation(event); |
| 604 | return true; |
| 605 | }); |
| 606 | |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 607 | mNotificationList = mNotificationView.findViewById(R.id.notifications); |
| 608 | mNotificationList.addOnScrollListener(new RecyclerView.OnScrollListener() { |
| 609 | @Override |
| 610 | public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { |
| 611 | super.onScrolled(recyclerView, dx, dy); |
| 612 | if (!mNotificationList.canScrollVertically(1)) { |
| 613 | mNotificationListAtBottom = true; |
| 614 | return; |
| 615 | } |
| 616 | mNotificationListAtBottom = false; |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 617 | mIsSwipingVerticallyToClose = false; |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 618 | mNotificationListAtBottomAtTimeOfTouch = false; |
| 619 | } |
| 620 | }); |
| 621 | mNotificationList.setOnTouchListener(new View.OnTouchListener() { |
| 622 | @Override |
| 623 | public boolean onTouch(View v, MotionEvent event) { |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 624 | mIsNotificationCardSwiping = Math.abs(mFirstTouchDownOnGlassPane - event.getRawX()) |
| 625 | > SWIPE_MAX_OFF_PATH; |
| 626 | if (mNotificationListAtBottomAtTimeOfTouch && mNotificationListAtBottom) { |
| 627 | // We need to save the state here as if notification card is swiping we will |
| 628 | // change the mNotificationListAtBottomAtTimeOfTouch. This is to protect |
| 629 | // closing the notification shade while the notification card is being swiped. |
| 630 | mIsSwipingVerticallyToClose = true; |
| 631 | } |
| 632 | |
| 633 | // If the card is swiping we should not allow the notification shade to close. |
| 634 | // Hence setting mNotificationListAtBottomAtTimeOfTouch to false will stop that |
| 635 | // for us. We are also checking for mIsTracking because while swiping the |
| 636 | // notification shade to close if the user goes a bit horizontal while swiping |
| 637 | // upwards then also this should close. |
| 638 | if (mIsNotificationCardSwiping && !mIsTracking) { |
| 639 | mNotificationListAtBottomAtTimeOfTouch = false; |
| 640 | } |
| 641 | |
Priyank Singh | bae09ae | 2019-04-25 18:17:02 -0700 | [diff] [blame] | 642 | boolean handled = closeGestureDetector.onTouchEvent(event); |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 643 | boolean isTracking = mIsTracking; |
Priyank Singh | 647f9e6 | 2019-05-16 15:19:53 -0700 | [diff] [blame] | 644 | Rect rect = mNotificationView.getClipBounds(); |
Priyank Singh | f391286 | 2019-04-22 10:41:58 -0700 | [diff] [blame] | 645 | float clippedHeight = 0; |
| 646 | if (rect != null) { |
| 647 | clippedHeight = rect.bottom; |
| 648 | } |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 649 | if (!handled && event.getActionMasked() == MotionEvent.ACTION_UP |
| 650 | && mIsSwipingVerticallyToClose) { |
| 651 | if (mSettleClosePercentage < mPercentageFromBottom && isTracking) { |
| 652 | animateNotificationPanel(DEFAULT_FLING_VELOCITY, false); |
| 653 | } else if (clippedHeight != mNotificationView.getHeight() && isTracking) { |
| 654 | // this can be caused when user is at the end of the list and trying to |
| 655 | // fling to top of the list by scrolling down. |
| 656 | animateNotificationPanel(DEFAULT_FLING_VELOCITY, true); |
| 657 | } |
| 658 | } |
| 659 | |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 660 | // Updating the mNotificationListAtBottomAtTimeOfTouch state has to be done after |
| 661 | // the event has been passed to the closeGestureDetector above, such that the |
| 662 | // closeGestureDetector sees the up event before the state has changed. |
| 663 | if (event.getActionMasked() == MotionEvent.ACTION_UP) { |
| 664 | mNotificationListAtBottomAtTimeOfTouch = false; |
| 665 | } |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 666 | return handled || isTracking; |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 667 | } |
| 668 | }); |
JianYang Liu | 1d429ee | 2019-11-15 13:20:35 -0800 | [diff] [blame] | 669 | mCarServiceProvider.addListener(car -> { |
| 670 | CarUxRestrictionsManager carUxRestrictionsManager = |
| 671 | (CarUxRestrictionsManager) |
| 672 | car.getCarManager(Car.CAR_UX_RESTRICTION_SERVICE); |
| 673 | mCarUxRestrictionManagerWrapper.setCarUxRestrictionsManager( |
| 674 | carUxRestrictionsManager); |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 675 | |
JianYang Liu | 1d429ee | 2019-11-15 13:20:35 -0800 | [diff] [blame] | 676 | mNotificationViewController = new NotificationViewController( |
| 677 | mNotificationView, |
| 678 | PreprocessingManager.getInstance(mContext), |
| 679 | carNotificationListener, |
| 680 | mCarUxRestrictionManagerWrapper, |
| 681 | mNotificationDataManager); |
| 682 | mNotificationViewController.enable(); |
| 683 | }); |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 684 | } |
| 685 | |
Brad Stenning | 44d3907 | 2019-04-20 11:53:17 -0700 | [diff] [blame] | 686 | /** |
Heemin Seog | ba4cd51 | 2019-11-22 08:35:57 -0800 | [diff] [blame] | 687 | * This method is called whenever there is an update to the number of unseen notifications. |
| 688 | * This method can be extended by OEMs to customize the desired logic. |
| 689 | */ |
| 690 | protected void onUnseenCountUpdate() { |
| 691 | if (mNotificationDataManager != null) { |
| 692 | boolean hasUnseen = mNotificationDataManager.getUnseenNotificationCount() > 0; |
| 693 | mCarNavigationBarController.toggleAllNotificationsUnseenIndicator( |
| 694 | mDeviceProvisionedController.isCurrentUserSetup(), hasUnseen); |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | /** |
Brad Stenning | 44d3907 | 2019-04-20 11:53:17 -0700 | [diff] [blame] | 699 | * @return true if the notification panel is currently visible |
| 700 | */ |
| 701 | boolean isNotificationPanelOpen() { |
| 702 | return mPanelExpanded; |
| 703 | } |
| 704 | |
Brad Stenning | 8d1a51c | 2018-11-20 17:34:16 -0800 | [diff] [blame] | 705 | @Override |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 706 | public void animateExpandNotificationsPanel() { |
| 707 | if (!mCommandQueue.panelsEnabled() || !mUserSetup) { |
| 708 | return; |
| 709 | } |
| 710 | // scroll to top |
| 711 | mNotificationList.scrollToPosition(0); |
| 712 | mStatusBarWindowController.setPanelVisible(true); |
| 713 | mNotificationView.setVisibility(View.VISIBLE); |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 714 | animateNotificationPanel(mOpeningVelocity, false); |
| 715 | |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 716 | setPanelExpanded(true); |
| 717 | } |
| 718 | |
| 719 | @Override |
| 720 | public void animateCollapsePanels(int flags, boolean force, boolean delayed, |
| 721 | float speedUpFactor) { |
| 722 | super.animateCollapsePanels(flags, force, delayed, speedUpFactor); |
| 723 | if (!mPanelExpanded || mNotificationView.getVisibility() == View.INVISIBLE) { |
| 724 | return; |
| 725 | } |
| 726 | mStatusBarWindowController.setStatusBarFocusable(false); |
Dave Mankoff | 0cf8dfc | 2019-09-27 12:46:41 -0400 | [diff] [blame] | 727 | mStatusBarWindowViewController.cancelExpandHelper(); |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 728 | mStatusBarView.collapsePanel(true /* animate */, delayed, speedUpFactor); |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 729 | |
| 730 | animateNotificationPanel(mClosingVelocity, true); |
| 731 | |
| 732 | if (!mIsTracking) { |
| 733 | mStatusBarWindowController.setPanelVisible(false); |
| 734 | mNotificationView.setVisibility(View.INVISIBLE); |
| 735 | } |
| 736 | |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 737 | setPanelExpanded(false); |
| 738 | } |
| 739 | |
Priyank Singh | a47b6f7 | 2019-05-28 13:02:47 -0700 | [diff] [blame] | 740 | private void maybeCompleteAnimation(MotionEvent event) { |
| 741 | if (event.getActionMasked() == MotionEvent.ACTION_UP |
| 742 | && mNotificationView.getVisibility() == View.VISIBLE) { |
| 743 | if (mSettleClosePercentage < mPercentageFromBottom) { |
| 744 | animateNotificationPanel(DEFAULT_FLING_VELOCITY, false); |
| 745 | } else { |
| 746 | animateNotificationPanel(DEFAULT_FLING_VELOCITY, true); |
| 747 | } |
| 748 | } |
| 749 | } |
| 750 | |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 751 | /** |
| 752 | * 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] | 753 | * 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] | 754 | * notification shade this method also makes the view invisible after animation ends. |
| 755 | */ |
| 756 | private void animateNotificationPanel(float velocity, boolean isClosing) { |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 757 | float to = 0; |
| 758 | if (!isClosing) { |
| 759 | to = mNotificationView.getHeight(); |
| 760 | } |
Priyank Singh | b9ab052 | 2019-05-03 15:36:25 -0700 | [diff] [blame] | 761 | |
Priyank Singh | 647f9e6 | 2019-05-16 15:19:53 -0700 | [diff] [blame] | 762 | Rect rect = mNotificationView.getClipBounds(); |
Priyank Singh | a0aa297 | 2019-06-26 18:21:44 -0700 | [diff] [blame] | 763 | if (rect != null && rect.bottom != to) { |
Priyank Singh | b9ab052 | 2019-05-03 15:36:25 -0700 | [diff] [blame] | 764 | float from = rect.bottom; |
| 765 | animate(from, to, velocity, isClosing); |
| 766 | return; |
| 767 | } |
| 768 | |
Priyank Singh | a0aa297 | 2019-06-26 18:21:44 -0700 | [diff] [blame] | 769 | // We will only be here if the shade is being opened programmatically or via button when |
| 770 | // height of the layout was not calculated. |
Priyank Singh | b9ab052 | 2019-05-03 15:36:25 -0700 | [diff] [blame] | 771 | ViewTreeObserver notificationTreeObserver = mNotificationView.getViewTreeObserver(); |
| 772 | notificationTreeObserver.addOnGlobalLayoutListener( |
| 773 | new ViewTreeObserver.OnGlobalLayoutListener() { |
| 774 | @Override |
| 775 | public void onGlobalLayout() { |
| 776 | ViewTreeObserver obs = mNotificationView.getViewTreeObserver(); |
| 777 | obs.removeOnGlobalLayoutListener(this); |
| 778 | float to = mNotificationView.getHeight(); |
| 779 | animate(/* from= */ 0, to, velocity, isClosing); |
| 780 | } |
| 781 | }); |
| 782 | } |
| 783 | |
| 784 | private void animate(float from, float to, float velocity, boolean isClosing) { |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 785 | if (mIsNotificationAnimating) { |
| 786 | return; |
| 787 | } |
| 788 | mIsNotificationAnimating = true; |
| 789 | mIsTracking = true; |
| 790 | ValueAnimator animator = ValueAnimator.ofFloat(from, to); |
| 791 | animator.addUpdateListener( |
| 792 | animation -> { |
| 793 | float animatedValue = (Float) animation.getAnimatedValue(); |
| 794 | setNotificationViewClipBounds((int) animatedValue); |
| 795 | }); |
| 796 | animator.addListener(new AnimatorListenerAdapter() { |
| 797 | @Override |
| 798 | public void onAnimationEnd(Animator animation) { |
| 799 | super.onAnimationEnd(animation); |
| 800 | mIsNotificationAnimating = false; |
| 801 | mIsTracking = false; |
| 802 | mOpeningVelocity = DEFAULT_FLING_VELOCITY; |
| 803 | mClosingVelocity = DEFAULT_FLING_VELOCITY; |
| 804 | if (isClosing) { |
| 805 | mStatusBarWindowController.setPanelVisible(false); |
| 806 | mNotificationView.setVisibility(View.INVISIBLE); |
Priyank Singh | 647f9e6 | 2019-05-16 15:19:53 -0700 | [diff] [blame] | 807 | mNotificationView.setClipBounds(null); |
Danny Epstein | d0af9d0 | 2019-06-19 13:48:51 -0700 | [diff] [blame] | 808 | mNotificationViewController.onVisibilityChanged(false); |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 809 | // let the status bar know that the panel is closed |
| 810 | setPanelExpanded(false); |
| 811 | } else { |
Danny Epstein | d0af9d0 | 2019-06-19 13:48:51 -0700 | [diff] [blame] | 812 | mNotificationViewController.onVisibilityChanged(true); |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 813 | // let the status bar know that the panel is open |
Jonathan Koo | c9f71aa | 2019-05-06 08:20:14 -0700 | [diff] [blame] | 814 | mNotificationView.setVisibleNotificationsAsSeen(); |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 815 | setPanelExpanded(true); |
| 816 | } |
| 817 | } |
| 818 | }); |
Jonathan Koo | 007ff07 | 2019-05-10 09:24:08 -0700 | [diff] [blame] | 819 | mFlingAnimationUtils.apply(animator, from, to, Math.abs(velocity)); |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 820 | animator.start(); |
| 821 | } |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 822 | |
| 823 | @Override |
Brad Stenning | 8d1a51c | 2018-11-20 17:34:16 -0800 | [diff] [blame] | 824 | protected QS createDefaultQSFragment() { |
| 825 | return new CarQSFragment(); |
| 826 | } |
| 827 | |
Rakesh Iyer | 545e47d | 2017-01-23 18:10:21 -0800 | [diff] [blame] | 828 | private BatteryController createBatteryController() { |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 829 | mCarBatteryController = new CarBatteryController(mContext); |
| 830 | mCarBatteryController.addBatteryViewHandler(this); |
| 831 | return mCarBatteryController; |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 832 | } |
| 833 | |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 834 | @Override |
Matthew Ng | 9438065 | 2019-04-08 13:43:07 -0700 | [diff] [blame] | 835 | protected void createNavigationBar(@Nullable RegisterStatusBarResult result) { |
Heemin Seog | d59786b | 2019-11-08 09:20:26 -0800 | [diff] [blame] | 836 | registerNavBarListeners(); |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 837 | } |
| 838 | |
Heemin Seog | d59786b | 2019-11-08 09:20:26 -0800 | [diff] [blame] | 839 | private void registerNavBarListeners() { |
| 840 | // In CarStatusBar, navigation bars are built by NavigationBar.java |
| 841 | // Instead, we register necessary callbacks to the navigation bar controller. |
| 842 | mCarNavigationBarController.registerTopBarTouchListener( |
| 843 | mTopNavBarNotificationTouchListener); |
Heemin Seog | 956cd51 | 2019-10-03 16:15:50 -0700 | [diff] [blame] | 844 | |
Heemin Seog | fcccab7 | 2019-10-22 08:30:23 -0700 | [diff] [blame] | 845 | mCarNavigationBarController.registerBottomBarTouchListener( |
| 846 | mNavBarNotificationTouchListener); |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 847 | |
Heemin Seog | fcccab7 | 2019-10-22 08:30:23 -0700 | [diff] [blame] | 848 | mCarNavigationBarController.registerLeftBarTouchListener( |
| 849 | mNavBarNotificationTouchListener); |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 850 | |
Heemin Seog | fcccab7 | 2019-10-22 08:30:23 -0700 | [diff] [blame] | 851 | mCarNavigationBarController.registerRightBarTouchListener( |
| 852 | mNavBarNotificationTouchListener); |
| 853 | |
| 854 | mCarNavigationBarController.registerNotificationController(() -> togglePanel()); |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 855 | } |
| 856 | |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 857 | @Override |
Qiming Shi | b9dfb92 | 2017-04-13 16:23:18 +0800 | [diff] [blame] | 858 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 859 | //When executing dump() function simultaneously, we need to serialize them |
Qiming Shi | b9dfb92 | 2017-04-13 16:23:18 +0800 | [diff] [blame] | 860 | //to get mStackScroller's position correctly. |
| 861 | synchronized (mQueueLock) { |
| 862 | pw.println(" mStackScroller: " + viewInfo(mStackScroller)); |
| 863 | pw.println(" mStackScroller: " + viewInfo(mStackScroller) |
| 864 | + " scroll " + mStackScroller.getScrollX() |
| 865 | + "," + mStackScroller.getScrollY()); |
| 866 | } |
| 867 | |
davidln | 5473915 | 2018-07-02 13:25:44 -0700 | [diff] [blame] | 868 | pw.print(" mFullscreenUserSwitcher="); |
| 869 | pw.println(mFullscreenUserSwitcher); |
Qiming Shi | b9dfb92 | 2017-04-13 16:23:18 +0800 | [diff] [blame] | 870 | pw.print(" mCarBatteryController="); |
| 871 | pw.println(mCarBatteryController); |
| 872 | pw.print(" mBatteryMeterView="); |
| 873 | pw.println(mBatteryMeterView); |
Qiming Shi | b9dfb92 | 2017-04-13 16:23:18 +0800 | [diff] [blame] | 874 | |
Dave Mankoff | e229469 | 2019-08-14 11:53:13 -0400 | [diff] [blame] | 875 | if (Dependency.get(KeyguardUpdateMonitor.class) != null) { |
| 876 | Dependency.get(KeyguardUpdateMonitor.class).dump(fd, pw, args); |
Qiming Shi | b9dfb92 | 2017-04-13 16:23:18 +0800 | [diff] [blame] | 877 | } |
| 878 | |
Dave Mankoff | c195ea8 | 2019-06-28 16:33:25 -0400 | [diff] [blame] | 879 | Dependency.get(FalsingManager.class).dump(pw); |
Qiming Shi | b9dfb92 | 2017-04-13 16:23:18 +0800 | [diff] [blame] | 880 | FalsingLog.dump(pw); |
| 881 | |
| 882 | pw.println("SharedPreferences:"); |
| 883 | for (Map.Entry<String, ?> entry : Prefs.getAll(mContext).entrySet()) { |
davidln | 5473915 | 2018-07-02 13:25:44 -0700 | [diff] [blame] | 884 | pw.print(" "); |
| 885 | pw.print(entry.getKey()); |
| 886 | pw.print("="); |
| 887 | pw.println(entry.getValue()); |
Qiming Shi | b9dfb92 | 2017-04-13 16:23:18 +0800 | [diff] [blame] | 888 | } |
| 889 | } |
| 890 | |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 891 | @Override |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 892 | public void showBatteryView() { |
| 893 | if (Log.isLoggable(TAG, Log.DEBUG)) { |
| 894 | Log.d(TAG, "showBatteryView(). mBatteryMeterView: " + mBatteryMeterView); |
| 895 | } |
| 896 | |
| 897 | if (mBatteryMeterView != null) { |
| 898 | mBatteryMeterView.setVisibility(View.VISIBLE); |
| 899 | } |
| 900 | } |
| 901 | |
| 902 | @Override |
| 903 | public void hideBatteryView() { |
| 904 | if (Log.isLoggable(TAG, Log.DEBUG)) { |
| 905 | Log.d(TAG, "hideBatteryView(). mBatteryMeterView: " + mBatteryMeterView); |
| 906 | } |
| 907 | |
| 908 | if (mBatteryMeterView != null) { |
| 909 | mBatteryMeterView.setVisibility(View.GONE); |
| 910 | } |
| 911 | } |
| 912 | |
Rakesh Iyer | 2790a37 | 2016-01-22 15:33:39 -0800 | [diff] [blame] | 913 | @Override |
| 914 | protected void createUserSwitcher() { |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 915 | UserSwitcherController userSwitcherController = |
| 916 | Dependency.get(UserSwitcherController.class); |
| 917 | if (userSwitcherController.useFullscreenUserSwitcher()) { |
Heemin Seog | eeca9a9 | 2019-11-08 16:16:49 -0800 | [diff] [blame] | 918 | mFullscreenUserSwitcher = mFullscreenUserSwitcherLazy.get(); |
| 919 | mFullscreenUserSwitcher.setStatusBar(this); |
| 920 | mFullscreenUserSwitcher.setContainer( |
| 921 | mStatusBarWindow.findViewById(R.id.fullscreen_user_switcher_stub)); |
Rakesh Iyer | 2790a37 | 2016-01-22 15:33:39 -0800 | [diff] [blame] | 922 | } else { |
| 923 | super.createUserSwitcher(); |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | @Override |
jovanak | 168dbdb | 2019-02-18 01:00:43 -0800 | [diff] [blame] | 928 | public void setLockscreenUser(int newUserId) { |
| 929 | super.setLockscreenUser(newUserId); |
| 930 | // Try to dismiss the keyguard after every user switch. |
| 931 | dismissKeyguardWhenUserSwitcherNotDisplayed(); |
| 932 | } |
| 933 | |
| 934 | @Override |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 935 | public void onStateChanged(int newState) { |
| 936 | super.onStateChanged(newState); |
jovanak | edba98c | 2018-09-14 15:46:24 -0700 | [diff] [blame] | 937 | |
jovanak | 168dbdb | 2019-02-18 01:00:43 -0800 | [diff] [blame] | 938 | if (newState != StatusBarState.FULLSCREEN_USER_SWITCHER) { |
| 939 | hideUserSwitcher(); |
jovanak | 604ad51 | 2018-08-14 18:41:27 -0700 | [diff] [blame] | 940 | } else { |
jovanak | 168dbdb | 2019-02-18 01:00:43 -0800 | [diff] [blame] | 941 | dismissKeyguardWhenUserSwitcherNotDisplayed(); |
| 942 | } |
| 943 | } |
| 944 | |
| 945 | /** Makes the full screen user switcher visible, if applicable. */ |
| 946 | public void showUserSwitcher() { |
| 947 | if (mFullscreenUserSwitcher != null && mState == StatusBarState.FULLSCREEN_USER_SWITCHER) { |
| 948 | mFullscreenUserSwitcher.show(); // Makes the switcher visible. |
| 949 | } |
| 950 | } |
| 951 | |
| 952 | private void hideUserSwitcher() { |
| 953 | if (mFullscreenUserSwitcher != null) { |
jovanak | 604ad51 | 2018-08-14 18:41:27 -0700 | [diff] [blame] | 954 | mFullscreenUserSwitcher.hide(); |
Aarthi Balachander | 0a427ef | 2018-07-13 15:00:58 -0700 | [diff] [blame] | 955 | } |
| 956 | } |
| 957 | |
jovanak | 622def2 | 2019-06-11 11:51:54 -0700 | [diff] [blame] | 958 | final ScreenLifecycle.Observer mScreenObserver = new ScreenLifecycle.Observer() { |
| 959 | @Override |
| 960 | public void onScreenTurnedOn() { |
| 961 | dismissKeyguardWhenUserSwitcherNotDisplayed(); |
| 962 | } |
| 963 | }; |
| 964 | |
jovanak | 168dbdb | 2019-02-18 01:00:43 -0800 | [diff] [blame] | 965 | // We automatically dismiss keyguard unless user switcher is being shown on the keyguard. |
| 966 | private void dismissKeyguardWhenUserSwitcherNotDisplayed() { |
| 967 | if (mFullscreenUserSwitcher == null) { |
| 968 | return; // Not using the full screen user switcher. |
| 969 | } |
| 970 | |
| 971 | if (mState == StatusBarState.FULLSCREEN_USER_SWITCHER |
| 972 | && !mFullscreenUserSwitcher.isVisible()) { |
| 973 | // Current execution path continues to set state after this, thus we deffer the |
| 974 | // dismissal to the next execution cycle. |
| 975 | postDismissKeyguard(); // Dismiss the keyguard if switcher is not visible. |
Rakesh Iyer | 2790a37 | 2016-01-22 15:33:39 -0800 | [diff] [blame] | 976 | } |
| 977 | } |
Rakesh Iyer | 74ebabe | 2016-03-11 10:10:43 -0800 | [diff] [blame] | 978 | |
jovanak | 604ad51 | 2018-08-14 18:41:27 -0700 | [diff] [blame] | 979 | public void postDismissKeyguard() { |
| 980 | mHandler.post(this::dismissKeyguard); |
| 981 | } |
| 982 | |
| 983 | /** |
| 984 | * Dismisses the keyguard and shows bouncer if authentication is necessary. |
| 985 | */ |
| 986 | public void dismissKeyguard() { |
jovanak | 622def2 | 2019-06-11 11:51:54 -0700 | [diff] [blame] | 987 | // Don't dismiss keyguard when the screen is off. |
| 988 | if (mScreenLifecycle.getScreenState() == ScreenLifecycle.SCREEN_OFF) { |
| 989 | return; |
| 990 | } |
jovanak | 604ad51 | 2018-08-14 18:41:27 -0700 | [diff] [blame] | 991 | executeRunnableDismissingKeyguard(null/* runnable */, null /* cancelAction */, |
Brad Stenning | 8d1a51c | 2018-11-20 17:34:16 -0800 | [diff] [blame] | 992 | true /* dismissShade */, true /* afterKeyguardGone */, true /* deferred */); |
jovanak | 604ad51 | 2018-08-14 18:41:27 -0700 | [diff] [blame] | 993 | } |
| 994 | |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 995 | /** |
| 996 | * Ensures that relevant child views are appropriately recreated when the device's density |
| 997 | * changes. |
| 998 | */ |
| 999 | @Override |
Jason Monk | 9cac5ff | 2017-06-02 11:35:50 -0400 | [diff] [blame] | 1000 | public void onDensityOrFontScaleChanged() { |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 1001 | super.onDensityOrFontScaleChanged(); |
Heemin Seog | d59786b | 2019-11-08 09:20:26 -0800 | [diff] [blame] | 1002 | registerNavBarListeners(); |
Anthony Chen | e658cc2 | 2017-04-27 11:17:35 -0700 | [diff] [blame] | 1003 | // Need to update the background on density changed in case the change was due to night |
| 1004 | // mode. |
| 1005 | mNotificationPanelBackground = getDefaultWallpaper(); |
| 1006 | mScrimController.setScrimBehindDrawable(mNotificationPanelBackground); |
| 1007 | } |
| 1008 | |
| 1009 | /** |
| 1010 | * Returns the {@link Drawable} that represents the wallpaper that the user has currently set. |
| 1011 | */ |
| 1012 | private Drawable getDefaultWallpaper() { |
| 1013 | return mContext.getDrawable(com.android.internal.R.drawable.default_wallpaper); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 1014 | } |
Brad Stenning | 19f236a | 2018-12-11 14:12:30 -0800 | [diff] [blame] | 1015 | |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1016 | private void setNotificationViewClipBounds(int height) { |
Priyank Singh | ea4af13 | 2019-05-01 17:57:06 -0700 | [diff] [blame] | 1017 | if (height > mNotificationView.getHeight()) { |
| 1018 | height = mNotificationView.getHeight(); |
| 1019 | } |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1020 | Rect clipBounds = new Rect(); |
| 1021 | clipBounds.set(0, 0, mNotificationView.getWidth(), height); |
Priyank Singh | 245bd12 | 2019-04-21 15:42:44 -0700 | [diff] [blame] | 1022 | // Sets the clip region on the notification list view. |
Priyank Singh | 647f9e6 | 2019-05-16 15:19:53 -0700 | [diff] [blame] | 1023 | mNotificationView.setClipBounds(clipBounds); |
| 1024 | if (mHandleBar != null) { |
| 1025 | ViewGroup.MarginLayoutParams lp = |
| 1026 | (ViewGroup.MarginLayoutParams) mHandleBar.getLayoutParams(); |
| 1027 | mHandleBar.setTranslationY(height - mHandleBar.getHeight() - lp.bottomMargin); |
| 1028 | } |
Priyank Singh | 245bd12 | 2019-04-21 15:42:44 -0700 | [diff] [blame] | 1029 | if (mNotificationView.getHeight() > 0) { |
Brad Stenning | 0b7e45e | 2019-07-16 16:46:28 -0700 | [diff] [blame] | 1030 | Drawable background = mNotificationView.getBackground().mutate(); |
JianYang Liu | cf7b336 | 2019-10-24 17:19:44 -0700 | [diff] [blame] | 1031 | background.setAlpha((int) (getBackgroundAlpha(height) * 255)); |
Brad Stenning | 0b7e45e | 2019-07-16 16:46:28 -0700 | [diff] [blame] | 1032 | mNotificationView.setBackground(background); |
Priyank Singh | 245bd12 | 2019-04-21 15:42:44 -0700 | [diff] [blame] | 1033 | } |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1034 | } |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 1035 | |
JianYang Liu | cf7b336 | 2019-10-24 17:19:44 -0700 | [diff] [blame] | 1036 | /** |
| 1037 | * Calculates the alpha value for the background based on how much of the notification |
| 1038 | * shade is visible to the user. When the notification shade is completely open then |
| 1039 | * alpha value will be 1. |
| 1040 | */ |
| 1041 | private float getBackgroundAlpha(int height) { |
| 1042 | return mInitialBackgroundAlpha + |
| 1043 | ((float) height / mNotificationView.getHeight() * mBackgroundAlphaDiff); |
| 1044 | } |
| 1045 | |
Priyank Singh | 956c482 | 2019-07-10 12:28:24 -0700 | [diff] [blame] | 1046 | @Override |
| 1047 | public void onConfigChanged(Configuration newConfig) { |
| 1048 | super.onConfigChanged(newConfig); |
| 1049 | |
| 1050 | int uiModeNightMask = (newConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK); |
| 1051 | |
| 1052 | boolean dayNightModeChanged = uiModeNightMask == Configuration.UI_MODE_NIGHT_YES |
| 1053 | || uiModeNightMask == Configuration.UI_MODE_NIGHT_NO; |
| 1054 | |
| 1055 | if (dayNightModeChanged) { |
| 1056 | mNotificationView.setBackgroundColor( |
| 1057 | mContext.getColor(R.color.notification_shade_background_color)); |
| 1058 | } |
| 1059 | } |
| 1060 | |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1061 | private void calculatePercentageFromBottom(float height) { |
| 1062 | if (mNotificationView.getHeight() > 0) { |
| 1063 | mPercentageFromBottom = (int) Math.abs( |
| 1064 | height / mNotificationView.getHeight() * 100); |
| 1065 | } |
| 1066 | } |
| 1067 | |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 1068 | private static final int SWIPE_DOWN_MIN_DISTANCE = 25; |
| 1069 | private static final int SWIPE_MAX_OFF_PATH = 75; |
| 1070 | private static final int SWIPE_THRESHOLD_VELOCITY = 200; |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1071 | |
Priyank Singh | a47b6f7 | 2019-05-28 13:02:47 -0700 | [diff] [blame] | 1072 | /** |
| 1073 | * Only responsible for open hooks. Since once the panel opens it covers all elements |
| 1074 | * there is no need to merge with close. |
| 1075 | */ |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 1076 | private abstract class OpenNotificationGestureListener extends |
| 1077 | GestureDetector.SimpleOnGestureListener { |
| 1078 | |
| 1079 | @Override |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1080 | public boolean onScroll(MotionEvent event1, MotionEvent event2, float distanceX, |
| 1081 | float distanceY) { |
| 1082 | |
| 1083 | if (mNotificationView.getVisibility() == View.INVISIBLE) { |
| 1084 | // when the on-scroll is called for the first time to open. |
| 1085 | mNotificationList.scrollToPosition(0); |
| 1086 | } |
| 1087 | mStatusBarWindowController.setPanelVisible(true); |
| 1088 | mNotificationView.setVisibility(View.VISIBLE); |
| 1089 | |
| 1090 | // clips the view for the notification shade when the user scrolls to open. |
| 1091 | setNotificationViewClipBounds((int) event2.getRawY()); |
| 1092 | |
| 1093 | // Initially the scroll starts with height being zero. This checks protects from divide |
| 1094 | // by zero error. |
| 1095 | calculatePercentageFromBottom(event2.getRawY()); |
| 1096 | |
| 1097 | mIsTracking = true; |
| 1098 | return true; |
| 1099 | } |
| 1100 | |
| 1101 | |
| 1102 | @Override |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 1103 | public boolean onFling(MotionEvent event1, MotionEvent event2, |
| 1104 | float velocityX, float velocityY) { |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1105 | if (velocityY > SWIPE_THRESHOLD_VELOCITY) { |
| 1106 | mOpeningVelocity = velocityY; |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 1107 | openNotification(); |
| 1108 | return true; |
| 1109 | } |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1110 | animateNotificationPanel(DEFAULT_FLING_VELOCITY, true); |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 1111 | |
| 1112 | return false; |
| 1113 | } |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1114 | |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 1115 | protected abstract void openNotification(); |
Brad Stenning | 19f236a | 2018-12-11 14:12:30 -0800 | [diff] [blame] | 1116 | } |
| 1117 | |
Priyank Singh | a47b6f7 | 2019-05-28 13:02:47 -0700 | [diff] [blame] | 1118 | /** |
| 1119 | * To be installed on the open panel notification panel |
| 1120 | */ |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 1121 | private abstract class CloseNotificationGestureListener extends |
| 1122 | GestureDetector.SimpleOnGestureListener { |
| 1123 | |
| 1124 | @Override |
Priyank Singh | bae09ae | 2019-04-25 18:17:02 -0700 | [diff] [blame] | 1125 | public boolean onSingleTapUp(MotionEvent motionEvent) { |
Priyank Singh | b9ab052 | 2019-05-03 15:36:25 -0700 | [diff] [blame] | 1126 | if (mPanelExpanded) { |
| 1127 | animateNotificationPanel(DEFAULT_FLING_VELOCITY, true); |
| 1128 | } |
| 1129 | return true; |
Priyank Singh | bae09ae | 2019-04-25 18:17:02 -0700 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | @Override |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1133 | public boolean onScroll(MotionEvent event1, MotionEvent event2, float distanceX, |
| 1134 | float distanceY) { |
Priyank Singh | bae09ae | 2019-04-25 18:17:02 -0700 | [diff] [blame] | 1135 | // should not clip while scroll to the bottom of the list. |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1136 | if (!mNotificationListAtBottomAtTimeOfTouch) { |
| 1137 | return false; |
| 1138 | } |
| 1139 | float actualNotificationHeight = |
| 1140 | mNotificationView.getHeight() - (event1.getRawY() - event2.getRawY()); |
| 1141 | if (actualNotificationHeight > mNotificationView.getHeight()) { |
| 1142 | actualNotificationHeight = mNotificationView.getHeight(); |
| 1143 | } |
| 1144 | if (mNotificationView.getHeight() > 0) { |
| 1145 | mPercentageFromBottom = (int) Math.abs( |
| 1146 | actualNotificationHeight / mNotificationView.getHeight() * 100); |
| 1147 | boolean isUp = distanceY > 0; |
| 1148 | |
| 1149 | // This check is to figure out if onScroll was called while swiping the card at |
| 1150 | // bottom of the list. At that time we should not allow notification shade to |
| 1151 | // close. We are also checking for the upwards swipe gesture here because it is |
| 1152 | // possible if a user is closing the notification shade and while swiping starts |
| 1153 | // to open again but does not fling. At that time we should allow the |
| 1154 | // notification shade to close fully or else it would stuck in between. |
| 1155 | if (Math.abs(mNotificationView.getHeight() - actualNotificationHeight) |
| 1156 | > SWIPE_DOWN_MIN_DISTANCE && isUp) { |
| 1157 | setNotificationViewClipBounds((int) actualNotificationHeight); |
| 1158 | mIsTracking = true; |
| 1159 | } else if (!isUp) { |
| 1160 | setNotificationViewClipBounds((int) actualNotificationHeight); |
| 1161 | } |
| 1162 | } |
| 1163 | // if we return true the the items in RV won't be scrollable. |
| 1164 | return false; |
| 1165 | } |
| 1166 | |
| 1167 | |
| 1168 | @Override |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 1169 | public boolean onFling(MotionEvent event1, MotionEvent event2, |
| 1170 | float velocityX, float velocityY) { |
Priyank Singh | a01f243 | 2019-05-17 16:33:57 -0700 | [diff] [blame] | 1171 | // should not fling if the touch does not start when view is at the bottom of the list. |
| 1172 | if (!mNotificationListAtBottomAtTimeOfTouch) { |
Priyank Singh | bae09ae | 2019-04-25 18:17:02 -0700 | [diff] [blame] | 1173 | return false; |
| 1174 | } |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 1175 | if (Math.abs(event1.getX() - event2.getX()) > SWIPE_MAX_OFF_PATH |
| 1176 | || Math.abs(velocityY) < SWIPE_THRESHOLD_VELOCITY) { |
| 1177 | // swipe was not vertical or was not fast enough |
| 1178 | return false; |
| 1179 | } |
| 1180 | boolean isUp = velocityY < 0; |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1181 | if (isUp) { |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 1182 | close(); |
| 1183 | return true; |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1184 | } else { |
| 1185 | // we should close the shade |
| 1186 | animateNotificationPanel(velocityY, false); |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 1187 | } |
| 1188 | return false; |
| 1189 | } |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1190 | |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 1191 | protected abstract void close(); |
| 1192 | } |
| 1193 | |
Priyank Singh | a47b6f7 | 2019-05-28 13:02:47 -0700 | [diff] [blame] | 1194 | /** |
| 1195 | * To be installed on the nav bars. |
| 1196 | */ |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 1197 | private abstract class NavBarCloseNotificationGestureListener extends |
| 1198 | CloseNotificationGestureListener { |
| 1199 | @Override |
| 1200 | public boolean onSingleTapUp(MotionEvent e) { |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1201 | mClosingVelocity = DEFAULT_FLING_VELOCITY; |
Priyank Singh | b9ab052 | 2019-05-03 15:36:25 -0700 | [diff] [blame] | 1202 | if (mPanelExpanded) { |
| 1203 | close(); |
| 1204 | } |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 1205 | return super.onSingleTapUp(e); |
| 1206 | } |
| 1207 | |
| 1208 | @Override |
Priyank Singh | b024158 | 2019-04-19 18:46:26 -0700 | [diff] [blame] | 1209 | public boolean onScroll(MotionEvent event1, MotionEvent event2, float distanceX, |
| 1210 | float distanceY) { |
| 1211 | calculatePercentageFromBottom(event2.getRawY()); |
| 1212 | setNotificationViewClipBounds((int) event2.getRawY()); |
| 1213 | return true; |
| 1214 | } |
Adora Zhang | 0237b9c | 2019-03-08 12:27:09 -0800 | [diff] [blame] | 1215 | } |
Brad Stenning | 2ccc2a4 | 2019-04-15 10:17:01 -0700 | [diff] [blame] | 1216 | |
| 1217 | /** |
Priyank Singh | a47b6f7 | 2019-05-28 13:02:47 -0700 | [diff] [blame] | 1218 | * To be installed on the handle bar. |
| 1219 | */ |
| 1220 | private class HandleBarCloseNotificationGestureListener extends |
| 1221 | GestureDetector.SimpleOnGestureListener { |
| 1222 | |
| 1223 | @Override |
| 1224 | public boolean onScroll(MotionEvent event1, MotionEvent event2, float distanceX, |
| 1225 | float distanceY) { |
| 1226 | calculatePercentageFromBottom(event2.getRawY()); |
| 1227 | // To prevent the jump in the clip bounds while closing the notification shade using |
| 1228 | // the handle bar we should calculate the height using the diff of event1 and event2. |
| 1229 | // This will help the notification shade to clip smoothly as the event2 value changes |
| 1230 | // as event1 value will be fixed. |
| 1231 | int clipHeight = |
| 1232 | mNotificationView.getHeight() - (int) (event1.getRawY() - event2.getRawY()); |
| 1233 | setNotificationViewClipBounds(clipHeight); |
| 1234 | return true; |
| 1235 | } |
| 1236 | } |
| 1237 | |
| 1238 | /** |
| 1239 | * SystemUi version of the notification manager that overrides methods such that the |
Brad Stenning | 2ccc2a4 | 2019-04-15 10:17:01 -0700 | [diff] [blame] | 1240 | * notifications end up in the status bar layouts instead of a standalone window. |
| 1241 | */ |
| 1242 | private class CarSystemUIHeadsUpNotificationManager extends CarHeadsUpNotificationManager { |
| 1243 | |
| 1244 | CarSystemUIHeadsUpNotificationManager(Context context, |
| 1245 | NotificationClickHandlerFactory clickHandlerFactory, |
| 1246 | NotificationDataManager notificationDataManager) { |
| 1247 | super(context, clickHandlerFactory, notificationDataManager); |
| 1248 | } |
| 1249 | |
| 1250 | @Override |
| 1251 | protected View createHeadsUpPanel() { |
| 1252 | // In SystemUi the view is already in the window so just return a reference. |
| 1253 | return mStatusBarWindow.findViewById(R.id.notification_headsup); |
| 1254 | } |
| 1255 | |
| 1256 | @Override |
| 1257 | protected void addHeadsUpPanelToDisplay() { |
| 1258 | // Set the panel initial state to invisible |
| 1259 | mHeadsUpPanel.setVisibility(View.INVISIBLE); |
| 1260 | } |
| 1261 | |
| 1262 | @Override |
Priyank Singh | 8bd920f | 2019-06-04 15:21:46 -0700 | [diff] [blame] | 1263 | protected void setInternalInsetsInfo(ViewTreeObserver.InternalInsetsInfo info, |
| 1264 | HeadsUpEntry currentNotification, boolean panelExpanded) { |
| 1265 | super.setInternalInsetsInfo(info, currentNotification, mPanelExpanded); |
| 1266 | } |
| 1267 | |
| 1268 | @Override |
Brad Stenning | 2ccc2a4 | 2019-04-15 10:17:01 -0700 | [diff] [blame] | 1269 | protected void setHeadsUpVisible() { |
Priyank Singh | 7e9344f | 2019-05-07 14:30:13 -0700 | [diff] [blame] | 1270 | // if the Notifications panel is showing don't show the Heads up |
Priyank Singh | 8bd920f | 2019-06-04 15:21:46 -0700 | [diff] [blame] | 1271 | if (!mEnableHeadsUpNotificationWhenNotificationShadeOpen && mPanelExpanded) { |
Priyank Singh | 7e9344f | 2019-05-07 14:30:13 -0700 | [diff] [blame] | 1272 | return; |
| 1273 | } |
Priyank Singh | 8bd920f | 2019-06-04 15:21:46 -0700 | [diff] [blame] | 1274 | |
Brad Stenning | 2ccc2a4 | 2019-04-15 10:17:01 -0700 | [diff] [blame] | 1275 | super.setHeadsUpVisible(); |
| 1276 | if (mHeadsUpPanel.getVisibility() == View.VISIBLE) { |
| 1277 | mStatusBarWindowController.setHeadsUpShowing(true); |
| 1278 | mStatusBarWindowController.setForceStatusBarVisible(true); |
| 1279 | } |
| 1280 | } |
| 1281 | |
| 1282 | @Override |
| 1283 | protected void removeNotificationFromPanel(HeadsUpEntry currentHeadsUpNotification) { |
| 1284 | super.removeNotificationFromPanel(currentHeadsUpNotification); |
| 1285 | // If the panel ended up empty and hidden we can remove it from SystemUi |
| 1286 | if (mHeadsUpPanel.getVisibility() != View.VISIBLE) { |
| 1287 | mStatusBarWindowController.setHeadsUpShowing(false); |
| 1288 | mStatusBarWindowController.setForceStatusBarVisible(false); |
| 1289 | } |
| 1290 | } |
| 1291 | } |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 1292 | } |