Permalink
Browse files

Base: HeadsUp snooze function [1/2]

5.1 introduced a snooze feature which activates when swiping up.
Default snooze time is 1 minute. Let's make it configurable!

Forward ported to marshmallow/Nougat By:@beanstown106
*pretty much a rewrite using the logic from my heads up timeout port
*also added a second toast for 1 minute instead of saying 1 minutes

Change-Id: If85a3d551a43e919d194e5ab356e4c5672e9736c
  • Loading branch information...
Nick0703 authored and xlxfoxxlx committed Apr 9, 2016
1 parent 9ada62d commit 6760237c68470f062afd59b9202d474f1b304c99
@@ -4402,6 +4402,12 @@ public boolean validate(String value) {
*/
public static final String HEADS_UP_TIMEOUT = "heads_up_timeout";
/**
* Defines the global heads up notification snooze
* @hide
*/
public static final String HEADS_UP_NOTIFICATION_SNOOZE = "heads_up_notification_snooze";
/**
* Settings to backup. This is here so that it's in the same place as the settings
* keys and easy to update.
@@ -230,4 +230,8 @@
<string name="omnijaws_current_text">Now</string>
<string name="omnijaws_package_not_available">OmniJaws not available</string>
<!-- Heads up snooze toast -->
<string name="heads_up_snooze_message_one_minute">Heads up is snoozing for 1 minute.</string>
<string name="heads_up_snooze_message">Heads up is snoozing for <xliff:g id="number">%d</xliff:g> minutes.</string>
</resources>
@@ -30,6 +30,7 @@
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.accessibility.AccessibilityEvent;
import android.widget.Toast;
import com.android.internal.logging.MetricsLogger;
import com.android.systemui.R;
@@ -56,16 +57,15 @@
VisualStabilityManager.Callback {
private static final String TAG = "HeadsUpManager";
private static final boolean DEBUG = false;
private static final String SETTING_HEADS_UP_SNOOZE_LENGTH_MS = "heads_up_snooze_length_ms";
private static final int TAG_CLICKED_NOTIFICATION = R.id.is_clicked_heads_up_tag;
private int mHeadsUpNotificationDecay;
private int mSnoozeLengthMs;
private final int mMinimumDisplayTime;
private final int mTouchAcceptanceDelay;
private final ArrayMap<String, Long> mSnoozedPackages;
private final HashSet<OnHeadsUpChangedListener> mListeners = new HashSet<>();
private final int mDefaultSnoozeLengthMs;
private final Handler mHandler = new Handler();
private final Pools.Pool<HeadsUpEntry> mEntryPool = new Pools.Pool<HeadsUpEntry>() {
@@ -92,7 +92,6 @@ public boolean release(HeadsUpEntry instance) {
private final Context mContext;
private final NotificationGroupManager mGroupManager;
private PhoneStatusBar mBar;
private int mSnoozeLengthMs;
private ContentObserver mSettingsObserver;
private HashMap<String, HeadsUpEntry> mHeadsUpEntries = new HashMap<>();
private HashSet<String> mSwipedOutKeys = new HashSet<>();
@@ -119,31 +118,17 @@ public HeadsUpManager(final Context context, View statusBarWindowView,
Resources resources = mContext.getResources();
mTouchAcceptanceDelay = resources.getInteger(R.integer.touch_acceptance_delay);
mSnoozedPackages = new ArrayMap<>();
mDefaultSnoozeLengthMs = resources.getInteger(R.integer.heads_up_default_snooze_length_ms);
mSnoozeLengthMs = mDefaultSnoozeLengthMs;
mMinimumDisplayTime = resources.getInteger(R.integer.heads_up_notification_minimum_time);
mHeadsUpNotificationDecay = Settings.System.getIntForUser(context.getContentResolver(),
Settings.System.HEADS_UP_TIMEOUT,
context.getResources().getInteger(R.integer.heads_up_notification_decay),
UserHandle.USER_CURRENT);
mSnoozeLengthMs = Settings.System.getIntForUser(context.getContentResolver(),
Settings.System.HEADS_UP_NOTIFICATION_SNOOZE,
context.getResources().getInteger(R.integer.heads_up_default_snooze_length_ms),
UserHandle.USER_CURRENT);
mClock = new Clock();
mSnoozeLengthMs = Settings.Global.getInt(context.getContentResolver(),
SETTING_HEADS_UP_SNOOZE_LENGTH_MS, mDefaultSnoozeLengthMs);
mSettingsObserver = new ContentObserver(mHandler) {
@Override
public void onChange(boolean selfChange) {
final int packageSnoozeLengthMs = Settings.Global.getInt(
context.getContentResolver(), SETTING_HEADS_UP_SNOOZE_LENGTH_MS, -1);
if (packageSnoozeLengthMs > -1 && packageSnoozeLengthMs != mSnoozeLengthMs) {
mSnoozeLengthMs = packageSnoozeLengthMs;
if (DEBUG) Log.v(TAG, "mSnoozeLengthMs = " + mSnoozeLengthMs);
}
}
};
context.getContentResolver().registerContentObserver(
Settings.Global.getUriFor(SETTING_HEADS_UP_SNOOZE_LENGTH_MS), false,
mSettingsObserver);
mStatusBarWindowView = statusBarWindowView;
mGroupManager = groupManager;
mStatusBarHeight = resources.getDimensionPixelSize(
@@ -345,6 +330,17 @@ public void snooze() {
String packageName = entry.entry.notification.getPackageName();
mSnoozedPackages.put(snoozeKey(packageName, mUser),
SystemClock.elapsedRealtime() + mSnoozeLengthMs);
if (mSnoozeLengthMs != 0) {
if (mSnoozeLengthMs == 60000) {
Toast.makeText(mContext,
mContext.getString(R.string.heads_up_snooze_message_one_minute),
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(mContext,
mContext.getString(R.string.heads_up_snooze_message,
mSnoozeLengthMs / 60 / 1000), Toast.LENGTH_LONG).show();
}
}
}
mReleaseOnExpandFinish = true;
}
@@ -676,6 +672,10 @@ public void updateEntry(boolean updatePostTime) {
Settings.System.HEADS_UP_TIMEOUT,
mContext.getResources().getInteger(R.integer.heads_up_notification_decay),
UserHandle.USER_CURRENT);
mSnoozeLengthMs = Settings.System.getIntForUser(mContext.getContentResolver(),
Settings.System.HEADS_UP_NOTIFICATION_SNOOZE,
mContext.getResources().getInteger(R.integer.heads_up_default_snooze_length_ms),
UserHandle.USER_CURRENT);
long currentTime = mClock.currentTimeMillis();
earliestRemovaltime = currentTime + mMinimumDisplayTime;
if (updatePostTime) {

0 comments on commit 6760237

Please sign in to comment.