Add delay to notifications before they can be dismissed.
Test: Run jank tests. Create notifications with a delay, then attempt to swipe them away as soon as they are perceivable to the user. Swiping during the animation should not result in notification dismissal, but swiping after the animation completes should. Fixes: 70293267 Change-Id: Ibca02666255693255185b8bd326cc97d8c574b2e
This commit is contained in:
@@ -37,6 +37,7 @@ import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.SystemClock;
|
||||
import android.os.Bundle;
|
||||
import android.service.notification.StatusBarNotification;
|
||||
import android.util.ArraySet;
|
||||
@@ -992,6 +993,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
mEntry.setInitializationTime(SystemClock.elapsedRealtime());
|
||||
Dependency.get(PluginManager.class).addPluginListener(this,
|
||||
NotificationMenuRowPlugin.class, false /* Allow multiple */);
|
||||
}
|
||||
|
||||
@@ -84,6 +84,7 @@ public class NotificationData {
|
||||
public static final class Entry {
|
||||
private static final long LAUNCH_COOLDOWN = 2000;
|
||||
private static final long REMOTE_INPUT_COOLDOWN = 500;
|
||||
private static final long INITIALIZATION_DELAY = 400;
|
||||
private static final long NOT_LAUNCHED_YET = -LAUNCH_COOLDOWN;
|
||||
private static final int COLOR_INVALID = 1;
|
||||
public String key;
|
||||
@@ -114,6 +115,9 @@ public class NotificationData {
|
||||
public ArraySet<Integer> mActiveAppOps = new ArraySet<>(3);
|
||||
public CharSequence headsUpStatusBarText;
|
||||
public CharSequence headsUpStatusBarTextPublic;
|
||||
|
||||
private long initializationTime = -1;
|
||||
|
||||
/**
|
||||
* Whether or not this row represents a system notification. Note that if this is
|
||||
* {@code null}, that means we were either unable to retrieve the info or have yet to
|
||||
@@ -169,6 +173,11 @@ public class NotificationData {
|
||||
return SystemClock.elapsedRealtime() < lastRemoteInputSent + REMOTE_INPUT_COOLDOWN;
|
||||
}
|
||||
|
||||
public boolean hasFinishedInitialization() {
|
||||
return initializationTime == -1 ||
|
||||
SystemClock.elapsedRealtime() > initializationTime + INITIALIZATION_DELAY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the icons for a notification
|
||||
* @param context the context to create the icons with
|
||||
@@ -341,6 +350,12 @@ public class NotificationData {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setInitializationTime(long time) {
|
||||
if (initializationTime == -1) {
|
||||
initializationTime = time;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final ArrayMap<String, Entry> mEntries = new ArrayMap<>();
|
||||
|
||||
@@ -4701,10 +4701,13 @@ public class NotificationStackScrollLayout extends ViewGroup
|
||||
|
||||
if (currView instanceof ExpandableNotificationRow) {
|
||||
ExpandableNotificationRow row = (ExpandableNotificationRow) currView;
|
||||
mCurrMenuRow = row.createMenu();
|
||||
mCurrMenuRow.setSwipeActionHelper(NotificationSwipeHelper.this);
|
||||
mCurrMenuRow.setMenuClickListener(NotificationStackScrollLayout.this);
|
||||
mCurrMenuRow.onTouchEvent(currView, ev, 0 /* velocity */);
|
||||
|
||||
if (row.getEntry().hasFinishedInitialization()) {
|
||||
mCurrMenuRow = row.createMenu();
|
||||
mCurrMenuRow.setSwipeActionHelper(NotificationSwipeHelper.this);
|
||||
mCurrMenuRow.setMenuClickListener(NotificationStackScrollLayout.this);
|
||||
mCurrMenuRow.onTouchEvent(currView, ev, 0 /* velocity */);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -178,7 +178,7 @@ public class StackScrollAlgorithm {
|
||||
return false;
|
||||
}
|
||||
ExpandableNotificationRow row = (ExpandableNotificationRow) v;
|
||||
if (row.areGutsExposed()) {
|
||||
if (row.areGutsExposed() || !row.getEntry().hasFinishedInitialization()) {
|
||||
return false;
|
||||
}
|
||||
return row.canViewBeDismissed();
|
||||
|
||||
Reference in New Issue
Block a user