Merge "Chronometer: Update the value only if displayed on screen"

This commit is contained in:
Alan Viverette
2016-05-27 14:18:20 +00:00
committed by Gerrit Code Review

View File

@@ -25,6 +25,7 @@ import android.os.SystemClock;
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 @@ public class Chronometer extends TextView {
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 @@ public class Chronometer extends TextView {
}
private void updateRunning() {
boolean running = mVisible && mStarted;
boolean running = mVisible && mStarted && isShown();
if (running != mRunning) {
if (running) {
updateText(SystemClock.elapsedRealtime());