Merge "Chronometer: Update the value only if displayed on screen"
am: 34cd48bcd8
* commit '34cd48bcd8d284d864a0876db1373099c51b98e2':
Chronometer: Update the value only if displayed on screen
Change-Id: I01a820daaa6308c1cc00cd19940db12ec827f424
This commit is contained in:
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user