Skip to content

Commit a2985ed

Browse files
committed
Chronometer support in Notifications.
@hidden for now while we experiment with it in Phone. Change-Id: Ib6ca3a8262f676d49d81e081a30c6d994c732a6b
1 parent 227dde2 commit a2985ed

File tree

6 files changed

+91
-6
lines changed

6 files changed

+91
-6
lines changed

core/java/android/app/Notification.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import android.os.IBinder;
2727
import android.os.Parcel;
2828
import android.os.Parcelable;
29+
import android.os.SystemClock;
2930
import android.text.TextUtils;
3031
import android.util.IntProperty;
3132
import android.util.Log;
@@ -942,6 +943,7 @@ public static class Builder {
942943
private ArrayList<Action> mActions = new ArrayList<Action>(3);
943944
private boolean mCanHasIntruder;
944945
private boolean mIntruderActionsShowText;
946+
private boolean mUseChronometer;
945947

946948
/**
947949
* Constructs a new Builder with the defaults:
@@ -982,6 +984,18 @@ public Builder setWhen(long when) {
982984
return this;
983985
}
984986

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+
985999
/**
9861000
* Set the small icon resource, which will be used to represent the notification in the
9871001
* status bar.
@@ -1434,7 +1448,15 @@ private RemoteViews applyStandardTemplate(int resId) {
14341448
}
14351449
}
14361450
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+
}
14381460
}
14391461
contentView.setViewVisibility(R.id.line3, hasLine3 ? View.VISIBLE : View.GONE);
14401462
return contentView;

core/java/android/widget/Chronometer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import android.text.format.DateUtils;
2626
import android.util.AttributeSet;
2727
import android.util.Log;
28+
import android.util.Slog;
2829
import android.view.accessibility.AccessibilityEvent;
2930
import android.view.accessibility.AccessibilityNodeInfo;
3031
import android.widget.RemoteViews.RemoteView;
@@ -247,6 +248,7 @@ private synchronized void updateText(long now) {
247248
}
248249
}
249250
setText(text);
251+
Slog.v("Chronometer", "updateText: sec=" + seconds + " mFormat=" + mFormat + " text=" + text);
250252
}
251253

252254
private void updateRunning() {

core/res/res/layout/notification_template_base.xml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,21 @@
5353
android:fadingEdge="horizontal"
5454
android:layout_weight="1"
5555
/>
56-
<DateTimeView android:id="@+id/time"
57-
android:textAppearance="@style/TextAppearance.StatusBar.EventContent.Time"
56+
<ViewStub android:id="@+id/time"
5857
android:layout_width="wrap_content"
5958
android:layout_height="wrap_content"
6059
android:layout_gravity="center"
6160
android:layout_weight="0"
62-
android:singleLine="true"
63-
android:gravity="center"
64-
android:paddingLeft="8dp"
61+
android:visibility="gone"
62+
android:layout="@layout/notification_template_part_time"
63+
/>
64+
<ViewStub android:id="@+id/chronometer"
65+
android:layout_width="wrap_content"
66+
android:layout_height="wrap_content"
67+
android:layout_gravity="center"
68+
android:layout_weight="0"
69+
android:visibility="gone"
70+
android:layout="@layout/notification_template_part_chronometer"
6571
/>
6672
</LinearLayout>
6773
<TextView android:id="@+id/text2"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright (C) 2012 The Android Open Source Project
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
17+
<Chronometer android:id="@+id/chronometer" xmlns:android="http://schemas.android.com/apk/res/android"
18+
android:textAppearance="@style/TextAppearance.StatusBar.EventContent.Time"
19+
android:layout_width="wrap_content"
20+
android:layout_height="wrap_content"
21+
android:layout_gravity="center"
22+
android:layout_weight="0"
23+
android:singleLine="true"
24+
android:gravity="center"
25+
android:paddingLeft="8dp"
26+
/>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright (C) 2012 The Android Open Source Project
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
17+
<DateTimeView android:id="@+id/time" xmlns:android="http://schemas.android.com/apk/res/android"
18+
android:textAppearance="@style/TextAppearance.StatusBar.EventContent.Time"
19+
android:layout_width="wrap_content"
20+
android:layout_height="wrap_content"
21+
android:layout_gravity="center"
22+
android:layout_weight="0"
23+
android:singleLine="true"
24+
android:gravity="center"
25+
android:paddingLeft="8dp"
26+
/>

core/res/res/values/public.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@
202202
<java-symbol type="id" name="action2" />
203203
<java-symbol type="id" name="big_picture" />
204204
<java-symbol type="id" name="big_text" />
205+
<java-symbol type="id" name="chronometer" />
205206

206207
<java-symbol type="attr" name="actionModeShareDrawable" />
207208
<java-symbol type="attr" name="alertDialogCenterButtons" />
@@ -1079,6 +1080,8 @@
10791080
<java-symbol type="layout" name="notification_intruder_content" />
10801081
<java-symbol type="layout" name="notification_template_base" />
10811082
<java-symbol type="layout" name="notification_template_big_picture" />
1083+
<java-symbol type="layout" name="notification_template_part_time" />
1084+
<java-symbol type="layout" name="notification_template_part_chronometer" />
10821085

10831086
<java-symbol type="anim" name="slide_in_child_bottom" />
10841087
<java-symbol type="anim" name="slide_in_right" />

0 commit comments

Comments
 (0)