Datasets:
ArXiv:
License:
File size: 1,176 Bytes
c574d3a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
package httpcli;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import java.util.concurrent.Executor;
import javax.swing.SwingUtilities;
public class Platform implements Executor {
private static final Platform PLATFORM = findPlatform();
static Platform get() {
return PLATFORM;
}
private static Platform findPlatform() {
try {
Class.forName("android.os.Build");
if (Build.VERSION.SDK_INT != 0) {
return new Android();
}
} catch (ClassNotFoundException ignored) {
}
try {
Class.forName("javax.swing.SwingUtilities");
return new JavaSwing();
} catch (ClassNotFoundException ignored) {
}
return new Platform();
}
@Override public void execute(Runnable command) {
command.run();
}
public static class Android extends Platform {
final Handler mHandler = new Handler(Looper.getMainLooper());
@Override public void execute(Runnable command) {
mHandler.post(command);
}
}
public static class JavaSwing extends Platform {
@Override public void execute(Runnable command) {
SwingUtilities.invokeLater(command);
}
}
}
|