add option to run SimpleWorker task onMainLoop before execution on worker-thread
This commit is contained in:
parent
bf2e0e44a8
commit
bdc18c9eb6
@ -8,7 +8,7 @@ import org.oscim.map.Map;
|
|||||||
*/
|
*/
|
||||||
public abstract class SimpleWorker<T> implements Runnable {
|
public abstract class SimpleWorker<T> implements Runnable {
|
||||||
|
|
||||||
private final Map mMap;
|
protected final Map mMap;
|
||||||
|
|
||||||
protected boolean mRunning;
|
protected boolean mRunning;
|
||||||
protected boolean mWait;
|
protected boolean mWait;
|
||||||
@ -48,7 +48,12 @@ public abstract class SimpleWorker<T> implements Runnable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: mTaskTodo == null?
|
||||||
if (mDelayed || mTaskTodo == null) {
|
if (mDelayed || mTaskTodo == null) {
|
||||||
|
|
||||||
|
if (mDelayed)
|
||||||
|
onMainLoop(mTaskTodo);
|
||||||
|
|
||||||
// entered on main-loop
|
// entered on main-loop
|
||||||
mDelayed = false;
|
mDelayed = false;
|
||||||
// unset running temporarily
|
// unset running temporarily
|
||||||
@ -88,6 +93,15 @@ public abstract class SimpleWorker<T> implements Runnable {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** do stuff on main-loop before executing the task */
|
||||||
|
public void onMainLoop(T task) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If delay > 0 onMainLoop will be called before Task
|
||||||
|
* is passed to worker-thread
|
||||||
|
*/
|
||||||
public synchronized void submit(long delay) {
|
public synchronized void submit(long delay) {
|
||||||
|
|
||||||
if (mRunning) {
|
if (mRunning) {
|
||||||
@ -101,9 +115,10 @@ public abstract class SimpleWorker<T> implements Runnable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!mDelayed) {
|
||||||
mDelayed = true;
|
mDelayed = true;
|
||||||
mMap.postDelayed(this, delay);
|
mMap.postDelayed(this, delay);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized T poll() {
|
public synchronized T poll() {
|
||||||
@ -133,4 +148,9 @@ public abstract class SimpleWorker<T> implements Runnable {
|
|||||||
cleanup(mTaskTodo);
|
cleanup(mTaskTodo);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized boolean isRunning() {
|
||||||
|
return mRunning;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user