summaryrefslogtreecommitdiff
path: root/platform/android/viewer/src/com/artifex/mupdfdemo/CancellableAsyncTask.java
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/viewer/src/com/artifex/mupdfdemo/CancellableAsyncTask.java')
-rw-r--r--platform/android/viewer/src/com/artifex/mupdfdemo/CancellableAsyncTask.java83
1 files changed, 0 insertions, 83 deletions
diff --git a/platform/android/viewer/src/com/artifex/mupdfdemo/CancellableAsyncTask.java b/platform/android/viewer/src/com/artifex/mupdfdemo/CancellableAsyncTask.java
deleted file mode 100644
index 53d16f57..00000000
--- a/platform/android/viewer/src/com/artifex/mupdfdemo/CancellableAsyncTask.java
+++ /dev/null
@@ -1,83 +0,0 @@
-package com.artifex.mupdfdemo;
-
-import java.util.concurrent.CancellationException;
-import java.util.concurrent.ExecutionException;
-
-// Ideally this would be a subclass of AsyncTask, however the cancel() method is final, and cannot
-// be overridden. I felt that having two different, but similar cancel methods was a bad idea.
-public class CancellableAsyncTask<Params, Result>
-{
- private final AsyncTask<Params, Void, Result> asyncTask;
- private final CancellableTaskDefinition<Params, Result> ourTask;
-
- public void onPreExecute()
- {
-
- }
-
- public void onPostExecute(Result result)
- {
-
- }
-
- public CancellableAsyncTask(final CancellableTaskDefinition<Params, Result> task)
- {
- if (task == null)
- throw new IllegalArgumentException();
-
- this.ourTask = task;
- asyncTask = new AsyncTask<Params, Void, Result>()
- {
- @Override
- protected Result doInBackground(Params... params)
- {
- return task.doInBackground(params);
- }
-
- @Override
- protected void onPreExecute()
- {
- CancellableAsyncTask.this.onPreExecute();
- }
-
- @Override
- protected void onPostExecute(Result result)
- {
- CancellableAsyncTask.this.onPostExecute(result);
- task.doCleanup();
- }
-
- @Override
- protected void onCancelled(Result result)
- {
- task.doCleanup();
- }
- };
- }
-
- public void cancel()
- {
- this.asyncTask.cancel(true);
- ourTask.doCancel();
-
- try
- {
- this.asyncTask.get();
- }
- catch (InterruptedException e)
- {
- }
- catch (ExecutionException e)
- {
- }
- catch (CancellationException e)
- {
- }
- }
-
- public void execute(Params ... params)
- {
- asyncTask.execute(params);
- }
-
-}