Permalink
Browse files

Make Heads Up snooze toast more informative

*tell the user which app is snoozing
*also center the toast to account for big app names
Example: SystemUI - Peeking notifications are snoozing for 1 minute.

Change-Id: Iad49371aef8c8c1939a0f39078bf9c22312fceaa
  • Loading branch information...
beanstown106 authored and xlxfoxxlx committed Nov 2, 2016
1 parent 6760237 commit 771c67c103cc85fc88b7456942602ea1a5205084
@@ -234,4 +234,8 @@
<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>
<!-- Heads up snooze toast -->
<string name="heads_up_snooze_message_one_minute"><xliff:g id="string">%s</xliff:g> - Peeking notification are snoozing for 1 minute.</string>
<string name="heads_up_snooze_message"><xliff:g id="string">%s</xliff:g> - Peeking notifications are snoozing for <xliff:g id="number">%d</xliff:g> minutes.</string>
</resources>
@@ -17,6 +17,7 @@
package com.android.systemui.statusbar.policy;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.os.Handler;
@@ -27,9 +28,11 @@
import android.util.ArraySet;
import android.util.Log;
import android.util.Pools;
import android.view.Gravity;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.accessibility.AccessibilityEvent;
import android.widget.TextView;
import android.widget.Toast;
import com.android.internal.logging.MetricsLogger;
@@ -331,14 +334,28 @@ public void snooze() {
mSnoozedPackages.put(snoozeKey(packageName, mUser),
SystemClock.elapsedRealtime() + mSnoozeLengthMs);
if (mSnoozeLengthMs != 0) {
String appName = null;
try {
appName = (String) mContext.getPackageManager().getApplicationLabel(
mContext.getPackageManager().getApplicationInfo(packageName,
PackageManager.GET_META_DATA));
} catch (PackageManager.NameNotFoundException e) {
appName = packageName;
}
if (mSnoozeLengthMs == 60000) {
Toast.makeText(mContext,
mContext.getString(R.string.heads_up_snooze_message_one_minute),
Toast.LENGTH_LONG).show();
Toast toast = Toast.makeText(mContext,
mContext.getString(R.string.heads_up_snooze_message_one_minute, appName),
Toast.LENGTH_LONG);
TextView v = (TextView) toast.getView().findViewById(android.R.id.message);
if( v != null) v.setGravity(Gravity.CENTER);
toast.show();
} else {
Toast.makeText(mContext,
mContext.getString(R.string.heads_up_snooze_message,
mSnoozeLengthMs / 60 / 1000), Toast.LENGTH_LONG).show();
Toast toast = Toast.makeText(mContext,
mContext.getString(R.string.heads_up_snooze_message, appName,
mSnoozeLengthMs / 60 / 1000), Toast.LENGTH_LONG);
TextView v = (TextView) toast.getView().findViewById(android.R.id.message);
if( v != null) v.setGravity(Gravity.CENTER);
toast.show();
}
}
}

0 comments on commit 771c67c

Please sign in to comment.