* commit '865c73b5f66bfd1e5a9eded75b5a5fb24e701042': Push back notification means snooze the package.
This commit is contained in:
@@ -139,6 +139,10 @@
|
|||||||
<!-- milliseconds before the heads up notification auto-dismisses. -->
|
<!-- milliseconds before the heads up notification auto-dismisses. -->
|
||||||
<integer name="heads_up_notification_decay">10000</integer>
|
<integer name="heads_up_notification_decay">10000</integer>
|
||||||
|
|
||||||
|
<!-- milliseconds after a heads up notification is pushed back
|
||||||
|
before the app can interrupt again. -->
|
||||||
|
<integer name="heads_up_default_snooze_length_ms">60000</integer>
|
||||||
|
|
||||||
<!-- milliseconds before the heads up notification accepts touches. -->
|
<!-- milliseconds before the heads up notification accepts touches. -->
|
||||||
<integer name="heads_up_sensitivity_delay">700</integer>
|
<integer name="heads_up_sensitivity_delay">700</integer>
|
||||||
|
|
||||||
|
|||||||
@@ -600,6 +600,7 @@ public abstract class BaseStatusBar extends SystemUI implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
mCurrentUserId = ActivityManager.getCurrentUser();
|
mCurrentUserId = ActivityManager.getCurrentUser();
|
||||||
|
setHeadsUpUser(mCurrentUserId);
|
||||||
|
|
||||||
IntentFilter filter = new IntentFilter();
|
IntentFilter filter = new IntentFilter();
|
||||||
filter.addAction(Intent.ACTION_USER_SWITCHED);
|
filter.addAction(Intent.ACTION_USER_SWITCHED);
|
||||||
@@ -662,7 +663,13 @@ public abstract class BaseStatusBar extends SystemUI implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void userSwitched(int newUserId) {
|
public void userSwitched(int newUserId) {
|
||||||
// should be overridden
|
setHeadsUpUser(newUserId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setHeadsUpUser(int newUserId) {
|
||||||
|
if (mHeadsUpNotificationView != null) {
|
||||||
|
mHeadsUpNotificationView.setUser(newUserId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isHeadsUp(String key) {
|
public boolean isHeadsUp(String key) {
|
||||||
@@ -2065,6 +2072,10 @@ public abstract class BaseStatusBar extends SystemUI implements
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mHeadsUpNotificationView.isSnoozed(sbn.getPackageName())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Notification notification = sbn.getNotification();
|
Notification notification = sbn.getNotification();
|
||||||
// some predicates to make the boolean logic legible
|
// some predicates to make the boolean logic legible
|
||||||
boolean isNoisy = (notification.defaults & Notification.DEFAULT_SOUND) != 0
|
boolean isNoisy = (notification.defaults & Notification.DEFAULT_SOUND) != 0
|
||||||
|
|||||||
@@ -3181,6 +3181,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void userSwitched(int newUserId) {
|
public void userSwitched(int newUserId) {
|
||||||
|
super.userSwitched(newUserId);
|
||||||
if (MULTIUSER_DEBUG) mNotificationPanelDebugText.setText("USER " + newUserId);
|
if (MULTIUSER_DEBUG) mNotificationPanelDebugText.setText("USER " + newUserId);
|
||||||
animateCollapsePanels();
|
animateCollapsePanels();
|
||||||
updatePublicMode();
|
updatePublicMode();
|
||||||
|
|||||||
@@ -18,8 +18,13 @@ package com.android.systemui.statusbar.policy;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.database.ContentObserver;
|
||||||
import android.graphics.Outline;
|
import android.graphics.Outline;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
|
import android.os.SystemClock;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.util.ArrayMap;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
@@ -39,17 +44,23 @@ import com.android.systemui.statusbar.ExpandableView;
|
|||||||
import com.android.systemui.statusbar.NotificationData;
|
import com.android.systemui.statusbar.NotificationData;
|
||||||
import com.android.systemui.statusbar.phone.PhoneStatusBar;
|
import com.android.systemui.statusbar.phone.PhoneStatusBar;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class HeadsUpNotificationView extends FrameLayout implements SwipeHelper.Callback, ExpandHelper.Callback,
|
public class HeadsUpNotificationView extends FrameLayout implements SwipeHelper.Callback, ExpandHelper.Callback,
|
||||||
ViewTreeObserver.OnComputeInternalInsetsListener {
|
ViewTreeObserver.OnComputeInternalInsetsListener {
|
||||||
private static final String TAG = "HeadsUpNotificationView";
|
private static final String TAG = "HeadsUpNotificationView";
|
||||||
private static final boolean DEBUG = false;
|
private static final boolean DEBUG = false;
|
||||||
private static final boolean SPEW = DEBUG;
|
private static final boolean SPEW = DEBUG;
|
||||||
|
private static final String SETTING_HEADS_UP_SNOOZE_LENGTH_MS = "heads_up_snooze_length_ms";
|
||||||
|
|
||||||
Rect mTmpRect = new Rect();
|
Rect mTmpRect = new Rect();
|
||||||
int[] mTmpTwoArray = new int[2];
|
int[] mTmpTwoArray = new int[2];
|
||||||
|
|
||||||
private final int mTouchSensitivityDelay;
|
private final int mTouchSensitivityDelay;
|
||||||
private final float mMaxAlpha = 1f;
|
private final float mMaxAlpha = 1f;
|
||||||
|
private final ArrayMap<String, Long> mSnoozedPackages;
|
||||||
|
private final int mDefaultSnoozeLengthMs;
|
||||||
|
|
||||||
private SwipeHelper mSwipeHelper;
|
private SwipeHelper mSwipeHelper;
|
||||||
private EdgeSwipeHelper mEdgeSwipeHelper;
|
private EdgeSwipeHelper mEdgeSwipeHelper;
|
||||||
|
|
||||||
@@ -57,8 +68,11 @@ public class HeadsUpNotificationView extends FrameLayout implements SwipeHelper.
|
|||||||
|
|
||||||
private long mStartTouchTime;
|
private long mStartTouchTime;
|
||||||
private ViewGroup mContentHolder;
|
private ViewGroup mContentHolder;
|
||||||
|
private int mSnoozeLengthMs;
|
||||||
|
private ContentObserver mSettingsObserver;
|
||||||
|
|
||||||
private NotificationData.Entry mHeadsUp;
|
private NotificationData.Entry mHeadsUp;
|
||||||
|
private int mUser;
|
||||||
|
|
||||||
public HeadsUpNotificationView(Context context, AttributeSet attrs) {
|
public HeadsUpNotificationView(Context context, AttributeSet attrs) {
|
||||||
this(context, attrs, 0);
|
this(context, attrs, 0);
|
||||||
@@ -66,8 +80,12 @@ public class HeadsUpNotificationView extends FrameLayout implements SwipeHelper.
|
|||||||
|
|
||||||
public HeadsUpNotificationView(Context context, AttributeSet attrs, int defStyle) {
|
public HeadsUpNotificationView(Context context, AttributeSet attrs, int defStyle) {
|
||||||
super(context, attrs, defStyle);
|
super(context, attrs, defStyle);
|
||||||
mTouchSensitivityDelay = getResources().getInteger(R.integer.heads_up_sensitivity_delay);
|
Resources resources = context.getResources();
|
||||||
|
mTouchSensitivityDelay = resources.getInteger(R.integer.heads_up_sensitivity_delay);
|
||||||
if (DEBUG) Log.v(TAG, "create() " + mTouchSensitivityDelay);
|
if (DEBUG) Log.v(TAG, "create() " + mTouchSensitivityDelay);
|
||||||
|
mSnoozedPackages = new ArrayMap<>();
|
||||||
|
mDefaultSnoozeLengthMs = resources.getInteger(R.integer.heads_up_default_snooze_length_ms);
|
||||||
|
mSnoozeLengthMs = mDefaultSnoozeLengthMs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateResources() {
|
public void updateResources() {
|
||||||
@@ -115,7 +133,7 @@ public class HeadsUpNotificationView extends FrameLayout implements SwipeHelper.
|
|||||||
sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
|
sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
|
||||||
|
|
||||||
mSwipeHelper.snapChild(mContentHolder, 1f);
|
mSwipeHelper.snapChild(mContentHolder, 1f);
|
||||||
mStartTouchTime = System.currentTimeMillis() + mTouchSensitivityDelay;
|
mStartTouchTime = SystemClock.elapsedRealtime() + mTouchSensitivityDelay;
|
||||||
|
|
||||||
mHeadsUp.setInterruption();
|
mHeadsUp.setInterruption();
|
||||||
|
|
||||||
@@ -166,6 +184,29 @@ public class HeadsUpNotificationView extends FrameLayout implements SwipeHelper.
|
|||||||
mHeadsUp = null;
|
mHeadsUp = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isSnoozed(String packageName) {
|
||||||
|
final String key = snoozeKey(packageName, mUser);
|
||||||
|
Long snoozedUntil = mSnoozedPackages.get(key);
|
||||||
|
if (snoozedUntil != null) {
|
||||||
|
if (snoozedUntil > SystemClock.elapsedRealtime()) {
|
||||||
|
if (DEBUG) Log.v(TAG, key + " snoozed");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
mSnoozedPackages.remove(packageName);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void snooze() {
|
||||||
|
mSnoozedPackages.put(snoozeKey(mHeadsUp.notification.getPackageName(), mUser),
|
||||||
|
SystemClock.elapsedRealtime() + mSnoozeLengthMs);
|
||||||
|
releaseAndClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String snoozeKey(String packageName, int user) {
|
||||||
|
return user + "," + packageName;
|
||||||
|
}
|
||||||
|
|
||||||
public void releaseAndClose() {
|
public void releaseAndClose() {
|
||||||
release();
|
release();
|
||||||
mBar.scheduleHeadsUpClose();
|
mBar.scheduleHeadsUpClose();
|
||||||
@@ -209,6 +250,24 @@ public class HeadsUpNotificationView extends FrameLayout implements SwipeHelper.
|
|||||||
mContentHolder = (ViewGroup) findViewById(R.id.content_holder);
|
mContentHolder = (ViewGroup) findViewById(R.id.content_holder);
|
||||||
mContentHolder.setOutlineProvider(CONTENT_HOLDER_OUTLINE_PROVIDER);
|
mContentHolder.setOutlineProvider(CONTENT_HOLDER_OUTLINE_PROVIDER);
|
||||||
|
|
||||||
|
mSnoozeLengthMs = Settings.Global.getInt(mContext.getContentResolver(),
|
||||||
|
SETTING_HEADS_UP_SNOOZE_LENGTH_MS, mDefaultSnoozeLengthMs);
|
||||||
|
mSettingsObserver = new ContentObserver(getHandler()) {
|
||||||
|
@Override
|
||||||
|
public void onChange(boolean selfChange) {
|
||||||
|
final int packageSnoozeLengthMs = Settings.Global.getInt(
|
||||||
|
mContext.getContentResolver(), SETTING_HEADS_UP_SNOOZE_LENGTH_MS, -1);
|
||||||
|
if (packageSnoozeLengthMs > -1 && packageSnoozeLengthMs != mSnoozeLengthMs) {
|
||||||
|
mSnoozeLengthMs = packageSnoozeLengthMs;
|
||||||
|
if (DEBUG) Log.v(TAG, "mSnoozeLengthMs = " + mSnoozeLengthMs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
mContext.getContentResolver().registerContentObserver(
|
||||||
|
Settings.Global.getUriFor(SETTING_HEADS_UP_SNOOZE_LENGTH_MS), false,
|
||||||
|
mSettingsObserver);
|
||||||
|
if (DEBUG) Log.v(TAG, "mSnoozeLengthMs = " + mSnoozeLengthMs);
|
||||||
|
|
||||||
if (mHeadsUp != null) {
|
if (mHeadsUp != null) {
|
||||||
// whoops, we're on already!
|
// whoops, we're on already!
|
||||||
showNotification(mHeadsUp);
|
showNotification(mHeadsUp);
|
||||||
@@ -217,10 +276,15 @@ public class HeadsUpNotificationView extends FrameLayout implements SwipeHelper.
|
|||||||
getViewTreeObserver().addOnComputeInternalInsetsListener(this);
|
getViewTreeObserver().addOnComputeInternalInsetsListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDetachedFromWindow() {
|
||||||
|
mContext.getContentResolver().unregisterContentObserver(mSettingsObserver);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||||
if (DEBUG) Log.v(TAG, "onInterceptTouchEvent()");
|
if (DEBUG) Log.v(TAG, "onInterceptTouchEvent()");
|
||||||
if (System.currentTimeMillis() < mStartTouchTime) {
|
if (SystemClock.elapsedRealtime() < mStartTouchTime) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return mEdgeSwipeHelper.onInterceptTouchEvent(ev)
|
return mEdgeSwipeHelper.onInterceptTouchEvent(ev)
|
||||||
@@ -246,7 +310,7 @@ public class HeadsUpNotificationView extends FrameLayout implements SwipeHelper.
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent(MotionEvent ev) {
|
public boolean onTouchEvent(MotionEvent ev) {
|
||||||
if (System.currentTimeMillis() < mStartTouchTime) {
|
if (SystemClock.elapsedRealtime() < mStartTouchTime) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
mBar.resetHeadsUpDecayTimer();
|
mBar.resetHeadsUpDecayTimer();
|
||||||
@@ -370,6 +434,10 @@ public class HeadsUpNotificationView extends FrameLayout implements SwipeHelper.
|
|||||||
return mHeadsUp == null ? null : mHeadsUp.notification.getKey();
|
return mHeadsUp == null ? null : mHeadsUp.notification.getKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setUser(int user) {
|
||||||
|
mUser = user;
|
||||||
|
}
|
||||||
|
|
||||||
private class EdgeSwipeHelper implements Gefingerpoken {
|
private class EdgeSwipeHelper implements Gefingerpoken {
|
||||||
private static final boolean DEBUG_EDGE_SWIPE = false;
|
private static final boolean DEBUG_EDGE_SWIPE = false;
|
||||||
private final float mTouchSlop;
|
private final float mTouchSlop;
|
||||||
@@ -397,7 +465,7 @@ public class HeadsUpNotificationView extends FrameLayout implements SwipeHelper.
|
|||||||
final float daX = Math.abs(ev.getX() - mFirstX);
|
final float daX = Math.abs(ev.getX() - mFirstX);
|
||||||
final float daY = Math.abs(dY);
|
final float daY = Math.abs(dY);
|
||||||
if (!mConsuming && daX < daY && daY > mTouchSlop) {
|
if (!mConsuming && daX < daY && daY > mTouchSlop) {
|
||||||
releaseAndClose();
|
snooze();
|
||||||
if (dY > 0) {
|
if (dY > 0) {
|
||||||
if (DEBUG_EDGE_SWIPE) Log.d(TAG, "found an open");
|
if (DEBUG_EDGE_SWIPE) Log.d(TAG, "found an open");
|
||||||
mBar.animateExpandNotificationsPanel();
|
mBar.animateExpandNotificationsPanel();
|
||||||
|
|||||||
Reference in New Issue
Block a user