Merge "Add new "incoming" header for HUNing notifications" into rvc-dev am: 0b17a06762

Change-Id: Ie0f8491897f02cab7853dc2fb0438326d22901b1
This commit is contained in:
Steve Elliott
2020-05-06 22:44:38 +00:00
committed by Automerger Merge Worker
3 changed files with 66 additions and 28 deletions

View File

@@ -1253,6 +1253,9 @@
<!-- The text for the notification history link. [CHAR LIMIT=40] --> <!-- The text for the notification history link. [CHAR LIMIT=40] -->
<string name="manage_notifications_history_text">History</string> <string name="manage_notifications_history_text">History</string>
<!-- Section title for notifications that have recently appeared. [CHAR LIMIT=40] -->
<string name="notification_section_header_incoming">Incoming</string>
<!-- Section title for notifications that do not vibrate or make noise. [CHAR LIMIT=40] --> <!-- Section title for notifications that do not vibrate or make noise. [CHAR LIMIT=40] -->
<string name="notification_section_header_gentle">Silent notifications</string> <string name="notification_section_header_gentle">Silent notifications</string>

View File

@@ -27,20 +27,17 @@ import com.android.systemui.statusbar.notification.NotificationFilter
import com.android.systemui.statusbar.notification.NotificationSectionsFeatureManager import com.android.systemui.statusbar.notification.NotificationSectionsFeatureManager
import com.android.systemui.statusbar.notification.collection.provider.HighPriorityProvider import com.android.systemui.statusbar.notification.collection.provider.HighPriorityProvider
import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier
import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier.Companion.TYPE_IMPORTANT_PERSON
import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier.Companion.TYPE_NON_PERSON import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier.Companion.TYPE_NON_PERSON
import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier.Companion.TYPE_PERSON
import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_ALERTING import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_ALERTING
import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_HEADS_UP import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_HEADS_UP
import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_PEOPLE import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_PEOPLE
import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_SILENT import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_SILENT
import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.PriorityBucket
import com.android.systemui.statusbar.phone.NotificationGroupManager import com.android.systemui.statusbar.phone.NotificationGroupManager
import com.android.systemui.statusbar.policy.HeadsUpManager import com.android.systemui.statusbar.policy.HeadsUpManager
import dagger.Lazy import dagger.Lazy
import java.util.Objects; import java.util.Objects
import javax.inject.Inject import javax.inject.Inject
import kotlin.Comparator
private const val TAG = "NotifRankingManager" private const val TAG = "NotifRankingManager"
@@ -140,33 +137,36 @@ open class NotificationRankingManager @Inject constructor(
.filterNot(notifFilter::shouldFilterOut) .filterNot(notifFilter::shouldFilterOut)
.sortedWith(rankingComparator) .sortedWith(rankingComparator)
.toList() .toList()
for (entry in filtered) { assignBuckets(filtered)
assignBucketForEntry(entry)
}
return filtered return filtered
} }
private fun assignBucketForEntry(entry: NotificationEntry) { private fun assignBuckets(entries: List<NotificationEntry>) {
entries.forEach { it.bucket = getBucketForEntry(it) }
if (!usePeopleFiltering) {
// If we don't have a Conversation section, just assign buckets normally based on the
// content.
return
}
// If HUNs are not continuous with the top section, break out into a new Incoming section.
entries.asReversed().asSequence().zipWithNext().forEach { (next, entry) ->
if (entry.isRowHeadsUp && entry.bucket > next.bucket) {
entry.bucket = BUCKET_HEADS_UP
}
}
}
@PriorityBucket
private fun getBucketForEntry(entry: NotificationEntry): Int {
val isHeadsUp = entry.isRowHeadsUp val isHeadsUp = entry.isRowHeadsUp
val isMedia = isImportantMedia(entry) val isMedia = isImportantMedia(entry)
val isSystemMax = entry.isSystemMax() val isSystemMax = entry.isSystemMax()
setBucket(entry, isHeadsUp, isMedia, isSystemMax) return when {
} usePeopleFiltering && entry.getPeopleNotificationType() != TYPE_NON_PERSON ->
BUCKET_PEOPLE
private fun setBucket( isHeadsUp || isMedia || isSystemMax || entry.isHighPriority() ->
entry: NotificationEntry, BUCKET_ALERTING
isHeadsUp: Boolean, else -> BUCKET_SILENT
isMedia: Boolean,
isSystemMax: Boolean
) {
if (usePeopleFiltering && isHeadsUp) {
entry.bucket = BUCKET_HEADS_UP
} else if (usePeopleFiltering && entry.getPeopleNotificationType() != TYPE_NON_PERSON) {
entry.bucket = BUCKET_PEOPLE
} else if (isHeadsUp || isMedia || isSystemMax || entry.isHighPriority()) {
entry.bucket = BUCKET_ALERTING
} else {
entry.bucket = BUCKET_SILENT
} }
} }

View File

