Remove CameraView usage of JobManager.

WorkManager flat-out can't handle anonymous implementations of Worker
classes due to it using reflection to instantiate them.
pull/1/head
Greyson Parrelli 7 years ago
parent 87e6aa48bb
commit 2f530dc970

@ -485,60 +485,40 @@ public class CameraView extends ViewGroup {
} }
private void enqueueTask(SerialAsyncTask job) { private void enqueueTask(SerialAsyncTask job) {
ApplicationContext.getInstance(getContext()).getJobManager().add(job); AsyncTask.SERIAL_EXECUTOR.execute(job);
} }
private static abstract class SerialAsyncTask<Result> extends Job { public static abstract class SerialAsyncTask<Result> implements Runnable {
public SerialAsyncTask() { @Override
super(JobParameters.newBuilder().withGroupId(CameraView.class.getSimpleName()).create()); public final void run() {
} if (!onWait()) {
@Override public void onAdded() {}
@Override public final void onRun() {
try {
onWait();
Util.runOnMainSync(new Runnable() {
@Override public void run() {
onPreMain();
}
});
final Result result = onRunBackground();
Util.runOnMainSync(new Runnable() {
@Override public void run() {
onPostMain(result);
}
});
} catch (PreconditionsNotMetException e) {
Log.w(TAG, "skipping task, preconditions not met in onWait()"); Log.w(TAG, "skipping task, preconditions not met in onWait()");
return;
} }
}
@Override public boolean onShouldRetry(Exception e) { Util.runOnMainSync(this::onPreMain);
return false; final Result result = onRunBackground();
Util.runOnMainSync(() -> onPostMain(result));
} }
@Override public void onCanceled() { } protected boolean onWait() { return true; }
protected void onWait() throws PreconditionsNotMetException {}
protected void onPreMain() {} protected void onPreMain() {}
protected Result onRunBackground() { return null; } protected Result onRunBackground() { return null; }
protected void onPostMain(Result result) {} protected void onPostMain(Result result) {}
} }
private abstract class PostInitializationTask<Result> extends SerialAsyncTask<Result> { private abstract class PostInitializationTask<Result> extends SerialAsyncTask<Result> {
@Override protected void onWait() throws PreconditionsNotMetException { @Override protected boolean onWait() {
synchronized (CameraView.this) { synchronized (CameraView.this) {
if (!camera.isPresent()) { if (!camera.isPresent()) {
throw new PreconditionsNotMetException(); return false;
} }
while (getMeasuredHeight() <= 0 || getMeasuredWidth() <= 0 || !surface.isReady()) { while (getMeasuredHeight() <= 0 || getMeasuredWidth() <= 0 || !surface.isReady()) {
Log.i(TAG, String.format("waiting. surface ready? %s", surface.isReady())); Log.i(TAG, String.format("waiting. surface ready? %s", surface.isReady()));
Util.wait(CameraView.this, 0); Util.wait(CameraView.this, 0);
} }
return true;
} }
} }
} }

Loading…
Cancel
Save