OSDN Git Service

Chronometer support in Notifications.
authorDaniel Sandler <dsandler@android.com>
Tue, 3 Apr 2012 20:42:00 +0000 (16:42 -0400)
committerDaniel Sandler <dsandler@android.com>
Wed, 4 Apr 2012 19:35:44 +0000 (15:35 -0400)
@hidden for now while we experiment with it in Phone.

Change-Id: Ib6ca3a8262f676d49d81e081a30c6d994c732a6b

core/java/android/app/Notification.java
core/java/android/widget/Chronometer.java
core/res/res/layout/notification_template_base.xml
core/res/res/layout/notification_template_part_chronometer.xml [new file with mode: 0644]
core/res/res/layout/notification_template_part_time.xml [new file with mode: 0644]
core/res/res/values/public.xml

index 096af93..257a467 100644 (file)
@@ -26,6 +26,7 @@ import android.os.Bundle;
 import android.os.IBinder;
 import android.os.Parcel;
 import android.os.Parcelable;
+import android.os.SystemClock;
 import android.text.TextUtils;
 import android.util.IntProperty;
 import android.util.Log;
@@ -942,6 +943,7 @@ public class Notification implements Parcelable
         private ArrayList<Action> mActions = new ArrayList<Action>(3);
         private boolean mCanHasIntruder;
         private boolean mIntruderActionsShowText;
+        private boolean mUseChronometer;
 
         /**
          * Constructs a new Builder with the defaults:
@@ -983,6 +985,18 @@ public class Notification implements Parcelable
         }
 
         /**
+         * @hide
+         * 
+         * Show the {@link Notification#when} field as a countdown (or count-up) timer instead of a timestamp.  
+         *
+         * @see Notification#when
+         */
+        public Builder setUsesChronometer(boolean b) {
+            mUseChronometer = b;
+            return this;
+        }
+
+        /**
          * Set the small icon resource, which will be used to represent the notification in the
          * status bar.
          *
@@ -1434,7 +1448,15 @@ public class Notification implements Parcelable
                 }
             }
             if (mWhen != 0) {
-                contentView.setLong(R.id.time, "setTime", mWhen);
+                if (mUseChronometer) {
+                    contentView.setViewVisibility(R.id.chronometer, View.VISIBLE);
+                    contentView.setLong(R.id.chronometer, "setBase",
+                            mWhen + (SystemClock.elapsedRealtime() - System.currentTimeMillis()));
+                    contentView.setBoolean(R.id.chronometer, "setStarted", true);
+                } else {
+                    contentView.setViewVisibility(R.id.time, View.VISIBLE);
+                    contentView.setLong(R.id.time, "setTime", mWhen);
+                }
             }
             contentView.setViewVisibility(R.id.line3, hasLine3 ? View.VISIBLE : View.GONE);
             return contentView;
index 0370049..9c9eb4b 100644 (file)
@@ -25,6 +25,7 @@ import android.os.SystemClock;
 import android.text.format.DateUtils;
 import android.util.AttributeSet;
 import android.util.Log;
+import android.util.Slog;
 import android.view.accessibility.AccessibilityEvent;
 import android.view.accessibility.AccessibilityNodeInfo;
 import android.widget.RemoteViews.RemoteView;
@@ -247,6 +248,7 @@ public class Chronometer extends TextView {
             }
         }
         setText(text);
+        Slog.v("Chronometer", "updateText: sec=" + seconds + " mFormat=" + mFormat + " text=" + text);
     }
 
     private void updateRunning() {
index 93843fd..b9710d6 100644 (file)
                 android:fadingEdge="horizontal"
                 android:layout_weight="1"
                 />
-            <DateTimeView android:id="@+id/time"
-                android:textAppearance="@style/TextAppearance.StatusBar.EventContent.Time"
+            <ViewStub android:id="@+id/time"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_gravity="center"
                 android:layout_weight="0"
-                android:singleLine="true"
-                android:gravity="center"
-                android:paddingLeft="8dp"
+                android:visibility="gone"
+                android:layout="@layout/notification_template_part_time"
+                />
+            <ViewStub android:id="@+id/chronometer"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_gravity="center"
+                android:layout_weight="0"
+                android:visibility="gone"
+                android:layout="@layout/notification_template_part_chronometer"
                 />
         </LinearLayout>
         <TextView android:id="@+id/text2"
diff --git a/core/res/res/layout/notification_template_part_chronometer.xml b/core/res/res/layout/notification_template_part_chronometer.xml
new file mode 100644 (file)
index 0000000..382b0e4
--- /dev/null
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<Chronometer android:id="@+id/chronometer" xmlns:android="http://schemas.android.com/apk/res/android"
+    android:textAppearance="@style/TextAppearance.StatusBar.EventContent.Time"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content"
+    android:layout_gravity="center"
+    android:layout_weight="0"
+    android:singleLine="true"
+    android:gravity="center"
+    android:paddingLeft="8dp"
+    />
diff --git a/core/res/res/layout/notification_template_part_time.xml b/core/res/res/layout/notification_template_part_time.xml
new file mode 100644 (file)
index 0000000..410fcaf
--- /dev/null
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<DateTimeView android:id="@+id/time" xmlns:android="http://schemas.android.com/apk/res/android"
+    android:textAppearance="@style/TextAppearance.StatusBar.EventContent.Time"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content"
+    android:layout_gravity="center"
+    android:layout_weight="0"
+    android:singleLine="true"
+    android:gravity="center"
+    android:paddingLeft="8dp"
+    />
index e5f049d..44e8326 100644 (file)
   <java-symbol type="id" name="action2" />
   <java-symbol type="id" name="big_picture" />
   <java-symbol type="id" name="big_text" />
+  <java-symbol type="id" name="chronometer" />
 
   <java-symbol type="attr" name="actionModeShareDrawable" />
   <java-symbol type="attr" name="alertDialogCenterButtons" />
   <java-symbol type="layout" name="notification_intruder_content" />
   <java-symbol type="layout" name="notification_template_base" />
   <java-symbol type="layout" name="notification_template_big_picture" />
+  <java-symbol type="layout" name="notification_template_part_time" />
+  <java-symbol type="layout" name="notification_template_part_chronometer" />
 
   <java-symbol type="anim" name="slide_in_child_bottom" />
   <java-symbol type="anim" name="slide_in_right" />