Skip to content

Commit 0c89049

Browse files
committed
Add Notification.Builder.setShowWhen(boolean).
No more setting when to 0 to hide the timestamp! *cheering* Bug: 6915046 Change-Id: I1560a1c2dd366d416d1d059704ca7c63149334eb
1 parent 8a0e1fe commit 0c89049

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

api/current.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3830,6 +3830,7 @@ package android.app {
38303830
method public android.app.Notification.Builder setOnlyAlertOnce(boolean);
38313831
method public android.app.Notification.Builder setPriority(int);
38323832
method public android.app.Notification.Builder setProgress(int, int, boolean);
3833+
method public android.app.Notification.Builder setShowWhen(boolean);
38333834
method public android.app.Notification.Builder setSmallIcon(int);
38343835
method public android.app.Notification.Builder setSmallIcon(int, int);
38353836
method public android.app.Notification.Builder setSound(android.net.Uri);

core/java/android/app/Notification.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,7 @@ public static class Builder {
951951
private ArrayList<Action> mActions = new ArrayList<Action>(MAX_ACTION_BUTTONS);
952952
private boolean mUseChronometer;
953953
private Style mStyle;
954+
private boolean mShowWhen = true;
954955

955956
/**
956957
* Constructs a new Builder with the defaults:
@@ -982,15 +983,25 @@ public Builder(Context context) {
982983

983984
/**
984985
* Add a timestamp pertaining to the notification (usually the time the event occurred).
986+
* It will be shown in the notification content view by default; use
987+
* {@link Builder#setShowWhen(boolean) setShowWhen} to control this.
985988
*
986-
987989
* @see Notification#when
988990
*/
989991
public Builder setWhen(long when) {
990992
mWhen = when;
991993
return this;
992994
}
993995

996+
/**
997+
* Control whether the timestamp set with {@link Builder#setWhen(long) setWhen} is shown
998+
* in the content view.
999+
*/
1000+
public Builder setShowWhen(boolean show) {
1001+
mShowWhen = show;
1002+
return this;
1003+
}
1004+
9941005
/**
9951006
* Show the {@link Notification#when} field as a stopwatch.
9961007
*
@@ -1467,7 +1478,7 @@ private RemoteViews applyStandardTemplate(int resId, boolean fitIn1U) {
14671478
contentView.setViewPadding(R.id.line1, 0, 0, 0, 0);
14681479
}
14691480

1470-
if (mWhen != 0) {
1481+
if (mWhen != 0 && mShowWhen) {
14711482
if (mUseChronometer) {
14721483
contentView.setViewVisibility(R.id.chronometer, View.VISIBLE);
14731484
contentView.setLong(R.id.chronometer, "setBase",
@@ -1477,7 +1488,10 @@ private RemoteViews applyStandardTemplate(int resId, boolean fitIn1U) {
14771488
contentView.setViewVisibility(R.id.time, View.VISIBLE);
14781489
contentView.setLong(R.id.time, "setTime", mWhen);
14791490
}
1491+
} else {
1492+
contentView.setViewVisibility(R.id.time, View.GONE);
14801493
}
1494+
14811495
contentView.setViewVisibility(R.id.line3, showLine3 ? View.VISIBLE : View.GONE);
14821496
contentView.setViewVisibility(R.id.overflow_divider, showLine3 ? View.VISIBLE : View.GONE);
14831497
return contentView;

0 commit comments

Comments
 (0)