| Index: webrtc/examples/androidapp/src/org/appspot/apprtc/util/LooperExecutor.java
|
| diff --git a/webrtc/examples/androidapp/src/org/appspot/apprtc/util/LooperExecutor.java b/webrtc/examples/androidapp/src/org/appspot/apprtc/util/LooperExecutor.java
|
| index 1563e26ddbd200213f1e522f8490e8229a77eb78..731630405a0d1f279ae76e32935cd8e6ce96d8d5 100644
|
| --- a/webrtc/examples/androidapp/src/org/appspot/apprtc/util/LooperExecutor.java
|
| +++ b/webrtc/examples/androidapp/src/org/appspot/apprtc/util/LooperExecutor.java
|
| @@ -14,6 +14,8 @@ import android.os.Handler;
|
| import android.os.Looper;
|
| import android.util.Log;
|
|
|
| +import java.util.LinkedList;
|
| +import java.util.List;
|
| import java.util.concurrent.Executor;
|
|
|
| /**
|
| @@ -24,6 +26,7 @@ public class LooperExecutor extends Thread implements Executor {
|
| // Object used to signal that looper thread has started and Handler instance
|
| // associated with looper thread has been allocated.
|
| private final Object looperStartedEvent = new Object();
|
| + private final List<Runnable> scheduledPeriodicRunnables = new LinkedList<Runnable>();
|
| private Handler handler = null;
|
| private boolean running = false;
|
| private long threadId;
|
| @@ -79,6 +82,41 @@ public class LooperExecutor extends Thread implements Executor {
|
| return (Thread.currentThread().getId() == threadId);
|
| }
|
|
|
| + public synchronized void scheduleAtFixedRate(final Runnable command, final long periodMillis) {
|
| + if (!running) {
|
| + Log.w(TAG, "Trying to schedule task for non running executor");
|
| + return;
|
| + }
|
| + Runnable runnable = new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + if (running) {
|
| + command.run();
|
| + if (!handler.postDelayed(this, periodMillis)) {
|
| + Log.e(TAG, "Failed to post a delayed runnable in the chain.");
|
| + }
|
| + }
|
| + }
|
| + };
|
| + scheduledPeriodicRunnables.add(runnable);
|
| + if (!handler.postDelayed(runnable, periodMillis)) {
|
| + Log.e(TAG, "Failed to post a delayed runnable.");
|
| + }
|
| + }
|
| +
|
| + public synchronized void cancelScheduledTasks() {
|
| + if (!running) {
|
| + Log.w(TAG, "Trying to cancel schedule tasks for non running executor");
|
| + return;
|
| + }
|
| +
|
| + // Stop scheduled periodic tasks.
|
| + for (Runnable r : scheduledPeriodicRunnables) {
|
| + handler.removeCallbacks(r);
|
| + }
|
| + scheduledPeriodicRunnables.clear();
|
| + }
|
| +
|
| @Override
|
| public synchronized void execute(final Runnable runnable) {
|
| if (!running) {
|
|
|