- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
128 lines
3.7 KiB
Java
128 lines
3.7 KiB
Java
package com.ea.nimble;
|
|
|
|
import android.os.Handler;
|
|
import android.os.Looper;
|
|
import android.os.SystemClock;
|
|
import com.ea.nimble.Log;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class Timer {
|
|
private static Handler s_handler = new Handler(Looper.getMainLooper());
|
|
private long m_fireTime;
|
|
private long m_pauseTime;
|
|
private Runnable m_task;
|
|
private Runnable m_taskToRun;
|
|
private long m_timeInterval;
|
|
private boolean m_running = false;
|
|
private boolean m_paused = false;
|
|
|
|
public boolean isPaused() {
|
|
return this.m_paused;
|
|
}
|
|
|
|
public boolean isRunning() {
|
|
return this.m_running;
|
|
}
|
|
|
|
public class RepeatingTask implements Runnable {
|
|
private RepeatingTask() {
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
if (Timer.this.m_paused || !Timer.this.m_running) {
|
|
return;
|
|
}
|
|
Timer.this.m_task.run();
|
|
Timer.this.m_fireTime = SystemClock.uptimeMillis() + Timer.this.m_fireTime;
|
|
Timer.s_handler.postDelayed(this, Timer.this.m_timeInterval);
|
|
}
|
|
}
|
|
|
|
public class SingleRunTask implements Runnable {
|
|
private SingleRunTask() {
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
if (Timer.this.m_paused || !Timer.this.m_running) {
|
|
return;
|
|
}
|
|
Timer.this.m_running = false;
|
|
Timer.this.m_task.run();
|
|
}
|
|
}
|
|
|
|
public Timer(Runnable runnable) {
|
|
this.m_task = runnable;
|
|
}
|
|
|
|
public void schedule(double d, boolean z) {
|
|
cancel();
|
|
if (d < 0.1d) {
|
|
if (z) {
|
|
Log.Helper.LOGES(null, "Timer scheduled to repeat for %.2f seconds, running only once", Double.valueOf(d));
|
|
}
|
|
if (Looper.myLooper() == Looper.getMainLooper()) {
|
|
this.m_task.run();
|
|
return;
|
|
} else {
|
|
s_handler.post(this.m_task);
|
|
return;
|
|
}
|
|
}
|
|
this.m_timeInterval = (long) (d * 1000.0d);
|
|
this.m_fireTime = SystemClock.uptimeMillis() + this.m_timeInterval;
|
|
if (z) {
|
|
this.m_taskToRun = new RepeatingTask();
|
|
} else {
|
|
this.m_taskToRun = new SingleRunTask();
|
|
}
|
|
s_handler.postDelayed(this.m_taskToRun, this.m_timeInterval);
|
|
this.m_running = true;
|
|
}
|
|
|
|
public void fire() {
|
|
cancel();
|
|
this.m_task.run();
|
|
if (this.m_taskToRun instanceof RepeatingTask) {
|
|
if (this.m_paused) {
|
|
this.m_fireTime = this.m_pauseTime + this.m_timeInterval;
|
|
return;
|
|
}
|
|
long uptimeMillis = SystemClock.uptimeMillis();
|
|
long j = this.m_timeInterval;
|
|
this.m_fireTime = uptimeMillis + j;
|
|
s_handler.postDelayed(this.m_taskToRun, j);
|
|
this.m_running = true;
|
|
}
|
|
}
|
|
|
|
public void pause() {
|
|
if (this.m_paused || !this.m_running) {
|
|
return;
|
|
}
|
|
this.m_pauseTime = SystemClock.uptimeMillis();
|
|
s_handler.removeCallbacks(this.m_taskToRun);
|
|
this.m_paused = true;
|
|
}
|
|
|
|
public void resume() {
|
|
if (this.m_paused && this.m_running) {
|
|
long uptimeMillis = this.m_fireTime + (SystemClock.uptimeMillis() - this.m_pauseTime);
|
|
this.m_fireTime = uptimeMillis;
|
|
s_handler.postAtTime(this.m_taskToRun, uptimeMillis);
|
|
this.m_paused = false;
|
|
}
|
|
}
|
|
|
|
public void cancel() {
|
|
if (this.m_running) {
|
|
if (!this.m_paused) {
|
|
s_handler.removeCallbacks(this.m_taskToRun);
|
|
}
|
|
this.m_running = false;
|
|
}
|
|
}
|
|
}
|