Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 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.notification.stack; |
| 18 | |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 19 | import static com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout.ROWS_GENTLE; |
| 20 | |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 21 | import static java.lang.annotation.RetentionPolicy.SOURCE; |
| 22 | |
Steve Elliott | 577ef79 | 2020-04-02 13:49:36 -0400 | [diff] [blame] | 23 | import android.annotation.ColorInt; |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 24 | import android.annotation.IntDef; |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 25 | import android.annotation.LayoutRes; |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 26 | import android.annotation.NonNull; |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 27 | import android.annotation.Nullable; |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 28 | import android.content.Intent; |
| 29 | import android.provider.Settings; |
| 30 | import android.view.LayoutInflater; |
| 31 | import android.view.View; |
| 32 | |
| 33 | import com.android.internal.annotations.VisibleForTesting; |
| 34 | import com.android.systemui.R; |
Selim Cinek | 5dbef2d | 2020-05-07 17:44:38 -0700 | [diff] [blame] | 35 | import com.android.systemui.media.KeyguardMediaController; |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 36 | import com.android.systemui.plugins.ActivityStarter; |
Ned Burns | 7eeccdd | 2019-05-15 14:50:11 -0400 | [diff] [blame] | 37 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
| 38 | import com.android.systemui.statusbar.StatusBarState; |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 39 | import com.android.systemui.statusbar.notification.NotificationSectionsFeatureManager; |
Steve Elliott | 58adc21 | 2019-10-15 11:07:54 -0400 | [diff] [blame] | 40 | import com.android.systemui.statusbar.notification.people.DataListener; |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 41 | import com.android.systemui.statusbar.notification.people.PeopleHubViewAdapter; |
| 42 | import com.android.systemui.statusbar.notification.people.PeopleHubViewBoundary; |
Steve Elliott | 58adc21 | 2019-10-15 11:07:54 -0400 | [diff] [blame] | 43 | import com.android.systemui.statusbar.notification.people.PersonViewModel; |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 44 | import com.android.systemui.statusbar.notification.people.Subscription; |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 45 | import com.android.systemui.statusbar.notification.row.ActivatableNotificationView; |
| 46 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 47 | import com.android.systemui.statusbar.notification.row.ExpandableView; |
| 48 | import com.android.systemui.statusbar.notification.row.StackScrollerDecorView; |
Ned Burns | 2c74c2a | 2019-06-13 19:06:47 -0400 | [diff] [blame] | 49 | import com.android.systemui.statusbar.policy.ConfigurationController; |
| 50 | import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener; |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 51 | |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 52 | import java.lang.annotation.Retention; |
| 53 | import java.util.ArrayList; |
| 54 | import java.util.List; |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 55 | import java.util.Objects; |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 56 | |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 57 | import javax.inject.Inject; |
| 58 | |
Steve Elliott | 58adc21 | 2019-10-15 11:07:54 -0400 | [diff] [blame] | 59 | import kotlin.sequences.Sequence; |
| 60 | |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 61 | /** |
| 62 | * Manages the boundaries of the two notification sections (high priority and low priority). Also |
| 63 | * shows/hides the headers for those sections where appropriate. |
| 64 | * |
| 65 | * TODO: Move remaining sections logic from NSSL into this class. |
| 66 | */ |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 67 | public class NotificationSectionsManager implements StackScrollAlgorithm.SectionProvider { |
| 68 | |
| 69 | private static final String TAG = "NotifSectionsManager"; |
| 70 | private static final boolean DEBUG = false; |
Steve Elliott | c406400 | 2020-03-31 11:54:26 -0400 | [diff] [blame] | 71 | private static final boolean ENABLE_SNOOZED_CONVERSATION_HUB = false; |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 72 | |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 73 | private final ActivityStarter mActivityStarter; |
Ned Burns | 7eeccdd | 2019-05-15 14:50:11 -0400 | [diff] [blame] | 74 | private final StatusBarStateController mStatusBarStateController; |
Ned Burns | 2c74c2a | 2019-06-13 19:06:47 -0400 | [diff] [blame] | 75 | private final ConfigurationController mConfigurationController; |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 76 | private final PeopleHubViewAdapter mPeopleHubViewAdapter; |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 77 | private final NotificationSectionsFeatureManager mSectionsFeatureManager; |
Selim Cinek | 5dbef2d | 2020-05-07 17:44:38 -0700 | [diff] [blame] | 78 | private final KeyguardMediaController mKeyguardMediaController; |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 79 | private final int mNumberOfSections; |
Steve Elliott | 1ba1b7c | 2020-05-05 14:16:32 -0400 | [diff] [blame] | 80 | private final NotificationSectionsLogger mLogger; |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 81 | private final PeopleHubViewBoundary mPeopleHubViewBoundary = new PeopleHubViewBoundary() { |
| 82 | @Override |
| 83 | public void setVisible(boolean isVisible) { |
| 84 | if (mPeopleHubVisible != isVisible) { |
| 85 | mPeopleHubVisible = isVisible; |
| 86 | if (mInitialized) { |
Steve Elliott | 1ba1b7c | 2020-05-05 14:16:32 -0400 | [diff] [blame] | 87 | updateSectionBoundaries("PeopleHub visibility changed"); |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | @NonNull |
| 93 | @Override |
| 94 | public View getAssociatedViewForClickAnimation() { |
| 95 | return mPeopleHubView; |
| 96 | } |
| 97 | |
| 98 | @NonNull |
| 99 | @Override |
| 100 | public Sequence<DataListener<PersonViewModel>> getPersonViewAdapters() { |
| 101 | return mPeopleHubView.getPersonViewAdapters(); |
| 102 | } |
| 103 | }; |
| 104 | |
| 105 | private NotificationStackScrollLayout mParent; |
Ned Burns | 2c74c2a | 2019-06-13 19:06:47 -0400 | [diff] [blame] | 106 | private boolean mInitialized = false; |
Steve Elliott | 58adc21 | 2019-10-15 11:07:54 -0400 | [diff] [blame] | 107 | |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 108 | private SectionHeaderView mGentleHeader; |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 109 | @Nullable private View.OnClickListener mOnClearGentleNotifsClickListener; |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 110 | |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 111 | private SectionHeaderView mAlertingHeader; |
Steve Elliott | 19b2c86 | 2020-05-05 14:15:14 -0400 | [diff] [blame] | 112 | private SectionHeaderView mIncomingHeader; |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 113 | |
| 114 | private PeopleHubView mPeopleHubView; |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 115 | private boolean mPeopleHubVisible = false; |
| 116 | @Nullable private Subscription mPeopleHubSubscription; |
| 117 | |
Robert Snoeberger | b6464ea | 2020-03-20 11:56:22 -0400 | [diff] [blame] | 118 | private MediaHeaderView mMediaControlsView; |
| 119 | |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 120 | @Inject |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 121 | NotificationSectionsManager( |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 122 | ActivityStarter activityStarter, |
Ned Burns | 7eeccdd | 2019-05-15 14:50:11 -0400 | [diff] [blame] | 123 | StatusBarStateController statusBarStateController, |
Ned Burns | 2c74c2a | 2019-06-13 19:06:47 -0400 | [diff] [blame] | 124 | ConfigurationController configurationController, |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 125 | PeopleHubViewAdapter peopleHubViewAdapter, |
Selim Cinek | 5dbef2d | 2020-05-07 17:44:38 -0700 | [diff] [blame] | 126 | KeyguardMediaController keyguardMediaController, |
Steve Elliott | 1ba1b7c | 2020-05-05 14:16:32 -0400 | [diff] [blame] | 127 | NotificationSectionsFeatureManager sectionsFeatureManager, |
| 128 | NotificationSectionsLogger logger) { |
| 129 | |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 130 | mActivityStarter = activityStarter; |
Ned Burns | 7eeccdd | 2019-05-15 14:50:11 -0400 | [diff] [blame] | 131 | mStatusBarStateController = statusBarStateController; |
Ned Burns | 2c74c2a | 2019-06-13 19:06:47 -0400 | [diff] [blame] | 132 | mConfigurationController = configurationController; |
Steve Elliott | 58adc21 | 2019-10-15 11:07:54 -0400 | [diff] [blame] | 133 | mPeopleHubViewAdapter = peopleHubViewAdapter; |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 134 | mSectionsFeatureManager = sectionsFeatureManager; |
| 135 | mNumberOfSections = mSectionsFeatureManager.getNumberOfBuckets(); |
Selim Cinek | 5dbef2d | 2020-05-07 17:44:38 -0700 | [diff] [blame] | 136 | mKeyguardMediaController = keyguardMediaController; |
Steve Elliott | 1ba1b7c | 2020-05-05 14:16:32 -0400 | [diff] [blame] | 137 | mLogger = logger; |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 138 | } |
| 139 | |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 140 | NotificationSection[] createSectionsForBuckets() { |
| 141 | int[] buckets = mSectionsFeatureManager.getNotificationBuckets(); |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 142 | NotificationSection[] sections = new NotificationSection[buckets.length]; |
| 143 | for (int i = 0; i < buckets.length; i++) { |
| 144 | sections[i] = new NotificationSection(mParent, buckets[i] /* bucket */); |
| 145 | } |
| 146 | |
| 147 | return sections; |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 148 | } |
| 149 | |
Ned Burns | 2c74c2a | 2019-06-13 19:06:47 -0400 | [diff] [blame] | 150 | /** Must be called before use. */ |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 151 | void initialize( |
| 152 | NotificationStackScrollLayout parent, LayoutInflater layoutInflater) { |
Ned Burns | 2c74c2a | 2019-06-13 19:06:47 -0400 | [diff] [blame] | 153 | if (mInitialized) { |
| 154 | throw new IllegalStateException("NotificationSectionsManager already initialized"); |
| 155 | } |
| 156 | mInitialized = true; |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 157 | mParent = parent; |
Ned Burns | 2c74c2a | 2019-06-13 19:06:47 -0400 | [diff] [blame] | 158 | reinflateViews(layoutInflater); |
| 159 | mConfigurationController.addCallback(mConfigurationListener); |
| 160 | } |
| 161 | |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 162 | private <T extends ExpandableView> T reinflateView( |
| 163 | T view, LayoutInflater layoutInflater, @LayoutRes int layoutResId) { |
| 164 | int oldPos = -1; |
| 165 | if (view != null) { |
| 166 | if (view.getTransientContainer() != null) { |
| 167 | view.getTransientContainer().removeView(mGentleHeader); |
| 168 | } else if (view.getParent() != null) { |
| 169 | oldPos = mParent.indexOfChild(view); |
| 170 | mParent.removeView(view); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | view = (T) layoutInflater.inflate(layoutResId, mParent, false); |
| 175 | |
| 176 | if (oldPos != -1) { |
| 177 | mParent.addView(view, oldPos); |
| 178 | } |
| 179 | |
| 180 | return view; |
| 181 | } |
| 182 | |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 183 | /** |
Ned Burns | 2c74c2a | 2019-06-13 19:06:47 -0400 | [diff] [blame] | 184 | * Reinflates the entire notification header, including all decoration views. |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 185 | */ |
Ned Burns | 2c74c2a | 2019-06-13 19:06:47 -0400 | [diff] [blame] | 186 | void reinflateViews(LayoutInflater layoutInflater) { |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 187 | mGentleHeader = reinflateView( |
| 188 | mGentleHeader, layoutInflater, R.layout.status_bar_notification_section_header); |
| 189 | mGentleHeader.setHeaderText(R.string.notification_section_header_gentle); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 190 | mGentleHeader.setOnHeaderClickListener(this::onGentleHeaderClick); |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 191 | mGentleHeader.setOnClearAllClickListener(this::onClearGentleNotifsClick); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 192 | |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 193 | mAlertingHeader = reinflateView( |
| 194 | mAlertingHeader, layoutInflater, R.layout.status_bar_notification_section_header); |
| 195 | mAlertingHeader.setHeaderText(R.string.notification_section_header_alerting); |
| 196 | mAlertingHeader.setOnHeaderClickListener(this::onGentleHeaderClick); |
| 197 | |
| 198 | if (mPeopleHubSubscription != null) { |
| 199 | mPeopleHubSubscription.unsubscribe(); |
Steve Elliott | 58adc21 | 2019-10-15 11:07:54 -0400 | [diff] [blame] | 200 | } |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 201 | mPeopleHubView = reinflateView(mPeopleHubView, layoutInflater, R.layout.people_strip); |
Steve Elliott | c406400 | 2020-03-31 11:54:26 -0400 | [diff] [blame] | 202 | if (ENABLE_SNOOZED_CONVERSATION_HUB) { |
| 203 | mPeopleHubSubscription = mPeopleHubViewAdapter.bindView(mPeopleHubViewBoundary); |
| 204 | } |
Robert Snoeberger | b6464ea | 2020-03-20 11:56:22 -0400 | [diff] [blame] | 205 | |
Steve Elliott | 19b2c86 | 2020-05-05 14:15:14 -0400 | [diff] [blame] | 206 | mIncomingHeader = reinflateView( |
| 207 | mIncomingHeader, layoutInflater, R.layout.status_bar_notification_section_header); |
| 208 | mIncomingHeader.setHeaderText(R.string.notification_section_header_incoming); |
| 209 | mIncomingHeader.setOnHeaderClickListener(this::onGentleHeaderClick); |
| 210 | |
Robert Snoeberger | b6464ea | 2020-03-20 11:56:22 -0400 | [diff] [blame] | 211 | mMediaControlsView = reinflateView(mMediaControlsView, layoutInflater, |
| 212 | R.layout.keyguard_media_header); |
Selim Cinek | 5dbef2d | 2020-05-07 17:44:38 -0700 | [diff] [blame] | 213 | mKeyguardMediaController.attach(mMediaControlsView); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 214 | } |
| 215 | |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 216 | /** Listener for when the "clear all" button is clicked on the gentle notification header. */ |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 217 | void setOnClearGentleNotifsClickListener(View.OnClickListener listener) { |
| 218 | mOnClearGentleNotifsClickListener = listener; |
| 219 | } |
| 220 | |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 221 | @Override |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 222 | public boolean beginsSection(@NonNull View view, @Nullable View previous) { |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 223 | return view == mGentleHeader |
Robert Snoeberger | b6464ea | 2020-03-20 11:56:22 -0400 | [diff] [blame] | 224 | || view == mMediaControlsView |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 225 | || view == mPeopleHubView |
| 226 | || view == mAlertingHeader |
Steve Elliott | 19b2c86 | 2020-05-05 14:15:14 -0400 | [diff] [blame] | 227 | || view == mIncomingHeader |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 228 | || !Objects.equals(getBucket(view), getBucket(previous)); |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | private boolean isUsingMultipleSections() { |
| 232 | return mNumberOfSections > 1; |
| 233 | } |
| 234 | |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 235 | @Nullable |
| 236 | private Integer getBucket(View view) { |
| 237 | if (view == mGentleHeader) { |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 238 | return BUCKET_SILENT; |
Steve Elliott | 19b2c86 | 2020-05-05 14:15:14 -0400 | [diff] [blame] | 239 | } else if (view == mIncomingHeader) { |
| 240 | return BUCKET_HEADS_UP; |
Robert Snoeberger | b6464ea | 2020-03-20 11:56:22 -0400 | [diff] [blame] | 241 | } else if (view == mMediaControlsView) { |
| 242 | return BUCKET_MEDIA_CONTROLS; |
Steve Elliott | 58adc21 | 2019-10-15 11:07:54 -0400 | [diff] [blame] | 243 | } else if (view == mPeopleHubView) { |
| 244 | return BUCKET_PEOPLE; |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 245 | } else if (view == mAlertingHeader) { |
| 246 | return BUCKET_ALERTING; |
| 247 | } else if (view instanceof ExpandableNotificationRow) { |
| 248 | return ((ExpandableNotificationRow) view).getEntry().getBucket(); |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 249 | } |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 250 | return null; |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 251 | } |
| 252 | |
Steve Elliott | 1ba1b7c | 2020-05-05 14:16:32 -0400 | [diff] [blame] | 253 | private void logShadeContents() { |
| 254 | final int childCount = mParent.getChildCount(); |
| 255 | for (int i = 0; i < childCount; i++) { |
| 256 | View child = mParent.getChildAt(i); |
| 257 | if (child == mIncomingHeader) { |
| 258 | mLogger.logPosition(i, "INCOMING HEADER"); |
| 259 | continue; |
| 260 | } |
| 261 | if (child == mMediaControlsView) { |
| 262 | mLogger.logPosition(i, "MEDIA CONTROLS"); |
| 263 | continue; |
| 264 | } |
| 265 | if (child == mPeopleHubView) { |
| 266 | mLogger.logPosition(i, "CONVERSATIONS HEADER"); |
| 267 | continue; |
| 268 | } |
| 269 | if (child == mAlertingHeader) { |
| 270 | mLogger.logPosition(i, "ALERTING HEADER"); |
| 271 | continue; |
| 272 | } |
| 273 | if (child == mGentleHeader) { |
| 274 | mLogger.logPosition(i, "SILENT HEADER"); |
| 275 | continue; |
| 276 | } |
| 277 | |
| 278 | if (!(child instanceof ExpandableNotificationRow)) { |
| 279 | mLogger.logPosition(i, "other:" + child.getClass().getName()); |
| 280 | continue; |
| 281 | } |
| 282 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 283 | // Once we enter a new section, calculate the target position for the header. |
| 284 | switch (row.getEntry().getBucket()) { |
| 285 | case BUCKET_HEADS_UP: |
| 286 | mLogger.logPosition(i, "Heads Up"); |
| 287 | break; |
| 288 | case BUCKET_PEOPLE: |
| 289 | mLogger.logPosition(i, "Conversation"); |
| 290 | break; |
| 291 | case BUCKET_ALERTING: |
| 292 | mLogger.logPosition(i, "Alerting"); |
| 293 | break; |
| 294 | case BUCKET_SILENT: |
| 295 | mLogger.logPosition(i, "Silent"); |
| 296 | break; |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | @VisibleForTesting |
| 302 | void updateSectionBoundaries() { |
| 303 | updateSectionBoundaries("test"); |
| 304 | } |
| 305 | |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 306 | /** |
| 307 | * Should be called whenever notifs are added, removed, or updated. Updates section boundary |
| 308 | * bookkeeping and adds/moves/removes section headers if appropriate. |
| 309 | */ |
Steve Elliott | 1ba1b7c | 2020-05-05 14:16:32 -0400 | [diff] [blame] | 310 | void updateSectionBoundaries(String reason) { |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 311 | if (!isUsingMultipleSections()) { |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 312 | return; |
| 313 | } |
| 314 | |
Steve Elliott | 1ba1b7c | 2020-05-05 14:16:32 -0400 | [diff] [blame] | 315 | mLogger.logStartSectionUpdate(reason); |
| 316 | |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 317 | // The overall strategy here is to iterate over the current children of mParent, looking |
| 318 | // for where the sections headers are currently positioned, and where each section begins. |
| 319 | // Then, once we find the start of a new section, we track that position as the "target" for |
| 320 | // the section header, adjusted for the case where existing headers are in front of that |
| 321 | // target, but won't be once they are moved / removed after the pass has completed. |
| 322 | |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 323 | final boolean showHeaders = mStatusBarStateController.getState() != StatusBarState.KEYGUARD; |
| 324 | final boolean usingPeopleFiltering = mSectionsFeatureManager.isFilteringEnabled(); |
Robert Snoeberger | b6464ea | 2020-03-20 11:56:22 -0400 | [diff] [blame] | 325 | final boolean usingMediaControls = mSectionsFeatureManager.isMediaControlsEnabled(); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 326 | |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 327 | boolean peopleNotifsPresent = false; |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 328 | |
Robert Snoeberger | b6464ea | 2020-03-20 11:56:22 -0400 | [diff] [blame] | 329 | int currentMediaControlsIdx = -1; |
Selim Cinek | 2d7be5f | 2020-05-01 13:16:01 -0700 | [diff] [blame] | 330 | int mediaControlsTarget = usingMediaControls ? 0 : -1; |
Steve Elliott | 19b2c86 | 2020-05-05 14:15:14 -0400 | [diff] [blame] | 331 | int currentIncomingHeaderIdx = -1; |
| 332 | int incomingHeaderTarget = -1; |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 333 | int currentPeopleHeaderIdx = -1; |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 334 | int peopleHeaderTarget = -1; |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 335 | int currentAlertingHeaderIdx = -1; |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 336 | int alertingHeaderTarget = -1; |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 337 | int currentGentleHeaderIdx = -1; |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 338 | int gentleHeaderTarget = -1; |
| 339 | |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 340 | int lastNotifIndex = 0; |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 341 | |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 342 | final int childCount = mParent.getChildCount(); |
| 343 | for (int i = 0; i < childCount; i++) { |
| 344 | View child = mParent.getChildAt(i); |
| 345 | |
| 346 | // Track the existing positions of the headers |
Steve Elliott | 19b2c86 | 2020-05-05 14:15:14 -0400 | [diff] [blame] | 347 | if (child == mIncomingHeader) { |
Steve Elliott | 1ba1b7c | 2020-05-05 14:16:32 -0400 | [diff] [blame] | 348 | mLogger.logPosition(i, "INCOMING HEADER"); |
Steve Elliott | 19b2c86 | 2020-05-05 14:15:14 -0400 | [diff] [blame] | 349 | currentIncomingHeaderIdx = i; |
| 350 | continue; |
| 351 | } |
Robert Snoeberger | b6464ea | 2020-03-20 11:56:22 -0400 | [diff] [blame] | 352 | if (child == mMediaControlsView) { |
Steve Elliott | 1ba1b7c | 2020-05-05 14:16:32 -0400 | [diff] [blame] | 353 | mLogger.logPosition(i, "MEDIA CONTROLS"); |
Robert Snoeberger | b6464ea | 2020-03-20 11:56:22 -0400 | [diff] [blame] | 354 | currentMediaControlsIdx = i; |
| 355 | continue; |
| 356 | } |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 357 | if (child == mPeopleHubView) { |
Steve Elliott | 1ba1b7c | 2020-05-05 14:16:32 -0400 | [diff] [blame] | 358 | mLogger.logPosition(i, "CONVERSATIONS HEADER"); |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 359 | currentPeopleHeaderIdx = i; |
| 360 | continue; |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 361 | } |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 362 | if (child == mAlertingHeader) { |
Steve Elliott | 1ba1b7c | 2020-05-05 14:16:32 -0400 | [diff] [blame] | 363 | mLogger.logPosition(i, "ALERTING HEADER"); |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 364 | currentAlertingHeaderIdx = i; |
| 365 | continue; |
| 366 | } |
| 367 | if (child == mGentleHeader) { |
Steve Elliott | 1ba1b7c | 2020-05-05 14:16:32 -0400 | [diff] [blame] | 368 | mLogger.logPosition(i, "SILENT HEADER"); |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 369 | currentGentleHeaderIdx = i; |
| 370 | continue; |
| 371 | } |
| 372 | |
| 373 | if (!(child instanceof ExpandableNotificationRow)) { |
Steve Elliott | 1ba1b7c | 2020-05-05 14:16:32 -0400 | [diff] [blame] | 374 | mLogger.logPosition(i, "other"); |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 375 | continue; |
| 376 | } |
| 377 | lastNotifIndex = i; |
| 378 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 379 | // Once we enter a new section, calculate the target position for the header. |
| 380 | switch (row.getEntry().getBucket()) { |
| 381 | case BUCKET_HEADS_UP: |
Steve Elliott | 1ba1b7c | 2020-05-05 14:16:32 -0400 | [diff] [blame] | 382 | mLogger.logPosition(i, "Heads Up"); |
Steve Elliott | 19b2c86 | 2020-05-05 14:15:14 -0400 | [diff] [blame] | 383 | if (showHeaders && incomingHeaderTarget == -1) { |
| 384 | incomingHeaderTarget = i; |
| 385 | // Offset the target if there are other headers before this that will be |
| 386 | // moved. |
| 387 | if (currentIncomingHeaderIdx != -1) { |
| 388 | incomingHeaderTarget--; |
| 389 | } |
| 390 | if (currentMediaControlsIdx != -1) { |
| 391 | incomingHeaderTarget--; |
| 392 | } |
| 393 | if (currentPeopleHeaderIdx != -1) { |
| 394 | incomingHeaderTarget--; |
| 395 | } |
| 396 | if (currentAlertingHeaderIdx != -1) { |
| 397 | incomingHeaderTarget--; |
| 398 | } |
| 399 | if (currentGentleHeaderIdx != -1) { |
| 400 | incomingHeaderTarget--; |
| 401 | } |
| 402 | } |
Robert Snoeberger | b6464ea | 2020-03-20 11:56:22 -0400 | [diff] [blame] | 403 | if (mediaControlsTarget != -1) { |
| 404 | mediaControlsTarget++; |
| 405 | } |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 406 | break; |
Steve Elliott | 49671e0 | 2020-05-12 13:51:28 -0400 | [diff] [blame] | 407 | case BUCKET_FOREGROUND_SERVICE: |
| 408 | if (mediaControlsTarget != -1) { |
| 409 | mediaControlsTarget++; |
| 410 | } |
| 411 | break; |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 412 | case BUCKET_PEOPLE: |
Steve Elliott | 1ba1b7c | 2020-05-05 14:16:32 -0400 | [diff] [blame] | 413 | mLogger.logPosition(i, "Conversation"); |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 414 | peopleNotifsPresent = true; |
| 415 | if (showHeaders && peopleHeaderTarget == -1) { |
| 416 | peopleHeaderTarget = i; |
| 417 | // Offset the target if there are other headers before this that will be |
| 418 | // moved. |
| 419 | if (currentPeopleHeaderIdx != -1) { |
| 420 | peopleHeaderTarget--; |
| 421 | } |
| 422 | if (currentAlertingHeaderIdx != -1) { |
| 423 | peopleHeaderTarget--; |
| 424 | } |
| 425 | if (currentGentleHeaderIdx != -1) { |
| 426 | peopleHeaderTarget--; |
| 427 | } |
| 428 | } |
| 429 | break; |
| 430 | case BUCKET_ALERTING: |
Steve Elliott | 1ba1b7c | 2020-05-05 14:16:32 -0400 | [diff] [blame] | 431 | mLogger.logPosition(i, "Alerting"); |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 432 | if (showHeaders && usingPeopleFiltering && alertingHeaderTarget == -1) { |
| 433 | alertingHeaderTarget = i; |
| 434 | // Offset the target if there are other headers before this that will be |
| 435 | // moved. |
| 436 | if (currentAlertingHeaderIdx != -1) { |
| 437 | alertingHeaderTarget--; |
| 438 | } |
| 439 | if (currentGentleHeaderIdx != -1) { |
| 440 | alertingHeaderTarget--; |
| 441 | } |
| 442 | } |
| 443 | break; |
| 444 | case BUCKET_SILENT: |
Steve Elliott | 1ba1b7c | 2020-05-05 14:16:32 -0400 | [diff] [blame] | 445 | mLogger.logPosition(i, "Silent"); |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 446 | if (showHeaders && gentleHeaderTarget == -1) { |
| 447 | gentleHeaderTarget = i; |
| 448 | // Offset the target if there are other headers before this that will be |
| 449 | // moved. |
| 450 | if (currentGentleHeaderIdx != -1) { |
| 451 | gentleHeaderTarget--; |
| 452 | } |
| 453 | } |
| 454 | break; |
| 455 | default: |
| 456 | throw new IllegalStateException("Cannot find section bucket for view"); |
| 457 | } |
| 458 | } |
| 459 | if (showHeaders && usingPeopleFiltering && mPeopleHubVisible && peopleHeaderTarget == -1) { |
| 460 | // Insert the people header even if there are no people visible, in order to show |
| 461 | // the hub. Put it directly above the next header. |
| 462 | if (alertingHeaderTarget != -1) { |
| 463 | peopleHeaderTarget = alertingHeaderTarget; |
| 464 | } else if (gentleHeaderTarget != -1) { |
| 465 | peopleHeaderTarget = gentleHeaderTarget; |
| 466 | } else { |
| 467 | // Put it at the end of the list. |
| 468 | peopleHeaderTarget = lastNotifIndex; |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 469 | } |
Steve Elliott | 6de51a7 | 2020-03-05 11:00:47 -0500 | [diff] [blame] | 470 | // Offset the target to account for the current position of the people header. |
| 471 | if (currentPeopleHeaderIdx != -1 && currentPeopleHeaderIdx < peopleHeaderTarget) { |
| 472 | peopleHeaderTarget--; |
| 473 | } |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 474 | } |
| 475 | |
Steve Elliott | 1ba1b7c | 2020-05-05 14:16:32 -0400 | [diff] [blame] | 476 | mLogger.logStr("New header target positions:"); |
| 477 | |
| 478 | mLogger.logPosition(incomingHeaderTarget, "INCOMING HEADER"); |
| 479 | mLogger.logPosition(mediaControlsTarget, "MEDIA CONTROLS"); |
| 480 | mLogger.logPosition(peopleHeaderTarget, "CONVERSATIONS HEADER"); |
| 481 | mLogger.logPosition(alertingHeaderTarget, "ALERTING HEADER"); |
| 482 | mLogger.logPosition(gentleHeaderTarget, "SILENT HEADER"); |
| 483 | |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 484 | // Add headers in reverse order to preserve indices |
| 485 | adjustHeaderVisibilityAndPosition( |
| 486 | gentleHeaderTarget, mGentleHeader, currentGentleHeaderIdx); |
| 487 | adjustHeaderVisibilityAndPosition( |
| 488 | alertingHeaderTarget, mAlertingHeader, currentAlertingHeaderIdx); |
| 489 | adjustHeaderVisibilityAndPosition( |
| 490 | peopleHeaderTarget, mPeopleHubView, currentPeopleHeaderIdx); |
Steve Elliott | 19b2c86 | 2020-05-05 14:15:14 -0400 | [diff] [blame] | 491 | adjustViewPosition(mediaControlsTarget, mMediaControlsView, currentMediaControlsIdx); |
Steve Elliott | 49671e0 | 2020-05-12 13:51:28 -0400 | [diff] [blame] | 492 | adjustHeaderVisibilityAndPosition(incomingHeaderTarget, mIncomingHeader, |
| 493 | currentIncomingHeaderIdx); |
Steve Elliott | 58adc21 | 2019-10-15 11:07:54 -0400 | [diff] [blame] | 494 | |
Steve Elliott | 1ba1b7c | 2020-05-05 14:16:32 -0400 | [diff] [blame] | 495 | |
| 496 | mLogger.logStr("Final order:"); |
| 497 | |
| 498 | logShadeContents(); |
| 499 | |
| 500 | mLogger.logStr("Section boundary update complete"); |
| 501 | |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 502 | // Update headers to reflect state of section contents |
| 503 | mGentleHeader.setAreThereDismissableGentleNotifs( |
| 504 | mParent.hasActiveClearableNotifications(ROWS_GENTLE)); |
| 505 | mPeopleHubView.setCanSwipe(showHeaders && mPeopleHubVisible && !peopleNotifsPresent); |
| 506 | if (peopleHeaderTarget != currentPeopleHeaderIdx) { |
| 507 | mPeopleHubView.resetTranslation(); |
| 508 | } |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 509 | } |
| 510 | |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 511 | private void adjustHeaderVisibilityAndPosition( |
| 512 | int targetPosition, StackScrollerDecorView header, int currentPosition) { |
Steve Elliott | 49671e0 | 2020-05-12 13:51:28 -0400 | [diff] [blame] | 513 | adjustViewPosition(targetPosition, header, currentPosition); |
| 514 | if (targetPosition != -1 && currentPosition == -1) { |
| 515 | header.setContentVisible(true); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 516 | } |
| 517 | } |
| 518 | |
Steve Elliott | 49671e0 | 2020-05-12 13:51:28 -0400 | [diff] [blame] | 519 | private void adjustViewPosition(int targetPosition, ExpandableView view, int currentPosition) { |
Robert Snoeberger | b6464ea | 2020-03-20 11:56:22 -0400 | [diff] [blame] | 520 | if (targetPosition == -1) { |
| 521 | if (currentPosition != -1) { |
Steve Elliott | 49671e0 | 2020-05-12 13:51:28 -0400 | [diff] [blame] | 522 | mParent.removeView(view); |
Robert Snoeberger | b6464ea | 2020-03-20 11:56:22 -0400 | [diff] [blame] | 523 | } |
| 524 | } else { |
| 525 | if (currentPosition == -1) { |
| 526 | // If the header is animating away, it will still have a parent, so detach it first |
| 527 | // TODO: We should really cancel the active animations here. This will happen |
| 528 | // automatically when the view's intro animation starts, but it's a fragile link. |
Steve Elliott | 49671e0 | 2020-05-12 13:51:28 -0400 | [diff] [blame] | 529 | if (view.getTransientContainer() != null) { |
| 530 | view.getTransientContainer().removeTransientView(view); |
| 531 | view.setTransientContainer(null); |
Robert Snoeberger | b6464ea | 2020-03-20 11:56:22 -0400 | [diff] [blame] | 532 | } |
Steve Elliott | 49671e0 | 2020-05-12 13:51:28 -0400 | [diff] [blame] | 533 | mParent.addView(view, targetPosition); |
Robert Snoeberger | b6464ea | 2020-03-20 11:56:22 -0400 | [diff] [blame] | 534 | } else { |
Steve Elliott | 49671e0 | 2020-05-12 13:51:28 -0400 | [diff] [blame] | 535 | mParent.changeViewPosition(view, targetPosition); |
Robert Snoeberger | b6464ea | 2020-03-20 11:56:22 -0400 | [diff] [blame] | 536 | } |
| 537 | } |
| 538 | } |
| 539 | |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 540 | /** |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 541 | * Updates the boundaries (as tracked by their first and last views) of the priority sections. |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 542 | * |
| 543 | * @return {@code true} If the last view in the top section changed (so we need to animate). |
| 544 | */ |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 545 | boolean updateFirstAndLastViewsForAllSections( |
| 546 | NotificationSection[] sections, |
| 547 | List<ActivatableNotificationView> children) { |
| 548 | |
| 549 | if (sections.length <= 0 || children.size() <= 0) { |
| 550 | for (NotificationSection s : sections) { |
| 551 | s.setFirstVisibleChild(null); |
| 552 | s.setLastVisibleChild(null); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 553 | } |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 554 | return false; |
| 555 | } |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 556 | |
| 557 | boolean changed = false; |
| 558 | ArrayList<ActivatableNotificationView> viewsInBucket = new ArrayList<>(); |
| 559 | for (NotificationSection s : sections) { |
| 560 | int filter = s.getBucket(); |
| 561 | viewsInBucket.clear(); |
| 562 | |
| 563 | //TODO: do this in a single pass, and more better |
| 564 | for (ActivatableNotificationView v : children) { |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 565 | Integer bucket = getBucket(v); |
| 566 | if (bucket == null) { |
| 567 | throw new IllegalArgumentException("Cannot find section bucket for view"); |
| 568 | } |
| 569 | |
| 570 | if (bucket == filter) { |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 571 | viewsInBucket.add(v); |
| 572 | } |
| 573 | |
| 574 | if (viewsInBucket.size() >= 1) { |
| 575 | changed |= s.setFirstVisibleChild(viewsInBucket.get(0)); |
| 576 | changed |= s.setLastVisibleChild(viewsInBucket.get(viewsInBucket.size() - 1)); |
| 577 | } else { |
| 578 | changed |= s.setFirstVisibleChild(null); |
| 579 | changed |= s.setLastVisibleChild(null); |
| 580 | } |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | if (DEBUG) { |
| 585 | logSections(sections); |
| 586 | } |
| 587 | |
| 588 | return changed; |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 589 | } |
| 590 | |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 591 | private void logSections(NotificationSection[] sections) { |
| 592 | for (int i = 0; i < sections.length; i++) { |
| 593 | NotificationSection s = sections[i]; |
| 594 | ActivatableNotificationView first = s.getFirstVisibleChild(); |
| 595 | String fs = first == null ? "(null)" |
| 596 | : (first instanceof ExpandableNotificationRow) |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 597 | ? ((ExpandableNotificationRow) first).getEntry().getKey() |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 598 | : Integer.toHexString(System.identityHashCode(first)); |
| 599 | ActivatableNotificationView last = s.getLastVisibleChild(); |
| 600 | String ls = last == null ? "(null)" |
| 601 | : (last instanceof ExpandableNotificationRow) |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 602 | ? ((ExpandableNotificationRow) last).getEntry().getKey() |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 603 | : Integer.toHexString(System.identityHashCode(last)); |
| 604 | android.util.Log.d(TAG, "updateSections: f=" + fs + " s=" + i); |
| 605 | android.util.Log.d(TAG, "updateSections: l=" + ls + " s=" + i); |
| 606 | } |
| 607 | } |
| 608 | |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 609 | @VisibleForTesting |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 610 | ExpandableView getGentleHeaderView() { |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 611 | return mGentleHeader; |
| 612 | } |
| 613 | |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 614 | @VisibleForTesting |
| 615 | ExpandableView getAlertingHeaderView() { |
| 616 | return mAlertingHeader; |
| 617 | } |
| 618 | |
| 619 | @VisibleForTesting |
| 620 | ExpandableView getPeopleHeaderView() { |
| 621 | return mPeopleHubView; |
| 622 | } |
| 623 | |
Steve Elliott | 6de51a7 | 2020-03-05 11:00:47 -0500 | [diff] [blame] | 624 | @VisibleForTesting |
Robert Snoeberger | b6464ea | 2020-03-20 11:56:22 -0400 | [diff] [blame] | 625 | ExpandableView getMediaControlsView() { |
| 626 | return mMediaControlsView; |
| 627 | } |
| 628 | |
| 629 | @VisibleForTesting |
Steve Elliott | 49671e0 | 2020-05-12 13:51:28 -0400 | [diff] [blame] | 630 | ExpandableView getIncomingHeaderView() { |
| 631 | return mIncomingHeader; |
| 632 | } |
| 633 | |
| 634 | @VisibleForTesting |
Steve Elliott | 6de51a7 | 2020-03-05 11:00:47 -0500 | [diff] [blame] | 635 | void setPeopleHubVisible(boolean visible) { |
| 636 | mPeopleHubVisible = visible; |
| 637 | } |
| 638 | |
Ned Burns | 2c74c2a | 2019-06-13 19:06:47 -0400 | [diff] [blame] | 639 | private final ConfigurationListener mConfigurationListener = new ConfigurationListener() { |
| 640 | @Override |
| 641 | public void onLocaleListChanged() { |
Steve Elliott | 59e23eb | 2020-03-18 16:13:19 -0400 | [diff] [blame] | 642 | reinflateViews(LayoutInflater.from(mParent.getContext())); |
Ned Burns | 2c74c2a | 2019-06-13 19:06:47 -0400 | [diff] [blame] | 643 | } |
| 644 | }; |
| 645 | |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 646 | private void onGentleHeaderClick(View v) { |
| 647 | Intent intent = new Intent(Settings.ACTION_NOTIFICATION_SETTINGS); |
| 648 | mActivityStarter.startActivity( |
| 649 | intent, |
| 650 | true, |
| 651 | true, |
| 652 | Intent.FLAG_ACTIVITY_SINGLE_TOP); |
| 653 | } |
Ned Burns | 6126944 | 2019-05-02 18:27:23 -0400 | [diff] [blame] | 654 | |
| 655 | private void onClearGentleNotifsClick(View v) { |
| 656 | if (mOnClearGentleNotifsClickListener != null) { |
| 657 | mOnClearGentleNotifsClickListener.onClick(v); |
| 658 | } |
| 659 | } |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 660 | |
Steve Elliott | 946b00c | 2019-10-28 11:20:24 -0400 | [diff] [blame] | 661 | void hidePeopleRow() { |
| 662 | mPeopleHubVisible = false; |
Steve Elliott | 1ba1b7c | 2020-05-05 14:16:32 -0400 | [diff] [blame] | 663 | updateSectionBoundaries("PeopleHub dismissed"); |
Steve Elliott | 58adc21 | 2019-10-15 11:07:54 -0400 | [diff] [blame] | 664 | } |
| 665 | |
Steve Elliott | 577ef79 | 2020-04-02 13:49:36 -0400 | [diff] [blame] | 666 | void setHeaderForegroundColor(@ColorInt int color) { |
| 667 | mPeopleHubView.setTextColor(color); |
| 668 | mGentleHeader.setForegroundColor(color); |
| 669 | mAlertingHeader.setForegroundColor(color); |
| 670 | } |
| 671 | |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 672 | /** |
| 673 | * For now, declare the available notification buckets (sections) here so that other |
| 674 | * presentation code can decide what to do based on an entry's buckets |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 675 | */ |
| 676 | @Retention(SOURCE) |
| 677 | @IntDef(prefix = { "BUCKET_" }, value = { |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 678 | BUCKET_HEADS_UP, |
Steve Elliott | 49671e0 | 2020-05-12 13:51:28 -0400 | [diff] [blame] | 679 | BUCKET_FOREGROUND_SERVICE, |
Robert Snoeberger | b6464ea | 2020-03-20 11:56:22 -0400 | [diff] [blame] | 680 | BUCKET_MEDIA_CONTROLS, |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 681 | BUCKET_PEOPLE, |
| 682 | BUCKET_ALERTING, |
| 683 | BUCKET_SILENT |
| 684 | }) |
| 685 | public @interface PriorityBucket {} |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 686 | public static final int BUCKET_HEADS_UP = 0; |
Steve Elliott | 49671e0 | 2020-05-12 13:51:28 -0400 | [diff] [blame] | 687 | public static final int BUCKET_FOREGROUND_SERVICE = 1; |
| 688 | public static final int BUCKET_MEDIA_CONTROLS = 2; |
| 689 | public static final int BUCKET_PEOPLE = 3; |
| 690 | public static final int BUCKET_ALERTING = 4; |
| 691 | public static final int BUCKET_SILENT = 5; |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 692 | } |