Optimize timer code.

Apparently onStop will be executed when the screen goes off.
This commit is contained in:
Mygod
2015-11-18 22:12:31 +08:00
parent 14414c644d
commit 3f8acd85ab
@@ -475,15 +475,12 @@ class Shadowsocks
} else {
TrafficMonitor.reset()
}
val pm = getSystemService(Context.POWER_SERVICE).asInstanceOf[PowerManager]
if (pm.isScreenOn) {
val trafficStat = getString(R.string.stat_summary).formatLocal(Locale.ENGLISH,
TrafficMonitor.getTxRate, TrafficMonitor.getRxRate,
TrafficMonitor.getTxTotal, TrafficMonitor.getRxTotal)
handler.post(() => {
preferences.findPreference(Key.stat).setSummary(trafficStat)
})
}
val trafficStat = getString(R.string.stat_summary).formatLocal(Locale.ENGLISH,
TrafficMonitor.getTxRate, TrafficMonitor.getRxRate,
TrafficMonitor.getTxTotal, TrafficMonitor.getRxTotal)
handler.post(() => {
preferences.findPreference(Key.stat).setSummary(trafficStat)
})
}
}
timer = new Timer(true)