|
26 | 26 | import android.os.IBinder; |
27 | 27 | import android.os.Parcel; |
28 | 28 | import android.os.Parcelable; |
| 29 | +import android.os.SystemClock; |
29 | 30 | import android.text.TextUtils; |
30 | 31 | import android.util.IntProperty; |
31 | 32 | import android.util.Log; |
@@ -942,6 +943,7 @@ public static class Builder { |
942 | 943 | private ArrayList<Action> mActions = new ArrayList<Action>(3); |
943 | 944 | private boolean mCanHasIntruder; |
944 | 945 | private boolean mIntruderActionsShowText; |
| 946 | + private boolean mUseChronometer; |
945 | 947 |
|
946 | 948 | /** |
947 | 949 | * Constructs a new Builder with the defaults: |
@@ -982,6 +984,18 @@ public Builder setWhen(long when) { |
982 | 984 | return this; |
983 | 985 | } |
984 | 986 |
|
| 987 | + /** |
| 988 | + * @hide |
| 989 | + * |
| 990 | + * Show the {@link Notification#when} field as a countdown (or count-up) timer instead of a timestamp. |
| 991 | + * |
| 992 | + * @see Notification#when |
| 993 | + */ |
| 994 | + public Builder setUsesChronometer(boolean b) { |
| 995 | + mUseChronometer = b; |
| 996 | + return this; |
| 997 | + } |
| 998 | + |
985 | 999 | /** |
986 | 1000 | * Set the small icon resource, which will be used to represent the notification in the |
987 | 1001 | * status bar. |
@@ -1434,7 +1448,15 @@ private RemoteViews applyStandardTemplate(int resId) { |
1434 | 1448 | } |
1435 | 1449 | } |
1436 | 1450 | if (mWhen != 0) { |
1437 | | - contentView.setLong(R.id.time, "setTime", mWhen); |
| 1451 | + if (mUseChronometer) { |
| 1452 | + contentView.setViewVisibility(R.id.chronometer, View.VISIBLE); |
| 1453 | + contentView.setLong(R.id.chronometer, "setBase", |
| 1454 | + mWhen + (SystemClock.elapsedRealtime() - System.currentTimeMillis())); |
| 1455 | + contentView.setBoolean(R.id.chronometer, "setStarted", true); |
| 1456 | + } else { |
| 1457 | + contentView.setViewVisibility(R.id.time, View.VISIBLE); |
| 1458 | + contentView.setLong(R.id.time, "setTime", mWhen); |
| 1459 | + } |
1438 | 1460 | } |
1439 | 1461 | contentView.setViewVisibility(R.id.line3, hasLine3 ? View.VISIBLE : View.GONE); |
1440 | 1462 | return contentView; |
|
0 commit comments