Chronometer: Update the value only if displayed on screen
Chronometer is refreshed every second even if not displayed
on the screen and if the screen is off.
Change-Id: I9348c4f988b6822f2c7d9cac0e47acaf82a02e01
Signed-off-by: Simon Dubray <simonx.dubray@intel.com>
Signed-off-by: Zhiquan Liu <zhiquan.liu@intel.com>
diff --git a/core/java/android/widget/Chronometer.java b/core/java/android/widget/Chronometer.java
index ebb54ff..1513264 100644
--- a/core/java/android/widget/Chronometer.java
+++ b/core/java/android/widget/Chronometer.java
@@ -25,6 +25,7 @@
import android.text.format.DateUtils;
import android.util.AttributeSet;
import android.util.Log;
+import android.view.View;
import android.view.accessibility.AccessibilityEvent;
import android.widget.RemoteViews.RemoteView;
@@ -226,6 +227,12 @@
updateRunning();
}
+ @Override
+ protected void onVisibilityChanged(View changedView, int visibility) {
+ super.onVisibilityChanged(changedView, visibility);
+ updateRunning();
+ }
+
private synchronized void updateText(long now) {
mNow = now;
long seconds = now - mBase;
@@ -254,7 +261,7 @@
}
private void updateRunning() {
- boolean running = mVisible && mStarted;
+ boolean running = mVisible && mStarted && isShown();
if (running != mRunning) {
if (running) {
updateText(SystemClock.elapsedRealtime());