Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package com.silcos.permainan;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import com.silcos.board.BoardPlatformProvider;
public class CustomBoardPlatformProvider extends BoardPlatformProvider {
static Handler sComputerThreadHandler;
static HandlerThread sComputerThread = new HandlerThread(COMPUTER_TASK) {
@Override
public void run() {
Looper.prepare();
sComputerThreadHandler = new Handler();
Looper.loop();
}
};
static Handler sGameEventThreadHandler;
static HandlerThread sGameEventThread = new HandlerThread(GAME_EVENT_TASK) {
@Override
public void run() {
Looper.prepare();
sGameEventThreadHandler = new Handler();
Looper.loop();
}
};
static {
sComputerThread.start();
sGameEventThread.start();
}
@Override
public void runComputeIntensiveTask(String taskName, Runnable taskExec) {
if (taskName.contentEquals(COMPUTER_TASK)) {
sComputerThreadHandler.post(taskExec);
return;
} else if (taskName.contentEquals(GAME_EVENT_TASK)) {
sGameEventThreadHandler.post(taskExec);
return;
}
throw new UnsupportedOperationException("taskName " + taskName + " is " +
"not recognized, couldn't run the compute task.");
}
@Override
public void runComputeIntensiveTaskAfter(int ms, String taskName, Runnable taskExec) {
if (taskName.contentEquals(COMPUTER_TASK)) {
sComputerThreadHandler.postDelayed(taskExec, ms);
return;
} else if (taskName.contentEquals(GAME_EVENT_TASK)) {
sGameEventThreadHandler.postDelayed(taskExec, ms);
return;
}
throw new UnsupportedOperationException("taskName " + taskName + " is " +
"not recognized, couldn't run the compute task.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.