Merge "Chronometer: Update the value only if displayed on screen"
This commit is contained in:
@@ -25,6 +25,7 @@ import android.os.SystemClock;
|
|||||||
import android.text.format.DateUtils;
|
import android.text.format.DateUtils;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
import android.view.accessibility.AccessibilityEvent;
|
import android.view.accessibility.AccessibilityEvent;
|
||||||
import android.widget.RemoteViews.RemoteView;
|
import android.widget.RemoteViews.RemoteView;
|
||||||
|
|
||||||
@@ -226,6 +227,12 @@ public class Chronometer extends TextView {
|
|||||||
updateRunning();
|
updateRunning();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onVisibilityChanged(View changedView, int visibility) {
|
||||||
|
super.onVisibilityChanged(changedView, visibility);
|
||||||
|
updateRunning();
|
||||||
|
}
|
||||||
|
|
||||||
private synchronized void updateText(long now) {
|
private synchronized void updateText(long now) {
|
||||||
mNow = now;
|
mNow = now;
|
||||||
long seconds = now - mBase;
|
long seconds = now - mBase;
|
||||||
@@ -254,7 +261,7 @@ public class Chronometer extends TextView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateRunning() {
|
private void updateRunning() {
|
||||||
boolean running = mVisible && mStarted;
|
boolean running = mVisible && mStarted && isShown();
|
||||||
if (running != mRunning) {
|
if (running != mRunning) {
|
||||||
if (running) {
|
if (running) {
|
||||||
updateText(SystemClock.elapsedRealtime());
|
updateText(SystemClock.elapsedRealtime());
|
||||||
|
|||||||
Reference in New Issue
Block a user