Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 814e1f51 authored by Simon Dubray's avatar Simon Dubray Committed by Zhiquan Liu
Browse files

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: default avatarSimon Dubray <simonx.dubray@intel.com>
Signed-off-by: default avatarZhiquan Liu <zhiquan.liu@intel.com>
parent 6fea6611
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -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());