@@ -109,6 +109,7 @@ public class NotificationSectionsManager implements StackScrollAlgorithm.Section
@Nullable private View.OnClickListener mOnClearGentleNotifsClickListener; @Nullable private View.OnClickListener mOnClearGentleNotifsClickListener;
private SectionHeaderView mAlertingHeader; private SectionHeaderView mAlertingHeader;
private SectionHeaderView mIncomingHeader;
private PeopleHubView mPeopleHubView; private PeopleHubView mPeopleHubView;
private boolean mPeopleHubVisible = false; private boolean mPeopleHubVisible = false;
@@ -199,6 +200,11 @@ public class NotificationSectionsManager implements StackScrollAlgorithm.Section
mPeopleHubSubscription = mPeopleHubViewAdapter.bindView(mPeopleHubViewBoundary); mPeopleHubSubscription = mPeopleHubViewAdapter.bindView(mPeopleHubViewBoundary);
} }
mIncomingHeader = reinflateView(
mIncomingHeader, layoutInflater, R.layout.status_bar_notification_section_header);
mIncomingHeader.setHeaderText(R.string.notification_section_header_incoming);
mIncomingHeader.setOnHeaderClickListener(this::onGentleHeaderClick);
if (mMediaControlsView != null) { if (mMediaControlsView != null) {
mKeyguardMediaPlayer.unbindView(); mKeyguardMediaPlayer.unbindView();
} }
@@ -218,6 +224,7 @@ public class NotificationSectionsManager implements StackScrollAlgorithm.Section
|| view == mMediaControlsView || view == mMediaControlsView
|| view == mPeopleHubView || view == mPeopleHubView
|| view == mAlertingHeader || view == mAlertingHeader
|| view == mIncomingHeader
|| !Objects.equals(getBucket(view), getBucket(previous)); || !Objects.equals(getBucket(view), getBucket(previous));
} }
@@ -229,6 +236,8 @@ public class NotificationSectionsManager implements StackScrollAlgorithm.Section
private Integer getBucket(View view) { private Integer getBucket(View view) {
if (view == mGentleHeader) { if (view == mGentleHeader) {
return BUCKET_SILENT; return BUCKET_SILENT;
} else if (view == mIncomingHeader) {
return BUCKET_HEADS_UP;
} else if (view == mMediaControlsView) { } else if (view == mMediaControlsView) {
return BUCKET_MEDIA_CONTROLS; return BUCKET_MEDIA_CONTROLS;
} else if (view == mPeopleHubView) { } else if (view == mPeopleHubView) {
@@ -267,6 +276,8 @@ public class NotificationSectionsManager implements StackScrollAlgorithm.Section
// Currently, just putting media controls in the front and incrementing the position based // Currently, just putting media controls in the front and incrementing the position based
// on the number of heads-up notifs. // on the number of heads-up notifs.
int mediaControlsTarget = isKeyguard && usingMediaControls ? 0 : -1; int mediaControlsTarget = isKeyguard && usingMediaControls ? 0 : -1;
int currentIncomingHeaderIdx = -1;
int incomingHeaderTarget = -1;
int currentPeopleHeaderIdx = -1; int currentPeopleHeaderIdx = -1;
int peopleHeaderTarget = -1; int peopleHeaderTarget = -1;
int currentAlertingHeaderIdx = -1; int currentAlertingHeaderIdx = -1;
@@ -281,6 +292,10 @@ public class NotificationSectionsManager implements StackScrollAlgorithm.Section
View child = mParent.getChildAt(i); View child = mParent.getChildAt(i);
// Track the existing positions of the headers // Track the existing positions of the headers
if (child == mIncomingHeader) {
currentIncomingHeaderIdx = i;
continue;
}
if (child == mMediaControlsView) { if (child == mMediaControlsView) {
currentMediaControlsIdx = i; currentMediaControlsIdx = i;
continue; continue;
@@ -306,6 +321,26 @@ public class NotificationSectionsManager implements StackScrollAlgorithm.Section
// Once we enter a new section, calculate the target position for the header. // Once we enter a new section, calculate the target position for the header.
switch (row.getEntry().getBucket()) { switch (row.getEntry().getBucket()) {
case BUCKET_HEADS_UP: case BUCKET_HEADS_UP:
if (showHeaders && incomingHeaderTarget == -1) {
incomingHeaderTarget = i;
// Offset the target if there are other headers before this that will be
// moved.
if (currentIncomingHeaderIdx != -1) {
incomingHeaderTarget--;
}
if (currentMediaControlsIdx != -1) {
incomingHeaderTarget--;
}
if (currentPeopleHeaderIdx != -1) {
incomingHeaderTarget--;
}
if (currentAlertingHeaderIdx != -1) {
incomingHeaderTarget--;
}
if (currentGentleHeaderIdx != -1) {
incomingHeaderTarget--;
}
}
if (mediaControlsTarget != -1) { if (mediaControlsTarget != -1) {
mediaControlsTarget++; mediaControlsTarget++;
} }
@@ -378,8 +413,8 @@ public class NotificationSectionsManager implements StackScrollAlgorithm.Section
alertingHeaderTarget, mAlertingHeader, currentAlertingHeaderIdx); alertingHeaderTarget, mAlertingHeader, currentAlertingHeaderIdx);
adjustHeaderVisibilityAndPosition( adjustHeaderVisibilityAndPosition(
peopleHeaderTarget, mPeopleHubView, currentPeopleHeaderIdx); peopleHeaderTarget, mPeopleHubView, currentPeopleHeaderIdx);
adjustViewPosition( adjustViewPosition(mediaControlsTarget, mMediaControlsView, currentMediaControlsIdx);
mediaControlsTarget, mMediaControlsView, currentMediaControlsIdx); adjustViewPosition(incomingHeaderTarget, mIncomingHeader, currentIncomingHeaderIdx);
// Update headers to reflect state of section contents // Update headers to reflect state of section contents
mGentleHeader.setAreThereDismissableGentleNotifs( mGentleHeader.setAreThereDismissableGentleNotifs(